@import 'tailwindcss';
@import 'tw-animate-css';
@import '../styles/onlyoffice-theme.css';
@import '../styles/richtext-editor.css';
@import '../styles/docs-print.css';
@import '../styles/landing.css';

@custom-variant dark (&:is(.dark *));

:root {
  --background: oklch(1 0 0);
  --foreground: oklch(0.145 0 0);
  --card: oklch(1 0 0);
  --card-foreground: oklch(0.145 0 0);
  --popover: oklch(1 0 0);
  --popover-foreground: oklch(0.145 0 0);
  --primary: oklch(0.205 0 0);
  --primary-foreground: oklch(0.985 0 0);
  --secondary: oklch(0.97 0 0);
  --secondary-foreground: oklch(0.205 0 0);
  --muted: oklch(0.97 0 0);
  --muted-foreground: oklch(0.556 0 0);
  --accent: oklch(0.97 0 0);
  --accent-foreground: oklch(0.205 0 0);
  --destructive: oklch(0.577 0.245 27.325);
  --destructive-foreground: oklch(0.577 0.245 27.325);
  --border: oklch(0.922 0 0);
  --input: oklch(0.922 0 0);
  --ring: oklch(0.708 0 0);
  --chart-1: oklch(0.646 0.222 41.116);
  --chart-2: oklch(0.6 0.118 184.704);
  --chart-3: oklch(0.398 0.07 227.392);
  --chart-4: oklch(0.828 0.189 84.429);
  --chart-5: oklch(0.769 0.188 70.08);
  --radius: 0.625rem;
  --sidebar: oklch(0.985 0 0);
  --sidebar-foreground: oklch(0.145 0 0);
  --sidebar-primary: oklch(0.205 0 0);
  --sidebar-primary-foreground: oklch(0.985 0 0);
  --sidebar-accent: oklch(0.97 0 0);
  --sidebar-accent-foreground: oklch(0.205 0 0);
  --sidebar-border: oklch(0.922 0 0);
  --sidebar-ring: oklch(0.708 0 0);
  /** Fond chrome (layout mail : header, rails, sidebar). */
  --app-canvas: #fafbfc;
  --mail-surface: #ffffff;
  --mail-surface-elevated: #ffffff;
  --mail-surface-muted: #f1f3f4;
  --mail-border: #dadce0;
  --mail-border-subtle: #eceff1;
  --mail-text: #3c4043;
  --mail-text-strong: #202124;
  --mail-text-muted: #5f6368;
  --mail-hover: #f1f3f4;
  --mail-active: #e8f0fe;
  --mail-row-unread: #ffffff;
  --mail-row-read: #f5f5f5;
  --mail-row-selected: #e8f0fe;
  --mail-row-active-split: #e8f0fe;
  --mail-nav-selected: #d3e3fd;
  --mail-nav-selected-fg: #202124;
  --mail-nav-hover: #f1f3f4;
  --mail-nav-drop: #fef7cd;
  --mail-invitation: #e8f0fe;
  --mail-list-divider: #eceff1;
  --mail-list-chip-border: #dadce0;
  --mail-list-chip-text: #3c4043;
  --mail-list-chip-muted: #f1f3f4;
  --mail-row-checkbox-border: #c2c2c2;
  --drive-canvas: var(--app-canvas);
  --drive-sidebar-foreground: var(--mail-text);
  --drive-surface: var(--mail-surface);
  --drive-toolbar: var(--mail-surface-elevated);
  --suite-surface-elevated: var(--mail-surface-elevated);
}

.dark {
  --app-canvas: #202124;
  --mail-surface: #2d2e30;
  --mail-surface-elevated: #35363a;
  --mail-surface-muted: #3c4043;
  --mail-border: #5f6368;
  --mail-border-subtle: #3c4043;
  --mail-text: #e8eaed;
  --mail-text-strong: #ffffff;
  --mail-text-muted: #9aa0a6;
  --mail-hover: #3c4043;
  --mail-active: #394457;
  --mail-row-unread: #2d2e30;
  --mail-row-read: #35363a;
  --mail-row-selected: #394457;
  --mail-row-active-split: #394457;
  --mail-nav-selected: #394457;
  --mail-nav-selected-fg: #e8eaed;
  --mail-nav-hover: #3c4043;
  --mail-nav-drop: #4a4428;
  --mail-invitation: #2d3a4d;
  --mail-list-divider: #3c4043;
  --mail-list-chip-border: #5f6368;
  --mail-list-chip-text: #e8eaed;
  --mail-list-chip-muted: #3c4043;
  --mail-row-checkbox-border: #9aa0a6;
  --drive-canvas: var(--app-canvas);
  --drive-sidebar-foreground: var(--mail-text);
  --drive-surface: var(--mail-surface);
  --drive-toolbar: var(--mail-surface-elevated);
  --suite-surface-elevated: var(--mail-surface-elevated);
  --background: oklch(0.145 0 0);
  --foreground: oklch(0.985 0 0);
  --card: oklch(0.145 0 0);
  --card-foreground: oklch(0.985 0 0);
  --popover: oklch(0.145 0 0);
  --popover-foreground: oklch(0.985 0 0);
  --primary: oklch(0.985 0 0);
  --primary-foreground: oklch(0.205 0 0);
  --secondary: oklch(0.269 0 0);
  --secondary-foreground: oklch(0.985 0 0);
  --muted: oklch(0.269 0 0);
  --muted-foreground: oklch(0.708 0 0);
  --accent: oklch(0.269 0 0);
  --accent-foreground: oklch(0.985 0 0);
  --destructive: oklch(0.65 0.22 25.3);
  --destructive-foreground: oklch(0.985 0 0);
  --border: oklch(0.269 0 0);
  --input: oklch(0.269 0 0);
  --ring: oklch(0.439 0 0);
  --chart-1: oklch(0.488 0.243 264.376);
  --chart-2: oklch(0.696 0.17 162.48);
  --chart-3: oklch(0.769 0.188 70.08);
  --chart-4: oklch(0.627 0.265 303.9);
  --chart-5: oklch(0.645 0.246 16.439);
  --sidebar: oklch(0.205 0 0);
  --sidebar-foreground: oklch(0.985 0 0);
  --sidebar-primary: oklch(0.488 0.243 264.376);
  --sidebar-primary-foreground: oklch(0.985 0 0);
  --sidebar-accent: oklch(0.269 0 0);
  --sidebar-accent-foreground: oklch(0.985 0 0);
  --sidebar-border: oklch(0.269 0 0);
  --sidebar-ring: oklch(0.439 0 0);
}

/* ── Mobile dark : fonds plus sombres (main, mail-list, preview) ── */
@media (max-width: 639px) {
  .dark {
    --app-canvas: #111113;
    --mail-surface: #161618;
    --mail-surface-elevated: #1e1e21;
    --mail-surface-muted: #262629;
    --mail-border-subtle: #2c2c2f;
    --mail-list-divider: #2c2c2f;
    --mail-row-unread: #161618;
    --mail-row-read: #1c1c1f;
    --mail-row-selected: #1c2d4a;
    --mail-row-active-split: #1c2d4a;
    --mail-hover: #222225;
    --mail-active: #1c2d4a;
  }
}

@theme inline {
  --font-sans: var(--font-geist-sans);
  --font-mono: var(--font-geist-mono);
  --color-background: var(--background);
  --color-foreground: var(--foreground);
  --color-card: var(--card);
  --color-card-foreground: var(--card-foreground);
  --color-popover: var(--popover);
  --color-popover-foreground: var(--popover-foreground);
  --color-primary: var(--primary);
  --color-primary-foreground: var(--primary-foreground);
  --color-secondary: var(--secondary);
  --color-secondary-foreground: var(--secondary-foreground);
  --color-muted: var(--muted);
  --color-muted-foreground: var(--muted-foreground);
  --color-accent: var(--accent);
  --color-accent-foreground: var(--accent-foreground);
  --color-destructive: var(--destructive);
  --color-destructive-foreground: var(--destructive-foreground);
  --color-border: var(--border);
  --color-input: var(--input);
  --color-ring: var(--ring);
  --color-chart-1: var(--chart-1);
  --color-chart-2: var(--chart-2);
  --color-chart-3: var(--chart-3);
  --color-chart-4: var(--chart-4);
  --color-chart-5: var(--chart-5);
  --radius-sm: calc(var(--radius) - 4px);
  --radius-md: calc(var(--radius) - 2px);
  --radius-lg: var(--radius);
  --radius-xl: calc(var(--radius) + 4px);
  --color-sidebar: var(--sidebar);
  --color-sidebar-foreground: var(--sidebar-foreground);
  --color-sidebar-primary: var(--sidebar-primary);
  --color-sidebar-primary-foreground: var(--sidebar-primary-foreground);
  --color-sidebar-accent: var(--sidebar-accent);
  --color-sidebar-accent-foreground: var(--sidebar-accent-foreground);
  --color-sidebar-border: var(--sidebar-border);
  --color-sidebar-ring: var(--sidebar-ring);
  --color-app-canvas: var(--app-canvas);
  --color-mail-surface: var(--mail-surface);
  --color-mail-surface-elevated: var(--mail-surface-elevated);
  --color-mail-surface-muted: var(--mail-surface-muted);
  --color-mail-text: var(--mail-text);
  --color-mail-text-strong: var(--mail-text-strong);
  --color-mail-text-muted: var(--mail-text-muted);
  --color-mail-active: var(--mail-active);
  --color-mail-nav-selected: var(--mail-nav-selected);
  --color-mail-nav-selected-fg: var(--mail-nav-selected-fg);
  --color-mail-nav-hover: var(--mail-nav-hover);
  --color-mail-border: var(--mail-border);
  --color-mail-border-subtle: var(--mail-border-subtle);
  --color-mail-invitation: var(--mail-invitation);
  --color-mail-list-divider: var(--mail-list-divider);
  --color-mail-list-chip-border: var(--mail-list-chip-border);
  --color-mail-list-chip-text: var(--mail-list-chip-text);
  --color-mail-list-chip-muted: var(--mail-list-chip-muted);
  --color-mail-row-checkbox-border: var(--mail-row-checkbox-border);
  --color-drive-canvas: var(--drive-canvas);
  --color-drive-surface: var(--drive-surface);
  --color-drive-sidebar-foreground: var(--drive-sidebar-foreground);
}

@layer base {
  * {
    @apply border-border outline-ring/50;
  }
  body {
    @apply bg-background text-foreground;
  }

  /* Main sur tout contrôle cliquable (boutons natifs, liens, rôles Radix). Les menus passent en pointer via composants UI. */
  button:not(:disabled):not([disabled]),
  a[href],
  summary,
  label[for] {
    cursor: pointer;
  }

  [role='button']:not([aria-disabled='true']),
  [role='tab']:not([aria-disabled='true']),
  [role='menuitem']:not([aria-disabled='true']):not([data-disabled]),
  [role='menuitemcheckbox']:not([aria-disabled='true']):not([data-disabled]),
  [role='menuitemradio']:not([aria-disabled='true']):not([data-disabled]),
  [role='option']:not([aria-disabled='true']):not([data-disabled]),
  [role='combobox']:not([aria-disabled='true']),
  [role='switch']:not([aria-disabled='true']),
  [role='radio']:not([aria-disabled='true']) {
    cursor: pointer;
  }

  button:disabled,
  button[disabled],
  [role='button'][aria-disabled='true'],
  [role='tab'][aria-disabled='true'],
  [role='menuitem'][aria-disabled='true'],
  [role='menuitem'][data-disabled],
  [role='option'][aria-disabled='true'],
  [role='option'][data-disabled],
  [role='combobox'][aria-disabled='true'] {
    cursor: not-allowed;
  }
}

/* Tiptap rich-text editor */
.tiptap {
  outline: none;
}
.tiptap p {
  margin: 0;
}
.tiptap ul,
.tiptap ol {
  padding-left: 1.5rem;
  margin: 0.25rem 0;
}
.tiptap ul {
  list-style-type: disc;
}
.tiptap ol {
  list-style-type: decimal;
}
.tiptap h1 {
  font-size: 1.5rem;
  font-weight: 700;
  margin: 0.5rem 0 0.25rem;
}
.tiptap h2 {
  font-size: 1.25rem;
  font-weight: 600;
  margin: 0.5rem 0 0.25rem;
}
.tiptap h3 {
  font-size: 1.1rem;
  font-weight: 600;
  margin: 0.25rem 0;
}
.tiptap blockquote {
  border-left: 3px solid #dadce0;
  padding-left: 0.75rem;
  margin: 0.5rem 0;
  color: #5f6368;
}
.tiptap a {
  color: #1a73e8;
  text-decoration: underline;
}
.tiptap code {
  background-color: #f1f3f4;
  border-radius: 3px;
  padding: 0.1rem 0.3rem;
  font-size: 0.875em;
}
.tiptap pre {
  background-color: #f1f3f4;
  border-radius: 4px;
  padding: 0.75rem;
  margin: 0.5rem 0;
  overflow-x: auto;
}
.tiptap pre code {
  background: none;
  padding: 0;
}

/* Sidebar nav DnD visual feedback (data-attribute driven, no React re-render) */
[data-nav-drag-source="true"] {
  opacity: 0.45;
}
[data-nav-drop="before"] {
  box-shadow: inset 0 2px 0 0 #1a73e8;
}
[data-nav-drop="after"] {
  box-shadow: inset 0 -2px 0 0 #1a73e8;
}
[data-nav-drop="inside"] {
  background-color: #e8f0fe;
  outline: 1px solid rgba(26, 115, 232, 0.4);
  outline-offset: -1px;
}

/* Mail shell: dynamic viewport height (tablet Safari chrome) + no document scroll */
html,
body {
  height: 100dvh;
  max-height: 100dvh;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

/* Tauri Android/iOS: respect status bar when edge-to-edge (viewport-fit: cover). */
html.native-shell body {
  padding-top: max(env(safe-area-inset-top, 0px), var(--native-safe-top, 0px));
  padding-bottom: env(safe-area-inset-bottom, 0px);
  box-sizing: border-box;
}

/* Native shells never use the web first-launch splash (blocks touch if left visible). */
html.native-shell .app-first-launch-splash {
  display: none !important;
  pointer-events: none !important;
}

/* Mail UI: text selection only in fields and message previews */
.ultimail-app {
  height: 100dvh;
  max-height: 100dvh;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

.ultimail-app input,
.ultimail-app textarea,
.ultimail-app select,
.ultimail-app [contenteditable="true"],
.ultimail-app [contenteditable=""],
.ultimail-app .tiptap,
.ultimail-app [data-selectable-text],
.ultimail-app [data-selectable-text] * {
  -webkit-user-select: text;
  user-select: text;
  -webkit-touch-callout: default;
}

.ultimail-app [data-sidebar] {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

/* Touch long-press acknowledgment (contact card, sidebar row menu, …) */
@keyframes long-press-ack {
  0% {
    transform: scale(1);
  }
  40% {
    transform: scale(0.94);
  }
  100% {
    transform: scale(1);
  }
}

.long-press-ack {
  animation: long-press-ack 0.28s cubic-bezier(0.2, 0.8, 0.2, 1);
  transform-origin: center;
}

/* First app open splashscreen */
@keyframes splash-aurora-drift {
  0% {
    transform: translate3d(-8%, -6%, 0) scale(1);
  }
  100% {
    transform: translate3d(8%, 6%, 0) scale(1.12);
  }
}

@keyframes splash-logo-float {
  0%,
  100% {
    transform: translateY(0px);
  }
  50% {
    transform: translateY(-5px);
  }
}

@keyframes splash-logo-spin {
  0% {
    transform: rotate(0deg);
  }
  14% {
    transform: rotate(36deg);
  }
  100% {
    transform: rotate(360deg);
  }
}

@keyframes splash-loader-progress {
  0% {
    transform: translateX(-104%);
  }
  100% {
    transform: translateX(104%);
  }
}

@keyframes splash-grain-pan {
  0% {
    transform: translate3d(0, 0, 0);
  }
  100% {
    transform: translate3d(-12%, -10%, 0);
  }
}

@keyframes splash-card-breathe {
  0%,
  100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.008);
  }
}

.app-first-launch-splash {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  padding: clamp(1rem, 3vw, 2rem);
  pointer-events: auto;
  background:
    radial-gradient(circle at 18% 20%, color-mix(in srgb, #1a73e8 32%, transparent) 0%, transparent 46%),
    radial-gradient(circle at 80% 15%, color-mix(in srgb, #34a853 26%, transparent) 0%, transparent 40%),
    radial-gradient(circle at 50% 100%, color-mix(in srgb, #ea4335 18%, transparent) 0%, transparent 55%),
    var(--app-canvas);
  transition:
    opacity 0.45s ease,
    visibility 0.45s ease;
}

html[data-splash-seen='1'] .app-first-launch-splash {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.app-first-launch-splash--hide {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.app-first-launch-splash__aurora {
  position: absolute;
  inset: -30%;
  pointer-events: none;
  background: conic-gradient(from 145deg, #1a73e8, #34a853, #fbbc04, #ea4335, #1a73e8);
  opacity: 0.12;
  filter: blur(clamp(56px, 8vw, 120px));
  animation: splash-aurora-drift 7.5s ease-in-out infinite alternate;
}

.app-first-launch-splash__grain {
  position: absolute;
  inset: -20%;
  pointer-events: none;
  opacity: 0.075;
  background-image: radial-gradient(rgb(255 255 255 / 55%) 0.75px, transparent 0.75px);
  background-size: 3px 3px;
  animation: splash-grain-pan 8s linear infinite alternate;
}

.app-first-launch-splash__content {
  position: relative;
  width: min(86vw, 420px);
  display: grid;
  gap: clamp(0.75rem, 1.7vw, 1.1rem);
  place-items: center;
  border: 1px solid color-mix(in srgb, var(--mail-border) 55%, transparent);
  border-radius: clamp(1rem, 2.8vw, 1.5rem);
  background: color-mix(in srgb, var(--mail-surface) 87%, transparent);
  box-shadow:
    0 20px 45px rgb(0 0 0 / 14%),
    inset 0 1px 0 rgb(255 255 255 / 45%);
  padding: clamp(1.25rem, 4.6vw, 2.2rem);
  backdrop-filter: blur(12px) saturate(135%);
  animation: splash-card-breathe 2.6s ease-in-out infinite;
}

.app-first-launch-splash__content::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  padding: 1px;
  background: linear-gradient(
    125deg,
    color-mix(in srgb, #1a73e8 58%, transparent),
    color-mix(in srgb, #34a853 45%, transparent),
    color-mix(in srgb, #ea4335 42%, transparent)
  );
  -webkit-mask:
    linear-gradient(#000 0 0) content-box,
    linear-gradient(#000 0 0);
  mask:
    linear-gradient(#000 0 0) content-box,
    linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  pointer-events: none;
  opacity: 0.75;
}

.app-first-launch-splash__pill {
  font-size: 0.66rem;
  letter-spacing: 0.16em;
  font-weight: 700;
  line-height: 1;
  padding: 0.4rem 0.62rem;
  border-radius: 999px;
  border: 1px solid color-mix(in srgb, var(--mail-border) 74%, transparent);
  background: color-mix(in srgb, var(--mail-surface) 84%, transparent);
  color: color-mix(in srgb, var(--mail-text) 92%, white 8%);
}

.app-first-launch-splash__subtitle {
  margin: -0.15rem 0 0;
  text-align: center;
  font-size: clamp(0.76rem, 1.6vw, 0.86rem);
  line-height: 1.3;
  color: color-mix(in srgb, var(--mail-text-muted) 92%, transparent);
}

.app-first-launch-splash__logo {
  animation: splash-logo-float 2s ease-in-out infinite;
}

.app-first-launch-splash__mark {
  transform-origin: center center;
}

.app-first-launch-splash__mark--spin {
  animation: splash-logo-spin 0.72s linear infinite;
}

.app-first-launch-splash__loader {
  width: min(58vw, 230px);
  height: 4px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--mail-border) 68%, transparent);
  overflow: hidden;
}

.app-first-launch-splash__loader > span {
  display: block;
  width: 58%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #1a73e8, #34a853, #1a73e8);
  animation: splash-loader-progress 1.05s ease-in-out infinite;
}

@media (prefers-reduced-motion: reduce) {
  .app-first-launch-splash__aurora,
  .app-first-launch-splash__grain,
  .app-first-launch-splash__content,
  .app-first-launch-splash__logo,
  .app-first-launch-splash__mark--spin,
  .app-first-launch-splash__loader > span {
    animation: none !important;
  }
}

/* ── Login : fond Aurore fixe (sm+), pas le fond mail utilisateur ── */
html:has(.ultimail-login)::before {
  opacity: 0 !important;
}

html:has(.ultimail-login) body {
  background-color: transparent !important;
}

/* ── Login : fond animé (orbes + grille + aurore), aligné sur la landing ── */
.ultimail-login {
  --login-bg: #f7f8fc;
  --login-line: rgba(21, 24, 30, 0.07);
  --login-glow-a: #4f6df5;
  --login-glow-b: #9a5cf0;
  --login-glow-c: #1fb6c9;
  --login-card-glass: rgba(255, 255, 255, 0.58);
  --login-card-glass-border: rgba(21, 24, 30, 0.1);
  --login-card-glass-highlight: rgba(255, 255, 255, 0.72);
  --login-card-glass-blur: 2px;
  --landing-glow-a: var(--login-glow-a);
  --landing-glow-b: var(--login-glow-b);
  --landing-glow-c: var(--login-glow-c);
  background-color: var(--login-bg);
  overflow: hidden;
}

.dark .ultimail-login {
  --login-bg: #0b0d12;
  --login-card-glass: rgba(12, 14, 20, 0.52);
  --login-card-glass-border: rgba(255, 255, 255, 0.09);
  --login-card-glass-highlight: rgba(255, 255, 255, 0.07);
  --login-text: #e8eaed;
  --login-text-strong: #ffffff;
  --login-text-muted: #bdc1c6;
  --login-text-link: #8ab4f8;
  --login-line: rgba(238, 240, 246, 0.08);
  --login-glow-a: #5d7bff;
  --login-glow-b: #a86bff;
  --login-glow-c: #2cc8dc;
}

.dark .ultimail-login [data-slot='card'] {
  color: var(--login-text);
}

.dark .ultimail-login [data-slot='card-description'],
.dark .ultimail-login [data-slot='card-footer'] p {
  color: var(--login-text-muted) !important;
}

.dark .ultimail-login [data-slot='card'] .font-bold {
  color: var(--login-text-strong);
}

.ultimail-login .landing-gradient-text {
  display: inline;
  background-image: linear-gradient(
    100deg,
    var(--login-glow-a) 0%,
    var(--login-glow-b) 28%,
    var(--login-glow-c) 55%,
    var(--login-glow-a) 80%
  );
  background-size: 220% 100%;
  background-repeat: repeat;
  background-clip: text;
  -webkit-background-clip: text;
  color: transparent !important;
  -webkit-text-fill-color: transparent !important;
  animation: landing-gradient-pan 9s linear infinite;
}

.dark .ultimail-login [data-slot='card'] a.text-primary {
  color: var(--login-text-link) !important;
}

.ultimail-login [data-slot='card'] {
  position: relative;
  isolation: isolate;
  background: transparent !important;
  border: 1px solid var(--login-card-glass-border) !important;
  box-shadow:
    inset 0 1px 0 var(--login-card-glass-highlight),
    0 10px 36px -14px rgb(0 0 0 / 18%);
}

.ultimail-login [data-slot='card']::before {
  content: '';
  position: absolute;
  inset: 0;
  z-index: 0;
  border-radius: inherit;
  background: var(--login-card-glass);
  -webkit-backdrop-filter: blur(var(--login-card-glass-blur)) saturate(1.45);
  backdrop-filter: blur(var(--login-card-glass-blur)) saturate(1.45);
  pointer-events: none;
}

.ultimail-login [data-slot='card'] > * {
  position: relative;
  z-index: 1;
}

.dark .ultimail-login [data-slot='card'] {
  box-shadow:
    inset 0 1px 0 var(--login-card-glass-highlight),
    0 14px 40px -16px rgb(0 0 0 / 55%);
}

.ultimail-login-backdrop {
  position: absolute;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  pointer-events: none;
}

.ultimail-login-backdrop::after {
  content: '';
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(to right, var(--login-line) 1px, transparent 1px),
    linear-gradient(to bottom, var(--login-line) 1px, transparent 1px);
  background-size: 56px 56px;
  mask-image: radial-gradient(ellipse 80% 70% at 50% 45%, black 30%, transparent 80%);
  -webkit-mask-image: radial-gradient(ellipse 80% 70% at 50% 45%, black 30%, transparent 80%);
}

.ultimail-login-aurora {
  position: absolute;
  inset: 0;
  background: radial-gradient(
    60% 50% at 50% 38%,
    color-mix(in oklab, var(--login-glow-a) 12%, transparent),
    transparent 70%
  );
}

.ultimail-login-orb {
  position: absolute;
  border-radius: 9999px;
  filter: blur(90px);
  opacity: 0.5;
  will-change: transform;
}

.dark .ultimail-login-orb {
  opacity: 0.4;
}

.ultimail-login-orb--a {
  width: 40rem;
  height: 40rem;
  top: -16rem;
  left: -12rem;
  background: radial-gradient(circle at 30% 30%, var(--login-glow-a), transparent 65%);
  animation: login-drift-a 26s ease-in-out infinite alternate;
}

.ultimail-login-orb--b {
  width: 34rem;
  height: 34rem;
  top: -10rem;
  right: -12rem;
  background: radial-gradient(circle at 60% 40%, var(--login-glow-b), transparent 65%);
  animation: login-drift-b 32s ease-in-out infinite alternate;
}

.ultimail-login-orb--c {
  width: 32rem;
  height: 32rem;
  bottom: -14rem;
  left: 50%;
  background: radial-gradient(circle at 50% 50%, var(--login-glow-c), transparent 65%);
  animation: login-drift-c 38s ease-in-out infinite alternate;
}

@keyframes login-drift-a {
  from {
    transform: translate3d(0, 0, 0) scale(1);
  }
  to {
    transform: translate3d(6rem, 4rem, 0) scale(1.12);
  }
}

@keyframes login-drift-b {
  from {
    transform: translate3d(0, 0, 0) scale(1.05);
  }
  to {
    transform: translate3d(-5rem, 6rem, 0) scale(0.94);
  }
}

@keyframes login-drift-c {
  from {
    transform: translate3d(-50%, 0, 0) scale(1);
  }
  to {
    transform: translate3d(-38%, -4rem, 0) scale(1.18);
  }
}

@media (prefers-reduced-motion: reduce) {
  .ultimail-login-orb {
    animation: none !important;
  }
}

/* ── Drive : pas de fond décoratif mail ── */
html[data-route-scope='drive']::before,
html:has([data-drive-app])::before {
  opacity: 0 !important;
}

html[data-route-scope='drive'] {
  background-color: var(--app-canvas);
}

html[data-route-scope='drive'] body {
  background-color: var(--app-canvas) !important;
}

@media (min-width: 640px) {
  .ultimail-login-card-frame {
    --login-card-outer-radius: 3rem;
    --login-card-border-width: 3px;
    position: relative;
    border-radius: var(--login-card-outer-radius);
    background: transparent;
    box-shadow: 0 16px 40px rgb(0 0 0 / 14%);
  }

  /* Arc-en-ciel confiné à l'anneau — le verre fumé floute le fond login, pas le gradient */
  .ultimail-login-card-frame::before {
    content: '';
    position: absolute;
    inset: 0;
    z-index: 2;
    border-radius: inherit;
    padding: var(--login-card-border-width);
    background: conic-gradient(
      from 145deg,
      #1a73e8,
      #34a853,
      #fbbc04,
      #ea4335,
      #1a73e8
    );
    pointer-events: none;
    -webkit-mask:
      linear-gradient(#fff 0 0) content-box,
      linear-gradient(#fff 0 0);
    -webkit-mask-composite: xor;
    mask:
      linear-gradient(#fff 0 0) content-box,
      linear-gradient(#fff 0 0);
    mask-composite: exclude;
  }

  .ultimail-login-card-frame > [data-slot='card'] {
    position: relative;
    z-index: 1;
    border-width: 0 !important;
    border-radius: var(--login-card-outer-radius) !important;
  }

  .dark .ultimail-login-card-frame {
    box-shadow: 0 16px 40px rgb(0 0 0 / 45%);
  }
}

/* Bouton connexion UltiSpace — fond noir cosmos */
@keyframes login-connect-border-spin {
  to {
    transform: rotate(360deg);
  }
}

@keyframes login-connect-shimmer {
  from {
    transform: translateX(-130%) skewX(-16deg);
    opacity: 0;
  }

  35% {
    opacity: 0.45;
  }

  to {
    transform: translateX(230%) skewX(-16deg);
    opacity: 0;
  }
}

.ultimail-login .ultimail-login-connect-border {
  position: relative;
  display: inline-flex;
  width: 100%;
  padding: 2px;
  border-radius: 9999px;
  overflow: hidden;
  isolation: isolate;
  background: transparent;
  box-shadow:
    0 8px 28px -12px rgb(0 0 0 / 70%),
    0 0 0 1px rgb(255 255 255 / 0.05);
  transition:
    transform 0.35s cubic-bezier(0.22, 1, 0.36, 1),
    box-shadow 0.35s ease;
}

.ultimail-login .ultimail-login-connect-border::before {
  content: '';
  position: absolute;
  inset: -120%;
  z-index: 0;
  transform-origin: center center;
  will-change: transform;
  background: conic-gradient(
    from 0deg,
    rgb(99 102 241 / 95%),
    rgb(168 85 247 / 90%) 25%,
    rgb(34 211 238 / 85%) 50%,
    rgb(129 140 248 / 90%) 75%,
    rgb(99 102 241 / 95%)
  );
  opacity: 0.85;
  transition: opacity 0.35s ease;
}

.ultimail-login .ultimail-login-connect-border:not(:hover)::before {
  animation: login-connect-border-spin 8s linear infinite;
}

.ultimail-login .ultimail-login-connect-border::after {
  content: '';
  position: absolute;
  inset: -1px;
  z-index: 0;
  border-radius: inherit;
  box-shadow:
    inset 0 0 0 1px rgb(255 255 255 / 0.08),
    0 0 18px -4px rgb(99 102 241 / 25%);
  pointer-events: none;
  opacity: 0.7;
  transform: scale(1);
  transition:
    box-shadow 0.45s cubic-bezier(0.22, 1, 0.36, 1),
    opacity 0.45s cubic-bezier(0.22, 1, 0.36, 1),
    transform 0.45s cubic-bezier(0.22, 1, 0.36, 1);
}

.dark .ultimail-login .ultimail-login-connect-border {
  box-shadow:
    0 8px 28px -12px rgb(0 0 0 / 80%),
    0 0 0 1px rgb(255 255 255 / 0.07);
}

.dark .ultimail-login .ultimail-login-connect-border::before {
  opacity: 0.95;
}

.ultimail-login .ultimail-login-connect-border:hover {
  transform: translateY(-3px) scale(1.015);
  box-shadow:
    0 20px 40px -14px rgb(0 0 0 / 75%),
    0 0 28px -6px rgb(99 102 241 / 45%),
    0 0 48px -12px rgb(34 211 238 / 25%);
}

.ultimail-login .ultimail-login-connect-border:hover::before {
  animation: none;
  transform: rotate(180deg);
  opacity: 1;
  transition:
    transform 0.65s cubic-bezier(0.22, 1, 0.36, 1),
    opacity 0.35s ease;
}

.ultimail-login .ultimail-login-connect-border:hover::after {
  opacity: 1;
  transform: scale(1.02);
  box-shadow:
    inset 0 0 0 1px rgb(255 255 255 / 0.14),
    0 0 24px -2px rgb(129 140 248 / 55%),
    0 0 40px -6px rgb(34 211 238 / 35%);
}

.ultimail-login .ultimail-login-connect-border:active {
  transform: translateY(-1px) scale(1.005);
  transition-duration: 0.12s;
}

.ultimail-login a.ultimail-login-connect-btn {
  position: relative;
  z-index: 1;
  isolation: isolate;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  width: 100%;
  height: 3rem;
  padding: 0 1.5rem;
  border: 0;
  border-radius: 9999px;
  overflow: hidden;
  font-size: 0.875rem;
  font-weight: 600;
  line-height: 1;
  white-space: nowrap;
  color: #fff !important;
  text-decoration: none !important;
  text-shadow: 0 1px 3px rgb(0 0 0 / 60%);
  background:
    radial-gradient(circle at 15% 25%, rgb(255 255 255 / 70%) 0, rgb(255 255 255 / 70%) 0.45px, transparent 1px),
    radial-gradient(circle at 62% 18%, rgb(255 255 255 / 55%) 0, rgb(255 255 255 / 55%) 0.4px, transparent 1px),
    radial-gradient(circle at 82% 68%, rgb(255 255 255 / 60%) 0, rgb(255 255 255 / 60%) 0.45px, transparent 1px),
    radial-gradient(circle at 35% 78%, rgb(255 255 255 / 45%) 0, rgb(255 255 255 / 45%) 0.35px, transparent 1px),
    radial-gradient(ellipse 70% 50% at 20% 0%, rgb(99 102 241 / 12%), transparent 55%),
    radial-gradient(ellipse 60% 45% at 90% 100%, rgb(34 211 238 / 8%), transparent 50%),
    linear-gradient(180deg, #050505 0%, #000 55%, #030303 100%) !important;
  background-size: 100% 100% !important;
  background-repeat: no-repeat !important;
  box-shadow:
    inset 0 1px 0 rgb(255 255 255 / 0.07),
    inset 0 -1px 0 rgb(0 0 0 / 0.5);
  transition:
    box-shadow 0.35s cubic-bezier(0.22, 1, 0.36, 1),
    filter 0.35s ease,
    letter-spacing 0.35s ease;
}

.ultimail-login a.ultimail-login-connect-btn > * {
  position: relative;
  z-index: 1;
}

.ultimail-login a.ultimail-login-connect-btn::before {
  content: '';
  position: absolute;
  inset: 0;
  z-index: -1;
  border-radius: inherit;
  background: radial-gradient(
    ellipse 90% 60% at 50% 0%,
    rgb(129 140 248 / 8%),
    transparent 70%
  );
  opacity: 0.85;
  pointer-events: none;
  transition:
    opacity 0.35s ease,
    transform 0.35s ease;
}

.ultimail-login a.ultimail-login-connect-btn::after {
  content: '';
  position: absolute;
  inset: 0;
  z-index: 0;
  border-radius: inherit;
  background: linear-gradient(
    105deg,
    transparent 35%,
    rgb(255 255 255 / 0.14) 50%,
    transparent 65%
  );
  transform: translateX(-130%) skewX(-16deg);
  opacity: 0;
  pointer-events: none;
}

.dark .ultimail-login a.ultimail-login-connect-btn {
  background:
    radial-gradient(circle at 15% 25%, rgb(255 255 255 / 75%) 0, rgb(255 255 255 / 75%) 0.45px, transparent 1px),
    radial-gradient(circle at 62% 18%, rgb(255 255 255 / 60%) 0, rgb(255 255 255 / 60%) 0.4px, transparent 1px),
    radial-gradient(circle at 82% 68%, rgb(255 255 255 / 65%) 0, rgb(255 255 255 / 65%) 0.45px, transparent 1px),
    radial-gradient(circle at 35% 78%, rgb(255 255 255 / 50%) 0, rgb(255 255 255 / 50%) 0.35px, transparent 1px),
    radial-gradient(ellipse 70% 50% at 20% 0%, rgb(129 140 248 / 14%), transparent 55%),
    radial-gradient(ellipse 60% 45% at 90% 100%, rgb(34 211 238 / 10%), transparent 50%),
    linear-gradient(180deg, #000 0%, #000 55%, #020202 100%) !important;
  background-size: 100% 100% !important;
  background-repeat: no-repeat !important;
}

.ultimail-login .ultimail-login-connect-border:hover a.ultimail-login-connect-btn {
  filter: brightness(1.14);
  letter-spacing: 0.01em;
  box-shadow:
    inset 0 1px 0 rgb(255 255 255 / 0.12),
    inset 0 -1px 0 rgb(0 0 0 / 0.4),
    inset 0 0 24px -8px rgb(99 102 241 / 35%);
}

.ultimail-login .ultimail-login-connect-border:hover a.ultimail-login-connect-btn::before {
  opacity: 1;
  transform: scale(1.08);
  background: radial-gradient(
    ellipse 100% 70% at 50% -10%,
    rgb(129 140 248 / 18%),
    transparent 72%
  );
}

.ultimail-login .ultimail-login-connect-border:hover a.ultimail-login-connect-btn::after {
  animation: login-connect-shimmer 0.85s cubic-bezier(0.22, 1, 0.36, 1) forwards;
}

@media (min-width: 640px) {
  .ultimail-login .ultimail-login-connect-border {
    width: auto;
  }
}

@media (prefers-reduced-motion: reduce) {
  .ultimail-login .ultimail-login-connect-border,
  .ultimail-login a.ultimail-login-connect-btn {
    transition: none;
  }

  .ultimail-login .ultimail-login-connect-border:not(:hover)::before,
  .ultimail-login .ultimail-login-connect-border::after,
  .ultimail-login .ultimail-login-connect-border:hover a.ultimail-login-connect-btn::after,
  .ultimail-login .landing-gradient-text {
    animation: none !important;
  }

  .ultimail-login .ultimail-login-connect-border:hover::before {
    transform: none;
  }

  .ultimail-login .ultimail-login-connect-border:hover::after {
    transform: none;
  }

  .ultimail-login .ultimail-login-connect-border:hover {
    transform: none;
  }

  .ultimail-login .ultimail-login-connect-border:active {
    transform: none;
  }
}

/* ── Mail : fond décoratif plein écran (derrière toute l’UI) ── */
html {
  background-color: var(--mail-bg-fallback, var(--app-canvas));
}

html::before {
  content: '';
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background: var(--mail-bg-layer, none);
  background-color: var(--mail-bg-fallback, transparent);
  opacity: 0;
  transition: opacity 0.25s ease;
}

html[data-mail-background]:not([data-mail-background='none'])::before {
  opacity: 1;
}

html[data-mail-background]:not([data-mail-background='none']) body {
  background-color: transparent !important;
}

html[data-mail-background]:not([data-mail-background='none']) .ultimail-app {
  background-color: transparent !important;
}

html[data-mail-background]:not([data-mail-background='none']) .ultimail-app :where(.bg-app-canvas) {
  background-color: color-mix(in srgb, var(--app-canvas) 78%, transparent) !important;
}

html[data-mail-background]:not([data-mail-background='none'])
  .ultimail-app
  :where(.bg-mail-surface, .bg-white) {
  background-color: color-mix(in srgb, var(--mail-surface) 88%, transparent) !important;
}

/* Drive : pas de fond décoratif mail — surfaces opaques (carte arrondie + chrome). */
html[data-mail-background]:not([data-mail-background='none']) [data-drive-app].ultimail-app {
  background-color: var(--app-canvas) !important;
}

html[data-mail-background]:not([data-mail-background='none']) [data-drive-app] :where(.bg-app-canvas) {
  background-color: var(--app-canvas) !important;
}

html[data-mail-background]:not([data-mail-background='none']) [data-drive-app] :where(.bg-mail-surface, .bg-white) {
  background-color: var(--mail-surface) !important;
}

html[data-mail-background]:not([data-mail-background='none']) [data-drive-app] :where(.bg-mail-surface-elevated) {
  background-color: var(--mail-surface-elevated) !important;
}

/* Contacts : pas de fond décoratif mail — surfaces opaques. */
html[data-mail-background]:not([data-mail-background='none']) [data-contacts-app].ultimail-app {
  background-color: var(--app-canvas) !important;
}

html[data-mail-background]:not([data-mail-background='none']) [data-contacts-app] :where(.bg-app-canvas) {
  background-color: var(--app-canvas) !important;
}

html[data-mail-background]:not([data-mail-background='none']) [data-contacts-app] :where(.bg-mail-surface, .bg-white) {
  background-color: var(--mail-surface) !important;
}

html[data-mail-background]:not([data-mail-background='none']) [data-contacts-app] :where(.bg-mail-surface-elevated) {
  background-color: var(--mail-surface-elevated) !important;
}

html[data-mail-background]:not([data-mail-background='none']) [data-contacts-app] :where(.bg-mail-surface-muted) {
  background-color: var(--mail-surface-muted) !important;
}

/* Agenda : pas de fond décoratif mail — surfaces opaques (carte arrondie + chrome). */
html[data-mail-background]:not([data-mail-background='none']) [data-agenda-app].ultimail-app {
  background-color: var(--app-canvas) !important;
}

html[data-mail-background]:not([data-mail-background='none']) [data-agenda-app] :where(.bg-app-canvas) {
  background-color: var(--app-canvas) !important;
}

html[data-mail-background]:not([data-mail-background='none']) [data-agenda-app] :where(.bg-mail-surface, .bg-white) {
  background-color: var(--mail-surface) !important;
}

html[data-mail-background]:not([data-mail-background='none']) [data-agenda-app] :where(.bg-mail-surface-elevated) {
  background-color: var(--mail-surface-elevated) !important;
}

html[data-mail-background]:not([data-mail-background='none']) [data-agenda-app] [data-agenda-calendar-card] {
  background-color: var(--mail-surface) !important;
}

/* Réglages / administration / compte : fond décoratif visible uniquement derrière la sidebar (contenu opaque). */
html[data-mail-background]:not([data-mail-background='none']) [data-mail-settings-app].ultimail-app,
html[data-mail-background]:not([data-mail-background='none']) [data-admin-settings-app].ultimail-app,
html[data-mail-background]:not([data-mail-background='none']) [data-compte-settings-app].ultimail-app {
  background-color: var(--app-canvas) !important;
}

html[data-mail-background]:not([data-mail-background='none'])
  [data-mail-settings-app]
  [data-mail-settings-sidebar],
html[data-mail-background]:not([data-mail-background='none'])
  [data-admin-settings-app]
  [data-admin-settings-sidebar],
html[data-mail-background]:not([data-mail-background='none'])
  [data-compte-settings-app]
  [data-compte-settings-sidebar] {
  background-color: color-mix(in srgb, var(--app-canvas) 72%, transparent) !important;
}

html[data-mail-background]:not([data-mail-background='none'])
  [data-mail-settings-app]
  :where([data-mail-settings-main]),
html[data-mail-background]:not([data-mail-background='none'])
  [data-admin-settings-app]
  :where([data-admin-settings-main]),
html[data-mail-background]:not([data-mail-background='none'])
  [data-compte-settings-app]
  :where([data-compte-settings-main]) {
  background-color: var(--mail-surface) !important;
}

.ultimail-app {
  position: relative;
  isolation: isolate;
  --border: var(--mail-border);
  --input: var(--mail-border);
}

/* Lignes de liste */
.bg-mail-row-unread {
  background-color: var(--mail-row-unread);
}
.bg-mail-row-read {
  background-color: var(--mail-row-read);
}
.bg-mail-row-selected {
  background-color: var(--mail-row-selected);
}
.bg-mail-row-active-split {
  background-color: var(--mail-row-active-split);
}
.bg-mail-nav-selected {
  background-color: var(--mail-nav-selected);
}
.text-mail-nav-selected {
  color: var(--mail-nav-selected-fg);
}
.bg-mail-nav-hover {
  background-color: var(--mail-nav-hover);
}
.bg-mail-nav-drop {
  background-color: var(--mail-nav-drop);
}
.bg-mail-invitation {
  background-color: var(--mail-invitation);
}

/**
 * Sidebar frosted strips — backdrop blur hides children scrolling behind sticky parents (sm+).
 * Background stays transparent so there is no tint — the blur alone conceals the text.
 */
.ultimail-app .mail-sidebar-blur-surface {
  background-color: transparent;
  -webkit-backdrop-filter: blur(24px) saturate(150%);
  backdrop-filter: blur(24px) saturate(150%);
}

/**
 * Hover-expanded sidebar frosted panel — uses ::before so it doesn't create
 * a backdrop-filter stacking context that would clip children's backdrop-filters.
 */
.ultimail-app .mail-sidebar-hover-frosted::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  -webkit-backdrop-filter: blur(24px) saturate(150%);
  backdrop-filter: blur(24px) saturate(150%);
  pointer-events: none;
}

/**
 * Sticky sidebar strip — blur spans full rail width (not just indented label).
 * Set --sidebar-sticky-pad-left on the element (px indent of row content).
 */
.ultimail-app .mail-sidebar-blur-sticky-strip {
  position: relative;
  isolation: isolate;
}

.ultimail-app .mail-sidebar-blur-sticky-strip::before {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: calc(-1 * var(--sidebar-sticky-pad-left, 0px));
  right: calc(-1 * var(--sidebar-nav-rail-inset, 14px));
  z-index: 0;
  background-color: transparent;
  -webkit-backdrop-filter: blur(24px) saturate(150%);
  backdrop-filter: blur(24px) saturate(150%);
  pointer-events: none;
}

.ultimail-app .mail-sidebar-blur-sticky-strip > * {
  position: relative;
  z-index: 1;
}

/**
 * Sidebar overlay (touch / xs) — fond opaque.
 * Nom hors préfixe bg-* pour éviter qu’un utility Tailwind écrase la règle.
 */
.ultimail-app .mail-sidebar-overlay-panel {
  background-color: #ffffff;
}

html.dark .ultimail-app .mail-sidebar-overlay-panel {
  background-color: var(--background);
}

html[data-mail-background]:not([data-mail-background='none']) .ultimail-app .mail-sidebar-overlay-panel {
  background-color: #ffffff !important;
}

html.dark[data-mail-background]:not([data-mail-background='none'])
  .ultimail-app
  .mail-sidebar-overlay-panel {
  background-color: var(--background) !important;
}

/* ── Mail : mode sombre (surcharges ciblées dans le shell) ── */
html.dark .ultimail-app {
  color-scheme: dark;
  /* Tokens shadcn → gris mail (cards réglages, popovers, champs). */
  --background: var(--app-canvas);
  --foreground: var(--mail-text);
  --card: var(--mail-surface-elevated);
  --card-foreground: var(--mail-text);
  --popover: var(--mail-surface-elevated);
  --popover-foreground: var(--mail-text);
  --secondary: var(--mail-surface-muted);
  --secondary-foreground: var(--mail-text);
  --muted: var(--mail-surface-muted);
  --muted-foreground: var(--mail-text-muted);
  --accent: var(--mail-nav-hover);
  --accent-foreground: var(--mail-text);
  --border: var(--mail-border);
  --input: var(--mail-border);
  --ring: var(--mail-border);
}

html.dark .ultimail-app :where(.bg-white) {
  background-color: var(--mail-surface) !important;
}

html.dark .ultimail-app :where(
  .bg-\[\#f1f3f4\],
  .bg-\[\#f8f9fa\],
  .bg-\[\#fafbfc\],
  .bg-\[\#edf2fc\],
  .bg-\[\#eaf1fb\],
  .bg-\[\#f6f9fe\],
  .bg-\[\#f5f5f5\],
  .bg-\[\#e8eaed\]
) {
  background-color: var(--mail-surface-muted) !important;
}

html.dark .ultimail-app :where(.bg-\[\#e8f0fe\]) {
  background-color: var(--mail-active) !important;
}

html.dark .ultimail-app :where(.bg-white\/80, .bg-white\/90, .bg-white\/95) {
  background-color: color-mix(in srgb, var(--mail-surface) 82%, transparent) !important;
}

html.dark .ultimail-app :where(.bg-gray-200) {
  background-color: var(--mail-surface-muted) !important;
}

html.dark .ultimail-app :where(.hover\:bg-\[\#f1f3f4\]:hover, .hover\:bg-\[\#f6f9fe\]:hover, .hover\:bg-gray-100:hover) {
  background-color: var(--mail-hover) !important;
}

html.dark .ultimail-app :where(.border-gray-200, .border-\[\#dadce0\], .border-\[\#eceff1\]) {
  border-color: var(--mail-border-subtle) !important;
}

html.dark .ultimail-app :where(.divide-gray-200 > :not(:last-child), .divide-\[\#eceff1\] > :not(:last-child)) {
  border-color: var(--mail-border-subtle) !important;
}

html.dark .ultimail-app :where(.text-gray-900, .text-gray-800, .text-gray-700, .text-\[\#202124\], .text-\[\#3c4043\], .text-\[\#1f1f1f\]) {
  color: var(--mail-text) !important;
}

html.dark .ultimail-app :where(.text-gray-600, .text-gray-500, .text-\[\#5f6368\], .text-\[\#444746\]) {
  color: var(--mail-text-muted) !important;
}

html.dark .ultimail-app :where(.text-gray-400, .text-\[\#c2c2c2\]) {
  color: #80868b !important;
}

html.dark .ultimail-app :where(.shadow-sm, .shadow-lg) {
  --tw-shadow-color: rgb(0 0 0 / 0.35);
}

html.dark .ultimail-app :where(input, textarea, select) {
  background-color: var(--mail-surface-muted);
  color: var(--mail-text);
  border-color: var(--mail-border-subtle);
}

html.dark .ultimail-app :where(.tiptap blockquote) {
  border-left-color: var(--mail-border);
  color: var(--mail-text-muted);
}

html.dark .ultimail-app :where(.tiptap code, .tiptap pre) {
  background-color: var(--mail-surface-muted);
}

/* Portails Radix (rendus hors .ultimail-app) — bordures/champs alignés sur le gris mail */
:where(
  [data-slot='dialog-content'],
  [data-slot='alert-dialog-content'],
  [data-slot='popover-content'],
  [data-slot='hover-card-content'],
  [data-slot='dropdown-menu-content'],
  [data-slot='dropdown-menu-sub-content'],
  [data-slot='context-menu-content'],
  [data-slot='context-menu-sub-content'],
  [data-slot='select-content'],
  [data-slot='menubar-content'],
  [data-slot='menubar-sub-content'],
  [data-slot='tooltip-content'],
  [data-slot='sheet-content'],
  [data-slot='drawer-content']
) {
  --border: var(--mail-border);
  --input: var(--mail-border);
}

/* ── Dark : portails Radix (rendus hors .ultimail-app) ── */
html.dark :where(
  [data-slot='dialog-content'],
  [data-slot='alert-dialog-content'],
  [data-slot='popover-content'],
  [data-slot='hover-card-content'],
  [data-slot='dropdown-menu-content'],
  [data-slot='dropdown-menu-sub-content'],
  [data-slot='context-menu-content'],
  [data-slot='context-menu-sub-content'],
  [data-slot='select-content'],
  [data-slot='menubar-content'],
  [data-slot='menubar-sub-content'],
  [data-slot='tooltip-content'],
  [data-slot='sheet-content'],
  [data-slot='drawer-content']
) {
  --background: var(--mail-surface-elevated);
  --foreground: var(--mail-text);
  --popover: var(--mail-surface-elevated);
  --popover-foreground: var(--mail-text);
  --card: var(--mail-surface-elevated);
  --card-foreground: var(--mail-text);
  --secondary: var(--mail-surface-muted);
  --secondary-foreground: var(--mail-text);
  --muted: var(--mail-surface-muted);
  --muted-foreground: var(--mail-text-muted);
  --accent: var(--mail-nav-hover);
  --accent-foreground: var(--mail-text);
  --border: var(--mail-border);
  --input: var(--mail-border);
  --ring: var(--mail-border);
  background-color: var(--mail-surface-elevated) !important;
  color: var(--mail-text) !important;
  border-color: var(--mail-border) !important;
}

html.dark :where([data-slot='dialog-content'], [data-slot='sheet-content'])
  :where([data-slot='input'], textarea, [data-slot='select-trigger']:not([data-variant='ghost'])) {
  background-color: var(--mail-surface-muted) !important;
  border-color: var(--mail-border) !important;
  color: var(--mail-text) !important;
}

/* Drive dialogs — fond plus foncé que les modales mail */
html.dark .drive-dialog[data-slot='dialog-content'],
html.dark .drive-dialog[data-slot='sheet-content'] {
  background-color: #292a2d !important;
  border-color: #3c4043 !important;
}

html.dark .drive-dialog[data-slot='dialog-content'] [data-slot='dialog-footer'],
html.dark .drive-dialog[data-slot='sheet-content'] [data-slot='sheet-footer'] {
  background-color: #252628 !important;
  border-color: #3c4043 !important;
}

html.dark .drive-dialog [data-slot='select-trigger'][data-variant='ghost'] {
  background-color: transparent !important;
  border-color: transparent !important;
}

html.dark .drive-dialog [data-slot='select-trigger'][data-variant='ghost']:hover,
html.dark .drive-dialog [data-slot='select-trigger'][data-variant='ghost'][data-state='open'] {
  background-color: transparent !important;
}

html.dark :where([data-slot='dialog-content'], [data-slot='sheet-content']) fieldset.border {
  border-color: var(--mail-border) !important;
}

/* Drive / Contacts : menus portés — gris mail, pas le noir `popover`. */
html.dark [data-drive-menu-surface],
html.dark [data-contacts-menu-surface] {
  background-color: var(--mail-surface-elevated) !important;
  color: var(--mail-text) !important;
  border-color: var(--mail-border-subtle) !important;
}

html.dark [data-drive-menu-surface] [data-slot='dropdown-menu-item']:focus,
html.dark [data-drive-menu-surface] [data-slot='dropdown-menu-item'][data-highlighted],
html.dark [data-drive-menu-surface] [data-slot='context-menu-item']:focus,
html.dark [data-drive-menu-surface] [data-slot='context-menu-item'][data-highlighted],
html.dark [data-contacts-menu-surface] [data-slot='dropdown-menu-item']:focus,
html.dark [data-contacts-menu-surface] [data-slot='dropdown-menu-item'][data-highlighted],
html.dark [data-contacts-menu-surface] [data-slot='dropdown-menu-sub-trigger']:focus,
html.dark [data-contacts-menu-surface] [data-slot='dropdown-menu-sub-trigger'][data-state='open'],
html.dark [data-contacts-menu-surface] [data-slot='select-item']:focus,
html.dark [data-contacts-menu-surface] [data-slot='select-item'][data-highlighted] {
  background-color: var(--mail-nav-hover) !important;
  color: var(--mail-text) !important;
}

html.dark [data-slot='dropdown-menu-item']:focus,
html.dark [data-slot='dropdown-menu-item'][data-highlighted],
html.dark [data-slot='dropdown-menu-sub-trigger']:focus,
html.dark [data-slot='dropdown-menu-sub-trigger'][data-state='open'],
html.dark [data-slot='context-menu-item']:focus,
html.dark [data-slot='context-menu-item'][data-highlighted],
html.dark [data-slot='context-menu-sub-trigger']:focus,
html.dark [data-slot='context-menu-sub-trigger'][data-state='open'] {
  background-color: var(--mail-nav-hover) !important;
  color: var(--mail-text) !important;
}

html.dark [data-slot='dropdown-menu-separator'],
html.dark [data-slot='context-menu-separator'] {
  background-color: var(--mail-border-subtle) !important;
}

/* Recherche avancée — champs (sheet xs + panneau dropdown desktop) */
html.dark :where([data-mail-mobile-search], [data-mail-search-advanced])
  :where([data-slot='input'], [data-slot='select-trigger']) {
  background-color: var(--mail-surface-muted) !important;
  border: 1px solid var(--mail-border) !important;
  color: var(--mail-text) !important;
}

/* Priorité sur .ultimail-app input { border-color: mail-border-subtle } */
html.dark .ultimail-app [data-mail-search-advanced]
  :where([data-slot='input'], [data-slot='select-trigger']) {
  background-color: var(--mail-surface-muted) !important;
  border: 1px solid var(--mail-border) !important;
  color: var(--mail-text) !important;
}

html.dark :where([data-mail-mobile-search], [data-mail-search-advanced])
  :where([data-slot='checkbox']) {
  background-color: var(--mail-surface-muted) !important;
  border: 1.5px solid var(--mail-row-checkbox-border) !important;
}

html.dark .ultimail-app [data-mail-search-advanced] :where([data-slot='checkbox']) {
  background-color: var(--mail-surface-muted) !important;
  border: 1.5px solid var(--mail-row-checkbox-border) !important;
}

html.dark .ultimail-app :where(.hover\:bg-gray-50:hover, .hover\:bg-gray-100:hover) {
  background-color: var(--mail-nav-hover) !important;
}

html.dark .ultimail-app :where(.bg-\[\#d3e3fd\]) {
  background-color: var(--mail-nav-selected) !important;
}

html.dark .ultimail-app :where(.bg-yellow-100) {
  background-color: var(--mail-nav-drop) !important;
}

html.dark .ultimail-app :where(.text-\[#0f172a\], .text-\[#0b57d0\]) {
  color: var(--foreground) !important;
}

html.dark
  :where(
    .ultimail-app,
    [data-slot='dialog-content'],
    [data-slot='popover-content'],
    [data-slot='sheet-content']
  )
  :where([data-slot='checkbox'][data-state='checked'], [data-slot='checkbox'][data-state='indeterminate']) {
  background-color: #1a73e8;
  border-color: #1a73e8;
}

/* ── Dark : fenêtre de composition ── */
html.dark [data-compose-window] {
  color: var(--foreground);
}

html.dark [data-compose-window] :where(.text-\[\#202124\], .text-\[\#3c4043\]) {
  color: var(--foreground) !important;
}

html.dark [data-compose-window] :where(.text-\[\#5f6368\], .text-\[\#80868b\]) {
  color: var(--muted-foreground) !important;
}

html.dark [data-compose-window] :where(.hover\:bg-\[\#f1f3f4\]:hover, .hover\:bg-\[\#f6f9fe\]:hover) {
  background-color: var(--accent) !important;
}

html.dark [data-compose-window] :where(.bg-\[\#e8eaed\], .bg-\[\#e8f0fe\]) {
  background-color: var(--accent) !important;
  color: var(--accent-foreground) !important;
}

html.dark [data-compose-window] .compose-toolbar :where(.bg-\[\#e8eaed\]) {
  background-color: var(--accent) !important;
}

/* Iframes d’aperçu mail : fond du navigateur, pas blanc par défaut */
html.dark .ultimail-app iframe[title='Contenu du message'],
html.dark .ultimail-app iframe[title='Sujet du message'] {
  background: transparent !important;
  color-scheme: dark;
}

/* Hovercard destinataire (portail Radix hors .ultimail-app) */
html.dark [data-contact-hover-card] {
  color-scheme: dark;
}

html.dark [data-contact-hover-card] :where(.text-\[\#202124\], .text-\[\#3c4043\], .text-\[\#1f1f1f\]) {
  color: var(--foreground) !important;
}

html.dark [data-contact-hover-card] :where(.text-\[\#5f6368\], .text-\[\#444746\]) {
  color: var(--muted-foreground) !important;
}

html.dark [data-contact-hover-card] :where(.text-\[\#001d35\]) {
  color: var(--foreground) !important;
}

html.dark [data-contact-hover-card] :where(.bg-\[\#d3e3fd\]) {
  background-color: var(--mail-nav-selected) !important;
}

html.dark [data-contact-hover-card] :where(.hover\:bg-\[\#c4d9fc\]:hover) {
  background-color: var(--mail-active) !important;
}

html.dark [data-contact-hover-card] :where(.hover\:bg-\[\#f1f3f4\]:hover) {
  background-color: var(--accent) !important;
}

html.dark [data-contact-hover-card] :where(.bg-\[\#f1f3f4\]) {
  background-color: var(--accent) !important;
}

html.dark [data-contact-hover-card] :where(.hover\:bg-\[\#e8eaed\]:hover) {
  background-color: var(--accent) !important;
}

html.dark [data-contact-hover-card] :where(.text-\[\#1a73e8\]) {
  color: #8ab4f8 !important;
}

html.dark [data-contact-hover-card] :where(.border-\[\#eceff1\]) {
  border-color: var(--border) !important;
}

/* ── Dark : panneau Contacts (formulaires) ── */
html.dark :where([data-contacts-panel] .bg-white) {
  background-color: var(--mail-surface) !important;
}

html.dark :where([data-contacts-panel] .text-\[\#1f1f1f\], [data-contacts-panel] .text-\[\#3c4043\]) {
  color: var(--foreground) !important;
}

html.dark :where([data-contacts-panel] .text-\[\#5f6368\]) {
  color: var(--muted-foreground) !important;
}

html.dark :where([data-contacts-panel] .hover\:bg-gray-100:hover, [data-contacts-panel] .hover\:bg-\[\#f5f5f5\]:hover) {
  background-color: var(--accent) !important;
}

html.dark :where([data-contacts-panel] .border-gray-200, [data-contacts-panel] .border-gray-300) {
  border-color: var(--border) !important;
}

/* Réglages mail / compte : cartes cohérentes en dark mode (fond + bordure plus visible) */
html.dark [data-mail-settings-main],
html.dark [data-compte-settings-main] {
  --border: var(--mail-border);
}

html.dark [data-mail-settings-main] :where(
  .mail-settings-card,
  [data-slot='card'],
  [class*='rounded-lg'].border,
  [class*='rounded-xl'].border,
  [class*='rounded-md'].border
):not(.mail-settings-masonry-section) {
  background-color: var(--mail-surface-elevated) !important;
  border-color: var(--mail-border) !important;
}

@media (min-width: 1024px) {
  html.dark [data-mail-settings-main] .mail-settings-masonry-section {
    background-color: var(--mail-surface-elevated) !important;
    border-color: var(--mail-border) !important;
  }
}

html.dark [data-mail-settings-main] :where(
  [class*='rounded-lg'][class*='border-dashed'],
  [class*='rounded-xl'][class*='border-dashed'],
  [class*='rounded-md'][class*='border-dashed']
) {
  border-color: color-mix(in srgb, var(--mail-border) 72%, transparent) !important;
}

html.dark [data-compte-settings-main] :where(
  .mail-settings-card,
  [data-slot='card'],
  [class*='rounded-lg'].border,
  [class*='rounded-xl'].border,
  [class*='rounded-md'].border,
  [class*='rounded-2xl'].border
) {
  background-color: var(--mail-surface-elevated) !important;
  border-color: var(--mail-border) !important;
}

/* Settings / Drive : cartes et champs internes — gris mail, pas le noir shadcn */
html.dark .ultimail-app :where(.bg-background) {
  background-color: var(--mail-surface-muted) !important;
}

html.dark .ultimail-app :where(.bg-muted\/10, .bg-muted\/20, .bg-muted\/30, .bg-muted\/40) {
  background-color: color-mix(in srgb, var(--mail-surface-muted) 72%, transparent) !important;
}

html.dark .ultimail-app :where([data-slot='input'], [data-slot='select-trigger'], [data-slot='textarea']) {
  background-color: var(--mail-surface-muted) !important;
  border-color: var(--mail-border) !important;
  color: var(--mail-text) !important;
}
