/* ============================================
   JSON Compare — Dark Modern Theme
   ============================================ */

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

:root {
  /* Background layers */
  --bg-root: #0d1117;
  --bg-surface: #161b22;
  --bg-card: #1c2129;
  --bg-input: #0d1117;
  --bg-hover: #21262d;

  /* Borders */
  --border: #30363d;
  --border-light: #21262d;

  /* Text */
  --text-primary: #e6edf3;
  --text-secondary: #8b949e;
  --text-muted: #484f58;
  --text-link: #58a6ff;

  /* Accent */
  --accent: #58a6ff;
  --accent-emphasis: #1f6feb;

  /* Diff colors */
  --diff-added-bg: rgba(46, 160, 67, 0.15);
  --diff-added-border: #2ea043;
  --diff-added-text: #3fb950;
  --diff-removed-bg: rgba(248, 81, 73, 0.15);
  --diff-removed-border: #f85149;
  --diff-removed-text: #f85149;
  --diff-changed-bg: rgba(210, 153, 34, 0.15);
  --diff-changed-border: #d29922;
  --diff-changed-text: #e3b341;

  /* Radius & Spacing */
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;

  /* Font */
  --font-ui: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-mono:
    "JetBrains Mono", "Fira Code", "Cascadia Code", "Consolas", monospace;
}

html {
  font-size: 16px;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-ui);
  background: var(--bg-root);
  color: var(--text-primary);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ---------- Scrollbar ---------- */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}
::-webkit-scrollbar-track {
  background: var(--bg-surface);
}
::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* ---------- Header ---------- */
.logo {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo h1 {
  font-size: 1.125rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: #58a6ff;
  white-space: nowrap;
}

/* ---------- Toolbar ---------- */
.toolbar {
  border-bottom: 1px solid var(--border);
  padding: 12px 24px;
  position: sticky;
  top: 0;
  z-index: 100;
  backdrop-filter: blur(12px);
  background: rgba(22, 27, 34, 0.85);
}

.toolbar-divider {
  width: 1px;
  height: 20px;
  background: var(--border);
  margin: 0 4px;
}

.created-by {
  font-size: 0.75rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.toolbar-inner {
  max-width: 1400px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

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

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  font-family: var(--font-ui);
  font-size: 0.8125rem;
  font-weight: 500;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
  user-select: none;
}

.btn svg {
  flex-shrink: 0;
}

.btn-primary {
  background: var(--accent-emphasis);
  border-color: var(--accent-emphasis);
  color: #fff;
}
.btn-primary:hover {
  background: #388bfd;
  border-color: #388bfd;
  box-shadow: 0 0 12px rgba(56, 139, 253, 0.4);
}

.btn-secondary {
  background: var(--bg-card);
  color: var(--text-primary);
}
.btn-secondary:hover {
  background: var(--bg-hover);
  border-color: var(--text-muted);
}

.btn-edit {
  background: rgba(56, 139, 253, 0.12);
  border-color: rgba(56, 139, 253, 0.4);
  color: #58a6ff;
}
.btn-edit:hover {
  background: rgba(56, 139, 253, 0.22);
  border-color: rgba(56, 139, 253, 0.6);
  box-shadow: 0 0 10px rgba(56, 139, 253, 0.2);
}

.btn-accent {
  background: rgba(163, 113, 247, 0.15);
  border-color: rgba(163, 113, 247, 0.4);
  color: #a371f7;
}
.btn-accent:hover {
  background: rgba(163, 113, 247, 0.25);
  border-color: rgba(163, 113, 247, 0.6);
  box-shadow: 0 0 12px rgba(163, 113, 247, 0.25);
}

.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.15s ease;
}
.btn-icon:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
  border-color: var(--border);
}
.btn-icon.copied {
  color: var(--diff-added-text);
}

/* ---------- Editor Panels ---------- */
.editors {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1px;
  background: var(--border);
  max-width: 1400px;
  margin: 16px auto 24px;
  width: calc(100% - 48px);
  border-radius: var(--radius-lg);
  overflow: hidden;
  border: 1px solid var(--border);
}

.editor-panel {
  display: flex;
  flex-direction: column;
  background: var(--bg-surface);
  min-height: 400px;
}

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

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

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

.validation-badge {
  font-size: 0.75rem;
  font-weight: 500;
  padding: 2px 8px;
  border-radius: 999px;
  display: none;
  align-items: center;
  gap: 4px;
}
.validation-badge.valid {
  display: inline-flex;
  background: var(--diff-added-bg);
  color: var(--diff-added-text);
  border: 1px solid rgba(46, 160, 67, 0.3);
}
.validation-badge.invalid {
  display: inline-flex;
  background: var(--diff-removed-bg);
  color: var(--diff-removed-text);
  border: 1px solid rgba(248, 81, 73, 0.3);
}

.editor-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  position: relative;
}

.editor {
  flex: 1;
  padding: 16px;
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  line-height: 1.6;
  color: var(--text-primary);
  background: var(--bg-input);
  border: none;
  outline: none;
  resize: none;
  tab-size: 2;
  -moz-tab-size: 2;
  white-space: pre;
  overflow: auto;
}

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

.editor:focus {
  background: rgba(13, 17, 23, 0.8);
  box-shadow: inset 0 0 0 1px var(--accent-emphasis);
}

/* ---------- Parse Error Hint ---------- */
.parse-error {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(248, 81, 73, 0.1);
  border-top: 1px solid rgba(248, 81, 73, 0.4);
  padding: 7px 14px;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--diff-removed-text);
  display: flex;
  align-items: flex-start;
  gap: 8px;
  line-height: 1.5;
  z-index: 10;
}

.parse-error .pe-icon {
  flex-shrink: 0;
  margin-top: 1px;
}

.parse-error .pe-location {
  font-weight: 600;
  margin-right: 4px;
}

.parse-error .pe-msg {
  color: #ffb3ae;
  word-break: break-word;
}

/* ---------- Diff Summary Bar ---------- */
.diff-summary-bar {
  max-width: 1400px;
  margin: 16px auto 16px;
  width: calc(100% - 48px);
  padding: 10px 16px;
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-size: 0.8125rem;
  animation: fadeSlideUp 0.3s ease;
}

.diff-summary-bar .summary-label {
  color: var(--text-secondary);
  font-weight: 500;
}

.diff-summary-bar .summary-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  user-select: none;
}

.diff-summary-bar .summary-item input[type="checkbox"] {
  accent-color: var(--accent);
  cursor: pointer;
}

.diff-summary-bar .summary-count {
  font-weight: 600;
}

.diff-summary-bar .summary-count.removed {
  color: var(--diff-removed-text);
}

.diff-summary-bar .summary-count.added {
  color: var(--diff-added-text);
}

.diff-summary-bar .summary-count.changed {
  color: var(--diff-changed-text);
}

.diff-summary-bar .summary-count.equal {
  color: var(--accent);
}

/* ---------- Code View (inline diff) ---------- */
.code-view {
  flex: 1;
  overflow: auto;
  background: var(--bg-input);
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  line-height: 1.6;
}

.code-view table {
  border-collapse: collapse;
  width: 100%;
  min-width: max-content;
}

.code-line {
  transition: background 0.15s ease;
}

.code-line td {
  padding: 0;
  vertical-align: top;
  white-space: pre;
}

.code-line .line-num {
  width: 44px;
  min-width: 44px;
  text-align: right;
  padding-right: 12px;
  color: var(--text-muted);
  user-select: none;
  font-size: 0.75rem;
  border-right: 1px solid var(--border-light);
}

.code-line .line-code {
  padding-left: 12px;
  padding-right: 16px;
  color: var(--text-primary);
}

/* Highlight types */
.code-line.hl-removed {
  background: rgba(248, 81, 73, 0.12);
}

.code-line.hl-removed .line-num {
  background: rgba(248, 81, 73, 0.18);
  color: var(--diff-removed-text);
}

.code-line.hl-removed .line-code {
  color: var(--diff-removed-text);
}

.code-line.hl-added {
  background: rgba(63, 185, 80, 0.12);
}

.code-line.hl-added .line-num {
  background: rgba(63, 185, 80, 0.18);
  color: var(--diff-added-text);
}

.code-line.hl-added .line-code {
  color: var(--diff-added-text);
}

.code-line.hl-changed {
  background: rgba(210, 153, 34, 0.12);
}

.code-line.hl-changed .line-num {
  background: rgba(210, 153, 34, 0.18);
  color: var(--diff-changed-text);
}

.code-line.hl-changed .line-code {
  color: var(--diff-changed-text);
}

/* Hide highlight class when unchecked via summary toggle */
.code-line.hl-hidden {
  background: transparent;
}

.code-line.hl-hidden .line-num {
  background: transparent;
  color: var(--text-muted);
}

.code-line.hl-hidden .line-code {
  color: var(--text-primary);
}

/* ---------- Results ---------- */
.results-section {
  max-width: 1400px;
  margin: 0 auto 24px;
  width: calc(100% - 48px);
  animation: fadeSlideUp 0.4s ease;
}

@keyframes fadeSlideUp {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.results-inner {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.results-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-card);
  flex-wrap: wrap;
  gap: 12px;
}

.results-header h2 {
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--text-primary);
}

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

.summary-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
}

.summary-badge.added {
  background: var(--diff-added-bg);
  color: var(--diff-added-text);
  border: 1px solid rgba(46, 160, 67, 0.3);
}
.summary-badge.removed {
  background: var(--diff-removed-bg);
  color: var(--diff-removed-text);
  border: 1px solid rgba(248, 81, 73, 0.3);
}
.summary-badge.changed {
  background: var(--diff-changed-bg);
  color: var(--diff-changed-text);
  border: 1px solid rgba(210, 153, 34, 0.3);
}
.summary-badge.equal {
  background: rgba(88, 166, 255, 0.1);
  color: var(--accent);
  border: 1px solid rgba(88, 166, 255, 0.3);
}

.results-body {
  padding: 8px 0;
  max-height: 600px;
  overflow-y: auto;
}

/* ---------- Diff Items ---------- */
.diff-item {
  display: grid;
  grid-template-columns: auto 1fr auto auto;
  align-items: start;
  gap: 12px;
  padding: 10px 20px;
  border-bottom: 1px solid var(--border-light);
  transition: background 0.15s ease;
  font-size: 0.8125rem;
}

.diff-item:last-child {
  border-bottom: none;
}

.diff-item:hover {
  background: var(--bg-hover);
}

.diff-type-badge {
  padding: 2px 8px;
  border-radius: var(--radius-sm);
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  white-space: nowrap;
  min-width: 64px;
  text-align: center;
}

.diff-type-badge.added {
  background: var(--diff-added-bg);
  color: var(--diff-added-text);
}
.diff-type-badge.removed {
  background: var(--diff-removed-bg);
  color: var(--diff-removed-text);
}
.diff-type-badge.changed {
  background: var(--diff-changed-bg);
  color: var(--diff-changed-text);
}

.diff-path {
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  color: var(--text-link);
  word-break: break-all;
  padding-top: 2px;
}

.diff-value {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  max-width: 280px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding: 3px 8px;
  border-radius: var(--radius-sm);
  background: rgba(0, 0, 0, 0.2);
}

.diff-value.left {
  color: var(--diff-removed-text);
}

.diff-value.right {
  color: var(--diff-added-text);
}

.diff-value.only {
  color: var(--text-primary);
}

/* When there's no diff */
.no-diff {
  text-align: center;
  padding: 40px 20px;
  color: var(--diff-added-text);
}

.no-diff svg {
  margin-bottom: 12px;
}

.no-diff p {
  font-size: 0.9375rem;
  font-weight: 500;
}

.no-diff .sub {
  font-size: 0.8125rem;
  color: var(--text-secondary);
  margin-top: 4px;
}

/* Error message */
.error-message {
  text-align: center;
  padding: 40px 20px;
  color: var(--diff-removed-text);
}

.error-message p {
  font-size: 0.9375rem;
  font-weight: 500;
}

.error-message .detail {
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  color: var(--text-secondary);
  margin-top: 8px;
  background: rgba(248, 81, 73, 0.08);
  display: inline-block;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
}

/* ---------- Footer ---------- */
.footer {
  text-align: center;
  padding: 20px 24px;
  border-top: 1px solid var(--border-light);
  color: var(--text-muted);
  font-size: 0.75rem;
}

/* ---------- Responsive ---------- */
@media (max-width: 768px) {
  .header-inner {
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
  }

  .toolbar-inner {
    flex-direction: column;
    align-items: stretch;
  }

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

  .editors {
    grid-template-columns: 1fr;
    width: calc(100% - 32px);
    margin: 12px auto;
  }

  .editor-panel {
    min-height: 250px;
  }

  .results-section {
    width: calc(100% - 32px);
  }

  .diff-item {
    grid-template-columns: 1fr;
    gap: 6px;
    padding: 12px 16px;
  }

  .diff-value {
    max-width: 100%;
  }

  .results-header {
    flex-direction: column;
    align-items: flex-start;
  }
}

/* ---------- Toast notification ---------- */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-primary);
  padding: 10px 18px;
  border-radius: var(--radius-md);
  font-size: 0.8125rem;
  font-weight: 500;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  z-index: 1000;
  animation:
    toastIn 0.3s ease,
    toastOut 0.3s ease 1.7s forwards;
}

@keyframes toastIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes toastOut {
  from {
    opacity: 1;
    transform: translateY(0);
  }
  to {
    opacity: 0;
    transform: translateY(8px);
  }
}

/* ---------- Pulse animation for Compare button ---------- */
@keyframes pulse {
  0%,
  100% {
    box-shadow: 0 0 0 0 rgba(31, 111, 235, 0.5);
  }
  50% {
    box-shadow: 0 0 0 6px rgba(31, 111, 235, 0);
  }
}

.btn-primary.pulse {
  animation: pulse 1.5s ease infinite;
}
