:root {
    --font: system-ui, Avenir, Helvetica, Arial, sans-serif;
    --primary-50: #f0f9ff;
    --primary-100: #e0f2fe;
    --primary-200: #bae6fd;
    --primary-300: #7dd3fc;
    --primary-400: #38bdf8;
    --primary-500: #0ea5e9;
    --primary-600: #0284c7;
    --primary-700: #0369a1;
    --bg: #f1f5f9;
    --surface: #ffffff;
    --text: #0f172a;
    --muted: #64748b;
    --border: #e2e8f0;
    --radius-sm: 6px;
    --radius: 10px;
    --radius-lg: 14px;
    --radius-xl: 18px;
    --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
    --shadow: 0 1px 3px rgba(15, 23, 42, 0.08), 0 1px 2px rgba(15, 23, 42, 0.06);
    --shadow-md: 0 4px 12px rgba(15, 23, 42, 0.08);
    --shadow-lg: 0 10px 30px rgba(15, 23, 42, 0.12);
    --ease: cubic-bezier(0.22, 1, 0.36, 1);
    --danger: #dc2626;
    --danger-hover: #b91c1c;
}

* { box-sizing: border-box; }

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    margin: 0;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}

/* ===== Buttons ===== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-family: inherit;
    font-size: 15px;
    font-weight: 600;
    padding: 10px 18px;
    border-radius: var(--radius);
    border: 1px solid transparent;
    cursor: pointer;
    text-decoration: none;
    transition: all 0.2s var(--ease);
}
.btn:active { transform: translateY(0); }
.btn-primary { background: var(--primary-500); color: #fff; box-shadow: var(--shadow-sm); }
.btn-primary:hover { background: var(--primary-600); transform: translateY(-1px); box-shadow: var(--shadow-md); }
.btn-primary:focus-visible { outline: none; box-shadow: 0 0 0 3px rgba(14, 165, 233, 0.35); }
.btn-ghost { background: #fff; color: var(--text); border-color: var(--border); }
.btn-ghost:hover { background: var(--primary-50); border-color: var(--primary-200); transform: translateY(-1px); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: var(--danger-hover); transform: translateY(-1px); }

/* ===== Form controls ===== */
input, select, textarea {
    font-family: inherit;
    font-size: 15px;
    color: var(--text);
    background: #fff;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 9px 12px;
    transition: border-color 0.2s var(--ease), box-shadow 0.2s var(--ease);
}
input:focus, textarea:focus {
    outline: none;
    border-color: var(--primary-500);
    box-shadow: 0 0 0 3px rgba(14, 165, 233, 0.2);
}

/* ===== Select dropdowns: smooth animations ===== */
select {
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    padding-right: 38px;
    background-color: #fff;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    background-size: 16px;
    cursor: pointer;
    transition: border-color 0.25s var(--ease), box-shadow 0.25s var(--ease),
                transform 0.25s var(--ease), background-position 0.25s var(--ease);
}
select:hover {
    border-color: var(--primary-300);
}
select:focus {
    outline: none;
    border-color: var(--primary-500);
    transform: translateY(-1px);
    box-shadow: 0 0 0 3px rgba(14, 165, 233, 0.2), var(--shadow-md);
    background-position: right 12px 56%;
}
select:active {
    transform: translateY(0);
}

/* ===== Custom dropdown (enhance-select) ===== */
.es-wrap {
    position: relative;
    display: inline-block;
    width: 100%;
}
.es-wrap > select {
    position: absolute;
    left: 0;
    top: 0;
    width: 1px;
    height: 1px;
    opacity: 0;
    pointer-events: none;
}
.es-button {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    font-family: inherit;
    font-size: 15px;
    color: var(--text);
    background: #fff;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 9px 38px 9px 12px;
    cursor: pointer;
    text-align: left;
    transition: border-color 0.25s var(--ease), box-shadow 0.25s var(--ease),
                transform 0.25s var(--ease);
}
.es-button:hover {
    border-color: var(--primary-300);
}
.es-button:focus,
.es-button[aria-expanded="true"] {
    outline: none;
    border-color: var(--primary-500);
    transform: translateY(-1px);
    box-shadow: 0 0 0 3px rgba(14, 165, 233, 0.2), var(--shadow-md);
}
.es-button[disabled] {
    opacity: 0.55;
    cursor: default;
    transform: none;
    box-shadow: none;
}
.es-value {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.es-arrow {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    color: var(--muted);
    transition: transform 0.25s var(--ease);
}
.es-button[aria-expanded="true"] .es-arrow {
    transform: translateY(-50%) rotate(180deg);
}
.es-list {
    position: fixed;
    z-index: 2000;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    margin: 0;
    padding: 8px;
    list-style: none;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    width: min(420px, 90vw);
    max-height: 70vh;
    overflow-y: auto;
    transform-origin: center center;
    display: none;
}
.es-list.open,
.es-list.closing {
    display: block;
}
.es-list.open {
    animation: esDrop 0.22s var(--ease);
}
.es-list.closing {
    animation: esDropOut 0.18s var(--ease) forwards;
}
.es-backdrop {
    position: fixed;
    inset: 0;
    z-index: 1500;
    background: rgba(15, 23, 42, 0.45);
    -webkit-backdrop-filter: blur(7px);
    backdrop-filter: blur(7px);
    opacity: 0;
    visibility: hidden;
    overflow: hidden;
    transition: opacity 0.25s var(--ease), visibility 0.25s var(--ease);
}
.es-backdrop::before,
.es-backdrop::after {
    content: '';
    position: absolute;
    inset: -10%;
    pointer-events: none;
}
.es-backdrop::before {
    background:
        radial-gradient(circle at 18% 28%, rgba(14, 165, 233, 0.55), transparent 38%),
        radial-gradient(circle at 78% 18%, rgba(56, 189, 248, 0.45), transparent 42%),
        radial-gradient(circle at 62% 72%, rgba(125, 211, 252, 0.45), transparent 40%),
        radial-gradient(circle at 30% 82%, rgba(2, 132, 199, 0.40), transparent 44%);
    filter: blur(26px);
    opacity: 0.55;
    animation: esBokehA 14s ease-in-out infinite alternate;
}
.es-backdrop::after {
    background:
        radial-gradient(circle at 50% 12%, rgba(186, 230, 253, 0.40), transparent 40%),
        radial-gradient(circle at 12% 60%, rgba(14, 165, 233, 0.40), transparent 42%),
        radial-gradient(circle at 88% 66%, rgba(7, 89, 133, 0.45), transparent 44%);
    filter: blur(34px);
    opacity: 0.45;
    animation: esBokehB 18s ease-in-out infinite alternate;
}
.es-backdrop.open {
    opacity: 1;
    visibility: visible;
}
@keyframes esBokehA {
    from { transform: translate3d(0, 0, 0) scale(1); }
    to   { transform: translate3d(2%, -2%, 0) scale(1.08); }
}
@keyframes esBokehB {
    from { transform: translate3d(0, 0, 0) scale(1.05); }
    to   { transform: translate3d(-2%, 2%, 0) scale(1); }
}
.es-option {
    padding: 9px 12px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    color: var(--text);
    cursor: pointer;
    transition: background 0.15s var(--ease), color 0.15s var(--ease);
}
.es-option:hover,
.es-option.es-active {
    background: var(--primary-50);
    color: var(--primary-700);
}
.es-option.es-selected {
    background: var(--primary-100);
    color: var(--primary-700);
    font-weight: 600;
}
@keyframes esDrop {
    from { opacity: 0; transform: translate(-50%, -50%) scale(0.96); }
    to   { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}
@keyframes esDropOut {
    from { opacity: 1; transform: translate(-50%, -50%) scale(1); }
    to   { opacity: 0; transform: translate(-50%, -50%) scale(0.96); }
}

/* ===== Tag / pill ===== */
.tag {
    display: inline-block;
    font-size: 0.75em;
    padding: 2px 10px;
    border-radius: 999px;
    background: var(--primary-100);
    color: var(--primary-700);
    margin-left: 6px;
}

/* ===== Modal (shared) ===== */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.45);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}
.modal-box {
    background: #fff;
    border-radius: var(--radius-xl);
    width: 92%;
    max-width: 760px;
    max-height: 88vh;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-lg);
    animation: fadeInUp 0.35s var(--ease) both;
}
.modal-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 18px;
    border-bottom: 1px solid var(--border);
    font-weight: 700;
}
.modal-close {
    background: none;
    border: none;
    font-size: 20px;
    cursor: pointer;
    color: var(--muted);
    line-height: 1;
    border-radius: var(--radius-sm);
    padding: 4px 8px;
    transition: background 0.2s var(--ease), color 0.2s var(--ease);
}
.modal-close:hover { background: var(--primary-50); color: var(--primary-700); }
.modal-body { padding: 18px; overflow: auto; }
.modal-hidden { display: none !important; }

/* ===== Animations (from PulseHub) ===== */
@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(16px); }
    to { opacity: 1; transform: translateY(0); }
}
@keyframes slideInLeft {
    from { opacity: 0; transform: translateX(-12px); }
    to { opacity: 1; transform: translateX(0); }
}
@keyframes glow {
    0%, 100% { box-shadow: 0 0 0 0 rgba(14, 165, 233, 0.1); }
    50% { box-shadow: 0 0 0 8px rgba(14, 165, 233, 0); }
}
.animate-fadeInUp { animation: fadeInUp 0.45s var(--ease) both; }
.animate-slideInLeft { animation: slideInLeft 0.4s var(--ease) both; }
.animate-glow { animation: glow 3s ease-in-out infinite; }

/* ===== SVG facade sketch (schematic, black & white) ===== */
.sketch-wrap { margin: 14px 0 4px; padding: 12px; background: #ffffff; border: 1px solid #cccccc; border-radius: var(--radius, 12px); text-align: center; }
.sketch-wrap.sketch-clickable { cursor: pointer; transition: border-color 0.15s, box-shadow 0.15s; }
.sketch-wrap.sketch-clickable:hover { border-color: var(--primary-400, #38bdf8); box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.18); }
.sketch-toolbar { display: flex; gap: 8px; justify-content: flex-end; margin-bottom: 8px; }
.sketch-mini { margin-top: 10px; padding: 8px; background: #ffffff; border: 1px solid #cccccc; border-radius: var(--radius, 12px); text-align: center; }

.facade-svg { display: block; margin: 0 auto; max-width: 100%; height: auto; }
.svg-outline { fill: #ffffff; stroke: #000000; stroke-width: 1.8; }
.svg-door { fill: #ffffff; stroke: #000000; stroke-width: 1; }
.svg-door-num { fill: #000000; font-family: sans-serif; font-weight: 700; }
.svg-insert { fill: #ffffff; stroke: #000000; stroke-width: 0.8; }
.svg-insert-ldsp { fill: #ffffff; stroke: #000000; stroke-width: 0.8; }
.svg-insert-mirror { fill: #e6e6e6; stroke: #000000; stroke-width: 0.8; stroke-dasharray: 4 3; }
.svg-profile { fill: #f1f5f9; stroke: #64748b; stroke-width: 0.8; vector-effect: non-scaling-stroke; }
.svg-handle { fill: #ffffff; stroke: #000000; stroke-width: 1; vector-effect: non-scaling-stroke; }
.svg-divider-band { fill: rgba(29,78,216,0.13); stroke: #1d4ed8; stroke-width: 0.8; vector-effect: non-scaling-stroke; pointer-events: none; }
.svg-divider { stroke: #1d4ed8; stroke-width: 2.5px; stroke-dasharray: 5 4; vector-effect: non-scaling-stroke; pointer-events: none; }
.svg-divider-hit { stroke: transparent; stroke-width: 16px; vector-effect: non-scaling-stroke; cursor: ns-resize; pointer-events: stroke; }
/* Подсветка прилипания делителя при перетаскивании: обычное — оранжевое,
   к фиксированной вставке — зелёное. Цель прилипания — пунктиром. */
.svg-divider.snapped { stroke: #e8590c; stroke-width: 4px; stroke-dasharray: none; }
.svg-divider.snapped-fixed { stroke: #2f9e44; stroke-width: 4px; stroke-dasharray: none; }
.svg-divider.snap-target { stroke: #e8590c; stroke-width: 3px; stroke-dasharray: 2 2; }
.svg-divider.snap-target-fixed { stroke: #2f9e44; stroke-width: 3px; stroke-dasharray: 2 2; }
.svg-divider-band.snapped { fill: rgba(232,89,12,.28); stroke: #e8590c; }
.svg-divider-band.snapped-fixed { fill: rgba(47,158,68,.28); stroke: #2f9e44; }
.svg-snap-badge { font-family: sans-serif; font-weight: 700; pointer-events: none; }
.svg-snap-badge.fixed { fill: #2f9e44; }
.svg-snap-badge.free { fill: #e8590c; }
.svg-doorhit { fill: transparent; stroke: transparent; cursor: ew-resize; pointer-events: all; }

/* ===== Sketch popover (interactive editing in modal) ===== */
.sketch-popover { position: fixed; z-index: 60; background: #fff; border: 1px solid var(--border, #d9e2ec); border-radius: 8px; box-shadow: var(--shadow-md, 0 10px 25px rgba(15,23,42,0.15)); padding: 6px; min-width: 170px; display: none; }
.sketch-pop-title { font-size: 12px; color: var(--text-muted, #64748b); padding: 2px 6px 6px; }
.sketch-pop-btn { display: block; width: 100%; text-align: left; padding: 6px 10px; border: none; background: #fff; border-radius: 6px; cursor: pointer; font-size: 14px; color: var(--text, #0f172a); }
.sketch-pop-btn:hover { background: var(--primary-50, #eef4ff); }
.sketch-pop-btn.sel { background: var(--primary-100, #dbe6ff); font-weight: 600; }
