/* =========================================================
   Poseidon Demo — shared theme
   Design tokens + components used across all pages.
   ========================================================= */

:root {
    --bg-dark: #12121a;
    --bg-panel: #1e1e2d;
    --bg-panel-glass: rgba(30, 30, 45, 0.85);
    --text-main: #ffffff;
    --text-muted: #a0a0b0;
    --accent: #3b82f6;
    --accent-hover: #2563eb;
    --accent-soft: rgba(59, 130, 246, 0.15);
    --success: #10b981;
    --success-soft: rgba(16, 185, 129, 0.15);
    --danger: #ef4444;
    --danger-soft: rgba(239, 68, 68, 0.15);
    --border: rgba(255, 255, 255, 0.1);
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
    --radius-pill: 999px;
    --shadow-md: 0 8px 25px rgba(0, 0, 0, 0.45);
    --shadow-lg: 0 15px 35px rgba(0, 0, 0, 0.6);
}

/* Tells the browser to use its dark native-UI palette for anything CSS
   can't restyle directly — the coordinate-format <select>'s open dropdown
   list, scrollbars, etc. Without this, those render with the browser's
   light-theme default (white) regardless of our own styles, since an open
   <select> options list is drawn by the OS/browser chrome, not the page. */
:root { color-scheme: dark; }

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-dark);
    color: var(--text-main);
    -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); }

::selection { background: var(--accent-soft); color: var(--text-main); }

/* ---------- Layout: authenticated shell (map + sidebar) ---------- */

body.app-shell {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

#sidebar {
    width: 320px;
    flex-shrink: 0;
    background: var(--bg-panel);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    z-index: 20;
    box-shadow: 4px 0 15px rgba(0, 0, 0, 0.4);
    transition: margin-left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

#sidebar.collapsed { margin-left: -320px; }

.sidebar-header {
    padding: 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.sidebar-header h3 {
    margin: 0;
    font-size: 15px;
    font-weight: 700;
    letter-spacing: 1px;
    text-transform: uppercase;
    display: flex;
    align-items: center;
    gap: 10px;
}

.sidebar-close {
    display: none;
}

.mission-list {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
}

.mission-list::-webkit-scrollbar { width: 6px; }
.mission-list::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.15); border-radius: 4px; }

.mission-card {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: var(--radius-md);
    padding: 16px;
    margin-bottom: 12px;
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease, transform 0.15s ease;
}

.mission-card:hover,
.mission-card:focus-visible {
    background: rgba(255, 255, 255, 0.08);
    border-color: var(--accent);
    transform: translateY(-2px);
}

.mission-card.active { border-color: var(--accent); background: var(--accent-soft); }

.mission-title { font-weight: 600; margin-bottom: 6px; font-size: 14px; display: flex; align-items: center; gap: 8px; }
.mission-date { font-size: 12px; color: var(--text-muted); display: flex; align-items: center; gap: 6px; }

.empty-state {
    text-align: center;
    margin-top: 50px;
    color: var(--text-muted);
    padding: 0 20px;
}
.empty-state svg { width: 44px; height: 44px; opacity: 0.2; margin-bottom: 14px; }
.empty-state p { font-size: 13px; line-height: 1.6; }

#sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 15;
}

#main-content {
    flex: 1;
    position: relative;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

#map {
    position: absolute;
    top: 0; bottom: 0; left: 0; right: 0;
    z-index: 1;
}

/* ---------- Floating toolbar (glassmorphism) ---------- */

#floating-controls {
    position: absolute;
    top: 20px; left: 50%;
    transform: translateX(-50%);
    z-index: 10;
    max-width: calc(100vw - 40px);
    background: var(--bg-panel-glass);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--border);
    border-radius: var(--radius-pill);
    padding: 10px 20px;
    box-shadow: var(--shadow-md);
    display: flex;
    align-items: center;
    gap: 22px;
    flex-wrap: nowrap;
}

.controls-divider { width: 1px; height: 24px; background: rgba(255, 255, 255, 0.15); flex-shrink: 0; }

.controls-text { display: flex; flex-direction: column; align-items: center; white-space: nowrap; }
.controls-title { margin: 0; font-size: 14px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px; }
.controls-subtitle { margin: 2px 0 0 0; font-size: 11px; color: var(--text-muted); }

.mission-form {
    margin: 0;
    display: flex;
    gap: 10px;
    align-items: center;
}

.commander-tag {
    display: flex;
    align-items: center;
    gap: 12px;
    white-space: nowrap;
}
.commander-tag .label { display: block; font-size: 9px; text-transform: uppercase; letter-spacing: 1px; margin-bottom: 2px; color: var(--text-muted); }
.commander-tag strong { color: white; font-size: 13px; }

.icon-link-danger {
    color: var(--danger);
    background: var(--danger-soft);
    padding: 8px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    transition: background 0.15s ease;
    flex-shrink: 0;
}
.icon-link-danger:hover { background: rgba(239, 68, 68, 0.3); }

/* ---------- Buttons ---------- */

.btn {
    padding: 10px 18px;
    border-radius: var(--radius-pill);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    border: none;
    transition: background 0.15s ease, border-color 0.15s ease, transform 0.15s ease, box-shadow 0.15s ease;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    outline: none;
    font-family: inherit;
    white-space: nowrap;
}
.btn:focus-visible { box-shadow: 0 0 0 2px var(--bg-dark), 0 0 0 4px var(--accent); }
.btn svg { width: 16px; height: 16px; flex-shrink: 0; }

.btn-new { background: rgba(255, 255, 255, 0.08); color: var(--text-main); border: 1px solid rgba(255, 255, 255, 0.1); }
.btn-new:hover { background: rgba(255, 255, 255, 0.15); border-color: rgba(255, 255, 255, 0.3); }

.btn-save { background: var(--accent); color: white; box-shadow: 0 4px 15px rgba(59, 130, 246, 0.4); }
.btn-save:hover { background: var(--accent-hover); transform: translateY(-1px); box-shadow: 0 6px 20px rgba(59, 130, 246, 0.6); }

.btn-danger-outline { background: var(--danger-soft); color: #f87171; border: 1px solid rgba(239, 68, 68, 0.4); }
.btn-danger-outline:hover { background: rgba(239, 68, 68, 0.3); }

.btn-icon { background: transparent; color: var(--text-main); padding: 8px; border-radius: 50%; position: relative; }
.btn-icon:hover { background: rgba(255, 255, 255, 0.1); }

.btn-block { width: 100%; justify-content: center; }

.btn-primary { background: var(--accent); color: white; }
.btn-primary:hover { background: var(--accent-hover); }

.btn-success { background: var(--success); color: white; }
.btn-success:hover { background: #059669; }

.btn-sm { padding: 8px 14px; border-radius: var(--radius-sm); font-size: 13px; }
.btn-approve { background: var(--success-soft); color: #34d399; border: 1px solid rgba(16, 185, 129, 0.4); }
.btn-approve:hover { background: rgba(16, 185, 129, 0.4); }
.btn-reject { background: var(--danger-soft); color: #f87171; border: 1px solid rgba(239, 68, 68, 0.4); }
.btn-reject:hover { background: rgba(239, 68, 68, 0.4); }

.badge-count {
    position: absolute;
    top: 0; right: 0;
    background: var(--danger);
    color: white;
    font-size: 9px;
    font-weight: 700;
    height: 14px;
    min-width: 14px;
    border-radius: 7px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 3px;
    border: 2px solid var(--bg-panel);
}

/* ---------- Form fields ---------- */

.field-input,
input[type="text"].field-input,
input[type="password"].field-input,
input[type="email"].field-input {
    padding: 10px 15px;
    border-radius: var(--radius-pill);
    border: 1px solid rgba(255, 255, 255, 0.2);
    background: rgba(0, 0, 0, 0.4);
    color: white;
    outline: none;
    font-family: inherit;
    font-size: 14px;
    transition: border-color 0.15s ease;
}
.field-input:focus { border-color: var(--accent); }

/* ---------- MapLibre + Mapbox Draw overrides ---------- */

.maplibregl-ctrl-group {
    background: var(--bg-panel) !important;
    border: 1px solid var(--border) !important;
    border-radius: 8px !important;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4) !important;
}
.maplibregl-ctrl button { filter: invert(1); opacity: 0.7; }
.maplibregl-ctrl button:hover { opacity: 1; }

/* !important throughout this block: maplibre-gl.css loads after theme.css
   (it's in each page's extra_head block, which renders below the theme.css
   <link> in base.html), so at equal specificity its defaults would
   otherwise win the cascade and the popup renders with its stock white
   background. */
.maplibregl-popup-content {
    background: var(--bg-panel) !important;
    color: white !important;
    border: 1px solid var(--border) !important;
    border-radius: 8px !important;
    padding: 12px 16px !important;
    font-family: 'Inter', sans-serif !important;
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.6) !important;
    font-size: 14px !important;
}
.maplibregl-popup-tip {
    border-top-color: var(--bg-panel) !important;
    border-bottom-color: var(--bg-panel) !important;
}
.maplibregl-popup-close-button {
    color: var(--text-muted) !important;
    background: transparent !important;
    font-size: 18px !important;
    padding: 4px 8px !important;
    right: 2px !important;
    top: 2px !important;
    transition: color 0.15s ease !important;
}
.maplibregl-popup-close-button:hover {
    background: transparent !important;
    color: var(--text-main) !important;
}

.coord-popup { min-width: 220px; padding-top: 4px; }
.coord-popup .prob-line { margin-bottom: 12px; font-weight: 600; font-size: 14px; }
.coord-popup .prob-line span { color: var(--success); }
.coord-popup .section-label {
    font-weight: 600; margin-bottom: 10px; border-bottom: 1px solid rgba(255,255,255,0.1);
    padding-bottom: 6px; font-size: 12px; text-transform: uppercase; color: var(--accent); letter-spacing: 0.5px;
}
.coord-popup select {
    width: 100%; margin-bottom: 12px; padding: 8px; border-radius: 4px;
    border: 1px solid rgba(255,255,255,0.2); background: var(--bg-dark); color: white;
    font-family: 'Inter', sans-serif; font-size: 13px; outline: none; cursor: pointer;
}
.coord-popup .coord-display {
    font-family: 'SFMono-Regular', Menlo, monospace; font-size: 13px; background: rgba(0,0,0,0.3);
    padding: 10px; border-radius: 6px; border: 1px solid rgba(255,255,255,0.05); word-break: break-all;
    color: var(--text-muted); line-height: 1.6;
}
.coord-popup .copy-btn {
    margin-top: 10px; width: 100%; padding: 8px; background: rgba(255,255,255,0.1); color: white;
    border: none; border-radius: 4px; cursor: pointer; display: flex; align-items: center; justify-content: center;
    gap: 8px; font-family: 'Inter', sans-serif; font-size: 13px; transition: background 0.15s ease;
}
.coord-popup .copy-btn:hover { background: rgba(255,255,255,0.18); }

/* ---------- Auth pages ---------- */

body.auth-shell {
    display: flex;
    min-height: 100vh;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background-image: url('https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/5/12/18');
    background-size: cover;
    background-position: center;
}

.overlay {
    position: fixed;
    inset: 0;
    background: rgba(18, 18, 26, 0.8);
    z-index: 1;
}

.auth-card {
    position: relative;
    background: var(--bg-panel-glass);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 40px;
    width: 100%;
    max-width: 380px;
    box-shadow: var(--shadow-lg);
    z-index: 10;
    max-height: 90vh;
    overflow-y: auto;
}
.auth-card::-webkit-scrollbar { width: 4px; }
.auth-card::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.15); border-radius: 4px; }

.auth-card h2 { margin: 0 0 4px 0; font-size: 24px; font-weight: 700; text-align: center; }
.auth-card .brand-subtitle {
    margin: 0 0 20px 0; font-size: 11px; font-weight: 600; text-align: center;
    color: var(--accent); letter-spacing: 1.5px; text-transform: uppercase;
}
.auth-card p.lede { margin: 0 0 24px 0; font-size: 14px; color: var(--text-muted); text-align: center; line-height: 1.6; }

.form-group { margin-bottom: 16px; }
.form-group label { display: block; margin-bottom: 6px; font-size: 13px; font-weight: 500; color: var(--text-muted); }

.form-group input {
    width: 100%;
    padding: 12px;
    box-sizing: border-box;
    background: rgba(0, 0, 0, 0.4);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: white;
    font-family: inherit;
    font-size: 14px;
    outline: none;
    transition: border-color 0.15s ease, background 0.15s ease;
}
.form-group input:focus { border-color: var(--accent); background: rgba(0, 0, 0, 0.6); }

.helptext { font-size: 11px; color: #6b7280; margin-top: 4px; display: block; line-height: 1.5; }

.auth-links { margin-top: 20px; text-align: center; font-size: 13px; color: var(--text-muted); }
.auth-links a { text-decoration: none; font-weight: 500; }
.auth-links a:hover { text-decoration: underline; }

.form-error-box {
    margin-bottom: 16px; padding: 10px 12px; background: var(--danger-soft);
    border: 1px solid rgba(239,68,68,0.3); border-radius: 6px; color: #fca5a5; font-size: 13px;
}
.form-error-box ul { list-style: none; padding: 0; margin: 0; }

.success-icon { color: var(--success); margin-bottom: 20px; }

/* ---------- Admin dashboard ---------- */

body.admin-shell {
    min-height: 100vh;
    background-image: url('https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/5/12/18');
    background-size: cover;
    background-position: center;
    background-attachment: fixed;
}
body.admin-shell .overlay { background: rgba(18, 18, 26, 0.88); }

.container {
    position: relative;
    z-index: 10;
    max-width: 1000px;
    margin: 0 auto;
    padding: 32px 20px 60px;
}

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    margin-bottom: 32px;
    background: var(--bg-panel-glass);
    padding: 20px 28px;
    border-radius: 12px;
    border: 1px solid var(--border);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    flex-wrap: wrap;
}
.page-header h2 { margin: 0; font-size: 22px; font-weight: 700; }
.page-header .eyebrow { font-size: 11px; color: var(--accent); margin-top: 4px; letter-spacing: 1.5px; text-transform: uppercase; }

.btn-back {
    display: inline-flex; align-items: center; gap: 8px; padding: 10px 18px;
    background: rgba(255,255,255,0.1); color: white; text-decoration: none;
    border-radius: 8px; font-size: 14px; font-weight: 600; transition: background 0.15s ease;
}
.btn-back:hover { background: rgba(255,255,255,0.2); }

.panel {
    background: var(--bg-panel-glass);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 28px;
    margin-bottom: 24px;
    box-shadow: 0 15px 35px rgba(0,0,0,0.4);
}
.panel h3 { margin: 0 0 20px 0; font-size: 17px; color: white; display: flex; align-items: center; gap: 10px; }
.panel .badge { background: rgba(255,255,255,0.1); padding: 2px 9px; border-radius: 12px; font-size: 12px; font-weight: 600; }

.table-scroll { overflow-x: auto; margin: 0 -4px; }
table { width: 100%; border-collapse: collapse; font-size: 14px; min-width: 480px; }
th, td { padding: 14px 12px; text-align: left; border-bottom: 1px solid var(--border); }
th { font-weight: 600; color: var(--text-muted); text-transform: uppercase; font-size: 11px; letter-spacing: 0.5px; }
tr:last-child td { border-bottom: none; }
td.muted { color: var(--text-muted); }
td.strong { font-weight: 500; }

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

.panel .empty-state { margin-top: 0; padding: 32px 0; }

/* ---------- Toasts ---------- */

.toast-container {
    position: fixed;
    bottom: 24px;
    top: auto;
    left: 50%;
    transform: translateX(-50%);
    z-index: 1000;
    display: flex;
    flex-direction: column-reverse;
    gap: 10px;
    align-items: center;
    pointer-events: none;
    width: 100%;
    max-width: 420px;
    padding: 0 16px;
}

.toast {
    pointer-events: auto;
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--bg-panel-glass);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--border);
    border-left: 3px solid var(--accent);
    border-radius: 10px;
    padding: 12px 16px;
    font-size: 13px;
    font-weight: 500;
    box-shadow: var(--shadow-md);
    width: 100%;
    opacity: 0;
    transform: translateY(12px);
    transition: opacity 0.2s ease, transform 0.2s ease;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.toast-success { border-left-color: var(--success); }
.toast.toast-error { border-left-color: var(--danger); }
.toast svg { width: 18px; height: 18px; flex-shrink: 0; }
.toast.toast-success svg { color: var(--success); }
.toast.toast-error svg { color: var(--danger); }
.toast.toast-info svg { color: var(--accent); }

/* ---------- Confirm modal ---------- */

.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 1100;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    opacity: 0;
    transition: opacity 0.15s ease;
}
.modal-backdrop.show { opacity: 1; }

.modal-card {
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 28px;
    width: 100%;
    max-width: 360px;
    box-shadow: var(--shadow-lg);
    transform: scale(0.96);
    transition: transform 0.15s ease;
}
.modal-backdrop.show .modal-card { transform: scale(1); }
.modal-card h4 { margin: 0 0 10px 0; font-size: 17px; font-weight: 700; }
.modal-card p { margin: 0 0 22px 0; font-size: 14px; color: var(--text-muted); line-height: 1.6; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; }
.modal-actions .btn { padding: 9px 18px; border-radius: 8px; }

/* ---------- Responsive ---------- */

@media (max-width: 900px) {
    #floating-controls {
        top: 14px;
        gap: 14px;
        padding: 10px 16px;
        border-radius: var(--radius-lg);
        max-width: calc(100vw - 24px);
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    #floating-controls::-webkit-scrollbar { display: none; }
    .controls-text { display: none; }
}

@media (max-width: 640px) {
    #sidebar {
        position: fixed;
        top: 0; bottom: 0; left: 0;
        width: 86vw;
        max-width: 320px;
        margin-left: -100vw;
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        transform: translateX(0);
    }
    #sidebar:not(.collapsed) { margin-left: 0; }
    #sidebar:not(.collapsed) ~ #sidebar-backdrop { display: block; }
    .sidebar-close { display: inline-flex; }

    #floating-controls {
        left: 12px;
        right: 12px;
        top: 12px;
        transform: none;
        max-width: none;
        width: auto;
        padding: 8px 12px;
        gap: 10px;
    }

    .commander-tag .label { display: none; }
    .mission-form input.field-input { width: 110px; }
    .btn-save span, .btn-new span { display: none; }
    .btn-save, .btn-new { padding: 10px; }

    .auth-card { padding: 28px 22px; }

    .page-header { padding: 16px 18px; }
    .container { padding: 20px 14px 40px; }
}
