/* ============================================================
   Prep — shared stylesheet
   Dark theme · left sidebar layout · shared components
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Fraunces:ital,opsz,wght@0,9..144,400;0,9..144,500;0,9..144,600;1,9..144,400;1,9..144,500&display=swap');

:root {
  --bg:          #181818;
  --surface:     #202020;
  --surface-2:   #2a2a2a;
  --sidebar-bg:  #1c1c1c;
  --border:      #2e2e2e;
  --border-soft: #242424;
  --text:        #e4e4e4;
  --text-muted:  #8a8a8a;
  --text-faint:  #4a4a4a;
  --gold:        #c9a35a;
  --gold-dim:    #5a4828;
  --gold-glow:   rgba(201,163,90,.10);
  --green:       #769656;
  --green-dim:   #3a4a2e;
  --green-glow:  rgba(118,150,86,.12);
  --red:         #c94f4f;
  --yellow:      #c8a84b;
  --blue:        #5b8dd9;
  --display-font: 'Fraunces', Georgia, 'Times New Roman', serif;
  --board-light: #b8a070;
  --board-dark:  #6b4f2a;
}

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

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--gold); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── App shell (sidebar + content) ──────────────────────── */

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

/* ── Sidebar ─────────────────────────────────────────────── */

.sidebar {
  width: 180px;
  flex-shrink: 0;
  position: fixed;
  top: 0; left: 0;
  height: 100vh;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 200;
}

.sidebar-brand {
  padding: 18px 18px 14px;
  border-bottom: 1px solid var(--border);
}

/* ── Wordmark ─────────────────────────────────────────────── */

.sidebar-wordmark {
  display: inline-flex;
  align-items: center;
  gap: 14px;
  color: var(--gold);           /* SVG inherits via currentColor */
  text-decoration: none;
}
.wm-glyph { flex-shrink: 0; display: block; }
.wm-glyph-sm { width: 22px; height: 26px; }
.wm-glyph-md { width: 32px; height: 38px; }
.wm-glyph-lg { width: 48px; height: 56px; }
.wm-text {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .24em;
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}
.wm-text-md { font-size: 22px; letter-spacing: .18em; }
.wm-text-lg { font-size: 28px; letter-spacing: .18em; }

.sidebar-nav {
  flex: 1;
  padding: 10px 8px;
  overflow-y: auto;
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 6px 12px;
  border-radius: 6px;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 400;
  text-decoration: none;
  transition: color .12s, background .12s;
  margin-bottom: 1px;
  position: relative;
}
.sidebar-link:hover {
  color: var(--text);
  background: rgba(255,255,255,.04);
  text-decoration: none;
}
.sidebar-link.active {
  color: var(--text);
  background: var(--gold-glow);
  font-weight: 500;
}
.sidebar-link.active .nav-icon { color: var(--gold); }

.sidebar-link .nav-badge {
  margin-left: auto;
  font-size: 10px;
  font-family: 'JetBrains Mono', 'Fira Mono', monospace;
  color: var(--gold);
  background: var(--gold-glow);
  border: 1px solid var(--gold-dim);
  padding: 1px 5px;
  border-radius: 8px;
}

.nav-icon {
  width: 15px;
  height: 15px;
  flex-shrink: 0;
  color: var(--text-faint);
  transition: color .12s;
}
.sidebar-link:hover .nav-icon { color: var(--text-muted); }

.sidebar-footer {
  padding: 10px 8px 16px;
  border-top: 1px solid var(--border);
}

.sidebar-logout {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 6px 12px;
  border-radius: 6px;
  color: var(--text-muted);
  font-size: 13px;
  text-decoration: none;
  transition: color .12s, background .12s;
}
.sidebar-logout:hover {
  color: var(--text);
  background: rgba(255,255,255,.04);
  text-decoration: none;
}
.sidebar-logout .nav-icon { color: var(--text-muted); }

.theme-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  margin: 0 12px 4px;
  border: none;
  background: none;
  color: var(--text-faint);
  font-size: 16px;
  cursor: pointer;
  border-radius: 6px;
  transition: color .12s, background .12s;
}
.theme-toggle:hover {
  color: var(--text-muted);
  background: rgba(255,255,255,.04);
}

/* ── Main content area ───────────────────────────────────── */

.main-content {
  margin-left: 180px;
  flex: 1;
  min-width: 0;
  min-height: 100vh;
}

/* ── Standard page layout ────────────────────────────────── */

.page {
  max-width: 1060px;
  margin: 0 auto;
  padding: 32px 28px 60px;
}

.page-wide {
  max-width: 1340px;
  margin: 0 auto;
  padding: 32px 28px 60px;
}

.page-header {
  margin-bottom: 28px;
}
.page-header h1 { margin-bottom: 4px; }
.page-header p  { color: var(--text-muted); font-size: 13px; margin: 0; }

/* ── Typography ─────────────────────────────────────────── */

h1 { font-size: 20px; font-weight: 600; color: var(--text); }
h2 { font-size: 16px; font-weight: 600; color: var(--text); margin-bottom: 10px; }
h3 {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: .07em;
  margin-bottom: 10px;
}

p { margin-bottom: 12px; }

.mono {
  font-family: 'JetBrains Mono', 'Fira Mono', 'Cascadia Code', monospace;
  font-size: 13px;
}

/* ── Layout helpers ──────────────────────────────────────── */

.row     { display: flex; gap: 20px; }
.col     { flex: 1; min-width: 0; }

/* ── Cards ───────────────────────────────────────────────── */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 18px 20px;
  margin-bottom: 14px;
}

.card-sm {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 12px 14px;
  margin-bottom: 10px;
}

/* ── Buttons ─────────────────────────────────────────────── */

button, .btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  transition: background .12s, border-color .12s;
  white-space: nowrap;
  line-height: 1;
}
button:hover, .btn:hover { background: var(--border); }
button:disabled, .btn:disabled { opacity: .4; cursor: not-allowed; }

.btn-primary {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: 6px;
  border: 1px solid var(--gold);
  background: var(--gold);
  color: #fff;
  font-size: 13px;
  font-family: inherit;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  line-height: 1;
  text-decoration: none;
  transition: background .12s, border-color .12s;
}
.btn-primary:hover { background: #b8923f; border-color: #b8923f; }
.btn-primary:disabled { background: var(--gold-dim); border-color: var(--gold-dim); }

.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--text-muted);
}
.btn-ghost:hover { background: var(--surface-2); color: var(--text); border-color: var(--border); }

.btn-danger {
  background: transparent;
  border-color: var(--red);
  color: var(--red);
}
.btn-danger:hover { background: rgba(201,79,79,.1); }

.btn-sm { padding: 4px 9px; font-size: 12px; border-radius: 5px; }
.w-full  { width: 100%; justify-content: center; }

/* ── Inputs ──────────────────────────────────────────────── */

input[type="text"],
input[type="number"],
input[type="date"],
select,
textarea {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-family: inherit;
  font-size: 13px;
  padding: 7px 10px;
  width: 100%;
  outline: none;
  transition: border-color .15s;
  -webkit-appearance: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--gold); }
textarea { resize: vertical; min-height: 80px; }
select option { background: var(--surface); }

.field { margin-bottom: 14px; }
.field label {
  display: block;
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 5px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: .04em;
}
.field-row {
  display: flex;
  gap: 10px;
  align-items: flex-end;
}
.field-row .field { margin-bottom: 0; flex: 1; }

/* ── Tables ──────────────────────────────────────────────── */

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th {
  text-align: left;
  padding: 8px 10px;
  color: var(--text-muted);
  font-weight: 500;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .05em;
  border-bottom: 1px solid var(--border);
}
td { padding: 9px 10px; border-bottom: 1px solid var(--border-soft); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--surface-2); }

/* ── Badges ──────────────────────────────────────────────── */

.badge {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 500;
  white-space: nowrap;
}
.badge-green  { background: var(--green-glow); color: var(--green); border: 1px solid var(--green-dim); }
.badge-red    { background: rgba(201,79,79,.1); color: var(--red);   border: 1px solid rgba(201,79,79,.25); }
.badge-yellow { background: rgba(200,168,75,.1);color: var(--yellow);border: 1px solid rgba(200,168,75,.25); }
.badge-gray   { background: var(--surface-2);  color: var(--text-muted); border: 1px solid var(--border); }

/* ── Alerts ──────────────────────────────────────────────── */

.alert { padding: 10px 14px; border-radius: 6px; font-size: 13px; margin-bottom: 14px; }
.alert-error   { background: rgba(201,79,79,.1); border: 1px solid rgba(201,79,79,.25); color: #e08080; }
.alert-success { background: var(--green-glow);  border: 1px solid var(--green-dim);    color: var(--green); }
.alert-info    { background: rgba(91,141,217,.08);border: 1px solid rgba(91,141,217,.25);color: var(--blue); }

/* ── Loading / empty ─────────────────────────────────────── */

.loading {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text-muted);
  padding: 32px 0;
  justify-content: center;
  font-size: 13px;
}

.spinner {
  width: 15px; height: 15px;
  border: 2px solid var(--border);
  border-top-color: var(--gold);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }

.empty {
  text-align: center;
  padding: 48px 20px;
  color: var(--text-muted);
}
.empty-icon { font-size: 28px; margin-bottom: 12px; opacity: .4; }
.empty p    { margin: 4px 0; font-size: 13px; }
.empty .hint { color: var(--text-faint); font-size: 12px; }

/* ── Stat boxes ──────────────────────────────────────────── */

.stats-row {
  display: flex;
  gap: 10px;
  margin-bottom: 20px;
}
.stat-box {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px 16px;
  text-align: center;
}
.stat-box .stat-value {
  font-size: 24px;
  font-weight: 700;
  color: var(--text);
  line-height: 1;
  margin-bottom: 4px;
}
.stat-box .stat-label {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .05em;
}

/* ── Progress bar ────────────────────────────────────────── */

.progress-bar { height: 4px; background: var(--surface-2); border-radius: 2px; overflow: hidden; }
.progress-bar-fill { height: 100%; background: var(--gold); border-radius: 2px; transition: width .3s ease; }

/* ── Section head ────────────────────────────────────────── */

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}
.section-head-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--text-faint);
}
.section-head-meta {
  font-size: 11px;
  color: var(--text-muted);
  font-family: 'JetBrains Mono', 'Fira Mono', monospace;
}

/* ── Section title (legacy) ──────────────────────────────── */

.section-title {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--text-faint);
  margin: 22px 0 10px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}

/* ── Scroll panel ────────────────────────────────────────── */

.scroll-panel {
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
}

/* ── Utilities ───────────────────────────────────────────── */

.text-muted   { color: var(--text-muted); }
.text-faint   { color: var(--text-faint); }
.text-gold    { color: var(--gold); }
.text-green   { color: var(--green); }
.text-red     { color: var(--red); }
.text-yellow  { color: var(--yellow); }
.flex         { display: flex; }
.flex-center  { display: flex; align-items: center; }
.gap-8        { gap: 8px; }
.gap-12       { gap: 12px; }
.mt-8         { margin-top: 8px; }
.mt-16        { margin-top: 16px; }
.mt-24        { margin-top: 24px; }
.mb-0         { margin-bottom: 0 !important; }
.text-right   { text-align: right; }
.nowrap       { white-space: nowrap; }
.hidden       { display: none !important; }

/* ── Light mode ──────────────────────────────────────────── */

[data-theme="light"] {
  --bg:          #faf9f6;
  --surface:     #ffffff;
  --surface-2:   #f1efe9;
  --sidebar-bg:  #f4f2ec;
  --border:      #e4e1d8;
  --border-soft: #ece9e0;
  --text:        #2a2825;
  --text-muted:  #7a7670;
  --text-faint:  #b5b0a5;
  --gold:        #8a6a22;
  --gold-dim:    #d4c088;
  --gold-glow:   rgba(138,106,34,.08);
  --green:       #4d6b38;
  --green-dim:   #c8d8bc;
  --green-glow:  rgba(77,107,56,.10);
  --red:         #b23b3b;
  --yellow:      #a37c1b;
  --blue:        #3f6bb8;
  --board-light: #e8d9b2;
  --board-dark:  #a88a5c;
}

/* ── Mobile topbar & backdrop ────────────────────────────── */

.mobile-topbar   { display: none; }
.sidebar-backdrop { display: none; }

/* ── Bottom tab bar ──────────────────────────────────────── */

.tab-bar { display: none; }

/* ── Mobile ──────────────────────────────────────────────── */

@media (max-width: 768px) {

  /* Top bar — wordmark only */
  .mobile-topbar {
    display: flex;
    align-items: center;
    padding: 0 16px;
    position: fixed;
    top: 0; left: 0; right: 0;
    height: 48px;
    background: var(--sidebar-bg);
    border-bottom: 1px solid var(--border);
    z-index: 300;
  }

  /* Sidebar overlay */
  .sidebar {
    transform: translateX(-100%);
    transition: transform .25s ease;
    z-index: 400;
    width: 220px;
    overflow-y: auto;
  }
  .sidebar.open { transform: translateX(0); }

  /* Let sidebar flow as one scrollable column — nav must not eat all height */
  .sidebar-nav {
    flex: none;
    overflow-y: visible;
  }

  /* Backdrop */
  .sidebar-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.6);
    z-index: 350;
    opacity: 0;
    pointer-events: none;
    transition: opacity .25s ease;
  }
  .sidebar-backdrop.open {
    opacity: 1;
    pointer-events: auto;
  }

  /* Content area */
  .main-content {
    margin-left: 0;
    padding-top: 48px;
    padding-bottom: 60px; /* above tab bar */
  }

  /* ── Bottom tab bar ────────────────────────────────────── */

  .tab-bar {
    display: flex;
    position: fixed;
    bottom: 0; left: 0; right: 0;
    height: 56px;
    padding-bottom: env(safe-area-inset-bottom);
    background: var(--sidebar-bg);
    border-top: 1px solid var(--border);
    z-index: 300;
  }

  .tab-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    color: var(--text-faint);
    text-decoration: none;
    font-size: 10px;
    font-weight: 500;
    letter-spacing: .02em;
    border: none;
    background: none;
    cursor: pointer;
    padding: 6px 2px;
    position: relative;
    transition: color .12s;
    font-family: inherit;
    -webkit-tap-highlight-color: transparent;
  }
  .tab-item svg { width: 20px; height: 20px; flex-shrink: 0; }
  .tab-item.active { color: var(--gold); }
  .tab-item:not(.active):hover { color: var(--text-muted); text-decoration: none; }
  .tab-item:hover { text-decoration: none; }

  .tab-badge {
    position: absolute;
    top: 5px;
    left: 50%;
    transform: translateX(6px);
    background: var(--gold);
    color: #1a1200;
    font-size: 9px;
    font-weight: 700;
    font-family: 'JetBrains Mono', monospace;
    padding: 1px 4px;
    border-radius: 8px;
    min-width: 14px;
    text-align: center;
    line-height: 1.5;
  }
}
