/* --- Reset & Variables --- */
:root {
    --primary: #0066CC;
    --primary-dark: #004999;
    --green: #22C55E;
    --green-bg: #F0FDF4;
    --orange: #F59E0B;
    --orange-bg: #FFFBEB;
    --red: #EF4444;
    --red-bg: #FEF2F2;
    --bg: #F8FAFC;
    --surface: #FFFFFF;
    --text: #1E293B;
    --text-secondary: #64748B;
    --border: #E2E8F0;
    --shadow: 0 1px 3px rgba(0,0,0,0.1);
    --shadow-lg: 0 -4px 20px rgba(0,0,0,0.12);
    --radius: 12px;
    --radius-sm: 8px;
    --top-bar: 52px;
    --filters-bar: 48px;
    --day-bar: 86px;
    --tab-bar: 60px;
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

html, body {
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    font-size: 15px;
    color: var(--text);
    background: var(--bg);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    overflow: hidden;
    touch-action: manipulation;
}

/* --- Top Bar --- */
#top-bar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--top-bar);
    padding-top: env(safe-area-inset-top, 0px);
    background: var(--primary);
    color: white;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-left: 16px;
    padding-right: 8px;
    z-index: 100;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}

#top-bar h1 {
    font-size: 17px;
    font-weight: 600;
    letter-spacing: -0.2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

#back-btn, #search-btn {
    background: none;
    border: none;
    color: white;
    font-size: 20px;
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    border-radius: 50%;
    -webkit-tap-highlight-color: transparent;
}

#back-btn:active, #search-btn:active {
    background: rgba(255,255,255,0.15);
}

.hidden { display: none !important; }

/* --- Header Actions --- */
.header-actions {
    display: flex;
    align-items: center;
    gap: 4px;
}

.lang-select {
    background: rgba(255,255,255,0.2);
    border: 1px solid rgba(255,255,255,0.3);
    color: white;
    border-radius: 4px;
    padding: 4px 6px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    -webkit-appearance: none;
}

.lang-select option { color: #333; background: white; }

/* --- Filters Bar --- */
#filters-bar {
    position: fixed;
    top: var(--top-bar);
    left: 0;
    right: 0;
    height: var(--filters-bar);
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    z-index: 95;
    display: flex;
    align-items: center;
    padding: 0 8px;
}

.filters-row {
    display: flex;
    gap: 6px;
    width: 100%;
    align-items: center;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.filter-select {
    height: 44px;
    border: 1.5px solid var(--border);
    border-radius: 15px;
    padding: 0 10px;
    font-size: 12px;
    font-weight: 500;
    background: var(--surface);
    color: var(--text);
    cursor: pointer;
    -webkit-appearance: none;
    white-space: nowrap;
}

.filter-select:focus { border-color: var(--primary); }

.filter-checkbox {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 14px;
    cursor: pointer;
    padding: 0 6px;
    height: 30px;
    border: 1.5px solid var(--border);
    border-radius: 15px;
    white-space: nowrap;
}

.filter-checkbox input { margin: 0; }

.filter-btn {
    width: 44px;
    height: 44px;
    border: 1.5px solid var(--border);
    border-radius: 50%;
    background: var(--surface);
    font-size: 14px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    -webkit-tap-highlight-color: transparent;
}

.filter-btn.active {
    background: var(--primary);
    border-color: var(--primary);
    color: white;
}

.filter-btn:active { transform: scale(0.9); }

/* --- Content Area --- */
#content {
    position: fixed;
    top: calc(var(--top-bar) + var(--filters-bar));
    left: 0;
    right: 0;
    bottom: calc(var(--day-bar) + var(--tab-bar) + var(--safe-bottom));
    overflow: hidden;
}

.view {
    width: 100%;
    height: 100%;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

/* --- Map --- */
#map-container {
    width: 100%;
    height: 100%;
}

/* --- Day + Slot Selector --- */
#day-selector {
    position: fixed;
    bottom: calc(var(--tab-bar) + var(--safe-bottom));
    left: 0;
    right: 0;
    height: var(--day-bar);
    background: var(--surface);
    border-top: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 4px 16px;
    z-index: 90;
}

.day-row, .slot-row {
    display: flex;
    gap: 6px;
    width: 100%;
    justify-content: center;
}

.slot-btn {
    flex: 1;
    max-width: 140px;
    height: 36px;
    border: 1.5px solid var(--primary);
    border-radius: 14px;
    background: transparent;
    color: var(--primary);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    transition: all 0.2s ease;
}

.slot-btn.selected {
    background: var(--primary);
    color: white;
}

.day-pill {
    flex: 1;
    max-width: 90px;
    height: 38px;
    border: 2px solid var(--primary);
    border-radius: 20px;
    background: transparent;
    color: var(--primary);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    transition: all 0.2s ease;
}

.day-pill.selected {
    background: var(--primary);
    color: white;
}

.day-pill:active {
    transform: scale(0.95);
}

/* --- Tab Bar --- */
#tab-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: calc(var(--tab-bar) + var(--safe-bottom));
    padding-bottom: var(--safe-bottom);
    background: var(--surface);
    border-top: 1px solid var(--border);
    display: flex;
    z-index: 90;
}

.tab {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    border: none;
    background: none;
    color: var(--text-secondary);
    font-size: 11px;
    font-weight: 500;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    transition: color 0.2s;
}

.tab.active {
    color: var(--primary);
}

.tab-icon {
    font-size: 22px;
    line-height: 1;
}

.tab:active {
    background: rgba(0,0,0,0.03);
}

/* --- List View --- */
#list-container {
    background: var(--bg);
    padding: 0 0 8px;
}

.list-summary {
    padding: 12px 16px 8px;
    font-size: 13px;
    color: var(--text-secondary);
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

.summary-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    display: inline-block;
    margin-right: 4px;
    vertical-align: middle;
}

.beach-card {
    margin: 6px 12px;
    padding: 14px 16px;
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    transition: transform 0.15s ease;
    border-left: 4px solid var(--border);
}

.beach-card:active {
    transform: scale(0.98);
}

.beach-card .condition-dot {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    flex-shrink: 0;
}

.beach-card .card-info {
    flex: 1;
    min-width: 0;
}

.beach-card .card-name {
    font-size: 15px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.beach-card .card-meta {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 2px;
    display: flex;
    gap: 12px;
}

/* Score circles */
.score-circle {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    color: white;
    font-size: 13px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.score-circle-sm {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    color: white;
    font-size: 11px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.beach-card .condition-badge {
    font-size: 12px;
    font-weight: 600;
    padding: 3px 10px;
    border-radius: 12px;
    flex-shrink: 0;
    text-align: center;
}

/* --- Detail View --- */
#detail-container {
    background: var(--bg);
    padding: 16px;
}

.detail-header {
    margin-bottom: 20px;
}

.detail-name {
    font-size: 22px;
    font-weight: 700;
    margin-bottom: 4px;
}

.detail-description {
    font-size: 14px;
    color: var(--text-secondary);
    margin: 4px 0 12px;
    line-height: 1.4;
}

.detail-actions-row {
    display: flex;
    gap: 8px;
    margin-top: 8px;
    flex-wrap: wrap;
}

.detail-action-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 8px 14px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
    -webkit-tap-highlight-color: transparent;
}

.detail-action-btn:active { background: var(--bg); }
.detail-action-btn.active { background: var(--primary); color: white; border-color: var(--primary); }

.directions-btn { background: #E8F5E9; border-color: #22C55E; color: #166534; }
.share-btn { background: #EFF6FF; border-color: var(--primary); color: var(--primary); }
.webcam-btn { background: #FFF3E0; border-color: #F59E0B; color: #92400E; }
.notify-btn { background: #F5F5F5; }

.detail-bottom-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
}

/* Services grid */
.detail-section {
    margin-top: 16px;
}

.detail-section h3 {
    font-size: 15px;
    font-weight: 600;
    margin-bottom: 10px;
}

.services-grid {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

.service-item {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 12px;
    background: var(--surface);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    font-size: 13px;
}

.service-icon { font-size: 16px; }

/* Favorites star */
.fav-star { color: #F59E0B; font-size: 14px; }

.card-services {
    display: flex;
    gap: 6px;
    margin-top: 2px;
    font-size: 11px;
    opacity: 0.7;
}

.card-distance {
    color: var(--primary);
    font-weight: 600;
}

/* Compare */
.compare-empty {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-secondary);
}

.compare-header {
    padding: 0 0 12px;
}

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

.compare-table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.compare-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.compare-table th, .compare-table td {
    padding: 10px 12px;
    text-align: center;
    border-bottom: 1px solid var(--border);
}

.compare-table th {
    background: var(--primary);
    color: white;
    font-weight: 600;
    font-size: 12px;
    white-space: nowrap;
}

.compare-label {
    text-align: left !important;
    color: var(--text-secondary);
    font-weight: 500;
    white-space: nowrap;
}

.detail-link {
    font-size: 14px;
    color: var(--primary);
    background: none;
    border: none;
    cursor: pointer;
    padding: 0;
    font-weight: 500;
}

.forecast-strip {
    display: flex;
    gap: 8px;
    margin-bottom: 20px;
}

.forecast-day {
    flex: 1;
    background: var(--surface);
    border-radius: var(--radius);
    padding: 12px 8px;
    text-align: center;
    box-shadow: var(--shadow);
    cursor: pointer;
    border: 2px solid transparent;
    transition: border-color 0.2s;
}

.forecast-day.selected {
    border-color: var(--primary);
}

.forecast-day .day-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.forecast-day .day-dot {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    margin: 0 auto 6px;
}

.forecast-day .day-condition {
    font-size: 11px;
    font-weight: 600;
}

.detail-data {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 16px;
    box-shadow: var(--shadow);
}

.detail-row {
    display: flex;
    justify-content: space-between;
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
    font-size: 14px;
}

.detail-row:last-child {
    border-bottom: none;
}

.detail-row .label {
    color: var(--text-secondary);
}

.detail-row .value {
    font-weight: 600;
}

/* --- Bottom Sheet --- */
#bottom-sheet {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--surface);
    border-radius: 16px 16px 0 0;
    box-shadow: var(--shadow-lg);
    padding: 12px 20px calc(var(--day-bar) + var(--tab-bar) + var(--safe-bottom) + 16px) 20px;
    transform: translateY(110%);
    transition: transform 0.3s cubic-bezier(0.32, 0.72, 0, 1);
    z-index: 200;
    pointer-events: none;
}

#bottom-sheet.visible {
    transform: translateY(0);
    pointer-events: auto;
}

.sheet-handle {
    width: 36px;
    height: 4px;
    border-radius: 2px;
    background: #CBD5E1;
    margin: 0 auto 12px;
}

.sheet-name {
    font-size: 18px;
    font-weight: 700;
    margin-bottom: 8px;
}

.sheet-condition {
    display: inline-block;
    font-size: 13px;
    font-weight: 600;
    padding: 4px 12px;
    border-radius: 12px;
    margin-bottom: 10px;
}

.sheet-stats {
    display: flex;
    gap: 20px;
    margin-bottom: 14px;
    font-size: 13px;
    color: var(--text-secondary);
}

.sheet-stats .stat-value {
    font-weight: 700;
    color: var(--text);
    font-size: 15px;
}

.sheet-detail-btn {
    width: 100%;
    height: 44px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.sheet-detail-btn:active {
    background: var(--primary-dark);
}

/* --- Search Overlay --- */
#search-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 200;
    display: flex;
    flex-direction: column;
}

#search-overlay .search-header {
    background: var(--primary);
    padding: 8px 8px 8px 16px;
    padding-top: calc(env(safe-area-inset-top, 0px) + 8px);
    display: flex;
    align-items: center;
    gap: 8px;
}

#search-input {
    flex: 1;
    height: 40px;
    border: none;
    border-radius: var(--radius-sm);
    padding: 0 14px;
    font-size: 16px;
    outline: none;
    background: rgba(255,255,255,0.95);
    color: var(--text);
}

#search-close {
    background: none;
    border: none;
    color: white;
    font-size: 16px;
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

#search-results {
    flex: 1;
    background: var(--bg);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.search-result {
    padding: 14px 16px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
}

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

.search-result .result-name {
    flex: 1;
    font-size: 15px;
    font-weight: 500;
}

/* --- Forecast Grid (detail view) --- */
.forecast-grid {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
    margin-bottom: 16px;
    display: table;
    width: 100%;
    border-collapse: collapse;
    table-layout: fixed;
}

.grid-header {
    display: table-row;
}

.grid-header > div {
    display: table-cell;
    text-align: center;
    padding: 10px 4px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border);
}

.grid-header > div:first-child {
    width: 80px;
}

.grid-row {
    display: table-row;
}

.grid-slot-label {
    display: table-cell;
    width: 80px;
    text-align: center;
    vertical-align: middle;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    background: var(--bg);
    padding: 8px 4px;
    border-bottom: 1px solid var(--border);
    border-right: 1px solid var(--border);
}

.grid-cell {
    display: table-cell;
    text-align: center;
    padding: 12px 4px;
    vertical-align: middle;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
}

.grid-cell.selected {
    background: #EFF6FF;
    box-shadow: inset 0 0 0 2px var(--primary);
}

.grid-cell.empty {
    color: var(--text-secondary);
    background: var(--bg);
}

.cell-score {
    font-size: 16px;
    font-weight: 700;
}

.cell-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin: 4px auto 0;
}

/* --- Detail Score Header --- */
.detail-score-header {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-bottom: 16px;
}

.detail-score-circle {
    width: 52px;
    height: 52px;
    border-radius: 50%;
    color: white;
    font-size: 20px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.detail-score-label {
    font-size: 18px;
    font-weight: 700;
}

.detail-score-sub {
    font-size: 13px;
    color: var(--text-secondary);
    margin-top: 2px;
}

/* --- Detail View Mode: hide day-selector + filters, expand content --- */
body.detail-view #day-selector {
    display: none;
}

body.detail-view #filters-bar {
    display: none;
}

body.detail-view #content {
    top: var(--top-bar);
    bottom: calc(var(--tab-bar) + var(--safe-bottom));
}

#detail-container {
    padding-bottom: 24px;
}

/* --- Offline Banner --- */
.offline-banner {
    position: fixed;
    top: var(--top-bar);
    left: 0;
    right: 0;
    background: #FEF3C7;
    color: #92400E;
    font-size: 12px;
    text-align: center;
    padding: 6px;
    z-index: 95;
}

/* Focus styles for keyboard navigation */
.tab:focus-visible,
.day-pill:focus-visible,
.slot-btn:focus-visible,
.beach-card:focus-visible,
.filter-select:focus-visible,
.filter-btn:focus-visible,
.detail-action-btn:focus-visible,
.sheet-detail-btn:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

#search-input:focus-visible {
    box-shadow: 0 0 0 2px white, 0 0 0 4px var(--primary);
}

.grid-day-label {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
}

/* Screen reader only */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0,0,0,0);
    white-space: nowrap;
}

/* Loading spinner */
.loading-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(255,255,255,0.95);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    z-index: 500;
    transition: opacity 0.3s;
}
.loading-overlay.fade-out {
    opacity: 0;
    pointer-events: none;
}
.spinner-ring {
    width: 40px; height: 40px;
    border: 4px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Install banner */
.install-banner {
    position: fixed;
    bottom: calc(var(--tab-bar) + var(--safe-bottom) + 8px);
    left: 12px; right: 12px;
    background: var(--primary);
    color: white;
    padding: 12px 16px;
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    gap: 10px;
    z-index: 300;
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
    font-size: 14px;
}
.install-btn {
    background: white;
    color: var(--primary);
    border: none;
    padding: 8px 16px;
    border-radius: 20px;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
}
.dismiss-btn {
    background: transparent;
    color: white;
    border: none;
    font-size: 18px;
    cursor: pointer;
    padding: 4px;
}

/* Data freshness */
.freshness-badge {
    font-size: 11px;
    color: rgba(255,255,255,0.7);
    margin-left: 8px;
}

/* Webcam embed */
.webcam-embed {
    width: 100%;
    border-radius: var(--radius);
    overflow: hidden;
    margin: 12px 0;
    background: #000;
    aspect-ratio: 16/9;
}
.webcam-embed iframe {
    width: 100%;
    height: 100%;
    border: none;
}

/* --- Desktop Breakpoint --- */
@media (min-width: 640px) {
    #detail-container {
        max-width: 600px;
        margin: 0 auto;
    }

    .forecast-strip {
        gap: 12px;
    }

    .detail-data {
        max-width: 500px;
    }

    #bottom-sheet {
        max-width: 420px;
        left: auto;
        right: 16px;
        border-radius: 16px;
    }
}
