/* =========================================================
   Tabak AI — iOS Design System
   Typography: SF Pro scale · Motion: iOS spring curves
   ========================================================= */

:root,
html[data-theme="light"] {
  --bg: #f4f4f6;
  --surface: #ffffff;
  --surface-2: #ececef;
  --fill: rgba(118, 118, 128, 0.11);
  --seg-thumb: #ffffff;
  --border: rgba(24, 24, 27, 0.09);
  --separator: rgba(24, 24, 27, 0.14);
  --text: #09090b;
  --text-2: rgba(24, 24, 27, 0.82);
  --muted: rgba(24, 24, 27, 0.56);
  --accent: #111113;
  --accent-soft: rgba(17, 17, 19, 0.09);
  --on-accent: #ffffff;
  --green: var(--accent);
  --green-soft: var(--accent-soft);
  --on-green: var(--on-accent);
  --good: #16a34a;
  --blue: #2563eb;
  --amber: #d97706;
  --rose: #db2777;
  --ring-track: #e4e4e7;
  --glass: rgba(244, 244, 246, 0.8);
  --glass-strong: rgba(250, 250, 252, 0.9);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 8px 24px rgba(0, 0, 0, 0.04);
  --shadow-lift: 0 12px 32px rgba(0, 0, 0, 0.12);
  color-scheme: light;

  --ease-ios: cubic-bezier(0.32, 0.72, 0, 1);
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --ease-spring: cubic-bezier(0.34, 1.36, 0.64, 1);
  --radius-card: 20px;
  --radius-ctrl: 12px;
  --space: 16px;
}

@media (prefers-color-scheme: dark) {
  html[data-theme="system"],
  html:not([data-theme]) {
    --bg: #000000;
    --surface: #171719;
    --surface-2: #242428;
    --fill: rgba(161, 161, 170, 0.18);
    --seg-thumb: #3f3f46;
    --border: rgba(255, 255, 255, 0.09);
    --separator: rgba(113, 113, 122, 0.45);
    --text: #ffffff;
    --text-2: rgba(244, 244, 245, 0.84);
    --muted: rgba(161, 161, 170, 0.76);
    --accent: #ffffff;
    --accent-soft: rgba(255, 255, 255, 0.13);
    --on-accent: #09090b;
    --green: var(--accent);
    --green-soft: var(--accent-soft);
    --on-green: var(--on-accent);
    --good: #22c55e;
    --blue: #3b82f6;
    --amber: #f59e0b;
    --rose: #ec4899;
    --ring-track: #27272a;
    --glass: rgba(0, 0, 0, 0.74);
    --glass-strong: rgba(18, 18, 20, 0.88);
    --shadow: none;
    --shadow-lift: 0 16px 40px rgba(0, 0, 0, 0.6);
    color-scheme: dark;
  }
}

html[data-theme="dark"] {
  --bg: #000000;
  --surface: #171719;
  --surface-2: #242428;
  --fill: rgba(161, 161, 170, 0.18);
  --seg-thumb: #3f3f46;
  --border: rgba(255, 255, 255, 0.09);
  --separator: rgba(113, 113, 122, 0.45);
  --text: #ffffff;
  --text-2: rgba(244, 244, 245, 0.84);
  --muted: rgba(161, 161, 170, 0.76);
  --accent: #ffffff;
  --accent-soft: rgba(255, 255, 255, 0.13);
  --on-accent: #09090b;
  --green: var(--accent);
  --green-soft: var(--accent-soft);
  --on-green: var(--on-accent);
  --good: #22c55e;
  --blue: #3b82f6;
  --amber: #f59e0b;
  --rose: #ec4899;
  --ring-track: #27272a;
  --glass: rgba(0, 0, 0, 0.74);
  --glass-strong: rgba(18, 18, 20, 0.88);
  --shadow: none;
  --shadow-lift: 0 16px 40px rgba(0, 0, 0, 0.6);
  color-scheme: dark;
}

/* ---------- Base ---------- */
* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", "Segoe UI", Roboto, sans-serif;
  font-size: 17px;
  line-height: 1.35;
  letter-spacing: -0.01em;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  min-height: 100%;
}

.tabular {
  font-variant-numeric: tabular-nums;
}

.hidden {
  display: none !important;
}

button,
a,
.tab-bar,
.segmented,
.chip {
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
}

/* ---------- App Shell ---------- */
.app-shell {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  position: relative;
}

/* Sticky navigation bar (constant height prevents iOS scroll-jitter loop) */
.top-bar {
  position: sticky;
  top: 0;
  z-index: 20;
  padding: calc(10px + env(safe-area-inset-top)) 20px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--bg);
  border-bottom: 0.5px solid transparent;
  transition: border-color 0.22s ease;
}

.top-bar > div:first-child {
  min-width: 0;
  flex: 1;
}

.top-bar.compact {
  background: var(--glass);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom-color: var(--separator);
}

.top-sub {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  line-height: 1.3;
  transition: opacity 0.22s ease;
}

.top-title {
  font-size: clamp(21px, 5.8vw, 26px);
  font-weight: 700;
  letter-spacing: -0.025em;
  line-height: 1.18;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transform-origin: left center;
  transition: transform 0.28s var(--ease-out);
}

.top-bar.compact .top-sub {
  opacity: 0.72;
}

.top-bar.compact .top-title {
  transform: scale(0.92);
}

.main-content {
  flex: 1;
  padding: 8px var(--space) calc(110px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* ---------- Typography helpers ---------- */
.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 10px 4px 0;
}

.section-title {
  margin: 0;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.link-btn {
  color: var(--green);
  font-size: 15px;
  font-weight: 600;
  min-height: 44px;
  padding: 0 4px;
}

.muted {
  color: var(--muted);
  font-size: 13px;
}

/* ---------- Cards ---------- */
.card {
  background: var(--surface);
  border: 0.5px solid var(--border);
  border-radius: var(--radius-card);
  padding: 16px;
  box-shadow: var(--shadow);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
  min-height: 32px;
}

.card-title {
  font-size: 16px;
  font-weight: 650;
  letter-spacing: -0.015em;
}

/* ---------- Pills ---------- */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 11px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  background: var(--fill);
  color: var(--text);
  white-space: nowrap;
}

.pill-green { background: var(--green-soft); color: var(--green); }
.pill-amber { background: rgba(255, 159, 10, 0.16); color: var(--amber); }
.pill-blue { background: rgba(10, 132, 255, 0.16); color: var(--blue); }
.pill-rose { background: rgba(255, 55, 95, 0.16); color: var(--rose); }

/* ---------- Buttons ---------- */
button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
  padding: 0;
  transition: transform 0.35s var(--ease-spring), opacity 0.2s ease, background-color 0.2s ease;
}

button:active:not(:disabled) {
  transform: scale(0.96);
  transition-duration: 0.12s;
}

button:disabled {
  opacity: 0.4;
  cursor: default;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 50px;
  padding: 12px 18px;
  border-radius: 14px;
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.01em;
  text-decoration: none;
}

.btn-primary {
  background: var(--green);
  color: var(--on-green);
}

.btn-secondary {
  background: var(--fill);
  color: var(--text);
}

.btn-danger {
  background: rgba(255, 55, 95, 0.14);
  color: var(--rose);
}

.btn-sm {
  min-height: 34px;
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 14px;
}

.btn-full {
  width: 100%;
}

/* ---------- Inputs (>=16px prevents iOS zoom) ---------- */
input,
select,
textarea {
  font-family: inherit;
  font-size: 17px;
  color: var(--text);
  background: var(--fill);
  border: 1.5px solid transparent;
  border-radius: var(--radius-ctrl);
  padding: 12px 14px;
  width: 100%;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
  transition: border-color 0.2s ease, box-shadow 0.25s ease, background-color 0.2s ease;
}

select {
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8' fill='none'%3E%3Cpath d='M1.5 1.75L6 6.25L10.5 1.75' stroke='%238e8e93' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-position: right 14px center;
  background-size: 12px 8px;
  background-repeat: no-repeat;
  padding-right: 36px;
}

input::placeholder,
textarea::placeholder {
  color: var(--muted);
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 4px var(--green-soft);
}

label.field {
  display: flex;
  flex-direction: column;
  gap: 7px;
  font-size: 13px;
  color: var(--muted);
  font-weight: 500;
}

/* ---------- Segmented control with sliding thumb ---------- */
.segmented {
  position: relative;
  isolation: isolate;
  display: flex;
  background: var(--fill);
  padding: 2px;
  border-radius: 10px;
  gap: 0;
  overflow: hidden;
}

.segmented button {
  position: relative;
  z-index: 1;
  flex: 1;
  min-height: 34px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-2);
  padding: 6px 8px;
  white-space: nowrap;
  transition: color 0.25s ease, transform 0.35s var(--ease-spring);
}

.segmented button.active {
  color: var(--text);
}

.segmented:not(.has-thumb) button.active {
  background: var(--seg-thumb);
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.12), 0 1px 1px rgba(0, 0, 0, 0.04);
}

.seg-thumb {
  position: absolute;
  top: 2px;
  bottom: 2px;
  left: 0;
  width: 0;
  border-radius: 8px;
  background: var(--seg-thumb);
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.12), 0 1px 1px rgba(0, 0, 0, 0.04);
  z-index: 0;
  pointer-events: none;
  transition: transform 0.32s var(--ease-ios), width 0.32s var(--ease-ios), opacity 0.2s ease;
}

.segmented button:active:not(:disabled) {
  transform: scale(0.94);
}

/* ---------- Date switcher ---------- */
.date-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--fill);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text);
}

.icon-btn svg {
  width: 18px;
  height: 18px;
}

.date-pill {
  min-height: 36px;
  padding: 0 16px;
  border-radius: 999px;
  background: var(--fill);
  font-size: 15px;
  font-weight: 600;
}

/* ---------- Hero ring + macros ---------- */
.hero-grid {
  display: flex;
  align-items: center;
  gap: 18px;
}

.ring-wrap {
  position: relative;
  width: 136px;
  height: 136px;
  flex-shrink: 0;
}

.ring-svg {
  transform: rotate(-90deg);
  display: block;
}

.ring-progress {
  transition: stroke-dashoffset 1.15s var(--ease-out), stroke 0.4s ease;
}

.ring-center {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.ring-num {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.05;
}

.ring-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
  margin-top: 2px;
}

.macro-col {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 11px;
}

.macro-row-head {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  font-weight: 500;
  margin-bottom: 5px;
}

.bar-track {
  height: 8px;
  border-radius: 999px;
  background: var(--ring-track);
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  border-radius: 999px;
  transition: width 0.9s var(--ease-out);
}

/* ---------- Stats strip ---------- */
.stats-strip {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.stat-tile {
  background: var(--surface);
  border: 0.5px solid var(--border);
  border-radius: 16px;
  padding: 12px 10px;
  text-align: center;
  box-shadow: var(--shadow);
}

.stat-tile .val {
  font-size: 17px;
  font-weight: 700;
  margin-top: 3px;
  letter-spacing: -0.02em;
}

.stat-label {
  font-size: 12px;
  color: var(--muted);
  font-weight: 500;
}

/* ---------- Meal list ---------- */
.meal-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.meal-card {
  width: 100%;
  text-align: left;
  background: var(--surface);
  border: 0.5px solid var(--border);
  border-radius: 18px;
  padding: 12px;
  display: flex;
  align-items: center;
  gap: 12px;
  box-shadow: var(--shadow);
}

.meal-thumb {
  width: 56px;
  height: 56px;
  border-radius: 14px;
  object-fit: cover;
  flex-shrink: 0;
  background: var(--fill);
  display: flex;
  align-items: center;
  justify-content: center;
}

.meal-thumb svg {
  width: 26px;
  height: 26px;
}

.meal-info {
  flex: 1;
  min-width: 0;
}

.meal-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
}

.meal-title {
  font-size: 16px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.meal-kcal {
  font-size: 16px;
  font-weight: 700;
  flex-shrink: 0;
}

.meal-sub {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 13px;
  color: var(--muted);
  margin-top: 4px;
}

.meal-sub span:first-child {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.empty-state {
  text-align: center;
  padding: 28px 18px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.empty-state svg {
  width: 52px;
  height: 52px;
  margin-bottom: 6px;
}

/* ---------- Bottom tab bar ---------- */
.tab-bar {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 480px;
  z-index: 30;
  background: var(--glass-strong);
  backdrop-filter: saturate(180%) blur(24px);
  -webkit-backdrop-filter: saturate(180%) blur(24px);
  border-top: 0.5px solid var(--separator);
  padding: 6px 12px calc(6px + env(safe-area-inset-bottom));
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  align-items: center;
  justify-items: center;
  gap: 4px;
}

.tab-item {
  width: 100%;
  min-height: 48px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.01em;
  color: var(--muted);
  transition: color 0.25s ease, transform 0.35s var(--ease-spring);
}

.tab-item svg {
  width: 24px;
  height: 24px;
}

.tab-item.active {
  color: var(--accent);
}

.tab-add-btn {
  width: 44px;
  height: 44px;
  margin: 0;
  border-radius: 50%;
  background: var(--accent);
  color: var(--on-accent);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.bump svg {
  animation: tab-bump 0.45s var(--ease-spring);
}

/* ---------- Bottom sheet (iOS) ---------- */
dialog.sheet {
  position: fixed;
  inset: auto 0 0 0;
  margin: 0 auto;
  width: 100%;
  max-width: 480px;
  max-height: 92dvh;
  border: none;
  border-radius: 20px 20px 0 0;
  background: var(--surface);
  color: var(--text);
  padding: 0;
  overflow: hidden;
  box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.35);
}

dialog.sheet[open] {
  animation: sheet-up 0.42s var(--ease-ios);
}

dialog.sheet::backdrop {
  background: rgba(0, 0, 0, 0.42);
}

dialog.sheet[open]::backdrop {
  animation: fade-in 0.3s ease;
}

dialog.sheet.closing::backdrop {
  animation: fade-out 0.26s ease forwards;
}

@media (min-width: 600px) {
  dialog.sheet {
    inset: 0;
    margin: auto;
    border-radius: 22px;
  }

  dialog.sheet[open] {
    animation: sheet-pop 0.4s var(--ease-ios);
  }
}

.sheet-inner {
  display: flex;
  flex-direction: column;
  max-height: 92dvh;
}

.sheet-grabber {
  display: block;
  width: 36px;
  height: 5px;
  min-height: 5px;
  border-radius: 999px;
  background: var(--separator);
  margin: 8px auto 0;
  flex-shrink: 0;
  cursor: grab;
}

.sheet-head {
  padding: 8px 18px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  cursor: grab;
}

.sheet-head strong {
  font-size: 17px;
  font-weight: 650;
  letter-spacing: -0.01em;
}

.sheet-body {
  padding: 4px 18px calc(24px + env(safe-area-inset-bottom));
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* ---------- Meal editor ---------- */
.item-row {
  background: var(--fill);
  border-radius: 14px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  animation: rise 0.4s var(--ease-out) both;
}

.item-row-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}

.item-row input {
  background: var(--surface);
}

.item-row-grid input {
  padding: 8px 6px;
  font-size: 16px;
  text-align: center;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip {
  padding: 8px 13px;
  min-height: 36px;
  border-radius: 999px;
  background: var(--fill);
  font-size: 14px;
  font-weight: 500;
}

/* ---------- Skeleton ---------- */
.skeleton {
  height: 18px;
  border-radius: 10px;
  background: var(--fill);
  animation: pulse-soft 1.3s ease-in-out infinite;
}

/* ---------- Heatmap ---------- */
.heatmap-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
}

.heat-cell {
  height: 30px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 600;
}

.heat-anim .heat-cell {
  animation: cell-in 0.45s var(--ease-spring) both;
  animation-delay: calc(var(--i, 0) * 14ms);
}

.heat-on_target { background: var(--accent); color: var(--on-accent); }
.heat-off_target { background: var(--amber); color: #1c1000; }
.heat-in_progress { background: var(--blue); color: #ffffff; }
.heat-empty { background: var(--fill); color: var(--muted); }

/* ---------- Toast (Dynamic Island style) ---------- */
.toast {
  position: fixed;
  top: calc(10px + env(safe-area-inset-top));
  left: 50%;
  z-index: 99;
  max-width: calc(100% - 32px);
  padding: 11px 18px;
  border-radius: 999px;
  background: rgba(28, 28, 30, 0.94);
  color: #ffffff;
  font-size: 14px;
  font-weight: 600;
  text-align: center;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  pointer-events: none;
  opacity: 0;
  transform: translate(-50%, -24px) scale(0.86);
  transition: transform 0.5s var(--ease-spring), opacity 0.25s ease;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0) scale(1);
}

/* ---------- Layout helpers ---------- */
.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.preview-img {
  width: 100%;
  max-height: 230px;
  object-fit: cover;
  border-radius: 16px;
  background: var(--fill);
  animation: rise 0.45s var(--ease-out) both;
}

.hairline {
  height: 0.5px;
  background: var(--separator);
  margin: 16px 0;
}

/* ---------- Body & Health components ---------- */
.comp-hero {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.comp-big-num {
  font-size: 40px;
  font-weight: 700;
  letter-spacing: -0.035em;
  line-height: 1;
}

.split-bar {
  display: flex;
  height: 12px;
  border-radius: 999px;
  overflow: hidden;
  background: var(--ring-track);
  gap: 2px;
}

.split-seg-lean {
  background: var(--blue);
  border-radius: 999px 0 0 999px;
  transition: width 1s var(--ease-out);
}

.split-seg-fat {
  background: var(--amber);
  border-radius: 0 999px 999px 0;
  transition: width 1s var(--ease-out) 0.08s;
}

.split-legend {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 12px;
}

.legend-box {
  background: var(--fill);
  border-radius: 14px;
  padding: 10px 12px;
}

.dot-inline {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 6px;
}

.meta-grid-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 12px;
}

.meta-pill-box {
  background: var(--fill);
  border-radius: 14px;
  padding: 9px 10px;
}

.energy-track-wrap {
  position: relative;
  padding: 8px 0 4px;
}

.energy-track {
  display: flex;
  height: 12px;
  border-radius: 999px;
  overflow: hidden;
  background: var(--ring-track);
  gap: 2px;
}

.energy-track > div {
  transition: width 1s var(--ease-out);
}

.energy-marker {
  position: absolute;
  top: 2px;
  width: 3px;
  height: 24px;
  border-radius: 999px;
  background: var(--text);
  transform: translateX(-50%);
  transition: left 1s var(--ease-spring);
}

.gauge-block {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.gauge-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.gauge-bar-wrap {
  position: relative;
  height: 22px;
  display: flex;
  align-items: center;
}

.gauge-track {
  width: 100%;
  height: 8px;
  border-radius: 999px;
  display: flex;
  overflow: hidden;
  gap: 2px;
}

.gauge-pin {
  position: absolute;
  top: 50%;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #ffffff;
  border: 3px solid var(--surface);
  box-shadow: 0 0 0 1px var(--separator), 0 3px 10px rgba(0, 0, 0, 0.35);
  transform: translate(-50%, -50%);
  transition: left 1.1s var(--ease-spring);
}

.gauge-ticks {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--muted);
}

.metric-grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.metric-card {
  background: var(--surface);
  border: 0.5px solid var(--border);
  border-radius: 18px;
  padding: 14px;
  text-align: left;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.metric-card-val {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.025em;
}

.lock-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 10px;
  padding: 10px 4px 4px;
}

.disclaimer-note {
  text-align: center;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.45;
  padding: 2px 12px 8px;
}

/* ---------- iOS Appearance Theme Picker ---------- */
.theme-picker {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  padding-top: 2px;
}

.theme-opt {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 9px;
  padding: 4px 2px 2px;
}

.theme-phone {
  position: relative;
  width: 100%;
  max-width: 92px;
  aspect-ratio: 9 / 12.2;
  border-radius: 16px;
  padding: 7px 6px 6px;
  display: flex;
  flex-direction: column;
  gap: 5px;
  overflow: hidden;
  border: 1px solid var(--separator);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.12);
  transition: box-shadow 0.3s var(--ease-spring), border-color 0.25s ease, transform 0.35s var(--ease-spring);
}

.theme-opt.active .theme-phone {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent);
}

.theme-opt:active .theme-phone {
  transform: scale(0.95);
}

.theme-phone-light,
.tp-half-light {
  background: #f4f4f6;
  --tp-card-bg: #ffffff;
  --tp-row-bg: #e4e4e7;
  --tp-island: #18181b;
  --tp-ring: #111113;
  --tp-bar1: #2563eb;
  --tp-bar2: #d97706;
}

.theme-phone-dark,
.tp-half-dark {
  background: #09090b;
  --tp-card-bg: #171719;
  --tp-row-bg: #27272a;
  --tp-island: #000000;
  --tp-ring: #ffffff;
  --tp-bar1: #3b82f6;
  --tp-bar2: #f59e0b;
}

.theme-phone-auto {
  padding: 0;
  background: #0a0a0c;
}

.tp-half {
  position: absolute;
  inset: 0;
  padding: 7px 6px 6px;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.tp-half-light {
  clip-path: inset(0 50% 0 0);
}

.tp-half-dark {
  clip-path: inset(0 0 0 50%);
}

.tp-island {
  width: 24px;
  height: 5px;
  border-radius: 999px;
  background: var(--tp-island);
  margin: 0 auto 2px;
  opacity: 0.75;
}

.tp-card {
  background: var(--tp-card-bg);
  border-radius: 9px;
  padding: 6px 5px;
  display: flex;
  align-items: center;
  gap: 5px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
}

.tp-ring {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 3px solid var(--tp-ring);
  border-top-color: var(--tp-row-bg);
  flex-shrink: 0;
}

.tp-bars {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.tp-bars span {
  display: block;
  height: 4px;
  border-radius: 999px;
}

.tp-bars span:first-child {
  width: 90%;
  background: var(--tp-bar1);
}

.tp-bars span:last-child {
  width: 68%;
  background: var(--tp-bar2);
}

.tp-row {
  height: 16px;
  border-radius: 7px;
  background: var(--tp-card-bg);
  margin-top: auto;
  opacity: 0.9;
}

.theme-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-2);
  transition: color 0.2s ease;
}

.theme-opt.active .theme-label {
  color: var(--text);
}

.theme-radio {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 1.8px solid var(--separator);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--on-green);
  transition: background-color 0.25s ease, border-color 0.25s ease, transform 0.4s var(--ease-spring);
}

.theme-radio svg {
  width: 12px;
  height: 12px;
  opacity: 0;
  transform: scale(0.4);
  transition: opacity 0.2s ease, transform 0.4s var(--ease-spring);
}

.theme-opt.active .theme-radio {
  background: var(--green);
  border-color: var(--green);
  transform: scale(1.06);
}

.theme-opt.active .theme-radio svg {
  opacity: 1;
  transform: scale(1);
}

/* ---------- iOS Settings Grouped Rows & Accordion ---------- */
.profile-hero {
  display: flex;
  align-items: center;
  gap: 13px;
}

.avatar-badge {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--on-accent);
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.02em;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.ios-group-wrap {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.ios-group-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 2px 14px 0;
}

.ios-group {
  background: var(--surface);
  border: 0.5px solid var(--border);
  border-radius: 18px;
  overflow: hidden;
  box-shadow: var(--shadow);
}

.ios-row {
  position: relative;
  width: 100%;
  min-height: 54px;
  padding: 11px 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  text-align: left;
  text-decoration: none;
  color: var(--text);
  background: transparent;
  transition: background-color 0.15s ease;
}

.ios-row:active {
  background: var(--fill);
  transform: none !important;
}

.ios-row + .ios-row::before,
.accordion-panel + .ios-row::before {
  content: "";
  position: absolute;
  top: 0;
  left: 56px;
  right: 0;
  height: 0.5px;
  background: var(--separator);
}

.ios-ico {
  width: 32px;
  height: 32px;
  border-radius: 9px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--fill);
  color: var(--text);
  flex-shrink: 0;
}

.ios-ico svg {
  width: 17px;
  height: 17px;
}

.ios-row-title {
  font-size: 16px;
  font-weight: 500;
  flex: 1;
  min-width: 0;
}

.ios-row-val {
  font-size: 14px;
  color: var(--muted);
  white-space: nowrap;
  max-width: 46%;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ios-chev {
  width: 16px;
  height: 16px;
  color: var(--muted);
  opacity: 0.65;
  flex-shrink: 0;
  transition: transform 0.32s var(--ease-ios);
}

.ios-row[aria-expanded="true"] .ios-chev {
  transform: rotate(90deg);
}

.ios-row-danger {
  justify-content: center;
  color: var(--rose);
  font-size: 16px;
  font-weight: 600;
}

.accordion-panel {
  display: grid;
  grid-template-rows: 0fr;
  opacity: 0;
  transition: grid-template-rows 0.38s var(--ease-ios), opacity 0.25s ease;
}

.accordion-panel.open {
  grid-template-rows: 1fr;
  opacity: 1;
}

.accordion-inner {
  overflow: hidden;
}

.accordion-content {
  padding: 6px 14px 16px;
}

/* ---------- Dedicated iOS Push Sub-Page ---------- */
.subpage {
  position: fixed;
  inset: 0;
  z-index: 45;
  max-width: 480px;
  margin: 0 auto;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  visibility: hidden;
  pointer-events: none;
  transition: transform 0.38s var(--ease-ios), visibility 0.38s;
}

.subpage.open {
  transform: translateX(0);
  visibility: visible;
  pointer-events: auto;
}

.subpage-head {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--glass);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 0.5px solid var(--separator);
  padding: calc(10px + env(safe-area-inset-top)) 14px 10px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
}

.subpage-back {
  justify-self: start;
  display: inline-flex;
  align-items: center;
  gap: 2px;
  min-height: 40px;
  padding: 0 4px;
  color: var(--green);
  font-size: 16px;
  font-weight: 600;
}

.subpage-back svg {
  width: 20px;
  height: 20px;
}

.subpage-title {
  font-size: 17px;
  font-weight: 650;
  letter-spacing: -0.015em;
  text-align: center;
}

.subpage-body {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  padding: 14px var(--space) calc(40px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.macro-split-preview {
  display: flex;
  height: 10px;
  border-radius: 999px;
  overflow: hidden;
  background: var(--ring-track);
  gap: 2px;
}

/* ---------- Chart motion ---------- */
.bar-grow {
  transform-box: fill-box;
  transform-origin: 50% 100%;
  animation: grow-y 0.75s var(--ease-out) both;
  animation-delay: calc(var(--i, 0) * 26ms);
}

.line-draw {
  stroke-dasharray: 1;
  stroke-dashoffset: 1;
  animation: draw 1.2s var(--ease-out) 0.1s forwards;
}

.area-fade {
  animation: fade-in 0.9s ease 0.35s both;
}

.dot-pop {
  transform-box: fill-box;
  transform-origin: center;
  animation: pop 0.5s var(--ease-spring) both;
  animation-delay: calc(0.4s + var(--i, 0) * 40ms);
}

.donut-seg {
  transition: stroke-dasharray 1.1s var(--ease-out), stroke-dashoffset 1.1s var(--ease-out);
}

.pop-in {
  animation: pop 0.6s var(--ease-spring) both;
}

/* ---------- View transitions ---------- */
.view-enter > * {
  animation: rise 0.55s var(--ease-out) both;
  animation-delay: calc(var(--i, 0) * 45ms);
}

.swipe-from-left {
  animation: slide-from-left 0.45s var(--ease-out);
}

.swipe-from-right {
  animation: slide-from-right 0.45s var(--ease-out);
}

/* ---------- Keyframes ---------- */
@keyframes rise {
  from { opacity: 0; transform: translateY(14px) scale(0.985); }
  to { opacity: 1; transform: none; }
}

@keyframes sheet-up {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

@keyframes sheet-pop {
  from { opacity: 0; transform: translateY(24px) scale(0.96); }
  to { opacity: 1; transform: none; }
}

@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes fade-out {
  from { opacity: 1; }
  to { opacity: 0; }
}

@keyframes pulse-soft {
  0%, 100% { opacity: 0.45; }
  50% { opacity: 1; }
}

@keyframes tab-bump {
  0% { transform: scale(1); }
  35% { transform: scale(0.82); }
  70% { transform: scale(1.12); }
  100% { transform: scale(1); }
}

@keyframes grow-y {
  from { transform: scaleY(0); }
  to { transform: scaleY(1); }
}

@keyframes draw {
  to { stroke-dashoffset: 0; }
}

@keyframes pop {
  0% { opacity: 0; transform: scale(0.6); }
  100% { opacity: 1; transform: scale(1); }
}

@keyframes cell-in {
  from { opacity: 0; transform: scale(0.5); }
  to { opacity: 1; transform: scale(1); }
}

@keyframes slide-from-left {
  from { opacity: 0.2; transform: translateX(-28px); }
  to { opacity: 1; transform: none; }
}

@keyframes slide-from-right {
  from { opacity: 0.2; transform: translateX(28px); }
  to { opacity: 1; transform: none; }
}

/* ---------- Accessibility: reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after,
  dialog.sheet::backdrop {
    animation-duration: 0.01ms !important;
    animation-delay: 0ms !important;
    transition-duration: 0.01ms !important;
  }

  .line-draw {
    stroke-dasharray: none;
    stroke-dashoffset: 0;
  }
}
