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

:root {
  --primary:      #4361ee;
  --primary-dark: #3a0ca3;
  --success:      #2dc653;
  --warning:      #f8961e;
  --danger:       #ef233c;
  --sidebar-bg:   #1a1a2e;
  --sidebar-w:    240px;
  --bg:           #f0f2f5;
  --card-bg:      #ffffff;
  --border:       #e2e8f0;
  --text:         #1e293b;
  --muted:        #64748b;
  --radius:       12px;
  --shadow:       0 2px 8px rgba(0,0,0,0.08);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  min-height: 100vh;
}

/* ── Sidebar ───────────────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  background: var(--sidebar-bg);
  color: #c8d3e8;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
  overflow-y: auto;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 24px 20px;
  font-size: 1.1rem;
  font-weight: 700;
  color: #fff;
  border-bottom: 1px solid rgba(255,255,255,0.07);
}

.nav-list { list-style: none; padding: 12px 0; flex: 1; }

.nav-item a {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 20px;
  color: #a0aec0;
  text-decoration: none;
  border-radius: 0;
  transition: background 0.15s, color 0.15s;
  font-size: 0.95rem;
}
.nav-item a:hover { background: rgba(255,255,255,0.06); color: #fff; }
.nav-item.active a { background: rgba(67,97,238,0.25); color: #fff; border-left: 3px solid var(--primary); }

.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid rgba(255,255,255,0.07);
  display: flex;
  align-items: center;
  gap: 10px;
}

.user-avatar {
  width: 36px; height: 36px;
  background: var(--primary);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; color: #fff; font-size: 0.9rem;
  flex-shrink: 0;
}
.user-name  { font-size: 0.85rem; font-weight: 600; color: #e2e8f0; }
.user-tier  { font-size: 0.72rem; color: #64748b; text-transform: uppercase; letter-spacing: 0.05em; }

.logout-btn {
  margin-left: auto;
  background: none; border: none;
  color: #64748b; cursor: pointer;
  padding: 4px; border-radius: 6px;
  transition: color 0.15s;
}
.logout-btn:hover { color: #ef233c; }

/* ── Main Content ──────────────────────────────────────────────────────── */
.main-content {
  margin-left: var(--sidebar-w);
  flex: 1;
  padding: 32px 40px;
  max-width: 100%;
}

.page-header {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 28px;
}
.page-header h1 { font-size: 1.6rem; font-weight: 700; }

/* ── Cards ─────────────────────────────────────────────────────────────── */
.card {
  background: var(--card-bg);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 24px;
  box-shadow: var(--shadow);
  margin-bottom: 20px;
}
.card h2 { font-size: 1.05rem; font-weight: 600; margin-bottom: 16px; }

/* ── Buttons ───────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  text-decoration: none;
  transition: opacity 0.15s, transform 0.1s;
}
.btn:hover:not(:disabled) { opacity: 0.9; transform: translateY(-1px); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }
.btn-primary  { background: var(--primary); color: #fff; }
.btn-danger   { background: var(--danger);  color: #fff; }
.btn-sm       { padding: 5px 12px; font-size: 0.8rem; }
.btn-full     { width: 100%; justify-content: center; }

.icon-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 8px;
  cursor: pointer;
  color: var(--muted);
  display: inline-flex; align-items: center;
  transition: background 0.15s, color 0.15s;
}
.icon-btn:hover { background: var(--bg); color: var(--primary); }

.btn-run {
  padding: 10px 24px;
  font-size: 0.95rem;
}

/* ── Forms ─────────────────────────────────────────────────────────────── */
label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--muted);
  margin-bottom: 14px;
}
input[type="text"],
input[type="email"],
input[type="password"],
select,
textarea {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.9rem;
  color: var(--text);
  background: var(--card-bg);
  transition: border-color 0.15s;
  width: 100%;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(67,97,238,0.15);
}
input:disabled { background: #f8fafc; cursor: not-allowed; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

/* ── Alerts ────────────────────────────────────────────────────────────── */
.alert {
  padding: 12px 16px;
  border-radius: 8px;
  margin-bottom: 16px;
  font-size: 0.9rem;
}
.alert p { margin: 2px 0; }
.alert-error   { background: #fff0f0; border: 1px solid #fca5a5; color: #b91c1c; }
.alert-success { background: #f0fdf4; border: 1px solid #86efac; color: #15803d; }

/* ── Stats ─────────────────────────────────────────────────────────────── */
.stats-row {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 24px;
}
.stat-card {
  flex: 1;
  min-width: 140px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 24px;
  box-shadow: var(--shadow);
}
.stat-value { font-size: 1.8rem; font-weight: 700; color: var(--primary); }
.stat-label { font-size: 0.8rem; color: var(--muted); margin-top: 4px; }

/* ── Tables ────────────────────────────────────────────────────────────── */
.data-table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
.data-table th {
  text-align: left;
  padding: 10px 12px;
  background: var(--bg);
  border-bottom: 2px solid var(--border);
  font-weight: 600;
  color: var(--muted);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.data-table td { padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.data-table tr:last-child td { border-bottom: none; }

/* ── Tier badges ───────────────────────────────────────────────────────── */
.tier-badge {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  padding: 3px 10px;
  border-radius: 20px;
}
.tier-free   { background: #e2e8f0; color: #475569; }
.tier-pro    { background: #dbeafe; color: #1d4ed8; }
.tier-max    { background: #ede9fe; color: #6d28d9; }
.tier-admin  { background: #fef3c7; color: #b45309; }
.tier-hint   { font-size: 0.8rem; color: var(--muted); }

.engine-tag {
  background: #f1f5f9;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 2px 8px;
  font-size: 0.78rem;
  font-weight: 600;
}

.status-badge {
  font-size: 0.75rem;
  padding: 2px 8px;
  border-radius: 20px;
}
.status-success { background: #dcfce7; color: #15803d; }
.status-error   { background: #fee2e2; color: #b91c1c; }
.status-pending { background: #fef9c3; color: #92400e; }

/* ── Auth pages ────────────────────────────────────────────────────────── */
.auth-body { background: var(--bg); display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.auth-card {
  background: var(--card-bg);
  border-radius: 16px;
  padding: 40px;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 4px 24px rgba(0,0,0,0.1);
}
.auth-logo { display: flex; align-items: center; gap: 10px; font-size: 1.2rem; font-weight: 700; margin-bottom: 24px; }
.auth-card h1 { font-size: 1.4rem; margin-bottom: 24px; }
.auth-footer { text-align: center; font-size: 0.85rem; color: var(--muted); margin-top: 16px; }
.auth-footer a { color: var(--primary); text-decoration: none; }
.auth-footer.small { font-size: 0.78rem; }

/* ── Settings ──────────────────────────────────────────────────────────── */
.settings-form { max-width: 680px; }

/* ── Empty state ───────────────────────────────────────────────────────── */
.empty-state { text-align: center; padding: 60px 20px; color: var(--muted); }
.empty-state p { margin-bottom: 16px; }

/* ── Misc ──────────────────────────────────────────────────────────────── */
.muted { color: var(--muted); }
.small { font-size: 0.8rem; }
select { cursor: pointer; }

/* ── Admin engine grid ─────────────────────────────────────────────────── */
.engine-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 12px;
}
.engine-status-card {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
  font-size: 0.85rem;
}
.engine-status-card.configured { border-color: #86efac; background: #f0fdf4; }
.engine-status-card.unconfigured { border-color: #fca5a5; background: #fff5f5; }
.es-name { font-weight: 700; margin-bottom: 4px; }
.es-tier { color: var(--muted); font-size: 0.78rem; }
.es-status { font-size: 0.8rem; margin-top: 6px; font-weight: 600; }
.engine-status-card.configured .es-status { color: #15803d; }
.engine-status-card.unconfigured .es-status { color: #b91c1c; }
.es-keys { margin-top: 4px; word-break: break-all; }

/* ── Tier select in admin ──────────────────────────────────────────────── */
.tier-select { width: auto; padding: 4px 8px; font-size: 0.82rem; }

/* ── Admin API key editor ──────────────────────────────────────────────── */
.api-key-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 20px;
}
.api-key-group {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
  background: #fafbff;
}
.api-key-group h3 {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--primary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}
.api-key-label {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin-bottom: 10px;
}
.api-key-label:last-child { margin-bottom: 0; }
.key-name {
  font-size: 0.73rem;
  font-weight: 700;
  color: var(--muted);
  font-family: 'SFMono-Regular', Consolas, monospace;
  letter-spacing: 0.02em;
}
.key-input-row {
  display: flex;
  gap: 6px;
}
.key-input {
  flex: 1;
  padding: 7px 10px;
  font-size: 0.82rem;
  font-family: 'SFMono-Regular', Consolas, monospace;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  width: auto;
  min-width: 0;
}
.key-input:focus { border-color: var(--primary); box-shadow: 0 0 0 2px rgba(67,97,238,0.12); outline: none; }
.key-toggle-btn {
  flex-shrink: 0;
  padding: 0 10px;
  font-size: 0.75rem;
  font-weight: 600;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  color: var(--muted);
  transition: background 0.15s, color 0.15s;
}
.key-toggle-btn:hover { background: #e0e7ff; color: var(--primary); }

/* ════════════════════════════════════════════════════════════════════════
   FLOWCHART
   ════════════════════════════════════════════════════════════════════════ */
.translation-main { padding: 32px 32px 32px 40px; }

.flowchart {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 100px;
  padding-bottom: 40px;
}

/* ── SVG arrow overlay ─────────────────────────────────────────────────── */
.flow-arrows-svg {
  position: absolute;
  top: 0; left: 0;
  width: 100%;
  pointer-events: none;
  overflow: visible;
  z-index: 0;
}

/* ── Flow nodes (shared) ───────────────────────────────────────────────── */
.flow-node {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 960px;
  background: var(--card-bg);
  border: 1.5px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06), 0 4px 16px rgba(0,0,0,0.05);
  overflow: hidden;
}

.node-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--border);
  background: #f8f9fc;
  flex-wrap: wrap;
}
.node-header h3 {
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: #475569;
  white-space: nowrap;
}

.node-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 7px 14px 7px 18px;
  border-top: 1px solid var(--border);
  background: #f8f9fc;
  font-size: 0.78rem;
  color: var(--muted);
  gap: 10px;
}
.node-footer-actions {
  display: flex;
  align-items: center;
  gap: 7px;
  flex-shrink: 0;
}
.kbd-hint {
  display: inline-block;
  font-family: inherit;
  font-size: 0.68rem;
  color: rgba(255,255,255,0.7);
  background: rgba(255,255,255,0.18);
  border-radius: 4px;
  padding: 1px 5px;
  letter-spacing: 0.02em;
  margin-left: 3px;
  vertical-align: middle;
}

/* Step badges */
.step-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px; height: 22px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  font-size: 0.72rem;
  font-weight: 800;
  flex-shrink: 0;
}
.step-badge-conf { background: #7c3aed; }
.step-badge-best { background: #d97706; }

/* ── Source node ───────────────────────────────────────────────────────── */
.source-node { border-color: #c7d2fe; }
.source-node .node-header { background: #eef2ff; border-bottom-color: #c7d2fe; }

.source-node textarea {
  display: block;
  width: 100%;
  border: none;
  border-radius: 0;
  resize: vertical;
  min-height: 120px;
  font-size: 0.95rem;
  line-height: 1.7;
  padding: 16px 18px;
  background: #fff;
  color: var(--text);
  box-shadow: none;
}
.source-node textarea:focus { outline: none; box-shadow: none; }
.char-count { font-size: 0.78rem; color: var(--muted); }

/* Language controls inside source header */
.lang-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  flex-wrap: wrap;
}
.lang-group {
  display: flex;
  align-items: center;
  gap: 6px;
}
.lang-group label {
  margin: 0;
  font-size: 0.72rem;
  font-weight: 700;
  color: #6366f1;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  flex-direction: row;
  white-space: nowrap;
}
.lang-group select {
  width: auto;
  min-width: 140px;
  padding: 5px 8px;
  font-size: 0.83rem;
  border-radius: 7px;
  border-color: #c7d2fe;
}
.lang-arrow { color: #a5b4fc; flex-shrink: 0; }

/* ── Engines section node ──────────────────────────────────────────────── */
.engines-node { border-color: #bfdbfe; }
.engines-node .node-header { background: #eff6ff; border-bottom-color: #bfdbfe; }

.node-body {
  padding: 0;
  background: #fff;
}

.add-engine-btn {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px; height: 28px;
  border-radius: 7px;
  border: 1.5px solid #93c5fd;
  background: #eff6ff;
  color: #3b82f6;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  flex-shrink: 0;
}
.add-engine-btn:hover { background: #dbeafe; border-color: var(--primary); color: var(--primary); }
.add-engine-btn:disabled { border-color: var(--border); color: #cbd5e1; background: #f8fafc; cursor: not-allowed; }

/* ── Engine picker ─────────────────────────────────────────────────────── */
.engine-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  background: #f8faff;
  min-height: 56px;
  align-items: center;
}
.picker-hint {
  font-size: 0.82rem;
  color: var(--muted);
  margin: 0;
}
.picker-cap {
  font-size: 0.75rem;
  color: var(--muted);
  margin: 0 0 0 auto;
  flex-shrink: 0;
}

.engine-pick-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 12px 6px 7px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  background: #fff;
  cursor: pointer;
  font-size: 0.82rem;
  font-weight: 500;
  color: #475569;
  transition: border-color 0.15s, background 0.15s, color 0.15s, box-shadow 0.15s;
  user-select: none;
}
.engine-pick-btn:hover:not(:disabled) {
  border-color: var(--primary);
  color: var(--primary);
  background: #eff6ff;
}
.engine-pick-btn.active {
  border-color: var(--primary);
  background: #eef2ff;
  color: var(--primary);
  font-weight: 600;
  box-shadow: 0 0 0 3px rgba(67,97,238,0.12);
}
.engine-pick-btn:disabled {
  opacity: 0.38;
  cursor: not-allowed;
}
.engine-pick-icon {
  width: 22px;
  height: 22px;
  border-radius: 5px;
  font-size: 0.66rem;
  font-weight: 800;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  letter-spacing: -0.02em;
}
.engine-pick-name {
  white-space: nowrap;
}
.engine-pick-check {
  display: flex;
  align-items: center;
  color: var(--primary);
  margin-left: 2px;
}

/* ── Engine card: badge chip (replaces select) ──────────────────────────── */
.engine-badge-chip {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 0.72rem;
  font-weight: 700;
  color: #fff;
  letter-spacing: 0.02em;
  flex-shrink: 0;
  white-space: nowrap;
}

/* ── Engine lanes row ──────────────────────────────────────────────────── */
.engine-lanes {
  display: flex;
  gap: 12px;
  align-items: stretch;
  padding: 14px;
}

/* ── Engine cards ──────────────────────────────────────────────────────── */
.engine-card {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  background: #fff;
  border: 1.5px solid #e2e8f0;
  border-radius: 10px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
  overflow: hidden;
  transition: border-color 0.18s, box-shadow 0.18s;
}
.engine-card:hover { border-color: #93c5fd; box-shadow: 0 2px 10px rgba(59,130,246,0.12); }

.card-head {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 8px 10px;
  border-bottom: 1px solid #f1f5f9;
  background: #f8faff;
}
.engine-num {
  font-size: 0.65rem;
  font-weight: 800;
  color: var(--primary);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  background: #eef2ff;
  padding: 2px 6px;
  border-radius: 20px;
  white-space: nowrap;
  flex-shrink: 0;
}
.card-head select {
  flex: 1;
  padding: 4px 7px;
  font-size: 0.8rem;
  border-radius: 6px;
  border-color: #e2e8f0;
  min-width: 0;
}

.close-btn {
  flex-shrink: 0;
  background: none;
  border: none;
  width: 20px; height: 20px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 15px;
  line-height: 1;
  color: #94a3b8;
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
}
.close-btn:hover { background: #fee2e2; color: var(--danger); }

.card-body {
  flex: 1;
  padding: 10px 12px;
  min-height: 88px;
}
.card-body textarea {
  width: 100%;
  border: none;
  resize: none;
  font-size: 0.87rem;
  line-height: 1.65;
  color: var(--text);
  background: transparent;
  min-height: 80px;
}
.card-body textarea:focus { outline: none; }
.placeholder-text {
  font-size: 0.8rem;
  color: #94a3b8;
  font-style: italic;
  line-height: 1.5;
}

.card-foot {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-top: 1px solid #f1f5f9;
  background: #f8faff;
  font-size: 0.76rem;
  color: var(--muted);
  min-height: 34px;
}
.card-foot .spacer { flex: 1; }

.status-dot {
  display: inline-block;
  width: 7px; height: 7px;
  border-radius: 50%;
  background: #cbd5e1;
  flex-shrink: 0;
}
.status-dot.running { background: var(--warning); animation: pulse 1s infinite; }
.status-dot.done    { background: var(--success); }
.status-dot.error   { background: var(--danger); }
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:0.35} }

/* ── Confidence section node ───────────────────────────────────────────── */
.confidence-node { border-color: #ddd6fe; }
.confidence-node .node-header { background: #f5f3ff; border-bottom-color: #ddd6fe; }

.model-tag {
  font-size: 0.7rem;
  font-weight: 600;
  color: #7c3aed;
  background: #ede9fe;
  padding: 2px 8px;
  border-radius: 20px;
  letter-spacing: 0.02em;
}

/* ── Confidence cards ──────────────────────────────────────────────────── */
.confidence-card {
  flex: 1;
  min-width: 0;
  background: #faf8ff;
  border: 1.5px solid #ede9fe;
  border-radius: 10px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
  overflow: hidden;
}

.conf-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  border-bottom: 1px solid #ede9fe;
  background: #f5f3ff;
}
.conf-head h4 {
  font-size: 0.67rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: #6d28d9;
}
.auto-run-label {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 0.73rem;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
}
.auto-run-label input { width: auto; margin: 0; }

.conf-body {
  padding: 14px 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  min-height: 110px;
}

.score-ring {
  width: 68px; height: 68px;
  border-radius: 50%;
  background: conic-gradient(#e2e8f0 0%, #e2e8f0 100%);
  display: flex; align-items: center; justify-content: center;
  position: relative;
  flex-shrink: 0;
}
.score-ring::after {
  content: '';
  position: absolute;
  inset: 9px;
  background: #faf8ff;
  border-radius: 50%;
}
.score-value {
  position: relative;
  z-index: 1;
  font-size: 1rem;
  font-weight: 800;
  color: #1e293b;
}
.conf-reasoning {
  font-size: 0.76rem;
  color: var(--muted);
  text-align: center;
  line-height: 1.45;
  max-width: 175px;
}
.conf-best-tag {
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  background: #fef3c7;
  color: #92400e;
  border: 1px solid #fde68a;
  border-radius: 20px;
  padding: 2px 10px;
}

/* ── Best translation node ─────────────────────────────────────────────── */
/* ── Translation progress bar ──────────────────────────────────────────── */
.run-progress {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 960px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 28px 24px;
  background: var(--card-bg);
  border: 1.5px solid #c7d2fe;
  border-radius: 14px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06), 0 4px 16px rgba(67,97,238,0.07);
}
.run-progress-track {
  width: 100%;
  max-width: 480px;
  height: 5px;
  background: #e2e8f0;
  border-radius: 20px;
  overflow: hidden;
}
.run-progress-bar {
  height: 100%;
  width: 42%;
  background: linear-gradient(90deg, #4361ee, #7c3aed);
  border-radius: 20px;
  animation: rp-sweep 1.6s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}
@keyframes rp-sweep {
  0%   { transform: translateX(-120%); }
  100% { transform: translateX(370%);  }
}
.run-progress-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.86rem;
  font-weight: 600;
  color: var(--primary);
}
.run-progress-dots {
  display: inline-flex;
  gap: 4px;
}
.run-progress-dots span {
  width: 5px; height: 5px;
  border-radius: 50%;
  background: var(--primary);
  animation: rp-dot 1.3s ease-in-out infinite both;
}
.run-progress-dots span:nth-child(2) { animation-delay: 0.18s; }
.run-progress-dots span:nth-child(3) { animation-delay: 0.36s; }
@keyframes rp-dot {
  0%, 80%, 100% { transform: scale(0.55); opacity: 0.35; }
  40%            { transform: scale(1);    opacity: 1;    }
}

/* ── Best translation – split layout ───────────────────────────────────── */
.best-node { border-color: #fde68a; }
.best-node .node-header { background: #fffbeb; border-bottom-color: #fde68a; }
.best-node .node-header h3 { color: #92400e; }
.best-meta {
  font-size: 0.8rem;
  font-weight: 600;
  color: #b45309;
  background: #fef3c7;
  border: 1px solid #fde68a;
  border-radius: 20px;
  padding: 2px 10px;
  white-space: nowrap;
}
.best-text {
  padding: 18px 20px;
  font-size: 0.95rem;
  line-height: 1.75;
  color: var(--text);
  min-height: 64px;
  background: #fff;
  white-space: pre-wrap;
  word-break: break-word;
}
.best-reasoning {
  padding: 8px 20px 14px;
  font-size: 0.8rem;
  color: #92400e;
  font-style: italic;
  line-height: 1.55;
  border-top: 1px solid #fde68a;
  background: #fffdf5;
  display: none;
}
.best-reasoning:not(:empty) { display: block; }

.best-split {
  display: flex;
  min-height: 120px;
}
.best-split-panel {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}
.best-split-divider {
  width: 1px;
  background: #fde68a;
  flex-shrink: 0;
}
.best-split-label {
  padding: 5px 20px;
  font-size: 0.67rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  border-bottom: 1px solid;
}
.best-split-source .best-split-label {
  color: #4338ca;
  background: #eef2ff;
  border-color: #c7d2fe;
}
.best-split-translation .best-split-label {
  color: #92400e;
  background: #fffbeb;
  border-color: #fde68a;
}
.best-source-text {
  padding: 18px 20px;
  font-size: 0.93rem;
  line-height: 1.75;
  color: #475569;
  background: #fafbff;
  flex: 1;
  white-space: pre-wrap;
  word-break: break-word;
}

@media (max-width: 600px) {
  .best-split { flex-direction: column; }
  .best-split-divider { width: 100%; height: 1px; }
}

/* ── Collapsible flow nodes ─────────────────────────────────────────────── */
.node-header.collapsible {
  cursor: pointer;
  user-select: none;
  padding-right: 42px;
  position: relative;
}
.node-header.collapsible:hover { filter: brightness(0.97); }

.collapse-chevron {
  position: absolute;
  right: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  transition: transform 0.22s ease;
  pointer-events: none;
}
.flow-node.collapsed .collapse-chevron {
  transform: translateY(-50%) rotate(180deg);
}

.flow-node.collapsed > *:not(.node-header) { display: none; }

/* ════════════════════════════════════════════════════════════════════════
   ADMIN PANEL
   ════════════════════════════════════════════════════════════════════════ */

/* ── Sub-navigation ────────────────────────────────────────────────────── */
.admin-subnav {
  display: flex;
  gap: 2px;
  border-bottom: 2px solid var(--border);
  margin-bottom: 24px;
}

.admin-tab-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 10px 18px;
  border: none;
  background: none;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  border-radius: 6px 6px 0 0;
  transition: color 0.15s, background 0.15s, border-color 0.15s;
  white-space: nowrap;
}
.admin-tab-btn:hover  { color: var(--primary); background: #f0f3ff; }
.admin-tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); background: #f0f3ff; }

/* ── Tab pane ──────────────────────────────────────────────────────────── */
.admin-tab-pane { animation: fadeIn 0.15s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* ── Tab toolbar (heading + action button) ─────────────────────────────── */
.tab-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.tab-toolbar h2 { font-size: 1.05rem; font-weight: 700; }

.tab-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: #e2e8f0;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
  border-radius: 20px;
  padding: 1px 8px;
  margin-left: 8px;
  vertical-align: middle;
}

/* ── User table cells ──────────────────────────────────────────────────── */
.user-cell {
  display: flex;
  align-items: center;
  gap: 10px;
}
.user-avatar-sm {
  width: 32px; height: 32px;
  font-size: 0.8rem;
  flex-shrink: 0;
}
.user-cell-name  { font-size: 0.88rem; font-weight: 600; }
.user-cell-email { font-size: 0.78rem; }

/* ── Row action buttons ────────────────────────────────────────────────── */
.row-actions {
  display: flex;
  gap: 4px;
  align-items: center;
}
.action-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px; height: 30px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: none;
  color: var(--muted);
  cursor: pointer;
  transition: background 0.14s, color 0.14s, border-color 0.14s;
}
.action-btn:hover              { background: var(--bg); color: var(--primary); border-color: #c7d2fe; }
.action-btn.action-btn-danger:hover { background: #fff0f0; color: var(--danger); border-color: #fca5a5; }

/* ── Language route tag ────────────────────────────────────────────────── */
.lang-route {
  font-size: 0.78rem;
  font-weight: 600;
  font-family: 'SFMono-Regular', Consolas, monospace;
  background: #f1f5f9;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 2px 7px;
}

/* ── Engine confidence leaderboard ────────────────────────────────────── */
.eng-score-table th,
.eng-score-table td { vertical-align: middle; }

.eng-score-cell {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 140px;
}
.eng-score-bar-wrap {
  flex: 1;
  height: 7px;
  background: #e2e8f0;
  border-radius: 20px;
  overflow: hidden;
}
.eng-score-bar-fill {
  height: 100%;
  border-radius: 20px;
  transition: width 0.4s ease;
  min-width: 2px;
}
.eng-score-num {
  font-size: 0.8rem;
  font-weight: 700;
  white-space: nowrap;
  min-width: 36px;
  text-align: right;
}
.eng-medal {
  font-size: 1rem;
  line-height: 1;
}

/* ── Dialogs ───────────────────────────────────────────────────────────── */
dialog.admin-dialog {
  border: none;
  border-radius: 14px;
  padding: 0;
  width: 100%;
  max-width: 440px;
  box-shadow: 0 8px 40px rgba(0,0,0,0.18);
  animation: dialogIn 0.18s ease;
  /* Counteract the * { margin:0 } reset — showModal() needs margin:auto to centre */
  margin: auto;
}
dialog.admin-dialog::backdrop {
  background: rgba(15,23,42,0.45);
  backdrop-filter: blur(2px);
}
@keyframes dialogIn {
  from { opacity: 0; transform: scale(0.96) translateY(-8px); }
  to   { opacity: 1; transform: none; }
}

.dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px 14px;
  border-bottom: 1px solid var(--border);
}
.dialog-header h3 { font-size: 1rem; font-weight: 700; }

.dialog-close {
  background: none;
  border: none;
  font-size: 22px;
  line-height: 1;
  color: var(--muted);
  cursor: pointer;
  padding: 0 4px;
  border-radius: 4px;
  transition: color 0.14s;
}
.dialog-close:hover { color: var(--danger); }

dialog.admin-dialog form,
dialog.admin-dialog > p { padding: 18px 20px; }

dialog.admin-dialog label {
  margin-bottom: 14px;
}

.dialog-error {
  background: #fff0f0;
  border: 1px solid #fca5a5;
  color: #b91c1c;
  border-radius: 7px;
  padding: 9px 12px;
  font-size: 0.85rem;
  margin-bottom: 14px;
}

.dialog-actions {
  display: flex;
  gap: 8px;
  padding-top: 4px;
  border-top: 1px solid var(--border);
  margin-top: 6px;
  padding-top: 16px;
}

/* ── Admin toast ───────────────────────────────────────────────────────── */
.admin-toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: #1e293b;
  color: #fff;
  padding: 10px 18px;
  border-radius: 8px;
  font-size: 0.85rem;
  z-index: 9999;
  box-shadow: 0 4px 16px rgba(0,0,0,0.2);
  transition: opacity 0.4s;
  pointer-events: none;
}
.admin-toast-error { background: var(--danger); }

.btn-outline {
  background: transparent;
  border: 1.5px solid var(--border);
  color: var(--text);
}
.btn-outline:hover:not(:disabled) {
  background: var(--bg);
  border-color: var(--primary);
  color: var(--primary);
  opacity: 1;
  transform: none;
}

/* ── Active session card (date-create page) ────────────────────────────── */
.active-session-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}
.active-session-row:first-of-type { padding-top: 0; }
.active-session-row:last-of-type  { border-bottom: none; padding-bottom: 0; }

.active-session-info {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
  flex: 1;
}

.active-session-code {
  font-family: 'SFMono-Regular', Consolas, monospace;
  font-size: 1.1rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  color: var(--text);
}

.active-session-detail {
  font-size: 0.78rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.active-session-btns {
  display: flex;
  gap: 6px;
  align-items: center;
  flex-shrink: 0;
}

/* ════════════════════════════════════════════════════════════════════════
   MOBILE TOPBAR + SIDEBAR OVERLAY
   ════════════════════════════════════════════════════════════════════════ */

/* Hidden on desktop; made visible inside the media query below */
.mobile-topbar {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 52px;
  background: var(--sidebar-bg);
  color: #fff;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  z-index: 201;
  box-shadow: 0 1px 4px rgba(0,0,0,0.3);
}

.mobile-brand {
  font-size: 1rem;
  font-weight: 700;
  color: #fff;
}

.hamburger-btn {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 6px;
  border-radius: 6px;
  color: rgba(255,255,255,0.85);
  flex-shrink: 0;
}
.hamburger-btn span {
  display: block;
  width: 20px;
  height: 2px;
  background: currentColor;
  border-radius: 2px;
  transition: opacity 0.15s;
}
.hamburger-btn:hover span { opacity: 1; color: #fff; }

/* Sidebar backdrop */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  z-index: 150;
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}
.sidebar-overlay-visible { display: block; }

/* Prevent body scroll when sidebar is open */
body.sidebar-is-open { overflow: hidden; }

/* ════════════════════════════════════════════════════════════════════════
   RESPONSIVE — ≤ 768 px
   ════════════════════════════════════════════════════════════════════════ */
@media (max-width: 768px) {

  /* Show mobile topbar */
  .mobile-topbar { display: flex; }

  /* Push content below the fixed topbar */
  body { padding-top: 52px; }

  /* Sidebar: slides in from left as overlay */
  .sidebar {
    transform: translateX(-100%);
    transition: transform 0.24s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 200;
  }
  .sidebar.sidebar-open { transform: translateX(0); }

  /* Main content fills the full width */
  .main-content {
    margin-left: 0;
    padding: 16px;
  }

  /* ── Page header ────────────────────────────────────────────────────── */
  .page-header { margin-bottom: 16px; gap: 10px; }
  .page-header h1 { font-size: 1.25rem; }

  /* ── Cards ──────────────────────────────────────────────────────────── */
  .card { padding: 16px; }

  /* ── Stats row ──────────────────────────────────────────────────────── */
  .stats-row { gap: 10px; }
  .stat-card { min-width: 0; padding: 14px 16px; }
  .stat-value { font-size: 1.5rem; }

  /* ── Tables – horizontal scroll ─────────────────────────────────────── */
  .data-table { font-size: 0.82rem; }
  .card:has(.data-table) { padding: 0; }
  .card:has(.data-table) h2 { padding: 16px 16px 0; }
  .data-table th,
  .data-table td { padding: 8px 10px; }

  /* ── Settings ────────────────────────────────────────────────────────── */
  .settings-form { max-width: 100%; }
  .two-col { grid-template-columns: 1fr; gap: 0; }

  /* ── Admin subnav – scroll horizontally ─────────────────────────────── */
  .admin-subnav {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    gap: 0;
    margin-bottom: 16px;
  }
  .admin-subnav::-webkit-scrollbar { display: none; }
  .admin-tab-btn { padding: 10px 13px; font-size: 0.82rem; white-space: nowrap; }

  /* ── Admin engine grid ───────────────────────────────────────────────── */
  .engine-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }

  /* ── API key grid ────────────────────────────────────────────────────── */
  .api-key-grid { grid-template-columns: 1fr; }

  /* ── Row actions ─────────────────────────────────────────────────────── */
  .user-cell-email { display: none; }

  /* ── Dialogs ─────────────────────────────────────────────────────────── */
  dialog.admin-dialog {
    width: calc(100vw - 24px);
    max-width: none;
    margin: 12px auto;
  }

  /* ── Active session buttons ──────────────────────────────────────────── */
  .active-session-row { flex-wrap: wrap; }
  .active-session-btns {
    width: 100%;
    justify-content: flex-end;
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid var(--border);
  }

  /* ── Auth pages ──────────────────────────────────────────────────────── */
  .auth-card { padding: 28px 20px; width: calc(100% - 32px); }

  /* ── Translation flowchart ───────────────────────────────────────────── */
  .translation-main { padding: 12px; }
  .flowchart { gap: 36px; }

  /* Engine and confidence lanes scroll horizontally on small screens */
  .engine-lanes {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 4px;
  }
  .engine-card,
  .confidence-card { min-width: 190px; }

  /* Tighten up the node body padding */
  .node-body { padding: 10px; }
  .node-header { padding: 10px 12px; gap: 8px; }

  /* Language selector – narrower on mobile */
  .lang-group select { min-width: 110px; }
  .lang-controls { gap: 6px; }

  /* ── Tier hint text – hide on very small screens ─────────────────────── */
  .tier-hint { display: none; }
}

/* ── Very small screens (≤ 420 px) ────────────────────────────────────── */
@media (max-width: 420px) {
  .page-header h1 { font-size: 1.1rem; }
  .btn-run { padding: 8px 14px; font-size: 0.85rem; }
  .active-session-btns { gap: 4px; }
  .active-session-btns .btn-sm { padding: 5px 9px; font-size: 0.76rem; }
}

/* ── i18n language selector – sidebar ─────────────────────────────────── */
.sidebar-lang {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-top: 1px solid rgba(255,255,255,0.07);
  color: rgba(255,255,255,0.4);
}
.sidebar-lang svg { flex-shrink: 0; }
.sidebar-lang .i18n-selector {
  flex: 1;
  min-width: 0;
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 6px;
  color: rgba(255,255,255,0.72);
  font-size: 0.77rem;
  padding: 5px 8px;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
}
.sidebar-lang .i18n-selector:hover {
  background: rgba(255,255,255,0.1);
  border-color: rgba(255,255,255,0.2);
  color: rgba(255,255,255,0.9);
}
.sidebar-lang .i18n-selector:focus { outline: none; border-color: #4361ee; }
.sidebar-lang .i18n-selector option { background: #1e293b; color: #f1f5f9; }

/* ── i18n language selector – auth pages ──────────────────────────────── */
.auth-lang-bar {
  position: fixed;
  top: 16px;
  right: 20px;
  display: flex;
  align-items: center;
  gap: 5px;
  color: #64748b;
  z-index: 10;
}
.auth-lang-bar svg { flex-shrink: 0; }
.auth-lang-bar .i18n-selector {
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  color: #475569;
  font-size: 0.78rem;
  padding: 4px 8px;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
}
.auth-lang-bar .i18n-selector:hover { border-color: #94a3b8; }
.auth-lang-bar .i18n-selector:focus { outline: none; border-color: #4361ee; }
