:root {
  --bg: #f4f5f7;
  --card-bg: #ffffff;
  --text: #1c1e21;
  --text-muted: #6b7280;
  --border: #e5e7eb;
  --primary: #2563eb;
  --primary-light: #eff4ff;
  --error-bg: #fef2f2;
  --error-text: #b91c1c;
  --error-border: #fecaca;
  --radius: 14px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #14161a;
    --card-bg: #1e2126;
    --text: #f0f1f3;
    --text-muted: #9aa0ab;
    --border: #2c3036;
    --primary: #5b8def;
    --primary-light: #1c2636;
    --error-bg: #2a1616;
    --error-text: #f87171;
    --error-border: #4c1f1f;
  }
}

:root[data-theme="dark"] {
  --bg: #14161a;
  --card-bg: #1e2126;
  --text: #f0f1f3;
  --text-muted: #9aa0ab;
  --border: #2c3036;
  --primary: #5b8def;
  --primary-light: #1c2636;
  --error-bg: #2a1616;
  --error-text: #f87171;
  --error-border: #4c1f1f;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.page {
  max-width: 560px;
  margin: 0 auto;
  padding: 32px 16px 48px;
}

.breadcrumb {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 16px;
}

.breadcrumb a {
  color: var(--text-muted);
  text-decoration: none;
}

.breadcrumb a:hover {
  color: var(--primary);
  text-decoration: underline;
}

.breadcrumb .lang-link {
  float: right;
}

/* Contient le flottant pour ne pas décaler le titre */
.breadcrumb {
  display: flow-root;
}

.header {
  text-align: center;
  margin-bottom: 24px;
}

.header h1 {
  font-size: 1.6rem;
  margin: 0 0 6px;
}

.subtitle {
  color: var(--text-muted);
  margin: 0;
  font-size: 0.95rem;
}

.intro {
  color: var(--text-muted);
  margin: 10px 0 0;
  font-size: 0.85rem;
  line-height: 1.5;
}

.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
}

.ad-slot {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100px;
  border: 1px dashed var(--border);
  border-radius: 10px;
  color: var(--text-muted);
  font-size: 0.75rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.ad-slot-top {
  margin-bottom: 20px;
}

.ad-slot-bottom {
  margin-top: 20px;
}

.field {
  margin-bottom: 18px;
}

.field label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--text-muted);
}

.input-group {
  display: flex;
  align-items: center;
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  background: var(--bg);
  transition: border-color 0.15s ease;
}

.input-group:focus-within {
  border-color: var(--primary);
}

.input-group input {
  flex: 1;
  border: none;
  background: transparent;
  padding: 12px 14px;
  font-size: 1rem;
  color: var(--text);
  min-width: 0;
}

.input-group input:focus {
  outline: none;
}

.input-group .unit {
  padding: 0 14px;
  color: var(--text-muted);
  font-size: 0.9rem;
  border-left: 1px solid var(--border);
  align-self: stretch;
  display: flex;
  align-items: center;
}

.tabs {
  display: flex;
  gap: 6px;
  background: var(--bg);
  padding: 4px;
  border-radius: 10px;
  margin-bottom: 20px;
}

.tab {
  flex: 1;
  border: none;
  background: transparent;
  padding: 10px 8px;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  border-radius: 8px;
  cursor: pointer;
  line-height: 1.3;
}

.tab.active {
  background: var(--card-bg);
  color: var(--primary);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.panel.hidden {
  display: none;
}

.error {
  background: var(--error-bg);
  border: 1px solid var(--error-border);
  color: var(--error-text);
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 0.85rem;
  margin-bottom: 18px;
}

.error.hidden {
  display: none;
}

.result {
  background: var(--primary-light);
  border-radius: 12px;
  padding: 20px;
}

.result-main {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding-bottom: 16px;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

.result-label {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.result-value {
  font-size: 2rem;
  font-weight: 700;
  color: var(--primary);
}

.result-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.result-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.result-item-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.result-item-value {
  font-size: 1.1rem;
  font-weight: 600;
}

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

/* ───────── Guide d'utilisation ───────── */

.guide {
  margin-top: 24px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  font-size: 0.95rem;
  line-height: 1.6;
}

.guide h2 {
  font-size: 1.25rem;
  margin: 0 0 4px;
}

.guide h3 {
  font-size: 1.05rem;
  color: var(--primary);
  margin: 24px 0 8px;
}

.guide h4 {
  font-size: 0.95rem;
  margin: 16px 0 4px;
}

.guide p {
  margin: 0 0 12px;
}

.guide ol,
.guide ul {
  margin: 0 0 12px;
  padding-left: 22px;
}

.guide li {
  margin-bottom: 6px;
}

.guide li ul {
  margin-top: 6px;
}

.guide .formula {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.85rem;
  background: var(--primary-light);
  border-radius: 8px;
  padding: 10px 14px;
  overflow-x: auto;
}

.guide .faq h4:first-child {
  margin-top: 0;
}

.guide .faq p:last-child {
  margin-bottom: 0;
}

.guide a {
  color: var(--primary);
}

/* ───────── Suivi de portefeuille ───────── */

:root { --gain: #15803d; --loss: #b91c1c; --gain-bg: #ecfdf3; --loss-bg: #fef2f2; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) { --gain: #4ade80; --loss: #f87171; --gain-bg: #14251b; --loss-bg: #2a1616; }
}
:root[data-theme="dark"] { --gain: #4ade80; --loss: #f87171; --gain-bg: #14251b; --loss-bg: #2a1616; }

.page.wide { max-width: 1040px; }
.card + .card { margin-top: 20px; }
.card h2 { font-size: 1.1rem; margin: 0 0 14px; display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.card h2 small { font-size: 0.8rem; font-weight: 400; color: var(--text-muted); }

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; }
.tile { background: var(--primary-light); border-radius: 12px; padding: 14px 16px; }
.tile-label { display: block; font-size: 0.75rem; color: var(--text-muted); margin-bottom: 4px; }
.tile-value { display: block; font-size: 1.3rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.tile-sub { display: block; font-size: 0.8rem; margin-top: 2px; font-variant-numeric: tabular-nums; }

.pos { color: var(--gain); }
.neg { color: var(--loss); }

.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px 14px; }
.form-grid .field { margin-bottom: 0; }
.form-grid .field.span2 { grid-column: span 2; }
.input, .form-grid select {
  width: 100%; border: 1px solid var(--border); border-radius: 10px; background: var(--bg); color: var(--text);
  padding: 10px 12px; font-size: 0.95rem; font-family: inherit;
}
.input:focus, .form-grid select:focus { outline: none; border-color: var(--primary); }
.hint { font-size: 0.8rem; color: var(--text-muted); margin: 10px 0 0; min-height: 1.2em; }
.form-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 16px; }

.btn {
  border: 1px solid var(--primary); background: var(--primary); color: #fff; border-radius: 10px;
  padding: 10px 16px; font-size: 0.9rem; font-weight: 600; font-family: inherit; cursor: pointer;
}
.btn.secondary { background: transparent; color: var(--primary); }
.btn.small { padding: 6px 10px; font-size: 0.8rem; }
.btn.danger { border-color: var(--loss); color: var(--loss); background: transparent; }
.btn:focus-visible { outline: 3px solid var(--primary); outline-offset: 2px; }
.btn[hidden] { display: none; }
.icon-btn { border: none; background: none; cursor: pointer; padding: 4px 6px; border-radius: 6px; color: var(--text-muted); font-size: 0.95rem; }
.icon-btn:hover { background: var(--primary-light); color: var(--primary); }

.segmented { display: inline-flex; gap: 4px; background: var(--bg); padding: 4px; border-radius: 10px; }
.segmented button { border: none; background: transparent; padding: 7px 12px; font-size: 0.85rem; font-weight: 600; color: var(--text-muted); border-radius: 8px; cursor: pointer; font-family: inherit; }
.segmented button.active { background: var(--card-bg); color: var(--primary); box-shadow: 0 1px 3px rgba(0,0,0,.08); }

.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; border: 1px solid var(--border); border-radius: 10px; }
table.data { width: 100%; border-collapse: collapse; font-size: 0.88rem; font-variant-numeric: tabular-nums; }
table.data th, table.data td { padding: 9px 10px; text-align: right; white-space: nowrap; border-bottom: 1px solid var(--border); }
table.data th { font-size: 0.75rem; color: var(--text-muted); font-weight: 600; background: var(--bg); position: sticky; top: 0; }
table.data th:first-child, table.data td:first-child, table.data td.left, table.data th.left { text-align: left; }
table.data tbody tr:last-child td { border-bottom: none; }
table.data tfoot td { font-weight: 700; border-top: 2px solid var(--border); border-bottom: none; }
table.data .sub { display: block; font-size: 0.75rem; color: var(--text-muted); white-space: normal; max-width: 220px; }
table.data input.price { width: 92px; text-align: right; padding: 5px 8px; border: 1px solid var(--border); border-radius: 7px; background: var(--bg); color: var(--text); font: inherit; }
table.data input.price:focus { outline: none; border-color: var(--primary); }
.badge { display: inline-block; font-size: 0.72rem; font-weight: 700; padding: 2px 8px; border-radius: 999px; }
.badge.achat { background: var(--primary-light); color: var(--primary); }
.badge.vente { background: var(--loss-bg); color: var(--loss); }
.badge.dividende { background: var(--gain-bg); color: var(--gain); }
.empty { text-align: center; color: var(--text-muted); padding: 22px 10px !important; white-space: normal !important; }

.alloc { display: grid; gap: 8px; margin-top: 16px; }
.alloc-row { display: grid; grid-template-columns: minmax(80px, 160px) 1fr 52px; align-items: center; gap: 10px; font-size: 0.82rem; }
.alloc-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.alloc-track { height: 10px; background: var(--bg); border-radius: 999px; overflow: hidden; }
.alloc-bar { height: 100%; background: var(--primary); border-radius: 999px; }
.alloc-pct { text-align: right; color: var(--text-muted); font-variant-numeric: tabular-nums; }

.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.toolbar .grow { flex: 1; }
.tax-row { display: flex; align-items: center; gap: 8px; font-size: 0.85rem; color: var(--text-muted); margin-top: 12px; flex-wrap: wrap; }
.tax-row input { width: 70px; }
.note { font-size: 0.8rem; color: var(--text-muted); margin: 12px 0 0; line-height: 1.5; }
.section-gap { margin-top: 20px; }

@media (max-width: 560px) {
  .form-grid .field.span2 { grid-column: auto; }
  .card { padding: 18px 14px; }
}

/* ───────── Suivi de comptes / solde prévisionnel ───────── */

.tile.big .tile-value { font-size: 1.6rem; }
.month-nav { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.month-nav .month-title { font-size: 1.05rem; font-weight: 700; min-width: 150px; text-align: center; text-transform: capitalize; }
.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.filters select { width: auto; padding: 6px 10px; font-size: 0.85rem; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.chip { background: var(--bg); border: 1px solid var(--border); border-radius: 999px; padding: 4px 12px; font-size: 0.8rem; font-variant-numeric: tabular-nums; }
.chip b { font-weight: 700; }
table.data td.chk { width: 34px; text-align: center; }
table.data td.chk input { width: 18px; height: 18px; cursor: pointer; accent-color: var(--gain); }
table.data tr.is-paid td { color: var(--text-muted); }
table.data tr.is-paid td.lbl { text-decoration: line-through; text-decoration-color: var(--gain); }
table.data tr.is-skip td:not(.act) { opacity: 0.45; text-decoration: line-through; }
table.data td.act { white-space: nowrap; }
table.data input.cell { width: 100%; min-width: 90px; padding: 5px 8px; border: 1px solid var(--border); border-radius: 7px; background: var(--bg); color: var(--text); font: inherit; }
table.data input.cell.num { width: 110px; min-width: 0; text-align: right; }
table.data input.cell:focus { outline: none; border-color: var(--primary); }
table.data select.cell { padding: 5px 8px; border: 1px solid var(--border); border-radius: 7px; background: var(--bg); color: var(--text); font: inherit; }
.badge.rec { background: var(--primary-light); color: var(--primary); }
.badge.one { background: var(--bg); color: var(--text-muted); border: 1px solid var(--border); }
.badge.late { background: var(--loss-bg); color: var(--loss); }
.badge.skip { background: var(--bg); color: var(--text-muted); }
.warn { color: var(--loss); font-weight: 600; }
.status-btn { border: 1px solid var(--border); background: transparent; color: var(--text-muted); border-radius: 999px; padding: 3px 10px; font-size: 0.75rem; font-family: inherit; cursor: pointer; }
.status-btn:hover { border-color: var(--primary); color: var(--primary); }
.status-btn.on { border-color: var(--loss); color: var(--loss); }
.add-bank { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 14px; }
.add-bank .input { flex: 1 1 160px; width: auto; }
.form-grid .field.hidden { display: none; }
.check-line { display: flex; align-items: center; gap: 8px; font-size: 0.88rem; margin-top: 12px; }
.check-line input { width: 18px; height: 18px; accent-color: var(--gain); }
.toast { font-size: 0.85rem; color: var(--gain); margin: 10px 0 0; min-height: 1.2em; }

/* ───────── Onglets (style navigateur) ───────── */

.tabbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: flex-end; gap: 2px;
  margin: 0; padding: 8px 10px 0; border-radius: 0;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
.tabbar .tab {
  flex: 0 1 230px; min-width: 0;
  position: relative;
  display: flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 16px 11px;
  font-size: 0.88rem; font-weight: 600; line-height: 1.25; text-align: center;
  color: var(--text-muted);
  background: transparent;
  border: 1px solid transparent; border-bottom: none;
  border-radius: 10px 10px 0 0;
  margin-bottom: -1px;
  box-shadow: none;
  transition: background 0.12s ease, color 0.12s ease;
}
/* Séparateur vertical entre onglets inactifs, comme dans un navigateur */
.tabbar .tab + .tab::before {
  content: ""; position: absolute; left: -2px; top: 25%; height: 50%;
  border-left: 1px solid var(--border);
}
.tabbar .tab.active::before, .tabbar .tab.active + .tab::before,
.tabbar .tab:hover::before, .tabbar .tab:hover + .tab::before { display: none; }
.tabbar .tab:hover { background: var(--primary-light); color: var(--text); }
.tabbar .tab.active {
  background: var(--card-bg); color: var(--primary);
  border-color: var(--border);
  z-index: 1;
}
.tabbar .tab:focus-visible { outline: 3px solid var(--primary); outline-offset: -3px; }

/* Contenu des onglets : un seul cadre relié à l'onglet actif */
.tabbar + main {
  background: var(--card-bg);
  border: 1px solid var(--border); border-top: none;
  border-radius: 0 0 var(--radius) var(--radius);
}
.tabbar + main .card { border: none; border-radius: 0; background: transparent; }
.tabbar + main .card + .card { margin-top: 0; border-top: 1px solid var(--border); }
.panel[hidden] { display: none; }
.panel:focus { outline: none; }
.card.backup { margin-top: 20px; padding: 14px 18px; }
.card.backup .toast { margin: 0; }
.lbl-short { display: none; }

/* Guide repliable (mobile) */
.guide-toggle { all: unset; display: block; cursor: default; }
.guide-toggle .acc-arrow { display: none; }
@media (max-width: 560px) {
  .guide { margin-top: 12px; padding: 14px 16px; font-size: 0.88rem; line-height: 1.55; }
  .guide h2 { margin: 0 !important; font-size: 1rem; }
  .guide:not(.is-collapsed) h2 { margin-bottom: 8px !important; }
  .guide-toggle { display: flex; align-items: center; justify-content: space-between; gap: 10px; width: 100%; cursor: pointer; }
  .guide-toggle:focus-visible { outline: 3px solid var(--primary); outline-offset: 4px; border-radius: 4px; }
  .guide-toggle .acc-arrow {
    display: block; flex: 0 0 auto; width: 9px; height: 9px; margin-right: 4px;
    border-right: 2px solid currentColor; border-bottom: 2px solid currentColor;
    transform: rotate(45deg); margin-top: -4px; transition: transform 0.15s ease;
  }
  .guide.is-collapsed .guide-toggle .acc-arrow { transform: rotate(-45deg); margin-top: 0; }
  .guide.is-collapsed > :not(h2) { display: none; }
  .guide:not(.op-related) h3 { font-size: 0.95rem; margin: 18px 0 6px; }
  .guide:not(.op-related) h4 { font-size: 0.88rem; margin: 12px 0 2px; }
}
@media (max-width: 560px) {
  .card.backup { margin-top: 12px; padding: 10px 12px; }
  .card.backup .toolbar { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
  .card.backup .btn { padding: 7px 4px; font-size: 0.76rem; white-space: nowrap; }
  .card.backup .toast:not(:empty) { grid-column: 1 / -1; font-size: 0.78rem; }
  .card.backup .toast:empty { display: none; }
  .card.backup .lbl-long { display: none; }
  .card.backup .lbl-short { display: inline; }
  .card.backup .error { margin-top: 8px !important; }
}
.link-btn { border: none; background: none; padding: 0; font: inherit; font-weight: 600; color: var(--primary); cursor: pointer; text-transform: capitalize; }
.link-btn:hover { text-decoration: underline; }
#tb-forecast tr { cursor: pointer; }
#tb-forecast tr:hover td { background: var(--primary-light); }
#s-chips:empty { display: none; }
.tabbar .tab-short { display: none; }

/* Accordéon (mobile) : titres de rubrique avec flèche */
.acc-head { display: none; }
@media (max-width: 560px) {
  .tabbar { display: none; }
  .tabbar + main { border-top: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
  .acc-head {
    display: flex; align-items: center; justify-content: space-between; gap: 10px;
    width: 100%; padding: 14px 16px; margin: 0;
    background: var(--card-bg); color: var(--text);
    border: none; border-top: 1px solid var(--border);
    font: inherit; font-size: 0.98rem; font-weight: 700; text-align: left; cursor: pointer;
  }
  .acc-head:first-child { border-top: none; }
  .acc-head .tab-short { display: none; }
  .acc-head.open { color: var(--primary); background: var(--primary-light); }
  .acc-head:focus-visible { outline: 3px solid var(--primary); outline-offset: -3px; }
  .acc-arrow {
    flex: 0 0 auto; width: 9px; height: 9px;
    border-right: 2px solid currentColor; border-bottom: 2px solid currentColor;
    transform: rotate(-45deg); transition: transform 0.15s ease; margin-right: 4px;
  }
  .acc-head.open .acc-arrow { transform: rotate(45deg); margin-top: -4px; }
  .acc-head + .panel .card:first-child { border-top: none; }
  /* Titre déjà affiché dans la barre de l'accordéon : on ne garde que ses éléments utiles (date, devise, aide, navigation). */
  #synthese-titre, #comptes-titre, #mois-titre { font-size: 0; justify-content: flex-start; }
  #synthese-titre:empty, #comptes-titre:empty { display: none; }
  #comptes-titre small { font-size: 0.8rem; }
}
@media (max-width: 560px) {
  .tabbar .tab-long { display: none; }
  .tabbar .tab-short { display: inline; }
  .tabbar { padding: 6px 4px 0; gap: 0; }
  .tabbar .tab { flex: 1 1 0; flex-direction: column; gap: 2px; padding: 8px 4px 9px; font-size: 0.72rem; }
}

/* ───────── Installation de l'application ───────── */

.card.install { display: flex; align-items: center; gap: 16px 20px; flex-wrap: wrap; margin-bottom: 20px; background: var(--primary-light); border-color: transparent; }
.card.install[hidden] { display: none; }
.install-text { flex: 1 1 320px; }
.card.install h2 { font-size: 1rem; margin: 0 0 6px; }
.card.install p { margin: 0; font-size: 0.88rem; line-height: 1.5; }
.card.install .install-help { margin-top: 8px; color: var(--text-muted); }
.card.install .btn { flex: 0 0 auto; }
@media (max-width: 560px) {
  .page.wide { padding-top: 12px; }
  .breadcrumb { font-size: 0.72rem; margin-bottom: 8px; }
  .header { margin-bottom: 12px; }
  .header h1 { font-size: 1.2rem; margin-bottom: 4px; }
  .header .subtitle { display: none; }
  .header .intro { font-size: 0.76rem; margin-top: 0; line-height: 1.4; }
  .card.install { padding: 12px 14px; gap: 10px; margin-bottom: 14px; }
  .card.install h2 { font-size: 0.92rem; margin: 0; }
  .card.install .install-text > p:not(.install-help) { display: none; }
  .card.install .install-help { margin-top: 4px; font-size: 0.8rem; line-height: 1.4; }
  .card.install .btn { width: 100%; padding: 8px 12px; }
}
.footer a { color: var(--text-muted); text-decoration: underline; text-decoration-color: var(--border); text-underline-offset: 2px; }
.footer a:hover { color: var(--primary); text-decoration-color: currentColor; }
@media (max-width: 560px) {
  .footer { margin-top: 12px; font-size: 0.7rem; line-height: 1.4; }
  .footer p { margin: 0 0 4px; }
  .page.wide { padding-bottom: 20px; }
}
@media (display-mode: standalone) {
  .breadcrumb, .op-related { display: none; }
}
