:root {
  --bg: #0b1222;
  --panel: #121c33;
  --panel-2: #18243f;
  --line: #26365a;
  --text: #e6ecf7;
  --muted: #93a3c4;
  --accent: #4c8dff;
  --in: #3fb6ff;
  --out: #f5b82e;
  --gtg: #2fd27a;
  --fmc: #2fd27a;
  --nmc: #ff5a5f;
  --overdue: #ff7a1a;
  --radius: 12px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--accent); }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0 0 .5rem; line-height: 1.2; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.05rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.hidden { display: none !important; }

/* ---------- layout ---------- */
header.top {
  position: sticky; top: 0; z-index: 1000;
  display: flex; align-items: center; gap: .75rem; padding: .6rem 1rem;
  background: rgba(11, 18, 34, .95); backdrop-filter: blur(6px); border-bottom: 1px solid var(--line);
}
header.top .brand { display: flex; align-items: center; gap: .5rem; font-weight: 700; text-decoration: none; color: var(--text); }
header.top .brand svg { width: 28px; height: 28px; }
header.top .spacer { flex: 1; }
header.top .who { color: var(--muted); font-size: .85rem; }
main { max-width: 1200px; margin: 0 auto; padding: 1rem; }

nav.tabs { display: flex; gap: .35rem; overflow-x: auto; padding: .25rem 0 .75rem; scrollbar-width: thin; }
nav.tabs a {
  flex: none; padding: .45rem .85rem; border-radius: 999px; border: 1px solid var(--line);
  color: var(--muted); text-decoration: none; font-weight: 600; font-size: .9rem; background: var(--panel);
}
nav.tabs a.active { background: var(--accent); border-color: var(--accent); color: #fff; }
nav.tabs .sep { flex: none; width: 1px; background: var(--line); margin: 0 .25rem; }

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: .6rem; margin-bottom: 1rem; }
.tile {
  display: flex; flex-direction: column; gap: .2rem; padding: .8rem 1rem; border-radius: var(--radius);
  background: var(--panel); border: 1px solid var(--line); text-decoration: none; color: var(--text);
  border-left: 4px solid var(--c, var(--accent));
}
.tile:hover { background: var(--panel-2); }
.tile.active { outline: 2px solid var(--c, var(--accent)); }
.tile .label { font-size: .8rem; color: var(--muted); font-weight: 600; letter-spacing: .02em; }
.tile .num { font-size: 1.6rem; font-weight: 800; color: var(--c, var(--text)); }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; margin-bottom: 1rem; }
.toolbar { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin-bottom: .75rem; }
.toolbar input[type=search] { flex: 1 1 220px; }

/* ---------- controls ---------- */
input, select, textarea {
  background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: .55rem .7rem; min-height: 42px; width: 100%;
}
textarea { min-height: 80px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: var(--accent); }
.toolbar select, .toolbar input { width: auto; }
label.field, div.field { display: block; font-size: .85rem; font-weight: 600; color: var(--muted); }
label.field > input, label.field > select, label.field > textarea, div.field > .seg { margin-top: .3rem; }
label.field > .small, div.field > .seg { display: block; width: max-content; }
label.field > .small { width: auto; margin-top: .25rem; font-weight: 400; }
label.field .req { color: var(--nmc); }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: .75rem; }
.grid .wide { grid-column: 1 / -1; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem; min-height: 42px;
  padding: .5rem 1rem; border-radius: 8px; border: 1px solid var(--line); background: var(--panel-2);
  font-weight: 600; cursor: pointer; text-decoration: none; color: var(--text); white-space: nowrap;
}
.btn:hover { filter: brightness(1.15); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.out { background: var(--out); border-color: var(--out); color: #1a1300; }
.btn.in { background: var(--in); border-color: var(--in); color: #001827; }
.btn.danger { background: transparent; border-color: var(--nmc); color: var(--nmc); }
.btn.big { min-height: 64px; font-size: 1.15rem; flex: 1; }
.btn.sm { min-height: 32px; padding: .25rem .6rem; font-size: .85rem; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg label { display: flex; align-items: center; gap: .35rem; padding: .55rem 1rem; cursor: pointer; font-weight: 700; }
.seg input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.seg label:has(input:checked) { background: var(--c); color: #04110a; }
.seg label:has(input:focus-visible) { outline: 2px solid var(--accent); }

/* ---------- badges ---------- */
.badge { display: inline-block; padding: .1rem .5rem; border-radius: 999px; font-size: .75rem; font-weight: 800; letter-spacing: .03em; border: 1px solid; }
.badge.IN { color: var(--in); border-color: var(--in); }
.badge.OUT { color: var(--out); border-color: var(--out); }
.badge.FMC { color: var(--fmc); border-color: var(--fmc); }
.badge.NMC { color: var(--nmc); border-color: var(--nmc); background: rgba(255, 90, 95, .12); }
.badge.GTG { color: #04110a; background: var(--gtg); border-color: var(--gtg); }
.badge.OVERDUE { color: #fff; background: var(--overdue); border-color: var(--overdue); }
.badge.RETIRED { color: var(--muted); border-color: var(--muted); }

/* ---------- equipment list ---------- */
.list { display: flex; flex-direction: column; gap: .5rem; }
.row {
  display: grid; grid-template-columns: 1fr auto; gap: .25rem 1rem; padding: .75rem 1rem; border-radius: 10px;
  background: var(--panel-2); border: 1px solid var(--line); text-decoration: none; color: var(--text);
}
.row:hover { border-color: var(--accent); }
.row.overdue { border-left: 4px solid var(--overdue); }
.row .title { font-weight: 700; }
.row .meta { color: var(--muted); font-size: .85rem; display: flex; flex-wrap: wrap; gap: .25rem .9rem; }
.row .badges { display: flex; gap: .3rem; align-items: start; justify-content: end; flex-wrap: wrap; }
.empty { text-align: center; color: var(--muted); padding: 2rem 1rem; }

table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { text-align: left; padding: .5rem .6rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; }
tr.click { cursor: pointer; }
tr.click:hover td { background: var(--panel-2); }
.table-wrap { overflow-x: auto; }

/* ---------- detail ---------- */
.detail-head { display: flex; flex-wrap: wrap; gap: 1rem; align-items: start; justify-content: space-between; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: .35rem 1rem; }
.kv dt { color: var(--muted); font-size: .85rem; }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.qr { background: #fff; padding: 8px; border-radius: 8px; width: 150px; }
.qr img { display: block; width: 100%; }
.actions { display: flex; gap: .6rem; flex-wrap: wrap; margin: 1rem 0; }
.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { padding: .55rem 0; border-bottom: 1px solid var(--line); display: grid; grid-template-columns: auto 1fr; gap: .2rem .75rem; }
.timeline .when { color: var(--muted); font-size: .8rem; white-space: nowrap; }
.ev { font-size: .7rem; font-weight: 800; padding: .05rem .4rem; border-radius: 4px; background: var(--line); }
.ev.SIGN_OUT { background: var(--out); color: #1a1300; }
.ev.SIGN_IN { background: var(--in); color: #001827; }
.ev.STATUS { background: #8b5cf6; color: #fff; }
.ev.RETIRED, .ev.DELETED { background: var(--nmc); color: #fff; }
.ev.ADDED, .ev.RESTORED { background: var(--gtg); color: #04110a; }

/* ---------- alerts / toast ---------- */
.alert { padding: .7rem 1rem; border-radius: 8px; margin-bottom: .75rem; border: 1px solid; }
.alert.error { border-color: var(--nmc); background: rgba(255, 90, 95, .1); color: #ffb3b5; }
.alert.warn { border-color: var(--out); background: rgba(245, 184, 46, .1); color: #ffe2a0; }
.alert.ok { border-color: var(--gtg); background: rgba(47, 210, 122, .1); color: #b4f5d0; }
#toast {
  position: fixed; left: 50%; bottom: 1.25rem; transform: translateX(-50%); z-index: 2000;
  padding: .75rem 1.1rem; border-radius: 10px; background: var(--gtg); color: #04110a; font-weight: 700;
  box-shadow: 0 8px 30px rgba(0, 0, 0, .4); max-width: 90vw;
}
#toast.error { background: var(--nmc); color: #fff; }

/* ---------- login ---------- */
.login { max-width: 380px; margin: 10vh auto; }
.login .brand-big { display: flex; flex-direction: column; align-items: center; gap: .5rem; margin-bottom: 1.25rem; text-align: center; }
.login .brand-big svg { width: 64px; height: 64px; }

/* ---------- map ---------- */
#map, .mini-map { height: 65vh; min-height: 360px; border-radius: var(--radius); border: 1px solid var(--line); background: #0e1730; }
.mini-map { height: 260px; min-height: 0; }
.drone-icon svg { width: 36px; height: 36px; filter: drop-shadow(0 2px 3px rgba(0, 0, 0, .6)); }
.drone-label {
  background: var(--panel); color: var(--text); border: 1px solid var(--line); font-weight: 700; box-shadow: none;
}
.leaflet-popup-content-wrapper, .leaflet-popup-tip { background: var(--panel); color: var(--text); }
.leaflet-container a.leaflet-popup-close-button { color: var(--muted); }

/* ---------- calendar ---------- */
.cal-head { display: flex; align-items: center; gap: .5rem; margin-bottom: .75rem; }
.cal-head h2 { margin: 0; flex: 1; text-align: center; }
.cal { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px; }
.cal .dow { text-align: center; color: var(--muted); font-size: .75rem; font-weight: 700; padding: .25rem 0; }
.cal .day { min-height: 92px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 4px; display: flex; flex-direction: column; gap: 2px; overflow: hidden; }
.cal .day.other { opacity: .4; }
.cal .day.today { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.cal .day .d { font-size: .75rem; font-weight: 700; color: var(--muted); }
.chip { font-size: .7rem; padding: 1px 4px; border-radius: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; cursor: pointer; border: 0; text-align: left; }
.chip.res { background: #3b5bdb; color: #fff; }
.chip.co { background: var(--out); color: #1a1300; }
.chip.co.late { background: var(--overdue); color: #fff; }
.legend { display: flex; gap: 1rem; flex-wrap: wrap; font-size: .8rem; color: var(--muted); margin-top: .5rem; }
.legend span::before { content: ""; display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: .35rem; background: var(--c); }

/* ---------- scanner ---------- */
.scanner video { width: 100%; max-height: 60vh; border-radius: var(--radius); background: #000; object-fit: cover; }

/* ---------- labels (print) ---------- */
.labels { display: grid; grid-template-columns: repeat(auto-fill, minmax(2.2in, 1fr)); gap: .15in; }
.label-card { background: #fff; color: #000; border: 1px dashed #999; border-radius: 6px; padding: .12in; display: flex; gap: .1in; align-items: center; break-inside: avoid; }
.label-card img { width: 1.1in; height: 1.1in; }
.label-card .t { font-weight: 800; font-size: 11pt; }
.label-card .s { font-size: 9pt; font-family: ui-monospace, monospace; }

@media print {
  header.top, nav.tabs, .no-print, #toast { display: none !important; }
  html, body { background: #fff; color: #000; }
  main { padding: 0; max-width: none; }
  .label-card { border-color: #ccc; }
}

@media (max-width: 640px) {
  main { padding: .75rem; }
  .tile .num { font-size: 1.3rem; }
  .tiles { grid-template-columns: repeat(3, 1fr); }
  .cal .day { min-height: 64px; }
  .cal .chip { font-size: .6rem; }
  header.top .who { display: none; }
  .row { grid-template-columns: 1fr; }
  .row .badges { justify-content: start; }
}

/* colour helpers (CSP blocks inline style attributes, so colours come from classes) */
.c-ALL { --c: var(--accent); } .c-IN { --c: var(--in); } .c-OUT { --c: var(--out); } .c-GTG { --c: var(--gtg); }
.c-FMC { --c: var(--fmc); } .c-NMC { --c: var(--nmc); } .c-OVERDUE { --c: var(--overdue); } .c-RES { --c: #3b5bdb; }
