/* JSON Viewer Pro - Professional Styles */
:root {
  --bg: #0f1419;
  --surface: #1a2332;
  --surface-hover: #243044;
  --border: #2d3a4d;
  --text: #e6edf3;
  --text-muted: #8b949e;
  --accent: #58a6ff;
  --accent-hover: #79b8ff;
  --success: #3fb950;
  --error: #f85149;
  --key: #ff7b72;
  --string: #a5d6ff;
  --number: #79c0ff;
  --boolean: #ffa657;
  --null: #8b949e;
  --radius: 8px;
  --font: 'Segoe UI', 'Vazirmatn', Tahoma, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  direction: rtl;
}

.app {
  max-width: 1400px;
  margin: 0 auto;
  padding: 1rem;
  min-height: 100vh;
}

/* Header */
.header {
  text-align: center;
  margin-bottom: 1.5rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}

.header-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.header-row h1 {
  margin: 0;
}

.lang-switcher {
  display: flex;
  gap: 0.25rem;
}

.btn-lang {
  padding: 0.35rem 0.65rem;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 0.85rem;
  font-family: inherit;
}

.btn-lang:hover {
  color: var(--text);
  border-color: var(--accent);
}

.btn-lang.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.header h1 {
  margin: 0;
  font-size: 1.75rem;
  font-weight: 600;
  color: var(--text);
}

.tagline {
  margin: 0.35rem 0 0;
  font-size: 0.9rem;
  color: var(--text-muted);
}

/* Tabs */
.tabs {
  display: flex;
  gap: 0.25rem;
  margin-bottom: 1rem;
}

.tab {
  padding: 0.6rem 1.2rem;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  border-radius: var(--radius);
  cursor: pointer;
  font-family: inherit;
  font-size: 0.95rem;
  transition: background 0.2s, color 0.2s, border-color 0.2s;
}

.tab:hover {
  background: var(--surface-hover);
  color: var(--text);
}

.tab.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

/* Toolbar */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  margin-bottom: 1rem;
}

.toolbar-right {
  margin-right: auto;
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.btn {
  padding: 0.5rem 1rem;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: var(--radius);
  cursor: pointer;
  font-family: inherit;
  font-size: 0.9rem;
  transition: background 0.2s, border-color 0.2s;
}

.btn:hover {
  background: var(--surface-hover);
  border-color: var(--accent);
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.btn-primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.btn-file {
  cursor: pointer;
  margin: 0;
}

.btn-sm {
  padding: 0.35rem 0.65rem;
  font-size: 0.85rem;
}

.btn-icon {
  padding: 0.5rem 0.75rem;
  font-size: 1.1rem;
}

.indent-select {
  padding: 0.5rem 0.5rem;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: var(--radius);
  font-family: inherit;
  font-size: 0.85rem;
  cursor: pointer;
}

/* Stats bar */
.stats-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  padding: 0.5rem 0;
  margin-bottom: 0.5rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.stats-bar.hidden {
  display: none;
}

.stats-bar span {
  white-space: nowrap;
}

.search-input {
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: var(--radius);
  font-family: inherit;
  font-size: 0.9rem;
  min-width: 180px;
}

.search-input::placeholder {
  color: var(--text-muted);
}

.search-input:focus {
  outline: none;
  border-color: var(--accent);
}

/* Share / Save link section */
.share-section {
  margin-bottom: 1rem;
  padding: 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.share-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

.share-password {
  padding: 0.5rem 1rem;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  border-radius: var(--radius);
  font-family: inherit;
  font-size: 0.9rem;
  width: 220px;
  min-width: 0;
}

.share-password::placeholder {
  color: var(--text-muted);
}

.share-result {
  margin-top: 1rem;
}

.share-result.hidden {
  display: none;
}

.share-result label {
  display: block;
  font-size: 0.9rem;
  color: var(--text-muted);
  margin-bottom: 0.35rem;
}

.share-url-row {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.share-url {
  flex: 1;
  min-width: 0;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--accent);
  border-radius: var(--radius);
  font-size: 0.9rem;
  direction: ltr;
  text-align: left;
}

/* Panels */
.panel {
  display: none;
  flex-direction: column;
  min-height: 400px;
}

.panel.active {
  display: flex;
}

/* Editor with line numbers */
.editor-wrap {
  display: flex;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  min-height: 420px;
}

.line-numbers {
  padding: 1rem 0.5rem 1rem 1rem;
  min-width: 2.5em;
  font-family: 'Consolas', 'Monaco', monospace;
  font-size: 0.9rem;
  line-height: 1.5;
  color: var(--text-muted);
  text-align: right;
  user-select: none;
  overflow: hidden;
}

.line-numbers pre {
  margin: 0;
}

.error-position {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-top: 0.25rem;
}

/* Copy as & Recent dropdowns */
.copy-as-wrap,
.recent-wrap {
  position: relative;
}

.copy-as-menu,
.recent-menu {
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: 0.25rem;
  min-width: 160px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
  z-index: 100;
  padding: 0.25rem;
}

.copy-as-menu.hidden,
.recent-menu.hidden {
  display: none;
}

.copy-as-menu button,
.recent-menu button {
  display: block;
  width: 100%;
  padding: 0.5rem 0.75rem;
  text-align: right;
  border: none;
  background: none;
  color: var(--text);
  cursor: pointer;
  border-radius: 4px;
  font-family: inherit;
  font-size: 0.9rem;
}

.copy-as-menu button:hover,
.recent-menu button:hover {
  background: var(--surface-hover);
}

.recent-menu .recent-item {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 280px;
}

.recent-menu .recent-empty {
  padding: 0.75rem;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.jsonpath-wrap {
  display: flex;
  gap: 0.25rem;
  align-items: center;
}

.jsonpath-input {
  min-width: 140px;
}

.jsonpath-result {
  margin-bottom: 0.75rem;
  padding: 0.5rem 0.75rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: 'Consolas', 'Monaco', monospace;
  font-size: 0.85rem;
  direction: ltr;
  text-align: left;
  word-break: break-all;
  max-height: 120px;
  overflow: auto;
}

.jsonpath-result.hidden {
  display: none;
}

.jsonpath-result .jsonpath-result-label {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 0.25rem;
}

/* Text area */
.editor-wrap .json-input {
  flex: 1;
  min-width: 0;
  border: none;
  border-radius: 0;
  border-right: 1px solid var(--border);
}

.json-input {
  width: 100%;
  min-height: 420px;
  padding: 1rem;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: var(--radius);
  font-family: 'Consolas', 'Monaco', 'Vazir Code', monospace;
  font-size: 0.9rem;
  line-height: 1.5;
  resize: vertical;
  direction: ltr;
  text-align: left;
}

.json-input:focus {
  outline: none;
  border-color: var(--accent);
}

.json-input::placeholder {
  color: var(--text-muted);
}

.error-msg {
  margin-top: 0.5rem;
  padding: 0.5rem 1rem;
  background: rgba(248, 81, 73, 0.15);
  color: var(--error);
  border-radius: var(--radius);
  font-size: 0.9rem;
}

.error-msg.hidden {
  display: none;
}

/* Viewer toolbar */
.viewer-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  margin-bottom: 0.75rem;
}

.tree-filter-input {
  padding: 0.4rem 0.75rem;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: var(--radius);
  font-family: inherit;
  font-size: 0.9rem;
  min-width: 180px;
  direction: ltr;
  text-align: left;
}

.tree-filter-input:focus {
  outline: none;
  border-color: var(--accent);
}

.detail-header {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  margin-bottom: 0.75rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border);
}

.detail-header.hidden {
  display: none;
}

.detail-path-label {
  font-size: 0.9rem;
  color: var(--text-muted);
}

.detail-path {
  flex: 1;
  min-width: 0;
  font-size: 0.85rem;
  padding: 0.25rem 0.5rem;
  background: var(--bg);
  border-radius: 4px;
  direction: ltr;
  text-align: left;
  word-break: break-all;
}

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 1rem;
}

.modal.hidden {
  display: none;
}

.modal-content {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  max-width: 480px;
  width: 100%;
}

.modal-content h3 {
  margin: 0 0 1rem;
  font-size: 1.1rem;
}

.url-input {
  width: 100%;
  padding: 0.6rem;
  margin-bottom: 0.5rem;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  border-radius: var(--radius);
  font-family: inherit;
  direction: ltr;
  text-align: left;
}

.modal-actions {
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
  margin-top: 1rem;
}

.shortcuts-list {
  list-style: none;
  padding: 0;
  margin: 0 0 1rem;
}

.shortcuts-list li {
  padding: 0.4rem 0;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.shortcuts-list kbd {
  padding: 0.2rem 0.4rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 0.85rem;
}

/* Toasts */
.toast-container {
  position: fixed;
  bottom: 1rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1001;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  pointer-events: none;
}

.toast {
  padding: 0.6rem 1.2rem;
  border-radius: var(--radius);
  font-size: 0.9rem;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  pointer-events: auto;
  animation: toastIn 0.25s ease;
}

.toast.success {
  background: var(--success);
  color: #fff;
}

.toast.error {
  background: var(--error);
  color: #fff;
}

.toast.info {
  background: var(--accent);
  color: #fff;
}

@keyframes toastIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Viewer layout - LTR so JSON displays correctly in English */
.viewer-layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  min-height: 450px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface);
  direction: ltr;
  text-align: left;
}

.tree-pane {
  overflow: auto;
  padding: 1rem;
  border-left: 1px solid var(--border);
  direction: ltr;
  text-align: left;
}

.detail-pane {
  overflow: auto;
  padding: 1rem;
  direction: ltr;
  text-align: left;
}

.tree-container {
  font-family: 'Consolas', 'Monaco', monospace;
  font-size: 0.9rem;
  line-height: 1.6;
  direction: ltr;
  text-align: left;
}

/* Tree nodes - preserve order, no alphabetical sort */
.tree-node {
  margin: 0.15rem 0;
}

.tree-toggle {
  display: inline-block;
  width: 1rem;
  cursor: pointer;
  color: var(--text-muted);
  user-select: none;
}

.tree-toggle:hover {
  color: var(--accent);
}

.tree-key {
  color: var(--key);
  margin-left: 0.25rem;
}

.tree-key.array-index {
  color: var(--number);
}

.tree-value {
  color: var(--string);
}

.tree-value.number {
  color: var(--number);
}

.tree-value.boolean {
  color: var(--boolean);
}

.tree-value.null {
  color: var(--null);
  font-style: italic;
}

.tree-children {
  margin-left: 1.25rem;
}

.tree-children.hidden {
  display: none;
}

.tree-node.selected > .tree-line {
  background: var(--surface-hover);
  border-radius: 4px;
}

.tree-line {
  padding: 2px 6px;
  cursor: pointer;
  border-radius: 4px;
}

.tree-line:hover {
  background: var(--surface-hover);
}

.tree-line .brace {
  color: var(--text-muted);
}

/* Detail table - same order as JSON */
.detail-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.detail-table th,
.detail-table td {
  padding: 0.5rem 0.75rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.detail-table th {
  color: var(--text-muted);
  font-weight: 500;
  width: 40%;
}

.detail-table td {
  color: var(--text);
  word-break: break-all;
}

.detail-table tr:hover td {
  background: var(--surface-hover);
}

.placeholder {
  color: var(--text-muted);
  font-size: 0.95rem;
  margin: 0;
}

/* Search highlight */
.tree-line mark {
  background: rgba(255, 200, 0, 0.4);
  color: inherit;
  padding: 0 2px;
  border-radius: 2px;
}

@media (max-width: 768px) {
  .viewer-layout {
    grid-template-columns: 1fr;
  }

  .toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .toolbar-right {
    margin-right: 0;
  }

  .search-input {
    min-width: 0;
  }

  .viewer-toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .tree-filter-input {
    min-width: 0;
  }
}

/* Light theme */
body.theme-light {
  --bg: #f6f8fa;
  --surface: #ffffff;
  --surface-hover: #eaeef2;
  --border: #d0d7de;
  --text: #1f2328;
  --text-muted: #656d76;
  --accent: #0969da;
  --accent-hover: #0550ae;
  --success: #1a7f37;
  --error: #cf222e;
  --key: #953800;
  --string: #0a3069;
  --number: #0550ae;
  --boolean: #bf3989;
  --null: #656d76;
}

body.theme-light .toast.success { color: #fff; }
body.theme-light .toast.error { color: #fff; }
body.theme-light .toast.info { color: #fff; }
