/* ========================================
   Text Compare — 样式
   ======================================== */

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

.hidden {
  display: none !important;
}

:root {
  --font-mono: 'JetBrains Mono', 'Cascadia Code', 'Fira Code', monospace;
  --font-ui: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;

  --color-bg: #f0f2f5;
  --color-surface: #ffffff;
  --color-header: #1e293b;
  --color-header-text: #f1f5f9;
  --color-text: #1e293b;
  --color-text-secondary: #64748b;
  --color-border: #e2e8f0;
  --color-gutter: #cbd5e1;

  --color-added-bg: rgba(34, 197, 94, 0.12);
  --color-added-word: rgba(34, 197, 94, 0.35);
  --color-added-line-num: #16a34a;
  --color-added-gutter: #22c55e;

  --color-removed-bg: rgba(239, 68, 68, 0.12);
  --color-removed-word: rgba(239, 68, 68, 0.35);
  --color-removed-line-num: #dc2626;
  --color-removed-gutter: #ef4444;

  --color-primary: #3b82f6;
  --color-primary-hover: #2563eb;

  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;

  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.08);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.1);
}

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: var(--font-ui);
  background: var(--color-bg);
  color: var(--color-text);
  display: flex;
  flex-direction: column;
}

/* ---- 顶部栏 ---- */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  height: 56px;
  min-height: 56px;
  background: var(--color-header);
  color: var(--color-header-text);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
  z-index: 100;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.header-title {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.02em;
  display: flex;
  align-items: center;
  gap: 8px;
}

.header-icon {
  width: 22px;
  height: 22px;
  color: var(--color-primary);
}

.header-center {
  display: flex;
  align-items: center;
  gap: 8px;
}

.header-right {
  display: flex;
  align-items: center;
}

/* ---- 按钮 ---- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border: none;
  border-radius: var(--radius-sm);
  font-family: var(--font-ui);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.btn svg {
  width: 15px;
  height: 15px;
  flex-shrink: 0;
}

.btn-primary {
  background: var(--color-primary);
  color: #fff;
}

.btn-primary:hover {
  background: var(--color-primary-hover);
  transform: translateY(-1px);
  box-shadow: 0 2px 8px rgba(59, 130, 246, 0.4);
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.1);
  color: var(--color-header-text);
}

.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.2);
}

.btn-ghost {
  background: transparent;
  color: var(--color-header-text);
  opacity: 0.8;
}

.btn-ghost:hover {
  opacity: 1;
  background: rgba(255, 255, 255, 0.1);
}

/* ---- 选项面板 ---- */
.options-panel {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 8px 24px;
  background: #f8fafc;
  border-bottom: 1px solid var(--color-border);
  transition: all 0.2s ease;
}

.options-panel.hidden {
  display: none;
}

.option-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--color-text-secondary);
  cursor: pointer;
  user-select: none;
}

.option-item input[type="checkbox"] {
  width: 15px;
  height: 15px;
  accent-color: var(--color-primary);
  cursor: pointer;
}

.option-item:hover {
  color: var(--color-text);
}

/* ---- 主内容区 ---- */
.main-content {
  flex: 1;
  display: flex;
  overflow: hidden;
  padding: 12px;
  gap: 0;
  min-height: 0;
}

/* ---- 面板 ---- */
.panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  min-width: 0;
}

.panel-left {
  border-radius: var(--radius-lg) 0 0 var(--radius-lg);
}

.panel-right {
  border-radius: 0 var(--radius-lg) var(--radius-lg) 0;
}

.gutter {
  width: 4px;
  background: var(--color-border);
  cursor: col-resize;
  flex-shrink: 0;
  transition: background 0.15s;
}

.gutter:hover {
  background: var(--color-primary);
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  border-bottom: 1px solid var(--color-border);
  background: #f8fafc;
}

.panel-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--color-text);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.panel-left .panel-label::before {
  content: '';
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--color-removed-gutter);
  margin-right: 8px;
}

.panel-right .panel-label::before {
  content: '';
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--color-added-gutter);
  margin-right: 8px;
}

.panel-stats {
  font-size: 12px;
  font-family: var(--font-mono);
  color: var(--color-text-secondary);
}

.panel-body {
  flex: 1;
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* ---- 文本输入 ---- */
.text-input {
  flex: 1;
  width: 100%;
  padding: 14px 16px;
  border: none;
  outline: none;
  resize: none;
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.65;
  color: var(--color-text);
  background: transparent;
  tab-size: 4;
}

.text-input::placeholder {
  color: var(--color-text-secondary);
  opacity: 0.6;
}

.text-input:focus {
  background: rgba(59, 130, 246, 0.02);
}

/* ---- 差异结果 ---- */
.diff-output {
  flex: 1;
  overflow: auto;
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.65;
}

.diff-output.hidden {
  display: none;
}

.diff-line {
  display: flex;
  min-height: 21.45px;
  border-bottom: 1px solid transparent;
}

.diff-line-num {
  width: 50px;
  min-width: 50px;
  padding: 2px 8px;
  text-align: right;
  color: var(--color-text-secondary);
  opacity: 0.6;
  font-size: 12px;
  user-select: none;
  display: flex;
  align-items: flex-start;
  justify-content: flex-end;
  border-right: 1px solid var(--color-border);
}

.diff-line-marker {
  width: 20px;
  min-width: 20px;
  padding: 2px 0;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  font-weight: 700;
  font-size: 12px;
  user-select: none;
}

.diff-line-content {
  flex: 1;
  padding: 2px 12px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: normal;
  display: block;
  min-width: 0;
}

/* 删除行 */
.diff-line.removed {
  background: var(--color-removed-bg);
}

.diff-line.removed .diff-line-num {
  color: var(--color-removed-line-num);
  opacity: 1;
  background: rgba(239, 68, 68, 0.06);
  border-right-color: rgba(239, 68, 68, 0.2);
}

.diff-line.removed .diff-line-marker {
  color: var(--color-removed-gutter);
}

.diff-word-removed {
  background: var(--color-removed-word);
  border-radius: 2px;
  padding: 0 1px;
}

/* 新增行 */
.diff-line.added {
  background: var(--color-added-bg);
}

.diff-line.added .diff-line-num {
  color: var(--color-added-line-num);
  opacity: 1;
  background: rgba(34, 197, 94, 0.06);
  border-right-color: rgba(34, 197, 94, 0.2);
}

.diff-line.added .diff-line-marker {
  color: var(--color-added-gutter);
}

.diff-word-added {
  background: var(--color-added-word);
  border-radius: 2px;
  padding: 0 1px;
}

/* 空白占位行（用于对齐） */
.diff-line.empty {
  background: #f9fafb;
}

.diff-line.empty .diff-line-num {
  opacity: 0.3;
}

.diff-line.empty .diff-line-content {
  opacity: 0;
}

/* ---- 统计栏 ---- */
.stats-bar {
  display: flex;
  justify-content: center;
  padding: 8px 20px;
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
  box-shadow: 0 -1px 4px rgba(0, 0, 0, 0.04);
  z-index: 50;
}

.stats-bar.hidden {
  display: none;
}

.stats-container {
  display: flex;
  align-items: center;
  gap: 28px;
}

.stat-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 500;
  color: var(--color-text-secondary);
}

.stat-item svg {
  width: 14px;
  height: 14px;
}

.stat-removed svg { color: var(--color-removed-gutter); }
.stat-added svg { color: var(--color-added-gutter); }
.stat-unchanged svg { color: var(--color-text-secondary); }

.stat-removed span:first-of-type { color: var(--color-removed-line-num); font-weight: 700; }
.stat-added span:first-of-type { color: var(--color-added-line-num); font-weight: 700; }

/* ---- 响应式 ---- */
@media (max-width: 768px) {
  .main-content {
    flex-direction: column;
    padding: 8px;
  }

  .gutter {
    width: 100%;
    height: 4px;
    cursor: row-resize;
  }

  .panel-left {
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  }

  .panel-right {
    border-radius: 0 0 var(--radius-lg) var(--radius-lg);
  }

  .header {
    padding: 0 12px;
    height: 48px;
    min-height: 48px;
  }

  .header-title {
    font-size: 15px;
  }

  .btn {
    padding: 5px 10px;
    font-size: 12px;
  }

  .btn-label {
    display: none;
  }
}

@media (max-width: 480px) {
  .header-center {
    gap: 4px;
  }
}

/* ---- 滚动条 ---- */
.diff-output::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

.diff-output::-webkit-scrollbar-track {
  background: transparent;
}

.diff-output::-webkit-scrollbar-thumb {
  background: var(--color-gutter);
  border-radius: 4px;
}

.diff-output::-webkit-scrollbar-thumb:hover {
  background: var(--color-text-secondary);
}

.text-input::-webkit-scrollbar {
  width: 8px;
}

.text-input::-webkit-scrollbar-track {
  background: transparent;
}

.text-input::-webkit-scrollbar-thumb {
  background: var(--color-gutter);
  border-radius: 4px;
}
