:root {
  --bg: #f5f6f8; --card: #fff; --line: #e3e6ec; --text: #1c2130; --muted: #6b7280;
  --primary: #1f5eff; --primary-ink: #fff; --danger: #c62828; --ok: #1b7f3b; --warn: #b26a00;
  --tap: 44px;
  font-family: "Malgun Gothic", "Apple SD Gothic Neo", system-ui, sans-serif; font-size: 15px; color: var(--text);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
a { color: var(--primary); text-decoration: none; }
h1 { font-size: 20px; margin: 0 0 14px; }
h2 { font-size: 14px; margin: 22px 0 8px; color: var(--muted); font-weight: 600; }
.muted { color: var(--muted); }
.error { color: var(--danger); margin: 8px 0; white-space: pre-line; }

/* 상단 */
header { display: flex; align-items: center; gap: 20px; padding: 0 16px; height: 54px; background: #fff; border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.brand { font-weight: 700; color: var(--text); white-space: nowrap; }
.tabs { display: flex; gap: 4px; flex: 1; }
.tabs a { padding: 8px 12px; border-radius: 8px; color: var(--muted); white-space: nowrap; min-height: var(--tap); display: inline-flex; align-items: center; }
.tabs a.active { background: #eef2ff; color: var(--primary); font-weight: 600; }
.tabs a.primary { background: var(--primary); color: var(--primary-ink); font-weight: 600; }
.count:not(:empty) { background: var(--danger); color: #fff; border-radius: 10px; padding: 0 6px; font-size: 11px; margin-left: 4px; }
.me { color: var(--muted); display: flex; gap: 12px; align-items: center; font-size: 13px; }
.me a, .me button { white-space: nowrap; }
.me a, .me button.link { display: inline-flex; align-items: center; min-height: var(--tap); }
.notification-link { min-width: var(--tap); justify-content: center; border-radius: 8px; }
.notification-link.active { background: #eef2ff; }
.visually-hidden, .file-picker input { position: absolute; width: 1px; height: 1px; padding: 0; min-height: 0; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

/* 하단 (폰) */
#bottom { display: none; position: fixed; left: 0; right: 0; bottom: 0; background: #fff; border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom, 0); z-index: 5; }
#bottom a { flex: 1; text-align: center; padding: 10px 4px; color: var(--muted); min-height: 52px; display: flex; flex-direction: column; justify-content: center; }
#bottom a.active { color: var(--primary); }
#bottom a .count { align-self: center; margin-left: 0; }
#bottom a.primary b { background: var(--primary); color: #fff; border-radius: 20px; padding: 6px 14px; display: inline-block; }

main { max-width: 900px; margin: 20px auto; padding: 0 16px 24px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 18px; margin-bottom: 14px; }
.list .item { display: block; padding: 14px 4px; border-bottom: 1px solid var(--line); color: var(--text); }
.list .item:last-child { border-bottom: 0; }
.item .t { font-weight: 600; margin: 2px 0 4px; }
.item .s { color: var(--muted); font-size: 13px; display: flex; gap: 10px; flex-wrap: wrap; }
.empty { padding: 36px 10px; text-align: center; color: var(--muted); }

.badge { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 12px; background: #eef0f4; color: var(--muted); white-space: nowrap; }
.badge.IN_PROGRESS, .badge.PENDING { background: #fff4e0; color: var(--warn); }
.badge.APPROVED { background: #e3f5e8; color: var(--ok); }
.badge.REJECTED { background: #fde7e7; color: var(--danger); }
.badge.WITHDRAWN, .badge.CANCELLED, .badge.SKIPPED { background: #eceef2; color: var(--muted); }
.badge.DRAFT, .badge.WAITING { background: #eef2ff; color: var(--primary); }

.chips { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.chips a { padding: 8px 14px; border-radius: 20px; border: 1px solid var(--line); background: #fff; color: var(--muted); min-height: 38px; display: inline-flex; align-items: center; }
.chips a.active { background: var(--text); color: #fff; border-color: var(--text); }

button, .btn { font: inherit; padding: 10px 16px; border-radius: 10px; border: 1px solid var(--line); background: #fff; cursor: pointer; min-height: var(--tap); }
.btn { display: inline-flex; align-items: center; width: fit-content; }
button.primary { background: var(--primary); color: #fff; border-color: var(--primary); font-weight: 600; }
button.danger { background: #fff; color: var(--danger); border-color: #f0b4b4; }
button.link { border: 0; background: none; color: var(--primary); padding: 0; min-height: 0; }
button.big { width: 100%; font-size: 16px; padding: 14px; }
button:disabled { opacity: .5; cursor: default; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 16px; }
.actions button { flex: 1; min-width: 120px; }

label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 5px; }
label .req { color: var(--danger); }
input, select, textarea { font: inherit; width: 100%; padding: 11px 12px; border: 1px solid var(--line); border-radius: 10px; background: #fff; min-height: var(--tap); }
textarea { min-height: 96px; resize: vertical; }
.field { margin-bottom: 14px; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; }
.login { max-width: 380px; margin: 70px auto; }

/* 양식 고르기 */
.forms { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 12px; }
.forms a { display: block; padding: 18px; border: 1px solid var(--line); border-radius: 12px; background: #fff; color: var(--text); min-height: 96px; }
.forms a:hover { border-color: var(--primary); }
.forms .n { font-weight: 700; font-size: 16px; margin-bottom: 6px; }
.forms .d { color: var(--muted); font-size: 13px; }

/* 표 입력 */
.rows { display: flex; flex-direction: column; gap: 10px; }
.row { border: 1px solid var(--line); border-radius: 10px; padding: 12px; background: #fafbfc; }
.row .rh { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; color: var(--muted); font-size: 13px; }
.row .grid { gap: 10px; }
.total { text-align: right; font-weight: 700; padding: 10px 2px; font-size: 16px; }

/* 결재선 */
.route { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.route .step { background: #eef2ff; border-radius: 10px; padding: 8px 12px; }
.route .step small { color: var(--muted); display: block; font-size: 12px; }
.route .arrow { color: var(--muted); }
.route .ref { background: #f1f3f6; }
.line-edit { display: grid; grid-template-columns: 64px 1fr 2fr 1fr auto; gap: 8px; align-items: center; margin-bottom: 8px; }
@media (max-width: 640px) { .line-edit { grid-template-columns: 1fr 1fr; } .line-edit select[name=userId] { grid-column: 1 / -1; } }

/* 문서 보기 */
.meta { display: flex; gap: 14px; flex-wrap: wrap; color: var(--muted); font-size: 13px; margin-bottom: 8px; }
.meta b { color: var(--text); font-weight: 600; }
.kv { display: grid; grid-template-columns: 120px 1fr; gap: 8px 12px; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; white-space: pre-wrap; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 9px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: 12px; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.scroll { overflow-x: auto; }
.history li { padding: 4px 0; font-size: 13px; }
.sticky-actions { position: sticky; bottom: 0; background: linear-gradient(transparent, var(--bg) 30%); padding-top: 14px; }
.list-heading { display: flex; align-items: start; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.list-heading h1 { margin: 0; overflow-wrap: anywhere; }
.list-heading .btn, .list-heading button { flex-shrink: 0; }
.notice-heading { margin-top: 14px; overflow-wrap: anywhere; }
.notice-body { white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.6; margin-top: 14px; }
.check-field { display: inline-flex; gap: 8px; align-items: center; min-height: var(--tap); }
.check-field input { width: auto; min-height: 0; }
.attachment-help { font-size: 13px; margin: 0 0 8px; }
.attachment-pickers { display: flex; gap: 8px; flex-wrap: wrap; }
.file-picker { position: relative; color: var(--primary); }
.file-picker:focus-within { outline: 2px solid var(--primary); }
.file-picker:has(input:disabled) { opacity: .5; cursor: default; }
.camera-picker { display: none; }
@media (pointer: coarse) { .camera-picker { display: inline-flex; } }
.attachment-list { margin: 8px 0; padding: 0; list-style: none; }
.attachment-list li { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 4px 0; }
.attachment-list li > a { display: flex; align-items: center; gap: 8px; }
.attachment-list li > a, .attachment-list li > span { min-height: var(--tap); min-width: 0; overflow-wrap: anywhere; }
.attachment-list li > span { align-content: center; }
.attachment-list img { width: 56px; height: 56px; border-radius: 6px; border: 1px solid var(--line); object-fit: cover; flex-shrink: 0; }
.attachment-list small { color: var(--muted); white-space: nowrap; }
.attachment-list button { flex-shrink: 0; }
.temp-pw { font-family: Consolas, monospace; font-size: 20px; letter-spacing: 1px; background: #fff8e1; padding: 8px 12px; border-radius: 6px; display: inline-block; }
.doc-search { display: flex; gap: 8px; margin-bottom: 12px; }
.doc-search input { flex: 1; min-width: 0; }
.doc-search button { flex-shrink: 0; }
.list .list-action { display: flex; align-items: start; justify-content: space-between; flex-wrap: wrap; gap: 12px; }
.payment-action { margin: 12px 0; }
.list-action .payment-action { margin: 0; }
.payment-action summary { width: max-content; }
.payment-action form { margin-top: 10px; }
.payment-action[open] { flex-basis: 100%; }
.tap-link { padding: 6px 8px; color: var(--primary); border: 0; }
.role-options { margin-top: 12px; border: 1px solid var(--line); border-radius: 8px; }
.role-options label { display: inline-flex; align-items: center; gap: 8px; margin: 0 12px 0 0; min-height: var(--tap); }
.role-options input { width: auto; min-height: 0; }
#user-edit, #org-edit { margin-bottom: 16px; }
#toast { position: fixed; bottom: 80px; left: 50%; transform: translateX(-50%); background: #1c2130; color: #fff; padding: 10px 16px; border-radius: 8px; z-index: 10; max-width: 90vw; }

@media (max-width: 1050px) {
  header { gap: 4px 12px; height: auto; min-height: 54px; flex-wrap: wrap; }
  .tabs { display: none; }
  #me-name { display: none; }
  .me { margin-left: auto; }
  #bottom { display: flex; }
  #bottom a { font-size: 13px; }
  #bottom a.primary b { padding-inline: 8px; }
  main { margin: 14px auto; padding-bottom: 90px; }
  .sticky-actions { bottom: calc(64px + env(safe-area-inset-bottom, 0px)); }
  .kv { grid-template-columns: 1fr; gap: 2px 0; } .kv dt { margin-top: 8px; font-size: 12px; }
}

@media print {
  @page { margin: 12mm; }
  body { background: #fff; }
  #top, #bottom, #toast, button, .actions, .print-hide, .payment-action, #comment-box, .document-card > .error { display: none !important; }
  main { max-width: none; margin: 0; padding: 0; }
  .card { border: 0; border-radius: 0; padding: 0; }
  .scroll { overflow: visible; }
  .approval-lines, .approval-lines table, tr { break-inside: avoid; page-break-inside: avoid; }
  h2 { break-after: avoid; }
}
