/* ============================================================
   UNC — Gestion des Visiteurs
   Cellule Accueil, Orientation et Inscription
   Identité visuelle institutionnelle
   ============================================================ */

:root {
    --unc-blue: #2C5CA8;
    --unc-navy: #152A4E;
    --unc-white: #FFFFFF;
    --unc-gray-light: #F5F7FA;
    --unc-gray: #E2E8F0;
    --unc-gray-dark: #64748B;
    --unc-accent: #D4A843;
    --unc-success: #16A34A;
    --unc-danger: #DC2626;
    --unc-warning: #D97706;
    --unc-info: #0284C7;
    --shadow-sm: 0 1px 3px rgba(21, 42, 78, 0.08);
    --shadow-md: 0 4px 12px rgba(21, 42, 78, 0.12);
    --shadow-lg: 0 8px 24px rgba(21, 42, 78, 0.16);
    --radius: 8px;
    --radius-lg: 12px;
    --sidebar-width: 260px;
    --topbar-height: 64px;
    --font: 'Segoe UI', system-ui, -apple-system, sans-serif;
    --transition: 0.2s ease;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* Le reset ci-dessus annule le margin:auto que le navigateur applique aux <dialog> :
   sans cette règle, toutes les modales s'affichent collées en haut à gauche. */
dialog { margin: auto; }

html { font-size: 16px; scroll-behavior: smooth; }

body {
    font-family: var(--font);
    background: var(--unc-gray-light);
    color: var(--unc-navy);
    line-height: 1.5;
    min-height: 100vh;
}

a { color: var(--unc-blue); text-decoration: none; transition: color var(--transition); }
a:hover { color: var(--unc-navy); }

/* ---- AUTH PAGE ---- */
.auth-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: linear-gradient(135deg, var(--unc-navy) 0%, var(--unc-blue) 100%);
}

.login-container { width: 100%; max-width: 440px; padding: 1.5rem; }

.login-card {
    background: var(--unc-white);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: 2.5rem 2rem;
}

.login-header { text-align: center; margin-bottom: 2rem; }

.login-logo {
    width: 90px;
    height: 90px;
    object-fit: contain;
    margin-bottom: 1rem;
}

.login-title {
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--unc-navy);
    letter-spacing: 0.03em;
    text-transform: uppercase;
    line-height: 1.4;
}

.login-subtitle {
    font-size: 1rem;
    color: var(--unc-blue);
    font-weight: 600;
    margin-top: 0.5rem;
}

.login-form { display: flex; flex-direction: column; gap: 1.25rem; }

.login-footer {
    text-align: center;
    margin-top: 1.5rem;
    font-size: 0.8rem;
    color: var(--unc-gray-dark);
}

/* ---- TOPBAR ---- */
.topbar {
    position: fixed;
    top: 0; left: 0; right: 0;
    height: var(--topbar-height);
    background: var(--unc-navy);
    color: var(--unc-white);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.5rem;
    z-index: 100;
    box-shadow: var(--shadow-md);
}

.topbar-brand { display: flex; align-items: center; gap: 0.75rem; }

.topbar-logo { width: 40px; height: 40px; object-fit: contain; }

.topbar-titles { display: flex; flex-direction: column; }

.topbar-app { font-weight: 700; font-size: 0.95rem; }

.topbar-sub { font-size: 0.75rem; opacity: 0.8; }

.topbar-user { display: flex; align-items: center; gap: 1rem; font-size: 0.875rem; }

.user-name { font-weight: 600; }
.user-role { opacity: 0.7; font-size: 0.8rem; }

/* ---- LAYOUT ---- */
.app-layout {
    display: flex;
    padding-top: var(--topbar-height);
    min-height: 100vh;
}

.sidebar {
    position: fixed;
    top: var(--topbar-height);
    left: 0;
    width: var(--sidebar-width);
    height: calc(100vh - var(--topbar-height));
    background: var(--unc-white);
    border-right: 1px solid var(--unc-gray);
    overflow-y: auto;
    z-index: 50;
}

.sidebar-nav { padding: 1rem 0.75rem; display: flex; flex-direction: column; gap: 0.25rem; }

.nav-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.7rem 1rem;
    border-radius: var(--radius);
    color: var(--unc-navy);
    font-size: 0.9rem;
    font-weight: 500;
    transition: all var(--transition);
}

.nav-item svg { width: 20px; height: 20px; flex-shrink: 0; }

.nav-item:hover { background: var(--unc-gray-light); color: var(--unc-blue); }

.nav-item.active {
    background: var(--unc-blue);
    color: var(--unc-white);
}

.nav-highlight {
    background: rgba(44, 92, 168, 0.08);
    color: var(--unc-blue);
    font-weight: 600;
}

.nav-highlight:hover { background: rgba(44, 92, 168, 0.15); }

.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    padding: 1.5rem 2rem;
    max-width: 1400px;
}

/* ---- PAGE HEADER ---- */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
    gap: 1rem;
}

.page-header h1 { font-size: 1.5rem; font-weight: 700; color: var(--unc-navy); }

.page-desc { color: var(--unc-gray-dark); font-size: 0.9rem; width: 100%; margin-top: -0.5rem; }

/* ---- STATS ---- */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.stats-grid-3 { grid-template-columns: repeat(3, 1fr); }
.stats-grid-4 { grid-template-columns: repeat(4, 1fr); }

.stat-card {
    background: var(--unc-white);
    border-radius: var(--radius);
    padding: 1.25rem;
    box-shadow: var(--shadow-sm);
    border-left: 4px solid var(--unc-blue);
}

.stat-card.stat-present { border-left-color: var(--unc-success); }

.stat-value { font-size: 2rem; font-weight: 700; color: var(--unc-navy); line-height: 1; }

.stat-label { font-size: 0.85rem; color: var(--unc-gray-dark); margin-top: 0.25rem; }

/* ---- CARDS & SECTIONS ---- */
.section { margin-bottom: 1.5rem; }

.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.75rem;
}

.section-header h2 { font-size: 1.1rem; font-weight: 600; }

.card {
    background: var(--unc-white);
    border-radius: var(--radius);
    padding: 1.25rem;
    box-shadow: var(--shadow-sm);
}

.grid-2 {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

/* ---- FORMS ---- */
.form-group { margin-bottom: 1rem; }

.form-group label {
    display: block;
    font-size: 0.85rem;
    font-weight: 600;
    margin-bottom: 0.35rem;
    color: var(--unc-navy);
}

.required { color: var(--unc-danger); }

.form-control {
    width: 100%;
    padding: 0.6rem 0.85rem;
    border: 1px solid var(--unc-gray);
    border-radius: var(--radius);
    font-size: 0.95rem;
    font-family: inherit;
    color: var(--unc-navy);
    background: var(--unc-white);
    transition: border-color var(--transition), box-shadow var(--transition);
}

.form-control:focus {
    outline: none;
    border-color: var(--unc-blue);
    box-shadow: 0 0 0 3px rgba(44, 92, 168, 0.15);
}

.form-control-lg { padding: 0.75rem 1rem; font-size: 1rem; }

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

.form-card {
    background: var(--unc-white);
    border-radius: var(--radius);
    padding: 1.5rem;
    box-shadow: var(--shadow-sm);
    margin-bottom: 1rem;
}

.form-section-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--unc-blue);
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 2px solid var(--unc-gray-light);
}

.form-actions {
    display: flex;
    gap: 0.75rem;
    justify-content: flex-end;
    margin-top: 1rem;
}

.form-hint { font-size: 0.8rem; color: var(--unc-gray-dark); margin-top: 0.5rem; }

.inline-form { display: inline; }

.filter-form { margin-bottom: 1rem; }

.filter-row {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    align-items: center;
}

.filter-row .form-control { width: auto; min-width: 140px; flex: 1; }

.search-form { margin-bottom: 1.5rem; }

.search-input-group {
    display: flex;
    gap: 0.5rem;
}

.search-input-group .form-control { flex: 1; }

.inline-add-form {
    display: flex;
    gap: 0.5rem;
    margin-top: 1rem;
}

.inline-add-form .form-control { flex: 1; }

/* ---- BUTTONS ---- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 44px;
    gap: 0.4rem;
    padding: 0.55rem 1.1rem;
    border: none;
    border-radius: var(--radius);
    font-size: 0.875rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: all var(--transition);
    text-decoration: none;
    white-space: nowrap;
}

.btn-primary {
    background: var(--unc-blue);
    color: var(--unc-white);
}

.btn-primary:hover { background: var(--unc-navy); color: var(--unc-white); }

.btn-success { background: var(--unc-success); color: var(--unc-white); }
.btn-success:hover { background: #15803D; color: var(--unc-white); }

.btn-outline {
    background: transparent;
    color: var(--unc-blue);
    border: 1px solid var(--unc-blue);
}

.btn-outline:hover { background: var(--unc-blue); color: var(--unc-white); }

.topbar .btn-outline {
    color: var(--unc-white);
    border-color: rgba(255,255,255,0.4);
}

.topbar .btn-outline:hover { background: rgba(255,255,255,0.15); color: var(--unc-white); }

.btn-sm { padding: 0.35rem 0.75rem; font-size: 0.8rem; }
.btn-lg { padding: 0.75rem 1.5rem; font-size: 1rem; }
.btn-block { width: 100%; }

/* ---- TABLE ---- */
.table-responsive { overflow-x: auto; border-radius: var(--radius); box-shadow: var(--shadow-sm); }

.table {
    width: 100%;
    border-collapse: collapse;
    background: var(--unc-white);
    font-size: 0.875rem;
}

.table th {
    background: var(--unc-navy);
    color: var(--unc-white);
    padding: 0.7rem 1rem;
    text-align: left;
    font-weight: 600;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    white-space: nowrap;
}

.table td { padding: 0.65rem 1rem; border-bottom: 1px solid var(--unc-gray-light); }

.table tbody tr:hover { background: rgba(44, 92, 168, 0.04); }

.highlight-row { background: rgba(44, 92, 168, 0.08) !important; }

.actions-cell { display: flex; gap: 0.5rem; flex-wrap: wrap; }

/* ---- BADGES ---- */
.badge {
    display: inline-block;
    padding: 0.2rem 0.6rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
}

.badge-present { background: #DCFCE7; color: #166534; }
.badge-terminee { background: var(--unc-gray-light); color: var(--unc-gray-dark); }
.badge-default { background: var(--unc-gray); color: var(--unc-navy); }
.badge-lg { font-size: 0.85rem; padding: 0.35rem 0.85rem; }

/* ---- ALERTS ---- */
.alert {
    padding: 0.85rem 1rem;
    border-radius: var(--radius);
    margin-bottom: 1rem;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.alert-success { background: #DCFCE7; color: #166534; border: 1px solid #BBF7D0; }
.alert-error { background: #FEE2E2; color: #991B1B; border: 1px solid #FECACA; }
.alert-info { background: #E0F2FE; color: #075985; border: 1px solid #BAE6FD; }

.alert-close {
    background: none; border: none; font-size: 1.2rem;
    cursor: pointer; opacity: 0.6; color: inherit;
}

/* ---- RANK LIST ---- */
.rank-list { list-style: none; }

.rank-list li {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--unc-gray-light);
}

.rank {
    width: 28px; height: 28px;
    background: var(--unc-blue);
    color: var(--unc-white);
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 0.75rem; font-weight: 700;
    flex-shrink: 0;
}

.rank-label { flex: 1; }
.rank-value { font-weight: 700; color: var(--unc-blue); }

/* ---- DETAIL LIST ---- */
.detail-list { display: grid; grid-template-columns: 140px 1fr; gap: 0.5rem 1rem; }
.detail-list dt { font-weight: 600; color: var(--unc-gray-dark); font-size: 0.85rem; }
.detail-list dd { font-size: 0.95rem; }

/* ---- CHART ---- */
.chart-bars {
    display: flex;
    align-items: flex-end;
    gap: 0.5rem;
    height: 200px;
    padding-top: 1rem;
}

.chart-bar-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    height: 100%;
    justify-content: flex-end;
}

.chart-bar {
    width: 100%;
    max-width: 40px;
    background: linear-gradient(to top, var(--unc-blue), #4A7BC8);
    border-radius: 4px 4px 0 0;
    min-height: 4px;
    transition: height 0.3s ease;
}

.chart-label { font-size: 0.7rem; color: var(--unc-gray-dark); margin-top: 0.35rem; }
.chart-value { font-size: 0.75rem; font-weight: 700; color: var(--unc-navy); }

/* ---- PAGINATION ---- */
.pagination { display: flex; gap: 0.35rem; margin-top: 1rem; flex-wrap: wrap; }

.page-link {
    padding: 0.4rem 0.75rem;
    border: 1px solid var(--unc-gray);
    border-radius: var(--radius);
    font-size: 0.85rem;
    color: var(--unc-navy);
}

.page-link.active, .page-link:hover {
    background: var(--unc-blue);
    color: var(--unc-white);
    border-color: var(--unc-blue);
}

/* ---- SUGGESTIONS (autocomplete) ---- */
.suggestions {
    position: absolute;
    top: 100%; left: 0; right: 0;
    background: var(--unc-white);
    border: 1px solid var(--unc-gray);
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    z-index: 10;
    max-height: 200px;
    overflow-y: auto;
    display: none;
}

.suggestions.active { display: block; }

.suggestion-item {
    padding: 0.6rem 0.85rem;
    cursor: pointer;
    font-size: 0.875rem;
    border-bottom: 1px solid var(--unc-gray-light);
}

.suggestion-item:hover { background: var(--unc-gray-light); }

.suggestion-item strong { color: var(--unc-navy); }

.suggestion-item small { color: var(--unc-gray-dark); display: block; }

.form-group { position: relative; }

/* ---- SETTINGS LIST ---- */
.settings-list { list-style: none; margin-bottom: 0.5rem; }

.settings-list li {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--unc-gray-light);
    font-size: 0.9rem;
}

/* ---- MISC ---- */
.empty-state { color: var(--unc-gray-dark); padding: 2rem; text-align: center; }

.empty-state-box {
    text-align: center;
    padding: 3rem;
    background: var(--unc-white);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
}

.results-count { font-size: 0.85rem; color: var(--unc-gray-dark); margin-bottom: 0.75rem; }

.text-muted { color: var(--unc-gray-dark); font-size: 0.875rem; }

.link { font-size: 0.85rem; font-weight: 600; }

.mt-3 { margin-top: 1rem; }
.mt-4 { margin-top: 1.5rem; }

code {
    background: var(--unc-gray-light);
    padding: 0.15rem 0.4rem;
    border-radius: 4px;
    font-size: 0.85rem;
}

/* ---- ERROR PAGES ---- */
.error-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: var(--unc-gray-light);
}

.error-box {
    text-align: center;
    background: var(--unc-white);
    padding: 3rem;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
}

.error-box h1 { font-size: 4rem; color: var(--unc-blue); margin-bottom: 0.5rem; }
.error-box p { color: var(--unc-gray-dark); margin-bottom: 1.5rem; }

/* ---- RESPONSIVE ---- */
@media (max-width: 1024px) {
    .stats-grid-4 { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
        transition: transform var(--transition);
    }

    .sidebar.open { transform: translateX(0); }

    .main-content { margin-left: 0; padding: 1rem; }

    .form-row { grid-template-columns: 1fr; }

    .stats-grid-3, .stats-grid-4 { grid-template-columns: 1fr 1fr; }

    .topbar-sub { display: none; }

    .filter-row .form-control { min-width: 100%; }

    .page-header { flex-direction: column; align-items: flex-start; }

    .detail-list { grid-template-columns: 1fr; }
}

@media (max-width: 480px) {
    .stats-grid, .stats-grid-3, .stats-grid-4 { grid-template-columns: 1fr; }

    .login-card { padding: 1.5rem; }

    .topbar-user .user-role { display: none; }
}
