:root {
  --bg: #f6f8fb;
  --panel-bg: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --border: #d1d5db;
  --primary: #2563eb;

  --json-key: #1d4ed8;
  --json-string: #047857;
  --json-number: #b45309;
  --json-boolean: #7e22ce;
  --json-null: #dc2626;
  --json-punctuation: #4b5563;

  --search-bg: #fde68a;
  --search-active-bg: #f59e0b;
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  font-family: Inter, system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.app {
  width: 100%;
  margin: 0;
  padding: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 0;
}

.app-header {
  padding: 0.75rem;
  border-bottom: 1px solid var(--border);
  background: var(--panel-bg);
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  max-height: 5rem;
  overflow: hidden;
  transition: max-height 0.25s ease, padding 0.25s ease, border-width 0.25s ease;
}

.app-header.collapsed {
  max-height: 0;
  padding-top: 0;
  padding-bottom: 0;
  border-bottom-width: 0;
}

.app-header h1 {
  margin: 0;
  font-size: 1.45rem;
  line-height: 1;
}

.app-header .app-logo {
  display: block;
  height: 2.25rem;
  width: auto;
  max-height: 44px;
}

.app-header p {
  margin: 0;
  color: var(--muted);
}

.app-header-link {
  margin-left: auto;
  font-size: 0.85rem;
  color: var(--muted);
  text-decoration: none;
  padding: 0.25rem 0.5rem;
  border-radius: 0.25rem;
  transition: color 0.15s ease, background-color 0.15s ease;
}

.app-header-link:hover,
.app-header-link:focus-visible {
  color: var(--primary);
  background-color: rgba(37, 99, 235, 0.08);
}

@media (max-width: 640px) {
  .app-tagline { display: none; }
  .app-header-link { font-size: 0.8rem; padding: 0.25rem 0.4rem; }
}

.panel {
  background: var(--panel-bg);
  border: none;
  border-radius: 0;
  padding: 0;
}

.editor-panel {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.sticky-toolbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--panel-bg);
  border-bottom: 1px solid var(--border);
  padding: 0.75rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}

.toolbar-actions {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}

.toolbar-search {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  flex: 1;
  min-width: 200px;
}

@media (max-width: 768px) {
  .sticky-toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .toolbar-actions {
    min-width: 0;
    max-width: 100%;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 0.25rem;
    margin: 0 -0.25rem 0 0;
    flex-wrap: nowrap;
  }

  .toolbar-actions::-webkit-scrollbar {
    height: 6px;
  }

  .toolbar-actions::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
  }

  .toolbar-search {
    min-width: 0;
    width: 100%;
  }

  #paste-btn .btn-label,
  #clear-btn .btn-label,
  #download-btn .btn-label,
  #load-json-btn .btn-label {
    display: none;
  }
}

button {
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 0.45rem 0.7rem;
  background: var(--primary);
  color: #fff;
  cursor: pointer;
}

button.secondary {
  background: #eef2ff;
  color: #1f2937;
  border-color: #c7d2fe;
}

#format-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}

#format-btn .btn-spinner {
  display: none;
  width: 14px;
  height: 14px;
  border: 2px solid rgba(255, 255, 255, 0.35);
  border-top-color: #fff;
  border-radius: 50%;
  animation: format-spin 0.6s linear infinite;
  flex-shrink: 0;
}

#format-btn.loading .btn-spinner {
  display: inline-block;
}

#format-btn.loading {
  opacity: 0.8;
  pointer-events: none;
}

@keyframes format-spin {
  to { transform: rotate(360deg); }
}

#unescape-btn {
  background: #fff7ed;
  color: #c2410c;
  border-color: #fdba74;
  transition: opacity 0.3s ease, transform 0.3s ease;
}

#unescape-btn:hover {
  background: #ffedd5;
  border-color: #fb923c;
}

#unescape-btn.fade-in {
  animation: unescape-pop 0.4s ease both;
}

@keyframes unescape-pop {
  from {
    opacity: 0;
    transform: translateY(-4px) scale(0.95);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

button:disabled,
button.secondary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

#paste-btn,
#clear-btn,
#download-btn,
#load-json-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.toolbar-actions button.icon-only {
  padding: 0.45rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

#paste-btn .icon-paste,
#clear-btn .icon-clear,
#download-btn .icon-download,
#load-json-btn .icon-load-json {
  flex-shrink: 0;
}

#search-input {
  flex: 1;
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.45rem 0.6rem;
}

.search-count {
  color: var(--muted);
  font-size: 0.85rem;
  display: none;
}

.search-count.active {
  display: inline;
}

.status-text {
  margin: 0.65rem 0 0.35rem;
  min-height: 1.2rem;
  color: var(--muted);
  font-size: 0.9rem;
}

.status-text.error {
  color: #b91c1c;
}

.status-text.warn {
  color: #9a3412;
}

.json-editor {
  margin: 0;
  padding: 0.8rem;
  border-radius: 0;
  border: none;
  background: transparent;
  flex: 1 1 auto;
  min-height: 0;
  height: 100%;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  overflow-x: hidden;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.88rem;
  line-height: 22px;
  outline: none;
  position: relative;
  z-index: 2;
}

.json-editor.structured-mode {
  white-space: pre-wrap;
  word-break: break-word;
  overflow-x: hidden;
}

.json-editor:empty::before {
  content: attr(data-placeholder);
  color: #9ca3af;
  pointer-events: none;
}

.editor-shell {
  flex: 1;
  min-height: 0;
  display: flex;
  background: #fbfdff;
  overflow: hidden;
}

.line-numbers {
  margin: 0;
  width: 48px;
  padding: 0.8rem 0.4rem 0.8rem 0;
  text-align: right;
  color: #9ca3af;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.88rem;
  line-height: 22px;
  user-select: none;
  overflow: auto;
  overscroll-behavior: none;
  background: #f8fafc;
  scrollbar-width: none;
  flex-shrink: 0;
}

.line-numbers::-webkit-scrollbar {
  width: 0;
  height: 0;
}

.ln-row {
  min-height: 22px;
  line-height: 22px;
  box-sizing: border-box;
}

.ln-row.ln-hidden {
  display: none;
}

.fold-gutter {
  margin: 0;
  width: 22px;
  padding: 0.8rem 0;
  border-right: 1px solid var(--border);
  font-size: 0.75rem;
  line-height: 22px;
  user-select: none;
  overflow: auto;
  overscroll-behavior: none;
  background: #f8fafc;
  scrollbar-width: none;
  flex-shrink: 0;
}

.fold-gutter::-webkit-scrollbar {
  width: 0;
  height: 0;
}

.fold-row {
  min-height: 22px;
  line-height: 22px;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 3px;
}

.fold-row.fold-hidden {
  display: none;
}

.fold-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  cursor: pointer;
  background: none;
  border: none;
  border-radius: 3px;
  padding: 0;
  font-size: 14px;
  color: #9ca3af;
  line-height: 1;
  transition: color 0.1s;
}

.fold-toggle:hover {
  color: #374151;
  background: #e5e7eb;
}

.editor-wrap {
  position: relative;
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

.active-line {
  position: absolute;
  left: 0;
  right: 0;
  height: 22px;
  background: #eef2f7;
  z-index: 1;
  pointer-events: none;
  display: none;
}

.json-key {
  color: var(--json-key);
}

.json-string {
  color: var(--json-string);
}

.json-number {
  color: var(--json-number);
}

.json-boolean {
  color: var(--json-boolean);
}

.json-null {
  color: var(--json-null);
}

.json-punctuation {
  color: var(--json-punctuation);
}

.json-search-hit {
  background: var(--search-bg);
  border-radius: 2px;
}

.json-search-hit.active {
  background: var(--search-active-bg);
}

.jline {
  min-height: 22px;
  line-height: 22px;
}

.jline.jline-hidden {
  display: none;
}

.collapsed-placeholder {
  color: #9ca3af;
  font-style: italic;
  cursor: pointer;
  margin-left: 2px;
}

.collapsed-placeholder:hover {
  color: #6b7280;
}

.bracket-match {
  outline: 2px solid #60a5fa;
  border-radius: 2px;
  background: rgba(96, 165, 250, 0.25);
}

/* Load JSON popup — modern */
.load-json-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(15, 23, 42, 0.5);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  animation: load-json-fade-in 0.2s ease;
}

@keyframes load-json-fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

.load-json-overlay[hidden] {
  display: none;
}

.load-json-modal {
  position: relative;
  background: var(--panel-bg);
  border-radius: 16px;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25), 0 0 0 1px rgba(0, 0, 0, 0.05);
  max-width: 440px;
  width: 100%;
  overflow: hidden;
  animation: load-json-scale-in 0.25s ease;
}

.load-json-loader {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.65rem;
  background: rgba(255, 255, 255, 0.88);
  backdrop-filter: blur(1px);
  -webkit-backdrop-filter: blur(1px);
}

.load-json-loader[hidden] {
  display: none;
}

.load-json-spinner {
  width: 28px;
  height: 28px;
  border: 3px solid #dbeafe;
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: load-json-spin 0.8s linear infinite;
}

@keyframes load-json-spin {
  to {
    transform: rotate(360deg);
  }
}

.load-json-loader p {
  margin: 0;
  color: #334155;
  font-size: 0.9rem;
  font-weight: 500;
}

@keyframes load-json-scale-in {
  from {
    opacity: 0;
    transform: scale(0.96);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

.load-json-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.25rem 1.5rem;
  background: linear-gradient(to bottom, rgba(248, 250, 252, 0.9), var(--panel-bg));
  border-bottom: 1px solid var(--border);
}

.load-json-modal-header h2 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--text);
}

.load-json-close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  background: none;
  border: none;
  border-radius: 10px;
  color: var(--muted);
  cursor: pointer;
  transition: color 0.15s ease, background 0.15s ease;
}

.load-json-close:hover {
  color: var(--text);
  background: rgba(0, 0, 0, 0.06);
}

.load-json-close:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px var(--primary);
}

.load-json-modal-body {
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0;
}

.load-json-section {
  margin: 0;
}

.load-json-section-title {
  margin: 0 0 0.75rem;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.load-json-url-row {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.load-json-url-row input {
  flex: 1;
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.6rem 0.85rem;
  font-size: 0.9375rem;
  background: var(--panel-bg);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.load-json-url-row input::placeholder {
  color: var(--muted);
}

.load-json-url-row input:hover {
  border-color: #94a3b8;
}

.load-json-url-row input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.load-json-btn-primary {
  flex-shrink: 0;
  padding: 0.6rem 1rem;
  border-radius: 10px;
  font-weight: 500;
  font-size: 0.9375rem;
  background: var(--primary);
  color: #fff;
  border: none;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.1s ease;
}

.load-json-btn-primary:hover {
  background: #1d4ed8;
}

.load-json-btn-primary:active {
  transform: scale(0.98);
}

.load-json-error {
  margin: 0;
  font-size: 0.8125rem;
  color: #dc2626;
  min-height: 1.25rem;
}

.load-json-divider {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin: 1.25rem 0;
}

.load-json-divider::before,
.load-json-divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border);
}

.load-json-divider span {
  font-size: 0.8125rem;
  color: var(--muted);
  font-weight: 500;
}

.load-json-drop-zone {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 120px;
  padding: 1.25rem;
  border: 2px dashed var(--border);
  border-radius: 12px;
  background: rgba(248, 250, 252, 0.6);
  cursor: pointer;
  transition: border-color 0.2s ease, background 0.2s ease;
}

.load-json-drop-zone.is-disabled {
  opacity: 0.6;
  pointer-events: none;
}

.load-json-drop-zone:hover {
  border-color: #94a3b8;
  background: rgba(241, 245, 249, 0.8);
}

.load-json-drop-zone.is-dragover {
  border-color: var(--primary);
  background: rgba(37, 99, 235, 0.06);
}

.load-json-drop-zone input[type="file"] {
  position: absolute;
  width: 0;
  height: 0;
  opacity: 0;
  pointer-events: none;
}

.load-json-drop-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  text-align: center;
}

.load-json-drop-icon {
  color: var(--muted);
  transition: color 0.2s ease;
}

.load-json-drop-zone:hover .load-json-drop-icon,
.load-json-drop-zone.is-dragover .load-json-drop-icon {
  color: var(--primary);
}

.load-json-drop-text {
  margin: 0;
  font-size: 0.9375rem;
  color: var(--text);
}

.load-json-drop-browse {
  color: var(--primary);
  font-weight: 500;
  text-decoration: underline;
  text-underline-offset: 2px;
}

/* Top-right toast status */
.toast-status {
  position: fixed;
  top: 14px;
  right: 14px;
  z-index: 1200;
  max-width: min(90vw, 380px);
  padding: 0.75rem 0.9rem;
  border-radius: 10px;
  border: 1px solid #dbeafe;
  background: #eff6ff;
  color: #1e3a8a;
  font-size: 0.88rem;
  line-height: 1.3;
  box-shadow: 0 12px 28px rgba(15, 23, 42, 0.18);
  transform: translateY(-8px);
  opacity: 0;
  pointer-events: none;
  transition: transform 0.2s ease, opacity 0.2s ease;
}

.toast-status.visible {
  transform: translateY(0);
  opacity: 1;
}

.toast-status.warn {
  border-color: #fed7aa;
  background: #fff7ed;
  color: #9a3412;
}

.toast-status.error {
  border-color: #fecaca;
  background: #fef2f2;
  color: #b91c1c;
}
