/* CRM-TO 2.38.2 — global layout safety layer.
 * Loaded last. Prevents tables, forms, grids and action groups from stretching
 * the whole cabinet or collapsing text into vertical letters.
 */

.er-app,
.er-app *{box-sizing:border-box}

.er-app,
.er-app .er-content,
.er-app .er-main,
.er-app .er-page,
.er-app .er-card,
.er-app .er-panel,
.er-app .er-tab-panel,
.er-app .er-dashboard,
.er-app .er-report,
.er-app .er-grid,
.er-app .er-form-grid,
.er-app .er-filter-row,
.er-app .er-toolbar,
.er-app .er-table-wrap,
.er-app .er-layout-table-scroll{min-width:0;max-width:100%}

.er-app img,
.er-app video,
.er-app canvas,
.er-app svg{max-width:100%;height:auto}

/* Universal table viewport. JS adds this wrapper to tables that did not have one. */
.er-layout-table-scroll{
  position:relative;
  width:100%;
  max-width:100%;
  overflow-x:auto;
  overflow-y:visible;
  -webkit-overflow-scrolling:touch;
  scrollbar-gutter:stable;
  border-radius:14px;
}

.er-app .er-table-wrap,
.er-app .er-wallet-table-wrap,
.er-app .er-agents-report-table-wrap{
  width:100%;
  max-width:100%;
  overflow-x:auto;
  overflow-y:visible;
  -webkit-overflow-scrolling:touch;
  scrollbar-gutter:stable;
}

/* Never allow table content to become one letter per line. */
.er-app table,
.er-app table.er-table{
  writing-mode:horizontal-tb!important;
  text-orientation:mixed!important;
}
.er-app table th,
.er-app table td,
.er-app table th *,
.er-app table td *{
  writing-mode:horizontal-tb!important;
  text-orientation:mixed!important;
  word-break:normal!important;
  overflow-wrap:break-word!important;
  hyphens:none;
}
.er-app table th,
.er-app table td{
  min-width:72px;
  vertical-align:middle;
}
.er-app table th{white-space:normal}
.er-app table td.er-num,
.er-app table th.er-num,
.er-app table [data-er-money],
.er-app table input[type="number"]{white-space:nowrap}

/* Keep action controls usable and horizontal. */
.er-app table td:last-child .er-btn,
.er-app table td:last-child button,
.er-app table td:last-child input,
.er-app table td.er-col-actions .er-btn,
.er-app table td.er-col-actions button,
.er-app table td.er-col-actions input{
  writing-mode:horizontal-tb!important;
  white-space:nowrap!important;
  word-break:keep-all!important;
}
.er-app .er-actions,
.er-app .er-inline-actions,
.er-app .er-row-actions,
.er-app .er-table-actions,
.er-app td.er-col-actions,
.er-app td:last-child .er-actions{
  display:flex;
  align-items:center;
  gap:7px;
  flex-wrap:wrap;
  min-width:0;
}
.er-app table input:not([type="checkbox"]):not([type="radio"]),
.er-app table select,
.er-app table textarea{
  max-width:100%;
  min-width:0;
}

/* Grids must shrink instead of widening the page. */
.er-app [class*="grid"] > *,
.er-app [class*="columns"] > *,
.er-app .er-card > *,
.er-app .er-panel > *{min-width:0}

/* Long technical values stay inside their card. */
.er-app code,
.er-app pre,
.er-app .er-technical-value,
.er-app .er-file-name,
.er-app .er-url{
  max-width:100%;
  overflow-wrap:anywhere;
  word-break:break-word;
}

/* Desktop/tablet: broad reports scroll internally, never stretch the page. */
@media (min-width:769px){
  .er-app{overflow-x:hidden}
  .er-app table.er-table{width:max-content;min-width:100%;max-width:none}
  .er-app table.er-table--compact,
  .er-app table.er-table-compact{min-width:720px}
  .er-app table.er-table-records{min-width:1480px}
  .er-app table.er-table-tx{min-width:980px}
  .er-app table.er-cash-history-table{min-width:1180px}
  .er-app table.er-wallet-history-table{min-width:900px}
  .er-app table.er-table-services-month{min-width:900px}
  .er-app table.er-table-agents-report{min-width:2260px;table-layout:fixed}

  .er-app table.er-table-agents-report th,
  .er-app table.er-table-agents-report td{overflow:hidden;text-overflow:ellipsis}
  .er-app table.er-table-agents-report td:nth-child(14),
  .er-app table.er-table-agents-report td:nth-child(15),
  .er-app table.er-table-agents-report td:nth-child(16){overflow:visible;text-overflow:clip}
}

/* Mobile: page itself never scrolls sideways; table workspaces may scroll internally. */
@media (max-width:768px){
  html,body{max-width:100%;overflow-x:hidden}
  .er-app{width:100%;max-width:100%;overflow-x:hidden}
  .er-app .er-card,
  .er-app .er-panel,
  .er-app .er-toolbar,
  .er-app .er-filter-row,
  .er-app .er-form-row{max-width:100%}
  .er-app .er-layout-table-scroll{border-radius:12px}
  .er-app .er-actions,
  .er-app .er-inline-actions,
  .er-app .er-row-actions{width:100%}
  .er-app .er-actions > *,
  .er-app .er-inline-actions > *,
  .er-app .er-row-actions > *{max-width:100%}

  .er-app input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]),
  .er-app select,
  .er-app textarea{max-width:100%;min-width:0}

  .er-app [style*="grid-template-columns"]{max-width:100%}
}


/* CRM-TO 2.38.4 — desktop tables fit the workspace without horizontal scrolling.
 * Replaces the over-aggressive 2.38.2/2.38.3 min-width rules on normal desktop screens.
 */
@media (min-width: 981px){
  html,body{max-width:none!important;overflow-x:hidden!important}

  body .er-app{
    width:100vw!important;
    max-width:none!important;
    min-width:0!important;
    margin-left:calc(50% - 50vw)!important;
    margin-right:calc(50% - 50vw)!important;
  }
  body .er-app .er-main{
    width:calc(100vw - 260px)!important;
    max-width:none!important;
    min-width:0!important;
    flex:1 1 auto!important;
  }
  body .er-app .er-main-inner{
    max-width:none!important;
    min-width:0!important;
  }

  .er-app .er-layout-table-scroll,
  .er-app .er-table-wrap,
  .er-app .er-wallet-table-wrap,
  .er-app .er-agents-report-table-wrap,
  .er-app .er-mobile-table-shell{
    width:100%!important;
    max-width:100%!important;
    min-width:0!important;
    overflow-x:hidden!important;
    scrollbar-gutter:auto!important;
  }

  .er-app table,
  .er-app table.er-table,
  .er-app table.er-table-records,
  .er-app table.er-table-agents-report,
  .er-app table.er-table-tx,
  .er-app table.er-cash-history-table,
  .er-app table.er-wallet-history-table,
  .er-app table.er-table-services-month{
    display:table!important;
    width:100%!important;
    min-width:0!important;
    max-width:100%!important;
    table-layout:fixed!important;
    border-collapse:collapse!important;
  }

  .er-app table th,
  .er-app table td{
    min-width:0!important;
    max-width:none!important;
    box-sizing:border-box!important;
    padding:5px 5px!important;
    font-size:clamp(8px,.62vw,11px)!important;
    line-height:1.2!important;
    white-space:normal!important;
    word-break:normal!important;
    overflow-wrap:anywhere!important;
    writing-mode:horizontal-tb!important;
    text-orientation:mixed!important;
    overflow:hidden!important;
    text-overflow:ellipsis!important;
    vertical-align:middle!important;
  }
  .er-app table th{
    font-size:clamp(8px,.57vw,10px)!important;
    text-align:center!important;
  }
  .er-app table td.er-num,
  .er-app table th.er-num,
  .er-app table [data-er-money]{white-space:nowrap!important}

  /* Records: compact but readable; action buttons always stay inside the row. */
  .er-app table.er-table-records th,
  .er-app table.er-table-records td{
    padding:4px!important;
    font-size:clamp(8px,.58vw,10px)!important;
  }
  .er-app table.er-table-records td:last-child,
  .er-app table.er-table-records th:last-child{
    width:54px!important;
    min-width:54px!important;
    max-width:54px!important;
    overflow:visible!important;
  }
  .er-app table.er-table-records td:last-child .er-btn,
  .er-app table.er-table-records td:last-child button{
    max-width:100%!important;
    min-width:0!important;
    padding:4px 6px!important;
    font-size:9px!important;
  }

  /* Agent report: all 16 columns fit exactly into the available desktop width. */
  .er-app .er-view[data-er-view="agents_report"] table.er-table-agents-report{
    width:100%!important;
    min-width:0!important;
    max-width:100%!important;
    table-layout:fixed!important;
  }
  .er-app .er-view[data-er-view="agents_report"] table.er-table-agents-report th,
  .er-app .er-view[data-er-view="agents_report"] table.er-table-agents-report td{
    width:auto!important;
    min-width:0!important;
    max-width:none!important;
    padding:4px 4px!important;
    font-size:clamp(7.5px,.53vw,9.5px)!important;
    line-height:1.15!important;
  }

  .er-table-agents-report .er-ar-col--agent{width:6%!important}
  .er-table-agents-report .er-ar-col--phone{width:6%!important}
  .er-table-agents-report .er-ar-col--period{width:5.5%!important}
  .er-table-agents-report .er-ar-col--manager{width:6.5%!important}
  .er-table-agents-report .er-ar-col--records{width:3.5%!important}
  .er-table-agents-report .er-ar-col--cash{width:4.5%!important}
  .er-table-agents-report .er-ar-col--cashless{width:4.5%!important}
  .er-table-agents-report .er-ar-col--services{width:6%!important}
  .er-table-agents-report .er-ar-col--paid{width:5%!important}
  .er-table-agents-report .er-ar-col--period-debt{width:5.5%!important}
  .er-table-agents-report .er-ar-col--old-debt{width:6%!important}
  .er-table-agents-report .er-ar-col--total-debt{width:6%!important}
  .er-table-agents-report .er-ar-col--last-payment{width:5.5%!important}
  .er-table-agents-report .er-ar-col--categories{width:7%!important}
  .er-table-agents-report .er-ar-col--branches{width:8%!important}
  .er-table-agents-report .er-ar-col--actions{width:14.5%!important}

  .er-app .er-view[data-er-view="agents_report"] .er-agent-report-pay-th,
  .er-app .er-view[data-er-view="agents_report"] .er-agent-report-pay-cell{
    width:auto!important;
    min-width:0!important;
    max-width:none!important;
    overflow:hidden!important;
    padding:4px!important;
  }
  .er-app .er-view[data-er-view="agents_report"] .er-agent-report-pay{
    display:flex!important;
    flex-direction:column!important;
    align-items:stretch!important;
    gap:4px!important;
    width:100%!important;
    min-width:0!important;
    max-width:100%!important;
  }
  .er-app .er-view[data-er-view="agents_report"] .er-agent-report-pay__row{
    display:grid!important;
    grid-template-columns:minmax(0,1fr) minmax(58px,42%)!important;
    gap:4px!important;
    width:100%!important;
    min-width:0!important;
  }
  .er-app .er-view[data-er-view="agents_report"] .er-agent-report-pay__input{
    width:100%!important;
    min-width:0!important;
    max-width:100%!important;
    height:25px!important;
    padding:3px 5px!important;
    font-size:8px!important;
  }
  .er-app .er-view[data-er-view="agents_report"] .er-agent-report-pay .er-btn-mini,
  .er-app .er-view[data-er-view="agents_report"] .er-agent-report-pay__full,
  .er-app .er-view[data-er-view="agents_report"] .er-agent-report-pay__empty{
    width:100%!important;
    min-width:0!important;
    max-width:100%!important;
    height:25px!important;
    min-height:25px!important;
    padding:3px 4px!important;
    font-size:clamp(7px,.48vw,9px)!important;
    line-height:1!important;
    white-space:nowrap!important;
    overflow:hidden!important;
    text-overflow:clip!important;
    display:flex!important;
    align-items:center!important;
    justify-content:center!important;
  }

  /* Remove sticky desktop columns inherited from tablet/mobile table styles. */
  .er-app table.er-table-agents-report th,
  .er-app table.er-table-agents-report td,
  .er-app table.er-table-records th,
  .er-app table.er-table-records td{
    position:static!important;
    left:auto!important;
    right:auto!important;
    box-shadow:none!important;
  }
}
