/* ─── Reset & Base ──────────────────────────────────────────── */
:root {
    --primary-color: #3b82f6;
    --bg-color: #f8fafc;
    --text-color: #1e293b;
    --border-color: #e2e8f0;
    --header-height: 56px;
    --panel-bg: rgba(255, 255, 255, 0.97);
    --panel-border: #e2e8f0;
    --field-bg: #f1f5f9;
    --field-border: #cbd5e1;
    --field-text: #1e293b;
    --muted-text: #64748b;
    --accent: #3b82f6;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
body {
    font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--bg-color);
    color: var(--text-color);
}

/* ─── App Header ────────────────────────────────────────────── */
.app-header {
    background: rgba(255, 255, 255, 0.92);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    padding: 0 1.25rem;
    height: var(--header-height);
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--border-color);
    box-shadow: 0 1px 3px rgb(0 0 0 / 0.06);
    z-index: 1000;
    position: relative;
    overflow: hidden;
}

/* ─── Header Brand (SVG logo + "Map" label) ─────────────────── */
.header-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
    min-width: 0;
    flex-shrink: 1;
}
.brand-logo {
    height: 28px;
    width: auto;
    flex-shrink: 0;
}
.brand-map-label {
    font-family: 'Georgia', 'Times New Roman', 'Garamond', serif;
    font-size: 1.3rem;
    font-weight: 400;
    color: #1B2A4A;
    letter-spacing: 0.06em;
    white-space: nowrap;
}

.app-header .badge {
    font-size: 0.65rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    background: rgba(59, 130, 246, 0.12);
    color: #3b82f6;
    padding: 2px 8px;
    border-radius: 6px;
    flex-shrink: 0;
}
.header-actions {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-shrink: 0;
}

/* ─── Viewer Link ───────────────────────────────────────────── */
.viewer-link,
.nav-link {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 6px 14px;
    border: 1.5px solid var(--border-color);
    border-radius: 10px;
    text-decoration: none;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--muted-text);
    transition: all 0.2s;
    white-space: nowrap;
}
.viewer-link:hover,
.nav-link:hover {
    background: var(--primary-color);
    border-color: var(--primary-color);
    color: white;
}

/* ─── User Badge ────────────────────────────────────────────── */
.user-badge {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 4px 12px;
    background: rgba(34, 197, 94, 0.08);
    border: 1px solid rgba(34, 197, 94, 0.25);
    border-radius: 20px;
    font-size: 0.75rem;
    color: #16a34a;
    white-space: nowrap;
}
.user-badge img {
    width: 24px;
    height: 24px;
    border-radius: 50%;
}
.sign-out-btn {
    background: none;
    border: none;
    color: #94a3b8;
    cursor: pointer;
    font-size: 0.75rem;
    padding: 2px 6px;
    transition: color 0.15s;
}
.sign-out-btn:hover { color: #ef4444; }

/* ─── Layer Selector ────────────────────────────────────────── */
.layer-select {
    padding: 8px 30px 8px 12px;
    background: var(--field-bg);
    border: 1px solid var(--field-border);
    border-radius: 8px;
    color: var(--field-text);
    font-family: 'Inter', sans-serif;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%2364748b'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M19 9l-7 7-7-7'%3E%3C/path%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 8px center;
    background-size: 14px;
}
.layer-select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(59,130,246,0.15);
}

/* ─── Header Button Group ──────────────────────────────────── */
.header-btn-group {
    display: flex;
    gap: 2px;
    background: var(--field-bg);
    border: 1px solid var(--field-border);
    border-radius: 10px;
    padding: 2px;
}
.header-btn {
    padding: 6px 14px;
    border: none;
    border-radius: 8px;
    font-family: 'Inter', sans-serif;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
    background: transparent;
    color: var(--muted-text);
    white-space: nowrap;
}
.header-btn:hover {
    background: white;
    color: var(--text-color);
    box-shadow: 0 1px 4px rgba(0,0,0,0.08);
}

.btn-sm {
    padding: 6px 14px;
    border: none;
    border-radius: 6px;
    font-family: 'Inter', sans-serif;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
}
.btn-apply { background: #3b82f6; color: white; }
.btn-delete { background: #ef4444; color: white; }
.btn-cancel { background: #94a3b8; color: white; }
.btn-autofill { background: linear-gradient(135deg, #f59e0b, #d97706); color: white; }
.btn-autofill:hover { transform: translateY(-1px); box-shadow: 0 3px 10px rgba(245,158,11,0.3); }

/* ─── Status ────────────────────────────────────────────────── */
.status {
    font-size: 0.8rem;
    color: var(--muted-text);
    padding: 0 12px;
}
.status.saved { color: #10b981; }
.status.unsaved { color: #f59e0b; }

/* ─── Map ───────────────────────────────────────────────────── */
#map {
    width: 100%;
    height: calc(100vh - var(--header-height));
}

/* ─── Side Panel (Zone Properties) ──────────────────────────── */
.side-panel {
    position: absolute;
    top: calc(var(--header-height) + 12px);
    left: 12px;
    width: 330px;
    max-height: calc(100vh - var(--header-height) - 24px);
    overflow-y: auto;
    background: var(--panel-bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--panel-border);
    border-radius: 12px;
    padding: 16px;
    z-index: 1000;
    display: none;
    box-shadow: 0 8px 32px rgba(0,0,0,0.08);
}
.side-panel.visible { display: block; }
.side-panel h3 {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--accent);
    margin-bottom: 12px;
}

/* ─── Form Fields ───────────────────────────────────────────── */
.field-group {
    margin-bottom: 10px;
}
.field-group label {
    display: block;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--muted-text);
    margin-bottom: 4px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.field-group input, .field-group select {
    width: 100%;
    padding: 8px 10px;
    background: var(--field-bg);
    border: 1px solid var(--field-border);
    border-radius: 6px;
    color: var(--field-text);
    font-family: 'Inter', sans-serif;
    font-size: 0.85rem;
}
.field-group input:focus, .field-group select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(59,130,246,0.15);
}

.panel-actions {
    display: flex;
    gap: 8px;
    margin-top: 14px;
    flex-wrap: wrap;
}

/* ─── Mode Toggle Bar ───────────────────────────────────────── */
.mode-bar {
    display: flex;
    gap: 4px;
    margin-bottom: 12px;
    background: var(--field-bg);
    border-radius: 8px;
    padding: 3px;
}
.mode-btn {
    flex: 1;
    padding: 7px 6px;
    border: none;
    border-radius: 6px;
    font-family: 'Inter', sans-serif;
    font-size: 0.73rem;
    font-weight: 600;
    cursor: pointer;
    background: transparent;
    color: var(--muted-text);
    transition: all 0.15s;
    text-align: center;
}
.mode-btn:hover { color: var(--text-color); }
.mode-btn.active {
    background: var(--accent);
    color: white;
    box-shadow: 0 2px 8px rgba(59,130,246,0.2);
}

/* ─── Simplify Controls ─────────────────────────────────────── */
.simplify-row {
    display: flex;
    gap: 6px;
    align-items: center;
    margin-bottom: 10px;
}
.simplify-row .btn-sm { flex-shrink: 0; }
.vertex-count {
    font-size: 0.75rem;
    color: var(--muted-text);
    margin-left: auto;
}

.mode-hint {
    font-size: 0.72rem;
    color: #d97706;
    padding: 6px 8px;
    background: rgba(245,158,11,0.08);
    border: 1px solid rgba(245,158,11,0.15);
    border-radius: 6px;
    margin-bottom: 10px;
    line-height: 1.4;
}

/* ─── Auto-fill feedback ────────────────────────────────────── */
.autofill-info {
    font-size: 0.72rem;
    color: var(--muted-text);
    padding: 6px 8px;
    background: rgba(59,130,246,0.05);
    border: 1px solid rgba(59,130,246,0.12);
    border-radius: 6px;
    margin-bottom: 10px;
    line-height: 1.4;
    display: none;
}
.autofill-info.visible { display: block; }

/* ─── Zone List Panel ───────────────────────────────────────── */
.zone-list-panel {
    position: absolute;
    top: calc(var(--header-height) + 12px);
    right: 12px;
    width: 280px;
    max-height: calc(100vh - var(--header-height) - 24px);
    display: flex;
    flex-direction: column;
    background: var(--panel-bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--panel-border);
    border-radius: 12px;
    padding: 12px;
    z-index: 1000;
    box-shadow: 0 8px 32px rgba(0,0,0,0.08);
    overflow: hidden;
}
.zone-list-header {
    flex-shrink: 0;
}
.zone-list-header h3 {
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--accent);
    margin-bottom: 8px;
}
.zone-list-divider {
    padding-bottom: 8px;
    margin-bottom: 4px;
    border-bottom: 1px solid var(--border-color);
}
.zone-list-scroll {
    flex: 1;
    overflow-y: auto;
    min-height: 0;
}
.btn-from-property {
    background: linear-gradient(135deg, #8b5cf6, #7c3aed);
    color: white;
}
.btn-from-property:hover {
    transform: translateY(-1px);
    box-shadow: 0 3px 10px rgba(139,92,246,0.3);
}
.btn-from-property.active {
    background: linear-gradient(135deg, #f59e0b, #d97706);
    box-shadow: 0 0 0 2px #fbbf24;
}
.zone-item {
    padding: 6px 8px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.8rem;
    color: var(--text-color);
    transition: all 0.15s;
    border-left: 3px solid transparent;
}
.zone-item:hover {
    background: #f1f5f9;
    border-left-color: var(--accent);
}
.zone-item.selected {
    background: rgba(59,130,246,0.08);
    border-left-color: var(--accent);
    color: var(--text-color);
    font-weight: 500;
}
.zone-count {
    font-size: 0.75rem;
    color: var(--muted-text);
    margin-bottom: 8px;
}

/* ─── Zone search (inline override) ─────────────────────────── */
#zoneSearch {
    background: var(--field-bg) !important;
    border-color: var(--field-border) !important;
    color: var(--field-text) !important;
}

/* ─── Instructions Toast ────────────────────────────────────── */
.instructions {
    position: absolute;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--panel-bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 10px 20px;
    z-index: 1000;
    font-size: 0.8rem;
    color: var(--muted-text);
    text-align: center;
    max-width: 600px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.06);
}
.instructions kbd {
    background: #e2e8f0;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.75rem;
    color: var(--text-color);
}

/* ─── Vertex Remove Markers ─────────────────────────────────── */
.vertex-remove-marker {
    width: 12px;
    height: 12px;
    background: #ef4444;
    border: 2px solid white;
    border-radius: 50%;
    cursor: pointer;
    transition: transform 0.1s;
}
.vertex-remove-marker:hover {
    transform: scale(1.5);
    background: #ff0000;
}

/* ─── Leaflet Draw Customizations ───────────────────────────── */
.leaflet-draw-toolbar a { background-color: white !important; }

/* ─── Mode Cursor Styles ────────────────────────────────────── */
.move-mode-cursor { cursor: move !important; }
.remove-mode-cursor { cursor: crosshair !important; }

/* ─── Auth Overlay ──────────────────────────────────────────── */
.auth-overlay {
    position: fixed;
    inset: 0;
    z-index: 9999;
    background: rgba(248, 250, 252, 0.92);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 1.5rem;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
}
.auth-overlay.hidden { display: none; }
.auth-card {
    background: white;
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 2.5rem;
    text-align: center;
    max-width: 400px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.08);
}
.auth-card h2 {
    color: var(--text-color);
    margin: 0 0 0.5rem;
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: -0.03em;
}
.auth-card p {
    color: var(--muted-text);
    margin: 0 0 1.5rem;
    font-size: 0.9rem;
}
.auth-error {
    color: #ef4444;
    margin-top: 1rem;
    font-size: 0.85rem;
}
.auth-divider {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 16px 0;
    color: #94a3b8;
    font-size: 0.8rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}
.auth-divider::before,
.auth-divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: #e2e8f0;
}
.apple-sign-in-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 300px;
    height: 44px;
    background: #000;
    color: #fff;
    border: none;
    border-radius: 8px;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    font-size: 15px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s;
}
.apple-sign-in-btn:hover { background: #1d1d1f; }
.apple-sign-in-btn svg { flex-shrink: 0; }

/* ─── Pump station SVG icons ────────────────────────────────── */
.pump-station-icon {
    background: transparent !important;
    border: none !important;
    transition: transform 0.15s ease, filter 0.15s ease;
}

/* ─── Popups (match viewer) ─────────────────────────────────── */
.leaflet-popup-content-wrapper {
    border-radius: 12px !important;
    box-shadow: 0 10px 15px -3px rgb(0 0 0 / 0.1) !important;
    padding: 4px;
}
.leaflet-popup-content {
    font-family: 'Inter', sans-serif;
    margin: 12px 14px;
}

/* ─── Mobile Responsive ─────────────────────────────────────── */
@media (max-width: 768px) {
    :root {
        --header-height: 48px;
    }

    .app-header {
        padding: 0 0.75rem;
    }

    .brand-logo {
        height: 22px;
    }

    .brand-map-label {
        font-size: 1.05rem;
    }

    .app-header .badge {
        display: none;
    }

    .header-actions {
        gap: 4px;
    }

    .btn {
        padding: 6px 12px;
        font-size: 0.78rem;
    }

    .viewer-link span,
    .nav-link span {
        display: none;
    }

    .user-badge span {
        display: none;
    }

    .side-panel {
        width: calc(100vw - 24px);
        left: 12px;
    }

    .zone-list-panel {
        width: calc(100vw - 24px);
        right: 12px;
    }
}
