/* =========================================
   NTM Viewer - NOAA Marine Chart Updates
   ========================================= */

:root {
    /* Color Palette - NOAA inspired */
    --primary: #0ea5e9;
    --primary-dark: #0284c7;
    --primary-light: #38bdf8;
    --accent: #06b6d4;

    /* Backgrounds */
    --bg-dark: #0f172a;
    --bg-panel: rgba(15, 23, 42, 0.95);
    --bg-card: rgba(30, 41, 59, 0.8);
    --bg-hover: rgba(51, 65, 85, 0.6);

    /* Text */
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;

    /* Borders */
    --border-color: rgba(148, 163, 184, 0.2);
    --border-glow: rgba(14, 165, 233, 0.4);

    /* Action Colors */
    --action-add: #22c55e;
    --action-change: #3b82f6;
    --action-delete: #ef4444;
    --action-relocate: #f97316;
    --action-revise: #a855f7;
    --action-revise-relocate: #ec4899;
    --action-substitute: #14b8a6;

    /* Sizing */
    --sidebar-width: 320px;
    --header-height: 80px;
}

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-dark);
    color: var(--text-primary);
    overflow: hidden;
}

/* =========================================
   Layout
   ========================================= */

.app-container {
    display: flex;
    height: 100vh;
    width: 100vw;
}

/* =========================================
   Sidebar
   ========================================= */

.sidebar {
    width: var(--sidebar-width);
    height: 100vh;
    background: var(--bg-panel);
    backdrop-filter: blur(20px);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    z-index: 100;
    transition: transform 0.3s ease;
}

.sidebar::-webkit-scrollbar {
    width: 6px;
}

.sidebar::-webkit-scrollbar-track {
    background: transparent;
}

.sidebar::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}

.sidebar-header {
    padding: 24px 20px;
    border-bottom: 1px solid var(--border-color);
    background: linear-gradient(135deg, rgba(14, 165, 233, 0.1), rgba(6, 182, 212, 0.05));
}

.sidebar-header h1 {
    font-size: 1.5rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--primary-light), var(--accent));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 4px;
}

.sidebar-header .subtitle {
    font-size: 0.8rem;
    color: var(--text-secondary);
    font-weight: 400;
}

/* =========================================
   Filter Sections
   ========================================= */

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

.section-title {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.section-title .icon {
    font-size: 1rem;
}

.section-title .select-all-btn {
    margin-left: auto;
    padding: 4px 10px;
    font-size: 0.65rem;
    background: var(--bg-hover);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s ease;
}

.section-title .select-all-btn:hover {
    background: var(--primary);
    color: var(--text-primary);
    border-color: var(--primary);
}

/* =========================================
   Basemap Toggle
   ========================================= */

.basemap-toggle {
    display: flex;
    gap: 8px;
}

.basemap-btn {
    flex: 1;
    padding: 10px 12px;
    font-size: 0.8rem;
    font-weight: 500;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s ease;
}

.basemap-btn:hover {
    background: var(--bg-hover);
    border-color: var(--primary);
}

.basemap-btn.active {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    border-color: var(--primary);
    color: white;
    box-shadow: 0 4px 12px rgba(14, 165, 233, 0.3);
}

/* =========================================
   Layer Toggles
   ========================================= */

.layer-toggles {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.toggle-item {
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
    padding: 8px 12px;
    background: var(--bg-card);
    border-radius: 8px;
    transition: background 0.2s ease;
}

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

.toggle-item input {
    display: none;
}

.toggle-slider {
    width: 40px;
    height: 22px;
    background: var(--bg-dark);
    border-radius: 11px;
    position: relative;
    transition: background 0.2s ease;
}

.toggle-slider::after {
    content: '';
    position: absolute;
    width: 18px;
    height: 18px;
    background: var(--text-muted);
    border-radius: 50%;
    top: 2px;
    left: 2px;
    transition: all 0.2s ease;
}

.toggle-item input:checked+.toggle-slider {
    background: var(--primary);
}

.toggle-item input:checked+.toggle-slider::after {
    transform: translateX(18px);
    background: white;
}

.toggle-label {
    font-size: 0.85rem;
    color: var(--text-primary);
}

/* =========================================
   Date Filter
   ========================================= */

.date-filter {
    display: flex;
    gap: 12px;
}

.date-input-group {
    flex: 1;
}

.date-input-group label {
    display: block;
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.date-input-group input {
    width: 100%;
    padding: 10px 12px;
    font-size: 0.8rem;
    font-family: 'Inter', sans-serif;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-primary);
    transition: all 0.2s ease;
}

.date-input-group input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--border-glow);
}

/* =========================================
   Checkbox List
   ========================================= */

.checkbox-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    max-height: 180px;
    overflow-y: auto;
    padding-right: 4px;
}

.checkbox-list::-webkit-scrollbar {
    width: 4px;
}

.checkbox-list::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 2px;
}

.checkbox-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    background: var(--bg-card);
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.2s ease;
}

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

.checkbox-item input {
    display: none;
}

.checkbox-marker {
    width: 18px;
    height: 18px;
    border-radius: 4px;
    background: var(--bg-dark);
    border: 2px solid var(--marker-color, var(--primary));
    position: relative;
    transition: all 0.2s ease;
}

.checkbox-marker::after {
    content: '✓';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0);
    color: white;
    font-size: 0.7rem;
    font-weight: bold;
    transition: transform 0.2s ease;
}

.checkbox-item input:checked+.checkbox-marker {
    background: var(--marker-color, var(--primary));
}

.checkbox-item input:checked+.checkbox-marker::after {
    transform: translate(-50%, -50%) scale(1);
}

.checkbox-item span:last-child {
    font-size: 0.8rem;
    color: var(--text-primary);
}

.loading-text {
    font-size: 0.8rem;
    color: var(--text-muted);
    font-style: italic;
    padding: 10px;
}

/* Style for codes not visible in current map extent */
.checkbox-item.not-in-view {
    opacity: 0.4;
    order: 1;
    /* Push to end of flex container */
}

.checkbox-item.not-in-view:hover {
    opacity: 0.7;
}

/* Make the checkbox list use flexbox for ordering */
.checkbox-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    max-height: 180px;
    overflow-y: auto;
    padding-right: 4px;
}

/* =========================================
   Apply / Reset Buttons
   ========================================= */

.apply-section {
    padding: 16px 20px;
    display: flex;
    gap: 10px;
    border-bottom: 1px solid var(--border-color);
}

.apply-btn {
    flex: 2;
    padding: 12px 20px;
    font-size: 0.85rem;
    font-weight: 600;
    font-family: 'Inter', sans-serif;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    border: none;
    border-radius: 8px;
    color: white;
    cursor: pointer;
    transition: all 0.2s ease;
}

.apply-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 20px rgba(14, 165, 233, 0.4);
}

.apply-btn:active {
    transform: translateY(0);
}

.reset-btn {
    flex: 1;
    padding: 12px 16px;
    font-size: 0.8rem;
    font-weight: 500;
    font-family: 'Inter', sans-serif;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s ease;
}

.reset-btn:hover {
    background: var(--bg-hover);
    border-color: var(--text-muted);
}

/* =========================================
   Feature Count
   ========================================= */

.feature-count {
    padding: 14px 20px;
    font-size: 0.75rem;
    color: var(--text-muted);
    text-align: center;
    background: var(--bg-card);
    margin-top: auto;
}

.feature-count span {
    font-weight: 600;
    color: var(--primary-light);
}

/* =========================================
   Sidebar Toggle
   ========================================= */

.sidebar-toggle {
    position: absolute;
    top: 16px;
    left: var(--sidebar-width);
    margin-left: 16px;
    width: 40px;
    height: 40px;
    background: var(--bg-panel);
    backdrop-filter: blur(20px);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 1.2rem;
    cursor: pointer;
    z-index: 101;
    display: none;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
}

.sidebar-toggle:hover {
    background: var(--bg-hover);
    border-color: var(--primary);
}

/* =========================================
   Map Container
   ========================================= */

.map-container {
    flex: 1;
    position: relative;
    height: 100vh;
}

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

/* =========================================
   Loading Overlay
   ========================================= */

.loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(15, 23, 42, 0.8);
    backdrop-filter: blur(4px);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 50;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.loading-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

.loading-spinner {
    width: 48px;
    height: 48px;
    border: 3px solid var(--border-color);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

.loading-overlay p {
    margin-top: 16px;
    font-size: 0.9rem;
    color: var(--text-secondary);
}

/* =========================================
   ArcGIS Popup Customization
   ========================================= */

.esri-popup__main-container {
    background: var(--bg-panel) !important;
    backdrop-filter: blur(20px) !important;
    border: 1px solid var(--border-color) !important;
    border-radius: 12px !important;
    color: var(--text-primary) !important;
}

.esri-popup__header-title {
    color: var(--primary-light) !important;
    font-weight: 600 !important;
}

.esri-popup__content {
    color: var(--text-primary) !important;
}

.esri-feature__fields {
    color: var(--text-primary) !important;
}

.esri-feature__field-header {
    color: var(--text-secondary) !important;
}

/* =========================================
   Responsive Design
   ========================================= */

@media (max-width: 768px) {
    .sidebar {
        position: absolute;
        left: 0;
        top: 0;
        transform: translateX(-100%);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .sidebar-toggle {
        display: flex;
        left: 16px;
    }

    .sidebar.open+.sidebar-toggle {
        left: var(--sidebar-width);
        margin-left: 16px;
    }
}