:root {
  --bg: #0d1210;
  --panel: #161d1a;
  --panel-2: #1e2723;
  --line: #2a3530;
  --text: #e8efe9;
  --muted: #8b9a92;
  --accent: #f5a623;     /* orange radio */
  --accent-ink: #1a1203;
  --tx: #ff4d3d;         /* émission */
  --rx: #39d98a;         /* réception */
  --lcd-bg: #9fb98a;
  --lcd-ink: #1c2a16;
  --radius: 16px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
svg { width: 22px; height: 22px; flex: none; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.error { color: var(--tx); margin: 4px 0 0; font-size: 14px; }

.screen { min-height: 100dvh; display: flex; flex-direction: column; }

/* ---------- Boutons ---------- */
.btn {
  border: 0; border-radius: 12px; padding: 13px 18px; font-weight: 600;
  background: var(--panel-2); width: 100%;
}
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.ghost { background: transparent; border: 1px solid var(--line); }
.btn:active { transform: scale(.98); }
.icon-btn {
  width: 42px; height: 42px; border-radius: 12px; border: 0;
  background: var(--panel-2); display: grid; place-items: center;
}

/* ---------- Connexion ---------- */
#login { justify-content: center; padding: 24px 16px calc(24px + var(--safe-b)); }
.login-card { width: 100%; max-width: 380px; margin: 0 auto; display: flex; flex-direction: column; gap: 14px; text-align: center; }
.logo { width: 84px; height: 84px; margin: 0 auto; border-radius: 24px; background: var(--panel); display: grid; place-items: center; color: var(--accent); }
.logo svg { width: 52px; height: 52px; }
h1 { margin: 0; font-size: 26px; letter-spacing: .5px; }
h2 { margin: 0; font-size: 18px; }
#loginForm { display: flex; flex-direction: column; gap: 14px; text-align: left; margin-top: 8px; }
label { display: flex; flex-direction: column; gap: 6px; font-size: 14px; font-weight: 600; }
input {
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  padding: 13px 14px; font-size: 16px; font-weight: 400; outline: none; width: 100%;
}
input:focus { border-color: var(--accent); }
#inMatricule { text-transform: uppercase; letter-spacing: 2px; font-family: ui-monospace, monospace; }

/* ---------- Barre du haut ---------- */
#radio { padding-top: var(--safe-t); }
.topbar { display: flex; justify-content: space-between; align-items: center; padding: 10px 16px; }
.me { display: flex; align-items: center; gap: 10px; min-width: 0; }
.mat { font-family: ui-monospace, monospace; font-weight: 700; letter-spacing: 1.5px; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--tx); flex: none; box-shadow: 0 0 0 3px #ff4d3d22; }
.dot.on { background: var(--rx); box-shadow: 0 0 0 3px #39d98a22; }
.top-actions { display: flex; gap: 8px; }

.banner { margin: 0 16px 8px; padding: 10px 12px; border-radius: 12px; background: #3a2c0f; color: var(--accent); text-align: center; font-size: 14px; }

/* ---------- Canaux ---------- */
.channels-bar { display: flex; gap: 8px; padding: 4px 16px 10px; align-items: stretch; }
.chan-list { display: flex; gap: 8px; overflow-x: auto; flex: 1; scrollbar-width: none; scroll-snap-type: x proximity; }
.chan-list::-webkit-scrollbar { display: none; }
.chan {
  position: relative; flex: none; min-width: 118px; max-width: 170px; padding: 9px 10px 9px 12px;
  border-radius: 14px; background: var(--panel); border: 1.5px solid var(--line);
  text-align: left; display: flex; flex-direction: column; gap: 2px; scroll-snap-align: start;
}
.chan.active { border-color: var(--accent); background: #251d0d; }
.chan .c-name { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding-right: 26px; }
.chan .c-sub { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.chan .c-live { width: 8px; height: 8px; border-radius: 50%; background: var(--line); }
.chan.rx .c-live { background: var(--rx); animation: pulse 0.8s infinite alternate; }
.chan.txing .c-live { background: var(--tx); }
.chan.muted { opacity: .55; }
.chan .c-mute { position: absolute; top: 5px; right: 5px; width: 28px; height: 28px; border-radius: 8px; border: 0; background: transparent; display: grid; place-items: center; color: var(--muted); }
.chan .c-mute svg { width: 17px; height: 17px; }
.chan.muted .c-mute { color: var(--tx); }
.chan .c-badge { position: absolute; bottom: 6px; right: 8px; }
.chan-add { flex: none; width: 48px; border-radius: 14px; border: 1.5px dashed var(--line); background: transparent; display: grid; place-items: center; color: var(--accent); }
.chan-empty { color: var(--muted); font-size: 14px; padding: 12px 4px; }

.badge { min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--tx); color: #fff; font-size: 11px; font-weight: 700; display: inline-grid; place-items: center; }

@keyframes pulse { from { opacity: .35; } to { opacity: 1; } }

/* ---------- LCD ---------- */
.lcd {
  margin: 0 16px; padding: 14px 16px 12px; border-radius: var(--radius);
  background: linear-gradient(180deg, #a9c493, var(--lcd-bg)); color: var(--lcd-ink);
  box-shadow: inset 0 2px 8px #0005, 0 0 0 4px #1b2420;
  font-family: ui-monospace, "SFMono-Regular", Menlo, monospace;
}
.lcd.tx { background: linear-gradient(180deg, #f3a59a, #e2877b); }
.lcd.rx { background: linear-gradient(180deg, #b8e6a2, #9fd68a); }
.lcd-top { display: flex; justify-content: space-between; align-items: center; }
.lcd-state { font-weight: 800; font-size: 13px; letter-spacing: 2px; }
.lcd-members { border: 0; background: #0000001a; color: inherit; border-radius: 8px; padding: 4px 8px; display: flex; align-items: center; gap: 5px; font-weight: 700; font-family: inherit; }
.lcd-members svg { width: 16px; height: 16px; }
.lcd-name { font-size: 22px; font-weight: 800; margin-top: 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lcd-talker { font-size: 15px; font-weight: 700; min-height: 21px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.vu { height: 6px; border-radius: 3px; background: #0000002a; margin-top: 8px; overflow: hidden; }
#vuBar { height: 100%; width: 0; background: var(--lcd-ink); transition: width 60ms linear; }
.lcd-other { font-size: 12px; margin-top: 6px; min-height: 16px; opacity: .8; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- PTT ---------- */
.ptt-wrap { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; padding: 18px 16px; }
.ptt {
  width: min(62vw, 250px); aspect-ratio: 1; border-radius: 50%; border: 0;
  background: radial-gradient(circle at 50% 35%, #ffb944, var(--accent) 60%, #c98213);
  color: var(--accent-ink); box-shadow: 0 10px 30px #f5a62333, inset 0 -6px 0 #0002, 0 0 0 10px var(--panel);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px;
  font-weight: 800; font-size: 13px; letter-spacing: 1px; text-align: center; padding: 20px;
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; touch-action: none;
  transition: transform .08s, box-shadow .15s, background .15s;
}
.ptt svg { width: 56px; height: 56px; }
.ptt:disabled { filter: grayscale(1) brightness(.55); cursor: not-allowed; }
.ptt.pending { transform: scale(.96); }
.ptt.tx {
  transform: scale(.95);
  background: radial-gradient(circle at 50% 35%, #ff7a6b, var(--tx) 60%, #b72a1d); color: #fff;
  box-shadow: 0 0 0 10px var(--panel), 0 0 0 18px #ff4d3d33, 0 0 50px #ff4d3d66;
}
.ptt.busy { animation: shake .3s; }
@keyframes shake { 25% { translate: -6px 0; } 75% { translate: 6px 0; } }
.switch-row { flex-direction: row; align-items: center; gap: 10px; font-weight: 400; color: var(--muted); font-size: 14px; }
.switch-row input { width: 20px; height: 20px; accent-color: var(--accent); }

/* ---------- Contrôles ---------- */
.controls {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px;
  padding: 10px 16px calc(12px + var(--safe-b)); background: var(--panel); border-top: 1px solid var(--line);
}
.ctrl {
  position: relative; border: 0; background: var(--panel-2); border-radius: 14px; padding: 10px 4px;
  display: flex; flex-direction: column; align-items: center; gap: 4px; font-size: 12px; font-weight: 600;
}
.ctrl.on { background: var(--accent); color: var(--accent-ink); }
.ctrl.danger { background: var(--tx); color: #fff; }
.ctrl span { white-space: nowrap; font-size: 11.5px; }
.ctrl .badge { position: absolute; top: 6px; right: calc(50% - 22px); }

/* ---------- Feuilles ---------- */
.sheet { position: fixed; inset: 0; background: #000a; z-index: 20; display: flex; align-items: flex-end; animation: fade .15s; }
.sheet-panel {
  width: 100%; max-width: 560px; margin: 0 auto; max-height: 88dvh; overflow: auto;
  background: var(--panel); border-radius: 22px 22px 0 0; padding: 16px 16px calc(16px + var(--safe-b));
  display: flex; flex-direction: column; gap: 12px; animation: up .2s ease-out;
}
.sheet-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
@keyframes fade { from { opacity: 0; } }
@keyframes up { from { transform: translateY(40px); opacity: .4; } }

.all-chans { display: flex; flex-direction: column; gap: 8px; }
.ch-row { display: flex; align-items: center; gap: 12px; padding: 12px; border-radius: 12px; background: var(--panel-2); }
.ch-row .ch-info { flex: 1; min-width: 0; }
.ch-row .ch-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ch-row button { border: 0; border-radius: 10px; padding: 8px 12px; font-weight: 600; background: var(--accent); color: var(--accent-ink); }
.ch-row.in button { background: transparent; border: 1px solid var(--line); color: var(--text); }
.create-form { display: flex; gap: 8px; }
.create-form .btn { width: auto; }

.members { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.members li { padding: 10px 12px; background: var(--panel-2); border-radius: 10px; display: flex; justify-content: space-between; gap: 10px; }
.members .m-mat { font-family: ui-monospace, monospace; font-weight: 700; }
.members .m-you { color: var(--accent); font-size: 12px; }

/* ---------- Chat ---------- */
.chat-panel { height: 88dvh; }
.chat-tabs { display: flex; gap: 6px; overflow-x: auto; flex: none; scrollbar-width: none; }
.chat-tabs button { flex: none; border: 1px solid var(--line); background: transparent; border-radius: 999px; padding: 6px 12px; font-size: 13px; display: flex; gap: 6px; align-items: center; }
.chat-tabs button.sel { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
.chat-log { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; padding: 4px 2px; min-height: 0; }
.msg { max-width: 82%; align-self: flex-start; background: var(--panel-2); padding: 8px 12px; border-radius: 14px 14px 14px 4px; overflow-wrap: anywhere; }
.msg.mine { align-self: flex-end; background: #3a2c0f; border-radius: 14px 14px 4px 14px; }
.msg .meta { font-size: 11px; color: var(--muted); margin-bottom: 2px; font-family: ui-monospace, monospace; }
.msg.mine .meta { color: #d6a65a; }
.msg.sys { align-self: center; background: transparent; color: var(--muted); font-size: 12px; padding: 2px; }
.chat-empty { margin: auto; color: var(--muted); }
.chat-form { display: flex; gap: 8px; }
.chat-form .send { background: var(--accent); color: var(--accent-ink); width: 50px; height: 48px; }

/* ---------- Appel entrant ---------- */
.ring-overlay { position: fixed; inset: 0; z-index: 40; background: #000c; display: grid; place-items: center; padding: 16px; animation: fade .2s; }
.ring-card { width: 100%; max-width: 340px; background: var(--panel); border-radius: 24px; padding: 28px 20px; text-align: center; display: flex; flex-direction: column; gap: 6px; }
.ring-icon { width: 84px; height: 84px; margin: 0 auto 10px; border-radius: 50%; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; animation: ring 0.5s infinite; }
.ring-icon svg { width: 44px; height: 44px; }
@keyframes ring { 0%,100% { rotate: -12deg; } 50% { rotate: 12deg; } }
.ring-chan { font-size: 22px; font-weight: 800; }
.ring-from { font-family: ui-monospace, monospace; color: var(--accent); }
.ring-actions { display: flex; gap: 10px; margin-top: 16px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 16px; right: 16px; bottom: calc(96px + var(--safe-b)); z-index: 50;
  max-width: 420px; margin: 0 auto; padding: 12px 14px; border-radius: 12px;
  background: #2b3631; border: 1px solid var(--line); text-align: center; font-size: 14px; animation: up .2s;
}

@media (min-height: 760px) { .ptt { width: min(66vw, 270px); } }
@media (max-height: 640px) { .ptt { width: min(48vw, 180px); } .ptt svg { width: 40px; height: 40px; } .switch-row { display: none; } }
