/* ============================================================
   СТРУКТОР — workspace UI (Figma-style)
   ============================================================ */

/* ==================== ТОКЕНЫ ==================== */
:root {
    --bg: #f7f7f8;
    --surface: #ffffff;
    --surface-2: #f3f4f6;
    --surface-hover: #f9fafb;
    --canvas-bg: #e8e9eb;
    --text: #111827;
    --text-muted: #6b7280;
    --text-faint: #9ca3af;
    --border: #e5e7eb;
    --border-soft: #f0f1f3;
    --border-strong: #111827;
    --brand: #2563eb;
    --danger: #dc2626;
    --radius: 8px;
    --radius-sm: 5px;
    --font: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    --topbar-h: 54px;
    --panel-w-left: 240px;
    --panel-w-right: 320px;
    --shadow-sheet: 0 2px 20px rgba(0, 0, 0, 0.16);
}

body.blueprint-mode {
    --bg: #0b2e59;
    --surface: #0d3059;
    --surface-2: #0a294e;
    --surface-hover: #12376a;
    --canvas-bg: #061c39;
    --text: #e0f2fe;
    --text-muted: #93c5fd;
    --text-faint: #60a5fa;
    --border: #1e40af;
    --border-soft: #16386e;
    --border-strong: #ffffff;
    --brand: #3b82f6;
    --danger: #f87171;
}

/* ==================== БАЗА ==================== */
* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }
body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: background-color 0.4s ease;
}

.hidden { display: none !important; }

body.blueprint-mode {
    background-image:
        linear-gradient(rgba(255,255,255,0.06) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255,255,255,0.06) 1px, transparent 1px);
    background-size: 28px 28px;
}

/* ==================== TOPBAR ==================== */
.topbar {
    height: var(--topbar-h);
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 0 16px;
    flex-shrink: 0;
    z-index: 100;
}
.topbar-left { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-logo {
    width: 30px; height: 30px; flex-shrink: 0;
    background: var(--brand); border-radius: 9px;
    display: flex; align-items: center; justify-content: center;
    color: #fff; font-weight: 700; font-size: 16px;
}
.project-name-input {
    width: 180px; font-size: 15px; font-weight: 600; font-family: inherit;
    color: var(--text); background: transparent;
    border: 1px solid transparent; border-radius: var(--radius-sm); padding: 5px 8px;
    transition: border-color 0.15s, background 0.15s;
}
.project-name-input:hover { border-color: var(--border); }
.project-name-input:focus { outline: none; border-color: var(--border-strong); background: var(--surface-2); }

.topbar-tabs { display: flex; gap: 4px; margin: 0 auto; overflow-x: auto; }
.nav-btn {
    padding: 8px 14px; font-size: 14px; font-weight: 500; font-family: inherit;
    color: var(--text-faint); background: none; border: none;
    border-bottom: 2px solid transparent; border-top: 2px solid transparent;
    cursor: pointer; white-space: nowrap; transition: color 0.15s, border-color 0.15s;
}
.nav-btn:hover { color: var(--text-muted); }
.nav-btn.active { color: var(--text); border-bottom-color: var(--text); }

.topbar-right { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }
.topbar-sep { width: 1px; height: 22px; background: var(--border); margin: 0 4px; }
.icon-btn {
    width: 32px; height: 32px;
    display: inline-flex; align-items: center; justify-content: center;
    background: none; border: 1px solid transparent; border-radius: var(--radius-sm);
    color: var(--text-muted); font-size: 15px; cursor: pointer;
    transition: all 0.15s;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); border-color: var(--border); }

/* ==================== WORKSPACE ==================== */
.app-main { flex: 1; min-height: 0; display: flex; }
.workspace {
    flex: 1;
    display: grid;
    grid-template-columns: var(--panel-w-left) 1fr var(--panel-w-right);
    min-height: 0;
}
.workspace.no-left { grid-template-columns: 0 1fr var(--panel-w-right); }
.workspace.no-right { grid-template-columns: var(--panel-w-left) 1fr 0; }
.workspace.no-left.no-right { grid-template-columns: 0 1fr 0; }
.workspace.no-left .panel-left,
.workspace.no-right .panel-right { display: none; }

/* ==================== ПАНЕЛИ ==================== */
.panel {
    background: var(--surface);
    display: flex;
    flex-direction: column;
    min-height: 0;
    position: relative;
    overflow: hidden;
}
.panel-left { border-right: 1px solid var(--border); }
.panel-right { border-left: 1px solid var(--border); }

.panel-head {
    display: flex; align-items: center; justify-content: space-between;
    padding: 12px 16px; border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.panel-title { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-muted); }
.panel-body { flex: 1; overflow-y: auto; padding: 12px; }
.panel-foot { border-top: 1px solid var(--border); padding: 10px 16px; flex-shrink: 0; }

/* Разделители-ресайзеры */
.panel-resizer {
    position: absolute; top: 0; bottom: 0; width: 7px;
    cursor: col-resize; z-index: 20;
}
.panel-left .panel-resizer { right: -3px; }
.panel-right .panel-resizer { left: -3px; }
.panel-resizer:hover { background: rgba(37, 99, 235, 0.25); }

/* Список объектов */
.object-row {
    display: flex; align-items: center; gap: 4px;
    padding: 8px 8px 8px 12px; border-radius: var(--radius-sm);
    cursor: pointer; border: 1px solid transparent;
    transition: background 0.12s, border-color 0.12s;
}
.object-row:hover { background: var(--surface-hover); }
.object-row.active {
    background: var(--surface-2);
    border-color: var(--border);
}
.blueprint-mode .object-row.active { border-color: var(--brand); }
.object-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.object-name { font-size: 14px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.object-meta { font-size: 12px; color: var(--text-faint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.objects-empty { font-size: 13px; color: var(--text-faint); font-style: italic; padding: 8px 4px; }

/* Итоги в панели */
.sum-row {
    display: flex; justify-content: space-between; gap: 8px;
    font-size: 13px; padding: 3px 0;
}
.sum-row span { color: var(--text-muted); }
.sum-row b { font-weight: 600; white-space: nowrap; }

/* ==================== ФОРМЫ ==================== */
.field-label { display: block; font-size: 12px; font-weight: 500; color: var(--text-muted); margin-bottom: 5px; }
.input, .select {
    width: 100%; padding: 7px 10px; font-size: 14px; font-family: inherit;
    color: var(--text); background: var(--surface);
    border: 1px solid var(--border); border-radius: var(--radius-sm);
    transition: border-color 0.15s;
}
.input:focus, .select:focus { outline: none; border-color: var(--border-strong); }
.select-inline { width: auto; padding: 5px 6px; font-size: 13px; background: transparent; color: var(--text-muted); cursor: pointer; }
.opening-num { width: 58px; flex-shrink: 0; }

.prop-block { margin-bottom: 18px; }
.prop-block + .prop-block { border-top: 1px solid var(--border-soft); padding-top: 18px; }

.grid { display: grid; gap: 12px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }

/* Кнопки */
.btn {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 7px 14px; font-size: 13px; font-weight: 500; font-family: inherit;
    color: var(--text); background: var(--surface);
    border: 1px solid var(--border); border-radius: var(--radius-sm);
    cursor: pointer; transition: border-color 0.15s, background 0.15s, color 0.15s;
    white-space: nowrap;
}
.btn:hover { border-color: var(--border-strong); }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-outline-strong { border-color: var(--border-strong); }
.btn-outline-strong:hover { background: var(--text); color: var(--bg); }
.btn-icon {
    background: none; border: none; color: var(--text-faint);
    font-size: 14px; line-height: 1; padding: 4px 6px;
    cursor: pointer; transition: color 0.15s; flex-shrink: 0;
}
.btn-icon:hover { color: var(--danger); }

/* Проёмы */
.openings-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 8px; }
.openings-head .field-label { margin: 0; }
.opening-row {
    display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
    background: var(--surface-2); border: 1px solid var(--border);
    border-radius: var(--radius-sm); padding: 7px; margin-bottom: 6px;
}
.empty-note { font-size: 12px; color: var(--text-faint); font-style: italic; }

/* ==================== РЕЗУЛЬТАТЫ ==================== */
.result-row {
    display: flex; justify-content: space-between; gap: 10px;
    padding: 6px 0; border-bottom: 1px solid var(--border-soft); font-size: 13px;
}
.result-row:last-child { border-bottom: none; }
.result-label { color: var(--text-muted); }
.result-value { font-weight: 500; text-align: right; }
.result-total { padding-top: 10px; margin-top: 6px; border-top: 1px solid var(--border) !important; }
.result-total .result-value { font-weight: 700; font-size: 16px; }

.summary-value { font-weight: 700; }

/* ==================== ХОЛСТ ==================== */
.canvas {
    position: relative;
    background: var(--canvas-bg);
    overflow: hidden;
    cursor: grab;
    user-select: none;
    -webkit-user-select: none;
    touch-action: none;
}
.canvas.grabbing { cursor: grabbing; }
.canvas-inner {
    position: absolute; left: 0; top: 0;
    transform-origin: 0 0;
    will-change: transform;
}
/* «Лист чертежа на столе» */
.canvas-inner svg {
    display: block;
    background: var(--surface);
    box-shadow: var(--shadow-sheet);
    border-radius: 3px;
}
.blueprint-mode .canvas-inner svg {
    filter: invert(100%) sepia(100%) saturate(0%) hue-rotate(288deg) brightness(150%) contrast(100%);
    mix-blend-mode: screen;
}

.canvas-toolbar {
    position: absolute; top: 12px; left: 12px; z-index: 10;
}
.canvas-tabs { display: flex; gap: 2px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 3px; box-shadow: 0 1px 6px rgba(0,0,0,0.08); }
.canvas-tab {
    padding: 5px 14px; font-size: 12px; font-weight: 500; font-family: inherit;
    color: var(--text-faint); background: none; border: none; border-radius: 3px;
    cursor: pointer; transition: all 0.15s;
}
.canvas-tab:hover { color: var(--text); }
.canvas-tab.active { background: var(--surface-2); color: var(--text); }
.blueprint-mode .canvas-tab.active { background: var(--brand); color: #fff; }

.canvas-controls {
    position: absolute; bottom: 14px; right: 14px; z-index: 10;
    display: flex; align-items: center; gap: 2px;
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius-sm); padding: 3px;
    box-shadow: 0 1px 6px rgba(0,0,0,0.08);
}
.canvas-controls button {
    width: 28px; height: 26px;
    background: none; border: none; border-radius: 3px;
    color: var(--text-muted); font-size: 14px; font-family: inherit; cursor: pointer;
}
.canvas-controls button:hover { background: var(--surface-2); color: var(--text); }
#zoom-label { font-size: 11px; color: var(--text-muted); min-width: 40px; text-align: center; }

.canvas-empty {
    position: absolute; inset: 0;
    display: flex; align-items: center; justify-content: center;
    color: var(--text-faint); font-size: 14px; pointer-events: none;
}

/* ==================== АНИМАЦИИ ==================== */
@keyframes fadeInTab { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.tab-animated { animation: fadeInTab 0.25s ease-out; }

/* ==================== ЗАГРУЗЧИК ==================== */
#loader-wrapper {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background-color: #111827; z-index: 99999;
    display: flex; flex-direction: column; justify-content: center; align-items: center;
    transition: opacity 0.6s ease, visibility 0.6s ease;
}
.loader-hide { opacity: 0; visibility: hidden; }
.loader-logo { width: 140px; height: 140px; margin-bottom: 20px; }
.loader-text {
    color: #fff; font-size: 12px; font-weight: 300;
    letter-spacing: 0.3em; text-transform: uppercase;
    opacity: 0; animation: fadeInText 0.5s ease-in-out 1.1s forwards;
}
.draw-path {
    fill: none; stroke: #ffffff; stroke-width: 2;
    stroke-linecap: round; stroke-linejoin: round;
    stroke-dasharray: 400; stroke-dashoffset: 400;
    animation: drawLine 1.5s ease-in-out forwards;
}
.delay-1 { animation-delay: 0.1s; }
.delay-2 { animation-delay: 0.5s; stroke-dasharray: 600; stroke-dashoffset: 600; }
.delay-3 { animation-delay: 0.9s; }
@keyframes drawLine { to { stroke-dashoffset: 0; } }
@keyframes fadeInText { to { opacity: 0.7; } }

/* ==================== МОБИЛЬНЫЕ ==================== */
@media (max-width: 899px) {
    .topbar { flex-wrap: wrap; height: auto; min-height: var(--topbar-h); padding: 8px 12px; gap: 8px; }
    .topbar-tabs { order: 3; width: 100%; margin: 0; }
    .project-name-input { width: 110px; }

    .workspace { display: block; position: relative; }
    .workspace.no-left .panel-left,
    .workspace.no-right .panel-right { display: flex; }

    .panel {
        position: fixed; top: 0; bottom: 0; width: min(85vw, 320px); z-index: 200;
        box-shadow: 0 0 40px rgba(0,0,0,0.3);
        transform: translateX(-105%);
        transition: transform 0.25s ease;
    }
    .panel-right { right: 0; transform: translateX(105%); }
    .panel.open { transform: none; }
    .panel-resizer { display: none; }
    .panel-foot { display: none; }
}

/* ==================== ПЕЧАТЬ / PDF ==================== */
#print-root { display: none; }

@media print {
    .topbar, .workspace, #loader-wrapper, .app-main { display: none !important; }
    body { overflow: visible; height: auto; display: block; background: #fff; }
    #print-root { display: block; }

    .print-cover { text-align: center; padding: 60px 0; page-break-after: always; }
    .print-cover h1 { font-size: 28px; margin-bottom: 8px; }
    .print-cover p { color: #666; font-size: 13px; }

    .print-section { page-break-after: always; }
    .print-section:last-child { page-break-after: auto; }
    .print-section h2 { font-size: 18px; margin-bottom: 4px; }
    .print-meta { font-size: 12px; color: #555; margin-bottom: 12px; }
    .print-drawing-title { font-size: 12px; font-weight: 600; margin: 14px 0 4px; }
    .print-drawing { border: 1px solid #ddd; padding: 10px; margin-bottom: 6px; }
    .print-drawing svg { width: 100% !important; height: auto !important; max-height: none !important; box-shadow: none; }
    .print-results .result-row { font-size: 12px; color: #222; }
}