/* ==========================================================================
   Components — SFA Middleware Prototype
   ==========================================================================
   Kartu, tabel, badge, tombol, modal, toast, skeleton, form, switch, kpi,
   health-dot, sparkline, json-view, timeline, range-field.
   Ketentuan kunci: hover/active hanya memakai transform/opacity (150-200ms);
   semua warna hanya via custom property dari css/tokens.css.
   ========================================================================== */

/* Card
   ========================================================================== */
.card {
  background: var(--surface);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-l);
  box-shadow: var(--shadow-1);
  padding: 20px;
}

.card__title {
  margin-bottom: 12px;
  color: var(--text-primary);
  font-size: 1rem;
  font-weight: 600;
}

/* Tabel
   ========================================================================== */
.table-wrap {
  width: 100%;
  overflow-x: auto;
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-m);
}

table.data {
  width: 100%;
  min-width: 560px;
  border-collapse: collapse;
  font-size: 0.875rem;
}

table.data thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  padding: 10px 14px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--glass-border);
  color: var(--text-secondary);
  text-align: left;
  font-weight: 600;
  white-space: nowrap;
}

table.data tbody td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--glass-border);
  color: var(--text-primary);
}

table.data tbody tr:last-child td {
  border-bottom: none;
}

table.data tbody tr {
  background: var(--surface);
  transition: transform 180ms ease;
}

table.data tbody tr:hover {
  transform: translateX(2px);
}

/* Baris yang baru berubah status (mis. job berpindah QUEUED -> SUCCESS) diberi
   highlight sekali-jalan yang memudar — sinyal perubahan data, bukan micro-interaction
   hover/active. */
@keyframes row-flash {
  from { background-color: var(--status-info-soft); }
  to { background-color: var(--surface); }
}

table.data tbody tr.row-flash {
  animation: row-flash 1200ms ease-out;
}

/* Badge
   ========================================================================== */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1.4;
  white-space: nowrap;
}

.badge--success {
  background: var(--status-success-soft);
  color: var(--status-success);
}

.badge--error {
  background: var(--status-error-soft);
  color: var(--status-error);
}

.badge--warning {
  background: var(--status-warning-soft);
  color: var(--status-warning);
}

.badge--info {
  background: var(--status-info-soft);
  color: var(--status-info);
}

.badge--neutral {
  background: var(--status-neutral-soft);
  color: var(--status-neutral);
}

.badge--processing {
  background: var(--status-info-soft);
  color: var(--status-info);
}

.badge--processing::before {
  content: "";
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  animation: badge-processing-pulse 1.2s ease-in-out infinite;
}

@keyframes badge-processing-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

/* Tombol
   ========================================================================== */
.btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 40px;
  padding: 0 18px;
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-s);
  background: var(--surface);
  color: var(--text-primary);
  font: inherit;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  user-select: none;
  transition: transform 160ms ease, opacity 160ms ease;
}

.btn:hover {
  transform: translateY(-1px);
}

.btn:active {
  transform: translateY(0) scale(0.98);
}

.btn:focus-visible {
  box-shadow: var(--focus-ring);
  outline: none;
}

.btn:disabled {
  cursor: not-allowed;
  opacity: 0.5;
  transform: none;
}

.btn--primary {
  background: var(--brand-primary);
  border-color: var(--brand-primary);
  color: var(--brand-contrast);
}

.btn--danger {
  background: var(--status-error);
  border-color: var(--status-error);
  color: var(--brand-contrast);
}

.btn--ghost {
  background: transparent;
  border-color: transparent;
}

.btn--ghost:hover {
  opacity: 0.8;
}

.btn--sm {
  height: 32px;
  padding: 0 12px;
  font-size: 0.8125rem;
}

.btn__icon {
  display: inline-flex;
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

.btn--sm .btn__icon {
  width: 14px;
  height: 14px;
}

/* Loading — spinner menggantikan .btn__icon, dimensi tombol tidak berubah. */
.btn--loading {
  cursor: default;
  pointer-events: none;
}

.btn--loading .btn__icon {
  display: none;
}

.btn--loading::before {
  content: "";
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  opacity: 0.85;
  animation: btn-spin 700ms linear infinite;
}

.btn--sm.btn--loading::before {
  width: 14px;
  height: 14px;
}

@keyframes btn-spin {
  to { transform: rotate(360deg); }
}

/* Modal
   ========================================================================== */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--overlay-scrim);
  backdrop-filter: blur(6px);
}

.modal {
  position: relative;
  z-index: 201;
  width: 100%;
  max-width: 480px;
  max-height: calc(100vh - 48px);
  overflow-y: auto;
  padding: 24px;
  background: var(--surface-glass);
  backdrop-filter: blur(14px);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-l);
  box-shadow: var(--shadow-1);
}

.modal h2,
.modal h3 {
  margin-bottom: 8px;
  color: var(--text-primary);
}

.modal p {
  margin-bottom: 16px;
  color: var(--text-secondary);
}

/* Toast
   ========================================================================== */
.toast-stack {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 300;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: min(360px, calc(100vw - 32px));
}

.toast {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 16px;
  border: 1px solid var(--glass-border);
  border-left: 3px solid var(--status-neutral);
  border-radius: var(--radius-m);
  background: var(--surface-glass);
  backdrop-filter: blur(14px);
  box-shadow: var(--shadow-1);
  color: var(--text-primary);
  font-size: 0.875rem;
  animation: toast-in 200ms ease;
}

.toast--success { border-left-color: var(--status-success); }
.toast--error { border-left-color: var(--status-error); }
.toast--warning { border-left-color: var(--status-warning); }
.toast--info { border-left-color: var(--status-info); }

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

/* Skeleton
   ========================================================================== */
.skeleton {
  position: relative;
  overflow: hidden;
  background: var(--surface-2);
  border-radius: var(--radius-s);
}

.skeleton::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent, var(--surface), transparent);
  transform: translateX(-100%);
  animation: skeleton-shimmer 1.4s ease-in-out infinite;
}

@keyframes skeleton-shimmer {
  100% { transform: translateX(100%); }
}

.skeleton-row {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 14px;
}

.skeleton-row .skeleton {
  height: 14px;
}

/* Form
   ========================================================================== */
.form-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 16px;
}

.form-field label {
  color: var(--text-secondary);
  font-size: 0.8125rem;
  font-weight: 600;
}

.form-field input,
.form-field select,
.form-field textarea {
  padding: 9px 12px;
  background: var(--surface);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-s);
  color: var(--text-primary);
  font: inherit;
  font-size: 0.875rem;
}

.form-field input:focus-visible,
.form-field select:focus-visible,
.form-field textarea:focus-visible {
  box-shadow: var(--focus-ring);
  outline: none;
}

.form-field--invalid input,
.form-field--invalid select,
.form-field--invalid textarea {
  border-color: var(--status-error);
}

.form-field__error {
  color: var(--status-error);
  font-size: 0.75rem;
}

/* Switch
   ========================================================================== */
.switch {
  position: relative;
  display: inline-flex;
  align-items: center;
  width: 42px;
  height: 24px;
  flex-shrink: 0;
  cursor: pointer;
}

.switch input {
  position: absolute;
  inset: 0;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}

.switch__track {
  position: absolute;
  inset: 0;
  background: var(--status-neutral-soft);
  border: 1px solid var(--glass-border);
  border-radius: 999px;
}

.switch__thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 18px;
  height: 18px;
  background: var(--surface);
  border-radius: 50%;
  box-shadow: var(--shadow-1);
  transition: transform 180ms ease;
}

.switch input:checked ~ .switch__track {
  background: var(--brand-primary);
}

.switch input:checked ~ .switch__thumb {
  transform: translateX(18px);
}

.switch input:focus-visible ~ .switch__track {
  box-shadow: var(--focus-ring);
}

.switch input:disabled ~ .switch__track,
.switch input:disabled ~ .switch__thumb {
  opacity: 0.5;
}

/* KPI
   ========================================================================== */
.kpi {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 18px 20px;
  background: var(--surface);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-l);
  box-shadow: var(--shadow-1);
}

.kpi__value {
  color: var(--text-primary);
  font-size: 1.75rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.kpi__label {
  color: var(--text-secondary);
  font-size: 0.8125rem;
}

/* Health dot
   ========================================================================== */
.health-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  flex-shrink: 0;
  border-radius: 50%;
  background: var(--status-neutral);
}

.health-dot--green {
  background: var(--status-success);
  box-shadow: 0 0 0 3px var(--status-success-soft);
}

.health-dot--yellow {
  background: var(--status-warning);
  box-shadow: 0 0 0 3px var(--status-warning-soft);
}

.health-dot--red {
  background: var(--status-error);
  box-shadow: 0 0 0 3px var(--status-error-soft);
}

.health-dot--gray {
  background: var(--status-neutral);
  box-shadow: 0 0 0 3px var(--status-neutral-soft);
}

/* Sparkline
   ========================================================================== */
.sparkline {
  display: block;
  width: 100%;
  height: 48px;
}

.sparkline polyline {
  fill: none;
  stroke: var(--brand-primary);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* JSON view
   ========================================================================== */
.json-view {
  padding: 14px 16px;
  background: var(--surface-2);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-s);
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  line-height: 1.5;
  white-space: pre;
  overflow: auto;
  max-height: 320px;
}

/* Timeline
   ========================================================================== */
.timeline {
  list-style: none;
  margin: 0;
  padding: 0;
}

.timeline li {
  position: relative;
  padding: 0 0 18px 24px;
  border-left: 2px solid var(--glass-border);
  color: var(--text-secondary);
  font-size: 0.8125rem;
}

.timeline li::before {
  content: "";
  position: absolute;
  left: -5px;
  top: 2px;
  width: 8px;
  height: 8px;
  background: var(--brand-primary);
  border: 2px solid var(--surface);
  border-radius: 50%;
}

.timeline li:last-child {
  padding-bottom: 0;
  border-left-color: transparent;
}

/* Range field
   ========================================================================== */
.range-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 16px;
}

.range-field__head {
  display: flex;
  justify-content: space-between;
  color: var(--text-secondary);
  font-size: 0.8125rem;
}

.range-field input[type="range"] {
  width: 100%;
  height: 4px;
  background: var(--surface-2);
  border-radius: 999px;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
}

.range-field input[type="range"]::-webkit-slider-thumb {
  width: 16px;
  height: 16px;
  background: var(--brand-primary);
  border-radius: 50%;
  box-shadow: var(--shadow-1);
  cursor: pointer;
  transition: transform 160ms ease;
  -webkit-appearance: none;
  appearance: none;
}

.range-field input[type="range"]::-webkit-slider-thumb:hover {
  transform: scale(1.15);
}

.range-field input[type="range"]::-moz-range-thumb {
  width: 16px;
  height: 16px;
  background: var(--brand-primary);
  border: none;
  border-radius: 50%;
  cursor: pointer;
  transition: transform 160ms ease;
}

.range-field input[type="range"]::-moz-range-thumb:hover {
  transform: scale(1.15);
}

.range-field input[type="range"]:focus-visible {
  box-shadow: var(--focus-ring);
}
