:root {
  color-scheme: dark;
  --bg: #0b1220;
  --card: #111a2c;
  --muted: #9fb0d0;
  --text: #e7efff;
  --accent: #4f8cff;
  --accent2: #2d6cf1;
  --border: rgba(255, 255, 255, 0.08);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: radial-gradient(1200px 600px at 20% -10%, rgba(79,140,255,0.28), transparent 60%),
              radial-gradient(900px 500px at 90% 0%, rgba(45,108,241,0.18), transparent 55%),
              var(--bg);
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial;
}

.wrap { max-width: 920px; margin: 40px auto; padding: 0 18px 40px; }
.wrap-wide { max-width: 1120px; }
.header h1 { margin: 0 0 6px; font-size: 24px; letter-spacing: 0.2px; }
.sub { margin: 0; color: var(--muted); }

.card {
  margin-top: 18px;
  background: linear-gradient(180deg, rgba(255,255,255,0.05), rgba(255,255,255,0.02));
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px;
  backdrop-filter: blur(6px);
}

.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field { display: grid; gap: 6px; }
.field span { font-size: 12px; color: var(--muted); }
.field input {
  width: 100%;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: rgba(0,0,0,0.25);
  color: var(--text);
  padding: 10px 12px;
  outline: none;
}
.field input:focus { border-color: rgba(79,140,255,0.6); box-shadow: 0 0 0 3px rgba(79,140,255,0.15); }
.field:nth-child(3) { grid-column: 1 / -1; }

.row { display: flex; gap: 10px; align-items: center; margin-top: 14px; }
.row-space { justify-content: space-between; }

/* Batch / index: keep action buttons visible when the row wraps on narrow viewports. */
.batch-toolbar {
  flex-wrap: wrap;
}
.batch-toolbar > button {
  flex-shrink: 0;
}
.batch-toolbar > .status {
  flex: 1 1 160px;
  min-width: 0;
}

button {
  border: 1px solid rgba(79,140,255,0.5);
  background: linear-gradient(180deg, var(--accent), var(--accent2));
  color: white;
  padding: 10px 14px;
  border-radius: 10px;
  cursor: pointer;
  font-weight: 650;
}
button:disabled { opacity: 0.5; cursor: not-allowed; }
.secondary {
  background: rgba(255,255,255,0.06);
  border: 1px solid var(--border);
  color: var(--text);
}
.danger {
  background: linear-gradient(180deg, rgba(231, 76, 60, 0.95), rgba(192, 57, 43, 0.92));
  border: 1px solid rgba(231, 76, 60, 0.55);
}

.status { color: var(--muted); font-size: 13px; }
.pre {
  margin: 12px 0 0;
  padding: 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: rgba(0,0,0,0.22);
  overflow: auto;
  min-height: 180px;
}

.dialog {
  width: min(920px, calc(100vw - 24px));
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 14px;
  background: linear-gradient(180deg, rgba(17,26,44,0.96), rgba(11,18,32,0.96));
  color: var(--text);
}
.dialog::backdrop {
  background: rgba(0,0,0,0.55);
  backdrop-filter: blur(4px);
}
.dialog-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}
.dialog-title {
  font-size: 14px;
  font-weight: 800;
  letter-spacing: 0.2px;
}
.dialog-sub {
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
}

.table-wrap {
  margin-top: 12px;
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
  background: rgba(0,0,0,0.18);
}
.table {
  width: 100%;
  border-collapse: collapse;
}
.table th,
.table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.table th {
  text-align: left;
  color: rgba(231, 239, 255, 0.9);
  background: rgba(255,255,255,0.04);
  letter-spacing: 0.2px;
}
.table tr:hover td {
  background: rgba(79,140,255,0.06);
}
.table td.muted {
  color: var(--muted);
}
.pill {
  display: inline-flex;
  align-items: center;
  padding: 3px 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.05);
  color: var(--text);
  font-weight: 650;
  font-size: 12px;
}
.pill.ok {
  border-color: rgba(46, 204, 113, 0.35);
  background: rgba(46, 204, 113, 0.12);
}
.pill.bad {
  border-color: rgba(231, 76, 60, 0.35);
  background: rgba(231, 76, 60, 0.12);
}
.pill.neutral {
  border-color: rgba(79,140,255,0.3);
  background: rgba(79,140,255,0.1);
}

.batch-settings-grid {
  grid-template-columns: 1fr 1fr;
}
.batch-settings-grid .field:nth-child(3) {
  grid-column: auto;
}

/* —— Batch UI (index + /batch.html): status-colored tabs + polish —— */
.batch-ui-root {
  -webkit-font-smoothing: antialiased;
  background:
    radial-gradient(ellipse 100% 80% at 50% -30%, rgba(99, 102, 241, 0.22), transparent 55%),
    radial-gradient(ellipse 80% 50% at 100% 20%, rgba(34, 211, 238, 0.08), transparent 45%),
    radial-gradient(ellipse 70% 45% at 0% 60%, rgba(244, 114, 182, 0.06), transparent 40%),
    radial-gradient(1200px 600px at 20% -10%, rgba(79, 140, 255, 0.22), transparent 60%),
    radial-gradient(900px 500px at 90% 0%, rgba(45, 108, 241, 0.14), transparent 55%),
    var(--bg);
}

.batch-ui-main .header h1 {
  font-size: 28px;
  letter-spacing: -0.02em;
  background: linear-gradient(115deg, #f1f5ff 0%, #c7d7ff 35%, #a5b8ff 55%, #e0e7ff 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-shadow: 0 0 40px rgba(99, 102, 241, 0.35);
}

.batch-ui-root .sub a {
  text-decoration: none;
  border-bottom: 1px solid rgba(79, 140, 255, 0.35);
  transition: color 0.15s ease, border-color 0.15s ease;
}
.batch-ui-root .sub a:hover {
  color: #fff;
  border-bottom-color: rgba(129, 176, 255, 0.8);
}

.batch-ui-root .card {
  border-radius: 18px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow:
    0 4px 24px rgba(0, 0, 0, 0.25),
    0 0 0 1px rgba(255, 255, 255, 0.04) inset;
  background: linear-gradient(165deg, rgba(22, 32, 52, 0.92) 0%, rgba(12, 18, 32, 0.88) 100%);
}

.batch-ui-root .field input {
  border-radius: 12px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.batch-ui-root .field input:focus {
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.2);
}

.batch-ui-root #startBtn:not(:disabled) {
  box-shadow: 0 6px 24px rgba(79, 140, 255, 0.35);
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}
.batch-ui-root #startBtn:not(:disabled):hover {
  transform: translateY(-1px);
  box-shadow: 0 10px 32px rgba(79, 140, 255, 0.45);
}

.batch-email-filter {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 12px;
  margin-top: 12px;
  margin-bottom: 2px;
}
.batch-email-filter-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  flex-shrink: 0;
}
.batch-email-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  min-width: 0;
}
.batch-email-chip {
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 650;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.06);
  color: rgba(232, 238, 252, 0.92);
  cursor: pointer;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.batch-email-chip:hover:not(:disabled) {
  border-color: rgba(129, 140, 248, 0.45);
  background: rgba(129, 140, 248, 0.12);
}
.batch-email-chip.is-active {
  border-color: rgba(99, 102, 241, 0.65);
  background: rgba(99, 102, 241, 0.28);
  color: #f5f7ff;
  box-shadow: 0 0 0 1px rgba(99, 102, 241, 0.2);
}
.batch-email-chip:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px rgba(79, 140, 255, 0.45);
}
.batch-email-chip.has-active-job {
  border-color: rgba(34, 197, 94, 0.55);
  background: rgba(34, 197, 94, 0.14);
}
.batch-email-chip.has-active-job.is-active {
  border-color: rgba(34, 197, 94, 0.85);
  background: rgba(34, 197, 94, 0.28);
  box-shadow: 0 0 0 1px rgba(34, 197, 94, 0.25);
}
.batch-email-chip-dot {
  display: inline-block;
  margin-left: 6px;
  font-size: 10px;
  line-height: 1;
  color: #22c55e;
  vertical-align: middle;
}

.batch-tab-head {
  margin-bottom: 12px;
}
.batch-tab-head h2 {
  font-weight: 750;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  font-size: 11px !important;
  color: rgba(167, 183, 214, 0.95);
}

.select-free-count-input {
  width: 4.5rem;
  box-sizing: border-box;
  padding: 7px 8px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(8, 12, 24, 0.85);
  color: rgba(232, 238, 252, 0.95);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}
.select-free-count-input::placeholder {
  color: rgba(167, 183, 214, 0.45);
}
.select-free-count-input:focus {
  outline: none;
  border-color: rgba(120, 160, 255, 0.55);
  box-shadow: 0 0 0 2px rgba(79, 140, 255, 0.2);
}

/* Live “free” count on Select (free) — matches tab-count pill look, tuned for .secondary */
.select-free-btn-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.35rem;
  margin-left: 6px;
  padding: 2px 7px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0;
  text-transform: none;
  background: rgba(129, 140, 248, 0.28);
  color: #e0e7ff;
}

/* Tab shell: outer glow follows active status */
.batch-tabs-shell {
  margin-top: 10px;
  border-radius: 18px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(6, 10, 20, 0.55);
  box-shadow:
    0 20px 50px -15px rgba(0, 0, 0, 0.55),
    0 0 0 1px rgba(255, 255, 255, 0.04) inset;
  transition: box-shadow 0.35s ease, border-color 0.35s ease;
}

.batch-tabs-shell[data-active="all"] {
  box-shadow:
    0 20px 50px -15px rgba(0, 0, 0, 0.55),
    0 0 40px -8px rgba(99, 102, 241, 0.18),
    0 0 0 1px rgba(129, 140, 248, 0.15) inset;
  border-color: rgba(129, 140, 248, 0.22);
}
.batch-tabs-shell[data-active="picked"] {
  box-shadow:
    0 20px 50px -15px rgba(0, 0, 0, 0.55),
    0 0 44px -6px rgba(251, 191, 36, 0.2),
    0 0 0 1px rgba(251, 191, 36, 0.12) inset;
  border-color: rgba(251, 191, 36, 0.2);
}
.batch-tabs-shell[data-active="running"] {
  box-shadow:
    0 20px 50px -15px rgba(0, 0, 0, 0.55),
    0 0 44px -6px rgba(34, 211, 238, 0.22),
    0 0 0 1px rgba(34, 211, 238, 0.14) inset;
  border-color: rgba(34, 211, 238, 0.22);
}
.batch-tabs-shell[data-active="success"] {
  box-shadow:
    0 20px 50px -15px rgba(0, 0, 0, 0.55),
    0 0 44px -6px rgba(52, 211, 153, 0.2),
    0 0 0 1px rgba(52, 211, 153, 0.14) inset;
  border-color: rgba(52, 211, 153, 0.22);
}
.batch-tabs-shell[data-active="failed"] {
  box-shadow:
    0 20px 50px -15px rgba(0, 0, 0, 0.55),
    0 0 44px -6px rgba(251, 113, 133, 0.22),
    0 0 0 1px rgba(251, 113, 133, 0.14) inset;
  border-color: rgba(251, 113, 133, 0.22);
}

.batch-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0;
  margin: 0;
  padding: 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.07);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.06) 0%, rgba(0, 0, 0, 0.12) 100%);
}

.batch-tab {
  flex: 1 1 auto;
  min-width: 0;
  position: relative;
  border: none;
  border-right: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 0;
  background: transparent;
  color: rgba(180, 198, 230, 0.72);
  padding: 14px 12px 16px;
  font-weight: 700;
  font-size: 12px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  cursor: pointer;
  text-align: center;
  transition: color 0.2s ease, background 0.2s ease, box-shadow 0.25s ease;
}

.batch-tab:last-child {
  border-right: none;
}

.batch-tab-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.35rem;
  margin-left: 6px;
  padding: 2px 7px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: none;
  opacity: 1;
  transition: background 0.2s ease, color 0.2s ease;
}

/* Inactive tab hues */
.batch-tab[data-tab="all"] {
  color: rgba(203, 213, 245, 0.65);
}
.batch-tab[data-tab="all"] .batch-tab-count {
  background: rgba(129, 140, 248, 0.2);
  color: #c7d2fe;
}

.batch-tab[data-tab="picked"] {
  color: rgba(253, 224, 71, 0.65);
}
.batch-tab[data-tab="picked"] .batch-tab-count {
  background: rgba(245, 158, 11, 0.22);
  color: #fde68a;
}

.batch-tab[data-tab="running"] {
  color: rgba(103, 232, 249, 0.65);
}
.batch-tab[data-tab="running"] .batch-tab-count {
  background: rgba(6, 182, 212, 0.22);
  color: #a5f3fc;
}

.batch-tab[data-tab="success"] {
  color: rgba(110, 231, 183, 0.65);
}
.batch-tab[data-tab="success"] .batch-tab-count {
  background: rgba(16, 185, 129, 0.22);
  color: #a7f3d0;
}

.batch-tab[data-tab="failed"] {
  color: rgba(253, 164, 175, 0.7);
}
.batch-tab[data-tab="failed"] .batch-tab-count {
  background: rgba(244, 63, 94, 0.2);
  color: #fecdd3;
}

.batch-tab:hover:not(.is-active) {
  color: rgba(255, 255, 255, 0.92);
  background: rgba(255, 255, 255, 0.05);
}

.batch-tab:focus-visible {
  outline: 2px solid rgba(129, 176, 255, 0.75);
  outline-offset: -2px;
  z-index: 2;
}

/* Active tab: strong status bar + glow */
.batch-tab.is-active {
  color: #fff;
}

.batch-tab[data-tab="all"].is-active {
  background: linear-gradient(180deg, rgba(99, 102, 241, 0.35) 0%, rgba(79, 70, 229, 0.12) 100%);
  box-shadow: inset 0 -3px 0 0 #a5b4fc, 0 -8px 28px rgba(129, 140, 248, 0.15);
}
.batch-tab[data-tab="all"].is-active .batch-tab-count {
  background: rgba(165, 180, 252, 0.35);
  color: #eef2ff;
}

.batch-tab[data-tab="picked"].is-active {
  background: linear-gradient(180deg, rgba(245, 158, 11, 0.4) 0%, rgba(180, 83, 9, 0.12) 100%);
  box-shadow: inset 0 -3px 0 0 #fbbf24, 0 -8px 28px rgba(251, 191, 36, 0.18);
}
.batch-tab[data-tab="picked"].is-active .batch-tab-count {
  background: rgba(253, 224, 71, 0.35);
  color: #422006;
}

.batch-tab[data-tab="running"].is-active {
  background: linear-gradient(180deg, rgba(6, 182, 212, 0.38) 0%, rgba(8, 145, 178, 0.12) 100%);
  box-shadow: inset 0 -3px 0 0 #22d3ee, 0 -8px 28px rgba(34, 211, 238, 0.2);
}
.batch-tab[data-tab="running"].is-active .batch-tab-count {
  background: rgba(103, 232, 249, 0.35);
  color: #083344;
}

.batch-tab[data-tab="success"].is-active {
  background: linear-gradient(180deg, rgba(16, 185, 129, 0.38) 0%, rgba(5, 122, 85, 0.12) 100%);
  box-shadow: inset 0 -3px 0 0 #34d399, 0 -8px 28px rgba(52, 211, 153, 0.18);
}
.batch-tab[data-tab="success"].is-active .batch-tab-count {
  background: rgba(167, 243, 208, 0.4);
  color: #064e3b;
}

.batch-tab[data-tab="failed"].is-active {
  background: linear-gradient(180deg, rgba(244, 63, 94, 0.38) 0%, rgba(159, 18, 57, 0.12) 100%);
  box-shadow: inset 0 -3px 0 0 #fb7185, 0 -8px 28px rgba(251, 113, 133, 0.2);
}
.batch-tab[data-tab="failed"].is-active .batch-tab-count {
  background: rgba(254, 205, 211, 0.4);
  color: #881337;
}

.batch-tabpanel {
  padding: 0;
}

.batch-failed-bulk {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 14px;
  padding: 10px 14px 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.07);
  background: rgba(244, 63, 94, 0.06);
}

.batch-failed-bulk-hint {
  font-size: 12px;
  line-height: 1.35;
  max-width: min(640px, 100%);
}

.batch-table-wrap {
  margin-top: 0;
  border: none;
  border-radius: 0;
  background: rgba(0, 0, 0, 0.2);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* Server-side pagination bar below the session table. */
.batch-pager {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 14px;
  padding: 10px 14px;
  border-top: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.02);
}
.batch-pager:empty {
  display: none;
}
.batch-pager-info {
  font-size: 12px;
}
.batch-pager-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}
.batch-pager-controls button {
  padding: 6px 10px;
  font-size: 12px;
}
.batch-pager-page {
  font-size: 12px;
  color: var(--muted);
  padding: 0 6px;
  white-space: nowrap;
}
.batch-pager-size {
  padding: 6px 8px;
  font-size: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.25);
  color: inherit;
}

/* "Selected N" indicator — the cross-page selection size. */
.batch-selected-count {
  font-size: 12px;
  white-space: nowrap;
}
.batch-selected-count #selectedCount {
  color: #c7d2f0;
  font-weight: 600;
}

.batch-ui-root .batch-table th {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.07) 0%, rgba(255, 255, 255, 0.02) 100%);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: rgba(199, 210, 240, 0.88);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.batch-ui-root .batch-table tr:hover td {
  background: rgba(99, 102, 241, 0.07);
}
.batch-ui-root .batch-table tr:hover td.batch-actions-cell {
  background: linear-gradient(90deg, rgba(12, 18, 32, 0) 0%, rgba(22, 30, 52, 0.98) 12px, rgba(22, 30, 52, 0.99) 100%);
}

.batch-table th,
.batch-table td {
  font-size: 12px;
  vertical-align: top;
}

/* Long error text: scroll in-cell so Actions stay visible; sticky Actions on horizontal scroll. */
.batch-ui-root .batch-table .batch-status-cell {
  max-width: min(520px, 52vw);
  word-wrap: break-word;
}

.batch-ui-root .batch-table .batch-row-error {
  max-height: 160px;
  overflow: auto;
  margin-top: 6px;
  padding: 8px 10px;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.38);
  border: 1px solid rgba(255, 255, 255, 0.08);
  font-size: 11px;
  line-height: 1.4;
  word-break: break-word;
}

.batch-ui-root .batch-table th.batch-actions-col,
.batch-ui-root .batch-table td.batch-actions-cell {
  position: sticky;
  right: 0;
  z-index: 2;
  min-width: 200px;
  width: 200px;
  vertical-align: top;
  background: linear-gradient(90deg, rgba(12, 18, 32, 0) 0%, rgba(15, 23, 42, 0.97) 12px, rgba(15, 23, 42, 0.98) 100%);
  box-shadow: -10px 0 18px -10px rgba(0, 0, 0, 0.55);
}

.batch-ui-root .batch-table thead th.batch-actions-col {
  z-index: 3;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.09) 0%, rgba(255, 255, 255, 0.03) 100%),
    linear-gradient(90deg, rgba(17, 26, 44, 0) 0%, rgba(17, 26, 44, 0.98) 14px, rgba(17, 26, 44, 1) 100%);
}

.batch-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.batch-actions button {
  padding: 6px 10px;
  font-size: 12px;
  border-radius: 8px;
  transition: transform 0.1s ease, filter 0.15s ease;
}
.batch-actions button:hover:not(:disabled) {
  filter: brightness(1.08);
}
.batch-actions button:active:not(:disabled) {
  transform: scale(0.97);
}

@media (max-width: 720px) {
  .grid { grid-template-columns: 1fr; }
}

@media (max-width: 640px) {
  .batch-ui-root .batch-tab {
    font-size: 10px;
    padding: 12px 6px 14px;
    letter-spacing: 0.02em;
  }
  .batch-ui-root .batch-tab-count {
    margin-left: 4px;
    padding: 1px 5px;
    font-size: 10px;
  }
}

