:root {
  --bg: #f4f6f9;
  --card: #ffffff;
  --ink: #1d2733;
  --muted: #76828f;
  --line: #e3e8ee;
  --primary: #1a6fd6;
  --primary-ink: #fff;
  --danger: #c0392b;
  --warn-bg: #fff4d6;
  --warn-ink: #8a6d1b;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, "PingFang TC", "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.5;
}
.topbar {
  display: flex; align-items: baseline; gap: 14px;
  padding: 14px 24px; background: #fff; border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; font-size: 18px; color: var(--ink); text-decoration: none; }
.tagline { color: var(--muted); font-size: 13px; }
.topnav { margin-left: auto; display: flex; align-items: center; gap: 14px; font-size: 13px; }
.topnav a { color: var(--primary); text-decoration: none; }
.linkbtn { border: none; background: none; color: var(--primary); cursor: pointer; font: inherit; padding: 0; }

.auth-card { max-width: 380px; margin: 48px auto; }
.auth-form { display: flex; flex-direction: column; gap: 12px; }
.auth-form label { display: flex; flex-direction: column; gap: 4px; font-size: 14px; }
.auth-form input { padding: 9px; border: 1px solid var(--line); border-radius: 8px; font-size: 14px; }
.auth-error { color: var(--danger); font-size: 14px; }
.yaml-edit { width: 100%; font-family: ui-monospace, Menlo, monospace; font-size: 13px; margin-bottom: 12px; }

/* Settings form (non-technical) */
.settings-card { max-width: 720px; }
.saved-note { color: #1f7a40; font-size: 14px; }
.settings-form { display: flex; flex-direction: column; gap: 16px; }
.fld { display: flex; flex-direction: column; gap: 4px; font-size: 14px; }
.fld input, .fld textarea {
  padding: 9px; border: 1px solid var(--line); border-radius: 8px; font: inherit; font-size: 14px;
}
.group {
  border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px;
  display: flex; flex-direction: column; gap: 10px;
}
.group legend { font-weight: 600; font-size: 14px; padding: 0 6px; }
.repeat-row { display: flex; gap: 8px; align-items: center; }
.repeat-row input { flex: 1; padding: 8px; border: 1px solid var(--line); border-radius: 7px; font-size: 14px; }
.repeat-row .row-del { color: var(--danger); border-color: #e7c3bd; white-space: nowrap; }
.container { max-width: 1200px; margin: 0 auto; padding: 24px; }

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  padding: 20px; margin-bottom: 20px;
}
.card h2 { margin: 0 0 14px; font-size: 17px; }
.upload-card form { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }

.progress {
  height: 8px; background: #eef1f5; border-radius: 999px; overflow: hidden;
  margin: 10px 0 6px; max-width: 420px;
}
.progress-bar {
  height: 100%; width: 0; background: var(--primary);
  transition: width 0.25s ease;
}

.search-bar { display: flex; gap: 8px; margin: 8px 0 14px; flex-wrap: wrap; }
.search-bar input[type="search"] {
  flex: 1; min-width: 180px; padding: 8px 10px;
  border: 1px solid var(--line); border-radius: 8px; font-size: 14px;
}
.search-bar select { padding: 8px; border: 1px solid var(--line); border-radius: 8px; font: inherit; }
.pager { display: flex; align-items: center; gap: 14px; justify-content: center; margin-top: 16px; }

.dup-panel { margin: 12px 0 8px; }
.dup-group {
  display: flex; flex-direction: column; align-items: flex-start; gap: 0;
  border: 1px solid var(--line); border-radius: 10px;
  padding: 8px 12px; margin-bottom: 12px; background: #fafbfd;
}
.dup-row {
  display: flex; gap: 8px; align-items: center; width: 100%;
  padding: 8px 0; font-size: 14px;
  border-bottom: 1px dashed var(--line);
}
.dup-row:last-of-type { border-bottom: none; }
.dup-group button { margin-top: 10px; }

.btn {
  border: 1px solid var(--line); background: #fff; color: var(--ink);
  padding: 8px 14px; border-radius: 8px; cursor: pointer; font-size: 14px;
  text-decoration: none; display: inline-block;
}
.btn:hover { background: #f0f3f7; }
.btn.primary { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); }
.btn.primary:hover { filter: brightness(1.05); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); border-color: #e7c3bd; }
.btn.small { padding: 5px 10px; font-size: 13px; }

.muted { color: var(--muted); font-size: 13px; }
.muted.inline { margin-left: 10px; }
.back { display: inline-block; margin-bottom: 14px; color: var(--primary); text-decoration: none; }

table.contacts { width: 100%; border-collapse: collapse; }
table.contacts th, table.contacts td {
  text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line); font-size: 14px;
}
table.contacts tbody tr { cursor: pointer; }
table.contacts tbody tr:hover { background: #f7f9fc; }
@media (max-width: 560px) {
  .container { padding: 14px; }
  table.contacts th, table.contacts td { padding: 8px 5px; font-size: 13px; }
  .upload-card form { gap: 8px; }
}

.badge {
  display: inline-block; padding: 2px 9px; border-radius: 999px;
  font-size: 12px; background: #eef1f5; color: var(--muted);
}
.status-structured { background: #e3f3e8; color: #1f7a40; }
.status-needs_review { background: var(--warn-bg); color: var(--warn-ink); }
.status-pending { background: #eef1f5; color: var(--muted); }
.status-not_card { background: #fbe4e1; color: var(--danger); }
.follow-to_follow { background: #fff4d6; color: #8a6d1b; }
.follow-contacted { background: #e3eefb; color: #1a5fb4; }
.follow-in_talks { background: #ece3fb; color: #6b3fb0; }
.follow-won { background: #e3f3e8; color: #1f7a40; }
.follow-dropped { background: #eef1f5; color: var(--muted); }
.status-ok { background: #e3f3e8; color: #1f7a40; }
.status-partial { background: var(--warn-bg); color: var(--warn-ink); }
.status-failed { background: #fbe4e1; color: var(--danger); }

.banner { padding: 12px 16px; border-radius: 10px; margin-bottom: 16px; }
.banner.warn { background: var(--warn-bg); color: var(--warn-ink); }
.banner.danger-banner { background: #fbe4e1; color: var(--danger); }
.hidden { display: none !important; }

.workspace {
  display: grid; gap: 20px;
  grid-template-columns: 300px 1fr 1fr;
  align-items: start;
}
@media (max-width: 1000px) { .workspace { grid-template-columns: 1fr; } }
.card-image { width: 100%; border-radius: 8px; border: 1px solid var(--line); cursor: zoom-in; }
.zoom-hint { margin: 6px 0 10px; }

/* Close button shared by overlays */
.lightbox-close {
  position: fixed; top: 16px; right: 20px; z-index: 1001;
  width: 40px; height: 40px; border-radius: 50%;
  border: none; background: rgba(255, 255, 255, 0.15); color: #fff;
  font-size: 20px; cursor: pointer;
}
.lightbox-close:hover { background: rgba(255, 255, 255, 0.3); }

/* Side-by-side compare + edit */
.compare {
  position: fixed; inset: 0; z-index: 1000;
  display: grid; grid-template-columns: 1fr 460px;
  background: rgba(0, 0, 0, 0.92);
}
@media (max-width: 820px) { .compare { grid-template-columns: 1fr; grid-template-rows: 1fr 1fr; } }
.compare-img {
  overflow: auto; display: flex; align-items: flex-start; justify-content: center;
  padding: 20px;
}
.compare-img img {
  max-width: 100%; max-height: calc(100vh - 40px); object-fit: contain;
  cursor: zoom-in; border-radius: 4px;
}
.compare-img img.zoomed { max-width: none; max-height: none; cursor: zoom-out; }
.compare-fields {
  background: var(--card); overflow-y: auto; padding: 22px 22px 60px;
}
.compare-fields h3 { margin: 0 0 14px; font-size: 16px; }
.compare-fields h3 .muted { font-weight: 400; }
.compare-fields .raw-ocr { margin-top: 18px; }

.raw-ocr { margin-top: 12px; }
.raw-ocr summary { cursor: pointer; font-size: 14px; }
.raw-ocr pre {
  white-space: pre-wrap; background: #f7f9fc; padding: 10px; border-radius: 8px;
  font-size: 13px; margin-top: 8px;
}

.fields-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 14px; }
.field { display: flex; flex-direction: column; font-size: 13px; }
.field span { color: var(--muted); margin-bottom: 3px; }
.field input {
  padding: 7px 9px; border: 1px solid var(--line); border-radius: 7px; font-size: 14px;
}
.conf {
  font-size: 11px; padding: 0 6px; border-radius: 999px; margin-left: 4px;
  font-weight: 600; vertical-align: middle;
}
.conf-high { background: #e3f3e8; color: #1f7a40; }
.conf-mid  { background: var(--warn-bg); color: var(--warn-ink); }
.conf-low  { background: #fbe4e1; color: var(--danger); }
#save-fields { margin-top: 14px; }

hr { border: none; border-top: 1px solid var(--line); margin: 20px 0; }

ul.notes { list-style: none; padding: 0; margin: 0 0 12px; }
ul.notes li {
  display: flex; justify-content: space-between; gap: 10px;
  padding: 8px 10px; background: #f7f9fc; border-radius: 8px; margin-bottom: 6px;
  font-size: 14px;
}
.note-body { white-space: pre-wrap; }
.link-del { border: none; background: none; color: var(--danger); cursor: pointer; font-size: 12px; }
textarea {
  width: 100%; padding: 9px; border: 1px solid var(--line); border-radius: 8px;
  font: inherit; font-size: 14px; resize: vertical;
}
#note-input { margin-bottom: 8px; }

.panel { margin-top: 12px; }
.panel h4 { margin: 12px 0 4px; font-size: 13px; color: var(--muted); }
.panel ul { margin: 4px 0; padding-left: 20px; font-size: 14px; }
.source-link { display: block; font-size: 12px; color: var(--primary); word-break: break-all; }

.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin: 10px 0; }
.row label { font-size: 13px; color: var(--muted); }
select { padding: 6px 8px; border: 1px solid var(--line); border-radius: 7px; font: inherit; }
.subject-input { width: 100%; padding: 9px; border: 1px solid var(--line); border-radius: 8px; font: inherit; margin: 8px 0; }
.draft-body { font-size: 14px; }
