:root {
  --bg: var(--tg-theme-bg-color, #0d0c12);
  --surface: var(--tg-theme-secondary-bg-color, #17151f);
  --surface-raised: color-mix(in srgb, var(--surface) 88%, white 12%);
  --text: var(--tg-theme-text-color, #f6f4fb);
  --muted: var(--tg-theme-hint-color, #9a96a7);
  --accent: var(--tg-theme-button-color, #7132f5);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --border: color-mix(in srgb, var(--muted) 22%, transparent);
  --green: #36c98f;
  --amber: #f1b84b;
  --red: #ff6868;
  --slate: #858194;
  --radius: 14px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

:root[data-theme="light"] {
  --green: #006644;
  --amber: #765000;
  --red: #a61b29;
  --slate: #4f4b57;
  --muted: #4f4b57;
}

:root[data-theme="light"] .mode-banner-paper {
  border-color: #c7aedf;
  background: #f2ebf8;
  color: #4f4b57;
}

:root[data-theme="light"] .mode-banner-paper strong { color: #4b168f; }

* { box-sizing: border-box; }

html { background: var(--bg); }

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--text);
  font-family: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-variant-numeric: tabular-nums;
}

button { font: inherit; }

.app-shell {
  width: min(100%, 760px);
  min-height: 100dvh;
  margin: 0 auto;
  padding: calc(18px + var(--safe-top)) 16px calc(28px + var(--safe-bottom));
}

.topbar,
.section-heading,
.capital-row > div:first-child,
footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.eyebrow,
.section-kicker {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .1em;
  text-transform: uppercase;
}

h1, h2 { margin: 0; letter-spacing: -.035em; }
h1 { font-size: 25px; line-height: 1.1; }
h2 { font-size: 20px; line-height: 1.2; }

.connection-state {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 36px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.state-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--amber);
}

.connection-state[data-state="ok"] .state-dot { background: var(--green); }
.connection-state[data-state="warning"] .state-dot { background: var(--amber); }
.connection-state[data-state="error"] .state-dot { background: var(--red); }

.demo-banner,
.mode-banner {
  margin-top: 14px;
  border-radius: 10px;
  font-size: 12px;
  font-weight: 650;
}

.demo-banner {
  padding: 9px 12px;
  background: var(--amber);
  color: #251a03;
  text-align: center;
  letter-spacing: .045em;
}

.mode-switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 3px;
  margin-top: 16px;
  padding: 3px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
}

.mode-button {
  min-height: 44px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-weight: 700;
}

.mode-button[aria-pressed="true"] {
  background: var(--accent);
  color: var(--accent-text);
}

.mode-button:focus-visible,
#retry-button:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 55%, white); outline-offset: 2px; }

.mode-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 12px;
  border: 1px solid color-mix(in srgb, var(--red) 32%, transparent);
  background: color-mix(in srgb, var(--red) 10%, var(--surface));
  color: var(--muted);
}

.mode-banner strong { color: var(--red); font-size: 11px; letter-spacing: .08em; }
.mode-banner-paper { border-color: color-mix(in srgb, var(--accent) 34%, transparent); background: color-mix(in srgb, var(--accent) 11%, var(--surface)); }
.mode-banner-paper strong { color: color-mix(in srgb, var(--accent) 70%, white); }

.section {
  margin-top: 14px;
  padding: 17px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.section-heading { align-items: flex-end; margin-bottom: 15px; }
.source-timestamp { color: var(--muted); font-size: 11px; }

.health-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.metric {
  min-width: 0;
  padding: 12px 10px;
  border-radius: 11px;
  background: var(--surface-raised);
}

.metric span { display: block; overflow: hidden; color: var(--muted); font-size: 10px; text-overflow: ellipsis; }
.metric strong { display: block; margin-top: 5px; font-size: 22px; line-height: 1; }
.health-healthy strong { color: var(--green); }
.health-warning strong { color: var(--amber); }
.health-critical strong { color: var(--red); }
.health-disabled strong { color: var(--slate); }

.capital-panel {
  display: grid;
  gap: 14px;
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.capital-row span { color: var(--muted); font-size: 12px; }
.capital-row strong { font-size: 13px; }
.bar { height: 6px; margin-top: 7px; overflow: hidden; border-radius: 999px; background: color-mix(in srgb, var(--muted) 17%, transparent); }
.bar span { display: block; width: 0; height: 100%; border-radius: inherit; background: var(--accent); transition: width .2s ease; }
.capital-row:last-child .bar span { background: var(--amber); }

.count-badge,
.item-badge {
  border-radius: 8px;
  background: color-mix(in srgb, var(--muted) 14%, transparent);
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}
.count-badge { padding: 5px 8px; }
.item-badge { padding: 4px 7px; white-space: nowrap; }
.item-badge[data-status="healthy"], .item-badge[data-status="complete"] { background: color-mix(in srgb, var(--green) 14%, transparent); color: var(--green); }
.item-badge[data-status="warning"], .item-badge[data-status="running"] { background: color-mix(in srgb, var(--amber) 14%, transparent); color: var(--amber); }
.item-badge[data-status="critical"], .item-badge[data-status="failed"] { background: color-mix(in srgb, var(--red) 14%, transparent); color: var(--red); }

.stack-list { display: grid; gap: 2px; }
.stack-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  padding: 12px 0;
  border-top: 1px solid var(--border);
}
.stack-item:first-child { border-top: 0; padding-top: 0; }
.stack-item:last-child { padding-bottom: 0; }
.stack-item strong { display: block; overflow: hidden; font-size: 14px; text-overflow: ellipsis; white-space: nowrap; }
.stack-item p { margin: 4px 0 0; color: var(--muted); font-size: 12px; line-height: 1.45; }

.empty-state {
  margin-top: 14px;
  padding: 24px 18px;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  color: var(--muted);
  text-align: center;
}
.empty-state strong { color: var(--text); }
.empty-state p { margin: 8px 0 16px; font-size: 13px; }
#retry-button { min-height: 44px; padding: 0 18px; border: 0; border-radius: 10px; background: var(--accent); color: var(--accent-text); cursor: pointer; font-weight: 700; }

footer { padding: 18px 2px 0; color: var(--muted); font-size: 11px; }

[hidden] { display: none !important; }

@media (max-width: 430px) {
  .app-shell { padding-inline: 12px; }
  .health-grid { grid-template-columns: repeat(2, 1fr); }
  .section { padding: 15px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}

/* Telegram safe-area variables complement the platform CSS insets. */
.app-shell { padding-top: calc(18px + max(var(--safe-top), var(--tg-content-safe-area-inset-top, 0px))); padding-bottom: calc(28px + max(var(--safe-bottom), var(--tg-content-safe-area-inset-bottom, 0px))); }
.top-subtitle { margin: 5px 0 0; color: var(--muted); font-size: 12px; }
.workspace-nav { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 5px; margin-top: 14px; }
.workspace-tab { min-width: 0; min-height: 42px; border: 1px solid var(--border); border-radius: 9px; background: var(--surface); color: var(--muted); font-size: 12px; cursor: pointer; }
.workspace-tab[aria-pressed="true"] { color: var(--accent-text); border-color: transparent; background: var(--accent); font-weight: 700; }
.workspace-tab:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.placeholder-copy { color: var(--muted); font-size: 14px; line-height: 1.55; }
.action-disabled { width: 100%; min-height: 46px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface-raised); color: var(--muted); opacity: .75; }
[hidden] { display: none !important; }
@media (max-width: 360px) { .workspace-tab { font-size: 11px; } .topbar { gap: 6px; } .connection-state { white-space: normal; } }

.telegram-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.telegram-actions button { min-height: 40px; padding: 0 12px; border: 1px solid var(--border); border-radius: 9px; background: var(--surface); color: var(--text); cursor: pointer; }
.telegram-actions button:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.journal-filters { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin-top: 18px; }
.journal-filters label { display: grid; gap: 6px; color: var(--muted); font-size: 12px; }
.journal-filters select { width: 100%; min-width: 0; min-height: 42px; border: 1px solid var(--border); border-radius: 9px; padding: 0 9px; color: var(--muted); background: var(--surface-raised); }
