/* Tokeny kolorystyczne i typograficzne przeniesione z projektu graficznego. */
:root {
  --bg: #fffffe;
  --surface: #ffffff;
  --surface-muted: #fafaf8;
  --row-selected: #f1f1ec;
  --border: #e4e4e0;
  --border-row: #efefeb;

  --text: #312c2c;
  --text-muted: #6b6b67;
  --text-faint: #9a9a96;
  --text-strong: #1a1a1a;

  --danger: #d6453d;
  --danger-soft: #fcebea;
  --danger-text: #7a2a25;
  --overdue: #e46060;

  --chip-ok-bg: #d0e2d2;      --chip-ok-fg: #010c04;
  --chip-bik-bg: #e58989;     --chip-bik-fg: #310401;
  --chip-docs-bg: #e0e589;    --chip-docs-fg: #3c3c03;
  --chip-data-bg: #8995e5;    --chip-data-fg: #050124;

  --stage-done: #312c2c;
  --stage-todo: #dadad6;

  --sidebar-w: 440px;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Instrument Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

.shell {
  display: flex;
  align-items: stretch;
  height: 100%;
}

/* ---------------------------------------------------------------- tabela */

.table-pane {
  flex: 1 0 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 20px;
  padding: 36px 40px;
  overflow: auto;
}

.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
}

.page-heading {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

/* Podpis mówiący, według czego ułożona jest lista — i droga powrotna do
   rankingu, gdy doradca posortuje tabelę ręcznie. */
.sort-note {
  margin: 0;
  font-size: 12px;
  color: var(--text-muted);
  min-height: 16px;   /* stała wysokość: przełączanie nie przesuwa tabeli */
}
.sort-reset {
  padding: 0;
  border: 0;
  background: none;
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: 4px;
}
.sort-reset:hover {
  color: var(--text);
  text-decoration: underline;
}
.sort-reset:focus-visible {
  outline: 2px solid var(--text);
  outline-offset: 3px;
}

.page-title {
  margin: 0;
  font-size: 24px;
  font-weight: 700;
  color: var(--text);
}

.search input {
  width: 240px;
  height: 38px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  font: inherit;
  font-size: 13px;
  color: var(--text);
}
.search input::placeholder { color: var(--text-faint); }
.search input:focus-visible {
  outline: 2px solid var(--text);
  outline-offset: 1px;
}

.table {
  /* flex: none jest tu konieczne. Jako element flexa w kolumnie tabela miałaby
     domyślnie flex-shrink: 1, więc przy niższym oknie kurczyłaby się zamiast
     zachować swoją wysokość — a że overflow ma hidden (zaokrąglone rogi),
     nadmiarowe wiersze zostałyby ucięte bez możliwości doscrollowania.
     Z flex: none tabela zachowuje pełną wysokość, a przewija się panel. */
  flex: none;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  overflow: hidden;
}

.table-header {
  display: flex;
  gap: 40px;
  align-items: center;
  padding: 12px 16px;
  background: var(--surface-muted);
  border-bottom: 1px solid var(--border-row);
}

/* Szerokości kolumn wg projektu; ostatnia wypełnia resztę wiersza. */
.col-name    { width: 200px; flex: none; }
.col-stage   { width: 160px; flex: none; }
.col-time    { width: 130px; flex: none; }
.col-problem { width: 200px; flex: none; }
/* Kolumna z przyciskiem rozwiązującym problem; pusta dla wniosków bez alertu.
   Szerokość mieści też dłuższy stan po wykonaniu akcji, żeby kliknięcie nie
   przesuwało pozostałych kolumn. */
.col-action  { width: 290px; flex: none; }

.th {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 0;
  border: 0;
  background: none;
  font: inherit;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  text-align: left;
}
.th .chev {
  width: 12px;
  height: 12px;
  opacity: .45;
  transition: transform .15s ease, opacity .15s ease;
}
.th[aria-sort] .chev { opacity: 1; }
.th[aria-sort="ascending"] .chev { transform: rotate(180deg); }

.row {
  display: flex;
  gap: 40px;
  align-items: center;
  width: 100%;
  padding: 8px 16px;
  border: 0;
  border-bottom: 1px solid var(--border-row);
  background: var(--surface);
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.row:last-child { border-bottom: 0; }
.row:hover { background: var(--row-selected); }
.row[aria-selected="true"] { background: var(--row-selected); }
.row:focus-visible {
  outline: 2px solid var(--text);
  outline-offset: -2px;
}

.client-name {
  font-weight: 600;
  color: var(--text);
}
.client-amount {
  margin-top: 2px;
  font-size: 12px;
  color: var(--text-muted);
}

.stage-bars {
  display: flex;
  gap: 3px;
  margin-bottom: 6px;
}
.stage-bars i {
  width: 28px;
  height: 4px;
  border-radius: 2px;
  background: var(--stage-todo);
}
.stage-bars i.on { background: var(--stage-done); }
.stage-label {
  font-size: 12px;
  color: var(--text-muted);
}

.time {
  display: flex;
  align-items: center;
  gap: 6px;
}
.time img { width: 14px; height: 14px; }
.time span { font-size: 14px; }
.time.overdue span {
  font-weight: 600;
  color: var(--overdue);
}

.chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 4px 12px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
}
.chip img { width: 14px; height: 14px; }
.chip.ok   { background: var(--chip-ok-bg);   color: var(--chip-ok-fg); }
.chip.bik  { background: var(--chip-bik-bg);  color: var(--chip-bik-fg); }
.chip.docs { background: var(--chip-docs-bg); color: var(--chip-docs-fg); }
.chip.data { background: var(--chip-data-bg); color: var(--chip-data-fg); }

.empty {
  margin: 0;
  padding: 24px 16px;
  color: var(--text-muted);
}


/* Skróty kontaktowe przy prawej krawędzi wiersza, widoczne stale.
   Dosunięte automatycznym marginesem, więc trzymają się krawędzi tabeli
   niezależnie od szerokości okna. */
.quick-actions {
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: flex-end;
  height: 30px;
  flex: none;
  margin-left: auto;   /* dosuwa skróty do prawej krawędzi tabeli */
}

.qa {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  flex: none;
  border-radius: 8px;
  background: #d7d7d3;
  cursor: pointer;
}
.qa:hover { background: #c7c7c2; }
.qa:focus-visible {
  outline: 2px solid var(--text);
  outline-offset: 1px;
}
.qa img { width: 14px; height: 14px; }

/* Wariant jednoprzyciskowy akcji w panelu (BIK, korekta danych).
   Podwójna klasa, bo .sb-action deklarowane jest niżej w pliku. */
.sb-action.sb-action-single {
  flex-direction: row;
  align-items: center;
  gap: 8px;
  width: fit-content;
  max-width: 100%;
  white-space: nowrap;
  border: 0;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  text-align: left;
  cursor: pointer;
}
.sb-action.sb-action-single:hover { background: #d7d7d3; }
.sb-action.sb-action-single:focus-visible {
  outline: 2px solid var(--text);
  outline-offset: 1px;
}
.sb-action.sb-action-single img { width: 18px; height: 18px; }

.sb-action.sb-action-single.is-done {
  background: transparent;
  padding: 0;
  color: var(--text-muted);
  font-weight: 500;
  cursor: default;
}
.sb-action.sb-action-single.is-done:hover { background: transparent; }
.sb-action.sb-action-single.is-done img { width: 14px; height: 14px; }


/* Akcja dopasowana do problemu, renderowana wprost na komponencie wiersza.
   Wysokość 30 px równa się wysokości kontenera skrótów, więc
   przełączanie wariantów nie zmienia wysokości wiersza. */
.row-action {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 30px;
  padding: 0 12px;
  border-radius: 6px;
  background: #e4e4e0;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  cursor: pointer;
}
.row-action:hover { background: #d7d7d3; }
.row-action:focus-visible {
  outline: 2px solid var(--text);
  outline-offset: 1px;
}
.row-action img { width: 18px; height: 18px; }

/* Stan po wykonaniu akcji: potwierdzenie, nie przycisk — stąd brak tła,
   brak hoveru i zwykły kursor. */
.row-action.is-done {
  background: transparent;
  color: var(--text-muted);
  font-weight: 500;
  padding-left: 0;
  cursor: default;
}
.row-action.is-done:hover { background: transparent; }
.row-action.is-done img { width: 14px; height: 14px; }

/* Panel otwarty: tabela jest węższa, więc akcje znikają z wierszy.
   Akcja jest wtedy dostępna w panelu. */
body.sidebar-open .quick-actions,
body.sidebar-open .col-action { display: none; }
/* Tabela ma wtedy ok. 920 px zamiast pełnej szerokości, więc odstępy i kolumny
   są ciaśniejsze — inaczej wiersz nie mieści się i pojawia się przewijanie. */
body.sidebar-open .table-header,
body.sidebar-open .row { min-width: 780px; gap: 24px; }
body.sidebar-open .col-time { width: 170px; }
body.sidebar-open .col-problem { width: auto; flex: 1 0 0; min-width: 150px; }

/* -------------------------------------------------------------- sidebar */

.sidebar {
  width: var(--sidebar-w);
  flex: none;
  height: 100%;
  padding: 32px 28px 28px;
  background: var(--surface);
  border-left: 1px solid var(--border);
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 24px;
}
/* Zwinięcie: panel wysuwa się w prawo, tabela odzyskuje pełną szerokość. */
.sidebar[hidden] { display: none; }

/* Nagłówek panelu: nazwisko i kwota po lewej, zamknięcie po prawej, oba
   wyrównane do górnej krawędzi. */
.sb-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}
.sb-close {
  flex: none;
  padding: 0;
  border: 0;
  background: none;
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: 4px;
}
.sb-close:hover { color: var(--text); }
.sb-close:focus-visible {
  outline: 2px solid var(--text);
  outline-offset: 3px;
}

.sb-name {
  margin: 0;
  font-size: 22px;
  font-weight: 700;
}
.sb-sub {
  margin: 6px 0 0;
  font-size: 13px;
  color: var(--text-muted);
}

.sb-alert {
  padding: 12px 14px;
  border-radius: 10px;
  background: var(--danger-soft);
  font-size: 13px;
}
.sb-alert strong {
  display: block;
  font-weight: 600;
  color: var(--danger);
}
.sb-alert span {
  display: block;
  margin-top: 4px;
  color: var(--danger-text);
}
/* Żądana korekta wartości: stara przekreślona, nowa wyróżniona, żeby kierunek
   zmiany był czytelny od razu. */
.sb-alert .was,
.sb-alert .now { display: inline; margin: 0; }
.sb-alert .was { text-decoration: line-through; opacity: .7; }
.sb-alert .now { font-weight: 600; }

.sb-action {
  padding: 8px 16px;
  border-radius: 6px;
  background: var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.sb-action-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 13px;
  font-weight: 600;
}
.send-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 0;
  background: none;
  font: inherit;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  padding: 0 2px;
  border-radius: 4px;
}
.send-btn img { width: 18px; height: 18px; }
.send-btn:disabled { opacity: .4; cursor: not-allowed; }

.channels {
  display: flex;
  gap: 6px;
  align-items: center;
  flex-wrap: wrap;
}
.channel {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.channel input {
  appearance: none;
  width: 16px;
  height: 16px;
  margin: 0;
  border: 1.5px solid var(--text);
  border-radius: 4px;
  background: transparent;
  cursor: pointer;
}
.channel input:checked {
  /* Znacznik to wyeksportowana ikona z projektu (assets/check.svg). */
  background-image: url('assets/check.svg');
  background-size: 10px 9px;
  background-position: center;
  background-repeat: no-repeat;
}

.sb-section { display: flex; flex-direction: column; gap: 10px; }
.sb-section h2 {
  margin: 0;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
}

.contact-line {
  display: flex;
  align-items: center;
  gap: 10px;
}
.contact-line img { width: 20px; height: 20px; }
.contact-line a {
  color: var(--text-strong);
  text-decoration: none;
}
.contact-line a:hover { text-decoration: underline; }

.doc {
  display: flex;
  align-items: center;
  gap: 10px;
}
.doc i {
  width: 16px;
  height: 16px;
  flex: none;
  border: 1.5px solid var(--text);
  border-radius: 4px;
  background-image: url('assets/check.svg');
  background-size: 10px 9px;
  background-position: center;
  background-repeat: no-repeat;
}
/* Brakujący dokument: pusty, czerwony znacznik — to jest sygnał "na już". */
.doc.missing i {
  border-color: var(--danger);
  background-image: none;
}
.doc.missing span {
  font-weight: 600;
  color: var(--danger);
}

.stage-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 2px;
  color: var(--text-faint);
}
.stage-row img { width: 14px; height: 14px; }
.stage-row.current {
  font-weight: 600;
  color: var(--text);
}

.hist { font-size: 13px; }
.hist.recent { color: var(--text-strong); }
.hist.old { color: var(--text-muted); }

.sb-spacer { flex: 1 0 0; min-height: 0; }

.sb-open {
  align-self: stretch;
  border: 0;
  background: none;
  font: inherit;
  font-weight: 600;
  font-size: 14px;
  color: var(--text-strong);
  text-align: right;
  cursor: pointer;
  padding: 4px;
}

/* -------------------------------------------------------------- tooltip */

.chip[data-tip] { cursor: help; }
.chip[data-tip]:focus-visible {
  outline: 2px solid var(--text);
  outline-offset: 2px;
}

.tooltip {
  position: fixed;
  z-index: 10;
  max-width: 280px;
  padding: 8px 12px;
  border-radius: 8px;
  background: var(--text);
  color: #fff;
  font-size: 13px;
  font-weight: 500;
  line-height: 1.35;
  opacity: 0;
  pointer-events: none;   /* dymek nigdy nie przechwytuje kursora */
  transition: opacity .12s ease;
}
.tooltip.show { opacity: 1; }

/* ---------------------------------------------------------------- toast */

.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translate(-50%, 16px);
  padding: 10px 18px;
  border-radius: 999px;
  background: var(--text);
  color: #fff;
  font-size: 13px;
  font-weight: 500;
  opacity: 0;
  pointer-events: none;
  transition: opacity .18s ease, transform .18s ease;
}
.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* ------------------------------------------------------------ responsive */

@media (max-width: 1400px) {
  .table { overflow-x: auto; }
  .table-header, .row { min-width: 1320px; }
}

@media (max-width: 1100px) {
  :root { --sidebar-w: 380px; }
  .table-pane { padding: 24px; }
}

@media (max-width: 820px) {
  .shell { flex-direction: column; }
  .sidebar {
    width: 100%;
    height: auto;
    border-left: 0;
    border-top: 1px solid var(--border);
  }
}
