/* 신청서가 기본 화면. 위쪽 버튼으로 오른쪽 자료창(매뉴얼 PDF / 작년 신청 자료)을 연다. 좁은 화면에서는 자료창이 전체 화면으로 덮인다. */
:root {
  --bg: #f4f6f5;
  --surface: #ffffff;
  --sunken: #e9eeec;
  --fg: #17211e;
  --muted: #5b6965;
  --line: #d3dcd9;
  --accent: #0d6b5c;
  --accent-ink: #ffffff;
  --accent-soft: #dcefe9;
  --warn: #a4471b;
  --warn-soft: #fbe9df;
  --focus: #1b8f7c;
  --info: #2a5b9e;
  --info-soft: #e3ecf8;
  --font: "IBM Plex Sans KR", "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
  --radius: 8px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #101614; --surface: #17201d; --sunken: #0c1110; --fg: #e3ebe8; --muted: #93a39e;
    --line: #2b3834; --accent: #4fc0a9; --accent-ink: #062019; --accent-soft: #163a32;
    --warn: #f0a07a; --warn-soft: #3a2117; --focus: #6fd6c0; --info: #8db4ea; --info-soft: #1a2a40; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #101614; --surface: #17201d; --sunken: #0c1110; --fg: #e3ebe8; --muted: #93a39e;
  --line: #2b3834; --accent: #4fc0a9; --accent-ink: #062019; --accent-soft: #163a32;
  --warn: #f0a07a; --warn-soft: #3a2117; --focus: #6fd6c0; --info: #8db4ea; --info-soft: #1a2a40; color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--fg); font: 15px/1.6 var(--font); }
h1, h2, h3 { text-wrap: balance; margin: 0; line-height: 1.3; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }

/* 머리말 */
.top {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px 20px;
  background: var(--surface); border-bottom: 1px solid var(--line);
  padding-block: 12px; padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px));
}
.top-title { display: grid; gap: 2px; min-width: 0; }
.top h1 { font-size: 18px; font-weight: 600; }
.top .meta { font-size: 13px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 4px 14px; }
.top .meta b { color: var(--fg); font-weight: 600; }
.deadline { background: var(--warn-soft); color: var(--warn); border-radius: 999px; padding: 1px 10px; font-weight: 600; }
.docbtns { display: flex; gap: 8px; flex-wrap: wrap; }
.btn.doc { padding: 8px 14px; font-weight: 600; }
.btn.doc[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

/* 본문 배치 */
.layout { min-height: 0; }
.layout.open { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr); height: calc(100% - var(--top-h, 70px)); }
.layout.open .pane-main { overflow: auto; min-height: 0; overscroll-behavior: contain; }
/* 자료창: 머리(닫기)는 고정, 본문(side-body)만 스크롤 */
.side { background: var(--sunken); border-left: 1px solid var(--line); display: flex; flex-direction: column; min-width: 0; min-height: 0; overflow: hidden; }
.side-head {
  flex: none; display: flex; align-items: center; justify-content: space-between; gap: 8px;
  background: var(--surface); border-bottom: 1px solid var(--line); padding: 8px 12px;
}
.side-body { flex: 1 1 auto; min-height: 0; overflow: auto; position: relative; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
@media (max-width: 900px) {
  .layout.open { display: block; height: auto; }
  .side { position: fixed; inset: 0; z-index: 20; border-left: 0;
    padding-top: env(safe-area-inset-top, 0px); padding-bottom: env(safe-area-inset-bottom, 0px); }
  body.side-open { overflow: hidden; }
}

/* PDF: 모든 쪽을 세로로 이어 붙여 스크롤 */
.pdfbar {
  position: sticky; top: 0; z-index: 2; display: flex; flex-wrap: wrap; align-items: center; gap: 6px;
  background: var(--surface); border-bottom: 1px solid var(--line); padding: 8px 12px;
}
.pdfbar select { max-width: 260px; min-width: 0; flex: 1 1 180px; }
.pdfbar .pageno { display: flex; align-items: center; gap: 4px; font-size: 14px; }
.pdfbar .pageno input { width: 56px; text-align: center; }
.pdfview { padding: 12px; }
.pg { position: relative; margin: 0 auto 12px; background: #fff; box-shadow: 0 1px 3px rgb(0 0 0 / .18); }
.pg canvas { display: block; width: 100%; height: 100%; }
.pg .pgno { position: absolute; right: 6px; bottom: 4px; font-size: 11px; color: #6b7672; background: rgb(255 255 255 / .85); padding: 0 6px; border-radius: 4px; }
.pdfmsg { padding: 40px 16px; text-align: center; color: var(--muted); }

/* 작년 자료 */
.prevpane { padding: 12px; display: grid; gap: 12px; align-content: start; }
.prevsum { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; font-size: 14px; display: grid; gap: 4px; }
.prevlist { display: grid; gap: 10px; }
.prevcard { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; display: grid; gap: 8px; }
.prevcard .head { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 6px 12px; align-items: baseline; }
.prevcard .title { font-weight: 600; }
.prevcard .sub { font-size: 13px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 2px 12px; }
.prevcard details summary { cursor: pointer; color: var(--accent); font-size: 13.5px; font-weight: 600; }
.prevcard .body { display: grid; gap: 8px; margin-top: 8px; font-size: 14px; }
.prevcard .body h4 { margin: 0; font-size: 13px; color: var(--muted); font-weight: 600; }
.prevcard .body p { margin: 0; white-space: pre-wrap; }
.chg { font-size: 13.5px; border-radius: 6px; padding: 4px 10px; border-left: 4px solid; }
.chg.removed { background: var(--warn-soft); color: var(--warn); border-color: var(--warn); }
.chg.removed .from { text-decoration: line-through; }
.chg.renamed { background: var(--info-soft); color: var(--info); border-color: var(--info); }
.chg.same { background: transparent; color: var(--muted); border-color: var(--line); font-size: 12.5px; }
.changes { display: grid; gap: 6px; margin-top: 6px; }
.prevcard .note { font-size: 13px; background: var(--warn-soft); color: var(--warn); border-radius: 6px; padding: 4px 8px; }

/* 버튼·입력 */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--line); background: var(--surface); border-radius: var(--radius);
  padding: 6px 12px; cursor: pointer; text-decoration: none; color: var(--fg); white-space: nowrap;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
.btn.danger { color: var(--warn); }
.btn.small { padding: 3px 9px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: default; }
.tabs { display: flex; gap: 4px; flex-wrap: wrap; }
.tab { border: 0; background: transparent; padding: 6px 12px; border-radius: var(--radius); cursor: pointer; color: var(--muted); font-weight: 600; }
.tab[aria-selected="true"] { background: var(--accent-soft); color: var(--accent); }

input[type=text], input[type=number], input[type=password], select, textarea {
  width: 100%; border: 1px solid var(--line); background: var(--surface); border-radius: var(--radius); padding: 7px 10px; min-width: 0;
}
textarea { resize: vertical; min-height: 76px; line-height: 1.5; }
input:focus, select:focus, textarea:focus { border-color: var(--focus); outline: none; box-shadow: 0 0 0 3px var(--accent-soft); }

/* 신청서 */
.formwrap { max-width: 780px; margin: 0 auto; padding-block: 16px 48px; padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); display: grid; gap: 16px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; display: grid; gap: 16px; min-width: 0; }
.card h2 { font-size: 16px; font-weight: 600; }
.section { border: 0; border-top: 1px solid var(--line); margin: 0; padding: 14px 0 0; display: grid; gap: 12px; min-width: 0; }
.section legend { font-weight: 600; font-size: 15px; padding: 0 8px 0 0; }
.unit { font-weight: 400; font-size: 13px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 14px; }
.span2 { grid-column: 1 / -1; }
@media (max-width: 560px) { .grid2 { grid-template-columns: 1fr; } }
.field { display: grid; gap: 4px; min-width: 0; }
.field label { font-size: 13px; font-weight: 600; letter-spacing: .01em; }
.hint { font-size: 12.5px; color: var(--muted); }
.req::after { content: " *"; color: var(--warn); }
.hp { position: absolute; left: -9999px; width: 1px; height: 1px; overflow: hidden; }

.projinfo { background: var(--accent-soft); border-radius: var(--radius); padding: 12px 14px; display: grid; gap: 6px; font-size: 14px; }
.projinfo .support { font-weight: 600; }
.projinfo ul, .rules ul { margin: 0; padding-left: 18px; display: grid; gap: 2px; }
.projinfo .row { display: flex; flex-wrap: wrap; gap: 6px 12px; align-items: center; }
.rules { font-size: 13.5px; color: var(--muted); }
.rules summary { cursor: pointer; font-weight: 600; color: var(--fg); }

/* 산출내역: 한 줄에 용도 하나 */
.calc { display: grid; gap: 6px; }
.calc-head, .calc-row { display: grid; grid-template-columns: 96px minmax(0, 1.1fr) minmax(0, 1.6fr) 96px 30px; gap: 6px; align-items: center; }
.calc-head { font-size: 12.5px; color: var(--muted); font-weight: 600; padding: 0 2px; }
.calc-head .r, .calc-row .amt { text-align: right; }
.calc-row select, .calc-row input { padding: 6px 8px; }
.calc-row .amt { font-variant-numeric: tabular-nums; }
.calc-row .amt.auto { color: var(--accent); }
.calc-row .x { border: 0; background: transparent; color: var(--muted); cursor: pointer; font-size: 18px; line-height: 1; padding: 4px; border-radius: 6px; }
.calc-row .x:hover { color: var(--warn); background: var(--warn-soft); }
#addRow { justify-self: start; }
.calc-foot { display: flex; flex-wrap: wrap; gap: 4px 16px; justify-content: flex-end; font-size: 13.5px; border-top: 1px dashed var(--line); padding-top: 8px; }
.calc-foot b { font-variant-numeric: tabular-nums; }
@media (max-width: 640px) {
  .calc-head { display: none; }
  .calc-row { grid-template-columns: 90px minmax(0, 1fr) 96px; border: 1px solid var(--line); border-radius: var(--radius); padding: 8px; }
  .calc-row .fund { grid-column: 1; grid-row: 1; }
  .calc-row .use { grid-column: 2; grid-row: 1; }
  .calc-row .x { grid-column: 3; grid-row: 1; justify-self: end; }
  .calc-row .basis { grid-column: 1 / 3; grid-row: 2; }
  .calc-row .amt { grid-column: 3; grid-row: 2; }
}
.intentwrap { display: grid; gap: 16px; }
tr.mine td { background: var(--accent-soft); }
.state { display: inline-block; font-size: 12px; padding: 0 8px; border-radius: 999px; white-space: nowrap; }
.state.done { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.state.todo { background: var(--sunken); color: var(--muted); }
.rowbtns { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.steps { margin: 0; padding-left: 20px; display: grid; gap: 8px; font-size: 14px; }
.steps .btn { margin-left: 6px; }
input[type=file] { width: 100%; border: 1px dashed var(--line); border-radius: var(--radius); padding: 10px; background: var(--sunken); }
.amountbox { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 8px; background: var(--sunken); border-radius: var(--radius); padding: 10px 14px; }
.amountbox output { font-size: 22px; font-weight: 600; }

.actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.actions.spread { justify-content: space-between; }
.notice { border-radius: var(--radius); padding: 10px 12px; font-size: 14px; }
.notice.ok { background: var(--accent-soft); color: var(--fg); }
.notice.bad { background: var(--warn-soft); color: var(--warn); }

/* 표 */
.tablewrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
table { border-collapse: collapse; width: 100%; font-size: 14px; }
th, td { text-align: left; padding: 7px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { background: var(--sunken); font-weight: 600; font-size: 13px; white-space: nowrap; }
td.amt, th.amt { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
tfoot td { font-weight: 600; background: var(--sunken); }

.sum-list { display: grid; gap: 8px; }
.sum-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 12px; align-items: center; }
.sum-row .name { font-weight: 600; font-size: 14px; }
.sum-row .val { font-variant-numeric: tabular-nums; font-size: 14px; }
.bar { grid-column: 1 / -1; height: 6px; background: var(--sunken); border-radius: 3px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--accent); }
.bar.over > i { background: var(--warn); }
.pill { display: inline-block; font-size: 12px; padding: 0 8px; border-radius: 999px; background: var(--sunken); color: var(--muted); }
.pill.over { background: var(--warn-soft); color: var(--warn); font-weight: 600; }
.empty { text-align: center; color: var(--muted); padding: 28px 12px; }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
