/* ===== CSS Variables / Theme ===== */
:root,
[data-theme="light"] {
  --bg-primary: #ffffff;
  --bg-secondary: #f8f9fa;
  --bg-tertiary: #e9ecef;
  --text-primary: #1a1a2e;
  --text-secondary: #495057;
  --text-muted: #868e96;
  --border-color: #dee2e6;
  --border-focus: #4c6ef5;
  --accent: #4c6ef5;
  --accent-hover: #3b5bdb;
  --accent-light: #dbe4ff;

  --diff-added-bg: #d4edda;
  --diff-added-char: #a3d9a5;
  --diff-added-border: #28a745;
  --diff-removed-bg: #f8d7da;
  --diff-removed-char: #f1a9a0;
  --diff-removed-border: #dc3545;
  --diff-modified-bg: #fff3cd;
  --diff-gutter-bg: #f1f3f5;
  --diff-line-number: #868e96;

  --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.1);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.12);

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

  --transition: 0.2s ease;
}

[data-theme="dark"] {
  --bg-primary: #1a1b26;
  --bg-secondary: #24283b;
  --bg-tertiary: #2f3347;
  --text-primary: #c0caf5;
  --text-secondary: #a9b1d6;
  --text-muted: #565f89;
  --border-color: #3b4261;
  --border-focus: #7aa2f7;
  --accent: #7aa2f7;
  --accent-hover: #89b4fa;
  --accent-light: #292e42;

  --diff-added-bg: #1a2f23;
  --diff-added-char: #2d5a3a;
  --diff-added-border: #3fb950;
  --diff-removed-bg: #3b1a1f;
  --diff-removed-char: #6e2a2f;
  --diff-removed-border: #f85149;
  --diff-modified-bg: #3b3520;
  --diff-gutter-bg: #1e2030;
  --diff-line-number: #565f89;

  --shadow-sm: 0 1px 3px rgba(0,0,0,0.3);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.4);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.5);
}

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

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg-secondary);
  color: var(--text-primary);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  transition: background var(--transition), color var(--transition);
}

/* ===== Header ===== */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  background: var(--bg-primary);
  border-bottom: 1px solid var(--border-color);
  box-shadow: var(--shadow-sm);
  position: sticky;
  top: 0;
  z-index: 100;
  transition: background var(--transition), border-color var(--transition);
}

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

.logo-icon {
  color: var(--accent);
}

.header h1 {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

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

/* ===== Buttons ===== */
.btn-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background: var(--bg-secondary);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition);
}

.btn-icon:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
  border-color: var(--accent);
}

[data-theme="light"] .icon-moon { display: none; }
[data-theme="dark"] .icon-sun { display: none; }

/* ===== Main ===== */
.main {
  flex: 1;
  padding: 24px;
  max-width: 1600px;
  width: 100%;
  margin: 0 auto;
}

/* ===== Input Section ===== */
.input-section {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-bottom: 20px;
}

.input-panel {
  background: var(--bg-primary);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-color);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  transition: border-color var(--transition), box-shadow var(--transition);
}

.input-panel:focus-within {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--accent-light);
}

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

.panel-title {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

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

.lang-select {
  padding: 4px 8px;
  font-size: 0.8rem;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background: var(--bg-primary);
  color: var(--text-secondary);
  cursor: pointer;
  outline: none;
  transition: border-color var(--transition);
}

.lang-select:focus {
  border-color: var(--accent);
}

.btn-upload,
.btn-clear {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  font-size: 0.8rem;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background: var(--bg-primary);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
}

.btn-upload:hover,
.btn-clear:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

.file-input {
  display: none;
}

.textarea-wrapper {
  position: relative;
}

.textarea-wrapper textarea {
  width: 100%;
  min-height: 240px;
  max-height: 480px;
  padding: 16px;
  border: none;
  outline: none;
  resize: vertical;
  font-family: "Cascadia Code", "Fira Code", "JetBrains Mono", "SF Mono", Consolas, monospace;
  font-size: 0.875rem;
  line-height: 1.6;
  background: var(--bg-primary);
  color: var(--text-primary);
  transition: background var(--transition), color var(--transition);
}

.textarea-wrapper textarea::placeholder {
  color: var(--text-muted);
}

/* Drop overlay */
.drop-overlay {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: var(--accent-light);
  border: 2px dashed var(--accent);
  border-radius: var(--radius-md);
  color: var(--accent);
  font-size: 0.9rem;
  font-weight: 500;
  z-index: 10;
  pointer-events: none;
}

.textarea-wrapper.dragging .drop-overlay {
  display: flex;
}

/* ===== Toolbar ===== */
.toolbar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 20px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}

/* Stats */
.stats {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 8px 16px;
  background: var(--bg-primary);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-sm);
  transition: opacity 0.3s ease, transform 0.3s ease;
}

.stats.hidden {
  display: none;
}

.stats.fade-in {
  animation: fadeSlideIn 0.3s ease forwards;
}

.stat {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.85rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.stat-added { color: var(--diff-added-border); }
.stat-removed { color: var(--diff-removed-border); }
.stat-modified { color: #e67700; }

[data-theme="dark"] .stat-modified { color: #fab005; }

/* ===== Output Section ===== */
.output-section {
  transition: opacity 0.3s ease, transform 0.3s ease;
}

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

.output-section.fade-in {
  animation: fadeSlideIn 0.4s ease forwards;
}

.diff-container {
  display: grid;
  grid-template-columns: 1fr 4px 1fr;
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-md);
  max-height: 70vh;
}

.diff-panel {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.diff-header {
  padding: 10px 16px;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  position: sticky;
  top: 0;
  z-index: 5;
}

.diff-content {
  overflow: auto;
  font-family: "Cascadia Code", "Fira Code", "JetBrains Mono", "SF Mono", Consolas, monospace;
  font-size: 0.8125rem;
  line-height: 1.7;
  flex: 1;
}

.diff-gutter {
  background: var(--border-color);
}

/* Diff lines */
.diff-line {
  display: flex;
  min-height: 1.7em;
  border-bottom: 1px solid transparent;
}

.diff-line-number {
  min-width: 48px;
  padding: 0 8px;
  text-align: right;
  color: var(--diff-line-number);
  user-select: none;
  background: var(--diff-gutter-bg);
  border-right: 1px solid var(--border-color);
  flex-shrink: 0;
}

.diff-line-content {
  flex: 1;
  padding: 0 12px;
  white-space: pre-wrap;
  word-break: break-all;
  min-width: 0;
}

/* Line type styling */
.diff-line.added {
  background: var(--diff-added-bg);
}

.diff-line.added .diff-line-number {
  background: var(--diff-added-bg);
  color: var(--diff-added-border);
}

.diff-line.removed {
  background: var(--diff-removed-bg);
}

.diff-line.removed .diff-line-number {
  background: var(--diff-removed-bg);
  color: var(--diff-removed-border);
}

.diff-line.empty-placeholder {
  background: var(--bg-tertiary);
  opacity: 0.5;
}

.diff-line.empty-placeholder .diff-line-number {
  background: var(--bg-tertiary);
}

/* Character-level highlighting */
.char-added {
  background: var(--diff-added-char);
  border-radius: 2px;
  padding: 1px 0;
}

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

/* ===== Empty State ===== */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  color: var(--text-muted);
  text-align: center;
  gap: 16px;
}

.empty-state.hidden {
  display: none;
}

.empty-state p {
  font-size: 0.95rem;
  max-width: 400px;
  line-height: 1.6;
}

/* ===== Footer ===== */
.footer {
  padding: 16px 24px;
  text-align: center;
  font-size: 0.8rem;
  color: var(--text-muted);
  border-top: 1px solid var(--border-color);
  background: var(--bg-primary);
}

/* ===== Animations ===== */
@keyframes fadeSlideIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ===== Scrollbar ===== */
.diff-content::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

.diff-content::-webkit-scrollbar-track {
  background: var(--bg-secondary);
}

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

.diff-content::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* ===== Responsive ===== */
@media (max-width: 900px) {
  .main {
    padding: 16px;
  }

  .input-section {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .diff-container {
    grid-template-columns: 1fr;
    max-height: none;
  }

  .diff-gutter {
    height: 2px;
  }

  .diff-panel + .diff-gutter + .diff-panel .diff-content {
    max-height: 50vh;
  }

  .diff-panel:first-child .diff-content {
    max-height: 50vh;
  }

  .textarea-wrapper textarea {
    min-height: 160px;
  }

  .panel-header {
    flex-wrap: wrap;
    gap: 8px;
  }

  .panel-actions {
    flex-wrap: wrap;
  }
}

@media (max-width: 480px) {
  .header {
    padding: 12px 16px;
  }

  .header h1 {
    font-size: 1.1rem;
  }

  .btn-compare {
    padding: 10px 24px;
    font-size: 0.9rem;
  }

  .stats {
    gap: 10px;
    padding: 6px 12px;
  }

  .stat {
    font-size: 0.8rem;
  }
}
