/* Lifeline: palette + styles for the login page and the one-page console. */

:root {
  --bg: #f7f6f2;
  --surface: #ffffff;
  --surface-2: #efeee9;
  --side: #eeece6;
  --side-hover: #e4e2db;
  --side-active: #dcdad2;
  --fg: #1d2125;
  --muted: #5d656d;
  --border: #dad8d0;
  --accent: #2459c7;
  --accent-fg: #ffffff;
  --ok: #1d7a3e;
  --ok-bg: #e5f4ea;
  --warn: #9a5b00;
  --warn-bg: #fdf1dc;
  --fail: #b42318;
  --fail-bg: #fde8e6;
  --stale: #5b4ea8;
  --stale-bg: #eeebfb;
  --term-bg: #14171c;
  --series: #2a78d6;
  --grid: #ebe9e3;
  --axis: #cfccc3;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.05), 0 2px 8px rgba(0, 0, 0, 0.04);
  --shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.18);
  --shadow-hover: 0 2px 4px rgba(0, 0, 0, 0.06), 0 8px 24px rgba(0, 0, 0, 0.08);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --side-w: 288px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17191c;
    --surface: #202327;
    --surface-2: #2a2e33;
    --side: #111315;
    --side-hover: #1d2023;
    --side-active: #262a2e;
    --fg: #eceeef;
    --muted: #a3abb3;
    --border: #363b41;
    --accent: #7aa3ff;
    --accent-fg: #0b1220;
    --ok: #5fd08a;
    --ok-bg: #173323;
    --warn: #f3b24d;
    --warn-bg: #3a2c12;
    --fail: #ff7b70;
    --fail-bg: #3d1c1a;
    --stale: #b3a8ff;
    --stale-bg: #2a2546;
    --term-bg: #101215;
    --series: #3987e5;
    --grid: #2d3137;
    --axis: #454b52;
    --shadow: 0 0 0 transparent;
    --shadow-hover: 0 6px 20px rgba(0, 0, 0, 0.35);
    --shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.5);
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font);
  font-size: 18px;
  line-height: 1.5;
}

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

h1, h2, h3 { line-height: 1.25; margin: 0; }
h2 { font-size: 1.3rem; }
h3 { font-size: 1.1rem; }

svg { width: 1em; height: 1em; flex: none; }

/* ---- buttons / inputs -------------------------------------------------- */
button, .button {
  font: inherit;
  font-size: 1rem;
  font-weight: 600;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--fg);
  padding: 10px 16px;
  min-height: 44px;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
button:hover, .button:hover { background: var(--surface-2); }
button:disabled { opacity: 0.6; cursor: progress; }
button.primary, .button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-fg);
}
button.primary:hover, .button.primary:hover { filter: brightness(1.08); background: var(--accent); }
button.big { font-size: 1.08rem; padding: 12px 20px; min-height: 52px; }
button.small { font-size: 0.95rem; min-height: 40px; padding: 8px 14px; }
button.danger { background: var(--fail); border-color: var(--fail); color: #fff; }
button.danger:hover { background: var(--fail); filter: brightness(1.08); }
button.danger-outline { color: var(--fail); border-color: color-mix(in srgb, var(--fail) 45%, var(--border)); background: transparent; }
button.danger-outline:hover { background: var(--fail-bg); }
button.link {
  background: none; border: none; color: var(--accent); padding: 4px 6px; min-height: 0;
  text-decoration: underline; font-weight: 500;
}
button.link.quiet { color: var(--muted); }
button:focus-visible, .button:focus-visible, input:focus-visible, summary:focus-visible, a:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}
.icon-btn {
  background: transparent; border: none; min-height: 44px; min-width: 44px; padding: 0;
  font-size: 24px; color: var(--fg); border-radius: 10px;
}
.icon-btn:hover { background: var(--side-hover); }
.menu-btn { position: relative; }
.menu-btn.has-problem::after {
  content: ""; position: absolute; top: 4px; right: 2px; width: 12px; height: 12px; border-radius: 50%;
  background: var(--fail); border: 2px solid var(--bg);
}

input[type="text"], input[type="password"] {
  font: inherit;
  width: 100%;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--fg);
}

/* ---- app shell: sidebar + main pane ------------------------------------- */
body.app-body { height: 100dvh; overflow: hidden; }
.app { display: flex; height: 100dvh; }

.sidebar {
  width: var(--side-w);
  flex: none;
  background: var(--side);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 14px 12px 12px;
  gap: 6px;
  min-height: 0;
}
.side-top { display: flex; align-items: center; justify-content: space-between; padding: 2px 6px 8px; }
.brand {
  display: inline-flex; align-items: center; gap: 10px;
  font-size: 1.3rem; font-weight: 750; letter-spacing: -0.01em; color: var(--fg); text-decoration: none;
}
.brand .logo {
  width: 32px; height: 32px; padding: 5px; border-radius: 9px;
  background: var(--accent); color: var(--accent-fg);
}

.new-session {
  justify-content: flex-start;
  width: 100%;
  min-height: 52px;
  padding: 12px 16px;
  font-size: 1.05rem;
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-fg);
  box-shadow: var(--shadow);
}
.new-session:hover { background: var(--accent); filter: brightness(1.08); }
.new-session svg { font-size: 20px; }
.more-options { align-self: flex-start; font-size: 0.9rem; margin: -2px 0 0 6px; }
.side-status { margin: 2px 6px; font-size: 0.9rem; }

.side-nav { margin-top: 10px; }
.nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px; border-radius: 10px;
  color: var(--fg); text-decoration: none; font-weight: 600;
  min-height: 46px;
}
.nav-item:hover { background: var(--side-hover); }
.nav-item.active { background: var(--side-active); }
.nav-label { flex: 1; }
.count {
  font-size: 0.85rem; font-weight: 700; min-width: 26px; height: 26px; padding: 0 8px;
  border-radius: 13px; display: inline-grid; place-items: center;
  background: var(--fail); color: #fff;
}
.count.warn { background: var(--warn); }
.count.stale { background: var(--stale); }
@media (prefers-color-scheme: dark) { .count { color: #111; } }

.status-dot {
  width: 12px; height: 12px; border-radius: 50%; flex: none; display: inline-block;
  background: var(--muted);
}
.status-dot.ok { background: var(--ok); }
.status-dot.warn { background: var(--warn); }
.status-dot.fail, .status-dot.bad { background: var(--fail); }
.status-dot.stale { background: var(--stale); }
.status-dot.fail { box-shadow: 0 0 0 0 color-mix(in srgb, var(--fail) 60%, transparent); animation: pulse 2s infinite; }
.status-dot.loading { background: var(--border); }
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--fail) 55%, transparent); }
  70% { box-shadow: 0 0 0 7px transparent; }
  100% { box-shadow: 0 0 0 0 transparent; }
}

.side-label {
  margin: 18px 12px 4px; font-size: 0.8rem; font-weight: 700; letter-spacing: 0.06em;
  text-transform: uppercase; color: var(--muted);
}
.side-scroll { flex: 1; min-height: 0; overflow-y: auto; margin: 0 -4px; padding: 0 4px; }
.session-list { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: minmax(0, 1fr); gap: 2px; }
.sess { position: relative; border-radius: 10px; }
.sess:hover { background: var(--side-hover); }
.sess.active { background: var(--side-active); }
.sess-link {
  display: flex; flex-direction: column; gap: 1px;
  padding: 9px 44px 9px 12px; color: var(--fg); text-decoration: none; border-radius: 10px;
  min-height: 52px; justify-content: center;
}
.sess-title { font-weight: 600; font-size: 0.98rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sess-sub {
  font-size: 0.82rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  display: flex; align-items: center; gap: 6px;
}
.run-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); flex: none; }
.sess.ended .sess-title { color: var(--muted); font-weight: 500; }
.ended-word { white-space: pre; }
.sess-end {
  position: absolute; right: 4px; top: 50%; transform: translateY(-50%);
  min-height: 36px; min-width: 36px; padding: 0; border: none; background: transparent;
  color: var(--muted); font-size: 18px; border-radius: 8px; opacity: 0;
}
.sess:hover .sess-end, .sess.active .sess-end, .sess-end:focus-visible { opacity: 1; }
.sess-end:hover { background: var(--fail-bg); color: var(--fail); }
@media (hover: none) { .sess-end { opacity: 1; } }
.side-empty { color: var(--muted); font-size: 0.92rem; margin: 6px 12px; }

.side-foot {
  display: flex; align-items: center; gap: 10px;
  border-top: 1px solid var(--border); padding: 12px 6px 2px; margin-top: 6px;
}
.avatar {
  width: 34px; height: 34px; border-radius: 50%; flex: none;
  display: grid; place-items: center; font-weight: 700;
  background: var(--surface); border: 1px solid var(--border);
}
.who-name { flex: 1; min-width: 0; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; min-height: 0; }
.view { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.view-head {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 28px; min-height: 64px; flex: none;
  border-bottom: 1px solid var(--border); background: var(--bg);
}
.view-head h1 { font-size: 1.35rem; }
.only-phone { display: none; }

/* ---- scrolling views (systems overview, one system) -------------------------- */
.scroll-view { overflow-y: auto; }
.page { max-width: 1180px; width: 100%; margin: 0 auto; padding: 4px 28px 40px; }

.offline {
  background: var(--fail);
  color: #fff;
  font-weight: 600;
  padding: 12px 16px;
  text-align: center;
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 50;
}

.banner {
  --tone: var(--muted);
  margin: 20px 0 22px;
  border-radius: var(--radius);
  padding: 20px 24px;
  display: flex;
  align-items: center;
  gap: 18px;
  border: 2px solid var(--tone);
}
.banner .icon {
  flex: none;
  width: 52px; height: 52px; border-radius: 50%;
  display: grid; place-items: center;
  font-size: 1.8rem; font-weight: 800;
  background: var(--tone);
  color: var(--surface);
}
.banner .headline { font-size: 1.65rem; font-weight: 750; line-height: 1.2; }
.banner .sub { color: var(--muted); margin-top: 4px; }
.banner.ok { --tone: var(--ok); background: var(--ok-bg); }
.banner.warn { --tone: var(--warn); background: var(--warn-bg); }
.banner.fail { --tone: var(--fail); background: var(--fail-bg); }
.banner.loading { --tone: var(--muted); background: var(--surface); }

section.area { margin: 36px 0; }
.area-head { margin-bottom: 12px; }
.area-head p { margin: 4px 0 0; color: var(--muted); }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px 18px;
  min-width: 0;
}

/* status words: always an icon + a word, never colour alone */
.pill {
  display: inline-flex; align-items: center; gap: 5px; flex: none;
  font-weight: 700; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.04em;
  padding: 3px 10px 3px 8px; border-radius: 999px; width: fit-content; white-space: nowrap;
}
.pill svg { width: 15px; height: 15px; }
.pill.big { font-size: 0.9rem; padding: 5px 12px 5px 10px; }
.pill.big svg { width: 17px; height: 17px; }
.pill.ok { color: var(--ok); background: var(--ok-bg); }
.pill.warn { color: var(--warn); background: var(--warn-bg); }
.pill.fail { color: var(--fail); background: var(--fail-bg); }
.pill.stale { color: var(--stale); background: var(--stale-bg); }
.pill.unknown, .pill.neutral { color: var(--muted); background: var(--surface-2); }

.s-icon {
  --tone: var(--muted);
  display: inline-grid; place-items: center; flex: none;
  width: 20px; height: 20px; border-radius: 50%;
  background: var(--tone); color: var(--surface);
}
.s-icon svg { width: 14px; height: 14px; }
.s-icon.ok { --tone: var(--ok); }
.s-icon.warn { --tone: var(--warn); }
.s-icon.fail { --tone: var(--fail); }
.s-icon.stale { --tone: var(--stale); }

/* ---- system cards ---- */
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 340px), 1fr));
  gap: 16px;
  align-items: start;
}
.sys-card {
  --tone: transparent;
  display: flex; flex-direction: column; gap: 12px;
  background: var(--surface); color: var(--fg); text-decoration: none;
  border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow), inset 5px 0 0 var(--tone);
  padding: 18px 20px 14px 22px; min-width: 0;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.sys-card:hover { border-color: color-mix(in srgb, var(--accent) 55%, var(--border)); box-shadow: var(--shadow-hover), inset 5px 0 0 var(--tone); }
.sys-card:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.sys-card.warn { --tone: var(--warn); }
.sys-card.fail { --tone: var(--fail); }
.sys-card.stale { --tone: var(--stale); }
.sys-card > *, .panel > * { min-width: 0; }
.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.card-title { font-size: 1.22rem; font-weight: 720; overflow-wrap: anywhere; }
.card-head .pill { margin-top: 2px; }
.card-desc {
  margin: -6px 0 0; color: var(--muted); font-size: 0.95rem; line-height: 1.4;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.card-calm {
  margin: 0; padding: 12px 14px; border-radius: 10px; background: var(--surface-2);
  color: var(--muted); font-size: 0.95rem; line-height: 1.45;
}

.card-problem { border-radius: 10px; padding: 10px 12px; background: var(--surface-2); }
.sys-card.fail .card-problem { background: var(--fail-bg); }
.sys-card.warn .card-problem { background: var(--warn-bg); }
.sys-card.stale .card-problem { background: var(--stale-bg); }
.cp-label { font-size: 0.75rem; font-weight: 750; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); margin-bottom: 4px; }
.card-problem ul { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; }
.card-problem li { display: flex; gap: 10px; align-items: flex-start; font-size: 0.97rem; line-height: 1.4; overflow-wrap: anywhere; }
.card-problem li .s-icon { margin-top: 1px; }
.card-problem p { margin: 3px 0 0; color: var(--muted); font-size: 0.9rem; }
.clamp { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(128px, 1fr)); gap: 10px; }
.stat {
  border: 1px solid var(--border); border-radius: 10px; padding: 9px 11px 6px;
  display: flex; flex-direction: column; gap: 1px; min-width: 0; background: var(--surface);
}
.stat.warn { border-color: color-mix(in srgb, var(--warn) 55%, var(--border)); }
.stat.fail { border-color: color-mix(in srgb, var(--fail) 55%, var(--border)); }
.stat.stale { border-color: color-mix(in srgb, var(--stale) 45%, var(--border)); }
.stat-label {
  display: flex; align-items: center; gap: 6px;
  font-size: 0.82rem; color: var(--muted); font-weight: 600; line-height: 1.25; min-height: 2.5em;
}
.stat-label span:last-child { hyphens: auto; -webkit-hyphens: auto; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.stat-label .s-icon { width: 17px; height: 17px; }
.stat-label .s-icon svg { width: 12px; height: 12px; }
.stat-value { font-size: 1.45rem; font-weight: 720; line-height: 1.2; letter-spacing: -0.01em; overflow-wrap: anywhere; }
.stat.stale .stat-value { color: var(--muted); }
.stat-note { font-size: 0.72rem; font-weight: 600; color: var(--muted); letter-spacing: 0; }
.spark { width: 100%; height: 30px; display: block; margin-top: 4px; overflow: visible; }
.spark-line { fill: none; stroke: var(--series); stroke-width: 1.6; stroke-linejoin: round; stroke-linecap: round; }
.spark-area { fill: var(--series); opacity: 0.12; }

.check-rows { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: minmax(0, 1fr); gap: 6px; }
.check-rows li { display: flex; align-items: center; gap: 10px; font-size: 0.95rem; }
.check-rows .s-icon { width: 18px; height: 18px; }
.check-rows .s-icon svg { width: 12px; height: 12px; }
.cr-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cr-word { color: var(--muted); font-size: 0.85rem; }

.card-foot {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  margin-top: auto; padding-top: 10px; border-top: 1px solid var(--border);
  color: var(--muted); font-size: 0.88rem;
}
.cf-more { display: inline-flex; align-items: center; gap: 8px; }
.cf-more .s-icon { width: 16px; height: 16px; }
.cf-more .s-icon svg { width: 11px; height: 11px; }
.cf-go { display: inline-flex; align-items: center; gap: 2px; color: var(--accent); font-weight: 650; margin-left: auto; white-space: nowrap; }
.cf-go svg { width: 16px; height: 16px; }
.sys-card:hover .cf-go { text-decoration: underline; }

/* the machines: present, but quieter than the systems that matter */
.cards.servers { grid-template-columns: repeat(auto-fill, minmax(min(100%, 270px), 1fr)); gap: 12px; }
.sys-card.server { background: transparent; box-shadow: inset 4px 0 0 var(--tone); padding: 14px 16px 10px 18px; gap: 10px; }
.sys-card.server:hover { background: var(--surface); }
.sys-card.server .card-title { font-size: 1.02rem; }
.sys-card.server .card-desc { font-size: 0.88rem; -webkit-line-clamp: 1; }
.sys-card.server .stat { background: transparent; padding: 7px 10px 4px; }
.sys-card.server .stat-label { min-height: 0; }
.sys-card.server .stat-value { font-size: 1.15rem; }
.sys-card.server .spark { height: 22px; }
.sys-card.server .card-foot { padding-top: 8px; font-size: 0.82rem; }

/* ---- one system ---- */
.back-link {
  display: inline-flex; align-items: center; gap: 6px; text-decoration: none; font-weight: 650;
  min-height: 44px; padding: 0 10px 0 4px; margin-left: -4px; border-radius: 10px; color: var(--accent);
}
.back-link:hover { background: var(--side-hover); }
.back-link svg { width: 20px; height: 20px; }
.sys-head { margin: 22px 0 6px; }
.sys-head-main { display: flex; align-items: center; gap: 12px 16px; flex-wrap: wrap; }
.sys-head h1 { font-size: 1.8rem; letter-spacing: -0.01em; overflow-wrap: anywhere; }
.sys-desc { margin: 6px 0 0; color: var(--muted); font-size: 1.02rem; }
.sys-desc:empty, .sys-since:empty { display: none; }
.sys-since { margin: 6px 0 0; font-size: 0.95rem; }
.sys-msg { color: var(--muted); margin: 24px 0; }

.toolbar { display: flex; align-items: center; gap: 12px; margin: 18px 0 16px; flex-wrap: wrap; }
.segmented {
  display: inline-flex; padding: 3px; gap: 2px; border-radius: 12px;
  background: var(--surface-2); border: 1px solid var(--border);
}
.segmented button {
  border: none; background: transparent; color: var(--muted);
  min-height: 40px; padding: 6px 14px; font-size: 0.95rem; font-weight: 600; border-radius: 9px;
}
.segmented button:hover { background: var(--surface); color: var(--fg); }
.segmented button[aria-pressed="true"] { background: var(--surface); color: var(--fg); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.14); font-weight: 750; }

.panels {
  display: grid; gap: 16px;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 440px), 1fr));
  align-items: start;
  transition: opacity 0.2s;
}
.panels.refetching { opacity: 0.5; }
.panel-empty { grid-column: 1 / -1; }
.panel {
  --tone: transparent;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow), inset 5px 0 0 var(--tone);
  padding: 16px 20px 14px 22px; min-width: 0;
  display: flex; flex-direction: column; gap: 8px;
}
.panel.warn { --tone: var(--warn); }
.panel.fail { --tone: var(--fail); }
.panel.stale { --tone: var(--stale); }
.panel-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.panel-head h3 { font-size: 1.12rem; overflow-wrap: anywhere; }
.panel-desc { margin: -4px 0 0; color: var(--muted); font-size: 0.93rem; line-height: 1.4; }
.panel-now { display: flex; align-items: baseline; gap: 4px 10px; flex-wrap: wrap; margin-top: 2px; }
.now-value { font-size: 2rem; font-weight: 740; letter-spacing: -0.015em; line-height: 1.1; }
.panel.stale .now-value { color: var(--muted); }
.now-label { color: var(--muted); font-size: 0.9rem; }
.now-when { color: var(--muted); font-size: 0.85rem; margin-left: auto; }
.panel-status { display: flex; align-items: center; gap: 12px; padding: 6px 0 2px; }
.panel-status .s-icon { width: 34px; height: 34px; }
.panel-status .s-icon svg { width: 22px; height: 22px; }
.panel-status > div { display: flex; flex-direction: column; }
.ps-word { font-size: 1.25rem; font-weight: 720; line-height: 1.2; }
.panel-status .now-when { margin-left: 0; }
.panel-detail { margin: 0; color: var(--muted); font-size: 0.92rem; overflow-wrap: anywhere; }

.help {
  background: var(--surface-2);
  border-radius: 10px;
  padding: 12px 14px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  display: grid; gap: 8px;
}
.help p { margin: 0; font-size: 0.97rem; line-height: 1.45; }
.help strong { display: block; margin-bottom: 1px; }
.help.fail { background: var(--fail-bg); }
.help.warn { background: var(--warn-bg); }
.help.stale { background: var(--stale-bg); }
.help-detail { font-size: 0.95rem; }

/* time-series charts: one series, so no legend; the panel title names it */
.chart-host { position: relative; width: 100%; margin-top: 4px; }
svg.chart { width: 100%; height: 100%; display: block; overflow: visible; touch-action: pan-y; border-radius: 6px; }
svg.chart:focus { outline: none; }
svg.chart:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }
.chart .grid line { stroke: var(--grid); stroke-width: 1; shape-rendering: crispEdges; }
.chart .grid line.base, .chart .grid line.tick { stroke: var(--axis); }
.chart .axis-label { fill: var(--muted); font-size: 12px; font-family: var(--font); font-variant-numeric: tabular-nums; }
.chart .band { fill: var(--series); opacity: 0.16; }
.chart .line { fill: none; stroke: var(--series); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .lone { fill: var(--series); }
.chart .end-dot, .chart .hover-dot { fill: var(--series); stroke: var(--surface); stroke-width: 2; }
.chart .crosshair { stroke: var(--muted); stroke-width: 1; shape-rendering: crispEdges; }
.chart .hit { fill: transparent; cursor: crosshair; }
.chart-tip {
  position: absolute; z-index: 2; pointer-events: none;
  display: flex; flex-direction: column; gap: 1px;
  background: var(--surface); color: var(--fg);
  border: 1px solid var(--border); border-radius: 9px; box-shadow: var(--shadow-lg);
  padding: 7px 11px; font-size: 0.82rem; line-height: 1.35; white-space: nowrap;
}
.chart-tip strong { font-size: 1.08rem; }
.tip-spread, .tip-time { color: var(--muted); }
.chart-empty {
  margin: 0; height: 100%; display: grid; place-items: center; text-align: center;
  color: var(--muted); background: var(--surface-2); border-radius: 10px; font-size: 0.95rem; padding: 0 16px;
}
.chart-table summary { cursor: pointer; color: var(--muted); font-size: 0.86rem; width: fit-content; }
.table-wrap { max-height: 240px; overflow: auto; margin-top: 8px; border: 1px solid var(--border); border-radius: 8px; }
table.numbers { width: 100%; border-collapse: collapse; font-size: 0.86rem; font-variant-numeric: tabular-nums; }
table.numbers th { position: sticky; top: 0; background: var(--surface-2); text-align: left; font-weight: 650; padding: 6px 10px; }
table.numbers td { padding: 4px 10px; border-top: 1px solid var(--border); white-space: nowrap; }

/* ---- recent changes + activity ---- */
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li {
  display: grid; grid-template-columns: 9em 1fr; gap: 12px;
  padding: 10px 0; border-bottom: 1px solid var(--border);
}
.timeline li:last-child { border-bottom: none; }
.timeline li.empty { display: block; }
.timeline .when { color: var(--muted); font-size: 0.92rem; }
.timeline .what { overflow-wrap: anywhere; }
.timeline .ev-sys { display: block; color: var(--muted); font-size: 0.85rem; font-weight: 600; }
.timeline .arrow { color: var(--muted); }
.timeline .ev-detail { color: var(--muted); font-size: 0.92rem; }
.timeline .pill { font-size: 0.74rem; padding: 2px 9px; }

details.activity { margin: 30px 0 20px; }
details.activity summary { cursor: pointer; font-weight: 600; color: var(--muted); font-size: 0.95rem; }
.audit { font-size: 0.9rem; width: 100%; border-collapse: collapse; margin-top: 10px; }
.audit td { padding: 6px 8px; border-bottom: 1px solid var(--border); vertical-align: top; overflow-wrap: anywhere; }
.audit td:first-child { white-space: nowrap; color: var(--muted); }

.note { color: var(--muted); font-size: 0.92rem; }
.error-text { color: var(--fail); font-weight: 600; }
.empty { color: var(--muted); padding: 8px 0; }

/* ---- language switch (sidebar and login page) ---- */
.lang-switch { display: flex; align-items: center; gap: 4px; padding: 4px 6px; margin-top: 4px; }
.lang-switch > svg { width: 20px; height: 20px; color: var(--muted); margin: 0 6px 0 6px; }
.lang-switch button {
  min-height: 38px; padding: 4px 12px; font-size: 0.92rem; font-weight: 550;
  border: 1px solid transparent; background: transparent; color: var(--muted); border-radius: 9px;
}
.lang-switch button:hover { background: var(--side-hover); color: var(--fg); }
.lang-switch button[aria-pressed="true"] { background: var(--surface); border-color: var(--border); color: var(--fg); font-weight: 720; }

/* ---- session view ---------------------------------------------------------- */
.sess-head { padding-top: 10px; padding-bottom: 10px; }
.sess-heading { flex: 1; min-width: 0; }
.sess-heading h1 { font-size: 1.2rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sess-meta {
  display: flex; align-items: center; gap: 6px 14px; flex-wrap: wrap;
  color: var(--muted); font-size: 0.88rem; margin-top: 2px;
}
.sess-meta #sess-repo { font-weight: 600; color: var(--fg); }
.tag {
  font-size: 0.78rem; font-weight: 700; padding: 1px 8px; border-radius: 999px;
  color: var(--warn); background: var(--warn-bg);
}
.conn { display: inline-flex; align-items: center; gap: 6px; }
.conn .status-dot { width: 9px; height: 9px; animation: none; }

.sess-notice {
  display: flex; align-items: center; gap: 12px; flex: none;
  margin: 12px 20px 0; padding: 10px 14px; border-radius: 10px;
  background: var(--surface); border: 1px solid var(--border); font-size: 0.95rem;
}
.sess-notice p { margin: 0; flex: 1; }
.sess-notice .first-time { color: var(--muted); }
.sess-notice.warn { background: var(--warn-bg); border-color: color-mix(in srgb, var(--warn) 35%, transparent); }
.sess-notice button { flex: none; }

.term-frame {
  position: relative; flex: 1; min-height: 0;
  margin: 12px 20px 16px; border-radius: 12px; overflow: hidden;
  background: var(--term-bg); border: 1px solid var(--border);
}
.term { position: absolute; inset: 10px 4px 6px 12px; }
.term .xterm { height: 100%; }
.term .xterm-viewport { background: var(--term-bg) !important; }

.term-overlay {
  position: absolute; inset: 0; display: grid; place-items: center; padding: 20px;
  background: color-mix(in srgb, var(--term-bg) 80%, transparent);
}
.overlay-box {
  background: var(--surface); color: var(--fg); border-radius: var(--radius); padding: 24px;
  max-width: 420px; width: 100%; box-shadow: var(--shadow-lg);
}
.overlay-title { font-size: 1.2rem; font-weight: 700; margin: 0 0 6px; }
.overlay-text { color: var(--muted); margin: 0 0 16px; }
.overlay-actions { display: flex; gap: 10px; flex-wrap: wrap; }

.keys {
  display: none; flex: none; gap: 6px; padding: 0 12px 10px; overflow-x: auto;
  padding-bottom: max(10px, env(safe-area-inset-bottom));
}
.keys button { flex: none; min-width: 48px; min-height: 42px; padding: 6px 12px; font-size: 0.9rem; font-family: var(--mono); }
@media (pointer: coarse), (max-width: 700px) { .keys { display: flex; } }

/* ---- dialogs ---------------------------------------------------------------- */
.dialog {
  border: 1px solid var(--border); border-radius: 18px; padding: 22px 24px 20px;
  background: var(--surface); color: var(--fg); box-shadow: var(--shadow-lg);
  width: min(560px, calc(100vw - 24px)); max-height: calc(100dvh - 32px);
}
.dialog::backdrop { background: rgba(10, 12, 16, 0.45); }
.dialog-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.dialog-head h2 { font-size: 1.35rem; }
.dialog-head .icon-btn { margin: -8px -10px -8px 0; }
.dialog-intro { color: var(--muted); margin: 4px 0 16px; }
.confirm { width: min(440px, calc(100vw - 24px)); }
.confirm h2 { font-size: 1.25rem; overflow-wrap: anywhere; }
.confirm p { color: var(--muted); margin: 8px 0 20px; }
.dialog-actions { display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; }

.repo-options { display: grid; gap: 10px; }
.repo-option {
  display: flex; flex-direction: column; align-items: stretch; gap: 8px; text-align: left;
  width: 100%; padding: 14px 16px; border-radius: 12px; font-weight: 400;
  border: 1px solid var(--border); background: var(--surface);
}
button.repo-option:hover { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 6%, var(--surface)); }
.repo-option, .repo-option button { font-size: 17px; }
.opt-text { display: flex; flex-direction: column; gap: 2px; }
.opt-foot { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.opt-go { color: var(--accent); font-weight: 700; }
button.repo-option:hover .opt-go { text-decoration: underline; }
.opt-name { font-weight: 700; font-size: 1.1rem; }
.opt-desc { color: var(--muted); }
.opt-state { display: inline-flex; align-items: center; gap: 8px; font-size: 0.92rem; color: var(--muted); font-weight: 600; }
.opt-state.ok { color: var(--ok); }
.opt-state svg { font-size: 18px; }
.repo-option.error { border-color: color-mix(in srgb, var(--fail) 40%, var(--border)); background: var(--fail-bg); }
.repo-option.missing { background: var(--surface-2); }
.opt-problem { font-size: 0.95rem; }
.opt-detail { font-size: 0.85rem; color: var(--muted); }
.opt-detail summary { cursor: pointer; }
.opt-detail p { margin: 6px 0 0; font-family: var(--mono); font-size: 0.8rem; overflow-wrap: anywhere; }
.opt-actions { display: flex; gap: 10px; }
.spinner {
  width: 16px; height: 16px; border-radius: 50%; flex: none;
  border: 2.5px solid var(--border); border-top-color: var(--accent);
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner, .status-dot.fail { animation-duration: 3s; } }

.toggle { display: flex; align-items: flex-start; gap: 10px; margin: 16px 0 0; cursor: pointer; }
.toggle input { width: 22px; height: 22px; margin-top: 3px; flex: none; }
.advanced { margin-top: 18px; border-top: 1px solid var(--border); padding-top: 12px; }
.advanced summary { cursor: pointer; color: var(--muted); font-size: 0.95rem; }
.advanced .note { margin: 8px 0; }
.shell-options { display: flex; flex-wrap: wrap; gap: 8px; }

/* ---- login -------------------------------------------------------------------- */
.login-box {
  max-width: 420px; margin: 10vh auto 40px; padding: 28px 24px;
}
.login-box h1 { font-size: 1.8rem; margin-bottom: 6px; }
.login-lang { justify-content: flex-end; margin: -14px -10px 6px 0; padding: 0; }
.login-box .lang-switch button { width: auto; margin-top: 0; }
.login-box .error-text { color: var(--fail); margin: 12px 0 0; }
.login-lang button:hover { background: var(--surface-2); }
.login-lang button[aria-pressed="true"] { background: var(--surface-2); }
.login-box p { color: var(--muted); margin: 0 0 20px; }
.login-box label { display: block; font-weight: 600; margin: 14px 0 6px; }
.login-box button { width: 100%; margin-top: 22px; }

/* ---- phones and narrow windows: the sidebar becomes a drawer ---------------------- */
@media (max-width: 860px) {
  .only-phone { display: inline-flex; }
  .sidebar {
    position: fixed; z-index: 40; top: 0; bottom: 0; left: 0;
    width: min(86vw, 320px);
    transform: translateX(-102%);
    transition: transform 0.22s ease;
    box-shadow: var(--shadow-lg);
    padding-top: max(14px, env(safe-area-inset-top));
  }
  body.drawer-open .sidebar { transform: none; }
  .scrim { position: fixed; inset: 0; z-index: 30; background: rgba(10, 12, 16, 0.45); }
  .view-head { padding: 8px 12px; min-height: 56px; gap: 6px; }
  .view-head h1 { font-size: 1.2rem; }
  .page { padding: 0 16px 32px; }
  .sess-notice { margin: 8px 10px 0; }
  .term-frame { margin: 8px 8px 8px; border-radius: 10px; }
  .term { inset: 6px 2px 4px 6px; }
  .keys { padding: 0 8px 8px; }
}
@media (prefers-reduced-motion: reduce) { .sidebar { transition: none; } }

@media (max-width: 600px) {
  body { font-size: 17px; }
  .banner { padding: 16px; gap: 14px; }
  .banner .icon { width: 44px; height: 44px; font-size: 1.5rem; }
  .banner .headline { font-size: 1.4rem; }
  .timeline li { grid-template-columns: 1fr; gap: 2px; }
  .sys-card { padding: 16px 16px 12px 18px; }
  .panel { padding: 14px 14px 12px 18px; }
  .sys-head h1 { font-size: 1.5rem; }
  .now-value { font-size: 1.75rem; }
  .segmented { display: flex; width: 100%; }
  .segmented button { flex: 1; padding: 6px 4px; font-size: 0.9rem; }
  .sess-head .danger-outline { padding: 8px 12px; min-height: 40px; font-size: 0.92rem; }
  .sess-meta #sess-started { display: none; }
  .sess-notice { font-size: 0.86rem; padding: 8px 12px; gap: 8px; line-height: 1.4; }
  .dialog { padding: 18px 16px 16px; }
}

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
[hidden] { display: none !important; }

/* ---- Accounts (login token + backup key) ---- */
.accounts-btn {
  width: 100%; justify-content: flex-start; gap: 10px; margin-top: 6px;
  border: 0; background: transparent; padding: 10px 12px; border-radius: 10px; font-weight: 600;
}
.accounts-btn:hover { background: var(--side-hover); }
.accounts-btn svg { width: 20px; height: 20px; flex: none; color: var(--muted); }
.accounts-btn .nav-label { flex: 1; text-align: left; }
.accounts-flag {
  font-size: 0.78rem; font-weight: 700; padding: 2px 8px; border-radius: 999px;
  background: var(--warn-bg, color-mix(in srgb, var(--warn) 18%, transparent)); color: var(--warn);
}
.accounts { width: min(600px, calc(100vw - 24px)); overflow-y: auto; }
.account { border: 1px solid var(--border); border-radius: 14px; padding: 16px; margin-top: 14px; }
.account-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.account-head h3 { font-size: 1.1rem; margin: 0; }
.account-state { font-weight: 700; font-size: 0.92rem; }
.account-state.on { color: var(--ok); }
.account-state.off { color: var(--muted); }
.account-state.soon { color: var(--warn); }
.account .note { margin: 8px 0 0; }
.account code { font-size: 0.92em; padding: 1px 5px; border-radius: 6px; background: var(--surface-2); }
.account-row { display: flex; gap: 10px; margin-top: 12px; }
.account-row input { flex: 1; min-width: 0; }
.account-msg { margin: 10px 0 0; font-weight: 600; }
.account-msg.good { color: var(--ok); }
.account-msg.bad { color: var(--fail); }
.account-msg.careful { color: var(--warn); }
.account .link { margin-top: 8px; padding-left: 0; }
@media (max-width: 520px) { .account-row { flex-direction: column; } }
