.viz-root {
  color-scheme: light;
  --bg: #f4f3f0;
  --surface-1: #fcfcfb;
  --surface-2: #f0efec;
  --border: #e3e2de;
  --grid: #ebeae6;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #7a7974;
  --accent: #2a78d6;
  --series-1: #2a78d6; --series-2: #eb6834; --series-3: #1baf7a; --series-4: #eda100;
  --series-5: #e87ba4; --series-6: #008300; --series-7: #6250d6; --series-other: #a3a29c;
  --good: #0f7a0f; --critical: #c13434;
  --radius: 10px;
}
:root[data-theme="dark"] .viz-root {
  color-scheme: dark;
  --bg: #121211;
  --surface-1: #1a1a19;
  --surface-2: #232321;
  --border: #2e2e2b;
  --grid: #2a2a27;
  --text-primary: #f0efec;
  --text-secondary: #c3c2b7;
  --text-muted: #8f8e86;
  --accent: #3987e5;
  --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70; --series-4: #c98500;
  --series-5: #d55181; --series-6: #008300; --series-7: #9085e9; --series-other: #6b6a64;
  --good: #3fbf3f; --critical: #e66767;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font: 14px/1.45 Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif; }
.viz-root { background: var(--bg); color: var(--text-primary); min-height: 100vh; }
h2 { font-size: 15px; font-weight: 600; margin: 0; }
h3 { font-size: 13px; font-weight: 600; margin: 0; color: var(--text-secondary); }
.muted { color: var(--text-muted); font-size: 12.5px; }
.num { font-variant-numeric: tabular-nums; }

/* -------- header */
.top {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 24px;
  padding: 12px 28px; background: color-mix(in srgb, var(--surface-1) 92%, transparent);
  border-bottom: 1px solid var(--border); backdrop-filter: blur(8px);
}
.brand { font-weight: 700; letter-spacing: -0.01em; font-size: 16px; }
.tabs { display: flex; gap: 4px; background: var(--surface-2); padding: 3px; border-radius: 9px; }
.tab {
  border: 0; background: none; color: var(--text-secondary); padding: 6px 16px; border-radius: 7px;
  font: inherit; font-weight: 500; cursor: pointer;
}
.tab.active { background: var(--surface-1); color: var(--text-primary); box-shadow: 0 1px 2px rgb(0 0 0 / .08); }
.sync { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.btn {
  font: inherit; font-size: 13px; border: 1px solid var(--border); background: var(--accent); color: #fff;
  border-radius: 8px; padding: 6px 12px; cursor: pointer;
}
.btn.ghost { background: var(--surface-1); color: var(--text-primary); }
.btn:hover { filter: brightness(1.05); }

/* -------- layout */
.tab-panel { max-width: 1320px; margin: 0 auto; padding: 22px 28px 60px; display: flex; flex-direction: column; gap: 18px; }
.grid.two { display: grid; grid-template-columns: 1.6fr 1fr; gap: 18px; }
.card { background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; min-width: 0; }
.card-head { display: flex; align-items: baseline; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.card-head.sub { margin-top: 18px; }
.chart { position: relative; height: 280px; }
.chart.tall { height: 320px; }

/* -------- tiles */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; }
.tile { background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.tile .label { display: flex; align-items: center; gap: 7px; color: var(--text-secondary); font-size: 12.5px; }
.tile .value { font-size: 24px; font-weight: 650; letter-spacing: -0.02em; margin-top: 4px; font-variant-numeric: tabular-nums; }
.tile.hero .value { font-size: 30px; }
.tile .foot { color: var(--text-muted); font-size: 12px; margin-top: 2px; }
.dot { width: 9px; height: 9px; border-radius: 3px; display: inline-block; flex: none; }
.share-track { display: flex; height: 6px; border-radius: 4px; overflow: hidden; gap: 2px; margin-top: 10px; background: var(--surface-1); }
.share-track span { display: block; height: 100%; }

/* -------- legend */
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; margin: -4px 0 10px; font-size: 12.5px; color: var(--text-secondary); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend span[data-label] { cursor: pointer; user-select: none; border-radius: 4px; transition: opacity .15s; }
.legend span[data-label]:hover { color: var(--text-primary); }
.legend span.off { opacity: .4; text-decoration: line-through; }

/* -------- bar lists */
.barlist { display: flex; flex-direction: column; gap: 9px; }
.bar-row { display: grid; grid-template-columns: minmax(110px, 38%) 1fr auto; align-items: center; gap: 10px; font-size: 13px; }
.bar-row .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-secondary); }
.bar-row .track { height: 12px; position: relative; }
.bar-row .fill { position: absolute; top: 0; bottom: 0; border-radius: 0 4px 4px 0; background: var(--series-1); min-width: 2px; }
.bar-row .fill.neg { background: var(--series-2); border-radius: 4px 0 0 4px; }
.bar-row .val { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.bar-row .val small { color: var(--text-muted); margin-left: 6px; }
.bar-row:hover .name { color: var(--text-primary); }

/* -------- tables */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data th {
  text-align: left; font-weight: 500; color: var(--text-muted); font-size: 12px; padding: 6px 10px;
  border-bottom: 1px solid var(--border); white-space: nowrap;
}
table.data td { padding: 8px 10px; border-bottom: 1px solid var(--grid); white-space: nowrap; }
table.data.compact td { padding: 6px 10px; }
table.data td.r, table.data th.r { text-align: right; font-variant-numeric: tabular-nums; }
table.data tr:hover td { background: var(--surface-2); }
table.data tr.group td { background: var(--surface-2); font-weight: 600; }
table.data tr.internal td { color: var(--text-muted); }
td.wrap { white-space: normal; max-width: 340px; }
.delta { font-variant-numeric: tabular-nums; white-space: nowrap; }
.delta.up { color: var(--good); }
.delta.down { color: var(--critical); }
.tag { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-secondary); }
.pill { font-size: 11px; padding: 1px 7px; border-radius: 99px; background: var(--surface-2); color: var(--text-secondary); }

/* -------- filters & tools */
.filters { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; }
.seg { display: flex; background: var(--surface-2); border-radius: 9px; padding: 3px; gap: 2px; }
.seg button { border: 0; background: none; font: inherit; font-size: 13px; padding: 5px 12px; border-radius: 7px; color: var(--text-secondary); cursor: pointer; }
.seg button.active { background: var(--surface-1); color: var(--text-primary); box-shadow: 0 1px 2px rgb(0 0 0 / .08); }
.dates { color: var(--text-secondary); font-size: 13px; display: flex; gap: 6px; align-items: center; }
input, select {
  font: inherit; font-size: 13px; color: var(--text-primary); background: var(--surface-1);
  border: 1px solid var(--border); border-radius: 7px; padding: 5px 8px;
}
.tx-tools { margin-left: auto; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.chk { font-size: 12.5px; color: var(--text-secondary); display: flex; gap: 5px; align-items: center; }
td select { padding: 2px 4px; font-size: 12.5px; max-width: 180px; }

/* -------- dialog */
dialog { border: 1px solid var(--border); border-radius: 12px; background: var(--surface-1); color: var(--text-primary); width: min(680px, 94vw); padding: 18px 20px; }
dialog::backdrop { background: rgb(0 0 0 / .35); }
.dlg-head { display: flex; justify-content: space-between; align-items: center; margin: 0; }
.rule-add { display: flex; gap: 8px; margin: 10px 0 14px; }
.rule-add input { flex: 1; }
.table-wrap.rules { max-height: 50vh; overflow-y: auto; }

.tooltip {
  position: fixed; pointer-events: none; z-index: 20; background: var(--surface-1); color: var(--text-primary);
  border: 1px solid var(--border); border-radius: 8px; padding: 7px 10px; font-size: 12.5px;
  box-shadow: 0 6px 18px rgb(0 0 0 / .12);
}
.empty { color: var(--text-muted); font-size: 13px; padding: 12px 0; }

@media (max-width: 900px) {
  .grid.two { grid-template-columns: 1fr; }
  .top { flex-wrap: wrap; padding: 10px 16px; gap: 12px; }
  .tab-panel { padding: 16px; }
}
.tab-panel[hidden] { display: none; }
.conn { border-top: 1px solid var(--border); padding: 14px 0 6px; }
.conn h3 { color: var(--text-primary); margin-bottom: 6px; }
.steps { padding-left: 18px; margin: 10px 0; font-size: 13px; color: var(--text-secondary); display: grid; gap: 10px; }
code { background: var(--surface-2); padding: 1px 6px; border-radius: 5px; font-size: 12.5px; }
.ok { color: var(--good); } .ko { color: var(--critical); }
.steps[hidden] { display: none; }
.form-row { display: flex; gap: 8px; margin: 8px 0; flex-wrap: wrap; }
.form-row input { flex: 1; min-width: 140px; }
.form-col { display: grid; gap: 8px; margin-top: 8px; max-width: 460px; }
.small { font-size: 12px; }
details summary { cursor: pointer; font-size: 13px; color: var(--accent); margin: 6px 0; }
.form-row[hidden], #tr-login[hidden], #tr-actions[hidden] { display: none; }
a { color: var(--accent); }
.version { font-size: 11px; font-weight: 500; color: var(--text-muted); margin-left: 4px; }
dialog.wide { width: min(980px, 96vw); }
.ai-results { max-height: 55vh; overflow-y: auto; }
td input.kw { width: 160px; }
#ai-cfg[hidden], #ai-apply-row[hidden] { display: none; }
.conf { font-size: 11.5px; color: var(--text-muted); }
.btn.danger { background: var(--critical); color: #fff; border-color: var(--critical); }
input.cat-name { width: 100%; max-width: 260px; }
.tk-edit { padding: 2px 8px; font-size: 12px; }
.wide-form { max-width: none; }
.form-row[hidden], #m-cancel[hidden] { display: none; }
td select.cls-sel { font-size: 12px; padding: 2px 4px; }
#man-table .btn { padding: 3px 8px; font-size: 12px; }
#man-table td.r { white-space: nowrap; }
th.sortable { cursor: pointer; user-select: none; position: relative; }
table.data th { position: relative; }
th.sortable:hover { color: var(--text-primary); }
th.sort-asc::after { content: " ▲"; font-size: 9px; }
th.sort-desc::after { content: " ▼"; font-size: 9px; }
.col-resizer { position: absolute; top: 0; right: -3px; width: 7px; height: 100%; cursor: col-resize; z-index: 2; }
.col-resizer:hover, body.resizing .col-resizer:active { background: color-mix(in srgb, var(--accent) 35%, transparent); }
body.resizing { cursor: col-resize; user-select: none; }
.clip { overflow: hidden; text-overflow: ellipsis; }
#sec-table tbody tr { cursor: pointer; }
.sd-tiles .tile .value { font-size: 20px; }
.pf-grid { grid-template-columns: 1.1fr 1fr; }
.pf-ai { border-left: 1px solid var(--border); padding-left: 18px; }
#pf-review { font-size: 13px; color: var(--text-secondary); max-height: 420px; overflow-y: auto; }
#pf-review p { margin: 6px 0; }
#pf-review ul { margin: 4px 0 8px; padding-left: 18px; }
#pf-review strong { color: var(--text-primary); }
.bar-row .fill.unknown { background: var(--series-other); }
@media (max-width: 900px) { .pf-ai { border-left: 0; padding-left: 0; } }
.pdf-sec { border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; margin: 10px 0; }
.pdf-sec h3 { display: flex; gap: 8px; align-items: center; color: var(--text-primary); margin: 0 0 8px; }
.pdf-sec details summary { margin: 8px 0 4px; }
.pdf-sec .table-wrap { max-height: 240px; overflow-y: auto; }
#pdf-apply-row[hidden] { display: none; }
#sav-card[hidden] { display: none; }
.sav-acc { margin-bottom: 14px; }
.sav-acc h3 { color: var(--text-primary); margin-bottom: 8px; }
.sav-acc .tiles { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
.sav-acc .tile .value { font-size: 19px; }
#pen-card[hidden], #m-ops[hidden] { display: none; }
/* cartes repliables */
.card-toggle { border: 0; background: none; color: var(--text-muted); cursor: pointer; font-size: 13px; padding: 0 4px 0 0;
  width: 18px; transition: transform .15s; align-self: center; }
.card-toggle:hover { color: var(--text-primary); }
.card.collapsed .card-toggle { transform: rotate(-90deg); }
.tab-panel .card > .card-head { cursor: pointer; user-select: none; }
.tab-panel .card > .card-head :is(button, input, select, label) { cursor: auto; }
.tab-panel .card > .card-head button { cursor: pointer; }
.card-sub { font-variant-numeric: tabular-nums; font-weight: 600; font-size: 14px; color: var(--text-primary); display: none; }
.card.collapsed .card-sub { display: inline; }
.card.collapsed > :not(.card-head) { display: none !important; }
.card.collapsed > .card-head { margin-bottom: 0; }
.card.collapsed > .card-head > .muted:not(.card-sub) { display: none; }
.grid > .card.collapsed { align-self: start; }

/* ---- Connexion (passkeys) ---- */
.login-root { display: grid; place-items: center; padding: 24px; }
.login-box { width: min(420px, 100%); background: var(--surface-1); border: 1px solid var(--border, #0001); border-radius: 14px; padding: 28px; display: grid; gap: 14px; }
.login-box h1 { margin: 0; font-size: 22px; }
.login-box section { display: grid; gap: 12px; }
.login-box label { display: grid; gap: 4px; font-size: 13px; }
.login-box input { width: 100%; box-sizing: border-box; }
.login-msg { min-height: 1.2em; margin: 0; font-size: 13px; }
.login-msg.err { color: var(--critical); }
.passkey-list { display: grid; gap: 6px; margin: 8px 0; }
.passkey-row { display: flex; align-items: center; gap: 10px; justify-content: space-between; padding: 8px 10px; background: var(--surface-2); border-radius: 8px; }

/* ======================================================= Mobile (iPhone) */
html { -webkit-text-size-adjust: 100%; background: #f4f3f0; color-scheme: light; }
html[data-theme="dark"] { background: #121211; color-scheme: dark; }
html[data-theme="dark"] body { background-color: #121211; }
body { background: inherit; min-height: 100dvh; }
body { -webkit-tap-highlight-color: transparent; }
.viz-root { padding-left: env(safe-area-inset-left); padding-right: env(safe-area-inset-right); }
.top { padding-top: max(12px, env(safe-area-inset-top)); }
.tab-panel { padding-bottom: max(60px, calc(env(safe-area-inset-bottom) + 40px)); }
.table-wrap { -webkit-overflow-scrolling: touch; }
@media (hover: none) {
  .col-resizer { display: none; }
  table.data tr:hover td { background: none; }
}
@media (max-width: 700px) {
  .top { display: grid; grid-template-columns: 1fr auto; gap: 10px; padding: max(10px, env(safe-area-inset-top)) 12px 10px; }
  .brand { align-self: center; }
  .sync { margin-left: 0; gap: 6px; }
  .sync .lbl, #sync-status { display: none; }
  .sync .btn { min-width: 40px; height: 40px; padding: 0; font-size: 17px; display: inline-grid; place-items: center; }
  .tabs { grid-column: 1 / -1; grid-row: 2; }
  .tab { flex: 1; padding: 8px 0; }
  .tab-panel { padding: 12px 10px 0; gap: 12px; padding-bottom: calc(env(safe-area-inset-bottom) + 40px); }
  .grid.two, .pf-grid { grid-template-columns: 1fr !important; gap: 12px; }
  .card { padding: 14px 12px; border-radius: 12px; }
  .card-head { gap: 8px; }
  .card-head > :is(.seg, button, select, input) { max-width: 100%; }
  .chart { height: 220px; }
  .chart.tall { height: 250px; }
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .tile { min-width: 0; padding: 12px; }
  .tile .value { font-size: 19px; overflow-wrap: anywhere; }
  .bar-row { grid-template-columns: minmax(80px, 34%) 1fr auto; gap: 8px; }
  .seg { overflow-x: auto; max-width: 100%; scrollbar-width: none; }
  .seg::-webkit-scrollbar { display: none; }
  .seg button { white-space: nowrap; flex: 0 0 auto; padding: 7px 12px; }
  .filters { display: flex; flex-direction: column; align-items: stretch; gap: 8px; }
  .dates { flex-wrap: wrap; }
  .dates input { flex: 1; min-width: 0; }
  table.data td, table.data th { padding: 7px 8px; }
  input, select, textarea { font-size: 15px; }
  table.data select { font-size: 12.5px; padding: 3px 4px; }
  .btn { min-height: 36px; }
  .form-row input { min-width: 0; flex: 1 1 140px; }
  /* Boîtes de dialogue en plein écran */
  dialog, dialog.wide {
    width: 100vw; max-width: 100vw; height: 100dvh; max-height: 100dvh; margin: 0; border: 0; border-radius: 0;
    padding: max(12px, env(safe-area-inset-top)) 14px max(16px, env(safe-area-inset-bottom));
    overscroll-behavior: contain;
  }
  .dlg-head { position: sticky; top: calc(-1 * max(12px, env(safe-area-inset-top))); background: var(--surface-1); z-index: 3;
              padding: 6px 0; margin-bottom: 6px; border-bottom: 1px solid var(--border); }
  .dlg-head .btn { min-width: 40px; height: 40px; }
  .table-wrap.rules, .pdf-sec .table-wrap { max-height: none; }
  .tooltip { max-width: calc(100vw - 24px); }
  .login-box { padding: 22px 18px; }
  dialog :is(input, select, textarea) { max-width: 100%; box-sizing: border-box; }
  .form-col { min-width: 0; }
  /* Colonnes secondaires masquées : le détail reste accessible (fiche du titre, édition) */
  #sec-table :is(th, td):is(:nth-child(2), :nth-child(3), :nth-child(5), :nth-child(6), :nth-child(n+9)),
  #items-table :is(th, td):is(:nth-child(2), :nth-child(5)),
  #rec-table :is(th, td):is(:nth-child(2), :nth-child(3), :nth-child(6), :nth-child(7)),
  #merch-table :is(th, td):nth-child(2),
  #tx-table :is(th, td):is(:nth-child(3), :nth-child(5), :nth-child(7)) { display: none; }
  #sec-table td:first-child, #tx-table td.wrap, #items-table td:first-child { white-space: normal; min-width: 110px; }
  #tx-table td.wrap .muted { font-size: 11.5px; }
  #tx-table td:first-child { font-size: 11.5px; padding-right: 2px; }
  #tx-table .yr { display: none; }
  #tx-table select, #items-table select { max-width: 104px; }
  #tx-table select { max-width: 86px; }
  #tx-table td.wrap { min-width: 100px; }
  table.data td, table.data th { padding: 7px 5px; }
}

.pasted-list { display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 0; }
.pill.pasted { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; padding: 3px 4px 3px 10px; }
.pill.pasted .btn { padding: 0 6px; min-height: 0; height: 22px; font-size: 11px; }

/* ---- Dépenses : tarte du mois, catégories cliquables */
.m-pie { display: grid; grid-template-columns: minmax(220px, 1fr) 1.2fr; gap: 18px; align-items: center; }
.m-pie[hidden], #m-bars-box[hidden] { display: none; }
.barlist.clickable .bar-row { cursor: pointer; border-radius: 6px; }
.barlist.clickable .bar-row:hover { background: var(--surface-2); }
.tx-scope { display: inline-flex; align-items: center; gap: 4px; padding: 2px 4px 2px 10px; font-size: 12.5px; }
.tx-scope[hidden] { display: none; }
.tx-scope .btn { padding: 0 6px; height: 22px; min-height: 0; font-size: 11px; }
@media (max-width: 700px) { .m-pie { grid-template-columns: 1fr; } .m-pie .chart.tall { height: 230px; } }

/* ---- Grand écran : cartes placées librement sur deux colonnes (positions calculées en JS) */
.card-board { display: flex; flex-direction: column; gap: 18px; }
@media (min-width: 1200px) {
  .tab-panel { display: flex; }
  .card-board.free { display: block; position: relative; }
  .card-board.free > .card { position: absolute; margin: 0; box-sizing: border-box; transition: left .18s ease, top .18s ease; }
  .card-board.free > .card[hidden] { display: none; }
  .tiles { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  #asset-tiles { grid-template-columns: repeat(6, minmax(0, 1fr)); }
}
@media (min-width: 1600px) { .tab-panel { max-width: 2300px; } }
@media (pointer: fine) and (min-width: 1200px) {
  .card-board > .card > .card-head { cursor: grab; }
  /* La barre de titre englobe la marge haute et les marges latérales : même curseur partout où l'on peut saisir la carte */
  .card-board > .card > .card-head { margin: -18px -20px 12px; padding: 18px 20px 0; border-radius: var(--radius) var(--radius) 0 0; }
  .card-board > .card.collapsed > .card-head { margin-bottom: 0; }
}
.card-board > .card.dragging { z-index: 30; opacity: .94; box-shadow: 0 18px 48px rgb(0 0 0 / .35); transition: none !important; }
.card-drop { position: absolute; z-index: 1; border: 2px dashed var(--accent); border-radius: var(--radius); background: color-mix(in srgb, var(--accent) 10%, transparent); pointer-events: none; box-sizing: border-box; transition: left .12s, top .12s, height .12s; }
body.card-dragging, body.card-dragging * { user-select: none !important; cursor: grabbing !important; }
.layout-choice { align-items: center; gap: 14px; }

/* ---- Cartes compactes (double-clic sur le bas) : listes à hauteur limitée, en-têtes figés */
.card-board > .card { position: relative; }
.card-grip { position: absolute; left: 0; right: 0; bottom: 0; height: 12px; cursor: ns-resize; border-radius: 0 0 var(--radius) var(--radius); }
.card-grip::after { content: ""; position: absolute; left: 50%; bottom: 4px; width: 36px; height: 3px; margin-left: -18px; border-radius: 3px; background: var(--border); opacity: 0; transition: opacity .15s; }
.card:hover > .card-grip::after, body.card-resizing .card-grip::after { opacity: 1; }
body.card-resizing, body.card-resizing * { cursor: ns-resize !important; user-select: none !important; }
.card.collapsed > .card-grip { display: none; }
.card.compact :is(.table-wrap, .barlist) { max-height: var(--list-max, 340px); overflow-y: auto; overscroll-behavior: contain; }
.card.compact .table-wrap thead th { position: sticky; top: 0; z-index: 1; background: var(--surface-1); }
.card.compact :is(.table-wrap, .barlist) { mask-image: linear-gradient(to bottom, #000 calc(100% - 18px), transparent); }
@media (max-width: 700px) { .card-grip { display: none; } }
/* La poignée de redimensionnement de la dernière colonne ne doit pas dépasser du tableau (barre de défilement inutile) */
table.data th:last-child > .col-resizer { right: 0; }
.form-row label.chk { display: inline-flex; align-items: center; gap: 6px; } .form-row label.chk input { flex: none; min-width: 0; }

.sd-hist { margin: 14px 0 0; }
.sd-hist textarea { width: 100%; box-sizing: border-box; font: inherit; font-size: 13px; padding: 8px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface-1); color: var(--text-primary); }

/* -------- 0.31.0 : onglets Investissements / Immobilier */
.t-short { display: none; }
@media (max-width: 700px) {
  .t-full { display: none; }
  .t-short { display: inline; }
  .tab { font-size: 13.5px; }
}
.tile .value.small-val { font-size: 15px; font-weight: 600; line-height: 1.35; }
dl.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0; font-size: 13.5px; }
dl.kv dt { color: var(--text-secondary); }
dl.kv dd { margin: 0; }
table.data tr.sub-row td { border-top: 0; padding-top: 0; }
table.data tr.cur td { background: color-mix(in srgb, var(--accent) 10%, transparent); font-weight: 600; }
table.data tr.past td { color: var(--text-muted); }
table.data tr.clickable-row { cursor: pointer; }
#re-dlg .conn[hidden], #re-events-box[hidden], #rl-cancel[hidden], #rp-del[hidden] { display: none; }
#re-dlg .table-wrap .btn { padding: 3px 8px; font-size: 12px; }
#rl-suggest .btn { padding: 2px 8px; font-size: 12px; margin: 2px 0; }
.card[hidden] { display: none; }
#re-tiles, #inv-tiles { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
.re-note { margin: 10px 0 0; white-space: normal; }
.sd-tiles { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }

.rule-form { display: grid; gap: 10px; margin: 6px 0 4px; }
.rule-form label { display: grid; gap: 4px; font-size: 13px; color: var(--text-secondary); }
.rule-form :is(input, select) { width: 100%; box-sizing: border-box; }
td.nowrap { white-space: nowrap; }

/* Fiche bénéficiaire */
a.txinfo-link { color: inherit; text-decoration: underline dotted; text-underline-offset: 3px; }
a.txinfo-link:hover { color: var(--accent); }
#txinfo-table tr.hl td { background: color-mix(in srgb, var(--accent) 10%, transparent); }
#txinfo-table td.wrap { white-space: normal; max-width: 340px; }
.txinfo-meta { margin: 10px 0; line-height: 1.6; }
.tile .value.small-value { font-size: 15px; }
dialog#txinfo-dlg { width: min(1280px, 96vw); }
#txinfo-table td.wrap:nth-child(3) { max-width: 220px; }

/* ---- Analyse IA ---- */
#an-context { width: 100%; box-sizing: border-box; resize: vertical; font: inherit; font-size: 13px; padding: 8px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface-1); color: var(--text-primary); }
.an-body { line-height: 1.55; max-width: 900px; }
.an-body h3 { font-size: 15px; margin: 18px 0 6px; }
.an-body h3:first-child { margin-top: 0; }
.an-body ul { margin: 4px 0 8px; padding-left: 20px; }
.an-body p { margin: 4px 0 8px; }
table.data tr.selected td { background: var(--surface-2); }
.an-cfg { margin-top: 8px; }
.an-cfg summary { cursor: pointer; }
#an-est p { margin: 6px 0; }

/* ---- Import : lignes non importées (doublons, paiement du solde) ---- */
.pdf-sec:not(.show-dup) tr.pd-skip { display: none; }
tr.pd-skip td { opacity: .55; }
.pd-showdup { margin: 6px 0; }
.small-btn { padding: 3px 10px; font-size: 12px; }

/* ---- Bouton IA occupé ---- */
.btn.busy { cursor: progress; opacity: .85; display: inline-flex; align-items: center; gap: 7px; }
.spin { width: 13px; height: 13px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%;
        display: inline-block; animation: spin .8s linear infinite; flex: none; }
.busy-t { font-variant-numeric: tabular-nums; opacity: .75; font-size: .9em; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spin { animation-duration: 2.4s; } }
.rule-form label.chk { display: flex; flex-direction: row; align-items: center; gap: 8px; flex-wrap: wrap; color: var(--text-primary); }
.rule-form label.chk input { width: auto; }

/* ---- Mode démo */
.demo-banner { position: sticky; top: 0; z-index: 40; display: flex; align-items: center; justify-content: center; gap: 12px; flex-wrap: wrap;
  padding: 8px 14px; background: #b45309; color: #fff; font-size: 13px; }
.demo-banner[hidden] { display: none; }
.demo-banner .btn { min-height: 28px; padding: 3px 12px; }
.demo-banner .btn.ghost { color: #fff; border-color: rgb(255 255 255 / .6); background: transparent; }
.demo-banner .btn:not(.ghost) { background: #fff; color: #b45309; border-color: #fff; }
a.btn { text-decoration: none; display: inline-flex; align-items: center; }

/* Détail des actifs : établissements repliables */
#items-table tr.inst-toggle { cursor: pointer; user-select: none; }
#items-table tr.inst-toggle .caret { display: inline-block; width: 1em; transition: transform .15s; }
#items-table tr.inst-toggle.closed .caret { transform: rotate(-90deg); }
#items-table tr[hidden] { display: none; }

/* Projection du patrimoine (0.46.0) */
.proj-form { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 10px 14px; margin-top: 14px; }
.proj-form label { display: flex; flex-direction: column; gap: 4px; font-size: 12.5px; color: var(--text-secondary); }
.proj-form input { width: 100%; box-sizing: border-box; }
.proj-form input.custom { border-color: var(--accent); }
.proj-tiles { margin-bottom: 10px; }

/* -------- 0.47.0 : santé financière */
.tab-menu-btn { display: none; }
.health-banner {
  display: flex; align-items: center; gap: 16px; background: var(--surface-1); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 10px 18px; cursor: pointer; transition: border-color .15s, box-shadow .15s;
}
.health-banner[hidden] { display: none; }
.health-banner:hover, .health-banner:focus-visible { border-color: var(--accent); box-shadow: 0 2px 10px rgb(0 0 0 / .06); outline: none; }
.health-banner .hl-gauge { flex: none; }
.hb-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.hb-title { font-weight: 650; font-size: 15px; display: flex; align-items: center; gap: 8px; }
.hb-tip { font-size: 13px; color: var(--text-secondary); overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.hb-go { color: var(--accent); font-weight: 600; font-size: 13px; white-space: nowrap; }
.hl-gauge .hl-g-score { font-size: 26px; font-weight: 700; fill: var(--text-primary); font-variant-numeric: tabular-nums; }
.hl-gauge .hl-g-sub { font-size: 9px; fill: var(--text-muted); }
.hl-grade { display: inline-grid; place-items: center; min-width: 22px; height: 22px; padding: 0 6px; border-radius: 6px; color: #fff; font-size: 13px; font-weight: 700; }
.hl-grade.big { min-width: 44px; height: 44px; font-size: 26px; border-radius: 10px; }
.hl-tiles .hl-hero { display: flex; align-items: center; gap: 14px; grid-column: span 2; }
.hl-comps { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 12px; }
.hl-comp { border: 1px solid var(--border); border-radius: 9px; padding: 12px 14px; display: flex; flex-direction: column; gap: 5px; background: var(--surface-1); }
.hl-comp.off { opacity: .6; }
.hl-c-head { display: flex; align-items: center; gap: 7px; font-size: 13px; }
.hl-c-head .muted { margin-left: auto; font-size: 11.5px; white-space: nowrap; }
.hl-c-val { font-size: 22px; font-weight: 650; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.hl-c-bar { height: 7px; border-radius: 4px; background: var(--surface-2); overflow: hidden; }
.hl-c-bar span { display: block; height: 100%; border-radius: 4px; }
.hl-c-score { font-size: 12.5px; }
.hl-c-adv { font-size: 12.5px; color: var(--text-secondary); border-top: 1px solid var(--grid); padding-top: 6px; margin-top: 2px; }
.hl-flow .bar-row.strong .name { color: var(--text-primary); font-weight: 600; }
.hl-flow .bar-row.sep { border-top: 1px solid var(--grid); padding-top: 9px; }
.hl-flow .bar-row.sub .name { padding-left: 12px; }
.hl-flow .fill.neg { border-radius: 0 4px 4px 0; }
ul.hl-alerts { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; font-size: 13px; }
ul.hl-alerts li { display: flex; gap: 8px; align-items: baseline; padding: 8px 10px; border-radius: 8px; background: var(--surface-2); }
ul.hl-alerts li > span { flex: none; width: 14px; text-align: center; }
ul.hl-alerts li.critical > span { color: var(--critical); }
ul.hl-alerts li.warn > span { color: var(--series-4); }
ul.hl-alerts li.info > span { color: var(--accent); }
.hl-kv { margin-top: 12px; font-size: 13px; }
#hl-range { font-size: 12.5px; }
@media (min-width: 1200px) { .hl-tiles { grid-template-columns: repeat(6, minmax(0, 1fr)); } }

/* Mobile : onglets dans un menu déroulant */
@media (max-width: 700px) {
  .tab-menu-btn {
    display: flex; align-items: center; gap: 10px; grid-column: 1 / -1; grid-row: 2; width: 100%;
    font: inherit; font-weight: 600; font-size: 15px; color: var(--text-primary); background: var(--surface-2);
    border: 0; border-radius: 9px; padding: 9px 14px; cursor: pointer; text-align: left;
  }
  .tab-menu-btn .caret { margin-left: auto; color: var(--text-muted); transition: transform .15s; }
  .tab-menu-btn[aria-expanded="true"] .caret { transform: rotate(180deg); }
  .top .tabs {
    display: none; position: absolute; left: 12px; right: 12px; top: calc(100% - 6px); z-index: 10;
    flex-direction: column; gap: 2px; padding: 6px; background: var(--surface-1); border: 1px solid var(--border);
    border-radius: 12px; box-shadow: 0 12px 32px rgb(0 0 0 / .18);
  }
  .top .tabs.open { display: flex; }
  .top .tabs .tab { flex: none; text-align: left; padding: 11px 14px; font-size: 15px; }
  .top .tabs .tab.active { background: var(--surface-2); box-shadow: none; }
  .top .tabs .t-full { display: inline; }
  .top .tabs .t-short { display: none; }
  .health-banner { padding: 10px 12px; gap: 10px; }
  .health-banner .hl-gauge { width: 74px; height: auto; }
  .hb-go { display: none; }
  .hl-tiles .hl-hero { grid-column: 1 / -1; }
  .hl-comps { grid-template-columns: 1fr; }
}

/* 0.48.0 — multi-utilisateur */
.user-badge { font-size: 11px; font-weight: 600; margin-left: 8px; padding: 1px 8px; border-radius: 999px;
  background: var(--surface-2, rgba(127,127,127,.15)); color: var(--text-muted); vertical-align: middle; }
.user-badge[hidden], #conn-users[hidden], #conn-tr[hidden], #conn-mcp[hidden], #eb-cfg[hidden], #ai-key[hidden], #invite-view[hidden] { display: none !important; }
#us-list .form-row { margin: 0; gap: 6px; flex-wrap: wrap; }
