/*
 * app.css — design tokens + shell components for the CMS study site.
 * Dark cellar palette: near-black background, bone text, wine-red accent.
 * Mobile-first (built to be used one-handed at a kitchen counter);
 * system font stack only; no external UI libraries.
 */

:root {
  /* surfaces */
  --bg: #0b0908;
  --bg-elevated: #14100e;
  --surface: #1c1613;
  --surface-2: #241b17;
  --border: #3a2c26;

  /* text */
  --text: #f2e9dc;
  --text-dim: #c8b9a9;
  --text-faint: #9c8b7a;

  /* wine-red accent family */
  --accent: #8e1537;
  --accent-2: #c02a4e;
  --accent-text: #ff9db3;
  --accent-soft: #341019;

  /* status */
  --success: #6fae6f;
  --success-soft: #16241a;
  --warn: #d9a441;
  --warn-soft: #2a2213;
  --danger: #e0584a;
  --danger-soft: #2a1614;

  --focus-ring: #ffd166;

  /* type + space */
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --radius: 10px;
  --radius-sm: 6px;
  --nav-h: 62px;
  --side-nav-w: 220px;
}

* {
  box-sizing: border-box;
}

html {
  color-scheme: dark;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

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

h1, h2, h3 {
  line-height: 1.2;
  margin: 0 0 var(--space-3);
}

h2 {
  font-size: 1.05rem;
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

p {
  margin: 0 0 var(--space-2);
}

code, pre {
  font-family: var(--font-mono);
}

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

.dim {
  color: var(--text-dim);
}

.eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-size: 0.72rem;
  color: var(--text-faint);
  margin: 0 0 var(--space-1);
}

/* ── shell layout ─────────────────────────────────────────────────── */

.app-shell {
  min-height: 100vh;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border);
  background: var(--bg-elevated);
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar__title {
  font-weight: 700;
  font-size: 1rem;
  letter-spacing: 0.02em;
}

.topbar__title .accent {
  color: var(--accent-text);
}

.main {
  padding: var(--space-4) var(--space-4) calc(var(--nav-h) + var(--space-5));
  max-width: 900px;
  margin: 0 auto;
}

/* bottom tab bar (mobile default) */
.tab-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  height: var(--nav-h);
  display: flex;
  background: var(--bg-elevated);
  border-top: 1px solid var(--border);
  z-index: 20;
  padding-bottom: env(safe-area-inset-bottom, 0);
}

.tab-bar__link {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  text-decoration: none;
  color: var(--text-faint);
  font-size: 0.68rem;
  padding: var(--space-2) 0;
  border-top: 2px solid transparent;
}

.tab-bar__link .tab-icon {
  font-size: 1.1rem;
  line-height: 1;
}

.tab-bar__link.is-active {
  color: var(--accent-text);
  border-top-color: var(--accent-2);
}

.side-nav {
  display: none;
}

@media (min-width: 760px) {
  .tab-bar {
    display: none;
  }

  .side-nav {
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: var(--side-nav-w);
    background: var(--bg-elevated);
    border-right: 1px solid var(--border);
    padding: var(--space-4) var(--space-2);
    gap: var(--space-1);
    z-index: 20;
  }

  .side-nav__brand {
    padding: 0 var(--space-3) var(--space-4);
    font-weight: 700;
  }

  .side-nav__brand .accent {
    color: var(--accent-text);
  }

  .side-nav__link {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius-sm);
    text-decoration: none;
    color: var(--text-dim);
    font-size: 0.9rem;
  }

  .side-nav__link:hover {
    background: var(--surface);
    color: var(--text);
  }

  .side-nav__link.is-active {
    background: var(--accent-soft);
    color: var(--accent-text);
    font-weight: 600;
  }

  .app-shell {
    margin-left: var(--side-nav-w);
  }

  .main {
    padding-bottom: var(--space-5);
  }

  .topbar {
    display: none;
  }
}

/* ── components ───────────────────────────────────────────────────── */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-4);
  margin-bottom: var(--space-4);
}

.card--hero {
  background: linear-gradient(160deg, var(--accent-soft), var(--surface) 65%);
}

.grid-2col {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-4);
}

@media (min-width: 540px) {
  .grid-2col {
    grid-template-columns: 1fr 1fr;
  }
}

.stat-huge {
  font-size: 2.6rem;
  font-weight: 800;
  margin: 0 0 var(--space-1);
  color: var(--text);
}

.stat-big {
  font-size: 1.4rem;
  font-weight: 700;
  margin: 0 0 var(--space-1);
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: var(--space-2) var(--space-3);
  font-size: 0.85rem;
  font-family: inherit;
  cursor: pointer;
  text-decoration: none;
}

.btn:hover {
  border-color: var(--accent-2);
}

.btn--primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}

.btn--primary:hover {
  background: var(--accent-2);
}

.btn--small {
  padding: var(--space-1) var(--space-2);
  font-size: 0.76rem;
}

.btn--danger {
  border-color: var(--danger);
  color: var(--danger);
  background: transparent;
}

.btn--file {
  position: relative;
}

.form-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
  align-items: flex-end;
}

.form-row label {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  font-size: 0.78rem;
  color: var(--text-dim);
}

.form-row__checkbox {
  flex-direction: row !important;
  align-items: center;
  gap: var(--space-2) !important;
}

.form-row__checkbox input[type="checkbox"] {
  width: auto;
}

input, textarea, select {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: var(--space-2);
  font-family: inherit;
  font-size: 0.9rem;
}

.table-wrap {
  overflow-x: auto;
}

table.mastery-table {
  border-collapse: collapse;
  width: 100%;
  font-size: 0.85rem;
}

.mastery-table th, .mastery-table td {
  text-align: left;
  padding: var(--space-2) var(--space-2);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.mastery-table th {
  color: var(--text-faint);
  font-weight: 600;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.progress-dots {
  display: inline-flex;
  gap: 4px;
}

.dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--border);
  display: inline-block;
}

.dot--filled {
  background: var(--accent-2);
}

.check {
  color: var(--success);
  font-weight: 700;
}

.badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 1px 8px;
  font-size: 0.7rem;
  font-weight: 700;
  line-height: 1.6;
}

.badge--retired {
  background: var(--warn-soft);
  color: var(--warn);
}

.badge--ok {
  background: var(--success-soft);
  color: var(--success);
}

.badge--warn {
  background: var(--warn-soft);
  color: var(--warn);
}

.badge--type {
  background: var(--surface-2);
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.badge--count {
  background: var(--accent);
  color: #fff;
}

.canvas-wrap {
  width: 100%;
  height: 180px;
}

#trend-canvas {
  width: 100%;
  height: 100%;
  display: block;
}

.legend {
  font-size: 0.75rem;
  color: var(--text-dim);
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-wrap: wrap;
}

.legend-swatch {
  display: inline-block;
  width: 14px;
  height: 3px;
  border-radius: 2px;
}

.legend-swatch--score {
  background: var(--accent-2);
}

.legend-swatch--sub {
  background: var(--accent-text);
  background-image: linear-gradient(90deg, var(--accent-text) 60%, transparent 40%);
  background-size: 6px 3px;
}

.progress-bar {
  height: 10px;
  border-radius: 999px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  overflow: hidden;
  margin-top: var(--space-1);
}

.progress-bar--small {
  height: 6px;
}

.progress-bar__fill {
  height: 100%;
  background: var(--accent-2);
}

.counter-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.counter-list li {
  display: flex;
  flex-direction: column;
  font-size: 0.85rem;
}

.counter-list li > span:first-child {
  font-weight: 600;
}

.flag-item {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: var(--space-3);
  margin-bottom: var(--space-3);
  background: var(--bg-elevated);
}

.flag-item__meta {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin-bottom: var(--space-1);
  font-size: 0.8rem;
}

.flag-item__actions {
  display: flex;
  gap: var(--space-2);
  flex-wrap: wrap;
  margin-top: var(--space-2);
}

.snippet-block {
  margin-top: var(--space-2);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: var(--space-2);
  font-size: 0.76rem;
  overflow-x: auto;
  white-space: pre;
  color: var(--accent-text);
}

.flag-btn {
  background: transparent;
  border: none;
  color: var(--text-faint);
  cursor: pointer;
  font-size: 0.95rem;
  line-height: 1;
  padding: 2px 4px;
  border-radius: var(--radius-sm);
}

.flag-btn:hover, .flag-btn.is-flagged {
  color: var(--accent-text);
  background: var(--accent-soft);
}

.placeholder-panel {
  padding: var(--space-6) var(--space-4);
  text-align: center;
  color: var(--text-dim);
}

.placeholder-panel h2 {
  justify-content: center;
  color: var(--text);
}
