/* ==========================================================================
   wprofitcc 모바일 전용 화면 — 카드형 입력, 하단 탭, 큰 터치 영역 (PC 와 같은 색 체계)
   ========================================================================== */
:root {
  --bg: #f4f5f7; --surface: #fff; --surface-2: #f8f9fb; --surface-3: #f1f3f6; --hover: #f3f6fd;
  --text: #111827; --text-2: #4b5563; --text-3: #9ca3af;
  --line: #e5e7eb; --line-soft: #eef0f3; --line-2: #cfd4dc;
  --accent: #3b5bdb; --accent-hover: #2f4bc4; --accent-soft: #eef2ff;
  --pos: #15803d; --neg: #dc2626; --neg-soft: #fef2f2; --warn: #b45309;
  --sys: #3b5bdb; --sys-soft: #eef3ff; --sale: #b45309; --sale-soft: #fff4e0;
  --radius: 14px; --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(17, 24, 39, .04), 0 1px 3px rgba(17, 24, 39, .06);
  --font: "Pretendard Variable", Pretendard, -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Malgun Gothic", "Segoe UI", Roboto, sans-serif;
  --top-h: 56px; --tab-h: 60px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body { font-family: var(--font); font-size: 15px; line-height: 1.45; color: var(--text); background: var(--bg); -webkit-font-smoothing: antialiased; font-feature-settings: "tnum" 1; overflow-x: hidden; }
h1, h2, h3 { margin: 0; font-weight: 600; }
h1 { font-size: 17px; }
h3 { font-size: 14px; display: flex; align-items: center; gap: 8px; }
h3::before { content: ""; width: 3px; height: 14px; border-radius: 2px; background: var(--accent); }
h3 .small { font-weight: 400; color: var(--text-3); }
p { margin: 0; }
.muted { color: var(--text-3); }
.small { font-size: 12px; font-weight: 400; }
.spacer { height: 88px; }
[hidden] { display: none !important; }

/* ---------- 상단 바 / 하단 탭 ---------- */
.mtop {
  position: sticky; top: 0; z-index: 30; height: var(--top-h);
  display: flex; align-items: center; justify-content: space-between; padding: 0 14px;
  background: var(--surface); border-bottom: 1px solid var(--line);
  padding-top: env(safe-area-inset-top);
}
.mbrand { display: flex; align-items: center; gap: 10px; }
.logo { display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: 8px; background: var(--accent); color: #fff; font-weight: 700; font-size: 15px; }
.mtop-actions { display: none; align-items: center; gap: 8px; }
body[data-view="calc"] .mtop-actions.calc-only { display: flex; }
body[data-view="board"] .mtop-actions.board-only, body[data-view="settings"] .mtop-actions.board-only { display: flex; }
.status { font-size: 12px; color: var(--text-2); display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--line); }
.status::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--text-3); }
.status.api::before { background: var(--pos); }
.status.local::before { background: var(--warn); }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; height: calc(var(--tab-h) + env(safe-area-inset-bottom));
  display: grid; grid-template-columns: repeat(3, 1fr); background: var(--surface); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar.four { grid-template-columns: repeat(4, 1fr); }
body[data-view="formulas"] .mtop-actions.board-only { display: flex; }
.doc-kicker { font-size: 11px; font-weight: 700; letter-spacing: .08em; color: var(--accent); }
.sec-no { display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 6px; background: var(--accent); color: #fff; font-size: 12px; font-weight: 700; margin-right: 2px; }

/* 기준표 선택 칩 */
.chips { display: flex; gap: 6px; overflow-x: auto; padding: 2px 0 10px; margin: 0 -14px 4px; padding-left: 14px; padding-right: 14px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chips button { flex-shrink: 0; height: 36px; padding: 0 14px; border-radius: 999px; border: 1px solid var(--line-2); background: var(--surface); font: inherit; font-size: 13px; font-weight: 500; color: var(--text-2); }
.chips button.on { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 700; }
.spane { display: none; }
.spane.on { display: block; }

/* 계산식 카드 */
.fcard { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 10px; box-shadow: var(--shadow); }
.fcard .f-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.fcard .f-head b { font-size: 15px; }
.fcard .f-head .excel { font-size: 11px; color: var(--text-3); }
.fcard .f-desc { font-size: 12px; color: var(--text-2); margin-top: 2px; }
.fcard .f-def { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12px; color: var(--text-3); margin-top: 8px; word-break: break-all; }
.fcard input.fx { margin-top: 8px; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 14px; }
.fcard input.fx.changed { border-color: var(--accent); background: var(--accent-soft); }
.fcard input.fx.err { border-color: #fca5a5; background: var(--neg-soft); }
.fcard .f-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 8px; font-size: 13px; }
.fcard .f-prev { color: var(--text-2); }
.fcard .f-prev b { color: var(--text); font-variant-numeric: tabular-nums; }
.fcard .f-prev.err { color: var(--neg); font-size: 12px; }
.fcard .fields2 { padding: 0; margin-top: 8px; }
.fref { background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; font-size: 12px; color: var(--text-2); line-height: 1.7; }
.fref code { font-family: ui-monospace, Menlo, Consolas, monospace; background: var(--surface); border: 1px solid var(--line); border-radius: 4px; padding: 0 4px; color: var(--accent); }
.tabbar button { border: 0; background: transparent; font: inherit; font-size: 12px; font-weight: 500; color: var(--text-3); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; cursor: pointer; }
.tabbar button .ti { font-size: 20px; line-height: 1; }
.tabbar button.on { color: var(--accent); font-weight: 700; }

.fab {
  position: fixed; right: 16px; bottom: calc(var(--tab-h) + 16px + env(safe-area-inset-bottom)); z-index: 25;
  height: 48px; padding: 0 18px; border: 0; border-radius: 999px; background: var(--accent); color: #fff;
  font: inherit; font-size: 15px; font-weight: 600; box-shadow: 0 8px 20px rgba(59, 91, 219, .35); cursor: pointer; display: none;
}
body[data-view="calc"] .fab.calc-only { display: inline-flex; align-items: center; }
.fab:active { background: var(--accent-hover); }

main { padding: 14px 14px 0; }
.view { display: none; }
.view.active { display: block; }

/* ---------- 버튼 / 입력 ---------- */
.btn, .menu-list button, .menu-list label, .menu-list a {
  font: inherit; font-size: 14px; font-weight: 500; line-height: 1; height: 40px; padding: 0 14px; border-radius: var(--radius-sm);
  border: 1px solid var(--line-2); background: var(--surface); color: var(--text); cursor: pointer; white-space: nowrap;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; text-decoration: none;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.subtle { border-color: transparent; background: transparent; color: var(--text-2); }
.btn.danger { color: var(--neg); }
.btn.sm { height: 34px; padding: 0 12px; font-size: 13px; }
.btn.excel { color: #15803d; border-color: #a7e3bd; background: #f0fdf4; font-weight: 600; }
.btn.icon { width: 40px; padding: 0; font-size: 18px; }
.btn.icon.sm { width: 34px; }
.btn.block { width: 100%; height: 46px; margin-top: 10px; font-size: 15px; }
.btn:disabled { opacity: .5; }
.btn:active { filter: brightness(.96); }
input[type="text"], input[type="search"], input[type="date"], select {
  font: inherit; font-size: 16px; color: var(--text); background: var(--surface); width: 100%;
  height: 44px; padding: 0 12px; border: 1px solid var(--line-2); border-radius: var(--radius-sm); min-width: 0;
}
input:focus, select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
input::placeholder { color: var(--text-3); }
input.num { text-align: right; font-variant-numeric: tabular-nums; }
.withunit { display: flex; align-items: center; gap: 6px; }
.withunit input { flex: 1 1 0; width: 0; }
.unit { color: var(--text-3); font-size: 13px; flex-shrink: 0; }

.menu { position: relative; }
.menu > summary { list-style: none; }
.menu > summary::-webkit-details-marker { display: none; }
.menu-list { position: absolute; right: 0; top: calc(100% + 6px); z-index: 40; min-width: 210px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 12px 32px rgba(17, 24, 39, .16); padding: 6px; display: flex; flex-direction: column; }
.menu-list button, .menu-list label, .menu-list a { border: 0; border-radius: 8px; justify-content: flex-start; font-weight: 400; height: 42px; }
.menu-list button:active, .menu-list label:active, .menu-list a:active { background: var(--surface-2); }
.menu-list hr { border: 0; border-top: 1px solid var(--line); margin: 4px 0; }

/* ---------- 문서 헤더 / KPI ---------- */
.doc { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.title-input { font-size: 18px; font-weight: 700; border-color: transparent; background: transparent; padding: 0 8px; margin-left: -8px; height: 40px; }
.memo-input { font-size: 14px; color: var(--text-2); border-color: transparent; background: transparent; padding: 0 8px; margin-left: -8px; height: 34px; }
.title-input:focus, .memo-input:focus { background: var(--surface); }
.doc-state { font-size: 12px; color: var(--text-3); }
.doc-state.dirty { color: var(--warn); }

.kpis { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 14px; }
.kpi { position: relative; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 10px 12px 10px 14px; overflow: hidden; }
.kpi::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--line-2); }
.kpi.k1::before { background: #94a3b8; } .kpi.k2::before { background: var(--sys); } .kpi.k3::before { background: var(--sale); } .kpi.k4::before { background: var(--text-3); }
.kpi.pos::before { background: var(--pos); } .kpi.neg::before { background: var(--neg); }
.kpi .k-label { font-size: 11px; color: var(--text-2); font-weight: 500; }
.kpi .k-value { font-size: 17px; font-weight: 700; margin-top: 2px; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi .k-sub { font-size: 11px; color: var(--text-3); margin-top: 1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi.pos .k-value { color: var(--pos); } .kpi.neg .k-value { color: var(--neg); }

.list-head { display: flex; align-items: center; justify-content: space-between; margin: 4px 0 8px; }
.lh-title { font-size: 15px; font-weight: 600; display: inline-flex; align-items: center; gap: 6px; }
.count { font-size: 12px; font-weight: 600; color: var(--text-2); background: var(--surface-3); border-radius: 999px; padding: 2px 8px; }

/* ---------- 상품 카드 ---------- */
.cards { display: flex; flex-direction: column; gap: 10px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.card-h { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-bottom: 1px solid var(--line); background: var(--surface-2); }
.card-h .no { display: inline-grid; place-items: center; width: 24px; height: 24px; border-radius: 6px; background: var(--surface-3); color: var(--text-2); font-size: 12px; font-weight: 600; flex-shrink: 0; }
.card-h input.name { flex: 1; height: 36px; border-color: transparent; background: transparent; font-weight: 600; font-size: 16px; padding: 0 6px; }
.card-h input.name:focus { background: var(--surface); }
.card-h .ib { width: 32px; height: 32px; border: 0; background: transparent; color: var(--text-3); font-size: 15px; border-radius: 8px; flex-shrink: 0; }
.card-h .ib:active { background: var(--surface-3); color: var(--text); }
.card-h .ib.danger:active { color: var(--neg); }
.fields2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 10px; padding: 12px; }
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field .lbl { font-size: 12px; color: var(--text-2); font-weight: 500; display: flex; align-items: center; gap: 6px; }
.field.wide { grid-column: 1 / -1; }
.results { border-top: 1px solid var(--line); }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); background: var(--sale-soft); }
.stat { padding: 10px 8px; text-align: center; border-right: 1px solid rgba(180, 83, 9, .12); }
.stat:last-child { border-right: 0; }
.stat .s-label { font-size: 11px; color: var(--sale); font-weight: 600; }
.stat .s-value { font-size: 17px; font-weight: 700; margin-top: 2px; font-variant-numeric: tabular-nums; }
.stat .s-value.neg { color: var(--neg); } .stat .s-value.pos { color: var(--pos); }
.kv { display: flex; justify-content: space-between; align-items: center; padding: 8px 14px; border-top: 1px solid var(--line-soft); font-size: 13px; }
.kv span { color: var(--text-2); }
.kv b { font-weight: 600; font-variant-numeric: tabular-nums; }
.kv.dim b { font-weight: 500; color: var(--text-2); }
.kv.sys span::before, .kv.sale span::before { content: ""; display: inline-block; width: 6px; height: 6px; border-radius: 2px; margin-right: 6px; vertical-align: 1px; }
.kv.sys span::before { background: var(--sys); } .kv.sale span::before { background: var(--sale); }
.kv.custom span::before { content: ""; display: inline-block; width: 6px; height: 6px; border-radius: 2px; margin-right: 6px; vertical-align: 1px; background: #15803d; }
.kv.custom { background: #f6fef9; }
details.more { border-top: 1px solid var(--line); }
details.more summary { list-style: none; padding: 9px 14px; font-size: 12px; color: var(--text-3); cursor: pointer; display: flex; justify-content: space-between; }
details.more summary::-webkit-details-marker { display: none; }
details.more summary::after { content: "▾"; }
details.more[open] summary::after { content: "▴"; }
.card.neg .card-h { border-bottom-color: #fecaca; }
.badge { display: inline-flex; align-items: center; justify-content: center; min-width: 24px; height: 22px; padding: 0 7px; border-radius: 999px; font-size: 12px; font-weight: 700; }
.badge.g1 { background: #fee2e2; color: #b91c1c; } .badge.g2 { background: #ffedd5; color: #c2410c; } .badge.g3 { background: #fef3c7; color: #a16207; } .badge.g4 { background: #dcfce7; color: #15803d; } .badge.g5 { background: #dbeafe; color: #1d4ed8; }
.empty { text-align: center; color: var(--text-3); padding: 36px 12px; background: var(--surface); border: 1px dashed var(--line-2); border-radius: var(--radius); font-size: 14px; }

details.sec { margin-top: 16px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 0 12px 12px; }
details.sec > summary { list-style: none; padding: 12px 0; font-weight: 600; font-size: 15px; cursor: pointer; display: flex; align-items: center; gap: 8px; }
details.sec > summary::-webkit-details-marker { display: none; }
details.sec > summary::before { content: "▸"; color: var(--text-3); font-size: 12px; }
details.sec[open] > summary::before { content: "▾"; }
.note { font-size: 11px; color: var(--text-3); line-height: 1.6; margin-top: 10px; }

.basis { margin-top: 14px; padding: 12px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); font-size: 12px; color: var(--text-2); line-height: 1.8; }
.basis b { color: var(--text); font-weight: 600; }
.basis a { color: var(--accent); font-weight: 500; }

/* ---------- 게시판 ---------- */
.search { display: flex; gap: 8px; margin-bottom: 12px; }
.search .btn { flex-shrink: 0; height: 44px; }
.bcard { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow); }
.bcard .b-title { font-size: 16px; font-weight: 700; display: flex; align-items: center; gap: 8px; }
.bcard .b-title::before { content: ""; width: 8px; height: 8px; border-radius: 2px; background: var(--accent); flex-shrink: 0; }
.bcard .b-sub { font-size: 13px; color: var(--text-2); margin-top: 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bcard .b-memo { font-size: 12px; color: var(--text-3); margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bcard .b-foot { display: flex; align-items: center; gap: 8px; margin-top: 10px; }
.bcard .b-date { font-size: 12px; color: var(--text-3); flex: 1; }
.bcard .b-foot .btn { height: 34px; padding: 0 12px; font-size: 13px; }

/* ---------- 설정 ---------- */
.sec-block { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; box-shadow: var(--shadow); }
.sec-block > h3 { margin-bottom: 12px; }
.sec-block .fields { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.gcard { border: 1px solid var(--line); border-radius: var(--radius-sm); margin-bottom: 10px; overflow: hidden; }
.gcard header { display: flex; align-items: center; gap: 8px; padding: 8px 12px; background: var(--surface-2); border-bottom: 1px solid var(--line); font-size: 13px; }
.gcard header .gout { margin-left: auto; color: var(--text-2); }
.gcard header .gout b { color: var(--text); }
.gcard .fields2 { padding: 10px 12px; }
.trow { display: grid; grid-template-columns: 22px 1fr 1fr; gap: 8px; align-items: center; padding: 6px 0; border-bottom: 1px solid var(--line-soft); }
.trow:last-of-type { border-bottom: 0; }
.trow .tno { font-size: 12px; color: var(--text-3); text-align: center; }
.trow .rng { display: flex; align-items: center; gap: 4px; font-size: 13px; }
.trow .rng .lo { min-width: 44px; text-align: right; color: var(--text-3); font-variant-numeric: tabular-nums; }
.trow .rng input { height: 38px; padding: 0 8px; font-size: 15px; }
.trow .rng .unit { font-size: 12px; }
.trow.open .rng .lo { color: var(--text); font-weight: 600; }
.trow .val { display: flex; align-items: center; gap: 4px; }
.trow .val input { height: 38px; padding: 0 8px; font-size: 15px; }
.tier-actions { display: flex; gap: 6px; justify-content: flex-end; margin-top: 10px; }
.actionbar {
  position: fixed; left: 0; right: 0; bottom: calc(var(--tab-h) + env(safe-area-inset-bottom)); z-index: 25;
  display: flex; align-items: center; gap: 8px; padding: 10px 14px; background: rgba(255, 255, 255, .96); border-top: 1px solid var(--line); backdrop-filter: blur(6px);
}
.actionbar .grow { flex: 1; }
.settings-note { font-size: 12px; color: var(--text-3); line-height: 1.6; margin-top: 8px; }

/* ---------- 토스트 ---------- */
.toast { position: fixed; left: 50%; bottom: calc(var(--tab-h) + 24px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: #111827; color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 13px; z-index: 60; box-shadow: 0 10px 30px rgba(0, 0, 0, .25); max-width: 90vw; }
.toast.error { background: var(--neg); }
.toast.ok { background: var(--pos); }
