:root {
  color-scheme: dark;

  /* Base neutrals -- 80% of the UI lives here */
  --bg: #0A0B0F;        /* Obsidian: page background */
  --bg-deep: #05060A;   /* header/nav/toast: a shade deeper for subtle layering */
  --surface: #14161D;   /* Graphite: cards, modals, panels */
  --surface-alt: #1B1E27; /* one step lighter than surface, for hover states */
  --border: #2A2D38;    /* Gunmetal: borders / dividers */
  --text: #F2EFE8;      /* Ivory: primary text */
  --muted: #8A8D98;     /* Ash: muted text */
  --on-accent: #0A0B0F; /* dark glyph color used on top of platinum/cyan/success fills */

  /* Platinum -- primary accent. Sparingly: CTAs, key numbers, thin borders, logo. */
  --platinum: #D4D7DE;
  --platinum-light: #EDEEF2; /* hover/highlight */
  --platinum-tint: rgba(212, 215, 222, 0.14);

  /* Cyan -- secondary accent. Even more sparingly: active/live states, links, focus. */
  --cyan: #3DD6F5;
  --cyan-tint: rgba(61, 214, 245, 0.14);

  /* Status colors, dark-theme tuned */
  --success: #34C77B;
  --success-tint: rgba(52, 199, 123, 0.14);
  --danger: #E5484D;
  --danger-dark: #C93B40;
  --danger-tint: rgba(229, 72, 77, 0.14);

  --radius: 12px;
  --shadow: 0 2px 10px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 20px 50px rgba(0, 0, 0, 0.55);
  --font-body: "Space Grotesk", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-display: "Syne", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.45;
  background: var(--bg);
  color: var(--text);
}

h1 { font-family: var(--font-display); font-weight: 700; font-size: 1.4rem; margin: 0; color: var(--text); letter-spacing: -0.01em; }
h2 { font-family: var(--font-display); font-weight: 600; font-size: 1.25rem; margin: 0 0 0.75rem; color: var(--text); }
h3 { font-size: 1.05rem; margin: 0; color: var(--text); }
p { margin: 0; }

.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.text-red { color: var(--danger); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

:focus-visible { outline: 2px solid var(--cyan); outline-offset: 2px; }

/* Dark scrollbars (WebKit/Blink) */
::-webkit-scrollbar { width: 12px; height: 12px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 999px; border: 3px solid var(--bg); }
::-webkit-scrollbar-thumb:hover { background: var(--surface-alt); }

/* ---------- Buttons ---------- */
button, summary.secondary {
  font: inherit;
  font-weight: 600;
  font-size: 0.95rem;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 0.6rem 1.05rem;
  min-height: 42px;
  background: var(--platinum);
  color: var(--on-accent);
  cursor: pointer;
  transition: background-color 0.12s ease, transform 0.05s ease;
}
button:hover { background: var(--platinum-light); }
button:active { transform: translateY(1px); }
button:disabled { background: var(--border); color: var(--muted); cursor: not-allowed; }
button.secondary, summary.secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
button.secondary:hover, summary.secondary:hover { background: var(--surface-alt); }
button.danger { background: var(--danger); color: var(--text); }
button.danger:hover { background: var(--danger-dark); }
button.link { background: none; color: var(--cyan); padding: 0.15rem 0.4rem; min-height: 0; font-size: 0.82rem; }
button.link:hover { background: var(--cyan-tint); }

/* ---------- Sign in ---------- */
.brand-logo {
  font-family: var(--font-display); font-weight: 800; letter-spacing: 0.04em;
  color: var(--platinum); white-space: nowrap;
}
.brand-logo-accent { color: var(--cyan); }
.brand-logo-lg { font-size: 1.9rem; margin: 0 auto 1rem; text-align: center; }
.brand { display: flex; align-items: center; gap: 0.75rem; }
.brand .brand-logo { font-size: 1.15rem; flex-shrink: 0; }
.header-subtitle { margin-top: 0.1rem; font-size: 0.82rem; color: var(--muted); }

#login-screen {
  min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 1rem;
  background: radial-gradient(circle at top, rgba(212, 215, 222, 0.07) 0%, var(--bg-deep) 55%);
}
.login-box { background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 2.5rem 2rem; width: 100%; max-width: 360px; text-align: center; box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5); }
.login-box h1 { font-size: 1.6rem; }
.login-box .muted { margin-top: 0.4rem; }
.login-box form { display: flex; flex-direction: column; gap: 0.75rem; margin-top: 1.5rem; }
.error-text { color: var(--danger); min-height: 1.3em; margin-top: 0.75rem; font-size: 0.92rem; }

input[type="text"], input[type="number"], input[type="password"], select {
  font: inherit; font-weight: 400; padding: 0.7rem 0.8rem; min-height: 44px;
  border: 1px solid var(--border); border-radius: 8px; color: var(--text); background: var(--surface); width: 100%;
  transition: border-color 0.12s ease, box-shadow 0.12s ease;
}
input:focus, select:focus { outline: none; border-color: var(--cyan); box-shadow: 0 0 0 3px var(--cyan-tint); }

/* ---------- App shell ---------- */
header {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: 0.9rem 1.75rem; background: var(--bg-deep); border-bottom: 1px solid var(--platinum);
}
header h1 { color: var(--text); }
header .secondary { background: transparent; border-color: rgba(242, 239, 232, 0.22); color: var(--text); }
header .secondary:hover { background: rgba(242, 239, 232, 0.08); }

main { padding: 1.5rem 1.75rem 4rem; max-width: 1200px; margin: 0 auto; }

/* ---------- Navbar ---------- */
.main-nav {
  display: flex; gap: 0.25rem; padding: 0 1.75rem; background: var(--bg-deep);
  border-bottom: 1px solid var(--border);
}
.nav-link {
  background: none; border: none; border-radius: 0; color: rgba(242, 239, 232, 0.6);
  padding: 0.75rem 1.1rem; min-height: 0; box-shadow: none; border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.nav-link:hover { color: var(--text); background: rgba(242, 239, 232, 0.05); }
.nav-link.is-active { color: var(--cyan); border-bottom-color: var(--cyan); }

/* ---------- Status banner ---------- */
.status-banner {
  display: flex; align-items: center; gap: 0.9rem; padding: 0.9rem 1.1rem; margin-bottom: 1.75rem;
  border-radius: var(--radius); border: 1px solid var(--border); background: var(--surface); box-shadow: var(--shadow);
}
.status-icon {
  width: 34px; height: 34px; border-radius: 50%; flex-shrink: 0; display: grid; place-items: center;
  font-weight: 700; color: var(--on-accent); background: var(--muted);
}
.status-text { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.status-text .muted { font-size: 0.88rem; }
.status-banner.is-ok { background: var(--success-tint); border-color: rgba(52, 199, 123, 0.3); }
.status-banner.is-ok .status-icon { background: var(--success); }
.status-banner.is-warn { background: var(--platinum-tint); border-color: rgba(212, 215, 222, 0.3); }
.status-banner.is-warn .status-icon { background: var(--platinum); }
.status-banner.is-bad { background: var(--danger-tint); border-color: rgba(229, 72, 77, 0.3); }
.status-banner.is-bad .status-icon { background: var(--danger); }

/* ---------- Toolbar ---------- */
.toolbar { display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem; margin-bottom: 1.25rem; flex-wrap: wrap; }
.page-title { margin: 0; }
.page-sub { margin-top: 0.2rem; max-width: 560px; }
.toolbar-actions { display: flex; gap: 0.6rem; }

.loading-state { text-align: center; padding: 3rem 1rem; color: var(--muted); }

/* ---------- Ad cards ---------- */
.rotation-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(360px, 1fr)); gap: 1.25rem; align-items: start; }
.rotation-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 1.15rem 1.25rem 1.25rem; display: flex; flex-direction: column; gap: 1rem;
}
.card-head { display: flex; justify-content: space-between; gap: 0.75rem; align-items: flex-start; }
.card-title { min-width: 0; }
.card-title h3 { overflow-wrap: anywhere; }
.card-section + .card-section { border-top: 1px solid var(--border); padding-top: 1rem; }

.badge { display: inline-block; padding: 0.25rem 0.7rem; border-radius: 999px; font-size: 0.8rem; font-weight: 700; white-space: nowrap; }
.badge-green { background: var(--cyan-tint); color: var(--cyan); }
.badge-red { background: var(--danger-tint); color: var(--danger); white-space: normal; text-align: right; }
.badge-grey { background: rgba(138, 141, 152, 0.14); color: var(--muted); }

.mini-label { font-size: 0.74rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); margin-bottom: 0.3rem; }

/* Automatic switching toggle -- "on" reads as an active/live state, so cyan */
.auto-row { display: flex; align-items: center; gap: 0.85rem; }
.auto-title { display: block; }
.switch { position: relative; display: inline-block; width: 52px; height: 30px; flex-shrink: 0; cursor: pointer; }
.switch input { position: absolute; opacity: 0; inset: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; z-index: 1; }
.slider { position: absolute; inset: 0; background: var(--border); border-radius: 999px; transition: background-color 0.15s ease; }
.slider::before {
  content: ""; position: absolute; width: 24px; height: 24px; left: 3px; top: 3px; background: var(--text);
  border-radius: 50%; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4); transition: transform 0.15s ease;
}
.switch input:checked + .slider { background: var(--cyan); }
.switch input:checked + .slider::before { transform: translateX(22px); }
.switch input:focus-visible + .slider { outline: 2px solid var(--cyan); outline-offset: 2px; }
.switch input:disabled + .slider { opacity: 0.6; }

/* Progress -- steady fill in platinum, "ready now" moment pulses cyan */
.progress-label { display: flex; justify-content: space-between; gap: 0.5rem; margin-bottom: 0.4rem; font-size: 0.92rem; flex-wrap: wrap; }
.progress { height: 10px; background: var(--border); border-radius: 999px; overflow: hidden; }
.progress-bar { height: 100%; background: var(--platinum); border-radius: 999px; transition: width 0.4s ease; }
.progress-bar.is-due { background: var(--cyan); }

/* Links */
.links-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.link-code {
  display: inline-block; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.85rem; font-weight: 600;
  background: var(--platinum-tint); color: var(--text); border: 1px solid rgba(212, 215, 222, 0.3); border-radius: 6px;
  padding: 0.15rem 0.5rem; overflow-wrap: anywhere;
}
.raw-link { margin-top: 0.4rem; font-size: 0.82rem; }
.raw-link summary { cursor: pointer; color: var(--cyan); font-weight: 600; }
.raw-link code {
  display: block; margin-top: 0.4rem; padding: 0.5rem; background: var(--surface-alt); border: 1px solid var(--border); border-radius: 6px;
  color: var(--text); font-size: 0.78rem; word-break: break-all; user-select: all;
}

/* Last check */
.last-check { font-size: 0.92rem; }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 0.3rem; vertical-align: baseline; }
.dot-green { background: var(--success); }
.dot-grey { background: var(--muted); }
.dot-red { background: var(--danger); }
.problem-text { margin-top: 0.4rem; padding: 0.55rem 0.7rem; background: var(--danger-tint); color: var(--danger); border-radius: 8px; font-size: 0.86rem; overflow-wrap: anywhere; }

/* Actions */
.card-actions { display: flex; gap: 0.6rem; flex-wrap: wrap; align-items: center; }
.card-actions .btn-switch { flex: 1 1 100%; }
.card-actions .btn-verify { flex: 1 1 auto; }

details.menu { position: relative; }
details.menu > summary { list-style: none; display: inline-flex; align-items: center; user-select: none; }
details.menu > summary::-webkit-details-marker { display: none; }
.menu-list {
  position: absolute; right: 0; bottom: calc(100% + 6px); z-index: 5; min-width: 220px; padding: 0.35rem;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow-lg);
  display: flex; flex-direction: column;
}
.menu-item { background: none; color: var(--text); text-align: left; font-weight: 500; border-radius: 6px; padding: 0.6rem 0.75rem; min-height: 0; }
.menu-item:hover { background: var(--surface-alt); }
.menu-danger { color: var(--danger); }
.menu-danger:hover { background: var(--danger-tint); }

/* ---------- Empty state ---------- */
.empty-state { text-align: center; padding: 3.5rem 1rem; background: var(--surface); border: 1px dashed var(--border); border-radius: var(--radius); }
.empty-state-mark {
  width: 52px; height: 52px; border-radius: 12px; margin: 0 auto 1rem;
  background: linear-gradient(135deg, var(--platinum-tint), var(--cyan-tint)); border: 2px dashed var(--platinum);
}
.empty-state h3 { margin-bottom: 0.3rem; }
.empty-state button { margin-top: 1.25rem; }

/* ---------- Modals ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(5, 6, 10, 0.72); display: flex; align-items: flex-start; justify-content: center;
  overflow-y: auto; padding: 2.5rem 1rem; z-index: 20;
}
#confirm-modal { z-index: 30; align-items: center; }
#proxies-modal, #proxy-edit-modal { z-index: 25; }
.modal {
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 1.75rem; width: 100%; max-width: 620px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.5); border-top: 3px solid var(--platinum);
}
.modal-small { max-width: 440px; }
.modal-small p { color: var(--muted); }
.modal-actions { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 0.6rem; margin-top: 1.5rem; padding-top: 1.1rem; border-top: 1px solid var(--border); }

/* Result popup */
.result-headline { display: flex; gap: 0.85rem; align-items: flex-start; padding: 0.9rem 1rem; border-radius: 10px; }
.result-headline p { margin-top: 0.25rem; font-size: 0.93rem; }
.result-icon { width: 30px; height: 30px; border-radius: 50%; flex-shrink: 0; display: grid; place-items: center; font-weight: 700; color: var(--on-accent); }
.tone-ok { background: var(--success-tint); color: var(--text); }
.tone-ok .result-icon { background: var(--success); }
.tone-error { background: var(--danger-tint); color: var(--danger); }
.tone-error .result-icon { background: var(--danger); }
.tone-info { background: var(--platinum-tint); color: var(--text); }
.tone-info .result-icon { background: var(--platinum); }
.result-links { margin-top: 1.1rem; display: flex; flex-direction: column; gap: 0.9rem; }
.result-link-label { display: block; font-size: 0.74rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); margin-bottom: 0.3rem; }
.footnote { margin-top: 1rem; font-size: 0.86rem; color: var(--muted); }

/* ---------- Form ---------- */
fieldset { border: none; padding: 0; margin: 0 0 1.4rem; min-width: 0; }
legend { font-weight: 700; font-size: 1rem; margin-bottom: 0.6rem; padding: 0; display: flex; align-items: center; gap: 0.5rem; color: var(--text); }
.step { width: 24px; height: 24px; border-radius: 50%; background: var(--platinum); color: var(--on-accent); font-size: 0.8rem; display: grid; place-items: center; }
.section-help { font-size: 0.86rem; color: var(--muted); margin-bottom: 0.75rem; }
form label { display: flex; flex-direction: column; gap: 0.3rem; font-size: 0.9rem; font-weight: 600; color: var(--text); margin-bottom: 0.9rem; }
form label em { font-weight: 400; font-style: normal; color: var(--muted); }
.hint { font-size: 0.8rem; color: var(--muted); font-weight: 400; }
.field-row { display: flex; gap: 0.75rem; }
.field-row label { flex: 1; min-width: 0; }
.checkbox-row { flex-direction: row; align-items: center; gap: 0.6rem; font-weight: 500; }
.checkbox-row input { width: 20px; height: 20px; min-height: 0; accent-color: var(--platinum); }

#validation-result { margin: 0.5rem 0; }
.callout { padding: 0.7rem 0.9rem; border-radius: 8px; font-size: 0.92rem; }
.callout-ok { background: var(--success-tint); color: var(--success); border-left: 3px solid var(--success); }
.callout-error { background: var(--danger-tint); color: var(--danger); border-left: 3px solid var(--danger); }
.issue-list { list-style: none; padding: 0; margin: 0.4rem 0; display: flex; flex-direction: column; gap: 0.35rem; font-size: 0.9rem; }
.issue-list li { padding: 0.5rem 0.7rem; border-radius: 8px; }

.fetched-row { display: flex; justify-content: space-between; align-items: center; gap: 0.75rem; padding: 0.7rem 0; border-bottom: 1px solid var(--border); }
.fetched-row:last-child { border-bottom: none; }
.fetched-row-main { min-width: 0; }
.fetched-row-actions { display: flex; gap: 0.4rem; flex-shrink: 0; }
.fetcher-controls {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 1.15rem 1.25rem 1.25rem; margin-bottom: 1.5rem;
}
.fetcher-controls .field-row { align-items: flex-end; }
.fetcher-controls #fetcher-count-input { max-width: 140px; }
.fetcher-actions { justify-content: flex-start; margin-top: 0.9rem; }

.proxy-row { display: flex; justify-content: space-between; align-items: flex-start; gap: 0.75rem; padding: 0.7rem 0; border-bottom: 1px solid var(--border); }
.proxy-row:last-child { border-bottom: none; }
.proxy-row-actions { display: flex; gap: 0.4rem; flex-shrink: 0; }
.proxy-test-slot:empty { display: none; }
.proxy-test-result { margin-top: 0.3rem; font-size: 0.85rem; font-weight: 600; }
.proxy-test-ok { color: var(--success); }
.proxy-test-fail { color: var(--danger); }
.issue-error { background: var(--danger-tint); color: var(--danger); border-left: 3px solid var(--danger); }
.issue-warning { background: var(--platinum-tint); color: var(--platinum-light); border-left: 3px solid var(--platinum); }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  max-width: min(92vw, 520px); padding: 0.8rem 1.2rem; border-radius: 10px; background: var(--surface); border: 1px solid var(--border); color: var(--text);
  font-size: 0.95rem; box-shadow: var(--shadow-lg); transition: opacity 0.2s ease, transform 0.2s ease; z-index: 40;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: var(--danger); border-color: var(--danger-dark); }

/* ---------- Small screens ---------- */
@media (max-width: 700px) {
  header { padding: 0.8rem 1rem; }
  .header-subtitle { display: none; }
  main { padding: 1rem 1rem 4rem; }
  .rotation-grid { grid-template-columns: minmax(0, 1fr); }
  .status-banner { flex-wrap: wrap; }
  .status-banner button { width: 100%; }
  .toolbar-actions { width: 100%; }
  .toolbar-actions button { flex: 1; }
  .field-row { flex-direction: column; gap: 0; }
  .links-grid { grid-template-columns: 1fr; }
  .modal { padding: 1.25rem; }
  .modal-actions button { flex: 1 1 auto; }
  .menu-list { right: auto; left: 0; }
}

.fatal-error { background: var(--danger-tint); color: var(--danger); border: 1px solid rgba(229, 72, 77, 0.3); border-left: 4px solid var(--danger); border-radius: var(--radius); padding: 0.9rem 1.1rem; margin-bottom: 1.25rem; }
.fatal-error p { margin: 0.4rem 0 0.7rem; font-size: 0.85rem; font-family: ui-monospace, Menlo, monospace; overflow-wrap: anywhere; color: var(--text); }
.build-info { text-align: center; color: var(--muted); font-size: 0.75rem; padding: 0 0 1.5rem; }

#override-modal { z-index: 30; }
#override-modal .modal { border-top-color: var(--danger); }
.override-check { display: flex; margin-top: 1.5rem !important; padding: 0.8rem 0.9rem; background: var(--danger-tint); border-radius: 8px; font-weight: 600; }
