:root {
  --fg: #1f2330;
  --muted: #5a6173;
  --bg: #f5f6fa;
  --card: #ffffff;
  --line: #e3e6ee;
  --accent: #2b6cb0;
  --accent-fg: #ffffff;
  --danger: #c53030;
  --ok: #2f855a;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;
  color: var(--fg);
  background: var(--bg);
}
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 1;
}
.topbar h1 { font-size: 18px; margin: 0; }
.topbar .links a { color: var(--muted); margin-left: 16px; text-decoration: none; }
.topbar .links a:hover { color: var(--accent); }
main {
  max-width: 880px;
  margin: 24px auto;
  padding: 0 16px;
  display: grid;
  gap: 20px;
}
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 20px;
}
.card h2 { margin: 0 0 6px; font-size: 17px; }
.hint { color: var(--muted); margin: 0 0 14px; }
label {
  display: block;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 12px;
}
input, textarea, button {
  font: inherit;
}
input[type=text], input[type=email], input[type=password], input[type=url], textarea {
  width: 100%;
  margin-top: 4px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fafbff;
  color: var(--fg);
}
textarea { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.grid-two {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
@media (max-width: 520px) { .grid-two { grid-template-columns: 1fr; } }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 6px; }
button {
  padding: 8px 14px;
  border: 0;
  border-radius: 6px;
  background: var(--accent);
  color: var(--accent-fg);
  cursor: pointer;
}
button:disabled { opacity: .5; cursor: not-allowed; }
button.secondary {
  background: #e3e6ee;
  color: var(--fg);
}
button.ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--line);
}
.status { font-size: 13px; color: var(--muted); margin: 10px 0 0; }
.status.ok { color: var(--ok); }
.status.err { color: var(--danger); }
.filepick {
  display: inline-block;
  padding: 8px 12px;
  border: 1px dashed var(--line);
  border-radius: 6px;
  cursor: pointer;
  color: var(--muted);
  margin-bottom: 12px;
}
.filepick input { display: none; }
.preview img {
  max-width: 100%;
  max-height: 240px;
  border-radius: 6px;
  margin: 10px 0;
  background: #000;
}
.preview progress { width: 100%; height: 6px; }
.captures {
  display: grid;
  gap: 12px;
  margin-top: 12px;
}
.captures article {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  display: grid;
  grid-template-columns: 96px 1fr;
  gap: 12px;
}
.captures article img {
  width: 96px;
  height: 96px;
  object-fit: cover;
  border-radius: 6px;
  background: #ddd;
}
.captures article .meta { font-size: 12px; color: var(--muted); }
.captures article pre {
  white-space: pre-wrap;
  word-break: break-word;
  margin: 6px 0 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 13px;
  max-height: 120px;
  overflow: auto;
}
.foot {
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  padding: 24px;
}
.foot a { color: var(--muted); }
.settings {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px 8px;
  background: #fafbff;
  margin-bottom: 14px;
}
.settings > summary {
  list-style: none;
  cursor: pointer;
  font-weight: 600;
  font-size: 13px;
  padding: 10px 0;
  color: var(--fg);
}
.settings > summary::after {
  content: ' ▾';
  color: var(--muted);
}
.settings[open] > summary::after { content: ' ▴'; }
.settings select {
  width: 100%;
  margin-top: 4px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--fg);
  font: inherit;
}
.badge {
  display: inline-block;
  padding: 4px 10px;
  font-size: 12px;
  border-radius: 999px;
  background: #eef0f6;
  color: var(--fg);
  border: 1px solid var(--line);
}

/* schema-template chips + generic small buttons */
.chiprow { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.chip {
  padding: 4px 10px;
  font-size: 12px;
  border-radius: 999px;
  background: #eef0f6;
  color: var(--fg);
  border: 1px solid var(--line);
  cursor: pointer;
}
.chip:hover { background: #e3e6ee; }

/* fields view (AI form) */
.fields-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 13px;
}
.fields-grid {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
}
.field {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #fafbff;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.field-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}
.field-label { margin: 0; color: var(--fg); }
.field-name { font-weight: 600; font-size: 13px; }
.field-name .req { color: var(--danger); margin-left: 3px; }
.field-meta {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  margin-top: 2px;
}
.field-input input[type=text],
.field-input input[type=number],
.field-input input[type=date] {
  width: 100%;
  margin-top: 0;
}
.field-input .checkbox {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--fg);
}
.field-input .checkbox input {
  width: auto;
  margin: 0;
}
.evidence {
  font-size: 11px;
  color: var(--muted);
  font-style: italic;
  border-left: 2px solid var(--line);
  padding-left: 6px;
  max-height: 3.6em;
  overflow: hidden;
  text-overflow: ellipsis;
}
.field-actions {
  display: flex;
  justify-content: flex-end;
}
.field-actions button {
  padding: 2px 8px;
  font-size: 11px;
}

.conf {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: 4px;
  white-space: nowrap;
}
.conf-ok   { background: #e6f4ea; color: #1e6c37; }
.conf-warn { background: #fff4e5; color: #8a5100; }
.conf-err  { background: #ffe4e4; color: #a52020; }

/* structured preview inside the captures list */
.mini-fields { display: flex; flex-wrap: wrap; gap: 4px; margin: 4px 0 6px; }
.pill {
  font-size: 11px;
  background: #eef0f6;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 2px 8px;
  color: var(--muted);
}
.pill b { color: var(--fg); font-weight: 600; }
code {
  font: 13px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace;
  background: #eef0f6;
  padding: 1px 6px;
  border-radius: 4px;
}
