/* Componentes compartidos por todas las pantallas (clases de C9). */

/* ============================================================
   ENCABEZADO DE PANTALLA
   ============================================================ */
.cab-pagina { margin-bottom: 18px; }
.cab-pagina h1 { font-size: 21px; }
.cab-pagina .sub { margin-top: 4px; max-width: 74ch; font-size: 13px; color: var(--ink-2); }
.vista [tabindex="-1"]:focus { outline: none; }   /* el h1 recibe el foco al navegar; no es un control */

/* ============================================================
   PANELES
   ============================================================ */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
.panel-cab {
  display: flex; align-items: center; gap: 10px;
  padding: 13px 16px;
  border-bottom: 1px solid var(--border);
}
.panel-cab h3 { font-size: 13.5px; }
.panel-cab .sub { font-size: 11.5px; color: var(--ink-3); }
.panel-cab .der { display: flex; align-items: center; gap: 7px; margin-left: auto; }
.panel-cuerpo { padding: 16px; }
.panel-cuerpo.plano { padding: 0; }

/* ============================================================
   GRILLAS
   ============================================================ */
.grilla, .grilla-2, .grilla-2-1 { display: grid; gap: 14px; align-items: start; }
.grilla-2 { grid-template-columns: repeat(2, minmax(0,1fr)); }
.grilla-2-1 { grid-template-columns: minmax(0,2fr) minmax(0,1fr); }

/* ============================================================
   BOTONES
   ============================================================ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  min-height: 36px; padding: 6px 14px;
  border: 1px solid var(--border-2); border-radius: var(--r-sm);
  background: var(--surface); color: var(--ink);
  font: 500 13px/1.2 var(--sans); text-align: center; text-decoration: none;
  cursor: pointer; touch-action: manipulation; -webkit-user-select: none; user-select: none;
  transition: background .12s, border-color .12s, color .12s;
}
.btn svg { flex: none; }
.btn-primario { background: var(--brand); border-color: var(--brand); color: var(--on-brand); font-weight: 600; }
.btn-chico { min-height: 28px; padding: 3px 10px; gap: 5px; font-size: 12px; }
.btn-fantasma { background: transparent; border-color: transparent; color: var(--ink-2); }
.btn-icono { width: 36px; padding: 0; }
.btn-chico.btn-icono { width: 28px; }
.btn[disabled] { opacity: .5; cursor: default; }
@media (hover: hover) {
  .btn:not([disabled]):hover { background: var(--surface-3); }
  .btn-primario:not([disabled]):hover { background: var(--brand-ink); border-color: var(--brand-ink); }
}
@media (hover: none) {
  .btn:not([disabled]):active { background: var(--surface-3); }
  .btn-primario:not([disabled]):active { background: var(--brand-ink); border-color: var(--brand-ink); }
}

/* ============================================================
   ESTADOS
   ============================================================ */
.pill {
  display: inline-flex; align-items: center; gap: 5px;
  height: 22px; padding: 0 8px; border-radius: 11px;
  background: var(--idle-soft); color: var(--ink-2);
  font-size: 11.5px; font-weight: 600; line-height: 1; white-space: nowrap;
}
.pill::before { content: ""; flex: none; width: 5px; height: 5px; border-radius: 50%; background: currentColor; }
.pill:has(svg)::before { display: none; }   /* con ícono no hace falta el punto */
.pill.bien    { background: var(--good-soft);  color: var(--good); }
.pill.alerta  { background: var(--warn-soft);  color: var(--warn); }
.pill.critico { background: var(--crit-soft);  color: var(--crit); }
.pill.info    { background: var(--brand-soft); color: var(--brand); }
.pill.neutro  { background: var(--idle-soft);  color: var(--ink-2); }

/* ============================================================
   FILTROS
   ============================================================ */
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; flex: none;
  min-height: 32px; padding: 5px 12px;
  border: 1px solid var(--border-2); border-radius: 30px;
  background: var(--surface); color: var(--ink-2);
  font: 500 12.5px/1.2 var(--sans); white-space: nowrap;
  cursor: pointer; touch-action: manipulation; -webkit-user-select: none; user-select: none;
}
.chip b { font-family: var(--mono); font-weight: 600; color: var(--ink); }
.chip[aria-pressed="true"] { background: var(--float-bg); border-color: var(--float-bg); color: var(--float-ink); }
.chip[aria-pressed="true"] b { color: inherit; }
@media (hover: hover) { .chip:not([aria-pressed="true"]):hover { background: var(--surface-3); } }

/* ============================================================
   PESTAÑAS
   ============================================================ */
.pestanas {
  display: flex; gap: 2px;
  width: fit-content; max-width: 100%; padding: 3px;
  background: var(--surface-3); border-radius: var(--r-md);
  overflow-x: auto; scrollbar-width: none;
}
.pestanas::-webkit-scrollbar { display: none; }
.pestana {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; flex: none;
  min-height: 30px; padding: 0 12px;
  border: 0; border-radius: var(--r-sm);
  background: none; color: var(--ink-2);
  font: 500 12.5px/1.2 var(--sans); white-space: nowrap;
  cursor: pointer; touch-action: manipulation;
}
.pestana b { font-family: var(--mono); font-weight: 500; color: var(--ink-3); }
.pestana[aria-selected="true"] { background: var(--surface); color: var(--ink); font-weight: 600; box-shadow: var(--shadow-sm); }
.pestana[aria-selected="true"] b { color: var(--brand-ink); }

/* ============================================================
   INDICADORES
   ============================================================ */
.kpis {
  display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0,1fr); gap: 1px;
  background: var(--border);
  border: 1px solid var(--border); border-radius: var(--r-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
.kpi {
  display: block; padding: 13px 15px;
  border: 0; background: var(--surface); color: var(--ink);
  font: inherit; text-align: left;
}
button.kpi { cursor: pointer; touch-action: manipulation; }
@media (hover: hover) { button.kpi:hover { background: var(--surface-2); } }
.kpi-l { margin-bottom: 5px; font-size: 11px; font-weight: 500; color: var(--ink-3); }
.kpi-v { font-family: var(--mono); font-size: 22px; font-weight: 600; letter-spacing: -.02em; line-height: 1.1; }

/* ============================================================
   LISTAS
   ============================================================ */
.lista { display: flex; flex-direction: column; }
.fila {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 16px;
  border-bottom: 1px solid var(--border);
}
.fila:last-child { border-bottom: 0; }
.fila-principal { flex: 1; min-width: 0; }
.fila-lado { display: flex; align-items: center; gap: 8px; flex: none; margin-left: auto; }

.miniatura {
  display: block; flex: none;
  width: 40px; height: 40px;
  border: 1px solid var(--border); border-radius: var(--r-sm);
  background: var(--surface-2);
  object-fit: contain;
}

.vacio { padding: 26px; text-align: center; font-size: 12.5px; color: var(--ink-3); }

/* ============================================================
   FORMULARIOS
   ============================================================ */
.campo { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.campo label { font-size: 11.5px; font-weight: 600; color: var(--ink-2); }
.campo input, .campo select, .campo textarea {
  width: 100%; min-height: 36px; padding: 7px 10px;
  border: 1px solid var(--border-2); border-radius: var(--r-sm);
  background: var(--surface); color: var(--ink);
  font: 13.5px/1.4 var(--sans);
}
.campo textarea { min-height: 84px; resize: vertical; }
.campo input:focus-visible, .campo select:focus-visible, .campo textarea:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; border-radius: var(--r-sm); }
.campo input:disabled, .campo select:disabled, .campo textarea:disabled { opacity: .6; }

.interruptor {
  position: relative; flex: none;
  width: 34px; height: 20px; padding: 0;
  border: 0; border-radius: 20px;
  background: var(--border-2);
  cursor: pointer; touch-action: manipulation;
  transition: background .15s;
}
.interruptor::after {
  content: ""; position: absolute; top: 2px; left: 2px;
  width: 16px; height: 16px; border-radius: 50%;
  background: #fff; box-shadow: var(--shadow-sm);
  transition: transform .15s;
}
.interruptor[aria-checked="true"] { background: var(--good); }
.interruptor[aria-checked="true"]::after { transform: translateX(14px); }
.interruptor[disabled] { opacity: .5; cursor: default; }

/* ============================================================
   BARRA DE ACCIÓN (selección)
   ============================================================ */
.barra-accion {
  position: sticky; bottom: 14px; z-index: 20;
  display: flex; align-items: center; flex-wrap: wrap; gap: 10px;
  margin-top: 14px; padding: 10px 14px;
  background: var(--float-bg); color: var(--float-ink);
  border-radius: var(--r-lg); box-shadow: var(--shadow-lg);
}
.barra-accion .btn { border-color: transparent; white-space: nowrap; }
.barra-accion .btn:not(.btn-primario) { background: rgba(127,127,127,.18); color: var(--float-ink); }
.barra-accion :focus-visible { outline-color: var(--sun); }

/* ============================================================
   HOJAS — panel a la derecha en escritorio, hoja inferior en celular
   ============================================================ */
.hoja-velo {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(6,18,22,.5);
  animation: aparecer .18s ease-out;
}
.hoja {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 61;
  display: flex; flex-direction: column;
  width: min(440px, 100vw);
  background: var(--surface);
  border-left: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  animation: hoja-entra .24s cubic-bezier(.22,1,.36,1);
}
.hoja.ancha { width: min(680px, 100vw); }
.hoja-asa { display: none; }
.hoja-cab {
  display: flex; align-items: flex-start; gap: 12px; flex: none;
  padding: 15px 14px 14px 18px;
  border-bottom: 1px solid var(--border);
}
.hoja-titulos { flex: 1; min-width: 0; }
.hoja-cab .eyebrow { margin-bottom: 3px; }
.hoja-cab h3 { font-size: 15px; overflow-wrap: anywhere; }
.hoja-cerrar { flex: none; margin-top: -4px; }
.hoja-cuerpo { flex: 1; min-height: 0; padding: 18px; overflow-y: auto; overscroll-behavior: contain; }
.hoja-pie {
  display: flex; align-items: center; justify-content: flex-end; flex-wrap: wrap; gap: 8px; flex: none;
  padding: 12px 18px;
  background: var(--surface);
  border-top: 1px solid var(--border);
}

/* Bloqueo del scroll del body mientras hay una hoja (solo lo activa hoja.js en celular) */
body.hoja-abierta { position: fixed; left: 0; right: 0; width: 100%; overflow: hidden; }

@keyframes aparecer   { from { opacity: 0; } }
@keyframes desvanecer { to { opacity: 0; } }
@keyframes hoja-entra { from { transform: translateX(24px); opacity: .4; } }
@keyframes hoja-sube  { from { transform: translateY(100%); } }
@keyframes hoja-baja  { to { transform: translateY(100%); } }

/* ============================================================
   AVISOS — la capa queda fija abajo al centro y apila hasta 3
   ============================================================ */
#capa-avisos {
  position: fixed; left: 50%; bottom: 24px; z-index: 95;
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  width: max-content; max-width: calc(100vw - 32px);
  transform: translateX(-50%);
  pointer-events: none;
}
.aviso {
  max-width: 100%; padding: 10px 16px;
  background: var(--float-bg); color: var(--float-ink);
  border-radius: 22px; box-shadow: var(--shadow-lg);
  font-size: 13px; line-height: 1.4; text-align: center;
  animation: aviso-entra .2s ease-out;
  transition: opacity .2s, transform .2s;
}
.aviso.saliendo { opacity: 0; transform: translateY(8px); }
@keyframes aviso-entra { from { opacity: 0; transform: translateY(12px); } }

/* ============================================================
   WHATSAPP — fondo de conversación y burbuja (como en Torre de Control)
   ============================================================ */
.fondo-wa {
  display: flex; flex-direction: column; gap: 8px;
  padding: 14px;
  background: var(--wa-bg);
  border-radius: var(--r-md);
}
.burbuja-wa {
  align-self: flex-end;
  max-width: 90%; padding: 9px 11px 6px;
  background: var(--wa-bubble); color: var(--ink);
  border-radius: 9px 9px 2px 9px;
  box-shadow: var(--shadow-sm);
  font-size: 13px; line-height: 1.5;
  white-space: pre-wrap; overflow-wrap: anywhere;
}
.burbuja-wa-hora {
  display: block; margin-top: 3px;
  font-family: var(--mono); font-size: 10px; color: var(--ink-3); text-align: right;
}

/* ============================================================
   PAPEL — foto de una lista escrita a mano o impresa (Ofertas y Chats)
   Es una foto: queda crema en los dos temas, apenas atenuada en el oscuro.
   ============================================================ */
.papel {
  padding: 10px 16px 12px;
  background-color: #F6F0DC;
  background-image: repeating-linear-gradient(to bottom, transparent 0 27px, rgba(70,100,150,.22) 27px 28px);
  background-origin: content-box;
  color: #2B2923;
  border-radius: 3px;
  box-shadow: 0 1px 2px rgba(11,25,30,.16), 0 8px 18px rgba(11,25,30,.10);
  font: 500 13px/28px var(--mono);
  transform: rotate(-.5deg);
}
.papel-renglon { margin: 0 -6px; padding: 0 6px; border-radius: 2px; white-space: pre-wrap; overflow-wrap: anywhere; }
.papel-renglon.marcado { background: rgba(245,166,35,.36); box-shadow: inset 3px 0 0 #D98300; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .papel { filter: brightness(.88); } }
:root[data-theme="dark"] .papel { filter: brightness(.88); }

/* ============================================================
   SPARKLINE — serie de 30 días (js/ui/sparkline.js)
   ============================================================ */
.sparkline { display: block; overflow: visible; }
.sparkline line, .sparkline polyline, .sparkline circle { vector-effect: non-scaling-stroke; }
.sparkline-linea { fill: none; stroke: var(--brand); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.sparkline-minimo { stroke: var(--border-2); stroke-width: 1; stroke-dasharray: 3 3; }
.sparkline-hoy { stroke: var(--ink-3); stroke-width: 1.5; stroke-dasharray: 2 3; }
.sparkline-marca { fill: var(--sun); stroke: var(--surface); stroke-width: 2; }

/* ============================================================
   CELULAR (<= 860 px)
   ============================================================ */
@media (max-width: 860px) {
  .cab-pagina { margin-bottom: 14px; }
  .cab-pagina h1 { font-size: 19px; }
  .cab-pagina .sub { max-width: none; font-size: 12.5px; line-height: 1.45; }

  .panel-cab { flex-wrap: wrap; row-gap: 8px; padding: 12px 14px; }
  .panel-cuerpo { padding: 14px; }

  .grilla-2, .grilla-2-1 { grid-template-columns: minmax(0,1fr); }

  /* Objetivos táctiles de 44 px */
  .btn { min-height: 44px; padding: 8px 14px; font-size: 13.5px; }
  .btn-chico { min-height: 44px; padding: 6px 12px; font-size: 12.5px; }
  .btn-icono, .btn-chico.btn-icono { width: 44px; padding: 0; }
  .chip { min-height: 44px; font-size: 13px; }
  .chips { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; margin: -3px; padding: 3px; }
  .chips::-webkit-scrollbar { display: none; }
  .pestanas { width: 100%; }
  .pestana { flex: 1 0 auto; min-height: 44px; font-size: 13px; }
  .pill { font-size: 11.5px; }

  .kpis { grid-auto-flow: row; grid-template-columns: repeat(2, minmax(0,1fr)); }
  .kpi { padding: 11px 12px; }
  .kpi-l { margin-bottom: 3px; }

  .fila { padding: 12px 14px; }

  .campo input, .campo select, .campo textarea { min-height: 44px; font-size: 16px; }   /* iOS no hace zoom al enfocar */

  .interruptor { width: 46px; height: 26px; }
  .interruptor::before { content: ""; position: absolute; inset: -9px -10px; }   /* área táctil de 44 px */
  .interruptor::after { width: 22px; height: 22px; }
  .interruptor[aria-checked="true"]::after { transform: translateX(20px); }

  .barra-accion {
    position: fixed; left: 16px; right: 16px; bottom: calc(74px + env(safe-area-inset-bottom, 0px));
    margin: 0;
  }
  .barra-accion .btn { flex: 1 1 auto; }

  .hoja {
    top: auto; left: 0; right: 0; bottom: 0;
    width: auto; height: 92%;
    border-left: 0; border-top: 1px solid var(--border);
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -12px 40px rgba(11,25,30,.28);
    animation: hoja-sube .28s cubic-bezier(.22,1,.36,1);
  }
  .hoja.ancha { width: auto; }
  .hoja.cerrando { animation: hoja-baja .2s ease-in forwards; }
  .hoja-velo { touch-action: none; }
  .hoja-velo.cerrando { animation: desvanecer .2s ease-in forwards; pointer-events: none; }
  .hoja-asa { display: grid; place-items: center; flex: none; height: 24px; }
  .hoja-asa::before { content: ""; width: 36px; height: 4px; border-radius: 2px; background: var(--border-2); }
  .hoja-cab { padding: 2px 8px 10px 16px; }
  .hoja-cab h3 { font-size: 17px; }
  .hoja-cerrar { margin-top: -6px; }
  .hoja-cuerpo { padding: 16px; }
  .hoja-cuerpo:last-child { padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px)); }
  .hoja-pie { padding: 12px 16px calc(12px + env(safe-area-inset-bottom, 0px)); }
  .hoja-pie .btn { flex: 1 1 auto; }

  #capa-avisos { bottom: calc(76px + env(safe-area-inset-bottom, 0px)); }
}
