/* =========================================
   IPMA Explorer — Design System
   Dark theme with meteorological blue tones
   ========================================= */

/* --- CSS Variables --- */
:root {
    --bg-primary: #0a0e1a;
    --bg-secondary: #111827;
    --bg-tertiary: #1a2235;
    --bg-card: rgba(26, 34, 53, 0.85);
    --bg-glass: rgba(17, 24, 39, 0.7);
    --bg-hover: rgba(59, 130, 246, 0.08);
    
    --border-subtle: rgba(255, 255, 255, 0.06);
    --border-active: rgba(59, 130, 246, 0.4);
    
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    
    --accent: #3b82f6;
    --accent-hover: #60a5fa;
    --accent-dim: rgba(59, 130, 246, 0.15);
    
    --success: #22c55e;
    --warning: #f59e0b;
    --danger: #ef4444;
    
    --gradient-main: linear-gradient(135deg, #0a0e1a 0%, #111827 50%, #0f172a 100%);
    --gradient-accent: linear-gradient(135deg, #1e40af, #3b82f6);
    --gradient-warm: linear-gradient(135deg, #f59e0b, #ef4444);
    --gradient-cool: linear-gradient(135deg, #06b6d4, #3b82f6);
    
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.5);
    --shadow-glow: 0 0 20px rgba(59, 130, 246, 0.15);
    
    --sidebar-width: 280px;
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
    --transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

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

html, body {
    height: 100%;
    overflow: hidden;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--gradient-main);
    color: var(--text-primary);
    display: flex;
    -webkit-font-smoothing: antialiased;
}

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

/* --- Sidebar --- */
.sidebar {
    width: var(--sidebar-width);
    height: 100vh;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-subtle);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    z-index: 100;
    overflow-y: auto;
}

.sidebar-header {
    padding: 20px 18px 12px;
    border-bottom: 1px solid var(--border-subtle);
}

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

.logo-icon {
    width: 38px;
    height: 38px;
    background: var(--gradient-accent);
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-glow);
}

.logo-icon svg {
    width: 22px;
    height: 22px;
    color: white;
}

.logo-text h1 {
    font-size: 16px;
    font-weight: 700;
    letter-spacing: -0.3px;
    background: linear-gradient(135deg, #f1f5f9, #94a3b8);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.logo-subtitle {
    font-size: 11px;
    color: var(--text-muted);
    font-weight: 500;
}

/* --- Navigation --- */
.sidebar-nav {
    padding: 12px 10px;
    display: flex;
    flex-direction: column;
    gap: 2px;
    border-bottom: 1px solid var(--border-subtle);
}

.nav-btn {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-family: inherit;
    font-size: 13px;
    font-weight: 500;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: var(--transition);
}

.nav-btn svg {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

.nav-btn:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.nav-btn.active {
    background: var(--accent-dim);
    color: var(--accent);
}

.nav-btn.active svg {
    stroke: var(--accent);
}

/* --- Sidebar Sections --- */
.sidebar-section {
    padding: 16px 14px;
    border-bottom: 1px solid var(--border-subtle);
}

.sidebar-section.hidden {
    display: none;
}

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

/* --- Filter Controls --- */
.filter-group {
    margin-bottom: 14px;
}

.filter-group.inline {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-right: 12px;
}

.filter-group.inline label {
    font-size: 12px;
    color: var(--text-secondary);
}

.filter-label {
    display: block;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.filter-select,
.filter-input {
    width: 100%;
    padding: 8px 10px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 12px;
    outline: none;
    transition: var(--transition);
}

.filter-select:focus,
.filter-input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-dim);
}

.filter-input.small {
    width: 140px;
    padding: 6px 8px;
}

.filter-select option {
    background: var(--bg-secondary);
}

/* Range slider */
.filter-range {
    width: 100%;
    -webkit-appearance: none;
    height: 4px;
    background: var(--bg-tertiary);
    border-radius: 2px;
    outline: none;
    margin: 6px 0;
}

.filter-range::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--accent);
    cursor: pointer;
    box-shadow: 0 0 8px rgba(59, 130, 246, 0.4);
    transition: var(--transition);
}

.filter-range::-webkit-slider-thumb:hover {
    transform: scale(1.2);
}

.range-labels {
    display: flex;
    justify-content: space-between;
    font-size: 10px;
    color: var(--text-muted);
}

/* Region Toggles */
.region-toggles {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}

.region-btn {
    padding: 5px 10px;
    border: 1px solid var(--border-subtle);
    background: transparent;
    color: var(--text-secondary);
    font-family: inherit;
    font-size: 11px;
    font-weight: 500;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: var(--transition);
}

.region-btn:hover {
    border-color: var(--accent);
    color: var(--text-primary);
}

.region-btn.active {
    background: var(--accent-dim);
    border-color: var(--accent);
    color: var(--accent);
}

/* Search box */
.search-box {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    margin-bottom: 10px;
}

.search-box svg {
    width: 16px;
    height: 16px;
    color: var(--text-muted);
    flex-shrink: 0;
}

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

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

.search-result-item {
    padding: 6px 10px;
    font-size: 12px;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: var(--transition);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

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

.search-result-item .region-tag {
    font-size: 9px;
    padding: 2px 6px;
    border-radius: 10px;
    font-weight: 600;
}

.region-tag.Continental { background: rgba(34, 197, 94, 0.15); color: #22c55e; }
.region-tag.Madeira { background: rgba(245, 158, 11, 0.15); color: #f59e0b; }
.region-tag.Açores { background: rgba(59, 130, 246, 0.15); color: #3b82f6; }

.selected-stations {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-top: 8px;
}

.selected-station-chip {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 10px;
    border-radius: var(--radius-sm);
    font-size: 11px;
    font-weight: 500;
    animation: fadeIn 0.2s ease;
}

.selected-station-chip .remove-btn {
    background: none;
    border: none;
    color: inherit;
    cursor: pointer;
    padding: 2px;
    opacity: 0.6;
    font-size: 14px;
    line-height: 1;
}

.selected-station-chip .remove-btn:hover {
    opacity: 1;
}

/* Sidebar Footer */
.sidebar-footer {
    margin-top: auto;
    padding: 14px;
    border-top: 1px solid var(--border-subtle);
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.summary-badge {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    color: var(--text-secondary);
}

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

/* --- Main Content --- */
.main-content {
    flex: 1;
    height: 100vh;
    overflow: hidden;
    position: relative;
}

/* --- Loading Overlay --- */
.loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--bg-primary);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    transition: opacity 0.5s ease;
}

.loading-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.loading-spinner {
    position: relative;
    width: 60px;
    height: 60px;
}

.spinner-ring {
    position: absolute;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    border: 3px solid transparent;
}

.spinner-ring:nth-child(1) {
    border-top-color: var(--accent);
    animation: spin 1.2s linear infinite;
}

.spinner-ring:nth-child(2) {
    border-right-color: #06b6d4;
    animation: spin 1.6s linear infinite reverse;
    width: 80%;
    height: 80%;
    top: 10%;
    left: 10%;
}

.spinner-ring:nth-child(3) {
    border-bottom-color: #8b5cf6;
    animation: spin 2s linear infinite;
    width: 60%;
    height: 60%;
    top: 20%;
    left: 20%;
}

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

.loading-text {
    margin-top: 20px;
    font-size: 14px;
    color: var(--text-secondary);
    font-weight: 500;
}

/* --- View Panels --- */
.view-panel {
    display: none;
    width: 100%;
    height: 100%;
    overflow: auto;
}

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

/* --- Map View --- */
.map-container {
    width: 100%;
    height: 100%;
    position: relative;
}

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

/* Override Leaflet styles for dark theme */
.leaflet-container {
    background: #0a0e1a;
}

.leaflet-tile-pane {
    filter: brightness(0.7) contrast(1.1) saturate(0.8);
}

.leaflet-popup-content-wrapper {
    background: var(--bg-card);
    backdrop-filter: blur(12px);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    color: var(--text-primary);
}

.leaflet-popup-tip {
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
}

.leaflet-popup-content {
    margin: 14px 16px;
    font-family: 'Inter', sans-serif;
    font-size: 12px;
    line-height: 1.6;
}

.popup-title {
    font-size: 14px;
    font-weight: 700;
    margin-bottom: 8px;
    color: var(--accent-hover);
}

.popup-row {
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: baseline;
    gap: 12px;
    padding: 3px 0;
    white-space: nowrap;
}

.popup-label {
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.popup-value {
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.popup-region {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 10px;
    font-weight: 600;
    margin-bottom: 6px;
}

/* Layer switcher control (top-right of the map) */
.leaflet-control-layers {
    background: var(--bg-card) !important;
    border: 1px solid var(--border-subtle) !important;
    border-radius: var(--radius-sm) !important;
    box-shadow: var(--shadow-md) !important;
    color: var(--text-primary) !important;
    font-family: 'Inter', sans-serif !important;
    font-size: 12px !important;
    backdrop-filter: blur(12px);
}
.leaflet-control-layers-toggle {
    background-color: transparent !important;
}
.leaflet-control-layers-expanded {
    padding: 8px 10px !important;
    min-width: 110px;
}
.leaflet-control-layers-base label {
    display: flex;
    align-items: center;
    gap: 6px;
    margin: 3px 0;
    cursor: pointer;
    color: var(--text-primary);
}
.leaflet-control-layers-base label:hover {
    color: var(--accent-hover);
}
.leaflet-control-layers-separator {
    border-top: 1px solid var(--border-subtle) !important;
}

/* Hover tooltip on station markers — mirrors the click popup styling */
.leaflet-tooltip.station-tooltip {
    background: var(--bg-card);
    backdrop-filter: blur(12px);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    color: var(--text-primary);
    font-family: 'Inter', sans-serif;
    font-size: 12px;
    line-height: 1.55;
    padding: 12px 14px;
    min-width: 240px;
    max-width: 360px;
    white-space: normal;
    pointer-events: none;
}

.leaflet-tooltip.station-tooltip::before {
    border-top-color: var(--bg-card);
}

/* Map Legend */
.map-legend {
    position: absolute;
    bottom: 30px;
    left: 20px;
    background: var(--bg-glass);
    backdrop-filter: blur(12px);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    padding: 14px 16px;
    z-index: 800;
    min-width: 180px;
}

.legend-title {
    font-size: 11px;
    font-weight: 700;
    color: var(--text-secondary);
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.legend-gradient {
    height: 12px;
    border-radius: 6px;
    margin-bottom: 4px;
}

.legend-labels {
    display: flex;
    justify-content: space-between;
    font-size: 10px;
    color: var(--text-muted);
}

/* On light/satellite/terrain basemaps the dark glass card is harder to read,
   so we flip the legend (and the layer switcher) to a light card with dark
   text. Triggered by the `.map-light-theme` class set by map.js. */
#leaflet-map.map-light-theme ~ .map-legend {
    background: rgba(255, 255, 255, 0.92);
    border-color: rgba(15, 23, 42, 0.15);
    color: #0f172a;
}
#leaflet-map.map-light-theme ~ .map-legend .legend-title {
    color: rgba(15, 23, 42, 0.75);
}
#leaflet-map.map-light-theme ~ .map-legend .legend-labels {
    color: rgba(15, 23, 42, 0.6);
}
#leaflet-map.map-light-theme .leaflet-control-layers {
    background: rgba(255, 255, 255, 0.95) !important;
    border-color: rgba(15, 23, 42, 0.15) !important;
    color: #0f172a !important;
}
#leaflet-map.map-light-theme .leaflet-control-layers-base label {
    color: #0f172a;
}
#leaflet-map.map-light-theme .leaflet-control-layers-base label:hover {
    color: var(--accent);
}

/* Map station markers */
.station-marker {
    border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, 0.3);
    transition: transform 0.15s ease, box-shadow 0.15s ease;
    cursor: pointer;
}

.station-marker:hover {
    transform: scale(1.4);
    box-shadow: 0 0 12px rgba(255, 255, 255, 0.3);
    z-index: 900 !important;
}

/* --- Charts View --- */
.charts-header {
    padding: 24px 30px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
}

.charts-header h2 {
    font-size: 22px;
    font-weight: 700;
    background: linear-gradient(135deg, #f1f5f9, #94a3b8);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.charts-controls {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.btn-primary {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    background: var(--gradient-accent);
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
}

.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-glow);
}

.chart-wrapper {
    position: relative;
    height: calc(100vh - 200px);
    padding: 0 30px 30px;
    display: none;
}

.chart-wrapper.visible {
    display: block;
}

.chart-empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: calc(100vh - 200px);
    color: var(--text-muted);
    text-align: center;
    gap: 16px;
}

.chart-empty-state h3 {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-secondary);
}

.chart-empty-state p {
    font-size: 13px;
    max-width: 320px;
}

.chart-empty-state.hidden {
    display: none;
}

/* --- Stats View --- */
.stats-header {
    padding: 24px 30px 8px;
}

.stats-header h2 {
    font-size: 22px;
    font-weight: 700;
    background: linear-gradient(135deg, #f1f5f9, #94a3b8);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.stats-period {
    font-size: 13px;
    color: var(--text-muted);
    margin-top: 4px;
}

.stats-cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 16px;
    padding: 20px 30px;
}

.stat-card {
    background: var(--bg-card);
    backdrop-filter: blur(8px);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    padding: 20px;
    transition: var(--transition);
    position: relative;
    overflow: hidden;
}

.stat-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}

.stat-card.blue::before { background: var(--gradient-cool); }
.stat-card.warm::before { background: var(--gradient-warm); }
.stat-card.green::before { background: linear-gradient(135deg, #22c55e, #10b981); }
.stat-card.purple::before { background: linear-gradient(135deg, #8b5cf6, #a78bfa); }

.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
    border-color: var(--border-active);
}

.stat-card-icon {
    font-size: 24px;
    margin-bottom: 10px;
}

.stat-card-value {
    font-size: 28px;
    font-weight: 800;
    letter-spacing: -1px;
    line-height: 1;
    margin-bottom: 4px;
}

.stat-card-label {
    font-size: 11px;
    color: var(--text-secondary);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.stat-card-detail {
    margin-top: 8px;
    font-size: 11px;
    color: var(--text-muted);
}

/* Stats tables */
.stats-tables {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(420px, 1fr));
    gap: 20px;
    padding: 10px 30px 30px;
}

.stats-table-container {
    background: var(--bg-card);
    backdrop-filter: blur(8px);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    padding: 20px;
    overflow: hidden;
}

.stats-table-container h3 {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 12px;
    color: var(--text-primary);
}

.stats-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
}

.stats-table th {
    text-align: left;
    padding: 8px 10px;
    font-weight: 600;
    color: var(--text-muted);
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 1px solid var(--border-subtle);
}

.stats-table td {
    padding: 8px 10px;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border-subtle);
}

.stats-table tr:last-child td {
    border-bottom: none;
}

.stats-table tr:hover td {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.stats-table td:last-child {
    font-weight: 700;
    color: var(--accent-hover);
    text-align: right;
}

/* --- Calendar View --- */
.calendar-header {
    padding: 24px 30px 8px;
}

.calendar-header h2 {
    font-size: 22px;
    font-weight: 700;
    background: linear-gradient(135deg, #f1f5f9, #94a3b8);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.calendar-description {
    font-size: 13px;
    color: var(--text-muted);
    margin-top: 4px;
}

.calendar-grid-container {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 24px;
    padding: 20px 30px;
}

.calendar-month {
    background: var(--bg-card);
    backdrop-filter: blur(8px);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    padding: 20px;
}

.calendar-month-title {
    font-size: 16px;
    font-weight: 700;
    text-align: center;
    margin-bottom: 14px;
    color: var(--text-primary);
}

.calendar-weekdays {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 4px;
    margin-bottom: 4px;
}

.calendar-weekday {
    text-align: center;
    font-size: 10px;
    font-weight: 700;
    color: var(--text-muted);
    padding: 4px;
    text-transform: uppercase;
}

.calendar-days {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 4px;
}

.calendar-day {
    aspect-ratio: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 600;
    border-radius: var(--radius-sm);
    transition: var(--transition);
    cursor: default;
    position: relative;
}

.calendar-day.empty {
    /* empty cell */
}

.calendar-day.ok {
    background: rgba(34, 197, 94, 0.15);
    color: #22c55e;
    cursor: pointer;
}

.calendar-day.ok:hover {
    background: rgba(34, 197, 94, 0.3);
    transform: scale(1.1);
}

.calendar-day.failed {
    background: rgba(239, 68, 68, 0.15);
    color: #ef4444;
}

/* Day present in the monitored period but with no CSV collected (incomplete).
   Amber to match the "Sem dados" legend dot, distinct from a hard failure. */
.calendar-day.incomplete {
    background: rgba(245, 158, 11, 0.15);
    color: #f59e0b;
}

.calendar-day.nodata {
    color: var(--text-muted);
    opacity: 0.3;
}

.calendar-day .day-tooltip {
    display: none;
    position: absolute;
    bottom: calc(100% + 6px);
    left: 50%;
    transform: translateX(-50%);
    background: var(--bg-tertiary);
    border: 1px solid var(--border-subtle);
    padding: 6px 10px;
    border-radius: var(--radius-sm);
    font-size: 10px;
    white-space: nowrap;
    color: var(--text-secondary);
    z-index: 100;
    pointer-events: none;
}

.calendar-day:hover .day-tooltip {
    display: block;
}

.calendar-legend-bar {
    display: flex;
    gap: 24px;
    justify-content: center;
    padding: 10px 30px 30px;
}

.cal-legend-item {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--text-secondary);
}

.cal-dot {
    width: 10px;
    height: 10px;
    border-radius: 3px;
}

.cal-dot.ok { background: rgba(34, 197, 94, 0.4); }
.cal-dot.failed { background: rgba(239, 68, 68, 0.4); }
.cal-dot.empty { background: rgba(245, 158, 11, 0.4); }
.cal-dot.nodata { background: rgba(100, 116, 139, 0.2); }

/* --- Animations --- */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

.animate-in {
    animation: fadeIn 0.3s ease forwards;
}

/* --- Responsive --- */
@media (max-width: 1024px) {
    .calendar-grid-container {
        grid-template-columns: 1fr;
    }
    
    .stats-tables {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        left: -280px;
        transition: left 0.3s ease;
    }
    
    .sidebar.open {
        left: 0;
    }
    
    .stats-cards {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* Chart.js dark theme overrides */
.chart-wrapper canvas {
    border-radius: var(--radius-md);
}

/* Hour chips (replaces the hour slider) */
.hour-chips {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 4px;
    margin-top: 6px;
}

.hour-chip {
    padding: 6px 0;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 11px;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    text-align: center;
}

.hour-chip:hover {
    background: var(--bg-hover);
    border-color: var(--border-active);
}

.hour-chip.active {
    background: var(--gradient-accent);
    border-color: var(--accent);
    color: white;
}

.hour-empty {
    grid-column: 1 / -1;
    padding: 16px;
    text-align: center;
    font-size: 12px;
    color: var(--text-muted);
    background: var(--bg-tertiary);
    border-radius: var(--radius-sm);
}

/* =========================================
   "Como usar?" tutorial view
   ========================================= */

#view-howto {
    overflow-y: auto;
    height: 100vh;
    padding: 32px 40px 60px;
}

.howto {
    max-width: 880px;
    margin: 0 auto;
    color: var(--text-primary);
    line-height: 1.7;
    counter-reset: howto-section;
}

/* Auto-number visible sections only — skips `.admin-only` when not unlocked
   so the visitor sees a continuous 1..N sequence. */
.howto-section { counter-increment: howto-section; }
body:not(.admin-unlocked) .howto-section.admin-only { counter-increment: none; }
.howto-num::before { content: counter(howto-section); }

.howto-header {
    border-bottom: 1px solid var(--border-subtle);
    padding-bottom: 18px;
    margin-bottom: 28px;
}

.howto-header h1 {
    font-size: 26px;
    font-weight: 800;
    margin-bottom: 6px;
    background: var(--gradient-accent);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}

.howto-header p {
    color: var(--text-secondary);
    font-size: 14px;
}

.howto-section {
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    padding: 22px 26px;
    margin-bottom: 18px;
    box-shadow: var(--shadow-sm);
}

.howto-section h2 {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 17px;
    font-weight: 700;
    margin-bottom: 12px;
    color: var(--text-primary);
}

.howto-num {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--gradient-accent);
    color: white;
    font-size: 12px;
    font-weight: 700;
    flex-shrink: 0;
}

.howto-section p {
    font-size: 13.5px;
    color: var(--text-primary);
    margin-bottom: 10px;
}

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

.howto-section em {
    color: var(--accent-hover);
    font-style: normal;
    font-weight: 500;
}

.howto-section strong {
    color: var(--text-primary);
}

.howto-bullets,
.howto-steps {
    margin: 8px 0 12px 22px;
    color: var(--text-primary);
    font-size: 13.5px;
}

.howto-bullets li,
.howto-steps li {
    margin-bottom: 6px;
    line-height: 1.6;
}

.howto-bullets.legend-inline {
    list-style: none;
    margin-left: 0;
}

.howto-bullets.legend-inline li {
    display: flex;
    align-items: center;
    gap: 10px;
}

.howto-tip {
    margin: 14px 0;
    padding: 12px 14px;
    background: rgba(59, 130, 246, 0.08);
    border-left: 3px solid var(--accent);
    border-radius: var(--radius-sm);
    font-size: 13px;
    color: var(--text-secondary);
}

.howto-tip strong {
    color: var(--accent-hover);
}

.howto-tip.warn {
    background: rgba(245, 158, 11, 0.08);
    border-left-color: var(--warning);
}

.howto-tip.warn strong {
    color: var(--warning);
}

.howto-cta {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-top: 12px;
    padding: 8px 14px;
    background: var(--gradient-accent);
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
}

.howto-cta:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-glow);
}

.howto-table {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 8px;
}

.howto-table-row {
    display: grid;
    grid-template-columns: 100px 1fr;
    gap: 16px;
    align-items: baseline;
    padding: 10px 12px;
    background: var(--bg-tertiary);
    border-radius: var(--radius-sm);
    font-size: 13px;
}

.howto-table-row strong {
    color: var(--accent-hover);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.howto kbd {
    display: inline-block;
    padding: 1px 6px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-subtle);
    border-bottom-width: 2px;
    border-radius: 3px;
    font-family: ui-monospace, "JetBrains Mono", monospace;
    font-size: 11px;
    color: var(--text-primary);
}

.howto code {
    padding: 1px 6px;
    background: var(--bg-tertiary);
    border-radius: 3px;
    font-family: ui-monospace, "JetBrains Mono", monospace;
    font-size: 12px;
    color: var(--accent-hover);
}

/* Calendar legend dots reused inline in the howto */
.howto .cal-dot {
    display: inline-block;
    width: 12px;
    height: 12px;
    border-radius: 3px;
    flex-shrink: 0;
}

.howto .cal-dot.ok { background: var(--success); }
.howto .cal-dot.failed { background: var(--danger); }
.howto .cal-dot.empty { background: var(--warning); }
.howto .cal-dot.nodata { background: var(--bg-tertiary); border: 1px solid var(--border-subtle); }

/* =========================================
   Recolha Panel — Cloudflare Worker control
   ========================================= */

#view-recolha {
    padding: 28px 32px 60px;
    overflow-y: auto;
    height: 100vh;
}

/* Admin-only elements (Recolha nav button + howto section).
   Hidden by default in CSS to avoid a flash of visible content before JS
   runs. Revealed when `body.admin-unlocked` is set by recolha.js after a
   successful password entry. */
body:not(.admin-unlocked) .admin-only { display: none !important; }

/* Admin password modal — centered overlay over the whole page */
.admin-modal {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9000;
}
.admin-modal.hidden { display: none; }

.admin-modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(10, 14, 26, 0.7);
    backdrop-filter: blur(6px);
}

.admin-modal-card {
    position: relative;
    width: calc(100% - 40px);
    max-width: 380px;
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    padding: 30px 28px 26px;
    text-align: center;
    box-shadow: var(--shadow-lg);
    backdrop-filter: blur(14px);
    animation: modal-pop 0.18s ease-out;
}

@keyframes modal-pop {
    from { transform: scale(0.96); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

.admin-modal-close {
    position: absolute;
    top: 8px;
    right: 12px;
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 22px;
    cursor: pointer;
    line-height: 1;
    padding: 4px 8px;
}
.admin-modal-close:hover {
    color: var(--text-primary);
}

.recolha-lock-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 64px;
    height: 64px;
    margin-bottom: 14px;
    background: var(--accent-dim);
    border-radius: 50%;
    color: var(--accent-hover);
}

.admin-modal-card h2 {
    font-size: 18px;
    font-weight: 700;
    margin-bottom: 8px;
}

.admin-modal-card p {
    color: var(--text-secondary);
    font-size: 13px;
    margin-bottom: 18px;
}

.admin-modal-card form {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.admin-modal-card input[type="password"] {
    width: 100%;
    padding: 10px 12px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 14px;
    text-align: center;
    letter-spacing: 0.1em;
}

.admin-modal-card input[type="password"]:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-dim);
}

.admin-modal-card .btn-primary {
    justify-content: center;
    padding: 10px 16px;
    font-size: 13px;
}

.recolha-pwd-error {
    margin-top: 12px;
    color: var(--danger);
    font-size: 12px;
    font-weight: 500;
}
.recolha-pwd-error.hidden { display: none; }

@keyframes shake-card {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-8px); }
    75% { transform: translateX(8px); }
}
.admin-modal-card.shake {
    animation: shake-card 0.35s cubic-bezier(0.36, 0.07, 0.19, 0.97);
}

.recolha-lock-btn {
    display: inline-block;
    margin-left: 8px;
    padding: 2px 8px;
    background: transparent;
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-family: inherit;
    font-size: 11px;
    cursor: pointer;
    transition: var(--transition);
}
.recolha-lock-btn:hover {
    color: var(--danger);
    border-color: var(--danger);
}

.recolha-header h2 {
    font-size: 22px;
    font-weight: 700;
    margin-bottom: 6px;
}

.recolha-header p {
    color: var(--text-secondary);
    font-size: 13px;
    margin-bottom: 20px;
}

.recolha-flash {
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    margin-bottom: 16px;
    border: 1px solid var(--border-subtle);
}
.recolha-flash.ok { background: rgba(34, 197, 94, 0.10); border-color: rgba(34, 197, 94, 0.35); color: #86efac; }
.recolha-flash.error { background: rgba(239, 68, 68, 0.10); border-color: rgba(239, 68, 68, 0.35); color: #fca5a5; }
.recolha-flash.hidden { display: none; }

.recolha-empty-state {
    padding: 40px;
    text-align: center;
    color: var(--text-secondary);
    background: var(--bg-card);
    border-radius: var(--radius-md);
    border: 1px dashed var(--border-subtle);
    margin-bottom: 16px;
}
.recolha-empty-state.hidden { display: none; }

.recolha-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
    gap: 16px;
    margin-bottom: 16px;
}

.recolha-card {
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    padding: 18px 20px;
    box-shadow: var(--shadow-sm);
}

.recolha-card-full {
    margin-bottom: 16px;
}

.recolha-card h3 {
    font-size: 13px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-secondary);
    margin-bottom: 14px;
}

.recolha-kv {
    display: grid;
    grid-template-columns: max-content 1fr;
    gap: 8px 16px;
    font-size: 13px;
}
.recolha-k { color: var(--text-secondary); }
.recolha-v { color: var(--text-primary); font-weight: 500; }

.recolha-error {
    margin-top: 12px;
    padding: 10px 12px;
    background: rgba(239, 68, 68, 0.10);
    border: 1px solid rgba(239, 68, 68, 0.30);
    border-radius: var(--radius-sm);
    color: #fca5a5;
    font-family: ui-monospace, "JetBrains Mono", monospace;
    font-size: 12px;
    white-space: pre-wrap;
    word-break: break-word;
}
.recolha-error.hidden { display: none; }

.recolha-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 600;
}
.badge-ok      { background: rgba(34, 197, 94, 0.15); color: #86efac; }
.badge-error   { background: rgba(239, 68, 68, 0.15); color: #fca5a5; }
.badge-skipped { background: rgba(148, 163, 184, 0.15); color: #cbd5e1; }

.recolha-controls {
    display: flex;
    flex-direction: column;
    gap: 12px;
    align-items: flex-start;
}

.btn-secondary {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
}
.btn-secondary:hover { background: var(--bg-hover); border-color: var(--border-active); }

.btn-primary:disabled, .btn-secondary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.recolha-switch {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    user-select: none;
}
.recolha-switch input { display: none; }
.recolha-slider {
    position: relative;
    width: 40px;
    height: 22px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-subtle);
    border-radius: 999px;
    transition: var(--transition);
}
.recolha-slider::before {
    content: "";
    position: absolute;
    top: 2px;
    left: 2px;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--text-secondary);
    transition: var(--transition);
}
.recolha-switch input:checked + .recolha-slider {
    background: var(--accent-dim);
    border-color: var(--border-active);
}
.recolha-switch input:checked + .recolha-slider::before {
    transform: translateX(18px);
    background: var(--accent);
}
.recolha-switch-label {
    font-size: 13px;
    color: var(--text-primary);
}

.recolha-hint {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 12px;
}

.recolha-table-wrapper {
    overflow-x: auto;
    max-height: 360px;
    overflow-y: auto;
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
}
.recolha-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
}
.recolha-table th {
    position: sticky;
    top: 0;
    background: var(--bg-tertiary);
    text-align: left;
    padding: 10px 12px;
    font-weight: 600;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border-subtle);
}
.recolha-table td {
    padding: 8px 12px;
    border-bottom: 1px solid var(--border-subtle);
    color: var(--text-primary);
}
.recolha-table tr:hover td { background: var(--bg-hover); }
.recolha-empty {
    text-align: center;
    color: var(--text-muted);
    padding: 20px;
}
.recolha-cell-error {
    color: #fca5a5;
    font-family: ui-monospace, "JetBrains Mono", monospace;
    font-size: 11px;
    max-width: 320px;
    word-break: break-word;
}

.recolha-form {
    display: flex;
    flex-direction: column;
    gap: 14px;
    max-width: 520px;
}
.recolha-field {
    display: flex;
    flex-direction: column;
    gap: 6px;
    font-size: 12px;
    color: var(--text-secondary);
    border: none;
}
.recolha-field input[type="url"],
.recolha-field input[type="password"] {
    padding: 9px 12px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 13px;
}
.recolha-field input:focus {
    outline: none;
    border-color: var(--border-active);
}
.recolha-field legend {
    margin-bottom: 6px;
}
.recolha-field label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: var(--text-primary);
    cursor: pointer;
    margin-top: 4px;
}

