/*
 * Wspólny standard wizualny ekranów roboczych.
 * Arkusz jest celowo ograniczony do #appShell i nie obejmuje urzędowych
 * formularzy, podglądów faktur ani dokumentów przeznaczonych do druku.
 */
#appShell {
  --ui-table-head: #f1f6f6;
  --ui-table-stripe: #fbfdfd;
  --ui-table-hover: #edf8f5;
  --ui-table-selected: #e3f4f0;
  --ui-focus: rgba(18, 129, 115, 0.2);
  --ui-info-bg: #e8f3fb;
  --ui-info-fg: #075985;
  --ui-info-line: #b9dcef;
  --ui-warn-bg: #fff5df;
  --ui-warn-fg: #8a5200;
  --ui-warn-line: #efd08c;
  --ui-error-bg: #fdecec;
  --ui-error-fg: #a12626;
  --ui-error-line: #efb7b7;
  --ui-ok-bg: #e7f6eb;
  --ui-ok-fg: #176534;
  --ui-ok-line: #b9dfc3;
  --ui-muted-bg: #eef2f4;
  --ui-muted-fg: #586873;
  --ui-muted-line: #d2dbe0;
}

#appShell main :is(
  table.kpir-table:not(.pit11-official-fields),
  table.compact-table,
  table.data-table,
  table.warehouse-table,
  table.law-status-table,
  table.mini-cost-table,
  table.mini-table
) {
  border-collapse: separate;
  border-spacing: 0;
}

#appShell main :is(
  table.kpir-table:not(.pit11-official-fields),
  table.compact-table,
  table.data-table,
  table.warehouse-table,
  table.law-status-table,
  table.mini-cost-table,
  table.mini-table
) thead th {
  background: var(--ui-table-head);
  box-shadow: inset 0 -1px 0 var(--line);
  color: #526674;
  font-size: 11px;
  font-weight: 750;
  letter-spacing: 0.025em;
  position: sticky;
  text-transform: uppercase;
  top: 0;
  z-index: 3;
}

/* W szerokich zestawieniach opis rekordu pozostaje widoczny podczas przewijania. */
#appShell main table.ui-sticky-first-column th:first-child,
#appShell main table.ui-sticky-first-column td:first-child {
  background-clip: padding-box;
  box-shadow: inset -1px 0 0 var(--line);
  left: 0;
  position: sticky;
  z-index: 2;
}

#appShell main table.ui-sticky-first-column thead th:first-child {
  background: var(--ui-table-head);
  z-index: 5;
}

#appShell main table.ui-sticky-first-column tbody tr:nth-child(odd) td:first-child {
  background-color: #fff;
}

#appShell main table.ui-sticky-first-column tbody tr:nth-child(even) td:first-child {
  background-color: var(--ui-table-stripe);
}

#appShell main table.ui-sticky-first-column tbody tr:hover td:first-child {
  background-color: var(--ui-table-hover);
}

#appShell main :is(
  table.kpir-table:not(.pit11-official-fields),
  table.compact-table,
  table.data-table,
  table.warehouse-table,
  table.law-status-table,
  table.mini-cost-table,
  table.mini-table
) tbody tr:nth-child(even):not(.selected):not(.active):not([aria-selected="true"]) td {
  background-color: var(--ui-table-stripe);
}

#appShell main :is(
  table.kpir-table:not(.pit11-official-fields),
  table.compact-table,
  table.data-table,
  table.warehouse-table,
  table.law-status-table,
  table.mini-cost-table,
  table.mini-table
) tbody tr:hover td {
  background-color: var(--ui-table-hover);
}

#appShell main :is(
  table.kpir-table:not(.pit11-official-fields),
  table.compact-table,
  table.data-table,
  table.warehouse-table,
  table.law-status-table,
  table.mini-cost-table,
  table.mini-table
) tbody tr:is(.selected, .active, [aria-selected="true"]) td {
  background-color: var(--ui-table-selected);
  box-shadow: inset 0 1px 0 #91cfc3, inset 0 -1px 0 #91cfc3;
}

#appShell main :is(.actions, .row-actions, .registry-inline-actions) button:not(.primary),
#appShell main td.actions button:not(.primary) {
  background: #fff;
  min-height: 32px;
  padding: 6px 10px;
}

#appShell main :is(.actions, .row-actions, .registry-inline-actions) button.primary,
#appShell main td.actions button.primary {
  box-shadow: 0 1px 2px rgba(12, 91, 80, 0.16);
  font-weight: 700;
}

/* Jeden porzadek dzialan: akcja glowna po prawej, pozostale obok niej. */
#appShell main :is(.actions, .row-actions, .registry-inline-actions) {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

#appShell main :is(.actions, .row-actions, .registry-inline-actions) > .primary {
  margin-left: auto;
  order: 20;
}

#appShell main button:focus-visible,
#appShell main a:focus-visible,
#appShell main input:focus-visible,
#appShell main select:focus-visible,
#appShell main textarea:focus-visible {
  outline: 3px solid var(--ui-focus);
  outline-offset: 1px;
}

#appShell main :is(.status-badge, .status-pill, .warehouse-status, .zus-registry-status) {
  align-items: center;
  border: 1px solid var(--ui-info-line);
  border-radius: 999px;
  display: inline-flex;
  font-size: 11px;
  font-weight: 750;
  line-height: 1.2;
  min-height: 22px;
  padding: 3px 8px;
  white-space: nowrap;
}

#appShell main :is(
  .status-badge.ok,
  .status-badge.success,
  .status-badge.booked,
  .status-pill.ok,
  .warehouse-status-posted,
  .warehouse-status-completed,
  .zus-registry-status-upo_received
) {
  background: var(--ui-ok-bg);
  border-color: var(--ui-ok-line);
  color: var(--ui-ok-fg);
}

#appShell main :is(
  .status-badge.warning,
  .status-pill.warning,
  .warehouse-status-draft,
  .warehouse-status-reserved,
  .zus-registry-status-prepared,
  .zus-registry-status-signing_pending,
  .zus-registry-status-sent
) {
  background: var(--ui-warn-bg);
  border-color: var(--ui-warn-line);
  color: var(--ui-warn-fg);
}

#appShell main :is(
  .status-badge.error,
  .status-pill.error,
  .status-pill.danger,
  .warehouse-status-error,
  .zus-registry-status-error
) {
  background: var(--ui-error-bg);
  border-color: var(--ui-error-line);
  color: var(--ui-error-fg);
}

#appShell main :is(
  .status-badge.muted,
  .status-pill.muted,
  .warehouse-status-cancelled,
  .zus-registry-status-cancelled
) {
  background: var(--ui-muted-bg);
  border-color: var(--ui-muted-line);
  color: var(--ui-muted-fg);
}

#appShell main :is(.status-badge, .status-pill):not(.ok):not(.success):not(.booked):not(.warning):not(.error):not(.danger):not(.muted) {
  background: var(--ui-info-bg);
  border-color: var(--ui-info-line);
  color: var(--ui-info-fg);
}

/* Lzejsze sekcje robocze: mniej ramek wewnatrz ramek. */
#appShell main .panel > :is(.panel, .books-cit-section, .books-closing-section) {
  border-left: 0;
  border-right: 0;
  border-radius: 0;
  box-shadow: none;
}

#appShell main :is(.books-cit-section, .books-closing-section) {
  border-color: var(--line);
  padding-block: 16px;
}

#appShell main :is(.books-cit-heading, .panel-title-row) h2,
#appShell main :is(.books-cit-heading, .panel-title-row) h3 {
  letter-spacing: -0.01em;
}

/* Podsumowanie CIT w czterech czytelnych grupach zamiast szeregu rownych kafelkow. */
#appShell main .books-cit-summary[data-ui-grouped="1"] {
  align-items: stretch;
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

#appShell main .books-cit-summary .ui-summary-group {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 9px;
  display: grid;
  gap: 7px;
  min-width: 0;
  padding: 11px 12px;
}

#appShell main .books-cit-summary .ui-summary-group h4 {
  color: #526674;
  font-size: 11px;
  letter-spacing: 0.04em;
  margin: 0 0 2px;
  text-transform: uppercase;
}

#appShell main .books-cit-summary .ui-summary-group > span {
  align-items: baseline;
  border: 0;
  display: flex;
  gap: 8px;
  justify-content: space-between;
  min-height: 0;
  padding: 0;
}

#appShell main .books-cit-summary .ui-summary-group > span strong {
  white-space: nowrap;
}

/* Rozbudowane filtry sa dostepne na zadanie, podstawowe pozostaja widoczne. */
#appShell main .ui-collapsible-filters [data-ui-advanced-filter="1"] {
  display: none;
}

#appShell main .ui-collapsible-filters.ui-filters-expanded [data-ui-advanced-filter="1"] {
  display: grid;
}

#appShell main .ui-filter-toggle {
  align-self: end;
  background: #fff;
  min-height: 38px;
}

/* Podglady dokumentow otwieraja sie jako boczny panel i nie zaslaniaja calej listy. */
#appShell ~ .modal-backdrop:has(.settlement-invoice-preview-modal-panel) {
  align-items: stretch;
  justify-content: flex-end;
  padding: 0;
}

#appShell ~ .modal-backdrop .settlement-invoice-preview-modal-panel {
  border-radius: 0;
  height: 100vh;
  margin: 0;
  max-height: 100vh;
  max-width: min(760px, 92vw);
  width: min(760px, 92vw);
}

/* Tryb skupienia daje szerokim zestawieniom cala przestrzen robocza. */
.ui-focus-mode-toggle {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  bottom: 18px;
  box-shadow: 0 3px 14px rgba(24, 45, 52, 0.16);
  color: #205e57;
  font-weight: 700;
  position: fixed;
  right: 18px;
  z-index: 60;
}

#appShell[hidden] ~ .ui-focus-mode-toggle {
  display: none;
}

body.ui-focus-mode #appShell {
  grid-template-columns: minmax(0, 1fr) !important;
}

body.ui-focus-mode #appShell > .sidebar {
  display: none !important;
}

body.ui-focus-mode #appShell > main {
  grid-column: 1 !important;
  max-width: none;
  width: 100%;
}

/* Wspolna wyszukiwarka i skroty administratora. */
#appShell .ui-global-search-trigger {
  align-items: center;
  display: grid;
  gap: 6px;
  grid-template-columns: auto 1fr auto;
  margin-top: 8px;
  text-align: left;
}

#appShell .ui-global-search-trigger kbd {
  background: var(--ui-muted-bg);
  border: 1px solid var(--ui-muted-line);
  border-radius: 5px;
  font-size: 10px;
  padding: 2px 4px;
}

#appShell .ui-global-search-icon {
  fill: none;
  height: 17px;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-width: 2;
  width: 17px;
}

.ui-global-search {
  align-items: flex-start;
  padding-top: min(12vh, 110px);
  z-index: 200;
}

.ui-global-search-panel {
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 18px 60px rgba(14, 35, 42, 0.28);
  max-height: min(76vh, 720px);
  max-width: 760px;
  overflow: hidden;
  padding: 18px;
  width: min(760px, calc(100vw - 28px));
}

.ui-global-search-panel header {
  align-items: center;
  display: flex;
  justify-content: space-between;
  margin-bottom: 12px;
}

.ui-global-search-panel h2,
.ui-global-search-panel small {
  margin: 0;
}

#uiGlobalSearchInput {
  font-size: 17px;
  min-height: 48px;
  width: 100%;
}

.ui-global-search-results {
  display: grid;
  gap: 6px;
  margin-top: 12px;
  max-height: 52vh;
  overflow: auto;
}

.ui-global-search-result {
  align-items: center;
  background: #fff;
  display: grid;
  gap: 4px 12px;
  grid-template-columns: 110px minmax(0, 1fr);
  padding: 10px 12px;
  text-align: left;
}

.ui-global-search-result:hover {
  background: var(--ui-table-hover);
}

.ui-global-search-result strong,
.ui-global-search-result small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ui-global-search-result small {
  grid-column: 2;
}

.ui-global-search-type {
  color: #31756c;
  font-size: 11px;
  font-weight: 750;
  grid-row: 1 / span 2;
  text-transform: uppercase;
}

.ui-global-search-empty {
  color: var(--ui-muted-fg);
  padding: 24px;
  text-align: center;
}

/* Panel kontrolny prowadzi bezposrednio do obszaru wymagajacego reakcji. */
#appShell main .month-control-card-action {
  background: #fff;
  margin-left: auto;
  min-width: 76px;
}

/* Miesieczna kontrola plac w jednym zwartym zestawieniu. */
#appShell main .hr-payroll-month-board {
  border-top: 1px solid var(--line);
  margin-top: 14px;
  padding-top: 14px;
}

#appShell main .hr-payroll-month-board > header {
  margin-bottom: 9px;
}

#appShell main .hr-payroll-month-board header small,
#appShell main .hr-payroll-month-board td small {
  display: block;
}

/* Najwazniejsze kwoty VAT pozostaja widoczne podczas dlugiego podgladu. */
#appShell main #vatRegisterSummary,
#appShell main #jpkVatSummary {
  background: rgba(255, 255, 255, 0.97);
  box-shadow: 0 1px 0 var(--line);
  position: sticky;
  top: 45px;
  z-index: 7;
}

/*
 * Podgląd JPK jest długim dokumentem, a nie przewijaną tabelą roboczą.
 * Przyklejone nagłówki i podsumowanie powodują kosztowne przeliczanie
 * setek wierszy w Firefoxie oraz potrafią uciąć dalszą część dokumentu.
 */
#appShell main #vatDeclarationsView #jpkVatSummary,
#appShell main #jpkVatPreview table th,
#appShell main #jpkVatPreview table td {
  position: static;
}

#appShell main #vatDeclarationsView #jpkVatSummary {
  box-shadow: none;
}

/* Rozrachunki sa dzielone wedlug pilnosci. */
#appShell main .contractor-settlement-group th {
  background: var(--ui-muted-bg);
  color: var(--ui-muted-fg);
  font-size: 11px;
  letter-spacing: 0.03em;
  padding: 7px 10px;
  text-align: left;
  text-transform: uppercase;
}

#appShell main .contractor-settlement-group.overdue th {
  background: var(--ui-error-bg);
  color: var(--ui-error-fg);
}

#appShell main .contractor-settlement-group.soon th {
  background: var(--ui-warn-bg);
  color: var(--ui-warn-fg);
}

#appShell main .contractor-settlement-group th span {
  float: right;
}

/* Kasa/Bank: uwaga skupia sie na nierozpoznanych pozycjach. */
#appShell main #bankSummary {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 10px;
}

#appShell main #cashBankTab .grid.two {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  min-width: 0;
}

#appShell main #cashBankTab :is(.panel, .tax-summary, .tax-summary > span) {
  box-sizing: border-box;
  min-width: 0;
}

#appShell main #cashBankTab :is(#bankSummary, #bankImportSummary) {
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
}

#appShell main #bankRows tr:has([data-bank-link-invoice]),
#appShell main #bankRows tr:has([data-bank-save-account]) {
  background: var(--ui-warn-bg);
}

/* Graficzna os zycia srodka trwalego. */
#appShell main .fixed-asset-timeline {
  display: grid;
  gap: 0;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin: 16px 0;
}

#appShell main .fixed-asset-timeline > span {
  border-top: 3px solid var(--ui-muted-line);
  display: grid;
  gap: 2px;
  padding: 12px 8px 0 0;
  position: relative;
}

#appShell main .fixed-asset-timeline > span i {
  background: var(--ui-muted-line);
  border: 3px solid #fff;
  border-radius: 50%;
  height: 13px;
  left: 0;
  position: absolute;
  top: -8px;
  width: 13px;
}

#appShell main .fixed-asset-timeline > span.done {
  border-color: #4fa58d;
}

#appShell main .fixed-asset-timeline > span.done i {
  background: #26816f;
}

#appShell main .fixed-asset-timeline > span.current {
  border-color: var(--ui-warn-line);
}

#appShell main .fixed-asset-timeline small {
  color: var(--ui-muted-fg);
}

#appShell main #fixedAssetsTab .grid.two {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  min-width: 0;
}

#appShell main #fixedAssetsTab :is(.panel, .form-grid, .tax-summary, label, input, select) {
  box-sizing: border-box;
  min-width: 0;
}

#appShell main #fixedAssetsTab .form-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

#appShell main #fixedAssetsSummary {
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
}

#appShell main .warehouse-summary article.warning {
  background: var(--ui-warn-bg);
  border-color: var(--ui-warn-line);
}

#appShell main .warehouse-summary article.muted {
  background: var(--ui-muted-bg);
}

@media (max-width: 900px) {
  #appShell main :is(
    table.kpir-table:not(.pit11-official-fields),
    table.compact-table,
    table.data-table,
    table.warehouse-table,
    table.law-status-table,
    table.mini-cost-table,
    table.mini-table
  ) thead th {
    position: static;
  }
}

@media (max-width: 1100px) {
  #appShell main .books-cit-summary[data-ui-grouped="1"] {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

/* Nawigacja robocza duzych modulow: bez wplywu na formularze i podglady urzedowe. */
#appShell main .module-workspace-nav {
  position: sticky;
  top: 0;
  z-index: 8;
  width: 100%;
  box-sizing: border-box;
  overflow-x: auto;
  flex-wrap: nowrap;
  scrollbar-width: thin;
  background: color-mix(in srgb, var(--surface, #fff) 96%, transparent);
  box-shadow: 0 1px 0 var(--line, #d7e1e5);
}

#appShell main .module-workspace-nav button {
  align-items: center;
  display: inline-flex;
  flex: 0 0 auto;
  gap: 6px;
  white-space: nowrap;
}

#appShell main .module-workspace-nav button.active {
  box-shadow: inset 0 -2px 0 currentColor;
}

#appShell main .module-nav-count {
  align-items: center;
  background: var(--warning-soft, #fff4df);
  border: 1px solid var(--warning-line, #e6c985);
  border-radius: 999px;
  color: var(--warning-ink, #795100);
  display: inline-flex;
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  justify-content: center;
  line-height: 1;
  min-width: 20px;
  padding: 3px 6px;
}

#appShell main .module-workspace-nav button.active .module-nav-count {
  background: rgba(255, 255, 255, 0.2);
  border-color: currentColor;
  color: inherit;
}

/* Kontrola kont CIT ma kilka krotkich kolumn i nie dziedziczy szerokosci obrotowki. */
#appShell main .books-cit-account-table-wrap {
  overflow-x: hidden;
}

#appShell main table.books-cit-account-table {
  min-width: 0;
  table-layout: fixed;
  width: 100%;
}

#appShell main table.books-cit-account-table th,
#appShell main table.books-cit-account-table td {
  white-space: normal;
}

#appShell main table.books-cit-account-table th:first-child,
#appShell main table.books-cit-account-table td:first-child {
  width: 42%;
}

#appShell main table.books-cit-account-table th:nth-child(2),
#appShell main table.books-cit-account-table td:nth-child(2) {
  width: 14%;
}

#appShell main table.books-cit-account-table td:nth-child(n + 3) {
  text-align: right;
  white-space: nowrap;
}

#appShell main table.books-cit-account-table .button-link {
  flex-wrap: wrap;
  gap: 4px;
  justify-content: flex-start;
  max-width: 100%;
  text-align: left;
  white-space: normal;
}

/* Formularz korekty CIT nie rozszerza calego modulu na srednich ekranach. */
#appShell main #booksTaxView .books-cit-adjustment-form {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

#appShell main #booksTaxView .books-cit-adjustment-description {
  grid-column: 1 / -1;
}

#appShell main #booksTaxView .books-cit-adjustment-form > button {
  justify-self: start;
}

@media (max-width: 700px) {
  #appShell main .books-cit-account-table-wrap {
    overflow-x: auto;
  }

  #appShell main table.books-cit-account-table {
    min-width: 680px;
  }

  #appShell main #booksTaxView .books-cit-adjustment-form {
    grid-template-columns: 1fr;
  }

  #appShell main #booksTaxView .books-cit-adjustment-description {
    grid-column: auto;
  }

  #appShell main .books-cit-summary[data-ui-grouped="1"] {
    grid-template-columns: 1fr;
  }

  .ui-focus-mode-toggle {
    bottom: 10px;
    right: 10px;
  }

  #appShell main .fixed-asset-timeline {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    row-gap: 20px;
  }

  #appShell main #fixedAssetsTab .grid.two,
  #appShell main #fixedAssetsTab .form-grid,
  #appShell main #cashBankTab .grid.two {
    grid-template-columns: 1fr;
  }

  .ui-global-search-result {
    grid-template-columns: 1fr;
  }

  .ui-global-search-result small,
  .ui-global-search-type {
    grid-column: 1;
    grid-row: auto;
  }
}

@media (max-width: 900px) {
  #appShell main .module-workspace-nav {
    position: static;
  }
}

#appShell main .invoice-view-switch button.active,
#appShell main .invoice-view-switch button[aria-pressed="true"] {
  background: var(--accent, #0f766e);
  color: #ffffff;
}
