/* ================================================================
   Comparator AI — Design System v2.0 (Dark Theme)
   Синий акцент, тёмный фон, сайдбар-навигация
   ================================================================ */

/* ── CSS Variables ──────────────────────────────────────────── */
:root {
  /* Фон */
  --bg-page: #0f172a;
  --bg-card: #1a1f35;
  --bg-card-hover: #212842;
  --bg-input: #131929;
  --border-subtle: #2a3149;

  /* Акцент — синий */
  --color-primary: #2563eb;
  --color-primary-light: #3b82f6;
  --color-primary-dark: #1d4ed8;
  --color-primary-gradient: linear-gradient(135deg, #2563eb, #60a5fa);
  --color-primary-glow: rgba(37, 99, 235, 0.15);

  /* Статусы */
  --color-success: #22c55e;
  --color-success-bg: rgba(34, 197, 94, 0.15);
  --color-danger: #ef4444;
  --color-danger-bg: rgba(239, 68, 68, 0.15);
  --color-warning: #f59e0b;
  --color-warning-bg: rgba(245, 158, 11, 0.15);
  --color-info: #3b82f6;
  --color-info-bg: rgba(59, 130, 246, 0.15);

  /* Текст */
  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;

  /* Радиусы */
  --radius-card: 16px;
  --radius-button: 10px;
  --radius-badge: 999px;
  --radius-input: 10px;
  --radius-sm: 6px;

  /* Тени */
  --shadow-card: 0 4px 20px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 10px 40px rgba(0, 0, 0, 0.4);
  --shadow-primary: 0 4px 20px rgba(37, 99, 235, 0.25);

  /* Layout */
  --sidebar-width: 240px;
  --topbar-height: 64px;

  /* Переходы */
  --transition-fast: 0.15s ease;
  --transition-base: 0.2s ease;
}

/* ── Reset & Base ───────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background: var(--bg-page);
  color: var(--text-primary);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ── Layout ─────────────────────────────────────────────────── */
.layout {
  display: flex;
  min-height: 100vh;
}

/* ── Sidebar ────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-card);
  border-right: 1px solid var(--border-subtle);
  position: fixed;
  top: 0;
  left: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  z-index: 50;
  overflow-y: auto;
}

.sidebar-logo {
  padding: 20px 20px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  border-bottom: 1px solid var(--border-subtle);
  flex-shrink: 0;
}

.sidebar-logo-icon {
  width: 36px;
  height: 36px;
  background: var(--color-primary-gradient);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 700;
  font-size: 14px;
  box-shadow: var(--shadow-primary);
  flex-shrink: 0;
}

.sidebar-logo-text {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: -0.01em;
}

.sidebar-logo-text span {
  color: var(--text-muted);
  font-weight: 400;
  font-size: 11px;
  display: block;
  margin-top: -2px;
}

.sidebar-nav {
  flex: 1;
  padding: 12px 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.sidebar-section-label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  padding: 16px 12px 6px;
}

.sidebar-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-button);
  font-size: 14px;
  color: var(--text-secondary);
  text-decoration: none;
  transition: all var(--transition-base);
  cursor: pointer;
  border: none;
  background: transparent;
  width: 100%;
  text-align: left;
  position: relative;
  font-family: inherit;
}

.sidebar-item:hover {
  background: var(--bg-card-hover);
  color: var(--text-primary);
}

.sidebar-item.active {
  background: var(--color-primary-glow);
  color: var(--color-primary-light);
  font-weight: 500;
}

.sidebar-item.active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 60%;
  background: var(--color-primary);
  border-radius: 0 3px 3px 0;
}

.sidebar-item .item-icon {
  font-size: 16px;
  width: 20px;
  text-align: center;
  flex-shrink: 0;
}

.sidebar-item .item-label { flex: 1; }

.sidebar-item .badge-soon {
  padding: 2px 6px;
  font-size: 9px;
  font-weight: 600;
  background: var(--border-subtle);
  color: var(--text-muted);
  border-radius: var(--radius-badge);
  margin-left: auto;
}

.sidebar-item.disabled {
  opacity: 0.5;
  cursor: default;
}

.sidebar-footer {
  padding: 12px 14px;
  border-top: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex-shrink: 0;
}

.sidebar-status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-muted);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.status-dot.online {
  background: var(--color-success);
  box-shadow: 0 0 6px rgba(34, 197, 94, 0.5);
}

.status-dot.offline {
  background: var(--color-danger);
  box-shadow: 0 0 6px rgba(239, 68, 68, 0.4);
}

.queue-progress {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  color: var(--text-muted);
}

.queue-progress-bar {
  flex: 1;
  height: 4px;
  background: var(--border-subtle);
  border-radius: var(--radius-badge);
  overflow: hidden;
}

.queue-progress-fill {
  height: 100%;
  background: var(--color-primary-gradient);
  border-radius: var(--radius-badge);
  transition: width 0.4s ease;
}

/* ── Main Wrapper ───────────────────────────────────────────── */
.main-wrapper {
  margin-left: var(--sidebar-width);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ── Top Bar ────────────────────────────────────────────────── */
.topbar {
  height: var(--topbar-height);
  background: var(--bg-card);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 40;
  flex-shrink: 0;
}

.topbar-search-wrapper {
  position: relative;
  flex: 1;
  max-width: 480px;
}

.topbar-search-wrapper .search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 14px;
  pointer-events: none;
  opacity: 0.6;
}

.topbar-search {
  width: 100%;
  padding: 10px 14px 10px 36px;
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-input);
  color: var(--text-primary);
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: border-color var(--transition-base), box-shadow var(--transition-base);
}

.topbar-search::placeholder { color: var(--text-muted); }

.topbar-search:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--color-primary-glow);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
}

.topbar-btn {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-button);
  border: 1px solid var(--border-subtle);
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  transition: all var(--transition-base);
  position: relative;
}

.topbar-btn:hover {
  background: var(--bg-card-hover);
  color: var(--text-primary);
}

.topbar-btn.has-notification::after {
  content: '';
  position: absolute;
  top: 8px;
  right: 8px;
  width: 7px;
  height: 7px;
  background: var(--color-danger);
  border-radius: 50%;
  border: 2px solid var(--bg-card);
}

.topbar-btn-primary {
  width: auto;
  padding: 0 16px;
  gap: 6px;
  background: var(--color-primary-gradient);
  color: #fff;
  border: none;
  font-size: 13px;
  font-weight: 500;
}

.topbar-btn-primary:hover {
  box-shadow: var(--shadow-primary);
  color: #fff;
}

/* ── Main Content ───────────────────────────────────────────── */
.main-content {
  flex: 1;
  padding: 24px;
}

.page-title {
  font-size: 22px;
  font-weight: 600;
  margin-bottom: 4px;
}

.page-subtitle {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 24px;
}

/* ── KPI Cards ──────────────────────────────────────────────── */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.kpi-card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-card);
  padding: 20px;
  box-shadow: var(--shadow-card);
  transition: border-color var(--transition-base);
}

.kpi-card:hover { border-color: var(--color-primary); }

.kpi-icon {
  font-size: 20px;
  margin-bottom: 8px;
  display: block;
}

.kpi-label {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 500;
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.kpi-value {
  font-size: 28px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--text-primary);
  line-height: 1.1;
}

.kpi-change {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: var(--radius-badge);
  font-size: 11px;
  font-weight: 600;
  margin-top: 8px;
}

.kpi-change.up    { background: var(--color-success-bg); color: var(--color-success); }
.kpi-change.down  { background: var(--color-danger-bg);  color: var(--color-danger); }
.kpi-change.flat  { background: var(--color-info-bg);    color: var(--color-info); }

/* ── Cards ──────────────────────────────────────────────────── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-card);
  padding: 20px;
  box-shadow: var(--shadow-card);
  margin-bottom: 20px;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border-subtle);
}

.card-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
}

.card-subtitle {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* ── Tables ─────────────────────────────────────────────────── */
.table-wrap {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-card);
  overflow: hidden;
  box-shadow: var(--shadow-card);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

thead { background: rgba(255, 255, 255, 0.02); }

th {
  text-align: left;
  padding: 14px 12px;
  font-weight: 600;
  color: var(--text-muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 1px solid var(--border-subtle);
}

td {
  padding: 14px 12px;
  border-bottom: 1px solid var(--border-subtle);
  vertical-align: middle;
  color: var(--text-secondary);
}

tr:last-child td { border-bottom: none; }

tbody tr { transition: background var(--transition-fast); }
tbody tr:hover { background: var(--bg-card-hover); }

td .num, td .vol { font-variant-numeric: tabular-nums; }
td .name { color: var(--text-primary); font-weight: 500; }
td .muted { color: var(--text-muted); font-style: italic; }
td .unit { color: var(--text-muted); font-size: 12px; }

/* ── Buttons ────────────────────────────────────────────────── */
.btn {
  padding: 10px 20px;
  border: none;
  border-radius: var(--radius-button);
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  font-family: inherit;
  transition: all var(--transition-base);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  white-space: nowrap;
}

.btn-primary {
  background: var(--color-primary-gradient);
  color: #fff;
}

.btn-primary:hover {
  box-shadow: var(--shadow-primary);
  transform: translateY(-1px);
}

.btn-primary:active { transform: translateY(0); }

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

.btn-secondary {
  background: transparent;
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
}

.btn-secondary:hover {
  background: var(--bg-card-hover);
  color: var(--text-primary);
  border-color: var(--text-muted);
}

.btn-danger { background: var(--color-danger); color: #fff; }
.btn-danger:hover { background: #dc2626; }

.btn-success { background: var(--color-success); color: #fff; }
.btn-success:hover { background: #16a34a; }

.btn-sm { padding: 6px 14px; font-size: 12px; }

/* ── Chips ──────────────────────────────────────────────────── */
.chip {
  padding: 6px 14px;
  border-radius: var(--radius-badge);
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  font-size: 13px;
  color: var(--text-secondary);
  cursor: pointer;
  user-select: none;
  transition: all var(--transition-base);
  display: inline-flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
  font-family: inherit;
}

.chip:hover {
  border-color: var(--color-primary);
  color: var(--color-primary-light);
}

.chip.active {
  background: var(--color-primary-glow);
  color: var(--color-primary-light);
  border-color: var(--color-primary);
  font-weight: 500;
}

.chip.disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.chip.disabled:hover {
  border-color: var(--border-subtle);
  color: var(--text-secondary);
}

.chip.stub {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.chip .count { color: var(--text-muted); font-size: 11px; }
.chip.active .count { color: var(--color-primary-light); }

/* ── Toolbar & Filters ──────────────────────────────────────── */
.toolbar, .filters, .chain-filter {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  flex-wrap: wrap;
  align-items: center;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  padding: 12px 16px;
  border-radius: var(--radius-card);
}

.filter-label {
  font-weight: 500;
  color: var(--text-muted);
  font-size: 13px;
  margin-right: 4px;
}

.stats {
  margin-left: auto;
  font-size: 13px;
  color: var(--text-muted);
}

/* ── Status Badges ──────────────────────────────────────────── */
.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 12px;
  border-radius: var(--radius-badge);
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
}

.status-completed,
.status-badge.match {
  background: var(--color-success-bg);
  color: var(--color-success);
}

.status-failed {
  background: var(--color-danger-bg);
  color: var(--color-danger);
}

.status-processing {
  background: var(--color-warning-bg);
  color: var(--color-warning);
}

.status-pending {
  background: var(--color-info-bg);
  color: var(--color-info);
}

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

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

.status-badge.estimate_only {
  background: rgba(168, 85, 247, 0.15);
  color: #a855f7;
}

/* ── Forms ──────────────────────────────────────────────────── */
.field { margin-bottom: 16px; }

.field label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--text-secondary);
}

.field label .req { color: var(--color-danger); }

.field select,
.field input,
.field textarea {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-input);
  font-size: 14px;
  font-family: inherit;
  color: var(--text-primary);
  background: var(--bg-input);
  transition: border-color var(--transition-base), box-shadow var(--transition-base);
}

.field select:focus,
.field input:focus,
.field textarea:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--color-primary-glow);
}

.field select option {
  background: var(--bg-card);
  color: var(--text-primary);
}

.field textarea { resize: vertical; min-height: 80px; }
.field .hint { font-size: 11px; color: var(--text-muted); margin-top: 4px; }
.field .error-msg { font-size: 12px; color: var(--color-danger); margin-top: 4px; display: none; }

.field.invalid input,
.field.invalid textarea,
.field.invalid select { border-color: var(--color-danger); }
.field.invalid .error-msg { display: block; }

/* ── Modal ──────────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}

.modal-backdrop.open { display: flex; }

.modal {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-card);
  width: 100%;
  max-width: 520px;
  padding: 28px;
  box-shadow: var(--shadow-lg);
  animation: modalSlideUp 0.2s ease-out;
}

@keyframes modalSlideUp {
  from { transform: translateY(20px); opacity: 0; }
  to   { transform: translateY(0); opacity: 1; }
}

.modal h2 { font-size: 20px; margin-bottom: 4px; color: var(--text-primary); }

.modal .context {
  background: var(--bg-card-hover);
  padding: 12px 14px;
  border-radius: var(--radius-button);
  font-size: 12px;
  color: var(--text-secondary);
  margin: 14px 0 20px;
  border-left: 3px solid var(--color-primary);
}

.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 24px;
}

/* ── Toast ──────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  padding: 14px 20px;
  border-radius: var(--radius-button);
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  color: var(--text-primary);
  font-size: 14px;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  transform: translateY(100px);
  opacity: 0;
  transition: all var(--transition-base);
  z-index: 200;
  border-left: 4px solid var(--text-muted);
}

.toast.show { transform: translateY(0); opacity: 1; }
.toast.success { border-left-color: var(--color-success); }
.toast.error   { border-left-color: var(--color-danger); }
.toast.info    { border-left-color: var(--color-primary); }

/* ── Score & Delta ──────────────────────────────────────────── */
.score {
  display: inline-block;
  min-width: 42px;
  text-align: center;
  padding: 3px 8px;
  border-radius: var(--radius-sm);
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  font-size: 12px;
}

.score.high   { background: var(--color-success-bg); color: var(--color-success); }
.score.medium { background: var(--color-warning-bg); color: var(--color-warning); }
.score.low    { background: var(--color-danger-bg); color: var(--color-danger); }

.delta-pos { color: var(--color-success); font-weight: 500; }
.delta-neg { color: var(--color-danger); font-weight: 500; }

/* ── Flag Button ────────────────────────────────────────────── */
.flag-btn {
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  border: 1px solid var(--border-subtle);
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition-base);
  font-weight: 500;
  font-family: inherit;
}

.flag-btn:hover { border-color: var(--color-danger); color: var(--color-danger); }

.flag-btn.flagged {
  background: var(--color-danger-bg);
  color: var(--color-danger);
  border-color: var(--color-danger);
}

/* ── Process Steps ──────────────────────────────────────────── */
.steps-timeline { display: flex; flex-direction: column; gap: 12px; }

.step-item {
  display: flex;
  gap: 12px;
  padding: 14px;
  background: var(--bg-card-hover);
  border-radius: var(--radius-button);
  border-left: 4px solid var(--color-primary);
}

.step-status { width: 32px; text-align: center; flex-shrink: 0; }
.step-content { flex: 1; }
.step-name { font-weight: 600; font-size: 14px; margin-bottom: 4px; color: var(--text-primary); }
.step-details { font-size: 12px; color: var(--text-muted); }

.step-details pre {
  background: var(--bg-page);
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  overflow-x: auto;
  font-size: 11px;
  margin-top: 8px;
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
}

/* ── Stepper (horizontal stages) ────────────────────────────── */
.stepper {
  display: flex;
  align-items: center;
  gap: 0;
  margin-bottom: 24px;
  overflow-x: auto;
}

.stepper-step {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  position: relative;
  white-space: nowrap;
  font-size: 13px;
  color: var(--text-muted);
}

.stepper-step::after {
  content: '→';
  margin-left: 8px;
  color: var(--border-subtle);
}

.stepper-step:last-child::after { content: none; }

.stepper-step.done { color: var(--color-success); font-weight: 500; }
.stepper-step.current { color: var(--color-primary-light); font-weight: 600; }
.stepper-step.soon { color: var(--text-muted); opacity: 0.6; }

.stepper-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--border-subtle);
  flex-shrink: 0;
}

.stepper-step.done .stepper-dot { background: var(--color-success); }
.stepper-step.current .stepper-dot {
  background: var(--color-primary);
  box-shadow: 0 0 8px var(--color-primary-glow);
}

/* ── Info Grid ──────────────────────────────────────────────── */
.info-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 16px;
}

.info-item { display: flex; flex-direction: column; }
.info-label { font-size: 12px; color: var(--text-muted); margin-bottom: 4px; }
.info-value { font-size: 14px; font-weight: 500; word-break: break-all; color: var(--text-primary); }
.info-value.monospace { font-family: 'SF Mono', Monaco, 'Cascadia Code', monospace; font-size: 12px; }

/* ── Charts (CSS-only) ─────────────────────────────────────── */
.chart-card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-card);
  padding: 20px;
  box-shadow: var(--shadow-card);
}

.chart-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 16px;
}

.chart-bars { display: flex; align-items: flex-end; gap: 6px; height: 100px; }

.chart-bar {
  flex: 1;
  background: var(--color-primary-gradient);
  border-radius: 4px 4px 0 0;
  min-height: 4px;
  transition: height 0.3s ease;
  opacity: 0.8;
}

.chart-bar:hover { opacity: 1; }

/* ── Activity Log ───────────────────────────────────────────── */
.activity-log { display: flex; flex-direction: column; }

.activity-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px 0;
  border-bottom: 1px solid var(--border-subtle);
}

.activity-item:last-child { border-bottom: none; }

.activity-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--color-primary-glow);
  color: var(--color-primary-light);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 600;
  flex-shrink: 0;
}

.activity-body { flex: 1; }

.activity-text { font-size: 13px; color: var(--text-secondary); }
.activity-text strong { color: var(--text-primary); }
.activity-time { font-size: 11px; color: var(--text-muted); margin-top: 2px; }

/* ── Loading & Spinner ──────────────────────────────────────── */
.loading { text-align: center; padding: 60px; color: var(--text-muted); }

.spinner {
  display: inline-block;
  width: 40px;
  height: 40px;
  border: 3px solid var(--border-subtle);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin: 0 auto 15px;
}

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

.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-card);
}

/* ── Pagination ─────────────────────────────────────────────── */
.pagination {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 6px;
  padding: 16px;
  margin-top: 16px;
  flex-wrap: wrap;
}

.pagination button {
  padding: 8px 14px;
  border: 1px solid var(--border-subtle);
  background: var(--bg-card);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 13px;
  color: var(--text-secondary);
  transition: all var(--transition-base);
  font-family: inherit;
}

.pagination button:hover:not(:disabled) {
  background: var(--bg-card-hover);
  border-color: var(--color-primary);
  color: var(--text-primary);
}

.pagination button:disabled { opacity: 0.3; cursor: not-allowed; }

.pagination button.active {
  background: var(--color-primary-glow);
  color: var(--color-primary-light);
  border-color: var(--color-primary);
}

/* ── Upload Area ────────────────────────────────────────────── */
.upload-area {
  border: 2px dashed var(--border-subtle);
  border-radius: var(--radius-card);
  padding: 40px;
  text-align: center;
  cursor: pointer;
  transition: all var(--transition-base);
  background: var(--bg-card);
}

.upload-area:hover,
.upload-area.dragover {
  border-color: var(--color-primary);
  background: var(--color-primary-glow);
}

/* ── Voice Recorder ─────────────────────────────────────────── */
.voice-recorder {
  background: var(--bg-card-hover);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-button);
  padding: 14px 16px;
}

.voice-recorder .vr-row { display: flex; align-items: center; gap: 10px; }

.vr-btn {
  width: 40px; height: 40px; border-radius: 50%; border: none;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; cursor: pointer; transition: all var(--transition-base);
  flex-shrink: 0;
}

.vr-btn-record { background: var(--color-danger); color: #fff; }
.vr-btn-record:hover { background: #dc2626; }
.vr-btn-record.recording { animation: vrPulse 1.2s infinite; }

@keyframes vrPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.4); }
  50% { box-shadow: 0 0 0 10px rgba(239, 68, 68, 0); }
}

.vr-timer { font-size: 14px; font-weight: 600; font-variant-numeric: tabular-nums; min-width: 50px; color: var(--text-primary); }

.vr-level { flex: 1; height: 24px; background: var(--border-subtle); border-radius: var(--radius-badge); overflow: hidden; }
.vr-level-bar { height: 100%; width: 0%; background: linear-gradient(90deg, var(--color-primary), var(--color-danger)); border-radius: var(--radius-badge); transition: width 0.1s linear; }

.vr-hint { font-size: 11px; color: var(--text-muted); margin-top: 8px; }
.vr-hint.error { color: var(--color-danger); }

.vr-mic-error {
  display: none; align-items: flex-start; gap: 8px;
  background: var(--color-danger-bg); border: 1px solid rgba(239, 68, 68, 0.3);
  border-radius: var(--radius-sm); padding: 10px 12px;
  font-size: 12px; color: var(--color-danger); margin-top: 8px;
}
.vr-mic-error.visible { display: flex; }

.vr-playback {
  display: none; align-items: center; gap: 10px; margin-top: 10px;
  background: var(--bg-input); border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm); padding: 8px 12px;
}
.vr-playback.visible { display: flex; }

.vr-play-btn {
  width: 32px; height: 32px; border-radius: 50%;
  border: 1px solid var(--border-subtle); background: var(--bg-card);
  font-size: 12px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: all var(--transition-base); flex-shrink: 0;
  color: var(--text-secondary);
}
.vr-play-btn:hover { border-color: var(--color-primary); color: var(--color-primary-light); }

.vr-progress { flex: 1; height: 6px; background: var(--border-subtle); border-radius: var(--radius-badge); overflow: hidden; cursor: pointer; }
.vr-progress-bar { height: 100%; width: 0%; background: var(--color-primary); border-radius: var(--radius-badge); transition: width 0.1s linear; }

.vr-duration { font-size: 12px; color: var(--text-muted); font-variant-numeric: tabular-nums; min-width: 40px; text-align: right; }

.vr-delete-btn {
  padding: 4px 10px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle); background: var(--bg-card);
  font-size: 11px; cursor: pointer; color: var(--text-muted);
  transition: all var(--transition-base); flex-shrink: 0;
}
.vr-delete-btn:hover { border-color: var(--color-danger); color: var(--color-danger); }

.vr-status { display: none; font-size: 11px; color: var(--color-success); margin-top: 6px; font-weight: 500; }
.vr-status.visible { display: block; }

/* ── Process/Table specific ─────────────────────────────────── */
.process-link { color: var(--color-primary-light); text-decoration: none; font-weight: 500; }
.process-link:hover { text-decoration: underline; }

.btn-open {
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  background: var(--color-primary-glow);
  color: var(--color-primary-light);
  border: 1px solid transparent;
  font-size: 12px;
  cursor: pointer;
  transition: all var(--transition-base);
  white-space: nowrap;
  font-weight: 500;
  font-family: inherit;
}

.btn-open:hover {
  background: var(--color-primary);
  color: #fff;
}

.chain-icon { font-size: 12px; color: var(--text-secondary); white-space: nowrap; }

.refresh-btn {
  background: var(--color-success);
  color: #fff;
  border: none;
  padding: 8px 16px;
  border-radius: var(--radius-button);
  cursor: pointer;
  font-family: inherit;
  transition: all var(--transition-base);
}

.refresh-btn:hover { background: #16a34a; }

.process-table {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-card);
  overflow-x: auto;
}

.num { color: var(--text-muted); font-variant-numeric: tabular-nums; }
.muted { color: var(--text-muted); font-style: italic; }
.mono { font-family: 'SF Mono', Monaco, 'Cascadia Code', monospace; }

/* ── Tabs ───────────────────────────────────────────────────── */
.tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--border-subtle);
  padding-bottom: 0;
}

.tab {
  padding: 10px 18px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all var(--transition-base);
  font-family: inherit;
  margin-bottom: -1px;
}

.tab:hover {
  color: var(--text-primary);
  background: var(--bg-card-hover);
}

.tab.active {
  color: var(--color-primary-light);
  border-bottom-color: var(--color-primary);
}

.tab-content {
  display: none;
}

.tab-content.active {
  display: block;
}

/* ── Files Grid ─────────────────────────────────────────────── */
.files-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
}

.file-card {
  background: var(--bg-card-hover);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-button);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.file-card-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 4px;
}

.file-card .monospace {
  font-family: 'SF Mono', Monaco, 'Cascadia Code', monospace;
  font-size: 12px;
  color: var(--text-muted);
  word-break: break-all;
}

/* ── Error List ─────────────────────────────────────────────── */
.error-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.error-item {
  background: var(--color-danger-bg);
  border: 1px solid rgba(239, 68, 68, 0.2);
  border-radius: var(--radius-button);
  padding: 14px 16px;
}

.error-step {
  font-weight: 600;
  font-size: 14px;
  color: var(--color-danger);
  margin-bottom: 4px;
}

.error-message {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.error-details {
  font-size: 12px;
  color: var(--text-muted);
}

/* ── Report Content ─────────────────────────────────────────── */
.report-content {
  background: var(--bg-card-hover);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-button);
  padding: 16px;
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
}

.report-content pre {
  margin: 0;
  font-family: 'SF Mono', Monaco, 'Cascadia Code', monospace;
  font-size: 12px;
  white-space: pre-wrap;
  word-break: break-all;
}

/* ── Normalize Table Page ──────────────────────────────────── */
.html-table {
  width: 100%;
  border-collapse: collapse;
}
.html-table th {
  background: var(--color-primary);
  color: #fff;
  padding: 10px 12px;
  text-align: left;
  font-size: 13px;
  font-weight: 600;
  position: sticky;
  top: 0;
}
.html-table td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border-subtle);
  font-size: 12px;
  vertical-align: top;
  color: var(--text-secondary);
}
.html-table tr:hover { background: var(--bg-card-hover); }

.tables-row {
  display: flex;
  gap: 20px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}
.table-col {
  flex: 1;
  min-width: 360px;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-card);
  max-height: 550px;
  overflow-y: auto;
  box-shadow: var(--shadow-card);
}
.table-col h3 {
  color: var(--text-primary);
  margin: 0;
  padding: 14px 18px;
  background: var(--bg-card-hover);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  font-size: 15px;
  font-weight: 600;
}

.copy-small-btn {
  background: var(--border-subtle);
  border: none;
  padding: 5px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 12px;
  color: var(--text-secondary);
  transition: all var(--transition-base);
  font-family: inherit;
}
.copy-small-btn:hover { background: var(--text-muted); color: var(--text-primary); }

.metadata-box {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  padding: 20px;
  border-radius: var(--radius-card);
  margin-top: 20px;
  box-shadow: var(--shadow-card);
}
.metadata-box h3 { margin-bottom: 14px; color: var(--text-primary); font-size: 16px; font-weight: 600; }
.metadata-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 12px;
}
.metadata-item {
  font-family: 'SF Mono', Monaco, 'Cascadia Code', monospace;
  font-size: 12px;
  word-break: break-all;
  padding: 10px 12px;
  background: var(--bg-card-hover);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
}
.metadata-item .metadata-label {
  font-weight: 600;
  color: var(--text-muted);
  margin-right: 6px;
}

/* Status inline messages (normalize-table) */
.status-msg {
  margin-top: 12px;
  padding: 12px 16px;
  border-radius: var(--radius-button);
  font-size: 14px;
}
.status-msg.success {
  background: var(--color-success-bg);
  color: var(--color-success);
  border-left: 4px solid var(--color-success);
}
.status-msg.error {
  background: var(--color-danger-bg);
  color: var(--color-danger);
  border-left: 4px solid var(--color-danger);
}
.status-msg.info {
  background: var(--color-info-bg);
  color: var(--color-info);
  border-left: 4px solid var(--color-primary);
}

/* Spinner for button */
.btn-spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin-right: 8px;
  vertical-align: middle;
}

/* Copy notification */
.copy-notification-norm {
  position: fixed;
  bottom: 24px;
  right: 24px;
  padding: 14px 20px;
  border-radius: var(--radius-button);
  color: #fff;
  font-size: 14px;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  z-index: 200;
  animation: copyFadeOut 2s ease-in-out forwards;
}
@keyframes copyFadeOut {
  0%  { opacity: 1; }
  70% { opacity: 1; }
  100% { opacity: 0; }
}

@media (max-width: 900px) {
  .tables-row { flex-direction: column; }
  .table-col { min-width: auto; }
}

/* ── History Page: Search & Filters ──────────────────────────── */
.search-section {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-card);
  padding: 20px;
  margin-bottom: 20px;
  box-shadow: var(--shadow-card);
}

.search-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 16px;
}

.search-row {
  display: flex;
  gap: 12px;
  align-items: flex-end;
  flex-wrap: wrap;
}

.search-group {
  flex: 1;
  min-width: 200px;
}

.search-group label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--text-secondary);
}

.search-group input {
  width: 100%;
  padding: 10px 14px;
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-input);
  color: var(--text-primary);
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: border-color var(--transition-base), box-shadow var(--transition-base);
}

.search-group input:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--color-primary-glow);
}

.search-group input::placeholder { color: var(--text-muted); }

.filter-row {
  display: flex;
  gap: 12px;
  align-items: flex-end;
  flex-wrap: wrap;
}

.filter-group {
  flex: 1;
  min-width: 180px;
}

.filter-group label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--text-secondary);
}

.filter-group input,
.filter-group select {
  width: 100%;
  padding: 10px 14px;
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-input);
  color: var(--text-primary);
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: border-color var(--transition-base), box-shadow var(--transition-base);
}

.filter-group input:focus,
.filter-group select:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--color-primary-glow);
}

.filter-group input::placeholder,
.filter-group select option {
  color: var(--text-muted);
  background: var(--bg-card);
}

.filter-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

/* ── History Page: Table Card ────────────────────────────────── */
.table-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 16px;
}

.table-card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-card);
  padding: 16px 20px;
  box-shadow: var(--shadow-card);
  cursor: pointer;
  transition: all var(--transition-base);
}

.table-card:hover {
  border-color: var(--color-primary);
  background: var(--bg-card-hover);
  box-shadow: var(--shadow-primary);
  transform: translateY(-1px);
}

.table-card .card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 0;
  padding-bottom: 0;
  border-bottom: none;
}

.table-card .card-id {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
}

.table-card .card-date {
  font-size: 12px;
  color: var(--text-muted);
}

.table-card .card-badges {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.badge-process,
.badge-task {
  padding: 4px 10px;
  border-radius: var(--radius-badge);
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}

.badge-process {
  background: var(--color-primary-glow);
  color: var(--color-primary-light);
}

.badge-task {
  background: var(--color-info-bg);
  color: var(--color-info);
}

.preview {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border-subtle);
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
}

.preview-text {
  flex: 1;
  min-width: 200px;
  font-size: 12px;
  color: var(--text-muted);
  font-family: 'SF Mono', Monaco, 'Cascadia Code', monospace;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── History Page: Detail View ───────────────────────────────── */
.detail-page {
  margin-bottom: 20px;
}

.detail-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  flex-wrap: wrap;
  gap: 12px;
}

.detail-title {
  font-size: 20px;
  font-weight: 600;
  color: var(--text-primary);
}

.back-to-list {
  padding: 8px 16px;
  border-radius: var(--radius-button);
  border: 1px solid var(--border-subtle);
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  transition: all var(--transition-base);
}

.back-to-list:hover {
  background: var(--bg-card-hover);
  color: var(--text-primary);
  border-color: var(--text-muted);
}

/* ── History Page: Notification ──────────────────────────────── */
.notification {
  position: fixed;
  top: 20px;
  right: 20px;
  padding: 12px 20px;
  border-radius: var(--radius-button);
  color: #fff;
  font-size: 14px;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  z-index: 300;
  animation: notificationSlide 0.2s ease-out;
}

@keyframes notificationSlide {
  from { transform: translateY(-20px); opacity: 0; }
  to   { transform: translateY(0); opacity: 1; }
}

/* ── Clickable KPI Cards ────────────────────────────────────── */
.kpi-card.clickable {
  cursor: pointer;
  transition: border-color var(--transition-base), transform var(--transition-base), background var(--transition-base);
}

.kpi-card.clickable:hover {
  border-color: var(--color-primary);
  transform: translateY(-2px);
}

.kpi-card.clickable.active {
  border-color: var(--color-primary-light);
  background: var(--color-primary-glow);
}

/* ── Role Access ────────────────────────────────────────────── */
body.role-estimator [data-role="admin"],
body.role-estimator .sidebar-item[data-role="admin"] {
  display: none !important;
}

/* ── Role Toggle Dropdown ───────────────────────────────────── */
.topbar-role {
  position: relative;
}

.role-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  width: auto;
  height: auto;
  padding: 6px 12px 6px 10px;
  border-radius: var(--radius-button);
  border: 1px solid var(--text-muted);
  background: var(--bg-card-hover);
  color: var(--text-primary);
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  transition: all var(--transition-base);
  white-space: nowrap;
}

.role-toggle:hover {
  background: var(--color-primary-glow);
  border-color: var(--color-primary);
  color: var(--color-primary-light);
}

.role-toggle .role-icon {
  font-size: 14px;
  line-height: 1;
}

.role-toggle .role-caret {
  margin-left: 2px;
  opacity: 0.6;
  font-size: 11px;
}

.role-toggle-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-button);
  box-shadow: var(--shadow-lg);
  min-width: 180px;
  z-index: 100;
  padding: 4px;
  animation: dropdownFade 0.15s ease-out;
}

@keyframes dropdownFade {
  from { transform: translateY(-4px); opacity: 0; }
  to   { transform: translateY(0); opacity: 1; }
}

.role-option {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 10px 12px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 13px;
  font-family: inherit;
  text-align: left;
  transition: all var(--transition-fast);
}

.role-option:hover {
  background: var(--bg-card-hover);
  color: var(--text-primary);
}

.role-option.active {
  background: var(--color-primary-glow);
  color: var(--color-primary-light);
  font-weight: 500;
}

/* ── Summary Line (process table) ───────────────────────────── */
.summary-line {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  line-height: 1.4;
}

.summary-line .match { color: var(--color-success); }
.summary-line .diff  { color: var(--color-danger); }
.summary-line .unchecked { color: var(--text-muted); }

/* ── Continue Review Button ─────────────────────────────────── */
.btn-continue {
  background: var(--color-warning);
  color: #fff;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  border: none;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  font-family: inherit;
  transition: all var(--transition-base);
}

.btn-continue:hover {
  background: #d97706;
  box-shadow: 0 2px 8px rgba(245, 158, 11, 0.3);
}

.status-review_pending {
  background: var(--color-warning-bg);
  color: var(--color-warning);
}

/* ── Note Field (inline) ────────────────────────────────────── */
.note-field {
  width: 100%;
  min-width: 140px;
  padding: 4px 8px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  color: var(--text-secondary);
  font-size: 11px;
  font-family: inherit;
  resize: none;
  height: 22px;
  line-height: 1.3;
  transition: border-color var(--transition-fast);
}

.note-field:focus {
  outline: none;
  border-color: var(--color-primary);
  color: var(--text-primary);
}

.note-field::placeholder {
  color: var(--text-muted);
}

/* ── Batch Action ───────────────────────────────────────────── */
.batch-action {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  margin-bottom: 12px;
  background: var(--bg-card);
  border: 1px solid var(--color-primary);
  border-radius: var(--radius-button);
  font-size: 13px;
  color: var(--text-secondary);
}

.batch-action strong {
  color: var(--color-primary-light);
  font-variant-numeric: tabular-nums;
}

.batch-action .btn-success {
  padding: 6px 14px;
  font-size: 12px;
}

/* ── Modified Badge ─────────────────────────────────────────── */
.modified-badge {
  display: inline-block;
  font-size: 10px;
  color: var(--color-warning);
  margin-left: 4px;
  vertical-align: middle;
  cursor: help;
}

/* ── Object Group (history page) ────────────────────────────── */
.object-group {
  margin-bottom: 20px;
}

.object-group-title {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 0;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  border-bottom: 1px solid var(--border-subtle);
  margin-bottom: 12px;
}

.object-group-title .badge {
  padding: 2px 8px;
  font-size: 10px;
  font-weight: 600;
  background: var(--bg-card-hover);
  color: var(--text-muted);
  border-radius: var(--radius-badge);
}

/* ── Precheck Status (upload page) ──────────────────────────── */
.precheck-status {
  margin-top: 12px;
  padding: 12px 16px;
  background: var(--bg-card-hover);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-button);
  font-size: 13px;
}

.precheck-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
}

.precheck-row .ok { color: var(--color-success); }
.precheck-row .warn { color: var(--color-warning); }

/* ── Chain Switcher (upload page) ───────────────────────────── */
.chain-switcher {
  display: flex;
  gap: 0;
  margin: 12px 0;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-button);
  overflow: hidden;
}

.chain-switcher-item {
  flex: 1;
  padding: 10px 14px;
  text-align: center;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: all var(--transition-fast);
  border-right: 1px solid var(--border-subtle);
}

.chain-switcher-item:last-child { border-right: none; }

.chain-switcher-item:hover {
  background: var(--bg-card-hover);
  color: var(--text-primary);
}

.chain-switcher-item.active {
  background: var(--color-primary);
  color: #fff;
}

/* ── Preset Selector ────────────────────────────────────────── */
.preset-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
}

.preset-row label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  white-space: nowrap;
}

.preset-selector {
  flex: 1;
  max-width: 300px;
  padding: 8px 12px;
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-input);
  color: var(--text-primary);
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  outline: none;
}

.preset-selector:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--color-primary-glow);
}

/* ── Phase 2 Stub ───────────────────────────────────────────── */
.phase2-stub {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 16px;
  padding: 12px 16px;
  background: var(--bg-card-hover);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-button);
  font-size: 13px;
  color: var(--text-muted);
  opacity: 0.6;
}

/* ── Upload Checklist ───────────────────────────────────────── */
.upload-checklist {
  display: flex;
  gap: 24px;
  margin: 12px 0;
  padding: 12px 16px;
  background: var(--bg-card-hover);
  border-radius: var(--radius-button);
}

.checklist-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-secondary);
}

.checklist-item input[type="checkbox"] {
  accent-color: var(--color-primary);
  width: 14px;
  height: 14px;
}

.checklist-item.done {
  color: var(--color-success);
}

/* ── SVG Icons ─────────────────────────────────────────────── */
.icon {
  display: inline-block;
  width: 16px;
  height: 16px;
  vertical-align: middle;
  flex-shrink: 0;
}

.icon-lg {
  width: 20px;
  height: 20px;
}

.icon-xl {
  width: 24px;
  height: 24px;
}

/* ── Chain Type Selector ───────────────────────────────────── */
.chain-type-selector {
  display: flex;
  gap: 12px;
  margin: 16px 0;
}

.chain-type-option {
  flex: 1;
  position: relative;
  display: block;
  padding: 16px;
  border: 2px solid var(--border-subtle);
  border-radius: var(--radius-card);
  cursor: pointer;
  transition: all var(--transition-base);
  background: var(--bg-card-hover);
}

.chain-type-option:hover {
  border-color: var(--color-primary);
  background: var(--bg-card);
}

.chain-type-option.active {
  border-color: var(--color-primary);
  background: var(--color-primary-glow);
}

.chain-type-option.disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.chain-type-option input[type="radio"] {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.chain-type-label {
  display: block;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 4px;
}

.chain-type-desc {
  display: block;
  font-size: 12px;
  color: var(--text-muted);
}

.badge-soon {
  display: inline-block;
  margin-left: 8px;
  padding: 2px 8px;
  font-size: 11px;
  font-weight: 500;
  background: var(--text-muted);
  color: var(--bg-page);
  border-radius: var(--radius-badge);
}

/* ── Document Formats ──────────────────────────────────────── */
.document-formats {
  display: flex;
  gap: 16px;
  margin: 16px 0;
}

.format-group {
  flex: 1;
}

.format-group label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.format-select {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg-card-hover);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-input);
  color: var(--text-primary);
  font-size: 14px;
  cursor: pointer;
  transition: all var(--transition-base);
}

.format-select:hover {
  border-color: var(--color-primary);
}

.format-select:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--color-primary-glow);
}

/* ── Status Badges (Updated) ───────────────────────────────── */
.status-badge.status-analyzing {
  background: var(--color-warning-bg);
  color: var(--color-warning);
}

.status-badge.status-requires-review {
  background: var(--color-info-bg);
  color: var(--color-info);
}

/* ── Progress Indicator ────────────────────────────────────── */
.progress-indicator {
  width: 120px;
  height: 6px;
  background: var(--bg-card-hover);
  border-radius: var(--radius-sm);
  overflow: hidden;
  position: relative;
}

.progress-bar {
  position: absolute;
  left: 0;
  top: 0;
  height: 100%;
  width: 30%;
  background: var(--color-primary-gradient);
  border-radius: var(--radius-sm);
  animation: progress 2s infinite ease-in-out;
}

@keyframes progress {
  0% {
    left: -30%;
  }
  100% {
    left: 100%;
  }
}

/* ── Error Diagnostics Modal ───────────────────────────────── */
.error-diag-modal {
  display: none;
  position: fixed;
  z-index: 1000;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  align-items: center;
  justify-content: center;
}

.error-diag-modal.open {
  display: flex;
}

.error-diag-content {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-card);
  padding: 24px;
  max-width: 480px;
  width: 90%;
  box-shadow: var(--shadow-lg);
}

.error-diag-content h3 {
  color: var(--color-danger);
  font-size: 18px;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.error-diag-section {
  margin-bottom: 16px;
}

.error-diag-section strong {
  display: block;
  color: var(--text-secondary);
  font-size: 13px;
  margin-bottom: 6px;
}

.error-diag-section p {
  color: var(--text-primary);
  font-size: 14px;
  line-height: 1.5;
}

.error-diag-actions {
  display: flex;
  gap: 12px;
  margin-top: 20px;
}

/* ── Flag Button (Enhanced) ────────────────────────────────── */
.flag-btn.flag-incorrect {
  background: var(--color-danger-bg);
  color: var(--color-danger);
  border: 2px solid var(--color-danger);
  transition: all 0.2s;
  font-weight: 500;
}

.flag-btn.flag-incorrect:hover {
  background: var(--color-danger);
  color: white;
  box-shadow: 0 0 12px rgba(239, 68, 68, 0.4);
  transform: scale(1.02);
}

.flag-btn.flag-neutral {
  background: var(--bg-input);
  color: var(--text-muted);
  border: 1px solid var(--border-subtle);
  transition: all 0.2s;
}

.flag-btn.flag-neutral:hover {
  background: var(--bg-card-hover);
  color: var(--text-secondary);
  border-color: var(--text-muted);
}

/* ── History Chain ─────────────────────────────────────────── */
.history-chain {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px;
  background: var(--bg-card-hover);
  border-radius: var(--radius-sm);
  margin-bottom: 12px;
  overflow-x: auto;
}

.chain-step {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  background: var(--bg-card);
  border-radius: var(--radius-sm);
  white-space: nowrap;
  flex-shrink: 0;
}

.chain-step .step-icon {
  display: inline-flex;
  width: 16px;
  height: 16px;
  align-items: center;
  justify-content: center;
}

.chain-step .step-label {
  font-size: 12px;
  color: var(--text-secondary);
  font-weight: 500;
}

.chain-step .step-date {
  font-size: 11px;
  color: var(--text-muted);
}

.chain-arrow {
  color: var(--text-muted);
  font-size: 14px;
  flex-shrink: 0;
}

/* ── Scrollbar ──────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-subtle); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ── Responsive ─────────────────────────────────────────────── */
@media (max-width: 1024px) {
  .sidebar { width: 60px; }
  .sidebar-logo-text,
  .sidebar-section-label,
  .sidebar-item .item-label,
  .sidebar-item .badge-soon,
  .sidebar-footer .queue-progress span { display: none; }
  .sidebar-item { justify-content: center; padding: 12px; }
  .sidebar-logo { justify-content: center; padding: 16px 8px; }
  .main-wrapper { margin-left: 60px; }
}

@media (max-width: 768px) {
  .sidebar { display: none; }
  .main-wrapper { margin-left: 0; }
  .main-content { padding: 16px; }
  .topbar { padding: 0 16px; }
  .kpi-grid { grid-template-columns: 1fr 1fr; }
  table { font-size: 12px; }
  th, td { padding: 10px 8px; }
  .info-grid { grid-template-columns: 1fr; }
}

/* ── Print ──────────────────────────────────────────────────── */
@media print {
  body { background: white; color: black; }
  .sidebar, .topbar, .pagination { display: none !important; }
  .main-wrapper { margin-left: 0 !important; }
  .card, .table-wrap { box-shadow: none; border: 1px solid #ccc; }
}
