/* 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; }

/* Global portal theme 20261001-r2 — admin and collaborator stay consistently dark. */
html.dark body.ew-v2-admin,
html.dark body.ew-v2-collab {
  background: hsl(var(--background)) !important;
  color: hsl(var(--foreground)) !important;
}
html.dark body.ew-v2-admin main,
html.dark body.ew-v2-collab main {
  background: hsl(var(--background)) !important;
  color: hsl(var(--foreground)) !important;
}
html.dark body.ew-v2-admin main [class*="bg-white"],
html.dark body.ew-v2-collab main [class*="bg-white"] {
  background: hsl(var(--card)) !important;
  color: hsl(var(--card-foreground)) !important;
  border-color: hsl(var(--border)) !important;
}
html.dark body.ew-v2-admin main [class*="border-gray"],
html.dark body.ew-v2-collab main [class*="border-gray"],
html.dark body.ew-v2-admin main [class*="border-slate"],
html.dark body.ew-v2-collab main [class*="border-slate"] {
  border-color: hsl(var(--border)) !important;
}


/* v30 — escolha de aparência por utilizador, consistente em /admin, /colaborador e Email Center. */
html:not(.dark) { color-scheme: light; }
html:not(.dark) body.ew-v2-collab,
html:not(.dark) body.ew-v2-admin {
  --background: 210 20% 98%;
  --foreground: 218 24% 17%;
  --card: 0 0% 100%;
  --card-foreground: 218 24% 17%;
  --popover: 0 0% 100%;
  --popover-foreground: 218 24% 17%;
  --primary: 174 58% 30%;
  --primary-foreground: 0 0% 100%;
  --secondary: 210 18% 94%;
  --secondary-foreground: 218 24% 24%;
  --muted: 210 18% 95%;
  --muted-foreground: 215 12% 45%;
  --accent: 174 35% 92%;
  --accent-foreground: 174 58% 22%;
  --destructive: 0 65% 48%;
  --destructive-foreground: 0 0% 100%;
  --border: 214 18% 87%;
  --input: 214 18% 87%;
  --ring: 174 58% 30%;
  --sidebar-background: 0 0% 100%;
  --sidebar-foreground: 218 24% 24%;
  --sidebar-primary: 174 58% 30%;
  --sidebar-primary-foreground: 0 0% 100%;
  --sidebar-accent: 174 35% 94%;
  --sidebar-accent-foreground: 174 58% 22%;
  --sidebar-border: 214 18% 89%;
  --sidebar-ring: 174 58% 30%;
  color: hsl(var(--foreground)) !important;
  background: hsl(var(--background)) !important;
}
html:not(.dark) body.ew-v2-collab,
html:not(.dark) body.ew-v2-admin { color-scheme: light; }
html:not(.dark) body.ew-v2-collab header.sticky,
html:not(.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(218 24% 17% / .07) !important;
}
html:not(.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(218 24% 17% / .04) !important;
}
html:not(.dark) body.ew-v2-collab main,
html:not(.dark) body.ew-v2-admin main {
  background: hsl(var(--background)) !important;
  color: hsl(var(--foreground)) !important;
}
html:not(.dark) body.ew-v2-collab main [class*="rounded-lg"][class*="border"],
html:not(.dark) body.ew-v2-collab main [class*="rounded-xl"][class*="border"],
html:not(.dark) body.ew-v2-admin main [class*="rounded-lg"][class*="border"],
html:not(.dark) body.ew-v2-admin main [class*="rounded-xl"][class*="border"] {
  background: hsl(var(--card)) !important;
  color: hsl(var(--card-foreground));
  border-color: hsl(var(--border)) !important;
  box-shadow: 0 1px 3px hsl(218 24% 17% / .045) !important;
}
html:not(.dark) body.ew-v2-collab input,
html:not(.dark) body.ew-v2-collab textarea,
html:not(.dark) body.ew-v2-collab [role="combobox"],
html:not(.dark) body.ew-v2-admin input,
html:not(.dark) body.ew-v2-admin textarea,
html:not(.dark) body.ew-v2-admin [role="combobox"] {
  color: hsl(var(--foreground)) !important;
  background: hsl(var(--card)) !important;
  border-color: hsl(var(--input)) !important;
}
html:not(.dark) body.ew-v2-collab [role="dialog"],
html:not(.dark) body.ew-v2-admin [role="dialog"] {
  color: hsl(var(--foreground)) !important;
  background: hsl(var(--card)) !important;
  border-color: hsl(var(--border)) !important;
  box-shadow: 0 18px 54px hsl(218 24% 17% / .18) !important;
}

/* Accessible compact appearance picker; the in-dialog instance remains available in Email Center. */
body.ew-v2-collab .ew-theme-control,
body.ew-v2-admin .ew-theme-control { z-index: 8500; font-family: Inter, ui-sans-serif, system-ui, sans-serif; letter-spacing: normal; }
body.ew-v2-collab .ew-theme-control--floating,
body.ew-v2-admin .ew-theme-control--floating {
  position: fixed; right: 18px; bottom: max(18px, env(safe-area-inset-bottom)); z-index: 8500;
}
body.ew-v2-collab .ew-theme-control--inline,
body.ew-v2-admin .ew-theme-control--inline { position: relative; flex: 0 0 auto; z-index: 20; }
body.ew-v2-collab .ew-theme-trigger,
body.ew-v2-admin .ew-theme-trigger {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 42px; padding: 0 13px; border: 1px solid hsl(var(--border)); border-radius: 12px;
  color: hsl(var(--foreground)); background: hsl(var(--card));
  box-shadow: 0 4px 12px hsl(218 24% 17% / .08); font: 650 12px/1 Inter, ui-sans-serif, system-ui, sans-serif;
  letter-spacing: 0; cursor: pointer; transition: background .15s ease, border-color .15s ease, box-shadow .15s ease;
}
body.ew-v2-collab .ew-theme-trigger:hover,
body.ew-v2-admin .ew-theme-trigger:hover { border-color: hsl(var(--primary) / .42); background: hsl(var(--accent)); }
body.ew-v2-collab .ew-theme-trigger:focus-visible,
body.ew-v2-admin .ew-theme-trigger:focus-visible,
body.ew-v2-collab .ew-theme-option:focus-visible,
body.ew-v2-admin .ew-theme-option:focus-visible { outline: 3px solid hsl(var(--ring) / .25); outline-offset: 2px; }
body.ew-v2-collab .ew-theme-trigger svg,
body.ew-v2-admin .ew-theme-trigger svg { width: 16px; height: 16px; flex: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; }
body.ew-v2-collab .ew-theme-trigger-label,
body.ew-v2-admin .ew-theme-trigger-label { font-size: 12px; }
body.ew-v2-collab .ew-theme-current,
body.ew-v2-admin .ew-theme-current { color: hsl(var(--muted-foreground)); font-size: 11px; }
body.ew-v2-collab .ew-theme-popover,
body.ew-v2-admin .ew-theme-popover {
  position: absolute; right: 0; bottom: calc(100% + 8px); z-index: 30; display: grid; gap: 4px;
  width: 188px; padding: 7px; border: 1px solid hsl(var(--border)); border-radius: 14px;
  color: hsl(var(--foreground)); background: hsl(var(--popover));
  box-shadow: 0 14px 36px hsl(218 24% 17% / .17);
}
body.ew-v2-collab .ew-theme-control--inline .ew-theme-popover,
body.ew-v2-admin .ew-theme-control--inline .ew-theme-popover { top: calc(100% + 8px); bottom: auto; }
body.ew-v2-collab .ew-theme-popover[hidden],
body.ew-v2-admin .ew-theme-popover[hidden] { display: none !important; }
body.ew-v2-collab .ew-theme-option,
body.ew-v2-admin .ew-theme-option {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; width: 100%; min-height: 39px;
  padding: 0 10px; border: 1px solid transparent; border-radius: 9px; color: hsl(var(--foreground));
  background: transparent; text-align: left; font: 600 12px/1.2 Inter, ui-sans-serif, system-ui, sans-serif; letter-spacing: 0; cursor: pointer;
}
body.ew-v2-collab .ew-theme-option:hover,
body.ew-v2-admin .ew-theme-option:hover { background: hsl(var(--accent)); }
body.ew-v2-collab .ew-theme-option[aria-pressed="true"],
body.ew-v2-admin .ew-theme-option[aria-pressed="true"] { color: hsl(var(--accent-foreground)); border-color: hsl(var(--primary) / .16); background: hsl(var(--accent)); }
body.ew-v2-collab .ew-theme-option-check,
body.ew-v2-admin .ew-theme-option-check { opacity: 0; color: hsl(var(--primary)); font-weight: 800; }
body.ew-v2-collab .ew-theme-option[aria-pressed="true"] .ew-theme-option-check,
body.ew-v2-admin .ew-theme-option[aria-pressed="true"] .ew-theme-option-check { opacity: 1; }
@media (max-width: 767px) {
  body.ew-v2-collab .ew-theme-control--floating,
  body.ew-v2-admin .ew-theme-control--floating { right: 12px; bottom: calc(74px + env(safe-area-inset-bottom)); }
}
@media (max-width: 480px) {
  body.ew-v2-collab .ew-theme-control--floating .ew-theme-trigger,
  body.ew-v2-admin .ew-theme-control--floating .ew-theme-trigger { width: 46px; min-height: 46px; padding: 0; border-radius: 14px; }
  body.ew-v2-collab .ew-theme-control--floating .ew-theme-trigger-label,
  body.ew-v2-collab .ew-theme-control--floating .ew-theme-current,
  body.ew-v2-admin .ew-theme-control--floating .ew-theme-trigger-label,
  body.ew-v2-admin .ew-theme-control--floating .ew-theme-current { display: none; }
}

/* The email dialog mounts its own selector in the header; avoid a duplicate floating control. */
body.ew-v2-collab.ew-mail-page-active .ew-theme-control--floating { display: none !important; }
