:root {
  --bg: #0b1120;
  --bg-2: #0f172a;
  --surface: #172033;
  --surface-2: #1f2b41;
  --border: #2a3752;
  --text: #eef2f8;
  --muted: #93a3bb;
  --primary: #f97316;
  --primary-press: #ea580c;
  --accent: #38bdf8;
  --danger: #ef4444;
  --success: #22c55e;
  --warn: #eab308;
  --radius: 14px;
  --shadow: 0 2px 8px rgba(0,0,0,0.28);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background:
    radial-gradient(1200px 500px at 50% -10%, rgba(249,115,22,0.10), transparent 60%),
    radial-gradient(900px 500px at 90% 0%, rgba(56,189,248,0.08), transparent 55%),
    var(--bg);
  background-attachment: fixed;
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
  letter-spacing: 0.1px;
}

/* Layout */
#app { min-height: 100vh; display: flex; flex-direction: column; }
.screen {
  flex: 1;
  padding: 16px 16px calc(104px + var(--safe-bottom));
  max-width: 720px;
  margin: 0 auto;
  width: 100%;
}
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: rgba(15, 23, 42, 0.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
  padding: 12px 16px;
  display: flex; align-items: center; gap: 12px;
}
.topbar h1 { font-size: 18px; margin: 0; flex: 1; }
.topbar .status-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); }
.status-dot.on_duty { background: var(--success); box-shadow: 0 0 8px var(--success); }
.status-dot.standby { background: var(--warn); }
.status-dot.off_duty, .status-dot.unavailable { background: var(--muted); }

/* Splash */
.splash { min-height: 100vh; display: grid; place-items: center; }
.spinner {
  width: 32px; height: 32px; border-radius: 50%;
  border: 3px solid var(--border); border-top-color: var(--primary);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
}
.card h3 { margin: 0 0 8px; font-size: 16px; }
.card .meta { color: var(--muted); font-size: 13px; }
.row { display: flex; gap: 10px; align-items: center; }
.row.between { justify-content: space-between; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1; }
.stack > * + * { margin-top: 10px; }

/* Dashboard tiles */
.tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; margin-bottom: 16px; }
.tile {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px;
  display: block; text-decoration: none; color: inherit;
  transition: transform 0.05s, border-color 0.15s;
}
a.tile:active { transform: scale(0.98); border-color: var(--accent); }
.tile .num { font-size: 28px; font-weight: 700; }
.tile .label { color: var(--muted); font-size: 13px; }
.tile.alert { border-color: var(--primary); }

/* Buttons */
button, .btn {
  display: inline-block; box-sizing: border-box;
  font: inherit; cursor: pointer; border: none; border-radius: 10px;
  padding: 12px 16px; background: var(--surface-2); color: var(--text);
  border: 1px solid var(--border); transition: background 0.15s, transform 0.05s;
  text-align: center; text-decoration: none; line-height: 1.2;
}
button:active, .btn:active { transform: scale(0.98); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #1a1000; font-weight: 600; }
.btn-primary:active { background: var(--primary-press); }
.btn-danger { background: transparent; border-color: var(--danger); color: var(--danger); }
.btn-ghost { background: transparent; }
.btn-block { display: block; width: 100%; }
.btn-sm { padding: 7px 12px; font-size: 13px; border-radius: 8px; }
button:disabled { opacity: 0.5; cursor: default; }

/* Forms */
label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
input, select, textarea {
  width: 100%; font: inherit; color: var(--text);
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 10px; padding: 12px; margin-bottom: 14px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); border-color: var(--accent); }
textarea { min-height: 90px; resize: vertical; }
.check { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.check input { width: auto; margin: 0; }
.check label { margin: 0; color: var(--text); }

/* Badges */
.badge {
  display: inline-block; font-size: 11px; font-weight: 600;
  padding: 3px 8px; border-radius: 999px; background: var(--surface-2);
  border: 1px solid var(--border); color: var(--muted);
}
.badge.critical { background: rgba(239,68,68,0.15); color: #fca5a5; border-color: var(--danger); }
.badge.high { background: rgba(234,179,8,0.15); color: #fde047; border-color: var(--warn); }
.badge.hold { background: rgba(239,68,68,0.15); color: #fca5a5; border-color: var(--danger); }
.badge.move { background: rgba(34,197,94,0.15); color: #86efac; border-color: var(--success); }
.badge.alert { background: rgba(249,115,22,0.15); color: #fdba74; border-color: var(--primary); }
.badge.vuln { background: rgba(56,189,248,0.15); color: #7dd3fc; border-color: var(--accent); }
.badge.new { background: rgba(56,189,248,0.15); color: #7dd3fc; border-color: var(--accent); }
.badge.done { background: rgba(34,197,94,0.12); color: #86efac; }

/* Section headers */
.section-title { font-size: 13px; text-transform: uppercase; letter-spacing: 0.5px;
  color: var(--muted); margin: 20px 0 8px; }

/* Banner (SITREP hold notice) */
.banner {
  border-radius: var(--radius); padding: 14px; margin-bottom: 16px;
  border: 1px solid var(--border); background: var(--surface);
}
.banner.hold { border-color: var(--danger); background: rgba(239,68,68,0.08); }
.banner.move { border-color: var(--success); background: rgba(34,197,94,0.08); }
.banner .title { font-weight: 700; margin-bottom: 4px; }

/* Bottom nav */
.nav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 30;
  display: flex; justify-content: space-around;
  background: rgba(15,23,42,0.96); backdrop-filter: blur(8px);
  border-top: 1px solid var(--border);
  padding: 8px 4px calc(8px + var(--safe-bottom));
}
.nav a {
  flex: 1; text-align: center; text-decoration: none; color: var(--muted);
  font-size: 10.5px; padding: 4px 2px; border-radius: 8px;
}
.nav a .ico { display: block; font-size: 20px; line-height: 1.2; }
.nav a.active { color: var(--primary); }

/* Toast */
.toast {
  position: fixed; left: 50%; bottom: calc(96px + var(--safe-bottom));
  transform: translateX(-50%);
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 10px;
  padding: 10px 16px; font-size: 14px; z-index: 50; max-width: 90%;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}
.toast.err { border-color: var(--danger); }
.toast.ok { border-color: var(--success); }

/* Auth screen */
.auth { max-width: 400px; margin: 0 auto; padding: 40px 20px; }
.auth .logo { text-align: center; margin-bottom: 24px; }
.auth .logo .mark { font-size: 40px; }
.auth .logo h1 { margin: 8px 0 2px; }
.auth .logo p { color: var(--muted); margin: 0; font-size: 14px; }
.switch { text-align: center; color: var(--muted); margin-top: 12px; font-size: 14px; }
.switch a { color: var(--accent); text-decoration: none; }

/* Map */
#map { height: 60vh; border-radius: var(--radius); border: 1px solid var(--border); }
.leaflet-container { background: var(--surface) !important; }

/* Top bar controls */
.topbar .iconbtn {
  background: transparent; border: none; color: var(--text);
  font-size: 20px; padding: 4px 8px; border-radius: 8px; line-height: 1;
}
.topbar .iconbtn:active { background: var(--surface-2); }
.role-badge {
  font-size: 10px; font-weight: 700; letter-spacing: 0.5px;
  padding: 3px 8px; border-radius: 999px; text-transform: uppercase;
  background: var(--surface-2); border: 1px solid var(--border); color: var(--muted);
}
.role-badge.admin { background: rgba(249,115,22,0.15); color: #fdba74; border-color: var(--primary); }
.role-badge.command { background: rgba(56,189,248,0.15); color: #7dd3fc; border-color: var(--accent); }
.role-badge.lead { background: rgba(34,197,94,0.12); color: #86efac; border-color: var(--success); }

/* Help panel */
.help-panel {
  background: var(--surface); border: 1px solid var(--accent);
  border-radius: var(--radius); padding: 14px; margin: 12px 16px 0;
  max-width: 720px; margin-left: auto; margin-right: auto;
}
.help-panel h4 { margin: 0 0 6px; font-size: 14px; }
.help-panel ul { margin: 6px 0 0; padding-left: 18px; }
.help-panel li { margin: 4px 0; font-size: 13px; color: var(--muted); }

/* Extra badge states */
.badge.ready { background: rgba(34,197,94,0.15); color: #86efac; border-color: var(--success); }
.badge.needs_service { background: rgba(234,179,8,0.15); color: #fde047; border-color: var(--warn); }
.badge.out_of_order { background: rgba(239,68,68,0.15); color: #fca5a5; border-color: var(--danger); }
.badge.current { background: rgba(249,115,22,0.18); color: #fdba74; border-color: var(--primary); }
.badge.asap { background: rgba(239,68,68,0.15); color: #fca5a5; border-color: var(--danger); }
.badge.unclaimed { background: rgba(234,179,8,0.12); color: #fde047; border-color: var(--warn); }

/* Success button variant */
.btn-ok { background: transparent; border-color: var(--success); color: #86efac; }
.copybox {
  display: flex; gap: 8px; align-items: center; margin-top: 8px;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px; font-size: 12px; word-break: break-all;
}

/* Avatars (initials) */
.avatar {
  width: 38px; height: 38px; border-radius: 50%; flex: 0 0 auto;
  display: grid; place-items: center; font-weight: 700; font-size: 14px; color: #0b1220;
}
.avatar.sq { border-radius: 10px; background: var(--surface-2); color: var(--text); }

/* Compact list rows (replace stacks of identical boxes) */
.lrow { display: flex; align-items: center; gap: 12px; padding: 11px 0; border-bottom: 1px solid var(--border); }
.lrow:last-child { border-bottom: none; }
.lrow .name { font-weight: 600; }
.lrow .sub { font-size: 12px; color: var(--muted); margin-top: 1px; }
.lrow .grow { min-width: 0; }
.lrow .name { overflow-wrap: anywhere; }
.lrow .sub { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Prominent header card for detail screens */
.hero {
  background: linear-gradient(160deg, #24344c 0%, var(--surface) 70%);
  position: relative;
}
.hero .kicker { font-size: 11px; text-transform: uppercase; letter-spacing: 0.7px; color: var(--muted); }
.hero h2 { margin: 3px 0 10px; font-size: 22px; line-height: 1.15; }

/* Slightly lift cards so they read as layered, not flat identical boxes */
.card { box-shadow: 0 1px 2px rgba(0,0,0,0.25); }
.card > h3:first-child { display: flex; align-items: center; gap: 8px; }

/* Count pill next to section titles */
.count { font-size: 12px; color: var(--muted); font-weight: 600; }

/* Collapsible section cards (Crew / Equipment) */
details.collapse > summary {
  list-style: none; cursor: pointer; display: flex; align-items: center; gap: 8px;
  margin: -4px 0; padding: 4px 0; user-select: none;
}
details.collapse > summary::-webkit-details-marker { display: none; }
details.collapse > summary h3 { margin: 0; flex: 1; }
details.collapse > summary .chev { color: var(--muted); font-size: 13px; transition: transform 0.15s ease; }
details.collapse[open] > summary .chev { transform: rotate(90deg); }
details.collapse[open] > summary { margin-bottom: 10px; }

.empty { text-align: center; color: var(--muted); padding: 40px 20px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
a.link { color: var(--accent); text-decoration: none; }
hr { border: none; border-top: 1px solid var(--border); margin: 16px 0; }

/* ============================================================
   Design system v2 — cohesive components
   ============================================================ */

/* Home greeting header */
.greeting { margin: 4px 2px 16px; }
.greeting .hello { font-size: 22px; font-weight: 700; }
.greeting .sub { color: var(--muted); font-size: 13px; margin-top: 2px; }

/* Section header with icon + optional action */
.sec { display: flex; align-items: center; gap: 8px; margin: 22px 2px 10px; }
.sec .ico { font-size: 16px; }
.sec h3 { margin: 0; font-size: 14px; text-transform: uppercase; letter-spacing: 0.6px; color: var(--muted); }
.sec .act { margin-left: auto; font-size: 13px; }

/* Card refinements */
.card { box-shadow: var(--shadow); border-color: var(--border); }
.card.tight { padding: 12px; }

/* List card: rows live in a single card, no more stacks of identical boxes */
.list { padding: 4px 14px; }
.list .lrow:first-child { padding-top: 12px; }
.list .lrow:last-child { padding-bottom: 12px; }
.lrow.tap { cursor: pointer; }
.lrow.tap:active { background: var(--surface-2); margin: 0 -14px; padding-left: 14px; padding-right: 14px; border-radius: 8px; }

/* Quick actions grid (home) */
.qa-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.qa {
  display: flex; flex-direction: column; gap: 6px; text-decoration: none; color: var(--text);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow); transition: transform 0.05s, border-color 0.15s;
}
.qa:active { transform: scale(0.98); border-color: var(--accent); }
.qa .ico { font-size: 24px; }
.qa .t { font-weight: 600; }
.qa .d { font-size: 12px; color: var(--muted); }
.qa.primary { background: linear-gradient(160deg, #7c3a12, #f97316); border-color: var(--primary); color: #1a1000; }
.qa.primary .d { color: rgba(26,16,0,0.7); }
.qa.full { grid-column: 1 / -1; flex-direction: row; align-items: center; }
.qa.full .ico { font-size: 22px; }

/* Status dot in a chip */
.dotchip { display: inline-flex; align-items: center; gap: 6px; }
.dotchip .d { width: 8px; height: 8px; border-radius: 50%; }

/* Duty control card */
.duty {
  display: flex; align-items: center; justify-content: space-between;
  background: linear-gradient(160deg, #1c2740, var(--surface));
}

/* Refined bottom nav */
.nav a.active .ico { transform: translateY(-1px); }

/* Screen title bigger */
.topbar h1 { font-size: 19px; font-weight: 700; }
