:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --border: #d9dce1;
  --text: #1f2328;
  --muted: #6b7280;
  --accent: #2563eb;
  --accent-soft: #dbeafe;
  --danger: #dc2626;
  --wall: #3f4650;
  --shared: #e07a1f;
  --canvas: #fbfbfc;
  --grid-minor: #eceef1;
  --grid-major: #d7dbe0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  color: var(--text);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body { display: flex; flex-direction: column; background: var(--bg); }

/* ---------- toolbar ---------- */
.toolbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px;
  padding: 8px 12px; background: var(--panel); border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; white-space: nowrap; }
.project-name {
  font: inherit; font-weight: 600; padding: 4px 8px; width: 220px;
  border: 1px solid transparent; border-radius: 6px; background: transparent;
}
.project-name:hover, .project-name:focus { border-color: var(--border); background: #fff; outline: none; }
.dirty { color: var(--shared); font-size: 20px; line-height: 1; width: 10px; }
.group { display: flex; gap: 4px; align-items: center; }
button, select {
  font: inherit; padding: 5px 10px; border: 1px solid var(--border); border-radius: 6px;
  background: #fff; color: var(--text); cursor: pointer;
}
button:hover:not(:disabled) { background: var(--accent-soft); border-color: var(--accent); }
button:disabled { opacity: .4; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover { background: #1d4ed8; }
button.danger { color: var(--danger); }
button.active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.menu { position: relative; }
.menu summary { list-style: none; cursor: pointer; padding: 5px 10px; border: 1px solid var(--border); border-radius: 6px; background: #fff; }
.menu summary::-webkit-details-marker { display: none; }
.menu[open] summary { background: var(--accent-soft); border-color: var(--accent); }
.menu-items { position: absolute; z-index: 10; top: calc(100% + 4px); left: 0; min-width: 240px; padding: 4px; display: flex; flex-direction: column; gap: 2px;
  background: #fff; border: 1px solid var(--border); border-radius: 8px; box-shadow: 0 8px 24px rgba(0,0,0,.12); }
.menu-items button { border: none; text-align: left; }
.menu-items hr { border: none; border-top: 1px solid var(--border); margin: 4px 0; width: 100%; }
.grid-select { display: flex; align-items: center; gap: 6px; color: var(--muted); }

/* ---------- layout ---------- */
.layout { flex: 1; display: flex; min-height: 0; }
.stage { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.stage-body { flex: 1; position: relative; display: flex; min-height: 0; }
.view3d { position: absolute; inset: 0; }
.view3d canvas { display: block; }
.floor-bar { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; padding: 6px 10px; background: var(--panel); border-bottom: 1px solid var(--border); }
.floor-bar .spacer { flex: 1; }
.floor-bar label.check { display: flex; align-items: center; gap: 4px; }
.floor-tab { border-radius: 14px; padding: 3px 12px; }
.floor-tab.active, .floor-tab.active:hover { background: var(--accent); border-color: var(--accent); color: #fff; }
.canvas { flex: 1; min-width: 0; background: var(--canvas); touch-action: none; user-select: none; cursor: default; }
.canvas.panning { cursor: grabbing; }
.panel {
  width: 320px; flex-shrink: 0; overflow-y: auto; padding: 10px;
  border-left: 1px solid var(--border); background: var(--bg);
  display: flex; flex-direction: column; gap: 10px;
}
.card { background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; }
.card h2 { font-size: 14px; margin: 0 0 8px; }
.muted { color: var(--muted); }
.small { font-size: 12px; font-weight: 400; }
.status { padding: 4px 12px; font-size: 12px; color: var(--muted); background: var(--panel); border-top: 1px solid var(--border); min-height: 24px; }
.status.error { color: var(--danger); }

/* ---------- forms ---------- */
.form { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 8px; }
.form label { display: flex; flex-direction: column; gap: 2px; font-size: 12px; color: var(--muted); }
.form label.wide { grid-column: 1 / -1; }
.form input { font: inherit; color: var(--text); padding: 4px 6px; border: 1px solid var(--border); border-radius: 5px; width: 100%; }
.form input[type="color"] { padding: 0 2px; height: 28px; }
.form h3 { grid-column: 1 / -1; font-size: 12px; margin: 8px 0 0; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.tag { display: inline-block; font-size: 11px; color: var(--shared); }
.tag.kind-exterior { color: var(--wall); }
.tag.kind-mixed { color: #a16207; }
.form label.check { flex-direction: row; align-items: center; gap: 6px; color: var(--text); font-size: 13px; }
.form label.check input { width: auto; }
.form .wide, .form h2.wide { grid-column: 1 / -1; }
.row-actions { grid-column: 1 / -1; display: flex; gap: 4px; flex-wrap: wrap; margin-top: 6px; }

.split-box { grid-column: 1 / -1; display: grid; grid-template-columns: 1fr 1fr; gap: 6px 8px; margin-top: 6px; padding-top: 4px; border-top: 1px solid var(--border); }
.split-box select { width: 100%; padding: 4px 6px; }
.split-box p { margin: 0; }

ul.openings { list-style: none; margin: 0; padding: 0; }
ul.openings li { padding: 3px 4px; border-top: 1px solid var(--border); cursor: pointer; font-size: 13px; }
ul.openings li:hover { background: var(--accent-soft); }
.daylight { margin: 4px 0 0; }
.ok { color: #15803d; }
.bad { color: #b45309; }
#preset-select { max-width: 230px; }

/* ---------- summary ---------- */
.stats { display: grid; grid-template-columns: 1fr auto; gap: 3px 8px; margin: 0; }
.stats dt { color: var(--muted); }
.stats dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
table.rooms { width: 100%; border-collapse: collapse; margin-top: 10px; font-size: 13px; }
table.rooms td, table.rooms th { padding: 3px 4px; border-top: 1px solid var(--border); text-align: left; }
table.rooms td.num, table.rooms th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.rooms tr.sel { background: var(--accent-soft); }
table.rooms tr { cursor: pointer; }
.warnings { margin: 10px 0 0; padding-left: 18px; color: var(--danger); font-size: 12px; }
.help ul { margin: 0; padding-left: 18px; color: var(--muted); font-size: 12px; line-height: 1.5; }
kbd { font-size: 11px; border: 1px solid var(--border); border-bottom-width: 2px; border-radius: 4px; padding: 0 4px; background: #fff; }

/* ---------- svg ---------- */
.grid-minor { stroke: var(--grid-minor); stroke-width: 1; }
.grid-major { stroke: var(--grid-major); stroke-width: 1; }
.wall { fill: var(--wall); }
.wall.interior { fill: var(--shared); }
.ghost { fill: none; stroke: #94a3b8; stroke-dasharray: 6 4; stroke-width: 1; vector-effect: non-scaling-stroke; pointer-events: none; }
.room { stroke: rgba(0,0,0,.25); stroke-width: 1; vector-effect: non-scaling-stroke; cursor: move; }
.room.selected { stroke: var(--accent); stroke-width: 2; }
.opening-cut { fill: var(--canvas); stroke: none; cursor: ew-resize; }
.opening .frame { fill: none; stroke: #334155; stroke-width: 1; vector-effect: non-scaling-stroke; pointer-events: none; }
.opening .glass { stroke: #0284c7; stroke-width: 1.2; vector-effect: non-scaling-stroke; pointer-events: none; }
.opening .door-leaf { stroke: #334155; stroke-width: 2; vector-effect: non-scaling-stroke; pointer-events: none; }
.opening .door-swing { fill: none; stroke: #64748b; stroke-width: 1; stroke-dasharray: 4 3; vector-effect: non-scaling-stroke; pointer-events: none; }
.opening.selected .opening-cut { fill: var(--accent-soft); }
.opening.selected .door-leaf, .opening.selected .frame { stroke: var(--accent); }
.stair-body { fill: #e2e8f0; stroke: #64748b; stroke-width: 1; vector-effect: non-scaling-stroke; cursor: move; }
.stair.selected .stair-body { stroke: var(--accent); stroke-width: 2; }
.stair .step { stroke: #64748b; stroke-width: 1; vector-effect: non-scaling-stroke; pointer-events: none; }
.stair-arrow { fill: none; stroke: #334155; stroke-width: 1.5; vector-effect: non-scaling-stroke; pointer-events: none; }
.stair-arrow-start { fill: #334155; pointer-events: none; }
.stair-label { fill: #334155; text-anchor: middle; dominant-baseline: middle; pointer-events: none; paint-order: stroke; stroke: #e2e8f0; stroke-width: 3px; }
.stair-void rect { fill: rgba(148, 163, 184, .12); stroke: #64748b; stroke-dasharray: 6 4; stroke-width: 1; vector-effect: non-scaling-stroke; pointer-events: none; }
.stair-void line { stroke: #94a3b8; stroke-width: 1; vector-effect: non-scaling-stroke; pointer-events: none; }
.roof { pointer-events: none; }
.roof-area { fill: rgba(154, 52, 18, .07); stroke: none; }
.ridge { fill: none; stroke: #9a3412; stroke-width: 1.5; stroke-dasharray: 10 4; vector-effect: non-scaling-stroke; }
.room.space { stroke: rgba(0,0,0,.12); }
.guide { stroke: #ec4899; stroke-width: 1; stroke-dasharray: 5 3; pointer-events: none; }
.marquee { fill: rgba(37, 99, 235, .08); stroke: var(--accent); stroke-dasharray: 4 3; pointer-events: none; }
.measure { stroke: #0f766e; stroke-width: 2; pointer-events: none; }
.measure-end { fill: #fff; stroke: #0f766e; stroke-width: 2; pointer-events: none; }
.measure-text { fill: #0f766e; font-size: 13px; font-weight: 600; text-anchor: middle; paint-order: stroke; stroke: var(--canvas); stroke-width: 4px; pointer-events: none; }
.canvas.measuring { cursor: crosshair; }
.canvas.pan-ready { cursor: grab; }
.dims { pointer-events: none; }
.dims .dim-line, .dims .dim-tick { stroke: #475569; stroke-width: 1; vector-effect: non-scaling-stroke; }
.dims .dim-line.total { stroke: #0f172a; }
.dim-label { fill: #334155; text-anchor: middle; dominant-baseline: auto; }
.room-label { fill: #1f2328; text-anchor: middle; dominant-baseline: middle; pointer-events: none; }
.room-label .dim { fill: #4b5563; }
.orient { fill: none; stroke: rgba(0,0,0,.45); stroke-width: 1.5; vector-effect: non-scaling-stroke; pointer-events: none; }
.peers { display: inline-flex; gap: 2px; }
.peer { display: inline-grid; place-items: center; width: 24px; height: 24px; border-radius: 50%; background: var(--peer); color: #fff; font-size: 12px; font-weight: 600; border: 2px solid var(--bg, #fff); }
.peer-sel { fill: none; stroke: var(--peer); stroke-width: 2; stroke-dasharray: 6 3; pointer-events: none; }
.peer-cursor { pointer-events: none; }
.peer-cursor path { fill: var(--peer); stroke: #fff; stroke-width: 1; }
.peer-cursor text { fill: var(--peer); font-size: 12px; font-weight: 600; paint-order: stroke; stroke: #fff; stroke-width: 3px; }
.sel-outline { fill: none; stroke: var(--accent); stroke-dasharray: 4 3; pointer-events: none; }
.handle { fill: #fff; stroke: var(--accent); stroke-width: 1.5; }
.handle[data-handle="n"], .handle[data-handle="s"] { cursor: ns-resize; }
.handle[data-handle="e"], .handle[data-handle="w"] { cursor: ew-resize; }
.handle[data-handle="ne"], .handle[data-handle="sw"] { cursor: nesw-resize; }
.handle[data-handle="nw"], .handle[data-handle="se"] { cursor: nwse-resize; }
.split-preview { fill: var(--shared); fill-opacity: .55; stroke: var(--shared); stroke-dasharray: 4 3; pointer-events: none; }
.split-preview.bad { fill: var(--danger); stroke: var(--danger); }
.dim-line { stroke: var(--accent); stroke-width: 1; }
.dim-text { fill: var(--accent); font-size: 11px; text-anchor: middle; dominant-baseline: middle; paint-order: stroke; stroke: var(--canvas); stroke-width: 3px; }

/* ---------- materials ---------- */
.stud { fill: #a16207; opacity: .85; }
.wall-id rect { fill: #fff; stroke: #a16207; stroke-width: 14; opacity: .92; }
.wall-id text { font-size: 150px; font-weight: 600; fill: #7c2d12; text-anchor: middle; dominant-baseline: central; }

/* ---------- развёртки стен ---------- */
dialog.walls-dialog { width: min(1200px, 97vw); }
.walls-layout { display: grid; grid-template-columns: 170px 1fr; gap: 12px; max-height: 76vh; }
.walls-list { overflow-y: auto; max-height: 70vh; display: flex; flex-direction: column; gap: 3px; padding-right: 4px; }
.walls-list h4 { margin: 6px 0 2px; font-size: 12px; color: var(--muted); }
.walls-list button { text-align: left; font-size: 13px; }
.walls-list button.exterior b { color: #3f4650; }
.walls-list button.interior b { color: #c2410c; }
.wall-view { overflow-y: auto; min-width: 0; max-height: 70vh; }
.wall-caption { margin: 0 0 6px; font-size: 13px; }
.elevation-box { border: 1px solid var(--border); border-radius: 6px; background: #fff; }
svg.elevation { width: 100%; height: auto; max-height: 52vh; display: block; }
svg.elevation .piece { fill: #f3e3c3; stroke: #8a5a2b; stroke-width: 6; }
svg.elevation .piece.brace { fill: #fca5a5; stroke: #b91c1c; fill-opacity: .85; }
svg.elevation .piece.header { fill: #ecd3a5; }
svg.elevation .piece:hover { fill: #fde68a; }
svg.elevation .wall-opening { fill: #e0f2fe; stroke: #0284c7; stroke-width: 8; }
svg.elevation .wall-opening-x { stroke: #0284c7; stroke-width: 5; fill: none; }
svg.elevation .el-mark { font-size: 90px; text-anchor: middle; dominant-baseline: middle; fill: #1f2328; pointer-events: none; }
svg.elevation .el-dim { stroke: #475569; stroke-width: 5; }
svg.elevation .el-dim-text { fill: #475569; text-anchor: middle; }
table.cut-list { margin-top: 8px; }
@media (max-width: 700px) { .walls-layout { grid-template-columns: 1fr; } .walls-list { flex-direction: row; flex-wrap: wrap; max-height: 120px; } }
dialog.wide-dialog { width: min(820px, 96vw); }
#materials { max-height: 65vh; overflow-y: auto; }
.materials-grid .stats { max-width: 420px; margin-bottom: 10px; }
table.spec { width: 100%; border-collapse: collapse; font-size: 13px; }
table.spec th, table.spec td { padding: 4px 6px; border-top: 1px solid var(--border); text-align: left; vertical-align: top; }
table.spec td.num, table.spec th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
table.spec tr.group { background: var(--bg); }
table.spec tr.group th { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
dialog .form { max-height: 80vh; overflow-y: auto; }

/* ---------- пользователи, история ---------- */
.badge { display: inline-block; font-size: 11px; padding: 1px 6px; border-radius: 9px; background: var(--accent-soft); color: var(--accent); font-weight: 500; }
.user-menu { margin-left: auto; }
.user-menu .menu-items { left: auto; right: 0; min-width: 140px; }
.history { display: grid; grid-template-columns: 300px 1fr; gap: 12px; }
.history .project-list { max-height: 60vh; }
.history .project-list li.current { background: var(--accent-soft); }
.history-preview { max-height: 60vh; overflow: auto; border: 1px solid var(--border); border-radius: 8px; min-height: 200px; }
.history-preview figure { margin: 6px; }
.history-preview figcaption { font-size: 12px; color: var(--muted); }
.history-preview svg { width: 100%; height: auto; }
.share-form { display: flex; gap: 6px; margin-top: 10px; }
.share-form input { flex: 1; font: inherit; padding: 4px 6px; border: 1px solid var(--border); border-radius: 5px; }
@media (max-width: 800px) { .history { grid-template-columns: 1fr; } }

/* ---------- dialog ---------- */
dialog { border: 1px solid var(--border); border-radius: 10px; padding: 16px; width: min(480px, 92vw); }
dialog h2 { margin-top: 0; font-size: 16px; }
.project-list { list-style: none; margin: 0; padding: 0; max-height: 50vh; overflow-y: auto; }
.project-list li { display: flex; align-items: center; gap: 8px; padding: 6px 4px; border-top: 1px solid var(--border); }
.project-list li .info { flex: 1; cursor: pointer; }
.project-list li .info:hover { color: var(--accent); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 6px; flex-wrap: wrap; margin-top: 12px; }

@media (max-width: 800px) {
  .layout { flex-direction: column; }
  .panel { width: auto; max-height: 40vh; border-left: none; border-top: 1px solid var(--border); }
  .canvas { min-height: 50vh; }
}

/* ---------- раскрой, обшивка ---------- */
dialog h2 label.inline { margin-left: 16px; font-weight: normal; }
label.inline { display: inline-flex; align-items: center; gap: 4px; }
svg.elevation .sheet-piece { fill: #14b8a6; fill-opacity: .08; stroke: #0f766e; stroke-width: 10; stroke-dasharray: 70 40; }
svg.elevation .sheet-piece.cut { fill-opacity: .18; }
svg.elevation .sheet-size { font-size: 85px; text-anchor: middle; dominant-baseline: middle; fill: #0f766e; pointer-events: none; }
.cutting h4 { margin: 12px 0 4px; font-size: 13px; font-weight: normal; }
.board-row { display: flex; align-items: center; gap: 6px; margin: 2px 0; font-size: 12px; }
.board-count { width: 34px; text-align: right; font-variant-numeric: tabular-nums; }
.board { position: relative; flex: 1; height: 18px; border: 1px solid #8a5a2b; background: #fff; border-radius: 2px; }
.board .cut { position: absolute; top: 0; bottom: 0; background: #f3e3c3; border-right: 2px solid #8a5a2b; font-size: 11px; text-align: center; overflow: hidden; line-height: 18px; }
.board .offcut { position: absolute; top: 0; bottom: 0; background: repeating-linear-gradient(45deg, #e5e7eb 0 4px, #fff 4px 8px); }
.structure-drawing svg { width: 100%; height: auto; max-height: 52vh; display: block; }

/* ---------- пользователи, приглашения ---------- */
.invite-link { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; margin: 6px 0; }
.invite-link input { flex: 1; min-width: 220px; font-family: ui-monospace, monospace; font-size: 12px; }
input.short { width: 60px; }
button.link { background: none; border: none; color: var(--accent); padding: 0; text-decoration: underline; cursor: pointer; }
.note { background: var(--accent-soft); border-radius: 6px; padding: 6px 10px; }
.auth-tabs { display: flex; gap: 0; margin-bottom: 12px; border-bottom: 1px solid var(--border); }
.auth-tab { border: none; border-bottom: 2px solid transparent; border-radius: 0; background: none; padding: 6px 14px; color: var(--muted); }
.auth-tab:hover:not(:disabled) { background: none; border-color: transparent; border-bottom-color: var(--border); color: var(--text); }
.auth-tab.active, .auth-tab.active:hover { background: none; border-bottom-color: var(--accent); color: var(--accent); }
.google-row { display: flex; flex-direction: column; align-items: stretch; gap: 6px; text-align: center; margin-top: 4px; }
.google-btn { display: flex; align-items: center; justify-content: center; gap: 8px; background: #fff; padding: 7px 10px; }
.google-g { font-weight: 700; color: #4285f4; font-family: Arial, sans-serif; }
table.admin-users td.actions { white-space: nowrap; text-align: right; }

/* ---------- многоугольники ---------- */
.draft { fill: none; stroke: var(--accent); stroke-width: 2; stroke-dasharray: 6 4; pointer-events: none; }
.draft.closing { stroke-opacity: .4; }
.draft-point { fill: #fff; stroke: var(--accent); stroke-width: 2; pointer-events: none; }
.draft-point.first { fill: var(--accent-soft); }
.vertex-handle { fill: #fff; stroke: var(--accent); stroke-width: 2; cursor: move; }
.vertex-handle.selected { fill: var(--accent); }
.insert-handle { cursor: copy; }
.insert-handle circle { fill: #fff; stroke: #16a34a; stroke-width: 1.5; opacity: .85; }
.insert-handle path { stroke: #16a34a; stroke-width: 1.6; }
.insert-handle:hover circle { fill: #dcfce7; }
table.edges { width: 100%; table-layout: fixed; }
table.edges th:nth-child(1) { width: 20px; }
table.edges th:nth-child(2) { width: 29%; }
table.edges th:nth-child(3) { width: 26%; }
table.edges th:nth-child(5) { width: 46px; }
table.edges input { width: 100%; box-sizing: border-box; min-width: 0; padding: 3px 4px; }
table.edges td, table.edges th { padding-left: 2px; padding-right: 2px; }
table.edges td.actions { white-space: nowrap; }
table.edges td.actions button { padding: 0 2px; font-size: 11px; display: block; width: 100%; margin: 1px 0; }
