/* ============================================================
 * 我的行事曆 — 樣式
 * ------------------------------------------------------------
 * 視覺方向：A ＋ B 雙皮
 *   淺色 = B 紙感極簡（暖白紙、細線、朱紅、近直角、無陰影）
 *   深色 = A 深空玻璃（極光光暈、毛玻璃、天藍、大圓角）
 *   兩者共用 B 的襯線標題與寬鬆密度。
 *
 * 對比度一律以「最壞情況」驗算：漸層取最不利色停，半透明先合成
 * 再算。全部量測值 ≥ 4.5:1（見 風格預覽.html 的實測器）。
 * ============================================================ */

/* ---------- 色票：淺色＝B 紙感極簡 ---------- */
:root {
  --bg:          #f4f1ea;   /* 紙 */
  --surface:     #fffdf9;
  --surface-2:   #f6f3ec;
  --surface-3:   #ece7dc;
  --text:        #1b1815;   /* 對 surface 17.40:1 */
  --muted:       #6d665d;   /* 對 surface  5.57:1 */
  --text-dim:    #6f6759;   /* 旁月日期，對 surface-2 5.04:1 */
  --border:      #e8e3d9;
  --border-2:    #ded8cd;
  --accent:      #a8321f;   /* 朱紅，白字 6.58:1 */
  --accent-fg:   #fffdf9;
  --accent-soft: #f8ece8;
  --danger:      #93261a;
  --danger-fg:   #fffdf9;
  --today-ring:  #a8321f;
  --chip-mix:    14%;       /* 分類色混入晶片底的比例 */
  --chip-base:   #fffdf9;
  --dot-ring:    rgb(0 0 0 / .26);
  --bar-bg:      #fffdf9;   /* 紙是實心的 */
  --panel-head:  #f6f3ec;   /* 面板表頭 */
  /* 週末與假日：紙感用同色系的淡色，不引入突兀的冷色 */
  --sat-bg:      #eef1f5;
  --sun-bg:      #faf1ef;
  --hol-bg:      #f7e8e4;
  --sat-fg:      #3d5570;   /* 對 sat-bg 6.78:1 */
  --sun-fg:      #9a3327;   /* 對 sun-bg 6.55:1 */
  --hol-fg:      #8f2e1f;
  --hover:       #f6f3ec;
  --active:      #ece7dc;

  /* 質感開關：淺色是紙，所以不發光、不模糊、幾乎不投影 */
  --glass:       none;
  --aurora:      0;
  --shadow-1:    0 1px 0 rgb(60 48 30 / .05);
  --shadow-2:    0 12px 34px rgb(60 48 30 / .13), 0 2px 6px rgb(60 48 30 / .08);
  --radius:      4px;
  --radius-sm:   3px;
  --chip-radius: 2px;
  --hair:        1px;       /* 格線粗細 */
  --today-glow:  0 0 0 0 transparent;   /* 紙上不發光 */
  --ring-w:      2px;

  --font: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", "Segoe UI",
          system-ui, -apple-system, sans-serif;
  --font-title: "Noto Serif TC", "Source Han Serif TC", "Songti TC",
                Georgia, "MingLiU", serif;
  --mono: "Cascadia Mono", "Consolas", ui-monospace, monospace;
}

/* ---------- 色票：深色＝A 深空玻璃 ---------- */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg:          #0a0d14;
    --surface:     rgb(255 255 255 / .055);
    --surface-2:   rgb(255 255 255 / .025);
    --surface-3:   rgb(255 255 255 / .10);
    --text:        #eef2f8;   /* 12.73:1 */
    --muted:       #a8b4c4;   /*  6.80:1 */
    --text-dim:    #96a1b1;   /*  5.99:1 */
    --border:      rgb(255 255 255 / .11);
    --border-2:    rgb(255 255 255 / .17);
    --accent:      #7dd3fc;   /* 天藍，深字 10.01:1 */
    --accent-fg:   #062031;
    --accent-soft: rgb(125 211 252 / .13);
    --danger:      #fda4af;
    --danger-fg:   #2a0710;
    --today-ring:  #7dd3fc;
    --chip-mix:    26%;
    --chip-base:   rgb(12 17 26 / .72);
    --dot-ring:    rgb(255 255 255 / .30);
    --bar-bg:      rgb(10 13 20 / .68);   /* 半透明＋模糊，捲動時底下的光暈會透出來 */
    --panel-head:  rgb(10 13 20 / .55);   /* 表頭要壓得住極光，不然淺灰字只剩 3.5:1 */
    --sat-bg:      rgb(125 211 252 / .055);
    --sun-bg:      rgb(253 164 175 / .07);
    --hol-bg:      rgb(253 164 175 / .13);
    --sat-fg:      #a8cdf0;
    --sun-fg:      #f5b8bf;
    --hol-fg:      #fda4af;
    --hover:       rgb(255 255 255 / .11);   /* 深色的 hover 要更亮，不是更暗 */
    --active:      rgb(255 255 255 / .16);

    --glass:       blur(22px) saturate(1.25);
    --aurora:      1;
    --shadow-1:    0 1px 3px rgb(0 0 0 / .45);
    --shadow-2:    0 22px 64px rgb(0 0 0 / .62), 0 2px 10px rgb(0 0 0 / .45);
    --radius:      16px;
    --radius-sm:   9px;
    --chip-radius: 6px;
    --hair:        1px;
    --ring-w:      1px;
    --today-glow:  0 0 24px -4px var(--today-ring);
  }
}

:root[data-theme="dark"] {
  --bg:          #0a0d14;
  --surface:     rgb(255 255 255 / .055);
  --surface-2:   rgb(255 255 255 / .025);
  --surface-3:   rgb(255 255 255 / .10);
  --text:        #eef2f8;
  --muted:       #a8b4c4;
  --text-dim:    #96a1b1;
  --border:      rgb(255 255 255 / .11);
  --border-2:    rgb(255 255 255 / .17);
  --accent:      #7dd3fc;
  --accent-fg:   #062031;
  --accent-soft: rgb(125 211 252 / .13);
  --danger:      #fda4af;
  --danger-fg:   #2a0710;
  --today-ring:  #7dd3fc;
  --chip-mix:    26%;
  --chip-base:   rgb(12 17 26 / .72);
  --dot-ring:    rgb(255 255 255 / .30);
  --bar-bg:      rgb(10 13 20 / .68);
  --panel-head:  rgb(10 13 20 / .55);
  --sat-bg:      rgb(125 211 252 / .055);
  --sun-bg:      rgb(253 164 175 / .07);
  --hol-bg:      rgb(253 164 175 / .13);
  --sat-fg:      #a8cdf0;
  --sun-fg:      #f5b8bf;
  --hol-fg:      #fda4af;
  --hover:       rgb(255 255 255 / .11);
  --active:      rgb(255 255 255 / .16);

  --glass:       blur(22px) saturate(1.25);
  --aurora:      1;
  --shadow-1:    0 1px 3px rgb(0 0 0 / .45);
  --shadow-2:    0 22px 64px rgb(0 0 0 / .62), 0 2px 10px rgb(0 0 0 / .45);
  --radius:      16px;
  --radius-sm:   9px;
  --chip-radius: 6px;
  --hair:        1px;
  --ring-w:      1px;
  --today-glow:  0 0 24px -4px var(--today-ring);
}

/* ---------- 基礎 ---------- */
* { box-sizing: border-box; }

/* [hidden] 的預設 display:none 特異性只有 0,0,1，任何 class 規則都壓得過它。
   .btn / .field-row 這種有 display 的元素掛 hidden 會失效，所以在這裡補一刀。 */
[hidden] { display: none !important; }

html { height: 100%; }

body {
  min-height: 100%;   /* 用 min-height，內容變長時狀態列才會被推下去而不是被蓋住 */
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
  display: flex;
  flex-direction: column;
  position: relative;
}

/* 極光光暈：只有深色主題會亮起來（--aurora 淺色是 0）。
   固定定位，所以捲動時光暈不會跟著跑。 */
body::before {
  content: "";
  position: fixed;
  inset: -20vmax;
  z-index: -1;
  pointer-events: none;
  opacity: var(--aurora);
  background:
    radial-gradient(42% 38% at 12% 4%,  rgb(125 211 252 / .58), transparent 62%),
    radial-gradient(38% 40% at 88% 10%, rgb(192 132 252 / .50), transparent 62%),
    radial-gradient(46% 42% at 50% 98%, rgb(34 211 238 / .40),  transparent 64%);
  filter: blur(26px);
  transition: opacity .25s;
}

svg { width: 20px; height: 20px; fill: none; stroke: currentColor;
      stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }

.spacer { flex: 1 1 auto; }

.skip-link {
  position: absolute; left: -9999px; top: 0; z-index: 100;
  background: var(--accent); color: var(--accent-fg);
  padding: 10px 16px; border-radius: 0 0 var(--radius) 0; text-decoration: none;
}
.skip-link:focus { left: 0; }

:where(button, input, select, textarea, a):focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

/* ---------- 按鈕 ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  height: 36px; padding: 0 12px;
  border: 1px solid var(--border-2);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font: inherit; font-size: 14px;
  cursor: pointer;
  white-space: nowrap;
  transition: background .12s, border-color .12s;
}
.btn:hover { background: var(--hover); }
.btn:active { background: var(--active); }
.btn--icon { width: 36px; padding: 0; justify-content: center; }
.btn--primary {
  background: var(--accent); color: var(--accent-fg); border-color: transparent;
}
.btn--primary:hover { filter: brightness(1.08); background: var(--accent); }
.btn--primary:active { filter: brightness(.94); }
.btn--danger {
  background: transparent; color: var(--danger); border-color: var(--danger);
}
.btn--danger:hover { background: color-mix(in srgb, var(--danger) 12%, var(--surface)); }

/* ---------- 頂列 ---------- */
.topbar {
  position: sticky; top: 0; z-index: 30;
  background: var(--bar-bg);
  backdrop-filter: var(--glass);
  -webkit-backdrop-filter: var(--glass);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-1);
}
.topbar__row { display: flex; align-items: center; gap: 8px; padding: 10px 14px; }
.topbar__row--filters {
  gap: 10px; padding-top: 0; padding-bottom: 10px;
  flex-wrap: wrap;
}
.nav-group { display: flex; gap: 6px; }

.period {
  margin: 0 0 0 8px;
  font-family: var(--font-title);
  font-size: 21px; font-weight: 700; letter-spacing: .02em;
  white-space: nowrap;
}

/* 檢視切換 */
.seg {
  display: inline-flex; padding: 3px; gap: 2px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.seg__btn {
  border: 0; background: transparent; color: var(--muted);
  font: inherit; font-size: 14px; padding: 4px 12px;
  border-radius: 5px; cursor: pointer;
}
.seg__btn:hover { color: var(--text); }
.seg__btn.is-active {
  background: var(--active); color: var(--text);
  font-weight: 700; box-shadow: var(--shadow-1);
}

/* 搜尋 */
.search {
  position: relative; display: flex; align-items: center;
  flex: 1 1 220px; max-width: 340px;
}
.search svg {
  position: absolute; left: 9px; width: 17px; height: 17px;
  color: var(--muted); pointer-events: none;
}
.search input {
  width: 100%; height: 34px;
  padding: 0 10px 0 32px;
  border: 1px solid var(--border-2); border-radius: var(--radius-sm);
  background: var(--surface-2); color: var(--text);
  font: inherit; font-size: 14px;
}
.search input::placeholder { color: var(--muted); }

/* 分類篩選 */
.cats { display: flex; flex-wrap: wrap; gap: 6px; }
.cat-chip {
  display: inline-flex; align-items: center; gap: 6px;
  height: 30px; padding: 0 11px;
  border: 1px solid var(--border-2); border-radius: 999px;
  background: var(--surface); color: var(--muted);
  font: inherit; font-size: 13px; cursor: pointer;
}
.cat-chip[aria-pressed="true"] {
  color: var(--text); font-weight: 600;
  border-color: var(--border-2);
  background: var(--surface-2);
}
.cat-chip[aria-pressed="false"] { opacity: .62; }
.cat-chip .dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--cat);
  box-shadow: inset 0 0 0 1px var(--dot-ring);
  flex: none;
}

/* ---------- 選單 ---------- */
.menu-wrap { position: relative; }
.menu {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 40;
  min-width: 236px; padding: 5px;
  background: var(--bar-bg);
  backdrop-filter: var(--glass);
  -webkit-backdrop-filter: var(--glass);
  border: 1px solid var(--border-2); border-radius: var(--radius);
  box-shadow: var(--shadow-2);
}
.menu__item {
  display: flex; align-items: center; justify-content: space-between; gap: 14px;
  width: 100%; padding: 8px 10px;
  border: 0; border-radius: var(--radius-sm);
  background: transparent; color: var(--text);
  font: inherit; font-size: 14px; text-align: left; cursor: pointer;
}
.menu__item:hover { background: var(--hover); }
.menu__hint { color: var(--muted); font-size: 12.5px; white-space: nowrap; }
.menu__sep { margin: 5px 8px; border: 0; border-top: 1px solid var(--border); }

/* ---------- 檢視容器 ---------- */
.view { flex: 1 1 auto; padding: 14px; min-height: 0;
  display: flex; flex-direction: column; }
.view:focus { outline: none; }

/* ---------- 月檢視 ---------- */
.month {
  flex: 1 1 auto;
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  grid-template-rows: auto repeat(var(--weeks, 6), minmax(96px, 1fr));
  gap: 1px;
  background: var(--border);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-1);
  backdrop-filter: var(--glass);
  -webkit-backdrop-filter: var(--glass);
}
.month__dow {
  background: var(--panel-head);
  padding: 9px 8px;
  font-size: 12px; font-weight: 700; color: var(--muted);
  letter-spacing: .14em;
  text-align: center;
}
.month__dow--sun { color: var(--sun-fg); }
.month__dow--sat { color: var(--sat-fg); }

.day {
  position: relative;
  background: var(--surface);
  min-height: 0;
  padding: 7px 7px 8px;
  display: flex; flex-direction: column; gap: 3px;
  cursor: pointer;
  border: 0;
  font: inherit; color: inherit;
  text-align: left;
  width: 100%;
}
.day--sat { background: var(--sat-bg); }
.day--sun { background: var(--sun-bg); }
.day--holiday { background: var(--hol-bg); }
.day--sat  .day__num { color: var(--sat-fg); }
.day--sun  .day__num { color: var(--sun-fg); }
.day--holiday .day__num { color: var(--hol-fg); }
/* 旁月的週末仍要比本月淡，否則跨月邊界會分不出來 */
.day--out.day--sat, .day--out.day--sun, .day--out.day--holiday { opacity: .55; }
.day:hover { background: var(--hover); }
.day--out { background: var(--surface-2); }
.day--out .day__num { color: var(--text-dim); }
.day--out:hover { background: var(--hover); }

.day__head {
  display: flex; align-items: center; gap: 5px; min-width: 0;
}
.day__hol {
  font-size: 11px; font-weight: 700; color: var(--hol-fg);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  min-width: 0;
}
.day__num {
  flex: none;
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 24px; height: 24px; padding: 0 6px;
  border-radius: 999px;
  font-size: 13px; font-weight: 600; font-variant-numeric: tabular-nums;
  color: var(--text);
}
.day--today .day__num {
  background: var(--accent); color: var(--accent-fg); font-weight: 700;
}
.day--today {
  box-shadow: inset 0 0 0 var(--ring-w) var(--today-ring), var(--today-glow);
}

.chips { display: flex; flex-direction: column; gap: 2px; min-width: 0; }

.chip {
  display: flex; align-items: center; gap: 5px;
  padding: 3px 7px;
  border-radius: var(--chip-radius);
  background: color-mix(in srgb, var(--cat) var(--chip-mix), var(--chip-base));
  border-left: 3px solid var(--cat);
  color: var(--text);
  font-size: 12.5px; line-height: 1.35;
  min-width: 0;
  cursor: pointer;
  text-align: left;
  border-top: 0; border-right: 0; border-bottom: 0;
  width: 100%;
  font-family: inherit;
}
.chip:hover { filter: brightness(.97); }
:root[data-theme="dark"] .chip:hover,
:root:not([data-theme="light"]) .chip:hover { filter: brightness(1.22); }
.chip__time {
  font-variant-numeric: tabular-nums; font-size: 11.5px;
  color: var(--muted); flex: none;
}
.chip__title {
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0;
}
.chip--allday .chip__title { font-weight: 600; }

.more {
  align-self: flex-start;
  border: 0; background: transparent; color: var(--muted);
  font: inherit; font-size: 11.5px; padding: 1px 5px; cursor: pointer;
  border-radius: 4px;
}
.more:hover { background: var(--hover); color: var(--text); }

/* ---------- 週檢視 ---------- */
.week {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-1);
  backdrop-filter: var(--glass);
  -webkit-backdrop-filter: var(--glass);
  display: flex; flex-direction: column;
}
.week__head {
  display: grid; grid-template-columns: 58px repeat(7, minmax(0, 1fr));
  border-bottom: 1px solid var(--border);
  background: var(--panel-head);
}
.week__corner { border-right: 1px solid var(--border); }
.week__day {
  padding: 6px 4px; text-align: center;
  border-right: 1px solid var(--border);
}
.week__day:last-child { border-right: 0; }
.week__dow { font-size: 12px; color: var(--muted); font-weight: 600; }
.week__date {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 26px; height: 26px; margin-top: 2px;
  border-radius: 999px; font-size: 14px; font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.week__day--today .week__date { background: var(--accent); color: var(--accent-fg); }

.week__allday {
  display: grid; grid-template-columns: 58px repeat(7, minmax(0, 1fr));
  border-bottom: 1px solid var(--border);
  min-height: 30px;
  background: var(--panel-head);
}
.week__allday-label {
  font-size: 11.5px; color: var(--muted); padding: 5px 6px; text-align: right;
  border-right: 1px solid var(--border);
}
.week__allday-cell {
  padding: 3px; border-right: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 2px; min-width: 0;
}
.week__allday-cell:last-child { border-right: 0; }

.week__grid {
  position: relative;
  display: grid; grid-template-columns: 58px repeat(7, minmax(0, 1fr));
  overflow-y: auto;
  max-height: calc(100vh - 260px);
}
.week__hours { border-right: 1px solid var(--border); }
.week__hour {
  height: 46px; padding: 0 7px;
  font-size: 11.5px; color: var(--muted); text-align: right;
  font-variant-numeric: tabular-nums;
  transform: translateY(-7px);
}
.week__col {
  position: relative;
  border-right: 1px solid var(--border);
  cursor: pointer;
}
.week__col:last-child { border-right: 0; }
.week__col::before {
  content: ""; position: absolute; inset: 0;
  background: repeating-linear-gradient(
    to bottom,
    transparent 0, transparent 45px,
    var(--border) 45px, var(--border) 46px
  );
  pointer-events: none;
}
.week__col--today { background: var(--accent-soft); }

.wevent {
  position: absolute; left: 2px; right: 2px;
  padding: 3px 6px;
  border-radius: 5px;
  background: color-mix(in srgb, var(--cat) var(--chip-mix), var(--chip-base));
  border-left: 3px solid var(--cat);
  color: var(--text);
  font-size: 12px; line-height: 1.3;
  overflow: hidden; cursor: pointer;
  text-align: left;
  border-top: 0; border-right: 0; border-bottom: 0;
  font-family: inherit;
  box-shadow: var(--shadow-1);
}
.wevent strong { font-weight: 600; display: block;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.wevent span { color: var(--muted); font-size: 11px;
  font-variant-numeric: tabular-nums; }

.now-line {
  position: absolute; left: 0; right: 0; height: 2px;
  background: var(--danger); z-index: 5; pointer-events: none;
}
.now-line::before {
  content: ""; position: absolute; left: -4px; top: -3px;
  width: 8px; height: 8px; border-radius: 50%; background: var(--danger);
}

/* ---------- 議程檢視 ---------- */
.agenda { max-width: 780px; margin: 0 auto; display: flex;
  flex-direction: column; gap: 16px; }
.agenda__day {
  background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-1);
  backdrop-filter: var(--glass);
  -webkit-backdrop-filter: var(--glass);
  overflow: hidden;
}
.agenda__head {
  display: flex; align-items: baseline; gap: 10px;
  padding: 9px 14px;
  background: var(--panel-head);
  border-bottom: 1px solid var(--border);
}
.agenda__date { font-family: var(--font-title); font-size: 17px; font-weight: 700;
  font-variant-numeric: tabular-nums; }
.agenda__dow { font-size: 13px; color: var(--muted); }
.agenda__rel { margin-left: auto; font-size: 12.5px; color: var(--muted); }
.agenda__day--today .agenda__head { background: var(--accent-soft); }
.agenda__day--today .agenda__rel { color: var(--accent); font-weight: 700; }

.arow {
  display: flex; align-items: flex-start; gap: 11px;
  width: 100%; padding: 10px 14px;
  border: 0; border-top: 1px solid var(--border);
  background: transparent; color: var(--text);
  font: inherit; text-align: left; cursor: pointer;
}
.agenda__day .arow:first-of-type { border-top: 0; }
.arow:hover { background: var(--hover); }
.arow__bar { width: 4px; align-self: stretch; border-radius: 2px;
  background: var(--cat); flex: none; min-height: 34px; }
.arow__time {
  width: 92px; flex: none; font-size: 13px; color: var(--muted);
  font-variant-numeric: tabular-nums; padding-top: 1px;
}
.arow__main { min-width: 0; flex: 1 1 auto; }
.arow__title { font-weight: 600; }
.arow__meta { font-size: 12.5px; color: var(--muted); margin-top: 2px;
  display: flex; flex-wrap: wrap; gap: 4px 12px; }

.empty {
  text-align: center; color: var(--muted);
  padding: 56px 20px; font-size: 14.5px;
}

/* ---------- 狀態列 ---------- */
.statusbar {
  padding: 8px 16px 14px;
  font-size: 12.5px; color: var(--muted);
  display: flex; flex-wrap: wrap; gap: 4px 18px;
}
.statusbar kbd {
  font-family: var(--mono); font-size: 11.5px;
  background: var(--surface-2); border: 1px solid var(--border-2);
  border-bottom-width: 2px; border-radius: 4px; padding: 0 5px;
  color: var(--text);
}

/* ---------- 對話框 ---------- */
.dlg {
  width: min(560px, calc(100vw - 28px));
  padding: 0; border: 1px solid var(--border-2);
  border-radius: calc(var(--radius) + 4px);
  background: var(--bar-bg); color: var(--text);
  backdrop-filter: var(--glass);
  -webkit-backdrop-filter: var(--glass);
  box-shadow: var(--shadow-2);
}
.dlg--narrow { width: min(430px, calc(100vw - 28px)); }
.dlg::backdrop { background: rgb(8 11 15 / .52); backdrop-filter: blur(2px); }

.dlg__head {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 14px 12px 18px;
  border-bottom: 1px solid var(--border);
}
.dlg__head h2 { margin: 0; font-size: 16.5px; flex: 1 1 auto; }
.dlg__body { padding: 16px 18px; display: flex; flex-direction: column; gap: 13px;
  max-height: min(66vh, 560px); overflow-y: auto; }
.dlg__foot {
  display: flex; align-items: center; gap: 8px;
  padding: 12px 18px 16px;
  border-top: 1px solid var(--border);
}

.form { display: contents; }

.field { display: flex; flex-direction: column; gap: 5px; flex: 1 1 0; min-width: 0; }
.field__label { font-size: 12.5px; font-weight: 600; color: var(--muted); }
.field input[type="text"], .field input[type="date"], .field input[type="time"],
.field select, .field textarea {
  width: 100%; padding: 8px 10px;
  border: 1px solid var(--border-2); border-radius: var(--radius-sm);
  background: var(--surface-2); color: var(--text);
  font: inherit; font-size: 14px;
}
.field textarea { resize: vertical; min-height: 62px; }
.field-row { display: flex; gap: 11px; align-items: flex-end; }
.field--check { flex: 0 0 auto; flex-direction: row; align-items: center;
  gap: 7px; padding-bottom: 9px; font-size: 14px; }
.field--check input { width: 17px; height: 17px; accent-color: var(--accent); }
.field[hidden] { display: none; }

/* 深色主題下讓原生日期／時間選擇器的圖示看得見 */
:root[data-theme="dark"] input[type="date"],
:root[data-theme="dark"] input[type="time"] { color-scheme: dark; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) input[type="date"],
  :root:not([data-theme="light"]) input[type="time"] { color-scheme: dark; }
}

/* 詳情 */
.detail__title { font-size: 17px; font-weight: 700; margin: 0 0 3px; }
.detail__cat { display: inline-flex; align-items: center; gap: 6px;
  font-size: 13px; color: var(--muted); margin-bottom: 12px; }
.detail__cat .dot { width: 10px; height: 10px; border-radius: 50%;
  background: var(--cat); box-shadow: inset 0 0 0 1px var(--dot-ring); }
.detail__list { display: grid; grid-template-columns: 62px 1fr;
  gap: 7px 12px; font-size: 14px; }
.detail__list dt { color: var(--muted); font-size: 13px; }
.detail__list dd { margin: 0; overflow-wrap: anywhere; }

/* ---------- QR 對話框 ---------- */
.dlg__body--qr { align-items: center; text-align: center; }
.qr-holder {
  /* QR 永遠放在白底上：深色主題直接反轉模組的話，部分掃碼器會讀不了 */
  background: #ffffff;
  padding: 10px;
  border-radius: 10px;
  line-height: 0;
}
.qr-holder svg { width: min(58vw, 240px); height: auto; display: block; }
.qr-url {
  margin: 0; font-family: var(--mono); font-size: 12.5px;
  color: var(--muted); word-break: break-all;
}
.qr-hint { margin: 0; font-size: 13px; color: var(--muted); }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  z-index: 90; max-width: min(440px, calc(100vw - 32px));
  padding: 11px 17px;
  background: var(--text); color: var(--bg);
  border-radius: var(--radius); box-shadow: var(--shadow-2);
  font-size: 14px;
}
.toast[hidden] { display: none; }

/* ---------- 手機版 ---------- */
@media (max-width: 760px) {
  /* 目標：主工具列擠進「一行」。按鈕一旦換行掉到左側，
     選單（right:0 相對按鈕）就會往左展開被切出畫面——實際發生過。 */
  .topbar__row--main {
    flex-wrap: wrap; gap: 4px; padding: 8px 10px;
    position: relative;   /* 選單改成相對整列定位的錨點 */
  }
  .period { order: -1; width: 100%; margin: 0 0 2px; font-size: 17px; }
  .btn { height: 34px; padding: 0 10px; font-size: 13.5px; }
  .btn--icon { width: 34px; padding: 0; }
  .seg__btn { padding: 3px 9px; font-size: 13px; }
  .btn--primary span { display: none; }
  .btn--primary { width: 34px; padding: 0; justify-content: center; }

  /* 選單錨到整列的右緣，而不是那顆可能換行的按鈕 */
  .menu-wrap { position: static; }
  .menu {
    right: 6px; top: calc(100% + 4px);
    max-width: calc(100vw - 16px);
  }

  /* 搜尋與分類擠一行，分類籤橫向捲動，不再往下堆 */
  .topbar__row--filters {
    flex-wrap: nowrap; overflow-x: auto;
    padding-bottom: 8px; scrollbar-width: none;
  }
  .topbar__row--filters::-webkit-scrollbar { display: none; }
  .search { flex: 0 0 150px; max-width: 150px; }
  .cats { flex-wrap: nowrap; }
  .cat-chip { white-space: nowrap; flex: none; }
  .view { padding: 9px; }
  .month { grid-template-rows: auto repeat(var(--weeks, 6), minmax(68px, 1fr)); }
  .day { padding: 3px; }
  .chip { padding: 1px 4px; font-size: 11px; gap: 3px; }
  .chip__time { display: none; }
  .month__dow { padding: 5px 2px; font-size: 11.5px; }
  .week__grid { max-height: calc(100vh - 300px); }
  .week__head, .week__allday, .week__grid {
    grid-template-columns: 42px repeat(7, minmax(0, 1fr));
  }
  .arow__time { width: 74px; font-size: 12.5px; }
  .statusbar { display: none; }
}

@media (max-width: 420px) {
  .month { grid-template-rows: auto repeat(var(--weeks, 6), minmax(56px, 1fr)); }
  .chips { flex-direction: row; flex-wrap: wrap; gap: 2px; }
  .chip { width: auto; padding: 0; border-left: 0;
    background: transparent; }
  .chip__title { display: none; }
  .chip::before {
    content: ""; width: 7px; height: 7px; border-radius: 50%;
    background: var(--cat); box-shadow: inset 0 0 0 1px var(--dot-ring);
  }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* 狀態列裡的警告（例如 events.js 推播後端讀不動） */
.warn-inline {
  color: var(--danger);
  font-weight: 600;
}
