/* Layout and components. Colours only through tokens.css. */
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink-soft); font: 400 15px/1.5 var(--font-body); }
h1, h2, h3 { color: var(--ink); font-family: var(--font-title); font-weight: 700; margin: 0 0 8px; }
a { color: var(--brand-pressed); }
.card { background: var(--surface); border-radius: var(--radius-card); box-shadow: var(--shadow); padding: 20px; }
.btn { display: inline-flex; align-items: center; gap: 8px; border: 0; border-radius: var(--radius-pill); padding: 10px 18px;
  background: var(--brand); color: #fff; font: 600 15px var(--font-body); text-decoration: none; cursor: pointer; }
.btn:hover, .btn:focus-visible { background: var(--brand-pressed); }
.btn.ghost { background: var(--surface); color: var(--ink); box-shadow: inset 0 0 0 1px var(--line); }
.btn[disabled], .btn[aria-disabled="true"] { background: var(--locked); color: var(--locked-ink); cursor: not-allowed; }
.pill { display: inline-block; border-radius: var(--radius-pill); padding: 2px 10px; font-size: 12px; font-weight: 700;
  background: var(--brand-soft); color: var(--brand-pressed); }
.notice { border-radius: var(--radius-small); padding: 12px 16px; }
.notice.error { background: var(--error-soft); color: var(--error-ink); }
.notice.ok { background: var(--success-soft); color: var(--success-ink); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.htmx-indicator { opacity: 0; transition: opacity 0.2s; }
.htmx-request .htmx-indicator, .htmx-request.htmx-indicator { opacity: 1; }
/* Auth pages */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.auth .card { width: min(420px, 100%); display: grid; gap: 12px; }
.auth .providers { display: grid; gap: 10px; }
/* Shell: side nav on desktop, a top bar under 760 px (spec-001). */
.shell { display: grid; grid-template-columns: 248px minmax(0, 1fr); min-height: 100vh; }
.side { background: var(--surface); border-right: 1px solid var(--line); padding: 20px 16px; display: flex; flex-direction: column; gap: 20px; }
.home { position: relative; display: flex; align-items: center; gap: 12px; color: var(--ink); text-decoration: none; }
.home small { display: block; color: var(--muted); font-size: 12px; }
.logo { width: 40px; height: 40px; border-radius: var(--radius-small); background: var(--brand); color: #fff; display: grid; place-items: center;
  font: 700 18px var(--font-title); object-fit: contain; }
img.logo { background: var(--surface); }
.version { position: absolute; left: 0; top: 48px; z-index: 5; white-space: nowrap; background: var(--ink); color: #fff; font-size: 12px;
  border-radius: var(--radius-small); padding: 6px 10px; opacity: 0; pointer-events: none; transition: opacity 0.15s; }
.home:hover .version, .home:focus-visible .version { opacity: 1; }
.nav { display: grid; gap: 4px; }
.nav a { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-radius: var(--radius-small); color: var(--ink-soft); text-decoration: none; font-weight: 500; }
.nav a:hover { background: var(--bg); }
.nav a.active { background: var(--brand-soft); color: var(--brand-pressed); }
.side-foot { margin-top: auto; }
.main { padding: 24px; min-width: 0; display: grid; gap: 16px; align-content: start; }
.topbar { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; }
.topbar h1 { margin: 0 auto 0 0; font-size: 26px; }
.tools { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.lang { color: var(--muted); font-weight: 700; text-decoration: none; padding: 4px 6px; }
.lang[aria-current="true"] { color: var(--ink); }
.picker select, .form input { font: inherit; padding: 8px 10px; border-radius: var(--radius-small); border: 1px solid var(--line); background: var(--surface); }
.form { display: grid; gap: 14px; max-width: 420px; }
.form label { display: grid; gap: 6px; color: var(--ink); font-weight: 500; }
.empty { text-align: center; padding: 40px 20px; }
.badge-demo { margin-left: 10px; vertical-align: middle; }
@media (max-width: 760px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .side, .nav, .topbar, .main > * { min-width: 0; max-width: 100%; }
  .topbar h1 { width: 100%; }
  .side { flex-direction: row; flex-wrap: wrap; align-items: center; border-right: 0; border-bottom: 1px solid var(--line); padding: 12px 16px; gap: 12px; }
  .nav { display: flex; overflow-x: auto; width: 100%; order: 3; }
  .nav a { white-space: nowrap; }
  .side-foot { margin: 0 0 0 auto; }
  .main { padding: 16px; }
}
/* Charts (internal/charts): tooltips on hover and keyboard focus, no JS. */
.chart { width: 100%; height: auto; display: block; font-family: var(--font-body); }
.chart .grid-line { stroke: var(--line); stroke-width: 1; }
.chart .axis, .chart .label, .chart .value { fill: var(--muted); font-size: 12px; }
.chart .label { fill: var(--ink-soft); font-size: 14px; }
.chart .value { fill: var(--ink); font-weight: 700; font-size: 14px; }
.chart .area { fill: var(--brand-soft); opacity: 0.6; }
.chart .line { fill: none; stroke: var(--brand); stroke-width: 3; }
.chart .bench { fill: none; stroke: var(--muted); stroke-width: 2; stroke-dasharray: 6 6; }
.chart .dot { fill: var(--surface); stroke: var(--brand); stroke-width: 2; }
.chart .hit { fill: transparent; }
.chart .vbar, .chart .hbar { fill: var(--brand); }
.chart .track { fill: var(--locked); }
.chart .tip { opacity: 0; pointer-events: none; transition: opacity 0.12s; }
.chart .tip rect { fill: var(--ink); }
.chart .tip text { fill: #fff; font-size: 12px; }
.chart .tip text.big { font-size: 14px; font-weight: 700; }
.chart .pt:hover .tip, .chart .pt:focus .tip, .chart .pt:focus-visible .tip { opacity: 1; }
.chart .pt:focus { outline: none; }
.chart .pt:focus .dot { stroke-width: 4; }
.ring .ring-track { fill: none; stroke: var(--locked); stroke-width: 8; }
.ring .ring-fill { fill: none; stroke: var(--brand); stroke-width: 8; stroke-linecap: round; }
/* Metrics page */
.hero { background: var(--brand); color: #fff; display: grid; gap: 12px; }
.hero h2, .hero b, .hero summary { color: #fff; }
.hero .iq { font: 700 64px/1 var(--font-title); margin: 0; }
.hero .trend { margin: 0; opacity: 0.9; }
.belts { list-style: none; display: grid; grid-template-columns: repeat(5, 1fr); gap: 4px; padding: 0; margin: 0; font-size: 12px; }
.belts li { padding: 8px 4px 0; border-top: 6px solid rgba(255, 255, 255, 0.3); text-align: center; }
.belts li.filled { border-top-color: #fff; }
.card-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; }
.ranges { display: flex; gap: 6px; }
.ranges [aria-pressed="true"] { background: var(--brand-soft); color: var(--brand-pressed); box-shadow: none; }
.legend { color: var(--muted); font-size: 13px; display: flex; align-items: center; gap: 6px; }
.legend .key { display: inline-block; width: 18px; height: 3px; background: var(--brand); }
.legend .key.bench { background: var(--muted); margin-left: 12px; }
.factors { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; }
.ring-row { display: flex; align-items: center; gap: 10px; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); }
.table-wrap { position: relative; overflow-x: auto; }
.belt-counts { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.belt-counts li { display: grid; gap: 4px; text-align: center; background: var(--bg); border-radius: var(--radius-small); padding: 10px; }
.belt-counts b { font: 700 22px var(--font-title); color: var(--ink); }
.habits { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; margin: 0; }
.habits dd { margin: 0; font: 700 22px var(--font-title); color: var(--ink); }
.weak { margin: 0; padding-left: 20px; }
@media (max-width: 760px) { .belt-counts { grid-template-columns: repeat(3, 1fr); } .hero .iq { font-size: 52px; } }
/* First-run tour */
.tour { position: fixed; right: 16px; bottom: 16px; z-index: 20; width: min(380px, calc(100% - 32px)); background: var(--ink); color: #fff;
  border-radius: var(--radius-card); padding: 16px; box-shadow: var(--shadow); display: grid; gap: 12px; }
.tour[hidden] { display: none; }
.tour-buttons { display: flex; justify-content: flex-end; gap: 8px; }
.tour-focus { outline: 4px solid var(--gold); outline-offset: 4px; border-radius: var(--radius-card); position: relative; z-index: 10; }
.menu { position: relative; }
.menu summary { list-style: none; }
.menu summary::-webkit-details-marker { display: none; }
.menu ul { position: absolute; right: 0; z-index: 15; list-style: none; margin: 6px 0 0; padding: 8px; min-width: 240px; background: var(--surface);
  border-radius: var(--radius-small); box-shadow: var(--shadow); }
.menu li a { display: block; padding: 6px 10px; border-radius: 8px; text-decoration: none; color: var(--ink); }
.menu li a:hover { background: var(--bg); }
/* Permission matrix: horizontal scroll inside the card, permission column fixed (AC11). */
.matrix-wrap { position: relative; overflow-x: auto; max-width: 100%; }
.matrix { border-collapse: separate; border-spacing: 0; min-width: 100%; }
.matrix th, .matrix td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: center; white-space: nowrap; }
.matrix .perm-col { position: sticky; left: 0; z-index: 2; background: var(--surface); text-align: left; min-width: 220px; white-space: normal; }
.matrix thead th { position: sticky; top: 0; background: var(--surface); vertical-align: bottom; }
.matrix thead th small { display: block; color: var(--muted); font-weight: 400; }
.matrix .group-head th { text-align: left; background: var(--bg); color: var(--ink); font-family: var(--font-title); }
.matrix .locked { background: var(--locked); }
.matrix .rename input { width: 9em; font: inherit; font-weight: 700; border: 1px solid transparent; border-radius: 8px; padding: 4px 6px; text-align: center; }
.matrix .rename input:focus { border-color: var(--line); }
.box { width: 28px; height: 28px; border-radius: 8px; border: 2px solid var(--line); background: var(--surface); color: #fff; font-weight: 700; cursor: pointer; }
.box.checked { background: var(--brand); border-color: var(--brand); }
.box[disabled] { cursor: not-allowed; opacity: 0.55; }
.link { background: none; border: 0; color: var(--error-ink); cursor: pointer; font: inherit; font-size: 12px; text-decoration: underline; }
.in-use { color: var(--muted); }
.search input { font: inherit; padding: 8px 12px; border-radius: var(--radius-pill); border: 1px solid var(--line); min-width: 220px; }
.cell-error { display: block; max-width: 14em; margin-top: 4px; color: var(--error-ink); font-size: 12px; white-space: normal; }
