/* Theme variables */
:root {
  --bg: #fafafa;
  --bg-card: #ffffff;
  --bg-editor: #f8f9fa;
  --text: #1a1a2e;
  --text-muted: #666;
  --border: #e0e0e0;
  --accent: #2891b8;
  --accent-hover: #237a9c;
  --accent-gold: #b59135;
  --success: #28a745;
  --error: #dc3545;
  --warning: #ffc107;
  --code-bg: #f4f4f4;

  /* Typography */
  --font-sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: "SF Mono", "Monaco", "Inconsolata", "Fira Code", monospace;

  /* Transitions */
  --transition-fast: 0.15s ease;
  --transition-normal: 0.2s ease;

  /* Border radius */
  --radius-sm: 3px;
  --radius-md: 4px;
  --radius-lg: 6px;
  --radius-xl: 8px;
}

[data-theme="dark"] {
  --bg: #0d1117;
  --bg-card: #161b22;
  --bg-editor: #1c2128;
  --text: #c9d1d9;
  --text-muted: #8b949e;
  --border: #30363d;
  --accent: #4db8db;
  --accent-hover: #3da8cb;
  --accent-gold: #d4a940;
  --success: #3fb950;
  --error: #f85149;
  --warning: #d29922;
  --code-bg: #1f2428;
}

/* Base */
* { box-sizing: border-box; }

body {
  font-family: var(--font-sans);
  line-height: 1.6;
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

/* Layout */
.app-container {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Header */
.site-header {
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  padding: 1rem 2rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.site-header h1 {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 600;
  padding-bottom: 0.25rem;
  border-bottom: 2px solid transparent;
  border-image: linear-gradient(90deg, var(--accent), var(--accent-gold)) 1;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 1rem;
}

/* Mode Toggle */
.mode-toggle {
  display: flex;
  gap: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.mode-toggle button {
  background: var(--bg);
  border: none;
  padding: 0.5rem 1rem;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 0.875rem;
  transition: all var(--transition-normal);
}

.mode-toggle button:hover {
  background: var(--bg-card);
}

.mode-toggle button.active {
  background: var(--accent);
  color: white;
}

/* Theme Toggle */
.theme-toggle {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 0.25rem 0.5rem;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1rem;
}

.theme-toggle:hover {
  border-color: var(--accent);
}

/* Sidebar Toggle */
.sidebar-toggle {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 0.25rem 0.5rem;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1rem;
  display: flex;
  align-items: center;
}

.sidebar-toggle:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.sidebar-toggle.collapsed {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

/* Main Layout - 2 columns by default */
.main-content {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1px;
  background: var(--border);
  min-height: 0;
}

/* With sidebar (local mode) - 3 columns */
.main-content.with-sidebar {
  grid-template-columns: 1fr 1fr 280px;
}

@media (max-width: 1024px) {
  .main-content {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto auto;
  }
}

/* Panels */
.panel {
  background: var(--bg-card);
  padding: 1rem;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
  flex-shrink: 0;
}

.panel-header h2 {
  margin: 0;
  font-size: 0.875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

.panel-content {
  flex: 1;
  min-height: 0;
  overflow: auto;
}

/* Data Panel (left side) */
.data-panel {
  display: flex;
  flex-direction: column;
}

.data-panel .panel-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.data-panel .editor-section {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.data-panel .remote-sections {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.data-panel .url-section {
  flex: 0 0 auto;
}

.data-panel .schema-section {
  flex: 1;
  min-height: 0;
}

/* Pattern + Results Panel (right side, stacked) */
.pattern-results-panel {
  display: flex;
  flex-direction: column;
  gap: 1px;
  background: var(--border);
  padding: 0;
  overflow: visible; /* Allow autocomplete dropdown to overflow */
}

.pattern-results-panel .pattern-section,
.pattern-results-panel .results-section {
  background: var(--bg-card);
  padding: 1rem;
  display: flex;
  flex-direction: column;
}

.pattern-results-panel .pattern-section {
  flex: 0 0 auto;
  min-height: 160px;
  max-height: 40%;
  overflow: visible; /* Allow autocomplete dropdown to overflow */
}

.pattern-results-panel .results-section {
  flex: 1;
  min-height: 0;
  overflow: auto;
}

.pattern-results-panel .section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.5rem;
  flex-shrink: 0;
}

.pattern-results-panel .section-header label {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

.pattern-results-panel .pattern-editor {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: visible; /* Allow autocomplete dropdown to overflow */
}

.pattern-results-panel .results-content {
  flex: 1;
  overflow: auto;
  font-family: var(--font-mono);
  font-size: 0.875rem;
}

/* Execute button in pattern section */
.pattern-results-panel .execute-btn {
  margin-top: 0;
  padding: 0.5rem 1rem;
  font-size: 0.75rem;
}

/* Editor Panel (deprecated, keeping for compatibility) */
.editor-panel {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

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

.editor-section label {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
}

.editor-section textarea {
  flex: 1;
  min-height: 120px;
  padding: 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--bg-editor);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 0.875rem;
  line-height: 1.5;
  resize: none;
}

.editor-section textarea:focus {
  outline: none;
  border-color: var(--accent);
}

.editor-section input[type="text"] {
  padding: 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--bg-editor);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 0.875rem;
}

.editor-section input[type="text"]:focus {
  outline: none;
  border-color: var(--accent);
}

/* Execute Button */
.execute-btn {
  background: var(--accent);
  color: white;
  border: none;
  padding: 0.75rem 1.5rem;
  border-radius: var(--radius-lg);
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition-normal);
  margin-top: 0.5rem;
}

.execute-btn:hover {
  background: var(--accent-hover);
}

.execute-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Results Panel */
.results-panel .panel-content {
  font-family: var(--font-mono);
  font-size: 0.875rem;
}

.result-section {
  margin-bottom: 1.5rem;
}

.result-section h3 {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin: 0 0 0.5rem 0;
}

.result-value {
  background: var(--code-bg);
  padding: 0.75rem;
  border-radius: var(--radius-lg);
  white-space: pre-wrap;
  word-break: break-word;
  overflow-x: auto;
}

.result-value.success {
  border-left: 3px solid var(--success);
}

.result-value.error {
  border-left: 3px solid var(--error);
  color: var(--error);
}

.result-value.empty {
  color: var(--text-muted);
  font-style: italic;
}

/* Loading indicator */
.loading {
  color: var(--text-muted);
  font-style: italic;
}

/* Examples Panel */
.examples-panel {
  border-left: 1px solid var(--border);
}

.example-list {
  list-style: none;
  padding: 0;
  margin: 0 0 1.5rem 0;
}

.example-list li {
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius-md);
  cursor: pointer;
  font-size: 0.875rem;
  transition: background var(--transition-normal);
}

.example-list li:hover {
  background: var(--bg);
}

.example-list li.active {
  background: var(--accent);
  color: white;
}

/* Syntax Reference */
.syntax-reference {
  margin-top: auto;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

.syntax-reference h3 {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin: 0 0 0.75rem 0;
}

.syntax-list {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  line-height: 1.8;
}

.syntax-item {
  display: flex;
  gap: 0.75rem;
}

.syntax-item code {
  color: var(--accent);
  min-width: 50px;
}

.syntax-item span {
  color: var(--text-muted);
}

/* Remote Mode Sections */
.remote-sections {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

/* Info hint icon with tooltip */
.info-hint {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1rem;
  height: 1rem;
  margin-left: 0.375rem;
  border-radius: 50%;
  border: 1.5px solid var(--warning);
  color: var(--warning);
  font-size: 0.625rem;
  font-weight: 600;
  font-style: normal;
  font-family: var(--font-sans);
  text-transform: none;
  cursor: help;
  position: relative;
  vertical-align: middle;
}

.info-hint:hover::after {
  content: attr(data-tooltip);
  position: absolute;
  top: calc(100% + 0.5rem);
  left: 0;
  width: 260px;
  padding: 0.5rem 0.75rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  color: var(--text);
  font-size: 0.8125rem;
  font-weight: 400;
  font-style: normal;
  line-height: 1.5;
  text-transform: none;
  letter-spacing: normal;
  white-space: normal;
  z-index: 100;
}

[data-theme="dark"] .info-hint:hover::after {
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

/* Schema Section (Remote mode) */
.schema-section {
  display: flex;
  flex-direction: column;
  min-height: 0;
  flex: 1;
}

.schema-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.5rem;
}

.schema-header label {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

.fetch-schema-btn {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 0.25rem 0.5rem;
  font-size: 0.75rem;
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--transition-normal);
}

.fetch-schema-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.fetch-schema-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.schema-content {
  flex: 1;
  min-height: 100px;
  max-height: 200px;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--bg-editor);
}

/* In remote mode (no sidebar), allow schema to use full height */
.main-content:not(.with-sidebar) .schema-content {
  max-height: none;
}

.schema-value {
  margin: 0;
  padding: 0.75rem;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--text);
}

.schema-empty {
  padding: 0.75rem;
  color: var(--text-muted);
  font-style: italic;
  font-size: 0.875rem;
}

.schema-error {
  padding: 0.75rem;
  color: var(--error);
  font-size: 0.875rem;
}

/* Dark mode icons */
.show-light { display: inline; }
.show-dark { display: none; }
[data-theme="dark"] .show-light { display: none; }
[data-theme="dark"] .show-dark { display: inline; }

/*=============================================================================
 * EDN Editor Component
 *============================================================================*/

/* Editor container - overlay textarea with highlighting */
.edn-editor {
  position: relative;
  flex: 1;
  min-height: 120px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--bg-editor);
  overflow: hidden;
}

.edn-editor:focus-within {
  border-color: var(--accent);
}

/* Hidden textarea for input - text is transparent, overlay shows through */
.edn-editor-input {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  padding: 0.75rem;
  margin: 0;
  border: none;
  background: none !important;
  background-color: transparent !important;
  color: transparent;
  -webkit-text-fill-color: transparent;
  caret-color: var(--text);
  font-family: var(--font-mono);
  font-size: 0.875rem;
  line-height: 1.5;
  resize: none;
  z-index: 1;
  white-space: pre-wrap;
  word-wrap: break-word;
  overflow: auto;
}

.edn-editor-input:focus {
  outline: none;
}

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

/* Syntax highlighting overlay */
.edn-editor-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  padding: 0.75rem;
  pointer-events: none;
  z-index: 2;
  overflow: auto;
}

/* When hoverable, allow keyword tokens to receive hover events */
.edn-editor-overlay.hoverable .token-keyword {
  pointer-events: auto;
  cursor: help;
  border-radius: 2px;
  transition: background-color var(--transition-fast);
}

.edn-editor-overlay.hoverable .token-keyword:hover {
  background-color: var(--accent);
  color: white;
}

.edn-editor-code {
  margin: 0;
  font-family: var(--font-mono);
  font-size: 0.875rem;
  line-height: 1.5;
  white-space: pre-wrap;
  word-wrap: break-word;
  color: var(--text);
}

/* Placeholder in overlay */
.edn-placeholder {
  color: var(--text-muted);
  font-style: italic;
}

/*=============================================================================
 * Syntax Highlighting Tokens
 *============================================================================*/

.token-keyword {
  color: #0550ae;
}

.token-string {
  color: #0a3069;
}

.token-number {
  color: #0550ae;
}

.token-literal {
  color: #cf222e;
}

.token-comment {
  color: #6e7781;
  font-style: italic;
}

.token-symbol {
  color: var(--text);
}

.token-variable {
  color: #8250df;
  font-weight: 500;
}

/* Dark mode token colors */
[data-theme="dark"] .token-keyword {
  color: #79c0ff;
}

[data-theme="dark"] .token-string {
  color: #a5d6ff;
}

[data-theme="dark"] .token-number {
  color: #79c0ff;
}

[data-theme="dark"] .token-literal {
  color: #ff7b72;
}

[data-theme="dark"] .token-comment {
  color: #8b949e;
}

[data-theme="dark"] .token-variable {
  color: #d2a8ff;
}

/*=============================================================================
 * Rainbow Parentheses
 *============================================================================*/

.token-paren {
  font-weight: 500;
}

/* Light mode rainbow colors */
.rainbow-1 { color: #e91e63; }  /* Pink */
.rainbow-2 { color: #9c27b0; }  /* Purple */
.rainbow-3 { color: #2196f3; }  /* Blue */
.rainbow-4 { color: #009688; }  /* Teal */
.rainbow-5 { color: #ff9800; }  /* Orange */
.rainbow-6 { color: #795548; }  /* Brown */

/* Dark mode rainbow colors - brighter for visibility */
[data-theme="dark"] .rainbow-1 { color: #f48fb1; }  /* Light Pink */
[data-theme="dark"] .rainbow-2 { color: #ce93d8; }  /* Light Purple */
[data-theme="dark"] .rainbow-3 { color: #90caf9; }  /* Light Blue */
[data-theme="dark"] .rainbow-4 { color: #80cbc4; }  /* Light Teal */
[data-theme="dark"] .rainbow-5 { color: #ffcc80; }  /* Light Orange */
[data-theme="dark"] .rainbow-6 { color: #bcaaa4; }  /* Light Brown */

/*=============================================================================
 * Schema Viewer (read-only display)
 *============================================================================*/

.schema-viewer {
  flex: 1;
  min-height: 100px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--bg-editor);
  overflow: auto;
}

.schema-viewer .schema-code {
  margin: 0;
  padding: 0.75rem;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  line-height: 1.5;
  white-space: pre-wrap;
  word-wrap: break-word;
}

.schema-viewer .schema-loading,
.schema-viewer .schema-empty,
.schema-viewer .schema-error {
  padding: 0.75rem;
  font-size: 0.875rem;
}

.schema-viewer .schema-loading,
.schema-viewer .schema-empty {
  color: var(--text-muted);
  font-style: italic;
}

.schema-viewer .schema-error {
  color: var(--error);
}

/* Schema tokens are hoverable */
.schema-viewer .token-keyword {
  cursor: help;
  border-radius: 2px;
  transition: background-color var(--transition-fast);
}

.schema-viewer .token-keyword:hover {
  background-color: var(--accent);
  color: white;
}

[data-theme="dark"] .schema-viewer .token-keyword:hover {
  background-color: var(--accent);
}

/*=============================================================================
 * Schema Tooltip
 *============================================================================*/

.schema-tooltip {
  position: fixed;
  z-index: 1000;
  max-width: 320px;
  padding: 0.75rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  font-size: 0.8125rem;
  line-height: 1.5;
}

[data-theme="dark"] .schema-tooltip {
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

.tooltip-header {
  font-family: var(--font-mono);
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 0.25rem;
}

.tooltip-type {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
}

.tooltip-doc {
  color: var(--text);
  margin-bottom: 0.5rem;
}

.tooltip-example {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: 0.25rem;
}

.tooltip-example code {
  background: var(--code-bg);
  padding: 0.125rem 0.25rem;
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
}

.tooltip-deprecated {
  color: var(--warning);
  font-size: 0.75rem;
  margin-top: 0.5rem;
  padding: 0.25rem 0.5rem;
  background: rgba(255, 193, 7, 0.1);
  border-radius: var(--radius-md);
}

.tooltip-since {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.tooltip-label {
  font-weight: 500;
}

/*=============================================================================
 * Autocomplete Dropdown
 *============================================================================*/

.autocomplete-dropdown {
  position: fixed;
  z-index: 1000;
  min-width: 150px;
  max-width: 300px;
  max-height: 200px;
  overflow-y: auto;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  font-family: var(--font-mono);
  font-size: 0.8125rem;
}

[data-theme="dark"] .autocomplete-dropdown {
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

.autocomplete-item {
  padding: 0.5rem 0.75rem;
  cursor: pointer;
  color: var(--accent);
  transition: background-color var(--transition-fast);
}

.autocomplete-item:hover,
.autocomplete-item.selected {
  background: var(--bg);
}

.autocomplete-item.selected {
  background: var(--accent);
  color: white;
}

/*=============================================================================
 * EDN Display (read-only, non-editable)
 *============================================================================*/

.edn-display {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--code-bg);
  overflow: auto;
}

.edn-display .edn-code {
  margin: 0;
  padding: 0.75rem;
  font-family: var(--font-mono);
  font-size: 0.875rem;
  line-height: 1.5;
  white-space: pre-wrap;
  word-wrap: break-word;
}

/*=============================================================================
 * Schema View Mode Toggle
 *============================================================================*/

.schema-view-toggle {
  display: flex;
  gap: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
  margin-bottom: 0.5rem;
  width: fit-content;
}

.schema-view-toggle button {
  background: var(--bg);
  border: none;
  padding: 0.25rem 0.5rem;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 0.6875rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  transition: all var(--transition-fast);
}

.schema-view-toggle button:hover {
  background: var(--bg-card);
}

.schema-view-toggle button.active {
  background: var(--accent);
  color: white;
}

/*=============================================================================
 * Sandbox Mode
 *============================================================================*/

.sandbox-data-section {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.sandbox-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.5rem;
  flex-shrink: 0;
}

.data-view-toggle {
  display: flex;
  gap: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.data-view-toggle button {
  background: var(--bg);
  border: none;
  padding: 0.25rem 0.5rem;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 0.6875rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  transition: all var(--transition-fast);
}

.data-view-toggle button:hover {
  background: var(--bg-card);
}

.data-view-toggle button.active {
  background: var(--accent);
  color: white;
}

.reset-btn {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 0.25rem 0.5rem;
  font-size: 0.75rem;
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--transition-normal);
}

.reset-btn:hover {
  border-color: var(--error);
  color: var(--error);
}

.sandbox-content {
  overflow: auto;
}

