/* ================================
   Diff Tool — Custom Styles
   ================================ */

:root {
  --bg: #FAFAF9;
  --bg-alt: #F5F5F4;
  --surface: #FFFFFF;
  --border: #E7E5E4;
  --border-strong: #D6D3D1;
  --text: #1E293B;
  --text-secondary: #52525B;
  --text-muted: #71717A;
  --primary: #4F46E5;
  --primary-hover: #4338CA;
  --primary-light: rgba(79, 70, 229, 0.08);
  --secondary: #F97316;
  --accent: #EC4899;
  --success: #059669;
  --radius: 10px;
  --radius-lg: 14px;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow: 0 4px 12px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.08);
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html { scroll-behavior: smooth; }

body {
  font-family: 'Inter', 'Noto Sans SC', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* ── Page ── */
.page {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 32px;
}

/* ── Toast ── */
.toast {
  position: fixed;
  top: 24px;
  right: 24px;
  background: var(--text);
  color: var(--bg);
  padding: 12px 20px;
  border-radius: 100px;
  font-size: 14px;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 8px;
  z-index: 1000;
  transform: translateX(calc(100% + 40px));
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.toast.show { transform: translateX(0); }
.toast-dot {
  width: 8px; height: 8px;
  background: var(--success);
  border-radius: 50%;
}

/* ================================
   Toolbar
   ================================ */
.toolbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px 0;
  flex-wrap: wrap;
}

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

.toolbar-group--center {
  flex: 1;
  justify-content: center;
}

.toolbar-group--right {
  margin-left: auto;
}

/* View toggle */
.view-toggle {
  display: flex;
  background: var(--bg-alt);
  border-radius: 10px;
  padding: 3px;
}

.view-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border: none;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  background: transparent;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}
.view-btn:hover { color: var(--text); }
.view-btn.active {
  background: #fff;
  color: #4F46E5;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

/* Toolbar buttons */
.tb-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 7px 14px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: #fff;
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}
.tb-btn:hover {
  color: #4F46E5;
  border-color: #4F46E5;
  background: var(--primary-light);
}

/* Diff stat */
.diff-stat {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* ================================
   Diff Nav
   ================================ */
.diff-nav {
  display: flex;
  align-items: center;
  gap: 2px;
  background: var(--bg-alt);
  border-radius: 8px;
  padding: 2px;
}

.nav-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.2s;
}
.nav-btn:hover:not(:disabled) {
  background: #fff;
  color: #4F46E5;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}
.nav-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.nav-info {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  padding: 0 4px;
  user-select: none;
  min-width: 32px;
  text-align: center;
}

/* ================================
   Collapse bar
   ================================ */
.collapse-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 4px 0;
  background: var(--bg-alt);
  border-top: 1px solid var(--border-strong);
  border-bottom: 1px solid var(--border-strong);
  cursor: pointer;
  user-select: none;
  transition: background 0.15s;
}
.collapse-bar:hover {
  background: var(--bg-alt);
}
.collapse-bar-line {
  flex: 1;
  height: 1px;
  background: #d8dce8;
  max-width: 60px;
}
.collapse-bar-text {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
}

/* ================================
   Diff line highlight animation
   ================================ */
.diff-line.diff-nav-highlight,
.unified-line.diff-nav-highlight {
  outline: 2px solid #4F46E5;
  outline-offset: -2px;
  z-index: 1;
  position: relative;
}

/* ================================
   Collapse toggle button active state
   ================================ */
.tb-btn.active {
  color: #4F46E5;
  border-color: #4F46E5;
  background: var(--primary-light);
}

/* ================================
   Main Content Area
   ================================ */
.main-content {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-bottom: 40px;
  min-height: 500px;
}

/* When unified view is active, hide side panels */
.main-content.unified-view {
  grid-template-columns: 1fr;
}

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

@media (max-width: 800px) {
  .input-row {
    grid-template-columns: 1fr;
  }
}

/* ================================
   View Bar (between input and diff)
   ================================ */
.view-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0;
  margin-bottom: 20px;
}

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

/* ================================
   Diff Panel (one side)
   ================================ */
.diff-panel {
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06), 0 4px 16px rgba(0, 0, 0, 0.04);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.input-row .diff-panel {
  height: auto;
}

.main-content .diff-panel {
  height: calc(100vh - 380px);
}

.diff-panel--unified {
  border-radius: 16px;
  height: calc(100vh - 380px);
}

/* ================================
   Input Area
   ================================ */
.panel-input-area {
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}

.panel-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}

.panel-actions {
  display: flex;
  gap: 6px;
}

.action-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 6px 12px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: #fff;
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}
.action-btn:hover {
  color: #4F46E5;
  border-color: #4F46E5;
  background: var(--primary-light);
}

.diff-textarea {
  padding: 16px;
  border: none;
  outline: none;
  resize: none;
  font-family: 'JetBrains Mono', 'Fira Code', 'SF Mono', monospace;
  font-size: 13px;
  line-height: 1.65;
  color: var(--text);
  background: #fff;
  tab-size: 2;
  height: 300px;
  overflow-y: auto;
}
.diff-textarea::placeholder {
  color: #A1A1AA;
}

.panel-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 18px;
  border-top: 1px solid var(--border);
  background: var(--bg-alt);
}

.char-count {
  font-size: 12px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

/* ================================
   Diff Result (below textarea)
   ================================ */
.diff-result {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  font-family: 'JetBrains Mono', 'Fira Code', 'SF Mono', monospace;
  font-size: 13px;
  line-height: 1.65;
  border-top: 1px solid var(--border-strong);
  background: var(--bg-alt);
  min-height: 0;
}
.diff-result:empty {
  display: none;
}

/* Diff line */
.diff-line {
  display: flex;
  padding: 1px 0;
  min-height: 1.65em;
  border-bottom: 1px solid rgba(0, 0, 0, 0.04);
}

.diff-line-num {
  min-width: 44px;
  padding: 0 10px;
  text-align: right;
  color: var(--text-muted);
  font-size: 12px;
  user-select: none;
  flex-shrink: 0;
  background: var(--bg-alt);
  border-right: 1px solid var(--border);
}

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

.diff-line-add {
  background: var(--border);
}
.diff-line-add .diff-line-num {
  background: #E7E5E4;
  color: var(--text);
}
.diff-line-add .diff-line-content {
  background: var(--border);
}

.diff-line-del {
  background: #fef2f2;
}
.diff-line-del .diff-line-num {
  background: #fee2e2;
  color: #dc2626;
}
.diff-line-del .diff-line-content {
  background: #fef2f2;
}

.diff-line-mod {
  background: #fefce8;
}
.diff-line-mod .diff-line-num {
  background: #fef08a;
  color: #ca8a04;
}
.diff-line-mod .diff-line-content {
  background: #fefce8;
}

.diff-line-empty {
  background: var(--bg-alt);
}
.diff-line-empty .diff-line-num {
  background: var(--bg-alt);
}

/* ================================
   Unified Diff View
   ================================ */
.unified-line {
  display: flex;
  padding: 1px 0;
  min-height: 1.65em;
  border-bottom: 1px solid rgba(0, 0, 0, 0.04);
}

.unified-line-num {
  min-width: 88px;
  padding: 0 10px;
  text-align: right;
  color: var(--text-muted);
  font-size: 12px;
  user-select: none;
  flex-shrink: 0;
  background: var(--bg-alt);
  border-right: 1px solid var(--border);
  display: flex;
  gap: 4px;
  justify-content: flex-end;
}

.unified-line-num .old-num,
.unified-line-num .new-num {
  min-width: 28px;
  text-align: right;
}

.unified-line-marker {
  min-width: 20px;
  padding: 0 6px;
  text-align: center;
  font-weight: 700;
  font-size: 12px;
  user-select: none;
  flex-shrink: 0;
}

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

.unified-add {
  background: var(--border);
}
.unified-add .unified-line-num {
  background: #E7E5E4;
}
.unified-add .unified-line-marker {
  color: var(--text);
  background: #E7E5E4;
}
.unified-add .unified-line-content {
  background: var(--border);
}

.unified-del {
  background: #fef2f2;
}
.unified-del .unified-line-num {
  background: #fee2e2;
}
.unified-del .unified-line-marker {
  color: #dc2626;
  background: #fee2e2;
}
.unified-del .unified-line-content {
  background: #fef2f2;
}

.unified-mod {
  background: #fefce8;
}
.unified-mod .unified-line-num {
  background: #fef08a;
}
.unified-mod .unified-line-marker {
  color: #ca8a04;
  background: #fef08a;
}
.unified-mod .unified-line-content {
  background: #fefce8;
}

/* ================================
   Inline Diff Highlights
   ================================ */
.inline-add {
  background: #a7f3d0;
  color: #065f46;
  border-radius: 2px;
  padding: 0 1px;
}
.inline-del {
  background: #fecaca;
  color: #991b1b;
  border-radius: 2px;
  padding: 0 1px;
  text-decoration: line-through;
}

/* ================================
   Scrollbar
   ================================ */
::selection {
  background: rgba(79, 70, 229, 0.2);
  color: #1E293B;
}

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #A5B4FC; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #4F46E5; }

/* ================================
   Mobile menu
   ================================ */
#mobileMenu {
  transition: max-height 0.3s ease-out, opacity 0.3s ease-out;
  max-height: 0;
  overflow: hidden;
  opacity: 0;
}
#mobileMenu.open {
  max-height: 300px;
  opacity: 1;
}

/* ================================
   Responsive
   ================================ */
@media (max-width: 800px) {
  .main-content {
    grid-template-columns: 1fr;
  }
  .main-content.unified-view {
    grid-template-columns: 1fr;
  }
  .toolbar {
    gap: 10px;
  }
  .toolbar-group--center {
    order: 3;
    flex: 0 1 100%;
    justify-content: flex-start;
  }
}

/* ================================
   Hidden utility
   ================================ */
.hidden {
  display: none;
}

/* ================================
   Guide Section (accordion)
   ================================ */
.guide-section {
  margin-bottom: 24px;
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
}
.guide-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 14px 20px;
  background: none;
  border: none;
  cursor: pointer;
  transition: background 0.15s ease;
}
.guide-toggle:hover {
  background: var(--bg-alt);
}
.guide-toggle.open .toggle-arrow {
  transform: rotate(180deg);
}
.guide-toggle-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  font-weight: 600;
  color: #1E293B;
}
.toggle-arrow {
  transition: transform 0.2s ease;
  color: var(--text-muted);
}
.guide-list {
  padding: 0 20px 20px;
}
.guide-list.hidden {
  display: none;
}
.guide-item {
  padding: 16px 0;
  border-top: 1px solid var(--border);
}
.guide-item:first-child {
  border-top: 1px solid var(--border);
}
.guide-item-title {
  font-size: 14px;
  font-weight: 600;
  color: #1E293B;
  margin-bottom: 6px;
}
.guide-item-body {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.8;
}
.guide-item-body kbd {
  padding: 1px 6px;
  background: var(--bg-alt);
  border: 1px solid var(--border-strong);
  border-radius: 4px;
  font-family: 'SF Mono', 'Cascadia Code', monospace;
  font-size: 12px;
  color: var(--text-secondary);
}