/* ── Variables ────────────────────────────────────────────────────────────── */
:root {
  --bg:       #0f1117;
  --surface:  #1a1f2e;
  --surface2: #252d3d;
  --border:   #2d3748;
  --text:     #e2e8f0;
  --muted:    #718096;
  --accent:   #3b82f6;
  --green:    #22c55e;
  --yellow:   #f59e0b;
  --red:      #ef4444;
  --nav-w:    200px;
  --nav-h:    60px;
}

/* ── Reset ───────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}
a { color: var(--accent); text-decoration: none; }
h1, h2, h3 { font-weight: 600; line-height: 1.3; }
h2 { font-size: 1.1rem; }
h3 { font-size: 1rem; }

/* ── Sidebar (desktop) ───────────────────────────────────────────────────── */
.sidebar {
  display: none;
  position: fixed;
  top: 0; left: 0;
  width: var(--nav-w);
  height: 100vh;
  background: var(--surface);
  border-right: 1px solid var(--border);
  flex-direction: column;
  padding: 1rem 0;
  z-index: 100;
  overflow-y: auto;
}

.brand {
  font-size: 1.1rem;
  font-weight: 700;
  padding: .75rem 1.25rem 1.25rem;
  color: var(--text);
  letter-spacing: .02em;
}

/* ── Bottom nav (mobile) ─────────────────────────────────────────────────── */
.bottom-nav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: var(--nav-h);
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  z-index: 100;
  padding-bottom: env(safe-area-inset-bottom);
}

/* ── Nav items ───────────────────────────────────────────────────────────── */
.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  padding: .4rem .25rem;
  color: var(--muted);
  font-size: .65rem;
  text-decoration: none;
  gap: 2px;
  transition: color .15s;
}
.nav-item:hover { color: var(--text); }
.nav-item.active { color: var(--accent); }
.nav-icon { font-size: 1.1rem; line-height: 1; }
.nav-label { font-size: .6rem; }

/* ── Main content ────────────────────────────────────────────────────────── */
.main {
  padding-bottom: calc(var(--nav-h) + 1rem + env(safe-area-inset-bottom));
}

.page-hdr {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1rem .5rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  position: sticky;
  top: 0;
  z-index: 50;
}
.page-title { font-size: 1.15rem; }
.clock { font-size: .8rem; color: var(--muted); font-variant-numeric: tabular-nums; }

.content { padding: 1rem; }

/* ── Desktop layout ──────────────────────────────────────────────────────── */
@media (min-width: 768px) {
  .sidebar { display: flex; }
  .bottom-nav { display: none; }
  .main { margin-left: var(--nav-w); }

  .sidebar .nav-item {
    flex-direction: row;
    width: 100%;
    flex: none;
    padding: .6rem 1.25rem;
    gap: .6rem;
    font-size: .875rem;
    border-radius: 0;
  }
  .sidebar .nav-icon { font-size: .9rem; }
  .sidebar .nav-label { font-size: .875rem; }

  .content { padding: 1.5rem; max-width: 1100px; }
}

/* ── Card ────────────────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: .5rem;
  padding: 1rem;
}
.card + .card { margin-top: .75rem; }

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: .75rem;
}

.card-label {
  font-size: .7rem;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--muted);
  margin-bottom: .25rem;
}
.card-value {
  font-size: 1.6rem;
  font-weight: 700;
  line-height: 1.2;
  font-variant-numeric: tabular-nums;
}
.card-sub { font-size: .8rem; color: var(--muted); margin-top: .2rem; }

/* ── Status dot ──────────────────────────────────────────────────────────── */
.dot {
  display: inline-block;
  width: 8px; height: 8px;
  border-radius: 50%;
  margin-right: .4rem;
  flex-shrink: 0;
}
.dot-green  { background: var(--green); box-shadow: 0 0 6px var(--green); }
.dot-yellow { background: var(--yellow); }
.dot-red    { background: var(--red); box-shadow: 0 0 6px var(--red); }
.dot-gray   { background: var(--muted); }

.status-row {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .5rem 0;
  border-bottom: 1px solid var(--border);
}
.status-row:last-child { border-bottom: none; }
.status-label { font-weight: 500; flex: 1; }
.status-detail { font-size: .8rem; color: var(--muted); }

/* ── Progress bars ───────────────────────────────────────────────────────── */
.progress-group { display: flex; flex-direction: column; gap: 1rem; }

.prog-item { }
.prog-header {
  display: flex;
  justify-content: space-between;
  font-size: .85rem;
  margin-bottom: .3rem;
}
.prog-name { font-weight: 600; }
.prog-vals { color: var(--muted); font-variant-numeric: tabular-nums; }

.prog-bar {
  height: 8px;
  background: var(--surface2);
  border-radius: 4px;
  overflow: hidden;
}
.prog-fill {
  height: 100%;
  border-radius: 4px;
  transition: width .3s ease;
}
.prog-fill.ok     { background: var(--green); }
.prog-fill.warn   { background: var(--yellow); }
.prog-fill.danger { background: var(--red); }

/* ── Badges ──────────────────────────────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: .15rem .45rem;
  border-radius: .25rem;
  font-size: .7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
}
.badge-product  { background: #1e3a5f; color: #60a5fa; }
.badge-email    { background: #1a3a2a; color: #4ade80; }
.badge-social   { background: #3a1a3a; color: #c084fc; }
.badge-purchase { background: #3a2a1a; color: #fb923c; }
.badge-decision { background: #3a3a1a; color: #facc15; }
.badge-other    { background: var(--surface2); color: var(--muted); }
.badge-approved { background: #1a3a2a; color: var(--green); }
.badge-rejected { background: #3a1a1a; color: var(--red); }
.badge-pending  { background: #3a2a1a; color: var(--yellow); }
.badge-urgent   { background: #5a1a1a; color: var(--red); }
.badge-high     { background: #3a2a1a; color: var(--yellow); }
.badge-warn     { background: var(--yellow); color: #000; }
.badge-count    { background: var(--accent); color: #fff; border-radius: 9999px; padding: .1rem .5rem; }

/* ── Buttons ─────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  padding: .4rem .85rem;
  border-radius: .375rem;
  border: none;
  font-size: .875rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity .15s, filter .15s;
}
.btn:hover { filter: brightness(1.1); }
.btn:active { filter: brightness(.9); }
.btn:disabled { opacity: .45; cursor: not-allowed; }

.btn-approve { background: var(--green); color: #000; }
.btn-reject  { background: var(--red);   color: #fff; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-ghost   { background: var(--surface2); color: var(--text); }
.btn-lg      { padding: .6rem 1.25rem; font-size: 1rem; }

/* ── Table ───────────────────────────────────────────────────────────────── */
.tbl-wrap { overflow-x: auto; }
table {
  width: 100%;
  border-collapse: collapse;
  font-size: .85rem;
}
th {
  text-align: left;
  font-size: .7rem;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted);
  padding: .4rem .5rem;
  border-bottom: 1px solid var(--border);
}
td {
  padding: .5rem .5rem;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
tr:last-child td { border-bottom: none; }
.mono { font-family: 'SF Mono', 'Cascadia Code', monospace; font-size: .8rem; }

/* ── Approval item ───────────────────────────────────────────────────────── */
.approval-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: .5rem;
  padding: 1rem;
  margin-bottom: .75rem;
}
.approval-item-hdr {
  display: flex;
  align-items: flex-start;
  gap: .5rem;
  margin-bottom: .5rem;
  flex-wrap: wrap;
}
.approval-title { font-weight: 600; flex: 1; min-width: 0; word-break: break-word; }
.approval-preview { color: var(--muted); font-size: .85rem; margin-bottom: .75rem; white-space: pre-wrap; word-break: break-word; }
.approval-meta { font-size: .75rem; color: var(--muted); margin-bottom: .75rem; }
.approval-actions { display: flex; gap: .5rem; flex-wrap: wrap; }

/* ── Section header ──────────────────────────────────────────────────────── */
.section-hdr {
  font-size: 1rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .07em;
  margin: 1.5rem 0 .75rem;
  display: flex;
  align-items: center;
  gap: .5rem;
}

/* ── Chart ───────────────────────────────────────────────────────────────── */
.chart-card { margin-top: 1rem; }
.chart-wrap { position: relative; height: 200px; }
@media (min-width: 768px) { .chart-wrap { height: 280px; } }

/* ── Tabs ────────────────────────────────────────────────────────────────── */
.tabs {
  display: flex;
  gap: .25rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
  border-bottom: 1px solid var(--border);
  padding-bottom: .5rem;
}
.tab-btn {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--muted);
  padding: .4rem .9rem;
  border-radius: .375rem;
  font-size: .85rem;
  cursor: pointer;
  transition: background .15s, color .15s;
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.tab-panel.hidden { display: none; }

/* ── Stage 5 banner ──────────────────────────────────────────────────────── */
.stage5-banner {
  background: linear-gradient(135deg, #1a2a3a, #1a3a2a);
  border-color: var(--green);
  margin-bottom: 1.25rem;
  font-size: .95rem;
}
.stage5-done { color: var(--green); font-weight: 600; }

/* ── Markdown body ───────────────────────────────────────────────────────── */
.md-body { font-size: .9rem; line-height: 1.7; }
.md-body h1 { font-size: 1.4rem; margin: 1.2rem 0 .5rem; }
.md-body h2 { font-size: 1.15rem; margin: 1.1rem 0 .4rem; padding-bottom: .3rem; border-bottom: 1px solid var(--border); }
.md-body h3 { font-size: 1rem; margin: .9rem 0 .3rem; }
.md-body p  { margin-bottom: .75rem; }
.md-body ul, .md-body ol { margin: .5rem 0 .75rem 1.5rem; }
.md-body li { margin-bottom: .25rem; }
.md-body code {
  background: var(--surface2);
  padding: .1rem .3rem;
  border-radius: .2rem;
  font-family: 'SF Mono', 'Cascadia Code', monospace;
  font-size: .85em;
}
.md-body pre {
  background: var(--surface2);
  padding: .75rem 1rem;
  border-radius: .375rem;
  overflow-x: auto;
  margin: .75rem 0;
}
.md-body pre code { background: none; padding: 0; }
.md-body table { margin: .75rem 0; }
.md-body blockquote {
  border-left: 3px solid var(--accent);
  padding-left: 1rem;
  color: var(--muted);
  margin: .75rem 0;
}
.md-body hr { border: none; border-top: 1px solid var(--border); margin: 1rem 0; }
.md-body strong { color: #fff; }
.md-body a { color: var(--accent); }

/* ── Memory browser ──────────────────────────────────────────────────────── */
.mem-layout {
  display: flex;
  flex-direction: column;
  gap: .75rem;
}
.mem-sidebar { min-width: 0; }
.mem-sidebar input[type="search"] {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: .4rem .6rem;
  border-radius: .375rem;
  font-size: .85rem;
  margin-bottom: .5rem;
  outline: none;
}
.mem-sidebar input[type="search"]:focus { border-color: var(--accent); }
.mem-file-list { display: flex; flex-direction: column; gap: .2rem; max-height: 250px; overflow-y: auto; }
.mem-link {
  display: block;
  padding: .3rem .4rem;
  border-radius: .25rem;
  font-size: .8rem;
  color: var(--muted);
  transition: background .1s, color .1s;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.mem-link:hover { background: var(--surface2); color: var(--text); }
.mem-link.active { background: var(--accent); color: #fff; }

@media (min-width: 768px) {
  .mem-layout { flex-direction: row; align-items: flex-start; }
  .mem-sidebar { width: 220px; flex-shrink: 0; position: sticky; top: 5rem; }
  .mem-file-list { max-height: calc(100vh - 200px); }
  .mem-body { flex: 1; min-width: 0; }
}

/* ── Reports select ──────────────────────────────────────────────────────── */
select {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: .4rem .6rem;
  border-radius: .375rem;
  font-size: .875rem;
  outline: none;
  cursor: pointer;
}
select:focus { border-color: var(--accent); }

/* ── Disk bar ────────────────────────────────────────────────────────────── */
.disk-bar {
  background: var(--surface2);
  height: 6px;
  border-radius: 3px;
  overflow: hidden;
  margin-top: .35rem;
}
.disk-fill { height: 100%; background: var(--accent); border-radius: 3px; transition: width .3s; }

/* ── Loading / misc ──────────────────────────────────────────────────────── */
.loading-text { color: var(--muted); font-size: .875rem; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.text-green { color: var(--green); }
.text-red   { color: var(--red); }
.text-yellow { color: var(--yellow); }
.mt1 { margin-top: .5rem; }
.mt2 { margin-top: 1rem; }
