/* Layout: tools on the left, the expense form drawn like the paper original on the right. Sinan teal and orange. */
:root {
  --bg: #f3f6f7;
  --surface: #ffffff;
  --sunk: #f3f8f8;
  --text: #1f2f33;
  --muted: #5f7377;
  --line: #d6e2e4;
  --brand: #0e5e66;
  --brand-deep: #0a474d;
  --brand-soft: #e0f0f1;
  --gold: #e8894a;
  --good: #2f8a3e;
  --bad: #a33838;
  --warn: #a35a00;
  --topbar: #0e5e66;
  --shadow: 0 10px 30px rgb(14 74 80 / 8%);
  --font: "Malgun Gothic", "Apple SD Gothic Neo", "Noto Sans KR", sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1719;
    --surface: #162225;
    --sunk: #121c1e;
    --text: #e4eff1;
    --muted: #9bb1b5;
    --line: #27393c;
    --brand: #86d0d6;
    --brand-deep: #b2e4e8;
    --brand-soft: #1b383c;
    --good: #5fcf96;
    --bad: #f08a8a;
    --warn: #f0b860;
    --topbar: #12343a;
    --shadow: 0 10px 30px rgb(0 0 0 / 35%);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); color: var(--text); font-family: var(--font); line-height: 1.5; }
button, input, select, textarea { font: inherit; color: inherit; }

.topbar { background: var(--topbar); color: #fff; }
.topbar-inner { max-width: 1320px; margin: 0 auto; padding: 14px 16px; display: flex; gap: 14px; align-items: center; }
.mark { width: 46px; height: 46px; }
.eyebrow { margin: 0; font-size: 13px; opacity: .85; }
h1 { margin: 0; font-size: 22px; }

.layout { max-width: 1320px; margin: 0 auto; padding: 18px 16px 40px; display: grid; grid-template-columns: 340px minmax(0, 1fr); gap: 18px; align-items: start; }
@media (max-width: 980px) { .layout { grid-template-columns: 1fr; } }

.side { display: grid; gap: 14px; min-width: 0; }
.side .panel { min-width: 0; }
.field select { width: 100%; min-width: 0; text-overflow: ellipsis; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px; box-shadow: var(--shadow); }
.panel h2 { margin: 0 0 10px; font-size: 16px; display: flex; gap: 8px; align-items: center; }
.step { display: inline-grid; place-items: center; width: 24px; height: 24px; border-radius: 50%; background: var(--gold); color: #fff; font-size: 13px; }
.hint { margin: 10px 0 0; font-size: 13px; color: var(--muted); }
.status { margin: 8px 0 0; font-size: 14px; min-height: 0; }
.status.good { color: var(--good); }
.status.bad { color: var(--bad); }
.status.warn { color: var(--warn); }

.drop { display: grid; gap: 4px; text-align: center; padding: 20px 12px; border: 2px dashed var(--brand); border-radius: 12px; background: var(--brand-soft); cursor: pointer; }
.drop.over { background: var(--surface); }
.drop input { display: none; }
.drop strong { color: var(--brand-deep); }
.drop span { font-size: 13px; color: var(--muted); }

.receipt-thumb { margin: 10px 0 0; }
.receipt-thumb img { width: 100%; max-height: 260px; object-fit: contain; background: var(--sunk); border: 1px solid var(--line); border-radius: 8px; }
.receipt-thumb figcaption { display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; font-size: 13px; margin-top: 6px; }

.field { display: grid; gap: 4px; font-size: 14px; }
.field input, .field select { padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); }
.row-buttons { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }

button, .button-like { cursor: pointer; border-radius: 8px; padding: 8px 14px; border: 1px solid var(--brand); font-size: 14px; }
.primary { background: var(--brand); color: #fff; border-color: var(--brand); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .primary { color: #0f1719; } }
.ghost { background: var(--surface); color: var(--brand-deep); }
.ghost.danger { border-color: var(--bad); color: var(--bad); }
.link { border: 0; background: none; padding: 0; color: var(--bad); text-decoration: underline; }
button:focus-visible, .button-like:focus-within, input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }

.docs { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; max-height: 300px; overflow: auto; }
.docs li { display: flex; gap: 8px; align-items: center; justify-content: space-between; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; font-size: 13px; }
.docs li.current { border-color: var(--brand); background: var(--brand-soft); }
.docs .open { flex: 1; text-align: left; border: 0; background: none; padding: 0; color: inherit; }
.docs .open b { display: block; font-size: 14px; }
.docs .del { padding: 2px 8px; font-size: 12px; border-color: var(--bad); color: var(--bad); background: none; }
.docs .empty { justify-content: center; color: var(--muted); }

.work { min-width: 0; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.toolbar .status { margin: 0; }
.paper-scroll { overflow-x: auto; padding-bottom: 8px; }

/* The form itself: always black on white, like the paper, in both themes. */
.paper {
  width: 794px; min-height: 1123px; margin: 0 auto 18px; padding: 70px 72px; background: #fff; color: #000;
  box-shadow: 0 4px 24px rgb(0 0 0 / 15%); font-size: 15px; color-scheme: light;
}
.paper input, .paper textarea { border: 0; background: transparent; color: #000; padding: 0; width: 100%; font-size: inherit; line-height: 1.35; }
/* 화면에서는 고칠 수 있는 칸을 연한 주황색으로 보여 줘요(인쇄할 때는 지워요). */
.paper input, .paper textarea { background: #fff8f0; border-radius: 3px; }
.paper input:hover, .paper textarea:hover { background: #ffeedd; }
.edit-hint { margin: -4px 0 12px; font-size: 13px; color: var(--muted); }
.edit-hint .swatch { background: #fff8f0; color: #8a4b1c; padding: 1px 6px; border: 1px solid #f3d6bb; border-radius: 4px; font-weight: 600; }
.paper input:focus, .paper textarea:focus { background: #fff1e3; outline: 1px solid var(--gold); outline-offset: 0; }
.paper textarea { resize: none; overflow: hidden; display: block; }
.paper .c, .paper input.c, .paper textarea.c { text-align: center; }
.doc-title { text-align: center; font-weight: 700; font-size: 17px !important; margin-bottom: 16px; }

.no-box { display: inline-flex; align-items: center; gap: 6px; width: 25%; padding: 6px 14px; border: 1.5px solid #000; border-bottom: 0; }
.no-box .w-no { width: 90px; text-align: center; }

.form { width: 100%; border-collapse: collapse; table-layout: fixed; }
.form + .form { margin-top: -1.5px; }
.form td { border: 1px solid #000; padding: 6px 8px; height: 40px; vertical-align: middle; }
.form { border: 1.5px solid #000; }
.approval .head { height: 44px; }
.approval .sign-row td { height: 52px; }
.approval .vertical { line-height: 1.5; }
.approval .blank { border-bottom: 0; }
.approval .amount-row td { height: 70px; border-top: 0; }
.approval .amount-row td:first-child { border-right: 1px solid #000; }
/* 글자 금액과 ￦ 숫자에 똑같은 밑줄(1px, 같은 높이)을 따로 그어요. */
.amount-line { display: inline-flex; align-items: baseline; gap: 28px; padding-left: 20px; }
.amount-part { display: inline-flex; align-items: baseline; border-bottom: 1px solid #000; padding-bottom: 2px; line-height: 1.35; }
#amount-words { margin-left: 0.4em; }
.paper .amount-input { display: inline-block; width: 9ch; line-height: 1.35; margin-left: 2px; }
.label.tight { white-space: nowrap; letter-spacing: -0.6px; padding-left: 4px; padding-right: 4px; }
.spaced { letter-spacing: 0.3em; }
.wide-spaced { letter-spacing: 1.6em; padding-left: 1.6em !important; white-space: nowrap; }
.vendor .wide-spaced { letter-spacing: 1.2em; padding-left: 1.2em !important; }
.fixed { white-space: nowrap; }
.items .item td { height: var(--row-h, 68px); padding-top: 2px; padding-bottom: 2px; }
/* '줄 추가' 단추 줄: 화면에서만 보이고 표 밖처럼 보이게 테두리를 지워요. */
.form.items { border-bottom: 0; }
.items tbody tr:last-child td { border-bottom: 1.5px solid #000; }
.items .row-tools td { border: 0; height: auto; padding: 6px 0; text-align: center; background: #fff; }
.items .row-tools button { font-size: 13px; padding: 4px 12px; margin: 0 4px; }
.items .row-tools button:disabled { opacity: .4; cursor: default; }
.form.items + .form { margin-top: 0; }
.items .amt { text-align: center; }
.vendor .sub { height: 34px; padding: 4px 8px; font-size: 14px; }
.vendor .sub { display: table-cell; }
.vendor .sub input, .vendor .sub textarea { display: inline; width: calc(100% - 52px); vertical-align: top; }
.account .lines { padding: 6px 12px; }
.account .lines div { display: flex; gap: 4px; }
.account .lines input { flex: 1; }
.closing { text-align: right; padding-right: 60px !important; height: 34px !important; }

.receipt-page { display: flex; flex-direction: column; align-items: center; }
.receipt-title { font-weight: 700; margin: 0 0 16px; }
.receipt-page img { max-width: 100%; max-height: 960px; object-fit: contain; }
.receipt-slot { width: 100%; flex: 1; min-height: 820px; align-content: center; gap: 10px; border-color: #0e5e66; background: #f1f8f8; color: #1f2f33; font-size: 15px; }
.receipt-slot strong { font-size: 22px; color: #0a474d; }
.receipt-slot span { color: #4c6064; }
.receipt-slot .slot-icon { font-size: 48px; }
.receipt-slot.over { background: #e0f0f1; border-style: solid; }
.replace-receipt { margin-top: 14px; }
.upload-button { font-weight: 700; }
.toolbar .upload-button.primary { background: var(--gold); border-color: var(--gold); color: #fff; }

.paper input::placeholder { color: #b9c4c6; }
.paper input.need { background: #fff1e3; outline: 2px solid var(--gold); }
.docs .pick { width: 18px; height: 18px; flex: none; }
.print-batch { display: none; }

@page { size: A4; margin: 0; }
@media print {
  body { background: #fff; }
  .topbar, .side, .toolbar { display: none !important; }
  .layout { display: block; padding: 0; max-width: none; }
  .paper-scroll { overflow: visible; padding: 0; }
  .paper { box-shadow: none; margin: 0; width: 210mm; min-height: 0; height: auto; padding: 14mm 19mm 10mm; }
  /* 내역 줄이 아주 많으면 한 쪽을 넘어 다음 쪽으로 이어져요(잘리지 않게). */
  .items tr { break-inside: avoid; }
  .receipt-page { break-before: page; }
  .paper input, .paper textarea, .paper input:hover, .paper textarea:hover, .paper input:focus, .paper textarea:focus { background: none; outline: 0; }
  .edit-hint, .items .row-tools { display: none; }
  .form.items + .form { margin-top: -1.5px; }
  .receipt-page.no-print, .receipt-page.empty, .replace-receipt { display: none !important; }
  .paper input::placeholder { color: transparent; }
  .paper input.need { background: none; outline: 0; }
  body.batch-print .paper-scroll { display: none; }
  body.batch-print .print-batch { display: block; }
  .print-batch .paper + .paper { break-before: page; }
}
