/* ============================================================================
   OATAK — tactical instrument-panel UI. Dark, dense, high-contrast.
   System fonts only; monospace for data, sans for chrome. No icon fonts.
   ========================================================================== */
:root {
  /* surfaces */
  --bg:      #0a0d11;
  --bg-2:    #0d1217;
  --panel:   #121922;
  --panel-2: #18212c;
  --panel-3: #202c39;
  --line:    #283440;
  --line-2:  #364654;
  /* text */
  --fg:      #cfd8e0;
  --fg-dim:  #93a2b0;
  --muted:   #69788a;
  /* signal */
  --accent:  #4f9cff;
  --accent-2:#1d3a5f;
  --ok:      #3fbf6a;
  --warn:    #e3a72b;
  --bad:     #e5484d;
  /* type */
  --mono: ui-monospace, "SFMono-Regular", "Cascadia Mono", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  /* layout */
  --header-h: 38px;
  --toolbar-h: 36px;
  --top-h: 74px;     /* header + toolbar */
  --rail-w: 240px;
  --radius: 3px;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--sans);
  background: var(--bg);
  color: var(--fg);
  font-size: 13px;
  line-height: 1.4;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

/* scrollbars */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: var(--bg-2); }
::-webkit-scrollbar-thumb { background: var(--line-2); border-radius: 5px; border: 2px solid var(--bg-2); }
::-webkit-scrollbar-thumb:hover { background: #44586a; }

.micro { font-family: var(--mono); font-size: 10px; color: var(--muted); letter-spacing: 1px; }
.spacer { flex: 1 1 auto; }
.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 11px; }

/* ---------------------------------------------------------------- header --- */
#topbar {
  position: fixed; inset: 0 0 auto 0; height: var(--header-h); z-index: 1000;
  display: flex; align-items: center; gap: 12px; padding: 0 10px;
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
  border-bottom: 1px solid var(--line);
}
.brand {
  font-weight: 800; letter-spacing: 3px; color: var(--accent); font-size: 15px;
}
.brand-sub {
  font-family: var(--mono); font-size: 9px; letter-spacing: 2px; color: var(--muted);
  border: 1px solid var(--line-2); border-radius: 2px; padding: 1px 4px; margin-left: -6px;
}
.op-group { display: flex; align-items: center; gap: 6px; }
#op-switcher {
  width: auto; min-width: 130px; max-width: 220px; height: 24px;
  padding: 0 22px 0 8px; font-size: 12px; font-weight: 600;
  background: var(--panel-3); border: 1px solid var(--line-2); color: var(--fg);
}
.clock {
  font-family: var(--mono); font-size: 12px; color: var(--fg-dim);
  letter-spacing: 1px; padding: 2px 6px; border: 1px solid var(--line);
  border-radius: var(--radius); background: var(--bg-2);
}
.me {
  font-family: var(--mono); font-size: 12px; cursor: pointer; padding: 3px 8px;
  border: 1px solid var(--line-2); border-radius: var(--radius); background: var(--panel-3);
}
.me:hover { border-color: var(--accent); }

.status {
  font-family: var(--mono); font-size: 10px; font-weight: 700; letter-spacing: 1px;
  padding: 3px 7px; border-radius: var(--radius); border: 1px solid var(--line-2);
  color: var(--muted);
}
.status[data-state="up"]   { color: var(--ok);   border-color: color-mix(in srgb, var(--ok) 55%, transparent); background: color-mix(in srgb, var(--ok) 10%, transparent); }
.status[data-state="down"] { color: var(--bad);  border-color: color-mix(in srgb, var(--bad) 55%, transparent); background: color-mix(in srgb, var(--bad) 10%, transparent); }
.status[data-state="wait"] { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 55%, transparent); }

.badge {
  font-family: var(--mono); font-size: 9px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 1px; padding: 2px 6px; border-radius: 2px; border: 1px solid var(--line-2);
  color: var(--muted);
}
.badge.leader { color: #04121f; background: var(--accent); border-color: var(--accent); }

/* ------------------------------------------------------------ buttons ----- */
button {
  font-family: var(--sans); font-size: 12px; color: var(--fg);
  background: var(--panel-3); border: 1px solid var(--line-2); border-radius: var(--radius);
  padding: 5px 10px; cursor: pointer; transition: background .1s, border-color .1s, color .1s;
}
button:hover { background: #283644; border-color: #44586a; }
button:active { background: #1a242e; }
button.ghost { background: transparent; border-color: var(--line); }
button.ghost:hover { background: var(--panel-2); }
button.active { background: var(--accent); border-color: var(--accent); color: #04121f; font-weight: 700; }
.iconbtn {
  width: 26px; height: 24px; padding: 0; display: inline-flex; align-items: center;
  justify-content: center; font-size: 14px; line-height: 1;
}

/* ----------------------------------------------------------- toolbar ------ */
#toolbar {
  position: fixed; top: var(--header-h); left: 0; right: 0; height: var(--toolbar-h);
  z-index: 999; display: flex; align-items: center; gap: 8px; padding: 0 10px;
  background: var(--panel); border-bottom: 1px solid var(--line);
}
.tb-group { display: flex; align-items: center; gap: 5px; }
.tb-label {
  font-family: var(--mono); font-size: 9px; letter-spacing: 1.5px; color: var(--muted);
  padding-right: 3px;
}
.tb-sep { width: 1px; height: 20px; background: var(--line); margin: 0 2px; }
.tool { height: 26px; padding: 0 11px; }
.tool.emergency {
  border-color: color-mix(in srgb, var(--bad) 60%, transparent); color: var(--bad);
  font-weight: 800; letter-spacing: 1px; background: color-mix(in srgb, var(--bad) 8%, transparent);
}
.tool.emergency:hover { background: color-mix(in srgb, var(--bad) 18%, transparent); }
.tool.emergency.arming { background: var(--bad); color: #fff; animation: emflash .4s steps(1) infinite; }

/* -------------------------------------------------------------- rail ------ */
#rail {
  position: fixed; top: var(--top-h); left: 0; bottom: 0; width: var(--rail-w); z-index: 800;
  background: var(--panel); border-right: 1px solid var(--line);
  display: flex; flex-direction: column;
}
.rail-head {
  padding: 9px 12px; font-weight: 700; letter-spacing: 1.5px; font-size: 11px;
  color: var(--fg-dim); border-bottom: 1px solid var(--line);
  display: flex; justify-content: space-between; align-items: center;
  background: var(--panel-2);
}
.count {
  color: var(--fg); font-family: var(--mono); background: var(--panel-3);
  border: 1px solid var(--line-2); border-radius: 8px; padding: 0 7px; font-size: 11px;
}
#perstat-ctl { padding: 6px 10px; border-bottom: 1px solid var(--line); background: var(--bg-2); }
.perstat-row { display: flex; gap: 5px; align-items: center; }
.perstat-row button { width: 26px; height: 24px; padding: 0; font-family: var(--mono); font-weight: 700; }
.perstat-row button[data-s="green"] { color: var(--ok); }
.perstat-row button[data-s="amber"] { color: var(--warn); }
.perstat-row button[data-s="red"]   { color: var(--bad); }
.perstat-row button[data-s="green"]:hover { background: var(--ok); color: #04121f; }
.perstat-row button[data-s="amber"]:hover { background: var(--warn); color: #04121f; }
.perstat-row button[data-s="red"]:hover   { background: var(--bad); color: #fff; }
.perstat-row #roster-sort { width: auto; margin-left: auto; height: 24px; padding: 0 4px; font-size: 11px; }

#contacts { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
#contacts li {
  padding: 8px 12px; border-bottom: 1px solid var(--line); cursor: pointer;
  display: flex; align-items: center; gap: 9px; border-left: 2px solid transparent;
}
#contacts li:hover { background: var(--panel-2); border-left-color: var(--accent); }
.dot { width: 9px; height: 9px; border-radius: 50%; flex: none; box-shadow: 0 0 0 1px #0006, 0 0 5px currentColor; }
.cs { font-family: var(--mono); font-size: 12px; font-weight: 600; }
.age { margin-left: auto; color: var(--muted); font-family: var(--mono); font-size: 11px; }
.sub { color: var(--muted); font-size: 11px; }

/* -------------------------------------------------------------- map ------- */
#map { position: fixed; top: var(--top-h); left: var(--rail-w); right: 0; bottom: 0; background: #05080b; }
.leaflet-container { background: #05080b; font-family: var(--sans); }
.leaflet-control-zoom a {
  background: var(--panel-2) !important; color: var(--fg) !important;
  border-color: var(--line) !important;
}
.leaflet-control-zoom a:hover { background: var(--panel-3) !important; }
.leaflet-control-attribution {
  background: rgba(10,13,17,.7) !important; color: var(--muted) !important;
}
.leaflet-control-attribution a { color: var(--fg-dim) !important; }

/* draw toolbar (Point / Line / Polygon / Radius) */
#draw-toolbar {
  position: fixed; top: calc(var(--top-h) + 6px); left: calc(var(--rail-w) + 8px);
  z-index: 1200; width: 150px; background: var(--panel); border: 1px solid var(--line-2);
  border-radius: var(--radius); padding: 6px; display: flex; flex-direction: column; gap: 3px;
  box-shadow: 0 8px 24px #000a;
}
#draw-toolbar .draw-title {
  font-family: var(--mono); font-size: 9px; letter-spacing: 1.5px; color: var(--muted);
  padding: 3px 4px 4px;
}
#draw-toolbar button {
  display: flex; align-items: center; gap: 10px; justify-content: flex-start;
  background: transparent; border-color: transparent; text-align: left; padding: 7px 8px;
}
#draw-toolbar button:hover { background: var(--panel-3); border-color: var(--line-2); }
#draw-toolbar button.active { background: var(--accent-2); border-color: var(--accent); }
#draw-toolbar .g-ico {
  font-family: var(--mono); width: 16px; text-align: center; color: var(--accent); font-size: 14px;
}

/* floating End/Cancel control while drawing */
#draw-ctl {
  position: fixed; bottom: 16px; left: calc(var(--rail-w) + 50%); transform: translateX(-50%);
  z-index: 1250; display: flex; align-items: center; gap: 9px; padding: 7px 11px;
  background: var(--panel); border: 1px solid var(--line-2); border-radius: var(--radius);
  box-shadow: 0 8px 28px #000b;
}
#draw-ctl .dc-hint { font-family: var(--mono); font-size: 11px; color: var(--fg-dim); min-width: 64px; }
#draw-ctl button { height: 26px; padding: 0 12px; }
#draw-ctl button:disabled { opacity: .45; cursor: not-allowed; }

/* marker form: color swatches + icon grid + geofence toggle */
.swatch-row { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.swatch-row .swatch {
  width: 22px; height: 22px; border-radius: var(--radius); border: 2px solid #0008;
  padding: 0; cursor: pointer; flex: none;
}
.swatch-row .swatch.sel { border-color: #fff; box-shadow: 0 0 0 2px var(--accent); }
.swatch-row .swatch-custom { width: 26px; height: 24px; padding: 0; border: 1px solid var(--line-2); background: var(--bg-2); cursor: pointer; }
.icon-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 5px; }
.icon-grid .icon-cell {
  aspect-ratio: 1; padding: 4px; display: flex; align-items: center; justify-content: center;
  background: var(--bg-2); border: 1px solid var(--line-2);
}
.icon-grid .icon-cell:hover { border-color: var(--line-2); background: var(--panel-3); }
.icon-grid .icon-cell.sel { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.icon-grid .ic { display: block; width: 100%; color: var(--fg-dim); }
.icon-grid .ic svg { width: 100%; height: 100%; display: block; }
.check-row { display: flex; align-items: center; gap: 8px; text-transform: none !important;
  letter-spacing: 0 !important; font-size: 12px !important; color: var(--fg) !important; cursor: pointer; }
.check-row input { width: auto; }

/* point markers rendered as tinted SVG glyphs */
.oa-icon { width: 22px; height: 22px; filter: drop-shadow(0 0 2px #000) drop-shadow(0 0 2px #000); }
.oa-icon svg { width: 100%; height: 100%; display: block; }

/* divicon markers */
.oa-marker { width: 13px; height: 13px; border-radius: 50%; border: 2px solid #05080b; box-shadow: 0 0 0 1px #fff7, 0 0 6px currentColor; }
.oa-self { width: 15px; height: 15px; border-radius: 50%; border: 3px solid #fff; box-shadow: 0 0 10px var(--accent); }
.oa-emergency { width: 22px; height: 22px; border-radius: 50%; background: var(--bad); border: 3px solid #fff; box-shadow: 0 0 14px var(--bad); animation: emflash .7s steps(1) infinite; }
.oa-label {
  position: absolute; left: 17px; top: -2px; white-space: nowrap;
  font-family: var(--mono); font-size: 11px; font-weight: 600; color: #fff;
  text-shadow: 0 0 3px #000, 0 0 3px #000, 0 0 3px #000; pointer-events: none;
}

/* ------------------------------------------------------- comms flyout ----- */
.flyout-tab {
  position: fixed; right: 0; top: calc(var(--top-h) + 44px); z-index: 901;
  width: 24px; height: 92px; padding: 0; border-right: none;
  border-radius: var(--radius) 0 0 var(--radius); background: var(--panel-2);
  display: flex; align-items: center; justify-content: center;
}
.flyout-tab .ft-ico { writing-mode: vertical-rl; letter-spacing: 3px; font-size: 11px; color: var(--fg-dim); }
.flyout-tab:hover { background: var(--panel-3); }
body.flyout-open .flyout-tab { display: none; }

#flyout {
  position: fixed; top: var(--top-h); right: 0; bottom: 0; width: 360px; z-index: 902;
  background: var(--panel); border-left: 1px solid var(--line-2);
  display: flex; flex-direction: column; box-shadow: -8px 0 28px #0009;
}
.fly-head {
  display: flex; align-items: center; gap: 8px; padding: 8px 10px;
  font-weight: 700; letter-spacing: 1.5px; font-size: 11px; color: var(--fg-dim);
  border-bottom: 1px solid var(--line); background: var(--panel-2);
}
.fly-panel { display: flex; flex-direction: column; border-bottom: 1px solid var(--line); min-height: 0; }
.fly-panel:not(.collapsed) { flex: 1 1 auto; }
.fly-panel.collapsed { flex: 0 0 auto; }
.fly-panel-head {
  display: flex; align-items: center; gap: 7px; padding: 8px 10px; cursor: pointer;
  background: var(--panel-2); user-select: none;
}
.fly-panel-head:hover { background: var(--panel-3); }
.fp-title { font-weight: 700; letter-spacing: 1.5px; font-size: 11px; color: var(--fg-dim); }
.fp-caret { color: var(--muted); transition: transform .15s; }
.fly-panel.collapsed .fp-caret { transform: rotate(-90deg); }
.fly-panel.collapsed .fly-panel-body { display: none; }
.fly-panel-body { display: flex; flex-direction: column; min-height: 0; overflow: hidden; flex: 1; }

#chat-channel-sel { width: auto; min-width: 84px; height: 22px; padding: 0 6px; font-size: 11px; }
#chat-log { list-style: none; margin: 0; padding: 8px; overflow-y: auto; flex: 1; }
#chat-log li { padding: 4px 4px; border-bottom: 1px solid #ffffff07; line-height: 1.45; }
#chat-log .who { color: var(--accent); font-family: var(--mono); font-weight: 600; }
#chat-log .ts { color: var(--muted); font-size: 10px; float: right; font-family: var(--mono); }
#chat-log .chat-att { display: block; margin-top: 4px; }
#chat-log .chat-att img { max-width: 180px; max-height: 130px; border: 1px solid var(--line); border-radius: 2px; display: block; }
#chat-log .chat-att.file { font-size: 11px; color: var(--accent); }
.chat-attach-row { display: flex; align-items: center; gap: 6px; padding: 4px 8px; border-top: 1px solid var(--line); }
.chat-attach-row #chat-attach-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#chat-form { display: flex; gap: 6px; padding: 8px; border-top: 1px solid var(--line); }
#chat-form #chat-input { flex: 1; }

/* attachments panel */
.attach-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; padding: 8px; overflow-y: auto; }
.attach-cell { position: relative; aspect-ratio: 1; border: 1px solid var(--line-2); background: var(--bg-2); overflow: hidden; cursor: pointer; display: flex; align-items: center; justify-content: center; }
.attach-cell img { width: 100%; height: 100%; object-fit: cover; }
.attach-cell .att-file { font-size: 10px; color: var(--fg-dim); padding: 4px; text-align: center; word-break: break-all; }
.attach-cell .att-src { position: absolute; top: 2px; left: 2px; font-size: 13px; text-shadow: 0 0 3px #000; }
.attach-grid .muted { grid-column: 1 / -1; padding: 12px; text-align: center; }

/* tasks panel */
.seg { display: flex; gap: 0; padding: 8px; }
.seg button { flex: 1; border-radius: 0; border-right-width: 0; font-size: 11px; padding: 5px 0; }
.seg button:first-child { border-radius: var(--radius) 0 0 var(--radius); }
.seg button:last-child { border-radius: 0 var(--radius) var(--radius) 0; border-right-width: 1px; }
#task-list { overflow-y: auto; flex: 1; padding: 0 8px; }
.task-card { border: 1px solid var(--line); border-left-width: 3px; border-radius: var(--radius); padding: 7px 9px; margin-bottom: 6px; background: var(--panel-2); }
.task-card.mine { border-left-color: var(--accent); }
.task-card.complete { opacity: .6; }
.task-card .t-title { font-weight: 600; }
.task-card .t-meta { font-size: 11px; color: var(--muted); margin-top: 2px; }
.task-card .t-actions { display: flex; gap: 5px; margin-top: 6px; flex-wrap: wrap; }
.task-card .t-actions button { padding: 3px 8px; font-size: 11px; }
button.full { width: 100%; margin: 8px; width: calc(100% - 16px); }

/* ----------------------------------------------------------- inputs ------- */
input, select, textarea {
  font-family: var(--sans); font-size: 13px; color: var(--fg);
  background: var(--bg-2); border: 1px solid var(--line-2); border-radius: var(--radius);
  padding: 6px 8px; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
select {
  appearance: none; -webkit-appearance: none; cursor: pointer; padding-right: 22px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath fill='%2369788a' d='M0 0l5 6 5-6z'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 7px center;
}

/* ---------------------------------------------------------- overlays ------ */
.overlay {
  position: fixed; inset: 0; z-index: 2000; background: rgba(3,6,9,.72);
  backdrop-filter: blur(2px); display: flex; align-items: center; justify-content: center;
}
.overlay .panel {
  background: var(--panel); border: 1px solid var(--line-2); border-radius: var(--radius);
  padding: 20px; width: 340px; max-width: 92vw; max-height: 88vh; overflow-y: auto;
  display: flex; flex-direction: column; gap: 8px; box-shadow: 0 16px 48px #000c;
}

/* login ------------------------------------------------------------------- */
#login-form { width: 360px; padding: 26px 24px; gap: 16px; }
.login-brand { display: flex; flex-direction: column; gap: 4px; align-items: center; }
.login-brand h1 { margin: 0; }
.login-brand .muted { margin: 0; }
.login-step { display: flex; flex-direction: column; gap: 9px; }
.login-step label { margin: 0; }      /* uniform gap handles all spacing */
.login-step input { padding: 10px 12px; }
.login-step .row { margin-top: 2px; }
#login-request, #login-verify { width: 100%; padding: 11px; font-weight: 600; font-size: 13px; }
#login-code { letter-spacing: 6px; text-align: center; font-family: var(--mono); font-size: 16px; }
#login-msg { margin: 2px 0 0; min-height: 15px; text-align: center; }
.panel h1 { margin: 0; letter-spacing: 4px; color: var(--accent); font-size: 26px; text-align: center; }
.panel h2 { margin: 2px 0 4px; font-size: 15px; letter-spacing: .5px; border-bottom: 1px solid var(--line); padding-bottom: 5px; }
.panel label { font-size: 10px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); margin-top: 5px; }
.panel .row { display: flex; gap: 8px; margin-top: 8px; }
.panel .row button { flex: 1; padding: 7px 10px; }

/* admin dashboard */
.panel.wide { width: 720px; max-width: 94vw; }
.adm-head { display: flex; align-items: center; gap: 10px; }
.adm-head h2 { border: none; margin: 0; padding: 0; }
.adm-tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin: 8px 0; }
.adm-tab { background: transparent; border: 1px solid transparent; border-bottom: none;
  border-radius: var(--radius) var(--radius) 0 0; padding: 6px 14px; color: var(--muted); }
.adm-tab.active { background: var(--panel-2); border-color: var(--line); color: var(--fg); }
#adm-body .op-roster tr.inactive { opacity: .5; }
#adm-body { max-height: 60vh; overflow-y: auto; }
.set-row { display: flex; align-items: center; gap: 10px; padding: 5px 0; }
.set-row label { flex: 1; margin: 0; text-transform: none; letter-spacing: 0; font-size: 12px; color: var(--fg); }
.set-row input, .set-row select { width: 160px; }

/* generic ask() modal sits above other overlays (e.g. the op/manage modal) */
#ask { z-index: 2600; }
#ask-panel .ask-note { margin: 0; color: var(--fg-dim); font-size: 13px; }
#ask-panel h2 { border-bottom: none; padding-bottom: 0; }

/* roster / list tables in modals */
.op-roster { width: 100%; border-collapse: collapse; margin: 4px 0; }
.op-roster th, .op-roster td { text-align: left; padding: 6px 7px; border-bottom: 1px solid var(--line); font-size: 12px; vertical-align: top; }
.op-roster th { color: var(--muted); font-size: 10px; text-transform: uppercase; letter-spacing: 1px; }
.op-roster .cs { font-family: var(--mono); }
.op-roster button { padding: 3px 7px; font-size: 11px; margin: 1px; }

/* leaflet popups */
.leaflet-popup-content-wrapper, .leaflet-popup-tip { background: var(--panel-2); color: var(--fg); border: 1px solid var(--line-2); }
.leaflet-popup-content-wrapper { border-radius: var(--radius); }
.leaflet-popup-content { font-family: var(--sans); font-size: 12px; margin: 10px 12px; }
.leaflet-popup-content b { font-family: var(--mono); color: var(--fg); }
.popup-actions { margin-top: 8px; display: flex; gap: 6px; }
.popup-actions button { padding: 3px 8px; font-size: 11px; }

/* -------------------------------------------------------- toasts/banners -- */
#toasts {
  position: fixed; top: calc(var(--top-h) + 8px); right: 14px; z-index: 3000;
  display: flex; flex-direction: column; gap: 7px; max-width: 320px;
}
.toast {
  background: var(--panel-2); border: 1px solid var(--line-2); border-left-width: 3px;
  border-radius: var(--radius); padding: 9px 11px; font-size: 12px; color: var(--fg);
  box-shadow: 0 4px 14px #000a; animation: toastin .14s ease-out; cursor: pointer;
}
.toast .t-title { font-weight: 700; letter-spacing: .5px; margin-bottom: 1px; }
.toast.info { border-left-color: var(--accent); }
.toast.ok   { border-left-color: var(--ok); }
.toast.warn { border-left-color: var(--warn); }
.toast.bad  { border-left-color: var(--bad); }
.toast.high { border-left-color: var(--warn); background: #241d0c; }
@keyframes toastin { from { opacity: 0; transform: translateX(16px); } }

#emergency-banner {
  position: fixed; top: 0; left: 0; right: 0; z-index: 3500; min-height: var(--header-h);
  display: flex; align-items: center; justify-content: center; gap: 16px; padding: 4px 12px;
  font-weight: 800; letter-spacing: 1.5px; color: #fff; background: var(--bad);
  animation: emflash 1s steps(1) infinite; box-shadow: 0 2px 14px #000a;
}
#emergency-banner button { background: #0007; border-color: #fff8; color: #fff; }
@keyframes emflash { 50% { background: #7f1d1d; } }

#timer-banner {
  position: fixed; top: var(--top-h); left: var(--rail-w); right: 0; z-index: 700; height: 26px;
  display: flex; align-items: center; justify-content: center; gap: 10px;
  background: var(--panel-3); border-bottom: 1px solid var(--line);
  font-family: var(--mono); font-size: 12px; font-weight: 700; letter-spacing: 1px; color: var(--fg);
}
#timer-banner.urgent { background: var(--bad); color: #fff; animation: emflash .8s steps(1) infinite; }

/* playback scrubber */
#playback-bar {
  position: fixed; bottom: 14px; left: calc(var(--rail-w) + 50%); transform: translateX(-50%);
  z-index: 950; display: flex; align-items: center; gap: 10px; padding: 7px 12px;
  background: var(--panel); border: 1px solid var(--line-2); border-radius: var(--radius);
  box-shadow: 0 8px 28px #000b; width: min(560px, calc(100vw - var(--rail-w) - 40px));
}
#playback-bar #pb-play { width: 30px; height: 28px; padding: 0; font-size: 13px; }
#playback-bar #pb-slider { flex: 1; accent-color: var(--accent); cursor: pointer; }
#playback-bar #pb-time { flex: 0 0 auto; }
#playback-bar #pb-speed { width: auto; height: 26px; padding: 0 22px 0 8px; }
@media (max-width: 640px) { #playback-bar { left: 50%; width: calc(100vw - 24px); } }

/* ---------------------------------------------------------- responsive ---- */
.mobile-only { display: none; }
#rail-backdrop, #flyout-backdrop {
  display: none; position: fixed; inset: var(--top-h) 0 0 0; z-index: 1400;
  background: rgba(3, 6, 9, .55);
}

/* Tablet: narrow the rail and flyout a little. */
@media (max-width: 1024px) {
  :root { --rail-w: 200px; }
  #flyout { width: 320px; }
}

/* Phone / small tablet: rail + flyout become slide-over overlays; the map is
   dominant; the top bar condenses; the draw toolbar floats over the map. */
@media (max-width: 820px) {
  :root { --rail-w: 0px; }
  .mobile-only { display: inline-flex; }

  #map, #timer-banner { left: 0; }
  #draw-toolbar { left: 8px; }
  #draw-ctl { left: 50%; }
  #playback-bar { left: 50%; width: calc(100vw - 24px); }

  /* off-canvas roster drawer (slides from the left) */
  #rail {
    width: min(82vw, 300px); transform: translateX(-100%);
    transition: transform .2s ease; z-index: 1500; box-shadow: 3px 0 24px #000b;
  }
  body.rail-open #rail { transform: none; }
  body.rail-open #rail-backdrop { display: block; }

  /* comms flyout becomes a right-side slide-over overlay */
  #flyout {
    width: min(90vw, 380px); transform: translateX(100%);
    transition: transform .2s ease; z-index: 1500;
  }
  #flyout.hidden { display: flex !important; }   /* keep it mounted, just slid out */
  body.flyout-open #flyout { transform: none; }
  body.flyout-open #flyout-backdrop { display: block; }
  .flyout-tab { top: auto; bottom: 16px; }       /* easier thumb reach */

  /* header compaction */
  #topbar { gap: 8px; padding: 0 8px; }
  .brand-sub, .clock { display: none; }
  .brand { font-size: 14px; letter-spacing: 2px; }
  #op-switcher { min-width: 84px; max-width: 130px; }
  .me { max-width: 92px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

  /* toolbar scrolls horizontally; labels/separators drop out */
  #toolbar { overflow-x: auto; overflow-y: hidden; gap: 6px; padding: 0 8px; scrollbar-width: none; }
  #toolbar::-webkit-scrollbar { display: none; }
  #toolbar .tb-label, #toolbar .tb-sep { display: none; }
  #toolbar .spacer { flex: 0 0 2px; }
  #toolbar .tool { flex: 0 0 auto; }

  #toasts { max-width: calc(100vw - 24px); right: 12px; }
  #login-form { padding: 22px 18px; }
}

/* Coarse-pointer (touch) niceties regardless of width. */
@media (pointer: coarse) {
  button, .tool { min-height: 30px; }
  #contacts li { padding: 11px 12px; }
}
