/* Rework Phase 2 — the two-realm sidebar IA, activity strip, realm/clause card
   badges, endpoint footers and the Connect landing view. Loaded after style.css
   + tokens.css; overrides the old two-column .main-layout with a three-column
   [ car rail | sidebar | active view ] grid. Sprite/vehicle CSS is untouched. */

.main-layout {
  grid-template-columns: minmax(260px, 28%) minmax(168px, 200px) 1fr;
}

/* ---- Sidebar navigation ---------------------------------------------- */
.sidebar {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  min-height: 0;
  overflow-y: auto;
  padding: var(--space-1) var(--space-2) var(--space-4) 0;
  border-right: 1px solid var(--border);
}

.nav-group { display: flex; flex-direction: column; gap: 2px; }

.nav-heading {
  font-size: var(--font-2xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-muted);
  padding: 2px 10px;
  margin-top: var(--space-2);
}
.nav-group--top { margin-bottom: var(--space-1); }

.nav-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  width: 100%;
  text-align: left;
  appearance: none;
  border: none;
  background: none;
  cursor: pointer;
  font-size: var(--font-sm);
  font-weight: 600;
  color: var(--text-soft);
  padding: 8px 10px;
  border-left: 3px solid transparent;
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.nav-item:hover { background: var(--bg-panel); color: var(--text); }
.nav-item.active { background: var(--bg-panel); font-weight: 700; }
.nav-item--sovd.active { color: var(--realm-sovd); border-left-color: var(--realm-sovd); }
.nav-item--sim.active { color: var(--realm-sim); border-left-color: var(--realm-sim); }
.nav-item--top.active { color: var(--text-strong); border-left-color: var(--text-strong); }
.nav-item--top { font-weight: 700; color: var(--text-strong); }

.nav-badge {
  flex: 0 0 auto;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: var(--radius-pill);
  background: var(--brand);
  color: #fff;
  font-size: var(--font-2xs);
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.nav-item--sim .nav-badge { background: var(--realm-sim); }
/* the element-level display above would otherwise defeat the [hidden] attribute */
.nav-badge[hidden] { display: none; }

/* ---- View area ------------------------------------------------------- */
.view-area {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  min-height: 0;
  overflow-y: auto;
  /* The tour-highlight ring (3px outline + 3px offset, 6px shadow spread)
     draws outside its target; as the scroll container this element clips ink
     overflow, so keep ≥6px of padding on every side the ring can reach. */
  padding: var(--space-1) var(--space-2) var(--space-2) var(--space-2);
}

.activity-strip {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  min-height: 40px;
}
.activity-empty { font-size: var(--font-xs); color: var(--text-muted); font-style: italic; }

.activity-chip {
  appearance: none;
  border: 1px solid var(--border);
  background: #fff;
  border-radius: var(--radius-pill);
  padding: 4px 12px;
  font-size: var(--font-xs);
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.activity-chip:hover:not(:disabled) { background: var(--bg-control); }
.activity-chip:disabled { cursor: default; }
.activity-chip--warn { border-color: var(--warning); color: var(--warning-hover); }
.activity-chip--error { border-color: var(--danger); color: var(--danger-hover); }
.activity-chip--ok { border-color: var(--success); color: var(--success); }

/* ---- Card realm/clause badges --------------------------------------- */
.card-badge {
  flex: 0 0 auto;
  margin-left: var(--space-2);
  padding: 2px 8px;
  border-radius: var(--radius-pill);
  font-size: var(--font-2xs);
  font-weight: 700;
  letter-spacing: 0.3px;
  text-transform: none;
}
.card-badge--sovd { background: var(--brand-bg-soft); color: var(--brand); }
.card-badge--sim { background: var(--realm-sim-bg-soft); color: var(--realm-sim); }
/* the badge sits just after the title, before the auto-margin push of the (i);
   in badge-less headers (e.g. the Session card) the (i) keeps its own
   margin-left:auto push from style.css */
.control-section h2 .card-badge { margin-right: auto; }
.control-section h2 .card-badge ~ .info-icon { margin-left: 0; }

/* ---- Endpoint footer ------------------------------------------------- */
.endpoint-footer { margin-top: var(--space-3); border-top: 1px dashed var(--border); padding-top: var(--space-2); }
.endpoint-footer > summary {
  cursor: pointer;
  font-size: var(--font-2xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--text-muted);
  list-style: revert;
}
.endpoint-list { display: flex; flex-direction: column; gap: 4px; margin-top: var(--space-2); }
.endpoint-row { display: flex; align-items: center; gap: var(--space-2); }
.endpoint-sig {
  flex: 1;
  min-width: 0;
  font-family: 'Cascadia Code', 'Fira Code', monospace;
  font-size: var(--font-2xs);
  color: var(--text-soft);
  overflow-x: auto;
  white-space: nowrap;
}
.endpoint-clause { flex: 0 0 auto; font-size: var(--font-2xs); color: var(--text-muted); }
.endpoint-copy { padding: 1px 8px; font-size: var(--font-2xs); }

/* ---- Connect view ---------------------------------------------------- */
.connect-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: var(--space-4);
  align-items: start;
}
.connect-card {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
}
.connect-card--wide { grid-column: 1 / -1; }
.connect-card h3 { font-size: var(--font-md); color: var(--brand); margin-bottom: var(--space-2); }
.connect-lead { font-size: var(--font-sm); color: var(--text-soft); line-height: 1.55; margin-bottom: var(--space-3); }
.connect-hint { font-size: var(--font-xs); color: var(--text-muted); margin-top: var(--space-2); font-style: italic; }
.connect-server-status { display: flex; align-items: center; gap: var(--space-2); font-size: var(--font-sm); }
.connect-btn-row { display: flex; flex-wrap: wrap; gap: var(--space-2); margin-top: var(--space-2); }
.connect-curl { display: flex; align-items: flex-start; gap: var(--space-2); }
.connect-curl pre {
  flex: 1;
  min-width: 0;
  margin: 0;
  padding: var(--space-3);
  background: #1e1e1e;
  color: #4ade80;
  border-radius: var(--radius-md);
  font-family: 'Cascadia Code', 'Fira Code', monospace;
  font-size: var(--font-xs);
  line-height: 1.5;
  overflow-x: auto;
  white-space: pre;
}
/* ---- Coverage view --------------------------------------------------- */
.coverage-view { padding: var(--space-2); max-width: 1100px; }
.coverage-asof { font-size: var(--font-xs); color: var(--text-muted); font-style: italic; margin-bottom: var(--space-3); }
.coverage-legend { display: flex; flex-wrap: wrap; gap: var(--space-2); margin-bottom: var(--space-3); }

.coverage-support {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 2px 9px;
  border-radius: var(--radius-pill);
  font-size: var(--font-2xs);
  font-weight: 700;
  white-space: nowrap;
}
.coverage-support--full { background: #dcfce7; color: #15803d; }
.coverage-support--partial { background: #fef3c7; color: var(--warning-hover); }
.coverage-support--sim-hook { background: var(--realm-sim-bg-soft); color: var(--realm-sim); }
.coverage-support--not-implemented { background: var(--bg-control); color: var(--text-muted); }
.coverage-support--gateway { background: #dbeafe; color: #1d4ed8; }

.coverage-table {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}
.coverage-row {
  display: grid;
  grid-template-columns: 116px 96px 1fr auto;
  column-gap: var(--space-3);
  row-gap: 2px;
  padding: 10px var(--space-3);
  border-bottom: 1px solid var(--border-soft);
  align-items: center;
}
.coverage-row:last-child { border-bottom: none; }
.coverage-row:nth-child(even) { background: #fafafa; }
.coverage-support { grid-row: 1; grid-column: 1; justify-self: start; }
.coverage-clause { grid-row: 1; grid-column: 2; font-weight: 700; font-size: var(--font-xs); color: var(--text); }
.coverage-name { grid-row: 1; grid-column: 3; font-weight: 600; font-size: var(--font-sm); }
.coverage-copy { grid-row: 1; grid-column: 4; padding: 1px 8px; font-size: var(--font-2xs); }
.coverage-entry {
  grid-row: 2; grid-column: 3 / 5;
  font-family: 'Cascadia Code', 'Fira Code', monospace;
  font-size: var(--font-2xs);
  color: var(--brand);
  overflow-x: auto;
  white-space: nowrap;
}
.coverage-notes { grid-row: 3; grid-column: 3 / 5; font-size: var(--font-2xs); color: var(--text-muted); line-height: 1.4; }

.coverage-limits {
  margin-top: var(--space-5);
  padding: var(--space-4);
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}
.coverage-limits h3 { font-size: var(--font-md); color: var(--brand); margin-bottom: var(--space-2); }
.coverage-limits-list { margin: 0; padding-left: var(--space-5); display: flex; flex-direction: column; gap: 6px; }
.coverage-limits-list li { font-size: var(--font-sm); color: var(--text-soft); line-height: 1.5; }

@media (max-width: 620px) {
  .coverage-row { grid-template-columns: auto 1fr auto; }
  .coverage-clause { grid-column: 2; }
  .coverage-name { grid-row: 2; grid-column: 1 / 4; }
  .coverage-entry { grid-row: 3; grid-column: 1 / 4; }
  .coverage-notes { grid-row: 4; grid-column: 1 / 4; }
}

/* ---- Responsive: stack the sidebar above the view on narrow widths --- */
@media (max-width: 980px) {
  .main-layout { grid-template-columns: 1fr; }
  .sidebar {
    flex-direction: row;
    flex-wrap: wrap;
    border-right: none;
    border-bottom: 1px solid var(--border);
    padding-bottom: var(--space-2);
  }
  .nav-group { flex-direction: row; flex-wrap: wrap; align-items: center; }
  .nav-heading { width: 100%; margin-top: 0; }
  .nav-item { width: auto; border-left: none; border-bottom: 3px solid transparent; border-radius: var(--radius-md); }
  .nav-item--sovd.active { border-left: none; border-bottom-color: var(--realm-sovd); }
  .nav-item--sim.active { border-left: none; border-bottom-color: var(--realm-sim); }
}

/* ====================================================================== */
/* Rework Phase 3 — UX layer: button/status tokens, contextual lock chip, */
/* connection chip + recovery dialog, expandable copy-as-curl API log.    */
/* ====================================================================== */

/* Button semantics live in style/components.css (§5.2 unified controls). */

/* Contextual lock chip */
.lock-chip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  padding: 6px 10px;
  margin-bottom: var(--space-3);
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  font-size: var(--font-xs);
  font-weight: 600;
}
.lock-chip[data-state="locked"] { background: #ecfdf3; border-color: #a7e3bf; color: #15803d; }
.lock-chip[data-state="unlocked"] { background: var(--brand-bg-soft); border-color: #f3c9d3; color: var(--brand); }
.lock-chip-txt { display: inline-flex; align-items: center; gap: 6px; }
.lock-chip-btn { padding: 3px 12px; font-size: var(--font-2xs); }

/* Connection chip in the activity strip */
.conn-chip {
  flex: 0 0 auto;
  padding: 3px 10px;
  border-radius: var(--radius-pill);
  font-size: var(--font-2xs);
  font-weight: 700;
  white-space: nowrap;
}
.conn-chip[data-status="live"] { background: #dcfce7; color: #15803d; }
.conn-chip[data-status="reconnecting"] { background: #fef3c7; color: var(--warning-hover); }
.conn-chip[data-status="lost"] { background: #fde8e8; color: var(--danger-hover); }

/* Expandable API log */
.api-log-filter {
  width: 100%;
  box-sizing: border-box;
  margin-bottom: var(--space-2);
  padding: 5px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: var(--font-2xs);
}
.log-entry--call .log-line {
  display: flex;
  align-items: baseline;
  gap: 4px;
  cursor: pointer;
  width: 100%;
  text-align: left;
}
.log-caret { color: var(--text-muted); font-size: 9px; flex: 0 0 auto; }
.log-line:hover .log-status { text-decoration: underline; }
.log-detail {
  margin: 2px 0 6px 14px;
  padding: 8px 10px;
  background: #0c0c0c;
  border-radius: var(--radius-sm);
}
.log-detail-json {
  margin: 6px 0 0;
  color: #cfd8cf;
  font-family: 'Cascadia Code', 'Fira Code', monospace;
  font-size: 11px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 260px;
  overflow: auto;
}
.log-copy-curl { padding: 2px 10px; font-size: var(--font-2xs); }

/* ---- Rework Phase 4 — guided tours ---------------------------------- */
.tour-launcher {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: var(--space-3);
  margin: var(--space-4) 0;
}
.tour-track-card {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
}
.tour-track-card h3 { font-size: var(--font-md); color: var(--brand); margin-bottom: var(--space-2); }
.tour-track-card p { font-size: var(--font-sm); color: var(--text-soft); line-height: 1.5; margin-bottom: var(--space-3); }

.tour-card {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 1200;
  width: 340px;
  max-width: calc(100vw - 40px);
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.28);
  padding: var(--space-4);
}
.tour-counter { font-size: var(--font-2xs); font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-muted); }
.tour-title { font-size: var(--font-lg); color: #000; margin: 4px 0 var(--space-2); }
.tour-body { font-size: var(--font-sm); color: var(--text-soft); line-height: 1.55; margin-bottom: var(--space-3); }
.tour-actions { display: flex; justify-content: space-between; gap: var(--space-2); }

/* The step target is raised and ringed so the eye lands on it. */
.tour-highlight {
  position: relative;
  z-index: 5;
  outline: 3px solid var(--brand);
  outline-offset: 3px;
  border-radius: var(--radius-md);
  box-shadow: 0 0 0 6px rgba(204, 0, 61, 0.15);
}
@media (prefers-reduced-motion: reduce) {
  .tour-highlight { box-shadow: none; }
}

/* Session-wide request feed (§4.6-D): external-tool traffic in the API log */
.log-entry--external { border-left: 2px solid var(--realm-sim); padding-left: 6px; }
.log-ext-badge { color: var(--realm-sim); font-weight: 700; font-size: 10px; margin-right: 4px; }
