/* GoTalk — bảng màu lấy cảm hứng từ hậu trường: thùng road case xanh than,
   giấy ghi chú, đèn cue vàng hổ phách và đèn "on air" đỏ. */
:root {
  --case: #162033;
  --panel: #1f2b42;
  --panel-2: #26344f;
  --line: #34435f;
  --text: #ede7dc;
  --dim: #97a3b9;
  --cue: #f2b705;
  --air: #e5484d;
  --ok: #6bd17a;
  --target: #f2b705;
  --radius-s: 8px;
  --font-body: "Barlow", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-label: "Barlow Condensed", "Arial Narrow", system-ui, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--case);
  color: var(--text);
  font: 16px/1.45 var(--font-body);
  -webkit-text-size-adjust: 100%;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--cue); outline-offset: 2px; }
a { color: var(--cue); }

.wordmark {
  font-family: var(--font-label);
  font-weight: 700;
  font-size: 2.6rem;
  line-height: 1;
  letter-spacing: 0.01em;
  margin: 0;
}
.wordmark.small { font-size: 1.35rem; }
.hint { color: var(--dim); font-size: 0.875rem; margin: 0.5rem 0 0; }

.flash { padding: 0.7rem 0.9rem; border-radius: var(--radius-s); margin: 0 0 1rem; border-left: 4px solid; background: var(--panel); }
.flash-ok { border-color: var(--ok); }
.flash-err { border-color: var(--air); }

.btn-primary {
  display: block;
  width: 100%;
  padding: 0.9rem 1rem;
  border: 0;
  border-radius: var(--radius-s);
  background: var(--cue);
  color: var(--case);
  font-family: var(--font-label);
  font-weight: 700;
  font-size: 1.3rem;
}
.btn-primary.big { font-size: 1.6rem; padding: 1.1rem; }

/* ---------- Trang vào bộ đàm ---------- */

body.join { display: flex; justify-content: center; padding: max(1.5rem, env(safe-area-inset-top)) 1.25rem 2rem; }
.join-card { width: 100%; max-width: 26rem; }
.join-mark {
  width: 3.2rem; height: 3.2rem; border-radius: 50%;
  background: var(--cue);
  box-shadow: 0 0 0 6px var(--case), 0 0 0 8px var(--line);
  margin-bottom: 1.25rem;
}
.join-lead { color: var(--dim); margin: 0.4rem 0 1.75rem; }
.join form > label { display: block; margin-bottom: 1.1rem; font-weight: 500; }
.join input[type=text], .join input[type=password] {
  display: block; width: 100%; margin-top: 0.35rem;
  padding: 0.8rem 0.9rem; font-size: 1.1rem;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius-s);
}
.dept-pick { border: 0; padding: 0; margin: 0 0 1.5rem; }
.dept-pick legend { font-weight: 500; margin-bottom: 0.5rem; padding: 0; }
.dept { display: block; margin-bottom: 0.45rem; }
.dept input { position: absolute; opacity: 0; }
.dept span {
  display: block; padding: 0.7rem 0.9rem 0.7rem 2.4rem; position: relative;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius-s);
}
.dept span::before {
  content: ""; position: absolute; left: 0.9rem; top: 50%; width: 0.8rem; height: 0.8rem; margin-top: -0.4rem;
  border-radius: 50%; background: var(--c);
}
.dept input:checked + span { border-color: var(--c); box-shadow: inset 0 0 0 1px var(--c); background: var(--panel-2); }
.dept input:focus-visible + span { outline: 3px solid var(--cue); outline-offset: 2px; }

/* ---------- Màn hình bộ đàm ---------- */

body.talk {
  display: flex; flex-direction: column;
  height: 100%; height: 100dvh; overflow: hidden;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) 0 env(safe-area-inset-left);
  -webkit-user-select: none; user-select: none;
}
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; padding: 0.7rem 1rem 0.5rem; }
.who { display: flex; align-items: baseline; gap: 0.7rem; min-width: 0; }
.me { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.me em { font-style: normal; color: var(--dim); font-weight: 400; margin-left: 0.4rem; }
.top-actions { display: flex; gap: 0.4rem; flex-shrink: 0; }
.pill {
  display: inline-flex; align-items: center; gap: 0.4rem;
  padding: 0.35rem 0.75rem; border-radius: 999px;
  background: var(--panel); border: 1px solid var(--line); font-size: 0.9rem;
}
.pill.ghost { background: none; color: var(--dim); }
.dot-live { width: 0.5rem; height: 0.5rem; border-radius: 50%; background: var(--ok); }

.online-panel { margin: 0 1rem 0.5rem; padding: 0.6rem 0.8rem; background: var(--panel); border-radius: var(--radius-s); font-size: 0.9rem; max-height: 35vh; overflow: auto; }
.online-group { display: flex; gap: 0.6rem; padding: 0.25rem 0; }
.online-group strong { flex: 0 0 7.5rem; font-weight: 600; }
.online-group span { color: var(--dim); }

.channel-strip { display: flex; gap: 0.4rem; padding: 0 1rem 0.5rem; overflow-x: auto; scrollbar-width: none; }
.channel-strip::-webkit-scrollbar { display: none; }
.chip {
  flex-shrink: 0; display: inline-flex; align-items: center; gap: 0.45rem;
  padding: 0.35rem 0.75rem; border-radius: 999px;
  background: var(--panel); border: 1px solid var(--line);
  font-family: var(--font-label); font-weight: 600; font-size: 1.05rem;
}
.chip-dot { width: 0.6rem; height: 0.6rem; border-radius: 50%; background: var(--c); }
.chip.is-muted { color: var(--dim); }
.chip.is-muted .chip-dot { background: none; box-shadow: inset 0 0 0 2px var(--dim); }
.chip-off { font-family: var(--font-body); font-weight: 400; font-size: 0.75rem; }

.status { margin: 0; padding: 0.45rem 1rem; font-size: 0.95rem; color: var(--dim); border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.status.live { color: var(--text); }
.status.warn { color: var(--cue); }
.status.air { color: #fff; background: var(--air); border-color: var(--air); }

.missed-bar { display: flex; align-items: center; gap: 0.5rem; padding: 0.5rem 1rem; background: var(--panel-2); font-size: 0.95rem; }
.missed-bar span { flex: 1; }
.missed-bar button { padding: 0.35rem 0.7rem; border-radius: var(--radius-s); border: 0; background: var(--cue); color: var(--case); font-weight: 600; }
.missed-bar button.ghost { background: none; color: var(--dim); }

.log { flex: 1; overflow-y: auto; padding: 0.5rem 1rem; -webkit-overflow-scrolling: touch; }
.msg {
  display: flex; align-items: center; gap: 0.75rem;
  padding: 0.55rem 0.6rem 0.55rem 0.8rem; margin-bottom: 0.4rem;
  border-left: 4px solid var(--c); border-radius: 0 var(--radius-s) var(--radius-s) 0;
  background: var(--panel);
}
.msg.is-old { opacity: 0.7; }
.msg.is-mine { background: none; box-shadow: inset 0 0 0 1px var(--line); }
.msg.is-urgent { background: rgba(229, 72, 77, 0.16); }
.msg.is-missed { box-shadow: inset 0 0 0 2px var(--cue); }
.msg.is-muted .msg-head strong::after { content: " (đã tắt tiếng)"; font-weight: 400; color: var(--dim); font-size: 0.85rem; }
.msg.is-playing { background: var(--panel-2); box-shadow: inset 0 0 0 2px var(--c); }
.play {
  flex-shrink: 0; width: 2.6rem; height: 2.6rem; border-radius: 50%;
  border: 0; background: var(--panel-2); display: grid; place-items: center;
}
.play-icon { width: 0; height: 0; border-style: solid; border-width: 0.45rem 0 0.45rem 0.75rem; border-color: transparent transparent transparent var(--text); margin-left: 0.2rem; }
.is-playing .play { background: var(--c); }
.is-playing .play-icon { border: 0; width: 0.75rem; height: 0.75rem; margin: 0; background: var(--case); }
.msg-body { min-width: 0; flex: 1; }
.msg-head { display: flex; align-items: center; gap: 0.5rem; }
.msg-head strong { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tag-urgent { background: var(--air); color: #fff; font-size: 0.75rem; font-weight: 600; padding: 0.05rem 0.4rem; border-radius: 4px; }
.msg-meta { display: flex; gap: 0.7rem; color: var(--dim); font-size: 0.85rem; }
.msg-ch { color: var(--c); }

/* Dock + nút giữ-để-nói */
.dock {
  padding: 0.6rem 1rem calc(0.9rem + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: var(--case);
  display: flex; flex-direction: column; align-items: center; gap: 0.7rem;
}
.dock-row { display: flex; gap: 0.5rem; width: 100%; align-items: center; }
.targets { flex: 1; display: flex; gap: 0.35rem; overflow-x: auto; scrollbar-width: none; }
.targets::-webkit-scrollbar { display: none; }
.target {
  flex-shrink: 0; padding: 0.4rem 0.75rem; border-radius: var(--radius-s);
  border: 1px solid var(--line); background: none; color: var(--dim);
  font-family: var(--font-label); font-weight: 600; font-size: 1rem;
}
.target.on { background: var(--c); border-color: var(--c); color: var(--case); }
.urgent-toggle {
  flex-shrink: 0; padding: 0.4rem 0.8rem; border-radius: var(--radius-s);
  border: 1px solid var(--air); background: none; color: var(--air);
  font-family: var(--font-label); font-weight: 700; font-size: 1rem;
}
.urgent-toggle[aria-pressed="true"] { background: var(--air); color: #fff; }

.ptt {
  position: relative;
  width: min(52vw, 13rem); aspect-ratio: 1;
  border-radius: 50%; border: 0;
  background: var(--target);
  color: var(--case);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  touch-action: none; -webkit-touch-callout: none; -webkit-tap-highlight-color: transparent;
  box-shadow: 0 0 0 8px var(--case), 0 0 0 10px var(--line);
  transition: transform 0.12s ease, background-color 0.15s ease;
}
.ptt-ring { position: absolute; inset: -10px; border-radius: 50%; pointer-events: none; }
.ptt-label { font-family: var(--font-label); font-weight: 700; font-size: 1.7rem; line-height: 1; }
.ptt-sub { font-size: 0.85rem; margin-top: 0.35rem; font-weight: 500; max-width: 80%; text-align: center; }

body.urgent-armed .ptt { box-shadow: 0 0 0 8px var(--case), 0 0 0 11px var(--air); }
body.arming .ptt { transform: scale(0.96); }
body.on-air .ptt { background: var(--air); color: #fff; transform: scale(0.96); }
body.on-air .ptt-ring { animation: onair 1.2s ease-out infinite; }
@keyframes onair {
  from { box-shadow: 0 0 0 0 rgba(229, 72, 77, 0.65); }
  to { box-shadow: 0 0 0 26px rgba(229, 72, 77, 0); }
}
@media (prefers-reduced-motion: reduce) {
  body.on-air .ptt-ring { animation: none; box-shadow: 0 0 0 6px var(--air); }
  .ptt { transition: none; }
}
@media (max-width: 420px) { .who .wordmark { display: none; } }
@media (max-height: 640px) { .ptt { width: min(40vw, 9.5rem); } .ptt-label { font-size: 1.35rem; } }

.start-overlay {
  position: fixed; inset: 0; z-index: 20;
  background: rgba(22, 32, 51, 0.97);
  display: flex; align-items: center; justify-content: center; padding: 1.5rem;
}
.start-box { max-width: 22rem; }
.start-box p { color: var(--dim); margin: 0.75rem 0 1.5rem; }
.start-box .hint { margin-top: 1.25rem; }

.toast {
  position: fixed; left: 1rem; right: 1rem; bottom: calc(15rem + env(safe-area-inset-bottom)); z-index: 30;
  max-width: 28rem; margin: 0 auto; padding: 0.7rem 0.9rem;
  background: var(--text); color: var(--case); border-radius: var(--radius-s); font-weight: 500;
}

/* ---------- Admin ---------- */

body.admin { min-height: 100%; }
.admin-bar {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.5rem 1.5rem;
  padding: 0.8rem 1.25rem; border-bottom: 1px solid var(--line);
}
.admin-bar .brand { font-family: var(--font-label); font-weight: 700; font-size: 1.5rem; color: var(--text); text-decoration: none; }
.admin-bar .brand span { color: var(--dim); font-weight: 600; font-size: 1.1rem; }
.admin-bar nav { display: flex; flex-wrap: wrap; gap: 0.25rem 1rem; }
.admin-bar nav a { color: var(--dim); text-decoration: none; padding: 0.2rem 0; border-bottom: 2px solid transparent; }
.admin-bar nav a.on { color: var(--text); border-color: var(--cue); }
.admin-main { max-width: 60rem; margin: 0 auto; padding: 1.25rem; }
.admin-main h1 { font-family: var(--font-label); font-weight: 700; font-size: 2rem; margin: 0 0 1rem; }
.admin-main h2 { font-family: var(--font-label); font-weight: 600; font-size: 1.4rem; margin: 2rem 0 0.6rem; }
.admin-main p { max-width: 42rem; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.95rem; }
th, td { text-align: left; padding: 0.55rem 0.6rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { color: var(--dim); font-weight: 500; }
.swatch { display: inline-block; width: 0.8rem; height: 0.8rem; border-radius: 50%; background: var(--c); margin-right: 0.45rem; vertical-align: -0.05rem; }
.badge { display: inline-block; font-size: 0.8rem; padding: 0.05rem 0.45rem; border-radius: 4px; background: var(--panel-2); color: var(--dim); }
.badge.on { background: rgba(107, 209, 122, 0.18); color: var(--ok); }

.form-grid { display: grid; gap: 0.9rem; max-width: 30rem; }
.form-grid label { display: grid; gap: 0.3rem; font-weight: 500; }
.admin input[type=text], .admin input[type=password], .admin input[type=number] {
  padding: 0.6rem 0.75rem; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius-s);
}
.admin input[type=color] { width: 3.5rem; height: 2.4rem; padding: 0.15rem; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius-s); }
.inline-form { display: inline; }
.btn {
  display: inline-block; padding: 0.5rem 0.9rem; border-radius: var(--radius-s);
  border: 1px solid var(--line); background: var(--panel); color: var(--text); text-decoration: none; font-size: 0.95rem;
}
.btn.primary { background: var(--cue); border-color: var(--cue); color: var(--case); font-weight: 600; }
.btn.danger { border-color: var(--air); color: var(--air); background: none; }
.btn.small { padding: 0.25rem 0.6rem; font-size: 0.875rem; }
.row-actions { display: flex; flex-wrap: wrap; gap: 0.35rem; }
.card-box { background: var(--panel); border-radius: var(--radius-s); padding: 1rem 1.1rem; margin-bottom: 1rem; }
.linkbox { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; }
.linkbox code { background: var(--case); padding: 0.4rem 0.6rem; border-radius: 6px; word-break: break-all; }
.admin-login { max-width: 22rem; margin: 12vh auto 0; padding: 0 1.25rem; }
.admin-login h1 { margin-bottom: 1.5rem; }
