:root {
    --primary: #1a73e8;
    --primary-dark: #1557b0;
    --primary-light: #e8f0fe;
    --danger: #d93025;
    --danger-dark: #b3261e;
    --success: #1e8e3e;
    --warning: #f9ab00;
    --bg: #f8f9fa;
    --surface: #ffffff;
    --text: #202124;
    --text-secondary: #5f6368;
    --border: #dadce0;
    --shadow: 0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.24);
    --shadow-lg: 0 4px 16px rgba(0,0,0,0.16);
    --radius: 12px;
    --radius-sm: 8px;
}

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    overflow: hidden;
    height: 100vh;
    height: 100dvh;
    -webkit-tap-highlight-color: transparent;
}

/* LOGIN */
.login-wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    min-height: 100dvh;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    padding: 20px;
}

.login-card {
    background: var(--surface);
    border-radius: 20px;
    padding: 48px 40px;
    width: 100%;
    max-width: 420px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
    text-align: center;
}

.login-card .logo {
    width: 72px;
    height: 72px;
    background: linear-gradient(135deg, #1a73e8, #764ba2);
    border-radius: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 24px;
    font-size: 32px;
    color: white;
}

.login-card h1 {
    font-size: 26px;
    font-weight: 700;
    margin-bottom: 8px;
    color: var(--text);
}

.login-card p {
    color: var(--text-secondary);
    margin-bottom: 32px;
    font-size: 14px;
}

.login-card input[type="email"],
.login-card input[type="password"] {
    width: 100%;
    padding: 14px 18px;
    border: 2px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 16px;
    outline: none;
    transition: border-color 0.2s;
    margin-bottom: 16px;
}

.login-card input[type="email"]:focus,
.login-card input[type="password"]:focus {
    border-color: var(--primary);
}

.login-card button {
    width: 100%;
    padding: 14px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}

.login-card button:hover { background: var(--primary-dark); }

.login-error {
    color: var(--danger);
    font-size: 13px;
    margin-top: 12px;
    display: none;
}

/* APP LAYOUT */
.app {
    display: flex;
    height: 100vh;
    height: 100dvh;
}

/* SIDEBAR */
.sidebar {
    width: 360px;
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    z-index: 1000;
    transition: transform 0.3s ease;
}

.sidebar-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--surface);
}

.sidebar-header .logo-sm {
    width: 36px;
    height: 36px;
    background: linear-gradient(135deg, #1a73e8, #764ba2);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 18px;
    flex-shrink: 0;
}

.sidebar-header h2 {
    font-size: 18px;
    font-weight: 700;
    flex: 1;
}

.sidebar-header .btn-icon {
    width: 36px;
    height: 36px;
    border: none;
    background: none;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    font-size: 18px;
    transition: background 0.2s;
}

.sidebar-header .btn-icon:hover { background: var(--bg); }

.sidebar-actions {
    padding: 16px 20px;
    display: flex;
    gap: 8px;
    border-bottom: 1px solid var(--border);
}

.btn {
    padding: 10px 18px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
}

.btn-primary {
    background: var(--primary);
    color: white;
}
.btn-primary:hover { background: var(--primary-dark); }

.btn-secondary {
    background: var(--primary-light);
    color: var(--primary);
}
.btn-secondary:hover { background: #d2e3fc; }

.btn-danger {
    background: #fce8e6;
    color: var(--danger);
}
.btn-danger:hover { background: #f5c6c2; }

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

.btn-full { width: 100%; justify-content: center; }

/* MAP LIST */
.map-list-section {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
}

.map-list-section h3 {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 8px 8px 12px;
}

.map-item {
    display: flex;
    align-items: center;
    padding: 12px 14px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background 0.15s;
    gap: 12px;
    margin-bottom: 2px;
}

.map-item:hover { background: var(--bg); }
.map-item.active { background: var(--primary-light); }

.map-item-icon {
    width: 40px;
    height: 40px;
    background: var(--primary-light);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--primary);
    font-size: 18px;
    flex-shrink: 0;
}

.map-item.active .map-item-icon {
    background: var(--primary);
    color: white;
}

.map-item-info { flex: 1; min-width: 0; }

.map-item-name {
    font-size: 14px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.map-item-meta {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 2px;
}

.map-item-actions {
    display: flex;
    gap: 2px;
    opacity: 0;
    transition: opacity 0.15s;
}

.map-item:hover .map-item-actions { opacity: 1; }

.map-item-actions button {
    width: 30px;
    height: 30px;
    border: none;
    background: none;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    color: var(--text-secondary);
    transition: all 0.15s;
}

.map-item-actions button:hover {
    background: var(--border);
}

.map-item-actions button.delete:hover {
    background: #fce8e6;
    color: var(--danger);
}

.empty-state {
    text-align: center;
    padding: 48px 24px;
    color: var(--text-secondary);
}

.empty-state .icon {
    font-size: 48px;
    margin-bottom: 16px;
    opacity: 0.5;
}

.empty-state p { font-size: 14px; line-height: 1.6; }

/* MAP AREA */
.map-container {
    flex: 1;
    position: relative;
}

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

/* MAP CONTROLS */
.map-toolbar {
    position: absolute;
    top: 16px;
    right: 16px;
    z-index: 999;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.map-btn {
    width: 44px;
    height: 44px;
    background: var(--surface);
    border: none;
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    color: var(--text);
    transition: all 0.2s;
}

.map-btn:hover { background: var(--bg); }
.map-btn.active { background: var(--primary); color: white; }

/* CURRENT MAP INFO BAR */
.map-info-bar {
    position: absolute;
    top: 16px;
    left: 16px;
    right: 80px;
    z-index: 999;
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    padding: 12px 18px;
    display: flex;
    align-items: center;
    gap: 12px;
}

.map-info-bar .map-name {
    font-weight: 700;
    font-size: 15px;
    flex: 1;
}

.map-info-bar .point-count {
    font-size: 13px;
    color: var(--text-secondary);
    background: var(--bg);
    padding: 4px 10px;
    border-radius: 20px;
}

/* POINT LIST PANEL */
.point-panel {
    position: absolute;
    bottom: 16px;
    left: 16px;
    z-index: 999;
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    width: 340px;
    max-height: 50vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: transform 0.3s ease, opacity 0.3s ease;
}

.point-panel.hidden {
    transform: translateY(20px);
    opacity: 0;
    pointer-events: none;
}

.point-panel-header {
    padding: 14px 18px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 600;
    font-size: 14px;
}

.point-panel-header .count {
    background: var(--primary);
    color: white;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 700;
}

.point-panel-search {
    padding: 10px 14px;
    border-bottom: 1px solid var(--border);
}

.point-panel-search input {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 13px;
    outline: none;
}

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

.point-list {
    flex: 1;
    overflow-y: auto;
    padding: 6px;
}

.point-item {
    display: flex;
    align-items: center;
    padding: 10px 12px;
    border-radius: 6px;
    cursor: pointer;
    gap: 10px;
    transition: background 0.15s;
    font-size: 13px;
}

.point-item:hover { background: var(--bg); }

.point-marker {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    flex-shrink: 0;
}

.point-item-info { flex: 1; min-width: 0; }

.point-item-name {
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.point-item-address {
    font-size: 12px;
    color: var(--text);
    margin-top: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.point-item-coords {
    font-size: 11px;
    color: var(--text-secondary);
    margin-top: 1px;
}

/* MODAL */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    padding: 20px;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s;
}

.modal-overlay.active {
    opacity: 1;
    pointer-events: all;
}

.modal {
    background: var(--surface);
    border-radius: var(--radius);
    width: 100%;
    max-width: 520px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
    transform: scale(0.95);
    transition: transform 0.2s;
}

.modal-overlay.active .modal { transform: scale(1); }

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

.modal-header h3 { font-size: 18px; font-weight: 700; }

.modal-close {
    width: 32px;
    height: 32px;
    border: none;
    background: none;
    border-radius: 50%;
    cursor: pointer;
    font-size: 20px;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-close:hover { background: var(--bg); }

.modal-body { padding: 24px; }

.modal-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

/* FORM */
.form-group {
    margin-bottom: 18px;
}

.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 6px;
    color: var(--text);
}

.form-group input,
.form-group select {
    width: 100%;
    padding: 10px 14px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s;
}

.form-group input:focus,
.form-group select:focus {
    border-color: var(--primary);
}

/* FILE DROP */
.file-drop {
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 40px 24px;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
    background: var(--bg);
}

.file-drop:hover,
.file-drop.dragover {
    border-color: var(--primary);
    background: var(--primary-light);
}

.file-drop .icon { font-size: 40px; margin-bottom: 12px; opacity: 0.6; }
.file-drop p { font-size: 14px; color: var(--text-secondary); }
.file-drop .format { font-size: 12px; color: var(--text-secondary); margin-top: 8px; }

/* COLUMN MAPPING */
.column-mapping {
    margin-top: 20px;
    padding: 16px;
    background: var(--bg);
    border-radius: var(--radius-sm);
}

.column-mapping h4 {
    font-size: 14px;
    margin-bottom: 12px;
}

.column-row {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 10px;
}

.column-row label {
    font-size: 13px;
    font-weight: 600;
    width: 100px;
    flex-shrink: 0;
}

.column-row select {
    flex: 1;
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 13px;
    outline: none;
}

/* COLOR PICKER */
.color-options {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-top: 8px;
}

.color-option {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 3px solid transparent;
    cursor: pointer;
    transition: all 0.15s;
}

.color-option:hover { transform: scale(1.15); }
.color-option.selected { border-color: var(--text); }

/* PREVIEW TABLE */
.preview-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
    margin-top: 12px;
}

.preview-table th,
.preview-table td {
    padding: 6px 10px;
    border: 1px solid var(--border);
    text-align: left;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 150px;
}

.preview-table th {
    background: var(--bg);
    font-weight: 600;
    position: sticky;
    top: 0;
}

.preview-wrapper {
    max-height: 200px;
    overflow: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    margin-top: 12px;
}

/* TOAST */
.toast-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 3000;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    background: var(--text);
    color: white;
    padding: 12px 20px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    box-shadow: var(--shadow-lg);
    transform: translateX(120%);
    transition: transform 0.3s ease;
    display: flex;
    align-items: center;
    gap: 8px;
}

.toast.show { transform: translateX(0); }
.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }

/* HAMBURGER */
.hamburger {
    display: none;
    position: absolute;
    top: 16px;
    left: 16px;
    z-index: 1001;
    width: 44px;
    height: 44px;
    background: var(--surface);
    border: none;
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow);
    cursor: pointer;
    align-items: center;
    justify-content: center;
    font-size: 22px;
}

/* MOBILE SIDEBAR CLOSE */
.sidebar-close {
    display: none;
    width: 36px;
    height: 36px;
    border: none;
    background: none;
    border-radius: 50%;
    cursor: pointer;
    font-size: 20px;
    color: var(--text-secondary);
    align-items: center;
    justify-content: center;
}

.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.4);
    z-index: 999;
}

/* LEAFLET POPUP */
.leaflet-popup-content-wrapper {
    border-radius: var(--radius-sm) !important;
    box-shadow: var(--shadow-lg) !important;
}

.leaflet-popup-content {
    margin: 14px 18px !important;
    font-family: 'Inter', sans-serif !important;
    font-size: 13px !important;
    line-height: 1.5 !important;
}

.popup-title {
    font-weight: 700;
    font-size: 15px;
    margin-bottom: 6px;
    color: var(--text);
}

.popup-field {
    color: var(--text-secondary);
    margin-bottom: 3px;
}

.popup-field strong {
    color: var(--text);
}

.popup-nav-btn {
    display: block;
    margin-top: 10px;
    padding: 8px 14px;
    background: #1a73e8;
    color: white !important;
    text-align: center;
    text-decoration: none;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    transition: background 0.2s;
}

.popup-nav-btn:hover {
    background: #1557b0;
}

/* RESPONSIVE */
@media (max-width: 768px) {
    .hamburger { display: flex; }
    .sidebar-close { display: flex; }

    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        width: 320px;
        transform: translateX(-100%);
        z-index: 1001;
    }

    .sidebar.open { transform: translateX(0); }
    .sidebar-overlay.open { display: block; }

    .map-info-bar {
        left: 68px;
        right: 68px;
        padding: 10px 14px;
    }

    .map-info-bar .map-name { font-size: 13px; }

    .point-panel {
        left: 10px;
        right: 10px;
        width: auto;
        bottom: 10px;
        max-height: 40vh;
    }

    .map-toolbar {
        right: 10px;
        top: auto;
        bottom: 10px;
        flex-direction: row;
    }

    .point-panel ~ .map-toolbar {
        bottom: auto;
        top: 70px;
    }

    .modal {
        max-width: 100%;
        margin: 10px;
        max-height: 85vh;
    }

    .login-card {
        padding: 36px 28px;
    }
}

@media (max-width: 480px) {
    .sidebar { width: 100%; }
    .sidebar-actions { flex-wrap: wrap; }
    .sidebar-actions .btn { flex: 1; }
}

/* SCROLLBAR */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-secondary); }

/* LOADING SPINNER */
.spinner {
    width: 20px;
    height: 20px;
    border: 2.5px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

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

/* SAFE AREA (iOS) */
@supports (padding-top: env(safe-area-inset-top)) {
    .sidebar-header {
        padding-top: calc(16px + env(safe-area-inset-top));
    }
    .map-info-bar {
        top: calc(16px + env(safe-area-inset-top));
    }
    .hamburger {
        top: calc(16px + env(safe-area-inset-top));
    }
}
