:root {
  --bg: #e8e5de;
  --paper: #f6f3ec;
  --paper-strong: #fffdf8;
  --ink: #17201e;
  --muted: #6d756f;
  --rule: #c8c5bc;
  --accent: #d35238;
  --accent-deep: #993620;
  --teal: #176b69;
  --teal-soft: #d8e9e5;
  --gold: #b68a37;
  --shadow: 0 18px 45px rgba(34, 43, 39, 0.13);
  --sans: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --serif: Iowan Old Style, Baskerville, "Times New Roman", serif;
}

* { box-sizing: border-box; }

html, body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
}

body {
  color: var(--ink);
  background:
    radial-gradient(circle at 15% 5%, rgba(211, 82, 56, 0.08), transparent 25%),
    linear-gradient(125deg, #ebe8e1, #e0ded8);
  font-family: var(--sans);
}

button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: 0.45; }

.masthead {
  height: 76px;
  display: grid;
  grid-template-columns: minmax(260px, 1fr) auto minmax(260px, 1fr);
  align-items: center;
  gap: 22px;
  padding: 0 22px;
  border-bottom: 1px solid #aaa9a2;
  background: rgba(246, 243, 236, 0.94);
  backdrop-filter: blur(14px);
}

.masthead h1 {
  margin: 2px 0 0;
  font-family: var(--serif);
  font-size: 27px;
  line-height: 1;
  letter-spacing: -0.035em;
}

.masthead h1 i { color: var(--accent); font-weight: 400; }

.eyebrow,
.field > span,
.section-heading,
.database-stats {
  font-size: 9px;
  font-weight: 750;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.eyebrow { color: var(--muted); }
.eyebrow.accent { color: var(--accent-deep); }

.database-stats {
  color: var(--muted);
  text-align: center;
}

.header-actions {
  display: flex;
  justify-content: flex-end;
  gap: 7px;
}

button {
  min-height: 32px;
  padding: 6px 11px;
  color: var(--ink);
  border: 1px solid #b5b2aa;
  border-radius: 3px;
  background: rgba(255, 253, 248, 0.85);
  font-size: 11px;
  font-weight: 650;
  transition: border-color 120ms, background 120ms, transform 120ms;
}

button:hover:not(:disabled) {
  border-color: #777d78;
  background: #fff;
}

button:active:not(:disabled) { transform: translateY(1px); }

button.primary {
  color: white;
  border-color: var(--teal);
  background: var(--teal);
}

button.primary:hover:not(:disabled) {
  border-color: #0d514f;
  background: #0d5b59;
}

button.quiet { background: transparent; }
button.full { width: 100%; }

.workspace {
  height: calc(100% - 76px);
  display: grid;
  grid-template-columns: 304px minmax(420px, 1fr) 326px;
}

.sidebar {
  min-height: 0;
  padding: 19px 17px 30px;
  overflow-y: auto;
  background: rgba(246, 243, 236, 0.96);
  scrollbar-width: thin;
}

.search-sidebar { border-right: 1px solid var(--rule); }
.detail-sidebar { border-left: 1px solid var(--rule); }

.panel-intro h2,
.detail-sidebar h2,
.canvas-empty h2 {
  margin: 5px 0 8px;
  font-family: var(--serif);
  font-size: 25px;
  line-height: 1;
  letter-spacing: -0.025em;
}

.panel-intro p,
.panel-copy,
.canvas-empty p,
.inspector-placeholder p,
dialog p {
  margin: 0 0 15px;
  color: var(--muted);
  font-family: var(--serif);
  font-size: 13px;
  line-height: 1.45;
}

.stack { display: grid; gap: 9px; }
.stack.compact { gap: 8px; padding-top: 11px; }

.field {
  position: relative;
  display: grid;
  min-width: 0;
  gap: 5px;
}

.field > span { color: var(--muted); }

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.field-row.three { grid-template-columns: 68px 1fr 1fr; }
.field-row .span-two { grid-column: span 2; }

input, select, textarea {
  width: 100%;
  min-width: 0;
  color: var(--ink);
  border: 1px solid #aaa9a2;
  border-radius: 3px;
  outline: none;
  background: var(--paper-strong);
  font-size: 12px;
}

input, select { height: 36px; padding: 0 9px; }
textarea { padding: 9px; resize: vertical; line-height: 1.4; }

input:focus, select:focus, textarea:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 2px rgba(23, 107, 105, 0.13);
}

.autocomplete-menu {
  position: absolute;
  z-index: 20;
  top: calc(100% + 3px);
  right: 0;
  left: 0;
  display: none;
  max-height: 230px;
  padding: 4px;
  overflow-y: auto;
  border: 1px solid #9d9e98;
  border-radius: 3px;
  background: var(--paper-strong);
  box-shadow: 0 14px 30px rgba(32, 40, 37, 0.2);
}

.autocomplete-menu.open { display: grid; }

.autocomplete-option {
  min-height: 34px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 6px 8px;
  border: 0;
  border-radius: 2px;
  background: transparent;
  text-align: left;
}

.autocomplete-option:hover,
.autocomplete-option.active {
  background: var(--teal-soft);
}

.autocomplete-option b {
  overflow: hidden;
  font-family: var(--serif);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.autocomplete-option small {
  color: var(--muted);
  font-size: 9px;
  white-space: nowrap;
}

.search-field input { height: 42px; font-size: 13px; }

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin: 18px 0 7px;
  color: var(--muted);
}

.section-heading::after {
  height: 1px;
  flex: 1;
  order: 1;
  content: "";
  background: var(--rule);
}

.section-heading span:last-child { order: 2; }

.record-list {
  max-height: 292px;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  list-style: none;
}

.record-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  padding: 10px 5px;
  border-bottom: 1px solid #d7d3ca;
}

.record-main {
  padding: 0;
  overflow: hidden;
  border: 0;
  background: transparent;
  text-align: left;
}

.record-main:hover { background: transparent !important; }
.record-main b, .record-main small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.record-main b { font-family: var(--serif); font-size: 14px; }
.record-main small { margin-top: 3px; color: var(--muted); font-size: 9px; letter-spacing: 0.06em; text-transform: uppercase; }

.record-add {
  width: 27px;
  min-height: 27px;
  align-self: center;
  padding: 0;
  border-radius: 50%;
}

.empty-copy {
  margin: 7px 0;
  color: var(--muted);
  font-family: var(--serif);
  font-size: 12px;
  line-height: 1.4;
}

.control-section {
  margin-top: 14px;
  border-top: 1px solid var(--rule);
}

.control-section summary {
  padding: 13px 0 4px;
  font-size: 10px;
  font-weight: 750;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  cursor: pointer;
}

.graph-desk {
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background:
    linear-gradient(rgba(38, 51, 47, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(38, 51, 47, 0.035) 1px, transparent 1px),
    #deddd7;
  background-size: 28px 28px;
}

#graph {
  position: absolute;
  inset: 47px 0 104px;
}

.graph-toolbar {
  position: absolute;
  z-index: 4;
  top: 0;
  left: 0;
  right: 0;
  height: 47px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: 0 10px;
  border-bottom: 1px solid rgba(151, 151, 145, 0.8);
  background: rgba(239, 237, 231, 0.9);
  backdrop-filter: blur(8px);
}

.tool-group { display: flex; gap: 5px; }
.tool-group:last-child { justify-content: flex-end; }
.tool-group button { min-height: 29px; padding: 4px 9px; background: rgba(255,255,255,0.45); }
.tool-group select { width: 130px; height: 29px; font-size: 10px; }

.canvas-empty {
  position: absolute;
  z-index: 2;
  top: 50%;
  left: 50%;
  width: min(380px, 75%);
  transform: translate(-50%, -55%);
  text-align: center;
  pointer-events: none;
}

.canvas-empty.hidden { display: none; }
.orbital-mark { display: block; color: var(--accent); font-size: 58px; font-weight: 200; }
.orbital-mark.small { font-size: 34px; }

.selection-dock {
  position: absolute;
  z-index: 5;
  right: 12px;
  bottom: 34px;
  left: 12px;
  min-height: 61px;
  display: grid;
  grid-template-columns: auto minmax(80px, 1fr) auto;
  align-items: center;
  gap: 13px;
  padding: 9px 11px;
  border: 1px solid #a9aaa5;
  border-radius: 5px;
  background: rgba(252, 250, 245, 0.94);
  box-shadow: var(--shadow);
  backdrop-filter: blur(9px);
}

.selection-summary { min-width: 88px; }
.selection-summary span, .selection-summary strong { display: block; }
.selection-summary strong { margin-top: 3px; font-family: var(--serif); font-size: 12px; }
.selection-chips { display: flex; gap: 5px; overflow-x: auto; }

.selection-chip {
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 5px;
  padding: 5px 7px;
  border-radius: 20px;
  color: #164f4d;
  background: var(--teal-soft);
  font-size: 10px;
}

.selection-chip button {
  width: 16px;
  min-height: 16px;
  padding: 0;
  border: 0;
  background: transparent;
}

.selection-actions { display: flex; gap: 5px; }
.selection-actions button { white-space: nowrap; }

.status-bar {
  position: absolute;
  z-index: 4;
  right: 0;
  bottom: 0;
  left: 0;
  height: 27px;
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 0 12px;
  color: var(--muted);
  border-top: 1px solid #b9b8b1;
  background: rgba(231, 229, 223, 0.96);
  font-size: 10px;
}

.status-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--teal); }
.status-bar.busy .status-dot { background: var(--gold); animation: pulse 700ms infinite alternate; }
.status-bar.error .status-dot { background: var(--accent); }
#visible-stats { margin-left: auto; }

@keyframes pulse { to { opacity: 0.3; } }

.tabs {
  position: sticky;
  z-index: 2;
  top: -19px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  margin: -19px -17px 19px;
  background: var(--paper);
}

.tab {
  min-height: 43px;
  border: 0;
  border-bottom: 1px solid var(--rule);
  border-radius: 0;
  background: transparent;
  font-size: 9px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.tab.active {
  color: var(--accent-deep);
  border-bottom: 2px solid var(--accent);
}

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

.inspector-placeholder { padding: 60px 14px 0; text-align: center; }

.record-heading {
  margin-bottom: 13px;
  padding-bottom: 13px;
  border-bottom: 1px solid var(--rule);
}

.record-heading h2 { overflow-wrap: anywhere; }
.record-badges { display: flex; flex-wrap: wrap; gap: 5px; }
.badge { padding: 3px 6px; color: #245654; border: 1px solid #9bb6b1; border-radius: 20px; font-size: 9px; }
.badge.edge { color: #823524; border-color: #d1a092; }

.record-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin-bottom: 15px;
}

.record-table { margin: 0; }
.record-row {
  display: grid;
  grid-template-columns: 92px minmax(0, 1fr);
  gap: 8px;
  padding: 7px 0;
  border-bottom: 1px solid #dedad1;
}
.record-row dt { color: var(--muted); font-size: 9px; letter-spacing: 0.06em; text-transform: uppercase; }
.record-row dd { margin: 0; overflow-wrap: anywhere; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 10px; line-height: 1.45; white-space: pre-wrap; }

.endpoint-button {
  width: 100%;
  margin: 4px 0;
  text-align: left;
}

.analysis-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px;
}
.analysis-grid button { min-height: 65px; text-align: left; }
.analysis-grid b, .analysis-grid span { display: block; }
.analysis-grid b { font-family: var(--serif); font-size: 13px; }
.analysis-grid span { margin-top: 4px; color: var(--muted); font-size: 9px; }
.button-stack { display: grid; gap: 6px; }

.analysis-result pre {
  max-height: 300px;
  padding: 10px;
  overflow: auto;
  border: 1px solid var(--rule);
  background: #eeece6;
  font-size: 9px;
  line-height: 1.45;
  white-space: pre-wrap;
}

.saved-list { display: grid; gap: 5px; margin-top: 8px; }
.saved-record { display: grid; grid-template-columns: 1fr auto; gap: 5px; }
.saved-record button:first-child { overflow: hidden; text-overflow: ellipsis; text-align: left; white-space: nowrap; }

dialog {
  width: min(440px, calc(100% - 32px));
  padding: 0;
  border: 1px solid #9e9f98;
  border-radius: 5px;
  background: var(--paper);
  box-shadow: 0 28px 90px rgba(20, 26, 24, 0.35);
}
dialog::backdrop { background: rgba(26, 31, 29, 0.52); backdrop-filter: blur(3px); }
.dialog-card { position: relative; display: grid; gap: 12px; padding: 27px; }
.dialog-card h2 { margin: 0; font-family: var(--serif); font-size: 28px; }
.dialog-close { position: absolute; top: 10px; right: 10px; width: 30px; padding: 0; border: 0; background: transparent; font-size: 21px; }

.toast-region { position: fixed; z-index: 20; right: 18px; bottom: 18px; display: grid; gap: 8px; }
.toast { max-width: 350px; padding: 11px 14px; color: white; border-radius: 4px; background: #213c39; box-shadow: var(--shadow); font-size: 11px; }
.toast.error { background: #8e3827; }

@media (max-width: 1120px) {
  .workspace { grid-template-columns: 270px minmax(390px, 1fr) 290px; }
  .selection-actions button { padding: 5px 7px; font-size: 9px; }
}

@media (max-width: 840px) {
  html, body { overflow: auto; }
  .masthead { position: sticky; z-index: 10; top: 0; grid-template-columns: 1fr auto; }
  .database-stats { display: none; }
  .workspace { height: auto; min-height: calc(100vh - 76px); grid-template-columns: 1fr; }
  .sidebar { max-height: none; border: 0; }
  .search-sidebar { order: 2; }
  .graph-desk { order: 1; height: 72vh; min-height: 540px; }
  .detail-sidebar { order: 3; }
  .selection-dock { grid-template-columns: 1fr; }
  .selection-actions { overflow-x: auto; }
}
