/* ── Design tokens (inspirés SNCF WCS) ──────────────────────────────────── */
:root {
    --primary: #1e173c;
    --primary-dark: #2e2750;
    --primary-light: #a9a6bb;

    --red: #CD0037;
    --dark: #1A1A1A;
    --gray-700: #444444;
    --gray-500: #767676;
    --gray-300: #C8C8C8;
    --gray-100: #F4F4F4;
    --surface: #FFFFFF;

    --header-h: 56px;
    --ribbon-h: 110px;
    --radius: 6px;
    --radius-lg: 10px;
    --shadow-sm: 0 1px 4px rgba(0, 0, 0, .08);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, .14);

    --font: 'Segoe UI', system-ui, -apple-system, sans-serif;
    --mono: 'Consolas', 'SF Mono', monospace;
}

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

/* Garantit que [hidden] n'est jamais écrasé par display:flex ou display:grid */
[hidden] {
    display: none !important;
}

html {
    height: 100%;
}

body {
    font-family: var(--font);
    font-size: 14px;
    color: var(--dark);
    background: var(--gray-100);
    height: 100dvh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* ── Header ──────────────────────────────────────────────────────────────── */
.app-header {
    height: var(--header-h);
    background: var(--surface);
    border-bottom: 3px solid var(--primary);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    flex-shrink: 0;
    z-index: 20;
    box-shadow: var(--shadow-sm);
}

.header-brand {
    display: flex;
    align-items: center;
    gap: 10px;
}

.brand-icon {
    width: 32px;
    height: 32px;
    flex-shrink: 0;
}

.header-title {
    font-size: 16px;
    font-weight: 700;
    letter-spacing: -0.01em;
    color: var(--dark);
}

.header-auth {
    display: flex;
    align-items: center;
    gap: 10px;
}

.user-label {
    font-size: 13px;
    color: var(--gray-500);
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ── Buttons ─────────────────────────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 16px;
    border: 2px solid transparent;
    border-radius: var(--radius);
    font-family: var(--font);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s, color 0.15s, transform 0.1s;
    line-height: 1.3;
    white-space: nowrap;
}

.btn:active {
    transform: scale(0.97);
}

.btn-primary {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}

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

.btn-outline {
    background: transparent;
    color: var(--primary);
    border-color: var(--primary);
}

.btn-outline:hover {
    background: var(--primary-light);
}

.btn-sm {
    padding: 4px 12px;
    font-size: 12px;
}

/* ── Main ────────────────────────────────────────────────────────────────── */
.app-main {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 16px 16px 8px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    min-height: 0;
}

#view-main {
    flex: 1;
    gap: 16px;
    display: flex;
    flex-direction: column;
}

section {
    flex: 1;
}

/* ── State panels (unauth / loading / empty) ─────────────────────────────── */
.state-panel {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 14px;
    padding: 48px 20px;
    text-align: center;
    flex: 1;
}

.state-icon-svg {
    width: 56px;
    height: 56px;
}

.state-panel h2 {
    font-size: 18px;
    color: var(--dark);
}

.state-panel p {
    font-size: 14px;
    color: var(--gray-500);
}

/* ── Item card ───────────────────────────────────────────────────────────── */
.item-card {
    background: var(--surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    padding: 16px;
    flex-shrink: 0;
}

.item-card-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    margin-bottom: 14px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--gray-100);
}

.card-label {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--gray-500);
    margin-bottom: 2px;
}

.item-datetime {
    font-size: 20px;
    font-weight: 700;
    font-family: var(--mono);
    color: var(--dark);
    letter-spacing: -0.02em;
}

/* Live indicator */
.live-dot {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    font-weight: 600;
    color: var(--red);
    flex-shrink: 0;
    padding-top: 2px;
}

.live-dot .pulse {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--red);
    flex-shrink: 0;
    animation: pulse 1.6s ease-in-out infinite;
}

.live-dot.paused {
    color: var(--gray-300);
}

.live-dot.paused .pulse {
    background: var(--gray-300);
    animation: none;
}

@keyframes pulse {

    0%,
    100% {
        opacity: 1;
        box-shadow: 0 0 0 0 rgba(205, 0, 55, .4);
    }

    50% {
        opacity: 0.6;
        box-shadow: 0 0 0 5px rgba(205, 0, 55, 0);
    }
}

/* Card body */
.item-card-body {
    display: flex;
    flex-direction: column;
    gap: 16px;
    align-items: center;
}

/* ── Vignette principale ──────────────────────────────────────────────────── */
.item-visual {
    flex-shrink: 0;
    display: flex;
    justify-content: center;
    width: 100%;
}

.thumb-btn {
    position: relative;
    display: block;
    width: 220px;
    height: 165px;
    border: 2px solid var(--gray-100);
    border-radius: var(--radius);
    overflow: hidden;
    cursor: pointer;
    background: var(--gray-100);
    padding: 0;
    transition: border-color 0.2s;
}

.thumb-btn:not(:disabled):hover {
    border-color: var(--primary);
}

.thumb-btn:disabled {
    cursor: default;
}

.thumb-btn img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    transition: opacity 0.25s;
}

.thumb-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, .35);
    opacity: 0;
    transition: opacity 0.2s;
    color: #fff;
}

.thumb-overlay svg {
    width: 28px;
    height: 28px;
}

.thumb-btn:not(:disabled):hover .thumb-overlay {
    opacity: 1;
}

/* Mode grande image (> 768 px) : originale à la place de la vignette */
.thumb-btn.large-view {
    width: auto;
    height: auto;
    max-width: 100%;
    max-height: 60vh;
    border: none;
    background: transparent;
    overflow: visible;
}

.thumb-btn.large-view img {
    width: auto;
    height: auto;
    max-width: 100%;
    max-height: 60vh;
    object-fit: contain;
}

/* ── Compteurs ───────────────────────────────────────────────────────────── */
.counters-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    width: 100%;
    align-content: start;
}

.counter-card {
    background: var(--gray-100);
    border-radius: var(--radius);
    padding: 14px 12px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    text-align: center;
    transition: background 0.15s;
}

.counter-icon {
    width: 26px;
    height: 26px;
    color: var(--primary);
    flex-shrink: 0;
}

.counter-value {
    font-size: 28px;
    font-weight: 800;
    color: var(--dark);
    line-height: 1;
    font-variant-numeric: tabular-nums;
    letter-spacing: -0.02em;
}

.counter-label {
    font-size: 11px;
    font-weight: 600;
    text-transform: capitalize;
    color: var(--gray-500);
    letter-spacing: 0.02em;
}

/* ── Ruban ───────────────────────────────────────────────────────────────── */
.ribbon-container {
    height: var(--ribbon-h);
    background: var(--surface);
    border-top: 1px solid var(--gray-300);
    display: flex;
    align-items: center;
    flex-shrink: 0;
}

.ribbon-nav {
    flex-shrink: 0;
    width: 36px;
    height: 100%;
    background: transparent;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--gray-500);
    transition: color 0.15s, background 0.15s;
}

.ribbon-nav:hover:not(:disabled) {
    color: var(--primary);
    background: var(--primary-light);
}

.ribbon-nav:disabled {
    color: var(--gray-300);
    cursor: default;
}

.ribbon-nav svg {
    width: 18px;
    height: 18px;
}

.ribbon-track {
    flex: 1;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    overflow: hidden;
    padding: 8px 0;
    touch-action: pan-y;
}

.ribbon-item {
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 4px;
    border-radius: var(--radius);
    border: 2px solid transparent;
    cursor: pointer;
    background: transparent;
    transition: background 0.15s, border-color 0.15s;
    font-family: var(--font);
}

.ribbon-item:hover {
    background: var(--gray-100);
}

.ribbon-item.active {
    border-color: var(--primary);
    background: white/* var(--primary-light) */;
}

.ribbon-thumb {
    border-radius: 4px;
    object-fit: cover;
    display: block;
}

.ribbon-time {
    font-size: 10px;
    color: var(--gray-500);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
    font-family: var(--mono);
}

/* Skeleton shimmer */
.ribbon-thumb.loading {
    background: linear-gradient(90deg, var(--gray-100) 25%, var(--gray-300) 50%, var(--gray-100) 75%);
    background-size: 200% 100%;
    animation: shimmer 1.2s infinite;
}

@keyframes shimmer {
    to {
        background-position: -200% 0;
    }
}

/* ── Spinner ─────────────────────────────────────────────────────────────── */
.spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--gray-300);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

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

/* ── Modal ───────────────────────────────────────────────────────────────── */
.modal {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: block;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
    cursor: grab;
}

/* Le backdrop reste fixe même quand le modal scrolle */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, .8);
    backdrop-filter: blur(4px);
    cursor: pointer;
    z-index: 0;
}

/* La box est un conteneur plein écran centrant l'image */
.modal-box {
    position: relative;
    z-index: 1;
    background: transparent;
    overflow: visible;
    min-width: 100vw;
    min-height: 100dvh;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Image à sa taille naturelle — le modal scrolle si elle dépasse */
.modal-box img {
    display: block;
    max-width: none;
    max-height: none;
    object-fit: none;
    width: auto;
    height: auto;
}

/* Bouton fermer en position fixe : toujours accessible même en cours de scroll */
.modal-close {
    position: fixed;
    top: 8px;
    right: 8px;
    width: 34px;
    height: 34px;
    background: rgba(0, 0, 0, .55);
    border: none;
    border-radius: 50%;
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1002;
    transition: background 0.15s;
}

.modal-close:hover {
    background: var(--primary);
}

.modal-close svg {
    width: 15px;
    height: 15px;
}

.modal-spinner {
    position: fixed;
    display: flex;
    align-items: center;
    justify-content: center;
    inset: 0;
    z-index: 1001;
}

/* ── Responsive ──────────────────────────────────────────────────────────── */

/* Petits écrans (< 600px) : portrait mobile */
@media (max-width: 599px) {
    .app-header {
        padding: 0 12px;
    }

    .header-title {
        font-size: 14px;
    }

    .user-label {
        display: none;
    }

    .app-main {
        padding: 10px 10px 6px;
        gap: 8px;
    }

    .item-card {
        padding: 12px;
    }

    .item-datetime {
        font-size: 15px;
    }

    .item-card-body {
        gap: 12px;
    }

    .counters-grid {
        gap: 6px;
    }

    .counter-card {
        padding: 8px 4px;
    }

    .counter-value {
        font-size: 20px;
    }

    .counter-icon {
        width: 20px;
        height: 20px;
    }

}

/* Tablette (600-899px) : 2 colonnes compteurs */
@media (min-width: 600px) and (max-width: 899px) {
    .counters-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* Large écran (≥ 1200px) : compteurs sur 1 ligne */
@media (min-width: 1200px) {
    .counters-grid {
        grid-template-columns: repeat(4, 1fr);
    }
}