:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --panel-soft: #fafbfc;
  --border: #e4e7ec;
  --border-strong: #d5dae1;
  --text: #232a33;
  --fg: var(--text);
  --muted: #737d89;
  --accent: #2d6cdf;
  --accent-dark: #1f4fb0;
  --accent-soft: #eef3fc;
  --danger: #c0392b;
  --ok: #1f9d55;
  --warn: #c47d0e;
  --radius: 8px;
  --radius-sm: 6px;
  --ring: 0 0 0 3px rgba(45, 108, 223, .14);
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .05);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 13px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
}

:focus-visible { outline: none; }
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: var(--ring);
}

.app {
  display: grid;
  grid-template-columns: 400px 1fr;
  grid-template-rows: minmax(56px, auto) 1fr;
  grid-template-areas: "header header" "sidebar main";
  height: 100vh;
}

header {
  grid-area: header;
  display: flex;
  align-items: center;
  gap: 8px;
  /* zawijanie, żeby przy wąskim oknie przyciski konta (Wyloguj) nie wypadały
     poza ekran — wiersz nagłówka rośnie (grid: minmax(56px, auto)) */
  flex-wrap: wrap;
  row-gap: 6px;
  padding: 8px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  /* NIE ustawiać overflow — `overflow-x:auto` wymusza `overflow-y:auto`,
     co przycinało rozwinięte menu eksportu do wysokości nagłówka */
  overflow: visible;
}
header button { white-space: nowrap; padding: 6px 11px; font-size: 12.5px; }

header h1 {
  font-size: 15px;
  margin: 0;
  font-weight: 700;
  letter-spacing: -.01em;
}
/* 5 kliknięć w logo otwiera tryb deweloperski — bez zaznaczania tekstu */
header h1 { white-space: nowrap; -webkit-user-select: none; user-select: none; }
header .sub { color: var(--muted); font-size: 12px; white-space: nowrap; }
header .spacer { flex: 1; }

button {
  font: inherit;
  cursor: pointer;
  border: 1px solid var(--border-strong);
  background: #fff;
  border-radius: var(--radius-sm);
  padding: 7px 13px;
  color: var(--text);
  font-weight: 500;
  transition: background-color .12s, border-color .12s, box-shadow .12s;
}
button:hover { background: var(--panel-soft); border-color: #c4cbd4; }
button:active { background: #eef0f3; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover { background: var(--accent-dark); border-color: var(--accent-dark); }

/* --- menu eksportu w nagłówku --- */
.menu { position: relative; }
.menu .caret { font-size: 10px; opacity: .7; margin-left: 2px; }
.menu-pop {
  position: absolute; top: calc(100% + 6px); right: 0; z-index: 40;
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(16, 24, 40, .12);
  padding: 4px; min-width: 232px;
  display: flex; flex-direction: column; gap: 1px;
}
.menu-pop[hidden] { display: none; }
.menu-pop button {
  border: none; background: none; border-radius: var(--radius-sm); font-weight: 400;
  text-align: left; padding: 7px 10px; font-size: 12.5px; white-space: nowrap;
}
.menu-pop button:hover { background: var(--accent-soft); color: var(--accent); }

/* --- lewy panel: pasek ikon + zawartość sekcji --- */
.sidebar {
  grid-area: sidebar;
  background: var(--panel);
  border-right: 1px solid var(--border);
  overflow: hidden;
  padding: 0;
  display: flex;
  min-height: 0;
}

.rail {
  flex: 0 0 66px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 8px 6px;
  background: var(--panel-soft);
  border-right: 1px solid var(--border);
  overflow-y: auto;
}
.rail-btn {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  border: 1px solid transparent; background: none; border-radius: var(--radius-sm);
  padding: 8px 2px 6px; color: var(--muted); font-weight: 500;
  font-size: 10px; line-height: 1.1; letter-spacing: .01em;
}
.rail-btn svg {
  width: 20px; height: 20px;
  fill: none; stroke: currentColor; stroke-width: 1.6;
  stroke-linecap: round; stroke-linejoin: round;
}
.rail-btn:hover { background: #eceff3; color: var(--text); }
.rail-btn.active {
  background: var(--accent-soft); border-color: transparent;
  color: var(--accent); font-weight: 600;
}

.sidepanel { flex: 1; min-width: 0; overflow-y: auto; padding: 14px 15px 20px; }
.sec { display: none; }
.sec.active { display: block; }
.sec-title {
  margin: 0 0 12px; font-size: 13.5px; font-weight: 700; letter-spacing: -.01em;
  display: flex; align-items: baseline; gap: 7px;
}
.sec-scope { font-size: 11.5px; font-weight: 400; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

fieldset {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin: 0 0 12px;
  padding: 9px 12px 12px;
}
legend { font-size: 11px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; padding: 0 4px; }

.field { margin-bottom: 8px; }
.field label { display: block; font-size: 11.5px; color: var(--muted); margin-bottom: 3px; }
.field input, .field select {
  width: 100%;
  padding: 6px 8px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font: inherit;
  background: #fff;
}
.row { display: flex; gap: 8px; }
.row .field { flex: 1; }

.main {
  grid-area: main;
  overflow: hidden;
  padding: 0;
  display: flex;
  flex-direction: column;
}

.tabs {
  display: flex;
  gap: 2px;
  padding: 6px 14px 0;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 2;
  overflow-x: auto;
}
.tab {
  border: none;
  background: none;
  padding: 8px 13px;
  margin-bottom: -1px;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  color: var(--muted);
  font-size: 12.5px;
  font-weight: 500;
  white-space: nowrap;
  flex: 0 0 auto;
}
.tab:hover { color: var(--text); background: none; }
.tab.active { color: var(--accent); font-weight: 600; border-bottom-color: var(--accent); background: none; }

.tabpanel { display: none; padding: 16px; }
/* aktywna zakładka wypełnia wysokość — canvas dostaje resztę miejsca */
.tabpanel.active { display: flex; flex-direction: column; flex: 1; min-height: 0; overflow: auto; }

canvas { background: #fff; border: 1px solid var(--border); border-radius: 8px; }
#cabinetCanvas { width: 100%; flex: 1; min-height: 360px; }

.parts-wrap { overflow: auto; border: 1px solid var(--border); border-radius: 8px; background: #fff; }

/* --- edytor rzutu pomieszczenia --- */
.room-wrap { flex: 1; min-height: 360px; display: flex; }
#roomCanvas { width: 100%; flex: 1; min-height: 360px; cursor: crosshair; }
.viewbar button.small:disabled { opacity: .4; cursor: default; }

table.list { border-collapse: collapse; width: 100%; font-size: 12.5px; }
table.list th, table.list td { border: 1px solid var(--border); padding: 6px 8px; text-align: left; }
table.list th { background: var(--panel-soft); font-weight: 600; color: var(--muted); position: sticky; top: 0; }

.legend-holes { display: flex; gap: 16px; flex-wrap: wrap; margin: 10px 0; font-size: 12px; color: var(--muted); }
.legend-holes span { display: inline-flex; align-items: center; gap: 6px; }
.dot { width: 12px; height: 12px; border-radius: 50%; display: inline-block; }

.warnings { color: var(--danger); font-size: 13px; margin: 8px 16px; }

/* --- kontrola kolizji --- */
.badge {
  display: none; margin-left: 6px; padding: 1px 6px; border-radius: 9px;
  font-size: 11px; font-weight: 700; color: #fff; background: var(--danger);
}
.badge.on { display: inline-block; }
.badge.warn { background: #d68910; }

.chk-row {
  display: flex; flex-direction: column; gap: 7px;
  border: 1px solid var(--border); border-left-width: 4px; border-radius: 6px;
  padding: 8px 10px; margin-bottom: 6px; font-size: 13px; background: #fff;
}
.chk-head { display: flex; gap: 10px; align-items: baseline; }
.chk-fix { display: flex; gap: 8px; align-items: center; }
.chk-fix select {
  flex: 0 1 340px; min-width: 0; padding: 4px 6px; font: inherit; font-size: 12px;
  border: 1px solid var(--border); border-radius: 5px; background: #fff;
}
.chk-row.error { border-left-color: var(--danger); }
.chk-row.warning { border-left-color: #d68910; }
.chk-row .chk-part { flex: 0 0 190px; font-weight: 600; }
.chk-row .chk-msg { flex: 1; }
.chk-row .chk-qty { color: var(--muted); white-space: nowrap; }
.chk-ok { color: var(--ok); font-size: 14px; padding: 20px; }
.empty { color: var(--muted); padding: 40px; text-align: center; }

/* --- 3D --- */
#canvas3d { width: 100%; flex: 1; min-height: 360px; display: block; cursor: grab; }
#canvas3d:active { cursor: grabbing; }
.viewbar {
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 8px 0 12px; font-size: 12.5px; color: var(--text);
}
.viewbar label { display: inline-flex; align-items: center; gap: 8px; }
.viewbar input[type=range] { width: 160px; }
.viewbar input[type=color] {
  width: 34px; height: 24px; padding: 1px; cursor: pointer;
  border: 1px solid var(--border); border-radius: 5px; background: #fff;
}
.hint { color: var(--muted); font-size: 11.5px; margin: 4px 0 0; }

button.small { padding: 5px 10px; font-size: 11.5px; border-radius: var(--radius-sm); }

/* --- generator renderu (zakładka Render) --- */
.render-wrap { display: flex; flex: 1; min-height: 0; gap: 14px; }
.render-col { flex: 1; min-width: 0; display: flex; flex-direction: column; margin: 0; }
.render-col figcaption {
  display: flex; align-items: center; gap: 10px;
  font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 6px;
}
.render-box {
  flex: 1; min-height: 320px; display: flex; align-items: center; justify-content: center;
  padding: 10px; overflow: hidden;
  background: var(--panel-soft); border: 1px solid var(--border); border-radius: 10px;
}
.render-box img { max-width: 100%; max-height: 100%; object-fit: contain; border-radius: 6px; display: none; }
.render-box .hint { max-width: 280px; text-align: center; margin: 0; }
@media (max-width: 900px) { .render-wrap { flex-direction: column; } }

/* --- ręczne pozycje zawiasów --- */
.hinge-row { margin-top: 8px; }
.hinge-lab { display: block; font-size: 12px; font-weight: 600; margin-bottom: 4px; }
.hinge-row .row { flex-wrap: wrap; }
.hinge-row .field { flex: 0 0 68px; margin-bottom: 4px; }
.hinge-row .field input { padding: 4px 5px; font-size: 12px; }

/* --- rozkrój i wycena --- */
.viewbar input.tiny {
  width: 68px; padding: 3px 5px; font: inherit; font-size: 12px;
  border: 1px solid var(--border); border-radius: 5px;
}
.nest-sum { display: flex; gap: 10px; flex-wrap: wrap; margin: 6px 0 14px; }
.nest-card {
  flex: 1 1 130px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 8px 10px; background: var(--panel-soft);
}
.nest-card b { display: block; font-size: 16px; font-weight: 700; line-height: 1.3; letter-spacing: -.01em; }
.nest-card span { color: var(--muted); font-size: 11.5px; }
.nest-card.total { background: #eef6f0; border-color: #bcdcc4; }
.nest-group { margin: 18px 0 6px; font-size: 13.5px; font-weight: 700; }
.nest-group small { font-weight: 400; color: var(--muted); }
.nest-boards { display: flex; gap: 14px; flex-wrap: wrap; margin: 10px 0 4px; }
.nest-board { flex: 0 0 320px; margin: 0; }
.nest-board svg { width: 100%; height: auto; border-radius: 4px; background: #fff; }
.nest-board figcaption { font-size: 12px; color: var(--muted); padding-top: 4px; }
.nest-board .half { color: #d68910; font-weight: 600; }
.nest-board .full { color: var(--ok); font-weight: 600; }
.nest-note { color: var(--danger); font-size: 13px; margin: 8px 0; }

/* --- oferta --- */
.offer-wrap { padding: 4px 2px 24px; }
.offer-cols { display: flex; gap: 14px; flex-wrap: wrap; align-items: flex-start; }
.offer-cols fieldset { flex: 1 1 300px; }
.offer-h { margin: 20px 0 4px; font-size: 13.5px; font-weight: 700; }
.offer-items { width: 100%; border-collapse: collapse; margin: 8px 0; font-size: 13px; }
.offer-items th {
  text-align: left; font-size: 11px; color: var(--muted); font-weight: 600;
  border-bottom: 1px solid var(--border); padding: 4px 6px;
}
.offer-items td { padding: 3px 6px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.offer-items input {
  width: 100%; padding: 4px 6px; font: inherit; font-size: 13px;
  border: 1px solid var(--border); border-radius: 5px;
}
.offer-items .num input { text-align: right; }
.offer-items .lp { width: 26px; color: var(--muted); }
.offer-items .val { text-align: right; white-space: nowrap; font-weight: 600; }
.offer-items .qty { width: 70px; }
.offer-items .unit { width: 70px; }
.offer-items .price { width: 110px; }
.offer-items .del {
  border: none; background: none; color: var(--danger);
  cursor: pointer; font-size: 15px; line-height: 1; padding: 0 4px;
}
.logo-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.logo-row img {
  max-width: 150px; max-height: 46px; border: 1px solid var(--border);
  border-radius: 5px; background: #fff; padding: 2px;
}
.offer-tot { margin-top: 10px; font-size: 13px; }
.offer-tot div { display: flex; justify-content: space-between; padding: 2px 0; }
.offer-tot .sum { border-top: 1px solid var(--border); margin-top: 4px; padding-top: 6px;
  font-size: 14px; font-weight: 700; }

/* --- edytor półek --- */
.shelf-row {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px;
  margin-bottom: 8px;
  background: #fafbfc;
}
.shelf-row .sh-head {
  display: flex; align-items: center; justify-content: space-between;
  font-size: 12px; font-weight: 600; margin-bottom: 6px;
}
.shelf-row .sh-del {
  border: none; background: none; color: var(--danger);
  cursor: pointer; font-size: 15px; line-height: 1; padding: 0 4px;
}
.shelf-row .sh-move {
  border: none; background: none; color: var(--muted);
  cursor: pointer; font-size: 13px; line-height: 1; padding: 0 2px;
}
.shelf-row .sh-move:hover { color: var(--accent); background: none; }
.shelf-row select, .shelf-row input {
  width: 100%; padding: 5px 6px; border: 1px solid var(--border);
  border-radius: 5px; font: inherit; font-size: 12px; background: #fff;
}
.shelf-row .sh-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.shelf-row .sh-grid.full { grid-template-columns: 1fr; }
.shelf-row label { display: block; font-size: 11px; color: var(--muted); margin-bottom: 2px; }
.shelf-row.fixed { background: #fff6ec; border-color: #f0c9a0; }
.shelf-row.fit-drawer { background: #eef5fd; border-color: #b8d1ee; }
.shelf-row.fit-divider { background: #f2f0fb; border-color: #cbc4ea; }

/* --- modal eksportu JAF --- */
.modal {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(20, 28, 40, .45);
  display: flex; align-items: center; justify-content: center; padding: 24px;
}
.modal[hidden] { display: none; }
.modal-box {
  background: var(--panel); border-radius: var(--radius); width: min(760px, 100%);
  max-height: 100%; display: flex; flex-direction: column;
  box-shadow: 0 12px 40px rgba(16, 24, 40, .18);
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; border-bottom: 1px solid var(--border);
}
.modal-head h2 { margin: 0; font-size: 14px; font-weight: 700; }
.modal-body { overflow-y: auto; padding: 14px 16px 4px; }

.chk { display: flex; align-items: center; gap: 8px; font-size: 13px; margin-bottom: 6px; cursor: pointer; }
.chk input { width: auto; margin: 0; }

/* --- Asystent AI --- */
button.ai { background: var(--accent); color: #fff; border-color: var(--accent); font-weight: 600; }
button.ai:hover { filter: brightness(1.07); }
.asst-box { width: min(680px, 100%); }
.asst-prompt { width: 100%; box-sizing: border-box; resize: vertical; min-height: 74px; font: inherit;
  padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; }
.asst-chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0 4px; }
.asst-chips[hidden] { display: none; }
.asst-chip { font-size: 12px; padding: 5px 10px; border: 1px solid var(--border); border-radius: 999px;
  background: var(--accent-soft); color: var(--accent); cursor: pointer; text-align: left; line-height: 1.3; }
.asst-chip:hover { background: var(--accent); color: #fff; }
.asst-actions { display: flex; align-items: center; gap: 12px; margin: 10px 0; }
.asst-status { font-size: 12px; color: var(--muted); }
.asst-status.busy::before { content: "⏳ "; }
.asst-status.err { color: var(--danger); }
.asst-result { border: 1px solid var(--border); border-radius: 8px; padding: 12px 14px; margin: 8px 0; background: #fbfaf7; }
.asst-sum { font-weight: 700; margin-bottom: 8px; }
.asst-cab { font-size: 13px; padding: 3px 0; }
.asst-assum { margin-top: 10px; font-size: 12px; color: var(--muted); }
.asst-assum ul { margin: 4px 0 0; padding-left: 18px; }
.asst-assum li { margin: 2px 0; }
.asst-apply { display: flex; gap: 10px; align-items: center; margin: 4px 0 8px; }

/* --- Asystent AI: czat --- */
.asst-chat { display: flex; flex-direction: column; min-height: 0; }
.asst-thread { flex: 1 1 auto; min-height: 260px; max-height: 52vh; overflow-y: auto;
  display: flex; flex-direction: column; gap: 10px; padding: 6px 2px; }
.asst-thread:empty { min-height: 0; }
.asst-msg { max-width: 86%; padding: 9px 12px; border-radius: 12px; font-size: 13px; line-height: 1.4;
  white-space: pre-wrap; word-wrap: break-word; }
.asst-msg.user { align-self: flex-end; background: var(--accent); color: #fff; border-bottom-right-radius: 4px; }
.asst-msg.ai { align-self: flex-start; background: #fbfaf7; border: 1px solid var(--border);
  border-bottom-left-radius: 4px; }
.asst-msg .asst-sum { font-weight: 700; margin-bottom: 6px; }
.asst-msg .asst-cab { font-size: 12.5px; padding: 2px 0; }
.asst-msg .asst-applied { margin-top: 8px; font-size: 12px; font-weight: 600; color: var(--accent); }
.asst-input { display: flex; gap: 8px; align-items: flex-end; margin-top: 8px; }
.asst-input .asst-prompt { min-height: 42px; }
.asst-input .primary { flex: 0 0 auto; align-self: stretch; }

/* --- modal edycji formatki 2D --- */
.pm-box { width: min(1040px, 100%); }
.modal-head .muted { margin-left: auto; margin-right: 12px; font-size: 12px; color: var(--muted); }
.pm-body { display: flex; gap: 14px; align-items: stretch; }
.pm-left { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: 10px; }
.pm-draw { flex: 1 1 auto; min-width: 0; display: flex; align-items: center; justify-content: center;
  background: #fbfaf7; border: 1px solid var(--border); border-radius: 8px; padding: 10px; overflow: hidden; }
.pm-draw svg { width: 100%; height: auto; max-height: 68vh; }
/* legenda oznaczeń rysunku — kolory otworów/frezów/okleiny */
.pm-legend { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 4px 12px;
  font-size: 11.5px; color: var(--fg); max-height: 132px; overflow-y: auto; }
.pm-legend .pm-lg-item { display: flex; align-items: flex-start; gap: 6px; min-width: 0; line-height: 1.35; }
.pm-legend .pm-lg-mark { flex: 0 0 auto; width: 12px; height: 12px; border-radius: 50%; margin-top: 2px; }
.pm-legend .pm-lg-mark.groove { border-radius: 2px; }
.pm-legend .pm-lg-mark.edge { height: 4px; border-radius: 2px; }
.pm-legend .pm-lg-mark.other { opacity: 0.4; border: 1px dashed var(--border-strong); }
.pm-legend .pm-lg-txt { min-width: 0; }
.pm-legend .pm-lg-txt b { font-weight: 600; }
.pm-legend .pm-lg-txt span { color: var(--muted); }
.pm-legend .pm-lg-empty { grid-column: 1 / -1; color: var(--muted); }
.pm-side { flex: 0 0 260px; display: flex; flex-direction: column; gap: 10px; }
.pm-ctrls { display: flex; flex-direction: column; gap: 10px; overflow-y: auto; max-height: 60vh; }
.pm-jrow { display: flex; flex-direction: column; gap: 3px; font-size: 12px; }
.pm-jrow .pm-jlab { display: flex; justify-content: space-between; color: var(--muted); }
.pm-jrow input[type=range] { width: 100%; margin: 0; }
.pm-jrow input[type=number] { width: 74px; }
.pm-actions { margin-top: auto; }
.pm-grp { display: flex; flex-direction: column; gap: 8px; padding-top: 8px; border-top: 1px solid var(--border); }
.pm-grp:first-child { border-top: 0; padding-top: 0; }
.pm-gact { display: flex; justify-content: flex-end; }
.pm-gact button { font-size: 11px; }
.pm-cnt { display: flex; justify-content: space-between; align-items: center; font-size: 12px; font-weight: 600; color: var(--fg); }
.pm-cnt-btns { display: flex; gap: 4px; }
.pm-cnt-btns button { width: 26px; padding: 2px 0; font-size: 14px; line-height: 1; }
.pm-cnt-btns button:disabled { opacity: 0.4; cursor: default; }
.pm-conn { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 12px; }
.pm-conn > span { color: var(--muted); white-space: nowrap; }
.pm-conn select { flex: 1 1 auto; min-width: 0; }
.pm-hole-drag { cursor: ns-resize; }
.pm-hole-drag:hover circle { stroke-width: 2; }

.jaf-edges { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 10px; }
.jaf-edges .field { margin-bottom: 0; }
.jaf-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.jaf-preview { max-height: 220px; overflow: auto; border: 1px solid var(--border); border-radius: 6px; }
.jaf-preview table { border-collapse: collapse; width: 100%; font-size: 11.5px; }
.jaf-preview th, .jaf-preview td { border: 1px solid var(--border); padding: 3px 6px; text-align: left; white-space: nowrap; }
.jaf-preview th { background: #f0f2f5; position: sticky; top: 0; }

/* --- lista korpusów --- */
.cab-row {
  display: flex; align-items: center; gap: 8px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 6px 9px; margin-bottom: 5px; cursor: pointer;
  font-size: 12px; background: var(--panel-soft);
  transition: background-color .12s, border-color .12s;
}
.cab-row:hover { background: #eceff3; }
.cab-row.active { border-color: var(--accent); background: var(--accent-soft); font-weight: 600; }
.cab-row .cab-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cab-row .cab-dim { color: var(--muted); font-weight: 400; }

/* zawsze widoczny przełącznik modyfikowanego korpusu (u góry panelu) */
.cab-switch {
  position: sticky; top: -14px; z-index: 5;
  margin: -14px -15px 12px; padding: 8px 15px;
  background: var(--accent-soft); border-bottom: 1px solid var(--border);
}
.cab-switch .cs-lab { display: block; font-size: 10px; letter-spacing: .04em;
  text-transform: uppercase; color: var(--muted); margin-bottom: 4px; }
.cab-switch .cs-row { display: flex; align-items: center; gap: 6px; }
.cab-switch select { flex: 1; min-width: 0; font-weight: 600; }
.cab-switch button.small { padding: 4px 10px; font-size: 15px; line-height: 1; }
.cab-switch button.small:disabled { opacity: .4; cursor: default; }

/* --- konta i chmura --- */
.acct { display: inline-flex; align-items: center; }
.user-chip { display: inline-flex; align-items: center; gap: 8px; }
.user-name { font-size: 13px; font-weight: 600; color: var(--text); max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
button.link { background: none; border: 0; color: var(--accent); cursor: pointer; padding: 0; font: inherit; }
button.link:hover { text-decoration: underline; }
button.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
button.danger:hover { background: #a5281a; border-color: #a5281a; }

/* --- ekran logowania (pełnoekranowy split z tłem) --- */
body.auth-open { overflow: hidden; }
.auth-cover {
  position: fixed; inset: 0; z-index: 60;
  display: flex; background: var(--panel);
}
.auth-cover[hidden] { display: none; }
.auth-visual {
  flex: 1 1 55%; position: relative;
  background-size: cover; background-position: center;
  display: flex; align-items: flex-end;
}
.auth-visual::after {
  content: ''; position: absolute; inset: 0;
  background: linear-gradient(180deg, rgba(15,23,42,.30) 0%, rgba(15,23,42,.62) 100%);
}
.auth-brand { position: relative; z-index: 1; padding: 48px; color: #fff; max-width: 540px; }
.auth-logo {
  font-size: 30px; font-weight: 800; letter-spacing: -.02em;
  color: #fff; margin-bottom: 14px;
}
.auth-logo-sm { color: var(--accent); font-size: 22px; margin-bottom: 8px; }
.auth-tagline { font-size: 17px; line-height: 1.5; margin: 0 0 20px; opacity: .95; }
.auth-points { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 10px; }
.auth-points li { position: relative; padding-left: 26px; font-size: 14.5px; opacity: .95; }
.auth-points li::before {
  content: '✓'; position: absolute; left: 0; top: -1px;
  width: 18px; height: 18px; border-radius: 50%;
  background: var(--accent); color: #fff; font-size: 11px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
}
.auth-panel {
  flex: 0 0 460px; max-width: 460px; position: relative;
  display: flex; align-items: center; justify-content: center;
  padding: 32px; overflow-y: auto;
}
.auth-x {
  position: absolute; top: 16px; right: 18px;
  background: none; border: 0; font-size: 26px; line-height: 1;
  color: var(--muted); cursor: pointer; padding: 4px 8px;
}
.auth-x:hover { color: var(--text); background: none; }
.auth-card { width: 100%; max-width: 340px; }
.auth-card h2 { margin: 0 0 6px; font-size: 24px; }
.auth-note { color: var(--muted); font-size: 13.5px; margin: 0 0 20px; line-height: 1.45; }
.auth-form { display: flex; flex-direction: column; gap: 14px; }
.auth-row { display: flex; flex-direction: column; gap: 5px; }
.auth-row[hidden], .auth-consent[hidden] { display: none; }
.auth-row > span { font-size: 12px; font-weight: 600; color: var(--muted); }
.auth-row input {
  padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px;
  font-size: 14px; transition: border-color .15s, box-shadow .15s;
}
.auth-row input:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(45,108,223,.15);
}
.auth-consent {
  display: flex; align-items: flex-start; gap: 9px;
  font-size: 12.5px; color: var(--muted); line-height: 1.45; cursor: pointer;
}
.auth-consent input { width: auto; margin: 2px 0 0; flex: 0 0 auto; }
.auth-consent a { color: var(--accent); }
.auth-err { color: var(--danger); font-size: 12.5px; margin: 0; }
.auth-err.ok { color: var(--ok); }
.auth-submit { width: 100%; padding: 11px; font-size: 14.5px; font-weight: 600; border-radius: 8px; }
.auth-links { display: flex; flex-direction: column; gap: 8px; margin-top: 18px; font-size: 13px; }
.auth-links button.link { text-align: left; }
.auth-legal {
  margin: 22px 0 0; font-size: 11.5px; color: var(--muted);
  border-top: 1px solid var(--border); padding-top: 14px;
}
.auth-legal a { color: var(--muted); }
.auth-legal a:hover { color: var(--accent); }
@media (max-width: 820px) {
  .auth-visual { display: none; }
  .auth-panel { flex: 1 1 100%; max-width: none; }
}

/* --- modal informacji prawnych --- */
#legalModal { z-index: 70; }   /* nad ekranem logowania (auth-cover: 60) */
.legal-box { width: min(720px, 100%); }
.legal-body { display: flex; flex-direction: column; gap: 0; padding: 0; }
.legal-tabs {
  display: flex; flex-wrap: wrap; gap: 4px;
  padding: 10px 16px; border-bottom: 1px solid var(--border);
  position: sticky; top: 0; background: var(--panel); z-index: 1;
}
.legal-tab {
  padding: 6px 12px; font-size: 12.5px; border-radius: 6px;
  border: 1px solid transparent; background: none; color: var(--muted); cursor: pointer;
}
.legal-tab:hover { background: #f0f2f5; color: var(--text); }
.legal-tab.active { background: #eaf1fd; border-color: var(--accent); color: var(--accent); font-weight: 600; }
.legal-content { padding: 16px 20px 20px; max-height: 62vh; overflow-y: auto; font-size: 13.5px; line-height: 1.6; color: var(--text); }
.legal-content h3 { font-size: 14.5px; margin: 18px 0 6px; }
.legal-content h3:first-child { margin-top: 0; }
.legal-content p { margin: 0 0 8px; }
.legal-content ul { margin: 0 0 10px; padding-left: 20px; }
.legal-content li { margin-bottom: 4px; }
.legal-content .lg-upd { color: var(--muted); font-size: 12px; margin-bottom: 14px; }

/* --- baner cookie --- */
.cookie-bar {
  position: fixed; left: 16px; right: 16px; bottom: 16px; z-index: 55;
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  background: var(--panel); border: 1px solid var(--border); border-radius: 10px;
  padding: 12px 16px; box-shadow: 0 10px 30px rgba(0,0,0,.16);
  max-width: 720px; margin: 0 auto;
}
.cookie-bar[hidden] { display: none; }
.cookie-text { flex: 1 1 320px; margin: 0; font-size: 12.5px; line-height: 1.5; color: var(--muted); }
.cookie-text a { color: var(--accent); }
.cookie-act { display: flex; align-items: center; gap: 12px; }
.cookie-link { font-size: 12px; color: var(--muted); }
.cookie-link:hover { color: var(--accent); }

/* ---------- chmura: przycisk w nagłówku + galeria projektów ---------- */
header button.cloud {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--accent-soft); border-color: #bcd2f4; color: var(--accent-dark); font-weight: 600;
}
header button.cloud:hover { background: #e2ecfb; border-color: var(--accent); }
header button.cloud svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.7; }
header #btnCloudSave.ok { background: var(--ok); border-color: var(--ok); color: #fff; }
header #btnCloudSave.err { background: var(--danger); border-color: var(--danger); color: #fff; }

.cloud-box { width: min(1180px, 96vw); max-width: none; height: min(86vh, 900px); }
.cloud-head { align-items: flex-start; gap: 16px; padding: 14px 18px; }
.cloud-title { display: flex; align-items: center; gap: 12px; min-width: 0; }
.cloud-title svg { width: 30px; height: 30px; flex: 0 0 auto; fill: none; stroke: var(--accent); stroke-width: 1.5; }
.cloud-title h2 { font-size: 16px; }
.cloud-cur { margin: 2px 0 0; font-size: 12px; color: var(--muted); }
.cloud-tools { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.cloud-tools input[type="search"] { width: 210px; padding: 6px 10px; font-size: 12.5px; }
.cloud-tools select { width: auto; padding: 6px 8px; font-size: 12.5px; }
.cloud-body { flex: 1; min-height: 0; display: flex; flex-direction: column; padding: 12px 18px; background: var(--bg); }
.cloud-msg { font-size: 12.5px; color: var(--muted); min-height: 16px; margin: 0 0 8px; }
.cloud-msg.err { color: var(--danger); }
.cloud-msg.ok { color: var(--ok); }
.cloud-foot { display: flex; align-items: center; gap: 10px; padding: 12px 18px; border-top: 1px solid var(--border); }
.cloud-foot .spacer { flex: 1; }
.cloud-count { font-size: 12px; }

.cloud-grid {
  flex: 1; min-height: 0; overflow: auto; align-content: start;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 16px; padding-bottom: 4px;
}
.cloud-card {
  border: 1px solid var(--border); border-radius: 10px; overflow: hidden; background: var(--panel);
  display: flex; flex-direction: column; cursor: pointer; outline: none;
  box-shadow: var(--shadow-sm); transition: box-shadow .14s, border-color .14s, transform .14s;
}
.cloud-card:hover, .cloud-card:focus-visible { border-color: var(--accent); box-shadow: 0 8px 22px rgba(16, 24, 40, .13); transform: translateY(-2px); }
.cloud-card.current { border-color: var(--accent); box-shadow: var(--ring); }
/* stała wysokość, nie aspect-ratio — miniatury 3D bywają pionowe i rozpychały kafelek */
.cloud-thumb { position: relative; width: 100%; height: 172px; overflow: hidden; background: #eef1f4; display: block; }
/* contain, nie cover — kafelek pokazuje CAŁY mebel (miniatury bywają pionowe) */
.cloud-thumb img { width: 100%; height: 100%; object-fit: contain; display: block; padding: 6px; }
.cloud-noimg { width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: 12px; }
.cloud-hover {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  background: rgba(20, 28, 40, .38); opacity: 0; transition: opacity .14s;
}
.cloud-card:hover .cloud-hover, .cloud-card:focus-visible .cloud-hover { opacity: 1; }
.cloud-open { background: #fff; color: var(--accent-dark); font-weight: 600; font-size: 12.5px; padding: 7px 16px; border-radius: 999px; }
.cloud-badge {
  position: absolute; top: 8px; left: 8px; background: var(--accent); color: #fff;
  font-size: 10.5px; font-weight: 600; padding: 2px 8px; border-radius: 999px; letter-spacing: .02em;
}
.cloud-meta { padding: 10px 12px 6px; display: flex; flex-direction: column; gap: 2px; }
.cloud-name { font-size: 13.5px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cloud-date { font-size: 11.5px; color: var(--muted); }
.cloud-card-act { display: flex; gap: 6px; padding: 0 12px 10px; }
.cloud-card-act button { flex: 1; font-size: 11.5px; padding: 5px 6px; background: var(--panel-soft); }
/* „Usuń" ma być dostępne, ale nie krzyczeć z każdego kafelka — czerwień na hover */
.cloud-card-act button.danger { background: var(--panel-soft); border-color: var(--border-strong); color: var(--muted); }
.cloud-card-act button.danger:hover { background: var(--danger); border-color: var(--danger); color: #fff; }
.cloud-empty { grid-column: 1 / -1; color: var(--muted); font-size: 13px; text-align: center; line-height: 1.7; padding: 48px 0; }

/* ---------- samouczek (tutorial.js) ---------- */
#tutRoot[hidden] { display: none; }
.tut-block { position: fixed; inset: 0; z-index: 4000; background: transparent; }
.tut-mask {
  position: fixed; z-index: 4001; display: none; border-radius: 8px;
  pointer-events: none; box-shadow: 0 0 0 9999px rgba(16, 24, 40, .55);
  transition: left .18s ease, top .18s ease, width .18s ease, height .18s ease;
  outline: 2px solid var(--accent); outline-offset: 0;
}
.tut-tip {
  position: fixed; z-index: 4002; width: 320px; max-width: calc(100vw - 24px);
  background: var(--panel); border: 1px solid var(--border-strong); border-radius: var(--radius);
  box-shadow: 0 14px 44px rgba(16, 24, 40, .24); padding: 14px 16px;
  transition: left .18s ease, top .18s ease;
}
.tut-step { font-size: 11px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--accent); }
.tut-title { margin: 4px 0 6px; font-size: 15px; font-weight: 700; color: var(--text); }
.tut-text { font-size: 12.5px; line-height: 1.55; color: var(--muted); }
.tut-text b { color: var(--text); font-weight: 600; }
.tut-nav { display: flex; align-items: center; gap: 8px; margin-top: 14px; }
.tut-spacer { flex: 1; }
.tut-act { margin-top: 12px; }
.tut-act[hidden] { display: none; }
.tut-act .tut-apply { width: 100%; }
.tut-nav .tut-sketch[hidden] { display: none; }

.tut-modal { position: fixed; inset: 0; z-index: 4100; display: flex; align-items: center; justify-content: center;
  background: rgba(16, 24, 40, .5); padding: 20px; }
.tut-card { width: 460px; max-width: 100%; background: var(--panel); border: 1px solid var(--border-strong);
  border-radius: var(--radius); box-shadow: 0 20px 60px rgba(16, 24, 40, .3); padding: 22px 24px; }
.tut-card.wide { width: 720px; }
.tut-card h2 { margin: 0 0 10px; font-size: 19px; font-weight: 700; color: var(--text); }
/* szkic od klienta — cały rysunek widoczny, bez kadrowania */
.tut-sketch-wrap { margin: 0 0 12px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  overflow: hidden; background: #fff; }
.tut-sketch-wrap img { display: block; width: 100%; max-height: 46vh; object-fit: contain; }
.tut-lead { font-size: 13.5px; line-height: 1.6; color: var(--text); margin: 0 0 12px; }
.tut-lead strong { color: var(--accent-dark); }
.tut-note { font-size: 12px; line-height: 1.5; color: var(--muted); margin: 10px 0 0; }
.tut-form { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 12px; margin: 6px 0 4px; }
.tut-form label { display: flex; flex-direction: column; gap: 4px; font-size: 11.5px; color: var(--muted); }
.tut-form label:first-child { grid-column: 1 / -1; }
.tut-form input { padding: 7px 9px; font-size: 13px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); }

#btnTutorial { width: 30px; padding: 0; font-weight: 700; }

/* zadania praktyczne — pływający panel w rogu (nie blokuje aplikacji) */
.tut-quest { position: fixed; right: 18px; bottom: 18px; z-index: 4050; width: 320px; max-width: calc(100vw - 36px);
  background: var(--panel); border: 1px solid var(--border-strong); border-radius: var(--radius);
  box-shadow: 0 16px 48px rgba(16, 24, 40, .28); padding: 12px 14px; }
.tut-quest[hidden] { display: none; }
.tq-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.tq-title { flex: 1; font-size: 13px; font-weight: 700; color: var(--text); }
.tq-close { width: 24px; height: 24px; padding: 0; line-height: 1; font-size: 16px; border: 1px solid var(--border);
  background: var(--panel); border-radius: var(--radius-sm); cursor: pointer; color: var(--muted); }
.tq-list { list-style: none; margin: 0 0 8px; padding: 0; display: flex; flex-direction: column; gap: 3px; }
.tq-list li { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted);
  padding: 3px 4px; border-radius: var(--radius-sm); }
.tq-list li.cur { color: var(--text); font-weight: 600; background: var(--accent-soft, rgba(43, 108, 240, .08)); }
.tq-list li.done { color: var(--muted); }
.tq-list li.done .tq-mark { background: #2e9e5b; border-color: #2e9e5b; color: #fff; }
.tq-mark { flex: 0 0 auto; width: 18px; height: 18px; display: inline-flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 700; border: 1px solid var(--border-strong); border-radius: 50%; color: var(--muted); }
.tq-list li.cur .tq-mark { border-color: var(--accent); color: var(--accent); }
.tq-cur { border-top: 1px solid var(--border); padding-top: 8px; }
.tq-cur-text { font-size: 12.5px; line-height: 1.5; color: var(--text); }
.tq-cur-text b { font-weight: 600; }
.tq-foot { display: flex; align-items: center; gap: 8px; margin-top: 10px; }
.tq-prog { flex: 1; font-size: 11px; color: var(--muted); }
