/* ===========================================================================
   EUREKA AI — Product Shell browser UI (PRODUCT-IMPL-001).
   Dependency-free semantic styling. Swiss business minimalism, light-first.
   Tokens follow DESIGN.md (VERIFIED / PROPOSED). No gradients, no glass.
   ========================================================================== */

/* ---------------------------------------------------------------------------
   1. Design tokens
   --------------------------------------------------------------------------- */
:root {
  color-scheme: light;

  --accent: #245bce;
  --accent-hover: #1749af;
  --accent-contrast: #ffffff;

  --bg: #f8fafc;
  --bg-panel: #eef2f7;
  --bg-hover: #e6edf5;
  --bg-selected: #dce8f7;

  --border: #cdd7e3;
  --control-border: #738197;

  --text: #202d40;
  --text-muted: #515c6b;
  --text-dim: #5e6673;

  --success: #16794a;
  --warning: #8a4b00;
  --critical: #b42318;

  --font-ui: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: "Noto Sans Mono", "JetBrains Mono", "Fira Code", Consolas, ui-monospace, monospace;

  --shadow-light: 0 1px 2px rgb(32 45 64 / 8%);
  --shadow-overlay: 0 8px 24px rgb(32 45 64 / 14%);

  --r-sm: 4px;
  --r-ctl: 6px;
  --r-card: 8px;
  --r-panel: 12px;

  --rail-w: 64px;
}

:root[data-theme="dark"] {
  color-scheme: dark;

  --accent: #9bc3ff;
  --accent-hover: #c6ddff;
  --accent-contrast: #182234;

  --bg: #18212e;
  --bg-panel: #202c3c;
  --bg-hover: #2a394d;
  --bg-selected: #324765;

  --border: #42546c;
  --control-border: #8294ad;

  --text: #e8eef8;
  --text-muted: #b8c7da;
  --text-dim: #9cacc4;

  --success: #7bd8a4;
  --warning: #f2c14e;
  --critical: #ff9b92;

  --shadow-light: 0 1px 2px rgb(0 0 0 / 24%);
  --shadow-overlay: 0 8px 24px rgb(0 0 0 / 36%);
}

body[data-rail="expanded"] { --rail-w: 224px; }

/* ---------------------------------------------------------------------------
   2. Reset / base
   --------------------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font-ui);
  font-size: 16px;
  line-height: 24px;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); text-decoration: underline; }

h1, h2, h3, p { margin: 0; }

button { font-family: inherit; }

[hidden] { display: none !important; }

.mono, .row-id, .od-value.mono, .provenance-line .mono {
  font-family: var(--font-mono);
}

.num, .kpi-value, .metric-value, .sum-value, td.num {
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum";
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 2px;
}

/* ---------------------------------------------------------------------------
   3. Layout shell
   --------------------------------------------------------------------------- */
body {
  display: grid;
  grid-template-columns: var(--rail-w) 1fr;
  grid-template-rows: 56px 1fr auto;
  grid-template-areas:
    "header header"
    "rail   main"
    "rail   bottomnav";
  min-height: 100dvh;
}

.header { grid-area: header; }
.rail { grid-area: rail; }
.main { grid-area: main; }
.bottom-nav { grid-area: bottomnav; }

.skip-link {
  position: absolute;
  left: 8px;
  top: -40px;
  z-index: 100;
  padding: 8px 12px;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--r-ctl);
  transition: top 160ms ease-out;
}
.skip-link:focus { top: 8px; }

/* ---------------------------------------------------------------------------
   4. Header
   --------------------------------------------------------------------------- */
.header {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 16px;
  height: 56px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  min-width: 0;
}

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

.logo {
  display: inline-flex;
  align-items: center;
  border-radius: var(--r-ctl);
  line-height: 0;
}
.logo-img {
  display: block;
  height: 40px;
  width: auto;
  max-width: 100%;
  object-fit: contain;
}
.enterprise-name {
  font-size: 13px;
  line-height: 18px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 260px;
  padding-left: 12px;
  border-left: 1px solid var(--border);
}
/* Identity not loaded yet: neutral placeholder, never an invented name. */
.enterprise-name.is-loading {
  display: inline-block;
  width: 160px;
  height: 12px;
  margin: 3px 0;
  border-radius: 6px;
  background: var(--border);
  animation: enterprise-name-pulse 1.2s ease-in-out infinite;
}
@keyframes enterprise-name-pulse {
  0%, 100% { opacity: 0.45; }
  50% { opacity: 0.9; }
}
@media (prefers-reduced-motion: reduce) {
  .enterprise-name.is-loading { animation: none; }
}

/* Breadcrumbs */
.breadcrumbs {
  flex: 1;
  min-width: 0;
  overflow: hidden;
}
.breadcrumbs-list {
  display: flex;
  align-items: center;
  gap: 6px;
  list-style: none;
  margin: 0;
  padding: 0;
  min-width: 0;
}
.crumb {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  line-height: 20px;
  min-width: 0;
  color: var(--text-muted);
}
.crumb-root, .crumb-current { flex-shrink: 0; }
.crumb-link, .crumb-text {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: block;
  max-width: 220px;
}
.crumb-current .crumb-text {
  color: var(--text);
  font-weight: 500;
}
.crumb-sep {
  display: inline-flex;
  color: var(--text-dim);
  flex-shrink: 0;
}

/* Header actions */
.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}
.seg {
  display: inline-flex;
  border: 1px solid var(--control-border);
  border-radius: var(--r-ctl);
  overflow: hidden;
  background: var(--bg-panel);
}
.seg-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 32px;
  padding: 0 10px;
  border: 0;
  background: transparent;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
}
.seg-btn + .seg-btn { border-left: 1px solid var(--control-border); }
.seg-btn:hover { background: var(--bg-hover); color: var(--text); }
.seg-btn[aria-pressed="true"] {
  background: var(--accent);
  color: var(--accent-contrast);
}
.seg-btn[aria-pressed="true"]:hover { background: var(--accent-hover); }

/* ---------------------------------------------------------------------------
   5. Navigation rail
   --------------------------------------------------------------------------- */
.rail {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
  padding: 8px 0;
  min-width: 0;
}
.rail-items { display: flex; flex-direction: column; gap: 4px; padding: 0 8px; }
.rail-item {
  display: flex;
  align-items: center;
  gap: 12px;
  height: 44px;
  padding: 0 12px;
  border-radius: var(--r-card);
  color: var(--text-muted);
  white-space: nowrap;
  min-width: 0;
}
.rail-item:hover { background: var(--bg-hover); color: var(--text); text-decoration: none; }
.rail-item[aria-current="page"] {
  background: var(--bg-selected);
  color: var(--accent);
  font-weight: 500;
}
.rail-item svg { flex-shrink: 0; }
.rail-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 14px;
}

/* Collapsed rail: icons only, centered. */
body[data-rail="collapsed"] .rail-item {
  justify-content: center;
  padding: 0;
  width: 48px;
  margin: 0 auto;
}
body[data-rail="collapsed"] .rail-label { display: none; }

.rail-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  align-self: center;
  width: 40px;
  height: 40px;
  margin: 4px auto 0;
  border: 0;
  border-radius: var(--r-ctl);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
}
.rail-toggle:hover { background: var(--bg-hover); color: var(--text); }
.rail-toggle svg { transition: transform 160ms ease-out; }
body[data-rail="expanded"] .rail-toggle svg { transform: rotate(180deg); }

/* ---------------------------------------------------------------------------
   6. Bottom navigation (mobile)
   --------------------------------------------------------------------------- */
.bottom-nav {
  display: none;
}

/* ---------------------------------------------------------------------------
   7. Main workspace
   --------------------------------------------------------------------------- */
.main {
  overflow-y: auto;
  padding: 24px;
  min-width: 0;
}
.workspace {
  max-width: 1240px;
  margin: 0 auto;
}

.page-head { margin-bottom: 24px; }
.page-title {
  font-size: 24px;
  line-height: 32px;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.page-lede {
  margin-top: 8px;
  max-width: 760px;
  font-size: 16px;
  line-height: 24px;
  color: var(--text-muted);
}
.section-title {
  font-size: 20px;
  line-height: 28px;
  font-weight: 600;
  margin: 24px 0 12px;
}

.provenance { margin-top: 12px; }
.provenance-line {
  font-size: 12px;
  line-height: 16px;
  color: var(--text-dim);
}

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 16px;
  font-size: 14px;
  line-height: 20px;
  font-weight: 500;
}

/* ---------------------------------------------------------------------------
   8. Buttons
   --------------------------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 40px;
  padding: 0 16px;
  border-radius: var(--r-ctl);
  border: 1px solid transparent;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
}
.btn:hover { text-decoration: none; }
.btn-primary {
  background: var(--accent);
  color: var(--accent-contrast);
  border-color: var(--accent);
}
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); color: var(--accent-contrast); }
.btn-secondary {
  background: transparent;
  color: var(--text);
  border-color: var(--control-border);
}
.btn-secondary:hover { background: var(--bg-hover); }

/* ---------------------------------------------------------------------------
   9. Domain grid + cards
   --------------------------------------------------------------------------- */
.domain-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 16px;
}
/* Live overview has four domains: a balanced 2×2 reads as a deliberate map. */
.domain-grid--two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.domain-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 20px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--r-card);
  transition: border-color 120ms ease-out, background 120ms ease-out;
}
.domain-card:hover { border-color: var(--accent); background: var(--bg-panel); }
.domain-card-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}
.domain-card-name {
  font-size: 16px;
  line-height: 24px;
  font-weight: 600;
  color: var(--text);
}
.domain-card-name a { color: var(--text); }
.domain-card-name a:hover { color: var(--accent); }
.domain-card-arrow { color: var(--text-dim); flex-shrink: 0; display: inline-flex; }
.domain-card:hover .domain-card-arrow { color: var(--accent); }
.domain-card-desc {
  font-size: 14px;
  line-height: 20px;
  color: var(--text-muted);
}
.domain-card-caps {
  list-style: none;
  margin: 4px 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.cap { font-size: 14px; line-height: 20px; }
.cap-link { font-weight: 500; }
.cap-cross {
  margin-left: 6px;
  font-size: 12px;
  color: var(--text-dim);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 0 6px;
}
.cap-unavailable { color: var(--text-muted); }
.cap-flag {
  margin-left: 6px;
  font-size: 12px;
  color: var(--text-dim);
  font-style: italic;
}
/* Domain detail capability list */
.cap-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 720px;
}
.cap-list .cap {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--r-card);
  min-height: 44px;
}
.cap-list .cap-unavailable { border-style: dashed; }

/* Primary transition under the overview content */
.process-cta { margin-top: 24px; }

/* ---------------------------------------------------------------------------
   10. KPI group
   --------------------------------------------------------------------------- */
.kpi-group {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 24px;
}
.kpi {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1 1 0;
  min-width: 180px;
  padding: 16px 20px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--r-card);
  text-decoration: none;
}
.kpi:hover { border-color: var(--accent); text-decoration: none; }
.kpi-label { font-size: 12px; line-height: 16px; color: var(--text-muted); }
.kpi-value { font-size: 22px; line-height: 28px; font-weight: 600; color: var(--text); }
/* Units stay visible but do not compete with the value. */
.kpi-value small { font-size: 0.64em; font-weight: 500; color: var(--text-muted); }

/* ---------------------------------------------------------------------------
   11. Table
   --------------------------------------------------------------------------- */
.table-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  align-items: flex-end;
  margin-bottom: 16px;
}
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 13px; line-height: 18px; font-weight: 500; color: var(--text-muted); }
.search-wrap {
  position: relative;
  display: flex;
  align-items: center;
}
.search-wrap svg {
  position: absolute;
  left: 10px;
  color: var(--text-dim);
  pointer-events: none;
}
.field input[type="search"], .field select {
  min-height: 40px;
  padding: 0 12px;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--control-border);
  border-radius: var(--r-ctl);
}
.field input[type="search"] { padding-left: 34px; min-width: 240px; }
.field select { min-width: 160px; }
.field input:focus-visible, .field select:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.table-scroll { overflow-x: auto; }
/* Row/entry count above an on-demand table */
.table-meta { margin: 0 0 8px; font-size: 12px; line-height: 16px; color: var(--text-muted); }
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
  line-height: 20px;
}
.data-table thead th {
  height: 40px;
  padding: 0 12px;
  text-align: left;
  font-weight: 500;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.data-table th.num, .data-table td.num { text-align: right; }
.data-table tbody tr {
  height: 48px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}
.data-table tbody tr:last-child { border-bottom: 0; }
.data-table tbody tr:hover { background: var(--bg-hover); }
.data-table tbody tr:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.data-table td { padding: 0 12px; vertical-align: middle; }
.row-link { font-weight: 500; }
.row-id { display: block; font-size: 12px; line-height: 16px; color: var(--text-dim); }
td.dim { color: var(--text-dim); }

/* Status badge */
.status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}
.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
  display: inline-block;
}
.dot-success { background: var(--success); }
.dot-warning { background: var(--warning); }
.dot-critical { background: var(--critical); }
.dot-info { background: var(--accent); }
.dot-neutral { background: var(--text-dim); }

.empty-state {
  padding: 32px 16px;
  text-align: center;
  color: var(--text-muted);
}
.empty-state .btn { margin-top: 12px; }

/* ---------------------------------------------------------------------------
   12. Object detail + relations
   --------------------------------------------------------------------------- */
.object-detail {
  padding: 24px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--r-panel);
}
.od-head { margin-bottom: 16px; }
.badge-type {
  display: inline-block;
  font-size: 12px;
  line-height: 16px;
  font-weight: 500;
  color: var(--accent);
  background: var(--bg-selected);
  border-radius: var(--r-sm);
  padding: 2px 8px;
  margin-bottom: 8px;
}
.od-head .page-title { font-size: 20px; line-height: 28px; }
.od-head .row-id { margin-top: 4px; }

.od-fields {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 16px 24px;
  margin: 0;
}
.od-row { min-width: 0; }
.od-label {
  font-size: 12px;
  line-height: 16px;
  color: var(--text-muted);
  margin-bottom: 2px;
}
.od-value { font-size: 15px; line-height: 22px; margin: 0; overflow-wrap: anywhere; }
.od-value.strong { font-weight: 600; }

.relations {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 720px;
}
.relation {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--r-card);
}
.relation-link {
  display: flex;
  flex-direction: column;
  gap: 2px;
  color: var(--text);
  font-weight: 500;
}
.relation-link:hover { color: var(--accent); }
.relation-type { font-size: 12px; line-height: 16px; color: var(--text-muted); font-weight: 400; }
.relation-name { font-size: 14px; line-height: 20px; }
.relation-meta { font-size: 12px; line-height: 16px; color: var(--text-dim); white-space: nowrap; }

.empty-hint { color: var(--text-muted); }

/* ---------------------------------------------------------------------------
   13. Process timeline + summary
   --------------------------------------------------------------------------- */
.process-timeline {
  display: flex;
  align-items: stretch;
  overflow-x: auto;
  gap: 0;
  margin: 16px 0 24px;
  padding-bottom: 4px;
}
.process-stage {
  display: flex;
  flex-direction: column;
  gap: 2px;
  align-items: flex-start;
  min-width: 128px;
  padding: 12px 14px;
  border: 1px solid var(--control-border);
  border-radius: var(--r-card);
  background: var(--bg);
  color: var(--text);
  cursor: pointer;
  text-align: left;
}
.process-stage:hover { border-color: var(--accent); background: var(--bg-hover); }
.process-stage.is-active {
  border-color: var(--accent);
  background: var(--bg-selected);
  box-shadow: inset 0 0 0 1px var(--accent);
}
.stage-name { font-size: 13px; line-height: 18px; font-weight: 600; }
.stage-obj { font-size: 12px; line-height: 16px; color: var(--text-muted); }
.stage-connector {
  flex: 1;
  min-width: 24px;
  align-self: center;
  height: 2px;
  background: var(--border);
}

.process-summary {
  padding: 20px 24px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--r-card);
  margin-bottom: 24px;
}
.sum-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px 24px;
}
.sum-item { display: flex; flex-direction: column; gap: 2px; }
.sum-label { font-size: 12px; line-height: 16px; color: var(--text-muted); }
.sum-value { font-size: 18px; line-height: 26px; font-weight: 600; }
.sum-value.strong { color: var(--accent); }
.process-summary .provenance { margin-top: 16px; }
.process-hint { padding: 24px; color: var(--text-muted); border: 1px dashed var(--control-border); border-radius: var(--r-card); }

/* ---------------------------------------------------------------------------
   14. Observability
   --------------------------------------------------------------------------- */
.filter-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0 0 24px;
}
.filter-chip {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  padding: 0 14px;
  border: 1px solid var(--control-border);
  border-radius: 999px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  text-decoration: none;
}
.filter-chip:hover { border-color: var(--accent); color: var(--text); text-decoration: none; }
.filter-chip.is-active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-contrast);
}

.obs-groups {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 16px;
  align-items: start;
}
.obs-group {
  padding: 20px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--r-card);
}
.obs-group-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 12px;
}
.obs-group-head .section-title { margin: 0; font-size: 16px; line-height: 22px; }
.metric-list { display: flex; flex-direction: column; gap: 10px; margin: 0; }
.metric { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.metric-label { font-size: 13px; line-height: 18px; color: var(--text-muted); margin: 0; }
.metric-value { font-size: 18px; line-height: 26px; font-weight: 600; margin: 0; }
.badge-derived {
  margin-left: 6px;
  font-size: 11px;
  color: var(--text-dim);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 0 6px;
}
.obs-group .agent-action {
  margin-top: 16px;
  flex-direction: column;
  align-items: stretch;
}
.obs-group .agent-action-btn { width: 100%; white-space: normal; }

/* ---------------------------------------------------------------------------
   15. Contextual agent action
   --------------------------------------------------------------------------- */
.agent-action {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-top: 24px;
  padding: 16px 20px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--r-card);
}
.agent-action-body { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.agent-action-title { font-size: 13px; line-height: 18px; font-weight: 600; }
.agent-action-summary { font-size: 14px; line-height: 20px; color: var(--text-muted); }
.agent-action-note { font-size: 12px; line-height: 16px; color: var(--text-dim); }
.agent-action-btn { flex-shrink: 0; }

/* ---------------------------------------------------------------------------
   16. Pi frame (agent / data sources)
   --------------------------------------------------------------------------- */
/* Sizing lives in §19 (full-bleed workspace); this block only keeps the
   shared surface basics for the frame and its on-demand load-error note. */
.pi-frame-wrap {
  display: flex;
  flex-direction: column;
  background: var(--bg);
}
.pi-frame {
  width: 100%;
  border: 0;
  display: block;
}
/* Hidden by default; revealed only when the frame's document is not the Pi
   app (proxied 502 etc.). Overlay, so it never takes layout space. */
.pi-load-error {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  background: var(--bg-panel);
  border: 1px solid var(--critical);
  border-radius: var(--r-card);
}
.pi-load-error p {
  font-size: 14px;
  line-height: 20px;
  color: var(--text);
}

/* ---------------------------------------------------------------------------
   17. Loading / error states
   --------------------------------------------------------------------------- */
.loading {
  display: flex;
  align-items: center;
  gap: 12px;
  justify-content: center;
  padding: 64px 24px;
  color: var(--text-muted);
}
.loading-spinner {
  width: 20px;
  height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 700ms linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.error-state {
  max-width: 640px;
  margin: 40px auto;
  padding: 32px;
  background: var(--bg-panel);
  border: 1px solid var(--critical);
  border-radius: var(--r-panel);
  text-align: center;
}
.error-state .page-title { color: var(--critical); }
.error-state .empty-hint { margin: 12px 0 20px; }

/* On-demand provenance / diagnostics: present but never the primary narrative. */
.provenance-details, .obs-details {
  margin: 8px 0 0;
  font-size: 13px;
  color: var(--text-muted);
}
.provenance-details summary, .obs-details summary {
  cursor: pointer;
  color: var(--text-muted);
  text-decoration: underline dotted;
  text-underline-offset: 3px;
}
.provenance-details summary:hover, .obs-details summary:hover { color: var(--text); }
.provenance-details-body { padding: 8px 0 0; display: grid; gap: 6px; }
.provenance-details-body p { margin: 0; }
.obs-details .table-scroll { margin-top: 12px; }

.noscript {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--bg);
  color: var(--critical);
  z-index: 200;
}

/* ---------------------------------------------------------------------------
   18. Responsive + accessibility
   --------------------------------------------------------------------------- */

/* Tablet: compact rail, hide enterprise-name text */
@media (max-width: 1279px) {
  body, body[data-rail="expanded"] { --rail-w: 56px; }
  .enterprise-name, .enterprise-name.is-loading { display: none; }
  .workspace { max-width: none; }
}

/* Mobile */
@media (max-width: 767px) {
  body {
    grid-template-columns: 1fr;
    grid-template-rows: 56px 1fr auto;
    grid-template-areas:
      "header"
      "main"
      "bottomnav";
  }
  .rail { display: none; }
  .breadcrumbs { display: none; }
  .enterprise-name, .enterprise-name.is-loading { display: none; }
  .header { gap: 8px; padding: 0 12px; }
  .logo-img { height: 32px; }
  .seg-text { display: none; }
  .seg-btn { padding: 0 8px; }

  .main { padding: 16px; }

  .bottom-nav {
    display: flex;
    align-items: stretch;
    background: var(--bg-panel);
    border-top: 1px solid var(--border);
    padding-bottom: env(safe-area-inset-bottom);
  }
  .bnav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    min-height: 56px;
    color: var(--text-muted);
    font-size: 11px;
    line-height: 14px;
    text-decoration: none;
  }
  .bnav-item[aria-current="page"] { color: var(--accent); font-weight: 600; }
  .bnav-label { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

  .domain-grid, .domain-grid--two { grid-template-columns: 1fr; }
  .obs-groups { grid-template-columns: 1fr; }
  .kpi { min-width: 100%; }
  .sum-grid { grid-template-columns: 1fr 1fr; }
  .field input[type="search"] { min-width: 0; width: 100%; }
  .field select { width: 100%; }
  .agent-action { flex-direction: column; align-items: stretch; }
  .agent-action-btn { width: 100%; }
  .object-detail { padding: 16px; }
  .relation { flex-direction: column; align-items: flex-start; }
  .od-fields { grid-template-columns: 1fr; }
}

/* Very narrow (390 px and below): keep everything reflowing without overflow */
@media (max-width: 420px) {
  .header-left { gap: 8px; }
  .seg-btn { min-height: 32px; }
  .crumb { max-width: 160px; }
  .sum-grid { grid-template-columns: 1fr; }
}

/* Touch targets */
@media (pointer: coarse) {
  .seg-btn { min-height: 44px; }
  .rail-item { height: 44px; }
  .bnav-item { min-height: 56px; }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  .loading-spinner { animation: none; border-top-color: var(--text-dim); }
}

/* ---------------------------------------------------------------------------
   19. Shellless Pi workspace (UX-COMPOSITION-001)
   Agent and Data Sources are full-bleed: no outer page-head, no width cap,
   no border card, no persistent fallback row, no outer scroll. Placed after
   the responsive rules so the route marker wins every cascade. Native Pi
   owns all inner scroll surfaces (conversation, sidebar, settings, registry).
   --------------------------------------------------------------------------- */
body[data-workspace="agent"] .main,
body[data-workspace="dataSources"] .main {
  min-height: 0;
  padding: 0;
  overflow: hidden;
}
body[data-workspace="agent"] .pi-workspace,
body[data-workspace="dataSources"] .pi-workspace {
  display: flex;
  flex-direction: column;
  height: 100%;
  max-width: none;
  margin: 0;
}
body[data-workspace="agent"] .pi-frame-wrap,
body[data-workspace="dataSources"] .pi-frame-wrap {
  position: relative;
  height: 100%;
  min-height: 0;
  gap: 0;
  border: 0;
  border-radius: 0;
}
body[data-workspace="agent"] .pi-frame,
body[data-workspace="dataSources"] .pi-frame {
  height: 100%;
  min-height: 0;
}


/* ---------------------------------------------------------------------------
   20. Personal identity and Users workspace (EUREKA-IDENTITY-001)
   --------------------------------------------------------------------------- */
.account-menu { position: relative; flex-shrink: 0; }
.account-summary {
  display: flex; align-items: center; gap: 8px; max-width: 220px; min-height: 40px;
  padding: 4px 8px; border: 1px solid var(--control-border); border-radius: var(--r-ctl);
  cursor: pointer; list-style: none; font-size: 14px; line-height: 20px;
}
.account-summary::-webkit-details-marker { display: none; }
.account-summary > span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account-role { color: var(--text-muted); font-size: 12px; }
.account-popover {
  position: absolute; z-index: 120; top: calc(100% + 8px); right: 0; width: 200px;
  padding: 8px; background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--r-card); box-shadow: var(--shadow-overlay);
}
.account-action {
  width: 100%; min-height: 40px; padding: 8px 12px; text-align: left;
  color: var(--text); background: transparent; border: 0; border-radius: var(--r-ctl);
  cursor: pointer;
}
.account-action:hover { background: var(--bg-hover); }

.login-body { display: block; min-height: 100dvh; background: var(--bg); }
.login-main { min-height: 100dvh; display: flex; align-items: center; justify-content: center; padding: 24px; }
.login-card {
  width: 100%; max-width: 440px; padding: 32px; background: var(--bg-panel);
  border: 1px solid var(--border); border-radius: var(--r-panel); box-shadow: var(--shadow-light);
}
.login-logo { display: block; width: 240px; max-width: 100%; height: auto; margin: 0 auto 16px; }
.login-kicker { margin-bottom: 24px; color: var(--text-muted); font-size: 12px; text-align: center; }
.login-lede { margin: 8px 0 24px; color: var(--text-muted); }
.login-submit { width: 100%; }
.login-preferences { display: flex; justify-content: space-between; gap: 16px; margin-top: 24px; }

.identity-form { display: grid; gap: 16px; }
.identity-form .field { display: grid; gap: 4px; }
.identity-form .field label { font-size: 14px; font-weight: 500; }
.identity-form input, .identity-form select {
  width: 100%; min-height: 40px; padding: 8px 12px; color: var(--text);
  background: var(--bg); border: 1px solid var(--control-border); border-radius: var(--r-ctl);
  font: inherit; font-size: 14px; line-height: 20px;
}
.field-hint { color: var(--text-muted); font-size: 12px; line-height: 16px; }
.form-error, .form-success { font-size: 14px; line-height: 20px; }
.form-error { color: var(--critical); }
.form-success { margin-bottom: 16px; color: var(--success); }
.identity-dialog {
  width: min(480px, calc(100vw - 32px)); max-height: calc(100dvh - 48px); overflow: auto;
  padding: 24px; color: var(--text); background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--r-card); box-shadow: var(--shadow-overlay);
}
.identity-dialog::backdrop { background: rgb(0 0 0 / 45%); }
.dialog-head, .dialog-actions, .section-toolbar, .users-head {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
}
.dialog-actions { justify-content: flex-end; margin-top: 8px; }
.icon-btn {
  width: 40px; height: 40px; padding: 0; color: var(--text); background: transparent;
  border: 0; border-radius: var(--r-ctl); font-size: 24px; cursor: pointer;
}
.icon-btn:hover { background: var(--bg-hover); }
.account-identity { display: grid; gap: 4px; overflow-wrap: anywhere; }
.account-identity .mono { color: var(--text-muted); font-size: 12px; }
.account-facts { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 0; }
.account-facts div { min-width: 0; }
.account-facts dt { color: var(--text-muted); font-size: 12px; }
.account-facts dd { margin: 4px 0 0; font-size: 14px; overflow-wrap: anywhere; }

.users-head { align-items: flex-start; margin-bottom: 24px; }
.users-table { min-width: 1080px; }
.users-table-wrap { margin-bottom: 32px; }
.user-actions { display: flex; flex-wrap: wrap; gap: 8px; min-width: 320px; }
.btn-small { min-height: 32px; padding: 4px 8px; font-size: 12px; }
.btn-danger { color: var(--accent-contrast); background: var(--critical); border-color: var(--critical); }
.btn-danger:hover { color: var(--accent-contrast); background: var(--critical); }
.role-badge { display: inline-block; padding: 2px 8px; background: var(--bg-selected); border-radius: 999px; font-size: 12px; }
.account-you { margin-left: 8px; color: var(--text-muted); font-size: 12px; }
.audit-section { margin-top: 32px; }
.audit-section .section-toolbar { margin-bottom: 16px; }
.audit-table { min-width: 800px; }
.audit-table .mono { font-size: 12px; }

@media (max-width: 767px) {
  .account-summary { max-width: 96px; min-height: 36px; padding: 4px 6px; }
  .account-role { display: none; }
  .account-popover { right: -8px; }
  .login-main { padding: 16px; }
  .login-card { padding: 24px 16px; }
  .users-head { flex-direction: column; }
  .users-head .btn { width: 100%; }
  .identity-dialog { padding: 16px; }
  .account-facts { grid-template-columns: 1fr; }
  .dialog-actions .btn { flex: 1; }
  .user-actions { min-width: 280px; }
}
@media (pointer: coarse) {
  .identity-form input, .identity-form select, .account-action { min-height: 44px; }
  .btn-small { min-height: 44px; }
}


@media (max-width: 767px) {
  .bottom-nav .bnav-label { display: none; }
  .users-table-wrap, .audit-section .table-scroll { overscroll-behavior-x: contain; }
}


@media (pointer: coarse) {
  .account-summary, .icon-btn { min-height: 44px; min-width: 44px; }
}


@media (pointer: coarse) {
  .btn { min-height: 44px; }
}


@media (pointer: coarse) {
  .btn { height: 44px; }
  .account-summary, .icon-btn { height: 44px; min-width: 44px; }
}


@media (forced-colors: active) {
  :focus-visible { outline: 2px solid Highlight !important; }
  .btn, .icon-btn, .identity-form input, .identity-form select { border: 1px solid ButtonText; }
}


@media (max-width: 420px) {
  .header { gap: 4px; padding: 0 8px; }
  .header-actions { gap: 4px; }
  .account-summary { width: 44px; max-width: 44px; justify-content: center; }
  .account-summary > span { display: none; }
  .account-summary::before { content: "···"; font-size: 18px; line-height: 20px; }
}
