/* ============================================================================
   Statistika › Žiūrimumas page — page-scoped styles
   ----------------------------------------------------------------------------
   File layout:
     1. Page shell
     2. Breadcrumb + filter toggle (mobile)
     3. Filters bar (Rodyti TOP / kanalų pagal / Filtruoti / dates / WebTV / Atnaujinti)
     4. Chart card (header + grid + horizontal stacked bars + x-axis)
     5. Tooltip (desktop hover white card)
     6. Mobile legend + expandable channel rows
     7. Responsive — all @media queries consolidated at the end
   ============================================================================ */


/* ============================ 1. Page shell ============================ */
.app-shell[data-page="statistics-viewing"] .content-shell {
  overflow: hidden;
}

.stats-page {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  gap: 16px;
  height: 100%;
  min-height: 0;
}


/* ============================ 2. Breadcrumb + filter toggle ============================ */
.stats-breadcrumb {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-heading);
  font-size: 20px;
  line-height: 26px;
  color: var(--dark4txt);
  font-weight: 500;
}

.stats-breadcrumb a,
.stats-breadcrumb-sep,
.stats-breadcrumb-current {
  font: inherit;
  color: inherit;
}

.stats-breadcrumb a {
  text-decoration: none;
}

.stats-breadcrumb-sep {
  color: var(--grey4txt);
}

.stats-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.stats-filter-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 60px;
  height: 38px;
  border: 1px solid var(--white);
  border-radius: var(--radius-sm);
  background: var(--button-bg-color);
  cursor: pointer;
}

.stats-filter-toggle img {
  width: 16px;
  height: 16px;
}

.stats-filter-toggle .stats-filter-toggle-chevron {
  width: 12px;
  height: 12px;
  transition: transform 0.18s ease;
}

.stats-page.is-filter-open .stats-filter-toggle-chevron {
  transform: rotate(180deg);
}


/* ============================ 3. Filters bar ============================ */
.stats-filters {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 16px;
}

.stats-filter-field {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  color: var(--dark4txt);
}

.stats-filter-field>span {
  color: var(--dark4txt);
  font-size: 14px;
  white-space: nowrap;
}

/* Stepper for "Rodyti TOP" — themed to match the inputs/dropdown (white bg) */
.stats-stepper {
  display: inline-flex;
  align-items: center;
  justify-content: space-between;
  gap: 4px;
  width: 110px;
  height: 38px;
  padding: 4px 6px;
  border: 1px solid var(--white);
  border-radius: var(--radius-sm);
  background: var(--white);
}

.stats-stepper button {
  width: 28px;
  height: 28px;
  border: 0;
  border-radius: 999px;
  background: var(--button-bg-color);
  color: var(--dark4txt);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
}

.stats-stepper button:hover {
  background: rgba(0, 0, 0, 0.06);
}

.stats-stepper-value {
  flex: 1 1 auto;
  text-align: center;
  font: inherit;
  font-weight: 500;
  color: var(--dark4txt);
}

.stats-dropdown {
  position: relative;
  display: inline-flex;
  width: 160px;
}

.stats-dropdown-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  height: 38px;
  padding: 0 14px;
  border: 1px solid var(--white);
  border-radius: var(--radius-sm);
  background: var(--white);
  color: var(--dark4txt);
  font: inherit;
  font-size: 14px;
  text-align: left;
  cursor: pointer;
}

.stats-dropdown-toggle:hover {
  background: rgba(0, 0, 0, 0.03);
}

.stats-dropdown-toggle strong {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 400;
}

.stats-dropdown-toggle img {
  width: 14px;
  height: 14px;
  transition: transform 0.18s ease;
}

.stats-dropdown.is-open .stats-dropdown-toggle img {
  transform: rotate(180deg);
}

.stats-dropdown-menu {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  z-index: 30;
  margin: 0;
  padding: 6px;
  list-style: none;
  border-radius: 10px;
  background: var(--white);
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.18);
}

.stats-dropdown-menu[hidden] {
  display: none;
}

.stats-dropdown-menu button {
  width: 100%;
  padding: 8px 12px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--dark4txt);
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.stats-dropdown-menu button:hover {
  background: rgba(123, 85, 203, 0.08);
}

.stats-input {
  display: inline-flex;
  align-items: center;
  height: 38px;
  width: 180px;
  padding: 0 14px;
  border: 1px solid var(--white);
  border-radius: var(--radius-sm);
  background: var(--white);
  color: var(--dark4txt);
  font: inherit;
  font-size: 14px;
  outline: 0;
}

.stats-input::placeholder {
  color: var(--grey4txt);
}

.stats-date-wrap {
  position: relative;
  display: inline-flex;
  align-items: center;
  width: 150px;
}

.stats-date {
  width: 100%;
  height: 38px;
  padding: 0 38px 0 14px;
  border: 1px solid var(--white);
  border-radius: var(--radius-sm);
  background: var(--white);
  color: var(--dark4txt);
  font: inherit;
  font-size: 14px;
  outline: 0;
}

.stats-date-icon {
  position: absolute;
  right: 10px;
  top: 50%;
  width: 18px;
  height: 18px;
  transform: translateY(-50%);
  pointer-events: none;
}

.stats-date-sep {
  font-size: 16px;
  color: var(--dark4txt);
  padding: 0 2px;
}

.stats-check {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  color: var(--dark4txt);
  cursor: pointer;
}

.stats-check input {
  appearance: none;
  width: 22px;
  height: 22px;
  margin: 0;
  border: 1px solid var(--white);
  border-radius: 6px;
  background: var(--button-bg-color);
  cursor: pointer;
}

.stats-check input:checked::after {
  content: "✓";
  display: block;
  margin-top: -2px;
  color: var(--dark4txt);
  font-size: 16px;
  line-height: 22px;
  text-align: center;
}

/* Atnaujinti button */
.stats-refresh-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 38px;
  padding: 0 18px;
  border: 1px solid var(--white);
  border-radius: var(--radius-sm);
  background: var(--button-bg-color);
  color: var(--dark4txt);
  font: inherit;
  font-size: 14px;
  cursor: pointer;
  white-space: nowrap;
}

.stats-refresh-btn:hover {
  background: var(--white);
}


/* ============================ 4. Chart card ============================ */
.stats-chart-card {
  --stats-label-width: 140px;
  --stats-column-gap: 10px;
  --stats-axis-lines:
    linear-gradient(#cccccc, #cccccc) 0 0 / 1px 100% no-repeat,
    linear-gradient(#cccccc, #cccccc) 14.285714% 0 / 1px 100% no-repeat,
    linear-gradient(#cccccc, #cccccc) 28.571429% 0 / 1px 100% no-repeat,
    linear-gradient(#cccccc, #cccccc) 42.857143% 0 / 1px 100% no-repeat,
    linear-gradient(#cccccc, #cccccc) 57.142857% 0 / 1px 100% no-repeat,
    linear-gradient(#cccccc, #cccccc) 71.428571% 0 / 1px 100% no-repeat,
    linear-gradient(#cccccc, #cccccc) 85.714286% 0 / 1px 100% no-repeat,
    linear-gradient(#cccccc, #cccccc) 100% 0 / 1px 100% no-repeat;

  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 16px 18px 12px;
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.65);
}

.stats-chart-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
  font-family: var(--font-heading);
  font-size: 16px;
  font-weight: 600;
  color: var(--dark4txt);
}

.stats-chart-scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  scrollbar-width: none;
}

.stats-chart-scroll::-webkit-scrollbar {
  display: none;
}

.stats-chart {
  position: relative;
  isolation: isolate;
  display: grid;
  grid-template-columns: var(--stats-label-width) minmax(0, 1fr);
  column-gap: var(--stats-column-gap);
  row-gap: 0;
  align-items: stretch;
}

.stats-chart-grid {
  position: absolute;
  top: 0;
  left: calc(var(--stats-label-width) + var(--stats-column-gap));
  right: 0;
  bottom: 0;
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  pointer-events: none;
  z-index: 1;
}

.stats-chart-grid span {
  grid-row: 1;
  width: 1px;
  min-width: 1px;
  height: 100%;
  background: #cccccc;
}

.stats-chart-grid span:first-child {
  grid-column: 1 / 2;
  justify-self: start;
}

.stats-chart-grid span:nth-child(2) {
  grid-column: 1 / 2;
  justify-self: end;
}

.stats-chart-grid span:nth-child(3) {
  grid-column: 2 / 3;
  justify-self: end;
}

.stats-chart-grid span:nth-child(4) {
  grid-column: 3 / 4;
  justify-self: end;
}

.stats-chart-grid span:nth-child(5) {
  grid-column: 4 / 5;
  justify-self: end;
}

.stats-chart-grid span:nth-child(6) {
  grid-column: 5 / 6;
  justify-self: end;
}

.stats-chart-grid span:nth-child(7) {
  grid-column: 6 / 7;
  justify-self: end;
}

.stats-chart-grid span:last-child {
  grid-column: 7 / 8;
  justify-self: end;
}

.stats-row {
  display: contents;
}

.stats-row-label,
.stats-row>.stats-bar-track {
  position: relative;
  z-index: 2;
  padding: 8px 0;
  height: 40px;
  border-bottom: 1px solid #cccccc;
}

.stats-row>.stats-bar-track {
  background: var(--stats-axis-lines);
}

.stats-row-label {
  font-size: 13px;
  color: var(--dark4txt);
  text-align: right;
  padding-right: 6px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.stats-bar-track {
  display: flex;
  height: 18px;
  width: 100%;
  background: transparent;
  cursor: pointer;
}

.stats-bar-track:hover {
  filter: brightness(1.05);
}

.stats-bar-seg {
  position: relative;
  z-index: 3;
  flex: 0 0 calc(var(--w, 0) / var(--max, 3500) * 100%);
  height: 100%;
}

.stats-bar-seg.is-archive {
  background: #7b55cb;
}

.stats-bar-seg.is-video {
  background: #6cc6f5;
}

.stats-bar-seg.is-index {
  background: #1ce7a4;
}

.stats-bar-seg.is-track {
  background: #f37c89;
}

/* X-axis */
.stats-chart-xaxis {
  display: grid;
  grid-template-columns: var(--stats-label-width) minmax(0, 1fr);
  column-gap: var(--stats-column-gap);
  margin-top: 6px;
  font-size: 12px;
  color: var(--grey4txt);
}

.stats-chart-xaxis-label {
  text-align: right;
  font-size: 13px;
  color: var(--dark4txt);
}

.stats-chart-xaxis-ticks {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  position: relative;
  height: 20px;
  overflow: hidden;
}

.stats-chart-xaxis-ticks span {
  grid-row: 1;
  min-width: 34px;
  text-align: center;
}

.stats-chart-xaxis-ticks span:first-child {
  grid-column: 1 / 2;
  justify-self: start;
  text-align: left;
}

.stats-chart-xaxis-ticks span:nth-child(2) {
  grid-column: 1 / 2;
  justify-self: end;
  transform: translateX(50%);
}

.stats-chart-xaxis-ticks span:nth-child(3) {
  grid-column: 2 / 3;
  justify-self: end;
  transform: translateX(50%);
}

.stats-chart-xaxis-ticks span:nth-child(4) {
  grid-column: 3 / 4;
  justify-self: end;
  transform: translateX(50%);
}

.stats-chart-xaxis-ticks span:nth-child(5) {
  grid-column: 4 / 5;
  justify-self: end;
  transform: translateX(50%);
}

.stats-chart-xaxis-ticks span:nth-child(6) {
  grid-column: 5 / 6;
  justify-self: end;
  transform: translateX(50%);
}

.stats-chart-xaxis-ticks span:nth-child(7) {
  grid-column: 6 / 7;
  justify-self: end;
  transform: translateX(50%);
}

.stats-chart-xaxis-ticks span:last-child {
  grid-column: 7 / 8;
  justify-self: end;
  text-align: right;
  transform: none;
}


/* ============================ 5. Tooltip — desktop hover ============================ */
.stats-tooltip {
  position: fixed;
  z-index: 60;
  display: none;
  min-width: 240px;
  padding: 12px 14px;
  border-radius: 10px;
  background: var(--white);
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.18);
  font-size: 13px;
  color: var(--dark4txt);
  pointer-events: none;
}

.stats-tooltip.is-open {
  display: block;
}

.stats-tooltip-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
  font-weight: 600;
}

.stats-tooltip-rank {
  color: var(--grey4txt);
  font-size: 12px;
  font-weight: 500;
}

.stats-tooltip-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.stats-tooltip-list li {
  display: grid;
  grid-template-columns: 14px minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  font-size: 13px;
}

.stats-tooltip-swatch {
  width: 14px;
  height: 14px;
  border-radius: 3px;
}

.stats-tooltip-swatch.is-archive {
  background: #7b55cb;
}

.stats-tooltip-swatch.is-video {
  background: #6cc6f5;
}

.stats-tooltip-swatch.is-index {
  background: #1ce7a4;
}

.stats-tooltip-swatch.is-track {
  background: #f37c89;
}

.stats-tooltip-num {
  font-weight: 600;
}

.stats-tooltip-total {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid rgba(3, 5, 34, 0.08);
  font-weight: 500;
}

.stats-tooltip-total strong {
  font-weight: 700;
  margin-left: 4px;
}


/* ============================ 6. Mobile legend + mobile rows ============================ */
.stats-legend {
  display: none;
  flex-wrap: wrap;
  gap: 10px 16px;
  padding: 6px 0 10px;
  border-bottom: 1px solid rgba(3, 5, 34, 0.08);
  margin-bottom: 8px;
}

.stats-legend-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--dark4txt);
}

.stats-legend-chip::before {
  content: "";
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: var(--c, var(--grey4txt));
}

.stats-legend-chip.is-archive::before {
  --c: #7b55cb;
}

.stats-legend-chip.is-video::before {
  --c: #6cc6f5;
}

.stats-legend-chip.is-index::before {
  --c: #1ce7a4;
}

.stats-legend-chip.is-track::before {
  --c: #f37c89;
}

/* Mobile row card (only shown on mobile) */
.stats-mrow {
  display: none;
}

.stats-mrow-head {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  color: var(--dark4txt);
  margin-bottom: 4px;
}

.stats-mrow-rank {
  color: var(--grey4txt);
  font-weight: 600;
}

.stats-mrow-name {
  flex: 1 1 auto;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.stats-mrow-toggle {
  width: 18px;
  height: 18px;
  border: 0;
  background: transparent;
  cursor: pointer;
  padding: 0;
  transition: transform 0.18s ease;
}

.stats-mrow.is-open .stats-mrow-toggle {
  transform: rotate(180deg);
}

.stats-mrow-total {
  font-weight: 600;
  color: var(--dark4txt);
}

.stats-mrow-detail {
  display: none;
  margin-top: 8px;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--white);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.12);
  font-size: 13px;
}

.stats-mrow.is-open .stats-mrow-detail {
  display: block;
}

/* ============================================================================
   8. Date picker calendar — themed popup attached to a .stats-date input
   ============================================================================ */
.stats-calendar {
  position: fixed;
  z-index: 80;
  width: 280px;
  padding: 12px;
  border-radius: 12px;
  background: var(--white);
  box-shadow: 0 14px 32px rgba(0, 0, 0, 0.22);
  color: var(--dark4txt);
  font-family: var(--font-body);
  font-size: 13px;
}

.stats-calendar[hidden] {
  display: none;
}

.stats-calendar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}

.stats-calendar-label {
  font-weight: 600;
  font-size: 14px;
  color: var(--dark4txt);
}

.stats-calendar-nav {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border: 0;
  border-radius: 999px;
  background: var(--button-bg-color);
  color: var(--dark4txt);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
}

.stats-calendar-nav:hover {
  background: rgba(0, 0, 0, 0.06);
}

.stats-calendar-weekdays,
.stats-calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 2px;
}

.stats-calendar-weekdays span {
  text-align: center;
  font-size: 11px;
  color: var(--grey4txt);
  padding: 4px 0;
}

.stats-calendar-day {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 32px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--dark4txt);
  font: inherit;
  cursor: pointer;
}

.stats-calendar-day:hover {
  background: rgba(123, 85, 203, 0.08);
}

.stats-calendar-day.is-today {
  font-weight: 700;
  color: #7b55cb;
}

.stats-calendar-day.is-selected {
  background: #7b55cb;
  color: var(--white);
  font-weight: 600;
}

.stats-calendar-day.is-outside {
  color: var(--grey4txt);
  opacity: 0.45;
}

.stats-date,
.stats-date-icon {
  cursor: pointer;
}

/* ============================================================================
   7. Responsive — all @media queries consolidated at the end
   ----------------------------------------------------------------------------
   Breakpoints (each appears once):
     1024px → reflow filters to a wrapped row with shrink
      768px → switch to mobile chart cards (vertical scroll list)
   ============================================================================ */

@media (max-width: 1024px) {
  .stats-filters {
    gap: 8px 12px;
  }

  .stats-input,
  .stats-dropdown,
  .stats-date-wrap {
    min-width: 0;
    width: auto;
  }
}

@media (max-width: 768px) {
  .stats-filter-toggle {
    display: inline-flex;
  }

  .stats-filters {
    display: none;
    flex-wrap: wrap;
    align-items: stretch;
    gap: 12px 12px;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    background: transparent;
  }

  .stats-page.is-filter-open .stats-filters {
    display: flex;
  }

  .stats-filter-field {
    flex: 1 1 calc(50% - 6px);
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
  }

  .stats-filter-field>span {
    font-size: 13px;
    color: var(--dark4txt);
  }

  .stats-stepper,
  .stats-dropdown,
  .stats-input {
    width: 100%;
  }

  .stats-date-range {
    flex: 1 1 100%;
    flex-direction: row;
    align-items: center;
    gap: 8px;
  }

  .stats-date-wrap {
    flex: 1 1 0;
    width: auto;
  }

  .stats-filter-field:has(.stats-input) {
    flex: 1 1 100%;
  }

  .stats-check {
    flex: 1 1 auto;
    align-items: center;
  }

  .stats-refresh-btn {
    flex: 1 1 100%;
    justify-content: center;
  }

  .stats-legend {
    display: flex;
  }

  .stats-chart,
  .stats-chart-xaxis {
    display: none;
  }

  .stats-mrow {
    display: block;
    padding: 10px 0;
    border-bottom: 1px solid var(--text-color);
  }

  .stats-mrow:last-child {
    border-bottom: 0;
  }

  .stats-mrow .stats-bar-track {
    height: 14px;
    width: 100%;
  }
}