/* =========================================================
   TeaTracker — style.css
   Mobile First / iPhone Safari + 加入主畫面 standalone
   主色系：#7F7B7F #C7CED6 #F6EDDD #DBD9D9
   ========================================================= */

/* ---------- 1. Design tokens ---------- */
:root {
  /* 品牌四色 */
  --c-brand:  #7F7B7F;
  --c-accent: #C7CED6;
  --c-cream:  #F6EDDD;
  --c-mist:   #DBD9D9;

  /* 茶種色階（單一色相 sequential ramp，依茶種固定順序） */
  --t-green:  #F6EDDD;
  --t-yellow: #E8D8C3;
  --t-white:  #D6C1A5;
  --t-blue:   #C3A98A;
  --t-red:    #A88F73;
  --t-puer:   #7F6B55;
  --t-other:  #C7CED6;

  /* 語意 */
  --bg:        #F6EDDD;
  --surface:   #FFFCF6;
  --surface-2: #F1E8D8;
  --raised:    #FFFFFF;
  --line:      rgba(127, 123, 127, .20);
  --line-2:    rgba(127, 123, 127, .10);
  --ink:       #322F32;
  --ink-2:     #6B676B;
  --ink-3:     #979397;
  --brand:     #6E6A6E;
  --danger:    #A2504A;
  --on-brand:  #FFFCF6;

  /* 元件語意色：深淺兩套都要定義，元件規則只用 var() */
  --btn-bg:      #7F7B7F;
  --btn-ink:     #FFFCF6;
  --chip-on-bg:  #7F7B7F;
  --chip-on-ink: #FFFCF6;
  --badge-bg:    #7F7B7F;
  --badge-ink:   #FFFCF6;
  --tag-ink:     #3B342B;
  --tag-line:    rgba(0, 0, 0, .06);
  --star-off:    #DBD9D9;
  --star-on:     #B09270;
  --req-ink:     #8C4A44;
  --req-bg:      rgba(162, 80, 74, .12);
  --swatch-line: rgba(0, 0, 0, .22);
  --empty-ic:    #DBD9D9;
  --toast-bg:    #322F32;
  --toast-ink:   #FFFCF6;

  --r-sm: 10px;
  --r-md: 14px;
  --r-lg: 20px;
  --r-full: 999px;

  --tap: 44px;                    /* Apple HIG 最小觸控尺寸 */
  --tabbar-h: 58px;
  --appbar-h: 52px;

  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --sar: env(safe-area-inset-right, 0px);

  --shadow-1: 0 1px 2px rgba(50, 47, 50, .05), 0 2px 8px rgba(50, 47, 50, .05);
  --shadow-2: 0 8px 28px rgba(50, 47, 50, .16);

  --font: -apple-system, BlinkMacSystemFont, "PingFang TC", "Noto Sans TC",
          "Heiti TC", "Microsoft JhengHei", "Segoe UI", Roboto, sans-serif;
  --font-num: ui-rounded, -apple-system, "SF Pro Rounded", var(--font);
}

/* 深色：自成一組階（不是自動反轉），並確保圖表色在深底上仍達 3:1 */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg:        #1A191A;
    --surface:   #242224;
    --surface-2: #2E2C2E;
    --raised:    #2A282A;
    --line:      rgba(219, 217, 217, .16);
    --line-2:    rgba(219, 217, 217, .08);
    --ink:       #F3EFE8;
    --ink-2:     #B4B0B4;
    --ink-3:     #858085;
    --brand:     #C7CED6;
    --danger:    #E0938C;
    --on-brand:  #1A191A;

    --btn-bg:      #C7CED6;
    --btn-ink:     #1A191A;
    --chip-on-bg:  #C7CED6;
    --chip-on-ink: #1A191A;
    --badge-bg:    #C7CED6;
    --badge-ink:   #1A191A;
    --tag-ink:     #241F1A;
    --tag-line:    rgba(255, 255, 255, .10);
    --star-off:    #4A464A;
    --star-on:     #B09270;
    --req-ink:     #E0938C;
    --req-bg:      rgba(224, 147, 140, .14);
    --swatch-line: rgba(255, 255, 255, .16);
    --empty-ic:    #464246;
    --toast-bg:    #EDE9E2;
    --toast-ink:   #1A191A;
    --shadow-1: 0 1px 2px rgba(0, 0, 0, .34), 0 2px 10px rgba(0, 0, 0, .24);
    --shadow-2: 0 10px 32px rgba(0, 0, 0, .55);
  }
}
:root[data-theme="dark"] {
  --bg:        #1A191A;
  --surface:   #242224;
  --surface-2: #2E2C2E;
  --raised:    #2A282A;
  --line:      rgba(219, 217, 217, .16);
  --line-2:    rgba(219, 217, 217, .08);
  --ink:       #F3EFE8;
  --ink-2:     #B4B0B4;
  --ink-3:     #858085;
  --brand:     #C7CED6;
  --danger:    #E0938C;
  --on-brand:  #1A191A;

  --btn-bg:      #C7CED6;
  --btn-ink:     #1A191A;
  --chip-on-bg:  #C7CED6;
  --chip-on-ink: #1A191A;
  --badge-bg:    #C7CED6;
  --badge-ink:   #1A191A;
  --tag-ink:     #241F1A;
  --tag-line:    rgba(255, 255, 255, .10);
  --star-off:    #4A464A;
  --star-on:     #B09270;
  --req-ink:     #E0938C;
  --req-bg:      rgba(224, 147, 140, .14);
  --swatch-line: rgba(255, 255, 255, .16);
  --empty-ic:    #464246;
  --toast-bg:    #EDE9E2;
  --toast-ink:   #1A191A;
  --shadow-1: 0 1px 2px rgba(0, 0, 0, .34), 0 2px 10px rgba(0, 0, 0, .24);
  --shadow-2: 0 10px 32px rgba(0, 0, 0, .55);
}

/* ---------- 2. Reset ---------- */
*, *::before, *::after { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  color-scheme: light dark;
}

body {
  margin: 0;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.55;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
  touch-action: manipulation;         /* 消除雙擊縮放與 300ms 延遲 */
}

/* 作者樣式的 display 會勝過瀏覽器預設的 [hidden]，所以必須自己補一條 */
[hidden] { display: none !important; }

h1, h2, h3, p, figure, ol, ul { margin: 0; }
ol, ul { padding: 0; list-style: none; }
button { font: inherit; color: inherit; }

:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
  border-radius: 6px;
}

.svg-sprite { position: absolute; width: 0; height: 0; overflow: hidden; }

.ic { width: 22px; height: 22px; flex: none; fill: none; }
.ic--lg { width: 26px; height: 26px; }
.ic--brand { width: 24px; height: 24px; color: var(--brand); }

/* ---------- 3. App 骨架 ---------- */
.app {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.appbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  height: calc(var(--appbar-h) + var(--sat));
  padding: var(--sat) calc(12px + var(--sar)) 0 calc(16px + var(--sal));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(180%) blur(14px);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 1px solid var(--line-2);
}

.appbar__brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: .04em;
}

.iconbtn {
  width: var(--tap);
  height: var(--tap);
  display: grid;
  place-items: center;
  border: 0;
  border-radius: var(--r-full);
  background: transparent;
  color: var(--ink-2);
  cursor: pointer;
}
.iconbtn:active { background: var(--line-2); }
.iconbtn--ghost { width: 38px; height: 38px; }
.iconbtn[aria-pressed="true"] { color: var(--ink); background: var(--surface-2); }

.views { flex: 1 1 auto; }

.view { display: none; }
.view.is-active { display: block; animation: fade .18s ease-out; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.view__pad {
  padding:
    14px
    calc(16px + var(--sar))
    calc(var(--tabbar-h) + var(--sab) + 88px)
    calc(16px + var(--sal));
  max-width: 720px;
  margin: 0 auto;
}

/* ---------- 4. 底部分頁列（浮動膠囊） ---------- */
.tabdock {
  position: fixed;
  left: 0; right: 0;
  bottom: calc(var(--sab) + 10px);        /* Home Indicator 讓位 */
  z-index: 40;
  display: flex;
  justify-content: center;
  pointer-events: none;                   /* 只有膠囊本身可以點 */
}

.tabdock__pill {
  pointer-events: auto;
  display: flex;
  gap: 2px;
  padding: 5px;
  border-radius: var(--r-full);
  background: color-mix(in srgb, var(--surface) 86%, transparent);
  backdrop-filter: saturate(180%) blur(18px);
  -webkit-backdrop-filter: saturate(180%) blur(18px);
  border: 1px solid var(--line-2);
  box-shadow: var(--shadow-2);
}

.tab {
  min-width: 68px;
  min-height: 50px;
  padding: 0 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  border: 0;
  border-radius: var(--r-full);
  background: none;
  color: var(--ink-3);
  font-size: 11px;
  letter-spacing: .05em;
  cursor: pointer;
  transition: color .18s, background .18s;
}
.tab.is-on {
  background: var(--raised);
  color: var(--ink);
  font-weight: 600;
  box-shadow: var(--shadow-1);
}
.tab:active { transform: scale(.96); }

/* ---------- 5. FAB（浮在膠囊上方，窄螢幕也不會撞在一起） ---------- */
.fab {
  position: fixed;
  right: calc(18px + var(--sar));
  bottom: calc(var(--sab) + var(--tabbar-h) + 24px);
  z-index: 41;
  width: 54px; height: 54px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: var(--r-full);
  background: var(--btn-bg);
  color: var(--btn-ink);
  box-shadow: var(--shadow-2);
  cursor: pointer;
  transition: transform .14s ease-out, opacity .14s;
}
.fab:active { transform: scale(.92); }

/* ---------- 6. 卡片 / 清單 ---------- */
.listhead {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: 2px 0 12px;
}
.listhead__count { font-size: 13px; color: var(--ink-3); letter-spacing: .04em; }

.cards { display: flex; flex-direction: column; gap: 10px; }

.rec {
  width: 100%;
  text-align: left;
  display: block;
  padding: 13px 14px;
  border: 1px solid var(--line-2);
  border-radius: var(--r-md);
  background: var(--surface);
  box-shadow: var(--shadow-1);
  cursor: pointer;
  transition: transform .12s ease-out;
}
.rec:active { transform: scale(.985); }

.rec__top {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 4px;
}

/* 月曆頁：茶名、星等、茶種標籤同一行 */
.rec__head {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 0 6px;
  margin-bottom: 7px;
}
.rec__head .rec__name { flex: 0 1 auto; min-width: 0; }
.rec__head .rec__type { flex: none; }
.rec__date {
  font-family: var(--font-num);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  color: var(--ink-3);
  letter-spacing: .04em;
}
.rec__type {
  margin-left: auto;
  flex: none;
  padding: 2px 9px;
  border-radius: var(--r-full);
  font-size: 11px;
  font-weight: 600;
  color: var(--tag-ink);
  border: 1px solid var(--tag-line);
}

.rec__name {
  font-size: 17px;
  font-weight: 600;
  line-height: 1.35;
  overflow-wrap: anywhere;
}
.rec__year {
  font-family: var(--font-num);
  font-size: 13px;
  font-weight: 500;
  color: var(--ink-3);
  margin-left: 6px;
}

.rec__stars { display: inline-flex; gap: 1px; margin: 0 0 0 7px; vertical-align: 1px; }
.rec__stars .ic { width: 14px; height: 14px; fill: var(--star-off); }
.rec__stars .is-on { fill: var(--star-on); }

.rec__attrs { display: flex; flex-wrap: wrap; gap: 6px; }
.attr {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  max-width: 100%;
  padding: 3px 8px;
  border-radius: var(--r-sm);
  background: var(--surface-2);
  font-size: 12px;
  color: var(--ink-2);
  overflow-wrap: anywhere;
}
.attr b { font-weight: 700; color: var(--brand); font-size: 11px; }

/* 卡片上的標籤：外框膠囊，跟實心的茶種標籤區隔開來 */
.rec__tags { display: flex; flex-wrap: wrap; gap: 5px; margin: 0 0 7px; }
.rec__tag {
  padding: 2px 9px;
  border-radius: var(--r-full);
  border: 1px solid var(--line);
  background: var(--surface-2);
  font-size: 11px;
  font-weight: 500;
  color: var(--ink-2);
  overflow-wrap: anywhere;
}

.rec__note {
  margin-top: 7px;
  font-size: 13px;
  color: var(--ink-2);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* 搜尋結果分頁 */
.pager {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  margin-top: 16px;
}
.pager__btn {
  width: var(--tap); height: var(--tap);
  display: grid; place-items: center;
  border: 1px solid var(--line);
  border-radius: var(--r-full);
  background: var(--surface);
  color: var(--ink-2);
  cursor: pointer;
  transition: opacity .14s;
}
.pager__btn:active { background: var(--surface-2); }
.pager__btn:disabled { opacity: .32; pointer-events: none; }
#page-prev .ic { transform: rotate(180deg); }
.pager__info {
  min-width: 92px;
  text-align: center;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  color: var(--ink-2);
}

.daysep {
  margin: 16px 0 8px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .08em;
  color: var(--ink-3);
}
.daysep:first-child { margin-top: 0; }

/* ---------- 6b. 月曆 ---------- */
/* pan-y：上下捲動交給瀏覽器，左右手勢留給我們自己換月 */
.cal { padding: 12px 10px 14px; touch-action: pan-y; }

.cal__head {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 0 4px 8px;
}
.cal__title {
  font-size: 16px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  min-width: 96px;
  text-align: center;
}
.cal__nav {
  width: 36px; height: 36px;
  display: grid; place-items: center;
  border: 0; border-radius: var(--r-full);
  background: none; color: var(--ink-2);
  cursor: pointer;
}
.cal__nav:active { background: var(--surface-2); }
#cal-prev .ic { transform: rotate(180deg); }
.cal__today {
  margin-left: auto;
  min-height: 32px;
  padding: 0 13px;
  border: 1px solid var(--line);
  border-radius: var(--r-full);
  background: var(--surface-2);
  color: var(--ink-2);
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
}
.cal__today:active { opacity: .7; }

.cal__week,
.cal__grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
}
.cal__week {
  padding-bottom: 4px;
  font-size: 11px;
  color: var(--ink-3);
  text-align: center;
}
.cal__grid { gap: 2px; }

/* 換月時讓新的月份從手指滑動的方向滑進來 */
@keyframes calInNext { from { opacity: 0; transform: translateX(16px); } to { opacity: 1; transform: none; } }
@keyframes calInPrev { from { opacity: 0; transform: translateX(-16px); } to { opacity: 1; transform: none; } }
.cal__grid--in-next { animation: calInNext .2s ease-out; }
.cal__grid--in-prev { animation: calInPrev .2s ease-out; }

@media (prefers-reduced-motion: reduce) {
  .cal__grid--in-next,
  .cal__grid--in-prev { animation: none; }
}

.cal__cell {
  position: relative;
  aspect-ratio: 1 / 1;
  min-height: 38px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  border: 0;
  border-radius: 12px;
  background: none;
  color: var(--ink);
  font-family: var(--font-num);
  font-size: 14px;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  transition: background .14s;
}
.cal__cell:disabled { cursor: default; }
.cal__cell--pad { visibility: hidden; }
.cal__cell--today { font-weight: 700; color: var(--brand); }
.cal__cell--on {
  background: var(--c-brand);
  color: #FFFCF6;
  font-weight: 700;
}
:root[data-theme="dark"] .cal__cell--on { background: var(--c-accent); color: #1A191A; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .cal__cell--on { background: var(--c-accent); color: #1A191A; }
}
.cal__dot {
  width: 4px; height: 4px;
  border-radius: var(--r-full);
  background: var(--star-on);
}
.cal__cell--on .cal__dot { background: currentColor; }
.cal__cell--empty .cal__dot { visibility: hidden; }

/* 本月摘要條 */
.msum {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  margin-bottom: 16px;
  padding: 12px 6px;
  border: 1px solid var(--line-2);
  border-radius: var(--r-md);
  background: var(--surface);
  box-shadow: var(--shadow-1);
}
.msum__item { text-align: center; }
.msum__item + .msum__item { border-left: 1px solid var(--line-2); }
.msum__v {
  font-family: var(--font-num);
  font-size: 20px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
}
.msum__l { margin-top: 2px; font-size: 11px; color: var(--ink-3); }

/* 選取日期標頭 */
.dayhead {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin: 0 2px 10px;
}
.dayhead__title { font-size: 14px; font-weight: 700; }
.dayhead__n { font-size: 12px; color: var(--ink-3); }

/* ---------- 7. 空狀態 ---------- */
.empty { text-align: center; padding: 56px 20px; color: var(--ink-3); }
.empty--sm { padding: 30px 20px; }
.empty__ic { width: 46px; height: 46px; color: var(--empty-ic); margin-bottom: 12px; }
.empty__title { font-size: 16px; font-weight: 600; color: var(--ink-2); }
.empty__desc { font-size: 13px; margin-top: 4px; }

/* ---------- 8. 表單元件 ---------- */
.field { margin-bottom: 18px; }
.field--row { display: flex; gap: 10px; }
.field__col { flex: 1 1 0; min-width: 0; display: block; }

.field__label {
  display: block;
  margin-bottom: 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-2);
  letter-spacing: .03em;
}
.req, .opt {
  font-style: normal;
  font-size: 10px;
  font-weight: 600;
  padding: 1px 5px;
  border-radius: var(--r-full);
  margin-left: 4px;
  vertical-align: 1px;
}
.req { color: var(--req-ink); background: var(--req-bg); }
.opt { color: var(--ink-3); background: var(--line-2); }

.input {
  width: 100%;
  min-height: var(--tap);
  padding: 10px 13px;
  font-size: 16px;               /* < 16px 會讓 iOS 聚焦時自動放大 */
  font-family: inherit;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  appearance: none;
  -webkit-appearance: none;
}
.input:focus { border-color: var(--brand); outline: none; box-shadow: 0 0 0 3px var(--line-2); }
.input::placeholder { color: var(--ink-3); }
.input--area { min-height: 88px; resize: vertical; line-height: 1.5; }
.input--select { padding-right: 40px; }
.input--icon { padding-left: 42px; }
.input.is-bad { border-color: var(--danger); }

/* 日期欄位：整格都可點（JS 會叫 showPicker），所以游標用手指 */
input[type="date"] {
  min-height: var(--tap);
  cursor: pointer;
}
input[type="date"]::-webkit-date-and-time-value { text-align: left; }
/* 桌機那顆小日曆圖示放大一點、對比高一點，比較看得出來可以點 */
input[type="date"]::-webkit-calendar-picker-indicator {
  width: 20px;
  height: 20px;
  padding: 2px;
  opacity: .55;
  cursor: pointer;
}
input[type="date"]::-webkit-calendar-picker-indicator:hover { opacity: 1; }
:root[data-theme="dark"] input[type="date"]::-webkit-calendar-picker-indicator { filter: invert(1); }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) input[type="date"]::-webkit-calendar-picker-indicator { filter: invert(1); }
}
input[type="search"]::-webkit-search-decoration,
input[type="search"]::-webkit-search-cancel-button { -webkit-appearance: none; }

.inputwrap { position: relative; }
.inputwrap__ic {
  position: absolute; left: 12px; top: 50%;
  transform: translateY(-50%);
  color: var(--ink-3); pointer-events: none;
}
.inputwrap__caret {
  position: absolute; right: 12px; top: 50%;
  transform: translateY(-50%) rotate(90deg);
  width: 18px; height: 18px;
  color: var(--ink-3); pointer-events: none;
}

.err { margin-top: 5px; font-size: 12px; color: var(--danger); }
.hint { margin-top: 6px; font-size: 12px; color: var(--ink-3); }

.divider {
  display: flex; align-items: center; gap: 10px;
  margin: 24px 0 16px;
  font-size: 12px; font-weight: 600; letter-spacing: .1em;
  color: var(--ink-3);
}
.divider::after { content: ""; flex: 1; height: 1px; background: var(--line); }

/* 茶種選擇：可換行的膠囊，取代下拉選單 */
.typegrid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--surface);
}
.typegrid.is-bad { border-color: var(--danger); }

.typechip {
  min-height: var(--tap);
  padding: 0 20px;
  border: 0;
  border-radius: var(--r-md);
  background: var(--surface-2);
  color: var(--ink-2);
  font-size: 15px;
  cursor: pointer;
  transition: background .16s, color .16s, transform .12s;
}
.typechip:active { transform: scale(.95); }
.typechip.is-on {
  background: var(--c-brand);
  color: #FFFCF6;
  font-weight: 600;
}
:root[data-theme="dark"] .typechip.is-on { background: var(--c-accent); color: #1A191A; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .typechip.is-on { background: var(--c-accent); color: #1A191A; }
}

/* 標籤：跟茶種同一種盒子，但膠囊更小，因為數量會長 */
.tagpick {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--surface);
}
.tagpick.is-bad { border-color: var(--danger); }

.tagchip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-height: 40px;
  padding: 0 15px;
  border: 1px solid transparent;
  border-radius: var(--r-full);
  background: var(--surface-2);
  color: var(--ink-2);
  font-size: 14px;
  font-family: inherit;
  cursor: pointer;
  transition: background .16s, color .16s, transform .12s;
}
.tagchip:active { transform: scale(.95); }
.tagchip .ic { width: 15px; height: 15px; }
.tagchip.is-on {
  background: var(--c-brand);
  color: #FFFCF6;
  font-weight: 600;
}
:root[data-theme="dark"] .tagchip.is-on { background: var(--c-accent); color: #1A191A; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .tagchip.is-on { background: var(--c-accent); color: #1A191A; }
}

/* 不在目前茶種選單裡、但已經貼在這筆紀錄上的標籤 */
.tagchip--orphan { border-style: dashed; border-color: var(--line); }

/* 「新增」「管理」這兩顆功能鍵 */
.tagchip--act {
  background: none;
  border-style: dashed;
  border-color: var(--line);
  color: var(--ink-3);
}
.tagchip--act.is-on {
  background: var(--surface-2);
  border-style: solid;
  color: var(--ink-2);
  font-weight: 600;
}

/* 管理模式：左半改名、右半刪除，中間一條分隔線 */
.tagchip--row {
  padding: 0;
  overflow: hidden;
  border-color: var(--line);
  background: var(--surface-2);
}
.tagchip__name,
.tagchip__del {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  border: 0;
  background: none;
  font-family: inherit;
  cursor: pointer;
  transition: background .12s;
}
.tagchip__name {
  padding: 0 11px 0 14px;
  font-size: 14px;
  color: var(--ink-2);
}
.tagchip__name .ic { width: 13px; height: 13px; opacity: .5; }
.tagchip__del {
  padding: 0 13px;
  color: var(--danger);
  border-left: 1px solid var(--line);
}
.tagchip__del .ic { width: 14px; height: 14px; }
.tagchip__name:active,
.tagchip__del:active { background: var(--line-2); }

/* 星等 */
.stars { display: flex; gap: 4px; }
.star {
  width: var(--tap); height: var(--tap);
  display: grid; place-items: center;
  border: 0; background: none; cursor: pointer;
  border-radius: var(--r-sm);
}
.star .ic { width: 30px; height: 30px; fill: var(--star-off); transition: fill .12s, transform .12s; }
.star.is-on .ic { fill: var(--star-on); }
.star:active .ic { transform: scale(.86); }

/* 分段控制 */
.seg {
  display: inline-flex;
  padding: 3px;
  gap: 2px;
  background: var(--surface-2);
  border-radius: var(--r-full);
}
.seg__btn {
  min-height: 34px;
  padding: 0 13px;
  border: 0;
  border-radius: var(--r-full);
  background: none;
  color: var(--ink-2);
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
  transition: background .14s, color .14s;
}
.seg__btn.is-on {
  background: var(--raised);
  color: var(--ink);
  font-weight: 600;
  box-shadow: var(--shadow-1);
}
.seg--sm .seg__btn { min-height: 30px; padding: 0 11px; font-size: 12px; }
.seg--full { display: flex; width: 100%; margin-bottom: 14px; }
.seg--full .seg__btn { flex: 1 1 0; min-height: 36px; padding: 0 6px; }

/* 篩選 chips */
.chips {
  display: flex;
  gap: 7px;
  overflow-x: auto;
  padding: 2px calc(16px + var(--sar)) 10px calc(16px + var(--sal));
  margin: 10px calc(-16px - var(--sar)) 2px calc(-16px - var(--sal));
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none;
  min-height: 34px;
  padding: 0 13px;
  border: 1px solid var(--line);
  border-radius: var(--r-full);
  background: var(--surface);
  color: var(--ink-2);
  font-size: 13px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.chip.is-on { background: var(--chip-on-bg); border-color: var(--chip-on-bg); color: var(--chip-on-ink); font-weight: 600; }
.chip__dot { width: 9px; height: 9px; border-radius: var(--r-full); border: 1px solid var(--swatch-line); }
.chip.is-on .chip__dot { display: none; }

/* 圖表卡片裡的茶種選擇列 */
.chips--pick { margin: 0 0 14px; }

/* 進階篩選面板裡的 chips：不橫向捲動，直接換行 */
.chips--wrap {
  flex-wrap: wrap;
  overflow: visible;
  margin: 0;
  padding: 0;
}

/* 搜尋列 */
.searchbar { position: relative; display: flex; align-items: center; }
.searchbar__ic { position: absolute; left: 13px; color: var(--ink-3); pointer-events: none; }
.searchbar__input {
  width: 100%;
  min-height: var(--tap);
  padding: 10px 44px;
  font-size: 16px;
  font-family: inherit;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-full);
  appearance: none; -webkit-appearance: none;
}
.searchbar__input:focus { outline: none; border-color: var(--brand); }
.searchbar__clear {
  position: absolute; right: 5px;
  width: 36px; height: 36px;
  display: grid; place-items: center;
  border: 0; border-radius: var(--r-full);
  background: var(--surface-2); color: var(--ink-2);
  cursor: pointer;
}
.searchbar__clear .ic { width: 16px; height: 16px; }

/* 進階篩選 */
.more { margin: 4px 0 14px; }
.more__sum {
  display: flex; align-items: center; gap: 8px;
  min-height: var(--tap);
  font-size: 14px; color: var(--ink-2);
  cursor: pointer; list-style: none;
}
.more__sum::-webkit-details-marker { display: none; }
.more__ar { width: 16px; height: 16px; transition: transform .18s; }
.more[open] .more__ar { transform: rotate(90deg); }
.more__badge {
  min-width: 20px; height: 20px; padding: 0 6px;
  display: inline-grid; place-items: center;
  border-radius: var(--r-full);
  background: var(--badge-bg); color: var(--badge-ink);
  font-size: 11px; font-weight: 700;
}
.more__body {
  padding: 14px;
  border: 1px solid var(--line-2);
  border-radius: var(--r-md);
  background: var(--surface);
}
.more__body .field:last-of-type { margin-bottom: 12px; }

/* ---------- 9. 按鈕 ---------- */
.btn {
  min-height: var(--tap);
  padding: 0 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid transparent;
  border-radius: var(--r-md);
  background: var(--btn-bg);
  color: var(--btn-ink);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: transform .12s, opacity .12s;
}
.btn:active { transform: scale(.985); opacity: .88; }
.btn:disabled { opacity: .45; pointer-events: none; }
.btn--full { width: 100%; margin-bottom: 10px; }
.btn--ghost { background: transparent; border-color: var(--line); color: var(--ink); }
.btn--danger {
  background: transparent;
  border-color: color-mix(in srgb, var(--danger) 36%, transparent);
  color: var(--danger);
}
.btn--text {
  background: none; border: 0; color: var(--brand);
  padding: 0 4px; font-weight: 500; min-width: 52px;
}
.btn--strong { font-weight: 700; }
.btn--placeholder { visibility: hidden; }

/* ---------- 10. Sheet（全螢幕表單） ---------- */
.sheet { position: fixed; inset: 0; z-index: 60; }
.sheet[hidden] { display: none; }
.sheet__scrim {
  position: absolute; inset: 0;
  background: rgba(30, 28, 30, .38);
  animation: fade .2s ease-out;
}
.sheet__panel {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  max-height: 96dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  border-radius: var(--r-lg) var(--r-lg) 0 0;
  box-shadow: var(--shadow-2);
  animation: slideup .26s cubic-bezier(.32, .72, 0, 1);
  overflow: hidden;
}
@keyframes slideup { from { transform: translateY(100%); } to { transform: none; } }

.sheet__bar {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 52px;
  padding: 8px calc(14px + var(--sar)) 8px calc(14px + var(--sal));
  border-bottom: 1px solid var(--line-2);
  background: var(--surface);
}
.sheet__title { font-size: 16px; font-weight: 700; }

.sheet__body {
  flex: 1 1 auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 18px calc(16px + var(--sar)) 0 calc(16px + var(--sal));
}
.sheet__foot { height: calc(28px + var(--sab)); }

.note {
  font-size: 13px;
  line-height: 1.6;
  color: var(--ink-2);
  margin-bottom: 12px;
}
.note strong { color: var(--ink); }
.note--stat {
  padding: 10px 12px;
  border-radius: var(--r-sm);
  background: var(--surface-2);
  font-family: var(--font-num);
  font-variant-numeric: tabular-nums;
}
.note--about { margin: 22px 0 0; font-size: 11px; color: var(--ink-3); text-align: center; }

/* ---------- 11. 對話框 ---------- */
.dialog { position: fixed; inset: 0; z-index: 80; display: grid; place-items: center; padding: 24px; }
.dialog[hidden] { display: none; }
.dialog__scrim { position: absolute; inset: 0; background: rgba(30, 28, 30, .44); }
.dialog__box {
  position: relative;
  width: 100%; max-width: 340px;
  padding: 20px;
  border-radius: var(--r-lg);
  background: var(--surface);
  box-shadow: var(--shadow-2);
  animation: pop .2s cubic-bezier(.32, .72, 0, 1);
}
@keyframes pop { from { transform: scale(.94); opacity: 0; } to { transform: none; opacity: 1; } }
.dialog__title { font-size: 17px; font-weight: 700; }
.dialog__text { margin-top: 8px; font-size: 14px; color: var(--ink-2); line-height: 1.6; }
.dialog__field { margin-top: 14px; }
.dialog__acts { display: flex; gap: 10px; margin-top: 20px; }
.dialog__acts .btn { flex: 1; }

/* ---------- 12. Toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tabbar-h) + var(--sab) + 22px);
  z-index: 90;
  transform: translateX(-50%);
  max-width: calc(100vw - 40px);
  padding: 11px 18px;
  border-radius: var(--r-full);
  background: var(--toast-bg);
  color: var(--toast-ink);
  font-size: 14px;
  text-align: center;
  box-shadow: var(--shadow-2);
  animation: toastin .24s cubic-bezier(.32, .72, 0, 1);
}
.toast[hidden] { display: none; }
.toast.is-bad { background: var(--danger); color: #FFF; }
@keyframes toastin { from { transform: translate(-50%, 14px); opacity: 0; } to { transform: translateX(-50%); opacity: 1; } }

/* ---------- 13. 統計頁 ---------- */
.tiles {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-bottom: 14px;
}
.tile {
  padding: 13px 14px;
  border: 1px solid var(--line-2);
  border-radius: var(--r-md);
  background: var(--surface);
  box-shadow: var(--shadow-1);
}
.tile__label { font-size: 12px; color: var(--ink-3); letter-spacing: .04em; }
.tile__value {
  margin-top: 2px;
  font-family: var(--font-num);
  font-size: 26px;
  font-weight: 700;
  line-height: 1.15;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}
.tile__value.is-text { font-size: 19px; padding-top: 4px; }
.tile__unit { font-size: 13px; font-weight: 500; color: var(--ink-3); margin-left: 3px; }

.card {
  padding: 16px 14px;
  border: 1px solid var(--line-2);
  border-radius: var(--r-md);
  background: var(--surface);
  box-shadow: var(--shadow-1);
  margin-bottom: 14px;
}
.chart__head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.chart__title { font-size: 15px; font-weight: 700; }
.chart__sub { font-size: 12px; color: var(--ink-3); margin-top: 1px; }
.chart__body { margin-top: 12px; }
.chart__body svg { display: block; width: 100%; height: auto; overflow: visible; }

.donut__total-n {
  font-family: var(--font-num);
  font-size: 30px;
  font-weight: 700;
  fill: var(--ink);
}
.donut__total-l { font-size: 11px; fill: var(--ink-3); letter-spacing: .06em; }
.slice { transition: opacity .14s; cursor: default; }
.slice--seg { stroke: var(--line); stroke-width: .8; }   /* 淺色扇形與卡片底色的分界 */
.slice.is-dim, .slice-label.is-dim { opacity: .28; }
.lead { stroke: var(--ink-3); stroke-width: 1; fill: none; opacity: .5; }
.leadtext { font-size: 11px; fill: var(--ink-2); font-family: var(--font-num); }

.legend {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px 10px;
  margin-top: 14px;
}
.legend__row {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 4px 2px;
  font-size: 12.5px;
  min-height: 30px;
  background: none;
  border: 0;
  text-align: left;
  cursor: pointer;
  border-radius: var(--r-sm);
}
.legend__row.is-dim { opacity: .38; }
.legend__sw {
  width: 12px; height: 12px; flex: none;
  border-radius: 3px;
  border: 1px solid var(--swatch-line);
}
.legend__name { color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.legend__val {
  margin-left: auto;
  font-family: var(--font-num);
  font-variant-numeric: tabular-nums;
  color: var(--ink);
  font-weight: 600;
}

.tablewrap { margin-top: 14px; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.dtable { width: 100%; border-collapse: collapse; font-size: 13px; }
.dtable th, .dtable td { padding: 7px 8px; text-align: left; border-bottom: 1px solid var(--line-2); }
.dtable th { font-size: 11px; color: var(--ink-3); font-weight: 600; letter-spacing: .05em; }
.dtable td:last-child, .dtable th:last-child { text-align: right; }
.dtable td.num { font-family: var(--font-num); font-variant-numeric: tabular-nums; }

/* 橫條圖 */
.bars { display: flex; flex-direction: column; gap: 9px; }
.bar { display: flex; align-items: center; gap: 10px; }
.bar__key {
  flex: none; width: 58px;
  display: flex; align-items: center; gap: 3px;
  font-size: 12px; color: var(--ink-2);
}
.bar__key .ic { width: 12px; height: 12px; fill: var(--star-on); }
.bar__track { flex: 1 1 auto; height: 12px; border-radius: var(--r-full); background: var(--surface-2); overflow: hidden; }
.bar__fill {
  display: block;                 /* inline span 吃不到 width，必須改成 block */
  height: 100%;
  border-radius: var(--r-full);
  transition: width .3s ease-out;
}
.bar__val {
  flex: none; min-width: 30px; text-align: right;
  font-family: var(--font-num); font-size: 12px;
  font-variant-numeric: tabular-nums; color: var(--ink-2);
}

/* 標籤橫條圖：名稱比星等長，鍵位要加寬並截斷 */
.bars--tags .bar__key { width: 96px; }
.bar__dot {
  flex: none;
  width: 8px; height: 8px;
  border-radius: var(--r-full);
  border: 1px solid var(--swatch-line);
}
.bar__name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* 月份直條圖 */
.cols { display: flex; align-items: flex-end; gap: 4px; height: 128px; }
.col { flex: 1 1 0; display: flex; flex-direction: column; align-items: center; gap: 5px; min-width: 0; height: 100%; justify-content: flex-end; }
.col__bar { display: block; width: 100%; max-width: 26px; border-radius: 4px 4px 0 0; min-height: 2px; transition: height .3s ease-out; }
.col__n { font-family: var(--font-num); font-size: 10px; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.col__m { font-size: 9.5px; color: var(--ink-3); white-space: nowrap; }

/* ---------- 14. 偏好設定 ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}

@media (min-width: 480px) {
  .tiles { grid-template-columns: repeat(4, 1fr); }
  .legend { grid-template-columns: repeat(3, 1fr); }
}
