/* Clarion-style theme: Barlow type, navy, coral accent, pale blue surfaces. */
@font-face { font-family: Barlow; font-weight: 400; font-display: swap; src: url(fonts/barlow-400.woff2) format("woff2"); }
@font-face { font-family: Barlow; font-weight: 500; font-display: swap; src: url(fonts/barlow-500.woff2) format("woff2"); }
@font-face { font-family: Barlow; font-weight: 600; font-display: swap; src: url(fonts/barlow-600.woff2) format("woff2"); }
@font-face { font-family: Barlow; font-weight: 700; font-display: swap; src: url(fonts/barlow-700.woff2) format("woff2"); }

:root {
  color-scheme: light;
  --navy: #003a56;
  --navy-dark: #002a3f;
  --coral: #c54d61;
  --coral-bright: #f1627d;
  --ink: #1b2a33;
  --muted: #55636c;
  --line: #d6e0e6;
  --surface: #ffffff;
  --page: #f6f9fb;
  --tint: #f3f9fc;
  --ok: #06774a;
  --ok-bg: #e6f5ee;
  --warn: #8a5a00;
  --warn-bg: #fdf3dc;
  --bad: #a3263c;
  --bad-bg: #fbe9ec;
  --radius: 4px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--page); color: var(--ink); font: 500 15px/1.45 Barlow, Arial, Helvetica, sans-serif; }
a { color: var(--navy); }
h1, h2, h3 { color: var(--navy); font-weight: 600; line-height: 1.2; margin: 0; }
h1 { font-size: 28px; }
h2 { font-size: 19px; }
h3 { font-size: 15px; }
p { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.num { text-align: right; font-variant-numeric: tabular-nums; }

.skip { position: absolute; left: -999px; top: 0; background: var(--tint); padding: 8px 12px; z-index: 50; }
.skip:focus { left: 8px; top: 8px; }
:focus-visible { outline: 2px solid var(--coral); outline-offset: 2px; }

/* Header */
.topbar { background: var(--surface); border-bottom: 3px solid var(--coral-bright); }
.topbar-inner { display: flex; align-items: center; gap: 24px; flex-wrap: wrap; padding: 10px 24px; }
.brand { display: flex; align-items: center; gap: 12px; text-decoration: none; color: var(--navy); }
.brand img { height: 46px; width: auto; display: block; }
.brand span { font-weight: 600; font-size: 16px; border-left: 1px solid var(--line); padding-left: 12px; }
.nav { display: flex; flex-wrap: wrap; gap: 2px; flex: 1; }
.nav a { padding: 8px 12px; text-decoration: none; font-weight: 600; color: var(--navy); border-radius: var(--radius); }
.nav a:hover { background: var(--tint); }
.nav a[aria-current="page"] { background: var(--navy); color: #fff; }
.who { display: flex; align-items: center; gap: 10px; font-size: 14px; }
.role { background: var(--tint); color: var(--navy); border-radius: 999px; padding: 2px 10px; font-weight: 600; font-size: 12px; }

main { padding: 20px 24px 48px; max-width: 1680px; margin: 0 auto; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; flex-wrap: wrap; gap: 12px; margin-bottom: 16px; }
.page-head p { color: var(--muted); max-width: 72ch; margin-top: 4px; }

/* Buttons and inputs */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 36px; padding: 6px 14px; border-radius: var(--radius); border: 1px solid var(--navy); background: var(--navy); color: #fff; font: 600 14px Barlow, Arial, sans-serif; text-decoration: none; cursor: pointer; }
.btn:hover { background: var(--navy-dark); }
.btn.secondary { background: var(--surface); color: var(--navy); }
.btn.secondary:hover { background: var(--tint); }
.btn.link { background: none; border: 0; color: var(--navy); text-decoration: underline; padding: 6px; min-height: 0; }
input, select, textarea { font: 500 14px Barlow, Arial, sans-serif; color: var(--ink); background: var(--surface); border: 1px solid #8fa3ae; border-radius: var(--radius); padding: 6px 8px; min-height: 36px; max-width: 100%; }
textarea { width: 100%; min-height: 70px; }
label.field { display: grid; gap: 4px; font-weight: 600; font-size: 13px; color: var(--navy); }
label.field .hint { font-weight: 500; color: var(--muted); }
.check { display: flex; align-items: center; gap: 8px; font-weight: 500; }
.check input { min-height: 0; width: 16px; height: 16px; accent-color: var(--navy); }

/* Cards */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 6px; padding: 16px; }
.card > h2 { margin-bottom: 10px; }
/* Let grid children shrink, so wide tables scroll inside their card on a phone. */
.stack > *, .grid-2 > *, .tiles > * { min-width: 0; }
dl.facts dd { min-width: 0; overflow-wrap: anywhere; }
.card-note { color: var(--muted); font-size: 13px; margin: -6px 0 10px; }
.stack { display: grid; gap: 16px; }
.grid-2 { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 560px), 1fr)); }
.tiles { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(145px, 1fr)); }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: 6px; padding: 12px 14px; }
.tile .label { color: var(--muted); font-size: 13px; font-weight: 600; }
.tile .value { color: var(--navy); font-size: 28px; font-weight: 600; line-height: 1.15; margin-top: 2px; font-variant-numeric: tabular-nums; }
.tile .sub { color: var(--muted); font-size: 13px; }
.chart { width: 100%; height: 340px; }

/* Tables */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 14px; }
table.data th { text-align: left; color: var(--navy); font-weight: 600; border-bottom: 2px solid var(--navy); padding: 6px 8px; vertical-align: bottom; }
table.data th.num { text-align: right; }
table.data td { border-bottom: 1px solid var(--line); padding: 6px 8px; vertical-align: top; }
table.data tr.total td { font-weight: 700; border-top: 2px solid var(--navy); border-bottom: 0; }
table.data tr.region th { background: var(--tint); border-bottom: 1px solid var(--line); padding-top: 8px; }
table.data tr.subtotal td { font-weight: 600; border-top: 1px solid var(--navy); }
dl.facts { display: grid; grid-template-columns: minmax(130px, max-content) 1fr; gap: 3px 14px; margin: 0; font-size: 14px; }
dl.facts dt { color: var(--muted); }
dl.facts dd { margin: 0; white-space: pre-line; }

/* Filters */
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: flex-end; background: var(--surface); border: 1px solid var(--line); border-radius: 6px; padding: 10px 12px; margin-bottom: 16px; }
.filter { position: relative; }
.filter summary { list-style: none; cursor: pointer; min-height: 36px; display: flex; align-items: center; gap: 6px; padding: 6px 10px; border: 1px solid #8fa3ae; border-radius: var(--radius); font-size: 14px; background: var(--surface); white-space: nowrap; }
.filter summary::-webkit-details-marker { display: none; }
.filter summary::after { content: "▾"; color: var(--muted); }
.filter[data-active="true"] summary { border-color: var(--navy); background: var(--tint); font-weight: 600; }
.filter-panel { position: absolute; z-index: 40; top: calc(100% + 4px); left: 0; background: var(--surface); border: 1px solid var(--line); border-radius: 6px; box-shadow: 0 6px 18px rgba(0,42,63,.16); padding: 8px 10px; display: grid; gap: 4px; max-height: 320px; overflow: auto; min-width: 220px; }
.filter-search { min-width: 200px; flex: 1 1 200px; }
.filter-actions { display: flex; gap: 6px; margin-left: auto; flex-wrap: wrap; }

/* Pills and status */
.pill { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--tint); color: var(--navy); margin: 1px 2px 1px 0; white-space: nowrap; }
.pill.warn { background: var(--warn-bg); color: var(--warn); }
.pill.bad { background: var(--bad-bg); color: var(--bad); }
.status { display: inline-block; padding: 4px 10px; border-radius: var(--radius); font-size: 14px; }
.status.ok { background: var(--ok-bg); color: var(--ok); }
.status.error { background: var(--bad-bg); color: var(--bad); }
.banner { padding: 10px 14px; border-radius: var(--radius); margin-bottom: 14px; }
.banner.ok { background: var(--ok-bg); color: var(--ok); }
.banner.error { background: var(--bad-bg); color: var(--bad); }
.banner.info { background: var(--tint); color: var(--navy); }

/* Data grids */
.totals { display: flex; flex-wrap: wrap; gap: 8px 20px; align-items: baseline; margin-bottom: 10px; font-size: 14px; }
.totals strong { color: var(--navy); font-size: 17px; }
#grid { background: var(--surface); }
.tabulator { font-family: inherit; font-size: 13.5px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); }
.tabulator .tabulator-header { background: var(--navy); color: #fff; border-bottom: 0; font-weight: 600; }
.tabulator .tabulator-header .tabulator-col { background: var(--navy); border-right: 1px solid rgba(255,255,255,.18); }
.tabulator .tabulator-header .tabulator-col.tabulator-sortable:hover { background: var(--navy-dark) !important; }
.tabulator .tabulator-row { border-bottom: 1px solid var(--line); }
.tabulator .tabulator-row.tabulator-row-even { background: #fafcfd; }
.tabulator .tabulator-row:hover { background: var(--tint) !important; }
.tabulator .tabulator-row.tabulator-selected { background: #dceef7 !important; }
.tabulator .tabulator-footer { background: var(--tint); border-top: 1px solid var(--line); color: var(--ink); font-weight: 500; }
.tabulator .tabulator-footer .tabulator-page { color: var(--navy); }
.tabulator .tabulator-footer .tabulator-page.active { background: var(--navy); color: #fff; }

/* Sign in */
.login-page { min-height: 100vh; display: grid; place-items: center; padding: 16px; background: var(--tint); }
.login-card { width: min(100%, 400px); background: var(--surface); border-radius: 8px; border-top: 4px solid var(--coral-bright); box-shadow: 0 8px 28px rgba(0,42,63,.12); padding: 26px; display: grid; gap: 14px; }
.login-card img { height: 56px; width: auto; justify-self: start; }
.login-card input { width: 100%; }
.login-card .btn { width: 100%; }

@media (max-width: 760px) {
  main { padding: 14px 16px 36px; }
  .topbar-inner { padding: 8px 16px; gap: 10px; }
  .brand img { height: 38px; }
  h1 { font-size: 24px; }
  .filter-panel { position: static; box-shadow: none; }
  .filter-actions { margin-left: 0; }
}

@media print {
  .topbar, .filters, .filter-actions { display: none; }
  body { background: #fff; }
}

/* Ageing RAG */
.rag { display: inline-block; min-width: 64px; text-align: center; padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 700; }
.rag.green { background: var(--ok-bg); color: var(--ok); }
.rag.amber { background: var(--warn-bg); color: var(--warn); }
.rag.red { background: var(--bad-bg); color: var(--bad); }
.rag.critical { background: var(--bad); color: #fff; }
.rag.hold { background: #eef1f3; color: var(--muted); }

/* Dashboard */
.as-at { color: var(--muted); font-size: 13px; margin: 0 0 8px; }
.tile.link { text-decoration: none; color: inherit; transition: border-color .15s, box-shadow .15s; }
.tile.link:hover { border-color: var(--navy); box-shadow: 0 2px 8px rgba(0,42,63,.08); }
.tile.link .label::after { content: " ›"; color: var(--coral); }
.card-head { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.card-head h2 { margin: 0; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; }
.sub-head { margin: 18px 0 8px; }
.filter-month select { min-width: 130px; }
.table-toggle { margin-top: 10px; }
.table-toggle summary { cursor: pointer; color: var(--navy); font-weight: 600; font-size: 14px; }
table.data.compact { font-size: 13px; }
table.data.compact th, table.data.compact td { padding: 5px 6px; white-space: nowrap; }
table.data tr.selected td { background: var(--tint); font-weight: 600; }
table.data tr.warn-row td { background: var(--warn-bg); }
.risk-list { display: grid; gap: 2px; margin: 0; padding: 0; list-style: none; }
.risk-list a { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 6px 8px; border-radius: var(--radius); text-decoration: none; }
.risk-list a:hover, .risk-list a[aria-current="true"] { background: var(--tint); }
.risk-list .count { font-weight: 700; color: var(--navy); font-variant-numeric: tabular-nums; font-size: 17px; }
.grid-search { max-width: 360px; margin-bottom: 10px; }
code { font-family: Consolas, "Courier New", monospace; font-size: 13px; background: var(--tint); padding: 1px 5px; border-radius: 3px; }

@media (max-width: 760px) {
  /* The menu becomes one scrollable row under the logo. */
  .nav { order: 3; flex: 1 0 100%; flex-wrap: nowrap; overflow-x: auto; padding-bottom: 2px; }
  .nav a { white-space: nowrap; }
}

/* Upload */
.upload-form { display: grid; gap: 14px; max-width: 520px; }
.upload-form > * { min-width: 0; }
.upload-form input { width: 100%; }
.upload-form input[type="file"] { padding: 8px; }
details.change { border-bottom: 1px solid var(--line); padding: 6px 0; }
details.change summary { cursor: pointer; display: flex; justify-content: space-between; gap: 12px; font-weight: 600; color: var(--navy); }
details.change .count { font-variant-numeric: tabular-nums; }
details.change ul { margin: 6px 0 4px; padding-left: 18px; max-height: 220px; overflow: auto; }
