#ticket-shop-sales-statistics-view {
  --statistics-border-color: oklch(from var(--color-gray) 0.86 c h);
  --statistics-panel-color: white;
  --statistics-secondary-color: oklch(from var(--color-gray) 0.48 c h);
  --statistics-online-color: var(--color-blue);
  --statistics-local-color: var(--color-orange);

  border-top-left-radius: var(--sheet-border-radius);
  border-top-right-radius: var(--sheet-border-radius);
  width: 100%;
  max-width: 110rem;
  height: 100%;
  max-height: min(92dvh, 100lvh - 0.8rem);

  @media (width >= 1140px) and (height >= 700px) {
    &:not([hidden]) {
      border-radius: var(--sheet-border-radius);
      translate: 0% calc((100vh - 100%) / -2);
    }
  }

  > header[purpose="toolbar"] {
    > select {
      min-width: 0;
      max-width: calc(100% - 9.2rem);
      font-weight: 500;
    }

    > .reload {
      padding: 0;
      display: grid;
      place-items: center;

      > svg {
        width: 2.2rem;
        height: 2.2rem;
        display: block;
        transform-box: view-box;
        transform-origin: center;
      }

      &:disabled > svg {
        animation: ticket-shop-statistics-reload 1s linear infinite;
      }
    }
  }

  > main {
    padding: 1.6rem;
    display: grid;
    align-content: start;
    gap: 1.6rem;
    background: oklch(from var(--color-gray) 0.975 c h);
  }

  &,
  strong,
  h1,
  h2,
  h3,
  th,
  button,
  button > span,
  label {
    font-weight: 500;
  }

  .custom-period {
    display: grid;
    grid-template-columns: auto minmax(0, 22rem) auto minmax(0, 22rem);
    align-items: center;
    justify-content: end;
    gap: 0.8rem;

    &[hidden] {
      display: none;
    }

    > label {
      display: contents;
      color: var(--statistics-secondary-color);
      font-size: 1.4rem;

      > span {
        white-space: nowrap;
      }

      > input {
        border: var(--toolbar-border);
        border-radius: 100vmax;
        padding-inline: 1.6rem;
        width: 100%;
        max-width: 100%;
        min-width: 0;
        height: 4.4rem;
        color: black;
        font-size: 1.6rem;
        font-weight: 400;
        background: white;
      }
    }
  }

  .metrics {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 1.2rem;

    > article {
      border: 1px solid var(--statistics-border-color);
      border-radius: 1.6rem;
      padding: 1.6rem;
      min-width: 0;
      display: grid;
      gap: 0.4rem;
      background: var(--statistics-panel-color);

      > .label,
      > .context {
        overflow: hidden;
        color: var(--statistics-secondary-color);
        text-overflow: ellipsis;
        white-space: nowrap;
      }

      > .label {
        font-size: 1.4rem;
        font-weight: 500;
      }

      > strong {
        overflow: hidden;
        font-size: 2.8rem;
        line-height: 1.2;
        text-overflow: ellipsis;
        white-space: nowrap;
      }

      > .context {
        font-size: 1.25rem;
      }
    }
  }

  .panel {
    border: 1px solid var(--statistics-border-color);
    border-radius: 1.6rem;
    padding: 1.6rem;
    min-width: 0;
    background: var(--statistics-panel-color);

    > header {
      margin-bottom: 1.6rem;
      display: flex;
      justify-content: space-between;
      align-items: start;
      gap: 1.6rem;

      h3 {
        font-size: 1.7rem;
        line-height: 1.3;
      }

      p {
        margin-top: 0.2rem;
        color: var(--statistics-secondary-color);
        font-size: 1.35rem;
      }

      > strong {
        font-size: 1.8rem;
      }
    }
  }

  .charts {
    display: grid;
    grid-template-columns: minmax(0, 2fr) minmax(28rem, 1fr);
    gap: 1.2rem;
  }

  .revenue-chart {
    > svg {
      width: 100%;
      height: auto;
      display: block;
      overflow: visible;

      .grid {
        line {
          stroke: var(--statistics-border-color);
          stroke-width: 1;
        }

        text {
          dominant-baseline: middle;
          text-anchor: end;
        }
      }

      text {
        fill: var(--statistics-secondary-color);
        font-size: 1.2rem;
      }

      > .area {
        fill: oklch(from var(--statistics-online-color) l c h / 0.12);
      }

      > .line {
        fill: none;
        stroke: var(--statistics-online-color);
        stroke-linecap: round;
        stroke-linejoin: round;
        stroke-width: 3;
      }

      > .points circle {
        fill: white;
        stroke: var(--statistics-online-color);
        stroke-width: 3;

        &:is(:hover, :focus) {
          fill: var(--statistics-online-color);
          outline: none;
        }
      }

      > .labels text {
        text-anchor: middle;
      }
    }
  }

  .product-chart {
    > ol {
      display: grid;
      gap: 1.4rem;
      list-style: none;

      > li {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        grid-template-areas:
          "name value"
          "bar  bar";
        gap: 0.5rem 1rem;

        > .name {
          grid-area: name;
          overflow: hidden;
          font-size: 1.35rem;
          text-overflow: ellipsis;
          white-space: nowrap;
        }

        > .bar {
          grid-area: bar;
          border-radius: 100vmax;
          height: 0.8rem;
          overflow: hidden;
          background: oklch(from var(--color-gray) 0.91 c h);

          &::before {
            content: '';
            border-radius: inherit;
            width: var(--amount);
            height: 100%;
            display: block;
            background: var(--statistics-online-color);
          }
        }

        > strong {
          grid-area: value;
          font-size: 1.35rem;
        }
      }
    }
  }

  .payment-summary {
    > .payment-bar {
      border-radius: 100vmax;
      height: 1.2rem;
      overflow: hidden;
      background: linear-gradient(
        to right,
        var(--statistics-online-color) 0 var(--online),
        var(--statistics-local-color) var(--online) 100%
      );

      &.empty {
        background: oklch(from var(--color-gray) 0.91 c h);
      }
    }

    > dl {
      margin-top: 1.2rem;
      display: flex;
      flex-wrap: wrap;
      gap: 1.2rem 2.4rem;

      > div {
        display: flex;
        align-items: baseline;
        gap: 0.4rem;
        white-space: nowrap;

        &::before {
          content: '';
          border-radius: 100vmax;
          width: 0.9rem;
          height: 0.9rem;
          align-self: center;
          margin-right: 0.4rem;
          background: var(--legend-color);
        }

        &.online {
          --legend-color: var(--statistics-online-color);
        }

        &.local {
          --legend-color: var(--statistics-local-color);
        }

        > dt {
          color: var(--statistics-secondary-color);
          font-size: 1.35rem;
          font-weight: 500;

          &::after {
            content: ':';
          }
        }

        > dd {
          font-size: 1.4rem;
          font-weight: 500;
        }
      }
    }
  }

  .products {
    padding-inline: 0;
    padding-bottom: 0;

    > header {
      padding-inline: 1.6rem;
    }

    > .table-scroll {
      overflow-x: auto;
    }

    table {
      border-collapse: collapse;
      width: 100%;
      min-width: 64rem;

      th,
      td {
        border-top: 1px solid var(--statistics-border-color);
        padding: 1.2rem 1.6rem;
        text-align: right;
        white-space: nowrap;

        &:first-child {
          width: 100%;
          text-align: left;
        }
      }

      thead th {
        color: var(--statistics-secondary-color);
        font-size: 1.3rem;
        font-weight: 500;
      }

      tbody th {
        font-weight: 500;
      }

      tbody td {
        font-weight: 400;
      }

      tbody .empty > td {
        padding-block: 2.4rem;
        color: var(--statistics-secondary-color);
        text-align: center;
        white-space: normal;
      }
    }
  }

  @media (max-width: 850px) {
    .metrics {
      grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .charts {
      grid-template-columns: 1fr;
    }
  }

  @media (max-width: 520px) {
    > main {
      padding: 1.2rem;
    }

    .custom-period {
      gap: 0.6rem;

      > label {
        font-size: 1.3rem;

        > input {
          padding-inline: 0.8rem;
          font-size: 1.4rem;
        }
      }
    }

    .metrics {
      grid-template-columns: 1fr;

      > article > strong {
        font-size: 2.4rem;
      }
    }

    .panel,
    .metrics > article {
      border-radius: 1.4rem;
      padding: 1.4rem;
    }

    .revenue-chart > svg text {
      font-size: 2.2rem;
    }

    .products {
      padding-inline: 0;
    }
  }
}


@keyframes ticket-shop-statistics-reload {
  to {
    rotate: 1turn;
  }
}
