/* ============================================================================
   roles - estructura de la replica original (replicador-web-integral/roles/replica-test)
   re-pintada con la paleta de Vector GPS
   ============================================================================ */
:root {
  --wire-paper: #ffffff;
  --wire-ink: #26313d;
  --wire-line: #bfcbd6;
  --wire-soft-line: #bfcbd6;
  --wire-muted: #f4f7f9;
  --wire-error: #dc3545;
  --wire-backdrop: rgba(0, 0, 0, .2);
  font: 13px/18px Roboto,Arial,sans-serif;
  color: var(--wire-ink);
  background: var(--wire-paper);
}
* { box-sizing: border-box; border-radius: 0; }
html, body { margin: 0; min-width: 0; color: var(--wire-ink); background: var(--wire-paper); }
button, input, select { font: inherit; color: inherit; }
button, input, select, fieldset, dialog { border:1px solid var(--wire-line); background: var(--wire-paper); }
button { min-height: 24px; padding: 2px 18px; cursor: pointer; }
button:disabled { color: var(--wire-line); background: var(--wire-muted); cursor: not-allowed; }
button:hover:not(:disabled), .role-row:hover { background: var(--wire-muted); }
button:focus-visible, input:focus-visible, select:focus-visible, [tabindex]:focus-visible { outline:2px solid #bfcbd6; outline-offset: 1px; }
[hidden] { display: none !important; }
.visually-hidden { position: absolute !important; width: 1px !important; height: 1px !important; padding: 0 !important; margin: -1px !important; overflow: hidden !important; clip-path: inset(50%) !important; white-space: nowrap !important; border:0 !important; }

#roles-app { min-height: 100vh; }
#status { position: fixed; z-index: 60; top: 8px; right: 8px; max-width: 420px; margin: 0; padding: 6px; border:1px solid var(--wire-line); background: var(--wire-paper); }
#toolbar { height: 44px; display: flex; align-items: center; gap: 6px; padding: 10px; overflow: hidden; }

#role-editor { position: relative; height: 704px; margin: 10px 20px; }
#role-form { height: 100%; }
#form-result { position: absolute; z-index: 3; top: 0; right: 0; max-width: 430px; padding: 5px 8px; border:1px solid var(--wire-line); background: var(--wire-paper); }
.form-row { position: relative; display: grid; grid-template-columns: max-content 200px; align-items: center; column-gap: 6px; height: 27px; margin-bottom: 10px; }
.form-row input { width: 200px; height: 27px; padding: 3px 6px; }
#role-name { transform: translateX(-3px); }
#role-description { transform: translateX(-5px); }
.field-error { position: absolute; left: 310px; top: 4px; min-width: 300px; color: var(--wire-error); }
#privileges-fieldset { height: 585px; min-width: 0; margin: 0 2px; padding: 10px; }
#privileges-fieldset legend { padding: 0 4px; font-weight: 600; }
#privilege-search { display: block; width: 200px; height: 30px; margin-top: 21px; padding: 5px 8px; }
.transfer { display: grid; grid-template-columns: 400px 33px 400px; gap: 0; align-items: end; margin-top: 0; max-width: 833px; }
.transfer section { min-width: 0; }
.transfer h2 { height: 37px; margin: 0; padding: 9px 8px; border:1px solid var(--wire-line); border-bottom:0; font-size: 12px; text-align: center; background: var(--wire-muted); }
.transfer select { display: block; width: 100%; height: 460px; padding: 3px; }
.transfer-controls { display: grid; align-content: start; gap: 0; height: 460px; padding-left: 4px; }
.transfer-controls button { width: 29px; height: 32px; min-width: 0; padding: 0; }
.form-actions { display: flex; align-items: center; gap: 4px; height: 24px; margin-top: 20px; }
.form-actions button { height: 24px; }

#list-section { margin: 0; }
#list-title { height: 42px; margin: 0; padding: 10px 5px 10px 15px; border:0; font-size: 16px; letter-spacing: 2px; }
#roles-grid { position: relative; width: 100%; height: calc(100vh - 86px); min-height: 300px; border:1px solid var(--wire-soft-line); overflow: hidden; }
#grid-tools { height: 58px; display: flex; justify-content: flex-end; align-items: flex-start; gap: 10px; padding: 7px 8px 0; }
#export-roles { order: 1; width: 30px; height: 27px; min-height: 27px; padding: 0; font-size: 18px; }
.search-field { order: 2; }
#role-search { width: 200px; height: 27px; padding: 4px 8px; }
#grid-header { height: 33px; min-width: 800px; overflow: hidden; }
.grid-head { position: relative; min-width: 0; height: 33px; border-right:1px solid var(--wire-soft-line); border-bottom:1px solid var(--wire-soft-line); background: var(--wire-muted); }
.sort-button { position: absolute; inset: 0 24px 0 0; width: calc(100% - 24px); height: 32px; padding: 6px 8px; border:0; text-align: left; font-weight: 600; background: var(--wire-muted); }
.sort-arrow { margin-left: 5px; }
.column-menu-button { position: absolute; top: 0; right: 0; width: 24px; height: 32px; min-height: 32px; padding: 0; border:0; font-size: 20px; font-weight: 700; background: var(--wire-muted); }
.resize-handle { position: absolute; z-index: 2; top: 0; right: -3px; width: 6px; height: 32px; cursor: col-resize; }
#role-rows { height: calc(100% - 91px); min-width: 800px; overflow: auto; }
.role-row { min-width: 800px; min-height: 31px; cursor: pointer; }
.role-row[aria-selected="true"] { outline:2px solid #bfcbd6; outline-offset: -2px; }
.grid-cell { height: 31px; overflow: hidden; padding: 6px 8px; border-right:1px solid var(--wire-soft-line); border-bottom:1px solid var(--wire-soft-line); white-space: nowrap; text-overflow: ellipsis; }

#column-menu { position: absolute; z-index: 40; width: 160px; border:1px solid var(--wire-line); background: var(--wire-paper); }
#column-menu > button { display: block; width: 100%; height: 29px; padding: 5px 12px; border:0; text-align: left; }
#column-menu hr { margin: 0; border:0; border-top:1px solid var(--wire-soft-line); }
#column-checks { position: absolute; left: 8px; top: 87px; width: 210px; padding: 4px; border:1px solid var(--wire-line); background: var(--wire-paper); }
#column-checks label { display: block; height: 28px; padding: 4px; white-space: nowrap; }

 dialog { width: min(440px, calc(100% - 20px)); padding: 12px; }
dialog h2 { margin: 0 0 10px; font-size: 16px; }
dialog::backdrop { background: var(--wire-backdrop); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 5px; margin-top: 12px; }

@media (max-width: 900px) {
  .transfer { grid-template-columns: minmax(260px, 1fr) 33px minmax(260px, 1fr); max-width: 100%; }
  #role-rows, #grid-header, .role-row { min-width: 640px; }
}
@media (max-width: 820px) {
  #role-editor { height: auto; min-height: 0; margin-inline: 8px; }
  #privileges-fieldset { height: auto; }
  .transfer { grid-template-columns: 1fr; gap: 6px; }
  .transfer select { height: 260px; }
  .transfer-controls { grid-template-columns: repeat(4, 1fr); height: auto; }
  .transfer-controls button { width: 100%; }
  .form-actions { margin-bottom: 10px; }
}
@media (max-width: 600px) {
  #toolbar { height: auto; min-height: 44px; display: grid; grid-template-columns: 1fr; overflow: visible; }
  #toolbar button { width: 100%; }
  .form-row { grid-template-columns: 1fr; height: auto; gap: 3px; margin-bottom: 10px; }
  .form-row input { width: 100%; }
  .field-error { position: static; min-width: 0; }
  #grid-tools { justify-content: stretch; }
  .search-field { flex: 1; }
  #role-search { width: 100%; }
}

/* ============================================================================
   Capa Vector GPS (colores, bordes y estados) - no altera el layout original
   Referencia: GUIA_ESTILOS_UI.md
   ============================================================================ */
:root {
  --v-primary: #0f8995; --v-primary-border: #0d7d88; --v-primary-dark: #0a6670;
  --v-primary-tint: #e6f4f5; --v-primary-ring: rgba(15, 137, 149, .18);
  --v-danger: #dc3545; --v-danger-dark: #bd2130; --v-success: #28a745; --v-success-dark: #1e8a37;
  --v-text: #26313d; --v-title: #1f2a35; --v-muted: #607080; --v-label: #485664;
  --v-border: #cfd9e2; --v-input-border: #bfcbd6; --v-th-bg: #f4f7f9; --v-input-bg: #f9fbfc;
  --v-shadow-pop: 0 12px 24px rgba(26, 36, 44, .22);
}

html, body { font-family: Roboto, -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Arial, "Noto Sans", sans-serif; color: var(--v-text); }
a { color: var(--v-primary); }
h1, h2, h3 { color: var(--v-title); }

button {
  border-color: var(--v-input-border);
  border-radius: 6px;
  background-color: #fff;
  color: var(--v-label);
  font-weight: 600;
  transition: background-color 120ms ease, border-color 120ms ease, color 120ms ease;
}
button:hover:not(:disabled) { color: var(--v-primary); border-color: var(--v-primary); background-color: var(--v-primary-tint); }
button:disabled { opacity: .5; color: #9aa6b2; background-color: #f4f7f9; border-color: #d8e0e6; cursor: not-allowed; }

button:is([id*="save" i],[id*="create" i],[id*="crear" i],[id*="guardar" i],[id*="accept" i],[id*="aceptar" i],[id*="apply" i],[id*="send" i],[id*="enviar" i],[id*="agregar" i],[id*="add" i],[id*="submit" i],[id*="filter" i]):not(:disabled) { color: #fff; background-color: var(--v-primary); border-color: var(--v-primary-border); }
button:is([id*="save" i],[id*="create" i],[id*="crear" i],[id*="guardar" i],[id*="accept" i],[id*="aceptar" i],[id*="apply" i],[id*="send" i],[id*="enviar" i],[id*="agregar" i],[id*="add" i],[id*="submit" i],[id*="filter" i]):hover:not(:disabled) { color: #fff; background-color: var(--v-primary-dark); border-color: var(--v-primary-dark); }

button:is([id*="edit" i],[id*="editar" i]):not(:disabled) { color: var(--v-primary); border-color: var(--v-primary); }

button:is([id*="delete" i],[id*="remove" i],[id*="borrar" i],[id*="eliminar" i]):not(:disabled) { color: var(--v-danger); border-color: #e3a0a8; background-color: #fff5f6; }
button:is([id*="delete" i],[id*="remove" i],[id*="borrar" i],[id*="eliminar" i]):hover:not(:disabled) { color: #fff; border-color: var(--v-danger); background-color: var(--v-danger); }

button:is([id*="excel" i],[id*="download" i],[id*="export" i],[id*="csv" i],[id*="descargar" i]):not(:disabled) { color: #fff; background-color: var(--v-success); border-color: var(--v-success); }
button:is([id*="excel" i],[id*="download" i],[id*="export" i],[id*="csv" i],[id*="descargar" i]):hover:not(:disabled) { color: #fff; background-color: var(--v-success-dark); border-color: var(--v-success-dark); }

button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, [tabindex]:focus-visible, [role="row"]:focus-visible {
  outline: 2px solid var(--v-primary);
}

input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="color"]):not([type="file"]), select, textarea {
  border-color: var(--v-input-border);
  border-radius: 6px;
  background-color: var(--v-input-bg);
  color: var(--v-text);
}
input:not([type="checkbox"]):not([type="radio"]):focus, select:focus, textarea:focus { border-color: var(--v-primary); box-shadow: 0 0 0 3px var(--v-primary-ring); }
input:disabled, select:disabled, textarea:disabled { color: #8a97a4; background-color: #f1f4f6; }
input[type="checkbox"], input[type="radio"], input[type="range"] { accent-color: var(--v-primary); }

fieldset { border-color: var(--v-border); border-radius: 8px; }
legend { color: var(--v-primary); font-weight: 700; }

th, [role="columnheader"] { background-color: var(--v-th-bg); color: #536171; font-weight: 700; }

tr[aria-selected="true"], [role="row"][aria-selected="true"], [role="option"][aria-selected="true"], tr.selected, [role="row"].selected,
[class*="row"].selected, [class*="item"].selected, [class*="row"][aria-selected="true"], [class*="item"][aria-selected="true"] {
  background-color: var(--v-primary-tint);
  box-shadow: inset 4px 0 0 var(--v-primary);
  outline: none;
}
tbody tr:hover, [role="grid"] [role="row"]:hover { background-color: rgba(15, 137, 149, .07); }
tr[aria-selected="true"]:hover, tr.selected:hover, [role="row"][aria-selected="true"]:hover { background-color: var(--v-primary-tint); }

dialog {
  border: 1px solid var(--v-border);
  border-top: 4px solid var(--v-primary);
  border-radius: 8px;
  background: #fff;
  color: var(--v-text);
  box-shadow: var(--v-shadow-pop);
}
dialog:not([open]) { display: none !important; }
dialog::backdrop { background: rgba(26, 36, 44, .5); }

/* Botones dentro de encabezados de tabla: sin caja */
th button, [role="columnheader"] button { background-color: transparent; border-color: transparent; box-shadow: none; color: inherit; }
th button:hover:not(:disabled), [role="columnheader"] button:hover:not(:disabled) { background-color: rgba(15, 137, 149, .10); border-color: transparent; color: var(--v-primary); }
/* Estado activo / seleccionado en botones (pestañas, filtros, categorías) */
button[aria-pressed="true"]:not(:disabled), button[aria-selected="true"]:not(:disabled), button.active:not(:disabled), button.selected:not(:disabled) {
  color: var(--v-primary-dark); background-color: var(--v-primary-tint); border-color: var(--v-primary); box-shadow: none;
}

/* ============================================================================
   v2 - encabezado, tarjetas, bandas de panel y diálogos al nivel de Alertas
   ============================================================================ */
html, body { background: #eef2f5; }

main.v2 {
  display: flex !important;
  flex-direction: column;
  gap: 10px;
  width: auto !important;
  min-width: 0 !important;
  max-width: none !important;
  min-height: 100vh;
  margin: 0 !important;
  padding: 14px 14px 44px !important;
  box-sizing: border-box;
  background: transparent !important;
}
main.v2 > * { min-width: 0; }

.hero {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px 16px;
  padding: 14px 16px;
  background: #fff;
  border: 1px solid var(--v-border);
  border-left: 4px solid var(--v-primary);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(31, 45, 61, .08);
}
.hero .eyebrow { margin: 0; font-size: 11.5px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--v-primary); }
.hero .hero-heading { margin: 0; font-size: 22.7px; line-height: 1.2; font-weight: 700; color: var(--v-title); }
.hero .hero-meta { margin: 2px 0 0; font-size: 12px; color: var(--v-muted); }
.hero > :not(.hero-title) {
  display: flex !important;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px !important;
  width: auto !important;
  height: auto !important;
  margin: 0 !important;
  padding: 0 !important;
  background: transparent !important;
  border: 0 !important;
  box-shadow: none !important;
}
.hero > :not(.hero-title) button { width: auto !important; min-width: 112px; height: auto !important; min-height: 34px; padding: 5px 14px; font-size: 12.5px; }

/* Tarjetas */
main.v2 :is(#role-editor,#list-section) {
  background: #fff !important;
  border: 1px solid var(--v-border) !important;
  border-radius: 8px !important;
  box-shadow: 0 3px 12px rgba(31, 45, 61, .06);
  margin: 0 !important;
  width: auto !important;
  max-width: none !important;
  overflow: hidden;
}

/* Bandas de panel (carbón + filo turquesa); incluye títulos ocultos visualmente */
main.v2 :is(#editor-title,#list-title) {
  display: block !important;
  position: static !important;
  clip: auto !important;
  clip-path: none !important;
  width: auto !important;
  height: auto !important;
  margin: 0 !important;
  padding: 9px 14px !important;
  overflow: visible !important;
  white-space: normal !important;
  font: 700 13px/1.45 Roboto, Arial, sans-serif !important;
  letter-spacing: .02em !important;
  text-transform: none !important;
  color: #fff !important;
  background: #343a40 !important;
  border: 0 !important;
  border-bottom: 3px solid var(--v-primary) !important;
  border-radius: 0 !important;
}

/* Contenido de las tarjetas: aire interno (cuadrículas y tablas a sangre) */
main.v2 :is(#role-editor,#list-section) > :not(:is(#editor-title,#list-title)):not(table):not([role="grid"]):not(.table-scroll):not(.table-wrap):not(.grid):not(.visually-hidden):not(.sr-only):not([hidden]) {
  margin-left: 14px;
  margin-right: 14px;
}
main.v2 :is(#role-editor,#list-section) > :nth-child(2):not(:is(#editor-title,#list-title)),
main.v2 :is(#editor-title,#list-title) + * { margin-top: 12px; }
main.v2 :is(#role-editor,#list-section) { padding-bottom: 14px !important; }

/* Diálogos con encabezado */
dialog { padding: 0 0 14px !important; overflow: auto; }
dialog > :not(header):not(h1:first-child):not(h2:first-child) { margin-left: 16px; margin-right: 16px; }
dialog > header, dialog > h1:first-child, dialog > h2:first-child {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin: 0 0 12px !important;
  padding: 9px 14px !important;
  font: 700 13px/1.45 Roboto, Arial, sans-serif !important;
  color: #fff !important;
  background: #343a40 !important;
  border: 0 !important;
  border-bottom: 3px solid var(--v-primary) !important;
}
dialog > header h2, dialog > header h1 { margin: 0 !important; padding: 0 !important; font: 700 13px/1.45 Roboto, Arial, sans-serif !important; color: #fff !important; background: transparent !important; border: 0 !important; }
dialog > header button { min-height: 26px; padding: 0 9px; color: #fff; background: transparent; border-color: rgba(255, 255, 255, .4); }
dialog > header button:hover:not(:disabled) { color: #fff; background: rgba(255, 255, 255, .16); border-color: #fff; }
dialog[id*="confirm" i] { border-top-color: var(--v-danger); }
dialog[id*="confirm" i] > h1:first-child, dialog[id*="confirm" i] > h2:first-child, dialog[id*="confirm" i] > header { border-bottom-color: var(--v-danger); }
/* v2: tipografia de formularios */
main.v2 label { color: var(--v-label); font-weight: 600; }
main.v2 label:has(> input[type="checkbox"]), main.v2 label:has(> input[type="radio"]) { font-weight: 500; color: var(--v-text); }
main.v2 legend { font-size: 12px; letter-spacing: .02em; }
main.v2 [role="alert"]:not(:empty), main.v2 .inline-error:not(:empty), main.v2 .field-error:not(:empty) { color: var(--v-danger); font-size: 11.5px; font-weight: 500; }
main.v2 [role="status"]:not(:empty):not([hidden]) { color: #155724; }
/* v2: cuadriculas dentro de tarjetas sin doble borde */
main.v2 [role="grid"]:not(table) { border: 0 !important; }
main.v2 [role="columnheader"] { min-height: 34px; }

/* v3: tablas a ancho completo del contenedor */
table { width: 100%; }

/* Tarjetas sin contenido visible (todos sus hijos ocultos por JS): no se muestran */
main.v2 section:has(> [hidden]):not(:has(> :not([hidden]))) { display: none !important; }