/* 문제지 조립 — 세션 캡처 UI
   컨셉: 모눈종이(graph paper) 위에서 문제를 순서대로 배열한다는 느낌.
   배경은 옅은 청회색 모눈, 강조색은 진한 인디고 + 정답지 빨강 포인트. */

:root {
  --ink: #1c2230;
  --ink-soft: #4a5266;
  --paper: #eef1f6;
  --paper-card: #ffffff;
  --line: #ccd3e0;
  --indigo: #2b3a67;
  --indigo-deep: #1c2747;
  --accent: #c1440e;      /* 채점/내보내기 포인트 - 붉은 인주색 계열 */
  --ok: #2f7a4f;
  --warn: #b8860b;
  --radius: 3px;
  font-size: 16px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  color: var(--ink);
  background:
    linear-gradient(var(--line) 1px, transparent 1px) 0 0 / 24px 24px,
    linear-gradient(90deg, var(--line) 1px, transparent 1px) 0 0 / 24px 24px,
    var(--paper);
  font-family: -apple-system, "Apple SD Gothic Neo", "Pretendard", "Malgun Gothic",
               "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.5;
}

.screen { min-height: 100vh; }

button { font-family: inherit; cursor: pointer; }
kbd {
  font-family: Consolas, Menlo, monospace;
  font-size: 0.85em;
  background: var(--indigo-deep);
  color: #fff;
  padding: 1px 6px;
  border-radius: 3px;
}

/* ---------- 버튼 ---------- */
.btn {
  border: 1px solid var(--line);
  background: var(--paper-card);
  color: var(--ink);
  padding: 9px 16px;
  border-radius: var(--radius);
  font-size: 0.92rem;
  font-weight: 600;
  transition: transform 0.06s ease, background 0.15s ease;
}
.btn:hover { background: #f5f6fa; }
.btn:active { transform: translateY(1px); }
.btn-block { width: 100%; }
.btn-small { padding: 7px 14px; font-size: 0.9rem; }
.btn-primary { background: var(--indigo); border-color: var(--indigo); color: #fff; }
.btn-primary:hover { background: var(--indigo-deep); }
.btn-accent { background: var(--accent); border-color: var(--accent); color: #fff; }
/* 주의: 배경을 명시적으로 다시 선언해야 한다. 그냥 filter만 쓰면
   위쪽의 .btn:hover { background: #f5f6fa } 가 (동일 명시도 + 이후
   선언 순서에서 background 프로퍼티 자체를 덮어쓰지 않으므로) 그대로
   적용되어 버튼이 거의 흰색이 되고, 흰 글자(color:#fff)와 겹쳐
   텍스트가 안 보이는 버그가 있었다. */
.btn-accent:hover { background: var(--accent); border-color: var(--accent); color: #fff; filter: brightness(1.08); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--ink-soft); }
.btn-ghost:hover { background: rgba(43, 58, 103, 0.08); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

/* ---------- 로그인 화면 ---------- */
#loginScreen {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--paper-card);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 36px 32px 30px;
  box-shadow: 0 1px 0 var(--line);
}
.brand { display: flex; align-items: baseline; gap: 8px; }
.brand-mark {
  font-size: 1.6rem;
  color: var(--accent);
  font-weight: 700;
}
.brand-mark.small { font-size: 1.15rem; }
.brand-name { font-size: 1.15rem; font-weight: 700; letter-spacing: -0.01em; }
.brand-home-link {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--ink);
  text-decoration: none;
}
.brand-home-link:hover { color: var(--indigo); }
.brand-sub { color: var(--ink-soft); font-size: 0.86rem; margin: 6px 0 26px; }

.login-form { display: flex; flex-direction: column; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 0.85rem; color: var(--ink-soft); }
.field input, .field textarea {
  font-family: inherit;
  font-size: 0.95rem;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--ink);
}
.field textarea { font-family: Consolas, Menlo, monospace; font-size: 0.88rem; resize: vertical; }
.field input:focus, .field textarea:focus, .dropzone:focus {
  outline: 2px solid var(--indigo);
  outline-offset: 1px;
}
.error-text { color: #b0281f; font-size: 0.84rem; margin: 2px 0 0; }
.status-text { font-size: 0.84rem; margin: 8px 0 0; }
.status-text.ok { color: var(--ok); }
.status-text.warn { color: var(--warn); }
.status-text.err { color: #b0281f; }
.status-text.busy { color: var(--indigo); }
#appendRetryBtn { margin-top: 8px; }

/* ---------- 상단바 ---------- */
.topbar {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 24px;
  background: var(--paper-card);
  border-bottom: 1px solid var(--line);
}
.topbar-left { display: flex; align-items: center; gap: 10px; }
.session-chip {
  font-family: Consolas, Menlo, monospace;
  font-size: 0.76rem;
  color: var(--ink-soft);
  background: var(--paper);
  border: 1px solid var(--line);
  padding: 2px 8px;
  border-radius: 12px;
}
.topbar-right { display: flex; align-items: center; gap: 10px; }
.user-label { font-size: 0.85rem; color: var(--ink-soft); }

/* ---------- 사용량/구독 정보 바 ---------- */
.quota-bar {
  padding: 8px 24px;
  text-align: right;
  background: var(--paper-card);
  border-bottom: 1px solid var(--line);
}
.quota-text {
  font-size: 0.84rem;
  font-weight: 700;
  color: #2f6fed;
}
.quota-text.err { color: var(--ink-soft); font-weight: 500; }

/* ---------- 작업 영역 ---------- */
.work-grid {
  display: grid;
  grid-template-columns: minmax(320px, 420px) 1fr;
  gap: 20px;
  padding: 20px 24px 40px;
  max-width: 1180px;
  margin: 0 auto;
}
@media (max-width: 860px) {
  .work-grid { grid-template-columns: 1fr; }
}

.panel {
  background: var(--paper-card);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 20px;
}
.panel-title {
  font-size: 0.95rem;
  font-weight: 700;
  margin: 0 0 14px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.count-badge {
  background: var(--indigo);
  color: #fff;
  font-size: 0.72rem;
  font-weight: 700;
  padding: 1px 7px;
  border-radius: 10px;
}

/* ---------- 캡처 패널 ---------- */
.dropzone {
  border: 2px dashed var(--line);
  border-radius: var(--radius);
  padding: 97px 20px;
  min-height: 513px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  margin-bottom: 14px;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.dropzone.is-active { border-color: var(--indigo); background: rgba(43, 58, 103, 0.05); }
.dropzone-main { margin: 0 0 8px; font-weight: 700; font-size: 1.25rem; }
/* 패널 제목("캡처 입력", 0.95rem)보다 작게 유지 */
.dropzone-sub { margin: 0 0 4px; font-size: 0.85rem; color: var(--ink-soft); }
.dropzone-main kbd { font-size: 0.78em; padding: 2px 8px; }
.paste-preview {
  margin-top: 18px;
  max-width: 100%;
  max-height: 220px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.pending-image-status {
  display: inline-block;
  margin: 8px 0 0;
  font-size: 0.76rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 10px;
  background: var(--paper);
  color: var(--ink-soft);
  border: 1px solid var(--line);
}
.pending-image-status.busy { color: var(--indigo); border-color: var(--indigo); }
.pending-image-status.ok { color: var(--ok); border-color: var(--ok); }
.pending-image-status.err { color: #b0281f; border-color: #e6b3ab; background: #fbe3e0; }

.screen-capture-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.hint-text { font-size: 0.85rem; color: var(--ink-soft); }

.capture-panel .field { margin-bottom: 12px; }

/* ---------- 항목 목록 패널 ---------- */
.items-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.items-hint { font-size: 0.88rem; color: var(--ink-soft); margin: 4px 0 14px; }

.item-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }

.item-card {
  display: grid;
  grid-template-columns: 34px 56px 1fr auto;
  align-items: center;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 12px;
  background: #fff;
  cursor: pointer;
  transition: border-color 0.12s ease, box-shadow 0.12s ease;
}
.item-card:hover { border-color: var(--indigo); box-shadow: 0 0 0 1px var(--indigo) inset; }
.item-card.is-dragging { opacity: 0.4; }
.item-card.status-convert_failed { border-left: 3px solid var(--warn); }
.item-card.status-ok { border-left: 3px solid var(--ok); }

.item-order {
  font-family: Consolas, Menlo, monospace;
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--ink-soft);
  text-align: center;
}
.item-thumb {
  width: 56px;
  height: 56px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  object-fit: cover;
  background: var(--paper);
}
.item-thumb.placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: Consolas, Menlo, monospace;
  font-size: 0.7rem;
  color: var(--ink-soft);
}
.item-body { min-width: 0; }
.item-label { font-size: 0.78rem; color: var(--ink-soft); margin: 0 0 2px; }
.item-preview {
  font-family: Consolas, Menlo, monospace;
  font-size: 0.82rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin: 0;
}
.item-status {
  font-size: 0.72rem;
  font-weight: 700;
  margin-top: 4px;
}
.item-status.ok { color: var(--ok); }
.item-status.convert_failed { color: var(--warn); }

.item-actions { display: flex; align-items: center; gap: 4px; }
.icon-btn {
  border: 1px solid var(--line);
  background: #fff;
  width: 26px;
  height: 26px;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  color: var(--ink-soft);
  line-height: 1;
}
.icon-btn:hover { background: var(--paper); }
.icon-btn.danger:hover { background: #fbe3e0; color: #b0281f; border-color: #e6b3ab; }

.empty-hint { color: var(--ink-soft); font-size: 0.98rem; padding: 20px 0; text-align: center; }

/* ---------- 화면 공유 캡처 오버레이 ---------- */
.capture-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 18, 28, 0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}
.capture-overlay-inner {
  background: var(--paper-card);
  border-radius: 6px;
  padding: 16px;
  max-width: min(90vw, 720px);
}
.capture-hint { margin: 0 0 10px; font-size: 0.85rem; color: var(--ink-soft); }
.capture-stage {
  position: relative;
  width: 100%;
  max-height: 60vh;
  line-height: 0;
  user-select: none;
  cursor: crosshair;
}
#screenVideo { width: 100%; max-height: 60vh; display: block; border-radius: var(--radius); background: #000; }
.capture-selection-box {
  position: absolute;
  border: 2px dashed var(--accent);
  background: rgba(193, 68, 14, 0.12);
  pointer-events: none;
}
.capture-overlay-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 14px;
}

/* ---------- 문서 미리보기 패널 ---------- */
.preview-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 18, 28, 0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 60;
  padding: 24px;
}
.preview-panel {
  background: var(--paper-card);
  border-radius: 6px;
  padding: 22px 24px;
  width: 100%;
  max-width: 640px;
  max-height: 86vh;
  overflow-y: auto;
}
.preview-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 6px;
}
.preview-panel-title { margin: 0; font-size: 1rem; font-weight: 700; }
.preview-status { margin: 0 0 12px; font-size: 0.82rem; font-weight: 700; }
.preview-status.ok { color: var(--ok); }
.preview-status.convert_failed { color: var(--warn); }

.preview-warnings {
  margin: 0 0 14px;
  padding: 10px 14px;
  background: #fdf3e2;
  border: 1px solid #ecd6a3;
  border-radius: var(--radius);
  color: #8a5a00;
  font-size: 0.82rem;
  list-style: disc;
  padding-left: 30px;
}
.preview-warnings li { margin: 2px 0; }

.preview-image-wrap { margin-bottom: 16px; text-align: center; }
.preview-image {
  max-width: 100%;
  max-height: 320px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--paper);
}

.preview-section { margin-top: 16px; }
.preview-section-title {
  margin: 0 0 8px;
  font-size: 0.76rem;
  font-weight: 700;
  color: var(--ink-soft);
  text-transform: uppercase;
  letter-spacing: 0.02em;
}
.preview-rendered {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  background: #fff;
  min-height: 40px;
  font-size: 1.02rem;
  overflow-x: auto;
}
.preview-rendered.render-error { color: #b0281f; font-size: 0.85rem; }
.preview-raw {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px;
  background: var(--paper);
  font-family: Consolas, Menlo, monospace;
  font-size: 0.82rem;
  white-space: pre-wrap;
  word-break: break-word;
  margin: 0;
}


/* OCR/KaTeX 미리보기 검수 경고 */
.katex-render-warning {
  margin: 0 0 10px;
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 13px;
  line-height: 1.5;
  background: #fff7d6;
  border: 1px solid #e7c96a;
}

/* hidden 속성은 항상 최우선으로 존중 (개별 클래스의 display 지정과 무관하게) */
[hidden] {
  display: none !important;
}

/* 보관된 파일(재다운로드) 목록 - CAPTURE변환/PDF변환 공용 */
.downloads-panel { grid-column: 1 / -1; }

.downloads-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }

.download-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 12px;
  background: #fff;
}

.download-info { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.download-name { font-weight: 600; word-break: break-all; }
.download-meta { font-size: 0.82rem; color: var(--ink-soft); }
