/* The components of the Cadence design system, as classes. Loaded after
   tokens.css, and used inside an element with the class cd-root.

   This is the design system's own stylesheet, with every measurement as it
   gives it. What differs is marked "Cadence:" below. /styleguide.html shows
   each component in each of its states. New styles use these classes and the
   tokens, and never a colour, size or corner of their own. */

.cd-root { font-family: var(--font-sans); color: var(--ink-primary); background: var(--surface-canvas); }
.cd-root *, .cd-root *::before, .cd-root *::after { box-sizing: border-box; }

/* ---------- Focus ---------- */
/* Cadence: the ring follows the shape of what it is on, so focus never changes a corner. */
.cd-root :focus-visible {
  outline: var(--focus-width) solid var(--focus-ring);
  outline-offset: var(--focus-width);
}
.cd-focus-demo { outline: var(--focus-width) solid var(--focus-ring); outline-offset: var(--focus-width); }

/* ---------- Icon ---------- */
.cd-icon { width: var(--icon-md); height: var(--icon-md); flex: none; display: block; }
.cd-icon svg { width: 100%; height: 100%; display: block; }
.cd-icon--sm { width: var(--icon-sm); height: var(--icon-sm); }
.cd-icon--lg { width: var(--icon-lg); height: var(--icon-lg); }

/* ---------- Button ---------- */
.cd-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
  height: var(--control-md); padding: 0 var(--space-3);
  border-radius: var(--radius-sm); border: 1px solid transparent;
  font-family: var(--font-sans); font-size: 13px; line-height: 16px; font-weight: 500;
  cursor: pointer; white-space: nowrap; text-decoration: none;
  transition: background-color 120ms ease, border-color 120ms ease, color 120ms ease;
}
.cd-btn--sm { height: var(--control-sm); padding: 0 var(--space-2); font-size: 12px; }
.cd-btn--lg { height: var(--control-lg); padding: 0 var(--space-4); font-size: 14px; }
.cd-btn--icon { width: var(--control-md); padding: 0; }

.cd-btn--primary { background: var(--accent); color: var(--on-accent); box-shadow: var(--shadow-xs); }
.cd-btn--primary:hover { background: var(--accent-hover); }
.cd-btn--primary:active { background: var(--accent-active); }

.cd-btn--secondary { background: var(--surface-raised); color: var(--ink-primary); border-color: var(--border-default); }
.cd-btn--secondary:hover { background: var(--surface-hover); border-color: var(--border-strong); }
.cd-btn--secondary:active { background: var(--surface-active); }

.cd-btn--ghost { background: transparent; color: var(--ink-secondary); }
.cd-btn--ghost:hover { background: var(--surface-hover); color: var(--ink-primary); }
.cd-btn--ghost:active { background: var(--surface-active); }

/* Cadence: the label takes ink-inverse in both themes, where the design system wrote white and a dark override. */
.cd-btn--danger { background: var(--danger); color: var(--ink-inverse); }
.cd-btn--danger:hover { background: var(--danger-hover); }
.cd-btn--danger[disabled]:hover { background: var(--danger); }

.cd-btn[disabled], .cd-btn[aria-disabled="true"] { cursor: not-allowed; opacity: var(--opacity-disabled); }
.cd-btn[disabled]:hover, .cd-btn[aria-disabled="true"]:hover { background: inherit; }
.cd-btn--primary[disabled]:hover { background: var(--accent); }
.cd-btn--secondary[disabled]:hover { background: var(--surface-raised); border-color: var(--border-default); }

.cd-btn__spinner {
  width: var(--icon-md); height: var(--icon-md); border-radius: var(--radius-full);
  border: 2px solid currentColor; border-top-color: transparent;
  animation: cd-spin 700ms linear infinite;
}
@keyframes cd-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .cd-btn__spinner { animation-duration: 2400ms; } }

/* ---------- Field ---------- */
.cd-field { display: flex; flex-direction: column; gap: 6px; }
.cd-field__label { font-size: 13px; line-height: 16px; font-weight: 500; color: var(--ink-primary); }
.cd-field__optional { color: var(--ink-tertiary); font-weight: 400; }
.cd-field__help { font-size: 12px; line-height: 16px; color: var(--ink-tertiary); }
.cd-field__error { display: inline-flex; align-items: center; gap: var(--space-1); font-size: 12px; line-height: 16px; color: var(--danger-text); }

.cd-input {
  width: 100%; height: var(--control-md); padding: 0 var(--space-3);
  background: var(--surface-raised); color: var(--ink-primary);
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  font-family: var(--font-sans); font-size: 14px; line-height: 20px;
  transition: border-color 120ms ease, box-shadow 120ms ease;
}
.cd-input::placeholder { color: var(--ink-tertiary); }
.cd-input:hover { border-color: var(--ink-tertiary); }
/* Cadence: a field shows the same solid ring as everything else, not a soft glow in its place. */
.cd-input:focus-visible { border-color: var(--accent); }
.cd-input--lg { height: var(--control-lg); }
.cd-input--area { height: auto; min-height: 84px; padding: var(--space-2) var(--space-3); resize: vertical; }
.cd-input--error { border-color: var(--danger); }
.cd-input--error:focus-visible { border-color: var(--danger); }
.cd-input[disabled] { background: var(--surface-sunken); color: var(--ink-tertiary); border-color: var(--border-default); cursor: not-allowed; }
.cd-input--loading { background-image: none; color: var(--ink-tertiary); }

/* ---------- Tabs ---------- */
.cd-tabs { display: flex; gap: var(--space-4); border-bottom: 1px solid var(--border-default); }
.cd-tab {
  position: relative; display: inline-flex; align-items: center; gap: var(--space-2);
  height: var(--control-lg); padding: 0 2px;
  background: none; border: none; cursor: pointer;
  font-family: var(--font-sans); font-size: 13px; line-height: 16px; font-weight: 500;
  color: var(--ink-secondary);
}
.cd-tab:hover { color: var(--ink-primary); }
.cd-tab[aria-selected="true"] { color: var(--ink-primary); }
.cd-tab[aria-selected="true"]::after {
  content: ""; position: absolute; left: 0; right: 0; bottom: -1px; height: 2px;
  background: var(--accent); border-radius: var(--radius-full);
}
.cd-tab[disabled] { color: var(--ink-tertiary); opacity: var(--opacity-disabled); cursor: not-allowed; }
.cd-tab__count {
  min-width: 18px; padding: 0 5px; border-radius: var(--radius-full);
  background: var(--surface-active); color: var(--ink-secondary);
  font-size: 11px; line-height: 18px; font-weight: 600; text-align: center;
}

/* ---------- Badge ---------- */
.cd-badge {
  display: inline-flex; align-items: center; gap: var(--space-1);
  height: 22px; padding: 0 var(--space-2);
  border-radius: var(--radius-sm); border: 1px solid transparent;
  font-size: 12px; line-height: 16px; font-weight: 500; white-space: nowrap;
}
.cd-badge__dot { width: 6px; height: 6px; border-radius: var(--radius-full); background: currentColor; flex: none; }
.cd-badge--neutral { background: var(--surface-sunken); color: var(--ink-secondary); border-color: var(--border-subtle); }
.cd-badge--accent { background: var(--accent-subtle); color: var(--accent-text); border-color: var(--accent-border); }
.cd-badge--success { background: var(--success-subtle); color: var(--success-text); border-color: color-mix(in srgb, var(--success) 30%, transparent); }
.cd-badge--warning { background: var(--warning-subtle); color: var(--warning-text); border-color: color-mix(in srgb, var(--warning) 30%, transparent); }
.cd-badge--danger { background: var(--danger-subtle); color: var(--danger-text); border-color: color-mix(in srgb, var(--danger) 30%, transparent); }

/* ---------- Nav ---------- */
.cd-nav { width: var(--sidebar-width); flex: none; display: flex; flex-direction: column; gap: var(--space-6);
  padding: var(--space-5) var(--space-3); background: var(--surface-sunken); border-right: 1px solid var(--border-subtle); }
.cd-nav__brand { display: flex; align-items: center; gap: var(--space-2); padding: 0 var(--space-2); }
.cd-nav__mark { width: 22px; height: 22px; border-radius: var(--radius-xs); background: var(--accent); color: var(--on-accent);
  display: grid; place-items: center; font-size: 12px; font-weight: 700; flex: none; }
.cd-nav__name { font-size: 14px; font-weight: 600; letter-spacing: -0.01em; }
.cd-nav__group { display: flex; flex-direction: column; gap: 2px; }
.cd-nav__heading { padding: 0 var(--space-2) var(--space-2); font-size: 11px; line-height: 14px; font-weight: 600;
  letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-tertiary); }
.cd-nav__item {
  position: relative; display: flex; align-items: center; gap: var(--space-2);
  height: var(--control-md); padding: 0 var(--space-2); border-radius: var(--radius-sm);
  color: var(--ink-secondary); font-size: 13px; font-weight: 500; text-decoration: none; cursor: pointer;
  background: none; border: none; width: 100%; text-align: left; font-family: var(--font-sans);
}
.cd-nav__item:hover { background: var(--surface-hover); color: var(--ink-primary); }
.cd-nav__item[aria-current="page"] { background: var(--surface-active); color: var(--ink-primary); }
.cd-nav__item[aria-current="page"]::before {
  content: ""; position: absolute; left: -12px; top: 8px; bottom: 8px;
  width: 2px; border-radius: var(--radius-full); background: var(--accent);
}
.cd-nav__item[disabled] { color: var(--ink-tertiary); opacity: var(--opacity-disabled); cursor: not-allowed; }
.cd-nav__count { margin-left: auto; font-size: 11px; font-weight: 600; color: var(--ink-tertiary); }
.cd-topbar { display: flex; align-items: center; gap: var(--space-3); height: 52px;
  padding: 0 var(--space-8); border-bottom: 1px solid var(--border-subtle); background: var(--surface-canvas); }
.cd-topbar__crumbs { display: flex; align-items: center; gap: var(--space-2); font-size: 13px; color: var(--ink-tertiary); }
.cd-topbar__crumbs b { font-weight: 500; color: var(--ink-primary); }
.cd-topbar__actions { margin-left: auto; display: flex; align-items: center; gap: var(--space-2); }

/* ---------- Card ---------- */
.cd-card { background: var(--surface-raised); border: 1px solid var(--border-subtle); border-radius: var(--radius-lg);
  padding: var(--space-5); box-shadow: var(--shadow-none); }
.cd-card__head { display: flex; align-items: center; gap: var(--space-2); margin-bottom: var(--space-4); }
.cd-card__title { font-size: 17px; line-height: 24px; font-weight: 600; letter-spacing: -0.01em; }
.cd-card__action { margin-left: auto; }

/* ---------- Board card ---------- */
/* Cadence: a board card is a button, which does not take the page's font and colour unless told to. */
.cd-bcard {
  font-family: var(--font-sans); color: var(--ink-primary);
  display: block; width: 100%; text-align: left; cursor: pointer;
  background: var(--surface-raised); border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md); padding: var(--space-4);
  box-shadow: var(--shadow-xs); transition: box-shadow 120ms ease, border-color 120ms ease, transform 120ms ease;
}
.cd-bcard:hover { box-shadow: var(--shadow-sm); border-color: var(--border-default); }
.cd-bcard--dragging { box-shadow: var(--shadow-md); transform: rotate(-0.6deg); border-color: var(--accent-border); }
.cd-bcard--selected { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-subtle); }
.cd-bcard__top { display: flex; align-items: center; gap: var(--space-2); margin-bottom: var(--space-2); }
.cd-bcard__ref { font-family: var(--font-mono); font-size: 11.5px; color: var(--ink-tertiary); }
.cd-bcard__title { font-size: 15px; line-height: 20px; font-weight: 600; margin: 0 0 var(--space-2); }
.cd-bcard__summary { font-size: 13px; line-height: 20px; color: var(--ink-secondary); margin: 0 0 var(--space-3); }
.cd-bcard__foot { display: flex; align-items: center; gap: var(--space-2); }
.cd-bcard__meta { margin-left: auto; display: inline-flex; align-items: center; gap: var(--space-1);
  font-size: 12px; font-weight: 500; color: var(--ink-tertiary); }
.cd-column { display: flex; flex-direction: column; gap: var(--space-3); width: 288px; flex: none;
  background: var(--surface-sunken); border: 1px solid var(--border-subtle); border-radius: var(--radius-lg); padding: var(--space-3); }
.cd-column__head { display: flex; align-items: center; gap: var(--space-2); padding: var(--space-1) var(--space-1) 0; }
.cd-column__name { font-size: 11px; line-height: 14px; font-weight: 600; letter-spacing: 0.08em;
  text-transform: uppercase; color: var(--ink-secondary); }
.cd-column__count { font-size: 11px; font-weight: 600; color: var(--ink-tertiary); }

/* ---------- Avatar ---------- */
.cd-avatar { width: 22px; height: 22px; border-radius: var(--radius-full); flex: none;
  display: grid; place-items: center; font-size: 10px; font-weight: 600;
  background: var(--surface-active); color: var(--ink-secondary); }
.cd-avatar--ai { background: var(--accent-subtle); color: var(--accent-text); border: 1px solid var(--accent-border); }
.cd-avatar--lg { width: 28px; height: 28px; font-size: 11px; }

/* ---------- Conversation ---------- */
.cd-convo { display: flex; flex-direction: column; gap: var(--space-5); }
.cd-msg { display: flex; gap: var(--space-3); }
.cd-msg__body { min-width: 0; }
.cd-msg__head { display: flex; align-items: baseline; gap: var(--space-2); margin-bottom: var(--space-1); }
.cd-msg__author { font-size: 13px; font-weight: 600; }
.cd-msg__time { font-size: 12px; color: var(--ink-tertiary); }
.cd-msg__text { font-size: 15px; line-height: 23px; color: var(--ink-primary); margin: 0; }
.cd-msg__text p { margin: 0 0 var(--space-2); }
.cd-msg__text p:last-child { margin-bottom: 0; }
.cd-msg--ai .cd-msg__text { background: var(--accent-subtle); border: 1px solid var(--accent-border);
  border-radius: var(--radius-md); padding: var(--space-3) var(--space-4); }
.cd-msg__decision { display: flex; gap: var(--space-2); align-items: flex-start; margin-top: var(--space-3);
  padding: var(--space-3) var(--space-4); border-left: 2px solid var(--accent);
  background: var(--surface-sunken); border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }
.cd-msg__decision b { font-weight: 600; }
.cd-composer { display: flex; flex-direction: column; gap: var(--space-2);
  border: 1px solid var(--border-strong); border-radius: var(--radius-md);
  background: var(--surface-raised); padding: var(--space-3); }
.cd-composer:focus-within { border-color: var(--accent); outline: var(--focus-width) solid var(--focus-ring); outline-offset: var(--focus-width); }
.cd-composer__input { border: none; background: none; resize: none; min-height: 40px; padding: 0;
  font-family: var(--font-sans); font-size: 15px; line-height: 23px; color: var(--ink-primary); }
.cd-composer__input:focus, .cd-root .cd-composer__input:focus-visible { outline: none; }
.cd-composer__input::placeholder { color: var(--ink-tertiary); }
.cd-composer__foot { display: flex; align-items: center; gap: var(--space-2); }
.cd-typing { display: inline-flex; align-items: center; gap: var(--space-2); font-size: 13px; color: var(--ink-tertiary); }
.cd-typing__dots { display: inline-flex; gap: 3px; }
.cd-typing__dots i { width: 4px; height: 4px; border-radius: var(--radius-full); background: var(--ink-tertiary);
  animation: cd-pulse 1.1s ease-in-out infinite; }
.cd-typing__dots i:nth-child(2) { animation-delay: 150ms; }
.cd-typing__dots i:nth-child(3) { animation-delay: 300ms; }
@keyframes cd-pulse { 0%, 100% { opacity: 0.35; } 50% { opacity: 1; } }

/* ---------- Approval panel ---------- */
.cd-approval { border: 1px solid var(--accent-border); border-radius: var(--radius-lg);
  background: var(--surface-raised); overflow: hidden; }
.cd-approval__head { display: flex; align-items: center; gap: var(--space-2);
  padding: var(--space-3) var(--space-4); background: var(--accent-subtle); border-bottom: 1px solid var(--accent-border); }
.cd-approval__title { font-size: 13px; font-weight: 600; color: var(--accent-text); }
.cd-approval__body { padding: var(--space-4); display: flex; flex-direction: column; gap: var(--space-3); }
.cd-approval__what { font-size: 15px; line-height: 23px; margin: 0; }
.cd-approval__list { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: var(--space-2); }
.cd-approval__list li { display: flex; gap: var(--space-2); font-size: 13px; line-height: 20px; color: var(--ink-secondary); }
.cd-approval__list code { font-family: var(--font-mono); font-size: 12.5px; color: var(--ink-primary); }
.cd-approval__foot { display: flex; align-items: center; gap: var(--space-2);
  padding: var(--space-3) var(--space-4); border-top: 1px solid var(--border-subtle); background: var(--surface-canvas); }
.cd-approval__note { margin-left: auto; font-size: 12px; color: var(--ink-tertiary); }
.cd-approval--approved { border-color: color-mix(in srgb, var(--success) 35%, transparent); }
.cd-approval--approved .cd-approval__head { background: var(--success-subtle); border-bottom-color: color-mix(in srgb, var(--success) 35%, transparent); }
.cd-approval--approved .cd-approval__title { color: var(--success-text); }
.cd-approval--rejected { border-color: color-mix(in srgb, var(--danger) 35%, transparent); }
.cd-approval--rejected .cd-approval__head { background: var(--danger-subtle); border-bottom-color: color-mix(in srgb, var(--danger) 35%, transparent); }
.cd-approval--rejected .cd-approval__title { color: var(--danger-text); }

/* ---------- Activity feed ---------- */
.cd-feed { display: flex; flex-direction: column; margin: 0; padding: 0; list-style: none; }
.cd-feed__item { position: relative; display: flex; gap: var(--space-3); padding: 0 0 var(--space-4) 0; }
.cd-feed__rail { position: relative; flex: none; width: 22px; display: flex; justify-content: center; }
.cd-feed__rail::before { content: ""; position: absolute; top: 20px; bottom: -18px; width: 1px; background: var(--border-default); }
.cd-feed__item:last-child { padding-bottom: 0; }
.cd-feed__item:last-child .cd-feed__rail::before { display: none; }
.cd-feed__dot { width: 20px; height: 20px; border-radius: var(--radius-full); display: grid; place-items: center;
  background: var(--surface-sunken); border: 1px solid var(--border-default); color: var(--ink-secondary); z-index: 1; }
.cd-feed__dot--accent { background: var(--accent-subtle); border-color: var(--accent-border); color: var(--accent-text); }
.cd-feed__dot--success { background: var(--success-subtle); border-color: color-mix(in srgb, var(--success) 35%, transparent); color: var(--success-text); }
.cd-feed__dot--warning { background: var(--warning-subtle); border-color: color-mix(in srgb, var(--warning) 35%, transparent); color: var(--warning-text); }
.cd-feed__text { font-size: 13px; line-height: 20px; color: var(--ink-secondary); padding-top: 1px; }
.cd-feed__text b { font-weight: 600; color: var(--ink-primary); }
.cd-feed__time { display: block; font-size: 12px; line-height: 16px; color: var(--ink-tertiary); margin-top: 2px; }

/* ---------- Empty state ---------- */
.cd-empty { display: flex; flex-direction: column; align-items: center; text-align: center;
  gap: var(--space-3); padding: var(--space-12) var(--space-6); }
.cd-empty__glyph { width: 40px; height: 40px; border-radius: var(--radius-md); display: grid; place-items: center;
  background: var(--surface-sunken); border: 1px solid var(--border-subtle); color: var(--ink-tertiary); }
.cd-empty__title { font-size: 15px; font-weight: 600; margin: 0; }
.cd-empty__body { font-size: 13px; line-height: 20px; color: var(--ink-secondary); margin: 0; max-width: 42ch; }

/* ---------- Skeleton ---------- */
.cd-skel { background: var(--skeleton); border-radius: var(--radius-xs); height: 12px;
  opacity: var(--opacity-skeleton); animation: cd-pulse 1.4s ease-in-out infinite; }
.cd-skel--title { height: 16px; }

/* ---------- Layout helpers ---------- */
.cd-grid { display: grid; gap: var(--space-5); }
.cd-row { display: flex; align-items: center; gap: var(--space-3); }
.cd-stack { display: flex; flex-direction: column; gap: var(--space-3); }
.cd-divider { height: 1px; background: var(--border-subtle); border: 0; margin: 0; }

/* ---------- Cadence: select, checkbox and switch ----------
   The design system names them in its tokens (border-strong for their outline,
   radius-xs for a checkbox) but draws none. These are made from those tokens.
   One that is on takes the ink, not the accent: a page of settings has many. */
.cd-select {
  height: var(--control-md); padding: 0 var(--space-2);
  background: var(--surface-raised); color: var(--ink-primary);
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  font-family: var(--font-sans); font-size: 14px; line-height: 20px;
}
.cd-select:hover { border-color: var(--ink-tertiary); }
.cd-select[disabled] { background: var(--surface-sunken); color: var(--ink-tertiary); border-color: var(--border-default); cursor: not-allowed; }
.cd-check, .cd-switch { display: inline-flex; align-items: center; gap: var(--space-2); font-size: 14px; line-height: 20px; color: var(--ink-primary); cursor: pointer; }
.cd-check input, .cd-switch input { appearance: none; -webkit-appearance: none; margin: 0; flex: none; cursor: pointer; border: 1px solid var(--border-strong); background: var(--surface-raised); transition: background-color 120ms ease, border-color 120ms ease; }
.cd-check input { width: 16px; height: 16px; border-radius: var(--radius-xs); display: grid; place-content: center; }
.cd-check input:checked { background: var(--ink-primary); border-color: var(--ink-primary); }
.cd-check input:checked::after { content: ""; width: 9px; height: 5px; border-left: 1.5px solid var(--surface-raised); border-bottom: 1.5px solid var(--surface-raised); transform: translateY(-1px) rotate(-45deg); }
.cd-switch input { position: relative; width: 32px; height: 18px; border-radius: var(--radius-full); background: var(--surface-sunken); }
.cd-switch input::after { content: ""; position: absolute; top: 2px; left: 2px; width: 12px; height: 12px; border-radius: var(--radius-full); background: var(--border-strong); }
.cd-switch input:checked { background: var(--ink-primary); border-color: var(--ink-primary); }
.cd-switch input:checked::after { left: 16px; background: var(--surface-raised); }
.cd-check:has(input[disabled]), .cd-switch:has(input[disabled]) { cursor: not-allowed; }
.cd-check input[disabled], .cd-switch input[disabled] { opacity: var(--opacity-disabled); cursor: not-allowed; }

/* ---------- Cadence: touch and motion ----------
   To the touch a control is at least 44px tall, as the size tokens say. A
   looping animation is slowed, not removed, for people who ask for less motion. */
@media (pointer: coarse) {
  .cd-btn, .cd-input, .cd-select, .cd-tab, .cd-nav__item { min-height: 44px; }
  .cd-btn--icon { min-width: 44px; }
  .cd-check, .cd-switch { min-height: 44px; }
}
@media (prefers-reduced-motion: reduce) {
  .cd-typing__dots i, .cd-skel { animation-duration: 4s; }
}
