/* ============================================
   JSON Formatter - VS Code Style
   ============================================ */

:root {
  --code-font: 'Cascadia Code', 'Fira Code', 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  --code-lh: 1.5;
  
  /* Light theme */
  --editor-bg: #ffffff;
  --editor-gutter-bg: #f5f5f5;
  --editor-border: #e0e0e0;
  --editor-text: #24292f;
  --editor-line-number: #6e7781;
  --editor-selection: #0969da1a;
  --editor-error-bg: #ffebee;
  --editor-error-border: #d32f2f;
  --editor-error-text: #c62828;
  --editor-success: #28a745;
  --toolbar-bg: #f6f8fa;
  --toolbar-border: #d0d7de;
}

[data-theme="dark"] {
  --editor-bg: #1e1e1e;
  --editor-gutter-bg: #252526;
  --editor-border: #3e3e42;
  --editor-text: #d4d4d4;
  --editor-line-number: #858585;
  --editor-selection: #264f78;
  --editor-error-bg: #2d1517;
  --editor-error-border: #f85149;
  --editor-error-text: #f85149;
  --editor-success: #3fb950;
  --toolbar-bg: #252526;
  --toolbar-border: #3e3e42;
}

/* Main container */
.json-formatter-wrapper {
  background: var(--mk-card-bg);
  border-radius: var(--mk-radius-lg);
  overflow: hidden;
  box-shadow: var(--mk-shadow-lg);
  border: 1px solid var(--mk-border);
  margin-bottom: 3rem;
}

/* Toolbar */
.json-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  background: var(--toolbar-bg);
  border-bottom: 1px solid var(--toolbar-border);
  gap: 0.75rem;
  flex-wrap: wrap;
  min-height: 56px;
}

.json-toolbar-left,
.json-toolbar-right {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.json-toolbar-actions {
  display: flex;
  gap: 0.375rem;
  flex-wrap: wrap;
}

.json-toolbar-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.375rem 0.75rem;
  background: var(--mk-card-bg);
  border: 1px solid var(--mk-border);
  border-radius: var(--mk-radius-sm);
  color: var(--mk-text-secondary);
  font-size: 0.8125rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--mk-transition-fast);
}

.json-toolbar-btn:hover {
  background: var(--mk-primary-light);
  border-color: var(--mk-primary);
  color: var(--mk-primary);
}

.json-toolbar-btn.primary {
  background: var(--mk-primary);
  border-color: var(--mk-primary);
  color: white;
}

.json-toolbar-btn.primary:hover {
  background: var(--mk-primary-hover);
  border-color: var(--mk-primary-hover);
}

/* Status badges */
.json-status-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.25rem 0.625rem;
  border-radius: var(--mk-radius-full);
  font-size: 0.75rem;
  font-weight: 600;
  border: 1px solid;
}

.json-status-badge.error {
  background: var(--editor-error-bg);
  border-color: var(--editor-error-border);
  color: var(--editor-error-text);
}

.json-status-badge.success {
  background: #f0fdf4;
  border-color: var(--editor-success);
  color: var(--editor-success);
}

[data-theme="dark"] .json-status-badge.success {
  background: #0d3818;
}

/* Editor grid */
.json-editor-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  height: 800px;
  background: var(--editor-bg);
  overflow: hidden;
}

@media (max-width: 992px) {
  .json-editor-grid {
    grid-template-columns: 1fr;
    height: 1000px;
  }
}

/* Editor panel */
.json-editor-panel {
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--editor-border);
  position: relative;
  overflow: hidden;
  min-height: 0;
}

.json-editor-panel:last-child {
  border-right: none;
}

@media (max-width: 992px) {
  .json-editor-panel {
    border-right: none;
    border-bottom: 1px solid var(--editor-border);
  }
  
  .json-editor-panel:last-child {
    border-bottom: none;
  }
}

/* Panel header */
.json-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 0.75rem;
  background: var(--toolbar-bg);
  border-bottom: 1px solid var(--toolbar-border);
  min-height: 36px;
}

.json-panel-title {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--mk-text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.json-panel-tabs {
  display: flex;
  gap: 0.25rem;
}

.json-panel-tab {
  padding: 0.25rem 0.625rem;
  background: transparent;
  border: none;
  border-radius: var(--mk-radius-sm);
  color: var(--mk-text-muted);
  font-size: 0.8125rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--mk-transition-fast);
}

.json-panel-tab:hover {
  background: var(--mk-primary-light);
  color: var(--mk-primary);
}

.json-panel-tab.active {
  background: var(--mk-primary);
  color: white;
}

/* Editor content */
.json-editor-content {
  flex: 1;
  display: flex;
  overflow: hidden;
  position: relative;
  min-height: 0;
}

/* Gutter */
.json-gutter {
  width: 48px;
  background: var(--editor-gutter-bg);
  border-right: 1px solid var(--editor-border);
  overflow-y: auto;
  overflow-x: hidden;
  user-select: none;
  font-family: var(--code-font);
  font-size: 0.9375rem;
  line-height: var(--code-lh);
  color: var(--editor-line-number);
  padding-top: 0.75rem;
  padding-bottom: 0.75rem;
  flex-shrink: 0;
}

.json-gutter::-webkit-scrollbar {
  width: 0;
}

.json-gutter-line {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding-right: 0.5rem;
  padding-left: 0.25rem;
  line-height: var(--code-lh);
  cursor: pointer;
  transition: all var(--mk-transition-fast);
}

.json-gutter-line:hover {
  background: var(--editor-selection);
}

.json-gutter-line.error {
  background: var(--editor-error-bg);
  color: var(--editor-error-text);
  font-weight: 600;
  position: relative;
}

.json-gutter-line.error::before {
  content: '●';
  position: absolute;
  left: 4px;
  font-size: 0.625rem;
  color: var(--editor-error-border);
}

/* Tooltip for error lines */
.json-gutter-line.error {
  position: relative;
}

.json-gutter-line.error::after {
  content: attr(data-error);
  position: absolute;
  left: 100%;
  top: 50%;
  transform: translateY(-50%);
  margin-left: 8px;
  padding: 0.5rem 0.75rem;
  background: var(--editor-error-bg);
  border: 1px solid var(--editor-error-border);
  border-radius: var(--mk-radius-sm);
  color: var(--editor-error-text);
  font-size: 0.75rem;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  transition: all var(--mk-transition-fast);
  z-index: 1000;
  box-shadow: var(--mk-shadow-lg);
  max-width: 300px;
  white-space: normal;
}

.json-gutter-line.error:hover::after {
  opacity: 1;
  visibility: visible;
}

/* Code editor */
.json-code-editor {
  flex: 1;
  font-family: var(--code-font);
  font-size: 0.9375rem;
  line-height: var(--code-lh);
  color: var(--editor-text);
  background: var(--editor-bg);
  border: none;
  outline: none;
  padding: 0.75rem;
  resize: none;
  white-space: pre;
  overflow-wrap: normal;
  overflow-x: auto;
  overflow-y: auto;
  tab-size: 2;
  min-height: 0;
}

.json-code-editor::placeholder {
  color: var(--mk-text-muted);
  opacity: 0.5;
}

.json-code-editor::selection {
  background: var(--editor-selection);
}

.json-code-editor:read-only {
  cursor: default;
}

/* Tree view */
.json-tree-view {
  flex: 1;
  padding: 1rem;
  overflow: auto;
  font-family: var(--code-font);
  font-size: 0.8125rem;
  line-height: 1.6;
  display: none;
  background: var(--editor-bg);
}

.json-tree-view:not(.d-none) {
  display: block;
}

.json-tree-node {
  margin-left: 1.25rem;
}

.json-tree-row {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  padding: 0.125rem 0;
}

.json-tree-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  background: var(--mk-card-bg);
  border: 1px solid var(--mk-border);
  border-radius: 3px;
  cursor: pointer;
  font-size: 0.625rem;
  line-height: 1;
  color: var(--mk-text-muted);
  transition: all var(--mk-transition-fast);
  flex-shrink: 0;
  margin-top: 2px;
}

.json-tree-toggle:hover {
  background: var(--mk-primary-light);
  border-color: var(--mk-primary);
  color: var(--mk-primary);
}

.json-tree-key {
  color: #0969da;
  font-weight: 500;
}

[data-theme="dark"] .json-tree-key {
  color: #58a6ff;
}

.json-tree-value {
  color: var(--mk-text-secondary);
}

.json-tree-string {
  color: #0a3069;
}

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

.json-tree-number {
  color: #0550ae;
}

[data-theme="dark"] .json-tree-number {
  color: #79c0ff;
  font-weight: 500;
}

.json-tree-badge {
  display: inline-flex;
  padding: 0.0625rem 0.375rem;
  background: var(--mk-primary-light);
  color: var(--mk-primary);
  border-radius: 3px;
  font-size: 0.6875rem;
  font-weight: 600;
  margin-left: 0.375rem;
}

[data-theme="dark"] .json-tree-badge {
  background: rgba(121, 192, 255, 0.2);
  color: #79c0ff;
  font-weight: 700;
}

/* Footer */
.json-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 1rem;
  background: var(--toolbar-bg);
  border-top: 1px solid var(--toolbar-border);
  font-size: 0.75rem;
  color: var(--mk-text-muted);
}

.json-footer-info {
  display: flex;
  align-items: center;
  gap: 1rem;
}

/* Errors panel */
.json-errors-panel {
  padding: 1rem;
  background: var(--editor-error-bg);
  border-top: 2px solid var(--editor-error-border);
  max-height: 200px;
  overflow-y: auto;
}

.json-errors-title {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--editor-error-text);
  margin-bottom: 0.75rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.json-error-item {
  padding: 0.5rem 0.75rem;
  background: var(--mk-card-bg);
  border-left: 3px solid var(--editor-error-border);
  border-radius: var(--mk-radius-sm);
  margin-bottom: 0.5rem;
  cursor: pointer;
  transition: all var(--mk-transition-fast);
}

.json-error-item:hover {
  transform: translateX(4px);
  box-shadow: var(--mk-shadow-sm);
}

.json-error-line {
  font-size: 0.6875rem;
  font-weight: 600;
  color: var(--editor-error-text);
  margin-bottom: 0.25rem;
}

.json-error-message {
  font-size: 0.8125rem;
  color: var(--mk-text-secondary);
}

/* Settings */
.json-setting {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.json-setting-label {
  font-size: 0.8125rem;
  color: var(--mk-text-secondary);
  font-weight: 500;
}

.json-setting-select {
  padding: 0.25rem 0.5rem;
  background: var(--mk-card-bg);
  border: 1px solid var(--mk-border);
  border-radius: var(--mk-radius-sm);
  color: var(--mk-text-main);
  font-size: 0.8125rem;
  cursor: pointer;
}

/* Scrollbar styling */
.json-code-editor::-webkit-scrollbar,
.json-tree-view::-webkit-scrollbar,
.json-errors-panel::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

.json-code-editor::-webkit-scrollbar-track,
.json-tree-view::-webkit-scrollbar-track,
.json-errors-panel::-webkit-scrollbar-track {
  background: var(--editor-gutter-bg);
}

.json-code-editor::-webkit-scrollbar-thumb,
.json-tree-view::-webkit-scrollbar-thumb,
.json-errors-panel::-webkit-scrollbar-thumb {
  background: var(--mk-border);
  border-radius: 5px;
}

.json-code-editor::-webkit-scrollbar-thumb:hover,
.json-tree-view::-webkit-scrollbar-thumb:hover,
.json-errors-panel::-webkit-scrollbar-thumb:hover {
  background: var(--mk-text-muted);
}
