/* =====================================================================
   Código Dodo · capa de aplicación sobre el Design System oficial v1.0
   ---------------------------------------------------------------------
   El marco replica index.asp + menu_izquierdo_bravoerp.asp del sistema en
   producción: menú lateral de 70 px (#343a40) que expande a 250 px, barra
   superior #f8f9fa con borde #dee2e6 y círculo de usuario #007bff.
   Los componentes de contenido son los del DS (cd-page, cd-panel, cd-kpi,
   cd-table, cd-status, cd-btn): aquí no se redefinen ni se encogen.
   ===================================================================== */

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--cd-bg);
  color: var(--cd-ink);
  font-family: var(--cd-font);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--cd-primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1,h2,h3,h4 { margin: 0; }
code, .mono { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 12px; }

/* ------------------------------------------------------------ contexto */
.ctx-central { --ctx: #8438c1; --ctx-soft: #f4e7fa; }
.ctx-portal  { --ctx: #078bb8; --ctx-soft: #e3f6fa; }
.ctx-tenant  { --ctx: #2166ff; --ctx-soft: #eaf1ff; }

/* =====================================================================
   MARCO
   ===================================================================== */
.cdd-shell { display: flex; min-height: 100vh; align-items: stretch; }

.cdd-side {
  width: 70px; flex: 0 0 70px;
  background: #343a40;
  border-right: 1px solid #dee2e6;
  transition: width .4s ease, flex-basis .4s ease, transform .3s ease;
  overflow: hidden; overflow-y: auto;
  position: sticky; top: 0; height: 100vh;
}
/* expande al pasar el mouse, salvo que esté fijado (data-fixed), como el original */
.cdd-side:hover:not([data-fixed="true"]),
.cdd-side[data-fixed="true"] { width: 250px; flex-basis: 250px; }

.cdd-side-logo {
  display: flex; align-items: center; gap: 10px;
  height: 48px; padding: 0 10px;
  background: #343a40; border-bottom: 1px solid #495057;
  text-decoration: none; white-space: nowrap;
}
.cdd-side-logo img { width: 24px; height: auto; flex: 0 0 24px; }
.cdd-side-brand { color: #fff; font-size: 13px; font-weight: 600; opacity: 0; transition: opacity .2s; }
.cdd-side:hover .cdd-side-brand, .cdd-side[data-fixed="true"] .cdd-side-brand { opacity: 1; }

.cdd-side-close { display: none; }

.cdd-side-item {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 16px; border-bottom: 1px solid #495057;
  color: #fff; font-size: 13px; text-decoration: none; white-space: nowrap;
  transition: background-color .3s;
}
.cdd-side-item i { min-width: 20px; text-align: center; font-size: 14px; }
.cdd-side-item:hover { background: #495057; color: #fff; text-decoration: none; }
/* el original no cambia el fondo del activo: sólo el icono pasa a azul */
.cdd-side-item.on { background: transparent; }
.cdd-side-item.on i { color: #0d6efd; }
.cdd-side-item.on:hover { background: #495057; }
.cdd-side-t { opacity: 0; transition: opacity .2s; }
.cdd-side:hover .cdd-side-t, .cdd-side[data-fixed="true"] .cdd-side-t { opacity: 1; }

/* ------------------------------------------------------------ barra superior */
.cdd-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.cdd-top {
  height: 48px; flex: 0 0 48px;
  background: #f8f9fa; border-bottom: 1px solid #dee2e6;
  display: flex; align-items: center; justify-content: space-between;
  padding: 6px 12px; position: sticky; top: 0; z-index: 30; gap: 12px;
}
.cdd-top-left, .cdd-top-right { display: flex; align-items: center; gap: 4px; min-width: 0; }

/* botones tipo btn btn-sm btn-outline-secondary de Bootstrap, como el original */
.cdd-top-btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 31px; height: 31px; padding: .25rem .5rem;
  border-radius: .2rem; border: 1px solid #6c757d; background: transparent;
  color: #6c757d; cursor: pointer; font-size: .875rem; line-height: 1.5;
}
.cdd-top-btn:hover { background: #6c757d; color: #fff; }
.cdd-top-btn.danger { color: #dc3545; border-color: #dc3545; }
.cdd-top-btn.danger:hover { background: #dc3545; color: #fff; }
.cdd-top-btn.disabled { opacity: .5; cursor: not-allowed; }
.cdd-top-btn.plain { border: 0; background: transparent; padding: 0; min-width: 32px; height: 32px; }
.cdd-top-btn.plain:hover { background: transparent; }

.cdd-top-link {
  display: inline-flex; align-items: center; gap: 6px;
  padding: .25rem .5rem; border-radius: .2rem; font-size: .875rem;
  color: #495057; text-decoration: none; white-space: nowrap;
  border: 1px solid transparent;
}
.cdd-top-link:hover { background: #e9ecef; color: #212529; text-decoration: none; }
.cdd-top-link i { font-size: 12px; opacity: .85; }

.cdd-avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: #007bff; color: #fff; font-weight: 700; font-size: 13px;
  display: inline-flex; align-items: center; justify-content: center; flex: none;
}
.cdd-avatar:hover { background: #0056b3; }

.cdd-content { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.cdd-content > .cd-page { flex: 1; }

/* modal de datos de usuario (equivalente al SweetAlert del original) */
.modal-cdd {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(12, 26, 43, .45);
  display: flex; align-items: center; justify-content: center;
}
.modal-cdd[hidden] { display: none; }
.modal-cdd-box {
  background: #fff; border-radius: 12px; box-shadow: 0 20px 60px rgba(16,42,80,.25);
  min-width: 320px; max-width: 92vw; padding: 18px 20px;
}
.modal-cdd-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 12px; }
.modal-cdd-head h3 { font-size: 15px; font-weight: 700; }
.cdd-kv-min { display: grid; grid-template-columns: 90px 1fr; gap: 8px 14px; font-size: 13px; margin: 0; }
.cdd-kv-min dt { color: #6c757d; margin: 0; }
.cdd-kv-min dd { margin: 0; word-break: break-word; }

@media (max-width: 767.98px) {
  .cdd-side {
    position: fixed; left: 0; top: 0; z-index: 9999; height: 100vh;
    width: 250px; flex-basis: 250px;
    transform: translateX(-100%);
  }
  .cdd-side.show-mobile { transform: translateX(0); }
  .cdd-side .cdd-side-brand, .cdd-side .cdd-side-t { opacity: 1; }
  .cdd-side-close {
    display: block; width: 100%; height: 48px; border: 0;
    background: #343a40; color: #fff; font-size: 15px; cursor: pointer;
    border-bottom: 1px solid #495057; text-align: right; padding: 0 18px;
  }
  .cdd-top-link { display: none; }
  .cdd-top-btn.danger[disabled] { display: none; }
}

/* =====================================================================
   UTILIDADES (siempre con tokens del DS)
   ===================================================================== */
.cd-grid-2 { display: grid; grid-template-columns: 2fr 1fr; gap: 20px; }
.cd-grid-2e { display: grid; grid-template-columns: 1fr 2fr; gap: 20px; }
.cd-grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 20px; }
@media (max-width: 1100px) { .cd-grid-2, .cd-grid-2e, .cd-grid-3 { grid-template-columns: 1fr; } }

/* 10 indicadores: dos filas de 5, nunca 6+4 cojo */
.cd-kpi-grid.cd-kpi-5 { grid-template-columns: repeat(5, minmax(0,1fr)); }
@media (max-width: 1350px) { .cd-kpi-grid.cd-kpi-5 { grid-template-columns: repeat(3, minmax(0,1fr)); } }
@media (max-width: 700px)  { .cd-kpi-grid.cd-kpi-5 { grid-template-columns: repeat(2, minmax(0,1fr)); } }
@media (max-width: 440px)  { .cd-kpi-grid.cd-kpi-5 { grid-template-columns: 1fr; } }

.cd-mt { margin-top: 20px; }
.cd-mb { margin-bottom: 20px; }
.cd-right { text-align: right; }
.cd-nowrap { white-space: nowrap; }
.cd-num { font-variant-numeric: tabular-nums; }
.cd-zero { color: #b3c1d4; }
.cd-bad { color: var(--cd-danger); font-weight: 600; }
.cd-warn { color: #a16b00; font-weight: 600; }

/* cabecera de panel (no existe en el DS; una sola definición, sin márgenes negativos) */
.cd-panel-title { font-size: 14px; font-weight: 600; margin: 0; }
.cd-panel-head {
  display: flex; align-items: center; gap: 12px;
  padding-bottom: 12px; margin-bottom: 14px;
  border-bottom: 1px solid var(--cd-border);
}
.cd-panel-head .cd-panel-action { margin-left: auto; font-size: 13px; }

.cd-kv { display: grid; grid-template-columns: 190px 1fr; gap: 10px 16px; font-size: 14px; margin: 0; }
.cd-kv dt { color: var(--cd-muted); font-size: 13px; margin: 0; }
.cd-kv dd { margin: 0; }

.cd-empty { text-align: center; padding: 44px 20px; color: var(--cd-muted); }
.cd-empty .cd-empty-icon { font-size: 26px; opacity: .3; margin-bottom: 10px; }

/* paginación numerada, 36 px, activa en azul (DS §11) */
.cd-pager { display: flex; gap: 6px; align-items: center; justify-content: flex-end; padding: 14px 2px 2px; font-size: 13px; }
.cd-pager a, .cd-pager span {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 36px; height: 36px; padding: 0 10px; border-radius: 8px;
  border: 1px solid var(--cd-border); background: #fff; color: var(--cd-ink);
}
.cd-pager a:hover { background: #eef4ff; text-decoration: none; }
.cd-pager .cur { background: var(--cd-primary); color: #fff; border-color: var(--cd-primary); font-weight: 600; }
.cd-pager .info { border: 0; background: transparent; color: var(--cd-muted); }
.cd-pager .off { opacity: .45; pointer-events: none; }

.cd-note {
  display: flex; gap: 10px; align-items: flex-start;
  border-left: 3px solid var(--cd-warning); background: #fffaeb;
  padding: 12px 16px; border-radius: 10px; font-size: 13px; color: #6b4a00;
  margin-bottom: 20px;
}

.cd-legend { display: flex; flex-wrap: wrap; gap: 8px 18px; margin-top: 12px; }
.cd-legend .li { display: flex; align-items: center; gap: 7px; font-size: 12.5px; color: var(--cd-muted); }
.cd-legend b { color: var(--cd-ink); font-variant-numeric: tabular-nums; }

.cd-donut { display: block; flex: none; }
.cd-spark { display: block; width: 100%; }
.cd-donut-wrap { display: flex; flex-direction: column; align-items: center; }
.cd-donut-n { font: 700 22px var(--cd-font); fill: var(--cd-ink); font-variant-numeric: tabular-nums; }
.cd-donut-l { font: 600 10px var(--cd-font); fill: var(--cd-muted); letter-spacing: .08em; text-transform: uppercase; }

svg.sb { display: block; width: 100%; }
svg.sb .sb-label { font: 400 12.5px var(--cd-font); fill: var(--cd-ink); }
svg.sb .sb-track { fill: #eaf0f8; }
svg.sb .sb-fill  { fill: var(--cd-primary); }
svg.sb .sb-val   { font: 600 12.5px var(--cd-font); fill: var(--cd-muted); }

.cd-tag {
  display: inline-block; padding: 3px 8px; border-radius: 7px;
  background: #eef3fa; color: #4a5f7d; font-size: 11.5px; font-weight: 600;
}
.cd-tag-mono { font-family: ui-monospace, Consolas, monospace; font-size: 11.5px; }

/* controles dentro de barras de filtro: en línea, no a ancho completo */
.cd-ui .cd-toolbar .cd-input, .cd-ui .cd-toolbar .cd-select { width: auto; }
.cd-ui .cd-toolbar .cd-input.cd-search { min-width: 260px; max-width: 340px; }
.cd-ui .cd-toolbar .cd-select { min-width: 170px; max-width: 270px; }
@media (max-width: 760px) {
  .cd-ui .cd-toolbar { justify-content: stretch; }
  .cd-ui .cd-toolbar .cd-input, .cd-ui .cd-toolbar .cd-select { width: 100%; max-width: none; min-width: 0; }
}

/* gráficos circulares en fila */
.cd-charts-2 { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 20px; }
@media (max-width: 1100px) { .cd-charts-2 { grid-template-columns: 1fr; } }
.cd-chart-body { display: flex; align-items: flex-start; gap: 20px; }
.cd-chart-body .cd-legend { flex-direction: column; align-items: flex-start; gap: 5px; margin: 0; max-height: 230px; overflow-y: auto; }
@media (max-width: 620px) { .cd-chart-body { flex-direction: column; align-items: center; } }

/* "Columnas a mostrar" */
.cd-cols { margin-top: 12px; border-top: 1px solid var(--cd-border); padding-top: 12px; }
.cd-cols summary {
  cursor: pointer; font-size: 13px; font-weight: 600; color: #4a5f7d;
  list-style: none; display: inline-flex; align-items: center; gap: 7px;
}
.cd-cols summary::-webkit-details-marker { display: none; }
.cd-cols summary:hover { color: var(--cd-primary); }
.cd-cols-grid { display: flex; flex-wrap: wrap; gap: 8px 18px; margin-top: 12px; }
.cd-cols-item { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--cd-ink); font-weight: 500; cursor: pointer; }
.cd-cols-item input { accent-color: var(--cd-primary); }

/* ------------------------------------------------------------ acceso */
.auth { min-height: 100vh; display: grid; grid-template-columns: 1.05fr .95fr; }
@media (max-width: 900px) { .auth { grid-template-columns: 1fr; } .auth .aside { display: none; } }
.auth .aside {
  position: relative; overflow: hidden; padding: 44px;
  background:
    radial-gradient(900px 480px at 10% 6%, rgba(33,102,255,.22), transparent 62%),
    radial-gradient(760px 520px at 92% 94%, rgba(245,127,33,.16), transparent 60%),
    linear-gradient(158deg, #102a50 0%, #123a6b 58%, #0b1f3a 100%);
  color: #d7e3f2; display: flex; flex-direction: column;
}
.auth .aside .logo-lg { width: 66px; height: auto; display: block; }
.auth .aside h1 { color: #fff; font-size: 33px; line-height: 1.16; letter-spacing: -.025em; font-weight: 700; margin-top: auto; }
.auth .aside p { color: #a9bfd8; max-width: 440px; margin-top: 14px; font-size: 14px; }
.auth .aside .rule { width: 48px; height: 3px; background: #f57f21; border-radius: 2px; margin: 24px 0; }
.auth .aside .meta { margin-top: auto; font-size: 12px; color: #7f98b5; }
.auth .mini { display: flex; gap: 30px; margin-top: 10px; }
.auth .mini .v { color: #fff; font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; }
.auth .mini .l { color: #8ba3c0; font-size: 11px; text-transform: uppercase; letter-spacing: .07em; font-weight: 600; }

.auth .panel { background: var(--cd-surface); display: flex; align-items: center; justify-content: center; padding: 40px 28px; }
.auth .panel-inner { width: 100%; max-width: 404px; }
.auth .panel h2 { font-size: 22px; font-weight: 700; }
.auth .panel .sub { color: var(--cd-muted); font-size: 13.5px; margin: 6px 0 24px; }
.auth .ctx-choice { display: flex; gap: 8px; margin-bottom: 20px; }
.auth .ctx-choice a {
  flex: 1; text-align: center; padding: 9px 0; font-size: 13px; font-weight: 600;
  border: 1px solid var(--cd-border); border-radius: var(--cd-radius-md);
  color: var(--cd-muted); background: #f7f9fc;
}
.auth .ctx-choice a.on { background: var(--cd-primary); border-color: var(--cd-primary); color: #fff; }
.auth .ctx-choice a:hover { text-decoration: none; }
.auth .btn-full { width: 100%; }
.auth .link-note { margin-top: 8px; font-size: 12px; color: var(--cd-muted); line-height: 1.6; }
.auth .quick { margin-top: 22px; padding-top: 18px; border-top: 1px solid var(--cd-border); }
.auth .quick-title { font-size: 11.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .07em; color: var(--cd-muted); margin-bottom: 10px; }

.demo-creds { margin-top: 18px; padding: 14px 16px; background: #f7f9fc; border: 1px dashed var(--cd-border); border-radius: var(--cd-radius-md); }
.demo-creds .demo-title { font-size: 11.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .07em; color: var(--cd-muted); margin-bottom: 10px; }
.demo-item { padding: 7px 0; border-top: 1px solid var(--cd-border); }
.demo-item:first-of-type { border-top: 0; }
.demo-item .demo-rol { font-size: 11.5px; color: var(--cd-muted); font-weight: 600; }
.demo-item .demo-line { display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; font-family: ui-monospace, Consolas, monospace; font-size: 12.5px; margin-top: 2px; }
.demo-item .demo-mail { color: var(--cd-ink); word-break: break-all; }
.demo-item .demo-pass { color: var(--cd-primary); font-weight: 700; }
.demo-creds .demo-note { margin-top: 12px; font-size: 11px; color: var(--cd-muted); line-height: 1.6; }

.alert { border-radius: var(--cd-radius-md); padding: 11px 14px; font-size: 13px; margin-bottom: 16px; border: 1px solid; }
.alert.bad { background: var(--cd-danger-soft); border-color: #ffc4cc; color: #b02035; }
.alert.ok  { background: var(--cd-success-soft); border-color: #a5e6bd; color: #15803d; }
.alert.info{ background: #eaf3ff; border-color: #c8d9f7; color: #1b4f9c; }

/* =====================================================================
   Acciones sobre documentos y formularios de la ficha de entidad
   ===================================================================== */
.cd-actions { display: flex; gap: 6px; justify-content: flex-end; align-items: center; }
.cd-actions .cd-btn { min-width: 34px; }

/* menú desplegable de acciones por fila (sin JS, con <details>) */
.cd-menu { position: relative; display: inline-block; }
.cd-menu > summary {
  list-style: none; cursor: pointer;
}
.cd-menu > summary::-webkit-details-marker { display: none; }
.cd-menu[open] > summary { background: #edf3fb; }
.cd-menu-box {
  position: absolute; right: 0; top: calc(100% + 4px); z-index: 40;
  width: 268px; background: #fff; border: 1px solid var(--cd-border);
  border-radius: 10px; box-shadow: 0 14px 40px rgba(16,42,80,.18);
  padding: 12px; text-align: left;
}
.cd-menu-form { display: flex; flex-direction: column; gap: 6px; }
.cd-menu-form + .cd-menu-form { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--cd-border); }
.cd-menu-form .cd-input, .cd-menu-form .cd-select { min-height: 34px; padding: 4px 8px; font-size: 13px; }
.cd-menu-form .cd-btn { width: 100%; }

.cd-check { display: inline-flex; align-items: center; gap: 7px; font-size: 13px; color: var(--cd-ink); }
.cd-check input { accent-color: var(--cd-primary); }

/* formulario de carga: rejilla de dos columnas */
.cd-form-grid { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 14px 18px; }
.cd-form-wide { grid-column: 1 / -1; }
.cd-form-foot {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--cd-border);
}
@media (max-width: 900px) { .cd-form-grid { grid-template-columns: 1fr 1fr; } }
@media (max-width: 620px) { .cd-form-grid { grid-template-columns: 1fr; } .cd-form-foot { flex-direction: column; align-items: stretch; } }

/* clases usadas por las plantillas que no estaban definidas */
.cdd-side-nav { display: block; }
.inline-form, .cdd-logout { margin: 0; display: inline-flex; }
.cd-kpi-link { cursor: pointer; }
.cd-kpi-link:hover { filter: brightness(1.04); }
/* alias: el DS no tiene cd-status-red, se usa el rojo de vencido */
.cd-ui .cd-status-red { color: #b02035; background: var(--cd-danger-soft); border-color: #ffc4cc; }

/* accesibilidad: al tabular por el menú colapsado se deben ver los textos */
.cdd-side:focus-within .cdd-side-t,
.cdd-side:focus-within .cdd-side-brand { opacity: 1; }
.cdd-side:focus-within { width: 250px; flex-basis: 250px; }
.cdd-side-item:focus-visible,
.cdd-top-btn:focus-visible,
.cdd-top-link:focus-visible { outline: 2px solid var(--cd-primary); outline-offset: 2px; }


/* =====================================================================
   Constructor de formularios (drag & drop) y matriz de permisos
   ===================================================================== */
.cd-builder { display: grid; grid-template-columns: 320px 1fr; gap: 20px; align-items: start; }
@media (max-width: 1100px) { .cd-builder { grid-template-columns: 1fr; } }

.cd-builder-hint { font-size: 12.5px; color: var(--cd-muted); margin: 0 0 12px; }
.cd-palette { display: flex; flex-direction: column; gap: 6px; }
.cd-palette-item {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px; border: 1px solid var(--cd-border); border-radius: 9px;
  background: #f8fbff; font-size: 13px; cursor: grab;
}
.cd-palette-item:active { cursor: grabbing; }
.cd-palette-item.usada { opacity: .45; background: #f4f6fa; cursor: default; }
.cd-palette-label { flex: 1; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cd-palette-type { font-size: 10.5px; color: var(--cd-muted); text-transform: uppercase; letter-spacing: .05em; }
.cd-palette-add { margin: 0; }
.cd-palette-add .cd-btn { min-width: 28px; padding: 2px 8px; }

.cd-canvas { display: flex; flex-direction: column; gap: 10px; min-height: 120px; }
.cd-canvas.drop-activo { outline: 2px dashed var(--cd-primary); outline-offset: 6px; border-radius: 10px; }

.cd-field-card {
  border: 1px solid var(--cd-border); border-radius: 10px; background: #fff;
  transition: box-shadow .15s, border-color .15s;
}
.cd-field-card.arrastrando { opacity: .45; }
.cd-field-card.drop-target { border-color: var(--cd-primary); box-shadow: 0 0 0 3px #e3edff; }
.cd-field-card-head { display: flex; align-items: center; gap: 8px; padding: 9px 12px; flex-wrap: wrap; }
.cd-drag { color: #9db0c9; cursor: grab; }
.cd-field-card-num { font-size: 11px; color: var(--cd-muted); font-variant-numeric: tabular-nums; }
.cd-field-card-name { font-size: 13.5px; }
.cd-field-card-actions { margin-left: auto; display: flex; gap: 6px; }
.cd-field-card-body {
  display: none; padding: 0 12px 12px; gap: 12px;
  grid-template-columns: repeat(4, minmax(0,1fr));
}
.cd-field-card.abierto .cd-field-card-body { display: grid; }
.cd-field-card.abierto { border-color: #b9cdf0; box-shadow: 0 6px 18px rgba(16,42,80,.07); }
.cd-field-save { display: flex; align-items: flex-end; }
@media (max-width: 900px) { .cd-field-card-body { grid-template-columns: 1fr 1fr; } }
@media (max-width: 560px) { .cd-field-card-body { grid-template-columns: 1fr; } }

/* rejilla de 12 columnas para los campos del formulario dinámico.
   Se usa la misma especificidad que el DS (.cd-ui .cd-form-grid) para ganarle. */
.cd-ui .cd-form-grid { grid-template-columns: repeat(12, minmax(0, 1fr)); }
.cd-span-1{grid-column:span 1}.cd-span-2{grid-column:span 2}.cd-span-3{grid-column:span 3}
.cd-span-4{grid-column:span 4}.cd-span-5{grid-column:span 5}.cd-span-6{grid-column:span 6}
.cd-span-7{grid-column:span 7}.cd-span-8{grid-column:span 8}.cd-span-9{grid-column:span 9}
.cd-span-10{grid-column:span 10}.cd-span-11{grid-column:span 11}.cd-span-12{grid-column:span 12}
@media (max-width: 900px) { .cd-form-grid > [class*="cd-span-"] { grid-column: span 12; } }
.cd-req { color: var(--cd-danger); }

/* matriz de permisos */
.cd-perm-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 20px; align-items: start; }
.cd-perm-list { display: flex; flex-direction: column; gap: 2px; max-height: 460px; overflow-y: auto; padding-right: 4px; }
.cd-perm-item {
  display: flex; gap: 9px; align-items: flex-start;
  padding: 6px 8px; border-radius: 7px; cursor: pointer; font-size: 13px;
}
.cd-perm-item:hover { background: #f4f8ff; }
.cd-perm-item input { margin-top: 3px; accent-color: var(--cd-primary); }
.cd-perm-code { display: block; font-family: ui-monospace, Consolas, monospace; font-size: 11.5px; color: #4a5f7d; }
.cd-perm-desc { display: block; font-size: 12px; color: var(--cd-muted); }

/* =====================================================================
   Diálogo reutilizable (modales)
   Sustituye el patrón de "formulario abajo de la página": el contenido se
   carga desde la misma URL y se inyecta en el <dialog>.
   ===================================================================== */
.cd-dialog {
  border: 0; padding: 0; background: transparent; color: var(--cd-ink);
  max-width: min(1000px, 94vw); max-height: 92vh; width: 100%;
}
.cd-dialog::backdrop { background: rgba(12, 26, 43, .5); backdrop-filter: blur(2px); }
.cd-dialog-box {
  background: #fff; border-radius: 14px; overflow: hidden;
  box-shadow: 0 24px 70px rgba(16, 42, 80, .35);
  display: flex; flex-direction: column; max-height: 92vh;
}
.cd-dialog-head {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 14px 18px; border-bottom: 1px solid var(--cd-border); background: #f8fafd;
}
.cd-dialog-head h2 { font-size: 16px; font-weight: 700; margin: 0; }
.cd-dialog-body { padding: 18px; overflow-y: auto; }
.cd-dialog-body .cd-page { padding: 0; }
.cd-dialog-body .cd-page-header { display: none; }
.cd-dialog-body .cd-form-foot { position: sticky; bottom: -18px; background: #fff; padding-top: 12px; }
.cd-dialog-cargando { padding: 40px; text-align: center; color: var(--cd-muted); }

/* vista previa de la plantilla CSV */
.cd-csv {
  background: #0f1d33; color: #d7e3f2; border-radius: 10px;
  padding: 14px 16px; font-family: ui-monospace, Consolas, monospace;
  font-size: 12px; line-height: 1.6; overflow-x: auto; white-space: pre;
  margin: 0;
}

/* =====================================================================
   Informe imprimible: al imprimir se oculta el marco y queda sólo el
   contenido del informe, en blanco y negro legible.
   ===================================================================== */
.cd-membrete {
  display: none;
  border-bottom: 2px solid var(--cd-ink);
  padding-bottom: 8px; margin-bottom: 16px;
  font-size: 12.5px; color: #33475f;
}
.cd-report-cols { display: grid; grid-template-columns: 1fr 1.4fr; gap: 20px; align-items: start; }
@media (max-width: 1000px) { .cd-report-cols { grid-template-columns: 1fr; } }

@media print {
  @page { size: A4 portrait; margin: 12mm; }
  body { background: #fff; font-size: 10.5px; }
  .cdd-side, .cdd-top, footer.foot, .no-print, .cd-toolbar.no-print { display: none !important; }
  .cdd-shell, .cdd-main, .cdd-content { display: block !important; }
  .cdd-content { padding: 0 !important; }
  .cd-page { padding: 0 !important; }
  .cd-page-header { margin-bottom: 8px !important; }
  .cd-page-title { font-size: 18px !important; }
  .cd-membrete { display: block !important; }
  .cd-panel { border: 1px solid #c9d4e3 !important; box-shadow: none !important; break-inside: avoid; page-break-inside: avoid; }
  .cd-panel-head { border-bottom: 1px solid #c9d4e3 !important; }
  .cd-table-scroll { overflow: visible !important; }
  .cd-table { font-size: 9.5px !important; }
  .cd-table thead th { background: #eef2f8 !important; color: #102a50 !important; }
  .cd-table tbody td { padding: 3px 6px !important; }
  .cd-status { border: 1px solid #9aa8bb !important; color: #102a50 !important; background: #fff !important; }
  .cd-kpi { break-inside: avoid; }
  .cd-report-cols { display: block !important; }
  a { color: inherit !important; text-decoration: none !important; }
}

/* el atributo hidden debe ganar al display del enlace */
.cdd-top-link[hidden] { display: none !important; }


/* buscador de la barra superior */
.cdd-top-search {
  display: inline-flex; align-items: center; gap: 8px;
  background: #fff; border: 1px solid #dee2e6; border-radius: 8px;
  padding: 0 10px; height: 32px; margin-right: 8px; min-width: 210px;
}
.cdd-top-search i { color: #8a94a6; font-size: 12px; }
.cdd-top-search input {
  border: 0; outline: 0; background: transparent; font: inherit;
  font-size: 13px; width: 100%; color: #22303f;
}
.cdd-top-search input::placeholder { color: #98a2b3; }
@media (max-width: 900px) { .cdd-top-search { display: none; } }

/* ---------------------------------------------------------------------
   Panel: tarjetas de trabajo pendiente (una por bloque del rol)
   --------------------------------------------------------------------- */
.cd-trabajo-grid {
  display: grid; gap: 12px; padding: 14px 16px 16px;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
}
.cd-trabajo {
  display: block; text-decoration: none; color: inherit;
  border: 1px solid #e2e8f1; border-left-width: 4px; border-radius: 10px;
  padding: 12px 14px; background: #fff; transition: box-shadow .15s, transform .15s;
}
.cd-trabajo:hover { box-shadow: 0 4px 14px rgba(16,42,80,.10); transform: translateY(-1px); }
.cd-trabajo-top { display: flex; align-items: center; justify-content: space-between; }
.cd-trabajo-valor { font-size: 24px; font-weight: 700; letter-spacing: -.02em; color: #102a50; }
.cd-trabajo-top i { font-size: 15px; opacity: .55; }
.cd-trabajo-titulo { font-size: 12.5px; font-weight: 600; color: #33475f; margin-top: 2px; }
.cd-trabajo-pie {
  display: flex; align-items: center; justify-content: space-between;
  margin-top: 8px; font-size: 11px; color: #7b8798;
}
.cd-trabajo-cta { color: #1677d2; font-weight: 600; white-space: nowrap; }
.cd-trabajo-red     { border-left-color: #dc2626; }
.cd-trabajo-orange  { border-left-color: #ea580c; }
.cd-trabajo-purple  { border-left-color: #7c3aed; }
.cd-trabajo-blue    { border-left-color: #1677d2; }
.cd-trabajo-gray    { border-left-color: #94a3b8; }

/* ---------------------------------------------------------------------
   Barra de cumplimiento (usada en el tablero por rol)
   --------------------------------------------------------------------- */
.cd-bar {
  height: 7px; border-radius: 99px; background: #e6ebf3; overflow: hidden;
  width: 100%;
}
.cd-bar-fill { display: block; height: 100%; border-radius: 99px; }
.cd-bar-fill.ok   { background: #16a34a; }
.cd-bar-fill.warn { background: #ea580c; }
.cd-bar-fill.bad  { background: #dc2626; }
.cd-bar-label { font-size: 11px; color: #7b8798; }
.cd-alerta { color: #b91c1c; font-weight: 600; }

/* anchos de la barra de cumplimiento: clases en lugar de style="" (CSP) */
.cd-col-bar { width: 150px; }
.cd-w0{width:0%}.cd-w5{width:5%}.cd-w10{width:10%}.cd-w15{width:15%}
.cd-w20{width:20%}.cd-w25{width:25%}.cd-w30{width:30%}.cd-w35{width:35%}
.cd-w40{width:40%}.cd-w45{width:45%}.cd-w50{width:50%}.cd-w55{width:55%}
.cd-w60{width:60%}.cd-w65{width:65%}.cd-w70{width:70%}.cd-w75{width:75%}
.cd-w80{width:80%}.cd-w85{width:85%}.cd-w90{width:90%}.cd-w95{width:95%}
.cd-w100{width:100%}

/* ---------------------------------------------------------------------
   Bloque de firmas de los informes que se imprimen
   --------------------------------------------------------------------- */
.cd-firmas {
  display: grid; grid-template-columns: 1fr 1fr; gap: 48px;
  margin-top: 48px; padding: 0 8px 24px;
}
.cd-firma { text-align: center; }
.cd-firma-linea { border-top: 1px solid #33475f; margin-bottom: 6px; }
.cd-firma-rol { font-size: 12px; font-weight: 600; color: #33475f; }
.cd-firma-campo { font-size: 11px; color: #7b8798; }
.cd-cumpl-grande { font-size: 28px; font-weight: 700; color: #102a50; }
@media print {
  .cd-firmas { break-inside: avoid; page-break-inside: avoid; margin-top: 40px; }
}

.cd-page-header .cd-btn-export { white-space: nowrap; }

/* columna de selección en las tablas por lote */
.cd-col-check { width: 36px; }
.cd-col-check input, .cd-check-doc { cursor: pointer; width: 15px; height: 15px; }

/* ---------------------------------------------------------------------
   Detalle de un evento de auditoría
   --------------------------------------------------------------------- */
.cd-json {
  margin: 0; padding: 14px 16px; max-height: 460px; overflow: auto;
  background: #f7f9fc; border-top: 1px solid #e2e8f1;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11.5px; line-height: 1.55; color: #22303f; white-space: pre-wrap;
  word-break: break-word;
}
.cd-diff-antes { color: #b91c1c; text-decoration: line-through; text-decoration-thickness: 1px; }
.cd-diff-despues { color: #15803d; font-weight: 500; }

/* detalle dentro de las tarjetas de hallazgos */
.cd-trabajo-detalle {
  font-size: 11px; color: #6b7787; margin-top: 6px; line-height: 1.45;
}
.cd-tag-alta { background: #fee2e2; color: #991b1b; border-color: #fecaca; }

/* ---------------------------------------------------------------------
   Formularios dentro de un modal.
   El formulario de alta se diseñó para una página completa (rejilla de 12
   columnas); al abrirse en el diálogo cada campo recibía una franja mínima y
   quedaba ilegible. Dentro del modal se usa una rejilla de 2 columnas.
   --------------------------------------------------------------------- */
.cd-dialog .cd-form-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  gap: 14px 16px !important;
}
.cd-dialog .cd-form-grid > .cd-field {
  grid-column: span 1 !important;
}
/* los campos que ocupan toda la fila de la página se respetan si son anchos */
.cd-dialog .cd-form-grid > .cd-span-12,
.cd-dialog .cd-form-grid > .cd-span-6 {
  grid-column: span 2 !important;
}
.cd-dialog .cd-form-foot { padding: 14px 20px !important; }
.cd-dialog .cd-panel {
  border: 0 !important; box-shadow: none !important; margin-bottom: 6px !important;
}
.cd-dialog .cd-panel-head { padding: 10px 20px 6px !important; }
.cd-dialog .cd-dialog-body { max-height: 72vh; overflow-y: auto; }

/* separador compacto en las cabeceras de panel */
.cd-mr { margin-right: 8px; }

/* ---------------------------------------------------------------------
   Menú replicado del original: secciones con título y opciones anidadas.
   --------------------------------------------------------------------- */
.cdd-side-sep { height: 1px; background: #495057; margin: 6px 12px; opacity: .7; }
.cdd-side-group {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 16px 4px; color: #adb5bd;
  font-size: 11px; font-weight: 600; text-transform: uppercase;
  letter-spacing: .04em; white-space: nowrap; overflow: hidden;
}
.cdd-side-group i { width: 18px; text-align: center; font-size: 12px; }
.cdd-side-sub { padding-left: 30px !important; }
.cdd-side-sub .cdd-side-t { font-size: 13px; }
.cdd-side-pending { opacity: .55; }
.cdd-side-pending:hover { opacity: .85; }

/* =====================================================================
   Menú lateral: valores copiados del CSS del original
   (menu_izquierdo_bravoerp.asp servido por el sistema en marcha).
   Fondo #343a40, separadores #495057, título 13px, submenú #3f474e,
   viñeta de 6px, activo #007bff.
   ===================================================================== */
.cdd-side { background-color: #343a40 !important; }
.cdd-side a { text-decoration: none; }

.cdd-logo-divider {
  border-bottom: 1px solid #495057;
  width: 100%;
}

.cdd-menu-item {
  cursor: pointer;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid #495057;
  transition: background-color .3s;
  color: #fff;
  font-family: 'Segoe UI', sans-serif;
}
.cdd-menu-item:hover { background-color: #495057; }
.cdd-menu-item.cdd-active { background-color: #495057; }
.cdd-menu-item .cdd-icon { min-width: 20px; text-align: center; font-size: 14px; }
.cdd-menu-item .cdd-menu-title {
  flex-grow: 1;
  white-space: nowrap;
  overflow: hidden;
  font-size: 13px;
  transition: opacity .3s, max-width .3s;
}
.cdd-submenu-toggle { font-size: 11px; transition: transform .3s ease; }
.cdd-menu-item.cdd-expanded .cdd-submenu-toggle { transform: rotate(90deg); }

.cdd-submenu {
  max-height: 0;
  overflow: hidden;
  transition: max-height .4s ease;
  background-color: #3f474e;
}
.cdd-submenu.cdd-open { max-height: 900px; }
.cdd-submenu a {
  display: block;
  padding: 10px 30px;
  font-size: 14px;
  color: #dee2e6;
  text-decoration: none;
  position: relative;
}
.cdd-submenu a::before {
  font-family: "Font Awesome 5 Free";
  content: "\f111";
  font-weight: 900;
  color: #fff;
  position: absolute;
  left: 15px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 6px;
}
.cdd-submenu a:hover { background-color: #495057; }
.cdd-submenu a.cdd-active { background-color: #007bff; color: #fff; }
.cdd-submenu a.cdd-pending { opacity: .6; }

/* barra colapsada: sólo iconos, como el original (70 px).
   Se muestran los títulos al pasar el ratón o cuando está fijada. */
.cdd-side:not(:hover):not([data-fixed="true"]) .cdd-menu-title,
.cdd-side:not(:hover):not([data-fixed="true"]) .cdd-submenu-toggle,
.cdd-side:not(:hover):not([data-fixed="true"]) .cdd-submenu { display: none; }


/* Buscador de selects largos (regla de listas desplegables). */
.cdd-select-buscar { display: block; width: 100%; box-sizing: border-box;
  margin: 0 0 4px; padding: .28rem .5rem; font: inherit; font-size: .8rem;
  color: inherit; background: #fff; border: 1px solid var(--cd-border, #dce5f2);
  border-radius: 7px; }
.cdd-select-buscar:focus { outline: 2px solid rgba(52, 120, 246, .22); border-color: #5b8def; }
.cdd-select-buscar--compact { margin-bottom: 3px; padding: .12rem .35rem; font-size: .72rem;
  border-radius: 5px; }


