/* Shared column geometry for catalog, nonstock and subtotal rows.
   Buňka Položka: číslo položky | Vybrat | typ | kód zboží | popis (stejná mřížka i v hlavičce). */
/* Pevné šířky mají jen číselné sloupce a akce; sloupec Položka (popis) bere zbylé místo.
   Pod ~1370 px šířky obsahu se objeví vodorovný posuvník místo mačkání polí. */
:root {
  --line-editor-table-min-width: 1620px;
  --line-editor-project-table-min-width: 1810px;
  --line-editor-number-width: 102px; /* 9 digits of the item number (8 are used) and the cell padding */
  --line-editor-grid-min-width: 748px;
  --line-editor-pick-size: calc(var(--line-editor-control-size) - 4px); /* the item picker button: smaller than the fields so it never makes the row taller */
  --line-editor-code-width: 120px;
  --line-editor-grid-columns: 44px var(--line-editor-pick-size) var(--line-editor-number-width) var(--line-editor-code-width) minmax(408px, 1fr);
  --line-editor-sticky-offset: calc(-194px - var(--line-editor-number-width) - var(--line-editor-pick-size));
  --line-editor-price-width: 96px;
  --line-editor-discount-width: 68px;
  --line-editor-total-width: 120px;
}
:root[data-density="compact"] {
  --line-editor-table-min-width: 1280px;
  --line-editor-project-table-min-width: 1470px;
  --line-editor-grid-min-width: 0px;
  --line-editor-code-width: 92px;
  --line-editor-number-width: 84px;
  --line-editor-grid-columns: 44px var(--line-editor-pick-size) var(--line-editor-number-width) var(--line-editor-code-width) minmax(0, 1fr);
  --line-editor-sticky-offset: calc(-166px - var(--line-editor-number-width) - var(--line-editor-pick-size));
  --line-editor-price-width: 82px;
  --line-editor-discount-width: 58px;
  --line-editor-total-width: 100px;
}
.app-content-scroll .quote-workspace .table-wrap > table.lines-table {
  width: 100%;
  min-width: var(--line-editor-table-min-width);
}
.app-content-scroll .quote-workspace .table-wrap > table.lines-table--projects {
  width: 100%;
  min-width: var(--line-editor-project-table-min-width);
}
.app-content-scroll .quote-workspace .lines-table :is(th, td):nth-child(2) {
  width: auto;
  min-width: calc(var(--line-editor-grid-min-width) + 12px);
  max-width: 1104px; /* nejvýše dvojnásobek původní šířky sloupce */
}
.app-content-scroll .quote-workspace .lines-table .document-line-editor {
  display: grid;
  grid-template-columns: var(--line-editor-grid-columns);
  gap: 6px;
  width: 100%;
  box-sizing: border-box;
  /* Popis (textarea) roste dolů – ostatní prvky zůstávají nahoře v řádku */
  align-items: start;
  min-width: var(--line-editor-grid-min-width);
}
/* Řádky položek se zvyšují podle popisu: buňky zarovnané nahoru, ne na střed */
.app-content-scroll .quote-workspace .lines-table td {
  vertical-align: top;
}
/* Popis jako textarea: 32 px na jeden řádek, výšku nastavuje fitLineDescription() v editor_lines.js */
.app-content-scroll .quote-workspace .lines-table textarea.line-description {
  display: block;
  height: var(--line-editor-control-size);
  min-height: var(--line-editor-control-size) !important;
  padding: 5px 8px !important;
  font: inherit;
  resize: none;
  overflow: hidden;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.app-content-scroll .quote-workspace .lines-table .document-line-editor > * {
  min-width: 0;
  margin: 0;
}
.app-content-scroll .quote-workspace .lines-table .document-line-editor :is(.line-code, .line-description) {
  width: 100% !important;
  min-width: 0;
  max-width: none;
  box-sizing: border-box;
}
/* Číslo položky a kód zboží jen ke čtení: jeden řádek, celé znění v title */
.app-content-scroll .quote-workspace .lines-table .document-line-editor :is(.line-identity, .line-goods-code) {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  line-height: var(--line-editor-control-size);
  padding: 0 8px;
}
/* Výběr položky: čtvercové tlačítko s ikonou (dřív text „Vybrat“ 60 px) */
.app-content-scroll .quote-workspace .lines-table .document-line-editor > button.line-pick-button {
  width: var(--line-editor-pick-size) !important;
  height: var(--line-editor-pick-size) !important;
  min-height: var(--line-editor-pick-size) !important;
  max-height: var(--line-editor-pick-size);
  margin-top: calc((var(--line-editor-control-size) - var(--line-editor-pick-size)) / 2) !important;
  padding: 0 !important;
  display: inline-grid;
  place-items: center;
}
.app-content-scroll .quote-workspace .lines-table .document-line-editor > button.line-pick-button svg { width: 16px; height: 16px; }
.quote-workspace .lines-table .line-project-field > button.line-pick-button {
  box-sizing: border-box;
  width: var(--line-editor-control-size) !important;
  height: var(--line-editor-control-size) !important;
  min-height: var(--line-editor-control-size) !important;
  flex: 0 0 var(--line-editor-control-size) !important;
  padding: 0 !important;
  display: inline-grid;
  place-items: center;
}
.quote-workspace .lines-table .line-project-cell .line-project-code {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.quote-workspace .lines-table .line-project-cell span.line-project-code { display: block; }
.app-content-scroll .quote-workspace .lines-table :is(.line-pick-button, .line-note-button, .line-calculation-button) svg { width: 18px; height: 18px; }

/* ===== Databázový vzhled tabulky položek (surová mřížka, ne e-shop) ===== */
.app-content-scroll .quote-workspace .lines-table {
  border: 1px solid var(--color-border);
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
}
.app-content-scroll .quote-workspace .lines-table :is(th, td) {
  border-right: 1px solid var(--color-divider);
  border-bottom: 1px solid var(--color-divider);
  padding: var(--line-editor-cell-padding-block) var(--line-editor-cell-padding-inline) !important;
  background-color: var(--color-surface);
}
.app-content-scroll .quote-workspace .lines-table :is(th, td):last-child { border-right: 0; }
.app-content-scroll .quote-workspace .lines-table th {
  background-color: var(--color-table-head);
  border-bottom: 1px solid var(--color-border-strong);
  color: var(--color-text-secondary);
  font-size: var(--table-heading-font-size);
  font-weight: 700;
  line-height: 16px;
  vertical-align: bottom;
  padding: var(--line-editor-heading-padding-block) var(--line-editor-cell-padding-inline) !important;
}
.app-content-scroll .quote-workspace .lines-table tbody tr:hover > td { background-color: var(--color-table-row-hover); }
/* Popisky v hlavičce sloupce Položka zarovnané s mřížkou řádků */
.app-content-scroll .quote-workspace .lines-table th.line-editor-head .document-line-editor { align-items: end; }
.app-content-scroll .quote-workspace .lines-table th.line-editor-head .document-line-editor > span { padding: 0 8px; white-space: nowrap; }
.app-content-scroll .quote-workspace .lines-table th.line-editor-head .document-line-editor > span:nth-child(-n+2) { padding: 0 4px; }
.app-content-scroll .quote-workspace .lines-table .document-line-editor .line-identity,
.app-content-scroll .quote-workspace .lines-table th.line-editor-head .document-line-editor > span:nth-child(3) { padding-inline: 4px; }
/* Sloupec Poř.: jen úchyt a dvoumístné číslo – užší (dřív ~90 px) */
.app-content-scroll .quote-workspace .lines-table :is(th, td):first-child { width: 54px; } /* + odsazení 6+6 px → ~67 px */
.app-content-scroll .quote-workspace .lines-table .position-control { gap: 4px; }
.app-content-scroll .quote-workspace .lines-table .position-input { flex: 0 0 36px !important; width: 36px !important; padding: 2px !important; }

/* Kompaktní sazba řádků. Dotyková pole mají dál vlastní velikost písma. */
:root[data-density="compact"] .app-content-scroll .quote-workspace .lines-table td {
  font-size: var(--table-body-font-size);
}
@media (width > 880px) and (pointer: fine) {
  :root[data-density="compact"] .app-content-scroll .quote-workspace .lines-table td :is(input:not([type="checkbox"]), select, textarea) {
    font-size: var(--control-font-size);
  }
}

/* Pole jako v tabulkovém procesoru: bez rámečku, rámeček při najetí a při úpravě */
.app-content-scroll .quote-workspace .lines-table td :is(input:not([type="checkbox"]), select, textarea) {
  border: 1px solid transparent !important;
  background: transparent !important;
  box-shadow: none !important;
}
.app-content-scroll .quote-workspace .lines-table td :is(input:not([type="checkbox"]), select, textarea):hover:not(:disabled) {
  border-color: var(--color-border) !important;
}
.app-content-scroll .quote-workspace .lines-table td :is(input:not([type="checkbox"]), select, textarea):focus {
  border-color: var(--color-focus) !important;
  background: var(--color-surface) !important;
}
/* Typ řádku jako malý štítek, při najetí ukáže, že jde vybrat */
.app-content-scroll .quote-workspace .lines-table .line-type-picker { border: 1px solid transparent; }
.app-content-scroll .quote-workspace .lines-table .line-type-picker:hover { border-color: var(--color-border); }

/* Množství: úzký sloupec, pole přes celou buňku a číslo vpravo pod hlavičkou
   (dřív pevné 66px pole vlevo v ~98px sloupci). Šířka buňky je bez odsazení 6+6 px → celkem ~73 px. */
.app-content-scroll .quote-workspace .lines-table :is(th, td):nth-child(3) { width: 60px; }
.app-content-scroll .quote-workspace .lines-table td input[data-field="quantity"] { width: 100% !important; min-width: 0 !important; box-sizing: border-box; }
/* Čísla vpravo; čísla položek a kódy se stejně širokými číslicemi (tabular-nums z tabulky) */
.app-content-scroll .quote-workspace .lines-table td input[data-field="quantity"] { text-align: right; }
.app-content-scroll .quote-workspace .lines-table td:is(.line-total, .subtotal-unit-price) { text-align: right; line-height: var(--line-editor-control-size); white-space: nowrap; }
.app-content-scroll .quote-workspace .lines-table td.subtotal-vat { line-height: var(--line-editor-control-size); }
.app-content-scroll .quote-workspace .lines-table th:nth-child(n+3):nth-child(-n+7):not(:nth-child(4)):not(:nth-child(6)) { text-align: right; }
.app-content-scroll .quote-workspace .lines-table :is(.line-identity, .line-goods-code, .line-code, .position-input) {
  font-size: var(--table-body-font-size);
  font-weight: 400;
}
.app-content-scroll .quote-workspace .lines-table .line-goods-code { color: var(--color-text-secondary); }
.app-content-scroll .quote-workspace .lines-table .position-input { text-align: center; }


/* Price columns share the existing spreadsheet input pattern. */
.app-content-scroll .quote-workspace .lines-table :is(th, td):nth-child(5),
.app-content-scroll .quote-workspace .lines-table :is(th, td):nth-child(6) { width: var(--line-editor-price-width); }
.app-content-scroll .quote-workspace .lines-table :is(th, td):nth-child(7) { width: var(--line-editor-discount-width); }
/* MJ a DPH: krátké hodnoty (ks, 21) – select přes celou úzkou buňku */
.app-content-scroll .quote-workspace .lines-table :is(th, td):nth-child(4) { width: 56px; }
.app-content-scroll .quote-workspace .lines-table :is(th, td):nth-child(8) { width: 52px; }
.app-content-scroll .quote-workspace .lines-table td :is(select.unit-select, select.vat-select) { width: 100% !important; min-width: 0 !important; padding-left: 2px !important; padding-right: 0 !important; }
.app-content-scroll .quote-workspace .lines-table :is(th, td):nth-child(9) { width: var(--line-editor-total-width); }
/* Cenová pole vyplní buňku (quote_ui.css omezoval Prodejní cenu na max-width 104px → text o 9 px vlevo) */
.app-content-scroll .quote-workspace .lines-table td input:is([data-field="purchasePrice"], [data-field="unitPrice"], [data-field="discountPct"], [data-field="totalPrice"]) { width: 100% !important; min-width: 0 !important; max-width: none !important; box-sizing: border-box; text-align: right; }
.app-content-scroll .quote-workspace .lines-table td input.price-above-list { color: var(--color-warning) !important; }
.app-content-scroll .quote-workspace .lines-table th:nth-child(n+5):nth-child(-n+9) { text-align: right; }
/* Celkem a akce (+ pozn., koš) zarovnané nahoru jako ostatní buňky – starší pravidla
   (.line-total a td:last-child v quote_ui.css/shell.css) je s !important dávala na střed,
   takže u vyššího řádku (zalomený popis) seděly níž než zbytek řádku. */
.app-content-scroll .quote-workspace .lines-table tr:not(.note-line) td:is(.line-total, :last-child) { vertical-align: top !important; }
/* Součtový řádek má cenu, DPH a celkem jako text, ostatní řádky jako pole s vnitřním odsazením
   (rámeček 1 px + 7 px). Stejné odsazení textu → hodnoty jsou ve sloupci pod sebou. */
.app-content-scroll .quote-workspace .lines-table tr.subtotal-line td:is(.subtotal-unit-price, .subtotal-vat, .line-total) { padding-left: 14px !important; padding-right: 14px !important; }
/* Akce: až tři čtvercová tlačítka (kalkulace u K řádku, poznámka, koš) vedle sebe – 3 × 32 px + 2 × 6 px mezery + odsazení buňky */
.app-content-scroll .quote-workspace .lines-table tr:not(.note-line) td:last-child,
.app-content-scroll .quote-workspace .lines-table th:last-child { width: calc(3 * var(--line-editor-control-size) + 28px) !important; min-width: calc(3 * var(--line-editor-control-size) + 28px) !important; }
.app-content-scroll .quote-workspace .lines-table tr:not(.note-line) td:last-child > button { width: var(--line-editor-control-size); display: inline-grid; place-items: center; height: var(--line-editor-control-size) !important; min-height: var(--line-editor-control-size) !important; padding: 0 !important; }
.app-content-scroll .quote-workspace .lines-table tr:not(.note-line) td:last-child .row-remove { margin-left: 6px !important; float: none; }
.app-content-scroll .quote-workspace .lines-table tr:not(.note-line) td:last-child > button + button { margin-left: 6px !important; }
/* Typ řádku: bez šipky (select se otevře kliknutím), písmeno na střed štítku */
.app-content-scroll .quote-workspace .lines-table .line-type-picker::after { content: none; }
.app-content-scroll .quote-workspace .lines-table .line-type-picker > span { inset: 0; }
.app-content-scroll .quote-workspace .lines-table .line-type-picker select { padding: 3px 5px !important; }
/* Čtvercová tlačítka (výběr, poznámka, kalkulace): hover jako ostatní sekundární tlačítka – shell.css dával .icon-button bílou ikonu, na světlém pozadí neviditelnou */
.app-content-scroll .quote-workspace .lines-table :is(.line-pick-button, .line-note-button, .line-calculation-button):is(:hover, :focus-visible):not(:disabled) { color: var(--color-text) !important; -webkit-text-fill-color: var(--color-text) !important; }

/* DPH: sazba vpravo, stejně v řádcích i v mezisoučtech (hodnota u pravého okraje vedle šipky výběru) */
.app-content-scroll .quote-workspace .lines-table :is(th, td):nth-child(8) { text-align: right; }
.app-content-scroll .quote-workspace .lines-table td select.vat-select { text-align: right; text-align-last: right; }
.app-content-scroll .quote-workspace .lines-table tr.subtotal-line td.subtotal-vat { text-align: right; padding-right: var(--line-editor-cell-padding-inline) !important; }
/* Číslo součtového řádku je pole s rámečkem: text začíná stejně jako číslo u ostatních řádků (padding 4 px, bez rámečku). */
.app-content-scroll .quote-workspace .lines-table tr.subtotal-line .line-number-input { padding-left: 3px !important; }

/* Textové a nadpisové řádky: pole přes celou šířku buňky, jinak se krátký text zalomí na dva řádky */
.app-content-scroll .quote-workspace .lines-table .document-text-editor .line-description {
  width: 100%;
  min-width: 0;
  box-sizing: border-box;
}

/* Typ převedeného řádku (zamčený štítek) má stejnou výšku jako ostatní prvky řádku: 32 px, text na střed, bez vlastního odsazení */
.app-content-scroll .quote-workspace .lines-table .line-type-locked {
  box-sizing: border-box;
  display: inline-grid;
  place-items: center;
  height: var(--line-editor-control-size);
  min-width: 44px;
  padding: 0 4px;
  border: 1px solid transparent;
  line-height: 1;
  white-space: nowrap;
}
/* Řádek položky: ovládací prvky mají pevnou výšku 32 px, roste jen popis (textarea) při zalomení */
.app-content-scroll .quote-workspace .lines-table .document-line-editor > :is(.line-type-picker, .line-type-locked, .line-pick-button, .line-identity, .line-goods-code) {
  height: var(--line-editor-control-size);
  min-height: var(--line-editor-control-size);
  align-self: start;
}

/* Koeficienty pro celý doklad jsou dočasně skryté: kalkulace se zatím dělají jen na jednotlivých položkách */
#calculationCoefficients { display: none !important; }

/* Keep the description visible when the editor has enough room for prices.
   Type, picker, number and code scroll out of view before the description sticks. */
@container (min-width: 760px) {
  [data-panel="quote"] #quotePanelLines .lines-table :is(th.line-editor-head, tr.priced-line > td:nth-child(2), tr.subtotal-line > td:nth-child(2)) {
    position: sticky;
    left: var(--line-editor-sticky-offset);
    z-index: 2;
  }
}

/* Jemne stridani radku vcetne pripnute bunky popisu. */
.app-content-scroll .quote-workspace .lines-table tbody tr:nth-child(even):not(:hover):not(.subtotal-line) > td {
  background-color: var(--color-table-row-alt);
}

/* Column separators inside the Položka cell (Typ | Číslo | Kód zboží | Popis), in the header and in every row including the subtotal row.
   Drawn as background lines at the middle of the grid gaps; the cell padding is taken over so the lines run through the whole row. */
.app-content-scroll .quote-workspace .lines-table :is(td, th) > .document-line-editor {
  --sep-0: calc(44px + 3px);
  --sep-1: calc(44px + 6px + var(--line-editor-pick-size) + 3px);
  --sep-2: calc(var(--sep-1) + 6px + var(--line-editor-number-width));
  --sep-3: calc(var(--sep-2) + 6px + var(--line-editor-code-width));
  --sep-pad: var(--line-editor-cell-padding-block);
  margin-block: calc(-1 * var(--sep-pad));
  padding-block: var(--sep-pad);
  background-image: linear-gradient(var(--color-divider), var(--color-divider)), linear-gradient(var(--color-divider), var(--color-divider)), linear-gradient(var(--color-divider), var(--color-divider)), linear-gradient(var(--color-divider), var(--color-divider));
  background-repeat: no-repeat;
  background-size: 1px 100%, 1px 100%, 1px 100%, 1px 100%;
  background-position: var(--sep-0) 0, var(--sep-1) 0, var(--sep-2) 0, var(--sep-3) 0;
}
.app-content-scroll .quote-workspace .lines-table th.line-editor-head > .document-line-editor { --sep-pad: var(--line-editor-heading-padding-block); }

/* Row height: the position cell (handle and number) follows the control size too; fixed 30-32 px there made compact rows 4 px taller than their fields. */
.app-content-scroll .quote-workspace .lines-table .position-control { min-height: var(--line-editor-control-size); }
.app-content-scroll .quote-workspace .lines-table .position-control .drag-handle { height: var(--line-editor-control-size); }
.app-content-scroll .quote-workspace .lines-table .position-control .position-input { height: var(--line-editor-control-size); min-height: var(--line-editor-control-size) !important; }

/* The note row is as tall as the other rows: the note field follows the control size (it had a fixed 30 px). */
.app-content-scroll .quote-workspace .lines-table tr.note-line .note-input { height: var(--line-editor-control-size); min-height: var(--line-editor-control-size) !important; box-sizing: border-box; }
.app-content-scroll .quote-workspace .lines-table tr.note-line td.note-action > button { width: var(--line-editor-control-size); height: var(--line-editor-control-size) !important; min-height: var(--line-editor-control-size) !important; padding: 0 !important; display: inline-grid; place-items: center; }
