/* =============================================================================
   Components — Shadcn-inspired primitives, pure CSS, token-driven.
   Consumes tokens defined in tokens.css. Variant API mirrors shadcn/ui:
   each primitive has variants (default/outline/ghost/secondary/destructive)
   and sizes (xs/sm/default/lg/icon) exposed via helper methods.
   ========================================================================== */

/* -----------------------------------------------------------------------------
   Button
   Usage:  link_to "Save", path, class: button_classes(variant: :primary)
           form.submit "Save", class: button_classes(size: :sm, block: true)
   -------------------------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  font-family: inherit;
  font-size: var(--text-sm);
  font-weight: var(--font-medium);
  line-height: 1;
  white-space: nowrap;
  height: 2.25rem;
  padding: 0 var(--space-3);
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  cursor: pointer;
  user-select: none;
  text-decoration: none;
  transition:
    background-color var(--duration) var(--ease),
    border-color var(--duration) var(--ease),
    color var(--duration) var(--ease),
    box-shadow var(--duration) var(--ease),
    opacity var(--duration) var(--ease);
}
.btn:focus-visible { outline: 2px solid var(--ring); outline-offset: 2px; }
.btn:disabled,
.btn[aria-disabled="true"] { opacity: 0.5; cursor: not-allowed; pointer-events: none; }
.btn svg { width: 1rem; height: 1rem; flex-shrink: 0; }

/* Variants */
.btn--primary {
  background: var(--primary);
  color: var(--primary-foreground);
}
.btn--primary:hover { background: color-mix(in oklch, var(--primary), white 12%); }
.btn--secondary {
  background: var(--secondary);
  color: var(--secondary-foreground);
}
.btn--secondary:hover { background: color-mix(in oklch, var(--secondary), black 6%); }
.btn--outline {
  background: var(--card);
  border-color: var(--border);
  color: var(--foreground);
}
.btn--outline:hover { background: var(--accent); color: var(--accent-foreground); }
.btn--ghost { background: transparent; color: var(--foreground); }
.btn--ghost:hover { background: var(--accent); color: var(--accent-foreground); }
.btn--destructive {
  background: var(--destructive);
  color: var(--destructive-foreground);
}
.btn--destructive:hover { background: color-mix(in oklch, var(--destructive), white 12%); }
.btn--link {
  background: transparent;
  color: var(--foreground);
  height: auto;
  padding: 0;
  border: 0;
  border-radius: 0;
}
.btn--link:hover { text-decoration: underline; }

/* Sizes */
.btn--xs { height: 1.75rem; font-size: var(--text-xs); padding: 0 var(--space-2); gap: var(--space-1); }
.btn--sm { height: 2rem; font-size: var(--text-xs); padding: 0 var(--space-2); }
.btn--lg { height: 2.75rem; font-size: var(--text-base); padding: 0 var(--space-5); }
.btn--icon { width: 2.25rem; padding: 0; }
.btn--icon.btn--xs { width: 1.75rem; }
.btn--icon.btn--sm { width: 2rem; }
.btn--icon.btn--lg { width: 2.75rem; }
.btn--block { width: 100%; }

/* -----------------------------------------------------------------------------
   Badge
   Usage:  status_badge(claim.status)  |  badge("New", variant: :outline)
   -------------------------------------------------------------------------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  font-size: var(--text-xs);
  font-weight: var(--font-medium);
  line-height: 1;
  border-radius: var(--radius-full);
  padding: 0.25rem 0.625rem;
  border: 1px solid transparent;
  white-space: nowrap;
}
.badge svg { width: 0.75rem; height: 0.75rem; flex-shrink: 0; }

.badge--primary { background: var(--primary); color: var(--primary-foreground); }
.badge--secondary { background: var(--secondary); color: var(--secondary-foreground); }
.badge--outline { border-color: var(--border); color: var(--foreground); }
.badge--muted { background: var(--muted); color: var(--muted-foreground); }

/* Status variants — driven by --status-* token pairs */
.badge--expected { background: var(--status-expected); color: var(--status-expected-foreground); }
.badge--running { background: var(--status-running); color: var(--status-running-foreground); }
.badge--paused { background: var(--status-paused); color: var(--status-paused-foreground); }
.badge--suspended { background: var(--status-suspended); color: var(--status-suspended-foreground); }
.badge--covered { background: var(--status-covered); color: var(--status-covered-foreground); }
.badge--uncovered { background: var(--status-uncovered); color: var(--status-uncovered-foreground); }
.badge--pending { background: var(--status-pending); color: var(--status-pending-foreground); }
.badge--consumed { background: var(--status-consumed); color: var(--status-consumed-foreground); }
.badge--triage { background: var(--status-triage); color: var(--status-triage-foreground); }
.badge--in_liquidation { background: var(--status-in-liquidation); color: var(--status-in-liquidation-foreground); }
.badge--liquidated { background: var(--status-liquidated); color: var(--status-liquidated-foreground); }
.badge--finished { background: var(--status-finished); color: var(--status-finished-foreground); }
.badge--cancelled { background: var(--status-cancelled); color: var(--status-cancelled-foreground); }

/* Status dot badge — Linear-style solid chip with leading dot */
.badge--dot::before {
  content: "";
  width: 0.4rem;
  height: 0.4rem;
  border-radius: var(--radius-full);
  background: currentColor;
  flex-shrink: 0;
}

.badge--sm { font-size: var(--text-xs); padding: 0.1875rem 0.5rem; }
.badge--md { font-size: var(--text-sm); padding: 0.3125rem 0.75rem; }

/* -----------------------------------------------------------------------------
   Card
   -------------------------------------------------------------------------- */
.card {
  background: var(--card);
  color: var(--card-foreground);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}
.card--raised { box-shadow: var(--shadow-md); }
.card__header { display: flex; flex-direction: column; gap: 0.1875rem; padding: var(--space-5) var(--space-6); }
.card__title { font-size: var(--text-lg); font-weight: var(--font-semibold); letter-spacing: var(--tracking-tight); line-height: var(--leading-tight); }
.card__description { font-size: var(--text-sm); color: var(--muted-foreground); line-height: var(--leading-normal); }
.card__content { padding: var(--space-6); }
.card__content--flush { padding: 0; }
.card__footer { display: flex; align-items: center; gap: var(--space-2); padding: var(--space-4) var(--space-6); border-top: 1px solid var(--border); }
.card--centered { text-align: center; }

/* -----------------------------------------------------------------------------
   Form controls: label, input, textarea, field
   -------------------------------------------------------------------------- */
.field { display: flex; flex-direction: column; gap: 0.375rem; margin-bottom: var(--space-4); }
.field:last-child { margin-bottom: 0; }
.field__hint { font-size: var(--text-xs); color: var(--muted-foreground); }
.field__hint-list {
  margin: var(--space-1) 0 0;
  padding-left: var(--space-4);
  list-style: disc;
  font-size: var(--text-xs);
  color: var(--muted-foreground);
}
.field__hint-list li + li { margin-top: var(--space-1); }
.field__error { font-size: var(--text-xs); color: var(--destructive); }

.label {
  font-size: var(--text-sm);
  font-weight: var(--font-medium);
  color: var(--foreground);
}

.input,
.textarea,
.select {
  font-family: inherit;
  font-size: var(--text-sm);
  width: 100%;
  border: 1px solid var(--input);
  border-radius: var(--radius-md);
  background: var(--card);
  color: var(--foreground);
  padding: 0.5rem var(--space-3);
  line-height: var(--leading-normal);
  transition: border-color var(--duration) var(--ease), box-shadow var(--duration) var(--ease);
}
.input::placeholder,
.textarea::placeholder { color: var(--muted-foreground); }
.input:focus,
.textarea:focus,
.select:focus {
  outline: none;
  border-color: var(--ring);
  box-shadow: 0 0 0 3px color-mix(in oklch, var(--ring), transparent 75%);
}
.input:disabled,
.textarea:disabled,
.select:disabled { opacity: 0.5; cursor: not-allowed; }
.textarea { min-height: 5rem; resize: vertical; }
.select { height: 2.25rem; cursor: pointer; }
.input--mono { font-family: var(--font-mono); font-size: var(--text-xs); }

/* Visually hidden — used for the attach-document file input trick. */
.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;
}

/* -----------------------------------------------------------------------------
   Dialog (native <dialog>, driven by modal_controller)
   -------------------------------------------------------------------------- */
.dialog {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--card);
  color: var(--card-foreground);
  padding: 0;
  max-width: 32rem;
  width: calc(100% - var(--space-6));
  margin: auto;
  box-shadow: var(--shadow-lg);
}
.dialog::backdrop {
  background: oklch(0 0 0 / 0.5);
  backdrop-filter: blur(2px);
}
.dialog__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-5) var(--space-6);
  border-bottom: 1px solid var(--border);
}
.dialog__title { font-size: var(--text-lg); font-weight: var(--font-semibold); letter-spacing: var(--tracking-tight); }
.dialog__close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem; height: 2rem;
  border: 0;
  background: transparent;
  color: var(--muted-foreground);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background-color var(--duration) var(--ease), color var(--duration) var(--ease);
}
.dialog__close:hover { background: var(--accent); color: var(--accent-foreground); }
.dialog__body { padding: var(--space-6); display: flex; flex-direction: column; gap: var(--space-4); }
.dialog__footer { display: flex; align-items: center; justify-content: flex-end; gap: var(--space-2); padding: var(--space-4) var(--space-6); border-top: 1px solid var(--border); }

/* -----------------------------------------------------------------------------
   Alert — inline banner (placeholder/empty states, warnings)
   -------------------------------------------------------------------------- */
.alert {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-4);
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  font-size: var(--text-sm);
  line-height: var(--leading-normal);
}
.alert svg { width: 1.125rem; height: 1.125rem; flex-shrink: 0; margin-top: 0.0625rem; }
.alert--warning {
  background: color-mix(in oklch, var(--status-paused), var(--card) 88%);
  border-color: color-mix(in oklch, var(--status-paused), transparent 50%);
  color: color-mix(in oklch, var(--status-paused-foreground), black 10%);
}
.alert--danger {
  background: color-mix(in oklch, var(--destructive), var(--card) 90%);
  border-color: color-mix(in oklch, var(--destructive), transparent 55%);
  color: var(--destructive);
}
.alert--info {
  background: color-mix(in oklch, var(--status-expected), var(--card) 90%);
  border-color: color-mix(in oklch, var(--status-expected), transparent 55%);
  color: color-mix(in oklch, var(--status-expected), black 25%);
}
.alert--success {
  background: color-mix(in oklch, var(--status-covered), var(--card) 90%);
  border-color: color-mix(in oklch, var(--status-covered), transparent 55%);
  color: color-mix(in oklch, var(--status-covered-foreground), black 20%);
}

/* -----------------------------------------------------------------------------
   Flash — top-of-page transient messages
   -------------------------------------------------------------------------- */
.flash {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  font-size: var(--text-sm);
  margin-bottom: var(--space-4);
}
.flash svg { width: 1rem; height: 1rem; flex-shrink: 0; margin-top: 0.125rem; }
.flash--alert {
  background: color-mix(in oklch, var(--destructive), var(--card) 90%);
  border-color: color-mix(in oklch, var(--destructive), transparent 55%);
  color: var(--destructive);
}
/* Mixed in oklab, not oklch: --card is achromatic, and Chrome interpolates the
   powerless hue toward 0 instead of adopting the other operand's, which turns
   this green wash pink. oklab has no hue channel, so there is nothing to skew.
   The text takes the token itself, the way .flash--alert takes --destructive —
   --status-covered-foreground is the near-white ink for the badge, and mixing
   it toward black only ever lands on unreadable grey. */
.flash--notice {
  background: color-mix(in oklab, var(--status-covered), var(--card) 90%);
  border-color: color-mix(in oklch, var(--status-covered), transparent 55%);
  color: var(--status-covered);
}

/* -----------------------------------------------------------------------------
   Separator
   -------------------------------------------------------------------------- */
.separator {
  height: 1px;
  width: 100%;
  background: var(--border);
  border: 0;
  margin: 0;
}
.separator--vertical { height: auto; width: 1px; align-self: stretch; background: var(--border); }

/* -----------------------------------------------------------------------------
   Empty state
   -------------------------------------------------------------------------- */
.empty {
  padding: var(--space-6);
  text-align: center;
  color: var(--muted-foreground);
  font-size: var(--text-sm);
}

/* -----------------------------------------------------------------------------
   Breadcrumb
   -------------------------------------------------------------------------- */
.breadcrumb { display: flex; align-items: center; flex-wrap: wrap; gap: 0.375rem; font-size: var(--text-sm); }
.breadcrumb__item { display: inline-flex; align-items: center; gap: 0.375rem; }
.breadcrumb__link { color: var(--muted-foreground); transition: color var(--duration) var(--ease); }
.breadcrumb__link:hover { color: var(--foreground); }
.breadcrumb__sep { color: var(--muted-foreground); opacity: 0.6; display: inline-flex; }
.breadcrumb__current { color: var(--foreground); font-weight: var(--font-medium); }

/* -----------------------------------------------------------------------------
   Timeline (claim event history)
   -------------------------------------------------------------------------- */
.timeline {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: var(--space-5);
  padding-left: var(--space-5);
  margin-top: var(--space-4);
}
.timeline::before {
  content: "";
  position: absolute;
  left: 0.34375rem;
  top: 0.5rem;
  bottom: 0.5rem;
  width: 2px;
  background: var(--border);
}
.timeline__item { position: relative; }
.timeline__dot {
  position: absolute;
  left: calc(-1 * var(--space-5) + 0.0625rem);
  top: 0.375rem;
  width: 0.625rem;
  height: 0.625rem;
  border-radius: var(--radius-full);
  background: var(--muted-foreground);
  box-shadow: 0 0 0 3px var(--background);
}
.timeline__meta { display: flex; align-items: center; gap: var(--space-2); }
.timeline__author { font-weight: var(--font-medium); font-size: var(--text-sm); }
.timeline__time { color: var(--muted-foreground); font-size: var(--text-xs); }
.timeline__transition { display: flex; align-items: center; gap: var(--space-2); margin-top: var(--space-1); flex-wrap: wrap; }
.timeline__transition svg { width: 0.875rem; height: 0.875rem; color: var(--muted-foreground); }
.timeline__description { margin-top: var(--space-1); font-size: var(--text-sm); color: var(--foreground); line-height: var(--leading-normal); }

/* -----------------------------------------------------------------------------
   Sidebar (app shell)
   -------------------------------------------------------------------------- */
.app-shell { display: flex; height: 100vh; height: 100dvh; overflow: hidden; }
.sidebar {
  width: 16rem;
  flex-shrink: 0;
  position: sticky;
  top: 0;
  height: 100vh;
  height: 100dvh;
  background: var(--sidebar);
  color: var(--sidebar-foreground);
  border-right: 1px solid var(--sidebar-border);
  display: flex;
  flex-direction: column;
}
.sidebar__brand {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-4) var(--space-5);
  font-weight: var(--font-semibold);
  font-size: var(--text-base);
  letter-spacing: var(--tracking-tight);
}
.sidebar__brand svg { width: 1.25rem; height: 1.25rem; color: var(--sidebar-primary); }
.sidebar__nav { flex: 1; padding: var(--space-2); display: flex; flex-direction: column; gap: 0.125rem; overflow-y: auto; }
.sidebar__section-label {
  padding: var(--space-3) var(--space-3) var(--space-1);
  font-size: var(--text-xs);
  color: var(--muted-foreground);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: var(--font-medium);
}
.sidebar__item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  font-weight: var(--font-medium);
  color: var(--muted-foreground);
  transition: background-color var(--duration) var(--ease), color var(--duration) var(--ease);
}
.sidebar__item:hover { background: var(--sidebar-accent); color: var(--sidebar-accent-foreground); }
.sidebar__item--active { background: var(--sidebar-grenat); color: var(--sidebar-grenat-foreground); }
.sidebar__item svg { width: 1rem; height: 1rem; flex-shrink: 0; opacity: 0.85; }
.sidebar__item-count {
  margin-left: auto;
  min-width: 1.25rem;
  padding: 0 var(--space-1);
  border-radius: var(--radius-sm);
  background: var(--sidebar-accent);
  color: var(--sidebar-accent-foreground);
  font-size: var(--text-xs);
  font-weight: var(--font-semibold);
  text-align: center;
}
.sidebar__item--active .sidebar__item-count {
  background: var(--sidebar-grenat-foreground);
  color: var(--sidebar-grenat);
}
.sidebar__footer { padding: var(--space-3); border-top: 1px solid var(--sidebar-border); display: flex; align-items: center; gap: var(--space-2); }
.sidebar__user { flex: 1; min-width: 0; }
.sidebar__user-name { font-size: var(--text-sm); font-weight: var(--font-medium); color: var(--sidebar-foreground); }
.sidebar__user-role { font-size: var(--text-xs); color: var(--muted-foreground); }

/* Theme toggle — shows the icon for the mode you'll switch TO. */
.sidebar__theme-toggle .sidebar__theme-icon--dark { display: inline-flex; }
.sidebar__theme-toggle .sidebar__theme-icon--light { display: none; }
.dark .sidebar__theme-toggle .sidebar__theme-icon--dark { display: none; }
.dark .sidebar__theme-toggle .sidebar__theme-icon--light { display: inline-flex; }

.app-shell__main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

/* -----------------------------------------------------------------------------
   App content + page layout
   -------------------------------------------------------------------------- */
.app-content { padding: var(--space-8) var(--space-6); flex: 1; display: flex; flex-direction: column; min-height: 0; }

.page-header { display: flex; flex-direction: column; gap: var(--space-2); margin-bottom: var(--space-6); }
.page-header__breadcrumb { margin-bottom: var(--space-1); }
.page-title { font-size: var(--text-3xl); font-weight: var(--font-bold); letter-spacing: var(--tracking-tight); line-height: var(--leading-tight); }
.page-subtitle { font-size: var(--text-sm); color: var(--muted-foreground); }

/* -----------------------------------------------------------------------------
   Sub-nav — horizontal tab bar below the claim card
   -------------------------------------------------------------------------- */
.sub-nav {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--border);
  margin: 0;
  padding: 0;
}
.sub-nav__item {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-2) var(--space-3);
  font-size: var(--text-sm);
  font-weight: var(--font-medium);
  color: var(--muted-foreground);
  background: none;
  border: 0;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  transition: color var(--duration) var(--ease), border-color var(--duration) var(--ease);
  margin-bottom: -1px;
  white-space: nowrap;
}
.sub-nav__item:hover { color: var(--foreground); }
.sub-nav__item--active {
  color: var(--foreground);
  border-bottom-color: var(--primary);
}

/* -----------------------------------------------------------------------------
   Tab panel — show/hide by sub-nav selection
   -------------------------------------------------------------------------- */
.tab-panel { display: none; }
.tab-panel--active { display: block; }

/* Auth + public centered layouts */
.auth-page { min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: var(--space-6); gap: var(--space-5); }
.auth-page__brand { font-size: var(--text-xl); font-weight: var(--font-bold); letter-spacing: var(--tracking-tight); }
.auth-page__card { width: 100%; max-width: 24rem; }
.auth-page__heading { font-size: var(--text-2xl); font-weight: var(--font-semibold); letter-spacing: var(--tracking-tight); margin-bottom: var(--space-5); }
.auth-page__footer { font-size: var(--text-sm); color: var(--muted-foreground); }

.public-page { min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: var(--space-6); }
.public-page__brand { margin-bottom: var(--space-6); font-size: var(--text-xl); font-weight: var(--font-bold); letter-spacing: var(--tracking-tight); }
.public-page__card { width: 100%; max-width: 40rem; }
.public-page__heading { font-size: var(--text-2xl); font-weight: var(--font-semibold); letter-spacing: var(--tracking-tight); margin-bottom: var(--space-4); }
.public-page__lead { font-size: var(--text-sm); color: var(--muted-foreground); margin-bottom: var(--space-4); }
.public-page blockquote {
  margin: var(--space-4) 0;
  padding: var(--space-4);
  border-left: 4px solid var(--status-expected);
  background: var(--muted);
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
  font-size: var(--text-sm);
  line-height: var(--leading-normal);
  color: var(--foreground);
}
.public-page--centered { text-align: center; }