/* ==========================================================================
   Конструктор шкафов: витрина (тема default) и карточка проекта в панели
   ========================================================================== */

.mb-app, .mb-report, #mebel-report {
    --mb-border: var(--border, #e5e7eb);
    --mb-card: var(--card, #fff);
    --mb-surface: var(--surface, #f5f6f8);
    --mb-accent: var(--accent, var(--primary, #5b4cf0));
    --mb-accent-soft: var(--accent-soft, var(--primary-soft, #efedff));
    --mb-muted: var(--muted, #8a909c);
    --mb-radius: var(--radius, 12px);
}

.mb-head { margin: 8px 0 18px; }
.mb-head h1 { margin-bottom: 6px; }
.mb-head p { margin: 0; max-width: 820px; }

.mb-layout { display: grid; grid-template-columns: 360px minmax(0, 1fr); gap: 18px; align-items: start; margin-bottom: 40px; }
.mb-panel { display: flex; flex-direction: column; gap: 12px; position: sticky; top: calc(var(--header-h, 0px) + 12px); max-height: calc(100vh - var(--header-h, 0px) - 24px); overflow: auto; padding-right: 4px; }
.mb-main { min-width: 0; display: flex; flex-direction: column; gap: 12px; }

.mb-box { background: var(--mb-card); border: 1px solid var(--mb-border); border-radius: var(--mb-radius); padding: 12px; display: flex; flex-direction: column; gap: 10px; }
.mb-box > summary { cursor: pointer; font-weight: 650; list-style: none; display: flex; justify-content: space-between; }
.mb-box > summary::after { content: '▾'; color: var(--mb-muted); }
.mb-box[open] > summary { margin-bottom: 4px; }
details.mb-box:not([open]) { gap: 0; }

.mb-field { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.mb-field > span { font-size: 12px; color: var(--mb-muted); }
.mb-field small { font-size: 11px; color: var(--mb-muted); }
.mb-field input, .mb-field select, .mb-field textarea, .mb-add, #mb-gsheet {
    width: 100%; min-width: 0; height: 36px; padding: 0 10px; border: 1px solid var(--mb-border); border-radius: 8px;
    background: var(--mb-surface); color: inherit; font: inherit; font-size: 14px;
}
.mb-field textarea { height: auto; padding: 8px 10px; }
.mb-field input:focus, .mb-field select:focus, .mb-field textarea:focus { outline: 2px solid var(--mb-accent); outline-offset: -1px; }
.mb-name input { font-weight: 650; font-size: 16px; }
.mb-check { display: flex; align-items: center; gap: 8px; font-size: 14px; cursor: pointer; }
.mb-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; align-items: end; }
.mb-grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.mb-row { display: flex; gap: 8px; align-items: center; }
.mb-row-split { justify-content: space-between; align-items: end; }
.mb-row-split .mb-field { flex: 1; }
.mb-wrap { flex-wrap: wrap; }
.mb-mini { display: flex; gap: 6px; }

.mb-mods { display: flex; flex-wrap: wrap; gap: 6px; }
.mb-mod { display: flex; flex-direction: column; align-items: flex-start; padding: 6px 10px; border: 1px solid var(--mb-border); border-radius: 10px; background: var(--mb-card); color: inherit; font: inherit; font-size: 13px; font-weight: 600; cursor: pointer; text-align: left; }
.mb-mod small { font-weight: 400; color: var(--mb-muted); font-size: 11px; }
.mb-mod.active { border-color: var(--mb-accent); background: var(--mb-accent-soft); }
.mb-add { width: auto; height: auto; padding: 8px 10px; cursor: pointer; }

.mb-sizes { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.mb-sizes .mb-muted { width: 100%; }
.mb-chip { padding: 4px 9px; border: 1px solid var(--mb-border); border-radius: 999px; background: var(--mb-surface); color: inherit; font: inherit; font-size: 12px; cursor: pointer; }
.mb-chip:hover { border-color: var(--mb-accent); }
.mb-chip.active { background: var(--mb-accent); border-color: var(--mb-accent); color: #fff; }
.mb-sec { border-top: 1px dashed var(--mb-border); padding-top: 10px; display: flex; flex-direction: column; gap: 8px; }
.mb-sec-head { display: flex; justify-content: space-between; align-items: center; font-size: 14px; }
.mb-x { border: 0; background: none; color: var(--mb-muted); font-size: 20px; line-height: 1; cursor: pointer; padding: 0 4px; }
.mb-x:hover { color: #e5484d; }

.mb-btn { display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 12px; border: 1px solid var(--mb-border); border-radius: 8px; background: var(--mb-card); color: inherit; font: inherit; font-size: 13px; cursor: pointer; white-space: nowrap; }
.mb-btn:hover { border-color: var(--mb-accent); }
.mb-btn.active { background: var(--mb-accent); border-color: var(--mb-accent); color: #fff; }
.mb-file { position: relative; }

.mb-view { position: relative; height: min(62vh, 640px); min-height: 340px; border-radius: var(--mb-radius); overflow: hidden; border: 1px solid var(--mb-border); background: var(--mb-surface); user-select: none; }
.mb-view canvas { display: block; cursor: grab; }
.mb-view canvas:active { cursor: grabbing; }
.mb-tools { position: absolute; top: 10px; left: 10px; display: flex; gap: 6px; flex-wrap: wrap; z-index: 2; }
.mb-tools .mb-btn { background: color-mix(in srgb, var(--mb-card) 88%, transparent); backdrop-filter: blur(6px); }
.mb-tools .mb-btn.active { background: var(--mb-accent); color: #fff; }
.mb-draw-wrap { position: absolute; inset: 0; z-index: 3; background: #fff; display: flex; flex-direction: column; color: #1f2937; }
.mb-draw-wrap[hidden] { display: none; }
.mb-draw-tools { position: absolute; top: 10px; right: 10px; display: flex; gap: 6px; align-items: center; z-index: 2; }
.mb-draw-tools .mb-btn, .mb-draw-tools .mb-check { background: #fff; color: #1f2937; border-color: #d1d5db; }
.mb-draw-tools .mb-check { padding: 0 10px; height: 32px; border: 1px solid #d1d5db; border-radius: 8px; font-size: 13px; }
.mb-draw-hint { position: absolute; left: 10px; bottom: 8px; font-size: 11px; color: #6b7280; z-index: 2; pointer-events: none; }
.mb-draw-svg { flex: 1; min-height: 0; padding: 50px 8px 24px; touch-action: none; }
.mb-draw-svg svg { width: 100%; height: 100%; display: block; user-select: none; }
.mb-drag { cursor: grab; }
.mb-drag:hover { fill: #ffd8b5; }
.mb-drag-x { cursor: ew-resize; }
.mb-drag-y { cursor: ns-resize; }
.mb-seg-btns { display: inline-flex; }
.mb-seg-btns .mb-btn:first-child { border-radius: 8px 0 0 8px; }
.mb-seg-btns .mb-btn:last-child { border-radius: 0 8px 8px 0; margin-left: -1px; }
.mb-tools { z-index: 4; }
.mb-flash { animation: mbflash .9s; }
@keyframes mbflash { 0%, 60% { background: var(--mb-accent-soft); } 100% { background: transparent; } }
.mb-sum { position: absolute; right: 10px; bottom: 10px; z-index: 2; padding: 8px 12px; border-radius: 10px; background: color-mix(in srgb, var(--mb-card) 90%, transparent); backdrop-filter: blur(6px); display: flex; flex-direction: column; align-items: flex-end; font-size: 12px; color: var(--mb-muted); }
.mb-sum b { font-size: 20px; color: var(--text, inherit); }
.mb-pick { position: absolute; left: 10px; bottom: 10px; z-index: 2; padding: 8px 12px; border-radius: 10px; background: color-mix(in srgb, var(--mb-card) 92%, transparent); backdrop-filter: blur(6px); display: flex; flex-direction: column; font-size: 12px; max-width: 60%; }
.mb-labels { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.mb-dim { position: absolute; left: 0; top: 0; padding: 1px 6px; border-radius: 6px; background: rgba(17, 20, 26, .78); color: #fff; font-size: 12px; font-weight: 600; white-space: nowrap; }
.mb-dim-sm { background: rgba(91, 76, 240, .8); font-size: 11px; }

.mb-tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--mb-border); overflow-x: auto; }
.mb-tabs button { border: 0; background: none; color: var(--mb-muted); font: inherit; font-weight: 600; font-size: 14px; padding: 10px 14px; cursor: pointer; border-bottom: 2px solid transparent; white-space: nowrap; }
.mb-tabs button.active { color: inherit; border-bottom-color: var(--mb-accent); }
.mb-tabpanel { display: flex; flex-direction: column; gap: 12px; }
.mb-tabpanel[hidden] { display: none; }

.mb-table-wrap { overflow-x: auto; border: 1px solid var(--mb-border); border-radius: var(--mb-radius); }
.mb-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.mb-table th, .mb-table td { padding: 6px 10px; border-bottom: 1px solid var(--mb-border); text-align: left; vertical-align: middle; }
.mb-table th { font-size: 12px; color: var(--mb-muted); font-weight: 600; background: var(--mb-surface); position: sticky; top: 0; }
.mb-table tbody tr[data-part] { cursor: pointer; }
.mb-table tbody tr[data-part]:hover { background: var(--mb-surface); }
.mb-table tbody tr.active { background: var(--mb-accent-soft); }
.mb-table .mb-total td { font-size: 15px; border-bottom: 0; }
.mb-r { text-align: right !important; white-space: nowrap; }
.mb-c { text-align: center !important; }
.mb-muted { color: var(--mb-muted); font-size: 12px; }
.mb-edge { color: #d9480f; vertical-align: middle; }
.mb-warn { margin: 0; padding: 8px 12px; border-radius: 8px; background: #fff4e5; color: #8a4b00; font-size: 13px; }
@media (prefers-color-scheme: dark) { .mb-warn { background: #3a2a10; color: #ffcf8a; } }

.mb-mat h4 { margin: 8px 0; font-size: 15px; }
.mb-mat h4 .mb-muted { font-weight: 400; }
.mb-fig { margin: 0 0 14px; padding: 10px; border: 1px solid var(--mb-border); border-radius: var(--mb-radius); background: var(--mb-card); }
.mb-fig figcaption { font-size: 12px; color: var(--mb-muted); margin-bottom: 6px; }
.mb-sheet { width: 100%; height: auto; display: block; }
.mb-sheet g[data-part] { cursor: pointer; }
.mb-sheet g[data-part]:hover rect { fill-opacity: 1; }

.mb-seg { display: flex; gap: 6px; flex-wrap: wrap; }
.mb-seg label { display: flex; align-items: center; gap: 6px; padding: 6px 12px; border: 1px solid var(--mb-border); border-radius: 8px; cursor: pointer; font-size: 14px; }
.mb-seg label:has(input:checked) { border-color: var(--mb-accent); background: var(--mb-accent-soft); }
.mb-box code { font-size: 12px; background: var(--mb-surface); padding: 1px 4px; border-radius: 4px; }
#mb-gsheet { width: auto; max-width: 100%; }

.mb-actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; padding: 12px 0; border-top: 1px solid var(--mb-border); }
.mb-link { display: flex; gap: 8px; align-items: center; font-size: 13px; word-break: break-all; }
.mb-link a { color: var(--mb-accent); }
.mb-dialog form { display: flex; flex-direction: column; gap: 10px; min-width: min(420px, 80vw); }
.mb-dialog h3 { margin: 0; }

@media (max-width: 980px) {
    .mb-layout { grid-template-columns: minmax(0, 1fr); gap: 12px; }
    .mb-layout > * { min-width: 0; }
    /* на телефоне: модель, форма, вкладки — одной колонкой */
    .mb-main { display: contents; }
    .mb-view { order: 1; height: 50vh; min-height: 280px; }
    .mb-panel { order: 2; position: static; max-height: none; overflow: visible; padding: 0; }
    .mb-tabs { order: 3; }
    .mb-tabpanel { order: 4; }
    .mb-actions { order: 5; }
}
@media (max-width: 520px) {
    .mb-grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .mb-table th, .mb-table td { padding: 5px 6px; }
}

/* Карточка проекта в панели */
#mebel-report h3 { margin: 16px 0 8px; font-size: 15px; }
#mebel-report h3:first-of-type { margin-top: 0; }
.mb-btn[hidden] { display: none; }
.mb-view .mb-sum { z-index: 4; }
.mb-hint-short { display: none; }
@media (max-width: 980px) {
    .mb-view.drawing .mb-sum { display: none; }
    .mb-hint-long { display: none; }
    .mb-hint-short { display: inline; }
    .mb-draw-svg { padding-top: 46px; }
}
.mb-drag-m { cursor: move; }
.mb-drag-m:hover, .mb-drag-on { fill: #ffe2c7; }
