/* ─── Reset & Base ──────────────────────────────────────────────────────── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.6;
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100%;
}

body {
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  transition: background-color var(--transition-slow), color var(--transition-slow);
}

/* ─── Accessibility ─────────────────────────────────────────────────────── */
.skip-link {
  position: absolute;
  top: -100px;
  left: 16px;
  background: var(--accent);
  color: #000;
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  font-weight: 700;
  z-index: 10000;
  text-decoration: none;
  transition: top 0.2s;
}
.skip-link:focus {
  top: 16px;
}

/* ─── Scrollbar ─────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 999px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ─── Focus Styles ──────────────────────────────────────────────────────── */
:focus-visible {
  outline: 2px solid var(--border-focus, var(--accent));
  outline-offset: 3px;
  border-radius: 4px;
}

/* ─── Typography ────────────────────────────────────────────────────────── */
h1, h2, h3, h4, h5, h6 {
  line-height: 1.25;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.02em;
}
h1 { font-size: clamp(1.75rem, 4vw, 2.5rem); }
h2 { font-size: clamp(1.25rem, 2.5vw, 1.75rem); }
h3 { font-size: clamp(1.05rem, 2vw, 1.25rem); }

p { color: var(--text-secondary); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code, pre { font-family: var(--font-mono); font-size: 0.875em; }
pre { white-space: pre-wrap; word-break: break-word; }

/* ─── Form Elements ─────────────────────────────────────────────────────── */
button, input, select, textarea {
  font: inherit;
}
input, select, textarea {
  background: var(--bg-surface);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  width: 100%;
  transition: border-color var(--transition), box-shadow var(--transition);
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.15);
}
input::placeholder, textarea::placeholder {
  color: var(--text-muted);
}

button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 20px;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: #0f172a;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition), opacity var(--transition), transform var(--transition);
  white-space: nowrap;
}
button:hover { background: var(--accent-dark, var(--accent)); filter: brightness(1.1); }
button:active { transform: scale(0.98); }
button:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }
button.btn-secondary {
  background: var(--bg-surface);
  color: var(--text-primary);
  border: 1px solid var(--border);
}
button.btn-secondary:hover { background: var(--bg-muted); filter: none; }
button.btn-danger {
  background: var(--danger);
  color: #fff;
}
button.btn-sm {
  padding: 6px 12px;
  font-size: 0.85rem;
  border-radius: var(--radius-sm);
}

img { max-width: 100%; display: block; }
ul, ol { padding-left: 1.4em; }

/* ─── App Layout ────────────────────────────────────────────────────────── */
.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
  flex: 1;
  min-height: calc(100dvh - var(--navbar-height));
}

#app {
  overflow-y: auto;
  min-height: 0;
}

/* ─── Page Shell ────────────────────────────────────────────────────────── */
.page-shell {
  padding: 28px 32px;
  max-width: var(--max-width);
  width: 100%;
  margin: 0 auto;
  animation: pageFadeIn 0.25s ease both;
}

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

/* ─── Cards ─────────────────────────────────────────────────────────────── */
.card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow-sm);
  transition: box-shadow var(--transition);
}
.card:hover { box-shadow: var(--shadow); }

.stat-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.stat-card span {
  font-size: 0.85rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.stat-card strong {
  font-size: clamp(1.8rem, 3vw, 2.5rem);
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.04em;
  font-variant-numeric: tabular-nums;
}

/* ─── Grids ─────────────────────────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 18px;
  margin-bottom: 28px;
}
.chart-panel {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  margin-bottom: 24px;
}

/* ─── Back to Top ───────────────────────────────────────────────────────── */
#back-to-top {
  position: fixed;
  bottom: 28px;
  right: 28px;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--accent);
  color: #0f172a;
  font-size: 1.4rem;
  padding: 0;
  box-shadow: var(--shadow);
  z-index: 200;
  opacity: 0;
  transform: translateY(16px);
  transition: opacity 0.25s ease, transform 0.25s ease;
  pointer-events: none;
}
#back-to-top.visible {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}
#back-to-top[hidden] { display: none; }

/* ─── Sidebar Overlay (mobile) ──────────────────────────────────────────── */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 99;
  backdrop-filter: blur(4px);
}
.sidebar-overlay.active { display: block; }

/* ─── Responsive ────────────────────────────────────────────────────────── */
@media (max-width: 900px) {
  .app-shell {
    grid-template-columns: 1fr;
  }
  #app-sidebar {
    position: fixed;
    top: var(--navbar-height);
    left: 0;
    bottom: 0;
    width: var(--sidebar-width);
    z-index: 100;
    transform: translateX(-100%);
    transition: transform var(--transition-slow);
  }
  #app-sidebar.open {
    transform: translateX(0);
    box-shadow: var(--shadow-lg);
  }
  .page-shell {
    padding: 20px 18px;
  }
}

@media (max-width: 540px) {
  h1 { font-size: 1.5rem; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .page-shell { padding: 16px 14px; }
}

/* ─── Print ─────────────────────────────────────────────────────────────── */
@media print {
  app-navbar, app-sidebar, app-footer, #back-to-top, #command-palette-root {
    display: none !important;
  }
  .app-shell { display: block; }
  .page-shell { padding: 0; max-width: 100%; }
  body { background: #fff; color: #000; }
}
