:root {
  --bg: #f6f4ef; --surface: #fffdf9; --ink: #2b2a28; --muted: #77716a; --line: #e5ded3;
  --oak: #a97f57; --oak-soft: #eadcca; --sage: #7f9277; --sand: #d9c3a0; --char: #4a4844;
  --ok: #3f7d58; --ok-bg: #e3f0e7; --warn: #9a6a17; --warn-bg: #f6ecd8; --idle: #6f6a64; --idle-bg: #ece8e2;
  --radius: 14px; --shadow: 0 1px 2px rgba(40, 30, 20, .05);
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #1a1917; --surface: #242220; --ink: #eeeae3; --muted: #a39d94; --line: #37342f;
    --oak: #cfa67f; --oak-soft: #4d3f31; --sage: #9db394; --sand: #8c7556; --char: #c9c4bc;
    --ok: #8fd0a5; --ok-bg: #213a2a; --warn: #e6bb6c; --warn-bg: #3d321d; --idle: #aaa39a; --idle-bg: #2f2c29; }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.55 -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", sans-serif; }
.wrap { max-width: 1160px; margin-inline: auto; padding-inline: 20px; }
h1, h2, h3 { line-height: 1.2; font-weight: 600; letter-spacing: -.01em; margin: 0; }
h2 { font-size: 1.5rem; margin-bottom: .25rem; }
h3 { font-size: 1.02rem; margin-bottom: .6rem; }
a { color: var(--oak); }
button { font: inherit; color: inherit; }
.muted { color: var(--muted); }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* Gate */
.gate { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.gate-card { width: 100%; max-width: 360px; background: var(--surface); border: 1px solid var(--line); border-radius: 18px; padding: 32px 28px; text-align: center; box-shadow: var(--shadow); }
.gate-mark { font-size: 2.4rem; }
.gate-card h1 { font-size: 1.5rem; margin: .4rem 0; }
.gate-card p { color: var(--muted); margin: 0 0 1.2rem; }
.gate-card input[type=password] { width: 100%; padding: 12px 14px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); color: var(--ink); font-size: 1rem; }
.remember { display: flex; gap: 8px; align-items: center; justify-content: center; margin: 12px 0; color: var(--muted); font-size: .9rem; }
.gate-card button { width: 100%; padding: 12px; border: 0; border-radius: 10px; background: var(--ink); color: var(--bg); font-weight: 600; cursor: pointer; }
.gate-card button:disabled { opacity: .6; }
.gate-err { color: #c0392b !important; margin: 12px 0 0 !important; }

/* Top bar */
.topbar { position: sticky; top: 0; z-index: 10; background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); }
.topbar-inner { display: flex; align-items: center; justify-content: space-between; padding-block: 12px 4px; }
.brand { text-decoration: none; color: var(--ink); font-weight: 600; font-size: 1.05rem; }
.lock { border: 1px solid var(--line); background: var(--surface); border-radius: 8px; padding: 5px 12px; cursor: pointer; font-size: .85rem; }
.tabs { display: flex; gap: 4px; overflow-x: auto; padding-block: 6px 8px; scrollbar-width: none; }
.tabs a { padding: 6px 12px; border-radius: 999px; color: var(--muted); text-decoration: none; white-space: nowrap; font-size: .92rem; }
.tabs a:hover { color: var(--ink); background: var(--surface); }
.tabs a.on { background: var(--ink); color: var(--bg); }

main { padding-block: 28px 20px; }
.section { margin-bottom: 36px; }
.section-head { display: flex; justify-content: space-between; align-items: end; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.section-head p { margin: 0; color: var(--muted); }
.page-title { margin-bottom: 22px; }
.page-title p { color: var(--muted); margin: .3rem 0 0; }

/* Cards & grids */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow); }
.grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.grid-2 { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr)); }
.stats { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.stat small { display: block; color: var(--muted); font-size: .8rem; }
.stat b { display: block; font-size: 1.35rem; font-weight: 600; margin-top: 2px; font-variant-numeric: tabular-nums; }
.stat span { color: var(--muted); font-size: .82rem; }

.hero { display: grid; gap: 20px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 340px), 1fr)); align-items: start; margin-bottom: 20px; }
.hero .eyebrow { text-transform: uppercase; letter-spacing: .12em; font-size: .75rem; color: var(--oak); }
.hero h1 { font-size: clamp(1.9rem, 5vw, 2.8rem); margin: .25rem 0 .4rem; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-block; padding: 3px 10px; border-radius: 999px; background: var(--idle-bg); color: var(--idle); font-size: .8rem; white-space: nowrap; }
.chip.ok { background: var(--ok-bg); color: var(--ok); }
.chip.warn { background: var(--warn-bg); color: var(--warn); }
button.chip { border: 1px solid transparent; cursor: pointer; }
button.chip.on { background: var(--ink); color: var(--bg); }

.kv { display: grid; grid-template-columns: minmax(120px, 40%) 1fr; gap: 8px 14px; margin: 0; }
.kv dt { color: var(--muted); font-size: .88rem; }
.kv dd { margin: 0; font-weight: 500; overflow-wrap: anywhere; }

.progress { height: 10px; border-radius: 6px; background: var(--line); overflow: hidden; display: flex; }
.progress > span { display: block; height: 100%; }
.legend { display: flex; flex-wrap: wrap; gap: 14px; margin-top: 10px; font-size: .85rem; color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.k-self { background: var(--oak); } .k-bank { background: var(--char); } .k-subvention { background: var(--sage); } .k-tds { background: var(--sand); } .k-due { background: var(--line); }

/* Tables */
.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--line); font-size: .9rem; vertical-align: top; }
th { color: var(--muted); font-weight: 500; font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; }
tfoot td { font-weight: 600; border-bottom: 0; }
.card > .table-scroll { margin: -6px -8px; }

/* Milestones */
.ms { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 10px; }
.ms > summary { list-style: none; cursor: pointer; display: grid; grid-template-columns: 34px 1fr auto; gap: 12px; align-items: center; padding: 14px 16px; }
.ms > summary::-webkit-details-marker { display: none; }
.ms-no { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; background: var(--idle-bg); color: var(--idle); font-size: .8rem; font-weight: 600; }
.ms.paid .ms-no { background: var(--ok-bg); color: var(--ok); }
.ms-name b { display: block; font-weight: 600; }
.ms-name small { color: var(--muted); }
.ms-amt { text-align: right; }
.ms-amt b { display: block; font-variant-numeric: tabular-nums; }
.ms-body { padding: 0 16px 16px; border-top: 1px dashed var(--line); }
.ms-body h4 { margin: 14px 0 6px; font-size: .8rem; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; font-weight: 500; }

/* Documents */
.doc-list { display: grid; gap: 8px; grid-template-columns: repeat(auto-fill, minmax(min(100%, 300px), 1fr)); }
.doc { display: grid; grid-template-columns: 42px 1fr; gap: 10px; align-items: center; text-align: left; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; cursor: pointer; width: 100%; }
.doc:hover { border-color: var(--oak); }
.doc .ext { font-size: .68rem; font-weight: 700; text-transform: uppercase; background: var(--oak-soft); color: var(--oak); border-radius: 6px; padding: 8px 0; text-align: center; }
.doc .dn { font-size: .88rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: block; }
.doc small { color: var(--muted); font-size: .76rem; }
.folder { margin-bottom: 22px; }
.folder h3 { font-size: .9rem; color: var(--muted); font-weight: 500; }
.search { width: 100%; max-width: 420px; padding: 10px 14px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); font-size: .95rem; }
.toolbar { display: flex; flex-direction: column; gap: 10px; margin-bottom: 18px; }

/* Images */
.plan-img { width: 100%; border-radius: 10px; background: var(--bg); min-height: 120px; display: block; cursor: zoom-in; }

/* Timeline */
.tl { list-style: none; margin: 0; padding: 0; border-left: 2px solid var(--line); margin-left: 6px; }
.tl li { position: relative; padding: 0 0 18px 22px; }
.tl li::before { content: ""; position: absolute; left: -7px; top: 5px; width: 12px; height: 12px; border-radius: 50%; background: var(--surface); border: 2px solid var(--muted); }
.tl li.done::before { background: var(--ok); border-color: var(--ok); }
.tl li.next::before { background: var(--oak); border-color: var(--oak); box-shadow: 0 0 0 4px var(--oak-soft); }
.tl time { font-size: .8rem; color: var(--muted); display: block; }
.tl b { font-weight: 600; }
.tl p { margin: 2px 0 0; color: var(--muted); font-size: .88rem; }
.phase ul, .card ul { margin: 0; padding-left: 1.1rem; }
.card li { margin-bottom: .25rem; }

.check { display: flex; gap: 10px; align-items: flex-start; padding: 5px 0; cursor: pointer; }
.check input { margin-top: 5px; accent-color: var(--oak); }
.check input:checked + span { color: var(--muted); text-decoration: line-through; }

.bar { display: flex; height: 8px; border-radius: 4px; background: var(--line); overflow: hidden; min-width: 80px; }
.bar .lo { background: var(--oak); } .bar .hi { background: var(--oak-soft); }
.swatches { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
.swatch span { display: block; height: 64px; border-radius: 10px; border: 1px solid var(--line); margin-bottom: 6px; }
.swatch small { display: block; color: var(--muted); }
.room-size { color: var(--oak); font-size: .85rem; font-weight: 500; margin: -.4rem 0 .6rem; }
.finish { margin: .7rem 0 0; padding-top: .6rem; border-top: 1px dashed var(--line); font-size: .85rem; color: var(--muted); }
.note { background: var(--warn-bg); color: var(--warn); border-radius: 10px; padding: 10px 14px; font-size: .88rem; margin: 0 0 14px; }

/* Viewer */
.viewer { width: min(1100px, 96vw); height: 92vh; padding: 0; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); color: var(--ink); }
.viewer::backdrop { background: rgba(0, 0, 0, .55); }
.viewer[open] { display: flex; flex-direction: column; }
.viewer-bar { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 14px; border-bottom: 1px solid var(--line); }
.viewer-bar strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .92rem; }
.viewer-actions { display: flex; gap: 14px; align-items: center; flex-shrink: 0; font-size: .88rem; }
.viewer-actions button { border: 0; background: none; cursor: pointer; font-size: 1.1rem; }
.viewer-body { flex: 1; overflow: auto; display: grid; place-items: center; background: var(--bg); }
.viewer-body iframe { width: 100%; height: 100%; border: 0; }
.viewer-body img { max-width: 100%; max-height: 100%; }
.viewer-body p { color: var(--muted); padding: 20px; text-align: center; }

/* 3D */
.v3d-canvas { position: relative; height: min(72vh, 680px); border-radius: var(--radius); overflow: hidden; border: 1px solid var(--line); background: #dfe6ea; touch-action: none; }
.v3d-canvas canvas { display: block; width: 100%; height: 100%; }
.v3d-labels { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.v3d-label { position: absolute; left: 0; top: 0; background: rgba(255, 253, 249, .88); color: #2b2a28; font-size: .72rem; padding: 2px 8px; border-radius: 999px; white-space: nowrap; box-shadow: 0 1px 3px rgba(0, 0, 0, .15); }
.v3d-hint { position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%); background: rgba(0, 0, 0, .7); color: #fff; font-size: .82rem; padding: 6px 12px; border-radius: 8px; white-space: nowrap; }
.v3d-bar { display: flex; flex-direction: column; gap: 10px; margin-top: 12px; }
.v3d-tools { display: flex; flex-wrap: wrap; gap: 10px 18px; align-items: center; font-size: .88rem; color: var(--muted); }
.v3d-tools label { display: flex; gap: 6px; align-items: center; }

.foot { padding-block: 24px 40px; color: var(--muted); font-size: .82rem; }

@media (max-width: 560px) {
  .ms > summary { grid-template-columns: 30px 1fr; }
  .ms-amt { grid-column: 2; text-align: left; }
  .kv { grid-template-columns: 1fr; gap: 2px; }
  .kv dd { margin-bottom: 8px; }
}
