/* ═══════════════════════════════════════════════════════════════════════════
   RH & Production — Design System Light
   Thème clair, mobile-first, épuré, naturel
   ═══════════════════════════════════════════════════════════════════════════ */

/* ─── CSS Variables ─────────────────────────────────────────────────────── */
:root {
    --bg-page: #f5f5f7;
    --bg-white: #ffffff;
    --bg-subtle: #f0f0f3;
    --bg-hover: #e8e8ec;

    --border: #e2e2e7;
    --border-focus: #4a6cf7;

    --text-primary: #1a1a2e;
    --text-secondary: #6b7085;
    --text-muted: #9ca0b0;

    --accent: #4a6cf7;
    --accent-hover: #3d5bd9;
    --accent-light: #eef1fe;

    --success: #2d9d5c;
    --success-light: #edf7f0;
    --warning: #d4880f;
    --warning-light: #fdf5e6;
    --danger: #d14343;
    --danger-light: #fdf0f0;
    --info: #3a7fc4;
    --info-light: #edf4fc;

    --shadow-sm: 0 1px 3px rgba(0,0,0,0.06);
    --shadow-md: 0 2px 8px rgba(0,0,0,0.08);

    --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --radius: 10px;
    --radius-sm: 8px;
    --transition: 200ms ease;
}


/* ─── Reset ─────────────────────────────────────────────────────────────── */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    overflow-y: scroll;
}

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


.header {
    background: var(--bg-white);
    border-bottom: 1px solid var(--border);
    padding: 14px 20px;
    position: sticky;
    top: 0;
    z-index: 100;
    max-width: 600px;
    margin: 0 auto;
}

.header-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}

.header-title {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-primary);
}

.header-user {
    display: flex;
    align-items: center;
    gap: 10px;
}

.avatar-sm {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--accent);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    font-weight: 700;
}

.btn-logout {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 6px;
    border-radius: 6px;
    display: flex;
    transition: var(--transition);
}

.btn-logout:hover {
    color: var(--danger);
    background: var(--danger-light);
}

/* Factory selector in header */
.factory-tabs {
    display: flex;
    gap: 6px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding-bottom: 2px;
}

.factory-tabs::-webkit-scrollbar { display: none; }

.factory-tab {
    padding: 7px 16px;
    border: none;
    background: var(--bg-subtle);
    color: var(--text-secondary);
    font-family: var(--font);
    font-size: 0.82rem;
    font-weight: 600;
    border-radius: 20px;
    cursor: pointer;
    white-space: nowrap;
    transition: var(--transition);
}

.factory-tab:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.factory-tab.active {
    background: var(--accent);
    color: white;
}


/* ─── Main Content ──────────────────────────────────────────────────────── */
.main {
    padding: 16px;
    max-width: 600px;
    margin: 0 auto;
}


/* ─── Stats Row ─────────────────────────────────────────────────────────── */
.stats-row {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 10px;
    margin-bottom: 20px;
}

.stat-box {
    background: var(--bg-white);
    border-radius: var(--radius);
    padding: 14px;
    text-align: center;
    box-shadow: var(--shadow-sm);
}

.stat-number {
    font-size: 1.6rem;
    font-weight: 800;
    line-height: 1;
    margin-bottom: 2px;
}

.stat-number.green { color: var(--success); }
.stat-number.red { color: var(--danger); }
.stat-number.orange { color: var(--warning); }

.stat-label {
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.3px;
}


/* ─── Section ───────────────────────────────────────────────────────────── */
.section {
    margin-bottom: 20px;
}

.section-title {
    font-size: 0.95rem;
    font-weight: 700;
    margin-bottom: 10px;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 6px;
}


/* ─── Card ──────────────────────────────────────────────────────────────── */
.card {
    background: var(--bg-white);
    border-radius: var(--radius);
    padding: 16px;
    box-shadow: var(--shadow-sm);
}


/* ─── Absence Form (inline) ─────────────────────────────────────────────── */
.absence-form-inline {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.form-label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
}

.form-input,
.form-select {
    width: 100%;
    padding: 11px 14px;
    background: var(--bg-subtle);
    border: 1.5px solid transparent;
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-family: var(--font);
    font-size: 0.9rem;
    transition: var(--transition);
    -webkit-appearance: none;
    appearance: none;
}

.form-select {
    background-image: url("data:image/svg+xml,%3Csvg width='10' height='6' viewBox='0 0 10 6' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%236b7085' stroke-width='1.5' stroke-linecap='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 32px;
}

.form-select option {
    background: white;
}

.form-input:focus,
.form-select:focus {
    outline: none;
    border-color: var(--accent);
    background: white;
    box-shadow: 0 0 0 3px var(--accent-light);
}

.form-input::placeholder {
    color: var(--text-muted);
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}


/* ─── Buttons ───────────────────────────────────────────────────────────── */
.btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 12px 20px;
    border: none;
    border-radius: var(--radius-sm);
    font-family: var(--font);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    width: 100%;
}

.btn-primary {
    background: var(--accent);
    color: white;
}

.btn-primary:hover {
    background: var(--accent-hover);
}

.btn-primary:active {
    transform: scale(0.98);
}

.btn-primary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-subtle {
    background: var(--bg-subtle);
    color: var(--text-secondary);
}

.btn-subtle:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.btn-sm {
    padding: 8px 14px;
    font-size: 0.8rem;
}

.btn-danger-sm {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 6px;
    border-radius: 6px;
    display: flex;
    transition: var(--transition);
}

.btn-danger-sm:hover {
    color: var(--danger);
    background: var(--danger-light);
}


/* ─── Absent List ───────────────────────────────────────────────────────── */
.absent-list {
    display: flex;
    flex-direction: column;
}

.absent-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 0;
    border-bottom: 1px solid var(--border);
}

.absent-item:last-child {
    border-bottom: none;
}

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

.absent-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
    font-weight: 700;
    color: white;
    flex-shrink: 0;
}

.absent-avatar.sick { background: var(--danger); }
.absent-avatar.at { background: var(--warning); }
.absent-avatar.absent { background: var(--info); }
.absent-avatar.other { background: var(--text-muted); }

.absent-details {
    min-width: 0;
}

.absent-name {
    font-size: 0.88rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.absent-meta {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.absent-actions {
    flex-shrink: 0;
}


/* ─── Badge ─────────────────────────────────────────────────────────────── */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 3px 9px;
    border-radius: 20px;
    font-size: 0.7rem;
    font-weight: 600;
}

.badge-danger { background: var(--danger-light); color: var(--danger); }
.badge-warning { background: var(--warning-light); color: var(--warning); }
.badge-success { background: var(--success-light); color: var(--success); }
.badge-info { background: var(--info-light); color: var(--info); }
.badge-neutral { background: var(--bg-subtle); color: var(--text-secondary); }


/* ─── Sick Leave Cards ──────────────────────────────────────────────────── */
.sick-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.sick-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    background: var(--bg-subtle);
    border-radius: var(--radius-sm);
    transition: var(--transition);
}

.sick-item-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    font-weight: 700;
    color: white;
    flex-shrink: 0;
}

.sick-item-avatar.maladie { background: var(--danger); }
.sick-item-avatar.at { background: var(--warning); }

.sick-item-info {
    flex: 1;
    min-width: 0;
}

.sick-item-name {
    font-size: 0.88rem;
    font-weight: 600;
}

.sick-item-dates {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.sick-item-badge {
    flex-shrink: 0;
}

.days-badge {
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 0.72rem;
    font-weight: 700;
}

.days-badge.soon { background: var(--success-light); color: var(--success); }
.days-badge.medium { background: var(--warning-light); color: var(--warning); }
.days-badge.long { background: var(--danger-light); color: var(--danger); }


/* ─── Empty State ───────────────────────────────────────────────────────── */
.empty-state {
    text-align: center;
    padding: 32px 16px;
    color: var(--text-muted);
}

.empty-state-icon {
    font-size: 2rem;
    margin-bottom: 8px;
}

.empty-state h3 {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

.empty-state p {
    font-size: 0.8rem;
}


/* ─── Toast ─────────────────────────────────────────────────────────────── */
.toast-container {
    position: fixed;
    bottom: 24px;
    left: 16px;
    right: 16px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: none;
}

.toast {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 16px;
    background: var(--text-primary);
    color: white;
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-md);
    animation: toastIn 0.3s ease-out;
    pointer-events: auto;
    font-size: 0.85rem;
    font-weight: 500;
    max-width: 500px;
    margin: 0 auto;
    width: 100%;
}

.toast.toast-out {
    animation: toastOut 0.3s ease-in forwards;
}

.toast-success { background: var(--success); }
.toast-error { background: var(--danger); }
.toast-warning { background: var(--warning); }

.toast-close {
    background: none;
    border: none;
    color: rgba(255,255,255,0.7);
    cursor: pointer;
    padding: 2px;
    display: flex;
    margin-left: auto;
    flex-shrink: 0;
}

@keyframes toastIn {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes toastOut {
    from { opacity: 1; transform: translateY(0); }
    to { opacity: 0; transform: translateY(20px); }
}


/* ─── Spinner ───────────────────────────────────────────────────────────── */
.spinner {
    display: inline-block;
    width: 18px;
    height: 18px;
    border: 2px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.5s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px;
    gap: 12px;
    color: var(--text-muted);
    font-size: 0.85rem;
}

.spinner-lg {
    width: 28px;
    height: 28px;
    border-width: 3px;
}


/* ─── Login ─────────────────────────────────────────────────────────────── */
.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 24px;
    background: white;
}

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

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

.login-logo-icon {
    width: 56px;
    height: 56px;
    background: var(--accent);
    border-radius: 14px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 14px;
}

.login-logo h1 {
    font-size: 1.3rem;
    font-weight: 700;
}

.login-logo p {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-top: 4px;
}

.login-form {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.login-error {
    display: none;
    padding: 10px 14px;
    background: var(--danger-light);
    border-radius: var(--radius-sm);
    color: var(--danger);
    font-size: 0.82rem;
    font-weight: 500;
}

.login-error.visible {
    display: block;
    animation: shake 0.35s ease;
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-6px); }
    75% { transform: translateX(6px); }
}


/* ─── Toggle (heures/journée) ───────────────────────────────────────────── */
.toggle-row {
    display: flex;
    background: var(--bg-subtle);
    border-radius: var(--radius-sm);
    padding: 3px;
    gap: 3px;
}

.toggle-btn {
    flex: 1;
    padding: 8px;
    border: none;
    background: transparent;
    font-family: var(--font);
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text-muted);
    border-radius: 6px;
    cursor: pointer;
    transition: var(--transition);
}

.toggle-btn.active {
    background: white;
    color: var(--text-primary);
    box-shadow: var(--shadow-sm);
}


/* ─── Hidden ────────────────────────────────────────────────────────────── */
.hidden { display: none !important; }
/* Ajout pour l'autocomplétion */
.autocomplete-container {
    position: relative;
    width: 100%;
}

.autocomplete-list {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    background: var(--bg-white);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-md);
    max-height: 200px;
    overflow-y: auto;
    z-index: 1000;
    display: none;
}

.autocomplete-list.active {
    display: block;
}

.autocomplete-item {
    padding: 10px 14px;
    cursor: pointer;
    font-size: 0.9rem;
    color: var(--text-primary);
    border-bottom: 1px solid var(--bg-subtle);
}

.autocomplete-item:last-child {
    border-bottom: none;
}

.autocomplete-item:hover,
.autocomplete-item.selected {
    background: var(--bg-subtle);
    color: var(--accent);
    font-weight: 600;
}

/* Modal Historique */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(2px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s, visibility 0.2s;
}

.modal-overlay.active {
    opacity: 1;
    visibility: visible;
}

.modal-content {
    background: var(--bg-white);
    border-radius: var(--radius-lg);
    width: 90%;
    max-width: 500px;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
    transform: translateY(20px);
    transition: transform 0.2s;
}

.modal-overlay.active .modal-content {
    transform: translateY(0);
}

.modal-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-title {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-primary);
}

.modal-close {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 4px;
    border-radius: var(--radius-sm);
    transition: background 0.2s;
}

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

.modal-body {
    padding: 20px;
    overflow-y: auto;
}

.history-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.history-item {
    padding: 12px;
    background: var(--bg-card);
    border-radius: 8px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.history-date {
    font-weight: 600;
    color: var(--text-main);
}

.history-motif {
    font-size: 13px;
    color: var(--text-muted);
}

/* ─── Bottom Navigation ──────────────────────────────────────────────────── */

.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--bg-white);
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 6px 0;
    padding-bottom: max(6px, env(safe-area-inset-bottom));
    z-index: 200;
}

.bottom-nav .nav-item {
    max-width: 300px;
}

.nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 6px 0;
    background: none;
    border: none;
    color: var(--text-muted);
    font-family: var(--font);
    font-size: 0.7rem;
    font-weight: 600;
    cursor: pointer;
    transition: color var(--transition);
}

.nav-item.active {
    color: var(--accent);
}

.nav-item svg {
    width: 22px;
    height: 22px;
}

.pb-safe {
    padding-bottom: 70px;
}


/* ─── Spinner & Loading ──────────────────────────────────────────────────── */

.spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.loading {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 24px;
    color: var(--text-muted);
    font-size: 0.85rem;
}


/* ─── Toast ──────────────────────────────────────────────────────────────── */

.toast-container {
    position: fixed;
    top: 16px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 5000;
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: 90%;
    max-width: 400px;
}

.toast {
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    font-size: 0.85rem;
    font-weight: 500;
    box-shadow: var(--shadow-md);
    animation: toast-in 0.3s ease;
}

.toast-success {
    background: var(--success-light);
    color: var(--success);
    border: 1px solid var(--success);
}

.toast-error {
    background: var(--danger-light);
    color: var(--danger);
    border: 1px solid var(--danger);
}

.toast-warning {
    background: var(--warning-light);
    color: var(--warning);
    border: 1px solid var(--warning);
}

.toast-close {
    background: none;
    border: none;
    cursor: pointer;
    color: inherit;
    opacity: 0.6;
    display: flex;
    padding: 2px;
}

.toast-close:hover {
    opacity: 1;
}

.toast-out {
    animation: toast-out 0.3s ease forwards;
}

@keyframes toast-in {
    from { opacity: 0; transform: translateY(-10px); }
    to   { opacity: 1; transform: translateY(0); }
}

@keyframes toast-out {
    from { opacity: 1; transform: translateY(0); }
    to   { opacity: 0; transform: translateY(-10px); }
}


/* ─── Production ─────────────────────────────────────────────────────────── */

.form-select {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: var(--font);
    font-size: 0.9rem;
    background: var(--bg-white);
    color: var(--text-primary);
    cursor: pointer;
    transition: border-color var(--transition);
}

.form-select:focus {
    outline: none;
    border-color: var(--border-focus);
}

.ref-list {
    display: flex;
    flex-direction: column;
}

.ref-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid var(--bg-subtle);
}

.ref-item:last-child {
    border-bottom: none;
}

.ref-name {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-primary);
    flex: 1;
}

.ref-input {
    width: 80px;
    text-align: center;
}

.prod-summary-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.prod-summary-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 0;
}

.prod-ref {
    font-size: 0.85rem;
    color: var(--text-secondary);
}


/* ─── Global Loader ──────────────────────────────────────────────────────── */

.global-loader {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: var(--bg-page);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.4s ease;
}

.global-loader.active {
    opacity: 1;
    pointer-events: all;
}

.global-loader .spinner {
    width: 44px;
    height: 44px;
    border-width: 4px;
    margin: 0 auto 20px;
    animation: spin 1.2s linear infinite;
}

.global-loader h2 {
    font-size: 1.15rem;
    font-weight: 700;
    margin-bottom: 8px;
    color: var(--text-primary);
}

.global-loader p {
    color: var(--text-muted);
    font-size: 0.85rem;
}