/* ==========================================================================
   Sistema visual — Obsidian Atelier (oscuro) & Paper Studio (claro)
   100 % CSP-safe (sin estilos en línea ni fuentes externas)
   ========================================================================== */
:root {
  --font-sans: "Inter", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;

  --radius-xs: 6px;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  --radius-pill: 999px;

  --sidebar-w: 260px;
  --inspector-w: 320px;
  --topbar-h: 54px;

  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
}

:root,
[data-theme="dark"] {
  color-scheme: dark;
  --bg-app: #0a0b0e;
  --bg-rail: #0f1116;
  --bg-surface: #151820;
  --bg-surface-2: #1c202a;
  --bg-surface-3: #242936;
  --bg-user: #1b202b;
  --bg-code: #0d0f14;
  --bg-code-head: #12151c;
  --bg-overlay: rgba(7, 8, 11, 0.74);

  --border-hairline: rgba(255, 255, 255, 0.065);
  --border-subtle: rgba(255, 255, 255, 0.1);
  --border-strong: rgba(255, 255, 255, 0.18);
  --inset-highlight: inset 0 1px 0 rgba(255, 255, 255, 0.045);

  --ink-1: #f2f4f8;
  --ink-2: #a0a8b8;
  --ink-3: #687182;

  --brand: #e08458;
  --brand-soft: rgba(224, 132, 88, 0.14);
  --brand-border: rgba(224, 132, 88, 0.34);

  --primary-bg: #f2f4f8;
  --primary-bg-hover: #ffffff;
  --primary-ink: #0a0b0e;

  --hover-quiet: rgba(255, 255, 255, 0.035);
  --active-quiet: rgba(255, 255, 255, 0.065);

  --ok: #34d399;
  --ok-soft: rgba(52, 211, 153, 0.12);
  --ok-border: rgba(52, 211, 153, 0.28);

  --warn: #f5b14c;
  --warn-soft: rgba(245, 177, 76, 0.12);
  --warn-border: rgba(245, 177, 76, 0.34);

  --err: #f26d6d;
  --err-soft: rgba(242, 109, 109, 0.12);
  --err-border: rgba(242, 109, 109, 0.34);

  --idle: #6b7485;

  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.28);
  --shadow-md: 0 10px 30px rgba(0, 0, 0, 0.42);
  --shadow-lg: 0 24px 64px rgba(0, 0, 0, 0.62);
}

[data-theme="light"] {
  color-scheme: light;
  --bg-app: #ffffff;
  --bg-rail: #f6f6f4;
  --bg-surface: #ffffff;
  --bg-surface-2: #f1f2f4;
  --bg-surface-3: #e6e8ec;
  --bg-user: #f3f2ee;
  --bg-code: #f7f8fa;
  --bg-code-head: #eff1f5;
  --bg-overlay: rgba(15, 18, 24, 0.42);

  --border-hairline: rgba(15, 23, 42, 0.075);
  --border-subtle: rgba(15, 23, 42, 0.12);
  --border-strong: rgba(15, 23, 42, 0.22);
  --inset-highlight: inset 0 1px 0 rgba(255, 255, 255, 0.8);

  --ink-1: #111318;
  --ink-2: #525b6a;
  --ink-3: #838d9e;

  --brand: #c96234;
  --brand-soft: rgba(201, 98, 52, 0.1);
  --brand-border: rgba(201, 98, 52, 0.3);

  --primary-bg: #14171f;
  --primary-bg-hover: #232834;
  --primary-ink: #ffffff;

  --hover-quiet: rgba(15, 23, 42, 0.04);
  --active-quiet: rgba(15, 23, 42, 0.065);

  --ok: #0e9f6e;
  --ok-soft: rgba(14, 159, 110, 0.1);
  --ok-border: rgba(14, 159, 110, 0.28);

  --warn: #c4760c;
  --warn-soft: rgba(196, 118, 12, 0.1);
  --warn-border: rgba(196, 118, 12, 0.3);

  --err: #cf3636;
  --err-soft: rgba(207, 54, 54, 0.09);
  --err-border: rgba(207, 54, 54, 0.28);

  --idle: #8c95a6;

  --shadow-sm: 0 2px 8px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 10px 30px rgba(15, 23, 42, 0.1);
  --shadow-lg: 0 24px 64px rgba(15, 23, 42, 0.16);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

/* `hidden` tiene que ganarle a cualquier `display` propio para que pantallas y paneles se oculten de verdad. */
[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg-app);
  color: var(--ink-1);
  font-family: var(--font-sans);
  font-size: 14.5px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow: hidden;
}

button,
input,
textarea {
  font: inherit;
  color: inherit;
}

button {
  border: 0;
  background: none;
  padding: 0;
  cursor: pointer;
}

button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

button:focus-visible,
input:focus-visible,
textarea:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}

::-webkit-scrollbar {
  width: 7px;
  height: 7px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: var(--border-subtle);
  border-radius: 999px;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--border-strong);
}

.ic {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  display: block;
}
.ic-sm {
  width: 14px;
  height: 14px;
}
.ic-lg {
  width: 20px;
  height: 20px;
}
.crece {
  flex: 1;
}

/* ==========================================================================
   Shell y Sidebar
   ========================================================================== */
.app-shell {
  display: flex;
  height: 100dvh;
  width: 100%;
  overflow: hidden;
  position: relative;
}

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--bg-rail);
  border-right: 1px solid var(--border-hairline);
  display: flex;
  flex-direction: column;
  transition: margin-left 0.22s var(--ease-out), transform 0.22s var(--ease-out);
  z-index: 30;
  user-select: none;
}

.app-shell.sidebar-collapsed .sidebar {
  margin-left: calc(var(--sidebar-w) * -1);
}

.sidebar-backdrop {
  position: fixed;
  inset: 0;
  background: var(--bg-overlay);
  backdrop-filter: blur(4px);
  z-index: 25;
}

.sidebar-head {
  height: var(--topbar-h);
  padding: 0 10px 0 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  border-bottom: 1px solid var(--border-hairline);
}

.host-ident {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--ink-1);
}
.host-ident-ic {
  color: var(--ink-2);
}
.host-ident-name {
  font-size: 13.5px;
  font-weight: 600;
  letter-spacing: -0.015em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.icon-btn {
  width: 30px;
  height: 30px;
  border-radius: var(--radius-sm);
  display: grid;
  place-items: center;
  color: var(--ink-2);
  transition: background 0.14s ease, color 0.14s ease;
}
.icon-btn:hover {
  background: var(--bg-surface-2);
  color: var(--ink-1);
}

.sidebar-search {
  padding: 10px 10px 4px;
}

.search-box {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 34px;
  padding: 0 10px;
  border-radius: var(--radius-sm);
  background: var(--bg-surface);
  border: 1px solid var(--border-hairline);
  color: var(--ink-3);
}
.search-box:focus-within {
  border-color: var(--border-strong);
  color: var(--ink-2);
}
.search-box input {
  width: 100%;
  border: 0;
  background: transparent;
  outline: none;
  font-size: 12.5px;
  color: var(--ink-1);
}
.search-box input::placeholder {
  color: var(--ink-3);
}
.kbd {
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--ink-3);
  padding: 1px 5px;
  border-radius: 4px;
  border: 1px solid var(--border-hairline);
  background: var(--bg-rail);
  flex-shrink: 0;
}

.sidebar-section-label {
  padding: 12px 12px 6px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink-3);
}

.count-badge {
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-weight: 500;
  padding: 1px 6px;
  border-radius: var(--radius-pill);
  background: var(--bg-surface-2);
  color: var(--ink-2);
}

.session-list {
  list-style: none;
  margin: 0;
  padding: 2px 8px 12px;
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.session-row {
  position: relative;
  display: flex;
  align-items: center;
}

.session-item {
  width: 100%;
  text-align: left;
  height: 36px;
  padding: 0 10px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--ink-2);
  transition: background 0.14s ease, color 0.14s ease;
}

.session-item:hover {
  background: var(--hover-quiet);
  color: var(--ink-1);
}

.session-item.is-open {
  background: var(--active-quiet);
  color: var(--ink-1);
}

.session-item-name {
  font-size: 13.5px;
  font-weight: 450;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
  min-width: 0;
}
.session-item.is-open .session-item-name {
  font-weight: 550;
}

.session-split-btn {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  width: 24px;
  height: 24px;
  border-radius: 6px;
  display: grid;
  place-items: center;
  background: var(--bg-surface-2);
  border: 1px solid var(--border-hairline);
  color: var(--ink-2);
  opacity: 0;
  transition: opacity 0.14s ease, background 0.14s ease, color 0.14s ease;
}
.session-row:hover .session-split-btn,
.session-split-btn:focus-visible {
  opacity: 1;
}
.session-split-btn:hover {
  background: var(--bg-surface-3);
  color: var(--ink-1);
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
  position: relative;
}
.status-dot.inactiva {
  background: var(--idle);
  opacity: 0.55;
}
.status-dot.working {
  background: var(--ok);
}
.status-dot.working::after {
  content: "";
  position: absolute;
  inset: -3px;
  border-radius: 50%;
  border: 1.5px solid var(--ok);
  animation: pulse-ring 1.7s var(--ease-out) infinite;
}
.status-dot.waiting_for_user {
  background: var(--warn);
}
.status-dot.waiting_for_user::after {
  content: "";
  position: absolute;
  inset: -3px;
  border-radius: 50%;
  border: 1.5px solid var(--warn);
  animation: pulse-ring 1.4s var(--ease-out) infinite;
}
.status-dot.failed {
  background: var(--err);
}

@keyframes pulse-ring {
  0% {
    transform: scale(0.75);
    opacity: 0.9;
  }
  100% {
    transform: scale(1.9);
    opacity: 0;
  }
}

.sidebar-empty {
  margin: 8px 12px;
  font-size: 12.5px;
  color: var(--ink-3);
  line-height: 1.5;
}
.sidebar-empty code {
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--ink-2);
  background: var(--bg-surface-2);
  padding: 1px 5px;
  border-radius: 4px;
  white-space: nowrap;
}

.sidebar-foot {
  padding: 8px;
  border-top: 1px solid var(--border-hairline);
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.rail-action {
  width: 100%;
  height: 34px;
  padding: 0 10px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 13px;
  color: var(--ink-2);
  transition: background 0.14s ease, color 0.14s ease;
}
.rail-action:hover {
  background: var(--bg-surface-2);
  color: var(--ink-1);
}

.user-row {
  margin-top: 4px;
  padding: 8px 10px;
  border-radius: var(--radius-md);
  background: var(--bg-surface);
  border: 1px solid var(--border-hairline);
  display: flex;
  align-items: center;
  gap: 9px;
}

.user-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--bg-surface-3);
  border: 1px solid var(--border-subtle);
  font-size: 11px;
  font-weight: 600;
  color: var(--ink-1);
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.user-info {
  min-width: 0;
  flex: 1;
}
.user-email {
  font-size: 12.5px;
  font-weight: 500;
  color: var(--ink-1);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.user-device {
  font-size: 11px;
  color: var(--ink-3);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ==========================================================================
   Área principal, Topbar y avisos
   ========================================================================== */
.workspace-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg-app);
  position: relative;
}

.aviso.certificado {
  margin: 0;
  padding: 8px 16px;
  background: var(--warn-soft);
  border-bottom: 1px solid var(--warn-border);
  color: var(--warn);
  font-size: 12.5px;
}
.aviso.certificado.vencido {
  background: var(--err-soft);
  border-bottom-color: var(--err-border);
  color: var(--err);
}

.topbar {
  height: var(--topbar-h);
  flex-shrink: 0;
  padding: 0 14px;
  border-bottom: 1px solid var(--border-hairline);
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg-app);
}

@media (min-width: 901px) {
  .app-shell:not(.sidebar-collapsed) #btn-abrir-sidebar {
    display: none;
  }
}

.topbar-title-group {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
}

.topbar-session-name {
  font-size: 14px;
  font-weight: 600;
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-cwd {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--ink-3);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-sep {
  color: var(--border-strong);
  font-size: 12px;
}

.estado {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 9px;
  border-radius: var(--radius-pill);
  font-size: 11.5px;
  font-weight: 500;
  border: 1px solid var(--border-hairline);
  background: var(--bg-surface);
  color: var(--ink-2);
  flex-shrink: 0;
}
.estado.working {
  color: var(--ok);
  background: var(--ok-soft);
  border-color: var(--ok-border);
}
.estado.waiting_for_user {
  color: var(--warn);
  background: var(--warn-soft);
  border-color: var(--warn-border);
}
.estado.failed {
  color: var(--err);
  background: var(--err-soft);
  border-color: var(--err-border);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.pill-btn {
  height: 30px;
  padding: 0 10px;
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--ink-2);
  border: 1px solid transparent;
  transition: background 0.14s ease, color 0.14s ease, border-color 0.14s ease;
}
.pill-btn:hover {
  background: var(--bg-surface-2);
  color: var(--ink-1);
}
.pill-btn.active {
  background: var(--bg-surface-2);
  border-color: var(--border-subtle);
  color: var(--ink-1);
}

/* ==========================================================================
   Paneles, Empty Stage y Transcript (+10 % ancho: 840px)
   ========================================================================== */
.content-row {
  flex: 1;
  min-height: 0;
  display: flex;
  overflow: hidden;
}

.empty-stage {
  flex: 1;
  display: grid;
  place-items: center;
  padding: 24px;
}
.empty-stage-card {
  max-width: 380px;
  text-align: center;
}
.empty-stage-title {
  margin: 0 0 6px;
  font-size: 15.5px;
  font-weight: 600;
  color: var(--ink-1);
}
.empty-stage-sub {
  margin: 0;
  font-size: 13.5px;
  color: var(--ink-3);
  line-height: 1.55;
}

.panels-grid {
  flex: 1;
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-columns: 1fr;
  background: var(--border-hairline);
  gap: 1px;
}
.panels-grid.multi {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  grid-auto-rows: minmax(0, 1fr);
}

.panel-sesion {
  background: var(--bg-app);
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
  position: relative;
}

.panel-barra {
  display: none;
  height: 42px;
  flex-shrink: 0;
  padding: 0 10px 0 14px;
  border-bottom: 1px solid var(--border-hairline);
  align-items: center;
  gap: 8px;
  background: var(--bg-rail);
}
.panels-grid.multi .panel-barra {
  display: flex;
}
.panel-sesion.is-focused .panel-barra {
  box-shadow: inset 0 2px 0 var(--brand);
}
.panel-barra .sesion {
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.transcript-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 20px 24px 28px;
}
.panels-grid.multi .transcript-scroll {
  padding: 16px 18px 20px;
}

.transcript-inner {
  max-width: 840px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 18px;
}
.panels-grid.multi .transcript-inner {
  max-width: 100%;
}

.older-row {
  display: flex;
  justify-content: center;
}
.older-btn {
  height: 30px;
  padding: 0 12px;
  border-radius: var(--radius-pill);
  background: var(--bg-surface);
  border: 1px solid var(--border-hairline);
  color: var(--ink-2);
  font-size: 12px;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.older-btn:hover {
  background: var(--bg-surface-2);
  border-color: var(--border-subtle);
  color: var(--ink-1);
}

.transcript {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* Mensajes: usuario a la derecha, modelo limpio a la izquierda (sin encabezados ni avatar) */
.mensaje {
  margin: 0;
}

.mensaje.user {
  display: flex;
  justify-content: flex-end;
}
.mensaje.user .texto {
  max-width: 82%;
  padding: 11px 16px;
  border-radius: 18px 18px 5px 18px;
  background: var(--bg-user);
  border: 1px solid var(--border-hairline);
  color: var(--ink-1);
  font-size: 14.5px;
  line-height: 1.55;
  box-shadow: var(--inset-highlight);
}
.mensaje.user .texto p {
  margin: 0;
}
.mensaje.user .texto p + p {
  margin-top: 8px;
}

.mensaje.assistant .texto {
  color: var(--ink-1);
  font-size: 14.5px;
  line-height: 1.65;
}
.mensaje.assistant .texto > *:first-child {
  margin-top: 0;
}
.mensaje.assistant .texto > *:last-child {
  margin-bottom: 0;
}
.mensaje.assistant .texto p {
  margin: 0 0 11px;
}
.mensaje.assistant .texto h1,
.mensaje.assistant .texto h2,
.mensaje.assistant .texto h3,
.mensaje.assistant .texto h4,
.mensaje.assistant .texto h5,
.mensaje.assistant .texto h6 {
  margin: 16px 0 7px;
  font-size: 15px;
  font-weight: 650;
  letter-spacing: -0.01em;
}
.mensaje.assistant .texto ul,
.mensaje.assistant .texto ol {
  margin: 0 0 12px;
  padding-left: 20px;
}
.mensaje.assistant .texto li {
  margin-bottom: 5px;
}
.mensaje.assistant .texto li::marker {
  color: var(--ink-3);
}

.mensaje .texto code {
  font-family: var(--font-mono);
  font-size: 0.86em;
  padding: 1.5px 5.5px;
  border-radius: 5px;
  background: var(--bg-surface-2);
  border: 1px solid var(--border-hairline);
}

/* Bloques de código */
.code-card {
  margin: 12px 0;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
  background: var(--bg-code);
  overflow: hidden;
}
.code-card-head {
  height: 34px;
  padding: 0 10px 0 13px;
  background: var(--bg-code-head);
  border-bottom: 1px solid var(--border-hairline);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.code-lang {
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--ink-3);
}
.copy-btn {
  height: 24px;
  padding: 0 8px;
  border-radius: 6px;
  font-size: 11.5px;
  font-weight: 500;
  color: var(--ink-2);
  display: inline-flex;
  align-items: center;
  gap: 5px;
}
.copy-btn:hover {
  background: var(--bg-surface-2);
  color: var(--ink-1);
}
.copy-btn.copied {
  color: var(--ok);
}

.mensaje .texto pre.codigo {
  margin: 0;
  padding: 13px 15px;
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: 12.5px;
  line-height: 1.62;
  tab-size: 2;
  font-variant-ligatures: none;
  background: var(--bg-code);
}
.mensaje .texto pre.codigo code {
  white-space: pre;
  background: none;
  border: 0;
  padding: 0;
  font-size: inherit;
}

/* Herramientas plegables en línea cronológica dentro del transcript */
.mensaje.tool {
  border-radius: var(--radius-md);
  border: 1px solid var(--border-hairline);
  background: var(--bg-surface);
  overflow: hidden;
}
.mensaje.tool + .mensaje.tool {
  margin-top: -14px;
}

.tool-row + .tool-row {
  border-top: 1px solid var(--border-hairline);
}

.tool-trigger {
  width: 100%;
  padding: 8px 11px;
  display: flex;
  align-items: center;
  gap: 9px;
  text-align: left;
}
.tool-trigger:hover {
  background: var(--bg-surface-2);
}
.tool-status-ic {
  width: 18px;
  height: 18px;
  border-radius: 5px;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}
.tool-status-ic.ok {
  background: var(--ok-soft);
  color: var(--ok);
}
.tool-status-ic.running {
  background: var(--brand-soft);
  color: var(--brand);
}
.tool-status-ic.error {
  background: var(--err-soft);
  color: var(--err);
}
.spin {
  animation: spin 0.9s linear infinite;
}
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}
.tool-name {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 500;
  color: var(--ink-1);
  flex-shrink: 0;
}
.tool-summary {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--ink-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
  min-width: 0;
}
.tool-chevron {
  color: var(--ink-3);
  transition: transform 0.16s var(--ease-out);
}
.tool-row.open .tool-chevron {
  transform: rotate(90deg);
}
.tool-detail {
  display: none;
  padding: 10px 12px 12px;
  border-top: 1px solid var(--border-hairline);
  background: var(--bg-code);
}
.tool-row.open .tool-detail {
  display: block;
}
.tool-detail-label {
  font-size: 10.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--ink-3);
  margin-bottom: 5px;
}
.tool-detail pre {
  margin: 0;
  font-family: var(--font-mono);
  font-size: 11.8px;
  line-height: 1.55;
  color: var(--ink-2);
  max-height: 220px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
}
.tool-detail pre + .tool-detail-label {
  margin-top: 10px;
}

.stream-cursor {
  display: inline-block;
  width: 7px;
  height: 15px;
  margin-left: 2px;
  vertical-align: -2px;
  border-radius: 2px;
  background: var(--brand);
  animation: blink 0.9s steps(2, start) infinite;
}
@keyframes blink {
  0%,
  49% {
    opacity: 1;
  }
  50%,
  100% {
    opacity: 0;
  }
}

.scroll-bottom-btn {
  position: absolute;
  bottom: 132px;
  left: 50%;
  transform: translateX(-50%);
  height: 32px;
  padding: 0 12px;
  border-radius: var(--radius-pill);
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  box-shadow: var(--shadow-md);
  color: var(--ink-1);
  font-size: 12px;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  z-index: 5;
}

/* ==========================================================================
   Dock: Diálogo UI y Compositor flotante
   ========================================================================== */
.composer-dock {
  flex-shrink: 0;
  padding: 0 24px calc(16px + env(safe-area-inset-bottom));
  background: linear-gradient(180deg, transparent, var(--bg-app) 22%);
}
.panels-grid.multi .composer-dock {
  padding: 0 16px 14px;
}

.composer-inner {
  max-width: 840px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  position: relative;
}
.panels-grid.multi .composer-inner {
  max-width: 100%;
}

.dialogo {
  border-radius: var(--radius-lg);
  background: var(--bg-surface);
  border: 1px solid var(--warn-border);
  box-shadow: var(--shadow-md), inset 0 2px 0 var(--warn);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.dialogo-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--warn);
}
.dialogo-titulo {
  margin: 0;
  font-size: 14.5px;
  font-weight: 600;
}
.dialogo-mensaje {
  margin: 0;
  font-size: 13px;
  color: var(--ink-2);
  line-height: 1.5;
}
.dialogo-opciones {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.dialogo-opciones button {
  width: 100%;
  padding: 9px 12px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
  background: var(--bg-app);
  display: flex;
  align-items: center;
  gap: 10px;
  text-align: left;
  font-size: 13.5px;
}
.dialogo-opciones button:hover {
  border-color: var(--brand-border);
  background: var(--bg-surface-2);
}
.prompt-opt-num {
  width: 22px;
  height: 22px;
  border-radius: 6px;
  background: var(--bg-surface-2);
  border: 1px solid var(--border-hairline);
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink-2);
  display: grid;
  place-items: center;
  flex-shrink: 0;
}
.dialogo-texto input,
.dialogo-texto textarea {
  width: 100%;
  padding: 9px 12px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
  background: var(--bg-app);
  color: var(--ink-1);
  outline: none;
  font-size: 13.5px;
}
.dialogo-texto textarea {
  font-family: var(--font-mono);
  font-size: 12.5px;
  min-height: 92px;
  resize: vertical;
}
.dialogo-texto input:focus,
.dialogo-texto textarea:focus {
  border-color: var(--brand);
}
.acciones {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.compositor-bloqueado {
  padding: 10px 14px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-hairline);
  background: var(--bg-rail);
  font-size: 12.5px;
  color: var(--ink-3);
}

.compositor {
  border-radius: var(--radius-xl);
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  box-shadow: var(--shadow-sm), var(--inset-highlight);
  display: flex;
  flex-direction: column;
  transition: border-color 0.16s ease, box-shadow 0.16s ease;
}
.compositor:focus-within {
  border-color: var(--border-strong);
  box-shadow: var(--shadow-md), 0 0 0 3px var(--brand-soft);
}
.compositor .prompt {
  width: 100%;
  border: 0;
  background: transparent;
  outline: none;
  resize: none;
  padding: 13px 16px 6px;
  min-height: 46px;
  max-height: 180px;
  font-size: 14.5px;
  line-height: 1.5;
  color: var(--ink-1);
}
.compositor .prompt::placeholder {
  color: var(--ink-3);
}
.compositor-barra {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 10px 9px 11px;
  flex-wrap: wrap;
}
.compositor-controles {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
  position: relative;
}
.chip-btn {
  height: 28px;
  padding: 0 9px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-weight: 500;
  color: var(--ink-2);
  display: inline-flex;
  align-items: center;
  gap: 5px;
  border: 1px solid transparent;
}
.chip-btn:hover,
.chip-btn.open {
  background: var(--bg-surface-2);
  color: var(--ink-1);
}
.chip-btn.open {
  border-color: var(--border-subtle);
}
.chip-mono {
  font-family: var(--font-mono);
  font-size: 11.5px;
}

.context-ring {
  width: 15px;
  height: 15px;
  transform: rotate(-90deg);
}
.context-ring circle {
  fill: none;
  stroke-width: 2.4;
}
.context-ring .ring-bg {
  stroke: var(--border-subtle);
}
.context-ring .ring-fg {
  stroke: var(--brand);
  stroke-linecap: round;
}

.compositor-derecha {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
}

.deliver-toggle {
  display: inline-flex;
  padding: 2px;
  border-radius: var(--radius-sm);
  background: var(--bg-app);
  border: 1px solid var(--border-hairline);
}
.deliver-toggle button {
  height: 24px;
  padding: 0 8px;
  border-radius: 6px;
  font-size: 11.5px;
  font-weight: 500;
  color: var(--ink-3);
}
.deliver-toggle button.active {
  background: var(--bg-surface-2);
  color: var(--ink-1);
}

.send-btn {
  width: 32px;
  height: 32px;
  border-radius: 10px;
  background: var(--primary-bg);
  color: var(--primary-ink);
  display: grid;
  place-items: center;
}
.send-btn:hover:not(:disabled) {
  background: var(--primary-bg-hover);
}
.send-btn:disabled {
  opacity: 0.28;
}

.abort-btn {
  height: 32px;
  padding: 0 11px;
  border-radius: 10px;
  background: var(--err-soft);
  border: 1px solid var(--err-border);
  color: var(--err);
  font-size: 12px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.abort-btn:hover {
  background: var(--err);
  color: #ffffff;
}

/* Popover dentro del compositor */
.popover-panel {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 0;
  min-width: 252px;
  max-width: 310px;
  border-radius: var(--radius-md);
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  box-shadow: var(--shadow-lg), var(--inset-highlight);
  padding: 6px;
  z-index: 40;
}
.popover-title {
  padding: 5px 8px 6px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--ink-3);
}
.popover-opt {
  width: 100%;
  padding: 7px 9px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  text-align: left;
  font-size: 12.5px;
  color: var(--ink-1);
}
.popover-opt:hover {
  background: var(--bg-surface-2);
}
.popover-opt.selected {
  background: var(--brand-soft);
  color: var(--brand);
}
.popover-sub {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink-3);
}
.popover-opt.selected .popover-sub {
  color: var(--brand);
}

.ctx-popover-body {
  padding: 6px 8px 4px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.ctx-progress {
  width: 100%;
  height: 6px;
  border: 0;
  border-radius: 999px;
  overflow: hidden;
  background: var(--bg-surface-2);
  accent-color: var(--brand);
}
.ctx-progress::-webkit-progress-bar {
  background: var(--bg-surface-2);
  border-radius: 999px;
}
.ctx-progress::-webkit-progress-value {
  background: var(--brand);
  border-radius: 999px;
}
.ctx-progress::-moz-progress-bar {
  background: var(--brand);
  border-radius: 999px;
}
.ctx-grid {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 12px;
  font-size: 12px;
}
.ctx-grid span:nth-child(odd) {
  color: var(--ink-3);
}
.ctx-grid span:nth-child(even) {
  font-family: var(--font-mono);
  color: var(--ink-1);
  text-align: right;
}

/* ==========================================================================
   Botones reutilizables
   ========================================================================== */
.btn {
  height: 34px;
  padding: 0 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 550;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
}
.btn-primary {
  background: var(--primary-bg);
  color: var(--primary-ink);
}
.btn-primary:hover {
  background: var(--primary-bg-hover);
}
.btn-secondary {
  background: var(--bg-surface-2);
  border: 1px solid var(--border-subtle);
  color: var(--ink-1);
}
.btn-secondary:hover {
  background: var(--bg-surface-3);
}
.btn-ghost {
  color: var(--ink-2);
}
.btn-ghost:hover {
  background: var(--bg-surface-2);
  color: var(--ink-1);
}
.btn-danger {
  background: var(--err-soft);
  border: 1px solid var(--err-border);
  color: var(--err);
}
.btn-danger:hover {
  background: var(--err);
  color: #ffffff;
}
.btn-full {
  width: 100%;
}
.btn-sm {
  height: 30px;
  padding: 0 11px;
  font-size: 12px;
}

/* ==========================================================================
   Inspector lateral (Árbol y Métricas)
   ========================================================================== */
.inspector {
  width: var(--inspector-w);
  flex-shrink: 0;
  border-left: 1px solid var(--border-hairline);
  background: var(--bg-rail);
  display: flex;
  flex-direction: column;
  z-index: 20;
}
.inspector-head {
  height: 46px;
  padding: 0 12px;
  border-bottom: 1px solid var(--border-hairline);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.seg-tabs {
  display: inline-flex;
  padding: 3px;
  border-radius: var(--radius-sm);
  background: var(--bg-surface);
  border: 1px solid var(--border-hairline);
}
.seg-tab {
  height: 26px;
  padding: 0 11px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 550;
  color: var(--ink-3);
}
.seg-tab.active {
  background: var(--bg-surface-2);
  color: var(--ink-1);
}
.inspector-body {
  flex: 1;
  overflow-y: auto;
  padding: 14px 12px;
}
.inspector-hint {
  font-size: 12px;
  color: var(--ink-3);
  margin: 0 0 10px;
  line-height: 1.45;
}
.tree-list {
  display: flex;
  flex-direction: column;
}
.tree-node {
  display: flex;
  align-items: stretch;
  gap: 10px;
  padding: 7px 9px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  text-align: left;
  width: 100%;
}
.tree-node:hover {
  background: var(--bg-surface-2);
}
.tree-node.is-leaf {
  background: var(--bg-surface);
  border-color: var(--brand-border);
}
.tree-node.off-branch {
  opacity: 0.6;
  padding-left: 24px;
}
.tree-rail {
  width: 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  position: relative;
  flex-shrink: 0;
}
.tree-rail::before {
  content: "";
  position: absolute;
  top: -8px;
  bottom: -8px;
  left: 50%;
  width: 1.5px;
  transform: translateX(-50%);
  background: var(--border-subtle);
}
.tree-node:first-child .tree-rail::before {
  top: 10px;
}
.tree-node:last-child .tree-rail::before {
  bottom: calc(100% - 10px);
}
.tree-node.active-branch .tree-rail::before {
  background: var(--brand-border);
}
.tree-dot {
  width: 9px;
  height: 9px;
  margin-top: 5px;
  border-radius: 50%;
  background: var(--border-strong);
  border: 2px solid var(--bg-rail);
  position: relative;
  z-index: 1;
}
.tree-node.active-branch .tree-dot {
  background: var(--brand);
}
.tree-node.kind-compaction .tree-dot {
  background: var(--ok);
  border-radius: 3px;
}
.tree-node-info {
  min-width: 0;
  flex: 1;
}
.tree-node-top {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--ink-3);
}
.tree-role {
  font-family: var(--font-mono);
  font-weight: 500;
  color: var(--ink-2);
}
.tree-leaf-tag {
  margin-left: auto;
  font-size: 10px;
  font-weight: 600;
  color: var(--brand);
  background: var(--brand-soft);
  padding: 0 5px;
  border-radius: 4px;
}
.tree-preview {
  font-size: 12.5px;
  color: var(--ink-1);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}

.stat-card {
  padding: 14px;
  border-radius: var(--radius-md);
  background: var(--bg-surface);
  border: 1px solid var(--border-hairline);
  margin-bottom: 10px;
}
.stat-card-title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--ink-3);
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.stat-pct {
  font-family: var(--font-mono);
  color: var(--brand);
}
.stat-big {
  font-family: var(--font-mono);
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.02em;
}
.stat-sub {
  font-size: 12px;
  color: var(--ink-3);
  margin-top: 4px;
  font-family: var(--font-mono);
}
.stat-kv-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 10px;
}
.stat-kv {
  display: flex;
  justify-content: space-between;
  font-size: 12.5px;
}
.stat-kv span:first-child {
  color: var(--ink-2);
}
.stat-kv span:last-child {
  font-family: var(--font-mono);
  color: var(--ink-1);
}
.session-file-box {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink-2);
  background: var(--bg-code);
  border: 1px solid var(--border-hairline);
  border-radius: var(--radius-sm);
  padding: 7px 9px;
  word-break: break-all;
}
.inspector-actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}
.inspector-actions .btn {
  flex: 1;
}

/* ==========================================================================
   Modal de Accesos, PIN (423) y Login
   ========================================================================== */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: var(--bg-overlay);
  backdrop-filter: blur(6px);
  display: grid;
  place-items: center;
  padding: 16px;
  z-index: 60;
}
.modal-card {
  width: 100%;
  max-width: 500px;
  border-radius: var(--radius-xl);
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  box-shadow: var(--shadow-lg), var(--inset-highlight);
  overflow: hidden;
}
.modal-head {
  padding: 16px 18px;
  border-bottom: 1px solid var(--border-hairline);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.modal-head h2 {
  margin: 0;
  font-size: 15.5px;
  font-weight: 650;
}
.modal-head p {
  margin: 2px 0 0;
  font-size: 12.5px;
  color: var(--ink-3);
}
.modal-body {
  padding: 14px 18px 18px;
  max-height: 70dvh;
  overflow-y: auto;
}
.devices-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.devices-list li {
  padding: 12px 14px;
  border-radius: var(--radius-md);
  background: var(--bg-rail);
  border: 1px solid var(--border-hairline);
  display: flex;
  align-items: center;
  gap: 12px;
}
.dispositivo {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.dispositivo-titulo {
  display: flex;
  align-items: center;
  gap: 7px;
  flex-wrap: wrap;
}
.dispositivo .detalle {
  font-size: 12px;
  color: var(--ink-3);
}
.dispositivo .actual {
  font-size: 10.5px;
  font-weight: 600;
  padding: 1px 7px;
  border-radius: var(--radius-pill);
  background: var(--brand-soft);
  color: var(--brand);
  border: 1px solid var(--brand-border);
}

.pin-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg-overlay);
  backdrop-filter: blur(14px);
  display: grid;
  place-items: center;
  padding: 20px;
  z-index: 65;
}
.pin-card {
  width: 100%;
  max-width: 360px;
  padding: 26px 24px 22px;
  border-radius: var(--radius-xl);
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  box-shadow: var(--shadow-lg), var(--inset-highlight);
  text-align: center;
}
.pin-icon {
  width: 44px;
  height: 44px;
  margin: 0 auto 12px;
  border-radius: 50%;
  background: var(--warn-soft);
  border: 1px solid var(--warn-border);
  color: var(--warn);
  display: grid;
  place-items: center;
}
.pin-card h2 {
  margin: 0 0 6px;
  font-size: 17px;
  font-weight: 650;
}
.pin-card p {
  margin: 0 0 18px;
  font-size: 13px;
  color: var(--ink-2);
}
.pin-input {
  width: 100%;
  height: 44px;
  text-align: center;
  font-family: var(--font-mono);
  font-size: 18px;
  letter-spacing: 0.25em;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
  background: var(--bg-app);
  color: var(--ink-1);
  outline: none;
  margin-bottom: 12px;
}
.pin-input:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-soft);
}

.auth-screen {
  position: fixed;
  inset: 0;
  background: var(--bg-app);
  display: grid;
  place-items: center;
  padding: 20px;
  z-index: 70;
  overflow-y: auto;
}
.auth-card {
  width: 100%;
  max-width: 400px;
  padding: 28px 26px 24px;
  border-radius: var(--radius-xl);
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  box-shadow: var(--shadow-lg), var(--inset-highlight);
}
.auth-head {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  margin-bottom: 22px;
}
.auth-logo {
  width: 44px;
  height: 44px;
  border-radius: 13px;
  background: var(--bg-surface-2);
  border: 1px solid var(--border-subtle);
  color: var(--ink-1);
  display: grid;
  place-items: center;
  margin-bottom: 12px;
}
.auth-head h1 {
  margin: 0;
  font-size: 20px;
  font-weight: 650;
  letter-spacing: -0.02em;
}
.auth-host-pill {
  margin-top: 8px;
  padding: 3px 10px;
  border-radius: var(--radius-pill);
  background: var(--bg-rail);
  border: 1px solid var(--border-hairline);
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--ink-2);
}

.field {
  margin-bottom: 14px;
}
.field-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--ink-2);
  margin-bottom: 6px;
}
.field-hint {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink-3);
}
.field-input-wrap {
  position: relative;
}
.field-input {
  width: 100%;
  height: 40px;
  padding: 0 12px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
  background: var(--bg-app);
  color: var(--ink-1);
  font-size: 14px;
  outline: none;
}
.field-input-pass {
  padding-right: 40px;
}
.field-input-otp {
  font-family: var(--font-mono);
  letter-spacing: 0.25em;
  text-align: center;
}
.field-input:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-soft);
}
.field-eye {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  width: 28px;
  height: 28px;
  border-radius: 7px;
  display: grid;
  place-items: center;
  color: var(--ink-3);
}
.field-eye:hover {
  color: var(--ink-1);
  background: var(--bg-surface-2);
}
.auth-submit {
  width: 100%;
  height: 42px;
  margin-top: 6px;
  border-radius: var(--radius-md);
  font-size: 14px;
  font-weight: 600;
}

.error {
  color: var(--err);
  min-height: 1.2em;
  font-size: 12.5px;
  margin: 10px 0 0;
  text-align: center;
}

.vacio {
  color: var(--ink-3);
  font-size: 13px;
}

.toast-aviso {
  position: fixed;
  top: 64px;
  right: 16px;
  margin: 0;
  padding: 10px 14px;
  border-radius: var(--radius-md);
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  box-shadow: var(--shadow-md);
  color: var(--ink-1);
  font-size: 13px;
  max-width: 360px;
  z-index: 80;
}

/* ==========================================================================
   Responsive móvil
   ========================================================================== */
@media (max-width: 900px) {
  .sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    margin-left: 0 !important;
    transform: translateX(-100%);
    box-shadow: var(--shadow-lg);
  }
  .app-shell.mobile-sidebar-open .sidebar {
    transform: translateX(0);
  }
  .inspector {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    z-index: 35;
    box-shadow: var(--shadow-lg);
  }
  .panels-grid.multi {
    grid-template-columns: 1fr;
    grid-auto-rows: minmax(18rem, 1fr);
  }
  .topbar-cwd,
  .topbar-sep,
  .hide-mobile,
  .kbd {
    display: none !important;
  }
  .topbar {
    padding: 0 10px;
    gap: 7px;
  }
}

@media (max-width: 640px) {
  .transcript-scroll {
    padding: 14px 14px 18px;
  }
  .composer-dock {
    padding: 0 12px calc(12px + env(safe-area-inset-bottom));
  }
  .mensaje.user .texto {
    max-width: 92%;
    padding: 10px 13px;
  }
}
