/* ========== Reset & Base ========== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0a0f1e;
  --bg-2: #0f172a;
  --surface: rgba(255, 255, 255, 0.04);
  --surface-2: rgba(255, 255, 255, 0.08);
  --border: rgba(148, 163, 184, 0.18);
  --border-strong: rgba(148, 163, 184, 0.32);
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --text-dim: #64748b;
  --accent: #3b82f6;
  --accent-2: #8b5cf6;
  --success: #10b981;
  --danger: #ef4444;
  --warning: #f59e0b;
  --info: #06b6d4;

  --add-bg: rgba(16, 185, 129, 0.18);
  --add-bg-strong: rgba(16, 185, 129, 0.35);
  --add-border: rgba(16, 185, 129, 0.45);
  --add-text: #6ee7b7;
  --del-bg: rgba(239, 68, 68, 0.18);
  --del-bg-strong: rgba(239, 68, 68, 0.35);
  --del-border: rgba(239, 68, 68, 0.45);
  --del-text: #fca5a5;
  --mod-bg: rgba(245, 158, 11, 0.12);
  --mod-border: rgba(245, 158, 11, 0.35);
  --gutter-bg: rgba(0,0,0,0.2);
  --gutter-text: #64748b;
  --hl: rgba(59, 130, 246, 0.25);

  --radius: 14px;
  --radius-sm: 8px;
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}

html, body {
  height: 100%;
  width: 100%;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

body {
  background:
    radial-gradient(1100px 500px at 10% -10%, rgba(59, 130, 246, 0.18), transparent 60%),
    radial-gradient(900px 500px at 90% 0%, rgba(139, 92, 246, 0.18), transparent 60%),
    radial-gradient(1100px 600px at 50% 110%, rgba(6, 182, 212, 0.10), transparent 60%),
    linear-gradient(180deg, #070b18, #0a0f1e);
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  width: 100vw;
}

/* ========== Header ========== */
.app-header {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  background: rgba(10, 15, 30, 0.6);
  -webkit-backdrop-filter: blur(18px);
  backdrop-filter: blur(18px);
  border-bottom: 1px solid var(--border);
  z-index: 20;
}

.brand { display: flex; align-items: center; gap: 12px; }

.logo {
  width: 42px;
  height: 42px;
  border-radius: 11px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2), var(--info));
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  box-shadow: 0 8px 22px rgba(59, 130, 246, 0.35);
}
.logo svg { width: 22px; height: 22px; }

.brand-text h1 {
  font-size: 18px;
  font-weight: 800;
  letter-spacing: -0.02em;
  background: linear-gradient(90deg, #fff, #bfdbfe);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.brand-text p { font-size: 12px; color: var(--text-muted); margin-top: 1px; }

.header-actions { display: flex; gap: 8px; }

/* ========== Buttons ========== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.18s ease;
  white-space: nowrap;
  color: var(--text);
  background: var(--surface);
}
.btn svg { width: 16px; height: 16px; flex-shrink: 0; }
.btn:hover:not(:disabled) { background: var(--surface-2); border-color: var(--border-strong); transform: translateY(-1px); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border: none;
  color: white;
  box-shadow: 0 4px 14px rgba(59, 130, 246, 0.4);
}
.btn-primary:hover:not(:disabled) { box-shadow: 0 6px 20px rgba(59, 130, 246, 0.5); filter: brightness(1.08); }
.btn-ghost { background: transparent; }
.btn-ghost:hover:not(:disabled) { background: var(--surface); }

.icon-btn {
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s;
}
.icon-btn:hover:not(:disabled) { background: var(--surface-2); color: var(--text); border-color: var(--border-strong); }
.icon-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.icon-btn svg { width: 16px; height: 16px; }

/* ========== Main ========== */
.app-main {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 18px 24px 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.app-main::-webkit-scrollbar { width: 10px; }
.app-main::-webkit-scrollbar-track { background: transparent; }
.app-main::-webkit-scrollbar-thumb { background: rgba(148, 163, 184, 0.2); border-radius: 10px; }
.app-main::-webkit-scrollbar-thumb:hover { background: rgba(148, 163, 184, 0.35); }

/* ========== Toolbar ========== */
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
}
.tool-group { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.tool-group.right-actions { gap: 10px; }
.toggle-group { gap: 14px; }

.segmented {
  display: inline-flex;
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 3px;
}
.seg {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  background: transparent;
  border: none;
  border-radius: 6px;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.15s;
}
.seg:hover { color: var(--text); }
.seg.active {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: white;
  box-shadow: 0 2px 8px rgba(59, 130, 246, 0.35);
}

.chk {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
}
.chk input {
  appearance: none;
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  border: 1.5px solid var(--border-strong);
  border-radius: 4px;
  background: rgba(0,0,0,0.25);
  cursor: pointer;
  position: relative;
  transition: all 0.15s;
  flex-shrink: 0;
}
.chk input:checked {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border-color: transparent;
}
.chk input:checked::after {
  content: '';
  position: absolute;
  left: 4px; top: 1px;
  width: 5px; height: 9px;
  border: solid white;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}
.chk:hover { color: var(--text); }

.nav-buttons {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 8px;
  background: rgba(0,0,0,0.25);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.nav-label {
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  color: var(--text-muted);
  min-width: 44px;
  text-align: center;
  font-weight: 600;
}

/* ========== Stats ========== */
.stats-bar {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 12px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  flex-wrap: wrap;
}
.stat { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; }
.stat-dot { width: 10px; height: 10px; border-radius: 50%; }
.stat-added .stat-dot { background: var(--success); box-shadow: 0 0 8px rgba(16,185,129,0.5); }
.stat-removed .stat-dot { background: var(--danger); box-shadow: 0 0 8px rgba(239,68,68,0.5); }
.stat-modified .stat-dot { background: var(--warning); box-shadow: 0 0 8px rgba(245,158,11,0.5); }
.stat-similarity .stat-dot { background: var(--accent); }
.stat-num { font-weight: 800; color: var(--text); font-variant-numeric: tabular-nums; }
.stat-lbl { color: var(--text-muted); font-weight: 500; font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; }
.stat-similarity, .stat-lines { margin-left: auto; gap: 6px; }

/* ========== Editors ========== */
.editors {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  height: 240px;
  flex-shrink: 0;
}
.pane { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.pane-divider { width: 1px; background: var(--border); }
.pane-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: rgba(0,0,0,0.25);
  border-bottom: 1px solid var(--border);
  gap: 10px;
  flex-shrink: 0;
}
.pane-title { display: inline-flex; align-items: center; gap: 8px; font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-muted); }
.pane-icon {
  width: 22px; height: 22px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 800;
  color: white;
}
.left-icon { background: linear-gradient(135deg, var(--accent), var(--info)); }
.right-icon { background: linear-gradient(135deg, var(--accent-2), var(--danger)); }
.pane-actions { display: inline-flex; align-items: center; gap: 8px; }
.line-count { font-size: 11px; color: var(--text-dim); font-variant-numeric: tabular-nums; font-weight: 600; }

.file-btn {
  width: 28px; height: 28px;
  display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s;
}
.file-btn:hover { background: var(--surface-2); color: var(--text); border-color: var(--border-strong); }

.editors textarea {
  flex: 1;
  width: 100%;
  min-height: 0;
  padding: 14px;
  background: rgba(0,0,0,0.2);
  border: none;
  outline: none;
  color: var(--text);
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.5;
  resize: none;
  tab-size: 2;
}
.editors textarea::placeholder { color: var(--text-dim); }

/* ========== Results ========== */
.results-section {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.results-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
}
.results-header h2 {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.01em;
}
.legend { display: flex; gap: 14px; flex-wrap: wrap; }
.legend-item { display: inline-flex; align-items: center; gap: 6px; font-size: 11px; color: var(--text-muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; }
.sw { width: 14px; height: 10px; border-radius: 3px; display: inline-block; }
.sw-add { background: var(--add-bg); border: 1px solid var(--add-border); }
.sw-del { background: var(--del-bg); border: 1px solid var(--del-border); }
.sw-mod { background: var(--mod-bg); border: 1px solid var(--mod-border); }
.sw-unch { background: rgba(255,255,255,0.05); border: 1px solid var(--border); }

.diff-container {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow-x: auto;
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.55;
  min-height: 300px;
}
.diff-container::-webkit-scrollbar { height: 10px; width: 10px; }
.diff-container::-webkit-scrollbar-track { background: transparent; }
.diff-container::-webkit-scrollbar-thumb { background: rgba(148, 163, 184, 0.2); border-radius: 10px; }

/* Split view */
.diff-split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  position: relative;
}
.diff-split-col { min-width: 0; }
.diff-split-col.col-left { border-right: 1px solid var(--border); }
.diff-col-head {
  position: sticky;
  top: 0;
  z-index: 5;
  padding: 8px 12px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  background: rgba(0,0,0,0.45);
  border-bottom: 1px solid var(--border);
  color: var(--text-muted);
}
.col-left .diff-col-head { color: var(--info); }
.col-right .diff-col-head { color: var(--accent-2); }

.diff-row {
  display: contents;
}
.diff-line {
  display: grid;
  grid-template-columns: 52px 1fr;
  min-height: 24px;
  border-left: 3px solid transparent;
  white-space: pre-wrap;
  word-break: break-word;
}
.diff-line.add { background: var(--add-bg); border-left-color: var(--success); }
.diff-line.del { background: var(--del-bg); border-left-color: var(--danger); }
.diff-line.mod { background: var(--mod-bg); border-left-color: var(--warning); }
.diff-line.empty { background: rgba(0,0,0,0.15); opacity: 0.5; }
.diff-line.current { box-shadow: inset 0 0 0 2px var(--accent); position: relative; z-index: 1; }

.gutter {
  padding: 2px 8px 2px 10px;
  text-align: right;
  color: var(--gutter-text);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  background: var(--gutter-bg);
  border-right: 1px solid var(--border);
  user-select: none;
}
.line-content {
  padding: 2px 12px;
  position: relative;
}
.line-content.no-num { padding-left: 12px; }
.gutter.no-num { color: transparent; }

/* Character-level changes */
.tok-add { background: var(--add-bg-strong); color: var(--add-text); border-radius: 3px; padding: 0 1px; text-decoration: none; }
.tok-del { background: var(--del-bg-strong); color: var(--del-text); border-radius: 3px; padding: 0 1px; }

/* Unified view */
.diff-unified { display: flex; flex-direction: column; }
.diff-unified .diff-line { grid-template-columns: 60px 60px 1fr; }
.diff-unified .gutter.b { background: rgba(0,0,0,0.2); }
.diff-unified .line-content.no-num { padding-left: 12px; }

/* No-diff message */
.no-diff {
  padding: 40px 20px;
  text-align: center;
  color: var(--success);
  font-weight: 600;
}
.no-diff svg { width: 44px; height: 44px; margin: 0 auto 10px; display: block; }

/* ========== Toast ========== */
.toast {
  position: fixed;
  bottom: 30px;
  left: 50%;
  transform: translateX(-50%);
  padding: 12px 20px;
  background: rgba(10, 15, 30, 0.95);
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  font-size: 13px;
  font-weight: 600;
  box-shadow: var(--shadow);
  z-index: 500;
  animation: toastIn 0.25s ease;
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  color: white;
}
.toast.success { border-color: var(--success); color: #a7f3d0; }
.toast.error { border-color: var(--danger); color: #fecaca; }
@keyframes toastIn {
  from { opacity: 0; transform: translate(-50%, 20px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

/* ========== Responsive ========== */
@media (max-width: 900px) {
  .app-header { padding: 12px 16px; }
  .app-main { padding: 14px; padding-bottom: 20px; }
  .editors {
    grid-template-columns: 1fr;
    height: auto;
    max-height: none;
  }
  .editors textarea { min-height: 160px; height: 160px; }
  .pane-divider { width: 100%; height: 1px; }
  .brand-text p { display: none; }
  .toggle-group { gap: 10px; }
  .stats-bar { gap: 12px; padding: 10px 12px; }
  .stat-similarity, .stat-lines { margin-left: 0; }
  .diff-split { grid-template-columns: 1fr; }
  .diff-split-col.col-left { border-right: none; border-bottom: 1px solid var(--border); }
  .header-actions .btn span { display: none; }
  .diff-container { min-height: 240px; font-size: 12px; }
}
@media (max-width: 600px) {
  .brand-text h1 { font-size: 16px; }
  .logo { width: 38px; height: 38px; }
  .toolbar { padding: 10px; }
  .seg { padding: 6px 10px; font-size: 11px; }
  .chk { font-size: 11px; }
  .legend { gap: 10px; }
}
