/**
 * Météo Centre - Frontend Core CSS
 * @version 4.0.0 - Full refactor with fluid units and unified cards
 *
 * Contents: Variables, Essential components, Messages, Modal, Unified cards
 * Loaded: ALWAYS (required by all blocks)
 *
 * CHANGES v4.0:
 * ✅ 100% unified cards (modal + city identical)
 * ✅ Fluid units (em, %, clamp) instead of fixed px
 * ✅ Robust grid without overflow
 * ✅ Simplified and maintainable code
 */

/* ========================================================================
 * VARIABLES CSS ESSENTIELLES
 * ======================================================================== */

:root {
    /* Main colours */
    --rsmc-primary: #667eea;
    --rsmc-primary-dark: #5568d3;
    --rsmc-secondary: #764ba2;

    /* Semantic colours */
    --rsmc-success: #28a745;
    --rsmc-danger: #dc3545;
    --rsmc-warning: #ffc107;

    /* Neutral colours (with WordPress fallback) */
    --rsmc-light: var(--wp--preset--color--base, #f8f9fa);
    --rsmc-dark: var(--wp--preset--color--contrast, #333);
    --rsmc-border: var(--wp--preset--color--tertiary, #e9ecef);

    /* Design tokens */
    --rsmc-radius: 12px;
    --rsmc-radius-sm: 8px;
    --rsmc-shadow: 0 2px 8px rgba(0,0,0,0.1);
    --rsmc-shadow-lg: 0 10px 40px rgba(0,0,0,0.3);
    --rsmc-transition: all 0.3s ease;

    /* ✅ NEW: Base card sizes (in em = fluid) */
    --rsmc-card-padding: 1em;
    --rsmc-card-gap: 1em;
    --rsmc-card-min-width: 12em; /* ~192px at 16px base */
    --rsmc-picto-size: 3.75em; /* 60px at 16px base */
}

/* ========================================================================
 * CONTENEURS DE BASE
 * ======================================================================== */

.rsmc-city-wrapper,
.rsmc-map-wrapper {
    margin: 30px 0;
    width: 100%;
    box-sizing: border-box;
    font-size: 16px; /* Base for em calculations */
}

.rsmc-city-wrapper *,
.rsmc-map-wrapper * {
    box-sizing: border-box;
}

/* ========================================================================
 * MESSAGES (Error, Loading, Info)
 * ======================================================================== */

.rsmc-error,
.rsmc-loading,
.rsmc-info {
    padding: 1.25rem;
    border-radius: var(--rsmc-radius-sm);
    margin: 1.25rem 0;
}

.rsmc-error {
    background: #fee;
    border-left: 4px solid var(--rsmc-danger);
    color: var(--rsmc-danger);
}

.rsmc-loading {
    text-align: center;
    color: #999;
}

.rsmc-info {
    background: #e7f3ff;
    border-left: 4px solid #2196f3;
    color: #1976d2;
}

/* ========================================================================
 * HEADER GRADIENT (Reusable)
 * ======================================================================== */

.rsmc-header {
    background: linear-gradient(135deg, var(--rsmc-primary) 0%, var(--rsmc-secondary) 100%);
    padding: clamp(20px, 5vw, 40px) clamp(20px, 4vw, 30px);
    color: #fff;
    border-radius: var(--rsmc-radius) var(--rsmc-radius) 0 0;
}

.rsmc-header h1,
.rsmc-header h2,
.rsmc-header h3 {
    color: inherit;
    margin-top: 0;
}

.rsmc-header p {
    opacity: 0.9;
    margin: 0;
}

/* ========================================================================
 * MODAL (7-day display from the map)
 * ======================================================================== */

.rsmc-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    padding: 20px;
    animation: rsmcOverlayIn 0.18s ease both; /* backdrop fade-in */
}

.rsmc-modal {
    background: #fff;
    border-radius: var(--rsmc-radius);
    max-width: 1000px;
    width: 100%;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    box-shadow: var(--rsmc-shadow-lg);
    font-size: 16px; /* ✅ Base for em units */
    animation: rsmcCardIn 0.22s cubic-bezier(0.2, 0.7, 0.3, 1) both; /* card fade + slight rise */
}

@keyframes rsmcOverlayIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes rsmcCardIn {
    from { opacity: 0; transform: translateY(6px) scale(0.985); }
    to { opacity: 1; transform: none; }
}

@media (prefers-reduced-motion: reduce) {
    .rsmc-modal-overlay,
    .rsmc-modal { animation: none; }
}

.rsmc-modal-header {
    padding: 1.25em 1.875em;
    background: linear-gradient(135deg, var(--rsmc-primary) 0%, var(--rsmc-secondary) 100%);
    color: #fff;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-radius: var(--rsmc-radius) var(--rsmc-radius) 0 0;
}

.rsmc-modal-header h2 {
    margin: 0;
    color: inherit;
    font-size: 1.5em;
}

.rsmc-modal-close {
    background: transparent;
    border: none;
    color: #fff;
    font-size: 2em;
    cursor: pointer;
    padding: 0;
    width: 1em;
    height: 1em;
    line-height: 1;
    transition: var(--rsmc-transition);
}

.rsmc-modal-close:hover {
    transform: rotate(90deg);
}

.rsmc-modal-body {
    padding: 1.875em;
    overflow-y: auto;
}

.rsmc-modal-forecasts {
    display: flex;
    flex-direction: column;
    gap: 1.875em;
}

.rsmc-modal-day h3 {
    margin: 0 0 0.9375em;
    color: var(--rsmc-primary);
    text-transform: capitalize;
    padding-bottom: 0.625em;
    border-bottom: 2px solid var(--rsmc-border);
    font-size: 1.25em;
}

/* ========================================================================
 * ✅ UNIFIED FORECAST CARDS (Modal + City block + Popup)
 * VERSION 4.0: Fluid, robust, maintainable
 * ======================================================================== */

/* Container grid - Horizontal scroll */
.rsmc-hours-grid {
    display: flex;
    gap: var(--rsmc-card-gap);
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 0.5em; /* Space for scrollbar */
    cursor: grab;
    user-select: none;
}

.rsmc-hours-grid:active {
    cursor: grabbing;
}

/* Scrollbar styling */
.rsmc-hours-grid::-webkit-scrollbar {
    height: 8px;
}

.rsmc-hours-grid::-webkit-scrollbar-track {
    background: var(--rsmc-light);
    border-radius: 4px;
}

.rsmc-hours-grid::-webkit-scrollbar-thumb {
    background: var(--rsmc-primary);
    border-radius: 4px;
}

.rsmc-hours-grid::-webkit-scrollbar-thumb:hover {
    background: var(--rsmc-primary-dark);
}

/* Individual hourly card - Fixed width for horizontal scroll */
.rsmc-hour-card {
    background: #eef2fb; /* fallback */
    background: color-mix(in srgb, var(--rsmc-primary) 7%, #ffffff);
    border: 1px solid rgba(0, 0, 0, 0.06);
    border-top: 3px solid var(--rsmc-primary);
    padding: var(--rsmc-card-padding);
    border-radius: var(--rsmc-radius-sm);
    text-align: center;
    transition: var(--rsmc-transition);
    display: flex;
    flex-direction: column;
    gap: 0.6em;
    min-width: 13em; /* Comfortable fixed width (208px at 16px) */
    flex-shrink: 0; /* Do not shrink */
}

.rsmc-hour-card:hover {
    background: color-mix(in srgb, var(--rsmc-primary) 13%, #ffffff);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

/* Time */
.rsmc-hour-time {
    font-weight: 600;
    color: var(--rsmc-primary);
    font-size: 0.9375em; /* 15px relative */
    cursor: help;
}

/* Main picto container (weather + temperature) */
.rsmc-hour-main {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 0.875em;
}

.rsmc-hour-sky-picto {
    width: var(--rsmc-picto-size);
    height: var(--rsmc-picto-size);
    max-width: 100%; /* ✅ Responsive safeguard */
    object-fit: contain;
    cursor: help;
}

.rsmc-hour-main > div {
    cursor: help; /* Temperature badge */
}

/* Details container (2-column grid by default) */
.rsmc-hour-details {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.5em;
}

/* ✅ DEDICATED FEELS-LIKE BLOCK (extended mode) */
.rsmc-detail-feels-block {
    grid-column: 1 / -1; /* Spans full width */
    background: rgba(102, 126, 234, 0.08);
    border: 1px solid rgba(102, 126, 234, 0.2);
    border-radius: 6px;
    padding: 0.625em;
}

.rsmc-detail-feels-title {
    font-size: 0.6875em; /* 11px */
    font-weight: 700;
    text-transform: uppercase;
    color: var(--rsmc-primary);
    margin-bottom: 0.5em;
    text-align: center;
}

.rsmc-detail-feels-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.5em;
}

.rsmc-detail-feels-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.25em;
    padding: 0.375em 0.25em;
    background: rgba(255, 255, 255, 0.7);
    border-radius: 4px;
    cursor: help;
    user-select: none;
}

.rsmc-detail-feels-label {
    font-size: 0.5625em; /* 9px */
    font-weight: 600;
    text-transform: uppercase;
    opacity: 0.7;
    color: #555;
}

.rsmc-detail-feels-value {
    font-size: 1em;
    font-weight: 700;
    color: var(--rsmc-primary);
}

/* Individual detail item */
.rsmc-detail-item {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.3125em;
    font-size: 0.8125em; /* 13px relative */
    color: #555;
    padding: 0.375em;
    background: #fff;
    border-radius: 4px;
    cursor: help;
    transition: var(--rsmc-transition);
    min-width: 0; /* Allows contraction */
    overflow: hidden; /* Prevents overflow */
}

.rsmc-detail-item:hover {
    background: #f0f4ff;
    transform: scale(1.02);
}

.rsmc-detail-emoji {
    font-size: 1.25em;
    flex-shrink: 0;
}

.rsmc-detail-picto {
    width: 1.375em; /* 18px relative */
    height: 1.375em;
    object-fit: contain;
    flex-shrink: 0;
}

.rsmc-detail-label {
    font-size: 0.769em; /* 10px relative */
    opacity: 0.75;
    font-weight: 600;
    text-transform: uppercase;
}

.rsmc-detail-value {
    font-weight: 600;
    color: #333;
    white-space: nowrap;
}

/* ========================================================================
 * SECTIONS & LAYOUT
 * ======================================================================== */

.rsmc-section {
    padding: 1.875em;
    background: #fff;
}

.rsmc-section h2 {
    margin-top: 0;
    color: var(--rsmc-dark);
}

/* ========================================================================
 * MOBILE TOGGLE BUTTON (Map)
 * ======================================================================== */

.rsmc-controls-toggle {
    display: none;
    position: absolute;
    bottom: 20px;
    left: 20px;
    z-index: 1001;
    width: 3em;
    height: 3em;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    border: 2px solid rgba(0, 0, 0, 0.2);
    /* Rounded square (no circle), matching the fullscreen / display map buttons. */
    border-radius: 8px;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
    align-items: center;
    justify-content: center;
    font-size: 1.5em;
    transition: var(--rsmc-transition);
    user-select: none;
}

.rsmc-controls-toggle:hover {
    background: #f4f4f4;
    transform: scale(1.05);
}

.rsmc-controls-toggle:active {
    transform: scale(0.95);
}

/* ========================================================================
 * GLOBAL ANIMATIONS
 * ======================================================================== */

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateX(-20px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

/* Apply animations */
.rsmc-city-wrapper,
.rsmc-map-wrapper,
.rsmc-section {
    animation: fadeIn 0.5s ease;
}

.rsmc-hour-card {
    animation: fadeIn 0.3s ease;
}

.rsmc-floating-controls.is-visible {
    animation: slideIn 0.3s ease;
}

/* ========================================================================
 * FIELD HINTS / FEELS-LIKE OVERLAY (RsmcTooltip) — themed from --rsmc-*
 * ======================================================================== */

[data-tip] {
    cursor: help;
}

.rsmc-tooltip {
    position: absolute;
    z-index: 99999;
    max-width: 17em;
    background: #fff;
    color: var(--rsmc-text, #2b2f38);
    padding: 0.55em 0.75em;
    border: 1px solid rgba(0, 0, 0, 0.08);
    border-top: 3px solid var(--rsmc-primary);
    border-radius: var(--rsmc-radius-sm, 8px);
    font-size: 0.8125em;
    line-height: 1.4;
    box-shadow: 0 8px 26px rgba(0, 0, 0, 0.16);
    /* Fade in/out; hidden + click-through until shown. */
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transform: translateY(2px);
    transition: opacity 0.14s ease, transform 0.14s ease, visibility 0.14s;
}

.rsmc-tooltip.is-shown {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transform: translateY(0);
}

.rsmc-tooltip--card {
    max-width: 22em;
    padding: 0.75em 0.9em;
}

.rsmc-feels-overlay-title {
    font-weight: 700;
    color: var(--rsmc-primary);
    margin-bottom: 0.5em;
}

.rsmc-feels-row {
    padding: 0.4em 0;
    border-top: 1px solid rgba(0, 0, 0, 0.08);
}

.rsmc-feels-row:first-of-type {
    border-top: 0;
}

.rsmc-feels-row-top {
    display: flex;
    justify-content: space-between;
    gap: 1em;
    font-weight: 600;
}

.rsmc-feels-row--primary {
    background: color-mix(in srgb, var(--rsmc-primary) 10%, transparent);
    border-radius: 6px;
    padding: 0.4em 0.5em;
    margin: 0.15em -0.25em;
}

.rsmc-feels-row--primary .rsmc-feels-name {
    color: var(--rsmc-primary);
}

.rsmc-feels-temp {
    font-variant-numeric: tabular-nums;
}

.rsmc-feels-desc {
    opacity: 0.72;
    font-size: 0.92em;
    margin-top: 0.15em;
}

.rsmc-detail-feels,
.rsmc-hour-feels {
    cursor: pointer;
}

/* The hourly card's "feels like" line sits right under the temperature. */
.rsmc-hour-feels {
    font-size: 0.85em;
    color: var(--rsmc-primary-dark, var(--rsmc-primary));
    font-weight: 500;
    text-align: center;
}

/* "Now" marker on the current hour card. */
.rsmc-hour-card.rsmc-hour-now {
    outline: 2px solid var(--rsmc-primary);
    outline-offset: -2px;
    position: relative;
}

.rsmc-hour-card.rsmc-hour-now::before {
    content: "●";
    position: absolute;
    top: 0.25em;
    right: 0.4em;
    color: var(--rsmc-primary);
    font-size: 0.7em;
}

/* Card images never start a native drag (so the whole strip drag-scrolls). */
.rsmc-hours-grid img,
.rsmc-weather-card img,
.rsmc-weather-main-picto {
    -webkit-user-drag: none;
    user-select: none;
    pointer-events: none;
}

/* …but elements that carry a hint must still receive hover/tap. */
.rsmc-hours-grid [data-tip],
.rsmc-weather-card[data-tip],
.rsmc-weather-main-picto[data-tip] {
    pointer-events: auto;
}

/* ========================================================================
 * COMPACT CARD LAYOUT — narrower / taller cards, same horizontal scroller.
 * Shared here (not in frontend-city.css) so the forecast map's 7-day modal
 * can use it too. Applied via a .rsmc-cards-compact ancestor.
 * ======================================================================== */

.rsmc-cards-compact .rsmc-hour-card {
    min-width: 7em;
    width: 7em;
    gap: 0.4em;
    padding: 0.5em 0.4em;
}

.rsmc-cards-compact .rsmc-hour-main {
    flex-direction: column;
    gap: 0.3em;
}

.rsmc-cards-compact .rsmc-hour-sky-picto {
    width: 2.6em;
    height: 2.6em;
}

/* Only the hourly cards shrink the badge — NOT the header's .rsmc-temp-main-badge. */
.rsmc-cards-compact .rsmc-hour-temp svg {
    width: 2.6em !important;
    height: 2.6em !important;
}

/* Compact → the 4 metrics stack 1×4 (the card is narrow). */
.rsmc-cards-compact .rsmc-hour-details {
    grid-template-columns: 1fr;
    gap: 0.2em;
}

.rsmc-cards-compact .rsmc-detail-item {
    font-size: 0.82em;
}

.rsmc-cards-compact .rsmc-detail-picto {
    width: 1.25em;
    height: 1.25em;
}

.rsmc-cards-compact .rsmc-detail-label {
    display: none; /* lean on the value + hover hint to save space */
}
