/* =====================================================================
   AUSAPE V8.4 · Responsive Total + Fórum Matrix Fix
   Objetivo: evitar solapes, mantener configuración visual y corregir
   matrices anchas de Fórum sin romper datos ni localStorage.
   ===================================================================== */
:root{
  --v84-blue:#009fe3;
  --v84-blue-dark:#005982;
  --v84-navy:#003b5c;
  --v84-ink:#10283d;
  --v84-muted:#60788d;
  --v84-line:rgba(0,117,170,.18);
  --v84-soft:#edf9ff;
  --v84-card:#fff;
  --v84-shadow:0 18px 48px rgba(0,64,96,.12);
  --v84-radius:20px;
  --v84-meta1:104px;
  --v84-meta2:132px;
  --v84-meta3:118px;
  --v84-meta-total:354px;
  --v84-room-col:220px;
}

html,body{max-width:100%;overflow-x:hidden!important;}
body.v84-ready{background:linear-gradient(135deg,#edf9ff 0%,#f8fdff 45%,#ffffff 100%)!important;}
body.v84-ready .app{width:100%;max-width:100vw;min-width:0;}
body.v84-ready .main{min-width:0!important;width:100%!important;max-width:100%!important;overflow-x:hidden!important;}
body.v84-ready .section{min-width:0!important;max-width:100%!important;}
body.v84-ready .section.active{animation:v84SectionSoftIn .22s cubic-bezier(.22,1,.36,1) both!important;}
@keyframes v84SectionSoftIn{from{opacity:.72;transform:translateY(6px);filter:blur(2px)}to{opacity:1;transform:none;filter:blur(0)}}

/* Layout universal anti-solape */
body.v84-ready .card,
body.v84-ready .panel,
body.v84-ready .module-card,
body.v84-ready .budget-panel,
body.v84-ready .forum-flex-card,
body.v84-ready .screen-preview-card{
  max-width:100%!important;
  min-width:0!important;
  overflow:hidden!important;
  contain:layout paint;
}
body.v84-ready .card > *,
body.v84-ready .panel > *,
body.v84-ready .module-card > *{min-width:0!important;}
body.v84-ready .section-title{grid-template-columns:minmax(0,1fr) auto!important;align-items:start!important;gap:18px!important;}
body.v84-ready .section-title h3,
body.v84-ready .section-title p{overflow-wrap:anywhere!important;}
body.v84-ready .actions,
body.v84-ready .top-actions,
body.v84-ready .table-head,
body.v84-ready .modal-actions{display:flex!important;flex-wrap:wrap!important;gap:10px!important;align-items:center!important;min-width:0!important;}
body.v84-ready .actions{justify-content:flex-start!important;}
body.v84-ready .filters,
body.v84-ready .formgrid,
body.v84-ready .forum-flex-toolbar{
  display:grid!important;
  grid-template-columns:repeat(auto-fit,minmax(min(100%,230px),1fr))!important;
  gap:12px!important;
  align-items:end!important;
  max-width:100%!important;
}
body.v84-ready input,
body.v84-ready select,
body.v84-ready textarea,
body.v84-ready .input{min-width:0!important;width:100%!important;max-width:100%!important;}
body.v84-ready .btn,
body.v84-ready .mini,
body.v84-ready button{max-width:100%;white-space:normal!important;overflow-wrap:anywhere!important;}
body.v84-ready .grid,
body.v84-ready .grid.two,
body.v84-ready .grid.main-dash,
body.v84-ready .grid.kpis,
body.v84-ready .kpis,
body.v84-ready .budget-kpis,
body.v84-ready .mini-kpis{
  display:grid!important;
  grid-template-columns:repeat(auto-fit,minmax(min(100%,240px),1fr))!important;
  gap:16px!important;
  max-width:100%!important;
}
body.v84-ready .kpi b,
body.v84-ready .card.kpi b{font-size:clamp(26px,4vw,44px)!important;line-height:1!important;overflow-wrap:anywhere!important;}

/* Scroll profesional de tablas: no encoger columnas críticas */
body.v84-ready .tablewrap,
body.v84-ready .tablebox,
body.v84-ready .matrix-wrap,
body.v84-ready .forum-matrix-wrap{
  width:100%!important;
  max-width:100%!important;
  overflow:auto!important;
  overscroll-behavior:contain!important;
  scrollbar-gutter:stable both-edges!important;
  -webkit-overflow-scrolling:touch!important;
  border-radius:20px!important;
}
body.v84-ready .tablewrap table,
body.v84-ready .tablebox table{width:max-content!important;min-width:100%!important;}
body.v84-ready th,
body.v84-ready td{word-break:normal!important;overflow-wrap:break-word!important;}
body.v84-ready thead th{white-space:nowrap!important;}

/* Fórum flexible: matriz ancha con columnas fijas y texto legible */
body.v84-ready .forum-flex-card{overflow:visible!important;contain:none!important;}
body.v84-ready .forum-flex-card .section-title{display:grid!important;grid-template-columns:minmax(0,1fr) auto!important;}
body.v84-ready .forum-flex-kpis{grid-template-columns:repeat(auto-fit,minmax(170px,1fr))!important;}
body.v84-ready .forum-flex-rules{display:flex!important;flex-wrap:wrap!important;gap:8px!important;}
body.v84-ready .forum-flex-rules span{white-space:normal!important;}
body.v84-ready .forum-matrix-wrap{
  position:relative!important;
  max-height:min(72vh,760px)!important;
  background:#fff!important;
  border:1px solid rgba(0,117,170,.20)!important;
  box-shadow:inset 0 0 0 1px rgba(255,255,255,.7),0 12px 34px rgba(0,64,96,.08)!important;
}
body.v84-ready .forum-matrix{
  border-collapse:separate!important;
  border-spacing:0!important;
  table-layout:fixed!important;
  width:max-content!important;
  min-width:calc(var(--v84-meta-total) + (8 * var(--v84-room-col)))!important;
}
body.v84-ready .forum-matrix th,
body.v84-ready .forum-matrix td{
  padding:12px!important;
  vertical-align:top!important;
  border-right:1px solid #e4f2f9!important;
  border-bottom:1px solid #e4f2f9!important;
}
body.v84-ready .forum-matrix thead th{
  position:sticky!important;
  top:0!important;
  z-index:5!important;
  background:linear-gradient(180deg,#dff4fd,#cdecf8)!important;
  color:#004d73!important;
  font-weight:950!important;
  text-align:left!important;
  white-space:nowrap!important;
  letter-spacing:.04em!important;
  height:auto!important;
}
body.v84-ready .forum-matrix thead th:nth-child(1),
body.v84-ready .forum-matrix tbody th:nth-child(1){
  position:sticky!important;left:0!important;z-index:7!important;width:var(--v84-meta1)!important;min-width:var(--v84-meta1)!important;max-width:var(--v84-meta1)!important;
}
body.v84-ready .forum-matrix thead th:nth-child(2),
body.v84-ready .forum-matrix tbody th:nth-child(2){
  position:sticky!important;left:var(--v84-meta1)!important;z-index:7!important;width:var(--v84-meta2)!important;min-width:var(--v84-meta2)!important;max-width:var(--v84-meta2)!important;
}
body.v84-ready .forum-matrix thead th:nth-child(3),
body.v84-ready .forum-matrix tbody th:nth-child(3){
  position:sticky!important;left:calc(var(--v84-meta1) + var(--v84-meta2))!important;z-index:7!important;width:var(--v84-meta3)!important;min-width:var(--v84-meta3)!important;max-width:var(--v84-meta3)!important;
}
body.v84-ready .forum-matrix tbody th:nth-child(-n+3){
  background:#f6fcff!important;
  color:#173047!important;
  font-weight:950!important;
  white-space:nowrap!important;
  word-break:normal!important;
  overflow-wrap:normal!important;
  writing-mode:horizontal-tb!important;
  text-orientation:mixed!important;
}
body.v84-ready .forum-matrix thead th:nth-child(-n+3){z-index:9!important;background:linear-gradient(180deg,#cdecf8,#bde7f6)!important;}
body.v84-ready .forum-matrix thead th:nth-child(n+4),
body.v84-ready .forum-matrix td{
  width:var(--v84-room-col)!important;
  min-width:var(--v84-room-col)!important;
  max-width:var(--v84-room-col)!important;
}
body.v84-ready .forum-matrix .matrix-empty{display:block;color:#6c8296!important;font-weight:850!important;white-space:nowrap!important;}
body.v84-ready .matrix-session{
  min-width:0!important;
  width:100%!important;
  margin:0 0 8px!important;
  padding:10px 12px!important;
  border-radius:14px!important;
  overflow:hidden!important;
}
body.v84-ready .matrix-session b,
body.v84-ready .matrix-session em{overflow-wrap:anywhere!important;}
body.v84-ready .matrix-session small{white-space:normal!important;}
.v84-swipe-hint{
  display:flex;align-items:center;justify-content:space-between;gap:10px;
  margin:10px 0 8px;padding:9px 12px;border:1px solid rgba(0,117,170,.18);
  background:linear-gradient(135deg,#f4fcff,#ffffff);border-radius:14px;color:#31506a;font-weight:850;font-size:12px;
}
.v84-swipe-hint code{background:#eaf8ff;border:1px solid #cfeffa;border-radius:8px;padding:3px 7px;color:#005982;font-weight:950;}
.v84-forum-viewbar{display:flex;flex-wrap:wrap;gap:8px;align-items:center;margin:10px 0 12px;}
.v84-forum-viewbar .mini.active{background:linear-gradient(135deg,#009fe3,#007eb9)!important;color:#fff!important;}
.v84-forum-cards{display:none;grid-template-columns:repeat(auto-fit,minmax(min(100%,280px),1fr));gap:12px;margin-top:12px;}
.v84-cards-mode .forum-matrix-wrap{display:none!important;}
.v84-cards-mode .v84-forum-cards{display:grid!important;}
.v84-forum-card{border:1px solid rgba(0,117,170,.16);border-radius:18px;background:#fff;padding:14px;box-shadow:0 10px 24px rgba(0,64,96,.08);}
.v84-forum-card .meta{display:flex;flex-wrap:wrap;gap:6px;margin-bottom:8px;}
.v84-forum-card .meta span{background:#eaf8ff;color:#005982;border-radius:999px;padding:4px 8px;font-weight:950;font-size:11px;}
.v84-forum-card b{display:block;color:#003b5c;font-size:16px;line-height:1.1;margin-bottom:4px;}
.v84-forum-card small{display:block;color:#60788d;font-weight:800;}
.v84-forum-card.conflict{border-color:#f59e0b;background:#fffaf0;}

/* Sidebar y pantallas pequeñas */
@media(max-width:1180px){
  body.v84-ready .app{grid-template-columns:minmax(248px,286px) minmax(0,1fr)!important;}
  body.v84-ready .topbar{grid-template-columns:1fr!important;}
  body.v84-ready .top-actions{justify-content:flex-start!important;}
  body.v84-ready .section-title{grid-template-columns:1fr!important;}
  body.v84-ready .forum-flex-card .section-title{grid-template-columns:1fr!important;}
}
@media(max-width:860px){
  body.v84-ready .app{display:block!important;}
  body.v84-ready .sidebar{position:relative!important;width:100%!important;max-height:none!important;min-height:auto!important;}
  body.v84-ready .sidebar .nav{max-height:none!important;grid-template-columns:repeat(auto-fit,minmax(180px,1fr))!important;display:grid!important;}
  body.v84-ready .main{padding:12px!important;}
  body.v84-ready .topbar{position:relative!important;border-radius:0 0 24px 24px!important;}
  body.v84-ready .session-card{max-width:100%!important;width:100%!important;}
  body.v84-ready .forum-matrix-wrap{max-height:68vh!important;}
}
@media(max-width:640px){
  :root{--v84-meta1:84px;--v84-meta2:112px;--v84-meta3:96px;--v84-meta-total:292px;--v84-room-col:190px;}
  body.v84-ready .nav{grid-template-columns:1fr!important;}
  body.v84-ready .kpi b,body.v84-ready .card.kpi b{font-size:30px!important;}
  body.v84-ready .card,body.v84-ready .panel,body.v84-ready .module-card{border-radius:18px!important;}
}

@media print{
  .v84-swipe-hint,.v84-forum-viewbar,.v84-forum-cards{display:none!important;}
  body.v84-ready .forum-matrix-wrap{max-height:none!important;overflow:visible!important;}
  body.v84-ready .forum-matrix{transform-origin:top left;}
}
