/* Style funkcji (edytor, rysunek, rozkrój, wycena) ponad Pico CSS i ui.css (wygląd, układ). */

/* Bez kotwiczenia przewijania: po podmianie fragmentu przez HTMX przeglądarka potrafiła
   „gonić” zniknięty element i przeskakiwać na dół lub górę strony */
html {
  overflow-anchor: none;
}

.flash-messages {
  position: fixed;
  bottom: 1rem;
  right: 1rem;
  z-index: 10;
  max-width: min(24rem, calc(100vw - 2rem));
  animation: flash-hide 0.4s ease 5s forwards;
}

.flash-messages .notice {
  margin: 0 0 0.5rem;
  box-shadow: var(--pico-card-box-shadow);
}

@keyframes flash-hide {
  to {
    opacity: 0;
    visibility: hidden;
  }
}

/* Wydruk (raport dla szefa): bez menu i przycisków */
@media print {
  .app {
    display: block;
  }

  .no-print,
  .flash-messages {
    display: none !important;
  }

  article {
    box-shadow: none;
    break-inside: avoid;
  }
}

/* Liczby w jednej linii; nazwy (pierwsza kolumna) się zawijają, także na wydruku */
.report-table td {
  white-space: nowrap;
}

.report-table tr.total th,
.report-table tr.total td {
  font-weight: 700;
}

.ok {
  color: var(--pico-ins-color);
}

/* --- Edytor kształtu --- */

.bad {
  color: var(--pico-del-color);
}

.muted {
  color: var(--pico-muted-color);
}

.check {
  display: block;
  min-height: 1.2em;
  margin-top: -0.6rem;
  margin-bottom: 0.4rem;
  color: var(--pico-muted-color);
}

.check.bad {
  color: var(--pico-del-color);
}

.shape-table input {
  margin-bottom: 0.5rem;
  min-width: 6rem;
}

.shape-table th[scope="row"] {
  font-weight: 700;
  width: 1%;
}

.shape-table .cell {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.shape-table .side-name {
  min-width: 1.8rem;
  color: var(--pico-muted-color);
  font-size: 0.85em;
}

.actions,
.examples {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

.actions button,
.examples button,
details button {
  width: auto;
  margin-bottom: 0;
  padding: 0.35rem 0.8rem;
  font-size: 0.9em;
}

details {
  margin-block: 1rem;
}

.diagonal {
  margin-bottom: 0.25rem;
}

@media (max-width: 575px) {
  .shape-table input {
    min-width: 3.5rem;
  }

  .shape-table th,
  .shape-table td {
    padding-inline: 0.3rem;
  }
}

/* --- Podgląd kształtu (SVG) --- */

.shape-preview {
  display: block;
  width: 100%;
  max-height: 60vh;
}

.shape-preview .outline {
  fill: var(--pico-primary-background);
  fill-opacity: 0.08;
  stroke: var(--pico-primary);
  stroke-width: 2;
  stroke-linejoin: round;
}

.shape-preview .diagonal-line {
  stroke: var(--pico-muted-color);
  stroke-width: 1;
  stroke-dasharray: 6 4;
}

/* Kolor etykiet ustalony na poziomie rysunku: Pico zmienia --pico-color w elementach
   z role="button" (biały tekst przycisku), więc etykieta nie może go czytać u siebie. */
.shape-preview {
  --label-color: var(--pico-color);
}

.shape-preview text {
  fill: var(--label-color);
  text-anchor: middle;
  dominant-baseline: central;
}

/* Etykiety wymiarów mają role="button" (obsługa klawiatury), a Pico nadaje takim elementom
   styl przycisku, w tym własny rozmiar czcionki. Przywracamy rozmiar z rysunku. */
.shape-preview .dim {
  font-size: 1em;
}

.shape-preview .ang {
  fill: var(--pico-muted-color);
  font-size: 0.85em;
}

.shape-preview .vtx {
  font-weight: 700;
}

.shape-preview .computed {
  fill: var(--pico-muted-color);
  font-style: italic;
}

.shape-preview .bad {
  fill: var(--pico-del-color);
  font-weight: 700;
}

.legend {
  color: var(--pico-muted-color);
  margin-bottom: 0.5rem;
}

/* --- Powiększanie i przesuwanie rysunków (zoom.js) --- */

.zoom-box {
  position: relative;
}

.zoom-tools {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 0.35rem;
  margin-bottom: 0.35rem;
}

.zoom-tools button.small {
  min-width: 2.2rem;
}

.zoom-hint {
  margin-right: auto;
  color: var(--pico-muted-color);
  font-size: 0.75em;
}

.zoom-level {
  min-width: 3rem;
  text-align: center;
  color: var(--pico-muted-color);
}

.shape-preview {
  touch-action: pan-y; /* jeden palec przewija stronę, dwa palce powiększają rysunek */
}

/* Także po powiększeniu: jeden palec przewija stronę, rysunek przesuwają dwa palce (zoom.js) */
.shape-preview.zoomed {
  cursor: grab;
}

.zoom-box:fullscreen {
  display: flex;
  flex-direction: column;
  padding: 1rem;
  background: var(--pico-background-color);
}

.zoom-box:fullscreen > svg {
  flex: 1;
  min-height: 0;
  max-height: none;
  width: 100%;
  height: 100%;
}

/* --- Szkic myszą --- */

.sketch {
  display: block;
  width: 100%;
  aspect-ratio: 48 / 30;
  border: 1px solid var(--pico-muted-border-color);
  border-radius: var(--pico-border-radius);
  background: var(--pico-background-color);
  cursor: crosshair;
  touch-action: none; /* palec na tablecie rysuje zamiast przewijać */
  user-select: none;
}

.sketch .grid-line {
  fill: none;
  stroke: var(--pico-muted-color);
  stroke-opacity: 0.25;
  stroke-width: 0.04;
}

.sketch .grid-line.major {
  stroke-opacity: 0.45;
  stroke-width: 0.07;
}

.sketch .sketch-path,
.sketch .sketch-shape,
.sketch .sketch-rubber {
  fill: none;
  stroke: var(--pico-primary);
  stroke-width: 0.12;
  stroke-linejoin: round;
}

.sketch .sketch-shape {
  fill: var(--pico-primary-background);
  fill-opacity: 0.1;
}

.sketch .sketch-rubber {
  stroke-dasharray: 0.3 0.2;
}

.sketch circle {
  fill: var(--pico-primary);
}

.sketch circle.start {
  fill: var(--pico-background-color);
  stroke: var(--pico-primary);
  stroke-width: 0.12;
}

.sketch .sketch-len {
  font-size: 1px;
  text-anchor: middle;
  fill: var(--pico-color);
}

.sketch-actions .cell-size {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  margin: 0;
}

.sketch-actions .cell-size input {
  width: 5rem;
  margin: 0;
  padding: 0.3rem 0.5rem;
}

.notice {
  padding: 0.5rem 0.75rem;
  border-left: 3px solid var(--pico-primary);
  background: var(--pico-card-sectioning-background-color);
}

.shape-preview [data-focus] {
  cursor: pointer;
}

/* --- Import z rysunku: obrysy znalezione w pliku --- */

.import-candidates {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.import-candidates button {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 11rem;
  padding: 0.4rem;
}

.import-candidates svg {
  width: 100%;
  height: 4rem;
}

.import-candidates polygon {
  fill: none;
  stroke: currentColor;
  stroke-width: 1.5;
  vector-effect: non-scaling-stroke;
}

/* --- Wycieraczka: profile na podglądzie i lista cięć --- */

.shape-preview .outline.with-mat {
  fill: none;
}

.shape-preview .mat {
  fill: none;
  stroke: var(--pico-muted-color);
  stroke-width: 1;
  stroke-dasharray: 5 3;
}

.shape-preview .profile {
  fill: var(--pico-primary-background);
  fill-opacity: 0.18;
  stroke: var(--pico-primary);
  stroke-width: 0.6;
}

/* Wkłady mieszane: pierwszy wkład z cennika w kolorze profili, kolejne wyróżnione
   (klasy insert-c1 … insert-c5 wg kolejności w cenniku, web/mat.py insert_css) */
.shape-preview .profile.insert-c1,
.insert-swatch.insert-c1 {
  fill: #c98a1a;
  background: #c98a1a;
}

.shape-preview .profile.insert-c2,
.insert-swatch.insert-c2 {
  fill: #2f9e5b;
  background: #2f9e5b;
}

.shape-preview .profile.insert-c3,
.insert-swatch.insert-c3 {
  fill: #8a5cc2;
  background: #8a5cc2;
}

.shape-preview .profile.insert-c4,
.insert-swatch.insert-c4 {
  fill: #c4473a;
  background: #c4473a;
}

.shape-preview .profile.insert-c5,
.insert-swatch.insert-c5 {
  fill: #1f8fa3;
  background: #1f8fa3;
}

.shape-preview .profile.insert-c1,
.shape-preview .profile.insert-c2,
.shape-preview .profile.insert-c3,
.shape-preview .profile.insert-c4,
.shape-preview .profile.insert-c5 {
  fill-opacity: 0.35;
}

.insert-swatch {
  display: inline-block;
  width: 0.9em;
  height: 0.9em;
  vertical-align: -0.1em;
  border: 1px solid var(--pico-primary);
  background: var(--pico-primary-background);
  opacity: 0.6;
}

.shape-preview .profile-no {
  fill: var(--pico-primary);
  font-weight: 600;
  paint-order: stroke;
  stroke: var(--pico-background-color);
  stroke-width: 6;
  pointer-events: none;
}

/* Segmenty montażowe (#24): ramka wokół grupy rzędów i oznaczenie S1, S2… */
.shape-preview .segment {
  fill: none;
  stroke: #c98a1a;
  stroke-width: 2;
  stroke-dasharray: 8 4;
  pointer-events: none;
}

.shape-preview .segment-no {
  fill: #a06a0c;
  font-weight: 700;
  text-anchor: middle;
  dominant-baseline: middle;
  paint-order: stroke;
  stroke: var(--pico-background-color);
  stroke-width: 6;
  pointer-events: none;
}

.shape-preview .walk-arrow {
  stroke: var(--pico-del-color);
  stroke-width: 2.5;
}

.shape-preview .arrow-head {
  fill: var(--pico-del-color);
}

.mat-settings {
  margin-top: 1rem;
}

.mat-settings label {
  margin-bottom: 0.5rem;
}

.cut-table td,
.cut-table th {
  white-space: nowrap;
}

.variants tr.current td {
  font-weight: 700;
}

.piece-icon {
  width: 4rem;
  height: 1rem;
  vertical-align: middle;
}

.piece-icon polygon {
  fill: var(--pico-primary-background);
  fill-opacity: 0.25;
  stroke: var(--pico-primary);
  stroke-width: 1.5;
}

/* --- Projekty --- */

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

.filters input[type="search"] {
  flex: 1 1 16rem;
  margin: 0;
}

.filters select,
.filters button,
.filters [role="button"] {
  width: auto;
  margin: 0;
}

.status {
  display: inline-block;
  padding: 0.05rem 0.5rem;
  border-radius: 1rem;
  font-size: 0.85em;
  background: var(--pico-card-sectioning-background-color);
  border: 1px solid var(--pico-muted-border-color);
}

.status-zamowiony,
.status-w_produkcji {
  border-color: var(--pico-primary);
  color: var(--pico-primary);
}

.status-wydany {
  border-color: var(--pico-ins-color);
  color: var(--pico-ins-color);
}

.status-anulowany {
  color: var(--pico-muted-color);
  text-decoration: line-through;
}

.save-bar input {
  font-weight: 600;
}

button.small {
  padding: 0.15rem 0.5rem;
  margin: 0;
  width: auto;
}

.files {
  list-style: none;
  padding: 0;
}

.files li {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.files form {
  margin: 0;
}

.notes {
  white-space: pre-line;
}

.status-form select {
  margin: 0;
}

/* --- Logowanie --- */

.login {
  max-width: 24rem;
  margin: 3rem auto;
}

.logout {
  margin: 0;
}

/* --- Rama z kątownika --- */

.shape-preview .frame-band {
  fill: var(--pico-muted-color);
  fill-opacity: 0.25;
  stroke: var(--pico-muted-color);
  stroke-width: 0.6;
}



/* --- Rozkrój belek --- */

.bars {
  list-style: none;
  padding: 0;
}

.bars li {
  margin-bottom: 1rem;
}

.bar-head {
  display: flex;
  gap: 0.75rem;
  align-items: baseline;
}

.bar {
  display: flex;
  height: 1.6rem;
  border: 1px solid var(--pico-muted-border-color);
  border-radius: 0.3rem;
  overflow: hidden;
  margin: 0.25rem 0;
}

.bar-part {
  flex-grow: 0;
  flex-shrink: 0;
  background: var(--pico-primary-background);
  color: var(--pico-primary-inverse);
  border-right: 2px solid var(--pico-background-color);
  font-size: 0.75rem;
  line-height: 1.6rem;
  text-align: center;
  overflow: hidden;
  white-space: nowrap;
}

.bar-waste {
  flex-grow: 0;
  flex-shrink: 0;
  background: repeating-linear-gradient(
    45deg,
    var(--pico-muted-border-color) 0 4px,
    transparent 4px 8px
  );
}

.bar-list {
  display: block;
  line-height: 1.4;
}

/* --- Cennik --- */

.pricing-table input[type="text"] {
  margin-bottom: 0;
  min-width: 6rem;
  max-width: 10rem;
  padding-block: 0.22rem;
}

.pricing-table td,
.pricing-table th {
  padding-block: 0.35rem;
}

.pricing-add {
  margin: 0.9rem 0 0;
}

.pricing-add [role="group"] {
  margin-bottom: 0;
}

.pricing-add button {
  white-space: nowrap;
  flex: none;
  width: auto;
}

.price-item input {
  max-width: 12rem;
}

.pricing-table input.narrow,
.pricing-add input.narrow {
  max-width: 7rem;
}

.pricing-table tr.muted td,
.pricing-table tr.muted th {
  opacity: 0.6;
}

/* --- Edytor w układzie CAD: parametry po lewej, rysunek i lista cięć po prawej --- */

.cad-page .content {
  padding: 0;
}

.cad {
  display: grid;
  grid-template-columns: 400px minmax(0, 1fr);
  height: 100vh;
}

.cad-params {
  display: flex;
  flex-direction: column;
  min-height: 0;
  margin: 0;
  background: var(--ui-surface);
  border-right: 1px solid var(--ui-line);
}

.params-head {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.85rem 1rem 0.75rem;
  border-bottom: 1px solid var(--ui-line);
}

.params-head h1 {
  --pico-font-size: 1.15rem;
}

.params-head .sub {
  margin: 0.1rem 0 0;
  color: var(--ui-muted);
  font-size: 0.85rem;
}

.params-head .back {
  flex: none;
  width: 1.8rem;
  height: 1.8rem;
  display: grid;
  place-items: center;
  border: 1px solid var(--ui-line);
  border-radius: 50%;
  color: var(--ui-muted);
  text-decoration: none;
}

.params-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}

.params-body > .notice {
  margin: 0.75rem 1rem 0;
}

.cad-params details.sec {
  margin: 0;
  border-bottom: 1px solid var(--ui-line);
}

.cad-params details.sec > summary {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.65rem 1rem;
  background: var(--ui-head);
  font-weight: 600;
  line-height: 1.3;
}

/* Rozwinięta sekcja: tytuł oddzielony od pól, które pod nim leżą */
.cad-params details.sec[open] > summary {
  margin-bottom: 0.75rem;
  border-bottom: 1px solid var(--ui-line);
}

.cad-params details.sec > summary::after {
  margin-left: 0.4rem;
}

.cad-params details.sec > summary .state {
  margin-left: auto;
  color: var(--ui-muted);
  font-size: 0.82rem;
  font-weight: 400;
  text-align: right;
}

.sec-body {
  padding: 0 1rem 0.9rem;
}

.cad-params label {
  font-size: 0.9rem;
}

.cad-params input:not([type="checkbox"], [type="radio"]),
.cad-params select {
  margin-bottom: 0.55rem;
}

.cad-params .fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 0.7rem;
}

.shape-switches {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0 0.7rem;
  align-items: start;
}

.shape-switches > label:last-child {
  grid-column: 1 / -1;
}

.cad-params fieldset.units {
  margin: 0;
}

.cad-params fieldset.units legend {
  font-size: 0.9rem;
  margin-bottom: 0.25rem;
}

/* Wybór jednostek jako przełącznik segmentowy */
.seg {
  display: inline-flex;
  margin-bottom: 0.55rem;
  border: 1px solid var(--pico-form-element-border-color);
  border-radius: 6px;
  overflow: hidden;
}

.seg label {
  margin: 0;
  font-size: 0.9rem;
}

.seg input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.seg span {
  display: block;
  padding: 0.33rem 0.75rem;
  border-right: 1px solid var(--pico-form-element-border-color);
  cursor: pointer;
}

.seg label:last-child span {
  border-right: 0;
}

.seg input:checked + span {
  background: var(--ui-primary-soft);
  color: var(--ui-primary);
  font-weight: 600;
}

.seg input:focus-visible + span {
  outline: 2px solid var(--ui-primary);
  outline-offset: -2px;
}

.cad-params .shape-table {
  margin-bottom: 0.4rem;
}

.cad-params .shape-table th,
.cad-params .shape-table td {
  padding: 0.25rem 0.3rem;
  vertical-align: top;
}

.cad-params .shape-table thead th {
  padding-block: 0.4rem;
}

.cad-params .shape-table input {
  min-width: 4.2rem;
  margin-bottom: 0.15rem;
}

.cad-params .shape-table th[scope="row"] {
  padding-top: 0.55rem;
}

.cad-params .check {
  margin: 0 0 0.2rem;
  font-size: 0.8rem;
}

.cad-params .arc-cell [role="group"] {
  margin-bottom: 0.15rem;
}

.cad-params .arc-cell select {
  min-width: 6.2rem;
  padding-right: 1.6rem;
  background-position: center right 0.4rem;
}

/* Nazwa boku (AB) jest w tabeli przy wierzchołku; w wąskim panelu tylko zabiera miejsce */
.cad-params .shape-table .side-name {
  display: none;
}

.params-foot {
  padding: 0.7rem 1rem;
  border-top: 1px solid var(--ui-line);
  background: var(--ui-surface);
}

.params-foot .save-bar {
  margin-bottom: 0.3rem;
}

.params-foot .save-bar input,
.params-foot .save-bar select,
.params-foot .save-bar button {
  margin-bottom: 0;
}

.params-foot .save-bar button {
  flex: none;
  white-space: nowrap;
}

.params-foot #save-status,
.params-foot > p {
  margin: 0;
}

.cad-view {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  height: 100vh;
}

.cad-drawing {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: #fbfcfd;
}

.cad-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem 0.6rem;
  padding: 0.4rem 0.75rem;
  background: var(--ui-surface);
  border-bottom: 1px solid var(--ui-line);
}

.layer-tools {
  display: flex;
  gap: 2px;
  padding-right: 0.6rem;
  border-right: 1px solid var(--ui-line);
}

.cad-toolbar button.layer {
  margin: 0;
  padding: 0.2rem 0.55rem;
  font-size: 0.85rem;
  color: var(--ui-muted);
  background: transparent;
  border: 1px solid transparent;
}

.cad-toolbar button.layer[aria-pressed="true"] {
  color: var(--ui-primary);
  background: var(--ui-primary-soft);
  border-color: #cfe1ec;
}

.cad-toolbar .zoom-tools {
  flex: 1;
  margin: 0;
}

.cad-canvas {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  background-color: #fbfcfd;
  background-image: linear-gradient(#eef1f4 1px, transparent 1px),
    linear-gradient(90deg, #eef1f4 1px, transparent 1px);
  background-size: 24px 24px;
}

.cad-canvas .zoom-box {
  position: absolute;
  inset: 0.75rem 0.75rem 2.25rem;
}

.cad-canvas .shape-preview {
  width: 100%;
  height: 100%;
  max-height: none;
}

.cad-canvas .legend {
  position: absolute;
  left: 0.75rem;
  bottom: 0.4rem;
  max-width: calc(100% - 12rem);
  margin: 0;
  padding: 0.15rem 0.6rem;
  border: 1px solid var(--ui-line);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.92);
}

.cad-empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 2rem;
  text-align: center;
}

.minimap {
  position: absolute;
  right: 0;
  bottom: -1.5rem;
  width: 150px;
  height: 100px;
  display: none;
  padding: 4px;
  border: 1px solid var(--ui-line);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.95);
}

.minimap.shown {
  display: block;
}

.minimap .outline {
  fill: var(--ui-primary-soft);
  stroke: var(--ui-primary);
  stroke-width: 1;
}

.minimap .frame-band {
  fill: #cdd5dc;
  stroke: none;
}

.minimap .mini-view {
  fill: rgba(183, 121, 31, 0.08);
  stroke: var(--ui-warn);
  stroke-width: 1.5;
}

.profile-info {
  position: absolute;
  z-index: 3;
  display: flex;
  flex-direction: column;
  max-width: 210px;
  padding: 0.35rem 0.6rem;
  border: 1px solid var(--ui-line);
  border-radius: 6px;
  background: #fff;
  box-shadow: 0 2px 8px rgba(31, 41, 51, 0.12);
  pointer-events: none;
}

.profile-info[hidden] {
  display: none;
}

.shape-preview .profile {
  cursor: pointer;
}

.shape-preview .profile.selected {
  stroke: var(--ui-warn);
  stroke-width: 2.5;
}

.cad-status {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem 1.2rem;
  padding: 0.45rem 0.9rem;
  background: var(--ui-surface);
  border-top: 1px solid var(--ui-line);
  color: var(--ui-muted);
  font-size: 0.9rem;
}

.cad-status strong {
  color: var(--ui-text);
  font-weight: 600;
}

.cad-messages {
  max-height: 25vh;
  overflow: auto;
  padding: 0.5rem 0.9rem;
  background: var(--ui-warn-soft);
  border-top: 1px solid var(--ui-line);
}

.cad-messages p,
.cad-messages ul,
.cad-messages details {
  margin-block: 0.2rem;
}

/* Warstwy rysunku (przyciski nad rysunkiem, cad.js) */
body.hide-profiles .shape-preview .profile,
body.hide-profiles .shape-preview .mat,
body.hide-numbers .shape-preview .profile-no,
body.hide-profiles .shape-preview .profile-no,
body.hide-frame .shape-preview .frame-band,
body.hide-dims .shape-preview .dim,
body.hide-dims .shape-preview .ang,
body.hide-dims .shape-preview .vtx,
body.hide-diagonals .shape-preview .diagonal-line,
body.hide-arrow .shape-preview .walk-arrow {
  display: none;
}

/* Dolny panel: lista cięć, rama, koszt, szpara */
.cad-bottom {
  flex: 0 0 38vh;
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--ui-surface);
  border-top: 1px solid var(--ui-line);
}

.cad-bottom.empty {
  display: none;
}

body.bottom-collapsed .cad-bottom {
  flex-basis: auto;
}

body.bottom-collapsed .cad-bottom .pane {
  display: none;
}

body.bottom-collapsed .bottom-toggle {
  transform: rotate(180deg);
}

.bottom-tabs {
  margin: 0;
  padding: 0 0.5rem;
}

.bottom-tabs button {
  margin: 0 0 -1px;
  padding: 0.55rem 0.85rem;
  border: 0;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  background: none;
  color: var(--ui-muted);
  font-weight: 500;
  white-space: nowrap;
}

.bottom-tabs button:hover {
  color: var(--ui-text);
  background: none;
}

.bottom-tabs button.active {
  color: var(--ui-primary);
  border-bottom-color: var(--ui-primary);
}

.bottom-tabs .bottom-toggle {
  margin-left: auto;
  font-size: 1.1rem;
}

.cad-bottom .pane {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 0.6rem 1rem;
}

.pane-title {
  --pico-font-size: 1rem;
  margin: 0 0 0.3rem;
}

.pane-summary {
  margin-bottom: 0.6rem;
  font-size: 0.9rem;
}

.table-scroll {
  overflow-x: auto;
}

.cad-bottom table {
  margin-bottom: 0.6rem;
}

/* Tablet w pionie, telefon: parametry nad rysunkiem, zwykłe przewijanie strony */
@media (max-width: 1100px) {
  .cad {
    grid-template-columns: minmax(0, 1fr);
    height: auto;
  }

  .cad-params {
    border-right: 0;
    border-bottom: 1px solid var(--ui-line);
  }

  .params-body {
    overflow: visible;
  }

  .cad-view {
    height: auto;
  }

  .cad-drawing {
    flex: none;
    height: 70vh;
  }

  .cad-bottom {
    flex: none;
  }
}

/* --- Oferta dla klienta (#15): dokument A4, na ekranie jak kartka --- */
.offer-rates {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 0 1rem;
}

.offer-rates label {
  width: 9rem;
}

.offer-rates button {
  width: auto;
}

.offer-custom {
  padding: 0.5rem 0.75rem;
  border-radius: 6px;
  background: var(--ui-warn-soft);
}

.offer-doc {
  max-width: 210mm;
  margin: 0 auto 2rem;
  padding: 14mm;
  background: #fff;
  border: 1px solid var(--ui-line);
  border-radius: 6px;
  color: #1d2733;
}

.offer-doc .pre {
  white-space: pre-line;
}

.offer-top {
  display: flex;
  justify-content: space-between;
  gap: 2rem;
  padding-bottom: 1rem;
  border-bottom: 2px solid var(--ui-primary);
}

.offer-company,
.offer-meta,
.offer-client {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.offer-meta {
  text-align: right;
}

.offer-meta h2 {
  margin: 0 0 0.3rem;
  font-size: 1.35rem;
}

.offer-logo {
  max-width: 45mm;
  max-height: 18mm;
  margin-bottom: 0.4rem;
  object-fit: contain;
  object-position: left;
}

.offer-client {
  margin: 1rem 0;
}

.offer-item {
  display: grid;
  grid-template-columns: 75mm 1fr;
  gap: 1.2rem;
  padding: 0.9rem 0;
  border-top: 1px solid var(--ui-line);
  break-inside: avoid;
}

.offer-drawing svg.shape-preview {
  width: 100%;
  height: auto;
  max-height: 70mm;
}

.offer-desc h3 {
  margin: 0 0 0.4rem;
  font-size: 1.05rem;
}

.offer-desc ul {
  margin: 0 0 0.5rem;
  padding-left: 1.1rem;
}

.offer-desc li {
  list-style: disc;
  margin: 0;
}

.offer-price {
  margin: 0;
}

.offer-sum {
  width: auto;
  margin: 1rem 0 1rem auto;
}

.offer-sum th,
.offer-sum td {
  padding: 0.25rem 0.75rem;
  text-align: right;
}

.offer-sum tr.total th,
.offer-sum tr.total td {
  font-weight: 700;
  border-top: 2px solid #1d2733;
}

.offer-terms {
  margin-top: 1rem;
  break-inside: avoid;
}

.offer-terms p {
  margin: 0.3rem 0 0;
}

.offer-foot {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  margin-top: 1.5rem;
  padding-top: 0.6rem;
  border-top: 1px solid var(--ui-line);
  font-size: 0.9em;
  color: var(--ui-muted);
}

@media print {
  @page {
    size: A4;
    margin: 12mm;
  }

  .offer-doc {
    max-width: none;
    margin: 0;
    padding: 0;
    border: 0;
  }

  /* Na wydruku oferty bez nagłówka aplikacji */
  .offer-page .page-head {
    display: none;
  }
}

@media (max-width: 700px) {
  .offer-doc {
    padding: 1rem;
  }

  .offer-top,
  .offer-item {
    display: block;
  }

  .offer-meta {
    margin-top: 1rem;
    text-align: left;
  }
}

/* Ostrzeżenie o niepełnej ofercie: także na wydruku */
.offer-warnings {
  max-width: 210mm;
  margin: 0 auto 1rem;
  padding: 0.75rem 1rem;
  border: 2px solid var(--pico-del-color);
  border-radius: 6px;
  color: var(--pico-del-color);
}

.offer-warnings p {
  margin: 0.3rem 0 0;
}

/* Biblioteka kształtów w panelu parametrów */
.sec-body.library {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.library-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin: 0;
  padding: 0;
}

.library-list li {
  display: inline-flex;
  gap: 0.15rem;
  margin: 0;
  list-style: none;
}

.library-list .icon-btn {
  padding-inline: 0.45rem;
}

.library-save {
  margin: 0.2rem 0 0.4rem;
}

/* Mocniej niż .cad-params input: bez dolnego marginesu przycisk w grupie ma wysokość pola */
.cad-params .library-save input:not([type="checkbox"], [type="radio"]) {
  margin: 0;
}

.library-save button {
  white-space: nowrap;
}
