@import 'tailwindcss';
@import 'tw-animate-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;
}

.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;
  --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.396 0.141 25.723);
  --destructive-foreground: oklch(0.637 0.237 25.331);
  --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);
}

@theme inline {
  --font-sans: 'Geist', 'Geist Fallback';
  --font-mono: 'Geist Mono', 'Geist Mono Fallback';
  --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-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);
}

@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%;
}

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

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

.ultimail-app {
  position: relative;
  isolation: isolate;
}

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

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([class*='bg-white/']) {
  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);
}

/* ── Dark : portails Radix & toasts (rendus hors .ultimail-app) ── */
html.dark [data-slot='dropdown-menu-content'],
html.dark [data-slot='dropdown-menu-sub-content'],
html.dark [data-slot='context-menu-content'],
html.dark [data-slot='context-menu-sub-content'],
html.dark [data-slot='popover-content'],
html.dark [data-slot='select-content'],
html.dark [data-slot='menubar-content'] {
  background-color: var(--popover) !important;
  color: var(--popover-foreground) !important;
  border-color: var(--border) !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(--accent) !important;
  color: var(--accent-foreground) !important;
}

html.dark [data-slot='dropdown-menu-separator'],
html.dark [data-slot='context-menu-separator'] {
  background-color: var(--border) !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 .ultimail-app :where([data-slot='checkbox']) {
  background-color: transparent;
  border-color: #9aa0a6;
}

html.dark .ultimail-app :where([data-slot='checkbox'][data-state='checked']) {
  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;
}

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