/* ============ 基礎 ============ */
:root {
  --bg: #f5f3ee;
  --surface: #ffffff;
  --surface-2: #faf8f4;
  --ink: #23262b;
  --ink-soft: #4a4e55;
  --muted: #8a8d93;
  --line: #e6e2d8;
  --accent: #8a6d4f;
  --accent-deep: #6f563d;
  --accent-soft: #f1e9df;
  --sidebar-bg: #23262b;
  --sidebar-ink: #c9cbd1;
  --ok: #4e7a5a;
  --ok-soft: #e7f0e9;
  --warn: #a8762a;
  --warn-soft: #f7eedd;
  --danger: #a0524d;
  --danger-soft: #f5e6e5;
  --info-soft: #e8ecf2;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(35, 38, 43, .06), 0 4px 16px rgba(35, 38, 43, .05);
  --font-serif: "Noto Serif TC", "Songti TC", "PMingLiU", serif;
  --font-sans: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", system-ui, sans-serif;
}
* { margin: 0; padding: 0; box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.6;
}
button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; font-size: 15px; }
a { color: var(--accent-deep); }

/* ============ 版面 ============ */
.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: 232px; flex-shrink: 0;
  background: var(--sidebar-bg); color: var(--sidebar-ink);
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
}
.brand {
  padding: 26px 24px 22px;
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.brand h1 {
  font-family: var(--font-serif);
  font-size: 21px; font-weight: 600; color: #fff; letter-spacing: 2px;
}
.brand p { font-size: 12px; color: var(--muted); letter-spacing: 1px; margin-top: 2px; }
.nav { padding: 14px 12px; flex: 1; }
.nav a {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 14px; margin-bottom: 2px;
  color: var(--sidebar-ink); text-decoration: none;
  border-radius: 8px; font-size: 14.5px;
  transition: background .15s, color .15s;
}
.nav a svg { width: 18px; height: 18px; flex-shrink: 0; opacity: .75; }
.nav a:hover { background: rgba(255,255,255,.07); color: #fff; }
.nav a.active { background: var(--accent); color: #fff; }
.nav a.active svg { opacity: 1; }
.sidebar-foot { padding: 16px 24px; font-size: 12px; color: #6b6f76; border-top: 1px solid rgba(255,255,255,.08); }

.main { flex: 1; min-width: 0; }
.topbar {
  display: none;
  position: sticky; top: 0; z-index: 50;
  background: var(--sidebar-bg); color: #fff;
  padding: 0 16px; height: 56px;
  align-items: center; gap: 14px;
}
.topbar .menu-btn {
  background: none; border: none; color: #fff;
  width: 40px; height: 40px; margin-left: -8px;
  display: flex; align-items: center; justify-content: center;
}
.topbar .menu-btn svg { width: 22px; height: 22px; }
.topbar h1 { font-family: var(--font-serif); font-size: 17px; font-weight: 600; letter-spacing: 2px; }

.content { padding: 32px 36px 64px; max-width: 1180px; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 24px; flex-wrap: wrap; }
.page-head h2 { font-family: var(--font-serif); font-size: 26px; font-weight: 600; letter-spacing: 1px; }
.page-head .sub { color: var(--muted); font-size: 13.5px; margin-top: 2px; }

/* ============ 元件 ============ */
.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.card-pad { padding: 20px 22px; }
.card h3 {
  font-family: var(--font-serif); font-size: 16.5px; font-weight: 600;
  letter-spacing: 1px; margin-bottom: 14px;
  display: flex; align-items: center; justify-content: space-between;
}
.grid { display: grid; gap: 18px; }
.grid-2 { grid-template-columns: 1fr 1fr; }
.grid-4 { grid-template-columns: repeat(4, 1fr); }

.stat { padding: 18px 20px; }
.stat .label { font-size: 13px; color: var(--muted); letter-spacing: 1px; }
.stat .value { font-family: var(--font-serif); font-size: 30px; font-weight: 600; margin-top: 4px; }
.stat .value small { font-size: 14px; color: var(--muted); font-family: var(--font-sans); font-weight: 400; margin-left: 2px; }

.btn {
  display: inline-flex; align-items: center; gap: 7px;
  border: 1px solid var(--line); background: var(--surface);
  color: var(--ink-soft); padding: 9px 16px; border-radius: 9px;
  font-size: 14px; transition: all .15s; text-decoration: none;
}
.btn:hover { border-color: var(--accent); color: var(--accent-deep); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-deep); border-color: var(--accent-deep); color: #fff; }
.btn-sm { padding: 5px 11px; font-size: 13px; border-radius: 7px; }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-ghost:hover { background: var(--accent-soft); }
.btn-danger:hover { border-color: var(--danger); color: var(--danger); }

.badge {
  display: inline-block; padding: 3px 10px; border-radius: 99px;
  font-size: 12.5px; line-height: 1.5; white-space: nowrap;
}
.badge-ok { background: var(--ok-soft); color: var(--ok); }
.badge-warn { background: var(--warn-soft); color: var(--warn); }
.badge-muted { background: #eeece6; color: var(--ink-soft); }
.badge-accent { background: var(--accent-soft); color: var(--accent-deep); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th {
  text-align: left; font-weight: 500; color: var(--muted);
  font-size: 12.5px; letter-spacing: 1px;
  padding: 10px 14px; border-bottom: 1px solid var(--line); white-space: nowrap;
}
td { padding: 12px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tbody tr { transition: background .12s; }
tbody tr:hover { background: var(--surface-2); }
.num { font-variant-numeric: tabular-nums; }

.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; color: var(--ink-soft); margin-bottom: 5px; letter-spacing: .5px; }
.field input, .field select, .field textarea {
  width: 100%; padding: 9px 12px;
  border: 1px solid var(--line); border-radius: 8px;
  background: var(--surface); color: var(--ink);
  outline: none; transition: border-color .15s;
}
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--accent); }
.field textarea { resize: vertical; min-height: 70px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.check-row { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--ink-soft); }
.check-row input { width: auto; }

.toolbar { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 18px; }
.toolbar input[type="search"] {
  flex: 1; min-width: 180px; max-width: 320px;
  padding: 9px 14px; border: 1px solid var(--line); border-radius: 9px;
  background: var(--surface); outline: none;
}
.toolbar input[type="search"]:focus { border-color: var(--accent); }
.toolbar select { padding: 9px 12px; border: 1px solid var(--line); border-radius: 9px; background: var(--surface); outline: none; }

/* 進度條 */
.progress { height: 6px; background: #ece9e1; border-radius: 99px; overflow: hidden; min-width: 80px; }
.progress > div { height: 100%; background: var(--accent); border-radius: 99px; transition: width .3s; }

/* 列表項 */
.list-item {
  display: flex; align-items: center; gap: 14px;
  padding: 13px 4px; border-bottom: 1px solid var(--line);
}
.list-item:last-child { border-bottom: none; }
.list-item .grow { flex: 1; min-width: 0; }
.list-item .title { font-weight: 500; }
.list-item .meta { font-size: 13px; color: var(--muted); }
.date-chip {
  flex-shrink: 0; text-align: center; min-width: 52px;
  background: var(--accent-soft); border-radius: 10px; padding: 7px 8px;
}
.date-chip .d { font-family: var(--font-serif); font-size: 19px; font-weight: 600; color: var(--accent-deep); line-height: 1.2; }
.date-chip .m { font-size: 11px; color: var(--accent-deep); letter-spacing: 1px; }

/* 案件卡片 */
.case-card {
  display: block; text-decoration: none; color: inherit;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 20px 22px; transition: border-color .15s, transform .15s;
}
.case-card:hover { border-color: var(--accent); transform: translateY(-1px); }
.case-card .head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.case-card .name { font-family: var(--font-serif); font-size: 19px; font-weight: 600; letter-spacing: 1px; }
.case-card .row { display: flex; align-items: center; justify-content: space-between; gap: 12px; font-size: 13.5px; color: var(--muted); margin-top: 10px; }

/* 頁籤 */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 20px; overflow-x: auto; }
.tabs button {
  background: none; border: none; padding: 10px 16px;
  font-size: 14.5px; color: var(--muted); white-space: nowrap;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tabs button.active { color: var(--accent-deep); border-bottom-color: var(--accent); font-weight: 500; }

/* 任務看板列 */
.task-row { display: flex; align-items: center; gap: 12px; padding: 12px 4px; border-bottom: 1px solid var(--line); }
.task-row:last-child { border-bottom: none; }
.task-row.done .t-name { color: var(--muted); text-decoration: line-through; }
.task-check {
  width: 22px; height: 22px; flex-shrink: 0;
  border: 1.5px solid var(--line); border-radius: 50%;
  background: var(--surface); display: flex; align-items: center; justify-content: center;
  transition: all .15s; padding: 0;
}
.task-check:hover { border-color: var(--accent); }
.task-check.checked { background: var(--ok); border-color: var(--ok); }
.task-check svg { width: 12px; height: 12px; color: #fff; }
.t-name { flex: 1; min-width: 0; }
.t-meta { font-size: 13px; color: var(--muted); white-space: nowrap; }

/* 時間軸 */
.timeline { position: relative; padding-left: 24px; }
.timeline::before { content: ''; position: absolute; left: 7px; top: 6px; bottom: 6px; width: 1.5px; background: var(--line); }
.tl-item { position: relative; padding-bottom: 20px; }
.tl-item:last-child { padding-bottom: 0; }
.tl-item::before {
  content: ''; position: absolute; left: -23px; top: 6px;
  width: 11px; height: 11px; border-radius: 50%;
  background: var(--surface); border: 2.5px solid var(--line);
}
.tl-item.done::before { background: var(--ok); border-color: var(--ok); }
.tl-item.now::before { background: var(--surface); border-color: var(--accent); }
.tl-item .tl-date { font-size: 12.5px; color: var(--muted); }
.tl-item .tl-title { font-weight: 500; }
.tl-item .tl-note { font-size: 13.5px; color: var(--ink-soft); margin-top: 2px; }

/* 擇日表 */
.almanac-day { border-bottom: 1px solid var(--line); padding: 14px 4px; display: flex; gap: 16px; align-items: flex-start; }
.almanac-day:last-child { border-bottom: none; }
.almanac-day.good { background: linear-gradient(to right, var(--ok-soft), transparent 60%); border-radius: 8px; }
.al-date { flex-shrink: 0; width: 96px; }
.al-date .solar { font-weight: 600; font-variant-numeric: tabular-nums; }
.al-date .lunar { font-size: 12.5px; color: var(--muted); }
.al-body { flex: 1; min-width: 0; font-size: 13.5px; }
.al-body .line { margin-bottom: 3px; }
.al-body .k { color: var(--muted); margin-right: 6px; font-size: 12.5px; }
.al-tags { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 4px; }

/* ============ 彈窗 ============ */
.modal-mask {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(35, 38, 43, .45);
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.modal {
  background: var(--surface); border-radius: 14px;
  width: 100%; max-width: 520px; max-height: 90vh; overflow-y: auto;
  padding: 26px 28px;
  box-shadow: 0 20px 60px rgba(0,0,0,.25);
}
.modal h3 { font-family: var(--font-serif); font-size: 19px; font-weight: 600; margin-bottom: 18px; letter-spacing: 1px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }

/* Toast */
.toast {
  position: fixed; bottom: 28px; left: 50%; transform: translateX(-50%);
  background: var(--sidebar-bg); color: #fff;
  padding: 11px 22px; border-radius: 10px; font-size: 14px;
  box-shadow: 0 8px 24px rgba(0,0,0,.25); z-index: 200;
  opacity: 0; transition: opacity .25s, transform .25s; pointer-events: none;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(-4px); }

.empty { text-align: center; color: var(--muted); padding: 36px 16px; font-size: 14px; }
.section-gap { margin-top: 18px; }
.mt-8 { margin-top: 8px; } .mb-16 { margin-bottom: 16px; }

/* ============ 家屬入口 ============ */
.family-page { max-width: 640px; margin: 0 auto; padding: 0 20px 80px; }
.family-hero {
  text-align: center; padding: 56px 16px 36px;
  border-bottom: 1px solid var(--line); margin-bottom: 32px;
}
.family-hero .eyebrow { font-size: 13px; letter-spacing: 4px; color: var(--accent-deep); margin-bottom: 14px; }
.family-hero h1 { font-family: var(--font-serif); font-size: 34px; font-weight: 600; letter-spacing: 4px; }
.family-hero .dates { color: var(--muted); font-size: 14px; margin-top: 12px; line-height: 1.8; }
.family-section { margin-bottom: 36px; }
.family-section h2 {
  font-family: var(--font-serif); font-size: 18px; font-weight: 600;
  letter-spacing: 2px; margin-bottom: 16px; padding-left: 12px;
  border-left: 3px solid var(--accent);
}
.family-foot { text-align: center; color: var(--muted); font-size: 12.5px; padding-top: 24px; border-top: 1px solid var(--line); line-height: 2; }

/* ============ 響應式 ============ */
@media (max-width: 1024px) {
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 860px) {
  .sidebar {
    position: fixed; left: 0; top: 0; z-index: 90;
    transform: translateX(-100%); transition: transform .22s ease;
    box-shadow: 0 0 40px rgba(0,0,0,.3);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-mask { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 80; }
  .topbar { display: flex; }
  .content { padding: 20px 16px 56px; }
  .grid-2 { grid-template-columns: 1fr; }
  .page-head h2 { font-size: 22px; }
  .field-row { grid-template-columns: 1fr; }
  /* 表格在手機改為卡片式 */
  table.responsive thead { display: none; }
  table.responsive tr { display: block; border-bottom: 1px solid var(--line); padding: 10px 0; }
  table.responsive td {
    display: flex; justify-content: space-between; gap: 16px;
    border: none; padding: 4px 8px; text-align: right;
  }
  table.responsive td::before {
    content: attr(data-label);
    color: var(--muted); font-size: 12.5px; text-align: left; flex-shrink: 0;
  }
  .almanac-day { flex-direction: column; gap: 6px; }
  .family-hero h1 { font-size: 27px; }
  /* 任務列在窄螢幕允許換行,名稱保持橫排 */
  .task-row { flex-wrap: wrap; row-gap: 6px; }
  .t-name { flex: 1 1 100%; order: -1; padding-left: 34px; }
  .task-row .task-check { position: absolute; }
  .task-row { position: relative; padding-left: 0; }
  .task-row .t-meta { margin-left: 34px; }
}
@media (max-width: 480px) {
  .grid-4 { grid-template-columns: 1fr 1fr; gap: 12px; }
  .stat .value { font-size: 24px; }
}

/* ============ 使用者列 (側欄底部 / 手機頂列) ============ */
.side-user .n { color: #e8e9ec; font-size: 13.5px; display: flex; align-items: center; flex-wrap: wrap; gap: 4px; }
.side-user .acts { display: flex; gap: 6px; margin-top: 8px; }
.side-user .acts .btn { color: var(--sidebar-ink); border-color: rgba(255,255,255,.16); background: rgba(255,255,255,.05); }
.side-user .acts .btn:hover { background: rgba(255,255,255,.12); color: #fff; }
.topbar-user { margin-left: auto; }
.user-chip {
  display: flex; align-items: center; gap: 8px;
  background: rgba(255,255,255,.08); border: none; color: #fff;
  padding: 5px 12px 5px 6px; border-radius: 999px;
}
.user-chip .avatar {
  width: 26px; height: 26px; border-radius: 50%; background: var(--accent);
  display: grid; place-items: center; font-size: 13px;
}
.user-chip .who { display: flex; flex-direction: column; align-items: flex-start; line-height: 1.25; }
.user-chip .who .n { font-size: 13px; }
.user-chip .who .r { font-size: 11px; opacity: .7; }

/* ============ 統計卡片延伸 ============ */
.card.stat.link { text-decoration: none; color: inherit; display: block; transition: transform .12s, box-shadow .12s; }
.card.stat.link:hover { transform: translateY(-1px); box-shadow: 0 6px 20px rgba(35,38,43,.09); }
.card.stat.alert { border-color: #e5c9c6; background: linear-gradient(180deg, #fdf6f5, var(--surface)); }
.card.stat.alert .value { color: var(--danger); }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.tab-num {
  display: inline-block; min-width: 18px; padding: 0 5px; margin-left: 2px;
  background: var(--accent-soft); color: var(--accent-deep);
  border-radius: 9px; font-size: 11.5px; line-height: 18px; text-align: center;
}

/* ============ 明細列表 (key-value) ============ */
.kv-list > div { display: flex; justify-content: space-between; gap: 14px; padding: 7px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.kv-list > div:last-child { border-bottom: none; }
.kv-list span { color: var(--muted); flex-shrink: 0; }
.kv-list b { font-weight: 500; text-align: right; word-break: break-all; }
.kv-list.big b { font-family: var(--font-serif); font-size: 16px; }
.kv-list .grand { border-top: 2px solid var(--accent); border-bottom: none; margin-top: 4px; padding-top: 10px; }
.kv-list .grand b { font-size: 21px; color: var(--accent-deep); }
.note-box { margin-top: 14px; padding: 10px 12px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 9px; font-size: 13.5px; color: var(--ink-soft); }
.hint-text { margin-top: 12px; font-size: 12.5px; color: var(--muted); line-height: 1.7; }
.sec-title {
  font-family: var(--font-serif); font-size: 15px; margin: 22px 0 10px;
  padding-bottom: 6px; border-bottom: 1px solid var(--line);
  display: flex; align-items: baseline; gap: 10px;
}
.sec-title .hint { font-family: var(--font-sans); font-size: 12px; color: var(--muted); font-weight: 400; }

/* ============ 費用明細編輯器 ============ */
.item-toolbar { display: flex; gap: 8px; margin-bottom: 10px; flex-wrap: wrap; }
.item-toolbar select { flex: 1; min-width: 220px; }
.item-table th { white-space: nowrap; }
.item-table input, .item-table select {
  width: 100%; padding: 6px 8px; border: 1px solid var(--line);
  border-radius: 7px; font-size: 13.5px; background: var(--surface);
}
.item-table input:focus, .item-table select:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.item-table td { vertical-align: middle; }
.item-total {
  margin-top: 12px; margin-left: auto; max-width: 320px;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px;
}
.item-total > div { display: flex; justify-content: space-between; font-size: 13.5px; padding: 3px 0; }
.item-total .grand { border-top: 1px solid var(--line); margin-top: 6px; padding-top: 8px; font-size: 16px; }
.item-total .grand b { font-family: var(--font-serif); color: var(--accent-deep); }
.item-total .opt { color: var(--muted); font-size: 12.5px; }
tr.row-optional td { background: var(--surface-2); color: var(--ink-soft); }
tr.row-danger td { background: #fdf6f5; }
tr.row-muted td { opacity: .55; }

/* ============ 檔案上傳 ============ */
.upload-row { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.upload-row select, .upload-row input {
  padding: 8px 11px; border: 1px solid var(--line); border-radius: 9px; background: var(--surface);
}
.dropzone {
  border: 2px dashed var(--line); border-radius: 12px; padding: 26px 18px;
  text-align: center; cursor: pointer; background: var(--surface-2);
  transition: border-color .15s, background .15s;
}
.dropzone:hover, .dropzone.over { border-color: var(--accent); background: var(--accent-soft); }
.dz-inner strong { color: var(--accent-deep); }
.dz-hint { font-size: 12.5px; color: var(--muted); margin-top: 5px; }
.up-line { margin-top: 10px; font-size: 13px; color: var(--muted); }
.up-line.err { color: var(--danger); }
.file-row {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 2px; border-bottom: 1px solid var(--line);
}
.file-row:last-child { border-bottom: none; }
.file-row .ficon {
  width: 40px; height: 40px; flex-shrink: 0; border-radius: 9px;
  background: var(--accent-soft); color: var(--accent-deep);
  display: grid; place-items: center; font-size: 11px; font-weight: 600; letter-spacing: .5px;
}
.file-row .grow { flex: 1; min-width: 0; }
.file-row .title { font-size: 14.5px; word-break: break-all; }
.file-row .meta { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.doc-check { display: flex; gap: 10px; flex-wrap: wrap; }
.doc-chip {
  display: flex; align-items: center; gap: 8px;
  padding: 9px 14px; border-radius: 10px; font-size: 14px; border: 1px solid var(--line);
}
.doc-chip .mark { width: 20px; height: 20px; border-radius: 50%; display: grid; place-items: center; font-size: 12px; color: #fff; }
.doc-chip .s { font-size: 12px; color: var(--muted); }
.doc-chip.ok { background: var(--ok-soft); border-color: #cfe0d4; }
.doc-chip.ok .mark { background: var(--ok); }
.doc-chip.miss { background: var(--danger-soft); border-color: #e5c9c6; }
.doc-chip.miss .mark { background: var(--danger); }

/* ============ 角色說明 ============ */
.role-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 12px; }
.role-grid > div { background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; padding: 11px 14px; }
.role-grid b { display: block; font-size: 14px; margin-bottom: 3px; color: var(--accent-deep); }
.role-grid span { font-size: 12.5px; color: var(--muted); line-height: 1.65; }

@media (max-width: 1024px) {
  .grid-3 { grid-template-columns: 1fr; }
  .item-total { max-width: none; }
}
@media (max-width: 860px) {
  .topbar-user .user-chip .who { display: none; }
  .upload-row { flex-direction: column; align-items: stretch; }
}

/* 寬版彈窗 (費用明細等) */
.modal-wide { max-width: 940px; }

/* 費用明細項目卡 */
.item-card {
  border: 1px solid var(--line); border-radius: 11px;
  padding: 12px 14px; margin-bottom: 10px; background: var(--surface);
}
.item-card:has(.it-optional:checked) { background: var(--surface-2); }
.ic-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; flex-wrap: wrap; }
.ic-no {
  width: 22px; height: 22px; flex-shrink: 0; border-radius: 50%;
  background: var(--accent-soft); color: var(--accent-deep);
  display: grid; place-items: center; font-size: 12px;
}
.ic-head select { flex: 1; min-width: 130px; padding: 7px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); }
.ic-opt { font-size: 12.5px; color: var(--muted); white-space: nowrap; }
.ic-head .it-del { margin-left: auto; }
.ic-grid { display: grid; grid-template-columns: 2.2fr 2fr .85fr .85fr 1.15fr 1.2fr; gap: 10px; align-items: end; }
.ic-grid label, .ic-amount { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.ic-grid span { font-size: 12px; color: var(--muted); }
.ic-grid input {
  width: 100%; padding: 7px 10px; border: 1px solid var(--line);
  border-radius: 8px; font-size: 14px; background: var(--surface);
}
.ic-grid input:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.ic-amount b { font-family: var(--font-serif); font-size: 15px; padding: 7px 0; white-space: nowrap; }
@media (max-width: 760px) {
  .ic-grid { grid-template-columns: repeat(2, 1fr); }
  .ic-grid .f-name, .ic-grid .f-spec { grid-column: span 2; }
}

/* 成本結構長條 */
.cost-bar { display: flex; align-items: center; gap: 12px; padding: 8px 0; font-size: 14px; }
.cost-bar .l { width: 84px; flex-shrink: 0; color: var(--muted); }
.cost-bar .track { flex: 1; height: 10px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.cost-bar .track i { display: block; height: 100%; background: var(--accent); }
.cost-bar b { width: 110px; text-align: right; font-family: var(--font-serif); }
.cost-bar .p { width: 42px; text-align: right; color: var(--muted); font-size: 12.5px; }
@media (max-width: 600px) {
  .cost-bar .l { width: 66px; font-size: 13px; }
  .cost-bar b { width: 88px; font-size: 13px; }
}

/* 卡片依內容決定高度,避免同列被最高者撐開留大片空白 */
.grid-2, .grid-3 { align-items: start; }

/* ============ 塔位圖 ============ */
.niche-legend { display: flex; flex-wrap: wrap; gap: 14px; margin-bottom: 14px; font-size: 12.5px; color: var(--muted); }
.niche-legend span { display: inline-flex; align-items: center; gap: 6px; }
.niche-legend i { width: 13px; height: 13px; border-radius: 3px; border: 1px solid var(--line); display: inline-block; }
.niche-map { overflow-x: auto; padding-bottom: 4px; }
.niche-row { display: flex; align-items: center; gap: 6px; margin-bottom: 6px; }
.niche-row .rk {
  flex: 0 0 52px; font-size: 12px; color: var(--muted); text-align: right; padding-right: 6px;
}
.niche-cell {
  width: 42px; height: 42px; flex: 0 0 42px; border-radius: 6px; border: 1px solid var(--line);
  background: var(--surface-2); color: var(--ink-soft); font-size: 11.5px; line-height: 1.1;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  cursor: pointer; transition: transform .1s, box-shadow .1s; padding: 2px;
}
.niche-cell:hover { transform: translateY(-1px); box-shadow: 0 4px 10px rgba(35,38,43,.12); }
.niche-cell small { font-size: 9.5px; opacity: .7; }
.niche-cell.s-可售 { background: #fff; border-color: #d9d5c9; }
.niche-cell.s-已保留 { background: var(--warn-soft); border-color: #e2cfa6; color: var(--warn); }
.niche-cell.s-已售 { background: var(--accent-soft); border-color: #ddcbb5; color: var(--accent-deep); }
.niche-cell.s-已進塔 { background: var(--ok-soft); border-color: #bcd4c3; color: var(--ok); }
.niche-cell.s-不可售 { background: #eeece6; border-color: #ddd9d0; color: var(--muted); text-decoration: line-through; }
.niche-detail-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 10px 20px; }
@media (max-width: 640px) {
  .niche-cell { width: 36px; height: 36px; flex: 0 0 36px; font-size: 10.5px; }
  .niche-row .rk { flex: 0 0 40px; }
}

/* ============ 頁面操作說明（頁面上方的可收合說明框） ============ */
.help-box { border: 1px solid var(--line); background: var(--accent-soft); border-radius: 8px; margin-bottom: 18px; }
.help-toggle {
  display: flex; align-items: center; gap: 8px; width: 100%; padding: 9px 12px;
  background: transparent; border: 0; cursor: pointer; font: inherit; font-size: 13px; font-weight: 600;
  color: var(--accent-deep); text-align: left;
}
.help-mark {
  display: inline-flex; align-items: center; justify-content: center; width: 18px; height: 18px;
  border-radius: 50%; background: var(--accent); color: #fff; font-size: 12px; font-weight: 700;
}
.help-arrow { margin-left: auto; font-weight: 400; color: var(--muted); }
.help-body { display: none; padding: 0 14px 12px 14px; font-size: 13px; line-height: 1.85; color: var(--ink-soft); }
.help-box.open .help-body { display: block; }
.help-intro { margin: 0 0 8px; }
.help-h { font-weight: 600; color: var(--ink); margin: 10px 0 4px; }
.help-body ol, .help-body ul { margin: 0; padding-left: 20px; }
.help-body li { margin-bottom: 3px; }
.help-body dl { margin: 0; }
.help-body dt { font-weight: 600; color: var(--ink); }
.help-body dd { margin: 0 0 5px 0; color: var(--muted); }
