:root {
  --bg: #f4f2ee;
  --panel: #ffffff;
  --ink: #232323;
  --muted: #777;
  --line: #ddd6cc;
  --accent: #9a7b4f;       /* oppein bronze */
  --accent-dark: #7a5f3a;
  --select: #2f6fed;
  --danger: #c0392b;
  --ok: #2e7d32;
  font-size: 14px;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: "Helvetica Neue", Arial, sans-serif;
  background: var(--bg); color: var(--ink);
  display: flex; flex-direction: column; overflow: hidden;
}

/* ---------- header ---------- */
#topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; padding: 8px 16px; background: #1f1c18; color: #f5efe6;
  border-bottom: 3px solid var(--accent);
  flex: 0 0 auto;
}
.brand-name { font-size: 19px; font-weight: 700; letter-spacing: 2px; }
.brand-name span { font-weight: 300; letter-spacing: 0; color: #d8c9ae; font-size: 15px; }
.brand-sub { font-size: 11px; color: #a99c86; margin-top: 2px; }
.order-fields { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.order-fields label { display: flex; flex-direction: column; font-size: 10px; color: #cdbfa8; gap: 2px; }
.order-fields input, .order-fields select {
  background: #2e2a24; border: 1px solid #4a443b; color: #f5efe6;
  border-radius: 4px; padding: 4px 6px; font-size: 12px; min-width: 110px;
}

/* ---------- layout ---------- */
#layout { display: flex; flex: 1 1 auto; min-height: 0; }
#palette { width: 248px; flex: 0 0 auto; background: var(--panel); border-right: 1px solid var(--line); overflow-y: auto; }
#stage { flex: 1 1 auto; display: flex; flex-direction: column; min-width: 0; position: relative; }
#rightbar { width: 332px; flex: 0 0 auto; background: var(--panel); border-left: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }

.panel-title {
  font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 1px;
  padding: 10px 12px 8px; color: var(--accent-dark);
  display: flex; justify-content: space-between; align-items: center;
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; background: var(--panel); z-index: 2;
}
.mini-toggle { font-size: 10px; font-weight: 400; text-transform: none; letter-spacing: 0; color: var(--muted); display: flex; gap: 3px; align-items: center; }
.panel-actions button {
  font-size: 11px; padding: 3px 8px; border: 1px solid var(--line);
  background: #faf8f4; border-radius: 4px; cursor: pointer;
}
.panel-actions button:hover { background: var(--accent); color: #fff; border-color: var(--accent); }

/* ---------- palette ---------- */
.pal-group { border-bottom: 1px solid var(--line); }
.pal-group > summary {
  cursor: pointer; padding: 8px 12px; font-weight: 600; font-size: 12.5px;
  list-style: none; display: flex; justify-content: space-between;
}
.pal-group > summary::after { content: "▾"; color: var(--muted); }
.pal-group:not([open]) > summary::after { content: "▸"; }
.pal-item {
  display: flex; justify-content: space-between; align-items: center;
  padding: 6px 10px 6px 8px; cursor: pointer; gap: 8px;
}
.pal-icon {
  flex: 0 0 28px; width: 28px; height: 32px;
  display: flex; align-items: center; justify-content: center;
}
.pal-icon-svg { width: 24px; height: 28px; display: block; }
.pal-text { flex: 1 1 auto; min-width: 0; }
.pal-item:hover { background: #f6efe3; }
.pal-item .p-sku { font-weight: 600; font-size: 12.5px; }
.pal-item .p-dim { color: var(--muted); font-size: 11px; }
.pal-item .p-price { font-size: 12px; color: var(--accent-dark); font-weight: 600; white-space: nowrap; }
.pal-item .p-price.unpriced { color: #b3a58d; font-weight: 400; }
.pal-item button.add {
  border: 1px solid var(--accent); color: var(--accent-dark); background: #fff;
  border-radius: 4px; cursor: pointer; font-size: 12px; padding: 2px 8px;
}
.pal-item button.add:hover { background: var(--accent); color: #fff; }

/* ---------- stage ---------- */
#view-tabs {
  display: flex; gap: 4px; align-items: center; padding: 6px 10px;
  background: #ece7de; border-bottom: 1px solid var(--line); flex: 0 0 auto;
}
.tab {
  border: 1px solid var(--line); background: #faf8f4; padding: 5px 14px;
  border-radius: 5px 5px 0 0; cursor: pointer; font-size: 12.5px;
}
.tab.active { background: var(--accent); color: #fff; border-color: var(--accent); font-weight: 600; }
.room-controls { margin-left: auto; font-size: 11.5px; color: var(--muted); display: flex; gap: 8px; align-items: center; }
.room-controls input { width: 52px; padding: 2px 4px; border: 1px solid var(--line); border-radius: 3px; }
.view { display: none; flex: 1 1 auto; min-height: 0; position: relative; }
.view.active { display: block; }
#view2d-wrap { background: #fdfdfb; overflow: auto; }
#view2d { display: block; width: 100%; height: 100%; }
#view3d-wrap { background: #e8e4dc; }
#view3d { width: 100%; height: 100%; display: block; }
#view3d-hint {
  position: absolute; bottom: 8px; left: 50%; transform: translateX(-50%);
  font-size: 11px; color: #00000088; background: #ffffffcc; padding: 3px 10px; border-radius: 10px;
  pointer-events: none;
}

/* 2D svg styles */
.dim-line, .dim-tick { stroke: #c0392b; stroke-width: 1; fill: none; }
.dim-text { fill: #c0392b; font-size: 11px; font-family: Arial; }
.sect-outline { stroke: #333; fill: #fff; stroke-width: 1.5; }
.sect-outline.selected { stroke: var(--select); stroke-width: 2.5; }
.panel-edge { stroke: #555; stroke-width: .75; fill: #f1ede6; }
.shelf-line { stroke: #444; stroke-width: 2; }
.shelf-line.shoe-back { stroke: #9a948a; stroke-width: 1; }
.rod-line { stroke: #888; stroke-width: 3; stroke-linecap: round; }
.drawer-box { fill: #faf6ef; stroke: #444; stroke-width: 1; }
.sku-label { font-size: 10.5px; font-family: Arial; fill: #555; text-anchor: middle; }
.click-target { fill: transparent; cursor: grab; touch-action: none; }
.click-target:hover { fill: #2f6fed11; }
.acc-target { fill: transparent; cursor: grab; touch-action: none; }
.acc-target:hover { fill: #2f6fed18; }
.sect-dragging { opacity: 0.65; }
.acc-dragging .shelf-line, .acc-dragging .rod-line { stroke: var(--select); }
.acc-dragging .drawer-box { stroke: var(--select); }
.acc-removing .shelf-line, .acc-removing .rod-line { stroke: var(--danger); stroke-dasharray: 4 3; }
.acc-removing .drawer-box { stroke: var(--danger); stroke-dasharray: 4 3; }
.acc-removing { opacity: 0.55; }
.drag-hint { font-size: 13px; font-family: Arial; fill: var(--danger); font-weight: 700; text-anchor: middle; }
.pal-item[draggable="true"] { cursor: grab; }

/* ---------- toast ---------- */
#toast {
  position: absolute; top: 52px; left: 50%; transform: translateX(-50%);
  background: #232323ee; color: #fff; padding: 8px 16px; border-radius: 6px;
  font-size: 12.5px; display: none; z-index: 30; max-width: 70%;
}
#toast.show { display: block; }
#toast.err { background: #a93226ee; }

/* ---------- inspector ---------- */
#inspector { flex: 0 0 auto; max-height: 46%; overflow-y: auto; border-bottom: 4px solid var(--line); display:flex; flex-direction:column; }
#inspector-body { padding: 8px 12px; overflow-y: auto; }
.empty { color: var(--muted); font-size: 12px; padding: 12px 4px; }
.insp-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 6px; }
.insp-head .sku { font-size: 15px; font-weight: 700; }
.insp-head .dims { font-size: 11px; color: var(--muted); }
.insp-btns { display: flex; gap: 5px; margin: 6px 0 10px; flex-wrap: wrap; }
.insp-btns button {
  font-size: 11.5px; padding: 4px 9px; border: 1px solid var(--line); background: #faf8f4;
  border-radius: 4px; cursor: pointer;
}
.insp-btns button:hover { background: #f0e9dc; }
.insp-btns button.danger { color: var(--danger); border-color: #e4b6b0; }
.insp-btns button.danger:hover { background: #fdf0ee; }
.acc-list { display: flex; flex-direction: column; gap: 4px; }
.acc-row {
  display: flex; align-items: center; gap: 6px; font-size: 12px;
  border: 1px solid var(--line); border-radius: 5px; padding: 4px 8px; background: #fcfbf8;
}
.acc-row .a-sku { font-weight: 600; min-width: 64px; }
.acc-row .a-pos { color: var(--muted); font-size: 11px; flex: 1; }
.acc-row .tag-incl { font-size: 9.5px; background: #e8f0e8; color: var(--ok); border-radius: 3px; padding: 1px 5px; }
.acc-row button { border: none; background: none; cursor: pointer; font-size: 13px; color: #666; padding: 1px 4px; }
.acc-row button:hover { color: #000; }
.acc-row button.del:hover { color: var(--danger); }
.insp-sub { font-size: 11px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); margin: 10px 0 5px; }

/* ---------- pricing ---------- */
#pricing { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; }
#pricing-body { overflow-y: auto; flex: 1 1 auto; padding-bottom: 10px; }
table.price { width: 100%; border-collapse: collapse; font-size: 11.5px; }
table.price th {
  text-align: left; font-size: 10px; text-transform: uppercase; color: var(--muted);
  padding: 6px 6px 4px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--panel);
}
table.price td { padding: 4px 6px; border-bottom: 1px solid #f0ebe2; }
table.price .cat-row td {
  font-weight: 700; font-size: 11px; color: var(--accent-dark);
  background: #f8f4ec; padding-top: 7px;
}
table.price td.num, table.price th.num { text-align: right; white-space: nowrap; }
table.price .qty-cell { display: flex; align-items: center; gap: 4px; justify-content: flex-end; }
table.price .qty-cell button {
  width: 17px; height: 17px; line-height: 1; border: 1px solid var(--line); background: #fff;
  border-radius: 3px; cursor: pointer; font-size: 11px; padding: 0;
}
table.price .qty-cell .q { min-width: 16px; text-align: center; font-weight: 600; }
.totals { border-top: 2px solid var(--accent); margin-top: 4px; padding: 8px 10px; font-size: 12.5px; }
.totals .trow { display: flex; justify-content: space-between; padding: 2px 0; }
.totals .grand { font-weight: 700; font-size: 15px; border-top: 1px solid var(--line); margin-top: 4px; padding-top: 6px; }
.totals .note { font-size: 10.5px; color: var(--muted); margin-top: 6px; }

/* ---------- print ---------- */
#print-area { display: none; }
@media print {
  body > header, body > main { display: none !important; }
  #print-area { display: block !important; font-family: Arial, sans-serif; color: #000; }
  @page { margin: 14mm; }
}
#print-area h1 { font-size: 20px; margin: 0; }
#print-area .ph-sub { font-size: 11px; color: #444; margin-bottom: 12px; }
#print-area h2 { font-size: 15px; border-bottom: 2px solid #000; padding-bottom: 4px; }
#print-area table { width: 100%; border-collapse: collapse; font-size: 11px; margin-top: 8px; }
#print-area th, #print-area td { border: 1px solid #999; padding: 4px 6px; text-align: left; }
#print-area th { background: #eee; }
#print-area td.num { text-align: right; }
#print-area .info-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 2px 24px; font-size: 12px; margin: 10px 0; }
#print-area .ptotals { margin-top: 10px; font-size: 13px; text-align: right; }

/* ---------- admin tools (topbar) ---------- */
.admin-tools { display: flex; align-items: center; gap: 8px; }
.admin-tools button {
  font-size: 12px; padding: 5px 10px; border-radius: 4px; cursor: pointer;
  background: #2e2a24; border: 1px solid #4a443b; color: #f5efe6;
}
.admin-tools button:hover { background: var(--accent); border-color: var(--accent); }
#btn-save-design { background: var(--accent); border-color: var(--accent); font-weight: 700; }
#btn-save-design:hover { background: var(--accent-dark); }
#admin-current {
  display: flex; align-items: center; gap: 6px; max-width: 260px;
  background: #2e2a24; border: 1px solid var(--accent); border-radius: 4px;
  padding: 4px 8px; font-size: 11.5px; color: #f0e6d2;
}
#admin-design-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#admin-current button {
  background: none; border: none; padding: 0 2px; font-size: 12px; cursor: pointer; color: #cdbfa8;
}
#admin-current button:hover { color: #fff; background: none; }

/* ---------- login overlay ---------- */
#login-overlay {
  position: fixed; inset: 0; z-index: 100; display: flex;
  align-items: center; justify-content: center;
  background: #1f1c18f2;
}
#login-overlay[hidden] { display: none; }
#login-form {
  background: var(--panel); border-radius: 10px; padding: 28px 32px; width: 320px;
  box-shadow: 0 24px 80px #00000066; display: flex; flex-direction: column; gap: 12px;
}
#login-form h3 { margin: 0 0 6px; font-size: 18px; letter-spacing: 2px; }
#login-form h3 span { font-weight: 300; letter-spacing: 0; font-size: 14px; color: var(--muted); }
#login-form label { display: flex; flex-direction: column; gap: 4px; font-size: 11px; color: var(--muted); }
#login-form input {
  border: 1px solid var(--line); border-radius: 5px; padding: 8px 10px; font-size: 14px;
}
#login-form button {
  margin-top: 4px; padding: 9px; border: none; border-radius: 5px; cursor: pointer;
  background: var(--accent); color: #fff; font-size: 14px; font-weight: 700;
}
#login-form button:hover { background: var(--accent-dark); }
.login-error { color: var(--danger); font-size: 12px; min-height: 15px; }

/* ---------- customers dialog ---------- */
#dlg-customers {
  border: 1px solid var(--line); border-radius: 10px; padding: 0;
  width: 560px; max-height: 80vh; box-shadow: 0 20px 60px #00000033;
}
#dlg-customers::backdrop { background: #1f1c1866; }
#dlg-customers .dlg-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 18px; border-bottom: 1px solid var(--line);
  position: sticky; top: 0; background: var(--panel); z-index: 2;
}
#dlg-customers h3 { margin: 0; font-size: 15px; }
#dlg-customers .dlg-head button { background: none; border: none; font-size: 15px; cursor: pointer; color: var(--muted); }
#customers-body { padding: 10px 18px 18px; overflow-y: auto; }
#customers-body .empty { color: var(--muted); padding: 18px 0; }
.cust-block { border-bottom: 1px solid var(--line); padding: 12px 0; }
.cust-block:last-child { border-bottom: none; }
.cust-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.cust-email { color: var(--muted); font-size: 12px; margin-left: 6px; }
.cust-new {
  font-size: 11.5px; padding: 4px 9px; border: 1px solid var(--accent); color: var(--accent-dark);
  background: none; border-radius: 4px; cursor: pointer;
}
.cust-new:hover { background: var(--accent); color: #fff; }
.cust-none { color: var(--muted); font-size: 12px; padding: 2px 0 4px; }
.cust-design { display: flex; align-items: center; gap: 10px; padding: 5px 0; font-size: 13px; }
.cd-name { flex: 0 0 auto; font-weight: 600; }
.cd-tag {
  font-size: 9.5px; font-weight: 400; text-transform: uppercase; letter-spacing: 1px;
  background: var(--accent); color: #fff; border-radius: 999px; padding: 1px 7px; margin-left: 4px;
}
.cd-meta { flex: 1 1 auto; color: var(--muted); font-size: 11.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cust-design button {
  font-size: 11.5px; padding: 3px 9px; border: 1px solid var(--line); border-radius: 4px;
  background: #faf8f4; cursor: pointer;
}
.cust-design button:hover { background: var(--accent); border-color: var(--accent); color: #fff; }
.cust-design button.danger:hover { background: var(--danger); border-color: var(--danger); }

/* ---------- new-closet-for-customer dialog ---------- */
#dlg-new-closet {
  border: 1px solid var(--line); border-radius: 10px; padding: 0;
  width: 360px; box-shadow: 0 20px 60px #00000033;
}
#dlg-new-closet::backdrop { background: #1f1c1866; }
#dlg-new-closet .dlg-head { padding: 14px 18px; border-bottom: 1px solid var(--line); }
#dlg-new-closet h3 { margin: 0; font-size: 15px; }
.ncc-body { padding: 14px 18px 18px; }
.ncc-body label { display: flex; flex-direction: column; gap: 5px; font-size: 12px; color: var(--muted); }
.ncc-body input { border: 1px solid var(--line); border-radius: 5px; padding: 8px 10px; font-size: 14px; }
.ncc-body .dlg-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 14px; }
.ncc-body button {
  font-size: 12.5px; padding: 7px 14px; border: 1px solid var(--line); border-radius: 5px;
  background: #faf8f4; cursor: pointer;
}
.ncc-body button[type="submit"] { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 700; }
.ncc-body button[type="submit"]:hover { background: var(--accent-dark); }
