/*
 * RV appearance layer.
 *
 * The RN tokens remain the source of truth. Dark mode remaps semantic tokens
 * and then closes the few legacy surface rules that still use neutral tokens
 * directly, so the same preference follows the user through every workspace.
 */

.rv-native-workspace[data-theme="dark"] {
  /* Dark palette tuned to the RN reference: blue slate canvas, lifted cards,
     lavender copy and small electric accents instead of near-black surfaces. */
  --rv-dark-canvas: #151d2b;
  --rv-dark-canvas-deep: #111a27;
  --rv-dark-surface: #1d2938;
  --rv-dark-surface-soft: #192536;
  --rv-dark-surface-muted: #202e40;
  --rv-dark-border: #2d3d50;
  --rv-dark-border-strong: #53647a;
  --rv-dark-text: #eef2f8;
  --rv-dark-heading: #f6f8fc;
  --rv-dark-text-subtle: #a4aec0;
  --rv-dark-text-muted: #7d8ca1;
  --rv-dark-blue: #9ab5ff;
  --rv-dark-blue-strong: #6f8fdf;
  --rv-dark-purple: #bf9cff;

  /* Remap the canonical scales once so legacy RN components inherit the same
     surface hierarchy without per-page overrides. */
  --rn-brand-50: #253550;
  --rn-brand-100: #2d405c;
  --rn-brand-200: #c2ceff;
  --rn-brand-300: #aebeff;
  --rn-brand-400: #9ab5ff;
  --rn-brand-500: #86a5f1;
  --rn-brand-600: #718ed6;
  --rn-brand-700: #5e78ba;
  --rn-brand-800: #3b557f;
  --rn-brand-900: var(--rv-dark-surface);
  --rn-brand-950: var(--rv-dark-canvas-deep);
  --rn-neutral-50: #202e40;
  --rn-neutral-100: #223246;
  --rn-neutral-200: #2d3d50;
  --rn-neutral-300: #3c4d63;
  --rn-neutral-400: #8191a8;
  --rn-neutral-500: #95a4b9;
  --rn-neutral-600: #a4b0c1;
  --rn-neutral-700: #b5bfce;
  --rn-neutral-800: #26384e;
  --rn-neutral-900: var(--rv-dark-surface-soft);
  --rn-neutral-950: var(--rv-dark-canvas);

  --rn-color-background: var(--rn-neutral-950);
  --rn-color-surface: var(--rn-brand-900);
  --rn-color-surface-soft: var(--rv-dark-surface-soft);
  --rn-color-surface-muted: var(--rv-dark-surface-muted);
  --rn-color-surface-brand: color-mix(in srgb, var(--rv-dark-blue) 14%, var(--rv-dark-surface));
  --rn-color-text: var(--rv-dark-text);
  --rn-color-text-subtle: var(--rv-dark-text-subtle);
  --rn-color-text-muted: var(--rv-dark-text-muted);
  --rn-color-heading: var(--rv-dark-heading);
  --rn-color-border: var(--rv-dark-border);
  --rn-color-border-strong: var(--rv-dark-border-strong);
  --rn-color-control-border: #56677e;
  --rn-color-primary: var(--rn-brand-600);
  --rn-color-primary-hover: var(--rn-brand-400);
  --rn-color-primary-active: var(--rn-brand-300);
  --rn-color-on-primary: #101a2a;
  --rn-color-accent: var(--rn-cyan);
  --rn-color-accent-strong: var(--rn-cyan);
  --rn-color-on-accent: var(--rn-neutral-950);
  --rn-color-brand-text: var(--rv-dark-blue);
  --rn-color-focus: var(--rv-dark-blue-strong);
  --rn-color-focus-accent: var(--rv-dark-blue);
  --rn-color-link: var(--rv-dark-blue);
  --rn-color-link-hover: var(--rn-neutral-0);
  --rn-color-overlay: color-mix(in srgb, var(--rn-brand-950) 88%, transparent);
  --rn-color-success: var(--rn-success-200);
  --rn-color-success-surface: color-mix(in srgb, var(--rn-success-700) 30%, var(--rn-neutral-950));
  --rn-color-warning: var(--rn-warning-200);
  --rn-color-warning-surface: color-mix(in srgb, var(--rn-warning-700) 30%, var(--rn-neutral-950));
  --rn-color-danger: var(--rn-danger-200);
  --rn-color-danger-surface: color-mix(in srgb, var(--rn-danger-700) 30%, var(--rn-neutral-950));
  --rn-color-data-1: var(--rv-dark-blue);
  --rn-color-data-2: var(--rn-cyan);
  --rn-color-data-3: var(--rn-neutral-400);
  --rn-color-data-4: var(--rn-success-200);
  --rn-color-data-5: var(--rn-warning-200);
  --rn-color-scene: var(--rv-dark-surface);
  --rn-color-scene-stage: var(--rv-dark-surface-muted);
  --rn-color-scene-deep: var(--rv-dark-canvas-deep);
  --rn-color-on-scene: var(--rv-dark-text);
  --rn-color-on-scene-strong: var(--rv-dark-heading);
  --rn-color-on-scene-muted: var(--rv-dark-text-subtle);
  --rn-color-scene-border: color-mix(in srgb, var(--rv-dark-blue) 24%, transparent);
  --rn-grid-line: color-mix(in srgb, var(--rn-cyan) 12%, transparent);
  --rn-focus-ring: 0 0 0 3px color-mix(in srgb, var(--rn-cyan) 60%, transparent);
}

/* Preserve the plain canvas across light and dark themes. */
.rv-native-workspace[data-theme="dark"] .rv-native-workspace {
}

.rv-native-workspace[data-theme="dark"] .rv-shell,.rv-native-workspace[data-theme="dark"] .rv-main {
}

/* Global navigation and account controls. */
.rv-native-workspace[data-theme="dark"] .rv-topbar {
  border-bottom-color: var(--rn-color-scene-border);
}

.rv-native-workspace[data-theme="dark"] .rv-sidebar {
  border-right-color: var(--rn-color-scene-border);
}

.rv-native-workspace[data-theme="dark"] .rv-sidebar.rv-sidebar--primary .rv-dashboard-navigation .rn-sidebar__link:not([aria-current]),.rv-native-workspace[data-theme="dark"] .rv-sidebar.rv-sidebar--primary .rv-nav-section-label {
}

.rv-native-workspace[data-theme="dark"] .rv-sidebar.rv-sidebar--primary .rv-dashboard-navigation .rn-sidebar__link:hover:not([aria-current]) {
}

.rv-native-workspace[data-theme="dark"] .rv-sidebar-bottom,.rv-native-workspace[data-theme="dark"] .rv-footer {
}

.rv-native-workspace[data-theme="dark"] :is(.rv-brand, .rv-account-label, .rv-account-label strong, .rv-sidebar-signature) {
}

.rv-native-workspace[data-theme="dark"] .rv-account-label small,.rv-native-workspace[data-theme="dark"] .rv-sidebar-signature small {
}

.rv-native-workspace[data-theme="dark"] .rv-topbar .rv-avatar {
}

.rv-native-workspace[data-theme="dark"] .rv-topbar .rv-search-trigger,.rv-native-workspace[data-theme="dark"] .rv-topbar .rv-account-trigger {
}

.rv-native-workspace[data-theme="dark"] .rv-topbar .rv-search-trigger:hover,.rv-native-workspace[data-theme="dark"] .rv-topbar .rv-account-trigger:hover,.rv-native-workspace[data-theme="dark"] .rv-topbar .rv-account-trigger[aria-expanded="true"] {
}

.rv-native-workspace[data-theme="dark"] .rv-topbar kbd {
}

.rv-native-workspace[data-theme="dark"] .rv-nav-group > summary,.rv-native-workspace[data-theme="dark"] .rv-nav-group .rn-sidebar__link,.rv-native-workspace[data-theme="dark"] .rv-context-navigation .rn-sidebar__link,.rv-native-workspace[data-theme="dark"] .rv-sector-link,.rv-native-workspace[data-theme="dark"] .rv-sector-more > summary {
}

.rv-native-workspace[data-theme="dark"] :is(.rv-nav-group > summary:hover, .rv-nav-group[open] > summary, .rv-nav-group .rn-sidebar__link:hover, .rv-context-navigation .rn-sidebar__link:hover, .rv-sector-more > summary:hover, .rv-sector-more[open] > summary) {
}

.rv-native-workspace[data-theme="dark"] :is(.rv-nav-group .rn-sidebar__link[aria-current="page"], .rv-context-navigation .rn-sidebar__link[aria-current], .rv-sector-link[aria-current], .rv-sector-more.is-current > summary) {
}

.rv-native-workspace[data-theme="dark"] .rv-sector-more > div,.rv-native-workspace[data-theme="dark"] .rv-account-menu,.rv-native-workspace[data-theme="dark"] .rv-mobile-navigation {
}

.rv-native-workspace[data-theme="dark"] .rv-sector-more > div > a,.rv-native-workspace[data-theme="dark"] .rv-account-menu-links a {
}

.rv-native-workspace[data-theme="dark"] :is(.rv-sector-more > div > a:hover, .rv-sector-more > div > a[aria-current], .rv-account-menu-links a:hover) {
}

.rv-native-workspace[data-theme="dark"] .rv-account-identity {
}

/* The toggle is intentionally compact: it sits directly beside the profile. */
:where(.rv-native-workspace) .rv-theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--rn-space-2);
  min-height: var(--rn-target-min);
  padding: 0 var(--rn-space-3);
  white-space: nowrap;
  cursor: pointer;
}

:where(.rv-native-workspace) .rv-theme-toggle:hover {
}

:where(.rv-native-workspace) .rv-theme-toggle:focus-visible {
  outline: 0;
}

:where(.rv-native-workspace) .rv-theme-toggle:active { transform: scale(.97); }

:where(.rv-native-workspace) .rv-theme-toggle-mark {
  display: block;
  width: var(--rn-space-4);
  height: var(--rn-space-4);
}

.rv-native-workspace[data-theme="dark"] .rv-theme-toggle {
}

.rv-native-workspace[data-theme="dark"] .rv-theme-toggle:hover {
}

.rv-native-workspace[data-theme="dark"] .rv-theme-toggle-mark {
}

/* Shared surfaces, dialogs, data tables and forms. */
.rv-native-workspace[data-theme="dark"] :is(.rn-card, .rn-card--soft, .rv-connection-editor, .rv-setup-form, .rv-setup-guide, .rv-handoff-card, .rv-account-list, .rv-accounts-toolbar, .rv-account-card, .rv-table-scroll, .rv-command-aside, .rv-editor-guide, .rv-page-preview, .rv-submit-status, .rv-opportunity, .rv-chart, .rn-empty-state, .rn-toast) {
}

.rv-native-workspace[data-theme="dark"] :is(.rv-account-row + .rv-account-row, .rv-account-identity, .rv-connection-config, .rv-connection-footer, .rv-sync-panel > .rv-list-row, .rv-table th, .rv-table td, .rv-list-row, .rv-detail-section, .rv-footer) {
}

.rv-native-workspace[data-theme="dark"] .rv-account-row:hover,.rv-native-workspace[data-theme="dark"] .rv-table tbody tr:hover,.rv-native-workspace[data-theme="dark"] .rv-table tbody tr:focus-within,.rv-native-workspace[data-theme="dark"] .rv-list-row:hover {
}

.rv-native-workspace[data-theme="dark"] .rv-table thead,.rv-native-workspace[data-theme="dark"] .rv-priority-table-head,.rv-native-workspace[data-theme="dark"] .rv-filter-disclosure > summary {
}

.rv-native-workspace[data-theme="dark"] :is(.rn-field__control, .rn-field select, .rn-field textarea, input, select, textarea) {
}

.rv-native-workspace[data-theme="dark"] :is(.rn-field__control, .rn-field select, .rn-field textarea, input, select, textarea)::placeholder {
}

.rv-native-workspace[data-theme="dark"] :is(.rn-field__control, .rn-field select, .rn-field textarea, input, select, textarea):focus {
}

.rv-native-workspace[data-theme="dark"] option { }

.rv-native-workspace[data-theme="dark"] :is(.rn-button--secondary, .rn-button--ghost) {
}

.rv-native-workspace[data-theme="dark"] :is(.rn-button--secondary:hover:not(:disabled), .rn-button--ghost:hover:not(:disabled)) {
}

.rv-native-workspace[data-theme="dark"] .rn-button--danger {
}

.rv-native-workspace[data-theme="dark"] :is(.rn-chip, .rn-badge, .rv-evidence-chips > span) {
}

.rv-native-workspace[data-theme="dark"] :is(.rn-chip--neutral, .rn-badge--neutral) {
}

.rv-native-workspace[data-theme="dark"] .rn-alert--success,.rv-native-workspace[data-theme="dark"] .rv-setup-ready { }
.rv-native-workspace[data-theme="dark"] .rn-alert--warning { }
.rv-native-workspace[data-theme="dark"] :is(.rn-alert--danger, .rn-error-summary) { }

.rv-native-workspace[data-theme="dark"] :is(h1, h2, h3, h4, h5, h6, dt, th, strong, .rn-heading) { }
.rv-native-workspace[data-theme="dark"] :is(.rn-muted, .rn-field__description, .rv-page-header > p, .rv-freshness, .rv-data-caution) { }
.rv-native-workspace[data-theme="dark"] a:not(.rn-button):not(.rv-brand) { }
.rv-native-workspace[data-theme="dark"] a:not(.rn-button):not(.rv-brand):hover { }

.rv-native-workspace[data-theme="dark"] dialog::backdrop { }

/* Keep all dashboard cards on the same RN scene as the reference card. */
.rv-native-workspace[data-theme="dark"] .rv-main {
  --rv-scene-background: radial-gradient(circle at 10% 90%, color-mix(in srgb, var(--rv-dark-blue) 11%, transparent), transparent 48%), radial-gradient(circle at 88% 8%, color-mix(in srgb, var(--rv-dark-purple) 7%, transparent), transparent 38%), linear-gradient(145deg, var(--rv-dark-canvas), var(--rv-dark-surface));
}

@media (max-width: 599px) {
  :where(.rv-native-workspace) .rv-theme-toggle { width: var(--rn-target-min); min-width: var(--rn-target-min); padding-inline: 0; }
  :where(.rv-native-workspace) .rv-theme-toggle-label { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  :where(.rv-native-workspace) .rv-theme-toggle,:where(.rv-native-workspace) .rv-theme-toggle-mark { }
}
