:root {
    --blue: #2f6fed;
    --blue-light: #eaf1ff;
    --blue-dark: #1f4fc4;
    --green: #1fa971;
    --green-light: #e6f8f0;
    --orange: #f2994a;
    --orange-light: #fef2e6;
    --red: #eb5757;
    --red-light: #fdeaea;
    --text: #1c2333;
    --text-muted: #6b7385;
    --border: #e7e9f0;
    --bg: #f6f7fb;
    --white: #ffffff;
    --radius: 14px;
    --shadow: 0 4px 20px rgba(28, 35, 51, 0.06);
}

[data-theme="dark"] {
    --blue-light: #1c2b4d;
    --green-light: #113328;
    --orange-light: #3a2a12;
    --red-light: #3a1717;
    --text: #eef0f5;
    --text-muted: #9aa2b4;
    --border: #2a3149;
    --bg: #12172a;
    --white: #1a2036;
    --shadow: 0 4px 20px rgba(0, 0, 0, 0.35);
}

[data-theme="dark"] input,
[data-theme="dark"] select,
[data-theme="dark"] textarea { background: #232a45; color: var(--text); }

.theme-toggle {
    background: none; border: none; cursor: pointer; color: var(--text-muted);
    display: flex; align-items: center;
}
.theme-toggle svg { width: 20px; height: 20px; }
[data-theme="dark"] .icon-sun { display: inline-flex; }
[data-theme="dark"] .icon-moon { display: none; }
.icon-moon { display: inline-flex; }
.icon-sun { display: none; }

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: 'Quicksand', sans-serif;
    background: var(--bg);
    color: var(--text);
}

svg {
    width: 20px;
    height: 20px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.container { max-width: 1240px; margin: 0 auto; padding: 0 32px; }

/* ==== Nav horizontale (façon Lagom) ==== */
.topnav {
    background: var(--white);
    border-bottom: 1px solid var(--border);
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 100;
}

body.has-fixed-nav { padding-top: 68px; }

.topnav-inner {
    max-width: 1240px;
    margin: 0 auto;
    padding: 14px 32px;
    display: flex;
    align-items: center;
    gap: 32px;
}

.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--text); font-weight: 700; font-size: 1.1rem; }
.brand-logo { width: 32px; height: 32px; border-radius: 8px; }
.admin-tag {
    font-size: 0.7rem; font-weight: 700; text-transform: uppercase;
    background: var(--blue-light); color: var(--blue);
    padding: 3px 8px; border-radius: 999px; margin-left: 4px;
}

.topnav-links { display: flex; gap: 4px; flex: 1; flex-wrap: wrap; }
.topnav-links a {
    color: var(--text-muted); text-decoration: none; font-weight: 600;
    padding: 9px 14px; border-radius: 8px; font-size: 0.9rem;
}
.topnav-links a:hover, .topnav-links a[aria-current="page"] { color: var(--blue); background: var(--blue-light); }

.topnav-actions { display: flex; align-items: center; gap: 18px; }
.topnav-icon-link { color: var(--text-muted); display: flex; position: relative; }
.nav-badge {
    position: absolute; top: -6px; right: -8px;
    background: var(--red); color: var(--white);
    font-size: 0.65rem; font-weight: 700;
    min-width: 16px; height: 16px; border-radius: 999px;
    display: flex; align-items: center; justify-content: center; padding: 0 4px;
}
.nav-toggle { display: none; background: none; border: none; cursor: pointer; color: var(--text); }

.topnav-user { position: relative; display: flex; align-items: center; gap: 10px; cursor: pointer; }
.topnav-avatar {
    width: 34px; height: 34px; border-radius: 50%;
    background: var(--blue-light); color: var(--blue);
    display: flex; align-items: center; justify-content: center;
}
.topnav-avatar svg { width: 18px; height: 18px; }
.topnav-username { font-weight: 600; font-size: 0.88rem; }

.topnav-user-menu {
    display: none;
    position: absolute; top: 100%; right: 0; margin-top: 10px;
    background: var(--white); border: 1px solid var(--border); border-radius: 12px;
    box-shadow: var(--shadow); min-width: 180px; padding: 8px; z-index: 50;
}
.topnav-user:hover .topnav-user-menu,
.topnav-user:focus-within .topnav-user-menu { display: block; }
.topnav-user-menu a {
    display: block; padding: 9px 12px; border-radius: 8px;
    color: var(--text); text-decoration: none; font-size: 0.88rem; font-weight: 500;
}
.topnav-user-menu a:hover { background: var(--blue-light); color: var(--blue); }
.topnav-user-menu .menu-logout { color: var(--red); }
.topnav-user-menu .menu-logout:hover { background: var(--red-light); color: var(--red); }

.page-header-bar {
    background: var(--white);
    border-bottom: 1px solid var(--border);
    padding: 18px 0;
    font-weight: 700;
    font-size: 1.15rem;
}

.content-shell { padding: 32px 0 8px; }

.app-footer {
    padding: 24px 0;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.85rem;
}

/* ==== Dashboard (grille façon Lagom) ==== */
.dashboard-grid {
    display: grid;
    grid-template-columns: 300px 1fr;
    gap: 24px;
    align-items: start;
}

.dashboard-side { display: flex; flex-direction: column; gap: 20px; }

.profile-card {
    background: linear-gradient(135deg, var(--blue), var(--blue-dark));
    color: var(--white);
    border-radius: var(--radius);
    padding: 28px 24px;
    text-align: center;
}
.profile-avatar {
    width: 72px; height: 72px; border-radius: 50%;
    background: rgba(255,255,255,0.18);
    display: flex; align-items: center; justify-content: center;
    margin: 0 auto 16px;
}
.profile-avatar img { width: 100%; height: 100%; border-radius: 50%; object-fit: cover; }
.profile-avatar svg { width: 34px; height: 34px; }
.profile-card h2 { margin: 0 0 8px; font-size: 1.15rem; }
.profile-address { margin: 0 0 20px; font-size: 0.85rem; opacity: 0.85; line-height: 1.5; }
.profile-actions { display: flex; gap: 10px; }
.btn-light { flex: 1; background: rgba(255,255,255,0.16); color: var(--white); }
.btn-light:hover { background: rgba(255,255,255,0.26); }

.side-panel {
    background: var(--white);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 20px;
}
.side-panel h3 { margin: 0 0 14px; font-size: 0.95rem; }

.side-list { list-style: none; margin: 0 0 14px; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.side-list li { display: flex; align-items: center; gap: 10px; font-size: 0.88rem; color: var(--text); }
.side-list svg { width: 18px; height: 18px; color: var(--blue); flex-shrink: 0; }

.side-link-btn {
    display: block; text-align: center; color: var(--blue); text-decoration: none;
    font-weight: 600; font-size: 0.85rem; padding: 8px; border-radius: 8px; background: var(--blue-light);
}

.shortcuts-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.shortcuts-list li { display: flex; align-items: center; gap: 10px; }
.shortcuts-list svg { width: 18px; height: 18px; color: var(--blue); flex-shrink: 0; }
.shortcuts-list a { color: var(--text); text-decoration: none; font-size: 0.88rem; font-weight: 500; padding: 8px 0; }
.shortcuts-list a:hover { color: var(--blue); }

.empty-note-sm { color: var(--text-muted); font-size: 0.82rem; margin: 0 0 12px; }

.dashboard-main { min-width: 0; }
.dashboard-greeting { margin: 0 0 20px; font-size: 1.5rem; }

.service-list { display: flex; flex-direction: column; }
.service-row {
    display: flex; align-items: center; gap: 16px;
    padding: 14px 0; border-bottom: 1px solid var(--border);
}
.service-row:last-child { border-bottom: none; }
.service-info { flex: 1; display: flex; flex-direction: column; gap: 2px; }
.service-info strong { font-size: 0.94rem; }
.service-info span { font-size: 0.8rem; color: var(--text-muted); }

.security-summary { color: var(--text-muted); font-size: 0.9rem; margin: 0; }

/* ==== Page intro (fallback pour anciennes vues) ==== */
.page-intro { margin-bottom: 24px; }
.page-intro h1 { margin: 0 0 4px; font-size: 1.6rem; }
.page-intro p { margin: 0; color: var(--text-muted); }

/* ==== Stat grid ==== */
.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
    margin-bottom: 28px;
}

.stat-card {
    background: var(--white);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 20px;
    display: flex;
    align-items: center;
    gap: 16px;
}

.stat-icon {
    width: 48px; height: 48px;
    border-radius: 12px;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
}
.stat-icon-blue { background: var(--blue-light); color: var(--blue); }
.stat-icon-green { background: var(--green-light); color: var(--green); }
.stat-icon-orange { background: var(--orange-light); color: var(--orange); }
.stat-icon-red { background: var(--red-light); color: var(--red); }

.stat-value { font-size: 1.5rem; font-weight: 700; }
.stat-label { color: var(--text-muted); font-size: 0.85rem; }

/* ==== Panels ==== */
.two-col {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-bottom: 20px;
}

.panel {
    background: var(--white);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 24px;
    margin-bottom: 20px;
}

.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}
.panel-header h2 { margin: 0; font-size: 1.05rem; }
.panel-link { color: var(--blue); text-decoration: none; font-size: 0.85rem; font-weight: 600; }
.panel-header-standalone { margin-bottom: 16px; display: flex; justify-content: flex-end; }

.empty-state { color: var(--text-muted); text-align: center; padding: 24px 0; margin: 0; }

/* Lists */
.simple-list { list-style: none; margin: 0; padding: 0; }
.simple-list li {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 0;
    border-bottom: 1px solid var(--border);
    gap: 12px;
}
.simple-list li:last-child { border-bottom: none; }
.simple-list a { color: var(--text); text-decoration: none; display: flex; justify-content: space-between; width: 100%; align-items: center; }
.simple-list a:hover { color: var(--blue); }
.service-info-sub { display: block; font-size: 0.78rem; color: var(--text-muted); font-weight: 400; }

/* Badges */
.badge {
    padding: 4px 12px;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: capitalize;
    white-space: nowrap;
}
.badge-active, .badge-paid, .badge-resolved, .badge-child-approved { background: var(--green-light); color: var(--green); }
.badge-due, .badge-submitted, .badge-in_review, .badge-child-pending { background: var(--orange-light); color: var(--orange); }
.badge-expired, .badge-rejected, .badge-cancelled, .badge-child-rejected { background: var(--red-light); color: var(--red); }

/* Table */
.data-table { width: 100%; border-collapse: collapse; }
.data-table th {
    text-align: left;
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--text-muted);
    padding: 10px 12px;
    border-bottom: 2px solid var(--border);
}
.data-table td {
    padding: 12px;
    border-bottom: 1px solid var(--border);
    font-size: 0.92rem;
}
.data-table tr:last-child td { border-bottom: none; }

/* Forms */
.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}
.form-field { display: flex; flex-direction: column; gap: 6px; }
.form-field-full { grid-column: 1 / -1; display: flex; flex-direction: column; gap: 6px; }
.form-field label, .form-field-full label { font-size: 0.85rem; font-weight: 600; color: var(--text-muted); }

input, select, textarea {
    font-family: 'Quicksand', sans-serif;
    padding: 11px 14px;
    border: 1px solid var(--border);
    border-radius: 10px;
    font-size: 0.92rem;
    background: var(--white);
    color: var(--text);
}
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--blue);
    box-shadow: 0 0 0 3px var(--blue-light);
}
input:disabled { background: var(--bg); color: var(--text-muted); }

.checkbox-field label { display: flex; align-items: center; gap: 10px; font-weight: 500; color: var(--text); }
.checkbox-field input { width: auto; }

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 11px 22px;
    border-radius: 10px;
    border: none;
    font-family: 'Quicksand', sans-serif;
    font-weight: 700;
    font-size: 0.9rem;
    cursor: pointer;
    text-decoration: none;
    transition: transform .1s, box-shadow .15s;
}
.btn-primary { background: var(--blue); color: var(--white); }
.btn-primary:hover { box-shadow: 0 6px 18px rgba(47,111,237,.35); transform: translateY(-1px); }
.btn-sm { background: var(--blue-light); color: var(--blue); padding: 7px 14px; font-size: 0.82rem; }
.btn-block { width: 100%; }
.btn-disabled { opacity: 0.5; cursor: not-allowed; pointer-events: none; }
.btn-approve { background: var(--green-light); color: var(--green); }
.btn-reject { background: var(--red-light); color: var(--red); }
.admin-actions { display: flex; gap: 8px; }

/* Groupes de permissions (édition de rôle) */
.permission-groups {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 20px;
    background: var(--bg);
    border-radius: 12px;
    padding: 20px;
}
.permission-group h4 { margin: 0 0 10px; font-size: 0.88rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.03em; }
.permission-item { display: flex; align-items: center; gap: 8px; font-size: 0.88rem; font-weight: 500; padding: 4px 0; cursor: pointer; }
.permission-item input { width: auto; }
.role-select { padding: 6px 10px; font-size: 0.82rem; border-radius: 8px; }
.breadcrumb { color: var(--text-muted); font-size: 0.85rem; margin-bottom: 16px; }
.breadcrumb a { color: var(--blue); text-decoration: none; }

/* ==== Barre latérale admin ==== */
.admin-shell { display: flex; min-height: 100vh; }

.admin-sidebar {
    width: 260px;
    flex-shrink: 0;
    background: var(--white);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    padding: 20px 14px;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
}

.admin-brand { padding: 0 8px 20px; margin-bottom: 8px; border-bottom: 1px solid var(--border); }

.admin-nav { display: flex; flex-direction: column; gap: 2px; }
.admin-nav a {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-radius: 10px;
    color: var(--text-muted);
    text-decoration: none;
    font-weight: 500;
    font-size: 0.9rem;
    position: relative;
}
.admin-nav a i { width: 18px; text-align: center; color: var(--text-muted); }
.admin-nav a:hover { background: var(--blue-light); color: var(--blue); }
.admin-nav a:hover i { color: var(--blue); }
.admin-nav a[aria-current="page"] { background: var(--blue-light); color: var(--blue); font-weight: 700; }
.admin-nav a[aria-current="page"] i { color: var(--blue); }

.admin-nav-divider { height: 1px; background: var(--border); margin: 10px 8px; }
.admin-nav-logout { color: var(--red) !important; }
.admin-nav-logout:hover { background: var(--red-light) !important; color: var(--red) !important; }
.admin-nav-logout i { color: var(--red) !important; }

.nav-badge-inline { margin-left: auto; }

.admin-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.admin-topbar {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 14px 32px;
    background: var(--white);
    border-bottom: 1px solid var(--border);
}
.admin-topbar-spacer { flex: 1; }
.admin-sidebar-toggle { display: none; }

/* Avatar */
.avatar-uploader { display: flex; align-items: center; gap: 20px; }
.avatar-preview { width: 72px; height: 72px; border-radius: 50%; object-fit: cover; flex-shrink: 0; }
.avatar-placeholder { background: var(--blue-light); color: var(--blue); display: flex; align-items: center; justify-content: center; }
.avatar-placeholder svg { width: 32px; height: 32px; }
.avatar-uploader form { display: flex; align-items: center; gap: 10px; }
.topnav-avatar img { width: 100%; height: 100%; border-radius: 50%; object-fit: cover; }

/* Bar chart (statistiques admin) */
.bar-chart {
    display: flex;
    align-items: flex-end;
    gap: 20px;
    padding: 20px 8px 0;
    min-height: 180px;
}
.bar-chart-col { display: flex; flex-direction: column; align-items: center; gap: 6px; flex: 1; }
.bar-chart-bar {
    width: 100%;
    max-width: 48px;
    background: linear-gradient(180deg, var(--blue), var(--blue-dark));
    border-radius: 6px 6px 0 0;
}
.bar-chart-value { font-size: 0.78rem; font-weight: 700; color: var(--text); }
.bar-chart-label { font-size: 0.72rem; color: var(--text-muted); }
.btn-icon {
    background: var(--red-light); color: var(--red);
    border: none; border-radius: 8px; padding: 8px; cursor: pointer;
    display: inline-flex; align-items: center; justify-content: center;
}
.btn-icon svg { width: 16px; height: 16px; }

/* Details/collapse */
.collapse { margin-top: 20px; border-top: 1px solid var(--border); padding-top: 16px; }
.collapse summary { cursor: pointer; font-weight: 700; color: var(--blue); }
.collapse form { margin-top: 16px; }

/* Detail list */
.detail-list { display: grid; grid-template-columns: 180px 1fr; row-gap: 12px; margin-bottom: 20px; }
.detail-list dt { color: var(--text-muted); font-weight: 600; }
.detail-list dd { margin: 0; }

/* Messages */
.message-thread { display: flex; flex-direction: column; gap: 12px; margin-bottom: 20px; max-height: 420px; overflow-y: auto; }
.message-bubble { max-width: 65%; padding: 12px 16px; border-radius: 14px; background: var(--bg); }
.message-bubble p { margin: 0 0 4px; }
.message-time { font-size: 0.72rem; color: var(--text-muted); }
.message-client { align-self: flex-end; background: var(--blue-light); }
.message-admin { align-self: flex-start; background: var(--bg); }
.message-form { display: flex; gap: 12px; align-items: flex-end; }
.message-form textarea { flex: 1; resize: vertical; }

/* Alerts */
.alert { padding: 14px 18px; border-radius: 10px; margin-bottom: 20px; font-weight: 600; font-size: 0.9rem; }
.alert-success { background: var(--green-light); color: var(--green); }
.alert-error { background: var(--red-light); color: var(--red); }

/* Error page */
.error-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: var(--bg); font-family: 'Quicksand', sans-serif; }
.error-box { text-align: center; }
.error-box h1 { font-size: 4rem; margin: 0; color: var(--blue); }

/* ==== Page de connexion (non authentifié) ==== */
.auth-shell {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: var(--bg);
}

.auth-card {
    background: var(--white);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 40px;
    width: 100%;
    max-width: 420px;
}

.auth-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 700;
    font-size: 1.2rem;
    margin-bottom: 28px;
}

.auth-logo { width: 34px; height: 34px; border-radius: 8px; }

.auth-card h1 { margin: 0 0 4px; font-size: 1.4rem; }
.auth-subtitle { margin: 0 0 24px; color: var(--text-muted); font-size: 0.9rem; }

.auth-form { display: flex; flex-direction: column; gap: 16px; }

.auth-footer-links {
    margin-top: 20px;
    text-align: center;
    font-size: 0.82rem;
    color: var(--text-muted);
}

.oauth-divider { display: flex; align-items: center; gap: 12px; margin: 20px 0; color: var(--text-muted); font-size: 0.8rem; }
.oauth-divider::before, .oauth-divider::after { content: ''; flex: 1; height: 1px; background: var(--border); }
.auth-section-divider { display: flex; align-items: center; gap: 12px; margin: 8px 0; color: var(--text-muted); font-size: 0.78rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.03em; }
.auth-section-divider::before, .auth-section-divider::after { content: ''; flex: 1; height: 1px; background: var(--border); }
.badge-suspended, .badge-deleted { background: var(--red-light); color: var(--red); }
.oauth-buttons { display: flex; gap: 12px; }
.btn-oauth { flex: 1; background: var(--white); color: var(--text); border: 1px solid var(--border); gap: 8px; }
.btn-oauth svg { width: 18px; height: 18px; }
.btn-oauth:hover { background: var(--bg); }

/* ==== Responsive ==== */
@media (max-width: 960px) {
    .dashboard-grid { grid-template-columns: 1fr; }
    .two-col { grid-template-columns: 1fr; }
    .form-grid { grid-template-columns: 1fr; }
}

@media (max-width: 768px) {
    .topnav-links {
        position: absolute; top: 100%; left: 0; right: 0;
        background: var(--white); border-bottom: 1px solid var(--border);
        flex-direction: column; padding: 12px 20px; gap: 2px;
        display: none;
    }
    .topnav-links.open { display: flex; }
    .nav-toggle { display: block; }
    .topnav-username { display: none; }
    .container { padding: 0 20px; }
    .content-shell { padding: 20px 0; }
    .stat-grid { grid-template-columns: 1fr 1fr; }
    .detail-list { grid-template-columns: 1fr; }
    .message-bubble { max-width: 85%; }
    .service-row { flex-wrap: wrap; }

    .admin-sidebar {
        position: fixed;
        left: -280px;
        top: 0;
        bottom: 0;
        z-index: 200;
        box-shadow: var(--shadow);
        transition: left .2s;
    }
    .admin-sidebar.open { left: 0; }
    .admin-sidebar-toggle { display: block; }
    body { padding-top: 0; }
}

@media (max-width: 480px) {
    .stat-grid { grid-template-columns: 1fr; }
}
