/* ==========================================================================
   Pointage des Heures — Design system partagé
   Light + dark mode, responsive/mobile-first, composants communs.
   ========================================================================== */

:root {
    --brand-1: #667eea;
    --brand-2: #764ba2;
    --brand-grad: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    --brand-strong: #5568d3;

    --bg: #eef0f7;
    --surface: #ffffff;
    --surface-2: #f8f9fa;
    --border: #e0e0e0;
    --text: #1f2430;
    --text-muted: #666b7a;
    --shadow: 0 20px 60px rgba(0, 0, 0, 0.25);

    --ok: #10b981;
    --warn: #f59e0b;
    --danger: #ef4444;
    --danger-strong: #dc2626;
    --info: #6366f1;

    --radius: 12px;
    --radius-sm: 8px;
    --space: 20px;

    --safe-b: env(safe-area-inset-bottom, 0px);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: var(--brand-grad) fixed;
    color: var(--text);
    min-height: 100vh;
    padding: clamp(10px, 3vw, 20px);
    padding-bottom: calc(clamp(10px, 3vw, 20px) + var(--safe-b));
    line-height: 1.5;
}
body.centered { display: flex; align-items: center; justify-content: center; }

/* ---- Layout ---- */
.container {
    max-width: 1200px;
    width: 100%;
    margin: 0 auto;
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}
.container.narrow { max-width: 500px; }
.container.auth { max-width: 420px; }

.app-header {
    background: var(--brand-grad);
    color: #fff;
    padding: clamp(18px, 4vw, 30px);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 14px;
    flex-wrap: wrap;
}
.app-header h1 { font-size: clamp(1.4em, 5vw, 2em); display: flex; align-items: center; gap: 8px; }
.app-header p { opacity: 0.9; font-size: 0.95em; }
.header-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.content { padding: clamp(18px, 4vw, 30px); }

/* ---- Buttons ---- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    background: var(--brand-grad); color: #fff; border: none;
    padding: 12px 22px; border-radius: var(--radius-sm);
    font-size: 16px; font-weight: 600; cursor: pointer;
    transition: transform 0.15s, box-shadow 0.15s, background 0.2s;
    text-decoration: none; min-height: 44px; line-height: 1.1;
}
.btn:hover { transform: translateY(-2px); box-shadow: 0 6px 16px rgba(102,126,234,0.4); }
.btn:active { transform: translateY(0); }
.btn:disabled { opacity: 0.6; cursor: not-allowed; transform: none; box-shadow: none; }
.btn.block { width: 100%; }
.btn-secondary { background: #6b7280; }
.btn-secondary:hover { background: #4b5563; box-shadow: none; }
.btn-ghost {
    background: rgba(255,255,255,0.15); border: 2px solid rgba(255,255,255,0.85);
    color: #fff; padding: 9px 16px; font-size: 14px; border-radius: 6px; min-height: 40px;
    text-decoration: none; display: inline-flex; align-items: center; gap: 5px; cursor: pointer;
}
.btn-ghost:hover { background: rgba(255,255,255,0.3); box-shadow: none; }
.btn-ok { background: var(--ok); }
.btn-ok:hover { background: #059669; box-shadow: none; }
.btn-warn { background: var(--warn); }
.btn-danger { background: var(--danger); }
.btn-danger:hover { background: var(--danger-strong); box-shadow: none; }
.btn-sm { padding: 7px 13px; font-size: 13px; min-height: 36px; }

.icon-btn {
    background: rgba(255,255,255,0.15); border: 2px solid rgba(255,255,255,0.85);
    color: #fff; width: 40px; height: 40px; border-radius: 8px; cursor: pointer;
    font-size: 17px; display: inline-flex; align-items: center; justify-content: center;
}
.icon-btn:hover { background: rgba(255,255,255,0.3); }

/* ---- Forms ---- */
.form-group { margin-bottom: var(--space); }
label { display: block; margin-bottom: 8px; color: var(--text); font-weight: 600; font-size: 15px; }
input[type="text"], input[type="number"], input[type="date"], input[type="time"],
input[type="password"], input[type="email"], select, textarea {
    width: 100%; padding: 13px 14px; border: 2px solid var(--border);
    border-radius: var(--radius-sm); font-size: 16px; /* 16px prevents iOS zoom */
    background: var(--surface); color: var(--text);
    transition: border-color 0.2s; font-family: inherit;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--brand-1); }
input:disabled, input[readonly] { background: var(--surface-2); color: var(--text-muted); cursor: not-allowed; }
.help-text { font-size: 0.85em; color: var(--text-muted); margin-top: 5px; }
.checkbox-row { display: flex; align-items: center; gap: 10px; cursor: pointer; user-select: none; }
.checkbox-row input[type="checkbox"] { width: auto; min-width: 20px; height: 20px; cursor: pointer; }
.checkbox-row label { margin: 0; cursor: pointer; }

/* ---- Cards / sections ---- */
.section { margin-bottom: 36px; }
.section h2, .section-title {
    color: var(--text); margin-bottom: var(--space); padding-bottom: 10px;
    border-bottom: 3px solid var(--brand-1);
    display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap;
}
.panel {
    background: var(--surface-2); padding: var(--space); border-radius: var(--radius-sm);
    border-left: 4px solid var(--brand-1);
}

/* ---- Stat cards ---- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 15px; margin-bottom: 30px; }
.stat-card { background: var(--brand-grad); color: #fff; padding: clamp(16px, 4vw, 25px); border-radius: var(--radius-sm); text-align: center; }
.stat-value { font-size: clamp(1.7em, 6vw, 2.4em); font-weight: 700; margin-bottom: 4px; }
.stat-label { font-size: 0.85em; opacity: 0.92; }

/* ---- Filters ---- */
.filters {
    background: var(--surface-2); padding: var(--space); border-radius: var(--radius-sm);
    margin-bottom: var(--space); display: flex; gap: 15px; flex-wrap: wrap; align-items: end;
}
.filter-group { flex: 1; min-width: 160px; }
.filter-group label { font-size: 14px; }
.filter-group input, .filter-group select { padding: 10px; font-size: 15px; }

/* ---- Badges ---- */
.badge { display: inline-block; padding: 4px 11px; border-radius: 20px; font-size: 0.82em; font-weight: 600; white-space: nowrap; }
.badge-hours { background: var(--brand-1); color: #fff; }
.badge-lunch { background: var(--warn); color: #fff; }
.badge-net { background: var(--ok); color: #fff; }
.badge-time { background: var(--info); color: #fff; }
.badge-pending { background: var(--warn); color: #fff; }
.badge-approved { background: var(--ok); color: #fff; }

/* ---- Tables (responsive: cards on mobile) ---- */
.table-wrap { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; border-radius: var(--radius-sm); }
.data-table { width: 100%; border-collapse: collapse; background: var(--surface); min-width: 520px; }
.data-table thead { background: var(--surface-2); }
.data-table th { padding: 14px; text-align: left; font-weight: 700; color: var(--text); border-bottom: 2px solid var(--border); white-space: nowrap; }
.data-table td { padding: 13px 14px; border-bottom: 1px solid var(--border); color: var(--text); }
.data-table tbody tr:hover { background: var(--surface-2); }

@media (max-width: 680px) {
    .data-table { min-width: 0; border: 0; }
    .data-table thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
    .data-table tbody tr {
        display: block; margin-bottom: 14px; border: 1px solid var(--border);
        border-radius: var(--radius-sm); background: var(--surface); padding: 6px 0; overflow: hidden;
    }
    .data-table td {
        display: flex; justify-content: space-between; align-items: center; gap: 12px;
        padding: 10px 14px; border-bottom: 1px solid var(--border); text-align: right;
    }
    .data-table tbody tr td:last-child { border-bottom: 0; }
    .data-table td::before {
        content: attr(data-label); font-weight: 700; color: var(--text-muted);
        text-align: left; flex: 0 0 45%; font-size: 0.85em;
    }
    .data-table td[data-label=""]::before { content: ""; }
    .row-actions { justify-content: flex-end; }
}

.row-actions { display: flex; gap: 6px; flex-wrap: wrap; }

/* ---- Flagged rows (duplicate / weekend, pending approval) ---- */
.data-table tbody tr.flagged td { background: rgba(239, 68, 68, 0.10); }
.data-table tbody tr.flagged:hover td { background: rgba(239, 68, 68, 0.16); }
.data-table tbody tr.flagged td:first-child { box-shadow: inset 4px 0 0 var(--danger); }
@media (max-width: 680px) {
    .data-table tbody tr.flagged { border-color: var(--danger); background: rgba(239, 68, 68, 0.08); }
    .data-table tbody tr.flagged td { background: transparent; }
    .data-table tbody tr.flagged td:first-child { box-shadow: none; }
}
.flag-tip { position: relative; display: inline-flex; align-items: center; cursor: help; }
.flag-badge {
    display: inline-flex; align-items: center; gap: 4px; padding: 4px 10px; border-radius: 20px;
    font-size: 0.8em; font-weight: 700; background: var(--danger); color: #fff; white-space: nowrap;
}
.flag-tip .tip {
    visibility: hidden; opacity: 0; position: absolute; bottom: 130%; left: 50%; transform: translateX(-50%);
    background: #1f2430; color: #fff; padding: 9px 12px; border-radius: 8px; font-size: 0.82em; font-weight: 500;
    width: max-content; max-width: 240px; white-space: normal; text-align: left; line-height: 1.4;
    z-index: 60; transition: opacity 0.15s; box-shadow: 0 8px 20px rgba(0,0,0,0.3); pointer-events: none;
}
.flag-tip .tip::after {
    content: ''; position: absolute; top: 100%; left: 50%; transform: translateX(-50%);
    border: 6px solid transparent; border-top-color: #1f2430;
}
.flag-tip:hover .tip, .flag-tip:focus .tip, .flag-tip:active .tip { visibility: visible; opacity: 1; }

/* ---- Empty state ---- */
.empty-state { text-align: center; padding: 50px 20px; color: var(--text-muted); }
.empty-state-icon { font-size: 3.5em; margin-bottom: 15px; }

/* ---- Collapsible ---- */
.section-toggle {
    background: none; border: none; color: var(--brand-1); font-size: 0.9em;
    cursor: pointer; padding: 6px 0; font-weight: 600;
}
.section-toggle:hover { color: var(--brand-strong); }
.collapsible-content { display: none; margin-top: 15px; }
.collapsible-content.show { display: block; }

/* ---- Modals ---- */
.modal {
    display: none; position: fixed; inset: 0; z-index: 1000; overflow: auto;
    background: rgba(0,0,0,0.55); align-items: flex-start; justify-content: center;
    padding: 20px; padding-bottom: calc(20px + var(--safe-b));
}
.modal.open { display: flex; animation: fadeIn 0.2s; }
.modal-content {
    background: var(--surface); color: var(--text); margin: 5vh auto; padding: clamp(20px, 5vw, 30px);
    border-radius: var(--radius); width: 100%; max-width: 560px; box-shadow: var(--shadow);
    animation: slideUp 0.25s;
}
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; gap: 12px; }
.modal-header h2 { color: var(--text); margin: 0; font-size: 1.4em; }
.modal-close { color: var(--text-muted); font-size: 28px; font-weight: bold; cursor: pointer; background: none; border: none; line-height: 1; }
.modal-close:hover { color: var(--text); }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; margin-top: 20px; }

/* ---- Toasts ---- */
#toast-container {
    position: fixed; left: 50%; transform: translateX(-50%);
    bottom: calc(20px + var(--safe-b)); z-index: 3000;
    display: flex; flex-direction: column; gap: 10px; width: min(420px, calc(100% - 24px));
}
.toast {
    background: #1f2430; color: #fff; padding: 14px 18px; border-radius: 10px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.35); font-weight: 600; font-size: 0.95em;
    display: flex; align-items: center; gap: 10px; animation: slideUp 0.25s;
    border-left: 5px solid var(--brand-1);
}
.toast.ok { border-left-color: var(--ok); }
.toast.error { border-left-color: var(--danger); }
.toast.warn { border-left-color: var(--warn); }
.toast .toast-icon { font-size: 1.2em; }

/* ---- Notification banner/modal ---- */
.notif-modal-header { font-size: 1.4em; font-weight: bold; color: var(--text); margin-bottom: 12px; padding-right: 30px; }
.notif-modal-message { font-size: 1em; color: var(--text-muted); line-height: 1.6; white-space: pre-wrap; word-wrap: break-word; }
.notif-nav { display: flex; justify-content: space-between; align-items: center; margin-top: 18px; gap: 10px; }
.notif-dots { display: flex; gap: 6px; }
.notif-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--border); }
.notif-dot.active { background: var(--brand-1); }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { transform: translateY(14px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

/* ---- Autocomplete ---- */
.autocomplete { position: relative; }
.autocomplete-items {
    position: absolute; top: 100%; left: 0; right: 0; z-index: 99; max-height: 220px; overflow-y: auto;
    background: var(--surface); border: 2px solid var(--border); border-top: none;
    border-radius: 0 0 var(--radius-sm) var(--radius-sm); box-shadow: 0 8px 18px rgba(0,0,0,0.15);
}
.autocomplete-items div { padding: 12px 14px; cursor: pointer; border-bottom: 1px solid var(--border); color: var(--text); }
.autocomplete-items div:hover, .autocomplete-active { background: var(--brand-1); color: #fff; }
.employee-number { color: var(--text-muted); font-size: 0.9em; margin-left: 8px; }
.autocomplete-active .employee-number { color: rgba(255,255,255,0.85); }

/* ---- Print ---- */
@media print {
    body { background: #fff; padding: 0; }
    .container { box-shadow: none; max-width: 100%; }
    .app-header { background: #fff !important; color: #000 !important; -webkit-print-color-adjust: exact; }
    .no-print, .header-actions, .filters, .section-toggle, .btn, .row-actions, #toast-container { display: none !important; }
    .data-table { min-width: 0; }
    .badge { border: 1px solid #ccc; color: #000 !important; background: #fff !important; }
    .stat-card { background: #f0f0f0 !important; color: #000 !important; -webkit-print-color-adjust: exact; }
}
