: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; }
}
