/* ── CSS 變數（品牌設計規範） ── */
:root {
  --bg-base: #121212;
  --bg-surface: #181818;
  --bg-interactive: #1f1f1f;
  --bg-card: #252525;

  --text-base: #ffffff;
  --text-muted: #b3b3b3;
  --text-subtle: #cbcbcb;

  --brand-primary: #1ed760;
  --brand-border: #1db954;

  --text-negative: #f3727f;
  --text-warning: #ffa42b;
  --text-info: #539df5;

  --border-default: #4d4d4d;
  --border-light: #7c7c7c;

  --shadow-card: rgba(0,0,0,0.3) 0px 8px 8px;
  --shadow-dialog: rgba(0,0,0,0.5) 0px 8px 24px;
  --shadow-inset: rgb(18,18,18) 0px 1px 0px, rgb(124,124,124) 0px 0px 0px 1px inset;

  --radius-card: 8px;
  --radius-pill: 500px;
  --radius-pill-sm: 9999px;
  --radius-circle: 50%;

  --nav-height: 64px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
}

/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; }
body {
  font-family: Inter, "Helvetica Neue", Arial, "PingFang TC", "Noto Sans TC", sans-serif;
  background: var(--bg-base);
  color: var(--text-base);
  min-height: 100dvh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}
button { cursor: pointer; border: none; background: none; color: inherit; font: inherit; }
input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; text-decoration: none; }
img { max-width: 100%; display: block; }
.hidden { display: none !important; }

/* ── 主內容區 ── */
#app {
  padding-top: calc(var(--safe-top) + 8px);
  padding-bottom: calc(var(--nav-height) + var(--safe-bottom) + 16px);
  min-height: 100dvh;
}

/* ── Tab Section ── */
.tab-section { display: none; padding: 0 16px; animation: fadeIn 0.2s ease; }
.tab-section.active { display: block; }

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

/* ── Section Header ── */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 0 16px;
  gap: 12px;
}
.section-title {
  font-size: 24px;
  font-weight: 700;
  color: var(--text-base);
  flex-shrink: 0;
}
.section-subtitle {
  font-size: 13px;
  color: var(--text-muted);
  flex: 1;
  text-align: right;
}

/* ── 底部導覽列 ── */
#bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: calc(var(--nav-height) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: var(--bg-surface);
  border-top: 1px solid var(--border-default);
  display: flex;
  align-items: stretch;
  z-index: 100;
}
.nav-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 8px 4px;
  color: var(--text-muted);
  transition: color 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.nav-btn svg { width: 24px; height: 24px; }
.nav-btn span { font-size: 10px; font-weight: 600; letter-spacing: 0.3px; }
.nav-btn.active { color: var(--brand-primary); }

/* ── 按鈕 ── */
.btn-pill-green {
  background: var(--brand-primary);
  color: #000000;
  font-size: 14px;
  font-weight: 700;
  padding: 8px 20px;
  border-radius: var(--radius-pill-sm);
  letter-spacing: 0.14px;
  transition: opacity 0.15s, transform 0.1s;
  white-space: nowrap;
  flex-shrink: 0;
}
.btn-pill-green:active { opacity: 0.85; transform: scale(0.97); }

.btn-pill-outline {
  background: transparent;
  border: 1px solid var(--border-light);
  color: var(--text-base);
  font-size: 14px;
  font-weight: 600;
  padding: 8px 16px;
  border-radius: var(--radius-pill-sm);
  transition: border-color 0.15s, opacity 0.15s;
  white-space: nowrap;
}
.btn-pill-outline:active { opacity: 0.75; }

.btn-icon {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-circle);
  color: var(--text-muted);
  font-size: 16px;
  transition: background 0.15s, color 0.15s;
}
.btn-icon:hover { background: var(--bg-interactive); color: var(--text-base); }
.btn-danger { border-color: var(--text-negative); color: var(--text-negative); }

/* ── 行程 Tab ── */
.itinerary-list { display: flex; flex-direction: column; gap: 12px; padding-bottom: 8px; }

.day-card {
  background: var(--bg-surface);
  border-radius: var(--radius-card);
  overflow: hidden;
  box-shadow: var(--shadow-card);
}
.day-header {
  display: flex;
  align-items: center;
  padding: 14px 16px;
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  gap: 12px;
}
.day-badge {
  background: var(--brand-primary);
  color: #000;
  font-size: 11px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: var(--radius-pill-sm);
  flex-shrink: 0;
}
.day-info { flex: 1; min-width: 0; }
.day-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-base);
}
.day-date {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}
.day-chevron {
  color: var(--text-muted);
  font-size: 12px;
  transition: transform 0.2s;
  flex-shrink: 0;
}
.day-card.open .day-chevron { transform: rotate(180deg); }

.day-events {
  display: none;
  border-top: 1px solid var(--border-default);
  padding: 8px 0;
}
.day-card.open .day-events { display: block; }

.event-item {
  display: flex;
  gap: 12px;
  padding: 10px 16px;
  align-items: flex-start;
}
.event-time {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 600;
  min-width: 40px;
  padding-top: 2px;
  flex-shrink: 0;
}
.event-body { flex: 1; min-width: 0; }
.event-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-base);
}
.event-notes {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 3px;
  line-height: 1.4;
}
.event-dot {
  width: 8px;
  height: 8px;
  border-radius: var(--radius-circle);
  margin-top: 5px;
  flex-shrink: 0;
}
.event-dot.transport  { background: var(--text-info); }
.event-dot.hotel      { background: var(--text-warning); }
.event-dot.shopping   { background: var(--brand-primary); }
.event-dot.sightseeing{ background: #c084fc; }
.event-dot.food       { background: var(--text-negative); }
.event-dot.other      { background: var(--text-muted); }

/* ── 購買清單 Tab ── */
.filter-bar {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 8px;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.filter-bar::-webkit-scrollbar { display: none; }

.filter-chip {
  background: var(--bg-interactive);
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 600;
  padding: 6px 14px;
  border-radius: var(--radius-pill-sm);
  white-space: nowrap;
  transition: background 0.15s, color 0.15s;
  flex-shrink: 0;
}
.filter-chip.active {
  background: var(--brand-primary);
  color: #000;
}

.shopping-stats {
  display: flex;
  gap: 16px;
  padding: 12px 0 8px;
  font-size: 13px;
  color: var(--text-muted);
}
.stat-item { display: flex; align-items: center; gap: 4px; }
.stat-value { color: var(--text-base); font-weight: 600; }

.shopping-list { display: flex; flex-direction: column; gap: 8px; padding-bottom: 8px; }

.shopping-item {
  background: var(--bg-surface);
  border-radius: var(--radius-card);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  cursor: pointer;
  transition: background 0.15s;
  -webkit-tap-highlight-color: transparent;
  box-shadow: var(--shadow-card);
}
.shopping-item:active { background: var(--bg-interactive); }
.shopping-item.checked { opacity: 0.45; }

.item-check {
  width: 22px;
  height: 22px;
  border-radius: var(--radius-circle);
  border: 2px solid var(--border-light);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s, border-color 0.15s;
}
.item-check.checked { background: var(--brand-primary); border-color: var(--brand-primary); }
.item-check.checked::after { content: '✓'; font-size: 12px; font-weight: 700; color: #000; }

.item-thumb {
  width: 44px;
  height: 44px;
  border-radius: 6px;
  object-fit: cover;
  flex-shrink: 0;
  background: var(--bg-interactive);
}
.item-thumb-placeholder {
  width: 44px;
  height: 44px;
  border-radius: 6px;
  background: var(--bg-interactive);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
}

.item-body { flex: 1; min-width: 0; }
.item-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-base);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.item-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 3px;
  flex-wrap: wrap;
}
.item-cat {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  background: var(--bg-interactive);
  padding: 2px 7px;
  border-radius: var(--radius-pill-sm);
}
.item-store {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.item-price {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-base);
  text-align: right;
  flex-shrink: 0;
}
.item-price-sub {
  font-size: 11px;
  color: var(--text-muted);
  text-align: right;
}

/* ── 工具 Tab ── */
.tool-card {
  background: var(--bg-surface);
  border-radius: var(--radius-card);
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: var(--shadow-card);
}
.tool-card-title {
  font-size: 18px;
  font-weight: 600;
  color: var(--text-base);
  margin-bottom: 16px;
}
.tool-card-desc {
  font-size: 14px;
  color: var(--text-muted);
  margin-bottom: 16px;
  line-height: 1.5;
}

/* 計算機 */
.calc-display {
  background: var(--bg-interactive);
  border-radius: 6px;
  padding: 16px;
  margin-bottom: 16px;
  text-align: right;
  min-height: 72px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  box-shadow: var(--shadow-inset);
}
.calc-expression { font-size: 14px; color: var(--text-muted); min-height: 20px; word-break: break-all; }
.calc-result { font-size: 36px; font-weight: 700; color: var(--text-base); word-break: break-all; }

.calc-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 12px;
}
.calc-btn {
  background: var(--bg-interactive);
  border-radius: 6px;
  padding: 16px 8px;
  font-size: 18px;
  font-weight: 600;
  color: var(--text-base);
  transition: background 0.1s, transform 0.1s;
  -webkit-tap-highlight-color: transparent;
}
.calc-btn:active { background: var(--bg-card); transform: scale(0.95); }
.calc-fn { color: var(--text-muted); font-size: 16px; }
.calc-op { color: var(--brand-primary); }
.calc-zero { grid-column: span 2; text-align: left; padding-left: 20px; }
.calc-eq  { background: var(--brand-primary); color: #000; }
.calc-eq:active { background: var(--brand-border); }

.calc-tax { width: 100%; text-align: center; }

/* 菜單分析 */
.menu-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.menu-loading {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 0;
  color: var(--text-muted);
  font-size: 14px;
}
.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid var(--border-default);
  border-top-color: var(--brand-primary);
  border-radius: var(--radius-circle);
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.menu-result { margin-top: 16px; }
.menu-result-title { font-size: 14px; font-weight: 600; color: var(--text-muted); margin-bottom: 10px; }
.menu-item-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 10px 0;
  border-bottom: 1px solid var(--border-default);
  gap: 12px;
}
.menu-item-row:last-child { border-bottom: none; }
.menu-item-names { flex: 1; }
.menu-item-ja { font-size: 14px; font-weight: 600; color: var(--text-base); }
.menu-item-zh { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.menu-item-price { font-size: 15px; font-weight: 700; color: var(--brand-primary); flex-shrink: 0; }
.menu-total {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--border-light);
  font-size: 16px;
  font-weight: 700;
  color: var(--text-base);
}
.menu-total-amount { color: var(--brand-primary); font-size: 20px; }

/* ── Modal ── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  z-index: 200;
  display: flex;
  align-items: flex-end;
  animation: fadeIn 0.15s ease;
}
.modal-sheet {
  background: var(--bg-surface);
  width: 100%;
  max-height: 90dvh;
  border-radius: 16px 16px 0 0;
  overflow-y: auto;
  padding: 0 0 calc(20px + var(--safe-bottom));
  box-shadow: var(--shadow-dialog);
  overscroll-behavior: contain;
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 20px 12px;
  position: sticky;
  top: 0;
  background: var(--bg-surface);
  z-index: 1;
  border-bottom: 1px solid var(--border-default);
}
.modal-title { font-size: 18px; font-weight: 600; }

/* Form */
.item-form { padding: 16px 20px 0; display: flex; flex-direction: column; gap: 14px; }
.form-label { font-size: 13px; font-weight: 600; color: var(--text-muted); }
.required { color: var(--text-negative); }
.form-input {
  width: 100%;
  background: var(--bg-interactive);
  border: none;
  border-radius: 6px;
  padding: 12px 14px;
  font-size: 15px;
  color: var(--text-base);
  box-shadow: var(--shadow-inset);
  outline: none;
  transition: box-shadow 0.15s;
  margin-top: 4px;
}
.form-input:focus {
  box-shadow: rgb(18,18,18) 0px 1px 0px, var(--brand-primary) 0px 0px 0px 2px inset;
}
.form-textarea { resize: vertical; min-height: 72px; }
select.form-input { appearance: none; -webkit-appearance: none; }

.image-preview-area {
  position: relative;
  margin-top: 4px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.preview-img {
  width: 80px;
  height: 80px;
  object-fit: cover;
  border-radius: 6px;
  cursor: pointer;
}
.remove-img {
  position: absolute;
  top: -8px;
  left: 68px;
  background: var(--bg-card);
  border: 1px solid var(--border-default);
  width: 22px;
  height: 22px;
  font-size: 12px;
}

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

/* ── 圖片全螢幕 Overlay ── */
.image-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.92);
  z-index: 300;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.15s ease;
}
.overlay-close {
  position: absolute;
  top: calc(var(--safe-top) + 16px);
  right: 16px;
  font-size: 20px;
  z-index: 1;
  color: var(--text-base);
  background: var(--bg-interactive);
  width: 36px;
  height: 36px;
}
.overlay-img {
  max-width: 90vw;
  max-height: 80dvh;
  object-fit: contain;
  border-radius: var(--radius-card);
}

/* ── 空狀態 ── */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-muted);
}
.empty-state-icon { font-size: 40px; margin-bottom: 12px; }
.empty-state-text { font-size: 15px; line-height: 1.5; }

/* ── 響應式（平板以上稍微加寬 padding） ── */
@media (min-width: 576px) {
  #app { padding-left: 0; padding-right: 0; max-width: 540px; margin: 0 auto; }
  .tab-section { padding: 0 24px; }
  .modal-sheet { max-width: 540px; margin: 0 auto; }
  #bottom-nav { max-width: 540px; left: 50%; transform: translateX(-50%); }
}
