:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --bg2: var(--tg-theme-secondary-bg-color, #f1f2f5);
  --text: var(--tg-theme-text-color, #16181d);
  --hint: var(--tg-theme-hint-color, #707884);
  --accent: var(--tg-theme-button-color, #2481cc);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --danger: var(--tg-theme-destructive-text-color, #d14343);
  --seat-stroke: rgba(0, 0, 0, .55);
  --mine: #1565ff;
  --safe-top: max(env(safe-area-inset-top, 0px), calc(var(--tg-safe-area-inset-top, 0px) + var(--tg-content-safe-area-inset-top, 0px)));
  --safe-bottom: max(env(safe-area-inset-bottom, 0px), calc(var(--tg-safe-area-inset-bottom, 0px) + var(--tg-content-safe-area-inset-bottom, 0px)));
  --safe-left: max(env(safe-area-inset-left, 0px), var(--tg-safe-area-inset-left, 0px));
  --safe-right: max(env(safe-area-inset-right, 0px), var(--tg-safe-area-inset-right, 0px));
}
@media (prefers-color-scheme: dark) {
  :root:not(.light) {
    --bg: var(--tg-theme-bg-color, #17191d);
    --bg2: var(--tg-theme-secondary-bg-color, #22252b);
    --text: var(--tg-theme-text-color, #eceef2);
    --hint: var(--tg-theme-hint-color, #9aa1ad);
  }
}
html.dark { --seat-stroke: rgba(0, 0, 0, .75); --mine: #5ea0ff; }

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font: 15px/1.35 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; }
body { overscroll-behavior: none; }
#app { display: flex; flex-direction: column; height: var(--tg-viewport-stable-height, 100vh); min-height: 100%;
  padding: var(--safe-top) var(--safe-right) 0 var(--safe-left); }
.hidden { display: none !important; }

.top { padding: 10px 14px 6px; flex: none; }
.title-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
h1 { font-size: 18px; margin: 0; }
.sub { color: var(--hint); font-size: 13px; }
.counter { background: var(--bg2); border-radius: 10px; padding: 6px 10px; font-size: 13px; text-align: right; white-space: nowrap; }
.counter b { font-size: 15px; }
.banner { margin-top: 8px; padding: 8px 10px; border-radius: 10px; background: var(--bg2); font-size: 14px; cursor: pointer; }
.banner.warn { background: color-mix(in srgb, #f5a623 22%, var(--bg2)); }
.banner.ok { background: color-mix(in srgb, #2fb36d 20%, var(--bg2)); }
.banner.closed { background: color-mix(in srgb, var(--danger) 18%, var(--bg2)); }

.map-wrap { position: relative; flex: 1 1 auto; min-height: 200px; overflow: hidden; background: var(--bg2);
  margin: 0 8px; border-radius: 14px; touch-action: none; }
#map { width: 100%; height: 100%; display: block; touch-action: none; user-select: none; -webkit-user-select: none; cursor: grab; }
#map.dragging { cursor: grabbing; }
.loading { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: var(--hint); }
.hint { position: absolute; left: 10px; right: 64px; bottom: 10px; font-size: 12px; color: var(--hint);
  background: color-mix(in srgb, var(--bg) 85%, transparent); padding: 6px 8px; border-radius: 8px; pointer-events: none; }
.zoom { position: absolute; right: 8px; bottom: 8px; display: flex; flex-direction: column; gap: 6px; }
.zoom button { width: 44px; height: 44px; border-radius: 12px; border: 0; font-size: 22px; line-height: 1;
  background: var(--bg); color: var(--text); box-shadow: 0 1px 4px rgba(0,0,0,.25); }
.zoom button:active { transform: scale(.95); }

/* --- схема --- */
.stage { fill: color-mix(in srgb, var(--text) 10%, var(--bg)); stroke: var(--text); stroke-width: 3; }
.stage-label { fill: var(--text); font-size: 26px; font-weight: 600; letter-spacing: 6px; text-anchor: middle; dominant-baseline: central; }
.axis { fill: var(--hint); font-size: 15px; text-anchor: middle; dominant-baseline: central; }
.seat { stroke: var(--seat-stroke); stroke-width: 1.3; }
.ov { fill: none; pointer-events: none; }
.ico { pointer-events: none; display: none; }
.st-admin .ov { fill: url(#hatch); }
.st-admin .ico-lock { display: inline; }
.st-taken .ov { fill: rgba(0, 0, 0, .52); }
.st-taken .ico-x { display: inline; }
.st-held .ov, .st-pending .ov { fill: rgba(255, 255, 255, .5); }
.st-held .seat { stroke-dasharray: 5 3; stroke-width: 1.8; }
.st-held .ico-clock { display: inline; }
.st-pending .seat { stroke-dasharray: 2 2.5; stroke-width: 2; }
.st-pending .ico-hourglass { display: inline; }
.mine .seat { stroke: var(--mine); stroke-width: 4.5; stroke-dasharray: none; }
.mine .ico { display: none; }
.mine .ico-check { display: inline; }
.sel .seat { stroke: var(--accent); stroke-width: 4; stroke-dasharray: none; }
.sel .sel-ring { display: inline; }
.sel-ring { display: none; fill: none; stroke: var(--accent); stroke-width: 2; pointer-events: none; }

/* --- легенда --- */
.legend { flex: none; margin: 6px 8px 0; background: var(--bg2); border-radius: 12px; padding: 0 10px; font-size: 13px; }
.legend summary { padding: 8px 0; cursor: pointer; color: var(--hint); }
.legend-body { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 6px 10px; padding-bottom: 10px; }
.lg { display: flex; align-items: center; gap: 6px; }
.lg svg { flex: none; }
.lg-note { grid-column: 1 / -1; color: var(--hint); }

/* --- карточка места --- */
.sheet { position: relative; flex: none; margin: 8px; padding: 12px 14px calc(12px + var(--safe-bottom));
  background: var(--bg); border-radius: 16px; box-shadow: 0 -2px 16px rgba(0,0,0,.18); }
.sheet-close { position: absolute; right: 8px; top: 8px; width: 36px; height: 36px; border: 0; border-radius: 10px;
  background: var(--bg2); color: var(--text); font-size: 16px; }
.sheet-head { display: flex; align-items: center; gap: 10px; padding-right: 40px; }
.chip { width: 22px; height: 22px; border-radius: 6px; border: 1px solid var(--seat-stroke); flex: none; }
.sheet-title { font-weight: 600; font-size: 16px; }
.sheet-status { margin-top: 6px; font-weight: 600; }
.sheet-text { margin-top: 4px; color: var(--hint); font-size: 14px; }
.sheet-actions { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }
.btn { appearance: none; border: 0; border-radius: 12px; padding: 13px 14px; font-size: 16px; font-weight: 600;
  background: var(--accent); color: var(--accent-text); width: 100%; }
.btn.secondary { background: var(--bg2); color: var(--text); }
.btn.danger { background: var(--bg2); color: var(--danger); }
.btn:disabled { opacity: .55; }

.toast { position: fixed; left: 12px; right: 12px; bottom: calc(16px + var(--safe-bottom)); z-index: 10;
  background: #2b2f36; color: #fff; padding: 12px 14px; border-radius: 12px; box-shadow: 0 4px 18px rgba(0,0,0,.3); font-size: 14px; }
