:root {
  --bg: #f6f2ec;
  --surface: #ffffff;
  --surface-2: #faf7f2;
  --border: #e2d9cc;
  --border-strong: #cdbfab;
  --text: #2b2520;
  --text-dim: #6d6257;
  --brand: #8a5a2b;
  --brand-ink: #ffffff;
  --brand-soft: #f3e7d8;
  --accent: #2f7d5d;
  --accent-ink: #ffffff;
  --accent-soft: #e3f1ea;
  --danger: #b3321f;
  --danger-soft: #fbe9e6;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(43, 37, 32, .06), 0 4px 16px rgba(43, 37, 32, .05);
  --maxw: 880px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1a1714;
    --surface: #241f1b;
    --surface-2: #2b2520;
    --border: #3b332c;
    --border-strong: #544840;
    --text: #efe8e0;
    --text-dim: #a89a8c;
    --brand: #d2a06a;
    --brand-ink: #241f1b;
    --brand-soft: #3a2f24;
    --accent: #6cc39a;
    --accent-ink: #14201a;
    --accent-soft: #24352d;
    --danger: #ef8b7a;
    --danger-soft: #3a2420;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
  }
}

:root[data-theme="dark"] {
  --bg: #1a1714;
  --surface: #241f1b;
  --surface-2: #2b2520;
  --border: #3b332c;
  --border-strong: #544840;
  --text: #efe8e0;
  --text-dim: #a89a8c;
  --brand: #d2a06a;
  --brand-ink: #241f1b;
  --brand-soft: #3a2f24;
  --accent: #6cc39a;
  --accent-ink: #14201a;
  --accent-soft: #24352d;
  --danger: #ef8b7a;
  --danger-soft: #3a2420;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
}

* { box-sizing: border-box; }

/* display 를 지정한 요소에도 hidden 속성이 통하도록 합니다. */
[hidden] { display: none !important; }

.boot-error {
  margin: 0;
  padding: 10px 16px;
  background: #fde8e8;
  color: #8a1f1f;
  font-size: .9rem;
}

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Pretendard", -apple-system, BlinkMacSystemFont, "Segoe UI",
               "Malgun Gothic", "Apple SD Gothic Neo", system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.65;
  word-break: keep-all;
  overflow-wrap: anywhere;
}

/* ---------- 상단 바 ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--brand);
  color: var(--brand-ink);
  box-shadow: var(--shadow);
}

.topbar-inner {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 10px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.topbar h1 {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: -.01em;
  flex: 1 1 auto;
  white-space: nowrap;
}

.title-short { display: none; }

@media (max-width: 480px) {
  .topbar h1 { font-size: 1.05rem; }
  .title-full { display: none; }
  .title-short { display: inline; }
  .date-field input { min-width: 8.6em; }
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.date-field {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: .85rem;
}

.date-field input {
  font: inherit;
  padding: 5px 8px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  background: rgba(255, 255, 255, .92);
  color: #2b2520;
  min-width: 9.5em;
}

.icon-btn {
  font-size: 1.15rem;
  line-height: 1;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, .35);
  background: rgba(255, 255, 255, .12);
  color: inherit;
  cursor: pointer;
}

.icon-btn:hover { background: rgba(255, 255, 255, .24); }

/* ---------- 레이아웃 ---------- */
main {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 16px 16px 48px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
}

.step-head {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  margin-bottom: 16px;
}

.step-no {
  flex: none;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--brand);
  color: var(--brand-ink);
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: .95rem;
  margin-top: 2px;
}

.step-head h2 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
}

.step-desc {
  margin: 2px 0 0;
  color: var(--text-dim);
  font-size: .92rem;
  line-height: 1.5;
}

/* ---------- 안내 ---------- */
.notice {
  background: var(--brand-soft);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 10px;
  font-size: .92rem;
}

.notice strong { font-weight: 700; }
.notice span { color: var(--text-dim); }
.notice .btn { margin-left: auto; }

/* ---------- 업로드 ---------- */
.dropzone {
  border: 2px dashed var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface-2);
  padding: 28px 16px;
  text-align: center;
  cursor: pointer;
  transition: border-color .15s, background .15s;
}

.dropzone:hover,
.dropzone:focus-visible,
.dropzone.over {
  border-color: var(--brand);
  background: var(--brand-soft);
  outline: none;
}

.dz-icon { font-size: 2rem; line-height: 1; }
.dz-title { margin: 8px 0 2px; font-weight: 600; }
.dz-sub { margin: 0; color: var(--text-dim); font-size: .88rem; }

.thumbs {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(108px, 1fr));
  gap: 10px;
  margin-top: 14px;
}

.thumb {
  position: relative;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--surface-2);
  aspect-ratio: 4 / 3;
}

.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }

.thumb button {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: none;
  background: rgba(0, 0, 0, .62);
  color: #fff;
  font-size: 1.15rem;
  line-height: 1;
  cursor: pointer;
}

/* ---------- 직접 입력 ---------- */
.manual {
  margin-top: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  background: var(--surface-2);
}

.manual summary {
  cursor: pointer;
  font-weight: 600;
  font-size: .92rem;
}

.manual[open] summary { margin-bottom: 8px; }

.period-field {
  margin-top: 14px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 8px;
  font-size: .9rem;
}

.period-field label { font-weight: 600; }

.period-field input {
  font: inherit;
  padding: 5px 8px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: inherit;
}

.period-field .period-until { color: var(--text-dim); }
.period-field .period-note { color: var(--accent); font-weight: 600; }

.period-field small {
  flex-basis: 100%;
  color: var(--text-dim);
  font-size: .82rem;
  line-height: 1.5;
}

.hint {
  margin: 0 0 8px;
  color: var(--text-dim);
  font-size: .88rem;
}

.hint code {
  background: var(--brand-soft);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: .95em;
}

textarea, input[type="text"], input[type="password"], select {
  font: inherit;
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  resize: vertical;
}

textarea:focus, input:focus, select:focus {
  outline: 2px solid var(--brand);
  outline-offset: -1px;
}

/* ---------- 버튼 ---------- */
.actions {
  display: flex;
  gap: 10px;
  margin-top: 16px;
  flex-wrap: wrap;
}

.btn {
  font: inherit;
  font-weight: 600;
  padding: 11px 20px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
}

.btn.primary { background: var(--brand); color: var(--brand-ink); }
.btn.primary:hover:not(:disabled) { filter: brightness(1.08); }

.btn.ghost {
  background: transparent;
  color: var(--text-dim);
  border-color: var(--border-strong);
}

.btn.ghost:hover:not(:disabled) { background: var(--surface-2); color: var(--text); }

.btn:disabled { opacity: .55; cursor: progress; }

.btn.small { padding: 7px 13px; font-size: .85rem; min-height: 36px; white-space: nowrap; }

.btn.copy { background: var(--accent); color: var(--accent-ink); }
.btn.copy:hover:not(:disabled) { filter: brightness(1.08); }
.btn.copy.done { background: var(--accent); }

.spinner {
  width: 15px;
  height: 15px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin .7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
  .spinner { animation-duration: 2s; }
}

/* ---------- 판독 결과 ---------- */
.review-meta {
  font-size: .9rem;
  color: var(--text-dim);
  margin-bottom: 12px;
}

.review-meta .warn {
  display: block;
  margin-top: 6px;
  color: var(--danger);
}

.items { display: flex; flex-direction: column; gap: 8px; }

.item {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px;
}

.item input.name {
  flex: 0 0 9em;
  font-weight: 600;
}

.item textarea.note {
  flex: 1 1 auto;
  min-height: 42px;
  resize: none;
}

.item button.del {
  flex: none;
  width: 40px;
  height: 40px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
}

.item button.del:hover { background: var(--danger-soft); color: var(--danger); border-color: var(--danger); }

@media (max-width: 560px) {
  .item { flex-wrap: wrap; }
  .item input.name { flex: 1 1 100%; }
  .item textarea.note { flex: 1 1 calc(100% - 48px); }
}

/* ---------- 결과 ---------- */
/* ---------- 모드별 표시 ---------- */
body[data-mode="api"] .only-subscription,
body[data-mode="api"] .only-local,
body[data-mode="subscription"] .only-api,
body[data-mode="subscription"] .only-local,
body[data-mode="subscription"] .only-upload,
body[data-mode="local"] .only-api,
body[data-mode="local"] .only-subscription { display: none !important; }

/* ---------- 노트북 연결 줄 ---------- */
.conn {
  margin-bottom: 14px;
  padding: 10px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
}

.conn-line {
  display: flex;
  align-items: center;
  gap: 6px 8px;
  font-size: .9rem;
  flex-wrap: wrap;
}

.conn-dot {
  flex: none;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--text-dim);
}

.conn-dot.ok { background: var(--accent); }
.conn-dot.bad { background: var(--danger); }
.conn-dot.busy { background: var(--brand); animation: pulse 1.2s ease-in-out infinite; }

@keyframes pulse { 50% { opacity: .3; } }

@media (prefers-reduced-motion: reduce) {
  .conn-dot.busy { animation: none; }
}

.conn-text {
  flex: 1 1 12em;
  min-width: 0;
}

/* 버튼 둘은 한 덩어리로 움직입니다. 자리가 좁으면 함께 다음 줄로 내려갑니다. */
.conn-tools { display: flex; gap: 8px; margin-left: auto; flex: none; }

.conn-edit { margin-top: 10px; display: flex; flex-direction: column; gap: 8px; }

.conn-edit input { font-size: .9rem; }

.conn-buttons { display: flex; gap: 8px; flex-wrap: wrap; }

.conn-edit .hint { margin: 0; }

.conn-cert {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px dashed var(--border-strong);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.conn-cert-head { display: flex; align-items: center; gap: 8px; }
.conn-cert-head h3 { margin: 0; font-size: .95rem; flex: 1 1 auto; min-width: 0; }
.conn-cert-head .btn { flex: none; }

.conn-cert h3 small { font-weight: 400; color: var(--text-dim); }

.conn-cert .hint { margin: 0; }

.cert-steps {
  margin: 0;
  padding-left: 1.3em;
  font-size: .9rem;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.cert-steps b { font-weight: 600; }

/* ---------- 노트북 작업 상태 ---------- */
.job-status {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 14px;
  padding: 12px 14px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  font-size: .92rem;
}

.job-status.running { border-color: var(--brand); background: var(--brand-soft); }
.job-status.done { border-color: var(--accent); background: var(--accent-soft); }
.job-status.error { border-color: var(--danger); background: var(--danger-soft); color: var(--danger); }

.job-status .job-text { flex: 1 1 auto; }

.job-list { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }

.job-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  font-size: .9rem;
  text-align: left;
  width: 100%;
  min-height: 44px;
  flex-wrap: wrap;
  cursor: pointer;
  color: inherit;
  font-family: inherit;
}

.job-row:hover { border-color: var(--brand); background: var(--brand-soft); }

.job-item { display: flex; gap: 6px; align-items: stretch; }
.job-item .job-row { flex: 1 1 auto; }
.job-del {
  flex: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text-dim);
  font: inherit;
  font-size: .88rem;
  padding: 0 12px;
  cursor: pointer;
}
.job-del:hover { color: var(--danger); border-color: var(--danger); }

.job-row .when { color: var(--text-dim); white-space: nowrap; }
.job-row .what { flex: 1 1 auto; min-width: 0; overflow-wrap: anywhere; }
.job-row .what .count { color: var(--text-dim); white-space: nowrap; }
.job-row .go { color: var(--brand); font-weight: 600; white-space: nowrap; margin-left: auto; }

.job-badge {
  font-size: .8rem;
  white-space: nowrap;
  font-weight: 600;
  border-radius: 999px;
  padding: 1px 9px;
  border: 1px solid currentColor;
}

.job-badge.queued,
.job-badge.running { color: var(--brand); }
.job-badge.done { color: var(--accent); }
.job-badge.error { color: var(--danger); }
.job-badge.adopted { color: var(--text-dim); }
.job-badge.confirmed { color: var(--accent); background: var(--surface-2); }

.confirm-wrap { align-items: center; margin-top: 12px; }
.confirm-note { color: var(--text-dim); flex: 1 1 200px; }

.mode-hint {
  margin: 0 0 14px;
  padding: 12px 14px;
  background: var(--brand-soft);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font-size: .92rem;
  line-height: 1.6;
}

.result-summary {
  margin: 0 0 12px;
  font-size: .9rem;
  color: var(--text-dim);
}

.results { display: flex; flex-direction: column; gap: 16px; }

.person {
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface-2);
}

.person-head {
  background: var(--brand-soft);
  padding: 10px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  border-bottom: 1px solid var(--border);
}

.person-head h3 {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
  flex: 1 1 auto;
}

.person-head .count {
  font-size: .85rem;
  color: var(--text-dim);
  font-weight: 500;
}

.uncertain-flag {
  font-size: .8rem;
  font-weight: 600;
  color: var(--danger);
  background: var(--danger-soft);
  border: 1px solid currentColor;
  border-radius: 999px;
  padding: 1px 9px;
}

.person-body { padding: 12px 14px 14px; display: flex; flex-direction: column; gap: 14px; }

.uncertain-note {
  margin: 0;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  background: var(--danger-soft);
  color: var(--danger);
  font-size: .88rem;
}

.source-notes {
  font-size: .88rem;
  color: var(--text-dim);
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
}

.source-notes b { color: var(--text); font-weight: 600; }

.field-block { display: flex; flex-direction: column; gap: 6px; }

.field-block .label-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.field-block label {
  font-weight: 600;
  font-size: .9rem;
  flex: 1 1 auto;
}

.field-block .len { font-size: .82rem; color: var(--text-dim); }

.field-block textarea {
  min-height: 92px;
  background: var(--surface);
  line-height: 1.6;
  resize: none;
}

.field-block.empty textarea {
  border-style: dashed;
  color: var(--text-dim);
}

.field-block.empty .btn.copy { display: none; }

.empty-hint {
  font-size: .85rem;
  color: var(--text-dim);
  margin: 0;
}

/* ---------- 설정 ---------- */
dialog {
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  padding: 0;
  width: min(520px, calc(100vw - 32px));
  box-shadow: 0 10px 40px rgba(0, 0, 0, .25);
}

dialog::backdrop { background: rgba(0, 0, 0, .45); }

.dlg-form { padding: 20px; display: flex; flex-direction: column; gap: 16px; }

.dlg-form h2 { margin: 0; font-size: 1.1rem; }

.field { display: flex; flex-direction: column; gap: 5px; }

.field > span { font-weight: 600; font-size: .9rem; }

.field small { color: var(--text-dim); font-size: .85rem; line-height: 1.5; }

.field > .btn { align-self: flex-start; margin-top: 4px; }

.field .inline-note { font-weight: 400; }

.field a { color: var(--brand); }

.dlg-actions {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.dlg-actions .dlg-right { display: flex; gap: 10px; margin-left: auto; }

/* ---------- 기타 ---------- */
.err {
  margin: 12px 0 0;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--danger-soft);
  color: var(--danger);
  font-size: .88rem;
  border: 1px solid currentColor;
}

.foot {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 0 16px 32px;
  color: var(--text-dim);
  font-size: .85rem;
  line-height: 1.6;
}

.toast {
  position: fixed;
  left: 50%;
  top: 72px; /* 상단바 바로 아래. 정확한 위치는 스크립트가 맞춥니다. */
  max-width: calc(100vw - 32px);
  text-align: center;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  padding: 10px 18px;
  border-radius: 999px;
  font-size: .88rem;
  font-weight: 600;
  box-shadow: var(--shadow);
  z-index: 50;
}
