/* 股東後台共用樣式（股東頁、登入流程頁、主席頁共用）。
   CSP：style-src 'self'，所以不寫 style 屬性、不用行內 <style>。手機優先（375px 寬）：窄螢幕表格改卡片。
   品牌：Titan Group（官網 TitanGroup_官網/styles.css 的墨黑、金、皇家藍）；配色固定一套淺色，不跟系統深淺色切換（老闆 12-03）。 */
:root {
  color-scheme: light;
  --bg: #faf8f4;
  --card: #ffffff;
  --text: #15151b;
  --muted: #5c5a54;
  --line: #e2dccf;
  --brand: #1f3fa8;
  --brand-ink: #ffffff;
  --ink: #0b0b0f;
  --mist: #f2efe6;
  --gold: #c9a24b;
  --gold-3: #9a7634;
  --ok: #137a3a;
  --warn: #8a5300;
  --bad: #b42318;
  --radius: 10px;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; min-height: 100vh; display: flex; flex-direction: column; font-family: "Inter", "Noto Sans TC", system-ui, -apple-system, "Segoe UI", "PingFang TC", "Microsoft JhengHei", sans-serif; font-size: 16px; line-height: 1.5; background: var(--bg); color: var(--text); }
body > main { flex: 1 0 auto; width: 100%; }
a { color: var(--brand); }
[hidden] { display: none !important; }

/* 頂列：墨黑底＋官網標誌（標誌是金＋米白字，只放深底） */
.topbar { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 12px; padding: 10px 16px; background: var(--ink); color: var(--mist); border-bottom: 2px solid var(--gold-3); }
.topbar .logo { display: block; height: 20px; width: auto; flex: 0 0 auto; }
.topbar .brand { font-weight: 600; font-size: 14px; color: var(--mist); padding-left: 12px; border-left: 1px solid rgba(242, 239, 230, .3); white-space: nowrap; }
.topbar .brand.role { color: var(--gold); }
.topbar .who { margin-left: auto; color: rgba(242, 239, 230, .75); font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.topbar button { background: transparent; color: var(--mist); border-color: rgba(242, 239, 230, .35); }

/* 分頁列：可橫滑時右側（與左側）出現漸層陰影提示（純 CSS 捲動陰影：local 遮罩＋scroll 陰影） */
.tabs {
  display: flex; gap: 4px; overflow-x: auto; padding: 8px 16px 0; border-bottom: 1px solid var(--line); scrollbar-width: none;
  background:
    linear-gradient(to right, var(--card) 40%, rgba(255, 255, 255, 0)) left center / 48px 100% no-repeat local,
    linear-gradient(to left, var(--card) 40%, rgba(255, 255, 255, 0)) right center / 48px 100% no-repeat local,
    linear-gradient(to right, rgba(11, 11, 15, .16), rgba(11, 11, 15, 0)) left center / 20px 100% no-repeat scroll,
    linear-gradient(to left, rgba(11, 11, 15, .16), rgba(11, 11, 15, 0)) right center / 20px 100% no-repeat scroll,
    var(--card);
}
.tabs::-webkit-scrollbar { display: none; }
.tabs button { flex: 0 0 auto; border: 0; background: none; color: var(--muted); padding: 10px 12px; font-size: 15px; border-bottom: 3px solid transparent; border-radius: 0; cursor: pointer; min-height: 44px; }
.tabs button[aria-selected="true"] { color: var(--text); border-bottom-color: var(--gold); font-weight: 600; }

main { max-width: 960px; margin: 0 auto; padding: 16px; }
main.narrow { max-width: 440px; padding-top: 40px; }
h1 { font-size: 22px; margin: 4px 0 16px; }
h2 { font-size: 18px; margin: 24px 0 10px; }
h3 { font-size: 16px; margin: 0 0 8px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.head-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.head-row h1, .head-row h2 { margin: 4px 0; }
.head-row { margin-bottom: 12px; }
.head-row .actions { margin-left: auto; }
.greet { margin: -8px 0 16px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; }
.grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); margin-bottom: 16px; }
.grid:empty { display: none; }
/* 卡片是 container：裡面的大字依「卡片本身的寬」縮放（cqi），兩欄小卡也不會衝出框 */
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; min-width: 0; container-type: inline-size; }
.stat .label { color: var(--muted); font-size: 13px; display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.stat .label .unit { font-size: 12px; letter-spacing: .02em; white-space: nowrap; }
/* 金額、百分比絕不斷行、也不准溢出（老闆 12-03）：不用 word-break: break-all；幣別放上一行小字，大字只放數字並依卡寬縮字 */
.stat .value { font-size: 22px; font-size: clamp(16px, 8cqi, 26px); font-weight: 700; font-variant-numeric: tabular-nums; margin-top: 2px; white-space: nowrap; }
.stat .value.secondary { font-size: 17px; font-size: clamp(14px, 6cqi, 19px); font-weight: 600; color: var(--muted); }
.stat .sub { color: var(--muted); font-size: 13px; margin-top: 4px; font-variant-numeric: tabular-nums; }
.stat .pair { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: baseline; gap: 4px 12px; margin-top: 8px; }
.stat .pair .value { margin-left: auto; }
.stat .pair + .pair { border-top: 1px solid var(--line); padding-top: 8px; }
.stat .pair .k { color: var(--muted); font-size: 14px; white-space: nowrap; }
.num, .nowrap { white-space: nowrap; font-variant-numeric: tabular-nums; }

/* 實際權益比例：一行＋可展開說明 */
.equity { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 12px; }
.equity .value { font-size: 22px; font-weight: 700; white-space: nowrap; font-variant-numeric: tabular-nums; }
.equity .parts { color: var(--muted); font-size: 14px; }
.equity .parts .num { color: var(--text); }
details.explain { margin-top: 10px; font-size: 14px; color: var(--muted); }
details.explain summary { cursor: pointer; color: var(--brand); min-height: 32px; display: inline-flex; align-items: center; }
details.explain ul { margin: 6px 0 0; padding-left: 18px; }

/* 最新一季財報摘要 */
.report-summary .meta { margin: 0 0 12px; }
.report-summary .actions, .figures + .actions { margin-top: 12px; }
.card > h2:first-child { margin-top: 0; }
.stat .label > span:first-child { white-space: nowrap; }

/* 空狀態：置中卡片＋一句下一步（股東頁用 .empty；主席頁沿用 common.js 的空表格文字，也套同樣外觀） */
.empty, [data-panel] div[id] > p.muted:only-child:not(.small) { text-align: center; background: var(--card); border: 1px dashed var(--line); border-radius: var(--radius); padding: 28px 16px; margin: 0 0 16px; color: var(--muted); }
.empty .title { color: var(--text); font-weight: 600; margin: 0 0 4px; }
.empty .next { margin: 0; font-size: 14px; }

.status { padding: 10px 12px; border-radius: 8px; background: var(--card); border: 1px solid var(--line); margin: 0 0 12px; }
.status.error { border-color: var(--bad); color: var(--bad); }
.status.ok { border-color: var(--ok); color: var(--ok); }
.status:empty { display: none; }

table { width: 100%; border-collapse: collapse; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 13px; color: var(--muted); font-weight: 600; background: var(--bg); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
.actions { display: flex; flex-wrap: wrap; gap: 6px; }

.badge { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; border: 1px solid var(--line); color: var(--muted); white-space: nowrap; }
.badge.ok { color: var(--ok); border-color: var(--ok); }
.badge.warn { color: var(--warn); border-color: var(--warn); }
.badge.bad { color: var(--bad); border-color: var(--bad); }

form .row { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 14px; color: var(--muted); flex: 1 1 160px; }
label.check { flex-direction: row; align-items: flex-start; gap: 10px; color: var(--text); font-size: 15px; }
label.check input { width: 20px; height: 20px; margin-top: 2px; flex: 0 0 auto; }
input, select, textarea { font: inherit; color: var(--text); background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; min-height: 44px; width: 100%; }
/* 指令框等一般文字框用正常字型（老闆 12-03）；只有貼 CSV 的框用等寬字方便對欄 */
textarea { min-height: 140px; font-size: 15px; }
#import-text { font-family: ui-monospace, Consolas, monospace; font-size: 14px; }
/* 要照抄的一行英文（CSV 表頭）：手機上可在逗號處換行，不衝出卡片 */
.code-line { font-family: ui-monospace, Consolas, monospace; font-size: 13px; background: var(--bg); border: 1px dashed var(--line); border-radius: 8px; padding: 6px 10px; white-space: pre; overflow-x: auto; -webkit-overflow-scrolling: touch; user-select: all; }
input:focus, select:focus, textarea:focus, button:focus-visible, summary:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; }

button, .button { font: inherit; display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; padding: 8px 16px; border-radius: 8px; border: 1px solid var(--line); background: var(--card); color: var(--text); cursor: pointer; text-decoration: none; white-space: nowrap; }
button.primary, .button.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); font-weight: 600; }
button.danger { color: var(--bad); border-color: var(--bad); }
button.small, .button.small { min-height: 36px; padding: 4px 10px; font-size: 14px; }
button:disabled { opacity: .5; cursor: not-allowed; }
button[aria-expanded="true"] { border-color: var(--brand); color: var(--brand); }
.full { width: 100%; }
.stack > * + * { margin-top: 12px; }
.secret { font-size: 15px; padding: 8px 12px; background: var(--bg); border: 1px dashed var(--line); border-radius: 8px; user-select: all; white-space: pre-wrap; word-break: break-word; }

.fig-row { align-items: flex-end; }
/* 財報數字卡：flex 換行＋可伸展，張數不整除時最後一列的卡撐滿（5 張不留空格） */
.figures { display: flex; flex-wrap: wrap; gap: 8px; }
.figures > * { flex: 1 1 150px; }
.figures .stat .value { font-size: 16px; font-size: clamp(13px, 12cqi, 20px); }
ul.tree { list-style: none; margin: 0; padding-left: 18px; border-left: 2px solid var(--line); }
.card > ul.tree { padding-left: 8px; }
ul.tree li { margin: 8px 0; }
.tree-node { display: flex; flex-direction: column; gap: 4px; }
.tree-head { display: flex; align-items: center; gap: 8px; }
.tree-head strong { min-width: 0; overflow-wrap: anywhere; }
.tree-head button { margin-left: auto; flex: 0 0 auto; }
.tree-tags { display: flex; flex-wrap: wrap; gap: 6px; }
.tree-tags:empty { display: none; }
fieldset { border: 1px solid var(--line); }

/* 登入頁：深色品牌區＋歡迎詞 */
.login-brand { background: var(--ink); border-radius: var(--radius) var(--radius) 0 0; padding: 22px 16px 18px; text-align: center; border-bottom: 2px solid var(--gold-3); }
.login-brand .logo { height: 26px; width: auto; }
.login-brand + .card { border-top: 0; border-radius: 0 0 var(--radius) var(--radius); }
.welcome { margin: 0 0 4px; font-size: 20px; }

/* 頁尾：公司名＋©年份 */
.site-footer { flex: 0 0 auto; text-align: center; color: var(--muted); font-size: 12px; padding: 20px 16px 28px; border-top: 1px solid var(--line); margin-top: 24px; }

/* 手機：表格改成一列一張卡片，每格前面顯示欄名（data-label）；統計卡一格一行 */
@media (max-width: 640px) {
  main { padding: 12px; }
  .topbar { gap: 10px; padding: 10px 12px; }
  .topbar .logo { height: 16px; }
  .topbar .who { display: none; }
  .topbar .brand + .who + button { margin-left: auto; }
  .grid { grid-template-columns: 1fr; }
  table.cards, table.cards tbody, table.cards tr, table.cards td { display: block; width: 100%; }
  table.cards { border: 0; background: none; }
  table.cards thead { display: none; }
  table.cards tr { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 10px; padding: 6px 0; }
  table.cards td { border: 0; padding: 6px 12px; display: flex; justify-content: space-between; gap: 12px; text-align: right; }
  table.cards td::before { content: attr(data-label); color: var(--muted); font-size: 13px; text-align: left; flex: 0 0 auto; }
  table.cards td.num { white-space: nowrap; }
  table.cards td .actions { justify-content: flex-end; }
  /* 待核准等操作列：手機上按鈕撐滿、夠大，一鍵按得到 */
  table.cards td[data-label="處理"] { display: block; }
  table.cards td[data-label="處理"]::before { display: none; }
  table.cards td[data-label="處理"] .actions button { flex: 1 1 0; min-height: 48px; font-size: 16px; }
  .tabs button { padding: 10px 10px; font-size: 14px; }
  /* 存取紀錄：每筆壓成 2～3 行——①時間＋誰 ②做了什麼＋對象＋結果 ③IP（小字），不顯示欄名 */
  table.cards.audit tr { display: grid; grid-template-columns: auto 1fr auto; align-items: baseline; gap: 2px 10px; padding: 8px 12px; }
  table.cards.audit td { display: block; width: auto; padding: 0; text-align: left; min-width: 0; overflow-wrap: anywhere; }
  table.cards.audit td::before { display: none; }
  table.cards.audit td:nth-child(1) { grid-column: 1; color: var(--muted); font-size: 13px; white-space: nowrap; font-variant-numeric: tabular-nums; }
  table.cards.audit td:nth-child(2) { grid-column: 2 / 4; text-align: right; }
  table.cards.audit td:nth-child(3) { grid-column: 1; font-weight: 600; }
  table.cards.audit td:nth-child(4) { grid-column: 2; color: var(--muted); font-size: 13px; }
  table.cards.audit td:nth-child(5) { grid-column: 3; }
  table.cards.audit td:nth-child(6) { grid-column: 1 / 4; color: var(--muted); font-size: 12px; }
}
