:root {
  /* Surfaces */
  --bg: #eef2f7;
  --bg-subtle: #e2e8f0;
  --panel: #ffffff;
  --panel2: #f8fafc;
  --line: #e2e8f0;
  --line-strong: #cbd5e1;
  --fg: #0f172a;
  --fg-secondary: #334155;
  --muted: #64748b;

  /* Brand & accent (teal — data / sustainability) */
  --accent: #0d9488;
  --accent-hover: #0f766e;
  --accent-soft: rgba(13, 148, 136, 0.1);
  --accent-glow: rgba(13, 148, 136, 0.25);

  /* Pipeline stage colors */
  --stage-upload: #0284c7;
  --stage-upload-soft: rgba(2, 132, 199, 0.1);
  --stage-etl: #7c3aed;
  --stage-etl-soft: rgba(124, 58, 237, 0.1);
  --stage-group: #d97706;
  --stage-group-soft: rgba(217, 119, 6, 0.1);
  --stage-submit: #059669;
  --stage-submit-soft: rgba(5, 150, 105, 0.1);

  /* Status */
  --ok: #059669;
  --ok-soft: rgba(5, 150, 105, 0.1);
  --warn: #d97706;
  --warn-soft: rgba(217, 119, 6, 0.1);
  --err: #dc2626;
  --err-soft: rgba(220, 38, 38, 0.08);

  /* Header */
  --header-bg: #0f172a;
  --header-fg: #f1f5f9;
  --header-muted: #94a3b8;

  --shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 4px 20px rgba(15, 23, 42, 0.08);
  --shadow-lg: 0 16px 48px rgba(15, 23, 42, 0.14);
  --radius: 8px;
  --radius-lg: 12px;

  /* Form controls — shared sizing */
  --ctrl-h: 36px;
  --ctrl-h-sm: 32px;
  --ctrl-px: 12px;
  --ctrl-radius: 6px;
  --ctrl-fs: 13px;
  --ctrl-fs-sm: 12.5px;
  --ctrl-gap: 8px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background:
    radial-gradient(ellipse 80% 50% at 50% -20%, rgba(13, 148, 136, 0.08), transparent),
    radial-gradient(ellipse 60% 40% at 100% 0%, rgba(2, 132, 199, 0.06), transparent),
    var(--bg);
  color: var(--fg);
  font: 14px/1.55 "DM Sans", "Segoe UI", system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); text-decoration: underline; }

/* ── Header ── */
header {
  background: var(--header-bg);
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  padding: 0 28px;
  height: 60px;
  display: flex;
  align-items: center;
  gap: 20px;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.2);
  position: sticky;
  top: 0;
  z-index: 100;
}

header .brand {
  display: flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
  color: var(--header-fg);
}

header .brand:hover { text-decoration: none; color: var(--header-fg); }

header .brand-mark {
  width: 32px;
  height: 32px;
  flex-shrink: 0;
  display: block;
}

header .brand-mark svg {
  width: 32px;
  height: 32px;
  display: block;
}

header .brand-text {
  display: flex;
  flex-direction: column;
  gap: 0;
  line-height: 1.2;
}

header h1 {
  font-size: 15px;
  font-weight: 700;
  margin: 0;
  letter-spacing: -0.02em;
  color: #fff;
}

header .brand-tagline {
  font-size: 10.5px;
  font-weight: 500;
  color: var(--header-muted);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

header .header-nav {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-left: 8px;
}

header .nav-link {
  display: inline-flex;
  align-items: center;
  height: var(--ctrl-h-sm);
  color: var(--header-muted);
  font-size: var(--ctrl-fs-sm);
  font-weight: 500;
  padding: 0 12px;
  border-radius: var(--ctrl-radius);
  transition: background 0.15s, color 0.15s;
}

header .nav-link:hover {
  color: var(--header-fg);
  background: rgba(255, 255, 255, 0.06);
  text-decoration: none;
}

header .nav-link.active {
  color: #fff;
  background: rgba(13, 148, 136, 0.25);
}

header .pill { margin-left: auto; }

header .pill.ok {
  background: rgba(5, 150, 105, 0.15);
  color: #6ee7b7;
  border-color: rgba(5, 150, 105, 0.3);
}

header .pill.err {
  background: rgba(220, 38, 38, 0.15);
  color: #fca5a5;
  border-color: rgba(220, 38, 38, 0.3);
}

.status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  animation: pulse-dot 2s ease-in-out infinite;
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 28px 24px 48px;
}

/* ── Typography & utilities ── */
h2, h3 { color: var(--fg); letter-spacing: -0.02em; }

.muted { color: var(--muted); }
.ml-auto { margin-left: auto; }
.mb-sm { margin-bottom: 12px; }
.mb-md { margin-bottom: 16px; }
.mb-lg { margin-bottom: 20px; }
.mt-sm { margin-top: 8px; }
.mt-md { margin-top: 12px; }

.page-header {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 20px;
  padding-bottom: 0;
  border-bottom: none;
}

.page-header h2 {
  margin: 0;
  font-size: 20px;
  font-weight: 600;
}

.page-header .stats {
  font-size: 13px;
  color: var(--muted);
}

.row {
  display: flex;
  gap: var(--ctrl-gap);
  align-items: center;
  flex-wrap: wrap;
}

/* ── Dashboard hero (homepage) ── */
.dash-hero {
  margin-bottom: 24px;
  padding: 28px 28px 0;
  background: linear-gradient(145deg, #0b1220 0%, #0f172a 35%, #134e4a 100%);
  border-radius: var(--radius-lg);
  color: #f1f5f9;
  box-shadow: var(--shadow-lg);
  position: relative;
  overflow: hidden;
}

.dash-hero::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse 70% 60% at 90% 10%, rgba(13, 148, 136, 0.22), transparent 55%),
    radial-gradient(ellipse 50% 50% at 10% 90%, rgba(2, 132, 199, 0.12), transparent 50%),
    linear-gradient(rgba(255,255,255,0.02) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,0.02) 1px, transparent 1px);
  background-size: auto, auto, 24px 24px, 24px 24px;
  pointer-events: none;
}

.dash-hero-grid {
  display: grid;
  grid-template-columns: 1fr 1.1fr;
  gap: 28px;
  align-items: center;
  position: relative;
  z-index: 1;
  padding-bottom: 24px;
}

.dash-hero-copy { max-width: 520px; }

.dash-hero-copy .hero-title {
  font-size: 32px;
  margin-bottom: 12px;
}

.dash-hero-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 20px;
}

.dash-status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0 12px;
  height: var(--ctrl-h-sm);
  border-radius: 999px;
  font-size: var(--ctrl-fs-sm);
  font-weight: 600;
  border: 1px solid transparent;
}

.dash-status-pill.ok {
  background: rgba(5, 150, 105, 0.15);
  color: #6ee7b7;
  border-color: rgba(5, 150, 105, 0.3);
}

.dash-status-pill.err {
  background: rgba(220, 38, 38, 0.15);
  color: #fca5a5;
  border-color: rgba(220, 38, 38, 0.3);
}

/* Pipeline visualization */
.dash-flow-viz {
  padding: 18px 20px;
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius-lg);
  backdrop-filter: blur(12px);
}

.df-title {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: #64748b;
  margin-bottom: 16px;
}

.df-track {
  display: flex;
  align-items: center;
  gap: 0;
  overflow-x: auto;
  padding-bottom: 4px;
}

.df-node {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  min-width: 68px;
  text-align: center;
}

.df-icon {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 700;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.06);
}

.df-n-upload .df-icon { background: rgba(2, 132, 199, 0.2); color: #7dd3fc; border-color: rgba(2, 132, 199, 0.35); }
.df-n-etl .df-icon { background: rgba(124, 58, 237, 0.2); color: #c4b5fd; border-color: rgba(124, 58, 237, 0.35); }
.df-n-store .df-icon { background: rgba(13, 148, 136, 0.2); color: #5eead4; border-color: rgba(13, 148, 136, 0.35); }
.df-n-group .df-icon { background: rgba(217, 119, 6, 0.2); color: #fcd34d; border-color: rgba(217, 119, 6, 0.35); }
.df-n-submit .df-icon { background: rgba(5, 150, 105, 0.2); color: #6ee7b7; border-color: rgba(5, 150, 105, 0.35); }

.df-label {
  font-size: 11px;
  font-weight: 700;
  color: #e2e8f0;
  letter-spacing: -0.01em;
}

.df-sub {
  font-size: 9px;
  color: #64748b;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.df-link {
  flex: 1;
  min-width: 20px;
  max-width: 36px;
  height: 2px;
  background: rgba(255, 255, 255, 0.12);
  position: relative;
  margin: 0 2px;
  margin-bottom: 28px;
}

.df-pulse {
  position: absolute;
  top: -3px;
  left: 0;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #5eead4;
  box-shadow: 0 0 8px rgba(94, 234, 212, 0.6);
  animation: df-flow 2.4s ease-in-out infinite;
}

.df-pulse-d2 { animation-delay: 0.5s; background: #c4b5fd; box-shadow: 0 0 8px rgba(196, 181, 253, 0.6); }
.df-pulse-d3 { animation-delay: 1.0s; }
.df-pulse-d4 { animation-delay: 1.5s; background: #6ee7b7; box-shadow: 0 0 8px rgba(110, 231, 183, 0.6); }

@keyframes df-flow {
  0% { left: 0; opacity: 0; }
  10% { opacity: 1; }
  90% { opacity: 1; }
  100% { left: calc(100% - 8px); opacity: 0; }
}

.df-live {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  font-size: 12px;
  font-weight: 500;
  color: #5eead4;
}

.df-live-idle { color: #64748b; }

/* Metrics strip */
.dash-metrics {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 1px;
  background: rgba(255, 255, 255, 0.08);
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
  overflow: hidden;
  position: relative;
  z-index: 1;
}

.dash-metric {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 16px 10px;
  background: rgba(15, 23, 42, 0.6);
  text-align: center;
}

.dash-metric-val {
  font-size: 22px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: #fff;
  line-height: 1;
}

.dash-metric-lbl {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #64748b;
}

.dash-metric-accent .dash-metric-val {
  color: #5eead4;
}

/* Compact dashboard hero */
.dash-hero-compact {
  padding: 20px 22px;
  margin-bottom: 20px;
}

.dash-hero-compact::before {
  background-size: auto, auto, 20px 20px, 20px 20px;
}

.dash-hero-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  position: relative;
  z-index: 1;
  margin-bottom: 14px;
}

.dash-hero-compact .hero-title {
  font-size: 22px;
  margin: 0 0 4px;
  line-height: 1.2;
}

.dash-hero-compact .hero-desc {
  margin: 0;
  font-size: 13px;
  color: #94a3b8;
  line-height: 1.4;
}

.dash-hero-compact .dash-hero-actions {
  margin-top: 0;
  flex-shrink: 0;
}

.dash-live-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0 10px;
  height: var(--ctrl-h-sm);
  border-radius: 999px;
  font-size: var(--ctrl-fs-sm);
  font-weight: 600;
  background: rgba(5, 150, 105, 0.15);
  color: #6ee7b7;
  border: 1px solid rgba(5, 150, 105, 0.3);
}

.dash-live-pill.idle {
  background: rgba(255, 255, 255, 0.06);
  color: #64748b;
  border-color: rgba(255, 255, 255, 0.1);
}

.dash-pipeline-inline {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  position: relative;
  z-index: 1;
  margin-bottom: 14px;
  padding: 8px 12px;
  background: rgba(0, 0, 0, 0.2);
  border: 1px solid rgba(255, 255, 255, 0.07);
  border-radius: var(--radius);
}

.dpi-step {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.02em;
  padding: 3px 8px;
  border-radius: 4px;
  border: 1px solid transparent;
}

.dpi-upload { color: #7dd3fc; background: rgba(2, 132, 199, 0.15); border-color: rgba(2, 132, 199, 0.25); }
.dpi-etl { color: #c4b5fd; background: rgba(124, 58, 237, 0.15); border-color: rgba(124, 58, 237, 0.25); }
.dpi-group { color: #fcd34d; background: rgba(217, 119, 6, 0.15); border-color: rgba(217, 119, 6, 0.25); }
.dpi-submit { color: #6ee7b7; background: rgba(5, 150, 105, 0.15); border-color: rgba(5, 150, 105, 0.25); }

.dpi-arrow {
  font-size: 10px;
  color: #475569;
  user-select: none;
}

.dash-stats-row {
  display: flex;
  flex-wrap: wrap;
  gap: 1px;
  position: relative;
  z-index: 1;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius);
  overflow: hidden;
}

.dash-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  flex: 1 1 72px;
  min-width: 64px;
  padding: 10px 8px;
  background: rgba(15, 23, 42, 0.55);
  text-align: center;
}

.dash-stat-divider {
  flex: 0 0 1px;
  min-width: 1px;
  padding: 0;
  background: rgba(255, 255, 255, 0.12);
  align-self: stretch;
}

.dash-stat-val {
  font-size: 18px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: #fff;
  line-height: 1;
}

.dash-stat-lbl {
  font-size: 9.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #64748b;
}

.dash-stat-active { color: #5eead4; }
.dash-stat-warn { color: #fcd34d; }
.dash-stat-accent { color: #5eead4; }

/* Dashboard panels row */
.dash-panels {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 28px;
}

.dash-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  box-shadow: var(--shadow-sm);
}

.dash-panel-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.dash-panel-head h2 {
  margin: 0;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.dash-panel-sub {
  font-size: 11px;
  color: var(--muted);
  font-weight: 500;
}

.ops-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-bottom: 16px;
}

.ops-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 12px 8px;
  background: var(--panel2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.ops-val {
  font-size: 20px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--fg);
  line-height: 1;
}

.ops-val-active { color: var(--accent); }
.ops-val-warn { color: var(--warn); }

.ops-lbl {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.ops-stack {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.ops-layer {
  display: grid;
  grid-template-columns: 10px 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  background: var(--panel2);
  border-radius: var(--radius);
  border: 1px solid var(--line);
}

.ops-layer-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.ops-dot-upload { background: var(--stage-upload); box-shadow: 0 0 6px rgba(2, 132, 199, 0.4); }
.ops-dot-etl { background: var(--stage-etl); box-shadow: 0 0 6px rgba(124, 58, 237, 0.4); }
.ops-dot-store { background: var(--accent); box-shadow: 0 0 6px var(--accent-glow); }
.ops-dot-submit { background: var(--stage-submit); box-shadow: 0 0 6px rgba(5, 150, 105, 0.4); }

.ops-layer-name {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--fg-secondary);
}

.ops-layer-desc {
  font-size: 10.5px;
  color: var(--muted);
  font-family: "JetBrains Mono", ui-monospace, monospace;
}

.stage-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.stage-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 10px 12px;
  background: var(--panel2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  transition: border-color 0.15s;
}

.stage-item:hover {
  border-color: var(--line-strong);
}

.stage-num {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 700;
}

.stage-num-upload { background: var(--stage-upload-soft); color: var(--stage-upload); }
.stage-num-etl { background: var(--stage-etl-soft); color: var(--stage-etl); }
.stage-num-group { background: var(--stage-group-soft); color: var(--stage-group); }
.stage-num-submit { background: var(--stage-submit-soft); color: var(--stage-submit); }

.stage-body {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.stage-body strong {
  font-size: 13px;
  font-weight: 600;
  color: var(--fg);
}

.stage-body span {
  font-size: 11.5px;
  color: var(--muted);
  line-height: 1.4;
}

.dash-scopes-head {
  margin-bottom: 12px;
}

.dash-scopes-head h2 {
  margin: 0 0 2px;
  font-size: 16px;
}

/* Compact scope cards (homepage) */
.scope-card-compact {
  padding: 0;
  overflow: hidden;
  transition: box-shadow 0.15s, border-color 0.15s;
}

.scope-card-compact:hover {
  border-color: var(--line-strong);
  box-shadow: var(--shadow-md);
}

.scope-card-link {
  display: block;
  color: inherit;
  text-decoration: none;
}

.scope-card-link:hover {
  color: inherit;
  text-decoration: none;
}

.scope-card-compact .scope-card-accent {
  height: 3px;
}

.scope-card-compact .scope-card-body {
  padding: 12px 14px;
}

.scc-head {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 10px;
  align-items: center;
}

.scope-card-compact .scope-cat-icon {
  width: 32px;
  height: 32px;
  font-size: 11px;
  border-radius: 7px;
}

.scc-title {
  min-width: 0;
}

.scc-title h3 {
  margin: 0;
  font-size: 14px;
  font-weight: 700;
  line-height: 1.25;
  letter-spacing: -0.02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.scc-slug {
  display: block;
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: 10px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 1px;
}

.scc-arrow {
  font-size: 14px;
  color: var(--muted);
  opacity: 0.5;
  transition: opacity 0.15s, transform 0.15s;
}

.scope-card-compact:hover .scc-arrow {
  opacity: 1;
  color: var(--accent);
  transform: translateX(2px);
}

.scc-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 8px;
}

.scc-tag {
  font-size: 10px;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 4px;
  background: var(--panel2);
  color: var(--fg-secondary);
  border: 1px solid var(--line);
  line-height: 1.4;
}

.scc-tag-nx {
  background: var(--stage-submit-soft);
  color: var(--stage-submit);
  border-color: rgba(5, 150, 105, 0.2);
}

.scc-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 8px;
}

.scc-chip {
  font-size: 10.5px;
  color: var(--muted);
  padding: 2px 7px;
  border-radius: 4px;
  background: var(--panel2);
  border: 1px solid var(--line);
  line-height: 1.35;
}

.scc-chip b {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  color: var(--fg);
}

.scc-chip-warn b { color: var(--warn); }
.scc-chip-active b { color: var(--accent); }
.scc-chip-ok b { color: var(--ok); }
.scc-chip-err b { color: var(--err); }

.scc-pipe {
  display: flex;
  align-items: center;
  gap: 0;
  margin-top: 8px;
}

.scc-pipe-sep {
  flex: 1;
  height: 2px;
  min-width: 6px;
  max-width: 14px;
  background: var(--line);
  margin: 0 2px;
}

.scc-step {
  flex-shrink: 0;
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: 0.02em;
  padding: 2px 6px;
  border-radius: 4px;
  border: 1px solid var(--line);
  background: var(--panel2);
  color: var(--muted);
  line-height: 1.3;
}

.scc-step-done {
  background: var(--ok-soft);
  color: var(--ok);
  border-color: rgba(5, 150, 105, 0.25);
}

.scc-step-active {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: rgba(13, 148, 136, 0.3);
  box-shadow: 0 0 0 2px var(--accent-glow);
}

.scc-step-pending {
  background: var(--panel2);
  color: var(--muted);
  border-style: dashed;
}

.scc-step-failed {
  background: var(--err-soft);
  color: var(--err);
  border-color: rgba(220, 38, 38, 0.25);
}

.scc-step-idle {
  opacity: 0.45;
}

.scc-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--line);
  min-height: 22px;
}

.scc-status {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 10.5px;
  font-weight: 600;
  min-width: 0;
  flex-shrink: 0;
}

.scc-status-run {
  color: var(--accent);
}

.scc-status-run .spinner {
  width: 10px;
  height: 10px;
}

.scc-status-stage {
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.scc-status-idle {
  color: var(--muted);
  font-weight: 500;
}

.scc-latest {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  margin-left: auto;
  font-size: 10px;
  color: var(--muted);
}

.scc-file {
  font-family: "JetBrains Mono", ui-monospace, monospace;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 120px;
}

.scc-size {
  flex-shrink: 0;
  opacity: 0.85;
}

.scc-dt {
  flex-shrink: 0;
  opacity: 0.75;
  font-variant-numeric: tabular-nums;
}

.pill.sm {
  padding: 1px 8px;
  font-size: 10.5px;
  gap: 3px;
}

.pill.sm .spinner {
  width: 10px;
  height: 10px;
}

/* Rich scope cards */
.scope-grid {
  gap: 14px;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
}

.scope-card-rich {
  display: flex;
  flex-direction: column;
  padding: 0;
}

.scope-card-rich .scope-card-accent {
  height: 4px;
}

.scope-card-top {
  display: flex;
  gap: 14px;
  padding: 18px 20px 0;
}

.scope-cat-icon {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: -0.02em;
  background: linear-gradient(135deg, var(--stage-upload-soft), var(--accent-soft));
  color: var(--accent);
  border: 1px solid rgba(13, 148, 136, 0.2);
  flex-shrink: 0;
}

.scope-card[data-category^="1"] .scope-cat-icon {
  background: linear-gradient(135deg, var(--stage-upload-soft), rgba(2, 132, 199, 0.08));
  color: var(--stage-upload);
  border-color: rgba(2, 132, 199, 0.2);
}

.scope-card[data-category^="2"] .scope-cat-icon {
  background: linear-gradient(135deg, var(--stage-etl-soft), rgba(124, 58, 237, 0.08));
  color: var(--stage-etl);
  border-color: rgba(124, 58, 237, 0.2);
}

.scope-card[data-category^="3"] .scope-cat-icon {
  background: linear-gradient(135deg, var(--stage-group-soft), rgba(217, 119, 6, 0.08));
  color: var(--stage-group);
  border-color: rgba(217, 119, 6, 0.2);
}

.scope-cat-icon-alt {
  background: var(--panel2) !important;
  color: var(--muted) !important;
  border-color: var(--line) !important;
}

.scope-card-head h3 {
  font-size: 16px;
  margin-bottom: 6px;
}

.scope-card-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.scope-card-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1px;
  margin: 14px 20px 0;
  background: var(--line);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}

.scs-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 10px 8px;
  background: var(--panel2);
}

.scs-val {
  font-size: 18px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--fg);
  line-height: 1;
}

.scs-val.scs-warn { color: var(--warn); }
.scs-val.scs-active { color: var(--accent); }

.scs-lbl {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.scope-card-status {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  padding: 12px 20px 0;
  min-height: 36px;
}

.scope-last-run { margin: 0; }

.scope-mini-pipeline {
  display: flex;
  align-items: center;
  gap: 0;
  padding: 14px 20px 0;
}

.smp {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
  opacity: 0.35;
  border: 2px solid var(--line-strong);
  background: var(--panel2);
}

.smp-line {
  flex: 1;
  height: 2px;
  background: var(--line);
  max-width: 24px;
}

.smp-upload { border-color: var(--stage-upload); }
.smp-etl { border-color: var(--stage-etl); }
.smp-group { border-color: var(--stage-group); }
.smp-submit { border-color: var(--stage-submit); }

.scope-card-rich:hover .smp {
  opacity: 0.7;
}

.scope-card-rich:hover .smp-upload { background: var(--stage-upload-soft); opacity: 1; }
.scope-card-rich:hover .smp-etl { background: var(--stage-etl-soft); opacity: 1; }
.scope-card-rich:hover .smp-group { background: var(--stage-group-soft); opacity: 1; }
.scope-card-rich:hover .smp-submit { background: var(--stage-submit-soft); opacity: 1; }

.scope-card-rich .card-footer {
  margin-top: auto;
  padding: 14px 20px 18px;
  border-top: 1px solid var(--line);
}

.btn-block {
  display: flex;
  width: 100%;
}

/* Legacy hero (detail/other pages if used) */
.hero {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 28px;
  align-items: center;
  margin-bottom: 28px;
  padding: 28px 32px;
  background: linear-gradient(135deg, #0f172a 0%, #1e293b 60%, #134e4a 100%);
  border-radius: var(--radius-lg);
  color: #f1f5f9;
  box-shadow: var(--shadow-lg);
  position: relative;
  overflow: hidden;
}

.hero::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at 80% 20%, rgba(13, 148, 136, 0.25), transparent 50%),
    radial-gradient(circle at 20% 80%, rgba(2, 132, 199, 0.15), transparent 40%);
  pointer-events: none;
}

.hero-content { position: relative; z-index: 1; }

.hero-badge {
  display: inline-block;
  padding: 4px 10px;
  margin-bottom: 12px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #5eead4;
  background: rgba(13, 148, 136, 0.2);
  border: 1px solid rgba(94, 234, 212, 0.25);
  border-radius: 999px;
}

.hero-title {
  margin: 0 0 10px;
  font-size: 26px;
  font-weight: 700;
  line-height: 1.25;
  letter-spacing: -0.03em;
  color: #fff;
}

.hero-accent {
  background: linear-gradient(90deg, #5eead4, #38bdf8);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.hero-desc {
  margin: 0;
  font-size: 14px;
  line-height: 1.6;
  color: #94a3b8;
  max-width: 480px;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  position: relative;
  z-index: 1;
  min-width: 280px;
}

.stat-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: var(--radius);
  backdrop-filter: blur(8px);
  transition: background 0.15s, transform 0.15s;
}

.stat-card:hover {
  background: rgba(255, 255, 255, 0.11);
  transform: translateY(-1px);
}

.stat-icon {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 700;
  flex-shrink: 0;
}

.stat-uploads .stat-icon { background: var(--stage-upload-soft); color: #38bdf8; }
.stat-etl .stat-icon { background: var(--stage-etl-soft); color: #a78bfa; }
.stat-group .stat-icon { background: var(--stage-group-soft); color: #fbbf24; }
.stat-submit .stat-icon { background: var(--stage-submit-soft); color: #34d399; }

.stat-body { display: flex; flex-direction: column; gap: 1px; }

.stat-value {
  font-size: 22px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: #fff;
  line-height: 1;
}

.stat-label {
  font-size: 11px;
  font-weight: 500;
  color: #94a3b8;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* ── Pipeline legend ── */
.pipeline-legend {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 24px;
  padding: 10px 16px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}

.pipeline-legend-inline {
  margin: 14px 0 0;
  justify-content: flex-start;
  background: rgba(255, 255, 255, 0.06);
  border-color: rgba(255, 255, 255, 0.1);
}

.pl-item {
  display: inline-flex;
  align-items: center;
  padding: 4px 12px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.pl-upload { background: var(--stage-upload-soft); color: var(--stage-upload); border: 1px solid rgba(2, 132, 199, 0.25); }
.pl-etl { background: var(--stage-etl-soft); color: var(--stage-etl); border: 1px solid rgba(124, 58, 237, 0.25); }
.pl-group { background: var(--stage-group-soft); color: var(--stage-group); border: 1px solid rgba(217, 119, 6, 0.25); }
.pl-submit { background: var(--stage-submit-soft); color: var(--stage-submit); border: 1px solid rgba(5, 150, 105, 0.25); }

.pl-arrow {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.pipeline-legend-inline .pl-arrow { color: rgba(255, 255, 255, 0.35); }
.pipeline-legend-inline .pl-upload { background: rgba(2, 132, 199, 0.2); color: #7dd3fc; border-color: rgba(2, 132, 199, 0.3); }
.pipeline-legend-inline .pl-etl { background: rgba(124, 58, 237, 0.2); color: #c4b5fd; border-color: rgba(124, 58, 237, 0.3); }
.pipeline-legend-inline .pl-group { background: rgba(217, 119, 6, 0.2); color: #fcd34d; border-color: rgba(217, 119, 6, 0.3); }
.pipeline-legend-inline .pl-submit { background: rgba(5, 150, 105, 0.2); color: #6ee7b7; border-color: rgba(5, 150, 105, 0.3); }

/* ── Scope banner (detail page) ── */
.scope-banner {
  margin-bottom: 24px;
  padding: 22px 26px;
  background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
  border-radius: var(--radius-lg);
  color: #f1f5f9;
  box-shadow: var(--shadow-md);
  position: relative;
  overflow: hidden;
}

.scope-banner::after {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  width: 4px;
  height: 100%;
  background: linear-gradient(180deg, var(--stage-upload), var(--stage-etl), var(--stage-group), var(--stage-submit));
}

.scope-banner-inner {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.scope-banner-title {
  margin: 0 0 8px;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: #fff;
}

.scope-banner-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.scope-banner .tag {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.12);
  color: #cbd5e1;
}

.scope-back {
  background: rgba(255, 255, 255, 0.08) !important;
  border-color: rgba(255, 255, 255, 0.15) !important;
  color: #e2e8f0 !important;
}

.scope-back:hover {
  background: rgba(255, 255, 255, 0.14) !important;
  color: #fff !important;
}

@media (max-width: 960px) {
  .dash-hero-grid {
    grid-template-columns: 1fr;
  }

  .dash-metrics {
    grid-template-columns: repeat(3, 1fr);
  }

  .dash-panels {
    grid-template-columns: 1fr;
  }

  .scope-card-compact .scc-foot {
    flex-wrap: wrap;
  }

  .scope-card-compact .scc-latest {
    width: 100%;
    margin-left: 0;
    margin-top: 2px;
  }
}

@media (max-width: 768px) {
  .dash-hero {
    padding: 22px 18px 0;
  }

  .dash-hero-compact {
    padding: 16px;
  }

  .dash-hero-top {
    flex-direction: column;
    align-items: stretch;
  }

  .dash-hero-compact .hero-title {
    font-size: 20px;
  }

  .dash-hero-compact .dash-hero-actions {
    justify-content: space-between;
  }

  .dash-stat-divider {
    display: none;
  }

  .dash-hero-copy .hero-title {
    font-size: 24px;
  }

  .dash-metrics {
    grid-template-columns: repeat(2, 1fr);
  }

  .ops-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .hero {
    grid-template-columns: 1fr;
    padding: 22px 20px;
  }
  .stats-grid { min-width: 0; }
  .hero-title { font-size: 22px; }
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 16px;
}

/* ── Cards & panels ── */
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  box-shadow: var(--shadow-sm);
  transition: border-color 0.15s, box-shadow 0.15s, transform 0.15s;
  position: relative;
  overflow: hidden;
}

.scope-card {
  padding-top: 22px;
}

.scope-card-accent {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--stage-upload), var(--stage-etl), var(--stage-group), var(--stage-submit));
}

.scope-card[data-category^="1"] .scope-card-accent {
  background: linear-gradient(90deg, #0284c7, #0d9488);
}

.scope-card[data-category^="2"] .scope-card-accent {
  background: linear-gradient(90deg, #7c3aed, #db2777);
}

.scope-card[data-category^="3"] .scope-card-accent {
  background: linear-gradient(90deg, #d97706, #ea580c);
}

.card:hover {
  border-color: var(--accent-glow);
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}

.card h3 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
}

.card .meta {
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 12px;
  line-height: 1.5;
}

.card-footer {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 20px 22px;
  margin-bottom: 20px;
  box-shadow: var(--shadow-sm);
  border-left: 3px solid var(--line-strong);
}

.panel-step-upload { border-left-color: var(--stage-upload); }
.panel-step-manage { border-left-color: var(--stage-etl); }

.panel h2 {
  font-size: 14px;
  font-weight: 600;
  margin: 0 0 4px;
  color: var(--fg);
  text-transform: none;
  letter-spacing: -0.01em;
}

.panel-desc {
  margin: 0 0 16px;
  font-size: 13px;
  color: var(--muted);
  line-height: 1.5;
}

.panel-header {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 4px;
}

.panel-header h2 { margin: 0; }

.step-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--bg-subtle);
  color: var(--fg-secondary);
  font-size: 11px;
  font-weight: 700;
  margin-right: 4px;
  vertical-align: middle;
}

.step-upload { background: var(--stage-upload-soft); color: var(--stage-upload); }
.step-manage { background: var(--stage-etl-soft); color: var(--stage-etl); }

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: var(--ctrl-h);
  min-height: var(--ctrl-h);
  padding: 0 14px;
  background: linear-gradient(135deg, var(--accent) 0%, #0891b2 100%);
  color: #fff;
  border: 1px solid transparent;
  border-radius: var(--ctrl-radius);
  cursor: pointer;
  font: inherit;
  font-size: var(--ctrl-fs);
  font-weight: 600;
  line-height: 1;
  white-space: nowrap;
  transition: background 0.15s, border-color 0.15s, box-shadow 0.15s, transform 0.1s;
  box-shadow: 0 2px 8px var(--accent-glow);
  vertical-align: middle;
}

.btn:hover {
  background: linear-gradient(135deg, var(--accent-hover) 0%, #0e7490 100%);
  text-decoration: none;
  color: #fff;
  transform: translateY(-1px);
  box-shadow: 0 4px 12px var(--accent-glow);
}
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.btn.ghost {
  background: var(--panel);
  color: var(--fg-secondary);
  border-color: var(--line-strong);
  box-shadow: var(--shadow-sm);
}

.btn.ghost:hover {
  background: var(--panel2);
  color: var(--fg);
  border-color: var(--muted);
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-sm {
  height: var(--ctrl-h-sm);
  min-height: var(--ctrl-h-sm);
  padding: 0 12px;
  font-size: var(--ctrl-fs-sm);
}

/* ── Status pills ── */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
  border: 1px solid transparent;
  white-space: nowrap;
}

.pill.ok { background: var(--ok-soft); color: var(--ok); border-color: rgba(5, 150, 105, 0.25); }
.pill.warn { background: var(--warn-soft); color: var(--warn); border-color: rgba(217, 119, 6, 0.25); }
.pill.err { background: var(--err-soft); color: var(--err); border-color: rgba(220, 38, 38, 0.25); }
.pill.skip { background: var(--stage-etl-soft); color: var(--stage-etl); border-color: rgba(124, 58, 237, 0.25); }
.pill.run { background: var(--accent-soft); color: var(--accent); border-color: rgba(13, 148, 136, 0.25); }
.pill.idle { background: var(--panel2); color: var(--muted); border-color: var(--line); }

.tag {
  font-family: "JetBrains Mono", ui-monospace, "Cascadia Code", "Consolas", monospace;
  font-size: 11px;
  color: var(--fg-secondary);
  background: var(--panel2);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 1px 6px;
}

.tag-cat {
  background: var(--stage-etl-soft);
  border-color: rgba(124, 58, 237, 0.2);
  color: var(--stage-etl);
  font-weight: 500;
}

.flash-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 12px;
  padding: 10px 14px;
  background: var(--panel2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font-size: 13px;
}

/* ── Tables ── */
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
}

th, td {
  text-align: left;
  padding: 9px 12px;
  border-bottom: 1px solid var(--line);
}

th {
  color: var(--muted);
  font-weight: 600;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  position: sticky;
  top: 0;
  background: var(--panel2);
  z-index: 1;
}

tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: var(--accent-soft); }
tr.row-selected td { background: rgba(13, 148, 136, 0.1) !important; }
tr.row-eam-skipped td { opacity: 0.55; }
tr.row-eam-skipped td.col-eam-reason,
tr.row-eam-skipped td.col-status { opacity: 1; }

.tablewrap {
  overflow: auto;
  max-height: 540px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
}

td.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

code.j {
  font-family: ui-monospace, "Cascadia Code", "Consolas", monospace;
  font-size: 11.5px;
  color: var(--fg-secondary);
  white-space: nowrap;
}

.reason { max-width: 320px; vertical-align: top; }
.reason-list { margin: 0; padding-left: 1.1em; font-size: 12px; line-height: 1.45; }
.reason-list li { margin: 0 0 3px; }
.reason-list-compact { font-size: 11px; max-width: 220px; }
.records-phase-hint {
  margin: 0 0 12px;
  padding: 8px 12px;
  font-size: 12px;
  line-height: 1.45;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
}
.reason-codes { display: block; margin-top: 4px; font-size: 10px; opacity: 0.8; }

/* ── Tabs & forms ── */
.tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.tabs .btn.ghost {
  height: var(--ctrl-h-sm);
  min-height: var(--ctrl-h-sm);
  padding: 0 12px;
  font-size: var(--ctrl-fs-sm);
  font-weight: 500;
}

.tabs .btn.ghost.active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 600;
}

.drop:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.drop {
  border: 1.5px dashed var(--line-strong);
  border-radius: var(--radius);
  padding: 18px 20px;
  background: linear-gradient(135deg, var(--panel2) 0%, rgba(13, 148, 136, 0.04) 100%);
  transition: border-color 0.15s, background 0.15s;
}

.drop input[type="file"] {
  font-size: 13px;
  color: var(--fg-secondary);
  max-width: 100%;
}

.drop input[type="file"]::file-selector-button {
  display: inline-flex;
  align-items: center;
  height: var(--ctrl-h);
  padding: 0 var(--ctrl-px);
  margin-right: 10px;
  background: var(--panel);
  border: 1px solid var(--line-strong);
  border-radius: var(--ctrl-radius);
  font: inherit;
  font-size: var(--ctrl-fs);
  font-weight: 500;
  color: var(--fg-secondary);
  cursor: pointer;
  vertical-align: middle;
}

.drop input[type="file"]::file-selector-button:hover {
  background: var(--bg-subtle);
}

.log {
  background: #0f172a;
  border: 1px solid #1e293b;
  border-radius: var(--radius);
  padding: 12px 14px;
  font-family: "JetBrains Mono", ui-monospace, "Cascadia Code", "Consolas", monospace;
  font-size: 11.5px;
  color: #94a3b8;
  max-height: 180px;
  overflow: auto;
  white-space: pre-wrap;
  line-height: 1.5;
  scroll-behavior: auto;
}

.results-root .log-live {
  max-height: min(420px, 50vh);
  min-height: 160px;
}

.spinner {
  display: inline-block;
  width: 11px;
  height: 11px;
  border: 2px solid var(--line-strong);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  vertical-align: -1px;
}

@keyframes spin { to { transform: rotate(360deg); } }

.htmx-indicator { opacity: 0; transition: opacity 0.15s; }
.htmx-request .htmx-indicator { opacity: 1; }

/* ── Pipeline stepper ── */
.pipeline {
  display: flex;
  align-items: stretch;
  gap: 0;
  flex-wrap: wrap;
  padding: 14px;
  background: linear-gradient(180deg, var(--panel2) 0%, var(--panel) 100%);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  margin-bottom: 6px;
}

.pipe-step {
  flex: 1;
  min-width: 120px;
  padding: 10px 14px;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: var(--panel);
}

.pipe-step.done {
  border-color: rgba(5, 150, 105, 0.35);
  background: var(--stage-submit-soft);
}

.pipe-step.active {
  border-color: rgba(13, 148, 136, 0.45);
  background: var(--accent-soft);
  box-shadow: 0 0 0 3px rgba(13, 148, 136, 0.08);
}

.pipe-step.pending { opacity: 0.55; }

.pipe-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--line-strong);
  font-size: 11px;
  font-weight: 700;
  margin-right: 5px;
  color: var(--fg-secondary);
}

.pipe-step.done .pipe-num { background: var(--stage-submit); color: #fff; }
.pipe-step.active .pipe-num { background: var(--accent); color: #fff; }

.pipe-sub {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 6px;
  min-height: 22px;
  line-height: 1.3;
}

.pipe-sub-file {
  display: block;
  max-width: 100%;
  padding: 3px 8px;
  font-family: ui-monospace, "Cascadia Code", "Consolas", monospace;
  font-size: 10.5px;
  font-weight: 500;
  color: var(--fg-secondary);
  background: var(--panel2);
  border: 1px solid var(--line);
  border-radius: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.pipe-sub-wait {
  font-size: 10.5px;
  font-weight: 500;
  color: var(--muted);
  letter-spacing: 0.02em;
}

.pipe-sub-wait::before {
  content: "—";
  margin-right: 4px;
  opacity: 0.5;
}

.pipe-sub-run {
  gap: 5px;
  padding: 2px 10px;
  font-size: 11px;
  font-weight: 500;
  color: var(--accent);
  background: var(--accent-soft);
  border: 1px solid rgba(13, 148, 136, 0.2);
  border-radius: 999px;
}

.pipe-step.done .pipe-sub-run {
  color: var(--stage-submit);
  background: var(--stage-submit-soft);
  border-color: rgba(5, 150, 105, 0.2);
}

.ps-chip {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 10.5px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  background: var(--panel2);
  border: 1px solid var(--line);
  color: var(--fg-secondary);
  line-height: 1.35;
}

.ps-chip.ok {
  background: var(--ok-soft);
  border-color: rgba(26, 127, 55, 0.28);
  color: var(--ok);
}

.ps-chip.warn {
  background: var(--warn-soft);
  border-color: rgba(154, 103, 0, 0.28);
  color: var(--warn);
}

.ps-chip.err {
  background: var(--err-soft);
  border-color: rgba(207, 34, 46, 0.28);
  color: var(--err);
}

.ps-metric {
  font-size: 14px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--fg);
  line-height: 1;
}

.ps-unit {
  font-size: 10.5px;
  font-weight: 500;
  color: var(--muted);
  margin-left: 1px;
}

.pipe-step.pending .pipe-sub-wait {
  opacity: 0.75;
}

.pipe-step.active .pipe-label {
  color: var(--accent);
}

.pipe-step.done .pipe-label {
  color: var(--stage-submit);
}

.pipe-arrow {
  align-self: center;
  color: var(--line-strong);
  padding: 0 6px;
  font-size: 14px;
}

.flow-running { padding: 8px 0; }

.clickable-row { cursor: pointer; }

/* ── Upload table pipeline steps ── */
.col-pipeline { white-space: nowrap; }

.row-steps {
  display: inline-flex;
  align-items: center;
  gap: 0;
}

.rs {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 3px;
  min-width: 30px;
  padding: 2px 7px;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.02em;
  border: 1px solid var(--line);
  background: var(--panel2);
  color: var(--muted);
  line-height: 1.35;
}

.rs-done {
  background: var(--stage-submit-soft);
  border-color: rgba(5, 150, 105, 0.3);
  color: var(--stage-submit);
}

.rs-active {
  background: var(--accent-soft);
  border-color: rgba(13, 148, 136, 0.35);
  color: var(--accent);
}

.rs-pending {
  opacity: 0.5;
  border-style: dashed;
}

.rs-failed {
  background: var(--err-soft);
  border-color: rgba(207, 34, 46, 0.3);
  color: var(--err);
}

.rs-sep {
  display: inline-block;
  width: 8px;
  height: 1px;
  background: var(--line-strong);
  flex-shrink: 0;
}

.rs-spin {
  width: 8px;
  height: 8px;
  border-width: 1.5px;
}

/* ── Modal ── */
.modal {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 1000;
  padding: 16px;
}

.modal.open {
  display: flex;
  align-items: center;
  justify-content: center;
  animation: modal-fade 0.14s ease;
}

.modal.open .modal-dialog {
  animation: modal-pop 0.18s cubic-bezier(0.2, 0.8, 0.2, 1);
}

@keyframes modal-fade {
  from { opacity: 0; }
}

@keyframes modal-pop {
  from { opacity: 0; transform: translateY(10px) scale(0.985); }
}

@media (prefers-reduced-motion: reduce) {
  .modal.open,
  .modal.open .modal-dialog {
    animation: none;
  }
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(28, 36, 48, 0.45);
  backdrop-filter: blur(3px);
}

.modal-dialog {
  position: relative;
  z-index: 1;
  width: min(1100px, 100%);
  max-height: calc(100vh - 32px);
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
}

.modal-dialog-lg {
  width: min(1180px, 100%);
  max-height: calc(100vh - 24px);
}

.modal-header {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
  background: var(--panel2);
  border-radius: 12px 12px 0 0;
}

.modal-title-group {
  flex: 1;
  min-width: 0;
}

.modal-header h2 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.modal-sub {
  margin: 4px 0 0;
  font-size: 12px;
  font-family: ui-monospace, "Cascadia Code", "Consolas", monospace;
}

.modal-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.modal-close {
  width: var(--ctrl-h-sm);
  height: var(--ctrl-h-sm);
  min-height: var(--ctrl-h-sm);
  padding: 0;
  font-size: 16px;
  line-height: 1;
  flex-shrink: 0;
}

.modal-body {
  overflow: auto;
  flex: 1;
  min-height: 0;
  padding: 0;
  background: var(--panel);
  border-radius: 0 0 12px 12px;
  overscroll-behavior: contain;
}

.results-root {
  padding: 0;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.results-root[data-empty] {
  padding: 16px 20px;
}

.results-placeholder {
  text-align: center;
  padding: 48px 24px;
  color: var(--muted);
}

.results-placeholder-icon {
  width: 48px;
  height: 48px;
  margin: 0 auto 14px;
  border-radius: 10px;
  background: var(--bg-subtle);
  border: 1px solid var(--line);
  position: relative;
}

.results-placeholder-icon::before {
  content: "";
  position: absolute;
  inset: 12px;
  border: 2px solid var(--line-strong);
  border-radius: 3px;
}

.results-placeholder-icon::after {
  content: "";
  position: absolute;
  top: 16px;
  left: 18px;
  right: 18px;
  height: 2px;
  background: var(--line-strong);
  box-shadow: 0 6px 0 var(--line-strong), 0 12px 0 var(--line-strong);
}

.results-placeholder p {
  margin: 0;
  font-size: 14px;
  max-width: 360px;
  margin-inline: auto;
  line-height: 1.55;
}

body.modal-open { overflow: hidden; }

.modal.modal-behind {
  pointer-events: none;
}

.modal.modal-behind .modal-dialog {
  opacity: 0.45;
  filter: blur(1px);
  transform: scale(0.985);
  transition: opacity 0.15s, filter 0.15s, transform 0.15s;
}

/* ── JSON payload dialog (native <dialog> = browser top layer) ── */
.json-dialog {
  border: none;
  border-radius: 12px;
  padding: 0;
  margin: auto;
  max-width: min(760px, calc(100vw - 32px));
  width: 100%;
  max-height: calc(100vh - 40px);
  background: transparent;
  overflow: visible;
}

.json-dialog::backdrop {
  background: rgba(28, 36, 48, 0.6);
  backdrop-filter: blur(2px);
}

.json-dialog-panel {
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 40px);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}

.json-dialog-fallback-open {
  position: fixed;
  inset: 0;
  z-index: 3000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(28, 36, 48, 0.6);
  max-width: none;
  width: 100%;
  max-height: none;
  height: 100%;
}

.json-dialog-fallback-open .json-dialog-panel {
  width: min(760px, 100%);
}

.group-records-dialog {
  max-width: min(980px, calc(100vw - 32px));
}

.group-records-dialog-panel {
  width: min(980px, calc(100vw - 32px));
}

.group-records-body {
  padding: 0 20px 20px;
  overflow: auto;
  flex: 1;
  min-height: 0;
  max-height: calc(100vh - 120px);
}

.flow-group-records-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.flow-group-records-table {
  max-height: min(520px, calc(100vh - 200px));
}

.flow-row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  align-items: center;
}

.col-actions {
  min-width: 180px;
  white-space: nowrap;
}

.modal-body-json {
  padding: 16px 20px 20px;
  overflow: auto;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.payload-json-modal {
  flex: 1;
  min-height: 180px;
  max-height: calc(100vh - 160px);
  overflow: auto;
  margin: 0;
}

.nx-view-store,
.nx-view-stash,
.nx-payload-store,
.nx-payload-stash {
  display: none !important;
}

.nx-view-btn {
  height: var(--ctrl-h-sm);
  min-height: var(--ctrl-h-sm);
  padding: 0 10px;
  font-size: var(--ctrl-fs-sm);
}

.nx-view-btn .tab-badge {
  margin-left: 2px;
  min-width: 16px;
  line-height: 14px;
  font-size: 9px;
}

.nx-view-err {
  color: var(--err);
  border-color: rgba(207, 34, 46, 0.35);
  background: var(--err-soft);
}

.nx-view-err:hover {
  color: var(--err);
  border-color: rgba(207, 34, 46, 0.5);
  background: rgba(207, 34, 46, 0.12);
}

.nx-view-res {
  color: var(--fg-secondary);
}

.col-response {
  white-space: nowrap;
  vertical-align: middle;
}

/* ── Flow view (modal content) ── */
.flow-view {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.flow-info-bar {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 10px 12px;
  background: var(--panel2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.flow-info-line {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  min-width: 0;
}

.flow-info-meta {
  gap: 6px 10px;
  font-size: 12px;
  line-height: 1.3;
}

.flow-filename {
  font-size: 13px;
  font-weight: 600;
  color: var(--fg);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: min(420px, 100%);
}

.fm {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
}

.fm-k {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.flow-stats-inline {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
  flex-shrink: 0;
}

.fs {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 4px;
  font-size: 11.5px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.fs-k {
  font-size: 10px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.fs-v {
  font-weight: 600;
  color: var(--fg-secondary);
}

.fs-v em { font-style: normal; font-weight: 700; }
.fs-v em.ok { color: var(--ok); }
.fs-v em.warn { color: var(--warn); }
.fs-v em.err { color: var(--err); }

.flow-error {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  font-size: 12px;
  padding-top: 2px;
}

@media (max-width: 720px) {
  .flow-stats-inline {
    margin-left: 0;
    width: 100%;
    flex-wrap: wrap;
  }
}

.flow-section {
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.flow-section-head {
  padding: 8px 14px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  background: var(--panel2);
  border-bottom: 1px solid var(--line);
}

.flow-section .pipeline {
  margin: 0;
  border: none;
  border-radius: 0;
  background: var(--panel);
}

.pipeline-connected {
  display: flex;
  align-items: stretch;
  flex-wrap: wrap;
  padding: 16px 14px;
  gap: 0;
}

.pipeline-connected .pipe-step {
  flex: 1;
  min-width: 110px;
  border: none;
  background: transparent;
  padding: 4px 10px;
  text-align: center;
}

.pipeline-connected .pipe-step.done,
.pipeline-connected .pipe-step.active {
  background: transparent;
  box-shadow: none;
}

.pipeline-connected .pipe-step .pipe-num {
  display: flex;
  margin: 0 auto 6px;
}

.pipeline-connected .pipe-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--fg-secondary);
  letter-spacing: -0.01em;
}

.pipeline-connected .pipe-sub {
  padding-left: 0;
  text-align: center;
  margin-top: 5px;
}

.pipe-connector {
  flex: 0 0 24px;
  /* Pin to the top of the row and offset down to the centre of the step-number
     circle. Deterministic regardless of step height, so the line stays level
     even as spinners / result chips appear and disappear during a run. */
  align-self: flex-start;
  height: 2px;
  margin: 14px -2px 0;
  background: var(--line-strong);
  border-radius: 1px;
}

.pipe-connector.active {
  background: var(--accent);
}

.flow-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  background: var(--accent-soft);
  border: 1px solid rgba(13, 148, 136, 0.2);
  border-radius: var(--radius);
}

.flow-check {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  cursor: pointer;
}

.flow-job-slot:empty { display: none; }

.flow-tabs {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  padding-bottom: 10px;
}

.results-root .flow-view {
  gap: 0;
  min-height: 0;
}

.results-root .flow-tabs {
  position: sticky;
  top: 0;
  z-index: 6;
  margin: 0;
  padding: 10px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  align-items: center;
}

.results-root .flow-tabs-meta {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  white-space: nowrap;
}

.results-root #flow-run-strip-wrap {
  padding: 10px 20px 0;
}

.results-root .flow-content {
  padding: 14px 20px 20px;
  min-height: 180px;
}

.flow-run-strip {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: var(--radius-lg);
  font-size: 12.5px;
  font-weight: 500;
  color: var(--accent);
  background: var(--accent-soft);
  border: 1px solid rgba(13, 148, 136, 0.2);
  box-shadow: var(--shadow-sm);
}

.flow-run-strip.running {
  animation: flow-strip-pulse 2.5s ease-in-out infinite;
}

@keyframes flow-strip-pulse {
  0%, 100% { box-shadow: var(--shadow-sm); }
  50% { box-shadow: 0 0 0 3px rgba(13, 148, 136, 0.08), var(--shadow-sm); }
}

@media (prefers-reduced-motion: reduce) {
  .flow-run-strip.running { animation: none; }
}

.flow-run-strip-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  flex-shrink: 0;
  border-radius: 50%;
  font-size: 13px;
  font-weight: 700;
  background: rgba(255, 255, 255, 0.65);
  border: 1px solid rgba(13, 148, 136, 0.15);
}

.flow-run-strip.done .flow-run-strip-icon.ok {
  color: var(--ok);
  background: rgba(255, 255, 255, 0.7);
  border-color: rgba(26, 127, 55, 0.2);
}

.flow-run-strip.err .flow-run-strip-icon.err {
  color: var(--err);
  background: rgba(255, 255, 255, 0.7);
  border-color: rgba(207, 34, 46, 0.2);
}

.flow-run-strip.done {
  color: var(--ok);
  background: var(--ok-soft);
  border-color: rgba(26, 127, 55, 0.2);
}

.flow-run-strip.err {
  color: var(--err);
  background: var(--err-soft);
  border-color: rgba(207, 34, 46, 0.2);
}

.flow-run-strip.idle {
  color: var(--muted);
  background: var(--panel2);
  border-color: var(--line);
}

.flow-run-msg {
  flex: 0 1 auto;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.flow-run-progress {
  flex: 1;
  min-width: 80px;
}

.flow-run-progress .flow-progress-track {
  height: 5px;
}

/* ── Summary tab (สรุป) ── */
.flow-summary {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.flow-summary-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px;
}

.flow-stat-card {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 12px 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}

.flow-stat-label {
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}

.flow-stat-values {
  display: flex;
  align-items: baseline;
  gap: 4px;
}

.flow-stat-val {
  font-size: 20px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--fg);
  line-height: 1.1;
}

.flow-stat-val.ok { color: var(--ok); }
.flow-stat-val.warn { color: var(--warn); }
.flow-stat-val.err { color: var(--err); }

.flow-stat-sep {
  font-size: 14px;
  font-weight: 500;
  color: var(--line-strong);
}

.flow-stat-hint {
  font-size: 11px;
}

.flow-summary-card {
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: var(--panel);
  box-shadow: var(--shadow-sm);
}

.flow-summary-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 16px;
  background: linear-gradient(180deg, var(--panel2) 0%, var(--panel) 100%);
  border-bottom: 1px solid var(--line);
}

.flow-summary-card-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.flow-summary-run {
  font-size: 11px;
}

.flow-section-compact {
  border: none;
  border-radius: 0;
  overflow: visible;
  margin-bottom: 0;
}

.flow-section-compact .flow-section-head {
  display: none;
}

.pipeline-modal {
  padding: 18px 14px 16px;
  background: var(--panel);
  border: none;
  border-radius: 0;
  margin: 0;
  gap: 6px;
}

.pipeline-connected.pipeline-modal .pipe-step {
  min-width: 88px;
  padding: 10px 8px 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel2);
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
}

.pipeline-connected.pipeline-modal .pipe-step.done {
  border-color: rgba(5, 150, 105, 0.3);
  background: var(--stage-submit-soft);
  box-shadow: none;
}

.pipeline-connected.pipeline-modal .pipe-step.active {
  border-color: rgba(13, 148, 136, 0.45);
  background: var(--accent-soft);
  box-shadow: 0 0 0 3px rgba(13, 148, 136, 0.08);
}

.pipeline-connected.pipeline-modal .pipe-step.pending {
  opacity: 0.65;
}

.pipeline-modal .pipe-label {
  font-size: 11.5px;
  font-weight: 600;
}

.pipeline-modal .pipe-connector {
  flex-basis: 20px;
  margin-top: 22px;
}

.flow-actions-card {
  padding: 14px 16px;
  background: linear-gradient(135deg, var(--panel2) 0%, var(--panel) 100%);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

.flow-action-running,
.flow-action-done {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.flow-action-status {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  flex: 1;
  min-width: 0;
}

.flow-action-status-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  flex-shrink: 0;
  border-radius: 50%;
  background: var(--accent-soft);
  border: 1px solid rgba(13, 148, 136, 0.25);
  color: var(--accent);
}

.flow-action-status-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.flow-action-status-title {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--fg);
}

.flow-action-done-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  flex-shrink: 0;
  border-radius: 50%;
  font-size: 16px;
  font-weight: 700;
  background: var(--ok-soft);
  border: 1px solid rgba(26, 127, 55, 0.25);
  color: var(--ok);
}

.flow-action-cta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.flow-action-blocked {
  opacity: 0.92;
}

.flow-action-blocked .flow-action-cta-title {
  color: var(--warn);
}

.flow-action-cta-text {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}

.flow-action-cta-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--fg);
}

.flow-action-cta-form {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin: 0;
}

.flow-check-card {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 7px 12px;
  font-size: 12.5px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--ctrl-radius);
  cursor: pointer;
  transition: border-color 0.12s, background 0.12s;
}

.flow-check-card:hover {
  border-color: var(--line-strong);
  background: var(--panel2);
}

.flow-check-card input {
  accent-color: var(--accent);
}

.btn-primary-flow {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: var(--ctrl-h);
  min-height: var(--ctrl-h);
  padding: 0 18px;
  font-weight: 600;
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  box-shadow: 0 2px 8px var(--accent-glow);
  transition: background 0.12s, box-shadow 0.12s, transform 0.1s;
}

.btn-primary-flow:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
  color: #fff;
  box-shadow: 0 4px 14px var(--accent-glow);
}

.btn-primary-flow:active {
  transform: translateY(1px);
}

.btn-primary-flow .btn-icon {
  font-size: 11px;
  opacity: 0.9;
}

.flow-error-banner {
  padding: 12px 14px;
  background: var(--err-soft);
  border: 1px solid rgba(207, 34, 46, 0.22);
  border-radius: var(--radius);
  font-size: 13px;
}

.flow-action-hint,
.flow-run-hint {
  font-size: 12px;
  line-height: 1.45;
}

.flow-run-hint.warn {
  color: var(--warn);
}

.flow-submit-form {
  margin: 0;
}

.flow-start-form.htmx-request .btn-primary-flow {
  opacity: 0.8;
  pointer-events: none;
}

.flow-start-form.htmx-request .btn-primary-flow::after {
  content: " …";
}

.flow-pipeline-inner + .flow-subsection,
#flow-pipeline-wrap + .flow-subsection {
  margin-top: 6px;
}

.flow-empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 6px;
  padding: 28px 20px;
  margin-top: 4px;
  background: var(--panel2);
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius-lg);
}

.flow-empty-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  margin-bottom: 4px;
  border-radius: 50%;
  font-size: 16px;
  background: var(--panel);
  border: 1px solid var(--line);
  color: var(--muted);
}

.flow-empty-icon.idle {
  color: var(--accent);
  background: var(--accent-soft);
  border-color: rgba(13, 148, 136, 0.25);
}

.flow-empty-wait .flow-empty-icon {
  color: var(--accent);
  background: var(--accent-soft);
  border-color: rgba(13, 148, 136, 0.25);
}

.flow-empty-title {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  color: var(--fg-secondary);
}

.flow-empty-state p {
  margin: 0;
  max-width: 320px;
  font-size: 13px;
  line-height: 1.5;
}

@media (max-width: 720px) {
  .results-root .flow-tabs-meta {
    display: none;
  }

  .flow-run-msg {
    white-space: normal;
  }

  .flow-summary-stats {
    grid-template-columns: 1fr 1fr;
  }

  .flow-action-cta {
    flex-direction: column;
    align-items: stretch;
  }

  .flow-action-cta-form {
    width: 100%;
    justify-content: stretch;
  }

  .flow-action-cta-form .btn-primary-flow {
    flex: 1;
    justify-content: center;
  }

  .pipeline-connected.pipeline-modal .pipe-step {
    min-width: 72px;
  }

  .pipeline-modal .pipe-connector {
    flex-basis: 12px;
  }
}

.flow-live {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.flow-progress {
  display: flex;
  align-items: center;
  gap: 10px;
}

.flow-progress-track {
  flex: 1;
  height: 6px;
  background: var(--line);
  border-radius: 999px;
  overflow: hidden;
}

.flow-progress-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), #0891b2);
  border-radius: 999px;
  transition: width 0.35s ease;
}

.flow-progress-label {
  flex-shrink: 0;
  min-width: 36px;
  font-size: 11px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--accent);
  text-align: right;
}

.flow-log-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}

.flow-log-head .flow-subsection-head {
  margin-bottom: 0;
}

.flow-log-stick {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  cursor: pointer;
  user-select: none;
}

.flow-log-trunc {
  margin: 6px 0 0;
  font-size: 11px;
}

.flow-log-wait {
  padding: 16px 12px;
}

.flow-live-pill {
  margin-left: auto;
}

.btn-xs {
  height: 26px;
  min-height: 26px;
  padding: 0 10px;
  font-size: 11px;
}

.flow-tab-jump {
  flex-shrink: 0;
}

.flow-tab {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  height: var(--ctrl-h-sm);
  min-height: var(--ctrl-h-sm);
  padding: 0 14px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--ctrl-radius);
  font: inherit;
  font-size: var(--ctrl-fs-sm);
  font-weight: 500;
  line-height: 1;
  color: var(--muted);
  cursor: pointer;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
}

.flow-tab:hover:not(:disabled) {
  background: var(--panel2);
  color: var(--fg-secondary);
}

.flow-tab.active {
  background: var(--accent-soft);
  border-color: rgba(13, 148, 136, 0.35);
  color: var(--accent);
  font-weight: 600;
}

.flow-tab:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.tab-badge {
  display: inline-block;
  min-width: 18px;
  padding: 0 5px;
  margin-left: 4px;
  border-radius: 999px;
  background: var(--line);
  color: var(--fg-secondary);
  font-size: 10px;
  font-weight: 700;
  line-height: 16px;
  vertical-align: 1px;
}

.flow-tab.active .tab-badge {
  background: rgba(13, 148, 136, 0.2);
  color: var(--accent);
}

.flow-content {
  min-height: 120px;
}

.flow-content .tablewrap {
  max-height: 420px;
}

.flow-content .tablewrap-nxmap {
  max-height: 480px;
}

.flow-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.col-request {
  white-space: nowrap;
  max-width: 260px;
  overflow: hidden;
}

.nx-method {
  font-size: 10px;
  font-weight: 700;
  margin-right: 4px;
}

.nx-path {
  display: inline-block;
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  vertical-align: bottom;
  font-family: ui-monospace, "Cascadia Code", "Consolas", monospace;
  font-size: 10.5px;
  color: var(--fg-secondary);
}

/* Marker on a request whose actual send diverged from the plan (e.g. a
   DATA_ENTRY that became a PUT to accumulate onto an existing month). */
.nx-plan-diff {
  margin-left: 4px;
  font-size: 9.5px;
  font-weight: 700;
  color: var(--warn, #b45309);
  border: 1px solid var(--warn, #b45309);
  border-radius: 4px;
  padding: 0 4px;
}

.col-status {
  white-space: nowrap;
}

.nx-http {
  margin-left: 4px;
  font-size: 10px;
}

.col-payload {
  min-width: 72px;
  white-space: nowrap;
  vertical-align: middle;
}

/* ── Detail tabs (Grouping / NXMap) ── */
.flow-detail-panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.flow-detail-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding-top: 5px;
}

.flow-detail-title {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  color: var(--fg);
}

.flow-detail-sub {
  margin: 4px 0 0;
  font-size: 12.5px;
  line-height: 1.45;
}

.flow-detail-stats {
  margin: 0;
}

.flow-detail-filters {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 4px;
}

.flow-detail-filter-label {
  flex-shrink: 0;
  min-width: 48px;
  padding-top: 6px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.flow-filter-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  flex: 1;
  min-width: 0;
}

.flow-filter-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 28px;
  padding: 0 10px;
  background: var(--panel2);
  border: 1px solid var(--line);
  border-radius: 999px;
  font: inherit;
  font-size: 11.5px;
  font-weight: 500;
  color: var(--fg-secondary);
  cursor: pointer;
  text-decoration: none;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
}

.flow-filter-chip:hover {
  background: var(--panel);
  border-color: var(--line-strong);
  color: var(--fg);
  text-decoration: none;
}

.flow-filter-chip.active {
  background: var(--accent-soft);
  border-color: rgba(13, 148, 136, 0.35);
  color: var(--accent);
  font-weight: 600;
}

.flow-detail-table-meta {
  align-items: center;
  gap: 10px;
}

.flow-detail-table {
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  overflow-x: auto;
  overflow-y: auto;
}

.flow-detail-table > table {
  width: max-content;
  min-width: 100%;
}

.flow-detail-table th.col-eam-activity,
.flow-detail-table td.col-eam-activity {
  width: 240px;
  min-width: 240px;
  max-width: 240px;
  overflow: hidden;
  vertical-align: top;
  box-sizing: border-box;
}

.flow-detail-table .eam-activity-id {
  display: block;
  max-width: 100%;
  font-family: ui-monospace, "Cascadia Code", "Consolas", monospace;
  font-size: 11.5px;
  line-height: 1.4;
  word-break: break-all;
  overflow-wrap: anywhere;
}

.flow-detail-table th.col-eam-reason,
.flow-detail-table td.col-eam-reason {
  width: 320px;
  min-width: 320px;
  max-width: 320px;
  overflow: hidden;
  vertical-align: top;
  box-sizing: border-box;
}

.flow-detail-table td.col-eam-reason.reason {
  max-width: 320px;
}

.flow-detail-table .col-eam-reason .reason-list-compact {
  max-width: 100%;
  margin: 0;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.flow-row-details {
  min-width: 88px;
}

.flow-row-details summary {
  list-style: none;
  cursor: pointer;
}

.flow-row-details summary::-webkit-details-marker {
  display: none;
}

.flow-detail-expand-body {
  margin-top: 8px;
  padding: 10px 12px;
  background: var(--panel2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  max-width: 420px;
}

.flow-detail-block + .flow-detail-block {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}

.flow-detail-block-label {
  display: block;
  margin-bottom: 4px;
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.flow-detail-inline {
  display: block;
  font-size: 11px;
  line-height: 1.45;
  word-break: break-all;
}

.flow-detail-pre {
  margin: 0;
  padding: 8px 10px;
  max-height: 200px;
  overflow: auto;
  font-family: ui-monospace, "Cascadia Code", "Consolas", monospace;
  font-size: 10.5px;
  line-height: 1.45;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 4px;
  white-space: pre-wrap;
  word-break: break-word;
}

.col-detail {
  min-width: 100px;
  vertical-align: top;
}

.col-ids {
  min-width: 120px;
  max-width: 180px;
}

.flow-id-chip {
  display: block;
  margin-bottom: 3px;
  padding: 2px 6px;
  font-family: ui-monospace, "Cascadia Code", "Consolas", monospace;
  font-size: 10px;
  background: var(--panel2);
  border: 1px solid var(--line);
  border-radius: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.flow-id-chip.ok {
  background: var(--ok-soft);
  border-color: rgba(26, 127, 55, 0.25);
  color: var(--ok);
}

.col-step {
  white-space: nowrap;
}

.pill.sm {
  height: 22px;
  min-height: 22px;
  padding: 0 8px;
  font-size: 10.5px;
}

.payload-json {
  margin: 0;
  padding: 10px 12px;
  background: #0f172a;
  border: 1px solid #1e293b;
  border-radius: 6px;
  font-family: "JetBrains Mono", ui-monospace, "Cascadia Code", "Consolas", monospace;
  font-size: 11px;
  line-height: 1.5;
  color: #94a3b8;
  white-space: pre-wrap;
  word-break: break-word;
}

.flow-status-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
  margin-bottom: 14px;
}

.flow-status-banner.run {
  background: var(--accent-soft);
  border: 1px solid rgba(13, 148, 136, 0.25);
  color: var(--accent);
}

.flow-status-banner.ok {
  background: var(--ok-soft);
  border: 1px solid rgba(26, 127, 55, 0.25);
  color: var(--ok);
}

.flow-status-banner.idle {
  background: var(--panel2);
  border: 1px solid var(--line);
  color: var(--muted);
}

.flow-status-banner.err {
  background: var(--err-soft);
  border: 1px solid rgba(207, 34, 46, 0.25);
  color: var(--err);
}

.flow-subsection {
  margin-top: 16px;
}

.flow-subsection-card {
  padding: 14px 16px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

.flow-subsection-card .flow-subsection-head {
  padding-bottom: 10px;
  margin-bottom: 10px;
  border-bottom: 1px solid var(--line);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}

.flow-subsection-head {
  font-size: 12px;
  font-weight: 600;
  color: var(--fg-secondary);
  margin-bottom: 8px;
}

.flow-empty-hint {
  padding: 24px 16px;
  text-align: center;
  font-size: 13px;
  background: var(--panel2);
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
}

.flow-error-box {
  padding: 14px 16px;
  background: var(--err-soft);
  border: 1px solid rgba(207, 34, 46, 0.2);
  border-radius: var(--radius);
  font-size: 13px;
}

.kv-table td:first-child {
  width: 140px;
  color: var(--muted);
  font-weight: 500;
}

/* ── EAM index admin ── */
.scope-banner-desc {
  margin: 0 0 8px;
  font-size: 13px;
  color: #94a3b8;
  line-height: 1.45;
}

.eam-alert {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 16px;
  padding: 12px 16px;
  background: var(--warn-soft);
  border: 1px solid rgba(217, 119, 6, 0.25);
  border-radius: var(--radius);
  font-size: 13px;
  line-height: 1.5;
  color: var(--fg-secondary);
}

.eam-warn {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px 18px;
  margin-bottom: 16px;
  border-left-color: var(--warn);
  background: linear-gradient(135deg, var(--panel) 0%, var(--warn-soft) 100%);
}

.eam-warn-icon {
  flex-shrink: 0;
  width: 22px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--warn);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
}

.eam-warn-body {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
}

.eam-warn-text {
  margin: 0;
  font-size: 13px;
  line-height: 1.55;
  color: var(--fg-secondary);
}

.eam-warn-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.eam-alert-icon {
  flex-shrink: 0;
  width: 22px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--warn);
  color: #fff;
  font-size: 13px;
  font-weight: 700;
}

.eam-alert-body {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.eam-alert-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.eam-filter-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.eam-stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 20px;
}

.eam-stat-activities {
  border-color: rgba(124, 58, 237, 0.25);
  background: linear-gradient(135deg, var(--panel) 0%, var(--stage-etl-soft) 100%);
}

.eam-stat-activities .eam-stat-value {
  color: var(--stage-etl);
}

.eam-stat-entities {
  border-color: rgba(13, 148, 136, 0.25);
  background: linear-gradient(135deg, var(--panel) 0%, var(--accent-soft) 100%);
}

.eam-stat-entities .eam-stat-value {
  color: var(--accent);
}

.eam-stat-categories .eam-stat-value {
  color: var(--stage-upload);
}

.eam-stat-card {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 16px 18px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

.eam-stat-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}

.eam-stat-value {
  font-size: 26px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--fg);
  line-height: 1;
}

.eam-stat-warn {
  border-color: rgba(217, 119, 6, 0.3);
  background: linear-gradient(135deg, var(--panel) 0%, var(--warn-soft) 100%);
}

.eam-stat-warn .eam-stat-value {
  color: var(--warn);
}

.scope-banner-eam::after {
  background: linear-gradient(180deg, var(--stage-etl), var(--accent));
}

.eam-workspace {
  padding: 0;
  overflow: hidden;
}

.eam-workspace-head {
  padding: 14px 20px 12px;
  border-bottom: 1px solid var(--line);
  background: var(--panel2);
}

.eam-tabs-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.eam-list-loading {
  display: inline-flex;
  align-items: center;
  flex-shrink: 0;
}

.eam-list-loading .spinner {
  width: 14px;
  height: 14px;
}

.eam-tabs {
  margin: 0;
  padding: 0 0 10px;
  border-bottom: none;
  background: transparent;
  flex: 1;
  min-width: 0;
}

.eam-tab-icon {
  font-size: 12px;
  opacity: 0.75;
  margin-right: 2px;
}

.eam-tab-btn.active {
  background: var(--stage-etl-soft);
  border-color: rgba(124, 58, 237, 0.3);
  color: var(--stage-etl);
}

.eam-workspace-desc {
  margin: 0;
  padding-bottom: 2px;
  font-size: 12.5px;
  line-height: 1.5;
}

.eam-list-pane {
  display: flex;
  flex-direction: column;
  min-height: 460px;
  margin: 0;
  padding: 0;
  border-radius: 0;
  border: none;
  border-top: 1px solid var(--line);
  box-shadow: none;
  background: var(--panel);
}

.eam-list-pane-head {
  padding: 12px 16px 10px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, var(--panel) 0%, var(--panel2) 100%);
}

.eam-list-pane-title {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  color: var(--fg);
}

.eam-list-pane-sub {
  margin: 2px 0 0;
  font-size: 12px;
}

.eam-list-body {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--panel2);
}

.eam-content {
  padding: 0;
}

.eam-section {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 0;
}

.eam-filter-bar {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

.eam-filter-bar-row {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

.eam-search-wrap {
  position: relative;
  width: 100%;
}

.eam-search-wrap-grow {
  flex: 1;
  min-width: 180px;
}

.eam-search-icon {
  position: absolute;
  left: 11px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 15px;
  color: var(--muted);
  pointer-events: none;
  line-height: 1;
}

.eam-search-input {
  width: 100%;
  padding-left: 32px !important;
}

.eam-year-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex-shrink: 0;
}

.eam-year-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.eam-filter-tabs {
  display: inline-flex;
  align-self: flex-start;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel2);
  gap: 2px;
}

.eam-filter-tab {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 28px;
  padding: 0 12px;
  border: none;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.12s, color 0.12s, box-shadow 0.12s;
}

.eam-filter-tab:hover {
  color: var(--fg-secondary);
  background: var(--panel);
}

.eam-filter-tab.active {
  background: var(--panel);
  color: var(--stage-etl);
  font-weight: 600;
  box-shadow: var(--shadow-sm);
}

.eam-filter-tab-warn.active {
  color: var(--warn);
}

.eam-list-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

.eam-active-filters {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
}

.eam-clear-filters {
  padding: 2px 8px !important;
  font-size: 11.5px !important;
}

.eam-list-scroll {
  flex: 1;
  min-height: 0;
  overflow: auto;
}

.eam-list-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 10px 16px;
  border-top: 1px solid var(--line);
  background: var(--panel);
}

/* Category chips */
.eam-cat-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin: 0;
  padding: 0;
  border-bottom: none;
}

.eam-cat-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  flex-shrink: 0;
}

.eam-cat-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.eam-cat-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: var(--ctrl-h-sm);
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel);
  color: var(--fg-secondary);
  font-size: var(--ctrl-fs-sm);
  font-weight: 500;
  font-family: inherit;
  line-height: 1;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
}

.eam-cat-chip:hover {
  border-color: var(--stage-etl);
  background: var(--stage-etl-soft);
  color: var(--stage-etl);
}

.eam-cat-chip.active {
  background: var(--stage-etl-soft);
  border-color: rgba(124, 58, 237, 0.35);
  color: var(--stage-etl);
  font-weight: 600;
}

.eam-cat-chip .tab-badge {
  margin-left: 2px;
  min-width: 16px;
  font-size: 9px;
}

/* Toolbar */
.eam-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 14px;
  padding: 12px 14px;
  background: var(--panel2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.eam-toolbar-form {
  display: flex;
  align-items: center;
  gap: var(--ctrl-gap);
  flex-wrap: wrap;
}

.eam-toolbar-form-wide {
  flex: 1;
  min-width: 280px;
}

.eam-field {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: var(--ctrl-gap);
}

.eam-field-grow {
  flex: 1;
  min-width: 180px;
}

.eam-field-label {
  flex-shrink: 0;
  font-size: var(--ctrl-fs-sm);
  font-weight: 600;
  color: var(--muted);
  white-space: nowrap;
}

.eam-toolbar-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  flex-shrink: 0;
}

.eam-result-count {
  font-size: 13px;
  font-weight: 600;
  color: var(--fg-secondary);
  font-variant-numeric: tabular-nums;
}

/* Table */
.eam-tablewrap {
  max-height: none;
  border: none;
  border-radius: 0;
}

.eam-table thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--panel2);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.eam-row {
  transition: background 0.1s ease;
}

.eam-row:hover td {
  background: rgba(124, 58, 237, 0.04);
}

.eam-row-warn:hover td {
  background: rgba(217, 119, 6, 0.08);
}

.eam-table {
  font-size: 12.5px;
}

.eam-table th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--panel2);
}

.eam-table .col-cat { width: 64px; }
.eam-table .col-year { width: 56px; }
.eam-table .col-entity { min-width: 120px; max-width: 180px; }
.eam-table .col-emission { min-width: 140px; max-width: 220px; }
.eam-table .col-entity-name { min-width: 160px; }
.eam-table .col-entity-id,
.eam-table .col-activity { min-width: 280px; }

.eam-table td {
  vertical-align: middle;
}

.eam-table-activities td.col-emission {
  color: var(--fg-secondary);
  font-size: 12px;
}

.eam-row-warn td {
  background: rgba(217, 119, 6, 0.04);
}

.eam-row-warn:hover td {
  background: rgba(217, 119, 6, 0.08) !important;
}

.eam-entity-name {
  display: block;
  margin-bottom: 2px;
}

.eam-row-flag {
  font-size: 10px;
  padding: 1px 6px;
}

.eam-cat-badge {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 4px;
  font-size: 10.5px;
  font-weight: 600;
  font-family: "JetBrains Mono", ui-monospace, monospace;
  background: var(--stage-etl-soft);
  color: var(--stage-etl);
  border: 1px solid rgba(124, 58, 237, 0.2);
}

.eam-local-badge {
  display: inline-flex;
  align-items: center;
  height: var(--ctrl-h-sm);
  padding: 0 8px;
  font-size: 10px;
  flex-shrink: 0;
}

/* Inline edit */
.eam-edit-form {
  display: flex;
  align-items: center;
  gap: var(--ctrl-gap);
  flex-wrap: nowrap;
}

.eam-input-edit {
  flex: 1;
  min-width: 120px;
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: var(--ctrl-fs-sm);
}

.eam-input-warn {
  border-color: rgba(217, 119, 6, 0.45);
  background: var(--warn-soft);
}

.eam-save-status {
  font-size: 11px;
  flex-shrink: 0;
}

/* Shared form controls (.eam-input used app-wide) */
.eam-input,
select.eam-input,
input.eam-input {
  box-sizing: border-box;
  height: var(--ctrl-h);
  min-height: var(--ctrl-h);
  padding: 0 var(--ctrl-px);
  border: 1px solid var(--line-strong);
  border-radius: var(--ctrl-radius);
  font: inherit;
  font-size: var(--ctrl-fs);
  line-height: normal;
  min-width: 160px;
  background: var(--panel);
  color: var(--fg);
  transition: border-color 0.12s, box-shadow 0.12s;
  vertical-align: middle;
}

select.eam-input {
  padding-right: 28px;
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%2364748b' d='M3 4.5 6 7.5 9 4.5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
}

.eam-input:focus,
select.eam-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.eam-toolbar .eam-input,
.eam-toolbar select.eam-input,
.eam-toolbar input.eam-input,
.eam-toolbar .btn,
.eam-edit-form .eam-input,
.eam-edit-form input.eam-input,
.eam-edit-form .btn {
  height: var(--ctrl-h-sm);
  min-height: var(--ctrl-h-sm);
  font-size: var(--ctrl-fs-sm);
}

.eam-edit-form .pill,
.eam-save-status {
  display: inline-flex;
  align-items: center;
  height: var(--ctrl-h-sm);
  padding: 0 8px;
}

.eam-input-narrow {
  min-width: 88px;
  width: 88px;
  max-width: 100px;
}

.eam-input-wide {
  min-width: 220px;
  flex: 1;
}

/* Empty & pagination */
.eam-empty {
  padding: 40px 20px;
  margin: 12px 16px;
  text-align: center;
  background: var(--panel);
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
}

.eam-empty-icon {
  display: block;
  font-size: 28px;
  margin-bottom: 8px;
  opacity: 0.7;
}

.eam-empty p {
  margin: 0 0 4px;
  font-size: 13px;
  color: var(--fg-secondary);
}

.eam-empty p.muted {
  color: var(--muted);
}

.eam-pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.eam-page-info {
  font-size: 12.5px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.eam-page-actions {
  display: flex;
  gap: 8px;
}

@media (max-width: 900px) {
  #eam-summary .eam-stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .eam-filter-bar-row {
    flex-direction: column;
    align-items: stretch;
  }
}

@media (max-width: 560px) {
  #eam-summary .eam-stats-grid {
    grid-template-columns: 1fr;
  }

  .eam-workspace-head,
  .eam-list-pane-head,
  .eam-filter-bar,
  .eam-list-meta,
  .eam-list-footer {
    padding-left: 12px;
    padding-right: 12px;
  }

  .eam-filter-tabs {
    width: 100%;
    justify-content: stretch;
  }

  .eam-filter-tab {
    flex: 1;
    justify-content: center;
  }
}

/* --- Dedup ledger ------------------------------------------------------- */
.scope-banner-ledger::after {
  background: linear-gradient(180deg, var(--stage-group), var(--warn));
}

.scope-banner-gnx::after {
  background: linear-gradient(180deg, var(--stage-group), var(--stage-submit, var(--accent)));
}

/* Grouping-NXMap combined page */
.gnx-scope-bar { margin-bottom: 6px; }
.gnx-scope-select { min-width: 280px; }
.gnx-tabbar { margin-top: 14px;  margin-bottom: 14px; }
.gnx-tabbar .gnx-tab { font-weight: 600; }
td.col-gnx-upload { max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.ledger-info {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px 18px;
  margin-bottom: 16px;
  border-left-color: var(--warn);
  background: linear-gradient(135deg, var(--panel) 0%, var(--warn-soft) 100%);
}

.ledger-info-icon {
  flex-shrink: 0;
  width: 22px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--warn-soft);
  color: var(--warn);
  font-size: 12px;
  font-weight: 700;
  border: 1px solid rgba(217, 119, 6, 0.25);
}

.ledger-info-text {
  margin: 0;
  font-size: 13px;
  line-height: 1.55;
  color: var(--fg-secondary);
}

.ledger-stats-grid {
  margin-bottom: 16px;
}

.ledger-stat-uploads {
  border-color: rgba(2, 132, 199, 0.25);
  background: linear-gradient(135deg, var(--panel) 0%, var(--stage-upload-soft) 100%);
}

.ledger-stat-uploads .eam-stat-value {
  color: var(--stage-upload);
}

.ledger-stat-scope .eam-stat-value.ledger-stat-scope-name {
  font-size: 15px;
  line-height: 1.2;
  font-weight: 600;
}

.ledger-workspace {
  padding: 10px;
  overflow: hidden;
}

.ledger-workspace-head {
  padding: 14px 20px 12px;
  border-bottom: 1px solid var(--line);
  background: var(--panel2);
}

.ledger-workspace-desc {
  margin: 10px 0 0;
  font-size: 12.5px;
}

.ledger-scope-bar {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  flex-wrap: wrap;
}

.ledger-scope-bar-label {
  flex-shrink: 0;
  margin-top: 7px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}

.ledger-scope-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  flex: 1;
  min-width: 0;
}

.ledger-scope-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: auto;
  min-height: var(--ctrl-h-sm);
  padding: 6px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--fg-secondary);
  font-size: var(--ctrl-fs-sm);
  font-weight: 500;
  font-family: inherit;
  line-height: 1.25;
  cursor: pointer;
  text-align: left;
  transition: background 0.12s, border-color 0.12s, color 0.12s, box-shadow 0.12s;
}

.ledger-scope-chip:hover {
  border-color: var(--stage-group);
  background: var(--stage-group-soft);
  color: var(--stage-group);
}

.ledger-scope-chip.active {
  background: var(--stage-group-soft);
  border-color: rgba(217, 119, 6, 0.4);
  color: var(--stage-group);
  font-weight: 600;
  box-shadow: inset 0 0 0 1px rgba(217, 119, 6, 0.08);
}

.ledger-scope-slug {
  font-size: 10.5px;
  font-family: "JetBrains Mono", ui-monospace, monospace;
  opacity: 0.75;
}

.ledger-list-meta-main {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.ledger-key-hint-inline {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.ledger-key-hint-inline .tag {
  font-size: 10.5px;
}

.ledger-key-tag {
  background: var(--stage-group-soft);
  border-color: rgba(217, 119, 6, 0.22);
  color: var(--stage-group);
  font-weight: 500;
}

.ledger-list-pane {
  display: flex;
  flex-direction: column;
  min-height: 420px;
  margin: 0;
  padding: 0;
  border-radius: 0;
  border: none;
  border-top: 1px solid var(--line);
  box-shadow: none;
  background: var(--panel);
}

.ledger-list-pane-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px 10px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, var(--panel) 0%, var(--panel2) 100%);
}

.ledger-list-pane-title {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  color: var(--fg);
}

.ledger-list-pane-sub {
  margin: 2px 0 0;
  font-size: 12px;
}

.ledger-list-loading {
  display: inline-flex;
  align-items: center;
  flex-shrink: 0;
}

.ledger-list-loading .spinner {
  width: 14px;
  height: 14px;
}

.ledger-filter-bar {
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--panel2);
}

.ledger-search-wrap {
  position: relative;
  width: 100%;
}

.ledger-search-icon {
  position: absolute;
  left: 11px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 15px;
  color: var(--muted);
  pointer-events: none;
  line-height: 1;
}

.ledger-search-input {
  width: 100%;
  padding-left: 32px !important;
}

.ledger-list-body {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--panel2);
}

.ledger-section {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.ledger-flash-banner {
  padding: 10px 16px 0;
}

.ledger-list-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

.ledger-active-filters {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
}

.ledger-clear-filters {
  padding: 2px 8px !important;
  font-size: 11.5px !important;
}

.ledger-list-scroll {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 0;
}

.ledger-tablewrap {
  max-height: none;
  border: none;
  border-radius: 0;
}

.ledger-list-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 10px 16px;
  border-top: 1px solid var(--line);
  background: var(--panel);
}

.ledger-flash {
  display: inline-block;
}

.ledger-table td,
.ledger-table th {
  font-variant-numeric: tabular-nums;
  vertical-align: middle;
}

.ledger-table thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--panel2);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  white-space: nowrap;
}

.ledger-table .ledger-col-key {
  background: rgba(217, 119, 6, 0.04);
}

.ledger-table thead .ledger-col-key {
  background: color-mix(in srgb, var(--panel2) 88%, var(--stage-group-soft));
}

.ledger-key-mark {
  display: inline-block;
  margin-left: 4px;
  padding: 0 4px;
  border-radius: 3px;
  background: var(--stage-group-soft);
  color: var(--stage-group);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.03em;
  vertical-align: middle;
}

.ledger-key-val {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 4px;
  background: var(--stage-group-soft);
  border: 1px solid rgba(217, 119, 6, 0.15);
  color: var(--fg);
  font-size: 12px;
  font-weight: 600;
}

.ledger-cell-val {
  font-size: 12.5px;
  color: var(--fg-secondary);
}

.ledger-time {
  font-size: 11.5px;
  white-space: nowrap;
}

.ledger-row {
  transition: background 0.1s ease;
}

.ledger-row:hover {
  background: rgba(13, 148, 136, 0.04);
}

.ledger-table .ledger-col-actions {
  width: 64px;
  text-align: right;
  white-space: nowrap;
}

.ledger-del-form {
  margin: 0;
}

.ledger-del-btn {
  color: var(--err) !important;
  border-color: rgba(220, 38, 38, 0.35) !important;
}

.ledger-del-btn:hover {
  background: var(--err-soft) !important;
  border-color: var(--err) !important;
}

.ledger-empty {
  padding: 36px 16px;
  text-align: center;
}

.ledger-empty-icon {
  display: block;
  font-size: 28px;
  margin-bottom: 8px;
  opacity: 0.7;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 900px) {
  .ledger-stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .ledger-scope-chip {
    flex: 1 1 calc(50% - 6px);
    min-width: 140px;
  }
}

@media (max-width: 560px) {
  .ledger-stats-grid {
    grid-template-columns: 1fr;
  }

  .ledger-scope-chip {
    flex: 1 1 100%;
  }

  .ledger-list-pane-head,
  .ledger-filter-bar,
  .ledger-list-meta,
  .ledger-list-footer {
    padding-left: 12px;
    padding-right: 12px;
  }
}

@media (max-width: 768px) {
  .eam-stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .eam-toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .eam-toolbar-meta {
    justify-content: flex-start;
  }

  .eam-edit-form {
    flex-wrap: wrap;
  }
}

/* System settings */
.scope-banner-settings::after {
  background: linear-gradient(180deg, var(--stage-etl), var(--stage-upload));
}

.settings-banner-actions {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
  flex-shrink: 0;
}

.settings-info {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px 18px;
  margin-bottom: 16px;
  border-left-color: var(--stage-etl);
  background: linear-gradient(135deg, var(--panel) 0%, var(--stage-etl-soft) 100%);
}

.settings-info-icon {
  flex-shrink: 0;
  width: 22px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--stage-etl-soft);
  color: var(--stage-etl);
  font-size: 12px;
  font-weight: 700;
  border: 1px solid rgba(124, 58, 237, 0.2);
}

.settings-info-text {
  margin: 0;
  font-size: 13px;
  line-height: 1.55;
}

.settings-workspace {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.settings-card-skeleton {
  min-height: 80px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.manage-ftp-card {
  margin-bottom: 0;
}

.manage-filter-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 180px;
}

.manage-filter-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.manage-select {
  font-family: var(--font-mono);
  font-size: 13px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel2);
  color: var(--text);
  min-width: 220px;
}

@media (max-width: 768px) {
  .manage-select {
    min-width: 100%;
  }
}

/* Uploads table filters */
.uploads-filters {
  gap: 12px;
  align-items: flex-end;
  flex-wrap: wrap;
  margin-bottom: 14px;
  padding: 12px 14px;
  background: var(--panel2);
  border: 1px solid var(--line);
  border-radius: var(--radius, 12px);
}

.uploads-filter-search {
  flex: 1 1 220px;
  min-width: 200px;
}

.uploads-search-input,
.uploads-date-input {
  font-family: var(--font-mono);
  font-size: 13px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  width: 100%;
}

.uploads-list-meta {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

.uploads-active-filters {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.uploads-content {
  min-height: 48px;
}

.uploads-tablewrap table {
  font-size: 12.5px;
}

.uploads-dt {
  font-size: 12px;
  white-space: nowrap;
}

.uploads-pagination {
  margin-top: 12px;
}

.uploads-empty {
  margin: 0;
}

/* --- Email inbox ---------------------------------------------------------- */
.scope-banner-email::after {
  background: linear-gradient(180deg, var(--stage-upload), var(--accent));
}

.email-stats-grid {
  grid-template-columns: repeat(4, 1fr);
}

.email-stat-ok {
  border-color: rgba(5, 150, 105, 0.28);
  background: linear-gradient(135deg, var(--panel) 0%, var(--ok-soft) 100%);
}

.email-stat-ok .eam-stat-value {
  color: var(--ok);
}

.email-workspace {
  padding: 0;
  overflow: hidden;
}

.email-workspace-head {
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  background: var(--panel2);
}

.email-workspace-desc {
  margin: 0 0 8px;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.4;
}

.email-type-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.email-type-bar-label {
  flex-shrink: 0;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}

.email-type-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  flex: 1;
  min-width: 0;
}

.email-type-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 26px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel);
  color: var(--fg-secondary);
  font-size: 11.5px;
  font-weight: 500;
  font-family: inherit;
  line-height: 1;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s, color 0.12s, box-shadow 0.12s;
}

.email-type-chip:hover {
  border-color: var(--stage-upload);
  background: var(--stage-upload-soft);
  color: var(--stage-upload);
}

.email-type-chip.active {
  background: var(--accent-soft);
  border-color: rgba(13, 148, 136, 0.35);
  color: var(--accent);
  font-weight: 600;
  box-shadow: inset 0 0 0 1px rgba(13, 148, 136, 0.08);
}

.email-type-chip .tab-badge {
  margin-left: 2px;
  min-width: 16px;
  font-size: 9px;
}

.email-type-chip.email-type-unclassified {
  border-style: dashed;
}

.email-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr);
  gap: 0;
  align-items: stretch;
  min-height: 460px;
}

.email-list-pane {
  display: flex;
  flex-direction: column;
  min-width: 0;
  border-right: 1px solid var(--line);
  margin: 0;
  padding: 0;
  border-radius: 0;
  border-top: none;
  border-bottom: none;
  border-left: none;
  box-shadow: none;
  background: var(--panel);
}

.email-list-pane-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  background: var(--panel2);
}

.email-list-pane-title {
  margin: 0;
  font-size: 13px;
  font-weight: 600;
  color: var(--fg);
  letter-spacing: -0.01em;
}

.email-list-pane-sub {
  margin: 1px 0 0;
  font-size: 11px;
}

.email-list-loading {
  display: inline-flex;
  align-items: center;
  flex-shrink: 0;
}

.email-list-loading .spinner {
  width: 14px;
  height: 14px;
}

.email-filter-bar {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
  background: var(--panel2);
}

.email-search-wrap {
  position: relative;
  width: 100%;
}

.email-search-icon {
  position: absolute;
  left: 11px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 15px;
  color: var(--muted);
  pointer-events: none;
  line-height: 1;
}

.email-search-input {
  width: 100%;
  padding-left: 32px !important;
}

.email-status-tabs {
  display: inline-flex;
  align-self: flex-start;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel);
  gap: 2px;
}

.email-status-tab {
  height: 26px;
  padding: 0 10px;
  border: none;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font-size: 11.5px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.12s, color 0.12s, box-shadow 0.12s;
}

.email-status-tab:hover {
  color: var(--fg-secondary);
  background: var(--panel2);
}

.email-status-tab.active {
  background: var(--panel);
  color: var(--accent);
  font-weight: 600;
  box-shadow: var(--shadow-sm);
}

.email-list-body {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--panel2);
}

.email-section {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 0;
}

.email-list-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
  padding: 6px 12px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

.email-active-filters {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
}

.email-clear-filters {
  margin-left: 2px;
  padding: 2px 8px !important;
  font-size: 11.5px !important;
}

.email-list-scroll {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 4px 6px;
}

.email-list-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  padding: 6px 12px;
  border-top: 1px solid var(--line);
  background: var(--panel);
}

.email-inbox-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 1px;
}

.email-inbox-item {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  width: 100%;
  margin: 0;
  padding: 7px 10px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: border-color 0.12s, background 0.12s;
}

.email-inbox-item:hover {
  border-color: transparent;
  background: var(--panel);
}

.email-inbox-item:focus-visible {
  outline: 2px solid var(--accent-glow);
  outline-offset: 1px;
}

.email-inbox-item.selected {
  border-color: rgba(13, 148, 136, 0.28);
  background: var(--accent-soft);
  box-shadow: inset 2px 0 0 var(--accent);
}

.email-inbox-item-pending {
  border-left: 2px solid rgba(217, 119, 6, 0.35);
}

.email-inbox-item-pending.selected {
  border-left-color: var(--accent);
}

.email-inbox-avatar {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--stage-upload-soft);
  color: var(--stage-upload);
  font-size: 11.5px;
  font-weight: 700;
  border: 1px solid rgba(2, 132, 199, 0.15);
  margin-top: 1px;
}

.email-inbox-item.selected .email-inbox-avatar {
  background: var(--panel);
  border-color: rgba(13, 148, 136, 0.25);
  color: var(--accent);
}

.email-inbox-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.email-inbox-item-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}

.email-inbox-sender-line {
  font-size: 12px;
  font-weight: 600;
  color: var(--fg-secondary);
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.email-inbox-time {
  flex-shrink: 0;
  font-size: 10px;
  color: var(--muted);
}

.email-inbox-subject {
  font-weight: 500;
  font-size: 12.5px;
  line-height: 1.3;
  color: var(--fg);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.email-inbox-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  margin-top: 1px;
}

.email-inbox-badges {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  min-width: 0;
}

.email-inbox-attach {
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
}

.email-empty {
  padding: 28px 14px;
  text-align: center;
}

.email-empty-icon {
  display: block;
  font-size: 24px;
  margin-bottom: 6px;
  opacity: 0.7;
}

.email-detail-pane {
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--panel);
  overflow: auto;
}

.email-detail-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 4px;
  flex: 1;
  min-height: 200px;
  padding: 24px 16px;
}

.email-detail-placeholder-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--panel2);
  border: 1px dashed var(--line-strong);
  font-size: 18px;
  margin-bottom: 2px;
}

.email-detail-placeholder-title {
  margin: 0;
  font-weight: 600;
  color: var(--fg-secondary);
}

.email-mono {
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: 0.85em;
}

.email-nowrap { white-space: nowrap; }

.tag.sm {
  font-size: 10px;
  padding: 0 5px;
}

/* per-classification accent chips */
.email-type { border-color: rgba(13, 148, 136, 0.25); }
.email-type-purchased-electricity { background: rgba(217, 119, 6, 0.12); color: var(--warn); }
.email-type-water { background: rgba(8, 145, 178, 0.12); color: #0e7490; }
.email-type-cooling { background: rgba(13, 148, 136, 0.12); color: var(--accent); }
.email-type-steam { background: rgba(99, 102, 241, 0.12); color: #4f46e5; }
.email-type-waste-generated { background: rgba(120, 113, 108, 0.14); color: #57534e; }
.email-type-wastewater-treatment { background: rgba(5, 150, 105, 0.12); color: var(--ok); }
.email-type-unclassified { background: var(--panel2); color: var(--muted); border-style: dashed; }

.email-detail {
  padding: 12px 14px 14px;
}

.email-flash {
  margin-bottom: 8px;
}

.email-detail-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
}

.email-detail-head-main {
  flex: 1;
  min-width: 0;
}

.email-detail-subject {
  margin: 0 0 5px;
  font-size: 0.98rem;
  line-height: 1.3;
  word-break: break-word;
}

.email-detail-badges {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

.email-detail-time {
  font-size: 11px;
  white-space: nowrap;
}

.email-detail-section {
  margin-bottom: 8px;
  padding: 0 0 8px;
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
}

.email-detail-section:last-of-type {
  border-bottom: none;
  margin-bottom: 0;
  padding-bottom: 0;
}

.email-detail-section-ok {
  border-bottom-color: var(--line);
  background: transparent;
  box-shadow: inset 2px 0 0 var(--ok);
  padding-left: 10px;
}

.email-detail-section-muted {
  border-bottom-style: solid;
  background: transparent;
  box-shadow: inset 2px 0 0 var(--line-strong);
  padding-left: 10px;
}

.email-section-title {
  margin: 0 0 6px;
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}

.email-section-count {
  font-weight: 700;
  color: var(--fg-secondary);
}

.email-meta {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0;
  margin: 0;
}

.email-meta > div {
  display: grid;
  grid-template-columns: 88px minmax(0, 1fr);
  gap: 6px;
  padding: 3px 0;
  border-bottom: none;
  font-size: 12.5px;
}

.email-meta > div:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.email-meta-compact > div {
  padding: 2px 0;
}

.email-meta dt {
  color: var(--muted);
  font-size: 0.78rem;
}

.email-meta dd {
  margin: 0;
  word-break: break-word;
  font-size: 12.5px;
}

.email-unclassified-note {
  margin: 0;
  font-size: 12.5px;
  color: var(--muted);
}

.email-attachments {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 4px;
}

.email-attachment {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px 8px;
  background: var(--panel2);
}

.email-attachment-icon {
  flex-shrink: 0;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 5px;
  background: var(--panel);
  border: 1px solid var(--line);
  font-size: 12px;
}

.email-attachment-body {
  flex: 1;
  min-width: 0;
}

.email-attachment-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 5px;
}

.email-attachment-name {
  font-weight: 500;
  font-size: 12.5px;
  word-break: break-all;
}

.email-attachment-meta {
  margin-top: 1px;
  font-size: 11px;
}

.email-routed {
  margin-top: 2px;
  font-size: 11px;
  word-break: break-all;
}

.email-no-attach {
  margin: 0;
  font-size: 12.5px;
}

.email-body {
  margin: 0;
  padding: 8px 10px;
  background: var(--panel2);
  border: 1px solid var(--line);
  border-radius: 6px;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 180px;
  overflow: auto;
  font-size: 0.8rem;
  line-height: 1.45;
}

.email-detail-actions {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--line);
}

@media (max-width: 1100px) {
  .email-stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 900px) {
  .email-layout {
    grid-template-columns: 1fr;
    min-height: 0;
  }

  .email-list-pane {
    border-right: none;
    border-bottom: 1px solid var(--line);
  }

  .email-detail-pane {
    min-height: 260px;
  }
}

@media (max-width: 560px) {
  .email-stats-grid {
    grid-template-columns: 1fr;
  }

  .email-list-pane-head,
  .email-filter-bar,
  .email-list-meta,
  .email-list-footer {
    padding-left: 10px;
    padding-right: 10px;
  }

  .email-list-scroll {
    padding: 4px 6px;
  }

  .email-detail {
    padding: 10px 12px 12px;
  }

  .email-status-tabs {
    width: 100%;
    justify-content: stretch;
  }

  .email-status-tab {
    flex: 1;
    padding: 0 8px;
  }
}

/* --- Login page ------------------------------------------------------------ */
.login-body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
}

.login-wrap {
  position: relative;
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px 16px;
}

/* soft decorative glows behind the card */
.login-wrap::before,
.login-wrap::after {
  content: "";
  position: absolute;
  border-radius: 50%;
  filter: blur(90px);
  pointer-events: none;
  z-index: 0;
}

.login-wrap::before {
  width: 420px;
  height: 420px;
  left: calc(50% - 420px);
  top: 8%;
  background: rgba(13, 148, 136, 0.16);
}

.login-wrap::after {
  width: 380px;
  height: 380px;
  right: calc(50% - 400px);
  bottom: 6%;
  background: rgba(2, 132, 199, 0.13);
}

.login-card {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 400px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow-lg);
  padding: 36px 32px 30px;
  animation: login-card-in 0.35s ease both;
}

@keyframes login-card-in {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.login-card::before {
  content: "";
  position: absolute;
  top: 0;
  left: 16px;
  right: 16px;
  height: 3px;
  border-radius: 0 0 3px 3px;
  background: linear-gradient(90deg, #0d9488, #0891b2);
}

.login-brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  margin-bottom: 22px;
  text-align: center;
}

.login-brand-mark {
  width: 56px;
  height: 56px;
  display: block;
  filter: drop-shadow(0 6px 16px rgba(13, 148, 136, 0.35));
}

.login-brand-mark svg {
  width: 100%;
  height: 100%;
  display: block;
}

.login-title {
  margin: 0;
  font-size: 21px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--fg);
}

.login-sub {
  margin: 2px 0 0;
  font-size: 12.5px;
  color: var(--muted);
}

.login-error {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin-bottom: 16px;
  padding: 10px 12px;
  border: 1px solid rgba(220, 38, 38, 0.25);
  border-left: 3px solid var(--err);
  border-radius: 8px;
  background: var(--err-soft);
  color: var(--err);
  font-size: 12.5px;
  line-height: 1.45;
  animation: login-shake 0.3s ease;
}

@keyframes login-shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-5px); }
  75% { transform: translateX(5px); }
}

.login-field {
  display: block;
  margin-bottom: 14px;
}

.login-label {
  display: block;
  margin-bottom: 5px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}

.login-input-wrap {
  position: relative;
}

.login-input {
  width: 100%;
  height: 44px;
  padding: 0 14px;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  background: var(--panel2);
  color: var(--fg);
  font: inherit;
  font-size: 14px;
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
}

.login-input::placeholder { color: var(--muted); opacity: 0.7; }

.login-input:focus {
  outline: none;
  background: var(--panel);
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.login-input-password { padding-right: 46px; }

.login-eye {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
}

.login-eye:hover {
  background: var(--accent-soft);
  color: var(--accent);
}

.login-btn {
  width: 100%;
  height: 46px;
  margin-top: 6px;
  border: none;
  border-radius: 10px;
  background: linear-gradient(135deg, #0d9488, #0891b2);
  color: #fff;
  font: inherit;
  font-size: 14.5px;
  font-weight: 600;
  letter-spacing: 0.01em;
  cursor: pointer;
  box-shadow: 0 6px 18px rgba(13, 148, 136, 0.3);
  transition: transform 0.12s, box-shadow 0.12s, filter 0.12s;
}

.login-btn:hover {
  filter: brightness(1.06);
  transform: translateY(-1px);
  box-shadow: 0 9px 24px rgba(13, 148, 136, 0.38);
}

.login-btn:active {
  transform: translateY(0);
  box-shadow: 0 4px 12px rgba(13, 148, 136, 0.28);
}

.login-btn:disabled {
  filter: grayscale(0.25) brightness(0.95);
  cursor: progress;
  transform: none;
}

.login-btn .spinner {
  width: 15px;
  height: 15px;
  margin-right: 8px;
  vertical-align: -2px;
  border-color: rgba(255, 255, 255, 0.35);
  border-top-color: #fff;
}

.login-foot {
  margin: 18px 0 0;
  text-align: center;
  font-size: 12px;
  color: var(--muted);
}

.login-offline {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-bottom: 16px;
  padding: 10px 12px;
  border: 1px dashed rgba(217, 119, 6, 0.4);
  border-radius: 8px;
  background: var(--warn-soft);
  color: var(--warn);
  font-size: 12.5px;
}

.login-page-foot {
  position: relative;
  z-index: 1;
  padding: 0 16px 22px;
  text-align: center;
  font-size: 11.5px;
  color: var(--muted);
}

@media (max-width: 480px) {
  .login-card { padding: 28px 22px 24px; }
}

