/* === DESIGN TOKENS === */
:root {
  /* Layout: multi-tab dashboard with sticky header */
  --bg: #F4F5FA;
  --surface: #FFFFFF;
  --surface-2: #EDEEF7;
  --border: #D4D7ED;
  --fg: #111320;
  --fg-2: #5A607A;
  --fg-3: #9199B5;
  --thomas: #C8921A;
  --thomas-bg: #FEF3DC;
  --frere: #1A6EB5;
  --frere-bg: #DCE9FE;
  --accent: #C8921A;
  --accent-hover: #A87210;
  --good: #19885A;
  --good-bg: #D4F0E5;
  --warn: #A85C10;
  --warn-bg: #FEE9D4;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 1px 3px rgba(17,19,32,.08), 0 4px 16px rgba(17,19,32,.05);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0D0F1A;
    --surface: #161926;
    --surface-2: #1E2235;
    --border: #2A2F48;
    --fg: #E6E8F4;
    --fg-2: #9199B5;
    --fg-3: #5A607A;
    --thomas: #E5A832;
    --thomas-bg: #2A2010;
    --frere: #4A9AE5;
    --frere-bg: #101828;
    --accent: #E5A832;
    --accent-hover: #F0BC55;
    --good: #2FBA7A;
    --good-bg: #0E2820;
    --warn: #E5862A;
    --warn-bg: #281A08;
    --shadow: 0 1px 3px rgba(0,0,0,.3), 0 4px 16px rgba(0,0,0,.2);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0D0F1A;
  --surface: #161926;
  --surface-2: #1E2235;
  --border: #2A2F48;
  --fg: #E6E8F4;
  --fg-2: #9199B5;
  --fg-3: #5A607A;
  --thomas: #E5A832;
  --thomas-bg: #2A2010;
  --frere: #4A9AE5;
  --frere-bg: #101828;
  --accent: #E5A832;
  --accent-hover: #F0BC55;
  --good: #2FBA7A;
  --good-bg: #0E2820;
  --warn: #E5862A;
  --warn-bg: #281A08;
  --shadow: 0 1px 3px rgba(0,0,0,.3), 0 4px 16px rgba(0,0,0,.2);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--bg);
  color: var(--fg);
  font-size: 14px;
  line-height: 1.5;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  padding-bottom: max(24px, env(safe-area-inset-bottom, 0px));
  min-height: 100%;
}
h1,h2,h3,h4 { font-family: 'Syne', sans-serif; text-wrap: balance; }
input, select, textarea, button { font-family: inherit; font-size: 14px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

/* === STICKY HEADER === */
.app-header {
  position: sticky;
  top: env(safe-area-inset-top, 0px);
  z-index: 100;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding-block: 0;
}
body::before {
  content: "";
  position: fixed;
  inset: 0 0 auto;
  height: env(safe-area-inset-top, 0px);
  z-index: 110;
  background: var(--surface);
}
.header-inner {
  max-width: 1100px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 0;
}
.header-logo {
  width: 36px; height: 36px;
  background: var(--accent);
  border-radius: 8px;
  display: grid; place-items: center;
  flex-shrink: 0;
}
.header-logo svg { width: 20px; height: 20px; fill: white; }
.header-title { font-family: 'Syne', sans-serif; font-size: 17px; font-weight: 700; line-height: 1.1; }
.header-sub { font-size: 12px; color: var(--fg-2); }
.header-actions { margin-left: auto; display: flex; gap: 8px; align-items: center; }
.theme-btn {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  width: 32px; height: 32px;
  cursor: pointer;
  display: grid; place-items: center;
  color: var(--fg-2);
  transition: color .15s;
}
.theme-btn:hover { color: var(--fg); }

/* === TABS === */
.tabs-bar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs-bar::-webkit-scrollbar { display: none; }
.tabs-inner {
  max-width: 1100px;
  margin: 0 auto;
  display: flex;
  gap: 0;
}
.tab-btn {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  padding: 10px 16px 9px;
  color: var(--fg-2);
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  transition: color .15s, border-color .15s;
  display: flex; align-items: center; gap: 6px;
}
.tab-btn:hover { color: var(--fg); }
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.tab-emoji { font-size: 15px; }

/* === MAIN CONTENT === */
.main { max-width: 1100px; margin: 0 auto; padding-block: 24px; }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* === CARDS === */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 16px;
}
.card-title {
  font-family: 'Syne', sans-serif;
  font-size: 15px; font-weight: 700;
  margin-bottom: 16px;
  display: flex; align-items: center; gap: 8px;
}
.card-title span { font-size: 16px; }

/* === STAT TILES === */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}
.stat-tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}
.stat-label { font-size: 11px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--fg-2); margin-bottom: 6px; }
.stat-value { font-family: 'Syne', sans-serif; font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat-sub { font-size: 11px; color: var(--fg-3); margin-top: 3px; }
.stat-tile.thomas .stat-value { color: var(--thomas); }
.stat-tile.frere .stat-value { color: var(--frere); }
.stat-tile.good .stat-value { color: var(--good); }

/* === PARTNER SPLIT BAR === */
.split-bar-wrap { margin-top: 16px; }
.split-bar-labels { display: flex; justify-content: space-between; margin-bottom: 6px; font-size: 12px; font-weight: 600; }
.split-bar { height: 10px; border-radius: 5px; background: var(--frere); overflow: hidden; }
.split-bar-fill { height: 100%; background: var(--thomas); border-radius: 5px 0 0 5px; transition: width .4s ease; }
.split-pct { display: flex; justify-content: space-between; margin-top: 4px; font-size: 11px; color: var(--fg-2); font-variant-numeric: tabular-nums; }

/* === CONTRIBUTION TABLE === */
.contrib-table { width: 100%; border-collapse: collapse; }
.contrib-table th { text-align: left; font-size: 11px; font-weight: 600; letter-spacing: .05em; text-transform: uppercase; color: var(--fg-2); padding: 6px 10px; border-bottom: 1px solid var(--border); }
.contrib-table td { padding: 10px 10px; border-bottom: 1px solid var(--border); font-variant-numeric: tabular-nums; vertical-align: middle; }
.contrib-table tr:last-child td { border-bottom: none; font-weight: 700; background: var(--surface-2); border-radius: 0 0 var(--radius-sm) var(--radius-sm); }
.contrib-table td.thomas { color: var(--thomas); font-weight: 600; }
.contrib-table td.frere { color: var(--frere); font-weight: 600; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 20px; font-size: 11px; font-weight: 600; }
.badge-thomas { background: var(--thomas-bg); color: var(--thomas); }
.badge-frere { background: var(--frere-bg); color: var(--frere); }
.badge-both { background: var(--surface-2); color: var(--fg-2); }

/* === FORMS === */
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 12px; }
.form-row-3 { display: grid; grid-template-columns: 2fr 1fr 1fr; gap: 12px; margin-bottom: 12px; }
.form-row-full { margin-bottom: 12px; }
@media (max-width: 540px) { .form-row, .form-row-3 { grid-template-columns: 1fr; } }
.field label { display: block; font-size: 12px; font-weight: 600; color: var(--fg-2); margin-bottom: 5px; letter-spacing: .03em; }
.field input, .field select, .field textarea {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  color: var(--fg);
  transition: border-color .15s;
}
.field input:hover, .field select:hover { border-color: var(--fg-3); }
.field textarea { resize: vertical; min-height: 60px; }
.btn {
  background: var(--accent);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  padding: 9px 18px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, transform .1s;
  display: inline-flex; align-items: center; gap: 6px;
}
.btn:hover { background: var(--accent-hover); }
.btn:active { transform: scale(.98); }
.btn-sm { padding: 6px 12px; font-size: 12px; }
.btn-ghost {
  background: none;
  border: 1px solid var(--border);
  color: var(--fg-2);
}
.btn-ghost:hover { background: var(--surface-2); color: var(--fg); }
.btn-danger { background: #c53030; }
.btn-danger:hover { background: #a82020; }

/* === TRAVAUX === */
.travail-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 16px;
  overflow: hidden;
}
.travail-header {
  padding: 14px 18px;
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  user-select: none;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.travail-header:hover { background: var(--surface-2); }
.travail-num {
  width: 28px; height: 28px;
  background: var(--accent);
  color: white;
  border-radius: 6px;
  display: grid; place-items: center;
  font-family: 'Syne', sans-serif;
  font-size: 13px;
  font-weight: 700;
  flex-shrink: 0;
}
.travail-info { flex: 1; min-width: 0; }
.travail-titre { font-weight: 700; font-size: 14px; }
.travail-desc { font-size: 12px; color: var(--fg-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.travail-total { font-family: 'Syne', sans-serif; font-size: 15px; font-weight: 700; font-variant-numeric: tabular-nums; color: var(--accent); }
.travail-chevron { color: var(--fg-3); transition: transform .2s; font-size: 12px; }
.travail-body { padding: 18px; display: none; }
.travail-body.open { display: block; }
.sub-section { margin-bottom: 20px; }
.sub-title { font-size: 12px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--fg-2); margin-bottom: 10px; display: flex; align-items: center; gap: 6px; }

/* === FACTURE BADGE === */
.facture-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 3px 10px;
  font-size: 11px;
  color: var(--fg-2);
}
.facture-badge.has-file { background: var(--good-bg); border-color: var(--good); color: var(--good); }

/* === HYPOTHÈQUE === */
.chart-wrap { position: relative; height: 280px; margin-bottom: 20px; }
.hypo-params { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; margin-bottom: 20px; }

/* === CODE D'ÉTHIQUE === */
.ethique-rule {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  margin-bottom: 10px;
  display: flex;
  gap: 10px;
  align-items: flex-start;
}
.rule-num {
  min-width: 24px; height: 24px;
  background: var(--accent);
  color: white;
  border-radius: 50%;
  display: grid; place-items: center;
  font-size: 11px;
  font-weight: 700;
  flex-shrink: 0;
}
.rule-text { flex: 1; min-width: 0; }
.rule-delete { background: none; border: none; color: var(--fg-3); cursor: pointer; padding: 0; font-size: 16px; line-height: 1; }
.rule-delete:hover { color: #c53030; }
.signatures { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-top: 20px; }
.signature-box {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 20px;
  text-align: center;
  cursor: pointer;
  transition: border-color .15s, background .15s;
}
.signature-box.signed {
  border: 2px solid var(--good);
  background: var(--good-bg);
}
.signature-box .sig-name { font-family: 'Syne', sans-serif; font-size: 15px; font-weight: 700; margin-bottom: 4px; }
.signature-box .sig-status { font-size: 12px; color: var(--fg-2); }
.signature-box.signed .sig-status { color: var(--good); font-weight: 600; }

/* === DEPENSES === */
.depense-row {
  display: grid;
  grid-template-columns: 1fr 120px 110px 100px 32px;
  gap: 8px;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.depense-row:last-of-type { border-bottom: none; }
.depense-row.header { font-size: 11px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--fg-2); padding-top: 0; }
@media (max-width: 600px) {
  .depense-row { grid-template-columns: 1fr 90px 32px; }
  .depense-row .col-date, .depense-row .col-pay { display: none; }
}

/* === SECTION HEADER === */
.section-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; flex-wrap: wrap; gap: 12px; }
.section-title { font-family: 'Syne', sans-serif; font-size: 20px; font-weight: 800; }
.section-title span { color: var(--fg-3); font-weight: 600; font-size: 14px; margin-left: 8px; }

/* === UTILS === */
.divider { height: 1px; background: var(--border); margin: 20px 0; }
.text-thomas { color: var(--thomas); font-weight: 600; }
.text-frere { color: var(--frere); font-weight: 600; }
.text-muted { color: var(--fg-2); }
.text-sm { font-size: 12px; }
.mt-16 { margin-top: 16px; }
.mb-16 { margin-bottom: 16px; }
.flex { display: flex; align-items: center; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.ml-auto { margin-left: auto; }
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--fg-2);
  font-size: 13px;
}
.empty-state .empty-icon { font-size: 32px; margin-bottom: 10px; }
.empty-state strong { display: block; font-size: 15px; color: var(--fg); margin-bottom: 4px; }
.note-box {
  background: var(--warn-bg);
  border: 1px solid var(--warn);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 12px;
  color: var(--warn);
  font-weight: 500;
  margin-bottom: 16px;
}
.info-box {
  background: var(--frere-bg);
  border: 1px solid var(--frere);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 12px;
  color: var(--frere);
  font-weight: 500;
  margin-bottom: 16px;
}

/* === Server sync (homeserver version) === */
.sync-status { font-size: 12px; color: var(--fg-3); white-space: nowrap; }
.sync-status.saving { color: var(--warn); }
.sync-status.error { color: #C0392B; font-weight: 600; }
.user-menu { position: relative; }
.user-menu > summary { list-style: none; display: inline-flex; align-items: center; justify-content: center; }
.user-menu > summary::-webkit-details-marker { display: none; }
.user-menu-panel { position: absolute; right: 0; top: calc(100% + 6px); z-index: 50; min-width: 210px; margin: 0; }
.user-menu-panel .btn { width: 100%; justify-content: flex-start; }
.hist-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 100; display: flex;
  align-items: flex-start; justify-content: center; padding: 60px 16px; overflow-y: auto; }
.hist-overlay[hidden] { display: none; }
.hist-panel { width: 100%; max-width: 560px; }
.hist-row { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 13px; }
.hist-row .hist-meta { flex: 1; min-width: 0; }
.hist-row .hist-note { color: var(--fg-3); font-size: 12px; }
.toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 200; background: var(--fg);
  color: var(--bg); padding: 10px 16px; border-radius: var(--radius-sm); font-size: 13px; box-shadow: var(--shadow);
  max-width: calc(100% - 32px); }
@media (max-width: 600px) { .sync-status { display: none; } }
