$primary: #135bec;
$danger: #ef4444;

:host {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

.invoice-container {
  display: flex;
  flex-direction: column;
  height: 100%;
  background: #fff;
  border-radius: 12px;
  border: 1px solid #e2e8f0;
  overflow: hidden;
  min-height: 0;
}

// ===== Header — fixed =====
.invoice-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  border-bottom: 1px solid #e2e8f0;
  background: #f8fafc;
  flex-shrink: 0;
}

.invoice-title {
  display: flex;
  align-items: center;
  gap: 8px;
  color: $primary;

  i { font-size: 16px; }

  h3 {
    font-size: 14px;
    font-weight: 700;
    margin: 0;
  }
}

.invoice-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.customer-selector {
  display: flex;
  align-items: center;
  gap: 4px;
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 0 8px;
  height: 30px;

  > i {
    color: #94a3b8;
    font-size: 12px;
  }

  :host ::ng-deep {
    .p-autocomplete-input {
      border: none !important;
      box-shadow: none !important;
      padding: 4px 8px !important;
      font-size: 12px !important;
      background: transparent !important;
    }
  }
}

.walkin-reset {
  background: none;
  border: none;
  color: #94a3b8;
  cursor: pointer;
  padding: 2px;
  font-size: 10px;

  &:hover { color: $danger; }
}

// Customer button (touch-friendly)
.customer-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  border-radius: 8px;
  border: 1px solid #e2e8f0;
  background: #fff;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  color: #1e293b;
  max-width: 200px;

  .pi-user { color: $primary; font-size: 12px; }
  .pi-chevron-down { color: #94a3b8; font-size: 10px; }

  span {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  &:hover { background: #f1f5f9; border-color: $primary; }
}

.walkin-reset-btn {
  width: 26px;
  height: 26px;
  border-radius: 6px;
  border: none;
  background: rgba($danger, 0.1);
  color: $danger;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  transition: all 0.15s;

  &:hover { background: $danger; color: #fff; }
}

.hold-btn {
  padding: 5px 12px;
  border-radius: 6px;
  border: 1px solid #cbd5e1;
  background: #fff;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  color: #475569;

  &:hover:not(:disabled) { background: #f1f5f9; }
  &:disabled { opacity: 0.5; cursor: not-allowed; }
}

.cancel-btn {
  padding: 5px 12px;
  border-radius: 6px;
  border: none;
  background: rgba($danger, 0.1);
  color: $danger;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;

  &:hover:not(:disabled) { background: $danger; color: #fff; }
  &:disabled { opacity: 0.5; cursor: not-allowed; }
}

// ===== Table Body — SCROLLABLE =====
.invoice-body {
  flex: 1;
  overflow-y: auto;
  min-height: 0;

  &::-webkit-scrollbar { width: 5px; }
  &::-webkit-scrollbar-track { background: transparent; }
  &::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 10px; }
}

.invoice-table {
  width: 100%;
  border-collapse: collapse;
  text-align: right;

  thead {
    position: sticky;
    top: 0;
    z-index: 2;

    tr {
      background: #f8fafc;
      border-bottom: 1px solid #e2e8f0;
    }

    th {
      padding: 8px 10px;
      font-size: 10px;
      font-weight: 700;
      text-transform: uppercase;
      letter-spacing: 0.05em;
      color: #64748b;
      white-space: nowrap;
    }
  }

  tbody {
    tr {
      border-bottom: 1px solid #f1f5f9;
      transition: background 0.15s;
      cursor: pointer;

      &:hover { background: #f8fafc; }

      &.selected {
        background: rgba($primary, 0.06);
        border-inline-start: 3px solid $primary;
      }
    }

    td {
      padding: 10px 10px;
      font-size: 13px;
      vertical-align: middle;
    }
  }
}

.col-qty {
  text-align: center;
  th { text-align: center; }
}

.col-discount,
.col-tax {
  text-align: center;
  th { text-align: center; }
}

.col-actions {
  width: 36px;
  text-align: center;
  th { text-align: center; }
}

// Badges for discount/tax display
.badge-discount {
  background: rgba($danger, 0.1);
  color: $danger;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 700;
}

.badge-tax {
  background: rgba($primary, 0.1);
  color: $primary;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 700;
}

.badge-none {
  color: #cbd5e1;
  font-size: 12px;
}

// Product info
.product-info {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.product-name {
  font-weight: 600;
  font-size: 13px;
  color: #1e293b;
}

.product-barcode {
  font-size: 10px;
  color: #94a3b8;
  font-family: monospace;
}

// Qty control
.qty-control {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.qty-btn {
  width: 26px;
  height: 26px;
  border-radius: 5px;
  background: #f1f5f9;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.15s;
  color: #475569;

  i { font-size: 10px; }

  &:hover { background: $primary; color: #fff; }
}

.qty-value {
  font-weight: 700;
  font-size: 14px;
  min-width: 18px;
  text-align: center;
}

// Delete button
.delete-btn {
  background: none;
  border: none;
  color: #cbd5e1;
  cursor: pointer;
  padding: 3px;
  border-radius: 5px;
  transition: all 0.15s;

  i { font-size: 13px; }

  &:hover { color: $danger; background: rgba($danger, 0.1); }
}

// Empty state
.empty-row td { padding: 40px 0 !important; }

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  color: #94a3b8;

  i { font-size: 32px; opacity: 0.4; }

  p {
    font-size: 13px;
    font-weight: 600;
    margin: 0;
  }

  .empty-hint { font-size: 11px; opacity: 0.7; }
}

// ===== Edit Bar — Touch-friendly row editor =====
.edit-bar {
  flex-shrink: 0;
  background: #f0f4ff;
  border-top: 2px solid $primary;
  padding: 10px 16px;
  animation: editBarSlide 0.15s ease-out;
}

@keyframes editBarSlide {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.edit-bar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.edit-bar-name {
  font-size: 13px;
  font-weight: 700;
  color: $primary;
}

.edit-bar-close {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  border: none;
  background: rgba(0, 0, 0, 0.06);
  color: #64748b;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;

  &:hover { background: $danger; color: #fff; }
}

.edit-bar-fields {
  display: flex;
  gap: 10px;
  align-items: flex-end;
}

.edit-field {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;

  label {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    color: #64748b;
    letter-spacing: 0.03em;
  }
}

.edit-field-control {
  display: flex;
  align-items: center;
  gap: 4px;
}

.edit-input {
  width: 100%;
  height: 44px;
  border: 2px solid #d1d5f0;
  border-radius: 10px;
  background: #fff;
  font-size: 18px;
  font-weight: 700;
  color: #1e293b;
  text-align: center;
  outline: none;
  transition: all 0.15s;
  -moz-appearance: textfield;
  touch-action: manipulation;

  &::-webkit-outer-spin-button,
  &::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
  }

  &:focus {
    border-color: $primary;
    box-shadow: 0 0 0 3px rgba($primary, 0.15);
  }
}

.edit-btn {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  font-size: 16px;
  transition: all 0.15s;
  touch-action: manipulation;

  &.minus {
    background: #fee2e2;
    color: $danger;

    &:hover { background: $danger; color: #fff; }
    &:active { transform: scale(0.95); }
  }

  &.plus {
    background: #dcfce7;
    color: #16a34a;

    &:hover { background: #16a34a; color: #fff; }
    &:active { transform: scale(0.95); }
  }
}

.edit-field-delete {
  flex: 0 0 auto;
}

.edit-delete-btn {
  height: 44px;
  padding: 0 16px;
  border-radius: 10px;
  border: none;
  background: $danger;
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: all 0.15s;
  touch-action: manipulation;
  white-space: nowrap;

  i { font-size: 14px; }

  &:hover { background: darken($danger, 10%); }
  &:active { transform: scale(0.97); }
}

// ===== Summary Footer — fixed =====
.invoice-summary {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  padding: 14px 18px;
  border-top: 1px solid #e2e8f0;
  background: #fff;
  flex-shrink: 0;
}

.summary-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.summary-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  color: #94a3b8;
  letter-spacing: 0.05em;
}

.summary-value {
  font-size: 18px;
  font-weight: 700;
  color: #475569;

  &.discount { color: $danger; }
}

.grand-total {
  align-items: flex-end;

  .summary-value {
    font-size: 28px;
    font-weight: 900;
    color: $primary;
  }
}

// ===== Customer Search Overlay =====
.cust-overlay-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.3);
  z-index: 1060;
}

.cust-overlay {
  position: fixed;
  top: 25%;
  inset-inline-start: 50%;
  transform: translate(-50%, -50%);
  width: 90%;
  max-width: 480px;
  max-height: 50vh;
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
  z-index: 1070;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: custSlide 0.15s ease-out;
}

:host-context([dir='rtl']) .cust-overlay {
  transform: translate(50%, -50%);
}

@keyframes custSlide {
  from { opacity: 0; transform: translate(-50%, -46%); }
  to { opacity: 1; transform: translate(-50%, -50%); }
}

:host-context([dir='rtl']) {
  @keyframes custSlide {
    from { opacity: 0; transform: translate(50%, -46%); }
    to { opacity: 1; transform: translate(50%, -50%); }
  }
}

.cust-overlay-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 18px;
  border-bottom: 1px solid #e2e8f0;
  flex-shrink: 0;

  > i { color: $primary; font-size: 18px; }
}

.cust-search-input {
  flex: 1;
  border: none;
  outline: none;
  font-size: 16px;
  font-weight: 500;
  color: #1e293b;
  background: transparent;

  &::placeholder { color: #94a3b8; }
}

.cust-overlay-close {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  border: 1px solid #e2e8f0;
  background: #f8fafc;
  color: #64748b;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;

  &:hover { background: $danger; color: #fff; border-color: $danger; }
}

.cust-walkin {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 18px;
  border-bottom: 1px solid #f1f5f9;
  cursor: pointer;
  transition: background 0.1s;
  font-weight: 600;
  font-size: 14px;
  color: #64748b;

  > .pi-user { font-size: 16px; }

  &:hover { background: #f8fafc; }
}

.cust-check {
  color: $primary;
  margin-inline-start: auto;
}

.cust-results {
  flex: 1;
  overflow-y: auto;
  max-height: 300px;
}

.cust-result-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 18px;
  cursor: pointer;
  border-bottom: 1px solid #f1f5f9;
  transition: background 0.1s;

  &:hover, &.active { background: #f0f4ff; }

  &:last-child { border-bottom: none; }
}

.cust-result-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.cust-result-name {
  font-size: 14px;
  font-weight: 600;
  color: #1e293b;
}

.cust-result-phone {
  font-size: 12px;
  color: #94a3b8;
  font-family: monospace;
}

.cust-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  color: $primary;

  i { font-size: 20px; }
}

.cust-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 24px;
  color: #94a3b8;

  i { font-size: 24px; opacity: 0.5; }
  span { font-size: 13px; }
}

.cust-add-new {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px 18px;
  border-top: 1px solid #e2e8f0;
  cursor: pointer;
  font-size: 13px;
  font-weight: 700;
  color: $primary;
  transition: background 0.1s;
  flex-shrink: 0;

  i { font-size: 16px; }

  &:hover { background: #f0f4ff; }
}

// New customer form
.cust-new-form {
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.cust-form-field {
  display: flex;
  flex-direction: column;
  gap: 5px;

  label {
    font-size: 12px;
    font-weight: 700;
    color: #64748b;
  }
}

.cust-form-input {
  height: 44px;
  border: 2px solid #e2e8f0;
  border-radius: 10px;
  padding: 0 14px;
  font-size: 15px;
  font-weight: 500;
  color: #1e293b;
  outline: none;
  transition: all 0.15s;

  &:focus { border-color: $primary; box-shadow: 0 0 0 3px rgba($primary, 0.12); }
  &::placeholder { color: #94a3b8; }
}

.cust-form-actions {
  display: flex;
  gap: 10px;
  margin-top: 4px;
}

.cust-form-cancel {
  flex: 1;
  height: 44px;
  border-radius: 10px;
  border: 1px solid #e2e8f0;
  background: #f8fafc;
  color: #64748b;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;

  &:hover { background: #e2e8f0; }
}

.cust-form-save {
  flex: 1;
  height: 44px;
  border-radius: 10px;
  border: none;
  background: $primary;
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: all 0.15s;

  &:hover:not(:disabled) { background: darken($primary, 10%); }
  &:disabled { opacity: 0.5; cursor: not-allowed; }
}
