:root {
  --bg: #0a0a0a;
  --bg-elev: #121212;
  --bg-card: #161616;
  --border: #1f1f1f;
  --border-strong: #2a2a2a;
  --text: #f5f5f5;
  --text-muted: #9a9a9a;
  --text-dim: #6a6a6a;
  --accent: #f5a524;
  --accent-strong: #ffb734;
  --accent-soft: rgba(245, 165, 36, 0.12);
  --danger: #ff5a5a;
  --radius: 12px;
  --shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
  --font: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-strong); }

/* ---------- Brand ---------- */
.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}
.brand-mark {
  width: 36px; height: 36px;
  display: grid; place-items: center;
  border-radius: 8px;
  background: var(--accent);
  color: #0a0a0a;
  font-weight: 800;
  letter-spacing: 0.5px;
  font-size: 12px;
}
.brand-text { display: flex; flex-direction: column; line-height: 1; }
.brand-title {
  font-weight: 800;
  letter-spacing: 2px;
  font-size: 13px;
  color: var(--text);
}
.brand-subtitle {
  font-weight: 600;
  letter-spacing: 2px;
  font-size: 10px;
  color: var(--text-muted);
  margin-top: 2px;
}
.brand-sm .brand-mark { width: 30px; height: 30px; font-size: 11px; }

/* ---------- Auth ---------- */
.auth-body {
  min-height: 100vh;
  background:
    radial-gradient(900px 500px at 20% -10%, rgba(245, 165, 36, 0.08), transparent 60%),
    radial-gradient(700px 400px at 100% 100%, rgba(245, 165, 36, 0.06), transparent 60%),
    var(--bg);
}
.auth-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.auth-card {
  width: 100%;
  max-width: 420px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
  box-shadow: var(--shadow);
}
.auth-title {
  margin: 24px 0 4px;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.01em;
}
.auth-subtitle {
  margin: 0 0 24px;
  color: var(--text-muted);
  font-size: 14px;
}
.auth-form { display: flex; flex-direction: column; gap: 14px; }
.auth-foot {
  margin-top: 20px;
  font-size: 12px;
  color: var(--text-dim);
  text-align: center;
}

/* ---------- Inputs ---------- */
.field { display: flex; flex-direction: column; gap: 6px; }
.field-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 0.4px;
  text-transform: uppercase;
}
.input {
  width: 100%;
  background: #0e0e0e;
  border: 1px solid var(--border-strong);
  color: var(--text);
  padding: 12px 14px;
  border-radius: 10px;
  font-size: 15px;
  font-family: inherit;
  transition: border-color 120ms ease, box-shadow 120ms ease, background 120ms ease;
}
.input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
  background: #0a0a0a;
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 18px;
  border-radius: 999px;
  border: 1px solid transparent;
  font-weight: 600;
  font-size: 14px;
  letter-spacing: 0.2px;
  cursor: pointer;
  font-family: inherit;
  transition: transform 80ms ease, background 120ms ease, border-color 120ms ease, color 120ms ease;
}
.btn:active { transform: translateY(1px); }
.btn-primary {
  background: var(--accent);
  color: #0a0a0a;
}
.btn-primary:hover { background: var(--accent-strong); }
.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border-color: var(--border-strong);
}
.btn-ghost:hover { color: var(--text); border-color: var(--text-dim); }
.btn-regen {
  background: #ff8a4c;
  color: #1a0d05;
  border-color: transparent;
}
.btn-regen:hover { background: #ff7733; }

.domains-status {
  font-size: 13px;
  font-weight: 600;
  padding: 4px 12px;
  border-radius: 999px;
  margin-right: auto;
}
.domains-status-ok {
  background: rgba(80, 200, 120, 0.12);
  color: #6eda94;
  border: 1px solid rgba(80, 200, 120, 0.3);
}
.domains-status-bad {
  background: rgba(255, 90, 90, 0.10);
  color: #ffb0b0;
  border: 1px solid rgba(255, 90, 90, 0.3);
}

.source-regen {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(80, 200, 120, 0.12);
  color: #6eda94;
  border: 1px solid rgba(80, 200, 120, 0.3);
  font-size: 12px;
  font-weight: 600;
  cursor: help;
}

/* ---------- Alerts ---------- */
.alert {
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 14px;
  margin-bottom: 12px;
}
.alert-error {
  background: rgba(255, 90, 90, 0.08);
  border: 1px solid rgba(255, 90, 90, 0.35);
  color: #ffb0b0;
}
.alert-warning {
  background: rgba(255, 184, 77, 0.08);
  border: 1px solid rgba(255, 184, 77, 0.35);
  color: #ffd9a3;
}
.alert-success {
  background: rgba(110, 220, 130, 0.08);
  border: 1px solid rgba(110, 220, 130, 0.35);
  color: #b5e8c1;
}

/* ---------- Topbar ---------- */
.topbar {
  border-bottom: 1px solid var(--border);
  background: rgba(10, 10, 10, 0.8);
  backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 14px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.topnav {
  display: flex;
  align-items: center;
  gap: 14px;
}
.who { color: var(--text-muted); font-size: 13px; }
.who strong { color: var(--text); font-weight: 600; }
.inline-form { margin: 0; }

/* ---------- Page / Dashboard ---------- */
.page {
  max-width: 1200px;
  margin: 0 auto;
  padding: 48px 24px 80px;
}
.hero h1 {
  font-size: 34px;
  margin: 0 0 8px;
  letter-spacing: -0.02em;
  font-weight: 700;
}
.accent { color: var(--accent); }
.lede { color: var(--text-muted); font-size: 16px; margin: 0 0 36px; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
}
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  min-height: 140px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}
.card-accent {
  border-color: rgba(245, 165, 36, 0.5);
  background: linear-gradient(180deg, rgba(245, 165, 36, 0.08), var(--bg-card));
}
.card-label {
  font-size: 12px;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  color: var(--text-muted);
}
.card-value {
  font-size: 32px;
  font-weight: 700;
  letter-spacing: -0.01em;
  margin-top: 8px;
}
.card-foot {
  color: var(--text-dim);
  font-size: 13px;
  margin-top: 8px;
}

.page-head { display: flex; align-items: flex-end; justify-content: space-between; margin-bottom: 24px; gap: 24px; }
.page-head h1 { margin: 0; }
.page-narrow { max-width: 760px; }
.table { width: 100%; border-collapse: collapse; background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.table th, .table td { padding: 12px 16px; text-align: left; border-bottom: 1px solid var(--border); }
.table thead th { font-size: 12px; letter-spacing: 0.5px; text-transform: uppercase; color: var(--text-muted); background: var(--bg-elev); }
.table tbody tr:last-child td { border-bottom: none; }
.table .link { color: var(--text); font-weight: 600; }
.table .link:hover { color: var(--accent); }
.table .dim { color: var(--text-dim); font-size: 13px; }
.table .truncate { max-width: 400px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.empty { color: var(--text-muted); padding: 32px; text-align: center; background: var(--bg-card); border: 1px dashed var(--border-strong); border-radius: var(--radius); }
.navlink { color: var(--text-muted); padding: 6px 10px; border-radius: 8px; font-size: 13px; font-weight: 600; }
.navlink:hover { color: var(--text); background: var(--bg-elev); }
.panel { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); padding: 24px; margin-bottom: 24px; }
.panel h2 { margin: 0 0 16px; font-size: 18px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.panel-head h2 { margin: 0; }
.checklist { display: flex; flex-direction: column; gap: 8px; }
.checklist-item { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; cursor: pointer; }
.checklist-item:hover { border-color: var(--border-strong); }
.checklist-item input { width: 18px; height: 18px; accent-color: var(--accent); }
.form-stack { display: flex; flex-direction: column; gap: 16px; }
.fieldset { border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; }
.fieldset legend { padding: 0 8px; color: var(--text-muted); font-size: 12px; letter-spacing: 0.5px; text-transform: uppercase; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.actions { display: flex; gap: 12px; justify-content: flex-end; margin-top: 8px; }
.pill { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; border: 1px solid var(--border-strong); color: var(--text-muted); }
.pill-draft { background: rgba(245,165,36,0.08); color: var(--accent); border-color: rgba(245,165,36,0.4); }
.pill-purchased { background: rgba(80,200,120,0.08); color: #7edc9d; border-color: rgba(80,200,120,0.3); }
.pill-csv_ready { background: rgba(80,200,255,0.08); color: #7ec8ff; border-color: rgba(80,200,255,0.3); }
.pill-completed { background: rgba(80,200,120,0.12); color: #7edc9d; border-color: rgba(80,200,120,0.5); }

.summary-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin: 8px 0; }
.stat { background: var(--bg-elev); border: 1px solid var(--border); border-radius: 10px; padding: 14px 16px; }
.stat-label { font-size: 11px; letter-spacing: 0.5px; text-transform: uppercase; color: var(--text-muted); }
.stat-value { font-size: 24px; font-weight: 700; margin-top: 4px; }
.stat-accent { border-color: rgba(245,165,36,0.5); background: linear-gradient(180deg, rgba(245,165,36,0.08), var(--bg-elev)); }
.stat-accent .stat-value { color: var(--accent); }
@media (max-width: 800px) { .summary-grid { grid-template-columns: repeat(2, 1fr); } }

.test-row { display: flex; align-items: center; gap: 14px; margin-top: 8px; }
.test-result { font-size: 13px; color: var(--text-muted); font-weight: 600; }
.test-result-pending { color: var(--accent); }
.test-result-ok { color: #7edc9d; }
.test-result-fail { color: #ffb0b0; }

/* ---------- Checklist row with edit button ---------- */
.checklist-row { display: flex; align-items: center; gap: 8px; }
.checklist-row .checklist-item { flex: 1; }
.btn-sm { padding: 6px 12px; font-size: 12px; }

/* ---------- Modal ---------- */
.modal {
  display: none;
  position: fixed; inset: 0;
  z-index: 100;
  align-items: center; justify-content: center;
  padding: 24px;
}
.modal.open { display: flex; }
.modal-backdrop {
  position: absolute; inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
}
.modal-panel {
  position: relative;
  background: var(--bg-elev);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  width: 100%;
  max-width: 640px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 24px;
}
.modal-panel-sm { max-width: 440px; }
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 16px;
}
.modal-head h3 { margin: 0; font-size: 18px; }
.modal-close {
  background: transparent; border: none; color: var(--text-muted);
  font-size: 24px; line-height: 1; cursor: pointer; padding: 4px 10px;
  border-radius: 8px;
}
.modal-close:hover { color: var(--text); background: var(--bg-card); }

/* ---------- Password reveal ---------- */
.input-group { position: relative; display: block; }
.input-group .input { padding-right: 72px; width: 100%; }
.reveal-btn {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  background: transparent; border: none; color: var(--text-muted);
  font-size: 12px; font-weight: 600; cursor: pointer; padding: 6px 10px;
  border-radius: 6px; font-family: inherit; letter-spacing: 0.3px;
}
.reveal-btn:hover { color: var(--text); background: var(--bg-card); }

/* ---------- Progress cell ---------- */
.progress { display: flex; flex-direction: column; gap: 6px; min-width: 140px; }
.progress-count { font-size: 12px; font-weight: 600; color: var(--text); letter-spacing: 0.2px; }
.progress-count .dim { font-weight: 500; margin-left: 4px; }
.progress-track { height: 4px; background: var(--border); border-radius: 999px; overflow: hidden; }
.progress-fill  { height: 100%; background: var(--accent); border-radius: 999px; transition: width 200ms ease; }
.progress-complete .progress-fill { background: #7edc9d; }
.progress-complete .progress-count { color: #7edc9d; }

/* ---------- Sortable + selectable table ---------- */
.col-check { width: 32px; }
.row-check, #select-all { width: 16px; height: 16px; accent-color: var(--accent); cursor: pointer; }
.sortable-col { cursor: pointer; user-select: none; }
.sortable-col:hover { color: var(--text); }
.sort-ind { display: inline-block; margin-left: 4px; color: var(--accent); font-weight: 700; }
.col-row-action { width: 32px; text-align: right; }
.col-row-actions { width: 84px; text-align: right; white-space: nowrap; }
.col-csv-download { width: 120px; white-space: nowrap; }
.csv-filename { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; word-break: break-all; }
.row-delete, .row-edit {
  background: transparent; border: none; color: var(--text-dim);
  font-size: 16px; line-height: 1; cursor: pointer;
  padding: 4px 8px; border-radius: 6px;
  font-family: inherit;
}
.row-delete:hover { color: #ffb0b0; background: rgba(255, 90, 90, 0.08); }
.row-edit:hover   { color: var(--accent); background: rgba(245,165,36,0.08); }
.row-delete { font-size: 18px; }

.row-unavailable td { background: rgba(255, 90, 90, 0.06); }
.row-unavailable td:nth-child(2) { color: #ffb0b0; font-weight: 600; }

.btn[disabled] { opacity: 0.45; cursor: not-allowed; pointer-events: none; }
.hint { font-size: 12px; align-self: center; }

.domains-actions {
  display: flex; align-items: center; justify-content: flex-end;
  margin-top: 12px; gap: 14px;
}
.domains-actions-right { display: flex; gap: 12px; }
.floating-bar {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  display: inline-flex; align-items: center; gap: 12px;
  padding: 8px 8px 8px 18px;
  background: var(--bg-elev);
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.5);
  font-size: 13px; color: var(--text);
  z-index: 100;
  animation: floating-bar-in 140ms ease-out;
}
.floating-bar[hidden] { display: none; }
.floating-bar-count { color: var(--text-muted); }
.floating-bar-count strong { color: var(--text); font-weight: 700; }
.floating-bar-sep { width: 1px; height: 22px; background: var(--border-strong); }
.floating-bar-btn {
  background: transparent;
  border: 1px solid var(--border-strong);
  color: var(--text-muted);
  font-family: inherit; font-size: 13px; font-weight: 600;
  padding: 8px 16px; border-radius: 999px;
  cursor: pointer;
  transition: background 120ms ease, border-color 120ms ease, color 120ms ease;
}
.floating-bar-btn:hover { color: var(--text); border-color: var(--text-dim); }
.floating-bar-btn-danger {
  background: rgba(255, 90, 90, 0.12);
  border-color: rgba(255, 90, 90, 0.4);
  color: #ffb0b0;
}
.floating-bar-btn-danger:hover {
  background: rgba(255, 90, 90, 0.22);
  border-color: var(--danger);
  color: #ffd0d0;
}
@keyframes floating-bar-in {
  from { opacity: 0; transform: translate(-50%, 8px); }
  to   { opacity: 1; transform: translate(-50%, 0); }
}
.notice-info {
  margin-top: 12px; padding: 12px 14px;
  background: rgba(80, 200, 255, 0.06);
  border: 1px solid rgba(80, 200, 255, 0.25);
  border-radius: var(--radius);
  color: var(--text); font-size: 13px; line-height: 1.5;
}
.notice-info strong { color: #7ec8ff; }
.bulk-inline { display: inline-flex; align-items: center; gap: 10px; font-size: 13px; }
.linkish {
  background: transparent; border: none; color: #ffb0b0;
  cursor: pointer; font-size: 13px; font-weight: 600; font-family: inherit;
  padding: 4px 8px; border-radius: 6px;
}
.linkish:hover { color: #ff7272; background: rgba(255, 90, 90, 0.08); }

.kw-form { margin-bottom: 20px; padding: 16px; background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); }
.kw-math-table summary::marker { color: var(--text-muted); }
.kw-math-table table { max-width: 260px; margin-bottom: 12px; }

/* ---------- Signature Generator ---------- */

.config-list { margin: 4px 0 0; padding-left: 16px; font-size: 13px; }
.config-list li { margin: 4px 0; }
.config-list code {
  background: #0a0a0a;
  padding: 1px 6px;
  border-radius: 3px;
  font-family: ui-monospace, monospace;
  font-size: 12px;
}

.checkbox-inline {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: #ccc;
  margin: 8px 0;
}

/* Structure cards on the new-run form */
.structure-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 12px;
}
.structure-card {
  display: block;
  background: rgba(255,255,255,0.03);
  border: 1px solid #2a2a2a;
  border-radius: 8px;
  padding: 12px;
  cursor: pointer;
}
.structure-card input[type=checkbox] { margin-right: 6px; }
.structure-card .structure-name {
  font-size: 12px;
  letter-spacing: 0.04em;
  color: #aaa;
  margin-bottom: 8px;
}
.structure-card .structure-preview {
  font-family: -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
  font-size: 12px;
  line-height: 1.5;
  color: #ddd;
  white-space: normal;
  margin: 0;
}

/* Sample cards on the run page */
.sample-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 12px;
}
.sample {
  background: rgba(255,255,255,0.02);
  border: 1px solid #2a2a2a;
  border-radius: 6px;
  padding: 12px 14px;
}
.sample .who { font-size: 11px; color: #5aa6ff; margin-bottom: 4px; }
.sample .tpl { font-size: 10px; color: #888; margin-bottom: 8px; letter-spacing: 0.04em; }
.sample-body {
  font-family: -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
  font-size: 12px;
  line-height: 1.5;
  color: #ddd;
}
.sample-body p { margin: 0; }

/* Progress bar + per-account list */
.progress-bar {
  height: 8px;
  background: #1a1a1a;
  border-radius: 4px;
  overflow: hidden;
  margin: 8px 0 12px;
}
.progress-bar .fill {
  height: 100%;
  background: linear-gradient(90deg, #2db862, #5aa6ff);
  transition: width 0.3s;
}
.progress-stats { font-size: 12px; color: #aaa; }

.accounts-list {
  font-size: 12px;
  max-height: 300px;
  overflow-y: auto;
  border: 1px solid #2a2a2a;
  border-radius: 4px;
}
.acct-row {
  display: flex;
  justify-content: space-between;
  padding: 5px 10px;
  border-bottom: 1px solid #1a1a1a;
}
.acct-row:last-child { border-bottom: none; }

.badge {
  font-size: 10px;
  padding: 1px 7px;
  border-radius: 9px;
}
.badge-pending  { background: #2a2a2a; color: #aaa; }
.badge-patched  { background: #1a3a2a; color: #5aff8e; }
.badge-failed   { background: #3a1a1a; color: #ff5a5a; }
.badge-skipped  { background: #2a2a1a; color: #ffc850; }

/* Pills for run status (extends existing .pill from styles.css) */
.pill-preview    { background: #1e3a5a; color: #5aa6ff; }
.pill-applying   { background: #3a3a1a; color: #ffc850; }
.pill-failed     { background: #3a1a1a; color: #ff5a5a; }
.pill-tag        { background: rgba(150, 110, 220, 0.12); color: #c8a8f5; border-color: rgba(150, 110, 220, 0.4); }

/* Signatures panel head with two stacked actions (Edit Signature Settings + Generate). */
.panel-head-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

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

/* Whole-row click target for table rows that link to a detail page. */
tr.row-link { cursor: pointer; }
tr.row-link:hover { background: rgba(255,255,255,0.03); }

