:root {
  --brand: #0f766e;
  --brand-2: #14b8a6;
  --brand-soft: #ccfbf1;
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f1f3f5;
  --border: #e2e5e9;
  --text: #15191e;
  --muted: #5f6873;
  --danger: #dc2626;
  --warn-bg: #fff7ed;
  --warn-text: #9a3412;
  --canvas-bg: #eef1f4;
  --hall-floor: #dfe3e8;
  --toast-bg: #15191e;
  --toast-text: #ffffff;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.05), 0 4px 16px rgb(0 0 0 / 0.06);
  --radius: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --brand: #2dd4bf;
    --brand-2: #14b8a6;
    --brand-soft: #134e4a;
    --bg: #0f1215;
    --surface: #171b20;
    --surface-2: #1f242a;
    --border: #2c333b;
    --text: #e7eaee;
    --muted: #9aa4af;
    --danger: #f87171;
    --warn-bg: #3a2312;
    --warn-text: #fdba74;
    --canvas-bg: #1a1f25;
    --hall-floor: #2a3139;
    --toast-bg: #e7eaee;
    --toast-text: #15191e;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--brand); }
h1 { font-size: 1.5rem; margin: 0; }
h2 { font-size: 1.1rem; margin: 0 0 0.6rem; }
h3 { font-size: 0.8rem; margin: 1rem 0 0.4rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: 0.82rem; }
hr { border: 0; border-top: 1px solid var(--border); margin: 1rem 0; }
kbd { font: 0.75rem ui-monospace, monospace; border: 1px solid var(--border); border-bottom-width: 2px; border-radius: 4px; padding: 0 4px; background: var(--surface-2); }

/* ---------- buttons & forms ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 38px; padding: 0 14px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: inherit; font-weight: 550; cursor: pointer; text-decoration: none;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: 0.55; cursor: default; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
@media (prefers-color-scheme: dark) { .btn.primary { color: #042f2e; } }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.small { min-height: 30px; padding: 0 10px; font-size: 0.85rem; }
.btn.block { width: 100%; }
.danger-text { color: var(--danger) !important; }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center; width: 38px; height: 38px;
  border-radius: 8px; border: 1px solid transparent; background: transparent; color: var(--text);
  font-size: 1.15rem; cursor: pointer; text-decoration: none;
}
.icon-btn:hover { background: var(--surface-2); }
.icon-btn:disabled { opacity: 0.35; cursor: default; background: transparent; }
:focus-visible { outline: 2px solid var(--brand-2); outline-offset: 2px; }

.form { display: flex; flex-direction: column; gap: 12px; }
.form label { display: flex; flex-direction: column; gap: 4px; font-size: 0.85rem; font-weight: 550; flex: 1; min-width: 0; }
.form label.inline { flex-direction: row; align-items: center; gap: 8px; flex: 0 0 auto; }
.form label.check { flex-direction: row; align-items: center; gap: 8px; font-weight: 450; }
.form .row { display: flex; gap: 10px; flex-wrap: wrap; }
.form .row > label { min-width: 110px; }
input, select, textarea {
  font: inherit; font-weight: 400; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; min-height: 38px; width: 100%;
}
input[type="color"] { padding: 2px; width: 44px; height: 34px; min-height: 0; cursor: pointer; }
input[type="checkbox"], input[type="radio"] { width: auto; min-height: 0; accent-color: var(--brand); }
input:disabled { background: var(--surface-2); color: var(--muted); }
fieldset { border: 1px solid var(--border); border-radius: 8px; padding: 8px 12px 12px; margin: 0; min-width: 0; }
legend { font-size: 0.8rem; font-weight: 600; padding: 0 4px; }
.actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; margin-top: 4px; }
.actions.left { justify-content: flex-start; }
.form-error { color: var(--danger); margin: 0; min-height: 1.2em; font-size: 0.9rem; }

/* ---------- app shell ---------- */
.topbar {
  display: flex; align-items: center; gap: 20px; padding: 0 20px; height: 58px;
  background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 5;
}
.brand { display: flex; align-items: center; gap: 9px; color: var(--text); text-decoration: none; font-size: 1.15rem; }
.brand b, .auth-brand b { color: var(--brand); }
.topbar nav { display: flex; gap: 4px; }
.topbar nav a { padding: 8px 12px; border-radius: 8px; color: var(--muted); text-decoration: none; font-weight: 550; }
.topbar nav a:hover { background: var(--surface-2); color: var(--text); }
.topbar nav a.active { color: var(--brand); background: var(--brand-soft); }
.topbar .account { margin-left: auto; max-width: 280px; overflow: hidden; text-overflow: ellipsis; color: var(--muted); }
.page { max-width: 1100px; margin: 0 auto; padding: 24px 20px 60px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; box-shadow: var(--shadow); }
.empty { grid-column: 1 / -1; text-align: center; padding: 60px 20px; border: 2px dashed var(--border); border-radius: var(--radius); }
.badge { font-size: 0.72rem; font-weight: 600; background: var(--brand-soft); color: var(--brand); padding: 1px 7px; border-radius: 99px; }
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.list li:last-child { border-bottom: 0; }
.list.compact li { padding: 6px 0; }
.loading-page { display: flex; flex-direction: column; gap: 12px; align-items: center; justify-content: center; min-height: 70vh; color: var(--muted); }

/* plans */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(310px, 1fr)); gap: 16px; }
.plan-card { padding: 0; display: flex; flex-direction: column; margin: 0; }
.plan-card .card-main { display: flex; gap: 14px; padding: 16px; color: var(--text); text-decoration: none; flex: 1; }
.plan-card .card-main:hover h3 { color: var(--brand); }
.plan-card h3 { margin: 0 0 2px; font-size: 1.02rem; text-transform: none; letter-spacing: 0; color: var(--text); }
.plan-card p { margin: 0; }
.plan-card .meta { font-size: 0.8rem; color: var(--muted); margin-top: 4px; }
.card-actions { display: flex; gap: 4px; padding: 6px 10px; border-top: 1px solid var(--border); }
.mini-booth { flex: 0 0 64px; height: 64px; display: flex; align-items: center; justify-content: center; }
.mini-booth span {
  display: block; background: var(--floor); border-radius: 3px; border: 2px solid var(--text); border-bottom-style: dashed;
  width: calc(60px * min(1, var(--w) / var(--d))); height: calc(60px * min(1, var(--d) / var(--w)));
}

/* tables */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.table th { text-align: left; font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); font-weight: 600; padding: 6px 8px; border-bottom: 1px solid var(--border); }
.table td { padding: 8px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table .num { text-align: right; white-space: nowrap; }
.table.compact { font-size: 0.82rem; }
.table.compact td, .table.compact th { padding: 5px 4px; }
.table tr.group td { font-weight: 650; padding-top: 10px; border-bottom: 0; color: var(--muted); font-size: 0.78rem; }
.row-actions { white-space: nowrap; text-align: right; }
.swatch { display: inline-block; width: 18px; height: 18px; border-radius: 5px; border: 1px solid rgb(0 0 0 / 0.15); flex: 0 0 auto; vertical-align: middle; }

/* auth */
.auth { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.auth-card { width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 28px; box-shadow: var(--shadow); }
.auth-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 6px; }
.auth-brand h1 { font-size: 1.7rem; font-weight: 600; }
.auth .switch { text-align: center; margin: 16px 0 0; font-size: 0.9rem; }

/* modal */
.modal-backdrop { position: fixed; inset: 0; background: rgb(0 0 0 / 0.45); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 50; }
.modal { background: var(--surface); border-radius: 14px; width: 100%; max-width: 520px; max-height: calc(100vh - 32px); overflow: auto; box-shadow: 0 20px 60px rgb(0 0 0 / 0.3); }
.modal.wide { max-width: 760px; }
.modal header { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px 0; }
.modal header h2 { margin: 0; }
.modal-body { padding: 12px 18px 18px; }
.types { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.type-option { flex-direction: column !important; align-items: center; gap: 4px !important; padding: 10px 4px; border: 1px solid var(--border); border-radius: 8px; cursor: pointer; text-align: center; color: var(--muted); }
.type-option input { position: absolute; opacity: 0; pointer-events: none; }
.type-option span { display: flex; flex-direction: column; color: var(--text); }
.type-option small { color: var(--muted); font-weight: 400; }
.type-option:has(input:checked) { border-color: var(--brand); background: var(--brand-soft); color: var(--brand); }
.type-option:has(input:focus-visible) { outline: 2px solid var(--brand-2); }
.copy-row { display: flex; gap: 8px; margin: 10px 0; }
.export-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.export-opt { text-align: left; display: flex; flex-direction: column; gap: 4px; padding: 14px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); color: var(--text); font: inherit; cursor: pointer; }
.export-opt:hover { border-color: var(--brand); background: var(--surface-2); }
.export-opt span { font-size: 0.82rem; color: var(--muted); }

#toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: var(--toast-bg); color: var(--toast-text); padding: 10px 16px; border-radius: 10px; font-weight: 550;
  transition: 0.2s; z-index: 60; max-width: calc(100vw - 32px);
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.error { background: var(--danger); color: #fff; }

/* ---------- editor ---------- */
.editor, .viewer {
  display: grid; height: 100vh; height: 100dvh;
  grid-template-columns: 250px 1fr 300px; grid-template-rows: 56px 1fr;
  grid-template-areas: "bar bar bar" "cat stage props";
}
.viewer { grid-template-columns: 1fr 280px; grid-template-areas: "bar bar" "stage props"; }
.editor-bar {
  grid-area: bar; display: flex; align-items: center; gap: 10px; padding: 0 12px;
  background: var(--surface); border-bottom: 1px solid var(--border); min-width: 0;
}
.plan-title { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.title-btn { border: 0; background: transparent; color: var(--text); font: inherit; cursor: pointer; padding: 6px 8px; border-radius: 8px; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.title-btn:hover { background: var(--surface-2); }
.title-btn .edit-hint { color: var(--muted); }
.seg { display: inline-flex; background: var(--surface-2); border-radius: 9px; padding: 3px; }
.seg button { border: 0; background: transparent; color: var(--muted); font: inherit; font-weight: 600; padding: 5px 14px; border-radius: 7px; cursor: pointer; }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgb(0 0 0 / 0.12); }
.tools { display: flex; align-items: center; gap: 4px; }
.snap { display: flex; align-items: center; gap: 6px; font-size: 0.82rem; color: var(--muted); margin-left: 6px; white-space: nowrap; }
.snap select { min-height: 32px; padding: 4px 6px; width: auto; }
.save-state { font-size: 0.8rem; color: var(--muted); min-width: 64px; text-align: right; }
.save-state.pending { color: var(--muted); font-style: italic; }
.save-state.error { color: var(--danger); font-weight: 600; }

.side { background: var(--surface); overflow-y: auto; min-height: 0; }
.catalog-side { grid-area: cat; border-right: 1px solid var(--border); display: flex; flex-direction: column; }
.props-side { grid-area: props; border-left: 1px solid var(--border); }
.side-head { padding: 10px; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--surface); }
.cat-list { padding: 0 8px 8px; flex: 1; }
.cat-list h3 { margin: 12px 6px 4px; }
.cat-item {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 7px 8px; border: 1px solid transparent; border-radius: 8px;
  background: transparent; color: var(--text); font: inherit; text-align: left; cursor: grab;
}
.cat-item:hover { background: var(--surface-2); border-color: var(--border); }
.cat-item .cat-text { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.cat-item b { font-weight: 550; font-size: 0.9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cat-item small { color: var(--muted); font-size: 0.75rem; }
.cat-item .plus { color: var(--brand); font-weight: 700; font-size: 1.1rem; opacity: 0; }
.cat-item:hover .plus { opacity: 1; }
.side-foot { padding: 10px 14px; margin: 0; border-top: 1px solid var(--border); }

.stage { grid-area: stage; position: relative; overflow: hidden; min-width: 0; min-height: 0; background: var(--canvas-bg); }
.stage canvas { display: block; }
.labels-layer { position: absolute; inset: 0; pointer-events: none; }
.stage-hint { position: absolute; left: 12px; bottom: 10px; z-index: 2; font-size: 0.75rem; color: var(--muted); background: color-mix(in srgb, var(--surface) 80%, transparent); padding: 4px 8px; border-radius: 6px; pointer-events: none; }
.item-label {
  font-size: 11px; font-weight: 600; color: #111; background: rgb(255 255 255 / 0.85); padding: 1px 5px; border-radius: 4px;
  white-space: nowrap; max-width: 140px; overflow: hidden; text-overflow: ellipsis; box-shadow: 0 1px 2px rgb(0 0 0 / 0.2);
}
.item-label.selected { background: var(--brand-2); color: #fff; }
.item-label.bad { background: #ef4444; color: #fff; }
.side-label { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); white-space: nowrap; }
.side-label.closed { opacity: 0.8; }
.dim-label { font-size: 12px; font-weight: 700; color: var(--text); background: var(--surface); padding: 1px 6px; border-radius: 4px; border: 1px solid var(--border); }

.tabs { display: flex; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--surface); z-index: 1; }
.tabs button { flex: 1; border: 0; background: transparent; padding: 12px 6px; font: inherit; font-weight: 600; color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; }
.tabs button.on { color: var(--brand); border-bottom-color: var(--brand); }
.tab-body { padding: 12px 14px 24px; }
.tab-body h3:first-child { margin-top: 4px; }
.facts { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; margin: 0 0 10px; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; text-align: right; font-weight: 550; }
.keys { padding-left: 16px; margin: 0; color: var(--muted); line-height: 1.9; }
.props { gap: 10px; }
.props .row > label { min-width: 70px; }
.prop-title { display: flex; gap: 10px; align-items: center; }
.prop-title .swatch { width: 28px; height: 28px; }
.rot-row { align-items: flex-end; }
.rot-row .btn { flex: 0 0 auto; }
.warn { background: var(--warn-bg); color: var(--warn-text); padding: 8px 10px; border-radius: 8px; margin: 0; font-size: 0.85rem; font-weight: 550; }
.warn-box { background: var(--warn-bg); color: var(--warn-text); padding: 10px 12px; border-radius: 8px; font-size: 0.85rem; margin-bottom: 12px; }
.warn-box ul { margin: 6px 0 0; padding-left: 18px; }
.warn-box a { color: inherit; }
.totals { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 8px; }
.totals div { background: var(--surface-2); border-radius: 8px; padding: 8px; display: flex; flex-direction: column; }
.totals small { color: var(--muted); font-size: 0.72rem; }
.totals b { font-size: 1rem; }

/* ---------- small screens: canvas on top, panels below ---------- */
@media (max-width: 900px) {
  .editor, .viewer {
    height: auto; min-height: 100dvh;
    grid-template-columns: minmax(0, 1fr); grid-template-rows: auto 58vh auto auto;
    grid-template-areas: "bar" "stage" "props" "cat";
  }
  .viewer { grid-template-rows: auto 60vh auto; grid-template-areas: "bar" "stage" "props"; }
  .editor-bar { flex-wrap: wrap; height: auto; padding: 8px; gap: 6px; }
  .plan-title { flex-basis: calc(100% - 50px); order: 0; }
  .tools .snap { display: none; }
  .editor-bar .btn { padding: 0 10px; }
  .save-state { min-width: 0; margin-left: auto; }
  .stage-hint { display: none; }
  .props-side .facts dd { overflow-wrap: anywhere; }
  .side { border: 0; border-top: 1px solid var(--border); overflow: visible; }
  .cat-list { columns: 2; }
  .cat-list h3 { column-span: all; }
  .topbar { gap: 8px; padding: 0 12px; }
  .topbar .brand span { display: none; }
  .topbar .account { max-width: 120px; }
  .types { grid-template-columns: repeat(2, 1fr); }
  .export-grid { grid-template-columns: 1fr; }
}

/* ---------- print (Export → Print / PDF) ---------- */
#print-root { display: none; }
@media print {
  @page { size: A4; margin: 12mm; }
  body { background: #fff; color: #111; font-size: 10pt; }
  #app, #toast, .modal-backdrop { display: none !important; }
  #print-root { display: block; }
  #print-root header { display: flex; justify-content: space-between; border-bottom: 2px solid #0f766e; padding-bottom: 6px; margin-bottom: 8px; }
  #print-root h1 { font-size: 18pt; }
  #print-root h2 { font-size: 12pt; margin: 14px 0 4px; color: #0f766e; break-after: avoid; }
  #print-root header p { margin: 2px 0 0; color: #555; }
  #print-root .right { text-align: right; }
  #print-root .facts { display: block; margin: 0 0 8px; }
  #print-root .muted { color: #666; }
  #print-root .views { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; break-inside: avoid; }
  #print-root figure { margin: 0; border: 1px solid #ddd; padding: 6px; }
  #print-root figure svg, #print-root figure img { width: 100%; height: auto; max-height: 120mm; object-fit: contain; display: block; }
  #print-root figcaption { font-size: 8pt; color: #666; margin-top: 4px; }
  #print-root table { width: 100%; border-collapse: collapse; font-size: 9pt; }
  #print-root th { text-align: left; border-bottom: 1px solid #999; padding: 3px 4px; }
  #print-root td { border-bottom: 1px solid #e5e5e5; padding: 3px 4px; }
  #print-root tr { break-inside: avoid; }
  #print-root tr.total td { font-weight: 700; border-top: 2px solid #111; }
  #print-root footer { margin-top: 16px; font-size: 8pt; color: #888; }
}
