:root {
  --bg: #f7f5f1;
  --panel: #ffffff;
  --border: #e4e0d8;
  --fg: #241f18;
  --fg-muted: #6b6457;
  --accent: #0b6e4f;
  --ok: #0b6e4f;
  --warn: #a2650f;
  --bad: #b3261e;
  --font-serif: 'Source Serif 4', Georgia, serif;
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --shadow-sm: 0 1px 2px rgba(20, 16, 8, 0.04), 0 1px 1px rgba(20, 16, 8, 0.03);
  --shadow-md: 0 4px 16px rgba(20, 16, 8, 0.06), 0 1px 2px rgba(20, 16, 8, 0.04);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #17160f;
    --panel: #211f17;
    --border: #38352a;
    --fg: #f1ede3;
    --fg-muted: #a39b89;
    --accent: #37c590;
    --ok: #37c590;
    --warn: #e2a33c;
    --bad: #f0786f;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.25);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.3);
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-sans);
  padding: 0 max(16px, env(safe-area-inset-left, 0px)) 48px max(16px, env(safe-area-inset-right, 0px));
}
.wrap { max-width: 72rem; margin-inline: auto; }

/* ---- Top nav, shared across every page ---- */
.topnav {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  max-width: 72rem; margin: 0 auto; padding: 16px max(16px, env(safe-area-inset-left, 0px)) 14px;
  flex-wrap: wrap;
}
.topnav .brand { display: flex; align-items: center; gap: 10px; font-family: var(--font-serif); font-weight: 600; font-size: 1.05rem; color: var(--fg); text-decoration: none; }
.topnav .brand .dot-logo { width: 10px; height: 10px; border-radius: 3px; background: var(--accent); display: inline-block; }
.topnav nav { display: flex; gap: 4px; flex-wrap: wrap; }
.topnav nav a {
  font-size: 0.85rem; font-weight: 600; color: var(--fg-muted); text-decoration: none;
  padding: 7px 14px; border-radius: 999px; transition: background-color 150ms ease, color 150ms ease;
}
.topnav nav a:hover { color: var(--fg); background: color-mix(in srgb, var(--fg) 6%, transparent); }
.topnav nav a.active { color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, transparent); }

header.page-head { margin: 8px 0 28px; }
h1 { font-family: var(--font-serif); font-weight: 600; font-size: clamp(1.5rem, 4vw, 2rem); margin: 0 0 6px; letter-spacing: -0.01em; }
.takeaway { color: var(--fg-muted); font-size: 0.95rem; margin: 0; }
.meta-row { display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: center; margin-top: 10px; font-size: 0.8rem; color: var(--fg-muted); }
.dot { width: 6px; height: 6px; border-radius: 50%; background: var(--ok); display: inline-block; margin-right: 6px; }

.icon { width: 1em; height: 1em; display: inline-block; vertical-align: -0.125em; }

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 13rem), 1fr)); gap: 14px; margin-bottom: 28px; }
.card { background: var(--panel); border: 1px solid var(--border); border-radius: 14px; padding: 18px 20px; box-shadow: var(--shadow-sm); }
.card-icon {
  width: 36px; height: 36px; border-radius: 10px; display: flex; align-items: center; justify-content: center;
  background: color-mix(in srgb, var(--accent) 12%, transparent); color: var(--accent); margin-bottom: 12px;
}
.card-icon svg { width: 18px; height: 18px; }
.card.warn .card-icon { background: color-mix(in srgb, var(--warn) 14%, transparent); color: var(--warn); }
.card.bad .card-icon { background: color-mix(in srgb, var(--bad) 14%, transparent); color: var(--bad); }
.card.ok .card-icon { background: color-mix(in srgb, var(--ok) 14%, transparent); color: var(--ok); }
.card-label { font-size: 0.72rem; color: var(--fg-muted); text-transform: uppercase; letter-spacing: .05em; margin: 0 0 6px; font-weight: 600; }
.card-value { font-family: var(--font-serif); font-weight: 600; font-size: 2rem; font-variant-numeric: tabular-nums; margin: 0; }
.card.warn .card-value { color: var(--warn); }
.card.bad .card-value { color: var(--bad); }
.card.ok .card-value { color: var(--ok); }
.card-sub { font-size: 0.78rem; color: var(--fg-muted); margin: 4px 0 0; }

.tablecard { background: var(--panel); border: 1px solid var(--border); border-radius: 14px; padding: 20px; box-shadow: var(--shadow-sm); margin-bottom: 20px; }
.tablecard-head { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.tablecard-head h2 { font-size: 1.05rem; font-weight: 600; margin: 0; }
.tablecard-head p { margin: 2px 0 0; font-size: 0.82rem; color: var(--fg-muted); }
.search-wrap { position: relative; min-width: 14rem; }
.search-wrap .icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--fg-muted); pointer-events: none; }
.search { font: inherit; font-size: 0.9rem; padding: 8px 12px 8px 34px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); color: var(--fg); width: 100%; transition: border-color 150ms ease, box-shadow 150ms ease; }
.search:focus-visible { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent); }
.table-scroll { overflow-x: auto; max-height: 34rem; overflow-y: auto; border-radius: 8px; }
table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
table.wide { min-width: 48rem; }
th, td { text-align: left; padding: 10px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { position: sticky; top: 0; background: var(--panel); color: var(--fg-muted); font-weight: 600; font-size: 0.72rem; text-transform: uppercase; letter-spacing: .03em; white-space: nowrap; }
th button { all: unset; cursor: pointer; display: inline-flex; align-items: center; gap: 4px; font: inherit; color: inherit; text-transform: inherit; letter-spacing: inherit; padding: 2px; border-radius: 4px; }
th button:hover { color: var(--fg); }
th button:focus-visible, tr.row:focus-visible, a.link:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
td.desc { max-width: 26rem; }
tbody tr.row:hover td { background: color-mix(in srgb, var(--fg) 4%, transparent); }
tbody tr.row { cursor: pointer; transition: background-color 150ms ease; }
td.expand-cell { width: 1.5rem; padding-right: 2px; }
.chevron { display: inline-block; transition: transform 150ms ease; color: var(--fg-muted); }
.chevron svg { width: 16px; height: 16px; display: block; }
tr.row[aria-expanded="true"] .chevron { transform: rotate(90deg); }
tr.detail-row td { background: color-mix(in srgb, var(--fg) 3%, transparent); padding: 16px 20px; }
.detail-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 13rem), 1fr)); gap: 12px 24px; }
.detail-item dt { font-size: 0.68rem; color: var(--fg-muted); text-transform: uppercase; letter-spacing: .04em; margin: 0 0 3px; }
.detail-item dd { margin: 0; font-size: 0.88rem; }
.pill { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 0.72rem; font-weight: 600; white-space: nowrap; }
.pill.pending { background: color-mix(in srgb, var(--fg) 10%, transparent); color: var(--fg-muted); }
.pill.success { background: color-mix(in srgb, var(--ok) 16%, transparent); color: var(--ok); }
.pill.failure { background: color-mix(in srgb, var(--bad) 14%, transparent); color: var(--bad); }
.pill.noresult { background: color-mix(in srgb, var(--fg) 10%, transparent); color: var(--fg-muted); }
.pill.missed { background: color-mix(in srgb, var(--warn) 16%, transparent); color: var(--warn); }
.follow-pill { background: color-mix(in srgb, var(--accent) 14%, transparent); color: var(--accent); }
.urgent { color: var(--bad); font-weight: 600; }
.follow-section { margin-bottom: 16px; }
.follow-pills { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0 10px; }
.follow-none { color: var(--fg-muted); font-size: 0.85rem; }
.follow-form { display: flex; gap: 8px; max-width: 24rem; }
.follow-input { flex: 1; min-width: 0; padding: 7px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--panel); color: var(--fg); font: inherit; font-size: 0.85rem; }
.follow-input:focus-visible { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent); }
.follow-btn { padding: 7px 14px; border: none; border-radius: 8px; background: var(--accent); color: #fff; font: inherit; font-size: 0.85rem; font-weight: 600; cursor: pointer; white-space: nowrap; transition: opacity 150ms ease; }
.follow-btn:hover { opacity: 0.88; }
.follow-btn:disabled { opacity: 0.5; cursor: default; }
.follow-status { font-size: 0.78rem; margin-top: 6px; min-height: 1.2em; }
.follow-status.error { color: var(--bad); }
.follow-status.ok { color: var(--ok); }
a.link { color: var(--fg); text-decoration: underline; text-underline-offset: 2px; }
.empty-row td { text-align: center; color: var(--fg-muted); padding: 32px; }
.skeleton { display: inline-block; height: 1em; width: 6em; border-radius: 4px; background: color-mix(in srgb, var(--fg) 10%, transparent); }
.empty-state { text-align: center; padding: 40px 20px; color: var(--fg-muted); }
.empty-state .big { font-size: 2rem; margin-bottom: 8px; }

/* ---- Hub / home page nav cards ---- */
.hub-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 16rem), 1fr)); gap: 16px; margin-bottom: 28px; }
.hub-card {
  display: block; background: var(--panel); border: 1px solid var(--border); border-radius: 16px; padding: 24px;
  box-shadow: var(--shadow-sm); text-decoration: none; color: inherit; transition: box-shadow 150ms ease, transform 150ms ease;
}
.hub-card:hover { box-shadow: var(--shadow-md); transform: translateY(-2px); }
.hub-card .hub-icon {
  width: 44px; height: 44px; border-radius: 12px; display: flex; align-items: center; justify-content: center;
  background: color-mix(in srgb, var(--accent) 12%, transparent); color: var(--accent); margin-bottom: 14px;
}
.hub-card .hub-icon svg { width: 22px; height: 22px; }
.hub-card h3 { margin: 0 0 6px; font-family: var(--font-serif); font-size: 1.2rem; font-weight: 600; }
.hub-card p { margin: 0; font-size: 0.88rem; color: var(--fg-muted); line-height: 1.5; }
.hub-card .hub-cta { margin-top: 14px; font-size: 0.8rem; font-weight: 600; color: var(--accent); display: flex; align-items: center; gap: 4px; }

/* ---- Performance report: leaderboard, bars ---- */
.lb-row { display: grid; grid-template-columns: 1.5rem 1fr auto; gap: 10px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--border); }
.lb-row:last-child { border-bottom: none; }
.lb-rank { font-family: var(--font-serif); font-weight: 600; color: var(--fg-muted); font-size: 0.9rem; }
.lb-name { font-weight: 600; font-size: 0.92rem; }
.lb-bar-wrap { grid-column: 1 / -1; height: 6px; border-radius: 999px; background: color-mix(in srgb, var(--fg) 8%, transparent); overflow: hidden; margin-top: 2px; }
.lb-bar { height: 100%; background: var(--accent); border-radius: 999px; }
.lb-stats { font-size: 0.8rem; color: var(--fg-muted); white-space: nowrap; }

.note-banner {
  background: color-mix(in srgb, var(--warn) 10%, transparent); border: 1px solid color-mix(in srgb, var(--warn) 30%, transparent);
  border-radius: 12px; padding: 14px 18px; font-size: 0.86rem; color: var(--fg); margin-bottom: 24px; line-height: 1.5;
}
.note-banner strong { color: var(--warn); }

@media (max-width: 480px) {
  .card-value { font-size: 1.6rem; }
}

/* Below this width, a wide scrolling table is a poor fit - reflow each
   row into a self-contained card and collapse the header into a row of
   compact sort chips instead of hiding it entirely. */
@media (max-width: 720px) {
  .table-scroll { overflow: visible; max-height: none; }
  table.wide { min-width: 0; }

  thead tr {
    display: flex; flex-wrap: wrap; gap: 6px;
    position: static; width: auto; height: auto; clip: auto;
    margin: 0 0 14px; padding: 0; border: none; background: none;
  }
  thead th {
    display: inline-flex; width: auto; padding: 0; border: none; background: none; position: static;
  }
  thead th.th-hide-mobile { display: none; }
  thead th button {
    padding: 7px 12px; border: 1px solid var(--border); border-radius: 999px; font-size: 0.72rem; background: var(--bg);
  }

  table.wide tbody, table.wide tr, table.wide td { display: block; width: 100%; }
  table.wide tr.row {
    position: relative;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 14px 44px 14px 14px;
    margin-bottom: 10px;
    box-shadow: var(--shadow-sm);
  }
  table.wide tr.row td { border: none; padding: 3px 0; font-size: 0.92rem; }
  table.wide tr.row td.expand-cell { position: absolute; top: 14px; right: 14px; width: auto; padding: 0; }
  table.wide tr.row td[data-label]::before {
    content: attr(data-label);
    display: block;
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--fg-muted);
    margin-bottom: 2px;
  }
  table.wide tr.row td.company { font-family: var(--font-serif); font-weight: 600; font-size: 1.05rem; padding-right: 20px; }
  table.wide tr.row td.desc { font-size: 0.9rem; color: var(--fg-muted); margin: 4px 0 6px; }
  table.wide tr.detail-row td { padding: 14px; border-radius: 0 0 12px 12px; margin-top: -10px; margin-bottom: 10px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
