// =========================================================================
// Production Packing — Account Master theme
// Tokens lifted from the Account Master screen so every GoodBooks form
// shares one visual language: white panels, soft grey inputs, indigo accent.
// =========================================================================

// ---- Tokens -------------------------------------------------------------
$am-bg:             #F6F7FB;
$am-panel-bg:       #FFFFFF;
$am-border:         #E4E6ED;
$am-border-soft:    #EEF0F4;

$am-text:           #1D2233;
$am-text-secondary: #545B6E;
$am-label:          #8A8FA3;

$am-accent:         #7B5CFA;
$am-accent-dark:    #6344E0;
$am-accent-soft:    #F0ECFE;

$am-input-bg:       #F6F7FA;
$am-input-border:   #E1E3EA;
$am-input-focus:    $am-accent;

$am-required:       #E0533D;

$am-navy:           #12172E;

$am-success:        #22A06B;
$am-success-soft:   #E7F6EF;
$am-danger:         #E0533D;
$am-danger-soft:    #FBEAE7;
$am-info:           #3B5BDB;
$am-info-soft:      #E8ECFB;

$radius-sm: 6px;
$radius-md: 8px;
$radius-pill: 999px;

$font-stack: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, sans-serif;

// ---- Mixins ---------------------------------------------------------------
@mixin field-label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: $am-label;
  margin-bottom: 6px;

  .required {
    color: $am-required;
    margin-left: 2px;
  }
}

@mixin field-input {
  width: 100%;
  height: 36px;
  padding: 0 12px;
  background: $am-input-bg;
  border: 1px solid $am-input-border;
  border-radius: $radius-sm;
  font-family: $font-stack;
  font-size: 13px;
  color: $am-text;
  transition: border-color .15s ease, box-shadow .15s ease;

  &::placeholder { color: #A6ABBB; }

//   &:hover { border-color: darken($am-input-border, 8%); }

  &:focus {
    outline: none;
    border-color: $am-input-focus;
    box-shadow: 0 0 0 3px rgba($am-accent, .14);
    background: $am-panel-bg;
  }

  &:disabled {
    background: $am-border-soft;
    color: $am-text-secondary;
    cursor: not-allowed;
  }
}

@mixin pill-button($bg, $fg, $border: transparent) {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 34px;
  padding: 0 14px;
  border-radius: $radius-sm;
  border: 1px solid $border;
  background: $bg;
  color: $fg;
  font-family: $font-stack;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  transition: filter .15s ease, background .15s ease;

  &:hover { filter: brightness(0.96); }
  &:active { filter: brightness(0.9); }
  &:disabled { opacity: .5; cursor: not-allowed; }
}

// =========================================================================
// Root
// =========================================================================
.pp {
  font-family: $font-stack;
  color: $am-text;
  background: $am-bg;
  padding: 20px 24px 32px;

  // ---- Top status bar ----------------------------------------------------
  &__topbar {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 28px;
    background: $am-panel-bg;
    border: 1px solid $am-border;
    border-radius: $radius-md;
    padding: 12px 18px;
    margin-bottom: 16px;
  }

  &__topbar-item {
    display: flex;
    flex-direction: column;
    gap: 3px;

    .pp__meta-label {
      font-size: 10px;
      font-weight: 700;
      letter-spacing: .06em;
      text-transform: uppercase;
      color: $am-label;
    }

    .pp__meta-value {
      font-size: 13px;
      font-weight: 600;
      color: $am-text;
    }

    &--link .pp__meta-value {
      color: $am-accent-dark;
    }
  }

  &__topbar-spacer { flex: 1; }

  &__status {
    display: flex;
    align-items: center;
    gap: 8px;

    select {
      @include field-input;
      width: auto;
      height: 30px;
      padding: 0 10px;
      font-weight: 600;
    }
  }

  &__status-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 12px;
    border-radius: $radius-pill;
    font-size: 12px;
    font-weight: 700;
    background: $am-success-soft;
    color: $am-success;

    &::before {
      content: "";
      width: 6px;
      height: 6px;
      border-radius: 50%;
      background: currentColor;
    }
  }

  // ---- Card shell ---------------------------------------------------------
  &__card {
    background: $am-panel-bg;
    border: 1px solid $am-border;
    border-radius: $radius-md;
    margin-bottom: 16px;
    overflow: hidden;
  }

  &__card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid $am-border-soft;

    h2 {
      margin: 0;
      font-size: 15px;
      font-weight: 700;
      color: $am-text;
    }
  }

  &__card-body {
    padding: 18px 20px 20px;
  }

  // ---- Field grid -----------------------------------------------------------
  &__grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 16px 20px;

    &--split {
      grid-template-columns: repeat(2, 1fr);
      gap: 0 10px;
    }
  }

  &__field {
    display: flex;
    flex-direction: column;
    min-width: 0;

    label { @include field-label; }

    input,
    select,
    textarea { @include field-input; }

    select {
      appearance: none;
      background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%238A8FA3' stroke-width='1.5' fill='none' fill-rule='evenodd' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
      background-repeat: no-repeat;
      background-position: right 12px center;
      padding-right: 30px;
    }

    &--date {
      position: relative;

      input[type="date"] { padding-right: 34px; }

      .pp__field-icon {
        position: absolute;
        right: 10px;
        bottom: 9px;
        color: $am-label;
        pointer-events: none;
      }
    }
  }

  &__subfield-pair {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }

  // ---- Pack Contents toolbar ------------------------------------------------
  &__toolbar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 16px 20px;
    border-bottom: 1px solid $am-border-soft;

    h2 {
      margin: 0 auto 0 0;
      font-size: 15px;
      font-weight: 700;
      color: $am-text;
    }
  }

  &__btn {
    &--add-item   { @include pill-button($am-success-soft, $am-success); }
    &--add-pack   { @include pill-button($am-accent-soft, $am-accent-dark); }
    &--delete-row { @include pill-button($am-danger-soft, $am-danger); }
  }

  // ---- Table ------------------------------------------------------------
  &__table-wrap {
    overflow-x: auto;
  }

  &__table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;

    thead th {
      position: sticky;
      top: 0;
      background: $am-bg;
      text-align: left;
      font-size: 10.5px;
      font-weight: 700;
      letter-spacing: .05em;
      text-transform: uppercase;
      color: $am-label;
      padding: 10px 14px;
      border-bottom: 1px solid $am-border;
      white-space: nowrap;
    }

    tbody td {
      padding: 10px 14px;
      border-bottom: 1px solid $am-border-soft;
      vertical-align: middle;
    }

    tbody tr:hover td { background: rgba($am-accent, .03); }

    input {
      @include field-input;
      height: 32px;
      font-size: 12.5px;
    }
  }

  &__item-cell {
    display: flex;
    align-items: center;
    gap: 10px;
  }

  &__item-tag {
    display: inline-flex;
    align-items: center;
    padding: 2px 9px;
    border-radius: $radius-pill;
    background: $am-info-soft;
    color: $am-info;
    font-size: 11px;
    font-weight: 700;
  }

  &__item-name {
    display: flex;
    flex-direction: column;
    line-height: 1.3;

    strong { font-size: 13px; font-weight: 600; color: $am-text; }
    span { font-size: 11px; color: $am-text-secondary; }
  }

  &__shade-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    background: $am-info-soft;
    color: $am-info;
    font-size: 11px;
    font-weight: 700;
  }

  // ---- Totals bar ---------------------------------------------------------
  &__totals {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 12px;
    padding: 16px 20px;
    background: $am-bg;
    border-top: 1px solid $am-border;
  }

  &__total-item {
    display: flex;
    flex-direction: column;
    gap: 3px;

    .pp__meta-label {
      font-size: 10px;
      font-weight: 700;
      letter-spacing: .05em;
      text-transform: uppercase;
      color: $am-label;
    }

    .pp__total-value {
      font-size: 15px;
      font-weight: 700;
      color: $am-text;

      &--accent { color: $am-accent-dark; }
    }

    input {
      @include field-input;
      height: 30px;
      width: 64px;
      font-weight: 700;
      text-align: center;
    }
  }

  // ---- Footer -------------------------------------------------------------
  &__footer {
    display: flex;
    align-items: flex-end;
    gap: 16px;
    background: $am-panel-bg;
    border: 1px solid $am-border;
    border-radius: $radius-md;
    padding: 16px 20px;
  }

  &__remarks {
    flex: 1;

    label { @include field-label; }
    input { @include field-input; }
  }

  &__actions {
    display: flex;
    gap: 10px;
  }

  &__btn-save   { @include pill-button($am-success, #FFFFFF); }
  &__btn-delete { @include pill-button($am-danger, #FFFFFF); }
  &__btn-clear  { @include pill-button($am-panel-bg, $am-text-secondary, $am-input-border); }
  &__btn-print  { @include pill-button($am-accent, #FFFFFF); }

  &__footnote {
    margin-top: 10px;
    text-align: right;
    font-size: 11px;
    color: $am-label;
  }

  // ---- Radio / checkbox, in case pack level / account-style toggles reuse this pattern
  &__radio-group {
    display: flex;
    flex-wrap: wrap;
    gap: 22px;
  }

  &__radio {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: $am-text;
    cursor: pointer;

    input[type="radio"] {
      appearance: none;
      width: 16px;
      height: 16px;
      border-radius: 50%;
      border: 1.5px solid #C7CBD4;
      display: grid;
      place-content: center;
      margin: 0;

      &::before {
        content: "";
        width: 8px;
        height: 8px;
        border-radius: 50%;
        transform: scale(0);
        transition: transform .12s ease;
        background: $am-accent;
      }

      &:checked {
        border-color: $am-accent;
        &::before { transform: scale(1); }
      }
    }
  }

  &__checkbox {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: $am-text;
    cursor: pointer;

    input[type="checkbox"] {
      appearance: none;
      width: 16px;
      height: 16px;
      border-radius: 4px;
      border: 1.5px solid #C7CBD4;
      display: grid;
      place-content: center;
      margin: 0;

      &::before {
        content: "";
        width: 9px;
        height: 9px;
        clip-path: polygon(14% 44%, 0 65%, 50% 100%, 100% 16%, 80% 0%, 43% 62%);
        transform: scale(0);
        transition: transform .12s ease;
        background: #FFFFFF;
      }

      &:checked {
        border-color: $am-accent;
        background: $am-accent;
        &::before { transform: scale(1); }
      }
    }
  }
}

// ---- Responsive -----------------------------------------------------------
@media (max-width: 960px) {
  .pp {
    &__grid { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
    &__totals { grid-template-columns: repeat(3, 1fr); }
    &__footer { flex-direction: column; align-items: stretch; }
    &__actions { justify-content: flex-end; flex-wrap: wrap; }
  }
}

@media (max-width: 620px) {
  .pp {
    padding: 14px;
    &__totals { grid-template-columns: repeat(2, 1fr); }
    &__topbar { gap: 16px; }
  }
}