:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --hard-bg: #fef2f2;
  --hard-text: #dc2626;
  --hard-border: #fecaca;
  --med-bg: #fffbeb;
  --med-text: #d97706;
  --med-border: #fde68a;
  --easy-bg: #f0fdf4;
  --easy-text: #16a34a;
  --easy-border: #bbf7d0;
  --na-bg: #f1f5f9;
  --na-text: #475569;
  --diff-bg: #fff7ed;
  --diff-border: #fdba74;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 24px;
  background: #0f172a;
  color: #fff;
  position: sticky;
  top: 0;
  z-index: 50;
  box-shadow: 0 2px 8px rgba(0,0,0,0.12);
}

.brand { display: flex; align-items: center; gap: 14px; }
.brand-badge {
  background: linear-gradient(135deg, #3b82f6, #6366f1);
  color: #fff;
  font-weight: 700;
  font-size: 12px;
  padding: 5px 10px;
  border-radius: 6px;
  letter-spacing: 0.5px;
}
.brand h1 { margin: 0; font-size: 17px; font-weight: 600; }
.brand p { margin: 2px 0 0; font-size: 12px; color: #94a3b8; }

.tabs { display: flex; gap: 8px; }
.tab {
  background: rgba(255,255,255,0.08);
  color: #cbd5e1;
  border: 1px solid rgba(255,255,255,0.12);
  padding: 8px 16px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  transition: all 0.15s;
}
.tab:hover { background: rgba(255,255,255,0.16); color: #fff; }
.tab.on { background: #3b82f6; color: #fff; border-color: #3b82f6; }

.workspace {
  display: grid;
  grid-template-columns: 380px minmax(0, 1fr);
  gap: 18px;
  padding: 18px 24px;
  max-width: 1920px;
  margin: 0 auto;
  align-items: start;
}

.sidebar { display: flex; flex-direction: column; gap: 14px; }
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.03);
}
.card-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}
.card-head h2, .card-head h3 {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  color: #1e293b;
}

.sample-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.sample-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #f8fafc;
  cursor: pointer;
  text-align: left;
  transition: all 0.15s;
}
.sample-item:hover { border-color: #93c5fd; background: #eff6ff; }
.sample-item.active { border-color: var(--primary); background: #eff6ff; box-shadow: 0 0 0 2px rgba(37,99,235,0.12); }
.sample-item img {
  width: 42px;
  height: 48px;
  object-fit: cover;
  border-radius: 5px;
  background: #fff;
  flex-shrink: 0;
}
.sample-info { min-width: 0; flex: 1; }
.sample-title { font-weight: 600; font-size: 12.5px; color: #1e293b; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sample-note { font-size: 11px; color: var(--muted); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

.dropzone {
  display: block;
  border: 2px dashed #cbd5e1;
  border-radius: 10px;
  padding: 12px;
  text-align: center;
  cursor: pointer;
  background: #f8fafc;
  transition: all 0.15s;
}
.dropzone:hover, .dropzone.over { border-color: var(--primary); background: #eff6ff; }
.dropzone-sm { padding: 8px; }
.drop-hint { display: flex; flex-direction: column; gap: 4px; color: var(--muted); font-size: 12px; padding: 10px 4px; }
.drop-hint strong { color: #334155; font-size: 13px; }

.preview-wrap { position: relative; display: inline-block; max-width: 100%; }
.preview-wrap img {
  max-height: 220px;
  max-width: 100%;
  border-radius: 8px;
  object-fit: contain;
  display: block;
  margin: 0 auto;
}
.dropzone-sm .preview-wrap img { max-height: 120px; }
.img-tag {
  position: absolute;
  top: 6px;
  left: 6px;
  background: rgba(15, 23, 42, 0.78);
  color: #fff;
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 4px;
}

.detected-area {
  margin-top: 10px;
  padding: 8px 10px;
  background: #f1f5f9;
  border-radius: 8px;
  font-size: 12px;
}
.detected-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; color: #475569; }
.detected-pills { display: flex; flex-wrap: wrap; gap: 6px; }
.det-pill {
  background: #fff;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  padding: 4px 8px;
  font-size: 12px;
  cursor: pointer;
}
.det-pill:hover, .det-pill.on { background: var(--primary); color: #fff; border-color: var(--primary); }

.crop-section { margin-top: 10px; }
.crop-head { display: flex; justify-content: space-between; font-size: 12px; color: #475569; margin-bottom: 4px; }

.field-group { margin-top: 10px; display: flex; flex-direction: column; gap: 4px; }
.field-group label { font-size: 12px; font-weight: 500; color: #475569; }
.field-group input {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
}

.model-checks { display: flex; flex-direction: column; gap: 7px; margin-bottom: 12px; }
.model-check {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  background: #f8fafc;
}
.model-check:hover { border-color: #93c5fd; }
.model-check input { margin-right: 8px; }
.model-check-left { display: flex; align-items: center; font-weight: 600; font-size: 13px; }
.model-provider { font-size: 11px; color: var(--muted); }

.btn-primary {
  width: 100%;
  background: var(--primary);
  color: #fff;
  border: none;
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-primary:disabled { opacity: 0.6; cursor: not-allowed; }

.btn-ghost {
  background: #f1f5f9;
  color: #334155;
  border: 1px solid #cbd5e1;
  padding: 6px 12px;
  border-radius: 7px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
}
.btn-ghost:hover { background: #e2e8f0; }
.link-btn {
  background: none;
  border: none;
  color: var(--primary);
  font-size: 12px;
  cursor: pointer;
  padding: 2px 4px;
}
.link-btn:hover { text-decoration: underline; }
.quick-picks { display: flex; gap: 4px; }

.status-msg { margin: 8px 0 0; font-size: 12px; color: var(--primary); text-align: center; }
.status-msg.err { color: var(--hard-text); }

.history-list { display: flex; flex-direction: column; gap: 6px; max-height: 260px; overflow-y: auto; }
.hist-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  background: #f8fafc;
}
.hist-item:hover { background: #eff6ff; border-color: #93c5fd; }
.hist-item img { width: 34px; height: 34px; border-radius: 4px; object-fit: cover; }
.hist-meta { flex: 1; min-width: 0; font-size: 12px; }
.hist-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hist-sub { font-size: 11px; color: var(--muted); }

/* Stage & Results */
.empty-stage {
  background: var(--surface);
  border: 1px dashed #cbd5e1;
  border-radius: 14px;
  padding: 64px 24px;
  text-align: center;
}
.empty-box h3 { margin: 0 0 8px; font-size: 18px; }
.empty-box p { margin: 0 0 18px; color: var(--muted); }
.legend-pills { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }

.lvl-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 6px;
  border: 1px solid transparent;
}
.lvl-hard { background: var(--hard-bg); color: var(--hard-text); border-color: var(--hard-border); }
.lvl-medium { background: var(--med-bg); color: var(--med-text); border-color: var(--med-border); }
.lvl-easy { background: var(--easy-bg); color: var(--easy-text); border-color: var(--easy-border); }
.lvl-na { background: var(--na-bg); color: var(--na-text); border-color: var(--border); }

.summary-bar {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}
.summary-imgs { display: flex; align-items: center; gap: 12px; }
.summary-imgs img {
  height: 76px;
  width: 76px;
  object-fit: contain;
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 8px;
}
.summary-info h3 { margin: 0 0 4px; font-size: 16px; }
.summary-info p { margin: 0; font-size: 12.5px; color: var(--muted); }

.model-cards-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}
.model-summary-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
}
.model-summary-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}
.model-summary-head b { font-size: 14px; }
.model-ms { font-size: 12px; color: var(--muted); background: #f1f5f9; padding: 2px 8px; border-radius: 99px; }
.model-target { font-size: 12.5px; color: #1e293b; margin-bottom: 8px; padding: 6px 8px; background: #f8fafc; border-radius: 6px; }
.model-counts { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 8px; }
.weakness-list { margin: 0; padding-left: 18px; font-size: 12px; color: #b91c1c; }
.weakness-list li { margin-bottom: 3px; }

.filter-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  background: var(--surface);
  padding: 10px 16px;
  border-radius: 10px;
  border: 1px solid var(--border);
}
.filter-left { display: flex; align-items: baseline; gap: 12px; }
.filter-left h3 { margin: 0; font-size: 15px; }
.compare-meta { font-size: 12.5px; color: var(--muted); }
.filter-controls { display: flex; gap: 12px; }
.CheckPill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  font-weight: 500;
  cursor: pointer;
  padding: 4px 10px;
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 99px;
}

.comparison-tables { display: flex; flex-direction: column; gap: 14px; margin-bottom: 18px; }
.group-block {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
}
.group-block-head {
  padding: 10px 16px;
  background: #f8fafc;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.group-block-head h4 { margin: 0; font-size: 14px; color: #0f172a; }
.group-block-head span { font-size: 12px; color: var(--muted); }

.comp-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}
.comp-table th, .comp-table td {
  padding: 10px 12px;
  border-bottom: 1px solid #f1f5f9;
  vertical-align: top;
  text-align: left;
}
.comp-table th {
  background: #fcfcfd;
  font-size: 12px;
  color: #475569;
  font-weight: 600;
}
.comp-table tr.row-diff { background: var(--diff-bg); }
.col-field { width: 250px; }
.field-title { font-weight: 600; font-size: 13px; color: #1e293b; display: flex; align-items: center; gap: 6px; }
.field-path { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 11px; color: var(--muted); display: block; margin-top: 2px; }
.field-weakness { font-size: 11.5px; color: #64748b; margin-top: 4px; display: block; }
.diff-tag {
  background: #ea580c;
  color: #fff;
  font-size: 10.5px;
  padding: 1px 6px;
  border-radius: 4px;
  font-weight: 600;
}

.cell-code {
  display: block;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
  color: #64748b;
  margin-top: 4px;
}
.cell-desc {
  display: block;
  font-size: 11.5px;
  color: #64748b;
  margin-top: 2px;
}

.raw-tabs { display: flex; gap: 6px; }
.raw-tab {
  padding: 4px 10px;
  font-size: 12px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: #f8fafc;
  cursor: pointer;
}
.raw-tab.on { background: var(--primary); color: #fff; border-color: var(--primary); }
.raw-json {
  background: #0f172a;
  color: #e2e8f0;
  padding: 14px;
  border-radius: 8px;
  font-size: 12px;
  overflow-x: auto;
  max-height: 420px;
  margin: 0;
}

/* Schema Page */
.schema-page, .prompt-page {
  max-width: 1600px;
  margin: 0 auto;
  padding: 20px 24px;
}
.schema-header {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px 22px;
  margin-bottom: 18px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 20px;
}
.schema-header h2 { margin: 0 0 6px; font-size: 18px; }
.schema-header p { margin: 0; color: var(--muted); font-size: 13px; }

.schema-group-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px 20px;
  margin-bottom: 16px;
}
.schema-group-card h3 { margin: 0 0 4px; font-size: 16px; }
.schema-group-sub { margin: 0 0 14px; font-size: 12.5px; color: var(--muted); }
.schema-fields-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(440px, 1fr));
  gap: 14px;
}
.schema-field-box {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  background: #fcfcfd;
}
.schema-field-top { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 4px; }
.schema-field-top b { font-size: 14px; }
.schema-field-top code { font-size: 12px; color: var(--primary); background: #eff6ff; padding: 2px 6px; border-radius: 4px; }
.schema-weakness { font-size: 12px; color: #475569; margin: 0 0 10px; padding-bottom: 8px; border-bottom: 1px dashed var(--border); }
.schema-opts { display: flex; flex-direction: column; gap: 6px; }
.schema-opt-row { display: flex; align-items: baseline; gap: 8px; font-size: 12.5px; }
.schema-opt-row code { font-size: 11.5px; color: #334155; background: #f1f5f9; padding: 1px 6px; border-radius: 4px; flex-shrink: 0; }

/* Prompt Page */
.prompt-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px 22px;
}
.prompt-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.prompt-top h2 { margin: 0 0 4px; font-size: 18px; }
.prompt-top p { margin: 0; font-size: 13px; color: var(--muted); }
.prompt-actions { display: flex; gap: 10px; }
.prompt-actions .btn-primary { width: auto; }
.prompt-grid { display: grid; grid-template-columns: 1.3fr 1fr; gap: 18px; }
.prompt-col { display: flex; flex-direction: column; gap: 8px; }
.prompt-col label { font-weight: 600; font-size: 13px; }
.prompt-col textarea {
  width: 100%;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12.5px;
  line-height: 1.5;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  resize: vertical;
}
.template-preview {
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  font-size: 12px;
  max-height: 360px;
  overflow-y: auto;
  margin: 0;
}
