/* Eletroware theme bridge — portal light/dark compatibility.
   Loaded after the legacy clean/mailbox skins so the portal toggle wins. */
html.dark { color-scheme: dark; }

html.dark body.ew-v2-collab,
html.dark body.ew-v2-admin {
  --background: 210 15% 11%;
  --foreground: 180 5% 85%;
  --card: 210 15% 14%;
  --card-foreground: 180 5% 85%;
  --popover: 210 15% 13%;
  --popover-foreground: 180 5% 85%;
  --primary: 160 60% 45%;
  --primary-foreground: 210 15% 8%;
  --secondary: 210 12% 18%;
  --secondary-foreground: 180 5% 75%;
  --muted: 210 12% 20%;
  --muted-foreground: 180 5% 55%;
  --accent: 160 50% 35%;
  --accent-foreground: 180 5% 90%;
  --destructive: 0 65% 50%;
  --destructive-foreground: 0 0% 100%;
  --border: 210 12% 22%;
  --input: 210 12% 20%;
  --ring: 160 60% 45%;
  --sidebar-background: 210 15% 12%;
  --sidebar-foreground: 180 5% 85%;
  --sidebar-primary: 160 60% 45%;
  --sidebar-primary-foreground: 210 15% 8%;
  --sidebar-accent: 210 12% 18%;
  --sidebar-accent-foreground: 180 5% 75%;
  --sidebar-border: 210 12% 22%;
  --sidebar-ring: 160 60% 45%;
  color: hsl(var(--foreground)) !important;
  background: hsl(var(--background)) !important;
}

html.dark body.ew-v2-collab::before,
html.dark body.ew-v2-admin::before { display: none !important; }
html.dark body.ew-v2-collab #root,
html.dark body.ew-v2-admin #root { isolation: isolate; }
html.dark body.ew-v2-collab h1,
html.dark body.ew-v2-collab h2,
html.dark body.ew-v2-collab h3,
html.dark body.ew-v2-collab h4,
html.dark body.ew-v2-admin h1,
html.dark body.ew-v2-admin h2,
html.dark body.ew-v2-admin h3,
html.dark body.ew-v2-admin h4 {
  color: hsl(var(--foreground)) !important;
  text-shadow: none !important;
}

html.dark body.ew-v2-collab header.sticky,
html.dark body.ew-v2-admin header.sticky {
  background: hsl(var(--card) / .96) !important;
  border-color: hsl(var(--border)) !important;
  box-shadow: 0 1px 3px hsl(0 0% 0% / .35) !important;
}
html.dark body.ew-v2-collab aside[class*="md:flex"] {
  background: hsl(var(--sidebar-background)) !important;
  border-color: hsl(var(--sidebar-border)) !important;
  box-shadow: 1px 0 4px hsl(0 0% 0% / .25) !important;
}
html.dark body.ew-v2-collab aside a:hover,
html.dark body.ew-v2-admin header div[class*="border-t"] a:hover {
  color: hsl(var(--foreground)) !important;
  background: hsl(var(--accent)) !important;
  border-color: hsl(var(--border)) !important;
}
html.dark body.ew-v2-collab aside a[class*="bg-primary"],
html.dark body.ew-v2-admin header div[class*="border-t"] a[class*="bg-primary"] {
  color: hsl(var(--primary-foreground)) !important;
  background: hsl(var(--primary)) !important;
  border-color: hsl(var(--primary)) !important;
}
html.dark body.ew-v2-collab main h1,
html.dark body.ew-v2-admin main h1 { color: hsl(var(--foreground)) !important; }
html.dark body.ew-v2-collab main h1 + p,
html.dark body.ew-v2-admin main h1 + p { color: hsl(var(--muted-foreground)) !important; }

html.dark body.ew-v2-collab main [class*="rounded-lg"][class*="border"],
html.dark body.ew-v2-collab main [class*="rounded-xl"][class*="border"],
html.dark body.ew-v2-admin main [class*="rounded-lg"][class*="border"],
html.dark body.ew-v2-admin main [class*="rounded-xl"][class*="border"] {
  border-color: hsl(var(--border)) !important;
  background: hsl(var(--card)) !important;
  box-shadow: 0 1px 3px hsl(0 0% 0% / .28) !important;
}
html.dark body.ew-v2-collab main [class*="rounded-lg"][class*="border"]:hover,
html.dark body.ew-v2-collab main [class*="rounded-xl"][class*="border"]:hover,
html.dark body.ew-v2-admin main [class*="rounded-lg"][class*="border"]:hover,
html.dark body.ew-v2-admin main [class*="rounded-xl"][class*="border"]:hover {
  border-color: hsl(var(--primary) / .55) !important;
}
html.dark body.ew-v2-collab main button[class*="bg-primary"],
html.dark body.ew-v2-admin main button[class*="bg-primary"] {
  background: hsl(var(--primary)) !important;
  color: hsl(var(--primary-foreground)) !important;
  border-color: hsl(var(--primary)) !important;
  box-shadow: none !important;
}
html.dark body.ew-v2-collab input,
html.dark body.ew-v2-collab textarea,
html.dark body.ew-v2-collab [role="combobox"],
html.dark body.ew-v2-admin input,
html.dark body.ew-v2-admin textarea,
html.dark body.ew-v2-admin [role="combobox"] {
  border-color: hsl(var(--border)) !important;
  background: hsl(var(--input)) !important;
  color: hsl(var(--foreground)) !important;
  box-shadow: none !important;
}
html.dark body.ew-v2-collab input::placeholder,
html.dark body.ew-v2-collab textarea::placeholder,
html.dark body.ew-v2-admin input::placeholder,
html.dark body.ew-v2-admin textarea::placeholder { color: hsl(var(--muted-foreground)) !important; }
html.dark body.ew-v2-collab #root > div > div.min-h-screen.flex.items-center.justify-center,
html.dark body.ew-v2-admin #root > div > div.min-h-screen.flex.items-center.justify-center {
  background: hsl(var(--background)) !important;
}
html.dark body.ew-v2-collab #root > div > div.min-h-screen.flex.items-center.justify-center > div {
  border-color: hsl(var(--border)) !important;
  background: hsl(var(--card)) !important;
  box-shadow: 0 12px 36px hsl(0 0% 0% / .42) !important;
}
html.dark body.ew-v2-collab div[class*="md:hidden"][class*="fixed"][class*="bottom-0"],
html.dark body.ew-v2-admin div[class*="md:hidden"][class*="fixed"][class*="bottom-0"] {
  background: hsl(var(--card) / .97) !important;
  border-color: hsl(var(--border)) !important;
  box-shadow: 0 -3px 12px hsl(0 0% 0% / .35) !important;
}
html.dark body.ew-v2-collab div[class*="md:hidden"][class*="fixed"][class*="bottom-0"] a[class*="bg-primary"],
html.dark body.ew-v2-admin div[class*="md:hidden"][class*="fixed"][class*="bottom-0"] a[class*="bg-primary"] {
  background: hsl(var(--primary) / .18) !important;
  border-color: hsl(var(--primary) / .45) !important;
  color: hsl(var(--primary)) !important;
}

/* Visit cards and the read-only consultation sheet. */
html.dark body.ew-v2-collab main .ew-visit-card {
  border-color: hsl(var(--border)) !important;
  background: hsl(var(--card)) !important;
  box-shadow: 0 2px 6px hsl(0 0% 0% / .28) !important;
}
html.dark body.ew-v2-collab main .ew-visit-card:hover { border-color: hsl(var(--primary) / .55) !important; }
html.dark body.ew-v2-collab main .ew-visit-card h4 { color: hsl(var(--foreground)) !important; }
html.dark body.ew-v2-collab main .ew-visit-card p,
html.dark body.ew-v2-collab main .ew-visit-card [class*="line-clamp-2"] { color: hsl(var(--muted-foreground)) !important; }
html.dark body.ew-v2-collab dialog.ew-visit-detail {
  border-color: hsl(var(--border));
  background: hsl(var(--card));
  color: hsl(var(--foreground));
  box-shadow: 0 22px 60px hsl(0 0% 0% / .55);
}
html.dark body.ew-v2-collab .ew-visit-detail-head,
html.dark body.ew-v2-collab .ew-visit-detail-actions { border-color: hsl(var(--border)); background: hsl(var(--card)); }
html.dark body.ew-v2-collab .ew-visit-detail-eyebrow,
html.dark body.ew-v2-collab .ew-visit-detail-protocol,
html.dark body.ew-v2-collab .ew-visit-detail-label { color: hsl(var(--muted-foreground)); }
html.dark body.ew-v2-collab .ew-visit-detail-title,
html.dark body.ew-v2-collab .ew-visit-detail-value,
html.dark body.ew-v2-collab .ew-visit-detail-section p { color: hsl(var(--foreground)); }
html.dark body.ew-v2-collab .ew-visit-detail-field,
html.dark body.ew-v2-collab .ew-visit-detail-section,
html.dark body.ew-v2-collab .ew-visit-detail-actions button {
  border-color: hsl(var(--border)); background: hsl(var(--secondary)); color: hsl(var(--foreground));
}
html.dark body.ew-v2-collab .ew-visit-detail-actions button[data-action="edit"] {
  border-color: hsl(var(--primary)); background: hsl(var(--primary)); color: hsl(var(--primary-foreground));
}

/* Radix dialogs: use theme tokens rather than the legacy light skin. */
html.dark body.ew-v2-collab [data-radix-dialog-overlay],
html.dark body.ew-v2-admin [data-radix-dialog-overlay] { background: hsl(0 0% 0% / .72) !important; }
html.dark body.ew-v2-collab [role="dialog"],
html.dark body.ew-v2-admin [role="dialog"] {
  border-color: hsl(var(--border)) !important;
  background: hsl(var(--card)) !important;
  color: hsl(var(--foreground)) !important;
  box-shadow: 0 18px 54px hsl(0 0% 0% / .55) !important;
}
html.dark body.ew-v2-collab [role="dialog"] > div:first-child,
html.dark body.ew-v2-admin [role="dialog"] > div:first-child {
  border-color: hsl(var(--border)) !important;
  background: hsl(var(--card)) !important;
}
html.dark body.ew-v2-collab [role="dialog"] label,
html.dark body.ew-v2-admin [role="dialog"] label { color: hsl(var(--foreground)) !important; }
html.dark body.ew-v2-collab [role="dialog"] > div:nth-child(2) > button,
html.dark body.ew-v2-admin [role="dialog"] > div:nth-child(2) > button {
  border-color: hsl(var(--border)) !important;
  background: hsl(var(--secondary)) !important;
  color: hsl(var(--foreground)) !important;
}
html.dark body.ew-v2-collab [role="dialog"] > div:nth-child(2) > button:last-child,
html.dark body.ew-v2-admin [role="dialog"] > div:nth-child(2) > button:last-child {
  background: hsl(var(--primary)) !important;
  color: hsl(var(--primary-foreground)) !important;
}

/* Native mailbox and inbox surfaces. */
html.dark body.ew-v2-collab dialog.ew-mailboxes-dialog,
html.dark body.ew-v2-collab dialog.ew-mail-native-dialog,
html.dark body.ew-v2-collab .ew-mail-native-login {
  color: hsl(var(--foreground)) !important;
  background: hsl(var(--card)) !important;
  border-color: hsl(var(--border)) !important;
}
html.dark body.ew-v2-collab .ew-mail-native-content,
html.dark body.ew-v2-collab .ew-mailboxes-content { background: hsl(var(--background)) !important; }
html.dark body.ew-v2-collab .ew-mailbox-card,
html.dark body.ew-v2-collab .ew-mail-native-card,
html.dark body.ew-v2-collab .ew-mail-native-message,
html.dark body.ew-v2-collab .ew-mail-native-empty,
html.dark body.ew-v2-collab .ew-mail-native-body-text,
html.dark body.ew-v2-collab .ew-mail-native-detail-meta {
  background: hsl(var(--card)) !important;
  color: hsl(var(--foreground)) !important;
  border-color: hsl(var(--border)) !important;
}
html.dark body.ew-v2-collab .ew-mailboxes-head h2,
html.dark body.ew-v2-collab .ew-mailbox-card-top,
html.dark body.ew-v2-collab .ew-mail-native-card-labels strong,
html.dark body.ew-v2-collab .ew-mail-native-folder strong,
html.dark body.ew-v2-collab .ew-mail-native-sender,
html.dark body.ew-v2-collab .ew-mail-native-subject,
html.dark body.ew-v2-collab .ew-mail-native-detail-subject { color: hsl(var(--foreground)) !important; }
html.dark body.ew-v2-collab .ew-mailboxes-subtitle,
html.dark body.ew-v2-collab .ew-mailbox-address,
html.dark body.ew-v2-collab .ew-mail-native-description,
html.dark body.ew-v2-collab .ew-mail-native-date,
html.dark body.ew-v2-collab .ew-mail-native-from,
html.dark body.ew-v2-collab .ew-mail-native-count,
html.dark body.ew-v2-collab .ew-mail-native-readonly-note { color: hsl(var(--muted-foreground)) !important; }
html.dark body.ew-v2-collab .ew-mailboxes-notice,
html.dark body.ew-v2-collab .ew-mail-native-admin-banner,
html.dark body.ew-v2-collab .ew-mail-native-admin-intro,
html.dark body.ew-v2-collab .ew-mail-native-search,
html.dark body.ew-v2-collab .ew-mail-native-password,
html.dark body.ew-v2-collab .ew-mail-native-secondary,
html.dark body.ew-v2-collab .ew-mail-native-icon-button {
  background: hsl(var(--secondary)) !important;
  color: hsl(var(--foreground)) !important;
  border-color: hsl(var(--border)) !important;
}
html.dark body.ew-v2-collab .ew-mail-native-primary,
html.dark body.ew-v2-collab .ew-mail-native-open:hover,
html.dark body.ew-v2-collab .ew-mail-native-primary:hover {
  background: hsl(var(--primary)) !important;
  border-color: hsl(var(--primary)) !important;
  color: hsl(var(--primary-foreground)) !important;
}
html.dark body.ew-v2-collab .ew-mailboxes-footer { background: hsl(var(--secondary)) !important; color: hsl(var(--muted-foreground)) !important; }
html.dark body.ew-v2-collab .ew-mail-native-search input { background: hsl(var(--input)) !important; color: hsl(var(--foreground)) !important; border-color: hsl(var(--border)) !important; }
html.dark body.ew-v2-collab .ew-mail-native-folder,
html.dark body.ew-v2-collab .ew-mail-native-loading { color: hsl(var(--muted-foreground)) !important; }
