/* Two layers share this file.

   The interface around the sheets (header, toolbar, tabs, dialogs) wears the
   look of tudoulab.com: its dark and light palettes, pill-shaped controls,
   monospace labels. Dark is the default; src/theme.js applies a saved choice.

   The sheets themselves are paper. They look the same in both themes and print
   the same as they always have: nothing in the print rules or in the rules for
   what is printed depends on the theme. Anything new that could reach a
   printed element is kept inside "@media screen". */

:root {
  color-scheme: light;

  /* Paper: the sheets, in both themes and in print. */
  --ink: #15231f;
  --muted: #64746e;
  --line: #d9e2de;
  --paper: #fffefa;
  --canvas: #eef3f0;
  --green: #2f6b0f;
  --green-soft: #e6f3d8;
  --red: #a83333;
  --red-soft: #fff0ef;
  --gold: #c7953d;

  /* Interface, dark. The same values as tudoulab.com. */
  --ui-bg: #101411;
  --ui-surface: #19211b;
  --ui-surface-2: #202a22;
  --ui-field: #101411;
  --ui-ink: #ecf3ee;
  --ui-muted: #9daca2;
  --ui-line: #2a372d;
  --ui-accent: #b8f36a;
  --ui-on-accent: #10160c;
  --ui-accent-text: #b8f36a;
  --ui-accent-soft: rgb(184 243 106 / 0.1);
  --ui-warn: #f0d37a;
  --ui-warn-soft: rgb(240 211 122 / 0.12);
  --ui-danger: #ff9d8f;
  --ui-danger-soft: rgb(255 157 143 / 0.12);
  --ui-dot: rgb(236 243 238 / 0.07);
  --ui-glow: rgb(184 243 106 / 0.22);
  --ui-glow-2: rgb(111 227 214 / 0.16);
  --ui-shadow: rgb(0 0 0 / 0.45);
  --font-sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
  --font-mono: ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
}

[data-theme="light"] {
  --ui-bg: #eef2ea;
  --ui-surface: #fbfcf9;
  --ui-surface-2: #e4eadf;
  --ui-field: #ffffff;
  --ui-ink: #121a14;
  --ui-muted: #4d5a51;
  --ui-line: #cbd5c8;
  --ui-accent-text: #2f6b0f;
  --ui-accent-soft: rgb(120 190 40 / 0.16);
  --ui-warn: #7a5a12;
  --ui-warn-soft: rgb(199 149 61 / 0.16);
  --ui-danger: #b3261e;
  --ui-danger-soft: rgb(179 38 30 / 0.1);
  --ui-dot: rgb(18 26 20 / 0.09);
  --ui-glow: rgb(120 190 40 / 0.14);
  --ui-glow-2: rgb(11 111 102 / 0.1);
  --ui-shadow: rgb(23 46 37 / 0.12);
}

/* On a sheet, and in the list that drops down from one of its cells, the
   controls are drawn for paper whatever the theme around it. */
.report-panel, .suggestions {
  --ui-surface: #ffffff;
  --ui-surface-2: #f1f4ee;
  --ui-field: #ffffff;
  --ui-ink: var(--ink);
  --ui-muted: var(--muted);
  --ui-line: var(--line);
  --ui-accent-text: var(--green);
  --ui-accent-soft: var(--green-soft);
  --ui-danger: var(--red);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  color: var(--ink);
  background: var(--canvas);
  font-family: "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
}

.masthead,
.intro,
main {
  width: min(1460px, calc(100% - 32px));
  margin-inline: auto;
}

@media screen {
  :root:not([data-theme="light"]) { color-scheme: dark; }
  .report-panel, .suggestions { color-scheme: light; color: var(--ink); }

  body {
    position: relative;
    min-height: 100vh;
    color: var(--ui-ink);
    background-color: var(--ui-bg);
    background-image: radial-gradient(var(--ui-dot) 1px, transparent 1px);
    background-size: 22px 22px;
    font-family: var(--font-sans);
    -webkit-font-smoothing: antialiased;
  }
  /* The glow at the top of the page, as on the homepage's first screen. */
  body::before {
    content: "";
    position: absolute;
    inset: 0 0 auto;
    height: 420px;
    background:
      radial-gradient(60% 55% at 18% 0%, var(--ui-glow), transparent 70%),
      radial-gradient(45% 45% at 88% 8%, var(--ui-glow-2), transparent 70%);
    pointer-events: none;
  }
  .masthead, .intro, main { position: relative; }
}

:focus-visible { outline: 2px solid var(--ui-accent-text); outline-offset: 2px; }
.label { font-family: var(--font-mono); font-size: 11px; letter-spacing: 0.14em; text-transform: uppercase; }

/* Header: the same floating pill as tudoulab.com. */
.masthead { padding-top: 12px; }
.masthead-bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; height: 48px; padding: 0 6px 0 16px; border: 1px solid var(--ui-line); border-radius: 9999px; background: color-mix(in srgb, var(--ui-surface) 80%, transparent); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); }
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; color: inherit; text-decoration: none; }
.brand-name { font-weight: 600; letter-spacing: -0.015em; white-space: nowrap; }
.brand-zh { color: var(--ui-muted); letter-spacing: 0.08em; white-space: nowrap; }
.masthead-tools { display: flex; align-items: center; gap: 6px; }
.masthead-link { display: flex; align-items: center; height: 34px; padding: 0 14px; border: 1px solid var(--ui-line); border-radius: 9999px; color: inherit; font-size: 13px; font-weight: 500; text-decoration: none; white-space: nowrap; }
.masthead-link:hover { background: var(--ui-surface-2); }
.icon-button { display: grid; place-items: center; width: 34px; height: 34px; padding: 0; }
[data-theme="light"] .icon-button .sun, :root:not([data-theme="light"]) .icon-button .moon { display: none; }

.intro { display: flex; align-items: flex-end; justify-content: space-between; flex-wrap: wrap; gap: 14px 24px; padding: 40px 4px 22px; }
.intro-label { display: flex; align-items: center; gap: 8px; margin: 0; color: var(--ui-accent-text); }
.intro-label .square { width: 8px; height: 8px; background: var(--ui-accent); }
.intro-label .slash { color: var(--ui-muted); }
h1 { margin: 14px 0 0; font-size: clamp(2rem, 4.4vw, 2.9rem); font-weight: 600; line-height: 1.15; letter-spacing: -0.025em; }
.subtitle { margin: 10px 0 0; color: var(--ui-muted); font-size: 16px; }
.privacy-pill { display: flex; align-items: center; gap: 8px; margin: 0; padding: 7px 13px; border: 1px solid var(--ui-line); border-radius: 9999px; color: var(--ui-accent-text); font-size: 13px; font-weight: 500; }
.privacy-pill .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

.toolbar {
  display: grid;
  grid-template-columns: minmax(210px, 1fr) minmax(210px, 1fr) 170px auto;
  gap: 14px 16px;
  align-items: end;
  padding: 20px;
  border: 1px solid var(--ui-line);
  border-radius: 20px;
  background: var(--ui-surface);
}

label span { display: block; margin-bottom: 7px; color: var(--ui-muted); font-size: 12px; font-weight: 700; }
input, button { font: inherit; }
.toolbar input, .toolbar select { width: 100%; height: 42px; padding: 0 14px; border: 1px solid var(--ui-line); border-radius: 9999px; background: var(--ui-field); color: var(--ui-ink); }
.actions { display: flex; flex-wrap: wrap; gap: 8px; justify-self: end; }
button { border: 1px solid var(--ui-line); border-radius: 9999px; background: var(--ui-surface); color: var(--ui-ink); padding: 9px 16px; cursor: pointer; font-weight: 600; transition: transform 160ms, border-color 160ms, color 160ms, background-color 160ms; }
button:hover { border-color: var(--ui-accent-text); color: var(--ui-accent-text); }
button.primary { border-color: var(--ui-accent); background: var(--ui-accent); color: var(--ui-on-accent); }
button.primary:hover { color: var(--ui-on-accent); transform: translateY(-1px); }
.save-status { grid-column: 1 / -1; margin: 0; color: var(--ui-muted); font-size: 12px; }
.print-hint { grid-column: 1 / -1; margin: -6px 0 0; color: var(--ui-muted); font-size: 12px; }
.print-hint + .print-hint { margin-top: -10px; }

.notice {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 12px;
  padding: 11px 15px;
  border: 1px solid color-mix(in srgb, var(--ui-accent-text) 30%, var(--ui-line));
  border-radius: 14px;
  background: var(--ui-accent-soft);
  color: var(--ui-ink);
  font-size: 13px;
  font-weight: 500;
  line-height: 1.5;
}
.notice.warn { border-color: color-mix(in srgb, var(--ui-warn) 40%, var(--ui-line)); background: var(--ui-warn-soft); color: var(--ui-warn); }
.notice.error { border-color: color-mix(in srgb, var(--ui-danger) 40%, var(--ui-line)); background: var(--ui-danger-soft); color: var(--ui-danger); }
.notice button { margin-left: auto; flex: none; padding: 6px 12px; font-size: 12px; }

.tabs { display: flex; gap: 4px; width: fit-content; max-width: 100%; margin: 24px 0 14px; padding: 4px; border: 1px solid var(--ui-line); border-radius: 9999px; background: var(--ui-surface); }
.tab { border: 0; background: transparent; color: var(--ui-muted); padding: 8px 18px; white-space: nowrap; }
.tab:hover { color: var(--ui-ink); }
.tab.active, .tab.active:hover { background: var(--ui-ink); color: var(--ui-bg); }

.report-panel {
  display: none;
  margin-bottom: 40px;
  padding: 34px 30px 30px;
  background: var(--paper);
  border-radius: 5px;
  box-shadow: 0 18px 50px var(--ui-shadow);
}
.report-panel.active { display: block; }
.report-heading { position: relative; text-align: center; }
.report-heading h2 { margin: 0 0 25px; font-family: SimSun, STSong, serif; font-size: 31px; letter-spacing: .24em; }
.report-heading.compact h2 { margin-bottom: 28px; }
.report-code { position: absolute; right: 0; top: 32px; margin: 0; font-family: SimSun, STSong, serif; }
.report-meta { display: flex; justify-content: space-between; margin-bottom: 4px; font-family: SimSun, STSong, serif; font-size: 15px; }

.balance-check { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 15px 0; }
.check-item { display: flex; justify-content: space-between; gap: 14px; padding: 10px 12px; border-radius: 10px; background: var(--green-soft); color: var(--green); font-size: 13px; font-weight: 700; }
.check-item.bad { background: var(--red-soft); color: var(--red); }

.table-wrap { overflow-x: auto; }
.report-table { width: 100%; border-collapse: collapse; table-layout: fixed; font-family: SimSun, STSong, serif; }
.report-table th, .report-table td { border: 1px solid #7f8985; padding: 3px 5px; }
.report-table th { background: #f4f6f4; font-weight: 600; text-align: center; }
.report-table th.spaced { white-space: pre; }
.balance-table th:nth-child(1), .balance-table th:nth-child(5) { width: 17%; }
.balance-table th:nth-child(2), .balance-table th:nth-child(6) { width: 4.3%; }
.balance-table th:nth-child(3), .balance-table th:nth-child(4), .balance-table th:nth-child(7), .balance-table th:nth-child(8) { width: 14.35%; }
.balance-table { min-width: 1120px; }
.profit-table { min-width: 620px; }

/* On screen the label column needs a little more room than the printed proportions give it,
   or the longest legacy line items run under the line-number column. Print keeps its own widths. */
@media screen {
  .balance-table th:nth-child(1), .balance-table th:nth-child(5) { width: 19.6%; }
  .balance-table th:nth-child(3), .balance-table th:nth-child(4),
  .balance-table th:nth-child(7), .balance-table th:nth-child(8) { width: 13.05%; }
}
.profit-wrap { max-width: 900px; margin-inline: auto; }
.profit-table th:first-child { width: 46%; }
.profit-table th.line-col { width: 8%; }
.report-table td.label-cell { white-space: nowrap; }
.report-table tr.section-row td { background: #f5f7f5; font-weight: 700; }
.report-table tr.total-row td { background: #f0f5f2; font-weight: 700; }
.line-cell { text-align: center; color: #53615c; }
.amount-cell { padding: 0 !important; text-align: right; }
.amount-input { width: 100%; min-width: 90px; border: 0; background: #fffdf5; color: var(--ink); padding: 5px 6px; text-align: right; outline: none; }
.amount-input:focus { background: #fff3c9; box-shadow: inset 0 0 0 2px var(--gold); }
.amount-input.invalid { background: var(--red-soft); box-shadow: inset 0 0 0 2px var(--red); }
.computed { display: block; min-height: 27px; padding: 5px 6px; background: #edf4f0; font-weight: 700; }
.empty-cell { background: #fafbf9; }

@media (max-width: 1180px) {
  .toolbar { grid-template-columns: 1fr 1fr; }
  .actions { grid-column: 1 / -1; justify-self: start; }
  .report-panel { padding-inline: 14px; }
}

@media (max-width: 640px) {
  .toolbar { grid-template-columns: 1fr; }
  .brand-zh { display: none; }
  .intro { padding-top: 30px; }
}

@page { size: A4 portrait; margin: 9mm; }

/* Chrome and Edge print their own header and footer (the time, the address) in
   the page's top and bottom margins, and leave them out when a page has none.
   So a sheet that fits on one page goes on a page without those margins and
   brings the 9 mm itself (.one-page, below): the paper comes out the same,
   minus the header and footer.

   A sheet too long for one page keeps the ordinary page above. Without margins
   its rows would run to the very edge of the paper, where printers cannot
   print. Only a voucher can get that long; app.js takes .one-page off it then. */
@page sheet { size: A4 portrait; margin: 0 9mm; }

@media print {
  body { background: white; color: black; }
  .no-print { display: none !important; }
  main { width: auto; margin: 0; }
  .report-panel { display: none !important; margin: 0; padding: 0; box-shadow: none; }
  /* 9 mm above and below, in place of the page margin. The paper colour stays
     inside the sheet as before; it does not spread into that space. */
  .report-panel.one-page { page: sheet; padding: 9mm 0; background-clip: content-box; }
  .report-panel.active { display: block !important; }
  /* 打印两表 means the two reports, not whichever other panel happens to exist. */
  body.print-all #balance-panel, body.print-all #profit-panel { display: block !important; }
  body.print-all #voucher-panel { display: none !important; }
  body.print-all #profit-panel { break-before: page; page-break-before: always; }
  .report-heading h2 { margin-bottom: 18px; font-size: 22px; }
  .report-code { top: 23px; font-size: 10px; }
  .report-meta { font-size: 10px; }
  .report-table { font-size: 8px; }
  .report-table th, .report-table td { padding: 1px 3px; height: 16px; border-color: #000; }
  .report-table th, .report-table tr.section-row td, .report-table tr.total-row td { background: white !important; }
  .amount-input { padding: 0; min-width: 0; background: white; font-size: 8px; }
  .computed { min-height: 0; padding: 0; background: white; }
  .profit-wrap { max-width: 160mm; }
  .balance-table, .profit-table { min-width: 0; }
}


/* --- vouchers -------------------------------------------------------------- */

.voucher-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px; margin-bottom: 18px; }
.voucher-actions, .voucher-browse { display: flex; gap: 8px; align-items: center; }
.voucher-browse select { height: 38px; max-width: 320px; padding: 0 10px; border: 1px solid var(--line); border-radius: 10px; background: white; color: var(--ink); }
.voucher-browse button { padding: 8px 13px; font-size: 15px; line-height: 1; }
.voucher-state { margin: 0 0 0 auto; font-size: 13px; font-weight: 700; color: var(--muted); }
.voucher-state.good { color: var(--green); }
.voucher-state.bad { color: var(--red); }

.voucher-sheet { max-width: 940px; margin-inline: auto; }
.voucher-sheet h2 { margin: 0 0 18px; font-family: SimSun, STSong, serif; font-size: 27px; letter-spacing: .2em; text-align: center; }
.voucher-head { display: flex; flex-wrap: wrap; gap: 10px 22px; margin-bottom: 10px; font-family: SimSun, STSong, serif; }
.voucher-head label { display: flex; align-items: center; gap: 7px; }
.voucher-head span { margin: 0; color: var(--ink); font-size: 14px; font-weight: 400; }
.voucher-head input, .voucher-head select { height: 32px; padding: 0 8px; border: 1px solid var(--line); border-radius: 8px; background: white; color: var(--ink); font: inherit; }
.voucher-head #voucher-number { width: 96px; }
.voucher-head #voucher-attachments { width: 64px; }

.voucher-table th:nth-child(1) { width: 5%; }
.voucher-table th:nth-child(2) { width: 27%; }
.voucher-table th:nth-child(3) { width: 30%; }
.voucher-table th:nth-child(4), .voucher-table th:nth-child(5) { width: 16%; }
.voucher-table th.row-tools, .voucher-table td.row-tools { width: 6%; border: 0; background: transparent; }
.voucher-table td { padding: 0; height: 30px; }
.voucher-table td.line-cell { padding: 3px 5px; }
.voucher-table tfoot td { padding: 4px 6px; background: #f0f5f2; font-weight: 700; }
.voucher-table tfoot #voucher-words { font-family: SimSun, STSong, serif; }

.sheet-input { width: 100%; border: 0; background: transparent; color: var(--ink); padding: 5px 6px; font: inherit; outline: none; }
.sheet-input:focus { background: #fff3c9; box-shadow: inset 0 0 0 2px var(--gold); }
.sheet-input.invalid { background: var(--red-soft); box-shadow: inset 0 0 0 2px var(--red); }
.voucher-table .amount-cell .sheet-input { text-align: right; }

.account-cell { position: relative; }
.account-cell .sheet-input { padding-right: 26px; }
.browse-account {
  position: absolute; top: 50%; right: 3px; transform: translateY(-50%);
  padding: 2px 6px; border-radius: 6px; font-size: 13px; line-height: 1.2; font-weight: 700; color: var(--muted);
}
.row-remove { padding: 2px 8px; border-color: transparent; background: transparent; color: var(--muted); font-size: 16px; line-height: 1.1; }
.row-remove:hover { border-color: var(--red); color: var(--red); }

.suggestions {
  position: absolute; z-index: 40; max-height: 240px; overflow-y: auto;
  margin: 2px 0 0; padding: 4px; list-style: none;
  border: 1px solid var(--line); border-radius: 10px; background: white;
  box-shadow: 0 14px 34px rgba(23, 46, 37, .16);
}
.suggestions li { padding: 6px 10px; border-radius: 7px; font-size: 14px; white-space: nowrap; cursor: pointer; }
.suggestions li.active, .suggestions li:hover { background: var(--green-soft); color: var(--green); }

.voucher-signoff { display: flex; flex-wrap: wrap; gap: 12px 40px; margin-top: 16px; font-family: SimSun, STSong, serif; font-size: 14px; }

#account-picker { width: min(560px, 92vw); padding: 0; border: 1px solid var(--ui-line); border-radius: 20px; background: var(--ui-surface); color: var(--ui-ink); box-shadow: 0 30px 70px rgb(0 0 0 / 0.4); }
#account-picker::backdrop { background: rgb(8 12 9 / 0.55); }
.picker { display: flex; flex-direction: column; gap: 12px; padding: 18px; }
.picker header { display: flex; flex-direction: column; gap: 10px; }
.picker h3 { margin: 0; font-size: 17px; }
.picker input[type="search"] { height: 40px; padding: 0 14px; border: 1px solid var(--ui-line); border-radius: 9999px; background: var(--ui-field); color: var(--ui-ink); font: inherit; }
.picker-categories { display: flex; flex-wrap: wrap; gap: 6px; }
.picker-categories button { padding: 6px 12px; font-size: 13px; }
.picker-categories button.active, .picker-categories button.active:hover { border-color: var(--ui-ink); background: var(--ui-ink); color: var(--ui-bg); }
.picker-list { max-height: 46vh; overflow-y: auto; margin: 0; padding: 4px; list-style: none; border: 1px solid var(--ui-line); border-radius: 14px; }
.picker-list li { padding: 7px 10px; border-radius: 9px; font-size: 14px; cursor: pointer; }
.picker-list li:hover { background: var(--ui-accent-soft); }
.picker-list li.active, .picker-list li.active:hover { background: var(--ui-ink); color: var(--ui-bg); }
.picker-list li.empty { color: var(--ui-muted); cursor: default; }
.picker-list li.empty:hover { background: transparent; }
.picker footer { display: flex; justify-content: flex-end; gap: 8px; }

@media print {
  .voucher-sheet h2 { font-size: 20px; margin-bottom: 12px; }
  .voucher-head { font-size: 11px; gap: 6px 18px; }
  .voucher-head input, .voucher-head select { border: 0; height: auto; padding: 0; }
  /* On paper the choice is just text: no arrow after it, no calendar beside the date. */
  .voucher-head select { appearance: none; -webkit-appearance: none; }
  .voucher-head input[type="date"]::-webkit-calendar-picker-indicator { display: none; }
  /* The calendar icon was what made this line 15px tall. Keep it that tall, so
     the table below stays exactly where it has always been printed. */
  .voucher-head label { min-height: 15px; }
  .voucher-table td { height: 20px; }
  .sheet-input { padding: 0; font-size: 9px; }
  .voucher-table tfoot td { background: white !important; }
  .voucher-signoff { font-size: 10px; margin-top: 24px; }
}
