:root {
  color-scheme: dark;
  --bg: #0e0e0f; --surface: #1a1a1c; --surface-2: #232326; --ink: #ececee; --muted: #9b9ba1; --line: #2e2e32;
  --header: #000000; --link: #7db4f5; --link-hover: #a9cdfa;
  --accent: #3987e5; --accent-soft: rgba(57, 135, 229, .16); --accent-2: #d95926;
  --btn: #3987e5; --btn-ink: #ffffff; --input: #121214; --input-line: #3a3a3f;
  --red: #ff6b6b; --red-bg: rgba(255, 82, 82, .16); --amber: #ffb84d; --amber-bg: rgba(255, 170, 40, .16);
  --ok: #5fd68a; --ok-bg: rgba(76, 200, 120, .15); --grey: #b4b4ba; --grey-bg: #2a2a2e;
  --radius: 10px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 15px; color: var(--ink);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); line-height: 1.45; }
a { color: var(--link); text-decoration: underline; text-decoration-color: rgba(125, 180, 245, .35); text-underline-offset: 2px; }
a:hover { color: var(--link-hover); text-decoration-color: currentColor; }
h1 { font-size: 1.6rem; margin: 0 0 4px; }
h2 { font-size: 1.15rem; margin: 0 0 12px; }
h3 { font-size: 1rem; margin: 18px 0 8px; }
p.lead { color: var(--muted); margin: 0 0 20px; }
small, .muted { color: var(--muted); }

header.top { background: var(--header); color: var(--ink); border-bottom: 2px solid var(--accent); padding: 10px 20px; display: flex; flex-wrap: wrap; align-items: center; gap: 8px 18px; position: sticky; top: 0; z-index: 5; }
header.top .brand { color: #fff; text-decoration: none; font-weight: 600; display: flex; align-items: center; gap: 8px; }
header.top .brand img { border-radius: 5px; }
.local-badge { font-size: 11px; background: #ffffff22; padding: 2px 8px; border-radius: 99px; }
header.top nav { display: flex; flex-wrap: wrap; gap: 2px; margin-left: auto; }
header.top nav a { color: #b9b9bf; text-decoration: none; padding: 6px 10px; border-radius: 6px; font-size: 14px; }
header.top nav a:hover { background: #ffffff1a; text-decoration: none; }
header.top nav a.on { background: var(--accent-soft); color: #a9cdfa; font-weight: 600; box-shadow: inset 0 -2px 0 var(--accent); }

main { max-width: 1240px; margin: 0 auto; padding: 24px 20px 60px; }
.pagehead { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-end; gap: 12px; margin-bottom: 18px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; margin-bottom: 18px; }
.grid { display: grid; gap: 18px; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }
.grid > .card { margin-bottom: 0; }
.stack > * + * { margin-top: 18px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 18px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.stat b { display: block; font-size: 1.6rem; font-variant-numeric: tabular-nums; }
.stat span { color: var(--muted); font-size: 13px; }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 7px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; background: var(--surface-2); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
tr.total td { font-weight: 600; background: var(--surface-2); }
tr.flag td { background: rgba(255, 170, 40, .06); }
.tablewrap { overflow-x: auto; }
td.nowrap, .nowrap { white-space: nowrap; }

.badge { display: inline-block; padding: 1px 8px; border-radius: 99px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.badge.red { background: var(--red-bg); color: var(--red); }
.badge.amber { background: var(--amber-bg); color: var(--amber); }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.grey { background: var(--grey-bg); color: var(--grey); }

.alerts { list-style: none; margin: 0; padding: 0; }
.alerts li { display: flex; gap: 10px; align-items: baseline; padding: 8px 0; border-bottom: 1px solid var(--line); }
.alerts li:last-child { border-bottom: 0; }
.alerts .area { color: var(--muted); font-size: 12px; min-width: 92px; }
.alerts .what { flex: 1; }
.alerts .what b { font-weight: 600; }

.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 16px; }
.flash.ok { background: var(--ok-bg); color: var(--ok); }
.flash.err { background: var(--red-bg); color: var(--red); }
.empty { color: var(--muted); font-style: italic; }
.note { background: var(--grey-bg); border-radius: 8px; padding: 10px 14px; font-size: 14px; color: var(--muted); }

form.form { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px 16px; align-items: start; }
form.inline { display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: flex-end; }
.field { display: flex; flex-direction: column; gap: 4px; font-size: 13px; }
.field > span { font-weight: 600; color: var(--muted); }
.field.wide { grid-column: 1 / -1; }
.field small { font-size: 12px; }
input, select, textarea { font: inherit; font-size: 14px; padding: 7px 9px; border: 1px solid var(--input-line); border-radius: 7px; background: var(--input); color: var(--ink); width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }
input[readonly] { color: var(--muted); }
input[type=checkbox] { width: auto; }
textarea { min-height: 70px; resize: vertical; }
form.inline .field { min-width: 140px; }
.actions { grid-column: 1 / -1; display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
button, .btn { font: inherit; font-size: 14px; font-weight: 600; padding: 8px 14px; border-radius: 7px; border: 1px solid var(--btn); background: var(--btn); color: var(--btn-ink); cursor: pointer; display: inline-block; text-decoration: none; }
button:hover, .btn:hover { background: #5a9cec; border-color: #5a9cec; color: #fff; }
button.secondary, .btn.secondary { background: transparent; color: var(--ink); border-color: #4a4a50; }
button.secondary:hover, .btn.secondary:hover { background: var(--surface-2); color: #fff; border-color: #6a6a70; }
button.danger { background: transparent; color: var(--red); border-color: var(--red); }
button.danger:hover { background: var(--red-bg); color: var(--red); border-color: var(--red); }
button.small, .btn.small { padding: 4px 10px; font-size: 13px; }
details > summary { cursor: pointer; font-weight: 600; color: var(--link); margin: 6px 0; }
h2 { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.card > h2::before { content: ''; width: 4px; height: 1em; border-radius: 2px; background: var(--accent); }
.tag { display: inline-block; font-size: 11px; font-weight: 700; padding: 1px 6px; border-radius: 4px; background: var(--grey-bg); color: var(--grey); }
.tag.dji { background: rgba(57, 135, 229, .2); color: #8fbcf3; }
.tag.fpv { background: rgba(217, 89, 38, .2); color: #f0946c; }
.chartbox { position: relative; height: 320px; }
.issue-list li { margin-bottom: 6px; }

@media (max-width: 700px) {
  main { padding: 16px; }
  header.top nav { margin-left: 0; }
  .grid { grid-template-columns: 1fr; }
  .alerts li { flex-wrap: wrap; gap: 4px 10px; }
  .alerts .what { flex-basis: 100%; }
}
@media print {
  header.top, form, .no-print { display: none !important; }
  body { background: #fff; color: #000; }
  .card { border: 0; padding: 0; }
}

code { background: var(--surface-2); padding: 1px 5px; border-radius: 4px; font-size: 13px; }

/* Dashboard tiles: coloured edge shows status; whole tile links to its page */
.stat.tile { display: block; color: var(--ink); text-decoration: none; border-top: 3px solid var(--accent); transition: background .15s; }
.stat.tile:hover { background: var(--surface-2); color: var(--ink); }
.stat.tile.ok { border-top-color: #0ca30c; }
.stat.tile.amber { border-top-color: #fab219; }
.stat.tile.red { border-top-color: #d03b3b; }
.stat.tile.red b { color: var(--red); }
.stat.tile.amber b { color: var(--amber); }
.stat.tile.accent b { color: #a9cdfa; }
h2.section { margin: 28px 0 12px; font-size: 1.25rem; }
h2.section::before { content: ''; width: 4px; height: 1em; border-radius: 2px; background: var(--accent-2); }
.card.attention { border-color: rgba(255, 170, 40, .45); box-shadow: inset 3px 0 0 #fab219; }
.chartbox.short { height: 240px; }
p.small, .small { font-size: 13px; }
.meter-row { margin: 10px 0 14px; }
.meter-head { display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; font-size: 14px; margin-bottom: 6px; }
.meter { height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.meter span { display: block; height: 100%; border-radius: 99px; }
.meter span.ok { background: #0ca30c; }
.meter span.red { background: #d03b3b; }
.alerts.compact li { padding: 6px 0; }
details.card { padding: 0; }
details.card > summary { padding: 14px 20px; margin: 0; list-style: none; display: flex; gap: 12px; align-items: center; flex-wrap: wrap; color: var(--ink); }
details.card > summary::-webkit-details-marker { display: none; }
details.card > summary::before { content: '▸'; color: var(--accent); transition: transform .15s; }
details.card[open] > summary::before { transform: rotate(90deg); }
details.card > summary:hover { background: var(--surface-2); border-radius: var(--radius); }
details.card > :not(summary) { margin-left: 20px; margin-right: 20px; }
details.card[open] { padding-bottom: 16px; }
details.card.month .month-name { font-weight: 700; font-size: 1.05rem; min-width: 150px; }

/* Signed-in user, top right */
form.whoami { display: flex; align-items: center; gap: 10px; font-size: 13px; }
form.whoami a { color: #b9b9bf; }
/* Sign-in page */
.login-wrap { max-width: 400px; margin: 8vh auto 0; }
.login-wrap form.form { grid-template-columns: 1fr; }

/* Grouped tabs: Upload sits last as a highlighted action; sub-tabs sit under the header */
header.top nav a.upload { margin-left: 6px; border: 1px solid var(--accent); color: #a9cdfa; }
header.top nav a.upload.on, header.top nav a.upload:hover { background: var(--accent); color: #fff; box-shadow: none; }
nav.subtabs { display: flex; gap: 4px; padding: 0 20px; background: #0b0b0c; border-bottom: 1px solid var(--line); overflow-x: auto; }
nav.subtabs a { padding: 10px 14px; color: var(--muted); text-decoration: none; font-size: 14px; font-weight: 600; border-bottom: 2px solid transparent; white-space: nowrap; }
nav.subtabs a:hover { color: var(--ink); }
nav.subtabs a.on { color: #a9cdfa; border-bottom-color: var(--accent); }

/* Settings (cog) and Account (person) icons, top right */
.icon-btn { display: inline-flex; align-items: center; justify-content: center; width: 34px; height: 34px; border-radius: 8px; color: #b9b9bf; text-decoration: none; }
.icon-btn:hover { background: var(--surface-2); color: #fff; }
.icon-btn.on { background: var(--accent-soft); color: #a9cdfa; box-shadow: inset 0 -2px 0 var(--accent); }
form.whoami { gap: 4px; }
form.whoami button { margin-left: 6px; }
