/* Admin console. */

body { overflow: auto; }

.admin-shell { min-height: 100vh; display: flex; flex-direction: column; }

.tabs {
  display: flex;
  gap: var(--space-4);
  padding: 0 var(--space-4);
  border-bottom: var(--rule-width) solid var(--rule-strong);
  background: var(--paper);
  position: sticky;
  top: 0;
  z-index: var(--z-nav);
}
.tab {
  height: var(--nav-height);
  padding: 0;
  font-family: var(--font-ui);
  font-size: var(--text-xs);
  font-weight: var(--weight-normal);
  color: var(--ink-muted);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  transition: color var(--duration) var(--ease), border-color var(--duration) var(--ease);
}
.tab:hover { color: var(--ink); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }

.tab-page { padding: var(--space-4); display: none; }
.tab-page.active { display: block; }

/* ------------------------------------------------------------------- metrics
   A ruled register, not a row of cards. The 1px gaps are the grid background
   showing through, so every division is a hairline. */

.metrics {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: var(--rule-width);
  margin-bottom: var(--space-5);
  background: var(--rule);
  border: var(--rule-width) solid var(--rule);
}
.metric {
  padding: var(--space-3);
  background: var(--paper);
}
.metric .label {
  font-family: var(--font-ui);
  font-size: var(--text-2xs);
  font-weight: var(--weight-normal);
  letter-spacing: var(--tracking-none);
  color: var(--ink-faint);
}
.metric .value {
  margin-top: var(--space-1);
  font-family: var(--font-ui);
  font-size: var(--text-2xl);
  font-weight: var(--weight-normal);
  letter-spacing: var(--tracking-tight);
  line-height: var(--leading-tight);
  font-variant-numeric: tabular-nums;
}
.metric .value.small-value { font-size: var(--text-base); }
.metric .note { margin-top: var(--space-1); font-size: var(--text-2xs); color: var(--ink-muted); overflow-wrap: break-word; }
.metric.accent .value { color: var(--accent); }

.grid-2 { display: grid; grid-template-columns: minmax(0, 1.55fr) minmax(0, 1fr); gap: var(--space-4); align-items: start; }
@media (max-width: 1080px) { .grid-2 { grid-template-columns: minmax(0, 1fr); } }

.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-3);
  padding-bottom: var(--space-2);
  border-bottom: var(--rule-width) solid var(--rule-strong);
}
.section-head h2 {
  margin: 0;
  font-family: var(--font-ui);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
}
.section-head p {
  margin: var(--space-1) 0 0;
  font-family: var(--font-prose);
  font-size: var(--text-xs);
  color: var(--ink-muted);
}

/* -------------------------------------------------------------- graph labels */

.graph-tags { display: flex; flex-wrap: wrap; gap: var(--space-1); }
.graph-tag {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: 0 var(--space-1);
  font-family: var(--font-ui);
  font-size: var(--text-2xs);
  border: var(--rule-width) solid var(--rule);
  border-radius: var(--radius);
  color: var(--ink-faint);
}
.graph-tag.filled { color: var(--ink); border-color: var(--rule-strong); }
.graph-tag i { width: var(--mark-status); height: var(--mark-status); flex: none; }

/* -------------------------------------------------------------- graph catalog */

.catalog-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: var(--rule-width);
  background: var(--rule);
  border: var(--rule-width) solid var(--rule);
}
.catalog-card {
  padding: var(--space-2) var(--space-3);
  background: var(--paper);
}
.catalog-card h5 {
  margin: 0 0 var(--space-1);
  font-family: var(--font-ui);
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  display: flex;
  align-items: center;
  gap: var(--space-2);
}
.catalog-card h5 i { width: var(--mark-swatch); height: var(--mark-swatch); flex: none; }
.catalog-card p {
  margin: 0;
  font-family: var(--font-prose);
  font-size: var(--text-xs);
  line-height: var(--leading-normal);
  color: var(--ink-muted);
}
.catalog-card-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  margin-top: var(--space-2);
}
.catalog-card-hidden { background: var(--paper-sunken); }
.catalog-card-hidden h5, .catalog-card-hidden p { color: var(--ink-faint); }

/* Optional features are a handful, not eighteen, so the cards size to their content
   rather than stretching a shared grid whose empty cells would show as bare rule. */
.feature-grid { display: flex; flex-wrap: wrap; gap: var(--space-3); }
.feature-grid .catalog-card {
  flex: 1 1 300px;
  max-width: 440px;
  border: var(--rule-width) solid var(--rule);
}

/* ------------------------------------------------------------------ mcp list */

.mcp-card {
  padding: var(--space-3);
  margin-bottom: var(--space-2);
  border: var(--rule-width) solid var(--rule);
  border-left: 2px solid var(--rule-strong);
}
.mcp-card.connected { border-left-color: var(--status-ok); }
.mcp-card.error { border-left-color: var(--status-bad); }
.mcp-card .cmd {
  margin-top: var(--space-2);
  padding: var(--space-1) var(--space-2);
  font-family: var(--font-ui);
  font-size: var(--text-2xs);
  color: var(--ink-muted);
  background: var(--paper-sunken);
  border-radius: var(--radius);
  overflow-x: auto;
  white-space: pre;
}

/* ------------------------------------------------------------ telegram cards
   Same shape as an MCP card. A code not yet redeemed is marked, since it is the
   one thing on the tab that is waiting on somebody. */

.link-card {
  padding: var(--space-3);
  margin-bottom: var(--space-2);
  border: var(--rule-width) solid var(--rule);
  border-left: 2px solid var(--status-ok);
}
.link-card.pending { border-left-color: var(--status-warn); }
.link-card .cmd {
  margin-top: var(--space-2);
  padding: var(--space-1) var(--space-2);
  font-family: var(--font-ui);
  font-size: var(--text-2xs);
  color: var(--ink-muted);
  background: var(--paper-sunken);
  border-radius: var(--radius);
  overflow-x: auto;
  white-space: pre;
}

.viz-embed { height: 60vh; min-height: 400px; border: var(--rule-width) solid var(--rule-strong); }

/* ----------------------------------------------------------- memory explorer
   The explorer is a workspace rather than a document, so it claims the height
   the nav, tabs and footer leave instead of a fixed slice of the viewport, and
   the stage keeps every column the inspector does not need. */

/* The shell is normally free to grow with the document. For this one tab it is
   pinned to the viewport, which is what gives the flex chain below a definite
   height to divide — without it a long entry list simply stretches the page. */
.admin-shell:has(.tab-page[data-page-id="memory"].active) { height: 100vh; }

.tab-page[data-page-id="memory"].active {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}
.memory-body {
  flex: 1;
  min-height: 0;
  align-items: stretch;
  grid-template-columns: minmax(0, 1fr) minmax(290px, 340px);
  /* An explicit bounded row; left to size itself, a long entry list would grow
     it and push the whole page into a scroll. */
  grid-template-rows: minmax(0, 1fr);
}
.memory-body .viz-embed { height: auto; min-height: 320px; }
.memory-side { min-height: 0; }
/* The inspector sizes to what it is showing; the entry list takes the rest. */
.memory-side > .panel:last-child {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}
.memory-side .entry-list { flex: 1; min-height: 0; }

/* Too narrow to sit side by side: fall back to the stacked, scrolling page. */
@media (max-width: 1080px) {
  .admin-shell:has(.tab-page[data-page-id="memory"].active) { height: auto; }
  .tab-page[data-page-id="memory"].active { display: block; }
  .memory-body { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto; }
  .memory-body .viz-embed { height: 60vh; }
  .memory-side .entry-list { max-height: 34vh; }
}

/* ----------------------------------------------------------------- knowledge */

.dropzone {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: var(--space-1);
  padding: var(--space-4);
  margin-bottom: var(--space-3);
  font-size: var(--text-xs);
  color: var(--ink-muted);
  border: var(--rule-width) dashed var(--rule-strong);
  border-radius: var(--radius);
  background: var(--paper);
  cursor: pointer;
  outline: none;
  transition: border-color var(--duration) var(--ease), background-color var(--duration) var(--ease);
}
.dropzone:hover, .dropzone:focus-visible { border-color: var(--ink); }
.dropzone.dragging { border-color: var(--accent); border-style: solid; background: var(--paper-sunken); }
.dropzone strong { font-weight: var(--weight-medium); color: var(--ink); }

.file-list { display: flex; flex-wrap: wrap; gap: var(--space-1); margin-bottom: var(--space-3); }
.file-tag {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: 0 var(--space-2);
  min-height: var(--control-h-sm);
  font-family: var(--font-ui);
  font-size: var(--text-2xs);
  border: var(--rule-width) solid var(--rule);
  border-radius: var(--radius);
}
.file-tag .drop {
  color: var(--ink-faint);
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.file-tag .drop:hover { color: var(--status-bad); }

.progress-block { margin-top: var(--space-3); }
.progress-block .bar {
  height: 4px;
  margin-top: var(--space-2);
  background: var(--paper-sunken);
  border: var(--rule-width) solid var(--rule);
  overflow: hidden;
}
.progress-block .bar i {
  display: block;
  width: 0;
  height: 100%;
  background: var(--accent);
  transition: width var(--duration) var(--ease);
}

.ingest-tally { display: flex; flex-wrap: wrap; gap: var(--space-1); margin-bottom: var(--space-3); }
#copy-summary { margin-top: var(--space-3); }

/* --------------------------------------------------------------- danger zone */

.danger-zone { border-left: 2px solid var(--status-bad); }
.danger-zone .section-head h2 { color: var(--status-bad); }
.warning-line {
  margin: var(--space-3) 0 0;
  font-family: var(--font-prose);
  font-size: var(--text-xs);
  line-height: var(--leading-normal);
  color: var(--status-warn);
}

.form-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 var(--space-3); }

/* --------------------------------------------------------------- live view */

#mem-live.active {
  color: var(--status-ok);
  border-color: var(--status-ok);
}
#mem-live.active::before {
  content: '';
  display: inline-block;
  width: 0.45em;
  height: 0.45em;
  margin-right: 0.45em;
  border-radius: 50%;
  background: var(--status-ok);
  vertical-align: 0.05em;
  box-shadow: 0 0 0 0 color-mix(in srgb, var(--status-ok) 55%, transparent);
  animation: mem-live-pulse 1.4s ease-out infinite;
}
@keyframes mem-live-pulse {
  0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--status-ok) 55%, transparent); }
  70% { box-shadow: 0 0 0 6px transparent; }
  100% { box-shadow: 0 0 0 0 transparent; }
}
#mem-title.live-on .mark { background: var(--status-ok); animation: mem-live-pulse 1.4s ease-out infinite; }

/* ---------------------------------------------------------------- responsive
   The console is a document, so it stays stacked and scrolling. Only the two
   things that cannot reflow — the tab strip and the data tables — are given a
   scroll of their own, rather than widening the page. */

@media (max-width: 820px) {
  .tabs {
    gap: var(--space-3);
    padding: 0 var(--space-3);
    overflow-x: auto;
    scrollbar-width: none;
  }
  .tabs::-webkit-scrollbar { display: none; }
  .tab { flex: none; white-space: nowrap; }

  .tab-page { padding: var(--space-3); }

  /* A section title and its actions stack rather than widen the page. */
  .section-head,
  .section-head .row { flex-wrap: wrap; }

  table.data {
    display: block;
    overflow-x: auto;
    white-space: nowrap;
  }

  .viz-embed { height: 52vh; min-height: 280px; }
  .memory-body .viz-embed { height: 52vh; }
}

@media (max-width: 620px) { .form-row { grid-template-columns: minmax(0, 1fr); } }
