/* Reusable iOS-style components. */

/* Typography */
.large-title, .title1, .title2, .title3 { font-family: var(--font-display); }
.large-title { font-size: var(--fs-large-title); font-weight: 700; letter-spacing: -0.01em; line-height: 1.1; }
.title1 { font-size: var(--fs-title1); font-weight: 700; letter-spacing: -0.01em; }
.title2 { font-size: var(--fs-title2); font-weight: 650; letter-spacing: -0.01em; }
.title3 { font-size: var(--fs-title3); font-weight: 650; }
.headline { font-size: var(--fs-headline); font-weight: 560; }
.body { font-size: var(--fs-body); font-weight: 400; }
.callout { font-size: var(--fs-callout); }
.subhead { font-size: var(--fs-subhead); }
.footnote { font-size: var(--fs-footnote); color: var(--label-2); }
.caption { font-size: var(--fs-caption); color: var(--label-2); }
.muted { color: var(--label-2); }
.muted-3 { color: var(--label-3); }
.tabular { font-variant-numeric: tabular-nums; }
.eyebrow { font-size: 11px; font-weight: 650; letter-spacing: 1.1px; text-transform: uppercase; color: var(--accent); }
.center { text-align: center; }
.right { text-align: right; }
.row { display: flex; align-items: center; gap: var(--sp-3); }
.row.between { justify-content: space-between; }
.row.wrap { flex-wrap: wrap; }
.col { display: flex; flex-direction: column; }
.grow { flex: 1; }
.gap-2 { gap: var(--sp-2); } .gap-3 { gap: var(--sp-3); } .gap-4 { gap: var(--sp-4); }
.mt-2 { margin-top: var(--sp-2);} .mt-3{margin-top:var(--sp-3);} .mt-4{margin-top:var(--sp-4);} .mt-6{margin-top:var(--sp-6);}
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-2);
  padding: 11px 18px; border-radius: var(--r-md); border: none;
  font-size: var(--fs-callout); font-weight: 580; color: var(--label);
  background: var(--fill); transition: transform var(--dur-fast) var(--ease-standard), filter var(--dur-fast), background var(--dur-fast);
  user-select: none; white-space: nowrap;
}
.btn:active { transform: scale(.96); }
.btn[disabled] { opacity: .45; pointer-events: none; }
.btn-primary { background: var(--accent); color: var(--accent-contrast); box-shadow: 0 6px 18px color-mix(in srgb, var(--accent) 40%, transparent); }
.btn-primary:active { background: var(--accent-pressed); }
.btn-tinted { background: var(--accent-tint); color: var(--accent); }
.btn-surface { background: var(--surface); border: 1px solid var(--surface-border); }
.btn-plain { background: transparent; color: var(--accent); padding-left: 8px; padding-right: 8px; }
.btn-danger { background: var(--red); color: #fff; }
.btn-sm { padding: 7px 12px; font-size: var(--fs-subhead); border-radius: var(--r-sm); }
.btn-lg { padding: 15px 22px; font-size: var(--fs-headline); border-radius: var(--r-lg); width: 100%; }
.btn-icon { padding: 9px; width: 38px; height: 38px; border-radius: var(--r-pill); }

/* Inputs */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: var(--sp-4); min-width: 0; }
.field > label { font-size: var(--fs-subhead); font-weight: 560; color: var(--label-2); }
.input, .textarea, select.input {
  width: 100%; padding: 12px 14px; border-radius: var(--r-md);
  background: var(--surface); color: var(--label);
  border: 1px solid var(--hairline); transition: border-color var(--dur-fast), box-shadow var(--dur-fast);
  outline: none; min-width: 0;
}
.input:focus, .textarea:focus, select.input:focus { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-tint); }
.textarea { min-height: 120px; resize: vertical; line-height: 1.5; }
.input::placeholder { color: var(--label-3); }

/* Custom searchable dropdowns */
.custom-select { position: relative; width: 100%; min-width: 0; }
.custom-select-trigger {
  width: 100%; min-height: 46px; display: flex; align-items: center; justify-content: space-between; gap: var(--sp-2);
  padding: 11px 13px 11px 14px; border-radius: var(--r-md); border: 1px solid var(--hairline);
  background: var(--surface); color: var(--label); font: inherit; text-align: left; outline: none;
  transition: border-color var(--dur-fast), box-shadow var(--dur-fast), background var(--dur-fast);
}
.custom-select-trigger:focus { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-tint); }
.custom-select-trigger.is-empty .custom-select-value { color: var(--label-3); }
.custom-select-value { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.custom-select-panel {
  position: absolute; z-index: 1200; left: 0; right: 0; top: calc(100% + 7px);
  display: grid; grid-template-rows: auto minmax(0, 1fr) auto; gap: var(--sp-2);
  max-height: min(320px, 58vh); padding: var(--sp-2); border-radius: var(--r-lg);
  background: var(--surface); border: 1px solid var(--surface-border); box-shadow: var(--shadow-lg);
}
.custom-select-search {
  width: 100%; padding: 10px 12px; border-radius: var(--r-md); border: 1px solid var(--hairline);
  background: color-mix(in srgb, var(--surface) 92%, transparent); outline: none;
}
.custom-select-search:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-tint); }
.custom-select-options { overflow-y: auto; display: grid; gap: 3px; padding-right: 2px; }
.custom-select-option {
  width: 100%; min-height: 38px; display: flex; align-items: stretch; justify-content: space-between; gap: var(--sp-1);
  border-radius: var(--r-md); background: transparent; color: var(--label); overflow: hidden;
}
.custom-select-option:hover, .custom-select-option.active { background: var(--fill); }
.custom-select-option.active { color: var(--accent); }
.custom-select-option-main {
  flex: 1; min-width: 0; min-height: 38px; display: flex; align-items: center;
  padding: 9px 10px; border: 0; border-radius: var(--r-md); background: transparent;
  color: inherit; font: inherit; font-weight: 560; text-align: left; cursor: pointer;
}
.custom-select-option-main span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.custom-select-option-main:focus-visible { outline: none; box-shadow: inset 0 0 0 2px var(--accent); }
.custom-select-remove {
  width: 30px; height: 30px; margin: 4px 4px 4px 0; flex: none; display: grid; place-items: center;
  border: 1px solid var(--hairline); border-radius: var(--r-pill);
  color: var(--label-2); background: color-mix(in srgb, var(--surface) 82%, var(--fill)); cursor: pointer;
}
.custom-select-option.active .custom-select-remove { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 22%, var(--hairline)); }
.custom-select-remove:hover { color: var(--red); background: color-mix(in srgb, var(--red) 12%, transparent); }
.custom-select-add {
  position: sticky; bottom: 0; width: 100%; display: flex; align-items: center; justify-content: center; gap: var(--sp-2);
  min-height: 42px; border: 0; border-radius: var(--r-md); background: linear-gradient(135deg, var(--accent), var(--accent-4));
  color: var(--accent-contrast); font-weight: 680; box-shadow: 0 8px 18px color-mix(in srgb, var(--accent) 24%, transparent);
}
.custom-select-add[disabled] { opacity: .55; box-shadow: none; cursor: default; }
.custom-select-empty { padding: var(--sp-4); text-align: center; color: var(--label-3); font-size: var(--fs-footnote); }

/* Toggle switch */
.toggle { position: relative; width: 50px; height: 30px; border-radius: 999px; background: var(--fill-2); transition: background var(--dur) var(--ease-standard); flex: none; }
.toggle.on { background: var(--green); }
.toggle::after { content: ""; position: absolute; top: 2px; left: 2px; width: 26px; height: 26px; border-radius: 50%; background: #fff; box-shadow: 0 2px 6px rgba(0,0,0,.3); transition: left var(--dur) var(--ease-spring); }
.toggle.on::after { left: 22px; }

/* Segmented control */
.segmented { display: inline-flex; padding: 3px; gap: 2px; border-radius: var(--r-md); background: var(--fill); }
.segmented button { flex: 1; border: none; background: transparent; color: var(--label-2); padding: 7px 14px; border-radius: 11px; font-size: var(--fs-subhead); font-weight: 600; transition: all var(--dur-fast); }
.segmented button.active { background: var(--surface); color: var(--label); box-shadow: var(--shadow); }

/* Grouped inset list */
.list { border-radius: var(--r-lg); overflow: hidden; background: var(--surface); border: 1px solid var(--surface-border); box-shadow: var(--shadow); }
.list-row { display: flex; align-items: center; gap: var(--sp-3); padding: 14px 16px; border-bottom: 1px solid var(--hairline); transition: background var(--dur-fast); }
.list-row:last-child { border-bottom: none; }
.list-row.tap:active { background: var(--fill); }
.list-row .title { font-weight: 560; }
.list-row .value { margin-left: auto; color: var(--label-2); }
.list-section-title { font-size: var(--fs-footnote); font-weight: 650; letter-spacing: .35px; text-transform: uppercase; color: var(--label-2); margin: var(--sp-5) 4px var(--sp-2); }

/* Cards */
.card { position: relative; z-index: 999; padding: var(--sp-5); border-radius: var(--r-lg); }
.stat { display: flex; flex-direction: column; gap: 2px; }
.stat .num { font-size: 28px; font-weight: 720; letter-spacing: 0; }
.stat .lbl { font-size: var(--fs-footnote); color: var(--label-2); font-weight: 560; }

/* Badge / chip */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 4px 10px; border-radius: 999px; font-size: var(--fs-caption); font-weight: 620; background: var(--fill); color: var(--label-2); }
.badge.green { background: color-mix(in srgb, var(--green) 18%, transparent); color: var(--green); }
.badge.red { background: color-mix(in srgb, var(--red) 18%, transparent); color: var(--red); }
.badge.orange { background: color-mix(in srgb, var(--orange) 20%, transparent); color: var(--orange); }
.badge.accent { background: var(--accent-tint); color: var(--accent); }
.dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.option-chip-list { display: flex; flex-wrap: wrap; gap: var(--sp-2); margin: -4px 0 var(--sp-4); }
.option-chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 6px 8px 6px 11px; border-radius: var(--r-pill);
  background: var(--accent-tint); color: var(--accent); font-size: var(--fs-footnote); font-weight: 800;
}
.option-chip button { width: 22px; height: 22px; display: grid; place-items: center; border: 0; border-radius: var(--r-pill); background: color-mix(in srgb, var(--accent) 10%, transparent); color: currentColor; padding: 0; }

/* Progress */
.progress { height: 8px; border-radius: 999px; background: var(--fill); overflow: hidden; }
.progress > i { display: block; height: 100%; border-radius: 999px; background: linear-gradient(90deg, var(--accent), var(--accent-2)); transition: width var(--dur) var(--ease-standard); }

/* Stepper */
.stepper { display: inline-flex; align-items: center; background: var(--fill); border-radius: var(--r-md); padding: 3px; }
.stepper button { width: 34px; height: 34px; border: none; background: transparent; color: var(--accent); font-size: 20px; font-weight: 600; border-radius: 9px; }
.stepper button:active { background: var(--accent-tint); }
.stepper .val { min-width: 38px; text-align: center; font-weight: 700; }

/* Table */
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-size: var(--fs-footnote); font-weight: 700; color: var(--label-2); padding: 10px 14px; border-bottom: 1px solid var(--hairline); position: sticky; top: 0; }
.table td { padding: 13px 14px; border-bottom: 1px solid var(--hairline); font-size: var(--fs-subhead); }
.table tr:last-child td { border-bottom: none; }
.table tr.tap { cursor: pointer; }
.table tr.tap:hover { background: var(--fill); }

/* Toast */
#toasts { position: fixed; left: 0; right: 0; bottom: 24px; display: flex; flex-direction: column; align-items: center; gap: 8px; z-index: 4000; pointer-events: none; }
.toast { pointer-events: none; padding: 12px 18px; border-radius: var(--r-pill); font-weight: 600; font-size: var(--fs-subhead); box-shadow: var(--shadow-lg); animation: toastIn var(--dur) var(--ease-spring); max-width: 90vw; }
.toast.error { background: var(--red); color: #fff; }
.toast.success { background: var(--green); color: #fff; }
.toast.info { background: var(--surface); border: 1px solid var(--surface-border); }
@keyframes toastIn { from { transform: translateY(16px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

/* Sheet / modal */
.sheet-overlay { position: fixed; inset: 0; background: rgba(10,8,24,.42); z-index: 3000; animation: fade var(--dur) var(--ease-standard); }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.sheet { position: fixed; left: 50%; bottom: 0; transform: translateX(-50%); width: min(560px, 100%); max-height: 92vh; z-index: 3001;
  background: var(--surface);
  border: 1px solid var(--surface-border); border-bottom: none; border-radius: var(--r-xl) var(--r-xl) 0 0; box-shadow: var(--shadow-lg);
  padding: var(--sp-3) var(--sp-5) calc(var(--sp-6) + env(safe-area-inset-bottom)); display: flex; flex-direction: column; animation: sheetUp var(--dur) var(--ease-spring); overflow: hidden; }
@keyframes sheetUp { from { transform: translate(-50%, 100%); } to { transform: translate(-50%, 0); } }
.grabber { width: 38px; height: 5px; border-radius: 999px; background: var(--fill-2); margin: 6px auto 14px; flex: none; }
.sheet .sheet-body { overflow-y: auto; }

/* Empty state */
.empty { text-align: center; padding: var(--sp-10) var(--sp-5); color: var(--label-2); }
.empty .icon { font-size: 40px; opacity: .7; margin-bottom: var(--sp-3); color: var(--accent); }

/* Avatar */
.avatar { width: 38px; height: 38px; border-radius: 50%; background: var(--accent); color: #fff; display: grid; place-items: center; font-weight: 700; flex: none; }

/* Spinner */
.spinner { width: 22px; height: 22px; border: 2.5px solid var(--fill-2); border-top-color: var(--accent); border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading-screen { min-height: 60vh; display: grid; place-items: center; }

ion-icon.icon { display: inline-block; font-size: 1.15em; line-height: 1; vertical-align: -0.18em; pointer-events: none; }
.btn ion-icon.icon, .nav-item ion-icon.icon, .tabbar ion-icon.icon { flex: none; }
