/**
 * ListKontrol - Main Stylesheet
 * ============================
 * 
 * Design system based on a professional construction/industrial aesthetic.
 * Uses Barlow (body) and JetBrains Mono (technical data) for clear hierarchy.
 * Color palette: Dark navy primary, orange accent for CTAs and highlights.
 * 
 * Architecture:
 * - CSS custom properties for consistent theming
 * - Mobile-first responsive breakpoint at 768px
 * - BEM-inspired naming for clarity
 * - Animations kept minimal for professional feel
 */

@import url('https://fonts.googleapis.com/css2?family=Barlow:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap');

/* ==========================================================================
   Design Tokens
   ========================================================================== */
:root {
    --primary: #0f172a;
    --primary-light: #1e293b;
    --accent: #f97316;
    --accent-dark: #ea580c;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --bg: #f8fafc;
    --card: #ffffff;
    --text: #0f172a;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --shadow: rgba(15, 23, 42, 0.1);
}

/* ==========================================================================
   Reset & Base
   ========================================================================== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Barlow', sans-serif;
    background: linear-gradient(135deg, #f8fafc 0%, #e2e8f0 100%);
    color: var(--text);
    min-height: 100vh;
}

/* ==========================================================================
   Layout: App Container (sidebar + main split)
   ========================================================================== */
.app-container {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* ==========================================================================
   Sidebar: Project navigation and management
   ========================================================================== */
.sidebar {
    width: 360px;
    background: var(--card);
    border-right: 2px solid var(--border);
    display: flex;
    flex-direction: column;
    box-shadow: 4px 0 24px var(--shadow);
    position: relative;
    z-index: 1000;
}

.header {
    padding: 24px;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
    color: white;
    border-bottom: 3px solid var(--accent);
}

.header h1 {
    font-size: 24px;
    font-weight: 700;
    margin-bottom: 4px;
    letter-spacing: -0.5px;
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

/* Version badge - monospace for technical appearance */
.version {
    display: inline-block;
    font-size: 10px;
    font-weight: 600;
    padding: 3px 8px;
    background: linear-gradient(135deg, rgba(255,255,255,0.2), rgba(255,255,255,0.1));
    border: 1px solid rgba(255,255,255,0.3);
    border-radius: 12px;
    color: rgba(255,255,255,0.95);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-family: 'JetBrains Mono', monospace;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.header p {
    font-size: 13px;
    opacity: 0.8;
    font-family: 'JetBrains Mono', monospace;
}

.project-section {
    padding: 20px;
    border-bottom: 1px solid var(--border);
}

.section-title {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-muted);
    margin-bottom: 12px;
}

/* ==========================================================================
   Buttons: Shared button system
   ========================================================================== */
.btn {
    padding: 12px 20px;
    border: none;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 14px;
    font-family: 'Barlow', sans-serif;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.btn-primary {
    background: var(--accent);
    color: white;
    width: 100%;
    justify-content: center;
}

.btn-primary:hover {
    background: var(--accent-dark);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(249, 115, 22, 0.3);
}

.btn-secondary {
    background: var(--bg);
    color: var(--text);
    border: 1px solid var(--border);
}

.btn-secondary:hover {
    background: white;
    border-color: var(--accent);
}

.btn-danger {
    background: var(--danger);
    color: white;
}

.btn-danger:hover {
    background: #dc2626;
}

.btn-success {
    background: var(--success);
    color: white;
}

.btn-success:hover {
    background: #059669;
}

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

/* ==========================================================================
   Project Cards: Sidebar project list items
   ========================================================================== */
.project-list {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
}

.project-card {
    background: white;
    border: 2px solid var(--border);
    border-radius: 12px;
    padding: 16px;
    margin-bottom: 12px;
    cursor: pointer;
    transition: all 0.2s;
}

.project-card:hover {
    border-color: var(--accent);
    transform: translateX(4px);
    box-shadow: 0 4px 12px var(--shadow);
}

.project-card.active {
    border-color: var(--accent);
    background: linear-gradient(135deg, #fff7ed 0%, white 100%);
    box-shadow: 0 4px 16px rgba(249, 115, 22, 0.2);
}

.project-name {
    font-weight: 600;
    font-size: 15px;
    margin-bottom: 8px;
    color: var(--text);
}

.project-meta {
    display: flex;
    gap: 12px;
    font-size: 12px;
    color: var(--text-muted);
    font-family: 'JetBrains Mono', monospace;
}

.project-meta span {
    display: flex;
    align-items: center;
    gap: 4px;
}

/* ==========================================================================
   Status Badges: Visual indicators for point status
   ========================================================================== */
.badge {
    padding: 4px 10px;
    border-radius: 6px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.badge-todo { background: #fef3c7; color: #92400e; }
.badge-progress { background: #dbeafe; color: #1e40af; }
.badge-done { background: #d1fae5; color: #065f46; }

/* ==========================================================================
   Main Content: Map area and toolbar
   ========================================================================== */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.toolbar {
    background: white;
    border-bottom: 2px solid var(--border);
    padding: 16px 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 2px 8px var(--shadow);
}

.toolbar-left {
    display: flex;
    gap: 12px;
    align-items: center;
}

.toolbar-right {
    display: flex;
    gap: 8px;
}

.current-project {
    font-weight: 600;
    font-size: 18px;
    color: var(--primary);
}

#map {
    flex: 1;
    position: relative;
}

/* ==========================================================================
   Modal System: Overlay dialogs for forms and confirmations
   ========================================================================== */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(15, 23, 42, 0.7);
    backdrop-filter: blur(4px);
    z-index: 2000;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.2s;
}

.modal.active {
    display: flex;
}

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

.modal-content {
    background: white;
    border-radius: 16px;
    width: 90%;
    max-width: 600px;
    max-height: 85vh;
    overflow-y: auto;
    box-shadow: 0 20px 60px rgba(15, 23, 42, 0.3);
    animation: slideUp 0.3s;
}

@keyframes slideUp {
    from { transform: translateY(20px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

.modal-header {
    padding: 24px;
    border-bottom: 2px solid var(--border);
    background: linear-gradient(135deg, var(--bg) 0%, white 100%);
}

.modal-header h2 {
    font-size: 22px;
    font-weight: 700;
    color: var(--primary);
}

.modal-body {
    padding: 24px;
}

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

/* ==========================================================================
   Forms: Input fields, textareas, selects
   ========================================================================== */
.form-group {
    margin-bottom: 20px;
}

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

.form-input,
.form-textarea,
.form-select {
    width: 100%;
    padding: 12px 16px;
    border: 2px solid var(--border);
    border-radius: 8px;
    font-size: 14px;
    font-family: 'Barlow', sans-serif;
    transition: all 0.2s;
}

.form-input:focus,
.form-textarea:focus,
.form-select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(249, 115, 22, 0.1);
}

.form-textarea {
    resize: vertical;
    min-height: 100px;
}

/* ==========================================================================
   Photo Upload: Drag area and multi-photo grid preview
   ========================================================================== */
.photo-upload {
    border: 2px dashed var(--border);
    border-radius: 8px;
    padding: 32px;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
    background: var(--bg);
}

.photo-upload:hover {
    border-color: var(--accent);
    background: white;
}

.photo-preview {
    max-width: 100%;
    max-height: 200px;
    margin-top: 12px;
    border-radius: 8px;
    box-shadow: 0 4px 12px var(--shadow);
}

/* Multi-photo grid: Shows thumbnails of all attached photos */
.photo-previews-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    gap: 8px;
    margin-top: 12px;
}

.photo-previews-grid .photo-thumb {
    position: relative;
    border-radius: 8px;
    overflow: hidden;
    aspect-ratio: 1;
}

.photo-previews-grid .photo-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.photo-previews-grid .photo-thumb .remove-photo {
    position: absolute;
    top: 4px;
    right: 4px;
    background: var(--danger);
    color: white;
    border: none;
    border-radius: 50%;
    width: 24px;
    height: 24px;
    cursor: pointer;
    font-size: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.2s;
}

.photo-previews-grid .photo-thumb:hover .remove-photo {
    opacity: 1;
}

/* ==========================================================================
   Points Panel: Floating side panel with point list
   ========================================================================== */
.points-panel {
    position: absolute;
    top: 16px;
    right: 16px;
    width: 320px;
    max-height: calc(100vh - 160px);
    background: white;
    border-radius: 12px;
    box-shadow: 0 8px 32px var(--shadow);
    overflow: hidden;
    z-index: 1000;
    display: none;
}

.points-panel.active {
    display: flex;
    flex-direction: column;
}

.points-header {
    padding: 16px;
    background: var(--primary);
    color: white;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.points-header h3 {
    font-size: 16px;
    font-weight: 600;
}

.close-panel {
    background: transparent;
    border: none;
    color: white;
    cursor: pointer;
    font-size: 20px;
    padding: 4px;
}

.points-list {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
}

.point-item {
    background: var(--bg);
    border: 2px solid var(--border);
    border-radius: 8px;
    padding: 12px;
    margin-bottom: 8px;
    cursor: pointer;
    transition: all 0.2s;
}

.point-item:hover {
    border-color: var(--accent);
    transform: translateX(-4px);
}

.point-item.selected {
    border-color: var(--accent);
    background: #fff7ed;
}

.point-header {
    display: flex;
    justify-content: space-between;
    align-items: start;
    margin-bottom: 8px;
}

.point-title {
    font-weight: 600;
    font-size: 14px;
    color: var(--primary);
}

.point-address {
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: 8px;
    font-style: italic;
}

.point-comment {
    font-size: 13px;
    color: var(--text);
    margin-bottom: 8px;
    line-height: 1.4;
}

.point-actions {
    display: flex;
    gap: 12px;
    margin-top: 12px;
    flex-wrap: wrap;
    align-items: center;
}

/* Status selector: Quick-toggle buttons for point status */
.status-selector {
    display: flex;
    gap: 6px;
    background: var(--bg);
    padding: 4px;
    border-radius: 8px;
    border: 1px solid var(--border);
}

.btn-status {
    width: 40px;
    height: 40px;
    border: 2px solid transparent;
    border-radius: 6px;
    background: white;
    cursor: pointer;
    font-size: 20px;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-status:hover {
    transform: scale(1.1);
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}

.btn-status.status-todo.active { border-color: #f59e0b; background: #fef3c7; }
.btn-status.status-progress.active { border-color: #3b82f6; background: #dbeafe; }
.btn-status.status-done.active { border-color: #10b981; background: #d1fae5; }

/* ==========================================================================
   Animations
   ========================================================================== */
.spinner {
    border: 3px solid var(--border);
    border-top: 3px solid var(--accent);
    border-radius: 50%;
    width: 24px;
    height: 24px;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

@keyframes pulse {
    0%, 100% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.1); opacity: 0.8; }
}

/* ==========================================================================
   Leaflet Overrides: Custom popup and control styles
   ========================================================================== */
.custom-popup {
    font-family: 'Barlow', sans-serif;
}

.custom-popup .leaflet-popup-content-wrapper {
    border-radius: 8px;
    padding: 0;
}

.custom-popup .leaflet-popup-content {
    margin: 0;
    width: 240px !important;
}

.leaflet-control-layers {
    border-radius: 8px !important;
    border: 2px solid var(--border) !important;
    box-shadow: 0 4px 12px var(--shadow) !important;
}

.leaflet-control-layers-toggle {
    background-size: 20px 20px !important;
    width: 40px !important;
    height: 40px !important;
}

.leaflet-control-layers-list {
    font-family: 'Barlow', sans-serif !important;
}

.leaflet-control-layers label {
    font-size: 14px !important;
    padding: 4px 0 !important;
}

.popup-content { padding: 12px; }
.popup-status { margin-bottom: 8px; }
.popup-comment { font-size: 13px; margin-bottom: 8px; color: var(--text-muted); }
.popup-image { width: 100%; height: 120px; object-fit: cover; border-radius: 6px; margin-bottom: 8px; }

/* ==========================================================================
   Responsive: Mobile layout (sidebar becomes full-screen overlay)
   ========================================================================== */
@media (max-width: 768px) {
    .sidebar {
        width: 100%;
        max-width: 100%;
        position: fixed;
        left: -100%;
        transition: left 0.3s;
        z-index: 1500;
        height: 100vh;
    }

    .sidebar.mobile-open { left: 0; }

    .main-content { width: 100%; }

    .toolbar {
        flex-direction: column;
        gap: 12px;
        align-items: stretch;
    }

    .toolbar-left,
    .toolbar-right {
        width: 100%;
        justify-content: center;
    }

    .toolbar-right { flex-wrap: wrap; }

    .btn-sm {
        padding: 10px 16px;
        font-size: 13px;
    }

    .points-panel {
        width: calc(100% - 32px);
        right: 16px;
        left: 16px;
        max-height: 60vh;
    }

    .modal-content {
        width: 95%;
        max-height: 90vh;
    }

    /* Prevent iOS zoom on input focus */
    .form-input,
    .form-textarea,
    .form-select {
        font-size: 16px;
    }

    /* Larger touch targets for mobile (Apple HIG: 44px minimum) */
    .btn { min-height: 44px; }
    .project-card { padding: 20px; }

    .photo-upload {
        padding: 40px 20px;
        font-size: 16px;
    }

    /* Mobile menu toggle button */
    .menu-toggle {
        position: fixed;
        top: 16px;
        left: 16px;
        z-index: 1600;
        background: var(--primary);
        color: white;
        border: none;
        width: 48px;
        height: 48px;
        border-radius: 50%;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 24px;
        box-shadow: 0 4px 12px var(--shadow);
        cursor: pointer;
    }
}

@media (min-width: 769px) {
    .menu-toggle { display: none; }
}

/* ==========================================================================
   Scrollbar: Custom styling for webkit browsers
   ========================================================================== */
::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }
