/* =============================================================================
   Admin theme — load AFTER styles.css.

   <link rel="stylesheet" href="/admin/theme.css" />

   Paint only: color, background, border, radius, shadow, font, transitions,
   focus. No display, position, width, height, margin, or overflow changes.

   Existing names (--bg, --card, --fg, --muted, --primary, …) stay valid and
   point at the scale below. html[data-theme="light"|"dark"] is set by
   applyTheme (localStorage ui_theme: light | dark | auto, plus a legacy
   adminTheme helper). "auto" follows prefers-color-scheme.
   ============================================================================= */

/* ---------- Light --------------------------------------------------------- */
:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-raised: #ffffff;
  --surface-sunken: #e7ecf4;

  --fg: #0f172a;
  --fg-muted: #3c4b63;
  --fg-subtle: #4a5c78;
  --fg-on-primary: #ffffff;

  --primary: #1d4ed8;
  --primary-hover: #1e40af;
  --primary-active: #1e3a8a;
  --primary-text: #1e40af;
  --primary-text-hover: #1e3a8a;
  --primary2: #6d28d9;
  --primary-soft: #dbe6fb;
  --on-primary-soft: #1e3a8a;

  --success: #166534;
  --success-solid: #157a3a;
  --on-success: #ffffff;
  --success-soft: #d8f3e3;
  --on-success-soft: #14532d;

  --warning: #92400e;
  --warning-solid: #b45309;
  --on-warning: #ffffff;
  --warning-soft: #fde8c0;
  --on-warning-soft: #78350f;

  --danger: #b91c1c;
  --danger-solid: #b91c1c;
  --on-danger: #ffffff;
  --danger-soft: #fde2e2;
  --on-danger-soft: #991b1b;

  --info: #0369a1;

  --border: #7e8ba2;
  --border-strong: #6d7c93;
  --focus: #1d4ed8;
  --focus-soft: rgba(29, 78, 216, 0.28);

  --overlay: rgba(15, 23, 42, 0.48);
  --scrollbar-thumb: #7e8ba2;
  --row-stripe: #f3f6fb;
  --row-hover: #e6eefb;
  --glow-1: rgba(29, 78, 216, 0.07);
  --glow-2: rgba(109, 40, 217, 0.05);

  --monitor-bg: #0f172a;
  --monitor-fg: #e8eef7;
  --monitor-border: #8aa0c0;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius: var(--radius-lg);

  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 8px 24px rgba(15, 23, 42, 0.08), 0 1px 2px rgba(15, 23, 42, 0.05);
  --shadow-lg: 0 18px 48px rgba(15, 23, 42, 0.16);
  --shadow: var(--shadow-md);

  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --space-7: 48px;

  --font-sans: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-mono: ui-monospace, "SF Mono", Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  --text-xs: 0.75rem;
  --text-sm: 0.875rem;
  --text-md: 1rem;
  --text-lg: 1.125rem;
  --text-xl: 1.25rem;
  --leading-tight: 1.3;
  --leading-normal: 1.5;
  --leading-relaxed: 1.6;

  /* Legacy names → this scale */
  --bg2: #e8edf6;
  --card: var(--surface);
  --card2: var(--surface-sunken);
  --muted: var(--fg-muted);
  --muted2: var(--fg-subtle);
  --chipBg: var(--surface-sunken);
  --chipFg: var(--fg);
  --canvas-grid: rgba(15, 23, 42, 0.14);
  --bg0: var(--bg);
  --bg1: var(--bg2);
  --surface0: var(--surface);
  --surface1: var(--surface-sunken);
  --surface2: var(--row-hover);
  --text0: var(--fg);
  --text1: var(--fg-muted);
  --text2: var(--fg-subtle);
  --accent1: var(--primary);
  --accent2: var(--primary2);
  --panel: var(--surface);
  --accent: var(--primary-text);
  --accent-soft: var(--primary-soft);
  --accent-strong: var(--primary-text);
  --text-main: var(--fg);
  --text-muted: var(--fg-muted);
  --text-primary: var(--fg);
  --text-secondary: var(--fg-muted);
  --panel-bg: var(--surface);
  --border-subtle: var(--border);
  --shadow-soft: var(--shadow-sm);

  /* Names used by inline styles but missing from styles.css */
  --card-bg: var(--surface-raised);
  --color-fg: var(--fg);
  --color-muted: var(--fg-muted);
  --color-primary: var(--primary);
  --color-bg-elevated: var(--surface-sunken);
}

/* ---------- Dark ---------------------------------------------------------- */
html[data-theme="dark"] {
  --bg: #0b1020;
  --surface: #151c2e;
  --surface-raised: #1c2538;
  --surface-sunken: #0a101c;

  --fg: #f3f6fb;
  --fg-muted: #c5d0e2;
  --fg-subtle: #a9b6cb;
  --fg-on-primary: #ffffff;

  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-active: #1e40af;
  --primary-text: #93c5fd;
  --primary-text-hover: #bfdbfe;
  --primary2: #6d28d9;
  --primary-soft: #1a3058;
  --on-primary-soft: #dbeafe;

  --success: #86efac;
  --success-solid: #157a3a;
  --on-success: #ffffff;
  --success-soft: #123524;
  --on-success-soft: #bbf7d0;

  --warning: #fcd34d;
  --warning-solid: #b45309;
  --on-warning: #ffffff;
  --warning-soft: #3a2a0c;
  --on-warning-soft: #fde68a;

  --danger: #fca5a5;
  --danger-solid: #b91c1c;
  --on-danger: #ffffff;
  --danger-soft: #3f1518;
  --on-danger-soft: #fecaca;

  --info: #7dd3fc;

  --border: #627494;
  --border-strong: #8aa0c0;
  --focus: #93c5fd;
  --focus-soft: rgba(147, 197, 253, 0.32);

  --overlay: rgba(0, 0, 0, 0.62);
  --scrollbar-thumb: #627494;
  --row-stripe: #182235;
  --row-hover: #243049;
  --glow-1: rgba(37, 99, 235, 0.16);
  --glow-2: rgba(109, 40, 217, 0.12);

  --monitor-bg: #0a101c;
  --monitor-fg: #e8eef7;
  --monitor-border: #627494;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 10px 28px rgba(0, 0, 0, 0.38);
  --shadow-lg: 0 24px 60px rgba(0, 0, 0, 0.5);
  --shadow: var(--shadow-md);

  --bg2: #10182a;
  --card: var(--surface);
  --card2: var(--surface-sunken);
  --muted: var(--fg-muted);
  --muted2: var(--fg-subtle);
  --chipBg: rgba(148, 163, 184, 0.14);
  --chipFg: var(--fg);
  --canvas-grid: rgba(138, 160, 192, 0.28);
  --bg0: var(--bg);
  --bg1: var(--bg2);
  --surface0: var(--surface);
  --surface1: var(--surface-sunken);
  --surface2: var(--row-hover);
  --text0: var(--fg);
  --text1: var(--fg-muted);
  --text2: var(--fg-subtle);
  --accent1: var(--primary);
  --accent2: var(--primary2);
  --panel: var(--surface);
  --accent: var(--primary-text);
  --accent-soft: var(--primary-soft);
  --accent-strong: var(--primary-text);
  --text-main: var(--fg);
  --text-muted: var(--fg-muted);
  --text-primary: var(--fg);
  --text-secondary: var(--fg-muted);
  --panel-bg: var(--surface);
  --border-subtle: var(--border);
  --shadow-soft: var(--shadow-sm);

  --card-bg: var(--surface-raised);
  --color-fg: var(--fg);
  --color-muted: var(--fg-muted);
  --color-primary: var(--primary);
  --color-bg-elevated: var(--surface-sunken);
}

/* ---------- Type, native controls, focus ---------------------------------- */
@font-face {
  font-family: Inter;
  src: local("Inter"), local("Inter var"), local("InterVariable");
  font-display: swap;
}

html {
  color-scheme: light;
}

html[data-theme="dark"] {
  color-scheme: dark;
}

html,
body {
  font-family: var(--font-sans);
  color: var(--fg);
  background-color: var(--bg);
}

body,
html[data-theme="dark"] body {
  background:
    radial-gradient(1000px 460px at 8% -12%, var(--glow-1), transparent 60%),
    radial-gradient(780px 400px at 100% -8%, var(--glow-2), transparent 55%),
    var(--bg);
}

html[data-theme="dark"] body::before {
  opacity: 0;
  background: none;
  animation: none;
}

::selection {
  background: var(--primary-soft);
  color: var(--on-primary-soft);
}

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

html {
  scrollbar-width: thin;
  scrollbar-color: var(--scrollbar-thumb) transparent;
}

input[type="checkbox"],
input[type="radio"] {
  accent-color: var(--primary);
}

/* ---------- App chrome ---------------------------------------------------- */
.app-shell,
html[data-theme="light"] .app-shell,
html[data-theme="dark"] .app-shell {
  background:
    radial-gradient(1000px 460px at 8% -12%, var(--glow-1), transparent 60%),
    radial-gradient(780px 400px at 100% -8%, var(--glow-2), transparent 55%),
    var(--bg);
  color: var(--fg);
}

.sidebar {
  background: var(--bg2);
  color: var(--fg);
  border-right-color: var(--border);
}

.logo-text-main,
.logo-title,
.main-title {
  color: var(--fg);
}

.logo-text-sub,
.logo-subtitle,
.main-subtitle,
.sidebar-footer {
  color: var(--fg-muted);
}

.nav-section-label {
  color: var(--fg-subtle);
}

.nav-button {
  color: var(--fg-muted);
  background: transparent;
  border-radius: var(--radius-md);
  transition: background-color 160ms ease, color 160ms ease, box-shadow 160ms ease;
}

.nav-button:hover:not(.active) {
  background: var(--row-hover);
  color: var(--fg);
}

.nav-button.active {
  background: var(--primary);
  color: var(--fg-on-primary);
  box-shadow: none;
}

.nav-button.active .nav-button-icon {
  background: color-mix(in srgb, var(--fg-on-primary) 22%, transparent);
  color: var(--fg-on-primary);
}

.nav-button:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.main-header,
.main-title-block {
  color: var(--fg);
}

.main-title-pill {
  background: var(--primary-soft);
  color: var(--on-primary-soft);
  border-color: transparent;
}

.theme-toggle {
  background: var(--surface-sunken);
  border-color: var(--border);
}

.theme-toggle-btn {
  color: var(--fg-muted);
  transition: background-color 160ms ease, color 160ms ease;
}

.theme-toggle-btn:hover {
  color: var(--fg);
}

.theme-toggle-btn.active {
  background: var(--surface);
  color: var(--fg);
  box-shadow: var(--shadow-sm);
}

.mobile-menu-toggle {
  background: var(--surface);
  color: var(--fg);
  border-color: var(--border-strong);
}

.mobile-menu-toggle:hover {
  background: var(--row-hover);
  border-color: var(--primary-text);
}

/* ---------- Cards and stats ----------------------------------------------- */
.card,
html[data-theme="light"] .card,
html[data-theme="dark"] .card,
.panel,
.campaigns-right,
.import-modal,
.modal {
  background: var(--surface);
  color: var(--fg);
  border-color: var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
}

html[data-theme="dark"] .card::before,
html[data-theme="dark"] .card::after {
  opacity: 0;
  background: none;
  animation: none;
}

.card-header,
.modal-header {
  background: transparent;
  border-bottom-color: var(--border);
}

.card-title {
  color: var(--fg);
}

.card-subtitle,
.kpi-label,
.kpi-sub,
.stat-label,
.stat-pill-label,
.stat-pill-caption {
  color: var(--fg-muted);
}

.kpi-value,
.stat-value,
.stat-pill-value {
  color: var(--fg);
}

.card,
.stat-tile,
.stat-pill,
.kpi-card,
.panel {
  transition: border-color 160ms ease, box-shadow 160ms ease, background-color 160ms ease;
}

.stat-tile,
.stat-pill,
.kpi-card,
.usage-strip,
.csv-preview,
.import-preview,
.hud-status-pill {
  background: var(--surface-sunken);
  color: var(--fg);
  border-color: var(--border);
}

.hud-status-pill {
  color: var(--fg);
}

.hud-status-dot {
  background: var(--success);
  box-shadow: none;
}

html[data-theme="light"] .admin-dash-subcard,
html[data-theme="dark"] .admin-dash-subcard {
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}

html[data-theme="light"] .admin-dash-oauth-edit,
html[data-theme="dark"] .admin-dash-oauth-edit {
  background: var(--surface-sunken);
  border: 1px solid var(--border);
}

.admin-dash-subcard-body {
  color: var(--fg);
}

.admin-dash-stat-list {
  color: var(--fg-muted);
}

/* ---------- Buttons ------------------------------------------------------- */
.button {
  background: var(--primary-soft);
  color: var(--on-primary-soft);
  border-color: transparent;
  box-shadow: none;
  font-weight: 600;
  transition: background-color 160ms ease, color 160ms ease, border-color 160ms ease, box-shadow 160ms ease;
}

.button:hover:not(:disabled) {
  background: color-mix(in srgb, var(--primary-soft) 78%, var(--primary) 22%);
  color: var(--on-primary-soft);
}

.button:active:not(:disabled) {
  background: color-mix(in srgb, var(--primary-soft) 65%, var(--primary) 35%);
}

.button.primary {
  background: var(--primary);
  color: var(--fg-on-primary);
  border-color: transparent;
  box-shadow: var(--shadow-sm);
}

.button.primary:hover:not(:disabled) {
  background: var(--primary-hover);
  color: var(--fg-on-primary);
  filter: none;
}

.button.primary:active:not(:disabled) {
  background: var(--primary-active);
  color: var(--fg-on-primary);
  filter: none;
}

.button.outline {
  background: transparent;
  color: var(--fg);
  border-color: var(--border-strong);
  box-shadow: none;
}

.button.outline:hover:not(:disabled) {
  background: var(--row-hover);
  color: var(--fg);
  border-color: var(--border-strong);
}

.button.ghost {
  background: transparent;
  color: var(--fg);
  border-color: transparent;
  box-shadow: none;
}

.button.ghost:hover:not(:disabled) {
  background: var(--row-hover);
  color: var(--fg);
}

.button.danger {
  background: transparent;
  color: var(--danger);
  border-color: var(--danger);
}

.button.danger:hover:not(:disabled) {
  background: var(--danger-soft);
  color: var(--on-danger-soft);
  border-color: var(--danger);
}

.button:disabled,
.button.primary:disabled,
.button.outline:disabled,
.button.ghost:disabled,
.button.danger:disabled {
  background: var(--surface-sunken);
  color: var(--fg-subtle);
  border-color: var(--border);
  box-shadow: none;
  filter: none;
  cursor: not-allowed;
  opacity: 1;
}

.button:focus-visible,
.icon-button:focus-visible,
.modal-close:focus-visible,
.tab-button:focus-visible,
.theme-toggle-btn:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.icon-button,
.modal-close {
  color: var(--fg-muted);
  transition: background-color 160ms ease, color 160ms ease;
}

.icon-button:hover,
.modal-close:hover {
  background: var(--row-hover);
  color: var(--fg);
}

/* ---------- Fields -------------------------------------------------------- */
.input,
.select,
textarea.input,
textarea,
.modal input:not([type="checkbox"]):not([type="radio"]):not([type="file"]):not([type="hidden"]):not([type="button"]):not([type="submit"]),
.modal select,
.modal textarea,
.import-modal input:not([type="checkbox"]):not([type="radio"]):not([type="file"]):not([type="hidden"]),
.import-modal select,
.import-modal textarea,
.form-group > input:not([type="checkbox"]):not([type="radio"]):not([type="file"]),
.form-group > select,
.form-group > textarea,
.theme-aware-form input:not([type="checkbox"]):not([type="radio"]):not([type="file"]):not([type="hidden"]),
.theme-aware-form select,
.theme-aware-form textarea,
.field > input:not([type="checkbox"]):not([type="radio"]):not([type="file"]):not([type="hidden"]),
.field > select,
.field > textarea,
.campaigns-right .field input,
.campaigns-right .field select {
  background: var(--surface);
  color: var(--fg);
  border-color: var(--border-strong);
  border-radius: var(--radius-md);
  box-shadow: none;
  transition: border-color 160ms ease, box-shadow 160ms ease, background-color 160ms ease;
}

html[data-theme="light"] .input,
html[data-theme="light"] .select,
html[data-theme="light"] textarea,
html[data-theme="light"] input[type="date"],
html[data-theme="light"] input[type="datetime-local"],
html[data-theme="light"] input[type="time"],
html[data-theme="light"] input[type="month"],
html[data-theme="light"] input[type="week"] {
  color-scheme: light;
}

html[data-theme="dark"] .input,
html[data-theme="dark"] .select,
html[data-theme="dark"] textarea,
html[data-theme="dark"] input[type="date"],
html[data-theme="dark"] input[type="datetime-local"],
html[data-theme="dark"] input[type="time"],
html[data-theme="dark"] input[type="month"],
html[data-theme="dark"] input[type="week"],
html[data-theme="dark"] .modal input,
html[data-theme="dark"] .modal select,
html[data-theme="dark"] .modal textarea,
html[data-theme="dark"] .import-modal input,
html[data-theme="dark"] .import-modal select,
html[data-theme="dark"] .import-modal textarea,
html[data-theme="dark"] .field > input,
html[data-theme="dark"] .field > select,
html[data-theme="dark"] .field > textarea {
  color-scheme: dark;
}

select option,
select optgroup {
  background-color: var(--surface);
  color: var(--fg);
}

.input::placeholder,
textarea::placeholder,
.login-form .input::placeholder {
  color: var(--fg-subtle);
  opacity: 1;
}

.input:hover:not(:disabled):not(:focus),
.select:hover:not(:disabled):not(:focus),
textarea:hover:not(:disabled):not(:focus),
.login-form .input:hover:not(:disabled) {
  border-color: var(--primary-text);
}

.input:focus,
.select:focus,
textarea:focus,
.field > input:focus,
.field > select:focus,
.field > textarea:focus,
.login-form .input:focus,
.campaigns-right .field input:focus,
.campaigns-right .field select:focus {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
  border-color: var(--focus);
  box-shadow: 0 0 0 4px var(--focus-soft);
}

.input:disabled,
.select:disabled,
textarea:disabled,
.input-readonly {
  background: var(--surface-sunken);
  color: var(--fg-subtle);
  border-color: var(--border);
  opacity: 1;
}

.field label,
.modal-body label,
.modal-body .field-label,
.field-label,
html[data-theme="light"] .field label,
html[data-theme="light"] label,
html[data-theme="light"] .card-body label,
html[data-theme="light"] .theme-aware-label,
html[data-theme="light"] .create-tenant-form label,
html[data-theme="light"] .theme-aware-form label,
html[data-theme="dark"] .field label,
html[data-theme="dark"] .modal-body label,
html[data-theme="dark"] .modal-body .field-label,
.theme-aware-label,
.create-tenant-form label,
.theme-aware-form label {
  color: var(--fg-muted);
}

.field-help,
html[data-theme="dark"] .field-help,
html[data-theme="light"] .field-help,
.muted,
.pagination-meta,
.flow-palette-item-help,
.flow-inspector-hint,
.flow-inspector-help,
.flow-empty-helper-list,
.flow-empty-helper-tip {
  color: var(--fg-muted);
}

/* ---------- Tables -------------------------------------------------------- */
.table {
  color: var(--fg);
}

.table thead tr,
.table thead th,
.tenants-list-scroll thead th {
  background: var(--surface-sunken);
  color: var(--fg-muted);
}

.table th {
  color: var(--fg-muted);
  border-bottom-color: var(--border);
}

.table td {
  color: var(--fg);
  border-bottom-color: var(--border);
}

.table tbody tr:nth-child(even) {
  background: var(--row-stripe);
}

.table tbody tr:hover,
.table-row-clickable:hover {
  background: var(--row-hover);
}

/* ---------- Badges -------------------------------------------------------- */
.badge {
  background: var(--surface-sunken);
  color: var(--fg);
  border-color: var(--border-strong);
  font-weight: 600;
}

.badge.new {
  background: var(--primary-soft);
  color: var(--on-primary-soft);
  border-color: var(--primary-text);
}

.badge.interested,
.badge.success {
  background: var(--success-soft);
  color: var(--on-success-soft);
  border-color: var(--success);
}

.badge.not-interested,
.badge.error {
  background: var(--danger-soft);
  color: var(--on-danger-soft);
  border-color: var(--danger);
}

.badge.dnc {
  background: var(--surface-sunken);
  color: var(--fg-muted);
  border-color: var(--border-strong);
}

/* ---------- Tabs ---------------------------------------------------------- */
.tab-button {
  color: var(--fg-muted);
  background: transparent;
  border-radius: 999px;
  transition: background-color 160ms ease, color 160ms ease, border-color 160ms ease;
}

.tab-button:hover {
  color: var(--fg);
  background: var(--row-hover);
}

.tab-button.active {
  background: var(--surface);
  color: var(--fg);
  border-color: var(--border-strong);
  box-shadow: var(--shadow-sm);
}

/* ---------- Modals, toasts, alerts ---------------------------------------- */
.modal-overlay,
.modal-backdrop,
.import-modal-backdrop,
.sidebar-backdrop {
  background: var(--overlay);
}

.modal-title,
.import-modal-title {
  color: var(--fg);
}

.import-modal-subtitle,
.modal-body,
html[data-theme="dark"] .modal-body {
  color: var(--fg);
}

.modal-footer,
.import-modal-footer {
  border-top-color: var(--border);
}

.admin-toast {
  background: var(--surface-raised) !important;
  color: var(--fg) !important;
  border: 1px solid var(--border) !important;
  border-left-width: 4px !important;
  border-radius: var(--radius-md) !important;
  box-shadow: var(--shadow-lg) !important;
}

.admin-toast-error {
  border-left-color: var(--danger) !important;
}

.admin-toast-success {
  border-left-color: var(--success) !important;
}

.admin-toast-info {
  border-left-color: var(--primary-text) !important;
}

.form-error,
.login-shell .form-error,
html[data-theme="light"] .login-shell .form-error,
.error {
  background: var(--danger-soft);
  color: var(--on-danger-soft);
  border: 1px solid var(--danger);
  border-radius: var(--radius-sm);
}

.success {
  background: var(--success-soft);
  color: var(--on-success-soft);
  border: 1px solid var(--success);
  border-radius: var(--radius-sm);
}

.flow-trigger-warning,
.flow-http-warning {
  background: var(--warning-soft);
  border-color: var(--warning);
  color: var(--fg);
}

.flow-trigger-warning-icon,
.flow-http-warning-icon {
  color: var(--warning);
}

.flow-test-result--ok {
  background: var(--success-soft);
  border-color: var(--success);
  color: var(--on-success-soft);
}

.flow-test-result--err {
  background: var(--danger-soft);
  border-color: var(--danger);
  color: var(--on-danger-soft);
}

/* ---------- Code, monitor, links, flow ------------------------------------ */
code,
pre,
.call-detail-transcript,
.flow-fullurl-preview,
.flow-baseurl-readonly {
  background: var(--surface-sunken);
  color: var(--fg);
  border-color: var(--border);
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
}

.monitor-log {
  background: var(--monitor-bg);
  color: var(--monitor-fg);
  border-color: var(--monitor-border);
}

.monitor-tag.call {
  background: rgba(14, 116, 144, 0.35);
  color: #e0f2fe;
}

.monitor-tag.conv {
  background: rgba(67, 56, 202, 0.4);
  color: #e0e7ff;
}

.monitor-tag.rec {
  background: rgba(6, 95, 70, 0.45);
  color: #d1fae5;
}

.monitor-tag.sum {
  background: rgba(120, 53, 15, 0.5);
  color: #fef3c7;
}

a {
  color: var(--primary-text);
  text-decoration-color: color-mix(in srgb, var(--primary-text) 50%, transparent);
}

a:hover {
  color: var(--primary-text-hover);
}

.flow-palette-item {
  background: var(--primary-soft);
  border-color: var(--primary-text);
  color: var(--fg);
}

.flow-palette-item:hover {
  background: color-mix(in srgb, var(--primary-soft) 70%, var(--primary) 30%);
}

.flow-edge-visual,
.flow-edges-layer g:hover .flow-edge-visual,
.flow-edges-layer g.flow-edge--selected .flow-edge-visual,
.flow-edge-preview {
  stroke: var(--primary-text);
}

.flow-node {
  background: var(--surface);
  border-color: var(--border-strong);
  box-shadow: var(--shadow-md);
  color: var(--fg);
}

.flow-node:hover,
.flow-node--selected {
  border-color: var(--primary-text);
}

.flow-node--selected {
  box-shadow: 0 0 0 2px var(--focus-soft);
}

.flow-node--error {
  border-color: var(--danger);
}

.flow-port {
  background: var(--border-strong);
}

.flow-port:hover {
  background: var(--primary-text);
}

.flow-port--valid-target {
  background: var(--success);
  box-shadow: 0 0 0 2px var(--success-soft);
}

.flow-toolbar,
.flow-palette,
.flow-inspector-wrap,
.flow-empty-helper {
  background: var(--surface);
  color: var(--fg);
  border-color: var(--border);
}

.flow-palette,
.flow-inspector-wrap {
  background: var(--bg2);
}

.login-shell,
html[data-theme="dark"] .login-shell {
  color: var(--fg);
  background:
    radial-gradient(ellipse 90% 55% at 50% -15%, var(--glow-1), transparent 58%),
    radial-gradient(ellipse 55% 45% at 100% 40%, var(--glow-2), transparent 52%),
    linear-gradient(180deg, var(--bg) 0%, var(--bg2) 100%);
}

.login-card,
html[data-theme="dark"] .login-card,
html[data-theme="light"] .login-card {
  background: var(--surface);
  color: var(--fg);
  border-color: var(--border);
  box-shadow: var(--shadow-lg);
}

hr {
  border-color: var(--border);
  background: transparent;
}

/* ---------- Inline-style escape hatches -----------------------------------
   React 18 assigns style objects through the CSSOM (element.style.color = …).
   Verified in Chrome on theme-preview.html (React 18.3 probe):
     style={{ color: '#9ca3af' }}  =>  "color: rgb(156, 163, 175);"
     style={{ background: '#0f172a', border: '1px solid #334155' }}
       => "background: rgb(15, 23, 42); border: 1px solid rgb(51, 65, 85);"
     style={{ background: 'rgba(15,23,42,0.9)' }}
       => "background: rgba(15, 23, 42, 0.9);"
     style={{ background: 'white' }}  =>  "background: white;"  (keyword kept)
     element.style.color = '#9ca3af'  =>  "color: rgb(156, 163, 175);"
   Selectors also cover the space-separated CSS Color 4 form and raw hex
   left behind by cssText strings (the toast builder). Only the property
   that was hardcoded is overridden.
   ------------------------------------------------------------------------- */

/* Muted gray text (#9ca3af, #94a3b8) — fails on light surfaces */
[style*="color: rgb(156, 163, 175)"],
[style*="color: rgb(156 163 175)"],
[style*="color:#9ca3af"],
[style*="color: #9ca3af"] {
  color: var(--fg-muted) !important;
}

[style*="color: rgb(148, 163, 184)"],
[style*="color: rgb(148 163 184)"],
[style*="color:#94a3b8"],
[style*="color: #94a3b8"] {
  color: var(--fg-subtle) !important;
}

/* Light gray text sitting on hardcoded dark panels (#e5e7eb) */
[style*="color: rgb(229, 231, 235)"],
[style*="color: rgb(229 231 235)"],
[style*="color:#e5e7eb"],
[style*="color: #e5e7eb"] {
  color: var(--fg) !important;
}

/* Error / danger text */
[style*="color: rgb(249, 115, 115)"],
[style*="color: rgb(249 115 115)"],
[style*="color:#f97373"],
[style*="color: #f97373"],
[style*="color: rgb(248, 113, 113)"],
[style*="color: rgb(248 113 113)"],
[style*="color:#f87171"],
[style*="color: #f87171"],
[style*="color: rgb(239, 68, 68)"],
[style*="color: rgb(239 68 68)"],
[style*="color:#ef4444"],
[style*="color: #ef4444"],
[style*="color: rgb(185, 28, 28)"],
[style*="color: rgb(185 28 28)"],
[style*="color:#b91c1c"],
[style*="color: #b91c1c"],
[style*="color: rgb(220, 38, 38)"],
[style*="color: rgb(220 38 38)"],
[style*="color:#dc2626"],
[style*="color: #dc2626"] {
  color: var(--danger) !important;
}

/* Success text (bright greens fail on white; dark greens fail on navy) */
[style*="color: rgb(74, 222, 128)"],
[style*="color: rgb(74 222 128)"],
[style*="color:#4ade80"],
[style*="color: #4ade80"],
[style*="color: rgb(34, 197, 94)"],
[style*="color: rgb(34 197 94)"],
[style*="color:#22c55e"],
[style*="color: #22c55e"],
[style*="color: rgb(22, 163, 74)"],
[style*="color: rgb(22 163 74)"],
[style*="color:#16a34a"],
[style*="color: #16a34a"] {
  color: var(--success) !important;
}

/* Warning / amber text */
[style*="color: rgb(234, 179, 8)"],
[style*="color: rgb(234 179 8)"],
[style*="color:#eab308"],
[style*="color: #eab308"],
[style*="color: rgb(245, 158, 11)"],
[style*="color: rgb(245 158 11)"],
[style*="color:#f59e0b"],
[style*="color: #f59e0b"],
[style*="color: rgb(249, 115, 22)"],
[style*="color: rgb(249 115 22)"],
[style*="color:#f97316"],
[style*="color: #f97316"],
[style*="color: rgb(180, 83, 9)"],
[style*="color: rgb(180 83 9)"],
[style*="color:#b45309"],
[style*="color: #b45309"] {
  color: var(--warning) !important;
}

/* Info / sky text and listening dots */
[style*="color: rgb(56, 189, 248)"],
[style*="color: rgb(56 189 248)"],
[style*="color:#38bdf8"],
[style*="color: #38bdf8"] {
  color: var(--info) !important;
}

/* --color-primary is a fill blue; when it is used as text, use the text token */
[style*="color: var(--color-primary"] {
  color: var(--primary-text) !important;
}

/* Status fills (dots, bars, step circles). success-solid keeps white #fff text AA. */
[style*="background: rgb(22, 163, 74)"],
[style*="background: rgb(22 163 74)"],
[style*="background:#16a34a"],
[style*="background: #16a34a"] {
  background-color: var(--success-solid) !important;
}

[style*="background: rgb(34, 197, 94)"],
[style*="background: rgb(34 197 94)"],
[style*="background:#22c55e"],
[style*="background: #22c55e"],
[style*="background: rgb(74, 222, 128)"],
[style*="background: rgb(74 222 128)"],
[style*="background:#4ade80"],
[style*="background: #4ade80"] {
  background-color: var(--success) !important;
}

[style*="background: rgb(249, 115, 22)"],
[style*="background: rgb(249 115 22)"],
[style*="background:#f97316"],
[style*="background: #f97316"],
[style*="background: rgb(234, 179, 8)"],
[style*="background: rgb(234 179 8)"] {
  background-color: var(--warning) !important;
}

[style*="background: rgb(56, 189, 248)"],
[style*="background: rgb(56 189 248)"],
[style*="background:#38bdf8"],
[style*="background: #38bdf8"] {
  background-color: var(--info) !important;
}

[style*="background: rgb(229, 231, 235)"],
[style*="background: rgb(229 231 235)"],
[style*="background:#e5e7eb"],
[style*="background: #e5e7eb"] {
  background-color: var(--fg-subtle) !important;
}

[style*="background: rgb(239, 68, 68)"],
[style*="background: rgb(239 68 68)"] {
  background-color: var(--danger) !important;
}

/* Dark slate panels whose text color is inherited (unreadable in light mode) */
[style*="background: rgb(15, 23, 42)"],
[style*="background: rgb(15 23 42)"],
[style*="background:#0f172a"],
[style*="background: #0f172a"],
[style*="background: rgb(31, 41, 55)"],
[style*="background: rgb(31 41 55)"],
[style*="background:#1f2937"],
[style*="background: #1f2937"] {
  background-color: var(--surface-raised) !important;
  color: var(--fg) !important;
}

[style*="background: rgba(15, 23, 42, 0.98)"],
[style*="background: rgba(15,23,42,0.98)"],
[style*="background: rgb(15 23 42 / 0.98)"],
[style*="background: rgba(15, 23, 42, 0.9)"],
[style*="background: rgba(15,23,42,0.9)"],
[style*="background: rgb(15 23 42 / 0.9)"],
[style*="background: rgba(15, 23, 42, 0.6)"],
[style*="background: rgba(15,23,42,0.6)"],
[style*="background: rgb(15 23 42 / 0.6)"] {
  background-color: var(--surface-sunken) !important;
  color: var(--fg) !important;
}

/* Hardcoded white surfaces in dark mode */
html[data-theme="dark"] [style*="background: white"],
html[data-theme="dark"] [style*="background:white"],
html[data-theme="dark"] [style*="background-color: white"],
html[data-theme="dark"] [style*="background-color:white"],
html[data-theme="dark"] [style*="background: rgb(255, 255, 255)"],
html[data-theme="dark"] [style*="background: rgb(255 255 255)"],
html[data-theme="dark"] [style*="background:#fff"],
html[data-theme="dark"] [style*="background: #fff"],
html[data-theme="dark"] [style*="background:#ffffff"],
html[data-theme="dark"] [style*="background: #ffffff"] {
  background-color: var(--surface) !important;
  color: var(--fg) !important;
}

/* Near-black text hardcoded against a theme surface */
html[data-theme="dark"] [style*="color: rgb(17, 17, 17)"],
html[data-theme="dark"] [style*="color: rgb(17 17 17)"],
html[data-theme="dark"] [style*="color:#111"],
html[data-theme="dark"] [style*="color: #111"],
html[data-theme="dark"] [style*="color: black"],
html[data-theme="dark"] [style*="color:black"] {
  color: var(--fg) !important;
}

/* Borders that disappear on the opposite theme */
[style*="solid rgb(51, 65, 85)"],
[style*="solid rgb(51 65 85)"],
[style*="#334155"],
[style*="solid rgb(31, 41, 51)"],
[style*="#1f2933"],
[style*="border-color: rgb(31, 41, 51)"],
[style*="rgba(148, 163, 184, 0.6)"],
[style*="rgba(148,163,184,0.6)"],
[style*="rgba(30, 64, 175, 0.8)"],
[style*="rgba(30,64,175,0.8)"] {
  border-color: var(--border-strong) !important;
}

[style*="rgba(30, 64, 175, 0.6)"],
[style*="rgba(30,64,175,0.6)"] {
  background-color: var(--primary-soft) !important;
  color: var(--on-primary-soft) !important;
}

[style*="rgba(34, 197, 94, 0.6)"],
[style*="rgba(34,197,94,0.6)"] {
  border-color: var(--success) !important;
}

[style*="border-color: #1f2933"],
[style*="border-color:#1f2933"],
[style*="borderColor: #1f2933"] {
  border-color: var(--border-strong) !important;
}

[style*="solid rgb(220, 38, 38)"],
[style*="solid rgb(220 38 38)"],
[style*="#dc2626"] {
  border-color: var(--danger) !important;
}

[style*="solid rgb(59, 130, 246)"],
[style*="solid rgb(59 130 246)"],
[style*="#3b82f6"] {
  border-color: var(--primary-text) !important;
}

[style*="solid rgb(34, 197, 94)"],
[style*="solid rgb(34 197 94)"],
[style*="#22c55e"] {
  border-color: var(--success) !important;
}

[style*="solid rgb(245, 158, 11)"],
[style*="solid rgb(245 158 11)"],
[style*="#f59e0b"],
[style*="rgba(234, 179, 8, 0.4)"],
[style*="rgba(234,179,8,0.4)"] {
  border-color: var(--warning) !important;
}

[style*="rgba(148,163,184,0.2)"],
[style*="rgba(148, 163, 184, 0.2)"] {
  border-color: var(--border) !important;
}

/* Soft status washes */
[style*="rgba(239, 68, 68, 0.15)"],
[style*="rgba(239,68,68,0.15)"],
[style*="rgba(239, 68, 68, 0.12)"],
[style*="rgba(239,68,68,0.12)"],
[style*="rgba(239,68,68,0.1)"],
[style*="rgba(239, 68, 68, 0.1)"],
[style*="rgba(248, 113, 113, 0.14)"],
[style*="rgba(249, 115, 115, 0.15)"] {
  background-color: var(--danger-soft) !important;
}

[style*="rgba(34, 197, 94, 0.15)"],
[style*="rgba(34,197,94,0.15)"],
[style*="rgba(34, 197, 94, 0.2)"],
[style*="rgba(34,197,94,0.2)"] {
  background-color: var(--success-soft) !important;
}

[style*="rgba(234, 179, 8, 0.15)"],
[style*="rgba(234,179,8,0.15)"],
[style*="rgba(234, 179, 8, 0.12)"],
[style*="rgba(234,179,8,0.12)"],
[style*="rgba(234, 179, 8, 0.2)"],
[style*="rgba(234,179,8,0.2)"] {
  background-color: var(--warning-soft) !important;
}

[style*="rgba(59, 130, 246, 0.12)"],
[style*="rgba(59,130,246,0.12)"],
[style*="rgba(59, 130, 246, 0.18)"],
[style*="rgba(59,130,246,0.18)"] {
  background-color: var(--primary-soft) !important;
}

[style*="rgba(148, 163, 184, 0.12)"],
[style*="rgba(148,163,184,0.12)"] {
  background-color: var(--surface-sunken) !important;
}

[style*="rgba(0,0,0,0.2)"],
[style*="rgba(0, 0, 0, 0.2)"] {
  background-color: var(--surface-sunken) !important;
  color: var(--fg) !important;
}

[style*="background: rgba(0, 0, 0, 0.5)"],
[style*="background: rgba(0,0,0,0.5)"],
[style*="background: rgba(0, 0, 0, 0.35)"] {
  background-color: var(--overlay) !important;
}
