:root {
  --paper: #F2EEE3;
  --paper-raised: #FAF7EF;
  --ink: #23281F;
  --ink-soft: #565A4C;
  --line: #CDC4A9;
  --forest: #3C5641;
  --forest-deep: #2A3E30;
  --forest-soft: #E1EBE2;
  --amber: #A9761F;
  --amber-soft: #F3EAD3;
  --critical: #A5432E;
  --critical-soft: #F4E3DE;
  --good: #3C6A4B;
  --good-soft: #E1EBE2;
  --shadow: 0 1px 2px rgba(35, 40, 31, 0.06), 0 4px 16px rgba(35, 40, 31, 0.05);
  --radius: 10px;
  --max: 980px;
}

html[data-theme="dark"] {
  --paper: #191D17;
  --paper-raised: #23271F;
  --ink: #EDE8D9;
  --ink-soft: #A6A794;
  --line: #383D30;
  --forest: #8FB596;
  --forest-deep: #BFDAC1;
  --forest-soft: #2A3B2C;
  --amber: #E0B45C;
  --amber-soft: #3A331E;
  --critical: #E28D77;
  --critical-soft: #3B2620;
  --good: #93CBA0;
  --good-soft: #253226;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: 'IBM Plex Sans', sans-serif;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  transition: background 0.15s ease, color 0.15s ease;
}

a { color: var(--forest-deep); }

h1, h2, h3, .serif {
  font-family: 'Source Serif 4', serif;
  color: var(--ink);
  letter-spacing: -0.01em;
}

/* ---------- Layout ---------- */
.wrap {
  max-width: var(--max);
  margin: 0 auto;
  padding: 0 24px calc(90px + env(safe-area-inset-bottom, 0px));
}

nav.topbar {
  border-bottom: 1px solid var(--line);
  margin-bottom: 36px;
  padding-top: env(safe-area-inset-top, 0px);
  background: var(--paper);
}
nav.topbar .inner {
  max-width: var(--max);
  margin: 0 auto;
  padding: 18px 24px;
  display: flex;
  align-items: center;
  gap: 18px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: 'Source Serif 4', serif;
  font-weight: 600;
  font-size: 19px;
  color: var(--ink);
  text-decoration: none;
}
.brand img { width: 28px; height: 28px; border-radius: 7px; display: block; }
nav.topbar .spacer { flex: 1; }
nav.topbar .navlink {
  font-size: 14px;
  color: var(--ink-soft);
  text-decoration: none;
  padding: 6px 10px;
  border-radius: 6px;
}
nav.topbar .navlink:hover { background: var(--paper-raised); color: var(--ink); }
.user-chip {
  font-size: 13px;
  color: var(--ink-soft);
}

.nav-panel {
  display: flex;
  align-items: center;
  gap: 6px;
}
.menu-toggle {
  display: none;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--paper-raised);
  color: var(--ink);
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.menu-toggle svg { width: 18px; height: 18px; }

@media (max-width: 700px) {
  nav.topbar .inner { padding: 14px 16px; flex-wrap: wrap; }
  .menu-toggle { display: flex; }
  .nav-panel {
    order: 5;
    flex-basis: 100%;
    flex-direction: column;
    align-items: stretch;
    gap: 4px;
    max-height: 0;
    overflow: hidden;
    width: 100%;
    transition: max-height 0.2s ease, margin-top 0.2s ease;
  }
  .nav-panel.open {
    max-height: 340px;
    margin-top: 14px;
    padding-top: 14px;
    border-top: 1px solid var(--line);
  }
  .nav-panel .navlink { padding: 12px 4px; }
  .user-chip { padding: 8px 4px; }
}

.theme-toggle {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--paper-raised);
  color: var(--ink);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.theme-toggle svg { width: 17px; height: 17px; }
.theme-toggle .icon-sun { display: none; }
html[data-theme="dark"] .theme-toggle .icon-moon { display: none; }
html[data-theme="dark"] .theme-toggle .icon-sun { display: block; }

/* ---------- Buttons & forms ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: 'IBM Plex Sans', sans-serif;
  font-size: 14px;
  font-weight: 500;
  padding: 10px 18px;
  border-radius: 8px;
  border: 1px solid var(--forest);
  background: var(--forest);
  color: #FAF7EF;
  cursor: pointer;
  text-decoration: none;
  line-height: 1.2;
}
.btn:hover { opacity: 0.92; }
.btn.ghost {
  background: transparent;
  color: var(--ink);
  border-color: var(--line);
}
.btn.ghost:hover { border-color: var(--forest); }
.btn.danger {
  background: transparent;
  color: var(--critical);
  border-color: var(--critical);
}
.btn.small { padding: 6px 12px; font-size: 12.5px; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; }

label { font-size: 13px; color: var(--ink-soft); display: block; margin-bottom: 5px; }
input, select, textarea {
  width: 100%;
  font-family: 'IBM Plex Sans', sans-serif;
  font-size: 14.5px;
  color: var(--ink);
  background: var(--paper-raised);
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 10px 12px;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--forest);
}
.field { margin-bottom: 16px; }
.field-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 16px;
}
fieldset {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  margin: 0 0 24px;
}
legend {
  font-family: 'Source Serif 4', serif;
  font-weight: 600;
  font-size: 15px;
  padding: 0 8px;
  color: var(--forest-deep);
}

/* ---------- Cards ---------- */
.card {
  background: var(--paper-raised);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}
.page-header h1 { margin: 0; font-size: clamp(26px, 5vw, 36px); }
.kicker { font-size: 13px; color: var(--ink-soft); margin-bottom: 8px; }

/* ---------- Dashboard ---------- */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
  margin: 28px 0 40px;
}
.stat {
  padding: 18px 20px;
  border-radius: var(--radius);
  background: var(--paper-raised);
  border: 1px solid var(--line);
}
.stat .label { font-size: 12.5px; color: var(--ink-soft); margin-bottom: 6px; }
.stat .value { font-family: 'Source Serif 4', serif; font-size: 24px; font-weight: 600; color: var(--forest-deep); }
.stat .value.neg { color: var(--critical); }

.prop-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 18px;
}
.prop-card {
  display: block;
  text-decoration: none;
  color: var(--ink);
  overflow: hidden;
}
.prop-card .photo {
  height: 150px;
  background: var(--forest-soft) center/cover no-repeat;
  display: flex; align-items: center; justify-content: center;
  color: var(--forest-deep);
}
.prop-card .photo svg { width: 34px; height: 34px; opacity: 0.5; }
.prop-card .body { padding: 16px 18px; }
.prop-card .addr { font-family: 'Source Serif 4', serif; font-weight: 600; font-size: 17px; margin-bottom: 2px; }
.prop-card .city { font-size: 13px; color: var(--ink-soft); margin-bottom: 12px; }
.prop-card .price { font-family: 'Source Serif 4', serif; font-size: 19px; color: var(--forest-deep); font-weight: 600; }
.empty-state {
  text-align: center;
  padding: 70px 20px;
  color: var(--ink-soft);
}

/* ---------- Status badge ---------- */
.badge {
  display: inline-block;
  font-size: 11.5px;
  font-weight: 500;
  padding: 3px 10px;
  border-radius: 20px;
  white-space: nowrap;
}
.badge.status-analyse { background: var(--amber-soft); color: var(--amber); }
.badge.status-offre { background: var(--amber-soft); color: var(--amber); }
.badge.status-achete { background: var(--good-soft); color: var(--good); }
.badge.status-vendu { background: var(--line); color: var(--ink-soft); }
.badge-btn {
  border: none;
  font-family: inherit;
  cursor: pointer;
}
.badge-btn:hover { filter: brightness(0.95); }
html[data-theme="dark"] .badge-btn:hover { filter: brightness(1.15); }
.tag { display:inline-block; font-size: 11.5px; padding: 2px 9px; border-radius: 20px; font-weight: 500; white-space: nowrap; }
.tag.critical { background: var(--critical-soft); color: var(--critical); }
.tag.check { background: var(--amber-soft); color: var(--amber); }
.tag.good { background: var(--good-soft); color: var(--good); }

/* ---------- Section tabs ---------- */
.section-nav {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  border-bottom: 1px solid var(--line);
  margin: 28px 0 32px;
  padding-bottom: 12px;
  position: sticky;
  top: 0;
  background: var(--paper);
  z-index: 5;
  padding-top: 10px;
}
.section-nav a {
  font-size: 13.5px;
  color: var(--ink-soft);
  text-decoration: none;
  padding: 7px 13px;
  border-radius: 20px;
}
.section-nav a:hover { background: var(--paper-raised); color: var(--ink); }

section.block, details.block { margin-bottom: 24px; scroll-margin-top: 70px; }
section.block > h2 { font-size: 22px; margin: 0 0 4px; }
.section-note { font-size: 13.5px; color: var(--ink-soft); margin: 0 0 20px; }

details.block { padding: 0; overflow: hidden; }
details.block summary {
  list-style: none;
  cursor: pointer;
  padding: 20px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  -webkit-tap-highlight-color: transparent;
}
details.block summary::-webkit-details-marker { display: none; }
details.block summary::marker { content: ''; }
details.block summary h2 { font-size: 19px; margin: 0; }
details.block .summary-chevron { width: 18px; height: 18px; color: var(--ink-soft); flex-shrink: 0; transition: transform 0.2s ease; }
details.block[open] .summary-chevron { transform: rotate(180deg); }
details.block summary:hover h2 { color: var(--forest-deep); }
details.block .block-body { padding: 0 24px 28px; }
details.block .block-body > .section-note:first-child { margin-top: -8px; }

/* ---------- Spec grid ---------- */
.spec-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}
.spec { padding: 12px 16px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); background: var(--paper-raised); }
.spec .k { font-size: 11px; color: var(--ink-soft); margin-bottom: 3px; }
.spec .v { font-size: 14.5px; font-weight: 500; }
@media (min-width: 620px) {
  .spec-grid { grid-template-columns: repeat(3, 1fr); }
  .spec:nth-child(3n) { border-right: none; }
}
@media (max-width: 619px) {
  .spec:nth-child(2n) { border-right: none; }
}

/* ---------- Findings ---------- */
.finding { padding: 16px 0; border-top: 1px solid var(--line); }
.finding:last-child { border-bottom: 1px solid var(--line); }
.finding-head { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; margin-bottom: 5px; justify-content: space-between; }
.finding-head-left { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.finding-title { font-weight: 600; font-size: 15.5px; }
.finding p.desc { margin: 0; font-size: 14px; color: var(--ink-soft); max-width: 62ch; }

.broker-row { display: flex; align-items: center; justify-content: space-between; gap: 14px; flex-wrap: wrap; margin-top: 12px; }

.note-list { display: flex; flex-direction: column; gap: 12px; }
.note-row { padding: 12px 14px; background: var(--paper); border: 1px solid var(--line); border-radius: 8px; }
.note-body { font-size: 14px; white-space: pre-wrap; }
.note-meta { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 8px; font-size: 11.5px; color: var(--ink-soft); }

/* ---------- Checklist ---------- */
.progress-bar { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.progress-track { flex: 1; height: 6px; background: var(--line); border-radius: 4px; overflow: hidden; }
.progress-fill { height: 100%; background: var(--forest); transition: width 0.2s ease; }
.progress-count { font-family: 'Source Serif 4', serif; font-weight: 600; font-size: 14px; white-space: nowrap; color: var(--forest-deep); }

.check-item { display: flex; gap: 14px; align-items: flex-start; padding: 16px 4px; border-top: 1px solid var(--line); }
.check-item:last-child { border-bottom: 1px solid var(--line); }
.check-box {
  flex-shrink: 0; width: 26px; height: 26px;
  border: 1.5px solid var(--forest); border-radius: 6px; margin-top: 2px;
  display: flex; align-items: center; justify-content: center;
  background: var(--paper-raised); cursor: pointer;
}
.check-box svg { width: 15px; height: 15px; opacity: 0; }
.check-item.done .check-box { background: var(--forest); }
.check-item.done .check-box svg { opacity: 1; }
.check-body { flex: 1; min-width: 0; }
.check-top { display: flex; align-items: baseline; gap: 8px; margin-bottom: 4px; flex-wrap: wrap; }
.check-rank { font-family: 'Source Serif 4', serif; font-weight: 600; font-size: 13px; color: var(--ink-soft); }
.check-title { font-weight: 600; font-size: 15.5px; cursor: pointer; }
.check-item.done .check-title { color: var(--ink-soft); text-decoration: line-through; text-decoration-color: var(--line); }
.check-item.read-only .check-box { cursor: default; }
.check-item.read-only .check-title { cursor: default; }
.check-ask { font-size: 13.5px; margin: 4px 0 2px; color: var(--forest-deep); }
.check-look { font-size: 13px; color: var(--ink-soft); margin: 0; }
.check-extra { margin-top: 10px; }
.check-comment { min-height: 34px; resize: vertical; font-size: 13.5px; }
.check-photo-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; align-items: center; }
.photo-add-btn {
  display: inline-flex; align-items: center; gap: 5px; font-size: 12px;
  color: var(--forest-deep); background: var(--paper-raised); border: 1px dashed var(--forest);
  border-radius: 6px; padding: 7px 10px; cursor: pointer;
}
.photo-thumb { position: relative; width: 54px; height: 54px; border-radius: 6px; overflow: hidden; border: 1px solid var(--line); }
.photo-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo-thumb form { position: absolute; top: 2px; right: 2px; }
.photo-thumb button.rm {
  width: 16px; height: 16px; border-radius: 50%; border: none;
  background: rgba(20,20,15,0.65); color: #fff; font-size: 10px; line-height: 16px; text-align: center; cursor: pointer; padding: 0;
}
.check-item-actions { margin-top: 8px; }

/* ---------- Tables ---------- */
table.tx-table { width: 100%; border-collapse: collapse; font-size: 14px; }
table.tx-table th, table.tx-table td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line); }
table.tx-table th { color: var(--ink-soft); font-size: 12px; font-weight: 500; text-transform: uppercase; letter-spacing: 0.03em; }
table.tx-table td.amount { font-family: 'Source Serif 4', serif; font-weight: 600; }
table.tx-table td.amount.neg { color: var(--critical); }
table.tx-table td.amount.pos { color: var(--good); }
.tx-summary { display: flex; gap: 22px; flex-wrap: wrap; margin: 18px 0 24px; }
.tx-summary .item .label { font-size: 12px; color: var(--ink-soft); }
.tx-summary .item .val { font-family: 'Source Serif 4', serif; font-weight: 600; font-size: 18px; }

/* ---------- Documents ---------- */
.doc-list { display: flex; flex-direction: column; gap: 8px; }
.doc-row { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border: 1px solid var(--line); border-radius: 8px; background: var(--paper-raised); }
.doc-row .name { flex: 1; font-size: 14px; }
.doc-row .meta { font-size: 12px; color: var(--ink-soft); }

/* ---------- Watch links ---------- */
.watch-list { display: flex; flex-direction: column; gap: 12px; }
.watch-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; padding: 16px 18px; }
.watch-photo {
  flex-shrink: 0;
  width: 84px;
  height: 84px;
  border-radius: 8px;
  background: var(--forest-soft) center/cover no-repeat;
  display: flex; align-items: center; justify-content: center;
  color: var(--forest-deep);
}
.watch-photo svg { width: 24px; height: 24px; opacity: 0.5; }
.watch-main { min-width: 0; flex: 1; }
.watch-title { font-family: 'Source Serif 4', serif; font-weight: 600; font-size: 16px; text-decoration: none; color: var(--forest-deep); }
.watch-url { font-size: 12px; color: var(--ink-soft); word-break: break-all; margin-top: 2px; }
.watch-notes { font-size: 13.5px; margin: 8px 0 0; }
.watch-meta { font-size: 11.5px; color: var(--ink-soft); margin-top: 8px; }

/* ---------- Auth pages ---------- */
.auth-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(24px + env(safe-area-inset-top, 0px)) calc(24px + env(safe-area-inset-right, 0px)) calc(24px + env(safe-area-inset-bottom, 0px)) calc(24px + env(safe-area-inset-left, 0px));
}
.auth-card { width: 100%; max-width: 400px; padding: 36px 32px; }
.auth-logo { display: flex; justify-content: center; margin-bottom: 18px; }
.auth-logo img { width: 56px; height: 56px; border-radius: 14px; }
.auth-card h1 { text-align: center; font-size: 24px; margin: 0 0 6px; }
.auth-card .sub { text-align: center; font-size: 13.5px; color: var(--ink-soft); margin-bottom: 24px; }
.error-msg { background: var(--critical-soft); color: var(--critical); padding: 10px 14px; border-radius: 8px; font-size: 13.5px; margin-bottom: 16px; }
.success-msg { background: var(--good-soft); color: var(--good); padding: 10px 14px; border-radius: 8px; font-size: 13.5px; margin-bottom: 16px; }

.inline-form { display: flex; gap: 8px; flex-wrap: wrap; align-items: flex-end; }
.callout {
  background: var(--critical-soft); border-left: 3px solid var(--critical);
  padding: 14px 16px; font-size: 13.5px; border-radius: 4px;
}
.divider { border-top: 1px solid var(--line); margin: 24px 0; }

@media (max-width: 480px) {
  .wrap { padding: 0 16px 70px; }
  .finding-head { flex-direction: column; align-items: flex-start; gap: 4px; }
}
