:root {
  color-scheme: light dark;
  --bg: #f5f6f8;
  --panel: #ffffff;
  --panel-2: #eef0f4;
  --text: #1c1e21;
  --muted: #6b7280;
  --border: #d6d9e0;
  --accent: #a80030; /* Debian red */
  --accent-soft: #f3d7de;
  --good-bg: #d9f2df;
  --good-border: #4caf50;
  --bad-bg: #fadadd;
  --bad-border: #d64550;
  --warn-border: #e07b00;
  --future-bg: #e8eefc;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161a;
    --panel: #1e2126;
    --panel-2: #262a31;
    --text: #e8eaed;
    --muted: #9aa0a6;
    --border: #343941;
    --accent: #ff5a76;
    --accent-soft: #3a2028;
    --good-bg: #1e3a26;
    --good-border: #4caf50;
    --bad-bg: #3d1f22;
    --bad-border: #d64550;
    --warn-border: #f2a23c;
    --future-bg: #1c2536;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
}

a { color: var(--accent); }

.topbar {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.6rem 1rem;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow);
  position: sticky;
  top: 0;
  z-index: 20;
  flex-wrap: wrap;
}

.topbar h1 { font-size: 1.15rem; margin: 0; }
.topbar .debian { display: flex; align-items: center; gap: 0.5rem; }
.topbar .debian::before {
  content: "";
  width: 28px; height: 28px;
  background: url("/img/debian-logo.png?ver=13") no-repeat center / contain;
  display: inline-block;
}
.topbar .spacer { flex: 1; }
.controls { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }

main { padding: 1rem; max-width: 1200px; margin: 0 auto; }

.tabs { display: flex; gap: 0.25rem; border-bottom: 1px solid var(--border); margin-bottom: 1rem; flex-wrap: wrap; }
.tabs button {
  background: none; border: none; color: var(--muted);
  padding: 0.5rem 0.9rem; cursor: pointer; font-size: 0.95rem;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tabs button.active { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }
.tabs button:disabled { opacity: 0.4; cursor: not-allowed; }

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem;
  box-shadow: var(--shadow);
}

button, select, input, textarea {
  font: inherit; color: inherit;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.4rem 0.6rem;
}
button { cursor: pointer; }
button.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
button.danger { color: var(--bad-border); border-color: var(--bad-border); }
button:disabled { opacity: 0.5; cursor: not-allowed; }
input:disabled, select:disabled, textarea:disabled { opacity: 0.45; cursor: not-allowed; }
.users-grid td label { font-weight: normal; }
.users-grid label:has(input:disabled) { opacity: 0.45; cursor: not-allowed; }
button.link { background: none; border: none; color: var(--accent); padding: 0.2rem; }

.year-tabs { display: flex; gap: 0.3rem; flex-wrap: wrap; margin-bottom: 0.75rem; }
.year-tabs button { padding: 0.25rem 0.6rem; }
.year-tabs button.active { background: var(--accent); color: #fff; border-color: var(--accent); }

.table-toolbar { display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap; margin-bottom: 0.75rem; }
.table-toolbar .spacer { flex: 1; }

.table-scroll { overflow-x: auto; }

table.grid { border-collapse: collapse; width: 100%; min-width: 520px; }
table.grid th, table.grid td { border: 1px solid var(--border); padding: 0.25rem 0.4rem; text-align: left; }
table.grid th { background: var(--panel-2); position: sticky; top: 0; font-weight: 600; }
table.grid td.month, table.grid td.to { font-variant-numeric: tabular-nums; white-space: nowrap; }
table.grid td.value input { width: 100%; border: none; background: transparent; padding: 0.2rem; }
table.grid td.value input:focus { outline: 2px solid var(--accent); border-radius: 3px; }
table.grid input.comment { width: 100%; border: none; background: transparent; }
table.grid td.dirty { background: var(--good-bg); }
table.grid td.invalid { background: var(--bad-bg); }
table.grid tr.future td.month { background: var(--future-bg); }
table.grid td.readonly { color: var(--muted); }
table.grid td .value-display { display: inline-block; min-width: 5rem; }

table.grid.summary td.month { font-variant-numeric: tabular-nums; white-space: nowrap; }
table.grid td.age-green { color: var(--good-border); }
table.grid td.age-orange { color: var(--warn-border); }
table.grid td.age-red { color: var(--bad-border); font-weight: 600; }
table.grid td.age-none { color: var(--muted); }
#view-summary .table-scroll + .table-scroll { margin-top: 1rem; }
#view-summary table.grid td.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }

.status { font-size: 0.85rem; color: var(--muted); }
.status.error { color: var(--bad-border); }
.status.ok { color: var(--good-border); }

.warn {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--bad-border);
  background: var(--bad-bg);
  border: 1px solid var(--bad-border);
  border-radius: 999px;
  padding: 0.15rem 0.6rem;
  max-width: 72ch;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.range-control { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.range-control button {
  background: var(--panel);
  color: var(--muted);
  border: none;
  border-right: 1px solid var(--border);
  padding: 0.25rem 0.7rem;
  font-size: 0.85rem;
  cursor: pointer;
}
.range-control button:last-child { border-right: none; }
.range-control button.active { background: var(--accent); color: #fff; font-weight: 600; }
.range-control button:disabled { opacity: 0.4; cursor: not-allowed; }

.chart-wrap { position: relative; width: 100%; height: 60vh; min-height: 320px; }
.legend { display: flex; flex-wrap: wrap; gap: 0.75rem; margin-top: 0.75rem; font-size: 0.85rem; }
.legend .swatch { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-right: 0.3rem; vertical-align: middle; }

dialog {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--panel);
  color: var(--text);
  padding: 1.25rem;
  width: min(380px, 92vw);
  box-shadow: 0 8px 30px rgba(0,0,0,0.35);
}
dialog::backdrop { background: rgba(0,0,0,0.45); }
dialog form { display: flex; flex-direction: column; gap: 0.75rem; }
dialog h2 { margin: 0 0 0.25rem; font-size: 1.1rem; }
.field { display: flex; flex-direction: column; gap: 0.25rem; }
.field label { font-size: 0.85rem; color: var(--muted); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 0.5rem; }

.profile-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 1rem; }
.profile-grid .field { margin-bottom: 0.5rem; }
.apikey { font-family: ui-monospace, monospace; background: var(--panel-2); padding: 0.5rem; border-radius: 6px; word-break: break-all; }

.log-table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.log-table th, .log-table td { border-bottom: 1px solid var(--border); padding: 0.35rem 0.5rem; text-align: left; }

.paging { display: flex; align-items: center; gap: 0.3rem; margin-top: 0.75rem; flex-wrap: wrap; }
.paging button { padding: 0.25rem 0.6rem; }
.paging button.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.paging button:disabled { opacity: 0.4; cursor: not-allowed; }
.paging .label { margin-left: 0.5rem; font-size: 0.85rem; color: var(--muted); }

.mass-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 1rem; }
.mass-grid textarea { width: 100%; font-family: ui-monospace, monospace; resize: vertical; white-space: pre; overflow-wrap: normal; overflow-x: auto; }
.mass-result { max-height: 22rem; overflow: auto; }
.mass-errors { margin: 0.5rem 0 0; padding-left: 1.1rem; color: var(--bad-border); font-size: 0.85rem; }
.mass-errors:empty { display: none; }

@media (max-width: 800px) {
  .mass-grid { grid-template-columns: 1fr; }
}

.muted { color: var(--muted); }
.hidden { display: none !important; }
.row { display: flex; gap: 0.75rem; flex-wrap: wrap; align-items: center; }

@media (max-width: 640px) {
  .topbar h1 { font-size: 1rem; }
  main { padding: 0.6rem; }
  .panel { padding: 0.6rem; }
  .chart-wrap { height: 48vh; }
}

/* ------------------------------------------------------------------ print
   Print/PDF output: keep the brand header, the active panel and its content
   (chart canvas or the data table), drop all interactive chrome. */
@media print {
  @page { margin: 12mm; }
  :root { color-scheme: light; }

  body { background: #fff; color: #000; }

  .topbar { position: static; box-shadow: none; border-bottom: 1px solid #999; }
  .topbar .controls { display: none !important; }

  .tabs, .year-tabs, .table-toolbar, .range-control, dialog,
  #table-hint, .status, .warn, .mass-errors, .profile-grid,
  #projection-toggle-wrap { display: none !important; }

  /* No buttons (none live inside the data table itself). */
  button { display: none !important; }

  main { padding: 0; max-width: none; margin: 0; }
  .panel { box-shadow: none; border: 1px solid #bbb; border-radius: 0; break-inside: avoid; }

  .chart-wrap { height: auto; break-inside: avoid; }
  .chart-wrap canvas { background: #fff; }

  .table-scroll { overflow: visible; }
  table.grid { width: 100%; min-width: 0; }
  table.grid th { position: static; }
  table.grid td.value input, table.grid input.comment { border: none; background: transparent; }
  tr { break-inside: avoid; }

  * {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
}
