/* ==========================================================================
   Journey Tracker Style Guide — Components
   Buttons, pills, inputs, cards, avatars, progress, toggles, etc.
   ========================================================================== */

/* ---------------------------------------------------------------
   BUTTONS
   --------------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 36px;
  padding: 0 16px;
  border: 1px solid transparent;
  border-radius: var(--radius-pill);
  background: var(--accent);
  color: var(--fg-on-accent);
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.1px;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease, box-shadow 0.15s ease, transform 0.05s ease;
  box-shadow: var(--shadow-xs);
  white-space: nowrap;
  line-height: 1;
}
.btn [data-lucide] { width: 15px; height: 15px; stroke-width: 2.2; }
.btn:hover { background: var(--accent-hover); }
.btn:focus-visible { outline: 0; box-shadow: var(--ring-focus); }
.btn:active { transform: translateY(0.5px); }
.btn[disabled] {
  background: var(--bg-offset);
  color: var(--fg-3);
  cursor: not-allowed;
  box-shadow: none;
}

.btn--secondary {
  background: var(--bg-surface);
  color: var(--fg-1);
  border-color: var(--border-2);
}
.btn--secondary:hover { background: var(--bg-subtle); border-color: var(--border-3); }
.btn--secondary[disabled] { background: var(--bg-offset); color: var(--fg-3); border-color: var(--border-1); }

.btn--ghost {
  background: transparent;
  color: var(--fg-2);
  box-shadow: none;
}
.btn--ghost:hover { background: var(--bg-subtle); color: var(--fg-1); }

.btn--danger {
  background: var(--st-overdue);
  color: #fff;
}
.btn--danger:hover { filter: brightness(0.94); }

.btn--sm { height: 28px; padding: 0 12px; font-size: 12px; }
.btn--lg { height: 44px; padding: 0 22px; font-size: 14px; }

/* Round icon button */
.btn-round {
  width: 36px; height: 36px;
  border-radius: 9999px;
  border: 0;
  background: var(--accent);
  color: var(--fg-on-accent);
  display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer;
  box-shadow: var(--shadow-xs);
  transition: background 0.15s ease, transform 0.1s ease;
}
.btn-round:hover { background: var(--accent-hover); }
.btn-round:active { transform: scale(0.96); }
.btn-round [data-lucide] { width: 16px; height: 16px; stroke-width: 2.4; }
.btn-round--success { background: var(--st-success); }
.btn-round--success:hover { filter: brightness(0.95); }
.btn-round--danger { background: var(--st-overdue); }
.btn-round--danger:hover { filter: brightness(0.95); }
.btn-round--ghost {
  background: var(--bg-offset); color: var(--fg-2); box-shadow: none;
}
.btn-round--ghost:hover { background: var(--accent-soft); color: var(--accent); }

/* Square icon (compact, table-row size) */
.btn-icon {
  width: 30px; height: 30px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-1);
  background: var(--bg-surface);
  color: var(--fg-2);
  display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer;
  transition: all 0.12s ease;
}
.btn-icon:hover { background: var(--bg-subtle); color: var(--fg-1); border-color: var(--border-2); }
.btn-icon [data-lucide] { width: 14px; height: 14px; }

/* ---------------------------------------------------------------
   PILLS / BADGES
   --------------------------------------------------------------- */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 24px;
  padding: 0 10px;
  border-radius: var(--radius-pill);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.1px;
  line-height: 1;
  white-space: nowrap;
}
.pill [data-lucide] { width: 12px; height: 12px; stroke-width: 2.4; }
.pill--lg { height: 28px; padding: 0 12px; font-size: 13px; }

/* Soft (default) — subtle tint with ring */
.pill--info    { background: var(--st-info-soft);    color: var(--st-info);    box-shadow: inset 0 0 0 1px var(--st-info-ring); }
.pill--success { background: var(--st-success-soft); color: var(--st-success); box-shadow: inset 0 0 0 1px var(--st-success-ring); }
.pill--review  { background: var(--st-review-soft);  color: var(--st-review);  box-shadow: inset 0 0 0 1px var(--st-review-ring); }
.pill--late    { background: var(--st-late-soft);    color: var(--st-late);    box-shadow: inset 0 0 0 1px var(--st-late-ring); }
.pill--overdue { background: var(--st-overdue-soft); color: var(--st-overdue); box-shadow: inset 0 0 0 1px var(--st-overdue-ring); }
.pill--draft   { background: var(--st-draft-soft);   color: var(--st-draft);   box-shadow: inset 0 0 0 1px var(--st-draft-ring); }
.pill--archive { background: var(--st-archive-soft); color: var(--st-archive); box-shadow: inset 0 0 0 1px var(--st-archive-ring); }
.pill--neutral { background: var(--bg-offset);       color: var(--fg-2);       box-shadow: inset 0 0 0 1px var(--border-1); }

/* Solid variant */
.pill--solid.pill--info    { background: var(--st-info);    color: #fff; box-shadow: none; }
.pill--solid.pill--success { background: var(--st-success); color: #fff; box-shadow: none; }
.pill--solid.pill--review  { background: var(--st-review);  color: #fff; box-shadow: none; }
.pill--solid.pill--late    { background: var(--st-late);    color: #fff; box-shadow: none; }
.pill--solid.pill--overdue { background: var(--st-overdue); color: #fff; box-shadow: none; }
.pill--solid.pill--draft   { background: var(--st-draft);   color: #fff; box-shadow: none; }

/* Pip — colored leading dot inside neutral pill */
.pill .pip {
  width: 7px; height: 7px;
  border-radius: 9999px;
  background: currentColor;
  flex-shrink: 0;
}

/* Count badge (small numeric chip) */
.badge-count {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 20px; height: 20px;
  padding: 0 6px;
  border-radius: 9999px;
  background: var(--bg-offset);
  color: var(--fg-2);
  font-size: 11px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}
.badge-count--accent { background: var(--accent-soft); color: var(--accent); }
.badge-count--alert  { background: var(--st-overdue);  color: #fff; }

/* ---------------------------------------------------------------
   INPUTS
   --------------------------------------------------------------- */
.input,
.select,
.textarea {
  width: 100%;
  height: 100%;
  appearance: none;
  font: inherit;
  font-size: 14px;
  color: var(--fg-1);
  background: var(--bg-surface);
  border: 1px solid var(--border-2);
  border-radius: var(--radius-md);
  padding: 9px 12px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}
.input::placeholder, .textarea::placeholder { color: var(--fg-3); }
.input:hover, .select:hover, .textarea:hover { border-color: var(--border-3); }
.input:focus, .select:focus, .textarea:focus {
  outline: 0;
  border-color: var(--accent);
  box-shadow: var(--ring-focus);
}
.input[disabled], .textarea[disabled] {
  background: var(--bg-offset);
  color: var(--fg-3);
  cursor: not-allowed;
}
.textarea { min-height: 96px; resize: vertical; line-height: 1.5; }

.select {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'><path d='m6 9 6 6 6-6'/></svg>");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
}

/* Field — label + input + helper text */
.field { display: flex; flex-direction: column; gap: 6px; min-width: 220px; }
.field label {
  font-size: 12px; font-weight: 600; color: var(--fg-2);
  letter-spacing: 0.1px;
}
.field .helper { font-size: 12px; color: var(--fg-3); }
.field .helper.error { color: var(--st-overdue); }
.field.has-error .input,
.field.has-error .select,
.field.has-error .textarea {
  border-color: var(--st-overdue);
}
.field.has-error .input:focus,
.field.has-error .textarea:focus {
  box-shadow: 0 0 0 3px var(--st-overdue-ring);
}

/* Search — pill input with leading icon */
.search-input {
  display: inline-flex; align-items: center; gap: 8px;
  height: 36px; padding: 0 14px;
  background: var(--bg-surface);
  border: 1px solid var(--border-2);
  border-radius: var(--radius-pill);
  min-width: 280px;
  color: var(--fg-3);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.search-input:focus-within { border-color: var(--accent); box-shadow: var(--ring-focus); }
.search-input [data-lucide] { width: 15px; height: 15px; flex-shrink: 0; }
.search-input input {
  border: 0; outline: 0; background: transparent;
  font: inherit; flex: 1;
  color: var(--fg-1);
}
.search-input input::placeholder { color: var(--fg-3); }
.search-input .kbd {
  margin-left: auto;
  font-family: var(--font-mono);
  font-size: 11px;
  background: var(--bg-offset);
  color: var(--fg-3);
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-1);
}

/* Checkbox & radio.
   Selector is `input.check` / `input.radio` (not bare `.check` /
   `.radio`) so the rules tie on specificity with classic Rails
   `form input` selectors that ship via `app/assets/stylesheets/forms.scss`.
   With equal specificity, source order wins — and the design-system
   bundle loads after the classic stylesheet, so these styles win. */
input.check, input.radio {
  appearance: none;
  -webkit-appearance: none;
  width: 16px; height: 16px;
  background: var(--bg-surface);
  border: 1.5px solid var(--border-2);
  padding: 0;
  margin: 0;
  box-shadow: none;
  cursor: pointer;
  transition: all 0.12s ease;
  flex-shrink: 0;
}
input.check { border-radius: 4px; }
input.radio { border-radius: 9999px; }
input.check:hover, input.radio:hover { border-color: var(--border-3); }
input.check:focus-visible, input.radio:focus-visible { outline: 0; box-shadow: var(--ring-focus); }
input.check:checked {
  background: var(--accent);
  border-color: var(--accent);
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='3.2' stroke-linecap='round' stroke-linejoin='round'><polyline points='20 6 9 17 4 12'/></svg>");
  background-position: center;
  background-repeat: no-repeat;
  background-size: 12px;
}
input.radio:checked {
  border: 5px solid var(--accent);
  background: var(--bg-surface);
}

/* Toggle switch
   Selector is `input.switch` (not bare `.switch`) so the rules tie on
   specificity with Bootstrap's `form input` rules and win on source order.
   See the same pattern on input.check / input.radio above. */
input.switch {
  appearance: none;
  width: 36px; height: 20px;
  background: var(--border-2);
  border-radius: 9999px;
  position: relative;
  cursor: pointer;
  transition: background 0.15s ease;
  flex-shrink: 0;
}
input.switch::before {
  content: "";
  position: absolute;
  width: 14px; height: 14px;
  border-radius: 9999px;
  background: #fff;
  top: 3px; left: 3px;
  transition: transform 0.15s ease;
  box-shadow: var(--shadow-xs);
}
input.switch:checked { background: var(--accent); }
input.switch:checked::before { transform: translateX(16px); }
input.switch:focus-visible { outline: 0; box-shadow: var(--ring-focus); }

/* Inline check/radio label rows */
.opt-row { display: inline-flex; align-items: center; gap: 8px; font-size: 14px; color: var(--fg-1); cursor: pointer; }

/* ---------------------------------------------------------------
   CARDS & SURFACES
   --------------------------------------------------------------- */
.card {
  background: var(--bg-surface);
  border: 1px solid var(--border-1);
  border-radius: var(--radius-xl);
  padding: 20px;
  box-shadow: var(--shadow-xs);
}
.card--hero {
  border-radius: var(--radius-2xl);
  padding: 24px;
  box-shadow: var(--shadow-md);
}
.card--flat { box-shadow: none; }
.card--ghost {
  background: transparent;
  border-style: dashed;
  border-color: var(--border-2);
}
.card-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}
.card-head h3 { margin: 0; font-size: 15px; }

/* Stat card */
.stat {
  display: flex; flex-direction: column; gap: 6px;
}
.stat .eyebrow {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.6px;
  color: var(--fg-3);
  text-transform: uppercase;
}
.stat .number {
  font-family: var(--font-display);
  font-size: 32px;
  font-weight: 700;
  color: var(--fg-1);
  line-height: 1;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}
.stat .number--success { color: var(--st-success); }
.stat .number--danger  { color: var(--st-overdue); }
.stat .delta {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 12px; color: var(--fg-3);
}
.stat .delta [data-lucide] { width: 12px; height: 12px; }

/* List item / row */
.list-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  transition: background 0.12s ease;
}
.list-row + .list-row { border-top: 1px solid var(--border-1); }
.list-row:hover { background: var(--bg-subtle); }
.list-row .title { font-size: 14px; font-weight: 500; color: var(--fg-1); }
.list-row .sub   { font-size: 12px; color: var(--fg-3); margin-top: 2px; }

/* ---------------------------------------------------------------
   AVATARS
   --------------------------------------------------------------- */
.avatar {
  display: inline-flex; align-items: center; justify-content: center;
  width: 36px; height: 36px;
  border-radius: 9999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.2px;
  flex-shrink: 0;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,0.04);
}
.avatar--xs { width: 22px; height: 22px; font-size: 10px; }
.avatar--sm { width: 28px; height: 28px; font-size: 11px; }
.avatar--lg { width: 56px; height: 56px; font-size: 18px; }
.avatar--xl { width: 80px; height: 80px; font-size: 24px; }

.avatar--moss     { background: rgba(79,122,79,0.18);  color: #3e6240; }
.avatar--terra    { background: rgba(180,106,61,0.18); color: #94522d; }
.avatar--ocean    { background: rgba(58,122,156,0.18); color: #2c6184; }
.avatar--violet   { background: rgba(140,100,180,0.18); color: #6e4ea0; }
.avatar--amber    { background: rgba(213,147,17,0.18); color: #8c6111; }

.avatar-stack {
  display: inline-flex;
}
.avatar-stack .avatar {
  border: 2px solid var(--bg-surface);
  margin-left: -8px;
}
.avatar-stack .avatar:first-child { margin-left: 0; }

/* Avatar with status dot */
.avatar-wrap { position: relative; display: inline-block; }
.avatar-wrap .status-dot {
  position: absolute;
  bottom: 0; right: 0;
  width: 10px; height: 10px;
  border-radius: 9999px;
  background: var(--st-success);
  border: 2px solid var(--bg-surface);
}

/* ---------------------------------------------------------------
   PROGRESS
   --------------------------------------------------------------- */
.progress {
  height: 6px;
  width: 100%;
  background: var(--bg-offset);
  border-radius: 9999px;
  overflow: hidden;
}
.progress > .fill {
  height: 100%;
  background: var(--accent);
  border-radius: 9999px;
  transition: width 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}
.progress--success > .fill { background: var(--st-success); }
.progress--late > .fill    { background: var(--st-late); }
.progress--lg { height: 8px; }

/* Steps progress (badge plan) */
.steps {
  display: flex; gap: 4px;
}
.steps .step {
  flex: 1; height: 6px;
  background: var(--bg-offset);
  border-radius: 9999px;
}
.steps .step.done { background: var(--accent); }
.steps .step.now  { background: var(--accent-soft); box-shadow: inset 0 0 0 1.5px var(--accent); }

/* Meter (numeric value bar) */
.meter {
  display: grid; grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
  font-size: 12px;
  color: var(--fg-3);
}
.meter .lbl { color: var(--fg-2); font-weight: 500; }
.meter .val { font-variant-numeric: tabular-nums; font-weight: 600; color: var(--fg-1); }

/* Spinner */
.spinner {
  width: 18px; height: 18px;
  border-radius: 9999px;
  border: 2.5px solid var(--bg-offset);
  border-top-color: var(--accent);
  animation: sg-spin 0.8s linear infinite;
}
@keyframes sg-spin { to { transform: rotate(360deg); } }

/* Skeleton */
.skel {
  background: linear-gradient(90deg, var(--bg-offset) 0%, var(--bg-subtle) 50%, var(--bg-offset) 100%);
  background-size: 200% 100%;
  animation: sg-skel 1.2s ease-in-out infinite;
  border-radius: var(--radius-sm);
}
@keyframes sg-skel { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }
.skel--text { height: 12px; }
.skel--block { height: 60px; border-radius: var(--radius-md); }

/* ---------------------------------------------------------------
   TABS / SEGMENTED
   --------------------------------------------------------------- */
.tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--border-1);
}
.tabs button {
  appearance: none; border: 0; background: transparent;
  font: inherit; font-size: 13px; font-weight: 500;
  color: var(--fg-3);
  padding: 10px 14px;
  position: relative;
  cursor: pointer;
  transition: color 0.15s ease;
  border-radius: var(--radius-md) var(--radius-md) 0 0;
}
.tabs button:hover { color: var(--fg-1); background: var(--bg-subtle); }
.tabs button.active { color: var(--fg-1); font-weight: 600; }
.tabs button.active::after {
  content: "";
  position: absolute;
  left: 12px; right: 12px; bottom: -1px;
  height: 2px;
  background: var(--accent);
  border-radius: 2px;
}

.segmented {
  display: inline-flex;
  background: var(--bg-offset);
  border-radius: var(--radius-pill);
  padding: 3px;
  gap: 2px;
}
.segmented button,
.segmented .segmented-link {
  appearance: none; border: 0; background: transparent;
  font: inherit; font-size: 12px; font-weight: 600;
  color: var(--fg-2);
  padding: 6px 14px;
  border-radius: var(--radius-pill);
  cursor: pointer;
  transition: all 0.15s ease;
  text-decoration: none;
}
.segmented button:hover,
.segmented .segmented-link:hover { color: var(--fg-1); }
.segmented button.active,
.segmented .segmented-link.active {
  background: var(--bg-surface);
  color: var(--fg-1);
  box-shadow: var(--shadow-xs);
}

/* ---------------------------------------------------------------
   TOOLTIP & POPOVER
   --------------------------------------------------------------- */
.tooltip-wrap { position: relative; display: inline-block; }
.tooltip-wrap .tip {
  position: absolute;
  bottom: calc(100% + 6px); left: 50%;
  transform: translateX(-50%) translateY(2px);
  background: var(--bg-inverse);
  color: var(--bg-app);
  padding: 5px 9px;
  border-radius: var(--radius-sm);
  font-size: 11.5px;
  font-weight: 500;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.12s ease, transform 0.12s ease;
  box-shadow: var(--shadow-md);
}
.tooltip-wrap:hover .tip,
.tooltip-wrap:focus-within .tip {
  opacity: 1; transform: translateX(-50%) translateY(0);
}

/* ---------------------------------------------------------------
   ALERTS / TOASTS
   --------------------------------------------------------------- */
.alert {
  display: flex; gap: 12px; align-items: flex-start;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  background: var(--accent-soft);
  border: 1px solid var(--accent-ring);
  font-size: 13px;
  color: var(--fg-1);
}
.alert [data-lucide] { width: 16px; height: 16px; color: var(--accent); flex-shrink: 0; margin-top: 1px; }
.alert .body strong { display: block; margin-bottom: 2px; font-weight: 600; font-size: 13px; }
.alert .body p { font-size: 13px; color: var(--fg-2); }

.alert--success { background: var(--st-success-soft); border-color: var(--st-success-ring); }
.alert--success [data-lucide] { color: var(--st-success); }
.alert--late    { background: var(--st-late-soft); border-color: var(--st-late-ring); }
.alert--late [data-lucide] { color: var(--st-late); }
.alert--overdue { background: var(--st-overdue-soft); border-color: var(--st-overdue-ring); }
.alert--overdue [data-lucide] { color: var(--st-overdue); }

.toast {
  display: flex; gap: 12px; align-items: center;
  background: var(--bg-inverse);
  color: var(--bg-app);
  padding: 12px 16px;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  font-size: 13px;
  min-width: 320px;
}
.toast [data-lucide] { width: 16px; height: 16px; color: var(--accent); flex-shrink: 0; }
.toast .grow { flex: 1; }
.toast .dismiss {
  background: transparent; border: 0; color: inherit;
  opacity: 0.6; cursor: pointer; padding: 0;
  display: inline-flex; align-items: center;
}
.toast .dismiss:hover { opacity: 1; }
