@import "tailwindcss";

/* =============================================================================
   Calem App — "Calem Authority" design system.
   Tokens are synced from design-system/tokens/theme.css (single source of truth)
   and inlined here as `@theme static` so every token is always emitted (Tailwind
   v4 tree-shakes vars that are only referenced from component CSS). The shared
   theme.css is left pristine; see design-system/NOTES.md.

   The palette spends almost nothing on colour and everything on contrast +
   warmth. Exactly ONE saturated accent — Amber (--color-action) — is reserved
   for the single primary action per screen + the app-icon `c`.
   ============================================================================= */
@theme static {
  /* ---- Brand + neutrals ------------------------------------------------- */
  --color-ink: #1f3a34;          /* tokens: hero / text-primary  ~11:1 on bone (AAA) */
  --color-ink-deep: #152823;     /* ink hover / pressed          ~14:1 on bone */
  --color-bone: #f7f4ef;         /* canvas — warm off-white, never stark white */
  --color-porcelain: #ffffff;    /* elevated surface — cards, panels, inputs */
  --color-mist: #e4dfd6;         /* hairlines, dividers, input outlines, skeletons */
  --color-stone: #5c655f;        /* text-secondary               ~5.6:1 on bone (AA) */
  --color-stone-light: #646c66;  /* text-muted (>=16px)          ~4.9:1 on bone */

  /* ---- The one reserved action colour (Amber) --------------------------- */
  /* tokens: used ONLY for the single primary CTA per screen + the app-icon `c`. */
  --color-action: #b45309;       /* tokens: white text ~5.0:1 (AA all sizes) */
  --color-action-deep: #963f07;  /* CTA hover/pressed + focus-ring base */

  /* ---- Semantic (always paired with an icon — never hue alone) ---------- */
  --color-success: #2e6b4f;      /* Success Pine — confirmed, paid/published */
  --color-warning: #8a5a12;      /* Ochre — honest scarcity; tint+icon, NEVER a button */
  --color-error: #b42318;        /* Alert Red — validation, destructive */
  --color-info: #dce6e0;         /* Sage Wash — info tints, selected chips, hero wash */
  --color-success-wash: #e7efe9; /* tint of Success Pine — confirmed / paid status pills */
  --color-error-wash: #f6e5e2;   /* tint of Alert Red — cancelled / day-off status pills */

  /* ---- Calendar / staff categorical palette (data-viz exception) -------- */
  /* Muted, warm hues that distinguish staff members; never UI chrome/actions. */
  --color-staff-1: #1f3a34; /* pine / ink   */
  --color-staff-2: #8a5a12; /* ochre        */
  --color-staff-3: #3f6d7d; /* slate teal   */
  --color-staff-4: #2e6b4f; /* success pine */
  --color-staff-5: #7c5e8c; /* muted plum   */
  --color-staff-6: #9c5a3c; /* clay         */
  --color-staff-7: #4a5b8c; /* muted indigo */
  --color-staff-8: #5c655f; /* stone        */

  /* ---- Type ------------------------------------------------------------- */
  /* Fraunces = display serif (wordmark + headlines); Plus Jakarta Sans = body/UI.
     Loaded as <link> in the layouts. */
  --font-jakarta: "Plus Jakarta Sans", system-ui, sans-serif;
  --font-fraunces: "Fraunces", Georgia, serif;
  --default-font-family: var(--font-jakarta);
  --default-mono-font-family: ui-monospace, "JetBrains Mono", monospace;

  /* Restrained, calm motion (150–250ms) */
  --ease-calm: cubic-bezier(0.4, 0, 0.2, 1);
}

/* Map brand fonts to Tailwind's font-* utilities (inline = reference live vars). */
@theme inline {
  --font-sans: var(--font-jakarta), system-ui, sans-serif;
  --font-display: var(--font-fraunces), Georgia, serif;
  --font-serif: var(--font-fraunces), Georgia, serif;
}

/* =============================================================================
   Base layer — typographic + accessibility defaults that define the look.
   ============================================================================= */
@layer base {
  :root {
    color-scheme: light;
  }

  html {
    scroll-behavior: smooth;
    scroll-padding-top: 5rem;
    scroll-padding-bottom: 7rem;
    -webkit-text-size-adjust: 100%;
  }

  body {
    background-color: var(--color-bone);
    color: var(--color-ink);
    font-family: var(--font-sans);
    font-size: 1rem; /* 16px min everywhere */
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
  }

  /* Headlines: editorial Fraunces with its optical-size axis enabled. */
  h1, h2, h3, h4 {
    font-family: var(--font-display);
    font-optical-sizing: auto;
    font-weight: 420;
    line-height: 1.1;
    letter-spacing: -0.01em;
    text-wrap: balance;
    color: var(--color-ink);
  }

  p { text-wrap: pretty; }

  /* Longer Spanish paragraphs get 1.6 line-height (~25–30% text expansion). */
  :lang(es) p,
  :lang(es) li { line-height: 1.6; }

  /* Visible 3:1 action-deep focus ring on every interactive element (WCAG 2.4.13). */
  :focus-visible {
    outline: 3px solid var(--color-action-deep);
    outline-offset: 2px;
    border-radius: 2px;
  }

  /* On dark (Ink) surfaces use a Bone ring so it clears 3:1 on field AND button. */
  .bg-ink :focus-visible,
  .bg-ink:focus-visible {
    outline-color: var(--color-bone);
  }

  /* Links inherit ink — amber is reserved for the action, never links. */
  a {
    color: inherit;
    text-underline-offset: 0.2em;
  }

  ::selection {
    background-color: color-mix(in srgb, var(--color-info) 80%, transparent);
    color: var(--color-ink);
  }

  /* Respect reduced-motion: disable non-essential transitions/animation. */
  @media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
      animation-duration: 0.01ms !important;
      animation-iteration-count: 1 !important;
      transition-duration: 0.01ms !important;
      scroll-behavior: auto !important;
    }
  }
}

/* =============================================================================
   Components — calm, hairline-first, >=44px targets, ease-calm motion.
   ============================================================================= */
@layer components {
  /* The ONE primary action per screen. Amber lives here and only here (+ .app-icon). */
  .btn-primary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    min-height: 2.75rem; /* 44px touch target */
    padding: 0.625rem 1.25rem;
    border-radius: 0.75rem; /* rounded-xl */
    font-weight: 600;
    line-height: 1.2;
    color: var(--color-porcelain);
    background-color: var(--color-action);
    box-shadow: 0 1px 2px 0 rgb(21 40 35 / 0.08); /* calm shadow-sm */
    transition:
      background-color 180ms var(--ease-calm),
      transform 150ms var(--ease-calm);
  }
  .btn-primary:hover { background-color: var(--color-action-deep); }
  .btn-primary:active { transform: translateY(1px); }
  .btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

  /* Secondary / neutral action — Ink hairline, never Amber. */
  .btn-secondary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    min-height: 2.75rem;
    padding: 0.625rem 1.25rem;
    border-radius: 0.75rem;
    font-weight: 600;
    line-height: 1.2;
    color: var(--color-ink);
    background-color: var(--color-porcelain);
    border: 1px solid var(--color-mist);
    transition:
      background-color 180ms var(--ease-calm),
      border-color 180ms var(--ease-calm),
      transform 150ms var(--ease-calm);
  }
  .btn-secondary:hover {
    background-color: var(--color-bone);
    border-color: var(--color-stone-light);
  }
  .btn-secondary:active { transform: translateY(1px); }

  /* Wordmark — always lowercase, monochrome Ink, in Fraunces. */
  .wordmark {
    font-family: var(--font-display);
    font-weight: 440;
    letter-spacing: -0.015em;
    text-transform: lowercase;
    color: var(--color-ink);
  }
  /* On Ink/dark surfaces the wordmark reverses to Bone. */
  .wordmark-reverse { color: var(--color-bone); }

  /* App-icon `c` — the rounded Amber square mark. Amber is allowed here. */
  .app-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-family: var(--font-display);
    font-weight: 500;
    text-transform: lowercase;
    line-height: 1;
    color: var(--color-porcelain);
    background-color: var(--color-action);
    border-radius: 0.75rem;
  }
}

/* =============================================================================
   Brand utilities — hairlines instead of heavy shadows, paper grain, washes.
   ============================================================================= */
@utility hairline {
  border: 1px solid var(--color-mist);
}

@utility wash-sage {
  background-image: linear-gradient(
    180deg,
    color-mix(in srgb, var(--color-info) 60%, var(--color-bone)) 0%,
    var(--color-bone) 100%
  );
}

@utility grain {
  position: relative;
  &::after {
    content: "";
    position: absolute;
    inset: 0;
    z-index: 0;
    pointer-events: none;
    opacity: 0.035;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  }
}

/* =============================================================================
   Brand button component classes (from main's brand pass). Available where a
   view opts into a component class instead of inline utilities. Amber .btn-primary
   stays the single reserved CTA; .btn-ink is the default dark action.
   ============================================================================= */
@layer components {
  .btn-primary {
    @apply inline-flex items-center justify-center gap-2 rounded-xl
           bg-action px-5 py-3 font-sans text-base font-medium text-white
           transition-colors duration-200
           hover:bg-action-deep
           focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-action-deep focus-visible:ring-offset-2 focus-visible:ring-offset-bone
           disabled:opacity-50 disabled:pointer-events-none;
  }

  .btn-ink {
    @apply inline-flex items-center justify-center gap-2 rounded-xl
           bg-ink px-5 py-3 font-sans text-base font-medium text-bone
           transition-colors duration-200
           hover:bg-ink-deep
           focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ink focus-visible:ring-offset-2 focus-visible:ring-offset-bone
           disabled:opacity-50 disabled:pointer-events-none;
  }

  .btn-secondary {
    @apply inline-flex items-center justify-center gap-2 rounded-xl
           border border-mist bg-porcelain px-5 py-3 font-sans text-base font-medium text-ink
           transition-colors duration-200
           hover:bg-bone
           focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ink focus-visible:ring-offset-2 focus-visible:ring-offset-bone
           disabled:opacity-50 disabled:pointer-events-none;
  }
}
