:root {
  color-scheme: dark;
  --bg: #0b1118;
  --panel: #121c26;
  --panel-2: #172532;
  --line: #294154;
  --text: #edf4f7;
  --muted: #a9bac4;
  --ok: #43c97f;
  --warn: #e7b94a;
  --bad: #ef6461;
  --accent: #2f9ad0;
  --touch: 56px;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--text); font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
body { padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); -webkit-user-select: none; user-select: none; }
input, select, button, textarea { font: inherit; font-size: 16px; }
button { min-height: 40px; border: 1px solid var(--line); border-radius: 6px; background: #1b2b3a; color: var(--text); padding: 0 14px; cursor: pointer; }
button.primary, .ptt { background: var(--accent); border-color: #62c2ee; color: #061018; font-weight: 800; }
button:disabled { opacity: .55; cursor: not-allowed; }
label { display: grid; gap: 6px; color: var(--muted); }
input, select, textarea { min-height: 40px; border-radius: 6px; border: 1px solid var(--line); background: #0e1720; color: var(--text); padding: 8px; }
input[type="range"] { padding: 0; }
meter { width: 100%; height: 14px; }
.hidden { display: none !important; }

.login-view { min-height: 100dvh; display: grid; place-items: center; padding: 24px; }
.login-panel { width: min(420px, 100%); display: grid; gap: 16px; padding: 24px; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; }
.login-panel h1 { margin: 0 0 8px; }
.message { min-height: 24px; color: var(--bad); margin: 0; }

.main-view { min-height: 100dvh; }
.topbar { position: sticky; top: 0; z-index: 10; display: grid; grid-template-columns: 1fr auto auto; gap: 12px; align-items: center; padding: 12px 16px; background: rgba(11, 17, 24, .96); border-bottom: 1px solid var(--line); backdrop-filter: blur(10px); }
.identity { display: grid; gap: 2px; }
.identity span, .global-panel span { color: var(--muted); }
.status-row, .top-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.pill, .state-pill { display: inline-flex; align-items: center; min-height: 30px; border-radius: 999px; padding: 4px 10px; border: 1px solid var(--line); font-size: 13px; color: var(--muted); }
.pill.on, .state-pill.on { color: #072010; background: var(--ok); border-color: var(--ok); }
.pill.off, .state-pill.off { color: #230b0b; background: var(--bad); border-color: var(--bad); }
.pill.warn { color: #1f1700; background: var(--warn); border-color: var(--warn); }

.notice-area { display: grid; gap: 8px; padding: 12px 16px 0; }
.notice { padding: 10px 12px; border: 1px solid var(--line); border-left: 5px solid var(--warn); background: var(--panel); border-radius: 6px; }
.notice.error { border-left-color: var(--bad); }
.notice.ok { border-left-color: var(--ok); }

.global-panel { margin: 16px; padding: 12px; display: grid; grid-template-columns: 1fr minmax(140px, 260px); gap: 16px; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; align-items: center; }
.group-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(310px, 1fr)); gap: 16px; padding: 0 16px 24px; }
.group-card { display: grid; gap: 12px; background: var(--panel); border: 1px solid var(--line); border-top: 4px solid var(--accent); border-radius: 8px; padding: 14px; touch-action: manipulation; }
.group-card header { display: flex; justify-content: space-between; gap: 12px; align-items: start; }
.group-card h2 { margin: 0; font-size: 20px; line-height: 1.2; }
.group-card p { margin: 4px 0 0; color: var(--muted); }
.speaker-line, .timer-line, .card-status { color: var(--muted); }
.inline { display: inline-flex; grid-auto-flow: column; align-items: center; justify-content: start; gap: 8px; }
.vox-row { display: grid; grid-template-columns: auto 1fr; gap: 10px; align-items: center; }
.vox-row meter { grid-column: 1 / -1; }
.ptt { width: 100%; min-height: 92px; font-size: clamp(28px, 8vw, 48px); letter-spacing: 0; border-radius: 8px; -webkit-touch-callout: none; }
.ptt.active { background: var(--bad); border-color: #ffaaa7; color: #fff; }
.ptt.pending { background: var(--warn); color: #201600; }

.modal { width: min(760px, calc(100vw - 24px)); max-height: calc(100dvh - 24px); border: 1px solid var(--line); border-radius: 8px; padding: 0; background: var(--panel); color: var(--text); }
.modal.wide { width: min(1120px, calc(100vw - 24px)); }
.modal::backdrop { background: rgba(0,0,0,.65); }
.modal form > header { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px; border-bottom: 1px solid var(--line); }
.modal h2 { margin: 0; font-size: 20px; }
.modal-body { padding: 12px; max-height: calc(100dvh - 112px); overflow: auto; }
.list-body { display: grid; gap: 10px; }
.list-item { display: grid; gap: 8px; padding: 10px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 10px; }
.admin-table { width: 100%; border-collapse: collapse; margin-top: 14px; }
.admin-table th, .admin-table td { border-bottom: 1px solid var(--line); text-align: left; padding: 8px; vertical-align: top; }
.tabs { display: flex; gap: 8px; }
.tabs .active { background: var(--accent); color: #061018; border-color: #62c2ee; }

@media (max-width: 820px) {
  .topbar { grid-template-columns: 1fr; align-items: stretch; }
  .status-row, .top-actions { justify-content: stretch; }
  .top-actions button { flex: 1 1 132px; min-height: var(--touch); }
  .global-panel { grid-template-columns: 1fr; }
  .group-grid { grid-template-columns: 1fr; }
}
