/* NovaCore 19.0.0 · Fase 54 · Visual Enterprise 2.0
   Capa final y no destructiva para uniformidad, CRM compacto, formularios y responsive. */

:root {
  --nc-card-radius: 18px;
  --nc-control-radius: 11px;
  --nc-soft-border: #e3e8f1;
  --nc-surface-soft: #f8faff;
  --nc-surface-subtle: #fbfcff;
  --nc-shadow-card: 0 10px 30px rgba(15, 23, 42, .055);
  --nc-shadow-float: 0 20px 55px rgba(15, 23, 42, .14);
}

/* Guardas globales de layout */
html, body { max-width: 100%; overflow-x: clip; }
.main-content { min-width: 0; }
.main-content > * { min-width: 0; }
.main-content :is(.panel,.panel-card,.content-grid,.form-grid,.definition-grid,.stat-grid) { min-width: 0; }
.main-content img, .main-content video, .main-content canvas, .main-content svg { max-width: 100%; }
.main-content pre, .main-content code { overflow-wrap: anywhere; }

/* Componentes visuales coherentes */
.panel,
.panel-card,
.stat-card {
  border-color: var(--nc-soft-border);
  box-shadow: var(--nc-shadow-card);
}

.page-hero {
  min-height: 142px;
  padding: clamp(1.15rem, 2vw, 1.55rem);
}
.page-hero.compact { min-height: 118px; }
.page-hero-copy { align-items: flex-start; }
.page-hero h1 { text-wrap: balance; }
.page-hero p { max-width: 72ch; text-wrap: pretty; }
.page-actions { justify-content: flex-end; }

/* Compatibilidad visual entre generaciones de botones */
.button.primary,
.button.button-primary { background: linear-gradient(135deg, var(--primary), #4641f6); color: #fff; border-color: transparent; box-shadow: 0 8px 19px rgba(53,48,242,.19); }
.button.secondary,
.button.button-secondary { background: var(--primary-soft); border-color: #dcdfff; color: var(--primary-dark); }
.button.ghost,
.button.button-ghost { background: transparent; border-color: transparent; color: #475467; box-shadow: none; }
.button.outline,
.button.button-outline { background: #fff; border-color: var(--border-strong); color: #344054; }
.button:focus-visible,
.icon-button:focus-visible { outline: 3px solid rgba(79, 70, 229, .22); outline-offset: 2px; }

/* Formularios: ritmo, centrado y controles modernos */
.main-content form:not(.inline-form):not(.crm-inline-form):not(.crm-inline-process-form):not(.crm-loss-reason-list form):not(.profile-popover form):not(.sidebar form) {
  min-width: 0;
}
.form-grid,
.form-grid.two,
.form-grid.three {
  align-items: start;
}
.form-grid > *,
.field,
.field > div { min-width: 0; }
.field input:not([type="checkbox"]):not([type="radio"]),
.field select,
.field textarea,
.form-control {
  width: 100%;
  max-width: 100%;
}
.field textarea,
textarea.form-control { resize: vertical; min-height: 108px; }
.form-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: .6rem;
}
.form-actions .button { min-width: 112px; }

/* Tablas: ningún ancho fijo debe romper el viewport; el scroll vive en el contenedor. */
.table-wrap,
.visual-table-wrap {
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  overscroll-behavior-inline: contain;
  scrollbar-width: thin;
  border-radius: inherit;
}
.visual-table-wrap > table { margin: 0; }
.table-panel { min-width: 0; }
.data-table td,
.data-table th { overflow-wrap: anywhere; }

/* CRM · navegación compacta */
.crm-enterprise-page { display: grid; gap: 1rem; }
.crm-enterprise-page > * { min-width: 0; margin: 0; }
.crm-enterprise-hero { margin-bottom: 0; }

.crm-command-nav {
  position: relative;
  z-index: 8;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .8rem;
  min-width: 0;
  padding: .42rem;
  border: 1px solid var(--nc-soft-border);
  border-radius: 15px;
  background: rgba(255,255,255,.96);
  box-shadow: 0 8px 24px rgba(15,23,42,.045);
}
.crm-command-primary {
  display: flex;
  align-items: center;
  gap: .18rem;
  min-width: 0;
}
.crm-command-primary > a,
.crm-nav-more > summary {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  padding: .54rem .72rem;
  border-radius: 10px;
  color: #667085;
  font-size: .69rem;
  font-weight: 820;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
  list-style: none;
  transition: background .16s ease, color .16s ease, box-shadow .16s ease;
}
.crm-nav-more > summary::-webkit-details-marker { display: none; }
.crm-command-primary > a:hover,
.crm-nav-more > summary:hover { background: #f5f6ff; color: #403bd4; }
.crm-command-primary > a.active,
.crm-nav-more.active > summary,
.crm-nav-more[open] > summary {
  background: #171a2f;
  color: #fff;
  box-shadow: 0 6px 16px rgba(23,26,47,.16);
}
.crm-nav-more { position: relative; }
.crm-nav-more[open] { z-index: 20; }
.crm-nav-menu {
  position: absolute;
  top: calc(100% + .55rem);
  left: 0;
  width: min(680px, calc(100vw - 2rem));
  display: grid;
  grid-template-columns: repeat(3, minmax(0,1fr));
  gap: .6rem;
  padding: .72rem;
  border: 1px solid #dfe5ef;
  border-radius: 16px;
  background: #fff;
  box-shadow: var(--nc-shadow-float);
}
.crm-nav-menu section {
  display: grid;
  align-content: start;
  gap: .22rem;
  padding: .35rem;
  border-radius: 12px;
  background: #fbfcff;
}
.crm-nav-menu section > small {
  padding: .3rem .42rem .38rem;
  color: #98a2b3;
  font-size: .55rem;
  font-weight: 900;
  letter-spacing: .09em;
  text-transform: uppercase;
}
.crm-nav-menu a {
  padding: .55rem .6rem;
  border-radius: 9px;
  color: #344054;
  font-size: .67rem;
  font-weight: 760;
  text-decoration: none;
}
.crm-nav-menu a:hover,
.crm-nav-menu a.active { background: #eef0ff; color: #403bd4; }
.crm-command-status {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  flex: 0 0 auto;
  padding: .43rem .62rem;
  border-radius: 999px;
  background: #f2f4f7;
  color: #667085;
  font-size: .6rem;
  font-weight: 850;
  white-space: nowrap;
}
.crm-command-status i { width: 7px; height: 7px; border-radius: 50%; background: #98a2b3; }
.crm-command-status.is-active { background: #eaf8ef; color: #15704d; }
.crm-command-status.is-active i { background: #16a36a; box-shadow: 0 0 0 4px rgba(22,163,106,.11); }
.crm-command-status.is-paused { background: #fff7e8; color: #8d5b00; }

/* CRM · resumen compacto */
.crm-runtime-banner-compact {
  min-height: auto;
  margin: 0;
  padding: .9rem 1rem;
  border-radius: 15px;
}
.crm-runtime-banner-compact h2 { margin: .12rem 0 .22rem; font-size: .92rem; }
.crm-runtime-banner-compact p { max-width: 78ch; font-size: .69rem; }
.crm-runtime-banner-compact .eyebrow { margin-bottom: .18rem; font-size: .54rem; }
.crm-runtime-actions { flex-wrap: wrap; justify-content: flex-end; }

.crm-stat-grid-primary {
  grid-template-columns: repeat(4, minmax(0,1fr));
  gap: .75rem;
  margin: 0;
}
.crm-stat-grid-primary .stat-card { min-height: 98px; }
.crm-stat-grid-primary .stat-card strong { font-size: 1.35rem; }

.crm-summary-strip {
  display: grid;
  grid-template-columns: repeat(4,minmax(0,1fr));
  gap: .65rem;
}
.crm-summary-strip article {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: .62rem;
  padding: .72rem .8rem;
  border: 1px solid var(--nc-soft-border);
  border-radius: 13px;
  background: #fbfcff;
}
.crm-summary-strip article > span {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  flex: 0 0 32px;
  border-radius: 10px;
  background: #eef0ff;
  color: #514bd9;
  font-weight: 900;
}
.crm-summary-strip article div { min-width: 0; display: grid; gap: .08rem; }
.crm-summary-strip small { color: #7d8798; font-size: .55rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.crm-summary-strip strong { color: #182033; font-size: .9rem; }

.crm-command-layout {
  display: grid;
  grid-template-columns: minmax(0,1.65fr) minmax(280px,.7fr);
  gap: 1rem;
  align-items: start;
}
.crm-focus-panel,
.crm-today-panel,
.crm-toolbox-panel { padding: 1rem; }
.crm-focus-panel .panel-heading,
.crm-today-panel .panel-heading,
.crm-toolbox-panel .panel-heading {
  margin: -1rem -1rem .65rem;
  padding: .9rem 1rem;
}
.crm-focus-actions { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: .55rem; }
.crm-focus-actions > a {
  min-width: 0;
  display: grid;
  grid-template-columns: 38px minmax(0,1fr) auto;
  align-items: center;
  gap: .65rem;
  padding: .72rem;
  border: 1px solid #e4e8f0;
  border-radius: 13px;
  background: #fff;
  color: inherit;
  text-decoration: none;
  transition: border-color .16s ease, background .16s ease, transform .16s ease;
}
.crm-focus-actions > a:hover { border-color: #c9ccff; background: #fbfbff; transform: translateY(-1px); }
.crm-focus-actions > a > span {
  width: 38px; height: 38px; display: grid; place-items: center;
  border-radius: 11px; background: #eef0ff; color: #514bd9; font-weight: 900;
}
.crm-focus-actions > a div { min-width: 0; display: grid; gap: .12rem; }
.crm-focus-actions strong { font-size: .7rem; }
.crm-focus-actions small { color: #7c8798; font-size: .57rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.crm-focus-actions b { color: #777ce9; font-size: .75rem; }

.crm-health-list { display: grid; }
.crm-health-list > div {
  display: grid;
  grid-template-columns: 10px minmax(0,1fr) auto;
  align-items: center;
  gap: .58rem;
  padding: .7rem .12rem;
  border-bottom: 1px solid #edf0f4;
}
.crm-health-list > div:last-child { border-bottom: 0; }
.crm-health-list div > div { min-width: 0; display: grid; gap: .08rem; }
.crm-health-list strong { font-size: .66rem; }
.crm-health-list small { color: #8a94a5; font-size: .54rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.crm-health-list b { color: #596579; font-size: .56rem; white-space: nowrap; }
.crm-health-dot { width: 8px; height: 8px; border-radius: 50%; background: #667eea; box-shadow: 0 0 0 4px rgba(102,126,234,.10); }
.crm-health-dot.success { background: #16a36a; box-shadow: 0 0 0 4px rgba(22,163,106,.10); }

.crm-toolbox-grid { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: .7rem; }
.crm-toolbox-group { display: grid; align-content: start; gap: .28rem; padding: .7rem; border-radius: 13px; background: #f8faff; }
.crm-toolbox-group > small { padding: .15rem .2rem .35rem; color: #8c96a8; font-size: .54rem; font-weight: 900; letter-spacing: .08em; text-transform: uppercase; }
.crm-toolbox-group > a {
  min-width: 0;
  display: grid;
  grid-template-columns: 32px minmax(0,1fr);
  align-items: center;
  gap: .55rem;
  padding: .55rem;
  border-radius: 10px;
  color: inherit;
  text-decoration: none;
}
.crm-toolbox-group > a:hover { background: #fff; box-shadow: 0 6px 18px rgba(15,23,42,.05); }
.crm-toolbox-group > a > span { width: 32px; height: 32px; display: grid; place-items: center; border-radius: 9px; background: #fff; color: #5652d8; font-weight: 900; }
.crm-toolbox-group > a div { min-width: 0; display: grid; gap: .08rem; }
.crm-toolbox-group strong { font-size: .64rem; }
.crm-toolbox-group em { color: #8a94a5; font-size: .53rem; font-style: normal; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.crm-disclosure-panel { padding: 0; overflow: clip; }
.crm-disclosure-panel > summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: .9rem 1rem;
  cursor: pointer;
  list-style: none;
  background: #fbfcff;
}
.crm-disclosure-panel > summary::-webkit-details-marker { display: none; }
.crm-disclosure-panel > summary span { display: grid; gap: .08rem; }
.crm-disclosure-panel > summary small { color: #8a94a5; font-size: .53rem; font-weight: 800; text-transform: uppercase; letter-spacing: .06em; }
.crm-disclosure-panel > summary strong { font-size: .7rem; }
.crm-disclosure-panel > summary b { color: #5a56d7; font-size: .58rem; }
.crm-disclosure-panel[open] > summary { border-bottom: 1px solid #e8ecf2; }
.crm-disclosure-content { padding: 1rem; }
.crm-contract-compact { grid-template-columns: repeat(4,minmax(0,1fr)); margin-top: .9rem; }
.crm-history-disclosure .roadmap-list.horizontal { overflow-x: auto; padding-bottom: .4rem; }

/* CRM formularios y listados: ancho legible y sin cortes */
body.module-crm .crm-entity-form,
body.module-crm .crm-document-form,
body.module-crm .crm-automation-form,
body.module-crm .crm-import-form {
  width: min(100%, 1120px);
  margin-inline: auto;
}
body.module-crm .crm-form-section { border-radius: 13px; }
body.module-crm .crm-form-section-head { align-items: flex-start; }
body.module-crm .crm-filter-panel,
body.module-crm .toolbar { min-width: 0; }
body.module-crm .crm-filter-grid { grid-template-columns: minmax(220px,1.4fr) repeat(3,minmax(130px,.75fr)); }
body.module-crm .crm-filter-actions { grid-column: 1/-1; }
body.module-crm .crm-document-filters { grid-template-columns: minmax(220px,1.2fr) repeat(2,minmax(150px,.65fr)) auto; }

/* Responsividad global y CRM */
@media (max-width: 1180px) {
  .crm-stat-grid-primary { grid-template-columns: repeat(2,minmax(0,1fr)); }
  .crm-summary-strip { grid-template-columns: repeat(2,minmax(0,1fr)); }
  .crm-command-layout { grid-template-columns: 1fr; }
  .crm-toolbox-grid { grid-template-columns: repeat(2,minmax(0,1fr)); }
  body.module-crm .crm-filter-grid { grid-template-columns: repeat(2,minmax(0,1fr)); }
}

@media (max-width: 900px) {
  .page-hero { align-items: flex-start; flex-direction: column; }
  .page-actions { width: 100%; justify-content: flex-start; }
  .crm-command-nav { align-items: stretch; flex-direction: column; }
  .crm-command-primary { overflow-x: auto; padding-bottom: .1rem; scrollbar-width: thin; }
  .crm-command-status { align-self: flex-start; }
  .crm-nav-more { position: static; }
  .crm-nav-menu { left: .42rem; right: .42rem; width: auto; }
  .crm-toolbox-grid { grid-template-columns: 1fr; }
  .crm-contract-compact { grid-template-columns: repeat(2,minmax(0,1fr)); }
}

@media (max-width: 720px) {
  .page-hero { min-height: auto; padding: 1rem; border-radius: 17px; }
  .page-hero-copy { gap: .7rem; }
  .hero-symbol { width: 46px; height: 46px; flex-basis: 46px; border-radius: 13px; }
  .page-actions .button { flex: 1 1 auto; }
  .form-grid,
  .form-grid.two,
  .form-grid.three { grid-template-columns: 1fr !important; }
  .form-actions { align-items: stretch; flex-direction: column-reverse; }
  .form-actions .button { width: 100%; }
  .crm-stat-grid-primary,
  .crm-summary-strip,
  .crm-focus-actions { grid-template-columns: 1fr; }
  .crm-nav-menu { grid-template-columns: 1fr; max-height: 68vh; overflow-y: auto; }
  .crm-runtime-banner-compact { align-items: flex-start; flex-direction: column; }
  .crm-runtime-actions { justify-content: flex-start; }
  .crm-contract-compact { grid-template-columns: 1fr; }
  body.module-crm .crm-filter-grid,
  body.module-crm .crm-document-filters { grid-template-columns: 1fr; }
  body.module-crm .crm-filter-actions { grid-column: auto; align-items: stretch; flex-direction: column; }
  body.module-crm .crm-filter-actions .button { width: 100%; }
}

@media (max-width: 420px) {
  .main-content { padding-inline: .72rem; }
  .crm-command-nav { border-radius: 13px; }
  .crm-command-primary > a,
  .crm-nav-more > summary { padding-inline: .62rem; }
  .crm-summary-strip article { padding: .65rem; }
  .panel, .panel-card { border-radius: 15px; }
}

@media (prefers-reduced-motion: reduce) {
  .crm-command-primary > a,
  .crm-focus-actions > a,
  .crm-toolbox-group > a { transition: none; }
}
