/* ==================================================================
   Diff Table — step-difference preview styles for ETL Studio
   Uses root design tokens from assets/css/base.css.
   ================================================================== */

/* --- Diff toolbar (toggle bar at top of center panel) ------------- */
.diff-toolbar {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: 4px var(--space-md);
  border-bottom: 1px solid var(--color-border);
  background: var(--color-surface);
  flex-shrink: 0;
}

.diff-toolbar-label {
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--color-text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  user-select: none;
}

.diff-toggle-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-sans);
  font-size: var(--text-xs);
  height: 32px;
  padding: 0 12px;
  border: 1px solid var(--color-border);
  border-radius: var(--border-radius-sm);
  background: var(--color-bg);
  color: var(--color-text-secondary);
  cursor: pointer;
  transition: background 150ms ease, color 150ms ease, border-color 150ms ease;
}

.diff-toggle-btn:hover {
  background: color-mix(in srgb, var(--color-accent) 6%, transparent);
  color: var(--color-text);
  border-color: var(--color-accent);
}

.diff-toggle-btn.active {
  background: var(--color-accent);
  color: var(--color-bg);
  border-color: var(--color-accent);
}

.diff-toggle-btn svg {
  display: block;
  pointer-events: none;
  flex-shrink: 0;
}

/* --- Diff table container ----------------------------------------- */
.diff-table-wrap {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: auto;
}

/* --- Summary bar -------------------------------------------------- */
.diff-summary {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: 6px var(--space-md);
  font-size: var(--text-xs);
  color: var(--color-text-secondary);
  border-bottom: 1px solid var(--color-border);
  background: var(--color-surface);
  flex-shrink: 0;
  flex-wrap: wrap;
}

.diff-summary-added { color: var(--color-success); font-weight: 600; }
.diff-summary-removed { color: var(--color-error); font-weight: 600; }
.diff-summary-changed { color: var(--color-warning); font-weight: 600; }
.diff-summary-unchanged { color: var(--color-text-secondary); font-weight: 600; }

/* --- Diff table --------------------------------------------------- */
.diff-table {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  table-layout: fixed;
}

.diff-table thead {
  position: sticky;
  top: 0;
  z-index: 3;
}

.diff-table thead::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 1px;
  background: var(--color-border);
  z-index: 4;
}

.diff-table thead th {
  font-weight: 600;
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-text-secondary);
  background: var(--color-bg);
  border-bottom: 1px solid var(--color-border);
  padding: 8px var(--space-sm);
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  user-select: none;
}

.diff-table tbody td {
  font-size: var(--text-sm);
  color: var(--color-text);
  border-bottom: 1px solid var(--color-border);
  padding: 4px var(--space-sm);
  line-height: 28px;
  height: 28px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.diff-table tbody td[data-type="number"] {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* --- Status indicator column -------------------------------------- */
.diff-indicator {
  width: 32px;
  min-width: 32px;
  max-width: 32px;
  text-align: center;
  font-weight: 700;
  font-size: var(--text-xs);
  padding: 4px 0 !important;
}

/* --- Row states --------------------------------------------------- */

/* Row backgrounds live on the <tr> so the pinned (sticky) cells can use
   background: inherit and keep their tint when scrolled horizontally.
   The colored left bar stays on the <td> (box-shadow) so each cell keeps
   its own edge marker. */

/* Added rows */
.diff-row-added {
  background: color-mix(in srgb, var(--color-success) 6%, transparent);
}
.diff-row-added td {
  box-shadow: inset 3px 0 0 var(--color-success);
}
.diff-row-added .diff-indicator { color: var(--color-success); }
.diff-table tbody tr.diff-row-added:hover {
  background: color-mix(in srgb, var(--color-success) 10%, transparent);
}

/* Removed rows */
.diff-row-removed {
  background: color-mix(in srgb, var(--color-error) 5%, transparent);
}
.diff-row-removed td {
  text-decoration: line-through;
  color: var(--color-text-secondary);
  box-shadow: inset 3px 0 0 var(--color-error);
}
.diff-row-removed .diff-indicator { color: var(--color-error); }
.diff-table tbody tr.diff-row-removed:hover {
  background: color-mix(in srgb, var(--color-error) 9%, transparent);
}

/* Changed rows */
.diff-row-changed {
  background: color-mix(in srgb, var(--color-warning) 4%, transparent);
}
.diff-row-changed td {
  box-shadow: inset 3px 0 0 var(--color-warning);
}
.diff-row-changed .diff-indicator { color: var(--color-warning); }
.diff-table tbody tr.diff-row-changed:hover {
  background: color-mix(in srgb, var(--color-warning) 8%, transparent);
}

/* Unchanged rows — opaque base so pinned cells inherit an opaque tint */
.diff-row-unchanged {
  background: var(--color-bg);
}
.diff-row-unchanged td { opacity: 0.6; }

/* --- Changed cells ------------------------------------------------- */
.diff-cell-changed {
  background: color-mix(in srgb, var(--color-warning) 15%, transparent) !important;
  border-bottom: 1px solid color-mix(in srgb, var(--color-warning) 30%, transparent) !important;
  cursor: help;
  position: relative;
}

/* --- Responsive ---------------------------------------------------- */
@media (max-width: 768px) {
  .diff-toolbar { padding: 4px var(--space-sm); }
  .diff-summary { padding: 4px var(--space-sm); gap: 4px; }
  .diff-toggle-btn { height: 28px; padding: 0 8px; font-size: 10px; }
}

@media (max-width: 480px) {
  .diff-toolbar-label { display: none; }
}

/* --- Dark mode overrides ------------------------------------------ */
[data-theme="dark"] .diff-row-added {
  background: color-mix(in srgb, var(--color-success) 10%, transparent);
}
[data-theme="dark"] .diff-row-removed {
  background: color-mix(in srgb, var(--color-error) 8%, transparent);
}
[data-theme="dark"] .diff-row-changed {
  background: color-mix(in srgb, var(--color-warning) 8%, transparent);
}
[data-theme="dark"] .diff-cell-changed {
  background: color-mix(in srgb, var(--color-warning) 20%, transparent) !important;
}

/* --- Reduced motion ----------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  .diff-table tbody td { transition: none !important; }
  .diff-toggle-btn { transition: none !important; }
}
