/* 洄流 Reflow — 共用基底
   淺色 = 沙洲日光；深色 = 夜潛
   潮汐藍青主色 × 珊瑚橘警示 × Fraunces 襯線標題 × JetBrains Mono 數據 */

:root {
  --bg: #F3F0E8;
  --bg-deep: #ECE6D8;
  --card: #FFFFFF;
  --surface: #EDE8DB;
  --line: #E0D9C8;
  --ink: #1A2B3A;
  --dim: #68737E;
  --brand: #1B3F63;
  --brand-soft: rgba(27, 63, 99, .10);
  --brand-logo: #1B3F63;
  --coral: #C4574A;
  --coral-soft: rgba(196, 87, 74, .09);
  --warn: #B26B2C;
  --warn-soft: rgba(178, 107, 44, .10);
  --ok: #2E8C6A;
  --ok-soft: rgba(46, 140, 106, .10);
  --shadow: 0 1px 2px rgba(24, 44, 51, .05), 0 4px 14px rgba(24, 44, 51, .05);
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, monospace;
  --serif: "Fraunces", "Noto Serif TC", Georgia, serif;
  --sp-1: 4px; --sp-2: 8px; --sp-3: 10px; --sp-4: 14px; --sp-5: 16px; --sp-6: 26px;
  --r: 14px; --r-sm: 10px; --r-xs: 6px;
  --fs-stat: 24px; --fs-title: 16px; --fs-body: 14px; --fs-sub: 13px; --fs-label: 12px;
  --ease-out: cubic-bezier(.23, 1, .32, 1);
}

:root[data-theme="dark"] {
  --bg: #0C141D;
  --bg-deep: #081019;
  --card: #131F2C;
  --surface: #1A2938;
  --line: #25384C;
  --ink: #E8E4D8;
  --dim: #8794A2;
  --brand: #7FB2D9;
  --brand-soft: rgba(127, 178, 217, .13);
  --brand-logo: #9CC4E4;
  --coral: #D96757;
  --coral-soft: rgba(217, 103, 87, .12);
  --warn: #D99A45;
  --warn-soft: rgba(217, 154, 69, .11);
  --ok: #46B388;
  --ok-soft: rgba(70, 179, 136, .11);
  --shadow: 0 6px 18px rgba(0, 0, 0, .3);
}

* { margin: 0; padding: 0; box-sizing: border-box; }
button { touch-action: manipulation; -webkit-tap-highlight-color: transparent; }

body {
  background: linear-gradient(180deg, var(--bg) 0%, var(--bg-deep) 100%) fixed;
  color: var(--ink);
  font-family: "Noto Sans TC", "Inter", -apple-system, "PingFang TC", sans-serif;
  min-height: 100vh;
  line-height: 1.6;
  overflow-x: hidden;
  padding-bottom: env(safe-area-inset-bottom);
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; letter-spacing: -.01em; }

.ic {
  width: 16px; height: 16px;
  stroke: currentColor; fill: none;
  stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round;
  vertical-align: -3px; flex: none;
}
.ic-lg { width: 20px; height: 20px; }

/* ---------- topbar / tabs ---------- */

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(16px + env(safe-area-inset-top)) 18px 8px;
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
}
.brand { display: flex; align-items: center; gap: 9px; }
.brand .logo { color: var(--brand); }
.brand h1 { font-size: 18px; font-weight: 700; letter-spacing: .2px; font-family: var(--serif); }
.brand .sub { color: var(--dim); font-size: var(--fs-label); margin-left: 2px; }
.topbar-right { display: flex; align-items: center; gap: 8px; }
.today-label { color: var(--dim); font-size: 13px; }
.icon-btn { background: none; border: none; color: var(--dim); cursor: pointer; padding: 6px 8px; border-radius: 9px; }
.icon-btn:hover { color: var(--ink); background: var(--surface); }

main { padding: 14px 16px 64px; max-width: 900px; margin: 0 auto; }

/* ---------- console 佈局：手機底部列 / 桌面側欄 ---------- */

.console-page main {
  padding-bottom: calc(86px + env(safe-area-inset-bottom));
}
.view-title { display: none; }

/* 手機底部列 */
.bottom-bar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 25;
  display: flex;
  background: color-mix(in srgb, var(--card) 92%, transparent);
  backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
}
.bottom-bar button {
  flex: 1;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  background: none; border: none; cursor: pointer;
  color: var(--dim); font-family: inherit; font-size: 10.5px; font-weight: 600;
  padding: 5px 0 3px; border-radius: 10px;
}
.bottom-bar button .ic { width: 21px; height: 21px; stroke-width: 1.7; }
.bottom-bar button.active { color: var(--brand); }
.bottom-bar button:active { transform: scale(.94); }

/* 更多 sheet */
.sheet-backdrop {
  position: fixed; inset: 0; z-index: 40;
  background: rgba(8, 16, 19, .45);
  display: none; align-items: flex-end;
}
.sheet-backdrop.open { display: flex; }
.more-sheet {
  background: var(--card);
  border-radius: 18px 18px 0 0;
  width: 100%;
  padding: 10px 16px calc(18px + env(safe-area-inset-bottom));
  animation: slide-up 240ms var(--ease-out);
  display: grid; grid-template-columns: 1fr 1fr; gap: 8px;
}
.sheet-grip {
  grid-column: 1 / -1;
  width: 40px; height: 4px; border-radius: 999px;
  background: var(--line);
  margin: 2px auto 8px;
}
.more-sheet button, .more-sheet .sheet-link {
  display: flex; align-items: center; gap: 10px;
  background: var(--surface); border: none; border-radius: var(--r-sm);
  color: var(--ink); font-family: inherit; font-size: 15px; font-weight: 600;
  padding: 13px 16px; cursor: pointer;
  text-decoration: none;
}
.more-sheet button.active { color: var(--brand); }
.more-sheet button:active, .more-sheet .sheet-link:active { transform: scale(.98); }
.more-sheet .sheet-link { grid-column: 1 / -1; justify-content: center; color: var(--dim); background: none; font-size: 13.5px; }

/* 桌面側欄 */
.side-nav { display: none; }
@media (min-width: 900px) {
  .console-page { display: flex; }
  .bottom-bar, .sheet-backdrop { display: none !important; }
  .console-page main { padding-bottom: 64px; }

  .side-nav {
    display: flex; flex-direction: column;
    width: 218px; flex: none;
    position: sticky; top: 0; height: 100dvh;
    border-right: 1px solid var(--line);
    background: color-mix(in srgb, var(--card) 55%, transparent);
    padding: 22px 14px calc(16px + env(safe-area-inset-bottom));
  }
  .side-brand { display: flex; align-items: center; gap: 10px; padding: 0 8px 20px; color: var(--brand-logo); }
  .side-brand h1 { font-family: var(--serif); font-size: 16.5px; color: var(--ink); line-height: 1.3; }
  .side-brand span { font-size: 11px; color: var(--dim); letter-spacing: .1em; }
  .side-tabs { display: flex; flex-direction: column; gap: 2px; }
  .side-tabs button {
    display: flex; align-items: center; gap: 10px;
    background: none; border: none; border-radius: var(--r-sm);
    color: var(--dim); font-family: inherit; font-size: 14.5px; font-weight: 500;
    padding: 10px 12px; cursor: pointer; text-align: left;
    transition: background 120ms, color 120ms;
  }
  .side-tabs button:hover { color: var(--ink); background: var(--surface); }
  .side-tabs button.active { background: var(--brand); color: var(--bg); font-weight: 700; }
  .side-foot { margin-top: auto; display: flex; flex-direction: column; gap: 2px; }
  .side-foot-link {
    display: flex; align-items: center; gap: 9px;
    background: none; border: none; border-radius: var(--r-sm);
    color: var(--dim); font-family: inherit; font-size: 13px;
    padding: 9px 12px; cursor: pointer; text-decoration: none; text-align: left;
  }
  .side-foot-link:hover { color: var(--ink); background: var(--surface); }

  .console-main { flex: 1; min-width: 0; }
  .console-page .topbar { padding-top: 18px; }
  .console-page .topbar .brand, .console-page .mobile-only { display: none; }
  .view-title { display: inline; font-family: var(--serif); font-weight: 700; font-size: 15px; }
  .console-page main { max-width: 1060px; }
}

/* ---------- cards / sections ---------- */

.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--r); box-shadow: var(--shadow);
  padding: var(--sp-5); margin-bottom: var(--sp-4);
}
.card.clickable { cursor: pointer; transition: transform 120ms var(--ease-out); }
.card.clickable:active { transform: scale(.99); }

.section-title {
  display: flex; align-items: center; justify-content: space-between;
  font-family: var(--serif); font-size: var(--fs-title); font-weight: 700;
  margin: var(--sp-6) 0 var(--sp-3);
}
.section-title:first-child { margin-top: var(--sp-2); }
.section-title .count { color: var(--dim); font-size: var(--fs-sub); font-weight: 400; }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: var(--sp-3); }
.stat {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--r);
  padding: 12px 14px; box-shadow: var(--shadow);
}
.stat .label { color: var(--dim); font-size: var(--fs-label); display: flex; align-items: center; gap: 5px; }
.stat .num { font-family: var(--mono); font-size: var(--fs-stat); font-weight: 700; line-height: 1.3; }
.stat .num small { font-size: 13px; font-weight: 400; color: var(--dim); }
.stat.alert .num { color: var(--coral); }
.stat.good .num { color: var(--ok); }

.empty { color: var(--dim); font-size: var(--fs-sub); text-align: center; padding: 22px 0; }

/* ---------- badges / chips ---------- */

.badge {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: var(--fs-label); font-weight: 600;
  padding: 1.5px 9px; border-radius: 999px;
  background: var(--surface); color: var(--dim);
  white-space: nowrap;
}
.badge.brand { background: var(--brand-soft); color: var(--brand); }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.danger { background: var(--coral-soft); color: var(--coral); }

.chip {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: var(--fs-label); padding: 2px 10px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--card); color: var(--ink);
}
.chip .dot { width: 8px; height: 8px; border-radius: 50%; }

.filter-row { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: var(--sp-4); }
.filter-row button {
  background: var(--card); border: 1px solid var(--line); color: var(--dim);
  font-size: var(--fs-sub); font-family: inherit; padding: 5px 13px;
  border-radius: 999px; cursor: pointer;
}
.filter-row button.active { background: var(--brand); border-color: var(--brand); color: var(--bg); font-weight: 700; }

/* ---------- buttons ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  background: var(--brand); color: var(--bg);
  border: none; border-radius: var(--r-sm);
  font-size: var(--fs-body); font-weight: 700; font-family: inherit;
  padding: 9px 18px; cursor: pointer;
  transition: filter 120ms var(--ease-out), transform 120ms var(--ease-out);
}
.btn:hover { filter: brightness(1.08); }
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.ghost { background: transparent; color: var(--brand); border: 1px solid var(--brand); }
.btn.subtle { background: var(--surface); color: var(--ink); }
.btn.danger { background: transparent; color: var(--coral); border: 1px solid var(--coral); }
.btn.sm { font-size: var(--fs-label); padding: 5px 12px; border-radius: 8px; }

/* ---------- list rows ---------- */

.row {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 10px;
  padding: 10px 0; border-bottom: 1px solid var(--line);
}
.row:last-child { border-bottom: none; }
.row .main-line { font-size: var(--fs-body); font-weight: 500; display: flex; align-items: center; gap: 7px; flex-wrap: wrap; overflow-wrap: anywhere; }
.row .sub-line { color: var(--dim); font-size: var(--fs-sub); margin-top: 1px; overflow-wrap: anywhere; }
.row .side { text-align: right; flex: none; }
.row-actions { display: flex; gap: 6px; margin-top: 6px; flex-wrap: wrap; }

/* ---------- form ---------- */

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 12px; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field.full { grid-column: 1 / -1; }
.field label { font-size: var(--fs-label); color: var(--dim); font-weight: 600; }
.field label .req { color: var(--coral); }
.field input, .field select, .field textarea {
  background: var(--bg); border: 1px solid var(--line); border-radius: var(--r-sm);
  color: var(--ink); font-size: 16px; font-family: inherit; /* ≥16px：iOS 聚焦才不會自動縮放頁面 */
  padding: 8px 11px; width: 100%;
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none; border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-soft);
}
.field textarea { min-height: 64px; resize: vertical; }
.field.check { flex-direction: row; align-items: center; gap: 8px; }
.field.check input { width: 18px; height: 18px; accent-color: var(--brand); }
.field.check label { font-size: var(--fs-body); color: var(--ink); font-weight: 500; }
.form-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: var(--sp-5); }
.form-actions .spacer { margin-right: auto; }

/* ---------- modal ---------- */

.modal-backdrop {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(8, 16, 19, .45);
  display: none; align-items: flex-end; justify-content: center;
  padding: 0;
}
.modal-backdrop.open { display: flex; }
.modal {
  background: var(--card); border-radius: 18px 18px 0 0;
  width: 100%; max-width: 640px; max-height: 88vh; overflow-y: auto;
  padding: 20px 18px calc(20px + env(safe-area-inset-bottom));
  animation: slide-up 240ms var(--ease-out);
}
@media (min-width: 700px) {
  .modal-backdrop { align-items: center; padding: 24px; }
  .modal { border-radius: 18px; }
}
@keyframes slide-up { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }
.modal h3 {
  font-family: var(--serif); font-size: 17px; margin-bottom: var(--sp-4);
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
}
.modal h3 .badge { font-family: "Noto Sans TC", sans-serif; }
.modal .close-x { background: none; border: none; color: var(--dim); font-size: 20px; cursor: pointer; padding: 2px 8px; }

/* ---------- toast ---------- */

#toast {
  position: fixed; left: 50%; bottom: calc(28px + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(8px);
  background: var(--ink); color: var(--bg);
  font-size: var(--fs-sub); font-weight: 600;
  padding: 9px 18px; border-radius: 999px;
  opacity: 0; pointer-events: none; z-index: 90;
  transition: opacity 160ms, transform 160ms var(--ease-out);
  max-width: 86vw; text-align: center;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.error { background: var(--coral); color: #fff; }

.loading { color: var(--dim); text-align: center; padding: 40px 0; }

/* ---------- 行程月曆 ---------- */

.cal-card { padding: 12px 14px 10px; }
.cal-card.collapsed { padding: 4px 14px; }
.cal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 4px; }
.cal-card.collapsed .cal-head { margin-bottom: 0; justify-content: center; }
.cal-head .icon-btn { font-size: 18px; line-height: 1; padding: 4px 12px; }
.cal-title-btn {
  display: inline-flex; align-items: center; gap: 7px;
  background: none; border: none; cursor: pointer;
  color: var(--ink); font-family: inherit; padding: 6px 10px; border-radius: 9px;
}
.cal-title-btn:hover { background: var(--surface); }
.cal-title-btn .ic { color: var(--dim); transition: transform 160ms var(--ease-out); }
.cal-title { font-weight: 700; font-size: 15px; letter-spacing: .08em; }
.cal-week {
  display: grid; grid-template-columns: repeat(7, 1fr);
  text-align: center; color: var(--dim); font-size: 11px;
  margin-bottom: 2px;
}
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }
.cal-cell {
  position: relative;
  min-height: 44px;
  background: none; border: none; border-radius: 9px;
  font-family: inherit; color: var(--ink); font-size: 13px;
  cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: flex-start;
  padding: 5px 0 3px; gap: 3px;
}
.cal-cell:hover { background: var(--surface); }
.cal-cell.blank { cursor: default; }
.cal-cell.blank:hover { background: none; }
.cal-cell.today .d {
  background: var(--brand); color: var(--bg);
  border-radius: 999px; min-width: 22px; height: 22px;
  display: inline-flex; align-items: center; justify-content: center;
  font-weight: 700;
}
.cal-cell .dots { display: flex; gap: 2.5px; flex-wrap: wrap; justify-content: center; max-width: 90%; }
.cal-cell .dots i { width: 6px; height: 6px; border-radius: 50%; display: block; }
