/* NeuralOps House — Pixel House styles */
:root {
  --bg-0: #2a2419;
  --bg-1: #3a3024;
  --paper: #f5efe2;
  --paper-soft: #ebe3d2;
  --ink: #2a2419;
  --ink-soft: #6b5f4a;
  --ink-faint: #a39880;
  --line: #d8cdb5;
  --line-soft: #ebe3d2;
  --accent: #d97757;
  --ok: #6fb38a;
  --busy: #e07a5a;
  --think: #7aa8d4;
  --warn: #e8b66c;
  --idle: #b3ad9f;
  --shadow: 0 1px 0 rgba(0,0,0,0.06), 0 8px 24px rgba(0,0,0,0.18);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: #1a1611;
  color: var(--ink);
  font-family: ui-sans-serif, system-ui, -apple-system, sans-serif;
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
  height: 100vh;
}

@font-face {
  font-family: "PixelMono";
  src: local("Press Start 2P");
}

#app {
  position: relative;
  width: 100vw;
  height: 100vh;
  display: grid;
  grid-template-columns: 260px 1fr 320px;
  grid-template-rows: 56px 1fr 200px;
  grid-template-areas:
    "header  header  header"
    "sidebar stage   profile"
    "sidebar log     profile";
  gap: 10px;
  padding: 10px;
  background: linear-gradient(180deg, #1a1611, #2a2218);
}

.loading {
  position: fixed; inset: 0;
  display: grid;
  place-items: center;
  background: #1a1611;
  color: var(--paper-soft);
  font-family: ui-monospace, monospace;
  font-size: 12px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}
.loading-bar { width: 200px; height: 6px; border: 1px solid var(--paper-soft); margin-bottom: 14px; }
.loading-bar-fill {
  width: 100%; height: 100%;
  background: var(--accent);
  animation: loadbar 1.4s ease-in-out infinite;
  transform-origin: left;
}
@keyframes loadbar { 0%,100% { transform: scaleX(0.2); } 50% { transform: scaleX(1); } }

/* Header */
.header {
  grid-area: header;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; }
.brand-mark {
  width: 28px; height: 28px;
  border-radius: 6px;
  background: var(--ink); color: var(--paper);
  display: grid; place-items: center;
  font-family: ui-monospace, monospace; font-size: 12px; font-weight: 700;
}
.brand-title { font-size: 14px; letter-spacing: 0.04em; }
.brand-sub { color: var(--ink-soft); font-size: 11px; font-family: ui-monospace, monospace; margin-left: 8px; }
.header-stats { display: flex; gap: 16px; font-family: ui-monospace, monospace; font-size: 12px; color: var(--ink-soft); }
.stat { display: flex; align-items: center; gap: 6px; }
.stat-num { color: var(--ink); font-weight: 600; }
.stat-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); animation: pulse 2s infinite; }
@keyframes pulse { 0%,100% { box-shadow: 0 0 0 3px rgba(111,179,138,0.18); } 50% { box-shadow: 0 0 0 6px rgba(111,179,138,0.05); } }

/* v3.8.2 — pulso de alerta para toasts y dots cuando aparece un nuevo CRITICAL */
@keyframes alertPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(224,122,90,0.5); transform: scale(1); }
  50%      { box-shadow: 0 0 0 6px rgba(224,122,90,0); transform: scale(1.05); }
}

.header-actions { display: flex; gap: 8px; }
.btn {
  padding: 6px 12px; border-radius: 6px;
  border: 1px solid var(--line); background: var(--paper);
  color: var(--ink); font-size: 12px; cursor: pointer; font-family: inherit;
}
.btn:hover { background: var(--paper-soft); }

/* Sidebar */
.sidebar {
  grid-area: sidebar;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow);
  display: flex; flex-direction: column;
  overflow: hidden;
}
.sidebar-head { padding: 14px 16px 8px; border-bottom: 1px solid var(--line-soft); }
.sidebar-title { font-size: 10px; font-family: ui-monospace, monospace; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-faint); }
.sidebar-count { font-size: 18px; font-weight: 600; }
.sidebar-count small { font-weight: 400; color: var(--ink-soft); font-size: 12px; margin-left: 6px; }
.team-list { flex: 1; overflow-y: auto; padding: 6px; }
.team-group { margin-bottom: 4px; }
.team-group-head { display: flex; align-items: center; gap: 8px; padding: 6px 8px; font-size: 10px; font-family: ui-monospace, monospace; text-transform: uppercase; color: var(--ink-soft); }
.team-group-dot { width: 8px; height: 8px; border-radius: 2px; }
.team-row {
  display: flex; align-items: center; gap: 8px;
  padding: 4px 6px; border-radius: 5px; cursor: pointer; font-size: 13px;
}
.team-row:hover { background: var(--paper-soft); }
.team-row.active { background: var(--paper-soft); box-shadow: inset 2px 0 0 var(--ink); }
.team-portrait {
  width: 28px; height: 28px;
  background: var(--paper-soft);
  border-radius: 4px;
  overflow: hidden;
  display: grid; place-items: center;
  flex-shrink: 0;
}
.team-portrait img {
  width: 96px; height: 32px;
  object-fit: none;
  object-position: -32px 0;
  transform: scale(1);
  margin-left: 0;
  /* Crop to first frame, down direction */
  width: 32px;
}
.team-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.team-status { width: 6px; height: 6px; border-radius: 50%; flex-shrink: 0; }
.team-status.busy { background: var(--busy); }
.team-status.idle { background: var(--idle); }
.team-status.thinking { background: var(--think); }
.team-status.meeting { background: var(--warn); }

/* Stage */
.stage {
  grid-area: stage;
  position: relative;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow);
  overflow: hidden;
  display: grid;
  place-items: center;
}
.stage-canvas-wrap {
  position: relative;
  display: block;
}
.stage-canvas-wrap canvas {
  display: block;
  cursor: pointer;
  border-radius: 6px;
  background: #1a1611;
}

.stage-legend {
  position: absolute;
  bottom: 10px; left: 10px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px 10px;
  display: flex; gap: 12px;
  font-size: 11px; font-family: ui-monospace, monospace; color: var(--ink-soft);
  z-index: 30;
}
.legend-item { display: flex; align-items: center; gap: 5px; }
.legend-dot { width: 8px; height: 8px; border-radius: 50%; }

.room-labels { position: absolute; inset: 0; pointer-events: none; }
.room-label {
  position: absolute;
  transform: translate(-50%, -100%);
  background: rgba(245, 239, 226, 0.95);
  border: 1px solid var(--line);
  padding: 2px 7px;
  border-radius: 4px;
  font-size: 10px;
  font-family: ui-monospace, monospace;
  letter-spacing: 0.04em;
  color: var(--ink);
  white-space: nowrap;
  display: flex;
  gap: 6px;
  align-items: center;
  z-index: 4;
}
.room-cap { font-weight: 600; text-transform: uppercase; font-size: 9px; }
.room-occ { color: var(--ink-faint); font-size: 9px; }

.bubbles { position: absolute; inset: 0; pointer-events: none; }
.bubble {
  position: absolute;
  transform: translate(-50%, -100%);
  background: var(--paper);
  border: 1px solid var(--ink);
  padding: 4px 8px;
  border-radius: 6px;
  font-size: 11px;
  white-space: nowrap;
  max-width: 200px;
  z-index: 25;
  box-shadow: 2px 2px 0 rgba(0,0,0,0.15);
  font-family: ui-monospace, monospace;
  animation: bubble-in 0.2s ease-out;
}
.bubble::after {
  content: "";
  position: absolute;
  bottom: -4px; left: 50%;
  width: 6px; height: 6px;
  background: var(--paper);
  border-right: 1px solid var(--ink);
  border-bottom: 1px solid var(--ink);
  transform: translateX(-50%) rotate(45deg);
}
@keyframes bubble-in { from { opacity: 0; transform: translate(-50%, -90%) scale(0.9); } to { opacity: 1; transform: translate(-50%, -100%) scale(1); } }

.bubble-idle {
  background: rgba(220, 220, 220, 0.9);
  color: #888;
  border-color: #b0b0b0;
  font-style: italic;
  opacity: 0.7;
  font-size: 10px;
}
.bubble-idle::after { background: rgba(220,220,220,0.9); border-color: #b0b0b0; }

/* ── Truncado inteligente v3.5 — mensajes largos no rompen layout ── */
.bubble {
  max-width: 240px;
  white-space: normal;
  word-break: break-word;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  line-height: 1.35;
}
.log-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}
.profile-current-task {
  word-break: break-word;
  /* v3.8.3 — sin recorte: mostramos el texto completo. Si es muy largo
     el propio .profile-body ya tiene scroll vertical, así que el bloque
     puede crecer libremente sin cortar nada. */
  max-height: none;
  overflow: visible;
  white-space: pre-wrap;
  line-height: 1.5;
}
.team-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Log */
.log-panel {
  grid-area: log;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow);
  display: flex; flex-direction: column;
  overflow: hidden;
}
.log-head { padding: 10px 14px; border-bottom: 1px solid var(--line-soft); display: flex; justify-content: space-between; align-items: center; }
.log-title { font-size: 10px; font-family: ui-monospace, monospace; text-transform: uppercase; letter-spacing: 0.08em; color: var(--ink-faint); }
.log-tag { font-size: 10px; font-family: ui-monospace, monospace; color: var(--ink-soft); background: var(--paper-soft); padding: 3px 7px; border-radius: 4px; }
.log-body { flex: 1; overflow-y: auto; padding: 6px 10px; font-family: ui-monospace, monospace; font-size: 12px; line-height: 1.45; }
.log-row { display: grid; grid-template-columns: 56px auto 1fr; gap: 10px; padding: 3px 4px; align-items: baseline; animation: log-in 0.3s ease-out; }
@keyframes log-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.log-time { color: var(--ink-faint); }
.log-agent { font-weight: 600; }
.log-text { color: var(--ink-soft); }

/* Profile */
.profile-panel {
  grid-area: profile;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow);
  display: flex; flex-direction: column;
  overflow: hidden;
}
.profile-empty { flex: 1; display: grid; place-items: center; text-align: center; padding: 24px; color: var(--ink-faint); font-size: 13px; }
.profile-empty-icon { font-size: 28px; margin-bottom: 8px; }
.profile-empty p { margin: 0; max-width: 200px; line-height: 1.5; }
.profile-head { padding: 16px 18px; border-bottom: 1px solid var(--line-soft); display: flex; gap: 12px; align-items: flex-start; }
.profile-portrait {
  width: 48px; height: 48px;
  border-radius: 8px;
  overflow: hidden;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  background: var(--paper-soft);
}
.profile-portrait img {
  width: 32px; height: 32px;
  object-fit: none;
  object-position: -32px 0;
  image-rendering: pixelated;
  transform: scale(1.4);
}
.profile-name { font-size: 16px; font-weight: 600; }
.profile-role { font-size: 12px; color: var(--ink-soft); margin-top: 2px; }
.profile-close { margin-left: auto; background: none; border: none; color: var(--ink-faint); cursor: pointer; font-size: 18px; line-height: 1; }
.profile-close:hover { color: var(--ink); }
.profile-body { flex: 1; overflow-y: auto; padding: 14px 18px; }
.profile-section { margin-bottom: 16px; }
.profile-label { font-size: 10px; font-family: ui-monospace, monospace; text-transform: uppercase; letter-spacing: 0.08em; color: var(--ink-faint); margin-bottom: 6px; }
.profile-status-row { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.profile-current-task { background: var(--paper-soft); border-radius: 6px; padding: 10px 12px; font-size: 13px; line-height: 1.5; }
.profile-stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.profile-stat { background: var(--paper-soft); border-radius: 5px; padding: 7px 10px; }
.profile-stat-num { font-size: 18px; font-weight: 600; font-family: ui-monospace, monospace; }
.profile-stat-lbl { font-size: 11px; color: var(--ink-soft); font-family: ui-monospace, monospace; }
.profile-tag { font-size: 11px; background: var(--paper-soft); padding: 3px 8px; border-radius: 4px; font-family: ui-monospace, monospace; color: var(--ink-soft); }
.profile-history { font-family: ui-monospace, monospace; font-size: 11px; color: var(--ink-soft); line-height: 1.6; }
.profile-history-row { display: grid; grid-template-columns: 50px 1fr; gap: 8px; padding: 3px 0; border-bottom: 1px dashed var(--line-soft); }
.profile-history-row:last-child { border-bottom: none; }
.profile-history-time { color: var(--ink-faint); }

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--line); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--ink-faint); }
