/* mod_xlstable — responsywna tabela z pliku Excel */

.xt {
  --xt-accent: #0b6aa2;
  --xt-text: #1d2733;
  --xt-muted: #5f6b78;
  --xt-bg: #fff;
  --xt-soft: #f4f6f8;
  --xt-line: #dde3e9;
  --xt-head: #eef2f6;
  --xt-radius: 10px;
  --xt-height: 75vh;
  --xt-sticky-top: 0px;

  --xt-c0: #0b6aa2;
  --xt-c1: #b5402a;
  --xt-c2: #2f7d4f;
  --xt-c3: #8a4fb0;
  --xt-c4: #a86c00;
  --xt-c5: #0f7f86;
  --xt-c6: #b03a73;
  --xt-c7: #4d5ba8;

  color: var(--xt-text);
  font-size: 0.95rem;
  line-height: 1.45;
  margin-block: 1rem;
}

.xt *,
.xt *::before,
.xt *::after { box-sizing: border-box; }

.xt svg {
  width: 1.1em;
  height: 1.1em;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.xt [hidden] { display: none !important; }

.xt-sr {
  position: absolute !important;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.xt-intro { margin-bottom: 1rem; }

/* ---------------------------------------------------------------- pasek */

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

.xt-search {
  position: relative;
  flex: 1 1 16rem;
  min-width: 0;
}

.xt-search-icon {
  position: absolute;
  left: 0.8rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--xt-muted);
  display: flex;
  pointer-events: none;
}

.xt .xt-search-input {
  width: 100%;
  margin: 0;
  height: 2.75rem;
  padding: 0 0.9rem 0 2.5rem;
  border: 1px solid var(--xt-line);
  border-radius: var(--xt-radius);
  background: var(--xt-bg);
  color: inherit;
  font: inherit;
  font-size: 1rem; /* 16px — iOS nie powiększa strony przy fokusie */
  box-shadow: none;
}

.xt-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.xt .xt-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  height: 2.75rem;
  margin: 0;
  padding: 0 0.95rem;
  border: 1px solid var(--xt-line);
  border-radius: var(--xt-radius);
  background: var(--xt-bg);
  color: var(--xt-text);
  font: inherit;
  font-weight: 600;
  line-height: 1;
  cursor: pointer;
  white-space: nowrap;
  text-decoration: none;
  box-shadow: none;
}

.xt .xt-btn:hover { background: var(--xt-soft); }

.xt .xt-btn-primary {
  background: var(--xt-accent);
  border-color: var(--xt-accent);
  color: #fff;
}

.xt .xt-btn-primary:hover { background: var(--xt-accent); filter: brightness(1.08); }

.xt-btn-clear { color: var(--xt-accent) !important; }

.xt-badge-count {
  min-width: 1.35rem;
  height: 1.35rem;
  padding: 0 0.35rem;
  border-radius: 999px;
  background: var(--xt-accent);
  color: #fff;
  font-size: 0.75rem;
  line-height: 1.35rem;
  text-align: center;
}

.xt-badge-count[hidden] { display: none; }

.xt :focus-visible {
  outline: 3px solid color-mix(in srgb, var(--xt-accent) 45%, transparent);
  outline-offset: 1px;
}

.xt .xt-search-input:focus,
.xt .xt-control:focus {
  border-color: var(--xt-accent);
  outline: 3px solid color-mix(in srgb, var(--xt-accent) 22%, transparent);
  outline-offset: 0;
}

/* ------------------------------------------------------- licznik, chipy */

.xt-status {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem 0.75rem;
  margin: 0.75rem 0 0.6rem;
}

.xt .xt-count {
  margin: 0;
  color: var(--xt-muted);
  font-size: 0.875rem;
}

.xt-count strong { color: var(--xt-text); }

.xt-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.xt .xt-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  max-width: 100%;
  margin: 0;
  padding: 0.3rem 0.5rem 0.3rem 0.7rem;
  border: 1px solid color-mix(in srgb, var(--xt-accent) 35%, transparent);
  border-radius: 999px;
  background: color-mix(in srgb, var(--xt-accent) 8%, #fff);
  color: var(--xt-text);
  font: inherit;
  font-size: 0.8125rem;
  line-height: 1.2;
  cursor: pointer;
}

.xt-chip-k { color: var(--xt-muted); }
.xt-chip-v { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.xt-chip svg { width: 0.95em; height: 0.95em; color: var(--xt-muted); }
.xt .xt-chip:hover { border-color: var(--xt-accent); }

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

.xt-scroll {
  max-height: var(--xt-height);
  overflow: auto;
  border: 1px solid var(--xt-line);
  border-radius: var(--xt-radius);
  background: var(--xt-bg);
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.xt-scroll[hidden] { display: none; }

.xt .xt-table {
  width: 100%;
  margin: 0;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 0.875rem;
  background: transparent;
}

.xt .xt-table thead {
  position: sticky;
  top: 0;
  z-index: 3;
}

.xt .xt-table th,
.xt .xt-table td {
  padding: 0.55rem 0.75rem;
  border: 0;
  border-bottom: 1px solid var(--xt-line);
  text-align: left;
  vertical-align: top;
  white-space: nowrap;
  background-clip: padding-box;
}

.xt .xt-table thead th {
  background: var(--xt-head);
  color: var(--xt-text);
  font-weight: 700;
  vertical-align: bottom;
}

.xt .xt-table .xt-head th { padding: 0; border-bottom: 0; }

.xt .xt-table .xt-filter-row th {
  padding: 0.15rem 0.5rem 0.55rem;
  font-weight: 400;
  border-bottom: 2px solid color-mix(in srgb, var(--xt-accent) 55%, var(--xt-line));
}

.xt .xt-table .xt-head:last-child th {
  border-bottom: 2px solid color-mix(in srgb, var(--xt-accent) 55%, var(--xt-line));
}

.xt .xt-table .xt-wide { white-space: normal; min-width: clamp(14rem, 24vw, 26rem); }

.xt .xt-table td.xt-num { font-variant-numeric: tabular-nums; }

.xt .xt-table tbody tr:nth-child(even) td { background: #fafbfc; }
.xt .xt-table tbody tr:hover td { background: color-mix(in srgb, var(--xt-accent) 6%, #fff); }

.xt .xt-sort,
.xt .xt-th-label {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 0.35rem;
  width: 100%;
  min-height: 100%;
  margin: 0;
  padding: 0.65rem 0.6rem 0.4rem 0.75rem;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  font-weight: 700;
  text-align: left;
  white-space: normal;
  line-height: 1.25;
  cursor: pointer;
  box-shadow: none;
}

.xt .xt-th-label { cursor: default; }

.xt .xt-sort:hover { color: var(--xt-accent); background: none; }

.xt .xt-sort-icon { opacity: 0.35; }
.xt .xt-sort-icon path { transition: opacity 0.15s; }
.xt th[data-dir="asc"] .xt-sort-icon,
.xt th[data-dir="desc"] .xt-sort-icon { opacity: 1; color: var(--xt-accent); }
.xt th[data-dir="asc"] .xt-dn { opacity: 0.2; }
.xt th[data-dir="desc"] .xt-up { opacity: 0.2; }
.xt th.xt-sorted { box-shadow: inset 0 -3px 0 var(--xt-accent); }

/* Pierwsza kolumna zablokowana przy przewijaniu w poziomie */
.xt .xt-freeze th:first-child,
.xt .xt-freeze td:first-child {
  position: sticky;
  left: 0;
  z-index: 1;
  background: var(--xt-bg);
  box-shadow: 1px 0 0 var(--xt-line);
}

.xt .xt-freeze thead th:first-child { z-index: 4; background: var(--xt-head); }

/* Kontrolki filtrów */
.xt .xt-control {
  display: block;
  width: 100%;
  min-width: 7rem;
  height: 2.25rem;
  margin: 0;
  padding: 0 0.55rem;
  border: 1px solid var(--xt-line);
  border-radius: 7px;
  background-color: var(--xt-bg);
  color: var(--xt-text);
  font: inherit;
  font-size: 0.8125rem;
  font-weight: 400;
  box-shadow: none;
}

.xt .xt-select {
  appearance: none;
  -webkit-appearance: none;
  padding-right: 1.8rem;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%235f6b78' stroke-width='2.5' stroke-linecap='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.5rem center;
  background-size: 0.9rem;
  text-overflow: ellipsis;
}

.xt .xt-control.xt-active {
  border-color: var(--xt-accent);
  background-color: color-mix(in srgb, var(--xt-accent) 7%, #fff);
  font-weight: 600;
}

/* Etykiety (pigułki) */
.xt-pill {
  --xt-pill: #6b7785;
  display: inline-block;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  background: color-mix(in srgb, var(--xt-pill) 13%, #fff);
  color: color-mix(in srgb, var(--xt-pill) 82%, #000);
  font-size: 0.78rem;
  font-weight: 600;
  line-height: 1.35;
  white-space: nowrap;
}

.xt mark {
  padding: 0 0.05em;
  border-radius: 3px;
  background: #ffe58a;
  color: inherit;
}

.xt .xt-link {
  color: var(--xt-accent);
  text-decoration: none;
  word-break: break-word;
}

.xt .xt-link:hover { text-decoration: underline; }

/* ----------------------------------------------------------------- karty */

.xt-mode-cards .xt-toolbar {
  position: sticky;
  top: var(--xt-sticky-top);
  z-index: 5;
  padding: 0.5rem 0;
  margin-top: -0.5rem;
  background: var(--xt-page-bg, #fff);
}

@media (max-width: 640px) {
  .xt-mode-cards .xt-search { flex-basis: 100%; }
  .xt-mode-cards .xt-actions { width: 100%; }
  .xt-mode-cards .xt-btn-filters { flex: 1; }
}
.xt-mode-table .xt-btn-filters { display: none !important; }

.xt-cards {
  --xt-gap: 0.75rem;
  display: grid;
  gap: var(--xt-gap);
  align-items: start;
  /* automatycznie: tyle kolumn, ile się zmieści (min. szerokość karty) */
  grid-template-columns: repeat(auto-fill, minmax(min(100%, var(--xt-card-min, 22rem)), 1fr));
}

/* stała liczba kolumn = maksimum; na węższych ekranach mniej, aż do 1 na telefonie */
.xt-cards-fixed .xt-cards {
  grid-template-columns: repeat(auto-fill, minmax(min(100%, max(var(--xt-card-min, 18rem), calc((100% - (var(--xt-cols) - 1) * var(--xt-gap)) / var(--xt-cols)))), 1fr));
}

/* równa wysokość kart w wierszu (do najwyższej) */
.xt-cards-equal .xt-cards { align-items: stretch; }
.xt-cards-equal .xt-card { display: flex; flex-direction: column; }
.xt-cards-equal .xt-card > .xt-dl { margin-bottom: 0.55rem; }
.xt-cards-equal .xt-card > .xt-more-info { margin-top: auto; }

.xt-cards[hidden] { display: none; }

.xt-card {
  container-type: inline-size;
  padding: 0.95rem 1rem 0.85rem;
  border: 1px solid var(--xt-line);
  border-left: 4px solid var(--xt-accent);
  border-radius: var(--xt-radius);
  background: var(--xt-bg);
  box-shadow: 0 1px 2px rgba(16, 24, 40, 0.04);
}

.xt-card-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  margin-bottom: 0.45rem;
}

.xt-card-badges .xt-pill { white-space: normal; }

.xt .xt-card-title {
  margin: 0 0 0.6rem;
  padding: 0;
  font-size: 1rem;
  font-weight: 700;
  line-height: 1.3;
  color: var(--xt-text);
  text-transform: none;
  letter-spacing: 0;
}

.xt .xt-dl {
  display: grid;
  /* kolumna etykiet = najdłuższa etykieta, maks. 40% karty */
  grid-template-columns: fit-content(40%) minmax(0, 1fr);
  align-items: baseline;
  gap: 0.3rem 0.75rem;
  margin: 0;
}

.xt-dl-row {
  display: contents;
  font-size: 0.875rem;
}

.xt .xt-dl dt,
.xt .xt-dl dd { font-size: 0.875rem; }

.xt .xt-dl dt {
  margin: 0;
  color: var(--xt-muted);
  font-weight: 400;
}

.xt .xt-dl dd {
  margin: 0;
  overflow-wrap: anywhere;
}

.xt .xt-dl .xt-link {
  display: inline-flex;
  align-items: baseline;
  gap: 0.35rem;
  max-width: 100%;
}

.xt .xt-dl .xt-link svg { align-self: center; flex: none; }

/* długie e-maile łamią się po @ i kropkach, ikona zostaje przy tekście */
.xt .xt-dl .xt-link > span { min-width: 0; overflow-wrap: break-word; }

.xt-more-info {
  margin-top: 0.55rem;
  min-height: 0;
  border-top: 1px dashed var(--xt-line);
}

.xt-more-info > summary {
  padding: 0.55rem 0 0.15rem;
  color: var(--xt-accent);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  list-style-position: inside;
}

.xt-more-info[open] > summary { margin-bottom: 0.4rem; }

/* bardzo wąska karta: etykieta nad wartością */
@container (max-width: 270px) {
  .xt .xt-dl { grid-template-columns: minmax(0, 1fr); row-gap: 0; }
  .xt .xt-dl dd + dt { margin-top: 0.3rem; }
  .xt .xt-dl dt { font-size: 0.78rem; }
}

/* ------------------------------------------------------ puste, więcej */

.xt .xt-empty {
  margin: 0.5rem 0;
  padding: 2rem 1rem;
  border: 1px dashed var(--xt-line);
  border-radius: var(--xt-radius);
  color: var(--xt-muted);
  text-align: center;
}

.xt-empty[hidden],
.xt-more[hidden] { display: none; }

.xt-more {
  display: flex;
  justify-content: center;
  margin-top: 0.85rem;
}

.xt-mode-cards .xt-btn-more { width: 100%; }

.xt .xt-updated {
  margin: 0.6rem 0 0;
  color: var(--xt-muted);
  font-size: 0.8125rem;
}

/* --------------------------------------------- panel filtrów (mobile) */

.xt-panel {
  width: min(32rem, 100%);
  max-width: 100%;
  max-height: min(88vh, 100%);
  margin: auto auto 0;
  padding: 0;
  border: 0;
  border-radius: 16px 16px 0 0;
  background: var(--xt-bg);
  color: var(--xt-text);
  box-shadow: 0 -8px 30px rgba(0, 0, 0, 0.18);
  overflow: hidden;
}

.xt-panel[open] { display: flex; flex-direction: column; }

.xt-panel::backdrop { background: rgba(15, 23, 32, 0.45); }

@media (min-width: 640px) {
  .xt-panel { margin: auto; border-radius: 16px; }
}

.xt-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.85rem 0.85rem 0.85rem 1.1rem;
  border-bottom: 1px solid var(--xt-line);
}

.xt .xt-panel-title {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 700;
}

.xt .xt-icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2.5rem;
  height: 2.5rem;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--xt-muted);
  cursor: pointer;
}

.xt .xt-icon-btn:hover { background: var(--xt-soft); }
.xt .xt-icon-btn svg { width: 1.35rem; height: 1.35rem; }

.xt-panel-body {
  flex: 1;
  overflow-y: auto;
  padding: 0.9rem 1.1rem;
  display: grid;
  gap: 0.85rem;
  align-content: start;
}

.xt-field label {
  display: block;
  margin: 0 0 0.3rem;
  font-size: 0.875rem;
  font-weight: 600;
}

.xt .xt-panel .xt-control {
  height: 2.75rem;
  font-size: 1rem;
}

.xt-panel-foot {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.5rem;
  padding: 0.75rem 1.1rem calc(0.75rem + env(safe-area-inset-bottom));
  border-top: 1px solid var(--xt-line);
}

/* ------------------------------------- rozwinięty blok filtrów (siatka) */

.xt-filterbox {
  margin-top: 0.75rem;
  border: 1px solid var(--xt-line);
  border-radius: var(--xt-radius);
  background: var(--xt-soft);
}

.xt .xt-filterbox-toggle {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  margin: 0;
  padding: 0.65rem 0.9rem;
  border: 0;
  background: none;
  color: var(--xt-text);
  font: inherit;
  font-weight: 700;
  text-align: left;
  cursor: pointer;
  box-shadow: none;
}

.xt .xt-filterbox-toggle:hover { color: var(--xt-accent); background: none; }
.xt-filterbox-title { flex: none; }
.xt .xt-chevron { margin-left: auto; transition: transform 0.15s; }
.xt-filterbox-toggle[aria-expanded="false"] .xt-chevron { transform: rotate(180deg); }

.xt-filterbox-grid {
  display: grid;
  /* tyle pól w wierszu, ile się zmieści — ale nigdy mniej niż 2 */
  grid-template-columns: repeat(auto-fill, minmax(min(var(--xt-field-w, 180px), calc(50% - 0.375rem)), 1fr));
  gap: 0.6rem 0.75rem;
  align-items: end; /* pola wyrównane do dołu, gdy etykieta zawija się w dwie linie */
  padding: 0 0.9rem 0.9rem;
}

.xt-filterbox .xt-field { min-width: 0; }

.xt .xt-filterbox .xt-field label {
  margin-bottom: 0.25rem;
  font-size: 0.8125rem;
  line-height: 1.25;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.xt .xt-filterbox .xt-control {
  min-width: 0;
  height: 2.5rem;
  font-size: 0.875rem;
}

/* sortowanie w bloku tylko w widoku kart — w tabeli sortują nagłówki */
.xt-mode-table .xt-filterbox .xt-field-sort { display: none; }

@media (max-width: 640px) {
  .xt-filterbox-grid { padding: 0 0.7rem 0.75rem; gap: 0.5rem; }
  .xt .xt-filterbox-toggle { padding: 0.6rem 0.7rem; }
  .xt .xt-filterbox .xt-control { font-size: 1rem; padding: 0 0.5rem; } /* iOS: bez powiększania przy fokusie */
  .xt .xt-filterbox .xt-select { padding-right: 1.6rem; }
}

@media print {
  .xt-toolbar, .xt-chips, .xt-more, .xt-filter-row, .xt-panel, .xt-filterbox { display: none !important; }
  .xt-scroll { max-height: none; overflow: visible; border: 0; }
  .xt .xt-table thead { position: static; }
  .xt-more-info { display: block; }
}
