/* ==========================================================================
   Components — buttons, cards, avatars, pills, fields, sheets, toasts.
   ========================================================================== */

/* --- buttons ------------------------------------------------------------- */
.btn {
  position: relative;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 32px;
  padding: 0 13px;
  border-radius: var(--r-sm);
  font-size: var(--fs-base);
  font-weight: 550;
  color: var(--text);
  background: var(--surface);
  border: var(--hairline) solid var(--separator-firm);
  box-shadow: var(--shadow-xs);
  white-space: nowrap;
  cursor: pointer;
  transition: background var(--t-fast) var(--ease), color var(--t-fast) var(--ease),
              border-color var(--t-fast) var(--ease), box-shadow var(--t-fast) var(--ease),
              transform var(--t-fast) var(--ease-spring), opacity var(--t-fast) var(--ease);
}
.btn:hover { background: var(--surface-2); border-color: var(--separator-firm); box-shadow: var(--shadow-sm); }
.btn:active { transform: scale(0.965); box-shadow: none; }
.btn:disabled { opacity: 0.45; pointer-events: none; }
.btn .icon { width: 15px; height: 15px; }

.btn--primary {
  background: var(--accent); color: #fff;
  border-color: transparent; box-shadow: var(--shadow-accent);
}
.btn--primary:hover { background: var(--accent-hover); box-shadow: 0 6px 18px rgba(0,122,255,0.34); }

.btn--accent { background: var(--accent-2); color: #fff; border-color: transparent; }
.btn--accent:hover { background: var(--purple-600); }

.btn--danger { color: var(--red); }
.btn--danger:hover { background: var(--red-soft); border-color: transparent; }

.btn--ghost { background: transparent; border-color: transparent; box-shadow: none; }
.btn--ghost:hover { background: var(--surface-hover); box-shadow: none; }

.btn--soft { background: var(--accent-soft); color: var(--accent); border-color: transparent; box-shadow: none; }
.btn--soft:hover { background: color-mix(in srgb, var(--accent) 18%, transparent); }

.btn--sm { height: 27px; padding: 0 10px; font-size: var(--fs-sm); border-radius: var(--r-xs); }
.btn--lg { height: 40px; padding: 0 20px; font-size: var(--fs-md); border-radius: var(--r-md); }
.btn--icon { width: 32px; padding: 0; }
.btn--icon.btn--sm { width: 27px; }
.btn--block { width: 100%; }

.btn.is-busy { color: transparent !important; pointer-events: none; }
.btn.is-busy::after {
  content: ""; position: absolute; inset: 0; margin: auto;
  width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid currentColor; border-top-color: transparent;
  color: var(--text-2);
  animation: spin 0.62s linear infinite;
}
.btn--primary.is-busy::after, .btn--accent.is-busy::after { color: #fff; }
@keyframes spin { to { transform: rotate(360deg); } }

/* --- segmented control (iOS) -------------------------------------------- */
.segmented {
  position: relative;
  display: inline-flex;
  padding: 2px;
  border-radius: var(--r-sm);
  background: var(--surface-3);
  gap: 2px;
}
.segmented__thumb {
  position: absolute; top: 2px; left: 2px;
  height: calc(100% - 4px);
  border-radius: 7px;
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  transition: transform var(--t) var(--ease), width var(--t) var(--ease);
  pointer-events: none;
}
.segmented__btn {
  position: relative; z-index: 1;
  height: 26px; padding: 0 12px;
  border-radius: 7px;
  font-size: var(--fs-sm); font-weight: 560;
  color: var(--text-3);
  display: inline-flex; align-items: center; gap: 5px;
  transition: color var(--t-fast) var(--ease), transform var(--t-fast) var(--ease);
}
.segmented__btn:active { transform: scale(0.95); }
.segmented__btn.is-active { color: var(--text); }

/* --- cards --------------------------------------------------------------- */
.card {
  background: var(--surface);
  border: var(--hairline) solid var(--separator);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-sm);
  transition: box-shadow var(--t) var(--ease), transform var(--t) var(--ease),
              border-color var(--t) var(--ease), background var(--t) var(--ease);
}
.card--pad { padding: var(--sp-5); }
.card--tight { padding: var(--sp-4); }
.card--hover:hover { box-shadow: var(--shadow); transform: translateY(-2px); }
.card--flat { box-shadow: none; background: var(--surface-2); }
.card__head {
  display: flex; align-items: center; gap: var(--sp-2);
  padding: var(--sp-4) var(--sp-5);
  border-bottom: var(--hairline) solid var(--separator);
}
.card__title { font-size: var(--fs-md); font-weight: 620; letter-spacing: -0.02em; }
.card__body { padding: var(--sp-5); }

/* --- stat tile ----------------------------------------------------------- */
.stat {
  position: relative;
  padding: var(--sp-4) var(--sp-5);
  border-radius: var(--r-lg);
  background: var(--surface);
  border: var(--hairline) solid var(--separator);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  transition: transform var(--t) var(--ease), box-shadow var(--t) var(--ease);
}
.stat:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.stat::after {
  content: ""; position: absolute; inset: auto auto 0 0;
  height: 2.5px; width: 100%;
  background: linear-gradient(90deg, var(--tint, var(--accent)), transparent 82%);
  opacity: 0.85;
}
.stat__label {
  font-size: var(--fs-xs); font-weight: 620; text-transform: uppercase;
  letter-spacing: var(--tracking-wide); color: var(--text-4);
}
.stat__value {
  margin-top: 6px;
  font-size: var(--fs-2xl); font-weight: 680; letter-spacing: -0.035em;
  font-variant-numeric: tabular-nums; line-height: 1.1;
}
.stat__sub { margin-top: 4px; font-size: var(--fs-sm); color: var(--text-3); }

/* Tiles that lead somewhere: full-width text-left button with a chevron that slides in. */
.stat--link {
  display: block; width: 100%; text-align: left;
  cursor: pointer; font: inherit; color: inherit;
}
.stat--link:active { transform: translateY(0) scale(0.99); }
.stat__go {
  position: absolute; top: 50%; right: var(--sp-4);
  transform: translate(6px, -50%);
  color: var(--text-4);
  opacity: 0;
  transition: opacity var(--t) var(--ease), transform var(--t) var(--ease),
              color var(--t) var(--ease);
}
.stat--link:hover .stat__go { opacity: 1; transform: translate(0, -50%); color: var(--tint, var(--accent)); }
.stat--link:focus-visible .stat__go { opacity: 1; transform: translate(0, -50%); }

/* --- avatar -------------------------------------------------------------- */
.avatar {
  position: relative;
  flex: 0 0 auto;
  width: 36px; height: 36px;
  border-radius: 50%;
  display: grid; place-items: center;
  font-size: var(--fs-sm); font-weight: 620; letter-spacing: -0.02em;
  color: #fff;
  background: linear-gradient(150deg, var(--av-a, var(--blue)), var(--av-b, var(--purple)));
  box-shadow: inset 0 0 0 var(--hairline) rgba(0,0,0,0.07), var(--shadow-xs);
  user-select: none;
  overflow: hidden;
  transition: transform var(--t) var(--ease-spring), box-shadow var(--t) var(--ease);
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar--xs { width: 22px; height: 22px; font-size: 9.5px; }
.avatar--sm { width: 30px; height: 30px; font-size: var(--fs-xs); }
.avatar--lg { width: 56px; height: 56px; font-size: var(--fs-lg); }
.avatar--xl { width: 76px; height: 76px; font-size: var(--fs-2xl); border-radius: 24px; }
.avatar__badge {
  position: absolute; right: -1px; bottom: -1px;
  width: 12px; height: 12px; border-radius: 50%;
  border: 2px solid var(--surface);
  background: var(--green);
}

/* --- pills & tags -------------------------------------------------------- */
.pill {
  display: inline-flex; align-items: center; gap: 5px;
  height: 21px; padding: 0 9px;
  border-radius: var(--r-pill);
  font-size: var(--fs-xs); font-weight: 620;
  letter-spacing: 0;
  background: var(--gray-soft); color: var(--text-2);
  white-space: nowrap;
  transition: background var(--t-fast) var(--ease), transform var(--t-fast) var(--ease);
}
.pill__dot { width: 5px; height: 5px; border-radius: 50%; background: currentColor; }
.pill--lg { height: 26px; padding: 0 12px; font-size: var(--fs-sm); }
.pill--stage { background: var(--hue-soft, var(--gray-soft)); color: var(--hue, var(--text-2)); }
.pill--button { cursor: pointer; }
.pill--button:hover { filter: brightness(0.97); }
.pill--button:active { transform: scale(0.95); }

.tag {
  display: inline-flex; align-items: center;
  height: 20px; padding: 0 8px;
  border-radius: var(--r-xs);
  background: var(--surface-3); color: var(--text-3);
  font-size: var(--fs-xs); font-weight: 550;
  transition: background var(--t-fast) var(--ease), color var(--t-fast) var(--ease);
}
.tag:hover { background: var(--accent-soft); color: var(--accent); }

/* --- score ring ---------------------------------------------------------- */
.ring { position: relative; width: 42px; height: 42px; flex: 0 0 auto; }
.ring svg { transform: rotate(-90deg); }
.ring__track { fill: none; stroke: var(--surface-3); stroke-width: 4; }
.ring__bar {
  fill: none; stroke: var(--tint, var(--accent)); stroke-width: 4; stroke-linecap: round;
  transition: stroke-dashoffset var(--t-lazy) var(--ease);
}
.ring__value {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  font-size: var(--fs-sm); font-weight: 660; font-variant-numeric: tabular-nums;
}

/* --- fields -------------------------------------------------------------- */
.field { display: flex; flex-direction: column; gap: 6px; }
.field__label {
  font-size: var(--fs-xs); font-weight: 620; text-transform: uppercase;
  letter-spacing: var(--tracking-wide); color: var(--text-4);
}
.input, .textarea, .select {
  width: 100%;
  min-height: 34px;
  padding: 7px 11px;
  border-radius: var(--r-sm);
  background: var(--surface);
  border: var(--hairline) solid var(--separator-firm);
  color: var(--text);
  font-size: var(--fs-base);
  transition: border-color var(--t-fast) var(--ease), box-shadow var(--t-fast) var(--ease),
              background var(--t-fast) var(--ease);
}
.input::placeholder, .textarea::placeholder { color: var(--text-4); }
.input:focus, .textarea:focus, .select:focus {
  border-color: var(--accent); box-shadow: var(--ring); outline: none;
}
.textarea { resize: vertical; min-height: 74px; line-height: var(--lh); }
.select { appearance: none; cursor: pointer; padding-right: 30px;
  background-image: linear-gradient(45deg, transparent 50%, var(--text-3) 50%),
                    linear-gradient(135deg, var(--text-3) 50%, transparent 50%);
  background-position: calc(100% - 15px) 14px, calc(100% - 10px) 14px;
  background-size: 5px 5px, 5px 5px; background-repeat: no-repeat; }

.search {
  position: relative; display: flex; align-items: center;
  height: 32px; min-width: 200px;
  padding: 0 10px 0 30px;
  border-radius: var(--r-sm);
  background: var(--surface-3);
  border: var(--hairline) solid transparent;
  transition: background var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease),
              box-shadow var(--t-fast) var(--ease), width var(--t) var(--ease);
}
.search:focus-within { background: var(--surface); border-color: var(--accent); box-shadow: var(--ring); }
.search .icon { position: absolute; left: 9px; width: 15px; height: 15px; color: var(--text-4); }
.search input { width: 100%; border: 0; background: none; font-size: var(--fs-base); }
.search input:focus { outline: none; }
.search kbd {
  font-family: var(--font); font-size: var(--fs-xs); color: var(--text-4);
  border: var(--hairline) solid var(--separator-firm); border-radius: 4px;
  padding: 1px 5px; margin-left: 6px; white-space: nowrap;
}

.switch {
  position: relative; width: 40px; height: 24px; flex: 0 0 auto;
  border-radius: var(--r-pill); background: var(--surface-3);
  border: var(--hairline) solid var(--separator);
  cursor: pointer;
  transition: background var(--t) var(--ease);
}
.switch::after {
  content: ""; position: absolute; top: 2px; left: 2px;
  width: 18px; height: 18px; border-radius: 50%;
  background: #fff; box-shadow: var(--shadow-sm);
  transition: transform var(--t) var(--ease-spring);
}
.switch.is-on { background: var(--green); border-color: transparent; }
.switch.is-on::after { transform: translateX(16px); }

/* --- list rows ----------------------------------------------------------- */
.list { border-radius: var(--r-lg); overflow: hidden; }
.list-row {
  position: relative;
  display: flex; align-items: center; gap: var(--sp-3);
  width: 100%;
  padding: 11px var(--sp-4);
  text-align: left;
  border-radius: var(--r-md);
  transition: background var(--t-fast) var(--ease), transform var(--t-fast) var(--ease);
}
.list-row:hover { background: var(--surface-hover); }
.list-row:active { transform: scale(0.995); background: var(--surface-press); }
.list-row + .list-row { box-shadow: inset 0 var(--hairline) 0 var(--separator); }
.list-row__title { font-size: var(--fs-base); font-weight: 570; }
.list-row__sub { font-size: var(--fs-sm); color: var(--text-3); margin-top: 1px; }
.list-row__aside { margin-left: auto; text-align: right; flex: 0 0 auto; }

/* --- tabs ---------------------------------------------------------------- */
.tabs {
  position: relative;
  display: flex; gap: 2px;
  border-bottom: var(--hairline) solid var(--separator);
  overflow-x: auto;
}
.tab {
  position: relative;
  padding: 9px 13px 11px;
  font-size: var(--fs-base); font-weight: 550;
  color: var(--text-3);
  white-space: nowrap;
  transition: color var(--t-fast) var(--ease);
}
.tab:hover { color: var(--text); }
.tab.is-active { color: var(--text); font-weight: 600; }
.tab__count {
  margin-left: 5px; font-size: var(--fs-xs); color: var(--text-4);
  font-variant-numeric: tabular-nums;
}
.tabs__ink {
  position: absolute; bottom: 0; left: 0; height: 2px;
  background: var(--accent); border-radius: 2px 2px 0 0;
  transition: transform var(--t) var(--ease), width var(--t) var(--ease);
}

/* --- empty & skeleton ---------------------------------------------------- */
.empty {
  display: flex; flex-direction: column; align-items: center; gap: var(--sp-3);
  padding: var(--sp-9) var(--sp-5);
  text-align: center;
  animation: popIn var(--t-slow) var(--ease) both;
}
.empty__icon {
  width: 46px; height: 46px; border-radius: var(--r-lg);
  display: grid; place-items: center;
  background: var(--surface-3); color: var(--text-4);
}
.empty__title { font-size: var(--fs-md); font-weight: 620; }
.empty__text { font-size: var(--fs-base); color: var(--text-3); max-width: 380px; }

.skel {
  border-radius: var(--r-sm);
  background: linear-gradient(90deg, var(--surface-3) 25%, var(--surface-hover) 37%, var(--surface-3) 63%);
  background-size: 840px 100%;
  animation: shimmer 1.5s linear infinite;
}
.skel--text { height: 11px; margin: 6px 0; }
.skel--title { height: 18px; width: 42%; }
.skel--card { height: 88px; border-radius: var(--r-lg); }
.skel--avatar { width: 36px; height: 36px; border-radius: 50%; }

/* --- sheets / modals ----------------------------------------------------- */
/* Layer order, low to high:
   popover 90 · peek 110 · fab 120 · assistant 130 · scrim (sheets, chat popup) 200 ·
   toasts 300. Sheets must clear the assistant and a peek, since either can raise one. */
.scrim {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(0, 0, 0, 0.28);
  backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px);
  display: grid; place-items: center;
  padding: var(--sp-5);
  animation: fadeIn var(--t) var(--ease) both;
}
.scrim.is-closing { animation: fadeIn var(--t-fast) var(--ease) reverse both; }

.sheet {
  width: min(560px, 100%);
  max-height: min(84vh, 760px);
  display: flex; flex-direction: column;
  background: var(--material-thick);
  backdrop-filter: var(--blur); -webkit-backdrop-filter: var(--blur);
  border: var(--hairline) solid var(--separator-firm);
  border-radius: var(--r-2xl);
  box-shadow: var(--shadow-xl);
  overflow: hidden;
  animation: sheetIn var(--t-slow) var(--ease-spring) both;
}
.sheet--wide { width: min(760px, 100%); }
.scrim.is-closing .sheet { animation: sheetOut var(--t-fast) var(--ease-in-out) both; }

@keyframes sheetIn {
  from { opacity: 0; transform: translateY(18px) scale(0.96); }
  to   { opacity: 1; transform: none; }
}
@keyframes sheetOut {
  from { opacity: 1; transform: none; }
  to   { opacity: 0; transform: translateY(8px) scale(0.985); }
}

.sheet__head {
  display: flex; align-items: center; gap: var(--sp-3);
  padding: var(--sp-4) var(--sp-5);
  border-bottom: var(--hairline) solid var(--separator);
}
.sheet__title { font-size: var(--fs-lg); font-weight: 640; letter-spacing: -0.02em; }
.sheet__body { padding: var(--sp-5); overflow-y: auto; display: flex; flex-direction: column; gap: var(--sp-4); }
.sheet__foot {
  display: flex; gap: var(--sp-2); justify-content: flex-end;
  padding: var(--sp-4) var(--sp-5);
  border-top: var(--hairline) solid var(--separator);
}

/* --- toasts -------------------------------------------------------------- */
.toasts {
  position: fixed; top: calc(var(--topbar-h) + 12px); right: 20px; z-index: 300;
  display: flex; flex-direction: column; gap: 8px;
  pointer-events: none;
}
.toast {
  display: flex; align-items: center; gap: 10px;
  min-width: 260px; max-width: 400px;
  padding: 11px 14px;
  border-radius: var(--r-md);
  background: var(--material-thick);
  backdrop-filter: var(--blur); -webkit-backdrop-filter: var(--blur);
  border: var(--hairline) solid var(--separator-firm);
  box-shadow: var(--shadow-lg);
  font-size: var(--fs-base); font-weight: 520;
  pointer-events: auto;
  animation: toastIn var(--t-slow) var(--ease-spring) both;
}
.toast.is-closing { animation: toastOut var(--t) var(--ease-in-out) both; }
.toast__icon { width: 18px; height: 18px; flex: 0 0 auto; }
.toast--success .toast__icon { color: var(--green); }
.toast--error   .toast__icon { color: var(--red); }
.toast--warn    .toast__icon { color: var(--amber); }
.toast--info    .toast__icon { color: var(--accent); }

@keyframes toastIn {
  from { opacity: 0; transform: translateX(28px) scale(0.94); }
  to   { opacity: 1; transform: none; }
}
@keyframes toastOut {
  from { opacity: 1; transform: none; }
  to   { opacity: 0; transform: translateX(20px) scale(0.96); }
}

/* --- command palette ----------------------------------------------------- */
.palette {
  width: min(620px, 100%);
  align-self: start; margin-top: 12vh;
  background: var(--material-thick);
  backdrop-filter: var(--blur); -webkit-backdrop-filter: var(--blur);
  border: var(--hairline) solid var(--separator-firm);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-xl);
  overflow: hidden;
  animation: sheetIn var(--t-slow) var(--ease-spring) both;
}
/* Every other panel in a scrim has one of these. Without it the palette left the scrim
   sitting invisibly over the page, because the teardown was waiting on an animation that
   never ran. */
.scrim.is-closing .palette { animation: sheetOut var(--t-fast) var(--ease-in-out) both; }
.palette__input {
  width: 100%; height: 52px;
  padding: 0 var(--sp-5);
  border: 0; background: none;
  font-size: var(--fs-lg); letter-spacing: -0.02em;
  border-bottom: var(--hairline) solid var(--separator);
}
.palette__input:focus { outline: none; }
.palette__results { max-height: 46vh; overflow-y: auto; padding: var(--sp-2); }
.palette__group {
  padding: var(--sp-3) var(--sp-3) 4px;
  font-size: var(--fs-xs); font-weight: 620; text-transform: uppercase;
  letter-spacing: var(--tracking-wide); color: var(--text-4);
}
.palette__item {
  display: flex; align-items: center; gap: 10px;
  width: 100%; padding: 8px 10px;
  border-radius: var(--r-sm);
  text-align: left;
  transition: background var(--t-fast) var(--ease);
}
.palette__item.is-active, .palette__item:hover { background: var(--surface-hover); }
.palette__item.is-active { background: var(--accent-soft); color: var(--accent); }

/* --- misc ---------------------------------------------------------------- */
.divider { height: var(--hairline); background: var(--separator); border: 0; margin: var(--sp-4) 0; }

.kv { display: grid; grid-template-columns: 132px 1fr; gap: 9px var(--sp-3); align-items: baseline; }
.kv__k { font-size: var(--fs-sm); color: var(--text-3); }
.kv__v { font-size: var(--fs-base); min-width: 0; word-break: break-word; }
.kv__v.is-editable { cursor: text; border-radius: var(--r-xs); padding: 2px 5px; margin: -2px -5px;
                     transition: background var(--t-fast) var(--ease); }
.kv__v.is-editable:hover { background: var(--surface-hover); }
.kv__v.is-empty { color: var(--text-4); font-style: italic; }

.meter { height: 6px; border-radius: var(--r-pill); background: var(--surface-3); overflow: hidden; }
.meter__fill {
  height: 100%; border-radius: var(--r-pill);
  background: linear-gradient(90deg, var(--tint, var(--accent)), color-mix(in srgb, var(--tint, var(--accent)) 62%, var(--purple)));
  transition: width var(--t-lazy) var(--ease);
}

.icon { display: inline-block; vertical-align: middle; stroke-width: 1.75; }
