/* =========================================================
   App CAISSE — feuille de style
   Identité Meti-Concept : encre profonde + or Meti (#E5CA17)
   Reprise du design system du Plan financier.
   Type : Fraunces (titres) + Inter Tight (interface)
   ========================================================= */

@import url('https://fonts.googleapis.com/css2?family=Fraunces:opsz,wght@9..144,400;9..144,500;9..144,600;9..144,700&family=Inter+Tight:wght@400;450;500;600;700&display=swap');

:root {
    /* Encre / neutres chauds */
    --ink:        #14161b;
    --ink-1:      #2a2f3a;
    --ink-soft:   #63697a;
    --ink-faint:  #9099ab;
    --line:       #e7e4dc;
    --line-2:     #f0ede6;
    --bg:         #f6f4ee;   /* fond papier ivoire */
    --bg-warm:    #efece3;
    --surface:    #ffffff;
    --surface-2:  #fbfaf6;

    /* Or Meti */
    --gold:       #E5CA17;
    --gold-deep:  #c9ae06;
    --gold-soft:  #fbf4cf;
    --gold-line:  #ecdf9a;

    /* Sémantique */
    --green:      #1f7a4d;
    --green-soft: #e7f2ea;
    --amber:      #b5820a;
    --amber-soft: #fbf1d8;
    --red:        #b23b3b;
    --red-soft:   #f8e9e6;

    /* Rayons & ombres */
    --r-sm: 8px;
    --r:    12px;
    --r-lg: 18px;
    --shadow-xs: 0 1px 0 rgba(20,22,27,.03), 0 1px 2px rgba(20,22,27,.04);
    --shadow:    0 1px 1px rgba(20,22,27,.04), 0 4px 14px -6px rgba(20,22,27,.14);
    --shadow-lg: 0 20px 60px -20px rgba(20,22,27,.35), 0 4px 12px -6px rgba(20,22,27,.18);
    --ring: 0 0 0 3px rgba(229,202,23,.32);
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: 'Inter Tight', system-ui, -apple-system, "Segoe UI", sans-serif;
    background: var(--bg);
    color: var(--ink);
    line-height: 1.5;
}

a { color: var(--ink); text-decoration-color: var(--gold-line); }

h1, h2, h3 {
    font-family: 'Fraunces', Georgia, serif;
    font-weight: 600;
    letter-spacing: -.01em;
    line-height: 1.14;
    font-optical-sizing: auto;
}
h1 { font-size: 1.55rem; margin: 0 0 4px; }
h2 { font-size: 1.2rem; margin: 26px 0 12px; }
.subtitle { color: var(--ink-soft); margin: 0 0 20px; }

/* ---------- Topbar ---------- */
.topbar {
    background: var(--surface);
    border-bottom: 1px solid var(--line);
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 0 clamp(14px, 4vw, 26px);
    height: 60px;
    box-shadow: var(--shadow-xs);
}
.brand { display: flex; align-items: center; gap: 13px; }
.logo-img { height: 26px; width: auto; display: block; }
.brand > div {
    display: flex; flex-direction: column; gap: 1px;
    border-left: 1px solid var(--line);
    padding-left: 13px; margin-left: 2px;
}
.brand-name { font-family: 'Fraunces', serif; font-weight: 600; font-size: 16px; letter-spacing: -.01em; line-height: 1; }
.brand-sub  { font-size: 11.5px; color: var(--ink-soft); letter-spacing: .01em; }

.mainnav { display: flex; align-items: center; gap: 2px; margin-left: 22px; }
.mainnav a {
    color: var(--ink-soft);
    text-decoration: none;
    padding: 8px 13px;
    border-radius: var(--r-sm);
    font-size: .9rem;
    font-weight: 500;
}
.mainnav a:hover { background: var(--bg-warm); color: var(--ink); }
.mainnav a.active { background: var(--ink); color: #fff; }

.spacer { flex: 1; }
.topbar-actions { display: flex; align-items: center; gap: 12px; }
.topbar-actions .user { font-size: .88rem; color: var(--ink-soft); display: flex; align-items: center; gap: 10px; }
.user-link { color: var(--ink); text-decoration: none; font-weight: 600; }
.user-link:hover { color: var(--gold-deep); text-decoration: underline; text-decoration-color: var(--gold); }
.badge-admin {
    background: var(--gold); color: var(--ink);
    font-size: .7rem; font-weight: 700;
    padding: 2px 9px; border-radius: 999px;
    text-transform: uppercase; letter-spacing: .05em;
}
.ctx-caisse {
    background: var(--ink); color: #fff;
    font-size: .82rem; padding: 5px 11px; border-radius: 999px;
    display: inline-flex; align-items: center; gap: 8px;
    border-left: 3px solid var(--gold);
}
.ctx-caisse strong { color: var(--gold); }
.ctx-caisse a { color: #cbd0da; text-decoration: none; font-weight: 700; }
.ctx-caisse a:hover { color: #fff; }

/* ---------- Conteneur ---------- */
.wrap { max-width: 1100px; margin: 30px auto; padding: 0 clamp(14px, 4vw, 20px); }
.wrap-sm { max-width: 430px; }

/* ---------- Cartes ---------- */
.card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--r);
    box-shadow: var(--shadow-xs);
    padding: 24px;
    margin-bottom: 20px;
}

/* ---------- Cartes de solde ---------- */
.soldes {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(178px, 1fr));
    gap: 14px;
    margin-bottom: 24px;
}
.solde-box {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--r);
    padding: 16px 18px;
    box-shadow: var(--shadow-xs);
}
.solde-box .lbl { font-size: .72rem; color: var(--ink-soft); text-transform: uppercase; letter-spacing: .05em; font-weight: 600; }
.solde-box .val { font-size: 1.5rem; font-weight: 700; margin-top: 5px; font-variant-numeric: tabular-nums; }
.solde-box.entree .val { color: var(--green); }
.solde-box.sortie .val { color: var(--red); }
.solde-box.fin {
    background: var(--ink);
    border-color: var(--ink);
    border-left: 3px solid var(--gold);
}
.solde-box.fin .lbl { color: var(--gold); }
.solde-box.fin .val { color: #fff; }
.solde-box.negatif .val { color: #fca5a5 !important; }

/* ---------- Tableaux ---------- */
table { width: 100%; border-collapse: collapse; font-size: .92rem; }
thead th {
    text-align: left;
    padding: 11px 12px;
    background: var(--surface-2);
    color: var(--ink-soft);
    font-weight: 600;
    font-size: .74rem;
    text-transform: uppercase;
    letter-spacing: .04em;
    border-bottom: 1px solid var(--line);
}
tbody td { padding: 11px 12px; border-bottom: 1px solid var(--line-2); }
tbody tr:hover { background: var(--surface-2); }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.pill { display: inline-block; font-size: .73rem; padding: 2px 9px; border-radius: 999px; font-weight: 600; }
.pill.e { background: var(--green-soft); color: var(--green); }
.pill.s { background: var(--red-soft); color: var(--red); }

/* ---------- Formulaires ---------- */
label { display: block; font-size: .84rem; font-weight: 600; margin: 15px 0 6px; color: var(--ink-1); }
input, select, textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: var(--r-sm);
    font-size: .95rem;
    font-family: inherit;
    background: #fff;
    color: var(--ink);
}
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--gold-deep);
    box-shadow: var(--ring);
}
.row { display: flex; gap: 14px; flex-wrap: wrap; }
.row > * { flex: 1; min-width: 140px; }

/* ---------- Boutons ---------- */
.btn {
    display: inline-block;
    background: var(--ink);
    color: #fff;
    border: none;
    padding: 10px 18px;
    border-radius: var(--r-sm);
    font-size: .92rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    text-decoration: none;
    transition: background .15s, transform .15s;
}
.btn:hover { background: #000; transform: translateY(-1px); box-shadow: var(--shadow); }
.btn.gold { background: var(--gold); color: var(--ink); }
.btn.gold:hover { background: var(--gold-deep); }
.btn.secondary { background: #fff; color: var(--ink); border: 1px solid var(--line); }
.btn.secondary:hover { background: var(--bg-warm); box-shadow: none; }
.btn.danger { background: var(--red); }
.btn.danger:hover { background: #8f2f2f; }
.btn.sm { padding: 6px 12px; font-size: .82rem; }
.actions { display: flex; gap: 10px; margin-top: 24px; }

/* ---------- Alertes ---------- */
.alert { padding: 12px 16px; border-radius: var(--r-sm); margin-bottom: 18px; font-size: .92rem; border: 1px solid transparent; }
.alert.ok   { background: var(--green-soft); color: var(--green); border-color: #b7dcc5; }
.alert.err  { background: var(--red-soft); color: var(--red); border-color: #e6c3c3; }
.alert.warn { background: var(--amber-soft); color: #8a6207; border-color: var(--gold-line); }

/* ---------- Sélecteur de période ---------- */
.periode { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 22px; }
.periode select { width: auto; }

/* ---------- Lignes de catégories ---------- */
.cat-row {
    display: flex; align-items: center; justify-content: space-between;
    gap: 14px; flex-wrap: wrap;
    padding: 12px 0; border-bottom: 1px solid var(--line-2);
}
.cat-row.off { opacity: .55; }
.cat-edit { display: flex; align-items: center; gap: 10px; margin: 0; flex-wrap: wrap; }
.cat-edit input, .cat-edit select { width: auto; }
.cat-edit input[name="libelle"] { min-width: 200px; }
.cat-actions { display: flex; align-items: center; gap: 8px; }

/* ---------- Commentaires (fil de discussion) ---------- */
.com-list { display: flex; flex-direction: column; gap: 14px; }
.com { display: flex; gap: 10px; align-items: flex-start; }
.com-av {
    flex: 0 0 auto; width: 34px; height: 34px; border-radius: 50%;
    display: grid; place-items: center; font-weight: 700; font-size: .9rem;
}
.com-body {
    flex: 1; min-width: 0; max-width: 86%;
    border: 1px solid var(--line); border-left: 4px solid var(--line);
    border-radius: 10px; padding: 10px 13px; background: var(--surface-2);
}
.com-meta { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: .85rem; }
.com-role {
    font-size: .68rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em;
    padding: 1px 8px; border-radius: 999px;
}
.com-text { margin: 6px 0 8px; white-space: pre-wrap; }
.com-actions { display: flex; gap: 8px; }

/* Cabinet = or Meti, aligné à droite */
.com.cabinet { flex-direction: row-reverse; }
.com.cabinet .com-av { background: var(--gold); color: var(--ink); }
.com.cabinet .com-body {
    background: var(--gold-soft); border-color: var(--gold-line);
    border-left: 1px solid var(--gold-line); border-right: 4px solid var(--gold);
}
.com.cabinet .com-role { background: var(--gold); color: var(--ink); }

/* Client = bleu ardoise, aligné à gauche */
.com.client .com-av { background: #3b6ea5; color: #fff; }
.com.client .com-body {
    background: #eef3f8; border-color: #d7e3ef; border-left-color: #3b6ea5;
}
.com.client .com-role { background: #3b6ea5; color: #fff; }

.com-badge {
    display: inline-flex; align-items: center; gap: 3px;
    font-size: .78rem; color: var(--ink-soft); text-decoration: none;
    padding: 1px 7px; border-radius: 999px; background: var(--bg-warm);
}
.com-badge:hover { background: var(--gold-soft); color: var(--gold-deep); }

/* ---------- Divers ---------- */
.muted { color: var(--ink-soft); }
.right { text-align: right; }
.center { text-align: center; }
.mono { font-variant-numeric: tabular-nums; }
.empty { text-align: center; color: var(--ink-soft); padding: 44px 0; }

/* ---------- Responsive ---------- */
@media (max-width: 760px) {
    .topbar { height: auto; min-height: 60px; flex-wrap: wrap; gap: 6px 10px; padding: 8px 14px; }
    .brand > div { display: none; }
    .mainnav { margin-left: 0; order: 3; width: 100%; overflow-x: auto; }
    .topbar-actions { margin-left: auto; }
}
