:root {
    --navy: #172554;
    --navy-dark: #0f172a;
    --blue: #2563eb;
    --gold: #f4b400;
    --green: #15803d;
    --green-bg: #dcfce7;
    --red: #b91c1c;
    --red-bg: #fee2e2;
    --orange: #c2410c;
    --orange-bg: #ffedd5;
    --gray-50: #f8fafc;
    --gray-100: #f1f5f9;
    --gray-200: #e2e8f0;
    --gray-500: #64748b;
    --gray-700: #334155;
    --white: #ffffff;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family:
        Inter,
        ui-sans-serif,
        system-ui,
        -apple-system,
        BlinkMacSystemFont,
        "Segoe UI",
        sans-serif;
    background: var(--gray-50);
    color: var(--navy-dark);
}

button,
input {
    font: inherit;
}

button {
    cursor: pointer;
}

.topbar {
    height: 72px;
    background: var(--navy-dark);
    color: white;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 34px;
    box-shadow: 0 2px 12px rgba(0,0,0,.16);
}

.brand,
.admin-area {
    display: flex;
    align-items: center;
    gap: 14px;
}

.brand strong {
    display: block;
    font-size: 17px;
}

.brand span {
    display: block;
    margin-top: 2px;
    color: #94a3b8;
    font-size: 12px;
}

.mark {
    width: 44px;
    height: 44px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--gold);
    color: var(--navy-dark);
    font-weight: 900;
}

.admin-area {
    font-size: 13px;
}

.dashboard {
    max-width: 1500px;
    margin: auto;
    padding: 36px;
}

.page-heading {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    gap: 30px;
    margin-bottom: 30px;
}

.page-heading h1 {
    margin: 3px 0 6px;
    font-size: 31px;
}

.page-heading p {
    color: var(--gray-500);
    margin: 0;
}

.eyebrow {
    color: var(--blue) !important;
    font-weight: 800;
    font-size: 12px;
    letter-spacing: .12em;
}

.stats {
    display: grid;
    grid-template-columns: repeat(4,1fr);
    gap: 18px;
    margin-bottom: 26px;
}

.stat-card {
    background: white;
    border: 1px solid var(--gray-200);
    border-radius: 14px;
    padding: 22px;
    box-shadow: 0 4px 16px rgba(15,23,42,.04);
}

.stat-card span,
.stat-card small {
    display: block;
    color: var(--gray-500);
}

.stat-card strong {
    display: block;
    font-size: 34px;
    margin: 8px 0 5px;
}

.online-card strong {
    color: var(--green);
}

.offline-card strong {
    color: var(--red);
}

.pending-card strong {
    color: var(--orange);
}

.panel {
    background: white;
    border: 1px solid var(--gray-200);
    border-radius: 14px;
    margin-bottom: 26px;
    overflow: hidden;
    box-shadow: 0 4px 16px rgba(15,23,42,.04);
}

.panel-heading {
    padding: 22px 24px;
    border-bottom: 1px solid var(--gray-200);
}

.panel-heading h2 {
    margin: 0 0 5px;
    font-size: 19px;
}

.panel-heading p {
    margin: 0;
    color: var(--gray-500);
    font-size: 13px;
}

.empty-state {
    padding: 38px;
    text-align: center;
    color: var(--gray-500);
}

.empty-state strong,
.empty-state span {
    display: block;
}

.empty-state strong {
    color: var(--gray-700);
    margin-bottom: 6px;
}

.pending-device {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 24px;
    border-bottom: 1px solid var(--gray-200);
}

.device-main {
    display: flex;
    gap: 16px;
    align-items: center;
}

.device-main strong,
.device-main span {
    display: block;
}

.device-main span {
    color: var(--gray-500);
    font-size: 12px;
    margin-top: 3px;
}

.device-icon {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    background: var(--navy);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
}

.pending-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

.state-badge,
.status {
    text-transform: capitalize;
    font-size: 12px;
    font-weight: 700;
    border-radius: 999px;
    padding: 6px 10px;
}

.state-badge.pending {
    background: var(--orange-bg);
    color: var(--orange);
}

.state-badge.approved {
    background: var(--green-bg);
    color: var(--green);
}

.state-badge.rejected {
    background: var(--red-bg);
    color: var(--red);
}

.table-wrap {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
}

th,
td {
    text-align: left;
    padding: 16px 18px;
    border-bottom: 1px solid var(--gray-200);
    font-size: 13px;
}

th {
    background: var(--gray-50);
    color: var(--gray-500);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .04em;
}

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

.status i {
    width: 8px;
    height: 8px;
    border-radius: 50%;
}

.status.online {
    background: var(--green-bg);
    color: var(--green);
}

.status.online i {
    background: var(--green);
}

.status.offline {
    background: var(--red-bg);
    color: var(--red);
}

.status.offline i {
    background: var(--red);
}

.mono {
    font-family:
        ui-monospace,
        SFMono-Regular,
        Menlo,
        monospace;
}

.refresh-button,
.approve-button,
.reject-button,
.secondary-button {
    border: 0;
    border-radius: 8px;
    padding: 9px 14px;
    font-weight: 700;
}

.refresh-button,
.approve-button {
    background: var(--navy);
    color: white;
}

.reject-button {
    background: var(--red-bg);
    color: var(--red);
}

.secondary-button {
    background: rgba(255,255,255,.1);
    color: white;
}

.text-button {
    background: none;
    border: 0;
    color: var(--blue);
    font-weight: 700;
}

.message {
    display: none;
    position: fixed;
    right: 24px;
    bottom: 24px;
    max-width: 420px;
    padding: 14px 18px;
    border-radius: 10px;
    box-shadow: 0 10px 35px rgba(0,0,0,.18);
    font-size: 13px;
    font-weight: 600;
}

.message.show {
    display: block;
    background: var(--green);
    color: white;
}

.message.show.error {
    background: var(--red);
}

body.login {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background:
        linear-gradient(
            135deg,
            var(--navy-dark),
            var(--navy)
        );
}

.login .card {
    width: 100%;
    max-width: 420px;
    background: white;
    border-radius: 16px;
    padding: 34px;
    box-shadow: 0 25px 70px rgba(0,0,0,.3);
}

.login .card .mark {
    margin-bottom: 20px;
}

.login .card h1 {
    margin: 6px 0 25px;
}

.login .card > p {
    color: var(--gray-500);
    margin: 0;
}

.login label {
    display: block;
    margin-bottom: 16px;
    font-size: 13px;
    font-weight: 700;
}

.login input {
    width: 100%;
    margin-top: 7px;
    padding: 12px;
    border: 1px solid var(--gray-200);
    border-radius: 8px;
    outline: none;
}

.login input:focus {
    border-color: var(--blue);
}

.login button[type="submit"] {
    width: 100%;
    border: 0;
    border-radius: 8px;
    padding: 12px;
    background: var(--navy);
    color: white;
    font-weight: 800;
    margin-top: 4px;
}

.login small {
    display: block;
    text-align: center;
    margin-top: 22px;
    color: var(--gray-500);
}

@media (max-width: 900px) {

    .stats {
        grid-template-columns: repeat(2,1fr);
    }

    .dashboard {
        padding: 22px;
    }

    .topbar {
        padding: 0 20px;
    }

    .admin-area > span {
        display: none;
    }

}

@media (max-width: 600px) {

    .stats {
        grid-template-columns: 1fr;
    }

    .page-heading,
    .pending-device {
        align-items: flex-start;
        flex-direction: column;
    }

    .pending-actions {
        width: 100%;
        flex-wrap: wrap;
    }

    .brand span {
        display: none;
    }

}

.tower-link {
    color: var(--navy-dark);
    font-weight: 800;
    text-decoration: none;
}

.tower-link:hover {
    color: var(--blue);
    text-decoration: underline;
}

.page-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

.secondary-link-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    padding: 9px 14px;
    font-weight: 700;
    text-decoration: none;
    color: var(--navy);
    background: white;
    border: 1px solid var(--gray-200);
}

.action-grid {
    display: grid;
    grid-template-columns: repeat(3,1fr);
    gap: 18px;
    padding: 22px;
}

.action-card {
    border: 1px solid var(--gray-200);
    border-radius: 12px;
    padding: 20px;
    background: var(--gray-50);
}

.action-card h3 {
    margin: 0 0 8px;
    font-size: 16px;
}

.action-card p {
    color: var(--gray-500);
    font-size: 13px;
    min-height: 56px;
}

.warning-button {
    border: 0;
    border-radius: 8px;
    padding: 9px 14px;
    font-weight: 700;
    background: var(--orange-bg);
    color: var(--orange);
}

.telemetry-grid {
    display: grid;
    grid-template-columns: repeat(4,1fr);
    gap: 0;
}

.telemetry-card {
    padding: 20px;
    min-height: 120px;
    border-right: 1px solid var(--gray-200);
    border-bottom: 1px solid var(--gray-200);
}

.telemetry-card span,
.telemetry-card small {
    display: block;
}

.telemetry-card span {
    color: var(--gray-500);
    font-size: 12px;
    margin-bottom: 8px;
}

.telemetry-card strong {
    font-size: 16px;
}

.telemetry-card small {
    margin-top: 7px;
    color: var(--gray-500);
    word-break: break-word;
}

.value-online {
    color: var(--green);
}

.value-offline {
    color: var(--red);
}

.command-state {
    display: inline-block;
    padding: 5px 9px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 800;
    text-transform: uppercase;
}

.command-state.completed {
    color: var(--green);
    background: var(--green-bg);
}

.command-state.failed {
    color: var(--red);
    background: var(--red-bg);
}

.command-state.queued,
.command-state.delivered {
    color: var(--orange);
    background: var(--orange-bg);
}

.command-state.expired {
    color: var(--gray-700);
    background: var(--gray-200);
}

@media (max-width: 1000px) {

    .telemetry-grid {
        grid-template-columns: repeat(2,1fr);
    }

    .action-grid {
        grid-template-columns: 1fr;
    }

}

@media (max-width: 600px) {

    .telemetry-grid {
        grid-template-columns: 1fr;
    }

    .page-actions {
        width: 100%;
        flex-wrap: wrap;
    }

}

/* =========================================================
   TRESPASS ALERT
   ========================================================= */

.trespass-modal[hidden] {
    display: none !important;
}

.trespass-modal {
    position: fixed;
    inset: 0;
    z-index: 10000;
    background: rgba(0,0,0,.82);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.trespass-panel {
    width: min(1000px, 96vw);
    max-height: 94vh;
    overflow: auto;
    background: #fff;
    border-radius: 14px;
    box-shadow: 0 20px 80px rgba(0,0,0,.55);
}

.trespass-header {
    background: #a80000;
    color: #fff;
    padding: 18px 22px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    font-size: 22px;
}

.trespass-header strong {
    letter-spacing: .04em;
}

.trespass-header span {
    font-size: 14px;
    margin-left: 8px;
}

.trespass-close {
    border: 0;
    border-radius: 8px;
    padding: 11px 18px;
    background: #fff;
    color: #7c0000;
    font-weight: 700;
    cursor: pointer;
}

.trespass-body {
    padding: 22px;
}

.trespass-meta {
    display: grid;
    grid-template-columns:
        repeat(3, minmax(0,1fr));
    gap: 14px;
    margin-bottom: 18px;
}

.trespass-meta div {
    background: #f4f5f7;
    border-radius: 9px;
    padding: 13px;
}

.trespass-meta span {
    display: block;
    font-size: 12px;
    color: #666;
    margin-bottom: 5px;
}

.trespass-media {
    min-height: 360px;
    background: #111;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.trespass-media video,
.trespass-media img {
    width: 100%;
    max-height: 65vh;
    object-fit: contain;
}

.trespass-no-video {
    color: #fff;
    text-align: center;
    padding: 40px;
    max-width: 600px;
}

@media (max-width: 700px) {
    .trespass-meta {
        grid-template-columns: 1fr;
    }

    .trespass-header {
        font-size: 17px;
    }

    .trespass-media {
        min-height: 220px;
    }
}


/* User Management buttons: visible on white panel */
#mps-users-panel .secondary-button {
    background: #173b68;
    color: #ffffff;
    border: 1px solid #173b68;
    cursor: pointer;
}

#mps-users-panel .secondary-button:hover {
    background: #24558c;
}

#mps-users-panel .secondary-button:focus-visible {
    outline: 3px solid #f59e0b;
    outline-offset: 2px;
}


/* MPS NONBLOCKING HUMAN DETECTION NOTIFICATION */
.trespass-modal:not([hidden]) {
    position: fixed;
    inset: auto 18px 18px auto;
    width: min(520px, calc(100vw - 36px));
    height: auto;
    max-height: 85vh;
    padding: 0;
    background: transparent;
    display: block;
    pointer-events: none;
    z-index: 10000;
}

.trespass-panel {
    width: 100%;
    max-height: 85vh;
    pointer-events: auto;
    box-shadow: 0 8px 35px rgba(0,0,0,.3);
}

.trespass-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.trespass-actions .trespass-close {
    padding: 8px 10px;
    font-size: 13px;
}

.trespass-restore:not([hidden]) {
    position: fixed;
    right: 18px;
    bottom: 18px;
    z-index: 10000;
    border: 0;
    border-radius: 10px;
    background: #a80000;
    color: #fff;
    padding: 12px 18px;
    font-weight: 700;
    cursor: pointer;
}

@media (max-width: 700px) {
    .trespass-modal:not([hidden]) {
        right: 8px;
        bottom: 8px;
        width: calc(100vw - 16px);
    }
    .trespass-header {
        padding: 10px;
        gap: 8px;
    }
    .trespass-media {
        min-height: 160px;
    }
}

/* MPS Fleet GPS Map */
#mps-fleet-map {
    height: 440px;
    width: 100%;
    border-radius: 10px;
    border: 1px solid #cbd5e1;
    background: #e2e8f0;
    margin: 14px 0;
}

.mps-map-toolbar {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
}

#mps-map-tower-select {
    padding: 8px 12px;
    border: 1px solid #cbd5e1;
    border-radius: 7px;
    max-width: 300px;
}

#mps-map-status {
    color: #475569;
    font-size: 13px;
}

#mps-map-details {
    padding: 12px;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    background: #f8fafc;
    line-height: 1.7;
}

.mps-gps-pin {
    width: 18px;
    height: 18px;
    border: 3px solid white;
    border-radius: 50%;
    box-shadow: 0 1px 6px #334155;
}

.mps-gps-pin.red {
    background: #dc2626;
}

.mps-gps-pin.green {
    background: #16a34a;
}
