:root {
  --bg: #0a0a0f;
  --surface: #14141c;
  --surface-2: #1a1a24;
  --border: #2a2a36;
  --text: #f0f0f5;
  --muted: #8b8b9a;
  --accent: #7b6cf6;
  --accent-hover: #6a5ce0;
  --success: #4ade80;
  --warning: #fbbf24;
  --danger: #f87171;
  --mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --header-h: 48px;
}

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

body {
  margin: 0;
  font: 14px/1.45 var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

.hidden { display: none !important; }
.muted { color: var(--muted); margin: 0; }
.hint { margin: 12px 0 0; font-size: 12px; color: var(--muted); }

code {
  font-family: var(--mono);
  font-size: 0.92em;
  background: var(--surface-2);
  padding: 1px 5px;
  border-radius: 4px;
}

/* Connect */
.connect-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.connect-box {
  width: min(360px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 24px;
}

.connect-box h1 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
}

.connect-box .muted { margin-top: 4px; font-size: 13px; }

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

.header {
  height: var(--header-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  gap: 12px;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 20px;
  min-width: 0;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.logo {
  font-weight: 700;
  font-size: 13px;
  letter-spacing: 0.06em;
  color: var(--accent);
}

.nav-desktop { display: flex; gap: 2px; }
.nav-mobile { display: none; }

.nav-link {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  padding: 6px 10px;
  border-radius: 6px;
  cursor: pointer;
}

.nav-link:hover { color: var(--text); background: var(--surface-2); }
.nav-link.active { color: var(--text); background: var(--surface-2); }

.nav-mobile select {
  font: inherit;
  font-size: 13px;
  padding: 6px 8px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
}

.host-tag {
  font-size: 12px;
  color: var(--muted);
  font-family: var(--mono);
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.page-bar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 20px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}

.page-bar h1 {
  margin: 0;
  font-size: 20px;
  font-weight: 600;
}

.page-bar .muted { font-size: 13px; margin-top: 2px; }

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

.content {
  flex: 1;
  padding: 16px 20px 32px;
  max-width: 1400px;
  width: 100%;
  margin: 0 auto;
}

.view { display: none; }
.view.active { display: block; }

/* Buttons */
.btn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 6px;
  padding: 7px 12px;
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
}

.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-hover); }
.btn.danger { color: var(--danger); border-color: #5c3030; }
.btn.sm { padding: 5px 10px; font-size: 12px; }

.chip {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  border-radius: 6px;
  padding: 4px 10px;
  font: inherit;
  font-size: 12px;
  cursor: pointer;
}

.chip:hover, .chip.active {
  color: var(--text);
  border-color: var(--accent);
  background: rgba(123, 108, 246, 0.12);
}

/* Stats */
.stat-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 16px;
}

.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 12px 14px;
}

.stat-label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.stat-value { font-size: 22px; font-weight: 600; margin-top: 4px; }

/* Panels */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
}

.panel-head {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  font-weight: 600;
}

.panel-body { padding: 14px; }

.split {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 12px;
  min-height: calc(100vh - 180px);
}

.split > .panel { display: flex; flex-direction: column; min-height: 0; }

.list-scroll { overflow: auto; flex: 1; }

.list-item {
  display: block;
  width: 100%;
  text-align: left;
  border: none;
  border-bottom: 1px solid var(--border);
  background: transparent;
  color: inherit;
  padding: 10px 14px;
  cursor: pointer;
  font: inherit;
}

.list-item:hover { background: var(--surface-2); }
.list-item.active { background: rgba(123, 108, 246, 0.1); box-shadow: inset 2px 0 0 var(--accent); }

.list-item-title { font-weight: 500; font-size: 13px; }
.list-item-meta { font-size: 11px; color: var(--muted); margin-top: 2px; }

/* Tables */
.table-wrap { overflow: auto; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

th, td {
  text-align: left;
  padding: 8px 14px;
  border-bottom: 1px solid var(--border);
}

th {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  background: var(--surface-2);
}

tbody tr:hover { background: rgba(255, 255, 255, 0.02); }

.table-link {
  appearance: none;
  border: none;
  background: none;
  color: var(--text);
  font: inherit;
  cursor: pointer;
  padding: 0;
  text-align: left;
}

.table-link:hover { color: var(--accent); }

/* Forms */
.field { display: grid; gap: 4px; margin-bottom: 12px; }
.field span,
.field label {
  font-size: 12px;
  color: var(--muted);
  font-weight: 500;
}

.field input,
.field select,
.field textarea,
.search-input,
.nav-mobile select {
  width: 100%;
  padding: 8px 10px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 13px;
}

.field textarea {
  min-height: 96px;
  resize: vertical;
  font-family: var(--mono);
  font-size: 12px;
}

.field input:focus,
.field select:focus,
.field textarea:focus,
.search-input:focus {
  outline: none;
  border-color: var(--accent);
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 12px;
}

.form-grid .full { grid-column: 1 / -1; }

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-bottom: 12px;
}

.search-input { margin-bottom: 0; }

.filter-row { display: flex; flex-wrap: wrap; gap: 6px; }

/* Editor */
.editor-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
}

.editor-head h2 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
}

.editor-head code { font-size: 11px; }

.tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--border);
  padding: 0 10px;
}

.tab {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 12px;
  font-weight: 500;
  padding: 10px 12px;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}

.tab:hover { color: var(--text); }
.tab.active { color: var(--text); border-bottom-color: var(--accent); }

.tab-panel { display: none; padding: 14px; overflow: auto; flex: 1; }
.tab-panel.active { display: block; }

.section-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 16px 0 8px;
}

.section-row:first-child { margin-top: 0; }
.section-row h3 { margin: 0; font-size: 13px; font-weight: 600; }

.card-row {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 12px;
  margin-bottom: 8px;
  background: var(--bg);
}

.card-row-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
  font-size: 13px;
  font-weight: 500;
}

.import-box {
  border: 1px dashed var(--border);
  border-radius: 6px;
  padding: 12px;
  margin-bottom: 12px;
}

.import-preview {
  margin-top: 8px;
  padding: 10px;
  background: var(--surface-2);
  border-radius: 6px;
  font-size: 12px;
  color: var(--muted);
}

.badge {
  display: inline-block;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 2px 6px;
  border-radius: 4px;
  background: var(--surface-2);
  color: var(--muted);
}

.badge-verified { color: var(--success); }
.badge-partial, .badge-needsReview { color: var(--warning); }
.badge-broken { color: var(--danger); }
.badge-multi { color: #c4baff; }
.badge-single { color: var(--success); }

.unsaved {
  font-size: 11px;
  color: var(--warning);
  font-weight: 600;
}

.empty {
  padding: 32px 16px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
}

.validation {
  margin-top: 12px;
  padding: 12px 14px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 13px;
}

.validation.ok { border-color: #2d5a3d; }
.validation.err { border-color: #5c3030; }
.validation ul { margin: 8px 0 0; padding-left: 18px; }
.validation .error { color: var(--danger); }
.validation .warn { color: var(--warning); }

.toast {
  position: fixed;
  bottom: 16px;
  right: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 10px 14px;
  border-radius: 6px;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s;
  z-index: 100;
  max-width: 320px;
}

.toast.show { opacity: 1; }

.file-btn { position: relative; overflow: hidden; }
.file-btn input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }

.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

@media (max-width: 900px) {
  .stat-row { grid-template-columns: repeat(2, 1fr); }
  .split { grid-template-columns: 1fr; }
  .form-grid, .two-col { grid-template-columns: 1fr; }
  .nav-desktop { display: none; }
  .nav-mobile { display: block; }
  .host-tag { display: none; }
}

@media (max-width: 520px) {
  .stat-row { grid-template-columns: 1fr; }
  .page-bar { flex-direction: column; }
}
