:root {
  color-scheme: light;

  --page: #f9f9f7;
  --surface: #fcfcfb;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --gridline: #e1e0d9;
  --baseline: #c3c2b7;
  --border: rgba(11, 11, 11, 0.1);
  --hover-wash: rgba(11, 11, 11, 0.04);

  /* Status palette. Slot order is the stacking order and is load-bearing:
     adjacent pairs were validated for colour-blind separation in this order. */
  --status-available: #008300;
  --status-busy: #e34948;
  --status-meeting: #2a78d6;
  --status-away: #eda100;
  --status-offline: #898781;

  --radius: 10px;
  --font: system-ui, -apple-system, 'Segoe UI', sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme='light'])) {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #898781;
    --gridline: #2c2c2a;
    --baseline: #383835;
    --border: rgba(255, 255, 255, 0.1);
    --hover-wash: rgba(255, 255, 255, 0.06);

    --status-available: #008300;
    --status-busy: #e66767;
    --status-meeting: #3987e5;
    --status-away: #c98500;
    --status-offline: #898781;
  }
}

:root[data-theme='dark'] {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface: #1a1a19;
  --text-primary: #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted: #898781;
  --gridline: #2c2c2a;
  --baseline: #383835;
  --border: rgba(255, 255, 255, 0.1);
  --hover-wash: rgba(255, 255, 255, 0.06);

  --status-available: #008300;
  --status-busy: #e66767;
  --status-meeting: #3987e5;
  --status-away: #c98500;
  --status-offline: #898781;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  padding: 0 0 64px;
  background: var(--page);
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.wrap {
  max-width: 1180px;
  margin: 0 auto;
  padding: 0 24px;
}

header.top {
  padding: 32px 0 20px;
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  align-items: flex-end;
  justify-content: space-between;
}

h1 {
  margin: 0;
  font-size: 24px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.subtitle {
  margin: 4px 0 0;
  color: var(--text-secondary);
  font-size: 13px;
}

.header-actions { display: flex; gap: 8px; align-items: center; }

/* ---- Controls ---- */

button, .btn, select, input[type='date'] {
  font: inherit;
  color: var(--text-primary);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 12px;
  cursor: pointer;
}

button:hover, .btn:hover, select:hover { background: var(--hover-wash); }

button:focus-visible, select:focus-visible, input:focus-visible, a:focus-visible {
  outline: 2px solid var(--status-meeting);
  outline-offset: 2px;
}

.btn { text-decoration: none; display: inline-block; }

/* One filter row scoping every chart below it, never per-card filters. */
.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 16px;
  align-items: center;
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 20px;
}

.filter-group { display: flex; gap: 6px; align-items: center; }

.filter-label {
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.segmented { display: flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.segmented button { border: 0; border-radius: 0; padding: 6px 11px; background: transparent; }
.segmented button + button { border-left: 1px solid var(--border); }
.segmented button[aria-pressed='true'] { background: var(--text-primary); color: var(--surface); }

.spacer { flex: 1 1 auto; }

/* ---- Banners ---- */

.banner {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 12px 16px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  margin-bottom: 20px;
  font-size: 13px;
}

.banner[hidden] { display: none; }
.banner .icon { font-size: 15px; line-height: 1.3; }
.banner strong { font-weight: 600; }

/* ---- Cards ---- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 20px;
}

.card h2 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
}

.card .card-sub {
  margin: 3px 0 0;
  font-size: 12.5px;
  color: var(--text-secondary);
}

.card-head {
  display: flex;
  gap: 16px;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 18px;
  flex-wrap: wrap;
}

/* ---- Stat tiles ---- */

.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 20px;
}

.tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
}

.tile .label {
  font-size: 12.5px;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.tile .value {
  font-size: 26px;
  font-weight: 600;
  letter-spacing: -0.02em;
  /* Proportional figures: tabular-nums reads loose at display sizes. */
}

.tile .value.hero { font-size: 40px; }

.tile .note { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

/* ---- Status chips ----
   These are both the control and the colour key. They read as checkboxes
   rather than as a legend, because a plain swatch-and-label legend gives no
   hint that it can be clicked. */

.status-group { flex-wrap: wrap; }

.status-chips { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }

.status-chip {
  display: inline-flex;
  gap: 6px;
  align-items: center;
  font-size: 12.5px;
  line-height: 1;
  padding: 6px 10px 6px 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-primary);
  cursor: pointer;
}

.status-chip:hover { background: var(--hover-wash); }

/* Fixed-width tick slot: hiding it with visibility keeps the chip from
   resizing as it is toggled, which would make the row jump. */
.status-chip .tick {
  width: 9px;
  font-size: 10px;
  flex: none;
  text-align: center;
  color: var(--text-secondary);
}

.status-chip[aria-pressed='false'] .tick { visibility: hidden; }

.status-chip .swatch {
  width: 10px;
  height: 10px;
  border-radius: 3px;
  flex: none;
}

/* Deselected reads as an empty checkbox: hollow swatch, recessive text. */
.status-chip[aria-pressed='false'] {
  color: var(--text-muted);
  border-style: dashed;
}

.status-chip[aria-pressed='false'] .swatch {
  background: transparent !important;
  box-shadow: inset 0 0 0 1.5px var(--text-muted);
}

.link-btn {
  border: 0;
  background: none;
  padding: 4px 2px;
  font-size: 12.5px;
  color: var(--text-secondary);
  text-decoration: underline;
  cursor: pointer;
}

.link-btn:hover { color: var(--text-primary); background: none; }
.link-btn[hidden] { display: none; }

/* ---- Charts ---- */

.chart-scroll { overflow-x: auto; }
/* Width and height are set in px by the renderer to match the viewBox exactly.
   A CSS width of 100% would letterbox the chart whenever the two aspect ratios
   disagree, which shifts every mark sideways. */
svg.chart { display: block; }
svg text { font-family: var(--font); }

.axis-label { fill: var(--text-muted); font-size: 11px; }
.tick-label { fill: var(--text-muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.series-label { fill: var(--text-primary); font-size: 12.5px; }
.value-label { fill: var(--text-secondary); font-size: 11.5px; font-variant-numeric: tabular-nums; }
.gridline { stroke: var(--gridline); stroke-width: 1; }
.baseline { stroke: var(--baseline); stroke-width: 1; }

.seg { cursor: pointer; }
.row-hit { fill: transparent; cursor: pointer; }
.row-hit:hover + .row-bg, .row-bg.hovered { fill: var(--hover-wash); }

/* Refetches hold the previous render at reduced opacity — no skeleton flash. */
.loading { opacity: 0.45; transition: opacity 120ms ease; }

/* ---- Tooltip ---- */

.tooltip {
  position: fixed;
  z-index: 20;
  pointer-events: none;
  background: var(--surface);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 12.5px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.14);
  min-width: 168px;
}

.tooltip[hidden] { display: none; }
.tooltip .tt-title { font-weight: 600; margin-bottom: 6px; }
.tooltip .tt-row { display: flex; align-items: center; gap: 8px; margin-top: 3px; }
.tooltip .tt-row .swatch { width: 9px; height: 9px; border-radius: 2px; flex: none; }
.tooltip .tt-row .tt-name { color: var(--text-secondary); }
.tooltip .tt-row .tt-val { margin-left: auto; font-variant-numeric: tabular-nums; }
.tooltip .tt-foot { margin-top: 7px; padding-top: 6px; border-top: 1px solid var(--border); color: var(--text-muted); font-size: 11.5px; }

/* ---- Table view ---- */

table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); }
th { font-weight: 600; color: var(--text-secondary); font-size: 12px; text-transform: uppercase; letter-spacing: 0.03em; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tbody tr:hover { background: var(--hover-wash); }
.table-scroll { overflow-x: auto; }

/* ---- Timeline ---- */

.timeline-row { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; }
.timeline-name { width: 150px; flex: none; font-size: 12.5px; }
.timeline-track { position: relative; flex: 1; height: 22px; border-radius: 5px; overflow: hidden; background: var(--gridline); }
.timeline-seg { position: absolute; top: 0; bottom: 0; }

.empty {
  padding: 40px 20px;
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
}

.footnote { color: var(--text-muted); font-size: 12px; margin-top: 20px; }

/* ---- Login ---- */

.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  width: 100%;
  max-width: 340px;
}

.login-card h1 { font-size: 19px; margin-bottom: 4px; }
.login-card label { display: block; font-size: 12.5px; color: var(--text-secondary); margin: 18px 0 6px; }
.login-card input { width: 100%; padding: 9px 11px; border-radius: 8px; border: 1px solid var(--border); background: var(--page); color: var(--text-primary); font: inherit; }
.login-card button { width: 100%; margin-top: 16px; padding: 10px; background: var(--text-primary); color: var(--surface); border: 0; font-weight: 500; }
.login-error { margin-top: 14px; font-size: 12.5px; color: var(--status-busy); }

@media print {
  .filters, .header-actions { display: none; }
}
