@use "../../abstracts/variables" as *;
@use "../../abstracts/mixins" as *;

.analysis {
  position: fixed;
  top: 0;
  left: 0;
  display: flex;
  justify-content: space-between;
  align-items: start;
  width: 100%;
  height: 100vh;
  pointer-events: none;
  z-index: 2;

  .analysis-card {
    min-width: 333px;
    border-radius: #{$border-radius-extra-large};
    margin: 8px;
    pointer-events: all;

    .analysis-card-wrapper {
      width: 100%;
      background: var(--background-color);
      border-radius: #{$border-radius-large};
      padding: 16px;
      display: flex;
      flex-direction: column;
      gap: 14px;
      backdrop-filter: blur(10px);
      outline: 1px solid var(--border-color);
      outline-offset: -1px;

      .card-header {
        width: 100%;
        display: flex;
        justify-content: space-between;
        align-items: center;

        .main-header {
          line-height: 20px;
          font-size: var(--font-size-regular);
        }

        .sub-header {
          font-weight: 300;
          font-size: var(--font-size-tiny);
          color: var(--text-color);
          opacity: 0.8;
        }
      }

      .process-container {
        display: flex;
        flex-direction: column;

        .throughput-value {
          font-size: 1rem;

          .value {
            font-weight: bold;
            font-size: 1.5rem;
          }
        }

        .progress-bar-wrapper {
          display: flex;
          gap: 8px;
          margin-top: 6px;
        }

        .progress-bar {
          position: relative;
          width: 100%;
          height: 4px;
          border-radius: #{$border-radius-large};
          overflow: hidden;
          background: #fbebd7;

          .bar-fill {
            position: absolute;
            height: 100%;
            top: 0;
            left: 0;
            background: #fc9d2f;
            border-radius: #{$border-radius-large};
          }

          .bar-fill.full {
            width: 100%;
          }

          .bar-fill.partial {
            width: 0; // inline style will override this
          }
        }
      }

      .metrics-section {
        padding-top: 16px;
        border-top: 1px solid var(--border-color);

        .metric {
          display: flex;
          justify-content: space-between;
          align-items: center;
          font-size: 14px;
          margin-bottom: 8px;

          .label {
            color: var(--text-color);
          }

          .value {
            font-weight: bold;
          }
        }
      }
    }

    .production-wrapper {
      .process-container {
        display: flex;
        flex-direction: row;
        align-items: center;
        justify-content: flex-start;
        gap: 16px;
        width: 100%;

        .throughput-value {
          font-size: var(--font-size-small);
          flex: 0.8;
          display: flex;
          flex-direction: column;

          .value {
            color: var(--accent-color);
          }

          /* Let the text take available space */
        }

        .lineChart {
          flex: 1.2;
          max-width: 200px;
          height: 100px;
          position: relative;
          background-image: radial-gradient(#8d8d8da4 1px, transparent 1px);
          background-size: 10px 10px;
          border-radius: #{$border-radius-medium};

          .assetUsage {
            text-align: right;
            position: absolute;
            right: 0;
            top: 0;

            .key,
            .value {
              font-size: var(--font-size-regular);
            }
          }

          canvas {
            background: transparent;
          }
        }
      }

      .footer {
        display: flex;
        gap: 16px; // Space between cards
        margin-top: 24px;

        .footer-card {
          width: 100%;
          background: var(--background-color);
          border-radius: #{$border-radius-large};
          padding: 12px;
          display: flex;
          flex-direction: column;
          gap: 12px;
          outline: 1px solid var(--border-color);

          &:first-child {
            width: 85%;
          }

          .header {
            font-size: var(--font-size-regular);
          }

          .value-container {
            display: flex;
            flex-direction: row;
            align-items: center;
            justify-content: end;
            gap: 6px;
          }
        }

        .shiftUtilization {
          .value-container {
            flex-direction: column;
            align-items: flex-start;
            justify-content: flex-start;

            .value {
              font-size: var(--font-size-xlarge);
            }

            .progress-wrapper {
              width: 100%;
              display: flex;
              gap: 6px;

              .progress {
                border-radius: #{$border-radius-medium};
                height: 5px;

                &:nth-child(1) {
                  background: #f3c64d;
                }

                &:nth-child(2) {
                  background: #67b3f4;
                }

                &:nth-child(3) {
                  background: #7981f5;
                }
              }
            }

            .progress-indicator {
              display: flex;
              justify-content: space-between;
              width: 100%;
              gap: 6px;
              padding-top: 3px;

              .shift-wrapper {
                display: flex;
                align-items: center;
                gap: 5px;

                /* Align items vertically */
                &:nth-child(1) {
                  .indicator {
                    background: #f3c64d;
                  }
                }

                &:nth-child(2) {
                  .indicator {
                    background: #67b3f4;
                  }
                }

                &:nth-child(3) {
                  .indicator {
                    background: #7981f5;
                  }
                }

                label {
                  font-weight: 200;
                  font-size: var(--font-size-tiny);
                  position: relative;
                }

                .indicator {
                  display: inline-block;
                  width: 5px;
                  height: 5px;
                  border-radius: #{$border-radius-circle};
                }
              }
            }
          }
        }
      }
    }
  }

  .roiSummary-wrapper {
    max-width: 470px;
    background-color: var(--background-color);

    .product-info {
      display: flex;
      align-items: center;
      gap: 6px;
    }

    .playBack {
      display: flex;
      align-items: center;
      gap: 2px;
      border-radius: 66px;
      background: var(--background-color);
      padding: 6px 12px;
      border: 1px solid var(--border-color);

      svg {
        scale: 0.8;
      }

      .info {
        span {
          font-size: var(--font-size-xlarge);

          &:first-child {
            color: #31c756;
          }

          &:last-child {
            color: var(--text-color);
          }
        }
      }
    }

    .roi-details {
      display: flex;
      align-items: center;
      gap: 12px;

      .progress-wrapper {
        width: 250px;
        display: flex;
        flex-direction: column;
        gap: 6px;

        .content {
          display: flex;
          flex-direction: column;
          gap: 3px;
          align-items: center;
          font-weight: 300;

          .key {
            font-weight: 500;
            font-size: var(--font-size-large);
            color: #28b9f3;
          }
        }
      }

      .roi-progress {
        width: 100%;
      }

      .metrics {
        display: flex;
        flex-direction: column;
        gap: 6px;

        .metric-item {
          width: 100%;
          border-radius: #{$border-radius-xxx};
          border: 1px solid #00ff56;
          background: #17eb5e42;
          display: flex;
          flex-direction: column;
          padding: 4px 8px;

          &:last-child {
            align-items: center;
          }

          .metric-label {
            opacity: 0.8;
            font-size: 10px;
            font-weight: 300;
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
            span{
              margin-right: 4px;
            }
          }

          .metric-value {
            text-align: center;
            line-height: 20px;
          }
        }

        .metric-item.loss {
          background: #ff301d48;
          border: 1px solid #FF301D;
          .metric-label {
            span {
              color: #ff7a6e;
              display: inline-block;
              transform: rotate(180deg);
            }
          }
        }

        .metric-wrapper {
          display: flex;
          gap: 6px;

          .metric-item {
            padding: 8px;
            border-radius: #{$border-radius-large};
            background: var(--background-color);
            border: 1px solid var(--border-color);
          }
        }
      }
    }

    .cost-breakdown {
      background: var(--background-color);
      border: 1px solid var(--border-color);
      border-radius: #{$border-radius-extra-large};
      max-height: 20vh;
      padding: 16px;
      overflow: auto;

      .breakdown-header {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 8px;

        .section-wrapper {
          display: flex;
          gap: 6px;
          align-items: center;
        }

        .section-number {
          color: #00aaff;
        }

        .section-title {
          font-size: var(--font-size-regular);
          color: var(--text-color);
        }

        .expand-icon {
          font-size: 16px;
          color: var(--text-color);
          cursor: pointer;
          transform: rotate(90deg);
          transition: transform 0.2s linear;
        }

        .expand-icon.open {
          transform: rotate(0deg);
        }
      }

      .breakdown-table {
        width: 100%;
        border-collapse: collapse;
        border-radius: #{$border-radius-medium};
        overflow: hidden;
        outline: 1px solid var(--border-color);
        outline-offset: -1px;
        margin-top: 12px;

        th,
        td {
          color: var(--text-color);
          padding: 8px;
          text-align: left;
          border: 1px solid var(--border-color);
        }

        th {
          background-color: var(--background-color);
        }
      }
    }

    .tips-section {
      background: var(--background-color);
      border-radius: #{$border-radius-extra-large};
      outline: 1px solid var(--border-color);
      display: flex;
      flex-direction: column;
      gap: 6px;
      padding: 12px;

      .tip-header {
        display: flex;
        align-items: center;
        gap: 4px;

        .lightbulb-icon {
          @include flex-center;
        }

        .tip-title {
          color: var(--text-color);
          font-weight: 600;
        }
      }

      .tip-description {
        span {
          font-size: var(--font-size-xlarge);
          color: #34c759;

          &:first-child {
            color: #34c759;
          }

          &:nth-child(2) {
            color: #488ef6;
          }
        }
      }
    }

    .get-tips-button {
      border: none;
      border-radius: #{$border-radius-small};
      cursor: pointer;
      font-size: 14px;
      margin-top: 8px;
      display: inline-block;
      display: flex;
      justify-content: flex-end;
      background: none;

      .btn {
        color: var(--text-button-color);
        background: var(--background-color-button);
        padding: 4px 12px;
        border-radius: #{$border-radius-large};
        display: inline-block;
        text-align: center;
      }
    }
  }

  .svg-half-donut {
    position: relative;

    .label-wrapper {
      width: 100%;
      position: absolute;
      bottom: 2px;
      display: flex;
      flex-direction: column;
      justify-content: center;
      align-items: center;

      .label {
        font-size: var(--font-size-xxlarge);
      }
    }
  }
}

.breakdown-table-wrapper {
  &.closed {
    max-height: 0;
    padding: 0;
  }

  &.open {
    max-height: 500px;
  }

  .breakdown-table {
    width: 100%;
    border-collapse: collapse;

    th,
    td {
      padding: 10px;
      border: 1px solid #ddd;
      text-align: left;
    }
  }
}

// Breakdown Table Open/Close Logic