:root {
  --bg: #e6ecf0;           /* 화면 바탕 (패널이 도드라지도록 약간 어둡게) */
  --panel: #ffffff;
  --line: #cfd8df;
  --line-strong: #9fadb9;
  --text: #17212b;
  --muted: #5b6875;
  --brand: #0f6e74;
  --brand-dark: #0a4f54;
  --brand-soft: #dff0f1;
  --grid-head: #0d5a60;    /* 그리드 머리글 */
  --grid-head2: #2a7b81;   /* 그리드 묶음 머리글 */
  --zebra: #f2f6f8;        /* 짝수행 */
  --hover: #e3f2f3;
  --sel: #ffe28a;          /* 선택행 (머리글 청록과 구분되는 노랑) */
  --sel-line: #e07b00;
  --danger: #c0392b;
  --warn: #b7791f;
  --ok: #2f855a;
  --radius: 6px;
  --ctl-h: 32px;           /* 입력·버튼 높이 (모바일에서 키움) */
  --row-h: 32px;           /* 그리드 행 높이 (모바일에서 키움) */
  font-family: "Malgun Gothic", "맑은 고딕", "Apple SD Gothic Neo", Arial, sans-serif;
  font-size: 13px;
  color: var(--text);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); }
button, input, select, textarea { font: inherit; color: inherit; }

/* ---------- 로그인 ---------- */
.login-wrap { min-height: 100%; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login-card { width: 100%; max-width: 380px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 32px 28px; box-shadow: 0 8px 28px rgba(15, 40, 60, .12); }
.login-card h1 { margin: 0 0 4px; font-size: 21px; color: var(--brand-dark); }
.login-card p { margin: 0 0 24px; color: var(--muted); }
.login-card label { display: block; margin: 14px 0 5px; font-weight: 700; }
.login-card input { width: 100%; height: 42px; border: 1px solid var(--line-strong); border-radius: 6px; padding: 0 10px; font-size: 15px; }
.login-card .btn { width: 100%; height: 44px; margin-top: 22px; font-size: 15px; }
.login-note { margin-top: 14px; font-size: 12px; color: var(--muted); }

/* ---------- 레이아웃 ---------- */
.shell { display: grid; grid-template-columns: 196px 1fr; grid-template-rows: 50px 1fr; height: 100vh; height: 100dvh; }
.topbar { grid-column: 1 / 3; display: flex; align-items: center; gap: 14px; padding: 0 16px; background: var(--brand-dark); color: #fff; box-shadow: 0 2px 6px rgba(0,0,0,.15); z-index: 20; }
.topbar .title { font-size: 16px; font-weight: 700; letter-spacing: .5px; white-space: nowrap; }
.topbar .spacer { flex: 1; }
.topbar .info { font-size: 12px; opacity: .92; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar select { height: 30px; border-radius: 4px; border: 0; padding: 0 6px; color: var(--text); }
.topbar .btn-ghost { color: #fff; border-color: rgba(255,255,255,.55); }
.topbar .burger { display: block; flex: none; width: 40px; height: 40px; border: 0; background: transparent; color: #fff; font-size: 22px; cursor: pointer; padding: 0; }
.nav { background: var(--panel); border-right: 1px solid var(--line); padding: 0 0 12px; overflow-y: auto; }
.nav-dim { display: none; }
/* 그룹 제목 : 배경 띠 + 진한 색 + 굵게 (클릭 불가) */
.nav .group {
  display: flex; align-items: center; gap: 6px;
  margin-top: 10px; padding: 8px 14px;
  background: #dfe7ec; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line);
  font-size: 12px; font-weight: 800; color: var(--brand-dark); letter-spacing: .5px;
  cursor: default; user-select: none;
}
.nav .group:first-child { margin-top: 0; border-top: 0; }
.nav .group::before { content: ""; width: 4px; height: 12px; border-radius: 2px; background: var(--brand); }
/* 메뉴 항목 : 들여쓰기 + 점 표시 */
.nav a { display: flex; align-items: center; gap: 8px; padding: 9px 14px 9px 26px; color: var(--text); text-decoration: none; border-left: 3px solid transparent; cursor: pointer; font-size: 13px; }
.nav a::before { content: ""; width: 5px; height: 5px; border-radius: 50%; background: #9fadb9; flex: none; }
.nav a:hover { background: var(--hover); }
.nav a:hover::before { background: var(--brand); }
.nav a.active { background: var(--brand-soft); color: var(--brand-dark); font-weight: 700; border-left-color: var(--brand); }
.nav a.active::before { background: var(--brand); }
.main { overflow: auto; padding: 14px 16px 28px; min-width: 0; }
.page-title { display: flex; align-items: baseline; flex-wrap: wrap; gap: 4px 10px; margin: 0 0 10px; }
.page-title h2 { margin: 0; font-size: 18px; color: var(--brand-dark); }
.page-title span { color: var(--muted); font-size: 12px; }

/* ---------- 패널 / 폼 ---------- */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 12px; box-shadow: 0 1px 3px rgba(15, 40, 60, .07); min-width: 0; }
.panel-head { display: flex; align-items: center; flex-wrap: wrap; gap: 6px 8px; margin-bottom: 10px; padding-bottom: 8px; border-bottom: 1px solid #e3e9ee; }
.panel-head h3 { margin: 0; font-size: 14px; color: var(--brand-dark); }
.panel-head .sub { color: var(--muted); font-size: 12px; }
.panel-head .right { margin-left: auto; display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.panel-head .right .field { flex-direction: row; align-items: center; gap: 6px; margin-left: 8px; }
.panel-head .right .field > label { white-space: nowrap; }
.cols { display: grid; gap: 12px; }
.cols-2 { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
.cols-73 { grid-template-columns: minmax(0, 7fr) minmax(0, 5fr); }
@media (max-width: 1100px) { .cols-2, .cols-73 { grid-template-columns: 1fr; } }

.form { display: flex; flex-wrap: wrap; gap: 8px 14px; align-items: flex-end; }
.field { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.field > label { font-size: 12px; color: var(--muted); font-weight: 700; }
.field > label.req::after { content: " *"; color: var(--danger); }
.field input, .field select, .field textarea { height: var(--ctl-h); border: 1px solid var(--line-strong); border-radius: 4px; padding: 0 8px; background: #fff; min-width: 0; }
.field input:focus, .field select:focus { outline: 2px solid rgba(15,110,116,.3); border-color: var(--brand); }
.field input[readonly] { background: #eef2f5; color: var(--muted); }
.w-xs { width: 70px; } .w-s { width: 100px; } .w-m { width: 140px; } .w-l { width: 200px; } .w-xl { width: 300px; }
.codefield { display: flex; align-items: center; gap: 4px; }
.codefield .code { width: 110px; }
.codefield .name { width: 170px; background: #eef2f5; color: var(--text); }
.codefield button { height: var(--ctl-h); width: 34px; padding: 0; }
.chk { display: flex; align-items: center; gap: 5px; min-height: var(--ctl-h); font-weight: 400; }
.chk input { width: 16px; height: 16px; }
.chk-group { display: flex; gap: 12px; flex-wrap: wrap; }

/* ---------- 버튼 ---------- */
.btn { height: var(--ctl-h); padding: 0 14px; border-radius: 4px; border: 1px solid var(--line-strong); background: #fff; cursor: pointer; white-space: nowrap; font-weight: 600; }
.btn:hover { background: var(--hover); }
.btn:disabled { opacity: .45; cursor: default; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); }
.btn-danger { color: #fff; background: var(--danger); border-color: var(--danger); }
.btn-danger:hover { background: #a93226; }
.btn-ghost { background: transparent; }

/* ---------- 그리드 (시인성) ----------
   머리글 = 진한 청록 + 흰 글씨 / 줄무늬 / 진한 테두리 / 선택행 = 진한 청록 바탕 + 굵게 + 왼쪽 강조 */
.grid-wrap { border: 1px solid var(--line-strong); border-radius: 4px; overflow: auto; background: #fff; -webkit-overflow-scrolling: touch; }
.grid { border-collapse: separate; border-spacing: 0; width: max-content; min-width: 100%; }
.grid th, .grid td { padding: 0 9px; height: var(--row-h); border-bottom: 1px solid #d9e1e7; border-right: 1px solid #e3e9ee; white-space: nowrap; text-align: center; }
.grid th { position: sticky; top: 0; z-index: 2; background: var(--grid-head); color: #fff; font-weight: 700; font-size: 12px; border-right: 1px solid rgba(255,255,255,.18); border-bottom: 0; }
.grid th input[type=checkbox] { accent-color: #fff; }
/* 머리글은 항상 중앙 · 데이터는 문자형 중앙 / 숫자형(.num) 오른쪽 */
.grid th, .grid th.num { text-align: center; }
.grid td.num { text-align: right; font-variant-numeric: tabular-nums; }
.grid td.ctr { text-align: center; }
.grid td.left { text-align: left; }
.grid thead tr.group-row th { top: 0; height: 26px; background: var(--grid-head2); color: #fff; border-bottom: 1px solid rgba(255,255,255,.25); }
.grid thead tr.group-row th.grp { border-left: 2px solid rgba(255,255,255,.45); }
.grid thead tr.group-row + tr th { top: 26px; }
.grid tbody tr { cursor: pointer; }
.grid tbody tr:nth-child(even) td { background: var(--zebra); }
.grid tbody tr:hover td { background: var(--hover); }
.grid tbody tr.sel td, .grid tbody tr.sel:hover td { background: var(--sel); color: #3b2a00; font-weight: 700; border-bottom-color: #f0c24a; }
.grid tbody tr.sel td:first-child { box-shadow: inset 5px 0 0 var(--sel-line); }
.grid tbody tr.dim td { color: #8b97a3; }
.grid tbody tr.dim.sel td { color: #6b5a2a; }
.grid td input.cell { width: 90px; height: 26px; border: 1px solid var(--line-strong); border-radius: 3px; text-align: right; padding: 0 4px; background: #fff; }
.grid td input[type=checkbox], .grid th input[type=checkbox] { width: 16px; height: 16px; }
.grid .empty { color: var(--muted); text-align: center; padding: 20px; cursor: default; background: #fff !important; font-weight: 400 !important; }
.grid-resize { height: 12px; margin-top: 2px; display: flex; align-items: center; justify-content: center; cursor: ns-resize; touch-action: none; user-select: none; border-radius: 4px; }
.grid-resize span { width: 48px; height: 4px; border-radius: 2px; background: var(--line-strong); }
.grid-resize:hover, .grid-resize.on { background: rgba(15,110,116,.12); }
.grid-resize:hover span, .grid-resize.on span { background: #0f6e74; }
.grid-foot { display: flex; flex-wrap: wrap; gap: 4px 12px; justify-content: space-between; color: var(--muted); font-size: 12px; padding: 5px 2px 0; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 11px; font-weight: 700; background: #dfe5ea; color: #33414d; }
.badge.b10 { background: #dfe5ea; } .badge.b30 { background: #ffe8b8; color: #8a5a00; }
.badge.b80 { background: #c9ecd5; color: #1d6b3f; } .badge.b99, .badge.bY { background: #f8d0cb; color: #9b2c22; }

/* ---------- 탭 ---------- */
.tabs { display: flex; gap: 2px; border-bottom: 2px solid var(--brand); margin-bottom: 12px; overflow-x: auto; }
.tabs button { border: 1px solid var(--line); border-bottom: 0; background: #d5dee4; padding: 9px 18px; border-radius: 6px 6px 0 0; cursor: pointer; color: #3d4852; font-weight: 700; white-space: nowrap; }
.tabs button.active { background: var(--brand); border-color: var(--brand); color: #fff; }

/* ---------- 모달 / 토스트 ---------- */
.modal-back { position: fixed; inset: 0; background: rgba(15, 25, 35, .45); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 16px; }
.modal { background: #fff; border-radius: 8px; width: 100%; max-width: 640px; max-height: 88vh; display: flex; flex-direction: column; box-shadow: 0 12px 40px rgba(0,0,0,.25); }
.modal-head { display: flex; align-items: center; padding: 12px 16px; background: var(--brand-dark); color: #fff; border-radius: 8px 8px 0 0; }
.modal-head h3 { margin: 0; font-size: 15px; }
.modal-head .x { margin-left: auto; color: #fff; border-color: rgba(255,255,255,.5); }
.modal-body { padding: 14px 16px; overflow: auto; }
.modal-body .grid-wrap { max-height: 50vh; }
.modal-foot { padding: 10px 16px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 6px; }
#toast-area { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 100; max-width: 420px; }
.toast { padding: 11px 14px; border-radius: 6px; color: #fff; background: #34495e; box-shadow: 0 4px 14px rgba(0,0,0,.2); line-height: 1.4; font-weight: 600; }
.toast.ok { background: var(--ok); } .toast.err { background: var(--danger); } .toast.warn { background: var(--warn); }
.hint { color: var(--muted); font-size: 12px; }

/* ---------- 표 안 입력 (반입 팝업 · 상세 입력행) ---------- */
.modal.modal-wide { max-width: 1180px; }
.btn-xs { height: 26px; padding: 0 7px; font-size: 12px; }
.cell-codebox { display: inline-flex; align-items: center; gap: 3px; }
.cell-codebox .cell-name { color: var(--muted); font-size: 12px; max-width: 140px; overflow: hidden; text-overflow: ellipsis; font-weight: 400; }
.grid td input.cell-code, .grid td input.cell-text, .grid td input.cell-date, .grid td select.cell-sel, .grid td select {
  height: 26px; border: 1px solid var(--line-strong); border-radius: 3px; padding: 0 4px; background: #fff; font-weight: 400;
}
.grid td input.cell-text { width: 140px; }
.grid td input.cell-date { width: 130px; }
.grid tbody tr.pending td { background: #fff3c4 !important; }
.grid tbody tr.locked td { color: #8b97a3; cursor: not-allowed; }
.grid tbody tr.locked:hover td { background: inherit; }
.grid tbody tr.deleted td { background: #fbe0dc !important; text-decoration: line-through; color: #8b97a3; }
.grid-wrap.sgrid:focus { outline: 3px solid rgba(15,110,116,.4); outline-offset: 1px; }
.grid-wrap:focus-visible { outline: 3px solid rgba(15,110,116,.4); }
.sel-info { padding: 6px 8px; background: var(--brand-soft); border-radius: 4px; margin-bottom: 8px; font-size: 12px; line-height: 1.6; }
.sel-info b { color: var(--brand-dark); }

/* =============================================================================================
   태블릿 · 모바일 (폭 760px 이하)
   - 왼쪽 메뉴 → ☰ 버튼으로 여닫는 서랍
   - 입력칸 한 줄 꽉 차게, 버튼 · 그리드 행 40px 이상 (손가락 터치)
   - 팝업 전체 화면
   ============================================================================================= */
@media (max-width: 760px) {
  :root { --ctl-h: 42px; --row-h: 42px; font-size: 14px; }
  .shell { grid-template-columns: minmax(0, 1fr); grid-template-rows: 54px minmax(0, 1fr); }
  .topbar { grid-column: 1; gap: 6px; padding: 0 6px; min-width: 0; overflow: hidden; }
  .topbar .burger { display: block; flex: none; }
  .topbar .title { font-size: 14px; flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
  .topbar .spacer { display: none; }
  .topbar .info { display: none; }
  .topbar select { flex: 0 1 auto; max-width: 104px; min-width: 0; height: 34px; }
  .topbar .btn-ghost { flex: none; padding: 0 8px; height: 34px; }
  .chk { white-space: nowrap; }
  .nav {
    position: fixed; top: 54px; left: 0; bottom: 0; width: 250px; z-index: 30;
    transform: translateX(-100%); transition: transform .2s ease; box-shadow: 4px 0 16px rgba(0,0,0,.2);
  }
  .shell.nav-open .nav { transform: translateX(0); }
  .shell.nav-open .nav-dim { display: block; position: fixed; inset: 54px 0 0 0; background: rgba(0,0,0,.35); z-index: 25; }
  .nav a { padding: 13px 16px 13px 28px; font-size: 15px; }
  .nav .group { padding: 10px 16px; font-size: 13px; }
  .main { grid-column: 1; padding: 10px 8px 24px; }
  .panel { padding: 10px; }
  .panel-head .right { margin-left: 0; width: 100%; }
  .panel-head .right .btn { flex: 1 1 auto; }
  .form { gap: 10px; }
  .form > .field { flex: 1 1 100%; }
  .form > .field input, .form > .field select { width: 100% !important; }
  .form > .btn { flex: 1 1 auto; }
  .codefield { width: 100%; }
  .codefield .code { flex: 0 0 38%; width: auto; }
  .codefield .name { flex: 1 1 auto; width: auto; }
  .codefield button { width: 44px; }
  .grid th { font-size: 13px; }
  .grid td { font-size: 14px; }
  .grid td input.cell, .grid td input.cell-code, .grid td input.cell-text, .grid td input.cell-date, .grid td select { height: 34px; }
  .grid td input[type=checkbox], .grid th input[type=checkbox] { width: 20px; height: 20px; }
  .btn-xs { height: 34px; padding: 0 10px; }
  .tabs button { padding: 11px 14px; flex: 1 0 auto; }
  .modal-back { padding: 0; align-items: stretch; }
  .modal, .modal.modal-wide { max-width: none; max-height: none; height: 100%; border-radius: 0; }
  .modal-head { border-radius: 0; }
  .modal-foot .btn { flex: 1; }
  #toast-area { left: 8px; right: 8px; bottom: 8px; max-width: none; }
}

/* 필수 입력칸 - 연노랑 배경 + 주황 테두리 (비활성 · 읽기전용은 제외) */
input.req:not(:disabled):not([readonly]), select.req:not(:disabled), textarea.req:not(:disabled),
.codefield.req > input.code:not(:disabled), .cell-codebox.req > input.cell-code:not(:disabled) {
  background: #fff6c8; border-color: #e3b341;
}
input.req:not(:disabled):focus, select.req:not(:disabled):focus,
.codefield.req > input.code:focus, .cell-codebox.req > input.cell-code:focus { background: #fffbe3; }

/* 그리드 건수 - 패널 / 팝업 제목 옆 */
.grid-count { display: inline-block; margin-left: 8px; padding: 1px 8px; border-radius: 10px; background: var(--brand-soft); color: var(--brand-dark); font-size: 12px; font-weight: 700; vertical-align: middle; }
.grid-count:empty { display: none; }
.grid td.seq { color: var(--muted); font-variant-numeric: tabular-nums; }
.grid tbody tr.sel td.seq { color: #3b2a00; }

/* 행 상세 버튼 칼럼 - 오른쪽 고정 */
.grid th.detail-col, .grid td.detail-col { position: sticky; right: 0; text-align: center; width: 52px; }
.grid th.detail-col { z-index: 3; }
.grid td.detail-col { z-index: 1; background: #fff; box-shadow: -2px 0 4px rgba(0,0,0,.08); }
.grid tbody tr:nth-child(even) td.detail-col { background: var(--zebra); }
.grid tbody tr:hover td.detail-col { background: var(--hover); }
.grid tbody tr.sel td.detail-col { background: var(--sel); }
/* 행 상세 팝업 */
.modal.modal-detail { max-width: 860px; }
.kv-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); border-top: 1px solid var(--line); border-left: 1px solid var(--line); }
.kv-item { display: grid; grid-template-columns: 44% 1fr; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); min-height: 32px; }
.kv-k { background: #eef3f5; color: #43545e; font-size: 12px; padding: 6px 8px; word-break: break-all; text-align: left; }
.kv-v { padding: 6px 8px; word-break: break-all; text-align: right; }
.kv-v.num { font-variant-numeric: tabular-nums; }
.kv-item.shown .kv-k { color: var(--brand-dark); font-weight: 700; background: var(--brand-soft); }
.kv-item.blank .kv-v { color: #b3bec6; }

/* PC : ☰ 로 왼쪽 메뉴 숨기기 (모바일은 서랍 방식 그대로) */
.topbar .burger:hover { background: rgba(255,255,255,.12); border-radius: 4px; }
@media (min-width: 761px) {
  .shell.nav-hidden { grid-template-columns: 0 minmax(0, 1fr); }
  .shell.nav-hidden > .nav, .shell.nav-hidden > .nav-dim { display: none; }
  .shell.nav-hidden > .main { grid-column: 2; grid-row: 2; }
}

/* 칼럼 폭 조절 (머리글 오른쪽 끝 드래그) */
.grid th .col-rsz { position: absolute; top: 0; right: 0; width: 7px; height: 100%; cursor: col-resize; touch-action: none; z-index: 3; }
.grid th .col-rsz:hover, .grid th .col-rsz.on { background: rgba(255,255,255,.45); }
.grid.fixed { table-layout: fixed; min-width: 0; }
.grid.fixed th, .grid.fixed td { overflow: hidden; text-overflow: ellipsis; }

/* 인쇄 미리보기 팝업 */
.modal.modal-print { max-width: 1000px; height: 92vh; max-height: 92vh; }
.modal-body.print-body { flex: 1; padding: 0; overflow: hidden; background: #e6eaee; }
.print-frame { width: 100%; height: 100%; border: 0; display: block; background: #e6eaee; }
