/* ── Reset & Base ─────────────────────────────────────────── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0; padding: 0;
  -webkit-tap-highlight-color: transparent;
}
html {
  -webkit-text-size-adjust: 100%;
  height: 100%;
}
body {
  font-family: 'DM Sans', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
  overscroll-behavior: none;
}

/* ── Design Tokens ────────────────────────────────────────── */
:root {
  --bg:         #F4F1ED;
  --surface:    #FDFCFB;
  --border:     #E5DFD8;
  --text:       #1C1917;
  --muted:      #78716C;
  --disabled:   #C4BDB5;
  --accent:     #C2410C;
  --accent-lt:  #FFF1EC;
  --green:      #15803D;
  --green-lt:   #F0FDF4;
  --red:        #DC2626;
  --red-lt:     #FEF2F2;
  --amber:      #D97706;
  --radius-card: 14px;
  --radius-btn:  10px;
  --shadow-card: 0 1px 4px rgba(0,0,0,.07), 0 0 0 1px var(--border);
}

/* ── Scrollbar ────────────────────────────────────────────── */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

/* ── Header ───────────────────────────────────────────────── */
#app-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 14px 3vw;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  gap: 16px;
}
.header-left { display: flex; flex-direction: column; gap: 2px; }
.header-title {
  font-family: 'Lora', Georgia, serif;
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.3px;
  line-height: 1.2;
}
.header-date {
  font-size: 13px;
  color: var(--muted);
  font-weight: 400;
}
.header-right { display: flex; align-items: center; gap: 10px; }

/* Status dot */
.status-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--disabled);
  flex-shrink: 0;
  transition: background .3s;
}
.status-dot.online  { background: var(--green); animation: pulse-dot 2.5s ease-in-out infinite; }
.status-dot.offline { background: var(--red); }
@keyframes pulse-dot {
  0%,100% { opacity: 1; transform: scale(1); }
  50%      { opacity: .5; transform: scale(.8); }
}

/* Refresh button */
.refresh-btn {
  display: flex; align-items: center; gap: 6px;
  background: var(--text); color: #fff;
  border: none; border-radius: var(--radius-btn);
  padding: 9px 16px;
  font-family: inherit; font-size: 13px; font-weight: 500;
  cursor: pointer;
  transition: opacity .15s;
}
.refresh-btn:active { opacity: .7; }
.refresh-btn svg { transition: transform .4s; }
.refresh-btn.loading svg { animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Main scroll area ─────────────────────────────────────── */
#main-content {
  flex: 1;
  overflow-y: auto;
  padding: 18px 3vw 32px;
  overscroll-behavior: contain;
}

/* ── State messages ───────────────────────────────────────── */
.state-msg {
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 12px;
  margin-top: 60px; text-align: center;
}
.state-msg p { font-size: 15px; color: var(--muted); line-height: 1.5; }
.state-msg.error p { color: var(--red); }
.state-msg svg { color: var(--disabled); }
.retry-btn {
  margin-top: 6px;
  background: var(--text); color: #fff;
  border: none; border-radius: var(--radius-btn);
  padding: 10px 22px;
  font-family: inherit; font-size: 14px; font-weight: 500;
  cursor: pointer;
}

/* ── Time section ─────────────────────────────────────────── */
.time-section { margin-bottom: 28px; }
.time-section:last-child { margin-bottom: 0; }

.time-label {
  display: flex; align-items: center; gap: 8px;
  font-size: 11px; font-weight: 600;
  letter-spacing: .9px; text-transform: uppercase;
  color: var(--muted); margin-bottom: 10px;
}
.time-section.past .time-label { color: var(--disabled); }

.now-badge {
  display: inline-flex; align-items: center;
  padding: 2px 9px; border-radius: 100px;
  background: var(--green); color: #fff;
  font-size: 10px; font-weight: 700; letter-spacing: .4px;
  text-transform: uppercase;
}
.past-badge {
  display: inline-flex; align-items: center;
  padding: 2px 9px; border-radius: 100px;
  background: var(--bg); color: var(--disabled);
  font-size: 10px; font-weight: 600;
  border: 1px solid var(--border);
}

/* ── Meals grid ───────────────────────────────────────────── */
.meals-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(47vw, 420px), 1fr));
  gap: 10px;
}

/* ── Meal card ────────────────────────────────────────────── */
.meal-card {
  background: var(--surface);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  padding: 16px 18px;
  display: flex; flex-direction: column; gap: 10px;
  animation: fadeUp .22s ease both;
}
.no-animate .meal-card { animation: none !important; }
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}
.meal-card:nth-child(1) { animation-delay: .03s; }
.meal-card:nth-child(2) { animation-delay: .07s; }
.meal-card:nth-child(3) { animation-delay: .11s; }
.meal-card:nth-child(4) { animation-delay: .15s; }
.meal-card.expired { opacity: .4; }

.meal-info { flex: 1; }
.meal-name {
  font-family: 'Lora', Georgia, serif;
  font-size: 17px; font-weight: 600;
  line-height: 1.35; color: var(--text);
  margin-bottom: 4px;
}
.meal-desc {
  font-size: 13px; color: var(--muted);
  font-weight: 400; line-height: 1.5;
}

/* Feedback button */
.feedback-btn {
  width: 100%;
  background: var(--accent-lt);
  color: var(--accent);
  border: 1px solid rgba(194,65,12,.14);
  border-radius: var(--radius-btn);
  padding: 10px 14px;
  font-family: inherit; font-size: 14px; font-weight: 600;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center; gap: 6px;
  transition: background .12s;
}
.feedback-btn:active { background: #FFE5D9; }
.feedback-btn svg { flex-shrink: 0; }

.card-tag {
  font-size: 12px; font-weight: 500;
  color: var(--disabled); background: var(--bg);
  border: 1px solid var(--border); border-radius: 8px;
  padding: 8px 14px; text-align: center;
}

/* ── Skeleton ─────────────────────────────────────────────── */
.skeleton {
  background: linear-gradient(90deg, var(--border) 25%, #EDE8E1 50%, var(--border) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
  border-radius: 6px;
}
@keyframes shimmer { to { background-position: -200% 0; } }

/* ── Overlay backdrop ─────────────────────────────────────── */
#sheet-overlay {
  position: fixed; inset: 0;
  background: rgba(15,10,5,.42);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  z-index: 100;
  display: flex; align-items: flex-end; justify-content: center;
  opacity: 0; pointer-events: none;
  transition: opacity .2s;
  padding-bottom: env(safe-area-inset-bottom, 0);
}
#sheet-overlay.open { opacity: 1; pointer-events: all; }
#sheet-overlay.open .sheet { transform: translateY(0); }

/* ── Bottom sheet ─────────────────────────────────────────── */
.sheet {
  background: var(--surface);
  border-radius: 20px 20px 0 0;
  width: 100%; max-width: 100%;
  padding: 0 0 28px;
  box-shadow: 0 -4px 32px rgba(0,0,0,.12);
  transform: translateY(100%);
  transition: transform .28s cubic-bezier(.32,1,.6,1);
  max-height: 88dvh;
  overflow-y: auto;
}
.sheet-handle {
  width: 32px; height: 4px;
  background: var(--border); border-radius: 2px;
  margin: 12px auto 0;
}
.sheet-header {
  padding: 16px 4vw 0;
  display: flex; align-items: flex-start;
  justify-content: space-between; gap: 14px;
}
.sheet-title-wrap { flex: 1; }
.sheet-label {
  font-size: 11px; font-weight: 600;
  letter-spacing: .9px; text-transform: uppercase;
  color: var(--muted); margin-bottom: 4px;
}
.sheet-meal-name {
  font-family: 'Lora', Georgia, serif;
  font-size: 19px; font-weight: 600;
  color: var(--text); line-height: 1.3;
}
.close-btn {
  background: var(--bg); border: 1px solid var(--border);
  border-radius: 50%; width: 32px; height: 32px;
  font-size: 14px; cursor: pointer; color: var(--muted);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; margin-top: 2px;
  transition: background .12s;
}
.close-btn:active { background: var(--border); }

.sheet-divider { height: 1px; background: var(--border); margin: 16px 4vw; }
.sheet-body { padding: 0 4vw; }

/* ── Section label ────────────────────────────────────────── */
.section-label {
  font-size: 11px; font-weight: 600;
  letter-spacing: .8px; text-transform: uppercase;
  color: var(--muted); margin-bottom: 10px;
}

/* ── Grade / Score row ────────────────────────────────────── */
.score-row {
  display: flex; gap: 7px;
  margin-bottom: 6px;
}
.score-btn {
  flex: 1; height: 50px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  font-family: 'Lora', Georgia, serif;
  font-size: 19px; font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  transition: all .12s;
  display: flex; align-items: center; justify-content: center;
}
.score-btn:active { transform: scale(.93); }
.score-btn.selected { color: #fff; border-color: transparent; }

.grade-display {
  display: flex; align-items: center; gap: 8px;
  margin-bottom: 20px; height: 22px;
  animation: fadeIn .2s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.grade-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.grade-text { font-size: 13px; font-weight: 600; }

/* ── Yes/No toggle buttons ────────────────────────────────── */
.yn-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 20px;
}
.yn-item {
  border-radius: 10px;
  padding: 11px 14px;
  display: flex; flex-direction: column; gap: 6px;
  cursor: pointer;
  transition: all .15s;
  -webkit-tap-highlight-color: transparent;
}
.yn-item-label {
  font-size: 12px; font-weight: 500;
  color: var(--muted); line-height: 1.3;
}
.yn-buttons { display: flex; gap: 6px; }

/* The Y/N button IS the answer */
.yn-btn {
  flex: 1; padding: 8px 6px;
  border-radius: 8px;
  font-family: inherit; font-size: 13px; font-weight: 600;
  cursor: pointer;
  border: 1.5px solid var(--border);
  background: var(--bg);
  color: var(--muted);
  transition: all .15s;
  display: flex; align-items: center; justify-content: center; gap: 4px;
}
.yn-btn:active { transform: scale(.95); }

/* Active states */
.yn-btn.yes-active {
  background: var(--green);
  border-color: var(--green);
  color: #fff;
}
.yn-btn.no-active {
  background: var(--red);
  border-color: var(--red);
  color: #fff;
}

/* ── Comment field ────────────────────────────────────────── */
.comment-wrap { margin-bottom: 20px; }
.comment-field {
  width: 100%;
  background: var(--bg);
  border: 1.5px solid var(--border);
  border-radius: 10px;
  padding: 11px 14px;
  font-family: inherit; font-size: 14px; color: var(--text);
  resize: none; outline: none;
  transition: border-color .15s;
  line-height: 1.5;
}
.comment-field::placeholder { color: var(--disabled); }
.comment-field:focus { border-color: var(--accent); }

/* ── Submit button ────────────────────────────────────────── */
.submit-btn {
  width: 100%;
  background: var(--border); color: var(--disabled);
  border: none; border-radius: 12px;
  padding: 15px;
  font-family: inherit; font-size: 15px; font-weight: 600;
  cursor: default;
  transition: background .2s, color .2s;
  letter-spacing: .2px;
  display: flex; align-items: center; justify-content: center; gap: 8px;
}
.submit-btn.ready {
  background: var(--accent); color: #fff;
  cursor: pointer;
}
.submit-btn.ready:active { opacity: .82; }
.submit-btn.sending { opacity: .6; cursor: default; }
.submit-btn svg { flex-shrink: 0; }

/* ── Success overlay ──────────────────────────────────────── */
#success-overlay {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(15,10,5,.78);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  display: flex; align-items: center; justify-content: center;
  opacity: 0; pointer-events: none;
  transition: opacity .25s;
}
#success-overlay.show { opacity: 1; pointer-events: all; }
.success-inner { text-align: center; }
.success-circle {
  stroke-dasharray: 251.3; stroke-dashoffset: 251.3;
  animation: draw-circle .6s ease-out .1s forwards;
}
.success-check {
  stroke-dasharray: 60; stroke-dashoffset: 60;
  animation: draw-check .35s ease-out .6s forwards;
}
@keyframes draw-circle { to { stroke-dashoffset: 0; } }
@keyframes draw-check  { to { stroke-dashoffset: 0; } }
.success-text {
  opacity: 0;
  animation: fade-up .4s ease-out .85s forwards;
}
@keyframes fade-up {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}
.success-title {
  font-family: 'Lora', Georgia, serif;
  font-size: 28px; font-weight: 600;
  color: #fff; margin-top: 18px;
}
.success-sub {
  font-size: 14px; color: rgba(255,255,255,.55);
  margin-top: 6px; font-weight: 400;
}

/* ── Toast ────────────────────────────────────────────────── */
#toast {
  position: fixed; top: 20px; left: 50%;
  transform: translateX(-50%) translateY(-8px);
  background: var(--text); color: #fff;
  padding: 11px 22px; border-radius: 100px;
  font-size: 14px; font-weight: 500;
  opacity: 0; pointer-events: none; z-index: 300;
  transition: opacity .2s, transform .2s;
  white-space: nowrap;
  display: flex; align-items: center; gap: 8px;
}
#toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
#toast.error { background: var(--red); }

/* ── Reduced motion ───────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    transition-duration: .01ms !important;
  }
}
