:root {
  color-scheme: light;
  --bg: #f6f6f3;
  --surface: #fcfcfb;
  --surface-2: #f0efeb;
  --line: #e4e2dc;
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #7a7973;
  --accent: #1a73e8;
  --accent-ink: #ffffff;
  --series-1: #2a78d6;   /* appointments */
  --series-2: #eb6834;   /* tasks */
  --good: #12805c;
  --critical: #c9372c;
  --radius: 14px;
  --shadow: 0 1px 2px rgb(0 0 0 / .04), 0 4px 16px rgb(0 0 0 / .04);
  --font: "Instrument Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "JetBrains Mono", ui-monospace, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --bg: #121211; --surface: #1a1a19; --surface-2: #232321; --line: #2e2e2b;
    --text: #ffffff; --text-2: #c3c2b7; --muted: #8f8e86;
    --accent: #5e9ff0; --accent-ink: #0b0b0b;
    --series-1: #3987e5; --series-2: #d95926;
    --good: #3fb68b; --critical: #ef6b61;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121211; --surface: #1a1a19; --surface-2: #232321; --line: #2e2e2b;
  --text: #ffffff; --text-2: #c3c2b7; --muted: #8f8e86;
  --accent: #5e9ff0; --accent-ink: #0b0b0b;
  --series-1: #3987e5; --series-2: #d95926;
  --good: #3fb68b; --critical: #ef6b61;
  --shadow: none;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.5 var(--font); }
[hidden] { display: none !important; }
h1, h2, h3 { margin: 0; letter-spacing: -.01em; }
h2 { font-size: 26px; font-weight: 600; }
h3 { font-size: 15px; font-weight: 600; }
code, .mono { font-family: var(--mono); font-size: 13px; }
a { color: inherit; }
.link { color: var(--accent); text-decoration: none; font-weight: 500; }
.link:hover { text-decoration: underline; }
.muted { color: var(--text-2); margin: 4px 0 0; }
.hint { color: var(--muted); font-size: 13px; margin: 0; }

/* ---------- buttons & inputs */
.btn {
  appearance: none; border: 1px solid var(--line); background: var(--surface); color: var(--text);
  font: 600 14px var(--font); padding: 9px 16px; border-radius: 999px; cursor: pointer;
  transition: background .15s, border-color .15s, transform .05s;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.07); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--text-2); }
.btn.small { padding: 5px 12px; font-size: 13px; }
.btn.danger { color: var(--critical); }
.btn:disabled { opacity: .5; cursor: default; }
input, select, textarea {
  width: 100%; font: 15px var(--font); color: var(--text); background: var(--surface);
  border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px; margin-top: 6px;
}
input:focus, select:focus, textarea:focus, .btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
label { display: block; font-size: 13px; font-weight: 500; color: var(--text-2); }
label.check { display: flex; gap: 10px; align-items: center; font-size: 14px; color: var(--text); }
label.check input { width: auto; margin: 0; }
.form-error { color: var(--critical); font-size: 13px; margin: 0; min-height: 0; }
.form-ok { color: var(--good); font-size: 13px; margin: 0; }
.form-error:empty, .form-ok:empty { display: none; }

/* ---------- login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: 100%; max-width: 360px; background: var(--surface); border: 1px solid var(--line);
  border-radius: 20px; padding: 28px; display: grid; gap: 16px; box-shadow: var(--shadow);
}
.login-card h1 { font-size: 22px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; }
.brand img { border-radius: 8px; }

/* ---------- shell */
.shell { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.side {
  position: sticky; top: 0; height: 100vh; padding: 22px 14px; border-right: 1px solid var(--line);
  display: flex; flex-direction: column; gap: 24px; background: var(--surface);
}
.side .brand { padding: 0 10px; }
nav { display: grid; gap: 2px; }
nav a {
  text-decoration: none; color: var(--text-2); padding: 8px 12px; border-radius: 10px; font-weight: 500;
}
nav a:hover { background: var(--surface-2); color: var(--text); }
nav a[aria-current="page"] { background: var(--surface-2); color: var(--text); box-shadow: inset 3px 0 0 var(--accent); }
.signout { margin-top: auto; align-self: flex-start; }
main { padding: 32px clamp(16px, 4vw, 48px) 64px; max-width: 1200px; width: 100%; }
main > section { display: grid; gap: 20px; }
.page-head { margin-bottom: 4px; }

/* ---------- cards */
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 20px; box-shadow: var(--shadow); min-width: 0;
}
.card.flush { padding: 0; overflow: hidden; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.grid-2 { display: grid; grid-template-columns: 1.6fr 1fr; gap: 20px; }
.form { display: grid; gap: 14px; align-content: start; }
.form.inline { grid-template-columns: 1fr auto; align-items: end; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* ---------- tiles */
.tiles { display: grid; grid-template-columns: repeat(5, 1fr); gap: 12px; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); }
.tile .label { font-size: 13px; color: var(--text-2); display: flex; align-items: center; gap: 8px; }
.tile .value { font-size: 30px; font-weight: 600; letter-spacing: -.02em; margin-top: 2px; font-variant-numeric: tabular-nums; }

/* ---------- chart */
.legend { display: flex; gap: 14px; font-size: 13px; color: var(--text-2); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.sw { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.sw.s1 { background: var(--series-1); }
.sw.s2 { background: var(--series-2); }
.chart { position: relative; height: 220px; }
.chart svg { width: 100%; height: 100%; display: block; overflow: visible; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .axis { fill: var(--muted); font: 11px var(--font); }
.chart .s1 { fill: var(--series-1); }
.chart .s2 { fill: var(--series-2); }
.chart .hit { fill: transparent; cursor: default; }
.chart .hit:hover + .hover-band, .chart .band-on { fill: var(--surface-2); }
.empty { color: var(--muted); text-align: center; padding: 32px 12px; font-size: 14px; }
.tooltip {
  position: fixed; z-index: 20; pointer-events: none; background: var(--text); color: var(--bg);
  padding: 8px 10px; border-radius: 8px; font-size: 12px; line-height: 1.45; box-shadow: var(--shadow);
  white-space: nowrap;
}
.tooltip b { font-weight: 600; }
.tooltip i { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 6px; }

/* ---------- feed / lists */
.feed, .list { list-style: none; margin: 0; padding: 0; display: grid; }
.feed li, .list li { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line); min-width: 0; }
.feed li:first-child, .list li:first-child { border-top: 0; }
.feed .title { font-weight: 500; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.feed .when { color: var(--text-2); font-size: 13px; white-space: nowrap; }
.list .grow { flex: 1; min-width: 0; }
.list .sub { color: var(--muted); font-size: 13px; }

/* ---------- pills */
.pill { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; padding: 2px 9px 2px 7px; border-radius: 999px; background: var(--surface-2); color: var(--text-2); white-space: nowrap; }
.pill::before { content: ""; width: 8px; height: 8px; border-radius: 2px; background: var(--series-1); }
.pill.task::before { background: var(--series-2); }
.pill.failed { color: var(--critical); }
.pill.failed::before { content: "!"; width: auto; height: auto; background: none; font-weight: 700; }
.status-ok { color: var(--good); }
.status-bad { color: var(--critical); }

/* ---------- tables */
.filters { display: grid; grid-template-columns: 1fr 180px 160px; gap: 10px; }
.filters input, .filters select { margin: 0; }
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th { text-align: left; font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; padding: 12px 16px; border-bottom: 1px solid var(--line); background: var(--surface); }
.table td { padding: 12px 16px; border-bottom: 1px solid var(--line); vertical-align: top; }
.table tr:last-child td { border-bottom: 0; }
.table .t-title { font-weight: 500; max-width: 340px; }
.table .t-orig { color: var(--muted); font-size: 12.5px; margin-top: 2px; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.table .nowrap { white-space: nowrap; }
.table .actions { text-align: right; white-space: nowrap; }
.pager { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; border-top: 1px solid var(--line); color: var(--text-2); font-size: 13px; }
.pager:empty { display: none; }

/* ---------- upload */
.drop {
  display: grid; place-items: center; text-align: center; min-height: 110px; padding: 16px;
  border: 1.5px dashed var(--line); border-radius: 12px; cursor: pointer; color: var(--text-2);
  transition: border-color .15s, background .15s;
}
.drop:hover, .drop.over { border-color: var(--accent); background: var(--surface-2); }
.drop input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.drop.has-file { color: var(--text); font-weight: 500; }

/* ---------- dialog */
.dialog {
  border: 1px solid var(--line); border-radius: 20px; padding: 24px; width: min(420px, calc(100vw - 32px));
  background: var(--surface); color: var(--text); box-shadow: 0 20px 60px rgb(0 0 0 / .25);
}
.dialog::backdrop { background: rgb(0 0 0 / .45); }
.dialog img { display: block; margin: 12px auto; border-radius: 12px; background: #fff; padding: 8px; }
.steps { margin: 10px 0 0; padding-left: 20px; color: var(--text-2); }
.copy { display: flex; gap: 8px; align-items: center; margin-top: 8px; }
.copy code { flex: 1; min-width: 0; overflow-x: auto; white-space: nowrap; background: var(--surface-2); padding: 8px 10px; border-radius: 8px; }
.warn { color: var(--critical); font-size: 13px; font-weight: 500; }
.dialog form { margin-top: 12px; text-align: right; }

.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 30;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 999px; font-size: 14px; font-weight: 500;
}

/* ---------- responsive */
@media (max-width: 1000px) {
  .tiles { grid-template-columns: repeat(3, 1fr); }
  .grid-2 { grid-template-columns: 1fr; }
}
@media (max-width: 720px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: sticky; z-index: 10; height: auto; flex-direction: row; align-items: center; padding: 10px 16px; gap: 12px; border-right: 0; border-bottom: 1px solid var(--line); overflow-x: auto; }
  .side .brand span { display: none; }
  nav { display: flex; gap: 2px; }
  nav a { white-space: nowrap; padding: 6px 10px; }
  nav a[aria-current="page"] { box-shadow: inset 0 -2px 0 var(--accent); }
  .signout { margin: 0 0 0 auto; }
  main { padding: 20px 16px 48px; }
  .tiles { grid-template-columns: repeat(2, 1fr); }
  .filters { grid-template-columns: 1fr 1fr; }
  .filters input { grid-column: 1 / -1; }
  .form.inline, .row { grid-template-columns: 1fr; }
  h2 { font-size: 22px; }
  .feed li { flex-wrap: wrap; row-gap: 2px; }
  .feed .title { flex-basis: calc(100% - 120px); }
  .feed .when { flex-basis: 100%; padding-left: 2px; }
}
