/* AFS K9 CAD — locked one-screen layout, 5 appearance modes via CSS vars. */
:root, [data-theme="day"] {
  --bg: #edf0f4; --panel: #ffffff; --panel2: #f4f6f9; --line: #c9d2dc;
  --text: #16222e; --dim: #5b6b7a; --accent: #0b5cad; --accent-t: #ffffff;
  --gold: #9a7200; --red: #c22730; --green: #1d7a3a; --amber: #a86a00;
  --amber-bg: #fdf3d7; --input-bg: #ffffff; --shadow: rgba(20,40,60,.18);
}
[data-theme="midnight"] {
  --bg: #050b1a; --panel: #0c1a33; --panel2: #102344; --line: #274268;
  --text: #dce9ff; --dim: #8fb0dd; --accent: #3d7bfd; --accent-t: #ffffff;
  --gold: #f0b429; --red: #ff5a5f; --green: #3fce74; --amber: #ffb02e;
  --amber-bg: #3a2c07; --input-bg: #0a1730; --shadow: rgba(0,0,0,.5);
}
[data-theme="tactical"] {
  --bg: #12050a; --panel: #200810; --panel2: #2c0d18; --line: #57202e;
  --text: #ffdadd; --dim: #d18b93; --accent: #e5484d; --accent-t: #ffffff;
  --gold: #f0b429; --red: #ff6b6f; --green: #53d769; --amber: #ffb02e;
  --amber-bg: #3a2c07; --input-bg: #1a060d; --shadow: rgba(0,0,0,.5);
}
[data-theme="green"] {
  --bg: #020d05; --panel: #06230f; --panel2: #093016; --line: #1d5230;
  --text: #ccffdb; --dim: #7ecb97; --accent: #2fbf5a; --accent-t: #03150a;
  --gold: #ffe066; --red: #ff7a59; --green: #4dff88; --amber: #ffd43b;
  --amber-bg: #2f2a05; --input-bg: #041a09; --shadow: rgba(0,0,0,.5);
}
[data-theme="charcoal"] {
  --bg: #141518; --panel: #212326; --panel2: #2a2c2f; --line: #414449;
  --text: #e9eaec; --dim: #a2a8ae; --accent: #8fa3b8; --accent-t: #141518;
  --gold: #f0b429; --red: #ff5a5f; --green: #3fce74; --amber: #ffb02e;
  --amber-bg: #38300f; --input-bg: #191b1d; --shadow: rgba(0,0,0,.5);
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--text); overflow: hidden;
  font-size: 15px;
}
.hidden { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
input, select, textarea {
  background: var(--input-bg); border: 1px solid var(--line); border-radius: 6px;
  padding: 7px 9px; width: 100%;
}
textarea { resize: vertical; }
label { display: block; margin: 8px 0; font-size: .85rem; color: var(--dim); }
label input, label textarea, label select { margin-top: 3px; color: var(--text); }
h2 { font-size: 1.1rem; margin: 0; }
h3 { margin: .4em 0; }
.hint { color: var(--dim); font-size: .82rem; }
.error { color: var(--red); font-size: .9rem; }
a { color: var(--accent); }

/* ---------- buttons ---------- */
.btn {
  background: var(--panel2); border: 1px solid var(--line); border-radius: 6px;
  padding: 7px 13px; cursor: pointer; white-space: nowrap;
}
.btn:hover { border-color: var(--accent); }
.btn-primary { background: var(--accent); color: var(--accent-t); border-color: var(--accent); }
.btn-danger { background: var(--red); color: #fff; border-color: var(--red); }
.btn-ghost { background: transparent; }
.btn-big { width: 100%; padding: 12px; font-size: 1.05rem; margin-top: 10px; }
.btn-logoff { background: var(--red); color: #fff; border-color: var(--red); font-weight: 700; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.btn-row.right { justify-content: flex-end; margin-top: 12px; }
.btn.small { padding: 3px 9px; font-size: .85rem; }

/* ---------- login ---------- */
.login-wrap { height: 100%; display: flex; align-items: center; justify-content: center; }
.login-card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  padding: 28px 30px; width: min(380px, 92vw); box-shadow: 0 8px 30px var(--shadow);
  text-align: left;
}
.login-card h1 { font-size: 1.35rem; margin: .2em 0; text-align: center; }
.login-sub { text-align: center; color: var(--dim); margin: 0 0 10px; }
.brand-logo { max-height: 54px; max-width: 200px; display: block; margin: 0 auto 6px; }

/* ---------- app frame (locked) ---------- */
#view-app { height: 100%; display: flex; flex-direction: column; }
#topbar {
  display: flex; align-items: center; gap: 14px; padding: 6px 12px;
  background: var(--panel); border-bottom: 2px solid var(--gold); flex: 0 0 auto;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand .brand-logo { margin: 0; max-height: 40px; }
#brand-title { font-weight: 800; font-size: 1.12rem; line-height: 1.1; white-space: nowrap; }
#brand-subtitle { color: var(--gold); font-size: .82rem; white-space: nowrap; }
#top-status { flex: 1 1 auto; display: flex; gap: 10px; justify-content: center; align-items: center; }
.top-status-btn {
  font-size: 1.15rem; font-weight: 700; padding: 12px 22px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--panel2); cursor: pointer;
}
.top-status-btn.enroute { background: #b97d10; color: #fff; }
.top-status-btn.onscene { background: var(--green); color: #fff; }
.top-status-btn.clear { background: var(--red); color: #fff; }
.top-status-btn.avail-on { background: var(--green); color: #fff; }
.top-status-btn.busy-on { background: #b97d10; color: #fff; }
.top-status-label { font-weight: 700; font-size: 1.05rem; }
.top-right { display: flex; align-items: center; gap: 10px; flex: 0 0 auto; }
.clock { font-variant-numeric: tabular-nums; color: var(--dim); font-size: .9rem; }
.me-chip { font-weight: 700; white-space: nowrap; }

#layout { flex: 1 1 auto; display: flex; min-height: 0; }
#rail {
  flex: 0 0 148px; display: flex; flex-direction: column; gap: 4px; padding: 8px 6px;
  background: var(--panel); border-right: 1px solid var(--line); overflow-y: auto;
}
.rail-btn {
  text-align: left; background: transparent; border: 1px solid transparent;
  border-radius: 6px; padding: 10px 9px; cursor: pointer; position: relative; font-weight: 600;
}
.rail-btn:hover { background: var(--panel2); }
.rail-btn.active { background: var(--panel2); border-color: var(--accent); }
.rail-badge {
  background: var(--red); color: #fff; border-radius: 9px; font-size: .72rem;
  padding: 1px 7px; margin-left: 5px; font-weight: 700;
}
@keyframes flashred { 0%,100% { background: transparent; } 50% { background: var(--red); color: #fff; } }
.flash-red { animation: flashred 1s infinite; }
#main { flex: 1 1 auto; min-width: 0; display: flex; }
.screen { flex: 1 1 auto; display: flex; min-height: 0; padding: 10px; }
.panel {
  flex: 1 1 auto; display: flex; flex-direction: column; min-height: 0;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px;
}
.panel.full { width: 100%; }
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 8px; flex-wrap: wrap; }
.scroll-area { flex: 1 1 auto; overflow-y: auto; min-height: 0; }
.dash-grid { flex: 1 1 auto; display: grid; grid-template-columns: 1.25fr 1fr; gap: 10px; min-height: 0; }
.dept-filter { display: flex; gap: 12px; flex-wrap: wrap; padding: 6px 2px; align-items: center; }
.dept-filter label { display: inline-flex; gap: 5px; align-items: center; margin: 0; color: var(--text); }
.dept-filter input { width: auto; }

/* ---------- unit rows ---------- */
.unit-row, .call-row, .conv-row, .bolo-row {
  border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; margin-bottom: 7px;
  background: var(--panel2); cursor: pointer;
}
.unit-row { display: flex; gap: 10px; align-items: flex-start; cursor: pointer; }
.unit-box {
  flex: 0 0 auto; background: var(--accent); color: var(--accent-t); font-weight: 800;
  border-radius: 6px; padding: 6px 8px; min-width: 58px; text-align: center;
}
.unit-name { font-weight: 700; }
.unit-title { color: var(--gold); font-weight: 700; font-size: .85rem; }
.unit-status { color: var(--dim); font-size: .85rem; }
.unit-group { margin: 10px 0 5px; font-weight: 800; color: var(--gold); }
.pinned { border: 2px solid var(--gold); }
.pinned-tag { color: var(--gold); font-weight: 800; font-size: .75rem; text-transform: uppercase; }
.call-title { font-weight: 700; }
.call-meta { color: var(--dim); font-size: .83rem; }
.empty-note { color: var(--dim); padding: 12px 4px; }

/* ---------- call detail ---------- */
.kv { display: grid; grid-template-columns: 130px 1fr; gap: 4px 12px; margin: 8px 0; }
.kv dt { color: var(--dim); } .kv dd { margin: 0; }
.note-row { border-left: 3px solid var(--accent); padding: 4px 9px; margin: 6px 0; background: var(--panel2); border-radius: 0 6px 6px 0; }
.note-meta { color: var(--dim); font-size: .8rem; }
.status-chip { border-radius: 9px; padding: 1px 9px; font-size: .78rem; font-weight: 700; background: var(--panel); border: 1px solid var(--line); }
.status-chip.en_route { background: #b97d10; color: #fff; }
.status-chip.on_scene { background: var(--green); color: #fff; }

/* ---------- messages ---------- */
.conv-row.unread { animation: flashred 1s infinite; }
.conv-row { display: flex; justify-content: space-between; gap: 10px; align-items: center; }
.conv-main { min-width: 0; }
.conv-name { font-weight: 700; }
.conv-last { color: var(--dim); font-size: .85rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 52vw; }
.chat-area { display: flex; flex-direction: column; gap: 6px; }
.msg { max-width: 78%; padding: 7px 11px; border-radius: 10px; background: var(--panel2); border: 1px solid var(--line); align-self: flex-start; }
.msg.mine { align-self: flex-end; background: var(--accent); color: var(--accent-t); }
.msg.alert { border: 2px solid var(--red); }
.msg .msg-meta { font-size: .75rem; opacity: .75; }
.msg .alert-badge { color: var(--red); font-weight: 800; font-size: .75rem; }
.chat-form { display: flex; gap: 8px; align-items: center; margin-top: 8px; }
.chat-form input[type="text"] { flex: 1; }
.alert-check { display: inline-flex; gap: 6px; align-items: center; color: var(--red); font-weight: 700; margin: 0; }
.alert-check input { width: auto; }

/* ---------- bolos ---------- */
.bolo-row { cursor: default; }
.bolo-row.unread { border-color: var(--red); border-width: 2px; }
.bolo-title { font-weight: 800; }
.inline-form { border: 1px solid var(--line); border-radius: 8px; padding: 10px; margin-bottom: 10px; background: var(--panel2); }

/* ---------- map / weather / notepad ---------- */
#map { flex: 1 1 auto; min-height: 0; border-radius: 8px; z-index: 0; }
.map-label { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 4px; padding: 0 5px; font-weight: 700; font-size: .78rem; white-space: nowrap; }
.wx-form { display: flex; gap: 8px; align-items: center; }
.wx-form input { width: 84px; }
.wx-alert { border: 2px solid var(--red); border-radius: 8px; padding: 9px 12px; margin-bottom: 9px; background: var(--panel2); }
.wx-alert h4 { margin: 0 0 4px; color: var(--red); }
.wx-period { border-bottom: 1px solid var(--line); padding: 7px 2px; }
#pad { flex: 1 1 auto; min-height: 0; font-family: ui-monospace, Menlo, monospace; font-size: 1rem; line-height: 1.45; }
.notes-list { display: flex; gap: 7px; flex-wrap: wrap; margin-bottom: 8px; }
.note-chip { display: inline-flex; gap: 6px; align-items: center; background: var(--panel2); border: 1px solid var(--line); border-radius: 14px; padding: 3px 6px 3px 11px; }
.note-chip button { border: none; background: transparent; cursor: pointer; color: var(--red); font-weight: 700; }

/* ---------- modals ---------- */
#modal-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 40; }
.modal { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; z-index: 50; }
.modal-card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  padding: 18px 20px; width: min(520px, 94vw); max-height: 88vh; overflow-y: auto;
  box-shadow: 0 10px 40px var(--shadow);
}
.modal-card h3 { margin-top: 0; }
.form-row { display: flex; gap: 10px; align-items: end; }
.form-row label { flex: 1; }

/* ---------- type-ahead combo ---------- */
.combo { position: relative; }
.combo-list {
  position: absolute; left: 0; right: 0; top: 100%; z-index: 60; max-height: 210px; overflow-y: auto;
  background: var(--panel); border: 1px solid var(--accent); border-radius: 6px; box-shadow: 0 8px 24px var(--shadow);
}
.combo-item { padding: 8px 10px; cursor: pointer; }
.combo-item:hover, .combo-item.active { background: var(--panel2); }

/* ---------- admin ---------- */
.admin-h { margin-top: 22px; border-top: 2px solid var(--gold); padding-top: 12px; }
.admin-nav { margin-bottom: 12px; }
table.grid { width: 100%; border-collapse: collapse; font-size: .9rem; }
table.grid th, table.grid td { border-bottom: 1px solid var(--line); padding: 6px 8px; text-align: left; vertical-align: top; }
table.grid th { color: var(--dim); }
.warn-amber { background: var(--amber-bg); color: var(--amber); border: 1px solid var(--amber); border-radius: 6px; padding: 4px 9px; font-weight: 700; font-size: .85rem; display: inline-block; }
.settings-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 14px; }
.settings-card { border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; background: var(--panel2); }
.switch-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin: 8px 0; }
.switch-row input { width: auto; transform: scale(1.25); }
.list-editor { border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; margin-bottom: 12px; background: var(--panel2); }
.list-items { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }
.list-item { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 2px 6px 2px 10px; display: inline-flex; gap: 6px; align-items: center; }
.list-item button { border: none; background: transparent; cursor: pointer; color: var(--red); font-weight: 700; }

/* ---------- toasts ---------- */
#toasts { position: fixed; right: 14px; bottom: 14px; z-index: 80; display: flex; flex-direction: column; gap: 8px; }
.toast { background: var(--panel); border: 1px solid var(--accent); border-left: 5px solid var(--accent); border-radius: 8px; padding: 9px 13px; box-shadow: 0 6px 20px var(--shadow); max-width: 340px; }
.toast.error { border-color: var(--red); border-left-color: var(--red); }

@media (max-width: 900px) {
  .dash-grid { grid-template-columns: 1fr; }
  #rail { flex-basis: 104px; }
  .top-status-btn { padding: 10px 12px; font-size: 1rem; }
  #brand-subtitle { display: none; }
}
