/* ===================================================
   JUDO COMPETITION MANAGER — DESIGN SYSTEM
   White Theme | Apple-inspired | App-Like Navigation
   =================================================== */

/* ===================================================
   1. CSS CUSTOM PROPERTIES
   =================================================== */
:root {
    /* Brand */
    --brand-primary: #0071e3;
    --brand-hover: #0077ed;
    --brand-light: #e8f2fc;

    --red: #ff3b30;
    --green: #34c759;
    --orange: #ff9500;

    /* Surfaces */
    --bg: #f2f2f7;
    /* System gray 6 */
    --surface: #ffffff;
    --surface-2: #f2f2f7;
    --sidebar-bg: #ffffff;

    /* Text */
    --text-primary: #1c1c1e;
    --text-secondary: #8e8e93;
    --text-tertiary: #c7c7cc;

    /* Borders */
    --border: rgba(0, 0, 0, 0.1);
    --border-light: rgba(0, 0, 0, 0.05);

    /* Shadows */
    --shadow-xs: 0 1px 3px rgba(0, 0, 0, 0.06);
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.07);
    --shadow-md: 0 4px 20px rgba(0, 0, 0, 0.09);
    --shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.12);

    /* Layout */
    --sidebar-w: 250px;
    --bottom-nav-h: 64px;
    --content-max: 1100px;
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 22px;
    --radius-pill: 9999px;

    /* Type */
    --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", sans-serif;

    /* Transitions */
    --ease: cubic-bezier(0.28, 0.11, 0.32, 1);
    --fast: 180ms;
    --mid: 300ms;
}

/* ===================================================
   2. RESET
   =================================================== */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    scroll-behavior: smooth;
}

body {
    font-family: var(--font);
    background-color: var(--bg);
    color: var(--text-primary);
    line-height: 1.5;
    min-height: 100vh;
}

a {
    color: inherit;
    text-decoration: none;
}

/* ===================================================
   3. LAYOUT — SIDEBAR + MAIN
   =================================================== */
/* Desktop */
.app-layout {
    display: flex;
    min-height: 100vh;
    overflow-x: hidden;
}

/* The sidebar nav */
.app-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: var(--sidebar-w);
    height: 100vh;
    background: var(--sidebar-bg);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    padding: 28px 16px;
    z-index: 200;
    overflow-y: auto;
    box-shadow: var(--shadow-xs);
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 8px 28px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 20px;
}

.sidebar-brand img {
    width: 40px;
    height: 40px;
    border-radius: 10px;
}

.sidebar-brand-text h2 {
    font-size: 15px;
    font-weight: 700;
    color: var(--text-primary);
    margin: 0;
    letter-spacing: -0.02em;
}

.sidebar-brand-text span {
    font-size: 12px;
    color: var(--text-secondary);
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex: 1;
}

.nav-section-label {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    padding: 0 8px;
    margin: 14px 0 6px;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 11px 12px;
    border-radius: var(--radius-md);
    font-size: 15px;
    font-weight: 500;
    color: var(--text-secondary);
    transition: background var(--fast) var(--ease),
        color var(--fast) var(--ease);
}

.nav-link svg {
    flex-shrink: 0;
    opacity: 0.7;
    transition: opacity var(--fast) var(--ease);
}

.nav-link:hover {
    background: var(--surface-2);
    color: var(--text-primary);
}

.nav-link:hover svg {
    opacity: 1;
}

.nav-link.active {
    background: var(--brand-light);
    color: var(--brand-primary);
    font-weight: 600;
}

.nav-link.active svg {
    opacity: 1;
}

/* Main content */
.app-main {
    margin-left: var(--sidebar-w);
    flex: 1;
    min-width: 0;
    /* Prevent flex overflow when content (tables) is wide */
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.page-header {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 22px 32px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    position: sticky;
    top: 0;
    z-index: 100;
}

.page-title {
    font-size: 20px;
    font-weight: 700;
    letter-spacing: -0.022em;
    color: var(--text-primary);
}

.page-subtitle {
    font-size: 13px;
    color: var(--text-secondary);
    margin-top: 2px;
}

/* Header action buttons (used in list/pesee/poule pages) */
.page-header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.page-body {
    padding: 28px 32px;
    max-width: var(--content-max);
    width: 100%;
    margin: 0 auto;
}

/* ===================================================
   4. COMPONENTS — CARD
   =================================================== */
.card {
    background: var(--surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-light);
    padding: 24px;
    margin-bottom: 20px;
}

.card-title {
    font-size: 17px;
    font-weight: 600;
    letter-spacing: -0.02em;
    margin-bottom: 16px;
    color: var(--text-primary);
}

/* ===================================================
   5. COMPONENTS — BUTTONS
   =================================================== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 20px;
    font-size: 15px;
    font-weight: 500;
    font-family: var(--font);
    line-height: 1;
    border-radius: var(--radius-pill);
    border: none;
    cursor: pointer;
    text-decoration: none;
    transition: all var(--fast) var(--ease);
    -webkit-appearance: none;
    appearance: none;
    white-space: nowrap;
}

/* Primary */
.btn {
    background: var(--brand-primary);
    color: #fff;
}

.btn:hover {
    background: var(--brand-hover);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 113, 227, 0.3);
}

.btn:active {
    transform: translateY(0);
    box-shadow: none;
}

.btn-sm {
    padding: 7px 14px;
    font-size: 13px;
}

/* Variants */
.btn-secondary {
    background: var(--surface-2);
    color: var(--text-primary);
}

.btn-secondary:hover {
    background: #e5e5ea;
    box-shadow: none;
}

.btn-danger {
    background: var(--red);
    color: #fff;
}

.btn-success {
    background: var(--green);
    color: #fff;
}

.btn-warning {
    background: var(--orange);
    color: #fff;
}

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

.btn-outline:hover {
    background: var(--brand-light);
    box-shadow: none;
    transform: none;
}

/* Grouped buttons row */
.btn-row {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 24px;
}

/* ===================================================
   6. COMPONENTS — FORMS
   =================================================== */
.form-group {
    margin-bottom: 20px;
}

label {
    display: block;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-primary);
    margin-bottom: 7px;
}

input[type="text"],
input[type="number"],
input[type="email"],
input[type="password"],
select {
    display: block;
    width: 100%;
    padding: 12px 14px;
    font-size: 16px;
    font-family: var(--font);
    background: var(--surface-2);
    border: 1.5px solid transparent;
    border-radius: var(--radius-md);
    color: var(--text-primary);
    outline: none;
    transition: border-color var(--fast), box-shadow var(--fast), background var(--fast);
    -webkit-appearance: none;
    appearance: none;
}

input:hover,
select:hover {
    border-color: var(--border);
    background: var(--surface);
}

input:focus,
select:focus {
    border-color: var(--brand-primary);
    background: var(--surface);
    box-shadow: 0 0 0 4px rgba(0, 113, 227, 0.12);
}

input::placeholder {
    color: var(--text-tertiary);
}

/* Radio / Checkbox Group */
.radio-group,
.check-group {
    display: flex;
    gap: 16px;
    flex-wrap: wrap;
    margin-top: 8px;
}

.radio-group label,
.check-group label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 400;
    cursor: pointer;
    margin-bottom: 0;
    font-size: 15px;
}

input[type="radio"],
input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: var(--brand-primary);
    cursor: pointer;
    display: inline;
}

/* Form row (two-col) */
.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

/* ===================================================
   7. COMPONENTS — TABLES
   =================================================== */
.table-wrapper {
    background: var(--surface);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-light);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
    margin-top: 20px;
}

table {
    width: 100%;
    border-collapse: collapse;
}

thead {
    background: var(--surface-2);
    border-bottom: 1px solid var(--border);
}

th {
    padding: 12px 20px;
    text-align: left;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    white-space: nowrap;
}

td {
    padding: 14px 20px;
    font-size: 15px;
    border-bottom: 1px solid var(--border-light);
    color: var(--text-primary);
}

tbody tr:last-child td {
    border-bottom: none;
}

tbody tr {
    transition: background var(--fast);
}

tbody tr:hover {
    background: var(--surface-2);
}

/* ===================================================
   8. COMPONENTS — ALERTS
   =================================================== */
.alert {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 18px;
    border-radius: var(--radius-md);
    font-size: 14px;
    font-weight: 500;
    margin-bottom: 20px;
    animation: slideIn var(--mid) var(--ease) forwards;
}

.alert-success {
    background: rgba(52, 199, 89, 0.1);
    color: #1a7a38;
    border: 1px solid rgba(52, 199, 89, 0.25);
}

.alert-error {
    background: rgba(255, 59, 48, 0.08);
    color: #c0281f;
    border: 1px solid rgba(255, 59, 48, 0.2);
}

.alert-warning {
    background: rgba(255, 149, 0, 0.1);
    color: #a05e00;
    border: 1px solid rgba(255, 149, 0, 0.2);
}

/* ===================================================
   9. COMPONENTS — MODALS
   =================================================== */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 500;
    background: rgba(0, 0, 0, 0.35);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.modal-overlay.open {
    display: flex;
}

.modal-box {
    background: var(--surface);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-lg);
    padding: 28px;
    width: 100%;
    max-width: 460px;
    animation: scaleIn var(--mid) var(--ease) forwards;
}

.modal-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    margin-bottom: 20px;
}

.modal-title {
    font-size: 18px;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.modal-close {
    background: var(--surface-2);
    border: none;
    border-radius: var(--radius-pill);
    width: 28px;
    height: 28px;
    font-size: 18px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    transition: background var(--fast);
    flex-shrink: 0;
}

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

/* ===================================================
   10. COMPONENTS — STAT CARDS (index dashbard)
   =================================================== */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.stat-card {
    background: var(--surface);
    border-radius: var(--radius-lg);
    padding: 20px;
    border: 1px solid var(--border-light);
    box-shadow: var(--shadow-sm);
    display: flex;
    align-items: center;
    gap: 16px;
}

.stat-icon {
    width: 44px;
    height: 44px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.stat-icon.blue {
    background: var(--brand-light);
    color: var(--brand-primary);
}

.stat-icon.green {
    background: rgba(52, 199, 89, 0.1);
    color: var(--green);
}

.stat-icon.orange {
    background: rgba(255, 149, 0, 0.1);
    color: var(--orange);
}

.stat-icon.red {
    background: rgba(255, 59, 48, 0.1);
    color: var(--red);
}

.stat-value {
    font-size: 26px;
    font-weight: 700;
    letter-spacing: -0.04em;
    color: var(--text-primary);
    line-height: 1;
}

.stat-label {
    font-size: 13px;
    color: var(--text-secondary);
    margin-top: 3px;
}

/* ===================================================
   11. COMPONENTS — POULE CARD
   =================================================== */
.poule-card {
    background: var(--surface);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
    margin-bottom: 16px;
    transition: box-shadow var(--fast);
}

.poule-card:hover {
    box-shadow: var(--shadow-md);
}

.poule-header {
    padding: 14px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: 600;
    font-size: 14px;
    border-bottom: 1px solid var(--border-light);
}

.poule-header.success {
    background: rgba(52, 199, 89, 0.08);
    color: #1a7a38;
}

.poule-header.warning {
    background: rgba(255, 149, 0, 0.08);
    color: #a05e00;
}

.poule-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 0 !important;
    border: none !important;
    box-shadow: none !important;
    border-radius: 0 !important;
}

.poule-table td {
    padding: 12px 20px;
    font-size: 14px;
    border-bottom: 1px solid var(--border-light);
}

.poule-table tr:last-child td {
    border-bottom: none;
}

/* ===================================================
   12. COMPONENTS — SEARCH BAR
   =================================================== */
.search-bar {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
}

.search-bar input {
    flex: 1;
}

/* ===================================================
   13. COMPONENTS — BADGE / TAG
   =================================================== */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 3px 10px;
    border-radius: var(--radius-pill);
    font-size: 12px;
    font-weight: 600;
}

.badge-blue {
    background: var(--brand-light);
    color: var(--brand-primary);
}

.badge-green {
    background: rgba(52, 199, 89, 0.1);
    color: var(--green);
}

.badge-red {
    background: rgba(255, 59, 48, 0.1);
    color: var(--red);
}

/* ===================================================
   14. BOTTOM NAV (Mobile Only — hidden on desktop)
   =================================================== */
.app-bottom-nav {
    display: none;
    /* Hidden on desktop */
}

/* ===================================================
   15. ANIMATIONS
   =================================================== */
@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateX(-8px);
    }

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

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(16px);
    }

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

@keyframes scaleIn {
    from {
        opacity: 0;
        transform: scale(0.96);
    }

    to {
        opacity: 1;
        transform: scale(1);
    }
}

.anim-up {
    animation: slideUp var(--mid) var(--ease) both;
}

/* Stagger */
.anim-up:nth-child(1) {
    animation-delay: 0ms;
}

.anim-up:nth-child(2) {
    animation-delay: 50ms;
}

.anim-up:nth-child(3) {
    animation-delay: 100ms;
}

.anim-up:nth-child(4) {
    animation-delay: 150ms;
}

.anim-up:nth-child(5) {
    animation-delay: 200ms;
}

/* ===================================================
   16. SCROLLBAR
   =================================================== */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--text-tertiary);
    border-radius: 100px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}

/* ===================================================
   17. MISC UTILITIES
   =================================================== */
.text-secondary {
    color: var(--text-secondary);
    font-size: 14px;
}

.mt-sm {
    margin-top: 8px;
}

.mt-md {
    margin-top: 16px;
}

.mt-lg {
    margin-top: 24px;
}

.mb-md {
    margin-bottom: 16px;
}

.empty-state {
    text-align: center;
    padding: 56px 24px;
    color: var(--text-secondary);
}

.empty-state svg {
    margin-bottom: 16px;
    opacity: 0.3;
}

.empty-state h3 {
    font-size: 17px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 6px;
}

.empty-state p {
    font-size: 14px;
}

/* ===================================================
   18. LIVE DASHBOARD — Derniers enregistrements
   =================================================== */

/* Card header row (title + live badge) */
.card-header-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0;
}

/* "Live" indicator badge */
.live-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    font-weight: 600;
    color: var(--green);
    background: rgba(52, 199, 89, 0.1);
    border: 1px solid rgba(52, 199, 89, 0.2);
    padding: 4px 10px;
    border-radius: var(--radius-pill);
}

/* Static green dot */
.live-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #34c759;
    flex-shrink: 0;
}

/* Skeleton / loading state */
.recent-skeleton {
    padding: 32px;
    text-align: center;
    color: var(--text-secondary);
    font-size: 14px;
}

/* Empty state inside live block */
.recent-empty {
    padding: 32px;
    text-align: center;
    color: var(--text-secondary);
    font-size: 14px;
}

/* Highlight animation for newest row */
@keyframes highlightRow {
    0% {
        background: rgba(52, 199, 89, 0.15);
    }

    100% {
        background: transparent;
    }
}

.highlight-new {
    animation: highlightRow 3s ease-out forwards;
}

/* ---- Belt/Ceinture badge colours ---- */
.badge-dark {
    background: #1c1c1e;
    color: #fff;
}

.badge-marron {
    background: #6b3b2c;
    color: #fff;
}

.badge-orange-v {
    background: #e67e22;
    color: #fff;
}

.badge-orange {
    background: rgba(255, 149, 0, 0.15);
    color: #a05e00;
}

.badge-yellow-o {
    background: rgba(255, 196, 0, 0.2);
    color: #856900;
}

.badge-yellow {
    background: rgba(255, 214, 0, 0.2);
    color: #7a6200;
}

.badge-white-j {
    background: rgba(255, 214, 0, 0.1);
    color: #7a6200;
    border: 1px solid rgba(255, 214, 0, 0.3);
}

.badge-light {
    background: var(--surface-2);
    color: var(--text-secondary);
    border: 1px solid var(--border);
}

/* The table inside the live block already uses .table-wrapper styles,
   but we reduce margin-top since it sits inside a card */
#recent-container .table-wrapper {
    margin-top: 16px;
}

/* Column visibility helpers for mobile tables */
/* Desktop: col-mobile-inline is hidden (info shown in its own column) */
.col-mobile-inline {
    display: none;
}

/* ===================================================
   18. RESPONSIVE — TABLET
   =================================================== */
@media (max-width: 1024px) {
    .form-row {
        grid-template-columns: 1fr;
    }

    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* ===================================================
   19. RESPONSIVE — MOBILE
   =================================================== */
@media (max-width: 768px) {

    /* Hide sidebar on mobile */
    .app-sidebar {
        display: none;
    }

    /* Main takes full width, pad for bottom nav + safe area */
    .app-main {
        margin-left: 0;
        padding-bottom: calc(var(--bottom-nav-h) + env(safe-area-inset-bottom, 0px));
    }

    /* Sticky header: stack title + actions vertically */
    .page-header {
        padding: 14px 16px;
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }

    /* Ensure buttons in header don't overflow */
    .page-header .btn-row {
        width: 100%;
        margin-bottom: 0;
        flex-wrap: wrap;
    }

    .page-header-actions {
        width: 100%;
        flex-wrap: wrap;
    }

    .page-header-actions .btn,
    .page-header-actions>a,
    .page-header-actions form {
        flex: 1;
        min-width: 0;
    }

    .page-header-actions form button {
        width: 100%;
        justify-content: center;
    }

    .page-header>a.btn,
    .page-header>form>button {
        width: 100%;
        justify-content: center;
    }

    .page-title {
        font-size: 20px;
    }

    .page-body {
        padding: 16px;
    }

    /* Mobile Bottom Navigation */
    .app-bottom-nav {
        display: flex;
        position: fixed;
        bottom: 0;
        left: 0;
        width: 100%;
        /* height accounts for safe area at bottom */
        height: calc(var(--bottom-nav-h) + env(safe-area-inset-bottom, 0px));
        background: rgba(249, 249, 249, 0.95);
        backdrop-filter: saturate(180%) blur(20px);
        -webkit-backdrop-filter: saturate(180%) blur(20px);
        border-top: 1px solid var(--border);
        z-index: 300;
        align-items: flex-start;
        justify-content: space-around;
        /* Top padding centers items in the nav zone, bottom padding = safe area */
        padding: 8px 4px env(safe-area-inset-bottom, 0px);
        box-shadow: 0 -1px 0 rgba(0, 0, 0, 0.08);
        /* Allow horizontal scroll if too many items */
        overflow-x: auto;
        overflow-y: hidden;
        scrollbar-width: none;
        /* Firefox */
    }

    .app-bottom-nav::-webkit-scrollbar {
        display: none;
        /* Chrome/Safari */
    }

    .bottom-nav-item {
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 2px;
        padding: 4px 8px;
        border-radius: var(--radius-md);
        color: var(--text-secondary);
        font-size: 10px;
        font-weight: 500;
        text-decoration: none;
        transition: color var(--fast), background var(--fast);
        /* Don't shrink — allow scrolling instead */
        flex: 0 0 auto;
        min-width: 56px;
        max-width: 80px;
        text-align: center;
        white-space: nowrap;
    }

    .bottom-nav-item svg {
        width: 24px;
        height: 24px;
        flex-shrink: 0;
        transition: transform var(--fast);
    }

    .bottom-nav-item:active svg {
        transform: scale(0.88);
    }

    .bottom-nav-item.active {
        color: var(--brand-primary);
    }

    /* Card adjustments */
    .card {
        padding: 16px;
    }

    /* Stats: 2 columns on medium mobile, 1 on very small */
    .stats-grid {
        grid-template-columns: 1fr 1fr;
        gap: 10px;
    }

    .stat-card {
        padding: 12px;
        gap: 10px;
    }

    .stat-icon {
        width: 38px;
        height: 38px;
    }

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

    .stat-label {
        font-size: 12px;
    }

    /* Table: horizontal scroll uniquement si le contenu déborde vraiment */
    .table-wrapper {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* Pas de min-width forcé : les colonnes cachées (col-mobile-hide)
       s'occupent de réduire le tableau sur mobile */
    table {
        min-width: 0;
    }

    /* Poule table is narrower — don't force min-width */
    .poule-table {
        min-width: 0;
    }

    /* Poule header: wrap text properly */
    .poule-header {
        flex-wrap: wrap;
        gap: 4px;
        padding: 12px 14px;
        font-size: 13px;
    }

    .btn-row {
        gap: 8px;
    }

    /* Make form submit buttons full-width for easier touch */
    .btn-row .btn {
        flex: 1;
        min-width: 120px;
        justify-content: center;
    }

    .search-bar {
        flex-direction: column;
    }

    .search-bar .btn {
        width: 100%;
        justify-content: center;
    }

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

    .modal-box {
        padding: 20px;
        border-radius: var(--radius-lg);
        /* Prevent modal from going off-screen */
        max-height: calc(100dvh - 40px);
        overflow-y: auto;
    }

    h1,
    .page-title {
        font-size: 20px;
    }

    th,
    td {
        padding: 10px 12px;
        font-size: 14px;
    }

    th {
        font-size: 11px;
    }

    /* Hide secondary table columns on mobile to avoid horizontal scroll */
    .col-mobile-hide {
        display: none;
    }

    /* Show inline fallback (e.g. first name appended in the Nom cell) */
    .col-mobile-inline {
        display: inline;
        font-weight: 400;
        color: var(--text-secondary);
    }
}

/* Very small phones (iPhone SE, Galaxy A series) */
@media (max-width: 390px) {

    .stats-grid {
        grid-template-columns: 1fr;
    }

    .page-header {
        padding: 12px 14px;
    }

    .page-body {
        padding: 12px;
    }

    .card {
        padding: 14px;
    }

    .bottom-nav-item {
        min-width: 48px;
        font-size: 9px;
    }
}

@media print {

    .app-sidebar,
    .app-bottom-nav,
    .page-header,
    .btn-row {
        display: none !important;
    }

    .app-main {
        margin-left: 0 !important;
    }

    .page-body {
        padding: 0 !important;
    }

    body {
        background: white;
    }
}

/* ===================================================
   21. SIDEBAR — FOOTER / USER BLOCK
   =================================================== */
/* Note: display:flex is already set in section 3; only add flex-direction here
   to avoid overriding the mobile display:none media query rule */
.app-sidebar {
    flex-direction: column;
}

.sidebar-nav {
    flex: 1;
}

.sidebar-footer {
    padding: 12px 16px;
    border-top: 1px solid var(--border-light);
    margin-top: auto;
}

.sidebar-user {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 0 12px;
}

.sidebar-user-avatar {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-pill);
    background: var(--brand-primary);
    color: #fff;
    font-size: 15px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.sidebar-user-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.sidebar-user-name {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-user-role {
    font-size: 11px;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: var(--radius-pill);
    display: inline-block;
    width: fit-content;
}

.sidebar-user-role.role-admin {
    background: rgba(0, 113, 227, 0.1);
    color: var(--brand-primary);
}

.sidebar-user-role.role-operateur {
    background: rgba(255, 149, 0, 0.1);
    color: var(--orange);
}

.nav-logout {
    color: var(--red) !important;
    margin-top: 4px;
}

.nav-logout:hover {
    background: rgba(255, 59, 48, 0.08) !important;
    color: var(--red) !important;
}

/* Nav link danger (Reset DB) */
.nav-link-danger {
    color: var(--red) !important;
}

.nav-link-danger:hover {
    background: rgba(255, 59, 48, 0.08) !important;
    color: var(--red) !important;
}

.nav-link-danger.active {
    background: rgba(255, 59, 48, 0.12) !important;
    color: var(--red) !important;
}

/* Nav link success (TV Screen) */
.nav-link-success {
    color: var(--green) !important;
}

.nav-link-success:hover {
    background: rgba(52, 199, 89, 0.08) !important;
    color: var(--green) !important;
}

.nav-link-success.active {
    background: rgba(52, 199, 89, 0.12) !important;
    color: var(--green) !important;
}

/* Danger card (reset page) */
.danger-card {
    border: 1px solid rgba(220, 38, 38, 0.25);
    background: rgba(255, 59, 48, 0.03);
}

/* Mobile logout item */
.bottom-nav-logout {
    color: var(--red) !important;
}

.bottom-nav-logout.active,
.bottom-nav-logout:hover {
    color: var(--red) !important;
}

/* ===================================================
   22. LOGIN PAGE
   =================================================== */
.login-body {
    background: var(--surface-2);
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px 16px;
}

.login-container {
    width: 100%;
    max-width: 420px;
}

.login-card {
    background: var(--surface);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-lg);
    padding: 40px 36px;
    border: 1px solid var(--border-light);
    animation: scaleIn var(--mid) var(--ease) both;
}

.login-brand {
    text-align: center;
    margin-bottom: 32px;
}

.login-logo {
    width: 72px;
    height: 72px;
    object-fit: contain;
    border-radius: var(--radius-lg);
    margin-bottom: 12px;
}

.login-title {
    font-size: 24px;
    font-weight: 700;
    letter-spacing: -0.03em;
    color: var(--text-primary);
    margin: 0 0 4px;
}

.login-subtitle {
    font-size: 14px;
    color: var(--text-secondary);
    margin: 0;
}

.login-form {
    margin-bottom: 24px;
}

.login-btn {
    width: 100%;
    padding: 13px 20px;
    font-size: 16px;
    margin-top: 8px;
}

.login-hint {
    border-top: 1px solid var(--border-light);
    padding-top: 20px;
}

.login-hint p {
    font-size: 12px;
    color: var(--text-secondary);
    text-align: center;
    margin-bottom: 10px;
}

.login-roles {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.login-role-badge {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 9px 14px;
    border-radius: var(--radius-md);
    font-size: 13px;
    font-weight: 500;
}

.admin-badge {
    background: rgba(0, 113, 227, 0.07);
    color: var(--brand-primary);
    border: 1px solid rgba(0, 113, 227, 0.15);
}

.op-badge {
    background: rgba(255, 149, 0, 0.07);
    color: var(--orange);
    border: 1px solid rgba(255, 149, 0, 0.15);
}

@media (max-width: 480px) {
    .login-card {
        padding: 28px 20px;
    }
}

/* ===================================================
   19. RECHERCHE LIVE — Page pesée
   =================================================== */

/* Wrapper global positionné pour le dropdown */
.live-search-wrapper {
    position: relative;
    margin-bottom: 8px;
}

/* Champ + icône + clear */
.live-search-input-wrap {
    position: relative;
    display: flex;
    align-items: center;
}

.live-search-icon {
    position: absolute;
    left: 14px;
    color: var(--text-secondary);
    pointer-events: none;
    flex-shrink: 0;
}

.live-search-input-wrap input[type="text"] {
    width: 100%;
    padding-left: 42px;
    padding-right: 42px;
    border-radius: var(--radius-pill);
    /* 16px minimum pour éviter le zoom automatique sur iOS/Android */
    font-size: 16px;
    transition: border-color var(--fast), box-shadow var(--fast);
}

.live-search-input-wrap input[type="text"]:focus {
    border-color: var(--brand-primary);
    box-shadow: 0 0 0 4px rgba(0, 113, 227, 0.12);
}

/* Bouton effacer ✕ */
.search-clear-btn {
    position: absolute;
    right: 12px;
    background: var(--surface-2);
    border: none;
    border-radius: 50%;
    width: 22px;
    height: 22px;
    font-size: 12px;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background var(--fast), color var(--fast);
    line-height: 1;
}

.search-clear-btn:hover {
    background: var(--border);
    color: var(--text-primary);
}

/* Dropdown suggestions */
.search-dropdown {
    display: none;
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    right: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
    z-index: 300;
    overflow: hidden;
    animation: slideUp var(--fast) var(--ease) both;
}

.search-dropdown.open {
    display: block;
}

/* Item suggestion */
.search-suggestion {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 11px 16px;
    cursor: pointer;
    border-bottom: 1px solid var(--border-light);
    transition: background var(--fast);
}

.search-suggestion:last-child {
    border-bottom: none;
}

.search-suggestion:hover {
    background: var(--surface-2);
}

.sugg-name {
    font-size: 14px;
    font-weight: 500;
    color: var(--text-primary);
}

.sugg-club {
    font-size: 12px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 160px;
}

/* Surbrillance des termes cherchés */
mark {
    background: rgba(0, 113, 227, 0.15);
    color: var(--brand-primary);
    border-radius: 2px;
    padding: 0 1px;
    font-style: normal;
}

/* Badge nombre de résultats */
.result-count-badge {
    display: inline-block;
    font-size: 12px;
    font-weight: 600;
    padding: 3px 10px;
    border-radius: var(--radius-pill);
    background: var(--brand-light);
    color: var(--brand-primary);
    margin-bottom: 12px;
}

.result-count-badge.badge-zero {
    background: rgba(255, 59, 48, 0.08);
    color: var(--red);
}

/* ===================================================
   PANIC BUTTON & ALERT CARD
   =================================================== */

/* ── Sidebar Panic Button ────────────────────────────────────────────────── */
.sidebar-panic {
    padding: 12px 8px;
    margin-top: 12px;
}

.btn-panic {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    width: 100%;
    padding: 14px 20px;
    font-size: 15px;
    font-weight: 700;
    font-family: var(--font);
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: #fff;
    background: var(--red);
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--fast) var(--ease);
    animation: panicPulse 2s ease-in-out infinite;
    box-shadow: 0 4px 15px rgba(255, 59, 48, 0.35);
}

.btn-panic:hover {
    background: #e0342a;
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(255, 59, 48, 0.45);
}

.btn-panic:active {
    transform: translateY(0);
    box-shadow: 0 2px 8px rgba(255, 59, 48, 0.3);
}

.btn-panic-sent {
    background: var(--green) !important;
    animation: none !important;
    box-shadow: 0 4px 15px rgba(52, 199, 89, 0.35) !important;
}

@keyframes panicPulse {

    0%,
    100% {
        box-shadow: 0 4px 15px rgba(255, 59, 48, 0.35);
    }

    50% {
        box-shadow: 0 4px 25px rgba(255, 59, 48, 0.55);
    }
}

/* ── Alert Card (Dashboard) ──────────────────────────────────────────────── */
.stat-card.alert-ok {
    border: 1.5px solid rgba(52, 199, 89, 0.3);
    background: linear-gradient(135deg, rgba(52, 199, 89, 0.04), var(--surface));
}

.stat-card.alert-danger {
    border: 1.5px solid rgba(255, 59, 48, 0.4);
    background: linear-gradient(135deg, rgba(255, 59, 48, 0.06), var(--surface));
    box-shadow: 0 2px 8px rgba(255, 59, 48, 0.1);
}

/* Static Alert Dot */
.alert-dot {
    display: block;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--red);
}

/* ── Alert Operator Names ────────────────────────────────────────────────── */
.alert-names {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    font-size: 15px !important;
}

.alert-operator {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 2px 10px;
    background: rgba(255, 59, 48, 0.1);
    color: var(--red);
    border-radius: var(--radius-pill);
    font-size: 13px;
    font-weight: 600;
}

/* ── Resolve Button ──────────────────────────────────────────────────────── */
.btn-resolve {
    background: var(--green);
    color: #fff;
    font-size: 12px;
    padding: 5px 12px;
    border-radius: var(--radius-pill);
    border: none;
    cursor: pointer;
    font-weight: 600;
    transition: all var(--fast);
}

.btn-resolve:hover {
    background: #2db84e;
    transform: translateY(-1px);
    box-shadow: 0 3px 10px rgba(52, 199, 89, 0.3);
}

/* ── Mobile Bottom Nav Panic ─────────────────────────────────────────────── */
.bottom-nav-panic {
    color: var(--red) !important;
}

.bottom-nav-panic svg {
    stroke: var(--red) !important;
    opacity: 1 !important;
}

.bottom-nav-panic span {
    color: var(--red) !important;
    font-weight: 600;
}