/* ==========================================================================
   Components — reusable UI primitives. One block per component, BEM-ish.
   ========================================================================== */

/* --- Button -------------------------------------------------------------- */
.btn {
  --btn-bg: var(--surface);
  --btn-fg: var(--text);
  --btn-shadow: var(--shadow-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  min-height: 46px;
  padding: 0 var(--sp-5);
  border-radius: var(--r-pill);
  background: var(--btn-bg);
  color: var(--btn-fg);
  box-shadow: var(--btn-shadow);
  font-size: var(--fs-base);
  font-weight: var(--fw-bold);
  white-space: nowrap;
  transition: transform var(--dur-fast) var(--ease), filter var(--dur-fast), opacity var(--dur-fast);
}
.btn:active { transform: scale(.96); }
.btn[disabled] { opacity: .45; pointer-events: none; }

.btn--primary { --btn-bg: var(--brand-500); --btn-fg: var(--text-invert); --btn-shadow: var(--shadow-brand); }
.btn--success { --btn-bg: var(--mint-500); --btn-fg: #fff; --btn-shadow: 0 8px 18px rgba(22,185,138,.3); }
.btn--danger  { --btn-bg: var(--danger-soft); --btn-fg: var(--danger); --btn-shadow: none; }
.btn--ghost   { --btn-bg: transparent; --btn-fg: var(--text-muted); --btn-shadow: none; }
.btn--soft    { --btn-bg: var(--surface-muted); --btn-fg: var(--text); --btn-shadow: none; }
.btn--block   { display: flex; width: 100%; }
.btn--sm      { min-height: 36px; padding: 0 var(--sp-4); font-size: var(--fs-sm); }
.btn--lg      { min-height: 54px; font-size: var(--fs-md); }

/* --- Card ---------------------------------------------------------------- */
.card {
  background: var(--surface);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-sm);
  padding: var(--sp-4);
}
.card--flat { box-shadow: none; border: 1px solid var(--border); }
.card--pad-0 { padding: 0; overflow: hidden; }
.card--interactive { transition: transform var(--dur-fast) var(--ease), box-shadow var(--dur); text-align: left; width: 100%; }
.card--interactive:active { transform: scale(.985); box-shadow: var(--shadow-md); }

/* --- Hero banner --------------------------------------------------------- */
.hero {
  position: relative;
  overflow: hidden;
  border-radius: var(--r-xl);
  padding: var(--sp-5);
  color: #fff;
  background: linear-gradient(135deg, var(--hero-from), var(--hero-via) 55%, var(--hero-to));
  box-shadow: var(--shadow-brand);
}
.hero::after {
  content: '';
  position: absolute; inset: auto -30px -60px auto;
  width: 190px; height: 190px; border-radius: 50%;
  background: rgba(255, 255, 255, .14);
}
.hero__label { font-size: var(--fs-xs); font-weight: var(--fw-bold); opacity: .85; text-transform: uppercase; letter-spacing: .08em; }
.hero__value { font-size: var(--fs-3xl); font-weight: var(--fw-black); line-height: 1; }
.hero > * { position: relative; z-index: 1; }

/* --- Avatar -------------------------------------------------------------- */
.avatar {
  --size: 44px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: var(--size);
  height: var(--size);
  border-radius: var(--r-pill);
  background: var(--avatar-color, var(--brand-100));
  font-size: calc(var(--size) * .5);
  line-height: 1;
  user-select: none;
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, .35);
}
.avatar--sm { --size: 32px; }
.avatar--lg { --size: 64px; }
.avatar--xl { --size: 84px; }
.avatar--ring { box-shadow: 0 0 0 3px var(--surface), 0 0 0 6px var(--brand-500); }

/* --- Chip / badge -------------------------------------------------------- */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px var(--sp-2);
  border-radius: var(--r-pill);
  background: var(--surface-muted);
  color: var(--text-muted);
  font-size: var(--fs-xs);
  font-weight: var(--fw-bold);
  white-space: nowrap;
}
.chip--points  { background: var(--warning-soft); color: #9A6B00; }
.chip--time    { background: var(--info-soft);    color: #1D6FA5; }
.chip--done    { background: var(--success-soft); color: var(--success); }
.chip--mine    { background: var(--brand-100);    color: var(--brand-700); }
.chip--danger  { background: var(--danger-soft);  color: var(--danger); }
.chip--photo   { background: var(--surface-sunk); color: var(--text-muted); }

@media (prefers-color-scheme: dark) {
  .chip--points { color: var(--mango-400); }
  .chip--time   { color: var(--sky-400); }
  .chip--mine   { background: #2E2650; color: var(--brand-300); }
}

/* --- Segmented control --------------------------------------------------- */
.segmented {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 2px;
  padding: 3px;
  border-radius: var(--r-pill);
  background: var(--surface-sunk);
}
.segmented__btn {
  min-height: 34px;
  padding-inline: var(--sp-2);
  border-radius: var(--r-pill);
  font-size: var(--fs-sm);
  font-weight: var(--fw-bold);
  color: var(--text-muted);
  transition: background var(--dur-fast), color var(--dur-fast);
}
.segmented__btn[aria-selected='true'] {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}

/* --- Form fields --------------------------------------------------------- */
.field { display: flex; flex-direction: column; gap: 6px; }
.field__label {
  font-size: var(--fs-xs);
  font-weight: var(--fw-black);
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--text-faint);
}
.field__hint { font-size: var(--fs-xs); color: var(--text-faint); }

.input, .select, .textarea {
  width: 100%;
  min-height: 48px;
  padding: var(--sp-3) var(--sp-4);
  border: 1.5px solid var(--border);
  border-radius: var(--r-md);
  background: var(--surface);
  font-size: var(--fs-base);
  font-weight: var(--fw-medium);
  transition: border-color var(--dur-fast), box-shadow var(--dur-fast);
}
.input:focus, .select:focus, .textarea:focus {
  outline: none;
  border-color: var(--brand-300);
  box-shadow: 0 0 0 4px var(--brand-50);
}
.textarea { min-height: 84px; resize: vertical; line-height: var(--lh-body); }
.select {
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--text-faint) 50%),
                    linear-gradient(135deg, var(--text-faint) 50%, transparent 50%);
  background-position: calc(100% - 20px) 21px, calc(100% - 14px) 21px;
  background-size: 6px 6px;
  background-repeat: no-repeat;
  padding-right: var(--sp-10);
}

@media (prefers-color-scheme: dark) {
  .input:focus, .select:focus, .textarea:focus { box-shadow: 0 0 0 4px rgba(108, 92, 231, .22); }
}

/* Stepper (number ± control) */
.stepper { display: flex; align-items: center; gap: var(--sp-2); }
.stepper__btn {
  display: grid; place-items: center;
  width: 42px; height: 42px;
  border-radius: var(--r-pill);
  background: var(--surface-muted);
  font-size: var(--fs-lg); font-weight: var(--fw-bold);
  transition: transform var(--dur-fast) var(--ease);
}
.stepper__btn:active { transform: scale(.9); }
.stepper__value {
  min-width: 56px; text-align: center;
  font-size: var(--fs-lg); font-weight: var(--fw-black);
  font-variant-numeric: tabular-nums;
}

/* Emoji / colour pickers */
.picker-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(44px, 1fr));
  gap: var(--sp-2);
}
.picker-grid__item {
  display: grid; place-items: center;
  aspect-ratio: 1;
  border-radius: var(--r-md);
  background: var(--surface-muted);
  font-size: var(--fs-lg);
  transition: transform var(--dur-fast) var(--ease), box-shadow var(--dur-fast);
}
.picker-grid__item[aria-pressed='true'] { box-shadow: 0 0 0 3px var(--brand-500); transform: scale(1.05); }
.picker-grid__item--color { background: var(--swatch); }

/* Toggle switch */
.switch { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-4); width: 100%; }
.switch__track {
  position: relative;
  flex: 0 0 auto;
  width: 52px; height: 30px;
  border-radius: var(--r-pill);
  background: var(--surface-sunk);
  transition: background var(--dur) var(--ease);
}
.switch__track::after {
  content: '';
  position: absolute; top: 3px; left: 3px;
  width: 24px; height: 24px;
  border-radius: 50%;
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  transition: transform var(--dur) var(--ease);
}
.switch[aria-pressed='true'] .switch__track { background: var(--mint-500); }
.switch[aria-pressed='true'] .switch__track::after { transform: translateX(22px); }

/* --- Progress ------------------------------------------------------------ */
.bar {
  height: 10px;
  border-radius: var(--r-pill);
  background: var(--surface-sunk);
  overflow: hidden;
}
.bar__fill {
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--hero-from), var(--hero-via));
  transition: width var(--dur-slow) var(--ease);
}
.bar__fill--warn { background: linear-gradient(90deg, var(--mango-500), var(--coral-400)); }
.bar__fill--full { background: linear-gradient(90deg, var(--coral-500), var(--coral-400)); }

/* --- List rows ----------------------------------------------------------- */
.list { display: flex; flex-direction: column; gap: var(--sp-2); }

.row-card {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  width: 100%;
  padding: var(--sp-3);
  border-radius: var(--r-lg);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  text-align: left;
  transition: transform var(--dur-fast) var(--ease);
}
.row-card:active { transform: scale(.985); }
.row-card__title { font-weight: var(--fw-bold); font-size: var(--fs-base); }
.row-card__meta { display: flex; gap: var(--sp-1); flex-wrap: wrap; margin-top: 3px; }
.row-card--done { opacity: .62; }
.row-card--done .row-card__title { text-decoration: line-through; }

/* --- Modal / sheet ------------------------------------------------------- */
.modal-backdrop {
  position: fixed; inset: 0;
  z-index: var(--z-modal);
  display: flex; align-items: flex-end; justify-content: center;
  background: rgba(28, 22, 48, .48);
  backdrop-filter: blur(3px);
  animation: fade-in var(--dur-fast) var(--ease);
}
.sheet {
  width: 100%;
  max-width: var(--app-max);
  max-height: 92dvh;
  display: flex;
  flex-direction: column;
  border-radius: var(--r-xl) var(--r-xl) 0 0;
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  animation: slide-up var(--dur) var(--ease);
}
.sheet__handle {
  width: 40px; height: 4px;
  margin: var(--sp-3) auto var(--sp-1);
  border-radius: var(--r-pill);
  background: var(--border-strong);
  flex: 0 0 auto;
}
.sheet__header {
  display: flex; align-items: center; gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-5) var(--sp-2);
}
.sheet__title { font-size: var(--fs-lg); font-weight: var(--fw-black); }
.sheet__body { padding: var(--sp-2) var(--sp-5); overflow-y: auto; -webkit-overflow-scrolling: touch; }
.sheet__footer {
  display: flex; gap: var(--sp-2);
  padding: var(--sp-4) var(--sp-5) calc(var(--sp-5) + var(--safe-bottom));
  border-top: 1px solid var(--border);
  background: var(--surface);
}
.sheet__footer > .btn { flex: 1; }

/* --- Toast --------------------------------------------------------------- */
.toast-root {
  position: fixed;
  left: 50%; bottom: calc(var(--tabbar-h) + var(--safe-bottom) + var(--sp-4));
  z-index: var(--z-toast);
  display: flex; flex-direction: column; gap: var(--sp-2);
  width: min(92vw, 420px);
  transform: translateX(-50%);
  pointer-events: none;
}
.toast {
  display: flex; align-items: center; gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  border-radius: var(--r-pill);
  background: var(--text);
  color: var(--bg);
  font-size: var(--fs-sm);
  font-weight: var(--fw-bold);
  box-shadow: var(--shadow-lg);
  animation: pop-in var(--dur) var(--ease);
}
.toast--success { background: var(--mint-500); color: #fff; }
.toast--error   { background: var(--coral-500); color: #fff; }

/* --- Empty state --------------------------------------------------------- */
.empty {
  display: flex; flex-direction: column; align-items: center; gap: var(--sp-2);
  padding: var(--sp-8) var(--sp-4);
  text-align: center;
  color: var(--text-muted);
}
.empty__emoji { font-size: 44px; animation: wiggle 2.6s var(--ease) infinite; }
.empty__title { font-weight: var(--fw-black); color: var(--text); font-size: var(--fs-md); }
