/* Telegram supplies --tg-theme-* from the user's own theme; the fallbacks
   are its default light and dark palettes, for a plain browser. */
:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --sec: var(--tg-theme-secondary-bg-color, #f1f1f4);
  --section: var(--tg-theme-section-bg-color, var(--bg));
  --text: var(--tg-theme-text-color, #000000);
  --hint: var(--tg-theme-hint-color, #6d6d72);
  --accent: var(--tg-theme-button-color, #1f74bd);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --link: var(--tg-theme-link-color, #1f74bd);
  --line: var(--tg-theme-section-separator-color, rgba(128, 128, 140, 0.22));
  --danger: var(--tg-theme-destructive-text-color, #c62828);
  --ok: #2e7d32;
  --ok-tint: rgba(46, 125, 50, 0.12);
  --warn: #b45309;
  --warn-tint: rgba(180, 83, 9, 0.13);
  --manual: rgba(128, 150, 175, 0.75);
  --radius: 14px;
  --safe-bottom: max(env(safe-area-inset-bottom, 0px), var(--tg-safe-area-inset-bottom, 0px));
}
@media (prefers-color-scheme: dark) {
  :root:not(.tg) {
    --bg: #17212b; --sec: #0e1621; --text: #f5f5f5; --hint: #93a3b3;
    --accent: #3a6fa8; --link: #6ab2f2; --line: #22303d; --danger: #ef6b6b;
  }
}
:root.dark { --ok: #6cc070; --ok-tint: rgba(108, 192, 112, 0.16); --warn: #f0a050; --warn-tint: rgba(240, 160, 80, 0.16); }
@media (prefers-color-scheme: dark) {
  :root:not(.tg) { --ok: #6cc070; --ok-tint: rgba(108, 192, 112, 0.16); --warn: #f0a050; --warn-tint: rgba(240, 160, 80, 0.16); }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--sec);
  color: var(--text);
  font: 15px/1.35 -apple-system, "SF Pro Text", Roboto, "Segoe UI", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
button { font: inherit; color: inherit; }
button:focus-visible, input:focus-visible { outline: 2px solid var(--link); outline-offset: 2px; }

#app {
  display: flex; flex-direction: column;
  height: var(--tg-viewport-stable-height, 100dvh);
  max-width: 640px; margin: 0 auto;
}

.top {
  flex-shrink: 0; display: flex; align-items: center; gap: 12px;
  padding: 12px 16px; background: var(--bg); border-bottom: 1px solid var(--line);
}
.logo {
  width: 36px; height: 36px; border-radius: 50%; background: var(--accent); color: var(--accent-text);
  display: flex; align-items: center; justify-content: center; font-weight: 700;
}
.top-text { flex: 1; min-width: 0; }
.top-title { font-weight: 600; font-size: 17px; }
.top-sub { font-size: 13px; color: var(--hint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pill {
  display: flex; align-items: center; gap: 6px; padding: 5px 10px; border-radius: 14px;
  font-size: 13px; font-weight: 600; background: var(--sec); color: var(--hint); white-space: nowrap;
}
.pill .dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.pill.ok { background: var(--ok-tint); color: var(--ok); }
.pill.warn { background: var(--warn-tint); color: var(--warn); }
.pill.bad { background: rgba(198, 40, 40, 0.12); color: var(--danger); }

.view {
  flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: 12px 12px 20px; display: flex; flex-direction: column; gap: 12px; outline: none;
}
.view::-webkit-scrollbar { display: none; }

.tabs {
  flex-shrink: 0; display: flex; background: var(--bg); border-top: 1px solid var(--line);
  padding: 4px 4px calc(6px + var(--safe-bottom));
}
.tabs button {
  flex: 1; min-width: 0; height: 54px; border: 0; background: transparent; color: var(--hint);
  font-size: 11px; font-weight: 500; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
}
.tabs button[aria-selected="true"] { color: var(--link); }
.tabs svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* building blocks */
.card { background: var(--section); border-radius: var(--radius); padding: 14px 16px; display: flex; flex-direction: column; gap: 10px; }
.card.flush { padding: 0; gap: 0; overflow: hidden; }
.label { font-size: 13px; color: var(--hint); text-transform: uppercase; letter-spacing: 0.04em; padding: 4px 4px 0; }
.note { font-size: 12px; color: var(--hint); padding: 0 4px; }
.hint { color: var(--hint); }
.row { display: flex; justify-content: space-between; gap: 12px; font-size: 14px; }
.row > :last-child { text-align: right; }
.list-item { display: flex; align-items: center; gap: 12px; padding: 11px 16px; border-bottom: 1px solid var(--line); font-size: 14px; }
.list-item:last-child { border-bottom: 0; }
.big { font-size: 20px; font-weight: 700; }
.num { font-variant-numeric: tabular-nums; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.tile { background: var(--sec); border-radius: 10px; padding: 10px 12px; min-width: 0; }
.card .tile { background: var(--sec); }
.grid2 > .card { padding: 12px 14px; gap: 2px; }
.tile-k, .stat-k { font-size: 12px; color: var(--hint); }
.tile-v { font-size: 17px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat-v { font-size: 26px; font-weight: 700; line-height: 1.15; }
.stat-s { font-size: 13px; color: var(--hint); }
.ok-text { color: var(--ok); }
.warn-text { color: var(--warn); }
.bad-text { color: var(--danger); }

.state { display: flex; align-items: center; gap: 12px; }
.state-icon { width: 44px; height: 44px; border-radius: 50%; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.state-icon svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }

.btn {
  height: 46px; border: 0; border-radius: 10px; padding: 0 16px; cursor: pointer;
  background: var(--accent); color: var(--accent-text); font-weight: 600; font-size: 16px;
}
.btn.soft { background: var(--sec); color: var(--warn); }
.btn.small { height: 40px; font-size: 15px; }
.btn:disabled { opacity: 0.5; cursor: default; }
.link-btn { border: 0; background: transparent; color: var(--danger); font-size: 14px; height: 40px; padding: 0 10px; cursor: pointer; }

.slots { display: flex; gap: 3px; height: 10px; }
.slots span { flex: 1; border-radius: 3px; background: var(--sec); }
.slots .bot { background: var(--accent); }
.slots .manual { background: var(--manual); }
.legend { display: flex; flex-wrap: wrap; gap: 14px; font-size: 13px; color: var(--hint); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }

.bar { height: 6px; border-radius: 3px; background: var(--sec); overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--accent); border-radius: 3px; }
.bar.warn > span { background: var(--warn); }

.badge { padding: 3px 8px; border-radius: 10px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.badge.ok { background: var(--ok-tint); color: var(--ok); }
.badge.warn { background: var(--warn-tint); color: var(--warn); }
.badge.bad { background: rgba(198, 40, 40, 0.12); color: var(--danger); }
.badge.info { background: var(--sec); color: var(--hint); }

.event { display: flex; gap: 12px; padding: 11px 16px; border-bottom: 1px solid var(--line); align-items: flex-start; font-size: 14px; }
.event:last-child { border-bottom: 0; }
.event time { width: 42px; flex-shrink: 0; color: var(--hint); }
.event .dot { width: 8px; height: 8px; border-radius: 50%; margin-top: 6px; flex-shrink: 0; background: var(--hint); }
.event .dot.ok { background: var(--ok); } .event .dot.warn { background: var(--warn); } .event .dot.info { background: var(--accent); }
.event span:last-child { min-width: 0; overflow-wrap: anywhere; }

.seg { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 4px; padding: 3px; border-radius: 10px; background: var(--line); }
.seg button { height: 34px; border: 0; border-radius: 8px; background: transparent; font-size: 14px; font-weight: 600; cursor: pointer; }
.seg button[aria-selected="true"] { background: var(--bg); box-shadow: 0 1px 2px rgba(0, 0, 0, 0.12); }

.chart { display: flex; align-items: flex-end; gap: 4px; height: 128px; }
.chart > div { flex: 1; min-width: 0; height: 100%; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: 4px; }
.chart b { font-size: 11px; font-weight: 400; color: var(--hint); }
.chart i { display: block; width: 100%; max-width: 28px; border-radius: 4px 4px 0 0; background: var(--accent); min-height: 2px; }
.chart-x { display: flex; gap: 4px; }
.chart-x span { flex: 1; min-width: 0; text-align: center; font-size: 11px; color: var(--hint); overflow: hidden; }

/* settings */
.field { display: flex; align-items: center; gap: 12px; padding: 0 16px; min-height: 50px; border-bottom: 1px solid var(--line); }
.field:last-child { border-bottom: 0; }
.field-k { flex: 1; min-width: 0; }
.field-k small { display: block; font-size: 12px; color: var(--hint); }
.field input {
  font: inherit; color: var(--text); background: transparent; border: 0; outline: 0;
  text-align: right; width: 120px; min-width: 0; padding: 12px 0;
}
.field input[type="time"] { width: 116px; }
.field input.bad { color: var(--danger); }
.stepper { display: flex; align-items: center; gap: 4px; }
.stepper button { width: 40px; height: 40px; border: 0; border-radius: 8px; background: var(--sec); font-size: 20px; cursor: pointer; }
.stepper output { min-width: 44px; text-align: center; font-weight: 600; font-variant-numeric: tabular-nums; }
.switch { width: 51px; height: 31px; border: 0; border-radius: 16px; padding: 2px; cursor: pointer; background: var(--line); display: flex; flex-shrink: 0; }
.switch[aria-checked="true"] { background: var(--ok); justify-content: flex-end; }
.switch span { width: 27px; height: 27px; border-radius: 50%; background: #ffffff; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25); }
.disclose { width: 100%; display: flex; align-items: center; gap: 12px; padding: 0 16px; height: 50px; border: 0; background: transparent; text-align: left; cursor: pointer; }
.disclose span:first-child { flex: 1; }
.savebar { position: sticky; bottom: 0; padding-top: 4px; }
.savebar .btn { width: 100%; height: 48px; }

/* users */
.invite { display: flex; gap: 8px; }
.invite label { flex: 1; display: flex; align-items: center; gap: 4px; padding: 0 12px; height: 44px; border-radius: 10px; background: var(--sec); min-width: 0; }
.invite input { flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; font: inherit; color: var(--text); }
.avatar { width: 36px; height: 36px; border-radius: 50%; background: var(--sec); color: var(--hint); display: flex; align-items: center; justify-content: center; font-weight: 600; flex-shrink: 0; }
.avatar.admin { background: var(--accent); color: var(--accent-text); }
.who { flex: 1; min-width: 0; }
.who div:first-child { font-weight: 500; overflow: hidden; text-overflow: ellipsis; }
.who div:last-child { font-size: 13px; color: var(--hint); }

.empty { padding: 14px 16px; font-size: 14px; color: var(--hint); }
.gate { margin: auto; text-align: center; padding: 32px 24px; display: flex; flex-direction: column; gap: 8px; }
.gate h1 { font-size: 20px; margin: 0; }
.skeleton { height: 120px; border-radius: var(--radius); background: var(--section); opacity: 0.6; }
