/* ============ Layout Lab — design tokens ============ */
:root {
  --bg: #f3f5fa;
  --surface: #ffffff;
  --surface-2: #f8f9fc;
  --line: #e5e8f0;
  --line-2: #d6dbe7;
  --ink: #0d1324;
  --ink-2: #364055;
  --sub: #6a7286;
  --muted: #98a0b3;
  --pri: #4f46e5;
  --pri-2: #6366f1;
  --pri-ink: #ffffff;
  --pri-soft: #eef0ff;
  --amber: #f59e0b;
  --amber-soft: #fff7e6;
  --ok: #059669;
  --ok-soft: #ecfdf5;
  --bad: #e11d48;
  --bad-soft: #fff1f3;
  --rail-w: 252px;
  --top-h: 64px;
  --r: 12px;
  --r-sm: 8px;
  --sh-1: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .07);
  --sh-2: 0 10px 30px -12px rgba(16, 24, 40, .18), 0 2px 6px rgba(16, 24, 40, .05);
  --sh-3: 0 24px 60px -20px rgba(30, 27, 75, .35);
  font-family: 'IBM Plex Sans Thai', 'Leelawadee UI', Tahoma, sans-serif;
  font-size: 14px;
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); overflow: hidden; }
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
.ic { flex: none; }

/* ---------- controls ---------- */
button {
  cursor: pointer; border: 1px solid var(--line-2); background: #fff; border-radius: var(--r-sm); padding: 6px 11px;
  transition: background .15s, border-color .15s, box-shadow .15s, transform .05s; line-height: 1.3;
}
button:hover { background: var(--surface-2); border-color: #c3cad9; }
button:active { transform: translateY(1px); }
button.primary, .btn.primary { background: var(--pri); color: #fff; border-color: var(--pri); box-shadow: 0 1px 2px rgba(79,70,229,.3), inset 0 1px 0 rgba(255,255,255,.15); }
button.primary:hover, .btn.primary:hover { background: #4338ca; border-color: #4338ca; }
button.danger { color: var(--bad); }
button.danger:hover { background: var(--bad-soft); border-color: #fecdd3; }
button.link { border: 0; background: none; color: var(--pri); padding: 0; font-weight: 600; }
button.link:hover { text-decoration: underline; }
.btn { display: inline-flex; align-items: center; gap: 7px; border: 1px solid var(--line-2); background: #fff; border-radius: 10px; padding: 7px 13px; font-weight: 500; cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--surface-2); }
.btn.lg { padding: 10px 18px; font-size: 15px; border-radius: 12px; }
.btn.amber { background: var(--amber); border-color: var(--amber); color: #1f1300; font-weight: 600; }
.btn.amber:hover { background: #fbbf24; }
.icon-btn { width: 36px; height: 36px; padding: 0; display: inline-grid; place-items: center; border-radius: 10px; color: var(--ink-2); }
input, select, textarea { border: 1px solid var(--line-2); border-radius: var(--r-sm); padding: 6px 9px; background: #fff; min-width: 0; transition: border-color .15s, box-shadow .15s; }
input:hover, select:hover, textarea:hover { border-color: #c3cad9; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--pri-2); box-shadow: 0 0 0 3px rgba(99,102,241,.18); }
input[type=checkbox] { accent-color: var(--pri); width: 15px; height: 15px; }
input[type=range] { accent-color: var(--pri); padding: 0; border: 0; box-shadow: none; }
kbd { background: var(--surface-2); border: 1px solid var(--line-2); border-bottom-width: 2px; border-radius: 5px; padding: 0 6px; font-size: 12px; font-family: inherit; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: #cfd5e3; border-radius: 99px; border: 2px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-thumb:hover { background-color: #b5bdcf; }

/* ============ shell ============ */
#app { height: 100%; }
.shell { display: flex; height: 100%; }
.rail {
  width: var(--rail-w); flex: none; display: flex; flex-direction: column; gap: 2px; padding: 16px 12px;
  background: radial-gradient(120% 60% at 0% 0%, #2a2560 0%, rgba(42,37,96,0) 60%), linear-gradient(180deg, #16132f 0%, #100e24 100%);
  color: #b8bdd8; overflow-y: auto; z-index: 30;
}
.rail-brand { display: flex; align-items: center; gap: 11px; padding: 4px 8px 18px; color: #fff; }
.mark { width: 36px; height: 36px; border-radius: 10px; background: linear-gradient(135deg, #6366f1, #4f46e5); display: grid; align-content: center; gap: 3px; padding: 0 8px; box-shadow: 0 6px 16px -4px rgba(99,102,241,.6); flex: none; }
.mark i { display: block; height: 4px; border-radius: 2px; background: #fff; }
.mark i:nth-child(2) { width: 62%; background: #c7d2fe; }
.mark i:nth-child(3) { background: #fbbf24; }
.brand-t b { display: block; font-size: 16px; letter-spacing: .2px; }
.brand-t small { display: block; color: #8b90b3; font-size: 11px; }
.rail-label { font-size: 11px; font-weight: 600; letter-spacing: .6px; color: #6f7499; padding: 14px 12px 6px; text-transform: uppercase; }
.rail-link {
  display: flex; align-items: center; gap: 12px; height: 42px; padding: 0 12px; border-radius: 10px; color: #c2c6df;
  border: 0; background: transparent; font-weight: 500; text-align: left; width: 100%; position: relative; white-space: nowrap;
}
.rail-link:hover { background: rgba(255,255,255,.06); color: #fff; border: 0; }
.rail-link.on { background: linear-gradient(90deg, rgba(99,102,241,.38), rgba(99,102,241,.1)); color: #fff; }
.rail-link.on::before { content: ''; position: absolute; left: -12px; top: 9px; bottom: 9px; width: 3px; border-radius: 0 3px 3px 0; background: #a5b4fc; }
.rail-link.on .ic { color: #c7d2fe; }
.rail-proj { color: #fcd34d; }
.rail-proj:hover { background: rgba(245,158,11,.12); color: #fde68a; }
.rail-spacer { flex: 1; min-height: 16px; }
.rail-card { background: rgba(255,255,255,.05); border: 1px solid rgba(255,255,255,.08); border-radius: 12px; padding: 12px; }
.rc-label { font-size: 11px; color: #8b90b3; font-weight: 600; }
.rc-name { width: 100%; background: transparent; border: 1px solid transparent; color: #fff; font-weight: 600; font-size: 14px; padding: 3px 6px; margin: 2px -6px; }
.rc-name:hover { border-color: rgba(255,255,255,.15); }
.rc-name:focus { background: rgba(255,255,255,.08); border-color: #818cf8; box-shadow: none; }
.rc-meta { font-size: 12px; color: #a3a8c8; margin-top: 2px; }
.rc-save { display: flex; align-items: center; gap: 6px; margin-top: 8px; font-size: 11px; color: #8b90b3; }
.rc-save .dot { width: 7px; height: 7px; border-radius: 50%; background: #34d399; box-shadow: 0 0 0 3px rgba(52,211,153,.18); }

.shell-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  height: var(--top-h); flex: none; display: flex; align-items: center; gap: 14px; padding: 0 20px;
  background: rgba(255,255,255,.88); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); z-index: 20;
}
.rail-toggle { display: none; }
.crumb { display: flex; align-items: center; gap: 12px; min-width: 0; }
.crumb-ic { width: 40px; height: 40px; border-radius: 11px; background: var(--pri-soft); color: var(--pri); display: grid; place-items: center; flex: none; }
.crumb h1 { margin: 0; font-size: 17px; font-weight: 700; letter-spacing: .1px; white-space: nowrap; }
.crumb p { margin: 1px 0 0; font-size: 12.5px; color: var(--sub); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.crumb > div:last-child { min-width: 0; }
.top-slot { flex: 1; }
.top-status { display: flex; gap: 8px; }
.pill { display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 13px; border-radius: 99px; font-size: 13px; font-weight: 600; white-space: nowrap; border: 1px solid transparent; transition: filter .15s; }
.pill:hover { filter: brightness(.97); }
.pill.ok { background: var(--ok-soft); color: #047857; border-color: #c7f0dd; }
.pill.bad { background: var(--bad-soft); color: #be123c; border-color: #fecdd3; }
.pill.money { background: var(--pri-soft); color: #3730a3; border-color: #dfe2ff; font-variant-numeric: tabular-nums; }
.top-actions { display: flex; gap: 6px; align-items: center; padding-left: 8px; border-left: 1px solid var(--line); }
.dropdown { position: relative; }
.dropdown-menu {
  display: none; position: absolute; right: 0; top: calc(100% + 8px); width: 270px; background: #fff; border: 1px solid var(--line);
  border-radius: 14px; box-shadow: var(--sh-3); padding: 6px; z-index: 60;
}
.dropdown.open .dropdown-menu { display: block; animation: pop .14s ease-out; }
@keyframes pop { from { opacity: 0; transform: translateY(-4px) scale(.98); } }
.dropdown-menu button { display: flex; gap: 11px; align-items: center; width: 100%; border: 0; background: none; text-align: left; padding: 9px 10px; border-radius: 9px; color: var(--ink-2); }
.dropdown-menu button:hover { background: var(--surface-2); }
.dropdown-menu b { display: block; font-weight: 600; color: var(--ink); font-size: 13.5px; }
.dropdown-menu small { color: var(--sub); font-size: 12px; }
.dropdown-menu hr { border: 0; border-top: 1px solid var(--line); margin: 5px 4px; }

.page-body { flex: 1; min-height: 0; position: relative; overflow: auto; }
.offscreen { position: fixed; left: -20000px; top: 0; pointer-events: none; }

/* ============ workspace (2D / 3D / shelves / quote) ============ */
.workspace { position: absolute; inset: 0; display: grid; grid-template-columns: 264px minmax(0, 1fr) 320px; }
.workspace.no-left { grid-template-columns: minmax(0, 1fr) 320px; }
.side-panel { background: var(--surface); overflow-y: auto; padding: 16px; }
.palette { border-right: 1px solid var(--line); }
.props { border-left: 1px solid var(--line); }
.sp-head { margin: 4px 0 10px; }
.sp-head + .sp-head, .pal-list + .sp-head { margin-top: 20px; }
.sp-head h3 { margin: 0; font-size: 13.5px; font-weight: 700; }
.sp-head p { margin: 2px 0 0; color: var(--sub); font-size: 12px; }
.stage { position: relative; background: #edf0f7; min-width: 0; }
.stage.dark { background: #d9e0e8; }
.canvas-wrap { position: absolute; inset: 0; overflow: hidden; }
.canvas-wrap canvas { display: block; position: absolute; inset: 0; touch-action: none; }
.stage-foot { position: absolute; right: 12px; bottom: 10px; font-size: 12px; color: var(--sub); background: rgba(255,255,255,.85); padding: 3px 10px; border-radius: 99px; font-variant-numeric: tabular-nums; pointer-events: none; }
.stage-foot:empty { display: none; }

.float-tools {
  position: absolute; top: 14px; left: 14px; display: flex; gap: 4px; align-items: center; flex-wrap: wrap; max-width: calc(100% - 28px);
  background: rgba(255,255,255,.94); backdrop-filter: blur(8px); border: 1px solid var(--line); border-radius: 14px; padding: 5px; box-shadow: var(--sh-2);
}
.float-tools button { border-color: transparent; background: transparent; display: inline-flex; align-items: center; gap: 6px; padding: 6px 10px; border-radius: 9px; font-weight: 500; }
.float-tools button:hover { background: var(--surface-2); border-color: var(--line); }
.float-tools button.on { background: var(--pri); color: #fff; }
.float-tools .sep { width: 1px; height: 22px; background: var(--line); margin: 0 4px; }
.float-tools .chk { font-size: 12.5px; margin: 0 5px; display: flex; gap: 5px; align-items: center; cursor: pointer; color: var(--ink-2); }
.float-tools .rng { font-size: 12.5px; display: flex; align-items: center; gap: 6px; margin: 0 6px; color: var(--ink-2); }
.float-tools .rng input { width: 86px; }

/* palette */
.pal-list { display: flex; flex-direction: column; gap: 6px; }
.pal { display: flex; gap: 10px; align-items: center; padding: 8px 10px; border: 1px solid var(--line); border-radius: 11px; cursor: grab; background: #fff; user-select: none; transition: border-color .15s, box-shadow .15s, transform .15s; }
.pal:hover { border-color: #c7cdfd; box-shadow: 0 4px 14px -6px rgba(79,70,229,.35); transform: translateY(-1px); }
.pal:active { cursor: grabbing; }
.pal svg { width: 42px; height: 30px; flex: none; background: var(--surface-2); border-radius: 7px; padding: 2px; }
.pal b { display: block; font-size: 13px; font-weight: 600; }
.pal small { color: var(--sub); font-size: 11.5px; }
.legend { display: flex; flex-wrap: wrap; gap: 6px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--ink-2); background: var(--surface-2); border: 1px solid var(--line); border-radius: 99px; padding: 2px 9px 2px 6px; }
.legend i { width: 10px; height: 10px; border-radius: 3px; }

/* props / generic form */
.panel-h { display: flex; align-items: center; gap: 8px; margin: 18px 0 8px; }
.panel-h:first-child { margin-top: 0; }
.panel-h h3 { margin: 0; font-size: 13.5px; font-weight: 700; color: var(--ink); }
.panel-h .sub { color: var(--sub); font-size: 12px; }
.panel-h .link, .panel-h .tag { margin-left: auto; }
.hint { color: var(--sub); font-size: 12px; margin: 4px 0 8px; line-height: 1.55; }
.hint.pad { padding: 0 24px; }
.muted { color: var(--muted); }
.tips { margin: 0; padding-left: 18px; color: var(--ink-2); font-size: 12.5px; line-height: 1.85; }
.tag { display: inline-block; font-size: 11px; background: var(--pri-soft); color: var(--pri); border-radius: 99px; padding: 1px 9px; font-weight: 600; }
.form { display: flex; flex-direction: column; gap: 9px; }
.form label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--sub); font-weight: 500; min-width: 0; }
.form label > input:not([type=checkbox]), .form label > select, .form label > textarea { width: 100%; color: var(--ink); }
.form label small { color: var(--muted); font-weight: 400; }
.form label.chk, label.chk { flex-direction: row; align-items: center; gap: 7px; font-size: 12.5px; cursor: pointer; color: var(--ink-2); }
.form.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; }
.form.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 9px; }
.form .span2 { grid-column: span 2; }
.form + .form { margin-top: 9px; }
.form label.bad input { border-color: #fda4af; background: var(--bad-soft); color: var(--bad); font-weight: 700; }
.form .stack { display: flex; flex-direction: column; gap: 5px; justify-content: end; }
.btnrow { display: flex; gap: 6px; flex-wrap: wrap; margin: 10px 0; }
.btnrow button { font-size: 13px; }
.btnrow.small button { font-size: 12px; padding: 4px 9px; }
.btnrow.end { justify-content: flex-end; }
.kv { display: grid; grid-template-columns: 1fr auto; gap: 5px 10px; font-size: 13px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; margin: 6px 0; font-variant-numeric: tabular-nums; }
.kv span { color: var(--sub); }
.kv .tot { border-top: 1px dashed var(--line-2); padding-top: 6px; font-weight: 700; color: var(--ink); }
.kv b.tot { color: var(--pri); }
.side-row { border: 1px solid var(--line); border-radius: 12px; padding: 10px; margin-top: 10px; display: flex; flex-direction: column; gap: 7px; background: var(--surface-2); }
.side-h { display: flex; align-items: center; justify-content: space-between; font-size: 12.5px; }
.mini-elev { width: 100%; border-radius: 8px; cursor: pointer; border: 1px solid var(--line); background: #fff; transition: box-shadow .15s; }
.mini-elev:hover { box-shadow: 0 0 0 3px rgba(99,102,241,.25); }

/* ============ 3D ============ */
.v3d-canvas { display: block; }
.v3d-tip, .pl-tip { position: absolute; display: none; pointer-events: none; background: rgba(13,19,36,.94); color: #fff; padding: 9px 12px; border-radius: 10px; font-size: 12.5px; line-height: 1.55; z-index: 5; max-width: 270px; box-shadow: var(--sh-2); }
.v3d-tip small, .pl-tip small { color: #c3c8da; }
.v3d-tip span { color: #a5b4fc; }
.v3d-label { background: rgba(79,70,229,.95); color: #fff; font-size: 12px; padding: 3px 10px; border-radius: 99px; white-space: nowrap; font-family: inherit; box-shadow: 0 4px 12px -4px rgba(79,70,229,.6); }
.v3d-label.warn { background: rgba(225,29,72,.95); }
.walk-help { position: absolute; bottom: 16px; left: 50%; transform: translateX(-50%); background: rgba(13,19,36,.86); backdrop-filter: blur(6px); color: #e5e7f0; padding: 9px 16px; border-radius: 12px; font-size: 13px; display: none; white-space: nowrap; }
.walk-help.on { display: block; }
.walk-help kbd { background: #2b3350; border-color: #3c4566; color: #fff; }

/* ============ shelves (planogram) ============ */
.plano-ws { grid-template-columns: 250px minmax(0, 1fr) 350px; }
.plano-list { border-right: 1px solid var(--line); padding: 16px 12px; background: var(--surface); overflow-y: auto; }
.plano-list .list { display: flex; flex-direction: column; gap: 4px; }
.pl-item { display: flex; gap: 10px; align-items: center; padding: 8px 10px; border-radius: 10px; cursor: pointer; border: 1px solid transparent; transition: background .12s; }
.pl-item:hover { background: var(--surface-2); }
.pl-item.on { background: var(--pri-soft); border-color: #d6dafe; }
.pl-item.bad b::after { content: ' ⚠'; color: var(--bad); }
.pl-item .dot { width: 10px; height: 26px; border-radius: 4px; flex: none; }
.pl-item b { display: block; font-size: 13px; font-weight: 600; }
.pl-item small { color: var(--sub); font-size: 11.5px; }
.plano-main { min-width: 0; display: flex; flex-direction: column; background: #edf0f7; }
.plano-toolbar { display: flex; align-items: center; gap: 12px; padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--line); }
.plano-toolbar .chk { display: flex; align-items: center; gap: 6px; font-size: 12.5px; }
.plano-main .canvas-wrap { position: relative; flex: 1; }
.pl-title b { font-size: 14.5px; }
.pl-title span { color: var(--sub); font-size: 12.5px; margin-left: 8px; }
.sp { flex: 1; }
.plano-edit { border-left: 1px solid var(--line); padding: 16px; background: var(--surface); overflow-y: auto; }
.seg { display: flex; border: 1px solid var(--line-2); border-radius: 10px; overflow: hidden; margin-bottom: 12px; padding: 3px; gap: 3px; background: var(--surface-2); }
.seg button { flex: 1; border: 0; border-radius: 7px; font-size: 12.5px; background: transparent; }
.seg button.on { background: #fff; color: var(--pri); font-weight: 600; box-shadow: var(--sh-1); }
.usage { margin: 10px 0; }
.usage .bar { height: 8px; background: #e6e9f2; border-radius: 99px; overflow: hidden; }
.usage .bar i { display: block; height: 100%; background: linear-gradient(90deg, #34d399, #059669); border-radius: 99px; }
.usage .bar i.bad { background: var(--bad); }
.usage small { color: var(--sub); font-size: 12px; }
.levels { display: flex; flex-direction: column; gap: 6px; }
.lv { display: grid; grid-template-columns: 40px 36px 1fr auto; gap: 7px; align-items: center; border: 1px solid var(--line); border-radius: 11px; padding: 7px; transition: background .3s, border-color .3s; background: #fff; }
.lv:hover { border-color: var(--line-2); }
.lv.bad { border-color: #fda4af; background: var(--bad-soft); }
.lv.flash { background: var(--pri-soft); border-color: #a5b4fc; }
.lv-n { font-size: 11px; color: var(--sub); font-weight: 600; text-align: center; }
.lv img { width: 36px; height: 42px; object-fit: contain; }
.lv-body select { width: 100%; font-size: 12px; padding: 4px 5px; }
.lv-info { font-size: 11.5px; color: var(--ink-2); margin-top: 3px; }
.lv-info .r { color: var(--bad); }
.lv-extra { font-size: 11px; color: var(--sub); display: flex; align-items: center; gap: 4px; margin-top: 3px; }
.lv-extra input { width: 54px; padding: 1px 5px; font-size: 11px; }
.lv-btns { display: flex; flex-direction: column; gap: 2px; }
.lv-btns button { padding: 0 7px; font-size: 12px; line-height: 19px; border-radius: 6px; }
.add-lv { display: flex; gap: 6px; margin-top: 12px; }
.add-lv select { flex: 1; font-size: 12px; }

/* ============ products ============ */
.library-ws { min-height: 100%; }
.lib-toolbar { display: flex; gap: 10px; align-items: center; padding: 14px 24px; background: rgba(255,255,255,.92); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 2; }
.lib-toolbar input[type=search] { width: 280px; padding: 8px 12px; border-radius: 10px; }
.lib-toolbar select { padding: 8px 10px; border-radius: 10px; }
.lib-toolbar .primary { padding: 8px 16px; border-radius: 10px; font-weight: 600; }
.library-ws > .hint.pad { margin: 14px 0 6px; }
.lib-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 16px; padding: 6px 24px 32px; }
.pcard { background: #fff; border: 1px solid var(--line); border-radius: 16px; overflow: hidden; display: flex; flex-direction: column; box-shadow: var(--sh-1); transition: box-shadow .2s, transform .2s; }
.pcard:hover { box-shadow: var(--sh-2); transform: translateY(-2px); }
.pimg { height: 160px; display: flex; align-items: center; justify-content: center; background: radial-gradient(circle at 50% 70%, #ffffff 0%, #f1f3f9 75%); position: relative; padding: 14px; border-bottom: 1px solid var(--line); }
.pimg img { max-height: 132px; max-width: 100%; object-fit: contain; filter: drop-shadow(0 6px 8px rgba(13,19,36,.18)); }
.badge { position: absolute; top: 10px; left: 10px; font-size: 11px; padding: 2px 9px; border-radius: 99px; font-weight: 700; }
.badge.real { background: var(--ok); color: #fff; }
.pbody { padding: 12px; display: flex; flex-direction: column; gap: 7px; }
.pcat { font-size: 11px; font-weight: 700; letter-spacing: .2px; }
.pname { font-weight: 600; font-size: 14px; line-height: 1.35; }
.pname small { color: var(--sub); font-weight: 400; }
.dims { display: grid; grid-template-columns: repeat(3, 1fr); gap: 5px; }
.dims label { display: flex; align-items: center; gap: 3px; font-size: 11px; color: var(--sub); }
.dims input { width: 100%; padding: 3px 5px; font-size: 12px; }
.pmeta { font-size: 11.5px; color: var(--sub); }
.pbtns { display: flex; gap: 5px; flex-wrap: wrap; }
.pbtns button { font-size: 12px; padding: 4px 9px; }
dialog { border: 0; border-radius: 18px; padding: 0; box-shadow: var(--sh-3); }
dialog::backdrop { background: rgba(13,19,36,.5); backdrop-filter: blur(2px); }
.dlg { padding: 22px; width: 500px; max-width: 92vw; }
.dlg h3 { margin: 0 0 14px; font-size: 18px; }

/* ============ quote ============ */
.quote-ws { grid-template-columns: 350px minmax(0, 1fr); }
.q-form { border-right: 1px solid var(--line); padding: 16px; background: var(--surface); overflow-y: auto; }
.q-preview { overflow: auto; padding: 20px 28px 48px; background: #e7eaf2; }
.q-actions { display: flex; gap: 8px; justify-content: flex-end; max-width: 210mm; margin: 0 auto 14px; }
.compare { display: flex; flex-direction: column; gap: 7px; }
.cmp { display: flex; gap: 10px; justify-content: space-between; border: 1px solid var(--line); border-radius: 11px; padding: 10px; font-size: 12.5px; background: var(--surface-2); }
.cmp small { display: block; color: var(--sub); font-size: 11px; line-height: 1.45; }
.cmp-r { text-align: right; display: flex; flex-direction: column; align-items: flex-end; gap: 3px; white-space: nowrap; }
.cmp-r small.g { color: var(--ok); font-weight: 700; }
.cmp-r small.r { color: var(--bad); font-weight: 700; }
.cmp-r button { font-size: 11px; padding: 2px 9px; }
.page { background: #fff; width: 210mm; min-height: 297mm; margin: 0 auto 18px; padding: 14mm; box-shadow: 0 12px 40px -16px rgba(13,19,36,.3); font-size: 12.5px; color: #111827; border-radius: 4px; }
.q-head { display: flex; justify-content: space-between; gap: 20px; border-bottom: 3px solid #312e81; padding-bottom: 10px; }
.q-head h1 { font-size: 18px; margin: 0 0 4px; color: #312e81; }
.q-head .small { font-size: 11.5px; color: #475569; line-height: 1.5; }
.q-title { text-align: right; }
.q-title h2 { margin: 0; font-size: 22px; color: #312e81; }
.q-title > div { color: #64748b; letter-spacing: 2px; font-size: 11px; margin-bottom: 6px; }
.q-title table { margin-left: auto; font-size: 12px; border-collapse: collapse; }
.q-title td { padding: 1px 0 1px 12px; }
.q-title td:first-child { color: #64748b; }
.q-cust { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 12px 0; }
.q-cust > div { border: 1px solid #e5e7eb; border-radius: 8px; padding: 8px 10px; line-height: 1.6; }
.q-cust span { display: block; font-size: 11px; color: #64748b; }
.q-cust b { font-size: 14px; }
.q-items { width: 100%; border-collapse: collapse; margin-top: 6px; }
.q-items th { background: #312e81; color: #fff; font-weight: 600; padding: 6px; font-size: 12px; }
.q-items td { border-bottom: 1px solid #e5e7eb; padding: 6px; vertical-align: top; }
.q-items td.r { text-align: right; white-space: nowrap; }
.q-items td.c { text-align: center; }
.q-items .d { color: #64748b; font-size: 11.5px; }
.linespec { font-size: 11px; padding: 1px 4px; margin-top: 3px; }
.q-sum { display: flex; justify-content: space-between; gap: 20px; margin-top: 10px; align-items: flex-start; }
.q-words { background: #f1f5f9; padding: 8px 10px; border-radius: 6px; font-weight: 600; flex: 1; }
.q-sum table { border-collapse: collapse; min-width: 260px; }
.q-sum td { padding: 4px 8px; }
.q-sum td:last-child { text-align: right; }
.q-sum .grand td { background: #312e81; color: #fff; font-weight: 700; font-size: 14px; }
.q-notes { margin-top: 16px; font-size: 12px; line-height: 1.7; color: #374151; }
.q-sign { display: grid; grid-template-columns: 1fr 1fr; gap: 40px; margin-top: 40px; text-align: center; font-size: 12px; }
.q-sign .ln { border-bottom: 1px dotted #111; height: 40px; margin-bottom: 6px; }
.pg-h { color: #312e81; margin: 0 0 8px; font-size: 15px; }
.q-img { width: 100%; border: 1px solid #e5e7eb; border-radius: 6px; margin-bottom: 14px; }

/* ============ home ============ */
.home { max-width: 1320px; margin: 0 auto; padding: 24px 28px 40px; display: flex; flex-direction: column; gap: 20px; }
.hero {
  display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.05fr); gap: 28px; align-items: center; padding: 28px; border-radius: 22px; color: #fff;
  background: radial-gradient(80% 120% at 100% 0%, rgba(129,140,248,.45) 0%, rgba(129,140,248,0) 55%), radial-gradient(60% 80% at 0% 100%, rgba(245,158,11,.22) 0%, rgba(245,158,11,0) 60%), linear-gradient(135deg, #1e1b4b 0%, #312e81 55%, #3730a3 100%);
  box-shadow: var(--sh-3); overflow: hidden;
}
.eyebrow { display: inline-block; font-size: 12px; font-weight: 600; letter-spacing: .4px; color: #c7d2fe; background: rgba(255,255,255,.1); border: 1px solid rgba(255,255,255,.15); padding: 3px 11px; border-radius: 99px; }
.hero h2 { margin: 12px 0 6px; font-size: 30px; line-height: 1.25; font-weight: 700; }
.hero p { margin: 0 0 22px; color: #d5d8f5; font-size: 14.5px; }
.hero-actions { display: flex; flex-wrap: wrap; gap: 10px; }
.hero .btn:not(.primary):not(.amber) { background: rgba(255,255,255,.1); border-color: rgba(255,255,255,.22); color: #fff; }
.hero .btn:not(.primary):not(.amber):hover { background: rgba(255,255,255,.18); }
.hero .btn.primary { background: #fff; color: #312e81; border-color: #fff; }
.hero .btn.primary:hover { background: #eef0ff; }
.hero-plan { display: block; background: #fff; border-radius: 16px; padding: 10px; box-shadow: 0 20px 50px -20px rgba(0,0,0,.6); transform: perspective(1200px) rotateY(-6deg) rotateX(3deg); transition: transform .4s; }
.hero-plan:hover { transform: perspective(1200px) rotateY(0) rotateX(0); }
.hero-plan img { display: block; width: 100%; border-radius: 10px; }
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; }
.kpi { display: flex; gap: 14px; align-items: flex-start; background: #fff; border: 1px solid var(--line); border-radius: 16px; padding: 18px; box-shadow: var(--sh-1); }
.k-ic { width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center; background: var(--surface-2); color: var(--ink-2); flex: none; }
.kpi small { display: block; color: var(--sub); font-size: 12.5px; font-weight: 500; }
.kpi b { display: block; font-size: 22px; font-weight: 700; margin: 2px 0; font-variant-numeric: tabular-nums; }
.kpi span:last-child { font-size: 12px; color: var(--muted); }
.kpi.ok .k-ic { background: var(--ok-soft); color: var(--ok); }
.kpi.ok b { color: var(--ok); }
.kpi.bad .k-ic { background: var(--bad-soft); color: var(--bad); }
.kpi.bad b { color: var(--bad); }
.kpi.pri .k-ic { background: var(--pri-soft); color: var(--pri); }
.home-grid { display: grid; grid-template-columns: minmax(0, 1.45fr) minmax(0, 1fr); gap: 20px; }
.card { background: #fff; border: 1px solid var(--line); border-radius: 18px; padding: 20px; box-shadow: var(--sh-1); }
.card-h { display: flex; flex-direction: column; gap: 2px; margin-bottom: 14px; }
.card-h + * + .card-h, .cats + .card-h { margin-top: 20px; }
.card-h h3 { margin: 0; font-size: 15.5px; }
.card-h span { color: var(--sub); font-size: 12.5px; }
.modules { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.module { display: flex; gap: 12px; align-items: center; padding: 14px; border: 1px solid var(--line); border-radius: 14px; transition: border-color .15s, box-shadow .15s, transform .15s; }
.module:hover { border-color: #c7cdfd; box-shadow: 0 10px 24px -14px rgba(79,70,229,.5); transform: translateY(-2px); }
.m-ic { width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center; background: var(--pri-soft); color: var(--pri); flex: none; }
.m-t { flex: 1; min-width: 0; }
.m-t b { display: block; font-size: 14px; }
.m-t small { display: block; color: var(--sub); font-size: 12px; line-height: 1.4; }
.m-t code { font-size: 11px; color: var(--muted); }
.m-go { color: var(--muted); transition: color .15s, transform .15s; }
.module:hover .m-go { color: var(--pri); transform: translateX(3px); }
.cats { display: flex; flex-direction: column; gap: 9px; }
.cat-row { display: grid; grid-template-columns: 12px 140px 1fr 48px; gap: 10px; align-items: center; font-size: 13px; }
.cdot { width: 12px; height: 12px; border-radius: 4px; }
.cname { color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cbar { height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.cbar i { display: block; height: 100%; border-radius: 99px; opacity: .85; }
.cat-row b { text-align: right; font-variant-numeric: tabular-nums; }
.specs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.spec-chip { border: 1px solid var(--line); border-radius: 12px; padding: 10px; text-align: center; color: var(--muted); }
.spec-chip b { display: block; font-size: 20px; }
.spec-chip span { font-size: 12px; }
.spec-chip.on { border-color: #d6dafe; background: var(--pri-soft); color: var(--pri); }
.steps { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 12px; counter-reset: s; }
.steps li { counter-increment: s; position: relative; padding: 46px 14px 14px; border-radius: 14px; background: var(--surface-2); border: 1px solid var(--line); }
.steps li::before { content: counter(s); position: absolute; top: 12px; left: 14px; width: 26px; height: 26px; border-radius: 8px; background: var(--pri); color: #fff; font-weight: 700; display: grid; place-items: center; font-size: 13px; }
.steps b { display: block; font-size: 14px; margin-bottom: 4px; }
.steps span { color: var(--sub); font-size: 12.5px; line-height: 1.5; }

/* ============ toast ============ */
#toasts { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 100; align-items: center; }
.toast { background: #0d1324; color: #fff; padding: 10px 18px; border-radius: 12px; font-size: 13px; box-shadow: var(--sh-3); transition: opacity .4s, transform .4s; }
.toast.error { background: var(--bad); }
.toast.warn { background: #b45309; }
.toast.out { opacity: 0; transform: translateY(8px); }

/* ============ projector ============ */
body.projector { background: #000; }
.pj-stage { position: fixed; inset: 0; background: #000; }
.pj-layer { position: absolute; inset: 0; }
.pj-layer canvas { position: absolute; inset: 0; }
.pj-bar { position: fixed; left: 50%; transform: translateX(-50%); bottom: 16px; width: max-content; max-width: calc(100% - 32px); display: flex; gap: 12px; align-items: center; background: rgba(16,14,36,.9); backdrop-filter: blur(10px); color: #e5e7f0; padding: 8px 12px; border-radius: 16px; border: 1px solid rgba(255,255,255,.1); font-size: 13px; transition: opacity .4s; flex-wrap: wrap; z-index: 10; box-shadow: 0 20px 50px -20px rgba(0,0,0,.8); }
.pj-bar.hidden, body.idle .pj-bar { opacity: 0; pointer-events: none; }
body.idle, body.idle * { cursor: none !important; }
.pj-bar .seg { margin: 0; border-color: rgba(255,255,255,.12); background: rgba(255,255,255,.05); }
.pj-bar .seg button { background: transparent; color: #c2c6df; padding: 6px 12px; }
.pj-bar .seg button.on { background: var(--pri); color: #fff; box-shadow: none; }
.pj-bar button { background: rgba(255,255,255,.06); color: #e5e7f0; border-color: rgba(255,255,255,.12); }
.pj-bar button.primary { background: var(--amber); border-color: var(--amber); color: #1f1300; font-weight: 600; }
.pj-bar input { background: rgba(255,255,255,.06); color: #fff; border-color: rgba(255,255,255,.15); }
.pj-bar .sp { display: none; }
.pj-cal { display: flex; align-items: center; gap: 5px; }
.pj-cal b { min-width: 42px; text-align: center; font-variant-numeric: tabular-nums; }
.pj-help { color: #8b90b3; font-size: 12px; }
.pj-wait { position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); color: #8b90b3; font-size: 18px; }

/* ============ responsive ============ */
@media (max-width: 1280px) {
  :root { --rail-w: 76px; }
  .rail { padding: 16px 10px; align-items: center; }
  .rail-brand { padding: 4px 0 16px; }
  .brand-t, .rail-label, .rail-card, .rail-link span { display: none; }
  .rail-link { width: 50px; justify-content: center; padding: 0; }
  .rail-link.on::before { left: -10px; }
  .rail-label { display: block; font-size: 0; height: 12px; padding: 0; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .steps { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .crumb p { display: none; }
}
@media (max-width: 1080px) {
  .workspace { grid-template-columns: 220px minmax(0, 1fr) 290px; }
  .plano-ws { grid-template-columns: 200px minmax(0, 1fr) 310px; }
  .hero, .home-grid { grid-template-columns: 1fr; }
  .hero-plan { transform: none; }
}
@media (max-width: 820px) {
  .rail { position: fixed; inset: 0 auto 0 0; transform: translateX(-100%); transition: transform .25s; width: 252px; align-items: stretch; }
  .rail .brand-t, .rail .rail-label, .rail .rail-card, .rail .rail-link span { display: initial; }
  .rail .rail-link { width: 100%; justify-content: flex-start; padding: 0 12px; }
  body.rail-open .rail { transform: none; box-shadow: var(--sh-3); }
  .rail-toggle { display: inline-grid; }
  .top-status .pill.money { display: none; }
  .workspace, .workspace.no-left, .plano-ws, .quote-ws { position: static; display: flex; flex-direction: column; min-height: 100%; }
  .stage, .plano-main { min-height: 60vh; order: -1; }
  .q-preview { order: -1; }
  .side-panel, .plano-list, .plano-edit, .q-form { border: 0; border-top: 1px solid var(--line); }
  .kpis, .modules, .steps { grid-template-columns: 1fr; }
  .home { padding: 16px; }
}

@media (max-width: 560px) {
  .top-status { display: none; }
  .topbar { gap: 8px; padding: 0 12px; }
  .top-actions .btn span { display: none; }
}

/* ============ print (ใบเสนอราคา) ============ */
@page { size: A4; margin: 0; }
@media print {
  html, body { overflow: visible !important; height: auto !important; background: #fff !important; }
  body.printing-quote .rail, body.printing-quote .topbar, body.printing-quote .q-form, body.printing-quote .q-actions,
  body.printing-quote .noprint, body.printing-quote .offscreen, body.printing-quote #toasts { display: none !important; }
  body.printing-quote #app, body.printing-quote .shell, body.printing-quote .shell-main, body.printing-quote .page-body,
  body.printing-quote .workspace, body.printing-quote .q-preview { display: block !important; position: static !important; overflow: visible !important; height: auto !important; padding: 0 !important; background: #fff !important; }
  body.printing-quote .page { box-shadow: none; margin: 0; border-radius: 0; page-break-after: always; break-after: page; }
  body.printing-quote .page:last-child { page-break-after: auto; }
}
