@import "@fontsource-variable/inter";
@import "tailwindcss";
@import "@agent-native/core/styles/agent-native.css";
@import "@agent-native/toolkit/styles.css";

@source "./**/*.{ts,tsx}";

:root {
  --background: 0 0% 100%;
  --foreground: 0 0% 10%;
  --card: 0 0% 100%;
  --card-foreground: 0 0% 10%;
  --popover: 0 0% 100%;
  --popover-foreground: 0 0% 10%;
  --primary: 0 0% 15%;
  --primary-foreground: 0 0% 100%;
  --secondary: 0 0% 95%;
  --secondary-foreground: 0 0% 15%;
  --muted: 0 0% 95%;
  --muted-foreground: 0 0% 45%;
  --accent: 0 0% 95%;
  --accent-foreground: 0 0% 15%;
  --destructive: 0 84% 60%;
  --destructive-foreground: 0 0% 98%;
  --border: 0 0% 90%;
  --input: 0 0% 90%;
  --ring: 0 0% 40%;
  --chart-1: 0 0% 20%;
  --chart-2: 155 36% 42%;
  --chart-3: 32 55% 50%;
  --chart-4: 270 25% 55%;
  --chart-5: 350 38% 55%;
  --chart-6: 190 25% 48%;
  --radius: 0.5rem;
  --sidebar-background: 0 0% 97%;
  --sidebar-foreground: 0 0% 45%;
  --sidebar-primary: 0 0% 15%;
  --sidebar-primary-foreground: 0 0% 100%;
  --sidebar-accent: 0 0% 95%;
  --sidebar-accent-foreground: 0 0% 15%;
  --sidebar-border: 0 0% 90%;
  --sidebar-ring: 0 0% 40%;

  /* --- CRM surface tokens -------------------------------------------------
     Geometry for the grid/record/board surfaces. Utilities generated from
     these live in the `@theme inline` block below; the raw vars here exist for
     `calc()`, virtualizer math, and arbitrary values. */

  /* Fixed grid metrics. There is no density toggle: rows are always 36px. */
  --crm-row-h: 36px;
  --crm-header-h: 40px;
  --crm-cell-px: 12px;
  --crm-cell-pt: 8px;

  /* Hairline used on BOTH grid axes. Near-invisible by design — a divider you
     can read at a glance is already too dark. */
  --crm-hairline: hsl(var(--foreground) / 0.07);

  /* Overlay alphas. Hover and selection animate this OPACITY on a dedicated
     layer; they never swap background-color (see `.crm-overlay`). */
  --crm-overlay-hover: 0.04;
  --crm-overlay-hover-strong: 0.08;
  --crm-overlay-selected: 0.1;

  /* The single knob for "selected/active" tint. Our skin has no brand hue, so
     selection derives from --primary; repoint this one var if that changes. */
  --crm-accent: var(--primary);

  /* Shadows are blue-black, never neutral grey, and always carry a hairline
     ring in the same stack so elevation and outline can never disagree. */
  --crm-shadow: 219 39% 18%;
  --crm-shadow-sticky: 6px 0 16px 4px hsl(var(--crm-shadow) / 0.12);
  --crm-elevation-1:
    0 0 0 1px hsl(var(--crm-shadow) / 0.06),
    0 1px 2px -1px hsl(var(--crm-shadow) / 0.1);
  --crm-elevation-2:
    0 0 0 1px hsl(var(--crm-shadow) / 0.06),
    0 4px 12px -2px hsl(var(--crm-shadow) / 0.12),
    0 2px 4px -2px hsl(var(--crm-shadow) / 0.08);
  --crm-elevation-3:
    0 0 0 1px hsl(var(--crm-shadow) / 0.05),
    0 16px 40px -8px hsl(var(--crm-shadow) / 0.2),
    0 4px 10px -4px hsl(var(--crm-shadow) / 0.1);

  /* Motion scale. --motion-comfortable is the app default (see
     --default-transition-duration). Zeroed under prefers-reduced-motion. */
  --motion-fast: 80ms;
  --motion-comfortable: 140ms;
  --motion-breezy: 200ms;
  --motion-sluggish: 300ms;
  --motion-sloth: 400ms;
}

.dark {
  --background: 0 0% 13%;
  --foreground: 0 0% 90%;
  --card: 0 0% 15%;
  --card-foreground: 0 0% 90%;
  --popover: 0 0% 15%;
  --popover-foreground: 0 0% 90%;
  --primary: 0 0% 75%;
  --primary-foreground: 0 0% 10%;
  --secondary: 0 0% 18%;
  --secondary-foreground: 0 0% 90%;
  --muted: 0 0% 16%;
  --muted-foreground: 0 0% 60%;
  --accent: 0 0% 18%;
  --accent-foreground: 0 0% 96%;
  --destructive: 0 84% 60%;
  --destructive-foreground: 0 0% 98%;
  --border: 0 0% 24%;
  --input: 0 0% 24%;
  --ring: 0 0% 60%;
  --chart-1: 0 0% 78%;
  --chart-2: 155 32% 58%;
  --chart-3: 32 50% 62%;
  --chart-4: 270 28% 68%;
  --chart-5: 350 38% 66%;
  --chart-6: 190 28% 62%;
  --sidebar-background: 0 0% 10%;
  --sidebar-foreground: 0 0% 60%;
  --sidebar-primary: 0 0% 75%;
  --sidebar-primary-foreground: 0 0% 10%;
  --sidebar-accent: 0 0% 16%;
  --sidebar-accent-foreground: 0 0% 90%;
  --sidebar-border: 0 0% 20%;
  --sidebar-ring: 0 0% 60%;

  /* Dark dividers stay subtractive — a line darker than the surface, not a
     lighter one. An alpha-white hairline here reads as a seam, not a grid. */
  --crm-hairline: hsl(0 0% 0% / 0.16);
  --crm-shadow: 219 45% 6%;
  --crm-shadow-sticky: 6px 0 16px 4px hsl(var(--crm-shadow) / 0.4);
  --crm-elevation-1:
    0 0 0 1px hsl(0 0% 100% / 0.06), 0 1px 2px -1px hsl(var(--crm-shadow) / 0.5);
  --crm-elevation-2:
    0 0 0 1px hsl(0 0% 100% / 0.06),
    0 4px 12px -2px hsl(var(--crm-shadow) / 0.55),
    0 2px 4px -2px hsl(var(--crm-shadow) / 0.4);
  --crm-elevation-3:
    0 0 0 1px hsl(0 0% 100% / 0.05),
    0 16px 40px -8px hsl(var(--crm-shadow) / 0.65),
    0 4px 10px -4px hsl(var(--crm-shadow) / 0.45);
}

/* `inline` so every value resolves against the element's own cascade — that is
   what lets one utility follow --foreground/--crm-shadow across light/dark. */
@theme inline {
  /* Radii, by the thing they wrap. `rounded-lg` (8px) already covers buttons
     and menu items, so it is not restated here. */
  --radius-badge: 4px;
  --radius-chip: 10px;
  --radius-row: 11px;
  --radius-card: 12px;
  --radius-column: 16px;
  --radius-panel: 20px;
  --radius-avatar-company: 30%;

  /* Content ramp: alpha over the surface, never solid greys, so text
     composites correctly on tinted cells and hover overlays. */
  --color-content-secondary: hsl(var(--foreground) / 0.63);
  --color-content-tertiary: hsl(var(--foreground) / 0.5);
  --color-content-ghost: hsl(var(--foreground) / 0.38);
  --color-hairline: var(--crm-hairline);

  --shadow-e1: var(--crm-elevation-1);
  --shadow-e2: var(--crm-elevation-2);
  --shadow-e3: var(--crm-elevation-3);

  --tracking-ui: -0.02em;
  --tracking-body: -0.01em;

  /* 400/500/600 only. Capping the weight namespace means a stray `font-bold`
     anywhere in the app renders 600 instead of shipping a heavier voice. */
  --font-weight-bold: 600;
  --font-weight-extrabold: 600;
  --font-weight-black: 600;

  /* Makes every bare `transition-*` in the app 140ms without touching a
     component. Named steps stay available as duration-[var(--motion-*)]. */
  --default-transition-duration: var(--motion-comfortable);
  --ease-drop: cubic-bezier(0.45, 0, 0.2, 1);
}

@layer base {
  * {
    @apply border-border;
  }
  html,
  body {
    @apply bg-background text-foreground;
    font-family: "Inter Variable", Inter, sans-serif;
    font-feature-settings: "cv02", "cv03", "cv04", "cv11";
    letter-spacing: var(--tracking-ui);
  }
  /* Body and caption sizes ride a touch looser than the -0.02em UI default.
     Zero specificity, so any `tracking-*` utility still wins. */
  :where(p, small, figcaption, .text-sm, .text-xs) {
    letter-spacing: var(--tracking-body);
  }
  :where(b, strong) {
    font-weight: 600;
  }
}

@layer components {
  /* Hover/selection primitive. The overlay is a real layer whose OPACITY
     animates; swapping background-color instead loses the composite over
     tinted cells and cannot cross-fade. Host may be static or positioned —
     Tailwind's position utilities sit in a later layer and still win. */
  .crm-overlay {
    position: relative;
    isolation: isolate;
  }
  .crm-overlay::before {
    content: "";
    position: absolute;
    inset: 0;
    z-index: -1;
    border-radius: inherit;
    pointer-events: none;
    background: hsl(var(--foreground));
    opacity: 0;
    transition:
      opacity var(--motion-comfortable) ease-in-out,
      background-color var(--motion-comfortable) ease-in-out;
  }
  .crm-overlay:hover::before,
  .crm-overlay[data-hovered="true"]::before {
    opacity: var(--crm-overlay-hover);
  }
  .crm-overlay[data-selected="true"]::before {
    background: hsl(var(--crm-accent));
    opacity: var(--crm-overlay-selected);
  }
  /* Cells select without the accent tint — the row already carries it. */
  .crm-overlay-soft[data-selected="true"]::before {
    background: hsl(var(--foreground));
    opacity: var(--crm-overlay-hover-strong);
  }
}

@media (prefers-reduced-motion: reduce) {
  :root {
    --motion-fast: 0ms;
    --motion-comfortable: 0ms;
    --motion-breezy: 0ms;
    --motion-sluggish: 0ms;
    --motion-sloth: 0ms;
  }
  /* Zeroing the vars only covers what opts into them. 0.01ms rather than 0 so
     transitionend/animationend still fire for components that unmount on them. */
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

::-webkit-scrollbar {
  width: 5px;
  height: 5px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  border-radius: 3px;
  background: hsl(var(--border));
}

.crm-chat-intro {
  display: none;
}
.crm-chat-panel [data-agent-empty-state="centered"] {
  justify-content: center;
  padding-bottom: clamp(4rem, 12vh, 8rem);
}
.crm-chat-panel [data-agent-empty-state="centered"] .crm-chat-intro {
  display: grid;
  width: 100%;
  max-width: min(670px, 90%);
  gap: 0.5rem;
  margin: 0 auto 1rem;
  text-align: center;
}
.crm-chat-intro h1 {
  margin: 0;
  font-size: clamp(1.75rem, 2.5vw, 2.5rem);
  font-weight: 600;
  letter-spacing: -0.03em;
  line-height: 1.1;
}
.crm-chat-intro p {
  margin: 0;
  color: hsl(var(--muted-foreground));
  font-size: 0.9375rem;
  line-height: 1.5;
}
.crm-chat-panel [data-agent-empty-state="centered"] .agent-chat-scroll {
  flex: 0 0 auto;
  min-height: 0;
  overflow: visible;
}
.crm-chat-panel [data-agent-empty-state="centered"] .agent-composer-area {
  width: 100%;
  max-width: min(670px, 90%);
  padding: 0;
}
.crm-chat-panel [data-agent-empty-state="centered"] .agent-composer-root {
  min-height: 7.5rem;
  border-color: hsl(var(--border));
  border-radius: 1rem;
  background: hsl(var(--card));
  box-shadow: none;
}
.crm-chat-panel
  [data-agent-empty-state="centered"]
  .agent-composer-prosemirror {
  min-height: 4.75rem;
  font-size: 1rem;
  line-height: 1.625rem;
}

@media (max-width: 767px) {
  .crm-chat-panel [data-agent-empty-state="centered"] {
    padding: 1rem;
    padding-bottom: 5rem;
  }
  .crm-chat-panel [data-agent-empty-state="centered"] .agent-composer-area,
  .crm-chat-panel [data-agent-empty-state="centered"] .crm-chat-intro {
    max-width: 100%;
  }
}
