/* Spinbit UI system. Figtree, a light workspace, one purple for selection and primary actions.
   Tokens first; the shell (sidebar + main) and shared components after. Spacing scale: 4 8 12 16 24 32. */
:root {
  --bg: #F6F7FB; --surface: #FFFFFF; --side-bg: #F1F2F6; --head-bg: #FAFBFC;
  --text: #323338; --text-2: #676879; --text-3: #9699A6;
  --line: #E6E9EF; --line-2: #D0D4DC;
  --accent: #6161FF; --accent-hover: #5151E6; --accent-soft: rgba(97, 97, 255, .05); --accent-soft-2: rgba(97, 97, 255, .1);
  --green: #00854A; --green-soft: #E6F6EE;
  --amber: #B26A00; --amber-soft: #FFF4E0;
  --red: #D83A3A; --red-soft: #FDECEC;
  --blue: #3B82F6; --lime: #7CB518;
  --radius: 12px; --radius-sm: 8px; --control: 34px;
  --font: Figtree, -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  --t: 120ms ease;
}
* { box-sizing: border-box; }
html { font-family: var(--font); font-size: 14px; line-height: 1.5; color: var(--text); -webkit-font-smoothing: antialiased; font-variant-numeric: tabular-nums; color-scheme: light; }
body.ui { margin: 0; background: var(--bg); min-height: 100vh; display: flex; font-family: var(--font); }
a { color: inherit; text-decoration: none; }
h1, h2, h3, p { margin: 0; }
button, input, select { font: inherit; font-family: var(--font); }
*:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

/* Sidebar */
.side { width: 230px; flex: none; background: var(--side-bg); border-right: 1px solid var(--line); min-height: 100vh; position: sticky; top: 0; display: flex; flex-direction: column; padding: 12px 0 12px; }
.side-brand { display: flex; align-items: center; gap: 10px; height: 44px; margin: 0 8px; padding: 0 12px; border-radius: 8px; }
.side-logo { width: 24px; height: 24px; border-radius: 6px; background: var(--accent); color: #fff; font-weight: 700; font-size: 13px; display: grid; place-items: center; flex: none; }
.side-brand-text { font-size: 14px; font-weight: 600; line-height: 1.15; }
.side-brand-text small { display: block; color: var(--text-2); font-size: 11px; font-weight: 400; }
.side-group { font-size: 10px; font-weight: 700; color: var(--text-3); letter-spacing: 1.1px; text-transform: uppercase; padding: 10px 0 3px 20px; }
.side-nav { display: flex; flex-direction: column; gap: 1px; padding: 0 8px; }
.side-nav a { position: relative; display: flex; align-items: center; gap: 10px; height: 33px; padding: 0 12px; border-radius: 8px; color: var(--text-2); font-size: 13px; font-weight: 500; transition: background var(--t), color var(--t); }
.side-nav a:hover { background: rgba(50, 51, 56, .05); color: var(--text); }
.side-nav a:hover .side-icon { color: var(--text); }
.side-nav a[aria-current="page"] { background: #FFFFFF; color: var(--accent); font-weight: 600; }
.side-nav a[aria-current="page"] .side-icon { color: var(--accent); }
.side-nav a[aria-current="page"]::before { content: ""; position: absolute; left: 0; top: 6px; bottom: 6px; width: 3px; background: var(--accent); border-radius: 0 3px 3px 0; }
.side-icon { width: 20px; display: inline-grid; place-items: center; color: var(--text-3); flex: none; }
.side-icon svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.side-foot { margin-top: auto; padding: 12px 20px 4px; border-top: 1px solid var(--line); margin-left: 8px; margin-right: 8px; }
.side-status { font-size: 12px; color: var(--text-2); display: inline-flex; align-items: center; gap: 8px; }
.side-status::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--green); }
.side-toggle { display: none; }

/* Main */
.main { flex: 1; min-width: 0; padding: 24px 32px 40px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 24px; min-height: var(--control); }
.page-head h1 { font-size: 20px; font-weight: 700; letter-spacing: -.3px; line-height: 1.3; }
.page-sub { color: var(--text-2); font-size: 12px; margin-top: 2px; }

/* Cards */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 18px 20px 12px; flex-wrap: wrap; }
.card-head h2 { font-size: 15px; font-weight: 600; color: var(--text); }
.card-head .muted { color: var(--text-2); font-size: 12px; }
.card-body { padding: 0 20px 20px; }

/* Stat tiles */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin-bottom: 24px; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.tile-icon { width: 28px; height: 28px; border-radius: 6px; background: var(--accent-soft-2); color: var(--accent); display: grid; place-items: center; margin-bottom: 10px; }
.tile-icon svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.tile-label { color: var(--text-2); font-size: 12px; font-weight: 500; }
.tile-value { font-size: 26px; font-weight: 700; letter-spacing: -.3px; line-height: 1.2; }
.tile-sub { color: var(--text-2); font-size: 12px; }

/* Stat chips (P&L header) */
.pills { display: flex; gap: 8px; flex-wrap: wrap; }
.pill { display: inline-flex; align-items: center; gap: 6px; height: 28px; padding: 0 10px; border-radius: 6px; border: 1px solid var(--line); font-size: 12px; font-weight: 500; color: var(--text-2); background: var(--surface); }
.pill b { font-weight: 600; color: var(--text); }
.pill.rev b { color: var(--green); }
.pill.spend b { color: var(--red); }
.pill.profit b, .pill.roas b { color: var(--green); }
.pill.neg b { color: var(--red); }

/* Controls */
.seg { display: inline-flex; gap: 2px; padding: 3px; background: #EEF0F5; border-radius: 8px; height: var(--control); }
.seg button { border: 0; background: transparent; color: var(--text-2); font-weight: 500; font-size: 13px; padding: 0 12px; border-radius: 6px; cursor: pointer; transition: background var(--t), color var(--t); }
.seg button:hover { color: var(--text); }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgba(50, 51, 56, .08); }
.btn { display: inline-flex; align-items: center; gap: 6px; height: var(--control); padding: 0 14px; border-radius: 6px; border: 1px solid var(--line); background: var(--surface); color: var(--text); font-size: 13px; font-weight: 500; cursor: pointer; transition: background var(--t), border-color var(--t); }
.btn:hover { background: var(--bg); border-color: var(--line-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn:disabled { opacity: .6; cursor: progress; }
.btn svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn { width: var(--control); height: var(--control); border-radius: 6px; border: 1px solid var(--line); background: var(--surface); color: var(--text-2); display: inline-grid; place-items: center; cursor: pointer; transition: background var(--t), color var(--t); }
.icon-btn:hover { background: var(--bg); color: var(--text); }
.icon-btn svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn.busy svg { animation: ui-spin 1s linear infinite; }
@keyframes ui-spin { to { transform: rotate(360deg); } }

/* Tables */
.tbl { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13px; }
.tbl th { background: var(--head-bg); color: var(--text-2); font-weight: 500; font-size: 12px; text-align: right; padding: 10px 14px; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); white-space: nowrap; }
.tbl th.left, .tbl td.left { text-align: left; }
.tbl td { text-align: right; padding: 0 14px; height: 44px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.tbl tbody tr:last-child td { border-bottom: 0; }
.tbl tbody tr:hover td { background: var(--side-bg); }
.tag { display: inline-block; padding: 2px 8px; border-radius: 6px; font-size: 12px; font-weight: 500; line-height: 18px; }
.tag.new { background: #EAF1FE; color: #1D4ED8; }
.tag.reach1 { background: var(--amber-soft); color: var(--amber); }
.tag.reach2 { background: #EEF6E2; color: #4D7A0F; }
.tag.done { background: var(--green-soft); color: var(--green); }
.empty { padding: 32px 20px; color: var(--text-2); text-align: center; font-size: 13px; }

/* Toast banners, top right: green only when the action really happened */
.toasts { position: fixed; top: 16px; right: 16px; z-index: 50; display: flex; flex-direction: column; gap: 8px; width: min(360px, calc(100vw - 32px)); pointer-events: none; }
.toast { background: var(--surface); border: 1px solid var(--line); border-left: 3px solid var(--green); border-radius: 8px; padding: 10px 14px; font-size: 13px; color: var(--text); box-shadow: 0 4px 16px rgba(50, 51, 56, .1); animation: toast-in 160ms ease; transition: opacity 200ms ease; }
.toast.bad { border-left-color: var(--red); }
.ask { position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; padding: 16px; background: rgba(20, 22, 32, .4); }
.ask[hidden] { display: none; }
.ask-box { width: min(400px, 100%); padding: 20px; border-radius: 12px; background: var(--surface); box-shadow: 0 12px 40px rgba(0, 0, 0, .2); }
.ask-box p { font-size: 14px; line-height: 1.5; color: var(--text); white-space: pre-line; }
.ask-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.toast.wait { border-left-color: #38BDF8; }
.is-busy { animation: ui-pulse 1s ease-in-out infinite; cursor: progress; }
@keyframes ui-pulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(56, 189, 248, .6); } 50% { box-shadow: 0 0 0 5px rgba(56, 189, 248, 0); } }
.toast.out { opacity: 0; }
@keyframes toast-in { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }

/* Narrow screens: the sidebar becomes a drawer */
@media (max-width: 900px) {
  .side { position: fixed; left: 0; top: 0; bottom: 0; z-index: 20; transform: translateX(-100%); transition: transform 160ms ease; box-shadow: none; }
  .side.open { transform: none; box-shadow: 0 0 0 100vw rgba(50, 51, 56, .25); }
  .side-toggle { display: inline-grid; place-items: center; position: fixed; top: 12px; left: 12px; z-index: 21; width: var(--control); height: var(--control); border-radius: 6px; border: 1px solid var(--line); background: var(--surface); color: var(--text); cursor: pointer; }
  .side-toggle svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }
  .main { padding: 60px 16px 32px; }
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (prefers-reduced-motion: reduce) { .ui * { transition: none !important; animation: none !important; } }
.toast.wait { border-left-color: #38BDF8; }

/* Phones: stacked cards instead of wide tables. Nothing below applies above 640px, so the PC view is untouched. */
@media (max-width: 640px) {
  .side-toggle { position: absolute; }
  .ui input, .ui select, .ui textarea { font-size: 16px; }
  .tbl, .tbl tbody { display: block; }
  .tbl thead { display: none; }
  .tbl tbody tr { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px 12px; padding: 12px 16px; border-bottom: 1px solid var(--line); }
  .tbl tbody tr:last-child { border-bottom: 0; }
  .tbl td, .tbl td.left, .tbl tbody tr:last-child td { display: block; min-width: 0; height: auto; padding: 0; border: 0; text-align: left; white-space: normal; overflow-wrap: anywhere; font-size: 14px; }
  .tbl td:first-child { grid-column: 1 / -1; font-weight: 600; }
  .tbl td:empty { display: none; }
  .tbl td::before { display: block; margin-bottom: 2px; color: var(--text-3); font-size: 11px; font-weight: 500; }
  .tbl tbody tr:hover td { background: none; }
}
