/* ==================== CSS VARIABLES ==================== */
:root {
    --bg-primary: rgba(255, 255, 255, 0.92);
    --bg-secondary: rgba(255, 255, 255, 0.98);
    --bg-header: rgba(0, 0, 0, 0.04);
    --bg-hover: rgba(0, 0, 0, 0.06);
    --bg-blur: blur(16px);
    
    --text-primary: #222;
    --text-secondary: #555;
    --text-muted: #888;
    --text-error: #d32f2f;
    --link: #0066cc;
    
    --border: rgba(0, 0, 0, 0.1);
    --border-light: rgba(0, 0, 0, 0.05);
    
    --radius: 12px;
    --radius-sm: 8px;
    --radius-lg: 16px;
    
    --shadow: 0 4px 24px rgba(0, 0, 0, 0.15);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.2);
    
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-left: env(safe-area-inset-left, 0px);
    --safe-right: env(safe-area-inset-right, 0px);
    
    --transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

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

html, body {
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    overflow: hidden;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    -webkit-font-smoothing: antialiased;
}

/* ==================== LAYOUT ==================== */
.map-wrapper {
    position: relative;
    width: 100%;
    height: 100%;
}

.map-container {
    position: absolute;
    inset: 0;
    z-index: 1;
}

/* ==================== TOP PANELS (Desktop) ==================== */
.top-panels {
    display: none;
}

.search-panel,
.seasons-panel,
.status-panel {
    pointer-events: auto;
}

.panel {
    background: var(--bg-primary);
    backdrop-filter: var(--bg-blur);
    -webkit-backdrop-filter: var(--bg-blur);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}

.panel-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    cursor: pointer;
    user-select: none;
    transition: var(--transition);
}

.panel-header:hover {
    background: var(--bg-hover);
}

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

.panel-count {
    font-size: 12px;
    color: var(--text-muted);
    background: var(--bg-header);
    padding: 2px 8px;
    border-radius: 10px;
}

.toggle-icon {
    font-size: 10px;
    color: var(--text-muted);
    transition: transform var(--transition);
}

.panel.expanded .toggle-icon {
    transform: rotate(180deg);
}

.panel-content {
    max-height: 0;
    overflow: hidden;
    transition: max-height var(--transition);
}

.panel.expanded .panel-content {
    max-height: 300px;
    overflow-y: auto;
}

/* Search Panel */
.search-panel {
    width: 280px;
}

.search-input {
    flex: 1;
    border: none;
    background: transparent;
    font-size: 14px;
    color: var(--text-primary);
    outline: none;
}

.search-input::placeholder {
    color: var(--text-muted);
}

.search-results {
    max-height: 200px;
    overflow-y: auto;
}

.search-result-item {
    padding: 10px 14px;
    font-size: 13px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 10px;
    transition: var(--transition);
}

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

.search-result-color {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    flex-shrink: 0;
}

.search-result-text {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.search-result-season {
    font-size: 11px;
    color: var(--text-muted);
}

.search-highlight {
    background: rgba(255, 200, 0, 0.4);
    padding: 1px 2px;
    border-radius: 2px;
}

.search-no-results {
    padding: 16px;
    text-align: center;
    color: var(--text-muted);
    font-size: 13px;
}

/* Seasons Panel */
.seasons-panel {
    width: 200px;
}

.seasons-controls {
    display: flex;
    gap: 8px;
    padding: 10px;
    position: sticky;
    top: 0;
    background: var(--bg-primary);
    border-bottom: 1px solid var(--border-light);
}

.seasons-btn {
    flex: 1;
    padding: 6px 10px;
    font-size: 12px;
    font-weight: 500;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: transparent;
    cursor: pointer;
    transition: var(--transition);
}

.seasons-btn:hover {
    background: var(--bg-hover);
}

.seasons-items {
    padding: 6px;
}

.season-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    font-size: 13px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: var(--transition);
}

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

.season-item.disabled {
    opacity: 0.35;
}

.season-color {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    flex-shrink: 0;
}

.season-text {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Status Panel */
.status-panel {
    width: 200px;
}

.status-content {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
}

.status-icon {
    font-size: 14px;
}

.status-text {
    font-size: 13px;
    color: var(--text-secondary);
}

.log-container {
    max-height: 150px;
    overflow-y: auto;
    border-top: 1px solid var(--border-light);
}

.log-item {
    padding: 6px 14px;
    font-size: 12px;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border-light);
}

.log-item.error {
    color: var(--text-error);
}

/* ==================== BOTTOM SHEET (Mobile) ==================== */
.bottom-sheet {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;

    height: 60vh;
    max-height: 80vh;

    background: #fff;
    border-radius: 0 0 16px 16px;
    box-shadow: 0 8px 25px rgba(0,0,0,0.25);

    display: flex;
    flex-direction: column;

    /* 👇 скрыто вверх, торчит только handle */
    transform: translateY(calc(-100% + 56px));
    transition: transform 0.3s ease;

    z-index: 9999;
}

/* состояние открыто */
.bottom-sheet.expanded {
    transform: translateY(0);
}


.bottom-sheet-handle {
    padding: 10px;
    cursor: grab;
    flex-shrink: 0;
}

.handle-bar {
    width: 36px;
    height: 4px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 2px;
    margin: 0 auto;
}

.bottom-sheet-tabs {
    display: flex;
    gap: 4px;
    padding: 0 10px 10px;
    flex-shrink: 0;
}

.sheet-tab {
    flex: 1;
    padding: 10px 6px;
    font-size: 13px;
    font-weight: 500;
    background: transparent;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    color: var(--text-muted);
    transition: var(--transition);
}

.sheet-tab.active {
    background: var(--bg-header);
    color: var(--text-primary);
}

.bottom-sheet-content {
    flex: 1;
    overflow: hidden;
    position: relative;
    min-height: 0;
}

.sheet-panel {
    position: absolute;
    inset: 0;
    overflow-y: auto;
    padding: 12px;
    display: none;
}

.sheet-panel.active {
    display: block;
}

.sheet-search-input {
    width: 100%;
    padding: 12px 14px;
    font-size: 15px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: #fff;
    outline: none;
    margin-bottom: 12px;
    color: var(--text-primary);
}

.sheet-search-input:focus {
    border-color: var(--link);
}

.sheet-search-results {
    overflow-y: auto;
}

.sheet-status-indicator {
    padding: 12px;
    font-size: 14px;
    color: var(--text-secondary);
    background: var(--bg-header);
    border-radius: var(--radius-sm);
    margin-bottom: 12px;
}

.sheet-panel .log-container {
    border: none;
    max-height: none;
}

/* ==================== LICENSE ==================== */
.license-container {
    position: fixed;
    bottom: calc(var(--safe-bottom) + 12px);
    right: calc(var(--safe-right) + 12px);
    z-index: 1001;
}

.license-toggle {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    background: var(--bg-primary);
    backdrop-filter: var(--bg-blur);
    -webkit-backdrop-filter: var(--bg-blur);
    box-shadow: var(--shadow);
    color: var(--text-secondary);
    font-size: 16px;
    cursor: pointer;
    transition: var(--transition);
}

.license-toggle:hover {
    transform: scale(1.05);
    color: var(--text-primary);
}

.license-expanded {
    position: absolute;
    bottom: calc(100% + 10px);
    right: 0;
    width: 280px;
    padding: 16px;
    background: var(--bg-secondary);
    backdrop-filter: var(--bg-blur);
    -webkit-backdrop-filter: var(--bg-blur);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    opacity: 0;
    visibility: hidden;
    transform: translateY(8px);
    transition: var(--transition);
    pointer-events: none;
}

.license-expanded.visible {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
    pointer-events: auto;
}

.license-title {
    font-weight: 600;
    font-size: 14px;
    margin-bottom: 10px;
}

.license-content {
    font-size: 12px;
    line-height: 1.5;
    color: var(--text-secondary);
}

.license-content a {
    color: var(--link);
    text-decoration: none;
}

.license-content a:hover {
    text-decoration: underline;
}

.license-section {
    margin-bottom: 8px;
}

.license-section:last-child {
    margin-bottom: 0;
}

/* ==================== LEAFLET ==================== */
.leaflet-control-zoom {
    border: none !important;
    box-shadow: var(--shadow) !important;
    background: var(--bg-primary) !important;
    backdrop-filter: var(--bg-blur) !important;
    -webkit-backdrop-filter: var(--bg-blur) !important;
    border-radius: var(--radius-sm) !important;
    overflow: hidden;
}

.leaflet-control-zoom a {
    width: 36px !important;
    height: 36px !important;
    line-height: 36px !important;
    font-size: 16px !important;
    color: var(--text-secondary) !important;
}

.leaflet-control-zoom a:hover {
    background: var(--bg-hover) !important;
    color: var(--text-primary) !important;
}

.leaflet-popup-content-wrapper {
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
}

.leaflet-popup-content {
    margin: 14px 16px;
    line-height: 1.5;
    font-size: 13px;
}

/* ==================== DESKTOP (>768px) ==================== */
@media (min-width: 769px) and (min-height: 501px) {
    .top-panels {
        display: flex;
        gap: 10px;
        position: fixed;
        top: calc(var(--safe-top) + 12px);
        left: calc(var(--safe-left) + 12px);
        z-index: 1000;
        pointer-events: none;
    }
    
    .bottom-sheet {
        display: none;
    }
    
    .license-container {
        bottom: calc(var(--safe-bottom) + 16px);
    }
    
    .license-toggle {
        width: 44px;
        height: 44px;
    }
}

/* ==================== LANDSCAPE MOBILE ==================== */
@media (max-height: 500px) and (orientation: landscape) {
    .top-panels {
        display: flex;
        gap: 8px;
        position: fixed;
        top: calc(var(--safe-top) + 6px);
        left: calc(var(--safe-left) + 6px);
        right: calc(var(--safe-right) + 60px);
        z-index: 1000;
        pointer-events: none;
    }
    
    .search-panel { width: 220px; }
    .seasons-panel { width: 160px; }
    .status-panel { width: 160px; }
    
    .bottom-sheet {
        display: none;
    }
    
    .panel-header { padding: 6px 10px; }
    .panel-title { font-size: 12px; }
    .panel.expanded .panel-content { max-height: 40vh; }
    
    .license-toggle {
        width: 36px;
        height: 36px;
    }
}

/* ==================== MOBILE (default) ==================== */
@media (max-width: 768px), (max-height: 500px) {
    .bottom-sheet {
        height: 60vh;
    }
    
    .license-container {
        bottom: 60px;
    }
}

/* ==================== SMALL SCREENS ==================== */
@media (max-width: 400px) {
    .sheet-tab {
        font-size: 12px;
        padding: 8px 4px;
    }
}

/* ==================== DARK MODE ==================== */
@media (prefers-color-scheme: dark) {
    :root {
        --bg-primary: rgba(28, 28, 30, 0.92);
        --bg-secondary: rgba(38, 38, 40, 0.98);
        --bg-header: rgba(255, 255, 255, 0.06);
        --bg-hover: rgba(255, 255, 255, 0.08);
        
        --text-primary: #fff;
        --text-secondary: #aaa;
        --text-muted: #777;
        
        --border: rgba(255, 255, 255, 0.12);
        --border-light: rgba(255, 255, 255, 0.06);
    }
    
    .handle-bar {
        background: rgba(255, 255, 255, 0.3);
    }
    
    .sheet-search-input {
        background: rgba(255, 255, 255, 0.1);
        border-color: var(--border);
        color: var(--text-primary);
    }
}
