:root {
  --bg: #0f1115;
  --bg-2: #161922;
  --bg-3: #1e2230;
  --border: #2a2f3e;
  --text: #e6e8ef;
  --muted: #8b93a7;
  --accent: #ff8c3a;
  --accent-2: #ffb36b;
  --green: #3ad671;
  --red: #e8556a;
  --blue: #4c7dff;
  --yellow: #ffcc4a;
  --safe-top: env(safe-area-inset-top, 0);
  --safe-bot: env(safe-area-inset-bottom, 0);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 16px; overflow: hidden; -webkit-user-select: none; user-select: none;
  touch-action: manipulation;
}
input, button { font: inherit; color: inherit; }
.m-screen { height: 100vh; height: 100dvh; width: 100vw; display: flex; flex-direction: column; }
.m-hidden { display: none !important; }
.m-muted { color: var(--muted); }
.m-error { color: var(--red); min-height: 1.2em; margin: 10px 0 0; }
.m-sep { margin: 0 6px; color: var(--muted); }

button {
  cursor: pointer; border: 1px solid var(--border); background: var(--bg-3);
  color: var(--text); padding: 12px 16px; border-radius: 10px; transition: background 100ms;
}
button:active { background: #252b3d; transform: scale(0.98); }
.m-primary { background: var(--accent); border-color: var(--accent); color: #1b1300; font-weight: 600; }
.m-secondary { background: transparent; }
.m-danger { background: transparent; border-color: var(--red); color: var(--red); }
.m-icon {
  width: 40px; height: 40px; padding: 0; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px; border: none; background: transparent;
}

#m-login {
  padding: calc(40px + var(--safe-top)) 24px calc(24px + var(--safe-bot));
  justify-content: center;
  background: radial-gradient(800px 500px at 50% -10%, #1b2030 0%, var(--bg) 60%);
}
.m-brand { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
.m-brand h1 { margin: 0; font-size: 24px; }
.m-dot { width: 12px; height: 12px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 10px var(--accent); }
.m-signup { display: block; margin: 10px 0 4px; padding: 10px 12px; border: 1px solid var(--accent);
  border-radius: 10px; background: rgba(255,140,58,0.08); color: var(--accent);
  font-size: 13px; font-weight: 600; text-align: center; text-decoration: none; }
.m-signup:hover { background: rgba(255,140,58,0.16); }
#m-login label { display: block; margin: 14px 0 0; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.6px; }
#m-login input, #m-login select {
  width: 100%; margin-top: 4px; padding: 14px; background: var(--bg-3);
  border: 1px solid var(--border); border-radius: 10px; color: var(--text); outline: none;
  font-size: 16px;
}
#m-login input:focus, #m-login select:focus { border-color: var(--accent); }
#m-login-btn { width: 100%; margin-top: 22px; padding: 16px; }

.m-topbar {
  height: calc(52px + var(--safe-top));
  padding: var(--safe-top) 8px 0;
  background: var(--bg-2); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 4px;
}
.m-title { flex: 1; text-align: center; font-weight: 600; }

.m-connbar {
  padding: 8px 16px; background: var(--bg-2); border-bottom: 1px solid var(--border);
  font-size: 12px; display: flex; align-items: center; gap: 6px;
}
.m-cdot { width: 8px; height: 8px; border-radius: 50%; background: var(--red); }
.m-cdot.ok { background: var(--green); box-shadow: 0 0 6px var(--green); }

.m-hint-bar { padding: 8px 14px; color: var(--muted); font-size: 12px; background: var(--bg-2); border-bottom: 1px solid var(--border); }

.m-channels {
  flex: 1; overflow-y: auto; padding: 12px;
  display: flex; flex-direction: column; gap: 10px;
}
.m-ch {
  background: var(--bg-2); border: 1px solid var(--border); border-radius: 12px;
  padding: 12px; display: flex; flex-wrap: wrap; align-items: center; gap: 10px;
  transition: border-color 150ms, box-shadow 150ms;
}
.m-ch.talking { border-color: var(--green); box-shadow: 0 0 14px rgba(58,214,113,.3); }
.m-ch.remote-talking { border-color: var(--yellow); }
.m-ch-info { flex: 1; min-width: 0; }
.m-ch-name { font-weight: 600; font-size: 15px; }
.m-ch-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.m-ch-btn {
  width: 56px; height: 56px; border-radius: 14px;
  font-weight: 700; font-size: 14px; letter-spacing: 0.5px;
  flex-shrink: 0;
}
.m-ch-btn.talk.on { background: var(--green); border-color: var(--green); color: #072111; }
.m-ch-btn.listen.on { background: var(--blue); border-color: var(--blue); color: #fff; }

.m-side {
  position: fixed; inset: 0 auto 0 0; width: 280px; max-width: 82vw;
  background: var(--bg-2); border-right: 1px solid var(--border);
  padding: calc(16px + var(--safe-top)) 16px calc(16px + var(--safe-bot));
  z-index: 20; display: flex; flex-direction: column; gap: 10px;
  animation: slide-in-left 180ms ease-out;
}
.m-side header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.m-side header h3 { margin: 0; }
@keyframes slide-in-left { from { transform: translateX(-100%); } to { transform: translateX(0); } }

/* Latched talk — pulsing outline so it's obvious the channel is locked open */
.m-ch-btn.talk.latched {
  box-shadow: 0 0 0 2px var(--green), 0 0 14px rgba(58, 214, 113, 0.45);
  animation: pulse-latch 1.4s ease-in-out infinite;
}
@keyframes pulse-latch {
  0%, 100% { box-shadow: 0 0 0 2px var(--green), 0 0 14px rgba(58, 214, 113, 0.35); }
  50%      { box-shadow: 0 0 0 2px var(--green), 0 0 22px rgba(58, 214, 113, 0.7); }
}

.m-chat {
  position: fixed; inset: 0; background: var(--bg); z-index: 25;
  display: flex; flex-direction: column;
  padding-top: var(--safe-top); padding-bottom: var(--safe-bot);
}
.m-chat header { display: flex; align-items: center; gap: 8px; padding: 8px 8px 10px; border-bottom: 1px solid var(--border); background: var(--bg-2); }
.m-chat header h3 { margin: 0; font-size: 16px; }
.m-chat-channels { list-style: none; margin: 0; padding: 8px 12px; display: flex; gap: 8px; overflow-x: auto; border-bottom: 1px solid var(--border); background: var(--bg-2); }
.m-chat-channels li { white-space: nowrap; padding: 6px 12px; background: var(--bg-3); border-radius: 999px; font-size: 13px; border: 1px solid var(--border); }
.m-chat-channels li.active { background: var(--accent); color: #1b1300; border-color: var(--accent); }
.m-chat-log { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.m-msg { max-width: 80%; }
.m-msg .meta { font-size: 11px; color: var(--muted); margin-bottom: 2px; }
.m-msg .bubble { background: var(--bg-2); border: 1px solid var(--border); padding: 8px 12px; border-radius: 12px; white-space: pre-wrap; word-break: break-word; }
.m-msg.self { align-self: flex-end; }
.m-msg.self .bubble { background: var(--accent); border-color: var(--accent); color: #1b1300; }
.m-msg.self .meta { text-align: right; }
.m-chat-form { display: flex; gap: 8px; padding: 10px; border-top: 1px solid var(--border); background: var(--bg-2); }
.m-chat-form input { flex: 1; background: var(--bg-3); border: 1px solid var(--border); border-radius: 10px; padding: 12px; color: var(--text); outline: none; font-size: 16px; }

.m-modal { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 16px; }
.m-modal-card { background: var(--bg-2); border: 1px solid var(--border); border-radius: 14px; padding: 20px; width: 100%; max-width: 380px; }
.m-modal-card h3 { margin: 0 0 10px; }
.m-modal-card input { width: 100%; padding: 12px; background: var(--bg-3); border: 1px solid var(--border); border-radius: 10px; color: var(--text); outline: none; margin-bottom: 8px; font-size: 16px; }
.m-modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 10px; }

::-webkit-scrollbar { display: none; }

/* VU meter under each channel */
.m-vu {
  height: 4px;
  background: var(--bg-3);
  border-radius: 2px;
  overflow: hidden;
  margin-top: 6px;
}
.m-vu > span {
  display: block;
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--green), var(--yellow), var(--red));
  transition: width 60ms linear;
}

/* On-air banner at top of mobile channels list */
.m-now-talking {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  padding: 8px 12px;
  margin: 0 0 10px;
  background: rgba(232, 85, 106, 0.08);
  border: 1px solid var(--red);
  border-radius: 10px;
}
.m-now-talking.m-hidden { display: none; }
.m-nt-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--red);
  font-weight: 700;
  animation: m-talker-flash 0.6s ease-in-out infinite alternate;
}
.m-nt-list { display: flex; flex-wrap: wrap; gap: 6px; }
.m-nt-person {
  font-size: 12px;
  padding: 3px 10px;
  border-radius: 12px;
  background: var(--red);
  color: #fff;
  font-weight: 700;
  animation: m-talker-flash 0.6s ease-in-out infinite alternate;
}
.m-nt-person .m-nt-ch {
  margin-left: 6px;
  font-weight: 400;
  font-size: 10px;
  opacity: 0.85;
}

/* Flashing red talker name inside the per-channel subtitle */
.m-talker {
  color: #fff;
  background: var(--red);
  padding: 1px 6px;
  border-radius: 8px;
  font-weight: 700;
  animation: m-talker-flash 0.6s ease-in-out infinite alternate;
  display: inline-block;
}

@keyframes m-talker-flash {
  from { background: var(--red); box-shadow: 0 0 4px rgba(232, 85, 106, 0.35); }
  to   { background: #ff3b5c;    box-shadow: 0 0 14px rgba(255, 59, 92, 0.8); }
}

/* =================== mobile chat toast (top-center) =================== */
.m-chat-toast-container {
  position: fixed;
  top: 60px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  z-index: 9999;
  pointer-events: none;
  width: calc(100% - 16px);
  max-width: 480px;
}
.m-chat-toast {
  pointer-events: auto;
  background: var(--bg-2);
  border: 1px solid var(--accent);
  border-left: 4px solid var(--accent);
  border-radius: 10px;
  padding: 10px 14px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.6);
  cursor: pointer;
  opacity: 0;
  transform: translateY(-12px);
  transition: opacity 0.22s ease, transform 0.22s ease;
  width: 100%;
}
.m-chat-toast.m-chat-toast-in { opacity: 1; transform: translateY(0); }
.m-chat-toast.m-chat-toast-out { opacity: 0; transform: translateY(-12px); }
.m-chat-toast-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 3px;
}
.m-chat-toast-head strong {
  color: var(--accent-2, #ff8c3a);
  font-size: 13px;
}
.m-chat-toast-ch {
  font-size: 10px;
  color: var(--muted);
  background: var(--bg-3);
  padding: 2px 8px;
  border-radius: 10px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}
.m-chat-toast-body {
  font-size: 14px;
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 64px;
  overflow: hidden;
}

/* =================== mobile chat sidebar: unread channel =================== */
#m-chat-channels li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 12px;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.2s;
}
#m-chat-channels li.active {
  background: var(--bg-3);
  border-left: 3px solid var(--accent);
}
#m-chat-channels li.unread {
  background: rgba(58, 214, 113, 0.2);
  color: #fff;
  font-weight: 700;
  border-left: 3px solid var(--green, #3ad671);
  animation: m-chat-unread-pulse 1.5s ease-in-out infinite;
}
@keyframes m-chat-unread-pulse {
  0%, 100% {
    background: rgba(58, 214, 113, 0.2);
    box-shadow: 0 0 6px rgba(58, 214, 113, 0.3);
  }
  50% {
    background: rgba(58, 214, 113, 0.35);
    box-shadow: 0 0 14px rgba(58, 214, 113, 0.6);
  }
}
.m-unread-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--green, #3ad671);
  box-shadow: 0 0 8px rgba(58, 214, 113, 0.9);
  flex-shrink: 0;
}

/* Chat icon button in header glows green when there are unread messages */
#m-chat-toggle.has-unread {
  color: var(--green, #3ad671);
  animation: m-chat-btn-pulse 1.5s ease-in-out infinite;
}
@keyframes m-chat-btn-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(58, 214, 113, 0); }
  50%      { box-shadow: 0 0 0 6px rgba(58, 214, 113, 0.5); }
}

/* ── Per-channel volume slider ───────────────────────────────────────────── */
.m-vol-row {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;           /* full width — sits below T / info / L row */
  flex-basis: 100%;      /* force onto its own line in the flex wrap */
  padding: 8px 10px;
  background: rgba(255,255,255,0.05);
  border-radius: 8px;
  margin-top: 2px;
  animation: vol-slide-in 0.15s ease;
}
@keyframes vol-slide-in {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: translateY(0); }
}
.m-vol-icon { font-size: 14px; flex-shrink: 0; }
.m-vol-slider {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 4px;
  border-radius: 2px;
  background: linear-gradient(to right, #f97316 0%, #f97316 var(--vol-pct, 67%), #444 var(--vol-pct, 67%), #444 100%);
  outline: none;
  cursor: pointer;
}
.m-vol-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #f97316;
  cursor: pointer;
  border: 2px solid #fff;
  box-shadow: 0 1px 4px rgba(0,0,0,0.4);
}
.m-vol-slider::-moz-range-thumb {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #f97316;
  cursor: pointer;
  border: 2px solid #fff;
}
.m-vol-val {
  font-size: 11px;
  color: #aaa;
  min-width: 36px;
  text-align: right;
  flex-shrink: 0;
}

/* ── Mobile Admin Panel ─────────────────────────────────────────────────── */
.m-admin-panel {
  position: fixed; inset: 0; z-index: 200;
  background: var(--bg); display: flex; flex-direction: column;
  transform: translateX(100%); transition: transform .25s ease;
}
.m-admin-panel:not(.m-hidden) { transform: translateX(0); }
.m-admin-panel.m-hidden { display: flex; pointer-events: none; }

.m-admin-header {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 16px; border-bottom: 1px solid var(--border);
  background: var(--bg-2);
}
.m-admin-header h3 { margin: 0; font-size: 17px; font-weight: 700; }

.m-admin-tabs {
  display: flex; border-bottom: 1px solid var(--border);
  background: var(--bg-2);
}
.m-admin-tab {
  flex: 1; padding: 12px; background: none; border: none;
  color: var(--muted); font-size: 14px; font-weight: 600; cursor: pointer;
  border-bottom: 2px solid transparent; transition: all .2s;
}
.m-admin-tab.active { color: var(--orange); border-bottom-color: var(--orange); }

.m-admin-section { flex: 1; overflow-y: auto; padding: 12px 16px; }

.m-admin-toolbar {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 12px;
}
.m-sm { padding: 8px 16px; font-size: 13px; border-radius: 8px; }

.m-admin-list { display: flex; flex-direction: column; gap: 10px; }

.m-admin-item {
  background: var(--bg-2); border: 1px solid var(--border);
  border-radius: 10px; padding: 12px 14px;
  display: flex; align-items: center; gap: 10px;
}
.m-admin-item-info { flex: 1; min-width: 0; }
.m-admin-item-name {
  font-weight: 600; font-size: 14px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.m-admin-item-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.m-admin-item-actions { display: flex; gap: 8px; flex-shrink: 0; }
.m-admin-item-actions button {
  padding: 6px 12px; font-size: 12px; font-weight: 600;
  border-radius: 7px; border: 1px solid var(--border); cursor: pointer;
  background: var(--bg-3); color: var(--text); transition: all .15s;
}
.m-admin-item-actions .del { color: var(--red); border-color: rgba(239,68,68,.4); }
.m-admin-item-actions button:active { opacity: .7; }

.m-role-badge {
  display: inline-block; padding: 2px 8px; border-radius: 6px;
  font-size: 10px; font-weight: 700; text-transform: uppercase;
}
.m-role-badge.owner { background: rgba(249,115,22,.15); color: var(--orange); }
.m-role-badge.admin { background: rgba(59,130,246,.15); color: var(--blue); }
.m-role-badge.user  { background: rgba(100,116,139,.15); color: #94a3b8; }

/* ── Per-channel audio buttons (admin + desktop only) ─────────────────────── */
.m-ch-audio-row {
  width: 100%; flex-basis: 100%;
  display: flex; gap: 8px; margin-top: 6px;
}
.m-ch-audio-btn {
  flex: 1; background: var(--bg-3);
  border: 1px solid var(--border); border-radius: 8px;
  color: var(--muted); font-size: 11px; padding: 5px 8px;
  cursor: pointer; text-align: left;
  overflow: hidden; white-space: nowrap; text-overflow: ellipsis;
  transition: border-color .15s, color .15s;
}
.m-ch-audio-btn:hover { border-color: #f97316; color: var(--text); }

/* Admin: company scope switcher (superadmin/owner) */
.m-admin-co-bar {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 16px; border-bottom: 1px solid var(--border);
  background: var(--bg-2);
}
.m-admin-co-bar label {
  color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .5px;
  white-space: nowrap;
}
.m-admin-co-bar select {
  flex: 1; min-width: 0; background: var(--bg-3); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px; padding: 9px 10px; font-size: 14px;
}
.m-admin-co-bar select:focus { border-color: var(--accent); outline: none; }
