/* DarkVessel — Clean Maritime SaaS Design (Light + Dark Mode) */
:root {
    --bg-app: #f1f5f9;
    --bg-sidebar: #f8fafc;
    --bg-surface: #ffffff;
    --bg-surface-soft: #f8fafc;
    --bg-elevated: rgba(255, 255, 255, 0.94);
    --border: #e2e8f0;
    --border-strong: #cbd5e1;
    --text-primary: #0f172a;
    --text-secondary: #475569;
    --text-muted: #94a3b8;
    --accent: #2563eb;
    --accent-hover: #1d4ed8;
    --accent-soft: #eff6ff;
    --accent-ring: #38bdf8;
    --success: #16a34a;
    --success-soft: #dcfce7;
    --warning: #d97706;
    --warning-soft: #fef3c7;
    --danger: #dc2626;
    --danger-soft: #fee2e2;
    --purple: #7c3aed;
    --purple-soft: #ede9fe;
    --shadow-sm: 0 2px 8px rgba(15, 23, 42, 0.05);
    --shadow-md: 0 10px 30px rgba(15, 23, 42, 0.08);
    --shadow-lg: 0 20px 45px rgba(15, 23, 42, 0.14);
}

[data-theme="dark"] {
    --bg-app: #060b16;
    --bg-sidebar: #0c1322;
    --bg-surface: #111b2e;
    --bg-surface-soft: #162238;
    --bg-elevated: rgba(17, 27, 46, 0.94);
    --border: #1e2d48;
    --border-strong: #2d4266;
    --text-primary: #f8fafc;
    --text-secondary: #cbd5e1;
    --text-muted: #64748b;
    --accent: #3b82f6;
    --accent-hover: #2563eb;
    --accent-soft: rgba(59, 130, 246, 0.14);
    --accent-ring: #38bdf8;
    --success: #22c55e;
    --success-soft: rgba(34, 197, 94, 0.16);
    --warning: #f59e0b;
    --warning-soft: rgba(245, 158, 11, 0.16);
    --danger: #ef4444;
    --danger-soft: rgba(239, 68, 68, 0.18);
    --purple: #a78bfa;
    --purple-soft: rgba(167, 139, 250, 0.16);
    --shadow-sm: 0 2px 10px rgba(0, 0, 0, 0.35);
    --shadow-md: 0 12px 32px rgba(0, 0, 0, 0.45);
    --shadow-lg: 0 22px 50px rgba(0, 0, 0, 0.65);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--bg-app);
    color: var(--text-primary);
    height: 100vh;
    overflow: hidden;
    display: flex;
    -webkit-font-smoothing: antialiased;
}

/* LEFT NAVIGATION RAIL */
.sidebar {
    width: 232px;
    flex-shrink: 0;
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: 20px 14px 16px;
    z-index: 900;
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 4px 10px 22px;
}

.brand-icon {
    width: 32px;
    height: 32px;
    border-radius: 9px;
    background: linear-gradient(135deg, #2563eb, #0ea5e9);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.32);
}

.brand-name {
    font-size: 17px;
    font-weight: 800;
    letter-spacing: -0.3px;
    color: var(--text-primary);
}

.brand-tag {
    font-size: 10px;
    color: var(--text-muted);
    font-weight: 600;
    display: block;
    margin-top: -2px;
}

.nav-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.nav-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 10px 12px;
    border-radius: 10px;
    border: 1.5px solid transparent;
    background: transparent;
    color: var(--text-secondary);
    font-size: 13.5px;
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
    transition: all 0.15s ease;
    width: 100%;
    text-align: left;
}

.nav-item-left {
    display: flex;
    align-items: center;
    gap: 10px;
}

.nav-item:hover {
    background: var(--bg-surface);
    color: var(--text-primary);
}

.nav-item.active {
    background: var(--accent-soft);
    border-color: var(--accent-ring);
    color: var(--accent);
    font-weight: 600;
}

.nav-badge {
    font-size: 10px;
    font-weight: 700;
    padding: 2px 7px;
    border-radius: 999px;
    background: var(--accent-soft);
    color: var(--accent);
}

.nav-badge.pro {
    background: linear-gradient(135deg, #0f172a, #1e3a8a);
    color: #fff;
}

.nav-badge.danger {
    background: var(--danger-soft);
    color: var(--danger);
}

.sidebar-footer {
    display: flex;
    flex-direction: column;
    gap: 14px;
    padding-top: 12px;
    border-top: 1px solid var(--border);
}

.theme-toggle {
    display: inline-flex;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 3px;
    width: fit-content;
    box-shadow: var(--shadow-sm);
}

.theme-btn {
    border: none;
    background: transparent;
    color: var(--text-muted);
    width: 34px;
    height: 28px;
    border-radius: 7px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    transition: 0.15s;
}

.theme-btn.active {
    background: var(--accent-soft);
    color: var(--accent);
}

.user-card {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 8px 6px;
    border-radius: 10px;
}

.user-info-wrap {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.user-avatar {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: linear-gradient(135deg, #2563eb, #0284c7);
    color: #fff;
    font-weight: 700;
    font-size: 13px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.user-meta {
    min-width: 0;
}

.user-name {
    font-size: 13px;
    font-weight: 700;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-email {
    font-size: 11px;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.icon-btn {
    border: 1px solid var(--border);
    background: var(--bg-surface);
    color: var(--text-secondary);
    width: 30px;
    height: 30px;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: 0.15s;
    flex-shrink: 0;
}

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

/* MAIN MAP STAGE */
.stage {
    position: relative;
    flex: 1;
    height: 100vh;
    overflow: hidden;
}

#map {
    width: 100%;
    height: 100%;
    z-index: 1;
}

/* TOP FLOATING FILTER PILLS (Reference Photo Style) */
.map-topbar {
    position: absolute;
    top: 16px;
    left: 16px;
    right: 400px;
    z-index: 700;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
    pointer-events: none;
}

.map-topbar > * { pointer-events: auto; }

.segmented-pills {
    display: inline-flex;
    align-items: center;
    background: var(--bg-elevated);
    backdrop-filter: blur(12px);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 4px;
    box-shadow: var(--shadow-md);
    gap: 2px;
}

.seg-btn {
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-size: 12.5px;
    font-weight: 600;
    padding: 7px 14px;
    border-radius: 8px;
    cursor: pointer;
    transition: 0.15s;
}

.seg-btn:hover { color: var(--text-primary); }

.seg-btn.active {
    background: var(--bg-surface);
    color: var(--text-primary);
    box-shadow: var(--shadow-sm);
}

[data-theme="dark"] .seg-btn.active {
    background: #1e2d48;
    color: #fff;
}

.filter-select {
    background: var(--bg-elevated);
    backdrop-filter: blur(12px);
    border: 1px solid var(--border);
    color: var(--text-primary);
    font-size: 12.5px;
    font-weight: 600;
    padding: 9px 12px;
    border-radius: 11px;
    box-shadow: var(--shadow-md);
    outline: none;
    cursor: pointer;
}

/* BOTTOM LIVE TELEMETRY PILL */
.live-pill {
    position: absolute;
    bottom: 18px;
    left: 16px;
    z-index: 700;
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--bg-elevated);
    backdrop-filter: blur(12px);
    border: 1px solid var(--border);
    padding: 8px 14px;
    border-radius: 999px;
    box-shadow: var(--shadow-md);
    font-size: 12px;
    color: var(--text-secondary);
}

.live-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--success);
    box-shadow: 0 0 0 4px var(--success-soft);
    animation: pulse 1.8s infinite;
}

.live-dot.offline {
    background: var(--warning);
    box-shadow: 0 0 0 4px var(--warning-soft);
}

@keyframes pulse {
    0% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.6; transform: scale(1.2); }
    100% { opacity: 1; transform: scale(1); }
}

/* RIGHT FLOATING TRACKING PANEL (Reference Photo Style) */
.right-panel {
    position: absolute;
    top: 16px;
    right: 16px;
    bottom: 16px;
    width: 372px;
    background: var(--bg-elevated);
    backdrop-filter: blur(16px);
    border: 1px solid var(--border);
    border-radius: 16px;
    box-shadow: var(--shadow-lg);
    z-index: 800;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.rp-header {
    padding: 18px 18px 12px;
    border-bottom: 1px solid var(--border);
}

.rp-title-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 6px;
}

.rp-title {
    font-size: 16.5px;
    font-weight: 800;
    color: var(--text-primary);
    letter-spacing: -0.2px;
}

.rp-sub {
    font-size: 12px;
    color: var(--text-muted);
    line-height: 1.45;
    margin-bottom: 12px;
}

.btn-primary {
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 9px;
    padding: 8px 13px;
    font-size: 12.5px;
    font-weight: 600;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    box-shadow: 0 3px 10px rgba(37, 99, 235, 0.25);
    transition: 0.15s;
}

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

.btn-secondary {
    background: var(--bg-surface);
    color: var(--text-primary);
    border: 1px solid var(--border);
    border-radius: 9px;
    padding: 7px 12px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    transition: 0.15s;
}

.btn-secondary:hover { border-color: var(--accent); color: var(--accent); }

.btn-danger {
    background: var(--danger);
    color: #fff;
    border: none;
    border-radius: 9px;
    padding: 7px 12px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
}

.search-box {
    position: relative;
}

.search-box input {
    width: 100%;
    padding: 9px 12px 9px 34px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: var(--bg-surface);
    color: var(--text-primary);
    font-size: 12.5px;
    outline: none;
    transition: 0.15s;
}

.search-box input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

.search-icon {
    position: absolute;
    left: 11px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    font-size: 13px;
}

.rp-body {
    flex: 1;
    overflow-y: auto;
    padding: 12px 14px 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

/* VESSEL CARDS (Reference Photo Style) */
.vessel-card {
    background: var(--bg-surface);
    border: 1.5px solid var(--border);
    border-radius: 12px;
    padding: 13px 14px;
    cursor: pointer;
    transition: all 0.16s ease;
}

.vessel-card:hover {
    border-color: var(--border-strong);
    box-shadow: var(--shadow-sm);
    transform: translateY(-1px);
}

.vessel-card.selected {
    border-color: var(--accent-ring);
    box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.18);
}

.vessel-card.dark-card {
    border-left: 4px solid var(--danger);
}

.vc-top {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 8px;
    margin-bottom: 6px;
}

.vc-name-wrap {
    min-width: 0;
}

.vc-name {
    font-size: 14px;
    font-weight: 700;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.vc-type {
    font-size: 11px;
    color: var(--text-muted);
    font-weight: 500;
    margin-left: 6px;
}

.vc-submeta {
    font-size: 11px;
    color: var(--text-secondary);
    margin-top: 2px;
}

.vc-right {
    text-align: right;
    flex-shrink: 0;
}

.flag-pill {
    display: inline-block;
    font-size: 10.5px;
    font-weight: 800;
    padding: 2px 7px;
    border-radius: 6px;
    background: var(--bg-surface-soft);
    border: 1px solid var(--border);
    color: var(--text-primary);
}

.vc-code {
    display: block;
    font-size: 10.5px;
    color: var(--text-muted);
    margin-top: 3px;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.vc-pills {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    margin: 7px 0;
}

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

.status-pill.sailing { background: #e0f2fe; color: #0284c7; }
.status-pill.docked { background: var(--warning-soft); color: var(--warning); }
.status-pill.anchored { background: #fef9c3; color: #a16207; }
.status-pill.dark { background: var(--danger-soft); color: var(--danger); }
.status-pill.cloaked { background: var(--purple-soft); color: var(--purple); }
[data-theme="dark"] .status-pill.sailing { background: rgba(14, 165, 233, 0.18); color: #38bdf8; }
[data-theme="dark"] .status-pill.anchored { background: rgba(234, 179, 8, 0.18); color: #facc15; }

.vc-route {
    font-size: 11px;
    color: var(--text-muted);
    border-top: 1px solid var(--border);
    padding-top: 7px;
    margin-top: 7px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

/* DETAIL VIEW INSIDE RIGHT PANEL */
.detail-box {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 14px;
}

.detail-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin: 10px 0;
}

.detail-kv {
    background: var(--bg-surface-soft);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 8px 10px;
}

.detail-k {
    font-size: 10px;
    text-transform: uppercase;
    color: var(--text-muted);
    font-weight: 700;
    letter-spacing: 0.4px;
}

.detail-v {
    font-size: 13px;
    font-weight: 700;
    color: var(--text-primary);
    margin-top: 2px;
}

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

/* MODALS */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.55);
    backdrop-filter: blur(6px);
    z-index: 2000;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 16px;
}

.modal-backdrop.open { display: flex; }

.modal {
    width: 100%;
    max-width: 460px;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    box-shadow: var(--shadow-lg);
    overflow: hidden;
    animation: popIn 0.18s ease;
}

@keyframes popIn {
    from { opacity: 0; transform: scale(0.96); }
    to { opacity: 1; transform: scale(1); }
}

.modal-head {
    padding: 18px 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-title { font-size: 16px; font-weight: 800; }

.modal-body {
    padding: 18px 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.field label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 5px;
}

.field input, .field select, .field textarea {
    width: 100%;
    padding: 9px 12px;
    border-radius: 9px;
    border: 1px solid var(--border);
    background: var(--bg-surface-soft);
    color: var(--text-primary);
    font-size: 13px;
    outline: none;
}

.field input:focus, .field select:focus {
    border-color: var(--accent);
}

.tabs-row {
    display: flex;
    gap: 6px;
    background: var(--bg-surface-soft);
    padding: 4px;
    border-radius: 10px;
    border: 1px solid var(--border);
}

.tab-btn {
    flex: 1;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    padding: 8px;
    border-radius: 7px;
    font-size: 12.5px;
    font-weight: 700;
    cursor: pointer;
}

.tab-btn.active {
    background: var(--bg-surface);
    color: var(--accent);
    box-shadow: var(--shadow-sm);
}

.alert-box {
    padding: 10px 12px;
    border-radius: 9px;
    font-size: 12px;
    line-height: 1.45;
}

.alert-box.info { background: var(--accent-soft); color: var(--accent); border: 1px solid rgba(59,130,246,0.25); }
.alert-box.error { background: var(--danger-soft); color: var(--danger); }
.alert-box.success { background: var(--success-soft); color: var(--success); }

/* LEAFLET POPUP CUSTOM */
.leaflet-popup-content-wrapper {
    background: var(--bg-surface) !important;
    color: var(--text-primary) !important;
    border-radius: 12px !important;
    box-shadow: var(--shadow-lg) !important;
    border: 1px solid var(--border);
}
.leaflet-popup-tip { background: var(--bg-surface) !important; }

/* TOAST */
.toast {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: #0f172a;
    color: #fff;
    padding: 10px 18px;
    border-radius: 10px;
    font-size: 13px;
    font-weight: 600;
    box-shadow: var(--shadow-lg);
    z-index: 3000;
    display: none;
}
.toast.show { display: block; }

.empty-state {
    text-align: center;
    padding: 28px 14px;
    color: var(--text-muted);
    font-size: 12.5px;
    line-height: 1.6;
}

/* MOBILE BOTTOM NAVIGATION & RESPONSIVE APP LAYOUT */
.mobile-bottom-nav {
    display: none;
}

.mobile-sheet-close {
    display: none;
}

@media (max-width: 900px) {
    body {
        height: 100dvh;
        height: 100vh;
        flex-direction: column;
        overflow: hidden;
    }

    .sidebar {
        display: none;
        position: fixed;
        inset: 0 auto 58px 0;
        width: min(82vw, 300px);
        z-index: 1600;
        box-shadow: var(--shadow-lg);
    }

    .sidebar.mobile-open {
        display: flex;
    }

    .stage {
        width: 100%;
        height: calc(100dvh - 58px);
        flex: 1;
    }

    .map-topbar {
        top: 10px;
        left: 10px;
        right: 10px;
        gap: 6px;
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        padding-bottom: 2px;
    }

    .map-topbar::-webkit-scrollbar { display: none; }

    .segmented-pills {
        flex-shrink: 0;
    }

    .seg-btn {
        padding: 6px 10px;
        font-size: 12px;
    }

    .filter-select {
        flex-shrink: 0;
        padding: 7px 10px;
        font-size: 12px;
    }

    .right-panel {
        position: fixed;
        top: auto;
        right: 0;
        left: 0;
        bottom: 58px;
        width: 100%;
        max-height: 75dvh;
        border-radius: 18px 18px 0 0;
        border-bottom: none;
        transform: translateY(115%);
        transition: transform 0.24s ease;
        z-index: 1300;
        box-shadow: 0 -10px 35px rgba(15, 23, 42, 0.25);
    }

    .right-panel.mobile-sheet-open {
        transform: translateY(0);
    }

    .mobile-sheet-close {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        width: 30px;
        height: 30px;
        border-radius: 8px;
        border: 1px solid var(--border);
        background: var(--bg-surface-soft);
        color: var(--text-primary);
        font-size: 14px;
        cursor: pointer;
    }

    .rp-header {
        padding: 12px 14px 10px;
    }

    .rp-body {
        padding: 8px 12px 16px;
        -webkit-overflow-scrolling: touch;
    }

    .leaflet-bottom.leaflet-right {
        bottom: 12px;
        right: 8px;
    }

    .modal {
        width: calc(100vw - 20px);
        max-width: 440px;
        max-height: 88dvh;
        overflow-y: auto;
    }

    .toast {
        bottom: 70px;
        max-width: calc(100vw - 24px);
        text-align: center;
    }

    .mobile-bottom-nav {
        display: flex;
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        height: 58px;
        background: var(--bg-surface);
        border-top: 1px solid var(--border);
        z-index: 1700;
        padding: 4px 6px env(safe-area-inset-bottom, 4px);
        justify-content: space-around;
        align-items: center;
        box-shadow: 0 -4px 18px rgba(15, 23, 42, 0.08);
    }

    .mob-nav-btn {
        flex: 1;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 2px;
        background: transparent;
        border: none;
        color: var(--text-secondary);
        font-size: 10.5px;
        font-weight: 700;
        padding: 4px 2px;
        border-radius: 10px;
        cursor: pointer;
    }

    .mob-nav-btn span.mob-ico {
        font-size: 17px;
        line-height: 1;
    }

    .mob-nav-btn.active {
        color: var(--accent);
        background: var(--accent-soft);
    }
}
