/* Reusable app components. */

/* Icons */
.i { width: 22px; height: 22px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.i--sm { width: 18px; height: 18px; }
.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }

/* App bar */
.app-bar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: var(--s2);
  min-height: calc(var(--appbar-h) + var(--safe-top));
  padding: var(--safe-top) var(--s3) 0;
  background: var(--brand); color: var(--on-brand);
}
.app-bar__title { flex: 1; min-width: 0; font-size: var(--text-lg); font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.app-bar__brand { display: flex; align-items: center; gap: var(--s2); flex: 1; min-width: 0; color: inherit; font-weight: 700; }
.app-bar__brand img { width: 32px; height: 32px; border-radius: 9px; }
.icon-btn {
  display: inline-grid; place-items: center; width: 44px; height: 44px; padding: 0;
  color: inherit; background: transparent; border: 0; border-radius: var(--r-pill); cursor: pointer;
}
.icon-btn:active { background: rgba(255, 255, 255, .18); }
.lang-chip {
  display: inline-flex; align-items: center; min-height: 32px; padding: 0 12px;
  font-size: var(--text-xs); font-weight: 700; color: inherit;
  border: 1.5px solid rgba(255, 255, 255, .55); border-radius: var(--r-pill);
}

/* Page container */
.page { width: 100%; max-width: 560px; margin: 0 auto; padding: var(--s4) var(--s4) calc(var(--s8) + var(--safe-bottom)); display: grid; gap: var(--s4); align-content: start; }
.page--tabs { padding-bottom: calc(var(--tabbar-h) + var(--s8) + var(--safe-bottom)); }
.page--wide { max-width: 1040px; }
@media (min-width: 900px) { .page { padding-top: var(--s6); } }

.section-title { display: flex; align-items: baseline; justify-content: space-between; gap: var(--s3); margin-top: var(--s2); }
.section-title h2 { font-size: var(--text-lg); }
.section-title span, .section-title a { font-size: var(--text-sm); color: var(--muted); }
.section-title a { color: var(--brand); font-weight: 600; }
.eyebrow { font-size: var(--text-xs); font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--brand-dark); }
.muted { color: var(--muted); }

/* Bottom tab bar */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: grid; grid-auto-flow: column; grid-auto-columns: 1fr;
  height: calc(var(--tabbar-h) + var(--safe-bottom)); padding-bottom: var(--safe-bottom);
  background: var(--surface); border-top: 1px solid var(--line); box-shadow: var(--shadow-up);
}
.tabbar a, .tabbar button {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  padding: 0; font-size: 11px; font-weight: 600; color: var(--muted);
  background: none; border: 0; cursor: pointer;
}
.tabbar .active { color: var(--brand); }
.tabbar .active .i { stroke-width: 2.4; }
@media (min-width: 900px) { .tabbar { left: 50%; right: auto; width: 560px; transform: translateX(-50%); border-radius: var(--r-lg) var(--r-lg) 0 0; border: 1px solid var(--line); border-bottom: 0; } }

/* Cards & lists */
.card { padding: var(--s4); background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: var(--shadow); }
.card--flat { box-shadow: none; }
.card > * + * { margin-top: var(--s3); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: var(--s3); }
.stack { display: grid; gap: var(--s3); }
.row { display: flex; align-items: center; gap: var(--s3); flex-wrap: wrap; }
.row--between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }

.list { display: grid; gap: var(--s2); }
.list-item {
  display: flex; align-items: center; gap: var(--s3);
  padding: var(--s3) var(--s4); background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--r-md);
}
.list-item__body { flex: 1; min-width: 0; }
.list-item__body strong { display: block; }
.list-item__body small { display: block; }
.list-item__end { text-align: right; font-weight: 700; white-space: nowrap; }
.list-item__end.credit { color: var(--ok); }
.list-item__end.debit { color: var(--danger); }
.group-label { margin-top: var(--s2); font-size: var(--text-sm); font-weight: 700; color: var(--muted); }

.date-chip { display: grid; place-items: center; width: 48px; height: 52px; flex: none; background: var(--brand-soft); color: var(--brand-dark); border-radius: var(--r-md); line-height: 1.1; }
.date-chip b { font-size: var(--text-lg); }
.date-chip span { font-size: 11px; font-weight: 600; }

.empty { display: grid; justify-items: center; gap: var(--s2); padding: var(--s8) var(--s4); text-align: center; color: var(--muted); background: var(--surface); border: 1.5px dashed var(--line); border-radius: var(--r-lg); }
.empty .i { width: 36px; height: 36px; }

/* Stat tiles */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--s2); }
.stats--2 { grid-template-columns: repeat(2, 1fr); }
.stat { padding: var(--s3); background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); }
.stat span { display: block; font-size: var(--text-xs); color: var(--muted); }
.stat strong { display: block; font-size: var(--text-xl); line-height: 1.2; }
.stat small { display: block; margin-top: 2px; }
.stat--brand { background: var(--brand); border-color: var(--brand); color: var(--on-brand); }
.stat--brand span, .stat--brand small { color: inherit; opacity: .85; }
.stats--4 { grid-template-columns: repeat(2, 1fr); }
@media (min-width: 640px) { .stats--4 { grid-template-columns: repeat(4, 1fr); } }

/* Balance hero */
.balance { display: flex; align-items: center; justify-content: space-between; gap: var(--s3); padding: var(--s4) var(--s5); color: var(--on-brand); background: linear-gradient(145deg, var(--brand), var(--brand-dark)); border-radius: var(--r-lg); box-shadow: var(--shadow); }
.balance span { display: block; font-size: var(--text-sm); opacity: .85; }
.balance strong { display: block; font-size: 1.9rem; line-height: 1.15; }
.balance .btn { flex: none; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s2);
  min-height: var(--tap); padding: 0 var(--s5);
  font-weight: 700; text-align: center; color: var(--on-brand); background: var(--brand);
  border: 1.5px solid var(--brand); border-radius: var(--r-md); cursor: pointer;
}
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .55; cursor: default; }
.btn--secondary { color: var(--brand); background: transparent; }
.btn--danger { color: var(--danger); background: transparent; border-color: var(--danger); }
.btn--light { color: var(--brand-dark); background: var(--surface); border-color: var(--surface); }
.btn--block { width: 100%; }
.btn--sm { min-height: 40px; padding: 0 var(--s4); font-size: var(--text-sm); }
.btn-row { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s2); }

/* Chips & segmented controls (radio inputs styled as buttons) */
.chips { display: flex; gap: var(--s2); overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; scroll-snap-type: x proximity; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; scroll-snap-align: start; }
.chip input, .segmented input { position: absolute; opacity: 0; pointer-events: none; }
.chip span {
  display: inline-flex; align-items: center; min-height: 40px; padding: 0 var(--s4);
  font-size: var(--text-sm); font-weight: 600; white-space: nowrap;
  background: var(--surface); border: 1.5px solid var(--line); border-radius: var(--r-pill); cursor: pointer;
}
.chip input:checked + span { color: var(--on-brand); background: var(--brand); border-color: var(--brand); }
.chip input:focus-visible + span, .segmented input:focus-visible + span { outline: 3px solid var(--accent); outline-offset: 2px; }

.segmented { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; padding: 4px; background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--r-md); }
.segmented label { position: relative; }
.segmented span { display: flex; align-items: center; justify-content: center; gap: 6px; min-height: 40px; font-size: var(--text-sm); font-weight: 600; color: var(--muted); border-radius: var(--r-sm); cursor: pointer; }
.segmented input:checked + span { color: var(--brand-dark); background: var(--surface); box-shadow: 0 1px 4px rgba(74, 42, 29, .15); }

/* Status badges */
.badge { display: inline-flex; align-items: center; padding: 2px 10px; font-size: var(--text-xs); font-weight: 700; white-space: nowrap; color: var(--brand-dark); background: var(--brand-soft); border-radius: var(--r-pill); }
.badge--ok, .badge.status-scheduled, .badge.status-active, .badge.status-successful, .badge.status-delivered, .badge.status-approved { color: var(--ok); background: var(--ok-bg); }
.badge--warn, .badge.status-payment_required, .badge.status-pending, .badge.status-created { color: var(--warn); background: var(--warn-bg); }
.badge--danger, .badge.status-paused, .badge.status-cancelled, .badge.status-failed, .badge.status-rejected, .badge.status-expired { color: var(--danger); background: var(--danger-bg); }
.badge.status-locked { color: var(--neutral); background: var(--neutral-bg); }

/* Toggle card (meal on/off) */
.toggle-card { display: flex; align-items: center; gap: var(--s3); padding: var(--s4); background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); }
.toggle-card__icon { display: grid; place-items: center; width: 44px; height: 44px; flex: none; color: var(--accent); background: var(--brand-soft); border-radius: var(--r-pill); }
.toggle-card.is-off { background: var(--surface-2); }
.toggle-card.is-off .toggle-card__icon { color: var(--muted); background: var(--neutral-bg); }

/* Notices */
.notice { padding: var(--s3) var(--s4); font-size: var(--text-sm); color: var(--warn); background: var(--warn-bg); border-radius: var(--r-md); }

/* Bottom sheet & dialog (native <dialog>) */
dialog { max-width: none; max-height: none; padding: 0; color: var(--ink); background: var(--surface); border: 0; }
dialog::backdrop { background: var(--overlay); }
.sheet { position: fixed; inset: auto 0 0 0; width: 100%; max-height: 90dvh; margin: 0; overflow-y: auto; border-radius: var(--r-lg) var(--r-lg) 0 0; padding-bottom: var(--safe-bottom); animation: sheet-up .22s ease-out; }
.sheet__grip { width: 40px; height: 4px; margin: var(--s2) auto 0; background: var(--line); border-radius: 4px; }
.sheet__head { display: flex; align-items: center; justify-content: space-between; padding: var(--s2) var(--s4) 0 var(--s5); }
.sheet__body { display: grid; gap: var(--s4); padding: var(--s3) var(--s5) var(--s6); }
@media (min-width: 640px) { .sheet { inset: auto; top: 50%; left: 50%; width: 480px; transform: translate(-50%, -50%); border-radius: var(--r-lg); animation: none; } }
@keyframes sheet-up { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }

.confirm { width: min(92vw, 380px); margin: auto; padding: var(--s5); border-radius: var(--r-lg); }
.confirm > * + * { margin-top: var(--s3); }
.rules-list { display: grid; gap: var(--s2); padding: 0; margin: 0; list-style: none; }
.rules-list li { display: flex; align-items: center; gap: var(--s3); padding: var(--s3); background: var(--brand-soft); border-radius: var(--r-md); }
.rules-list .i { color: var(--brand); flex: none; }
.zone-fields { display: grid; gap: var(--s3); }
.sheet-link { display: flex; align-items: center; gap: var(--s3); min-height: var(--tap); font-weight: 600; color: var(--ink); }
.sheet-link .i { color: var(--brand); }

/* Toasts */
.toast { position: fixed; left: var(--s4); right: var(--s4); bottom: calc(var(--tabbar-h) + var(--s4) + var(--safe-bottom)); z-index: 50; max-width: 520px; margin: 0 auto; padding: var(--s3) var(--s4); font-weight: 600; color: #fff; border-radius: var(--r-md); box-shadow: var(--shadow); animation: sheet-up .2s ease-out; }
.toast--ok { background: #356b4d; }
.toast--error { background: #9d3835; }

/* Search suggestions */
.suggestions { display: grid; border: 1px solid var(--line); border-radius: var(--r-md); overflow: hidden; }
.suggestions button { display: grid; gap: 2px; padding: var(--s3) var(--s4); text-align: left; background: var(--surface); border: 0; border-bottom: 1px solid var(--line); cursor: pointer; }
.suggestions button:last-child { border-bottom: 0; }

/* Key/value list */
.kv { display: grid; grid-template-columns: auto 1fr; gap: var(--s2) var(--s4); font-size: var(--text-sm); }
.kv dt { color: var(--muted); }
.kv dd { overflow-wrap: anywhere; text-align: right; }

/* Disclosure */
details.card > summary, details.more > summary { display: flex; align-items: center; justify-content: space-between; min-height: 40px; font-weight: 700; cursor: pointer; list-style: none; }
details > summary::-webkit-details-marker { display: none; }
details > summary::after { content: "+"; font-size: 1.3em; color: var(--brand); }
details[open] > summary::after { content: "-"; }
details.more > summary { font-size: var(--text-sm); color: var(--brand); }

.pager { display: flex; justify-content: space-between; gap: var(--s3); }

@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
