:root {
  --navy: #1f3a5f; --navy-2: #2d5286; --bg: #f3f5f8; --card: #fff; --line: #dfe4eb; --text: #1d2530; --muted: #6b7684;
  --ok: #1f8a4c; --ok-bg: #e5f5ec; --warn: #b46900; --warn-bg: #fff4e0; --bad: #c62f2f; --bad-bg: #fdecec;
  --info: #2d5286; --info-bg: #e8f0fb; --radius: 10px;
  font-family: "Pretendard", "Apple SD Gothic Neo", "Malgun Gothic", system-ui, sans-serif;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.5; -webkit-text-size-adjust: 100%; }
a { color: var(--navy-2); }
h1 { font-size: 20px; margin: 0 0 16px; }
h2 { font-size: 16px; margin: 0 0 12px; }
.muted { color: var(--muted); }
.center { text-align: center; }
.pad { padding: 40px 16px; }
.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }

/* 상단 */
#topbar { background: var(--navy); color: #fff; position: sticky; top: 0; z-index: 10; }
.bar { max-width: 1080px; margin: 0 auto; display: flex; align-items: center; justify-content: space-between; padding: 10px 16px; }
.brand { color: #fff; text-decoration: none; display: flex; gap: 8px; align-items: center; font-weight: 700; }
.brand img { width: 26px; height: 26px; border-radius: 6px; background: #fff; }
.who { font-size: 13px; display: flex; gap: 10px; align-items: center; }
.who .link { color: #cfe0f5; }
#nav { max-width: 1080px; margin: 0 auto; display: flex; gap: 2px; padding: 0 8px; overflow-x: auto; scrollbar-width: none; }
#nav a { color: #cfe0f5; text-decoration: none; padding: 9px 12px; white-space: nowrap; border-bottom: 3px solid transparent; font-size: 14px; }
#nav a.on { color: #fff; border-bottom-color: #7fb2ee; font-weight: 600; }
#nav .badge { background: #ff6b6b; color: #fff; border-radius: 9px; padding: 0 6px; font-size: 11px; margin-left: 3px; }
#nav .sep { border-left: 1px solid #3b5a82; margin: 8px 4px; }

main { max-width: 1080px; margin: 0 auto; padding: 20px 16px 60px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin-bottom: 16px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spread { justify-content: space-between; }
.grid { display: grid; gap: 12px; }
.stats { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); margin-bottom: 16px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; text-decoration: none; color: inherit; display: block; }
.stat b { display: block; font-size: 24px; color: var(--navy); font-variant-numeric: tabular-nums; }
.stat span { color: var(--muted); font-size: 13px; }
a.stat:hover { border-color: var(--navy-2); }

/* 폼 */
label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
input, select, textarea { width: 100%; font: inherit; color: inherit; padding: 9px 10px; border: 1px solid #c9d1dc; border-radius: 8px; background: #fff; }
input:focus, select:focus, textarea:focus { outline: 2px solid #9cc0ee; border-color: var(--navy-2); }
textarea { min-height: 70px; resize: vertical; }
.field { margin-bottom: 12px; }
.fields { display: grid; gap: 0 12px; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.hint { font-size: 12px; color: var(--muted); margin-top: 4px; }
.warnline { font-size: 12px; color: var(--warn); background: var(--warn-bg); border-radius: 6px; padding: 6px 8px; margin-top: 6px; }
button, .btn { font: inherit; border: 1px solid #c9d1dc; background: #fff; color: var(--text); padding: 8px 14px; border-radius: 8px; cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; gap: 6px; }
button:hover, .btn:hover { background: #f1f4f8; }
.primary { background: var(--navy); border-color: var(--navy); color: #fff; }
.primary:hover { background: var(--navy-2); }
.danger { color: var(--bad); border-color: #f0b8b8; }
.okbtn { background: var(--ok); border-color: var(--ok); color: #fff; }
.okbtn:hover { background: #197340; }
.link { background: none; border: none; padding: 0; color: var(--navy-2); text-decoration: underline; cursor: pointer; }
button:disabled { opacity: .55; cursor: default; }
.small { padding: 4px 9px; font-size: 13px; }
.actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; margin-top: 12px; }

/* 로그인 */
.auth { max-width: 380px; margin: 8vh auto 0; }
.auth .logo { text-align: center; margin-bottom: 18px; }
.auth .logo img { width: 52px; height: 52px; }
.auth .logo div { font-weight: 700; font-size: 18px; margin-top: 6px; }
.err { color: var(--bad); font-size: 13px; min-height: 18px; margin: 4px 0 8px; }

/* 표 */
.tablewrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; background: #fff; }
th, td { padding: 9px 10px; border-bottom: 1px solid var(--line); text-align: left; font-size: 14px; vertical-align: middle; }
th { background: #f7f9fb; color: var(--muted); font-weight: 600; font-size: 13px; white-space: nowrap; }
tr.click { cursor: pointer; }
tr.click:hover td { background: #f7faff; }
tr.off td { color: #a0a8b3; }
tfoot td { font-weight: 700; background: #f7f9fb; }

.pill { display: inline-block; padding: 1px 9px; border-radius: 20px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.st-pending { background: var(--info-bg); color: var(--info); }
.st-approved { background: var(--ok-bg); color: var(--ok); }
.st-paid { background: #eceff3; color: #3d4652; }
.st-rejected { background: var(--bad-bg); color: var(--bad); }
.st-withdrawn { background: #f1f1f1; color: #888; }

/* 품의서 작성 */
.item { border: 1px solid var(--line); border-radius: 8px; padding: 12px; margin-bottom: 10px; background: #fbfcfd; }
.item .fields { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.item-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; font-weight: 600; font-size: 14px; }
.total { font-size: 18px; font-weight: 700; color: var(--navy); }
.thumbs { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 10px; }
.thumb { width: 104px; position: relative; font-size: 11px; color: var(--muted); }
.thumb .box { width: 104px; height: 104px; border: 1px solid var(--line); border-radius: 8px; background: #eef1f5 center/cover no-repeat; display: flex; align-items: center; justify-content: center; font-weight: 700; color: var(--bad); overflow: hidden; }
.thumb .x { position: absolute; top: -8px; right: -8px; width: 24px; height: 24px; border-radius: 50%; padding: 0; justify-content: center; background: #fff; }
.thumb .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-top: 3px; }
.thumb.busy .box::after { content: "올리는 중…"; font-size: 12px; color: var(--muted); font-weight: 400; }
.uploadbtns { display: flex; gap: 8px; flex-wrap: wrap; }
.uploadbtns label { margin: 0; color: var(--text); font-size: 15px; }
.uploadbtns input { display: none; }

/* 결재선 도장칸 */
.stamps { display: flex; border: 1px solid #9aa6b5; border-radius: 4px; overflow: hidden; width: max-content; max-width: 100%; }
.stamp { border-left: 1px solid #9aa6b5; min-width: 92px; text-align: center; font-size: 13px; }
.stamp:first-child { border-left: none; }
.stamp .t { background: #f1f4f8; border-bottom: 1px solid #9aa6b5; padding: 3px 6px; font-weight: 600; }
.stamp .s { height: 54px; display: flex; align-items: center; justify-content: center; }
.stamp .s i { font-style: normal; border: 2px solid var(--bad); color: var(--bad); border-radius: 50%; width: 44px; height: 44px; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 13px; transform: rotate(-12deg); }
.stamp .s i.rej { border-color: #555; color: #555; }
.stamp .n { padding: 2px 6px 4px; }
.stamp .d { font-size: 11px; color: var(--muted); padding-bottom: 4px; }
.line-preview { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; font-size: 14px; }
.line-preview .chip { background: var(--info-bg); color: var(--info); border-radius: 6px; padding: 3px 9px; }
.meta { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 8px 16px; font-size: 14px; }
.meta div span { color: var(--muted); display: inline-block; min-width: 70px; }
.gallery { display: flex; flex-wrap: wrap; gap: 10px; }
.gallery a { display: block; width: 140px; height: 140px; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: #eef1f5; text-decoration: none; }
.gallery img { width: 100%; height: 100%; object-fit: cover; }
.gallery .pdf { display: flex; height: 100%; align-items: center; justify-content: center; flex-direction: column; color: var(--bad); font-weight: 700; font-size: 13px; padding: 8px; text-align: center; }
.gallery .pdf small { color: var(--muted); font-weight: 400; word-break: break-all; }
.comments { font-size: 14px; }
.comments div { padding: 6px 0; border-bottom: 1px dashed var(--line); }

/* 모달·알림 */
dialog { border: none; border-radius: 12px; padding: 0; width: min(520px, calc(100vw - 32px)); box-shadow: 0 20px 50px rgba(0,0,0,.25); }
dialog::backdrop { background: rgba(15, 25, 40, .45); }
#modalBody { padding: 20px; max-height: 85vh; overflow: auto; }
.pwbox { font-size: 22px; font-weight: 700; letter-spacing: 1px; background: #f3f6fa; border: 1px dashed #9aa6b5; border-radius: 8px; padding: 10px; text-align: center; font-family: Consolas, monospace; margin: 6px 0 12px; }
#toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: #1d2530; color: #fff; padding: 10px 18px; border-radius: 8px; font-size: 14px; opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 50; max-width: calc(100vw - 32px); }
#toast.show { opacity: 1; }
#toast.bad { background: var(--bad); }

.leave-card { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; background: linear-gradient(90deg, #e8f5ef, #f2f8ff); }

/* 모바일: 표를 카드처럼 */
@media (max-width: 640px) {
  main { padding: 14px 12px 60px; }
  .card { padding: 14px; }
  table.list thead { display: none; }
  table.list, table.list tbody, table.list tr, table.list td { display: block; width: 100%; }
  table.list tr { border-bottom: 1px solid var(--line); padding: 8px 4px; }
  table.list td { border: none; padding: 2px 6px; }
  table.list td[data-l]::before { content: attr(data-l) " "; color: var(--muted); font-size: 12px; }
  table.list td.num { text-align: left; }
  .stamp { min-width: 76px; }
}

@media print {
  #topbar, .actions, .noprint, #toast { display: none !important; }
  body { background: #fff; }
  main { padding: 0; max-width: none; }
  .card { border: none; padding: 0 0 12px; }
  .gallery a { width: 45%; height: auto; page-break-inside: avoid; }
  .gallery img { object-fit: contain; }
}
