.products-page {
  .page-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 1.25rem;

    .header-text {
      h1 { margin: 0; font-size: 1.25rem; font-weight: 600; color: var(--color-brand); }
      p { margin: 0.25rem 0 0; color: var(--color-text-secondary); font-size: 0.8125rem; }
    }

    .header-actions {
      display: flex;
      gap: 0.5rem;
    }
  }

  .loading-state,
  .error-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 2.5rem;
    gap: 1rem;
    background: var(--color-surface);
    border-radius: 10px;

    i { font-size: 2rem; color: var(--color-danger); }
    p { color: var(--color-text-secondary); }
  }

  .table-card {
    background: var(--color-surface);
    border-radius: 10px;
    overflow: hidden;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);

    :host ::ng-deep {
      .p-datatable {
        .p-datatable-header-cell {
          background: var(--color-surface-muted);
          font-weight: 600;
          color: var(--color-text-primary);
          white-space: nowrap;
        }
        .p-datatable-row-cell { vertical-align: middle; }
      }
      .p-paginator { border-top: 1px solid var(--color-surface-border); }
    }

    .mono { font-family: 'Courier New', monospace; font-weight: 600; }
    .action-buttons { display: flex; gap: 0.25rem; }
    .text-center { text-align: center; color: var(--color-text-muted); padding: 2rem !important; }
  }
}

// Tabbed product form
.product-tabbed-form {
  padding-top: 0 !important;
  gap: 0 !important;

  :host ::ng-deep {
    .p-tabs {
      width: 100%;
    }
    .p-tablist {
      border-bottom: 2px solid var(--color-surface-border);
    }
    .p-tab {
      padding: 0.75rem 1.25rem;
      font-size: 0.875rem;
      font-weight: 600;
      gap: 0.5rem;

      i { font-size: 1rem; }
    }
    .p-tabpanels {
      padding: 0;
    }
    .p-tabpanel {
      padding: 0;
    }
  }

  .tab-content {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    padding: 1rem 0.25rem 0.5rem;
  }
}

// Single edit dialog form
.dialog-form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding-top: 0.5rem;

  .form-field {
    display: flex;
    flex-direction: column;
    gap: 0.375rem;

    label { font-weight: 600; font-size: 0.8125rem; color: var(--color-text-primary); }
    input { width: 100%; }
    .p-error { font-size: 0.75rem; }
  }

  .form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
  }

  .switch-field-wrap {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 0.75rem;
    padding-top: 1.5rem;
  }

  .section-title {
    margin: 0.5rem 0 0;
    font-size: 1rem;
    font-weight: 600;
    color: var(--color-brand);
    border-top: 1px solid var(--color-surface-border);
    padding-top: 0.75rem;
  }

  .sub-table {
    overflow-x: auto;
    table {
      width: 100%;
      border-collapse: collapse;
      thead th {
        background: var(--color-surface-muted);
        padding: 0.5rem;
        font-size: 0.8rem;
        font-weight: 600;
        text-align: start;
        border-bottom: 1px solid var(--color-surface-border);
      }
      tbody td {
        padding: 0.4rem 0.5rem;
        border-bottom: 1px solid var(--color-surface-border);
        font-size: 0.8125rem;
      }
      .mono { font-family: 'Courier New', monospace; font-weight: 600; }
    }
  }

  .no-data-text {
    color: var(--color-text-muted);
    font-size: 0.8125rem;
    margin: 0;
  }

  .serial-hint {
    color: #64748b;
    font-size: 0.8rem;
    font-style: italic;
    margin: 0 0 0.5rem;
  }

  .add-price-row {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    margin-top: 0.5rem;

    :host ::ng-deep .p-select { min-width: 160px; }
    :host ::ng-deep .p-inputnumber { max-width: 150px; }
  }
}

// Variant builder
.variant-builder {
  .builder-label {
    display: block;
    font-weight: 600;
    font-size: 0.8125rem;
    color: var(--color-text-primary);
    margin-bottom: 0.5rem;
  }

  .attr-row {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    margin-bottom: 0.5rem;

    .attr-name {
      width: 140px;
      flex-shrink: 0;
    }
    .attr-values {
      flex: 1;
    }
  }

  .attr-actions {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.5rem;
  }
}

.variant-grid {
  margin-top: 0.75rem;

  .variant-grid-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;

    span {
      font-size: 0.8125rem;
      font-weight: 600;
      color: var(--color-accent);
    }
  }
}

// Product images
.image-section {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: flex-start;

  .image-preview {
    position: relative;
    width: 120px;
    height: 120px;
    border-radius: 8px;
    overflow: hidden;
    border: 1px solid var(--color-surface-border);

    img {
      width: 100%;
      height: 100%;
      object-fit: cover;
    }

    :host ::ng-deep p-button {
      position: absolute;
      top: 4px;
      right: 4px;
    }
  }

  .image-upload-btn {
    .upload-label {
      display: flex;
      align-items: center;
      gap: 0.5rem;
      padding: 0.5rem 1rem;
      border: 1px dashed var(--color-surface-border);
      border-radius: 8px;
      cursor: pointer;
      font-size: 0.8125rem;
      color: var(--color-text-secondary);
      transition: all 0.2s;

      &:hover {
        border-color: var(--color-accent);
        color: var(--color-accent);
      }

      i { font-size: 1rem; }
    }
  }
}

.gallery-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;

  .gallery-item {
    position: relative;
    width: 80px;
    height: 80px;
    border-radius: 6px;
    overflow: hidden;
    border: 1px solid var(--color-surface-border);

    img {
      width: 100%;
      height: 100%;
      object-fit: cover;
    }

    .gallery-delete {
      position: absolute;
      top: 2px;
      right: 2px;
    }
  }
}

.import-dialog {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;

  p { margin: 0; font-size: 0.8125rem; color: var(--color-text-secondary); }
  .import-columns { color: var(--color-text-primary); }
  .import-file-input { margin-top: 0.5rem; }
  .import-file-name { color: var(--color-brand); font-weight: 600; }
}

// ─── Tree View ───
.tree-view-card {
  background: var(--color-surface);
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 1px 2px rgba(0,0,0,0.05);

  .tree-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--color-surface-border);
    background: var(--color-surface-muted);

    .tree-title {
      font-weight: 600;
      font-size: 0.9rem;
      color: var(--color-brand);
      display: flex;
      align-items: center;
      gap: 0.5rem;

      i { font-size: 1.1rem; }
    }
  }

  .tree-loading {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 3rem;
  }

  :host ::ng-deep {
    .p-treetable {
      .p-treetable-header-cell {
        background: var(--color-surface-muted);
        font-weight: 600;
        color: var(--color-text-primary);
        white-space: nowrap;
        padding: 0.65rem 0.75rem;
        font-size: 0.8125rem;
      }
      .p-treetable-row-cell {
        vertical-align: middle;
        padding: 0.5rem 0.75rem;
        font-size: 0.8125rem;
      }
    }
  }

  .tree-cat-name {
    font-weight: 600;
    color: var(--color-brand);
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;

    i {
      color: var(--color-accent);
      font-size: 1rem;
    }

    .tree-cat-count {
      font-weight: 400;
      font-size: 0.75rem;
      color: var(--color-text-muted);
    }
  }

  .tree-cat-code {
    color: var(--color-text-muted);
  }

  .tree-product-name {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;

    i {
      color: var(--color-text-muted);
      font-size: 0.9rem;
    }
  }
}

// ─── Multi-Product Dialog: full-screen ───
:host ::ng-deep .multi-product-dialog {
  .p-dialog {
    margin: 0 !important;
    border-radius: 0 !important;
    max-height: 100vh !important;
  }
  .p-dialog-content {
    flex: 1;
    overflow: auto;
    padding: 0.75rem 1rem;
  }
}

// Defaults bar at top of multi dialog
.multi-defaults-bar {
  display: flex;
  align-items: flex-end;
  gap: 1rem;
  padding: 0.75rem 1rem;
  margin-bottom: 0.5rem;
  background: var(--color-surface-muted);
  border-radius: 0.5rem;
  border: 1px solid var(--color-surface-border);

  .default-field {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    min-width: 200px;

    label {
      font-size: 0.7rem;
      font-weight: 700;
      color: var(--color-brand);
      text-transform: uppercase;
      letter-spacing: 0.03em;
    }
  }

  .default-info {
    flex-direction: row;
    align-items: center;
    gap: 0.5rem;
    min-width: auto;
    font-size: 0.75rem;
    color: var(--color-text-muted);
    margin-inline-start: auto;

    i { font-size: 0.85rem; }
  }
}

// Multi-product table — compact mode
.multi-product-table {
  overflow-x: auto;

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

    thead th {
      background: var(--color-surface-muted);
      padding: 0.5rem 0.35rem;
      font-size: 0.75rem;
      font-weight: 600;
      color: var(--color-brand);
      text-align: start;
      white-space: nowrap;
      border-bottom: 1px solid var(--color-surface-border);
    }

    tbody td {
      padding: 0.25rem 0.2rem;
      vertical-align: middle;
      border-bottom: 1px solid var(--color-surface-border);
    }

    tbody tr:hover td {
      background: var(--color-surface-muted);
    }

    tbody tr.invalid-row td {
      background: rgba(231, 76, 60, 0.05);
    }

    .col-num {
      width: 32px;
      text-align: center;
      font-weight: 600;
      color: var(--color-text-muted);
      font-size: 0.75rem;
    }
    .col-name-wide { min-width: 200px; flex: 1; }
    .col-barcode { min-width: 120px; max-width: 140px; }
    .col-price { min-width: 90px; max-width: 110px; }
    .col-action { width: 36px; }
  }

  &.compact {
    table tbody td {
      padding: 0.15rem 0.15rem;
    }
    table thead th {
      padding: 0.4rem 0.25rem;
      font-size: 0.7rem;
    }
  }

  // Compact inputs
  ::ng-deep {
    input.p-inputtext {
      width: 100%;
      padding: 0.4rem 0.5rem;
      font-size: 0.8rem;
    }
    .p-select {
      width: 100%;
      .p-select-label {
        font-size: 0.8rem;
        padding: 0.4rem 0.5rem;
      }
    }
    .p-inputnumber {
      width: 100%;
      input {
        padding: 0.4rem 0.5rem;
        font-size: 0.8rem;
        text-align: center;
      }
    }
  }
}

// Print options
.print-options {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;

  .switch-field-wrap {
    padding-top: 0;
    gap: 0.5rem;
  }
}

.print-info {
  padding: 0.75rem;
  background: var(--color-surface-muted);
  border-radius: 8px;
  font-size: 0.8125rem;
  color: var(--color-text-secondary);
  text-align: center;
}

.multi-actions-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-top: 0.5rem;
  padding-top: 0.5rem;
  border-top: 1px solid var(--color-surface-border);

  .row-count {
    font-size: 0.75rem;
    color: var(--color-text-muted);
    font-weight: 600;
  }

  .save-progress {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.75rem;
    color: var(--color-text-secondary);
    margin-inline-start: auto;
  }
}
