/* 台股帳本：像試算表的唯讀畫面。報酬率紅正綠負、輸入欄藍字（README 第 2 節的慣例）。 */
:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --ink: #1f2328;
  --muted: #6a737d;
  --line: #d8dee4;
  --head: #e8eef6;
  --accent: #2b5fa8;
  --pos: #c62828;      /* 正 = 紅 */
  --neg: #1b7f3b;      /* 負 = 綠 */
  --input: #1f4fbf;    /* 輸入欄藍字 */
  --calc: #eef0f3;     /* 計算欄灰底 */
  --warn: #b26a00;
  --bad: #c62828;
  --ok: #1b7f3b;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink);
  font: 14px/1.45 "Microsoft JhengHei", "PingFang TC", "Noto Sans TC", system-ui, sans-serif; }
.top { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; padding: 10px 16px;
  background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
.brand { font-weight: 700; font-size: 17px; }
.pf select { margin-left: 4px; font: inherit; padding: 3px 6px; }
.badge { font-size: 12px; padding: 1px 8px; border-radius: 10px; background: #eef1f4; color: var(--muted);
  border: 1px solid var(--line); }
.actions { margin-left: auto; display: flex; gap: 6px; flex-wrap: wrap; }
.btn { display: inline-block; padding: 4px 10px; border: 1px solid var(--line); border-radius: 4px;
  background: #fff; color: var(--accent); text-decoration: none; font-size: 13px; }
.btn:hover { background: var(--head); }
.tabs { display: flex; gap: 2px; overflow-x: auto; padding: 0 16px; background: var(--panel);
  border-bottom: 1px solid var(--line); scrollbar-width: thin; }
.tabs a { flex: none; padding: 8px 12px; color: var(--ink); text-decoration: none; border-bottom: 3px solid transparent;
  white-space: nowrap; }
.tabs a.on { border-bottom-color: var(--accent); color: var(--accent); font-weight: 700; }
main { padding: 12px 16px 24px; max-width: 100%; }
.foot { padding: 8px 16px 16px; color: var(--muted); font-size: 12px; }
.muted, .note { color: var(--muted); font-size: 13px; }
.note { margin: 6px 0 10px; }
.error { color: var(--bad); font-weight: 700; }
section.block { margin: 0 0 18px; }
section.block > h2 { font-size: 15px; margin: 0 0 6px; }
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 8px 10px; min-width: 0; }
.kpi .l { color: var(--muted); font-size: 12px; }
.kpi .v { font-size: 17px; font-weight: 700; word-break: break-word; font-variant-numeric: tabular-nums; }
.kpi .v.small { font-size: 14px; font-weight: 600; }
.pos { color: var(--pos); }
.neg { color: var(--neg); }
.s-ok { color: var(--ok); }
.s-warn { color: var(--warn); font-weight: 700; }
.s-bad { color: var(--bad); font-weight: 700; }
.tbl { background: var(--panel); max-width: 100%; }
.tabulator { font-size: 13px; border: 1px solid var(--line); background: var(--panel); }
.tabulator .tabulator-header .tabulator-col { background: var(--head); }
.tabulator .tabulator-header .tabulator-col .tabulator-col-title { white-space: normal; }
.tabulator-row .tabulator-cell { font-variant-numeric: tabular-nums; }
.tabulator-row .tabulator-cell.in { color: var(--input); }
.tabulator-row .tabulator-cell.calc { background: var(--calc); }
.tabulator-row .tabulator-cell.calc.stale { font-style: italic; color: var(--muted); }
.legend { font-size: 12px; color: var(--muted); margin: 0 0 6px; display: flex; flex-wrap: wrap; align-items: center; gap: 4px 6px; }
.legend .lg-in { color: var(--input); font-weight: 700; padding: 0 6px; border: 1px solid var(--line); background: var(--panel); }
.legend .lg-calc { padding: 0 6px; border: 1px solid var(--line); background: var(--calc); color: var(--ink); margin-left: 8px; }
.tabulator-row.total { font-weight: 700; background: #f3f6fa; }
.tabulator-row .tabulator-cell.link { color: var(--accent); cursor: pointer; text-decoration: underline; }
.tabulator .tabulator-header .tabulator-col input { font-size: 12px; padding: 2px 4px; }
.charts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.chart { background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 6px; min-width: 0; }
.chart h3 { font-size: 14px; margin: 2px 4px 0; }
.chart .c { width: 100%; height: 320px; }
.picker select { font: inherit; padding: 4px 6px; max-width: 100%; min-width: 220px; }
@media (max-width: 760px) {
  .top { padding: 8px 12px; }
  .actions { margin-left: 0; width: 100%; }
  .tabs { padding: 0 8px; }
  main { padding: 10px 12px 20px; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpi .v { font-size: 15px; }
  .charts { grid-template-columns: minmax(0, 1fr); }
  .chart .c { height: 260px; }
  .picker select { min-width: 0; width: 100%; }
}
/* S5：登入頁、頁首的使用者、管理頁 */
[hidden] { display: none !important; }
.badge.write { background: #fdf0e0; color: var(--warn); border-color: #f0c68c; }
.user { align-self: center; font-size: 13px; color: var(--muted); }
button.btn { font: inherit; font-size: 13px; cursor: pointer; }
.btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); padding: 8px 16px; font-size: 15px; }
.testmode { background: #fff3cd; color: #7a5300; padding: 4px 16px; font-size: 13px; border-bottom: 1px solid #f0d58c; }
body.login { display: flex; justify-content: center; padding: 40px 16px; }
.login-box { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 20px 24px; max-width: 420px; width: 100%; }
.login-box h1 { font-size: 20px; margin: 0 0 12px; }
.login-box .err { color: var(--bad); font-weight: 700; }
.login-box form.test { margin-top: 16px; border-top: 1px dashed var(--line); padding-top: 8px; }
.login-box input { font: inherit; padding: 4px 6px; max-width: 100%; }
body.admin-mode #portfolio, body.admin-mode .pf, body.admin-mode #export-page, body.admin-mode #export-all, body.admin-mode #badge { display: none; }
.scroll { overflow-x: auto; max-width: 100%; }
table.admin-users, table.admin-events { border-collapse: collapse; background: var(--panel); font-size: 13px; }
table.admin-users th, table.admin-users td, table.admin-events th, table.admin-events td { border: 1px solid var(--line); padding: 4px 6px; white-space: nowrap; }
table.admin-users th, table.admin-events th { background: var(--head); }
table.admin-users input.name { width: 8em; }
table.admin-users input.email { width: 16em; }
table.admin-users tr.new td { background: #f7fbff; }
.job-buttons { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0; }
.job-buttons button { white-space: normal; text-align: left; }
table.snaps { border-collapse: collapse; background: var(--panel); font-size: 13px; }
table.snaps th, table.snaps td { border: 1px solid var(--line); padding: 3px 6px; white-space: nowrap; }
table.snaps th { background: var(--head); }
table.snaps td.r { text-align: right; }
/* S6：編輯（草稿）、差異確認、改動紀錄 */
.editbar { display: flex; flex-wrap: wrap; gap: 6px 10px; align-items: center; background: #fff8e1; border: 1px solid #f0d58c;
  border-radius: 6px; padding: 8px 10px; margin-bottom: 12px; }
.editbar .grow { flex: 1; }
.btn.primary-s { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.edtools { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 0 0 6px; }
.edtools input { font: inherit; padding: 3px 6px; }
.tabulator-row .tabulator-cell.draft { background: #fff3b0; }
.tabulator-row.added .tabulator-cell { background: #e6f4ea; }
.tabulator-row.deleted .tabulator-cell { text-decoration: line-through; color: var(--muted); background: #f3f3f3; }
.tabulator-row.deleted .tabulator-cell.delcell { text-decoration: none; }
.tabulator-row .tabulator-cell.delcell { color: var(--accent); cursor: pointer; text-decoration: underline; }
.overlay { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 50; display: flex; align-items: flex-start;
  justify-content: center; padding: 40px 12px; overflow-y: auto; }
.dialog { background: var(--panel); border-radius: 8px; padding: 14px 18px; max-width: 720px; width: 100%; }
.dialog h2 { font-size: 16px; margin: 0 0 8px; }
ol.diff { padding-left: 22px; margin: 6px 0; max-height: 60vh; overflow-y: auto; }
ol.diff > li { margin: 0 0 6px; }
ol.diff > li.bad, ul li.bad { color: var(--bad); }
ol.diff ul, ul.chg { margin: 2px 0; padding-left: 18px; }
.old { color: var(--muted); text-decoration: line-through; }
.dlg-btns { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; margin-top: 10px; }
.flash { background: #e6f4ea; border: 1px solid #b7dfc3; color: #1b5e20; padding: 6px 10px; border-radius: 6px; }
table.hist { border-collapse: collapse; background: var(--panel); font-size: 13px; }
table.hist th, table.hist td { border: 1px solid var(--line); padding: 4px 6px; vertical-align: top; }
table.hist th { background: var(--head); white-space: nowrap; }
table.hist td:first-child { white-space: nowrap; }
table.hist tr.reverted td { color: var(--muted); }
/* 匯入（S7） */
.imp h3 { font-size: 14px; margin: 14px 0 4px; padding: 4px 6px; border-radius: 3px; }
.imp h3.ok { background: #e6f4ea; } .imp h3.warn { background: #fdecea; } .imp h3.new { background: #e8f0fe; }
table.imp-t { border-collapse: collapse; background: var(--panel); font-size: 13px; margin-bottom: 4px; }
table.imp-t th, table.imp-t td { border: 1px solid var(--line); padding: 2px 6px; text-align: right; white-space: nowrap; }
table.imp-t th { background: var(--head); text-align: center; }
table.imp-t td.l { text-align: left; white-space: normal; }
table.imp-t td.l label { margin-right: 10px; white-space: nowrap; }
table.imp-t tr.b td { background: #fafcff; } table.imp-t tr.m td { background: #fffaf2; }
table.imp-t input.num { text-align: right; }
.imp-bar { position: sticky; bottom: 0; background: var(--panel); padding: 8px 0; border-top: 1px solid var(--line); align-items: center; }

/* S11：風險頁的自訂壓力測試、管理頁的設定 */
.page-form { display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: flex-end; }
.page-form label { display: flex; flex-direction: column; font-size: 13px; gap: 2px; }
.page-form input { width: 9em; padding: 4px 6px; }
.page-form input[type=date] { width: 11em; }
.admin-settings td { padding: 4px 8px; vertical-align: top; }
.admin-settings input[type=number] { width: 6em; }
.admin-settings tr.group th { text-align: left; padding-top: 10px; }
.small { font-size: 12px; }
