/* ---------- 顏色與字型（要換色只改這裡）----------
   沿用 Welly 官網配色：近白底、深炭灰文字、品牌黃當主要按鈕與重點、深黃當強調字；頁首淡黃→淡青漸層。
   只借配色，不放 Welly Logo／名稱（這是應徵作業的 POC，不是官方工具）。
   不用紅色：台灣股市紅色代表上漲，財報用紅綠容易看反；「要處理」一律用黃色系。 */
:root {
  --paper: #FCFCFC;    /* 頁面底色 */
  --card: #FFFFFF;     /* 區塊底色 */
  --tile: #F7F7F7;     /* 區塊內的小格底色 */
  --ink: #2E2E2E;      /* 主要文字（深炭灰） */
  --muted: #636363;    /* 次要文字 */
  --hair: #DBDBDB;     /* 細框線 */
  --dark: #2E2E2E;     /* 深色數字區、選取狀態 */
  --yellow: #FDDA5A;   /* 品牌黃：主要按鈕、優先查核、重點數字 */
  --yellow-d: #F5AD0B; /* 深黃：留意框線、圖表 */
  --yellow-l: #FEF3C7; /* 淡黃：提醒底色 */
  --warn-text: #8A5A00;/* 白底上的警示文字（深黃褐，確保可讀對比） */
  --cyan-l: #E4F9FF;   /* 淡青：已還原 */
  --cyan-d: #1F5F70;   /* 淡青底上的文字 */
}
* { box-sizing: border-box; }
body { font-family: -apple-system, "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", "Segoe UI", system-ui, sans-serif; margin: 0; background: var(--paper); color: var(--ink); font-size: 15px; line-height: 1.65; -webkit-font-smoothing: antialiased; }
code { font-size: 12.5px; background: var(--tile); border: 1px solid var(--hair); padding: 0 5px; border-radius: 3px; }

/* ---------- 頁首 ---------- */
.top { background: linear-gradient(90deg, #FFFBEB 0%, #FCFCFC 55%, #E4F9FF 100%); border-bottom: 1px solid var(--hair); padding: 28px 24px 24px; }
.top h1 { max-width: 1180px; margin: 0 auto 6px; font-size: 27px; letter-spacing: .01em; }
.lead { max-width: 1180px; margin: 0 auto; color: var(--muted); font-size: 14.5px; }
main { max-width: 1180px; margin: 0 auto; padding: 24px 18px; }

/* ---------- 區塊 ---------- */
.panel { background: var(--card); border: 1px solid var(--hair); border-radius: 4px; padding: 20px 22px; margin-bottom: 18px; }
.panel h2 { font-size: 18px; margin: 0 0 14px; display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.panel h3 { font-size: 15px; margin: 20px 0 6px; color: var(--muted); }
/* 首頁分層：①拖放框（唯一焦點，框裡只有大字＋按鈕）②框下方淡色三步驟 ③頁尾灰色備註。載入後框縮成一行、步驟隱藏 */
#upload { border: 2px dashed #C9C9C9; text-align: center; padding: 56px 24px; }
#upload.dragover { border-color: var(--yellow-d); background: #FFFBEB; }
.drop-title { font-size: 24px; font-weight: bold; margin: 0 0 18px; text-wrap: balance; }
#upload .error { text-align: left; }
.scroll { overflow-x: auto; }
.drop-actions { justify-content: center; }
#fileInfo:empty { display: none; }
#upload p { margin: 8px 0 0; }
.steps { list-style: none; counter-reset: s; display: flex; justify-content: center; margin: 8px auto 0; padding: 0; max-width: 760px; }
.steps li { counter-increment: s; flex: 1; font-size: 13px; color: var(--muted); padding: 0 12px; position: relative; text-align: center; }
.steps li::before { content: counter(s); display: block; width: 26px; height: 26px; line-height: 26px; margin: 0 auto 6px; border-radius: 50%; background: var(--yellow); color: var(--ink); font-weight: bold; font-size: 13px; }
.steps li + li::after { content: '→'; position: absolute; left: -8px; top: 2px; color: #BDBDBD; }
.steps b { display: block; color: var(--ink); font-size: 14px; }
#upload.loaded { text-align: left; padding: 12px 18px; display: flex; flex-wrap: wrap; align-items: center; gap: 4px 14px; }
#upload.loaded .drop-title { font-size: 15px; margin: 0; }
#upload.loaded .drop-actions { justify-content: flex-start; margin: 0; }
#upload.loaded p { margin: 0; }
#upload.loaded .error { flex-basis: 100%; }
#upload.loaded + .steps { display: none; }
/* 頁尾備註 */
.notes { list-style: none; margin: 0 auto; padding: 18px 18px 0; max-width: 1180px; border-top: 1px solid #EBEBEB; text-align: center; }
.notes li { margin: 2px 0; }
.sample { color: var(--ink); text-decoration: none; border-bottom: 2px solid var(--yellow); }
.sample:hover { background: #FFFBEB; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin: 6px 0; }
.between { justify-content: space-between; }
.muted { color: var(--muted); } .small { font-size: 13px; }
.hint { font-size: 13.5px; background: var(--tile); border: 1px solid var(--hair); color: var(--muted); padding: 10px 14px; border-radius: 4px; margin: 12px 0 0; }
.error { white-space: pre-wrap; background: var(--yellow-l); color: var(--warn-text); padding: 10px 14px; border-radius: 4px; margin-top: 10px; }
.trust { margin-top: 12px; padding: 10px 14px; border-left: 4px solid var(--yellow); background: var(--tile); font-size: 14px; display: flex; flex-wrap: wrap; gap: 4px 22px; align-items: baseline; }
.stat b { font-size: 18px; }
.stat.muted { margin-left: auto; font-size: 13px; }
/* 本月重點：白話摘要，一句一行 */
.summary { margin: 0; padding-left: 1.2em; font-size: 15px; line-height: 1.9; }
#secSummary { border-left: 4px solid var(--yellow); }
/* 跳轉連結：放在數字區下方，一行小字 */
.jumps { display: flex; flex-wrap: wrap; align-items: center; gap: 2px 4px; margin: -8px 0 18px; }
button.link { border: 0; background: none; color: var(--ink); font: inherit; font-size: 13.5px; padding: 2px 8px; cursor: pointer; border-bottom: 2px solid var(--yellow); }
button.link:hover { background: #FFFBEB; }
/* 可收放的長表：標題列可點，前面的箭頭顯示目前狀態 */
details.fold > summary { list-style: none; cursor: pointer; }
details.fold > summary::-webkit-details-marker { display: none; }
details.fold > summary h2 { margin-bottom: 0; }
details.fold > summary h2::before { content: '▸'; display: inline-block; width: 1em; color: var(--muted); transition: transform .15s; }
details.fold[open] > summary h2::before { transform: rotate(90deg); }
details.fold[open] > summary h2 { margin-bottom: 14px; }
details.fold > summary h2 { justify-content: flex-start; }

/* 分級圖例：一級一行，標籤在前 */
.legend { list-style: none; margin: 0 0 4px; padding: 0; font-size: 13.5px; }
.legend li { margin: 4px 0; }
.legend .tier { min-width: 6.5em; text-align: center; margin-right: 6px; }
input[type=date] { font: inherit; padding: 5px 10px; border: 1px solid #C9C9C9; border-radius: 4px; background: #fff; color: var(--ink); }

/* ---------- 按鈕（品牌黃、方角，同官網「聯絡我們」） ---------- */
.btn { border: 1px solid var(--yellow); background: var(--yellow); color: var(--ink); border-radius: 3px; padding: 7px 20px; cursor: pointer; font-size: 14.5px; font-family: inherit; }
.btn:hover { filter: brightness(.96); }
.btn[disabled] { background: #E6E6E6; border-color: #E6E6E6; color: #9A9A9A; cursor: default; filter: none; }
#printBtn { background: #fff; border-color: var(--ink); }   /* 次要操作：外框 */

/* ---------- 數字區（深炭灰，重點數字用品牌黃） ---------- */
.cards { display: grid; grid-template-columns: repeat(4, 1fr); margin-bottom: 18px; border-radius: 4px; overflow: hidden; background: var(--dark); }
.card { color: #fff; padding: 20px 22px; cursor: pointer; border-left: 1px solid rgba(255,255,255,.16); transition: background .15s; }
.card:first-child { border-left: 0; }
.card:hover { background: rgba(255,255,255,.06); }
.card .n { font-size: 30px; font-weight: bold; line-height: 1.25; font-variant-numeric: tabular-nums; }
.card .t { font-size: 13.5px; color: rgba(255,255,255,.78); margin-top: 4px; }
.card.hl .n { color: var(--yellow); }   /* 整區唯一的重點：毛利異常家數 */
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.two .panel { margin-bottom: 18px; }

/* ---------- 表格 ---------- */
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 8px 10px; border-bottom: 1px solid #EBEBEB; text-align: left; vertical-align: top; white-space: nowrap; }
th { background: var(--tile); color: var(--muted); font-size: 13px; }
td.wrap, th.wrap { white-space: normal; min-width: 10em; }
td.name { white-space: normal; min-width: 9em; max-width: 22em; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr.click { cursor: pointer; } tr.click:hover td { background: #FFFBEB; }
tr.detail > td { background: var(--tile); padding: 8px 16px; }
#alertTable, #growthTable, #monthlyTable, #overdueTable, #belowTable, #pendingTable, #flagTable, #arPendingTable { overflow-x: auto; }

/* 分級標籤：要處理的實心黃、要留意的黃框、沒問題的淡化，眼睛先看到要處理的 */
.tier { display: inline-block; padding: 1px 10px; border-radius: 3px; font-size: 12.5px; white-space: nowrap; border: 1px solid transparent; }
.tier.red { background: var(--yellow); color: var(--ink); font-weight: bold; }
.tier.yellow { background: #fff; color: var(--warn-text); border-color: var(--yellow-d); }
.tier.grey { background: var(--tile); color: var(--muted); border-color: var(--hair); }
.tier.none { background: transparent; color: var(--muted); }   /* 無底色來淡化；字色維持可讀對比 */
.down { color: var(--warn-text); font-weight: bold; } .up { color: var(--muted); }

/* ---------- 篩選鈕、圖表切換 ---------- */
.chips { margin-bottom: 8px; }
.chips button, .toggle button { border: 1px solid var(--hair); background: #fff; border-radius: 3px; padding: 2px 12px; margin-right: 4px; cursor: pointer; font-size: 13px; color: var(--ink); font-family: inherit; }
.chips button.on, .toggle button.on { background: var(--dark); color: #fff; border-color: var(--dark); }
.toggle { font-weight: normal; }

/* ---------- 交接包、還原 ---------- */
.handoff { white-space: pre-wrap; background: var(--tile); border: 1px solid var(--hair); padding: 14px; border-radius: 4px; max-height: 420px; overflow: auto; font-size: 13.5px; min-height: 40px; }
textarea { width: 100%; font: inherit; padding: 10px 12px; border: 1px solid #C9C9C9; border-radius: 4px; background: #fff; color: var(--ink); }
.restored { white-space: pre-wrap; background: var(--tile); border: 1px solid var(--hair); padding: 14px; border-radius: 4px; min-height: 40px; }
.tag { padding: 0 5px; border-radius: 3px; }
.tag.ok { background: var(--cyan-l); color: var(--cyan-d); } .tag.bad { background: var(--yellow-l); color: var(--warn-text); }

svg text { font-family: inherit; fill: var(--ink); }
footer { text-align: center; padding: 10px 0 28px; }
.printonly { display: none; }

@media (max-width: 800px) {
  .cards, .two { grid-template-columns: 1fr; }
  .card { border-left: 0; border-top: 1px solid rgba(255,255,255,.16); }
  .card:first-child { border-top: 0; }
}

/* ---------- 列印（A4 直式，給老闆看） ---------- */
@page { size: A4; margin: 12mm; }
@media print {
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }  /* 保留數字區、分級標籤與圖表顏色 */
  body { background: #fff; font-size: 11px; }
  main { max-width: none; padding: 0; }
  .top { background: #fff; padding: 0 0 6px; border-bottom: 3px solid var(--yellow); margin-bottom: 8px; }
  .top h1 { font-size: 17px; margin: 0; }
  .lead { display: none; }
  .noprint, footer { display: none !important; }
  .printonly { display: inline; }
  .panel { border: 1px solid #D5D5D5; padding: 8px 10px; margin-bottom: 8px; }
  .panel h2 { font-size: 13px; margin-bottom: 6px; }
  .cards { grid-template-columns: repeat(4, 1fr) !important; margin-bottom: 8px; }
  .card { padding: 7px 9px; border-left: 1px solid rgba(255,255,255,.2) !important; border-top: 0 !important; }
  .card:first-child { border-left: 0 !important; }
  .card .n { font-size: 17px; }
  .card .t { font-size: 9.5px; }
  .two { grid-template-columns: 1fr 1fr !important; gap: 8px; }
  .two .panel { margin-bottom: 8px; }
  table { font-size: 10.5px; }
  th, td { padding: 3px 5px; }
  th { font-size: 10px; }
  td.wrap, th.wrap { min-width: 0; }
  td.name { min-width: 7em; max-width: 14em; }
  .tier { font-size: 9.5px; padding: 0 6px; }
  .trust { font-size: 10.5px; padding: 4px 8px; }
  h2, h3 { break-after: avoid; }
  tr { break-inside: avoid; }
  thead { display: table-header-group; }   /* 換頁時表頭重複 */
  .panel, .card { break-inside: auto; }
  .cards, .two, #secAlert { break-inside: avoid; }
  .handoff { max-height: none; }
  details.fold > summary h2::before { display: none; }   /* 紙本不需要收放箭頭 */
  .summary { font-size: 11px; line-height: 1.6; }
  #secSummary { break-inside: avoid; }
  tr.detail { display: none; }
  #alertTable, #growthTable, #monthlyTable, #overdueTable, #belowTable, #pendingTable, #flagTable, #arPendingTable { overflow: visible; }
}
