/* Sapporta design tokens and base rules. Shipped as raw CSS — this file
   does NOT `@import "tailwindcss"`. It is declarative theme data that
   expects a Tailwind v4 pipeline to be running upstream, i.e. a consumer
   `app.css` that does:

     @import "tailwindcss";
     @import "@sapporta/ui/index.css";
     @source "./";

   Two parallel `@import "tailwindcss"` (one in the library, one in the
   consumer) re-emit Tailwind's defaults into @layer theme and clobber
   each other's tokens on source order. One pipeline owned by the
   consumer keeps the cascade predictable: Tailwind defaults → Sapporta
   tokens → user overrides.

   Font loading sits in the consumer's index.html (as a <link> tag), not
   here, so apps can swap family / self-host / pick a loading strategy
   without forking this file. */

/* Scan this package's own source for Tailwind utility classes. Path is
   relative to this file, so it resolves both in dev (src/) and when
   shipped (dist/). Tailwind v4 excludes node_modules from automatic
   content detection, so without this @source a consumer's Tailwind
   pipeline would only see their own classes — not the ones used by
   components in this package. */
@source "./";

/* ────────────────────────────────────────────────────────────────────────────
 * Design tokens
 *
 * Two palettes with identical structure — the refined-shadcn direction from
 * the Sapporta design explorations. Data-role names (positive/negative, not
 * debit/credit) so non-accounting apps can reuse them for any numeric
 * emphasis.
 *
 * The `sap-` prefix namespaces the canonical palette to the library so
 * `bg-sap-surface` / `text-sap-fg` / `border-sap-border` won't collide
 * with a downstream project's own `--bg`, `--fg`, or `--border`. The same
 * prefix applies to the typography, tracking, and density scales below.
 *
 * Shadcn-compat aliases (unprefixed `--background`, `--primary`, `--muted`,
 * `--accent`, etc.) are provided at the bottom of each palette so that
 * existing shadcn utility classes like `bg-primary`, `text-muted-foreground`,
 * `bg-accent` continue to resolve; they delegate to the canonical tokens.
 * ───────────────────────────────────────────────────────────────────────── */

:root {
  /* Scrollbars, form controls, and the canvas the browser paints itself
     follow the theme rather than staying on the light default. */
  color-scheme: light;

  /* Surfaces */
  --sap-bg: #ffffff;
  --sap-surface: #ffffff;
  --sap-sidebar: #fafafa;
  --sap-nested-bg: #ffffff;
  --sap-chip-bg: #eeeeee;
  --sap-row: #ffffff;
  --sap-row-hover: #f4f4f5;

  /* Borders */
  --sap-border: #e4e4e7;
  --sap-border-strong: #d4d4d8;
  --sap-border-soft: #eeeeef;

  /* Text hierarchy */
  --sap-fg: #111111;
  --sap-fg-soft: #3f3f46;
  --sap-fg-muted: #71717a;
  --sap-fg-subtle: #a1a1aa;

  /* Brand / emphasis */
  --sap-brand: #8b5d3c;
  --sap-brand-soft: #f3ece6;
  --sap-selection: #eeeeee;
  --sap-focus-ring: rgb(139 93 60 / 0.42);
  --sap-link: #1f6fb0;
  --sap-drill-down-link: var(--sap-link);
  --sap-drill-down-link-soft: rgb(31 111 176 / 0.12);
  --sap-loading-indicator-bar: #2f6f9f;

  /* Numeric emphasis (any deltas / gains-losses / data accents). `negative`
     also paints errors and destructive actions; an app whose negative
     figures are not problems (money out in a ledger) sets
     `--sap-numeric-negative` on its own. */
  --sap-positive: #1a4d2e;
  --sap-warning: #8a5a00;
  --sap-negative: #8b2f2f;
  --sap-numeric-negative: var(--sap-negative);

  /* Nav chrome */
  --sap-active-nav-bg: #ededed;
  --sap-nav-count-bg: #eeeeee;

  /* The navigation sidebar: a warm plane set apart by its tone alone, grey
     rows whose hover and selection are faint washes over it, so the sidebar
     stays quiet beside the page. */
  --sap-nav-bg: #f9f8f7;
  --sap-nav-fg: #5f5e59;
  --sap-nav-icon: #8e8b86;
  --sap-nav-section: #91918e;
  --sap-nav-hover-bg: rgb(0 0 0 / 0.04);
  --sap-nav-selected-bg: rgb(0 0 0 / 0.03);

  /* Kbd chrome */
  --sap-kbd-bg: #ffffff;
  --sap-kbd-inverted-bg: rgba(255, 255, 255, 0.15);
  --sap-proj-chip-kbd-bg: #f7f6f3;

  /* The one shadow for floating layers: popovers, menus, dialogs, sheets,
     tooltips. Surfaces in the page flow carry no shadow. */
  --sap-shadow-elevated:
    0 8px 24px rgb(0 0 0 / 0.12), 0 1px 2px rgb(0 0 0 / 0.08);

  /* Project switcher */
  --sap-proj-bg: #ffffff;
  --sap-proj-grad: linear-gradient(
    135deg,
    var(--sap-fg) 0 58%,
    var(--sap-brand) 58% 100%
  );

  /* Radii. The `--sap-radius-*` values are the ones to override; the
     unprefixed `--radius*` names are the shadcn-compat aliases and the
     `rounded-*` utilities read the same values through @theme below. */
  --sap-radius: 6px;
  --sap-radius-sm: 3px;
  --sap-radius-lg: 8px;
  --sap-radius-xl: 10px;
  --radius: var(--sap-radius);
  --radius-sm: var(--sap-radius-sm);
  --radius-lg: var(--sap-radius-lg);
  --radius-xl: var(--sap-radius-xl);

  /* ── shadcn-compat aliases ───────────────────────────────────────────── */
  --background: var(--sap-bg);
  --foreground: var(--sap-fg);
  --card: var(--sap-surface);
  --card-foreground: var(--sap-fg);
  --popover: var(--sap-surface);
  --popover-foreground: var(--sap-fg);
  --primary: var(--sap-fg); /* filled button bg (dark-on-light) */
  --primary-foreground: var(--sap-bg);
  --secondary: var(--sap-chip-bg);
  --secondary-foreground: var(--sap-fg);
  --muted: var(--sap-nested-bg);
  --muted-foreground: var(--sap-fg-muted);
  --accent: var(--sap-row-hover); /* shadcn bg-accent → hover wash  */
  --accent-foreground: var(--sap-fg);
  --destructive: var(--sap-negative);
  --destructive-foreground: var(--sap-bg);
  --border: var(--sap-border);
  --input: var(--sap-border);
  --ring: var(--sap-brand);
  --sidebar-foreground: var(--sap-fg);
  --sidebar-border: var(--sap-border);
  --sidebar-accent: var(--sap-active-nav-bg);
  --sidebar-accent-foreground: var(--sap-fg);

  --sap-z-grid-row-indicator: 1;
  --sap-z-grid-cell-focus: 2;
  --sap-z-grid-editor: 10;
  --sap-z-grid-header: 20;
  --sap-z-grid-header-popover: 30;
  --sap-z-shell-sticky: 40;
  --sap-z-popover: 50;
  --sap-z-modal-overlay: 60;
  --sap-z-modal-content: 70;
}

/* Terminal-inspired dark: warm-tinted near-blacks, fruit-brown brand emphasis,
   bright-green positives, soft-red negatives, warm-brown selection. Same structure
   as light — only values change. */
[data-theme="dark"] {
  color-scheme: dark;

  --sap-bg: #0e0f0b;
  --sap-surface: #14150f;
  --sap-sidebar: #0a0b07;
  --sap-nested-bg: #18190f;
  --sap-chip-bg: #14150f;
  --sap-row: #14150f;
  --sap-row-hover: #1a1b13;

  --sap-border: #2a2b22;
  --sap-border-strong: #3d3e32;
  --sap-border-soft: #202119;

  --sap-fg: #e8e6d8;
  --sap-fg-soft: #c7c5b8;
  --sap-fg-muted: #9a998a;
  --sap-fg-subtle: #6a6a5c;

  --sap-brand: #dca86b;
  --sap-brand-soft: rgb(220 168 107 / 0.14);
  --sap-selection: #3a2a1e;
  --sap-focus-ring: rgb(220 168 107 / 0.42);
  --sap-link: #6dc0e0;
  --sap-drill-down-link: var(--sap-link);
  --sap-drill-down-link-soft: rgb(109 192 224 / 0.14);
  --sap-loading-indicator-bar: #6fb6df;

  --sap-positive: #7bc67b;
  --sap-warning: #f2c14e;
  --sap-negative: #e08070;

  --sap-active-nav-bg: rgb(220 168 107 / 0.14);
  --sap-nav-count-bg: #1f1f17;

  --sap-nav-bg: #0a0b07;
  --sap-nav-fg: #aeac9f;
  --sap-nav-icon: #807f71;
  --sap-nav-section: #6a6a5c;
  --sap-nav-hover-bg: rgb(232 230 216 / 0.06);
  --sap-nav-selected-bg: rgb(232 230 216 / 0.045);

  --sap-kbd-bg: #1a1b13;
  --sap-kbd-inverted-bg: rgba(0, 0, 0, 0.15);
  --sap-proj-chip-kbd-bg: #1a1b13;
  --sap-shadow-elevated:
    0 8px 24px rgb(0 0 0 / 0.5), 0 1px 2px rgb(0 0 0 / 0.4);

  --sap-proj-bg: #14150f;
  --sap-proj-grad: linear-gradient(135deg, var(--sap-fg), var(--sap-brand));
}

/* ────────────────────────────────────────────────────────────────────────────
 * Tailwind @theme inline — registers tokens as utility classes
 *
 * Every `--color-sap-*` here emits `bg-sap-*`, `text-sap-*`, `border-sap-*`,
 * `ring-sap-*` utilities. The unprefixed shadcn block below keeps
 * `bg-primary`, `text-muted-foreground`, `bg-accent` etc. resolving so
 * pasted-in shadcn components keep working.
 * ───────────────────────────────────────────────────────────────────────── */

@theme inline {
  /* Fonts */
  --font-sans:
    ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  --font-mono: ui-monospace, monospace;

  /* Canonical tokens → utility classes */
  --color-sap-bg: var(--sap-bg);
  --color-sap-surface: var(--sap-surface);
  --color-sap-sidebar: var(--sap-sidebar);
  --color-sap-nested: var(--sap-nested-bg);
  --color-sap-chip: var(--sap-chip-bg);
  --color-sap-row: var(--sap-row);
  --color-sap-row-hover: var(--sap-row-hover);

  --color-sap-border: var(--sap-border);
  --color-sap-border-strong: var(--sap-border-strong);
  --color-sap-border-soft: var(--sap-border-soft);

  --color-sap-fg: var(--sap-fg);
  --color-sap-soft: var(--sap-fg-soft);
  --color-sap-muted: var(--sap-fg-muted);
  --color-sap-subtle: var(--sap-fg-subtle);

  --color-sap-brand: var(--sap-brand);
  --color-sap-brand-soft: var(--sap-brand-soft);
  --color-sap-selection: var(--sap-selection);
  --color-sap-focus-ring: var(--sap-focus-ring);
  --color-sap-link: var(--sap-link);
  --color-sap-drill-down-link: var(--sap-drill-down-link);
  --color-sap-drill-down-link-soft: var(--sap-drill-down-link-soft);
  --color-sap-loading-indicator-bar: var(--sap-loading-indicator-bar);

  --color-sap-positive: var(--sap-positive);
  --color-sap-warning: var(--sap-warning);
  --color-sap-negative: var(--sap-negative);
  --color-sap-numeric-negative: var(--sap-numeric-negative);

  --color-sap-active-nav: var(--sap-active-nav-bg);
  --color-sap-nav-count: var(--sap-nav-count-bg);
  --color-sap-nav: var(--sap-nav-bg);
  --color-sap-nav-fg: var(--sap-nav-fg);
  --color-sap-nav-icon: var(--sap-nav-icon);
  --color-sap-nav-section: var(--sap-nav-section);
  --color-sap-nav-hover: var(--sap-nav-hover-bg);
  --color-sap-nav-selected: var(--sap-nav-selected-bg);

  --color-sap-kbd: var(--sap-kbd-bg);
  --color-sap-kbd-inverted: var(--sap-kbd-inverted-bg);
  --color-sap-proj-chip-kbd: var(--sap-proj-chip-kbd-bg);
  --color-sap-proj: var(--sap-proj-bg);

  /* Elevation → `shadow-sap-elevated` */
  --shadow-sap-elevated: var(--sap-shadow-elevated);

  /* Shadcn-compat → utility classes (keeps bg-primary, bg-muted, etc. working) */
  --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-sidebar-foreground: var(--sidebar-foreground);
  --color-sidebar-border: var(--sidebar-border);
  --color-sidebar-accent: var(--sidebar-accent);
  --color-sidebar-accent-foreground: var(--sidebar-accent-foreground);

  /* Radii */
  --radius-sm: var(--sap-radius-sm);
  --radius-md: var(--sap-radius);
  --radius-lg: var(--sap-radius-lg);
  --radius-xl: var(--sap-radius-xl);

  /* ── Typography scale ────────────────────────────────────────────────
   * Ten tiers, matching the target's measured sizes. Names describe the
   * role (label/data/emph/body/display), not the px value, so components
   * don't need to know the exact measurement. Changing a tier here
   * propagates everywhere. Tailwind's defaults (`text-xs`, `text-sm`,
   * `text-base`, `text-lg`) remain available — a consumer that doesn't
   * care about Sapporta's dense UI scale can keep using the native
   * ladder. */
  --text-sap-tiny: 9px; /* sort indicators and other tertiary glyphs */
  --text-sap-micro: 10px; /* stat card labels (smallest uppercase tier) */
  --text-sap-label: 10.5px; /* section labels, grid column headers, nav counts, version chip */
  --text-sap-meta: 11px; /* status bar, breadcrumb separator, chip metadata */
  --text-sap-menu: 11.5px; /* command-menu label, select cell */
  --text-sap-data: 12px; /* inline data — IDs, dates, FK refs, chips, child rows */
  --text-sap-emph: 12.5px; /* buttons, search input, ledger/child row body */
  --text-sap-body: 13px; /* primary data rows, top-bar title, sidebar items */
  --text-sap-mark: 14.5px; /* wordmark */
  --text-sap-display: 18px; /* stat card values (the one "shout" tier) */

  /* ── Letter-spacing scale ────────────────────────────────────────────
   * Four tiers from the design doc. Named by typographic role. */
  --tracking-sap-display: 0; /* wordmark, stat values */
  --tracking-sap-head: 0.06em; /* grid column headers, uppercase labels */
  --tracking-sap-label: 0.06em; /* stat card labels */
  --tracking-sap-section: 0.08em; /* sidebar section labels (widest) */

  /* ── Density tiers ───────────────────────────────────────────────────
   * Row-height ladder. Registered under `--height-*` so only `h-sap-*`
   * utilities are emitted — not `p-sap-row`, `w-sap-row`, `gap-sap-row`,
   * which would come along for the ride under `--spacing-*`. */
  --height-sap-row: 32px; /* primary data rows */
  --height-sap-header: 29px; /* grid header, child rows, pagination, filter bar */
  --height-sap-ctl: 30px; /* buttons, inputs, search — interactive affordances */
  --height-sap-bar: 24px; /* status bar, chip strips */
  --height-sap-topbar: 52px; /* application top bar (outlier, named for grep-ability) */
}

/* ────────────────────────────────────────────────────────────────────────────
 * Base
 * ───────────────────────────────────────────────────────────────────────── */

html,
body {
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-sans);
  font-size: 13px;
  line-height: 1.38;
  letter-spacing: 0;
  text-rendering: optimizeLegibility;
  background: var(--sap-bg);
  color: var(--sap-fg);
}

* {
  box-sizing: border-box;
}

/* Tailwind's preflight sets `border-color: currentColor`, so a `border`
   utility without a colour draws in the text colour. Layered like preflight
   itself, so an app's own base rules still win. */
@layer base {
  *,
  ::after,
  ::before,
  ::backdrop,
  ::file-selector-button {
    border-color: var(--border);
  }
}

/* Monospace for tabular data. `tnum` lines up digit columns. */
.mono,
.font-mono {
  font-family: var(--font-mono);
  font-feature-settings: "tnum" 1;
}
