/* ═══ Editor de tarifa detallada ═══════════════════════════════════════
   Estilos scoped a .ed-* para que se puedan montar en cualquier página
   sin pisar el layout del padre (sidebar de /app, etc). El editor
   funciona embebido dentro de /app#editor (via window.EditorDetallado.mount)
   o standalone en /editor-detallado.                                     */

.ed-main {
  max-width: 1480px;
  margin: 0 auto;
  padding: 22px 18px 110px; /* espacio para la bottom-bar */
}
.ed-host {
  /* Cuando el editor se monta dentro del editor del rápido, el padre ya
   * tiene su propio padding; el host no añade margin extra. */
  display: block;
}

/* Cuando el editor detallado está embebido en /app#editor, ocultamos el
 * breadcrumb "✏ Editando: ..." del editor padre — es redundante con el
 * propio shell del detallado y empuja el contenido demasiado hacia
 * abajo. La clase .ed-detailed-active se añade desde JS al hacer mount;
 * el :has() es un belt-and-braces para browsers que no soporten clases
 * dinámicas. */
body.ed-detailed-active .tab-breadcrumb,
body:has(.ed-host) .tab-breadcrumb { display: none !important; }

/* ─── Hero + selector de tarifa ─── */
.ed-hero {
  background: var(--card-bg, #fff);
  border-radius: 18px;
  padding: 18px 24px;
  margin-bottom: 16px;
  box-shadow: 0 6px 20px rgba(11, 33, 54, .06);
  border: 1px solid rgba(165, 188, 206, 0.32);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}
.ed-hero h1 {
  margin: 0 0 4px;
  font-family: var(--brand-display);
  font-size: 24px;
  letter-spacing: -.4px;
  color: #132d46;
}
.ed-hero-sub { margin: 0; color: var(--muted); font-size: 13.5px; }
.ed-hero-sub b { color: var(--accent); font-weight: 700; }

.ed-tariff-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}
.ed-tariff-chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid rgba(165, 188, 206, .55);
  background: #fff;
  font-size: 12.5px;
  font-weight: 600;
  color: #17334c;
  cursor: pointer;
  transition: all .18s ease;
  position: relative;
}
.ed-tariff-chip:hover { border-color: rgba(21, 152, 108, .5); transform: translateY(-1px); }
.ed-tariff-chip[data-active="true"] {
  background: linear-gradient(132deg, rgba(12, 96, 125, .14), rgba(21, 152, 108, .14));
  border-color: rgba(21, 152, 108, .55);
  color: #0c5b78;
  box-shadow: 0 4px 12px rgba(21, 152, 108, .14);
}
.ed-tariff-chip-active-mark {
  background: #15986c;
  color: #fff;
  border-radius: 999px;
  font-size: 9.5px;
  font-weight: 800;
  padding: 1px 6px;
  letter-spacing: .4px;
  text-transform: uppercase;
}
.ed-tariff-chip-seed-mark {
  background: var(--muted);
  color: #fff;
  border-radius: 999px;
  font-size: 9.5px;
  font-weight: 800;
  padding: 1px 6px;
  letter-spacing: .4px;
  text-transform: uppercase;
}
.ed-tariff-chip-actions {
  display: inline-flex;
  gap: 4px;
  margin-left: 4px;
}
.ed-tariff-chip-act {
  background: transparent;
  border: 0;
  color: var(--muted);
  cursor: pointer;
  font-size: 14px;
  padding: 2px 4px;
  border-radius: 6px;
}
.ed-tariff-chip-act:hover { background: rgba(124,161,188,.12); color: var(--accent); }
.ed-tariff-chip-act-danger:hover { color: #b91c1c; }
.ed-new-tariff-btn {
  background: linear-gradient(132deg, #0c607d 0%, #15986c 100%);
  color: #fff;
  border: none;
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 12.5px;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
}
.ed-new-tariff-btn:hover { transform: translateY(-1px); box-shadow: 0 6px 18px rgba(14,79,102,.25); }

/* ─── Tabs (familias) ─── */
.ed-tabs-bar {
  display: flex;
  gap: 6px;
  padding: 6px;
  margin-bottom: 12px;
  background: var(--card-bg, #fff);
  border-radius: 14px;
  box-shadow: 0 6px 20px rgba(11, 33, 54, .06);
  border: 1px solid rgba(165, 188, 206, 0.32);
  overflow-x: auto;
  scrollbar-width: thin;
}
.ed-tab {
  display: flex; align-items: center; gap: 8px;
  padding: 9px 16px; border: 1px solid transparent; border-radius: 10px;
  background: transparent; font-family: inherit; font-size: 13.5px;
  font-weight: 700; color: #2a4560; cursor: pointer; white-space: nowrap; flex-shrink: 0;
  transition: all .18s ease;
}
.ed-tab:hover { background: rgba(124, 161, 188, .1); }
.ed-tab[data-active="true"] {
  background: linear-gradient(132deg, #0c607d 0%, #15986c 100%);
  color: #fff;
  box-shadow: 0 6px 18px rgba(14, 79, 102, .25);
}
.ed-tab-count {
  font-size: 11px; font-weight: 800;
  background: rgba(124, 161, 188, .2); color: #17334c;
  border-radius: 999px; padding: 1px 7px; min-width: 22px;
  text-align: center; line-height: 1.4;
}
.ed-tab[data-active="true"] .ed-tab-count { background: rgba(255,255,255,.25); color: #fff; }

/* Wrap del tab + botón de menú ⋮ + botón "+" para añadir familia/capítulo */
.ed-tab-wrap, .ed-chip-wrap { display: inline-flex; align-items: stretch; flex-shrink: 0; border-radius: 10px; }
.ed-chip-wrap { border-radius: 999px; }
.ed-tab-menu-btn, .ed-chip-menu-btn {
  border: none; background: transparent;
  color: rgba(124, 161, 188, .65);
  padding: 0 8px; font-size: 16px; font-weight: 800;
  cursor: pointer; border-radius: 8px;
  transition: background .15s, color .15s;
  font-family: inherit;
}
.ed-tab-menu-btn:hover, .ed-chip-menu-btn:hover { background: rgba(124, 161, 188, .15); color: var(--accent); }
.ed-tab-add, .ed-chip-add {
  background: rgba(21, 152, 108, .1);
  border: 1px dashed rgba(21, 152, 108, .55);
  color: #0c5b78; font-family: inherit;
  font-size: 12.5px; font-weight: 600;
  padding: 8px 14px; border-radius: 10px;
  cursor: pointer; transition: all .15s ease;
  flex-shrink: 0; margin-left: 4px; align-self: center;
}
.ed-chip-add { border-radius: 999px; padding: 6px 14px; font-size: 12px; }
.ed-tab-add:hover, .ed-chip-add:hover { background: rgba(21, 152, 108, .2); transform: translateY(-1px); }

/* Menú contextual flotante */
.ed-ctx-menu {
  position: fixed; background: #fff;
  border-radius: 10px;
  border: 1px solid rgba(165, 188, 206, .45);
  box-shadow: 0 14px 38px rgba(11, 33, 54, .18);
  padding: 4px; z-index: 9998;
  min-width: 200px;
  display: flex; flex-direction: column; gap: 2px;
  animation: edCtxIn .14s ease-out both;
}
@keyframes edCtxIn { 0% { opacity: 0; transform: translateY(-4px); } 100% { opacity: 1; transform: translateY(0); } }
.ed-ctx-item {
  display: flex; align-items: center; gap: 9px;
  padding: 8px 12px; border: none; background: transparent;
  font-family: inherit; font-size: 13px; color: #17334c;
  cursor: pointer; border-radius: 7px; text-align: left;
  transition: background .12s;
}
.ed-ctx-item:hover { background: rgba(124, 161, 188, .12); }
.ed-ctx-item:disabled { opacity: .35; cursor: not-allowed; }
.ed-ctx-item-danger { color: #b91c1c; }
.ed-ctx-item-danger:hover { background: rgba(185, 28, 28, .08); }
.ed-ctx-icon { font-size: 14px; width: 18px; text-align: center; }
.ed-ctx-divider { height: 1px; background: rgba(158, 184, 206, .35); margin: 4px 6px; }

/* ─── Chips (capítulos) ─── */
.ed-chips-bar {
  display: flex; flex-wrap: wrap; gap: 6px;
  padding: 8px 10px; margin-bottom: 14px;
  background: rgba(255, 255, 255, .55);
  border-radius: 12px;
  border: 1px solid rgba(165, 188, 206, 0.22);
  min-height: 50px; align-items: center;
}
.ed-chip {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 7px 12px; border: 1px solid rgba(165, 188, 206, .55);
  border-radius: 999px; background: #fff; font-family: inherit;
  font-size: 12.5px; font-weight: 600; color: #17334c;
  cursor: pointer; white-space: nowrap;
  transition: all .18s ease;
}
.ed-chip:hover { border-color: rgba(21, 152, 108, .55); transform: translateY(-1px); }
.ed-chip[data-active="true"] {
  background: linear-gradient(132deg, rgba(12, 96, 125, .14), rgba(21, 152, 108, .14));
  border-color: rgba(21, 152, 108, .55);
  color: #0c5b78;
  box-shadow: 0 4px 12px rgba(21, 152, 108, .14);
}
.ed-chip[data-hidden-flag="true"] {
  opacity: .5;
  text-decoration: line-through;
}

/* ─── Capítulo editable ─── */
.ed-chapter-host { min-height: 300px; }
.ed-empty {
  text-align: center; color: var(--muted); padding: 60px 20px;
  font-size: 14px;
}
.ed-chapter {
  background: #fff;
  border-radius: 16px;
  padding: 22px 26px 18px;
  box-shadow: 0 6px 20px rgba(11, 33, 54, .06);
  border: 1px solid rgba(165, 188, 206, 0.32);
  animation: edChapterEnter .32s ease-out both;
}
@keyframes edChapterEnter {
  0%   { opacity: 0; }
  100% { opacity: 1; }
}
/* Cascada SOLO con opacity — los textos no se mueven (mareaba). */
.ed-chapter .ed-item-row {
  animation: edItemRowEnter .32s ease-out both;
  animation-delay: calc(var(--row-idx, 0) * 18ms + 60ms);
}
@keyframes edItemRowEnter {
  0%   { opacity: 0; }
  100% { opacity: 1; }
}
@media (prefers-reduced-motion: reduce) {
  .ed-chapter, .ed-chapter .ed-item-row { animation: none; }
}
/* Re-render por edición de un item (toggle visible, mover, borrar,
 * cambio de calcType): NO disparar la animación de cascada — mareaba. */
.ed-chapter.ed-chapter-no-anim,
.ed-chapter.ed-chapter-no-anim .ed-item-row { animation: none; }

.ed-chapter-hdr {
  display: flex; flex-wrap: wrap; align-items: center; gap: 12px;
  margin-bottom: 14px; padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
}
.ed-chapter-hdr-meta {
  display: flex; flex-wrap: wrap; align-items: center; gap: 14px;
  flex: 1; min-width: 0;
}
.ed-chapter-hdr-meta label {
  display: flex; flex-direction: column; gap: 3px;
  font-size: 11px; font-weight: 700; color: var(--muted);
  text-transform: uppercase; letter-spacing: .35px;
}
.ed-chapter-hdr-meta input,
.ed-chapter-hdr-meta select {
  padding: 7px 10px; border: 1px solid rgba(165, 188, 206, .55);
  border-radius: 8px; font-size: 13.5px; background: #fff; color: #17334c;
  font-family: inherit; text-transform: none; letter-spacing: 0;
}
.ed-chapter-hdr-meta input:focus, .ed-chapter-hdr-meta select:focus {
  outline: none; border-color: rgba(21, 152, 108, .6);
  box-shadow: 0 0 0 3px rgba(21, 152, 108, .14);
}
.ed-chapter-hdr-meta input[type="text"] { min-width: 280px; }
.ed-chapter-hdr-meta input[type="number"] { width: 110px; text-align: right; }

/* ─── Lista de items editable ─── */
.ed-items {
  display: flex; flex-direction: column;
  margin-bottom: 14px;
}
.ed-item-row {
  display: grid;
  grid-template-columns: 1fr 100px 80px 110px 90px auto;
  gap: 8px;
  align-items: center;
  padding: 8px 4px;
  border-bottom: 1px solid rgba(158, 184, 206, .18);
}
.ed-item-row:last-child { border-bottom: none; }
.ed-item-row[data-visible="false"] { opacity: .55; }
.ed-item-row input,
.ed-item-row select {
  padding: 6px 8px; border: 1px solid rgba(165, 188, 206, .55);
  border-radius: 7px; font-size: 13px; background: #fff; color: #17334c;
  font-family: inherit; width: 100%;
}
.ed-item-row input[type="number"] { text-align: right; font-variant-numeric: tabular-nums; }
.ed-item-row input:focus, .ed-item-row select:focus {
  outline: none; border-color: rgba(21, 152, 108, .6);
  box-shadow: 0 0 0 2px rgba(21, 152, 108, .12);
}
.ed-item-actions {
  display: inline-flex; gap: 2px; justify-content: flex-end;
}
.ed-item-act {
  background: transparent; border: 0; cursor: pointer;
  width: 28px; height: 28px; border-radius: 6px;
  display: grid; place-items: center;
  font-size: 14px; color: var(--muted);
  transition: background .12s, color .12s;
}
.ed-item-act:hover { background: rgba(124,161,188,.12); color: var(--accent); }
.ed-item-act:disabled { opacity: .25; cursor: not-allowed; }
.ed-item-act-danger:hover { color: #b91c1c; background: rgba(185,28,28,.08); }
.ed-item-act-toggle[data-on="true"] { color: var(--accent); }

/* sub-celda extra para tier (minTotal) o range/interpolated (min/max) */
.ed-item-extra {
  grid-column: 1 / -1;
  display: flex; gap: 12px; align-items: center;
  padding: 4px 4px 8px 4px;
  font-size: 12px; color: var(--muted);
}
.ed-item-extra label { display: flex; align-items: center; gap: 6px; }
.ed-item-extra input { width: 90px; }

/* ── Sub-panel dimensiones 2D (ventanas / puertas / encimeras) ── */
.ed-item-2d {
  flex-direction: column; align-items: stretch; gap: 8px;
  padding: 10px; background: color-mix(in srgb, var(--accent) 4%, transparent);
  border: 1px solid color-mix(in srgb, var(--accent) 20%, transparent);
  border-radius: 6px;
}
.ed-2d-bounds {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px;
}
.ed-2d-bounds label { font-size: 11px; color: var(--muted); display: flex; flex-direction: column; gap: 3px; }
.ed-2d-bounds input { width: 100%; }
.ed-2d-mode-row {
  display: flex; gap: 16px; padding: 4px 0; border-top: 1px dashed var(--border);
}
.ed-2d-mode-row label {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 12px; cursor: pointer;
}
.ed-2d-price-uniform input { width: 110px; }
.ed-2d-price-points {
  display: flex; flex-direction: column; gap: 6px;
}
.ed-2d-point {
  display: flex; align-items: center; gap: 6px;
  font-size: 12px; flex-wrap: wrap;
}
.ed-2d-point strong { min-width: 60px; color: var(--text); }
.ed-2d-point input { width: 75px; }
.ed-2d-point input[data-2d-point$="-price"] { width: 95px; }

@media (max-width: 860px) {
  .ed-item-row {
    grid-template-columns: 1fr 100px;
    gap: 6px;
  }
  .ed-item-row > .ed-mobile-hide { display: none; }
}

/* ─── Add item / sección ─── */
.ed-add-row {
  display: flex; gap: 10px; padding-top: 8px;
  border-top: 1px dashed rgba(158, 184, 206, .35);
}
.ed-add-btn {
  background: rgba(21, 152, 108, .1);
  border: 1px dashed rgba(21, 152, 108, .55);
  color: #0c5b78;
  font-family: inherit; font-size: 12.5px; font-weight: 600;
  padding: 8px 14px; border-radius: 8px; cursor: pointer;
}
.ed-add-btn:hover { background: rgba(21,152,108,.18); }

/* ─── Bottom bar ─── */
.ed-bottom-bar {
  position: fixed;
  bottom: 0; right: 0;
  /* Borde derecho del sidebar flotante = ancho + margen flotante. */
  left: calc(var(--sidebar-w, 252px) + var(--float-gap, 16px));
  background: rgba(255,255,255,.96);
  backdrop-filter: blur(8px);
  border-top: 1px solid rgba(165, 188, 206, .55);
  padding: 14px 24px;
  display: flex; align-items: center; gap: 14px;
  z-index: 100;
  box-shadow: 0 -8px 22px rgba(11, 33, 54, .08);
}
/* Sidebar plegado en escritorio: la barra ocupa todo el ancho. */
body.sb-closed .ed-bottom-bar { left: 0; }
@media (max-width: 860px) {
  .ed-bottom-bar { left: 0; }
  body.sb-closed .ed-bottom-bar { left: 0; }
}
.ed-bottom-status {
  display: flex; align-items: center; gap: 8px;
  font-size: 13px; color: var(--muted); flex: 1;
}
.ed-dot {
  width: 10px; height: 10px; border-radius: 999px;
  display: inline-block;
}
.ed-dot-clean { background: #cbd5e1; }
.ed-dot-dirty { background: #f59e0b; box-shadow: 0 0 0 4px rgba(245, 158, 11, .15); }

/* ─── Modales ─── */
.ed-modal-backdrop[hidden] { display: none !important; }
.ed-modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(11, 33, 54, .55);
  display: flex; align-items: center; justify-content: center;
  z-index: 9999; backdrop-filter: blur(4px); padding: 16px;
}
.ed-modal {
  background: #fff; border-radius: 16px;
  padding: 26px 28px 22px; width: min(440px, 96vw);
  box-shadow: 0 24px 60px rgba(11, 33, 54, .30);
  font-family: inherit; color: #17334c;
}
.ed-modal h2 { margin: 0 0 8px; font-size: 19px; }
.ed-modal p { margin: 0 0 14px; font-size: 13.5px; color: #5e768d; line-height: 1.5; }
.ed-modal-field { display: block; margin-bottom: 12px; }
.ed-modal-field span { display: block; font-size: 12px; font-weight: 600; color: #17334c; margin-bottom: 4px; }
.ed-modal-field input, .ed-modal-field select {
  width: 100%; box-sizing: border-box;
  padding: 10px 12px; border: 1px solid #cfd8e3; border-radius: 9px;
  font-size: 14px; background: #fff;
}
.ed-modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }

/* ─── Toast ─── */
.ed-toast {
  position: fixed; bottom: 110px; right: 24px;
  background: linear-gradient(132deg, #0c607d, #15986c);
  color: #fff;
  padding: 10px 16px; border-radius: 10px;
  box-shadow: 0 14px 28px rgba(14, 79, 102, .22);
  font-size: 13.5px; font-weight: 600;
  z-index: 9998;
  opacity: 0; transform: translateY(8px);
  transition: opacity .25s, transform .25s;
}
.ed-toast.visible { opacity: 1; transform: translateY(0); }
.ed-toast-error { background: linear-gradient(132deg, #b91c1c, #ef4444); }

/* ═══ Modo oscuro ══════════════════════════════════════════════════════
   Sin estas reglas las tarjetas heredaban el #fff cableado (background:
   var(--card-bg,#fff)) → tarjetas blancas con texto claro = "tarjetas en
   blanco". Usamos los tokens de la paleta oscura de app.css.            */
html[data-theme="dark"] .ed-tabs-bar,
html[data-theme="dark"] .ed-chapter {
  background: var(--card, #151B2D);
  border-color: var(--border, #232B3E);
  box-shadow: var(--shadow, 0 2px 6px rgba(0,0,0,.32));
}
html[data-theme="dark"] .ed-chips-bar {
  background: var(--surface-2, #1B2236);
  border-color: var(--border-soft, #1E263A);
}
html[data-theme="dark"] .ed-tab { color: var(--text, #E5E7EB); }
html[data-theme="dark"] .ed-tab:hover { background: rgba(124,161,188,.16); }
html[data-theme="dark"] .ed-tab-count { background: var(--surface-2, #1B2236); color: var(--text, #E5E7EB); }
html[data-theme="dark"] .ed-chip {
  background: var(--card, #151B2D);
  border-color: var(--border, #232B3E);
  color: var(--text, #E5E7EB);
}
html[data-theme="dark"] .ed-chip[data-active="true"] { color: #5fd6a6; }

/* Cabecera del capítulo + inputs/select */
html[data-theme="dark"] .ed-chapter-hdr { border-bottom-color: var(--border, #232B3E); }
html[data-theme="dark"] .ed-chapter-hdr-meta input,
html[data-theme="dark"] .ed-chapter-hdr-meta select,
html[data-theme="dark"] .ed-item-row input,
html[data-theme="dark"] .ed-item-row select {
  background: var(--surface-2, #1B2236);
  border-color: var(--border, #232B3E);
  color: var(--text, #E5E7EB);
}
html[data-theme="dark"] .ed-item-row { border-bottom-color: var(--border-soft, #1E263A); }

/* Barra inferior fija — era blanca translúcida (tapaba todo en oscuro). */
html[data-theme="dark"] .ed-bottom-bar {
  background: rgba(21, 27, 45, .96);
  border-top-color: var(--border, #232B3E);
}

/* Menú contextual y modal de formulario (eran blancos). */
html[data-theme="dark"] .ed-ctx-menu {
  background: var(--card, #151B2D);
  border-color: var(--border, #232B3E);
}
html[data-theme="dark"] .ed-ctx-item { color: var(--text, #E5E7EB); }
html[data-theme="dark"] .ed-ctx-item:hover { background: var(--surface-2, #1B2236); }
html[data-theme="dark"] .ed-modal {
  background: var(--card, #151B2D);
  color: var(--text, #E5E7EB);
}
html[data-theme="dark"] .ed-modal-field input,
html[data-theme="dark"] .ed-modal-field select {
  background: var(--surface-2, #1B2236);
  border-color: var(--border, #232B3E);
  color: var(--text, #E5E7EB);
}
