:root {
  --surface-1: #fcfcfb;
  --page-plane: #f9f9f7;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --gridline: #e1e0d9;
  --baseline: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);

  --series-1: #2a78d6; /* blue */
  --series-2: #eb6834; /* orange */
  --series-3: #1baf7a; /* aqua */
  --series-4: #eda100; /* yellow */
  --series-5: #e87ba4; /* magenta */
  --series-6: #008300; /* green */
  --series-7: #4a3aa7; /* violet */
  --series-8: #e34948; /* red */

  --status-good: #0ca30c;
  --status-warning: #fab219;
  --status-serious: #ec835a;
  --status-critical: #d03b3b;
  --ref-red: #c8102e; /* ticket references (includes/ticket_reference.html) */

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

/* Dark mode: follows the OS preference by default, unless the person has
   explicitly picked a mode with the toggle in the topbar (data-theme on
   <html>, set by the inline script in base.html -- see theme-toggle). */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --surface-1: #1c1c1a;
    --page-plane: #121211;
    --text-primary: #f2f2ef;
    --text-secondary: #b9b7b0;
    --text-muted: #87857d;
    --gridline: #333230;
    --baseline: #46453f;
    --border: rgba(255, 255, 255, 0.12);
    --message-success-text: #4ade80;
    --message-error-text: #f87171;
    --message-warning-text: #fcd34d;
    --ref-red: #ff5a5f;
  }
}

:root[data-theme="dark"] {
  --ref-red: #ff5a5f;
  --surface-1: #1c1c1a;
  --page-plane: #121211;
  --text-primary: #f2f2ef;
  --text-secondary: #b9b7b0;
  --text-muted: #87857d;
  --gridline: #333230;
  --baseline: #46453f;
  --border: rgba(255, 255, 255, 0.12);
  --message-success-text: #4ade80;
  --message-error-text: #f87171;
  --message-warning-text: #fcd34d;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font);
  background: var(--page-plane);
  color: var(--text-primary);
  font-size: 15px;
  line-height: 1.5;
  transition: background-color 0.15s ease, color 0.15s ease;
}

a { color: var(--series-1); text-decoration: none; }
a:hover { text-decoration: underline; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--surface-1);
  border-bottom: 1px solid var(--border);
  padding: 0 20px;
  height: 56px;
}

.topbar .brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 16px;
  color: var(--text-primary);
  text-decoration: none;
}

.brand-logo {
  width: 24px;
  height: 24px;
  border-radius: 6px;
  display: block;
}

.topbar nav { display: flex; gap: 4px; align-items: center; }

.topbar nav a {
  color: var(--text-secondary);
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
}

.topbar nav a:hover { background: var(--page-plane); text-decoration: none; }
.topbar nav a.active { color: var(--text-primary); background: var(--page-plane); }

.link-btn {
  color: var(--text-secondary);
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  background: none;
  border: none;
  font-family: inherit;
  cursor: pointer;
}
.link-btn:hover { background: var(--page-plane); }

.theme-toggle {
  font-size: 16px;
  line-height: 1;
  padding: 7px 10px;
}

.avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 12px;
  font-weight: 700;
}

.container {
  max-width: 1180px;
  margin: 0 auto;
  padding: 24px 20px 60px;
}

.container.narrow { max-width: 640px; }

h1 { font-size: 22px; margin: 0 0 4px; }
h2 { font-size: 17px; margin: 0 0 12px; }
.subtitle { color: var(--text-secondary); margin: 0 0 20px; font-size: 14px; }

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

.card + .card { margin-top: 16px; }

.grid { display: grid; gap: 16px; }
.grid.cols-2 { grid-template-columns: 1fr 1fr; }
.grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
.grid.cols-4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 820px) {
  .grid.cols-2, .grid.cols-3, .grid.cols-4 { grid-template-columns: 1fr 1fr; }
}

.stat-tile {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
}
.stat-tile .value { font-size: 28px; font-weight: 700; line-height: 1.1; }
.stat-tile .label { color: var(--text-secondary); font-size: 13px; margin-top: 4px; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--border);
  background: var(--surface-1);
  color: var(--text-primary);
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.btn:hover { background: var(--page-plane); text-decoration: none; }
.btn.primary { background: var(--series-1); border-color: var(--series-1); color: #fff; }
.btn.primary:hover { background: #2166b8; }
.btn.small { padding: 5px 10px; font-size: 13px; }

.input {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 14px;
  background: var(--surface-1);
  color: var(--text-primary);
}
.input:focus { outline: 2px solid var(--series-1); outline-offset: 1px; }

.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 5px; color: var(--text-secondary); }
.field .errorlist { color: var(--status-critical); font-size: 13px; padding: 0; margin: 4px 0 0; list-style: none; }

table.list { width: 100%; border-collapse: collapse; }
table.list th {
  text-align: left;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-muted);
  border-bottom: 1px solid var(--gridline);
  padding: 8px 10px;
}
table.list td {
  padding: 10px;
  border-bottom: 1px solid var(--gridline);
  font-size: 14px;
  vertical-align: middle;
}
table.list tr:hover td { background: var(--page-plane); }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

.badge.status-open { background: rgba(42,120,214,0.12); color: var(--series-1); }
.badge.status-pending { background: rgba(250,178,25,0.16); color: #9a6c00; }
.badge.status-on_hold { background: rgba(236,131,90,0.16); color: #a04a26; }
.badge.status-resolved { background: rgba(12,163,12,0.13); color: var(--status-good); }
.badge.status-closed { background: rgba(137,135,129,0.16); color: var(--text-secondary); }
.badge.staff-only { background: rgba(198,40,40,0.12); color: #c62828; }

.badge.priority-low { background: rgba(137,135,129,0.16); color: var(--text-secondary); }
.badge.priority-medium { background: rgba(42,120,214,0.12); color: var(--series-1); }
.badge.priority-high { background: rgba(250,178,25,0.16); color: #9a6c00; }
.badge.priority-urgent { background: rgba(208,59,59,0.14); color: var(--status-critical); }

.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; align-items: center; }
.filters select, .filters input[type="search"] { padding: 7px 9px; border: 1px solid var(--border); border-radius: var(--radius-sm); font-size: 13px; background: var(--surface-1); }

.tabs { display: flex; gap: 4px; margin-bottom: 16px; border-bottom: 1px solid var(--gridline); }
.tabs a {
  padding: 9px 14px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-secondary);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.tabs a.active { color: var(--series-1); border-bottom-color: var(--series-1); }
.tabs a .count { color: var(--text-muted); font-weight: 500; }

.comment {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 12px;
}
.comment.internal { background: rgba(250,178,25,0.07); border-color: rgba(250,178,25,0.35); }
.comment .meta { font-size: 12px; color: var(--text-muted); margin-bottom: 6px; display: flex; gap: 8px; align-items: center; }
.comment .body { white-space: pre-wrap; font-size: 14px; }

.messages { list-style: none; padding: 0; margin: 0 0 16px; }
.messages li {
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  margin-bottom: 8px;
  background: rgba(12,163,12,0.10);
  color: var(--message-success-text, #0a5c0a);
  border: 1px solid rgba(12,163,12,0.25);
}
.messages li.error {
  background: rgba(208,59,59,0.10);
  color: var(--message-error-text, #8f2323);
  border-color: rgba(208,59,59,0.3);
}

.legend { display: flex; gap: 14px; flex-wrap: wrap; margin-top: 10px; font-size: 12px; color: var(--text-secondary); }
.legend .item { display: flex; align-items: center; gap: 6px; }
.legend .swatch { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }

.chart-table { margin-top: 10px; }
details.chart-table summary { cursor: pointer; font-size: 12px; color: var(--text-secondary); margin-top: 8px; }

.empty-state { text-align: center; padding: 40px 20px; color: var(--text-secondary); }

.split { display: flex; gap: 24px; align-items: flex-start; }
.split .main { flex: 1; min-width: 0; }
.split .side { width: 280px; flex-shrink: 0; }

.kv { font-size: 13px; }
.kv dt { color: var(--text-muted); margin-top: 10px; }
.kv dd { margin: 2px 0 0; font-weight: 600; }

.auth-wrap { display: flex; min-height: 100vh; align-items: center; justify-content: center; background: var(--page-plane); }
.auth-card { width: 380px; background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius); padding: 32px; }
.auth-card h1 { text-align: center; margin-bottom: 20px; }

/* SLA state badges */
.badge.sla-breached { background: var(--status-critical); color: #fff; }
.badge.sla-warning { background: var(--status-warning); color: #0b0b0b; }
.badge.sla-ok { background: rgba(42,120,214,.15); color: var(--series-1); }
.badge.sla-met { background: rgba(12,163,12,.15); color: var(--status-good); }
.badge.sla-paused { background: var(--gridline); color: var(--text-secondary); }

.messages li.warning {
  background: rgba(250,178,25,0.14);
  color: var(--message-warning-text, #6b4b00);
  border-color: rgba(250,178,25,0.45);
}
.messages li a { color: inherit; font-weight: 600; }

.bulk-bar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 10px 14px; margin-bottom: 12px; }
.bulk-bar[hidden] { display: none; }

/* Risk heatmap (desk/risk_heatmap.html) */
.heatmap { border-collapse: separate; border-spacing: 4px; font-size: 13px; }
.heatmap th { font-weight: 500; color: var(--text-secondary); padding: 4px 8px; text-align: center; white-space: nowrap; }
.heatmap td { width: 64px; height: 44px; text-align: center; border-radius: var(--radius-sm); }
.heat-low { background: rgba(12,163,12,0.16); }
.heat-medium { background: rgba(250,178,25,0.26); }
.heat-high { background: rgba(236,131,90,0.38); }
.heat-critical { background: rgba(208,59,59,0.42); }
.legend .swatch.heat-low, .legend .swatch.heat-medium, .legend .swatch.heat-high, .legend .swatch.heat-critical { width: 12px; height: 12px; }
.major-incident { background: rgba(208,59,59,0.12); border: 1px solid rgba(208,59,59,0.45); }

table.list .badge { white-space: nowrap; }
.grid > .card + .card { margin-top: 0; }

/* WEES staff organisation switcher (base.html) */
.org-switch { display: inline-flex; align-items: center; }
.org-switch select { width: auto; max-width: 190px; padding: 4px 8px; font-size: 13px; }
.wees-visiting {
  background: rgba(34,127,133,0.14); border-bottom: 1px solid rgba(34,127,133,0.35);
  color: var(--text-primary); font-size: 13px; padding: 6px 16px; text-align: center;
}

/* Reports (templates/reports/dashboard.html) */
.report-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; }
.report-head .subtitle { margin-bottom: 12px; }
.report-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.filters input[type="date"] { padding: 6px 8px; border: 1px solid var(--border); border-radius: var(--radius-sm); font-size: 13px; background: var(--surface-1); color: inherit; }
.report-nav { position: sticky; top: 0; z-index: 5; background: var(--page-plane); overflow-x: auto; white-space: nowrap; }
.report-section { scroll-margin-top: 56px; margin-bottom: 28px; }
.section-title { font-size: 18px; margin: 8px 0 12px; }
.section-title .muted, .muted { color: var(--text-muted); font-weight: 400; font-size: 0.85em; }
.card h3 { font-size: 14px; margin: 0 0 10px; }
.grid.cols-5 { grid-template-columns: repeat(5, 1fr); }
@media (max-width: 1100px) { .grid.cols-5 { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 800px) { .grid.cols-5 { grid-template-columns: 1fr 1fr; } }
.kpis { margin-bottom: 16px; }
.kpis .value { font-size: 24px; }
.change { font-size: 12px; margin-top: 6px; font-weight: 600; }
.change.good { color: var(--status-good); }
.change.bad { color: var(--status-critical); }
.change.neutral { color: var(--text-secondary); }
.highlights { list-style: none; padding: 0; margin: 0; }
.highlights li { padding: 6px 0 6px 18px; position: relative; font-size: 14px; border-bottom: 1px solid var(--gridline); }
.highlights li:last-child { border-bottom: 0; }
.highlights li::before { content: ""; position: absolute; left: 2px; top: 13px; width: 8px; height: 8px; border-radius: 50%; background: var(--text-muted); }
.highlights li.good::before { background: var(--status-good); }
.highlights li.warn::before { background: var(--status-warning); }
.highlights li.bad::before { background: var(--status-critical); }
.bars { list-style: none; padding: 0; margin: 0; }
.bars li { display: grid; grid-template-columns: minmax(0, 38%) 1fr auto; gap: 10px; align-items: center; padding: 4px 0; font-size: 13px; }
.bar-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { height: 8px; background: var(--gridline); border-radius: 4px; overflow: hidden; }
.bar-fill { display: block; height: 100%; border-radius: 4px; }
.bar-value { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.bar-fill.csat-5 { background: var(--status-good); }
.bar-fill.csat-4 { background: var(--series-3); }
.bar-fill.csat-3 { background: var(--status-warning); }
.bar-fill.csat-2 { background: var(--status-serious); }
.bar-fill.csat-1 { background: var(--status-critical); }
.legend .swatch { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; vertical-align: -1px; }
.legend { margin: -4px 0 8px; }
table.list.num td + td, table.list.num th + th { text-align: right; font-variant-numeric: tabular-nums; }
.scroll-x { overflow-x: auto; }
.hour-map { border-collapse: separate; border-spacing: 2px; font-size: 11px; }
.hour-map th { font-weight: 500; color: var(--text-secondary); padding: 2px 4px; }
.hour-map td { min-width: 24px; height: 24px; text-align: center; border-radius: 3px; font-variant-numeric: tabular-nums;
  background: color-mix(in srgb, var(--series-1) calc(var(--a, 0) * 85% + 6%), transparent); }
.mini-tiles .stat-tile .value { font-size: 22px; }
.csat-quote { margin: 0 0 10px; padding: 6px 10px; border-left: 3px solid var(--gridline); font-size: 13px; }
.section-picks { border: 0; padding: 0; margin: 0 0 14px; display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 6px 16px; }
.section-picks legend { font-size: 13px; font-weight: 600; color: var(--text-secondary); margin-bottom: 6px; }
.section-picks label { font-size: 14px; }
.definitions { margin: 12px 0 0; font-size: 13px; }
.definitions dt { font-weight: 600; margin-top: 10px; }
.definitions dd { margin: 2px 0 0; color: var(--text-secondary); }

/* Ticket reference: big, bold and red above the ticket, and in the
   "ticket logged" pop-up (includes/ticket_reference.html, ticket_logged_dialog.html) */
.ticket-ref-block { margin: 10px 0 6px; }
.ticket-ref-label { display: block; font-size: 12px; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; color: var(--text-secondary); }
.ticket-ref { display: block; font-size: 42px; font-weight: 700; line-height: 1.1; color: var(--ref-red); margin: 2px 0; overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }

.ref-dialog { max-width: 520px; width: calc(100% - 32px); border: 1px solid var(--border); border-radius: var(--radius); padding: 24px; background: var(--surface-1); color: var(--text-primary); text-align: center; }
.ref-dialog::backdrop { background: rgba(0, 0, 0, 0.45); }
.ref-dialog h2 { margin: 0 0 12px; }
.ref-dialog .ticket-ref { font-size: 42px; line-height: 1.1; margin: 4px 0 16px; }
.ref-dialog p { font-size: 14px; line-height: 1.5; }
.ref-dialog-actions { display: flex; gap: 8px; justify-content: center; margin-top: 16px; flex-wrap: wrap; }
@media (max-width: 480px) { .ticket-ref, .ref-dialog .ticket-ref { font-size: 30px; } }
