:root {
  --sky-1: #a99de9;
  --sky-2: #d9a3d8;
  --sky-3: #f7a38c;
  --sky-4: #fcc56f;
  --sky-5: #fde9a6;
  --dusk: #6e5a96;
  --dusk-deep: #4d3d73;
  --ink: #3b2f5c;
  --muted: #7d6f99;
  --coral: #f2765a;
  --coral-soft: #ffe1d6;
  --gold: #fbbf4f;
  --sky-blue: #7cc3e8;
  --mint: #6cc9a1;
  --red: #e25555;
  --card: rgba(255, 255, 255, 0.82);
  --card-strong: rgba(255, 255, 255, 0.94);
  --line: rgba(110, 90, 150, 0.15);
  --shadow: 0 10px 30px rgba(77, 61, 115, 0.18);
  --radius: 22px;
  --radius-sm: 14px;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: "Nunito", "Noto Sans TC", system-ui, sans-serif;
  color: var(--ink);
  background: linear-gradient(180deg, var(--sky-1) 0%, var(--sky-2) 28%, var(--sky-3) 55%, var(--sky-4) 78%, var(--sky-5) 100%) fixed;
  background-color: var(--sky-3);
  min-height: 100vh;
  line-height: 1.5;
}
a { color: inherit; }
h1, h2, h3, h4 { margin: 0 0 .5rem; line-height: 1.25; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.05rem; }
small, .muted { color: var(--muted); }

/* ---------- scenery ---------- */
.scenery { position: fixed; inset: 0; pointer-events: none; z-index: 0; overflow: hidden; }
.scenery .sun {
  position: absolute; right: 8%; bottom: 14vh; width: 220px; height: 220px; border-radius: 50%;
  background: radial-gradient(circle at 50% 45%, #ffb36b, #f7834f 70%);
  box-shadow: 0 0 120px 60px rgba(255, 190, 110, .45);
}
.scenery .rays {
  position: absolute; right: calc(8% - 290px); bottom: calc(14vh - 290px); width: 800px; height: 800px;
  background: repeating-conic-gradient(rgba(255, 240, 200, .18) 0 6deg, transparent 6deg 14deg);
  border-radius: 50%; mask: radial-gradient(circle, #000 20%, transparent 65%);
  -webkit-mask: radial-gradient(circle, #000 20%, transparent 65%);
}
.scenery .hills { position: absolute; left: 0; right: 0; bottom: 0; width: 100%; height: 22vh; }
.cloud {
  position: absolute; height: 46px; border-radius: 40px;
  background: linear-gradient(180deg, #fff3ea, #f9d6cc);
  opacity: .85;
}
.cloud::before, .cloud::after { content: ""; position: absolute; background: inherit; border-radius: 50%; }
.cloud::before { width: 60px; height: 60px; left: 22%; top: -30px; }
.cloud::after { width: 80px; height: 80px; left: 48%; top: -44px; }
.cloud.c1 { width: 240px; top: 6%; left: -40px; }
.cloud.c2 { width: 280px; top: 32%; right: -60px; }
.cloud.c3 { width: 180px; top: 48%; left: 12%; opacity: .55; }
.sparkle { position: absolute; color: #fff8e1; opacity: .85; font-size: 14px; animation: twinkle 3s ease-in-out infinite; }
@keyframes twinkle { 50% { opacity: .25; transform: scale(.8); } }
@media (prefers-reduced-motion: reduce) { .sparkle { animation: none; } }

/* ---------- layout ---------- */
.app { position: relative; z-index: 1; display: grid; grid-template-columns: 240px 1fr; gap: 20px; padding: 20px; max-width: 1500px; margin: 0 auto; }
.sidebar {
  position: sticky; top: 20px; align-self: start; height: calc(100vh - 40px);
  background: rgba(77, 61, 115, .55); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-radius: var(--radius); padding: 18px 14px; color: #fff; display: flex; flex-direction: column; gap: 6px;
  box-shadow: var(--shadow); overflow-y: auto;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 1.15rem; padding: 4px 8px 12px; text-decoration: none; }
.brand svg { width: 46px; height: 34px; flex: none; }
.trip-switch select {
  width: 100%; border: 0; border-radius: 12px; padding: 8px 10px; font: inherit; font-weight: 700;
  background: rgba(255, 255, 255, .2); color: #fff; margin-bottom: 8px;
}
.trip-switch option { color: var(--ink); }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 14px; text-decoration: none;
  font-weight: 700; color: rgba(255, 255, 255, .9); transition: background .15s;
}
.nav a:hover { background: rgba(255, 255, 255, .14); }
.nav a.active { background: linear-gradient(90deg, var(--coral), var(--gold)); color: #fff; box-shadow: 0 4px 14px rgba(242, 118, 90, .45); }
.nav .ico { width: 22px; text-align: center; }
.nav .badge { margin-left: auto; }
.sidebar .spacer { flex: 1; }
.sidebar .me { font-size: .85rem; padding: 8px 12px; opacity: .9; }

.main { display: flex; flex-direction: column; gap: 20px; min-width: 0; }

/* top dashboard */
.stats { display: grid; grid-template-columns: 1.1fr 1.2fr 1fr; gap: 16px; }
.card {
  background: var(--card); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow); min-width: 0;
}
.card-title { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.card-title h3 { margin: 0; font-size: .95rem; color: var(--muted); font-weight: 800; letter-spacing: .02em; }
.big { font-size: 1.9rem; font-weight: 800; line-height: 1.1; }
.big small { font-size: .9rem; font-weight: 700; }
.progress { height: 12px; background: rgba(110, 90, 150, .12); border-radius: 99px; overflow: hidden; margin: 10px 0; }
.progress > span { display: block; height: 100%; border-radius: 99px; background: linear-gradient(90deg, var(--gold), var(--coral)); }
.progress.over > span { background: linear-gradient(90deg, var(--coral), var(--red)); }
.kv { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 14px; }
.kv div { display: flex; flex-direction: column; }
.kv dt, .kv .k { font-size: .78rem; color: var(--muted); font-weight: 700; }
.kv dd, .kv .v { margin: 0; font-weight: 800; }
.pill-status { display: inline-block; padding: 3px 10px; border-radius: 99px; background: var(--coral-soft); color: var(--coral); font-weight: 800; font-size: .8rem; }

.mini-timeline { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; max-height: 150px; overflow-y: auto; }
.mini-timeline li a { display: flex; gap: 10px; align-items: center; text-decoration: none; padding: 4px 6px; border-radius: 10px; }
.mini-timeline li a:hover { background: rgba(110, 90, 150, .08); }
.mini-timeline .t { font-variant-numeric: tabular-nums; font-weight: 800; color: var(--coral); min-width: 44px; font-size: .9rem; }
.mini-timeline .done { text-decoration: line-through; opacity: .55; }

/* bottom: content + detail */
.lower { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(300px, 1fr); gap: 20px; align-items: start; }
.lower.wide { grid-template-columns: 1fr; }
.detail { position: sticky; top: 20px; max-height: calc(100vh - 40px); overflow-y: auto; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.section-head h2 { margin: 0; }

/* ---------- components ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px; border: 0; cursor: pointer; font: inherit; font-weight: 800;
  padding: 8px 16px; border-radius: 99px; text-decoration: none; font-size: .9rem;
  background: linear-gradient(90deg, var(--coral), #f79a5b); color: #fff; box-shadow: 0 4px 12px rgba(242, 118, 90, .35);
}
.btn:hover { filter: brightness(1.05); }
.btn.ghost { background: rgba(110, 90, 150, .1); color: var(--dusk-deep); box-shadow: none; }
.btn.danger { background: rgba(226, 85, 85, .12); color: var(--red); box-shadow: none; }
.btn.ok { background: linear-gradient(90deg, #5bbf94, var(--mint)); box-shadow: 0 4px 12px rgba(108, 201, 161, .4); }
.btn.sm { padding: 5px 12px; font-size: .8rem; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }
.badge { display: inline-block; min-width: 22px; padding: 1px 8px; border-radius: 99px; background: var(--gold); color: var(--dusk-deep); font-weight: 800; font-size: .75rem; text-align: center; }
.chip {
  display: inline-flex; align-items: center; gap: 4px; padding: 5px 12px; border-radius: 99px; font-weight: 700; font-size: .85rem;
  background: rgba(255, 255, 255, .7); text-decoration: none; border: 1px solid var(--line);
}
.chip.active { background: var(--dusk); color: #fff; border-color: var(--dusk); }
.tag { font-size: .72rem; font-weight: 800; padding: 2px 8px; border-radius: 99px; background: rgba(124, 195, 232, .25); color: #2f7aa3; }
.tag.coral { background: var(--coral-soft); color: var(--coral); }
.tag.mint { background: rgba(108, 201, 161, .2); color: #2f8a62; }
.tag.gray { background: rgba(110, 90, 150, .12); color: var(--muted); }
.empty { text-align: center; color: var(--muted); padding: 24px 10px; }
.empty .e { font-size: 2.2rem; display: block; margin-bottom: 6px; }

.list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.row {
  display: flex; align-items: center; gap: 12px; padding: 10px 14px; border-radius: var(--radius-sm);
  background: var(--card-strong); border: 1px solid var(--line); text-decoration: none; cursor: pointer;
}
.row:hover { border-color: rgba(242, 118, 90, .5); }
.row .grow { flex: 1; min-width: 0; }
.row .title { font-weight: 800; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .amount { font-weight: 800; font-variant-numeric: tabular-nums; }

table.table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.table th { text-align: left; font-size: .78rem; color: var(--muted); font-weight: 800; padding: 8px 10px; border-bottom: 2px solid var(--line); }
.table td { padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; font-weight: 700; }
.table-wrap { overflow-x: auto; }
.neg { color: var(--red); }
.pos { color: #2f8a62; }

/* itinerary board */
.board { display: flex; gap: 14px; overflow-x: auto; padding-bottom: 10px; scroll-snap-type: x proximity; }
.day-col {
  flex: 0 0 270px; scroll-snap-align: start; background: rgba(255, 255, 255, .62); border-radius: var(--radius);
  padding: 14px; display: flex; flex-direction: column; gap: 10px; border: 2px solid transparent;
}
.day-col.today { border-color: var(--coral); background: rgba(255, 255, 255, .8); }
.day-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 6px; }
.day-num { font-size: .78rem; font-weight: 800; color: #fff; background: var(--dusk); padding: 2px 10px; border-radius: 99px; }
.day-date { font-weight: 800; margin-top: 4px; }
.day-title { font-size: .85rem; color: var(--muted); }
.sortable { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; min-height: 60px; }
.item-card {
  background: #fff; border-radius: var(--radius-sm); padding: 10px 12px; box-shadow: 0 2px 8px rgba(77, 61, 115, .1);
  display: flex; gap: 10px; align-items: flex-start; cursor: grab; border: 1px solid var(--line);
}
.item-card:active { cursor: grabbing; }
.item-card .handle { color: var(--muted); user-select: none; }
.item-card .time { font-size: .78rem; font-weight: 800; color: var(--coral); }
.item-card .name { font-weight: 800; }
.item-card.is-done .name { text-decoration: line-through; opacity: .5; }
.sortable-ghost { opacity: .4; background: var(--coral-soft); }
.check { border: 0; background: none; cursor: pointer; font-size: 1.1rem; padding: 0; line-height: 1; }

/* places grid */
.grid-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; }
.place-card { background: var(--card-strong); border-radius: var(--radius-sm); padding: 14px; border: 1px solid var(--line); cursor: pointer; text-decoration: none; display: block; }
.place-card:hover { border-color: rgba(242, 118, 90, .5); transform: translateY(-1px); }
.place-card .ico { font-size: 1.6rem; }
.place-card .name { font-weight: 800; margin: 4px 0; }
.place-card p { margin: 0; font-size: .85rem; color: var(--muted); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

/* detail */
.detail-hero { font-size: 2.2rem; }
.map-frame { width: 100%; height: 220px; border: 0; border-radius: var(--radius-sm); margin: 10px 0; background: #eee; }
.detail p.desc { white-space: pre-wrap; }

/* bars */
.bars { display: flex; flex-direction: column; gap: 8px; }
.bar-row { display: grid; grid-template-columns: 70px 1fr auto; gap: 10px; align-items: center; font-size: .88rem; font-weight: 700; }
.bar { height: 12px; background: rgba(110, 90, 150, .1); border-radius: 99px; overflow: hidden; }
.bar > span { display: block; height: 100%; background: linear-gradient(90deg, var(--sky-blue), var(--dusk)); border-radius: 99px; }

/* forms */
form .field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
form label { font-size: .82rem; font-weight: 800; color: var(--muted); }
form input:not([type=checkbox]), form select, form textarea {
  font: inherit; padding: 9px 12px; border-radius: 12px; border: 1.5px solid var(--line); background: #fff; color: var(--ink); width: 100%;
}
form input:focus, form select:focus, form textarea:focus { outline: none; border-color: var(--coral); box-shadow: 0 0 0 3px var(--coral-soft); }
.field.check-field { flex-direction: row; align-items: center; gap: 8px; }
.errorlist { list-style: none; margin: 2px 0 0; padding: 0; color: var(--red); font-size: .82rem; font-weight: 700; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.form-grid .field.full { grid-column: 1 / -1; }
.notice { padding: 10px 14px; border-radius: 12px; background: rgba(251, 191, 79, .2); font-size: .85rem; font-weight: 700; margin-bottom: 12px; }

/* diff */
.diff { font-size: .85rem; margin: 6px 0 0; padding: 0; list-style: none; }
.diff li { padding: 2px 0; }
.diff del { color: var(--red); background: rgba(226, 85, 85, .08); text-decoration: line-through; padding: 0 4px; border-radius: 4px; }
.diff ins { color: #2f8a62; background: rgba(108, 201, 161, .15); text-decoration: none; padding: 0 4px; border-radius: 4px; }

/* chat */
.chat-log { display: flex; flex-direction: column; gap: 10px; max-height: 55vh; overflow-y: auto; padding: 4px; }
.bubble { max-width: 80%; padding: 10px 14px; border-radius: 18px; white-space: pre-wrap; font-size: .93rem; }
.bubble.me { align-self: flex-end; background: linear-gradient(135deg, var(--coral), #f79a5b); color: #fff; border-bottom-right-radius: 6px; }
.bubble.other { align-self: flex-end; background: rgba(124, 195, 232, .3); border-bottom-right-radius: 6px; }
.bubble.ai { align-self: flex-start; background: #fff; border: 1px solid var(--line); border-bottom-left-radius: 6px; }
.bubble .who { font-size: .72rem; font-weight: 800; opacity: .75; display: block; }
.chat-form { display: flex; gap: 8px; margin-top: 12px; }
.chat-form input { flex: 1; }
.htmx-indicator { display: none; }
.htmx-request .htmx-indicator, .htmx-request.htmx-indicator { display: inline; }

/* toasts */
.toasts { position: fixed; top: 16px; left: 50%; transform: translateX(-50%); z-index: 50; display: flex; flex-direction: column; gap: 8px; width: min(92vw, 420px); }
.toast { background: var(--card-strong); border-radius: 14px; padding: 10px 16px; box-shadow: var(--shadow); font-weight: 700; border-left: 5px solid var(--mint); animation: fadeout 5s forwards; }
.toast.error { border-color: var(--red); }
.toast.info { border-color: var(--gold); }
@keyframes fadeout { 85% { opacity: 1; } 100% { opacity: 0; visibility: hidden; } }

/* auth pages */
.auth-wrap { position: relative; z-index: 1; min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.auth-card { width: min(100%, 400px); }
.auth-card .brand { color: var(--ink); justify-content: center; font-size: 1.4rem; }

/* ---------- responsive ---------- */
@media (max-width: 1100px) {
  .stats { grid-template-columns: 1fr 1fr; }
  .stats .card:nth-child(2) { grid-column: 1 / -1; order: -1; }
  .lower { grid-template-columns: 1fr; }
  .detail { position: static; max-height: none; order: -1; }
  .detail:has(.detail-empty) { display: none; }
}
@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; padding: 12px 16px; gap: 14px; }
  .sidebar { position: static; height: auto; flex-direction: column; padding: 12px; }
  .nav { display: flex; overflow-x: auto; gap: 4px; }
  .nav a { white-space: nowrap; padding: 8px 12px; }
  .sidebar .spacer, .sidebar .me { display: none; }
  .stats { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .big { font-size: 1.6rem; }
  .scenery .sun { width: 140px; height: 140px; }
}
.row .grow .title, .row .grow small { display: block; }
.row .grow small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cur-switch select { font: inherit; font-size: .8rem; font-weight: 800; border: 1px solid var(--line); border-radius: 99px; padding: 3px 8px; background: #fff; color: var(--dusk-deep); cursor: pointer; }
.home-cur { font-size: .78rem; color: var(--muted); font-weight: 700; }
.orig { font-size: .78rem; color: var(--muted); font-weight: 600; display: block; }
.notice.warn { background: rgba(242, 118, 90, .14); color: #a6402a; }
.conflict-ok { background: var(--coral-soft); padding: 8px 12px; border-radius: 12px; }
.conflict-ok label { color: var(--coral) !important; }
.form-grid { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
form input, form select, form textarea { min-width: 0; max-width: 100%; }
.detail { overflow-x: hidden; }
@media (max-width: 760px) { .form-grid { grid-template-columns: minmax(0, 1fr); } }

/* footer */
.site-footer {
  position: relative; z-index: 1; display: flex; justify-content: center; align-items: center; gap: 14px; flex-wrap: wrap;
  padding: 10px 16px 22px; color: #fff; font-weight: 700; font-size: .85rem; text-shadow: 0 1px 6px rgba(77, 61, 115, .5);
}
.carpe { display: inline-flex; align-items: center; gap: 4px; }
.carpe-text {
  font-style: italic; font-weight: 800; letter-spacing: .04em;
  background: linear-gradient(90deg, #fff, #ffe08a, #ffb3c1, #fff); background-size: 200% 100%;
  -webkit-background-clip: text; background-clip: text; color: transparent; text-shadow: none;
  animation: shimmer 3s linear infinite;
}
.heart { display: inline-block; animation: beat 1.4s ease-in-out infinite; text-shadow: none; }
.heart:nth-child(3) { animation-delay: .2s; }
.heart:nth-child(4) { animation-delay: .4s; }
@keyframes shimmer { to { background-position: -200% 0; } }
@keyframes beat { 0%, 100% { transform: translateY(0) scale(1); } 30% { transform: translateY(-4px) scale(1.25); } 60% { transform: translateY(0) scale(.95); } }
@media (prefers-reduced-motion: reduce) { .carpe-text, .heart { animation: none; } }
.auth-wrap { min-height: calc(100vh - 60px); }
