:root {
    --primary: #d63031;
    --accent: #ff7675;
    --bg-gradient: linear-gradient(135deg, #f0f4f8 0%, #d9e4f0 100%);
    --text-dark: #2d3436;
    --text-muted: #636e72;
    --ok-color: #44bd32;
    --near-miss-color: #fbc531;
    --accident-color: #e84118;
    --card-bg: #ffffff;
    --card-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
    --card-radius: 16px;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Outfit', sans-serif;
}

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

body {
    background: var(--bg-gradient);
    color: var(--text-dark);
    display: flex;
    flex-direction: column;
}

/* ========== LOGIN ========== */
.login-bg {
    background: var(--bg-gradient);
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow-y: auto;
}

.glass-container {
    background: var(--card-bg);
    border-radius: var(--card-radius);
    box-shadow: var(--card-shadow);
    padding: 2rem;
    margin-bottom: 2rem;
}

.login-box {
    width: 100%;
    max-width: 420px;
    text-align: center;
}

.logo-container {
    margin-bottom: 1.5rem;
}

.logo {
    max-width: 180px;
    height: auto;
}

.logo-text {
    font-size: 3.5rem;
    font-weight: 800;
    color: var(--primary);
    text-transform: uppercase;
    letter-spacing: -2px;
}

.logo-subtitle {
    font-size: 0.9rem;
    color: var(--text-muted);
    margin-top: 0.3rem;
}

h2 {
    margin-bottom: 1.5rem;
    color: var(--text-dark);
    font-weight: 700;
}

/* ========== ADMIN ========== */
.admin-bg {
    background: var(--bg-gradient);
    min-height: 100%;
    overflow-y: auto;
}

.main-content {
    max-width: 1100px;
    margin: 0 auto;
    padding: 2rem;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

/* Card generica per admin */
.admin-card {
    background: var(--card-bg);
    border-radius: var(--card-radius);
    box-shadow: var(--card-shadow);
    padding: 1.8rem 2rem;
}

.admin-card h2 {
    margin-bottom: 1.5rem;
    font-size: 1.4rem;
    font-weight: 700;
}

/* Select input */
.select-input {
    width: 100%;
    padding: 0.9rem 1.2rem;
    border: 2px solid #dfe6e9;
    border-radius: 10px;
    outline: none;
    font-size: 1rem;
    font-family: 'Outfit', sans-serif;
    background: #fff;
    color: var(--text-dark);
    cursor: pointer;
    transition: border-color 0.3s;
}

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

/* Badge ruolo */
.badge {
    display: inline-block;
    padding: 0.25rem 0.7rem;
    border-radius: 6px;
    font-size: 0.82rem;
    font-weight: 700;
    letter-spacing: 0.5px;
}

.badge-admin {
    background: var(--primary);
    color: white;
}

.badge-user {
    background: #dfe6e9;
    color: var(--text-muted);
}


/* ========== INPUTS / FORMS ========== */
.input-group {
    margin-bottom: 1.5rem;
    text-align: left;
}

.input-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 600;
    font-size: 0.95rem;
    color: var(--text-muted);
}

.input-group input {
    width: 100%;
    padding: 0.9rem 1.2rem;
    border: 2px solid #dfe6e9;
    border-radius: 10px;
    outline: none;
    font-size: 1rem;
    transition: border-color 0.3s;
    background: #fff;
}

.input-group input:focus {
    border-color: var(--primary);
}

.input-row {
    display: flex;
    gap: 1.5rem;
    margin-bottom: 0;
    align-items: flex-end;   /* allinea le textbox in basso indipendentemente dall'altezza della label */
}

.flex-1 {
    flex: 1;
}

.date-input-wrapper {
    display: flex;
    gap: 0.5rem;
}

.date-input-wrapper input {
    flex: 1;
}

.readonly-input {
    background-color: #f1f2f6 !important;
    cursor: not-allowed;
}

.status-selection {
    margin-bottom: 2rem;
}

.status-selection>label {
    font-weight: 600;
    color: var(--text-muted);
    display: block;
    margin-bottom: 0.5rem;
}

.radio-group {
    display: flex;
    gap: 1rem;
    margin-top: 0.8rem;
}

.radio-card {
    flex: 1;
    cursor: pointer;
}

.radio-card input {
    display: none;
}

.card-content {
    display: block;
    padding: 1.2rem;
    text-align: center;
    border-radius: 12px;
    font-weight: 700;
    border: 2px solid #dfe6e9;
    transition: all 0.3s;
    color: var(--text-muted);
    background: white;
    font-size: 1.1rem;
}

.ok-card input:checked+.card-content {
    background: var(--ok-color);
    color: white;
    border-color: var(--ok-color);
    box-shadow: 0 4px 15px rgba(68, 189, 50, 0.3);
}

.near-miss-card input:checked+.card-content {
    background: var(--near-miss-color);
    color: white;
    border-color: var(--near-miss-color);
    box-shadow: 0 4px 15px rgba(251, 197, 49, 0.3);
}

.accident-card input:checked+.card-content {
    background: var(--accident-color);
    color: white;
    border-color: var(--accident-color);
    box-shadow: 0 4px 15px rgba(232, 65, 24, 0.3);
}

/* ========== TABLE ========== */
.table-section {
    margin-top: 2rem;
}

.table-responsive {
    overflow-x: auto;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 1rem;
    background: white;
    border-radius: 12px;
    overflow: hidden;
}

.data-table th,
.data-table td {
    padding: 1rem 1.2rem;
    text-align: left;
    border-bottom: 1px solid #dfe6e9;
}

.data-table th {
    font-weight: 700;
    color: var(--text-muted);
    background-color: #f8f9fa;
}

.bg-ok {
    background-color: var(--ok-color) !important;
    color: white;
    font-weight: 600;
    border-radius: 6px;
    padding: 0.3rem 0.8rem;
    display: inline-block;
}

.bg-near-miss {
    background-color: var(--near-miss-color) !important;
    color: white;
    font-weight: 600;
    border-radius: 6px;
    padding: 0.3rem 0.8rem;
    display: inline-block;
}

.bg-accident {
    background-color: var(--accident-color) !important;
    color: white;
    font-weight: 600;
    border-radius: 6px;
    padding: 0.3rem 0.8rem;
    display: inline-block;
}

/* ========== BUTTONS ========== */
.btn {
    display: inline-block;
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    font-weight: 600;
    font-size: 1rem;
    transition: all 0.3s ease;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.btn-sm {
    padding: 0.4rem 0.9rem;
    font-size: 0.85rem;
}

.btn-lg {
    width: 100%;
    padding: 1rem 1.5rem;
    font-size: 1.1rem;
}

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

.btn-primary:hover {
    background-color: #b32626;
    transform: translateY(-2px);
    box-shadow: 0 6px 15px rgba(214, 48, 49, 0.3);
}

.btn-secondary {
    background-color: #0984e3;
    color: white;
}

.btn-secondary:hover {
    background-color: #076aba;
}

.btn-outline {
    background: transparent;
    border: 2px solid var(--primary);
    color: var(--primary);
    padding: 0.4rem 0.9rem;
    border-radius: 8px;
    font-weight: 600;
}

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

.error-text {
    color: var(--accident-color);
    font-size: 0.9rem;
    margin-bottom: 1rem;
}

.mt-2 {
    margin-top: 0.5rem;
}

.mt-3 {
    margin-top: 1rem;
}

.mt-4 {
    margin-top: 2rem;
}

/* ========== NAVBAR ========== */
.top-nav {
    background: #ffffff;
    border-bottom: 1px solid #e8ecef;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: clamp(0.3rem, 0.8vh, 0.6rem) clamp(1rem, 2vw, 2rem);
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
    flex-shrink: 0;
}

.logo-container-nav {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.logo-small {
    height: clamp(42px, 6.5vh, 85px);
}

.logo-text-small {
    font-size: 1.8rem;
    font-weight: 800;
    color: var(--primary);
    letter-spacing: -1px;
}

.nav-links {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.nav-link {
    color: var(--text-dark);
    text-decoration: none;
    font-weight: 600;
    transition: color 0.3s;
    font-size: 0.95rem;
}

.nav-link:hover {
    color: var(--primary);
}

/* ========== DASHBOARD LAYOUT ========== */
.dashboard-bg {
    background: var(--bg-gradient);
    height: 100%;
    display: flex;
    flex-direction: column;
}

.main-dashboard {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.7rem;
    padding: 0.7rem 1.5rem 0.7rem 1.5rem;
    overflow: hidden;
    min-height: 0;
}

.dashboard-grid {
    display: grid;
    gap: 1rem;
}

.top-row {
    grid-template-columns: 3fr 2fr;
    flex: 1 1 0;
    min-height: 0;
}

.bottom-row {
    grid-template-columns: 1fr 1fr;
    flex: 0 0 auto;
}

/* ========== CARDS ========== */
.card {
    background: var(--card-bg);
    border-radius: var(--card-radius);
    box-shadow: var(--card-shadow);
    padding: 1.2rem 1.5rem;
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
}

.card-title {
    font-size: 1rem;
    font-weight: 800;
    text-align: center;
    color: var(--text-dark);
    letter-spacing: 1px;
    margin-bottom: 0.8rem;
    text-transform: uppercase;
    flex-shrink: 0;
}

.chart-card {
    flex: 1;
    min-height: 0;
}

.chart-container {
    position: relative;
    flex: 1;
    min-height: 0;
    width: 100%;
}

/* ========== CALENDARIO ========== */
.cal-card {
    display: flex;
    flex-direction: column;
    min-height: 0;
    padding-left: 0.8rem;
    /* ridotto per far stare le 7 colonne */
    padding-right: 0.8rem;
}

.cal-nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.8rem;
    flex-shrink: 0;
}

.cal-nav-btn {
    background: transparent;
    border: 2px solid var(--primary);
    color: var(--primary);
    border-radius: 8px;
    width: 32px;
    height: 32px;
    font-size: 1.3rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    transition: all 0.2s;
    font-weight: 700;
}

.cal-nav-btn:hover {
    background: var(--primary);
    color: white;
}

.calendar-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.calendar-header {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 4px;
    /* stesso gap del calendar-grid → allineamento perfetto */
    text-align: center;
    font-weight: 700;
    color: var(--text-muted);
    margin-bottom: 0.4rem;
    font-size: 0.75rem;
    flex-shrink: 0;
}

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

.cal-day {
    aspect-ratio: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #edf2f7;
    border-radius: 6px;
    font-weight: 700;
    font-size: 1.1rem;
    color: #b2bec3;
    transition: transform 0.15s;
    min-width: 0;
    overflow: hidden;
}

.cal-day.day-ok,
.cal-day.day-near-miss,
.cal-day.day-accident {
    color: white;
    /* testo bianco sui giorni colorati */
}

.cal-day:hover {
    transform: scale(1.08);
}

.cal-day.empty {
    background: transparent;
    pointer-events: none;
}

.cal-day.today {
    outline: 3px solid #0984e3;
    outline-offset: -2px;
}

.cal-day.day-ok {
    background: var(--ok-color);
    color: white;
}

.cal-day.day-near-miss {
    background: var(--near-miss-color);
    color: white;
}

.cal-day.day-accident {
    background: var(--accident-color);
    color: white;
}

.calendar-legend {
    display: flex;
    justify-content: center;
    gap: 1rem;
    margin-top: 0.6rem;
    font-size: 0.8rem;
    font-weight: 600;
    flex-shrink: 0;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.color-dot {
    width: 16px;
    height: 16px;
    border-radius: 4px;
    display: inline-block;
}

.dot-ok {
    background: var(--ok-color);
}

.dot-near-miss {
    background: var(--near-miss-color);
}

.dot-accident {
    background: var(--accident-color);
}

/* ========== CONTATORI ========== */
.counter-card {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    padding: 1.5rem 2rem;
    border-bottom: 6px solid var(--accident-color);
}

.counter-label h2 {
    margin: 0;
    font-size: 1.3rem;
    text-transform: uppercase;
    font-weight: 800;
    letter-spacing: 0.5px;
    line-height: 1.2;
}

.counter-label p {
    margin: 0.3rem 0 0;
    font-style: italic;
    color: var(--text-muted);
    font-size: 0.85rem;
}

.digital-container {
    background: #1e272e;
    padding: 0.8rem 1.2rem;
    border-radius: 10px;
    border: 4px solid #2f3542;
    min-width: 130px;
    text-align: center;
    flex-shrink: 0;
}

.digital-number {
    font-family: 'Courier New', Courier, monospace;
    font-size: clamp(2.5rem, 5vh, 4rem);
    font-weight: 900;
    color: #ff4757;
    line-height: 1;
    text-shadow: 0 0 15px rgba(255, 71, 87, 0.8);
}

/* ========== VIDEO OVERLAY ========== */
.video-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background-color: black;
    z-index: 9999;
    display: flex;
    justify-content: center;
    align-items: center;
}

.promo-video {
    width: 100%;
    height: 100%;
    object-fit: contain;
    background: black;
}

/* ========== ANIMAZIONI CALENDARIO ========== */
@keyframes slideInFromRight {
    from {
        transform: translateX(40px);
        opacity: 0;
    }

    to {
        transform: translateX(0);
        opacity: 1;
    }
}

@keyframes slideInFromLeft {
    from {
        transform: translateX(-40px);
        opacity: 0;
    }

    to {
        transform: translateX(0);
        opacity: 1;
    }
}

.cal-slide-next {
    animation: slideInFromRight 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94) forwards;
}

.cal-slide-prev {
    animation: slideInFromLeft 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94) forwards;
}

/* ========== GESTIONE VIDEO ========== */
.video-settings-row {
    display: flex;
    align-items: flex-end;
    gap: 1.5rem;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
}

.interval-save-msg {
    color: var(--ok-color);
    font-weight: 700;
    font-size: 0.95rem;
    margin: 0;
    align-self: flex-end;
    padding-bottom: 0.2rem;
}

/* Drag & Drop */
.drop-zone {
    border: 2px dashed #b2bec3;
    border-radius: 14px;
    background: #f8fafc;
    padding: 2.5rem 2rem;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s ease;
    margin-bottom: 1rem;
}

.drop-zone:hover,
.drop-zone.drag-over {
    border-color: var(--primary);
    background: #fff5f5;
}

.drop-zone.drag-over {
    transform: scale(1.01);
    box-shadow: 0 0 0 4px rgba(214, 48, 49, 0.15);
}

.drop-icon {
    font-size: 3rem;
    margin-bottom: 0.5rem;
}

.drop-title {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-dark);
    margin: 0 0 0.3rem;
}

.drop-subtitle {
    font-size: 0.9rem;
    color: var(--text-muted);
    margin: 0;
}

/* Progress bar */
.upload-progress-wrap {
    display: flex;
    align-items: center;
    gap: 1rem;
    background: #f0f4f8;
    border-radius: 10px;
    padding: 0.8rem 1.2rem;
    margin-bottom: 1rem;
}

.upload-progress-label {
    font-weight: 600;
    font-size: 0.9rem;
    min-width: 150px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
}

.upload-progress-bar-bg {
    flex: 2;
    background: #dfe6e9;
    border-radius: 999px;
    height: 10px;
    overflow: hidden;
}

.upload-progress-bar {
    height: 100%;
    width: 0%;
    background: var(--primary);
    border-radius: 999px;
    transition: width 0.2s ease;
}

/* Lista video */
.video-list {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
}

.no-videos-msg {
    color: var(--text-muted);
    font-style: italic;
    text-align: center;
    padding: 1rem 0;
}

.video-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: #f8fafc;
    border: 1px solid #dfe6e9;
    border-radius: 10px;
    padding: 0.8rem 1.2rem;
    gap: 1rem;
}

.video-item-info {
    display: flex;
    align-items: center;
    gap: 0.8rem;
    flex: 1;
    min-width: 0;
}

.video-item-icon { font-size: 1.4rem; flex-shrink: 0; }

.video-item-name {
    font-weight: 600;
    font-size: 0.95rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ---- Drag handle (puntini) ---- */
.drag-handle {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 3px;
    padding: 4px;
    cursor: grab;
    flex-shrink: 0;
    opacity: 0.4;
    transition: opacity 0.2s;
    border-radius: 4px;
}

.drag-handle:hover { opacity: 1; }
.drag-handle:active { cursor: grabbing; }

.drag-handle span {
    width: 4px;
    height: 4px;
    background: #636e72;
    border-radius: 50%;
    display: block;
}

/* Stato mentre si trascina */
.video-item.dragging {
    opacity: 0.4;
    border: 2px dashed var(--primary);
}


/* Evidenzia il video target durante drag-over (swap) */
.video-item.drag-over {
    border: 2px solid var(--primary);
    background: #fff5f5;
    transform: scale(1.01);
}

/* Badge ordine salvato */
.order-saved-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    color: var(--ok-color);
    font-weight: 700;
    font-size: 0.85rem;
    margin-left: 1rem;
    opacity: 0;
    transition: opacity 0.3s;
}

.order-saved-badge.show { opacity: 1; }

/* ========== RESPONSIVE ========== */
@media (max-width: 900px) {
    .top-row {
        grid-template-columns: 1fr;
    }

    .bottom-row {
        grid-template-columns: 1fr;
    }

    .counter-card {
        flex-direction: column;
        text-align: center;
        gap: 1rem;
    }
}

/* ========== TV / SCHERMI GRANDI (≥1600px) ========== */
/*
   Su televisori:
   - il browser può avere zoom diverso
   - l'overscan taglia i bordi (~3-5%)
   Compensiamo con padding di sicurezza e
   ridimensioniamo i testi in modo proporzionale.
*/
@media (min-width: 1600px) {
    /* Compensazione overscan: margine di sicurezza sui bordi */
    body.dashboard-bg {
        padding: 8px 12px;
    }

    .top-nav {
        padding: 0.3rem 1.5rem;
    }

    .logo-small {
        height: clamp(38px, 5.5vh, 65px);
    }

    .main-dashboard {
        gap: 0.5rem;
        padding: 0.5rem 1.2rem;
    }

    .dashboard-grid {
        gap: 0.8rem;
    }

    .card {
        padding: 0.9rem 1.2rem;
    }

    .card-title {
        font-size: 0.9rem;
        margin-bottom: 0.5rem;
    }

    .counter-label h2 {
        font-size: 1.1rem;
    }

    .counter-label p {
        font-size: 0.78rem;
    }

    .digital-container {
        min-width: 110px;
        padding: 0.6rem 1rem;
    }

    .calendar-legend {
        font-size: 0.72rem;
        gap: 0.8rem;
        margin-top: 0.4rem;
    }

    .color-dot {
        width: 12px;
        height: 12px;
    }

    .cal-day {
        font-size: 0.95rem;
    }

    .calendar-header {
        font-size: 0.68rem;
    }
}