* { box-sizing: border-box; }
:root {
  --bg: #f4f6fa;
  --card: #fff;
  --line: #dde2ea;
  --text: #1f2937;
  --muted: #6b7280;
  --primary: #2b3a8c;
  --primary-dark: #1f2a6b;
  --accent: #d62828;
  --danger: #c53030;
  --warn: #b45309;
  --ok: #15803d;
}
body {
  margin: 0;
  font-family: '맑은 고딕', 'Malgun Gothic', 'Apple SD Gothic Neo', sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}
.hidden { display: none !important; }

.topbar {
  display: flex; align-items: center; gap: 18px;
  padding: 10px 24px; background: #fff; border-bottom: 3px solid var(--primary);
  position: sticky; top: 0; z-index: 20;
}
.topbar .logo { height: 22px; }
.topbar h1 { font-size: 17px; margin: 0; color: var(--primary); }
.topbar nav { display: flex; gap: 4px; margin-left: 12px; }
.tab { background: transparent; color: var(--muted); border: 0; padding: 8px 14px; border-radius: 6px; cursor: pointer; font: inherit; }
.tab:hover { background: #eef1f8; color: var(--text); }
.tab.active { background: var(--primary); color: #fff; font-weight: 600; }

main { max-width: 1400px; margin: 0 auto; padding: 18px 20px; }
.panel { display: none; }
.panel.active { display: block; }

.toolbar { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.status { color: var(--muted); font-size: 13px; margin-left: auto; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: #fff; }
.seg button { border: 0; border-radius: 0; background: #fff; padding: 8px 16px; font: inherit; cursor: pointer; color: var(--muted); }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.on { background: var(--primary); color: #fff; font-weight: 600; }
.card-head .seg button { padding: 6px 12px; font-size: 13px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 14px 18px; margin-bottom: 14px; }
.card h2 { font-size: 15px; margin: 0 0 12px; }
.card h2 small { font-weight: normal; color: var(--muted); font-size: 12px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.card-head h2 { margin: 0; }
.actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.hint { color: var(--muted); margin: 10px 0 0; font-size: 12.5px; }
.hint:empty { display: none; }

.grid { display: grid; gap: 10px 14px; }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.grid label.wide { grid-column: 1 / -1; }
.grid label.w2 { grid-column: span 2; }
.grid label.req { color: var(--text); font-weight: 600; }
.grid .sub { margin-top: 10px; }
.grid.sub { margin-top: 12px; padding-top: 12px; border-top: 1px dashed var(--line); }
.chk-row { flex-direction: row !important; align-items: center; flex-wrap: wrap; gap: 6px !important; color: var(--text) !important; font-size: 13px !important; padding-top: 18px; }
.chk-row input { width: auto; }
.chk-row small { flex-basis: 100%; color: var(--muted); font-size: 11.5px; }
.info { grid-column: span 3; background: #f5f7fc; border-radius: 8px; padding: 8px 12px; font-size: 13px; line-height: 1.6; }

input, select, textarea {
  font: inherit; color: var(--text); padding: 7px 9px;
  border: 1px solid var(--line); border-radius: 6px; background: #fff; width: 100%;
}
input::placeholder { color: #9aa3b2; }
input:focus, select:focus, textarea:focus { outline: 2px solid #c7cff0; border-color: var(--primary); }
textarea { resize: vertical; line-height: 1.5; }
input.num { text-align: right; font-variant-numeric: tabular-nums; }
/* 자동 기입 값: 일반 입력값과 똑같이 진하게 / 직접 고친 값: 노란색 */
input.auto-filled { color: var(--text); }
input.manual { background: #fff4cc; border-color: #e0b100; }

button { font: inherit; cursor: pointer; border-radius: 6px; padding: 8px 14px; }
button.primary { background: var(--primary); color: #fff; border: 1px solid var(--primary); font-weight: 600; }
button.primary:hover { background: var(--primary-dark); }
button.ghost { background: #fff; color: var(--text); border: 1px solid var(--line); }
button.ghost:hover { background: #f1f5f9; }
button.small { padding: 5px 10px; font-size: 12.5px; }
button.icon { background: none; border: 0; color: var(--muted); padding: 4px 8px; }
button.icon:hover { color: var(--danger); }
button.link { background: none; border: 0; color: var(--primary); padding: 3px 5px; }
button.link.danger { color: var(--danger); }

/* 발전기 견적 레이아웃 */
.gen-layout { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 14px; align-items: start; }
.gen-summary .sticky { position: sticky; top: 70px; max-height: calc(100vh - 86px); overflow: auto; }
.margin { display: flex; align-items: center; justify-content: space-between; gap: 10px; font-weight: 600; margin-bottom: 12px; }
.margin input { width: 110px; font-size: 16px; font-weight: 600; }
.big { display: flex; justify-content: space-between; align-items: baseline; padding: 8px 0; border-top: 1px solid var(--line); }
.big span { color: var(--muted); font-size: 13px; }
.big strong { font-size: 19px; font-variant-numeric: tabular-nums; }
.big.total strong { color: var(--primary); font-size: 22px; }
.small-row { display: flex; justify-content: space-between; font-size: 12.5px; color: var(--muted); padding: 2px 0; }
.small-row b { color: var(--text); font-weight: 500; font-variant-numeric: tabular-nums; }
.msgs { list-style: none; margin: 10px 0; padding: 0; font-size: 12.5px; }
.msgs li { padding: 6px 9px; border-radius: 6px; margin-bottom: 5px; line-height: 1.4; }
.msgs .err { background: #fdecec; color: var(--danger); font-weight: 600; }
.msgs .warn { background: #fff7e6; color: var(--warn); }
.msgs .ok { background: #ecfdf3; color: var(--ok); }
details summary { cursor: pointer; font-weight: 600; font-size: 13px; padding: 6px 0; }
table.cost { width: 100%; border-collapse: collapse; font-size: 12px; }
table.cost td { padding: 4px 2px; border-bottom: 1px solid #f0f2f6; vertical-align: top; }
table.cost td small { display: block; color: var(--muted); font-size: 11px; }
table.cost td.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
table.cost tr.sep td { border-top: 2px solid var(--line); font-weight: 600; }
table.cost tr.strong td { color: var(--primary); font-size: 13px; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { background: #f1f5f9; font-weight: 600; font-size: 12px; color: #475569; padding: 8px 6px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
td { padding: 4px 6px; border-bottom: 1px solid #eef1f5; }
table.items td input { padding: 5px 7px; }
table.list td { padding: 9px 6px; }
table.list tr:hover td { background: #f8fafc; }
table.preview td { vertical-align: top; font-size: 13px; padding: 4px; }
table.preview td.no, table.preview td.num { vertical-align: middle; }
table.preview textarea, table.preview input { font-size: 12.5px; padding: 5px 7px; resize: vertical; line-height: 1.45; }
table.preview td:nth-child(3) textarea { min-width: 380px; }
table.preview .c-pname { width: 130px; }
table.preview td.edited textarea, table.preview td.edited input { background: #fff4cc; border-color: #e0b100; }
table.preview .reset { font-size: 16px; color: var(--primary); }
.target-box { margin: 10px 0 4px; padding: 10px 12px; border: 1px dashed #c7cff0; border-radius: 8px; background: #f8f9fe; }
.target-box label { display: flex; flex-direction: column; gap: 4px; font-size: 12.5px; font-weight: 600; }
.target-box label small { font-weight: normal; color: var(--muted); }
.target-box input { font-size: 15px; font-weight: 600; }
.target-preview { margin-top: 8px; font-size: 12.5px; line-height: 1.7; }
.target-preview .row { display: flex; justify-content: space-between; gap: 8px; }
.target-preview .row b { font-variant-numeric: tabular-nums; }
.target-preview .arrow { color: var(--muted); }
.target-preview .up { color: var(--ok); }
.target-preview .down { color: var(--danger); }
.target-preview .note { color: var(--muted); font-size: 11.5px; margin-top: 4px; }
.target-actions { display: flex; gap: 6px; margin-top: 8px; }
.target-locked { font-size: 13px; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.target-locked b { color: var(--primary); }
.margin input:disabled { background: #eef4ff; color: var(--primary); }
.panel-summary { margin-top: 10px; background: #f5f7fc; border-radius: 8px; padding: 9px 12px; font-size: 13px; }
.panel-summary b { color: var(--primary); }
.grid label small { font-weight: normal; }
.panel-box { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.2fr); gap: 12px; align-items: center; }
.panel-memo { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--text); font-weight: 600; }
.panel-memo small { font-weight: normal; color: var(--muted); }
.panel-memo input { background: #fff; }
table.cost tr.outside-head td { padding-top: 10px; color: var(--muted); font-weight: 600; font-size: 11.5px; border-bottom: 1px solid var(--line); }
table.cost td.sep-amt { color: var(--primary); }
.detail-box { margin-top: 16px; padding-top: 14px; border-top: 2px solid var(--line); }
.detail-toggle { display: flex; align-items: center; gap: 8px; font-size: 14px; cursor: pointer; }
.detail-toggle input { width: 18px; height: 18px; }
.detail-box h3 { font-size: 14px; margin: 14px 0 0; }
.detail-box h3 small { display: block; font-weight: normal; color: var(--muted); font-size: 11.5px; margin-top: 3px; }
.c-act2 { width: 64px; white-space: nowrap; text-align: right; }
table.detail .del { font-size: 14px; }
table.detail .del:hover { color: var(--danger); }
.detail-hidden { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-top: 8px; font-size: 12.5px; color: var(--muted); }
.detail-hidden:empty { display: none; }
.detail-hidden button { color: var(--muted); text-decoration: line-through; }
.detail-hidden button b { text-decoration: none; color: var(--primary); font-weight: 600; margin-left: 4px; display: inline-block; }
table.detail input.locked { background: #f3f4f6; color: var(--text); cursor: not-allowed; font-weight: 600; }
table.detail td.auto-adjusted input { background: #eef4ff; border-color: #9db4ea; }
.edited-total { color: #b45309 !important; }
.edited-total::after { content: ' ✎'; font-size: 14px; }
table.preview tr.sum td { background: #ede7f3; font-weight: 600; text-align: center; }
table.preview tr.sum td.num { text-align: right; }
td.acts { white-space: nowrap; }
.c-no { width: 40px; text-align: center; }
.c-unit { width: 70px; }
.c-qty { width: 80px; }
.c-num { width: 130px; text-align: right; }
.c-act { width: 40px; }
.c-cat { width: 120px; }
td.num { text-align: right; font-variant-numeric: tabular-nums; }
td.no { text-align: center; color: var(--muted); }
.empty { text-align: center; color: var(--muted); padding: 24px; }
.count { font-weight: normal; color: var(--muted); font-size: 12px; margin-left: 6px; }
.chk { display: flex; align-items: center; gap: 4px; font-size: 13px; white-space: nowrap; }
.chk input { width: auto; }
#product-search { width: 240px; }
#history-search { width: 260px; }
#prod-filter { width: 200px; }
#prod-cat, #q-vat { width: 140px; }
input.note { font-size: 12px; color: var(--muted); }
tr.flag td { background: #fff7e6; }

.totals { display: flex; justify-content: flex-end; gap: 28px; margin-top: 14px; padding-top: 12px; border-top: 2px solid var(--line); }
.totals div { display: flex; gap: 10px; align-items: baseline; }
.totals span { color: var(--muted); font-size: 13px; }
.totals strong { font-size: 16px; font-variant-numeric: tabular-nums; }
.totals .grand strong { font-size: 20px; color: var(--primary); }

.extras { margin-top: 12px; padding-top: 10px; border-top: 1px dashed var(--line); }
.extras-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; font-size: 13px; }
.extras-head small { color: var(--muted); font-size: 11.5px; }
.extras-head .ex-sum { margin-left: auto; font-weight: 600; color: var(--primary); font-variant-numeric: tabular-nums; }
.extras-head button { margin-left: auto; }
.extras-head .ex-sum + button { margin-left: 0; }
.ex-table { margin-top: 6px; }
.ex-table th { font-size: 11.5px; padding: 5px 6px; }
.ex-table td { padding: 3px 4px; }
.ex-table input { padding: 5px 7px; }
.order-bar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; background: #f5f7fc; border-radius: 8px; padding: 8px 12px; margin-bottom: 10px; }
.order-bar small { color: var(--muted); flex-basis: 100%; }
#sel-count { font-weight: 600; font-size: 13px; }
.c-chk { width: 32px; text-align: center; }
td.c-chk input { width: auto; }
select.st { width: auto; padding: 3px 6px; font-size: 12.5px; }
select.st.s-수주 { background: #eef4ff; border-color: #9db4ea; }
select.st.s-발주완료 { background: #ecfdf3; border-color: #86c79f; color: var(--ok); font-weight: 600; }
#history-status { width: 120px; }
h2.mt { margin-top: 22px !important; }
table.reps { max-width: 620px; margin-bottom: 8px; }
.footer-actions { display: flex; justify-content: flex-end; align-items: center; gap: 10px; padding: 4px 0 40px; }

#toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: #1e293b; color: #fff; padding: 10px 18px; border-radius: 8px;
  opacity: 0; transition: all .2s; pointer-events: none; z-index: 50; max-width: 80vw;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.error { background: var(--danger); }

@media (max-width: 1100px) {
  .gen-layout { grid-template-columns: 1fr; }
  .gen-summary .sticky { position: static; max-height: none; }
}
@media (max-width: 800px) {
  .g4 { grid-template-columns: 1fr 1fr; }
  .topbar { flex-wrap: wrap; }
}

/* 상세 내역 합계 ≠ 견적서 총액 */
#detail-total.mismatch { color: #c62828; font-weight: 700; }
.err-mark { color: #c62828; font-weight: 600; margin-left: 8px; }
.ok-mark { color: #2e7d32; margin-left: 8px; font-weight: 500; }

/* 행 추가 버튼 · 합계 직접 입력 */
.row-tools { margin-top: 8px; }
input.total-input { width: 100%; text-align: right; font-weight: 700; background: #fffbe6; border: 1px solid #e0b100; }
tr.added td.no { color: var(--primary); }

/* 큰 항목 제목 (2. 원가 산출) */
.section-title { margin: 18px 2px 8px; font-size: 17px; }
.section-title small { font-size: 12px; color: var(--muted); font-weight: 400; margin-left: 6px; }
/* 원가 산출 내역 직접 편집 */
table.cost input.ci { border: 1px solid transparent; background: transparent; font: inherit; font-size: 11.5px; padding: 1px 3px; border-radius: 3px; }
table.cost input.ci:hover, table.cost input.ci:focus { border-color: var(--line); background: #fff; }
table.cost input.ci.edited { background: #fff4cc; border-color: #e0b100; }
table.cost input.ci[data-cf="name"] { width: 100%; font-weight: 600; }
table.cost input.cm { display: block; width: 100%; color: var(--muted); }
table.cost input.cq { width: 26px; text-align: right; }
table.cost input.cp { width: 68px; text-align: right; }
table.cost td.c-x { white-space: nowrap; width: 34px; text-align: right; }
table.cost td.c-x .icon { padding: 0 2px; }
table.cost tr.cost-tools td { padding: 6px 2px; }
.detail-hidden.inline { display: inline-flex; margin: 4px 0 0; }
table.cost td:first-child { min-width: 112px; }
table.cost td.c-x { width: 30px; }

/* 구성 단계(카드) 삭제·추가 */
h2[data-card], .custom-card h2 { display: flex; align-items: center; gap: 6px; }
.sec-tools { margin-left: auto; display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 400; }
.sec-tools .off-label { color: #c62828; }
.card.sec-off > :not(h2) { display: none; }
.card.sec-off h2 { color: var(--muted); text-decoration: line-through; margin-bottom: 0; }
.card.sec-off h2 .sec-tools { text-decoration: none; }
.custom-card .sec-title { font: inherit; font-size: 15px; font-weight: 700; border: 1px solid var(--line); border-radius: 4px; padding: 2px 6px; flex: 1; max-width: 360px; }
button.add-section { width: 100%; padding: 12px; border: 1px dashed var(--line); margin-bottom: 14px; }
button.add-section small { color: var(--muted); font-weight: 400; }

/* 로그인 · 가입 화면 */
.login-page { min-height: 100vh; display: flex; align-items: flex-start; justify-content: center; padding: 8vh 16px 24px; }
.login-wrap { width: 100%; max-width: 400px; }
.login-brand { display: flex; align-items: center; gap: 10px; justify-content: center; margin-bottom: 16px; font-size: 18px; font-weight: 700; color: var(--primary); }
.login-brand img { height: 30px; }
.login-card form { display: flex; flex-direction: column; gap: 10px; margin-top: 12px; }
.login-card form[hidden] { display: none; }
.login-card label { display: flex; flex-direction: column; gap: 4px; }
.login-card label small { color: var(--muted); font-weight: 400; }
.login-card .grid.g2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.login-card button.primary { padding: 10px; font-size: 15px; margin-top: 4px; }
.login-seg { display: flex; width: 100%; }
.login-seg button { flex: 1; }
.login-msg { margin: 10px 0 0; font-size: 13px; min-height: 1em; }
.login-msg.err { color: #c62828; }
.login-msg.ok { color: #2e7d32; }
/* 헤더 사용자 표시 */
.user-box { margin-left: auto; display: flex; align-items: center; gap: 8px; font-size: 13px; }
.user-box .uname { font-weight: 600; }
/* 사용자 관리 */
.status-pending { color: #b26a00; font-weight: 600; }
.status-active { color: #2e7d32; }
.status-disabled { color: #c62828; }
/* 헤더: 좁은 화면에서 줄바꿈 (탭 글자가 세로로 쪼개지지 않게) */
.topbar { flex-wrap: wrap; row-gap: 6px; }
.topbar h1, .tab, .user-box, .user-box button { white-space: nowrap; }
.topbar nav { flex-wrap: wrap; }
#tab-users td { white-space: nowrap; }
