/* Хром интерфейса следует теме Telegram (--tg-theme-*), сами комнаты — своя тёплая палитра. */
:root {
  --bg: var(--tg-theme-bg-color, #f4f1ea);
  --surface: var(--tg-theme-secondary-bg-color, #ffffff);
  --text: var(--tg-theme-text-color, #1d1d24);
  --muted: var(--tg-theme-hint-color, #7a7884);
  --accent: var(--tg-theme-button-color, #2f6fde);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --line: color-mix(in srgb, var(--text) 12%, transparent);
  --ok: #2f9e55;
  --warn: #d49b0b;
  --bad: #d63b3b;
  --off: #8b8f9c;
  --wall: #e8dcc4;
  --wall-dark: #d6c6a6;
  --floor-a: #c8955a;
  --floor-b: #b98549;
  --plate: #2a2730;
  --plate-text: #f6f2e8;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: var(--tg-theme-bg-color, #17171d);
    --surface: var(--tg-theme-secondary-bg-color, #22222b);
    --text: var(--tg-theme-text-color, #ecebf2);
    --muted: var(--tg-theme-hint-color, #9a98a6);
    --wall: #3a3446;
    --wall-dark: #2e2939;
    --floor-a: #6b4a2c;
    --floor-b: #5e4026;
  }
}

:root[data-theme="dark"] {
  --wall: #3a3446;
  --wall-dark: #2e2939;
  --floor-a: #6b4a2c;
  --floor-b: #5e4026;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

body {
  padding: 12px 16px calc(16px + env(safe-area-inset-bottom));
  max-width: 720px;
  margin: 0 auto;
}

h1,
h2 {
  margin: 0;
  font-size: 18px;
  letter-spacing: 0.01em;
}

.top {
  display: grid;
  gap: 10px;
  margin-bottom: 14px;
}

.brand {
  display: flex;
  gap: 10px;
  align-items: center;
}

.reason {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.lamp {
  width: 14px;
  height: 14px;
  flex: none;
  background: var(--off);
  box-shadow: 0 0 0 2px var(--plate);
  image-rendering: pixelated;
}

.lamp[data-status="ok"] {
  background: var(--ok);
}
.lamp[data-status="degraded"] {
  background: var(--warn);
  animation: pulse 1.2s steps(2) infinite;
}
.lamp[data-status="down"] {
  background: var(--bad);
  animation: pulse 0.6s steps(2) infinite;
}

@keyframes pulse {
  50% {
    opacity: 0.35;
  }
}

.kpis {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
  margin: 0;
}

.kpis div {
  background: var(--surface);
  border: 2px solid var(--line);
  padding: 6px 8px;
}

.kpis dt {
  font-size: 11px;
  color: var(--muted);
}

.kpis dd {
  margin: 0;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  font-size: 17px;
}











.sprite {
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.sprite.big {
  width: 80px;
  height: 80px;
  flex: none;
  background: var(--wall);
  border: 3px solid var(--plate);
}




.foot {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 14px;
  color: var(--muted);
  font-size: 12px;
}

button {
  font: inherit;
  cursor: pointer;
}

.link {
  border: 0;
  background: none;
  color: var(--accent);
  padding: 4px 0;
}

.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(10, 10, 15, 0.45);
}

.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  max-height: 86vh;
  overflow: auto;
  max-width: 720px;
  margin: 0 auto;
  padding: 8px 16px calc(16px + env(safe-area-inset-bottom));
  background: var(--surface);
  border-top: 3px solid var(--plate);
  animation: rise 0.18s steps(4);
}

@keyframes rise {
  from {
    transform: translateY(40px);
    opacity: 0;
  }
}

.sheet-grip {
  width: 40px;
  height: 4px;
  margin: 0 auto 10px;
  background: var(--line);
}

.sheet-head {
  display: flex;
  gap: 12px;
  align-items: center;
}

.role {
  margin: 2px 0 6px;
  color: var(--muted);
  font-size: 13px;
}

.badge {
  display: inline-block;
  padding: 1px 8px;
  font-size: 12px;
  font-weight: 700;
  color: #fff;
  background: var(--off);
}

.badge[data-activity="working"],
.badge[data-activity="idle"] {
  background: var(--ok);
}
.badge[data-activity="confused"] {
  background: var(--warn);
}
.badge[data-activity="alarm"] {
  background: var(--bad);
}

.speech {
  position: relative;
  margin: 14px 0 12px;
  padding: 10px 12px;
  border: 3px solid var(--plate);
  background: var(--bg);
  font-weight: 500;
}

.speech::before {
  content: "";
  position: absolute;
  top: -11px;
  left: 28px;
  border: 8px solid transparent;
  border-bottom-color: var(--plate);
  border-top: 0;
}

.facts {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 6px 12px;
  margin: 0 0 12px;
  font-size: 14px;
}

.facts dt {
  color: var(--muted);
}

.facts dd {
  margin: 0;
  text-align: right;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

.facts dd[data-tone="ok"] {
  color: var(--ok);
}
.facts dd[data-tone="warn"] {
  color: var(--warn);
}
.facts dd[data-tone="bad"] {
  color: var(--bad);
}

.error-box {
  margin: 0 0 12px;
  padding: 10px 12px;
  border-left: 4px solid var(--bad);
  background: color-mix(in srgb, var(--bad) 8%, var(--surface));
  font-size: 13px;
  overflow-wrap: anywhere;
}

.error-box b {
  display: block;
  margin-bottom: 4px;
}

.error-box code {
  font: 12px/1.4 ui-monospace, Consolas, monospace;
}

.actions {
  display: grid;
  gap: 8px;
}

.actions button {
  padding: 11px 14px;
  border: 2px solid var(--line);
  background: var(--bg);
  color: var(--text);
  font-weight: 600;
}

.actions .primary {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--accent-text);
}


@media (prefers-reduced-motion: reduce) {
  .lamp,
  .sheet {
    animation: none !important;
  }
}

.floor {
  position: relative;
  border: 3px solid var(--plate);
  box-shadow: 4px 4px 0 var(--plate);
  background: var(--plate);
  overflow: hidden;
}

.world {
  display: block;
  width: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  cursor: pointer;
  touch-action: manipulation;
}

.labels,
.bubbles {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.room-label {
  position: absolute;
  left: 6px;
  padding: 0 5px;
  font-size: 10px;
  line-height: 14px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--plate-text);
  background: rgba(20, 18, 26, 0.7);
}

.bubble {
  position: absolute;
  left: 0;
  top: 0;
  max-width: 150px;
  padding: 3px 6px;
  font-size: 11px;
  line-height: 1.25;
  font-weight: 600;
  color: #1d1d24;
  background: #fffdf4;
  border: 2px solid #1b1b24;
  overflow-wrap: anywhere;
}

.bubble::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -6px;
  border: 4px solid transparent;
  border-top-color: #1b1b24;
  border-bottom: 0;
  transform: translateX(-50%);
}

.status-line {
  margin: 0;
  padding: 8px;
  color: var(--plate-text);
  font-size: 13px;
}

.status-line:empty {
  display: none;
}

.feed-box {
  margin-top: 14px;
}

.feed-box h2 {
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 6px;
}

.feed,
.sheet-feed {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 4px;
}

.sheet-feed {
  margin: 0 0 12px;
}

.feed-item,
.sheet-feed li {
  display: grid;
  grid-template-columns: auto auto 1fr;
  gap: 8px;
  align-items: baseline;
  padding: 6px 8px;
  background: var(--surface);
  border-left: 3px solid var(--line);
  font-size: 13px;
}

.sheet-feed li {
  display: block;
  background: var(--bg);
}

.feed-item.past {
  opacity: 0.7;
}

.feed-item[data-type="workflow_error"] {
  border-left-color: var(--bad);
}

.feed-item[data-type="bet_settled"],
.feed-item[data-type="prediction_ready"] {
  border-left-color: var(--ok);
}

.feed-item[data-type="agent_visit"] {
  border-left-color: var(--accent);
}

.feed time,
.sheet-feed time {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  font-size: 12px;
}

.feed .who {
  white-space: nowrap;
}

.feed-empty {
  padding: 10px;
  color: var(--muted);
  font-size: 13px;
}
