$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: #3b82f6;
$primary-dark: #2563eb;
$success-color: #22c55e;

.viewdetails-page {
  font-family: $font-family;
  background-color: $bg-color;
  min-height: 100vh;
  padding: 24px 40px;
  overflow-y: auto;
}

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 24px;
  border-bottom: 1px solid $border-color;
  margin-bottom: 24px;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 16px;
}

.btn-back {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: $text-secondary;
  cursor: pointer;
  transition: all 0.2s;

  mat-icon {
    font-size: 20px;
    width: 20px;
    height: 20px;
  }

  &:hover {
    background: #f3f4f6;
    color: $text-primary;
  }
}

.back-text {
  font-family: $font-family;
  font-size: 14px;
  color: $text-secondary;
  cursor: pointer;
  padding-right: 24px;
  border-right: 1px solid $border-color;
  margin-right: 8px;

  &:hover {
    color: $text-primary;
  }
}

.order-info {
  .order-title {
    font-family: $font-family;
    font-size: 24px;
    font-weight: 700;
    color: $text-primary;
    margin: 0 0 4px 0;
  }

  .order-subtitle {
    display: flex;
    align-items: center;
    gap: 12px;

    .subtitle-text {
      font-family: $font-family;
      font-size: 14px;
      color: $text-secondary;
    }

    .sap-badge {
      font-family: $font-family;
      font-size: 12px;
      font-weight: 500;
      color: $success-color;
      background: #dcfce7;
      padding: 4px 10px;
      border-radius: 16px;
    }
  }
}

.header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.btn-outline {
  font-family: $font-family;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: $card-bg;
  color: $text-primary;
  border: 1px solid $border-color;
  padding: 8px 16px;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;

  mat-icon {
    font-size: 18px;
    width: 18px;
    height: 18px;
    color: $text-secondary;
  }

  &:hover {
    background: #f3f4f6;
    border-color: #d1d5db;
  }
}

.btn-edit {
  font-family: $font-family;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: $card-bg;
  color: $text-primary;
  border: 1px solid $border-color;
  padding: 8px 16px;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;

  mat-icon {
    font-size: 18px;
    width: 18px;
    height: 18px;
    color: $text-secondary;
  }

  &:hover {
    background: #f3f4f6;
    border-color: #d1d5db;
  }
}

.btn-pdf {
  font-family: $font-family;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: $card-bg;
  color: $primary-color;
  border: 1px solid $border-color;
  padding: 8px 16px;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;

  mat-icon {
    font-size: 18px;
    width: 18px;
    height: 18px;
    color: $primary-color;
  }

  &:hover {
    background: #eff6ff;
    border-color: $primary-color;
  }
}

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 13px;
  font-weight: 500;
  padding: 6px 14px;
  border-radius: 6px;
  white-space: nowrap;

  mat-icon {
    font-size: 16px;
    width: 16px;
    height: 16px;
  }

  &.status-completed {
    background: transparent;
    border: 1px solid $success-color;
    color: $success-color;
  }

  &.status-validated {
    background: #d1fae5;
    border: 1px solid #10b981;
    color: #059669;
  }

  &.status-processing {
    background: #e0e7ff;
    color: #4f46e5;
  }

  &.status-queued {
    background: #fef3c7;
    color: #d97706;
  }

  &.status-failed {
    background: #fee2e2;
    color: #dc2626;
  }
}

.loading-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 80px 24px;
  color: $text-muted;

  .spinner {
    width: 32px;
    height: 32px;
    border: 3px solid $border-color;
    border-top-color: $primary-color;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 16px;
  }

  p {
    font-family: $font-family;
    font-size: 14px;
    margin: 0;
  }
}

@keyframes spin {
  from {
    transform: rotate(0deg);
  }

  to {
    transform: rotate(360deg);
  }
}

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 80px 24px;
  text-align: center;

  .empty-icon {
    margin-bottom: 16px;

    mat-icon {
      font-size: 48px;
      width: 48px;
      height: 48px;
      color: #d1d5db;
    }
  }

  .empty-title {
    font-family: $font-family;
    font-size: 16px;
    font-weight: 600;
    color: $text-primary;
    margin: 0 0 4px 0;
  }

  .empty-subtitle {
    font-family: $font-family;
    font-size: 14px;
    color: $text-muted;
    margin: 0;
  }
}

.details-content {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.progress-card {
  background: #e0f2fe;
  border: 1px solid #bae6fd;
  border-radius: 12px;
  padding: 24px 32px;
}

.progress-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 32px;
}

.progress-title {
  font-family: $font-family;
  font-size: 18px;
  font-weight: 600;
  color: $text-primary;
  margin: 0;
}

.stage-indicator {
  font-family: $font-family;
  font-size: 14px;
  color: $text-secondary;
}

.progress-stepper {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  gap: 16px;
  margin-bottom: 32px;
}

.stage-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  min-width: 140px;

  .stage-circle {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: #d1d5db;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 12px;
    color: white;
    font-size: 18px;
    font-weight: 600;

    mat-icon {
      font-size: 28px;
      width: 28px;
      height: 28px;
    }
  }

  .stage-label {
    font-family: $font-family;
    font-size: 14px;
    font-weight: 500;
    color: $text-secondary;
    margin-bottom: 4px;
  }

  .stage-description {
    font-family: $font-family;
    font-size: 12px;
    color: $text-muted;
    max-width: 120px;
  }

  &.completed,
  &.current {
    .stage-circle {
      background: $success-color;
    }

    .stage-label {
      color: $primary-color;
    }
  }
}

.stage-arrow {
  display: flex;
  align-items: center;
  padding-top: 16px;
  color: $success-color;

  mat-icon {
    font-size: 20px;
    width: 20px;
    height: 20px;
  }
}

.current-stage-info {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  background: $card-bg;
  border: 1px solid #dbeafe;
  border-left: 4px solid $primary-color;
  border-radius: 8px;
  padding: 16px 20px;

  .info-icon {
    font-size: 20px;
    width: 20px;
    height: 20px;
    color: $primary-color;
    margin-top: 2px;
  }

  .info-content {
    display: flex;
    flex-direction: column;
    gap: 4px;
  }

  .info-label {
    font-family: $font-family;
    font-size: 14px;
    color: $text-primary;

    strong {
      font-weight: 600;
      color: $primary-color;
    }
  }

  .info-description {
    font-family: $font-family;
    font-size: 13px;
    color: $text-secondary;
  }
}

.info-card {
  background: $card-bg;
  border: 1px solid $border-color;
  border-radius: 12px;
  padding: 24px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.card-header-section {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
  padding-bottom: 16px;
  border-bottom: 1px solid $border-color;
}

.card-icon {
  font-size: 24px;
  width: 24px;
  height: 24px;
  color: $text-primary;
}

.card-title {
  font-family: $font-family;
  font-size: 18px;
  font-weight: 600;
  color: $text-primary;
  margin: 0;
}

.info-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 24px;
}

.info-list {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.info-item {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.info-label {
  font-family: $font-family;
  font-size: 13px;
  font-weight: 500;
  color: $text-secondary;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin: 0;
}

.info-value {
  font-family: $font-family;
  font-size: 16px;
  font-weight: 600;
  color: $text-primary;
  margin: 0;
  word-break: break-word;
}

.two-column-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 24px;
}

@media (max-width: 1024px) {
  .info-grid {
    grid-template-columns: 1fr;
  }

  .two-column-grid {
    grid-template-columns: 1fr;
  }
}

// Ice Data Viewer Styles
.btn-ice {
  background: var(--action-primary-default, $primary-color) !important;
  color: #fff !important;
  border-color: var(--action-primary-default, $primary-color) !important;

  &:hover {
    background: var(--primary-dark, $primary-dark) !important;
  }
}

.ice-data-viewer {
  margin-top: 24px;
  background: $card-bg;
  border-radius: 12px;
  border: 1px solid $border-color;
  overflow: hidden;
}

.viewer-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  background: var(--bg-surface, #f9fafb);
  border-bottom: 1px solid $border-color;
}

.viewer-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 16px;
  font-weight: 600;
  color: $text-primary;
  margin: 0;

  mat-icon {
    color: var(--action-primary-default, $primary-color);
  }
}

.btn-close-viewer {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: $text-secondary;
  cursor: pointer;
  transition: all 0.2s;

  &:hover {
    background: #f3f4f6;
    color: $text-primary;
  }
}

.viewer-loading,
.viewer-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 48px;
  color: $text-secondary;
  text-align: center;

  mat-icon {
    font-size: 48px;
    width: 48px;
    height: 48px;
    margin-bottom: 12px;
    opacity: 0.5;
  }

  p {
    margin: 0;
  }
}

.viewer-content {
  padding: 20px;
}

// Order Changes Analysis Card
.changes-analysis-card,
.line-items-card {
  background: $card-bg;
  border: 1px solid $border-color;
  border-radius: 12px;
  margin-bottom: 24px;
  overflow: hidden;
}

.card-header-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid $border-color;
}

.card-title-section {
  display: flex;
  align-items: center;
  gap: 10px;

  mat-icon {
    color: var(--action-primary-default, $primary-color);
    font-size: 22px;
    width: 22px;
    height: 22px;
  }

  h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
    color: $text-primary;
  }
}

.items-count {
  background: #f3f4f6;
  padding: 4px 10px;
  border-radius: 12px;
  font-size: 12px;
  color: $text-secondary;
}

.changes-badge {
  padding: 6px 12px;
  border-radius: 16px;
  font-size: 12px;
  font-weight: 500;

  &.modified {
    background: #fef3c7;
    color: #d97706;
    border: 1px solid #fcd34d;
  }

  &.added {
    background: #d1fae5;
    color: #059669;
  }

  &.removed {
    background: #fee2e2;
    color: #dc2626;
  }
}

.changes-subtitle {
  padding: 12px 20px;
  margin: 0;
  font-size: 13px;
  color: $text-secondary;
  background: #fafafa;
  border-bottom: 1px solid $border-color;
}

.changes-table-container,
.line-items-table-container {
  overflow-x: auto;
}

.changes-table,
.line-items-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;

  thead {
    background: #f9fafb;

    th {
      padding: 12px 16px;
      text-align: left;
      font-weight: 600;
      color: $text-secondary;
      border-bottom: 1px solid $border-color;
      white-space: nowrap;

      &.text-right {
        text-align: right;
      }
    }
  }

  tbody {
    tr {
      border-bottom: 1px solid #f3f4f6;

      &:hover {
        background: #fafafa;
      }
    }

    td {
      padding: 14px 16px;
      color: $text-primary;
      vertical-align: middle;

      &.text-right {
        text-align: right;
      }
    }
  }
}

.description-cell {
  max-width: 250px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 500;

  mat-icon {
    font-size: 14px;
    width: 14px;
    height: 14px;
  }

  &.status-modified {
    background: #fef3c7;
    color: #d97706;
  }

  &.status-added {
    background: #d1fae5;
    color: #059669;
  }

  &.status-removed {
    background: #fee2e2;
    color: #dc2626;
  }

  &.status-unchanged {
    background: #f3f4f6;
    color: $text-secondary;
  }
}

.price-current {
  display: block;
  font-weight: 500;
}

.price-was {
  display: block;
  font-size: 11px;
  color: $text-muted;
  text-decoration: line-through;
}

.change-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.change-btn {
  padding: 4px 10px;
  border: 1px solid $border-color;
  border-radius: 6px;
  background: $card-bg;
  font-size: 11px;
  color: $text-secondary;
  cursor: default;

  &:hover {
    background: #f3f4f6;
  }
}

.changes-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 20px;
  background: #fafafa;
  border-top: 1px solid $border-color;
}

.total-items {
  font-size: 13px;
  color: $text-secondary;
}

.changes-summary {
  display: flex;
  gap: 16px;
}

.summary-item {
  font-size: 12px;

  &.added {
    color: #059669;
  }

  &.removed {
    color: #dc2626;
  }

  &.modified {
    color: #d97706;
  }

  &.unchanged {
    color: $text-secondary;
  }
}

// ── ✅ Target JSON button — inherits btn-outline, adds blue tint ───────
.btn-target-json {
  color: #0369a1;
  border-color: #e0f2fe;
  background: #f0f9ff;

  mat-icon {
    color: #0369a1;
  }

  &:hover {
    background: #e0f2fe;
    border-color: #7dd3fc;
  }
}

// ── TARGET JSON VIEWER PANEL ─────────────────────────────────────────────
.json-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: overlayFadeIn 0.2s ease;
}

@keyframes overlayFadeIn {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}

.json-panel {
  background: #0f172a;
  border: 1px solid #1e3a5f;
  border-radius: 16px;
  width: 90vw;
  max-width: 860px;
  max-height: 88vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 32px 80px rgba(0, 0, 0, 0.7), 0 0 0 1px rgba(56, 189, 248, 0.1);
  animation: panelSlideUp 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes panelSlideUp {
  from {
    transform: translateY(32px);
    opacity: 0;
  }

  to {
    transform: translateY(0);
    opacity: 1;
  }
}

// Panel Header
.json-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  background: #1e293b;
  border-bottom: 1px solid #334155;
  flex-shrink: 0;
}

.json-panel-title {
  display: flex;
  align-items: center;
  gap: 10px;
}

.json-panel-icon {
  font-size: 20px;
}

.json-panel-title>span:nth-child(2) {
  font-family: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', monospace;
  font-size: 15px;
  font-weight: 700;
  color: #38bdf8;
}

.json-panel-sub {
  font-size: 11px;
  color: #475569;
  font-weight: 400;
  margin-left: 2px;
  font-family: 'Segoe UI', sans-serif;
}

.json-panel-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.json-copy-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: #0ea5e9;
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 7px 16px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;

  mat-icon {
    font-size: 15px;
    width: 15px;
    height: 15px;
  }

  &:hover {
    background: #0284c7;
  }

  &.copied {
    background: #16a34a;
    animation: copyPop 0.2s ease;
  }
}

@keyframes copyPop {
  0% {
    transform: scale(1);
  }

  50% {
    transform: scale(1.07);
  }

  100% {
    transform: scale(1);
  }
}

.json-close-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  background: transparent;
  border: 1px solid #334155;
  border-radius: 8px;
  color: #64748b;
  cursor: pointer;
  transition: all 0.2s;

  mat-icon {
    font-size: 18px;
    width: 18px;
    height: 18px;
  }

  &:hover {
    background: #334155;
    color: #f1f5f9;
    border-color: #475569;
  }
}

// Summary Badges
.json-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 12px 20px;
  background: #0a0f1e;
  border-bottom: 1px solid #1e293b;
  flex-shrink: 0;
}

.json-badge {
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  font-family: 'JetBrains Mono', 'Fira Code', monospace;
  letter-spacing: 0.3px;
  white-space: nowrap;

  &.blue {
    background: #082f49;
    color: #38bdf8;
    border: 1px solid #0c4a6e;
  }

  &.amber {
    background: #1c1001;
    color: #fbbf24;
    border: 1px solid #78350f;
  }

  &.green {
    background: #052e16;
    color: #4ade80;
    border: 1px solid #14532d;
  }

  &.purple {
    background: #1e1038;
    color: #a78bfa;
    border: 1px solid #3b0764;
  }

  &.teal {
    background: #042f2e;
    color: #2dd4bf;
    border: 1px solid #0f3d3a;
  }

  &.gray {
    background: #1e293b;
    color: #94a3b8;
    border: 1px solid #334155;
  }
}

// Code Block
.json-code-wrap {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;

  &::-webkit-scrollbar {
    width: 6px;
  }

  &::-webkit-scrollbar-track {
    background: #0f172a;
  }

  &::-webkit-scrollbar-thumb {
    background: #334155;
    border-radius: 3px;
  }

  &::-webkit-scrollbar-thumb:hover {
    background: #475569;
  }
}

.json-code {
  margin: 0;
  padding: 24px 28px;
  font-family: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', 'Courier New', monospace;
  font-size: 13px;
  line-height: 1.85;
  color: #cbd5e1;
  white-space: pre;
  background: transparent;
  border: none;
  overflow-x: auto;
  tab-size: 2;

  // Syntax highlight — using ::ng-deep for innerHTML spans
  ::ng-deep .json-key {
    color: #7dd3fc;
  }

  // blue   — keys
  ::ng-deep .json-str {
    color: #86efac;
  }

  // green  — string values
  ::ng-deep .json-num {
    color: #c4b5fd;
  }

  // purple — numbers
  ::ng-deep .json-bool {
    color: #fde68a;
  }

  // yellow — true / false
  ::ng-deep .json-null {
    color: #f87171;
  }

  // red    — null
}

@media (max-width: 768px) {
  .json-panel {
    width: 100vw;
    max-width: 100vw;
    max-height: 100vh;
    border-radius: 16px 16px 0 0;
    align-self: flex-end;
  }

  .json-overlay {
    align-items: flex-end;
  }
}