/* ── Brand tokens ─────────────────────────────────────── */
:root {
  --color-primary:   #354fa3;
  --color-secondary: #5596c0;
  --color-surface:   #e4ecf7;
  --color-accent:    #ef8534;
  --color-text:      #1a1a2e;
  --color-border:    #d0d9ee;
  --color-muted:     #888;
  --font-mono: 'Monaco', 'Menlo', 'Consolas', monospace;

  /* PicoCSS overrides */
  --pico-primary:            #354fa3;
  --pico-primary-background: #354fa3;
  --pico-primary-border:     #354fa3;
  --pico-primary-hover:      #2d4290;
  --pico-primary-focus:      rgba(53, 79, 163, 0.25);
  --pico-primary-inverse:    #fff;
  --pico-font-size:          14px;
  --pico-border-radius:      4px;
}

/* ── Reset for full-viewport shell ───────────────────── */
html, body {
  height: 100%;
  margin: 0;
  padding: 0;
  overflow: hidden;
  background: #fff;
}

#app {
  height: 100%;
}

/* PicoCSS adds padding/max-width to these — reset them */
main, aside, header, nav {
  max-width: none;
  padding: 0;
  margin: 0;
}

/* ── Shell layout ─────────────────────────────────────── */
.shell {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

.shell-body {
  display: flex;
  flex: 1;
  overflow: hidden;
}

.shell-main {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* ── MenuBar ──────────────────────────────────────────── */
.shell-header {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  padding: 0 1rem;
  height: 52px;
  background: #fff;
  border-bottom: 1px solid var(--color-border);
  flex-shrink: 0;
}

.menubar-brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  text-decoration: none;
  flex-shrink: 0;
}

.menubar-brand img {
  height: 28px;
  width: auto;
}

.menubar-brand-name {
  font-size: 1rem;
  font-weight: 600;
  color: var(--color-primary);
  letter-spacing: -0.01em;
  white-space: nowrap;
}

.menubar-nav {
  display: flex;
  gap: 0.25rem;
  flex: 1;
}

.menubar-tab {
  padding: 0.35rem 0.875rem;
  border-radius: 4px;
  font-size: 0.875rem;
  color: var(--color-text);
  cursor: pointer;
  border: none;
  background: none;
  line-height: 1.4;
  transition: background 0.1s;
}

.menubar-tab:hover:not([disabled]) {
  background: var(--color-surface);
}

.menubar-tab.active {
  background: var(--color-primary);
  color: #fff;
}

.menubar-tab[disabled] {
  opacity: 0.38;
  cursor: default;
}

/* ── Sidebar ──────────────────────────────────────────── */
.shell-sidebar {
  width: 224px;
  flex-shrink: 0;
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  overflow-y: auto;
  padding: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.sidebar-label {
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--color-secondary);
  padding: 0.5rem 0.25rem 0.25rem;
}

.sidebar-inputs {
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
  margin-bottom: 0.5rem;
}

.sidebar-inputs input {
  padding: 0.35rem 0.6rem;
  font-size: 0.82rem;
  border: 1px solid var(--color-border);
  border-radius: 4px;
  background: #fff;
  color: var(--color-text);
  margin: 0;
}

.sidebar-inputs input:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(53, 79, 163, 0.12);
}

.sidebar-connect-btn {
  width: 100%;
  padding: 0.375rem;
  font-size: 0.82rem;
  font-weight: 500;
  background: var(--color-primary);
  color: #fff;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  margin: 0;
  transition: background 0.1s;
}

.sidebar-connect-btn:hover:not([disabled]) {
  background: var(--color-secondary);
}

.sidebar-connect-btn[disabled] {
  opacity: 0.45;
  cursor: default;
}

.sidebar-tree {
  display: flex;
  flex-direction: column;
  gap: 0.125rem;
}

.sidebar-domain-header {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.25rem 0.25rem;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--color-primary);
  cursor: pointer;
  border-radius: 3px;
  user-select: none;
}

.sidebar-domain-header:hover {
  background: rgba(53, 79, 163, 0.08);
}

.sidebar-context-item {
  display: flex;
  align-items: center;
  padding: 0.22rem 0.25rem 0.22rem 1.1rem;
  font-size: 0.8rem;
  cursor: pointer;
  border-radius: 3px;
  color: var(--color-text);
  user-select: none;
}

.sidebar-context-item:hover {
  background: rgba(53, 79, 163, 0.08);
}

.sidebar-context-item.active {
  background: var(--color-primary);
  color: #fff;
}

.sidebar-error {
  font-size: 0.74rem;
  color: #c62828;
  padding: 0.25rem 0.25rem;
  word-break: break-word;
}

.sidebar-status {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.74rem;
  color: var(--color-text);
  padding: 0.25rem 0.25rem;
  font-family: var(--font-mono);
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
}

.status-dot.connected  { background: #43a047; }
.status-dot.connecting { background: #fb8c00; }
.status-dot.error      { background: #e53935; }

.sidebar-session-item {
  padding: 0.15rem 0.25rem 0.15rem 2rem;
  font-size: 0.75rem;
  color: var(--color-muted);
  cursor: pointer;
  border-radius: 3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-session-item:hover {
  background: rgba(53, 79, 163, 0.06);
}

.chevron {
  font-style: normal;
  font-size: 0.65rem;
  display: inline-block;
  width: 0.75rem;
  flex-shrink: 0;
}

/* ── REPL Panel ───────────────────────────────────────── */
.repl-panel {
  display: flex;
  flex-direction: column;
  height: 100%;
  background: #fff;
}

/* ── REPL toolbar ─────────────────────────────────────── */
.repl-toolbar {
  display: flex;
  justify-content: flex-end;
  padding: 0.3rem 1.5rem 0;
  flex-shrink: 0;
}

.repl-clear-btn {
  font-size: 0.75rem;
  color: var(--color-muted);
  background: none;
  border: none;
  padding: 0.2rem 0.4rem;
  border-radius: 4px;
  cursor: pointer;
  margin: 0;
}

.repl-clear-btn:hover {
  color: #c62828;
  background: #fff5f5;
}

/* ── Transcript ───────────────────────────────────────── */
.repl-transcript {
  flex: 1;
  overflow-y: auto;
  padding: 1.25rem 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.transcript-empty {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #bbb;
  font-size: 0.875rem;
  margin: auto;
}

.transcript-entry {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  max-width: 88%;
}

.transcript-entry.query {
  align-self: flex-end;
  align-items: flex-end;
}

.transcript-entry.reply {
  align-self: flex-start;
  align-items: flex-start;
}

.transcript-entry-label {
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  padding: 0 0.2rem;
}

.transcript-entry.query .transcript-entry-label {
  color: var(--color-secondary);
}

.transcript-entry.reply .transcript-entry-label {
  color: var(--color-primary);
}

.transcript-entry.error .transcript-entry-label {
  color: #c62828;
}

.transcript-bubble {
  padding: 0.55rem 0.8rem;
  border-radius: 6px;
  font-family: var(--font-mono);
  font-size: 0.82rem;
  white-space: pre-wrap;
  word-break: break-all;
  line-height: 1.55;
  border: 1px solid var(--color-border);
}

.transcript-entry.query .transcript-bubble {
  background: var(--color-surface);
  cursor: pointer;
}

.transcript-entry.query .transcript-bubble:hover {
  border-color: var(--color-secondary);
}

.transcript-entry.reply .transcript-bubble {
  background: #fff;
}

.transcript-entry.error .transcript-bubble {
  background: #fff8f8;
  border-color: #e57373;
}

.transcript-line + .transcript-line {
  margin-top: 0.35rem;
}

.transcript-kml {
  white-space: pre-wrap;
  word-break: break-all;
}

.transcript-nl {
  font-family: var(--font-sans, sans-serif);
  font-size: 0.78rem;
  color: var(--color-secondary, #888);
  font-style: italic;
  margin-top: 0.15rem;
  padding-left: 0.5rem;
  white-space: normal;
}

/* ── Input Area ───────────────────────────────────────── */
.repl-input-area {
  flex-shrink: 0;
  border-top: 1px solid var(--color-border);
  padding: 0.75rem 1.5rem 1rem;
  background: #fafbfd;
}

.repl-lang-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.5rem;
}

.repl-lang-label {
  font-size: 0.72rem;
  color: var(--color-muted);
  white-space: nowrap;
}


.repl-lang-spacer { flex: 1; }

.repl-lang-select {
  font-size: 0.78rem;
  padding: 0.2rem 0.4rem;
  border: 1px solid var(--color-border);
  border-radius: 4px;
  background: #fff;
  color: var(--color-text);
  margin: 0;
  height: auto;
  width: fit-content;
  white-space: nowrap;
  cursor: pointer;
}

.repl-lang-select:focus {
  outline: none;
  border-color: var(--color-primary);
}

.repl-lang-select[disabled] {
  opacity: 0.65;
  cursor: default;
}

.repl-textarea {
  display: block;
  width: 100%;
  box-sizing: border-box;
  font-family: var(--font-mono);
  font-size: 0.84rem;
  line-height: 1.55;
  resize: vertical;
  min-height: 76px;
  max-height: 220px;
  border: 1px solid var(--color-border);
  border-radius: 4px;
  padding: 0.5rem 0.75rem;
  background: #fff;
  color: var(--color-text);
  margin-bottom: 0.5rem;
}

.repl-textarea:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(53, 79, 163, 0.1);
}

.repl-actions-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.repl-table-btn {
  font-size: 0.78rem;
  color: var(--color-secondary);
  background: none;
  border: none;
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
  cursor: pointer;
  margin: 0;
}

.repl-table-btn:hover:not([disabled]) {
  background: var(--color-surface);
}

.repl-table-btn[disabled] {
  opacity: 0.35;
  cursor: default;
}

.repl-send-btn {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--color-accent);
  color: #fff;
  border: none;
  padding: 0.4rem 1.25rem;
  border-radius: 4px;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  margin: 0;
  transition: background 0.1s;
}

.repl-send-btn:hover:not([disabled]) {
  background: #d9751f;
}

.repl-send-btn[disabled] {
  opacity: 0.45;
  cursor: default;
}

.repl-send-btn kbd {
  font-size: 0.7rem;
  opacity: 0.75;
  background: rgba(255,255,255,0.2);
  border-radius: 3px;
  padding: 0.05rem 0.3rem;
  font-family: var(--font-mono);
}

/* ── Table Popup ──────────────────────────────────────── */
.table-overlay {
  position: fixed;
  inset: 0;
  background: rgba(26, 26, 46, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
}

.table-popup {
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.18);
  min-width: 540px;
  max-width: 82vw;
  max-height: 68vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.table-popup-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--color-border);
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--color-primary);
  flex-shrink: 0;
}

.table-popup-close {
  background: none;
  border: none;
  color: var(--color-muted);
  font-size: 1rem;
  cursor: pointer;
  padding: 0;
  margin: 0;
  line-height: 1;
}

.table-popup-close:hover {
  color: var(--color-text);
}

.table-popup-body {
  overflow-y: auto;
  padding: 0.75rem 1rem;
}

.table-popup-empty {
  color: var(--color-muted);
  font-size: 0.85rem;
  text-align: center;
  padding: 1.5rem 0;
}

.table-popup-body table {
  width: 100%;
  font-size: 0.82rem;
  border-collapse: collapse;
  margin: 0;
}

.table-popup-body thead th {
  text-align: left;
  padding: 0.4rem 0.6rem;
  background: var(--color-surface);
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-primary);
  border-bottom: 1px solid var(--color-border);
}

.table-popup-body tbody td {
  padding: 0.4rem 0.6rem;
  border-bottom: 1px solid #f0f3f9;
  font-family: var(--font-mono);
  vertical-align: top;
}

.belief-true    { color: #2e7d32; font-weight: 600; }
.belief-false   { color: #c62828; font-weight: 600; }
.belief-unknown { color: var(--color-muted); }
