/* ============================================================== 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;
  --tap:       72px;
  --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: 34px; }
.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; animation-delay: 0s; }
.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, filter .15s;
}
.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; }

.role-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.role-grid button {
  min-height: var(--tap); padding: 12px 10px; border-radius: 16px;
  background: var(--surface); border: 2px solid var(--line);
  font-size: 15px; font-weight: 650; line-height: 1.25;
}
.role-grid button[aria-pressed=true] { border-color: var(--accent); background: #17304d; color: #fff; }

.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: 12px;
  padding: calc(var(--safe-t) + 10px) 14px 10px;
  background: linear-gradient(var(--bg-2), var(--bg));
  border-bottom: 1px solid var(--line);
  flex: none;
}
.who { display: flex; align-items: center; gap: 10px; min-height: 52px; padding-right: 8px; }
.avatar {
  width: 42px; height: 42px; border-radius: 13px; flex: none;
  display: grid; place-items: center; font-weight: 800; font-size: 16px;
  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: 16px; }
.who-text small { font-size: 12.5px; color: var(--ink-dim); }

.topbar-right { display: flex; align-items: center; gap: 8px; }
.status { display: flex; align-items: center; gap: 7px; font-size: 12.5px; color: var(--ink-dim); padding: 7px 11px; border-radius: 999px; background: var(--surface); }
.status .dot { width: 9px; height: 9px; 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); }

.now-banner {
  display: flex; align-items: center; gap: 10px; flex: none;
  padding: 11px 16px; font-size: 15px; font-weight: 650;
  background: #123a2c; color: #7dffc6; border-bottom: 1px solid #1d5d47;
}
.now-banner .pulse { width: 10px; height: 10px; border-radius: 50%; background: currentColor; animation: blink .9s infinite; flex: none; }

.zone-banner {
  display: flex; align-items: center; gap: 10px; flex: none;
  padding: 11px 16px; font-size: 14.5px; font-weight: 650;
  background: #3a2a10; color: #ffcf7a; border-bottom: 1px solid #5c4417;
}
.zone-banner svg { width: 19px; height: 19px; flex: none; }

/* =========================================================== channels === */
.grid {
  flex: 1; min-height: 0; overflow-y: auto;
  display: grid; grid-template-columns: repeat(2, 1fr);
  gap: 12px; padding: 12px;
  align-content: start;
  -webkit-overflow-scrolling: touch;
}
@media (min-width: 620px) { .grid { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 980px) { .grid { grid-template-columns: repeat(4, 1fr); } }

.tile {
  position: relative; display: flex; flex-direction: column; justify-content: space-between;
  min-height: 150px; padding: 14px; border-radius: var(--radius);
  background: var(--surface); border: 2px solid var(--line);
  text-align: left; overflow: hidden;
  touch-action: pan-y;           /* drag scrolls the grid, press talks */
  transition: transform .07s ease, background .12s, border-color .12s;
}
.tile::before {
  content: ''; position: absolute; inset: 0;
  background: var(--c); opacity: .09; transition: opacity .12s;
}
.tile-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; position: relative; }
.tile-code {
  font-size: 12px; font-weight: 800; letter-spacing: .1em;
  padding: 5px 9px; border-radius: 8px; color: #06121d;
  background: var(--c);
}
.tile-people { display: flex; align-items: center; gap: 4px; font-size: 13px; color: var(--ink-dim); font-variant-numeric: tabular-nums; }
.tile-people svg { width: 15px; height: 15px; stroke-width: 2.4; }

.tile-name { position: relative; font-size: 24px; font-weight: 800; letter-spacing: -.4px; line-height: 1.1; margin: 10px 0 2px; }
.tile-state { position: relative; font-size: 13.5px; color: var(--ink-dim); min-height: 19px; font-weight: 600; }

.tile-replay {
  position: absolute; right: 8px; bottom: 8px;
  width: 46px; height: 46px; border-radius: 13px;
  display: grid; place-items: center;
  background: var(--surface-2); color: var(--ink-dim); border: 1.5px solid var(--line);
}
.tile-replay svg { width: 19px; height: 19px; }
.tile-replay:active { background: var(--accent); color: #04121f; }

/* state: I'm transmitting */
.tile[data-tx=true] { border-color: var(--c); transform: scale(.975); background: color-mix(in srgb, var(--c) 30%, var(--surface)); }
.tile[data-tx=true]::before { opacity: .38; }
.tile[data-tx=true] .tile-state { color: #fff; }
.tile[data-tx=true]::after {
  content: ''; position: absolute; inset: -2px; border-radius: var(--radius);
  border: 3px solid var(--c); animation: keyed .9s ease-out infinite;
}
@keyframes keyed { 0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--c) 60%, transparent); } 100% { box-shadow: 0 0 0 16px transparent; } }

/* state: someone else is talking */
.tile[data-rx=true] { border-color: var(--ok); background: color-mix(in srgb, var(--ok) 16%, var(--surface)); }
.tile[data-rx=true] .tile-state { color: #8effcd; }
.tile[data-busy=true] { border-color: var(--warn); }
.tile[data-busy=true] .tile-state { color: var(--warn); }
.tile[data-muted=true] { opacity: .5; }

/* outside the channel's geofence: visible and audible, but you can't key up */
.tile[data-geo=locked] { border-style: dashed; }
.tile[data-geo=locked]::before { opacity: .03; }
.tile[data-geo=locked] .tile-name,
.tile[data-geo=locked] .tile-code { opacity: .55; }
.tile[data-geo=locked] .tile-state { color: #ffcf7a; }
.tile-pin { position: absolute; right: 12px; top: 46px; width: 18px; height: 18px; color: #ffcf7a; }


.tile .bars { position: absolute; left: 14px; bottom: 16px; display: flex; gap: 3px; align-items: flex-end; height: 18px; }
.tile .bars span { width: 4px; height: 20%; background: currentColor; border-radius: 2px; transition: height .08s; }

/* =========================================================== bottombar === */
.bottombar {
  flex: none; display: flex; gap: 12px; padding: 10px 12px calc(var(--safe-b) + 12px);
  background: linear-gradient(transparent, var(--bg-2) 40%);
  border-top: 1px solid var(--line);
}
.btn-repeat {
  flex: 1; min-height: 74px; border-radius: 18px;
  display: flex; align-items: center; gap: 14px; padding: 0 18px;
  background: var(--surface-2); border: 2px solid var(--line);
}
.btn-repeat svg { width: 28px; height: 28px; flex: none; color: var(--accent); }
.btn-repeat span { display: flex; flex-direction: column; align-items: flex-start; line-height: 1.25; min-width: 0; }
.btn-repeat strong { font-size: 19px; font-weight: 800; }
.btn-repeat small { font-size: 13px; color: var(--ink-dim); max-width: 46vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.btn-repeat:active { background: var(--accent); color: #04121f; }
.btn-repeat:active svg, .btn-repeat:active small { color: #04121f; }
.btn-repeat:disabled { opacity: .45; }

.btn-alarm {
  position: relative; width: 84px; min-height: 74px; border-radius: 18px; flex: none;
  background: linear-gradient(#b8353a, #8d2226); border: 2px solid #e5484d;
  font-weight: 900; letter-spacing: .06em; font-size: 17px; color: #fff;
  overflow: hidden;
}
.alarm-ring { position: absolute; inset: 0; background: #fff; opacity: 0; }
.btn-alarm[data-arming=true] .alarm-ring { animation: arm 1.2s linear forwards; opacity: .22; transform-origin: left; }
@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);
}
@media (min-width: 620px) { .sheet { align-items: center; justify-content: center; } .sheet-card { max-width: 560px; border-radius: 26px; } }
@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); }

.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; }
.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; }

.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; }

.version { text-align: center; color: var(--ink-faint); font-size: 12px; margin-top: 6px; }

/* ================================================================= log === */
.log-list { display: flex; flex-direction: column; gap: 8px; }
.log-item { display: flex; align-items: center; gap: 12px; padding: 12px; border-radius: 16px; background: var(--surface); border: 1.5px solid var(--line); }
.log-item .log-c { width: 6px; align-self: stretch; border-radius: 3px; background: var(--c); flex: none; }
.log-item .log-meta { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.log-item .log-meta strong { font-size: 16px; }
.log-item .log-meta small { font-size: 12.5px; color: var(--ink-faint); }
.log-play { width: 54px; height: 54px; border-radius: 15px; background: var(--surface-2); display: grid; place-items: center; flex: none; border: 1.5px solid var(--line); }
.log-play:active { background: var(--accent); color: #04121f; }
.log-empty { text-align: center; color: var(--ink-faint); padding: 40px 10px; font-size: 15px; }

/* ============================================================== toasts === */
.toast-wrap { position: fixed; left: 0; right: 0; bottom: calc(var(--safe-b) + 108px); 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; }

@media (prefers-reduced-motion: reduce) { * { animation-duration: .001s !important; } }
