/* ═══════════════════════════════════════════════════════════════════════════
   Entigui — Entity Execution Environment
   All classes prefixed .eg- — zero collision with Coretria or ck- namespaces
   Uses Coretria CSS variables for theme consistency.
   ═══════════════════════════════════════════════════════════════════════════ */

/* ── Layout Shell ─────────────────────────────────────────────────────────── */

.eg-root {
  display: flex;
  height: 100%;
  width: 100%;
  overflow: hidden;
  font-family: 'JetBrains Mono', 'Fira Mono', 'Cascadia Code', 'Consolas', monospace;
  font-size: 13px;
  background: var(--bg-main, #0d1117);
  color: var(--text-primary, #e6edf3);
  gap: 0;
  position: relative;
}

/* ── Board Column (left — entity card list) ───────────────────────────────── */

.eg-board {
  display: flex;
  flex-direction: column;
  width: 52%;
  min-width: 360px;
  border-right: 1px solid var(--border, #21262d);
  overflow: hidden;
}

.eg-board-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px 12px;
  border-bottom: 1px solid var(--border, #21262d);
  background: var(--bg-card, #161b22);
  flex-shrink: 0;
}

.eg-board-title {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-muted, #7d8590);
  margin: 0;
  flex: 1;
}

.eg-entity-count {
  font-size: 10px;
  color: var(--text-muted, #7d8590);
  background: var(--bg-main, #0d1117);
  border: 1px solid var(--border, #21262d);
  border-radius: 10px;
  padding: 1px 8px;
}

.eg-search-wrap {
  padding: 10px 16px;
  border-bottom: 1px solid var(--border, #21262d);
  background: var(--bg-card, #161b22);
  flex-shrink: 0;
}

.eg-search {
  width: 100%;
  background: var(--bg-main, #0d1117);
  border: 1px solid var(--border, #21262d);
  border-radius: 6px;
  color: var(--text-primary, #e6edf3);
  padding: 7px 12px 7px 32px;
  font-size: 12px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s;
  box-sizing: border-box;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%237d8590' stroke-width='2'%3E%3Ccircle cx='11' cy='11' r='8'/%3E%3Cpath d='m21 21-4.35-4.35'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: 10px center;
}

.eg-search:focus {
  border-color: var(--accent, #58a6ff);
}

.eg-search::placeholder { color: var(--text-muted, #7d8590); }

.eg-card-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.eg-card-list::-webkit-scrollbar { width: 4px; }
.eg-card-list::-webkit-scrollbar-track { background: transparent; }
.eg-card-list::-webkit-scrollbar-thumb { background: var(--border, #21262d); border-radius: 2px; }

/* ── Entity Card ──────────────────────────────────────────────────────────── */

.eg-card {
  background: var(--bg-card, #161b22);
  border: 1px solid var(--border, #21262d);
  border-radius: 8px;
  cursor: pointer;
  transition: border-color 0.12s, background 0.12s;
  overflow: hidden;
  flex-shrink: 0;
}

.eg-card:hover {
  border-color: var(--accent, #58a6ff);
}

.eg-card.eg-card--expanded {
  border-color: var(--accent, #58a6ff);
  background: var(--bg-card, #161b22);
}

.eg-card.eg-card--error {
  border-left: 3px solid #f85149;
}

.eg-card.eg-card--success {
  border-left: 3px solid #3fb950;
}

.eg-card-header {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 12px;
}

.eg-exit-badge {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  font-size: 10px;
  font-weight: 700;
  flex-shrink: 0;
  margin-top: 1px;
}

.eg-exit-badge--ok  { background: rgba(63, 185, 80, 0.15); color: #3fb950; }
.eg-exit-badge--err { background: rgba(248, 81, 73, 0.15); color: #f85149; }

.eg-card-meta {
  flex: 1;
  min-width: 0;
}

.eg-card-command {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-primary, #e6edf3);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-family: inherit;
  line-height: 1.4;
}

.eg-card-submeta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 3px;
}

.eg-card-cwd {
  font-size: 10px;
  color: var(--text-muted, #7d8590);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 200px;
}

.eg-card-time {
  font-size: 10px;
  color: var(--text-muted, #7d8590);
  white-space: nowrap;
  flex-shrink: 0;
}

.eg-card-runtime {
  font-size: 10px;
  color: var(--text-muted, #7d8590);
  white-space: nowrap;
  flex-shrink: 0;
}

.eg-card-actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
  opacity: 0;
  transition: opacity 0.12s;
}

.eg-card:hover .eg-card-actions { opacity: 1; }

.eg-action-btn {
  background: var(--bg-main, #0d1117);
  border: 1px solid var(--border, #21262d);
  border-radius: 4px;
  color: var(--text-muted, #7d8590);
  cursor: pointer;
  font-size: 11px;
  padding: 3px 7px;
  font-family: inherit;
  transition: color 0.1s, border-color 0.1s;
  white-space: nowrap;
}

.eg-action-btn:hover { color: var(--text-primary, #e6edf3); border-color: var(--accent, #58a6ff); }
.eg-action-btn--danger:hover { color: #f85149; border-color: #f85149; }

/* ── Expanded Card — Semantic Output Panel ────────────────────────────────── */

.eg-card-body {
  border-top: 1px solid var(--border, #21262d);
  display: none;
}

.eg-card--expanded .eg-card-body {
  display: block;
}

.eg-output-meta {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 8px 12px;
  background: var(--bg-main, #0d1117);
  border-bottom: 1px solid var(--border, #21262d);
  font-size: 10px;
  color: var(--text-muted, #7d8590);
  flex-wrap: wrap;
}

.eg-output-meta-item { display: flex; gap: 4px; align-items: center; }
.eg-output-meta-label { opacity: 0.6; }
.eg-output-meta-value { color: var(--text-primary, #e6edf3); font-weight: 500; }

.eg-stdout-wrap {
  padding: 10px 12px;
  max-height: 420px;
  overflow-y: auto;
  overflow-x: auto;
}

.eg-stdout-wrap::-webkit-scrollbar { width: 3px; height: 3px; }
.eg-stdout-wrap::-webkit-scrollbar-thumb { background: var(--border, #21262d); }

.eg-stdout {
  white-space: pre;
  font-family: inherit;
  font-size: 12px;
  line-height: 1.6;
  color: var(--text-primary, #e6edf3);
  margin: 0;
  word-break: break-all;
}

.eg-stdout--empty {
  color: var(--text-muted, #7d8590);
  font-style: italic;
}

/* Semantic regions */
.eg-region-path {
  color: #79c0ff;
  cursor: pointer;
  text-decoration: underline;
  text-decoration-color: rgba(121,192,255,0.3);
  text-underline-offset: 2px;
  border-radius: 2px;
  transition: background 0.1s;
}
.eg-region-path:hover { background: rgba(121,192,255,0.1); }

.eg-region-url {
  color: #58a6ff;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.eg-region-url:hover { opacity: 0.8; }

.eg-region-ipv4 {
  color: #ffa657;
  background: rgba(255,166,87,0.08);
  border-radius: 2px;
  padding: 0 2px;
}

.eg-region-http-ok  { color: #3fb950; font-weight: 600; }
.eg-region-http-err { color: #f85149; font-weight: 600; }
.eg-region-http-redir { color: #d29922; font-weight: 600; }

.eg-region-trace {
  color: #f85149;
  background: rgba(248,81,73,0.07);
  border-radius: 2px;
  padding: 0 2px;
}

.eg-region-json {
  color: #bc8cff;
  cursor: pointer;
}
.eg-region-json:hover { background: rgba(188,140,255,0.08); }

.eg-stderr-wrap {
  border-top: 1px solid rgba(248,81,73,0.25);
  padding: 8px 12px;
  max-height: 200px;
  overflow-y: auto;
  background: rgba(248,81,73,0.04);
}

.eg-stderr-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: #f85149;
  opacity: 0.7;
  margin-bottom: 6px;
}

.eg-stderr {
  white-space: pre;
  font-family: inherit;
  font-size: 12px;
  line-height: 1.6;
  color: #ffa198;
  margin: 0;
  word-break: break-all;
}

/* ── Empty State ──────────────────────────────────────────────────────────── */

.eg-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 200px;
  color: var(--text-muted, #7d8590);
  gap: 8px;
  text-align: center;
  padding: 20px;
}

.eg-empty-icon {
  font-size: 32px;
  opacity: 0.3;
}

.eg-empty-text {
  font-size: 12px;
  opacity: 0.6;
  line-height: 1.5;
}

/* ── Side Panel ───────────────────────────────────────────────────────────── */

.eg-side {
  display: flex;
  flex-direction: column;
  flex: 1;
  overflow: hidden;
  background: var(--bg-main, #0d1117);
}

/* ── Directory Navigator ──────────────────────────────────────────────────── */

.eg-nav {
  border-bottom: 1px solid var(--border, #21262d);
  background: var(--bg-card, #161b22);
  flex-shrink: 0;
}

.eg-nav-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px 8px;
  border-bottom: 1px solid var(--border, #21262d);
}

.eg-nav-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-muted, #7d8590);
  flex: 1;
}

.eg-breadcrumb {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0;
  padding: 6px 14px;
  font-size: 11px;
  min-height: 30px;
  overflow-x: auto;
}

.eg-breadcrumb::-webkit-scrollbar { height: 2px; }
.eg-breadcrumb::-webkit-scrollbar-thumb { background: var(--border, #21262d); }

.eg-crumb {
  color: var(--accent, #58a6ff);
  cursor: pointer;
  padding: 2px 3px;
  border-radius: 3px;
  transition: background 0.1s;
  white-space: nowrap;
  font-family: inherit;
}

.eg-crumb:hover { background: rgba(88,166,255,0.12); }

.eg-crumb-sep {
  color: var(--text-muted, #7d8590);
  padding: 0 1px;
  user-select: none;
}

.eg-crumb--current {
  color: var(--text-primary, #e6edf3);
  cursor: default;
  font-weight: 600;
}

.eg-crumb--current:hover { background: none; }

.eg-fs-list {
  max-height: 220px;
  overflow-y: auto;
  padding: 4px 0;
  border-top: 1px solid var(--border, #21262d);
}

.eg-fs-list::-webkit-scrollbar { width: 3px; }
.eg-fs-list::-webkit-scrollbar-thumb { background: var(--border, #21262d); }

.eg-fs-entry {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 14px;
  cursor: pointer;
  transition: background 0.1s;
  font-size: 12px;
  color: var(--text-primary, #e6edf3);
}

.eg-fs-entry:hover { background: rgba(255,255,255,0.04); }

.eg-fs-icon {
  font-size: 12px;
  width: 16px;
  text-align: center;
  flex-shrink: 0;
  opacity: 0.8;
}

.eg-fs-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.eg-fs-name--dir { color: #79c0ff; }
.eg-fs-name--file { color: var(--text-primary, #e6edf3); }

.eg-fs-size {
  font-size: 10px;
  color: var(--text-muted, #7d8590);
  flex-shrink: 0;
}

.eg-fs-loading {
  padding: 12px 14px;
  font-size: 11px;
  color: var(--text-muted, #7d8590);
}

/* ── Command Input ────────────────────────────────────────────────────────── */

.eg-input-area {
  padding: 12px 14px;
  background: var(--bg-card, #161b22);
  border-bottom: 1px solid var(--border, #21262d);
  flex-shrink: 0;
}

.eg-input-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-muted, #7d8590);
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.eg-cwd-display {
  font-size: 10px;
  color: var(--accent, #58a6ff);
  font-weight: 400;
  letter-spacing: 0;
  text-transform: none;
  opacity: 0.8;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 240px;
}

.eg-input-row {
  display: flex;
  gap: 8px;
  align-items: flex-start;
}

.eg-prompt-symbol {
  color: #3fb950;
  font-size: 14px;
  font-weight: 700;
  flex-shrink: 0;
  user-select: none;
  line-height: 1;
  margin-top: 10px;
}

.eg-prompt-symbol--admin { color: #f85149; }

.eg-command-input {
  flex: 1;
  background: var(--bg-main, #0d1117);
  border: 1px solid var(--border, #21262d);
  border-radius: 6px;
  color: var(--text-primary, #e6edf3);
  font-family: inherit;
  font-size: 13px;
  padding: 8px 12px;
  outline: none;
  transition: border-color 0.15s;
  caret-color: var(--accent, #58a6ff);
  resize: none;
  overflow: hidden;
  min-height: 36px;
  max-height: 200px;
  line-height: 1.5;
  box-sizing: border-box;
}

.eg-command-input:focus { border-color: var(--accent, #58a6ff); }
.eg-command-input::placeholder { color: var(--text-muted, #7d8590); }

.eg-card-multiline-badge {
  font-size: 9px;
  color: var(--accent, #58a6ff);
  background: rgba(88,166,255,0.12);
  border-radius: 3px;
  padding: 1px 5px;
  margin-left: 4px;
  vertical-align: middle;
  font-weight: 600;
  letter-spacing: 0.05em;
}

.eg-run-btn {
  background: var(--accent, #58a6ff);
  color: #0d1117;
  border: none;
  border-radius: 6px;
  padding: 8px 16px;
  font-family: inherit;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  transition: opacity 0.15s, background 0.15s;
  flex-shrink: 0;
  white-space: nowrap;
  margin-top: 1px;
}

.eg-run-btn:hover { opacity: 0.85; }
.eg-run-btn:disabled { opacity: 0.4; cursor: not-allowed; }

.eg-run-btn--running {
  background: var(--text-muted, #7d8590);
  display: flex;
  align-items: center;
  gap: 6px;
}

/* Spinner */
.eg-spinner {
  width: 12px;
  height: 12px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: eg-spin 0.6s linear infinite;
  flex-shrink: 0;
}

@keyframes eg-spin { to { transform: rotate(360deg); } }

/* ── Entity Log (bottom of side) ─────────────────────────────────────────── */

.eg-log {
  flex: 1;
  overflow-y: auto;
  padding: 10px 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.eg-log::-webkit-scrollbar { width: 3px; }
.eg-log::-webkit-scrollbar-thumb { background: var(--border, #21262d); }

.eg-log-entry {
  font-size: 11px;
  color: var(--text-muted, #7d8590);
  line-height: 1.4;
  display: flex;
  align-items: baseline;
  gap: 6px;
}

.eg-log-ts {
  color: var(--text-muted, #7d8590);
  opacity: 0.5;
  white-space: nowrap;
  flex-shrink: 0;
  font-size: 10px;
}

.eg-log-text { flex: 1; }
.eg-log-entry--ok .eg-log-text { color: #3fb950; }
.eg-log-entry--err .eg-log-text { color: #f85149; }
.eg-log-entry--info .eg-log-text { color: var(--accent, #58a6ff); }

/* ── CodeMirror Editor Overlay ────────────────────────────────────────────── */

.eg-editor-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  background: var(--bg-main, #0d1117);
  animation: eg-editor-in 0.15s ease;
}

@keyframes eg-editor-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.eg-editor-overlay.eg-editor-closing {
  animation: eg-editor-out 0.1s ease forwards;
}

@keyframes eg-editor-out {
  to { opacity: 0; transform: translateY(8px); }
}

.eg-editor-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  background: var(--bg-card, #161b22);
  border-bottom: 1px solid var(--border, #21262d);
  flex-shrink: 0;
}

.eg-editor-path {
  flex: 1;
  font-family: inherit;
  font-size: 12px;
  color: var(--text-primary, #e6edf3);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.eg-editor-lang {
  font-size: 10px;
  color: var(--text-muted, #7d8590);
  background: var(--bg-main, #0d1117);
  border: 1px solid var(--border, #21262d);
  border-radius: 4px;
  padding: 2px 8px;
  flex-shrink: 0;
}

.eg-editor-status {
  font-size: 11px;
  padding: 2px 10px;
  border-radius: 4px;
  flex-shrink: 0;
}

.eg-editor-status--saving { color: #d29922; }
.eg-editor-status--saved  { color: #3fb950; }
.eg-editor-status--error  { color: #f85149; }

.eg-editor-btn {
  background: none;
  border: 1px solid var(--border, #21262d);
  border-radius: 5px;
  color: var(--text-muted, #7d8590);
  cursor: pointer;
  font-family: inherit;
  font-size: 11px;
  padding: 4px 12px;
  transition: color 0.1s, border-color 0.1s;
  white-space: nowrap;
}

.eg-editor-btn:hover { color: var(--text-primary, #e6edf3); border-color: var(--accent, #58a6ff); }

.eg-editor-btn--save {
  background: var(--accent, #58a6ff);
  border-color: var(--accent, #58a6ff);
  color: #0d1117;
  font-weight: 700;
}

.eg-editor-btn--save:hover { opacity: 0.85; color: #0d1117; border-color: var(--accent, #58a6ff); }

.eg-editor-body {
  flex: 1;
  overflow: hidden;
  position: relative;
}

/* CodeMirror container fill */
.eg-editor-body .CodeMirror {
  height: 100%;
  font-family: 'JetBrains Mono', 'Fira Mono', 'Cascadia Code', 'Consolas', monospace;
  font-size: 13px;
  line-height: 1.6;
  background: #282a36; /* Dracula base — overridden by theme but safe fallback */
}

.eg-editor-body .CodeMirror-scroll {
  height: 100%;
}

/* ── Fork Modal ───────────────────────────────────────────────────────────── */

.eg-fork-backdrop {
  position: fixed;
  inset: 0;
  z-index: 9998;
  background: rgba(0,0,0,0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  animation: eg-fade-in 0.1s ease;
}

@keyframes eg-fade-in { from { opacity: 0; } to { opacity: 1; } }

.eg-fork-modal {
  background: var(--bg-card, #161b22);
  border: 1px solid var(--border, #21262d);
  border-radius: 10px;
  width: 540px;
  max-width: 90vw;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  animation: eg-editor-in 0.12s ease;
}

.eg-fork-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-primary, #e6edf3);
  margin: 0;
}

.eg-fork-field {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.eg-fork-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-muted, #7d8590);
}

.eg-fork-input {
  background: var(--bg-main, #0d1117);
  border: 1px solid var(--border, #21262d);
  border-radius: 6px;
  color: var(--text-primary, #e6edf3);
  font-family: inherit;
  font-size: 12px;
  padding: 8px 12px;
  outline: none;
  width: 100%;
  box-sizing: border-box;
  transition: border-color 0.15s;
}

.eg-fork-input:focus { border-color: var(--accent, #58a6ff); }

.eg-fork-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

/* ── Jail badge (shown to tenants) ───────────────────────────────────────── */

.eg-jail-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  background: rgba(210, 153, 34, 0.1);
  border: 1px solid rgba(210, 153, 34, 0.25);
  border-radius: 5px;
  font-size: 10px;
  color: #d29922;
  margin: 6px 14px 0;
  flex-shrink: 0;
}

/* ── Responsive truncation ────────────────────────────────────────────────── */

@media (max-width: 900px) {
  .eg-board { width: 100%; min-width: 0; border-right: none; }
  .eg-side  { display: none; }
  .eg-root.eg-mobile-input .eg-board { display: none; }
  .eg-root.eg-mobile-input .eg-side  { display: flex; width: 100%; }
}
