:root {
  --primary: #3498db;
  --primary-dark: #2980b9;
  --primary-light: #e3f2fd;
  --gray: #95a5a6;
  --dark: #2c3e50;
  --text-light: #666;
  --light-bg: #f8f9fa;
  --border-radius: 8px;
  --shadow: 0 4px 12px rgba(0,0,0,0.1);
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: 'Segoe UI', system-ui, sans-serif;
  background: linear-gradient(135deg, #f0f7ff, #e3f2fd);
  color: var(--dark);
  line-height: 1.6;
  padding: 10px;
  min-height: 100vh;
}

.container {
  height: 100%;
  display: flex;
  flex-direction: column;
}

header {
  text-align: center;
  margin-bottom: 20px;
}

header h1 {
  font-size: 2.2rem;
  color: var(--primary);
  margin-bottom: 8px;
}

header p {
  color: var(--gray);
  font-size: 1rem;
}

/* 三列布局 */
.main-layout {
  display: flex;
  gap: 10px;
  flex: 1;
  min-height: 0;
}

.panel {
  flex: 1;
  background: white;
  border-radius: var(--border-radius);
  box-shadow: var(--shadow);
  padding: 10px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 600px;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  flex-shrink: 0; /* 🔒 头部不收缩 */
}

.panel h2 {
  font-size: 1.4rem;
  color: var(--primary);
  display: flex;
  align-items: center;
  gap: 8px;
}

.top-right {
  display: flex;
  gap: 8px;
}

footer {
  text-align: center;
  margin-top: 20px;
  color: var(--text-light);
  font-size: 0.9rem;
}

footer a,
footer a:visited,
footer a:hover,
footer a:active {
  color: var(--text-light);
  text-decoration: none;
}

/* 统一文本样式：禁止换行，等宽字体 */
.text-panel textarea,
.diff-result pre,
.diff-result code {
  font-family: 'Consolas', 'Courier New', monospace;
  font-size: 14px;
  line-height: 1.4;
  white-space: pre;
  overflow-x: auto;
  overflow-y: auto;
  tab-size: 4;
}

/* ===== 关键修复：文本编辑面板高度同步 & 无滚动条闪烁 ===== */
.text-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0; /* ✅ 允许内容区收缩 */
}

.text-panel textarea {
  flex: 1;
  width: 100%;
  min-height: 0; /* ✅ 向下穿透 flex shrink */
  padding: 12px;
  border: 1px solid #ddd;
  border-radius: 6px;
  resize: none;
  /* 🚫 禁用垂直滚动条（靠容器控制） */
  overflow-x: auto;
  overflow-y: hidden; /* 🔑 核心修复 */
}

/* ===== 行号与编辑器容器 —— 精确高度同步 ===== */
.editor-container {
  position: relative;
  flex: 1;
  display: flex;
  min-height: 0; /* ✅ 关键：允许 flex shrink */
  border: 1px solid #ddd;
  border-radius: 6px;
  overflow: hidden;
}

.line-numbers {
  width: 50px;
  padding: 12px 8px;
  background: #f6f8fa;
  color: #959da5;
  font-family: 'Consolas', 'Courier New', monospace;
  font-size: 14px;
  line-height: 1.4;
  text-align: right;
  user-select: none;
  pointer-events: none; /* 禁止鼠标交互，穿透到 textarea */
  overflow-y: auto; /* ✅ 行号可滚动（JS 同步） */
  overflow-x: hidden;
  border-right: 1px solid #e1e4e8;
  flex-shrink: 0; /* 宽度固定不收缩 */
}

.editor-container textarea {
  flex: 1;
  min-height: 0;
  margin: 0;
  padding: 12px 12px;
  border: none;
  outline: none;
  resize: none;
  overflow-x: auto;
  overflow-y: hidden; /* 🚫 再次强调：禁止垂直滚动 */
  background: white;
  white-space: pre;
  tab-size: 4;
}

/* Diff 面板 */
.diff-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  flex-shrink: 0;
}

.mode-toggle {
  display: flex;
  gap: 6px;
  flex-wrap: nowrap;
}

.mode-btn {
  padding: 6px 10px;
  font-size: 0.85rem;
  border: 1px solid #ddd;
  background: white;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}

.mode-btn:hover {
  background: #f1f9ff;
  border-color: #a0cfee;
}

.mode-btn.active {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

.diff-result {
  flex: 1;
  background: #fcfdfe;
  border: 1px solid #eaeef5;
  border-radius: 6px;
  padding: 12px;
  overflow: auto;
}

.diff-result pre {
  margin: 0;
}

/* Diff 高亮 */
.diff-add     { background-color: #e6ffed; color: #22863a; }
.diff-remove  { background-color: #ffeef0; color: #cb2431; }
.diff-equal   { color: inherit; }
.patch-header { color: #586069; font-weight: bold; }
.patch-hunk   { color: #6f42c1; background-color: #f5f0ff; }
.patch-context{ color: #586069; }

/* 按钮 */
.btn {
  padding: 6px 12px;
  border: none;
  border-radius: 6px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 0.85rem;
  min-width: auto;
}

.btn.secondary {
  background: white;
  color: var(--primary);
  border: 1px solid var(--primary);
}

.btn.secondary:hover {
  background: var(--primary-light);
}

.btn.outline {
  background: transparent;
  border: 1px solid var(--gray);
  color: var(--gray);
}

.btn.outline:hover {
  background: #f1f3f5;
}

/* 使用说明 */
.instructions {
  background: white;
  border-radius: var(--border-radius);
  padding: 20px;
  box-shadow: var(--shadow);
  margin-top: 20px;
}

.instructions h3 {
  color: var(--primary);
  margin-bottom: 12px;
}

.instructions ul {
  padding-left: 0;
  list-style: none; /* ✅ 移除默认圆点 */
}

.instructions li {
  margin-bottom: 10px;
  padding-left: 24px;
  position: relative;
}

.instructions li::before {
  content: '🔹';
  position: absolute;
  left: 0;
  color: var(--primary);
}

.instructions li ul {
  margin-top: 6px;
  list-style: none; /* ✅ 嵌套列表也清除 */
}

.instructions li li {
  font-size: 0.95rem;
  color: var(--gray);
  padding-left: 36px;
}

.instructions li li::before {
  content: '•';
  color: var(--gray);
}

/* —— 行号高亮状态（增强可见性）—— */
.line-numbers .line-hover {
  /* 更鲜明的背景色（Tailwind blue-100） */
  background-color: #dbeafe !important;
  /* 明显左移：通过 text-indent 实现（不影响布局高度，比 padding-left 更精准） */
  text-indent: -2px;
  /* 可选：加一点左侧 border 强化指示 */
  border-left: 2px solid #3b82f6;
  border-radius: 2px 0 0 2px;
}
.line-numbers .line-focused,
.line-numbers .line-selected {
  background-color: #dbeafe;
  color: #1e40af;
}
/* 优先级：悬停 > 选中/聚焦 */
.line-numbers .line-hover.line-focused,
.line-numbers .line-hover.line-selected {
  background-color: #bfdbfe !important; /* 更亮一层 */
  color: #1d4ed8 !important;
}

/* 响应式 */
@media (max-width: 768px) {
  .main-layout {
    flex-direction: column;
  }
  .mode-toggle {
    flex-wrap: wrap;
  }
}