:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f8f9fb;
  --ink: #0c1122;
  --ink-2: #4a5164;
  --ink-3: #8a90a0;
  --line: #e3e6ec;
  --accent: #0c1122;
  --accent-ink: #ffffff;
  --focus: #3b6cf6;
  --danger: #c4261d;
  --ok: #1d8a4e;
  --warn: #b26a00;
  --stage: #e9ebf0;
  --radius: 10px;
  --shadow: 0 8px 28px rgba(12, 17, 34, 0.12);
  --aside: clamp(180px, 22vw, 300px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d1018;
    --surface: #151a25;
    --surface-2: #1b2130;
    --ink: #eef0f5;
    --ink-2: #b4bacb;
    --ink-3: #7c8396;
    --line: #2a3142;
    --accent: #eef0f5;
    --accent-ink: #0c1122;
    --stage: #0a0d14;
    --danger: #ff6b5f;
    --ok: #4fd18b;
    --warn: #f3b04a;
    --shadow: 0 8px 28px rgba(0, 0, 0, 0.5);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0d1018; --surface: #151a25; --surface-2: #1b2130; --ink: #eef0f5; --ink-2: #b4bacb; --ink-3: #7c8396;
  --line: #2a3142; --accent: #eef0f5; --accent-ink: #0c1122; --stage: #0a0d14; --danger: #ff6b5f; color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--ink); font: 14px/1.45 "Be Vietnam Pro", system-ui, sans-serif; }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }

.boot { display: grid; place-items: center; height: 100%; color: var(--ink-3); letter-spacing: 0.08em; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; letter-spacing: 0.04em; }
.mark { display: inline-grid; place-items: center; width: 28px; height: 28px; border-radius: 7px; background: var(--ink); color: var(--bg); font-size: 12px; }

/* buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 36px; padding: 0 14px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface); cursor: pointer; white-space: nowrap; }
.btn:hover:not(:disabled) { border-color: var(--ink-3); }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }
.btn.solid { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
.btn.danger { color: var(--danger); border-color: var(--danger); background: transparent; font-weight: 600; }
.btn.quiet { border-color: transparent; background: transparent; }
.btn.icon { width: 36px; padding: 0; font-size: 18px; }
.btn.sm { height: 30px; padding: 0 10px; font-size: 13px; }
.btn.icon.sm { width: 30px; padding: 0; }
.btn.wide { width: 100%; }
.btn.tool { height: 32px; padding: 0 10px; font-weight: 600; }
.btn.tool span { font-weight: 400; color: var(--ink-2); }

/* login */
.login { display: grid; place-items: center; height: 100%; padding: 16px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); }
.login-card { width: min(360px, 100%); padding: 28px; display: grid; gap: 16px; }
.field { display: grid; gap: 6px; }
.field > span { font-size: 12px; color: var(--ink-2); font-weight: 500; }
input, select, textarea { height: 36px; border: 1px solid var(--line); border-radius: 8px; padding: 0 10px; background: var(--surface); width: 100%; }
textarea { height: auto; min-height: 64px; padding: 8px 10px; resize: vertical; }
.error { color: var(--danger); margin: 0; font-size: 13px; }

/* app frame */
.app { display: grid; grid-template-columns: 232px minmax(0, 1fr) var(--aside); height: 100vh; }
.side { border-right: 1px solid var(--line); background: var(--surface); display: flex; flex-direction: column; padding: 16px 12px; gap: 16px; min-height: 0; }
.type-list { display: grid; gap: 4px; }
.type-item { text-align: left; border: 1px solid transparent; background: transparent; border-radius: 8px; padding: 8px 10px; cursor: pointer; display: grid; gap: 2px; }
.type-item:hover { background: var(--surface-2); }
.type-item.on { background: var(--surface-2); border-color: var(--line); }
.type-item b { font-weight: 600; }
.type-item small { color: var(--ink-3); }
.side-section { display: flex; flex-direction: column; gap: 6px; min-height: 0; flex: 1; }
.side-title { font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--ink-3); padding: 0 10px; }
.version-list { overflow: auto; display: grid; gap: 2px; align-content: start; }
.ver { text-align: left; border: 0; background: transparent; border-radius: 6px; padding: 6px 10px; cursor: pointer; display: grid; gap: 1px; font-size: 13px; }
.ver:hover { background: var(--surface-2); }
.ver.on { background: var(--surface-2); font-weight: 600; }
.ver small { color: var(--ink-3); font-weight: 400; }
.side-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; border-top: 1px solid var(--line); padding-top: 12px; }
.me { font-size: 13px; color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.main-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 14px 20px; border-bottom: 1px solid var(--line); background: var(--surface); }
.main-head h1 { font-size: 18px; margin: 0; font-weight: 700; }
.meta { font-size: 12px; color: var(--ink-3); }
.meta .dirty { color: var(--warn); font-weight: 600; }
.meta .old { color: var(--danger); font-weight: 600; }
.actions { display: flex; gap: 8px; align-items: center; }

.toolbar { display: flex; align-items: center; gap: 8px; padding: 8px 20px; border-bottom: 1px solid var(--line); background: var(--surface); flex-wrap: wrap; }
.tabs { display: flex; gap: 4px; }
.tab { border: 1px solid var(--line); background: var(--surface); border-radius: 8px; height: 32px; padding: 0 12px; cursor: pointer; font-weight: 500; }
.tab.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.tab.dirty::after { content: "•"; margin-left: 4px; color: var(--warn); }
.tools { display: flex; gap: 4px; flex-wrap: wrap; }
.sep { width: 1px; height: 22px; background: var(--line); }
.grow { flex: 1; }
.toggle { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--ink-2); }
.toggle input { width: auto; height: auto; }

.stage { flex: 1; min-height: 0; overflow: auto; background: var(--stage); display: grid; place-items: center; padding: 32px; position: relative; }
.canvas-wrap { box-shadow: var(--shadow); background: #fff; line-height: 0; }
.empty { color: var(--ink-3); }

.aside { border-left: 1px solid var(--line); background: var(--surface); overflow: auto; min-width: 0; }
.panel { padding: 14px 14px 16px; border-bottom: 1px solid var(--line); display: grid; gap: 10px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.panel-head h2 { font-size: 13px; margin: 0; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; color: var(--ink-2); }
.props { display: grid; gap: 10px; }
.props .row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.props .row3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.props .field input, .props .field select { height: 32px; }
.chips { display: flex; gap: 4px; flex-wrap: wrap; }
.chip { height: 30px; min-width: 30px; padding: 0 8px; border-radius: 7px; border: 1px solid var(--line); background: var(--surface); cursor: pointer; }
.chip.on { border-color: var(--ink); background: var(--surface-2); font-weight: 600; }
.swatch { width: 30px; height: 30px; border-radius: 7px; border: 1px solid var(--line); cursor: pointer; padding: 0; }
.swatch.on { outline: 2px solid var(--focus); outline-offset: 1px; }
.obj-list { display: grid; gap: 2px; max-height: 280px; overflow: auto; }
.obj-row { display: flex; gap: 8px; align-items: center; text-align: left; border: 0; background: transparent; padding: 5px 8px; border-radius: 6px; cursor: pointer; font-size: 13px; }
.obj-row:hover { background: var(--surface-2); }
.obj-row i { font-style: normal; width: 18px; text-align: center; color: var(--ink-3); }
.obj-row span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.muted { color: var(--ink-3); font-size: 13px; }

.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; background: transparent; height: 28px; padding: 0 10px; font-size: 12px; cursor: pointer; }
.seg button.on { background: var(--accent); color: var(--accent-ink); }
.product-pick { position: relative; display: grid; gap: 6px; }
.results { position: absolute; top: 38px; left: 0; right: 0; z-index: 5; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow); max-height: 260px; overflow: auto; }
.results button { display: grid; width: 100%; text-align: left; border: 0; background: transparent; padding: 7px 10px; cursor: pointer; gap: 1px; }
.results button:hover, .results button.on { background: var(--surface-2); }
.results small { color: var(--ink-3); }
.chosen { font-size: 12px; color: var(--ink-2); }
.preview { position: relative; background: var(--stage); border-radius: 8px; padding: 10px; display: grid; place-items: center; min-height: 120px; }
.preview img { max-width: 100%; image-rendering: pixelated; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2); }
.preview img[src=""] { display: none; }
.pv-state { position: absolute; right: 8px; bottom: 6px; font-size: 11px; color: var(--ink-3); }
.pv-state.err { color: var(--danger); position: static; }

/* menus — right edge of the panel on the right edge of the button, opens down, grows left */
.menu-wrap { position: relative; }
.menu { position: absolute; right: 0; top: calc(100% + 6px); z-index: 20; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow); padding: 6px; display: grid; width: max-content; }
.menu button { display: flex; align-items: center; gap: 10px; border: 0; background: transparent; padding: 0 12px; height: 34px; border-radius: 6px; cursor: pointer; text-align: left; white-space: nowrap; }
.menu button:hover { background: var(--surface-2); }
.menu button i { font-style: normal; width: 16px; text-align: center; color: var(--ink-3); }
.menu button.danger { color: var(--danger); }
.menu button.danger i { color: var(--danger); }
.menu button:disabled { opacity: 0.4; cursor: default; }
.menu hr { border: 0; border-top: 1px solid var(--line); margin: 4px 0; }

/* dialog */
.dlg { border: 0; border-radius: 14px; padding: 0; width: min(460px, calc(100% - 32px)); background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.dlg::backdrop { background: rgba(8, 10, 18, 0.45); }
.dlg form { padding: 22px; display: grid; gap: 14px; }
.dlg h3 { margin: 0; font-size: 17px; }
.dlg p { margin: 0; color: var(--ink-2); }
.dlg .btns { display: flex; justify-content: space-between; gap: 8px; margin-top: 4px; }
.dlg .check { display: flex; gap: 8px; align-items: flex-start; font-size: 13px; color: var(--ink-2); }
.dlg .check input { width: auto; height: auto; margin-top: 3px; }
.dlg img { max-width: 100%; background: #fff; border-radius: 4px; }
.dlg .labels { display: flex; gap: 6px; flex-wrap: wrap; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 10px; box-shadow: var(--shadow); z-index: 50; max-width: min(560px, calc(100% - 32px)); }
.toast.err { background: var(--danger); color: #fff; }

@media (max-width: 1000px) {
  .app { grid-template-columns: 200px minmax(0, 1fr) var(--aside); }
  .btn.tool span { display: none; }
  .stage { padding: 16px; }
}
@media (max-width: 720px) {
  .app { grid-template-columns: 1fr; grid-template-rows: auto auto auto; height: auto; }
  .side, .aside { border: 0; }
}
