:root {
  --bg: #f4f6f9;
  --card: #fff;
  --text: #1f2933;
  --muted: #6b7785;
  --line: #dde3ea;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --danger: #dc2626;
  --ok-bg: #e8f6ee; --ok-fg: #166534;
  --warn-bg: #fff6e0; --warn-fg: #8a5a00;
  --err-bg: #fdecec; --err-fg: #9b1c1c;
  --weekend: #f7f8fb;
  --today: #eef4ff;
}
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.5 -apple-system, "Segoe UI", "Microsoft JhengHei", "PingFang TC", "Noto Sans TC", sans-serif;
}
a { color: var(--primary); text-decoration: none; }
h1 { font-size: 1.5rem; margin: 0; }
h2 { font-size: 1.1rem; margin: 0 0 .75rem; }

/* 導覽列: 寬螢幕橫排 + 「管理」與個人選單為下拉；窄螢幕收成漢堡選單 */
.topbar {
  display: flex; align-items: center; gap: 1.25rem;
  background: #1e293b; color: #fff; padding: .55rem 1.25rem; position: relative; z-index: 60;
}
.topbar .brand { color: #fff; font-weight: 700; font-size: 1.1rem; white-space: nowrap; }
.topnav { display: flex; align-items: center; gap: .75rem; flex: 1; min-width: 0; }
.topbar nav { display: flex; gap: .2rem; flex: 1; align-items: center; }
.topbar nav a, .nav-dd > summary { color: #cbd5e1; padding: .35rem .7rem; border-radius: 6px; white-space: nowrap; cursor: pointer; }
.topbar nav a:hover, .nav-dd > summary:hover { background: #334155; color: #fff; }
.topbar nav a.active, .nav-dd > summary.active { background: var(--primary); color: #fff; }
.nav-dd { position: relative; }
.nav-dd > summary { list-style: none; display: block; user-select: none; }
.nav-dd > summary::-webkit-details-marker { display: none; }
.nav-dd .caret { font-size: .7em; opacity: .8; }
.nav-dd[open] > summary { background: #334155; color: #fff; }
.nav-menu { position: absolute; top: calc(100% + 6px); left: 0; min-width: 160px; background: #fff; border: 1px solid var(--line); border-radius: 8px;
  box-shadow: 0 10px 30px rgba(15, 23, 42, .18); padding: .3rem; z-index: 70; }
.nav-menu.right { left: auto; right: 0; }
.topbar .nav-menu a, .nav-item-btn { display: block; width: 100%; text-align: left; color: var(--text); padding: .45rem .7rem; border-radius: 5px; background: none; border: 0; cursor: pointer; font: inherit; }
.topbar .nav-menu a:hover, .nav-item-btn:hover { background: #eef4ff; color: var(--text); }
.topbar .nav-menu a.active { background: #eef4ff; color: var(--primary); font-weight: 600; }
.nav-menu form { margin: 0; }
.topbar .me > summary { color: #e2e8f0; }
.nav-toggle { display: none; margin-left: auto; width: 40px; height: 36px; border: 1px solid #334155; border-radius: 6px; background: transparent; cursor: pointer; position: relative; }
.nav-toggle .bars, .nav-toggle .bars::before, .nav-toggle .bars::after { display: block; width: 18px; height: 2px; background: #e2e8f0; border-radius: 1px; position: absolute; left: 10px; }
.nav-toggle .bars { top: 17px; }
.nav-toggle .bars::before, .nav-toggle .bars::after { content: ''; left: 0; }
.nav-toggle .bars::before { top: -6px; }
.nav-toggle .bars::after { top: 6px; }
.nav-toggle[aria-expanded="true"] .bars { background: transparent; }
.nav-toggle[aria-expanded="true"] .bars::before { top: 0; transform: rotate(45deg); }
.nav-toggle[aria-expanded="true"] .bars::after { top: 0; transform: rotate(-45deg); }
.nav-toggle .badge.dot { position: absolute; top: -4px; right: -4px; width: 10px; height: 10px; min-width: 0; padding: 0; margin: 0; border-radius: 50%; background: var(--danger); }
@media (max-width: 900px) {
  .topbar { flex-wrap: wrap; gap: .5rem; padding: .5rem 1rem; }
  .nav-toggle { display: block; }
  .topnav { display: none; flex-basis: 100%; flex-direction: column; align-items: stretch; gap: 0; padding: .25rem 0 .5rem; border-top: 1px solid #334155; }
  .topbar.nav-open .topnav { display: flex; }
  .topbar nav { flex-direction: column; align-items: stretch; gap: 0; }
  .topbar nav a, .nav-dd > summary { padding: .55rem .75rem; }
  .nav-menu, .nav-menu.right { position: static; box-shadow: none; border: 0; background: transparent; padding: 0 0 0 1rem; min-width: 0; }
  .topbar .nav-menu a, .nav-item-btn { color: #cbd5e1; padding: .5rem .75rem; }
  .topbar .nav-menu a:hover, .nav-item-btn:hover, .topbar .nav-menu a.active { background: #334155; color: #fff; }
  .topbar .me { border-top: 1px solid #334155; margin-top: .25rem; padding-top: .25rem; }
}

.container { max-width: 1280px; margin: 0 auto; padding: 1.5rem 1rem 3rem; }
.page-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; margin-bottom: .25rem; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 1.25rem; margin: 1rem 0; }

.alert { padding: .7rem 1rem; border-radius: 8px; margin: .75rem 0; }
.alert.ok { background: var(--ok-bg); color: var(--ok-fg); }
.alert.warn { background: var(--warn-bg); color: var(--warn-fg); }
.alert.error { background: var(--err-bg); color: var(--err-fg); }

.muted { color: var(--muted); }
.small { font-size: .85em; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }
.inline { display: inline; }
.spacer { flex: 1; }

input, select, button { font: inherit; }
input:not([type=checkbox]):not([type=radio]), select {
  padding: .45rem .6rem; border: 1px solid var(--line); border-radius: 6px; background: #fff; width: 100%;
}
input:focus, select:focus { outline: 2px solid #bfd3fe; border-color: var(--primary); }
input.invalid, select.invalid { border-color: var(--danger); background: var(--err-bg); }
input:disabled:not([type=checkbox]):not([type=radio]), select:disabled, textarea:disabled {
  background: #f1f3f6; color: #8a95a3; border-color: #e6e9ee; cursor: not-allowed;
}
label { display: block; font-size: .9rem; color: var(--muted); margin-bottom: .75rem; }
label input, label select { margin-top: .25rem; color: var(--text); }
label.check { display: flex; align-items: center; gap: .4rem; color: var(--text); }

.btn {
  display: inline-block; padding: .45rem .9rem; border-radius: 6px; border: 1px solid var(--line);
  background: #fff; color: var(--text); cursor: pointer; white-space: nowrap;
}
.btn:hover { background: #f1f4f8; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-dark); }
.btn.danger { color: var(--danger); border-color: #f3c4c4; }
.btn.ghost { background: transparent; }
.btn.small { padding: .25rem .6rem; font-size: .85rem; }
.btn.block { width: 100%; padding: .6rem; }
.linkbtn { background: none; border: 0; padding: 0; color: var(--primary); cursor: pointer; }

.login-box { max-width: 380px; margin: 4rem auto; }
.login-box h1 { margin-bottom: 1rem; text-align: center; }
.login-links { text-align: center; margin: 1rem 0 0; }
/* 密碼欄: 右側「顯示 / 隱藏」按鈕 */
.pw-wrap { position: relative; display: block; margin-top: .25rem; }
.pw-wrap input { margin-top: 0; padding-right: 3.6rem; }
.pw-toggle {
  position: absolute; right: .35rem; top: 50%; transform: translateY(-50%);
  background: none; border: 0; padding: .2rem .45rem; border-radius: 4px;
  color: var(--primary); font-size: .85rem; cursor: pointer;
}
.pw-toggle:hover { background: #eef4ff; }
.caps-warn { margin: -.4rem 0 .75rem; padding: .3rem .6rem; border-radius: 6px; background: var(--warn-bg); color: var(--warn-fg); font-size: .85rem; }
.pw-hint { margin: -.25rem 0 1rem; }
.pw-hint li { margin: .1rem 0; }
.pw-hint ul { margin: .25rem 0 0; padding-left: 1.2rem; }
.topbar .badge { display: inline-block; min-width: 1.2rem; margin-left: .3rem; padding: 0 .35rem; border-radius: 999px; background: var(--danger); color: #fff; font-size: .75rem; line-height: 1.2rem; text-align: center; }

.form-row { display: flex; gap: .75rem; align-items: flex-end; flex-wrap: wrap; }
.form-row label { margin: 0; min-width: 140px; }
.form-row label.grow { flex: 1; min-width: 200px; }
.form-row label.check { padding-bottom: .5rem; }

.week-nav { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.week-nav input[type=week] { width: auto; }

.table-wrap { overflow-x: auto; }
table.grid { width: 100%; border-collapse: collapse; background: #fff; }
.grid th, .grid td { border-bottom: 1px solid var(--line); padding: .45rem .5rem; text-align: left; vertical-align: middle; }
.grid thead th { background: #f8fafc; font-weight: 600; font-size: .9rem; white-space: nowrap; }
.grid tfoot th { background: #f8fafc; }
.grid .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.grid .strong { font-weight: 600; }
.grid tr.inactive td { color: var(--muted); background: #fafafa; }
.grid tr.missing td { color: var(--err-fg); }
.grid td.note { max-width: 420px; font-size: .9rem; }
.grid input.w-code { width: 120px; }

.timesheet { min-width: 1080px; }
.timesheet .col-project { width: 260px; }
.timesheet .col-day { width: 72px; text-align: center; }
.timesheet .col-day input { text-align: center; padding: .4rem .2rem; }
.timesheet .col-total { width: 64px; text-align: center; font-weight: 600; }
.timesheet .col-del { width: 36px; text-align: center; }
.timesheet .weekend { background: var(--weekend); }
.timesheet .today { background: var(--today); }
.timesheet thead th.today { color: var(--primary); }
.timesheet .day-total { text-align: center; }
.timesheet .over { color: var(--danger); }
.timesheet .day-sum { display: table; margin: 3px auto 0; padding: 0 .4rem; border-radius: 999px; font-size: .78rem; font-weight: 700; line-height: 1.4; color: #c2410c; background: #fff1e6; }
.timesheet .day-sum.sum-ok { color: #15803d; background: #dcf5e6; }
.timesheet .day-sum.sum-over { color: #854d0e; background: #fde68a; }
.timesheet .day-sum.sum-off { color: #9aa4b1; background: #eef0f3; font-weight: 500; }
.timesheet .col-progress { width: 200px; }
.prog-cell { display: flex; align-items: center; gap: .25rem; }
.prog-cell select.pstat { width: 84px; min-width: 0; padding-left: .3rem; padding-right: .1rem; }
.prog-cell input.ppct { width: 54px; min-width: 0; text-align: right; padding: .4rem .25rem; }
.prog-cell .pct { color: var(--muted); font-size: .85rem; }
.prog-cell .pnote { text-decoration: none; font-size: 1.05rem; padding: 0 .15rem; }
.prog-cell .pnote:hover { background: #eef2f7; border-radius: 4px; }
.del-row { border: 0; background: none; color: var(--muted); font-size: 1.3rem; cursor: pointer; line-height: 1; }
.del-row:hover { color: var(--danger); }
.actions { display: flex; gap: .5rem; align-items: center; margin-top: 1rem; flex-wrap: wrap; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 1rem; margin: 1rem 0; }
.stat { background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 1rem 1.25rem; }
.stat-label { color: var(--muted); font-size: .9rem; }
.stat-value { font-size: 1.8rem; font-weight: 700; }
.stat-value small { font-size: .9rem; font-weight: 400; color: var(--muted); }
.card.export { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }

.tag { display: inline-block; padding: .1rem .5rem; border-radius: 999px; background: #eef2f7; font-size: .8rem; margin: 0 .25rem .25rem 0; color: var(--text); }
.tag.red { background: var(--err-bg); color: var(--err-fg); }

.form-row label.narrow { min-width: 90px; width: 120px; }
textarea {
  width: 100%; padding: .5rem .6rem; border: 1px solid var(--line); border-radius: 6px;
  font: inherit; color: var(--text); margin-top: .25rem; resize: vertical;
}
.pre { white-space: pre-wrap; }

.tabs { display: flex; gap: .25rem; border-bottom: 2px solid var(--line); margin: 1rem 0 .5rem; flex-wrap: wrap; }
.tab { padding: .5rem 1rem; color: var(--muted); border-bottom: 3px solid transparent; margin-bottom: -2px; }
.tab:hover { color: var(--text); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }
.tab-count { font-size: .8rem; background: #eef2f7; border-radius: 999px; padding: 0 .45rem; margin-left: .25rem; color: var(--muted); }
.mode-planned .timesheet thead th { background: #fdf7ec; }

.timesheet .holiday { background: #fdf0f0; }
.timesheet thead th.holiday { color: var(--danger); }
.timesheet input:disabled { background: #f1f3f6; color: #9aa4b1; cursor: not-allowed; border-color: #eceff3; }
.daymark { display: inline-block; font-size: .72rem; line-height: 1.3; padding: 0 .35rem; border-radius: 4px; margin-top: 2px; font-weight: 500; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.daymark.holiday { background: #fde2e2; color: #b91c1c; }
.daymark.workday { background: #e0ecff; color: #1d4ed8; }

.grid.projects select, .grid.projects input:not([type=checkbox]) { min-width: 0; }
.grid input.w-pct { width: 70px; }
.status { display: inline-block; padding: .1rem .5rem; border-radius: 999px; font-size: .82rem; font-weight: 600; white-space: nowrap; }
.status-normal { background: #e8f6ee; color: #15803d; }
.status-delayed { background: #fdecec; color: #b91c1c; }
.status-paused { background: #eef0f3; color: #4b5563; }
.status-pending_close { background: #fff1e6; color: #c2410c; }
.status-closed { background: #e6efff; color: #1d4ed8; }
.status-cancelled { background: #f3f4f6; color: #9ca3af; }
select.status-delayed { color: #b91c1c; font-weight: 600; }
.bar { display: inline-block; width: 80px; height: 8px; background: #e5e9f0; border-radius: 4px; overflow: hidden; vertical-align: middle; margin-right: .4rem; }
.bar > div { height: 100%; background: var(--primary); }
.prev-note { margin: .5rem 0; font-size: .9rem; }
.prev-note .pre { background: #f8fafc; border: 1px solid var(--line); border-radius: 6px; padding: .6rem; margin-top: .4rem; }
.grid .pos { color: #b45309; }
.grid .neg { color: #2563eb; }

/* 公司自訂日期 (與國定假日不同色系) */
.daymark.company-off { background: #ffedd5; color: #c2410c; }
.daymark.company-event { background: #f3e8ff; color: #7e22ce; }
.daymark.company-workday { background: #ccfbf1; color: #0f766e; }
.daymarks { display: flex; flex-direction: column; align-items: center; gap: 1px; cursor: help; }
.grid input.w-color { width: 48px; height: 32px; padding: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* 首頁 */
.home-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr); gap: 1rem; align-items: start; }
.home-grid > div > .card:first-child, .home-grid > .card { margin-top: 0; }
@media (max-width: 960px) { .home-grid { grid-template-columns: 1fr; } }
.stats.compact { margin: .5rem 0; gap: .5rem; grid-template-columns: repeat(3, 1fr); }
.stats.compact .stat { padding: .6rem .8rem; color: inherit; }
.stats.compact .stat:hover { border-color: var(--primary); }
.stats.compact .stat-value { font-size: 1.4rem; }
.announcement { border-top: 1px solid var(--line); padding: .75rem 0; }
.announcement:first-of-type { border-top: 0; padding-top: 0; }
.announcement h3 { margin: 0; font-size: 1.05rem; }
.announcement.pinned h3 { color: var(--primary-dark); }
.ann-body { margin-top: .4rem; }

/* 月曆 */
.cal-head { display: flex; align-items: center; gap: .5rem; margin-bottom: .5rem; }
.cal-head strong { font-size: 1.1rem; min-width: 7.5em; text-align: center; }
.cal-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); border-top: 1px solid var(--line); border-left: 1px solid var(--line); }
.cal-wd { text-align: center; font-size: .85rem; font-weight: 600; padding: .3rem 0; background: #f8fafc; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.cal-wd.weekend { color: var(--danger); }
.cal-day { min-height: 74px; padding: .25rem; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); display: flex; flex-direction: column; gap: 2px; overflow: hidden; }
.cal-day[data-tip] { cursor: pointer; }
.cal-day[data-tip]:hover, .cal-day.selected { outline: 2px solid var(--primary); outline-offset: -2px; }
.cal-day.other { background: #fafbfc; }
.cal-day.other > * { opacity: .45; }
.cal-day.weekend { background: var(--weekend); }
.cal-day.weekend .cal-num { color: var(--danger); }
.cal-day.off { background: #fff5f5; }
.cal-day.off .cal-num { color: var(--danger); }
.cal-num { font-size: .9rem; font-weight: 600; width: 1.7em; height: 1.7em; line-height: 1.7em; text-align: center; border-radius: 50%; }
.cal-day.today .cal-num { background: var(--primary); color: #fff !important; }
.cal-day .daymark { font-size: .7rem; }
.cal-legend { display: flex; flex-wrap: wrap; gap: .4rem .9rem; margin-top: .5rem; color: var(--muted); }
.cal-legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: .3rem; vertical-align: -1px; }
.lg.today { background: var(--primary); border-radius: 50%; }
.lg.holiday { background: #fca5a5; }
.lg.workday { background: #93c5fd; }
.lg.company-off { background: #fdba74; }
.lg.company-event { background: #d8b4fe; }
.lg.company-workday { background: #5eead4; }
.cal-detail { margin-top: .6rem; padding: .6rem .8rem; border: 1px solid var(--line); border-left: 4px solid var(--primary); border-radius: 6px; background: #f8fafc; }
.cal-list { margin-top: .6rem; font-size: .9rem; }
.cal-list ul { padding-left: 1.1rem; margin: .4rem 0 0; }
.cal-list li { margin-bottom: .35rem; }
@media (max-width: 640px) {
  .cal-day { min-height: 54px; }
  .cal-day .daymark { display: none; }
  .cal-day[data-tip]::after { content: ''; width: 6px; height: 6px; border-radius: 50%; background: var(--danger); align-self: center; }
}

/* 任務規劃 */
.grid.tasks .col-wbs { width: 3.5rem; }
.grid.tasks tr.parent td.task-name { font-weight: 600; }
.grid.tasks tr.done td.task-name { color: var(--muted); }
.grid.tasks .diamond { color: #7e22ce; }
.grid.tasks tr.milestone td { background: #fcfaff; }
.grid.tasks .caret { color: var(--muted); font-size: .8em; }
.task-actions .icon { padding: .25rem .45rem; }
.inline-check { display: inline-flex; margin: 0; }
.type-switch { border: 0; padding: 0; margin: 0 0 .5rem; display: flex; gap: 1rem; align-items: center; min-width: auto; }
.type-switch label { margin: 0; min-width: 0 !important; white-space: nowrap; }
.stat-value.small-value { font-size: 1.1rem; padding-top: .45rem; }
[hidden] { display: none !important; }

/* 甘特圖: 左側任務表 + 右側時間軸，列高固定 34px 讓兩邊對齊 */
.gantt-toolbar { display: flex; gap: .4rem; align-items: center; flex-wrap: wrap; margin-bottom: .75rem; }
.gantt { display: flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: #fff; font-size: .85rem; }
.g-left { flex: 0 0 auto; width: 430px; border-right: 2px solid var(--line); background: #fff; z-index: 2; }
.g-lhead, .g-row { display: flex; align-items: center; height: 34px; border-bottom: 1px solid #eef1f5; box-sizing: border-box; }
.g-lhead { height: 52px; background: #f8fafc; font-weight: 600; border-bottom: 1px solid var(--line); }
.g-row.parent { font-weight: 600; }
.g-row.milestone .diamond { color: #7e22ce; }
.g-name { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding-right: .3rem; }
.g-wbs { color: var(--muted); font-weight: 400; font-size: .8em; margin-right: .35rem; }
.g-date { width: 46px; text-align: center; color: var(--muted); font-variant-numeric: tabular-nums; }
.g-dur { width: 46px; text-align: right; color: var(--muted); }
.g-pct { width: 46px; text-align: right; padding-right: .5rem; font-variant-numeric: tabular-nums; }
.g-lhead .g-date, .g-lhead .g-dur, .g-lhead .g-pct { color: var(--text); }
.g-lhead .g-name { padding-left: .5rem; }
.g-right { flex: 1; overflow-x: auto; position: relative; }
.g-canvas { position: relative; }
.g-head { height: 52px; background: #f8fafc; border-bottom: 1px solid var(--line); position: sticky; top: 0; }
.g-hrow { position: relative; height: 26px; }
.g-hrow + .g-hrow { border-top: 1px solid #e5e9f0; }
.g-hcell { position: absolute; top: 0; height: 26px; line-height: 26px; text-align: center; border-left: 1px solid #e5e9f0; overflow: hidden; white-space: nowrap; font-size: .78rem; color: #374151; box-sizing: border-box; }
.g-hcell small { display: none; }
.g-hcell.today { background: var(--primary); color: #fff; font-weight: 700; }
.g-body { position: relative; background: repeating-linear-gradient(to bottom, transparent 0 33px, #eef1f5 33px 34px); }
.g-vline { position: absolute; top: 0; bottom: 0; width: 1px; background: #f1f3f6; }
.g-vline.strong { background: #e2e6ec; }
.g-off { position: absolute; top: 0; bottom: 0; background: rgba(148, 163, 184, .13); }
.g-today { position: absolute; top: 0; bottom: 0; width: 2px; margin-left: -1px; background: #ef4444; z-index: 3; }
.g-bar { position: absolute; height: 18px; border-radius: 4px; background: #bfdbfe; border: 1px solid #93c5fd; overflow: hidden; box-sizing: border-box; z-index: 2; }
.g-bar { height: 20px; }
.g-bar .g-fill { position: absolute; left: 0; top: 0; display: block; height: 100%; background: #2563eb; overflow: hidden; }
/* 條內百分比: 底層深色字，已完成區塊內疊一層白色字 (以 g-fill 的寬度裁切) */
.g-bar .g-text { position: absolute; left: 0; top: 0; width: 100%; height: 100%; line-height: 18px; text-align: center;
  font-size: .72rem; font-weight: 700; color: #1e3a8a; white-space: nowrap; pointer-events: none; }
.g-bar .g-fill .g-text { color: #fff; }
.g-bar.done { background: #bbf7d0; border-color: #86efac; }
.g-bar.done .g-fill { background: #16a34a; }
.g-bar.done > .g-text { color: #14532d; }
.g-bar.overdue { border: 2px solid #ef4444; box-shadow: 0 0 0 2px #fee2e2; }
.g-bar.overdue .g-text { line-height: 16px; }
.g-bar.overdue > .g-text { color: #b91c1c; }
.g-row.overdue .g-pct { color: var(--danger); font-weight: 700; }
.g-label.strong { font-weight: 700; color: #1f2933; }
.btn-group { display: inline-flex; }
.btn-group .btn { border-radius: 0; margin-left: -1px; }
.btn-group .btn:first-child { border-radius: 6px 0 0 6px; margin-left: 0; }
.btn-group .btn:last-child { border-radius: 0 6px 6px 0; }
.btn[data-disabled] { opacity: .4; cursor: not-allowed; }
.zoom-level { display: inline-flex; align-items: center; gap: .35rem; margin-right: .5rem; }
.zoom-dots { display: inline-flex; gap: 2px; }
.zoom-dots i { width: 4px; height: 10px; border-radius: 1px; background: #d8dee7; }
.zoom-dots i.on { background: var(--primary); }
.g-hcell small { display: inline; color: var(--muted); margin-left: 2px; font-size: .9em; }
.g-hcell.today small { color: #dbeafe; }
a.g-bar:hover, a.g-summary:hover, a.g-ms:hover { filter: brightness(.92); outline: 2px solid #1d4ed8; outline-offset: 1px; }
.g-summary { position: absolute; height: 9px; background: #475569; border-radius: 2px; z-index: 2; }
.g-summary::before, .g-summary::after { content: ''; position: absolute; top: 9px; border: 5px solid transparent; border-top-color: #475569; }
.g-summary::before { left: 0; border-left-color: #475569; }
.g-summary::after { right: 0; border-right-color: #475569; }
.g-summary .g-sfill { display: block; height: 100%; background: #111827; border-radius: 2px; }
.g-ms { position: absolute; width: 14px; height: 14px; background: #7e22ce; transform: rotate(45deg); border-radius: 2px; z-index: 3; }
.g-ms.done { background: #16a34a; }
.g-label { position: absolute; height: 34px; line-height: 34px; font-size: .75rem; color: #4b5563; white-space: nowrap; z-index: 2; pointer-events: none; }
.g-hcell small { margin-left: 1px; }
.gantt-legend .lg { width: 14px; }
.lg.g-lg-bar { background: linear-gradient(to right, #2563eb 50%, #bfdbfe 50%); }
.lg.g-lg-done { background: #16a34a; }
.lg.g-lg-overdue { background: #fff; border: 2px solid #ef4444; box-sizing: border-box; }
.lg.g-lg-summary { background: #475569; height: 6px !important; }
.lg.g-lg-today { background: #ef4444; width: 3px !important; }
.lg.g-lg-off { background: rgba(148, 163, 184, .35); }
@media (max-width: 760px) {
  .g-left { width: 180px; }
  .g-date, .g-dur { display: none; }
}
@media print {
  .gantt { overflow: visible; }
  .g-right { overflow: visible; }
  .g-left { width: 300px; }
}

/* 甘特圖編輯: 名稱可點、每列「⋯」選單、編輯視窗 */
.toolbar-sep { width: 1px; height: 22px; background: var(--line); margin: 0 .25rem; }
.g-left.editable { width: 460px; }
a.g-name.g-open { color: inherit; display: block; }
a.g-name.g-open:hover { color: var(--primary); text-decoration: underline; }
.g-menu-btn { width: 26px; flex: 0 0 26px; height: 26px; border: 0; background: none; border-radius: 4px; color: var(--muted); cursor: pointer; font-size: 1.05rem; line-height: 1; }
.g-row .g-menu-btn { opacity: .35; }
.g-row:hover .g-menu-btn, .g-menu-btn:focus { opacity: 1; background: #eef2f7; color: var(--text); }
.g-row.flash { animation: rowflash 2.2s ease-out; }
@keyframes rowflash { 0%, 40% { background: #fef9c3; } 100% { background: transparent; } }
.prio { display: inline-block; font-size: .68rem; font-weight: 700; padding: 0 .3rem; border-radius: 3px; vertical-align: 1px; }
.prio-high { background: #ffedd5; color: #c2410c; }
.prio-urgent { background: #fee2e2; color: #b91c1c; }
.g-menu { position: absolute; z-index: 50; min-width: 210px; background: #fff; border: 1px solid var(--line); border-radius: 8px;
  box-shadow: 0 10px 30px rgba(15, 23, 42, .15); padding: .3rem; }
.g-menu button { display: block; width: 100%; text-align: left; border: 0; background: none; padding: .45rem .7rem; border-radius: 5px; cursor: pointer; font: inherit; color: var(--text); }
.g-menu button:hover:not(:disabled), .g-menu button:focus { background: #eef4ff; outline: none; }
.g-menu button:disabled { color: #b8c0cc; cursor: not-allowed; }
.g-menu button.danger { color: var(--danger); }
.g-menu hr { border: 0; border-top: 1px solid var(--line); margin: .25rem 0; }

.task-dialog { width: min(860px, calc(100vw - 2rem)); max-height: calc(100vh - 2rem); padding: 0; border: 0; border-radius: 12px; box-shadow: 0 20px 60px rgba(15, 23, 42, .3); }
.task-dialog::backdrop { background: rgba(15, 23, 42, .45); }
.task-dialog form { display: flex; flex-direction: column; max-height: calc(100vh - 2rem); }
.td-head { display: flex; align-items: center; padding: 1rem 1.25rem .25rem; }
.td-head h2 { margin: 0; flex: 1; font-size: 1.15rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.td-x { border: 0; background: none; font-size: 1.6rem; line-height: 1; color: var(--muted); cursor: pointer; padding: 0 .25rem; }
.td-x:hover { color: var(--text); }
.td-tabs { margin: .25rem 1.25rem 0; }
.td-tabs .tab { border: 0; background: none; font: inherit; cursor: pointer; border-bottom: 3px solid transparent; }
.td-tabs .tab.active { border-bottom-color: var(--primary); }
.td-error { margin: .75rem 1.25rem 0; }
.td-body { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); gap: 1.25rem; padding: 1rem 1.25rem; overflow-y: auto; }
.td-body[data-panel="deps"] { display: block; min-height: 200px; }
.td-body[hidden] { display: none !important; }
.td-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 .9rem; }
.td-grid label { margin-bottom: .6rem; }
.td-done { align-self: end; padding-bottom: .6rem; }
.td-side textarea { min-height: 280px; }
.td-parent-note { margin: .25rem 0 0; }
.td-foot { display: flex; gap: .5rem; padding: .85rem 1.25rem; border-top: 1px solid var(--line); background: #f8fafc; }
@media (max-width: 720px) {
  .td-body { grid-template-columns: 1fr; }
  .td-side textarea { min-height: 120px; }
  .g-left.editable { width: 210px; }
}

/* 相依箭頭與前置任務設定 */
.g-links { position: absolute; left: 0; top: 0; z-index: 1; pointer-events: none; overflow: visible; }
.g-links path { fill: none; stroke: #64748b; stroke-width: 1.4; }
.g-links path.bad { stroke: #dc2626; stroke-width: 1.8; stroke-dasharray: 4 3; }
.dep-warn { color: #dc2626; font-weight: 700; }
.lg.g-lg-link { height: 2px !important; width: 16px !important; background: #64748b; vertical-align: 3px !important; position: relative; }
.lg.g-lg-link::after { content: ''; position: absolute; right: -2px; top: -3px; border: 4px solid transparent; border-left: 5px solid #64748b; border-right: 0; }
.lg.g-lg-link.bad { background: repeating-linear-gradient(to right, #dc2626 0 4px, transparent 4px 7px); }
.lg.g-lg-link.bad::after { border-left-color: #dc2626; }
.conflict-list { margin: .35rem 0 0; padding-left: 1.2rem; }
.dep-cols { display: grid; grid-template-columns: 1.3fr 1fr; gap: 1.5rem; }
.dep-cols h3 { margin: 0 0 .25rem; font-size: 1rem; }
.dep-list { list-style: none; padding: 0; margin: .5rem 0; border: 1px solid var(--line); border-radius: 8px; }
.dep-list li { display: flex; align-items: center; gap: .5rem; padding: .45rem .6rem; border-top: 1px solid #eef1f5; }
.dep-list li:first-child { border-top: 0; }
.dep-list li.bad { background: #fef2f2; color: #b91c1c; }
.dep-list li.empty { justify-content: center; }
.dep-list .dep-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dep-add { display: flex; gap: .5rem; }
.dep-add select { flex: 1; }
@media (max-width: 720px) { .dep-cols { grid-template-columns: 1fr; } }

/* 甘特圖左側可自訂欄位 */
.g-col { flex: 0 0 auto; box-sizing: border-box; padding: 0 5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  color: var(--muted); font-variant-numeric: tabular-nums; text-align: center; }
.g-lhead .g-col { color: var(--text); }
.g-col-duration, .g-col-progress { text-align: right; }
.g-col-progress { color: var(--text); }
.g-col-assignee, .g-col-notes { text-align: left; }
.g-col-notes { font-size: .8rem; }
.g-row.overdue .g-col-progress { color: var(--danger); font-weight: 700; }
.g-col .prio { vertical-align: 0; }
.prio-low { background: #f1f5f9; color: #64748b; }
.prio-normal { background: transparent; color: var(--muted); font-weight: 400; }
@media (max-width: 760px) {
  .g-col:not(.g-col-progress) { display: none; }
}

/* 任務表 / 時間軸分隔線 (可拖曳)、只看圖表、拖窄時任務表左右捲動 */
.g-left { overflow-x: auto; overflow-y: hidden; max-width: calc(100% - 140px); }
.g-left .g-lhead, .g-left .g-row { min-width: var(--g-min, 0); }
.g-split { flex: 0 0 6px; margin: 0 -3px; cursor: col-resize; position: relative; z-index: 4; background: transparent; touch-action: none; }
.g-split::after { content: ''; position: absolute; top: 0; bottom: 0; left: 2px; width: 2px; background: transparent; transition: background .15s; }
.g-split:hover::after, .g-split:focus::after, .gantt.resizing .g-split::after { background: var(--primary); }
.g-split:focus { outline: none; }
.gantt.resizing { cursor: col-resize; user-select: none; }
.gantt.chart-only .g-left, .gantt.chart-only .g-split { display: none; }
.btn[aria-pressed="true"] { background: #eef4ff; border-color: #bfd3fe; color: var(--primary-dark); }
@media (max-width: 760px) {
  .g-left { max-width: 55%; }
}

/* 專案總覽列 (甘特圖最上方) 與時間軸上的任務名稱 */
.g-row.g-project { background: #f0f9ff; font-weight: 700; border-bottom: 1px solid #cfe3f1; }
.g-row.g-project .g-name { padding-left: .5rem; }
.g-proj-icon { color: #0e7490; margin-right: .35rem; }
.g-pbar { position: absolute; height: 16px; border-radius: 3px; background: #a5f3fc; border: 1px solid #22d3ee; overflow: hidden; box-sizing: border-box; z-index: 2; }
.g-pbar .g-pfill { display: block; height: 100%; background: #0e7490; }
.gantt.has-project .g-body::before { content: ''; position: absolute; left: 0; right: 0; top: 0; height: 34px; background: rgba(224, 242, 254, .45); pointer-events: none; }
.g-lname { font-weight: 400; color: #374151; }
.g-label.strong .g-lname { font-weight: 600; }
.lg.g-lg-project { background: linear-gradient(to right, #0e7490 50%, #a5f3fc 50%); }

/* 欄位設定視窗 */
.col-dialog { width: min(680px, calc(100vw - 2rem)); }
.col-body { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr); gap: 1.25rem; padding: 1rem 1.25rem; overflow-y: auto; }
.col-list { border: 1px solid var(--line); border-radius: 8px; padding: .25rem; max-height: 360px; overflow-y: auto; }
.col-item { display: flex; align-items: center; gap: .5rem; padding: .4rem .5rem; border-radius: 6px; cursor: pointer; }
.col-item:hover { background: #f5f7fa; }
.col-item.selected { background: #eef4ff; }
.col-item:focus { outline: 2px solid #bfd3fe; outline-offset: -2px; }
.col-item .col-name { flex: 1; }
.col-item.fixed { cursor: default; color: var(--muted); }
.eye { width: 28px; height: 26px; border: 1px solid var(--line); border-radius: 5px; background: #fff; cursor: pointer; font-size: .9rem; line-height: 1; color: #b8c0cc; display: inline-flex; align-items: center; justify-content: center; }
.eye.on { color: var(--primary); border-color: #bfd3fe; background: #f5f9ff; }
span.eye { cursor: default; }
.col-detail h3 { margin: 0 0 .5rem; font-size: 1rem; }
.col-detail dl { display: grid; grid-template-columns: auto 1fr; gap: .4rem .9rem; margin: 0 0 .75rem; }
.col-detail dt { color: var(--muted); }
.col-detail dd { margin: 0; }
@media (max-width: 600px) { .col-body { grid-template-columns: 1fr; } }

#report svg { max-width: 100%; height: auto; }
@media (max-width: 900px) {
  #report td.pie { display: block; width: 100% !important; padding: 0 !important; }
}
@media print {
  .topbar, .no-print, .alert { display: none !important; }
  .card { border: 0; padding: 0; }
}

@media (max-width: 640px) {
  .topbar { gap: .5rem; }
  .container { padding: 1rem .75rem 2rem; }
  .card { padding: 1rem; }
}

/* 專案資料夾路徑 */
.folder-form { display: flex; gap: .5rem; align-items: flex-end; flex-wrap: wrap; margin: .25rem 0 .75rem; }
.folder-form label { flex: 1; min-width: 260px; max-width: 640px; }
.folder-cell { max-width: 240px; }
.folder-path { display: inline-block; max-width: 170px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; vertical-align: middle; font-size: .85rem; color: var(--muted); }.folder-line { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
.folder-line code { background: #f1f5f9; padding: .15rem .4rem; border-radius: 4px; word-break: break-all; }
.folder-bases { display: flex; flex-wrap: wrap; gap: .35rem; margin-bottom: .75rem; }
.folder-help { background: #f1f5f9; color: var(--text); margin: .5rem 0 0; }
kbd { border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 4px; padding: 0 .3rem; background: #fff; font-size: .85em; }
.part-no { display: inline-block; margin-left: .35rem; padding: 0 .4rem; border-radius: 4px; background: #eef2f7; color: #475569; font-size: .8rem; white-space: nowrap; }

/* 工程小工具 */
.login-tools { max-width: 380px; margin: 0 auto 2rem; }
.login-tools-link { display: flex; gap: .8rem; align-items: center; padding: .9rem 1.1rem; color: var(--text); margin: 0; }
.login-tools-link:hover { border-color: var(--primary); box-shadow: 0 4px 14px rgba(37, 99, 235, .12); }
.lt-icon { font-size: 1.8rem; }
.tools { display: grid; grid-template-columns: 250px minmax(0, 1fr); gap: 1rem; align-items: start; margin-top: 1rem; }
.tools-nav { position: sticky; top: .75rem; max-height: calc(100vh - 1.5rem); overflow-y: auto; background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: .6rem; }
.tools-search { margin-bottom: .4rem; }
.tools-select { display: none; }
.tools-group { font-size: .78rem; font-weight: 700; color: var(--muted); padding: .6rem .5rem .2rem; letter-spacing: .05em; }
.tools-item { display: flex; align-items: center; gap: .55rem; padding: .38rem .5rem; border-radius: 6px; color: var(--text); font-size: .92rem; }
.tools-item:hover { background: #f1f5f9; }
.tools-item.active { background: #eef4ff; color: var(--primary); font-weight: 600; }
.ti-icon { width: 1.6rem; text-align: center; flex: 0 0 1.6rem; font-size: .95rem; }
.tools-main { margin: 0; min-height: 300px; }
.tools-main h2 { font-size: 1.25rem; }
.tools-main h3 { font-size: 1.05rem; margin: 0 0 .5rem; }
.tl-row { display: grid; grid-template-columns: 170px minmax(0, 320px) auto; gap: .6rem; align-items: center; margin-bottom: .55rem; }
.tl-row[hidden] { display: none; }
.tl-label { color: var(--text); }
.tl-suffix { font-size: .9rem; }
.tl-out { margin-top: 1rem; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.tl-out:empty { display: none; }
.tl-out-row { display: grid; grid-template-columns: 190px minmax(0, 1fr); gap: .75rem; padding: .5rem .8rem; border-top: 1px solid #eef1f5; }
.tl-out-row:first-child { border-top: 0; }
.tl-out-row strong { font-weight: 600; font-variant-numeric: tabular-nums; word-break: break-all; font-family: Consolas, "Cascadia Mono", monospace, inherit; }
.tl-out-row.bad strong { color: var(--danger); font-family: inherit; }
.tl-out-row.muted strong { color: var(--muted); font-weight: 400; font-family: inherit; }
.tools-main textarea { width: 100%; max-width: 640px; font-family: Consolas, "Cascadia Mono", monospace; padding: .5rem .6rem; border: 1px solid var(--line); border-radius: 6px; }
.conv-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: .6rem .9rem; }
.conv-cell { display: flex; flex-direction: column; gap: .2rem; font-size: .88rem; color: var(--muted); }
.conv-cell input { font-variant-numeric: tabular-nums; }
.tl-table td, .tl-table th { white-space: nowrap; }
.tl-table .mono, .mono { font-family: Consolas, "Cascadia Mono", monospace; }
.ascii-ch { font-weight: 700; font-size: 1.05rem; }
.bit-view { margin: .25rem 0 .5rem; padding: .5rem .7rem; background: #f8fafc; border: 1px solid var(--line); border-radius: 6px; letter-spacing: .05em; overflow-x: auto; white-space: pre; }
.bit-view:empty { display: none; }
.color-sel { max-width: 200px; }
.resistor { display: flex; align-items: center; gap: 6px; height: 42px; padding: 0 22px; margin: .5rem 0; width: max-content; min-width: 200px; background: linear-gradient(#e8d3a8, #d9bc85); border-radius: 18px; position: relative; }
.resistor::before, .resistor::after { content: ''; position: absolute; top: 20px; width: 40px; height: 3px; background: #9ca3af; }
.resistor::before { left: -40px; } .resistor::after { right: -40px; }
.resistor .band { width: 10px; height: 100%; border: 1px solid rgba(0,0,0,.15); }
.resistor .band.gap { margin-left: 18px; }
.resistor { margin-left: 44px; }
.color-swatch { width: 120px; height: 60px; border-radius: 8px; border: 1px solid var(--line); margin-top: .5rem; }
.tl-note { margin: .25rem 0 .75rem; }
@media (max-width: 760px) {
  .tools { grid-template-columns: 1fr; }
  .tools-nav { position: static; max-height: none; }
  .tools-nav nav { display: none; }
  .tools-select { display: block; }
  .tl-row { grid-template-columns: 1fr; gap: .2rem; }
  .tl-out-row { grid-template-columns: 1fr; gap: 0; }
  .conv-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media print { .tools-nav { display: none; } .tools { display: block; } }