:root {
  --bg: #f6f5f2;
  --fg: #2b2926;
  --muted: #6b6658;
  --border: #e2ddd3;
  --accent: #a97142;
  --accent-dark: #7e5330;
  --pos: #2f7a4f;
  --neg: #b3432b;
  --card-bg: #ffffff;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  background: var(--bg);
  color: var(--fg);
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 24px;
  background: var(--accent-dark);
  color: #fff;
}
.topbar .brand { color: #fff; font-weight: 700; text-decoration: none; font-size: 16px; }
.topbar nav a { color: #f1e6d8; margin-left: 18px; text-decoration: none; font-size: 14px; }
.topbar nav a:hover { text-decoration: underline; }
.topbar nav .nav-sep { color: #7e5330; margin-left: 18px; }
.topbar .nav-user { color: #cbb896; margin-left: 18px; font-size: 13px; }
.topbar .link-logout, .topbar .link-logout:hover { background: none; border: none; color: #f1e6d8; margin-left: 8px; font-size: 14px; text-decoration: underline; cursor: pointer; padding: 0; }
.nav-toggle { display: none; background: none; border: 1px solid #f1e6d8; color: #fff; font-size: 18px; padding: 2px 10px; border-radius: 4px; cursor: pointer; }

.container { padding: 24px; max-width: 1500px; margin: 0 auto; }

h1 { font-size: 22px; margin-bottom: 4px; }
h2 { font-size: 17px; margin-top: 28px; border-left: 4px solid var(--accent); padding-left: 8px; }

.meta, .hint { color: var(--muted); font-size: 13px; }
.case-number { font-size: 12px; font-weight: 700; color: var(--fg); }
.attachment-cell { min-width: 110px; }
.attachment-item { display: flex; align-items: center; gap: 4px; font-size: 12px; white-space: nowrap; }
.attachment-item a { max-width: 90px; overflow: hidden; text-overflow: ellipsis; }
.attachment-upload-form input[type="file"] { font-size: 11px; width: 110px; }
.editlink { font-size: 13px; margin-left: 10px; }
input.row-editable:read-only, select.row-editable:disabled { background: var(--bg); color: var(--muted); cursor: default; }
.row-edit-btn { font-size: 12px; }

.flash { background: #fff2e0; border: 1px solid var(--accent); padding: 8px 12px; border-radius: 6px; margin-bottom: 16px; font-size: 13px; }

table.grid { width: 100%; border-collapse: collapse; background: var(--card-bg); font-size: 14px; }
table.grid.small { font-size: 13px; }
table.grid th, table.grid td { padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: left; }
table.grid th { color: var(--muted); font-weight: 600; white-space: nowrap; }
.table-scroll { overflow-x: auto; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.pos { color: var(--pos); }
.neg { color: var(--neg); }
.health-icon-link { display: inline-block; padding: 6px; margin: -6px; text-decoration: none; font-size: 15px; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 12px; background: #e9e4d8; color: var(--accent-dark); }
.badge.status-已收, .badge.status-已付, .badge.status-已完工, .badge.status-已結案, .badge.status-已開, .badge.status-已拍攝 { background: #dff0e2; color: var(--pos); }
.badge.status-未收, .badge.status-未付, .badge.status-未開, .badge.status-未拍攝 { background: #f5e3df; color: var(--neg); }
.badge.status-無需拍攝, .badge.status-不適用 { background: #e8e6e2; color: var(--muted); }
.badge.badge-bianyeng { background: #dbe7f5; color: #1d5a99; font-weight: bold; }

.invoice-photo-widget { display: flex; align-items: center; gap: 3px; margin-top: 4px; flex-wrap: wrap; }
.invoice-photo-thumb { display: inline-flex; align-items: center; gap: 1px; font-size: 13px; }
.invoice-photo-thumb a { text-decoration: none; }
.invoice-photo-delete { background: none; border: none; color: var(--muted); font-size: 12px; padding: 0 2px; cursor: pointer; }
.invoice-photo-delete:hover { color: var(--neg); background: none; }
.invoice-photo-add { cursor: pointer; font-size: 13px; color: var(--muted); opacity: 0.7; }
.invoice-photo-add:hover { opacity: 1; }
.invoice-photo-add input[type="file"] { display: none; }

.badge-btn, .badge-btn:hover { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 12px; background: #e9e4d8; color: var(--accent-dark); border: none; cursor: pointer; white-space: nowrap; }
.badge-btn.status-已收, .badge-btn.status-已付, .badge-btn.status-已完工, .badge-btn.status-已結案, .badge-btn.status-已開, .badge-btn.status-已拍攝,
.badge-btn.status-已收:hover, .badge-btn.status-已付:hover, .badge-btn.status-已完工:hover, .badge-btn.status-已結案:hover, .badge-btn.status-已開:hover, .badge-btn.status-已拍攝:hover { background: #dff0e2; color: var(--pos); }
.badge-btn.status-未收, .badge-btn.status-未付, .badge-btn.status-未開, .badge-btn.status-未拍攝,
.badge-btn.status-未收:hover, .badge-btn.status-未付:hover, .badge-btn.status-未開:hover, .badge-btn.status-未拍攝:hover { background: #f5e3df; color: var(--neg); }
.badge-btn.status-無需拍攝, .badge-btn.status-無需拍攝:hover,
.badge-btn.status-不適用, .badge-btn.status-不適用:hover { background: #e8e6e2; color: var(--muted); }
.badge-btn.status-暫緩, .badge-btn.status-暫緩:hover { background: #f5e6c8; color: #8a5a1f; }
.badge-btn:hover { opacity: 0.75; }

.status-tabs { display: flex; gap: 6px; flex-wrap: wrap; margin: 12px 0 16px; }
.status-tab { border: 1px solid var(--border); background: var(--card-bg); color: var(--muted); border-radius: 20px; padding: 6px 14px; font-size: 13px; cursor: pointer; }
.status-tab:hover { border-color: var(--accent); color: var(--accent-dark); }
.status-tab.active { background: var(--accent-dark); border-color: var(--accent-dark); color: #fff; }
.status-tab .status-tab-count { font-size: 11px; opacity: 0.8; }

.sort-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 0 0 14px; font-size: 13px; color: var(--muted); }
.sort-bar select { border: 1px solid var(--border); border-radius: 6px; padding: 4px 8px; font-size: 13px; background: var(--card-bg); color: var(--fg); cursor: pointer; }
.case-search-input { flex: 1; max-width: 280px; border: 1px solid var(--border); border-radius: 6px; padding: 5px 10px; font-size: 13px; }

/* 案件列表14欄在一般筆電寬度(1366~1440px)常常會逼出橫向捲軸，操作欄(編輯/刪除)被切到看不全；
   用較窄的padding+把客戶欄截斷加title顯示完整名稱，讓整張表在筆電寬度也能完整顯示不用捲動。 */
table.cases-table th, table.cases-table td { padding: 6px 7px; }
.cases-table .client-cell { max-width: 130px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; cursor: default; }

.progress-cell { min-width: 130px; }
.mini-progress-row { display: flex; align-items: center; gap: 6px; font-size: 11px; color: var(--muted); }
.mini-progress-row + .mini-progress-row { margin-top: 3px; }
.mini-progress-label { width: 24px; flex-shrink: 0; }
.list-mini-bar-outer { flex: 1; height: 6px; background: #eee7db; border-radius: 3px; overflow: hidden; }
.list-mini-bar-inner { height: 100%; background: var(--accent); border-radius: 3px; }
.list-mini-bar-inner.design { background: #6b8c9e; }
.mini-progress-pct { width: 30px; text-align: right; flex-shrink: 0; }

.status-select { border: none; border-radius: 10px; padding: 2px 6px; font-size: 12px; background: #e9e4d8; color: var(--accent-dark); cursor: pointer; }
.status-select.status-已完工, .status-select.status-已結案 { background: #dff0e2; color: var(--pos); }
.status-select.status-討論中 { background: #dde6ee; color: #3d5a73; }
.status-select.status-未成交 { background: #e8e6e2; color: var(--muted); }
.status-select.status-暫緩, .badge.status-暫緩 { background: #f5e6c8; color: #8a5a1f; }
.status-select.status-客變中, .badge.status-客變中 { background: #dbe7f5; color: #1d5a99; }
.status-select.status-施工中, .badge.status-施工中 { background: #fbe8a6; color: #7a5c00; }

/* 應收帳款狀態機（ERP第一階段） */
.badge.status-NOT_DUE { background: #e8e6e2; color: var(--muted); }
.badge.status-DUE { background: #f5e6c8; color: #8a5a1f; }
.badge.status-OVERDUE { background: #f5e3df; color: var(--neg); font-weight: bold; }
.badge.status-PARTIALLY_PAID { background: #dbe7f5; color: #1d5a99; }
.badge.status-PAID { background: #dff0e2; color: var(--pos); }

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin: 16px 0; }

.cards-tier1 { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; margin: 16px 0 10px; }
.card-tier1 { background: var(--card-bg); border: 1px solid var(--border); border-left: 5px solid var(--accent); border-radius: 8px; padding: 16px 18px; display: flex; flex-direction: column; }
.card-tier1 .card-label { font-size: 13px; color: var(--muted); min-height: 2.4em; }
.card-tier1 .card-value { font-size: 30px; font-weight: 700; margin-top: 6px; color: var(--accent-dark); }
.card-tier1 .card-mini-bar-outer { margin-top: auto; }
.card-tier1 .card-value { margin-bottom: 8px; }
.cards-tier2 { margin-top: 0; }
.cards-tier2 .card-label { color: var(--muted); }

.project-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; margin: 14px 0; }
.project-card { display: block; background: var(--card-bg); border: 1px solid var(--border); border-radius: 8px; padding: 14px 16px; text-decoration: none; color: var(--fg); transition: box-shadow 0.2s; }
.project-card:hover { box-shadow: 0 2px 8px rgba(0,0,0,0.08); }
.project-card.health-green { border-left: 5px solid var(--pos); }
.project-card.health-yellow { border-left: 5px solid var(--accent-dark); }
.project-card.health-red { border-left: 5px solid var(--neg); }
.project-card.health-gray { border-left: 5px solid var(--muted); }
.project-card-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.project-card-name { font-weight: 700; font-size: 15px; color: var(--fg); }
.project-card-health { font-size: 18px; }
.project-card-row { display: flex; justify-content: space-between; font-size: 13px; padding: 3px 0; }
.mini-bar-outer { background: #f1efe9; border-radius: 4px; height: 4px; overflow: hidden; margin: -1px 0 4px; }
.mini-bar-inner { background: var(--pos); height: 100%; border-radius: 4px; }

.stat-bar-row { display: flex; align-items: center; gap: 10px; padding: 5px 0; }
.stat-bar-label { width: 110px; flex-shrink: 0; font-size: 13px; color: var(--fg); }
.stat-bar-outer { flex: 1; background: #f1efe9; border-radius: 5px; height: 10px; overflow: hidden; }
.stat-bar-inner { background: var(--accent); height: 100%; border-radius: 5px; }
.stat-bar-count { width: 70px; flex-shrink: 0; text-align: right; font-size: 13px; color: var(--muted); }

.month-chart { display: flex; align-items: flex-end; gap: 6px; height: 200px; padding: 10px 8px 4px; overflow-x: auto; border-bottom: 1px solid var(--border); }
.month-bar-col { display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; min-width: 40px; flex-shrink: 0; }
.month-bar-value { font-size: 10px; color: var(--muted); margin-bottom: 3px; white-space: nowrap; }
.month-bar-outer { width: 16px; flex: 1; display: flex; flex-direction: column-reverse; }
.month-bar-inner { width: 100%; }
.month-bar-inner.stage-contacted { background: var(--muted); }
.month-bar-inner.stage-consulted { background: var(--pos); border-radius: 2px 2px 0 0; }
.month-bar-label { font-size: 10px; color: var(--muted); margin-top: 6px; white-space: nowrap; }
.month-chart-legend { display: flex; gap: 16px; margin-top: 8px; font-size: 12px; color: var(--muted); }
.legend-item { display: flex; align-items: center; gap: 5px; }
.legend-swatch { display: inline-block; width: 10px; height: 10px; border-radius: 2px; }
.legend-swatch.stage-contacted { background: var(--muted); }
.legend-swatch.stage-consulted { background: var(--pos); }
.project-card-row span:first-child { color: var(--muted); }
.project-card-warnings { margin: 8px 0 0; padding-left: 18px; font-size: 12px; }
.project-card-warnings li { margin-bottom: 2px; }

.health-card { border-radius: 8px; padding: 14px 16px; margin: 16px 0; border: 1px solid var(--border); }
.health-card.health-green { background: #dff0e2; border-color: #b9dcc0; }
.health-card.health-yellow { background: #f3e6d3; border-color: #e0c69a; }
.health-card.health-red { background: #f5e3df; border-color: #e0b3a5; }
.health-card.health-gray { background: #f1efe9; border-color: var(--border); }
.health-badge { font-size: 17px; font-weight: 700; }
.dimension-badges { display: flex; flex-wrap: wrap; gap: 18px; font-size: 15px; }
.health-reasons { margin: 8px 0 0; padding-left: 20px; font-size: 13px; }
.health-reasons li { margin-bottom: 2px; }
.health-reason-red { color: var(--neg); }
.health-reason-yellow { color: var(--accent-dark); }
.health-reason-green { color: var(--pos); }
.confidence-red { color: #dc2626; font-weight: 700; }
.confidence-yellow { color: #d97706; font-weight: 700; }
.confidence-green { color: #16a34a; font-weight: 700; }
.health-ok-note { margin: 6px 0 0; font-size: 13px; color: var(--muted); }
.card { background: var(--card-bg); border: 1px solid var(--border); border-radius: 8px; padding: 12px 14px; }
.form-section { margin-bottom: 16px; }
.detail-card { background: var(--card-bg); border: 1px solid var(--border); border-radius: 8px; padding: 14px 16px; margin-bottom: 16px; }
.form-section > h3:first-child { margin-top: 0; }
.card-label { font-size: 12px; color: var(--muted); }
.info-icon { display: inline-block; margin-left: 4px; color: var(--muted); border: 1px solid var(--muted); border-radius: 50%; width: 13px; height: 13px; line-height: 12px; text-align: center; font-size: 10px; font-style: normal; cursor: help; user-select: none; }
.invoice-status-row { display: flex; flex-wrap: wrap; gap: 6px 20px; margin: 4px 0; }
.invoice-status-item { display: flex; align-items: center; gap: 6px; white-space: nowrap; }
.invoice-status-item .meta { margin: 0; }
.card-value { font-size: 20px; font-weight: 700; margin-top: 4px; }
.card-mini-bar-outer { background: #f1efe9; border-radius: 6px; height: 6px; overflow: hidden; margin-top: 8px; }
.card-mini-bar-inner { background: var(--pos); height: 100%; border-radius: 6px; transition: width 0.3s; }
.card-mini-bar-label { font-size: 11px; color: var(--muted); margin-top: 3px; text-align: right; }

.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
@media (max-width: 800px) { .two-col { grid-template-columns: 1fr; } }

.form label { display: block; margin-bottom: 12px; font-size: 14px; }
.form input[type=text], .form input[type=number], .form select, .form textarea {
  display: block; width: 100%; margin-top: 4px; padding: 6px 8px; border: 1px solid var(--border); border-radius: 4px; font-size: 14px;
}
.actions { margin-top: 16px; display: flex; gap: 12px; align-items: center; }

button { background: var(--accent); color: #fff; border: none; padding: 7px 14px; border-radius: 5px; cursor: pointer; font-size: 13px; white-space: nowrap; }
button:hover { background: var(--accent-dark); }
button.danger { background: var(--neg); }
button.positive { background: var(--pos); }
button.positive:hover { background: #245f3f; }
button.muted { background: var(--muted); }
button.muted:hover { background: #6f6a5e; }
button.link-danger, button.link-danger:hover { background: none; border: none; color: var(--neg); padding: 0; font-size: 13px; text-decoration: underline; cursor: pointer; }

.inline-form { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 10px 0; }
.inline-form input, .inline-form select { padding: 6px 8px; border: 1px solid var(--border); border-radius: 4px; font-size: 13px; }
.inline-form.tight { margin: 0; }

.gantt { background: var(--card-bg); border: 1px solid var(--border); border-radius: 8px; padding: 14px; margin-bottom: 12px; }
.gantt-range { font-size: 12px; color: var(--muted); margin-bottom: 10px; }
.gantt-body { display: flex; }
.gantt-names { width: 140px; flex-shrink: 0; }
.gantt-name { font-size: 13px; height: 20px; line-height: 20px; margin-bottom: 8px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gantt-name-spacer { height: 16px; margin-bottom: 4px; }
.gantt-scroll { flex: 1; overflow-x: auto; min-width: 0; }
.gantt-tracks { position: relative; min-width: 100%; }
.gantt-track { position: relative; height: 20px; margin-bottom: 8px; background: #f1efe9; border-radius: 4px; }
.gantt-bar { position: absolute; height: 8px; border-radius: 4px; }
.gantt-bar.planned { top: 2px; background: #cbb896; }
.gantt-bar.actual { bottom: 2px; background: var(--accent); }
.gantt-legend { font-size: 12px; color: var(--muted); margin-top: 6px; }
.gantt-ticks-track { height: 16px; margin-bottom: 4px; background: none; }
.gantt-tick-label { position: absolute; top: 0; font-size: 11px; color: var(--muted); white-space: nowrap; }
.gantt-gridline { position: absolute; top: 0; bottom: 0; width: 1px; background: var(--border); }
.gantt-today-line { position: absolute; top: 0; bottom: 0; width: 0; border-left: 2px dashed var(--neg); }
.gantt-today-label { position: absolute; top: 0; font-size: 11px; color: var(--neg); font-weight: 700; white-space: nowrap; transform: translateX(-50%); }
.gantt-case-group { margin: 14px 0 4px; }
.gantt-case-name { font-weight: 700; color: var(--accent-dark); text-decoration: none; }
.gantt-case-name:hover { text-decoration: underline; }
.gantt-mark-bar { position: absolute; top: 6px; height: 8px; border-radius: 4px; background: var(--accent); cursor: default; }
.legend { display: inline-block; width: 12px; height: 8px; border-radius: 3px; margin-right: 4px; }
.legend.planned { background: #cbb896; }
.legend.actual { background: var(--accent); margin-left: 12px; }

.login-wrap { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.login-box { background: var(--card-bg); border: 1px solid var(--border); border-radius: 10px; padding: 32px; width: 300px; }
.login-box h1 { font-size: 17px; margin: 0 0 20px; text-align: center; }
.login-box label { display: block; margin-bottom: 14px; font-size: 14px; }
.login-box input { display: block; width: 100%; margin-top: 4px; padding: 8px; border: 1px solid var(--border); border-radius: 4px; font-size: 14px; box-sizing: border-box; }
.login-box button { width: 100%; padding: 10px; margin-top: 6px; }

.notes { white-space: pre-wrap; background: var(--card-bg); border: 1px solid var(--border); border-radius: 8px; padding: 12px; font-size: 14px; }

.item-group { background: var(--card-bg); border: 1px solid var(--border); border-radius: 8px; margin-bottom: 10px; overflow: hidden; }
.item-group summary { cursor: pointer; padding: 10px 14px; display: flex; justify-content: space-between; align-items: center; font-weight: 600; background: #f6f2ea; list-style: none; transition: background 0.3s; }
.item-group summary::-webkit-details-marker { display: none; }
.item-group-name::before { content: "▸"; display: inline-block; width: 1em; margin-right: 8px; color: var(--accent); }
.item-group[open] .item-group-name::before { content: "▾"; }
.item-group-stat { font-weight: 400; font-size: 13px; color: var(--muted); }
.item-group-right { display: flex; align-items: center; gap: 12px; }
.mini-btn { background: none; border: 1px solid var(--accent); color: var(--accent-dark); border-radius: 5px; padding: 3px 8px; font-size: 12px; font-weight: 400; cursor: pointer; white-space: nowrap; }
.mini-btn:hover { background: var(--accent); color: #fff; }
.item-group table { border-top: 1px solid var(--border); }
h3 { font-size: 14px; margin: 10px 0 4px; color: var(--accent-dark); }

.pie-block { display: flex; align-items: center; gap: 28px; background: var(--card-bg); border: 1px solid var(--border); border-radius: 8px; padding: 18px; margin-bottom: 14px; flex-wrap: wrap; }
.pie-chart { width: 140px; height: 140px; border-radius: 50%; flex-shrink: 0; }
.pie-legend { list-style: none; margin: 0; padding: 0; font-size: 13px; display: flex; flex-direction: column; min-width: 420px; }
.pie-legend li { display: flex; align-items: center; padding: 6px 0; border-bottom: 1px solid var(--border); color: var(--fg); }
.pie-legend li:last-child { border-bottom: none; }
.pie-cat { width: 90px; flex-shrink: 0; }
.pie-amount { width: 100px; text-align: right; flex-shrink: 0; font-variant-numeric: tabular-nums; }
.pie-pct { width: 60px; text-align: right; flex-shrink: 0; color: var(--muted); }
.ppp { width: 110px; text-align: right; flex-shrink: 0; color: var(--accent-dark); font-weight: 600; }
.pie-swatch { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 6px; }

.progress-bar-outer { background: #f1efe9; border-radius: 8px; height: 16px; overflow: hidden; margin: 10px 0 4px; }
.progress-bar-inner { background: var(--pos); height: 100%; border-radius: 8px; transition: width 0.3s; }
.checkbtn, .checkbtn:hover { background: none; border: none; font-size: 20px; line-height: 1; cursor: pointer; padding: 10px 16px; color: var(--accent-dark); display: block; width: 100%; text-align: left; }
td.check-cell { padding: 0 !important; }
td.check-cell form { display: block; }
tr.item-done td { color: var(--muted); text-decoration: line-through; }
table.grid tr[id] { scroll-margin-top: 16px; }
table.grid input[type=text], table.grid input[type=date], table.grid input[type=number] {
  border: 1px solid var(--border); border-radius: 4px; padding: 4px 6px; font-size: 13px; font-family: inherit;
}
table.grid input[type=date] { width: 118px; }
.site-log-list { display: flex; flex-direction: column; gap: 10px; margin-top: 14px; }
.site-log-entry { background: var(--card-bg); border: 1px solid var(--border); border-radius: 8px; padding: 12px 14px; }
.site-log-header { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.site-log-date { font-weight: 600; }
.site-log-content { margin: 8px 0 0; font-size: 14px; white-space: pre-wrap; }
.site-log-photos { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.site-log-photos img { width: 100px; height: 100px; object-fit: cover; border-radius: 6px; border: 1px solid var(--border); }

.timeline-strip { display: flex; overflow-x: auto; padding: 22px 12px 14px; margin-top: 10px; }
.timeline-strip-item { position: relative; flex: 0 0 140px; width: 140px; text-align: center; padding-top: 16px; }
.timeline-strip-item::before { content: ''; position: absolute; top: 5px; left: 0; right: 0; height: 2px; background: var(--border); }
.timeline-strip-item:first-child::before { left: 50%; }
.timeline-strip-item:last-child::before { right: 50%; }
.timeline-strip-dot { position: absolute; top: 0; left: 50%; transform: translateX(-50%); width: 11px; height: 11px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 3px var(--bg); z-index: 1; }
.timeline-strip-dot.timeline-dot-today { background: var(--pos); }
.timeline-strip-date { font-size: 11px; color: var(--muted); white-space: nowrap; }
.timeline-strip-event { font-size: 13px; font-weight: 600; margin-top: 2px; word-break: break-word; }

.timeline-list-wrapper { margin-top: 10px; }
.timeline-list-wrapper > summary { cursor: pointer; list-style: none; font-weight: 600; }
.timeline-list-wrapper > summary::-webkit-details-marker { display: none; }
.timeline-list-wrapper > summary::before { content: "▸"; display: inline-block; width: 14px; color: var(--muted); transition: transform 0.15s; }
.timeline-list-wrapper[open] > summary::before { transform: rotate(90deg); }

.phase-list-wrapper, .site-log-list-wrapper { margin-top: 10px; }
.phase-list-wrapper > summary, .site-log-list-wrapper > summary { cursor: pointer; list-style: none; font-weight: 600; }
.phase-list-wrapper > summary::-webkit-details-marker, .site-log-list-wrapper > summary::-webkit-details-marker { display: none; }
.phase-list-wrapper > summary::before, .site-log-list-wrapper > summary::before { content: "▸"; display: inline-block; width: 14px; color: var(--muted); transition: transform 0.15s; }
.phase-list-wrapper[open] > summary::before, .site-log-list-wrapper[open] > summary::before { transform: rotate(90deg); }
.timeline-list { display: flex; flex-direction: column; gap: 6px; margin-top: 6px; }
.timeline-entry { background: var(--card-bg); border: 1px solid var(--border); border-radius: 8px; }
.timeline-entry-body { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; padding: 10px 12px; }
.timeline-event-input { flex: 1; min-width: 160px; font-weight: 600; }
.timeline-note-input { flex: 1; min-width: 160px; }
.site-log-photo-wrap { position: relative; }
.site-log-photo-delete { position: absolute; top: -6px; right: -6px; margin: 0; }
.site-log-photo-delete button { background: var(--neg); color: #fff; border-radius: 50%; width: 20px; height: 20px; padding: 0; line-height: 20px; font-size: 13px; text-decoration: none; }
.phase-name-input { cursor: text; }
.phase-name-input:hover { border-color: var(--border) !important; background: var(--card-bg) !important; }
.phase-name-input:focus { border-color: var(--accent) !important; background: var(--card-bg) !important; outline: none; }
table.grid input[type=number] { width: 70px; }
tr.item-done .checkbtn { text-decoration: none; }

.today-section, .today-subsection { margin-top: 28px; }
.today-section summary, .today-subsection summary { cursor: pointer; list-style: none; }
.today-section summary::-webkit-details-marker, .today-subsection summary::-webkit-details-marker { display: none; }
.today-section > summary h2, .today-subsection > summary h3 { display: inline-block; margin: 0; }
.today-section summary::before, .today-subsection summary::before { content: "▸"; display: inline-block; width: 14px; color: var(--muted); transition: transform 0.15s; }
.today-section[open] > summary::before, .today-subsection[open] > summary::before { transform: rotate(90deg); }
.today-subsection { margin-top: 14px; }
.today-subsection summary h3 { border-left: none; padding-left: 0; }
.section-count { margin-left: 6px; font-size: 12px; font-weight: 400; color: var(--muted); }
.risk-badge { display: inline-block; margin-left: 8px; padding: 1px 9px; border-radius: 10px; font-size: 12px; font-weight: 700; background: var(--neg); color: #fff; vertical-align: 2px; }

.toast-stack { position: fixed; right: 20px; bottom: 20px; display: flex; flex-direction: column-reverse; gap: 8px; z-index: 1000; max-width: 320px; }
.toast { background: var(--fg); color: #fff; padding: 10px 14px; border-radius: 8px; font-size: 13px; display: flex; align-items: center; justify-content: space-between; gap: 14px; box-shadow: 0 4px 16px rgba(0,0,0,0.18); animation: toast-in 0.15s ease-out; }
.toast-msg { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.toast .toast-undo, .toast .toast-undo:hover { background: none; border: none; color: #f1e6d8; text-decoration: underline; padding: 0; font-size: 13px; cursor: pointer; flex-shrink: 0; }
.toast .toast-undo:hover { color: #fff; }
@keyframes toast-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }

/* ==================== 響應式調整（放在檔案最後，才能真的覆蓋掉上面的預設樣式；
   CSS同樣specificity的情況下後面的規則會贏，media query擋不住這件事）==================== */

/* 平板（iPad系列，直向約768~834px、橫向約1024~1194px）：畫面比手機寬很多，
   導覽列不用整個收起來，用wrap讓它自己換行就好；容器不用桌機那種1500px寬版，
   但也不用手機那種12px小邊距；卡片區塊維持auto-fit自動排版，不用強制單欄。 */
@media (min-width: 781px) and (max-width: 1024px) {
  .container { padding: 18px; max-width: 100%; }
  .topbar nav { flex-wrap: wrap; row-gap: 8px; }
  .topbar nav a, .topbar nav .nav-user, .topbar nav form { margin-bottom: 2px; }
  .nav-toggle { display: none; }

  table.grid { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .inline-form input, .inline-form select { min-width: 90px; }
}

/* 手機版（含iPhone，780px以下）響應式調整 */
@media (max-width: 780px) {
  .topbar { flex-wrap: wrap; padding: 10px 14px; }
  .nav-toggle { display: block; }
  .topbar nav#main-nav {
    display: none;
    width: 100%;
    flex-direction: column;
    align-items: flex-start;
    margin-top: 10px;
  }
  .topbar nav#main-nav.open { display: flex; }
  .topbar nav#main-nav a, .topbar nav#main-nav .nav-user, .topbar nav#main-nav form {
    margin-left: 0;
    padding: 8px 0;
    width: 100%;
    border-bottom: 1px solid rgba(255,255,255,0.15);
  }
  .topbar nav#main-nav .nav-sep { display: none; }

  .container { padding: 12px; max-width: 100%; }
  h1 { font-size: 19px; }
  h2 { font-size: 16px; }

  /* 寬表格在窄螢幕直接讓表格本身橫向捲動，不用逐一修改每個頁面。
     只把最外層table改成block+scroll，thead/tbody/tr/td保持原本的table顯示值，
     瀏覽器會用CSS2.1的匿名表格補完規則自動包成一個完整表格再讓外層捲動，欄寬才不會跑掉。 */
  table.grid { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; }

  .inline-form { flex-direction: column; align-items: stretch; }
  .inline-form input, .inline-form select, .inline-form button { width: 100%; box-sizing: border-box; }

  .cards, .cards-tier1, .cards-tier2, .project-cards { grid-template-columns: 1fr; }

  /* 搜尋/篩選/排序列擠了搜尋框+2個下拉+checkbox，780px以下沒有flex-wrap會直接被裁掉、
     使用者(iPhone)完全點不到排序或篩選，所以搜尋框強制佔滿一行，其餘控制項自然換行。 */
  .case-search-input { flex-basis: 100%; max-width: none; }

  /* 案件列表在手機上橫向捲動看14欄時，把「案件名稱」欄位固定在左邊，
     滑到報價/毛利那些欄位時還看得到是哪個案件，不用一直往回捲確認。 */
  .cases-table th:nth-child(2), .cases-table td:nth-child(2) {
    position: sticky;
    left: 0;
    background: var(--card-bg);
    z-index: 1;
    box-shadow: 2px 0 4px rgba(0, 0, 0, 0.08);
  }
  .cases-table thead th:nth-child(2) { z-index: 2; }

  /* 工期總覽的甘特圖沒有捲動容器，手機寬度下天數刻度跟色塊會硬擠到看不清楚；
     改成整個甘特圖橫向捲動、每列維持最小寬度，色塊才有足夠的每日像素可以看。 */
  .gantt { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .gantt-row { min-width: 600px; }

  .toast-stack { left: 12px; right: 12px; bottom: 12px; max-width: none; }
}
