/* 문서작성 — 양식을 종이 모양으로 그리고 칸을 바로 고친다.
   데스크톱: 목록 | 문서 | 도구 3단. 1200px 아래: 양식을 고른 뒤 목록은 서랍으로. 900px 아래: 한 줄로 쌓고 아래 고정 막대. */
/* 이 화면의 색은 여기서만 정한다 */
.documents-page {
    --doc-surface: #fff;
    --doc-bg: #f8faff;
    --doc-fill: #f1f4fa;
    --doc-ink: #17203a;
    --doc-text-chip: #33406b;
    --doc-text-sub: #536077;
    --doc-text-muted: #667085;
    --doc-text-faint: #98a2b3;
    --doc-border: #e2e8f5;
    --doc-line: #dde4f7;
    --doc-line-soft: #eef1f8;
    --doc-primary: #344cdb;
    --doc-primary-strong: #263fae;
    --doc-focus: rgba(52,76,219,.28);
    --doc-shadow: rgba(35,48,76,0.08);
    --doc-warn: #b54708;
    --doc-warn-bg: #fff4ed;
    --doc-danger: #e0483f;
    background: var(--doc-bg);
}
/* 고정 헤더(데스크톱 아래 경계 104px, 모바일 82px) 밑에서 시작한다 */
/* --doc-top: 고정 헤더(120px)와 공지 띠 아래로 내리는 기준. 양옆 패널의 sticky 위치도 같은 값을 쓴다. */
.doc-app { --doc-top: calc(136px + var(--notice-bar-height, 0px)); max-width: 1500px; margin: 0 auto; padding: var(--doc-top) 16px 32px; box-sizing: border-box; color: var(--doc-ink); }
.doc-app *, .doc-mobilebar * { box-sizing: border-box; }

.doc-topbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 14px; padding: 16px 20px; border: 1px solid var(--doc-border); border-radius: 14px; background: var(--doc-surface); }
.doc-topbar__text { min-width: 0; }
.doc-topbar h1 { margin: 0; font-size: 24px; line-height: 1.25; font-weight: 850; letter-spacing: -.04em; color: var(--doc-ink); }
.doc-topbar p { margin: 6px 0 0; color: var(--doc-text-sub); font-size: 13.5px; line-height: 1.5; font-weight: 600; }
.doc-topbar p b { color: var(--doc-primary); font-weight: 800; }
.doc-topbar__links { flex: 0 0 auto; }
.doc-topbar__links a { display: inline-flex; align-items: center; gap: 6px; min-height: 44px; padding: 0 16px; white-space: nowrap; border: 1px solid var(--doc-line); border-radius: 9px; background: var(--doc-surface); color: var(--doc-primary-strong); font-size: 13px; font-weight: 700; text-decoration: none; }

.doc-layout { display: grid; grid-template-columns: 260px minmax(0, 1fr) 300px; gap: 14px; align-items: start; }

/* 양식 목록 */
.doc-library { position: sticky; top: var(--doc-top); display: flex; flex-direction: column; max-height: calc(100vh - var(--doc-top) - 12px); min-width: 0; padding: 14px; border: 1px solid var(--doc-border); border-radius: 14px; background: var(--doc-surface); }
.doc-library__head { display: flex; align-items: center; justify-content: space-between; }
.doc-library__close { display: none; }
.doc-label { display: block; margin: 0 0 5px; color: var(--doc-text-sub); font-size: 12px; font-weight: 700; }
.doc-app input[type="search"], .doc-app select, .doc-app textarea, .doc-app input[type="text"], .doc-app input[type="date"], .doc-app input[type="tel"], .doc-app input[type="email"] {
    width: 100%; min-height: 40px; padding: 8px 11px; border: 1px solid var(--doc-line); border-radius: 9px; background: var(--doc-surface); color: var(--doc-ink); font-size: 13.5px; font-family: inherit;
}
.doc-app input:focus, .doc-app select:focus, .doc-app textarea:focus { outline: 2px solid var(--doc-focus); outline-offset: 1px; border-color: var(--doc-primary); }
.doc-chips { display: flex; flex: 0 0 auto; flex-wrap: wrap; gap: 6px; margin: 10px 0; }
.doc-chips button { min-height: 32px; padding: 0 11px; border: 1px solid var(--doc-line); border-radius: 999px; background: var(--doc-surface); color: var(--doc-text-chip); font-size: 12px; font-weight: 700; cursor: pointer; }
.doc-chips button.is-active { border-color: var(--doc-primary); background: var(--doc-primary); color: var(--doc-surface); }
.doc-list { flex: 1; min-height: 0; margin: 0; padding: 0; list-style: none; overflow-y: auto; border-top: 1px solid var(--doc-line-soft); }
.doc-list li[hidden] { display: none; }
.doc-list a { display: flex; flex-direction: column; gap: 2px; padding: 9px 8px; border-bottom: 1px solid var(--doc-line-soft); color: var(--doc-ink); text-decoration: none; }
.doc-list a b { font-size: 13.5px; font-weight: 700; word-break: keep-all; }
.doc-list a span { color: var(--doc-text-faint); font-size: 11.5px; font-weight: 600; }
.doc-list a:hover { background: var(--doc-bg); }
.doc-list a[aria-current="page"] { background: var(--doc-fill); box-shadow: inset 3px 0 0 var(--doc-primary); }
.doc-list__empty { margin: 12px 0 0; color: var(--doc-text-muted); font-size: 12.5px; }

/* 문서 */
.doc-stage { min-width: 0; }
.doc-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; margin-bottom: 10px; }
.doc-app .doc-toolbar__pick, .doc-app:not(.has-form) .doc-toolbar { display: none; }
.doc-stats { display: flex; flex-wrap: wrap; gap: 4px 12px; color: var(--doc-text-sub); font-size: 12.5px; font-weight: 600; }
.doc-stats b { color: var(--doc-ink); font-weight: 800; }
#doc-save-state { color: var(--doc-text-faint); }
.doc-toolbar__actions { display: flex; gap: 6px; margin-left: auto; }
.doc-missing { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-bottom: 10px; padding: 8px 10px; border-radius: 10px; background: var(--doc-warn-bg); }
.doc-missing[hidden] { display: none; }
.doc-missing span { color: var(--doc-warn); font-size: 12px; font-weight: 800; }
.doc-missing button { min-height: 32px; padding: 0 10px; border: 1px solid var(--doc-line); border-radius: 999px; background: var(--doc-surface); color: var(--doc-warn); font-size: 12px; font-weight: 700; cursor: pointer; }

.doc-paper { max-width: 820px; margin: 0 auto; padding: 40px 48px 36px; border: 1px solid var(--doc-border); border-radius: 4px; background: var(--doc-surface); box-shadow: 0 8px 24px var(--doc-shadow); }
.doc-paper__title { margin: 0; text-align: center; font-size: 24px; font-weight: 800; letter-spacing: .08em; color: var(--doc-ink); word-break: keep-all; }
.doc-paper__purpose { margin: 8px 0 22px; text-align: center; color: var(--doc-text-muted); font-size: 12.5px; word-break: keep-all; }
.doc-paper__loading { text-align: center; color: var(--doc-text-faint); font-size: 13px; }
.doc-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); border-top: 2px solid var(--doc-ink); border-left: 1px solid var(--doc-line); }
.doc-row { display: grid; grid-template-columns: 112px minmax(0, 1fr); border-right: 1px solid var(--doc-line); border-bottom: 1px solid var(--doc-line); }
.doc-row--wide { grid-column: 1 / -1; }
.doc-row__label { display: flex; flex-direction: column; justify-content: center; gap: 2px; padding: 6px 8px; background: var(--doc-fill); color: var(--doc-text-chip); font-size: 12.5px; font-weight: 700; word-break: keep-all; }
.doc-row__label em { color: var(--doc-danger); font-size: 11px; font-style: normal; font-weight: 700; }
.doc-row__value { min-width: 0; padding: 2px; }
.doc-row__value small { display: block; padding: 0 8px 4px; color: var(--doc-text-faint); font-size: 11px; }
.doc-app .doc-input { min-height: 38px; border-color: transparent; border-radius: 4px; background: transparent; font-size: 13.5px; }
.doc-app textarea.doc-input { min-height: 56px; line-height: 1.6; resize: vertical; }
.doc-app .doc-input:hover { border-color: var(--doc-line); }
.doc-row.is-ai .doc-row__value { background: var(--doc-bg); box-shadow: inset 3px 0 0 var(--doc-primary); }
.doc-paper.is-blank-only .doc-row.is-filled { display: none; }

.doc-body { margin: 24px 0 0; font-size: 14px; line-height: 1.9; color: var(--doc-ink); }
.doc-body p { margin: 0 0 8px; word-break: keep-all; overflow-wrap: anywhere; }
.doc-slot { display: inline; padding: 0 2px; border: 0; border-bottom: 1px solid var(--doc-text-faint); background: transparent; color: var(--doc-ink); font: inherit; font-weight: 700; cursor: pointer; overflow-wrap: anywhere; }
.doc-slot.is-blank { color: var(--doc-text-faint); font-weight: 600; }
.doc-slot.is-ai { border-bottom-color: var(--doc-primary); color: var(--doc-primary-strong); }
.doc-slot:hover, .doc-slot:focus { background: var(--doc-fill); outline: none; }
.doc-signs { margin-top: 28px; text-align: right; }
.doc-signs__date { margin: 0 0 14px; text-align: center; font-size: 14px; font-weight: 700; }
.doc-sign-line { display: flex; justify-content: flex-end; align-items: center; gap: 12px; min-height: 44px; font-size: 14px; }
.doc-sign-line > span:first-child { color: var(--doc-text-sub); font-weight: 700; }
.doc-sign-line b { min-width: 90px; text-align: left; }
.doc-sign-line__mark { min-width: 110px; color: var(--doc-text-faint); font-size: 12.5px; }
.doc-sign-line__mark img { display: block; max-width: 120px; max-height: 44px; }
.doc-paper__foot { margin: 28px 0 0; padding-top: 10px; border-top: 1px solid var(--doc-line-soft); color: var(--doc-text-faint); font-size: 11.5px; }

.doc-welcome { padding: 20px 0; text-align: center; }
.doc-welcome h2 { margin: 0; font-size: 20px; font-weight: 800; }
.doc-welcome p { margin: 8px 0 18px; color: var(--doc-text-muted); font-size: 13px; }
.doc-welcome__grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; text-align: left; }
.doc-welcome__grid a { display: flex; align-items: center; min-height: 44px; padding: 8px 12px; border: 1px solid var(--doc-line); border-radius: 10px; color: var(--doc-ink); font-size: 13.5px; font-weight: 700; text-decoration: none; word-break: keep-all; }
.doc-welcome__grid a:hover { border-color: var(--doc-primary); color: var(--doc-primary-strong); }

/* 도구 */
.doc-tools { position: sticky; top: var(--doc-top); display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.doc-card { padding: 14px; border: 1px solid var(--doc-border); border-radius: 14px; background: var(--doc-surface); }
.doc-card h3 { margin: 0 0 10px; font-size: 15px; font-weight: 800; letter-spacing: -.02em; }
.doc-card textarea { min-height: 110px; line-height: 1.6; resize: vertical; }
.doc-card__meta { margin-top: 4px; text-align: right; color: var(--doc-text-faint); font-size: 11.5px; }
.doc-card__row { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 8px; }
.doc-card__row .doc-btn { flex: 1 1 auto; }
.doc-note { margin: 8px 0 0; color: var(--doc-text-muted); font-size: 12px; line-height: 1.55; word-break: keep-all; }
.doc-btn { display: inline-flex; align-items: center; justify-content: center; min-height: 44px; padding: 0 12px; border: 1px solid var(--doc-line); border-radius: 9px; background: var(--doc-surface); color: var(--doc-primary-strong); font-size: 13px; font-weight: 700; font-family: inherit; cursor: pointer; white-space: nowrap; }
.doc-btn--primary { border-color: var(--doc-primary); background: var(--doc-primary); color: var(--doc-surface); }
.doc-btn--primary:hover { background: var(--doc-primary-strong); }
.doc-btn--block { width: 100%; margin-top: 8px; }
.doc-btn:disabled { opacity: .55; cursor: default; }
.doc-sign { display: block; width: 100%; height: auto; aspect-ratio: 3 / 1; border: 1px dashed var(--doc-text-faint); border-radius: 9px; background: var(--doc-surface); touch-action: none; cursor: crosshair; }
.doc-check { display: inline-flex; align-items: center; gap: 6px; min-height: 44px; color: var(--doc-text-chip); font-size: 13px; font-weight: 700; }
.doc-mobilebar { display: none; }

/* 이 양식의 API */
.doc-api { margin-top: 20px; padding: 18px 20px; border: 1px solid var(--doc-border); border-radius: 14px; background: var(--doc-surface); }
.doc-api[hidden] { display: none; }
.doc-api h2 { margin: 0; font-size: 18px; font-weight: 800; }
.doc-api h3 { margin: 14px 0 6px; font-size: 13.5px; font-weight: 800; color: var(--doc-text-chip); }
.doc-api__lead { margin: 6px 0 0; color: var(--doc-text-sub); font-size: 13px; line-height: 1.6; word-break: keep-all; }
.doc-api__lead a { color: var(--doc-primary-strong); font-weight: 700; }
.doc-api code { font-family: Consolas, Menlo, monospace; font-size: 12px; overflow-wrap: anywhere; }
.doc-api__grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 4px 20px; }
.doc-api__code { margin: 0; padding: 10px 12px; border-radius: 9px; background: var(--doc-ink); color: var(--doc-surface); font-size: 12px; line-height: 1.6; white-space: pre-wrap; word-break: break-all; }
.doc-api__fields { border-top: 1px solid var(--doc-line); }
.doc-api__row { display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(0, 1.2fr) minmax(0, .7fr) 44px; gap: 8px; padding: 6px 4px; border-bottom: 1px solid var(--doc-line-soft); font-size: 12.5px; }
.doc-api__row--head { color: var(--doc-text-faint); font-size: 11.5px; font-weight: 700; }
.doc-api__row code { color: var(--doc-primary-strong); }

/* 1200px 아래 — 양식을 고르면 목록은 서랍으로 빠진다 */
@media (max-width: 1199px) {
    .doc-layout { grid-template-columns: minmax(0, 1fr) 280px; }
    .doc-app:not(.has-form) .doc-layout { grid-template-columns: 240px minmax(0, 1fr) 280px; }
    .doc-app.has-form .doc-library { position: fixed; top: 0; left: 0; bottom: 0; z-index: 1000; width: min(320px, 88vw); max-height: none; border-radius: 0; box-shadow: 0 8px 24px var(--doc-shadow); transform: translateX(-105%); transition: transform .2s ease; }
    .doc-app.has-form.is-library-open .doc-library { transform: none; }
    .doc-app.has-form .doc-library__close { display: inline-flex; min-height: 44px; padding: 0 12px; border: 1px solid var(--doc-line); border-radius: 9px; background: var(--doc-surface); color: var(--doc-primary-strong); font-size: 13px; font-weight: 700; cursor: pointer; }
    .doc-app.has-form .doc-toolbar__pick { display: inline-flex; }
    .doc-paper { padding: 32px 28px; }
}

/* 900px 아래 — 한 줄로 쌓는다 */
@media (max-width: 899px) {
    .doc-app { --doc-top: calc(104px + var(--notice-bar-height, 0px)); padding: var(--doc-top) 12px 88px; }
    /* 제목과 연동 버튼은 한 줄, 설명은 그 아래 전체 폭으로 둔다 */
    .doc-topbar { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 4px 10px; margin-bottom: 10px; padding: 12px 14px; }
    .doc-topbar__text { display: contents; }
    .doc-topbar h1 { grid-column: 1; grid-row: 1; font-size: 20px; }
    .doc-topbar p { grid-column: 1 / -1; grid-row: 2; margin: 0; font-size: 12.5px; }
    .doc-topbar__links { grid-column: 2; grid-row: 1; }
    .doc-topbar__links a { padding: 0 12px; font-size: 12.5px; }
    .doc-layout, .doc-app:not(.has-form) .doc-layout { grid-template-columns: minmax(0, 1fr); gap: 10px; }
    .doc-app:not(.has-form) .doc-library { position: static; max-height: 60vh; }
    .doc-app:not(.has-form) .doc-tools { display: none; }
    .doc-tools { position: static; }
    .doc-chips { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 2px; }
    .doc-chips button { flex: 0 0 auto; min-height: 44px; }
    .doc-toolbar__actions { margin-left: 0; }
    .doc-paper { padding: 20px 12px; border-radius: 4px; }
    .doc-paper__title { font-size: 20px; letter-spacing: .04em; }
    .doc-paper__purpose { margin-bottom: 14px; }
    .doc-grid { grid-template-columns: minmax(0, 1fr); }
    .doc-row { grid-template-columns: 92px minmax(0, 1fr); }
    .doc-row__label { padding: 6px; font-size: 12px; }
    .doc-app input[type="search"], .doc-app select, .doc-app textarea, .doc-app input[type="text"], .doc-app input[type="date"], .doc-app input[type="tel"], .doc-app input[type="email"], .doc-app .doc-input { min-height: 44px; font-size: 16px; }
    .doc-missing { flex-wrap: nowrap; overflow-x: auto; }
    .doc-missing span, .doc-missing button { flex: 0 0 auto; }
    .doc-missing button { min-height: 44px; }
    .doc-body { font-size: 13.5px; line-height: 1.8; }
    .doc-sign-line { flex-wrap: wrap; justify-content: flex-start; gap: 4px 10px; }
    .doc-sign-line__mark { min-width: 0; }
    .doc-welcome__grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .doc-api { padding: 14px 12px; }
    .doc-api__grid { grid-template-columns: minmax(0, 1fr); }
    .doc-api__row { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 2px 8px; }
    .doc-api__row--head span:nth-child(n+3) { display: none; }
    .doc-api__row > :nth-child(n+3) { color: var(--doc-text-faint); font-size: 11.5px; }
    .doc-app.has-form ~ .doc-mobilebar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 99; display: flex; gap: 8px; padding: 8px 12px; border-top: 1px solid var(--doc-border); background: var(--doc-surface); }
    .doc-mobilebar .doc-btn { flex: 1; }
}

@media print {
    .doc-library, .doc-tools, .doc-toolbar, .doc-missing, .doc-topbar, .doc-mobilebar, .doc-app.has-form ~ .doc-mobilebar { display: none; }
    .doc-layout { display: block; }
    .doc-paper { max-width: none; border: 0; box-shadow: none; }
}
