/* ============================================================== tokens === */
:root {
  --bg:        #0b1016;
  --bg-2:      #121a24;
  --surface:   #17222f;
  --surface-2: #1e2c3c;
  --line:      #29394c;
  --ink:       #eaf2fb;
  --ink-dim:   #93a6bd;
  --ink-faint: #64788f;
  --accent:    #3e9bff;
  --ok:        #30c48d;
  --warn:      #f4b740;
  --danger:    #e5484d;
  --radius:    20px;
  --infobar-h: 74px;          /* fast — raden ska aldrig knuffa layouten */
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
}

body.bright {
  --bg:        #05080c;
  --bg-2:      #0b1118;
  --surface:   #12202e;
  --surface-2: #1b3048;
  --line:      #48678a;
  --ink:       #ffffff;
  --ink-dim:   #c3d5e8;
  --ink-faint: #93a9c0;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

/* Webbläsarens egen regel för `hidden` är `display: none`, men den är en
   UA-regel och förlorar mot varje författarregel som sätter display — och
   nästan allt som döljs här är flex eller grid. Utan den här raden gör
   hidden-attributet ingenting alls. */
[hidden] { display: none !important; }

html, body { height: 100%; background: var(--bg); color: var(--ink); font-family: var(--font); overscroll-behavior: none; }
body {
  display: flex; flex-direction: column;
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
  touch-action: manipulation;
}
body.booting > * { display: none; }

svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
button, input, select { font: inherit; color: inherit; }
button { background: none; border: 0; cursor: pointer; }

/* ========================================================== onboarding === */
.onboard {
  position: fixed; inset: 0; z-index: 60; display: grid; place-items: center;
  padding: calc(var(--safe-t) + 24px) 20px calc(var(--safe-b) + 24px);
  background: radial-gradient(120% 90% at 50% 0%, #17283b 0%, var(--bg) 62%);
  overflow-y: auto;
}
.onboard-inner { width: min(460px, 100%); }
.onboard-head { text-align: center; margin-bottom: 30px; }
.onboard-head h1 { font-size: 34px; letter-spacing: -0.5px; margin-top: 14px; }
.tagline { color: var(--ink-dim); margin-top: 4px; font-size: 15px; }

.logo { display: inline-flex; align-items: flex-end; gap: 5px; height: 42px; }
.logo span { width: 7px; border-radius: 4px; background: var(--accent); animation: wave 1.1s ease-in-out infinite; }
.logo span:nth-child(1) { height: 18px; }
.logo span:nth-child(2) { height: 40px; animation-delay: .15s; background: var(--ok); }
.logo span:nth-child(3) { height: 26px; animation-delay: .3s; background: var(--warn); }
@keyframes wave { 0%,100% { transform: scaleY(.45); } 50% { transform: scaleY(1); } }

.step { display: flex; flex-direction: column; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 8px; }
.field-label { font-size: 13px; font-weight: 700; letter-spacing: .09em; text-transform: uppercase; color: var(--ink-faint); }
.field-label.small { display: flex; justify-content: space-between; text-transform: none; letter-spacing: 0; font-size: 14px; color: var(--ink-dim); }
.field-label b { color: var(--ink); }
.hint { font-size: 14px; color: var(--ink-faint); line-height: 1.45; }

input[type=text], select {
  width: 100%; height: 60px; padding: 0 18px; background: var(--surface);
  border: 2px solid var(--line); border-radius: 16px; font-size: 19px; outline: none;
}
input[type=text]:focus, select:focus { border-color: var(--accent); }
select { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--ink-dim) 50%), linear-gradient(135deg, var(--ink-dim) 50%, transparent 50%); background-position: right 22px center, right 16px center; background-size: 6px 6px, 6px 6px; background-repeat: no-repeat; }

.btn-primary { height: 68px; border-radius: 18px; font-size: 19px; font-weight: 800; background: var(--accent); color: #04121f; margin-top: 8px; transition: transform .08s; }
.btn-primary:active { transform: scale(.98); }
.btn-primary:disabled { background: var(--surface-2); color: var(--ink-faint); }
.btn-ghost { height: 54px; border-radius: 14px; color: var(--ink-dim); font-weight: 600; }
.btn-ghost.danger { color: var(--danger); border: 2px solid rgba(229,72,77,.35); margin-top: 20px; }
.btn-small { min-height: 46px; padding: 0 16px; border-radius: 12px; background: var(--surface-2); border: 1.5px solid var(--line); font-size: 15px; font-weight: 650; }
.btn-small:active { background: var(--accent); color: #04121f; }

.role-grid, .lang-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.role-grid button, .lang-grid button {
  min-height: 68px; padding: 12px 10px; border-radius: 16px;
  background: var(--surface); border: 2px solid var(--line);
  font-size: 15px; font-weight: 650; line-height: 1.25;
}
.lang-grid button { display: flex; align-items: center; gap: 10px; justify-content: flex-start; padding-left: 16px; }
.lang-grid .flag { font-size: 26px; line-height: 1; }
.role-grid button[aria-pressed=true], .lang-grid button[aria-pressed=true] { border-color: var(--accent); background: #17304d; color: #fff; }

.place-grid { display: grid; gap: 10px; }
.place-card {
  display: flex; flex-direction: column; align-items: flex-start; gap: 4px;
  padding: 18px; border-radius: 18px; text-align: left;
  background: var(--surface); border: 2px solid var(--line);
}
.place-card svg { width: 26px; height: 26px; color: var(--accent); margin-bottom: 4px; }
.place-card strong { font-size: 19px; }
.place-card small { font-size: 13.5px; color: var(--ink-faint); line-height: 1.4; }
.place-card[aria-pressed=true] { border-color: var(--accent); background: #17304d; }
.place-card[aria-pressed=true] small { color: var(--ink-dim); }

.radius-row { display: flex; gap: 8px; flex-wrap: wrap; }
.radius-row button {
  min-height: 52px; padding: 0 18px; border-radius: 14px; font-size: 16px; font-weight: 700;
  background: var(--surface); border: 2px solid var(--line);
}
.radius-row button[aria-pressed=true] { border-color: var(--ok); background: color-mix(in srgb, var(--ok) 20%, var(--surface)); }

.chan-picker { display: flex; flex-wrap: wrap; gap: 10px; }
.chan-chip { min-height: 54px; padding: 10px 16px; border-radius: 14px; background: var(--surface); border: 2px solid var(--line); display: flex; align-items: center; gap: 10px; font-size: 16px; font-weight: 650; }
.chan-chip i { width: 12px; height: 12px; border-radius: 50%; background: var(--c, var(--accent)); flex: none; }
.chan-chip[aria-pressed=true] { border-color: var(--c, var(--accent)); background: color-mix(in srgb, var(--c, var(--accent)) 18%, var(--surface)); }
.chan-chip[data-locked=true] { opacity: .75; }

/* ============================================================== topbar === */
#app { display: flex; flex-direction: column; height: 100%; min-height: 0; }

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: calc(var(--safe-t) + 8px) 12px 8px;
  background: var(--bg-2); border-bottom: 1px solid var(--line); flex: none;
}
.who { display: flex; align-items: center; gap: 10px; min-height: 48px; }
.avatar { width: 40px; height: 40px; border-radius: 12px; flex: none; display: grid; place-items: center; font-weight: 800; font-size: 15px; background: var(--accent); color: #04121f; }
.who-text { display: flex; flex-direction: column; align-items: flex-start; line-height: 1.2; }
.who-text strong { font-size: 15.5px; }
.who-text small { font-size: 12px; color: var(--ink-dim); }

.topbar-right { display: flex; align-items: center; gap: 8px; }
.lang-chip { font-size: 22px; line-height: 1; }
.status { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--ink-dim); padding: 7px 10px; border-radius: 999px; background: var(--surface); }
.status .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--warn); }
.status[data-state=online] .dot { background: var(--ok); box-shadow: 0 0 10px var(--ok); }
.status[data-state=offline] .dot { background: var(--danger); }
.status[data-state=connecting] .dot { animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: .25; } }

.icon-btn { width: 48px; height: 48px; border-radius: 14px; display: grid; place-items: center; background: var(--surface); color: var(--ink-dim); }
.icon-btn:active { background: var(--surface-2); }

/* ============================================================= infobar === */
/* Höjden är låst. Innehållet byts, raden flyttar sig aldrig. */
.infobar {
  flex: none; height: var(--infobar-h); min-height: var(--infobar-h);
  display: flex; align-items: center; gap: 12px; width: 100%;
  padding: 0 14px; text-align: left;
  background: var(--surface); border-bottom: 1px solid var(--line);
  transition: background .18s, border-color .18s;
}
.infobar:active { background: var(--surface-2); }
.info-icon { width: 10px; height: 10px; border-radius: 50%; background: var(--ink-faint); flex: none; }
.info-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.info-main { font-size: 16px; font-weight: 650; line-height: 1.25; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.info-sub { font-size: 12.5px; color: var(--ink-faint); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.info-chev { color: var(--ink-faint); display: grid; place-items: center; flex: none; }
.info-chev svg { width: 20px; height: 20px; }

.infobar[data-kind=live] { background: #123a2c; border-bottom-color: #1d5d47; }
.infobar[data-kind=live] .info-icon { background: #7dffc6; animation: blink .9s infinite; }
.infobar[data-kind=live] .info-main { color: #7dffc6; }
.infobar[data-kind=tx] { background: #123049; border-bottom-color: #1d4d78; }
.infobar[data-kind=tx] .info-icon { background: var(--accent); animation: blink .7s infinite; }
.infobar[data-kind=zone] { background: #3a2a10; border-bottom-color: #5c4417; }
.infobar[data-kind=zone] .info-icon { background: var(--warn); }
.infobar[data-kind=zone] .info-main { color: #ffcf7a; }
.infobar[data-kind=msg] .info-icon { background: var(--accent); }

/* ========================================================== stor knapp === */
.stage { flex: 1; min-height: 0; display: grid; place-items: center; padding: 16px 20px; }

.ptt {
  position: relative; width: min(74vw, 300px); aspect-ratio: 1; border-radius: 50%;
  display: grid; place-items: center;
  background: radial-gradient(circle at 50% 38%, color-mix(in srgb, var(--c, var(--accent)) 42%, var(--surface)) 0%, var(--surface) 72%);
  border: 4px solid var(--c, var(--accent));
  box-shadow: 0 14px 40px rgba(0,0,0,.45), inset 0 2px 0 rgba(255,255,255,.08);
  transition: transform .08s ease, border-color .15s, background .15s;
  touch-action: none;
}
.ptt:active, .ptt[data-tx=true] { transform: scale(.965); }
.ptt-inner { display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 10px; }
.ptt-chan { font-size: clamp(26px, 8vw, 40px); font-weight: 900; letter-spacing: -1px; line-height: 1; text-align: center; }
.ptt-hint { font-size: 14px; color: var(--ink-dim); font-weight: 600; text-align: center; max-width: 82%; }

.ptt[data-tx=true] { background: radial-gradient(circle at 50% 38%, color-mix(in srgb, var(--c) 72%, #000) 0%, color-mix(in srgb, var(--c) 30%, var(--surface)) 74%); }
.ptt[data-tx=true] .ptt-hint { color: #fff; }
.ptt-ring { position: absolute; inset: -4px; border-radius: 50%; pointer-events: none; }
.ptt[data-tx=true] .ptt-ring { animation: keyed 1s ease-out infinite; }
@keyframes keyed {
  0%   { box-shadow: 0 0 0 0 color-mix(in srgb, var(--c) 55%, transparent); }
  100% { box-shadow: 0 0 0 26px transparent; }
}
.ptt[data-busy=true] { border-color: var(--warn); }
.ptt[data-geo=locked] { border-style: dashed; opacity: .82; }

.ptt-bars { display: flex; align-items: flex-end; gap: 4px; height: 22px; }
.ptt-bars span { width: 5px; height: 15%; background: currentColor; border-radius: 3px; opacity: .55; transition: height .07s; }
.ptt[data-tx=true] .ptt-bars span { opacity: 1; }

/* =========================================================== kanalval === */
.selectors {
  flex: none; display: grid; gap: 8px; padding: 0 12px 10px;
  grid-template-columns: repeat(4, 1fr);
}
.selectors[data-count="1"], .selectors[data-count="2"], .selectors[data-count="3"] { grid-template-columns: repeat(3, 1fr); }
.selectors[data-count="5"], .selectors[data-count="6"] { grid-template-columns: repeat(3, 1fr); }

.chan {
  position: relative; min-height: 64px; border-radius: 15px; padding: 8px 6px 7px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  background: var(--surface); border: 2px solid var(--line);
  transition: border-color .12s, background .12s, transform .07s;
}
.chan:active { transform: scale(.96); }
.chan-code { font-size: 13px; font-weight: 850; letter-spacing: .06em; line-height: 1; }
.chan-who { font-size: 10.5px; color: var(--ink-faint); line-height: 1; font-variant-numeric: tabular-nums; }
.chan[aria-pressed=true] { border-color: var(--c); background: color-mix(in srgb, var(--c) 22%, var(--surface)); }
.chan[aria-pressed=true] .chan-code { color: #fff; }
.chan[data-rx=true] { border-color: var(--ok); }
.chan[data-rx=true] .chan-who { color: #7dffc6; }
.chan[data-geo=locked] { border-style: dashed; opacity: .6; }
.chan-dot { position: absolute; top: 6px; right: 7px; width: 9px; height: 9px; border-radius: 50%; background: var(--ok); }
.chan-dot[hidden] { display: none; }
.chan-unread { position: absolute; top: 5px; left: 6px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--accent); color: #04121f; font-size: 11px; font-weight: 800; display: grid; place-items: center; }
.chan-unread[hidden] { display: none; }

/* ============================================================ actions === */
.actions { flex: none; display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; padding: 0 12px calc(var(--safe-b) + 12px); }
.act {
  min-height: 70px; border-radius: 17px; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 5px;
  background: var(--surface-2); border: 2px solid var(--line); font-size: 13px; font-weight: 750;
}
.act svg { width: 25px; height: 25px; }
.act:active { transform: scale(.97); }
.act-repeat svg { color: var(--accent); }
.act-repeat:disabled { opacity: .42; }
.act-qr svg { color: var(--ok); }
.act-alarm { position: relative; overflow: hidden; background: linear-gradient(#b8353a, #8d2226); border-color: #e5484d; color: #fff; letter-spacing: .05em; }
.alarm-ring { position: absolute; inset: 0; background: #fff; opacity: 0; transform-origin: left; }
.act-alarm[data-arming=true] .alarm-ring { animation: arm 1.2s linear forwards; opacity: .22; }
@keyframes arm { from { transform: scaleX(0); } to { transform: scaleX(1); } }

/* ============================================================== sheets === */
.sheet { position: fixed; inset: 0; z-index: 50; background: rgba(4,8,13,.72); display: flex; align-items: flex-end; backdrop-filter: blur(6px); }
.sheet-card { width: 100%; max-height: 92dvh; display: flex; flex-direction: column; background: var(--bg-2); border-radius: 26px 26px 0 0; border-top: 1px solid var(--line); animation: rise .22s cubic-bezier(.2,.8,.3,1); }
.sheet-card.tall { height: 92dvh; }
@media (min-width: 620px) { .sheet { align-items: center; justify-content: center; } .sheet-card { max-width: 560px; border-radius: 26px; } .sheet-card.tall { height: 80dvh; } }
@keyframes rise { from { transform: translateY(24px); opacity: .5; } }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 16px 12px; border-bottom: 1px solid var(--line); flex: none; }
.sheet-head h2 { font-size: 20px; }
.sheet-body { overflow-y: auto; padding: 18px 16px calc(var(--safe-b) + 28px); display: flex; flex-direction: column; gap: 14px; -webkit-overflow-scrolling: touch; }

.toggle { display: flex; align-items: center; gap: 14px; min-height: 60px; }
.toggle input { position: absolute; opacity: 0; pointer-events: none; }
.toggle span { width: 56px; height: 34px; border-radius: 999px; background: var(--surface-2); border: 2px solid var(--line); flex: none; position: relative; transition: background .15s, border-color .15s; }
.toggle span::after { content: ''; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: var(--ink-dim); transition: transform .15s, background .15s; }
.toggle input:checked + span { background: color-mix(in srgb, var(--accent) 35%, var(--surface)); border-color: var(--accent); }
.toggle input:checked + span::after { transform: translateX(22px); background: var(--accent); }
.toggle em { font-style: normal; font-weight: 650; font-size: 16px; display: flex; flex-direction: column; }
.toggle em small { font-weight: 400; font-size: 13px; color: var(--ink-faint); margin-top: 2px; }

input[type=range] { -webkit-appearance: none; appearance: none; width: 100%; height: 40px; background: transparent; }
input[type=range]::-webkit-slider-runnable-track { height: 10px; border-radius: 5px; background: var(--surface-2); }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 32px; height: 32px; border-radius: 50%; background: var(--accent); margin-top: -11px; border: 3px solid var(--bg-2); }
input[type=range]::-moz-range-track { height: 10px; border-radius: 5px; background: var(--surface-2); }
input[type=range]::-moz-range-thumb { width: 28px; height: 28px; border: 3px solid var(--bg-2); border-radius: 50%; background: var(--accent); }

.meter { height: 14px; border-radius: 7px; background: var(--surface-2); overflow: hidden; }
.meter-fill { height: 100%; width: 0%; background: linear-gradient(90deg, var(--ok), var(--warn) 78%, var(--danger)); transition: width .07s linear; }

.pos-box { background: var(--surface); border: 2px solid var(--line); border-radius: 16px; padding: 14px; display: flex; flex-direction: column; gap: 12px; }
.pos-read { font-size: 15px; color: var(--ink-dim); line-height: 1.5; font-variant-numeric: tabular-nums; }
.pos-read b { color: var(--ink); font-size: 17px; }
.pos-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.version { text-align: center; color: var(--ink-faint); font-size: 12px; margin-top: 6px; }

/* ================================================================ chat === */
.chat-body { gap: 10px; }
.msg { display: flex; flex-direction: column; gap: 5px; padding: 12px 14px; border-radius: 16px; background: var(--surface); border: 1.5px solid var(--line); border-left: 4px solid var(--c, var(--accent)); }
.msg-head { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.msg-head strong { font-size: 15px; }
.msg-head small { font-size: 12px; color: var(--ink-faint); font-variant-numeric: tabular-nums; }
.msg-text { font-size: 16.5px; line-height: 1.45; }
.msg-text.pending { color: var(--ink-faint); font-style: italic; }
.msg-orig { font-size: 13.5px; color: var(--ink-faint); line-height: 1.4; padding-top: 4px; border-top: 1px dashed var(--line); }
.msg-foot { display: flex; align-items: center; gap: 10px; margin-top: 2px; }
.msg-play { min-height: 40px; padding: 0 14px; border-radius: 11px; background: var(--surface-2); border: 1.5px solid var(--line); font-size: 14px; font-weight: 650; display: flex; align-items: center; gap: 7px; }
.msg-play svg { width: 16px; height: 16px; }
.msg-play:active { background: var(--accent); color: #04121f; }
.msg-tag { font-size: 11px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--ink-faint); padding: 3px 8px; border-radius: 6px; background: var(--surface-2); }
.chat-empty { text-align: center; color: var(--ink-faint); padding: 48px 12px; font-size: 15px; line-height: 1.6; }

/* ================================================================== QR === */
.qr-body { align-items: center; }
.qr-frame { background: #fff; padding: 14px; border-radius: 20px; width: min(280px, 72vw); }
.qr-frame img { display: block; width: 100%; height: auto; }
.qr-code { font-size: 30px; font-weight: 900; letter-spacing: .22em; font-variant-numeric: tabular-nums; }
.qr-chans { font-size: 14px; color: var(--ink-dim); text-align: center; line-height: 1.5; }
.qr-body .field-label, .qr-body .chan-picker, .qr-body .hint { align-self: stretch; }

/* ============================================================== toasts === */
.toast-wrap { position: fixed; left: 0; right: 0; bottom: calc(var(--safe-b) + 100px); z-index: 70; display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; padding: 0 16px; }
.toast { background: var(--surface-2); border: 1.5px solid var(--line); color: var(--ink); padding: 13px 18px; border-radius: 14px; font-size: 15px; font-weight: 650; box-shadow: 0 10px 30px rgba(0,0,0,.5); animation: pop .18s; max-width: 100%; }
.toast[data-kind=warn] { border-color: var(--warn); color: var(--warn); }
.toast[data-kind=err] { border-color: var(--danger); color: #ffb3b5; }
@keyframes pop { from { transform: translateY(10px); opacity: 0; } }

/* =============================================================== alarm === */
.alarm-overlay { position: fixed; inset: 0; z-index: 80; display: grid; place-items: center; padding: 24px; background: rgba(120,10,14,.86); animation: flash 1s steps(1) infinite; }
@keyframes flash { 50% { background: rgba(60,4,6,.9); } }
.alarm-box { text-align: center; display: flex; flex-direction: column; gap: 14px; max-width: 360px; width: 100%; }
.alarm-box h2 { font-size: 40px; letter-spacing: .08em; }
.alarm-box p { font-size: 18px; color: #ffd9da; }

/* Låg skärm: krymp den stora knappen hellre än att något åker utanför. */
@media (max-height: 700px) {
  :root { --infobar-h: 66px; }
  .ptt { width: min(58vw, 220px); }
  .act { min-height: 60px; }
  .chan { min-height: 56px; }
}
@media (prefers-reduced-motion: reduce) { * { animation-duration: .001s !important; } }
