* { box-sizing: border-box; }
body {
  font-family: system-ui, "Microsoft JhengHei", sans-serif;
  margin: 0; background: #f5f6f8; color: #222;
}
header {
  background: #1f2937; color: #fff; padding: .8rem 1.2rem;
  display: flex; align-items: center; gap: 1.5rem; flex-wrap: wrap;
  position: sticky; top: 0; z-index: 30;   /* 捲動時固定在最上,不隨頁面滾走 */
}
header h1 { font-size: 1.1rem; margin: 0; }
header a { color: #fff; text-decoration: none; }
header nav a { margin-right: 1rem; opacity: .85; }
header nav a:hover { opacity: 1; }
main { max-width: 880px; margin: 1.5rem auto; padding: 0 1rem; }
h2 { margin-top: 1.8rem; }
.cards { display: flex; gap: 1rem; flex-wrap: wrap; }
.card {
  flex: 1 1 240px; background: #fff; border-radius: 10px; padding: 1.2rem;
  text-decoration: none; color: inherit; box-shadow: 0 1px 3px rgba(0,0,0,.08);
}
.card:hover { box-shadow: 0 2px 10px rgba(0,0,0,.12); }
.box {
  background: #fff; border-radius: 10px; padding: 1.2rem; display: grid; gap: .8rem;
  box-shadow: 0 1px 3px rgba(0,0,0,.08);
}
label { display: grid; gap: .3rem; font-size: .9rem; }
input, select, textarea {
  padding: .5rem; border: 1px solid #ccc; border-radius: 6px; font: inherit; width: 100%;
}
button {
  padding: .5rem .9rem; border: 0; border-radius: 6px; background: #2563eb; color: #fff;
  cursor: pointer; font: inherit;
}
button:hover { background: #1d4ed8; }
button.link-danger { background: #dc2626; }
.btn-small { font-size: .8rem; background: #2563eb; color: #fff; padding: .2rem .6rem; border-radius: 6px; text-decoration: none; }
table { width: 100%; border-collapse: collapse; background: #fff; margin-top: .6rem; border-radius: 8px; overflow: hidden; }
th, td { padding: .55rem .7rem; border-bottom: 1px solid #eee; text-align: left; font-size: .9rem; vertical-align: top; }
thead th { background: #f0f2f5; }
.actions { display: flex; gap: .4rem; flex-wrap: wrap; }
.actions form { display: inline; }
.muted { color: #888; }
.hint { color: #888; font-size: .85rem; margin-top: 1.2rem; }
.error { background: #fee2e2; color: #991b1b; padding: .6rem .8rem; border-radius: 6px; }
.success { background: #dafbe1; color: #116329; padding: .6rem .8rem; border-radius: 6px; }
.compare { display: flex; gap: 1rem; flex-wrap: wrap; align-items: flex-start; }
.compare .col { flex: 1 1 320px; }
.compare img { max-width: 100%; border: 1px solid #ccc; border-radius: 6px; }
.row2 { display: flex; gap: 1rem; }
.row2 label { flex: 1; }
.actions .spacer { flex: 1; }
#itemsTable input { padding: .35rem; }
#itemsTable td { padding: .3rem; }

/* Costco 分帳表 */
.cc-table td, .cc-table th { padding: .25rem .35rem; text-align: center; white-space: nowrap; }
.cc-table input { width: 5.5rem; padding: .25rem; text-align: right; }
.cc-table td:first-child input { width: 9rem; text-align: left; }
.cc-table td.ro { background: #fafbfc; color: #333; min-width: 4rem; }
.cc-table .person-head input { width: 6rem; text-align: center; }
.cc-table .btn-x { background: none; color: #cf222e; padding: 0 .2rem; font-size: 1rem; }
.cc-table .cc-foot td { border-top: 2px solid #c9ced4; font-weight: 600; }
.cc-table td.cell-ok { background: #dafbe1 !important; }   /* 核對相符:淺綠 */
/* 區塊分隔(熟食)與各區塊小計 */
.cc-table .cc-sec td {
  text-align: left; background: #eaeef2; color: #57606a;
  font-size: .85rem; padding: .3rem .5rem; border-top: 2px solid #c9ced4;
}
.cc-table .cc-sub td { border-top: 1px solid #c9ced4; background: #f6f8fa; font-weight: 600; }
/* 分帳表像 Excel 凍結窗格:表頭(兩列)、品名欄、總計列捲動時都固定 */
.cc-scroll { max-height: 75vh; }
.cc-scroll .cc-table { border-collapse: separate; border-spacing: 0; overflow: visible; margin-top: 0; }
.cc-scroll .cc-table thead th { z-index: 3; }
.cc-scroll .cc-table tbody td:first-child,
.cc-scroll .cc-table tfoot td:first-child {
  position: sticky; left: 0; z-index: 2; background: #fff; box-shadow: 1px 0 0 #d7dbe0;
}
.cc-scroll .cc-table thead tr:first-child th:first-child { left: 0; z-index: 4; box-shadow: 1px 1px 0 #d7dbe0; }
.cc-scroll .cc-table .cc-sub td:first-child { background: #f6f8fa; }
.cc-scroll .cc-table .cc-sec td { position: static; }
.cc-scroll .cc-table tfoot td { position: sticky; bottom: 0; z-index: 2; background: #f6f8fa; }
.cc-scroll .cc-table tfoot td:first-child { z-index: 3; background: #f6f8fa; }
/* 依歷史紀錄猜的分配:淡藍底,使用者一改就恢復白底 */
.cc-table td.guess input { background: #eef4ff; border-color: #54aeff; }
/* 購物小計 vs 收據總額的對帳結果 */
.check-line { margin: .5rem 0; padding: .45rem .6rem; border-radius: 6px; font-size: .9rem; }
.check-line.ok   { background: #dafbe1; border: 1px solid #1a7f37; color: #1a7f37; }
.check-line.warn { background: #fff8c5; border: 1px solid #9a6700; color: #7d4e00; font-weight: 600; }

/* 提醒頁 */
fieldset.rtype-fields {
  border: 1px solid #e2e5ea; border-radius: 8px; padding: .8rem 1rem;
  display: grid; gap: .8rem; margin: 0;
}
/* 關鍵:hidden 屬性要能蓋過上面的 display:grid,否則型別收合會失效 */
fieldset.rtype-fields[hidden] { display: none; }
fieldset.rtype-fields legend { color: #555; font-size: .85rem; padding: 0 .4rem; }
label.inline { display: flex; align-items: center; gap: .4rem; }
label.inline input { width: auto; }
.badge-danger {
  display: inline-block; margin-left: .4rem; padding: .05rem .4rem; border-radius: 5px;
  background: #fee2e2; color: #991b1b; font-size: .78rem;
}
tr.row-due td { background: #fff8ec; }
tr.row-done td { background: #f4f5f7; color: #999; }
tr.row-off td { background: #f1f2f4; color: #9aa0a6; }   /* 停用列淡灰 */
button.btn-off { background: #6b7280; }                   /* 停用鈕:灰 */
button.btn-off:hover { background: #4b5563; }
button.btn-on { background: #16a34a; }                     /* 啟用鈕:綠 */
button.btn-on:hover { background: #15803d; }
button:disabled, button:disabled:hover { background: #cbd5e1; color: #eef2f7; cursor: not-allowed; }
.io-row { display: flex; gap: .8rem; align-items: center; flex-wrap: wrap; }
.io-import { display: flex; gap: .5rem; align-items: center; }
.io-import input[type=file] { width: auto; }
.btn-link {
  display: inline-block; padding: .5rem .9rem; border-radius: 6px;
  background: #2563eb; color: #fff; text-decoration: none;
}
.btn-link:hover { background: #1d4ed8; }
button.link-warn { background: #d97706; }

/* 提醒頁:左側固定大綱 + 加寬內文 */
.side-outline {
  position: fixed; left: 0; top: 3rem;                 /* 貼左邊、在 header 下方 */
  width: 150px; height: calc(100vh - 3rem); overflow-y: auto;
  display: flex; flex-direction: column; gap: .25rem;
  background: #fff; border-right: 1px solid var(--border, #e3e6ea);
  padding: 1rem .6rem; z-index: 5;
}
.side-outline .outline-title { font-size: .75rem; color: #999; padding: 0 .4rem .35rem; }
.side-outline a { text-decoration: none; color: #333; padding: .5rem .55rem; border-radius: 6px; font-size: .92rem; }
.side-outline a:hover { background: #eef2f7; }

main.rem-wide { margin: 1.5rem 2rem 1.5rem 176px; max-width: none; }  /* 讓左邊給大綱、內文拉寬 */
main.rem-wide section { scroll-margin-top: 4rem; }                    /* 錨點跳轉時不被 header 蓋住 */
main.rem-wide h2:first-child { margin-top: 0; }

.cancel-edit { font-size: .8rem; font-weight: normal; margin-left: .6rem; color: #dc2626; text-decoration: none; }
tr.row-editing td { background: #eef6ff; box-shadow: inset 3px 0 0 #2563eb; }

/* 新增/編輯:半寬、與上一段拉開間距、按鈕移到標題右側 */
.compose { max-width: 620px; margin-top: 3rem; padding-top: 1.5rem; border-top: 1px solid #e6e8eb; }
.compose-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.compose-head h2 { margin: 0; border: none; }
.compose-head #saveBtn { flex: 0 0 auto; }

/* 現有提醒:自身可捲動,約 10 項高度,不會把整頁拉很長 */
.table-scroll { max-height: 620px; overflow-y: auto; border: 1px solid #eee; border-radius: 8px; }
.table-scroll table { margin: 0; }
/* 捲動時表頭固定在容器最上;要自帶背景+陰影,內容才不會透出來 */
.table-scroll thead th {
  position: sticky; top: 0; z-index: 2;
  background: #f0f2f5; box-shadow: 0 1px 0 #d7dbe0;
}
/* 可排序欄位標題 */
th.sortable { cursor: pointer; user-select: none; white-space: nowrap; }
th.sortable::after { content: "⇅"; opacity: .3; font-size: .8em; margin-left: .3em; }
th.sortable[data-dir="asc"]::after { content: "▲"; opacity: .75; }
th.sortable[data-dir="desc"]::after { content: "▼"; opacity: .75; }

/* 操作按鈕縮小(只縮內距,字級不變) */
.actions button, .actions .btn-small { padding: .2rem .5rem; }
.actions { gap: .3rem; }

/* 匯出/匯入:跟前一段用分隔線拉開(同 compose) */
main.rem-wide #io { margin-top: 3rem; padding-top: 1.5rem; border-top: 1px solid #e6e8eb; }

.pm-quick { display: none; }
@media (max-width: 820px) {
  .side-outline { display: none; }
  .pm-quick { display: flex; flex-wrap: wrap; gap: .5rem; margin-bottom: 1rem; }
  .pm-quick a { padding: .45rem .8rem; border: 1px solid #d0d7de; border-radius: 8px; background: #f6f8fa; color: #1f2328; text-decoration: none; font-size: .92rem; }
  main.rem-wide { margin: 1.5rem 1rem; }
}

/* ── 說明文件分頁 ── */
/* 文件本身自帶左側大綱(280px)+ 表格,再套站台預設的 880px 會把內容欄擠到
   剩 500px 左右,4 欄表格就變成一字一行。這頁改成吃滿視窗寬。 */
main.help-wide { max-width: none; margin: 1.5rem 2rem; padding: 0; }  /* 基底 main 有 padding:0 1rem,這裡收掉讓 iframe 吃滿 */
/* 這頁上方的東西比較少(標題+一行說明+分頁列),iframe 可以拉高一點 */
main.help-wide .doc-frame { height: calc(100vh - 13rem); min-height: 520px; }

@media (max-width: 820px) {
  main.help-wide { margin: 1rem; }
  main.help-wide .doc-frame { height: 74vh; min-height: 360px; }
}

/* ── 報表頁 ── */
.report-section { margin-bottom: 3rem; }
.report-head { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.report-head h2 { margin: 0; }
.report-range select { padding: .25rem .4rem; border: 1px solid #cfd4da; border-radius: 6px; }
.report-desc { color: #4b5563; font-size: .92rem; line-height: 1.6; margin: .5rem 0 1rem; max-width: 780px; }
.report-desc .muted { color: #9aa1ab; }
.forecast-summary {
  background: #fff; border: 1px solid #e6e8eb; border-radius: 8px;
  padding: .6rem .9rem; font-size: .95rem; margin-bottom: 1rem;
}
.forecast-summary strong { color: #1d4ed8; font-variant-numeric: tabular-nums; }

.chart-wrap { position: relative; background: #fff; border: 1px solid #e6e8eb; border-radius: 10px; padding: .8rem; }
#forecast-chart { width: 100%; height: auto; display: block; }
#forecast-chart .seg { cursor: pointer; }
#forecast-chart .axis-label { fill: #8a929c; font-size: 12px; }
#forecast-chart .axis-year { fill: #b3b9c2; font-size: 11px; }
#forecast-chart .bar-total { fill: #4b5563; font-size: 11px; font-weight: 600; }

.chart-tip {
  position: absolute; pointer-events: none; z-index: 10;
  background: #1f2937; color: #fff; font-size: .82rem; line-height: 1.4;
  padding: .4rem .6rem; border-radius: 6px; box-shadow: 0 2px 8px rgba(0,0,0,.25);
  white-space: nowrap;
}
.chart-tip .tip-freq { color: #9ca3af; font-size: .75rem; }

.chart-legend { display: flex; flex-wrap: wrap; gap: .35rem 1.1rem; margin-top: 1rem; }
.legend-item { display: flex; align-items: center; gap: .4rem; font-size: .88rem; }
.legend-item .swatch { width: 12px; height: 12px; border-radius: 3px; flex: 0 0 auto; }
.legend-name { color: #333; }
.legend-total { color: #6b7280; font-variant-numeric: tabular-nums; }

.empty-hint {
  background: #fff; border: 1px dashed #cfd4da; border-radius: 10px;
  padding: 1.4rem; color: #4b5563; line-height: 1.7;
}

/* ── HTML 文件掛載頁 ── */
main.html-wide { max-width: 1200px; }

/* 橫向分頁:文件多了就超出寬度,容器自己橫捲,不撐破頁面 */
.doc-tabs {
  display: flex; gap: .3rem; overflow-x: auto; -webkit-overflow-scrolling: touch;
  margin: 1.2rem 0 0; padding-bottom: .1rem;
  border-bottom: 1px solid #dde2e8;
}
.doc-tab {
  flex: 0 0 auto; white-space: nowrap;
  padding: .5rem .9rem; font-size: .92rem;
  background: #e9edf2; color: #444; text-decoration: none;
  border: 1px solid #dde2e8; border-bottom: 0;
  border-radius: 8px 8px 0 0;
}
.doc-tab:hover { background: #dfe5ec; }
.doc-tab.active {
  background: #fff; color: #1d4ed8; font-weight: 600;
  margin-bottom: -1px; padding-bottom: calc(.5rem + 1px);   /* 蓋住下緣那條線,做出「連著內容」的效果 */
}

.doc-frame-wrap {
  background: #fff; border: 1px solid #dde2e8; border-top: 0;
  border-radius: 0 0 10px 10px; overflow: hidden;
}
.doc-frame {
  display: block; width: 100%; border: 0;
  height: calc(100vh - 16rem); min-height: 460px;
}

.doc-meta {
  display: flex; align-items: center; justify-content: space-between;
  gap: .8rem; flex-wrap: wrap; margin-top: .7rem; font-size: .88rem;
}
.doc-meta-actions { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
.doc-meta-actions form { display: flex; gap: .35rem; align-items: center; }
.doc-rename input { width: 12rem; padding: .3rem .45rem; font-size: .88rem; }
.doc-meta-actions button { padding: .3rem .7rem; font-size: .85rem; }

/* ══════════════════════════════════════════════════════════════
   行動裝置調整(第一層:純 CSS,不動任何 HTML)
   ══════════════════════════════════════════════════════════════ */

/* 寬表格自身橫向捲動,不要撐破頁面
   (.table-scroll 原本只有 overflow-y,寬度方向會溢出到 body) */
.table-scroll { overflow-x: auto; }

/* 觸控裝置:輸入元件字級一律 >= 16px。
   iOS Safari 只要 input 字級 < 16px,一聚焦就會自動放大整頁,版面全歪。
   原本 input 用 `font: inherit` 繼承了 label 的 .9rem(14.4px) 才踩到這個雷。
   用 pointer:coarse 限定觸控裝置 → PC 維持原本緊湊字級,不受影響。 */
@media (pointer: coarse) {
  input, select, textarea { font-size: 16px; }
}

@media (max-width: 640px) {
  /* 頁首:nav 換行時收緊,免得 sticky header 吃掉太多畫面 */
  header { gap: .6rem 1rem; padding: .6rem .8rem; }
  header nav a { margin-right: .8rem; }

  main { margin: 1rem auto; padding: 0 .8rem; }
  main.rem-wide { margin: 1rem; }
  h2 { margin-top: 1.4rem; }

  /* 裸放的表格(歷史帳單、明細等)也能自己橫捲。
     table 轉 block 後寬度改由內容決定,溢出部分在自己容器裡捲。 */
  main table { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .table-scroll table { display: table; }
  .cc-scroll { max-height: 70vh; }
  .cc-scroll .cc-table td:first-child input { width: 6.5rem; }   /* 這個已有外層容器負責捲,不必再轉 */

  /* 觸控目標放大到堪按的高度(桌機維持 .2rem 緊湊內距) */
  .actions button, .actions .btn-small, .actions .btn-link {
    min-height: 40px; padding: .45rem .7rem; display: inline-flex;
    align-items: center; justify-content: center;
  }
  .actions { gap: .4rem; }
  button, .btn-link { min-height: 40px; }

  /* 兩欄表單在窄螢幕改成上下排,不要硬擠成各半寬 */
  .row2 { flex-wrap: wrap; }
  .row2 label { flex: 1 1 240px; }

  /* 表單區塊留白收斂 */
  .box { padding: 1rem; }
  .compose { margin-top: 2rem; padding-top: 1.2rem; }
  .compose-head { flex-wrap: wrap; }

  /* 現有提醒列表:手機畫面矮,固定 620px 高度太佔版面 */
  .table-scroll { max-height: 70vh; }

  /* ── 現有提醒:手機改成卡片式 ──
     6 欄橫排在 375px 寬根本擺不下,而且「操作」欄有 5 顆按鈕,
     在窄欄位裡會垂直堆成一長條,把整列高度撐到超過半個螢幕。
     改成一列 = 一張卡片,用 grid 重排資訊密度。 */
  #existing .table-scroll {
    max-height: none; overflow: visible;
    border: 0; border-radius: 0; background: transparent;
  }
  #existing table {
    display: block; overflow: visible;
    background: transparent; box-shadow: none; margin-top: .8rem;
  }
  #existing thead { display: none; }          /* 欄名改用卡片內排版表達 */
  #existing tbody, #existing tr, #existing td { display: block; }

  #existing tbody tr {
    background: #fff; border: 1px solid #e6e8eb; border-radius: 10px;
    box-shadow: 0 1px 3px rgba(0,0,0,.08);
    padding: .75rem .85rem; margin-bottom: .7rem;
    display: grid; grid-template-columns: 1fr auto; gap: .3rem .7rem;
    align-items: baseline;
  }
  #existing tbody td { border: 0; padding: 0; font-size: .9rem; }

  #existing .c-name   { grid-column: 1; grid-row: 1; font-size: 1rem; font-weight: 600; }
  #existing .c-amount { grid-column: 2; grid-row: 1; text-align: right; font-weight: 600;
                        font-variant-numeric: tabular-nums; white-space: nowrap; }
  #existing .c-type   { grid-column: 1; grid-row: 2; color: #6b7280; font-size: .82rem; }
  #existing .c-status { grid-column: 2; grid-row: 2; text-align: right; font-size: .82rem; }
  #existing .c-due    { grid-column: 1 / -1; grid-row: 3; }
  #existing .actions  { grid-column: 1 / -1; grid-row: 4; margin-top: .35rem; }

  /* 「啟用」是常態,不必每張卡都佔一格;只有停用才需要明講 */
  #existing tbody tr:not(.row-off) .c-status { display: none; }

  #existing .c-due::before {
    content: attr(data-label) "  ";
    color: #9aa1ab; font-size: .8rem;
  }

  /* 卡片寬度夠,按鈕橫排即可(不再是撐高列高的元兇);
     內距收回來,5 顆大約排成兩行 */
  #existing .actions { display: flex; flex-wrap: wrap; gap: .35rem; }
  #existing .actions button,
  #existing .actions .btn-small {
    min-height: 36px; padding: .35rem .6rem; font-size: .85rem;
  }

  /* 整列狀態底色在卡片模式要下到 tr 本身,否則 td 沒背景會失效 */
  #existing tbody tr.row-due  { background: #fff8ec; }
  #existing tbody tr.row-done { background: #f4f5f7; }
  #existing tbody tr.row-off  { background: #f1f2f4; }
  #existing tbody tr.row-due td, #existing tbody tr.row-done td,
  #existing tbody tr.row-off td { background: transparent; }

  /* ── HTML 文件頁 ── */
  /* 手機畫面矮,iframe 用固定 vh;分頁列本身已經會橫捲,不必再壓縮 */
  .doc-frame { height: 68vh; min-height: 320px; }
  .doc-tab { padding: .55rem .8rem; font-size: .88rem; }
  .doc-tab.active { padding-bottom: calc(.55rem + 1px); }
  .doc-meta { font-size: .82rem; }
  .doc-meta-actions { width: 100%; }
  .doc-rename { flex: 1 1 100%; }
  .doc-rename input { flex: 1; width: auto; }
  .doc-meta-actions button, .doc-meta-actions .btn-small { min-height: 36px; }
}

/* ══════════════════════════════════════════════════════════════
   專案管理
   ══════════════════════════════════════════════════════════════ */
.side-outline a.sub { padding-left: 1.4rem; font-size: .86rem; color: #555; }

/* 燈號:0 正常 / 1 即將到期 / 2 逾期 */
.pm-light {
  display: inline-block; width: .75rem; height: .75rem; border-radius: 50%;
  background: #1a7f37; flex: 0 0 auto; vertical-align: middle;
}
.health-1 .pm-light, .pm-light.health-1 { background: #d97706; }
.health-2 .pm-light, .pm-light.health-2 { background: #dc2626; }

.pm-status { font-size: .75rem; font-weight: normal; background: #e5e7eb; color: #4b5563; padding: .05rem .45rem; border-radius: 5px; }

.pm-alerts { list-style: none; padding: 0; margin: .6rem 0 0; display: grid; gap: .4rem; }
.pm-alerts li a {
  display: flex; flex-wrap: wrap; align-items: center; gap: .3rem .5rem;
  background: #fff; border: 1px solid #e6e8eb; border-left: 4px solid #d97706;
  border-radius: 8px; padding: .5rem .8rem; color: inherit; text-decoration: none; font-size: .92rem;
}
.pm-alerts li.is-overdue a { border-left-color: #dc2626; }
.pm-alerts li a:hover { background: #f8fafc; }
.pm-alert-when { font-weight: 600; min-width: 5.5em; }
.pm-alerts li.is-overdue .pm-alert-when { color: #b91c1c; }

.pm-kind { font-size: .75rem; padding: .05rem .4rem; border-radius: 5px; background: #eef2ff; color: #3730a3; }
.pm-kind-milestone { background: #dbeafe; color: #1e40af; }
.pm-kind-waiting { background: #fef3c7; color: #92400e; }

.pm-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: .9rem; margin-top: .6rem; }
.pm-card {
  display: grid; gap: .45rem; background: #fff; border: 1px solid #e6e8eb; border-radius: 10px;
  padding: .9rem 1rem; color: inherit; text-decoration: none; box-shadow: 0 1px 3px rgba(0,0,0,.06);
}
.pm-card:hover { box-shadow: 0 2px 10px rgba(0,0,0,.12); }
.pm-card.is-paused, .pm-card.is-closed { opacity: .65; }
.pm-card-head { display: flex; align-items: center; gap: .5rem; font-size: 1.02rem; }
.pm-card-meta { display: flex; gap: .5rem; align-items: center; font-size: .85rem; color: #4b5563; flex-wrap: wrap; }
.pm-card-meta .badge-danger { margin-left: 0; }
.pm-card-next { font-size: .88rem; }
.pm-badge-wait { font-size: .78rem; padding: .05rem .4rem; border-radius: 5px; background: #fef3c7; color: #92400e; }

.pm-progress { height: 6px; background: #e5e7eb; border-radius: 3px; overflow: hidden; }
.pm-progress span { display: block; height: 100%; background: #2563eb; }

.pm-overview { display: flex; flex-wrap: wrap; gap: .4rem 1.6rem; margin: .4rem 0 .7rem; font-size: .92rem; }
.pm-notes { white-space: pre-wrap; color: #4b5563; font-size: .9rem; background: #fff; border: 1px solid #e6e8eb; border-radius: 8px; padding: .6rem .8rem; }
#overview h2 { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }

main.rem-wide h3 { margin: 1.4rem 0 .5rem; font-size: 1rem; scroll-margin-top: 4rem; }
.pm-items { list-style: none; padding: 0; margin: 0; display: grid; gap: .35rem; }
.pm-items li {
  display: flex; align-items: flex-start; gap: .7rem;
  background: #fff; border: 1px solid #e6e8eb; border-radius: 8px; padding: .55rem .75rem;
}
.pm-items li.is-soon { background: #fff8ec; }
.pm-items li.is-overdue { background: #fef2f2; border-color: #fecaca; }
.pm-items li.is-done { background: #f4f5f7; color: #999; }
.pm-items li.is-done .pm-item-title { text-decoration: line-through; }
.pm-items li.is-editing, .pm-timeline li.is-editing { box-shadow: inset 3px 0 0 #2563eb; background: #eef6ff; }
.pm-check button {
  width: 1.5rem; height: 1.5rem; min-height: 0; padding: 0; border-radius: 5px;
  background: #fff; border: 2px solid #9ca3af; color: #1a7f37; font-weight: 700; line-height: 1;
}
.pm-check button:hover { background: #f0fdf4; border-color: #1a7f37; }
.pm-item-body { flex: 1; min-width: 0; }
.pm-item-title { font-weight: 600; }
.pm-item-meta { font-size: .85rem; margin-top: .15rem; }
.pm-owner { font-weight: normal; font-size: .78rem; margin-left: .4rem; padding: .05rem .4rem; border-radius: 5px; background: #eef2f7; color: #374151; }
#item-compose { max-width: 720px; margin-top: 1.6rem; }
#item-compose .compose-head h3 { margin: 0; }

.pm-log-filter { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; margin-bottom: .8rem; }
.pm-log-filter select { width: auto; }
.pm-log-filter input[type=search] { flex: 1 1 200px; width: auto; }

.pm-timeline { list-style: none; padding: 0; margin: 0 0 1.5rem; border-left: 2px solid #d0d7de; }
.pm-timeline li { position: relative; margin: 0 0 .8rem 1rem; background: #fff; border: 1px solid #e6e8eb; border-radius: 8px; padding: .55rem .8rem; }
.pm-timeline li::before {
  content: ""; position: absolute; left: calc(-1rem - 6px); top: .9rem;
  width: 10px; height: 10px; border-radius: 50%; background: #9ca3af; border: 2px solid #f5f6f8;
}
.pm-timeline li.pm-log-decision::before { background: #7c3aed; }
.pm-timeline li.pm-log-meeting::before { background: #2563eb; }
.pm-timeline li.pm-log-issue::before { background: #dc2626; }
.pm-timeline li.pm-log-client::before { background: #d97706; }
.pm-timeline li.pm-log-commit::before { background: #1f2937; }
.pm-timeline li.pm-log-decision { border-left: 3px solid #7c3aed; }
.pm-log-head { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; font-size: .85rem; }
.pm-log-date { font-weight: 600; font-variant-numeric: tabular-nums; }
.pm-logkind { padding: .05rem .4rem; border-radius: 5px; background: #eef2f7; color: #374151; font-size: .78rem; }
.pm-log-decision .pm-logkind { background: #ede9fe; color: #5b21b6; }
.pm-vis { font-size: .78rem; color: #92400e; }
.pm-log-actions { margin-left: auto; display: flex; gap: .6rem; align-items: center; }
.pm-log-actions a { font-size: .8rem; color: #2563eb; text-decoration: none; }
.pm-log-actions form { display: inline; }
button.pm-linkbtn { background: none; color: #dc2626; padding: 0; font-size: .8rem; min-height: 0; }
.pm-log-content { white-space: pre-wrap; margin-top: .3rem; font-size: .93rem; line-height: 1.55; }
#log-compose + form { max-width: 720px; }

.pm-ics-url { display: block; padding: .5rem .7rem; background: #f6f8fa; border: 1px solid #d0d7de; border-radius: 6px; word-break: break-all; user-select: all; }

@media (max-width: 640px) {
  .pm-items li { flex-wrap: wrap; }
  .pm-items .actions { width: 100%; justify-content: flex-end; }
  .pm-check button { width: 2rem; height: 2rem; }
  .pm-log-actions { margin-left: 0; width: 100%; justify-content: flex-end; }
}
main.pm-page > section + section { margin-top: 2.6rem; }
main.pm-page > section + section.compose { margin-top: 3rem; }

/* ── 專案 第 2 期:標籤、決策一覽、甘特、請款 ── */
.pm-tag { display: inline-block; font-size: .78rem; margin-left: .3rem; padding: .05rem .4rem; border-radius: 5px; background: #eef2f7; color: #374151; }
.pm-bill-billable { background: #fef3c7; color: #92400e; }
.pm-bill-invoiced { background: #dbeafe; color: #1e40af; }
.pm-bill-paid, .pm-agreed { background: #dcfce7; color: #166534; }
.pm-log-change .pm-logkind { background: #ffedd5; color: #9a3412; }
.pm-log-extra { font-size: .88rem; margin-top: .2rem; }
.pm-decisions td { vertical-align: top; font-size: .9rem; }
/* 左右、上下都在 .gantt-wrap 這一層捲:名稱欄(sticky left)與表頭(sticky top)才會凍結。
   不能讓 .g-body 自己 overflow —— 那會變成 sticky 的參考框,而它本身不會左右捲,名稱欄就跟著滑走。 */
.gantt-wrap { overflow: auto; max-height: 75vh; -webkit-overflow-scrolling: touch; border: 1px solid #e5e7eb; border-radius: 8px; background: #fff; }
.gantt { min-width: 760px; --g-row: 34px; }
.gantt .g-row { display: grid; grid-template-columns: 200px 1fr; height: var(--g-row); border-bottom: 1px solid #f1f3f5; }
.gantt .g-head { height: 40px; border-bottom: 1px solid #e5e7eb; background: #fafbfc; }
/* 約 10 列,超過就框內捲動;表頭固定在上面 */
.gantt .g-head { position: sticky; top: 0; z-index: 4; }
.gantt .g-name { display: flex; align-items: center; gap: .35rem; padding: 0 .5rem; font-size: 13px; min-width: 0; }
.gantt .g-name input { width: auto; flex: none; margin: 0; }
.gantt .g-name a { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: #1f2328; text-decoration: none; }
.gantt .g-name a:hover { color: #0969da; text-decoration: underline; }
.gantt .g-track { position: relative; margin-right: 12px; }
.gantt .g-tick { position: absolute; bottom: 4px; font-size: 11px; color: #6b7280; padding-left: 3px; white-space: nowrap; border-left: 1px solid #e5e7eb; line-height: 1.25; }
.gantt .g-tick b { display: block; color: #374151; font-weight: 600; }
.gantt .g-grid { position: absolute; top: 0; bottom: 0; border-left: 1px solid #f1f3f5; }
.gantt .g-bar { position: absolute; top: 9px; height: 16px; border-radius: 4px; background: #bfdbfe; border: 1px solid #3b82f6; box-sizing: border-box; }
.gantt .g-bar.is-paused { background: #e5e7eb; border-color: #9ca3af; }
.gantt .g-bar.is-guess { border-style: dashed; }
.gantt .g-bar.clip-l { border-top-left-radius: 0; border-bottom-left-radius: 0; border-left: 3px double #3b82f6; }
.gantt .g-bar.clip-r { border-top-right-radius: 0; border-bottom-right-radius: 0; border-right: 3px double #3b82f6; }
.gantt .g-ms { position: absolute; top: 10px; width: 12px; height: 12px; margin-left: -6px; background: #7c3aed; border: 1px solid #fff; transform: rotate(45deg); }
.gantt .g-ms.is-done { background: #9ca3af; }
.gantt .g-today { position: absolute; top: 0; bottom: 0; border-left: 2px solid #dc2626; }
.gantt .g-out { position: absolute; top: 9px; left: 4px; font-size: 12px; }
.gantt .g-block.is-hidden { opacity: .45; }
/* 依外部只讀分組的組標題 */
.gantt .g-sec-head { height: 28px; background: #f6f8fa; border-top: 1px solid #d0d7de; border-bottom: 1px solid #d0d7de; }
.gantt .g-sec-head .g-name { background: #f6f8fa; font-weight: 600; font-size: 12.5px; color: #1f2328; }
/* 展開:專案 → 里程碑階段條(◆)→ 細項 */
.gantt .g-name { position: sticky; left: 0; z-index: 2; background: #fff; }
.gantt .g-head .g-name { background: #fafbfc; }
.gantt .g-head .g-name { z-index: 5; }
.gantt .g-fold { flex: none; width: 1.4rem; height: 1.4rem; padding: 0; border: 0; background: none; color: #57606a; font-size: 16px; line-height: 1; cursor: pointer; }
.gantt .g-fold:hover { color: #0969da; }
.gantt .g-fold-sp { flex: none; width: 1.4rem; }
.gantt .g-all { padding: .1rem .5rem; font-size: 12px; background: #f6f8fa; color: #1f2328; border: 1px solid #d0d7de; border-radius: 6px; }
.gantt .g-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gantt .g-count { flex: none; font-size: 11px; color: #57606a; background: #eaeef2; border-radius: 9px; padding: 0 .4rem; }
.gantt .g-tag { flex: none; font-size: 11px; color: #9a6700; background: #fff8c5; border-radius: 4px; padding: 0 .3rem; }
.gantt .g-lv1, .gantt .g-lv2 { height: 30px; background: #fbfcfd; }
.gantt .g-lv1 .g-name { padding-left: 1.4rem; background: #fbfcfd; font-size: 12.5px; }
.gantt .g-lv2 .g-name { background: #fbfcfd; font-size: 12px; color: #374151; }
.gantt .g-lv1.is-done .g-label, .gantt .g-lv2.is-done .g-label { color: #8c959f; text-decoration: line-through; }
.gantt .g-phase { position: absolute; top: 9px; height: 12px; border-radius: 3px; background: #ddd6fe; border: 1px solid #7c3aed; box-sizing: border-box; }
.gantt .g-phase.is-done { background: #e5e7eb; border-color: #9ca3af; }
.gantt .g-lv1 .g-ms { top: 8px; }
.gantt .g-task { position: absolute; top: 10px; height: 10px; border-radius: 3px; background: #bbf7d0; border: 1px solid #16a34a; box-sizing: border-box; }
.gantt .g-task.is-wait { background: #fef3c7; border-color: #d97706; }
.gantt .g-task.is-done { background: #e5e7eb; border-color: #9ca3af; }
.gantt .g-dot { position: absolute; top: 9px; width: 11px; height: 11px; margin-left: -5.5px; border-radius: 50%; background: #16a34a; border: 1px solid #fff; }
.gantt .g-dot.is-wait { background: #d97706; }
.gantt .g-dot.is-done { background: #9ca3af; }
.gantt .g-lv1 .g-out, .gantt .g-lv2 .g-out { top: 7px; }
@media (max-width: 640px) {
  .gantt .g-row { grid-template-columns: 150px 1fr; }
  .gantt .g-lv1 .g-name { padding-left: .6rem; }
}
.gantt-legend { display: flex; flex-wrap: wrap; gap: .3rem 1rem; font-size: 12px; color: #57606a; margin: .4rem 0 0; }
.gantt-legend i { display: inline-block; vertical-align: -1px; margin-right: .3rem; }
.gantt-legend .l-bar { width: 18px; height: 10px; background: #bfdbfe; border: 1px solid #3b82f6; border-radius: 3px; }
.gantt-legend .l-phase { width: 18px; height: 10px; background: #ddd6fe; border: 1px solid #7c3aed; border-radius: 3px; }
.gantt-legend .l-ms { width: 9px; height: 9px; background: #7c3aed; transform: rotate(45deg); }
.gantt-legend .l-task { width: 18px; height: 9px; background: #bbf7d0; border: 1px solid #16a34a; border-radius: 3px; }
.gantt-legend .l-wait { width: 9px; height: 9px; background: #d97706; border-radius: 50%; }
.gantt-legend .l-today { width: 2px; height: 12px; background: #dc2626; }

.gantt-range { display: flex; flex-wrap: wrap; align-items: center; gap: .4rem .6rem; }
.gantt-range label { display: flex; align-items: center; gap: .3rem; margin: 0; }
.gantt-range input[type=month] { width: auto; }
/* label.inline 有 display:flex,會蓋掉 hidden 屬性 */
.pm-agreed-field[hidden], .pm-reason-fields[hidden] { display: none; }
.billing-table td.num, .billing-table th.num { text-align: right; white-space: nowrap; }

/* ── 專案:貼文字整理預覽表 ── */
.pm-digest table { width: 100%; }
.pm-digest td { vertical-align: top; }
.pm-digest td input[type=text], .pm-digest td textarea, .pm-digest td select { width: 100%; box-sizing: border-box; }
.pm-digest td input[type=text] + input[type=text] { margin-top: .3rem; }
.pm-digest td:first-child { width: 2.5rem; text-align: center; }
.pm-digest-done { list-style: none; padding-left: 0; }
.pm-digest > div:last-child { margin-top: 1rem; }

/* ── 專案成員與權限(主站) ── */
.pm-member-head { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; margin-bottom: .4rem; }
.pm-perm-grid { width: 100%; }
.pm-perm-grid th:not(:first-child), .pm-perm-grid td:not(:first-child) { text-align: center; width: 4.5rem; }
.pm-perm-grid td:first-child .muted { font-size: .8rem; margin-left: .3rem; }
.pm-member .io-row { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; margin-top: .6rem; }
.pm-member-add { display: flex; gap: .8rem; align-items: end; flex-wrap: wrap; }
.pm-users td { vertical-align: middle; }
.pm-inline-form { display: flex; gap: .3rem; align-items: center; }
.pm-inline-form input { width: 9rem; }
.pm-user-actions { display: flex; gap: .6rem; }
.pm-newpw code { font-size: 1.1rem; padding: .1rem .4rem; }

/* ── 協作站 ── */
.portal header nav { display: flex; gap: .9rem; align-items: center; }
.portal-me { color: #cbd5e1; }
.portal-logout { display: inline; margin: 0; }
.portal-logout .pm-linkbtn { color: inherit; }
.portal-login { max-width: 380px; margin: 2rem auto; }
.pm-overview { display: flex; gap: .7rem; align-items: center; flex-wrap: wrap; margin-bottom: .4rem; }
.pm-check button:disabled { cursor: default; opacity: .6; }
