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

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--background);
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
}

body {
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom)
    env(safe-area-inset-left);
}

#root {
  min-height: 100dvh;
}

button,
input,
textarea,
select {
  font-family: inherit;
}

a {
  color: inherit;
  text-decoration: none;
}

img {
  max-width: 100%;
  display: block;
}

button {
  border: 0;
  background: none;
  cursor: pointer;
  color: inherit;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.app-shell {
  min-height: 100dvh;
  background: var(--background);
}

.app-frame {
  width: 100%;
  margin: 0 auto;
  max-width: var(--max-app);
  min-height: 100dvh;
  position: relative;
}

@media (min-width: 768px) {
  .app-frame {
    max-width: 560px;
  }
}

@media (min-width: 1100px) {
  .app-shell--resident .app-frame {
    max-width: var(--max-desktop);
  }
}

.page {
  padding: calc(var(--safe-top) + 8px) var(--page-pad) calc(var(--nav-height) + var(--safe-bottom) + 24px);
  animation: page-in 0.28s ease;
}

@keyframes page-in {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 22px;
}

.page-header h1 {
  margin: 0;
  font-size: 28px;
  letter-spacing: -0.04em;
  font-weight: 700;
  line-height: 1.15;
}

.page-header .sub {
  margin: 6px 0 0;
  color: var(--text-secondary);
  font-size: 15px;
  font-weight: 400;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.icon-btn {
  width: 44px;
  height: 44px;
  min-width: 44px;
  border-radius: 50%;
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  display: grid;
  place-items: center;
  color: var(--text-primary);
}

.icon-btn:hover {
  transform: translateY(-1px);
}

.card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 18px;
}

.card-hover {
  transition: transform 0.18s ease, box-shadow 0.18s ease;
}

.card-hover:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

.card-hover:active {
  transform: translateY(0);
}

.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin: 28px 0 12px;
}

.section-head h2 {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.03em;
}

.link-green {
  color: var(--primary);
  font-size: 14px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 2px;
  min-height: 44px;
}

.token-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--surface);
  border-radius: var(--radius-pill);
  padding: 8px 12px 8px 8px;
  box-shadow: var(--shadow-sm);
  font-weight: 700;
  font-size: 14px;
  color: var(--text-primary);
  min-height: 44px;
  white-space: nowrap;
}

.token-badge--soft {
  background: var(--token-soft);
  box-shadow: none;
}

.token-coin {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #ffd56a, var(--token) 55%, #d4890c);
  display: grid;
  place-items: center;
  color: #fff;
  font-size: 11px;
  font-weight: 800;
  flex-shrink: 0;
}

.action-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.action-card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 16px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 92px;
  text-align: left;
  transition: transform 0.18s ease, box-shadow 0.18s ease;
}

.action-card:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

.action-card__body {
  min-width: 0;
  flex: 1;
}

.action-card__body strong {
  display: block;
  font-size: 15px;
  letter-spacing: -0.02em;
}

.action-card__body span {
  display: block;
  color: var(--text-secondary);
  font-size: 12px;
  margin-top: 2px;
}

.action-icon {
  width: 40px;
  height: 40px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.action-icon--green {
  background: var(--primary-soft);
  color: var(--primary);
}
.action-icon--red {
  background: var(--danger-soft);
  color: var(--danger);
}
.action-icon--purple {
  background: var(--purple-soft);
  color: var(--purple);
}
.action-icon--gold {
  background: var(--token-soft);
  color: #d4890c;
}

.chevron {
  color: var(--text-tertiary);
  flex-shrink: 0;
}

.meal-highlight {
  display: flex;
  gap: 14px;
  align-items: stretch;
  padding: 12px;
}

.meal-highlight img,
.meal-thumb {
  width: 86px;
  height: 86px;
  object-fit: cover;
  border-radius: 18px;
  background: var(--surface-secondary);
  flex-shrink: 0;
}

.meal-meta {
  min-width: 0;
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.meal-date {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text-secondary);
  font-size: 12px;
  margin-bottom: 4px;
}

.meal-meta h3 {
  margin: 0;
  font-size: 16px;
  letter-spacing: -0.03em;
}

.meal-meta p {
  margin: 2px 0 8px;
  color: var(--text-secondary);
  font-size: 13px;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  border-radius: var(--radius-pill);
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 700;
  width: fit-content;
}

.badge--success {
  background: var(--primary-soft);
  color: var(--primary);
}

.badge--popular {
  background: var(--primary-soft);
  color: var(--primary);
  margin-top: 6px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 52px;
  padding: 0 20px;
  border-radius: var(--radius-pill);
  font-weight: 700;
  font-size: 15px;
  letter-spacing: -0.02em;
  transition: transform 0.12s ease, background 0.12s ease, opacity 0.12s ease;
}

.btn:hover:not(:disabled) {
  transform: translateY(-1px);
}

.btn:active:not(:disabled) {
  transform: translateY(0);
}

.btn-dark {
  background: var(--dark-button);
  color: #fff;
  width: 100%;
}

.btn-dark:hover:not(:disabled) {
  background: #2c3038;
}

.btn-danger {
  background: var(--danger);
  color: #fff;
  width: 100%;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
  width: 100%;
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  width: 100%;
}

.btn-sm {
  min-height: 36px;
  padding: 0 14px;
  font-size: 13px;
}

.btn-loading {
  pointer-events: none;
}

.updates-card {
  padding: 6px 4px 8px;
}

.update-row {
  display: flex;
  gap: 12px;
  padding: 14px 14px;
  align-items: flex-start;
}

.update-row + .update-row {
  border-top: 1px solid var(--border);
}

.update-copy {
  min-width: 0;
  flex: 1;
}

.update-copy strong {
  display: block;
  font-size: 15px;
}

.update-copy p {
  margin: 2px 0 0;
  color: var(--text-secondary);
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.update-side {
  text-align: right;
  flex-shrink: 0;
  color: var(--text-tertiary);
  font-size: 12px;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--primary);
  display: inline-block;
  margin-top: 6px;
}

.count-badge {
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 50px;
  background: var(--primary);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  display: inline-grid;
  place-items: center;
  margin-top: 4px;
}

.avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--primary-soft);
  color: var(--primary);
  display: grid;
  place-items: center;
  font-weight: 700;
  flex-shrink: 0;
  overflow: hidden;
}

.avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.avatar--sm {
  width: 36px;
  height: 36px;
  font-size: 12px;
}

.avatar--lg {
  width: 88px;
  height: 88px;
  font-size: 28px;
}

.bottom-nav {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: 0;
  width: 100%;
  max-width: var(--max-app);
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(16px);
  border-top: 1px solid var(--border);
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  padding: 8px 8px calc(8px + var(--safe-bottom));
  z-index: 40;
}

@media (min-width: 768px) {
  .bottom-nav {
    max-width: 560px;
  }
}

@media (min-width: 1100px) {
  .app-shell--resident .bottom-nav {
    max-width: var(--max-desktop);
  }
}

.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  color: var(--text-tertiary);
  font-size: 11px;
  font-weight: 600;
  min-height: 44px;
  padding: 4px 0;
}

.nav-item.active {
  color: var(--primary);
}

.meal-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
}

.meal-row + .meal-row {
  border-top: 1px solid var(--border);
}

.cal-icon {
  width: 42px;
  height: 42px;
  border-radius: 14px;
  background: var(--primary-soft);
  color: var(--primary);
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 16px;
}

.field label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
}

.input {
  width: 100%;
  min-height: 52px;
  border: 0;
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  border-radius: var(--radius-md);
  padding: 0 16px;
  font-size: 16px;
  color: var(--text-primary);
}

.input:focus {
  outline: 2px solid var(--primary-soft);
  box-shadow: 0 0 0 3px rgba(22, 155, 98, 0.18);
}

.sheet-backdrop,
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: var(--overlay);
  z-index: 60;
  animation: fade-in 0.2s ease;
}

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

.bottom-sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  margin: 0 auto;
  max-width: var(--max-app);
  background: var(--surface);
  border-radius: 28px 28px 0 0;
  padding: 12px 20px calc(24px + var(--safe-bottom));
  z-index: 61;
  animation: sheet-up 0.28s ease;
  box-shadow: var(--shadow-lg);
}

@keyframes sheet-up {
  from {
    transform: translateY(24px);
    opacity: 0.6;
  }
  to {
    transform: none;
    opacity: 1;
  }
}

.sheet-handle {
  width: 40px;
  height: 4px;
  border-radius: 4px;
  background: #ddd;
  margin: 6px auto 16px;
}

.modal {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(92vw, 400px);
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 24px;
  z-index: 62;
  animation: fade-in 0.2s ease;
  box-shadow: var(--shadow-lg);
}

.toast-stack {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(var(--nav-height) + 16px + var(--safe-bottom));
  z-index: 80;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: min(92vw, 400px);
}

.toast {
  background: var(--dark-button);
  color: #fff;
  border-radius: 16px;
  padding: 12px 16px;
  font-size: 14px;
  font-weight: 600;
  box-shadow: var(--shadow-md);
  animation: sheet-up 0.2s ease;
}

.skeleton {
  background: linear-gradient(90deg, #ececea 25%, #f6f6f4 37%, #ececea 63%);
  background-size: 400% 100%;
  animation: shimmer 1.2s ease infinite;
  border-radius: 12px;
}

@keyframes shimmer {
  0% {
    background-position: 100% 0;
  }
  100% {
    background-position: 0 0;
  }
}

.empty {
  text-align: center;
  padding: 36px 16px;
  color: var(--text-secondary);
}

.empty h3 {
  margin: 12px 0 6px;
  color: var(--text-primary);
}

.chat-page {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  background: var(--background);
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 12px 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.bubble {
  max-width: 78%;
  padding: 10px 14px;
  border-radius: 18px;
  font-size: 15px;
  line-height: 1.4;
}

.bubble--them {
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  border-bottom-left-radius: 6px;
  align-self: flex-start;
}

.bubble--me {
  background: var(--primary);
  color: #fff;
  border-bottom-right-radius: 6px;
  align-self: flex-end;
}

.bubble--system {
  align-self: center;
  background: transparent;
  color: var(--text-secondary);
  font-size: 12px;
  text-align: center;
  max-width: 90%;
}

.chat-composer {
  display: flex;
  gap: 8px;
  padding: 10px 16px calc(12px + var(--safe-bottom));
  background: var(--surface);
  border-top: 1px solid var(--border);
}

.chat-composer input {
  flex: 1;
  min-height: 44px;
  border-radius: var(--radius-pill);
  background: var(--background);
  border: 0;
  padding: 0 16px;
  font-size: 16px;
}

.send-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  display: grid;
  place-items: center;
}

.package-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 18px;
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  margin-bottom: 10px;
  border: 2px solid transparent;
}

.package-card.selected {
  border-color: var(--primary);
  background: #f4fbf7;
}

.package-card strong {
  display: block;
  font-size: 16px;
}

.balance-card {
  padding: 20px;
}

.balance-card .label {
  color: var(--text-secondary);
  font-size: 13px;
  margin-bottom: 10px;
}

.balance-row {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 28px;
  font-weight: 800;
  letter-spacing: -0.04em;
}

.info-list {
  padding: 4px 16px;
}

.info-row {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 52px;
}

.info-row + .info-row {
  border-top: 1px solid var(--border);
}

.info-row span {
  color: var(--text-secondary);
  flex: 1;
}

.info-row b {
  font-weight: 600;
}

.hero-image {
  width: 100%;
  aspect-ratio: 16 / 11;
  object-fit: cover;
  border-radius: var(--radius-lg);
  margin: 8px 0 16px;
}

.profile-menu {
  overflow: hidden;
  padding: 4px 0;
}

.profile-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  width: 100%;
  text-align: left;
  min-height: 52px;
}

.profile-item + .profile-item {
  border-top: 1px solid var(--border);
}

.tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  background: var(--surface);
  border-radius: var(--radius-pill);
  padding: 4px;
  box-shadow: var(--shadow-sm);
  margin-bottom: 16px;
}

.tabs button {
  min-height: 40px;
  border-radius: var(--radius-pill);
  font-weight: 700;
  color: var(--text-secondary);
}

.tabs button.active {
  background: var(--primary-soft);
  color: var(--primary);
}

.tx-amount {
  font-weight: 800;
}

.tx-amount.credit {
  color: var(--primary);
}

.tx-amount.debit {
  color: var(--text-primary);
}

.login-page {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 32px 24px;
  max-width: 430px;
  margin: 0 auto;
}

.brand-mark {
  width: 64px;
  height: 64px;
  border-radius: 20px;
  background: var(--primary-soft);
  color: var(--primary);
  display: grid;
  place-items: center;
  margin-bottom: 20px;
}

.desktop-home {
  display: block;
}

@media (min-width: 1100px) {
  .desktop-home {
    display: grid;
    grid-template-columns: 1.4fr 0.9fr;
    gap: 28px;
    align-items: start;
  }

  .page {
    padding-left: 32px;
    padding-right: 32px;
  }
}

.admin-shell {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: 100dvh;
  background: var(--background);
}

.admin-side {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 24px 16px;
}

.admin-side a,
.admin-side button.navlink {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 12px;
  color: var(--text-secondary);
  font-weight: 600;
  width: 100%;
  text-align: left;
  min-height: 44px;
}

.admin-side a.active {
  background: var(--primary-soft);
  color: var(--primary);
}

.admin-main {
  padding: 28px 32px 48px;
  overflow: auto;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
}

.stat-card h3 {
  margin: 0;
  font-size: 13px;
  color: var(--text-secondary);
  font-weight: 600;
}

.stat-card p {
  margin: 8px 0 0;
  font-size: 28px;
  font-weight: 800;
  letter-spacing: -0.04em;
}

.table {
  width: 100%;
  border-collapse: collapse;
}

.table th {
  text-align: left;
  font-size: 12px;
  color: var(--text-secondary);
  font-weight: 600;
  padding: 10px 12px;
}

.table td {
  padding: 12px;
  border-top: 1px solid var(--border);
  font-size: 14px;
}

.bar-chart {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  height: 140px;
}

.bar-chart .bar {
  flex: 1;
  background: var(--primary-soft);
  border-radius: 8px 8px 4px 4px;
  position: relative;
  min-height: 6px;
}

.bar-chart .bar span {
  position: absolute;
  inset: auto 0 0 0;
  background: var(--primary);
  border-radius: 8px 8px 4px 4px;
}

@media (max-width: 900px) {
  .admin-shell {
    grid-template-columns: 1fr;
  }

  .admin-side {
    display: flex;
    overflow-x: auto;
    gap: 4px;
    padding: 12px;
  }

  .stats-grid {
    grid-template-columns: 1fr 1fr;
  }
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}
