/* doc-to-md styles. Two themes via [data-theme] on <html>. */

:root, html[data-theme="light"] {
  --bg: #f6f8f7;
  --panel: #ffffff;
  --ink: #17211d;
  --muted: #5a6b64;
  --line: #dbe4e0;
  --accent: #1f6f5c;
  --accent-ink: #ffffff;
  --accent-soft: #e2f1ec;
  --warn: #8a5a00;
  --warn-bg: #fff4dc;
  --bad: #a33232;
  --bad-bg: #fdecec;
  --good: #1f6f2c;
  --good-bg: #e7f5e9;
  --code-bg: #eef2f0;
  --shadow: 0 1px 3px rgba(20, 40, 34, 0.08);
}

html[data-theme="dark"] {
  --bg: #131a17;
  --panel: #1b2420;
  --ink: #e4ece8;
  --muted: #93a49d;
  --line: #2c3833;
  --accent: #4fae95;
  --accent-ink: #0d1512;
  --accent-soft: #22352f;
  --warn: #e3b45e;
  --warn-bg: #33290f;
  --bad: #e08a8a;
  --bad-bg: #3a1f1f;
  --good: #7fce8d;
  --good-bg: #1c2f20;
  --code-bg: #16201c;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }
html { font-size: 16px; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  line-height: 1.55;
}
a { color: var(--accent); }
h1, h2, h3 { line-height: 1.25; }

.visually-hidden {
  position: absolute; width: 1px; height: 1px; margin: -1px;
  clip: rect(0 0 0 0); overflow: hidden; white-space: nowrap;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.warn { color: var(--warn); background: var(--warn-bg); padding: 6px 10px; border-radius: 8px; }

/* header */
.site-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 20px; border-bottom: 1px solid var(--line);
  background: var(--panel); position: sticky; top: 0; z-index: 10;
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; }
.header-nav { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.muted-link { color: var(--muted); text-decoration: none; font-size: 0.9rem; }
.muted-link:hover { color: var(--accent); }

/* buttons, pills */
.btn {
  background: var(--panel); color: var(--ink);
  border: 1px solid var(--line); border-radius: 8px;
  padding: 8px 14px; font-size: 0.95rem; cursor: pointer;
}
.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
.btn.ghost { background: transparent; }
.btn.small { padding: 5px 10px; font-size: 0.85rem; }
.icon-btn {
  background: none; border: 1px solid var(--line); border-radius: 8px;
  padding: 4px 9px; cursor: pointer; color: var(--ink); font-size: 1rem;
}
.pill {
  border: 1px solid var(--line); border-radius: 999px; padding: 3px 10px;
  font-size: 0.8rem; color: var(--muted);
}
.pill.accent { border-color: var(--accent); color: var(--accent); }

/* layout */
main { max-width: 980px; margin: 0 auto; padding: 24px 16px 48px; }
.hero { margin: 8px 0 20px; }
.hero h1 { margin: 0 0 8px; font-size: 1.7rem; }
.hero p { margin: 0; max-width: 64ch; color: var(--muted); }
.card {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 14px; box-shadow: var(--shadow);
  padding: 20px; margin-bottom: 20px;
}
.card h2 { margin-top: 0; font-size: 1.15rem; }

/* dropzone */
.dropzone {
  border: 2px dashed var(--line); border-radius: 12px;
  padding: 26px; text-align: center; cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.dropzone:hover, .dropzone:focus-visible, .dropzone.dragover {
  border-color: var(--accent); background: var(--accent-soft); outline: none;
}
.dz-icon { font-size: 1.9rem; color: var(--accent); }
.dz-hint { color: var(--muted); font-size: 0.85rem; margin-bottom: 0; }
.sample-row { display: flex; align-items: center; gap: 10px; margin-top: 14px; flex-wrap: wrap; }
.sample-row select {
  flex: 1; min-width: 220px; padding: 7px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--panel); color: var(--ink);
}
.options { margin-top: 12px; color: var(--muted); }
.options summary { cursor: pointer; }
.opt-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 8px; padding: 10px 2px; }
.opt-grid label { font-size: 0.9rem; }
.opt-grid input[type="number"] { width: 80px; padding: 3px 6px; border-radius: 6px; border: 1px solid var(--line); background: var(--panel); color: var(--ink); }

/* result */
.result-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; }
.result-head h2, .result-head h3 { margin: 0 0 4px; word-break: break-word; }
.result-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 12px 0; }
.chip {
  background: var(--accent-soft); color: var(--ink);
  border-radius: 999px; padding: 3px 11px; font-size: 0.8rem;
}
.warnings { margin: 10px 0; }
.warnings div {
  background: var(--warn-bg); color: var(--warn);
  border-radius: 8px; padding: 6px 10px; margin-bottom: 6px; font-size: 0.88rem;
}

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-top: 14px; }
.tab {
  background: none; border: none; border-bottom: 2px solid transparent;
  padding: 8px 14px; cursor: pointer; color: var(--muted); font-size: 0.95rem;
}
.tab.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.pane {
  border: 1px solid var(--line); border-top: none;
  border-radius: 0 0 10px 10px; padding: 16px;
  max-height: 560px; overflow: auto; background: var(--panel);
}
.raw {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.82rem; white-space: pre-wrap; word-break: break-word; margin: 0;
}

/* markdown preview */
.md-preview h1 { font-size: 1.5rem; border-bottom: 1px solid var(--line); padding-bottom: 6px; }
.md-preview h2 { font-size: 1.25rem; }
.md-preview h3 { font-size: 1.05rem; }
.md-preview pre {
  background: var(--code-bg); border-radius: 8px; padding: 12px; overflow-x: auto;
}
.md-preview code { background: var(--code-bg); border-radius: 4px; padding: 1px 5px; font-size: 0.86em; }
.md-preview pre code { background: none; padding: 0; }
.md-preview blockquote {
  border-left: 3px solid var(--accent); margin-left: 0; padding-left: 14px; color: var(--muted);
}
.md-tablewrap { overflow-x: auto; }
.md-preview table, #formatsTable { border-collapse: collapse; width: 100%; font-size: 0.9rem; }
.md-preview th, .md-preview td, #formatsTable th, #formatsTable td {
  border: 1px solid var(--line); padding: 6px 10px; text-align: left; vertical-align: top;
}
.md-preview th, #formatsTable th { background: var(--accent-soft); }
.md-meta {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 4px 16px; background: var(--code-bg); border-radius: 8px;
  padding: 10px 14px; margin: 0 0 14px; font-size: 0.85rem;
}
.md-meta div { display: flex; gap: 8px; }
.md-meta dt { color: var(--muted); font-weight: 600; margin: 0; }
.md-meta dd { margin: 0; word-break: break-word; }
.md-marker {
  color: var(--muted); font-size: 0.78rem; font-family: ui-monospace, Menlo, monospace;
  border-left: 3px solid var(--line); padding: 2px 8px; margin: 10px 0;
}
.md-img {
  display: inline-block; background: var(--code-bg); border: 1px dashed var(--line);
  border-radius: 6px; padding: 2px 8px; font-size: 0.85rem; color: var(--muted);
}
.md-img::before { content: "image: "; }
.md-fndef { font-size: 0.85rem; color: var(--muted); margin: 4px 0; }

/* AI card */
.gaps { display: flex; flex-direction: column; gap: 6px; margin: 12px 0; }
.gap-item {
  display: flex; gap: 10px; align-items: flex-start;
  background: var(--accent-soft); border-radius: 8px; padding: 8px 12px; font-size: 0.9rem;
}
.gap-item input { margin-top: 3px; }
.gap-item .gap-detail { color: var(--muted); font-size: 0.82rem; display: block; }
.ai-note-label { display: block; font-size: 0.85rem; color: var(--muted); margin-top: 8px; }
#aiNote {
  width: 100%; padding: 8px 10px; border: 1px solid var(--line);
  border-radius: 8px; background: var(--panel); color: var(--ink); margin: 4px 0 12px;
}
.ai-controls { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }

.progress { margin-top: 16px; }
.progress ol { list-style: none; margin: 0 0 8px; padding: 0; }
.progress li {
  padding: 5px 0 5px 26px; position: relative; color: var(--muted); font-size: 0.92rem;
}
.progress li::before {
  content: ""; position: absolute; left: 6px; top: 11px;
  width: 9px; height: 9px; border-radius: 50%; border: 2px solid var(--line);
}
.progress li.active { color: var(--ink); font-weight: 600; }
.progress li.active::before { border-color: var(--accent); background: var(--accent-soft); }
.progress li.done { color: var(--ink); }
.progress li.done::before { border-color: var(--good); background: var(--good); }
.progress-meta { display: flex; align-items: center; gap: 14px; color: var(--muted); font-size: 0.88rem; }

.reconcile { margin: 12px 0; display: flex; flex-direction: column; gap: 6px; }
.reconcile div { border-radius: 8px; padding: 7px 11px; font-size: 0.88rem; }
.reconcile .ok { background: var(--good-bg); color: var(--good); }
.reconcile .bad { background: var(--bad-bg); color: var(--bad); }
.reconcile .note { background: var(--warn-bg); color: var(--warn); }
.changes {
  background: var(--code-bg); border-radius: 8px; padding: 10px 14px;
  font-size: 0.88rem; margin-bottom: 8px;
}
.changes ul { margin: 6px 0 0; padding-left: 18px; }

/* history */
.history { list-style: none; margin: 0; padding: 0; }
.history li {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  border-top: 1px solid var(--line); padding: 9px 2px; flex-wrap: wrap;
}
.history li:first-child { border-top: none; }
.history .h-name { font-weight: 600; word-break: break-word; }
.history .h-meta { color: var(--muted); font-size: 0.82rem; }
.history .h-actions { display: flex; gap: 6px; }

/* footer */
.site-footer {
  border-top: 1px solid var(--line); padding: 18px 20px 30px;
  color: var(--muted); font-size: 0.85rem; text-align: center;
}

@media (max-width: 640px) {
  .site-header { flex-direction: column; gap: 8px; }
  .hero h1 { font-size: 1.35rem; }
  .pane { max-height: 420px; }
}

/* drive lane */
.drive-controls { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 12px; }
.drive-options {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  margin-top: 12px; font-size: 0.9rem;
}
.drive-options select {
  padding: 5px 8px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--panel); color: var(--ink); max-width: 100%;
}
.queue { list-style: none; margin: 14px 0 0; padding: 0; }
.queue .q-item {
  display: flex; justify-content: space-between; align-items: flex-start; gap: 14px;
  padding: 9px 0; border-top: 1px solid var(--line);
}
.queue .q-item:first-child { border-top: none; }
.queue .q-name { font-weight: 600; word-break: break-word; }
.queue .q-meta { color: var(--muted); font-size: 0.8rem; word-break: break-all; }
.queue .q-status { font-size: 0.85rem; text-align: right; flex: 0 0 44%; word-break: break-word; }
.queue .q-status.pending { color: var(--muted); }
.queue .q-status.skip { color: var(--muted); font-style: italic; }
.queue .q-status.ok { color: var(--good); }
.queue .q-status.bad { color: var(--bad); }

/* url input + scanned-PDF fallback chain */
.url-row { display: flex; align-items: center; gap: 10px; margin-top: 14px; flex-wrap: wrap; }
.url-row label { font-size: 0.9rem; color: var(--muted); }
.url-row input[type="url"] {
  flex: 1 1 280px; min-width: 200px; padding: 6px 10px;
  border: 1px solid var(--line); border-radius: 8px;
  background: var(--panel); color: var(--ink); font: inherit; font-size: 0.9rem;
}
.url-row input[type="url"]:disabled { opacity: 0.55; }
.small.ok { color: var(--good); }
.small.bad { color: var(--bad); }
.scan-lane {
  margin: 16px 0; padding: 14px 16px; border: 1px solid var(--line);
  border-left: 3px solid var(--accent); border-radius: 0 10px 10px 0;
  background: var(--code-bg);
}
.scan-lane h3 { margin: 0 0 4px; font-size: 1rem; }
.scan-steps { margin: 10px 0 0; padding-left: 20px; }
.scan-steps li { margin-bottom: 12px; font-size: 0.9rem; line-height: 1.55; }
.scan-steps li:last-child { margin-bottom: 0; }
.scan-steps .ai-controls { margin-top: 8px; }

/* multi-turn refinement */
.refine {
  margin-top: 18px; padding: 14px 16px; border: 1px solid var(--line);
  border-radius: 10px; background: var(--code-bg);
}
.refine h4 { margin: 0 0 6px; font-size: 0.98rem; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.refine-row { display: flex; gap: 10px; margin-top: 10px; flex-wrap: wrap; }
.refine-row input[type="text"] {
  flex: 1 1 320px; min-width: 200px; padding: 6px 10px;
  border: 1px solid var(--line); border-radius: 8px;
  background: var(--panel); color: var(--ink); font: inherit; font-size: 0.9rem;
}
.refine-row input[type="text"]:disabled { opacity: 0.55; }
.refine-turns { list-style: decimal; margin: 12px 0 0; padding-left: 22px; }
.refine-turns li { margin-bottom: 10px; font-size: 0.88rem; }
.refine-turns .t-ask { font-weight: 600; }
.refine-turns .t-meta { color: var(--muted); font-size: 0.82rem; }
.refine-turns .t-bad { color: var(--bad); font-size: 0.82rem; }
.refine-turns .t-changes { margin: 4px 0 0; padding-left: 18px; color: var(--muted); }

/* per-run model override */
.model-row { display: flex; align-items: center; gap: 10px; margin-top: 12px; flex-wrap: wrap; }
.model-row label { font-size: 0.9rem; color: var(--muted); }
.model-row select {
  padding: 5px 8px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--panel); color: var(--ink); max-width: 100%;
}

/* other output targets */
.export-list { list-style: none; margin: 10px 0 0; padding: 0; }
.export-list li {
  display: flex; justify-content: space-between; align-items: flex-start; gap: 14px;
  padding: 9px 0; border-top: 1px solid var(--line);
}
.export-list li:first-child { border-top: none; }
.export-list .x-name { font-weight: 600; }
.export-list .x-note { color: var(--muted); font-size: 0.82rem; }
.export-list .x-actions { display: flex; gap: 6px; flex: 0 0 auto; }

/* --- re-convert with changed options ------------------------------------- */
.opt-actions {
  display: flex; flex-wrap: wrap; align-items: flex-start; gap: 10px;
  padding: 6px 2px 2px; border-top: 1px solid var(--line); margin-top: 6px;
}
.opt-actions .small { flex: 1 1 300px; }

/* --- what changed (free-lane diff) --------------------------------------- */
.diff-head {
  display: flex; flex-wrap: wrap; gap: 10px; align-items: baseline;
  justify-content: space-between; margin-bottom: 10px;
}
.diff-head p { margin: 0; }
.diff-base { font-size: 0.82rem; color: var(--muted); display: flex; gap: 6px; align-items: center; }
.diff-base select {
  padding: 3px 6px; border-radius: 6px; border: 1px solid var(--line);
  background: var(--panel); color: var(--ink); font-size: 0.82rem; max-width: 220px;
}
.diff-body {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.78rem; line-height: 1.5;
}
.d-hunk { border: 1px solid var(--line); border-radius: 8px; overflow: hidden; margin-bottom: 10px; }
.d-line { display: flex; gap: 8px; padding: 0 8px; white-space: pre-wrap; word-break: break-word; }
.d-mark { flex: 0 0 1ch; color: var(--muted); user-select: none; }
.d-text { flex: 1 1 auto; }
.d-add { background: var(--good-bg); color: var(--good); }
.d-del { background: var(--bad-bg); color: var(--bad); }
.d-same { color: var(--muted); }
.d-gap {
  font-size: 0.75rem; color: var(--muted); text-align: center;
  padding: 4px 0 8px; letter-spacing: 0.03em;
}

/* --- FAQ ------------------------------------------------------------------ */
.faq h3 { font-size: 1rem; margin: 18px 0 4px; }
.faq h3:first-child { margin-top: 4px; }
.faq p { margin: 0 0 4px; color: var(--muted); font-size: 0.92rem; }
