/* views.css — edytor kosztorysu, katalog, plan fakturowania, budżet */

/* ================= EDYTOR ================= */
.est-layout { display: grid; grid-template-columns: 280px minmax(0, 1fr); gap: 18px; align-items: start; }
/* tryb podglądu / zablokowany — katalog ukryty, treść na całą szerokość (bez wąskiej kolumny 280px) */
.est-layout.single { grid-template-columns: minmax(0, 1fr); }

/* hierarchia wersji na liście kosztorysów — warianty wcięte pod oryginałem */
.grid tr.version-row > td { background: var(--surface-2); }
.grid tr.version-row > td:first-child { border-left: 2px solid var(--line-strong); }
.ver-branch { color: var(--muted); font-weight: 700; margin-right: 6px; }
/* wyraźny „rozwijacz" rodziny — chip z liczbą wariantów */
.tree-toggle {
  display: inline-flex; align-items: center; gap: 5px; cursor: pointer;
  background: var(--surface-3); border: 1px solid var(--line); border-radius: var(--r-pill);
  color: var(--accent); font-size: 11.5px; font-weight: 700; padding: 2px 10px; line-height: 1.5;
  transition: background var(--t-fast) var(--ease), color var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease);
}
.tree-toggle:hover { background: var(--accent); color: #fff; border-color: var(--accent); }
.tree-toggle .tt-arr { font-size: 10px; }
/* pole wyboru wielu działów (wygląda jak input) */
.field-box { display: flex; align-items: center; gap: 8px; padding: 6px 10px; border: 1px solid var(--line); border-radius: var(--r-md, 10px); background: var(--surface); min-height: 38px; }
.field-box #f-depts-label { flex: 1; font-size: 13.5px; color: var(--text-strong); }
/* pasek wyniku sprzedażowego w edytorze */
.outcome-bar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; padding: 8px 14px; border: 1px solid var(--line); border-radius: var(--r-md, 10px); background: var(--surface-2); }
.outcome-bar .btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.tag.rejected { background: var(--danger-bg, #fde8e8); color: var(--danger, #c0392b); }
/* status + wynik (wygrany/przegrany) w jednej linii */
.status-cell { display: flex; align-items: center; gap: 8px; flex-wrap: nowrap; white-space: nowrap; }
.oc-line { display: inline-flex; align-items: center; gap: 4px; }
.rp-delta-up { color: var(--ok, #2e7d32); font-weight: 700; }
.rp-delta-down { color: var(--danger, #c0392b); font-weight: 700; }
/* pozwala kolumnie treści kurczyć się — szerokie tabele (plan, pozycje) scrollują się
   wewnątrz swoich kontenerów .items-wrap zamiast rozpychać całą stronę w prawo */
.est-layout > * { min-width: 0; }
.est-layout .items-wrap, .est-layout .plan-wrap { max-width: 100%; }

/* katalog po lewej (sticky) */
.est-catalog {
  position: sticky; top: calc(var(--topbar-h) + 18px);
  max-height: calc(100vh - var(--topbar-h) - 36px); overflow: auto; padding: 16px;
}
.est-catalog .search { width: 100%; margin-bottom: 10px; }
.cat-group { margin-bottom: 18px; }
/* wyraźny separator między działami */
.cat-group + .cat-group { border-top: 1px solid var(--line-strong); padding-top: 12px; }
/* nagłówek działu — mocny, brandowy, dobrze odgranicza sekcje */
.cat-group h4 {
  font-size: 11.5px; text-transform: uppercase; letter-spacing: .06em; color: #fff;
  font-weight: 800; margin: 0 0 9px; padding: 9px 12px;
  background: var(--grad-brand); border-radius: var(--r-sm); box-shadow: 0 2px 8px rgba(27,63,230,.25);
}
/* podkategoria — czytelny śródtytuł z akcentem po lewej */
.cat-sub {
  font-size: 10.5px; font-weight: 800; color: var(--text-strong); margin: 13px 0 6px;
  text-transform: uppercase; letter-spacing: .05em;
  padding: 5px 0 5px 9px; border-left: 3px solid var(--sky);
  background: var(--surface-2); border-radius: 0 5px 5px 0;
}
.cat-item {
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  padding: 8px 10px; border-radius: var(--r-xs); cursor: pointer; font-size: 12.5px;
  border: 1px solid transparent; border-bottom: 1px solid var(--line);
  transition: all var(--t-fast) var(--ease);
}
.cat-item:last-child { border-bottom-color: transparent; }
.cat-item:hover { background: var(--surface-3); border-color: var(--line-strong); transform: translateX(2px); }
.cat-item .price { color: var(--muted); font-size: 11.5px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.cat-item.bundle { background: var(--grad-brand-soft); border-color: color-mix(in srgb, var(--violet) 20%, transparent); }
.cat-item.bundle:hover { border-color: var(--violet); }

/* karty edytora */
.ed-card { margin-bottom: 16px; }
.ed-head {
  display: flex; align-items: center; gap: 10px; font-size: 14px; font-weight: 700;
  color: var(--text-strong); margin-bottom: 14px;
}
.ed-head-sub { font-size: 11.5px; font-weight: 500; color: var(--muted); }
.ed-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--grad-brand); box-shadow: 0 0 0 4px var(--info-bg); }
.ed-subhead { font-size: 11.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 18px 0 10px; }

/* dane oferty — rozkłada się na tyle kolumn, ile zmieści szeroki obszar roboczy */
.est-meta { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 14px 18px; }
.est-meta label { display: block; font-size: 11px; font-weight: 700; color: var(--text-strong); }
.est-meta label input, .est-meta label select { width: 100%; margin-top: 5px; font-weight: 400; }
.toggles { display: flex; flex-wrap: wrap; gap: 10px 22px; }
.toggles .check { font-size: 12.5px; }

/* tabela pozycji — gęsta, ale czytelna: wyraźne pola edycji, wyróżniony wynik */
.items-wrap { overflow-x: auto; border-radius: var(--r-md); border: 1px solid var(--line); box-shadow: var(--sh-1); }
table.items-edit { width: 100%; border-collapse: separate; border-spacing: 0; min-width: 1040px; background: var(--surface); }
table.items-edit th {
  font-size: 10px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 700;
  text-align: left; padding: 11px 10px; background: var(--surface-2);
  border-bottom: 2px solid var(--line-strong); white-space: nowrap;
}
table.items-edit th.num { text-align: right; }
table.items-edit td { padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.items-edit tbody tr { transition: background var(--t-fast) var(--ease); }
table.items-edit tbody tr:nth-child(even) td { background: color-mix(in srgb, var(--surface-2) 55%, transparent); }
table.items-edit tbody tr:hover td { background: var(--info-bg); }
table.items-edit tr:last-child td { border-bottom: none; }
/* pola w komórkach wyraźnie wyglądają na edytowalne (wgłębione tło) */
table.items-edit input, table.items-edit select {
  padding: 7px 9px; font-size: 12.5px; width: 100%; background: var(--surface-inset);
  border-color: var(--line);
}
table.items-edit input:hover, table.items-edit select:hover { border-color: var(--line-strong); }
table.items-edit input:focus, table.items-edit select:focus { background: var(--surface); }
table.items-edit input:disabled { background: transparent; border-color: transparent; color: var(--muted); box-shadow: none; }
table.items-edit .num { text-align: right; }
.items-edit col.c-name { width: 23%; } .items-edit col.c-mode { width: 104px; }
.items-edit col.c-qty { width: 84px; } .items-edit col.c-rate { width: 156px; }
.items-edit col.c-price { width: 112px; } .items-edit col.c-disc { width: 74px; }
.items-edit col.c-vat { width: 68px; } .items-edit col.c-owner { width: 136px; }
.items-edit col.c-net { width: 132px; } .items-edit col.c-act { width: 162px; }
.wide-in { width: 100%; }
/* kolumna akcji — równe, kwadratowe przyciski (te same pozycje w każdym wierszu) */
.items-edit td.acts { white-space: nowrap; }
.items-edit td.acts > .act-b {
  display: inline-flex; align-items: center; justify-content: center;
  width: 28px; min-width: 28px; height: 28px; padding: 0; margin: 0 1px;
  box-sizing: border-box; vertical-align: middle; font-size: 13px;
}
.items-edit td.acts > span.act-gap { background: transparent; border: none; box-shadow: none; cursor: default; }
.items-edit td.acts .act-faded { opacity: .4; }
/* wiersze-dzieci: rozbicie wewnętrzne pokazane pod pozycją (hierarchia) */
.items-edit tr.has-bd > td { border-bottom-color: transparent; }
.items-edit tr.bd-sub td { background: var(--surface-2); padding-top: 6px; padding-bottom: 6px; font-size: 12px; }
.items-edit tr.bd-sub td.bd-name { padding-left: 28px; position: relative; color: var(--text); border-left: 3px solid var(--sky); }
.items-edit tr.bd-sub td.bd-name::before { content: '↳'; position: absolute; left: 11px; color: var(--faint); }
.items-edit tr.bd-sub:last-child td { border-bottom: 1px solid var(--line); }
/* nazwa pozycji z katalogu — czytelnie wskazana jako edytowalna (dwuklik) */
[data-dbl] {
  cursor: text; padding: 6px 8px; border-radius: 6px; transition: background var(--t-fast), box-shadow var(--t-fast);
  box-shadow: inset 0 0 0 1px transparent;
}
[data-dbl]:hover { background: var(--info-bg); box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--accent) 28%, transparent); }
/* kolumna wyniku (Netto) — wyraźnie „obliczana", nie do edycji */
table.items-edit td[data-net] {
  font-variant-numeric: tabular-nums; font-weight: 700; color: var(--text-strong);
  background: var(--grad-brand-soft); border-left: 1px solid var(--line);
}
table.items-edit tbody tr:hover td[data-net] { background: var(--info-bg); }
table.items-edit td[data-net] .cell-sub { font-weight: 500; }

/* strefa wewnętrzna */
.internal-card {
  background: var(--surface); border: 1px dashed color-mix(in srgb, var(--warn) 45%, var(--line));
  border-radius: var(--r-md); padding: 20px 22px; margin-bottom: 16px;
  position: relative;
}
.internal-card::before {
  content: '🔒 wewnętrzne'; position: absolute; top: -10px; left: 18px;
  font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em;
  color: var(--warn); background: var(--warn-bg); padding: 2px 9px; border-radius: var(--r-pill);
}
.internal-card h3 { font-size: 13px; color: var(--warn); margin-bottom: 12px; text-transform: none; letter-spacing: 0; }

/* podsumowanie wyceny */
.ed-summary-label { display: flex; align-items: center; gap: 10px; font-size: 14px; font-weight: 700; color: var(--text-strong); margin: 6px 0 12px; }
.totals-bar {
  display: flex; flex-wrap: wrap; gap: 12px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md);
  padding: 18px 20px; box-shadow: var(--sh-1); margin-bottom: 16px;
}
.totals-bar .t {
  flex: 1; min-width: 150px; display: flex; flex-direction: column; gap: 4px;
  padding: 12px 14px; border-radius: var(--r-sm); background: var(--surface-2); border: 1px solid var(--line);
}
.totals-bar .t .sub { font-size: 11px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
.totals-bar .t b { font-size: 18px; color: var(--text-strong); font-variant-numeric: tabular-nums; }
.totals-bar .t.grand { background: var(--grad-brand); border: none; }
.totals-bar .t.grand .sub { color: rgba(255,255,255,.85); }
.totals-bar .t.grand b { color: #fff; }

.dept-split-card { margin-bottom: 16px; }

/* budżet i plan — wspólny nagłówek */
.budget-card { margin-bottom: 16px; }
.budget-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 6px; }
.budget-head h3 { font-size: 15px; }
.budget-actions { display: flex; gap: 7px; align-items: center; flex-wrap: wrap; }

/* plan fakturowania */
.plan-wrap { overflow-x: auto; border-radius: var(--r-md); border: 1px solid var(--line); margin-top: 10px; }
table.plan-table { min-width: 760px; border-spacing: 0; }
.plan-table th, .plan-table td { padding: 7px 8px; }
.plan-table input { padding: 5px 7px; font-size: 12px; }
/* kolumny miesięcy: wyśrodkowane nagłówki i inputy → zawsze nad sobą, niezależnie od szerokości kolumny */
.plan-m { width: 74px; min-width: 74px; text-align: center; }
.plan-table th.plan-m { text-align: center; color: var(--accent); }
.plan-table td.plan-m { text-align: center; }
.plan-act { min-width: 180px; }
.plan-rate { width: 84px; }
.plan-h { width: 100%; text-align: center; }
.plan-tot { font-variant-numeric: tabular-nums; white-space: nowrap; }
.plan-sum td { background: var(--surface-2); font-weight: 700; font-size: 12px; font-variant-numeric: tabular-nums; }
.plan-sum td:first-child { color: var(--muted); text-transform: uppercase; font-size: 10.5px; letter-spacing: .04em; }

/* ================= KATALOG ================= */
.catalog-layout { display: grid; grid-template-columns: minmax(0, 1fr) 230px; gap: 18px; align-items: start; }
.catalog-layout > * { min-width: 0; }
.dept-panel {
  position: sticky; top: calc(var(--topbar-h) + 18px);
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md);
  padding: 14px; box-shadow: var(--sh-1); display: flex; flex-direction: column; gap: 4px;
}
.dept-panel-title { font-size: 10.5px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 700; margin-bottom: 6px; padding: 0 4px; }
.dept-pill {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  border: 1px solid transparent; background: transparent; color: var(--text);
  font: 600 12.5px var(--font); padding: 9px 11px; border-radius: var(--r-sm); cursor: pointer; text-align: left;
  transition: all var(--t-fast) var(--ease);
}
.dept-pill:hover { background: var(--surface-3); }
.dept-pill.active { background: var(--info-bg); color: var(--accent); }
.dept-cnt { font-size: 11px; color: var(--muted); background: var(--surface-3); border-radius: var(--r-pill); padding: 1px 8px; font-variant-numeric: tabular-nums; }
.dept-pill.active .dept-cnt { background: var(--surface); color: var(--accent); }

.cat-tree { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); margin-bottom: 12px; box-shadow: var(--sh-1); overflow: hidden; }
.cat-tree.sub { border: none; box-shadow: none; margin: 0; border-radius: 0; }
.cat-tree > summary {
  list-style: none; cursor: pointer; display: flex; align-items: center; gap: 10px;
  padding: 13px 16px; font-weight: 700; color: var(--text-strong); user-select: none;
}
.cat-tree.dept > summary { font-size: 14px; }
.cat-tree.sub > summary { font-size: 12.5px; padding: 9px 16px; color: var(--muted); background: var(--surface-2); border-top: 1px solid var(--line); }
.cat-tree > summary::-webkit-details-marker { display: none; }
.cat-tree > summary::before {
  content: '▸'; color: var(--faint); transition: transform var(--t-fast) var(--ease); font-size: 12px;
}
.cat-tree[open] > summary::before { transform: rotate(90deg); }
.tree-name { flex: 1; }
.tree-count { font-size: 11px; color: var(--muted); background: var(--surface-3); border-radius: var(--r-pill); padding: 1px 9px; font-weight: 600; }
.sub-body { display: flex; flex-direction: column; }

.svc-leaf {
  display: grid; grid-template-columns: 1fr auto auto; gap: 14px; align-items: start;
  padding: 13px 16px; border-top: 1px solid var(--line);
}
.svc-leaf:hover { background: var(--surface-2); }
.svc-leaf-main { min-width: 0; }
.svc-leaf-price { text-align: right; white-space: nowrap; }
.svc-leaf-price b { display: block; color: var(--text-strong); font-size: 14px; font-variant-numeric: tabular-nums; }
.svc-leaf-act { display: flex; gap: 4px; align-items: flex-start; }
.svc-desc.clamped { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.desc-toggle { font-size: 11.5px; color: var(--accent); cursor: pointer; font-weight: 600; }

/* ================= RESPONSYWNOŚĆ ================= */
@media (max-width: 1100px) {
  .est-layout { grid-template-columns: 1fr; }
  .est-catalog { position: static; max-height: 340px; }
  .catalog-layout { grid-template-columns: 1fr; }
  .dept-panel { position: static; flex-direction: row; flex-wrap: wrap; }
  .est-meta { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 640px) {
  .est-meta, .form-grid { grid-template-columns: 1fr; }
  .modal { padding: 20px; }
}
