/* ============================================================
   ERP — app.css
   Variables CSS custom + Layout sidebar glissière + composants
   ============================================================ */

/* ── Reset minimal ──────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; }
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
       background: var(--bg-page); color: var(--text-primary); line-height: 1.5;
       min-height: 100vh; }
a { color: var(--color-primary); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; }
button { cursor: pointer; font: inherit; }

/* ── Variables ──────────────────────────────────────────────────────────────── */
:root {
    /* Couleurs principales */
    --color-primary:     #2563EB;
    --color-primary-dk:  #1D4ED8;
    --color-primary-lt:  #EFF6FF;
    --color-danger:      #DC2626;
    --color-danger-lt:   #FEF2F2;
    --color-success:     #16A34A;
    --color-success-lt:  #F0FDF4;
    --color-warning:     #D97706;
    --color-warning-lt:  #FFFBEB;
    --color-info:        #0891B2;
    --color-info-lt:     #ECFEFF;

    /* Layout */
    --sidebar-w:         240px;
    --sidebar-collapsed: 0px;
    --topbar-h:          56px;

    /* Fonds */
    --bg-page:           #F3F4F6;
    --bg-card:           #FFFFFF;
    --bg-sidebar:        #1E293B;
    --bg-sidebar-hover:  #334155;
    --bg-sidebar-active: #2563EB;

    /* Textes */
    --text-primary:      #111827;
    --text-secondary:    #6B7280;
    --text-muted:        #9CA3AF;
    --text-sidebar:      #CBD5E1;
    --text-sidebar-muted:#64748B;

    /* Bordures */
    --border:            #E5E7EB;
    --border-focus:      #2563EB;

    /* Ombres */
    --shadow-sm:         0 1px 2px rgba(0,0,0,.05);
    --shadow:            0 1px 3px rgba(0,0,0,.10), 0 1px 2px rgba(0,0,0,.06);
    --shadow-md:         0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.06);

    /* Arrondi */
    --radius:            6px;
    --radius-lg:         10px;

    /* Transitions */
    --transition:        150ms ease;
    --sidebar-transition: 280ms cubic-bezier(.4,0,.2,1);

    /* Typographie */
    --font-mono:         'SF Mono', Consolas, 'Liberation Mono', monospace;

    /* Codes couleurs journées planning */
    --day-work:        #4CAF50;
    --day-vacation:    #2196F3;
    --day-sick:        #FF9800;
    --day-holiday:     #9C27B0;
    --day-overtime:    #00BCD4;
    --day-training:    #607D8B;
    --day-remote:      #8BC34A;
    --day-unpaid:      #9E9E9E;
    --day-accident:    #F44336;
    --day-absent:      #B71C1C;
}

/* ── Sidebar ─────────────────────────────────────────────────────────────────── */
.sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    width: var(--sidebar-w);
    background: var(--bg-sidebar);
    display: flex;
    flex-direction: column;
    transform: translateX(0);
    transition: transform var(--sidebar-transition);
    z-index: 200;
    overflow-y: auto;
    overflow-x: hidden;
}

.sidebar.collapsed { transform: translateX(calc(-1 * var(--sidebar-w))); }

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.45);
    z-index: 199;
}
.sidebar-overlay.visible { display: block; }

/* Header sidebar */
.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1rem .75rem;
    border-bottom: 1px solid rgba(255,255,255,.08);
    flex-shrink: 0;
}

.sidebar-logo {
    display: flex;
    align-items: center;
    gap: 10px;
    color: #fff;
    font-weight: 600;
    font-size: 15px;
}
.sidebar-logo .ti { font-size: 22px; color: var(--color-primary); }

.sidebar-toggle-btn {
    background: none;
    border: none;
    color: var(--text-sidebar-muted);
    font-size: 18px;
    padding: 4px;
    border-radius: var(--radius);
    display: none;
}
.sidebar-toggle-btn:hover { color: #fff; background: var(--bg-sidebar-hover); }

/* Navigation */
.sidebar-nav {
    flex: 1;
    padding: .5rem 0;
    overflow-y: auto;
}

.sidebar-group {
    font-size: 10px;
    font-weight: 600;
    letter-spacing: .08em;
    text-transform: uppercase;
    color: var(--text-sidebar-muted);
    padding: 1.2rem 1rem .4rem;
}

.sidebar-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: .55rem 1rem;
    color: var(--text-sidebar);
    font-size: 13.5px;
    border-radius: 0;
    transition: background var(--transition), color var(--transition);
    position: relative;
}
.sidebar-item .ti { font-size: 18px; flex-shrink: 0; }
.sidebar-item:hover { background: var(--bg-sidebar-hover); color: #fff; text-decoration: none; }
.sidebar-item.active {
    background: var(--bg-sidebar-active);
    color: #fff;
    font-weight: 500;
}
.sidebar-item.active::before {
    content: '';
    position: absolute;
    left: 0; top: 0; bottom: 0;
    width: 3px;
    background: #fff;
    border-radius: 0 2px 2px 0;
}

.sidebar-badge {
    margin-left: auto;
    background: rgba(255,255,255,.15);
    color: #fff;
    font-size: 11px;
    font-weight: 600;
    padding: 1px 7px;
    border-radius: 20px;
    min-width: 20px;
    text-align: center;
}
.sidebar-item.active .sidebar-badge { background: rgba(255,255,255,.25); }

/* Footer sidebar */
.sidebar-footer {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: .75rem 1rem;
    border-top: 1px solid rgba(255,255,255,.08);
    flex-shrink: 0;
}

.sidebar-user { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; }

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

.sidebar-user-info { min-width: 0; }
.sidebar-user-name { display: block; font-size: 13px; color: #fff; font-weight: 500;
                     white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-user-role { display: block; font-size: 11px; color: var(--text-sidebar-muted); }

.sidebar-logout {
    color: var(--text-sidebar-muted);
    font-size: 18px;
    padding: 6px;
    border-radius: var(--radius);
    transition: color var(--transition), background var(--transition);
    flex-shrink: 0;
}
.sidebar-logout:hover { color: var(--color-danger); background: rgba(220,38,38,.1); text-decoration: none; }

/* ── Main wrapper ──────────────────────────────────────────────────────────────── */
.main-wrapper {
    margin-left: var(--sidebar-w);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    transition: margin-left var(--sidebar-transition);
}

/* ── Topbar ──────────────────────────────────────────────────────────────────── */
.topbar {
    height: var(--topbar-h);
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 1.5rem;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow-sm);
}

.topbar-menu-btn {
    display: none;
    background: none;
    border: none;
    font-size: 22px;
    color: var(--text-secondary);
    padding: 4px;
    border-radius: var(--radius);
}
.topbar-menu-btn:hover { background: var(--bg-page); }

.topbar-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
    flex: 1;
}

.topbar-actions { display: flex; align-items: center; gap: 8px; }

/* ── Main content ─────────────────────────────────────────────────────────────── */
.main-content { flex: 1; padding: 1.5rem; }

/* ── Cards ────────────────────────────────────────────────────────────────────── */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border);
}
.card-title { font-size: 15px; font-weight: 600; color: var(--text-primary); }
.card-body  { padding: 1.25rem; }
.card-footer { padding: .75rem 1.25rem; border-top: 1px solid var(--border);
               background: var(--bg-page); border-radius: 0 0 var(--radius-lg) var(--radius-lg); }

/* ── KPI cards ────────────────────────────────────────────────────────────────── */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 1rem; }

.kpi-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.kpi-label  { font-size: 12px; font-weight: 500; color: var(--text-secondary); text-transform: uppercase; letter-spacing: .04em; }
.kpi-value  { font-size: 26px; font-weight: 700; color: var(--text-primary); line-height: 1.1; }
.kpi-sub    { font-size: 12px; color: var(--text-muted); }
.kpi-trend  { font-size: 12px; font-weight: 500; display: flex; align-items: center; gap: 3px; }
.kpi-trend.up   { color: var(--color-success); }
.kpi-trend.down { color: var(--color-danger); }

/* ── Tableaux ────────────────────────────────────────────────────────────────── */
.table-wrapper { overflow-x: auto; }

table.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}
.data-table th {
    text-align: left;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: .05em;
    padding: .65rem 1rem;
    background: var(--bg-page);
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}
.data-table td {
    padding: .75rem 1rem;
    border-bottom: 1px solid var(--border);
    color: var(--text-primary);
    vertical-align: middle;
}
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover td { background: #F9FAFB; }
.data-table td.text-right, .data-table th.text-right { text-align: right; }
.data-table td.text-center, .data-table th.text-center { text-align: center; }
.data-table td.mono { font-family: var(--font-mono); font-size: 13px; }

/* ── Formulaires ────────────────────────────────────────────────────────────── */
.form-group   { margin-bottom: 1rem; }
.form-label   { display: block; font-size: 13px; font-weight: 500; color: var(--text-primary); margin-bottom: 5px; }
.form-label .required { color: var(--color-danger); margin-left: 2px; }

.form-control {
    display: block;
    width: 100%;
    padding: .5rem .75rem;
    font-size: 14px;
    color: var(--text-primary);
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    transition: border-color var(--transition), box-shadow var(--transition);
    line-height: 1.5;
}
.form-control:focus {
    outline: none;
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px rgba(37,99,235,.15);
}
.form-control::placeholder { color: var(--text-muted); }
.form-control:disabled, .form-control[readonly] { background: var(--bg-page); color: var(--text-secondary); }

select.form-control { cursor: pointer; }
textarea.form-control { resize: vertical; min-height: 80px; }

.form-hint  { font-size: 12px; color: var(--text-muted); margin-top: 4px; }
.form-error { font-size: 12px; color: var(--color-danger); margin-top: 4px; }
.form-control.is-invalid { border-color: var(--color-danger); }

.form-row { display: grid; gap: 1rem; }
.form-row.cols-2 { grid-template-columns: 1fr 1fr; }
.form-row.cols-3 { grid-template-columns: 1fr 1fr 1fr; }
.form-row.cols-4 { grid-template-columns: repeat(4, 1fr); }

/* ── Boutons ─────────────────────────────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: .45rem 1rem;
    font-size: 14px;
    font-weight: 500;
    border-radius: var(--radius);
    border: 1px solid transparent;
    transition: background var(--transition), border-color var(--transition),
                color var(--transition), box-shadow var(--transition);
    white-space: nowrap;
    line-height: 1.4;
    text-decoration: none;
}
.btn:hover { text-decoration: none; }
.btn .ti   { font-size: 16px; }

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

.btn-secondary { background: var(--bg-card); color: var(--text-primary); border-color: var(--border); }
.btn-secondary:hover { background: var(--bg-page); }

.btn-danger    { background: var(--color-danger);  color: #fff; border-color: #B91C1C; }
.btn-danger:hover  { background: #B91C1C; }

.btn-success   { background: var(--color-success); color: #fff; border-color: #15803D; }
.btn-success:hover { background: #15803D; }

.btn-ghost     { background: transparent; color: var(--text-secondary); border-color: transparent; }
.btn-ghost:hover { background: var(--bg-page); color: var(--text-primary); }

.btn-sm   { padding: .3rem .7rem; font-size: 13px; }
.btn-sm .ti { font-size: 14px; }
.btn-lg   { padding: .65rem 1.4rem; font-size: 15px; }
.btn-icon { padding: .45rem; width: 34px; height: 34px; justify-content: center; }
.btn-icon.btn-sm { width: 28px; height: 28px; padding: .3rem; }

/* ── Badges & Statuts ────────────────────────────────────────────────────────── */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 11px;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 20px;
    white-space: nowrap;
}
.badge-success { background: var(--color-success-lt); color: var(--color-success); }
.badge-danger  { background: var(--color-danger-lt);  color: var(--color-danger);  }
.badge-warning { background: var(--color-warning-lt); color: var(--color-warning); }
.badge-info    { background: var(--color-info-lt);    color: var(--color-info);    }
.badge-neutral { background: #F3F4F6; color: var(--text-secondary); }
.badge-primary { background: var(--color-primary-lt); color: var(--color-primary); }

/* Statuts factures */
.badge-draft    { background: #F3F4F6; color: #6B7280; }
.badge-sent     { background: #EFF6FF; color: #2563EB; }
.badge-partial  { background: #FFFBEB; color: #D97706; }
.badge-paid     { background: #F0FDF4; color: #16A34A; }
.badge-overdue  { background: #FEF2F2; color: #DC2626; }
.badge-cancelled{ background: #F3F4F6; color: #9CA3AF; }

/* ── Alerts ──────────────────────────────────────────────────────────────────── */
.alert {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: .75rem 1rem;
    font-size: 14px;
    margin: 0 1.5rem .75rem;
    border-radius: var(--radius);
    border-left: 4px solid;
}
.alert .ti { font-size: 18px; flex-shrink: 0; }
.alert-close { margin-left: auto; background: none; border: none; font-size: 16px; opacity: .5; }
.alert-close:hover { opacity: 1; }

.alert-success { background: var(--color-success-lt); color: #14532D; border-color: var(--color-success); }
.alert-error   { background: var(--color-danger-lt);  color: #7F1D1D; border-color: var(--color-danger);  }
.alert-warning { background: var(--color-warning-lt); color: #78350F; border-color: var(--color-warning); }
.alert-info    { background: var(--color-info-lt);    color: #164E63; border-color: var(--color-info);    }

/* ── Planning — grille calendrier ───────────────────────────────────────────── */
.planning-grid {
    display: grid;
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
    font-size: 13px;
}

.planning-grid-header {
    display: grid;
    grid-template-columns: 160px repeat(31, 1fr);
    background: var(--bg-page);
    border-bottom: 1px solid var(--border);
}

.planning-grid-body { overflow-x: auto; }

.pg-header-cell, .pg-day-num {
    padding: 6px 2px;
    text-align: center;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-secondary);
    border-right: 1px solid var(--border);
}
.pg-header-cell:first-child { text-align: left; padding-left: 12px; }

.pg-row {
    display: grid;
    grid-template-columns: 160px repeat(31, 1fr);
    border-bottom: 1px solid var(--border);
    min-height: 44px;
}
.pg-row:last-child { border-bottom: none; }
.pg-row:hover { background: #FAFAFA; }

.pg-employee-name {
    padding: .5rem .75rem;
    font-weight: 500;
    font-size: 13px;
    border-right: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
    overflow: hidden;
}

.pg-day-cell {
    border-right: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    position: relative;
    transition: opacity var(--transition);
    min-height: 44px;
}
.pg-day-cell:hover::after {
    content: '';
    position: absolute;
    inset: 2px;
    border: 2px solid var(--color-primary);
    border-radius: 3px;
    pointer-events: none;
}
.pg-day-cell.weekend { background: #FAFAFA; }
.pg-day-cell.today   { outline: 2px solid var(--color-primary); outline-offset: -2px; }
.pg-day-cell.empty   { background: #F9FAFB; cursor: default; }
.pg-day-cell.empty:hover::after { display: none; }

/* Code couleur journées */
.day-dot {
    width: 28px;
    height: 28px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 600;
    color: #fff;
}
.day-hours {
    font-size: 10px;
    position: absolute;
    bottom: 2px;
    left: 0; right: 0;
    text-align: center;
    color: var(--text-muted);
}

/* ── Légende planning ────────────────────────────────────────────────────────── */
.planning-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: .75rem;
    background: var(--bg-page);
    border-top: 1px solid var(--border);
    font-size: 12px;
}
.legend-item { display: flex; align-items: center; gap: 5px; }
.legend-dot  { width: 14px; height: 14px; border-radius: 3px; flex-shrink: 0; }

/* ── Pagination ──────────────────────────────────────────────────────────────── */
.pagination {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: .75rem 1rem;
    border-top: 1px solid var(--border);
    font-size: 13px;
}
.page-info { color: var(--text-secondary); margin-right: auto; }
.page-link {
    padding: .35rem .7rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-size: 13px;
    background: var(--bg-card);
    transition: background var(--transition);
}
.page-link:hover { background: var(--bg-page); text-decoration: none; }
.page-link.active { background: var(--color-primary); color: #fff; border-color: var(--color-primary); }
.page-link.disabled { opacity: .4; pointer-events: none; }

/* ── Modal ───────────────────────────────────────────────────────────────────── */
.modal-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.45);
    z-index: 300;
    align-items: center;
    justify-content: center;
}
.modal-backdrop.open { display: flex; }
.modal {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    width: min(560px, 95vw);
    max-height: 90vh;
    overflow-y: auto;
    animation: modal-in .2s ease;
}
@keyframes modal-in { from { transform: scale(.95) translateY(8px); opacity:0; } to { transform:scale(1) translateY(0); opacity:1; } }
.modal-header { display: flex; align-items: center; justify-content: space-between;
                padding: 1rem 1.25rem; border-bottom: 1px solid var(--border); }
.modal-title  { font-size: 15px; font-weight: 600; }
.modal-body   { padding: 1.25rem; }
.modal-footer { padding: .75rem 1.25rem; border-top: 1px solid var(--border);
                display: flex; gap: 8px; justify-content: flex-end;
                background: var(--bg-page); border-radius: 0 0 var(--radius-lg) var(--radius-lg); }

/* ── Utilitaires ─────────────────────────────────────────────────────────────── */
.flex        { display: flex; }
.flex-center { display: flex; align-items: center; }
.flex-between{ display: flex; align-items: center; justify-content: space-between; }
.gap-1       { gap: .25rem; }
.gap-2       { gap: .5rem; }
.gap-3       { gap: .75rem; }
.gap-4       { gap: 1rem; }
.mt-1        { margin-top: .25rem; }
.mt-2        { margin-top: .5rem; }
.mt-3        { margin-top: .75rem; }
.mt-4        { margin-top: 1rem; }
.mb-4        { margin-bottom: 1rem; }
.text-right  { text-align: right; }
.text-muted  { color: var(--text-muted); }
.text-danger { color: var(--color-danger); }
.text-success{ color: var(--color-success); }
.font-mono   { font-family: var(--font-mono); }
.fw-600      { font-weight: 600; }
.d-none      { display: none; }

/* ── Responsive ──────────────────────────────────────────────────────────────── */
@media (max-width: 900px) {
    .sidebar { transform: translateX(calc(-1 * var(--sidebar-w))); }
    .sidebar.open { transform: translateX(0); }
    .main-wrapper { margin-left: 0; }
    .topbar-menu-btn { display: flex; }
    .sidebar-toggle-btn { display: block; }
    .form-row.cols-3, .form-row.cols-4 { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 600px) {
    .main-content { padding: 1rem; }
    .form-row.cols-2, .form-row.cols-3, .form-row.cols-4 { grid-template-columns: 1fr; }
    .kpi-grid { grid-template-columns: 1fr 1fr; }
    .topbar { padding: 0 1rem; }
}
