:root {
  /* Dark is the default theme — see [data-theme="light"] below for the
     override. Set once at load from localStorage (falling back to the
     server-saved preference) by the inline script in <head>, before first
     paint, so there's no flash of the wrong theme. */
  --bg: #0f1117;
  --panel: #1a1d27;
  --border: #2c303c;
  --text: #e5e7eb;
  --muted: #8b93a3;
  --accent: #3b82f6;
  --clean: #34d399;
  --listed: #f87171;
  --unknown: #fbbf24;
  --clean-bg: rgba(52, 211, 153, 0.12);
  --listed-bg: rgba(248, 113, 113, 0.12);
  --unknown-bg: rgba(251, 191, 36, 0.12);
  --badge-clean-bg: rgba(52, 211, 153, 0.18);
  --badge-listed-bg: rgba(248, 113, 113, 0.18);
  --badge-unknown-bg: rgba(251, 191, 36, 0.18);
  --warning-bg: rgba(251, 191, 36, 0.15);
  --warning-text: #fbbf24;
  --overlay: rgba(0, 0, 0, 0.6);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
}

:root[data-theme="light"] {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --border: #e0e2e7;
  --text: #1c1e21;
  --muted: #6b7280;
  --accent: #2563eb;
  --clean: #16a34a;
  --listed: #dc2626;
  --unknown: #d97706;
  --clean-bg: #f0fdf4;
  --listed-bg: #fef2f2;
  --unknown-bg: #fffbeb;
  --badge-clean-bg: #dcfce7;
  --badge-listed-bg: #fee2e2;
  --badge-unknown-bg: #fef3c7;
  --warning-bg: #fef3c7;
  --warning-text: #92400e;
  --overlay: rgba(0, 0, 0, 0.4);
}

* { box-sizing: border-box; }

/* Form fields don't inherit page colors on their own — without this every
   input/textarea/select stays browser-default white-on-black regardless of
   theme, which clashes hard against a dark panel. */
input, textarea, select {
  background: var(--panel);
  color: var(--text);
  accent-color: var(--accent);
}
input::placeholder, textarea::placeholder { color: var(--muted); opacity: 1; }

a { color: var(--accent); }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 24px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}

header h1 { font-size: 18px; margin: 0; }

main {
  max-width: 1100px;
  margin: 24px auto;
  padding: 0 24px 60px;
  display: grid;
  gap: 20px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px 24px;
}

.panel h2 { margin: 0 0 4px; font-size: 16px; }
.panel-sub { color: var(--muted); font-size: 13px; margin-bottom: 16px; }

.icon-btn {
  background: none;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 12px;
  cursor: pointer;
  font-size: 13px;
}
.icon-btn:hover { background: var(--bg); }

.primary-btn {
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 6px;
  padding: 8px 16px;
  cursor: pointer;
  font-size: 13px;
}
.primary-btn:hover { opacity: 0.9; }
.primary-btn:disabled { opacity: 0.5; cursor: not-allowed; }

.secondary-btn {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 14px;
  cursor: pointer;
  font-size: 13px;
}
.secondary-btn:hover { background: var(--bg); }

.domain-group { margin-bottom: 18px; }
.domain-group h3 { font-size: 14px; margin: 0 0 8px; }

.blocklist-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  border-radius: 6px;
  margin-bottom: 4px;
  font-size: 13px;
}
.blocklist-row.listed { background: var(--listed-bg); }
.blocklist-row.unknown { background: var(--unknown-bg); }
.blocklist-row.clean { background: var(--clean-bg); }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
  margin-right: 8px;
  text-transform: uppercase;
}
.badge.clean { background: var(--badge-clean-bg); color: var(--clean); }
.badge.listed { background: var(--badge-listed-bg); color: var(--listed); }
.badge.unknown { background: var(--badge-unknown-bg); color: var(--unknown); }

.row-detail { color: var(--muted); flex: 1; margin: 0 12px; }
.row-name { font-weight: 500; min-width: 200px; }

.reference-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.reference-header .domain-label { font-weight: 600; font-size: 14px; }
.reference-field { margin-bottom: 12px; border: 1px solid var(--border); border-radius: 6px; padding: 10px 12px; }
.reference-field .field-label { font-weight: 500; font-size: 12px; color: var(--muted); margin-bottom: 4px; display: flex; justify-content: space-between; align-items: center; }
.reference-field .field-value { font-size: 13px; white-space: pre-wrap; word-break: break-word; }
.reference-field .field-value.empty { color: var(--muted); font-style: italic; }
.copy-btn { background: none; color: var(--text); border: 1px solid var(--border); border-radius: 4px; padding: 2px 8px; font-size: 11px; cursor: pointer; }
.copy-btn:hover { background: var(--bg); }
.copy-btn.copied { background: var(--badge-clean-bg); border-color: var(--clean); color: var(--clean); }

/* ---- settings tabs ---- */

.settings-tabs {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  border-bottom: 1px solid var(--border);
  margin: 16px 0 18px;
}
.settings-tab {
  background: none;
  color: var(--muted);
  border: 0;
  border-bottom: 2px solid transparent;
  padding: 8px 12px;
  margin-bottom: -1px;
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
}
.settings-tab:hover { color: var(--text); }
.settings-tab.active { color: var(--accent); border-bottom-color: var(--accent); }

.settings-panel { display: none; }
.settings-panel.active { display: block; }

.placeholder-help {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
  margin-bottom: 16px;
  background: var(--panel);
}
.placeholder-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.placeholder-chip {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11.5px;
  padding: 3px 8px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg);
  color: var(--accent);
  cursor: pointer;
}
.placeholder-chip:hover { border-color: var(--accent); }
.placeholder-chip.copied { background: var(--badge-clean-bg); border-color: var(--clean); color: var(--clean); }

.manual-status { display: flex; flex-direction: column; gap: 4px; margin-bottom: 14px; }
.manual-status-row {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 6px 10px; border: 1px solid var(--border); border-radius: 6px;
  font-size: 13px; cursor: pointer;
}
.manual-status-row:hover { background: var(--bg); }
.manual-status-domain { font-weight: 500; min-width: 170px; }
.manual-domain-picker { display: block; font-size: 13px; font-weight: 500; margin-bottom: 14px; }
.manual-domain-picker select {
  margin-left: 8px; padding: 6px 8px; border: 1px solid var(--border);
  border-radius: 6px; font-family: inherit; font-size: 13px;
}

.manual-field { margin-bottom: 16px; }
.manual-field label { display: block; font-weight: 500; margin-bottom: 4px; font-size: 13px; }
.manual-field textarea { width: 100%; font-family: inherit; font-size: 13px; padding: 8px; border: 1px solid var(--border); border-radius: 6px; }
.manual-field .saved-at { color: var(--muted); font-size: 11px; margin-left: 8px; }

.approval-area { text-align: center; }
.empty-state { color: var(--muted); font-size: 13px; }
.approval-area img { max-width: 100%; border: 1px solid var(--border); border-radius: 8px; margin-bottom: 16px; }
.approval-actions { display: flex; gap: 12px; justify-content: center; }
.approval-status { font-size: 13px; color: var(--muted); margin-bottom: 8px; }
.warning-banner { background: var(--warning-bg); color: var(--warning-text); padding: 10px 14px; border-radius: 6px; font-size: 13px; margin-bottom: 12px; }

.modal {
  position: fixed; inset: 0; background: var(--overlay);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 40px 20px; overflow-y: auto;
}
.modal.hidden { display: none; }
.modal-content {
  background: var(--panel); border-radius: 10px; padding: 24px 28px;
  max-width: 640px; width: 100%;
}
.modal-header { display: flex; justify-content: space-between; align-items: center; }
.modal-content h3 { margin-top: 24px; margin-bottom: 8px; font-size: 14px; }

.form-grid { display: grid; gap: 12px; }
.form-grid label { font-size: 13px; font-weight: 500; display: block; }
.form-grid input, .form-grid textarea {
  width: 100%; margin-top: 4px; padding: 8px; border: 1px solid var(--border);
  border-radius: 6px; font-family: inherit; font-size: 13px;
}

.domain-row { display: flex; align-items: center; justify-content: space-between; padding: 6px 0; border-bottom: 1px solid var(--border); font-size: 13px; }
.domain-row button { background: none; border: none; color: var(--listed); cursor: pointer; font-size: 12px; }
.add-domain-row { display: flex; gap: 8px; margin-top: 10px; }
.add-domain-row input { flex: 1; padding: 8px; border: 1px solid var(--border); border-radius: 6px; }

.blocklist-field-section { border: 1px solid var(--border); border-radius: 8px; padding: 14px 16px; margin-top: 14px; }
.blocklist-field-section .master-title { font-size: 14px; font-weight: 700; margin-bottom: 10px; }
.blocklist-field-section .field-note { color: var(--muted); font-size: 12.5px; line-height: 1.5; }
.blocklist-field-section .bf-row { margin-bottom: 10px; }
.blocklist-field-section .bf-row label { font-size: 12.5px; font-weight: 500; display: block; margin-bottom: 3px; }
.blocklist-field-section .bf-row input, .blocklist-field-section .bf-row textarea {
  width: 100%; padding: 7px 8px; border: 1px solid var(--border); border-radius: 6px;
  font-family: inherit; font-size: 13px;
}
.blocklist-field-section .bf-row input:disabled, .blocklist-field-section .bf-row textarea:disabled {
  background: var(--bg); color: var(--muted); font-style: italic;
}
.blocklist-field-section .bf-save { margin-top: 4px; }
.add-domain-row button { padding: 8px 14px; border: 1px solid var(--border); border-radius: 6px; background: var(--panel); color: var(--text); cursor: pointer; }

/* ---- stamp loader: stamping "BLACKLISTED" then erasing it, looped while checking ---- */

.stamp-loader {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 28px 0 20px;
}

.stamp-scene {
  position: relative;
  width: 240px;
  height: 150px;
  margin-top: 85px;
}

.stamp-scene .envelope {
  position: absolute;
  left: 50%;
  top: 55px;
  transform: translateX(-50%);
  width: 190px;
  height: 105px;
  background: #f8f2e3;
  border: 1px solid #d9cba3;
  border-radius: 3px;
  box-shadow: 0 6px 14px rgba(0,0,0,0.12), inset 0 0 0 1px rgba(255,255,255,0.4);
  overflow: hidden;
}

.stamp-scene .envelope::before {
  /* flap */
  content: "";
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 0;
  border-left: 95px solid transparent;
  border-right: 95px solid transparent;
  border-top: 48px solid #efe4c8;
}

.stamp-scene .envelope::after {
  /* faint address lines for realism */
  content: "";
  position: absolute;
  left: 18px; bottom: 16px; right: 60px;
  height: 2px;
  background: repeating-linear-gradient(
    to bottom, #d9cba3 0, #d9cba3 1px, transparent 1px, transparent 10px
  );
  height: 22px;
  opacity: 0.7;
}

.stamp-scene .ink-text {
  position: absolute;
  left: 50%;
  top: 62%;
  width: 108px;
  box-sizing: border-box;
  text-align: center;
  transform: translate(-50%, -50%) rotate(-5deg) scale(0.85);
  font-family: Impact, "Arial Narrow", "Arial Black", sans-serif;
  font-size: 17px;
  font-weight: 900;
  letter-spacing: 1px;
  color: #a3182a;
  border: 3px solid #a3182a;
  border-radius: 2px;
  padding: 3px 4px;
  white-space: nowrap;
  opacity: 0;
  mix-blend-mode: multiply;
  box-shadow: 0 0 0 1px rgba(163,24,42,0.3);
  animation: inkAppear 3.6s ease-in-out infinite;
  z-index: 2;
}

.stamp-scene .stamp {
  position: absolute;
  left: 50%;
  top: 0;
  width: 108px;
  transform: translate(-50%, -75px) rotate(-6deg);
  transform-origin: bottom center;
  animation: stampMove 3.6s ease-in-out infinite;
  z-index: 3;
  filter: drop-shadow(0 6px 6px rgba(0,0,0,0.25));
}

.stamp-scene .stamp-handle {
  width: 108px;
  height: 44px;
  margin: 0 auto;
  border-radius: 9px 9px 4px 4px;
  background: linear-gradient(155deg, #9c6a3f 0%, #6b4423 55%, #442a15 100%);
  box-shadow: inset -5px -6px 8px rgba(0,0,0,0.35), inset 3px 3px 5px rgba(255,255,255,0.15);
}

.stamp-scene .stamp-base {
  width: 108px;
  height: 32px;
  margin: 2px auto 0;
  border-radius: 4px;
  background: linear-gradient(180deg, #cf5252 0%, #8e1f1f 100%);
  box-shadow: inset 0 -4px 6px rgba(0,0,0,0.3), inset 0 3px 4px rgba(255,255,255,0.2);
}

.stamp-scene .impact-ring {
  position: absolute;
  left: 50%;
  top: 62%;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  border: 2px solid rgba(163,24,42,0.5);
  opacity: 0;
  animation: impactRing 3.6s ease-in-out infinite;
  z-index: 2;
}

.stamp-scene .eraser {
  position: absolute;
  left: 50%;
  top: 62%;
  width: 38px;
  height: 18px;
  transform: translate(-160px, -50%) rotate(-8deg);
  border-radius: 3px;
  background: linear-gradient(180deg, #f6b3cb 0%, #e0759e 100%);
  box-shadow: 0 3px 6px rgba(0,0,0,0.3);
  opacity: 0;
  animation: eraserSweep 3.6s ease-in-out infinite;
  z-index: 4;
}

.stamp-scene .eraser::after {
  content: "";
  position: absolute;
  left: 0; right: 0; top: 38%;
  height: 5px;
  background: #3a72b8;
  opacity: 0.9;
}

.stamp-loader-caption {
  color: var(--muted);
  font-size: 13px;
  margin: 0;
}

@keyframes stampMove {
  0%   { transform: translate(-50%, -75px) rotate(-10deg); }
  14%  { transform: translate(-50%, 15px) rotate(-5deg); }
  24%  { transform: translate(-50%, 15px) rotate(-5deg); }
  36%  { transform: translate(-50%, -75px) rotate(-10deg); }
  100% { transform: translate(-50%, -75px) rotate(-10deg); }
}

@keyframes inkAppear {
  0%, 13%   { opacity: 0; transform: translate(-50%, -50%) rotate(-5deg) scale(0.85); }
  15%       { opacity: 1; transform: translate(-50%, -50%) rotate(-5deg) scale(1.12); }
  20%       { opacity: 1; transform: translate(-50%, -50%) rotate(-5deg) scale(1); }
  58%       { opacity: 1; transform: translate(-50%, -50%) rotate(-5deg) scale(1); }
  74%       { opacity: 0; transform: translate(-50%, -50%) rotate(-5deg) scale(1); }
  100%      { opacity: 0; }
}

@keyframes impactRing {
  0%, 13%  { opacity: 0; width: 10px; height: 10px; }
  15%      { opacity: 0.8; width: 10px; height: 10px; }
  26%      { opacity: 0; width: 90px; height: 90px; }
  100%     { opacity: 0; width: 10px; height: 10px; }
}

@keyframes eraserSweep {
  0%, 56%   { opacity: 0; transform: translate(-150px, -50%) rotate(-10deg); }
  59%       { opacity: 1; transform: translate(-95px, -50%) rotate(-10deg); }
  74%       { opacity: 1; transform: translate(95px, -50%) rotate(8deg); }
  77%, 100% { opacity: 0; transform: translate(150px, -50%) rotate(8deg); }
}

/* ---- auth pages (login / first-run setup) ---- */

.hidden { display: none !important; }

.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.auth-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 32px 36px;
  max-width: 380px;
  width: 100%;
}

.auth-card h1 { font-size: 18px; margin: 0 0 6px; }
.auth-card form { display: flex; flex-direction: column; gap: 14px; margin-top: 16px; }
.auth-card label { font-size: 13px; font-weight: 500; display: block; }
.auth-card input {
  width: 100%; margin-top: 4px; padding: 9px 10px; border: 1px solid var(--border);
  border-radius: 6px; font-family: inherit; font-size: 14px;
}
.auth-card .primary-btn { padding: 10px; font-size: 14px; }

.password-field { position: relative; }
.password-field input { padding-right: 40px; }
.password-toggle {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  background: none; border: none; cursor: pointer; padding: 4px;
  display: flex; align-items: center; justify-content: center;
  color: var(--muted);
}
.password-toggle:hover { color: var(--text); }
.password-toggle svg { width: 18px; height: 18px; }

/* ---- assisted delisting: site on the left, your values on the right ---- */

.assist-body {
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;  /* each pane scrolls on its own, the page never does */
}

.assist-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.assist-split {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
  min-height: 0;  /* without this a grid child refuses to shrink and scroll */
}

.assist-pane {
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
}
.assist-left { border-right: 1px solid var(--border); }

.assist-pane-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  font-size: 12.5px;
  font-weight: 600;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.assist-pane-body { flex: 1; min-height: 0; background: var(--bg); }
.assist-scroll { overflow-y: auto; padding: 14px; }
.assist-pane-body iframe { width: 100%; height: 100%; border: 0; display: block; }

.assist-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  height: 100%;
  padding: 24px;
  text-align: center;
}

.assist-section-title {
  font-size: 13px;
  font-weight: 700;
  margin: 18px 0 4px;
}
.assist-section-title:first-child { margin-top: 0; }

.assist-field {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 9px 11px;
  margin-bottom: 9px;
  background: var(--panel);
}
.assist-field-label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
  margin-bottom: 5px;
}
.assist-field-value {
  font-size: 13px;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 150px;
  overflow-y: auto;
}
.assist-field-value.empty { color: var(--muted); font-style: italic; }

.assist-login-box {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px;
  margin-bottom: 16px;
  background: var(--panel);
}
.assist-cred-label {
  display: block;
  font-size: 12.5px;
  font-weight: 500;
  margin-bottom: 8px;
}
.assist-cred-label input {
  width: 100%;
  margin-top: 3px;
  padding: 7px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-family: inherit;
  font-size: 13px;
}

.copy-btn:disabled { opacity: 0.45; cursor: not-allowed; }

/* Stack the panes on a phone — side-by-side halves are unusable below this. */
@media (max-width: 900px) {
  .assist-split { grid-template-columns: 1fr; grid-template-rows: 45vh 1fr; }
  .assist-left { border-right: 0; border-bottom: 1px solid var(--border); }
}

