:root { --topbar-h: 52px; --nav-w: 236px; --active-bg: #e8eefc; --bg: #f6f7f9; --card: #fff; --ink: #1d2433; --muted: #667085; --line: #e3e6eb; --accent: #2659c7; --good: #1f8a4c; --warn: #b26b00; --bad: #b42318; }
* { box-sizing: border-box; }
body { margin: 0; font: 15px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif; background: var(--bg); color: var(--ink); }
main { flex: 1; min-width: 0; max-width: 1100px; margin: 0 auto; padding: 24px 16px 48px; }
h1 { font-size: 24px; margin: 8px 0 16px; } h2 { font-size: 17px; margin: 0 0 12px; } h3 { font-size: 15px; }
a { color: var(--accent); }
.topbar { position: sticky; top: 0; z-index: 30; display: flex; align-items: center; gap: 16px; height: var(--topbar-h); padding: 0 16px; background: var(--card); border-bottom: 1px solid var(--line); }
.topbar-actions { display: flex; align-items: center; gap: 12px; margin-left: auto; flex-wrap: nowrap; min-width: 0; overflow-x: auto; white-space: nowrap; }
.brand { flex: none; }
.topbar-actions a { text-decoration: none; padding: 4px 6px; border-radius: 6px; }
.topbar-actions a.active { background: var(--active-bg); font-weight: 600; }
.topbar-actions form { margin: 0; }
.tabs a { padding: 6px 10px; border-radius: 6px; text-decoration: none; color: var(--ink); }
.tabs a.active { background: var(--active-bg); color: var(--accent); font-weight: 600; }
.brand { font-weight: 700; text-decoration: none; color: var(--ink); }
.tabs { display: flex; gap: 4px; margin-bottom: 12px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 16px; margin-bottom: 16px; }
.narrow { max-width: 420px; margin: 80px auto; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; }
.kpi span { display: block; color: var(--muted); font-size: 13px; } .kpi strong { font-size: 20px; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 7px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { color: var(--muted); font-weight: 600; font-size: 13px; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.muted { color: var(--muted); font-size: 13px; }
.badge { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; background: #eef0f3; }
.badge.categorise { background: #fff1db; color: var(--warn); } .badge.review { background: #e5f0ff; color: var(--accent); }
.badge.conflict { background: #fde8e7; color: var(--bad); } .badge.done { background: #e3f4ea; color: var(--good); }
form.inline { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
input, select, button { font: inherit; padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px; background: var(--card); color: var(--ink); }
button, .button { background: var(--accent); color: var(--card); border-color: var(--accent); cursor: pointer; text-decoration: none; padding: 6px 12px; border-radius: 6px; }
button.link { background: none; border: none; color: var(--accent); padding: 0 4px; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 12px; }
.title-row { display: flex; justify-content: space-between; align-items: center; }
.errors { color: var(--bad); } .error { color: var(--bad); }
.bars { display: grid; gap: 4px; } .bar-row { display: grid; grid-template-columns: 70px 1fr 140px; gap: 8px; align-items: center; }
.bar { background: #eef0f3; border-radius: 4px; height: 12px; } .bar div { background: var(--accent); height: 12px; border-radius: 4px; }
.facts { display: grid; grid-template-columns: 200px 1fr; gap: 6px 12px; margin: 0; } .facts dt { color: var(--muted); } .facts dd { margin: 0; }
.tree { list-style: none; padding: 0; margin: 0 0 12px; } .tree li { padding: 4px 0; border-bottom: 1px solid var(--line); }
.embed { min-height: 600px; border: 1px solid var(--line); border-radius: 8px; }
.load-status { margin-top: 12px; }
.inline { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
button.secondary { background: var(--card); color: var(--accent); }
button.danger { background: var(--bad); border-color: var(--bad); color: #fff; }
button.link.danger { background: none; border: none; color: var(--bad); }
label.check { flex-direction: row; align-items: center; gap: 4px; }
.pager { display: flex; gap: 12px; }

/* Tree editor (FR-HIE-02) */
.tree li { display: flex; align-items: center; gap: 8px; padding-top: 2px; padding-bottom: 2px; }
.tree .node-name { min-width: 14rem; }
.tree .node-keys { width: 12rem; }
.tree .node-actions { display: flex; gap: 4px; flex-wrap: wrap; }
.tree button.link.danger { color: var(--bad); background: none; }
p.error { color: var(--danger, #b42318); }

/* Report filters and layouts (FR-REP-02) */
form.filters { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; }
form.filters label { display: flex; flex-direction: column; gap: 4px; font-size: 0.85rem; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 28rem), 1fr)); gap: 16px; }
.report-list { margin: 0; padding-left: 1.2rem; line-height: 1.8; }
.embed iframe { width: 100%; height: 900px; border: 0; }

/* Account settings */
form.settings { display: flex; flex-direction: column; gap: 14px; max-width: 44rem; }
form.settings label:not(.check) { display: flex; flex-direction: column; gap: 4px; }
p.ok { color: var(--ok, #067647); }

/* Administration */
details.group { border-top: 1px solid var(--line); padding: 10px 0; }
details.group summary { cursor: pointer; font-weight: 600; }
.cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 18rem), 1fr)); gap: 16px; margin: 10px 0; }
fieldset { border: 1px solid var(--line); border-radius: 8px; display: flex; flex-direction: column; gap: 4px; }

/* Dark theme (FR-ADM-05): chosen in the header, remembered in this browser. */
:root[data-theme="dark"] { --active-bg: #23304d; --bg: #12161f; --card: #1b2130; --ink: #e6e9ef; --muted: #98a2b3; --line: #2c3446; --accent: #7aa2ff; --good: #4cc38a; --warn: #f0b252; --bad: #f97066; color-scheme: dark; }
:root[data-theme="dark"] input, :root[data-theme="dark"] select, :root[data-theme="dark"] textarea { background: #11151d; color: var(--ink); border-color: var(--line); }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) { --active-bg: #23304d; --bg: #12161f; --card: #1b2130; --ink: #e6e9ef; --muted: #98a2b3; --line: #2c3446; --accent: #7aa2ff; --good: #4cc38a; --warn: #f0b252; --bad: #f97066; color-scheme: dark; }
}
.theme-toggle { font-size: 16px; line-height: 1; background: none; border: 1px solid var(--line); color: var(--ink); border-radius: 6px; padding: 4px 8px; cursor: pointer; }

/* Project board (FR-PRJ-03) */
.board { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(14rem, 1fr); gap: 12px; overflow-x: auto; margin-top: 12px; }
.board .column { background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 10px; min-height: 12rem; }
.board .card-item { border: 1px solid var(--line); border-radius: 6px; padding: 8px; margin-bottom: 8px; background: var(--bg); cursor: grab; }

/* Surveys */
fieldset.question { margin-bottom: 10px; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.branches { display: flex; flex-direction: column; gap: 4px; width: 100%; }
@media print { .topbar, .sidenav, button, .theme-toggle { display: none !important; } }

/* Tree editor drag and drop */
.tree { list-style: none; margin: 0; padding: 0; }
.tree li { border-radius: 6px; border: 1px solid transparent; }
.tree li:hover { background: var(--bg); }
.tree li.dragging { opacity: 0.4; }
.tree li.drop-before { border-top: 2px solid var(--accent); }
.tree li.drop-after { border-bottom: 2px solid var(--accent); }
.tree li.drop-inside { background: color-mix(in srgb, var(--accent) 15%, transparent); border-color: var(--accent); }
.tree .handle { cursor: grab; color: var(--muted); padding: 0 4px; user-select: none; }
.tree .twisty { width: 1.4em; text-align: center; color: var(--muted); }
.tree .node-actions { opacity: 0.35; }
.tree li:hover .node-actions, .tree li:focus-within .node-actions { opacity: 1; }
.tree-tools { margin-bottom: 8px; } .tree-tools input[type=search] { width: auto; min-width: 16rem; }
.drop-root { margin-top: 8px; padding: 12px; border: 2px dashed var(--line); border-radius: 8px; text-align: center; color: var(--muted); }

/* Layout fixes: controls keep a sensible width, wide tables scroll inside their card */
form.inline input, form.inline select, form.inline textarea { width: auto; max-width: 100%; }
.card table select { width: auto; max-width: 15rem; }
.card { overflow-x: auto; }
td form { margin: 0; }

/* Main menu (FR-UI-01 to FR-UI-03) and icons (FR-UI-09, FR-UI-12) */
.shell { display: flex; align-items: flex-start; min-height: calc(100vh - var(--topbar-h)); }
.sidenav { position: sticky; top: var(--topbar-h); flex: none; width: var(--nav-w); height: calc(100vh - var(--topbar-h)); overflow-y: auto; padding: 8px; background: var(--card); border-right: 1px solid var(--line); display: flex; flex-direction: column; gap: 2px; }
.nav-link, .nav-section-toggle { display: flex; align-items: center; gap: 10px; width: 100%; min-height: 34px; padding: 6px 8px; border: 0; border-radius: 6px; background: none; color: var(--ink); text-decoration: none; font: inherit; text-align: left; cursor: pointer; }
.nav-link:hover, .nav-section-toggle:hover { background: var(--bg); }
.nav-link.active { background: var(--active-bg); color: var(--accent); font-weight: 600; }
.nav-section-toggle { font-weight: 600; }
.nav-section-toggle .chevron { margin-left: auto; color: var(--muted); transition: transform .15s; }
.nav-section-toggle[aria-expanded="true"] .chevron { transform: rotate(90deg); }
.nav-items { padding-left: 14px; }
.nav-group-label { display: block; padding: 8px 8px 2px; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.nav-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-collapse { align-self: flex-end; background: none; border: 1px solid var(--line); color: var(--muted); padding: 2px 8px; margin-bottom: 4px; }
.menu-button { display: none; background: none; color: var(--ink); border: 1px solid var(--line); padding: 4px 10px; }
.nav-backdrop { display: none; }
/* A fixed box with the label's initial under the image: a missing icon changes nothing else. */
.icon { position: relative; flex: none; display: inline-grid; place-items: center; width: 20px; height: 20px; overflow: hidden; border-radius: 4px; background: var(--line); color: var(--muted); font-size: 11px; font-weight: 700; line-height: 1; }
.icon img { position: absolute; inset: 0; width: 20px; height: 20px; background: var(--card); }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip-link { position: absolute; left: -999px; } .skip-link:focus { left: 8px; top: 8px; z-index: 50; background: var(--card); padding: 6px 10px; }

/* Collapsed to a bar of icons; page names show as tooltips (FR-UI-02). */
@media (min-width: 801px) {
  :root[data-nav="collapsed"] .sidenav { width: 56px; }
  :root[data-nav="collapsed"] .nav-label, :root[data-nav="collapsed"] .nav-section-toggle, :root[data-nav="collapsed"] .nav-group { display: none; }
  :root[data-nav="collapsed"] .nav-items[hidden] { display: block; }
  :root[data-nav="collapsed"] .nav-items { padding-left: 0; }
  :root[data-nav="collapsed"] .nav-section { border-top: 1px solid var(--line); padding-top: 2px; }
  :root[data-nav="collapsed"] .nav-collapse { align-self: center; transform: rotate(180deg); }
}

/* Small screens: the menu opens over the page from the menu button. */
@media (max-width: 800px) {
  .menu-button { display: inline-block; }
  .nav-collapse { display: none; }
  .topbar { gap: 8px; padding: 0 8px; }
  .topbar-actions { gap: 2px; font-size: 13px; }
  .sidenav { position: fixed; z-index: 40; left: 0; top: var(--topbar-h); width: min(85vw, 300px); transform: translateX(-105%); transition: transform .2s; box-shadow: 0 8px 24px rgba(0,0,0,.2); }
  .nav-mobile-open .sidenav { transform: none; }
  .nav-mobile-open .nav-backdrop { display: block; position: fixed; inset: var(--topbar-h) 0 0 0; z-index: 35; background: rgba(0,0,0,.35); }
}

/* Report pages fill the width and the available height (FR-REP-08). */
main:has(.report-page) { max-width: none; }
.report-page .embed { min-height: 0; height: calc(100vh - var(--topbar-h) - 150px); }
.report-page .embed iframe { height: 100%; }
.report-cards { list-style: none; margin: 0 0 16px; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 18rem), 1fr)); gap: 10px; }
.report-cards li { border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; }
.report-cards a { font-weight: 600; }
.report-cards p { margin: 4px 0 0; }

/* Paged lists (FR-UI-05 to FR-UI-08) */
.pager { align-items: center; justify-content: space-between; flex-wrap: wrap; margin-top: 12px; }
.pager-links { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.pager .disabled { color: var(--muted); }
.pager a { text-decoration: none; }
form.list-filter { margin-bottom: 12px; }
form.list-filter input[type="search"] { min-width: min(100%, 26rem); }

/* Platform staff working in another account (FR-ACC-05). */
.staff-visit { background: #b45309; color: #fff; border-radius: 4px; padding: 2px 8px; font-weight: 600; text-decoration: none; }

/* The logo next to the name in the top bar, and above the sign-in form. */
.brand { display: inline-flex; align-items: center; gap: 8px; }
.brand-logo { display: block; }
.login-logo { display: block; margin: 0 auto 12px; }
