:root {
  --bg: #f5f3ef;
  --surface: #ffffff;
  --text: #24272b;
  --muted: #737a83;
  --border: #e3dfd8;
  --accent: #2f7d6d;
  --accent-soft: #e2f0ec;
  --danger: #c4473a;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(0, 0, 0, .06), 0 4px 12px rgba(0, 0, 0, .04);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17191c;
    --surface: #212429;
    --text: #e8e9eb;
    --muted: #9aa1aa;
    --border: #33373d;
    --accent: #5cc0a9;
    --accent-soft: #23362f;
    --danger: #e87265;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

button, .button-like {
  font: inherit;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #fff;
  border-radius: 8px;
  padding: 6px 14px;
  cursor: pointer;
  white-space: nowrap;
}
button:hover, .button-like:hover { filter: brightness(1.08); }
button.ghost, .button-like.ghost { background: transparent; color: var(--accent); }
button.danger { background: transparent; border-color: var(--danger); color: var(--danger); }
button.icon { background: transparent; border: none; color: var(--muted); padding: 4px 6px; }
button.icon:hover { color: var(--text); }

input, select, textarea {
  font: inherit;
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
}
textarea { resize: vertical; }

.muted { color: var(--muted); font-size: .9em; }

/* Top bar */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between;
  padding: 12px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; font-size: 1.15rem; }
.trip-controls { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.trip-controls select { width: auto; min-width: 180px; }

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

.trip-summary {
  display: flex; flex-wrap: wrap; gap: 8px 24px; align-items: baseline;
  margin-bottom: 16px;
}
.trip-summary h1 { margin: 0; font-size: 1.6rem; }

/* Tabs */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 12px; overflow-x: auto; }
.tab {
  background: transparent; color: var(--muted);
  border: none; border-bottom: 3px solid transparent; border-radius: 0;
  padding: 10px 14px; font-weight: 600;
}
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }

/* Day pills */
.day-strip { display: flex; gap: 8px; overflow-x: auto; padding: 4px 0 12px; }
.day-pill {
  flex: none;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border);
  border-radius: 999px; padding: 6px 14px;
  text-align: center; line-height: 1.25;
}
.day-pill small { display: block; color: var(--muted); font-size: .75em; }
.day-pill.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.day-pill.active small { color: rgba(255, 255, 255, .8); }

/* Cards & layout */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
}
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.section-head h2 { margin: 0; font-size: 1.15rem; }
.empty { text-align: center; color: var(--muted); padding: 40px 16px; }

/* Timeline */
.timeline { list-style: none; margin: 0; padding: 0; position: relative; }
.timeline::before {
  content: ""; position: absolute; left: 58px; top: 8px; bottom: 8px;
  width: 2px; background: var(--border);
}
.timeline li { display: grid; grid-template-columns: 50px 1fr; gap: 24px; padding: 8px 0; position: relative; }
.timeline li::before {
  content: ""; position: absolute; left: 53px; top: 18px;
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--accent); border: 2px solid var(--surface);
}
.timeline .time { font-weight: 700; color: var(--accent); padding-top: 8px; text-align: right; font-variant-numeric: tabular-nums; }
.timeline .card { padding: 12px 14px; }
.item-head { display: flex; justify-content: space-between; gap: 8px; align-items: start; }
.item-head h3 { margin: 0; font-size: 1.02rem; }
.item-actions { display: flex; flex: none; }
.loc-link {
  display: inline-flex; gap: 4px; margin-top: 4px;
  background: none; border: none; padding: 0; color: var(--accent); font-size: .92em;
}
.loc-link:hover { text-decoration: underline; filter: none; }
.note { margin: 6px 0 0; color: var(--muted); white-space: pre-wrap; font-size: .92em; }

/* Map */
.map-layout { display: grid; grid-template-columns: 300px 1fr; gap: 16px; }
.map-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.map-list button {
  width: 100%; text-align: left;
  background: transparent; color: var(--text); border: 1px solid var(--border);
  display: grid; grid-template-columns: 26px 1fr; gap: 8px; align-items: center;
  white-space: normal;
}
.map-list button.active { border-color: var(--accent); background: var(--accent-soft); }
.map-list .num {
  width: 24px; height: 24px; border-radius: 50%;
  background: var(--accent); color: #fff; display: grid; place-items: center; font-size: .8em; font-weight: 700;
}
.map-list small { display: block; color: var(--muted); }
.map-frame { width: 100%; height: 520px; border: 0; border-radius: var(--radius); background: var(--border); }
.map-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.map-actions a { text-decoration: none; }

/* Expenses */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat .label { color: var(--muted); font-size: .85em; }
.stat .value { font-size: 1.45rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.cost-layout { display: grid; grid-template-columns: 1fr 320px; gap: 16px; align-items: start; }
.bars { display: flex; flex-direction: column; gap: 10px; }
.bar-row { display: grid; grid-template-columns: 48px 1fr auto; gap: 8px; align-items: center; font-size: .92em; }
.bar-track { height: 10px; background: var(--bg); border-radius: 999px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 999px; }
.bar-row .amt { font-variant-numeric: tabular-nums; color: var(--muted); }

.table-wrap { overflow-x: auto; }
td { white-space: nowrap; }
table { width: 100%; border-collapse: collapse; font-size: .95em; }
th, td { padding: 9px 6px; text-align: left; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 600; font-size: .85em; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tfoot td { font-weight: 700; border-bottom: none; }
.tag {
  display: inline-block; padding: 1px 8px; border-radius: 999px;
  font-size: .8em; color: #fff; white-space: nowrap;
}

/* Login */
.login-step { display: flex; flex-direction: column; gap: 12px; }
.login-step[hidden] { display: none; }
.login-step p { margin: 0; }
button.link { align-self: flex-start; background: none; border: none; padding: 0; color: var(--accent); font-size: .9em; }
button.link:hover { text-decoration: underline; filter: none; }

/* Dialog */
dialog {
  border: none; border-radius: var(--radius);
  padding: 0; width: min(440px, calc(100vw - 32px));
  background: var(--surface); color: var(--text);
  box-shadow: 0 20px 50px rgba(0, 0, 0, .25);
}
dialog::backdrop { background: rgba(0, 0, 0, .35); }
dialog form { padding: 20px; display: flex; flex-direction: column; gap: 12px; }
dialog h3 { margin: 0 0 4px; }
dialog label { display: flex; flex-direction: column; gap: 4px; font-size: .9em; color: var(--muted); }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.dialog-actions { display: flex; gap: 8px; margin-top: 6px; }
.spacer { flex: 1; }

@media (max-width: 760px) {
  .map-layout, .cost-layout { grid-template-columns: 1fr; }
  .map-frame { height: 360px; }
  .topbar { padding: 10px 16px; }
  .trip-controls select { min-width: 0; flex: 1; }
}

/* Favorites */
.fav-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 12px; }
.fav-card { display: flex; flex-direction: column; gap: 8px; }
.fav-meta { display: grid; grid-template-columns: 22px 1fr; gap: 6px 4px; margin: 0; font-size: .92em; }
.fav-meta dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.fav-meta a { color: var(--accent); }
.pre { white-space: pre-wrap; }
.fav-actions { margin-top: auto; padding-top: 4px; }
.badge {
  display: inline-block; vertical-align: middle; margin-left: 4px;
  padding: 1px 8px; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent);
  font-size: .72em; font-weight: 600;
}

/* Sync */
.sync-box { display: flex; align-items: center; gap: 2px; }
.sync-status { font-size: .85em; color: var(--muted); white-space: nowrap; }
.sync-status.error { color: var(--danger); }

/* Members */
.member-box { border-top: 1px solid var(--border); padding-top: 12px; display: flex; flex-direction: column; gap: 8px; }
.member-box h4 { margin: 0; font-size: .95rem; }
.member-box p { margin: 0; font-size: .85em; }
.member-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; font-size: .9em; }
.member-list li { display: flex; align-items: center; gap: 6px; }
.member-list li > span:first-child { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.badge.pending { background: var(--bg); color: var(--muted); }
.invite-row { display: flex; gap: 8px; }
