/**
 * @taiebs/theme-ui — the eye-safe dual theme.
 *
 * Two palettes, one contract. Neither uses a pure white or pure black surface:
 * the brightest text is #F4F4F6 on #0A0A0C, the darkest ink is #1C1B18 on
 * #F4F3EF. That keeps contrast well above WCAG AA while removing the halation
 * that turns a 12-hour ledger or spreadsheet session into eye strain.
 *
 * The variable names and values below are locked: every component in the
 * workspace reads them, and a value change here is a brand change.
 *
 * Components also pass inline fallbacks (`var(--bg-surface, #121216)`) so a
 * pane still renders correctly during the first paint, before this stylesheet
 * has been applied.
 */

:root,
[data-theme='carbon-dark'] {
  color-scheme: dark;

  --bg-canvas: #0A0A0C;
  --bg-surface: #121216;
  --bg-elevated: #1A1A20;
  --bg-glass: rgba(18, 18, 22, 0.78);
  --border-subtle: rgba(255, 255, 255, 0.07);
  --border-focus: rgba(37, 99, 235, 0.55);
  --text-primary: #F4F4F6;
  --text-secondary: #8E8E98;
  --text-muted: #5A5A66;
  --accent-primary: #2563EB;
  --accent-emerald: #10B981;
  --accent-amber: #F59E0B;
  --accent-crimson: #EF4444;

  --shadow-elevated: 0 18px 48px rgba(10, 10, 12, 0.55);
  --shadow-raised: 0 2px 10px rgba(10, 10, 12, 0.4);
  --tint-hover: rgba(244, 244, 246, 0.04);
  --tint-active: rgba(244, 244, 246, 0.07);
}

[data-theme='warm-stone-light'] {
  color-scheme: light;

  --bg-canvas: #F4F3EF;
  --bg-surface: #FAF9F5;
  --bg-elevated: #EAE8E1;
  --bg-glass: rgba(250, 249, 245, 0.85);
  --border-subtle: rgba(28, 27, 24, 0.09);
  --border-focus: rgba(29, 78, 216, 0.45);
  --text-primary: #1C1B18;
  --text-secondary: #65635D;
  --text-muted: #928F87;
  --accent-primary: #1D4ED8;
  --accent-emerald: #059669;
  --accent-amber: #D97706;
  --accent-crimson: #DC2626;

  --shadow-elevated: 0 18px 48px rgba(28, 27, 24, 0.14);
  --shadow-raised: 0 2px 10px rgba(28, 27, 24, 0.08);
  --tint-hover: rgba(28, 27, 24, 0.04);
  --tint-active: rgba(28, 27, 24, 0.07);
}

:root {
  --radius-xs: 4px;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-pill: 999px;

  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;

  --font-sans: 'Inter', 'SF Pro Display', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'SF Mono', 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;

  --duration-fast: 120ms;
  --duration-base: 180ms;
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);

  --z-pill: 60;
  --z-popover: 70;
  --z-toast: 90;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg-canvas);
  color: var(--text-primary);
}

body {
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
  letter-spacing: -0.01em;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

::selection {
  background: color-mix(in srgb, var(--accent-primary) 32%, transparent);
  color: var(--text-primary);
}

:focus-visible {
  outline: 2px solid var(--border-focus);
  outline-offset: 2px;
  border-radius: var(--radius-xs);
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

/*
 * Scrollbars are tinted with the surface colour rather than a bright thumb, so
 * a long ledger does not introduce a second light source at the pane edge.
 */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--text-muted) transparent;
}

*::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

*::-webkit-scrollbar-track {
  background: transparent;
}

*::-webkit-scrollbar-thumb {
  background: var(--border-subtle);
  border-radius: var(--radius-pill);
  border: 2px solid transparent;
  background-clip: content-box;
}

*::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
  background-clip: content-box;
}

/* ------------------------------------------------------------------------- */
/* Reference input (cmdk) — styled by attribute, because cmdk owns the DOM.   */
/* ------------------------------------------------------------------------- */

.ts-at {
  position: relative;
  width: 100%;
  color: var(--text-primary);
}

.ts-at-input-row {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: 0 var(--space-3);
  height: 38px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
  background: var(--bg-surface);
  transition: border-color var(--duration-fast) var(--ease-out);
}

.ts-at-input-row:focus-within {
  border-color: var(--border-focus);
}

[cmdk-input] {
  flex: 1;
  min-width: 0;
  height: 100%;
  border: 0;
  outline: none;
  background: transparent;
  color: var(--text-primary);
}

[cmdk-input]::placeholder {
  color: var(--text-muted);
}

[cmdk-list] {
  max-height: 320px;
  overflow-y: auto;
  padding: var(--space-1);
  margin-top: var(--space-2);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-subtle);
  background: var(--bg-glass);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  box-shadow: var(--shadow-elevated);
}

[cmdk-item] {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  cursor: pointer;
  user-select: none;
}

[cmdk-item][data-selected='true'] {
  background: var(--bg-elevated);
  color: var(--text-primary);
}

[cmdk-item] svg {
  color: var(--text-muted);
  flex: none;
}

[cmdk-empty] {
  padding: var(--space-3);
  color: var(--text-muted);
  font-size: 13px;
}

[cmdk-group-heading] {
  padding: var(--space-2) var(--space-3) var(--space-1);
  font-size: 11px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-muted);
}

/* ------------------------------------------------------------------------- */
/* Small utilities used by the components.                                    */
/* ------------------------------------------------------------------------- */

.ts-spin {
  animation: ts-spin 900ms linear infinite;
}

@keyframes ts-spin {
  to {
    transform: rotate(360deg);
  }
}

.ts-sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.ts-pane-scroll {
  overflow: auto;
  overscroll-behavior: contain;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 1ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 1ms !important;
    scroll-behavior: auto !important;
  }
}
