/* Layout: fixed sidebar on desktop, top bar plus bottom tabs on phones. Content scrolls inside one main column. */
:root {
  --bg: #f4f6f5;
  --surface: #ffffff;
  --surface-2: #eef2f0;
  --line: #dde4e1;
  --fg: #16201c;
  --muted: #5d6b66;
  --accent: #1d6b57;
  --accent-fg: #ffffff;
  --accent-soft: #dcefe8;
  --good: #1a7f4b;   --good-soft: #dff3e8;
  --warn: #a15c00;   --warn-soft: #fbeccd;
  --bad: #b3261e;    --bad-soft: #fbe0dd;
  --info: #2457a6;   --info-soft: #e0e9f8;
  --radius: 8px;
  --font: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --display: 'Space Grotesk', 'Inter', system-ui, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1613; --surface: #17211d; --surface-2: #1e2b26; --line: #2b3a34; --fg: #e8efec; --muted: #9aaba4;
    --accent: #4fc4a2; --accent-fg: #06251c; --accent-soft: #1b3a31;
    --good: #5bd08e; --good-soft: #17352a; --warn: #f0b155; --warn-soft: #3a2c10;
    --bad: #ff8a80; --bad-soft: #3d1b18; --info: #8db7ff; --info-soft: #1a2c4a; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1613; --surface: #17211d; --surface-2: #1e2b26; --line: #2b3a34; --fg: #e8efec; --muted: #9aaba4;
  --accent: #4fc4a2; --accent-fg: #06251c; --accent-soft: #1b3a31;
  --good: #5bd08e; --good-soft: #17352a; --warn: #f0b155; --warn-soft: #3a2c10;
  --bad: #ff8a80; --bad-soft: #3d1b18; --info: #8db7ff; --info-soft: #1a2c4a; color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--fg); font: 14px/1.5 var(--font); -webkit-text-size-adjust: 100%; }
h1, h2, h3 { font-family: var(--display); margin: 0; line-height: 1.2; text-wrap: balance; }
h1 { font-size: 1.5rem; } h2 { font-size: 1.1rem; } h3 { font-size: .95rem; }
a { color: var(--accent); text-decoration: none; } a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); } .small { font-size: .8rem; } .right { text-align: right; }
.row { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; } .grow { flex: 1; min-width: 0; }
.stack { display: flex; flex-direction: column; gap: .75rem; }
.hide { display: none !important; }

/* Shell */
.shell { display: grid; grid-template-columns: 232px minmax(0, 1fr); min-height: 100%; }
.side { background: var(--surface); border-right: 1px solid var(--line); padding: 1rem .75rem; display: flex; flex-direction: column; gap: 1rem; position: sticky; top: 0; height: 100vh; }
.brand { font: 700 1.05rem var(--display); padding: .25rem .5rem; display: flex; gap: .5rem; align-items: center; }
.brand i { width: 22px; height: 22px; border-radius: 6px; background: var(--accent); display: inline-block; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a { padding: .5rem .65rem; border-radius: 6px; color: var(--fg); display: flex; justify-content: space-between; gap: .5rem; align-items: center; }
.nav a:hover { background: var(--surface-2); text-decoration: none; }
.nav a.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.me { margin-top: auto; border-top: 1px solid var(--line); padding-top: .75rem; display: flex; flex-direction: column; gap: .4rem; }
.topbar { display: none; }
main { padding: 1.25rem max(16px, env(safe-area-inset-right, 0px)) 3rem max(20px, env(safe-area-inset-left, 0px)); min-width: 0; max-width: 1400px; width: 100%; }
.head { display: flex; justify-content: space-between; align-items: flex-end; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.head p { margin: .2rem 0 0; color: var(--muted); }

/* Components */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; min-width: 0; }
.card > h2 { margin-bottom: .6rem; }
.grid { display: grid; gap: .9rem; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.kpis { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: .8rem .9rem; }
.kpi b { display: block; font: 600 1.55rem var(--display); margin-top: .1rem; font-variant-numeric: tabular-nums; }
.kpi span { color: var(--muted); font-size: .78rem; }
.kpi.bad b { color: var(--bad); } .kpi.warn b { color: var(--warn); }
.btn { border: 1px solid var(--line); background: var(--surface); border-radius: 6px; padding: .45rem .8rem; cursor: pointer; font-weight: 500; min-height: 36px; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--bad); }
.btn.sm { padding: .2rem .55rem; min-height: 30px; font-size: .82rem; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.pill { display: inline-block; padding: .08rem .5rem; border-radius: 99px; font-size: .74rem; font-weight: 600; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.pill.good { background: var(--good-soft); color: var(--good); } .pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.bad { background: var(--bad-soft); color: var(--bad); } .pill.info { background: var(--info-soft); color: var(--info); }
.pill.accent { background: var(--accent-soft); color: var(--accent); }
.notice { border-radius: 6px; padding: .55rem .75rem; background: var(--info-soft); color: var(--info); font-size: .85rem; }
.notice.warn { background: var(--warn-soft); color: var(--warn); } .notice.bad { background: var(--bad-soft); color: var(--bad); }
.empty { padding: 1.5rem; text-align: center; color: var(--muted); border: 1px dashed var(--line); border-radius: var(--radius); }
label.f { display: flex; flex-direction: column; gap: .25rem; font-size: .8rem; font-weight: 500; color: var(--muted); min-width: 0; }
input, select, textarea { background: var(--surface); border: 1px solid var(--line); border-radius: 6px; padding: .5rem .6rem; min-height: 38px; width: 100%; min-width: 0; color: var(--fg); }
textarea { min-height: 80px; resize: vertical; }
.filters { display: flex; gap: .5rem; flex-wrap: wrap; margin-bottom: .8rem; align-items: center; }
.filters input[type=search] { max-width: 240px; } .filters select { width: auto; max-width: 100%; }
.tabs { display: flex; gap: .25rem; flex-wrap: wrap; margin-bottom: .8rem; }
.tabs button { border: 1px solid transparent; background: none; padding: .35rem .7rem; border-radius: 99px; cursor: pointer; color: var(--muted); font-weight: 500; }
.tabs button.on { background: var(--accent-soft); color: var(--accent); }

/* Tables become stacked cards on phones */
.tablewrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
table { border-collapse: collapse; width: 100%; }
th, td { text-align: left; padding: .55rem .7rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: .74rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; white-space: nowrap; background: var(--surface-2); }
tr:last-child td { border-bottom: 0; }
tr.click { cursor: pointer; } tr.click:hover td { background: var(--surface-2); }
td.n, th.n { text-align: right; font-variant-numeric: tabular-nums; }

/* List rows (tasks, activity) */
.list { display: flex; flex-direction: column; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.item { display: flex; gap: .75rem; padding: .7rem .9rem; border-bottom: 1px solid var(--line); align-items: flex-start; min-width: 0; }
.item:last-child { border-bottom: 0; } .item > .grow > div:first-child { overflow-wrap: anywhere; }
.item .when { width: 92px; flex: none; font-size: .78rem; color: var(--muted); }
.item.over { box-shadow: inset 3px 0 0 var(--bad); }

/* Pipeline */
.board { display: flex; gap: .7rem; overflow-x: auto; padding-bottom: .6rem; align-items: flex-start; scroll-snap-type: x proximity; }
.col { flex: 0 0 250px; background: var(--surface-2); border-radius: var(--radius); padding: .5rem; scroll-snap-align: start; min-height: 140px; }
.col.drop { outline: 2px dashed var(--accent); }
.col h3 { display: flex; justify-content: space-between; padding: .2rem .35rem .5rem; }
.lc { background: var(--surface); border: 1px solid var(--line); border-radius: 6px; padding: .6rem; margin-bottom: .5rem; cursor: grab; display: flex; flex-direction: column; gap: .3rem; }
.lc b { overflow-wrap: anywhere; }
.lc.over { border-left: 3px solid var(--bad); }

.bar { height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--accent); }
.funnel { display: flex; flex-direction: column; gap: .55rem; }
.funnel .r { display: grid; grid-template-columns: 110px minmax(0, 1fr) 70px; gap: .6rem; align-items: center; }
.kv { display: grid; grid-template-columns: 120px minmax(0, 1fr); gap: .35rem .75rem; margin: 0; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; overflow-wrap: anywhere; }
.media-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: .8rem; }
.thumb { aspect-ratio: 16/10; border-radius: 6px; background: linear-gradient(135deg, var(--accent-soft), var(--surface-2)); display: grid; place-items: center; font: 600 .8rem var(--display); color: var(--accent); text-transform: uppercase; letter-spacing: .06em; }

/* Modal, toasts, login */
dialog { border: 1px solid var(--line); border-radius: 10px; background: var(--surface); color: var(--fg); padding: 0; width: min(520px, calc(100vw - 24px)); max-height: calc(100vh - 24px); overflow: auto; }
dialog::backdrop { background: rgb(0 0 0 / .45); }
dialog form { padding: 1.1rem; display: flex; flex-direction: column; gap: .8rem; }
dialog .actions { display: flex; gap: .5rem; justify-content: flex-end; flex-wrap: wrap; }
#toasts { position: fixed; bottom: calc(1rem + env(safe-area-inset-bottom, 0px)); right: 1rem; display: flex; flex-direction: column; gap: .5rem; z-index: 50; }
.toast { background: var(--fg); color: var(--bg); padding: .6rem .9rem; border-radius: 6px; max-width: 340px; box-shadow: 0 6px 20px rgb(0 0 0 / .25); }
.toast.err { background: var(--bad); color: #fff; }
.login { min-height: 100%; display: grid; place-items: center; padding: 1rem; }
.login .card { width: min(380px, 100%); display: flex; flex-direction: column; gap: .8rem; }
.fields2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .7rem; }

@media (max-width: 900px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .side { position: fixed; inset: 0 auto 0 0; width: 260px; z-index: 30; transform: translateX(-102%); transition: transform .2s; height: 100%; padding-top: calc(1rem + env(safe-area-inset-top, 0px)); }
  .side.open { transform: none; box-shadow: 0 0 40px rgb(0 0 0 / .35); }
  .topbar { display: flex; align-items: center; gap: .6rem; padding: calc(.6rem + env(safe-area-inset-top, 0px)) max(16px, env(safe-area-inset-right, 0px)) .6rem max(16px, env(safe-area-inset-left, 0px)); background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
  main { padding-left: max(16px, env(safe-area-inset-left, 0px)); }
  .g2, .g3, .fields2 { grid-template-columns: minmax(0, 1fr); }
  .col { flex-basis: 78vw; }
  table.stack-sm thead { display: none; }
  table.stack-sm, table.stack-sm tbody, table.stack-sm tr, table.stack-sm td { display: block; width: 100%; }
  table.stack-sm tr { padding: .5rem .2rem; border-bottom: 1px solid var(--line); }
  table.stack-sm td { border: 0; padding: .15rem .7rem; text-align: left !important; }
  table.stack-sm td[data-l]::before { content: attr(data-l) ': '; color: var(--muted); font-size: .76rem; }
  .item { flex-wrap: wrap; } .item .when { width: auto; }
  .funnel .r { grid-template-columns: 90px minmax(0, 1fr) 56px; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
