*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root, [data-theme="dark"] {
  --black: #000000;
  --gray-950: #0a0a0a;
  --gray-900: #111111;
  --gray-850: #171717;
  --gray-800: #1a1a1a;
  --gray-700: #262626;
  --gray-600: #404040;
  --gray-500: #6b6b6b;
  --gray-400: #8a8a8a;
  --gray-300: #b3b3b3;
  --gray-200: #d4d4d4;
  --white: #ffffff;
  --radius: 8px;
  --shadow-drop: 0 8px 24px rgba(0,0,0,.5);
  --shadow-dialog: 0 20px 60px rgba(0,0,0,.6);
  --overlay-bg: rgba(0,0,0,.6);
  --row-hover: rgba(255,255,255,.04);
  --divider-split: rgba(0,0,0,.15);
}

[data-theme="light"] {
  --black: #ffffff;
  --gray-950: #f9f9f9;
  --gray-900: #f3f3f3;
  --gray-850: #eeeeee;
  --gray-800: #e5e5e5;
  --gray-700: #d4d4d4;
  --gray-600: #a3a3a3;
  --gray-500: #737373;
  --gray-400: #525252;
  --gray-300: #404040;
  --gray-200: #262626;
  --white: #000000;
  --shadow-drop: 0 8px 24px rgba(0,0,0,.08);
  --shadow-dialog: 0 20px 60px rgba(0,0,0,.12);
  --overlay-bg: rgba(0,0,0,.25);
  --row-hover: rgba(0,0,0,.03);
  --divider-split: rgba(0,0,0,.08);
}

::selection {
  background: var(--white);
  color: var(--black);
}

html, body {
  height: 100%;
}

body {
  font-family: 'Inter', -apple-system, system-ui, sans-serif;
  background: var(--black);
  color: var(--white);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ── Header ── */
header {
  padding: 0 32px;
  height: 52px;
  border-bottom: 1px solid var(--gray-800);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.logo {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo-mark {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.1em;
  color: var(--gray-500);
  border: 1px solid var(--gray-700);
  border-radius: 4px;
  padding: 2px 6px;
}

header h1 {
  font-size: 14px;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.coffee-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 6px;
  border: 1px solid var(--gray-600);
  background: transparent;
  color: var(--gray-300);
  cursor: pointer;
  transition: all 0.15s;
  text-decoration: none;
}

.coffee-link:hover {
  border-color: var(--gray-400);
  color: var(--white);
  background: var(--gray-900);
}

.coffee-link svg { width: 16px; height: 16px; }

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 6px;
  border: 1px solid var(--gray-600);
  background: transparent;
  color: var(--gray-300);
  cursor: pointer;
  transition: all 0.15s;
}

.theme-toggle:hover {
  border-color: var(--gray-400);
  color: var(--white);
  background: var(--gray-900);
}

.theme-toggle svg { width: 16px; height: 16px; }

/* Dark mode: show moon, hide sun */
[data-theme="dark"] .icon-sun,
:root:not([data-theme]) .icon-sun { display: none; }
[data-theme="dark"] .icon-moon,
:root:not([data-theme]) .icon-moon { display: block; }

/* Light mode: show sun, hide moon */
[data-theme="light"] .icon-sun { display: block; }
[data-theme="light"] .icon-moon { display: none; }

/* ── Stats Dialog ── */
.stats-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: var(--overlay-bg);
  z-index: 9998;
}

.stats-overlay.open { display: block; }

.stats-dialog {
  display: none;
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: var(--gray-900);
  border: 1px solid var(--gray-700);
  border-radius: 12px;
  padding: 28px 32px;
  z-index: 9999;
  min-width: 360px;
  box-shadow: var(--shadow-dialog);
}

.stats-dialog.open { display: block; }

.stats-dialog-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.stats-dialog-header h2 {
  font-size: 13px;
  font-weight: 600;
  color: var(--white);
  letter-spacing: -0.01em;
}

.stats-dialog-close {
  width: 28px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  border: none;
  background: transparent;
  color: var(--gray-500);
  cursor: pointer;
  transition: all 0.15s;
}

.stats-dialog-close:hover {
  background: var(--gray-800);
  color: var(--white);
}

.stats-dialog-close svg { width: 16px; height: 16px; }

.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1px;
  background: var(--gray-800);
  border-radius: var(--radius);
  overflow: hidden;
}

.stats-grid .stat {
  background: var(--gray-950);
  padding: 16px 20px;
}

.stats-grid .stat:last-child:nth-child(odd) {
  grid-column: span 2;
}

.stats-grid .stat-value {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.stats-grid .stat-label {
  font-size: 10px;
  color: var(--gray-500);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-top: 4px;
}

/* ── Container ── */
.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px 32px;
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
  width: 100%;
}

/* ── Upload ── */
.upload-options {
  margin: auto 0;
  text-align: center;
}

.upload-tabs {
  display: flex;
  justify-content: center;
  gap: 4px;
  margin-bottom: 16px;
}

.upload-tab {
  padding: 6px 16px;
  font-size: 12px;
  font-weight: 500;
  color: var(--gray-500);
  background: none;
  border: 1px solid transparent;
  border-radius: 6px;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.15s;
}

.upload-tab:hover { color: var(--gray-300); }

.upload-tab.active {
  color: var(--white);
  background: var(--gray-900);
  border-color: var(--gray-700);
}

.upload-panel { display: none; }
.upload-panel.active { display: block; }

.upload-zone {
  border: 1px solid var(--gray-800);
  border-radius: var(--radius);
  padding: 96px 32px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
  position: relative;
}

.upload-zone:hover {
  border-color: var(--gray-600);
}

.upload-zone.dragover {
  border-color: var(--white);
  background: var(--row-hover);
}

.upload-icon {
  width: 48px;
  height: 48px;
  margin: 0 auto 24px;
  border: 1px solid var(--gray-700);
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
}

.upload-icon svg {
  width: 20px;
  height: 20px;
  color: var(--gray-500);
}

.upload-zone h2 {
  font-size: 14px;
  font-weight: 500;
  margin-bottom: 4px;
}

.upload-zone p {
  font-size: 13px;
  color: var(--gray-500);
}

.how-to-hint {
  position: relative;
  display: inline-block;
  font-size: 12px;
  color: var(--gray-500);
  cursor: help;
  text-decoration: underline;
  text-decoration-style: dashed;
  text-underline-offset: 3px;
  text-decoration-color: var(--gray-600);
  margin-top: 10px;
  text-align: center;
}
.how-to-hint:hover { color: var(--gray-300); text-decoration-color: var(--gray-400); }
.how-to-img {
  display: none;
  position: fixed;
  width: 420px;
  height: 430px;
  border-radius: 8px;
  border: 1px solid var(--gray-700);
  box-shadow: 0 12px 40px rgba(0,0,0,.5);
  pointer-events: none;
  z-index: 9999;
  background: url('../images/how-to.png') center / contain no-repeat var(--gray-900);
}
.how-to-hint:hover .how-to-img { display: block; }

.upload-zone input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

/* ── API Upload ── */
.api-form {
  border: 1px solid var(--gray-800);
  border-radius: var(--radius);
  padding: 48px 32px;
  max-width: 480px;
  margin: 0 auto;
  text-align: left;
}

.api-field {
  margin-bottom: 16px;
}

.api-field label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--gray-300);
  margin-bottom: 6px;
}

.api-field input[type="text"],
.api-field input[type="password"] {
  width: 100%;
  padding: 8px 12px;
  font-size: 13px;
  font-family: 'JetBrains Mono', monospace;
  background: var(--gray-950);
  border: 1px solid var(--gray-700);
  border-radius: 6px;
  color: var(--white);
  outline: none;
  transition: border-color 0.15s;
}

.api-field input:focus {
  border-color: var(--gray-500);
}

.api-input-row {
  display: flex;
  gap: 6px;
  align-items: center;
}

.api-input-row input { flex: 1; }

.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 6px;
  border: 1px solid var(--gray-700);
  background: transparent;
  color: var(--gray-400);
  cursor: pointer;
  transition: all 0.15s;
  flex-shrink: 0;
}

.btn-icon:hover {
  border-color: var(--gray-500);
  color: var(--white);
}

.btn-icon svg { width: 14px; height: 14px; }

.btn-icon .icon-eye-off { display: none; }
.btn-icon.active .icon-eye { display: none; }
.btn-icon.active .icon-eye-off { display: block; }

.api-hint {
  font-size: 11px;
  color: var(--gray-600);
  margin-top: 4px;
}

.api-error {
  color: #ef4444;
  font-size: 12px;
  margin-top: 12px;
  text-align: center;
}

.api-form .btn-white {
  width: 100%;
  justify-content: center;
  margin-top: 8px;
}

/* ── Processing ── */
.processing {
  display: none;
  text-align: center;
  padding: 96px 32px;
  border: 1px solid var(--gray-800);
  border-radius: var(--radius);
  margin: auto 0;
}

.processing.show { display: block; }

.spinner {
  width: 20px;
  height: 20px;
  border: 1.5px solid var(--gray-700);
  border-top-color: var(--white);
  border-radius: 50%;
  margin: 0 auto 16px;
  animation: spin 0.6s linear infinite;
}

.processing p { font-size: 13px; color: var(--gray-500); }

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

/* ── Results ── */
.results { display: none; }
.results.show {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

/* ── Toolbar ── */
.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  gap: 12px;
  flex-wrap: wrap;
  flex-shrink: 0;
  position: relative;
  z-index: 10;
}

.btn-group {
  display: flex;
  gap: 8px;
  align-items: center;
}

.btn-split {
  display: inline-flex;
  align-items: stretch;
  border-radius: 6px;
  position: relative;
}

.btn-split .btn {
  border-top-right-radius: 0;
  border-bottom-right-radius: 0;
  border-right: none;
}

.btn-split .btn-dropdown-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  border: 1px solid var(--gray-700);
  border-left: 1px solid var(--gray-700);
  border-top-right-radius: 6px;
  border-bottom-right-radius: 6px;
  border-top-left-radius: 0;
  border-bottom-left-radius: 0;
  background: transparent;
  color: var(--gray-400);
  cursor: pointer;
  transition: all 0.15s;
  padding: 0;
}

.btn-split .btn-dropdown-toggle:hover {
  border-color: var(--gray-500);
  color: var(--white);
}

.btn-split .btn-dropdown-toggle svg {
  width: 12px;
  height: 12px;
}

.btn-split.white .btn-dropdown-toggle {
  background: var(--white);
  color: var(--black);
  border-color: var(--white);
  border-left-color: var(--divider-split);
}

.btn-split.white .btn-dropdown-toggle:hover {
  background: var(--gray-200);
  border-color: var(--gray-200);
  border-left-color: var(--divider-split);
  color: var(--black);
}

.filter-dropdown {
  position: fixed;
  background: var(--gray-900);
  border: 1px solid var(--gray-700);
  border-radius: 8px;
  padding: 6px 0;
  min-width: 170px;
  z-index: 9999;
  display: none;
  box-shadow: var(--shadow-drop);
}

.filter-dropdown.open { display: block; }

.filter-dropdown label {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 14px;
  font-size: 12px;
  font-weight: 500;
  color: var(--gray-300);
  cursor: pointer;
  transition: background 0.1s, color 0.1s;
  user-select: none;
}

.filter-dropdown label:hover {
  background: var(--gray-800);
  color: var(--white);
}

.filter-dropdown input[type="checkbox"] {
  appearance: none;
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  border: 1.5px solid var(--gray-600);
  border-radius: 3px;
  background: transparent;
  cursor: pointer;
  position: relative;
  flex-shrink: 0;
  transition: all 0.15s;
}

.filter-dropdown input[type="checkbox"]:checked {
  background: var(--white);
  border-color: var(--white);
}

.filter-dropdown input[type="checkbox"]:checked::after {
  content: '';
  position: absolute;
  left: 3px;
  top: 0.5px;
  width: 5px;
  height: 8px;
  border: solid var(--black);
  border-width: 0 1.5px 1.5px 0;
  transform: rotate(45deg);
}

.filter-dropdown input[type="radio"] {
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  width: 16px;
  height: 16px;
  min-width: 16px;
  min-height: 16px;
  border: 2px solid var(--gray-600);
  border-radius: 50%;
  background: transparent;
  cursor: pointer;
  flex-shrink: 0;
  transition: all 0.15s;
  display: inline-block;
  vertical-align: middle;
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

.filter-dropdown input[type="radio"]:checked {
  border-color: var(--white);
  border-width: 5px;
  background: var(--white);
}

.dropdown-section-label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--gray-500);
  padding: 6px 14px 2px;
}

.dropdown-divider {
  height: 1px;
  background: var(--gray-700);
  margin: 6px 0;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 500;
  border: 1px solid var(--gray-700);
  background: transparent;
  color: var(--gray-400);
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
  font-family: inherit;
}

.btn:hover {
  border-color: var(--gray-500);
  color: var(--white);
}

.btn svg { width: 14px; height: 14px; }

.btn-white {
  background: var(--white);
  color: var(--black);
  border-color: var(--white);
  font-weight: 600;
}

.btn-white:hover {
  background: var(--gray-200);
  border-color: var(--gray-200);
  color: var(--black);
}

.btn-white.copied {
  background: var(--gray-300);
  border-color: var(--gray-300);
}

.reset-link {
  font-size: 12px;
  color: var(--gray-500);
  cursor: pointer;
  background: none;
  border: none;
  padding: 7px 4px;
  font-family: inherit;
  transition: color 0.15s;
  text-decoration: underline;
  text-decoration-color: var(--gray-700);
  text-underline-offset: 3px;
}

.reset-link:hover { color: var(--white); text-decoration-color: var(--gray-400); }

.stats-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  color: var(--gray-500);
  cursor: pointer;
  background: none;
  border: none;
  padding: 7px 4px;
  font-family: inherit;
  transition: color 0.15s;
}
.stats-link:hover { color: var(--white); }
.stats-link svg { width: 13px; height: 13px; }

/* ── Layout ── */
.layout {
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 1px;
  background: var(--gray-800);
  border-radius: var(--radius);
  overflow: hidden;
  flex: 1;
  min-height: 0;
}

@media (max-width: 768px) {
  .layout { grid-template-columns: 1fr; }
}

/* ── Sidebar ── */
.sidebar {
  background: var(--gray-950);
  padding: 12px;
  overflow-y: auto;
  min-height: 0;
}

.sidebar::-webkit-scrollbar { width: 3px; }
.sidebar::-webkit-scrollbar-track { background: transparent; }
.sidebar::-webkit-scrollbar-thumb { background: var(--gray-700); border-radius: 2px; }

.sidebar-section {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--gray-500);
  padding: 8px 6px 6px;
}

.sidebar-section:not(:first-child) { margin-top: 12px; }

.tree-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 6px;
  border-radius: 4px;
  font-size: 12px;
  color: var(--gray-400);
  cursor: pointer;
  transition: color 0.1s, background 0.1s;
  user-select: none;
}

.tree-item:hover { color: var(--white); }

.tree-item.active {
  color: var(--white);
  background: var(--gray-800);
}

.tree-item.active .tree-dot {
  background: var(--white);
}

.tree-item.active .meta {
  color: var(--gray-400);
}

.tree-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  flex-shrink: 0;
  background: var(--gray-600);
}

.tree-item.sub-item .tree-dot {
  background: var(--gray-700);
  width: 4px;
  height: 4px;
}

.tree-item .meta {
  font-size: 10px;
  color: var(--gray-600);
  margin-left: auto;
  font-family: 'JetBrains Mono', monospace;
}

/* ── Main panel ── */
.main-panel {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.tabs {
  display: flex;
  background: var(--gray-950);
  border-bottom: 1px solid var(--gray-800);
  padding: 0 8px;
  flex-shrink: 0;
  flex-grow: 0;
  height: 38px;
  overflow: hidden;
}

.tabs::-webkit-scrollbar { display: none; }

.tab {
  padding: 10px 14px;
  font-size: 12px;
  font-weight: 500;
  color: var(--gray-500);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all 0.15s;
  white-space: nowrap;
  background: none;
  border-top: none;
  border-left: none;
  border-right: none;
  font-family: inherit;
  margin-bottom: -1px;
}

.tab:hover { color: var(--gray-300); }

.tab.active {
  color: var(--white);
  border-bottom-color: var(--white);
}

.tab .count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: 3px;
  font-size: 10px;
  font-weight: 600;
  margin-left: 5px;
  font-family: 'JetBrains Mono', monospace;
  color: var(--gray-600);
}

.tab.active .count {
  color: var(--gray-400);
}

.output-panel {
  background: var(--gray-950);
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.markdown-output {
  padding: 24px;
  font-family: 'Inter', -apple-system, system-ui, sans-serif;
  font-size: 13px;
  line-height: 1.5;
  height: 100%;
  overflow-y: auto;
  color: var(--gray-300);
}

.markdown-output::-webkit-scrollbar { width: 3px; }
.markdown-output::-webkit-scrollbar-track { background: transparent; }
.markdown-output::-webkit-scrollbar-thumb { background: var(--gray-700); border-radius: 2px; }

/* Rendered markdown */
.markdown-output h1 {
  font-size: 16px;
  font-weight: 700;
  color: var(--white);
  margin-bottom: 20px;
  letter-spacing: -0.02em;
}

.markdown-output h2 {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--gray-400);
  margin: 32px 0 16px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--gray-700);
}

.markdown-output h2:first-child { margin-top: 0; }

.markdown-output h3 {
  font-size: 14px;
  font-weight: 600;
  color: var(--white);
  margin: 24px 0 4px;
  letter-spacing: -0.01em;
}

.markdown-output h3 .parent-ref {
  font-weight: 400;
  color: var(--gray-500);
  font-size: 12px;
}

.markdown-output table {
  width: 100%;
  border-collapse: collapse;
  margin: 8px 0 16px;
  font-size: 12px;
}

.markdown-output thead th {
  text-align: left;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--gray-500);
  padding: 8px 12px;
  border-bottom: 1px solid var(--gray-700);
}

.markdown-output tbody td {
  padding: 7px 12px;
  border-bottom: 1px solid var(--gray-850);
  vertical-align: top;
}

.markdown-output tbody tr:last-child td {
  border-bottom: none;
}

.markdown-output tbody tr:hover td {
  background: var(--row-hover);
}

.markdown-output .field-name {
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
  color: var(--white);
}

.markdown-output .field-type {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  color: var(--gray-400);
}

.markdown-output .field-type .ref {
  color: var(--gray-300);
}

.markdown-output .field-type .ref[data-ref-name] {
  cursor: pointer;
  color: var(--white);
  text-decoration: underline;
  text-decoration-color: var(--gray-500);
  text-underline-offset: 2px;
  transition: color 0.15s, text-decoration-color 0.15s;
}

.markdown-output .field-type .ref[data-ref-name]:hover {
  color: var(--white);
  text-decoration-color: var(--white);
}

.markdown-output .enum-list {
  list-style: none;
  padding: 0;
  margin: 8px 0 16px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.markdown-output .enum-value {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  color: var(--gray-200);
  background: var(--gray-800);
  border: 1px solid var(--gray-700);
  padding: 3px 10px;
  border-radius: 4px;
}

.markdown-output .empty-note {
  color: var(--gray-600);
  font-style: italic;
  font-size: 12px;
}
