/* ── Buttons ────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 50px;
  padding: 0 22px;
  border-radius: 999px;
  border: 1px solid var(--line-strong);
  background: var(--ink-3);
  font-weight: 600;
  font-size: 16px;
  white-space: nowrap;
  text-decoration: none;
  user-select: none;
  -webkit-user-select: none;
  transition: transform 0.18s var(--ease-out), background-color 0.2s, opacity 0.2s, box-shadow 0.2s;

  &:active { transform: scale(0.965); }
  &[disabled], &[aria-busy="true"] { opacity: 0.5; pointer-events: none; }
  & .icon { width: 20px; height: 20px; }
}
.btn--primary {
  border-color: transparent;
  color: oklch(21% 0.05 274);
  background: linear-gradient(180deg, oklch(92% 0.05 272), oklch(80% 0.1 274));
  box-shadow: 0 10px 26px -12px oklch(72% 0.14 276 / 0.8), inset 0 1px 0 oklch(100% 0 0 / 0.55);
}
.btn--ember {
  border-color: transparent;
  color: oklch(23% 0.06 45);
  background: linear-gradient(180deg, oklch(86% 0.13 72), var(--ember-deep));
  box-shadow: 0 10px 26px -12px oklch(70% 0.17 48 / 0.85), inset 0 1px 0 oklch(100% 0 0 / 0.45);
}
.btn--ghost { background: transparent; }
.btn--danger {
  color: var(--danger);
  background: color-mix(in oklch, var(--danger) 13%, transparent);
  border-color: color-mix(in oklch, var(--danger) 30%, transparent);
}
.btn--block { width: 100%; }
.btn--sm { min-height: 38px; padding: 0 14px; font-size: 14px; & .icon { width: 17px; height: 17px; } }

.icon-btn {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  flex: none;
  border-radius: 50%;
  color: var(--text-2);
  background: var(--ink-2);
  border: 1px solid var(--line);
  transition: transform 0.18s var(--ease-out), color 0.2s;
  &:active { transform: scale(0.92); }
  & .icon { width: 20px; height: 20px; }
}

/* ── Segmented control ──────────────────────────────────────────────────── */
.segmented {
  position: relative;
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  padding: 4px;
  border-radius: 999px;
  background: var(--ink-1);
  border: 1px solid var(--line);
  isolation: isolate;

  & button {
    min-height: 38px;
    padding: 0 12px;
    border-radius: 999px;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-3);
    transition: color 0.25s;
    &[aria-pressed="true"] { color: var(--text); }
  }
}
.segmented__thumb {
  position: absolute;
  z-index: -1;
  inset-block: 4px;
  left: 4px;
  width: calc((100% - 8px) / var(--count));
  border-radius: 999px;
  background: var(--ink-3);
  box-shadow: 0 4px 12px -4px oklch(0% 0 0 / 0.6), inset 0 1px 0 oklch(100% 0 0 / 0.08);
  transform: translateX(calc(var(--index) * 100%));
  transition: transform 0.45s var(--ease-spring);
}

/* ── Avatars, badges, status pills ──────────────────────────────────────── */
.avatar {
  --c: var(--moon);
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  flex: none;
  border-radius: 50%;
  background: var(--c);
  color: var(--on-color);
  font: 700 14px/1 var(--font-display);
  letter-spacing: -0.02em;
}
.avatar--xs { width: 22px; height: 22px; font-size: 10px; }
.avatar--sm { width: 30px; height: 30px; font-size: 12px; }
.avatar--lg { width: 72px; height: 72px; font-size: 28px; }
.avatar--ring { background: transparent; color: var(--c); box-shadow: inset 0 0 0 2px var(--c); }
.avatars { display: flex; & .avatar { box-shadow: 0 0 0 2px var(--ink-2); } & .avatar--ring { box-shadow: inset 0 0 0 2px var(--c), 0 0 0 2px var(--ink-2); background: var(--ink-2); } & > * + * { margin-left: -6px; } }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--text-2);
  background: var(--ink-3);
  white-space: nowrap;
  & .icon { width: 12px; height: 12px; }
}
.badge--ember { color: var(--ember); background: color-mix(in oklch, var(--ember) 15%, transparent); }
.badge--moon { color: var(--moon); background: color-mix(in oklch, var(--moon) 13%, transparent); }
.badge--free { color: var(--free); background: color-mix(in oklch, var(--free) 14%, transparent); }

.status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  color: var(--text-3);
  background: var(--ink-3);
  &::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
}
.status--free { color: var(--free); background: color-mix(in oklch, var(--free) 13%, transparent); }
.status--maybe { color: var(--maybe); background: color-mix(in oklch, var(--maybe) 12%, transparent); }
.status--busy { color: var(--busy); background: color-mix(in oklch, var(--busy) 13%, transparent); }

/* ── Cards, lists, forms ────────────────────────────────────────────────── */
.card {
  position: relative;
  padding: 16px;
  border-radius: var(--radius-l);
  border: 1px solid var(--line);
  background: linear-gradient(180deg, oklch(100% 0 0 / 0.03), transparent 50%), oklch(19% 0.028 268 / 0.82);
  box-shadow: var(--shadow);
}

.section-title { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin: 26px 2px 12px; }
.section-title h2 { font-size: 20px; }
.section-title p { font-size: 13px; color: var(--text-3); }

.field { display: grid; gap: 6px; }
.field__label { font-size: 13px; font-weight: 600; color: var(--text-2); }
.field__hint { font-size: 12px; color: var(--text-3); }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.input {
  width: 100%;
  min-height: 52px;
  padding: 0 16px;
  border-radius: var(--radius);
  border: 1px solid var(--line-strong);
  background: var(--ink-1);
  font-size: 17px; /* ≥16px stops iOS Safari from zooming on focus */
  transition: border-color 0.2s, box-shadow 0.2s;
  &::placeholder { color: var(--text-3); }
  &:focus { outline: none; border-color: var(--moon-strong); box-shadow: 0 0 0 4px color-mix(in oklch, var(--moon) 16%, transparent); }
}
input[type="date"].input { appearance: none; -webkit-appearance: none; display: flex; align-items: center; }
input[type="date"].input::-webkit-date-and-time-value { text-align: left; }
input[type="date"].input::-webkit-calendar-picker-indicator { filter: invert(0.8); }

/* ── PIN input: one real numeric input over four decorative cells ───────── */
.pin { position: relative; display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; width: min(100%, 17.5rem); }
.pin__cell {
  display: grid;
  place-items: center;
  aspect-ratio: 1 / 1.12;
  border-radius: 18px;
  border: 1px solid var(--line-strong);
  background: var(--ink-1);
  transition: border-color 0.2s, box-shadow 0.2s, transform 0.35s var(--ease-spring);
  &::after { content: ""; width: 14px; height: 14px; border-radius: 50%; background: var(--text); scale: 0; transition: scale 0.35s var(--ease-spring); }
  &[data-filled]::after { scale: 1; }
  &[data-filled] { transform: translateY(-2px); }
}
.pin:focus-within .pin__cell[data-active] { border-color: var(--moon-strong); box-shadow: 0 0 0 4px color-mix(in oklch, var(--moon) 16%, transparent); }
.pin__input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0.01;
  border: 0;
  background: transparent;
  color: transparent;
  caret-color: transparent;
  font-size: 16px;
}
.pin[data-error] { animation: shake 0.42s var(--ease-out); & .pin__cell { border-color: var(--danger); } }
.pin[data-success] .pin__cell { border-color: var(--free); }

/* ── Bottom sheet (dialog on desktop) ───────────────────────────────────── */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: oklch(8% 0.02 268 / 0.62);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
  transition: opacity 0.3s;
  @starting-style { opacity: 0; }
  &[data-closing] { opacity: 0; }
}
.sheet {
  position: fixed;
  z-index: 51;
  inset-inline: 0;
  bottom: 0;
  max-width: 34rem;
  max-height: min(88dvh, 760px);
  margin-inline: auto;
  display: flex;
  flex-direction: column;
  padding: 6px 20px calc(var(--safe-bottom) + 20px);
  border-radius: 30px 30px 0 0;
  border: 1px solid var(--line-strong);
  border-bottom: 0;
  background: linear-gradient(180deg, oklch(100% 0 0 / 0.035), transparent 120px), var(--ink-1);
  box-shadow: 0 -24px 60px -24px oklch(0% 0 0 / 0.9);
  transform: translateY(var(--drag, 0px));
  transition: transform 0.5s var(--ease-spring);
  @starting-style { transform: translateY(100%); }
  &[data-closing] { transform: translateY(105%); transition: transform 0.26s var(--ease-out); }
  &[data-dragging] { transition: none; }
}
.sheet__grab { flex: none; padding: 8px 0 14px; touch-action: none; cursor: grab; &::before { content: ""; display: block; width: 42px; height: 5px; margin: 0 auto; border-radius: 3px; background: var(--line-strong); } }
.sheet__header { display: flex; align-items: flex-start; gap: 12px; margin-bottom: 18px; }
.sheet__heading { flex: 1; min-width: 0; }
.sheet__title { font-size: 24px; }
.sheet__subtitle { margin-top: 5px; font-size: 14px; color: var(--text-2); }
.sheet__body { display: grid; gap: 16px; overflow-y: auto; overscroll-behavior: contain; margin-inline: -20px; padding: 2px 20px 4px; }

@media (min-width: 48rem) {
  .sheet {
    bottom: auto;
    top: 50%;
    width: min(92vw, 30rem);
    padding-bottom: 24px;
    border-radius: 28px;
    border-bottom: 1px solid var(--line-strong);
    translate: 0 -50%;
    opacity: 1;
    transform: none;
    transition: transform 0.4s var(--ease-spring), opacity 0.25s;
    @starting-style { transform: scale(0.94); opacity: 0; }
    &[data-closing] { transform: scale(0.96); opacity: 0; }
  }
  .sheet__grab { display: none; }
}

/* ── Toasts ─────────────────────────────────────────────────────────────── */
.toasts {
  position: fixed;
  z-index: 60;
  inset-inline: 0;
  bottom: calc(var(--safe-bottom) + var(--tabbar-h) + 26px);
  display: grid;
  justify-items: center;
  gap: 8px;
  padding-inline: 16px;
  pointer-events: none;
}
.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: 26rem;
  padding: 12px 16px;
  border-radius: 16px;
  border: 1px solid var(--line-strong);
  background: oklch(25% 0.03 268 / 0.92);
  -webkit-backdrop-filter: blur(16px);
  backdrop-filter: blur(16px);
  box-shadow: var(--shadow);
  font-size: 14px;
  font-weight: 500;
  pointer-events: auto;
  transition: opacity 0.3s, transform 0.45s var(--ease-spring);
  @starting-style { opacity: 0; transform: translateY(14px) scale(0.95); }
  &[data-leaving] { opacity: 0; transform: translateY(8px) scale(0.97); }
  & .icon { width: 18px; height: 18px; }
}
.toast--error .icon { color: var(--danger); }
.toast--ok .icon { color: var(--free); }

/* ── Tab bar ────────────────────────────────────────────────────────────── */
.tabbar {
  position: fixed;
  z-index: 30;
  left: 50%;
  bottom: calc(var(--safe-bottom) + 10px);
  translate: -50% 0;
  width: min(calc(100% - 24px), 25rem);
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  padding: 6px;
  border-radius: 28px;
  border: 1px solid var(--line-strong);
  background: oklch(20% 0.03 268 / 0.7);
  -webkit-backdrop-filter: blur(22px) saturate(170%);
  backdrop-filter: blur(22px) saturate(170%);
  box-shadow: 0 22px 44px -18px oklch(0% 0 0 / 0.85), inset 0 1px 0 oklch(100% 0 0 / 0.06);
  view-transition-name: tabbar;
}
.tab {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 8px 0 6px;
  border-radius: 22px;
  color: var(--text-3);
  font-size: 11px;
  font-weight: 600;
  isolation: isolate;
  transition: color 0.25s;
  & .icon { width: 24px; height: 24px; transition: transform 0.45s var(--ease-spring); }
  &[aria-current="page"] { color: var(--text); & .icon { transform: translateY(-1px) scale(1.07); } }
}
.tab__pill { position: absolute; inset: 0; z-index: -1; border-radius: inherit; background: oklch(100% 0 0 / 0.085); view-transition-name: tab-pill; }

/* ── Misc ───────────────────────────────────────────────────────────────── */
.empty { display: grid; justify-items: center; gap: 8px; padding: 44px 20px; text-align: center; color: var(--text-2); }
.empty .icon { width: 46px; height: 46px; margin-bottom: 6px; color: var(--moon); stroke-width: 1.4; }
.empty h3 { font-size: 20px; color: var(--text); }
.empty p { max-width: 20rem; font-size: 14px; }

.divider { height: 1px; margin: 4px 0; background: var(--line); border: 0; }
.muted { color: var(--text-2); }
.faint { color: var(--text-3); }
