/* Capa de componentes del Tablero. Portada del ai-dash (Sidebar/Topbar/Login/
   tasks/TaskDrawer de web-src) a CSS plano: mismos tamanos, radios, colores y
   animaciones. Los tokens viven en theme.css. Cero egreso: ni una URL externa. */

/* --- Shell: rejilla sidebar | contenido ---------------------------------- */
.shell {
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
  height: 100dvh;
  min-height: 100vh;
  background: var(--bg);
}
.shell[hidden] { display: none; }
.main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
}
.content {
  flex: 1;
  overflow: auto;
  padding: var(--content-pad);
  background: var(--bg);
}
.content-inner { animation: content-rise 240ms ease both; }
.page { display: flex; flex-direction: column; gap: 18px; min-width: 0; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.row-end { justify-content: flex-end; }
.grow { flex: 1 1 auto; min-width: 0; }

/* --- Sidebar -------------------------------------------------------------- */
.sidebar {
  background: var(--sidebar);
  color: #e5edf7;
  display: flex;
  flex-direction: column;
  height: 100dvh;
  min-height: 100vh;
  border-right: 1px solid rgba(255, 255, 255, 0.08);
}
.sidebar .brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 18px 18px 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}
.sidebar .brand-link { display: block; text-decoration: none; color: inherit; }
.brand-logo {
  width: 36px; height: 36px; object-fit: contain;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.25));
}
.brand-text { line-height: 1.2; }
.brand-name { font-weight: 700; font-size: 15px; color: #fff; letter-spacing: 0.2px; }
.brand-sub {
  font-size: 10px; color: var(--dsi-turquoise-bright); font-weight: 600;
  letter-spacing: 0.8px; text-transform: uppercase;
}
.nav-list { flex: 1; padding: 14px 12px; display: flex; flex-direction: column; gap: 16px; overflow-y: auto; }
.nav-group { display: flex; flex-direction: column; gap: 2px; }
.nav-group-title {
  padding: 0 10px 6px;
  font-size: 9.5px; font-weight: 700; letter-spacing: 1px;
  text-transform: uppercase; color: rgba(184, 200, 220, 0.45);
}
.nav-item {
  position: relative;
  display: flex; align-items: center; gap: 11px; padding: 8px 10px;
  font-size: 13px; font-weight: 500; color: #b8c8dc;
  border-radius: 8px; text-decoration: none;
  transition: background 140ms ease, color 140ms ease;
}
.nav-item:hover { background: var(--sidebar-hover); color: #fff; text-decoration: none; }
.nav-item:hover .nav-icon { color: #d7e6f5; }
.nav-item.active { background: var(--sidebar-active); color: #fff; }
.nav-item.active .nav-icon { color: var(--dsi-turquoise-bright); }
.nav-item.active::before {
  content: '';
  position: absolute;
  left: -12px; top: 50%;
  transform: translateY(-50%);
  width: 3px; height: 18px;
  border-radius: 0 3px 3px 0;
  background: var(--dsi-turquoise-bright);
}
.nav-icon {
  display: flex; align-items: center; justify-content: center;
  width: 20px; height: 20px; color: #7f93ab;
  transition: color 140ms ease;
}
.nav-item .label { flex: 1; }
.sidebar-footer { padding: 12px 18px; border-top: 1px solid rgba(255, 255, 255, 0.06); }
.sidebar-footer .muted { font-size: 11px; display: block; color: rgba(184, 200, 220, 0.55); }

/* --- Topbar --------------------------------------------------------------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px;
  padding: 10px var(--content-pad);
  background: rgba(255, 255, 255, 0.86);
  border-bottom: 1px solid var(--border);
  min-height: var(--topbar-height);
  backdrop-filter: blur(12px);
}
html[data-theme="dark"] .topbar { background: rgba(17, 31, 48, 0.86); }
.topbar .left, .topbar .right { display: flex; align-items: center; gap: 12px; }
.topbar .left { min-width: 0; }
.module-title { min-width: 150px; display: flex; flex-direction: column; gap: 1px; padding-right: 4px; }
.module-title span { color: var(--text); font-size: 13px; font-weight: 700; line-height: 1.15; }
.module-title small {
  color: var(--text-muted); font-size: 10px; font-weight: 700;
  letter-spacing: var(--track-caps); line-height: 1.15; text-transform: uppercase;
}
.indicator { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.indicator .stat {
  display: inline-flex; align-items: center; gap: 6px;
  min-height: 28px; padding: 4px 10px; border-radius: 999px;
  font-size: 12px; font-weight: 600;
  background: var(--surface-subtle); border: 1px solid var(--border);
  color: var(--text-secondary);
}
.indicator .stat strong { color: var(--text); font-weight: 800; }
.indicator .stat.bad { background: var(--bad-bg); color: var(--bad); border-color: transparent; }
.indicator .stat.bad strong { color: var(--bad); }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px;
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text-secondary);
  transition: background 120ms ease, border-color 120ms ease, color 120ms ease, box-shadow 120ms ease;
}
.icon-btn:hover { background: var(--surface-subtle); border-color: var(--accent); color: var(--accent); }
.icon-btn:focus-visible { outline: none; box-shadow: var(--ring); }
.user { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.avatar {
  display: inline-flex; align-items: center; justify-content: center;
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--accent-soft); color: var(--accent);
  font-size: 12px; font-weight: 700;
}
.user-meta { display: flex; flex-direction: column; line-height: 1.2; }
.user-meta strong { font-size: 12.5px; }
.user-meta .muted { font-size: 10.5px; text-transform: uppercase; letter-spacing: var(--track-caps-tight); }

/* --- Login ---------------------------------------------------------------- */
.login-wrap {
  display: flex; align-items: center; justify-content: center;
  height: 100vh; background: var(--bg);
}
.login-wrap[hidden] { display: none; }
.login-card {
  width: 380px;
  padding: 36px 32px 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  text-align: center;
}
.login-card .logo { width: 100px; height: 100px; object-fit: contain; filter: drop-shadow(0 4px 12px rgba(13, 48, 80, 0.2)); }
.login-card .logo-block { margin-bottom: 16px; }
.login-card h1 { margin: 0 0 4px; font-size: 24px; font-weight: 700; }
.login-card .sub { margin: 0 0 28px; font-size: 13px; color: var(--text-secondary); font-weight: 500; }
.login-card form { display: flex; flex-direction: column; gap: 14px; text-align: left; }
.login-card label { display: flex; flex-direction: column; gap: 6px; }
.login-card label > span {
  font-size: 11px; font-weight: 600; color: var(--text-secondary); text-transform: uppercase;
}
.login-card button { width: 100%; justify-content: center; padding: 11px; font-size: 14px; margin-top: 4px; }
.login-indicator {
  display: flex; gap: 8px; margin-top: 22px;
}
.login-indicator:empty { display: none; }
.login-indicator .figure {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 10px 6px; border-radius: var(--radius);
  background: var(--surface-subtle); border: 1px solid var(--border);
}
.login-indicator .figure-value { font-size: 17px; font-weight: 800; color: var(--text); }
.login-indicator .figure-label {
  font-size: 10px; font-weight: 600; color: var(--text-muted); text-transform: uppercase;
}
.login-indicator .figure.bad { background: var(--bad-bg); border-color: transparent; }
.login-indicator .figure.bad .figure-value { color: var(--bad); }
.login-card .login-footer {
  margin-top: 24px; padding-top: 16px; border-top: 1px solid var(--border);
  font-size: 11px; color: var(--text-muted);
}
.error {
  background: var(--bad-bg); color: var(--bad);
  padding: 9px 12px; border-radius: var(--radius);
  font-size: 13px; font-weight: 500;
}
.error:empty { display: none; }

/* --- Barra de herramientas del tablero ------------------------------------ */
.toolbar {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px 18px;
  display: flex; flex-direction: column; gap: 10px;
}
.toolbar-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.toolbar-main { justify-content: space-between; }
.toolbar-actions { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.toolbar .hero h1 { margin: 0; font-size: 18px; letter-spacing: -0.3px; }
.toolbar .hero p { margin: 2px 0 0; font-size: 11px; color: var(--text-muted); }
.segmented {
  display: inline-flex; padding: 2px; gap: 2px;
  border-radius: 8px; background: var(--surface-subtle);
  border: 1px solid var(--border);
}
.segmented button {
  background: transparent; color: var(--text-muted); border: 0;
  padding: 5px 10px; min-height: 26px; border-radius: 6px;
  font-size: 11px; font-weight: 700; cursor: pointer;
}
.segmented button.active { background: var(--accent); color: var(--accent-contrast); }
.filter-input, .filter-select { width: auto; flex: 0 0 auto; font-size: 12px; padding: 6px 9px; }
.filter-input { flex: 1 1 180px; min-width: 0; max-width: 280px; }
.counter-chip {
  background: var(--accent-soft); color: var(--accent);
  font-weight: 700; font-size: 11px; padding: 4px 9px;
  border-radius: 999px; min-height: 26px;
  display: inline-flex; align-items: center;
}

/* --- Tablero por columnas ------------------------------------------------- */
.board {
  margin-top: 18px;
  display: grid;
  grid-template-columns: repeat(var(--status-count, 6), minmax(155px, 1fr));
  gap: 8px;
  align-items: start;
  padding: 0 0 6px;
}
.column {
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-subtle);
  padding: 8px 10px 10px;
  min-height: 260px;
}
.column.drag-over { border-color: var(--accent); background: rgba(23, 147, 141, 0.08); }
.column-head {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 10px;
  border-radius: 8px; padding: 6px 10px; border: 1px solid;
  transition: background 120ms;
}
.column-head h2 {
  margin: 0; font-size: 11px; text-transform: uppercase;
  font-weight: 800; letter-spacing: 0.5px;
}
.column-head .count {
  min-width: 24px; text-align: center; padding: 2px 6px;
  font-size: 11px; line-height: 1.2; border-radius: 999px; font-weight: 700;
}
.column .empty { color: var(--text-muted); font-size: 13px; padding: 18px 6px; text-align: center; }

.card.task {
  display: block; width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  margin: 0 0 8px;
  box-shadow: none;
  cursor: pointer;
  transition: border-color 120ms ease, transform 120ms ease, box-shadow 120ms ease;
}
.card.task:hover { transform: translateY(-1px); border-color: var(--accent); }
.card.task:focus-visible { outline: none; border-color: var(--accent); box-shadow: 0 0 0 2px rgba(23, 147, 141, 0.30); }
.card.task.dragging { opacity: 0.55; }
.card-title {
  display: block; margin: 0 0 4px;
  font-size: 14px; font-weight: 800; line-height: 1.28;
  overflow-wrap: anywhere;
}
/* El resumen se recorta a 3 lineas (ai-dash viejo): sin esto una descripcion
   larga estira la tarjeta y la columna deja de leerse. max-height es el
   fallback para navegadores sin el box de WebKit. */
.card-summary {
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical;
  overflow: hidden; text-overflow: ellipsis;
  margin: 0 0 8px;
  color: var(--text-muted); font-size: 12px; line-height: 1.35;
  max-height: calc(1.35em * 3);
  overflow-wrap: anywhere;
}
.meta-row { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  border: 0; border-radius: 999px; padding: 5px 10px;
  background: var(--surface-subtle); color: var(--accent);
  font-size: 12px; font-weight: 600; min-height: 26px;
  font-family: inherit;
}
.chip.status-pill {
  background: var(--surface-subtle); border: 1px solid var(--border);
  color: var(--text); font-weight: 700; font-size: 11px; cursor: pointer;
  min-height: 0; padding: 4px 9px; line-height: 1;
}
.chip.status-pill:disabled { opacity: 0.72; cursor: default; }
.chip.stale { background: var(--bad-bg); color: var(--bad); font-weight: 700; }
.chip.chip-action { cursor: pointer; border: 1px solid var(--border); }
.chip.chip-action:hover { background: var(--accent-soft); }
.card-footer {
  display: flex; justify-content: flex-end;
  color: var(--text-muted); font-size: 11px; margin-top: 6px;
}
.blocked-reason {
  color: var(--bad);
  background: rgba(194, 65, 58, 0.10);
  border: 1px solid rgba(194, 65, 58, 0.18);
  border-radius: 8px; padding: 8px 10px; font-size: 12px;
  overflow-wrap: anywhere;
}
/* Densidad compacta (Dense) = SOLO el titulo. Sin chips no queda senal de
   estado, asi que el acento del borde izquierdo la sustituye. */
.compact .card.task {
  padding: 6px 9px; margin-bottom: 4px; border-radius: 6px;
  border-left: 3px solid var(--card-accent, var(--border));
}
.compact .card-summary, .compact .card-footer, .compact .detail-chip,
.compact .meta-row, .compact .blocked-reason { display: none; }
.compact .card-title { margin: 0; font-size: 13px; }
.compact .chip { padding: 4px 7px; }

/* --- Drawer derecho ------------------------------------------------------- */
.drawer-overlay { position: fixed; inset: 0; background: rgba(8, 20, 35, 0.42); z-index: 999; border: 0; padding: 0; cursor: pointer; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0;
  width: min(640px, 100vw);
  background: var(--surface); z-index: 1000;
  display: flex; flex-direction: column;
  border-left: 1px solid var(--border);
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.24);
}
.drawer-header {
  padding: 16px 20px; border-bottom: 1px solid var(--border);
  display: flex; justify-content: space-between; gap: 14px; align-items: flex-start;
}
.drawer-header h2 { margin: 0 0 8px; font-size: 18px; line-height: 1.3; overflow-wrap: anywhere; }
.header-info { flex: 1; min-width: 0; }
.header-badges { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.drawer-close {
  background: none; border: none; font-size: 18px; cursor: pointer;
  color: var(--text-secondary); padding: 4px; line-height: 1;
}
.drawer-tabs { border-bottom: 1px solid var(--border); display: flex; padding: 0 20px; gap: 4px; }
.drawer-tabs button {
  border: 0; border-bottom: 2px solid transparent;
  padding: 10px 16px; background: transparent;
  color: var(--text-secondary); cursor: pointer; font-size: 13px; font-weight: 600;
}
.drawer-tabs button.active { color: var(--accent); border-bottom-color: var(--accent); }
.drawer-body { flex: 1; overflow-y: auto; padding: 16px 20px 40px; }
.drawer-actions { padding: 8px 20px; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.detail-section { margin-bottom: 24px; }
.section-title {
  margin: 0 0 10px; font-size: 11px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-secondary);
  display: flex; align-items: center; gap: 6px;
}
.section-count { font-size: 10px; background: var(--surface-subtle); border-radius: 999px; padding: 1px 7px; }
.info-grid { display: grid; gap: 10px; }
.info-item { display: grid; grid-template-columns: 110px 1fr; gap: 8px; align-items: baseline; }
.info-label { font-size: 11px; font-weight: 700; text-transform: uppercase; color: var(--text-secondary); letter-spacing: 0.3px; }
.info-value { font-size: 13px; overflow-wrap: anywhere; }
.task-content { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; font-size: 13px; line-height: 1.5; font-family: inherit; background: transparent; border: 0; padding: 0; }
.comment-item, .event-item { padding: 10px 0; border-bottom: 1px solid var(--border); }
.comment-item:last-child, .event-item:last-child { border-bottom: 0; }
.comment-header { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.comment-author { font-size: 12px; font-weight: 700; }
.comment-time { font-size: 11px; color: var(--text-secondary); }
.comment-body { font-size: 13px; white-space: pre-wrap; overflow-wrap: anywhere; }
/* Comentario renderizado como Markdown (P9 R3): el salto de linea lo pone el
   propio marcado, asi que aqui NO vale pre-wrap o todo saldria doblemente
   espaciado. */
.comment-body.md { white-space: normal; line-height: 1.55; }
.comment-body.md > :first-child { margin-top: 0; }
.comment-body.md > :last-child { margin-bottom: 0; }
.comment-body.md p { margin: 0 0 8px; }
.comment-body.md ul, .comment-body.md ol { margin: 0 0 8px; padding-left: 20px; }
.comment-body.md li { margin: 2px 0; }
.comment-body.md h1, .comment-body.md h2,
.comment-body.md h3, .comment-body.md h4 {
  margin: 10px 0 6px; font-size: 13px; font-weight: 700; line-height: 1.3;
}
.comment-body.md code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px; background: var(--surface-alt, rgba(127,127,127,.12));
  border-radius: 4px; padding: 1px 4px;
}
.comment-body.md pre {
  margin: 0 0 8px; padding: 8px 10px; overflow: auto;
  background: var(--surface-alt, rgba(127,127,127,.12));
  border: 1px solid var(--border); border-radius: 6px;
}
.comment-body.md pre code { background: transparent; padding: 0; }
.comment-body.md blockquote {
  margin: 0 0 8px; padding-left: 10px;
  border-left: 3px solid var(--border-strong, var(--border));
  color: var(--text-secondary);
}
.comment-body.md a { color: var(--accent, inherit); }
.comment-expand {
  margin-top: 4px; padding: 2px 8px; font-size: 11px;
}
.checklist-item { display: flex; align-items: center; gap: 8px; padding: 6px 0; cursor: pointer; }
.checklist-item input { width: auto; }
.stage-flow { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.stage-sep { color: var(--text-muted); }
.pager { display: flex; gap: 8px; align-items: center; margin-top: 10px; }
.inline-add { display: grid; grid-template-columns: 1fr auto; gap: 6px; align-items: start; margin-top: 10px; }

/* --- Tablas y formularios de las vistas de gestion ------------------------ */
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 10px; align-items: end; }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > span { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: var(--track-caps); color: var(--text-secondary); }
.check { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; }
.check input { width: auto; }
table.data td .btn { margin-right: 4px; }
table.data td input, table.data td select { min-width: 90px; }
.btn-danger { border-color: rgba(194, 65, 58, 0.45); color: var(--bad); }
.btn-danger:hover { background: var(--bad-bg); border-color: var(--bad); color: var(--bad); }
.stage-row { display: grid; grid-template-columns: 26px 1fr 170px auto; gap: 8px; align-items: center; padding: 6px 0; border-bottom: 1px solid var(--border); }
.stage-row:last-of-type { border-bottom: 0; }
.stage-index { font-size: 11px; font-weight: 800; color: var(--text-muted); }
.pipeline-box { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 12px 14px; background: var(--surface-subtle); margin-bottom: 12px; }
.pipeline-box .pipeline-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 8px; }
.pipeline-box .pipeline-head strong { font-size: 13px; }
.token-value {
  font-family: var(--mono); font-size: 12px; word-break: break-all;
  background: var(--surface-subtle); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 10px 12px; margin-top: 8px;
}

/* --- Responsive ----------------------------------------------------------- */
@media (max-width: 1200px) {
  .board { grid-template-columns: repeat(var(--status-count, 6), minmax(155px, 1fr)); overflow-x: auto; }
}
@media (max-width: 860px) {
  .shell { display: flex; flex-direction: column; min-height: 100dvh; height: auto; }
  .main { min-height: 0; overflow: visible; }
  .content { overflow: visible; }
  .sidebar { height: auto; min-height: 0; border-right: 0; border-bottom: 1px solid rgba(255, 255, 255, 0.08); }
  .nav-list { flex-direction: row; gap: 4px; overflow-x: auto; padding: 8px 12px 12px; }
  .nav-group { flex-direction: row; gap: 4px; }
  .nav-group-title, .sidebar-footer { display: none; }
  .nav-item { min-width: max-content; }
  .nav-item.active::before { display: none; }
  .topbar { align-items: flex-start; flex-direction: column; gap: 10px; }
  .topbar .left, .topbar .right { width: 100%; flex-wrap: wrap; }
  .topbar .right { justify-content: space-between; }
  .board { grid-template-columns: repeat(var(--status-count, 6), minmax(155px, 84vw)); }
}

/* --- Editor de tarea a pantalla completa (#/task/<id>/edit) ---------------- */
/* Calco del editor del ai-dash viejo. Ocupa toda la ventana por encima del
   shell; el drawer queda desmontado mientras el editor esta abierto. */

#editor-root:empty { display: none; }

.editor-shell {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

.editor-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 18px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex: 0 0 auto;
}

.editor-back { flex: 0 0 auto; }

.editor-title {
  flex: 1 1 auto;
  min-width: 0;
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 6px 10px;
}
.editor-title:hover:not(:disabled) { border-color: var(--border); }
.editor-title:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--surface-subtle);
}

.editor-header-badges { display: flex; align-items: center; gap: 6px; flex: 0 0 auto; }
.editor-status { flex: 0 0 auto; font-size: 12px; min-width: 88px; text-align: right; }
.editor-save { flex: 0 0 auto; }

/* Banner de borrador recuperado. */
.draft-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 18px;
  background: var(--warn-bg);
  color: var(--warn);
  border-bottom: 1px solid var(--warn);
  font-size: 13px;
  flex: 0 0 auto;
}
.draft-banner[hidden] { display: none; }
.draft-icon { font-size: 15px; }
.draft-text { flex: 1 1 auto; }

.editor-body {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
}

/* Split arrastrable: la posicion vive en --split-pct (persistida). */
.editor-split {
  --split-pct: 50%;
  display: grid;
  grid-template-columns: var(--split-pct) 7px minmax(0, 1fr);
  min-width: 0;
  min-height: 0;
}

.editor-pane { min-width: 0; min-height: 0; display: flex; flex-direction: column; overflow: hidden; }
.editor-pane-preview { overflow: auto; padding: 16px 20px; background: var(--surface); }

.split-handle {
  width: 7px;
  cursor: col-resize;
  background: var(--border);
  border-left: 1px solid var(--border);
  border-right: 1px solid var(--border);
}
.split-handle:hover, .split-handle.dragging, .split-handle:focus-visible {
  background: var(--accent);
  outline: none;
}
body.split-dragging { cursor: col-resize; user-select: none; }

/* Alternancias de paneles: mismo boton-icono de la topbar. */
.editor-toggle { flex: 0 0 auto; }
.icon-btn.active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
}

/* Sin vista previa el texto ocupa todo el ancho y el divisor desaparece:
   un manejador huerfano no arrastraria nada. */
.editor-split.hide-preview { grid-template-columns: minmax(0, 1fr); }
.editor-split.hide-preview .split-handle,
.editor-split.hide-preview .editor-pane-preview { display: none; }

.editor-body.hide-side { grid-template-columns: minmax(0, 1fr); }
.editor-body.hide-side .editor-side { display: none; }

.editor-textarea {
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  resize: none;
  border: 0;
  outline: none;
  padding: 14px 16px;
  background: var(--surface);
  color: var(--text);
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.55;
  tab-size: 2;
}

/* Barra de formato. */
.md-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 7px 10px;
  background: var(--surface-subtle);
  border-bottom: 1px solid var(--border);
  flex: 0 0 auto;
}
.md-tool {
  height: 28px;
  min-width: 28px;
  padding: 0 8px;
  border-radius: 7px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-secondary);
  font-size: 12px;
  line-height: 1;
  cursor: pointer;
}
.md-tool:hover { border-color: var(--border-strong); color: var(--text); }
.md-tool.active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
}
.md-tool.md-bold { font-weight: 700; }
.md-tool.md-italic { font-style: italic; }

/* Buscador de tareas para enlazar (#<id>). */
.task-search {
  display: flex; flex-direction: column; gap: 6px;
  padding: 8px 10px;
  background: var(--surface-subtle);
  border-bottom: 1px solid var(--border);
  flex: 0 0 auto;
}
.task-search-input {
  width: 100%; height: 30px; padding: 0 9px;
  border: 1px solid var(--border); border-radius: 7px;
  background: var(--surface); color: var(--text); font-size: 13px;
}
.task-search-results { display: flex; flex-direction: column; gap: 4px; max-height: 190px; overflow-y: auto; }
.task-search-item {
  display: flex; align-items: center; gap: 8px; width: 100%;
  padding: 6px 8px; text-align: left;
  border: 1px solid transparent; border-radius: 7px;
  background: var(--surface); color: var(--text);
  font-family: inherit; font-size: 13px; cursor: pointer;
}
.task-search-item:hover { border-color: var(--accent); background: var(--accent-soft); }
.task-search-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Seccion plegable del lateral (historial). */
.side-collapse > summary {
  cursor: pointer; list-style: none;
  display: flex; align-items: center; gap: 6px;
}
.side-collapse > summary::-webkit-details-marker { display: none; }
.side-collapse > summary::before { content: "▸"; color: var(--text-muted); font-size: 11px; }
.side-collapse[open] > summary::before { content: "▾"; }

/* Panel lateral derecho. */
.editor-side {
  border-left: 1px solid var(--border);
  background: var(--surface);
  overflow-y: auto;
  padding: 14px 16px;
  min-width: 0;
}

/* Preview renderizado (subconjunto de etiquetas de markdown.js). */
.markdown-body { color: var(--text); font-size: 14px; line-height: 1.6; }
.markdown-body h1 { font-size: 22px; margin: 18px 0 8px; }
.markdown-body h2 { font-size: 18px; margin: 16px 0 8px; }
.markdown-body h3 { font-size: 15px; margin: 14px 0 6px; }
.markdown-body h4 { font-size: 14px; margin: 12px 0 6px; }
.markdown-body h1:first-child, .markdown-body h2:first-child { margin-top: 0; }
.markdown-body p { margin: 0 0 10px; }
.markdown-body ul, .markdown-body ol { margin: 0 0 10px; padding-left: 22px; }
.markdown-body li { margin: 2px 0; }
.markdown-body blockquote {
  margin: 0 0 10px;
  padding: 6px 12px;
  border-left: 3px solid var(--accent);
  background: var(--surface-subtle);
  color: var(--text-secondary);
}
.markdown-body code {
  font-family: var(--mono);
  font-size: 12.5px;
  background: var(--surface-subtle);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 4px;
}
.markdown-body pre {
  margin: 0 0 10px;
  padding: 10px 12px;
  overflow-x: auto;
  background: var(--surface-subtle);
  border: 1px solid var(--border);
  border-radius: 7px;
}
.markdown-body pre code { border: 0; background: none; padding: 0; }
.markdown-body hr { border: 0; border-top: 1px solid var(--border); margin: 14px 0; }
.markdown-body a { color: var(--accent); }

/* Cabecera del drawer: el boton de editor va junto al de cerrar. */
.drawer-header-actions { display: flex; align-items: center; gap: 8px; flex: 0 0 auto; }

/* En pantallas estrechas el split colapsa a bloques apilados. */
@media (max-width: 899px) {
  .editor-body { grid-template-columns: minmax(0, 1fr); grid-auto-rows: min-content; overflow-y: auto; }
  .editor-split { display: flex; flex-direction: column; }
  .split-handle { display: none; }
  .editor-textarea { min-height: 44vh; }
  .editor-pane-preview { border-top: 1px solid var(--border); }
  .editor-side { border-left: 0; border-top: 1px solid var(--border); overflow: visible; }
  .editor-header { flex-wrap: wrap; }
  .editor-title { order: -1; width: 100%; flex-basis: 100%; }
}

/* --- Avisos in-app, estados de carga y guardado (P9 R4) ------------------- */
/* Reemplazan a alert(): no bloquean el hilo, no parecen un fallo del navegador
   y distinguen exito de error. Se apilan abajo a la derecha y se van solos. */
.toasts {
  position: fixed; right: 16px; bottom: 16px; z-index: 60;
  display: flex; flex-direction: column; gap: 8px;
  max-width: min(380px, calc(100vw - 32px)); pointer-events: none;
}
.toast {
  padding: 10px 12px; border-radius: 8px; font-size: 13px; line-height: 1.4;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); box-shadow: 0 6px 20px rgba(0, 0, 0, .18);
  animation: toast-in .16s ease-out;
}
.toast-ok { border-left: 3px solid #12806f; }
.toast-error { border-left: 3px solid #c2413a; }
@keyframes toast-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .toast { animation: none; } }

.loading-box, .empty-box { padding: 14px 2px; font-size: 13px; }

/* Confirmacion discreta en la propia fila: se guarda sin repintar la tabla, asi
   que hace falta una senal local de que el cambio entro. */
.row-saved > td { background: rgba(18, 128, 111, .10); transition: background .4s ease; }

/* Modelo: desplegable del catalogo + campo libre que solo aparece con "otro…" */
.model-pick { display: flex; flex-direction: column; gap: 4px; min-width: 150px; }
.model-pick .model-free { font-size: 12px; }
/* Los desplegables de la tabla de agentes no deben recortar su valor: con
   "claude-code" cortado a la mitad no se sabe que harness tiene la maquina. */
.data td select { min-width: 132px; max-width: 100%; }
.data td input[type="text"], .data td input[type="password"] { min-width: 120px; }
