:root {
  --bg: #f6f3ee;
  --surface: #ffffff;
  --surface-2: #f1ede6;
  --text: #1f1d1a;
  --muted: #6b665e;
  --line: #e2dcd2;
  --accent: #2f5d50;
  --accent-ink: #ffffff;
  --accent-soft: #e3ece8;
  --warn: #b5572e;
  --danger: #b3261e;
  --good: #2f7d4f;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(30, 25, 20, .06), 0 4px 16px rgba(30, 25, 20, .06);
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background: var(--bg);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #171614; --surface: #211f1c; --surface-2: #2a2824; --text: #efebe4; --muted: #a49d92;
    --line: #38342e; --accent: #7fb8a4; --accent-ink: #10201b; --accent-soft: #24332e; --warn: #e08a5f;
    --danger: #ef7a72; --good: #74c495;
  }
}
* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; background: var(--bg); }
h1, h2, h3, h4 { margin: 0 0 .5rem; line-height: 1.2; }
p { margin: 0 0 .6rem; line-height: 1.5; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.right { text-align: right; }
.error { color: var(--danger); }
[hidden] { display: none !important; }

/* buttons & inputs */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  border: 1px solid var(--accent); background: var(--accent); color: var(--accent-ink);
  border-radius: 999px; padding: .55rem 1.1rem; font: inherit; font-weight: 600; cursor: pointer;
  transition: filter .15s, background .15s;
}
.btn:hover { filter: brightness(1.08); }
.btn:disabled { opacity: .45; cursor: not-allowed; filter: none; }
.btn.ghost { background: transparent; color: var(--text); border-color: var(--line); }
.btn.ghost:hover { background: var(--surface-2); }
.btn.ghost.active { background: var(--accent-soft); border-color: var(--accent); }
.btn.small { padding: .32rem .75rem; font-size: .82rem; }
.btn.danger { color: var(--danger); }
.icon-btn { border: 0; background: none; font-size: 1.6rem; cursor: pointer; color: var(--muted); line-height: 1; }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--line);
  border-radius: 8px; padding: .5rem .6rem; width: 100%;
}
input:focus, select:focus, textarea:focus, .btn:focus-visible, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
label { display: block; font-size: .85rem; color: var(--muted); }
label > input, label > select, label > textarea { margin-top: .25rem; }
.check { display: inline-flex; align-items: center; gap: .35rem; color: var(--text); }
.check input { width: auto; margin: 0; }

/* top bar */
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 1rem;
  padding: .6rem 1rem; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: .55rem; font-weight: 700; color: var(--accent); white-space: nowrap; }
.brand svg { width: 28px; height: 28px; }
.brand span { color: var(--text); }
.project-name { max-width: 280px; border-color: transparent; background: transparent; font-weight: 600; }
.project-name:hover, .project-name:focus { border-color: var(--line); background: var(--surface); }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: .5rem; }
.lang { display: flex; align-items: center; gap: .4rem; white-space: nowrap; }
.lang select { width: auto; padding: .3rem .4rem; margin: 0; }

/* start */
.start { display: flex; justify-content: center; padding: 3rem 1rem; }
.hero { max-width: 720px; text-align: center; }
.hero h1 { font-size: clamp(1.8rem, 4vw, 2.6rem); letter-spacing: -.02em; }
.hero > p { color: var(--muted); font-size: 1.08rem; }
.dropzone {
  margin: 1.8rem 0 .6rem; display: flex; flex-direction: column; align-items: center; gap: .4rem;
  padding: 2.6rem 1rem; border: 2px dashed var(--line); border-radius: 18px; background: var(--surface);
  cursor: pointer; color: var(--text); font-size: 1rem; transition: border-color .15s, background .15s;
}
.dropzone svg { width: 44px; height: 44px; color: var(--accent); }
.dropzone span { color: var(--muted); font-size: .9rem; }
.dropzone:hover, .dropzone.over { border-color: var(--accent); background: var(--accent-soft); }
.hint { font-size: .88rem; color: var(--muted); }
.features { list-style: none; padding: 0; margin: 2rem 0 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: .6rem; text-align: left; }
.features li { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: .8rem .9rem; font-size: .9rem; color: var(--muted); }
.features b { color: var(--text); display: block; }

/* workspace */
.workspace { display: grid; grid-template-columns: minmax(0, 1fr) 420px; gap: 1rem; padding: 1rem; align-items: start; }
.stage-wrap { position: sticky; top: 4.2rem; }
.stage-toolbar { display: flex; justify-content: space-between; align-items: center; gap: .5rem; margin-bottom: .5rem; flex-wrap: wrap; }
.toolbar-right { display: flex; align-items: center; gap: .8rem; }
.segmented { display: inline-flex; background: var(--surface-2); border-radius: 999px; padding: 3px; }
.segmented button { border: 0; background: none; padding: .35rem .9rem; border-radius: 999px; font: inherit; font-size: .88rem; cursor: pointer; color: var(--muted); }
.segmented button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); font-weight: 600; }
.stage { position: relative; border-radius: var(--radius); overflow: hidden; background: #000; box-shadow: var(--shadow); user-select: none; touch-action: none; line-height: 0; }
.stage canvas { width: 100%; height: auto; display: block; }
.stage canvas.before { position: absolute; inset: 0; height: 100%; }
.stage.drawing { cursor: crosshair; }
.render-img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; background: #000; }
.overlay { position: absolute; inset: 0; width: 100%; height: 100%; }
.part-shape { cursor: pointer; transition: fill-opacity .15s; }
.part-shape:hover { fill-opacity: .22; }
.stage.drawing .part-shape { pointer-events: none; }
.vertex { cursor: grab; }
.compare-handle { position: absolute; top: 0; bottom: 0; width: 3px; margin-left: -1.5px; background: #fff; pointer-events: none; box-shadow: 0 0 6px rgba(0,0,0,.4); }
.compare-handle span { position: absolute; top: 50%; left: 50%; width: 34px; height: 34px; margin: -17px 0 0 -17px; border-radius: 50%; background: #fff; box-shadow: 0 1px 6px rgba(0,0,0,.4); }
.compare-handle span::before { content: "‹ ›"; position: absolute; inset: 0; display: grid; place-items: center; color: #333; font-weight: 700; line-height: 1; }
.stage-busy { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1rem; background: rgba(20, 18, 15, .55); color: #fff; line-height: 1.4; text-align: center; padding: 1rem; }
.stage-note { font-size: .8rem; color: var(--muted); margin-top: .5rem; }
.draw-bar { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; margin-top: .5rem; padding: .6rem .8rem; background: var(--accent-soft); border-radius: var(--radius); font-size: .88rem; }
.draw-bar span { flex: 1 1 220px; }
.spinner { width: 38px; height: 38px; border: 3px solid rgba(255,255,255,.3); border-top-color: #fff; border-radius: 50%; animation: spin .9s linear infinite; }
.spinner.small { width: 14px; height: 14px; border-width: 2px; border-color: currentColor; border-top-color: transparent; display: inline-block; vertical-align: -2px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* panel */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.variant-bar { display: flex; align-items: end; gap: .4rem; padding: .7rem .8rem; border-bottom: 1px solid var(--line); background: var(--surface-2); flex-wrap: wrap; }
.variant-bar label { flex: 1 1 140px; }
.variant-bar select { padding: .3rem .5rem; }
.tabs { display: flex; border-bottom: 1px solid var(--line); }
.tabs button { flex: 1; border: 0; background: none; padding: .75rem .3rem; font: inherit; font-size: .9rem; cursor: pointer; color: var(--muted); border-bottom: 2px solid transparent; }
.tabs button.active { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }
.tab-body { padding: .9rem; max-height: calc(100vh - 11rem); overflow-y: auto; }
.tab-body > section { display: none; }
.tab-body > section.active { display: block; }
.card { background: var(--surface-2); border-radius: var(--radius); padding: .8rem .9rem; margin-bottom: .9rem; font-size: .92rem; }
.card.warn { background: color-mix(in srgb, var(--warn) 14%, var(--surface)); }
.analysis dl { display: grid; grid-template-columns: auto 1fr; gap: .2rem .7rem; margin: .4rem 0; font-size: .86rem; }
.analysis dt { color: var(--muted); }
.analysis dd { margin: 0; }
details summary { cursor: pointer; font-weight: 600; font-size: .88rem; margin: .3rem 0; }
details ul { margin: .3rem 0; padding-left: 1.1rem; font-size: .88rem; line-height: 1.5; }
.section-head { display: flex; align-items: center; justify-content: space-between; margin: .4rem 0 .6rem; }
.section-head h3 { font-size: 1rem; margin: 0; }
.section-head .muted { font-weight: 400; font-size: .82rem; }

/* parts */
.part { border: 1px solid var(--line); border-left: 4px solid var(--part); border-radius: 10px; margin-bottom: .5rem; background: var(--surface); }
.part.open { box-shadow: var(--shadow); }
.part header { display: flex; align-items: center; gap: .65rem; padding: .6rem .7rem; cursor: pointer; }
.part-title { flex: 1; min-width: 0; }
.part-title strong { display: block; font-size: .92rem; }
.part-title small { color: var(--muted); font-size: .78rem; }
.cond.worn, .cond.dated { color: var(--warn); }
.cond.damaged { color: var(--danger); }
.cond.good { color: var(--good); }
.swatch { width: 22px; height: 22px; border-radius: 6px; border: 1px solid rgba(0,0,0,.15); flex: none; }
.switch { position: relative; width: 36px; height: 20px; flex: none; cursor: pointer; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch span { position: absolute; inset: 0; background: var(--line); border-radius: 999px; transition: background .15s; }
.switch span::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: transform .15s; box-shadow: 0 1px 2px rgba(0,0,0,.2); }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { transform: translateX(16px); }
.switch input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.part-body { padding: 0 .8rem .8rem; }
fieldset { border: 0; padding: 0; margin: .7rem 0 0; }
legend { font-size: .78rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin-bottom: .35rem; }
fieldset.inline { display: flex; align-items: center; gap: .6rem; }
fieldset.inline legend { float: left; margin: 0; }
fieldset.inline select { width: auto; }
.treatments { display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: .35rem; }
.treat { text-align: left; border: 1px solid var(--line); background: var(--surface); border-radius: 8px; padding: .4rem .5rem; cursor: pointer; font: inherit; color: var(--text); }
.treat b { display: block; font-size: .84rem; }
.treat > span { font-size: .72rem; color: var(--muted); }
.treat.active { border-color: var(--accent); background: var(--accent-soft); box-shadow: inset 0 0 0 1px var(--accent); }
.off { opacity: .25; }
.dots { letter-spacing: -1px; font-size: .7em; }
.materials { display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: .35rem; }
.mat { display: flex; align-items: center; gap: .4rem; border: 1px solid var(--line); background: var(--surface); border-radius: 8px; padding: .3rem .4rem; font: inherit; font-size: .78rem; cursor: pointer; color: var(--text); text-align: left; }
.mat.active { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.mat-swatch { width: 22px; height: 22px; border-radius: 5px; flex: none; background: var(--c); border: 1px solid rgba(0,0,0,.12); }
.tex-wood { background: repeating-linear-gradient(95deg, var(--c) 0 3px, color-mix(in srgb, var(--c) 80%, #000) 3px 4px, var(--c) 4px 7px); }
.tex-marble { background: linear-gradient(135deg, var(--c) 40%, color-mix(in srgb, var(--c) 60%, #777) 45%, var(--c) 50%); }
.tex-concrete { background: radial-gradient(circle at 30% 30%, color-mix(in srgb, var(--c) 85%, #fff), var(--c)); }
.tex-terrazzo { background: radial-gradient(circle at 25% 30%, #c48460 2px, transparent 2.5px), radial-gradient(circle at 70% 65%, #506860 2px, transparent 2.5px), radial-gradient(circle at 60% 20%, #777 1.5px, transparent 2px), var(--c); }
.tex-subway { background: linear-gradient(#bbb 1px, transparent 1px) 0 0 / 100% 7px, var(--c); }
.tex-square, .tex-zellige { background: linear-gradient(#bbb 1px, transparent 1px) 0 0 / 7px 7px, linear-gradient(90deg, #bbb 1px, transparent 1px) 0 0 / 7px 7px, var(--c); }
.tex-brushed { background: repeating-linear-gradient(0deg, var(--c) 0 1px, color-mix(in srgb, var(--c) 85%, #fff) 1px 2px); }
.colors { display: flex; flex-wrap: wrap; gap: .3rem; }
.color { width: 28px; height: 28px; border-radius: 50%; border: 1px solid rgba(0,0,0,.18); cursor: pointer; padding: 0; position: relative; }
.color.active { box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--accent); }
.color.custom { display: grid; place-items: center; background: conic-gradient(red, yellow, lime, cyan, blue, magenta, red); overflow: hidden; }
.color.custom input { position: absolute; inset: 0; opacity: 0; cursor: pointer; padding: 0; margin: 0; }
.color.custom span { color: #fff; font-weight: 700; text-shadow: 0 0 3px #000; pointer-events: none; line-height: 1; }
.part-tools { display: flex; flex-wrap: wrap; gap: .3rem; margin-top: .8rem; padding-top: .7rem; border-top: 1px dashed var(--line); }

/* styles */
.style-card { display: flex; flex-direction: column; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; margin-bottom: .7rem; }
.style-card.active { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.palette { display: flex; height: 38px; }
.palette span { flex: 1; }
.style-body { padding: .7rem .8rem; font-size: .9rem; }
.style-body h4 { display: flex; align-items: center; gap: .4rem; flex-wrap: wrap; font-size: 1rem; }
.rec { color: var(--accent); font-weight: 500; }
.badge { font-size: .7rem; font-weight: 700; background: var(--accent-soft); color: var(--accent); border-radius: 999px; padding: .12rem .5rem; }
.badge.dark { background: var(--accent); color: var(--accent-ink); }

/* plan */
.plan-form .grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: .6rem; margin-bottom: .6rem; }
.plan-form textarea { margin-bottom: .7rem; }
.plan h3 { font-size: 1.2rem; }
.plan h4 { margin: 1.3rem 0 .5rem; font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.total { display: flex; justify-content: space-between; align-items: baseline; padding: .8rem .9rem; border-radius: var(--radius); background: var(--accent-soft); margin: .5rem 0; }
.total strong { font-size: 1.3rem; color: var(--accent); }
.note { font-size: .9rem; padding: .5rem .7rem; border-left: 3px solid var(--warn); background: var(--surface-2); border-radius: 4px; }
.plan-actions { display: flex; flex-wrap: wrap; gap: .4rem; margin: .7rem 0 .4rem; }
.plan-part { border: 1px solid var(--line); border-radius: 10px; padding: .7rem .8rem; margin-bottom: .5rem; font-size: .9rem; }
.plan-part header { display: flex; justify-content: space-between; gap: .5rem; margin-bottom: .2rem; }
.plan-part .meta { color: var(--muted); font-size: .8rem; }
.verdict { font-size: .72rem; font-weight: 700; border-radius: 999px; padding: .1rem .5rem; white-space: nowrap; align-self: start; }
.good_choice .verdict { background: color-mix(in srgb, var(--good) 18%, transparent); color: var(--good); }
.possible .verdict { background: var(--surface-2); color: var(--muted); }
.reconsider .verdict { background: color-mix(in srgb, var(--warn) 18%, transparent); color: var(--warn); }
.reconsider { border-color: color-mix(in srgb, var(--warn) 50%, var(--line)); }
.tips, .warnings { margin: .3rem 0 0; padding-left: 1.1rem; font-size: .84rem; line-height: 1.45; }
.warnings li { color: var(--warn); }
.plan-palette { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: .5rem; }
.plan-palette div { font-size: .8rem; }
.plan-palette span { display: block; height: 40px; border-radius: 8px; border: 1px solid rgba(0,0,0,.12); margin-bottom: .25rem; }
.plan-palette small { display: block; color: var(--muted); }
.steps { padding-left: 1.2rem; font-size: .9rem; }
.steps li { margin-bottom: .5rem; }
.steps p { margin: .15rem 0 0; color: var(--muted); }
.shopping { list-style: none; padding: 0; margin: 0; font-size: .88rem; }
.shopping label { display: flex; align-items: center; gap: .5rem; padding: .35rem 0; border-bottom: 1px solid var(--line); color: var(--text); font-size: .88rem; }
.shopping input { width: auto; margin: 0; }
.shopping span { flex: 1; }
.shopping input:checked ~ span { text-decoration: line-through; color: var(--muted); }

/* chat */
.chat-log { display: flex; flex-direction: column; gap: .5rem; min-height: 200px; max-height: 50vh; overflow-y: auto; margin-bottom: .7rem; }
.msg { padding: .6rem .8rem; border-radius: 12px; font-size: .9rem; max-width: 92%; }
.msg p:last-child { margin: 0; }
.msg ul { margin: .2rem 0 .5rem; padding-left: 1.1rem; }
.msg.user { align-self: flex-end; background: var(--accent); color: var(--accent-ink); }
.msg.assistant { align-self: flex-start; background: var(--surface-2); }
.chips { display: flex; flex-wrap: wrap; gap: .3rem; margin-bottom: .6rem; }
.chip { border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: .25rem .65rem; font: inherit; font-size: .78rem; cursor: pointer; color: var(--text); }
.chip:hover { border-color: var(--accent); }
.chat-form { display: flex; gap: .4rem; align-items: end; }
.chat-form textarea { resize: vertical; }

/* dialogs, toast */
.dialog { border: 0; border-radius: 16px; padding: 1.2rem; width: min(560px, calc(100vw - 2rem)); background: var(--surface); color: var(--text); box-shadow: 0 10px 40px rgba(0,0,0,.25); }
.dialog.small { width: min(400px, calc(100vw - 2rem)); }
.dialog::backdrop { background: rgba(20, 18, 15, .45); }
.dialog > header { display: flex; justify-content: space-between; align-items: center; }
.dialog footer { display: flex; gap: .5rem; justify-content: flex-end; margin-top: 1rem; flex-wrap: wrap; }
.dialog form > * { margin-bottom: .7rem; }
.row-end { display: flex; justify-content: flex-end; gap: .5rem; }
.project-list { display: flex; flex-direction: column; gap: .5rem; max-height: 55vh; overflow-y: auto; }
.project-row { display: flex; align-items: center; gap: .7rem; padding: .5rem; border: 1px solid var(--line); border-radius: 10px; }
.project-row.current { border-color: var(--accent); }
.project-row img { width: 64px; height: 48px; object-fit: cover; border-radius: 6px; }
.project-row div { flex: 1; min-width: 0; }
.project-row small { display: block; color: var(--muted); font-size: .78rem; }
.toast { position: fixed; bottom: 1.2rem; left: 50%; transform: translateX(-50%); z-index: 50; background: var(--text); color: var(--bg); padding: .7rem 1.1rem; border-radius: 10px; box-shadow: var(--shadow); max-width: min(560px, calc(100vw - 2rem)); font-size: .92rem; }
.toast.error { background: var(--danger); color: #fff; }

/* print report */
.report { display: none; }
@media print {
  body > *:not(.report) { display: none !important; }
  .report { display: block; color: #000; background: #fff; font-size: 11pt; }
  .report .imgs { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
  .report figure { margin: 0; }
  .report img { width: 100%; border-radius: 6px; }
  .report figcaption { font-size: 9pt; color: #555; }
  .report table { width: 100%; border-collapse: collapse; margin: 6px 0; }
  .report td, .report th { border-bottom: 1px solid #ddd; padding: 4px; text-align: left; font-size: 10pt; }
  .report .sw { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-right: 4px; vertical-align: -1px; border: 1px solid #999; }
  .report h2 { margin-top: 16px; }
  .report h3 { font-size: 11pt; margin: 10px 0 2px; }
}

/* small screens */
@media (max-width: 960px) {
  .workspace { grid-template-columns: 1fr; padding: .6rem; }
  .stage-wrap { position: static; }
  .tab-body { max-height: none; }
  .lang { font-size: 0; gap: 0; }
  .lang select { font-size: .85rem; }
  .project-name { max-width: 140px; }
  .brand span { display: none; }
}
@media (max-width: 480px) {
  .plan-form .grid2 { grid-template-columns: 1fr; }
  .topbar { gap: .4rem; padding: .5rem .6rem; }
}
@media (max-width: 600px) {
  .topbar { flex-wrap: wrap; }
  .project-name { order: 3; flex: 1 1 100%; max-width: none; }
}

/* Android app and notched phones */
.topbar { padding-top: max(.6rem, env(safe-area-inset-top)); }
body { padding-bottom: env(safe-area-inset-bottom); }
.android-link { display: inline-block; margin-bottom: .6rem; color: var(--accent); font-weight: 600; font-size: .92rem; }
