/* Design tokens: neutral ground, white cards, dark navigation and one blue accent. */
:root {
  --ground: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #fafbfc;
  --line: #e2e5ea;
  --line-soft: #eef0f3;
  --line-strong: #d5d9e0;
  --ink: #171a1f;
  --ink-2: #4f5663;
  --muted: #636b78;
  --accent: #2457c5;
  --accent-ink: #1a3f91;
  --accent-soft: #eaf0fc;
  --nav: #13171d;
  --nav-active: #252c38;
  --nav-ink: #c9ced6;
  --nav-muted: #8b93a0;
  --ok: #1c6b3f;
  --ok-soft: #e5f3ea;
  --warn: #8a5300;
  --warn-soft: #fdf1dc;
  --warn-line: #f3d9a6;
  --danger: #b42318;
  --danger-soft: #fdecea;
  --danger-line: #e8b4ae;
  font: 14px/1.45 Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--ground);
}
body { margin: 0; background: var(--ground); }
[hidden] { display: none !important; }
a { color: var(--accent); }
a:hover { color: var(--accent-ink); }
:focus-visible { outline: 3px solid #337cbd; outline-offset: 2px; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.block { display: block; }
.mono { font-family: ui-monospace, Consolas, monospace; }
.grow { flex: 1 1 auto; min-width: 0; }

/* Sign-in screen. */
.signin { min-height: 100vh; display: grid; place-items: center; padding: 16px; box-sizing: border-box; }
.signin-card { width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 28px; display: flex; flex-direction: column; gap: 16px; box-sizing: border-box; }
.signin-card p { margin: 0; color: var(--ink-2); }
/* While sign-in finishes, show a spinner before the status line. */
.busy #status { display: flex; align-items: center; gap: 10px; }
.busy #status::before { content: ""; flex: none; width: 18px; height: 18px; border-radius: 50%; border: 2px solid var(--line-strong); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .busy #status::before { animation-duration: 2.4s; } }

/* Shell: navigation beside content, stacking above it on narrow screens. */
.app { display: flex; flex-wrap: wrap; min-height: 100vh; }
.sidebar { flex: 1 1 240px; max-width: 100%; box-sizing: border-box; background: var(--nav); padding: 18px 12px 24px; display: flex; flex-direction: column; gap: 2px; }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 14px; color: #fff; font-weight: 600; font-size: 15px; }
.brand-dark { color: var(--ink); padding: 0; }
.logo { width: 32px; height: 32px; border-radius: 8px; background: #2f6fde; color: #fff; font-weight: 700; font-size: 13px; display: inline-flex; align-items: center; justify-content: center; flex: none; }
#nav { display: flex; flex-direction: column; gap: 2px; }
.nav-head { padding: 16px 10px 6px; font-size: 11px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--nav-muted); }
.nav-link { display: flex; align-items: center; gap: 10px; min-height: 40px; padding: 0 10px; border-radius: 8px; color: var(--nav-ink); font-weight: 500; text-decoration: none; }
a.nav-link:hover { color: #fff; background: #1c222b; }
.nav-link[aria-current="page"] { background: var(--nav-active); color: #fff; font-weight: 600; }
.nav-link.planned { color: var(--nav-muted); }
.nav-link .tag { margin-left: auto; border-color: #3a424f; color: var(--nav-muted); }
.content { flex: 999 1 560px; min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 32px; background: var(--surface); border-bottom: 1px solid var(--line); }
.who { display: flex; align-items: center; gap: 10px; }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); font-weight: 600; font-size: 12px; display: inline-flex; align-items: center; justify-content: center; }
.env { align-self: flex-start; font-size: 12px; font-weight: 600; color: var(--warn); background: var(--warn-soft); border: 1px solid var(--warn-line); padding: 4px 10px; border-radius: 999px; }
.topbar .env { align-self: center; }
.notice { margin: 16px 32px 0; padding: 10px 14px; border-radius: 8px; background: var(--accent-soft); color: var(--accent-ink); }
.page { padding: 28px 32px 56px; display: flex; flex-direction: column; gap: 20px; max-width: 1280px; width: 100%; box-sizing: border-box; outline: none; }

/* Page heading and actions. */
.page-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-end; gap: 12px; }
.page-head h1 { font-size: 26px; font-weight: 700; letter-spacing: -.01em; }
.sub { margin: 4px 0 0; color: var(--ink-2); }
.title-line { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.crumbs { font-size: 13px; color: var(--muted); }
.crumbs a { text-decoration: none; font-weight: 500; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }
.actions.end { justify-content: flex-end; }

/* Buttons. */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 40px; padding: 0 16px; border: 1px solid var(--line-strong); border-radius: 8px; background: var(--surface); color: var(--ink); font: inherit; font-weight: 600; text-decoration: none; cursor: pointer; box-sizing: border-box; }
.btn:hover { color: var(--ink); background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-ink); color: #fff; }
.btn.dark { background: var(--ink); border-color: var(--ink); color: #fff; }
.btn.danger { color: var(--danger); border-color: var(--danger-line); }
.btn.wide { width: 100%; }
.btn:disabled { opacity: .55; cursor: wait; }

/* Cards, sections and columns. */
.card { margin: 0; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 20px; display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.card.flush { padding: 0; gap: 0; }
fieldset.card { min-inline-size: 0; }
.card-title { font-size: 16px; font-weight: 600; padding: 0; }
legend.card-title { float: left; width: 100%; margin-bottom: 4px; }
.section { display: flex; flex-direction: column; gap: 12px; }
.section-title { font-size: 16px; font-weight: 600; }
.minor { font-size: 13px; font-weight: 600; margin: 6px 0; }
.columns { display: flex; flex-wrap: wrap; gap: 20px; align-items: flex-start; }
.columns > * { flex: 1 1 420px; }
.form-columns > .grow-2 { flex: 2 1 520px; }
.form-columns > .review-card { flex: 1 1 280px; }
.stack { display: flex; flex-direction: column; gap: 20px; min-width: 0; }
.empty { margin: 0; color: var(--muted); padding: 4px 0; }
.error-box, .warn-box, .info-box { margin: 0; padding: 12px 14px; border-radius: 8px; }
.error-box { background: var(--danger-soft); color: var(--danger); }
.warn-box { background: var(--warn-soft); color: #6e4200; border: 1px solid var(--warn-line); }
.info-box { background: var(--accent-soft); color: var(--accent-ink); }

/* Key numbers and destination tiles. */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 16px; }
.kpi { display: flex; flex-direction: column; gap: 6px; padding: 18px 20px; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; color: var(--ink); text-decoration: none; }
a.kpi:hover { border-color: var(--line-strong); color: var(--ink); }
.kpi-label { font-size: 13px; font-weight: 500; color: var(--ink-2); }
.kpi-value { font-size: 30px; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.kpi-sub { font-size: 13px; color: var(--muted); }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 16px; }
.tile { display: flex; padding: 18px 20px; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; color: var(--ink-2); text-decoration: none; }
a.tile:hover { border-color: var(--accent); color: var(--ink-2); }
.tile.planned { background: var(--surface-2); border-style: dashed; border-color: var(--line-strong); }
.tile-text { display: flex; flex-direction: column; gap: 4px; }
.tile-title { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 15px; color: var(--ink); }
.tile-meta { font-size: 12px; font-weight: 500; color: var(--muted); }
.tag { font-size: 11px; font-weight: 500; padding: 1px 7px; border: 1px solid var(--line-strong); border-radius: 999px; color: var(--ink-2); }

/* Lists of rows (attention, history, devices). */
.rows { list-style: none; margin: -4px 0; padding: 0; }
.row { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; padding: 11px 0; border-bottom: 1px solid var(--line-soft); }
.row:last-child { border-bottom: 0; }
.when { flex: none; width: 110px; color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.chip { flex: none; display: inline-block; font-size: 12px; font-weight: 600; padding: 2px 9px; border-radius: 999px; white-space: nowrap; }
.chip.ok { color: var(--ok); background: var(--ok-soft); }
.chip.warn { color: var(--warn); background: var(--warn-soft); }
.chip.danger { color: var(--danger); background: var(--danger-soft); }
.chip.info { color: var(--accent-ink); background: var(--accent-soft); }
.chip.off { color: var(--ink-2); background: var(--line-soft); }

/* Filters, fields and toolbars. */
.pills { display: flex; flex-wrap: wrap; gap: 8px; }
.pill { min-height: 36px; padding: 0 14px; border-radius: 999px; border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink); font: inherit; font-weight: 600; cursor: pointer; }
.pill[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: #fff; }
.pill .count { font-variant-numeric: tabular-nums; opacity: .8; }
.toolbar { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.card.toolbar { border-bottom: 1px solid var(--line); flex-direction: row; padding: 14px 16px; }
.field { display: flex; flex-direction: column; gap: 4px; font-size: 13px; font-weight: 600; color: var(--ink-2); }
.field.narrow { max-width: 320px; }
.field-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 14px; }
input:not([type="checkbox"]):not([type="radio"]), select { box-sizing: border-box; min-height: 40px; padding: 0 12px; border: 1px solid var(--line-strong); border-radius: 8px; background: var(--surface); font: inherit; font-size: 14px; font-weight: 400; color: var(--ink); }
.checks { display: flex; flex-direction: column; border-top: 1px solid var(--line-soft); }
.check { display: flex; gap: 12px; align-items: flex-start; padding: 12px 0; border-bottom: 1px solid var(--line-soft); font-weight: 400; }
.check input { width: 16px; height: 16px; margin: 3px 0 0; }
.form-status { margin: 0; min-height: 1.2em; color: var(--ink-2); }
.review { margin: 0; display: flex; flex-direction: column; gap: 10px; }
.review div { display: flex; justify-content: space-between; gap: 12px; }
.review dt { color: var(--ink-2); }
.review dd { margin: 0; font-weight: 600; text-align: right; }

/* Tables. */
.table-scroll { overflow-x: auto; }
table.data { width: 100%; min-width: 720px; border-collapse: collapse; font-variant-numeric: tabular-nums; }
table.data.compact { min-width: 0; }
table.data th { text-align: left; font-size: 12px; font-weight: 600; color: var(--ink-2); background: var(--surface-2); padding: 10px 12px; }
table.data td { padding: 12px; border-top: 1px solid var(--line-soft); vertical-align: top; }
table.data th:first-child, table.data td:first-child { padding-left: 20px; }
.card:not(.flush) table.data th:first-child, .card:not(.flush) table.data td:first-child { padding-left: 12px; }
.strong-link { font-weight: 600; color: var(--ink); text-decoration: none; }
.strong-link:hover { color: var(--accent); text-decoration: underline; }
.table-foot { margin: 0; padding: 12px 20px; border-top: 1px solid var(--line); color: var(--ink-2); }

/* Detail screen pieces. */
.defs { margin: 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px 20px; }
.defs dt { font-size: 12px; font-weight: 600; color: var(--ink-2); }
.defs dd { margin: 2px 0 0; }
.meters { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; }
.meter { display: flex; flex-direction: column; gap: 4px; padding: 12px 14px; border: 1px solid var(--line-soft); border-radius: 8px; background: var(--surface-2); }
.meter-label { font-size: 12px; font-weight: 600; color: var(--ink-2); }
.meter-value { font-size: 16px; font-weight: 600; font-variant-numeric: tabular-nums; }
.meter-bar { display: block; height: 6px; margin: 4px 0; border-radius: 3px; background: var(--line); overflow: hidden; }
.meter-fill { display: block; height: 100%; background: var(--accent); border-radius: 3px; }
.meter-fill.full { background: #c27a00; }
.perm-list { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--line-soft); }
.perm { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line-soft); }

/* Key issued. */
.issued { max-width: 640px; margin: 12px auto 0; width: 100%; box-sizing: border-box; }
.issued h1 { font-size: 22px; }
.done-mark { width: 44px; height: 44px; border-radius: 50%; background: var(--ok-soft); color: var(--ok); font-size: 22px; font-weight: 700; display: inline-flex; align-items: center; justify-content: center; }
.key-field { min-height: 56px !important; font-family: ui-monospace, Consolas, monospace !important; font-size: 20px !important; letter-spacing: .06em; background: var(--surface-2) !important; width: 100%; }

/* Daily chart: thin bars on a zero baseline with a 2px gap. */
.chart { display: flex; gap: 10px; height: 200px; }
.chart-axis { display: flex; flex-direction: column; justify-content: space-between; font-size: 12px; color: var(--muted); text-align: right; font-variant-numeric: tabular-nums; }
.chart-bars { flex: 1; min-width: 0; display: flex; align-items: flex-end; gap: 2px; border-bottom: 1px solid #c9ced6; }
.chart-slot { flex: 1; height: 100%; display: flex; align-items: flex-end; }
.chart-bar { display: block; width: 100%; min-height: 1px; background: var(--accent); border-radius: 4px 4px 0 0; }
/* 180-day account chart: 1px gaps, empty days drawn flat, hover tooltip and month ticks. */
.chart-wrap { position: relative; margin-top: 16px; }
.chart-bars.dense { gap: 1px; }
.chart-bar.zero { min-height: 0; }
.chart-bar.hot { background: var(--accent-ink); }
.chart-slot { cursor: default; }
.chart-tip { position: absolute; top: -6px; transform: translate(-50%, -100%); padding: 4px 8px; border-radius: 6px; background: var(--ink); color: #fff; font-size: 12px; white-space: nowrap; pointer-events: none; z-index: 1; }
.chart-ticks { position: relative; height: 18px; margin: 4px 0 8px 36px; font-size: 12px; color: var(--muted); }
.chart-ticks span { position: absolute; top: 0; white-space: nowrap; }
.device-cell { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.chart-labels { display: flex; justify-content: space-between; padding-left: 26px; font-size: 12px; color: var(--muted); }
details summary { cursor: pointer; color: var(--accent); font-weight: 600; font-size: 13px; }

/* Narrow screens: tighter gutters. */
@media (max-width: 640px) {
  .topbar { padding: 12px 16px; }
  .page { padding: 20px 16px 40px; }
  .notice { margin: 12px 16px 0; }
}

/* Portal Admins */
.plain-list { margin: 0; padding-left: 20px; display: grid; gap: 8px; }
fieldset.plain { border: 0; padding: 0; margin: 0 0 12px; min-inline-size: 0; display: grid; gap: 8px; }
.strong { font-weight: 600; }
.data td .chip + .chip { margin-left: 4px; }
.form-columns > .card:not(.grow-2) { flex: 1 1 280px; }
