/* ============================================
   MADx Hub Styles
   v5.0 - Unified black/red/white theme
   ============================================ */

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #1a1a2e;
    color: #eee;
    min-height: 100vh;
    overflow-x: hidden;
}

/* ========== LOGIN SCREEN ========== */

#login-screen {
    display: flex;
    align-items: center;
    justify-content: center;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, #050508 0%, #0a0a1a 50%, #0d0d18 100%);
    z-index: 10000;
}

.login-card {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(230, 57, 70, 0.25);
    border-top: 2px solid #e63946;
    border-radius: 12px;
    padding: 40px;
    width: 360px;
    max-width: 90vw;
    backdrop-filter: blur(10px);
}

.login-logo {
    text-align: center;
    margin-bottom: 32px;
}

.login-logo h1 {
    color: #fff;
    font-size: 28px;
    margin: 0;
    letter-spacing: 2px;
}

.login-logo p {
    color: rgba(255, 255, 255, 0.4);
    font-size: 13px;
    margin: 8px 0 0 0;
}

.login-field {
    margin-bottom: 16px;
}

.login-field label {
    display: block;
    color: rgba(255, 255, 255, 0.5);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 6px;
}

.login-field input {
    width: 100%;
    padding: 12px 14px;
    background: rgba(0, 0, 0, 0.4);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 6px;
    color: #fff;
    font-size: 15px;
    outline: none;
    transition: border-color 0.2s;
    box-sizing: border-box;
}

.login-field input:focus {
    border-color: #e63946;
}

.login-field input::placeholder {
    color: rgba(255, 255, 255, 0.2);
}

#login-btn {
    width: 100%;
    padding: 12px;
    background: #e63946;
    color: #fff;
    border: none;
    border-radius: 6px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
    margin-top: 8px;
}

#login-btn:hover {
    background: #d32f3f;
}

#login-btn:disabled {
    background: rgba(230, 57, 70, 0.3);
    cursor: not-allowed;
}

#login-error {
    color: #ff4444;
    font-size: 13px;
    text-align: center;
    margin-top: 12px;
    min-height: 18px;
}

/* ========== MADx LOGO TYPE ========== */

.madx-logo {
    font-weight: 700;
    letter-spacing: 0.5px;
}

.madx-accent {
    color: #e63946;
}

/* ========== HEADER ========== */

header {
    background: #0a0a1a;
    padding: 0.5rem 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 2px solid #e63946;
    height: 44px;
}

header h1 {
    font-size: 1.1rem;
    color: #fff;
}

#district-name {
    color: rgba(255, 255, 255, 0.45);
    font-size: 13px;
    font-weight: normal;
    margin-left: 12px;
}

.sign-out-btn {
    background: none;
    border: 1px solid rgba(255, 255, 255, 0.15);
    color: rgba(255, 255, 255, 0.5);
    padding: 4px 10px;
    border-radius: 4px;
    font-size: 11px;
    cursor: pointer;
    transition: all 0.2s;
}

.sign-out-btn:hover {
    border-color: #e63946;
    color: #e63946;
}

/* ========== MAP CONTAINER ========== */

#map-container {
    position: relative;
    height: calc(100vh - 44px - 22px); /* header + debug bar */
}

#map {
    width: 100%;
    height: 100%;
}

/* ========== MAP DRAWER ========== */

.map-drawer {
    position: absolute;
    top: 10px;
    right: 10px;
    z-index: 1000;
}

.drawer-btn {
    background: #0a0a1a;
    border: 1px solid #333;
    color: #eee;
    padding: 0.5rem 0.75rem;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.85rem;
    transition: border-color 0.2s, color 0.2s;
}

.drawer-btn:hover {
    border-color: #e63946;
    color: #fff;
}

.drawer-panel {
    display: none;
    background: #0a0a1a;
    border: 1px solid #333;
    border-top: 2px solid #e63946;
    border-radius: 4px;
    margin-top: 0.5rem;
    padding: 0.75rem;
    width: 280px;
    max-height: calc(100vh - 150px);
    overflow-y: auto;
}

.drawer-panel.open {
    display: block;
}

.drawer-section {
    margin-bottom: 1rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid #222;
}

.drawer-section:last-child {
    margin-bottom: 0;
    padding-bottom: 0;
    border-bottom: none;
}

.drawer-section h4 {
    color: #e63946;
    font-size: 0.75rem;
    text-transform: uppercase;
    margin-bottom: 0.5rem;
    letter-spacing: 0.5px;
    font-weight: 700;
}

.drawer-section select,
.drawer-section input[type="date"] {
    width: 100%;
    background: #111;
    border: 1px solid #333;
    color: #eee;
    padding: 0.4rem;
    border-radius: 4px;
    font-size: 0.85rem;
}

.drawer-section select:focus,
.drawer-section input:focus {
    outline: none;
    border-color: #e63946;
}

/* ========== DATE SELECTOR ========== */

.date-display {
    background: #111;
    border: 1px solid #333;
    border-radius: 4px;
    padding: 0.5rem;
    text-align: center;
    font-size: 0.9rem;
    color: #fff;
    margin-bottom: 0.5rem;
}

.date-quick-btns {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.25rem;
    margin-bottom: 0.5rem;
}

.date-quick-btn {
    background: #111;
    border: 1px solid #333;
    color: #aaa;
    padding: 0.35rem 0.5rem;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.75rem;
    transition: all 0.2s;
}

.date-quick-btn:hover {
    border-color: #e63946;
    color: #fff;
}

.date-quick-btn.active {
    background: #e63946;
    border-color: #e63946;
    color: #fff;
}

.date-input {
    width: 100%;
    background: #111;
    border: 1px solid #333;
    color: #eee;
    padding: 0.4rem;
    border-radius: 4px;
    font-size: 0.85rem;
}

.date-input::-webkit-calendar-picker-indicator {
    filter: invert(1);
}

/* ========== LAYER TOGGLES ========== */

.layer-toggle {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.25rem 0;
    font-size: 0.85rem;
    color: #ccc;
    cursor: pointer;
}

.layer-toggle input[type="checkbox"] {
    accent-color: #e63946;
}

.layer-toggle:hover {
    color: #fff;
}

/* ========== MAP STATS ========== */

.map-stats {
    position: absolute;
    bottom: 20px;
    left: 10px;
    z-index: 1000;
    background: rgba(10, 10, 26, 0.9);
    border: 1px solid #333;
    border-radius: 4px;
    padding: 0.5rem 0.75rem;
    display: flex;
    gap: 1rem;
}

.stat {
    display: flex;
    align-items: center;
    gap: 0.3rem;
}

.stat-label {
    color: #888;
    font-size: 0.75rem;
}

.stat-value {
    color: #fff;
    font-size: 0.85rem;
    font-weight: bold;
}

/* ========== MAP LEGEND ========== */

.map-legend {
    position: absolute;
    bottom: 20px;
    right: 10px;
    z-index: 1000;
    background: rgba(10, 10, 26, 0.9);
    border: 1px solid #333;
    border-radius: 4px;
    padding: 0.5rem 0.75rem;
    display: flex;
    gap: 0.75rem;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 0.3rem;
    font-size: 0.7rem;
    color: #aaa;
}

.legend-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
}

/* ========== LOADING OVERLAY ========== */

.loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(10, 10, 26, 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
}

.loading-overlay.hidden {
    display: none;
}

.loading-spinner {
    color: #e63946;
    font-size: 1rem;
}

/* ========== DEBUG BAR ========== */

.debug-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: #050508;
    color: #0f0;
    padding: 0.3rem 0.75rem;
    font-family: monospace;
    font-size: 0.7rem;
    border-top: 1px solid #222;
    z-index: 9999;
    height: 22px;
}

/* ========== POPUPS ========== */

.popup-title {
    font-weight: bold;
    color: #e63946;
    margin-bottom: 0.3rem;
}

.popup-status {
    font-size: 0.85rem;
    padding: 0.2rem 0.4rem;
    border-radius: 3px;
    margin-bottom: 0.3rem;
    display: inline-block;
}

.popup-status.status-fresh { background: #00ff88; color: #000; }
.popup-status.status-recent { background: #ffff00; color: #000; }
.popup-status.status-aging { background: #ffa500; color: #000; }
.popup-status.status-overdue { background: #ff4444; color: #fff; }
.popup-status.status-never { background: #ff0000; color: #fff; }

.popup-detail {
    font-size: 0.8rem;
    color: #666;
    line-height: 1.4;
}

.popup-divider {
    border-top: 1px solid #222;
    margin: 0.5rem 0;
}

.popup-form { margin-top: 0.5rem; }
.popup-field { margin-bottom: 0.5rem; }

.popup-field label {
    display: block;
    font-size: 0.75rem;
    color: #888;
    margin-bottom: 0.2rem;
}

.popup-textarea {
    width: 100%;
    min-height: 50px;
    background: #111;
    border: 1px solid #333;
    border-radius: 4px;
    color: #eee;
    padding: 0.4rem;
    font-size: 0.8rem;
    resize: vertical;
}

.popup-textarea:focus {
    outline: none;
    border-color: #e63946;
}

.popup-cycle {
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.popup-input {
    width: 60px;
    background: #111;
    border: 1px solid #333;
    border-radius: 4px;
    color: #eee;
    padding: 0.3rem;
    font-size: 0.85rem;
    text-align: center;
}

.popup-input:focus {
    outline: none;
    border-color: #e63946;
}

.popup-cycle span {
    font-size: 0.8rem;
    color: #888;
}

.popup-actions {
    display: flex;
    gap: 0.4rem;
    margin-top: 0.5rem;
}

.popup-btn {
    flex: 1;
    padding: 0.4rem 0.6rem;
    border-radius: 4px;
    font-size: 0.75rem;
    cursor: pointer;
    border: 1px solid;
    transition: all 0.2s;
}

.popup-btn.save {
    background: #e63946;
    border-color: #e63946;
    color: #fff;
}

.popup-btn.save:hover {
    background: #d32f3f;
}

.popup-btn.clear {
    background: transparent;
    border-color: #444;
    color: #888;
}

.popup-btn.clear:hover {
    border-color: #ff4444;
    color: #ff4444;
}

/* ========== LEAFLET OVERRIDES ========== */

.leaflet-popup-content-wrapper {
    background: #0a0a1a;
    color: #eee;
    border-radius: 6px;
}

.leaflet-popup-tip {
    background: #0a0a1a;
}

.leaflet-popup-close-button {
    color: #888 !important;
}

.leaflet-control-zoom a {
    background: #0a0a1a !important;
    color: #eee !important;
    border-color: #333 !important;
}

.leaflet-control-zoom a:hover {
    background: #1a1a2e !important;
}

.leaflet-control-attribution {
    background: rgba(10, 10, 26, 0.8) !important;
    color: #666 !important;
    font-size: 0.6rem !important;
}

.leaflet-control-attribution a {
    color: #888 !important;
}

/* ========== RELAY MARKERS ========== */

.relay-marker {
    background: transparent;
    border: none;
    text-align: center;
    line-height: 12px;
}

/* ========== RESPONSIVE ========== */

@media (max-width: 600px) {
    header h1 {
        font-size: 0.95rem;
    }
    
    #district-name {
        display: none;
    }
    
    .map-stats,
    .map-legend {
        font-size: 0.7rem;
        padding: 0.4rem 0.5rem;
    }
    
    .map-legend {
        flex-wrap: wrap;
        max-width: 150px;
    }
    
    .drawer-panel {
        width: 260px;
    }
}

/* ========== REFRESH TOAST ========== */

.refresh-toast {
    position: absolute;
    top: 12px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 1100;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 20px;
    background: rgba(10, 10, 26, 0.92);
    border: 1px solid rgba(230, 57, 70, 0.4);
    border-radius: 10px;
    color: #fff;
    font-size: 13px;
    font-weight: 500;
    letter-spacing: 0.3px;
    backdrop-filter: blur(8px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    transition: opacity 0.3s ease, transform 0.3s ease;
    pointer-events: none;
}

.refresh-toast.hidden {
    opacity: 0;
    transform: translateX(-50%) translateY(-20px);
}

.refresh-spinner {
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255, 255, 255, 0.2);
    border-top-color: #e63946;
    border-radius: 50%;
    animation: refresh-spin 0.8s linear infinite;
}

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