@use "sass:color";

$font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
$bg-color: #f8f9fa;
$card-bg: #ffffff;
$border-color: #e5e7eb;
$text-primary: #1f2937;
$text-secondary: #6b7280;
$text-muted: #9ca3af;
$primary-color: #7b1fa2;
$primary-light: #f3e5f5;

.edit-order-page {
  font-family: $font-family;
  background-color: $bg-color;
  min-height: 100vh;
  padding: 24px 40px;
}

/* ================================
   HEADER
   ================================ */
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 24px;
  padding-bottom: 16px;
  border-bottom: 1px solid $border-color;
}

.header-left {
  .page-title {
    font-size: 20px;
    font-weight: 600;
    color: $primary-color;
    margin: 0 0 4px 0;
  }

  .page-subtitle {
    font-size: 13px;
    color: $text-secondary;
    margin: 0;
    display: flex;
    align-items: center;
    gap: 12px;
  }
}

.header-right {
  display: flex;
  gap: 12px;
  align-items: center;
}

/* ================================
   BUTTONS
   ================================ */
.btn-primary {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: $primary-color;
  color: #fff;
  border: none;
  padding: 10px 20px;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s;

  mat-icon {
    font-size: 18px;
    width: 18px;
    height: 18px;
  }

  &:hover:not(:disabled) {
    background: color.adjust($primary-color, $lightness: -10%);
  }

  &:disabled {
    opacity: 0.6;
    cursor: not-allowed;
  }
}

.btn-outline {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: $card-bg;
  color: $text-primary;
  border: 1px solid $border-color;
  padding: 10px 20px;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;

  mat-icon {
    font-size: 18px;
    width: 18px;
    height: 18px;
  }

  &:hover:not(:disabled) {
    background: #f3f4f6;
    border-color: #d1d5db;
  }

  &:disabled {
    opacity: 0.5;
    cursor: not-allowed;
  }
}

.btn-add {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: $primary-light;
  color: $primary-color;
  border: 1px solid $primary-color;
  padding: 6px 12px;
  border-radius: 4px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;

  mat-icon {
    font-size: 16px;
    width: 16px;
    height: 16px;
  }

  &:hover {
    background: $primary-color;
    color: #fff;
  }
}

.btn-remove {
  background: none;
  border: none;
  color: $text-muted;
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;

  mat-icon {
    font-size: 18px;
    width: 18px;
    height: 18px;
  }

  &:hover {
    background: #fef2f2;
    color: #dc2626;
  }
}

/* ================================
   LOADING STATE
   ================================ */
.loading-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 80px 20px;
  color: $text-secondary;

  .spinner {
    width: 40px;
    height: 40px;
    border: 3px solid $border-color;
    border-top-color: $primary-color;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 16px;
  }

  p {
    font-size: 14px;
    margin: 0;
  }
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ================================
   FORM CARDS
   ================================ */
.form-card {
  background: $card-bg;
  border: 1px solid $border-color;
  border-radius: 8px;
  padding: 20px 24px;
  margin-bottom: 20px;
}

.card-title {
  font-size: 16px;
  font-weight: 600;
  color: $text-primary;
  margin: 0 0 16px 0;
}

.card-header-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;

  .card-title {
    margin: 0;
  }
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px 24px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-label {
  font-size: 13px;
  font-weight: 500;
  color: $text-secondary;

  .required {
    color: #dc2626;
  }
}

.form-input,
.form-select {
  font-family: $font-family;
  font-size: 14px;
  padding: 10px 12px;
  border: 1px solid $border-color;
  border-radius: 6px;
  background: $card-bg;
  color: $text-primary;
  transition: border-color 0.2s;

  &:focus {
    outline: none;
    border-color: $primary-color;
  }

  &::placeholder {
    color: $text-muted;
  }
}

.form-select {
  cursor: pointer;
}

/* ================================
   LINE ITEMS TABLE
   ================================ */
.line-items-table {
  overflow-x: auto;
}

.items-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;

  th {
    text-align: left;
    padding: 10px 8px;
    background: #f9fafb;
    color: $text-secondary;
    font-weight: 500;
    border-bottom: 1px solid $border-color;
  }

  td {
    padding: 8px;
    border-bottom: 1px solid #f3f4f6;
    vertical-align: middle;
  }

  .col-item-no { width: 40px; text-align: center; }
  .col-part { width: 120px; }
  .col-desc { width: auto; }
  .col-qty { width: 80px; }
  .col-uom { width: 70px; }
  .col-price { width: 100px; }
  .col-total { width: 100px; }
  .col-action { width: 40px; }
}

.table-input {
  font-family: $font-family;
  font-size: 13px;
  padding: 6px 8px;
  border: 1px solid $border-color;
  border-radius: 4px;
  width: 100%;
  background: $card-bg;
  color: $text-primary;

  &:focus {
    outline: none;
    border-color: $primary-color;
  }
}

.text-right {
  text-align: right;
}

.total-row {
  background: #f9fafb;
  font-weight: 600;

  td {
    padding: 12px 8px;
    border-bottom: none;
  }
}

.total-label {
  color: $text-secondary;
}

.total-value {
  color: $primary-color;
  font-size: 14px;
}

.empty-items {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
  color: $text-muted;

  mat-icon {
    font-size: 40px;
    width: 40px;
    height: 40px;
    margin-bottom: 12px;
    opacity: 0.5;
  }

  p {
    font-size: 14px;
    margin: 0;
  }
}

/* ================================
   STATUS BADGES
   ================================ */
.status-badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 500;
  text-transform: capitalize;
}

.status-completed {
  background: #dcfce7;
  color: #16a34a;
}

.status-validated {
  background: #dbeafe;
  color: #2563eb;
}

.status-processing {
  background: #fef3c7;
  color: #d97706;
}

.status-queued {
  background: #e5e7eb;
  color: #6b7280;
}

.status-failed {
  background: #fee2e2;
  color: #dc2626;
}

.status-uploaded {
  background: #f3e5f5;
  color: #7b1fa2;
}

/* ================================
   RESPONSIVE
   ================================ */
@media (max-width: 768px) {
  .edit-order-page {
    padding: 16px;
  }

  .page-header {
    flex-direction: column;
    gap: 16px;
  }

  .form-grid {
    grid-template-columns: 1fr;
  }

  .items-table {
    font-size: 12px;
  }
}
