:root {
  --navy: #10295f;
  --ink: #182543;
  --muted: #66738e;
  --line: #dbe3f0;
  --soft: #f5f8fd;
  --accent: #3455f5;
  --accent-2: #7157e8;
  --success: #18a874;
  --danger: #c13e55;
  --shadow: 0 14px 40px rgba(22, 48, 99, .08);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: #fff;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; min-width: 320px; background: #fff; overflow-y: auto; }
button, input { font: inherit; }
button { cursor: pointer; }
button:focus-visible, input:focus-visible, label:has(input:focus-visible) { outline: 3px solid rgba(52, 85, 245, .25); outline-offset: 2px; }

.app-header {
  min-height: 68px; padding: 0 28px; display: grid; grid-template-columns: auto 1fr auto; gap: 18px; align-items: center;
  border-bottom: 1px solid var(--line); background: rgba(255,255,255,.96); position: sticky; top: 0; z-index: 20;
}
.brand { color: var(--navy); font-size: 1.45rem; font-weight: 800; text-decoration: none; letter-spacing: -.04em; }
.privacy-state { margin: 0; display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: .9rem; font-weight: 650; }
.privacy-state span { width: 9px; height: 9px; border-radius: 50%; background: #25c888; box-shadow: 0 0 0 4px #ddf8ec; }
.text-button { border: 0; background: transparent; color: var(--navy); font-weight: 700; min-height: 44px; padding: 8px 12px; }
.header-actions { display: flex; align-items: center; gap: 6px; }
.header-actions a { min-height: 44px; display: inline-flex; align-items: center; padding: 8px 12px; color: var(--navy); font-size: .9rem; font-weight: 700; text-decoration: none; }

.app-shell { display: grid; grid-template-columns: 250px minmax(430px, 1.08fr) minmax(410px, .94fr); min-height: calc(100vh - 68px); }
.is-embedded .app-header { display: none; }
.is-embedded .app-shell { min-height: 100dvh; }
.workflow, .canvas-panel, .results-panel { min-width: 0; padding: 22px; }
.workflow { border-right: 1px solid var(--line); }
.results-panel { border-left: 1px solid var(--line); }

.step { display: grid; grid-template-columns: 38px 1fr; gap: 12px; position: relative; padding-bottom: 20px; }
.step:not(:last-of-type)::after { content: ""; position: absolute; left: 18px; top: 40px; bottom: 0; width: 1px; background: var(--line); }
.step-number { width: 38px; height: 38px; display: grid; place-items: center; border-radius: 50%; color: var(--accent); background: #eef2ff; font-weight: 800; position: relative; z-index: 1; }
.step.is-active .step-number, .step.is-complete .step-number { color: white; background: linear-gradient(135deg, var(--accent), var(--accent-2)); }
.step h2 { margin: 4px 0 4px; font-size: 1rem; color: var(--navy); }
.step p { margin: 0 0 10px; color: var(--muted); font-size: .83rem; line-height: 1.4; }

.upload-box { min-height: 70px; border: 1.5px dashed #b9c7e1; border-radius: 10px; position: relative; color: var(--accent); transition: .2s ease; }
.upload-box:hover, .upload-box.is-dragging { background: #f2f5ff; border-color: var(--accent); }
.upload-prompt { min-height: 68px; display: flex; align-items: center; justify-content: center; gap: 10px; padding: 10px; cursor: pointer; }
.upload-prompt svg { width: 25px; min-width: 25px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.upload-prompt span { display: grid; gap: 2px; min-width: 0; }
.upload-box small { color: var(--muted); }
.upload-preview-card { min-height: 68px; display: grid; grid-template-columns: 50px minmax(0,1fr) 36px; align-items: center; gap: 9px; padding: 8px; color: var(--ink); }
.upload-preview-card > img { width: 50px; height: 50px; border-radius: 8px; object-fit: cover; background: var(--soft); }
.upload-file-meta { min-width: 0; display: grid; gap: 3px; font-size: .72rem; }
.upload-file-meta strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-menu-button { width: 36px; height: 36px; padding: 0; border: 0; border-radius: 8px; color: var(--navy); background: var(--soft); font-weight: 900; letter-spacing: 1px; }
.file-menu { position: absolute; right: 8px; top: 50px; z-index: 30; min-width: 145px; padding: 6px; border: 1px solid var(--line); border-radius: 9px; background: #fff; box-shadow: var(--shadow); }
.file-menu label, .file-menu button { width: 100%; min-height: 38px; display: flex; align-items: center; padding: 8px 10px; border: 0; border-radius: 6px; color: var(--navy); background: transparent; font-size: .72rem; font-weight: 700; text-align: left; cursor: pointer; }
.file-menu label:hover, .file-menu button:hover { background: var(--soft); }

.dimension-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.dimension-grid label, .range-label { color: var(--muted); font-size: .75rem; font-weight: 650; }
.dimension-grid input { width: 100%; min-height: 42px; margin-top: 6px; border: 1px solid var(--line); border-radius: 8px; padding: 0 10px; color: var(--ink); }
.area-value { margin: 10px 0 0; padding: 8px 10px; border-radius: 8px; background: var(--soft); text-align: center; }
.dimension-visual { position: relative; height: 86px; margin: 38px 12px 0 18px; border: 1px dashed #9db4df; background: linear-gradient(145deg,#f8fbff,#eef4ff); color: var(--muted); }
.dimension-visual::before { content: ""; position: absolute; top: -13px; left: 0; right: 0; border-top: 1px solid #7899d2; }
.dimension-visual::after { content: ""; position: absolute; top: 0; bottom: 0; left: -13px; border-left: 1px solid #7899d2; }
.dimension-visual > strong { position: absolute; inset: 0; display: grid; place-content: center; color: var(--navy); font-size: .72rem; line-height: 1.45; text-align: center; }
.dimension-width { position: absolute; top: -25px; left: 50%; transform: translateX(-50%); padding: 0 6px; background: #fff; font-size: .7rem; font-weight: 700; white-space: nowrap; }
.dimension-height { position: absolute; left: -44px; top: 50%; width: 68px; transform: translate(-50%,-50%) rotate(-90deg); font-size: .7rem; font-weight: 700; text-align: center; white-space: nowrap; }
.placement-options { margin: 17px 0 0; padding: 0; display: grid; gap: 7px; border: 0; }
.placement-options legend { margin-bottom: 7px; color: var(--navy); font-size: .76rem; font-weight: 800; }
.placement-options label { min-height: 42px; display: flex; align-items: center; gap: 8px; padding: 8px 9px; border: 1px solid var(--line); border-radius: 8px; color: var(--muted); background: #fff; font-size: .72rem; font-weight: 700; cursor: pointer; }
.placement-options label:has(input:checked) { border-color: #9aabfb; color: var(--navy); background: #f2f4ff; }
.placement-options input { width: 17px; height: 17px; margin: 0; accent-color: var(--accent); }
.range-label { display: flex; justify-content: space-between; }
input[type="range"] { width: 100%; accent-color: var(--accent); }

.primary-button, .secondary-button { width: 100%; min-height: 48px; border-radius: 9px; font-weight: 750; }
.primary-button { border: 0; color: white; background: linear-gradient(135deg, var(--accent), var(--accent-2)); box-shadow: 0 8px 22px rgba(68, 76, 222, .2); }
.primary-button:disabled { opacity: .65; cursor: wait; }
.secondary-button { margin-top: 10px; border: 1px solid var(--accent); color: var(--accent); background: white; display: flex; align-items: center; justify-content: center; gap: 8px; }
.secondary-button:disabled { opacity: .4; cursor: not-allowed; }
.secondary-button svg { width: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.form-error { margin: 0 0 10px; padding: 10px; border-radius: 8px; color: var(--danger); background: #fff1f3; font-size: .8rem; line-height: 1.4; }

.canvas-panel { background: #fbfcff; }
.section-heading { min-height: 58px; display: flex; justify-content: space-between; gap: 18px; align-items: flex-start; margin-bottom: 18px; }
.section-heading h1, .section-heading h2 { margin: 0 0 5px; color: var(--navy); font-size: 1.45rem; line-height: 1.1; letter-spacing: -.025em; }
.section-heading p { margin: 0; color: var(--muted); font-size: .83rem; }
.catalog-state { padding: 7px 10px; border-radius: 7px; color: #22614e; background: #e9f8f2; font-size: .72rem; font-weight: 700; white-space: nowrap; }
.catalog-state.is-example { color: #82511a; background: #fff2d8; }
.preview-stage { min-height: clamp(360px,50vh,520px); border: 1px solid var(--line); border-radius: 12px; background: white; display: grid; place-items: center; overflow: hidden; position: relative; box-shadow: var(--shadow); }
.is-demo .canvas-panel .section-heading { display:none; }
.empty-state { display: grid; justify-items: center; gap: 9px; padding: 28px; color: var(--muted); text-align: center; }
.empty-state svg { width: 80px; fill: none; stroke: #9fb1d0; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.empty-state strong { color: var(--navy); }
.comparison { position: absolute; inset: 0; background: #edf1f8; }
.wall-surface { position: absolute; z-index: 0; overflow: hidden; border: 1px dashed #8fa7cf; border-radius: 6px; background-color: #fff; background-image: linear-gradient(45deg,#f3f5f9 25%,transparent 25%),linear-gradient(-45deg,#f3f5f9 25%,transparent 25%),linear-gradient(45deg,transparent 75%,#f3f5f9 75%),linear-gradient(-45deg,transparent 75%,#f3f5f9 75%); background-size: 18px 18px; background-position: 0 0,0 9px,9px -9px,-9px 0; }
.wall-surface span { position: absolute; right: 8px; bottom: 7px; padding: 4px 7px; border-radius: 6px; color: var(--muted); background: rgba(255,255,255,.88); font-size: .65rem; font-weight: 700; }
.comparison > img { position: absolute; z-index: 1; max-width:none; max-height:none; object-fit: contain; display: block; }
.segmented-layer { position: absolute; z-index: 2; background: transparent; }
.segmented-layer img { width: 100%; height: 100%; object-fit: contain; display: block; }
.comparison-range { position: absolute; z-index: 7; margin: 0; opacity: 0; cursor: ew-resize; }
.comparison-handle { position: absolute; z-index: 8; transform: translate(-50%, -50%); width: 44px; height: 44px; display: grid; place-items: center; border-radius: 50%; background: white; color: var(--navy); font-weight: 900; box-shadow: 0 6px 18px rgba(16, 41, 95, .2); pointer-events: none; }
.comparison-handle::before { content: ""; position: absolute; left: 50%; top: -260px; bottom: -260px; width: 2px; background: white; transform: translateX(-50%); z-index: -1; }
.preview-label { position: absolute; top: 14px; z-index: 9; padding: 7px 10px; border-radius: 7px; background: rgba(255,255,255,.92); color: var(--navy); font-size: .72rem; font-weight: 750; }
.original-label { left: 14px; }
.segmented-label { right: 14px; }
.comparison.is-loading { filter: saturate(.5); opacity: .5; }
.loading-state { position: absolute; z-index: 6; display: grid; justify-items: center; gap: 10px; color: var(--navy); }
.loading-state span { width: 36px; height: 36px; border: 3px solid #d9e0f3; border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
.loading-state strong { text-align: center; }
.loading-state small { max-width: 320px; color: var(--muted); font-size: .78rem; line-height: 1.4; text-align: center; }
@keyframes spin { to { transform: rotate(360deg); } }
.crop-overlay { position: absolute; inset: 0; z-index: 5; pointer-events: none; overflow: hidden; }
.crop-frame {
  position: absolute; pointer-events: auto; touch-action: none; cursor: grab; border: 3px solid #fff;
  border-radius: 5px; box-shadow: 0 0 0 9999px rgba(16, 41, 95, .46), 0 0 0 1px rgba(16, 41, 95, .55), 0 8px 22px rgba(0,0,0,.22);
}
.crop-frame.is-dragging { cursor: grabbing; }
.crop-frame span { position: absolute; left: 10px; top: 10px; padding: 6px 9px; border-radius: 7px; color: var(--navy); background: rgba(255,255,255,.94); font-size: .72rem; font-weight: 800; white-space: nowrap; }
.format-note { margin: 14px 0 0; padding: 12px 14px; border-radius: 9px; color: #584916; background: #fff7d9; font-size: .78rem; line-height: 1.45; }
.edit-crop-button { min-height: 44px; margin-top: 12px; padding: 8px 14px; border: 1px solid var(--accent); border-radius: 8px; color: var(--accent); background: #fff; font-weight: 750; }
.dimension-note { margin-top: 16px; padding: 15px; display: flex; gap: 12px; border: 1px solid #d6e2fb; border-radius: 10px; background: #f1f6ff; }
.dimension-note svg { width: 22px; min-width: 22px; fill: none; stroke: var(--accent); stroke-width: 1.8; stroke-linecap: round; }
.dimension-note strong { color: var(--navy); font-size: .84rem; }
.dimension-note p { margin: 4px 0 0; color: var(--muted); font-size: .78rem; line-height: 1.45; }

.results-empty { min-height: 420px; display: grid; place-items: center; padding: 30px; border: 1px dashed #cbd6e8; border-radius: 10px; color: var(--muted); text-align: center; line-height: 1.55; }
.color-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.color-row { display: grid; gap: 11px; padding: 12px; border: 1px solid var(--line); border-radius: 10px; background: #fff; }
.color-row small { display: block; margin-top: 3px; color: var(--muted); font-size: .68rem; line-height: 1.3; }
.product-link { display: block; color: var(--navy); font-size: .81rem; font-weight: 800; line-height: 1.25; text-decoration: none; overflow-wrap: break-word; hyphens: auto; }
.product-link:hover { color: var(--accent); text-decoration: underline; text-underline-offset: 2px; }
.color-row .stock-warning { color: var(--danger); font-weight: 700; }
.color-card-head { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 10px; align-items: center; }
.color-identity { display: flex; align-items: center; gap: 8px; }
.color-select { min-height: 44px; display: inline-flex; align-items: center; gap: 7px; padding: 7px 9px; border: 1px solid var(--line); border-radius: 8px; color: var(--navy); background: var(--soft); font-size: .68rem; font-weight: 750; cursor: pointer; }
.color-select input { width: 18px; height: 18px; margin: 0; accent-color: var(--accent); }
.product-visual { width: 60px; height: 60px; min-width: 60px; position: relative; display: grid; place-items: center; border: 1px solid var(--line); border-radius: 9px; overflow: hidden; background: #fff; }
.product-thumb { width: 100%; height: 100%; object-fit: contain; display: block; }
.swatch { width: 30px; height: 30px; min-width: 30px; border-radius: 7px; background: var(--swatch); box-shadow: inset 0 0 0 1px rgba(0,0,0,.07); }
.product-thumb + .swatch { width: 13px; height: 13px; min-width: 13px; position: absolute; right: 3px; bottom: 3px; border: 2px solid white; border-radius: 50%; box-shadow: 0 1px 4px rgba(0,0,0,.18); }
.color-metrics { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 6px; margin: 0; }
.color-metrics div { min-width: 0; padding: 7px; border-radius: 7px; background: var(--soft); }
.color-metrics dt { color: var(--muted); font-size: .58rem; font-weight: 700; line-height: 1.15; }
.color-metrics dd { margin: 4px 0 0; color: var(--navy); font-size: .68rem; font-weight: 800; line-height: 1.25; overflow-wrap: break-word; }
.summary { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 16px 0; }
.summary div { padding: 14px; border-radius: 9px; background: #eef5ff; }
.summary dt { color: var(--muted); font-size: .72rem; }
.summary dd { margin: 5px 0 0; color: var(--navy); font-size: 1.15rem; font-weight: 800; }
.result-note { margin: 0; padding: 13px; border-radius: 9px; color: #376555; background: #eaf8f2; font-size: .75rem; line-height: 1.45; }
.result-note span { color: var(--success); margin-right: 7px; }
.cart-button { width: 100%; min-height: 50px; margin-top: 12px; padding: 10px 16px; border: 0; border-radius: 9px; color: white; background: linear-gradient(135deg, var(--accent), var(--accent-2)); font-weight: 800; box-shadow: 0 8px 22px rgba(68, 76, 222, .2); }
.cart-button:disabled { opacity: .5; cursor: not-allowed; box-shadow: none; }
.cart-status { min-height: 1.2em; margin: 7px 0 0; color: var(--muted); font-size: .72rem; line-height: 1.4; }

@media (max-width: 960px) {
  .app-shell { grid-template-columns: 260px 1fr; }
  .results-panel { grid-column: 1 / -1; border-left: 0; border-top: 1px solid var(--line); }
  .results-empty { min-height: 160px; }
}

@media (min-width: 961px) {
  .app-shell { min-height: calc(100dvh - 68px); align-items: start; }
  .is-embedded .app-shell { min-height: 100dvh; }
  .workflow, .canvas-panel, .results-panel { height: auto; overflow: visible; }
  .canvas-panel { position: sticky; top: 68px; align-self: start; }
  .is-embedded .canvas-panel { top: 0; }
}

@media (max-width: 760px) {
  html, body { width: 100%; min-height: 100%; overflow-x: hidden; }
  .app-header { min-height: 60px; padding: 0 16px; grid-template-columns: auto 1fr auto; gap: 10px; }
  .brand { font-size: 1.15rem; }
  .privacy-state { font-size: .72rem; }
  .text-button { font-size: .78rem; padding-inline: 4px; }
  .header-actions a, .header-actions .text-button:not(#new-plan) { display: none; }
  .app-shell { display: block; width: 100%; min-height: calc(100dvh - 60px); }
  .workflow, .canvas-panel, .results-panel { width: 100%; min-height: calc(100dvh - 60px); padding: 22px 18px; border: 0; border-bottom: 1px solid var(--line); }
  .is-embedded .workflow, .is-embedded .canvas-panel, .is-embedded .results-panel { min-height: 100dvh; }
  .workflow { padding-bottom: 26px; }
  .step { padding-bottom: 20px; }
  .preview-stage { min-height: 360px; }
  .section-heading { display: grid; min-height: auto; }
  .catalog-state { width: fit-content; }
  .color-row { padding: 13px; }
  .color-card-head { align-items: start; }
  .color-select span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); }
  .color-select { min-width: 44px; justify-content: center; padding: 8px; }
  .color-metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .color-metrics div:last-child { grid-column: 1 / -1; }
  .dimension-visual { margin-left: 18px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
