/* ============================================================
   Data Model Explorer — design tokens
   Palette: academic standards-document feel — deep indigo ink,
   warm brass accent for the one "seal" color, warm paper neutrals.
   ============================================================ */

:root {
  --bg: #f5f3ee;
  --surface: #ffffff;
  --surface-2: #eeece4;
  --border: #ddd8cb;
  --ink: #211f2e;
  --muted: #6c6a7a;
  --faint: #9b98a8;

  --accent: #a8702c;       /* brass — the one warm accent */
  --accent-ink: #6e4a1c;
  --accent-soft: #f1e3cd;

  --indigo: #33436e;       /* structural / domain color */
  --indigo-soft: #e4e8f1;

  --link-explicit: #33436e;
  --link-inferred: #a8702c;

  /* Graph-bubble fills: deliberately fixed (not swapped per theme) so a
     circle reads as a soft, neutral light-grey chip regardless of theme,
     with dark-grey text carrying the contrast instead of the fill color.
     Lightness (not hue) is what tells the three kinds apart. */
  --node-domain: #dadde3;   /* domain bubbles — light grey */
  --node-entity: #e4e6e9;   /* individual-entity bubbles — slightly lighter grey */
  --node-self: #c6c8cf;     /* the entity a relationship graph is centered on — a touch darker, "you are here" */
  --node-text: #34343c;     /* dark grey label color inside any graph bubble */
  --node-text-halo: rgba(255, 255, 255, 0.65); /* soft light outline keeping the label readable over edges/overlaps */

  --good: #2f7a4f;
  --good-soft: #e2f1e7;
  --warn: #a8702c;
  --crit: #a5402f;
  --crit-soft: #f6e4e1;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --shadow-sm: 0 1px 2px rgba(33, 31, 46, 0.06), 0 1px 1px rgba(33, 31, 46, 0.04);
  --shadow-md: 0 8px 24px rgba(33, 31, 46, 0.10), 0 2px 6px rgba(33, 31, 46, 0.06);

  --font-display: "Source Serif 4", Georgia, "Times New Roman", serif;
  --font-body: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #15161d;
    --surface: #1c1e28;
    --surface-2: #232532;
    --border: #34364420;
    --border: #34364a;
    --ink: #ece9e2;
    --muted: #a7a5b5;
    --faint: #6c6a7a;

    --accent: #d29a55;
    --accent-ink: #f0d3a8;
    --accent-soft: #3a3020;

    --indigo: #93a6d6;
    --indigo-soft: #232941;

    --link-explicit: #93a6d6;
    --link-inferred: #d29a55;

    --good: #5fbf87;
    --good-soft: #1c3226;
    --warn: #d29a55;
    --crit: #e08874;
    --crit-soft: #3a2420;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 10px 30px rgba(0, 0, 0, 0.45);
  }
}
:root[data-theme="dark"] {
  --bg: #15161d;
  --surface: #1c1e28;
  --surface-2: #232532;
  --border: #34364a;
  --ink: #ece9e2;
  --muted: #a7a5b5;
  --faint: #6c6a7a;

  --accent: #d29a55;
  --accent-ink: #f0d3a8;
  --accent-soft: #3a3020;

  --indigo: #93a6d6;
  --indigo-soft: #232941;

  --link-explicit: #93a6d6;
  --link-inferred: #d29a55;

  --good: #5fbf87;
  --good-soft: #1c3226;
  --warn: #d29a55;
  --crit: #e08874;
  --crit-soft: #3a2420;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 10px 30px rgba(0, 0, 0, 0.45);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 14px;
  line-height: 1.5;
}
h1, h2, h3 { font-family: var(--font-display); font-weight: 600; text-wrap: balance; margin: 0; }
code, .mono { font-family: var(--font-mono); }
a { color: inherit; }
button { font-family: inherit; }

#app { display: flex; flex-direction: column; min-height: 100vh; }

/* ---------------- topbar ---------------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 10px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
  flex-wrap: wrap;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px 2px;
  color: inherit;
  flex-shrink: 0;
}
.brand-mark {
  font-size: 22px;
  color: var(--accent);
  line-height: 1;
}
.brand-text { display: flex; flex-direction: column; align-items: flex-start; }
.brand-name { font-family: var(--font-display); font-weight: 600; font-size: 16px; }
.brand-sub { font-size: 11px; color: var(--muted); }

.crumbs {
  flex: 1 1 260px;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 6px;
  overflow-x: auto;
  white-space: nowrap;
  scrollbar-width: thin;
}
.crumbs::-webkit-scrollbar { height: 4px; }
.crumb {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 13px;
  padding: 4px 6px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
}
.crumb:hover { background: var(--surface-2); color: var(--ink); }
.crumb.current { color: var(--ink); font-weight: 600; cursor: default; }
.crumb.current:hover { background: none; }
.crumb-sep { color: var(--faint); font-size: 12px; }

.folder-btn {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  font-family: var(--font-body);
  cursor: pointer;
  max-width: 220px;
}
/* An author rule's `display` beats the UA default [hidden] rule at equal
   specificity, so without this the button would stay visible in browsers
   that don't support the folder picker even after JS sets `hidden = true`. */
.folder-btn[hidden] { display: none; }
.folder-btn:hover { border-color: var(--indigo); color: var(--ink); }
.folder-btn .name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 140px;
}
.folder-btn.attention { border-color: var(--accent); color: var(--accent-ink); background: var(--accent-soft); }

.search { position: relative; flex: 0 1 280px; min-width: 180px; }
.search input {
  width: 100%;
  padding: 8px 12px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--ink);
  font-size: 13px;
}
.search input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.search-results {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  max-height: 360px;
  overflow-y: auto;
  z-index: 30;
}
.search-result {
  display: block;
  width: 100%;
  text-align: left;
  padding: 9px 12px;
  background: none;
  border: none;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  color: inherit;
}
.search-result:last-child { border-bottom: none; }
.search-result:hover, .search-result.active { background: var(--surface-2); }
.search-result .r-title { font-weight: 600; font-size: 13px; }
.search-result .r-meta { font-size: 11px; color: var(--muted); margin-top: 1px; }
.search-empty { padding: 12px; color: var(--muted); font-size: 13px; }

/* ---------------- layout ---------------- */
.layout { flex: 1; display: flex; min-height: 0; }

main {
  flex: 1;
  min-width: 0;
  overflow-y: auto;
  padding: 24px clamp(16px, 3vw, 40px) 60px;
}

.statusbar {
  border-top: 1px solid var(--border);
  background: var(--surface);
  padding: 6px 20px;
  font-size: 11px;
  color: var(--faint);
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
}

/* ---------------- loading / error ---------------- */
.loading-state, .error-state, .start-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 80px 20px;
  color: var(--muted);
  text-align: center;
}
.error-state h2 { color: var(--crit); }
.error-state code { background: var(--surface-2); padding: 2px 6px; border-radius: 4px; }
.start-state h2 { color: var(--ink); font-size: 20px; }
.start-state p { max-width: 46ch; }
.start-state code { background: var(--surface-2); padding: 2px 6px; border-radius: 4px; }
.start-state .start-icon {
  font-size: 34px;
  color: var(--indigo);
  width: 64px;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--surface-2);
  border: 1px solid var(--border);
}
.spinner {
  width: 28px; height: 28px;
  border-radius: 50%;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 2s; } }

/* ---------------- overview ---------------- */
.view-header { margin-bottom: 18px; }
.view-header h1 { font-size: 22px; }
.view-header p { color: var(--muted); margin: 6px 0 0; max-width: 62ch; }

.stat-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 10px;
  margin: 18px 0 26px;
}
.stat-tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 14px;
}
.stat-tile .n {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 22px;
  font-weight: 600;
  color: var(--indigo);
}
.stat-tile .l { font-size: 11.5px; color: var(--muted); margin-top: 2px; }

.graph-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 10px;
  box-shadow: var(--shadow-sm);
  margin-bottom: 26px;
}
.graph-panel svg { display: block; width: 100%; height: auto; }

.zoom-controls {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 2;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.zoom-controls button {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink);
  font-size: 15px;
  line-height: 1;
  font-weight: 600;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
}
.zoom-controls button:hover { background: var(--surface-2); }
.zoom-controls button[data-zoom="reset"] { font-size: 12px; }
.graph-caption { font-size: 12px; color: var(--muted); padding: 8px 6px 2px; }

.node { cursor: pointer; }
.node circle { stroke: var(--surface); stroke-width: 2px; transition: r 0.12s ease; }
.node:hover circle { filter: brightness(1.08); }
.node text {
  font-family: var(--font-display);
  font-size: 11px;
  fill: var(--ink);
  pointer-events: none;
}
.edge-explicit { stroke: var(--link-explicit); }
.edge-inferred { stroke: var(--link-inferred); stroke-dasharray: 3 3; }
.legend { display: flex; gap: 16px; flex-wrap: wrap; padding: 2px 6px 8px; font-size: 11.5px; color: var(--muted); align-items: center; }
.legend span.swatch { display: inline-block; width: 16px; height: 0; border-top: 2px solid; vertical-align: middle; margin-right: 5px; }

.view-toggle {
  display: inline-flex;
  background: var(--surface-2);
  border-radius: 999px;
  padding: 3px;
  gap: 2px;
  margin: 2px 6px 10px;
}
.view-toggle button {
  border: none;
  background: transparent;
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  padding: 6px 14px;
  border-radius: 999px;
  cursor: pointer;
}
.view-toggle button.active { background: var(--indigo); color: #fff; }
.view-toggle button:not(.active):hover { color: var(--ink); }


.domain-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 12px;
}
.domain-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 14px 16px;
  cursor: pointer;
  text-align: left;
  box-shadow: var(--shadow-sm);
}
.domain-card:hover { border-color: var(--indigo); box-shadow: var(--shadow-md); }
.domain-card h3 { font-size: 14.5px; margin-bottom: 4px; }
.domain-card p { font-size: 12px; color: var(--muted); margin: 0 0 10px; max-width: 46ch; }
.domain-card .badge { }

/* ---------------- badges & chips ---------------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
}
.badge.indigo { background: var(--indigo-soft); color: var(--indigo); }
.badge.brass { background: var(--accent-soft); color: var(--accent-ink); }
.badge.required { background: var(--crit-soft); color: var(--crit); }

/* ---------------- domain / entity list ---------------- */
.entity-toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 14px; flex-wrap: wrap; }
.entity-toolbar input {
  flex: 1 1 220px;
  padding: 7px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink);
  font-size: 13px;
}
.entity-list { display: grid; gap: 8px; }
.entity-row {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  cursor: pointer;
  text-align: left;
}
.entity-row:hover { border-color: var(--indigo); }
.entity-row .name { font-weight: 600; font-size: 13.5px; flex: 1; min-width: 0; }
.entity-row .name .fieldname { color: var(--muted); font-family: var(--font-mono); font-size: 11.5px; font-weight: 400; margin-left: 6px; }
.entity-row .counts { display: flex; gap: 6px; flex-shrink: 0; }

/* ---------------- entity detail ---------------- */
.entity-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; margin-bottom: 4px; }
.entity-header h1 { font-size: 21px; }
.entity-title-meta { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 6px; }
.entity-desc { color: var(--muted); max-width: 68ch; margin: 10px 0 22px; }
.entity-desc.empty { font-style: italic; color: var(--faint); }

.entity-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr);
  gap: 20px;
  align-items: start;
}
@media (max-width: 860px) { .entity-grid { grid-template-columns: 1fr; } }

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}
.panel-head h2 { font-size: 14px; font-family: var(--font-body); font-weight: 700; letter-spacing: 0.01em; }
.panel-body { padding: 4px 0; }
.panel-body.pad { padding: 14px 16px; }

.table-scroll { overflow-x: auto; }
table.attrs { width: 100%; min-width: 480px; border-collapse: collapse; font-size: 12.5px; }
table.attrs th {
  text-align: left;
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--faint);
  padding: 8px 16px 6px;
  border-bottom: 1px solid var(--border);
}
table.attrs td { padding: 8px 16px; border-bottom: 1px solid var(--border); vertical-align: top; }
table.attrs tr:last-child td { border-bottom: none; }
table.attrs .fname { font-family: var(--font-mono); font-weight: 600; }
table.attrs .ftype { font-family: var(--font-mono); color: var(--indigo); white-space: nowrap; }
table.attrs .fdesc { color: var(--muted); max-width: 40ch; }
table.attrs .fenum { display: block; margin-top: 3px; color: var(--faint); font-size: 11px; }

.rel-list { list-style: none; margin: 0; padding: 0; }
.rel-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 10px 16px;
  background: none;
  border: none;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  color: inherit;
}
.rel-item:last-child { border-bottom: none; }
.rel-item:hover { background: var(--surface-2); }
.rel-field { font-family: var(--font-mono); font-weight: 600; font-size: 12.5px; }
.rel-arrow { color: var(--faint); margin: 0 6px; }
.rel-target { font-weight: 600; font-size: 12.5px; }
.rel-target .domain { color: var(--muted); font-weight: 400; font-size: 11px; }
.rel-desc { color: var(--muted); font-size: 11.5px; margin-top: 3px; }
.rel-meta { margin-top: 4px; display: flex; gap: 6px; flex-wrap: wrap; }

.section-label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--faint); padding: 10px 16px 4px; }

.empty-note { padding: 14px 16px; color: var(--faint); font-size: 12.5px; font-style: italic; }

.ego-panel { margin-top: 20px; }
.ego-panel svg { display: block; width: 100%; height: auto; }

/* ---------------- extends chip row ---------------- */
.extends-row { display: flex; align-items: center; gap: 8px; margin: 8px 0 18px; flex-wrap: wrap; font-size: 12.5px; color: var(--muted); }
.extends-row button { background: var(--indigo-soft); color: var(--indigo); border: none; border-radius: 999px; padding: 3px 10px; font-size: 12px; font-weight: 600; cursor: pointer; }

@media (max-width: 720px) {
  main { padding: 18px 14px 60px; }
}
