.qc-gate-page,
.qc-gate-page * {
  box-sizing: border-box;
}

.qc-gate-page {
  --bg: #f5f7fa;
  --card-bg: #ffffff;
  --text: #1f2937;
  --muted: #64748b;
  --border: #dbe3ef;
  --header-from: var(--portal-brand-start, #667eea);
  --header-to: var(--portal-brand-end, #764ba2);
  --success: #22c55e;
  --warning: #facc15;
  --danger: #ef4444;
  --shadow: 0 2px 10px rgba(15, 23, 42, 0.08);
  --shadow-strong: 0 6px 24px rgba(102, 126, 234, 0.24);
  margin: 0 auto;
  font-family: 'Microsoft JhengHei', Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  padding: 20px;
  max-width: 1900px;
}

.qc-gate-header {
  background: linear-gradient(135deg, var(--header-from) 0%, var(--header-to) 100%);
  color: #ffffff;
  border-radius: 12px;
  box-shadow: var(--shadow-strong);
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  padding: 20px 24px;
  margin-bottom: 16px;
}

.qc-gate-header h1 {
  margin: 0;
  font-size: 24px;
  line-height: 1.2;
}

.header-subtitle {
  margin: 8px 0 0;
  font-size: 14px;
  color: rgba(255, 255, 255, 0.85);
}

.header-meta {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.meta-row {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 140px;
}

.meta-label {
  font-size: 11px;
  color: rgba(255, 255, 255, 0.76);
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

.meta-value {
  font-size: 14px;
  font-weight: 600;
}

.refresh-button {
  border: 1px solid rgba(255, 255, 255, 0.35);
  background: rgba(255, 255, 255, 0.16);
  color: #ffffff;
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.refresh-button:hover {
  background: rgba(255, 255, 255, 0.26);
}

.refresh-button:disabled {
  cursor: not-allowed;
  opacity: 0.7;
}

.error-banner {
  margin: 0 0 16px;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid rgba(239, 68, 68, 0.25);
  background: #fee2e2;
  color: #991b1b;
  font-size: 13px;
}

.qc-gate-content {
  display: grid;
  gap: 16px;
}

.panel {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  overflow: hidden;
  transition: box-shadow 0.2s ease, border-color 0.2s ease;
}

.panel.is-refreshing {
  border-color: #c7d2fe;
  box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.12);
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  background: #f8fafc;
}

.panel-header h2 {
  margin: 0;
  font-size: 16px;
}

.panel-hint {
  font-size: 12px;
  color: var(--muted);
}

.loading-state,
.empty-state {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 280px;
  color: var(--muted);
  font-size: 14px;
}

.chart-panel {
  padding-bottom: 8px;
}

.chart-panel.is-refreshing .chart-canvas,
.table-panel.is-refreshing .lot-table-wrap {
  animation: refreshPulse 0.9s ease-in-out;
}

@keyframes refreshPulse {
  0% {
    opacity: 0.78;
    transform: translateY(2px);
  }
  100% {
    opacity: 1;
    transform: translateY(0);
  }
}

.qc-gate-chart {
  min-height: 320px;
  padding: 10px 14px 2px;
}

.chart-canvas {
  width: 100%;
  height: 340px;
}

.filter-indicator {
  border: 1px solid #93c5fd;
  background: #dbeafe;
  color: #1d4ed8;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  padding: 6px 12px;
  cursor: pointer;
}

.filter-indicator:hover {
  background: #bfdbfe;
}

.lot-table-wrap {
  padding: 12px 14px 16px;
}

.filter-chip {
  display: inline-flex;
  align-items: center;
  margin-bottom: 10px;
  border: 1px solid #93c5fd;
  background: #eff6ff;
  color: #1e40af;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  padding: 5px 10px;
  cursor: pointer;
}

.filter-chip:hover {
  background: #dbeafe;
}

.lot-table-scroll {
  overflow: auto;
  max-height: 520px;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.lot-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 1280px;
}

.lot-table th,
.lot-table td {
  padding: 8px 10px;
  border-bottom: 1px solid #e2e8f0;
  font-size: 12px;
  text-align: left;
  white-space: nowrap;
}

.lot-table th {
  background: #f1f5f9;
  position: sticky;
  top: 0;
  z-index: 1;
}

.sort-button {
  border: none;
  background: transparent;
  padding: 0;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: #334155;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}

.sort-indicator {
  color: #64748b;
  font-size: 11px;
  min-width: 10px;
}

.lot-table tbody tr:hover {
  background: #f8fafc;
}

@media (prefers-reduced-motion: reduce) {
  .panel,
  .refresh-button,
  .chart-panel.is-refreshing .chart-canvas,
  .table-panel.is-refreshing .lot-table-wrap {
    transition: none !important;
    animation: none !important;
  }
}

.cell-number {
  text-align: right;
}

.table-empty {
  text-align: center;
  color: var(--muted);
  padding: 24px 0;
}

.bucket-pill {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  padding: 3px 8px;
}

.bucket-lt-6h {
  background: #dcfce7;
  color: #166534;
}

.bucket-6h-12h {
  background: #fef9c3;
  color: #854d0e;
}

.bucket-12h-24h {
  background: #ffedd5;
  color: #9a3412;
}

.bucket-gt-24h {
  background: #fee2e2;
  color: #991b1b;
}

@media (max-width: 1100px) {
  .qc-gate-page {
    padding: 12px;
  }

  .qc-gate-header {
    flex-direction: column;
    align-items: stretch;
  }

  .header-meta {
    justify-content: flex-start;
  }

  .chart-canvas {
    height: 300px;
  }
}
