/* =====================================================================
   Door designer (door-studio-demo.html) — built on the site design system
   (inventory.css, scoped under .iv). Only what the warehouse doesn't have.
   Desktop: doors | properties | elevation | profile side by side.
   Below 1024px: one panel at a time, picked by the bottom nav (#dsApp[data-tab]).
   ===================================================================== */

html, body { margin: 0; padding: 0; height: 100%; background: #f1f5f9; }
.iv.ds { box-sizing: border-box; display: flex; flex-direction: column; height: 100vh; height: 100dvh; padding: 0; background: #f1f5f9; overflow: hidden; }
.ds .hidden { display: none !important; }
.ds .ds-sr { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
.ds input[type=number]::-webkit-inner-spin-button, .ds input[type=number]::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
.ds input[type=number] { -moz-appearance: textfield; }
.ds ::-webkit-scrollbar { width: 6px; height: 6px; }
.ds ::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 999px; }

/* ---------- top bar ---------- */
.ds-top { display: flex; align-items: center; gap: 10px; padding: 10px 14px; background: var(--iv-panel); border-bottom: 1px solid var(--iv-border-strong); flex-shrink: 0; }
.ds-top .iv-icon-btn { width: 36px; height: 36px; }
.ds-title { min-width: 0; flex: 1; }
.ds-title h1 { margin: 0; font-size: 18px; font-weight: 800; line-height: 1.3; color: var(--iv-text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ds-title .sub { font-size: 12.5px; color: var(--iv-text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ds-kpis { display: flex; gap: 6px; align-items: center; }
.ds-kpis .iv-pill { font-size: 12px; padding: 3px 10px; }
.ds-actions { display: flex; gap: 6px; align-items: center; flex-shrink: 0; }

/* ---------- workspace grid ---------- */
.ds-main {
    flex: 1; min-height: 0; display: grid; gap: 12px; padding: 12px;
    grid-template-columns: 15rem 19rem minmax(0, 1fr) minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr);
    grid-template-areas: "doors props elev prof";
}
#panelDoorsList { grid-area: doors; }
#panelProps { grid-area: props; }
#panelElevationCard { grid-area: elev; }
#panelProfileCard { grid-area: prof; }
@media (max-width: 1399px) {
    .ds-main { grid-template-columns: 14rem 18rem minmax(0, 1fr); grid-template-rows: minmax(0, 1.25fr) minmax(0, 1fr); grid-template-areas: "doors props elev" "doors props prof"; }
}

.ds-panel { background: var(--iv-panel); border: 1px solid var(--iv-border-strong); border-radius: var(--iv-radius-lg); display: flex; flex-direction: column; min-height: 0; min-width: 0; overflow: hidden; }
.ds-panel-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 14px; border-bottom: 1px solid var(--iv-border); flex-shrink: 0; min-height: 48px; }
.ds-panel-head .t { font-weight: 800; font-size: 14px; display: flex; align-items: center; gap: 6px; }
.ds-panel-head .t .ti { font-size: 17px; color: var(--iv-muted); }
.ds-panel-body { flex: 1; min-height: 0; overflow-y: auto; }
.ds-panel-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 12px; border-top: 1px solid var(--iv-border); font-size: 12.5px; color: var(--iv-text-2); flex-shrink: 0; }
.ds-viewport { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; padding: 8px; overflow: hidden; }
.ds-viewport { touch-action: none; position: relative; }
.ds-viewport > svg { width: 100%; height: 100%; max-height: 100% !important; overflow: visible; }
.ds-viewport.ds-zoomed { cursor: grab; }
.ds-viewport.ds-zoomed:active { cursor: grabbing; }
.ds-zoom { display: inline-flex; align-items: center; border: 1px solid var(--iv-border-strong); border-radius: 10px; overflow: hidden; flex-shrink: 0; }
.ds-zoom button { width: 30px; height: 28px; display: inline-flex; align-items: center; justify-content: center; color: #475569; }
.ds-zoom button .ti { font-size: 15px; }
.ds-zoom button:hover { background: var(--iv-sub); color: var(--iv-accent); }
.ds-zoom .lbl { width: auto; min-width: 46px; padding: 0 6px; font-size: 11.5px; font-weight: 700; font-variant-numeric: tabular-nums; border-inline: 1px solid var(--iv-border-strong); }
.ds-panel-head .ds-flat { margin-inline-start: auto; white-space: nowrap; }
.ds-loading { color: var(--iv-muted); font-size: 13px; }

/* ---------- doors list ---------- */
.ds-search { padding: 10px 12px 4px; position: relative; }
.ds-search .ti { position: absolute; left: 22px; top: 50%; transform: translateY(-30%); color: var(--iv-muted); font-size: 16px; }
.ds .ds-search .iv-input.sm { padding-left: 34px; }
#doorsListContainer { padding: 6px 8px 8px; }
.ds-door { display: block; width: 100%; text-align: left; padding: 9px 10px; border-radius: 12px; border: 1px solid transparent; margin-bottom: 4px; transition: background .12s, border-color .12s; }
.ds-door:hover { background: var(--iv-sub); }
.ds-door.on { background: var(--iv-accent-bg); border-color: #c7d2fe; }
.ds-door-row { display: flex; align-items: center; gap: 9px; }
.ds-door-no { min-width: 34px; height: 30px; padding: 0 6px; border-radius: 9px; background: #f1f5f9; color: #334155; font-weight: 800; font-size: 12.5px; display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0; }
.ds-door.on .ds-door-no { background: var(--iv-accent); color: #fff; }
.ds-door .size { font-weight: 700; font-size: 13.5px; color: var(--iv-text); font-variant-numeric: tabular-nums; direction: ltr; unicode-bidi: isolate; }
.ds-door .meta { font-size: 11.5px; color: var(--iv-text-2); }
.ds-door .qty { font-size: 12px; font-weight: 700; color: var(--iv-text-2); font-variant-numeric: tabular-nums; margin-inline-start: auto; white-space: nowrap; }
.ds-door .tags { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; padding-inline-start: 43px; }
.ds-door .tags .iv-pill { font-size: 10.5px; padding: 1px 7px; }
.ds-empty { padding: 28px 12px; text-align: center; color: var(--iv-muted); font-size: 13px; }

/* ---------- properties ---------- */
.ds-sec { border-bottom: 1px solid var(--iv-border); padding: 0 14px; }
.ds-sec:last-child { border-bottom: 0; }
.ds-sec > summary { list-style: none; display: flex; align-items: center; justify-content: space-between; padding: 12px 0; cursor: pointer; font-weight: 800; font-size: 13.5px; user-select: none; }
.ds-sec > summary::-webkit-details-marker { display: none; }
.ds-sec > summary .ti { color: var(--iv-muted); font-size: 16px; transition: transform .15s; }
.ds-sec[open] > summary .ti { transform: rotate(90deg); }
.ds-sec-body { padding-bottom: 14px; display: flex; flex-direction: column; gap: 10px; }
.ds .iv-field > span { font-size: 12.5px; color: var(--iv-text-2); margin-bottom: 4px; }
.ds .iv-input.sm, .ds .iv-select.sm { height: 36px; font-size: 13.5px; border-radius: 10px; padding-inline: 10px; }
.ds .iv-select.sm { padding-right: 26px; }
.ds .iv-input[readonly] { background: var(--iv-sub); color: var(--iv-text-2); }
.ds-unit { position: relative; }
.ds .ds-unit .iv-input.sm { padding-right: 34px; }
.ds-unit > i { position: absolute; right: 10px; top: 50%; transform: translateY(-50%); font-style: normal; font-size: 11.5px; color: var(--iv-muted); pointer-events: none; }
.ds-grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.ds-grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.ds-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.ds-toggle { cursor: pointer; display: inline-flex; position: relative; }
.ds-toggle .iv-chip { height: 34px; padding: 0 12px; user-select: none; }
.ds-toggle.ds-wide, .ds-toggle.ds-wide .iv-chip { width: 100%; justify-content: center; }
.ds-toggle input:checked + .iv-chip { background: var(--iv-accent-bg) !important; color: var(--iv-accent-text) !important; border-color: #c7d2fe !important; }
.ds-toggle input:checked + .iv-chip.bad { background: var(--iv-bad-bg) !important; color: var(--iv-bad) !important; border-color: var(--iv-bad-border) !important; }
.ds-toggle input:checked + .iv-chip.warn { background: var(--iv-warn-bg) !important; color: var(--iv-warn) !important; border-color: var(--iv-warn-border) !important; }
.ds-toggle input:focus-visible + .iv-chip { box-shadow: 0 0 0 3px var(--iv-accent-soft); }
.ds-toggle input:disabled + .iv-chip { opacity: .45; cursor: not-allowed; }
.ds-sub { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--iv-text-2); background: var(--iv-sub); border: 1px solid var(--iv-border); border-radius: 10px; padding: 8px 10px; }
.ds-sub .iv-input { width: 84px; flex: none; }
.ds-note { font-size: 11.5px; color: var(--iv-muted); }

/* ---------- status footer (door-studio-footer.js) ---------- */
#dsFooter { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; padding: 7px 16px; background: var(--iv-panel); border-top: 1px solid var(--iv-border-strong); font-size: 12.5px; color: var(--iv-text-2); flex-shrink: 0; }
#dsFooter b { color: var(--iv-text); font-weight: 800; font-variant-numeric: tabular-nums; direction: ltr; unicode-bidi: isolate; }

/* ---------- bottom nav (phones / tablets) ---------- */
.ds-nav { display: none; }

/* ---------- toast ---------- */
.ds-toast { opacity: 0; pointer-events: none; transform: translate(-50%, 12px); transition: opacity .2s, transform .2s; max-width: calc(100vw - 32px); }
.ds-toast.show { opacity: 1; transform: translate(-50%, 0); }
.ds-toast .ic { font-size: 16px; }
.ds-toast.ok .ic { color: #6ee7b7; }
.ds-toast.bad .ic { color: #fda4af; }
.ds-toast.warn .ic { color: #fcd34d; }
.ds-toast.info .ic { color: #a5b4fc; }

/* ---------- modals ---------- */
.ds .iv-modal-head p { margin: 2px 0 0; font-size: 12.5px; color: var(--iv-text-2); }
.ds-dim-input { width: 100%; height: 56px; text-align: center; font-size: 26px; font-weight: 800; border: 1px solid var(--iv-border-input); border-radius: var(--iv-radius); outline: none; font-variant-numeric: tabular-nums; }
.ds-dim-input:focus { border-color: var(--iv-accent); box-shadow: 0 0 0 3px var(--iv-accent-soft); }
.ds-steps { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }

/* ---------- below 1024px: one panel at a time ---------- */
@media (max-width: 1023px) {
    .ds-main { display: block; padding: 8px; }
    .ds-main > .ds-panel { display: none; height: 100%; }
    .ds[data-tab="doors"] #panelDoorsList,
    .ds[data-tab="props"] #panelProps,
    .ds[data-tab="elevation"] #panelElevationCard,
    .ds[data-tab="profile"] #panelProfileCard { display: flex; }
    .ds-viewport { padding: 4px; }

    .iv.ds { padding-bottom: calc(60px + env(safe-area-inset-bottom)); }
    .ds-nav {
        display: grid; grid-template-columns: repeat(4, 1fr);
        position: fixed; bottom: 0; right: 0; left: 0; z-index: 41;
        background: var(--iv-panel); border-top: 1px solid var(--iv-border-strong);
        padding-bottom: env(safe-area-inset-bottom); box-shadow: 0 -4px 16px rgba(15, 23, 42, .05);
    }
    .ds-nav button { height: 60px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: 11.5px; color: var(--iv-muted); position: relative; }
    .ds-nav button .ti { font-size: 22px; }
    .ds-nav button.on { color: var(--iv-accent); font-weight: 700; }
    .ds-nav .badge { position: absolute; top: 6px; right: calc(50% - 24px); background: var(--iv-accent); color: #fff; border-radius: 999px; font-size: 10px; line-height: 16px; min-width: 16px; padding: 0 4px; }
    .ds-toast { bottom: calc(72px + env(safe-area-inset-bottom)); }
    .ds-kpis { display: none; }
    #dsFooter { padding: 6px 12px; gap: 12px; }
    /* 16px stops iOS from zooming into a focused field */
    .ds .iv-input.sm, .ds .iv-select.sm, .ds .iv-input, .ds .iv-select { font-size: 16px; height: 42px; }
    .ds .ds-sub .iv-input { height: 38px; }
    .ds-toggle .iv-chip { height: 38px; }
    .ds-door { padding: 11px 10px; }
    .ds-zoom button { width: 38px; height: 34px; }
}
@media (max-width: 767px) {
    .ds-top { padding: 8px 10px; gap: 8px; }
    .ds-title h1 { font-size: 16px; }
    .ds-title .sub { font-size: 11.5px; }
    .ds-actions .iv-btn.sm { height: 36px; padding: 0 10px; }
    .ds-actions .ds-lbl { display: none; }
    .ds-actions .iv-btn.primary .ds-lbl { display: inline; }
    .ds .iv-modal-scrim { align-items: flex-end; padding: 0; }
    .ds .iv-modal { max-width: none !important; border-radius: 22px 22px 0 0; max-height: 92vh; }
}

.ds-swatch { width: 32px; height: 32px; flex-shrink: 0; border-radius: 10px; border: 1px solid var(--iv-border-input); background: #fff; }

/* ---------- door note: a flat box in the free margin beside the door (positioned by positionNote) ---------- */
#panelElevationCard { position: relative; }
.ds-notestrip { position: absolute; z-index: 5; top: 58px; right: 12px; width: 200px; max-width: calc(100% - 24px); max-height: 60vh; display: flex; flex-direction: column; gap: 3px;
    padding: 7px 9px; background: #fffdf5; border: 1px solid #fde68a; border-radius: 8px; color: #78350f; }
.ds-note-head { display: flex; align-items: center; justify-content: space-between; gap: 6px; font-size: 11px; font-weight: 700; color: #b45309; }
.ds-note-body { font-size: 12px; font-weight: 500; line-height: 1.55; white-space: pre-wrap; overflow-wrap: anywhere; overflow-y: auto; }
.ds-note-edit { width: 20px; height: 20px; border-radius: 6px; color: #b45309; display: inline-flex; align-items: center; justify-content: center; opacity: .6; }
.ds-note-edit .ti { font-size: 13px; }
.ds-note-edit:hover { opacity: 1; background: rgba(217, 119, 6, .12); }

/* ---------- list filters, multi-select ---------- */
.ds-filters { display: flex; flex-wrap: wrap; gap: 6px; padding: 6px 12px 2px; }
.ds-filters .iv-chip { height: 28px; padding: 0 10px; font-size: 12px; }
.ds-pick { width: 17px; height: 17px; accent-color: var(--iv-accent); flex-shrink: 0; cursor: pointer; }
#btnPaintPreview { height: 28px; padding: 0 10px; font-size: 12px; }
#btnPaintPreview.on { background: var(--iv-accent-bg) !important; color: var(--iv-accent-text) !important; border-color: #c7d2fe !important; }

/* ---------- the «Tools» drop-down (positioned under its button by door-studio-extras.js) ---------- */
.ds-doors-menu { position: relative; display: inline-flex; }
.ds-menu { position: fixed; top: 56px; right: 12px; z-index: 80; width: 260px; max-width: calc(100vw - 16px); max-height: calc(100vh - 80px); overflow-y: auto;
    background: var(--iv-panel); border: 1px solid var(--iv-border-strong); border-radius: var(--iv-radius); box-shadow: 0 12px 32px rgba(15,23,42,.16); padding: 6px; }
.ds-menu.hidden { display: none; }
.ds-menu button { width: 100%; display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 9px; text-align: left; font-size: 13.5px; font-weight: 600; color: #334155; background: none; border: 0; cursor: pointer; }
.ds-menu button .ti { font-size: 17px; color: var(--iv-text-2); flex-shrink: 0; }
.ds-menu button:hover, .ds-menu button:focus-visible { background: var(--iv-sub); color: var(--iv-accent-text); outline: none; }
.ds-menu button:hover .ti { color: var(--iv-accent); }
.ds-menu .sep { height: 1px; background: var(--iv-border); margin: 4px 2px; }

/* ---------- checks / DXF preview / quick table ---------- */
.ds-issue { display: flex; gap: 10px; padding: 10px 12px; border-radius: 10px; margin-bottom: 8px; font-size: 14px; border: 1px solid transparent; }
.ds-issue.err { background: var(--iv-bad-bg); border-color: var(--iv-bad-border); color: #9f1239; }
.ds-issue.warn { background: var(--iv-warn-bg); border-color: var(--iv-warn-border); color: #92400e; }
.ds-issue.info { background: var(--iv-accent-bg); color: var(--iv-accent-text); }
.ds-issue .no { font-weight: 800; white-space: nowrap; }
.ds-parts { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 10px; }
.ds-part { border: 1px solid var(--iv-border-strong); border-radius: var(--iv-radius); padding: 8px; background: #fff; }
.ds-part .svgbox { height: 190px; display: flex; align-items: center; justify-content: center; }
.ds-part .svgbox svg { width: 100%; height: 100%; }
.ds-part .cap { font-size: 12.5px; color: var(--iv-text-2); display: flex; justify-content: space-between; gap: 6px; }
.ds-table input, .ds-table select { height: 34px; font-size: 13.5px; padding: 0 8px; }
.ds-legend { display: flex; gap: 12px; flex-wrap: wrap; font-size: 12px; color: var(--iv-text-2); margin-bottom: 10px; }
.ds-legend i { display: inline-block; width: 18px; height: 3px; border-radius: 2px; margin-inline-end: 5px; vertical-align: middle; }

/* small square icon toggle (hinge distribution / manual placement) */
.ds-toggle.ds-sq .iv-chip { width: 36px; height: 36px; padding: 0; justify-content: center; border-radius: 10px; }
.ds-toggle.ds-sq .iv-chip .ti { font-size: 18px; margin: 0; }
@media (max-width: 1023px) { .ds-toggle.ds-sq .iv-chip { width: 42px; height: 42px; } }

/* ---------- paint colour picker ---------- */
.ds-swatch-btn { cursor: pointer; padding: 0; transition: box-shadow .15s, border-color .15s; }
.ds-swatch-btn:hover { border-color: var(--iv-accent); box-shadow: 0 0 0 3px var(--iv-accent-soft); }
.ds-paint-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 8px; max-height: 52vh; overflow-y: auto; padding: 2px; }
.ds-paint-card { display: flex; align-items: center; gap: 10px; padding: 8px; text-align: left; background: #fff; border: 1px solid var(--iv-border-strong); border-radius: var(--iv-radius); cursor: pointer; }
.ds-paint-card:hover { border-color: var(--iv-accent); background: var(--iv-sub); }
.ds-paint-card.on { border-color: var(--iv-accent); box-shadow: 0 0 0 2px var(--iv-accent-soft); background: var(--iv-accent-bg); }
.ds-paint-card .sw { width: 44px; height: 44px; border-radius: 10px; border: 1px solid rgba(15,23,42,.18); flex-shrink: 0; }
.ds-paint-card .t { display: flex; flex-direction: column; gap: 1px; min-width: 0; font-size: 13px; }
.ds-paint-card .n { font-size: 12px; color: var(--iv-text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ds-paint-card .m { font-size: 11.5px; color: var(--iv-text-2); }
.ds-paint-free { display: flex; flex-direction: column; gap: 6px; padding-top: 10px; border-top: 1px solid var(--iv-border); }

/* on / off items of the tools menu */
.ds-menu button .chk { margin-inline-start: auto; opacity: 0; color: var(--iv-accent); }
.ds-menu button.on .chk { opacity: 1; }
.ds-menu button.on { color: var(--iv-accent-text); }

/* glazed frame: frame / mullion section switch in the profile pane head */
.ds-gzseg { display: inline-flex; border: 1px solid var(--iv-border, #cbd5e1); border-radius: 8px; overflow: hidden; }
.ds-gzseg.hidden { display: none; }
.ds-gzseg button { padding: 2px 12px; font: inherit; font-size: 12px; font-weight: 700; background: transparent; color: var(--iv-text-2, #475569); border: 0; cursor: pointer; }
.ds-gzseg button + button { border-inline-start: 1px solid var(--iv-border, #cbd5e1); }
.ds-gzseg button.on { background: var(--iv-accent, #4f46e5); color: #fff; }
