/* Instagram Reporting - design system
   Warm paper background, ink typography, muted olive accent, hairline borders.
   Components: shell (sidebar + topbar), page header, sections, tables, badges,
   buttons, forms, filters, callouts, stat strip, bars, empty states. */

:root {
  --paper: #f5f3ee;
  --paper-2: #efece5;
  --surface: #fcfbf8;
  --ink: #1b1b18;
  --ink-2: #3a3a35;
  --muted: #74726a;
  --faint: #9b988e;
  --line: #e3dfd5;
  --line-2: #d6d1c4;
  --olive: #55613a;
  --olive-ink: #3f4a28;
  --olive-soft: #e9ecdf;
  --olive-line: #cdd4b8;
  --amber: #8a5f17;
  --amber-soft: #f5ecd9;
  --amber-line: #e6d3ad;
  --brick: #93392b;
  --brick-soft: #f6e4de;
  --brick-line: #e8c4ba;
  --slate: #4f5b66;
  --slate-soft: #e9ecee;
  --radius: 6px;
  --radius-sm: 4px;
  --shadow: 0 1px 2px rgba(27, 27, 24, .04);
  --sidebar: 236px;
  --font: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --serif: "Newsreader", "Iowan Old Style", Georgia, serif;
  --mono: "JetBrains Mono", ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--paper); color: var(--ink);
  font: 14px/1.55 var(--font); font-feature-settings: "cv11", "ss01";
  -webkit-font-smoothing: antialiased;
}
a { color: var(--olive-ink); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 3px; }
strong { font-weight: 600; }
code { font: 12.5px var(--mono); background: var(--paper-2); padding: 1px 5px; border-radius: 3px; }
h1, h2, h3 { margin: 0; color: var(--ink); }
p { margin: 0 0 10px; }
ul { margin: 6px 0; padding-left: 18px; }
.num, td.num, .tabular { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.small { font-size: 12.5px; }
.err { color: var(--brick); }
.nowrap { white-space: nowrap; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
svg.i { width: 16px; height: 16px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.6;
  stroke-linecap: round; stroke-linejoin: round; vertical-align: -3px; }
:focus-visible { outline: 2px solid var(--olive); outline-offset: 2px; border-radius: 3px; }

/* ------------------------------------------------------------ shell */
.devbar { background: var(--ink); color: #d9d6cc; font-size: 12px; text-align: center; padding: 5px 12px; letter-spacing: .01em; }
.devbar b { color: #fff; font-weight: 600; }
.shell { display: grid; grid-template-columns: var(--sidebar) 1fr; min-height: 100vh; }
.sidebar {
  position: sticky; top: 0; height: 100vh; overflow-y: auto; display: flex; flex-direction: column;
  border-right: 1px solid var(--line); background: var(--paper); padding: 18px 14px 14px;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 2px 8px 18px; color: var(--ink); }
.brand:hover { text-decoration: none; }
.brand-mark { width: 26px; height: 26px; border-radius: 5px; background: var(--ink); color: var(--paper);
  display: grid; place-items: center; font: 600 13px var(--serif); letter-spacing: .02em; }
.brand-name { font: 600 14px var(--font); letter-spacing: -.01em; line-height: 1.15; }
.brand-name small { display: block; font-weight: 400; font-size: 11.5px; color: var(--muted); letter-spacing: 0; }
.nav-label { font-size: 10.5px; letter-spacing: .09em; text-transform: uppercase; color: var(--faint); padding: 14px 10px 6px; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 7px 10px; border-radius: var(--radius-sm);
  color: var(--ink-2); font-weight: 450; transition: background .12s, color .12s; }
.nav a:hover { background: var(--paper-2); text-decoration: none; color: var(--ink); }
.nav a.active { background: var(--surface); color: var(--ink); box-shadow: inset 0 0 0 1px var(--line); font-weight: 550; }
.nav a.active svg.i { color: var(--olive); }
.nav a .count { margin-left: auto; font-size: 11px; color: var(--brick); font-weight: 600; font-variant-numeric: tabular-nums; }
.sidebar-foot { margin-top: auto; border-top: 1px solid var(--line); padding-top: 12px; }
.userbox { display: flex; align-items: center; gap: 10px; padding: 6px 8px; }
.avatar { width: 28px; height: 28px; border-radius: 50%; background: var(--olive-soft); color: var(--olive-ink);
  display: grid; place-items: center; font-weight: 600; font-size: 11.5px; flex: none; text-transform: uppercase; }
.userbox .who { min-width: 0; line-height: 1.25; }
.userbox .who div { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12.5px; }
.userbox .who span { font-size: 11px; color: var(--muted); letter-spacing: .04em; text-transform: uppercase; }
.userbox form { margin-left: auto; }

.main { min-width: 0; display: flex; flex-direction: column; }
.scrim { display: none; }
.topbar { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 12px;
  height: 52px; padding: 0 32px; border-bottom: 1px solid var(--line); background: rgba(245, 243, 238, .94);
  backdrop-filter: saturate(1.2) blur(6px); }
.crumbs { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); min-width: 0; }
.crumbs a { color: var(--muted); }
.crumbs .sep { color: var(--line-2); }
.crumbs .here { color: var(--ink); font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar .right { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.btn.menu-btn { display: none; }
.content { width: 100%; max-width: 1240px; padding: 28px 32px 64px; }

/* ------------------------------------------------------------ page header */
.page-head { display: flex; align-items: flex-end; gap: 20px; flex-wrap: wrap; padding-bottom: 20px;
  margin-bottom: 24px; border-bottom: 1px solid var(--line); }
.page-head .titles { min-width: 0; flex: 1 1 380px; }
.eyebrow { font-size: 11px; letter-spacing: .09em; text-transform: uppercase; color: var(--muted); margin-bottom: 6px; }
.page-title { font: 500 28px/1.15 var(--serif); letter-spacing: -.012em; }
.page-sub { margin-top: 6px; color: var(--muted); max-width: 70ch; }
.page-head .actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ------------------------------------------------------------ sections and panels */
.section { margin-bottom: 32px; }
.section-head { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.section-title { font: 600 15px/1.3 var(--font); letter-spacing: -.005em; }
.section-head .meta { color: var(--muted); font-size: 12.5px; }
.section-head .tools { margin-left: auto; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.panel-body { padding: 18px 20px; }
.panel + .panel { margin-top: 16px; }
.divider { border: 0; border-top: 1px solid var(--line); margin: 20px 0; }
.lede { color: var(--ink-2); max-width: 72ch; }
.note { color: var(--muted); font-size: 12.5px; max-width: 80ch; }

/* ------------------------------------------------------------ stat strip */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); border: 1px solid var(--line);
  border-radius: var(--radius); background: var(--surface); margin-bottom: 28px; }
.stat { padding: 14px 18px; border-left: 1px solid var(--line); }
.stat:first-child { border-left: 0; }
.stat .label { font-size: 11.5px; color: var(--muted); letter-spacing: .02em; }
.stat .value { font: 500 24px/1.2 var(--serif); margin-top: 4px; font-variant-numeric: tabular-nums; }
.stat .hint { font-size: 12px; color: var(--muted); margin-top: 2px; }
.stat .value.warn { color: var(--amber); }
.stat .value.bad { color: var(--brick); }

/* ------------------------------------------------------------ tables */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 11px 14px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 11px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--muted);
  background: var(--paper); white-space: nowrap; }
tbody tr:last-child td, table tr:last-child td { border-bottom: 0; }
tr.small td, td.small { font-size: 12.5px; }
tbody tr:hover td { background: #faf8f3; }
td .sub, .sub { display: block; color: var(--muted); font-size: 12px; margin-top: 2px; }
td.actions { white-space: nowrap; text-align: right; }
td.actions form { display: inline; }
.handle { display: flex; align-items: center; gap: 10px; min-width: 0; }
.handle .avatar { width: 30px; height: 30px; font-size: 12px; background: var(--paper-2); color: var(--ink-2);
  box-shadow: inset 0 0 0 1px var(--line); }
.handle strong { font-weight: 600; }
.mono { font-family: var(--mono); font-size: 12px; color: var(--muted); }

/* ------------------------------------------------------------ metric lists */
.metrics { display: flex; flex-wrap: wrap; gap: 3px 16px; margin-top: 4px; }
.metrics span { white-space: nowrap; color: var(--muted); font-size: 12.5px; }
.metrics strong { color: var(--ink); font-weight: 600; font-variant-numeric: tabular-nums; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 18px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }

/* ------------------------------------------------------------ badges (status pills) */
.pill { display: inline-flex; align-items: center; gap: 6px; height: 22px; padding: 0 9px; border-radius: 999px;
  font-size: 11.5px; font-weight: 550; line-height: 1; white-space: nowrap; letter-spacing: .01em;
  background: var(--brick-soft); color: var(--brick); box-shadow: inset 0 0 0 1px var(--brick-line); }
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .85; }
.pill.active, .pill.run-success { background: var(--olive-soft); color: var(--olive-ink); box-shadow: inset 0 0 0 1px var(--olive-line); }
.pill.needs_reauth, .pill.missing_permissions, .pill.permission_error, .pill.run-partial, .pill.run-running, .pill.warn {
  background: var(--amber-soft); color: var(--amber); box-shadow: inset 0 0 0 1px var(--amber-line); }
.pill.disabled, .pill.neutral { background: var(--paper-2); color: var(--muted); box-shadow: inset 0 0 0 1px var(--line); }
.pill.error, .pill.run-failed, .pill.run-blocked { background: var(--brick-soft); color: var(--brick); box-shadow: inset 0 0 0 1px var(--brick-line); }
.pill.info { background: var(--slate-soft); color: var(--slate); box-shadow: inset 0 0 0 1px #d5dbe0; }
.tag { display: inline-block; font-size: 11px; padding: 1px 7px; border-radius: 3px; background: var(--paper-2);
  color: var(--ink-2); box-shadow: inset 0 0 0 1px var(--line); white-space: nowrap; }

/* ------------------------------------------------------------ buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 7px; height: 34px; padding: 0 14px;
  border-radius: var(--radius-sm); border: 1px solid var(--ink); background: var(--ink); color: var(--paper);
  font: 500 13px var(--font); cursor: pointer; white-space: nowrap; text-decoration: none;
  transition: background .12s, border-color .12s, color .12s; }
.btn:hover { background: #33332e; border-color: #33332e; text-decoration: none; color: #fff; }
.btn.secondary { background: var(--surface); color: var(--ink); border-color: var(--line-2); }
.btn.secondary:hover { background: var(--paper-2); border-color: var(--faint); color: var(--ink); }
.btn.accent { background: var(--olive); border-color: var(--olive); color: #fff; }
.btn.accent:hover { background: var(--olive-ink); border-color: var(--olive-ink); }
.btn.sm { height: 28px; padding: 0 10px; font-size: 12.5px; }
.btn.link { height: auto; padding: 0; background: none; border: 0; color: var(--olive-ink); font-weight: 500; }
.btn.link:hover { text-decoration: underline; text-underline-offset: 3px; background: none; color: var(--olive-ink); }
.btn.danger-link { color: var(--brick); }
.btn[disabled], .btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.icon { width: 34px; padding: 0; background: transparent; border-color: transparent; color: var(--ink-2); }
.btn.icon:hover { background: var(--paper-2); color: var(--ink); }
form.inline { display: inline; }

/* ------------------------------------------------------------ forms */
label { font-size: 12.5px; color: var(--ink-2); font-weight: 500; }
input, select, textarea { font: 13.5px var(--font); color: var(--ink); background: var(--surface); height: 34px;
  padding: 0 10px; border: 1px solid var(--line-2); border-radius: var(--radius-sm); max-width: 100%;
  transition: border-color .12s, box-shadow .12s; }
select { padding-right: 28px; appearance: none; -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2374726a' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 9px center; }
input:hover, select:hover { border-color: var(--faint); }
input:focus, select:focus { outline: none; border-color: var(--olive); box-shadow: 0 0 0 3px var(--olive-soft); }
input[type=checkbox], input[type=radio] { height: 15px; width: 15px; padding: 0; accent-color: var(--olive); vertical-align: -2px; }
select:disabled, input:disabled { background: var(--paper-2); color: var(--muted); }
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field > input, .field > select { width: 100%; }
.field .help { font-size: 12px; color: var(--muted); font-weight: 400; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px 16px; align-items: end; }
.form-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
.check { display: flex; gap: 9px; align-items: flex-start; font-weight: 400; color: var(--ink-2); line-height: 1.45; }
.check input { margin-top: 2px; }
.grid { display: grid; gap: 14px 16px; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); align-items: end; }

/* filter bar */
.filters { display: flex; flex-wrap: wrap; gap: 10px 12px; align-items: flex-end; padding: 14px 16px;
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); margin-bottom: 16px; }
.filters .field { flex: 1 1 150px; }
.filters .field.date { flex: 0 1 150px; }
.filters .go { display: flex; gap: 8px; }

.filters.grid4 { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); }
.filters.grid4 .go { align-self: end; }

/* segmented control */
.segmented { display: inline-flex; padding: 3px; gap: 2px; background: var(--paper-2); border: 1px solid var(--line);
  border-radius: 7px; }
.segmented a { padding: 5px 12px; border-radius: 5px; color: var(--muted); font-weight: 500; font-size: 13px; }
.segmented a:hover { color: var(--ink); text-decoration: none; }
.segmented a.on { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.06), inset 0 0 0 1px var(--line); }

/* ------------------------------------------------------------ callouts (flash, alerts) */
.flash, .callout { display: flex; gap: 10px; align-items: flex-start; padding: 11px 14px; border-radius: var(--radius);
  margin-bottom: 18px; font-size: 13.5px; border: 1px solid var(--line); background: var(--surface); }
.flash.ok, .callout.ok { background: var(--olive-soft); border-color: var(--olive-line); color: var(--olive-ink); }
.flash.error, .callout.error { background: var(--brick-soft); border-color: var(--brick-line); color: #6f2b20; }
.callout.warn { background: var(--amber-soft); border-color: var(--amber-line); color: #6a4910; }
.callout.info { background: var(--slate-soft); border-color: #d5dbe0; color: #3b4651; }
.callout svg.i { margin-top: 1px; }
.callout.small { font-size: 12.5px; }
.callout ul { margin: 4px 0 0; }

/* ------------------------------------------------------------ empty state */
.empty { padding: 36px 24px; text-align: center; color: var(--muted); border: 1px dashed var(--line-2);
  border-radius: var(--radius); background: transparent; }
.empty strong { display: block; color: var(--ink); font: 500 17px var(--serif); margin-bottom: 4px; }
.empty .btn { margin-top: 12px; }

/* ------------------------------------------------------------ bars (simple charts) */
.bars { display: grid; gap: 8px; }
.bar-row { display: grid; grid-template-columns: minmax(0, 200px) 1fr 90px; gap: 12px; align-items: center; font-size: 12.5px; }
.bar-row .track { height: 8px; background: var(--paper-2); border-radius: 999px; overflow: hidden; }
.bar-row .fill { height: 100%; background: var(--olive); border-radius: 999px; }
.bar-row > span:first-child { overflow: hidden; text-overflow: ellipsis; }
.bar-row .val { text-align: right; font-variant-numeric: tabular-nums; color: var(--ink-2); }

/* ------------------------------------------------------------ details */
details summary { cursor: pointer; color: var(--ink-2); font-size: 13px; }
details[open] summary { margin-bottom: 8px; }

/* ------------------------------------------------------------ auth layout */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 32px 16px; }
.auth-card { width: 100%; max-width: 420px; }
.auth-card .brand { justify-content: center; padding-bottom: 26px; }
.auth-card h1 { font: 500 26px/1.2 var(--serif); text-align: center; margin-bottom: 6px; }
.auth-card .auth-sub { text-align: center; margin-bottom: 22px; }
.auth-card .panel-body { padding: 22px; }
.auth-card .stack { display: grid; gap: 12px; }
.auth-card .stack > .btn { width: 100%; height: 38px; }

/* ------------------------------------------------------------ responsive */
@media (max-width: 960px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; z-index: 20; left: 0; top: 0; width: 272px; transform: translateX(-102%);
    transition: transform .18s ease; background: var(--paper); }
  body.nav-open .sidebar { transform: none; box-shadow: 0 0 0 1px var(--line), 12px 0 32px rgba(0,0,0,.08); }
  body.nav-open .scrim { display: block; position: fixed; inset: 0; z-index: 15; background: rgba(27,27,24,.25); }
  .btn.menu-btn { display: inline-flex; margin-left: -8px; }
  .topbar { padding: 0 16px; }
  .content { padding: 20px 16px 48px; }
  .page-title { font-size: 24px; }
  .filters.grid4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 640px) {
  .stats { grid-template-columns: 1fr 1fr; }
  .stat:nth-child(odd) { border-left: 0; }
  .stat:nth-child(n+3) { border-top: 1px solid var(--line); }
  th, td { padding: 10px 11px; }
  .page-head { padding-bottom: 16px; margin-bottom: 18px; }
  .bar-row { grid-template-columns: minmax(0, 120px) 1fr 64px; }
  .filters .field, .filters .field.date { flex: 1 1 100%; }
  .filters.grid4 { grid-template-columns: 1fr 1fr; }
  .filters.grid4 .go { grid-column: 1 / -1; }
  /* tables marked .stack-sm become labelled cards on phones */
  .stack-sm table, .stack-sm tbody, .stack-sm tr, .stack-sm td { display: block; width: 100%; }
  .stack-sm thead { display: none; }
  .stack-sm tr { padding: 12px 14px; border-bottom: 1px solid var(--line); }
  .stack-sm tbody tr:last-child { border-bottom: 0; }
  .stack-sm td { border: 0; padding: 5px 0; text-align: left; }
  .stack-sm td[data-label]::before { content: attr(data-label); display: block; font-size: 10.5px; letter-spacing: .07em;
    text-transform: uppercase; color: var(--faint); margin-bottom: 2px; }
  .stack-sm td.actions { white-space: normal; display: flex; flex-wrap: wrap; gap: 8px 14px; align-items: center; padding-top: 10px; }
  .stack-sm td.actions > div, .stack-sm td.actions > form { margin: 0 !important; }
  .stack-sm tbody tr:hover td { background: transparent; }
  .topbar .right .who-inline { display: none; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* ---- simple sheet page: numbered setup steps ---- */
.steps { display: grid; gap: 12px; margin: 0; padding: 0; list-style: none; }
.step { display: grid; grid-template-columns: 34px 1fr; gap: 14px; background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; }
.step.current { border-color: var(--olive-line); box-shadow: 0 0 0 3px var(--olive-soft); }
.step-num { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; font-weight: 600;
  font-size: 13.5px; background: var(--paper-2); color: var(--muted); border: 1px solid var(--line-2); }
.step.done .step-num { background: var(--olive); color: #fff; border-color: var(--olive); }
.step.current .step-num { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.step h3 { font-size: 15px; font-weight: 600; margin: 4px 0 6px; }
.step p { margin: 0 0 8px; color: var(--ink-2); }
.step .actions-row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-top: 10px; }
.colmap { display: grid; gap: 6px; margin: 6px 0 4px; }
.colmap div { display: flex; gap: 10px; align-items: baseline; }
.colmap .what { min-width: 230px; color: var(--muted); font-size: 13px; }
.colmap .cols { font-weight: 500; }
.letter { display: inline-block; min-width: 22px; padding: 1px 6px; margin-right: 4px; border-radius: 4px; text-align: center;
  font-family: var(--mono); font-size: 12px; background: var(--paper-2); border: 1px solid var(--line); color: var(--ink); }
@media (max-width: 720px) { .colmap div { flex-direction: column; gap: 2px; } .colmap .what { min-width: 0; } }
