:root {
  --bg: #f6f7f9; --panel: #fff; --line: #dde1e6; --text: #1d2329; --muted: #6b7480;
  --accent: #1f5fae; --accent-soft: #e8f0fb; --sec1: #fff4d6; --sec2: #fbf8ec; --sec3: #fdfcf6;
  --sel: #dcebff; --err: #b3261e; --ok: #1b7a3e; --excl: #f3e8ff;
}
* { box-sizing: border-box; }
body { margin: 0; font: 13px/1.45 "Malgun Gothic", "Apple SD Gothic Neo", system-ui, sans-serif; color: var(--text); background: var(--bg); }
.hidden { display: none !important; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; border: 1px solid var(--line); background: #fff; border-radius: 6px; padding: 5px 10px; }
button:hover { border-color: #b9c1cb; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.danger { color: var(--err); }
button.link { border: 0; background: none; color: var(--accent); padding: 2px 4px; }
button:disabled { opacity: .5; cursor: default; }
input, select, textarea { border: 1px solid var(--line); border-radius: 5px; padding: 4px 6px; background: #fff; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.muted { color: var(--muted); }
.err { color: var(--err); min-height: 1em; }
.num { text-align: right; font-variant-numeric: tabular-nums; }

.login-card { width: 340px; margin: 12vh auto; background: var(--panel); padding: 28px; border-radius: 12px; border: 1px solid var(--line); display: flex; flex-direction: column; gap: 12px; }
.login-card h1 { margin: 0; font-size: 20px; }
.login-card label { display: flex; flex-direction: column; gap: 4px; }

.top { display: flex; align-items: center; gap: 24px; padding: 0 16px; height: 48px; background: #1d2b3a; color: #fff; position: sticky; top: 0; z-index: 20; }
.top .brand { font-weight: 700; font-size: 15px; }
.top nav { display: flex; gap: 4px; flex: 1; }
.top nav a { color: #cfd8e3; text-decoration: none; padding: 6px 12px; border-radius: 6px; }
.top nav a.on { background: rgba(255,255,255,.14); color: #fff; }
.top .me { color: #cfd8e3; }
.top .me button.link { color: #9cc3ff; }
main { padding: 16px; }

.bar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 12px; }
.bar h2 { margin: 0 12px 0 0; font-size: 18px; }
.bar .spacer { flex: 1; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; }
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 12px; }
.tabs button { border: 0; border-bottom: 2px solid transparent; border-radius: 0; background: none; padding: 8px 14px; color: var(--muted); }
.tabs button.on { color: var(--accent); border-bottom-color: var(--accent); font-weight: 700; }

table.grid { border-collapse: collapse; width: 100%; background: #fff; }
table.grid th, table.grid td { border: 1px solid var(--line); padding: 3px 6px; vertical-align: middle; }
table.grid th { background: #eef2f7; font-weight: 600; position: sticky; top: 0; z-index: 2; white-space: nowrap; }
table.grid tr:hover td { background: #fafcff; }
table.grid tr.sel td { background: var(--sel) !important; }
table.grid tr.l1 td { background: var(--sec1); font-weight: 700; }
table.grid tr.l2 td { background: var(--sec2); font-weight: 600; }
table.grid tr.l3 td { background: var(--sec3); font-weight: 600; }
table.grid tr.excl td.c-name::after { content: " 별도계상"; color: #7b3fbf; font-size: 11px; font-weight: 400; }
table.grid tr.sub td { background: #f2f2f2; font-weight: 700; }
table.grid td input, table.grid td select { width: 100%; border: 1px solid transparent; background: transparent; padding: 2px 4px; }
table.grid td input:hover, table.grid td select:hover { border-color: var(--line); }
table.grid td input:focus { background: #fff; }
table.grid td input.num { text-align: right; }
table.grid tr.excl-line td { color: #888; font-style: italic; }
.scroll { overflow: auto; max-height: calc(100vh - 210px); border: 1px solid var(--line); border-radius: 8px; }
.kind { font-size: 11px; padding: 1px 6px; border-radius: 10px; background: #eef2f7; white-space: nowrap; }
.kind.hobo { background: #e6f4ea; color: var(--ok); }
.kind.labor { background: #fff0e0; color: #9a5b00; }
.kind.mat { background: #eef2ff; color: #3949ab; }
.kind.fixed { background: #f3f3f3; }
.indent { display: inline-block; }

.split { display: grid; grid-template-columns: 380px 1fr; gap: 12px; }
.list { max-height: calc(100vh - 200px); overflow: auto; }
.list .item { padding: 7px 10px; border-bottom: 1px solid var(--line); cursor: pointer; }
.list .item:hover { background: #fafcff; }
.list .item.on { background: var(--sel); }
.list .item .t { font-weight: 600; }
.list .item .s { color: var(--muted); font-size: 12px; }

.drawer { position: fixed; top: 48px; right: 0; bottom: 0; width: 560px; background: #fff; border-left: 1px solid var(--line); box-shadow: -8px 0 24px rgba(0,0,0,.08); z-index: 15; display: flex; flex-direction: column; }
.drawer .head { padding: 10px 12px; border-bottom: 1px solid var(--line); display: flex; gap: 8px; align-items: center; }
.drawer .body { overflow: auto; flex: 1; }
.res-row { padding: 6px 12px; border-bottom: 1px solid #eef0f3; cursor: pointer; display: grid; grid-template-columns: 1fr auto; gap: 8px; }
.res-row:hover { background: #f5f9ff; }
.res-row .c { font-size: 11px; color: var(--muted); }
.res-row .p { text-align: right; font-size: 12px; white-space: nowrap; }

.modal { position: fixed; inset: 0; background: rgba(0,0,0,.3); z-index: 30; display: flex; align-items: flex-start; justify-content: center; padding-top: 6vh; }
.modal-box { background: #fff; border-radius: 12px; width: min(1100px, 94vw); max-height: 86vh; overflow: auto; padding: 16px 18px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.modal-head h3 { margin: 0; }
.form { display: grid; grid-template-columns: 140px 1fr; gap: 8px 12px; align-items: center; max-width: 640px; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: #1d2b3a; color: #fff; padding: 9px 16px; border-radius: 8px; z-index: 40; }
.toast.err { background: var(--err); }
.sheet td.k { width: 260px; }
.sheet tr.s2 td { background: #eef2f7; font-weight: 700; }
.sheet tr.s1 td { font-weight: 700; }
.chip { display: inline-block; padding: 2px 8px; border-radius: 10px; background: #eef2f7; font-size: 12px; margin-right: 4px; }
.hint { color: var(--muted); font-size: 12px; }
.summary { display: flex; gap: 18px; padding: 8px 12px; background: #fff; border: 1px solid var(--line); border-radius: 8px; margin-bottom: 10px; flex-wrap: wrap; }
.summary b { font-variant-numeric: tabular-nums; }
@media (max-width: 900px) { .split { grid-template-columns: 1fr; } .drawer { width: 100%; } }

/* ---- 그리드 표준: 열 너비 조정·정렬·행 머리 선택 ---- */
table.grid.fixed { table-layout: fixed; }
table.grid.fixed td { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
table.grid.fixed td input:not([type=checkbox]), table.grid.fixed td select { width: 100% !important; min-width: 0 !important; }
table.grid th { user-select: none; }
.col-rs { position: absolute; right: -4px; top: 0; bottom: 0; width: 8px; cursor: col-resize; z-index: 3; }
.col-rs:hover { background: rgba(31,95,174,.25); }
table.grid th.s-asc::after { content: " ▲"; font-size: 10px; color: var(--accent); }
table.grid th.s-desc::after { content: " ▼"; font-size: 10px; color: var(--accent); }
#lg td.rh { background: #f1f4f8; color: var(--muted); text-align: center; cursor: pointer; font-size: 11px; user-select: none; }
#lg tr.sel td.rh { background: var(--accent) !important; color: #fff; }
#lg thead th:first-child { cursor: pointer; }
#lg tr.cut td { opacity: .5; }
#lg tr.cut td.rh { outline: 1px dashed var(--accent); outline-offset: -2px; }
#lg td.c-name { position: relative; }
#lg td.c-name .tag-sep { position: absolute; right: 4px; top: 50%; transform: translateY(-50%); background: var(--excl); color: #7b3fbf; }
#lg td.lk.open { cursor: pointer; }
#lg td.lk.open:hover { background: #eef7f0; }
.cc b { font-weight: 600; color: var(--accent); }
.bar.tb { gap: 6px; }
.bar.tb select { padding: 4px 6px; }
.bar .sep { width: 1px; height: 22px; background: var(--line); display: inline-block; margin: 0 2px; }
.sortbar { background: #fff8e1; border: 1px solid #f0d58a; border-radius: 6px; padding: 5px 10px; margin-bottom: 8px; font-size: 12px; }
.summary [data-go] { cursor: default; border-bottom: 1px dotted transparent; }
.summary [data-go]:hover { border-bottom-color: var(--muted); }
p.keys { margin: 6px 2px 0; }
#pg tbody tr[data-pid] { cursor: default; }
