:root {
    --color-primary: #4f46e5;
    --color-primary-dark: #4338ca;
    --color-green: #16a34a;
    --color-green-bg: #dcfce7;
    --color-orange: #ea580c;
    --color-orange-bg: #ffedd5;
    --color-red: #dc2626;
    --color-red-bg: #fee2e2;
    --color-gray: #6b7280;
    --color-gray-bg: #f3f4f6;
    --color-bg: #f8fafc;
    --color-card: #ffffff;
    --color-border: #e5e7eb;
    --color-text: #111827;
    --color-text-muted: #6b7280;
    --radius: 14px;
    --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
}

* { box-sizing: border-box; }
body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    background: var(--color-bg);
    color: var(--color-text);
    -webkit-font-smoothing: antialiased;
}
a { color: var(--color-primary); text-decoration: none; }

/* ---------- Boutons ---------- */
.btn-primary, .btn-secondary, .btn-link {
    display: inline-flex; align-items: center; justify-content: center;
    border: none; border-radius: 10px; cursor: pointer; font-weight: 600;
    font-size: 15px; padding: 12px 20px; transition: 0.15s ease;
}
.btn-primary { background: var(--color-primary); color: #fff; }
.btn-primary:hover { background: var(--color-primary-dark); }
.btn-secondary { background: #fff; color: var(--color-text); border: 1px solid var(--color-border); }
.btn-secondary:hover { background: var(--color-gray-bg); }
.btn-small { padding: 8px 14px; font-size: 13px; }
.btn-large { width: 100%; padding: 16px; font-size: 17px; }
.btn-link { background: none; padding: 4px 8px; font-size: 13px; color: var(--color-primary); }
.btn-link-danger { color: var(--color-red); }

/* ---------- Auth pages ---------- */
.auth-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 20px; background: linear-gradient(160deg, #eef2ff, #f8fafc); }
.auth-card { background: #fff; border-radius: 20px; padding: 40px 32px; width: 100%; max-width: 380px; box-shadow: var(--shadow); text-align: center; }
.auth-logo { font-size: 28px; font-weight: 800; margin-bottom: 4px; }
.auth-logo span { color: var(--color-primary); }
.auth-logo-img { max-width: 220px; width: 100%; height: auto; margin-bottom: 10px; }
.auth-subtitle { color: var(--color-text-muted); margin-bottom: 24px; font-size: 14px; }
.auth-card form { text-align: left; }
.auth-card label { display: block; font-size: 13px; font-weight: 600; margin: 14px 0 6px; }
.auth-card input { width: 100%; padding: 12px 14px; border: 1px solid var(--color-border); border-radius: 10px; font-size: 15px; }
.auth-card button { margin-top: 20px; width: 100%; }
.auth-switch { display: block; margin-top: 18px; font-size: 13px; }
.auth-hint { background: #eef2ff; color: var(--color-primary); font-size: 13px; padding: 10px 12px; border-radius: 10px; margin-bottom: 6px; }
.scan-hint-alt { color: #9ca3af; font-size: 12px; margin-top: 24px; line-height: 1.5; }
.form-error { color: var(--color-red); font-size: 13px; margin-top: 10px; }

/* ---------- Layout admin ---------- */
.sidebar {
    position: fixed; top: 0; left: 0; bottom: 0; width: 220px;
    background: #ffffff; color: #4b5563; padding: 24px 14px; display: flex; flex-direction: column; gap: 4px;
    border-right: 1px solid var(--color-border);
}
.sidebar-logo { margin-bottom: 22px; padding: 0 10px; }
.sidebar-logo img { width: 100%; max-width: 150px; height: auto; display: block; }
.sidebar a { display: flex; align-items: center; gap: 12px; color: #4b5563; padding: 10px 12px; border-radius: 10px; font-size: 14px; font-weight: 500; }
.sidebar a:hover { background: #f3f4f6; color: var(--color-text); }
.sidebar a.active { background: #eef2ff; color: var(--color-primary); font-weight: 700; }
.sidebar .nav-logout { margin-top: auto; color: var(--color-red); }
.nav-icon { display: inline-flex; width: 20px; height: 20px; flex-shrink: 0; }
.nav-icon svg { width: 100%; height: 100%; }
.main-content { margin-left: 220px; padding: 28px 32px 90px; max-width: 1100px; }
.bottom-nav { display: none; }

.page-header { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 12px; margin-bottom: 20px; }
.page-header h1 { font-size: 22px; margin: 0; }
.header-actions { display: flex; gap: 10px; align-items: center; }
.select-input { padding: 9px 12px; border-radius: 8px; border: 1px solid var(--color-border); font-size: 14px; background: #fff; }

.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 14px; margin-bottom: 22px; }
.stat-card { background: var(--color-card); border-radius: var(--radius); padding: 18px; display: flex; align-items: center; gap: 12px; box-shadow: var(--shadow); }
.stat-icon { font-size: 26px; width: 26px; height: 26px; flex-shrink: 0; }
.stat-icon svg { width: 100%; height: 100%; }
.stat-value { font-size: 22px; font-weight: 800; }
.stat-label { font-size: 12px; color: var(--color-text-muted); }
.stat-green .stat-value { color: var(--color-green); }
.stat-orange .stat-value { color: var(--color-orange); }
.stat-red .stat-value { color: var(--color-red); }

.card { background: var(--color-card); border-radius: var(--radius); padding: 22px; box-shadow: var(--shadow); margin-bottom: 20px; }
.card-title { font-size: 16px; margin: 0 0 16px; }

.table-wrap { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.data-table th { text-align: left; padding: 10px 12px; color: var(--color-text-muted); font-weight: 600; font-size: 12px; text-transform: uppercase; border-bottom: 1px solid var(--color-border); }
.data-table td { padding: 12px; border-bottom: 1px solid var(--color-border); }
.empty-row { text-align: center; color: var(--color-text-muted); padding: 30px; }
.actions-cell { white-space: nowrap; }
.mobile-cards { display: none; }

.badge { padding: 4px 10px; border-radius: 999px; font-size: 12px; font-weight: 700; }
.badge-green { background: var(--color-green-bg); color: var(--color-green); }
.badge-orange { background: var(--color-orange-bg); color: var(--color-orange); }
.badge-red { background: var(--color-red-bg); color: var(--color-red); }
.badge-gray { background: var(--color-gray-bg); color: var(--color-gray); }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-grid label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; }
.form-grid input, .form-grid select { width: 100%; padding: 10px 12px; border: 1px solid var(--color-border); border-radius: 8px; font-size: 14px; }
.form-section-title { grid-column: 1 / -1; font-size: 12px; text-transform: uppercase; color: var(--color-text-muted); font-weight: 700; margin-top: 8px; border-top: 1px solid var(--color-border); padding-top: 14px; }
.form-actions { grid-column: 1 / -1; display: flex; gap: 10px; margin-top: 6px; }
.form-map-wrap { grid-column: 1 / -1; }
.form-map-wrap label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; }
#siteMap { height: 320px; border-radius: 12px; border: 1px solid var(--color-border); z-index: 1; }
.form-map-hint { font-size: 12px; color: var(--color-text-muted); margin: 8px 0 0; }
.checkbox-row { display: flex; align-items: center; }
.checkbox-row label { display: flex; align-items: center; gap: 8px; font-weight: 500; }

.alert { padding: 12px 16px; border-radius: 10px; margin-bottom: 16px; font-size: 14px; }
.alert-success { background: var(--color-green-bg); color: var(--color-green); }
.alert-error { background: var(--color-red-bg); color: var(--color-red); }
.text-muted { color: var(--color-text-muted); font-size: 14px; line-height: 1.6; }

.profile-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; font-size: 14px; }

.qr-kiosk { text-align: center; padding: 40px 20px; }
.qr-kiosk-logo { max-width: 200px; width: 100%; height: auto; margin-bottom: 24px; }
#qrcode { display: inline-block; padding: 20px; background: #fff; border-radius: 16px; box-shadow: var(--shadow); }
.qr-timer { margin-top: 16px; font-size: 14px; color: var(--color-text-muted); }
.qr-hint { margin-top: 10px; color: var(--color-text-muted); font-size: 14px; }

.calendar-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.cal-month-title { text-transform: uppercase; }
[dir="rtl"] .cal-month-title { text-transform: none; }
.cal-dow { text-align: center; font-size: 12px; font-weight: 700; color: var(--color-text-muted); padding: 6px 0; }
.cal-cell { aspect-ratio: 1; border: 1px solid var(--color-border); border-radius: 8px; display: flex; flex-direction: column; align-items: center; justify-content: center; font-size: 12px; gap: 4px; }
.cal-empty { border: none; }
.cal-icon { font-size: 16px; }

.modal { position: fixed; inset: 0; background: rgba(0,0,0,0.4); display: flex; align-items: center; justify-content: center; z-index: 100; padding: 20px; }
.modal-box { background: #fff; border-radius: 16px; padding: 24px; width: 100%; max-width: 360px; }
.modal-box label { display: block; font-size: 13px; font-weight: 600; margin: 12px 0 6px; }
.modal-box input { width: 100%; padding: 10px 12px; border: 1px solid var(--color-border); border-radius: 8px; }
.modal-actions { display: flex; gap: 10px; margin-top: 18px; }

.toast { position: fixed; bottom: 24px; right: 24px; background: #111827; color: #fff; padding: 14px 18px; border-radius: 10px; font-size: 14px; opacity: 0; transform: translateY(10px); transition: 0.25s; pointer-events: none; z-index: 200; max-width: 320px; }
.toast.show { opacity: 1; transform: translateY(0); }

/* ---------- Sélecteur de langue (FR / AR) ---------- */
.lang-switch { display: flex; justify-content: center; gap: 6px; margin-bottom: 14px; }
.lang-switch a { font-size: 12px; font-weight: 600; padding: 5px 10px; border-radius: 999px; background: var(--color-gray-bg); color: var(--color-text-muted); }
.lang-switch a.active { background: var(--color-primary); color: #fff; }
.employee-header .lang-switch { margin-bottom: 0; }
.header-actions-right { display: flex; align-items: center; gap: 14px; }
.scan-page .lang-switch a { background: rgba(255,255,255,0.1); color: #fff; }
.scan-page .lang-switch a.active { background: #fff; color: var(--color-primary); }

/* ---------- Support RTL (arabe) — parcours employé ---------- */
[dir="rtl"] .auth-card form { text-align: right; }
[dir="rtl"] .today-summary div { align-items: flex-end; }
[dir="rtl"] .scan-btn-icon { order: 2; }

/* ---------- Support RTL (arabe) — espace admin ---------- */
[dir="rtl"] .sidebar { left: auto; right: 0; border-right: none; border-left: 1px solid var(--color-border); }
[dir="rtl"] .main-content { margin-left: 0; margin-right: 220px; }
[dir="rtl"] .sidebar .nav-logout { margin-top: auto; }
[dir="rtl"] .auth-switch { display: block; }
[dir="rtl"] .data-table th { text-align: right; }
[dir="rtl"] .actions-cell { text-align: left; }
.sidebar-lang-switch { margin: 10px 0 16px; padding-top: 14px; border-top: 1px solid var(--color-border); }
@media (max-width: 860px) {
    [dir="rtl"] .main-content { margin-right: 0; }
}

/* ---------- Espace employé ---------- */
.employee-header { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; background: #fff; box-shadow: var(--shadow); font-weight: 700; position: sticky; top: 0; z-index: 10; }
.header-logo-img { height: 26px; width: auto; }
.logout-link, .back-link { font-size: 13px; font-weight: 500; color: var(--color-text-muted); }
.employee-main { max-width: 420px; margin: 0 auto; padding: 30px 20px 60px; text-align: center; }
.greeting { font-size: 24px; margin: 10px 0 2px; }
.today-date { color: var(--color-text-muted); margin: 0 0 30px; font-size: 14px; }

.status-circle { width: 180px; height: 180px; border-radius: 50%; margin: 0 auto 26px; display: flex; flex-direction: column; align-items: center; justify-content: center; font-size: 44px; gap: 8px; box-shadow: var(--shadow); }
.status-icon { width: 56px; height: 56px; }
.status-circle div { font-size: 16px; font-weight: 800; letter-spacing: 1px; }
.status-present { background: var(--color-green-bg); color: var(--color-green); }
.status-done { background: var(--color-gray-bg); color: var(--color-gray); }
.status-none { background: var(--color-gray-bg); color: var(--color-gray); }

.today-summary { display: flex; justify-content: space-around; background: #fff; border-radius: 14px; padding: 18px; margin-bottom: 30px; box-shadow: var(--shadow); }
.today-summary div { display: flex; flex-direction: column; gap: 4px; }
.today-summary span { font-size: 11px; color: var(--color-text-muted); text-transform: uppercase; }
.today-summary strong { font-size: 17px; }

.scan-btn { display: flex; align-items: center; justify-content: center; gap: 10px; padding: 22px; border-radius: 18px; font-size: 19px; font-weight: 800; color: #fff; box-shadow: var(--shadow); }
.scan-btn-icon { width: 26px; height: 26px; flex-shrink: 0; }
.scan-btn-arrival { background: var(--color-green); }
.scan-btn-depart { background: var(--color-orange); }
.done-message { padding: 22px; background: var(--color-green-bg); color: var(--color-green); border-radius: 18px; font-weight: 700; }

.offline-banner { background: var(--color-red); color: #fff; text-align: center; padding: 10px; font-size: 13px; font-weight: 600; }

.scan-page { background: #000; min-height: 100vh; color: #fff; }
.scan-page .employee-header { background: #000; color: #fff; box-shadow: none; }
.scan-page .back-link { color: #fff; }
.scan-main { text-align: center; padding: 20px; }
.video-wrap { position: relative; width: 100%; max-width: 380px; margin: 20px auto; border-radius: 20px; overflow: hidden; aspect-ratio: 1; background: #111; }
.video-wrap video { width: 100%; height: 100%; object-fit: cover; }
.scan-frame { position: absolute; inset: 12%; border: 3px solid #fff; border-radius: 16px; box-shadow: 0 0 0 999px rgba(0,0,0,0.35); }
.scan-status { font-size: 15px; margin-top: 20px; min-height: 22px; }
.scan-status-success { color: #4ade80; font-weight: 700; }
.scan-status-error { color: #f87171; font-weight: 700; }
.scan-status-info { color: #facc15; }
.camera-fallback { padding: 20px; }
.camera-fallback input { width: 100%; padding: 12px; border-radius: 10px; border: none; margin: 12px 0; }

/* ---------- Responsive ---------- */
@media (max-width: 860px) {
    .sidebar { display: none; }
    .main-content { margin-left: 0; padding: 18px 16px 90px; }
    .bottom-nav { display: flex; position: fixed; bottom: 0; left: 0; right: 0; background: #fff; border-top: 1px solid var(--color-border); justify-content: space-around; padding: 8px 0; z-index: 50; }
    .bottom-nav a { font-size: 22px; padding: 8px 14px; border-radius: 10px; width: 24px; height: 24px; color: #6b7280; }
    .bottom-nav a.active { background: var(--color-gray-bg); color: var(--color-primary); }
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .form-grid { grid-template-columns: 1fr; }
    .profile-grid { grid-template-columns: 1fr; }
    .table-wrap { display: none; }
    .mobile-cards { display: block; }
}
