:root {
  --bg: #f4f6f9; --card: #ffffff; --text: #1d2433; --muted: #6b7486; --line: #dde2ea;
  --accent: #2f6fed; --accent-ink: #fff; --danger: #c8333f; --ok: #1f8a4c; --warn: #b7791f;
  --plan-bg: #fbfcfe; --grid: #e9edf3; --room: rgba(47,111,237,.06); --room-sel: rgba(47,111,237,.14); --wall: #3b4252;
  --code-bg: #0f1522; --code-ink: #d8e1f0;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f131a; --card: #171c25; --text: #e6e9ef; --muted: #98a1b3; --line: #2a3140;
    --accent: #5b8cff; --plan-bg: #121721; --grid: #1d2430; --room: rgba(91,140,255,.08); --room-sel: rgba(91,140,255,.2); --wall: #c8cfdc;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--accent); }
h1 { font-size: 1.5rem; margin: .2em 0 .6em; }
h2 { font-size: 1.1rem; margin: .2em 0; }
.muted { color: var(--muted); } .small { font-size: .82rem; } .right { text-align: right; }
.row { display: flex; align-items: center; flex-wrap: wrap; } .between { justify-content: space-between; }
.gap { gap: .6rem; margin: .4rem 0; } .gap4 { gap: .4rem; }
.inline { display: inline; margin: 0; }
input, select, textarea { width: 100%; padding: .5rem .6rem; border: 1px solid var(--line); border-radius: 8px; background: var(--card); color: var(--text); font: inherit; }
textarea { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .85rem; }
label { display: block; font-size: .85rem; color: var(--muted); margin: .4rem 0; }
label input, label select, label textarea { margin-top: .2rem; color: var(--text); }
label.file input { border: 0; padding: .3rem 0; }
.btn { display: inline-block; padding: .5rem .9rem; border-radius: 8px; border: 1px solid var(--line); background: var(--card); color: var(--text); text-decoration: none; cursor: pointer; font: inherit; font-size: .9rem; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { color: var(--danger); }
.btn.small { padding: .3rem .6rem; font-size: .8rem; }
.btn.wide { width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
button.link { background: none; border: 0; color: var(--muted); cursor: pointer; font: inherit; }
kbd { font-size: .7rem; opacity: .7; }
hr { border: 0; border-top: 1px solid var(--line); margin: 1rem 0; }
pre { white-space: pre-wrap; }

.top { display: flex; justify-content: space-between; align-items: center; padding: .6rem 1rem; background: var(--card); border-bottom: 1px solid var(--line); gap: 1rem; }
.top nav { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.brand { font-weight: 700; color: var(--text); text-decoration: none; white-space: nowrap; }
.logo { display: inline-grid; place-items: center; width: 1.6em; height: 1.6em; background: var(--accent); color: #fff; border-radius: 6px; }
.flashes { padding: .5rem 1rem 0; }
.flash { padding: .55rem .8rem; border-radius: 8px; margin: .3rem 0; background: var(--card); border: 1px solid var(--line); }
.flash.error { border-color: var(--danger); color: var(--danger); }
.flash.warn { border-color: var(--warn); color: var(--warn); }
.flash.ok { border-color: var(--ok); color: var(--ok); }

.page { max-width: 1100px; margin: 0 auto; padding: 1rem; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 1rem 1.2rem; }
.card.narrow { max-width: 380px; margin: 3rem auto; }
.card.empty { text-align: center; padding: 2.5rem; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 1rem; }
.form-grid .span2 { grid-column: span 2; }
@media (max-width: 700px) { .form-grid { grid-template-columns: 1fr; } .form-grid .span2 { grid-column: auto; } }
.grid-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 1rem; }
.project { color: var(--text); text-decoration: none; display: flex; flex-direction: column; gap: .35rem; }
.project:hover { border-color: var(--accent); }
.stats { display: flex; gap: 1rem; flex-wrap: wrap; font-size: .9rem; }
.stats.big { font-size: 1rem; margin-bottom: .6rem; }
.pill { display: inline-block; padding: .1rem .55rem; border-radius: 99px; font-size: .75rem; background: var(--grid); color: var(--text); white-space: nowrap; }
.s-approved, .s-done { background: #d5f2e0; color: #145c33; }
.s-changes-requested { background: #ffe9c7; color: #8a5300; }
.s-quote-sent { background: #dce8ff; color: #1f4fb3; }
.s-installing { background: #ece0ff; color: #5a2ca0; }
.tabs-inline a { margin-left: .8rem; text-decoration: none; color: var(--muted); }
.tabs-inline a.on { color: var(--text); font-weight: 600; }

/* ---- editor ---- */
.editor-page main { height: calc(100vh - 52px); }
.editor-page .flashes { position: fixed; top: 56px; left: 50%; transform: translateX(-50%); z-index: 20; max-width: 90vw; }
.editor { display: grid; grid-template-columns: 220px 1fr 340px; height: 100%; min-height: 0; }
.tools, .panels { background: var(--card); overflow-y: auto; min-height: 0; }
.tools { border-right: 1px solid var(--line); padding: .7rem; }
.panels { border-left: 1px solid var(--line); display: flex; flex-direction: column; }
.proj { margin-bottom: .6rem; }
.toolgroup { margin: .7rem 0; }
.toolgroup .label, .label { font-size: .72rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin-bottom: .35rem; font-weight: 600; }
.tool { display: flex; align-items: center; gap: .4rem; width: 100%; text-align: left; padding: .35rem .5rem; margin: 2px 0; border: 1px solid transparent; border-radius: 7px; background: none; color: var(--text); cursor: pointer; font: inherit; font-size: .85rem; }
.tool:hover { background: var(--grid); }
.tool.on { border-color: var(--accent); background: var(--room-sel); }
.tool:disabled { opacity: .4; }
.tool i { width: 12px; height: 12px; border-radius: 3px; flex: none; }
.palette { display: grid; grid-template-columns: 1fr; }
.save { position: sticky; bottom: 0; background: var(--card); padding-top: .4rem; border-top: 1px solid var(--line); }
.stage { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.viewbar { display: flex; gap: .6rem; align-items: center; padding: .45rem .6rem; border-bottom: 1px solid var(--line); background: var(--card); flex-wrap: wrap; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; background: var(--card); color: var(--text); padding: .3rem .65rem; cursor: pointer; font: inherit; font-size: .82rem; border-right: 1px solid var(--line); }
.seg button:last-child { border-right: 0; }
.seg button.on { background: var(--accent); color: var(--accent-ink); }
.planctl { display: flex; align-items: center; gap: .3rem; margin: 0; }
.planctl input { width: auto; margin: 0; }
.planctl .btn.on { border-color: var(--accent); background: var(--room-sel); }
.views { flex: 1; display: grid; min-height: 0; }
.views.v-split { grid-template-columns: 1fr 1fr; }
.views.v-plan .view3d, .views.v-3d .view2d { display: none; }
.view2d, .view3d { position: relative; min-height: 0; min-width: 0; overflow: hidden; }
.view2d { border-right: 1px solid var(--line); }
#plan { display: block; touch-action: none; }
#three { position: absolute; inset: 0; }
#three canvas { display: block; }
.hint { position: absolute; left: .6rem; bottom: .5rem; background: var(--card); padding: .2rem .5rem; border-radius: 6px; border: 1px solid var(--line); color: var(--muted); pointer-events: none; }
.ptabs { display: flex; flex-wrap: wrap; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--card); z-index: 2; }
.ptabs button { flex: 1; border: 0; background: none; padding: .55rem .3rem; cursor: pointer; color: var(--muted); font: inherit; font-size: .8rem; border-bottom: 2px solid transparent; }
.ptabs button.on { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }
.panel { display: none; padding: .8rem; }
.panel.on { display: block; }
.stack > * { margin-bottom: .3rem; }
table.inv { width: 100%; border-collapse: collapse; font-size: .85rem; margin-bottom: .6rem; }
table.inv th, table.inv td { padding: .4rem .3rem; border-bottom: 1px solid var(--line); vertical-align: top; text-align: left; }
table.inv .num { text-align: right; white-space: nowrap; }
table.inv .sub td { font-weight: 600; background: var(--bg); }
table.inv .grand td { font-weight: 700; font-size: 1rem; border-bottom: 2px solid var(--text); }
.code { background: var(--code-bg); color: var(--code-ink); padding: .7rem; border-radius: 8px; font: .75rem/1.45 ui-monospace, SFMono-Regular, Menlo, monospace; max-height: calc(100vh - 230px); overflow: auto; white-space: pre; }
.yamltabs { margin-bottom: .4rem; flex-wrap: wrap; }
.history { list-style: none; padding: 0; margin: 0; }
.history li { display: flex; justify-content: space-between; gap: .5rem; padding: .5rem 0; border-bottom: 1px solid var(--line); align-items: center; }
.history form { margin: 0; }
#propsBody label { margin: .25rem 0; }

.mode-customer .tools .proj::after { content: "Customer preview – move or add devices, then send your changes"; display: block; font-size: .78rem; color: var(--muted); margin-top: .4rem; }

@media (max-width: 1100px) {
  .editor { grid-template-columns: 190px 1fr; grid-template-rows: 1fr auto; }
  .panels { grid-column: span 2; border-left: 0; border-top: 1px solid var(--line); max-height: 40vh; }
}
@media (max-width: 700px) {
  .editor-page main { height: auto; }
  .editor { display: flex; flex-direction: column; }
  .tools { border-right: 0; border-bottom: 1px solid var(--line); }
  .palette { grid-template-columns: 1fr 1fr; }
  .stage { height: 70vh; }
  .views.v-split { grid-template-columns: 1fr; grid-template-rows: 1fr 1fr; }
  .stage { order: -1; }
  .panels { max-height: none; }
  .save { position: static; }
}

/* ---- quote ---- */
.quote-page { background: #eee; color: #1d2433; }
.quote { max-width: 820px; margin: 1.5rem auto; background: #fff; padding: 2rem 2.4rem; border-radius: 8px; }
.quote .muted { color: #6b7486; }
.quote table.inv td, .quote table.inv th { border-color: #dde2ea; }
.quote table.inv .sub td { background: #f4f6f9; }
@media print { .noprint { display: none; } .quote-page { background: #fff; } .quote { margin: 0; padding: 0; } }
.notes { padding-left: 1.1rem; } .notes li { margin: .3rem 0; }
.rooms { list-style: none; padding: 0; } .rooms li { padding: .35rem 0; border-bottom: 1px solid var(--line); }
#panel-review h3 { margin: .2rem 0 .4rem; }
.areas { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; }
.areas .btn { text-align: left; padding: .3rem .4rem; }
.floorbar { padding: .35rem .6rem; }
.allfloors { display: flex; align-items: center; gap: .3rem; margin: 0 0 0 auto; }
.allfloors input { width: auto; margin: 0; }
.checks { list-style: none; padding: 0; margin: 0; }
.checks li { padding: .45rem .5rem; border-left: 3px solid var(--line); margin: .3rem 0; background: var(--bg); border-radius: 0 6px 6px 0; cursor: pointer; font-size: .85rem; }
.checks li.warn { border-left-color: var(--warn); }
.checks li.info { border-left-color: var(--accent); }
.checks li:hover { outline: 1px solid var(--line); }
#checkCount:not(:empty) { background: var(--warn); color: #fff; border-radius: 99px; padding: 0 .4em; font-size: .75em; }
label.check { display: flex; gap: .4rem; align-items: center; }
label.check input { width: auto; margin: 0; }
.flash { position: relative; padding-right: 2rem; }
.flash .x { position: absolute; right: .4rem; top: .35rem; border: 0; background: none; color: inherit; cursor: pointer; font-size: .9rem; opacity: .7; }
.editor-page .flashes { width: min(760px, 92vw); max-height: 40vh; overflow-y: auto; box-shadow: 0 8px 24px rgba(0,0,0,.18); border-radius: 10px; }
.editor-page .flash { margin: 0 0 4px; font-size: .85rem; background: var(--card); }

.read-only .save .btn, .read-only #panel-requirements form, .read-only #panel-details form, .read-only #addArea { display: none; }
a.link { color: var(--muted); text-decoration: none; }

table.prices td input { margin: 0; }
