/* Global reset */
*,
*::before,
*::after {
    box-sizing: border-box;
}

body, html {
    margin: 0;
    height: 100%;
    line-height: 1.5;
    font-family: system-ui, sans-serif;
    padding-bottom: 3.5rem;
}

@supports (padding-bottom: env(safe-area-inset-bottom)) {
    body {
        padding-bottom: calc(3.5rem + env(safe-area-inset-bottom));
    }
}

/* Map full height */
#map {
    height: calc(var(--vh, 1vh) * 100 - 25px);
}

/* Toggle Button */
#toggle-refresh {
    position: absolute;
    top: 12px;
    right: 12px;
    z-index: 9999;
    padding: 6px 12px;
    min-width: 160px;
    font-size: 13px;
    font-weight: 500;
    border-radius: 6px;
    border: 1px solid #ccc;
    background-color: white;
    color: #333;
    cursor: pointer;
    transition: all 0.2s ease;
}

#toggle-refresh.active {
    background-color: #4CAF50;
    color: white;
    border-color: #3e8e41;
}

/* Camera Thumbnail */
.cam-thumb-wrapper {
    position: relative;
    display: inline-block;
}

.cam-thumb-overlay {
    width: 72px;
    height: 56px;
    border-radius: 5px;
    overflow: hidden;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.cam-thumb-overlay:hover {
    transform: scale(1.75);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    z-index: 10;
}

.cam-thumb-overlay:hover .cam-label-overlay {
    display: none;
}

.cam-thumb-overlay img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.cam-thumb-overlay img[data-loaded="false"] {
    filter: blur(4px) grayscale(1);
    opacity: 0.5;
}

/* Thumbnail Label */
.cam-label-overlay {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 2px 6px;
    font-size: 10px;
    font-weight: 500;
    color: white;
    background: linear-gradient(to top, rgba(0, 0, 0, 0.75), transparent);
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.9);
    pointer-events: none;
    word-break: break-word;
    border-bottom-left-radius: 5px;
    border-bottom-right-radius: 5px;
}

/* Tooltip */
.cam-tooltip {
    visibility: hidden;
    opacity: 0;
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    margin-bottom: 22px;
    padding: 4px 8px;
    font-size: 11px;
    color: #fff;
    background-color: rgba(0, 0, 0, 0.85);
    border-radius: 4px;
    white-space: nowrap;
    text-align: center;
    pointer-events: none;
    z-index: 9999;
    transition: opacity 0.2s ease;
}

.cam-thumb-wrapper:hover .cam-tooltip {
    visibility: visible;
    opacity: 1;
}

/* Popup Layout */
.popup-content {
    display: flex;
    flex-direction: column;
    align-items: stretch;
}

.popup-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    padding-bottom: 6px;
}

.popup-title {
    font-size: 17px;
    font-weight: bold;
}

.popup-image {
    width: 100%;
    height: auto;
    max-width: 100%;
    border-radius: 0px;
    object-fit: cover;
}

/* Directions link */
.directions-link {
    font-size: 13px;
    color: #007bff;
    text-decoration: none;
}

.directions-link:hover {
    text-decoration: underline;
}

/* Weather Info */
.weather-box {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 10px 16px;
    margin-top: 12px;
    width: 100%;
    font-size: 13px;
    color: #333;
    border-radius: 8px;
}

.weather-item {
    display: flex;
    align-items: center;
    gap: 8px;
    line-height: 1.4;
}

.weather-icon {
    width: 20px;
    text-align: center;
    font-size: 16px;
    opacity: 0.8;
}

.weather-loading {
    text-align: center;
    font-size: 13px;
    color: #777;
}

.weather-label {
    font-size: 11px;
    color: #777;
    margin-bottom: 2px;
}

.weather-text {
    display: flex;
    flex-direction: column;
}

/* Leaflet Popup Width */
.leaflet-popup-content {
    width: 520px !important;
    max-width: 100%;
    margin: 15px 10px 5px 10px !important;
}

.wind-arrow {
    display: inline-block;
    transform-origin: center;
    vertical-align: middle;
    width: 1em;
    height: 1em;
    margin-left: 2px;
}

#site-footer {
    position: fixed;
    height: 25px;
    bottom: 0;
    left: 0;
    right: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    background: rgba(255, 255, 255, 0.95);
    border-top: 1px solid #ddd;
    color: #555;
    z-index: 9999;
}

#site-footer a {
    color: #007bff;
    text-decoration: none;
}

#site-footer a:hover {
    text-decoration: underline;
}

#site-footer .emoji {
    font-size: 9px;
}

.forecast-scroll {
    display: flex;
    overflow-x: auto;
    gap: 1rem;
    padding: 0.5rem;
    scroll-snap-type: x mandatory;
}

.forecast-hour {
    position: relative;
    flex: 0 0 auto;
    scroll-snap-align: start;
    background: #fff;
    border: 1px solid #ddd;
    border-radius: 10px;
    padding: 10px 14px;
    text-align: center;
    font-size: 12px;
    line-height: 1.4;
    min-width: 120px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
    display: flex;
    flex-direction: column;
    gap: 6px;
    color: #333;
}

.forecast-hour .forecast-time {
    font-size: 11px;
    font-weight: 600;
    color: #444;
}

.forecast-hour .forecast-date {
    font-size: 11px;
    color: #777;
}

.forecast-hour .forecast-icon {
    margin-top: 15px;
    font-size: 15px;
}

.forecast-hour div {
    white-space: nowrap;
    display: inline-block;
}

.forecast-hour strong {
    display: inline-block;
    font-weight: 600;
    color: #111;
    margin-right: 4px;
}

.wind-arrow {
    width: 1em;
    height: 1em;
    vertical-align: middle;
    margin-left: 2px;
    transform-origin: center;
}

.forecast-hour:hover {
    background: #f0f8ff;
    border-color: #b3d4fc;
}

.forecast-hour.now {
    background: #fff8e1;
    border-color: #ffecb3;
}

.forecast-date {
    position: absolute;
    top: 5px;
    right: 5px;
    font-size: 11px;
    font-weight: 500;
    color: #777;
}

.forecast-time {
    position: absolute;
    top: 5px;
    left: 5px;
    font-size: 12px;
    font-weight: 600;
    color: #444;
}

.forecast-day-group {
    flex: 0 0 auto;
    display: flex;
    flex-direction: column;
    border-radius: 6px;
    scroll-snap-align: start;
    min-width: max-content;
}

.forecast-day-label {
    position: sticky;
    left: 0;
    top: 0;
    background: #f0f0f0;
    font-weight: 600;
    font-size: 0.75rem;
    padding: 1px 6px;
    margin-bottom: 0.3rem;
    z-index: 1;
    border-radius: 5px;
}

.forecast-day-cards {
    display: flex;
    gap: 0.5rem;
}

.visually-hidden {
    position: absolute;
    left: -9999px;
    top: auto;
    width: 1px;
    height: 1px;
    overflow: hidden;
}

/* Mobile Responsive */
@media (max-width: 600px) {
    #toggle-refresh {
        font-size: 12px;
        padding: 5px 10px;
        min-width: auto;
        top: 8px;
        right: 8px;
    }

    .popup-header {
        align-items: flex-start;
    }

    .popup-image {
        width: 100%;
        max-width: 100%;
    }

    .leaflet-popup-content-wrapper {
        margin-left: auto !important;
        margin-right: auto !important;
    }

    .leaflet-popup-content {
        width: calc(100vw - 32px) !important;
        margin: 0 auto;
    }
}
