:root {
  --bg: #faf7f3;
  --card-bg: #ffffff;
  --primary: #ea580c;
  --primary-dark: #c2410c;
  --primary-soft: #fef1e6;
  --primary-soft-strong: #fde0c4;
  --text: #241f1a;
  --text-muted: #7a746c;
  --border: #e9e3db;
  --green: #16a34a;
  --green-soft: #e8f7ec;
  --shadow: 0 1px 2px rgba(36, 31, 26, 0.04), 0 1px 8px rgba(36, 31, 26, 0.04);
  --radius-lg: 16px;
  --radius-md: 12px;
  --radius-sm: 9px;
}

/* Dark mode: theo hệ thống (mặc định, không set data-theme) HOẶC ép buộc qua nút
   Sáng/Tối/Hệ thống (đổi data-theme trên <html>). Đủ 3 trạng thái để nút bấm luôn
   thắng lựa chọn hệ điều hành khi người dùng chủ động chọn. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1a1613;
    --card-bg: #241f1a;
    --primary: #fb923c;
    --primary-dark: #fdba74;
    --primary-soft: #3a2a1a;
    --primary-soft-strong: #4a3420;
    --text: #f5f0ea;
    --text-muted: #a89d8f;
    --border: #3a332c;
    --green: #4ade80;
    --green-soft: #16321f;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 1px 10px rgba(0, 0, 0, 0.35);
  }
}
:root[data-theme="dark"] {
  --bg: #1a1613;
  --card-bg: #241f1a;
  --primary: #fb923c;
  --primary-dark: #fdba74;
  --primary-soft: #3a2a1a;
  --primary-soft-strong: #4a3420;
  --text: #f5f0ea;
  --text-muted: #a89d8f;
  --border: #3a332c;
  --green: #4ade80;
  --green-soft: #16321f;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 1px 10px rgba(0, 0, 0, 0.35);
}

* {
  box-sizing: border-box;
}

/* Accessibility: focus rõ ràng khi điều hướng bằng bàn phím (không dựa màu sắc), và
   tôn trọng "reduced motion" của hệ điều hành cho mọi hiệu ứng/animation trong app. */
:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

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

/* Cảm giác "app thật" khi chạm: mọi nút bấm hơi lún xuống lúc nhấn. Cố tình dùng
   selector element thuần (button, không phải .class) để specificity THẤP hơn mọi
   class cụ thể như .chip/.mode-btn — nếu không, rule chung này sẽ đè mất hẳn
   transition border-color/background/color riêng của .chip thay vì cộng thêm vào
   (transition là shorthand, "thắng" là thắng toàn bộ chứ không gộp từng vế). Nút
   :disabled trình duyệt vốn không bao giờ khớp :active nên không cần loại trừ riêng. */
button {
  transition: transform 0.12s ease;
}
button:active {
  transform: scale(0.96);
}

/* Các khối chỉ ẩn/hiện qua thuộc tính [hidden] (không phải đổi nội dung liên tục)
   tự nhiên phát lại animation mỗi lần rời display:none -> hiện, không cần JS. */
#dishListPanel,
#favoritesRow,
#historySection,
#resultsSection,
#foodResult {
  animation: fadeIn 0.2s ease;
}

@keyframes cardPop {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.food-card.is-revealing {
  animation: cardPop 0.28s ease;
}

/* Bắt buộc [hidden] luôn thắng, kể cả khi 1 class khác trên cùng phần tử có set
   display (vd .sheet-backdrop, .location-chip đều dùng display:flex) — nếu không có
   dòng này, các phần tử "hidden" bằng JS vẫn hiện ra do class ghi đè display. */
[hidden] {
  display: none !important;
}

body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Be Vietnam Pro", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

.app {
  max-width: 480px;
  margin: 0 auto;
  padding: 32px 16px calc(96px + env(safe-area-inset-bottom, 0px));
}

/* Header */
.app-header {
  text-align: center;
  margin-bottom: 28px;
  position: relative;
}

.header-toggles {
  display: flex;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
}

.lang-toggle {
  display: inline-flex;
  border: 1.5px solid var(--border);
  border-radius: 999px;
  padding: 2px;
  margin-bottom: 10px;
}

.lang-btn {
  border: none;
  background: none;
  font-family: inherit;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--text-muted);
  padding: 5px 12px;
  border-radius: 999px;
}

.lang-btn.is-active {
  background: var(--primary-soft);
  color: var(--primary-dark);
}

.brand {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.brand-badge {
  font-size: 1.3rem;
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--primary-soft);
  border-radius: 9px;
}

.app-header h1 {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 800;
  letter-spacing: -0.01em;
}

.subtitle {
  margin: 6px 0 0;
  color: var(--text-muted);
  font-size: 0.82rem;
  font-weight: 500;
  letter-spacing: 0.01em;
}

/* Card */
.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}

.card h2 {
  margin: 0 0 16px;
  font-size: 0.98rem;
  font-weight: 700;
  color: var(--text);
}

.card h2 .hint {
  font-weight: 500;
  color: var(--text-muted);
  font-size: 0.8rem;
}

/* Location */
.location-chip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--primary-soft);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 0.88rem;
  font-weight: 600;
  margin-bottom: 14px;
}

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

.mode-btn {
  flex: 1;
  min-width: 150px;
  padding: 12px 10px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--border);
  background: var(--card-bg);
  color: var(--text);
  font-weight: 600;
  font-size: 0.88rem;
  font-family: inherit;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease, transform 0.12s ease;
}

.mode-btn:hover {
  border-color: var(--primary);
  background: var(--primary-soft);
}

.mode-btn.is-active {
  border-color: var(--primary);
  background: var(--primary-soft);
  color: var(--primary-dark);
}

.region-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
  margin-bottom: 4px;
}

.region-row select {
  width: 100%;
  min-width: 0;
  padding: 10px 6px;
  font-size: 0.8rem;
}

.divider {
  display: flex;
  align-items: center;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.75rem;
  margin: 14px 0 10px;
}

.divider::before,
.divider::after {
  content: "";
  flex: 1;
  border-bottom: 1px solid var(--border);
}

.divider span {
  padding: 0 10px;
}

.address-row {
  display: flex;
  gap: 8px;
}

.address-row input {
  flex: 1;
  min-width: 0;
}

input[type="text"],
select {
  padding: 11px 13px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.92rem;
  font-family: inherit;
  background: var(--card-bg);
  color: var(--text);
  transition: border-color 0.15s ease;
}

input[type="text"] {
  width: 100%;
}

input[type="text"]:focus,
select:focus {
  outline: none;
  border-color: var(--primary);
}

select {
  width: auto;
}

.suggestions {
  list-style: none;
  margin: 8px 0 0;
  padding: 0;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.suggestions li {
  padding: 11px 14px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  font-size: 0.88rem;
}

.suggestions li:last-child {
  border-bottom: none;
}

.suggestions li:hover {
  background: var(--bg);
}

.status-text {
  margin: 10px 0 0;
  font-size: 0.82rem;
  color: var(--text-muted);
  min-height: 1.1em;
  line-height: 1.5;
}

.link-note {
  cursor: default;
}

/* Chips */
.chip-group {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}

.filter-label {
  margin: 16px 0 0;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
}

.filter-label:first-of-type {
  margin-top: 0;
}

.chip {
  border: 1.5px solid var(--border);
  background: var(--card-bg);
  color: var(--text);
  font-family: inherit;
  font-size: 0.84rem;
  font-weight: 600;
  padding: 8px 14px;
  border-radius: 999px;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease, color 0.15s ease, transform 0.12s ease;
}

.chip:hover {
  border-color: var(--primary);
}

.chip.is-active {
  border-color: var(--primary);
  background: var(--primary-soft);
  color: var(--primary-dark);
}

.chip:disabled,
.chip.chip-disabled {
  opacity: 0.4;
  cursor: not-allowed;
  text-decoration: line-through;
}

.chip:disabled:hover,
.chip.chip-disabled:hover {
  border-color: var(--border);
}

.chip-toggle.is-active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.favorites-row {
  margin-top: 16px;
}

/* Buttons */
button {
  cursor: pointer;
  font-family: inherit;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  padding: 13px 16px;
  font-size: 0.95rem;
  font-weight: 700;
}

.btn-primary:hover {
  background: var(--primary-dark);
}

.btn-primary:disabled {
  background: var(--border);
  color: var(--text-muted);
  cursor: not-allowed;
}

.btn-lg {
  padding: 16px;
  font-size: 1.02rem;
}

.btn-wide {
  width: 100%;
}

.link-btn {
  background: none;
  border: none;
  color: var(--primary-dark);
  font-weight: 700;
  font-size: 0.86rem;
  padding: 4px;
}

.link-btn:hover {
  text-decoration: underline;
}

.reroll-link {
  display: block;
  width: 100%;
  text-align: center;
  margin-top: 12px;
  color: var(--text-muted);
}

.dish-list-toggle {
  display: block;
  width: 100%;
  text-align: center;
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.dish-list {
  list-style: none;
  margin: 12px 0 0;
  padding: 0;
  max-height: 360px;
  overflow-y: auto;
}

.dish-list-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 4px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  background: none;
  border-left: none;
  border-right: none;
  border-top: none;
  width: 100%;
  text-align: left;
  font-family: inherit;
}

.dish-list-item:last-child {
  border-bottom: none;
}

.dish-list-item:hover {
  background: var(--bg);
}

.dish-list-emoji {
  font-size: 1.4rem;
  flex-shrink: 0;
  width: 34px;
  text-align: center;
}

.dish-list-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.dish-list-name {
  display: block;
  font-weight: 700;
  font-size: 0.92rem;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.dish-list-meta {
  display: block;
  font-size: 0.78rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.dish-list-price {
  flex-shrink: 0;
  font-weight: 700;
  font-size: 0.85rem;
  color: var(--primary-dark);
  white-space: nowrap;
}

.button-row {
  margin-top: 14px;
}

/* Food card — hero image, chữ đè lên ảnh (kiểu card nhà hàng trên app giao đồ ăn) */
.pick-hint {
  margin: 0;
  text-align: center;
  color: var(--text-muted);
  padding: 12px 0;
}

.meal-greeting {
  margin: 0;
  text-align: center;
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--primary-dark);
  padding: 4px 0 0;
}

.food-card {
  position: relative;
  border-radius: var(--radius-md);
  overflow: hidden;
  background: var(--primary-soft);
  aspect-ratio: 4 / 3;
}

.food-image-wrap {
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, var(--primary-soft), var(--primary-soft-strong));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 4rem;
  overflow: hidden;
}

.food-image-wrap img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.food-scrim {
  position: absolute;
  inset: 0;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.72) 0%, rgba(0, 0, 0, 0.32) 42%, rgba(0, 0, 0, 0) 68%);
  pointer-events: none;
}

.food-actions-overlay {
  position: absolute;
  top: 12px;
  right: 12px;
  display: flex;
  gap: 8px;
  z-index: 2;
}

.icon-btn {
  width: 38px;
  height: 38px;
  border-radius: 999px;
  border: none;
  background: rgba(255, 255, 255, 0.92);
  font-size: 1.05rem;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
}

.icon-btn.is-active {
  background: var(--primary);
}

.icon-btn-plain {
  width: 32px;
  height: 32px;
  border-radius: 999px;
  border: none;
  background: var(--bg);
  color: var(--text-muted);
  font-size: 0.95rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

.food-info-overlay {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 16px;
  z-index: 1;
}

.food-category {
  margin: 0 0 2px;
  font-size: 0.78rem;
  font-weight: 700;
  color: rgba(255, 255, 255, 0.88);
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
}

.food-name {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 800;
  color: #fff;
  text-shadow: 0 1px 6px rgba(0, 0, 0, 0.3);
}

.food-price {
  margin: 4px 0 0;
  font-size: 1.05rem;
  font-weight: 800;
  color: #ffe4c4;
  text-shadow: 0 1px 6px rgba(0, 0, 0, 0.35);
}

.chip-row {
  display: flex;
  justify-content: flex-start;
  flex-wrap: wrap;
  gap: 6px;
  margin: 8px 0 0;
}

.tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: rgba(255, 255, 255, 0.88);
  border: none;
  color: var(--text);
  font-size: 0.76rem;
  font-weight: 700;
  padding: 5px 10px;
  border-radius: 999px;
  backdrop-filter: blur(4px);
}

.pick-note {
  margin: 12px 0 0;
  text-align: center;
  font-size: 0.78rem;
  color: var(--text-muted);
  line-height: 1.5;
}

.thinking {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.92rem;
  text-align: center;
}

/* History */
.history-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.history-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}

.history-item:last-child {
  border-bottom: none;
}

.history-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.history-date {
  font-size: 0.76rem;
  color: var(--text-muted);
}

.history-name {
  display: block;
  font-size: 0.92rem;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history-price {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.history-again-btn {
  flex-shrink: 0;
  font-size: 0.78rem;
  white-space: nowrap;
}

/* Results */
.results-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
}

.results-header h2 {
  margin: 0;
}

.view-toggle {
  display: flex;
  border: 1.5px solid var(--border);
  border-radius: 999px;
  padding: 2px;
}

.view-btn {
  border: none;
  background: none;
  font-family: inherit;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-muted);
  padding: 6px 12px;
  border-radius: 999px;
}

.view-btn.is-active {
  background: var(--primary-soft);
  color: var(--primary-dark);
}

.results-list {
  list-style: none;
  margin: 12px 0 0;
  padding: 0;
}

.result-item {
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
  display: flex;
  gap: 12px;
  align-items: flex-start;
}

.result-item:last-child {
  border-bottom: none;
}

.result-emoji {
  font-size: 1.4rem;
  flex-shrink: 0;
  width: 34px;
  height: 34px;
  border-radius: 9px;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
}

.result-body {
  flex: 1;
  min-width: 0;
}

.result-name {
  font-weight: 700;
  margin: 0 0 3px;
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.result-meta {
  margin: 0;
  font-size: 0.82rem;
  color: var(--text-muted);
  line-height: 1.6;
}

.status-open {
  color: var(--green);
  font-weight: 600;
}

.badge-match {
  display: inline-block;
  background: var(--green-soft);
  color: var(--green);
  font-size: 0.68rem;
  font-weight: 700;
  border-radius: 6px;
  padding: 2px 7px;
}

.result-links {
  display: flex;
  gap: 14px;
  margin-top: 6px;
}

.result-link {
  font-size: 0.82rem;
  color: var(--primary-dark);
  text-decoration: none;
  font-weight: 700;
}

.result-link:hover {
  text-decoration: underline;
}

.map-view {
  height: 280px;
  border-radius: var(--radius-md);
  margin-top: 12px;
  overflow: hidden;
  border: 1px solid var(--border);
}

.rating-note {
  margin: 16px 0 0;
  font-size: 0.78rem;
  color: var(--text-muted);
}

#fallbackWrap {
  margin-top: 14px;
  text-align: center;
}

.spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  vertical-align: middle;
}

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

.app-footer {
  text-align: center;
  font-size: 0.7rem;
  color: var(--text-muted);
  line-height: 1.5;
}

@media (max-width: 400px) {
  .region-row {
    grid-template-columns: 1fr;
  }
  .location-modes {
    flex-direction: column;
  }
}

/* Bottom CTA bar — dính đáy màn hình như nút "Đặt món" trên các app giao đồ ăn */
.bottom-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 500;
  background: color-mix(in srgb, var(--card-bg) 92%, transparent);
  backdrop-filter: blur(10px);
  border-top: 1px solid var(--border);
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom, 0px));
}

.bottom-bar .btn-primary {
  max-width: 480px;
  margin: 0 auto;
  display: block;
}

/* Bottom sheet modal — chọn khu vực */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(20, 15, 10, 0.45);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  animation: fadeIn 0.15s ease;
}

.sheet {
  width: 100%;
  max-width: 480px;
  background: var(--card-bg);
  border-radius: 20px 20px 0 0;
  padding: 8px 20px calc(20px + env(safe-area-inset-bottom, 0px));
  box-shadow: 0 -8px 24px rgba(0, 0, 0, 0.16);
  animation: slideUp 0.22s ease;
  max-height: 85vh;
  overflow-y: auto;
}

.sheet-handle {
  width: 36px;
  height: 4px;
  border-radius: 999px;
  background: var(--border);
  margin: 0 auto 14px;
}

.sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.sheet-header h3 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}
