/* ==========================================================================
   DESIGN SYSTEM & CSS VARIABLES
   ========================================================================== */
:root {
    --bg-dark: #090d16;
    --bg-surface: #111827;
    --bg-card: rgba(17, 24, 39, 0.85);
    --bg-card-hover: rgba(31, 41, 55, 0.9);
    --bg-input: #1f2937;

    --border-color: rgba(255, 255, 255, 0.08);
    --border-highlight: rgba(59, 130, 246, 0.4);

    --primary: #3b82f6;
    --primary-hover: #2563eb;
    --primary-glow: rgba(59, 130, 246, 0.35);

    --success: #10b981;
    --success-hover: #059669;
    --success-glow: rgba(16, 185, 129, 0.3);

    --danger: #ef4444;
    --danger-hover: #dc2626;

    --text-main: #f9fafb;
    --text-muted: #9ca3af;
    --text-sub: #6b7280;

    --font-heading: 'Outfit', sans-serif;
    --font-body: 'Inter', sans-serif;

    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 18px;
    --radius-full: 9999px;

    --shadow-card: 0 20px 40px rgba(0, 0, 0, 0.5);
    --backdrop-blur: blur(14px);
}

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

body, html {
    width: 100%;
    height: 100%;
    overflow: hidden;
    font-family: var(--font-body);
    background-color: var(--bg-dark);
    color: var(--text-main);
    -webkit-font-smoothing: antialiased;
}

/* Scrollbar Customization */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.15);
    border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* ==========================================================================
   VIEW CONTROLLERS
   ========================================================================== */
.view-container {
    display: none;
    width: 100vw;
    height: 100vh;
}

.view-container.active {
    display: flex;
}

/* ==========================================================================
   LANDING / LOADER VIEW
   ========================================================================== */
#loaderView {
    justify-content: center;
    align-items: center;
    position: relative;
    background: radial-gradient(circle at 50% 20%, #1e293b 0%, #090d16 100%);
}

.loader-backdrop {
    position: absolute;
    inset: 0;
    background-image: radial-gradient(rgba(59, 130, 246, 0.1) 1px, transparent 1px);
    background-size: 24px 24px;
    pointer-events: none;
}

.loader-card {
    position: relative;
    z-index: 10;
    width: 100%;
    max-width: 480px;
    padding: 40px 36px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-card);
    backdrop-filter: var(--backdrop-blur);
    text-align: center;
    animation: popIn 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes popIn {
    from { opacity: 0; transform: scale(0.94) translateY(10px); }
    to { opacity: 1; transform: scale(1) translateY(0); }
}

.brand-logo {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    margin-bottom: 12px;
}

.logo-icon {
    font-size: 32px;
}

.brand-logo h1 {
    font-family: var(--font-heading);
    font-size: 24px;
    font-weight: 700;
    letter-spacing: -0.5px;
    background: linear-gradient(135deg, #ffffff 0%, #93c5fd 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.subtitle {
    font-size: 14px;
    color: var(--text-muted);
    line-height: 1.5;
    margin-bottom: 28px;
}

.territory-form {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.input-group {
    position: relative;
    display: flex;
    align-items: center;
}

.input-icon {
    position: absolute;
    left: 14px;
    font-size: 16px;
    pointer-events: none;
    opacity: 0.7;
}

.input-group input {
    width: 100%;
    padding: 14px 14px 14px 44px;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-main);
    font-size: 14px;
    outline: none;
    transition: all 0.2s ease;
}

.input-group input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-glow);
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 20px;
    font-size: 14px;
    font-weight: 600;
    border-radius: var(--radius-md);
    border: none;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-hover) 100%);
    color: white;
    box-shadow: 0 4px 14px var(--primary-glow);
}

.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 20px var(--primary-glow);
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-main);
    border: 1px solid var(--border-color);
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.14);
}

.btn-success {
    background: linear-gradient(135deg, var(--success) 0%, var(--success-hover) 100%);
    color: white;
    box-shadow: 0 4px 14px var(--success-glow);
}

.btn-success:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 20px var(--success-glow);
}

.btn-icon-text {
    background: rgba(255, 255, 255, 0.06);
    color: var(--text-main);
    padding: 8px 12px;
    font-size: 13px;
    border: 1px solid var(--border-color);
}

.btn-icon-text:hover {
    background: rgba(255, 255, 255, 0.12);
}

.btn-icon {
    width: 36px;
    height: 36px;
    padding: 0;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-main);
}

.btn-icon:hover {
    background: rgba(255, 255, 255, 0.12);
}

.loader-footer {
    margin-top: 24px;
    padding-top: 16px;
    border-top: 1px solid var(--border-color);
}

.hint-text {
    font-size: 12px;
    color: var(--text-sub);
}

/* ==========================================================================
   DASHBOARD VIEW LAYOUT
   ========================================================================== */
#dashboardView {
    flex-direction: column;
}

/* TOP NAVBAR */
.top-navbar {
    height: 64px;
    padding: 0 20px;
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    z-index: 100;
}

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

.brand-mini {
    display: flex;
    align-items: center;
    gap: 8px;
    text-decoration: none;
    color: var(--text-main);
}

.brand-title {
    font-family: var(--font-heading);
    font-weight: 700;
    font-size: 18px;
}

.territory-badge {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 10px;
    background: rgba(59, 130, 246, 0.1);
    border: 1px solid rgba(59, 130, 246, 0.2);
    border-radius: var(--radius-full);
    font-size: 12px;
    font-weight: 500;
    color: #93c5fd;
}

.badge-dot {
    width: 6px;
    height: 6px;
    background: var(--primary);
    border-radius: 50%;
    box-shadow: 0 0 8px var(--primary);
}

.nav-center {
    flex: 1;
    max-width: 400px;
    margin: 0 20px;
}

.progress-box {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.progress-info {
    display: flex;
    justify-content: space-between;
    font-size: 12px;
    color: var(--text-muted);
    font-weight: 500;
}

.progress-bar-track {
    width: 100%;
    height: 8px;
    background: rgba(255, 255, 255, 0.08);
    border-radius: 4px;
    overflow: hidden;
}

.progress-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--primary), var(--success));
    border-radius: 4px;
    transition: width 0.4s ease;
}

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

/* MAIN DASHBOARD CONTENT */
.dashboard-main {
    flex: 1;
    display: flex;
    position: relative;
    overflow: hidden;
}

/* SIDEBAR DRAWER */
.sidebar-drawer {
    width: 380px;
    height: 100%;
    background: var(--bg-surface);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    z-index: 90;
    transition: transform 0.3s ease;
}

.drawer-header {
    padding: 16px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    gap: 12px;
    background: rgba(17, 24, 39, 0.95);
}

.search-box {
    position: relative;
    display: flex;
    align-items: center;
}

.search-icon {
    position: absolute;
    left: 12px;
    font-size: 14px;
    opacity: 0.6;
    pointer-events: none;
}

.search-box input {
    width: 100%;
    padding: 10px 32px 10px 36px;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-main);
    font-size: 13px;
    outline: none;
    transition: border-color 0.2s;
}

.search-box input:focus {
    border-color: var(--primary);
}

.clear-btn {
    position: absolute;
    right: 10px;
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 14px;
    cursor: pointer;
}

.filter-tabs {
    display: flex;
    background: rgba(0, 0, 0, 0.2);
    padding: 3px;
    border-radius: var(--radius-sm);
    gap: 2px;
}

.tab-btn {
    flex: 1;
    padding: 6px 8px;
    background: none;
    border: none;
    border-radius: 6px;
    color: var(--text-muted);
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

.tab-btn:hover {
    color: var(--text-main);
}

.tab-btn.active {
    background: var(--bg-input);
    color: var(--text-main);
    box-shadow: 0 2px 6px rgba(0,0,0,0.3);
}

.direction-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 12px;
    color: var(--text-muted);
}

.dir-toggle-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-main);
    font-size: 12px;
    cursor: pointer;
    transition: background 0.2s;
}

.dir-toggle-btn:hover {
    background: rgba(255, 255, 255, 0.1);
}

/* STREET LIST */
.street-list-container {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
    position: relative;
}

.loading-spinner-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 40px 20px;
    color: var(--text-muted);
    font-size: 14px;
}

.spinner {
    width: 32px;
    height: 32px;
    border: 3px solid rgba(255, 255, 255, 0.1);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.street-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.street-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 12px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    transition: all 0.15s ease;
    user-select: none;
}

.street-item:hover {
    background: var(--bg-card-hover);
    border-color: rgba(255, 255, 255, 0.18);
    transform: translateX(2px);
}

.street-item.done {
    opacity: 0.65;
    background: rgba(16, 185, 129, 0.06);
    border-color: rgba(16, 185, 129, 0.2);
}

.street-item.done:hover {
    opacity: 1;
}

.street-item-left {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 1;
    overflow: hidden;

    label {
        display: flex;
        align-items: center;
        gap: 10px;
        flex: 1;
        cursor: pointer;
        overflow: hidden;
    }
}

.street-checkbox {
    width: 18px;
    height: 18px;
    accent-color: var(--success);
    cursor: pointer;
    border-radius: 4px;
}

.street-name-text {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-main);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.btn-11880 {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 5px 10px;
    background: var(--primary);
    border: none;
    border-radius: 6px;
    color: white;
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.btn-11880:hover {
    background: var(--primary-hover);
    box-shadow: 0 2px 8px var(--primary-glow);
}

.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-muted);

    span {
        font-size: 32px;
        margin-bottom: 8px;
        display: block;
    }
    p {
        font-size: 13px;
    }
}

/* MAP SECTION */
.map-section {
    flex: 1;
    height: 100%;
    position: relative;
}

#map {
    width: 100%;
    height: 100%;
    background: #0f172a;
}

/* Dark Mode Leaflet Tile Filter (Applies strictly to OpenStreetMap tiles, leaving Satellite imagery natural & crisp) */
#map.dark-tiles img.leaflet-tile[src*="openstreetmap.org"] {
    filter: brightness(0.65) invert(1) contrast(2.2) hue-rotate(200deg) saturate(0.4);
}



/* Custom Leaflet Tooltip */
.custom-polyline-tooltip {
    background: rgba(15, 23, 42, 0.9) !important;
    border: 1px solid rgba(255, 255, 255, 0.15) !important;
    color: white !important;
    font-family: var(--font-body) !important;
    font-weight: 600 !important;
    font-size: 12px !important;
    padding: 4px 8px !important;
    border-radius: 6px !important;
    box-shadow: 0 4px 12px rgba(0,0,0,0.4) !important;
}

/* Custom Leaflet Layer Control */
.leaflet-control-layers {
    background: var(--bg-surface) !important;
    border: 1px solid var(--border-color) !important;
    border-radius: var(--radius-sm) !important;
    color: var(--text-main) !important;
    font-family: var(--font-body) !important;
    box-shadow: 0 4px 14px rgba(0,0,0,0.4) !important;
    padding: 6px 10px !important;
}

.leaflet-control-layers-toggle {
    filter: invert(1);
}

.leaflet-control-layers-expanded {
    padding: 10px 14px !important;
    background: rgba(17, 24, 39, 0.95) !important;
}


/* ==========================================================================
   11880 MODAL DIALOG
   ========================================================================== */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(8px);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.modal-card {
    width: 100%;
    max-width: 720px;
    max-height: 85vh;
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-card);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: popIn 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

.modal-header {
    padding: 20px 24px;
    background: rgba(31, 41, 55, 0.5);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.modal-title-box {
    display: flex;
    align-items: center;
    gap: 12px;
}

.modal-icon {
    font-size: 24px;
}

.modal-header h3 {
    font-family: var(--font-heading);
    font-size: 18px;
    font-weight: 700;
    color: var(--text-main);
}

.modal-subtitle {
    font-size: 12px;
    color: var(--text-muted);
}

.close-btn {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    font-size: 16px;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
}

.close-btn:hover {
    background: rgba(239, 68, 68, 0.2);
    color: var(--danger);
    border-color: rgba(239, 68, 68, 0.4);
}

.modal-body {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    background: var(--bg-dark);
}

.results-content {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.result-card {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    transition: all 0.2s ease;
}

.result-card:hover {
    border-color: var(--primary);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}

.result-index {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    background: var(--bg-input);
    border-radius: 50%;
    font-weight: 700;
    font-size: 14px;
    color: var(--primary);
    margin-right: 14px;
}

.result-name {
    flex: 1;
    font-size: 16px;
    font-weight: 600;
    color: var(--text-main);
    text-decoration: none;
}

.result-link-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    background: white;
    color: #0f172a;
    font-weight: 700;
    font-size: 13px;
    border-radius: var(--radius-sm);
    text-decoration: none;
    transition: transform 0.2s ease;
}

.result-link-btn:hover {
    transform: scale(1.04);
}

.no-results-box {
    text-align: center;
    padding: 30px;
    color: var(--text-muted);
    font-size: 15px;
}

.modal-footer {
    padding: 16px 24px;
    background: rgba(31, 41, 55, 0.5);
    border-top: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.key-hint {
    font-size: 12px;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 6px;

    kbd {
        background: var(--bg-input);
        border: 1px solid var(--border-color);
        border-radius: 4px;
        padding: 2px 6px;
        font-family: monospace;
        font-size: 11px;
        color: var(--text-main);
    }
}

.footer-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

/* RESPONSIVE LAYOUT */
@media (max-width: 768px) {
    .dashboard-main {
        flex-direction: column;
    }

    .sidebar-drawer {
        width: 100%;
        height: 40vh;
    }

    .map-section {
        height: 60vh;
    }

    .top-navbar {
        padding: 0 12px;
    }

    .nav-center {
        display: none;
    }
}
