/* ============================================================
   CSO Dashboard - dark security-ops theme
   ============================================================ */

:root {
    --bg:            #0f1116;
    --panel:         #171a22;
    --panel-border:  #262b38;
    --text:          #e8eaf0;
    --text-dim:      #8a90a3;
    --accent:        #3b82f6;
    --green:         #22c55e;
    --amber:         #f59e0b;
    --red:           #ef4444;
    --grey:          #4b5163;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
}

/* ============================================================
   Login page (index.html) - structure mirrors gate_app/css/styles.css
   ============================================================ */

.app-container {
    max-width: 420px;
    margin: 0 auto;
    padding: 24px;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.login-header {
    display: flex;
    align-items: center;
    gap: 10px;
    justify-content: center;
    font-size: 22px;
    font-weight: 700;
    margin-bottom: 32px;
    color: var(--text);
}

.brand-logo { width: 64px; height: 64px; object-fit: contain; }

.login-content { display: flex; flex-direction: column; gap: 16px; }

.login-title {
    text-align: center;
    font-size: 16px;
    font-weight: 500;
    color: var(--text-dim);
    margin: 0 0 8px;
}

.input-wrapper { position: relative; }

.input-wrapper input {
    width: 100%;
    padding: 16px 44px 16px 44px;
    background: var(--panel);
    border: 1px solid var(--panel-border);
    border-radius: 12px;
    color: var(--text);
    font-size: 15px;
}

.input-wrapper input:focus { outline: none; border-color: var(--accent); }

.input-icon {
    position: absolute;
    left: 16px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-dim);
}

.dropdown-icon, .toggle-password {
    position: absolute;
    right: 16px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-dim);
    cursor: pointer;
}

.pseudo-select { cursor: pointer; }

.floating-label {
    position: absolute;
    left: 44px;
    top: -9px;
    background: var(--bg);
    padding: 0 4px;
    font-size: 12px;
    color: var(--text-dim);
}

.btn-large {
    width: 100%;
    padding: 16px;
    border: none;
    border-radius: 12px;
    background: var(--accent);
    color: #fff;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.btn-large:disabled { opacity: 0.6; cursor: default; }
.btn-large.btn-secondary { background: var(--panel-border); color: var(--text); }

.error-message { color: var(--red); font-size: 13px; text-align: center; min-height: 16px; }

.modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
}

.modal.hidden { display: none; }

.modal-content {
    background: var(--panel);
    border: 1px solid var(--panel-border);
    border-radius: 12px;
    padding: 20px;
    width: 90%;
    max-width: 400px;
    height: 80%;
    max-height: 70vh;
    display: flex;
    flex-direction: column;
}

.modal-title { margin: 0 0 12px; font-size: 18px; }

.search-box {
    width: 100%;
    padding: 12px;
    border-radius: 10px;
    border: 1px solid var(--panel-border);
    background: var(--bg);
    color: var(--text);
    margin-bottom: 12px;
}

.estate-list { overflow-y: auto; flex: 1; }

.estate-item {
    padding: 14px 8px;
    border-bottom: 1px solid var(--panel-border);
    cursor: pointer;
}

.estate-item:hover { background: var(--panel-border); }

.loading-text { padding: 15px; color: var(--text-dim); }

.close-btn {
    margin-top: 12px;
    padding: 14px;
    border: none;
    border-radius: 10px;
    background: var(--panel-border);
    color: var(--text);
    cursor: pointer;
}

/* ============================================================
   Bottom Sheet - same idiom as gate_app/js/auth.js's SheetUI
   ============================================================ */

.sheet-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 3000;
    display: none;
    opacity: 0;
    transition: opacity 0.3s ease;
    backdrop-filter: blur(2px);
}

.sheet-overlay.active { display: block; opacity: 1; }

.bottom-sheet {
    position: fixed;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%) translateY(100%);
    width: 100%;
    max-width: 480px;
    background: var(--panel);
    border: 1px solid var(--panel-border);
    border-bottom: none;
    border-radius: 20px 20px 0 0;
    z-index: 3001;
    padding: 20px;
    box-sizing: border-box;
    transition: transform 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
}

.bottom-sheet.active { transform: translateX(-50%) translateY(0); }

.sheet-handle {
    width: 40px;
    height: 5px;
    background: var(--panel-border);
    border-radius: 10px;
    margin: 0 auto 20px auto;
}

.sheet-title { font-size: 18px; font-weight: 700; margin-bottom: 10px; text-align: center; }
.sheet-body { font-size: 15px; color: var(--text-dim); line-height: 1.5; margin-bottom: 22px; text-align: center; }
.sheet-actions { display: flex; flex-direction: column; gap: 12px; }
.sheet-actions .btn-large { padding: 15px; font-size: 15px; }
.sheet-actions-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

@media print { .sheet-overlay, .bottom-sheet { display: none !important; } }

/* ============================================================
   Dashboard shell
   ============================================================ */

.dash-header {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 12px 20px;
    background: var(--panel);
    border-bottom: 1px solid var(--panel-border);
    position: sticky;
    top: 0;
    z-index: 100;
}

.dash-header .brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 16px; }
.dash-header .brand i { color: var(--accent); }

.sos-badge {
    display: none;
    align-items: center;
    gap: 6px;
    background: var(--red);
    color: #fff;
    padding: 4px 10px;
    border-radius: 999px;
    font-size: 13px;
    font-weight: 700;
}

.sos-badge.active { display: flex; }

.dash-clock { font-variant-numeric: tabular-nums; color: var(--text-dim); font-size: 14px; }

.header-spacer { flex: 1; }

.icon-btn {
    background: none;
    border: 1px solid var(--panel-border);
    color: var(--text-dim);
    width: 36px;
    height: 36px;
    border-radius: 10px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.icon-btn:hover { color: var(--text); border-color: var(--accent); }
.icon-btn.muted { color: var(--red); border-color: var(--red); }

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

.panel {
    background: var(--panel);
    border: 1px solid var(--panel-border);
    border-radius: 14px;
    padding: 14px;
}

.panel h2 {
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-dim);
    margin: 0 0 12px;
    display: flex;
    align-items: center;
    gap: 8px;
}

/* --- Shifts --- */

.shift-card {
    border: 1px solid var(--panel-border);
    border-left: 4px solid var(--green);
    border-radius: 10px;
    padding: 10px 12px;
    margin-bottom: 10px;
}

.shift-card.solo { border-left-color: var(--amber); }
.shift-card.gap  { border-left-color: var(--red); }

.shift-card .gate-name { font-weight: 600; font-size: 14px; }
.shift-card .lead-line { font-size: 13px; color: var(--text-dim); margin-top: 2px; }
.shift-card .meta-row { display: flex; justify-content: space-between; margin-top: 8px; font-size: 12px; color: var(--text-dim); }
.shift-card .duration { font-variant-numeric: tabular-nums; }
.shift-card .no-shift { color: var(--red); font-weight: 600; font-size: 12px; display: flex; align-items: center; gap: 6px; margin-top: 4px; }

/* --- Devices --- */

.device-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 0;
    border-bottom: 1px solid var(--panel-border);
}

.device-row:last-child { border-bottom: none; }

.device-info { flex: 1; min-width: 0; }
.device-name { font-size: 13px; font-weight: 600; }
.device-meta { font-size: 12px; color: var(--text-dim); }

.status-pill {
    font-size: 11px;
    font-weight: 700;
    padding: 3px 8px;
    border-radius: 999px;
    display: flex;
    align-items: center;
    gap: 4px;
}

.status-pill.online  { background: rgba(34,197,94,0.15);  color: var(--green); }
.status-pill.idle    { background: rgba(245,158,11,0.15); color: var(--amber); }
.status-pill.offline { background: rgba(239,68,68,0.15);  color: var(--red); }

.battery-bar {
    width: 44px;
    height: 6px;
    border-radius: 3px;
    background: var(--panel-border);
    overflow: hidden;
}

.battery-bar > div { height: 100%; }

.locate-link { color: var(--accent); font-size: 12px; text-decoration: none; white-space: nowrap; }

/* --- Counts --- */

.count-cards { display: flex; gap: 10px; margin-bottom: 14px; }
.count-card { flex: 1; background: var(--bg); border: 1px solid var(--panel-border); border-radius: 10px; padding: 10px; text-align: center; }
.count-card .value { font-size: 22px; font-weight: 700; }
.count-card .label { font-size: 11px; color: var(--text-dim); text-transform: uppercase; }

.gate-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.gate-table th { text-align: left; color: var(--text-dim); font-weight: 500; padding: 4px 6px; border-bottom: 1px solid var(--panel-border); }
.gate-table td { padding: 6px; border-bottom: 1px solid var(--panel-border); }
.disclaimer { font-size: 11px; color: var(--text-dim); margin-top: 6px; }

/* --- Incident feed --- */

.incident-panel { grid-column: 1 / -1; }

.incident-card {
    border: 1px solid var(--panel-border);
    border-left: 4px solid var(--grey);
    border-radius: 10px;
    padding: 12px 14px;
    margin-bottom: 10px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

.incident-card.open {
    border-left-color: var(--red);
    animation: pulse-border 1.4s infinite;
}

.incident-card.responding { border-left-color: var(--amber); }
.incident-card.resolved   { opacity: 0.5; }

@keyframes pulse-border {
    0%, 100% { box-shadow: 0 0 0 0 rgba(239,68,68,0.4); }
    50%      { box-shadow: 0 0 0 6px rgba(239,68,68,0); }
}

.incident-main { flex: 1; min-width: 220px; }
.incident-title { font-weight: 700; font-size: 14px; display: flex; align-items: center; gap: 8px; }
.incident-title .time { color: var(--text-dim); font-weight: 400; font-size: 12px; }
.incident-detail { font-size: 13px; color: var(--text-dim); margin-top: 4px; }
.incident-status { font-size: 12px; margin-top: 6px; }
.incident-status.responding { color: var(--amber); }

.incident-actions { display: flex; gap: 8px; }

.btn-sm {
    padding: 8px 14px;
    border-radius: 8px;
    border: none;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
}

.btn-sm.respond  { background: var(--red); color: #fff; }
.btn-sm.navigate { background: var(--accent); color: #fff; text-decoration: none; }
.btn-sm.resolve  { background: var(--panel-border); color: var(--text); }

.empty-state { color: var(--text-dim); font-size: 13px; text-align: center; padding: 20px; }

/* --- Mobile: stack columns, incident feed becomes a bottom sheet-style drawer --- */

@media (max-width: 768px) {
    .dash-grid { grid-template-columns: 1fr; padding: 12px; padding-bottom: 90px; }
    .incident-panel { position: fixed; left: 0; right: 0; bottom: 0; margin: 0; border-radius: 16px 16px 0 0; max-height: 45vh; overflow-y: auto; z-index: 200; }
    .dash-header .brand span { display: none; }
}
