:root {
  --bg: #f4f6f9;
  --panel: #fff;
  --border: #d8dee9;
  --text: #1e293b;
  --muted: #64748b;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --annotated: #059669;
  --danger: #dc2626;
  --header-h: 72px;
  --load-h: 52px;
  --status-h: 28px;
}

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

body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.app-header {
  background: linear-gradient(135deg, #1e3a5f, #2563eb);
  color: #fff;
  padding: 0.5rem 1rem;
  flex-shrink: 0;
}

.header-inner {
  display: flex;
  align-items: baseline;
  gap: 1rem;
  flex-wrap: wrap;
}

.app-header h1 {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.tagline {
  font-size: 0.85rem;
  opacity: 0.9;
}

.header-nav {
  margin-left: auto;
  display: flex;
  gap: 1rem;
}

.header-nav a {
  color: #e2e8f0;
  text-decoration: none;
  font-size: 0.8rem;
}

.header-nav a:hover {
  text-decoration: underline;
}

.load-bar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0.75rem;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  flex-wrap: wrap;
}

.mode-fieldset {
  border: none;
  display: flex;
  gap: 0.5rem;
  align-items: center;
  font-size: 0.8rem;
}

.mode-fieldset legend {
  font-weight: 600;
  margin-right: 0.25rem;
}

.mode-option {
  display: flex;
  align-items: center;
  gap: 0.2rem;
  cursor: pointer;
}

.url-input {
  flex: 1;
  min-width: 200px;
  padding: 0.35rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-family: ui-monospace, monospace;
  font-size: 0.75rem;
}

.file-label {
  font-size: 0.8rem;
  color: var(--muted);
}

.file-select {
  max-width: 280px;
  padding: 0.3rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 0.75rem;
}

.workspace {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(240px, 32%) 1fr minmax(200px, 22%);
  gap: 0;
  min-height: 0;
  overflow: hidden;
}

.panel {
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.panel h2 {
  font-size: 0.85rem;
  font-weight: 600;
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.hint {
  font-size: 0.7rem;
  color: var(--muted);
  padding: 0 0.75rem 0.35rem;
  flex-shrink: 0;
}

.tree-container {
  flex: 1;
  overflow: auto;
  padding: 0;
  min-height: 120px;
}

.tree-empty {
  padding: 1rem;
  color: var(--muted);
  font-size: 0.85rem;
}

.definition-tree-svg {
  display: block;
  font-size: 11px;
}

.definition-tree-svg .link {
  fill: none;
  stroke: #cbd5e1;
  stroke-width: 1px;
}

.definition-tree-svg .node text {
  font-family: ui-monospace, monospace;
  font-size: 10px;
}

.definition-tree-svg .node circle {
  fill: #94a3b8;
  stroke: #64748b;
  stroke-width: 1px;
}

.definition-tree-svg .node.has-annotations circle,
.definition-tree-svg .node circle.annotated {
  fill: var(--annotated);
  stroke: #047857;
}

.definition-tree-svg .node.selected circle {
  stroke: var(--accent);
  stroke-width: 2px;
}

.definition-tree-svg .node.selected text {
  font-weight: 700;
  fill: var(--accent);
}

.detail-panel {
  border-right: 1px solid var(--border);
}

.selected-path {
  font-family: ui-monospace, monospace;
  font-size: 0.8rem;
  padding: 0.5rem 0.75rem;
  background: #f1f5f9;
  border-bottom: 1px solid var(--border);
  word-break: break-all;
}

.lang-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  flex-shrink: 0;
}

.annotation-table {
  width: 100%;
  border-collapse: collapse;
  margin: 0 0.75rem 0.75rem;
}

.annotation-table th,
.annotation-table td {
  border: 1px solid var(--border);
  padding: 0.25rem 0.35rem;
  text-align: left;
}

.annotation-table th {
  background: #f8fafc;
  font-size: 0.75rem;
}

.annotation-table input {
  width: 100%;
  border: none;
  font-family: inherit;
  font-size: 0.85rem;
  padding: 0.2rem;
}

.palette-panel {
  border-right: none;
}

.palette-list {
  list-style: none;
  overflow-y: auto;
  flex: 1;
  padding: 0.25rem 0.5rem;
}

.palette-list li {
  display: flex;
  gap: 0.25rem;
  margin-bottom: 0.25rem;
}

.palette-apply {
  flex: 1;
  text-align: left;
  padding: 0.3rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: #f8fafc;
  cursor: pointer;
  font-size: 0.75rem;
  font-family: ui-monospace, monospace;
}

.palette-apply:hover {
  background: #e0f2fe;
  border-color: var(--accent);
}

.palette-remove {
  width: 1.6rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: #fff;
  cursor: pointer;
  color: var(--danger);
}

.palette-add,
.palette-io {
  padding: 0.5rem 0.75rem;
  border-top: 1px solid var(--border);
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  flex-shrink: 0;
}

.palette-input {
  flex: 1;
  min-width: 80px;
  padding: 0.3rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 0.8rem;
}

.btn {
  padding: 0.35rem 0.75rem;
  border-radius: 4px;
  border: 1px solid transparent;
  cursor: pointer;
  font-size: 0.8rem;
  font-weight: 500;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
}

.btn-primary:disabled {
  opacity: 0.6;
  cursor: wait;
}

.btn-secondary {
  background: #f1f5f9;
  border-color: var(--border);
  color: var(--text);
}

.btn-secondary:hover {
  background: #e2e8f0;
}

.btn-sm {
  padding: 0.25rem 0.5rem;
  font-size: 0.75rem;
}

.btn-danger {
  color: var(--danger);
}

.upload-label {
  cursor: pointer;
  display: inline-block;
}

.status-bar {
  flex-shrink: 0;
  padding: 0.35rem 0.75rem;
  font-size: 0.75rem;
  color: var(--muted);
  background: var(--panel);
  border-top: 1px solid var(--border);
}

.status-bar.is-error {
  color: var(--danger);
}

@media (max-width: 900px) {
  .workspace {
    grid-template-columns: 1fr;
    grid-template-rows: 40% 1fr auto;
  }

  .palette-panel {
    max-height: 200px;
  }
}
