:root {
    --bg-color: #0c0c14;
    --glass-bg: rgba(20, 20, 35, 0.7);
    --glass-border: rgba(255, 255, 255, 0.1);
    --accent-color: #ff3e81;
    --accent-glow: rgba(255, 62, 129, 0.5);
    --text-primary: #ffffff;
    --text-secondary: #a0a0b8;
    --font-main: 'Outfit', sans-serif;
    --sidebar-width: 360px;
}

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

body {
    font-family: var(--font-main);
    background-color: var(--bg-color);
    color: var(--text-primary);
    overflow: hidden;
    height: 100vh;
    height: 100dvh; /* modern mobile viewports */
}

/* ============ LOADING OVERLAY ============ */
.loading-overlay {
    position: fixed;
    top: 0; left: 0; width: 100vw; height: 100vh;
    background: var(--bg-color);
    display: flex; justify-content: center; align-items: center;
    z-index: 9999; transition: opacity 0.5s ease;
}
.loading-overlay.hidden { opacity: 0; pointer-events: none; }
.loader-content { text-align: center; color: var(--accent-color); font-family: var(--font-main); letter-spacing: 2px; }
.scanner-ring {
    width: 60px; height: 60px; border: 3px solid transparent;
    border-top: 3px solid var(--accent-color);
    border-radius: 50%; animation: spin-loader 1s linear infinite;
    margin: 0 auto 20px;
}
@keyframes spin-loader { 100% { transform: rotate(360deg); } }

/* ============ LAYOUT ============ */
#app {
    display: flex;
    height: 100%;
    position: relative;
}

/* ============ SIDEBAR ============ */
.sidebar {
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    height: 100%;
    z-index: 1000;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    border-right: 1px solid var(--glass-border);
    backdrop-filter: blur(20px);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    flex-shrink: 0;
}

.glass {
    background: var(--glass-bg);
    box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
}

.glass-inner {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    padding: 1rem;
}

/* ============ SIDEBAR TOGGLE (hidden on desktop) ============ */
.sidebar-toggle {
    display: none; /* shown via media query */
    position: fixed;
    top: 12px;
    left: 12px;
    z-index: 1100;
    width: 44px;
    height: 44px;
    border: none;
    border-radius: 12px;
    background: var(--glass-bg);
    backdrop-filter: blur(12px);
    color: white;
    font-size: 1.4rem;
    cursor: pointer;
    border: 1px solid var(--glass-border);
    box-shadow: 0 4px 20px rgba(0,0,0,0.4);
    transition: transform 0.2s ease, background 0.2s ease;
}
.sidebar-toggle:active {
    transform: scale(0.92);
}

/* ============ HEADER ============ */
header h1 {
    font-size: 2rem;
    font-weight: 800;
    letter-spacing: -1px;
}
header h1 span { color: var(--accent-color); }
header p { color: var(--text-secondary); margin-top: 0.3rem; font-size: 0.85rem; }

/* ============ MAP ============ */
#map {
    flex: 1;
    height: 100%;
    min-width: 0; /* flexbox shrink fix */
    background-color: #1a1a2e;
}
.leaflet-container { background: #0c0c14 !important; }

/* ============ NOTIFICATION ============ */
.notification {
    position: fixed;
    top: 1rem;
    right: 1rem;
    padding: 0.8rem 1.5rem;
    background: var(--glass-bg);
    backdrop-filter: blur(10px);
    border: 1px solid var(--accent-color);
    border-radius: 8px;
    z-index: 2000;
    transition: all 0.5s ease;
    font-size: 0.85rem;
    max-width: 90vw;
}

.hidden {
    display: none !important;
}

/* ============ COMPANION SECTIONS ============ */
.companion-section {
    margin-top: 8px;
    padding: 0 !important;
    overflow: hidden;
    transition: all 0.3s ease;
}

.section-header {
    padding: 10px 12px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    background: rgba(255, 255, 255, 0.03);
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}
.section-header h3 {
    font-size: 0.85rem;
    margin: 0;
    font-weight: 600;
    color: var(--text-secondary);
}

.section-content {
    padding: 12px;
    border-top: 1px solid var(--glass-border);
}
.section-content.hidden {
    display: none !important;
}

.toggle-icon {
    font-size: 0.7rem;
    color: var(--text-secondary);
    transition: transform 0.3s ease;
}
.companion-section.active .toggle-icon {
    transform: rotate(180deg);
}

/* ============ STAT CARD ============ */
.stat-card {
    display: flex; flex-direction: column;
    align-items: center; justify-content: center; text-align: center;
}
.stat-card .label { font-size: 0.75rem; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 1px; }
.stat-card .value { font-size: 1.5rem; font-weight: 700; color: var(--accent-color); text-shadow: 0 0 20px var(--accent-glow); }

/* ============ FORM ELEMENTS ============ */
h3 { font-size: 1rem; margin-bottom: 0.75rem; font-weight: 600; color: var(--text-secondary); }

.filter-group { margin-bottom: 1rem; }

label {
    display: block; font-size: 0.8rem;
    margin-bottom: 0.4rem; color: var(--text-secondary);
}

select {
    width: 100%; padding: 10px;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 10px; color: white;
    font-family: var(--font-main);
    cursor: pointer; transition: all 0.3s ease;
    appearance: none; -webkit-appearance: none;
    font-size: 0.85rem;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    background-size: 14px;
}
select:focus { outline: none; border-color: var(--accent-color); background-color: rgba(255, 62, 129, 0.1); }
select option { background: #1a1a1a; color: white; padding: 10px; }
select:disabled { opacity: 0.5; cursor: not-allowed; }

textarea {
    width: 100%; padding: 10px; border-radius: 8px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--glass-border);
    color: white; font-family: inherit; font-size: 0.85rem;
    outline: none; transition: all 0.3s ease; resize: vertical;
    min-height: 70px; max-height: 200px;
}
textarea:focus { border-color: var(--accent-color); background: rgba(255, 255, 255, 0.1); }

.form-group { margin-bottom: 10px; }
.form-group label { display: block; font-size: 0.7rem; color: var(--text-secondary); margin-bottom: 4px; }
.form-group input, .form-group select {
    width: 100%;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--glass-border);
    padding: 8px; border-radius: 6px;
    color: white; font-size: 0.8rem;
}
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.btn-primary {
    width: 100%; padding: 12px;
    border-radius: 8px; border: none;
    background: var(--accent-color); color: white;
    font-weight: 600; font-size: 0.9rem;
    cursor: pointer; margin-top: 0.75rem;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px var(--accent-glow);
    -webkit-tap-highlight-color: transparent;
}
.btn-primary:hover { transform: translateY(-2px); box-shadow: 0 6px 20px var(--accent-glow); }
.btn-primary:active { transform: scale(0.97); }
.btn-primary:disabled { opacity: 0.6; transform: none; cursor: wait; }

/* ============ CHAT MODULE ============ */
.chat-box {
    max-height: 250px;
    height: auto;
    overflow-y: auto;
    display: flex; flex-direction: column; gap: 8px;
    margin-bottom: 15px; padding-right: 5px;
}
.msg {
    padding: 8px 12px; border-radius: 12px;
    font-size: 0.8rem; max-width: 85%; line-height: 1.4;
    word-wrap: break-word;
}
.msg.bot {
    align-self: flex-start;
    background: rgba(26, 115, 232, 0.2);
    border-bottom-left-radius: 2px; color: #e8f0fe;
}
.msg.user {
    align-self: flex-end;
    background: var(--accent-color);
    border-bottom-right-radius: 2px; color: white;
}
.chat-input-row { display: flex; gap: 8px; }
.chat-input-row input {
    flex: 1;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid var(--glass-border);
    border-radius: 8px; padding: 10px 12px;
    color: white; font-size: 0.85rem;
    min-width: 0;
    transition: all 0.3s ease;
}
.chat-input-row input:focus {
    background: rgba(255, 255, 255, 0.12);
    border-color: var(--accent-color);
    box-shadow: 0 0 10px rgba(255, 62, 129, 0.2);
    outline: none;
}
.chat-input-row button {
    padding: 8px 14px;
    background: var(--accent-color); border: none;
    border-radius: 6px; color: white;
    cursor: pointer; font-size: 0.8rem;
    white-space: nowrap; flex-shrink: 0;
}

/* ============ EMERGENCY HUB ============ */
.helpline-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.helpline-card {
    background: rgba(255, 255, 255, 0.05);
    padding: 10px; border-radius: 8px;
    text-align: center;
    border: 1px solid rgba(255, 255, 255, 0.1);
}
.h-label { display: block; font-size: 0.6rem; color: var(--text-secondary); margin-bottom: 4px; }
.h-value { font-size: 1.1rem; font-weight: 800; color: #ff5252; }
.state-alert {
    font-size: 0.75rem; padding: 8px;
    background: rgba(255, 193, 7, 0.1);
    border: 1px solid rgba(255, 193, 7, 0.3);
    border-radius: 6px; color: #ffca28;
}

/* ============ MARKER / CLUSTER STYLES ============ */
.marker-cluster-small { background-color: rgba(255, 62, 129, 0.6); }
.marker-cluster-small div { background-color: rgba(255, 62, 129, 0.9); color: white; }
.marker-cluster-medium { background-color: rgba(255, 62, 129, 0.7); }
.marker-cluster-medium div { background-color: rgba(255, 62, 129, 0.95); color: white; }
.marker-cluster-large { background-color: rgba(255, 62, 129, 0.8); }
.marker-cluster-large div { background-color: var(--accent-color); color: white; font-weight: 800; }
.marker-cluster div {
    font-family: var(--font-main);
    width: 30px; height: 30px; margin-left: 5px; margin-top: 5px;
    text-align: center; border-radius: 15px; font-size: 12px;
}

.badge-official {
    background: #ff3e81; color: white;
    padding: 3px 8px; border-radius: 20px;
    font-size: 9px; font-weight: 800;
    letter-spacing: 0.5px;
    box-shadow: 0 0 10px rgba(255, 62, 129, 0.4);
    display: inline-block; margin-bottom: 4px;
}
.badge-user {
    background: rgba(255, 255, 255, 0.1); color: var(--text-secondary);
    padding: 3px 8px; border-radius: 20px;
    font-size: 9px; font-weight: 600;
    border: 1px solid rgba(255, 255, 255, 0.2);
    display: inline-block; margin-bottom: 4px;
}

.shield-marker {
    background: var(--accent-color); border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 14px;
    box-shadow: 0 0 15px var(--accent-color);
    border: 2px solid white;
    animation: shield-pulse 2s infinite;
}
@keyframes shield-pulse {
    0% { transform: scale(1); box-shadow: 0 0 10px var(--accent-color); }
    50% { transform: scale(1.1); box-shadow: 0 0 25px var(--accent-color); }
    100% { transform: scale(1); box-shadow: 0 0 10px var(--accent-color); }
}

/* News cards */
.news-card { margin-bottom: 8px; padding: 10px; border-radius: 8px; }
.news-meta { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.news-source { font-size: 0.6rem; color: var(--text-secondary); }
.news-card h4 { font-size: 0.78rem; font-weight: 600; line-height: 1.3; margin-bottom: 4px; }
.news-card a { font-size: 0.65rem; color: var(--accent-color); text-decoration: none; }
.news-card a:hover { text-decoration: underline; }

/* Trip analysis card */
.trip-analysis-card {
    background: rgba(255,255,255,0.03);
    padding: 12px; border-radius: 8px;
}
.trip-analysis-card .trip-score { font-weight: 700; font-size: 0.85rem; margin-bottom: 6px; }
.trip-analysis-card p { font-size: 0.75rem; line-height: 1.4; color: var(--text-secondary); }

/* Placeholder text */
.placeholder { font-size: 0.75rem; color: var(--text-secondary); font-style: italic; }

/* Popup content */
.popup-content { font-family: var(--font-main); }

/* Scrollbar */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-thumb { background: var(--glass-border); border-radius: 3px; }
.chat-box::-webkit-scrollbar { width: 4px; }
.chat-box::-webkit-scrollbar-track { background: rgba(255, 255, 255, 0.02); }
.chat-box::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.1); border-radius: 10px; }

/* Footer */
footer { padding: 0.5rem 0; text-align: center; }
footer p { font-size: 0.7rem; color: var(--text-secondary); }


/* ============================================================ */
/* =============== RESPONSIVE: TABLET (768–1024px) ============ */
/* ============================================================ */
@media (max-width: 1024px) {
    :root { --sidebar-width: 320px; }

    .sidebar { padding: 1.2rem; gap: 0.8rem; }
    header h1 { font-size: 1.7rem; }
    .btn-primary { padding: 10px; font-size: 0.85rem; }
}

/* ============================================================ */
/* =============== RESPONSIVE: MOBILE (≤ 768px) =============== */
/* ============================================================ */
@media (max-width: 768px) {
    :root { --sidebar-width: 100%; }

    body { overflow: hidden; }

    #app {
        flex-direction: column-reverse;
        height: 100vh;
        height: 100dvh;
    }

    /* Hamburger button visible */
    .sidebar-toggle {
        display: flex;
        align-items: center;
        justify-content: center;
    }

    /* Sidebar becomes a slide-over drawer */
    .sidebar {
        position: fixed;
        top: 0; left: 0;
        width: 100%;
        height: 100%;
        z-index: 1050;
        padding: 3.5rem 1.2rem 1.2rem; /* extra top for toggle button */
        transform: translateX(-100%);
        transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
        border-right: none;
        border-bottom: 1px solid var(--glass-border);
        will-change: transform;
    }
    .sidebar.open {
        transform: translateX(0);
    }

    /* Map takes full screen */
    #map {
        width: 100%;
        height: 100%;
    }

    /* Reduce spacing */
    header h1 { font-size: 1.6rem; }
    header p { font-size: 0.8rem; }

    .glass-inner { padding: 0.8rem; border-radius: 10px; }
    .companion-section { margin-top: 6px; }
    .section-header { padding: 10px; }
    .section-header h3 { font-size: 0.8rem; }
    .section-content { padding: 10px; }

    .chat-box { height: 150px; }
    .btn-primary { padding: 11px; font-size: 0.85rem; }

    /* Notifications */
    .notification {
        top: auto;
        bottom: 1rem;
        right: 0.5rem;
        left: 0.5rem;
        text-align: center;
        font-size: 0.8rem;
    }

    /* Leaflet zoom controls */
    .leaflet-control-zoom {
        margin-bottom: 20px !important;
    }

    /* Overlay behind sidebar */
    .sidebar-overlay {
        position: fixed;
        top: 0; left: 0;
        width: 100%; height: 100%;
        background: rgba(0,0,0,0.5);
        z-index: 1040;
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.3s ease;
    }
    .sidebar-overlay.active {
        opacity: 1;
        pointer-events: all;
    }
}

/* ============================================================ */
/* ======== RESPONSIVE: SMALL PHONE (≤ 400px) ================= */
/* ============================================================ */
@media (max-width: 400px) {
    .sidebar { padding: 3rem 0.8rem 0.8rem; }
    header h1 { font-size: 1.4rem; }
    .section-header h3 { font-size: 0.75rem; }
    .form-row { grid-template-columns: 1fr; gap: 6px; }
    .helpline-grid { grid-template-columns: 1fr; gap: 6px; }
    .msg { font-size: 0.75rem; }
    .chat-input-row input { font-size: 0.75rem; padding: 7px 8px; }
    .chat-input-row button { padding: 7px 10px; font-size: 0.75rem; }
}

/* ============================================================ */
/* ======== LANDSCAPE PHONE FIX =============================== */
/* ============================================================ */
@media (max-height: 500px) and (orientation: landscape) {
    .sidebar { padding-top: 2.5rem; }
    .chat-box { height: 100px; }
    header h1 { font-size: 1.3rem; }
    header p { display: none; }
}
