:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --border: #e2e5ea;
  --text: #1f2430;
  --muted: #6b7280;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-soft: #eff4ff;
  --danger: #dc2626;
  --success: #15803d;
  --warn-bg: #fff7ed;
  --warn-border: #fdba74;
  --warn-text: #9a3412;
  --radius: 10px;
}

* { box-sizing: border-box; }

/* hidden 속성이 항상 우선하도록 보장.
   .loading{display:flex} 등 클래스 규칙이 UA의 [hidden]{display:none}을 덮어써서
   hidden=true 로도 안 사라지는 문제를 막는다(예: 로딩 스피너가 계속 도는 버그). */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Apple SD Gothic Neo",
    "Malgun Gothic", "Noto Sans KR", sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
html { height: 100%; }
body { min-height: 100vh; }

.app {
  min-width: 320px;
  max-width: 420px;
  margin: 0 auto;
  padding: 14px 14px 24px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* Header */
.app__header {
  padding: 2px 2px 0;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}
.app__title {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.01em;
}
.app__subtitle {
  margin: 2px 0 0;
  font-size: 12px;
  color: var(--muted);
}
.app__link {
  flex: 0 0 auto;
  font-size: 11px;
  font-weight: 600;
  color: var(--primary);
  text-decoration: none;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 10px;
  background: var(--primary-soft);
  white-space: nowrap;
}
.app__link:hover { border-color: var(--primary); }

/* Footer (항상 하단 고정) */
.app__footer {
  margin-top: auto;
  padding-top: 8px;
  border-top: 1px solid var(--border);
  font-size: 11px;
  color: var(--muted);
  text-align: center;
}

/* Action buttons */
.actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.btn {
  appearance: none;
  border: 1px solid transparent;
  border-radius: var(--radius);
  padding: 10px 12px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background-color .15s ease, border-color .15s ease, opacity .15s ease;
  white-space: nowrap;
}
.btn:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}
.btn--primary {
  background: var(--primary);
  color: #fff;
}
.btn--primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn--ghost {
  background: var(--surface);
  border-color: var(--border);
  color: var(--text);
}
.btn--ghost:hover:not(:disabled) { background: var(--primary-soft); border-color: var(--primary); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn--full { grid-column: 1 / -1; }
.btn--sm { padding: 6px 10px; font-size: 12px; }

/* 입력창 교정 툴바 */
.editable-bar {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px; margin-bottom: 8px;
  background: var(--primary-soft); border: 1px solid var(--border); border-radius: var(--radius);
}
.editable-bar__kind { font-size: 11px; color: var(--muted); }
.editable-bar__actions { margin-left: auto; display: inline-flex; gap: 6px; }
.result-list--editable .result-item__line { align-items: center; }
.result-chk { margin: 0 6px 0 0; flex: 0 0 auto; width: 15px; height: 15px; }
.field-head {
  list-style: none; margin: 12px 0 4px; padding: 4px 8px;
  font-size: 12px; font-weight: 700; color: var(--primary);
  background: var(--primary-soft); border-radius: 6px;
}
.field-head:first-child { margin-top: 0; }
.field-none { list-style: none; padding: 4px 8px; font-size: 12px; color: var(--muted); }

/* Status / notice banners */
.status {
  border-radius: var(--radius);
  padding: 9px 12px;
  font-size: 12.5px;
  font-weight: 500;
}
.status--success { background: #ecfdf5; color: var(--success); border: 1px solid #a7f3d0; }
.status--error   { background: #fef2f2; color: var(--danger);  border: 1px solid #fecaca; }
.status--info    { background: var(--primary-soft); color: var(--primary); border: 1px solid #bfdbfe; }

.notice {
  border-radius: var(--radius);
  padding: 10px 12px;
  font-size: 12.5px;
}
.notice--warn {
  background: var(--warn-bg);
  border: 1px solid var(--warn-border);
  color: var(--warn-text);
}

/* Results */
.results {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  min-height: 120px;
}
.results__head {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 8px;
}
.results__title { margin: 0; font-size: 14px; font-weight: 700; }
.results__count { font-size: 12px; color: var(--muted); }
.results__tools { margin-left: auto; display: inline-flex; gap: 10px; }
.linkbtn {
  background: none; border: none; padding: 0; cursor: pointer;
  font-size: 12px; color: var(--primary); text-decoration: underline;
}
.linkbtn:disabled { color: var(--muted); text-decoration: none; cursor: default; opacity: .6; }
.linkbtn--on { font-weight: 700; }

/* 교정 기록 모달 */
.modal {
  position: fixed; inset: 0; z-index: 1000;
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.modal__backdrop { position: absolute; inset: 0; background: rgba(15, 23, 42, 0.5); }
.modal__dialog {
  position: relative; background: var(--surface); width: 100%; max-width: 440px;
  max-height: 88vh; display: flex; flex-direction: column;
  border-radius: 14px; box-shadow: 0 12px 40px rgba(0, 0, 0, 0.3); overflow: hidden;
}
.modal__head {
  display: flex; align-items: center; gap: 8px;
  padding: 12px 14px; border-bottom: 1px solid var(--border);
}
.modal__title { margin: 0; font-size: 14px; font-weight: 700; }
.modal__close {
  margin-left: auto; border: none; background: none; cursor: pointer;
  font-size: 22px; line-height: 1; color: var(--muted); padding: 0 4px;
}
.modal__close:hover { color: var(--text); }
.modal__tools {
  display: flex; gap: 12px; padding: 10px 14px; border-bottom: 1px solid var(--border);
}
.modal__body { padding: 12px 14px; overflow: auto; }
.history-list { list-style: none; margin: 0; padding: 0; }
.hist-item {
  border: 1px solid var(--border); border-radius: 8px;
  padding: 8px 10px; margin-bottom: 8px; background: var(--surface);
}
.hist-item__head { display: flex; align-items: baseline; gap: 8px; }
.hist-item__title { font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hist-item__count { margin-left: auto; font-size: 11px; color: var(--muted); flex: 0 0 auto; }
.hist-item__meta { font-size: 11px; color: var(--muted); margin: 2px 0 6px; }
.hist-item__actions { display: flex; gap: 12px; }

.empty {
  color: var(--muted);
  font-size: 12.5px;
  text-align: center;
  padding: 24px 8px;
}

.loading {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--primary);
  font-size: 13px;
  padding: 16px 4px;
}
.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid #bfdbfe;
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  flex: none;
}
@keyframes spin { to { transform: rotate(360deg); } }

.result-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.result-item {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 10px;
  background: #fcfcfd;
}
.result-item__line {
  display: flex;
  align-items: baseline;
  gap: 6px;
  flex-wrap: wrap;
}
.result-item__idx {
  flex: none;
  min-width: 22px;
  height: 20px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--primary);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.result-item__org {
  color: var(--danger);
  text-decoration: line-through;
  font-weight: 600;
  word-break: break-all;
}
.result-item__arrow { color: var(--muted); }
.result-item__cand {
  color: var(--success);
  font-weight: 700;
  word-break: break-all;
}
.result-item__alt {
  color: var(--muted);
  font-size: 11.5px;
}
.result-item__reason {
  margin-top: 4px;
  font-size: 12px;
  color: var(--muted);
  word-break: break-word;
}

/* 탭 */
.tabs { display: flex; gap: 6px; }
.tab {
  flex: 1; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface); color: var(--muted); font-size: 13px; font-weight: 600; cursor: pointer;
}
.tab--on { background: var(--primary-soft); border-color: var(--primary); color: var(--primary); }
.tabpanel { display: flex; flex-direction: column; gap: 12px; }

/* 직접 입력 / OCR */
.manual-text {
  width: 100%; min-height: 150px; resize: vertical; box-sizing: border-box;
  padding: 10px; border: 1px solid var(--border); border-radius: var(--radius);
  font-family: inherit; font-size: 14px; line-height: 1.7; color: var(--text); background: var(--surface);
}
.manual-bar { display: flex; align-items: center; gap: 8px; }
.manual-count { font-size: 12px; color: var(--muted); }
.manual-bar__actions { margin-left: auto; display: inline-flex; gap: 6px; flex-wrap: wrap; }
.ocr-status {
  font-size: 12px; color: var(--muted); background: var(--primary-soft);
  border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px;
}
.manual-result { border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; background: var(--surface); }
.manual-doc {
  white-space: pre-wrap; font-size: 14px; line-height: 1.9; background: var(--bg);
  border: 1px solid var(--border); border-radius: 8px; padding: 10px; margin-bottom: 10px;
}
/* 인라인 redline(직접 입력 결과) */
.bl-edit { white-space: nowrap; }
.bl-del { color: #b91c1c; text-decoration: line-through; text-decoration-color: #dc2626; }
.bl-ins { color: #15803d; font-weight: 600; text-decoration: none; margin-left: 2px; }
sup.bl-n { color: #2563eb; font-size: 9px; font-weight: 700; margin-left: 1px; }

.manual-hint { font-size: 11px; color: var(--muted); margin-top: -4px; }
