:root {
    --navy: #0f2b46;
    --navy-dark: #0a1e33;
    --blue: #1d6fb8;
    --blue-light: #e8f2fb;
    --green: #1f8a5b;
    --red: #b3261e;
    --amber: #a86b00;
    --ink: #1b2733;
    --muted: #64748b;
    --border: #d9e2ec;
    --bg: #f4f7fa;
    --white: #fff;
    --shadow: 0 8px 24px rgba(15, 43, 70, .08);
    --radius: 12px;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    max-width: 100%;
    overflow-x: hidden;
}

body {
    font-family: "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    color: var(--ink);
    background: var(--bg);
    line-height: 1.5;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.container {
    width: min(1180px, 94%);
    margin: 0 auto;
}

.grid > *,
.card,
.stat,
.qr-box {
    min-width: 0;
}

.site-header {
    background: linear-gradient(135deg, var(--navy), var(--navy-dark));
    color: var(--white);
    box-shadow: var(--shadow);
}

.header-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
    min-height: 76px;
    flex-wrap: wrap;
    padding: 12px 0;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    color: var(--white);
    text-decoration: none;
}

.brand-mark {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    display: block;
    overflow: hidden;
    background: var(--white);
    flex: 0 0 44px;
}

.brand-mark img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.brand strong { display: block; font-size: 1.05rem; }
.brand small { display: block; opacity: .75; font-size: .76rem; }

.main-nav { display: flex; gap: 6px; flex-wrap: wrap; }

.main-nav a {
    color: rgba(255,255,255,.88);
    text-decoration: none;
    padding: 8px 11px;
    border-radius: 8px;
    font-size: .9rem;
}

.main-nav a:hover, .main-nav a.active { background: rgba(255,255,255,.12); color: var(--white); }
.main-nav .nav-logout { background: rgba(255,255,255,.1); }

.main-content { flex: 1; padding: 30px 0 48px; }

.site-footer {
    background: var(--navy-dark);
    color: rgba(255,255,255,.75);
    padding: 22px 0;
    font-size: .85rem;
}
.site-footer p { margin: 2px 0; }
.site-footer .muted { opacity: .65; }

h1, h2, h3 { color: var(--navy); line-height: 1.25; }
h1 { font-size: 1.8rem; margin: 0 0 6px; }
h2 { font-size: 1.3rem; margin: 0 0 16px; }
h3 { font-size: 1.05rem; margin: 0 0 10px; }
p.lead { color: var(--muted); margin: 0 0 24px; }

.page-head {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    gap: 16px;
    margin-bottom: 24px;
    flex-wrap: wrap;
}

.card {
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 22px;
    margin-bottom: 20px;
}

.card.tight { padding: 16px; }

.grid { display: grid; gap: 20px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }

.stats-grid { margin-bottom: 34px; }
.section-title { margin-bottom: 24px; }

@media (max-width: 900px) {
    .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
}

.stat {
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px;
    box-shadow: var(--shadow);
}
.stat span { color: var(--muted); font-size: .85rem; }
.stat strong { display: block; font-size: 2rem; color: var(--navy); margin-top: 4px; }

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 16px;
    border: 1px solid transparent;
    border-radius: 9px;
    background: var(--blue);
    color: var(--white);
    text-decoration: none;
    font-size: .92rem;
    font-weight: 600;
    cursor: pointer;
    transition: filter .15s, background .15s;
}
.btn:hover { filter: brightness(.95); }
.btn-secondary { background: var(--white); color: var(--navy); border-color: var(--border); }
.btn-success { background: var(--green); }
.btn-danger { background: var(--red); }
.btn-small { padding: 6px 10px; font-size: .82rem; }
.btn-block { width: 100%; }

.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.inline-form { display: inline-block; margin: 0; }
.actions .inline-form { display: inline-flex; }

label {
    display: block;
    font-weight: 600;
    font-size: .88rem;
    margin-bottom: 6px;
    color: var(--navy);
}

input[type="text"], input[type="password"], input[type="email"], input[type="date"], input[type="file"], select, textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 9px;
    background: var(--white);
    color: var(--ink);
    font: inherit;
    font-size: .92rem;
}
input:focus, select:focus, textarea:focus {
    outline: 3px solid rgba(29,111,184,.16);
    border-color: var(--blue);
}

.field { margin-bottom: 16px; }
.field .hint { color: var(--muted); font-size: .78rem; margin-top: 4px; }
.required { color: var(--red); }
.check-label { display: inline-flex; align-items: center; gap: 8px; font-weight: 600; font-size: .88rem; color: var(--text); }
.check-label input[type="checkbox"] { width: 18px; height: 18px; margin: 0; }
.ar-text { direction: rtl; unicode-bidi: plaintext; font-size: 1rem; }

.form-row { display: grid; gap: 0 16px; grid-template-columns: repeat(2, minmax(0,1fr)); }
@media (max-width: 700px) { .form-row { grid-template-columns: 1fr; } }

.alert {
    border-radius: 9px;
    padding: 12px 14px;
    margin-bottom: 12px;
    border: 1px solid transparent;
    font-size: .9rem;
}
.alert-success { background: #e8f6ee; border-color: #b7e1c8; color: #155e3a; }
.alert-error, .alert-danger { background: #fdecea; border-color: #f3c2bd; color: #8a1f18; }
.alert-warning { background: #fff6e0; border-color: #f1d79b; color: #7a5200; }
.alert-info { background: var(--blue-light); border-color: #bcd9f2; color: #134f86; }
.flash-stack { margin-bottom: 18px; }

.error-list { margin: 0; padding-left: 18px; color: var(--red); font-size: .88rem; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { padding: 11px 12px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; overflow-wrap: anywhere; }
th { background: #f7f9fc; color: var(--navy); font-size: .8rem; text-transform: uppercase; letter-spacing: .4px; }
tbody tr:hover { background: #fafcfe; }
td.actions-cell { white-space: nowrap; }

.code {
    font-family: Consolas, "Courier New", monospace;
    font-weight: 700;
    letter-spacing: 1px;
    color: var(--navy);
    background: var(--blue-light);
    padding: 4px 8px;
    border-radius: 6px;
    font-size: .88rem;
    overflow-wrap: anywhere;
    word-break: break-word;
}

.badge {
    display: inline-block;
    padding: 3px 9px;
    border-radius: 999px;
    font-size: .75rem;
    font-weight: 700;
}
.badge-ok { background: #e8f6ee; color: #155e3a; }
.badge-error { background: #fdecea; color: #8a1f18; }
.badge-info { background: var(--blue-light); color: #134f86; }
.badge-warning { background: #fff6e0; color: #7a5200; }
.badge-danger { background: #fdecea; color: #8a1f18; }

.search-bar { display: flex; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; }
.search-bar input { max-width: 360px; }

.qr-layout { display: grid; grid-template-columns: 260px 1fr; gap: 28px; align-items: start; }
@media (max-width: 760px) { .qr-layout { grid-template-columns: 1fr; } }

.qr-box {
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px;
    text-align: center;
}
.qr-box img { max-width: 100%; width: 220px; height: auto; image-rendering: pixelated; }
.qr-box p { font-size: .8rem; color: var(--muted); margin: 10px 0 0; word-break: break-all; }

.info-list { margin: 0; }
.info-list div {
    display: grid;
    grid-template-columns: minmax(0, 180px) minmax(0, 1fr);
    gap: 12px;
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
}
.info-list dt {
    color: var(--muted);
    font-size: .85rem;
    min-width: 0;
    overflow-wrap: anywhere;
}
.info-list dd {
    margin: 0;
    font-weight: 600;
    min-width: 0;
    overflow-wrap: anywhere;
}

.copy-row { display: flex; gap: 8px; align-items: center; min-width: 0; }
.copy-row input { font-family: Consolas, "Courier New", monospace; font-size: .82rem; min-width: 0; flex: 1 1 auto; }
.copy-row .btn { flex: 0 0 auto; }

.lock-card { max-width: 460px; margin: 30px auto; text-align: center; }
.lock-icon { font-size: 2.4rem; }

.muted { color: var(--muted); }
.small { font-size: .82rem; }
.text-center { text-align: center; }

.pagination { display: flex; gap: 6px; margin-top: 16px; flex-wrap: wrap; }
.pagination a, .pagination span {
    padding: 6px 11px;
    border: 1px solid var(--border);
    border-radius: 7px;
    text-decoration: none;
    color: var(--navy);
    font-size: .84rem;
    background: var(--white);
}
.pagination .current { background: var(--navy); color: var(--white); border-color: var(--navy); }

.empty { text-align: center; padding: 36px; color: var(--muted); }

/* Corrections mobiles : éviter tout décalage horizontal */
@media (max-width: 600px) {
    .header-inner { align-items: flex-start; gap: 10px; }

    .main-nav { width: 100%; gap: 4px; }
    .main-nav a { flex: 1 1 auto; text-align: center; padding: 8px 6px; }

    .main-content { padding: 20px 0 36px; }

    .page-head { align-items: stretch; }
    .page-head .actions,
    .page-head .actions .btn,
    .page-head .actions .inline-form { width: 100%; }
    .page-head .actions .btn { justify-content: center; }

    .info-list div { grid-template-columns: 1fr; gap: 2px; padding: 9px 0; }
    .info-list dt { font-size: .8rem; }
    .info-list dd { font-size: .92rem; }

    .copy-row { flex-wrap: wrap; }
    .copy-row input { flex: 1 1 100%; }
    .copy-row .btn { width: 100%; }

    .search-bar input { max-width: none; width: 100%; }
    .search-bar .btn { flex: 0 0 auto; }

    td.actions-cell { white-space: normal; }
    td.actions-cell .btn,
    td.actions-cell .inline-form { display: block; width: 100%; margin-bottom: 5px; }
    td.actions-cell .inline-form .btn { margin-bottom: 0; }

    .qr-box img { width: min(220px, 70vw); }

    .card { padding: 16px; }
    .stat strong { font-size: 1.7rem; }

    .stats-grid { margin-bottom: 24px; }
    .section-title { margin-bottom: 18px; }
}

