/* Detective Lumberjack UI.
 *
 * Design tokens live here as custom properties so light and dark differ in one
 * place. The chart series colours are a validated categorical palette: adjacent
 * pairs clear colour-vision-deficiency separation and every slot clears 3:1
 * against its own surface, in both modes.
 *
 * The Aiir brand colour #28C1DE is 2.15:1 on white, which is fine for washes,
 * focus rings and marks on dark surfaces but not for text or for thin lines on
 * white. Light mode therefore uses darker steps of the same hue where contrast
 * has to carry meaning, and the brand colour itself where it does not.
 */

:root {
  color-scheme: light dark;

  --aiir: #28c1de;
  --aiir-strong: #0a7590;
  --aiir-deep: #08697f;

  --page: #f4f7f8;
  --surface: #ffffff;
  --surface-2: #f8fafb;
  --surface-3: #eef3f5;
  --border: #dde5e9;
  --border-strong: #c6d2d8;

  --text: #1f2933;
  --text-2: #5c6b73;
  --text-muted: #6b7a82;

  --series-1: #0f8ca8;
  --series-2: #eb6834;
  --series-3: #4a3aa7;

  --good: #0ca30c;
  --good-text: #0a7d0a;
  --warning: #fab219;
  --warning-text: #8a5c00;
  --serious: #ec835a;
  --critical: #d03b3b;
  --critical-text: #b32626;

  --grid: #e9eef1;
  --axis: #c6d2d8;

  --shadow-sm: 0 1px 2px rgba(31, 41, 51, .06);
  --shadow-md: 0 2px 8px rgba(31, 41, 51, .08);
  --shadow-lg: 0 8px 28px rgba(31, 41, 51, .14);

  --radius: 10px;
  --radius-sm: 6px;
  --sidebar-w: 232px;
  --topbar-h: 56px;

  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

/* Dark values are declared under both scopes: the media query follows the OS
 * setting, the data-theme scope follows the in-app toggle, and the toggle wins
 * in both directions. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) { color-scheme: dark; }
  :root:not([data-theme="light"]) {
    --page: #0f1214;
    --surface: #161a1d;
    --surface-2: #1c2125;
    --surface-3: #232a2f;
    --border: #2a3238;
    --border-strong: #3a444b;

    --text: #e8eef1;
    --text-2: #97a5ad;
    --text-muted: #8b99a1;

    --aiir-strong: #28c1de;
    --aiir-deep: #56cfe6;

    --series-1: #1ba0ba;
    --series-2: #dc6a33;
    --series-3: #8d80e0;

    --good-text: #21bb21;
    --warning-text: #f0b93c;
    --critical-text: #f07070;

    --grid: #232a2f;
    --axis: #3a444b;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow-md: 0 2px 10px rgba(0, 0, 0, .45);
    --shadow-lg: 0 10px 30px rgba(0, 0, 0, .55);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0f1214;
  --surface: #161a1d;
  --surface-2: #1c2125;
  --surface-3: #232a2f;
  --border: #2a3238;
  --border-strong: #3a444b;

  --text: #e8eef1;
  --text-2: #97a5ad;
  --text-muted: #8b99a1;

  --aiir-strong: #28c1de;
  --aiir-deep: #56cfe6;

  --series-1: #1ba0ba;
  --series-2: #dc6a33;
  --series-3: #8d80e0;

  --good-text: #21bb21;
  --warning-text: #f0b93c;
  --critical-text: #f07070;

  --grid: #232a2f;
  --axis: #3a444b;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
  --shadow-md: 0 2px 10px rgba(0, 0, 0, .45);
  --shadow-lg: 0 10px 30px rgba(0, 0, 0, .55);
}

* { box-sizing: border-box; }

/* The hidden attribute must win.
 *
 * A browser's own stylesheet says [hidden] { display: none }, but ANY author
 * display rule beats it — and .login, .app and .user-menu all set display. Without
 * this override, hiding the login form does nothing and it stays on screen on top
 * of the application. !important is the only way an attribute selector can outrank
 * a class here. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
}

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

a { color: var(--aiir-strong); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3, h4 { margin: 0; font-weight: 600; line-height: 1.25; }
h1 { font-size: 21px; }
h2 { font-size: 16px; }
h3 { font-size: 14px; }

:focus-visible {
  outline: 2px solid var(--aiir);
  outline-offset: 2px;
  border-radius: 4px;
}

/* ---------------------------------------------------------------- Layout --- */

.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  grid-template-rows: var(--topbar-h) 1fr;
  grid-template-areas: "topbar topbar" "sidebar main";
  min-height: 100vh;
}

.topbar {
  grid-area: topbar;
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 14px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.topbar-spacer { flex: 1; }

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  color: var(--text);
  font-weight: 650;
  letter-spacing: -0.01em;
}
.brand:hover { text-decoration: none; }
.brand .mark { width: 26px; height: 26px; color: var(--aiir); flex: none; }
.brand-name { white-space: nowrap; }

.nav-toggle { display: none; }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-2);
  cursor: pointer;
}
.icon-btn:hover { background: var(--surface-3); color: var(--text); }
.icon-btn svg { width: 19px; height: 19px; }

.conn-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--good);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--good) 18%, transparent);
  flex: none;
}
.conn-dot[data-state="stale"] { background: var(--warning); box-shadow: 0 0 0 3px color-mix(in srgb, var(--warning) 20%, transparent); }
.conn-dot[data-state="down"] { background: var(--critical); box-shadow: 0 0 0 3px color-mix(in srgb, var(--critical) 20%, transparent); }

.user-menu { display: flex; align-items: center; gap: 8px; }
.username { color: var(--text-2); font-size: 13px; }

.sidebar {
  grid-area: sidebar;
  position: sticky;
  top: var(--topbar-h);
  align-self: start;
  height: calc(100vh - var(--topbar-h));
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 12px 10px;
  background: var(--surface);
  border-right: 1px solid var(--border);
}

.nav-section { display: flex; flex-direction: column; gap: 2px; }
.nav-bottom { margin-top: auto; padding-top: 10px; border-top: 1px solid var(--border); }

.nav-heading {
  margin: 12px 8px 4px;
  font-size: 11px;
  font-weight: 650;
  letter-spacing: .07em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 7px 9px;
  border-radius: var(--radius-sm);
  color: var(--text-2);
  font-weight: 500;
  border-left: 3px solid transparent;
}
.nav-link:hover { background: var(--surface-3); color: var(--text); text-decoration: none; }
.nav-link svg { width: 17px; height: 17px; flex: none; }
.nav-link.active {
  background: color-mix(in srgb, var(--aiir) 12%, transparent);
  border-left-color: var(--aiir-strong);
  color: var(--text);
  font-weight: 650;
}

.nav-host { display: flex; flex-direction: column; }
.nav-host .nav-link { justify-content: space-between; }
.nav-host-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--good); flex: none;
}
.nav-host-dot[data-online="false"] { background: var(--text-muted); }
.nav-sub { display: none; flex-direction: column; padding-left: 12px; }
.nav-host.open .nav-sub { display: flex; }
.nav-sub .nav-link { font-size: 13px; padding: 5px 9px; }

.scrim {
  position: fixed;
  inset: var(--topbar-h) 0 0 0;
  background: rgba(15, 18, 20, .45);
  z-index: 19;
  border: 0;
}

.main {
  grid-area: main;
  min-width: 0;
  padding: 18px;
  outline: none;
}

/* --------------------------------------------------------------- Widgets --- */

.page-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 14px;
  margin-bottom: 16px;
}
.page-head h1 { display: flex; align-items: center; gap: 9px; }
.page-head .sub { color: var(--text-2); font-size: 13px; }
.page-head-actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }

.tabs {
  display: flex;
  gap: 2px;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  padding: 8px 13px;
  border: 0;
  border-bottom: 2px solid transparent;
  background: transparent;
  color: var(--text-2);
  font: inherit;
  font-weight: 550;
  cursor: pointer;
  white-space: nowrap;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--text); border-bottom-color: var(--aiir-strong); }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
.card-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 14px;
  border-bottom: 1px solid var(--border);
}
.card-head h2 { flex: 1; min-width: 0; }
.card-body { padding: 14px; }
.card-body.tight { padding: 8px 14px 12px; }

.grid { display: grid; gap: 14px; }
.grid-charts { grid-template-columns: repeat(auto-fit, minmax(420px, 1fr)); }
.grid-tiles { grid-template-columns: repeat(auto-fit, minmax(158px, 1fr)); }

/* Stat tiles: a big number is the right form when there is one value to read,
 * with an optional sparkline for trend rather than a full chart. */
.tile {
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  min-width: 0;
}
.tile-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  font-weight: 650;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--text-muted);
}
.tile-value {
  margin-top: 4px;
  font-size: 25px;
  font-weight: 620;
  letter-spacing: -0.02em;
  line-height: 1.15;
  color: var(--text);
  overflow-wrap: anywhere;
}
.tile-value .unit { font-size: 15px; font-weight: 550; color: var(--text-2); margin-left: 2px; }
.tile-sub { margin-top: 2px; font-size: 12px; color: var(--text-2); }

/* Meter: a proportion of a known total. Track and fill both carry a 2px gap
 * from the surface so the fill edge stays legible. */
.meter {
  margin-top: 8px;
  height: 6px;
  border-radius: 999px;
  background: var(--surface-3);
  overflow: hidden;
}
.meter > span {
  display: block;
  height: 100%;
  border-radius: 999px;
  background: var(--series-1);
  transition: width .3s ease;
}
.meter[data-state="warning"] > span { background: var(--warning); }
.meter[data-state="critical"] > span { background: var(--critical); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 6px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 550;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-3); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn svg { width: 15px; height: 15px; }
.btn-primary {
  background: var(--aiir-strong);
  border-color: var(--aiir-strong);
  color: #fff;
}
.btn-primary:hover { background: var(--aiir-deep); border-color: var(--aiir-deep); }
:root[data-theme="dark"] .btn-primary,
.btn-primary { color: #fff; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .btn-primary { color: #06232b; }
}
:root[data-theme="dark"] .btn-primary { color: #06232b; }
.btn-quiet { border-color: transparent; background: transparent; color: var(--text-2); }
.btn-quiet:hover { background: var(--surface-3); color: var(--text); }
/* For an action that destroys something. It is coloured rather than filled: the
 * button should be findable and give pause, not draw the eye first. */
.btn-danger {
  color: var(--critical-text);
  border-color: color-mix(in srgb, var(--critical) 40%, var(--border));
}
.btn-danger:hover {
  background: color-mix(in srgb, var(--critical) 12%, transparent);
  border-color: var(--critical);
}
.btn-block { width: 100%; padding: 9px; }
.btn-sm { padding: 4px 9px; font-size: 13px; }

.btn.active {
  background: color-mix(in srgb, var(--aiir) 16%, transparent);
  border-color: var(--aiir-strong);
  color: var(--text);
  font-weight: 650;
}

.range-picker { display: flex; flex-wrap: wrap; gap: 4px; }
.range-picker .btn { padding: 4px 9px; font-size: 12.5px; }

input[type="text"], input[type="password"], input[type="search"], select {
  padding: 6px 10px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  min-width: 0;
}
input::placeholder { color: var(--text-muted); }

.field-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; min-width: 140px; }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-2);
  white-space: nowrap;
}
.badge .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-online { color: var(--good-text); border-color: color-mix(in srgb, var(--good) 35%, var(--border)); }
.badge-offline { color: var(--text-2); }
.badge-warn { color: var(--warning-text); border-color: color-mix(in srgb, var(--warning) 40%, var(--border)); }
.badge-crit { color: var(--critical-text); border-color: color-mix(in srgb, var(--critical) 40%, var(--border)); }

.muted { color: var(--text-2); }
.mono { font-family: var(--mono); font-size: 12.5px; }
.nums { font-variant-numeric: tabular-nums; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.empty {
  padding: 34px 18px;
  text-align: center;
  color: var(--text-2);
}
.empty h3 { color: var(--text); margin-bottom: 6px; }
.empty p { margin: 0 auto; max-width: 46ch; }
.empty code {
  font-family: var(--mono);
  background: var(--surface-3);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 12.5px;
}

.spinner {
  width: 18px; height: 18px;
  border: 2px solid var(--border-strong);
  border-top-color: var(--aiir-strong);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading { display: flex; align-items: center; gap: 9px; padding: 24px; color: var(--text-2); }

/* ---------------------------------------------------------------- Tables --- */

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td {
  padding: 8px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
th {
  font-size: 11px;
  font-weight: 650;
  letter-spacing: .05em;
  text-transform: uppercase;
  color: var(--text-muted);
  background: var(--surface-2);
  position: sticky;
  top: 0;
  z-index: 1;
}
th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--text); }
th .arrow { opacity: .45; margin-left: 3px; }
th.sorted { color: var(--text); }
th.sorted .arrow { opacity: 1; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr.clickable { cursor: pointer; }
tbody tr.clickable:hover { background: var(--surface-2); }
tbody tr.exited td { color: var(--text-2); }

.cell-name { display: flex; align-items: center; gap: 8px; min-width: 0; }
.cell-name .label { font-weight: 550; }
.cell-cmd {
  max-width: 46ch;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-2);
  font-family: var(--mono);
  font-size: 12px;
}

/* What a process is, in one sentence, under its name. It wraps rather than
 * truncating: a description cut off mid-clause explains nothing, and the row is
 * already tall enough to carry two lines. */
.cell-desc {
  max-width: 72ch;
  margin-top: 1px;
  color: var(--text-2);
  font-size: 12px;
  line-height: 1.35;
}
/* An unrecognised process still says something, but should not read as loudly as
 * a real description. */
.cell-desc.unknown { font-style: italic; opacity: .72; }

/* The same sentence at the top of a process's own page, where there is room for
 * it to sit on one line. */
.page-head .cell-desc { max-width: 90ch; margin-top: 5px; font-size: 13px; }

.spark { display: block; width: 84px; height: 22px; }

/* Bar rendered inside a table cell: a proportion read against its row. */
.cell-bar {
  position: relative;
  min-width: 92px;
  height: 6px;
  border-radius: 999px;
  background: var(--surface-3);
  overflow: hidden;
}
.cell-bar > span { position: absolute; inset: 0 auto 0 0; border-radius: 999px; background: var(--series-1); }

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

.chart { width: 100%; }
.chart-hint {
  padding: 0 14px 10px;
  font-size: 12px;
  color: var(--text-muted);
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
  padding: 0 14px 10px;
}
.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  color: var(--text-2);
}
.legend-swatch {
  width: 10px;
  height: 10px;
  border-radius: 2px;
  flex: none;
  /* 2px surface ring so overlapping marks stay separable. */
  box-shadow: 0 0 0 1.5px var(--surface);
}
.legend-value { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }

.dl-tooltip {
  position: absolute;
  z-index: 20;
  min-width: 150px;
  max-width: 280px;
  padding: 8px 10px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  font-size: 12.5px;
  pointer-events: none;
  opacity: 0;
  transition: opacity .1s;
}
.dl-tooltip.on { opacity: 1; }
.dl-tooltip .tt-time {
  font-weight: 650;
  color: var(--text);
  margin-bottom: 5px;
  font-variant-numeric: tabular-nums;
}
.dl-tooltip .tt-row {
  display: flex;
  align-items: center;
  gap: 7px;
  color: var(--text-2);
}
.dl-tooltip .tt-row .name { flex: 1; }
.dl-tooltip .tt-row .val { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }
.dl-tooltip .tt-foot { margin-top: 6px; color: var(--text-muted); font-size: 11.5px; }

.uplot { width: 100% !important; font-family: var(--sans) !important; }
.u-legend { display: none !important; }
.u-select { background: color-mix(in srgb, var(--aiir) 18%, transparent) !important; }
.u-cursor-x, .u-cursor-y { border-color: var(--axis) !important; }

/* Per-core strip: many small magnitudes at once, where a full chart each would
 * be noise. Each cell is a one-hue meter. */
.cores { display: flex; flex-wrap: wrap; gap: 6px; }
.core {
  width: 46px;
}
.core-bar {
  height: 34px;
  border-radius: 4px;
  background: var(--surface-3);
  position: relative;
  overflow: hidden;
}
.core-bar > span {
  position: absolute;
  inset: auto 0 0 0;
  background: var(--series-1);
  border-radius: 4px 4px 0 0;
}
.core-label {
  margin-top: 3px;
  font-size: 10.5px;
  color: var(--text-muted);
  text-align: center;
  font-variant-numeric: tabular-nums;
}

/* ------------------------------------------------------------ Attribution --- */

.attr-panel {
  border: 1px solid var(--aiir-strong);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-md);
  overflow: hidden;
}
.attr-head {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 11px 14px;
  background: color-mix(in srgb, var(--aiir) 10%, var(--surface));
  border-bottom: 1px solid var(--border);
}
.attr-head h2 { flex: 1; min-width: 0; }
.attr-when { font-variant-numeric: tabular-nums; font-weight: 650; }
.attr-metrics { display: flex; gap: 4px; }

/* ------------------------------------------------------------------- Logs --- */

.log-layout {
  display: grid;
  grid-template-columns: 262px 1fr;
  gap: 14px;
  align-items: start;
}

.log-tree { padding: 8px; }
.log-source { margin-bottom: 4px; }
.log-source-name {
  display: flex;
  align-items: center;
  gap: 7px;
  width: 100%;
  padding: 7px 8px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  text-align: left;
}
.log-source-name:hover { background: var(--surface-3); }
.log-source-name .chev { width: 14px; height: 14px; color: var(--text-muted); transition: transform .15s; flex: none; }
.log-source.open .chev { transform: rotate(90deg); }
.log-files { display: none; flex-direction: column; padding-left: 6px; }
.log-source.open .log-files { display: flex; }

.log-file {
  display: block;
  padding: 5px 9px;
  border-radius: var(--radius-sm);
  color: var(--text-2);
  border-left: 3px solid transparent;
}
.log-file:hover { background: var(--surface-3); color: var(--text); text-decoration: none; }
.log-file.active {
  background: color-mix(in srgb, var(--aiir) 12%, transparent);
  border-left-color: var(--aiir-strong);
  color: var(--text);
}
.log-file-name { display: flex; align-items: center; gap: 6px; font-family: var(--mono); font-size: 12.5px; }
.log-file-meta { font-size: 11px; color: var(--text-muted); font-variant-numeric: tabular-nums; }

.log-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}

.log-view {
  margin: 0;
  padding: 8px 0;
  max-height: min(66vh, 720px);
  overflow: auto;
  background: var(--surface);
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.55;
  border-radius: 0 0 var(--radius) var(--radius);
  overscroll-behavior: contain;
}

.log-line {
  display: flex;
  gap: 10px;
  padding: 0 12px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

/* Word wrap off: lines keep their real shape and run off to the right, which is
 * what makes columnar logs readable. The pane already scrolls, and min-width
 * forces every row to the width of the longest one so a single scroll position
 * lines them all up. */
.log-view.nowrap .log-line {
  white-space: pre;
  overflow-wrap: normal;
  min-width: max-content;
}
.log-view.nowrap .log-line .txt { flex: none; }
/* The line number stays put while the text scrolls under it, so a long line can
 * be read across without losing which line it belongs to. */
.log-view.nowrap .log-line .ln {
  position: sticky;
  left: 0;
  z-index: 1;
  background: var(--surface);
}
.log-view.nowrap .log-line:hover .ln { background: var(--surface-2); }
.log-line:hover { background: var(--surface-2); }
.log-line .ln {
  flex: none;
  min-width: 3.5ch;
  text-align: right;
  color: var(--text-muted);
  user-select: none;
  font-variant-numeric: tabular-nums;
}
.log-line .txt { flex: 1; min-width: 0; }

/* Level highlighting is a hint, not an assumption: it only applies when a level
 * token is actually recognised, and the text stays readable either way. */
.log-line.lv-error .txt, .log-line.lv-fatal .txt { color: var(--critical-text); }
.log-line.lv-warn .txt { color: var(--warning-text); }
.log-line.lv-debug .txt, .log-line.lv-trace .txt { color: var(--text-2); }
.log-line.lv-fatal { background: color-mix(in srgb, var(--critical) 8%, transparent); }
.log-line.marker {
  color: var(--aiir-strong);
  font-weight: 650;
  justify-content: center;
  padding: 4px 12px;
  background: color-mix(in srgb, var(--aiir) 8%, transparent);
}
.log-line.marker .ln { display: none; }
.log-line mark {
  background: color-mix(in srgb, var(--aiir) 34%, transparent);
  color: inherit;
  border-radius: 2px;
}

.log-foot {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  padding: 8px 12px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-2);
}

.follow-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--text-muted);
}
.btn.active .follow-dot {
  background: var(--good);
  animation: pulse 1.6s ease-in-out infinite;
}
@keyframes pulse { 50% { opacity: .35; } }

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

.login {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 20px;
  background: var(--page);
}
.login-card {
  width: 100%;
  max-width: 350px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
}
.login-brand { display: flex; align-items: center; gap: 11px; margin-bottom: 14px; }
.login-brand .mark { width: 36px; height: 36px; color: var(--aiir); flex: none; }
.login-brand h1 { font-size: 17px; }
.login-brand p { margin: 2px 0 0; color: var(--text-2); font-size: 13px; }
.login-card label { margin-top: 8px; font-size: 12.5px; font-weight: 600; color: var(--text-2); }
.login-card .btn { margin-top: 16px; }
.login-error {
  margin: 10px 0 0;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--critical) 12%, transparent);
  color: var(--critical-text);
  font-size: 13px;
}

/* ----------------------------------------------------------------- Toasts --- */

.toast-stack {
  position: fixed;
  right: 14px;
  bottom: 14px;
  z-index: 60;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: min(360px, calc(100vw - 28px));
}
.toast {
  display: flex;
  gap: 9px;
  padding: 10px 12px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-left: 3px solid var(--critical);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  font-size: 13px;
}
.toast[data-kind="info"] { border-left-color: var(--aiir-strong); }
.toast[data-kind="warn"] { border-left-color: var(--warning); }

/* ------------------------------------------------------------- Responsive --- */

@media (max-width: 1000px) {
  .grid-charts { grid-template-columns: 1fr; }
  .log-layout { grid-template-columns: 1fr; }
  .log-tree { max-height: 260px; overflow-y: auto; }
}

@media (max-width: 820px) {
  .app {
    grid-template-columns: 1fr;
    grid-template-areas: "topbar" "main";
  }
  .nav-toggle { display: inline-flex; }
  .sidebar {
    position: fixed;
    top: var(--topbar-h);
    left: 0;
    bottom: 0;
    width: min(280px, 84vw);
    z-index: 20;
    transform: translateX(-102%);
    transition: transform .2s ease;
    box-shadow: var(--shadow-lg);
  }
  .app.nav-open .sidebar { transform: none; }
  .main { padding: 14px; }
  .brand-name { display: none; }
  .username { display: none; }
  /* Secondary process columns collapse; the detail view carries them. */
  .hide-sm { display: none !important; }
  .cell-cmd { max-width: 22ch; }
  .cell-desc { max-width: 34ch; }
  .tile-value { font-size: 22px; }
  h1 { font-size: 19px; }
}

@media (max-width: 560px) {
  .grid-tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .hide-xs { display: none !important; }
  .main { padding: 11px; }
  .log-view { max-height: 60vh; font-size: 12px; }
  .page-head-actions { width: 100%; }
  .range-picker { width: 100%; }
  .range-picker .btn { flex: 1; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}
