:root {
  color-scheme: light;
  --page: #efede8;
  --surface: #f8f7f4;
  --panel: #fbfaf8;
  --card: #f1eee9;
  --card-strong: #e7e2da;
  --text: #25221e;
  --muted: #77716a;
  --border: #d8d3cb;
  --border-strong: #bcb5ab;
  --dark: #282521;
  --accent: #9a795c;
  --accent-soft: #e5dace;
  --danger: #9a4e45;
  --success: #56715a;
  --shadow: 0 18px 48px rgba(57, 49, 41, 0.09);
}

* { box-sizing: border-box; }

html, body { margin: 0; min-height: 100%; background: var(--page); color: var(--text); }
body { font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; overflow: hidden; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: 0.45; }

.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
.mobile-only { display: none; }

.app-shell { min-height: 100vh; display: grid; grid-template-rows: 72px minmax(0, 1fr); }
.topbar { display: grid; grid-template-columns: minmax(220px, 1fr) auto minmax(300px, 1fr); gap: 20px; align-items: center; padding: 0 24px; border-bottom: 1px solid var(--border); background: rgba(248, 247, 244, 0.97); z-index: 10; }
.brand { display: inline-flex; width: max-content; align-items: center; gap: 11px; color: var(--text); text-decoration: none; }
.brand-mark { display: grid; place-items: center; width: 38px; height: 38px; border-radius: 11px; background: var(--dark); color: #fff; font-size: 18px; font-weight: 700; }
.brand strong, .brand small { display: block; }
.brand strong { font-size: 15px; letter-spacing: 0.01em; }
.brand small { margin-top: 2px; color: var(--muted); font-size: 11px; }
.project-switcher, .top-actions, .toolbar-group { display: flex; align-items: center; gap: 8px; }
.top-actions { justify-content: flex-end; }
.select-control, input[type="text"], input[type="number"], select, textarea { width: 100%; border: 1px solid var(--border); border-radius: 10px; background: #fff; padding: 10px 12px; outline: none; }
.select-control { min-width: 210px; padding: 9px 34px 9px 12px; }
.select-control:focus, input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(154, 121, 92, 0.12); }
.btn { min-height: 38px; border: 1px solid transparent; border-radius: 10px; padding: 9px 14px; font-weight: 600; transition: 0.18s ease; }
.btn:hover { transform: translateY(-1px); }
.btn-light { border-color: var(--border); background: #fff; }
.btn-light:hover { border-color: var(--border-strong); }
.btn-dark { background: var(--dark); color: #fff; }
.btn-dark:hover { background: #151310; }
.btn-danger { border-color: rgba(154, 78, 69, 0.25); background: #fff5f3; color: var(--danger); }
.btn-block { width: 100%; }
.save-status { font-size: 12px; color: var(--muted); }
.save-status.is-dirty { color: var(--accent); }
.save-status.is-saving { color: #76634f; }
.save-status.is-saved { color: var(--success); }

.workspace { min-height: 0; display: grid; grid-template-columns: 84px 300px minmax(480px, 1fr) 320px; }
.stepbar { display: flex; flex-direction: column; gap: 8px; padding: 16px 10px; border-right: 1px solid var(--border); background: #e8e5df; }
.step-button { display: grid; gap: 6px; min-height: 78px; align-content: center; border: 1px solid transparent; border-radius: 12px; background: transparent; color: var(--muted); font-size: 11px; text-align: left; padding: 10px; }
.step-button:hover { background: rgba(255,255,255,0.55); color: var(--text); }
.step-button.is-active { border-color: var(--border); background: #fff; color: var(--text); box-shadow: 0 8px 20px rgba(68, 59, 50, 0.06); }
.step-number { font-size: 10px; letter-spacing: 0.12em; color: var(--accent); }

.panel { min-width: 0; background: var(--panel); }
.left-panel { border-right: 1px solid var(--border); }
.right-panel { border-left: 1px solid var(--border); }
.panel-heading { min-height: 82px; display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 18px 18px 14px; border-bottom: 1px solid var(--border); }
.panel-heading h1, .panel-heading h2 { margin: 4px 0 0; font-size: 18px; line-height: 1.25; }
.eyebrow { display: block; color: var(--accent); font-size: 10px; font-weight: 700; letter-spacing: 0.12em; text-transform: uppercase; }
.panel-content { height: calc(100vh - 154px); overflow: auto; padding: 16px; scrollbar-width: thin; }
.section-block + .section-block { margin-top: 20px; padding-top: 18px; border-top: 1px solid var(--border); }
.section-title { display: flex; justify-content: space-between; gap: 8px; align-items: center; margin: 0 0 10px; font-size: 13px; font-weight: 700; }
.section-note { margin: -3px 0 12px; color: var(--muted); font-size: 12px; line-height: 1.45; }

.canvas-area { min-width: 0; min-height: 0; display: grid; grid-template-rows: 54px minmax(0, 1fr); background: #f0eee9; }
.canvas-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 14px; border-bottom: 1px solid var(--border); background: var(--surface); }
.tool-btn { min-height: 34px; border: 1px solid var(--border); border-radius: 8px; background: #fff; padding: 7px 10px; font-size: 12px; }
.tool-btn:hover { border-color: var(--border-strong); }
.toolbar-divider { width: 1px; height: 24px; background: var(--border); }
.switch-control { display: inline-flex; gap: 7px; align-items: center; color: var(--muted); font-size: 12px; }
.switch-control input { accent-color: var(--dark); }
.size-badge { border-radius: 999px; background: var(--card); padding: 7px 10px; color: var(--muted); font-size: 12px; }
.canvas-wrap { position: relative; min-height: 0; padding: 18px; overflow: hidden; }
#planSvg { width: 100%; height: 100%; min-height: 420px; display: block; border: 1px solid var(--border); border-radius: 16px; background: #f7f5f1; box-shadow: var(--shadow); touch-action: none; user-select: none; }
.canvas-hint { position: absolute; left: 34px; bottom: 32px; border: 1px solid var(--border); border-radius: 999px; background: rgba(255,255,255,0.92); padding: 7px 11px; color: var(--muted); font-size: 11px; pointer-events: none; }

.field { display: grid; gap: 6px; margin-bottom: 12px; }
.field > span { color: var(--muted); font-size: 11px; font-weight: 600; }
.field-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; }
.field-row.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.field input[type="color"] { width: 100%; height: 42px; border: 1px solid var(--border); border-radius: 10px; background: #fff; padding: 4px; }

.template-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; }
.template-grid.compact { max-height: 360px; overflow: auto; }
.template-card { border: 1px solid var(--border); border-radius: 12px; background: #fff; padding: 10px; text-align: left; }
.template-card:hover, .template-card.is-active { border-color: var(--accent); background: #fbf7f2; }
.template-shape { height: 56px; display: grid; place-items: center; margin-bottom: 8px; border-radius: 8px; background: var(--card); }
.template-shape svg { width: 54px; height: 42px; overflow: visible; }
.template-card strong { display: block; font-size: 12px; }
.template-card small { display: block; margin-top: 3px; color: var(--muted); font-size: 10px; line-height: 1.3; }

.catalog-roots { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin-bottom: 14px; }
.root-tab { border: 1px solid var(--border); border-radius: 10px; background: #fff; padding: 10px 8px; font-size: 11px; font-weight: 600; }
.root-tab.is-active { border-color: var(--dark); background: var(--dark); color: #fff; }
.breadcrumbs { display: flex; flex-wrap: wrap; align-items: center; gap: 5px; margin-bottom: 12px; }
.breadcrumb { border: 0; background: transparent; padding: 0; color: var(--muted); font-size: 11px; }
.breadcrumb:hover { color: var(--text); }
.breadcrumb + .breadcrumb::before { content: "/"; margin-right: 5px; color: var(--border-strong); }
.category-list { display: grid; gap: 8px; }
.category-card { display: flex; align-items: center; justify-content: space-between; gap: 10px; width: 100%; border: 1px solid var(--border); border-radius: 11px; background: #fff; padding: 11px 12px; text-align: left; }
.category-card:hover { border-color: var(--accent); }
.category-card strong { font-size: 12px; }
.category-card span { color: var(--muted); font-size: 18px; }
.catalog-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; }
.item-card { overflow: hidden; border: 1px solid var(--border); border-radius: 12px; background: #fff; text-align: left; padding: 0; }
.item-card:hover { border-color: var(--accent); transform: translateY(-1px); }
.item-preview { position: relative; height: 82px; display: grid; place-items: center; background: var(--card); }
.item-preview::after { content: ""; width: 54%; height: 34%; border-radius: 12px; background: var(--preview-color, #c8c0b5); box-shadow: 0 8px 16px rgba(49, 42, 35, 0.14); }
.item-preview[data-type*="wallpaper"]::after, .item-preview[data-type="paint"]::after, .item-preview[data-type="floor"]::after, .item-preview[data-type="tile"]::after { width: 100%; height: 100%; border-radius: 0; box-shadow: none; opacity: 0.9; }
.item-preview[data-type="chandelier"]::after { width: 45%; height: 12%; border-radius: 999px; border: 5px solid var(--preview-color); background: transparent; box-shadow: 0 14px 12px rgba(49,42,35,.12); }
.item-preview[data-type="plant"]::after { width: 36%; height: 62%; border-radius: 60% 45% 55% 40%; }
.item-preview[data-type="rug"]::after { width: 72%; height: 56%; border-radius: 7px; }
.item-body { padding: 9px; }
.item-body strong { display: block; font-size: 11px; line-height: 1.3; }
.item-body small { display: block; margin-top: 4px; color: var(--muted); font-size: 9px; }

.selection-card { border: 1px solid var(--border); border-radius: 12px; background: var(--card); padding: 12px; margin-bottom: 14px; }
.selection-card strong { display: block; font-size: 13px; }
.selection-card small { display: block; margin-top: 4px; color: var(--muted); font-size: 11px; }
.button-row { display: flex; gap: 8px; }
.button-row .btn { flex: 1; }
.vertex-list { display: grid; gap: 6px; }
.vertex-row { display: grid; grid-template-columns: 28px 1fr 1fr; gap: 6px; align-items: center; }
.vertex-index { display: grid; place-items: center; width: 28px; height: 28px; border-radius: 8px; background: var(--card); color: var(--muted); font-size: 10px; }

.finish-summary { display: grid; gap: 8px; }
.finish-row { display: grid; grid-template-columns: 36px 1fr auto; align-items: center; gap: 9px; border: 1px solid var(--border); border-radius: 10px; background: #fff; padding: 8px; }
.finish-swatch { width: 36px; height: 36px; border-radius: 8px; border: 1px solid rgba(0,0,0,.07); }
.finish-row strong { display: block; font-size: 11px; }
.finish-row small { display: block; margin-top: 2px; color: var(--muted); font-size: 9px; }
.clear-link { border: 0; background: transparent; color: var(--danger); font-size: 10px; padding: 4px; }

.style-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.style-card { position: relative; min-height: 72px; display: grid; align-content: end; border: 1px solid var(--border); border-radius: 11px; background: var(--style-color, #d0c8bd); padding: 10px; text-align: left; overflow: hidden; }
.style-card::before { content: ""; position: absolute; inset: 0; background: rgba(255,255,255,.5); }
.style-card span { position: relative; font-size: 11px; font-weight: 700; }
.style-card.is-active { border: 2px solid var(--dark); }
.render-note { min-height: 100px; resize: vertical; }
.render-status { border: 1px solid var(--border); border-radius: 12px; background: var(--card); padding: 12px; margin-bottom: 12px; }
.render-status strong { display: block; font-size: 12px; }
.render-status p { margin: 5px 0 0; color: var(--muted); font-size: 11px; line-height: 1.4; }
.result-list { display: grid; gap: 12px; }
.result-card { overflow: hidden; border: 1px solid var(--border); border-radius: 12px; background: #fff; }
.result-card img { width: 100%; aspect-ratio: 3 / 2; display: block; object-fit: cover; background: var(--card); }
.result-card div { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 9px 10px; }
.result-card strong { font-size: 11px; }
.result-card a { color: var(--accent); font-size: 10px; text-decoration: none; }
.angle-placeholders { display: grid; gap: 8px; }
.angle-placeholder { min-height: 72px; display: flex; align-items: center; justify-content: space-between; gap: 12px; border: 1px dashed var(--border-strong); border-radius: 11px; padding: 12px; background: #fff; }
.angle-placeholder strong { font-size: 11px; }
.angle-placeholder span { color: var(--muted); font-size: 10px; }

.icon-btn { display: grid; place-items: center; width: 34px; height: 34px; border: 1px solid var(--border); border-radius: 9px; background: #fff; font-size: 20px; line-height: 1; }
.toast { position: fixed; left: 50%; bottom: 24px; z-index: 50; max-width: min(440px, calc(100vw - 32px)); transform: translate(-50%, 20px); border-radius: 12px; background: var(--dark); color: #fff; padding: 11px 15px; font-size: 12px; opacity: 0; pointer-events: none; transition: .2s ease; }
.toast.is-visible { opacity: 1; transform: translate(-50%, 0); }
.dialog { width: min(760px, calc(100vw - 24px)); border: 0; border-radius: 18px; padding: 0; background: transparent; }
.dialog::backdrop { background: rgba(25,22,19,.46); }
.dialog-card { max-height: min(700px, calc(100vh - 32px)); overflow: auto; border: 1px solid var(--border); border-radius: 18px; background: var(--panel); padding: 20px; box-shadow: var(--shadow); }
.dialog-header, .dialog-actions { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.dialog-header { margin-bottom: 18px; }
.dialog-header h2 { margin: 4px 0 0; font-size: 21px; }
.dialog-actions { margin-top: 18px; justify-content: flex-end; }

.room-fill { fill: #ece7de; stroke: none; }
.zone-fill { fill: rgba(154,121,92,.08); stroke: #a78b71; stroke-width: 1.5; stroke-dasharray: 7 6; }
.zone-label { font-size: 13px; fill: #857b70; font-weight: 600; pointer-events: none; }
.wall-line { fill: none; stroke: #39342e; stroke-width: 11; stroke-linecap: square; stroke-linejoin: miter; }
.wall-inner { fill: none; stroke: #f9f8f5; stroke-width: 4; stroke-linecap: square; stroke-linejoin: miter; }
.object-group { cursor: grab; }
.object-group:active { cursor: grabbing; }
.object-shape { stroke: rgba(52,46,40,.34); stroke-width: 1.5; filter: url(#objectShadow); }
.object-label { fill: #3f3933; font-size: 11px; font-weight: 650; text-anchor: middle; dominant-baseline: middle; pointer-events: none; }
.selected-outline { fill: none; stroke: #7c6049; stroke-width: 3; stroke-dasharray: 7 5; pointer-events: none; }
.rotation-line { stroke: #7c6049; stroke-width: 2; pointer-events: none; }
.rotation-handle { fill: #fff; stroke: #7c6049; stroke-width: 3; cursor: grab; }
.vertex-handle { fill: #fff; stroke: #8c6b50; stroke-width: 3; cursor: move; }
.vertex-handle.is-selected { fill: #8c6b50; }
.opening-group { cursor: grab; }
.opening-cut { stroke: #f9f8f5; stroke-width: 15; }
.window-line { stroke: #779096; stroke-width: 7; }
.window-line-inner { stroke: #d9e4e6; stroke-width: 2; }
.door-leaf { stroke: #9a795c; stroke-width: 5; }
.door-arc { fill: none; stroke: #9a795c; stroke-width: 2; stroke-dasharray: 5 4; }
.dimension-line { stroke: #918980; stroke-width: 1.4; }
.dimension-text { fill: #746d65; font-size: 11px; text-anchor: middle; }

@media (max-width: 1240px) {
  .workspace { grid-template-columns: 72px 270px minmax(420px, 1fr) 290px; }
  .topbar { grid-template-columns: minmax(180px, 1fr) auto minmax(220px, 1fr); padding: 0 16px; }
  .save-status { display: none; }
}

@media (max-width: 980px) {
  body { overflow: auto; }
  .app-shell { min-height: 100dvh; grid-template-rows: auto minmax(0, 1fr); }
  .topbar { min-height: 68px; grid-template-columns: 1fr auto; padding: 10px 12px; }
  .project-switcher { display: none; }
  .top-actions .btn-light { display: none; }
  .workspace { min-height: calc(100dvh - 68px); grid-template-columns: 1fr; grid-template-rows: minmax(0, 1fr) 74px; }
  .stepbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; height: 74px; flex-direction: row; padding: 7px 10px; border: 0; border-top: 1px solid var(--border); }
  .step-button { flex: 1; min-height: 58px; text-align: center; align-content: center; justify-items: center; padding: 6px; }
  .left-panel, .right-panel { position: fixed; top: 0; bottom: 74px; z-index: 40; width: min(360px, 92vw); box-shadow: var(--shadow); transition: transform .22s ease; }
  .left-panel { left: 0; transform: translateX(-104%); }
  .right-panel { right: 0; transform: translateX(104%); }
  .left-panel.is-open, .right-panel.is-open { transform: translateX(0); }
  .panel-content { height: calc(100dvh - 156px); }
  .canvas-area { grid-row: 1; grid-template-rows: auto minmax(0, 1fr) auto; min-height: calc(100dvh - 142px); }
  .canvas-wrap { min-height: 560px; padding: 10px; }
  #planSvg { min-height: 530px; }
  .canvas-toolbar { flex-wrap: wrap; padding: 7px 10px; }
  .canvas-hint { left: 24px; bottom: 22px; }
  .mobile-only { display: grid; }
  .mobile-canvas-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; padding: 8px 10px 12px; }
}

@media (max-width: 560px) {
  .brand small { display: none; }
  .top-actions { gap: 6px; }
  .top-actions .btn { padding: 9px 10px; font-size: 11px; }
  .toolbar-group:first-child .switch-control, .toolbar-divider, #fitBtn { display: none; }
  .canvas-toolbar { min-height: 50px; }
  .size-badge { margin-left: auto; }
  .canvas-wrap { min-height: 490px; }
  #planSvg { min-height: 465px; border-radius: 12px; }
  .template-grid, .catalog-grid { grid-template-columns: 1fr 1fr; }
  .field-row.three { grid-template-columns: 1fr 1fr; }
}
.result-links { display: flex; align-items: center; gap: 10px; }
.result-links a { white-space: nowrap; }
