/* 800伴帳單生成器: tool chrome.
 * Shape system: every box is square (radius 0), matching the invoice hairlines.
 * One accent (--accent) for every interactive affordance. Paper is always white.
 */

:root {
  color-scheme: light;
  --bg: #f3f4f6;
  --surface: #ffffff;
  --ink: #14161a;
  --muted: #5c626d;
  --line: #d5d8dd;
  --line-strong: #14161a;
  --accent: #1f4fd8;
  --accent-on: #ffffff;
  --accent-soft: #e8edfc;
  --danger: #a4271f;
  --danger-soft: #fbecea;
  --ui: 'Noto Sans TC', 'PingFang TC', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  --mono: ui-monospace, 'SF Mono', 'JetBrains Mono', Menlo, Consolas, monospace;
  --shadow: 0 1px 2px rgba(20, 22, 26, .06), 0 12px 32px rgba(20, 22, 26, .08);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #101114;
    --surface: #191b1f;
    --ink: #eceef2;
    --muted: #9aa1ad;
    --line: #2b2e34;
    --line-strong: #6e7581;
    --accent: #7c9cff;
    --accent-on: #0d1016;
    --accent-soft: #1d2434;
    --danger: #ff9a90;
    --danger-soft: #2a1a18;
    --shadow: 0 1px 2px rgba(0, 0, 0, .5), 0 16px 40px rgba(0, 0, 0, .45);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #101114;
  --surface: #191b1f;
  --ink: #eceef2;
  --muted: #9aa1ad;
  --line: #2b2e34;
  --line-strong: #6e7581;
  --accent: #7c9cff;
  --accent-on: #0d1016;
  --accent-soft: #1d2434;
  --danger: #ff9a90;
  --danger-soft: #2a1a18;
  --shadow: 0 1px 2px rgba(0, 0, 0, .5), 0 16px 40px rgba(0, 0, 0, .45);
}

* { box-sizing: border-box; }

/* Beats the display:flex/grid on .file-info and .pager, which would otherwise
   win over the user agent's [hidden] rule. */
[hidden] { display: none !important; }

html, body { margin: 0; }

body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--ui);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.num { font-family: var(--mono); font-variant-numeric: tabular-nums; }

/* ---------- top bar ---------- */

.topbar {
  display: flex; align-items: center; gap: 16px;
  height: 72px; padding: 0 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

/* The lockup is black ink on transparency, so dark mode flips it to white. */
.brand { height: 26px; width: auto; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .brand { filter: invert(1); } }
:root[data-theme="dark"] .brand { filter: invert(1); }

.topbar-text { display: flex; align-items: baseline; gap: 12px; min-width: 0; }
.topbar h1 { margin: 0; font-size: 16px; font-weight: 700; letter-spacing: -.01em; }
.topbar p { margin: 0; color: var(--muted); font-size: 13px; }

@media (max-width: 640px) {
  .topbar { height: auto; padding: 14px 16px; }
  .topbar-text { flex-direction: column; gap: 2px; }
}

/* ---------- layout ---------- */

/* Above 900px the two columns scroll independently, so the sheet stays put
   while the month list is scrolled. Below that it is one ordinary page. */
.layout {
  display: grid;
  grid-template-columns: 400px minmax(0, 1fr);
  gap: 1px;
  background: var(--line);
  height: calc(100dvh - 72px);
  overflow: hidden;
}
.panel { background: var(--surface); padding: 4px 20px 32px; overflow-y: auto; }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; height: auto; overflow: visible; }
  .panel { overflow-y: visible; }
}
.stage { background: var(--bg); display: flex; flex-direction: column; min-width: 0; overflow: hidden; }

/* ---------- panel blocks ---------- */

.block { padding: 20px 0; border-bottom: 1px solid var(--line); }
.block:last-child { border-bottom: 0; }

.block-head {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 12px; margin-bottom: 12px;
}
.block-head h3 { margin: 0; font-size: 13px; font-weight: 700; letter-spacing: .01em; }
.block-actions { display: flex; gap: 12px; }

.link-btn {
  border: 0; background: none; padding: 0;
  color: var(--accent); font: inherit; font-size: 12px; cursor: pointer;
  text-underline-offset: 3px;
}
.link-btn:hover { text-decoration: underline; }

/* ---------- drop zone ---------- */

.drop {
  border: 1px dashed var(--line-strong);
  padding: 22px 16px; text-align: center; cursor: pointer;
  background: transparent; transition: background .12s ease, border-color .12s ease;
}
.drop:hover, .drop.is-over { background: var(--accent-soft); border-color: var(--accent); }
.drop-title { margin: 0 0 4px; font-size: 13px; font-weight: 600; }
.drop-hint { margin: 0; font-size: 12px; color: var(--muted); }

.file-info {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; border: 1px solid var(--line); padding: 10px 12px;
}
.file-name { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.notice {
  margin-top: 12px; padding: 10px 12px; font-size: 12px; line-height: 1.55;
  background: var(--accent-soft); border-left: 2px solid var(--accent); color: var(--ink);
}
.notice.is-error { background: var(--danger-soft); border-left-color: var(--danger); color: var(--danger); }
.notice ul { margin: 4px 0 0; padding-left: 16px; }

/* ---------- fields ---------- */

.field-grid { display: grid; gap: 14px; }
.field { display: grid; gap: 6px; margin: 0; }
.field label { font-size: 12px; font-weight: 600; color: var(--muted); }
.field .hint { font-size: 11px; color: var(--muted); font-family: var(--mono); }

input[type="text"], input[type="date"] {
  width: 100%; padding: 8px 10px; font: inherit; font-size: 13px;
  color: var(--ink); background: var(--surface);
  border: 1px solid var(--line-strong); border-radius: 0;
}
input::placeholder { color: var(--muted); }

:where(input, button, [tabindex]):focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}

/* ---------- months ---------- */

.months { width: 100%; border-collapse: collapse; font-size: 13px; }
.months th {
  text-align: left; font-size: 11px; font-weight: 600; color: var(--muted);
  padding: 0 0 6px; border-bottom: 1px solid var(--line);
}
.months th.num, .months td.num { text-align: right; }
.months td { padding: 7px 0; border-bottom: 1px solid var(--line); }
.months .c-check { width: 26px; }
.months input[type="checkbox"] { width: 15px; height: 15px; accent-color: var(--accent); }
.months tr.is-off td:not(.c-check) { color: var(--muted); }
.months .src { display: block; font-size: 10px; color: var(--muted); }

.months-sum {
  display: flex; justify-content: space-between; gap: 12px;
  margin: 10px 0 0; font-size: 13px; font-weight: 700;
}

/* ---------- actions ---------- */

.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.btn {
  padding: 11px 14px; font: inherit; font-size: 13px; font-weight: 700;
  color: var(--ink); background: var(--surface);
  border: 1px solid var(--line-strong); border-radius: 0; cursor: pointer;
  transition: background .12s ease, color .12s ease;
}
.btn:hover { background: var(--accent-soft); }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-on); }
.btn-primary:hover { background: var(--accent); filter: brightness(1.08); }
.btn[disabled] { opacity: .45; cursor: not-allowed; }
.hint { margin: 10px 0 0; font-size: 11px; color: var(--muted); line-height: 1.5; }

/* ---------- stage ---------- */

.stage-bar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 12px 20px; background: var(--surface); border-bottom: 1px solid var(--line);
}
.tabs { display: flex; gap: 0; }
.tab {
  padding: 7px 14px; font: inherit; font-size: 12px; font-weight: 700;
  color: var(--muted); background: transparent; cursor: pointer;
  border: 1px solid var(--line); border-right-width: 0; border-radius: 0;
}
.tab:last-child { border-right-width: 1px; }
.tab.is-on { color: var(--accent-on); background: var(--accent); border-color: var(--accent); }

.pager { display: flex; align-items: center; gap: 8px; }
.icon-btn {
  width: 28px; height: 28px; line-height: 1; font-size: 16px;
  color: var(--ink); background: var(--surface);
  border: 1px solid var(--line-strong); border-radius: 0; cursor: pointer;
}
.icon-btn[disabled] { opacity: .35; cursor: not-allowed; }
.page-label { font-size: 12px; color: var(--muted); min-width: 48px; text-align: center; }

.stage-body { flex: 1; overflow: auto; padding: 24px; display: flex; justify-content: center; }

.empty { margin: auto; text-align: center; max-width: 320px; }
.empty-title { margin: 0 0 6px; font-size: 14px; font-weight: 700; }
.empty-body { margin: 0; font-size: 13px; color: var(--muted); }

/* A4 is 1:1.4142, so the widest the sheet can be and still fit the stage
   height is (available height) x 0.7071. */
.paper {
  width: min(100%, 640px, calc((100dvh - 200px) * 0.7071));
  height: fit-content;
  background: #fff; box-shadow: var(--shadow);
}
@media (max-width: 900px) {
  .paper { width: min(100%, 640px); }
}
.paper svg { display: block; width: 100%; height: auto; }

/* ---------- print ---------- */

#print-root { display: none; }
.print-page { width: 595.276pt; height: 841.89pt; overflow: hidden; background: #fff; }
.print-page svg { display: block; width: 595.276pt; height: 841.89pt; }

@page { size: A4; margin: 0; }

@media print {
  html, body { background: #fff; margin: 0; padding: 0; }
  body > *:not(#print-root) { display: none !important; }
  #print-root { display: block; }
  .print-page { break-after: page; page-break-after: always; break-inside: avoid; }
  .print-page:last-child { break-after: auto; page-break-after: auto; }
}
