/* Statistiky */
.stats-page { max-width: 1280px; }
.stats-toolbar { position: static; margin-top: 0; padding-top: 0; display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.stats-range { display: flex; align-items: center; gap: 8px; }
.stats-range-f { display: flex; align-items: center; gap: 6px; margin: 0; }
.stats-range-f > span { font-size: 13px; color: var(--muted); }
.stats-range .date-picker { width: 172px; }
.stats-range .date-display { height: var(--ctl); min-height: var(--ctl); }
.stats-range-sep { color: var(--muted); }
.stats-seg { max-width: 100%; overflow-x: auto; }
.stats-content { transition: opacity .15s; }
.stats-content.loading { opacity: .45; pointer-events: none; }
.stats-body { display: grid; gap: 16px; }
.stats-page .card { margin-bottom: 0; }

.stats-kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; }
@media (min-width: 900px) { .stats-kpis.n8 { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.stats-kpi { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 16px; border-top: 3px solid var(--line); min-width: 0; }
.stats-kpi.money { border-top-color: var(--brand); }
.stats-kpi-label { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; }
.stats-kpi-val { font-size: 26px; font-weight: 700; line-height: 1.2; margin-top: 4px; color: var(--ink); font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.stats-kpi-val small { font-size: 15px; font-weight: 600; color: var(--muted); }
.stats-kpi-sub { font-size: 12.5px; color: var(--muted); margin-top: 2px; display: flex; flex-wrap: wrap; gap: 2px 8px; align-items: baseline; }
.stats-delta { font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; color: var(--muted); }
.stats-delta.good { color: var(--ok); }
.stats-delta.bad { color: var(--danger); }
.stats-cmp { margin: 8px 2px 0; font-size: 12.5px; color: var(--muted); }

.stats-card { padding: 16px 18px; min-width: 0; }
.stats-card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.stats-card-head h3 { margin: 0; font-size: 15px; }
.stats-note { margin: -4px 0 8px; font-size: 12.5px; color: var(--muted); }

.stats-chart-wrap { position: relative; }
.stats-chart { display: flex; align-items: stretch; gap: 6px; height: 220px; overflow-x: auto; padding-bottom: 2px; scrollbar-width: thin; }
.stats-col { flex: 1 0 0; min-width: 34px; display: grid; grid-template-rows: 18px 1fr 22px; align-items: end; text-align: center; border-radius: 6px; outline-offset: 1px; }
.stats-col:hover, .stats-col:focus-visible { background: var(--brand-soft); }
.stats-col-val { font-size: 11.5px; font-weight: 600; color: #374151; font-variant-numeric: tabular-nums; white-space: nowrap; align-self: end; }
.stats-col-bar { height: 100%; display: flex; align-items: flex-end; justify-content: center; border-bottom: 1px solid var(--line); }
.stats-col-bar span { display: block; width: min(70%, 44px); background: var(--brand); border-radius: 4px 4px 0 0; min-height: 0; transition: height .25s; }
.stats-col-bar span.zero { background: transparent; }
.stats-col-lab { font-size: 12px; color: var(--muted); align-self: center; white-space: nowrap; }

.stats-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; align-items: start; }
@media (max-width: 1100px) { .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

.stats-rank { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; }
.stats-row { min-width: 0; }
/* dlouhé názvy (zákazník s adresou a IČ, vada s dlouhým názvem): text se zalomí nejvýš na 2 řádky, čísla zůstanou v pevném sloupci vpravo */
.stats-row-top { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; align-items: baseline; gap: 0 8px; }
.stats-name { min-width: 0; display: flex; flex-direction: column; }
.stats-lab { font-size: 14px; color: var(--ink); text-decoration: none; min-width: 0; overflow: hidden; overflow-wrap: anywhere;
  display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; line-clamp: 2; }
a.stats-lab:hover { color: var(--brand-dark); text-decoration: underline; }
.stats-sub { font-size: 12px; color: var(--muted); overflow-wrap: anywhere; min-width: 0; }
.stats-num { display: contents; font-size: 14px; font-variant-numeric: tabular-nums; }
.stats-num b { font-size: 14px; text-align: right; white-space: nowrap; }
.stats-pct { font-size: 12px; color: var(--muted); min-width: 34px; text-align: right; white-space: nowrap; }
.stats-track { height: 6px; border-radius: 3px; background: var(--line-soft); margin-top: 4px; overflow: hidden; }
.stats-track span { display: block; height: 100%; background: var(--brand); border-radius: 3px; }
.stats-extra { font-size: 12px; color: var(--muted); margin-top: 2px; }
.stats-more { margin-top: 12px; border: 0; background: none; color: var(--brand-dark); font: inherit; font-size: 13px; font-weight: 600; cursor: pointer; padding: 4px 0; }
.stats-more:hover { text-decoration: underline; }

.stats-card-head .stats-note { margin: 0; }

/* tabulka vad */
.dt-filters { display: flex; flex-wrap: wrap; gap: 8px 10px; align-items: end; margin-bottom: 12px; }
.dt-search { flex: 1 1 220px; min-width: 0; }
.dt-filter { display: flex; flex-direction: column; gap: 3px; flex: 0 1 190px; min-width: 0; margin: 0; }
.dt-filter > span { font-size: 12px; color: var(--muted); font-weight: 500; }
.dt-filters input, .dt-filters select { height: 38px; min-height: 38px; }
.dt-reset { margin: 0 0 6px; }
.dt-wrap { overflow-x: clip; margin: 0 -18px; padding: 0 18px; }
.dt-wrap.hscroll { overflow-x: auto; } /* fitScroll: posouvání jen když se tabulka nevejde — posuvný předek vypne přilepenou hlavičku */
.dt-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.dt-table th { text-align: left; font-size: 12px; font-weight: 600; color: var(--muted); padding: 0; white-space: nowrap;
  position: sticky; top: var(--stick-top); z-index: 5; background: var(--surface); box-shadow: inset 0 -1px 0 var(--line); } /* čára stínem: rámeček sbalené tabulky by s přilepenou hlavičkou nejel */
.dt-table thead.stuck th { box-shadow: inset 0 -1px 0 var(--line), 0 8px 12px -10px rgba(15, 37, 61, .35); }
.dt-table th.num { text-align: right; }
.dt-sort { white-space: nowrap; border: 0; background: none; font: inherit; color: inherit; cursor: pointer; padding: 8px 8px; display: inline-flex; gap: 3px; width: 100%; justify-content: inherit; }
.dt-table th.num .dt-sort { justify-content: flex-end; }
.dt-sort:hover { color: var(--ink); }
.dt-table th[aria-sort="ascending"], .dt-table th[aria-sort="descending"] { color: var(--ink); }
.dt-arrow { min-width: 10px; display: inline-block; }
.dt-table td { padding: 8px 8px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
.dt-table td.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.dt-row { cursor: pointer; }
.dt-row:hover td, .dt-row.open td { background: #f7f9fb; }
.dt-row:focus-visible { outline: 2px solid var(--brand); outline-offset: -2px; }
.dt-code { white-space: nowrap; font-weight: 600; color: #374151; font-variant-numeric: tabular-nums; }
.dt-name { min-width: 200px; }
@media (max-width: 1100px) { .dt-name { min-width: 150px; } } /* užší desktop: tabulka se vejde bez posouvání, takže hlavička může viset */
.dt-name > span:not(.sevp) { vertical-align: middle; }
.dt-name .sevp { margin-left: 6px; font-size: 11px; vertical-align: middle; }
.dt-chev { display: inline-block; width: 14px; color: var(--muted); transition: transform .15s; font-weight: 700; }
.dt-row.open .dt-chev { transform: rotate(90deg); }
.dt-share-in { display: flex; align-items: center; justify-content: flex-end; gap: 8px; }
.dt-bar { width: 64px; height: 6px; border-radius: 3px; background: var(--line-soft); overflow: hidden; display: block; }
.dt-bar span { display: block; height: 100%; background: var(--brand); }
.dt-share-in > span:last-child { min-width: 34px; color: var(--muted); }
.dt-family, .dt-material { color: #374151; }
.dt-material { white-space: nowrap; font-size: 12.5px; }
.dt-severity { white-space: nowrap; }
.dt-none { text-align: center; color: var(--muted); padding: 24px 8px !important; }
.dt-detail-row > td { background: #f7f9fb; padding: 4px 8px 14px 30px; }
.dt-detail-head { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 6px 14px; margin: 4px 0 8px; font-size: 13px; }
.dt-plist { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; max-height: 340px; overflow-y: auto; }
.dt-plist li { display: grid; grid-template-columns: 90px minmax(0, 1.4fr) minmax(0, 1fr) 40px; gap: 10px; align-items: baseline; padding: 5px 0; border-top: 1px solid var(--line-soft); }
.dt-plist li:first-child { border-top: 0; }
.dt-pdate { color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.dt-ptitle, .dt-pcust { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.dt-pcust { color: #374151; }
.dt-pn { text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; }

/* vývoj top vad */
.trend-list { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(min(220px, 100%), 1fr)); gap: 14px 22px; }
.trend-row { min-width: 0; }
.trend-name .stats-lab { min-width: 0; display: block; white-space: nowrap; text-overflow: ellipsis; }
.trend-name { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; font-size: 13.5px; }
.trend-name .stats-lab { font-size: 13.5px; }
.trend-spark { display: flex; align-items: flex-end; gap: 2px; height: 46px; margin-top: 6px; border-bottom: 1px solid var(--line); }
.trend-spark span { flex: 1 1 0; min-width: 2px; background: color-mix(in srgb, var(--brand) 75%, #fff); border-radius: 2px 2px 0 0; }
.trend-spark span:hover { background: var(--brand-dark); }

.stats-empty { text-align: center; padding: 48px 20px; }
.stats-empty-ico { font-size: 40px; }
.stats-empty h3 { margin: 8px 0 4px; }

@media (max-width: 767px) {
  .stats-grid { grid-template-columns: 1fr; }
  .stats-kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stats-kpi-val { font-size: 22px; }
  .stats-seg { width: 100%; }
  .stats-seg button { flex: 1 0 auto; }
  .stats-card { padding: 14px; }
  .stats-toolbar { align-items: stretch; }
  .stats-toolbar .stats-seg { order: 0; }
  .stats-range { width: 100%; order: 5; }
  .stats-range-f { flex: 1 1 0; min-width: 0; }
  .stats-range .date-picker { width: auto; flex: 1; min-width: 0; }
  .stats-range-sep { display: none; }
  .stats-card-head { flex-wrap: wrap; }
  .dt-filter { flex: 1 1 calc(50% - 5px); }
  .dt-search { flex-basis: 100%; }
  /* tabulka vad jako karty: kód + název, pod tím čísla a štítky */
  .dt-wrap { margin: 0; padding: 0; overflow: visible; }
  .dt-table thead { display: block; position: sticky; top: var(--stick-top); z-index: 5; background: var(--surface); }
  .dt-table thead.stuck { box-shadow: 0 8px 12px -10px rgba(15, 37, 61, .35); }
  .dt-table thead tr { display: flex; flex-wrap: wrap; gap: 0 2px; border-bottom: 1px solid var(--line); }
  .dt-table th { border: 0; display: block; position: static; box-shadow: none !important; }
  .dt-table th.dt-share, .dt-table th.dt-family, .dt-table th.dt-material, .dt-table th.dt-code { display: none; }
  .dt-sort { padding: 6px 6px; width: auto; }
  .dt-table tbody { display: block; }
  .dt-row { display: grid; gap: 3px 10px; align-items: baseline; padding: 9px 2px; border-bottom: 1px solid var(--line-soft); }
  .dt-row td { display: block; padding: 0; border: 0; background: none !important; }
  .dt-row:hover, .dt-row.open { background: #f7f9fb; }
  .dt-code { grid-area: code; }
  .dt-name { grid-area: name; min-width: 0; }
  .dt-occurrences { grid-area: occ; }
  .dt-protocols, .dt-share, .dt-severity, .dt-family, .dt-material { grid-row: 2; font-size: 12.5px; color: var(--muted); }
  .dt-row { grid-template-areas: "code name name name name occ" "prot share sev fam fam fam"; grid-template-columns: auto auto auto auto minmax(0, 1fr) auto; }
  .dt-protocols { grid-area: prot; text-align: left !important; }
  td.dt-protocols::after { content: " prot."; }
  .dt-share { grid-area: share; }
  .dt-share .dt-bar { display: none; }
  .dt-severity { grid-area: sev; }
  .dt-family { grid-area: fam; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .dt-material { display: none !important; }
  .dt-detail-row, .dt-detail-row > td { display: block; }
  .dt-detail-row > td { padding: 4px 6px 12px; }
  .dt-plist li { grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "t n" "c d"; gap: 0 10px; }
  .dt-ptitle { grid-area: t; } .dt-pn { grid-area: n; } .dt-pcust { grid-area: c; font-size: 12.5px; } .dt-pdate { grid-area: d; font-size: 12.5px; text-align: right; }
  .dt-none { display: block; }
  .trend-list { grid-template-columns: minmax(0, 1fr); }
}
