:root {
    --navy: #10263a;
    --navy2: #183a58;
    --blue: #28689c;
    --gold: #e2ad3b;
    --red: #b63d3d;
    --green: #2c8a55;
    --bg: #eef2f5;
    --panel: #fff;
    --text: #1a2731;
    --muted: #66737f;
    --line: #d5dde4;
    --shadow: 0 8px 24px rgba(13, 35, 52, .08);
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    min-height: 100%;
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    background: var(--bg);
    color: var(--text);
}

a { color: inherit; }

.topbar {
    height: 64px;
    padding: 0 20px;
    background: var(--navy);
    color: white;
    border-bottom: 4px solid var(--gold);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
}

.topbar > div:first-child {
    display: flex;
    align-items: baseline;
    gap: 12px;
}

.topbar strong {
    letter-spacing: .8px;
}

.topbar span {
    color: #c3d1dd;
    font-size: 14px;
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 15px;
    font-size: 14px;
}

.topbar-right a {
    color: white;
    text-decoration: none;
}

.dispatch-layout {
    display: grid;
    grid-template-columns: minmax(560px, 1.10fr) minmax(400px, .90fr);
    gap: 18px;
    padding: 18px;
    min-height: calc(100vh - 64px);
}

.panel {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
    padding: 18px;
}

.panel-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 20px;
    margin-bottom: 16px;
}

.panel h2 {
    margin: 0 0 4px;
    color: var(--navy);
    font-size: 20px;
}

.panel p {
    margin: 0;
    color: var(--muted);
    font-size: 14px;
}

.pulsepoint-panel {
    display: flex;
    flex-direction: column;
    min-height: 700px;
}

.pulsepoint-frame {
    width: 100%;
    flex: 1;
    min-height: 650px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: white;
}

.btn {
    border: 1px solid #b9c5cf;
    background: #f8fafb;
    color: var(--navy);
    padding: 9px 13px;
    border-radius: 5px;
    font-weight: 700;
    cursor: pointer;
    text-decoration: none;
    font-size: 14px;
}

.btn:hover { background: #edf3f7; }

.btn.primary {
    background: var(--blue);
    color: white;
    border-color: var(--blue);
}

.btn.danger {
    background: var(--red);
    color: white;
    border-color: var(--red);
}

.incident-list {
    display: grid;
    gap: 12px;
}

.incident-card {
    border: 1px solid var(--line);
    border-left: 6px solid var(--blue);
    border-radius: 6px;
    background: #fff;
    padding: 14px;
}

.incident-card.priority-1 { border-left-color: #b52f2f; }
.incident-card.priority-2 { border-left-color: #d57a22; }
.incident-card.priority-3 { border-left-color: #2b6fa5; }
.incident-card.priority-4 { border-left-color: #6f7d89; }

.incident-top {
    display: flex;
    justify-content: space-between;
    gap: 15px;
    margin-bottom: 8px;
}

.incident-number {
    font-size: 13px;
    color: var(--muted);
    font-weight: 800;
}

.incident-title {
    font-size: 19px;
    font-weight: 800;
    color: var(--navy);
}

.priority-badge {
    white-space: nowrap;
    font-size: 12px;
    font-weight: 900;
    padding: 4px 8px;
    border-radius: 999px;
    background: #eef2f5;
}

.incident-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 7px 14px;
    color: var(--muted);
    font-size: 13px;
    margin: 8px 0;
}

.incident-notes {
    margin-top: 10px;
    white-space: pre-wrap;
}

.targets {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    margin-top: 10px;
}

.tag {
    font-size: 11px;
    padding: 3px 7px;
    border-radius: 999px;
    background: #e8f0f6;
    color: var(--navy2);
    font-weight: 800;
}

.card-actions {
    display: flex;
    gap: 8px;
    margin-top: 12px;
    flex-wrap: wrap;
}

.modal {
    position: fixed;
    inset: 0;
    background: rgba(6, 18, 27, .65);
    z-index: 50;
    display: grid;
    place-items: center;
    padding: 20px;
}

.hidden { display: none !important; }

.modal-card {
    width: min(700px, 100%);
    max-height: 92vh;
    overflow: auto;
    background: white;
    border-radius: 8px;
    box-shadow: 0 20px 60px rgba(0,0,0,.25);
}

.modal-head {
    padding: 16px 18px;
    background: var(--navy);
    color: white;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-head h2 {
    margin: 0;
    font-size: 20px;
}

.icon-btn {
    border: 0;
    background: transparent;
    color: white;
    font-size: 28px;
    cursor: pointer;
}

.incident-form {
    padding: 18px;
    display: grid;
    gap: 14px;
}

.grid2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
}

label, fieldset {
    font-size: 13px;
    font-weight: 700;
    color: var(--navy);
}

input, select, textarea {
    width: 100%;
    margin-top: 5px;
    border: 1px solid #b8c5cf;
    border-radius: 5px;
    padding: 10px;
    font: inherit;
    color: var(--text);
    background: white;
}

textarea { resize: vertical; }

fieldset {
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 12px;
}

.org-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
}

.check {
    display: flex;
    align-items: center;
    gap: 7px;
}

.check input {
    width: auto;
    margin: 0;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

.unit-banner {
    background: #dce7ef;
    border-bottom: 1px solid #b9c8d3;
    padding: 16px 22px;
    display: flex;
    justify-content: space-between;
    gap: 30px;
}

.unit-banner > div {
    display: grid;
    gap: 2px;
}

.unit-banner strong {
    font-size: 22px;
    color: var(--navy);
}

.unit-banner small {
    color: var(--muted);
}

.eyebrow {
    font-size: 10px;
    letter-spacing: 1.5px;
    color: var(--muted);
    font-weight: 900;
}

.mdt-main {
    padding: 18px;
    display: grid;
    grid-template-columns: 1.4fr .6fr;
    gap: 18px;
}

.status-buttons {
    display: grid;
    gap: 10px;
    margin-top: 14px;
}

.status-btn {
    width: 100%;
    padding: 14px;
    text-align: left;
}

.status-btn.active {
    background: var(--green);
    color: white;
    border-color: var(--green);
}

.login-body {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 20px;
    background:
        linear-gradient(rgba(16,38,58,.92), rgba(16,38,58,.92)),
        radial-gradient(circle at top right, #315c7c, #10263a);
}

.login-card {
    width: min(440px, 100%);
    background: white;
    border-radius: 8px;
    padding: 26px;
    box-shadow: 0 25px 80px rgba(0,0,0,.25);
}

.brand-block {
    display: flex;
    gap: 14px;
    align-items: center;
    margin-bottom: 22px;
}

.brand-mark {
    width: 54px;
    height: 54px;
    border-radius: 50%;
    background: var(--navy);
    color: var(--gold);
    display: grid;
    place-items: center;
    font-weight: 900;
}

.brand-block h1 {
    margin: 0;
    font-size: 20px;
    color: var(--navy);
}

.brand-block p {
    margin: 3px 0 0;
    color: var(--muted);
}

.stack {
    display: grid;
    gap: 14px;
}

.alert {
    padding: 10px 12px;
    border-radius: 5px;
    margin-bottom: 14px;
}

.alert.error {
    background: #fbe9e9;
    border: 1px solid #edbcbc;
    color: #8d2929;
}

.empty {
    padding: 24px;
    text-align: center;
    color: var(--muted);
    border: 1px dashed #bac7d0;
    border-radius: 6px;
}

@media (max-width: 1050px) {
    .dispatch-layout,
    .mdt-main {
        grid-template-columns: 1fr;
    }

    .pulsepoint-panel {
        min-height: 650px;
    }
}

@media (max-width: 650px) {
    .topbar {
        height: auto;
        padding: 12px;
        align-items: flex-start;
    }

    .topbar > div:first-child,
    .topbar-right {
        flex-direction: column;
        align-items: flex-start;
        gap: 4px;
    }

    .dispatch-layout,
    .mdt-main {
        padding: 10px;
    }

    .grid2,
    .org-grid {
        grid-template-columns: 1fr;
    }

    .unit-banner {
        flex-direction: column;
    }
}


.dispatch-left {
    display: grid;
    align-content: start;
    gap: 18px;
    min-width: 0;
}

.unit-status-panel {
    min-width: 0;
}

.status-refresh {
    color: var(--muted);
    font-size: 12px;
    white-space: nowrap;
}

.user-status-list {
    display: grid;
    gap: 8px;
}

.user-status-row {
    display: grid;
    grid-template-columns: minmax(120px, 1.1fr) 80px minmax(115px, .8fr) auto;
    gap: 10px;
    align-items: center;
    padding: 10px 11px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: #fbfcfd;
}

.user-status-identity {
    min-width: 0;
}

.user-status-identity strong,
.user-status-identity span {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.user-status-identity strong {
    color: var(--navy);
    font-size: 14px;
}

.user-status-identity span,
.user-status-time {
    color: var(--muted);
    font-size: 11px;
}

.org-badge {
    display: inline-block;
    justify-self: start;
    padding: 3px 7px;
    border-radius: 999px;
    background: #e8f0f6;
    color: var(--navy2);
    font-size: 11px;
    font-weight: 900;
}

.unit-status-badge {
    display: inline-block;
    justify-self: start;
    padding: 5px 8px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 900;
    white-space: nowrap;
    border: 1px solid transparent;
}

.unit-status-badge.available { background: #e6f5ec; color: #207342; border-color: #b9dec8; }
.unit-status-badge.assigned { background: #e8f0f8; color: #245e8b; border-color: #bfd2e3; }
.unit-status-badge.en-route { background: #fff1d8; color: #965c00; border-color: #edd19d; }
.unit-status-badge.on-scene { background: #fde5dc; color: #9e3d1c; border-color: #edbca9; }
.unit-status-badge.clear { background: #eef1f3; color: #58646e; border-color: #d0d7dc; }
.unit-status-badge.out-of-service { background: #f3e5e7; color: #8f3040; border-color: #dfbcc3; }

@media (max-width: 650px) {
    .user-status-row {
        grid-template-columns: 1fr auto;
    }

    .user-status-time {
        grid-column: 1 / -1;
    }
}


.topbar-link-button {
    border: 0;
    background: transparent;
    color: white;
    padding: 0;
    font: inherit;
    cursor: pointer;
}

.topbar-link-button:hover,
.topbar-right a:hover {
    text-decoration: underline;
}

.pulsepoint-actions {
    display: flex;
    gap: 8px;
    align-items: center;
}

.pulsepoint-mobile-placeholder {
    min-height: 180px;
    border: 1px dashed #b9c8d3;
    border-radius: 6px;
    background: #f6f9fb;
    display: grid;
    place-items: center;
    align-content: center;
    text-align: center;
    gap: 9px;
    padding: 24px;
    color: var(--muted);
}

.pulsepoint-mobile-placeholder strong {
    color: var(--navy);
    font-size: 17px;
}

.pulsepoint-mobile-placeholder span {
    max-width: 480px;
    font-size: 13px;
}

.pulsepoint-panel.mobile-pulsepoint-hidden {
    display: none;
}

.admin-layout {
    display: grid;
    grid-template-columns: minmax(600px, 1.25fr) minmax(390px, .75fr);
    gap: 18px;
    padding: 18px;
    align-items: start;
}

.admin-user-list {
    display: grid;
    gap: 8px;
}

.admin-user-row {
    display: grid;
    grid-template-columns: minmax(180px, 1.3fr) 74px 92px minmax(118px, .8fr) 84px;
    gap: 10px;
    align-items: center;
    text-decoration: none;
    color: inherit;
    padding: 10px 11px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: #fbfcfd;
}

.admin-user-row:hover {
    background: #f1f6fa;
    border-color: #b9c8d3;
}

.admin-user-row.inactive {
    opacity: .58;
}

.admin-user-main {
    min-width: 0;
}

.admin-user-main strong,
.admin-user-main span {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.admin-user-main strong {
    color: var(--navy);
}

.admin-user-main span {
    margin-top: 2px;
    color: var(--muted);
    font-size: 11px;
}

.role-badge,
.active-badge {
    display: inline-block;
    justify-self: start;
    padding: 4px 7px;
    border-radius: 4px;
    font-size: 10px;
    font-weight: 900;
    white-space: nowrap;
}

.role-badge {
    background: #edf1f4;
    color: #4f5d67;
}

.active-badge.yes {
    background: #e6f5ec;
    color: #207342;
}

.active-badge.no {
    background: #f3e5e7;
    color: #8f3040;
}

.alert.success {
    background: #e8f6ed;
    border: 1px solid #b8dec7;
    color: #216b3e;
}

.admin-active-check {
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: 5px;
    background: #f8fafb;
}

@media (max-width: 1100px) {
    .admin-layout {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 760px) {
    .admin-layout {
        padding: 10px;
    }

    .admin-user-row {
        grid-template-columns: 1fr auto;
    }

    .admin-user-row .unit-status-badge,
    .admin-user-row .active-badge {
        grid-column: auto;
    }
}


.brand-header { display:flex; align-items:center; gap:10px; }
.brand-header > div:last-child { display:flex; flex-direction:column; gap:1px; }
.header-logo-wrap { width:42px; height:42px; flex:0 0 42px; }
.header-logo { width:42px; height:42px; object-fit:contain; display:block; }
.header-logo-fallback { width:42px; height:42px; border:2px solid var(--gold); border-radius:50%; display:grid; place-items:center; color:var(--gold); font-weight:900; font-size:12px; }
.target-groups, .membership-groups { display:grid; gap:10px; }
.target-group-block, .membership-group { border:1px solid var(--line); border-radius:6px; padding:10px; background:#fbfcfd; }
.target-group-name { font-size:14px; }
.target-subgroups, .membership-subgroups { margin:8px 0 0 24px; display:grid; grid-template-columns:repeat(2,minmax(0,1fr)); gap:7px 12px; }
.system-admin-group { background:#fff7e3; }
.quick-status-select { width:170px; margin:0; padding:6px 8px; font-size:11px; font-weight:800; }
.admin-user-row { grid-template-columns:minmax(220px,1fr) 92px 180px 84px; }
.admin-user-main { text-decoration:none; color:inherit; }
.group-admin-list,.subgroup-admin-list { display:grid; gap:8px; }
.group-admin-row { display:grid; grid-template-columns:minmax(220px,1fr) 90px 100px auto; gap:10px; align-items:center; border:1px solid var(--line); border-radius:6px; padding:10px; text-decoration:none; color:inherit; background:#fbfcfd; }
.group-admin-row:hover { background:#f1f6fa; }
.group-admin-row > div strong,.group-admin-row > div span { display:block; }
.group-admin-row > div span { font-size:11px; color:var(--muted); margin-top:2px; }
.subgroup-admin-row { display:flex; align-items:center; justify-content:space-between; gap:12px; border:1px solid var(--line); border-radius:5px; padding:8px 10px; }
.subgroup-admin-row form { margin:0; }
.inline-subgroup-form { display:grid; grid-template-columns:1fr auto; gap:8px; margin-top:10px; }
.inline-subgroup-form input { margin:0; }
.section-rule { border:0; border-top:1px solid var(--line); margin:20px 0; }
@media(max-width:760px){.target-subgroups,.membership-subgroups{grid-template-columns:1fr}.group-admin-row{grid-template-columns:1fr auto}.group-admin-row>span:nth-of-type(2){display:none}.admin-user-row{grid-template-columns:1fr auto}.quick-status-select{width:150px}}


/* ============================================================
   v0.4.1 - Compact EMCOMM application header
   ============================================================ */

.topbar {
    height: 48px;
    min-height: 48px;
    padding: 0 14px;
    border-bottom-width: 3px;
    gap: 14px;
    box-sizing: border-box;
}

.brand-header {
    height: 100%;
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
}

.brand-header > div:last-child {
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 0;
    min-width: 0;
    line-height: 1;
}

.header-logo-wrap {
    width: 36px;
    height: 36px;
    flex: 0 0 36px;
}

.header-logo {
    width: 36px;
    height: 36px;
    object-fit: contain;
    display: block;
    margin: 0;
}

.header-logo-fallback {
    width: 36px;
    height: 36px;
    border-width: 2px;
    font-size: 10px;
}

.brand-header strong {
    display: block;
    margin: 0;
    font-size: 15px;
    line-height: 17px;
    font-weight: 800;
    letter-spacing: .65px;
    white-space: nowrap;
}

.brand-header > div:last-child > span {
    display: block;
    margin: 0;
    padding: 0;
    color: #c3d1dd;
    font-size: 11px;
    line-height: 12px;
    white-space: nowrap;
}

.topbar-right {
    height: 100%;
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 12px;
    white-space: nowrap;
}

.topbar-right span,
.topbar-right a,
.topbar-link-button {
    margin: 0;
    line-height: 1;
}

.dispatch-layout {
    min-height: calc(100vh - 48px);
}

/* Keep the compact branding intact on phones while allowing
   the navigation controls to wrap when necessary. */
@media (max-width: 650px) {
    .topbar {
        height: auto;
        min-height: 48px;
        padding: 6px 10px;
        align-items: center;
        flex-wrap: wrap;
    }

    .topbar > .brand-header {
        flex-direction: row;
        align-items: center;
        gap: 8px;
    }

    .topbar-right {
        height: auto;
        flex-direction: row;
        align-items: center;
        flex-wrap: wrap;
        gap: 7px 10px;
        width: 100%;
        padding-left: 44px;
    }

    .header-logo-wrap,
    .header-logo {
        width: 34px;
        height: 34px;
    }

    .header-logo-wrap {
        flex-basis: 34px;
    }

    .header-logo-fallback {
        width: 34px;
        height: 34px;
    }

    .brand-header strong {
        font-size: 13px;
        line-height: 15px;
    }

    .brand-header > div:last-child > span {
        font-size: 10px;
        line-height: 11px;
    }
}


/* ============================================================
   v0.4.2 - Header alignment correction
   Fixes older selector specificity that was still forcing
   baseline alignment and excessive spacing.
   ============================================================ */

.topbar {
    height: 44px !important;
    min-height: 44px !important;
    padding: 0 12px !important;
    border-bottom: 3px solid var(--gold) !important;
    align-items: center !important;
}

.topbar > .brand-header,
.topbar > div:first-child.brand-header {
    display: flex !important;
    align-items: center !important;
    gap: 8px !important;
    height: 41px !important;
    min-height: 41px !important;
    margin: 0 !important;
    padding: 0 !important;
}

.brand-header > div:last-child {
    display: flex !important;
    flex-direction: column !important;
    justify-content: center !important;
    align-items: flex-start !important;
    gap: 0 !important;
    height: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
    line-height: 1 !important;
}

.header-logo-wrap {
    width: 32px !important;
    height: 32px !important;
    flex: 0 0 32px !important;
    margin: 0 !important;
    padding: 0 !important;
}

.header-logo {
    width: 32px !important;
    height: 32px !important;
    margin: 0 !important;
    padding: 0 !important;
    object-fit: contain !important;
}

.header-logo-fallback {
    width: 32px !important;
    height: 32px !important;
    font-size: 9px !important;
}

.brand-header strong,
.topbar .brand-header strong {
    display: block !important;
    margin: 0 !important;
    padding: 0 !important;
    font-size: 14px !important;
    line-height: 15px !important;
    letter-spacing: .6px !important;
}

.brand-header > div:last-child > span,
.topbar .brand-header > div:last-child > span {
    display: block !important;
    margin: 1px 0 0 !important;
    padding: 0 !important;
    font-size: 10px !important;
    line-height: 11px !important;
}

.topbar-right {
    height: 41px !important;
    min-height: 41px !important;
    align-items: center !important;
    gap: 10px !important;
    margin: 0 !important;
    padding: 0 !important;
    font-size: 12px !important;
}

.dispatch-layout {
    min-height: calc(100vh - 44px) !important;
}

/* Mobile: retain compact brand row, allow controls beneath only if needed */
@media (max-width: 650px) {
    .topbar {
        height: auto !important;
        min-height: 44px !important;
        padding: 5px 9px !important;
    }

    .topbar > .brand-header,
    .topbar > div:first-child.brand-header {
        height: 34px !important;
        min-height: 34px !important;
    }

    .topbar-right {
        height: auto !important;
        min-height: 0 !important;
        padding: 2px 0 0 40px !important;
    }

    .header-logo-wrap,
    .header-logo,
    .header-logo-fallback {
        width: 30px !important;
        height: 30px !important;
    }

    .header-logo-wrap {
        flex-basis: 30px !important;
    }
}


/* ============================================================
   v0.4.3 - Dark mode
   Persistent per-browser theme toggle. If the user has never
   selected a theme, the browser/OS preference is used.
   ============================================================ */

.theme-toggle {
    min-width: 52px;
    color: #fff;
    opacity: .92;
}

.theme-toggle:hover {
    opacity: 1;
    text-decoration: none !important;
}

/* Dark palette */
html[data-theme="dark"] {
    --navy: #0d2234;
    --navy2: #75b5e3;
    --blue: #2f86c5;
    --gold: #e2ad3b;
    --red: #d65757;
    --green: #39a66a;
    --bg: #0b1117;
    --panel: #111b24;
    --text: #e6edf3;
    --muted: #94a5b4;
    --line: #293946;
    --shadow: 0 8px 24px rgba(0, 0, 0, .28);
    color-scheme: dark;
}

html[data-theme="dark"] body {
    background: var(--bg);
    color: var(--text);
}

html[data-theme="dark"] .topbar {
    background: #10283b;
}

html[data-theme="dark"] .panel,
html[data-theme="dark"] .modal-card,
html[data-theme="dark"] .login-card {
    background: var(--panel);
    border-color: var(--line);
    color: var(--text);
}

html[data-theme="dark"] .panel h2,
html[data-theme="dark"] .incident-title,
html[data-theme="dark"] .user-status-identity strong,
html[data-theme="dark"] .unit-banner strong,
html[data-theme="dark"] label,
html[data-theme="dark"] fieldset,
html[data-theme="dark"] .admin-user-main strong,
html[data-theme="dark"] .group-card h3,
html[data-theme="dark"] .subgroup-row strong {
    color: #eaf3fa;
}

html[data-theme="dark"] .panel p,
html[data-theme="dark"] .incident-number,
html[data-theme="dark"] .incident-meta,
html[data-theme="dark"] .unit-banner small,
html[data-theme="dark"] .eyebrow,
html[data-theme="dark"] .user-status-identity span,
html[data-theme="dark"] .user-status-time,
html[data-theme="dark"] .status-refresh,
html[data-theme="dark"] .admin-user-main span {
    color: var(--muted);
}

html[data-theme="dark"] .incident-card,
html[data-theme="dark"] .user-status-row,
html[data-theme="dark"] .admin-user-row,
html[data-theme="dark"] .group-card,
html[data-theme="dark"] .subgroup-row {
    background: #14212b;
    border-color: var(--line);
}

html[data-theme="dark"] .admin-user-row:hover {
    background: #192a36;
    border-color: #3a5265;
}

html[data-theme="dark"] .priority-badge {
    background: #22323e;
    color: #eef5fa;
}

html[data-theme="dark"] .tag,
html[data-theme="dark"] .org-badge {
    background: #18344a;
    color: #a9d5f2;
}

html[data-theme="dark"] .role-badge {
    background: #24343f;
    color: #c9d6df;
}

html[data-theme="dark"] .active-badge.yes {
    background: #173a2b;
    color: #79d6a2;
}

html[data-theme="dark"] .active-badge.no {
    background: #42232a;
    color: #f0a0ae;
}

html[data-theme="dark"] input,
html[data-theme="dark"] select,
html[data-theme="dark"] textarea {
    background: #0c151c;
    color: #ecf3f8;
    border-color: #3a4c59;
}

html[data-theme="dark"] input::placeholder,
html[data-theme="dark"] textarea::placeholder {
    color: #728390;
}

html[data-theme="dark"] input:focus,
html[data-theme="dark"] select:focus,
html[data-theme="dark"] textarea:focus {
    border-color: #438fc4;
    outline: none;
    box-shadow: 0 0 0 2px rgba(47, 134, 197, .16);
}

html[data-theme="dark"] fieldset {
    border-color: var(--line);
}

html[data-theme="dark"] .btn {
    background: #1b2a35;
    color: #e6edf3;
    border-color: #3a4b58;
}

html[data-theme="dark"] .btn:hover {
    background: #243846;
}

html[data-theme="dark"] .btn.primary {
    background: var(--blue);
    border-color: var(--blue);
    color: #fff;
}

html[data-theme="dark"] .btn.danger {
    background: #a73d43;
    border-color: #a73d43;
    color: #fff;
}

html[data-theme="dark"] .unit-banner {
    background: #122433;
    border-bottom-color: #2b4050;
}

html[data-theme="dark"] .empty {
    color: var(--muted);
    border-color: #415260;
    background: rgba(255, 255, 255, .015);
}

html[data-theme="dark"] .pulsepoint-mobile-placeholder {
    background: #101b23;
    border-color: #3d4d59;
    color: var(--muted);
}

html[data-theme="dark"] .pulsepoint-mobile-placeholder strong {
    color: #eaf3fa;
}

/* Status chips retain semantic colors but are darkened for contrast. */
html[data-theme="dark"] .unit-status-badge.available {
    background: #173a2b;
    color: #79d6a2;
    border-color: #285b43;
}

html[data-theme="dark"] .unit-status-badge.assigned {
    background: #173149;
    color: #86bee7;
    border-color: #2b5270;
}

html[data-theme="dark"] .unit-status-badge.en-route {
    background: #443318;
    color: #f0c670;
    border-color: #6b5227;
}

html[data-theme="dark"] .unit-status-badge.on-scene {
    background: #45251c;
    color: #f1a184;
    border-color: #6f3c2c;
}

html[data-theme="dark"] .unit-status-badge.clear {
    background: #28333b;
    color: #c0ccd4;
    border-color: #42515c;
}

html[data-theme="dark"] .unit-status-badge.out-of-service {
    background: #42232a;
    color: #f0a0ae;
    border-color: #633640;
}

html[data-theme="dark"] .admin-active-check {
    background: #101a22;
    border-color: var(--line);
}

/* Alerts */
html[data-theme="dark"] .alert.error {
    background: #402126;
    border-color: #6b353d;
    color: #ffb3bd;
}

html[data-theme="dark"] .alert.success {
    background: #173629;
    border-color: #2b5d45;
    color: #91d7ac;
}

/* PulsePoint itself is cross-origin and keeps whatever theme it provides.
   We only theme its surrounding EMCOMM panel. */
html[data-theme="dark"] .pulsepoint-frame {
    border-color: #30414e;
    background: #101820;
}

@media (max-width: 650px) {
    .theme-toggle {
        min-width: auto;
    }
}


/* ============================================================
   v0.4.4 - Dark mode contrast/status fixes
   ============================================================ */

/* Restore unmistakable MDT status colors in dark mode */
html[data-theme="dark"] .status-btn {
    color: #fff !important;
    border-color: transparent !important;
    font-weight: 800;
}

html[data-theme="dark"] .status-btn[data-status="AVAILABLE"] {
    background: #1f7a45 !important;
}
html[data-theme="dark"] .status-btn[data-status="ASSIGNED"] {
    background: #235f9a !important;
}
html[data-theme="dark"] .status-btn[data-status="EN ROUTE"] {
    background: #b77713 !important;
}
html[data-theme="dark"] .status-btn[data-status="ON SCENE"] {
    background: #b34e2c !important;
}
html[data-theme="dark"] .status-btn[data-status="CLEAR"] {
    background: #586975 !important;
}
html[data-theme="dark"] .status-btn[data-status="OUT OF SERVICE"] {
    background: #8f303b !important;
}

html[data-theme="dark"] .status-btn.active {
    outline: 3px solid #fff !important;
    outline-offset: 2px;
    box-shadow: 0 0 0 2px rgba(0,0,0,.45) !important;
}

/* Group manager/list contrast */
html[data-theme="dark"] .group-card,
html[data-theme="dark"] .group-list-item,
html[data-theme="dark"] .group-row,
html[data-theme="dark"] .subgroup-row {
    background: #14212b !important;
    color: #eaf3fa !important;
    border-color: #304351 !important;
}

html[data-theme="dark"] .group-card *,
html[data-theme="dark"] .group-list-item *,
html[data-theme="dark"] .group-row *,
html[data-theme="dark"] .subgroup-row * {
    color: inherit;
}

html[data-theme="dark"] .group-card h3,
html[data-theme="dark"] .group-card strong,
html[data-theme="dark"] .group-list-item strong,
html[data-theme="dark"] .group-row strong,
html[data-theme="dark"] .subgroup-row strong {
    color: #ffffff !important;
}

html[data-theme="dark"] .group-card small,
html[data-theme="dark"] .group-list-item small,
html[data-theme="dark"] .group-row small,
html[data-theme="dark"] .subgroup-row small,
html[data-theme="dark"] .group-card .muted,
html[data-theme="dark"] .group-list-item .muted {
    color: #9fb1bf !important;
}

html[data-theme="dark"] .group-card input,
html[data-theme="dark"] .group-card select,
html[data-theme="dark"] .group-card textarea,
html[data-theme="dark"] .subgroup-row input,
html[data-theme="dark"] .subgroup-row select {
    background: #0b141b !important;
    color: #f4f7fa !important;
    border-color: #415566 !important;
}

/* User settings/editor readability */
html[data-theme="dark"] .admin-editor-panel,
html[data-theme="dark"] .admin-users-panel,
html[data-theme="dark"] .admin-user-form {
    color: #eaf3fa !important;
}

html[data-theme="dark"] .admin-user-form label,
html[data-theme="dark"] .admin-user-form legend,
html[data-theme="dark"] .admin-user-form .check,
html[data-theme="dark"] .admin-editor-panel label,
html[data-theme="dark"] .admin-editor-panel legend {
    color: #dce8f0 !important;
}

html[data-theme="dark"] .admin-user-form input,
html[data-theme="dark"] .admin-user-form select,
html[data-theme="dark"] .admin-user-form textarea,
html[data-theme="dark"] .admin-editor-panel input,
html[data-theme="dark"] .admin-editor-panel select,
html[data-theme="dark"] .admin-editor-panel textarea {
    background: #0b141b !important;
    color: #f7fafc !important;
    border-color: #415566 !important;
}

html[data-theme="dark"] .admin-user-form option,
html[data-theme="dark"] .admin-editor-panel option {
    background: #101a22 !important;
    color: #f7fafc !important;
}

html[data-theme="dark"] .admin-user-row {
    background: #14212b !important;
    color: #eaf3fa !important;
}

html[data-theme="dark"] .admin-user-row:hover {
    background: #1b2c39 !important;
}

html[data-theme="dark"] .admin-user-main strong {
    color: #ffffff !important;
}

html[data-theme="dark"] .admin-user-main span {
    color: #a4b5c2 !important;
}

/* Make generic light backgrounds inside admin/group screens dark as a safety net */
html[data-theme="dark"] .admin-layout [style*="background: #fff"],
html[data-theme="dark"] .admin-layout [style*="background:#fff"],
html[data-theme="dark"] .admin-layout [style*="background: white"],
html[data-theme="dark"] .admin-layout [style*="background:white"] {
    background: #14212b !important;
    color: #eaf3fa !important;
}


/* ============================================================
   v0.4.5 - Exact dark-mode fixes for v0.4 group/admin selectors
   ============================================================ */

/*
 * The v0.4 application uses these exact classes for group and
 * membership rows:
 *   .target-group-block
 *   .membership-group
 *   .group-admin-row
 *   .system-admin-group
 *
 * These override the hard-coded light backgrounds in the base CSS.
 */

/* Dispatch targeting + Admin user membership boxes */
html[data-theme="dark"] .target-group-block,
html[data-theme="dark"] .membership-group {
    background: #14212b !important;
    color: #eaf3fa !important;
    border-color: #304351 !important;
}

html[data-theme="dark"] .target-group-block:hover,
html[data-theme="dark"] .membership-group:hover {
    background: #182936 !important;
}

html[data-theme="dark"] .target-group-block label,
html[data-theme="dark"] .membership-group label,
html[data-theme="dark"] .target-group-name,
html[data-theme="dark"] .membership-group strong {
    color: #f4f8fb !important;
}

html[data-theme="dark"] .target-subgroups,
html[data-theme="dark"] .membership-subgroups {
    color: #c7d4dd !important;
}

html[data-theme="dark"] .target-subgroups label,
html[data-theme="dark"] .membership-subgroups label {
    color: #c7d4dd !important;
}

/* System-managed EMCOMM Admin membership */
html[data-theme="dark"] .system-admin-group {
    background: #3a311b !important;
    color: #ffe3a1 !important;
    border-color: #6a5828 !important;
}

html[data-theme="dark"] .system-admin-group label,
html[data-theme="dark"] .system-admin-group strong,
html[data-theme="dark"] .system-admin-group span {
    color: #ffe3a1 !important;
}

/* Group Administration list */
html[data-theme="dark"] .group-admin-row {
    background: #14212b !important;
    color: #eaf3fa !important;
    border-color: #304351 !important;
}

html[data-theme="dark"] .group-admin-row:hover {
    background: #1b2c39 !important;
    border-color: #41586a !important;
}

html[data-theme="dark"] .group-admin-row > div strong {
    color: #ffffff !important;
}

html[data-theme="dark"] .group-admin-row > div span {
    color: #9fb1bf !important;
}

/* Subgroup administration rows */
html[data-theme="dark"] .subgroup-admin-row {
    background: #101b23 !important;
    color: #eaf3fa !important;
    border-color: #304351 !important;
}

html[data-theme="dark"] .subgroup-admin-row strong,
html[data-theme="dark"] .subgroup-admin-row span,
html[data-theme="dark"] .subgroup-admin-row label {
    color: #eaf3fa !important;
}

/* Admin user settings: checkbox rows and membership text */
html[data-theme="dark"] .admin-user-form .membership-group,
html[data-theme="dark"] .admin-editor-panel .membership-group {
    background: #14212b !important;
    color: #eaf3fa !important;
}

html[data-theme="dark"] .admin-user-form .membership-group *,
html[data-theme="dark"] .admin-editor-panel .membership-group * {
    color: inherit;
}

/* Keep form controls dark even when nested inside membership/group blocks */
html[data-theme="dark"] .membership-group input,
html[data-theme="dark"] .membership-group select,
html[data-theme="dark"] .target-group-block input,
html[data-theme="dark"] .target-group-block select,
html[data-theme="dark"] .group-admin-row input,
html[data-theme="dark"] .group-admin-row select,
html[data-theme="dark"] .subgroup-admin-row input,
html[data-theme="dark"] .subgroup-admin-row select {
    background: #0b141b !important;
    color: #f7fafc !important;
    border-color: #415566 !important;
}

/* Native checkbox/radio accent color */
html[data-theme="dark"] input[type="checkbox"],
html[data-theme="dark"] input[type="radio"] {
    accent-color: #2f86c5;
}

/* MDT status board - reinforce exact semantic colors */
html[data-theme="dark"] .status-buttons .status-btn[data-status="AVAILABLE"] {
    background: #1f7a45 !important;
    color: #fff !important;
}

html[data-theme="dark"] .status-buttons .status-btn[data-status="ASSIGNED"] {
    background: #235f9a !important;
    color: #fff !important;
}

html[data-theme="dark"] .status-buttons .status-btn[data-status="EN ROUTE"] {
    background: #b77713 !important;
    color: #fff !important;
}

html[data-theme="dark"] .status-buttons .status-btn[data-status="ON SCENE"] {
    background: #b34e2c !important;
    color: #fff !important;
}

html[data-theme="dark"] .status-buttons .status-btn[data-status="CLEAR"] {
    background: #586975 !important;
    color: #fff !important;
}

html[data-theme="dark"] .status-buttons .status-btn[data-status="OUT OF SERVICE"] {
    background: #8f303b !important;
    color: #fff !important;
}

html[data-theme="dark"] .status-buttons .status-btn.active {
    outline: 3px solid #ffffff !important;
    outline-offset: 2px !important;
    box-shadow: 0 0 0 2px rgba(0,0,0,.55) !important;
}
