/* Mutuelle santé — feuille de style unique, sans dépendance */
:root {
  color-scheme: light;
  --bg: #f4f4f1;
  --surface: #fcfcfb;
  --surface-2: #f0efec;
  --border: #e2e1dc;
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #6f6e69;
  --primary: #1c5cab;
  --primary-ink: #ffffff;
  --primary-soft: #e3eefc;
  --danger: #d03b3b;
  /* séries (palette validée, ordre d'empilement : reste, sécu, mutuelle, attente) */
  --s-rac: #eb6834;
  --s-ss: #2a78d6;
  --s-mut: #1baf7a;
  --s-att: #eda100;
  /* statuts (réservés, toujours accompagnés d'une icône et d'un libellé) */
  --good: #0ca30c;
  --warning: #fab219;
  --serious: #ec835a;
  --critical: #d03b3b;
  --good-ink: #006300;
  --warning-ink: #7a5200;
  --serious-ink: #9a3a14;
  --critical-ink: #a32424;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 2px 8px rgba(0,0,0,.04);
  --tabbar-h: 0px;
  font-size: 16px;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #121211;
    --surface: #1a1a19;
    --surface-2: #242422;
    --border: #383835;
    --text: #f0efec;
    --text-2: #c3c2b7;
    --muted: #9a998f;
    --primary: #5598e7;
    --primary-ink: #0b0b0b;
    --primary-soft: #1c2a3c;
    --s-rac: #d95926;
    --s-ss: #3987e5;
    --s-mut: #199e70;
    --s-att: #c98500;
    --good-ink: #5fd35f;
    --warning-ink: #fab219;
    --serious-ink: #ec835a;
    --critical-ink: #ef7a7a;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  line-height: 1.45; padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.5rem; margin: 0 0 .25rem; letter-spacing: -.01em; }
h2 { font-size: 1.1rem; margin: 0 0 .75rem; }
h3 { font-size: 1rem; margin: 1rem 0 .5rem; }
p { margin: .25rem 0 .75rem; }
code { font-size: .85em; background: var(--surface-2); padding: .1em .35em; border-radius: 4px; }
code.wrap { word-break: break-all; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.icon { flex: none; }
[hidden] { display: none !important; }

/* --- barre supérieure --- */
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 1rem;
  padding: .6rem 1.25rem; background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: .5rem; font-weight: 700; color: var(--text); white-space: nowrap; }
.brand .icon { color: var(--s-rac); }
.brand:hover { text-decoration: none; }
.mainnav { display: flex; gap: .25rem; flex: 1; }
.mainnav a { padding: .45rem .8rem; border-radius: 8px; color: var(--text-2); font-weight: 500; }
.mainnav a:hover { background: var(--surface-2); text-decoration: none; }
.mainnav a.active { background: var(--primary-soft); color: var(--primary); }
.usermenu { position: relative; margin-left: auto; }
.app-version { margin-left: auto; font-size: .75rem; color: var(--text-2); white-space: nowrap; font-variant-numeric: tabular-nums; }
.app-version + .usermenu { margin-left: 0; }
.usermenu summary { list-style: none; display: flex; align-items: center; gap: .5rem; cursor: pointer; padding: .25rem; border-radius: 999px; }
.usermenu summary::-webkit-details-marker { display: none; }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--primary); color: var(--primary-ink); display: grid; place-items: center; font-weight: 700; }
.usermenu .menu {
  position: absolute; right: 0; top: calc(100% + 6px); min-width: 230px; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius); box-shadow: 0 8px 24px rgba(0,0,0,.12); padding: .4rem; z-index: 30;
}
.usermenu .menu a, .usermenu .menu .linklike { display: block; width: 100%; text-align: left; padding: .5rem .7rem; border-radius: 8px; color: var(--text); font: inherit; }
.usermenu .menu a:hover, .usermenu .menu .linklike:hover { background: var(--surface-2); text-decoration: none; }
.menu-head { padding: .5rem .7rem; font-weight: 600; border-bottom: 1px solid var(--border); margin-bottom: .3rem; }
.menu-head small { display: block; font-weight: 400; color: var(--muted); }
.linklike { background: none; border: 0; cursor: pointer; }

/* --- barre d'onglets mobile --- */
.tabbar { display: none; }

/* --- mise en page --- */
.container { max-width: 1240px; margin: 0 auto; padding: 1.25rem; }
.container.narrow { max-width: 440px; padding-top: 8vh; }
.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.page-head p { margin: 0; }
.back { display: inline-block; font-size: .875rem; margin-bottom: .25rem; }
.actions, .actions-bar { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.actions-bar { margin: 1rem 0; justify-content: flex-end; }
.actions-bar form { margin: 0; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; margin-bottom: 1rem; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1.1rem 1.2rem; box-shadow: var(--shadow); margin-bottom: 1rem; min-width: 0;
}
.grid-2 > .card { margin-bottom: 0; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: .5rem; margin-bottom: .5rem; }
.card-head h2 { margin: 0; }
.empty { text-align: center; padding: 2.5rem 1rem; }
.narrow-card { max-width: 480px; }

/* --- boutons --- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem; min-height: 40px;
  padding: .5rem 1rem; border-radius: 9px; border: 1px solid var(--border); background: var(--surface);
  color: var(--text); font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn-primary:hover { background: var(--primary); filter: brightness(1.08); }
.btn-danger { color: var(--critical-ink); border-color: var(--critical); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--primary); }
.btn-small { min-height: 32px; padding: .3rem .7rem; font-size: .875rem; }
.btn-block { width: 100%; }
summary.btn { list-style: none; }
summary.btn::-webkit-details-marker { display: none; }

/* --- formulaires --- */
.form label { display: flex; flex-direction: column; gap: .3rem; font-weight: 500; font-size: .925rem; margin-bottom: .8rem; }
.form label.check, label.check { flex-direction: row; align-items: flex-start; gap: .55rem; font-weight: 400; }
label.check input { margin-top: .25rem; width: 18px; height: 18px; flex: none; }
input[type=text], input[type=password], input[type=date], input[type=number], input[type=search], input[type=email], select, textarea {
  font: inherit; font-size: 1rem; padding: .55rem .7rem; border: 1px solid var(--border); border-radius: 9px;
  background: var(--surface); color: var(--text); min-height: 42px; width: 100%;
}
input:focus, select:focus, textarea:focus, .btn:focus-visible, a:focus-visible, summary:focus-visible { outline: 2px solid var(--primary); outline-offset: 1px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 1rem; }
.span-2 { grid-column: 1 / -1; }
.form-row { display: flex; gap: .75rem; flex-wrap: wrap; align-items: flex-end; }
.form-row label { flex: 1 1 150px; }
.form-inline { display: flex; gap: .5rem; align-items: flex-end; flex-wrap: wrap; margin-top: .5rem; }
.form-inline label { display: flex; gap: .4rem; align-items: center; }
.form-inline input { width: 110px; min-height: 34px; }
fieldset { border: 1px solid var(--border); border-radius: var(--radius); padding: .75rem 1rem; margin: 0 0 1rem; }
legend { font-weight: 600; padding: 0 .3rem; }
.checks { display: flex; gap: 1rem; flex-wrap: wrap; }
.inline-form { margin-top: 1rem; }
.inline-form[open] summary { margin-bottom: .75rem; }

/* --- filtres --- */
.filters { display: flex; flex-wrap: wrap; gap: .6rem; align-items: flex-end; margin-bottom: 1rem; }
.filters label { display: flex; flex-direction: column; gap: .2rem; font-size: .8rem; color: var(--muted); font-weight: 500; }
.filters select, .filters input { min-height: 38px; padding: .35rem .6rem; font-size: .95rem; width: auto; min-width: 120px; }
.filters .f-search input { min-width: 220px; }
.f-dates { display: contents; }
.js .filters button[type=submit] { display: none; }

/* --- messages --- */
.flash { padding: .7rem 1rem; border-radius: 9px; margin-bottom: 1rem; border: 1px solid; }
.flash-success { background: color-mix(in srgb, var(--good) 10%, var(--surface)); border-color: color-mix(in srgb, var(--good) 40%, transparent); }
.flash-error { background: color-mix(in srgb, var(--critical) 10%, var(--surface)); border-color: color-mix(in srgb, var(--critical) 45%, transparent); }
.flash-info { background: var(--primary-soft); border-color: color-mix(in srgb, var(--primary) 35%, transparent); }
.warnings { margin: .5rem 0; padding-left: 1.2rem; color: var(--warning-ink); font-size: .9rem; }

/* --- badges & étiquettes --- */
.badge {
  display: inline-flex; align-items: center; gap: .3rem; padding: .12rem .5rem; border-radius: 999px;
  font-size: .78rem; font-weight: 600; white-space: nowrap; border: 1px solid;
}
.badge-good { color: var(--good-ink); border-color: var(--good); background: color-mix(in srgb, var(--good) 10%, transparent); }
.badge-warning { color: var(--warning-ink); border-color: var(--warning); background: color-mix(in srgb, var(--warning) 14%, transparent); }
.badge-serious { color: var(--serious-ink); border-color: var(--serious); background: color-mix(in srgb, var(--serious) 12%, transparent); }
.badge-critical { color: var(--critical-ink); border-color: var(--critical); background: color-mix(in srgb, var(--critical) 10%, transparent); }
.badge-neutral { color: var(--text-2); border-color: var(--border); background: var(--surface-2); }
.tag { display: inline-block; font-size: .72rem; font-weight: 700; padding: .1rem .45rem; border-radius: 6px; text-transform: uppercase; letter-spacing: .03em; margin-right: .3rem; }
.tag-ameli { background: color-mix(in srgb, var(--s-ss) 15%, transparent); color: var(--s-ss); }
.tag-mutuelle { background: color-mix(in srgb, var(--s-mut) 15%, transparent); color: var(--text-2); }
.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 3px; background: var(--c); margin-right: .4rem; vertical-align: baseline; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--c); margin-right: .35rem; }

/* --- indicateurs --- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: .75rem; margin-bottom: 1rem; }
.kpi {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: .9rem 1rem; box-shadow: var(--shadow); color: var(--text); display: block;
}
.kpi-label { font-size: .82rem; color: var(--text-2); font-weight: 600; display: flex; align-items: center; gap: .1rem; }
.kpi-value { font-size: 1.55rem; font-weight: 700; letter-spacing: -.02em; margin: .2rem 0; font-variant-numeric: tabular-nums; }
.kpi-sub { font-size: .8rem; color: var(--muted); }
.kpi-hero { border-color: color-mix(in srgb, var(--s-rac) 55%, var(--border)); }
.kpi-hero .kpi-value { font-size: 1.8rem; }
.kpi-link:hover { text-decoration: none; border-color: var(--primary); }
.kpi-alert { border-color: var(--critical); }

/* --- graphiques --- */
.chart-card .chart-box { position: relative; height: 340px; }
.legend { list-style: none; display: flex; flex-wrap: wrap; gap: .3rem 1rem; padding: 0; margin: 0 0 .5rem; font-size: .85rem; color: var(--text-2); }
.table-details { margin-top: .75rem; }
.table-details summary { cursor: pointer; color: var(--primary); font-size: .9rem; }

/* --- tableaux --- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table { width: 100%; border-collapse: collapse; font-size: .92rem; }
.table th { text-align: left; font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; border-bottom: 1px solid var(--border); padding: .5rem .5rem; white-space: nowrap; }
.table td { border-bottom: 1px solid var(--border); padding: .55rem .5rem; vertical-align: top; }
.table tr:last-child td { border-bottom: 0; }
.table.compact td, .table.compact th { padding: .35rem .45rem; }
.table.num td, .table.num th { font-variant-numeric: tabular-nums; }
.table.num td:not(:first-child), .table.num th:not(:first-child) { text-align: right; white-space: nowrap; }
.table tr.inactive td { opacity: .55; }
.table td.r, .table th.r { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.row-actions { display: flex; gap: .3rem; justify-content: flex-end; flex-wrap: wrap; }
.row-actions form { margin: 0; }
.plain { list-style: none; padding: 0; margin: 0; }
.plain li { padding: .25rem 0; }

/* --- liste des dépenses --- */
.sumbar { display: flex; flex-wrap: wrap; gap: .5rem 1.5rem; padding: .75rem 1rem; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: .75rem; }
.sumbar div { display: flex; flex-direction: column; font-variant-numeric: tabular-nums; }
.sumbar span { font-size: .78rem; }
.dep-list { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.dep-row {
  display: grid; grid-template-columns: 76px minmax(0, 2.6fr) minmax(0, 1fr) 96px 96px 96px 104px 168px;
  gap: .6rem; align-items: center; padding: .6rem 1rem; font-variant-numeric: tabular-nums;
}
.dep-head { font-size: .75rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; border-bottom: 1px solid var(--border); background: var(--surface-2); }
.dep-row .r { text-align: right; }
.dep-month { padding: .45rem 1rem; font-weight: 700; font-size: .85rem; background: var(--surface-2); border-bottom: 1px solid var(--border); border-top: 1px solid var(--border); color: var(--text-2); }
.dep-group { border-bottom: 1px solid var(--border); }
.dep-group:last-child { border-bottom: 0; }
.dep-group > summary { list-style: none; cursor: pointer; }
.dep-group > summary::-webkit-details-marker { display: none; }
.dep-group > summary:hover { background: var(--surface-2); }
.dep-group[open] > summary { background: var(--primary-soft); }
.d-title { display: flex; gap: .55rem; align-items: center; min-width: 0; }
.d-title > span:last-child { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.d-meta { display: none; }
.d-prov { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cat-icon { width: 30px; height: 30px; border-radius: 8px; background: var(--surface-2); display: grid; place-items: center; flex: none; font-size: 1rem; }
.d-person { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dep-lines { padding: .5rem 1rem 1rem; background: var(--surface); }
.pager { display: flex; gap: .3rem; flex-wrap: wrap; justify-content: center; margin: 1rem 0; }
.pager a { min-width: 38px; height: 38px; display: grid; place-items: center; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); }
.pager a.active { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); }

.mini-list { list-style: none; padding: 0; margin: 0; }
.mini-list li { border-bottom: 1px solid var(--border); }
.mini-list li:last-child { border-bottom: 0; }
.mini-list a { display: flex; justify-content: space-between; gap: .75rem; padding: .6rem 0; color: var(--text); align-items: center; }
.mini-list a:hover { text-decoration: none; background: var(--surface-2); }
.ml-main { display: flex; flex-direction: column; min-width: 0; }
.ml-title { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ml-side { display: flex; flex-direction: column; align-items: flex-end; gap: .2rem; white-space: nowrap; font-variant-numeric: tabular-nums; }

/* --- fiche dépense --- */
.breakdown, .info { margin: 0; }
.breakdown div, .info div { display: flex; justify-content: space-between; gap: 1rem; padding: .45rem 0; border-bottom: 1px dashed var(--border); }
.breakdown dd, .info dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }
.info dd { text-align: right; max-width: 65%; overflow-wrap: anywhere; }
.breakdown dt, .info dt { color: var(--text-2); }
.breakdown .sub { font-size: .85rem; border-bottom-style: none; padding-top: 0; }
.breakdown .sub dt, .breakdown .sub dd { color: var(--muted); }
.breakdown .total { border-bottom: 0; border-top: 2px solid var(--text); margin-top: .3rem; font-weight: 700; font-size: 1.1rem; }

/* --- import --- */
.dropzone { border: 2px dashed var(--border); text-align: center; transition: border-color .15s, background .15s; }
.dropzone.drag { border-color: var(--primary); background: var(--primary-soft); }
.dz-inner { max-width: 560px; margin: 0 auto; padding: 1rem 0; }
.dz-inner .icon { width: 36px; height: 36px; color: var(--primary); }
.dz-inner input[type=file] { margin: .75rem auto; display: block; max-width: 100%; }
.dz-files { list-style: none; padding: 0; font-size: .875rem; color: var(--text-2); }
.preview details { margin: .5rem 0; }
.preview summary { cursor: pointer; color: var(--primary); }

.unlinked { border-top: 1px solid var(--border); padding: .75rem 0; }
.unlinked:first-of-type { border-top: 0; }
.ul-head { display: flex; justify-content: space-between; gap: 1rem; align-items: flex-start; }
.cand { display: flex; justify-content: space-between; gap: .5rem; align-items: center; padding: .3rem 0; }
.cand form { margin: 0; }

.subnav { display: flex; gap: .3rem; flex-wrap: wrap; margin-bottom: 1rem; }
.subnav a { padding: .35rem .8rem; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); color: var(--text-2); font-size: .9rem; }
.subnav a.active { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); }
.person-card h2 small { font-weight: 400; font-size: .85rem; }

/* --- connexion --- */
.login-card { text-align: center; padding: 2rem 1.5rem; }
.login-card .form { text-align: left; margin-top: 1.5rem; }
.login-logo { width: 56px; height: 56px; border-radius: 16px; background: var(--primary-soft); color: var(--s-rac); display: grid; place-items: center; margin: 0 auto 1rem; }
.login-logo .icon { width: 30px; height: 30px; }

/* ========== tablette ========== */
@media (max-width: 1100px) {
  .dep-row { grid-template-columns: 70px minmax(0, 2fr) minmax(0, .9fr) 88px 88px 88px 96px; }
  .dep-row .d-status { display: none; }
  .dep-head span:last-child { display: none; }
}

/* ========== mobile ========== */
@media (max-width: 760px) {
  :root { --tabbar-h: 64px; }
  .container { padding: .9rem .75rem; }
  h1 { font-size: 1.3rem; }
  .topbar { padding: .5rem .9rem; }
  .mainnav { display: none; }
  .usermenu .uname { display: none; }
  .tabbar {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 25; height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom); background: var(--surface); border-top: 1px solid var(--border);
  }
  .tabbar a { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .15rem; color: var(--muted); font-size: .7rem; font-weight: 600; }
  .tabbar a.active { color: var(--primary); }
  .tabbar a:hover { text-decoration: none; }
  .tabbar .icon { width: 22px; height: 22px; }
  .page-head .actions .btn { min-height: 38px; padding: .4rem .8rem; }
  .grid-2, .form-grid { grid-template-columns: 1fr; }
  .card { padding: .9rem; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .5rem; }
  .kpi { padding: .7rem .8rem; }
  .kpi-value { font-size: 1.2rem; }
  .kpi-hero { grid-column: 1 / -1; }
  .kpi-hero .kpi-value { font-size: 1.6rem; }
  .chart-card .chart-box { height: 240px; }

  .filters { gap: .4rem; }
  .filters label { flex: 1 1 calc(50% - .4rem); }
  .filters select, .filters input { width: 100%; min-width: 0; }
  .filters .f-search { flex-basis: 100%; }
  .filters .f-search input { min-width: 0; }

  .sumbar { gap: .4rem 1rem; font-size: .9rem; }
  .dep-head { display: none; }
  .dep-row {
    grid-template-columns: minmax(0, 1fr) auto; grid-template-areas:
      "title reste" "meta status";
    gap: .15rem .75rem; padding: .7rem .8rem;
  }
  .d-title { grid-area: title; }
  .d-reste { grid-area: reste; }
  .d-date, .d-person { display: none; }
  .d-paye, .d-ss, .d-mut { display: none !important; }
  .dep-row .d-status { display: block; grid-area: status; text-align: right; }
  .d-meta { display: block; font-size: .8rem; }
  .d-prov { font-size: .78rem; }
  .dep-lines { padding: .4rem .6rem .8rem; }
  .dep-lines .table { font-size: .8rem; }

  .info dd { max-width: 60%; }
  .actions-bar { justify-content: stretch; }
  .actions-bar > * { flex: 1; }
  .actions-bar .btn { width: 100%; }
  .ul-head { flex-direction: column; }
  .cand { flex-direction: column; align-items: flex-start; }
}

@media (forced-colors: active) {
  .swatch, .dot { forced-color-adjust: none; border: 1px solid CanvasText; }
}
@media print {
  .topbar, .tabbar, .filters, .actions, .actions-bar, .btn { display: none !important; }
  body { background: #fff; }
  .card { box-shadow: none; break-inside: avoid; }
}
