/* ===== Variables (shadcn-inspired) ===== */
:root {
  --background: oklch(1 0 0);
  --foreground: rgb(36, 36, 36);
  --card: oklch(1 0 0);
  --card-foreground: oklch(0.145 0 0);
  --muted: oklch(0.965 0 0);
  --muted-foreground: oklch(0.45 0 0);
  --border: oklch(0.922 0 0);
  --input: oklch(0.922 0 0);
  --primary: oklch(0.208 0 0);
  --primary-foreground: oklch(0.985 0 0);
  --secondary: oklch(0.965 0 0);
  --secondary-foreground: rgb(36, 36, 36);
  --destructive: rgb(239, 67, 67);
  --destructive-foreground: oklch(0.985 0 0);
  --ring: oklch(0.208 0 0);
  --radius: 0.5rem;
  --radius-lg: 0.75rem;
  --font-sans: "Inter", ui-sans-serif, system-ui, sans-serif;
  --font-mono: "JetBrains Mono", "Fira Code", ui-monospace, monospace;
}

[data-theme="dark"] {
  --background: oklch(0.145 0 0);
  --foreground: oklch(0.985 0 0);
  --card: oklch(0.165 0 0);
  --card-foreground: oklch(0.985 0 0);
  --muted: oklch(0.269 0 0);
  --muted-foreground: oklch(0.708 0 0);
  --border: oklch(0.269 0 0);
  --input: oklch(0.269 0 0);
  --primary: oklch(0.985 0 0);
  --primary-foreground: oklch(0.208 0 0);
  --secondary: oklch(0.269 0 0);
  --secondary-foreground: oklch(0.985 0 0);
  --ring: oklch(0.708 0 0);
}

/* ===== Base ===== */
*, *::before, *::after { box-sizing: border-box; }
html { font-size: 16px; scroll-behavior: smooth; }
body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font-sans);
  background: var(--background);
  color: var(--foreground);
  line-height: 1.5;
}
code, .cm-editor { font-family: var(--font-mono); }

/* ===== App layout ===== */
.app {
  max-width: 65rem;
  margin: 0 auto;
  padding: 0.3rem 1.5rem 1.5rem 1.5rem;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ===== Header ===== */
.header {
  position: relative;
}
.logo {
  font-size: 1.5rem;
  font-weight: 300;
  letter-spacing: -0.025em;
  margin: 0 0 0.25rem 0;
}
.tagline {
  color: var(--muted-foreground);
  font-size: 0.875rem;
  margin: 0;
}
.theme-toggle {
  position: absolute;
  top: 0;
  right: 0;
  width: 2.25rem;
  height: 2.25rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--background);
  color: var(--foreground);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s, border-color 0.2s, transform 0.2s;
}
.theme-toggle:hover {
  background: var(--muted);
  border-color: var(--muted-foreground);
}
[data-theme="dark"] .theme-toggle {
  border-color: rgba(255, 255, 255, 0.35);
}
[data-theme="dark"] .theme-toggle:hover {
  border-color: rgba(255, 255, 255, 0.5);
}
.theme-icon { display: none; }
.theme-toggle .theme-icon .theme-toggle-svg {
  width: 1.25rem;
  height: 1.25rem;
  display: block;
  color: currentColor;
}
[data-theme="light"] .theme-icon.sun { display: inline-flex; }
[data-theme="dark"] .theme-icon.moon { display: inline-flex; }

/* ===== Main ===== */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

/* ===== Editor section ===== */
.editor-section {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--card);
  color: var(--card-foreground);
  overflow: hidden;
}
.editor-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  background: var(--muted);
}
.editor-toolbar .label {
  font-size: 0.875rem;
  font-weight: 300;
}
.editor-toolbar .label.valid { color: rgb(50, 216, 75); }
.editor-toolbar .label.invalid { color: var(--destructive); }
.buttons {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}
.btn {
  padding: 0.375rem 0.75rem;
  font-size: 0.875rem;
  font-weight: 300;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  cursor: pointer;
  font-family: inherit;
  transition: background 0.2s, color 0.2s, border-color 0.2s, transform 0.2s, filter 0.2s;
}
.btn-primary {
  background: var(--primary);
  color: var(--primary-foreground);
  border-color: var(--border);
}
.btn-primary:hover {
  filter: brightness(0.9);
  box-shadow: 0 2px 6px color-mix(in oklch, var(--primary) 35%, transparent);
}
.btn-secondary {
  background: var(--secondary);
  color: var(--secondary-foreground);
}
.btn-secondary:hover {
  background: var(--muted);
  border-color: var(--muted-foreground);
  color: var(--foreground);
}
.checkbox-label {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.875rem;
  color: var(--muted-foreground);
  cursor: pointer;
  user-select: none;
}
.checkbox {
  width: 1rem;
  height: 1rem;
  accent-color: var(--primary);
}
.editor-wrap {
  position: relative;
  height: 400px;
  overflow: hidden;
}
/* Textarea скрыт до инициализации CodeMirror: невидимые границы и прозрачный фон */
.editor-wrap textarea#editor {
  background: transparent;
  border: none;
  color: transparent;
  caret-color: transparent;
}
/* Copy button inside editor, top-right corner — прозрачный фон в обеих темах */
.editor-copy-btn {
  position: absolute;
  top: 0.5rem;
  right: 1.6rem;
  z-index: 10;
  width: 2rem;
  height: 2rem;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: transparent;
  color: var(--card-foreground);
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s, color 0.2s;
}
.editor-copy-btn:hover {
  background: rgba(0, 0, 0, 0.06);
  border-color: var(--muted-foreground);
}
.editor-copy-btn svg {
  width: 1rem;
  height: 1rem;
  flex-shrink: 0;
}
.editor-copy-btn .check-icon {
  display: none;
}
.editor-copy-btn.editor-copy-btn--copied .copy-icon {
  display: none;
}
.editor-copy-btn.editor-copy-btn--copied .check-icon {
  display: block;
  color: oklch(0.488 0.243 142.496);
}
/* Тёмная тема: светлые рамки, чтобы кнопка была видна на тёмном фоне */
[data-theme="dark"] .editor-copy-btn {
  background: transparent;
  border-color: rgba(255, 255, 255, 0.35);
  color: rgba(255, 255, 255, 0.9);
}
[data-theme="dark"] .editor-copy-btn:hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.5);
}
[data-theme="dark"] .editor-copy-btn.editor-copy-btn--copied .check-icon {
  color: #6ee7b7;
}
.editor-wrap .CodeMirror {
  height: 400px;
  font-size: 0.875rem;
  font-family: var(--font-mono);
  padding: 0;
}
[data-theme="dark"] .editor-wrap .CodeMirror.cm-s-default {
  background: #1a1d23;
  color: #e2e8f0;
}
[data-theme="dark"] .editor-wrap .CodeMirror.cm-s-default .CodeMirror-cursor {
  border-left-color: #e2e8f0;
}
/* Подсветка синтаксиса JSON для тёмной темы */
[data-theme="dark"] .editor-wrap .CodeMirror.cm-s-default .cm-keyword { color: #c792ea; }
[data-theme="dark"] .editor-wrap .CodeMirror.cm-s-default .cm-atom { color: #f78c6c; }
[data-theme="dark"] .editor-wrap .CodeMirror.cm-s-default .cm-number { color: #f78c6c; }
[data-theme="dark"] .editor-wrap .CodeMirror.cm-s-default .cm-string { color: #c3e88d; }
[data-theme="dark"] .editor-wrap .CodeMirror.cm-s-default .cm-string-2 { color: #89ddff; }
[data-theme="dark"] .editor-wrap .CodeMirror.cm-s-default .cm-property { color: #82aaff; }
[data-theme="dark"] .editor-wrap .CodeMirror.cm-s-default .cm-punctuation,
[data-theme="dark"] .editor-wrap .CodeMirror.cm-s-default .cm-operator { color: #89ddff; }
[data-theme="dark"] .editor-wrap .CodeMirror.cm-s-default .CodeMirror-linenumber { color: #546e7a; }
[data-theme="dark"] .editor-wrap .CodeMirror.cm-s-default .CodeMirror-gutters {
  background: #15181e;
  border-right-color: #2d323b;
}
[data-theme="dark"] .editor-wrap .CodeMirror.cm-s-default .CodeMirror-foldgutter-open,
[data-theme="dark"] .editor-wrap .CodeMirror.cm-s-default .CodeMirror-foldgutter-folded { color: #546e7a; }
/* Скроллбары только при переполнении, горизонтальный — у нижнего края редактора */
.editor-wrap .CodeMirror .CodeMirror-scroll {
  overflow-x: auto;
  overflow-y: auto;
}
.editor-wrap .CodeMirror.CodeMirror-fullscreen .CodeMirror-scroll {
  overflow: auto;
}
/* Blinking cursor as in a text editor */
@keyframes cm-cursor-blink {
  0%, 50% { opacity: 1; }
  51%, 100% { opacity: 0; }
}
.editor-wrap .CodeMirror-cursor {
  border-left-color: var(--foreground);
  animation: cm-cursor-blink 1s step-end infinite;
}
.editor-wrap .CodeMirror-gutters {
  background: var(--muted);
  border-right: 1px solid var(--border);
}
.editor-wrap .CodeMirror-linenumber { color: var(--muted-foreground); }
/* Fold gutter: buttons for collapsing objects/arrays */
.editor-wrap .CodeMirror-foldgutter {
  width: 1.2em;
}
.editor-wrap .CodeMirror-foldgutter-open,
.editor-wrap .CodeMirror-foldgutter-folded {
  cursor: pointer;
  color: var(--muted-foreground);
}
.editor-wrap .CodeMirror-foldgutter-open:hover,
.editor-wrap .CodeMirror-foldgutter-folded:hover {
  color: var(--foreground);
}
.editor-wrap .CodeMirror-guttermarker-subtle {
  color: var(--muted-foreground);
}
.editor-wrap .cm-error-line { background: color-mix(in oklch, var(--destructive) 15%, transparent); }

/* ===== Results section ===== */
.results-section {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--card);
  color: var(--card-foreground);
  overflow: hidden;
}
.results-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  background: var(--muted);
}
.results-header .label {
  font-size: 0.875rem;
  font-weight: 500;
}
.status {
  font-size: 0.8125rem;
  font-weight: 500;
}
.status.valid { color: oklch(0.488 0.243 142.496); }
.status.invalid { color: var(--destructive); }
.results-content {
  min-height: 120px;
  padding: 1rem;
  position: relative;
}
.results-placeholder {
  color: var(--muted-foreground);
  font-size: 0.875rem;
}
.results-output,
.results-error {
  margin: 0;
  font-size: 0.8125rem;
  font-family: var(--font-mono);
  white-space: pre-wrap;
  word-break: break-all;
}
.results-output { color: var(--foreground); }
.results-error { color: var(--destructive); }
.hidden { display: none !important; }

/* ===== Footer ===== */
/* ===== Intro (below editor) ===== */
.intro {
  margin-top: 1.5rem;
  color: var(--muted-foreground);
  font-size: 0.9375rem;
  line-height: 1.6;
}
.intro p {
  margin: 0 0 0.75rem 0;
}
.intro p:last-child {
  margin-bottom: 0;
}
.intro strong {
  color: var(--foreground);
  font-weight: 500;
}

.footer {
  margin-top: 1.5rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
  color: var(--muted-foreground);
  font-size: 0.75rem;
}
.footer code {
  padding: 0.125rem 0.375rem;
  border-radius: 0.25rem;
  background: var(--muted);
}
