/* 平台樣式。配色全部用 CSS 變數，各趟旅程在 config.json 的 theme 覆寫 */
:root {
  --primary: #5E7F99;
  --primary-deep: #4F6D8C;
  --accent: #C4A05A;
  --accent-deep: #8F7030;
  --on-primary: #FFFFFF;
  --on-accent: #FFFFFF;
  --action: #5F7F66;
  --action-deep: #4C6852;
  --bg: #F4F5F7;
  --bg-deep: #E9E4E8;
  --card: #FFFFFF;
  --ink: #3A3542;
  --ink-soft: #6F6779;
  --line: #E4DEDA;
  --shadow: 0 2px 14px rgba(58, 53, 66, 0.08);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: light only;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--bg);
  color: var(--ink);
  font-family: 'Noto Sans TC', -apple-system, BlinkMacSystemFont, 'PingFang TC', sans-serif;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}
h1, h2, h3 { font-family: 'Noto Serif TC', 'Songti TC', serif; margin: 0; }

/* ---------- App 外框：固定高度，內容在 main 裡捲動（iOS 獨立模式防護） ---------- */
#app {
  max-width: 560px;
  margin: 0 auto;
  height: 100vh;
  height: var(--app-height, 100vh);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg);
}
#mainContent {
  flex: 1;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 18px 16px 24px;
}

/* ---------- 頂部 ---------- */
.app-header {
  flex: none;
  padding-top: var(--safe-top);
  color: var(--on-primary);
  background: var(--primary);
}
.app-header-top { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 14px 16px 14px; }
.app-header-title { display: flex; align-items: center; gap: 8px; min-width: 0; }
.app-title { font-size: 17px; font-weight: 700; color: var(--on-primary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.header-actions { display: flex; align-items: center; gap: 7px; flex-shrink: 0; }
.header-icon-btn {
  width: 30px; height: 30px; flex-shrink: 0;
  border-radius: 50%; border: none;
  background: rgba(0, 0, 0, 0.12); color: var(--on-primary);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; padding: 0;
}
.header-icon-btn svg { width: 15px; height: 15px; }
.header-icon-btn.spinning svg { animation: spin .7s linear; }
@keyframes spin { from { transform: rotate(0); } to { transform: rotate(360deg); } }
.countdown-badge, .sync-badge {
  background: rgba(0, 0, 0, 0.12);
  color: var(--on-primary);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
}
.sync-badge { background: rgba(0, 0, 0, 0.25); }
.sync-banner { background: #8A3F3F; color: white; font-size: 12.5px; line-height: 1.5; padding: 8px 16px; }

/* ---------- 首頁：旅程列表 ---------- */
.trip-card-list { display: flex; flex-direction: column; gap: 14px; }
.trip-card { display: block; background: var(--card); border-radius: 16px; padding: 16px 18px; box-shadow: var(--shadow); text-decoration: none; color: var(--ink); }
.trip-card-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.trip-card-name { font-family: 'Noto Serif TC', 'Songti TC', serif; font-size: 17px; font-weight: 700; }
.trip-card-date { font-size: 13px; color: var(--ink-soft); margin-top: 6px; }
.trip-card-cities { font-size: 13px; margin-top: 2px; }
.trip-status { font-size: 11.5px; font-weight: 700; padding: 3px 10px; border-radius: 999px; white-space: nowrap; }
.trip-status-active { background: #DDEBDD; color: #3F6345; }
.trip-status-upcoming { background: var(--bg-deep); color: var(--ink); }
.trip-status-ended { background: var(--bg-deep); color: var(--ink-soft); }

/* ---------- 分頁 ---------- */
.tab-panel { display: none; }
.tab-panel.active { display: block; animation: fadeIn .2s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.panel-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; gap: 10px; }
.panel-head h2 { font-size: 18px; }

.overview-section { margin-bottom: 20px; padding-bottom: 18px; border-bottom: 1px solid var(--line); }
.overview-section-last { border-bottom: none; padding-bottom: 0; margin-bottom: 0; }
.overview-section-title, .section-card-title, .section-toggle-label {
  font-size: 12px;
  font-weight: 700;
  color: var(--accent-deep);
  letter-spacing: 0.06em;
}
.overview-section-title { margin-bottom: 10px; }
.section-card-title { margin-bottom: 12px; }
.section-toggle {
  width: 100%; background: none; border: none; padding: 4px 0;
  display: flex; align-items: center; justify-content: space-between;
  cursor: pointer; font-family: inherit; margin-bottom: 8px;
}
.section-toggle-chevron { width: 16px; height: 16px; flex-shrink: 0; color: var(--ink-soft); transition: transform .2s ease; display: flex; align-items: center; justify-content: center; }
.section-toggle-chevron.open { transform: rotate(180deg); }

.inline-form-card, .section-card { background: var(--card); border-radius: 16px; padding: 16px; box-shadow: var(--shadow); margin-bottom: 16px; }
.inline-form-card h3 { font-size: 14px; color: var(--ink-soft); margin-bottom: 12px; }
.section-card .list-item { background: var(--bg); box-shadow: none; }
.section-card .empty-state { padding: 16px 4px; }

/* ---------- 航班 ---------- */
.flight-summary-list { display: flex; flex-direction: column; gap: 10px; }
.fs-item { background: var(--card); border-radius: 12px; padding: 10px 12px; box-shadow: var(--shadow); }
.fs-no { font-size: 11px; font-weight: 700; color: var(--accent-deep); margin-bottom: 3px; }
.fs-route { font-size: 14px; font-weight: 600; }
.fs-main { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; margin-top: 4px; }
.fs-date { font-size: 12px; color: var(--ink-soft); font-weight: 600; flex-shrink: 0; }
.fs-times { flex: 1; min-width: 0; }
.fs-time-row { display: grid; grid-template-columns: 28px 38px 1fr auto; gap: 6px; align-items: center; font-size: 11.5px; color: var(--ink-soft); }
.fs-label { color: var(--accent-deep); font-weight: 700; }
.fs-time { font-weight: 700; color: var(--ink); }
.fs-city { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fs-terminal { text-align: right; white-space: nowrap; }
.fs-plus { font-size: 9px; color: var(--accent-deep); margin-left: 1px; }
.fs-note { font-size: 12px; color: var(--ink-soft); margin-top: 6px; padding-top: 6px; border-top: 1px solid var(--line); }

/* ---------- 按鈕 ---------- */
.btn-primary, .btn-secondary {
  border: none; border-radius: 10px; padding: 9px 15px;
  font-size: 13px; font-weight: 600; font-family: inherit; cursor: pointer; white-space: nowrap;
}
.btn-primary { background: var(--action); color: white; }
.btn-primary:disabled { opacity: 0.6; cursor: default; }
.btn-primary:active { background: var(--action-deep); }
.btn-secondary { background: var(--card); color: var(--ink); border: 1px solid var(--line); display: inline-block; text-align: center; text-decoration: none; }
.btn-primary svg, .btn-secondary svg { width: 14px; height: 14px; vertical-align: -2px; margin-right: 4px; }
.btn-full { width: 100%; padding: 12px 15px; font-size: 14px; }

/* ---------- 清單 ---------- */
.list { display: flex; flex-direction: column; gap: 10px; }
.list-item { background: var(--card); border-radius: 14px; padding: 13px 14px; box-shadow: var(--shadow); display: flex; align-items: flex-start; gap: 10px; }
.item-body { flex: 1; min-width: 0; }
.item-title { font-weight: 600; font-size: 14px; word-break: break-word; }
.item-convert { font-size: 12.5px; color: var(--accent-deep); font-weight: 600; margin-top: 2px; }
.item-sub { font-size: 12.5px; color: var(--ink-soft); margin-top: 2px; }
.item-actions { display: flex; gap: 6px; }
.icon-btn { background: none; border: none; color: var(--ink-soft); cursor: pointer; padding: 6px; display: flex; align-items: center; justify-content: center; }
.icon-btn svg { width: 18px; height: 18px; }

/* ---------- 記帳 ---------- */
.expense-summary { text-align: center; }
.balance-line { font-family: 'Noto Serif TC', 'Songti TC', serif; font-size: 17px; font-weight: 700; color: var(--accent-deep); }
.balance-sub { font-size: 12.5px; color: var(--ink-soft); margin-top: 4px; }
.balance-sub + .balance-line { margin-top: 12px; }
.rate-note { font-size: 14px; color: var(--ink); text-align: center; font-weight: 600; }
.rate-source { font-size: 11.5px; color: var(--ink-soft); font-weight: 400; margin-top: 2px; }
.rate-source:empty { display: none; }
.amount-preview { font-size: 13px; color: var(--accent-deep); font-weight: 600; text-align: right; margin: -6px 2px 10px; }
.amount-preview:empty { display: none; }

/* ---------- 切換鈕 ---------- */
.city-toggle { display: flex; gap: 8px; margin-bottom: 14px; }
.city-btn {
  flex: 1; padding: 9px; border-radius: 10px; border: 1px solid var(--line); background: var(--card);
  font-family: inherit; font-size: 14px; font-weight: 600; color: var(--ink-soft); cursor: pointer;
}
.city-btn.active { background: var(--primary-deep); border-color: var(--primary-deep); color: white; }

/* ---------- 備註 ---------- */
.card-grid { display: flex; flex-direction: column; gap: 12px; }
.note-card { background: var(--card); border-radius: 14px; padding: 14px; box-shadow: var(--shadow); }
.note-text { font-size: 14px; line-height: 1.6; white-space: pre-wrap; word-break: break-word; }
.note-meta { font-size: 11.5px; color: var(--ink-soft); margin-top: 8px; }
.note-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 6px; }
.note-link-card { display: block; background: var(--bg); border-radius: 10px; padding: 10px 12px; margin-top: 6px; text-decoration: none; }
.nlc-domain { font-size: 13px; font-weight: 700; color: var(--action-deep); }
.nlc-url { font-size: 11.5px; color: var(--ink-soft); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-top: 2px; }

/* ---------- 天氣 ---------- */
.weather-today {
  background: var(--primary);
  color: var(--on-primary); border-radius: 14px; padding: 12px 16px; margin-bottom: 12px; min-height: 92px;
}
.wt-top { display: flex; justify-content: space-between; align-items: flex-start; }
.wt-city { font-size: 12.5px; opacity: 0.95; }
.temp-now { font-family: 'Noto Serif TC', 'Songti TC', serif; font-size: 30px; font-weight: 700; line-height: 1.15; }
.wt-label { font-size: 12.5px; opacity: 0.95; }
.wt-sun { text-align: right; font-size: 11.5px; opacity: 0.95; line-height: 1.6; }
.wt-tip { font-size: 12.5px; margin-top: 8px; padding-top: 8px; border-top: 1px solid rgba(127, 127, 127, 0.35); }
.weather-hourly { display: flex; overflow-x: auto; gap: 14px; padding: 4px 2px 10px; }
.weather-hour { flex: 0 0 auto; text-align: center; font-size: 12.5px; color: var(--ink-soft); }
.h-temp { font-weight: 700; color: var(--ink); font-size: 14px; margin: 4px 0; }
.weather-days-strip { display: flex; overflow-x: auto; gap: 10px; padding: 2px 2px 8px; }
.wd-card { flex: 0 0 auto; min-width: 64px; text-align: center; background: var(--card); border-radius: 12px; padding: 10px 8px; box-shadow: var(--shadow); font-size: 12px; color: var(--ink-soft); }
.wd-temp { font-size: 12.5px; color: var(--ink); font-weight: 600; margin-top: 4px; }

/* ---------- 住宿 ---------- */
.stay-card { background: var(--card); border-radius: 16px; padding: 16px; box-shadow: var(--shadow); border: 2px solid transparent; }
.stay-current { border-color: var(--accent); }
.stay-past { opacity: 0.72; }
.stay-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.stay-date { font-size: 12.5px; color: var(--accent-deep); font-weight: 700; }
.stay-here { background: var(--accent); color: var(--on-accent); font-size: 11px; font-weight: 700; padding: 3px 10px; border-radius: 999px; white-space: nowrap; }
.stay-name { font-family: 'Noto Serif TC', 'Songti TC', serif; font-size: 15.5px; margin: 4px 0; }
.stay-area { font-size: 13px; color: var(--ink-soft); }
.stay-address { font-size: 12.5px; color: var(--ink-soft); margin-top: 4px; display: flex; align-items: center; gap: 4px; }
.stay-address svg { flex-shrink: 0; }
.stay-meta { font-size: 12.5px; color: var(--ink-soft); margin-top: 4px; }
.stay-meta a { color: var(--ink-soft); }
.fs-status { display: inline-block; font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 6px; margin-left: 6px; background: var(--bg-deep); color: var(--ink); }
.status-pill { display: inline-block; font-size: 11px; font-weight: 700; padding: 3px 10px; border-radius: 999px; margin-top: 8px; }
.status-pill.booked { background: #DDEBDD; color: #3F6345; }
.status-pill.pending { background: var(--bg-deep); color: var(--ink); }
.stay-photos, .item-photos { display: flex; gap: 8px; overflow-x: auto; margin-top: 10px; }
.stay-photos img { width: 76px; height: 76px; object-fit: cover; border-radius: 10px; flex-shrink: 0; cursor: pointer; }
.item-photos img { width: 64px; height: 64px; object-fit: cover; border-radius: 8px; flex-shrink: 0; cursor: pointer; }
.photo-fallback {
  width: 64px; height: 64px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; text-align: center;
  padding: 4px; border-radius: 8px; border: 1px dashed var(--line);
  background: var(--bg); color: var(--ink-soft); font-size: 10px; line-height: 1.3; cursor: pointer;
}
.stay-photos .photo-fallback { width: 76px; height: 76px; border-radius: 10px; }
.photo-thumb-wrap .photo-fallback { width: 100%; height: 100%; }
.photo-thumb-row { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; padding: 6px 6px 0 0; }
.photo-thumb-wrap { position: relative; width: 64px; height: 64px; flex-shrink: 0; }
.photo-thumb-wrap img { width: 100%; height: 100%; object-fit: cover; border-radius: 8px; }
.photo-thumb-remove {
  position: absolute; top: -6px; right: -6px; width: 22px; height: 22px; border-radius: 50%;
  background: var(--ink); color: white; border: 2px solid var(--bg);
  font-size: 12px; line-height: 1; cursor: pointer; padding: 0;
}
.stay-note { font-size: 13px; margin-top: 10px; white-space: pre-wrap; word-break: break-word; background: var(--bg); border-radius: 10px; padding: 10px; }
.stay-actions { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }

/* ---------- 底部導覽：在版面流裡，不用 fixed，獨立模式不會跑位 ---------- */
.bottom-nav {
  flex: none;
  background: var(--card);
  border-top: 1px solid var(--line);
  display: flex;
  padding: 6px 2px calc(6px + var(--safe-bottom));
}
.home-mode .bottom-nav { display: none; }
.nav-item {
  flex: 1; background: none; border: none;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  font-size: 11px; color: var(--ink-soft); padding: 6px 2px; font-family: inherit; cursor: pointer;
}
.nav-icon { width: 20px; height: 20px; display: flex; align-items: center; justify-content: center; }
.nav-icon svg { width: 19px; height: 19px; }
.nav-item.active { color: var(--primary-deep); font-weight: 700; }

/* ---------- Modal ---------- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(58, 53, 66, 0.45); display: none; align-items: flex-end; justify-content: center; z-index: 2000; }
.modal-backdrop.open { display: flex; }
.modal {
  background: var(--bg); width: 100%; max-width: 560px;
  border-radius: 20px 20px 0 0;
  padding: 20px 18px calc(20px + var(--safe-bottom));
  max-height: calc(var(--app-height, 100vh) * 0.88);
  overflow-y: auto; overflow-x: hidden;
  animation: slideUp .22s ease;
}
@keyframes slideUp { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }
.modal h3 { font-size: 16px; margin-bottom: 14px; }
.modal-actions { display: flex; gap: 10px; margin-top: 6px; }
.modal-actions .btn-primary, .modal-actions .btn-secondary { flex: 1; padding: 12px; text-align: center; }

/* ---------- 表單：字級 16px，iOS 點輸入框才不會自動放大版面 ---------- */
.field { margin-bottom: 12px; min-width: 0; overflow: hidden; border-radius: 10px; }
.field label { display: block; font-size: 12.5px; color: var(--ink-soft); margin-bottom: 5px; font-weight: 600; }
.field input, .field select, .field textarea {
  width: 100%; max-width: 100%; min-width: 0;
  border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px;
  font-size: 16px; font-family: inherit; background: white; color: var(--ink);
}
.field input[type="date"] { -webkit-appearance: none; appearance: none; min-height: 42px; }
.field textarea { min-height: 80px; resize: vertical; }
.field-row { display: flex; gap: 10px; }
.field-row .field { flex: 1; min-width: 0; }
.split-options { display: flex; flex-direction: column; gap: 6px; }
.split-options button {
  border: 1px solid var(--line); background: white; border-radius: 10px;
  padding: 10px 14px; font-size: 13.5px; font-family: inherit; cursor: pointer; color: var(--ink-soft); text-align: left;
}
.split-options button.active { background: var(--primary-deep); border-color: var(--primary-deep); color: white; font-weight: 600; }

.upload-progress-wrap { margin: 8px 0 10px; }
.upload-progress-bar { height: 6px; background: var(--line); border-radius: 999px; overflow: hidden; }
.upload-progress-fill { height: 100%; width: 0%; background: var(--action); transition: width .15s ease; }
.upload-progress-text { font-size: 11.5px; color: var(--ink-soft); margin-top: 4px; text-align: center; }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  bottom: calc(76px + var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  width: max-content;
  max-width: calc(100vw - 32px);
  background: var(--ink); color: white;
  font-size: 13.5px; padding: 10px 18px; border-radius: 999px;
  opacity: 0; pointer-events: none; transition: all .25s ease;
  z-index: 2500;
  display: flex; align-items: center; gap: 10px;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); pointer-events: auto; }
.toast-undo-btn {
  background: rgba(255, 255, 255, 0.18); border: none; color: white; font-weight: 700;
  padding: 4px 10px; border-radius: 999px; font-size: 12.5px; font-family: inherit; cursor: pointer;
}

/* ---------- 燈箱 ---------- */
.lightbox {
  position: fixed; inset: 0; background: rgba(20, 18, 15, 0.92);
  display: none; align-items: center; justify-content: center;
  padding: 24px; z-index: 3000; overflow: hidden; touch-action: none;
  transition: background .05s linear;
}
.lightbox.open { display: flex; }
.lightbox-msg { color: rgba(255, 255, 255, 0.85); font-size: 15px; text-align: center; }
.lightbox img {
  max-width: 100%; max-height: 100%; border-radius: 10px; touch-action: none;
  transform-origin: center center;
  transition: transform .05s ease-out, opacity .14s ease;
  will-change: transform, opacity;
}
.lightbox-close {
  position: absolute; top: calc(16px + var(--safe-top)); right: 16px;
  width: 36px; height: 36px; border-radius: 50%; border: none;
  background: rgba(255, 255, 255, 0.15); z-index: 3001; cursor: pointer;
}
.lightbox-close::before, .lightbox-close::after {
  content: ''; position: absolute; top: 50%; left: 50%;
  width: 16px; height: 2px; background: white;
  transform: translate(-50%, -50%) rotate(45deg);
}
.lightbox-close::after { transform: translate(-50%, -50%) rotate(-45deg); }
.lightbox-nav {
  position: absolute; top: 50%; transform: translateY(-50%);
  width: 42px; height: 42px; border-radius: 50%; border: none;
  background: rgba(255, 255, 255, 0.15); z-index: 3001; cursor: pointer;
}
.lightbox-nav::before {
  content: ''; position: absolute; top: 50%; left: 50%;
  width: 11px; height: 11px; border-top: 2px solid white; border-right: 2px solid white;
}
.lightbox-prev { left: 12px; }
.lightbox-prev::before { transform: translate(-30%, -50%) rotate(-135deg); }
.lightbox-next { right: 12px; }
.lightbox-next::before { transform: translate(-70%, -50%) rotate(45deg); }
.lightbox-counter {
  position: absolute; bottom: calc(20px + var(--safe-bottom)); left: 50%; transform: translateX(-50%);
  background: rgba(255, 255, 255, 0.15); color: white;
  font-size: 12.5px; font-weight: 600; padding: 5px 14px; border-radius: 999px; z-index: 3001;
}

.empty-state { text-align: center; color: var(--ink-soft); font-size: 13px; padding: 36px 20px; }

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
