:root {
    --bg-canvas: #f8fafc;
    --panel-bg: #ffffff;
    --border-color: #cbd5e1;
    --text-main: #1e293b;
    --accent: #3b82f6;
}

body {
    margin: 0;
    font-family: system-ui, sans-serif;
    background: #f1f5f9;
    color: var(--text-main);
    height: 100vh;
    display: flex;
    flex-direction: column;
}

.main-header {
    background: linear-gradient(135deg, #1e293b, #0f172a);
    padding: 12px 20px;
    color: white;
}

.header-content { 
    display: flex; 
    justify-content: space-between; 
    align-items: center;
}

.logo {
    color: #f59e0b;
    text-decoration: none;
    font-weight: 700;
    font-size: 1.2rem;
}

.nav {
    display: flex;
    gap: 20px;
    align-items: center;
}

.nav a {
    color: #cbd5e1;
    text-decoration: none;
}

.planner-main {
    flex: 1;
    padding: 20px;
    overflow: hidden;
}

/* Контекстное меню холста (ПКМ) */
.context-menu {
    position: fixed;
    z-index: 10000;
    min-width: 200px;
    background: #ffffff;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: 0 10px 28px rgba(15, 23, 42, 0.12);
    padding: 4px 0;
    display: flex;
    flex-direction: column;
}
.context-menu.hidden {
    display: none !important;
}
.context-menu__item {
    padding: 9px 16px;
    border: none;
    background: none;
    text-align: left;
    cursor: pointer;
    font: inherit;
    color: var(--text-main);
}
.context-menu__item:hover:not(:disabled) {
    background: #f1f5f9;
}
.context-menu__item:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

/* Ручки редактирования углов стены (режим «Редактировать стены») */
.wall-edit-handle {
    fill: #ffffff;
    stroke: #2563eb;
    stroke-width: 2;
    cursor: grab;
    pointer-events: all;
}

.container {
    max-width: 100%;
    height: 100%;
}

.planner-wrap {
    height: 100%;
    display: flex;
    flex-direction: column;
}

.canvas-area {
    position: relative;
}

.room-label-editor-host {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 50;
}

.room-label-editor-host textarea.room-label-editor-input {
    pointer-events: auto;
    position: absolute;
    min-width: 120px;
    max-width: 280px;
    min-height: 28px;
    padding: 6px 10px;
    margin: 0;
    border: 1px solid #cbd5e1;
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.92);
    box-shadow: 0 2px 10px rgba(15, 23, 42, 0.12);
    font: italic 0.85rem/1.3 Georgia, 'Times New Roman', serif;
    color: #334155;
    resize: both;
    transform: translate(-50%, -50%);
    z-index: 51;
}

.planner-shell {
    display: grid;
    /* Панели узкие (240px), центр широкий */
    grid-template-columns: 240px minmax(0, 1fr) 240px; 
    gap: 12px;
    flex: 1;
    min-height: 0;
}

/* ПАНЕЛИ */
.tool-panel {
    background: var(--panel-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 10px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
    overflow-y: auto;
}

.panel-toggle {
    width: 100%;
    padding: 10px;
    background: linear-gradient(135deg, #d1d5db, #9ca3af);
    border: 1px solid #94a3b8;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 600;
    margin-bottom: 10px;
}

.tools-collapse {
    display: block;
}

.tool-section { 
    margin-bottom: 15px; 
    padding: 8px;
    background: rgba(241, 245, 249, 0.5);
    border-radius: 6px;
}

.tool-section h4 { 
    margin: 0 0 8px; 
    text-transform: uppercase; 
    font-size: 0.7rem; 
    color: #64748b; 
    letter-spacing: 0.05em;
}

.tool-buttons {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

/* КНОПКИ ИНСТРУМЕНТОВ */
.btn-tool {
    width: 100%;
    text-align: left;
    padding: 8px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background: #f1f5f9;
    cursor: pointer;
    font-size: 0.85rem;
}

.btn-tool:hover {
    background: #e2e8f0;
}

.btn-tool.active { 
    background: #dbeafe; 
    border-color: var(--accent); 
    font-weight: bold; 
}

/* ПОЛЯ ВВОДА */
.tool-params {
    margin-top: 8px;
    padding: 8px;
    background: rgba(255, 255, 255, 0.8);
    border-radius: 6px;
    border: 1px dashed #cbd5e1;
}

.tool-params label {
    display: block;
    font-size: 0.75rem;
    color: #64748b;
    margin-bottom: 6px;
}

.tool-params input[type="number"] {
    width: 100%;
    padding: 6px; 
    border: 1px solid #cbd5e1; 
    border-radius: 4px;
    margin-top: 4px;
}

.tool-hint {
    font-size: 0.72rem;
    color: #64748b;
    margin: 8px 0 0;
    line-height: 1.35;
}

.radio-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-bottom: 8px;
}

.radio-group label {
    font-size: 0.72rem;
    display: flex;
    align-items: center;
    gap: 4px;
}

.hidden { 
    display: none !important; 
}

/* ХОЛСТ */
.canvas-area {
    background: #e2e8f0;
    border-radius: 12px;
    overflow: hidden;
    position: relative;
    display: flex;
    flex-direction: column;
}

.sticky-toolbar {
    padding: 10px;
    background: linear-gradient(180deg, #f8fafc, #ffffff);
    border-bottom: 1px solid #e2e8f0;
    display: flex;
    align-items: center;
    gap: 12px;
}

#modeSelect {
    padding: 6px;
    border-radius: 4px;
    border: 1px solid #cbd5e1;
}

#planCanvas {
    width: 100%; 
    flex: 1;
    background: radial-gradient(circle at center, #ffffff 0%, #f8fafc 100%);
    cursor: crosshair;
    outline: none;
}

/* ПРАВАЯ ПАНЕЛЬ */
.static-section {
    margin-bottom: 15px;
    padding: 10px;
    background: rgba(241, 245, 249, 0.5);
    border-radius: 6px;
}

.static-section h4 {
    margin: 0 0 8px;
    font-size: 0.7rem;
    text-transform: uppercase;
    color: #64748b;
    letter-spacing: 0.05em;
}

.btn-row {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.btn-row button {
    width: 100%;
    padding: 8px;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    background: #f1f5f9;
    cursor: pointer;
    font-size: 0.82rem;
}

.btn-row button:hover {
    background: #e2e8f0;
}

.btn-danger {
    background: linear-gradient(180deg, #fee2e2, #fecaca) !important;
    border-color: #ef4444 !important;
    color: #b91c1c !important;
}

.btn-primary {
    background: linear-gradient(135deg, #3b82f6, #2563eb) !important;
    color: white !important;
    border: none !important;
    font-weight: 600;
}

/* FULLSCREEN LOGIC */
body.fullscreen-mode .left-panel,
body.fullscreen-mode .right-panel,
body.fullscreen-mode .main-header,
body.fullscreen-mode h1 {
    display: none !important;
}

body.fullscreen-mode .planner-shell {
    grid-template-columns: 1fr;
    height: 100vh;
}

body.fullscreen-mode .planner-main {
    padding: 0;
}

body.fullscreen-mode .canvas-area {
    width: 100vw; 
    height: 100vh;
    margin: 0; 
    border-radius: 0; 
    position: fixed; 
    top: 0; 
    left: 0; 
    z-index: 999;
}

.fullscreen-exit-btn {
    position: fixed; 
    bottom: 20px; 
    left: 50%; 
    transform: translateX(-50%);
    padding: 12px 24px; 
    background: rgba(51, 65, 85, 0.95); 
    color: white; 
    border: 1px solid rgba(255,255,255,0.2); 
    border-radius: 24px;
    z-index: 1000; 
    cursor: pointer; 
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s;
    box-shadow: 0 4px 12px rgba(0,0,0,0.4);
    backdrop-filter: blur(4px);
    font-weight: 600;
}

body.fullscreen-mode .fullscreen-exit-btn { 
    opacity: 1;
    pointer-events: auto;
}

/* Правая панель: закрепленная высота, внутренний скролл */
#rightStaticPanel {
    height: 100%; 
    max-height: calc(100vh - 100px);
    overflow-y: auto;
    position: sticky;
    top: 10px;
    z-index: 50;
}

/* Дополнительные стили для правой панели */
.section-header {
    margin: 0 0 8px;
    font-size: 0.7rem;
    text-transform: uppercase;
    color: #64748b;
    letter-spacing: 0.05em;
    font-weight: 600;
}

.btn--silver {
    background: linear-gradient(180deg, #f1f5f9, #e2e8f0);
    border: 1px solid #cbd5e1;
    color: #334155;
    font-size: 0.82rem;
    padding: 8px;
    border-radius: 6px;
    cursor: pointer;
    width: 100%;
    text-align: left;
}

.btn--silver:hover {
    background: linear-gradient(180deg, #e2e8f0, #cbd5e1);
}

.btn--danger {
    background: linear-gradient(180deg, #fee2e2, #fecaca) !important;
    border: 1px solid #ef4444 !important;
    color: #b91c1c !important;
}

.history-buttons,
.action-buttons,
.file-buttons {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.view-label {
    display: block;
    margin-bottom: 6px;
    font-size: 0.78rem;
    color: #475569;
    cursor: pointer;
}

.action-btn {
    justify-content: center;
    text-align: center;
}

.opening-snap-row {
    margin-top: 8px;
    padding: 8px;
    background: rgba(255, 255, 255, 0.85);
    border-radius: 6px;
    border: 1px dashed #cbd5e1;
}

.opening-snap-row.hidden {
    display: none !important;
}

.opening-snap-label {
    display: block;
    font-size: 0.72rem;
    color: #64748b;
    margin-bottom: 6px;
}

.opening-snap-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}

.opening-snap-buttons .opening-snap-btn {
    flex: 1 1 calc(33.33% - 3px);
    min-width: 0;
    padding: 6px 4px;
    font-size: 0.75rem;
}

.btn.opening-snap-btn.active {
    background: #dbeafe;
    border-color: var(--accent);
    font-weight: bold;
}

.door-controls {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-top: 8px;
}

.door-controls button {
    flex: 1 1 calc(50% - 2px);
    padding: 6px 4px;
    font-size: 0.72rem;
    border: 1px solid #cbd5e1;
    border-radius: 4px;
    background: #f1f5f9;
    cursor: pointer;
}

.door-controls button:hover {
    background: #e2e8f0;
}

.door-controls button:last-child {
    flex: 1 1 100%;
}

/* Замеры: рулетка и точка (правая панель) */
.measure-tool-buttons {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.btn-aux-tool {
    width: 100%;
    text-align: left;
}

.btn.btn-aux-tool.active {
    background: #dbeafe;
    border-color: var(--accent);
    font-weight: bold;
}

.measure-readout {
    margin-top: 8px;
    padding: 8px;
    font-size: 0.78rem;
    line-height: 1.35;
    color: #334155;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
}

.measure-point-panel {
    margin-top: 8px;
}

.measure-point-label {
    display: block;
    font-size: 0.75rem;
    color: #64748b;
}

.measure-point-input {
    width: 100%;
    margin-top: 4px;
    padding: 6px;
    border: 1px solid #cbd5e1;
    border-radius: 4px;
    box-sizing: border-box;
}

.measure-hint {
    margin: 6px 0 0;
    font-size: 0.72rem;
    color: #64748b;
}

.layout-point-marker {
    pointer-events: none;
}

.plan-annotation {
    pointer-events: none;
}

#planCanvas .plan-dimension-label,
#planCanvas .plan-area-label {
    font-family: system-ui, -apple-system, Segoe UI, sans-serif;
    font-weight: 600;
    pointer-events: none;
    fill: #0f172a;
    paint-order: stroke fill;
    stroke: rgba(255, 255, 255, 0.92);
    stroke-width: 0.4px;
}

.plan-area-label {
    opacity: 0.95;
}

.room-label-cloud {
    pointer-events: none;
}

.room-label-cloud-rect {
    fill: rgba(255, 255, 255, 0.78);
    stroke: rgba(148, 163, 184, 0.55);
    stroke-width: 0.8;
}

.room-label-cloud-text {
    font-family: Georgia, 'Times New Roman', serif;
    font-style: italic;
    font-weight: 500;
    fill: #475569;
}

/* Каталог мебели (левая панель) */
.furniture-tool-section {
    margin-top: 4px;
}

.furniture-panel-toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    background: linear-gradient(180deg, #ffffff, #f8fafc);
    cursor: pointer;
    font: inherit;
    font-weight: 600;
    color: #1e293b;
    text-align: left;
    transition: background 0.15s, border-color 0.15s;
}

.furniture-panel-toggle:hover {
    background: #f1f5f9;
    border-color: #94a3b8;
}

.furniture-panel-toggle[aria-expanded="true"] {
    border-color: var(--accent);
    background: #eff6ff;
}

.furniture-panel-toggle__icon {
    font-size: 1.1rem;
    line-height: 1;
}

.furniture-panel-toggle__label {
    flex: 1;
}

.furniture-toggle-chevron {
    font-size: 0.75rem;
    color: #64748b;
    transition: transform 0.15s;
}

.furniture-panel-toggle[aria-expanded="true"] .furniture-toggle-chevron {
    transform: rotate(90deg);
}

.furniture-collapse.hidden {
    display: none !important;
}

.furniture-collapse {
    margin-top: 10px;
    padding-top: 4px;
    border-top: 1px dashed #e2e8f0;
}

.furniture-kitchen-params {
    margin-bottom: 10px;
    padding: 10px;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
}

.furniture-kitchen-params__title {
    margin: 0 0 8px;
    font-size: 0.72rem;
    font-weight: 600;
    color: #475569;
}

.furniture-dim-label {
    display: block;
    font-size: 0.72rem;
    color: #64748b;
    margin-bottom: 8px;
}

.furniture-dim-label:last-child {
    margin-bottom: 0;
}

.furniture-dim-label input {
    display: block;
    width: 100%;
    margin-top: 4px;
    padding: 6px 8px;
    border: 1px solid #cbd5e1;
    border-radius: 4px;
    box-sizing: border-box;
    font-size: 0.85rem;
}

.furniture-catalog-hint {
    font-size: 0.72rem;
    line-height: 1.35;
    margin: 0 0 8px;
}

.furniture-catalog-subhead {
    grid-column: 1 / -1;
    margin: 10px 0 4px;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: #64748b;
}

.furniture-catalog-subhead:first-child {
    margin-top: 0;
}

.furniture-catalog {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
    max-height: min(52vh, 420px);
    overflow-y: auto;
    padding: 2px;
}

.furniture-cat-item {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 2px;
    padding: 8px 8px;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    background: #f8fafc;
    cursor: pointer;
    font-size: 0.75rem;
    text-align: left;
    transition: background 0.12s, border-color 0.12s;
}

.furniture-cat-item:hover {
    background: #e2e8f0;
}

.furniture-cat-item.active {
    background: #dbeafe;
    border-color: var(--accent);
    font-weight: 600;
}

.furniture-cat-item__swatch {
    width: 100%;
    height: 10px;
    border-radius: 3px;
    margin-bottom: 2px;
}

.furniture-cat-item__dims {
    font-size: 0.68rem;
    color: #64748b;
}

.furniture-cat-item__cat {
    font-size: 0.62rem;
    color: #94a3b8;
    text-transform: uppercase;
    letter-spacing: 0.02em;
}

.furniture-actions {
    margin-top: 10px;
}

.furniture-actions .btn {
    width: 100%;
}

.plan-furniture {
    cursor: move;
}

.plan-furniture polygon {
    pointer-events: visiblePainted;
}

.plan-furniture text {
    pointer-events: none;
}

.plan-furniture-graphic path,
.plan-furniture-graphic line,
.plan-furniture-graphic circle,
.plan-furniture-graphic ellipse,
.plan-furniture-graphic rect,
.plan-furniture-graphic polygon {
    vector-effect: non-scaling-stroke;
}

/* Адаптивность */
@media (max-width: 900px) {
    .planner-shell {
        grid-template-columns: 1fr;
    }
    
    .tool-panel {
        max-height: 300px;
    }
}
