/* ==========================================================================
   1. LAYOUT & ESTRUCTURA BASE (layout.css)
   Optimizado como Wireframe estructural por defecto usando Variables Estantes
   ========================================================================== */

:root {
  /* Alambres/Wireframe por defecto (si no hay tema cargado) */
  --font-main: 'Courier New', monospace;
  --font-size-sm: 11px;
  --font-size-md: 13px;
  --font-size-lg: 15px;
  --icon-size:3rem;

  --space-xs:  4px;
  --space-sm:  8px;
  --space-md:  12px;
  --space-lg:  16px;

  --radius:    0px;
  --radius-lg: 0px;

  --h-title:   24px;
  --h-menubar: 30px;
  --h-taskbar: 32px;

  /* Colores Estructurales Estilo Boceto / Wireframe */
  --c-bg:             #ffffff;
  --c-bg-dot:         #e0e0e0;
  --c-surface:        #ffffff;
  --c-surface-alt:    #f5f5f5;
  --c-surface-hover:  #eeeeee;
  --c-menubar-bg:     #ffffff;
  --c-border:         #000000;
  --c-border-light:   #dddddd;
  --c-border-focus:   #000000;
  --c-border-table:   #eeeeee;
  --c-text-main:      #000000;
  --c-text-muted:     #777777;
  --c-text-inverse:   #ffffff;

  --c-accent:         #333333;
  --c-accent-hover:   #000000;
  --c-accent-text:    #ffffff;
  --c-danger:         #ff3333;
  --c-danger-border:  #cc0000;
  --c-warning:        #ffcc00;
  --c-warning-border: #cc9900;
  --c-success:        #33cc33;
  --c-success-border: #009900;
  
  --c-scrollbar:       #dddddd;
  --c-scrollbar-hover: #aaaaaa;
  --c-tree-sel-bg:     #eeeeee;
  --c-tree-sel-color:  #000000;
  --c-shortcut-hover:  #eeeeee;
  --c-shortcut-border: #000000;

  --shadow-inset:      none;
  --shadow-win:        4px 4px 0px #000000;
  --shadow-win-blur:   2px 2px 0px #777777;
  --shadow-text:       none;
  --stripe-pattern:    line-through;
  --win-border:        1px solid var(--c-border);

  --z-win-resize: 5;
  --z-shortcuts:  10;
  --z-menubar:    9000;
  --z-context:    10000;
  --z-overlay:    99998;
}

/* --- RESET & BODY --- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

.hidden{
	display:none!important;
}

body {
  width: 100vw; height: 100vh; overflow: hidden;
  font-family: var(--font-main); font-size: var(--font-size-md); color: var(--c-text-main);
  background: var(--c-bg);
  background-image: radial-gradient(var(--c-bg-dot) 1px, transparent 1px);
  background-size: 8px 8px;
  display: flex; flex-direction: column;
  user-select: none; -webkit-user-select: none;
}

/* --- MENUBAR GLOBAL --- */
#menubar {
  height: var(--h-menubar); flex-shrink: 0; z-index: var(--z-menubar);
  background: var(--c-menubar-bg); border-bottom: 1px solid var(--c-border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 var(--space-md); gap: var(--space-sm);
  font-size: var(--font-size-md); font-weight: bold;
  box-shadow: var(--shadow-inset);
}

/* --- ESCRITORIO Y SHORTCUTS --- */
#desktop { flex: 1; position: relative; overflow: hidden; pointer-events: none; }

#shortcuts {
  position: absolute; top: var(--space-lg); right: var(--space-lg); left: var(--space-lg); bottom: var(--space-lg);
  display: flex; flex-direction: row; gap: var(--space-md); z-index: var(--z-shortcuts); flex-wrap: wrap;
  overflow-y: auto; align-content: flex-start;
}
.shortcut {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  width: 85px; padding: var(--space-sm) var(--space-xs); border-radius: var(--radius-lg); cursor: pointer;
  border: 1px solid transparent; transition: all .15s; pointer-events: all;
}
.shortcut:hover { background-color: var(--c-shortcut-hover); border-color: var(--c-shortcut-border); }
.shortcut-icon  { font-size: 32px; line-height: 1; margin-bottom: var(--space-xs); }
.shortcut-label { font-size: var(--font-size-sm); text-align: center; font-weight: bold; color: var(--c-text-main); text-shadow: var(--shadow-text); }
div.CodeMirror{
    height:100%;
}

/**context**/
.row.ctx-item .row-text{
	padding-right:1rem;
}


/* --- VENTANAS (WINDOWS) --- */
.win {
  pointer-events: all; position: absolute;
  background: var(--c-surface); border: var(--win-border);
  box-shadow: var(--shadow-win-blur);
  display: flex; flex-direction: column;
  min-width: 240px; min-height: 140px; max-width: 100%;
  overflow: hidden; border-radius: var(--radius);
  transition: box-shadow .15s, border-color .15s;
}
.win.focused { box-shadow: var(--shadow-win); border-color: var(--c-border-focus); }
.win.maximized { top: 0 !important; left: 0 !important; width: 100% !important; height: 100% !important; border-radius: 0; }
.win.maximized .win-resize { display: none; }
.win.minimized { height: auto !important; padding-bottom: 0; }
.win.minimized .win-body, .win.minimized .win-menu, .win.minimized .win-resize { display: none; }

/* Barra de Título */
.win-title {
  height: var(--h-title); flex-shrink: 0; position: relative; cursor: grab;
  display: flex; align-items: center; justify-content: center;
  border-bottom: 1px solid var(--c-border); background: var(--c-surface-alt);
  overflow: hidden;
}
.win-title::before { content: ''; position: absolute; inset: 0; background: var(--stripe-pattern); opacity: .4; }

.win-title-text {
  position: relative; z-index: 1; background: var(--c-surface);
  padding: 0 var(--space-md); font-weight: bold; font-size: var(--font-size-sm);
  pointer-events: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  border-left: 1px solid var(--c-border); border-right: 1px solid var(--c-border);
  display: flex; align-items: center; gap: var(--space-xs);
}

/* Botones de Control */
.win-btns { position: absolute; left: var(--space-sm); display: flex; gap: var(--space-xs); z-index: 2; }
.win-btn {
  width: 14px; height: 14px; border: 1px solid var(--c-border); background: var(--c-surface);
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  font-size: 9px; font-weight: bold; border-radius: var(--radius); color: var(--c-text-muted);
  box-shadow: var(--shadow-inset); transition: all .1s;
}
.win-btn.close:hover { background: var(--c-danger); color: var(--c-text-inverse); border-color: var(--c-danger-border); }
.win-btn.min:hover   { background: var(--c-warning); color: var(--c-text-inverse); border-color: var(--c-warning-border); }
.win-btn.max:hover   { background: var(--c-success); color: var(--c-text-inverse); border-color: var(--c-success-border); }

/* Menú Interno de Ventana */
.win-menu {
  display: flex; align-items: center; gap: var(--space-xs); padding: var(--space-xs) var(--space-sm);
  background: var(--c-surface-alt); border-bottom: 1px solid var(--c-border); flex-shrink: 0;
}
.win-menu-btn {
  background: transparent; border: 1px solid transparent; padding: 3px var(--space-sm); font-family: var(--font-main);
  font-size: var(--font-size-sm); cursor: pointer; border-radius: var(--radius); color: var(--c-text-main);
}
.win-menu-btn:hover { background: var(--c-surface-hover); border-color: var(--c-border); }
.win-menu-toolbar{
    display:flex;align-items: center;pad:1rem;
}
.win-menu-toolbar .form-controller-layout{
	flex-direction: row;
	align-items: center;
}
.win-menu-toolbar .form-submits{
	border:0;
}
.win-menu {
  display: flex; 
  align-items: center; 
  justify-content: flex-start; /* Empuja los dropdowns a la izq y el toolbar a la der */
  gap: var(--space-sm); 
  padding: var(--space-xs) var(--space-sm);
  background: var(--c-surface-alt); 
  border-bottom: 1px solid var(--c-border); 
  flex-shrink: 0;
  width: 100%; /* Asegura que tome todo el ancho de la ventana */
}

/* Contenedor izquierdo (Menús desplegables) */
.win-menu-dropdowns {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
}

/* Contenedor derecho (Toolbar con accesorios y tabs) */
.win-menu-toolbar {
  display: flex;
  align-items: center;
  gap: var(--space-md); /* Espacio entre el botón "Ver en Web" y las pestañas */
}

/* ==========================================================================
   TABS / PESTAÑAS DENTRO DEL MENU
   ========================================================================== */

.tabs-header {
  display: flex;
  align-items: center;
  gap: 2px; /* Pequeña separación para estilo wireframe */
}

.tab-btn {
  background: transparent; 
  border: 1px solid transparent; 
  padding: var(--space-xs) var(--space-sm); 
  font-family: var(--font-main);
  font-size: var(--font-size-sm); 
  cursor: pointer; 
  border-radius: var(--radius); 
  color: var(--c-text-muted);
  transition: all 0.15s;
}

.tab-btn:hover { 
  background: var(--c-surface-hover); 
  color: var(--c-text-main); 
}

.tab-btn.active {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  color: var(--c-text-main);
  font-weight: bold;
  box-shadow: var(--shadow-inset);
}



/* Breadcrumb */
.breadcrumb {
  display: flex; align-items: center; flex: 1; min-width: 0; overflow: hidden;
  margin-left: var(--space-sm); padding-left: var(--space-sm); border-left: 1px solid var(--c-border); gap: 2px;
}
.bc-seg {
  cursor: pointer; padding: 2px var(--space-xs); white-space: nowrap; font-size: var(--font-size-sm);
  border-radius: var(--radius); color: var(--c-text-main);
}
.bc-seg:hover { background: var(--c-accent); color: var(--c-accent-text); }

/* Cuerpo y Redimensión */
.win-body { flex: 1; overflow: auto; display: flex; flex-direction: column; background: var(--c-surface); }
.win-resize {
  position: absolute; right: 0; bottom: 0; width: 16px; height: 16px; cursor: nwse-resize;
  display: flex; align-items: flex-end; justify-content: flex-end; padding: 2px; z-index: var(--z-win-resize);
}
.win-resize svg { pointer-events: none; opacity: .4; }

/* --- LAYOUTS INTERNOS Y CONTENEDORES --- */
.app-layout, .form-layout, .list-layout { display: flex; flex-direction: column; width: 100%; height: 100%; overflow: hidden; }
/* =========================================
   CONTENEDOR PRINCIPAL
   ========================================= */
.data-list { 
  flex: 1; 
  padding: var(--space-md); 
  overflow-y: auto; 
  align-content: start; 
}

/* Base común para los items */
.data-item { 
  cursor: pointer; 
  border-radius: var(--radius); 
  position: relative; 
}

.data-item:hover { 
  background-color: var(--c-surface-hover); 
}


/* =========================================
   VISTA DE LISTA (Tu nuevo diseño)
   ========================================= */
.data-list.view-list { 
  display: flex; 
  flex-direction: column; 
  gap: 0; 
  padding: var(--space-xs); 
}

.view-list .data-item { 
  display: grid;
  grid-template-columns: auto 1fr auto; 
  grid-template-rows: auto auto;        
  grid-template-areas: 
    "icon title badge"
    "icon desc  badge";
  align-items: center;                  
  gap: 4px 12px;
  padding: var(--space-sm) var(--space-md); 
  border-bottom: 1px solid var(--c-border-light); 
}

.view-list .data-item:last-child { 
  border-bottom: none; 
}

/* Asignación de áreas de la vista lista */
.view-list .item-icon { 
  grid-area: icon;
  font-size: 20px; 
}

.view-list .data-item > div:nth-child(2) { 
  grid-area: title;
  font-weight: bold;
  font-size: var(--font-size-md);
  white-space: nowrap; 
  overflow: hidden; 
  text-overflow: ellipsis;
}

.view-list .item-desc {
  grid-area: desc;
  font-size: var(--font-size-sm);
  /* color: var(--c-text-muted); Opcional: darle un tono más gris al subtitulo */
}

.view-list .theme-badge {
  grid-area: badge;
}


/* =========================================
   VISTA DE CUADRÍCULA (Grid view)
   ========================================= */
.data-list.view-grid {
  display: grid; 
  grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  grid-auto-rows: min-content; 
  gap: var(--space-md);
}

.view-grid .data-item { 
  display: flex; 
  flex-direction: column; 
  align-items: center; 
  text-align: center; 
  padding: var(--space-md) var(--space-sm); 
  border: 1px solid transparent; 
}

.view-grid .item-icon { 
  font-size: 36px; 
  line-height: 1; 
  margin-bottom: 6px; 
}

/* El título en la vista grid */
.view-grid .data-item > div:nth-child(2) { 
  font-size: var(--font-size-sm); 
  font-weight: bold; /* Para mantener consistencia con la vista lista */
  word-wrap: break-word; 
  overflow: hidden; 
  display: -webkit-box; 
  -webkit-line-clamp: 2; 
  -webkit-box-orient: vertical; 
}

/* Opcional: Ocultar subtítulo y badge en la vista de cuadrícula para no romper las cajas */
.view-grid .item-desc,
.view-grid .theme-badge {
  display: none;
}


/* --- BOTONES --- */
.btn {
  background: var(--c-surface); border: 1px solid var(--c-border);
  border-radius: var(--radius); padding: var(--space-sm) var(--space-lg); cursor: pointer;
  font-size: var(--font-size-sm); font-family: var(--font-main); color: var(--c-text-main);
  box-shadow: var(--shadow-inset); display: inline-flex; align-items: center; gap: var(--space-xs); white-space: nowrap;
}
.btn:active { transform: translate(1px, 1px); }
.btn:hover  { background: var(--c-accent); color: var(--c-text-inverse); border-color: var(--c-accent); }
.btn.primary { background: var(--c-accent); color: var(--c-text-inverse); border-color: var(--c-accent); font-weight: bold; }
.btn.danger:hover { background: var(--c-danger); color: var(--c-text-inverse); border-color: var(--c-danger-border); }
.btn.btn-sm { padding: var(--space-xs) var(--space-sm); }
.btn.btn-icon { padding: var(--space-xs) var(--space-sm); border-color: transparent; background: transparent; color: var(--c-text-muted); }
.btn.btn-icon:hover { background: var(--c-surface-hover); color: var(--c-text-main); border-color: var(--c-border); }

/* --- TABLAS / GRIDS DE DATOS --- */
.list-filters { display: flex; flex-wrap: wrap; gap: var(--space-xs); padding: var(--space-xs) var(--space-sm); background: var(--c-surface); border-bottom: 1px solid var(--c-border); flex-shrink: 0; }
.filter-ctrl { border: 1px solid var(--c-border); border-radius: var(--radius); font-size: var(--font-size-sm); padding: 3px var(--space-sm); height: 26px; outline: none; background: var(--c-surface); color: var(--c-text-main); }

.list-table-wrap { flex: 1; overflow: auto; }
.list-table { display: flex; flex-direction: column; width: 100%; font-size: var(--font-size-md); }
.list-tr { display: grid; grid-template-columns: var(--cols, repeat(auto-fit, minmax(80px, 1fr))); width: 100%; }
.list-thead { position: sticky; top: 0; z-index: 2; background: var(--c-surface-alt); border-bottom: 2px solid var(--c-border); }
.list-th { position: relative; padding: var(--space-sm) var(--space-md); font-weight: bold; font-size: var(--font-size-sm); color: var(--c-text-muted); border-right: 1px solid var(--c-border); display: flex; align-items: center; gap: var(--space-xs); overflow: hidden; }
.list-th.sortable { cursor: pointer; }
.list-th.sortable:hover { background: var(--c-surface-hover); color: var(--c-text-main); }

.col-resizer { position: absolute; right: 0; top: 0; bottom: 0; width: 6px; cursor: col-resize; z-index: 10; background: transparent; }
.col-resizer:hover, .col-resizer:active { background: var(--c-accent); opacity: 0.5; }

.list-tbody .list-tr { border-bottom: 1px solid var(--c-border-table); cursor: pointer; }
.list-tbody .list-tr:hover { background: var(--c-surface-hover); }
.list-td { padding: 0 var(--space-md); height: 34px; display: flex; align-items: center; border-right: 1px solid var(--c-surface-alt); overflow: hidden; }
.td-inner { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; width: 100%; display:flex;}
.list-td.td-actions { justify-content: center; opacity: 0; }
.list-tbody .list-tr:hover .list-td.td-actions { opacity: 1; }

.list-pager { display: flex; align-items: center; gap: var(--space-xs); padding: var(--space-xs) var(--space-sm); background: var(--c-surface-alt); border-top: 1px solid var(--c-border); flex-shrink: 0; }
/* Quita el borde de foco por defecto de la tabla */
.list-table:focus {
    outline: none;
}

/* El estilo de la fila enfocada por teclado */
.list-tr.row-focused {
    background-color: rgba(59, 130, 246, 0.1); /* Azul sutil, ajusta a tu paleta */
    outline: 2px solid #3b82f6; /* Borde para accesibilidad */
    outline-offset: -2px;
}


.list-td > img {
	width: 100%;
	height:100%;
	object-fit: cover;
}



/* --- FORMULARIOS --- */
/* =========================================
   VARIABLES BASE (Ajusta a tu paleta)
   (Por si te falta alguna en tu :root)
========================================= */
:root {
  --c-danger-muted: #fee2e2;
  --c-danger-border: #fca5a5;
  --c-accent-muted: rgba(59, 130, 246, 0.2);
}

/* =========================================
   UTILIDADES
========================================= */
.hidden { display: none !important; }

/* =========================================
   LAYOUT PRINCIPAL DEL CONTROLADOR
========================================= */
.form-controller-layout {
  display: flex;
  flex-direction: column;
  height: 100%;
  flex: 1;
  overflow: hidden;
  background: var(--c-surface);
}

/* Alertas y Errores de Validación */
.form-errors {
  background: var(--c-danger-muted);
  color: var(--c-danger);
  border: 1px solid var(--c-danger-border);
  border-radius: var(--radius);
  padding: var(--space-sm) var(--space-md);
  margin: var(--space-md) var(--space-lg) 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
  font-size: var(--font-size-sm);
}
.form-error-item {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
}

/* Cuerpo del formulario (Scrollable) */
.form-body {
  flex: 1;
  padding: var(--space-lg);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: var(--space-md); /* Espaciado automático entre campos */
}

/* Contenedor de Botones (Fijo al fondo) */
.form-submits {
  justify-content: flex-end;
  padding: var(--space-sm) var(--space-lg);
  border-top: 1px solid var(--c-border);
  background: var(--c-surface-alt);
  display: flex;
  gap: var(--space-sm);
  flex-shrink: 0;
}

/* =========================================
   CAMPOS Y ETIQUETAS (FIELDS)
========================================= */
.field {
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
  width: 100%;
}

.field-label {
  display: flex;
  align-items: center;
  gap: 4px; /* Espacio para los indicadores (* y •) */
  font-weight: bold;
  font-size: var(--font-size-sm);
  color: var(--c-text-main);
}

/* Indicadores de estado en labels */
.field-flag-req {
  color: var(--c-danger);
  font-weight: bold;
}
.field-flag-dirty {
  color: var(--c-accent);
  font-size: 1.2em;
  line-height: 1;
}

/* =========================================
   INPUTS AUTOMÁTICOS
========================================= */
.field-input {
  display: flex;
  flex-direction: column;
  width: 100%;
  position: relative;
}

/* Estilo unificado para todo input de texto, select y textarea dentro de un form */
.field-input > input:not([type="checkbox"]):not([type="radio"]):not([type="file"]),
.field-input > select,
.field-input > textarea,
.fk-search-input,
.form-control {
  width: 100%;
  box-sizing: border-box;
  border: 1px solid var(--c-border);
  background: var(--c-surface);
  color: var(--c-text-main);
  border-radius: var(--radius);
  font-size: var(--font-size-md);
  padding: var(--space-sm) var(--space-md);
  outline: none;
  font-family: inherit;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

/* Foco animado y moderno */
.field-input > input:not([type="checkbox"]):not([type="radio"]):not([type="file"]):focus,
.field-input > select:focus,
.field-input > textarea:focus,
.fk-search-input:focus,
.form-control:focus {
  border-color: var(--c-accent);
  box-shadow: 0 0 0 3px var(--c-accent-muted);
}

/* Estados deshabilitados */
.field-input > input[disabled], 
.field-input > select[disabled], 
.field-input > textarea[disabled],
.fk-search-input[readonly] {
  background: var(--c-surface-alt);
  color: var(--c-text-muted);
  cursor: not-allowed;
}

/* =========================================
   CHECKBOXES Y RADIOS
========================================= */
.field-input-checks {
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
  margin-top: 4px;
}
.field-input-checks label {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  font-size: var(--font-size-md);
  cursor: pointer;
  color: var(--c-text-main);
}
.field-input > input[type="checkbox"],
.field-input-checks input[type="radio"] {
  width: 18px;
  height: 18px;
  cursor: pointer;
  accent-color: var(--c-accent);
  margin: 0;
}

/* =========================================
   INPUT FILE
========================================= */
.field-input > input[type="file"] {
  font-size: var(--font-size-sm);
  padding: var(--space-xs) 0;
  cursor: pointer;
}
.field-input > input[type="file"]::file-selector-button {
  background: var(--c-surface-alt);
  border: 1px solid var(--c-border);
  padding: var(--space-xs) var(--space-sm);
  border-radius: var(--radius);
  cursor: pointer;
  margin-right: var(--space-md);
  font-family: inherit;
  font-size: var(--font-size-sm);
  transition: background 0.2s;
}
.field-input > input[type="file"]::file-selector-button:hover {
  background: var(--c-surface-hover);
}

/* =========================================
   TEXTAREA WRAPPER (Para el editor MD/Code)
========================================= */
.textarea-editor-wrap {
  display: flex;
  flex-direction: column;
  width: 100%;
}
.textarea-editor-wrap .btn {
  align-self: flex-end;
  margin-bottom: var(--space-xs);
}
.textarea-editor-wrap textarea {
  min-height: 100px;
  resize: vertical;
}

/* =========================================
   FOREIGN KEYS (Dropdowns dinámicos)
========================================= */
.fk-wrap {
  position: relative;
  width: 100%;
  display: flex;
  align-items: center;
}

.fk-search-input {
  width: 100%;
  padding-right: 36px; /* Espacio para que el texto no pise la "x" */
}

/* Botón de limpiar */
.fk-clear-btn {
  display: none;
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  background: transparent;
  border: none;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  color: var(--c-text-muted);
  width: 24px;
  height: 24px;
  border-radius: 50%;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}
.fk-clear-btn:hover {
  color: var(--c-danger);
  background: var(--c-surface-hover);
}
.fk-wrap.has-value .fk-clear-btn {
  display: flex;
}

/* Menú desplegable */
.fk-dropdown {
  display: none;
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  box-shadow: 0 8px 16px rgba(0,0,0,0.1);
  max-height: 250px;
  overflow-y: auto;
  z-index: 100;
  flex-direction: column;
}
.fk-wrap.is-open .fk-dropdown {
  display: flex;
}

/* Opciones del Dropdown */
.fk-item {
  background: transparent;
  border: none;
  text-align: left;
  padding: var(--space-sm) var(--space-md);
  font-size: var(--font-size-md);
  cursor: pointer;
  border-bottom: 1px solid var(--c-surface-alt);
  color: var(--c-text-main);
  font-family: inherit;
  transition: background 0.1s ease;
}
.fk-item:last-child {
  border-bottom: none;
}
.fk-item:hover, .fk-item:focus {
  background: var(--c-surface-hover);
  color: var(--c-accent);
  outline: none;
}

/* Mensajes dentro del dropdown (Cargando, Vacío) */
.fk-msg {
  padding: var(--space-sm) var(--space-md);
  font-size: var(--font-size-sm);
  color: var(--c-text-muted);
  font-style: italic;
  text-align: center;
}

/* --- COMPONENTES AUXILIARES --- */
.context-menu {
  position: fixed; z-index: var(--z-context); display: none; flex-direction: column;
  background: var(--c-surface); border: var(--win-border); box-shadow: var(--shadow-win);
  border-radius: var(--radius); padding: var(--space-xs) 0; min-width: 160px;
}
.context-menu.visible { display: flex; }
.context-menu button { background: transparent; color: var(--c-text-main); border: none; padding: var(--space-sm) var(--space-lg); text-align: left; font-size: var(--font-size-md); cursor: pointer; }
.context-menu button:hover { background: var(--c-accent); color: var(--c-accent-text); }

/* Tree View */
.tree-view { overflow: auto; height: 100%; min-width: max(150px, 25%); font-size: 0.95em; }
.tree-group { list-style: none; }
.tree-node .tree-group { display: none; padding-left: var(--space-md); border-left: 1px solid var(--c-border-light); margin-left: 10px; }
.tree-node.expanded > .tree-group { display: block; }
.tree-row { display: flex; align-items: center; padding: var(--space-xs); border-radius: var(--radius-lg); cursor: pointer; }
.tree-row:hover { background-color: var(--c-surface-hover); }
.tree-row.selected { background-color: var(--c-tree-sel-bg); color: var(--c-tree-sel-color); font-weight: bold; }
.tree-toggle { display: inline-block; width: 20px; text-align: center; font-size: 0.8em; opacity: 0.5; }
.tree-toggle.has-kids { opacity: 1; }
.tree-icon { margin: 0 var(--space-xs); }
.tree-label { flex: 1; white-space: nowrap; text-overflow: ellipsis; overflow: hidden; }

/* Scrollbars */
::-webkit-scrollbar { width: 12px; height: 12px; }
::-webkit-scrollbar-track { background: var(--c-bg); border-left: 1px solid var(--c-border); }
::-webkit-scrollbar-thumb { background: var(--c-scrollbar); border: 1px solid var(--c-border); }
::-webkit-scrollbar-thumb:hover { background: var(--c-scrollbar-hover); }

#dragOverlay { display: none; position: fixed; inset: 0; z-index: var(--z-overlay); }
body.dragging #dragOverlay { display: block; cursor: grabbing; }
body.resizing #dragOverlay { display: block; cursor: nwse-resize; }

/* ==========================================================================
   FOOTERS FIJOS (Toolbars y Paginadores)
   ========================================================================== */
/* Asegura que form-submits y toolbars se queden al fondo (flex-shrink: 0) */
.form-submits, .toolbar.right { 
  justify-content: flex-end; 
  padding: var(--space-sm); 
  border-top: 1px solid var(--c-border); 
  background: var(--c-surface-alt); 
  display: flex; 
  gap: var(--space-sm); 
  flex-shrink: 0; /* Evita que el scroll lo aplaste */
}

.list-pager { 
  display: flex; 
  align-items: center; 
  gap: var(--space-xs); 
  padding: var(--space-xs) var(--space-sm); 
  background: var(--c-surface-alt); 
  border-top: 1px solid var(--c-border); 
  flex-shrink: 0; /* Paginador fijo abajo */
}

/* ==========================================================================
   ALERTAS Y ESTADOS DE CARGA
   ========================================================================== */
.alert{
    display:flex;flex-direction: column;height:100%;
}
.win-body > .alert-text { 
  height: 100%; display: flex; flex-direction: column; 
  padding: 24px var(--space-lg) var(--space-lg); 
  overflow-y: auto; /* Scroll si el mensaje es muy largo */
}
.alert-text { 
  flex: 1; display: flex; align-items: center; justify-content: center; 
  font-size: var(--font-size-lg); color: var(--c-text-main); 
  text-align: center; line-height: 1.4; padding: 0 var(--space-md); 
}
.win-body > .alert > .btn { 
  align-self: center; min-width: 100px; justify-content: center; 
  padding: 6px var(--space-lg); margin-top: var(--space-lg); 
}

/* Barra de progreso de carga para ventanas */
.win.loading::after {
  content: "";
  position: absolute; 
  top: 0; /* Cambia a top: 0 si prefieres la barra arriba */
  left: 0;
  height: 4px; /* Grosor de la barra de progreso */
  background-color: #0078D7; /* Color de la barra (ej. azul de Windows) */
  z-index: 50;
  
  /* Llama a la animación: dura 6s, velocidad constante, y se queda al 100% al terminar */
  animation: fillProgress 6s linear forwards;
}

/* Definición de la animación */
@keyframes fillProgress {
  0% {
    width: 0%;
  }
  100% {
    width: 100%;
  }
}
/* Clase para cuando el cuerpo de la ventana no tiene contenido */
.win.loading .win-body{
  /* Un gradiente lineal con colores neutros muy suaves */
  background: linear-gradient(135deg, #f0f4f8, #d9e2ec, #f0f4f8);
  
  /* Hacemos el fondo el doble de grande para tener margen de movimiento */
  background-size: 200% 200%;
  
  /* Animación muy lenta (15s) para que no abrume */
  animation: gentlePan 15s ease infinite;
}

/* Animación que mueve la posición del fondo de ida y vuelta */
@keyframes gentlePan {
  0% {
    background-position: 0% 50%;
  }
  50% {
    background-position: 100% 50%;
  }
  100% {
    background-position: 0% 50%;
  }
}


/* ==========================================================================
   LAYOUTS COMPLEJOS Y SCROLL INTERNO (Code Editor & Forms)
   ========================================================================== */
.win-body .code-editor-layout {
  flex-grow: 1;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: stretch;
  min-height: 0; /* Clave para que el flex-child permita scroll interno */
}
.win-body .code-editor-layout .code-editor-container, 
.code-editor-layout .CodeMirror { 
  height: 100%; 
  overflow: auto; /* Scroll del editor */
}

.form-controller-layout { 
  flex: 1; display: flex; flex-direction: column; min-height: 0; 
}
.row-actions { white-space: nowrap; }
.textarea-editor-wrap > textarea { display: none; }

/* ==========================================================================
   FORMULARIOS (Mejora a 2 Columnas)
   ========================================================================== */

/* 1. Convertimos el contenedor del formulario en un Grid */
.form-body { 
  flex: 1; 
  padding: var(--space-lg); 
  overflow-y: auto; 
  
  /* Magia del Grid */
  display: grid; 
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); 
  gap: var(--space-md) var(--space-lg); /* gap vertical y horizontal */
  align-items: start; /* Para que los campos no se estiren verticalmente si uno es más alto */
  align-content: start;
}

/* 2. Mantener la estructura interna del form-group intacta */
.form-group { 
  display: flex; 
  flex-direction: column; 
  gap: var(--space-xs); 
  /* No necesitamos width: 100% aquí porque el Grid ya lo gestiona */
}

/* 3. Opcional: Hacer que los Textareas (editores) ocupen las 2 columnas */
/* Es muy útil que los campos grandes no queden apretados en una sola columna */
.form-group:has(.textarea-editor-wrap) {
  grid-column: 1 / -1; /* Esto le dice que ocupe desde la primera hasta la última línea de columna */
}

/* Nota: Si tu navegador no soporta :has(), puedes usar una clase específica 
   en los divs de los textareas, pero :has() ya tiene un gran soporte actual. */

/* Estilos de los inputs (asegurando que se vean bien en el nuevo layout) */
.form-group label { font-weight: bold; font-size: var(--font-size-sm); }
.form-control { 
  width: 100%; /* Asegura que el input llene su columna */
  border: 1px solid var(--c-border); 
  background: var(--c-surface); 
  color: var(--c-text-main); 
  border-radius: var(--radius); 
  font-size: var(--font-size-md); 
  padding: var(--space-sm) var(--space-md); 
  outline: none; 
}
.form-control:focus { border-color: var(--c-accent); }



/**** TABS ****/
.page-detail,.tabs-body,.tab-content,.tab-form-wrap, .tab-form-wrap > *{
    height:100%;
}

.app,.list-layout,.form-controller-layout{
    height:100%;
}


/*** FORM FIELDS **/
/* Contenedor relativo para que el menú flote respecto al input */
.fk-search-wrap {
    position: relative;
    width: 100%;
}

/* El botón "X" para limpiar */
.fk-clear-btn {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    border: none;
    background: transparent;
    font-size: 1.2rem;
    color: #6c757d; /* o var(--bs-secondary) */
    z-index: 5;
    padding: 0 4px;
    
    /* Oculto por defecto */
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
}

.fk-clear-btn.visible {
    opacity: 1;
    pointer-events: auto;
    cursor: pointer;
}

/* El dropdown con el estilo inspirado en tu context-menu */
.fk-dropdown {
    position: absolute;
    top: calc(100% + 4px); /* Separado ligeramente del input */
    left: 0;
    right: 0; /* Ocupa el ancho del input */
    background: #ffffff; /* o var(--bs-body-bg) */
    border: 1px solid rgba(0,0,0,0.15);
    border-radius: 0.375rem;
    box-shadow: 0 0.5rem 1rem rgba(0,0,0,0.15);
    max-height: 250px;
    overflow-y: auto;
    z-index: 1050;
    margin: 0;
    padding: 0.25rem 0;
    
    /* Oculto por defecto con transición */
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transform: translateY(-10px);
    transition: all 0.2s ease;
}

.fk-dropdown.visible {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transform: translateY(0);
}

/* Los items (botones) dentro del dropdown */
.fk-dropdown-item {
    display: block;
    width: 100%;
    padding: 0.5rem 1rem;
    text-align: left;
    background: transparent;
    border: none;
    font-size: 0.95rem;
    cursor: pointer;
    border-bottom: 1px solid #f8f9fa; /* Separador sutil */
    transition: background-color 0.15s ease;
}

.fk-dropdown-item:last-child {
    border-bottom: none;
}

.fk-dropdown-item:hover,
.fk-dropdown-item:focus {
    background-color: #f8f9fa; /* o var(--bs-tertiary-bg) */
    outline: none;
}

fk-dropdown { display: none; }
.fk-clear-btn { display: none; }

/* Estado: Tiene Valor */
.fk-wrap.has-value .fk-clear-btn { display: block; }

/* Estado: Abierto */
.fk-wrap.is-open fk-dropdown { display: block; }

.row{
	display:flex;
}
.row-icon{
	width:var(--icon-size);
	height:var(--icon-size);
	flex-shrink: 0;
	display: flex;align-items: center;justify-content: center;
}

.row-text{
	display: flex;flex-direction: column;
	flex-grow: 2;justify-content: center;
}




/* ==========================================================================
   2. CAPA DE TEMAS (themes.css)
   Contiene el diseño Retro clásico (manteniendo lo anterior)
   y el diseño Modernizado (contemporáneo, espaciado generoso y estilizado)
   ========================================================================== */

/* ==========================================================================
   TEMA: RETRO (El diseño clásico basado en ventanas OS antiguo)
   ========================================================================== */
body[data-theme="retro"] {
  /* Tipografía clásica */
  --font-main: 'Geneva', 'Segoe UI', Tahoma, sans-serif;
  --font-size-sm: 11px;
  --font-size-md: 12px;
  --font-size-lg: 13px;

  /* Espaciado compacto original */
  --space-xs:  4px;
  --space-sm:  8px;
  --space-md:  12px;
  --space-lg:  16px;

  /* Geometría rígida de la época */
  --radius: 2px;
  --radius-lg: 4px;
  --h-title:   24px;
  --h-menubar: 28px;
  
  /* Paleta clásica grisácea */
  --c-bg:             #e4e6e8;
  --c-bg-dot:         #c8cdd2;
  --c-surface:        #f8f9fa;
  --c-surface-alt:    #ebeef0;
  --c-surface-hover:  rgba(122, 139, 161, 0.12);
  --c-menubar-bg:     #f0f2f4;

  --c-border:         #9aa2ac;
  --c-border-light:   #d1d5da;
  --c-border-focus:   #778088;
  --c-border-table:   #e2e5e8;

  --c-text-main:      #444444;
  --c-text-muted:     #888888;
  --c-text-inverse:   #ffffff;

  --c-accent:         #7a8ba1;
  --c-accent-hover:   #6a798d;
  --c-accent-text:    #ffffff;
  --c-danger:         #d97b7b;
  --c-danger-border:  #c96a6a;
  --c-warning:        #d4b872;
  --c-warning-border: #c4a55d;
  --c-success:        #82b382;
  --c-success-border: #6b9e6b;
  
  --c-scrollbar:       #cfd4d8;
  --c-scrollbar-hover: #b8bec4;
  --c-tree-sel-bg:     rgba(59, 130, 246, 0.15);
  --c-tree-sel-color:  #3b82f6;
  --c-shortcut-hover:  rgba(255, 255, 255, 0.2);
  --c-shortcut-border: rgba(255, 255, 255, 0.4);

  /* Efectos visuales retro */
  --shadow-inset:      0 1px 0 rgba(255, 255, 255, 0.8) inset;
  --shadow-win:        3px 3px 0 rgba(154, 162, 172, 0.4);
  --shadow-win-blur:   2px 2px 0 rgba(154, 162, 172, 0.2);
  --shadow-text:       0 1px 0 rgba(255, 255, 255, 0.5);
  --stripe-pattern:    repeating-linear-gradient(to right, #e0e3e6 0, #e0e3e6 1px, #f8f9fa 1px, #f8f9fa 3px);
  --win-border:        1px solid var(--c-border);
}


/* ==========================================================================
   TEMA: MODERN (Rediseño contemporáneo, limpio, suave y con botones grandes)
   ========================================================================== */
body[data-theme="modern"] {
  /* Tipografía moderna y limpia */
  --font-main: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-size-sm: 12px;
  --font-size-md: 14px;
  --font-size-lg: 16px;

  /* Espaciado generoso (Botones y controles más grandes y cómodos) */
  --space-xs:  6px;
  --space-sm:  10px;
  --space-md:  16px;
  --space-lg:  24px;

  /* Bordes notablemente redondeados */
  --radius: 8px;
  --radius-lg: 12px;
  
  /* Dimensiones ampliadas para look actual */
  --h-title:   36px;
  --h-menubar: 44px;

  /* Paleta moderna basada en Slate/Indigo de alta fidelidad */
  --c-bg:             #f1f5f9; /* Slate 100 */
  --c-bg-dot:         #cbd5e1; /* Slate 300 */
  --c-surface:        #ffffff;
  --c-surface-alt:    #f8fafc; /* Slate 50 */
  --c-surface-hover:  #f1f5f9; /* Slate 100 */
  --c-menubar-bg:     #ffffff;

  --c-border:         #e2e8f0; /* Slate 200 */
  --c-border-light:   #f1f5f9;
  --c-border-focus:   #6366f1; /* Indigo 500 */
  --c-border-table:   #f1f5f9;

  --c-text-main:      #0f172a; /* Slate 900 */
  --c-text-muted:     #64748b; /* Slate 500 */
  --c-text-inverse:   #ffffff;

  /* Acentuación Semántica */
  --c-accent:         #6366f1; /* Indigo 500 */
  --c-accent-hover:   #4f46e5; /* Indigo 600 */
  --c-accent-text:    #ffffff;
  --c-danger:         #ef4444; /* Red 500 */
  --c-danger-border:  #dc2626;
  --c-warning:        #f59e0b; /* Amber 500 */
  --c-warning-border: #d97706;
  --c-success:        #10b981; /* Emerald 500 */
  --c-success-border: #059669;
  
  --c-scrollbar:       #cbd5e1;
  --c-scrollbar-hover: #94a3b8;
  --c-tree-sel-bg:     #eef2ff; /* Indigo 50 */
  --c-tree-sel-color:  #4f46e5;
  --c-shortcut-hover:  rgba(99, 102, 241, 0.08);
  --c-shortcut-border: rgba(99, 102, 241, 0.2);

  /* Sombras suaves de profundidad, eliminando patrones rígidos */
  --shadow-inset:      transparent;
  --shadow-win:        0 10px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.1);
  --shadow-win-blur:   0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -2px rgba(0, 0, 0, 0.05);
  --shadow-text:       transparent;
  --stripe-pattern:    transparent; /* Sin rallas en títulos modernos */
  --win-border:        1px solid var(--c-border);
}

/* Modificadores específicos para pulir la experiencia del tema Moderno */
body[data-theme="modern"] .win {
  transition: box-shadow 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}
body[data-theme="modern"] .win-title {
  padding: 0 var(--space-md);
}
body[data-theme="modern"] .win-title-text {
  border: none; /* Eliminar líneas divisorias rígidas retro */
}
body[data-theme="modern"] .win-btns {
  right: var(--space-sm); left: auto; /* Botones a la derecha al estilo moderno moderno */
}
body[data-theme="modern"] .win-btn {
  width: 16px; height: 16px; border-radius: 50%; /* Botones circulares modernos */
  border: none;
}
body[data-theme="modern"] .btn {
  font-weight: 500;
  transition: all 0.2s ease;
}
body[data-theme="modern"] .btn:hover {
  transform: translateY(-1px);
}
body[data-theme="modern"] ::webkit-scrollbar {
  width: 8px; height: 8px;
}
body[data-theme="modern"] ::webkit-scrollbar-track {
  background: transparent; border: none;
}
body[data-theme="modern"] ::webkit-scrollbar-thumb {
  background: var(--c-scrollbar); border-radius: 4px; border: none;
}


/* ==========================================================================
   TEMA: WINDOWS 11 (Diseño "Fluent", translúcido, sombras y animaciones)
   ========================================================================== */
body[data-theme="win11"] {
  /* Tipografía oficial de Windows */
  --font-main: 'Segoe UI Variable', 'Segoe UI', system-ui, sans-serif;
  --font-size-sm: 12px;
  --font-size-md: 14px;
  --font-size-lg: 16px;

  /* Espaciado más amplio y cómodo */
  --space-xs:  6px;
  --space-sm:  12px;
  --space-md:  16px;
  --space-lg:  24px;

  /* Bordes redondeados característicos de Win11 */
  --radius: 4px;
  --radius-lg: 8px;
  
  --h-title:   36px;
  --h-menubar: 48px;

  /* Paleta "Mica" (Modo claro translúcido) */
  --c-bg:             #f3f3f3;
  --c-bg-dot:         #e5e5e5;
  --c-surface:        rgba(255, 255, 255, 0.75); /* Translúcido para el blur */
  --c-surface-alt:    rgba(249, 249, 249, 0.5);
  --c-surface-hover:  rgba(0, 0, 0, 0.04);
  --c-menubar-bg:     rgba(243, 243, 243, 0.85);

  --c-border:         rgba(0, 0, 0, 0.1);
  --c-border-light:   rgba(0, 0, 0, 0.05);
  --c-border-focus:   #0067c0;
  --c-border-table:   rgba(0, 0, 0, 0.05);

  --c-text-main:      #202020;
  --c-text-muted:     #5d5d5d;
  --c-text-inverse:   #ffffff;

  /* Acento Windows (Azul clásico) */
  --c-accent:         #0067c0;
  --c-accent-hover:   #005a9e;
  --c-accent-text:    #ffffff;
  --c-danger:         #c42b1c;
  --c-danger-border:  #b3271a;
  
  /* Sombras de gran profundidad */
  --shadow-inset:      none;
  --shadow-win:        0 12px 32px rgba(0, 0, 0, 0.15), 0 0 0 1px rgba(0, 0, 0, 0.05);
  --shadow-win-blur:   0 4px 16px rgba(0, 0, 0, 0.1), 0 0 0 1px rgba(0, 0, 0, 0.05);
  --shadow-text:       none;
  --stripe-pattern:    transparent;
  --win-border:        1px solid transparent;
}

/* --- EFECTOS "MICA" (Desenfocado de fondo) --- */
body[data-theme="win11"] #menubar,
body[data-theme="win11"] .win {
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
}

/* --- VENTANAS Y ANIMACIONES --- */
body[data-theme="win11"] .win {
  border-radius: var(--radius-lg);
  /* Animación de entrada suave (escala + opacidad) */
 /* animation: win11Open 0.25s cubic-bezier(0, 0, 0, 1) forwards;*/
  transform-origin: center center;
}

@keyframes win11Open {
  0% { transform: scale(0.92); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

/* Transiciones al mover o hacer focus */
body[data-theme="win11"] .win.focused {
  transition: box-shadow 0.2s ease;
}

/* --- BARRA DE TÍTULO --- */
body[data-theme="win11"] .win-title {
  background: transparent;
  border-bottom: none;
  padding: 0 var(--space-md);
}
body[data-theme="win11"] .win-title-text {
  background: transparent;
  border: none;
  font-weight: 600;
  font-size: 13px; /* Título un poco más discreto */
}

/* --- BOTONES DE CONTROL (A la derecha, estilo Win11) --- */
body[data-theme="win11"] .win-btns {
  right: 0; 
  left: auto; /* Anula el left del layout base */
  top: 0;
  height: 100%;
  gap: 0;
}
body[data-theme="win11"] .win-btn {
  width: 46px; /* Ancho estándar de Win11 */
  height: 100%;
  border-radius: 0;
  border: none;
  background: transparent;
  color: var(--c-text-main);
  box-shadow: none;
  font-size: 10px;
}
/* Hovers específicos de Windows */
body[data-theme="win11"] .win-btn.min:hover,
body[data-theme="win11"] .win-btn.max:hover { 
  background: rgba(0, 0, 0, 0.06); 
  color: var(--c-text-main); 
}
body[data-theme="win11"] .win-btn.close:hover { 
  background: #e81123; 
  color: white; 
}
/* Bordes superiores derechos redondeados para el botón de cerrar */
body[data-theme="win11"] .win-btn.close {
  border-top-right-radius: var(--radius-lg);
}
body[data-theme="win11"] .win.maximized .win-btn.close {
  border-top-right-radius: 0;
}

/* --- BOTONES INTERNOS --- */
body[data-theme="win11"] .btn {
  border-radius: var(--radius);
  border: 1px solid rgba(0,0,0,0.1);
  background: rgba(255,255,255,0.7);
  transition: all 0.15s ease;
}
body[data-theme="win11"] .btn:hover {
  background: rgba(250,250,250,0.9);
  box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}
body[data-theme="win11"] .btn.primary {
  background: var(--c-accent);
  border-color: transparent;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.2);
}
body[data-theme="win11"] .btn.primary:hover {
  background: var(--c-accent-hover);
}

/* --- SCROLLBARS ESTILO WIN11 (Finas y superpuestas) --- */
body[data-theme="win11"] ::-webkit-scrollbar {
  width: 14px; 
  height: 14px;
}
body[data-theme="win11"] ::-webkit-scrollbar-track {
  background: transparent;
  border: none;
}
body[data-theme="win11"] ::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.2);
  border: 4px solid rgba(255, 255, 255, 0); /* Truco para hacerla parecer más fina */
  background-clip: padding-box;
  border-radius: 99px;
}
body[data-theme="win11"] ::-webkit-scrollbar-thumb:hover {
  background: rgba(0, 0, 0, 0.4);
  border: 4px solid rgba(255, 255, 255, 0);
  background-clip: padding-box;
}


