/* TeamCal 樣式：兩個主題（data-theme）
 *   dusk  暮光：紫藍粉漸層背景＋白色卡片＋桃粉強調色（參考 design/refs-20261116/ref1）
 *   ocean 深海：深藍到藍綠漸層＋半透明毛玻璃卡片（參考 design/refs-20261116/ref2）
 * 行程顏色：k-normal 一般、k-repeat 重複、k-allday 全天、k-zhai 十齋日。不使用外部字體或圖片。 */

:root,
[data-theme="dusk"] {
  --page: linear-gradient(135deg, #a18cd1 0%, #8fa6f2 45%, #f5b6d8 100%);
  --surface: rgba(255, 255, 255, .58);
  --surface-2: rgba(255, 255, 255, .42);
  --fg: #2b2547;
  --muted: #514a6e;
  --line: rgba(80, 60, 150, .14);
  --edge: rgba(255, 255, 255, .75);
  --accent: #e0407f;
  --accent-fg: #ffffff;
  --accent-soft: #fde7f1;
  --nav-bg: linear-gradient(120deg, #2c2c6c, #4a3a8c);
  --nav-fg: #ffffff;
  --nav-muted: rgba(255, 255, 255, .72);
  --k-normal: #14a99c;
  --k-repeat: #6c5ce7;
  --k-allday: #e0407f;
  --k-zhai: #b7791f;
  --holiday: #d93f45;
  --workday: #b45309;
  --error-bg: #fde8e8;
  --error-fg: #8a1c1c;
  --warn-bg: #fff4d6;
  --warn-fg: #6b4300;
  --shadow: 0 10px 30px rgba(60, 40, 120, .16);
  --blur: blur(18px) saturate(140%);
  --input-bg: rgba(255, 255, 255, .85);
  color-scheme: light;
}

[data-theme="ocean"] {
  --page: linear-gradient(160deg, #18264a 0%, #1e3a5f 50%, #0d6f6c 100%);
  --surface: rgba(255, 255, 255, .09);
  --surface-2: rgba(255, 255, 255, .05);
  --fg: #f1f5f9;
  --muted: #b4c2d3;
  --line: rgba(255, 255, 255, .16);
  --edge: rgba(255, 255, 255, .2);
  --accent: #4fb3e8;
  --accent-fg: #071a2e;
  --accent-soft: rgba(79, 179, 232, .2);
  --nav-bg: rgba(8, 18, 38, .45);
  --nav-fg: #ffffff;
  --nav-muted: rgba(255, 255, 255, .7);
  --k-normal: #4fb3e8;
  --k-repeat: #f6c453;
  --k-allday: #f0657a;
  --k-zhai: #f4a261;
  --holiday: #ff9a9a;
  --workday: #f6c453;
  --error-bg: rgba(240, 101, 122, .2);
  --error-fg: #ffd9df;
  --warn-bg: rgba(246, 196, 83, .18);
  --warn-fg: #ffeab8;
  --shadow: 0 10px 30px rgba(0, 0, 0, .25);
  --blur: blur(14px);
  --input-bg: rgba(255, 255, 255, .1);
  color-scheme: dark;
}

/* 系統要求減少透明度時，毛玻璃改成實色 */
@media (prefers-reduced-transparency: reduce) {
  [data-theme="dusk"] {
    --surface: #ffffff;
    --surface-2: #f6f4fb;
    --input-bg: #ffffff;
    --blur: none;
  }
  [data-theme="ocean"] {
    --surface: #213659;
    --surface-2: #1b2d4b;
    --input-bg: #1b2d4b;
    --nav-bg: #13203d;
    --blur: none;
  }
}

* { box-sizing: border-box; }
html { background: #2c2c6c; }
html[data-theme="ocean"] { background: #18264a; }
body {
  margin: 0;
  min-height: 100vh;
  background: var(--page);
  background-attachment: fixed;
  color: var(--fg);
  font: 16px/1.6 -apple-system, BlinkMacSystemFont, "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
}
a { color: inherit; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
h1 { font-size: 24px; margin: 4px 0; letter-spacing: .02em; }
h2 { font-size: 17px; margin: 0 0 8px; }
h2.sub { font-size: 17px; margin: 4px 0; }
code { background: var(--surface-2); padding: 1px 6px; border-radius: 4px; }

/* ---- 頁首 ---- */
.bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 16px;
  /* viewport-fit=cover：頁面延伸到瀏海與底部指示條區域，內容用安全區域內距避開（2026-11-18 LINE 內建瀏覽器底部白底） */
  padding: calc(10px + env(safe-area-inset-top)) calc(20px + env(safe-area-inset-right)) 10px calc(20px + env(safe-area-inset-left));
  background: var(--nav-bg);
  color: var(--nav-fg);
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
  box-shadow: 0 4px 20px rgba(0, 0, 0, .15);
}
.brand { display: flex; align-items: center; gap: 8px; text-decoration: none; font-weight: 700; font-size: 18px; }
.logo { display: inline-grid; place-items: center; width: 32px; height: 32px; border-radius: 10px; background: var(--accent); color: var(--accent-fg); }
.tag { font-size: 12px; padding: 1px 8px; border-radius: 999px; background: #f59e0b; color: #111; }
.nav { display: flex; gap: 4px; }
/* 分頁不換行、不縮小：中文可以在任兩字之間斷行，窄螢幕會變成一字一行（2026-11-18 手機 LINE 回報） */
.nav a { text-decoration: none; padding: 6px 14px; border-radius: 999px; color: var(--nav-muted); white-space: nowrap; flex: none; }
.nav a:hover { color: var(--nav-fg); background: rgba(255, 255, 255, .1); }
.nav a.on { color: var(--nav-fg); background: rgba(255, 255, 255, .18); font-weight: 600; }
.me { margin-left: auto; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.me form { display: flex; gap: 6px; align-items: center; margin: 0; }
.name { color: var(--nav-muted); font-size: 14px; text-decoration: none; }
a.name:hover { color: var(--nav-fg); text-decoration: underline; }
.bar button.ghost { color: var(--nav-fg); border-color: rgba(255, 255, 255, .35); }
.theme-switch .chip { padding: 3px 10px; font-size: 13px; color: var(--nav-muted); border-color: rgba(255, 255, 255, .3); background: transparent; }
.theme-switch .chip.on { color: var(--nav-fg); background: rgba(255, 255, 255, .2); }

/* ---- 按鈕、輸入 ---- */
button, .button {
  display: inline-block;
  font: inherit;
  padding: 8px 16px;
  border-radius: 999px;
  border: 1px solid transparent;
  background: var(--accent);
  color: var(--accent-fg);
  cursor: pointer;
  text-decoration: none;
  font-weight: 600;
  box-shadow: 0 4px 14px rgba(0, 0, 0, .12);
}
button.ghost, .button.ghost { background: transparent; color: var(--fg); border-color: var(--line); box-shadow: none; font-weight: 500; }
.danger, button.danger, .button.danger { background: #dc2626; color: #fff; }
.chip {
  display: inline-block;
  padding: 4px 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--fg);
  text-decoration: none;
  font-size: 14px;
  box-shadow: none;
  font-weight: 500;
}
select, input, textarea {
  font: inherit;
  padding: 8px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--input-bg);
  color: var(--fg);
}
textarea { width: 100%; }
label { display: grid; gap: 4px; }
label.check { display: flex; align-items: center; gap: 6px; }
input.short { width: 80px; }
fieldset { border: 1px solid var(--line); border-radius: 12px; display: grid; gap: 8px; }
fieldset > div { display: grid; gap: 8px; }
.row { display: flex; flex-wrap: wrap; gap: 12px; }

/* ---- 版面 ---- */
main { max-width: 1040px; margin: 0 auto; padding: 20px; }
.panel, .card, .day, .preview, .admin, .month {
  background: var(--surface);
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
  border: 1px solid var(--edge);
  border-radius: 18px;
  box-shadow: var(--shadow);
}
.panel { padding: 16px 18px; margin-bottom: 16px; }
.card { display: grid; gap: 10px; max-width: 380px; padding: 18px; }
.card.wide { max-width: 680px; }
/* grid 子項預設不會縮到比內容窄：檔案選擇欄在手機上會撐出卡片 */
.card > * { min-width: 0; }
input[type="file"] { max-width: 100%; }
.guide .card { margin-bottom: 14px; }
.guide h2 { margin: 0; font-size: 17px; }
.guide ol, .guide ul { margin: 0; padding-left: 1.3em; display: grid; gap: 6px; }
.head-row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
.head-row h1, .head-row h2 { margin: 0; }
main > .head-row h1 { color: var(--fg); }
[data-theme="dusk"] main > .head-row h1, [data-theme="dusk"] main > h1 { color: #ffffff; text-shadow: 0 2px 8px rgba(40, 20, 90, .35); }
.pager { display: flex; gap: 6px; }
.note { color: var(--muted); font-size: 14px; }
[data-theme="dusk"] main > .note { color: #ffffff; }
.empty { color: var(--muted); }
.flash { padding: 10px 14px; border-radius: 12px; background: var(--surface); border: 1px solid var(--accent); box-shadow: var(--shadow); }
.error { padding: 10px 14px; border-radius: 12px; background: var(--error-bg); color: var(--error-fg); }
.warn { padding: 10px 14px; border-radius: 12px; background: var(--warn-bg); color: var(--warn-fg); margin: 12px 0; }
.warn ul { margin: 4px 0 0; padding-left: 20px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 12px; }
.actions form { margin: 0; }

/* ---- 月檢視 ---- */
.month { width: 100%; table-layout: fixed; border-collapse: separate; border-spacing: 0; overflow: hidden; box-shadow: none; }
.panel .month { border: 0; background: transparent; backdrop-filter: none; -webkit-backdrop-filter: none; }
.month th { font-weight: 500; font-size: 13px; color: var(--muted); padding: 6px 4px; }
.month td { vertical-align: top; height: 104px; padding: 4px 6px; border-top: 1px solid var(--line); border-left: 1px solid var(--line); overflow: hidden; }
.month td:first-child { border-left: 0; }
.month td.weekend { background: rgba(255, 255, 255, .14); }
[data-theme="dusk"] .month td.weekend { background: rgba(120, 90, 200, .07); }
.month td.out { opacity: .45; }
.month td.sel { box-shadow: inset 0 0 0 2px var(--accent); border-radius: 10px; }
.dnum {
  display: inline-grid;
  place-items: center;
  min-width: 26px;
  height: 26px;
  border-radius: 999px;
  text-decoration: none;
  font-size: 13px;
  font-weight: 600;
}
.month td:last-child .dnum, .month td.holiday .dnum { color: var(--holiday); }
.month td.workday .dnum { color: var(--workday); text-decoration: underline; }
.month td.today .dnum { background: var(--accent); color: var(--accent-fg); }
.sp { font-size: 11px; margin-left: 4px; }
.sp.holiday { color: var(--holiday); }
.sp.workday { color: var(--workday); }
.dots { display: none; gap: 3px; justify-content: center; margin-top: 2px; }
.dot { width: 7px; height: 7px; border-radius: 999px; background: var(--k-normal); }
.dot.k-repeat { background: var(--k-repeat); }
.dot.k-allday { background: var(--k-allday); }
.dot.k-zhai { background: var(--k-zhai); }
.dot.k-zhai-off { background: transparent; box-shadow: inset 0 0 0 1.5px var(--k-zhai); }

/* 農曆與十齋日（月曆格子：日期旁的農曆小字；十齋日所有人都看得到，自己參加的加深） */
.lunar-s { font-size: 11px; color: var(--muted); margin-left: 2px; }
.lunar { font-size: 13px; color: var(--muted); font-weight: 400; }
/* 節氣：和農曆並列，用主題色區分（2026-11-18 使用者選並列） */
.term-s { font-size: 11px; color: var(--accent); font-weight: 600; margin-left: 4px; }
.term { font-size: 13px; color: var(--accent); font-weight: 600; }
.zhai {
  display: block;
  margin-top: 3px;
  padding: 0 8px;
  border-radius: 6px;
  font-size: 11px;
  text-decoration: none;
  color: var(--muted);
  border: 1px dashed color-mix(in srgb, var(--k-zhai) 60%, transparent);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.zhai.on { color: var(--fg); border-style: solid; background: color-mix(in srgb, var(--k-zhai) 20%, transparent); }
.eyebrow { margin: 0; font-size: 13px; color: var(--muted); }
.zhai-actions form { display: flex; flex-wrap: wrap; gap: 8px; }
.zhai-nav { flex-wrap: wrap; }

/* 月格裡的行程膠囊 */
.ev {
  display: block;
  margin-top: 3px;
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-decoration: none;
  background: color-mix(in srgb, var(--k-normal) 16%, transparent);
}
.ev::before { content: ""; display: inline-block; vertical-align: middle; width: 6px; height: 6px; margin-right: 4px; border-radius: 999px; background: var(--k-normal); }
.ev.k-repeat { background: color-mix(in srgb, var(--k-repeat) 16%, transparent); }
.ev.k-repeat::before { background: var(--k-repeat); }
.ev.k-allday { background: color-mix(in srgb, var(--k-allday) 18%, transparent); border-radius: 6px; }
.ev.k-allday::before { background: var(--k-allday); }
.ev .t { color: var(--muted); }
.more { display: block; font-size: 11px; color: var(--muted); margin-top: 2px; }

/* ---- 議程（週、清單、選取日） ---- */
.days { display: grid; gap: 12px; }
.day { padding: 12px 16px; }
.day.today { box-shadow: var(--shadow), inset 0 0 0 2px var(--accent); }
.day h2 a { text-decoration: none; }
.item {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px 10px 14px;
  margin-top: 8px;
  border-radius: 12px;
  background: var(--surface-2);
  border-left: 4px solid var(--k-normal);
  text-decoration: none;
}
.item:hover { background: color-mix(in srgb, var(--accent) 10%, var(--surface-2)); }
.item.k-repeat { border-left-color: var(--k-repeat); }
.item.k-allday { border-left-color: var(--k-allday); }
.item.k-zhai { border-left-color: var(--k-zhai); }
.item.faint { opacity: .6; border-left-style: dashed; }
.item-main, .item-side { display: grid; }
.item-side { text-align: right; flex: none; }
.item-title { font-weight: 600; }
.item-time { font-weight: 600; font-variant-numeric: tabular-nums; }
.item-sub { color: var(--muted); font-size: 13px; }

/* ---- 詳細、表單 ---- */
dl { display: grid; grid-template-columns: max-content 1fr; gap: 6px 14px; margin: 0; }
dt { color: var(--muted); }
dd { margin: 0; }
.note-text { white-space: pre-wrap; }
.people { display: flex; flex-wrap: wrap; gap: 4px 16px; }
.ext { color: var(--muted); font-size: 13px; }
.people-edit { margin-top: 12px; border: 1px solid var(--line); border-radius: 12px; padding: 8px 12px; }
.people-edit summary { cursor: pointer; color: var(--muted); }

/* ---- 常用地點 ---- */
.place { padding: 10px 0; border-top: 1px solid var(--line); }
.place:first-of-type { border-top: 0; }
.place-head { display: flex; flex-wrap: wrap; gap: 4px 12px; align-items: baseline; justify-content: space-between; }
.place-addr, .addr { margin: 4px 0; overflow-wrap: anywhere; }
.place summary { cursor: pointer; color: var(--muted); }
.place-form { display: grid; gap: 8px; margin-top: 8px; }
.people-edit form { display: grid; gap: 8px; margin-top: 8px; }

/* ---- 匯入、管理 ---- */
.grid2 { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.table-wrap { overflow-x: auto; border-radius: 18px; }
.preview, .admin { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 14px; overflow: hidden; }
.preview th, .preview td, .admin th, .admin td { border-bottom: 1px solid var(--line); padding: 8px 10px; text-align: left; vertical-align: middle; }
.admin th { white-space: nowrap; }
.preview tr.bad td { background: var(--error-bg); color: var(--error-fg); }
.admin form { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin: 0; }
.admin select, .admin button { padding: 4px 10px; }
.admin td.c { text-align: center; }
.raw { color: var(--muted); font-size: 12px; }
.dup { color: var(--workday); }
.badge { font-size: 12px; padding: 1px 8px; border-radius: 999px; background: var(--surface-2); }
.badge.pending { background: var(--warn-bg); color: var(--warn-fg); }
.badge.suspended { background: var(--error-bg); color: var(--error-fg); }
.tabs { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 14px; }
.tabs a { text-decoration: none; padding: 6px 14px; border-radius: 999px; background: var(--surface); border: 1px solid var(--line); }
.tabs a.on { background: var(--accent); color: var(--accent-fg); border-color: transparent; }
/* 間距（CSP 只允許 style.css，模板不能用 style 屬性） */
main .mt-sm { margin-top: 12px; }
main .mt { margin-top: 16px; }
main .mt-lg { margin-top: 24px; }
hr { border: 0; border-top: 1px solid var(--line); margin: 20px 0; }

/* ---- 頁尾 ---- */
.attribution { max-width: 1040px; margin: 8px auto 24px; padding: 0 20px; font-size: 12px; color: var(--muted); }
[data-theme="dusk"] .attribution { color: rgba(255, 255, 255, .85); }
.attribution p { margin: 2px 0; }
.lic { white-space: pre-line; }

/* ---- 手機 ---- */
.tabbar { display: none; }

@media (max-width: 640px) {
  .bar { padding: calc(10px + env(safe-area-inset-top)) calc(12px + env(safe-area-inset-right)) 10px calc(12px + env(safe-area-inset-left)); }
  .me { margin-left: 0; width: 100%; justify-content: flex-end; flex-wrap: nowrap; gap: 6px; }
  .me .add { display: none; }
  .me form { gap: 4px; min-width: 0; }
  .bar button.ghost { padding: 6px 12px; white-space: nowrap; }
  .theme-switch .chip { padding: 3px 8px; white-space: nowrap; }
  .name { min-width: 0; max-width: 34vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .me form:last-child { min-width: 0; }
  main { padding: 12px; }
  h1 { font-size: 20px; }

  /* 月曆格只顯示日期與圓點，行程列在下方 */
  .month td { height: 52px; padding: 3px 1px; text-align: center; border-left: 0; }
  .month td.sel { border-radius: 12px; }
  .cell-events, .month .sp { display: none; }
  .lunar-s { display: block; margin: 0; font-size: 10px; line-height: 1.1; }
  .term-s { display: block; margin: 0; font-size: 10px; line-height: 1.1; }
  .dots { display: flex; }
  .panel { padding: 12px; }

  /* 底部圖示導覽，取代頁首的分頁（原本只有深海；2026-11-18 使用者要求暮光也一樣，拿掉浮動新增按鈕） */
  .nav { display: none; }
  body { padding-bottom: calc(72px + env(safe-area-inset-bottom)); }
  .tabbar {
    display: flex;
    justify-content: space-around;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
    background: var(--nav-bg);
    backdrop-filter: var(--blur);
    -webkit-backdrop-filter: var(--blur);
    border-top: 1px solid var(--line);
  }
  .tabbar a { display: grid; justify-items: center; gap: 2px; text-decoration: none; font-size: 11px; color: var(--nav-muted); padding: 4px 10px; border-radius: 12px; }
  .tabbar a.on { color: var(--accent); }
  .tabbar .tab-add { color: var(--accent-fg); background: var(--accent); }
}

/* 月曆下方的本月行程 */
.month-agenda h2 { margin-bottom: 4px; }
.agenda-day { padding: 10px 0; border-top: 1px solid var(--line); scroll-margin-top: 16px; }
.agenda-day:first-of-type { border-top: 0; }
.agenda-day .head-row { margin-bottom: 0; }
.agenda-day h3 { font-size: 15px; margin: 0; }
.agenda-day.sel { margin: 0 -10px; padding: 10px; border-radius: 14px; box-shadow: inset 0 0 0 2px var(--accent); border-top-color: transparent; }
/* 「更多」頁：大按鈕清單（手機底部導覽的第五格） */
.more-list { display: grid; gap: 10px; max-width: 520px; }
.more-list a { display: flex; align-items: center; gap: 14px; padding: 14px 16px; border-radius: 16px; background: var(--surface); border: 1px solid var(--line); text-decoration: none; }
.more-list a svg { flex: none; color: var(--accent); }
.more-list span { display: grid; }
.more-list small { color: var(--muted); font-size: 13px; }
input.mono { width: 100%; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; }
