/* ===== Reset & Base ===== */
* { box-sizing: border-box; }
:root {
  --bg: #f8fafc;
  --panel: #ffffff;
  --panel-2: #f1f5f9;
  --border: #e2e8f0;
  --text: #1e293b;
  --text-dim: #64748b;
  --accent: #0ea5e9;
  --added: #16a34a;
  --added-bg: rgba(34, 197, 94, 0.10);
  --removed: #dc2626;
  --removed-bg: rgba(239, 68, 68, 0.10);
  --modified: #d97706;
  --modified-bg: rgba(245, 158, 11, 0.10);
  --typechanged: #8b5cf6;
  --typechanged-bg: rgba(139, 92, 246, 0.10);
  --placeholder: #f1f5f9;
  --equal-bg: rgba(148, 163, 184, 0.06);
  --warn: #f97316;
}

/* ===== 兜底:hidden 属性优先级 ===== */
[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: -apple-system, "PingFang SC", "Microsoft YaHei", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 13px;
  color: var(--text);
  background: var(--bg);
  min-height: 100vh;
}
button, input, select, textarea {
  font: inherit;
  color: inherit;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ===== Top bar ===== */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 24px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand .logo {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px; height: 32px;
  background: linear-gradient(135deg, #0ea5e9 0%, #6366f1 100%);
  border-radius: 6px;
  font-size: 18px;
  color: #ffffff;
  font-weight: 700;
}
.brand .title { font-size: 18px; font-weight: 700; letter-spacing: 0.5px; }
.brand .subtitle { color: var(--text-dim); margin-left: 8px; font-size: 12px; }
.actions .link {
  margin-left: 12px;
  font-size: 12px;
  color: var(--text-dim);
}

/* ===== Toolbar ===== */
.toolbar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: 12px 24px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  gap: 12px;
}
.toolbar-left, .toolbar-center, .toolbar-right { display: flex; align-items: center; gap: 8px; }
.toolbar-right { justify-content: flex-end; flex-wrap: wrap; }

.btn {
  display: inline-flex;
  align-items: center;
  padding: 7px 14px;
  border-radius: 6px;
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--text);
  cursor: pointer;
  transition: all 0.15s ease;
  font-size: 13px;
  white-space: nowrap;
}
.btn:hover { background: var(--panel-2); border-color: #cbd5e1; }
.btn:active { transform: translateY(1px); }
.btn.primary {
  background: linear-gradient(180deg, #38bdf8 0%, #0ea5e9 100%);
  border-color: #0284c7;
  color: #ffffff;
  font-weight: 600;
}
.btn.primary:hover { filter: brightness(1.08); }
.btn.small { padding: 5px 10px; font-size: 12px; }
.btn.ghost { background: transparent; border-color: var(--border); color: var(--text-dim); }
.btn.ghost:hover { color: var(--text); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }

.seg {
  display: inline-flex;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 2px;
}
.seg-btn {
  border: none;
  background: transparent;
  padding: 5px 12px;
  font-size: 12px;
  border-radius: 4px;
  cursor: pointer;
  color: var(--text-dim);
}
.seg-btn.active {
  background: var(--panel);
  color: var(--text);
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.08);
}

.check { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-dim); cursor: pointer; }
.check input { accent-color: var(--accent); }
.warn-text { color: var(--warn); }
.select { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-dim); }
.select select {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 4px 8px;
  font-size: 12px;
}

/* ===== Cards ===== */
.cards {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 12px;
  padding: 16px 24px;
}
.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 16px;
  position: relative;
  overflow: hidden;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.05);
}
.card-label { color: var(--text-dim); font-size: 12px; }
.card-value { font-size: 22px; font-weight: 700; margin-top: 6px; }
.card.added { border-top: 3px solid var(--added); }
.card.removed { border-top: 3px solid var(--removed); }
.card.modified { border-top: 3px solid var(--modified); }
.card.typed { border-top: 3px solid var(--typechanged); }
.card.total { border-top: 3px solid var(--accent); }
.card.equal-card { border-top: 3px solid #94a3b8; }
.card.added .card-value { color: var(--added); }
.card.removed .card-value { color: var(--removed); }
.card.modified .card-value { color: var(--modified); }
.card.typed .card-value { color: var(--typechanged); }
.card.equal-card.success .card-value { color: var(--added); }

/* ===== IO cards ===== */
.io {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  padding: 0 24px 16px;
}
.io-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 220px;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.05);
}
.io-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.io-title { display: flex; align-items: center; gap: 8px; }
.io-label { font-size: 13px; color: var(--text-dim); }
.io-meta { display: flex; gap: 12px; font-size: 12px; color: var(--text-dim); }
.badge {
  display: inline-block;
  padding: 2px 8px;
  font-size: 11px;
  border-radius: 4px;
  font-weight: 600;
  font-family: ui-monospace, "SFMono-Regular", "SF Mono", Menlo, Consolas, monospace;
}
.badge.orig { background: #fee2e2; color: #b91c1c; }
.badge.new { background: #dcfce7; color: #15803d; }

.io-buttons { display: flex; gap: 8px; }
.file-btn {
  display: inline-flex;
  padding: 5px 10px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
}
.file-btn:hover { border-color: #cbd5e1; }
.file-btn input { display: none; }
textarea {
  width: 100%;
  min-height: 180px;
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px 12px;
  resize: vertical;
  font-family: ui-monospace, "SFMono-Regular", "SF Mono", Menlo, Consolas, monospace;
  font-size: 12px;
  line-height: 1.55;
  outline: none;
}
textarea::placeholder { color: #94a3b8; }
textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(14, 165, 233, 0.12); }
.io-status {
  font-size: 12px;
  min-height: 18px;
}
.io-status.error { color: var(--removed); }
.io-status.success { color: var(--added); }

/* ===== Navigator ===== */
.navigator {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 0 24px 12px;
  padding: 10px 16px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.nav-info { font-size: 13px; color: var(--text-dim); }
.nav-buttons { display: flex; gap: 6px; }

/* ===== Diff result area ===== */
.result {
  margin: 0 24px 16px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  min-height: 240px;
  overflow: hidden;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.05);
}
.empty-state {
  padding: 60px;
  text-align: center;
  color: var(--text-dim);
}
.empty-state p { margin: 8px 0; }

.equal-banner {
  padding: 16px;
  background: rgba(34, 197, 94, 0.08);
  color: #15803d;
  text-align: center;
  font-weight: 600;
  border-bottom: 1px solid rgba(34, 197, 94, 0.25);
}

/* ----- Splits diff -----
 * 4 列 CSS grid： [ L行号 | L内容 | R行号 | R内容 ]
 * 每个 split_diff[idx] 在 HTML 里展开为 4 个 cell，配对的 remove/add
 * 永远在同一 grid-row 上，左红右绿严格水平对齐。
 */
.split-wrap {
  display: grid;
  grid-template-columns: 56px minmax(0, 1fr) 56px minmax(0, 1fr);
  font-family: ui-monospace, "SFMono-Regular", "SF Mono", Menlo, Consolas, monospace;
  font-size: 12.5px;
  max-height: 70vh;
  overflow: auto;
  background: var(--panel);
}
.split-hdr-l {
  position: sticky; top: 0;
  background: var(--panel-2);
  padding: 8px 12px;
  font-size: 12px;
  border-bottom: 1px solid var(--border);
  border-right: 1px solid var(--border);
  z-index: 2;
}
.split-hdr-mid {
  position: sticky; top: 0;
  background: var(--panel-2);
  border-bottom: 1px solid var(--border);
  border-right: 1px solid var(--border);
  z-index: 2;
}
.split-hdr-r {
  position: sticky; top: 0;
  background: var(--panel-2);
  padding: 8px 12px;
  font-size: 12px;
  border-bottom: 1px solid var(--border);
  border-left: 1px solid var(--border);
  z-index: 2;
}
.split-wrap > .cell {
  padding: 2px 10px;
  white-space: pre;
  overflow: hidden;
  text-overflow: clip;
  min-height: 20px;
  border-bottom: 1px solid #f1f5f9;
}
.split-wrap > .cell.no {
  background: var(--panel-2);
  color: var(--text-dim);
  text-align: right;
  user-select: none;
  border-right: 1px solid var(--border);
}
.split-wrap > .cell.content.L {
  border-right: 1px solid var(--border);
}
.split-wrap > .cell.content { overflow-x: auto; }
.split-wrap > .cell.equal { background: var(--equal-bg); }
.split-wrap > .cell.remove.content,
.split-wrap > .cell.remove.no { background: var(--removed-bg); color: #b91c1c; }
.split-wrap > .cell.remove.no { font-weight: 600; background: rgba(239, 68, 68, 0.16); }
.split-wrap > .cell.add.content,
.split-wrap > .cell.add.no { background: var(--added-bg); color: #15803d; }
.split-wrap > .cell.add.no { font-weight: 600; background: rgba(34, 197, 94, 0.16); }
.split-wrap > .cell.placeholder {
  background: transparent !important;
  color: transparent;
  border-right-color: transparent;
  border-bottom-color: transparent;
}
.split-wrap > .cell.diff-marker {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
  z-index: 1;
}


/* ----- Unified diff ----- */
.unified-wrap {
  font-family: ui-monospace, "SFMono-Regular", "SF Mono", Menlo, Consolas, monospace;
  font-size: 12.5px;
  max-height: 70vh;
  overflow: auto;
}
.unified-line {
  display: grid;
  grid-template-columns: 56px 56px 24px 1fr;
  white-space: pre;
  border-bottom: 1px solid #f1f5f9;
}
.unified-line .no { color: var(--text-dim); padding: 2px 8px; text-align: right; user-select: none; background: var(--panel-2); border-right: 1px solid var(--border); }
.unified-line .marker { text-align: center; color: var(--text-dim); padding: 2px 0; user-select: none; }
.unified-line .content { padding: 2px 10px; overflow-x: auto; }
.unified-line.equal .content { background: var(--equal-bg); }
.unified-line.add .content { background: var(--added-bg); color: #15803d; }
.unified-line.add .marker { color: #16a34a; font-weight: 700; }
.unified-line.remove .content { background: var(--removed-bg); color: #b91c1c; }
.unified-line.remove .marker { color: #dc2626; font-weight: 700; }
.unified-line.diff-marker { outline: 2px solid var(--accent); outline-offset: -2px; }
.unified-hunk { color: #0369a1; padding: 6px 12px; background: rgba(14, 165, 233, 0.08); border-top: 1px solid rgba(14, 165, 233, 0.18); border-bottom: 1px solid rgba(14, 165, 233, 0.18); }

/* ===== Structured diff table ===== */
.structured {
  margin: 0 24px 24px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.05);
}
.structured-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}
.structured-header h3 { margin: 0; font-size: 14px; }
.count-pill {
  display: inline-block;
  background: var(--panel-2);
  color: var(--text);
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}
.structured-table-wrap { overflow-x: auto; }
.structured-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
}
.structured-table th {
  background: var(--panel-2);
  text-align: left;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  color: var(--text-dim);
}
.structured-table td {
  padding: 8px 12px;
  border-bottom: 1px solid #f1f5f9;
  vertical-align: top;
}
.structured-table tbody tr:hover { background: rgba(14, 165, 233, 0.05); cursor: pointer; }
.col-idx { width: 36px; color: var(--text-dim); }
.col-path { font-family: ui-monospace, "SFMono-Regular", "SF Mono", Menlo, Consolas, monospace; }
.col-type { width: 100px; }
.col-old, .col-new { width: 80px; }
.col-act { width: 60px; }
.type-tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}
.type-tag.added { background: var(--added-bg); color: #15803d; }
.type-tag.removed { background: var(--removed-bg); color: #b91c1c; }
.type-tag.modified { background: var(--modified-bg); color: #b45309; }
.type-tag.type_changed { background: var(--typechanged-bg); color: #7c3aed; }
.type-tag.warning, .type-tag.too_deep { background: rgba(249, 115, 22, 0.12); color: #c2410c; }
.val { font-family: ui-monospace, "SFMono-Regular", "SF Mono", Menlo, Consolas, monospace; word-break: break-all; max-width: 360px; }
.val.muted { color: var(--text-dim); }
.val.preview { cursor: pointer; text-decoration: underline dotted; }
.act-btn {
  display: inline-flex;
  align-items: center;
  padding: 3px 8px;
  font-size: 11px;
  border-radius: 4px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text-dim);
  cursor: pointer;
}
.act-btn:hover { color: var(--text); }
.copy-status { color: var(--added); font-size: 11px; margin-left: 6px; }

/* ===== Modal ===== */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.modal-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  max-width: 800px;
  width: 92%;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 12px 40px rgba(15, 23, 42, 0.18);
}
.modal-card header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  background: var(--panel-2);
  border-bottom: 1px solid var(--border);
}
.modal-card header button {
  padding: 4px 10px;
  border-radius: 4px;
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--text-dim);
  cursor: pointer;
  font-size: 12px;
}
.modal-card header button:hover { color: var(--text); border-color: #cbd5e1; }
.modal-card pre {
  margin: 0;
  padding: 16px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-all;
  font-family: ui-monospace, "SFMono-Regular", "SF Mono", Menlo, Consolas, monospace;
  font-size: 13px;
}

/* ===== Toast ===== */
.toast {
  position: fixed;
  top: 20px; left: 50%;
  transform: translateX(-50%);
  background: var(--panel);
  border: 1px solid var(--border);
  padding: 10px 18px;
  border-radius: 6px;
  z-index: 200;
  font-size: 13px;
  box-shadow: 0 6px 24px rgba(15, 23, 42, 0.12);
}
.toast.success { border-color: #16a34a; color: #15803d; }
.toast.error { border-color: #dc2626; color: #b91c1c; }

/* ===== Footer ===== */
.foot {
  display: flex;
  justify-content: space-between;
  padding: 18px 24px;
  font-size: 11px;
  color: var(--text-dim);
  border-top: 1px solid var(--border);
  background: var(--panel);
}

/* ===== Responsive ===== */
@media (max-width: 980px) {
  .io { grid-template-columns: 1fr; }
  .cards { grid-template-columns: repeat(3, 1fr); }
  .toolbar { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  .cards { grid-template-columns: repeat(2, 1fr); }
}

/* ===== 折叠未变化行（由 JS 添加 .collapsed-equal 触发） ===== */
.split-wrap > .cell.collapsed-equal { display: none; }
.unified-line.collapsed-equal { display: none; }

/* ===== 折叠汇总占位行（分页结果"折叠未变化"的全量差异视图） ===== */
/* 虚线贯穿整行，文字居中压在线上；浅色主题下用 --text-dim 灰字 */
.fold-gap {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 7px 12px;
  color: var(--text-dim);
  background: var(--panel-2);
  font-size: 12px;
  user-select: none;
  border-bottom: 1px solid var(--border);
}
.fold-gap::before {
  content: "";
  position: absolute;
  left: 16px;
  right: 16px;
  top: 50%;
  border-top: 1px dashed #cbd5e1;
}
.fold-gap-text {
  position: relative;
  background: var(--panel-2);
  padding: 0 12px;
  white-space: nowrap;
}
/* split 视图：占位行 = 空 cell（L行号列）+ 文本 cell 占满剩余 3 列 */
.split-wrap > .cell.fold-gap { grid-column: 2 / -1; }
.split-wrap > .cell.fold-gap-empty {
  background: var(--panel-2);
  border-bottom: 1px solid var(--border);
  min-height: 20px;
}
/* unified 视图：占位行占满整行 */
.unified-line.fold-gap { grid-column: 1 / -1; }

/* ===== 警告横幅（后端 warnings / warning 降级提示） ===== */
.warn-banner {
  padding: 10px 16px;
  background: rgba(249, 115, 22, 0.08);
  color: #c2410c;
  font-size: 12.5px;
  font-weight: 600;
  border-bottom: 1px solid rgba(249, 115, 22, 0.25);
}

/* ===== 导航条扩展：差异跳转 / 行搜索 ===== */
.navigator { flex-wrap: wrap; gap: 8px; }
.nav-info { display: inline-flex; align-items: center; gap: 6px; }
.nav-goto-input {
  width: 72px;
  padding: 4px 8px;
  font-size: 12px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--panel);
  color: var(--text);
}
.nav-search { display: inline-flex; align-items: center; gap: 6px; }
.nav-search input {
  width: 160px;
  padding: 4px 8px;
  font-size: 12px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--panel);
  color: var(--text);
}
.nav-search input:focus, .nav-goto-input:focus {
  border-color: var(--accent);
  outline: none;
  box-shadow: 0 0 0 3px rgba(14, 165, 233, 0.12);
}
.search-info { font-size: 12px; color: var(--text-dim); min-width: 64px; }
.btn.ghost.active {
  color: var(--accent);
  border-color: var(--accent);
}

/* ===== 搜索命中高亮（与差异定位的 diff-marker 区分，用暖橙色） ===== */
.split-wrap > .cell.search-hit {
  outline: 2px solid var(--warn);
  outline-offset: -2px;
  z-index: 1;
}
.unified-line.search-hit {
  outline: 2px solid var(--warn);
  outline-offset: -2px;
}

/* ===== 超长行：默认截断 + 点击展开 ===== */
.longline-toggle {
  color: var(--accent);
  cursor: pointer;
  font-size: 11px;
  padding-left: 6px;
  white-space: nowrap;
  user-select: none;
}
.longline-toggle:hover { text-decoration: underline; }
.cell.content.has-longline, .unified-line .content.has-longline { cursor: pointer; }
.cell.content.expanded, .unified-line .content.expanded {
  cursor: text;
}

/* ===== 长行换行开关（缓解 white-space: pre 导致的横向细滚动条） ===== */
#resultArea.wrap-lines .split-wrap > .cell.content,
#resultArea.wrap-lines .unified-line .content {
  white-space: pre-wrap;
  word-break: break-all;
  overflow-x: hidden;
}
#resultArea.wrap-lines .unified-line { white-space: normal; }

/* ===== 分页条：统一行视图与结构化表格的分页样式 ===== */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 10px;
  padding: 8px 12px;
  border-top: 1px solid var(--border, #e2e8f0);
}
.pager-info { font-size: 12px; color: var(--text-dim, #64748b); }
.pager-goto { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; color: var(--text-dim); }
.pager-goto input {
  width: 64px;
  padding: 4px 8px;
  font-size: 12px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--panel);
  color: var(--text);
}
.pager-goto input:focus {
  border-color: var(--accent);
  outline: none;
  box-shadow: 0 0 0 3px rgba(14, 165, 233, 0.12);
}

/* ===== 结构化差异表：垂直滚动 + 表头吸顶 + 过滤条 ===== */
.structured-table-wrap {
  overflow: auto;
  max-height: 60vh;
}
.structured-table thead th {
  position: sticky;
  top: 0;
  z-index: 2;
}
.trunc-note {
  font-size: 12px;
  color: #c2410c;
  background: rgba(249, 115, 22, 0.10);
  padding: 2px 10px;
  border-radius: 999px;
  font-weight: 600;
}
.struct-filter {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.struct-filter input, .struct-filter select {
  padding: 4px 8px;
  font-size: 12px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--panel);
  color: var(--text);
}
.struct-filter input { width: 160px; }
.struct-filter input:focus, .struct-filter select:focus {
  border-color: var(--accent);
  outline: none;
  box-shadow: 0 0 0 3px rgba(14, 165, 233, 0.12);
}
