/* Fit & Calm — base components: page head, sub-tabs, card, button, field, chip, ring, tick box,
   stat, bar, chart wrapper, dialog / sheet, toast, empty state, confetti, theme picker. */

/* ---------- page head & sub-tabs ---------- */
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: var(--s-2) var(--s-5); margin-bottom: var(--s-5); }
.page-head .eyebrow { display: flex; align-items: center; gap: var(--s-2); margin-bottom: 2px; font-size: var(--fs-xs); font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--primary-strong); }
.page-head p { margin-top: 2px; font-size: var(--fs-sm); color: var(--text-muted); }
.page-head-actions { display: flex; gap: var(--s-3); }

.subtabs {
  display: flex; gap: 4px; margin: 0 calc(var(--gutter) * -1) var(--s-5); padding: 0 var(--gutter);
  overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch;
}
.subtabs::-webkit-scrollbar { display: none; }
.subtab {
  flex: none; display: inline-flex; align-items: center; height: 32px; padding: 0 var(--s-6);
  border: 1px solid var(--line); border-radius: var(--r-pill); background: var(--surface);
  color: var(--text-muted); font-size: var(--fs-sm); font-weight: 500; text-decoration: none; white-space: nowrap;
}
.subtab[aria-current="page"] { background: var(--surface-2); border-color: var(--line-strong); color: var(--primary-strong); font-weight: 600; }
@media (min-width: 860px) { .subtabs { margin-left: 0; margin-right: 0; padding: 0; } }

/* ---------- layout helpers ---------- */
.stack { display: grid; gap: var(--gap); }
.grid-2, .grid-3, .grid-4 { display: grid; gap: var(--gap); grid-template-columns: minmax(0, 1fr); }
@media (min-width: 600px) { .grid-2, .grid-3, .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (min-width: 1000px) { .grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); } .grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.row { display: flex; align-items: center; gap: var(--s-3); min-width: 0; }
.row-wrap { flex-wrap: wrap; }
.spacer { flex: 1; }
.hint { font-size: var(--fs-sm); color: var(--text-muted); }
.muted { color: var(--text-muted); }
.small { font-size: var(--fs-sm); }

/* ---------- card ---------- */
.card {
  min-width: 0; padding: var(--card-pad);
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-card);
  box-shadow: var(--shadow);
}
.card-soft { background: var(--surface-2); border-color: transparent; box-shadow: none; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: var(--s-3); margin-bottom: var(--s-3); }
.card-title { font-family: var(--font-body); font-size: var(--fs-md); font-weight: 600; letter-spacing: 0; }
.card-link { font-size: var(--fs-sm); font-weight: 500; color: var(--link); text-decoration: none; white-space: nowrap; }
a.card { display: block; color: inherit; text-decoration: none; transition: border-color var(--t-fast); }
@media (hover: hover) { a.card:hover { border-color: var(--line-strong); } }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s-2);
  min-height: var(--ctl-h); padding: 0 var(--s-6);
  border: 1px solid var(--line-strong); border-radius: var(--r-pill);
  background: var(--surface); color: var(--text);
  font-size: 13px; font-weight: 600; white-space: nowrap; text-decoration: none;
  transition: background var(--t-fast), transform var(--t-fast);
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--button-bg); border-color: var(--button-bg); color: var(--on-button); }
.btn-soft { background: var(--surface-2); border-color: transparent; color: var(--link); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-muted); }
.btn-danger { background: transparent; border-color: var(--danger-soft); color: var(--danger); }
.btn-sm { min-height: 30px; padding: 0 var(--s-5); font-size: var(--fs-sm); }
.btn-lg { min-height: 48px; padding: 0 var(--s-8); font-size: var(--fs-lg); }
.btn-block { width: 100%; }
@media (hover: hover) {
  .btn-primary:hover { background: var(--button-bg-hover); border-color: var(--button-bg-hover); }
  .btn-soft:hover, .btn:not(.btn-primary):not(.btn-ghost):hover { background: var(--surface-3); }
}
.icon-btn {
  display: inline-grid; place-items: center; width: 34px; height: 34px; padding: 0;
  border: 0; border-radius: var(--r-pill); background: transparent; color: var(--text-muted);
}
.icon-btn:hover { background: var(--surface-3); color: var(--text); }

/* ---------- forms ---------- */
.field { display: block; min-width: 0; }
.field-label { display: block; margin-bottom: 4px; font-size: var(--fs-sm); font-weight: 500; color: var(--text-muted); }
.input {
  display: block; width: 100%; min-width: 0; height: var(--ctl-h); padding: 0 var(--s-4);
  border: 1px solid var(--line-strong); border-radius: var(--r-sm);
  background: var(--surface); font-size: var(--fs-input);
  -webkit-appearance: none; appearance: none;
}
textarea.input { height: auto; min-height: 80px; padding: var(--s-3) var(--s-4); resize: vertical; }
select.input { -webkit-appearance: auto; appearance: auto; }
.input:focus { outline: none; border-color: var(--primary-strong); box-shadow: 0 0 0 2px var(--primary-soft); }
.input::-webkit-date-and-time-value { text-align: left; min-height: 1.4em; }
@media (min-width: 860px) { .input { font-size: var(--fs-md); } }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s-5) var(--s-4); }
.span-2 { grid-column: 1 / -1; }

.segmented { display: flex; padding: 3px; gap: 3px; border-radius: var(--r-pill); background: var(--surface-2); }
.segmented button { flex: 1; min-height: 30px; padding: 0 var(--s-4); border: 0; border-radius: var(--r-pill); background: transparent; color: var(--text-muted); font-size: var(--fs-sm); font-weight: 500; white-space: nowrap; }
.segmented button[aria-pressed="true"] { background: var(--surface); color: var(--primary-strong); font-weight: 600; box-shadow: var(--shadow); }

/* ---------- chips & pills ---------- */
.chip {
  display: inline-flex; align-items: center; gap: 4px; height: 24px; padding: 0 var(--s-4);
  border-radius: var(--r-pill); background: var(--surface-2); color: var(--text-muted);
  font-size: var(--fs-xs); font-weight: 500; white-space: nowrap;
}
.chip-strong { color: var(--link); }
.chip-gold { background: #FFF3DD; color: var(--gold-ink); }
button.chip { border: 1px solid transparent; }
button.chip[aria-pressed="true"] { background: var(--button-bg); color: var(--on-button); }

/* ---------- progress ring ---------- */
.ring { position: relative; display: inline-grid; place-items: center; flex: none; }
.ring svg { transform: rotate(-90deg); }
.ring .ring-track { fill: none; stroke: var(--primary-soft); }
.ring .ring-fill { fill: none; stroke: var(--primary); stroke-linecap: round; transition: stroke-dashoffset var(--t-med) var(--ease); }
.ring.ring-accent .ring-fill { stroke: var(--accent-2); }
.ring.ring-gold .ring-fill { stroke: var(--gold); }
.ring-label { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; line-height: 1.05; }
.ring-label strong { font-size: var(--fs-md); font-weight: 700; }
.ring-label small { font-size: var(--fs-2xs); color: var(--text-muted); }
.ring-caption { margin-top: 4px; font-size: var(--fs-xs); color: var(--text-muted); text-align: center; }

/* ---------- tick box ---------- */
.tick { display: flex; align-items: center; gap: var(--s-4); min-height: var(--row-h); cursor: pointer; font-size: var(--fs-md); }
.tick input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.tick-box {
  flex: none; display: grid; place-items: center; width: 22px; height: 22px;
  border: 1.5px solid var(--line-strong); border-radius: 7px; background: var(--surface);
  transition: background var(--t-fast), border-color var(--t-fast), transform var(--t-fast) var(--ease-bounce);
}
.tick-box svg { width: 14px; height: 14px; fill: none; stroke: var(--on-button); stroke-width: 2.6; stroke-linecap: round; stroke-linejoin: round; opacity: 0; transform: scale(.6); transition: opacity var(--t-fast), transform var(--t-fast) var(--ease-bounce); }
.tick input:checked + .tick-box { background: var(--button-bg); border-color: var(--button-bg); transform: scale(1.06); }
.tick input:checked + .tick-box svg { opacity: 1; transform: scale(1); }
.tick input:focus-visible + .tick-box { outline: 2px solid var(--focus); outline-offset: 2px; }
.tick input:checked ~ .tick-text { color: var(--text-muted); }

/* ---------- stats & bars ---------- */
.stat { min-width: 0; }
.stat-value { font-family: var(--font-display); font-size: var(--fs-stat); font-weight: 600; line-height: 1.1; }
.stat-label { font-size: var(--fs-xs); color: var(--text-muted); }
.bar { height: 6px; border-radius: var(--r-pill); background: var(--primary-soft); overflow: hidden; }
.bar > span { display: block; height: 100%; border-radius: inherit; background: var(--primary); transition: width var(--t-med) var(--ease); }

/* ---------- chart wrapper ---------- */
.chart { position: relative; width: 100%; }
.chart svg { width: 100%; height: auto; overflow: visible; }
.chart .grid-line { stroke: var(--line); stroke-width: 1; }
.chart .axis-text { fill: var(--text-muted); font-size: 10px; font-family: var(--font-body); }
.chart .series-line { fill: none; stroke: var(--primary-strong); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.chart .series-line.s2 { stroke: var(--accent-2); stroke-dasharray: 4 4; }
.chart .series-area { fill: var(--primary-soft); opacity: .55; }
.chart .series-dot { fill: var(--surface); stroke: var(--primary-strong); stroke-width: 1.6; }
.chart .series-bar { fill: var(--primary); }
.chart .series-bar.is-current { fill: var(--primary-strong); }
.chart .goal-line { stroke: var(--gold); stroke-width: 1.5; stroke-dasharray: 5 4; }
.chart-empty { display: grid; place-items: center; min-height: 120px; font-size: var(--fs-sm); color: var(--text-muted); background: var(--surface-3); border-radius: var(--r-md); }

/* ---------- dialog / sheet ---------- */
dialog.fc-dialog {
  width: min(440px, calc(100vw - 24px)); max-height: calc(100dvh - 32px); padding: 0;
  border: 1px solid var(--line); border-radius: var(--r-lg);
  background: var(--surface); color: var(--text); box-shadow: var(--shadow-lift);
}
dialog.fc-dialog::backdrop { background: var(--overlay); }
dialog.fc-dialog[open] { animation: dlg-in var(--t-med) var(--ease); }
.dialog-body { padding: var(--s-7) var(--s-6) var(--s-6); overflow-y: auto; max-height: inherit; }
.dialog-body > h2 { margin-bottom: var(--s-4); padding-right: 28px; font-size: var(--fs-xl); }
.dialog-body > p { color: var(--text-muted); font-size: var(--fs-md); }
.dialog-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: var(--s-3); margin-top: var(--s-7); }
.dialog-close { position: absolute; top: 8px; right: 8px; }
.sheet-grip { display: none; }
@media (max-width: 599px) {
  dialog.fc-sheet { width: 100%; max-width: none; margin: auto 0 0; border-radius: var(--r-lg) var(--r-lg) 0 0; border-bottom: 0; }
  dialog.fc-sheet[open] { animation: sheet-in var(--t-med) var(--ease); }
  dialog.fc-sheet .dialog-body { padding-bottom: calc(var(--s-6) + var(--safe-b)); }
  .fc-sheet .sheet-grip { display: block; width: 36px; height: 4px; margin: 8px auto 0; border-radius: 2px; background: var(--line-strong); }
}
@keyframes dlg-in { from { opacity: 0; transform: translateY(8px) scale(.98); } }
@keyframes sheet-in { from { transform: translateY(100%); } }

/* ---------- toast ---------- */
.toast-wrap {
  position: fixed; left: 50%; transform: translateX(-50%); z-index: 60;
  bottom: calc(var(--tabbar-h) + var(--safe-b) + 10px);
  display: grid; gap: 6px; width: max-content; max-width: calc(100vw - 24px);
}
@media (min-width: 860px) { .toast-wrap { bottom: 24px; } }
.toast {
  display: flex; align-items: center; gap: var(--s-5); padding: 9px var(--s-6);
  border-radius: var(--r-pill); background: var(--text); color: var(--surface);
  font-size: var(--fs-sm); box-shadow: var(--shadow-lift);
  animation: toast-in var(--t-med) var(--ease);
}
.toast button { padding: 0; border: 0; background: none; color: var(--primary-soft); font-weight: 600; text-decoration: underline; }
.toast.leaving { opacity: 0; transition: opacity 180ms; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

/* ---------- empty state ---------- */
.empty { display: grid; justify-items: center; gap: var(--s-4); padding: var(--s-8) var(--s-6); text-align: center; }
.empty-art { width: 84px; height: 84px; }
.empty p { max-width: 34ch; font-size: var(--fs-sm); color: var(--text-muted); }

/* ---------- confetti ---------- */
.confetti { position: fixed; inset: 0; z-index: 80; pointer-events: none; overflow: hidden; }
.confetti i {
  position: absolute; top: -12px; width: 7px; height: 11px; border-radius: 2px;
  animation: confetti-fall var(--dur) var(--delay) cubic-bezier(.25, .6, .4, 1) forwards;
}
.confetti i.round { width: 8px; height: 8px; border-radius: 50%; }
@keyframes confetti-fall { to { transform: translate(var(--dx), 105vh) rotate(var(--rot)); opacity: .9; } }

/* ---------- theme picker ---------- */
.theme-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--s-3); }
.theme-tile {
  display: grid; gap: 4px; justify-items: start; align-content: start; padding: var(--s-4);
  border: 1px solid var(--line-strong); border-radius: var(--r-md); background: var(--surface);
  text-align: left; font-size: var(--fs-sm);
}
.theme-tile[aria-checked="true"] { border-color: var(--primary-strong); box-shadow: 0 0 0 1px var(--primary-strong); }
.theme-tile strong { font-weight: 600; }
.theme-swatches { display: flex; }
.theme-swatches i { width: 16px; height: 16px; border-radius: 50%; border: 1.5px solid var(--surface); box-shadow: 0 0 0 1px rgba(0, 0, 0, .08); }
.theme-swatches i + i { margin-left: -5px; }

/* ---------- form pieces: hint, stepper, switch, settings rows ---------- */
.field-hint { margin-top: 4px; font-size: var(--fs-xs); color: var(--text-muted); }
.stepper { display: inline-flex; align-items: center; gap: 2px; padding: 2px; border: 1px solid var(--line-strong); border-radius: var(--r-pill); background: var(--surface); }
.stepper-btn { width: 32px; height: 32px; font-size: 18px; line-height: 1; color: var(--link); }
.stepper-btn:disabled { opacity: .35; cursor: default; }
.stepper-value { min-width: 54px; text-align: center; font-weight: 600; font-variant-numeric: tabular-nums; }
.switch {
  position: relative; flex: none; width: 40px; height: 24px; margin: 0;
  border-radius: var(--r-pill); background: var(--line-strong); cursor: pointer;
  -webkit-appearance: none; appearance: none; transition: background var(--t-fast);
}
.switch::after { content: ''; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #FFFFFF; box-shadow: 0 1px 3px rgba(0, 0, 0, .2); transition: transform var(--t-fast) var(--ease); }
.switch:checked { background: var(--button-bg); }
.switch:checked::after { transform: translateX(16px); }
.set-row { display: flex; align-items: center; justify-content: space-between; gap: var(--s-5); min-height: 48px; padding: 6px 0; border-top: 1px solid var(--line); }
.set-row:first-of-type { border-top: 0; }
label.set-row { cursor: pointer; }
.set-text { min-width: 0; }
.set-text strong { display: block; font-size: var(--fs-md); font-weight: 500; }
.set-text small { display: block; font-size: var(--fs-xs); color: var(--text-muted); }
.set-row .input { width: auto; max-width: 160px; }
.set-row .segmented { flex: none; min-width: 120px; }

/* ---------- list rows ---------- */
.rows > li { display: flex; align-items: center; gap: var(--s-4); min-height: var(--row-h); padding: 4px 0; border-top: 1px solid var(--line); font-size: var(--fs-md); list-style: none; }
.rows > li:first-child { border-top: 0; }
.row-main { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-meta { flex: none; font-size: var(--fs-sm); color: var(--text-muted); white-space: nowrap; }
