@import "tailwindcss";

@source "../../views/**/*.erb";
@source "../../helpers/**/*.rb";
@source "../../javascript/**/*.js";

/* Cornerstone design tokens (ref -> sys -> cmp), scoped by data-brand/data-theme on <html> */
@import "@cruglobal/cornerstone-design-system/css/ref";
@import "@cruglobal/cornerstone-design-system/css/cru-light";
@import "@cruglobal/cornerstone-design-system/css/cru-dark";

/* daisyUI + Cornerstone's daisyUI theme bridge (cru-light / cru-dark) */
@plugin "daisyui" {
  themes: false;
}
@import "../../../node_modules/@cruglobal/cornerstone-design-system/libraries/daisyui.css";

/* Map Tailwind utility colors onto Cornerstone sys tokens so bg-surface,
   text-on-surface, border-outline, etc. re-skin via the cascade. */
@theme inline {
  --color-surface: var(--sys-color-surface-default);
  --color-surface-low: var(--sys-color-surface-container-low);
  --color-surface-container: var(--sys-color-surface-container);
  --color-surface-high: var(--sys-color-surface-container-high);
  --color-surface-highest: var(--sys-color-surface-container-highest);
  --color-surface-bright: var(--sys-color-surface-bright);
  --color-on-surface: var(--sys-color-on-surface);
  --color-muted: var(--sys-color-on-surface-variant);
  --color-outline: var(--sys-color-outline-variant-default);
  --color-outline-strong: var(--sys-color-outline-default);
  --color-divider: var(--sys-color-divider);
  --color-brand: var(--sys-color-primary-default);
  --color-on-brand: var(--sys-color-on-primary);
  --color-danger: var(--sys-color-danger-default);
  --color-on-danger: var(--sys-color-on-danger);
  --color-success-tone: var(--sys-color-success-default);
  --color-warning-tone: var(--sys-color-warning-default);
  --color-info-tone: var(--sys-color-information-default);
  --color-link: var(--sys-color-link-default);

  --font-display: var(--sys-string-font-family-display);
  --font-headline: var(--sys-string-font-family-headline);
  --font-body: var(--sys-string-font-family-body);
}

@layer base {
  html {
    @apply h-full;
  }
  body {
    @apply h-full bg-surface text-on-surface font-body antialiased text-[13px];
  }
  ::-webkit-scrollbar {
    width: 8px;
    height: 8px;
  }
  ::-webkit-scrollbar-thumb {
    background: var(--sys-color-outline-variant-default);
    border-radius: 4px;
  }
  ::-webkit-scrollbar-track {
    background: transparent;
  }
}

@layer components {
  /* App shell */
  .fd-rail-btn {
    @apply flex flex-col items-center gap-1 px-2 py-1.5 rounded-md text-muted transition-colors
      hover:text-on-surface hover:bg-surface-high cursor-pointer text-[10px];
  }
  .fd-rail-btn.active {
    @apply text-on-surface bg-surface-high;
  }
  .fd-side-link {
    @apply flex items-center gap-2 px-2 py-1.5 rounded-md text-[13px] text-muted transition-colors
      hover:bg-surface-high hover:text-on-surface;
  }
  .fd-side-link.active {
    @apply bg-surface-high text-on-surface;
  }

  /* Square icon button used in the top bar (hamburger, search, help, inbox) */
  .fd-icon-btn {
    @apply inline-flex items-center justify-center size-9 rounded-md text-muted transition-colors
      hover:text-on-surface hover:bg-surface-high cursor-pointer shrink-0;
  }

  /* Property chips on work item rows/cards */
  .fd-chip {
    @apply inline-flex items-center gap-1 rounded-sm border border-outline px-1.5 py-0.5
      text-[11px] leading-4 text-muted transition-colors hover:bg-surface-high cursor-pointer whitespace-nowrap;
  }

  /* Plane-style ↑N ↓N vote counts in the work-item header (FD-188) */
  .fd-vote {
    @apply inline-flex items-center gap-0.5 rounded-md border border-outline px-1.5 h-7
      text-[12px] text-muted transition-colors hover:bg-surface-high hover:text-on-surface cursor-pointer;
  }
  .fd-vote-on {
    @apply border-brand text-on-surface;
  }

  .fd-input {
    @apply input input-sm bg-surface-low border-outline w-full rounded-md text-[13px]
      focus:outline-none focus:border-outline-strong;
  }

  /* Plane-style collapsible groups in the Properties rail (Details / Project structure) */
  .fd-prop-group {
    @apply border-t border-divider/60 pt-2 mt-2 first:border-0 first:pt-0 first:mt-0;
  }
  .fd-prop-group-summary {
    @apply flex items-center gap-1 cursor-pointer list-none select-none py-0.5
      text-[12px] font-medium text-on-surface;
  }
  .fd-prop-group-summary::-webkit-details-marker { display: none; }
  .fd-prop-group-chevron {
    @apply text-[10px] leading-none text-muted transition-transform;
  }

  /* Plane-style property picker: trigger pill + popover panel */
  .fd-prop-pill {
    @apply inline-flex items-center gap-1.5 w-full rounded-md border border-transparent px-1.5 py-1
      text-[12px] text-on-surface text-left transition-colors cursor-pointer
      hover:bg-surface-high hover:border-outline focus:outline-none focus:bg-surface-high focus:border-outline-strong;
  }
  .fd-date-pill {
    @apply bg-transparent border border-transparent rounded-md px-1.5 py-1 text-[12px] w-full
      transition-colors hover:bg-surface-high hover:border-outline focus:outline-none focus:border-outline-strong;
  }
  /* Inline variants for the under-title property strip (Plane shows State/Priority/
     Assignees/dates as a row of discrete pills beneath the title). */
  .fd-prop-pill-inline {
    @apply inline-flex items-center gap-1.5 rounded-md border border-outline px-2 py-1
      text-[12px] text-on-surface transition-colors cursor-pointer whitespace-nowrap
      hover:bg-surface-high focus:outline-none focus:border-outline-strong;
  }
  .fd-date-pill-inline {
    @apply inline-flex items-center rounded-md border border-outline bg-transparent px-2 py-1 text-[12px]
      transition-colors hover:bg-surface-high focus:outline-none focus:border-outline-strong;
  }
  .fd-popover {
    @apply absolute left-0 top-full mt-1 z-50 w-64 max-w-[80vw] rounded-lg border border-outline
      bg-surface shadow-lg overflow-hidden;
  }
  .fd-popover-list {
    @apply max-h-64 overflow-y-auto p-1 flex flex-col;
  }
  .fd-popover-opt {
    @apply flex items-center gap-2 px-2 py-1.5 rounded-md text-[12px] cursor-pointer
      transition-colors hover:bg-surface-high;
  }
  .fd-popover-check {
    @apply ml-auto shrink-0 text-brand opacity-0;
  }
  .fd-popover-opt .peer:checked ~ .fd-popover-check { @apply opacity-100; }
  .fd-popover-opt:has(.peer:checked) { @apply bg-surface-high/60; }
  /* daisyUI 5's .btn carries no cursor, and Tailwind v4 dropped the old
     button→pointer default, so add it here for <button> elements (links already
     get pointer). */
  .fd-btn-primary {
    @apply btn btn-sm btn-primary rounded-md font-medium cursor-pointer;
  }
  .fd-btn-ghost {
    @apply btn btn-sm btn-ghost rounded-md font-normal border border-outline cursor-pointer;
  }

  .fd-card {
    @apply bg-surface-low border border-outline rounded-lg;
  }

  /* Kanban — full-ish width columns on phones (swipe between), fixed on desktop */
  .fd-kanban-col {
    @apply w-[86vw] max-w-[320px] shrink-0 flex flex-col rounded-lg bg-surface-low/60 snap-start
      md:w-[320px] md:max-w-none;
  }
  .fd-kanban-card {
    @apply bg-surface-low border border-outline rounded-lg p-3 flex flex-col gap-2 cursor-pointer hover:bg-surface-container shadow-sm;
  }
  .fd-kanban-card.sortable-ghost {
    @apply opacity-40 border-dashed border-outline-strong;
  }

  /* Rich text (Action Text, rendered read-only) */
  .fd-prose {
    @apply max-w-none leading-relaxed text-[13px];
  }
  .fd-prose h1 { @apply text-xl font-semibold mt-4 mb-2 font-headline; }
  .fd-prose h2 { @apply text-lg font-semibold mt-3 mb-1.5 font-headline; }
  .fd-prose h3 { @apply text-base font-semibold mt-2 mb-1; }
  .fd-prose ul { @apply list-disc pl-5 my-1.5; }
  .fd-prose ol { @apply list-decimal pl-5 my-1.5; }
  .fd-prose a { @apply text-link underline; }
  .fd-prose pre { @apply bg-surface-high rounded-md p-3 my-2 overflow-x-auto text-xs; }
  .fd-prose blockquote { @apply border-l-2 border-outline-strong pl-3 text-muted my-2; }
  .fd-prose img { @apply rounded-md my-2 max-w-full; }

  /* Help center long-form docs */
  .help-doc h1 { @apply text-2xl font-headline font-semibold mb-3; }
  .help-doc h2 { @apply text-base font-headline font-semibold mt-6 mb-2; }
  .help-doc p { @apply my-2 leading-relaxed text-[13px]; }
  .help-doc ul, .help-doc ol { @apply my-2 leading-relaxed; }
  .help-doc li { @apply my-1; }
  .help-doc code { @apply bg-surface-high border border-outline rounded px-1 py-0.5 text-[11px]; }
  .help-doc kbd { @apply kbd kbd-sm; }
  .help-doc strong { @apply text-on-surface; }
  .help-doc .not-prose a, .help-doc .not-prose div { @apply no-underline text-on-surface; }
  .help-doc .not-prose .text-muted { @apply text-muted; }
  .help-doc table { @apply w-full my-3 text-[12px] border border-outline rounded-lg; }
  .help-doc th { @apply text-left text-muted font-medium px-3 py-1.5 border-b border-outline bg-surface-low; }
  .help-doc td { @apply px-3 py-1.5 border-b border-divider align-top; }


  /* FD-208: Tiptap block editor (progressive enhancement of Action Text fields) */
  .fd-block-editor {
    @apply bg-surface-low border border-outline rounded-md overflow-hidden focus-within:border-outline-strong;
  }
  .fd-block-toolbar {
    @apply flex flex-wrap items-center gap-0.5 px-1.5 py-1 border-b border-outline bg-surface-low/60;
  }
  .fd-block-btn {
    @apply inline-flex items-center justify-center min-w-7 h-7 px-1.5 rounded text-[12px] text-muted
      cursor-pointer hover:bg-surface-high hover:text-on-surface transition-colors;
  }
  .fd-block-sep { @apply w-px h-4 mx-1 bg-outline; }
  .fd-block-surface { @apply min-h-64 p-3 overflow-y-auto relative; } /* FD-69: relative anchors presence carets */
  .fd-block-surface--compact { @apply min-h-16; } /* FD-212: comment composers */
  .fd-block-content { @apply outline-none; }
  .fd-block-content > :first-child { @apply mt-0; }
  /* Placeholder text on the empty first line (Tiptap Placeholder extension). */
  .fd-block-content p.is-editor-empty:first-child::before {
    content: attr(data-placeholder);
    @apply text-muted float-left h-0 pointer-events-none;
  }

  /* FD-69: real-time editing presence — avatar roster, remote carets, concurrency banner. */
  .fd-presence-bar { @apply flex items-center ml-auto pl-2 pr-1; }
  .fd-presence-avatar {
    @apply inline-flex items-center justify-center w-6 h-6 rounded-full text-[10px] font-semibold
      text-white ring-2 ring-surface-low -ml-1.5 first:ml-0 select-none;
  }
  .fd-presence-banner {
    @apply hidden items-center gap-2 px-3 py-1.5 text-[12px] text-on-surface bg-surface-high border-b border-outline;
  }
  .fd-presence-banner.is-active { @apply flex; }
  .fd-presence-caret { @apply absolute z-20 w-0.5 -ml-px pointer-events-none rounded-sm; }
  .fd-presence-caret-flag {
    @apply absolute -top-4 left-0 px-1 rounded text-[9px] leading-4 text-white whitespace-nowrap select-none;
  }

  /* FD-267: CollaborationCaret remote carets (colors are injected inline per user). */
  .collaboration-carets__caret {
    border-left: 1px solid currentColor;
    border-right: 1px solid currentColor;
    margin-left: -1px;
    margin-right: -1px;
    pointer-events: none;
    position: relative;
    word-break: normal;
  }
  .collaboration-carets__label {
    @apply text-[10px] font-semibold text-white whitespace-nowrap select-none;
    border-radius: 3px 3px 3px 0;
    left: -1px;
    line-height: normal;
    padding: 0.1rem 0.3rem;
    position: absolute;
    top: -1.4em;
  }
  .collaboration-carets__selection { border-radius: 0.1em; }

  /* FD-209: slash "/" command menu popup (appended to <body>, page-positioned). */
  .fd-slash-menu {
    @apply absolute z-[60] min-w-44 max-h-72 overflow-y-auto p-1 rounded-md border border-outline
      bg-surface-low shadow-lg text-[13px];
  }
  .fd-slash-item {
    @apply block w-full text-left px-2 py-1.5 rounded cursor-pointer text-on-surface hover:bg-surface-high;
  }
  .fd-slash-item.is-selected { @apply bg-surface-high; }
  .fd-slash-empty { @apply px-2 py-1.5 text-muted; }

  /* FD-209: to-do (task) lists — styled for both the editor and the read-only render. */
  [data-type="taskList"] { @apply list-none pl-0 my-1.5; }
  [data-type="taskItem"] { @apply flex items-start gap-2; }
  [data-type="taskItem"] > label { @apply mt-1 shrink-0; }
  [data-type="taskItem"] > div { @apply flex-1; }
  [data-type="taskItem"] > div > p { @apply my-0; }

  /* FD-210: table controls — hidden until the controller flags the caret in a table. */
  .fd-block-table-ops { @apply hidden items-center; }
  .fd-block-toolbar.is-in-table .fd-block-table-ops { @apply inline-flex; }

  /* FD-210: tables + callouts — styled for both the editor and the read-only render. */
  .fd-prose table, .fd-block-content table { @apply w-full my-3 text-[12px] border border-outline rounded-lg border-collapse; }
  .fd-prose th, .fd-block-content th { @apply text-left font-medium px-3 py-1.5 border border-outline bg-surface-low; }
  .fd-prose td, .fd-block-content td { @apply px-3 py-1.5 border border-outline align-top; }
  .fd-block-content .selectedCell { @apply bg-brand/10; } /* Tiptap cell selection */
  [data-type="callout"] {
    @apply my-2 px-3 py-2 rounded-md border-l-2 border-brand bg-surface-high/40;
  }
  [data-type="callout"] > :first-child { @apply mt-0; }
  [data-type="callout"] > :last-child { @apply mb-0; }

  /* FD-211: block-editor image/file attachments (the editor nodeView). */
  .fd-block-attachment { @apply my-2; }
  .fd-block-attachment img { @apply max-w-full rounded-md; }
  .fd-block-attachment.ProseMirror-selectednode img { @apply outline outline-2 outline-brand; }
  .fd-block-file-chip {
    @apply inline-flex items-center gap-1 px-2 py-1 rounded-md border border-outline bg-surface-high text-[12px] text-muted;
  }
}

/* Safe-area insets for installed PWA / notched devices (no-ops on desktop). */
.pt-safe { padding-top: env(safe-area-inset-top); }
.pb-safe { padding-bottom: env(safe-area-inset-bottom); }
.pl-safe { padding-left: env(safe-area-inset-left); }
.pr-safe { padding-right: env(safe-area-inset-right); }

/* Keyboard focus visibility for interactive shell controls. */
.fd-icon-btn:focus-visible,
.fd-side-link:focus-visible,
.fd-rail-btn:focus-visible {
  outline: 2px solid var(--color-brand);
  outline-offset: -1px;
}

/* Roomier tap targets on touch / small screens (desktop density unchanged). */
@media (max-width: 767px) {
  .fd-side-link { padding-top: 0.5rem; padding-bottom: 0.5rem; }
  .fd-icon-btn { width: 2.75rem; height: 2.75rem; }
  .fd-rail-btn { min-height: 2.75rem; justify-content: center; }
  /* Smoother momentum scrolling for horizontal surfaces (board, spreadsheet). */
  .fd-scroll-x { scroll-snap-type: x proximity; -webkit-overflow-scrolling: touch; }
}

/* Respect reduced-motion: disable the drawer slide / scrim fade transitions. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }
}
