/* Family Admin Dashboard — Phase 1 stylesheet
   Warm, readable, mobile-friendly. 16px minimum font.
   Status & priority badges, clickable cards, responsive tables, modal. */

:root {
    --bg: #faf7f2;
    --surface: #ffffff;
    --surface-alt: #f5efe8;
    --primary: #8b5e3c;        /* warm brown */
    --primary-dark: #6b4628;
    --accent: #c98a4a;         /* amber */
    --text: #2d2a26;
    --text-muted: #6b6359;
    --border: #e3d9cc;
    --danger: #c0392b;
    --warning: #b8860b;
    --success: #2d8659;
    --info: #2c6f8f;
    --purple: #6c4c8c;
    --radius: 10px;
    --shadow: 0 2px 8px rgba(43, 38, 35, 0.08);
    --shadow-hover: 0 4px 16px rgba(43, 38, 35, 0.14);
    --max-width: 1100px;
}

* { box-sizing: border-box; }

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

body {
    margin: 0;
    font-family: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
}

a { color: var(--primary-dark); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- Layout ---------- */
.container {
    max-width: var(--max-width);
    margin: 0 auto;
    padding: 1rem 1.25rem 3rem;
}

/* ---------- Header ---------- */
.site-header {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow);
    position: sticky;
    top: 0;
    z-index: 100;
}
.site-header__inner {
    max-width: var(--max-width);
    margin: 0 auto;
    padding: 0.75rem 1.25rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
}
.site-header__title {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--primary-dark);
    margin: 0;
}
.site-header__nav {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    font-size: 0.95rem;
}
.site-header__nav a {
    color: var(--text-muted);
    padding: 0.3rem 0.6rem;
    border-radius: 6px;
    transition: background 0.12s, color 0.12s;
}
.site-header__nav a:hover, .site-header__nav a.active {
    background: var(--surface-alt);
    color: var(--primary-dark);
    text-decoration: none;
}
.site-header__user {
    font-size: 0.85rem;
    color: var(--text-muted);
}

/* ---------- Cards / panels ---------- */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    box-shadow: var(--shadow);
    margin-bottom: 1.25rem;
    transition: box-shadow 0.15s;
}
.card__title {
    margin: 0 0 0.75rem;
    font-size: 1.1rem;
    color: var(--primary-dark);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
}
.card__title a { font-size: 0.85rem; font-weight: 400; }

.grid {
    display: grid;
    gap: 1.25rem;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

/* Stat cards (clickable) */
.stat {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem 1.25rem;
    box-shadow: var(--shadow);
    transition: box-shadow 0.15s, transform 0.1s;
    text-decoration: none;
    color: inherit;
    display: block;
}
.stat:hover {
    box-shadow: var(--shadow-hover);
    text-decoration: none;
    transform: translateY(-1px);
}
.stat__label {
    font-size: 0.8rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    font-weight: 600;
}
.stat__value {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--primary-dark);
    margin-top: 0.25rem;
}
.stat__sub {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-top: 0.25rem;
}

/* ---------- Progress bar ---------- */
.progress {
    background: var(--surface-alt);
    border-radius: 999px;
    height: 10px;
    overflow: hidden;
    margin: 0.5rem 0;
    border: 1px solid var(--border);
}
.progress__bar {
    background: linear-gradient(90deg, var(--success), #4ea878);
    height: 100%;
    border-radius: 999px;
    transition: width 0.4s ease;
}
.progress__label {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 0.25rem;
}

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.95rem;
}
th, td {
    text-align: left;
    padding: 0.6rem 0.5rem;
    border-bottom: 1px solid var(--border);
    vertical-align: top;
}
th {
    font-weight: 600;
    color: var(--text-muted);
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    cursor: default;
}
th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--primary-dark); }
th.sort-asc::after { content: " ▲"; font-size: 0.7em; }
th.sort-desc::after { content: " ▼"; font-size: 0.7em; }
tr:hover { background: var(--surface-alt); }
tr.task-row { cursor: pointer; transition: background 0.1s; }
tr.task-row:hover { background: var(--surface-alt); }

/* ---------- Status badges ---------- */
.badge {
    display: inline-block;
    padding: 0.18rem 0.65rem;
    border-radius: 999px;
    font-size: 0.78rem;
    font-weight: 600;
    white-space: nowrap;
}
/* Task statuses */
.badge--a_faire { background: #ece8e0; color: #6b6359; }
.badge--en_cours { background: #e3eef9; color: #2c6f8f; }
.badge--en_attente_tiers { background: #fdebd0; color: #b8860b; }
.badge--en_attente { background: #fdebd0; color: #b8860b; }
.badge--a_valider { background: #ede1f5; color: #6c4c8c; }
.badge--termine { background: #dcf0e4; color: #2d8659; }
.badge--bloque { background: #fae0dc; color: #c0392b; }
.badge--non_applicable { background: #f0f0f0; color: #999; }
.badge--abandonne { background: #f0f0f0; color: #999; }
/* Priorities */
.badge--critique { background: #fae0dc; color: #c0392b; }
.badge--haute { background: #fde6d4; color: #d35400; }
.badge--normale { background: #e3eef9; color: #2c6f8f; }
.badge--basse { background: #ece8e0; color: #6b6359; }
/* Generic fallback */
.badge--done { background: #dcf0e4; color: #2d8659; }
.badge--todo { background: #ece8e0; color: #6b6359; }
/* Activity event types */
.badge--login, .badge--login_failed { background: #e3eef9; color: #2c6f8f; }
.badge--login_failed { background: #fae0dc; color: #c0392b; }
.badge--task_created, .badge--task_updated, .badge--status_change { background: #dcf0e4; color: #2d8659; }
.badge--note_added { background: #fde6d4; color: #8b5e3c; }
.badge--document_added { background: #ede1f5; color: #6c4c8c; }
.badge--financial_change { background: #fdebd0; color: #b8860b; }
.badge--proposal_reviewed { background: #e3eef9; color: #2c6f8f; }
.badge--export, .badge--user_change { background: #ece8e0; color: #6b6359; }
/* Calendar event types */
.badge--échéance_légale { background: #fae0dc; color: #c0392b; }
.badge--rendez_vous { background: #ede1f5; color: #6c4c8c; }
.badge--relance, .badge--réponse_attendue { background: #fdebd0; color: #b8860b; }
.badge--prélèvement_à_surveiller { background: #e3eef9; color: #2c6f8f; }
.badge--dépôt_à_effectuer { background: #ece8e0; color: #6b6359; }
.badge--contrôle_périodique { background: #e3eef9; color: #2c6f8f; }
/* Claims statuses */
.badge--estimé, .badge--réclamé { background: #fdebd0; color: #b8860b; }
.badge--confirmé { background: #e3eef9; color: #2c6f8f; }
.badge--reçu { background: #dcf0e4; color: #2d8659; }
.badge--refusé { background: #fae0dc; color: #c0392b; }

/* Due date colors */
.due { font-weight: 600; }
.due--overdue { color: var(--danger); }
.due--soon { color: #d35400; }
.due--near { color: var(--warning); }
.due--ok { color: var(--text); }
.due--none { color: var(--text-muted); font-weight: 400; }

/* Days remaining color coding */
.days-remaining { font-weight: 600; }
.days-remaining--red { color: var(--danger); }
.days-remaining--orange { color: #d35400; }
.days-remaining--yellow { color: var(--warning); }
.days-remaining--green { color: var(--success); }

/* ---------- Filters bar ---------- */
.filters {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    align-items: flex-end;
    margin-bottom: 1.25rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem 1.25rem;
    box-shadow: var(--shadow);
}
.filter-group { display: flex; flex-direction: column; gap: 0.25rem; }
.filter-group label {
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
    font-weight: 600;
    margin: 0;
}
.filters select, .filters input {
    min-width: 140px;
    padding: 0.5rem 0.65rem;
    font-size: 0.92rem;
}
.filters .search-input { min-width: 200px; flex: 1; }

/* ---------- Modal ---------- */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(43, 38, 35, 0.45);
    z-index: 1000;
    align-items: flex-start;
    justify-content: center;
    padding: 2rem 1rem;
    overflow-y: auto;
}
.modal-overlay.open { display: flex; }
.modal {
    background: var(--surface);
    border-radius: 12px;
    box-shadow: 0 12px 48px rgba(0,0,0,0.25);
    max-width: 680px;
    width: 100%;
    padding: 1.5rem;
    margin-bottom: 2rem;
}
.modal__header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--border);
}
.modal__title { margin: 0; font-size: 1.2rem; color: var(--primary-dark); }
.modal__close {
    background: none; border: none; font-size: 1.5rem; line-height: 1;
    color: var(--text-muted); cursor: pointer; padding: 0 0.4rem;
    border-radius: 4px;
}
.modal__close:hover { background: var(--surface-alt); color: var(--text); }
.modal__body { font-size: 0.95rem; }
.modal__section { margin-bottom: 1rem; }
.modal__section h4 {
    font-size: 0.82rem; text-transform: uppercase; letter-spacing: 0.04em;
    color: var(--text-muted); margin: 0 0 0.35rem;
}
.modal__meta { display: flex; flex-wrap: wrap; gap: 0.75rem 1.5rem; margin-bottom: 1rem; }
.modal__meta-item { font-size: 0.88rem; }
.modal__meta-item .label { color: var(--text-muted); font-weight: 600; }

/* Notes section in modal */
.notes-list { margin: 0.5rem 0; max-height: 200px; overflow-y: auto; }
.note-item {
    background: var(--surface-alt);
    border-radius: 8px;
    padding: 0.6rem 0.85rem;
    margin-bottom: 0.5rem;
    font-size: 0.9rem;
}
.note-item__meta { font-size: 0.78rem; color: var(--text-muted); margin-bottom: 0.2rem; }
.note-add { display: flex; gap: 0.5rem; margin-top: 0.75rem; }
.note-add input { flex: 1; }
.note-add .btn { padding: 0.5rem 1rem; white-space: nowrap; }

/* Inline status change */
.status-select {
    padding: 0.3rem 0.5rem;
    font-size: 0.82rem;
    border-radius: 6px;
    border: 1px solid var(--border);
    background: var(--surface);
    cursor: pointer;
}
.status-select.changed { border-color: var(--accent); }

/* ---------- Timeline (activity & calendar) ---------- */
.timeline { list-style: none; padding: 0; margin: 0; }
.timeline-item {
    display: flex;
    gap: 1rem;
    padding: 0.85rem 0;
    border-bottom: 1px solid var(--border);
}
.timeline-item:last-child { border-bottom: none; }
.timeline-item__dot {
    flex-shrink: 0;
    width: 10px; height: 10px;
    border-radius: 50%;
    background: var(--accent);
    margin-top: 0.5rem;
}
.timeline-item__dot--login { background: var(--info); }
.timeline-item__dot--login_failed { background: var(--danger); }
.timeline-item__dot--task_created, .timeline-item__dot--task_updated { background: var(--success); }
.timeline-item__dot--note_added { background: var(--accent); }
.timeline-item__dot--status_change { background: var(--purple); }
.timeline-item__body { flex: 1; }
.timeline-item__time { font-size: 0.78rem; color: var(--text-muted); }
.timeline-item__desc { font-size: 0.92rem; margin-top: 0.15rem; }
.timeline-item__actor { font-weight: 600; }

/* Calendar event card */
.event-card {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.85rem 1rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 0.75rem;
    background: var(--surface);
    box-shadow: var(--shadow);
    transition: box-shadow 0.15s;
}
.event-card:hover { box-shadow: var(--shadow-hover); }
.event-card__date {
    flex-shrink: 0;
    text-align: center;
    min-width: 64px;
    padding: 0.5rem;
    background: var(--surface-alt);
    border-radius: 8px;
}
.event-card__date .day { font-size: 1.4rem; font-weight: 700; color: var(--primary-dark); line-height: 1; }
.event-card__date .month { font-size: 0.78rem; color: var(--text-muted); text-transform: uppercase; }
.event-card__body { flex: 1; }
.event-card__title { font-weight: 600; font-size: 0.98rem; }
.event-card__meta { font-size: 0.82rem; color: var(--text-muted); margin-top: 0.15rem; }
.event-card__days { flex-shrink: 0; text-align: right; }

/* ---------- Urgent task list ---------- */
.urgent-list { list-style: none; padding: 0; margin: 0; }
.urgent-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.7rem 0;
    border-bottom: 1px solid var(--border);
}
.urgent-item:last-child { border-bottom: none; }
.urgent-item__title { flex: 1; font-weight: 500; }
.urgent-item__due { font-size: 0.82rem; flex-shrink: 0; }

/* ---------- Forms ---------- */
.form-group { margin-bottom: 1rem; }
label {
    display: block;
    font-weight: 600;
    margin-bottom: 0.3rem;
    font-size: 0.95rem;
}
input[type="text"], input[type="password"], input[type="email"], input[type="date"],
input[type="search"], select, textarea {
    width: 100%;
    padding: 0.65rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 1rem;
    background: var(--surface);
    color: var(--text);
    font-family: inherit;
}
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(201, 138, 74, 0.15);
}

.btn {
    display: inline-block;
    padding: 0.65rem 1.25rem;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    background: var(--primary);
    color: white;
    font-family: inherit;
    transition: background 0.15s;
}
.btn:hover { background: var(--primary-dark); text-decoration: none; }
.btn--secondary { background: var(--surface-alt); color: var(--text); border: 1px solid var(--border); }
.btn--secondary:hover { background: var(--border); }
.btn--danger { background: var(--danger); }
.btn--danger:hover { background: #a93226; }
.btn--sm { padding: 0.35rem 0.8rem; font-size: 0.85rem; }

/* ---------- Login page ---------- */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
    background: linear-gradient(135deg, #faf7f2 0%, #f0e8db 100%);
}
.login-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 2rem;
    box-shadow: 0 8px 32px rgba(43, 38, 35, 0.12);
    width: 100%;
    max-width: 380px;
}
.login-card__title {
    text-align: center;
    margin: 0 0 0.5rem;
    color: var(--primary-dark);
    font-size: 1.5rem;
}
.login-card__sub {
    text-align: center;
    color: var(--text-muted);
    margin: 0 0 1.5rem;
    font-size: 0.95rem;
}
.login-error {
    background: #fae8e6;
    color: var(--danger);
    padding: 0.75rem 1rem;
    border-radius: 8px;
    margin-bottom: 1rem;
    font-size: 0.95rem;
}

/* ---------- Misc ---------- */
.text-muted { color: var(--text-muted); }
.text-danger { color: var(--danger); }
.text-success { color: var(--success); }
.text-warning { color: var(--warning); }
.font-mono { font-family: "SF Mono", "Fira Code", Consolas, monospace; font-size: 0.9em; }
.empty-state {
    text-align: center;
    color: var(--text-muted);
    padding: 2rem;
}
.section-title {
    font-size: 1.15rem;
    color: var(--primary-dark);
    margin: 1.5rem 0 0.75rem;
    border-bottom: 1px solid var(--border);
    padding-bottom: 0.3rem;
}
.section-row {
    display: grid;
    gap: 1.25rem;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    margin-bottom: 1.25rem;
}
.countdown {
    font-size: 2rem;
    font-weight: 800;
    line-height: 1.1;
}
.countdown--red { color: var(--danger); }
.countdown--orange { color: #d35400; }
.countdown--yellow { color: var(--warning); }
.countdown--green { color: var(--success); }
.clickable { cursor: pointer; transition: box-shadow 0.15s; }
.clickable:hover { box-shadow: var(--shadow-hover); }
a.stat, a.stat:hover { color: inherit; }

/* ---------- Toast ---------- */
.toast {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    background: var(--primary-dark);
    color: white;
    padding: 0.75rem 1.25rem;
    border-radius: 8px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.2);
    z-index: 2000;
    font-size: 0.92rem;
    opacity: 0;
    transform: translateY(10px);
    transition: opacity 0.2s, transform 0.2s;
    pointer-events: none;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast--error { background: var(--danger); }

/* ---------- Responsive: table becomes cards on mobile ---------- */
@media (max-width: 680px) {
    .site-header__inner { flex-direction: column; align-items: flex-start; }
    .site-header__nav { font-size: 0.88rem; gap: 0.35rem; }
    .stat__value { font-size: 1.4rem; }

    /* Convert tables to stacked card layout */
    table.responsive { border: none; }
    table.responsive thead { display: none; }
    table.responsive, table.responsive tbody, table.responsive tr, table.responsive td {
        display: block;
        width: 100%;
    }
    table.responsive tr {
        background: var(--surface);
        border: 1px solid var(--border);
        border-radius: var(--radius);
        padding: 0.75rem;
        margin-bottom: 0.75rem;
        box-shadow: var(--shadow);
    }
    table.responsive tr:hover { background: var(--surface); }
    table.responsive td {
        border-bottom: 1px dashed var(--border);
        padding: 0.45rem 0;
        display: flex;
        justify-content: space-between;
        align-items: center;
        gap: 0.75rem;
        text-align: right;
    }
    table.responsive td::before {
        content: attr(data-label);
        font-weight: 600;
        font-size: 0.78rem;
        text-transform: uppercase;
        letter-spacing: 0.04em;
        color: var(--text-muted);
        text-align: left;
    }
    table.responsive td:last-child { border-bottom: none; }
    /* Hide the data-label column header on mobile for expansion control */
    .modal-overlay { padding: 0; align-items: stretch; }
    .modal { border-radius: 0; min-height: 100vh; padding: 1rem; }
}

/* ---------- Phase 3: Finances dashboard ---------- */
.grid-finances {
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    margin-bottom: 1.25rem;
}
.stat-card {
    padding: 1rem 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    margin-bottom: 0;
}
.stat-card__label {
    font-size: 0.78rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    font-weight: 600;
}
.stat-card__value {
    font-size: 1.7rem;
    font-weight: 800;
    color: var(--primary-dark);
    line-height: 1.15;
}
.stat-card__sub {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-top: 0.15rem;
}
.stat-card__sub .badge { margin-right: 0.25rem; font-size: 0.72rem; }
.stat-card__foot {
    font-size: 0.82rem;
    margin-top: 0.2rem;
    min-height: 1.1rem;
}
.stat-card__details { margin-top: 0.5rem; font-size: 0.88rem; }
.stat-card__details summary { cursor: pointer; font-size: 0.8rem; }
.stat-card__details .savings-list {
    list-style: none; padding: 0; margin: 0.4rem 0 0;
}
.stat-card__details .savings-list li {
    display: flex; justify-content: space-between;
    padding: 0.25rem 0; border-bottom: 1px dashed var(--border);
    font-size: 0.82rem;
}
.stat-card__details .savings-list li:last-child { border-bottom: none; }

.stat-card--treasury { border-left: 4px solid var(--accent); }
.stat-card--income   { border-left: 4px solid var(--info); }
.stat-card--expenses { border-left: 4px solid var(--danger); }
.stat-card--savings  { border-left: 4px solid var(--success); }
.stat-card--capital  { border-left: 4px solid var(--purple); }

/* Chart cards */
.chart-card { padding: 1rem 1.25rem; }
.chart-wrap {
    position: relative;
    width: 100%;
    min-height: 220px;
    height: 240px;
}
.chart-wrap--doughnut { height: 260px; }
.chart-wrap canvas { width: 100% !important; }

/* Transaction debit/credit coloring */
.tx-debit { color: var(--danger); font-weight: 600; }
.tx-credit { color: var(--success); font-weight: 600; }
.num { text-align: right; font-variant-numeric: tabular-nums; }

/* Category badge (neutral but warm) */
.badge--cat {
    background: var(--surface-alt);
    color: var(--primary-dark);
    font-size: 0.72rem;
    font-weight: 600;
}
.badge--debit { background: #fae0dc; color: var(--danger); }
.badge--credit { background: #dcf0e4; color: var(--success); }

/* Pagination controls */
.pagination {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin: 1rem 0 2rem;
    padding: 0.75rem 1rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}
.pagination__btns { display: flex; gap: 0.5rem; }

.filter-group--grow { flex: 1 1 200px; }
.filter-group--grow input { width: 100%; }

/* Legitimacy / prélèvement statut colors (reuse existing badges) */
.badge--frauduleux { background: #6b1d14; color: #fff; }
.badge--résilié { background: #d8d4cd; color: #6b6359; }
.badge--contésté { background: #fae0dc; color: var(--danger); }
.badge--légitime { background: #dcf0e4; color: var(--success); }

@media (max-width: 680px) {
    .grid-finances { grid-template-columns: 1fr; }
    .chart-wrap, .chart-wrap--doughnut { height: 200px; }
    .pagination { flex-direction: column; align-items: stretch; }
}