:root {
  --bg: #f4f5f7;
  --paper: #fff;
  --ink: #1b1d21;
  --muted: #6b7280;
  --line: #c9ccd2;
  --head: #e9edf3;
  --head2: #f3f5f8;
  --sum: #eef1f5;
  --low-bg: #ffe1e1;
  --low-line: #e03131;
  --crit-bg: #ffb3b3;
  --crit-line: #a40000;
  --hit: #fff3b0;
  --accent: #b71c1c;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body { font-family: Pretendard, "Pretendard Variable", -apple-system, "Malgun Gothic", sans-serif; font-size: 13px; }

header { background: var(--paper); border-bottom: 1px solid var(--line); padding: 14px 20px 10px; }
header h1 { margin: 0 0 8px; font-size: 20px; font-weight: 700; letter-spacing: -0.2px; display: flex; align-items: center; gap: 9px; }
header h1 .mark { height: 22px; width: 83px; flex: none; }
.meta { display: flex; flex-wrap: wrap; gap: 6px 16px; align-items: center; color: var(--muted); font-size: 12.5px; }
.meta b { color: var(--ink); font-weight: 600; }
.banner { margin-top: 10px; padding: 9px 12px; border-radius: 6px; font-weight: 600; }
.banner.warn { background: #fff4e5; color: #8a4b00; border: 1px solid #f5c07a; }
.banner.err { background: #fdecec; color: #8a1c1c; border: 1px solid #f1a3a3; }
.banner[hidden] { display: none; }

.controls { display: flex; flex-wrap: wrap; gap: 8px 14px; align-items: center; padding: 10px 20px; background: var(--paper); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
.controls label { display: inline-flex; align-items: center; gap: 6px; font-weight: 500; }
.controls input[type="text"] { width: 200px; padding: 6px 8px; border: 1px solid var(--line); border-radius: 5px; font: inherit; }
.controls input[type="number"] { width: 64px; padding: 6px 6px; border: 1px solid var(--line); border-radius: 5px; font: inherit; }
.controls button { padding: 6px 12px; border: 1px solid var(--line); background: #fff; border-radius: 5px; font: inherit; cursor: pointer; }
.controls button:hover { background: #f1f3f5; }
.legend { display: inline-flex; gap: 10px; align-items: center; color: var(--muted); margin-left: auto; }
.legend i { display: inline-block; width: 14px; height: 14px; border: 2px solid; vertical-align: middle; margin-right: 4px; }
.legend .l { background: var(--low-bg); border-color: var(--low-line); }
.legend .c { background: var(--crit-bg); border-color: var(--crit-line); }

/* 표가 가로 전체를 쓰도록 저조 전형 목록은 표 아래에 배치 */
main { padding: 14px 20px 40px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; }

/* 표 안에서 따로 스크롤하지 않고 페이지 전체가 스크롤되도록 둔다 */
.tablewrap { overflow: visible; background: var(--paper); border: 1px solid var(--line); }
table { border-collapse: separate; border-spacing: 0; white-space: nowrap; }
th, td { border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); padding: 4px 6px; text-align: center; font-variant-numeric: tabular-nums; }
thead th { background: var(--head); font-weight: 600; position: sticky; top: 0; z-index: 5; } /* top은 app.js가 실제 높이로 보정 */
thead tr:nth-child(2) th, thead tr:nth-child(3) th { background: var(--head2); }
thead tr:nth-child(4) th { background: var(--head2); font-weight: 500; color: var(--muted); font-size: 12px; }
thead th.unit, tbody td.unit, tfoot td.unit { position: sticky; left: 0; z-index: 6; background: var(--paper); text-align: left; font-weight: 600; min-width: 170px; border-right: 2px solid #9aa0a8; }
thead th.unit { z-index: 8; background: var(--head); }
th.group-start, td.group-start { border-left: 1px solid var(--line); }
td.q { color: var(--muted); }
td.r { font-weight: 600; }
td.blank { background: #fafafa; }
tfoot td { background: var(--sum); font-weight: 700; position: sticky; bottom: 0; z-index: 5; }
tfoot td.unit { background: var(--sum); z-index: 7; }

/* 전년대비 */
th.dcol, td.dcol { font-size: 11.5px; color: var(--muted); min-width: 52px; }
.d-up { color: #1565c0; font-weight: 600; }
.d-down { color: #c62828; font-weight: 600; }
.d-flat { color: var(--muted); }
.d-na { color: #b0b5bd; }
.c-yoy { font-size: 12px; color: var(--muted); margin-top: 5px; }

td.low { background: var(--low-bg); box-shadow: inset 0 0 0 2px var(--low-line); color: #8a1c1c; }
td.crit { background: var(--crit-bg); box-shadow: inset 0 0 0 2px var(--crit-line); color: #5c0000; font-weight: 800; }
/* 마우스 올린 줄 강조.
   배치를 다시 계산하게 만드는 속성(글자 굵기·크기 등)은 쓰지 않고 배경색만 바꾼다.
   붉은 박스 칸은 그대로 두어 저조·미달 표시가 묻히지 않게 한다. */
@media (hover: hover) {
  tbody tr:hover td:not(.low):not(.crit) { background-color: #e8f0ea; }
  tbody tr:hover td.unit { background-color: #d9e7dd; }
}

tr.hit td.unit { background: var(--hit); }
tr.hit td { box-shadow: inset 0 -1px 0 #e0c200; }
tr.dim td { opacity: 0.35; }
tr.hidden-row { display: none; }
tr.flash td.unit { animation: flash 1.6s ease-out; }
@keyframes flash { 0% { background: #ffd54f; } 100% { background: var(--hit); } }

.panel { background: var(--paper); border: 1px solid var(--line); align-self: start; max-height: 460px; overflow: auto; }
.panel table { table-layout: fixed; }
.panel th:first-child, .panel td:first-child { width: 38%; }
.panel h2 { margin: 0; padding: 10px 12px; font-size: 14px; border-bottom: 1px solid var(--line); background: var(--head); position: sticky; top: 0; }
.panel table { width: 100%; }
.panel th { background: var(--head2); font-weight: 600; position: sticky; top: 38px; }
.panel td { cursor: pointer; }
.panel tr:hover td { background: #fff8e1; }
.panel .empty { padding: 14px; color: var(--muted); }
.panel[hidden] { display: none; }

footer { padding: 0 20px 24px; color: var(--muted); font-size: 12px; }

/* ---------- 보기 모드 전환 ---------- */
body.view-cards .tablewrap, body.view-cards #panel, body.view-cards .t-only, body.view-cards .legend, body.view-cards footer { display: none; }
.c-note { color: var(--muted); font-size: 12px; text-align: center; padding: 8px 0 4px; }

/* 상단 배너 (학생용 페이지) */
#topBanner { background: #1b2a4a; line-height: 0; }
#topBanner img { display: block; width: 100%; height: auto; }

/* 엑셀 다운로드 버튼 */
.controls button.btn-xlsx { display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px;
  border: 1px solid #145433; background: #145433; color: #fff; border-radius: 6px; font-weight: 600; }
.controls button.btn-xlsx svg { width: 15px; height: 15px; }
.controls button.btn-xlsx:hover { background: #0f4429; }
.controls button.btn-xlsx:disabled { opacity: 0.6; cursor: default; }
body.view-table #cards, body.view-table .c-only { display: none; }
body.view-cards main { display: block; padding: 10px 12px 40px; }

/* ---------- 카드 (모바일) ---------- */
.c-summary { color: var(--muted); font-size: 12.5px; margin: 2px 2px 10px; }
.c-empty { text-align: center; padding: 56px 16px; color: var(--muted); }
.c-empty p { font-size: 15px; line-height: 1.6; margin: 0 0 18px; }
.c-empty button { padding: 11px 18px; border: 1px solid var(--line); background: var(--paper); border-radius: 8px; font: inherit; font-weight: 600; color: var(--ink); cursor: pointer; }
.c-band { margin-bottom: 16px; }
.c-band h3 { margin: 0 0 8px; font-size: 14px; font-weight: 700; display: flex; align-items: center; gap: 8px; }
.c-band h3 span { font-weight: 500; color: var(--muted); font-size: 12.5px; }
.card { display: flex; align-items: center; justify-content: space-between; gap: 10px; background: var(--paper); border: 1px solid var(--line); border-left: 6px solid #c9ccd2; border-radius: 8px; padding: 10px 12px; margin-bottom: 8px; }
.card.low { border-left-color: var(--low-line); background: #fff5f5; }
.card.crit { border-left-color: var(--crit-line); background: #ffeaea; }
.c-name { font-size: 16px; font-weight: 700; letter-spacing: -0.2px; }
.c-group { font-size: 13px; color: var(--muted); margin-top: 2px; }
.c-nums { font-size: 12.5px; color: var(--muted); margin-top: 4px; }
.c-nums b { color: var(--ink); font-weight: 600; }
.c-r { font-size: 24px; font-weight: 800; font-variant-numeric: tabular-nums; white-space: nowrap; }
.c-r small { font-size: 12px; font-weight: 600; color: var(--muted); margin-left: 3px; }
.card.low .c-r { color: #b71c1c; }
.card.crit .c-r { color: #7a0000; }
.c-band .empty { padding: 10px 12px; color: var(--muted); background: var(--paper); border: 1px dashed var(--line); border-radius: 8px; }

/* ---------- 좁은 화면 공통 ---------- */
@media (max-width: 900px) {
  header { padding: 12px 12px 8px; }
  header h1 { font-size: 16px; margin-bottom: 4px; gap: 7px; }
  header h1 .mark { height: 18px; width: 68px; }
  .meta { gap: 4px 10px; font-size: 12px; }
  .controls { padding: 8px 12px; gap: 6px 10px; }
  .controls input[type="text"] { width: 150px; }
  .controls label { font-size: 12.5px; }
  footer { padding: 0 12px 24px; }
}
