:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --line: #e3e6eb;
  --text: #1f2430;
  --muted: #6b7280;
  --blue: #2563eb;
  --blue-soft: #e8f0fe;
  --green: #15803d;
  --green-soft: #e6f4ea;
  --red: #c62828;
  --red-soft: #fdecea;
  --amber: #b45309;
  --amber-soft: #fff4e0;
  --gray-soft: #eef0f3;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: 'Malgun Gothic', 'Apple SD Gothic Neo', 'Noto Sans KR', system-ui, sans-serif;
  font-size: 14px; color: var(--text); background: var(--bg);
}
[hidden] { display: none !important; }
h1, h2, h3 { margin: 0; }
.muted { color: var(--muted); }
.error { color: var(--red); min-height: 1.2em; margin: 6px 0 10px; white-space: pre-wrap; }

/* 로그인 */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: 340px; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 28px; }
.login-card h1 { font-size: 20px; margin-bottom: 4px; }
.login-card label { display: block; margin: 18px 0 6px; font-weight: 600; }

/* 레이아웃 */
.app { display: grid; grid-template-columns: 210px 1fr; min-height: 100vh; }
.side { background: var(--panel); border-right: 1px solid var(--line); padding: 20px 12px; display: flex; flex-direction: column; gap: 6px; position: sticky; top: 0; height: 100vh; }
.brand { font-weight: 700; font-size: 16px; padding: 4px 10px 14px; color: var(--blue); }
.side nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.side nav a { color: var(--text); text-decoration: none; padding: 9px 12px; border-radius: 8px; }
.side nav a:hover { background: var(--gray-soft); }
.side nav a.active { background: var(--blue-soft); color: var(--blue); font-weight: 700; }
.main { padding: 24px 28px 48px; min-width: 0; }
.page-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.page-head h2 { font-size: 20px; }
.spacer { flex: 1; }

/* 패널 / 필터 */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 16px; margin-bottom: 16px; }
.panel h3 { font-size: 15px; margin-bottom: 10px; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.filters label { color: var(--muted); display: inline-flex; align-items: center; gap: 6px; }

input, select, textarea {
  font: inherit; color: inherit; background: #fff;
  border: 1px solid #cfd4dc; border-radius: 8px; padding: 7px 10px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--blue-soft); border-color: var(--blue); }
input:disabled { background: var(--gray-soft); color: var(--muted); }
input[type=checkbox] { width: 16px; height: 16px; padding: 0; accent-color: var(--blue); }
textarea { width: 100%; resize: vertical; min-height: 60px; }

.btn { font: inherit; border: 1px solid #cfd4dc; background: #fff; color: var(--text); padding: 7px 14px; border-radius: 8px; cursor: pointer; }
.btn:hover { background: var(--gray-soft); }
.btn.primary { background: var(--blue); border-color: var(--blue); color: #fff; font-weight: 600; }
.btn.primary:hover { background: #1d4fd0; }
.btn.danger { color: var(--red); border-color: #f0b4b0; }
.btn.danger:hover { background: var(--red-soft); }
.btn.danger.solid { background: var(--red); color: #fff; border-color: var(--red); }
.btn.ghost { border-color: transparent; color: var(--muted); }
.btn.small { padding: 4px 10px; font-size: 13px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* 표 (헤더 고정) */
.tbl-wrap { overflow: auto; max-height: calc(100vh - 290px); border: 1px solid var(--line); border-radius: 10px; background: #fff; }
.tbl-wrap.short { max-height: 420px; }
table { border-collapse: separate; border-spacing: 0; width: 100%; }
th, td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
td.wrap { white-space: normal; }
th { position: sticky; top: 0; background: #f0f2f5; z-index: 2; font-weight: 700; font-size: 13px; color: #374151; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr.click { cursor: pointer; }
tbody tr.click:hover td { background: #f7faff; }
td.num, th.num { text-align: right; }
td.click-month { cursor: pointer; }
td.click-month:hover { background: #f0f2f5; }
td.click-month.active { background: var(--blue-soft); color: var(--blue); font-weight: 700; }
td.empty { text-align: center; color: var(--muted); padding: 28px; }
tr.extra td { background: #fbfcff; }
tr.absent td { background: var(--red-soft); }
.cell-input { width: 100%; min-width: 150px; padding: 5px 8px; }

.badge { display: inline-block; padding: 2px 9px; border-radius: 99px; font-size: 12px; font-weight: 600; background: var(--gray-soft); color: #4b5563; }
.badge.blue { background: var(--blue-soft); color: var(--blue); }
.badge.green { background: var(--green-soft); color: var(--green); }
.badge.red { background: var(--red-soft); color: var(--red); }
.badge.amber { background: var(--amber-soft); color: var(--amber); }

.info { display: flex; gap: 20px; flex-wrap: wrap; color: var(--muted); margin-top: 6px; }
.info b { color: var(--text); font-weight: 600; }
.notice { background: var(--blue-soft); color: #1e3a8a; border-radius: 8px; padding: 10px 12px; margin-bottom: 12px; }
.notice.warn { background: var(--amber-soft); color: #7c4a03; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 12px; }
.tabs button { font: inherit; background: none; border: 0; padding: 9px 16px; cursor: pointer; color: var(--muted); border-bottom: 2px solid transparent; }
.tabs button.active { color: var(--blue); border-bottom-color: var(--blue); font-weight: 700; }

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; margin-bottom: 14px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; }
.card .label { color: var(--muted); font-size: 13px; }
.card .value { font-size: 22px; font-weight: 700; margin-top: 4px; }

/* 캘린더 */
.cal { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; background: #fff; }
.cal .dow { background: #f0f2f5; padding: 8px; font-weight: 700; font-size: 13px; text-align: center; border-bottom: 1px solid var(--line); }
.cal .day { height: 104px; max-height: 104px; padding: 6px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); overflow: hidden; }
.cal .day.expanded { height: auto; max-height: none; }
.cal .day:nth-child(7n) { border-right: 0; }
.cal .day.other { background: #fafbfc; color: #b0b6c0; }
.cal .day .n { font-size: 13px; margin-bottom: 4px; }
.cal .day.today .n { background: var(--blue); color: #fff; border-radius: 99px; display: inline-block; min-width: 22px; text-align: center; padding: 1px 4px; }
.chip { display: block; font-size: 12px; padding: 2px 6px; border-radius: 5px; margin-bottom: 3px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-decoration: none; }
.chip.req { background: var(--blue-soft); color: var(--blue); }
.chip.app { background: var(--green-soft); color: var(--green); }
.more-toggle { display: block; width: 100%; text-align: left; font-size: 11px; color: var(--blue); background: none; border: 0; padding: 1px 0; cursor: pointer; }
.more-toggle:hover { text-decoration: underline; }
.month-nav { display: flex; align-items: center; gap: 8px; }
.month-nav strong { min-width: 110px; text-align: center; font-size: 17px; }

/* 모달 */
.overlay { position: fixed; inset: 0; background: rgba(17, 24, 39, .45); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal { background: #fff; border-radius: 14px; width: min(520px, 100%); max-height: 92vh; display: flex; flex-direction: column; box-shadow: 0 20px 60px rgba(0, 0, 0, .25); }
.modal.wide { width: min(920px, 100%); }
.modal header { padding: 16px 20px; border-bottom: 1px solid var(--line); font-weight: 700; font-size: 16px; }
.modal .body { padding: 16px 20px; overflow: auto; }
.modal footer { padding: 12px 20px; border-top: 1px solid var(--line); display: flex; gap: 8px; justify-content: flex-end; align-items: center; }
.field { margin-bottom: 12px; }
.field label { display: block; margin-bottom: 5px; font-weight: 600; }
.field input, .field select { width: 100%; }
.field .hint { color: var(--muted); font-size: 12px; margin-top: 4px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
pre.err { background: var(--red-soft); color: var(--red); padding: 10px; border-radius: 8px; white-space: pre-wrap; font-family: inherit; }

.toasts { position: fixed; right: 20px; bottom: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 100; }
.toast { background: #1f2937; color: #fff; padding: 11px 16px; border-radius: 10px; max-width: 380px; box-shadow: 0 6px 20px rgba(0,0,0,.25); }
.toast.err { background: var(--red); }

/* 헤더 클릭 정렬 */
th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { background: #e6e9ee; }
th.sortable::after { content: ' ↕'; color: #b0b6c0; font-size: 11px; }
th.sortable.asc::after { content: ' ▲'; color: var(--blue); }
th.sortable.desc::after { content: ' ▼'; color: var(--blue); }
