*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  -webkit-text-size-adjust: 100%;
  -moz-text-size-adjust: 100%;
  text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  transition: background var(--transition-theme);
}

html, body {
  height: 100%;
}

body {
  background: var(--bg);
  color: var(--text-primary);
  font: var(--text-base)/var(--leading-relaxed) var(--font-sans);
  overflow: hidden;
  transition: background var(--transition-theme), color var(--transition-theme), border-color var(--transition-theme);
}

img, svg, video {
  display: block;
  max-width: 100%;
}

a {
  color: var(--accent);
  text-decoration: none;
  transition: color var(--transition-fast);
}

a:hover {
  color: var(--accent-hover);
}

button {
  font-family: inherit;
  cursor: pointer;
}

input, textarea, select {
  font-family: inherit;
  font-size: inherit;
}

textarea {
  resize: vertical;
}

::selection {
  background: var(--accent-subtle);
  color: var(--text-primary);
}

/* Scrollbar */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: var(--scrollbar-track);
}

::-webkit-scrollbar-thumb {
  background: var(--scrollbar-thumb);
  border-radius: var(--radius-full);
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-tertiary);
}

/* Focus ring */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Typography */
h1, h2, h3, h4, h5, h6 {
  font-weight: 600;
  line-height: var(--leading-tight);
  color: var(--text-primary);
}

h1 { font-size: var(--text-3xl); letter-spacing: var(--tracking-tight); }
h2 { font-size: var(--text-2xl); letter-spacing: var(--tracking-tight); }
h3 { font-size: var(--text-xl); letter-spacing: var(--tracking-tight); }
h4 { font-size: var(--text-lg); }
h5 { font-size: var(--text-base); }
h6 { font-size: var(--text-sm); }

p { margin-bottom: var(--space-3); }
p:last-child { margin-bottom: 0; }

small, .text-small {
  font-size: var(--text-sm);
  color: var(--text-secondary);
}

code {
  font-family: var(--font-mono);
  font-size: 0.92em;
  padding: 2px 6px;
  background: var(--bg-inset);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-primary);
}

pre {
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  line-height: var(--leading-relaxed);
}

/* Utility classes */
.text-muted { color: var(--text-secondary); }
.text-accent { color: var(--accent); }
.text-success { color: var(--success); }
.text-warning { color: var(--warning); }
.text-danger { color: var(--danger); }

.flex { display: flex; }
.flex-col { flex-direction: column; }
.flex-wrap { flex-wrap: wrap; }
.items-center { align-items: center; }
.items-end { align-items: flex-end; }
.justify-center { justify-content: center; }
.justify-between { justify-content: space-between; }
.justify-end { justify-content: flex-end; }
.gap-1 { gap: var(--space-1); }
.gap-2 { gap: var(--space-2); }
.gap-3 { gap: var(--space-3); }
.gap-4 { gap: var(--space-4); }
.grow { flex: 1; }
.shrink-0 { flex-shrink: 0; }

.truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

/* Animations */
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes fadeInScale {
  from { opacity: 0; transform: scale(0.95); }
  to { opacity: 1; transform: scale(1); }
}

@keyframes slideInRight {
  from { opacity: 0; transform: translateX(16px); }
  to { opacity: 1; transform: translateX(0); }
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

@keyframes skeleton {
  0% { background-position: -200px 0; }
  100% { background-position: calc(200px + 100%) 0; }
}

@keyframes wave {
  0%, 100% { height: 8px; }
  50% { height: 20px; }
}

.animate-fadeIn { animation: fadeIn var(--transition-base) ease both; }
.animate-fadeInUp { animation: fadeInUp var(--transition-base) ease both; }
.animate-fadeInScale { animation: fadeInScale var(--transition-base) ease both; }
.animate-slideInRight { animation: slideInRight var(--transition-base) ease both; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* App layout */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
  grid-template-rows: var(--header-height) 1fr;
  height: 100vh;
  width: 100vw;
  overflow: hidden;
}

.app-header {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--space-6);
  height: var(--header-height);
  border-bottom: 1px solid var(--border-primary);
  background: var(--glass);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  z-index: var(--z-header);
  transition: background var(--transition-theme), border-color var(--transition-theme);
}

.app-sidebar {
  grid-row: 2;
  overflow-y: auto;
  border-right: 1px solid var(--border-primary);
  background: var(--bg-surface);
  padding: var(--space-4);
  transition: background var(--transition-theme), border-color var(--transition-theme);
}

.app-content {
  grid-row: 2;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  background: var(--bg-elevated);
  transition: background var(--transition-theme);
}

@media (max-width: 768px) {
  .app {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
  }
  .app-sidebar {
    display: none;
  }
  .app-sidebar.open {
    display: block;
    position: fixed;
    inset: 0;
    z-index: var(--z-sidebar);
  }
}