/* RankHub design system — "Ledger". Warm paper background, graphite rail, one deep
   green accent, tabular figures in a mono face. Dense by default; nothing decorative. */
:root {
  --paper: #f4f4ef;
  --surface: #ffffff;
  --ink: #17191e;
  --ink-2: #4b5059;
  --muted: #7a808a;
  --line: #e2e2d9;
  --line-2: #cfcfc4;
  --rail: #1c1f25;
  --rail-ink: #d9dbe0;
  --rail-muted: #8b909a;
  --accent: #0f6b5c;
  --accent-ink: #ffffff;
  --accent-soft: #e0efe9;
  --good: #1f7a3d;
  --warn: #a35a00;
  --bad: #b4231f;
  --radius: 6px;
  --font: "Instrument Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
}
* { box-sizing: border-box; }
html { font-size: 14px; }
body { margin: 0; font-family: var(--font); color: var(--ink); background: var(--paper); line-height: 1.45; -webkit-font-smoothing: antialiased; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
h1 { font-size: 22px; }
h3 { font-size: 14px; }
h4 { font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--rail-muted); margin: 14px 0 4px; }
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.small { font-size: 12px; }
.muted { color: var(--muted); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
code { font-family: var(--mono); font-size: 12px; background: var(--accent-soft); padding: 1px 5px; border-radius: 4px; }
code.block { display: block; padding: 10px; word-break: break-all; }

/* top bar */
.topbar { display: grid; grid-template-columns: 180px 1fr auto auto; gap: 16px; align-items: center; height: 48px; padding: 0 16px; background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 10; }
.brand { display: inline-flex; align-items: center; gap: 8px; font-weight: 700; color: var(--ink); letter-spacing: -0.02em; }
.brand .mark { width: 14px; height: 14px; border-radius: 3px; background: linear-gradient(135deg, var(--accent), #1f9a84); display: inline-block; }
.search { display: flex; max-width: 520px; }
.search input { flex: 1; height: 32px; border: 1px solid var(--line-2); border-right: 0; border-radius: var(--radius) 0 0 var(--radius); padding: 0 10px; font: inherit; background: var(--paper); }
.search button { height: 32px; border: 1px solid var(--accent); background: var(--accent); color: var(--accent-ink); border-radius: 0 var(--radius) var(--radius) 0; padding: 0 12px; font: inherit; cursor: pointer; }
.project-switch { display: flex; align-items: center; gap: 6px; }
.project-switch select { height: 32px; border: 1px solid var(--line-2); border-radius: var(--radius); padding: 0 8px; font: inherit; background: var(--surface); max-width: 320px; }
.account { display: flex; align-items: center; gap: 12px; font-size: 13px; }
.account .pill { font-family: var(--mono); font-size: 11px; background: var(--accent-soft); color: var(--accent); padding: 2px 8px; border-radius: 999px; text-transform: uppercase; }
.account a { color: var(--ink-2); }
button.link { background: none; border: 0; color: var(--accent); font: inherit; cursor: pointer; padding: 0; }
button.link.danger { color: var(--bad); }

/* shell */
.shell { display: grid; grid-template-columns: 236px 1fr; min-height: calc(100vh - 48px); }
.embed .shell { grid-template-columns: 1fr; min-height: 100vh; }
.rail { background: var(--rail); color: var(--rail-ink); padding: 12px 10px 24px; position: sticky; top: 48px; height: calc(100vh - 48px); overflow: auto; }
.toolkits { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 4px; }
.toolkits .tk { display: block; padding: 6px 8px; border-radius: 4px; color: var(--rail-ink); font-size: 12.5px; font-weight: 500; }
.toolkits .tk:hover { background: rgba(255,255,255,0.06); text-decoration: none; }
.toolkits .tk.active { background: var(--accent); color: #fff; }
.sections { margin-top: 10px; border-top: 1px solid rgba(255,255,255,0.08); padding-top: 6px; }
.sections .tagline { font-size: 12px; color: var(--rail-muted); margin: 6px 0 4px; }
.sections ul { list-style: none; margin: 0; padding: 0; }
.sections li a { display: block; padding: 4px 8px; border-radius: 4px; color: var(--rail-ink); font-size: 13px; }
.sections li a:hover { background: rgba(255,255,255,0.06); text-decoration: none; }
.sections li a.active { background: rgba(255,255,255,0.12); color: #fff; font-weight: 600; }
.content { padding: 20px 24px 60px; min-width: 0; }

/* page head + inputs */
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 14px; }
.crumbs { margin: 0 0 2px; font-size: 12px; color: var(--muted); }
.blurb { margin: 4px 0 0; color: var(--ink-2); max-width: 70ch; }
.project-tag { margin: 0; font-size: 12px; color: var(--muted); white-space: nowrap; }
.inputs { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; margin-bottom: 14px; }
.inputs label, .stack label, .row label { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--ink-2); }
input[type=text], input[type=search], input[type=url], input[type=email], input[type=password], select, textarea { height: 32px; border: 1px solid var(--line-2); border-radius: var(--radius); padding: 0 8px; font: inherit; font-size: 13px; background: var(--surface); color: var(--ink); min-width: 160px; }
textarea { height: auto; padding: 6px 8px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.btn { display: inline-flex; align-items: center; height: 32px; padding: 0 14px; border-radius: var(--radius); background: var(--accent); color: var(--accent-ink); border: 1px solid var(--accent); font: inherit; font-weight: 600; cursor: pointer; }
.btn:hover { text-decoration: none; filter: brightness(1.05); }
.btn-ghost { display: inline-flex; align-items: center; height: 32px; padding: 0 10px; border-radius: var(--radius); border: 1px solid var(--line-2); background: var(--surface); color: var(--ink-2); font: inherit; cursor: pointer; }
.btn-ghost:hover { text-decoration: none; border-color: var(--ink-2); }
.stack { display: flex; flex-direction: column; gap: 10px; }
.row { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; }

/* states */
.state { border: 1px solid var(--line); border-left: 3px solid var(--muted); background: var(--surface); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 14px; display: flex; flex-wrap: wrap; gap: 6px 12px; align-items: baseline; }
.state-needs { border-left-color: var(--warn); }
.state-error { border-left-color: var(--bad); }
.state-collecting { border-left-color: var(--accent); }
.state .needs { width: 100%; font-size: 12px; color: var(--ink-2); display: flex; gap: 10px; flex-wrap: wrap; }
.state .actions, .actions.top { width: 100%; display: flex; gap: 8px; margin-top: 6px; }
.actions.top { margin-bottom: 12px; }
.error { color: var(--bad); background: #fbeceb; border: 1px solid #f1c9c6; padding: 8px 10px; border-radius: var(--radius); margin: 0 0 10px; }
.note { font-size: 12px; color: var(--muted); margin: 8px 0 0; }
.badge { display: inline-block; font-size: 11px; font-family: var(--mono); padding: 2px 7px; border-radius: 999px; background: #eee; color: var(--ink-2); }
.badge.good { background: #e3f2e7; color: var(--good); }
.badge.warn { background: #f8ecd9; color: var(--warn); }
.badge.muted { background: #ececec; color: var(--muted); }

/* KPIs */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 10px; margin-bottom: 14px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; display: flex; flex-direction: column; gap: 2px; }
.kpi .label { font-size: 11.5px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }
.kpi .value { font-size: 22px; font-weight: 600; line-height: 1.2; }
.kpi .sub { font-size: 12px; color: var(--ink-2); }

/* charts */
.charts { display: grid; grid-template-columns: repeat(auto-fit, minmax(360px, 1fr)); gap: 10px; margin-bottom: 14px; }
.chart { margin: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; }
.chart figcaption { font-size: 12px; color: var(--ink-2); margin-bottom: 6px; font-weight: 600; }

/* tables */
.table-block { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 14px; }
.table-head { display: flex; justify-content: space-between; align-items: center; padding: 8px 12px; border-bottom: 1px solid var(--line); }
.table-tools { display: flex; gap: 8px; align-items: center; }
.table-tools input { height: 28px; min-width: 140px; }
.table-wrap { overflow: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data th { text-align: left; font-weight: 600; font-size: 11.5px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; padding: 7px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; cursor: pointer; user-select: none; }
table.data th.num, table.data td.num { text-align: right; }
table.data td { padding: 6px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.data tr:last-child td { border-bottom: 0; }
table.data tbody tr:hover { background: #fafaf6; }
.empty-row { color: var(--muted); text-align: center; padding: 18px !important; }
.table-block > .note { padding: 6px 12px 10px; }

/* panels */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 14px; }
.panel.narrow { max-width: 560px; }
.panel h3 { margin-bottom: 8px; }
details.panel summary { cursor: pointer; font-weight: 600; }
.inline-list { list-style: none; padding: 0; margin: 8px 0 0; display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 13px; }
.kv { display: grid; grid-template-columns: 120px 1fr; gap: 4px 12px; margin: 0; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }

/* footer */
.tool-foot { margin-top: 10px; font-size: 12px; color: var(--muted); }
.tool-foot .source { display: flex; flex-wrap: wrap; gap: 6px 16px; }
.computed { margin-top: 8px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 6px 12px; color: var(--ink-2); }
.computed summary { cursor: pointer; font-weight: 600; color: var(--ink); }
.computed div { padding: 8px 0 4px; max-width: 90ch; }

/* public */
body.public { background: var(--paper); }
.pub-top { display: flex; justify-content: space-between; align-items: center; padding: 14px 28px; }
.pub-top nav { display: flex; gap: 14px; align-items: center; }
.pub-main { max-width: 960px; margin: 0 auto; padding: 24px; }
.pub-foot { text-align: center; color: var(--muted); font-size: 12px; padding: 40px 0; }
.hero { padding: 60px 0 30px; max-width: 640px; }
.hero h1 { font-size: 34px; line-height: 1.15; letter-spacing: -0.02em; }
.hero p { font-size: 16px; color: var(--ink-2); }
.cta { display: flex; gap: 10px; margin-top: 18px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.grid3 > div { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.grid3 p { margin: 6px 0 0; color: var(--ink-2); font-size: 13px; }
.card.auth { max-width: 400px; margin: 40px auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 22px; }
.card.auth h1 { margin-bottom: 12px; }
.card.auth input { min-width: 0; width: 100%; }

@media (max-width: 900px) {
  .topbar { grid-template-columns: 1fr auto; height: auto; padding: 8px 12px; gap: 8px; }
  .search { grid-column: 1 / -1; max-width: none; }
  .shell { grid-template-columns: 1fr; }
  .rail { position: static; height: auto; }
  .content { padding: 14px 16px 40px; }
  .grid3 { grid-template-columns: 1fr; }
}
@media print {
  .topbar, .rail, .inputs, .table-tools, .actions { display: none !important; }
  .shell { grid-template-columns: 1fr; }
  body { background: #fff; }
}
