.pisell-sku-detail-weighing {
  --weighing-scale: 1;
  --weighing-padding: 12px;
  --weighing-radius: 18px;
  --weighing-gap: 12px;
  --weighing-input-radius: 12px;
  width: 100%;
  padding: var(--weighing-padding);
  background: linear-gradient(180deg, #ffffff 0%, #fcfbff 100%);
  border: 1px solid #eaecf0;
  border-radius: var(--weighing-radius);
  box-shadow: 0 1px 2px rgba(16, 24, 40, 0.06);
  box-sizing: border-box;

  &__header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: var(--weighing-gap);
  }

  &__header-main {
    min-width: 0;
  }

  &__title-row {
    display: flex;
    align-items: center;
    gap: 8px;
  }

  &__connection-dot {
    flex-shrink: 0;
    width: 8px;
    height: 8px;
    border-radius: 50%;

    &--connected {
      background: #22c55e;
      box-shadow: 0 0 0 2px rgba(34, 197, 94, 0.2);
    }

    &--error {
      background: #f04438;
      box-shadow: 0 0 0 2px rgba(240, 68, 56, 0.16);
    }
  }

  &__title {
    color: #1d2939;
    font-size: clamp(14px, calc(12px + 4px * var(--weighing-scale)), 18px);
    font-weight: 600;
  }

  &__subtitle {
    margin-top: 4px;
    color: #667085;
    font-size: clamp(12px, calc(11px + 2px * var(--weighing-scale)), 14px);
    line-height: 1.4;

    &--error {
      color: #f04438;
      font-weight: 500;
    }
  }

  &__mode-switcher {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px;
    background: #fff;
    border: 1px solid #eaecf0;
    border-radius: 12px;
    box-shadow: 0 1px 2px rgba(16, 24, 40, 0.04);
  }

  &__mode-tab {
    flex-shrink: 0;
    min-width: 56px;
    padding: 0 10px;
    color: #667085;
    font-size: 12px;
    font-weight: 600;
    line-height: 28px;
    white-space: nowrap;
    background: transparent;
    border: 1px solid transparent;
    border-radius: 8px;
    cursor: pointer;
    transition:
      color 0.2s ease,
      border-color 0.2s ease,
      background-color 0.2s ease,
      box-shadow 0.2s ease;

    &--active {
      color: var(--theme-color, #5d3f9f);
      background: rgba(93, 63, 159, 0.08);
      border-color: rgba(93, 63, 159, 0.24);
      box-shadow: 0 1px 2px rgba(16, 24, 40, 0.04);
    }

    &:hover {
      color: var(--theme-color, #5d3f9f);
    }

    &:focus-visible {
      outline: none;
      box-shadow: 0 0 0 3px rgba(93, 63, 159, 0.12);
    }
  }

  &__tare-quick-bar {
    --tare-quick-bar-edge-padding: max(
      4px,
      calc(6px * var(--weighing-scale))
    );
    display: flex;
    gap: 6px;
    margin:
      calc(var(--weighing-gap) - 4px)
      calc(var(--tare-quick-bar-edge-padding) * -1)
      -4px;
    padding: 4px var(--tare-quick-bar-edge-padding);
    overflow-x: auto;
    overscroll-behavior-x: contain;
    scroll-padding-inline: var(--tare-quick-bar-edge-padding);
    scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;

    &::-webkit-scrollbar {
      display: none;
    }

    &--expanded {
      gap: var(--weighing-gap);
    }
  }

  &__tare-chip {
    flex-shrink: 0;
    display: inline-flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    gap: 5px;
    min-width: max(44px, calc(36px + 12px * var(--weighing-scale)));
    padding:
      clamp(5px, calc(4px + 3px * var(--weighing-scale)), 8px)
      clamp(10px, calc(8px + 5px * var(--weighing-scale)), 14px);
    color: #667085;
    background: #fff;
    border: 1px solid #d0d5dd;
    border-radius: 8px;
    cursor: pointer;
    white-space: nowrap;
    scroll-snap-align: start;
    scroll-snap-stop: always;
    transition:
      color 0.15s ease,
      border-color 0.15s ease,
      background-color 0.15s ease,
      box-shadow 0.15s ease;

    &--active {
      color: var(--theme-color, #5d3f9f);
      background: rgba(93, 63, 159, 0.08);
      border-color: rgba(93, 63, 159, 0.26);
      box-shadow: 0 2px 6px rgba(93, 63, 159, 0.1);
    }

    &:hover:not(&--active) {
      color: var(--theme-color, #5d3f9f);
      border-color: rgba(93, 63, 159, 0.26);
    }

    &:focus-visible {
      outline: none;
      box-shadow: 0 0 0 3px rgba(93, 63, 159, 0.12);
    }
  }

  &__tare-quick-bar--expanded &__tare-chip {
    flex-direction: column;
    align-items: center;
    justify-content: space-between;
    min-width: max(96px, calc(((100% - var(--weighing-gap) * 3) / 4) * 0.75));
    min-height: clamp(66px, calc(56px + 18px * var(--weighing-scale)), 76px);
    padding:
      clamp(9px, calc(7px + 5px * var(--weighing-scale)), 12px)
      clamp(10px, calc(8px + 6px * var(--weighing-scale)), 14px);
    border-radius: max(8px, calc(10px * var(--weighing-scale)));
  }

  &__tare-quick-bar--expanded &__tare-chip--no-value {
    justify-content: center;
  }

  &__tare-quick-bar--compact &__tare-chip {
    min-width: max(88px, calc(72px + 24px * var(--weighing-scale)));
    min-height: clamp(40px, calc(32px + 16px * var(--weighing-scale)), 48px);
    padding:
      clamp(10px, calc(8px + 8px * var(--weighing-scale)), 16px)
      clamp(18px, calc(16px + 12px * var(--weighing-scale)), 28px);
  }

  &__tare-chip-label {
    font-size: 13px;
    font-weight: 600;
    line-height: 1.3;
  }

  &__tare-quick-bar--expanded &__tare-chip-label {
    font-size: clamp(12px, calc(11px + 3px * var(--weighing-scale)), 14px);
  }

  &__tare-quick-bar--compact &__tare-chip-label {
    font-size: clamp(13px, calc(12px + 3px * var(--weighing-scale)), 15px);
  }

  &__tare-chip-value {
    color: #98a2b3;
    font-size: 11px;
    line-height: 1.3;

    .pisell-sku-detail-weighing__tare-chip--active & {
      color: rgba(93, 63, 159, 0.6);
    }
  }

  &__tare-quick-bar--expanded &__tare-chip-value {
    font-size: clamp(12px, calc(11px + 3px * var(--weighing-scale)), 14px);
    font-weight: 600;
  }

  &__metrics {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--weighing-gap);
    margin-top: var(--weighing-gap);
  }

  &__metric-card {
    position: relative;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    min-width: 0;
    min-height: 96px;
    padding: var(--weighing-padding);
    background: #fff;
    border: 1px solid #d0d5dd;
    border-radius: var(--weighing-radius);
    box-shadow: 0 1px 2px rgba(16, 24, 40, 0.05);
    box-sizing: border-box;
    transition:
      border-color 0.2s ease,
      box-shadow 0.2s ease,
      background-color 0.2s ease;

    &--highlight {
      background: var(--theme-color, #5d3f9f);
      border-color: var(--theme-color, #5d3f9f);
      box-shadow: 0 8px 18px rgba(93, 63, 159, 0.2);
    }

    &--interactive {
      cursor: pointer;

      &:hover {
        border-color: rgba(93, 63, 159, 0.3);
        box-shadow: 0 6px 14px rgba(93, 63, 159, 0.1);
      }

      &:focus-visible {
        outline: none;
        box-shadow: 0 0 0 3px rgba(93, 63, 159, 0.12);
      }
    }
  }

  &__metric-card--highlight.pisell-sku-detail-weighing__metric-card--interactive:hover {
    border-color: var(--theme-color, #5d3f9f);
    box-shadow: 0 10px 22px rgba(93, 63, 159, 0.26);
  }

  &__metric-icon {
    position: absolute;
    top: var(--weighing-padding);
    right: var(--weighing-padding);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--theme-color, #5d3f9f);
  }

  &__metric-card--highlight &__metric-icon {
    color: rgba(255, 255, 255, 0.8);
  }

  &__icon--spinning {
    animation: pisell-sku-detail-weighing-spin 0.45s ease;
  }

  &__metric-top {
    padding-right: 28px;
  }

  &__metric-label {
    color: #667085;
    font-size: clamp(12px, calc(11px + 2px * var(--weighing-scale)), 14px);
    font-weight: 500;
    line-height: 1.4;
  }

  &__metric-card--highlight &__metric-label {
    color: rgba(255, 255, 255, 0.8);
  }

  &__metric-description {
    margin-top: 4px;
    color: #98a2b3;
    font-size: clamp(11px, calc(10px + 2px * var(--weighing-scale)), 13px);
    line-height: 1.4;
  }

  &__metric-card--highlight &__metric-description {
    color: rgba(255, 255, 255, 0.65);
  }

  &__metric-value-row {
    display: flex;
    align-items: flex-end;
    gap: max(2px, calc(4px * var(--weighing-scale)));
    flex-wrap: nowrap;
    max-width: 100%;
    overflow: hidden;
  }

  &__metric-value-row--editable {
    display: inline-flex;
    width: fit-content;
    padding: max(4px, calc(6px * var(--weighing-scale)))
      max(6px, calc(10px * var(--weighing-scale)));
    background: #fff;
    border: 1px solid var(--theme-color, #5d3f9f);
    border-radius: var(--weighing-input-radius);
    box-shadow: 0 0 0 max(2px, calc(4px * var(--weighing-scale)))
      rgba(93, 63, 159, 0.1);
    box-sizing: border-box;
  }

  &__metric-value {
    color: #1d2939;
    font-size: clamp(24px, calc(18px + 16px * var(--weighing-scale)), 40px);
    font-weight: 600;
    line-height: 1;
    letter-spacing: -0.04em;
    word-break: break-word;
    overflow: hidden;
  }

  &__metric-card--highlight &__metric-value {
    color: #fff;
  }

  &__metric-value--editable {
    color: var(--theme-color, #5d3f9f);
  }

  &__metric-card--highlight &__metric-value--editable {
    color: var(--theme-color, #5d3f9f);
  }

  &__metric-unit {
    padding-bottom: 2px;
    color: #667085;
    font-size: clamp(12px, calc(11px + 4px * var(--weighing-scale)), 16px);
    transform: translateY(2px);
  }

  &__metric-card--highlight &__metric-unit {
    color: rgba(255, 255, 255, 0.8);
  }

  &__metric-card--highlight &__metric-value-row--editable &__metric-unit {
    color: #667085;
  }

  &__metric-input {
    width: 100%;
    max-width: 180px;
    padding: max(4px, calc(6px * var(--weighing-scale))) max(6px, calc(10px * var(--weighing-scale)));
    color: var(--theme-color, #5d3f9f);
    font-size: clamp(24px, calc(18px + 16px * var(--weighing-scale)), 40px);
    font-weight: 600;
    line-height: 1;
    letter-spacing: -0.04em;
    background: #fff;
    border: 1px solid var(--theme-color, #5d3f9f);
    border-radius: var(--weighing-input-radius);
    outline: none;
    box-shadow: 0 0 0 max(2px, calc(4px * var(--weighing-scale))) rgba(93, 63, 159, 0.1);
    box-sizing: border-box;

    &[readonly] {
      cursor: pointer;
      caret-color: transparent;
    }
  }

  &__settings-panel {
    width: min(320px, calc(100vw - 64px));
    padding: 4px;
    background: #fff;
    border-radius: 16px;
  }

  &__popover-trigger {
    display: block;
    width: 100%;
  }

  &__settings-group+&__settings-group {
    margin-top: 12px;
  }

  &__settings-group-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
  }

  &__settings-label {
    color: #1d2939;
    font-size: 13px;
    font-weight: 600;
  }

  &__settings-subtitle {
    margin-top: 6px;
    color: #667085;
    font-size: 12px;
    line-height: 1.4;
  }

  &__settings-link {
    padding: 0;
    color: var(--theme-color, #5d3f9f);
    font-size: 12px;
    font-weight: 600;
    background: transparent;
    border: none;
    cursor: pointer;

    &:hover {
      color: var(--theme-color, #5d3f9f);
    }
  }

  &__settings-tare-list {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
    max-height: 300px;
    margin-top: 8px;
    overflow-y: auto;
    padding-right: 2px;
  }

  &__settings-form {
    margin-top: 8px;
  }

  &__settings-form-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 96px auto;
    gap: 8px;
    margin-top: 8px;
  }

  &__settings-input {
    width: 100%;
    padding: 10px 12px;
    color: #1d2939;
    font-size: 13px;
    line-height: 20px;
    background: #fff;
    border: 1px solid #d0d5dd;
    border-radius: 10px;
    outline: none;
    box-sizing: border-box;

    &:focus {
      border-color: var(--theme-color, #5d3f9f);
      box-shadow: 0 0 0 3px rgba(93, 63, 159, 0.1);
    }

    &--error {
      border-color: #f04438;
      box-shadow: 0 0 0 1px rgba(240, 68, 56, 0.04);

      &:focus {
        border-color: #f04438;
        box-shadow: 0 0 0 3px rgba(240, 68, 56, 0.16);
      }
    }

    &--readonly {
      cursor: pointer;
      caret-color: transparent;
    }
  }

  &__tare-option {
    position: relative;
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 10px 34px 10px 10px;
    color: #1d2939;
    text-align: left;
    background: #fff;
    border: 1px solid #d0d5dd;
    border-radius: 12px;
    cursor: pointer;
    transition:
      border-color 0.2s ease,
      box-shadow 0.2s ease,
      background-color 0.2s ease,
      color 0.2s ease;
    box-sizing: border-box;
    overflow: hidden;

    &--active {
      color: var(--theme-color, #5d3f9f);
      background: rgba(93, 63, 159, 0.08);
      border-color: rgba(93, 63, 159, 0.26);
      box-shadow: 0 4px 12px rgba(93, 63, 159, 0.1);
    }

    &:hover {
      border-color: rgba(93, 63, 159, 0.26);
    }

    &:focus-visible {
      outline: none;
      box-shadow: 0 0 0 3px rgba(93, 63, 159, 0.1);
    }
  }

  &__tare-option-content {
    display: flex;
    flex: 1;
    min-width: 0;
    flex-direction: column;
    gap: 4px;
  }

  &__tare-option-label {
    font-size: 13px;
    font-weight: 600;
    line-height: 1.3;
    text-overflow: ellipsis;
    overflow: hidden;
    display: inline-block;
    width: 100%;
  }

  &__tare-option-value {
    color: #667085;
    font-size: 12px;
    line-height: 1.3;
  }

  &__tare-delete {
    position: absolute;
    top: 12px;
    right: 8px;
    width: 22px;
    min-width: 32px;
    height: 32px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: #98a2b3;
    background: transparent;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;

    &:hover {
      color: #e11d48;
      background: #fff3f6;
    }
  }

  &__settings-action {
    min-width: 68px;
    padding: 10px 12px;
    color: var(--theme-color, #5d3f9f);
    font-size: 13px;
    font-weight: 600;
    background: rgba(93, 63, 159, 0.08);
    border: 1px solid rgba(93, 63, 159, 0.24);
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.2s ease;

    &:hover {
      background: rgba(93, 63, 159, 0.14);
    }

    &:disabled {
      color: #98a2b3;
      background: #f2f4f7;
      border-color: #eaecf0;
      cursor: not-allowed;
      box-shadow: none;
    }
  }

  &__popover {
    max-width: min(360px, calc(100vw - 32px));
  }

  &__keyboard-popover {
    max-width: min(420px, calc(100vw - 32px));
  }

  @media screen and (max-width: 420px) {
    &__settings-form-row {
      grid-template-columns: 1fr;
    }

    &__settings-tare-list {
      grid-template-columns: 1fr;
    }

    &__metric-value-row {
      align-items: flex-end;
      gap: 4px;
    }

    &__metric-value-row--editable {
      padding: 6px 10px;
    }

    &__metric-unit {
      padding-bottom: 0;
    }
  }
}

@keyframes pisell-sku-detail-weighing-spin {
  from {
    transform: rotate(0deg);
  }

  to {
    transform: rotate(360deg);
  }
}