/* 總帳（v1.8）：會計科目、傳票（記帳）、財務報表、會計月結的「入帳到總帳」
   顏色一律用 /assets/base.css 的變數（深色模式才會正確）；手機版面（≤640px）在最下面 */

/* ---------- 共用：科目代號、號碼 ---------- */
.gl-code { display: inline-block; margin-right: 8px; color: var(--muted); font-weight: 500; font-variant-numeric: tabular-nums; }
.gl-mono { font-variant-numeric: tabular-nums; letter-spacing: .01em; }
.gl-pager { display: flex; align-items: center; justify-content: center; gap: 14px; padding: 12px 16px; border-top: 1px solid var(--line-2); }

/* ---------- 科目選擇框（打代號或名稱） ---------- */
.acc-pick { position: relative; min-width: 0; }
.acc-pick > .input { width: 100%; }
.acc-pick-list {
  position: absolute; z-index: 30; top: calc(100% + 4px); left: 0; min-width: 100%; width: max-content; max-width: min(420px, 92vw); max-height: 280px; overflow-y: auto;
  margin: 0; padding: 4px; list-style: none; background: var(--surface); border: 1px solid var(--line-strong); border-radius: 12px; box-shadow: var(--shadow-lg);
}
.acc-pick-list li { display: flex; align-items: baseline; gap: 10px; padding: 7px 10px; border-radius: 8px; font-size: 14px; cursor: pointer; }
.acc-pick-list li.on { background: var(--brand-50); }
.acc-pick-list li:hover { background: var(--hover); }
.acc-pick-list li.on:hover { background: var(--brand-50); }
.acc-pick-list li.off .acc-pick-name { color: var(--muted); }
.acc-pick-code { flex: none; min-width: 3.4em; color: var(--muted); font-variant-numeric: tabular-nums; }
.acc-pick-name { min-width: 0; overflow-wrap: anywhere; }
.acc-pick-none { color: var(--muted); cursor: default !important; }

/* ---------- 會計科目 ---------- */
.gla-table tr.gla-off td.col-main b { color: var(--muted); font-weight: 500; }
.gla-table td.actions { text-align: right; }
.gla-del { padding-left: 8px; padding-right: 8px; }

/* ---------- 傳票清單 ---------- */
.glv-tot { padding: 10px 16px 0; }
.glv-table tr.glv-void td.col-main b { color: var(--muted); font-weight: 500; text-decoration: line-through; }
.glv-table tr.glv-void td.num { color: var(--muted); }
.glv-facc { width: 210px; max-width: 100%; }

/* ---------- 記帳畫面 ---------- */
.glv-top { grid-template-columns: 220px minmax(0, 1fr); margin-bottom: 18px; }
.glv-lines { display: flex; flex-direction: column; }
.glv-line {
  display: grid; grid-template-columns: minmax(170px, 1.3fr) minmax(120px, 1.2fr) minmax(110px, .9fr) 128px 128px 104px; gap: 8px; align-items: center;
  padding: 7px 0; border-bottom: 1px solid var(--line-2);
}
.glv-head { padding: 0 0 6px; font-size: 12.5px; color: var(--muted); border-bottom: 1px solid var(--line); }
.glv-head .num { text-align: right; padding-right: 12px; }
.glv-line .input { width: 100%; min-width: 0; }
.glv-amt { min-width: 0; }
.glv-amt-l { display: none; font-size: 12.5px; color: var(--muted); }
.glv-amt .money-input > .input { text-align: right; }
.glv-line-acts { display: flex; align-items: center; justify-content: flex-end; gap: 2px; min-width: 0; }
.glv-fill { padding-left: 8px; padding-right: 8px; white-space: nowrap; color: var(--brand); }
.glv-add { margin-top: 10px; }
.glv-sum {
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px 22px; margin-top: 14px; padding: 11px 14px; border-radius: 12px; font-size: 14.5px;
  background: var(--line-2); color: var(--ink-2);
}
.glv-sum b { color: var(--ink); font-weight: 600; font-variant-numeric: tabular-nums; }
.glv-sum-st { display: inline-flex; align-items: center; gap: 5px; margin-left: auto; font-weight: 600; }
.glv-sum.ok { background: var(--green-bg); color: var(--green-ink); }
.glv-sum.bad { background: var(--red-bg); color: var(--red-ink); }
.glv-sum.ok b, .glv-sum.bad b { color: inherit; }
.glv-errs { margin: 4px 0 0; padding-left: 20px; }
.glv-foot { display: flex; align-items: center; gap: 10px; padding: 14px 20px; border-top: 1px solid var(--line-2); }
.glv-foot-hint { flex: 1; min-width: 0; }

/* ---------- 財務報表 ---------- */
.glr-print-head { display: none; }
.glr-bar { display: flex; align-items: center; flex-wrap: wrap; gap: 10px 16px; margin-bottom: 16px; }
.glr-period { display: flex; align-items: center; flex-wrap: wrap; gap: 8px 12px; min-width: 0; flex: 1 1 auto; }
.glr-asof { display: inline-flex; align-items: center; gap: 8px; }
.glr-acts { display: flex; align-items: center; gap: 8px; flex: none; margin-left: auto; }
.glr-pick { display: flex; flex-wrap: wrap; gap: 10px 16px; margin-bottom: 16px; }
.glr-pick label { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.glr-pick-acc { flex: 1 1 280px; max-width: 420px; }
.glr-pick-proj { flex: 0 1 240px; }
.glr-busy { opacity: .55; transition: opacity .15s; }
.glr-check { display: inline-flex; align-items: center; gap: 4px; padding: 2px 10px; border-radius: 999px; font-size: 13px; font-weight: 600; white-space: nowrap; }
.glr-check.ok { background: var(--green-bg); color: var(--green); }
.glr-check.bad { background: var(--red-bg); color: var(--red); white-space: normal; }
.glr-check.big { align-self: flex-start; margin-top: 6px; padding: 5px 14px; font-size: 15px; }
.glr-note { margin-left: 8px; font-weight: 400; }

/* 試算表、分類帳 */
.glr-table td.num, .glr-table th.num { white-space: nowrap; }
.glr-table tr.glr-group td { padding-top: 12px; padding-bottom: 6px; font-size: 13px; font-weight: 600; color: var(--brand); background: var(--line-2); }
.glr-table tr.glr-open td { color: var(--ink-2); background: var(--line-2); }
.glr-table tfoot .glr-total td { padding-top: 11px; padding-bottom: 11px; border-top: 2px solid var(--line-strong); line-height: 1.55; }
/* 合計列的「借 X」「貸 X」：電腦上下兩行，手機卡片上排成一行 */
.glr-pair { display: block; }

/* 資產負債表、損益表：一列＝代號、名稱、（百分比）、金額 */
.glr-two { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; align-items: start; }
.glr-is { max-width: 860px; }
.glr-g { margin-bottom: 14px; }
.glr-gh, .glr-row, .glr-subtotal, .glr-grand { display: flex; align-items: baseline; gap: 10px; min-width: 0; }
.glr-gh { padding: 6px 0; font-weight: 600; color: var(--ink); border-bottom: 1px solid var(--line); }
.glr-gh > :first-child, .glr-subtotal > :first-child, .glr-grand > :first-child { flex: 1; min-width: 0; }
.glr-row { padding: 6px 0 6px 10px; font-size: 14.5px; color: var(--ink-2); border-bottom: 1px solid var(--line-2); }
.glr-row:last-child { border-bottom: 0; }
.glr-row .gl-code { flex: none; min-width: 3.6em; margin-right: 0; font-size: 13.5px; }
.glr-name { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.glr-row.contra .glr-name { color: var(--muted); }
.glr-sub { display: block; font-size: 12.5px; font-weight: 400; color: var(--muted); }
.glr .num { text-align: right; font-variant-numeric: tabular-nums; }
.glr-row > .num, .glr-gh > .num, .glr-subtotal > .num, .glr-grand > .num { flex: none; min-width: 7.5em; }
.glr-pct { flex: none; min-width: 4.2em; text-align: right; font-size: 13px; font-weight: 400; color: var(--muted); font-variant-numeric: tabular-nums; }
.glr-part { margin: 4px 0 8px; font-size: 13px; font-weight: 600; color: var(--brand); }
.glr-g + .glr-part, .glr-subtotal + .glr-part { margin-top: 18px; }
.glr-subtotal { margin: 4px 0 14px; padding: 9px 12px; border-radius: 10px; background: var(--line-2); font-weight: 600; color: var(--ink); }
.glr-grand { margin: 4px 0 0; padding: 11px 12px; border-radius: 10px; background: var(--brand-50); font-weight: 700; color: var(--ink); font-size: 15.5px; }
.glr-subtotal.neg > .num, .glr-grand.neg > .num { color: var(--red); }
.glr-none { margin: 6px 0 12px; }

/* ---------- 會計月結：入帳到總帳 ---------- */
.mc-post { display: flex; align-items: center; flex-wrap: wrap; gap: 8px 12px; margin-top: 8px; }
.glp-counts { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 14px; padding: 0; list-style: none; }
.glp-counts li { display: flex; flex-direction: column; gap: 1px; min-width: 96px; padding: 9px 14px; border-radius: 12px; background: var(--line-2); font-size: 13px; color: var(--ink-2); }
.glp-counts li b { font-size: 20px; font-weight: 600; color: var(--ink); font-variant-numeric: tabular-nums; line-height: 1.3; }
.glp-counts li.on { background: var(--brand-50); }
.glp-counts li.on b { color: var(--brand); }
.glp-sec { margin-top: 16px; }
.glp-sec > h4 { display: flex; align-items: center; flex-wrap: wrap; gap: 6px 10px; margin: 0 0 6px; font-size: 14.5px; }
.glp-sec > p { margin: 0 0 8px; font-size: 13.5px; color: var(--ink-2); line-height: 1.6; }
.glp-list { margin: 0; padding: 0; list-style: none; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.glp-list li { display: flex; align-items: flex-start; gap: 10px; padding: 9px 12px; font-size: 13.5px; line-height: 1.55; border-bottom: 1px solid var(--line-2); }
.glp-list li:last-child { border-bottom: 0; }
.glp-list label { display: flex; align-items: flex-start; gap: 10px; flex: 1; min-width: 0; cursor: pointer; }
.glp-list input[type="checkbox"] { flex: none; margin-top: 3px; }
.glp-it { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.glp-it small { display: block; color: var(--muted); font-size: 12.5px; }
.glp-it small.bad { color: var(--red); }
.glp-amt { flex: none; font-variant-numeric: tabular-nums; color: var(--ink-2); }
.glp-all { font: inherit; font-size: 13px; font-weight: 400; color: var(--brand); background: none; border: 0; padding: 0; cursor: pointer; }
.glp-all:hover { text-decoration: underline; }
.glp-done { display: flex; align-items: flex-start; gap: 8px; }
.glp-done svg { flex: none; margin-top: 3px; }

/* ---------- 手機（≤640px） ---------- */
@media (max-width: 860px) {
  .glr-two { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 760px) {
  /* 記帳：每一行分錄變成一張小卡——科目、摘要、專案各佔一行，借方與貸方並排 */
  .glv-top { grid-template-columns: minmax(0, 1fr); }
  .glv-head { display: none; }
  .glv-line {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 8px; padding: 12px; margin-bottom: 10px;
    border: 1px solid var(--line); border-radius: 12px; background: var(--surface);
  }
  .glv-line > .glv-acc, .glv-line > .glv-memo, .glv-line > .glv-proj, .glv-line > .glv-line-acts { grid-column: 1 / -1; }
  .glv-amt-l { display: block; margin-bottom: 3px; }
  .glv-line-acts { justify-content: space-between; }
  .glv-line-acts > .icon-btn { margin-left: auto; }
  .glv-sum-st { margin-left: 0; flex-basis: 100%; }
  .glv-foot { flex-wrap: wrap; padding: 12px 16px; }
  .glv-foot-hint { flex-basis: 100%; }
  .glv-foot .btn { flex: 1; min-height: 44px; }
}
/* 手機記帳（v1.10）：傳票表單的借貸狀態與儲存鈕固定在畫面下方，填到哪一行都看得到差多少、隨時能存 */
.glv-foot-bal { display: none; }
@media (max-width: 640px) {
  .glv-foot { position: sticky; bottom: 0; z-index: 6; flex-wrap: wrap; gap: 8px; padding: 10px 14px calc(10px + env(safe-area-inset-bottom)); background: var(--card); box-shadow: 0 -8px 18px -14px rgba(15, 23, 42, 0.45); }
  .glv-foot-hint { display: none; }
  .glv-foot-bal { display: inline-flex; flex: 1 1 100%; align-items: center; font-weight: 600; font-variant-numeric: tabular-nums; }
  .glv-foot-bal.ok { color: var(--green-ink); }
  .glv-foot-bal.bad { color: var(--red-ink); }
  .glv-foot .btn { flex: 1; min-height: 44px; }
  .acc-pick-list { width: auto; right: 0; max-width: none; max-height: 240px; }
  .acc-pick-list li { padding: 10px; }
  .glv-facc { width: 100%; }
  .gl-pager .btn { min-height: 40px; }
  .glr-bar { align-items: stretch; }
  .glr-period { flex-direction: column; align-items: stretch; }
  .glr-period .dr-presets { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .glr-period .dr-fields { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); }
  .glr-period .dr-fields .date-field { min-width: 0; }
  .glr-asof { justify-content: space-between; }
  .glr-acts { margin-left: 0; width: 100%; }
  .glr-acts .btn { flex: 1; min-height: 40px; }
  .glr-pick-acc, .glr-pick-proj { flex: 1 1 100%; max-width: none; }
  .glr-row { padding-left: 0; font-size: 14px; }
  .glr-row > .num, .glr-gh > .num, .glr-subtotal > .num, .glr-grand > .num { min-width: 0; }
  .glr-pct { min-width: 3.4em; }
  .glr-row .gl-code { min-width: 3.2em; }
  .glr-pair { display: inline; }
  .glr-pair + .glr-pair { margin-left: 10px; }
  .glp-counts li { flex: 1 1 calc(33% - 8px); min-width: 0; }
  .mc-post .btn { min-height: 44px; }
}

/* =========================================================================
   列印／另存 PDF：只印報表——A4 直向、卡片不要陰影；側邊欄、頂端列、頁籤、期間選擇與按鈕都不印
   （只有財務報表頁有 .glr，其他頁面列印不受影響）
   ========================================================================= */
@page glreport { size: A4 portrait; margin: 13mm 12mm 14mm; }
@media print {
  body:has(.glr) { background: var(--card); }
  body:has(.glr) .layout { display: block; min-height: 0; zoom: 1 !important; }
  body:has(.glr) .layout > .main { display: block; }
  body:has(.glr) :is(.side, .side-mask, .topbar, .acct-banner, .demo-banner, #toast-box) { display: none !important; }
  body:has(.glr) .content { padding: 0; max-width: none; }
  body:has(.glr) .content > * { animation: none !important; }
  .glr { page: glreport; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .glr-print-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin: 0 0 14px; padding: 0 0 9px; border-bottom: 1.5px solid var(--ink); }
  .glr-ph-l { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
  .glr-ph-l b { font-size: 12.5px; font-weight: 500; color: var(--ink-2); }
  .glr-ph-l span { font-size: 19px; font-weight: 700; color: var(--ink); letter-spacing: .02em; }
  .glr-ph-r { display: flex; flex-direction: column; align-items: flex-end; gap: 1px; font-size: 12px; color: var(--ink-2); text-align: right; }
  .glr :is(.glr-bar, .glr-pick, .glr-foot, .btn) { display: none !important; }
  .glr .card { box-shadow: none; border-color: var(--line-strong); break-inside: avoid; }
  .glr .card:has(.table-wrap), .glr .glr-col, .glr .glr-is { break-inside: auto; }
  .glr .card-h { break-after: avoid; padding: 10px 14px; }
  .glr .card-b { padding: 10px 14px; }
  .glr .table tr, .glr .glr-row, .glr .glr-gh, .glr .glr-subtotal, .glr .glr-grand { break-inside: avoid; }
  .glr .table-wrap { overflow: visible !important; background: none !important; }
  .glr .table-wrap > .table { min-width: 0 !important; }
  .glr .table { font-size: 12px; }
  .glr .table th, .glr .table td { padding: 5px 8px; }
  .glr .table a { color: inherit; text-decoration: none; }
  .glr .grid.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)) !important; gap: 8px; }
  .glr .stat { padding: 9px 12px; }
  .glr .stat .value { font-size: 17px; }
  .glr .glr-two { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .glr .glr-row { padding-top: 3px; padding-bottom: 3px; font-size: 12.5px; }
  .glr .glr-is { max-width: none; }
  .glr .mb { margin-bottom: 10px; }
  .glr-busy { opacity: 1; }
}
