:root {
  --ink: #1b2a4a;
  --ink-soft: #41506b;
  --accent: #e4572e;
  --accent-dark: #c2451f;
  --bg: #f3f4f7;
  --card: #ffffff;
  --line: #e2e5ec;
  --ok: #1f8a52;
  --shadow: 0 2px 14px rgba(27, 42, 74, 0.08);
  --radius: 16px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans TC",
    "Hiragino Sans", "Microsoft JhengHei", sans-serif;
  line-height: 1.55;
  -webkit-text-size-adjust: 100%;
}

main {
  max-width: 680px;
  margin: 0 auto;
  padding: 16px 16px 40px;
}

.topbar {
  background: linear-gradient(135deg, #1b2a4a 0%, #2c4170 100%);
  color: #fff;
  padding: calc(env(safe-area-inset-top) + 20px) 16px 22px;
  text-align: center;
}
.topbar h1 {
  margin: 0;
  font-size: 1.45rem;
  letter-spacing: 0.04em;
}
.topbar .sub {
  margin: 6px 0 0;
  font-size: 0.84rem;
  opacity: 0.82;
}

.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  margin-top: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.field { display: flex; flex-direction: column; gap: 6px; border: 0; padding: 0; margin: 0; }
.field > span, .field > legend {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--ink-soft);
  padding: 0;
}

input[type="text"],
input[type="date"],
input[type="password"] {
  width: 100%;
  padding: 12px 13px;
  font-size: 1rem;
  border: 1.5px solid var(--line);
  border-radius: 11px;
  background: #fafbfc;
  color: var(--ink);
  transition: border-color 0.15s;
}
input:focus {
  outline: none;
  border-color: var(--ink);
  background: #fff;
}

.row { display: flex; gap: 12px; }
.row .field { flex: 1; }

.hint {
  margin: -4px 2px 0;
  font-size: 0.78rem;
  color: #8a93a6;
}

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  position: relative;
  cursor: pointer;
}
.chip input { position: absolute; opacity: 0; pointer-events: none; }
.chip span {
  display: inline-block;
  padding: 8px 15px;
  border: 1.5px solid var(--line);
  border-radius: 999px;
  font-size: 0.92rem;
  background: #fafbfc;
  color: var(--ink-soft);
  transition: all 0.15s;
}
.chip input:checked + span {
  background: var(--ink);
  border-color: var(--ink);
  color: #fff;
}

.hq-toggle {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 14px;
  border: 1.5px solid var(--line);
  border-radius: 12px;
  background: #fafbfc;
  cursor: pointer;
}
.hq-toggle input {
  flex: none;
  width: 18px;
  height: 18px;
  margin-top: 2px;
  accent-color: var(--accent);
}
.hq-text { display: flex; flex-direction: column; gap: 2px; }
.hq-text b { font-size: 0.9rem; color: var(--ink); }
.hq-text small { font-size: 0.76rem; color: #8a93a6; line-height: 1.4; }

.pw-details summary {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--ink-soft);
  cursor: pointer;
}
.pw-details[open] { display: flex; flex-direction: column; gap: 10px; }
.pw-details[open] summary { margin-bottom: 4px; }

button#submit-btn {
  width: 100%;
  padding: 14px;
  font-size: 1.05rem;
  font-weight: 700;
  color: #fff;
  background: var(--accent);
  border: 0;
  border-radius: 12px;
  cursor: pointer;
  transition: background 0.15s, transform 0.05s;
}
button#submit-btn:hover { background: var(--accent-dark); }
button#submit-btn:active { transform: scale(0.99); }
button#submit-btn:disabled { background: #c9ccd4; cursor: not-allowed; }

.status {
  margin-top: 16px;
  padding: 14px 16px;
  border-radius: 12px;
  font-size: 0.92rem;
  text-align: center;
}
.status.loading { background: #eef1f7; color: var(--ink-soft); }
.status.error { background: #fdecea; color: var(--accent-dark); }

.spinner {
  display: inline-block;
  width: 16px; height: 16px;
  margin-right: 8px;
  border: 2.5px solid #c9ccd4;
  border-top-color: var(--ink);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  vertical-align: -3px;
}
@keyframes spin { to { transform: rotate(360deg); } }

.results { margin-top: 16px; display: flex; flex-direction: column; gap: 12px; }

.event {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  border-left: 4px solid var(--accent);
}
.event-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 6px;
}
.event-name { font-size: 1.06rem; font-weight: 700; margin: 0; }
.event-cat {
  flex: none;
  font-size: 0.74rem;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: 999px;
  background: #eef1f7;
  color: var(--ink-soft);
}
.event-meta { font-size: 0.86rem; color: var(--ink-soft); margin: 2px 0; }
.event-meta b { color: var(--ink); font-weight: 600; }
.event-desc { font-size: 0.94rem; margin: 8px 0 0; }
.event-buzz {
  font-size: 0.86rem;
  margin: 8px 0 0;
  padding: 8px 11px;
  background: #fdeee9;
  border-radius: 9px;
  color: #9b3415;
}
.event-link {
  display: inline-block;
  margin-top: 10px;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--accent-dark);
  text-decoration: none;
}
.event-link:hover { text-decoration: underline; }

.results-summary {
  font-size: 0.85rem;
  color: var(--ink-soft);
  padding: 2px 2px 0;
}

.cat-heading {
  font-size: 0.92rem;
  font-weight: 800;
  color: var(--ink);
  margin: 16px 2px 2px;
  padding-bottom: 4px;
  border-bottom: 2px solid var(--accent);
}

.map-link { color: var(--ink-soft) !important; }

.foot {
  text-align: center;
  font-size: 0.76rem;
  color: #8a93a6;
  padding: 16px;
}

/* ===== 分頁 ===== */
.tabs {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-top: 14px;
}
.tab {
  appearance: none;
  border: 0;
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
  font-size: 0.95rem;
  font-weight: 600;
  padding: 8px 22px;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.15s;
}
.tab.active { background: var(--accent); }
.badge {
  display: inline-block;
  min-width: 18px;
  margin-left: 6px;
  padding: 1px 6px;
  font-size: 0.72rem;
  line-height: 1.5;
  background: #fff;
  color: var(--accent-dark);
  border-radius: 999px;
}

/* ===== 查詢結果卡片動作列 ===== */
.event-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 10px;
}
.event-actions .event-link { margin-top: 0; }
.add-trip-btn {
  flex: none;
  border: 1.5px solid var(--accent);
  background: #fff;
  color: var(--accent-dark);
  font-weight: 700;
  font-size: 0.86rem;
  padding: 7px 13px;
  border-radius: 999px;
  cursor: pointer;
}
.add-trip-btn:active { background: #fdeee9; }

/* ===== 行程檢視 ===== */
.trip-head { gap: 12px; }
.trip-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.trip-actions button {
  flex: 1;
  min-width: 90px;
  padding: 10px;
  font-size: 0.92rem;
  font-weight: 600;
  border-radius: 10px;
  border: 0;
  background: var(--ink);
  color: #fff;
  cursor: pointer;
}
button.ghost {
  background: #fff !important;
  color: var(--ink-soft) !important;
  border: 1.5px solid var(--line) !important;
}

.empty-hint {
  text-align: center;
  color: #8a93a6;
  font-size: 0.9rem;
  padding: 28px 16px;
  margin-top: 16px;
}

.day-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px;
  margin-top: 14px;
}
.day-head {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 10px;
}
.day-label { font-weight: 800; font-size: 1.05rem; color: var(--ink); }
.day-date {
  flex: 1;
  padding: 7px 9px !important;
  font-size: 0.86rem !important;
  border-radius: 8px !important;
}
.day-empty { color: #9aa3b2; font-size: 0.86rem; margin: 4px 0; }

.icon-btn {
  border: 1.5px solid var(--line);
  background: #fafbfc;
  color: var(--ink-soft);
  font-size: 0.82rem;
  font-weight: 600;
  padding: 6px 11px;
  border-radius: 9px;
  cursor: pointer;
}
.icon-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.icon-btn.danger { color: var(--accent-dark); border-color: #f3c9bd; }

.trip-item {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  margin-top: 10px;
  background: #fcfcfd;
}
.trip-item-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}
.trip-item-name { margin: 0; font-size: 1rem; font-weight: 700; }
.trip-item-edit { display: flex; gap: 8px; margin-top: 10px; }
.trip-time { flex: 0 0 38%; }
.trip-note { flex: 1; }
.trip-item-edit input {
  padding: 9px 10px !important;
  font-size: 0.88rem !important;
}
.trip-item-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
}

/* ===== 底部彈出（選擇加入哪一天）===== */
.sheet { position: fixed; inset: 0; z-index: 50; }
.sheet-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(20, 28, 46, 0.45);
}
.sheet-panel {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  background: #fff;
  border-radius: 20px 20px 0 0;
  padding: 20px 18px calc(env(safe-area-inset-bottom) + 20px);
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 70vh;
  overflow-y: auto;
  box-shadow: 0 -6px 24px rgba(0, 0, 0, 0.16);
}
.sheet-panel h3 { margin: 0 0 4px; font-size: 1.05rem; text-align: center; }
.sheet-list { display: flex; flex-direction: column; gap: 8px; }
.sheet-day, #day-sheet-new, #day-sheet-cancel {
  width: 100%;
  padding: 13px;
  font-size: 1rem;
  font-weight: 600;
  border-radius: 11px;
  border: 1.5px solid var(--line);
  background: #fafbfc;
  color: var(--ink);
  cursor: pointer;
}
#day-sheet-new { border-color: var(--accent); color: var(--accent-dark); }

/* ===== Toast ===== */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom) + 24px);
  transform: translateX(-50%);
  background: var(--ink);
  color: #fff;
  font-size: 0.9rem;
  padding: 11px 18px;
  border-radius: 999px;
  box-shadow: var(--shadow);
  z-index: 60;
}
@media (min-width: 560px) {
  .sheet-panel {
    left: 50%;
    right: auto;
    transform: translateX(-50%);
    width: 460px;
    border-radius: 20px;
    bottom: 24px;
  }
}
