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

.dark {
  --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);
}

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