/* ==========================================================================
   Resbit — Production styles
   Design system: warm light default + dark mode via [data-theme]; TBD shell
   (240px sidebar / 60px topbar) with Resbit brand (green + terracotta).
   ========================================================================== */

/* ============================================================
   Resbit App Shell — modeled on the TBD ecosystem shell
   (240px sidebar · 60px topbar · data-theme light/dark tokens)
   ============================================================ */
:root {
  --brand: #2F5D50;           /* Resbit green */
  --brand-hover: #234A40;
  --accent: #C96F4A;          /* terracotta */
  --accent-soft: #F3E2D8;
  --good: #2E7D4F;
  --warn: #B98A2E;
  --danger: #B3402A;

  --bg: #FAF6F0;
  --surface-1: #FFFFFF;
  --surface-2: #F4EEE5;
  --surface-3: #EDE5D8;
  --border-subtle: #E5DDD2;
  --border-default: #D5CBBC;

  --text-primary: #29241E;
  --text-secondary: #5A5248;
  --text-muted: #8A8072;
  --text-on-brand: #FFFFFF;

  --good-bg: #E4EFE7; --warn-bg: #F5EED9; --danger-bg: #F6E2DC;

  --sidebar-width: 240px;
  --topbar-height: 60px;
  --radius-sm: 6px; --radius-md: 10px; --radius-lg: 14px;
  --shadow-md: 0 4px 12px rgba(60,45,30,.08);
  --shadow-lg: 0 12px 32px rgba(60,45,30,.14);
  --font-display: Georgia, 'Times New Roman', serif;
  --font-body: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --transition: 160ms cubic-bezier(.4,0,.2,1);
}
[data-theme="dark"] {
  --brand: #7FB5A5;
  --brand-hover: #9CCABC;
  --accent: #E08D66;
  --accent-soft: #3A2A22;
  --good: #7FBE97; --warn: #D9B15E; --danger: #E08872;

  --bg: #121815;
  --surface-1: #1A211D;
  --surface-2: #212925;
  --surface-3: #2A332E;
  --border-subtle: #2A332E;
  --border-default: #3A453F;

  --text-primary: #F2EEE7;
  --text-secondary: #C9C2B6;
  --text-muted: #8F887B;
  --text-on-brand: #121815;

  --good-bg: #1E2E25; --warn-bg: #2E2818; --danger-bg: #321E17;
  --shadow-md: 0 4px 12px rgba(0,0,0,.35);
  --shadow-lg: 0 12px 32px rgba(0,0,0,.5);
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
  font-family: var(--font-body); background: var(--bg); color: var(--text-primary);
  font-size: 15px; line-height: 1.5; -webkit-font-smoothing: antialiased;
}
button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; border-radius: 2px; }
[hidden] { display: none !important; }

/* ---------- shell ---------- */
.app-shell { display: grid; grid-template-columns: var(--sidebar-width) 1fr; min-height: 100vh; }
.sidebar {
  background: var(--surface-1); border-right: 1px solid var(--border-subtle);
  display: flex; flex-direction: column; padding: 20px 12px;
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.sidebar-brand {
  display: flex; align-items: center; gap: 12px;
  padding: 0 12px 20px; border-bottom: 1px solid var(--border-subtle); margin-bottom: 16px;
}
.brand-mark {
  width: 36px; height: 36px; border-radius: var(--radius-md);
  background: var(--brand); color: var(--text-on-brand);
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-display); font-weight: 700; font-size: 15px;
}
.brand-text { font-family: var(--font-display); font-size: 19px; font-weight: 700; }
.brand-text .accent { color: var(--accent); }
.nav { flex: 1; display: flex; flex-direction: column; gap: 2px; }
.nav-label { font-size: 11px; letter-spacing: 1.2px; text-transform: uppercase; color: var(--text-muted); padding: 14px 12px 6px; }
.nav-item {
  display: flex; align-items: center; gap: 10px; padding: 9px 12px;
  border-radius: var(--radius-sm); color: var(--text-secondary); font-size: 14px;
  text-align: left; width: 100%; transition: background var(--transition), color var(--transition);
}
.nav-item:hover { background: var(--surface-2); color: var(--text-primary); }
.nav-item.active { background: var(--surface-2); color: var(--brand); font-weight: 600; }
.nav-item .ico { width: 20px; text-align: center; font-size: 15px; }
.nav-item .pill { margin-left: auto; font-size: 11px; font-weight: 700; background: var(--accent); color: #fff; border-radius: 999px; padding: 1px 7px; }
.sidebar-footer { border-top: 1px solid var(--border-subtle); padding-top: 12px; }
.user-chip { display: flex; align-items: center; gap: 10px; padding: 8px 12px; }
.user-avatar {
  width: 32px; height: 32px; border-radius: 50%; background: var(--accent-soft); color: var(--accent);
  display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 13px;
}
.user-meta .name { font-size: 13.5px; font-weight: 600; }
.user-meta .org { font-size: 12px; color: var(--text-muted); }

/* ---------- topbar ---------- */
.main { display: flex; flex-direction: column; min-width: 0; }
.topbar {
  height: var(--topbar-height); display: flex; align-items: center; justify-content: space-between;
  padding: 0 24px; border-bottom: 1px solid var(--border-subtle);
  background: var(--surface-1); position: sticky; top: 0; z-index: 40;
}
.view-title { font-family: var(--font-display); font-size: 20px; font-weight: 700; }
.topbar-right { display: flex; align-items: center; gap: 8px; }
.icon-btn {
  width: 36px; height: 36px; border-radius: var(--radius-sm); display: flex; align-items: center;
  justify-content: center; color: var(--text-secondary); font-size: 16px; position: relative;
  transition: background var(--transition);
}
.icon-btn:hover { background: var(--surface-2); color: var(--text-primary); }
.icon-btn .badge {
  position: absolute; top: 4px; right: 4px; width: 15px; height: 15px; border-radius: 50%;
  background: var(--accent); color: #fff; font-size: 9.5px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
}
.btn-speedrun {
  display: flex; align-items: center; gap: 7px; font-size: 13px; font-weight: 600;
  padding: 7px 14px; border-radius: 999px; color: var(--accent);
  border: 1.5px solid var(--accent); transition: background var(--transition);
}
.btn-speedrun:hover { background: var(--accent-soft); }

/* ---------- views ---------- */
.view-container { padding: 26px 28px 60px; max-width: 1080px; width: 100%; margin: 0 auto; }
.grid-tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; margin-bottom: 22px; }
.hero-tile, .stat-tile {
  background: var(--surface-1); border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg); padding: 18px 20px;
}
.hero-tile { grid-column: 1 / -1; display: flex; align-items: baseline; gap: 16px; flex-wrap: wrap; }
.hero-tile .value { font-size: 48px; font-weight: 600; letter-spacing: -1px; }
.hero-tile .label { font-size: 14px; color: var(--text-secondary); max-width: 340px; }
.stat-tile .label { font-size: 13px; color: var(--text-secondary); margin-bottom: 4px; }
.stat-tile .value { font-size: 26px; font-weight: 600; }
.stat-tile .delta { font-size: 12.5px; margin-top: 2px; color: var(--text-muted); }

.card {
  background: var(--surface-1); border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg); padding: 20px 22px; margin-bottom: 16px;
}
.card h3 { font-family: var(--font-display); font-size: 17px; margin-bottom: 12px; }
.card h3 .sub { font-family: var(--font-body); font-size: 12.5px; font-weight: 400; color: var(--text-muted); margin-left: 8px; }

.feed-item {
  display: flex; gap: 12px; padding: 11px 0; border-bottom: 1px solid var(--border-subtle);
  font-size: 14px; align-items: flex-start;
}
.feed-item:last-child { border-bottom: none; }
.feed-item .time { color: var(--text-muted); font-size: 12.5px; min-width: 62px; padding-top: 2px; }
.feed-item .what { flex: 1; }
.feed-item .what .who { font-weight: 600; }
.feed-item .what .did { color: var(--text-secondary); }

.badge-t { display: inline-flex; align-items: center; gap: 5px; font-size: 11.5px; font-weight: 700; padding: 3px 9px; border-radius: 999px; white-space: nowrap; }
.badge-t.handled { background: var(--good-bg); color: var(--good); }
.badge-t.options { background: var(--warn-bg); color: var(--warn); }
.badge-t.escalated { background: var(--danger-bg); color: var(--danger); }
.badge-t.neutral { background: var(--surface-2); color: var(--text-secondary); }

.decision {
  border: 1.5px solid var(--accent); border-radius: var(--radius-md);
  padding: 14px 16px; margin-bottom: 10px; background: var(--surface-1);
}
.decision .q { font-weight: 600; margin-bottom: 8px; }
.decision .row { display: flex; gap: 8px; flex-wrap: wrap; }
.btn { font-size: 13.5px; font-weight: 600; padding: 8px 16px; border-radius: var(--radius-sm); transition: background var(--transition); }
.btn-primary { background: var(--brand); color: var(--text-on-brand); }
.btn-primary:hover { background: var(--brand-hover); }
.btn-ghost { border: 1px solid var(--border-default); color: var(--text-secondary); }
.btn-ghost:hover { background: var(--surface-2); }

table.data { width: 100%; border-collapse: collapse; font-size: 14px; }
table.data th { text-align: left; font-size: 12px; letter-spacing: .6px; text-transform: uppercase; color: var(--text-muted); padding: 8px 10px; border-bottom: 1px solid var(--border-default); }
table.data td { padding: 10px; border-bottom: 1px solid var(--border-subtle); vertical-align: top; }
table.data tr:last-child td { border-bottom: none; }
table.data .num { font-variant-numeric: tabular-nums; }

.prog { margin-bottom: 12px; padding: 14px 16px; border: 1px solid var(--border-subtle); border-radius: var(--radius-md); background: var(--surface-1); }
.prog .top { display: flex; justify-content: space-between; gap: 10px; align-items: baseline; flex-wrap: wrap; }
.prog .name { font-weight: 600; }
.prog .amt { font-weight: 600; color: var(--brand); }
.prog .next { font-size: 13px; color: var(--text-secondary); margin-top: 6px; }
.prog .next b { color: var(--accent); }

.playbook-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 14px; }
.playbook {
  background: var(--surface-1); border: 1px solid var(--border-subtle); border-radius: var(--radius-lg);
  padding: 18px; display: flex; flex-direction: column; gap: 8px;
}
.playbook .t { font-family: var(--font-display); font-size: 16px; font-weight: 700; }
.playbook .d { font-size: 13px; color: var(--text-secondary); flex: 1; }

.auth-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 10px; }
.auth-cell { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 10px 12px; border: 1px solid var(--border-subtle); border-radius: var(--radius-sm); font-size: 13.5px; background: var(--surface-1); }

/* ---------- AI help drawer ---------- */
.drawer {
  position: fixed; top: 0; right: 0; height: 100vh; width: 360px; max-width: 92vw;
  background: var(--surface-1); border-left: 1px solid var(--border-subtle);
  box-shadow: var(--shadow-lg); z-index: 90; display: flex; flex-direction: column;
  transform: translateX(100%); transition: transform 240ms cubic-bezier(.4,0,.2,1);
}
.drawer.open { transform: translateX(0); }
.drawer-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 18px; border-bottom: 1px solid var(--border-subtle); }
.drawer-head .t { font-family: var(--font-display); font-size: 17px; font-weight: 700; }
.drawer-body { flex: 1; overflow-y: auto; padding: 16px 18px; display: flex; flex-direction: column; gap: 10px; }
.msg { max-width: 88%; padding: 10px 13px; border-radius: var(--radius-md); font-size: 13.5px; line-height: 1.45; }
.msg.ai { background: var(--surface-2); align-self: flex-start; border-bottom-left-radius: 3px; }
.msg.me { background: var(--brand); color: var(--text-on-brand); align-self: flex-end; border-bottom-right-radius: 3px; }
.drawer-foot { display: flex; gap: 8px; padding: 12px 14px; border-top: 1px solid var(--border-subtle); }
.drawer-foot input { flex: 1; font-size: 14px; padding: 10px 12px; border: 1px solid var(--border-default); border-radius: var(--radius-sm); background: var(--surface-1); color: var(--text-primary); font-family: inherit; }

/* ---------- speedrun ---------- */
.sr-dim { position: fixed; inset: 0; z-index: 100; display: none; }
.sr-dim.on { display: block; }
.sr-spot {
  position: absolute; border-radius: 10px; border: 2px solid var(--accent);
  box-shadow: 0 0 0 9999px rgba(20,16,12,.62); transition: all 280ms cubic-bezier(.4,0,.2,1);
  pointer-events: none;
}
.sr-card {
  position: fixed; left: 50%; bottom: 34px; transform: translateX(-50%);
  width: min(560px, 92vw); background: var(--surface-1); color: var(--text-primary);
  border: 1px solid var(--border-default); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg); padding: 18px 20px; z-index: 101;
}
.sr-card .beat { font-size: 11px; letter-spacing: 1.2px; text-transform: uppercase; color: var(--accent); font-weight: 700; margin-bottom: 5px; }
.sr-card .cap { font-family: var(--font-display); font-size: 19px; font-weight: 700; margin-bottom: 5px; line-height: 1.3; }
.sr-card .vo { font-size: 13.5px; color: var(--text-secondary); margin-bottom: 13px; }
.sr-card .row { display: flex; justify-content: space-between; align-items: center; }
.sr-dots { display: flex; gap: 5px; }
.sr-dots i { width: 7px; height: 7px; border-radius: 50%; background: var(--border-default); }
.sr-dots i.on { background: var(--accent); }

/* ---------- toast ---------- */
.toast-container { position: fixed; bottom: 22px; right: 22px; z-index: 120; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: var(--surface-1); border: 1px solid var(--border-default); border-left: 3px solid var(--brand);
  border-radius: var(--radius-md); box-shadow: var(--shadow-md); padding: 12px 16px; font-size: 13.5px;
  animation: slideIn .25s ease;
}
@keyframes slideIn { from { transform: translateX(30px); opacity: 0; } to { transform: none; opacity: 1; } }

@media (max-width: 860px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { display: none; }
}

/* ---------- auth gate (TBD pattern) ---------- */
.auth-gate {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  padding: 24px;
  background: radial-gradient(at 20% 30%, rgba(201,111,74,0.08), transparent 50%),
              radial-gradient(at 80% 70%, rgba(47,93,80,0.07), transparent 50%), var(--bg);
}
.auth-card {
  background: var(--surface-1); border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg); padding: 40px; max-width: 420px; width: 100%;
  box-shadow: var(--shadow-lg);
}
.auth-logo { font-family: var(--font-display); font-size: 26px; font-weight: 700; margin-bottom: 6px; }
.auth-logo .accent { color: var(--accent); }
.auth-tagline { color: var(--text-secondary); font-size: 14px; margin-bottom: 24px; }
.auth-input {
  width: 100%; font-size: 14px; padding: 11px 13px; margin-bottom: 8px;
  border: 1px solid var(--border-default); border-radius: var(--radius-sm);
  background: var(--surface-1); color: var(--text-primary); font-family: inherit;
}
.loading { padding: 60px 0; text-align: center; color: var(--text-muted); }
.empty-state { padding: 60px 0; text-align: center; color: var(--text-secondary); }
.empty-state h2 { font-family: var(--font-display); margin-bottom: 10px; color: var(--text-primary); }
.toast-success { border-left-color: var(--good); }
.toast-error { border-left-color: var(--danger); }
.sidebar-footer .signout { width: 100%; margin-top: 8px; padding: 8px 12px; border: 1px solid var(--border-subtle); border-radius: 6px; color: var(--danger); font-size: 13px; text-align: left; }

/* ---------- QuickForm modal ---------- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(20,16,12,.55); z-index: 200;
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.modal-card {
  background: var(--surface-1); color: var(--text-primary);
  border: 1px solid var(--border-default); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg); padding: 22px 24px; width: min(480px, 94vw);
  max-height: 86vh; overflow-y: auto;
}
.row-actions { display: flex; gap: 6px; }
.row-edit {
  font-size: 12px; color: var(--text-muted); border: 1px solid var(--border-subtle);
  border-radius: 6px; padding: 3px 9px;
}
.row-edit:hover { color: var(--text-primary); background: var(--surface-2); }
.empty-live { color: var(--text-muted); font-size: 14px; padding: 8px 0; }
.add-btn { margin-top: 10px; font-size: 13.5px; font-weight: 600; color: var(--brand); border: 1px dashed var(--border-default); border-radius: 8px; padding: 8px 14px; }
.add-btn:hover { background: var(--surface-2); }
