/* =============================================================================
   Diario de comidas — styles inspired by Apple's Liquid Glass.

   Two layers, as in Apple's guidance:
   · Content layer: a soft ambient background with frosted "material" cards.
   · Functional layer (Liquid Glass): floating toolbar controls, the tab bar,
     toasts, and segmented-control thumbs while pressed. Glass is kept off the
     content and used sparingly; shapes are capsules with concentric radii.
   Accessibility settings (reduced transparency, increased contrast, reduced
   motion) switch the glass to solid surfaces / remove animation.
   ========================================================================== */

:root {
  color-scheme: light dark;

  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-display: -apple-system, BlinkMacSystemFont, "SF Pro Display", system-ui, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-rounded: ui-rounded, "SF Pro Rounded", var(--font-display);

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);

  --gutter: 16px;
  --content: 620px;
  --toolbar-h: 60px;
  --tabbar-h: 64px;
  --tabbar-gap: max(12px, calc(var(--safe-bottom) - 10px));
  --side: max(calc(var(--gutter) + var(--safe-left)), calc((100% - var(--content)) / 2));
  --side-r: max(calc(var(--gutter) + var(--safe-right)), calc((100% - var(--content)) / 2));

  /* concentric radii: card − padding = inner element */
  --r-card: 28px;
  --pad-card: 14px;
  --r-inner: 14px;
  --r-pill: 999px;

  --spring: cubic-bezier(0.34, 1.45, 0.5, 1);
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);

  /* light */
  --bg: #f5f0eb;
  --label: #1c1c1e;
  --label-2: rgba(60, 60, 67, 0.7);
  --label-3: rgba(60, 60, 67, 0.4);
  --separator: rgba(60, 60, 67, 0.16);
  --fill: rgba(118, 118, 128, 0.12);
  --fill-2: rgba(118, 118, 128, 0.2);

  --material: rgba(255, 255, 255, 0.6);
  --material-edge: rgba(255, 255, 255, 0.8);
  --material-shadow: 0 1px 2px rgba(80, 50, 20, 0.05), 0 10px 30px rgba(80, 50, 20, 0.07);
  --material-blur: blur(30px) saturate(170%);

  --glass: rgba(255, 255, 255, 0.42);
  --glass-strong: rgba(255, 255, 255, 0.72);
  --glass-rim: rgba(255, 255, 255, 0.95);
  --glass-rim-soft: rgba(255, 255, 255, 0.35);
  --glass-shadow: 0 8px 24px rgba(40, 25, 10, 0.13), 0 1px 3px rgba(40, 25, 10, 0.08);
  --glass-blur: blur(14px) saturate(200%) brightness(1.06);
  --lens: rgba(255, 255, 255, 0.55);

  --thumb: #ffffff;
  --thumb-shadow: 0 3px 8px rgba(0, 0, 0, 0.12), 0 1px 1px rgba(0, 0, 0, 0.05);

  --accent: #e8590c; /* fills with white text */
  --accent-text: #c2410c; /* tinted text and icons */
  --accent-soft: rgba(232, 89, 12, 0.13);
  --danger: #d70015;

  --deficit: #1d6fe0;
  --equilibrio: #1e8e3e;
  --superavit: #e0284f;

  --tone-orange: #ff9500;
  --tone-green: #34c759;
  --tone-pink: #ff2d55;
  --tone-indigo: #5856d6;
  --tone-teal: #30b0c7;
  --tone-blue: #007aff;
  --tone-red: #ff3b30;
  --tone-gray: #8e8e93;

  --ambient-1: rgba(255, 166, 94, 0.55);
  --ambient-2: rgba(255, 112, 150, 0.32);
  --ambient-3: rgba(110, 205, 160, 0.42);
  --ambient-4: rgba(126, 156, 255, 0.36);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0c0d12;
    --label: #f5f5f7;
    --label-2: rgba(235, 235, 245, 0.68);
    --label-3: rgba(235, 235, 245, 0.36);
    --separator: rgba(84, 84, 88, 0.6);
    --fill: rgba(118, 118, 128, 0.24);
    --fill-2: rgba(118, 118, 128, 0.36);

    --material: rgba(32, 32, 38, 0.58);
    --material-edge: rgba(255, 255, 255, 0.08);
    --material-shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 12px 30px rgba(0, 0, 0, 0.3);
    --material-blur: blur(30px) saturate(150%);

    --glass: rgba(48, 48, 56, 0.5);
    --glass-strong: rgba(64, 64, 72, 0.72);
    --glass-rim: rgba(255, 255, 255, 0.3);
    --glass-rim-soft: rgba(255, 255, 255, 0.07);
    --glass-shadow: 0 8px 26px rgba(0, 0, 0, 0.45), 0 1px 3px rgba(0, 0, 0, 0.3);
    --glass-blur: blur(14px) saturate(170%) brightness(0.95);
    --lens: rgba(255, 255, 255, 0.13);

    --thumb: #636366;
    --thumb-shadow: 0 3px 8px rgba(0, 0, 0, 0.35);

    --accent-text: #ff9f0a;
    --accent-soft: rgba(255, 159, 10, 0.16);
    --danger: #ff453a;

    --tone-orange: #ff9f0a;
    --tone-green: #30d158;
    --tone-pink: #ff375f;
    --tone-indigo: #5e5ce6;
    --tone-teal: #40c8e0;
    --tone-blue: #0a84ff;
    --tone-red: #ff453a;
    --tone-gray: #98989d;

    --ambient-1: rgba(255, 128, 50, 0.28);
    --ambient-2: rgba(220, 60, 120, 0.2);
    --ambient-3: rgba(40, 160, 130, 0.22);
    --ambient-4: rgba(80, 100, 240, 0.28);
  }
}

/* ── base ─────────────────────────────────────────────────────────────────── */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  font: 17px/1.35 var(--font);
  letter-spacing: -0.01em;
  color: var(--label);
  background: transparent; /* the html element paints --bg; the ambient layer sits between */
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

button,
input,
textarea {
  font: inherit;
  letter-spacing: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
}

a {
  color: inherit;
  text-decoration: none;
  touch-action: manipulation;
}

[hidden] {
  display: none !important;
}

.icon {
  width: 1.25em;
  height: 1.25em;
  flex: none;
}

:focus-visible {
  outline: 3px solid var(--accent-text);
  outline-offset: 2px;
}

body.is-booting .main,
body.is-booting .tabbar {
  visibility: hidden;
}

/* ── content layer: ambient background ───────────────────────────────────── */

.ambient {
  position: fixed;
  inset: -15vmax;
  z-index: -1;
  pointer-events: none;
  background:
    radial-gradient(40vmax 32vmax at 25% 18%, var(--ambient-1), transparent 70%),
    radial-gradient(34vmax 28vmax at 88% 28%, var(--ambient-2), transparent 70%),
    radial-gradient(42vmax 34vmax at 78% 82%, var(--ambient-3), transparent 70%),
    radial-gradient(36vmax 30vmax at 14% 76%, var(--ambient-4), transparent 70%),
    var(--bg);
}

/* Scroll edge effect: content fades and blurs under the floating controls. */
.edge {
  position: fixed;
  left: 0;
  right: 0;
  z-index: 10;
  pointer-events: none;
  -webkit-backdrop-filter: blur(12px) saturate(140%);
  backdrop-filter: blur(12px) saturate(140%);
}

.edge-top {
  top: 0;
  height: calc(var(--safe-top) + var(--toolbar-h) + 22px);
  background: linear-gradient(
    to bottom,
    color-mix(in srgb, var(--bg) 82%, transparent) 0%,
    color-mix(in srgb, var(--bg) 60%, transparent) 55%,
    transparent 100%
  );
  -webkit-mask-image: linear-gradient(to bottom, #000 62%, transparent);
  mask-image: linear-gradient(to bottom, #000 62%, transparent);
}

.edge-bottom {
  bottom: 0;
  height: calc(var(--tabbar-h) + var(--tabbar-gap) + 30px);
  background: linear-gradient(to top, color-mix(in srgb, var(--bg) 70%, transparent) 0%, transparent 100%);
  -webkit-mask-image: linear-gradient(to top, #000 45%, transparent);
  mask-image: linear-gradient(to top, #000 45%, transparent);
}

body.is-login .edge {
  display: none;
}

/* ── layout ───────────────────────────────────────────────────────────────── */

.main {
  padding: calc(var(--safe-top) + var(--toolbar-h)) var(--side-r)
    calc(var(--tabbar-h) + var(--tabbar-gap) + 36px) var(--side);
  outline: none;
}

body.is-login .main {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding-top: calc(var(--safe-top) + 24px);
  padding-bottom: calc(var(--safe-bottom) + 24px);
}

.stack {
  display: grid;
  gap: 14px;
}

.view-enter {
  animation: view-in 0.3s var(--ease) both;
}

.view-enter[data-direction="forward"] {
  animation-name: view-in-forward;
}

.view-enter[data-direction="back"] {
  animation-name: view-in-back;
}

@keyframes view-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
}

@keyframes view-in-forward {
  from {
    opacity: 0;
    transform: translateX(28px);
  }
}

@keyframes view-in-back {
  from {
    opacity: 0;
    transform: translateX(-28px);
  }
}

/* ── large titles ─────────────────────────────────────────────────────────── */

.large-title {
  padding: 4px 4px 16px;
}

.title {
  margin: 0;
  font: 700 34px/1.12 var(--font-display);
  letter-spacing: -0.025em;
}

.subtitle {
  margin: 3px 0 0;
  font-size: 17px;
  color: var(--label-2);
}

.subtitle::first-letter {
  text-transform: uppercase;
}

.date-trigger {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border-radius: 12px;
  transition: opacity 0.15s;
}

.date-trigger:active {
  opacity: 0.55;
}

.title-chevron {
  width: 22px;
  height: 22px;
  margin-top: 4px;
  color: var(--accent-text);
  stroke-width: 2.6;
}

/* Invisible native date input covering the title: tapping the title opens the iOS picker. */
.date-input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  border: 0;
  opacity: 0;
  font-size: 16px;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
}

.date-input::-webkit-calendar-picker-indicator {
  position: absolute;
  inset: 0;
  width: auto;
  height: auto;
  cursor: pointer;
}

.sync-status {
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 18px;
  margin: 8px 0 0;
  font-size: 13px;
  font-weight: 500;
  color: var(--label-2);
}

.sync-status .icon {
  width: 15px;
  height: 15px;
  stroke-width: 2.4;
}

.sync-status[data-state="saved"] .icon {
  color: var(--equilibrio);
}

.sync-status[data-state="saving"] .icon {
  animation: spin 1s linear infinite;
}

.sync-status[data-state="offline"],
.sync-status[data-state="error"],
.sync-status[data-state="auth"] {
  color: var(--accent-text);
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ── material cards (content layer) ──────────────────────────────────────── */

.card {
  position: relative;
  padding: var(--pad-card);
  border-radius: var(--r-card);
  background: var(--material);
  -webkit-backdrop-filter: var(--material-blur);
  backdrop-filter: var(--material-blur);
  box-shadow: var(--material-shadow), inset 0 0 0 0.5px var(--material-edge);
}

.card-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 2px 2px 12px;
}

.card-title {
  margin: 0;
  font: 600 20px/1.2 var(--font-display);
  letter-spacing: -0.02em;
}

.badge {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 10px;
  color: #fff;
  background: linear-gradient(180deg, color-mix(in srgb, var(--tone) 78%, #fff), var(--tone));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.4), 0 3px 8px color-mix(in srgb, var(--tone) 35%, transparent);
}

.badge .icon {
  width: 19px;
  height: 19px;
  stroke-width: 2.1;
}

[data-tone="orange"] { --tone: var(--tone-orange); }
[data-tone="green"] { --tone: var(--tone-green); }
[data-tone="pink"] { --tone: var(--tone-pink); }
[data-tone="indigo"] { --tone: var(--tone-indigo); }
[data-tone="teal"] { --tone: var(--tone-teal); }
[data-tone="blue"] { --tone: var(--tone-blue); }
[data-tone="red"] { --tone: var(--tone-red); }
[data-tone="gray"] { --tone: var(--tone-gray); }

/* ── meal items ───────────────────────────────────────────────────────────── */

.items {
  display: grid;
  gap: 12px;
}

.item {
  display: grid;
  gap: 10px;
}

.item + .item {
  padding-top: 12px;
  border-top: 0.5px solid var(--separator);
}

.field {
  display: block;
  width: 100%;
  min-height: 48px;
  padding: 12px 14px;
  border: 0;
  border-radius: var(--r-inner);
  background: var(--fill);
  font-size: 17px;
  line-height: 1.4;
  resize: none;
  overflow: hidden;
  field-sizing: content;
  transition: background-color 0.2s, box-shadow 0.2s;
}

.field::placeholder {
  color: var(--label-3);
}

.field:focus {
  outline: none;
  background: var(--fill-2);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent-text) 60%, transparent);
}

.item-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.item-row .segmented {
  flex: 1;
}

.icon-button {
  display: grid;
  place-items: center;
  flex: none;
  width: 38px;
  height: 38px;
  border: 0;
  border-radius: var(--r-pill);
  background: var(--fill);
  color: var(--label-2);
  transition: transform 0.3s var(--spring), background-color 0.2s;
}

.icon-button:active {
  transform: scale(0.88);
  background: var(--fill-2);
}

.icon-button .icon {
  width: 17px;
  height: 17px;
  stroke-width: 2.4;
}

.add-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin: 10px 0 0 -6px;
  padding: 8px 12px;
  border: 0;
  border-radius: var(--r-pill);
  background: none;
  color: var(--accent-text);
  font-size: 15px;
  font-weight: 600;
  transition: background-color 0.2s, transform 0.3s var(--spring);
}

.add-item .icon {
  width: 18px;
  height: 18px;
  stroke-width: 2.5;
}

.add-item:active {
  background: var(--accent-soft);
  transform: scale(0.96);
}

/* ── segmented control ────────────────────────────────────────────────────── */

.segmented {
  --count: 3;
  --index: 0;
  --pad: 3px;
  position: relative;
  display: grid;
  grid-template-columns: repeat(var(--count), minmax(0, 1fr));
  padding: var(--pad);
  border-radius: var(--r-pill);
  background: var(--fill);
  isolation: isolate;
}

.segmented-thumb {
  position: absolute;
  z-index: 0;
  top: var(--pad);
  bottom: var(--pad);
  left: var(--pad);
  width: calc((100% - 2 * var(--pad)) / var(--count));
  border-radius: var(--r-pill);
  background: var(--thumb);
  box-shadow: var(--thumb-shadow);
  opacity: 0;
  transform: translateX(calc(var(--index) * 100%));
  transition:
    transform 0.5s var(--spring),
    scale 0.3s var(--spring),
    opacity 0.2s,
    background-color 0.25s;
}

.segmented.has-value .segmented-thumb {
  opacity: 1;
}

/* Liquid Glass on interaction: the thumb becomes a glass lens while pressed. */
.segmented:has(.segment:active) .segmented-thumb {
  scale: 1.06 1.14;
  background: var(--glass-strong);
  -webkit-backdrop-filter: var(--glass-blur);
  backdrop-filter: var(--glass-blur);
  box-shadow: var(--glass-shadow), inset 0 1px 0.5px var(--glass-rim);
}

.segment {
  position: relative;
  z-index: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  min-width: 0;
  min-height: 38px;
  padding: 6px 6px;
  border: 0;
  border-radius: var(--r-pill);
  background: none;
  color: var(--label-2);
  font-size: 15px;
  font-weight: 500;
  white-space: nowrap;
  transition: color 0.2s;
}

.segment[aria-pressed="true"] {
  color: var(--label);
  font-weight: 600;
}

.segment span {
  overflow: hidden;
  text-overflow: ellipsis;
}

.segmented-balance .segment {
  min-height: 46px;
}

.segmented-balance .segment .icon {
  width: 17px;
  height: 17px;
  stroke-width: 2.6;
}

.segmented-balance .segment[data-key="deficit"] { --c: var(--deficit); }
.segmented-balance .segment[data-key="equilibrio"] { --c: var(--equilibrio); }
.segmented-balance .segment[data-key="superavit"] { --c: var(--superavit); }

.segmented-balance .segment .icon {
  color: var(--c);
}

.segmented-balance .segment[aria-pressed="true"],
.segmented-balance .segment[aria-pressed="true"] .icon {
  color: #fff;
}

.segmented-balance[data-value="deficit"] .segmented-thumb { background: var(--deficit); }
.segmented-balance[data-value="equilibrio"] .segmented-thumb { background: var(--equilibrio); }
.segmented-balance[data-value="superavit"] .segmented-thumb { background: var(--superavit); }

/* ── calendar ─────────────────────────────────────────────────────────────── */

.weekdays,
.month-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
}

.weekdays span {
  padding-bottom: 8px;
  text-align: center;
  font-size: 13px;
  font-weight: 600;
  color: var(--label-2);
}

.month-grid {
  row-gap: 4px;
}

.cal-cell {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 2px 0 4px;
  border-radius: 14px;
}

.cal-num {
  display: grid;
  place-items: center;
  width: min(40px, 100%);
  aspect-ratio: 1;
  border-radius: 50%;
  font: 500 17px/1 var(--font);
  font-variant-numeric: tabular-nums;
  transition: transform 0.3s var(--spring);
}

.cal-cell:active .cal-num {
  transform: scale(0.86);
}

.cal-cell.is-future .cal-num {
  color: var(--label-3);
}

.cal-cell.is-today .cal-num {
  color: var(--accent-text);
  font-weight: 700;
  box-shadow: inset 0 0 0 2px var(--accent-text);
}

.cal-cell.bal-deficit .cal-num { background: var(--deficit); }
.cal-cell.bal-equilibrio .cal-num { background: var(--equilibrio); }
.cal-cell.bal-superavit .cal-num { background: var(--superavit); }

.cal-cell[class*="bal-"] .cal-num {
  color: #fff;
  font-weight: 600;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.3);
}

.cal-cell.is-today[class*="bal-"] .cal-num {
  box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--accent-text);
}

.cal-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--label-3);
  visibility: hidden;
}

.cal-cell.has-meals .cal-dot {
  visibility: visible;
}

.stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.stat {
  display: grid;
  justify-items: start;
  gap: 2px;
  padding: 12px;
  border-radius: var(--r-inner);
  background: color-mix(in srgb, var(--c) 13%, transparent);
}

.stat.bal-deficit { --c: var(--deficit); }
.stat.bal-equilibrio { --c: var(--equilibrio); }
.stat.bal-superavit { --c: var(--superavit); }

.stat .icon {
  width: 20px;
  height: 20px;
  color: var(--c);
  stroke-width: 2.5;
}

.stat strong {
  font: 700 28px/1.1 var(--font-rounded);
  font-variant-numeric: tabular-nums;
}

.stat span {
  font-size: 13px;
  font-weight: 500;
  color: var(--label-2);
}

.stats-foot {
  margin: 12px 2px 2px;
  font-size: 15px;
  color: var(--label-2);
}

/* ── grouped lists (settings) ─────────────────────────────────────────────── */

.group {
  display: grid;
  gap: 8px;
}

.group-title {
  margin: 6px 18px 0;
  font: 600 15px/1.3 var(--font);
  color: var(--label-2);
}

.card.list {
  padding: 6px 0;
  overflow: hidden;
}

.list-row {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 56px;
  padding: 10px 16px;
  border: 0;
  background: none;
  text-align: left;
  color: var(--label);
  font-size: 17px;
}

.list-row + .list-row::before,
.password-form + .list-row::before {
  content: "";
  position: absolute;
  top: 0;
  left: 58px;
  right: 0;
  height: 0.5px;
  background: var(--separator);
}

button.list-row {
  transition: background-color 0.15s;
}

button.list-row:active {
  background: var(--fill);
}

.row-icon {
  display: grid;
  place-items: center;
  flex: none;
  width: 30px;
  height: 30px;
  border-radius: 9px;
  color: #fff;
  background: linear-gradient(180deg, color-mix(in srgb, var(--tone) 80%, #fff), var(--tone));
}

.row-icon .icon {
  width: 18px;
  height: 18px;
}

.row-text {
  display: grid;
  flex: 1;
  gap: 1px;
  min-width: 0;
}

.row-label {
  flex: 1;
}

.row-hint {
  font-size: 13px;
  color: var(--label-2);
}

.row-value {
  max-width: 55%;
  overflow: hidden;
  color: var(--label-2);
  text-align: right;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.row-chevron {
  width: 16px;
  height: 16px;
  color: var(--label-3);
  stroke-width: 2.6;
}

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

.list-row.is-destructive {
  color: var(--danger);
}

.password-form {
  display: grid;
  gap: 10px;
  padding: 4px 16px 16px 58px;
}

.password-form input {
  width: 100%;
  height: 46px;
  padding: 0 14px;
  border: 0;
  border-radius: 12px;
  background: var(--fill);
  font-size: 17px;
}

.password-form input:focus {
  outline: none;
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent-text) 60%, transparent);
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.form-error {
  margin: 0;
  color: var(--danger);
  font-size: 15px;
}

/* ── buttons ──────────────────────────────────────────────────────────────── */

.button {
  height: 46px;
  padding: 0 20px;
  border: 0;
  border-radius: var(--r-pill);
  background: var(--fill);
  font-size: 17px;
  font-weight: 600;
  transition: transform 0.3s var(--spring), opacity 0.2s;
}

.button:active {
  transform: scale(0.96);
}

.button:disabled {
  opacity: 0.55;
}

/* Prominent (tinted) glass: the one primary action of a screen. */
.button-prominent {
  color: #fff;
  background: linear-gradient(180deg, color-mix(in srgb, var(--accent) 86%, #fff), var(--accent));
  box-shadow: 0 6px 18px color-mix(in srgb, var(--accent) 35%, transparent), inset 0 1px 0 rgba(255, 255, 255, 0.4);
}

.button-block {
  width: 100%;
  height: 52px;
}

/* ── functional layer: Liquid Glass ───────────────────────────────────────── */

.glass {
  position: relative;
  isolation: isolate;
  background: var(--glass);
  -webkit-backdrop-filter: var(--glass-blur);
  backdrop-filter: var(--glass-blur);
  box-shadow:
    var(--glass-shadow),
    inset 0 1px 0.5px var(--glass-rim),
    inset 0 -1px 1px var(--glass-rim-soft);
}

/* Specular rim: light catching the edge of the glass from the top-left. */
.glass::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  padding: 1px;
  border-radius: inherit;
  background: linear-gradient(135deg, var(--glass-rim), transparent 38%, transparent 62%, var(--glass-rim-soft));
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
  mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  mask-composite: exclude;
  pointer-events: none;
}

.toolbar {
  position: fixed;
  z-index: 20;
  top: 0;
  left: 0;
  right: 0;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 8px;
  height: calc(var(--safe-top) + var(--toolbar-h));
  padding: calc(var(--safe-top) + 6px) var(--side-r) 6px var(--side);
  pointer-events: none;
}

.toolbar-side {
  display: flex;
  gap: 8px;
}

.toolbar-side > * {
  pointer-events: auto;
}

.toolbar-right {
  justify-content: flex-end;
}

.toolbar-title {
  max-width: 52vw;
  overflow: hidden;
  font-size: 17px;
  font-weight: 600;
  white-space: nowrap;
  text-overflow: ellipsis;
  opacity: 0;
  transform: translateY(6px);
  transition: opacity 0.2s, transform 0.25s var(--ease);
}

.toolbar.is-condensed .toolbar-title {
  opacity: 1;
  transform: none;
}

.glass-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 44px;
  min-width: 44px;
  padding: 0 18px;
  border: 0;
  border-radius: var(--r-pill);
  font-size: 16px;
  font-weight: 600;
  transition: transform 0.35s var(--spring);
}

.glass-button.is-icon {
  width: 44px;
  padding: 0;
}

.glass-button.is-tinted-text {
  color: var(--accent-text);
}

.glass-button:active {
  transform: scale(0.9);
}

.glass-group {
  display: inline-flex;
  padding: 0 2px;
  border-radius: var(--r-pill);
}

.glass-group > button {
  display: grid;
  place-items: center;
  width: 46px;
  height: 44px;
  border: 0;
  border-radius: var(--r-pill);
  background: none;
  transition: transform 0.35s var(--spring), background-color 0.2s;
}

.glass-group > button:active {
  transform: scale(0.86);
  background: var(--lens);
}

.glass-group .icon,
.glass-button .icon {
  width: 22px;
  height: 22px;
  stroke-width: 2.3;
}

/* Tab bar: a floating glass capsule; the selection is a lens that slides. */
.tabbar {
  --tab-w: 94px;
  --tab-index: 0;
  position: fixed;
  z-index: 30;
  left: 50%;
  bottom: var(--tabbar-gap);
  transform: translateX(-50%);
}

.tabbar-inner {
  display: grid;
  grid-template-columns: repeat(3, var(--tab-w));
  height: var(--tabbar-h);
  padding: 5px;
  border-radius: var(--r-pill);
  transition: height 0.35s var(--spring), grid-template-columns 0.35s var(--spring);
}

.tab-lens {
  position: absolute;
  z-index: 0;
  top: 5px;
  bottom: 5px;
  left: 5px;
  width: var(--tab-w);
  border-radius: var(--r-pill);
  background: var(--lens);
  box-shadow: inset 0 1px 0.5px var(--glass-rim-soft);
  transform: translateX(calc(var(--tab-index) * 100%));
  transition: transform 0.5s var(--spring), width 0.35s var(--spring);
}

.tab {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  border-radius: var(--r-pill);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0;
}

.tab .icon {
  width: 25px;
  height: 25px;
  stroke-width: 1.9;
  transition: transform 0.3s var(--spring);
}

.tab:active .icon {
  transform: scale(0.85);
}

.tab[aria-current="page"] {
  color: var(--accent-text);
}

.tab-label {
  max-height: 14px;
  transition: opacity 0.2s, max-height 0.3s var(--ease);
}

.tabbar.is-minimized {
  --tab-w: 62px;
}

.tabbar.is-minimized .tabbar-inner {
  height: 50px;
}

.tabbar.is-minimized .tab-label {
  max-height: 0;
  opacity: 0;
}

/* Toasts */
.toasts {
  position: fixed;
  z-index: 40;
  left: 0;
  right: 0;
  bottom: calc(var(--tabbar-gap) + var(--tabbar-h) + 14px);
  display: grid;
  justify-items: center;
  gap: 8px;
  padding: 0 var(--gutter);
  pointer-events: none;
}

body.is-login .toasts {
  bottom: calc(var(--safe-bottom) + 20px);
}

.toast {
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: 520px;
  min-height: 48px;
  padding: 8px 8px 8px 20px;
  border-radius: 24px;
  background: var(--glass-strong);
  font-size: 15px;
  font-weight: 500;
  opacity: 0;
  transform: translateY(14px) scale(0.96);
  transition: opacity 0.25s, transform 0.4s var(--spring);
  pointer-events: auto;
}

.toast:not(:has(.toast-action)) {
  padding-right: 20px;
}

.toast.is-visible {
  opacity: 1;
  transform: none;
}

.toast-action {
  flex: none;
  padding: 8px 16px;
  border: 0;
  border-radius: var(--r-pill);
  background: var(--accent);
  color: #fff;
  font-size: 15px;
  font-weight: 600;
}

/* ── login ────────────────────────────────────────────────────────────────── */

.view-login {
  width: 100%;
  max-width: 400px;
}

.login-card {
  display: grid;
  gap: 4px;
  padding: 30px 20px 22px;
  text-align: center;
}

.login-icon {
  width: 76px;
  height: 76px;
  margin: 0 auto 10px;
  border-radius: 18px;
  box-shadow: 0 10px 24px rgba(232, 89, 12, 0.28);
}

.login-title {
  margin: 0;
  font: 700 28px/1.15 var(--font-display);
  letter-spacing: -0.02em;
}

.login-subtitle {
  margin: 0 0 16px;
  color: var(--label-2);
}

.login-form {
  display: grid;
  gap: 14px;
  text-align: left;
}

.field-group {
  overflow: hidden;
  border-radius: var(--r-inner);
  background: var(--fill);
}

.field-row {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 52px;
  padding: 0 16px;
}

.field-row + .field-row {
  border-top: 0.5px solid var(--separator);
}

.field-row span {
  flex: none;
  width: 92px;
  font-weight: 500;
}

.field-row input {
  flex: 1;
  min-width: 0;
  height: 50px;
  border: 0;
  background: none;
  font-size: 17px;
  outline: none;
}

.login-form .form-error {
  text-align: center;
}

/* ── pointer devices ──────────────────────────────────────────────────────── */

@media (hover: hover) {
  button.list-row:hover,
  .icon-button:hover {
    background: var(--fill);
  }

  .glass-group > button:hover,
  .glass-button:hover {
    background-color: var(--lens);
  }

  .cal-cell:not([class*="bal-"]):hover .cal-num {
    background: var(--fill);
  }

  .add-item:hover {
    background: var(--accent-soft);
  }
}

/* ── accessibility settings ───────────────────────────────────────────────── */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

@media (prefers-reduced-transparency: reduce) {
  :root {
    --material: #ffffff;
    --glass: #f2f2f7;
    --glass-strong: #ffffff;
    --lens: rgba(118, 118, 128, 0.16);
  }

  .card,
  .glass,
  .edge,
  .segmented-thumb {
    -webkit-backdrop-filter: none !important;
    backdrop-filter: none !important;
  }

  .ambient {
    background: var(--bg);
  }
}

@media (prefers-reduced-transparency: reduce) and (prefers-color-scheme: dark) {
  :root {
    --material: #1c1c1e;
    --glass: #2c2c2e;
    --glass-strong: #2c2c2e;
  }
}

@media (prefers-contrast: more) {
  :root {
    --label-2: rgba(60, 60, 67, 0.9);
    --label-3: rgba(60, 60, 67, 0.7);
    --separator: rgba(60, 60, 67, 0.45);
    --material: rgba(255, 255, 255, 0.92);
    --glass: rgba(255, 255, 255, 0.88);
  }

  .card,
  .glass {
    box-shadow: inset 0 0 0 1px var(--separator);
  }
}

@media (prefers-contrast: more) and (prefers-color-scheme: dark) {
  :root {
    --label-2: rgba(235, 235, 245, 0.9);
    --label-3: rgba(235, 235, 245, 0.7);
    --material: rgba(28, 28, 30, 0.95);
    --glass: rgba(44, 44, 46, 0.92);
  }
}

@supports not ((-webkit-backdrop-filter: blur(1px)) or (backdrop-filter: blur(1px))) {
  :root {
    --material: rgba(255, 255, 255, 0.92);
    --glass: rgba(250, 250, 250, 0.94);
  }
}
