:root {
  --bg: #0f1115;
  --surface: #171a21;
  --surface-2: #1f232c;
  --border: #2a2f3a;
  --text: #e7eaf0;
  --muted: #8b93a3;
  --accent: #4f9dff;
  --green: #34c759;
  --green-dim: #1e3a2a;
  --red: #ff5c5c;
  --amber: #ffb020;
  --radius: 14px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text); }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 15px; line-height: 1.4;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
button { font-family: inherit; }

/* ===== Layout ===== */
.app { max-width: 900px; margin: 0 auto; padding-bottom: calc(72px + var(--safe-bottom)); }

.topbar {
  position: sticky; top: 0; z-index: 20;
  background: rgba(15,17,21,.92); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  padding: calc(10px + var(--safe-top)) 14px 10px;
}
.topbar-row { display: flex; align-items: center; gap: 10px; }
.topbar h1 { font-size: 16px; margin: 0; font-weight: 650; flex: 1; }
.clock { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 13px; }

.status-dots { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 8px; }
.pill {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 999px; padding: 4px 10px; font-size: 12px; color: var(--muted);
}
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.dot.on { background: var(--green); box-shadow: 0 0 8px var(--green); }
.dot.off { background: var(--red); }
.dot.warn { background: var(--amber); }

.summary { display: flex; gap: 8px; margin-top: 10px; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.summary .kpi {
  flex: 1 0 auto; min-width: 92px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 8px 10px;
}
.kpi .k-label { font-size: 11px; color: var(--muted); }
.kpi .k-value { font-size: 17px; font-weight: 700; font-variant-numeric: tabular-nums; }

/* ===== Content ===== */
.content { padding: 14px; }
.section-title { font-size: 13px; color: var(--muted); margin: 18px 2px 8px; text-transform: uppercase; letter-spacing: .04em; }

/* ===== Таблица статистики по столам ===== */
.stat-tbl-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.stat-tbl { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; font-size: 13px; }
.stat-tbl th, .stat-tbl td { padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
.stat-tbl th { color: var(--muted); font-weight: 600; font-size: 12px; }
.stat-tbl td.num, .stat-tbl th.num { text-align: right; font-variant-numeric: tabular-nums; }
.stat-tbl tbody tr:last-child td, .stat-tbl tr:last-child td { border-bottom: none; }

/* ===== Table cards ===== */
.tables-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 10px; }
.tcard {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 12px; position: relative; overflow: hidden;
}
.tcard.playing { border-color: rgba(52,199,89,.5); background: linear-gradient(180deg, var(--green-dim), var(--surface) 60%); }
.tcard.idle { opacity: .92; }
.tcard-head { display: flex; align-items: center; gap: 8px; }
.tcard-name { font-weight: 700; font-size: 15px; flex: 1; }
.badge { font-size: 11px; padding: 2px 8px; border-radius: 999px; border: 1px solid var(--border); color: var(--muted); }
.badge.play { background: var(--green); color: #04210f; border-color: transparent; font-weight: 700; }
.tcard .big-sum { font-size: 26px; font-weight: 800; margin: 8px 0 2px; font-variant-numeric: tabular-nums; }
.tcard .rowline { display: flex; justify-content: space-between; font-size: 13px; margin-top: 4px; }
.tcard .rowline .lbl { color: var(--muted); }
.tcard .timer { font-variant-numeric: tabular-nums; }
.tcard .relay-err { color: var(--red); font-size: 12px; margin-top: 6px; }
.tcard.idle .big-sum { color: var(--muted); font-size: 18px; }
.cue-list { margin-top: 8px; border-top: 1px solid var(--border); padding-top: 6px; display: flex; flex-direction: column; gap: 3px; }
.cue-item { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); }
.cue-item .timer, .cue-item span:last-child { font-variant-numeric: tabular-nums; }

/* ===== Lists ===== */
.list { display: flex; flex-direction: column; gap: 8px; }
.row {
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  padding: 10px 12px; display: flex; align-items: center; gap: 10px;
}
.row .grow { flex: 1; min-width: 0; }
.row .title { font-weight: 600; }
.row .sub { font-size: 12px; color: var(--muted); }
.row .amt { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tag { font-size: 11px; color: var(--muted); border: 1px solid var(--border); border-radius: 6px; padding: 1px 6px; }

/* ===== Controls ===== */
.controls { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 8px; }
input[type=date], select, input[type=text], input[type=password] {
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text);
  border-radius: 10px; padding: 9px 11px; font-size: 15px;
}
.btn {
  background: var(--accent); color: #04213f; border: none; border-radius: 10px;
  padding: 10px 14px; font-weight: 700; font-size: 15px; cursor: pointer;
}
.btn.ghost { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); }
.btn.sm { padding: 6px 10px; font-size: 13px; }

/* ===== Charts ===== */
.chart { display: flex; align-items: flex-end; gap: 4px; height: 140px; padding: 8px 0; overflow-x: auto; }
.bar-wrap { display: flex; flex-direction: column; align-items: center; gap: 4px; min-width: 26px; flex: 1 0 auto; }
.bar { width: 100%; max-width: 34px; background: linear-gradient(180deg, var(--accent), #2a6fd6); border-radius: 6px 6px 0 0; min-height: 2px; }
.bar-label { font-size: 10px; color: var(--muted); white-space: nowrap; }
.bar-val { font-size: 10px; color: var(--text); font-variant-numeric: tabular-nums; }
.bar-wrap { cursor: pointer; }
.bar-wrap .bar { transition: filter .1s; }
.bar-wrap.sel .bar { filter: brightness(1.35); box-shadow: 0 0 0 2px var(--accent); }
.bar-wrap.sel .bar-label { color: var(--accent); }
.chart-info { font-size: 13px; color: var(--text); margin-bottom: 4px; min-height: 18px; font-variant-numeric: tabular-nums; }

.split { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
.split .cell { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 10px; text-align: center; }
.split .cell .c-lbl { font-size: 11px; color: var(--muted); }
.split .cell .c-val { font-size: 18px; font-weight: 700; }

/* ===== Bottom nav ===== */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: flex; background: rgba(23,26,33,.96); backdrop-filter: blur(10px);
  border-top: 1px solid var(--border); padding-bottom: var(--safe-bottom);
}
.tabbar button {
  flex: 1; background: none; border: none; color: var(--muted);
  padding: 10px 4px; font-size: 11px; display: flex; flex-direction: column; align-items: center; gap: 3px; cursor: pointer;
}
.tabbar button.active { color: var(--accent); }
.tabbar .ico { font-size: 20px; line-height: 1; }

/* ===== Login ===== */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.login-card { background: var(--surface); border: 1px solid var(--border); border-radius: 18px; padding: 26px; width: 100%; max-width: 360px; }
.login-card h2 { margin: 0 0 4px; }
.login-card p { color: var(--muted); margin: 0 0 18px; font-size: 13px; }
.login-card .field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.login-card label { font-size: 12px; color: var(--muted); }
.login-card input { width: 100%; }
.login-card .btn { width: 100%; margin-top: 6px; }
.err { color: var(--red); font-size: 13px; margin-top: 10px; min-height: 16px; }

.muted { color: var(--muted); }
.empty { color: var(--muted); text-align: center; padding: 30px 10px; }
.center { text-align: center; }
.spinner { text-align: center; color: var(--muted); padding: 40px; }
