:root {
    --bg: #202431;
    --bar: #242938;
    --bar-soft: #2a3040;
    --panel: #f8fbfa;
    --panel-soft: #eef8f5;
    --line: #189681;
    --line-soft: #b7dcd5;
    --text: #202b34;
    --muted: #60707a;
    --accent: #0b8d7e;
    --accent-dark: #076f64;
    --danger: #ce3d3d;
    --danger-dark: #a92f2f;
    --warning: #f2b705;
    --white: #ffffff;
    --shadow: 0 22px 60px rgba(8, 15, 24, .28);
    --radius: 4px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { min-height: 100%; }

body {
    margin: 0;
    color: var(--text);
    font-family: "Segoe UI", Roboto, Arial, sans-serif;
    background: linear-gradient(180deg, rgba(43, 49, 64, .96), rgba(32, 36, 49, 1)), var(--bg);
}

button, input, select, textarea, a { font: inherit; }
a { color: var(--accent-dark); }

.sr-only {
    position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

/* ---------- Topbar ---------- */
.topbar {
    min-height: 58px; display: flex; align-items: center; gap: 16px;
    padding: 9px 18px; color: #dfe8eb; background: var(--bar);
    border-bottom: 3px solid var(--line); box-shadow: 0 4px 18px rgba(0, 0, 0, .26);
}
.brand-block {
    width: 118px; min-width: 118px; height: 38px; display: grid; place-items: center;
    color: #17202b; background: var(--white); border-left: 8px solid var(--danger);
    border-radius: 2px; font-size: 11px; font-weight: 800; line-height: 1.15;
    text-align: center; text-transform: uppercase;
}
.brand-title {
    display: flex; align-items: baseline; gap: 8px; min-width: 0;
    font-size: clamp(17px, 2vw, 22px); font-weight: 800; white-space: nowrap;
    overflow: hidden; text-overflow: ellipsis;
}
.brand-title span { color: #aeb9c2; font-size: .66em; font-weight: 600; }

.top-nav { display: flex; align-items: center; gap: 4px; margin-left: 8px; }
.top-nav a {
    display: inline-flex; align-items: center; gap: 7px; min-height: 34px; padding: 0 12px;
    color: #c8d3d9; text-decoration: none; border-radius: 3px; font-size: 13px; font-weight: 600;
}
.top-nav a svg { width: 16px; height: 16px; }
.top-nav a:hover { color: #fff; background: var(--bar-soft); }
.top-nav a.is-active { color: #fff; background: var(--bar-soft); box-shadow: inset 0 -3px 0 var(--line); }

.top-actions { margin-left: auto; display: flex; align-items: center; gap: 10px; color: #d0d9df; font-size: 12px; white-space: nowrap; }
.user-chip { display: inline-flex; flex-direction: column; align-items: flex-end; line-height: 1.2; }
.user-chip strong { color: #fff; font-size: 13px; }
.user-chip span { color: #9fb0b8; font-size: 11px; }
.dept-pill {
    display: inline-flex; align-items: center; gap: 6px; min-height: 30px; padding: 0 11px;
    color: #fff; background: var(--bar-soft); border: 1px solid #465061; border-radius: 3px;
    font-size: 12px; font-weight: 800;
}
.dept-pill::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--line); box-shadow: 0 0 0 3px rgba(24, 150, 129, .2); }
.logout-link {
    display: inline-flex; align-items: center; gap: 6px; min-height: 30px; padding: 0 10px;
    color: #eef5f6; background: #333a4a; border: 1px solid #465061; border-radius: 3px; text-decoration: none;
}
.logout-link:hover { background: #3c4457; }

/* ---------- Shell / layout ---------- */
.page-shell { min-height: calc(100vh - 58px); display: grid; grid-template-rows: minmax(0, 1fr) auto; gap: 12px; padding: 12px; }
.console-grid { min-height: 0; display: grid; grid-template-columns: minmax(420px, 1fr) minmax(360px, 460px); gap: 12px; }

.panel {
    min-width: 0; background: var(--panel); border: 2px solid var(--line);
    border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden;
}
.map-panel { position: relative; min-height: 640px; }
.side-col { display: flex; flex-direction: column; min-height: 640px; }

#map, .leaflet-container { width: 100%; height: 100%; min-height: 640px; background: #dcebe3; font-family: inherit; }
.leaflet-tile, .leaflet-tile-container img { border: 0 !important; outline: 0 !important; box-shadow: none !important; }
.leaflet-tile-loaded { opacity: 1 !important; }
.leaflet-popup-content-wrapper, .leaflet-popup-tip { border-radius: var(--radius); }

.panel-head { padding: 20px 20px 16px; border-bottom: 1px solid var(--line-soft); background: linear-gradient(180deg, #fff, #eef8f5); }
.eyebrow { margin: 0 0 8px; color: var(--accent); font-size: 12px; font-weight: 800; letter-spacing: .6px; text-transform: uppercase; }
.panel-head h1, .panel-head h2 { margin: 0; color: #24313a; font-size: 24px; line-height: 1.12; }
.panel-head p { margin: 9px 0 0; color: var(--muted); font-size: 14px; line-height: 1.45; }

/* ---------- Live alert list ---------- */
.alert-toolbar { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-bottom: 1px solid var(--line-soft); background: #fff; }
.live-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--line); box-shadow: 0 0 0 0 rgba(24,150,129,.5); animation: pulse 1.8s infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(24,150,129,.5);} 70% { box-shadow: 0 0 0 8px rgba(24,150,129,0);} 100% { box-shadow: 0 0 0 0 rgba(24,150,129,0);} }
.alert-toolbar strong { font-size: 13px; color: #26323a; }
.alert-toolbar .count { margin-left: auto; color: var(--muted); font-size: 12px; font-weight: 700; }

.alert-list { flex: 1; overflow: auto; padding: 12px; display: grid; gap: 10px; align-content: start; }
.alert-card {
    display: grid; grid-template-columns: auto 1fr auto; gap: 12px; align-items: center; padding: 14px;
    background: #fff; border: 1px solid #d9e8e5; border-left: 4px solid var(--danger); border-radius: var(--radius);
    cursor: pointer; text-align: left; width: 100%;
}
.alert-card:hover { border-color: var(--line); box-shadow: 0 8px 22px rgba(18,31,42,.10); }
.alert-card.resolved { border-left-color: var(--line); opacity: .72; }
.alert-badge {
    width: 40px; height: 40px; display: grid; place-items: center; color: #202431;
    font-size: 12px; font-weight: 900; background: #ffda2e; border: 2px solid #111827;
    clip-path: polygon(50% 0, 100% 100%, 0 100%);
}
.alert-card.resolved .alert-badge { background: var(--line-soft); border-color: var(--accent-dark); clip-path: none; border-radius: 50%; }
.alert-main strong { display: block; color: #1c2830; font-size: 14px; }
.alert-main span { display: block; margin-top: 3px; color: var(--muted); font-size: 12px; line-height: 1.35; }
.alert-meta { text-align: right; white-space: nowrap; }
.status-tag { display: inline-block; padding: 3px 8px; border-radius: 20px; font-size: 11px; font-weight: 800; text-transform: uppercase; }
.status-tag.dispatched { color: #7a3b00; background: #ffedcc; }
.status-tag.in_progress { color: #0b5e54; background: #d6f0ea; }
.status-tag.pending { color: #7a3b00; background: #fff0d6; }
.status-tag.resolved { color: #445; background: #e7edf0; }
.alert-meta .time { display: block; margin-top: 5px; color: #83939c; font-size: 11px; }
.list-empty { padding: 40px 16px; text-align: center; color: var(--muted); font-size: 13px; }

/* ---------- Buttons ---------- */
.btn {
    min-height: 44px; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    padding: 0 16px; color: #fff; background: var(--accent); border: 1px solid var(--accent-dark);
    border-radius: var(--radius); font-weight: 800; text-decoration: none; cursor: pointer;
}
.btn svg { width: 18px; height: 18px; }
.btn:hover { background: var(--accent-dark); }
.btn.secondary { color: #26323a; background: #fff; border-color: #cbded9; }
.btn.secondary:hover { background: #eef8f5; }
.btn.danger { background: var(--danger); border-color: var(--danger-dark); }
.btn.danger:hover { background: var(--danger-dark); }
.btn.block { width: 100%; }
.btn:disabled { cursor: not-allowed; opacity: .5; }

.home-actions { display: grid; gap: 12px; padding: 18px; }
.home-button {
    min-height: 88px; display: grid; grid-template-columns: 40px 1fr 22px; align-items: center; gap: 14px;
    padding: 18px; color: #fff; text-decoration: none; background: var(--accent);
    border: 1px solid var(--accent-dark); border-radius: var(--radius); box-shadow: 0 12px 28px rgba(11,141,126,.2);
}
.home-button.alt { background: var(--bar); border-color: #10151f; box-shadow: 0 12px 28px rgba(20,24,34,.28); }
.home-button:hover { filter: brightness(1.03); }
.home-button .ico { width: 40px; height: 40px; display: grid; place-items: center; }
.home-button .ico svg { width: 26px; height: 26px; }
.home-button strong { display: block; font-size: 19px; }
.home-button span.sub { display: block; margin-top: 4px; color: rgba(255,255,255,.9); font-size: 13px; }

/* ---------- Footer ---------- */
.site-footer {
    min-height: 60px; display: flex; align-items: center; gap: 10px; padding: 14px 18px;
    color: #d9e6e8; background: var(--bar); border: 1px solid rgba(255,255,255,.08); border-radius: 2px;
    font-size: 13px; line-height: 1.45;
}
.site-footer::before { content: ""; width: 12px; height: 12px; flex: 0 0 12px; border-radius: 50%; background: var(--line); box-shadow: 0 0 0 4px rgba(24,150,129,.18); }
.site-footer strong { color: #fff; }

/* ---------- Forms ---------- */
.field { display: grid; gap: 7px; min-width: 0; }
.field label, .fieldset-title { color: #26323a; font-size: 13px; font-weight: 800; }
.field input, .field select, .field textarea {
    width: 100%; min-height: 44px; color: #1d2a32; background: #fff; border: 1px solid #cbded9;
    border-radius: var(--radius); padding: 10px 12px; outline: none;
}
.field textarea { min-height: 92px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(11,141,126,.14); }
.field input[readonly] { color: #314049; background: #edf5f3; font-weight: 800; }
.field-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 14px; }
.field-grid.single { grid-template-columns: 1fr; }
.error-text { min-height: 15px; color: var(--danger); font-size: 12px; font-weight: 700; }

/* ---------- Login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card { width: min(420px, 100%); background: var(--panel); border: 2px solid var(--line); border-radius: 6px; box-shadow: var(--shadow); overflow: hidden; }
.login-head { padding: 26px 26px 18px; text-align: center; background: linear-gradient(180deg, #fff, #eef8f5); border-bottom: 1px solid var(--line-soft); }
.login-logo { display: inline-grid; grid-auto-flow: column; align-items: center; gap: 10px; }
.login-logo .mark { width: 44px; height: 44px; display: grid; place-items: center; color: #fff; background: var(--bar); border-left: 6px solid var(--danger); border-radius: 3px; font-weight: 900; font-size: 12px; }
.login-logo b { font-size: 26px; color: #1c2830; }
.login-logo b span { color: var(--accent); }
.login-head p { margin: 12px 0 0; color: var(--muted); font-size: 13px; }
.login-body { padding: 24px 26px 26px; display: grid; gap: 16px; }
.login-alert { padding: 11px 13px; color: #7a1d1d; background: #fbe7e7; border: 1px solid #edc4c4; border-radius: var(--radius); font-size: 13px; font-weight: 700; }
.login-foot { padding: 14px 26px; color: #77868f; font-size: 12px; text-align: center; background: #f2f8f6; border-top: 1px solid var(--line-soft); }

/* ---------- Detail drawer ---------- */
.drawer-backdrop { position: fixed; inset: 0; z-index: 1200; background: rgba(16,20,28,.5); display: none; }
.drawer-backdrop.open { display: block; }
.drawer {
    position: fixed; top: 0; right: 0; z-index: 1300; height: 100vh; width: min(460px, 100%);
    background: var(--panel); border-left: 3px solid var(--line); box-shadow: -20px 0 50px rgba(0,0,0,.3);
    transform: translateX(100%); transition: transform .22s ease; display: flex; flex-direction: column;
}
.drawer.open { transform: translateX(0); }
.drawer-head { padding: 18px 20px; background: var(--bar); color: #fff; display: flex; align-items: center; gap: 12px; }
.drawer-head h3 { margin: 0; font-size: 16px; }
.drawer-head .close { margin-left: auto; width: 34px; height: 34px; display: grid; place-items: center; color: #cdd8dc; background: transparent; border: 0; cursor: pointer; border-radius: 4px; }
.drawer-head .close:hover { background: var(--bar-soft); }
.drawer-body { flex: 1; overflow: auto; padding: 18px 20px; display: grid; gap: 12px; align-content: start; }
.drawer-foot { padding: 14px 20px; border-top: 1px solid var(--line-soft); background: #f2f8f6; display: flex; gap: 10px; }
.info-row { display: grid; grid-template-columns: 130px 1fr; gap: 10px; padding: 11px 12px; background: #fff; border: 1px solid #d9e8e5; border-radius: var(--radius); }
.info-row span:first-child { color: var(--muted); font-size: 11px; font-weight: 800; text-transform: uppercase; }
.info-row span:last-child { color: #26323a; font-size: 13px; font-weight: 700; }
.responder-line { display: grid; grid-template-columns: 26px 1fr auto; gap: 10px; align-items: center; padding: 10px 12px; background: #fff; border: 1px solid #d9e8e5; border-left: 3px solid var(--line); border-radius: var(--radius); }
.responder-line .dot { width: 22px; height: 22px; border-radius: 50%; background: var(--accent); display: grid; place-items: center; color: #fff; }
.responder-line .dot svg { width: 13px; height: 13px; }
.responder-line strong { font-size: 12px; color: #26323a; }
.responder-line span { font-size: 12px; color: var(--muted); }

/* ---------- Toast ---------- */
#toast { position: fixed; z-index: 2000; bottom: 20px; left: 50%; transform: translateX(-50%); display: grid; gap: 8px; }
.toast { padding: 12px 16px; color: #fff; background: var(--bar); border-left: 4px solid var(--line); border-radius: var(--radius); box-shadow: 0 12px 30px rgba(0,0,0,.35); font-size: 13px; }
.toast.err { border-left-color: var(--danger); }

/* ---------- Responsive ---------- */
@media (max-width: 1080px) {
    .console-grid { grid-template-columns: 1fr; }
    .map-panel, .side-col, #map, .leaflet-container { min-height: 420px; }
}
@media (max-width: 720px) {
    .topbar { flex-wrap: wrap; }
    .top-nav { order: 3; width: 100%; }
    .top-actions { margin-left: auto; }
    .field-grid { grid-template-columns: 1fr; }
}
