/* 견적 관리 시스템 — 외부 CDN 없이 사내망에서도 동작하도록 자체 스타일 */
:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --ink: #1d2433;
  --ink-2: #4a5468;
  --muted: #8a93a6;
  --line: #e2e5eb;
  --line-strong: #c9ced8;
  --accent: #1f4e8c;
  --accent-ink: #ffffff;
  --accent-soft: #e8eef8;
  --ok: #1e7a4c;  --ok-soft: #e3f3ea;
  --warn: #9a6200; --warn-soft: #fbf0dc;
  --bad: #b3261e; --bad-soft: #fbe6e4;
  --gray-soft: #eceef2;
  --radius: 6px;
  --font: "Malgun Gothic", "맑은 고딕", "Apple SD Gothic Neo", "Noto Sans KR", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { font-family: var(--font); font-size: 14px; color: var(--ink); background: var(--bg); line-height: 1.5; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 20px; margin: 0; }
h2 { font-size: 16px; margin: 0 0 12px; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.center { text-align: center; }
.muted { color: var(--muted); }
.nowrap { white-space: nowrap; }

/* ---- 상단 바 ---- */
.topbar { background: var(--ink); color: #fff; }
.topbar .inner { max-width: 1280px; margin: 0 auto; padding: 0 20px; height: 52px; display: flex; align-items: center; gap: 28px; }
.brand { color: #fff; font-weight: 700; font-size: 15px; letter-spacing: -0.2px; }
.brand:hover { text-decoration: none; }
.brand-logo { height: 36px; width: auto; margin-right: 12px; padding: 2px 6px; background: #fff; border-radius: var(--radius); vertical-align: middle; }
.brand small { color: #9fb0cc; font-weight: 400; margin-left: 6px; }
.nav { display: flex; gap: 4px; flex: 1; }
.nav a { color: #c8d1e0; padding: 6px 12px; border-radius: var(--radius); }
.nav a:hover, .nav a.active { color: #fff; background: rgba(255,255,255,.1); text-decoration: none; }
.nav-count { display: inline-block; min-width: 18px; height: 18px; line-height: 18px; padding: 0 5px; margin-left: 6px; border-radius: 9px; background: var(--bad); color: #fff; font-size: 11px; font-weight: 700; text-align: center; vertical-align: 1px; }
.userbox { display: flex; align-items: center; gap: 10px; color: #c8d1e0; font-size: 13px; }
.userbox a, .userbox button { color: #c8d1e0; background: none; border: 0; font: inherit; cursor: pointer; padding: 0; }
.userbox a:hover, .userbox button:hover { color: #fff; }

/* ---- 본문 ---- */
.container { max-width: 1280px; margin: 0 auto; padding: 24px 20px 60px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.page-head .sub { color: var(--muted); font-size: 13px; margin-top: 2px; }
.home-logo { height: 88px; width: auto; display: block; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; margin-bottom: 16px; }
.card.flush { padding: 0; overflow-x: auto; }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.span-2 { grid-column: span 2; }
.span-all { grid-column: 1 / -1; }

/* ---- 버튼 ---- */
.btn { display: inline-flex; align-items: center; gap: 4px; height: 34px; padding: 0 14px; border-radius: var(--radius);
       border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink); font: inherit; font-size: 13px;
       cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--gray-soft); text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { background: #183f73; }
.btn.danger { color: var(--bad); border-color: #e5b4b0; }
.btn.danger:hover { background: var(--bad-soft); }
.btn.sm { height: 28px; padding: 0 10px; font-size: 12px; }
.btn.icon { width: 28px; padding: 0; justify-content: center; }
form.inline { display: inline; }

/* ---- 폼 ---- */
label.fl { display: block; font-size: 12px; color: var(--ink-2); margin-bottom: 4px; font-weight: 600; }
label.fl .req { color: var(--bad); }
.input, select.input, textarea.input {
  width: 100%; height: 34px; padding: 0 10px; border: 1px solid var(--line-strong); border-radius: var(--radius);
  font: inherit; font-size: 13px; background: #fff; color: var(--ink);
}
textarea.input { height: auto; min-height: 80px; padding: 8px 10px; resize: vertical; }
.input:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.input.num { text-align: right; }
.field-error { color: var(--bad); font-size: 12px; margin-top: 3px; }
.input.is-invalid { border-color: var(--bad); }
.check { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; cursor: pointer; }
.searchbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: flex-end; }
.searchbar .input { width: auto; min-width: 140px; }
.form-foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }

/* ---- 표 ---- */
table.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl th { text-align: left; font-weight: 600; color: var(--ink-2); background: #f8f9fb; border-bottom: 1px solid var(--line);
          padding: 9px 12px; white-space: nowrap; }
.tbl th.num { text-align: right; }
.tbl th.center { text-align: center; }
.tbl td { border-bottom: 1px solid var(--line); padding: 9px 12px; vertical-align: middle; }
.tbl tbody tr:hover { background: #fafbfc; }
.tbl tr.group td { background: var(--accent-soft); font-weight: 600; color: var(--accent); }
.tbl tr.subtotal td { background: #f8f9fb; font-weight: 600; }
.tbl tr.total td { font-weight: 700; }
.tbl tr.grand td { font-weight: 700; font-size: 15px; background: var(--accent-soft); }
.tbl .empty { text-align: center; color: var(--muted); padding: 40px 0; }
.tbl tr.inactive td { color: var(--muted); }

/* 견적 품목 입력 표 */
.lines { width: 100%; border-collapse: collapse; font-size: 13px; min-width: 1050px; }
.lines th { background: #f8f9fb; font-weight: 600; color: var(--ink-2); padding: 8px 6px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
.lines td { padding: 4px 3px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.lines .input { height: 30px; padding: 0 6px; }
.lines td.amount { text-align: right; padding-right: 10px; font-weight: 600; white-space: nowrap; }
.lines .handle { color: var(--muted); text-align: center; width: 28px; }
.totals { width: 360px; margin-left: auto; border-collapse: collapse; font-size: 14px; }
.totals td { padding: 6px 10px; }
.totals tr.grand td { border-top: 2px solid var(--ink); font-weight: 700; font-size: 16px; }
.totals .input { height: 30px; width: 140px; text-align: right; }

/* ---- 배지 ---- */
.badge { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.badge.secondary { background: var(--gray-soft); color: var(--ink-2); }
.badge.primary { background: var(--accent-soft); color: var(--accent); }
.badge.success { background: var(--ok-soft); color: var(--ok); }
.badge.danger { background: var(--bad-soft); color: var(--bad); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.dark { background: #dfe2e8; color: #3a4252; }
.badge.cat { background: #f1f3f6; color: var(--ink-2); font-weight: 500; }

/* ---- 알림 ---- */
.alert { padding: 10px 14px; border-radius: var(--radius); margin-bottom: 16px; font-size: 13px; }
.alert.ok { background: var(--ok-soft); color: var(--ok); }
.alert.err { background: var(--bad-soft); color: var(--bad); }
.alert.warn { background: var(--warn-soft); color: var(--warn); }

/* ---- 상세 ---- */
dl.kv { display: grid; grid-template-columns: 100px 1fr; gap: 8px 12px; margin: 0; font-size: 13px; }
dl.kv dt { color: var(--muted); }
dl.kv dd { margin: 0; }
.amount-hero { display: flex; align-items: baseline; gap: 14px; flex-wrap: wrap; }
.amount-hero .big { font-size: 26px; font-weight: 700; letter-spacing: -0.5px; font-variant-numeric: tabular-nums; }
.amount-hero .kor { color: var(--ink-2); font-size: 13px; }
.pre { white-space: pre-wrap; }

/* ---- 대시보드 ---- */
.quick { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: 12px; margin-bottom: 20px; }
.quick a { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; color: var(--ink); }
.quick a:hover { border-color: var(--accent); text-decoration: none; }
.quick b { display: block; font-size: 15px; margin-bottom: 2px; }
.quick span { font-size: 12px; color: var(--muted); }

/* ---- 페이지 ---- */
.pager { display: flex; justify-content: center; gap: 4px; padding: 14px 0; }
.pager a, .pager span { min-width: 30px; height: 30px; display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid var(--line); border-radius: var(--radius); background: #fff; font-size: 13px; padding: 0 8px; }
.pager .cur { background: var(--accent); color: #fff; border-color: var(--accent); }

/* ---- 로그인 ---- */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.login-box { width: 360px; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 32px 30px; }
.login-logo { display: block; height: 96px; width: auto; margin: 0 auto 20px; }
.login-box h1 { font-size: 18px; margin-bottom: 4px; }
.login-box .sub { color: var(--muted); font-size: 13px; margin-bottom: 22px; }
.login-box .row { margin-bottom: 14px; }
.login-box .btn { width: 100%; justify-content: center; height: 40px; font-size: 14px; }
.login-alt { text-align: center; font-size: 13px; color: var(--muted); margin-top: 16px; }
.signup-box { width: 400px; }
.signup-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }

@media (max-width: 900px) {
  .grid-2, .grid-3, .grid-4, .quick { grid-template-columns: 1fr; }
  .span-2 { grid-column: auto; }
  .topbar .inner { gap: 12px; overflow-x: auto; }
  .totals { width: 100%; }
}

/* ===== Ref 기반 견적 작성 ===== */
.jump { display: flex; gap: 2px; margin-top: 6px; flex-wrap: wrap; }
.jump a { font-size: 12px; color: var(--ink-2); padding: 3px 8px; border-radius: 4px; background: var(--gray-soft); }
.jump a:hover { background: var(--accent-soft); color: var(--accent); text-decoration: none; }
.ref-block, .manual-block { border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px 6px; }
.manual-block + .manual-block { margin-top: 12px; }
.ref-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 6px; font-size: 13px; }
.ref-head .muted { font-size: 12px; }
.lines.compact { min-width: 0; }
.lines.compact.wide { min-width: 1100px; }
.lines.compact th { padding: 6px 4px; font-size: 12px; }
.lines.compact td { padding: 3px 2px; }
.lines.compact tfoot td { border-bottom: 0; padding-top: 6px; font-size: 12px; color: var(--ink-2); }
.lines textarea.input { height: 30px; min-height: 30px; padding: 5px 6px; resize: vertical; line-height: 1.35; }
.w-num { width: 72px; }
.w-act { width: 34px; }
.input[readonly] { background: #f6f7f9; color: var(--ink-2); }
table.dimmed { opacity: .4; pointer-events: none; }
.ref-totals { display: flex; flex-wrap: wrap; gap: 6px 18px; font-size: 12px; color: var(--ink-2); padding: 10px 2px 0; }

.with-bottombar { padding-bottom: 96px; }
.bottombar { position: fixed; left: 0; right: 0; bottom: 0; background: var(--surface); border-top: 1px solid var(--line-strong);
             box-shadow: 0 -2px 8px rgba(0,0,0,.05); z-index: 10; }
.bottombar .inner { max-width: 1280px; margin: 0 auto; padding: 10px 20px; display: flex; align-items: center; gap: 28px; justify-content: flex-end; font-size: 13px; }
.bottombar b { font-size: 16px; margin-left: 6px; font-variant-numeric: tabular-nums; }
.proposal-amt { color: var(--bad); }

.tbl tr.statutory td { background: #faf8f2; }
.tbl tr.proposal td { background: #fff9c4; font-weight: 700; font-size: 15px; }
.tbl tr.proposal td:last-child { color: var(--bad); }
.tbl.detail { font-size: 12px; }
.tbl.detail td, .tbl.detail th { padding: 6px 8px; }
.cost-check-title { padding: 12px 16px; font-weight: 600; font-size: 13px; border-bottom: 1px solid var(--line); }
.cost-check-title .muted { font-weight: 400; font-size: 12px; margin-left: 6px; }
.cost-check .neg { color: var(--bad); font-weight: 600; }
.cost-check table { table-layout: fixed; min-width: 840px; }   /* 위아래 표의 열 위치를 맞춤 */
.cost-check .cost-input { width: 100%; height: 28px; padding: 0 6px; font-size: 12px; }
.cost-check-state { margin-left: 10px; }
.cost-check-state[hidden] { display: none; }
.cost-check-state .btn { height: 24px; padding: 0 8px; font-size: 12px; margin-left: 6px; }
.line-basis { margin-top: 3px; font-size: 11px; line-height: 1.5; color: var(--ink-2); }
.line-basis-calc { font-variant-numeric: tabular-nums; color: var(--accent); }
.detail-toggle { cursor: pointer; padding: 12px 16px; font-weight: 600; font-size: 13px; color: var(--accent); }
details[open] > .detail-toggle { border-bottom: 1px solid var(--line); }
.input.changed { border-color: var(--warn); background: var(--warn-soft); }

/* 부서·직급 관리 */
.code-title { font-size: 15px; margin: 4px 0 10px; }
.code-add { display: flex; gap: 8px; padding: 12px; }
.code-add .input[name=name] { flex: 1; }
.code-add .input[name=sortOrder] { width: 80px; }
label.fl .fl-link { font-weight: 400; margin-left: 6px; font-size: 11px; }

/* 계정관리 목록 필터 */
.user-filter { margin-bottom: 12px; align-items: center; }
.user-filter .filter-count { color: var(--muted); font-size: 13px; margin-left: 4px; }

/* 품목 그룹 탭 */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 14px; flex-wrap: wrap; }
.tabs a { padding: 9px 16px; color: var(--ink-2); border: 1px solid transparent; border-bottom: none;
          border-radius: var(--radius) var(--radius) 0 0; margin-bottom: -1px; font-weight: 600; font-size: 14px; }
.tabs a:hover { background: var(--gray-soft); text-decoration: none; }
.tabs a.active { background: var(--surface); border-color: var(--line); color: var(--accent); }
.tab-tools { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.import-bar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 10px 14px; margin-bottom: 12px; }
.import-bar .muted { font-size: 12px; }
.paste-import { padding: 10px 14px; margin-bottom: 12px; }
.paste-import summary { cursor: pointer; }
.paste-import .muted { font-size: 12px; }
.paste-import form { margin-top: 8px; }
.paste-import textarea { margin-top: 6px; white-space: pre; overflow: auto; font-size: 12px; }
.import-errors ul { margin: 6px 0 0; padding-left: 18px; max-height: 240px; overflow-y: auto; }
.vendor-sub { font-size: 11px; line-height: 1.4; }
#vendorFields[hidden] { display: none; }
.md-card { max-width: 720px; }
.md-note { font-size: 12px; max-width: 720px; line-height: 1.6; }
.md-items-title { margin-top: 28px; }
.ref-sum-label { margin-left: 8px; }

/* 추가 견적 섹션 순서 */
.extra-order { margin-top: 10px; padding: 10px 12px; background: #f8f9fb; border: 1px dashed var(--line); border-radius: var(--radius); font-size: 13px; }
.extra-order-head { display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; margin-bottom: 6px; }
.extra-order-head .muted { font-size: 12px; }
.extra-order-list { margin: 0; padding-left: 22px; }
.extra-order-list li { display: flex; align-items: center; gap: 6px; padding: 3px 0; }
.extra-order-list li::marker { color: var(--muted); }
.extra-order-name { font-weight: 600; min-width: 140px; }
.extra-order-list .muted { font-size: 12px; margin-right: 6px; }
.extra-order-empty { font-size: 12px; }

/* WCS 산출 방식 */
.wcs-mode { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.wcs-mode .muted { font-size: 12px; flex-basis: 100%; }
.hidden { display: none !important; }

.wcs-rates { display: flex; align-items: flex-end; gap: 12px; flex-wrap: wrap; margin-top: 10px; }
.wcs-rates label.fl { display: flex; flex-direction: column; gap: 4px; margin: 0; }
.wcs-rates .input { width: 90px; }
.wcs-rates .muted { font-size: 12px; flex: 1; min-width: 260px; }
#sec-ref.locked { opacity: .5; }
#sec-ref.locked input { background: #f3f4f6; cursor: not-allowed; }
.login-checks { display: flex; gap: 16px; flex-wrap: wrap; }
a.btn.busy { opacity: .6; pointer-events: none; }

/* 단가 변경 이력 */
.price-history td.up { color: #c0392b; }
.price-history td.down { color: #1f6fd1; }
.price-history td.changes { white-space: normal; line-height: 1.5; }
.rough-groups { margin-top: 6px; }
/* 산정 기준 › 가견적 품목 */
.rough-tbl td { padding-top: 4px; padding-bottom: 4px; }
.rough-tbl tfoot tr.add-row td { background: #f7faf7; }

/* 품목 변경 확인창 (item-check.js) */
dialog.item-check { border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; width: min(560px, calc(100vw - 32px)); }
dialog.item-check::backdrop { background: rgba(0, 0, 0, .4); }
dialog.item-check h2 { margin: 0 0 8px; }
dialog.item-check ul { margin: 12px 0; padding-left: 18px; max-height: 50vh; overflow-y: auto; }
dialog.item-check li { margin-bottom: 8px; }

/* 견적서 첨부파일 */
.attach-card { position: relative; }
.attach-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding: 14px 20px; }
.attach-head h2 { margin: 0; font-size: 16px; }
.attach-note { font-weight: 400; font-size: 12px; margin-left: 6px; }
.attach-upload { display: flex; align-items: center; gap: 8px; }
.attach-limit { font-size: 12px; }
.attach-progress { padding: 0 20px 12px; }
.attach-progress .bar { height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; }
.attach-progress .bar span { display: block; height: 100%; width: 0; background: var(--accent); transition: width .2s; }
.attach-progress .text { font-size: 12px; margin-top: 6px; word-break: break-all; }
.attach-off { margin: 0 20px 14px; }
.attach-empty { padding: 4px 20px 16px; font-size: 13px; }
.attach-card.dragover { outline: 2px dashed var(--accent); outline-offset: -4px; }
.attach-drop { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; background: rgba(255,255,255,.85);
               color: var(--accent); font-weight: 600; pointer-events: none; z-index: 1; }
.attach-drop[hidden] { display: none; }
.attach-head.flat { padding: 0 0 10px; }
.attach-list { list-style: none; margin: 0; padding: 0; font-size: 13px; }
.attach-list li { display: flex; align-items: center; gap: 10px; padding: 7px 0; border-top: 1px solid var(--line); }
.attach-list li:first-child { border-top: 0; }
.attach-list li > span:first-of-type, .attach-list li > a { word-break: break-all; }
.attach-list li .btn.icon { margin-left: auto; }
.attach-list li.selected > span:first-of-type::before { content: "대기"; font-size: 11px; color: var(--muted); border: 1px solid var(--line); border-radius: 3px; padding: 0 4px; margin-right: 6px; }
.attach-list li.uploaded > span:first-of-type::before { content: "올라감"; font-size: 11px; color: var(--ok); border: 1px solid var(--ok); border-radius: 3px; padding: 0 4px; margin-right: 6px; }
.attach-form .attach-progress { padding: 8px 0 0; }
.attach-form .attach-off { margin: 0; }
.w-act3 { width: 92px; }
.row-acts { white-space: nowrap; }
.row-acts .btn.icon { width: 26px; }
.row-acts .btn.icon + .btn.icon { margin-left: 2px; }
.attach-folder { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; padding: 4px 0 10px; }
.attach-folder .fl { margin: 0; }
.attach-folder .input { width: 320px; max-width: 100%; }
.attach-folder .muted { font-size: 12px; }
