/* 남식쌤 내신 플래너 — 업무허브 2.0 디자인 기준 적용
   기준: 시스템 글꼴 11px · 최대 1536px · 간격 5px · 모서리 3px · 3테마
   모바일 예외(≤700px): 입력 16px · 터치 44px
   앱별 예외는 파일 하단 '적용 예외' 주석에 근거를 기록한다. */

:root {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
  font-size: 11px;
  color: var(--text);
  background: var(--bg);
  color-scheme: light;

  --bg: #f3f5f8;
  --panel: #fff;
  --text: #253347;
  --muted: #5c6b7f;
  --line: #cbd3df;
  --soft: #eaf0f7;
  --accent: #244e7d;
  --bar: #203f64;

  /* 상태색 — 색상만으로 구분하지 않고 글자·형태를 함께 사용한다 */
  --ok-bg: #e4f0e6;   --ok-fg: #1f6b39;   --ok-line: #b6d8c0;
  --warn-bg: #fdf2dc; --warn-fg: #855700; --warn-line: #e6cf9d;
  --err-bg: #fbe6e4;  --err-fg: #a3291c;  --err-line: #e8b8b2;
}

:root[data-theme="dark"] {
  --bg: #141c27;
  --panel: #1d2837;
  --text: #e1e8f1;
  --muted: #b3c0d2;
  --line: #45566d;
  --soft: #2a3b51;
  --accent: #a6caff;
  --bar: #1a2e47;
  color-scheme: dark;

  --ok-bg: #1d3a29;   --ok-fg: #8fd6a6;   --ok-line: #35624a;
  --warn-bg: #3b3018; --warn-fg: #f0c775; --warn-line: #6a5528;
  --err-bg: #3d211f;  --err-fg: #f2a79d;  --err-line: #6d3b36;
}

@media (prefers-color-scheme: dark) {
  :root[data-theme="system"] {
    --bg: #141c27;
    --panel: #1d2837;
    --text: #e1e8f1;
    --muted: #b3c0d2;
    --line: #45566d;
    --soft: #2a3b51;
    --accent: #a6caff;
    --bar: #1a2e47;
    color-scheme: dark;

    --ok-bg: #1d3a29;   --ok-fg: #8fd6a6;   --ok-line: #35624a;
    --warn-bg: #3b3018; --warn-fg: #f0c775; --warn-line: #6a5528;
    --err-bg: #3d211f;  --err-fg: #f2a79d;  --err-line: #6d3b36;
  }
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; }
h1, h2, h3, p, ul, ol, figure { margin: 0; }
h1, h2, h3, small, button, input, select, textarea { font: inherit; }
h1, h2, h3 { font-weight: 700; }
ul, ol { padding: 0; list-style: none; }
a { color: var(--accent); }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* ── 셸 ─────────────────────────────────────────────── */
.app-shell { width: 100%; max-width: 1536px; margin-inline: auto; }

.topbar {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  padding: 7px 10px; background: var(--bar); color: #fff;
}
.topbar .brand { display: flex; align-items: baseline; gap: 7px; margin-right: auto; }
.topbar .brand strong { font-weight: 700; }
.topbar .brand span { color: #b9cbe2; }
.topbar label { color: #b9cbe2; }
.topbar select {
  background: rgba(255,255,255,.10); color: #fff; border-color: rgba(255,255,255,.35);
}
.topbar select option { color: #253347; background: #fff; }

.page { padding: 5px; display: grid; gap: 5px; }
.statusline {
  display: flex; align-items: center; flex-wrap: wrap; gap: 10px;
  padding: 0 3px 2px; color: var(--muted);
}

/* ── 패널 ───────────────────────────────────────────── */
.panel {
  min-width: 0; background: var(--panel);
  border: 1px solid var(--line); border-radius: 3px; overflow: hidden;
}
.panel-heading {
  min-height: 26px; padding: 3px 6px; background: var(--soft);
  display: flex; align-items: center; justify-content: space-between;
  gap: 5px; flex-wrap: wrap; border-bottom: 1px solid var(--line);
}
.panel-heading h2 { font-size: inherit; }
.panel-heading > span, .panel-heading .hint { color: var(--muted); font-weight: 400; }
.panel-body { padding: 5px; display: grid; gap: 5px; }

/* 성적 입력 이후 패널들 — 한 섹션 약 500px 로 두고 화면 폭에 맞춰 개수를 정한다.
   1536px→3개(약 505px) · 1024px→2개 · 좁은 화면→1개 */
.panel-grid {
  display: grid; gap: 5px; align-items: start;
  grid-template-columns: repeat(auto-fill, minmax(400px, 1fr));
}
@media (max-width: 700px) { .panel-grid { grid-template-columns: minmax(0, 1fr); } }

/* ── 폼 컨트롤 ──────────────────────────────────────── */
button {
  display: inline-flex; align-items: center; justify-content: center; gap: 5px;
  cursor: pointer; min-height: 26px; padding: 3px 8px;
  border: 1px solid var(--line); border-radius: 3px;
  background: var(--panel); color: var(--text);
}
button:hover { background: var(--soft); }
button:disabled { opacity: .45; cursor: not-allowed; }
button[aria-pressed="true"], button[aria-current="page"] {
  background: var(--soft); color: var(--accent); font-weight: 700;
}
button.primary { background: var(--bar); color: #fff; border-color: var(--bar); }
button.primary:hover { background: var(--accent); }
button.linkish { border-color: transparent; background: none; color: var(--accent); text-decoration: underline; }

input, select, textarea {
  min-width: 0; max-width: 100%; padding: 4px;
  border: 1px solid var(--line); border-radius: 3px;
  background: var(--panel); color: var(--text);
}
input[type="number"] { text-align: right; }

/* ── 표 ─────────────────────────────────────────────── */
.table-scroll { overflow-x: auto; max-width: 100%; }
table { width: 100%; border-collapse: collapse; table-layout: fixed; }
th, td {
  border: 1px solid var(--line); padding: 3px 5px; height: 26px;
  text-align: center; overflow-wrap: anywhere;
}
th { background: var(--soft); font-weight: 600; }
td.left, th.left { text-align: left; }
td.num { text-align: right; font-variant-numeric: tabular-nums; }

/* 과목 입력 시트 — 항상 카드 배치.
   학기를 여러 열로 나누면 한 열이 좁아져 표가 가로 스크롤 뒤로 숨는다.
   등급 선택이 이 앱의 핵심 입력이라 어느 폭에서도 보여야 하므로 표 대신 카드로 쌓는다.
   기준 문서가 허용하는 '모바일 열 재배치'를 전 구간으로 확장한 것이며 근거는 위와 같다. */
.sheet, .sheet tbody, .sheet tr, .sheet td { display: block; }
.sheet { min-width: 0; width: 100%; }
.sheet thead { display: none; }
.sheet tr {
  display: grid; gap: 4px; align-items: center;
  /* 과목이 카드 폭의 약 절반. 나머지 절반에 단위·등급·삭제를 같은 줄로 넣어
     과목당 두 줄이던 것을 한 줄로 줄인다. */
  grid-template-columns: minmax(0, 1fr) 40px 64px 22px;
  border: 1px solid var(--line); border-radius: 3px;
  padding: 3px; margin-bottom: 4px;
}
.sheet td { border: 0; padding: 0; height: auto; text-align: left; }
.sheet td[data-l]::before { content: none; }
.sheet select, .sheet input { width: 100%; height: 26px; padding: 0 5px; }
.sheet td.del { align-self: end; }
.sheet td.del button { width: 100%; padding: 0; border-color: transparent; background: none; color: var(--muted); }
.sheet td.del button:hover { color: var(--err-fg); background: var(--err-bg); border-color: var(--err-line); }

/* ── 요약 지표 ──────────────────────────────────────── */
.metrics { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: 5px; }
@media (max-width: 599px) { .metrics { grid-template-columns: repeat(2, minmax(0,1fr)); } }
.metric { border: 1px solid var(--line); border-radius: 3px; padding: 5px 7px; background: var(--panel); }
.metric.lead { background: var(--soft); }
.metric dt { color: var(--muted); }
.metric dd { margin: 1px 0 0; font-weight: 700; color: var(--accent); font-variant-numeric: tabular-nums; }
.metric .unit { font-size: 11px; font-weight: 400; color: var(--muted); margin-left: 2px; }
.metric .sub { color: var(--muted); }

/* ── 학기 목록 ──────────────────────────────────────── */
.sem { border: 1px solid var(--line); border-radius: 3px; background: var(--panel); overflow: hidden; }
.sem + .sem { margin-top: 5px; }
.sem-head {
  width: 100%; display: flex; align-items: center; gap: 7px; text-align: left;
  padding: 4px 6px; background: var(--soft); border: 0; border-radius: 0; min-height: 28px;
}
.sem-head:hover { background: var(--line); }
.sem-head .yr { font-weight: 700; }
.sem-head .meta { color: var(--muted); margin-left: auto; }
.sem-head .chev { color: var(--muted); width: 12px; text-align: center; }
.sem-body { padding: 5px; display: grid; gap: 5px; border-top: 1px solid var(--line); }

.badge {
  display: inline-block; padding: 1px 6px; border-radius: 3px;
  border: 1px solid var(--line); background: var(--panel); font-weight: 700;
  font-variant-numeric: tabular-nums; white-space: nowrap;
}
.badge.none { color: var(--muted); font-weight: 400; }
.badge.part { background: var(--warn-bg); color: var(--warn-fg); border-color: var(--warn-line); }
.badge.err  { background: var(--err-bg);  color: var(--err-fg);  border-color: var(--err-line); }

/* ── 알림 박스 (색 + 글자 접두어로 구분) ─────────────── */
.note { border: 1px solid var(--line); border-radius: 3px; padding: 5px 7px; background: var(--soft); line-height: 1.6; }
.note.ok   { background: var(--ok-bg);   color: var(--ok-fg);   border-color: var(--ok-line); }
.note.warn { background: var(--warn-bg); color: var(--warn-fg); border-color: var(--warn-line); }
.note.err  { background: var(--err-bg);  color: var(--err-fg);  border-color: var(--err-line); }
.note b { font-weight: 700; }

.modes { display: flex; gap: 5px; flex-wrap: wrap; }
.chips { display: flex; gap: 5px; flex-wrap: wrap; }
.chip {
  display: inline-block; padding: 2px 7px; border: 1px solid var(--line);
  border-radius: 3px; background: var(--soft); color: var(--muted);
}
.chip.strong { color: var(--text); font-weight: 700; background: var(--panel); }
.field { display: flex; align-items: center; gap: 5px; flex-wrap: wrap; }
.field label { color: var(--muted); }
.muted { color: var(--muted); }
/* 주의사항 목록 — 패널 안에서 ※ 대신 여백으로 항목을 구분한다 */
.footnote { color: var(--muted); line-height: 1.65; display: grid; gap: 6px; }
.footnote li { padding-left: 11px; position: relative; }
.footnote li::before { content: "※"; position: absolute; left: 0; }
.footnote b { color: var(--text); }

/* ── 적용 예외 기록 ──────────────────────────────────
   1) (해제됨) 지표 숫자 확대 예외는 사용자 요청으로 없앴다. 폰에서 글자가 커서
      잘리는 곳이 있었다. 이제 전 요소가 11px 이며 위계는 굵기·색으로만 표현한다.
      모바일 입력도 11px 로 통일했다 — 아래 모바일 블록의 주의사항 참고.
   2) 3열 대시보드 미사용 — 사용자 요청. 단일 열 + 넓은 화면 2열로 대체한다.
   ─────────────────────────────────────────────────── */

/* 학기 섹션 — 학기 하나가 하나의 섹션.
   한 섹션은 300~330px 면 충분하다. 최소 280px 를 확보하고 남는 폭은 고르게 나눠,
   화면 폭에 맞춰 한 줄에 들어가는 개수를 자동으로 정한다.
   1536px→5개(299px) · 1280px→4개(312px) · 1024px→3개(333px) · 768px→2개 · ≤700px→1개.
   (330px 고정으로 두면 5×330+간격=1682px 라 기준 최대폭 1536px 를 넘어 4개만 들어간다) */
#semList {
  display: grid; gap: 8px; align-items: start;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
}
#semList .sem + .sem { margin-top: 0; }

@media (max-width: 700px) {
  #semList { grid-template-columns: minmax(0, 1fr); gap: 5px; }
}

/* ── 모바일 접근성 예외 (≤700px) ─────────────────────
   D-036 허용 예외. 입력 16px·터치 44px 는 이 구간에만 적용하고
   태블릿·PC 밀도 기준으로 확장하지 않는다. */
@media (max-width: 700px) {
  button { min-height: 44px; }
  /* 글자 크기는 PC 와 동일하게 11px 로 두고, 터치 영역만 44px 로 확보한다 */
  input, select, textarea { min-height: 44px; }
  .sem-head { min-height: 44px; }
  /* 44px 터치 영역을 확보하려면 한 줄에 넣을 수 없어 두 줄로 되돌린다 */
  .sheet tr {
    grid-template-columns: 84px minmax(0, 1fr) 44px;
    grid-template-areas: "name name name" "unit grade del";
    padding: 4px; margin-bottom: 5px;
  }
  .sheet td:nth-child(1) { grid-area: name; }
  .sheet td:nth-child(2) { grid-area: unit; }
  .sheet td:nth-child(3) { grid-area: grade; }
  .sheet td:nth-child(4) { grid-area: del; }
  .sheet td[data-l]::before {
    content: attr(data-l); display: block;
    font-size: 11px; color: var(--muted); margin-bottom: 1px;
  }
  .sheet select, .sheet input { height: 44px; }
  .sheet td.del button { min-height: 44px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
