:root {
  color-scheme: dark;
  --bg: var(--tg-theme-bg-color, #0b0c0f);
  --surface: var(--tg-theme-secondary-bg-color, #15171c);
  --surface-soft: color-mix(in srgb, var(--surface) 78%, var(--bg));
  --text: var(--tg-theme-text-color, #f2f3f5);
  --muted: var(--tg-theme-hint-color, #8e939d);
  --link: var(--tg-theme-link-color, #4f9cff);
  --button: var(--tg-theme-button-color, #2f86f6);
  --button-text: var(--tg-theme-button-text-color, #fff);
  --line: color-mix(in srgb, var(--muted) 22%, transparent);
  --ok: #3bb68a;
  --warn: #e39a2d;
  --bad: #f05b66;
  --run: #4f9cff;
  --safe-top: var(--tg-content-safe-area-inset-top, var(--tg-safe-area-inset-top, 0px));
  --safe-bottom: var(--tg-content-safe-area-inset-bottom, var(--tg-safe-area-inset-bottom, 0px));
  --topbar-height: 48px;
  --tabbar-height: 64px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { min-height: 100%; background: var(--bg); }
body {
  min-height: 100%;
  margin: 0;
  padding-top: var(--safe-top);
  padding-bottom: calc(var(--tabbar-height) + var(--safe-bottom) + 12px);
  background: var(--bg);
  color: var(--text);
  font: 15px/1.35 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}
body.sheet-open { overflow: hidden; }
button, input, select { font: inherit; }
button { -webkit-tap-highlight-color: transparent; cursor: pointer; }
button:focus-visible, input:focus-visible, select:focus-visible, summary:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--link) 42%, transparent);
  outline-offset: 2px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  min-height: var(--topbar-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 4px 8px 4px 16px;
  border-bottom: .5px solid var(--line);
  background: var(--bg);
}
.brand { min-width: 0; }
.brand strong, .brand small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.brand strong { font-size: 15px; line-height: 19px; letter-spacing: -.15px; }
.brand small { max-width: 230px; color: var(--muted); font-size: 10px; line-height: 13px; }
.top-actions { display: flex; align-items: center; gap: 2px; }
.icon-button, .sheet-action {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--link);
}
.icon-button:active, .sheet-action:active { background: color-mix(in srgb, var(--link) 14%, transparent); }
.icon-button svg, .sheet-action svg { width: 21px; height: 21px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.freshness-pill {
  min-height: 30px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0 9px;
  border: 1px solid color-mix(in srgb, var(--warn) 25%, transparent);
  border-radius: 999px;
  background: transparent;
  color: var(--warn);
  font-size: 10px;
}
.freshness-pill > span { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.freshness-note {
  position: sticky;
  top: calc(var(--safe-top) + var(--topbar-height));
  z-index: 9;
  margin: 0;
  padding: 7px 16px;
  border-bottom: .5px solid color-mix(in srgb, var(--warn) 28%, transparent);
  background: color-mix(in srgb, var(--warn) 8%, var(--bg));
  color: var(--text);
  font-size: 11px;
}

main { width: min(100%, 720px); margin: 0 auto; padding: 0 16px 8px; }
.loading, .empty, .empty-state { padding: 36px 14px; text-align: center; color: var(--muted); }
.empty-state { margin: 12px 0; border: 1px dashed var(--line); border-radius: 14px; }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 5px; font-size: clamp(1.55rem, 7vw, 2rem); line-height: 1.08; letter-spacing: -.75px; }
h2 { font-size: 15px; line-height: 20px; letter-spacing: -.1px; }
h3 { margin: 20px 0 8px; font-size: 14px; }
p { margin-bottom: 8px; }
.eyebrow, .detail-kicker {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 750;
  letter-spacing: .09em;
}
.muted { color: var(--muted); }

.status-hero, .server-hero {
  position: relative;
  margin: 0 -16px 4px;
  padding: 20px 20px 17px 24px;
  border-bottom: .5px solid var(--line);
}
.status-hero::before, .server-hero::before {
  content: "";
  position: absolute;
  left: 0;
  top: 20px;
  bottom: 18px;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: var(--muted);
}
.status-hero.CRITICAL::before, .status-hero.ERROR::before, .server-hero.CRITICAL::before, .server-hero.ERROR::before { background: var(--bad); }
.status-hero.WARNING::before, .status-hero.STALE::before, .server-hero.WARNING::before, .server-hero.STALE::before { background: var(--warn); }
.status-hero.OK::before, .server-hero.OK::before { background: var(--ok); }
.status-hero p, .server-hero p { margin: 0; color: var(--muted); font-size: 13px; }
.hero-meta { min-height: 24px; display: flex; align-items: center; flex-wrap: wrap; gap: 7px; margin-top: 14px; }
.hero-meta .count { padding: 3px 7px; border: 1px solid var(--line); border-radius: 999px; font-size: 10px; font-weight: 700; }
.hero-meta .critical { border-color: color-mix(in srgb, var(--bad) 35%, transparent); color: var(--bad); }
.hero-meta .warning { border-color: color-mix(in srgb, var(--warn) 35%, transparent); color: var(--warn); }
.hero-meta .updated { margin-left: auto; color: var(--muted); font-size: 10px; }

.panel { margin: 0 -4px; padding: 17px 4px 5px; }
.section-title { min-width: 0; display: flex; align-items: flex-end; justify-content: space-between; gap: 10px; padding: 0 4px 8px; }
.section-title > div { min-width: 0; }
.section-title h2 { margin: 0; }
.section-title small { display: block; margin-top: 1px; color: var(--muted); font-size: 11px; line-height: 15px; }
.section-link, .text-action {
  min-height: 38px;
  padding: 0 4px;
  border: 0;
  background: transparent;
  color: var(--link);
  font-size: 12px;
  font-weight: 650;
  white-space: nowrap;
}
.text-action { padding: 0; }
.footer-action { width: 100%; margin-top: 8px; }

.state {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}
.state::before, .status-dot::before {
  content: "";
  width: 7px;
  height: 7px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: #808690;
}
.status-dot { width: 18px; height: 24px; display: inline-flex; align-items: center; justify-content: center; }
.state.OK::before, .state.RESOLVED::before, .status-dot.OK::before, .status-dot.RESOLVED::before { background: var(--ok); }
.state.RUNNING::before, .state.ACTIVE::before, .status-dot.RUNNING::before, .status-dot.ACTIVE::before { background: var(--run); }
.state.WARNING::before, .state.RETRY::before, .state.WAITING::before, .state.STALE::before,
.status-dot.WARNING::before, .status-dot.RETRY::before, .status-dot.WAITING::before, .status-dot.STALE::before { background: var(--warn); }
.state.ERROR::before, .state.CRITICAL::before, .status-dot.ERROR::before, .status-dot.CRITICAL::before { background: var(--bad); }

.alert-row, .summary-row, .process-row {
  width: 100%;
  min-height: 60px;
  display: grid;
  align-items: center;
  gap: 9px;
  padding: 9px 4px;
  border: 0;
  border-top: .5px solid var(--line);
  border-radius: 0;
  background: transparent;
  color: var(--text);
  text-align: left;
}
.alert-row { grid-template-columns: 25px minmax(0, 1fr) 16px; }
.summary-row { grid-template-columns: 18px minmax(0, 1fr) 16px; }
.process-row { grid-template-columns: 18px minmax(0, 1fr) auto 16px; }
.alert-row:first-of-type, .summary-row:first-of-type, .process-row:first-of-type { border-top: 0; }
.alert-row:active, .summary-row:active, .process-row:active { opacity: .55; }
.row-copy { min-width: 0; }
.row-copy strong, .row-copy span, .row-copy small, .summary-row strong, .summary-row small { display: block; }
.row-copy strong, .summary-row strong { overflow-wrap: anywhere; font-size: 13px; line-height: 17px; }
.row-message, .row-copy small, .summary-row small {
  display: -webkit-box;
  overflow: hidden;
  margin-top: 2px;
  color: var(--muted);
  font-size: 11px;
  line-height: 15px;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}
.row-copy small { margin-top: 3px; font-size: 10px; }
.chevron { color: color-mix(in srgb, var(--muted) 68%, transparent); font-size: 23px; font-weight: 300; line-height: 1; text-align: right; }
.severity-mark { width: 20px; height: 20px; display: grid; place-items: center; border: 1px solid var(--warn); border-radius: 50%; color: var(--warn); font-size: 12px; font-weight: 800; }
.alert-row.critical .severity-mark { border-radius: 6px; border-color: var(--bad); background: color-mix(in srgb, var(--bad) 12%, transparent); color: var(--bad); }

.area-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); border: .5px solid var(--line); border-radius: 14px; overflow: hidden; }
.area-tile {
  position: relative;
  min-height: 66px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-content: center;
  gap: 2px 7px;
  padding: 11px 12px;
  border: 0;
  border-right: .5px solid var(--line);
  border-bottom: .5px solid var(--line);
  background: transparent;
  color: var(--text);
  text-align: left;
}
.area-tile:nth-child(2n) { border-right: 0; }
.area-tile:nth-last-child(-n + 2) { border-bottom: 0; }
.area-tile strong { overflow: hidden; font-size: 13px; text-overflow: ellipsis; white-space: nowrap; }
.area-tile > span:not(.status-dot) { color: var(--muted); font-size: 11px; }
.area-tile .status-dot { grid-column: 2; grid-row: 1 / 3; align-self: center; }
.area-tile:active { background: var(--surface-soft); }
.healthy-note { margin: 9px 4px 0; color: var(--muted); font-size: 11px; }

.screen-intro { position: relative; padding: 20px 0 14px; border-bottom: .5px solid var(--line); }
.screen-intro h1 { margin-bottom: 4px; font-size: 26px; }
.screen-intro p { margin: 0; color: var(--muted); font-size: 12px; }
.screen-intro .text-action { position: static; width: fit-content; margin-top: 10px; }
.segmented { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; margin: 12px 0 8px; padding: 3px; border-radius: 11px; background: var(--surface); }
.segmented button { min-width: 0; min-height: 36px; padding: 5px; border: 0; border-radius: 8px; background: transparent; color: var(--muted); font-size: 11px; font-weight: 650; display: flex; align-items: center; justify-content: center; gap: 5px; }
.segmented button[data-active="true"] { background: color-mix(in srgb, var(--text) 10%, var(--surface)); color: var(--text); }
.filter-label { min-width: 0; overflow-wrap: anywhere; line-height: 1.15; }
.filter-count { min-width: 17px; flex: 0 0 auto; padding: 1px 5px; border-radius: 999px; background: color-mix(in srgb, var(--text) 8%, transparent); font-variant-numeric: tabular-nums; line-height: 17px; text-align: center; }
.segmented button[data-active="true"] .filter-count { background: color-mix(in srgb, var(--accent) 18%, transparent); }
.job-filters { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.alert-search { margin: 3px 0 8px; }
.alert-section { margin: 15px 0 0; }
.alert-section > header { min-height: 26px; display: flex; align-items: center; gap: 7px; padding: 0 4px 6px; }
.alert-section > header h2 { margin: 0; }
.alert-section > header span { min-width: 20px; padding: 1px 6px; border: 1px solid var(--line); border-radius: 999px; color: var(--muted); font-size: 10px; text-align: center; }
.alert-section.critical > header h2 { color: var(--bad); }
.alert-section.warning > header h2 { color: var(--warn); }

.process-section { margin: 17px 0 0; }
.process-section > h2 { margin: 0; padding: 0 4px 6px; }
.process-section.problem > h2 { color: var(--warn); }
.process-section.healthy { margin-top: 22px; }
.process-section.healthy > h2 { color: var(--muted); font-size: 13px; }
.process-section.healthy .state { display: none; }

.server-hero { padding-bottom: 14px; }
.server-hero h1 { max-width: 280px; margin-bottom: 8px; font-size: 24px; }
.server-hero > .state { position: absolute; top: 22px; right: 18px; }
.server-metrics { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0; margin-top: 18px; }
.server-metrics > div { min-width: 0; padding: 0 9px; border-left: .5px solid var(--line); }
.server-metrics > div:first-child { padding-left: 0; border-left: 0; }
.server-metrics strong, .server-metrics span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.server-metrics strong { font-size: 17px; letter-spacing: -.25px; }
.server-metrics span { margin-top: 2px; color: var(--muted); font-size: 9px; }
.server-sections { margin-top: 11px; }

button.primary, button.quiet, button.wide {
  min-height: 44px;
  padding: 9px 13px;
  border: 0;
  border-radius: 11px;
  background: var(--button);
  color: var(--button-text);
  font-weight: 650;
}
button.quiet { background: color-mix(in srgb, var(--link) 12%, var(--surface)); color: var(--link); }
button.wide { width: 100%; margin-top: 8px; }
.button-row { display: flex; flex-wrap: wrap; gap: 8px; }
.button-row > button { flex: 1 1 145px; }

input, select {
  width: 100%;
  min-height: 44px;
  padding: 9px 11px;
  border: .5px solid var(--line);
  border-radius: 11px;
  background: var(--surface);
  color: var(--text);
}
.tools { position: sticky; top: 0; z-index: 2; display: grid; grid-template-columns: minmax(0, 1fr) auto auto; gap: 7px; padding: 2px 0 8px; background: var(--surface); }
.tools select { width: auto; max-width: 140px; }
.session-tools { grid-template-columns: minmax(0, 1fr) minmax(112px, .85fr) minmax(104px, .75fr); }

.detail-lead { margin: 0 0 12px; padding-bottom: 10px; border-bottom: .5px solid var(--line); }
.detail-lead .state { margin-bottom: 6px; }
.detail-lead p { margin: 0; font-size: 14px; }
.detail { display: grid; grid-template-columns: minmax(105px, .8fr) minmax(0, 1.2fr); gap: 0 12px; margin: 0; }
.detail dt, .detail dd { min-height: 40px; display: flex; align-items: center; padding: 7px 0; border-bottom: .5px solid var(--line); }
.detail dt { color: var(--muted); font-size: 12px; }
.detail dd { justify-content: flex-end; margin: 0; overflow-wrap: anywhere; text-align: right; font-size: 12px; font-weight: 600; }
.stat-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; margin: 8px 0; }
.stat { min-width: 0; padding: 9px; border: .5px solid var(--line); border-radius: 10px; }
.stat small, .stat strong { display: block; }
.stat small { color: var(--muted); font-size: 10px; }
.stat strong { margin-top: 2px; font-size: 13px; }
details.technical { margin-top: 11px; border-top: .5px solid var(--line); }
details.technical summary { min-height: 44px; display: flex; align-items: center; color: var(--link); font-size: 12px; cursor: pointer; }
.subcard { display: grid; grid-template-columns: auto 1fr; gap: 5px 9px; margin: 6px 0; padding: 9px 0; border-bottom: .5px solid var(--line); }
.subcard small, .subcard p { grid-column: 2; margin: 0; }
.notice { margin: 8px 0; padding: 10px 11px; border-left: 3px solid var(--warn); background: color-mix(in srgb, var(--warn) 7%, transparent); font-size: 12px; }
.error-text, pre { overflow-wrap: anywhere; white-space: pre-wrap; color: var(--bad); }
.job, .issue { min-height: 48px; display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 8px; padding: 8px 0; border-bottom: .5px solid var(--line); }
.job:last-child, .issue:last-child { border-bottom: 0; }
.job small, .issue small { color: var(--muted); font-size: 11px; text-align: right; }
.list-row {
  width: 100%;
  min-height: 56px;
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr) 18px;
  align-items: center;
  gap: 7px;
  padding: 8px 0;
  border: 0;
  border-top: .5px solid var(--line);
  background: transparent;
  color: var(--text);
  text-align: left;
}
.list-row:first-of-type { border-top: 0; }
.list-row strong, .list-row small { display: block; }
.list-row strong { overflow-wrap: anywhere; font-size: 13px; }
.list-row small { margin-top: 2px; color: var(--muted); font-size: 11px; }
.duration-row { grid-template-columns: 18px minmax(0, 1fr) auto 16px; }
.duration-value { color: var(--text); font-size: 12px; font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.chart { width: 100%; height: 180px; border: .5px solid var(--line); border-radius: 12px; background: var(--surface); }
.chart path { fill: none; stroke: var(--link); stroke-width: 2; }
.chart circle { fill: var(--surface); stroke: var(--link); stroke-width: 2; }
#refresh[aria-busy="true"] svg { animation: spin .7s linear infinite; }

#tabs {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 11;
  min-height: calc(var(--tabbar-height) + var(--safe-bottom));
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  align-items: start;
  padding: 4px 6px calc(6px + var(--safe-bottom));
  border-top: .5px solid var(--line);
  background: var(--bg);
}
#tabs button {
  position: relative;
  min-height: 54px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  padding: 4px 2px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 9px;
  font-weight: 620;
}
#tabs button svg { width: 21px; height: 21px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
#tabs button:first-child svg { fill: currentColor; stroke: none; }
#tabs button[data-active="true"] { color: var(--link); }
#alert-count:not(:empty) { position: absolute; top: 1px; left: calc(50% + 7px); min-width: 17px; height: 17px; display: grid; place-items: center; padding: 0 4px; border: 2px solid var(--bg); border-radius: 9px; background: var(--bad); color: #fff; font-size: 9px; line-height: 1; }

#sheet { position: fixed; inset: 0; z-index: 20; display: flex; align-items: flex-end; justify-content: center; padding-top: var(--safe-top); }
#sheet[hidden] { display: none; }
#sheet-scrim { position: absolute; inset: 0; width: 100%; height: 100%; padding: 0; border: 0; border-radius: 0; background: rgba(0, 0, 0, .46); }
#sheet-panel {
  position: relative;
  width: min(100%, 720px);
  max-height: min(74dvh, 620px);
  display: flex;
  flex-direction: column;
  padding-bottom: var(--safe-bottom);
  border: .5px solid var(--line);
  border-bottom: 0;
  border-radius: 18px 18px 0 0;
  background: var(--surface);
  overflow: hidden;
  animation: sheet-in .2s cubic-bezier(.2, .8, .2, 1);
}
#sheet-panel[data-mode="full"] { max-height: calc(100dvh - var(--safe-top) - 8px); min-height: min(82dvh, 720px); }
.sheet-grabber { width: 34px; height: 4px; flex: 0 0 auto; margin: 7px auto 2px; border-radius: 3px; background: color-mix(in srgb, var(--muted) 42%, transparent); }
#sheet-panel > header { min-height: 48px; display: grid; grid-template-columns: 44px minmax(0, 1fr) 44px; align-items: center; padding: 0 4px; border-bottom: .5px solid var(--line); }
#sheet-back { grid-column: 1; }
#sheet-title { padding: 7px 0; overflow-wrap: anywhere; font-size: 15px; line-height: 19px; text-align: center; }
#sheet-title { grid-column: 2; }
#sheet-close { grid-column: 3; }
#sheet-body { min-width: 0; min-height: 0; overflow-x: hidden; overflow-y: auto; overscroll-behavior: contain; padding: 13px 16px 20px; }

@keyframes sheet-in { from { transform: translateY(16px); opacity: .6; } to { transform: translateY(0); opacity: 1; } }
@keyframes spin { to { transform: rotate(360deg); } }
@media (max-width: 370px) {
  main { padding-right: 12px; padding-left: 12px; }
  .status-hero, .server-hero { margin-right: -12px; margin-left: -12px; padding-left: 20px; }
  .segmented button { font-size: 10px; }
  .process-row .state { display: none; }
  .screen-intro .text-action { position: static; margin-top: 8px; }
  .server-hero > .state { position: static; margin-bottom: 8px; }
}
@media (max-width: 470px) {
  .tools { grid-template-columns: 1fr 1fr; }
  .tools input { grid-column: 1 / -1; }
  .tools select { width: 100%; max-width: none; }
  .session-tools { grid-template-columns: minmax(0, 1.1fr) minmax(0, .9fr); }
}
@media (min-width: 721px) {
  #sheet { align-items: center; padding: 24px; }
  #sheet-panel { border-radius: 18px; border-bottom: .5px solid var(--line); padding-bottom: 0; }
  #tabs { left: 50%; width: 720px; transform: translateX(-50%); border-right: .5px solid var(--line); border-left: .5px solid var(--line); }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; animation: none !important; }
}
