/* ============================================================
   iEntopWEB - Sistema de Temas y Estilos
   Paletas intercambiables via CSS Variables + Tailwind
   ============================================================ */

/* ---------- Root: Indigo Deep (Default / Dark) ---------- */
:root,
[data-theme="indigo-deep"] {
  --color-bg-primary: #0f172a;
  /* slate-900 */
  --color-bg-secondary: #1e293b;
  /* slate-800 */
  --color-bg-sidebar: #0c1222;
  --color-bg-header: #1e293b;
  --color-bg-card: #1e293b;
  --color-bg-input: #334155;
  /* slate-700 */
  --color-bg-hover: #334155;

  --color-text-primary: #f1f5f9;
  /* slate-100 */
  --color-text-secondary: #94a3b8;
  /* slate-400 */
  --color-text-muted: #64748b;
  /* slate-500 */
  --color-text-accent: #818cf8;
  /* indigo-400 */

  --color-accent: #6366f1;
  /* indigo-500 */
  --color-accent-hover: #818cf8;
  /* indigo-400 */
  --color-accent-subtle: rgba(99, 102, 241, 0.15);

  --color-border: #334155;
  /* slate-700 */
  --color-border-focus: #6366f1;

  --color-success: #22c55e;
  --color-warning: #f59e0b;
  --color-danger: #ef4444;

  --shadow-card: 0 1px 3px rgba(0, 0, 0, 0.4);
  --radius: 0.5rem;
  --transition: all 0.2s ease;
}

/* ---------- Indigo Light ---------- */
[data-theme="indigo-light"] {
  --color-bg-primary: #f8fafc;
  --color-bg-secondary: #ffffff;
  --color-bg-sidebar: #eef2ff;
  --color-bg-header: #ffffff;
  --color-bg-card: #ffffff;
  --color-bg-input: #f1f5f9;
  --color-bg-hover: #e2e8f0;

  --color-text-primary: #1e293b;
  --color-text-secondary: #475569;
  --color-text-muted: #94a3b8;
  --color-text-accent: #4f46e5;

  --color-accent: #4f46e5;
  --color-accent-hover: #6366f1;
  --color-accent-subtle: rgba(79, 70, 229, 0.08);

  --color-border: #e2e8f0;
  --color-border-focus: #4f46e5;

  --shadow-card: 0 1px 3px rgba(0, 0, 0, 0.08);
}

/* ---------- Emerald Dark ---------- */
[data-theme="emerald-dark"] {
  --color-bg-primary: #0a1612;
  --color-bg-secondary: #14231d;
  --color-bg-sidebar: #081210;
  --color-bg-header: #14231d;
  --color-bg-card: #14231d;
  --color-bg-input: #1f3a30;
  --color-bg-hover: #1f3a30;

  --color-text-primary: #ecfdf5;
  --color-text-secondary: #86efac;
  --color-text-muted: #4ade80;
  --color-text-accent: #34d399;

  --color-accent: #10b981;
  --color-accent-hover: #34d399;
  --color-accent-subtle: rgba(16, 185, 129, 0.15);

  --color-border: #1f3a30;
  --color-border-focus: #10b981;

  --shadow-card: 0 1px 3px rgba(0, 0, 0, 0.5);
}

/* ---------- Amber Warm ---------- */
[data-theme="amber-warm"] {
  --color-bg-primary: #fffbeb;
  --color-bg-secondary: #ffffff;
  --color-bg-sidebar: #fef3c7;
  --color-bg-header: #ffffff;
  --color-bg-card: #ffffff;
  --color-bg-input: #fef9ee;
  --color-bg-hover: #fde68a;

  --color-text-primary: #451a03;
  --color-text-secondary: #78350f;
  --color-text-muted: #92400e;
  --color-text-accent: #d97706;

  --color-accent: #f59e0b;
  --color-accent-hover: #d97706;
  --color-accent-subtle: rgba(245, 158, 11, 0.1);

  --color-border: #fde68a;
  --color-border-focus: #f59e0b;

  --shadow-card: 0 1px 3px rgba(0, 0, 0, 0.06);
}

/* ---------- Slate Neutral ---------- */
[data-theme="slate-neutral"] {
  --color-bg-primary: #111827;
  --color-bg-secondary: #1f2937;
  --color-bg-sidebar: #0d1320;
  --color-bg-header: #1f2937;
  --color-bg-card: #1f2937;
  --color-bg-input: #374151;
  --color-bg-hover: #374151;

  --color-text-primary: #f9fafb;
  --color-text-secondary: #9ca3af;
  --color-text-muted: #6b7280;
  --color-text-accent: #60a5fa;

  --color-accent: #3b82f6;
  --color-accent-hover: #60a5fa;
  --color-accent-subtle: rgba(59, 130, 246, 0.15);

  --color-border: #374151;
  --color-border-focus: #3b82f6;

  --shadow-card: 0 1px 3px rgba(0, 0, 0, 0.4);
}

/* ---------- Emerald Light ---------- */
[data-theme="emerald-light"] {
  --color-bg-primary: #f0fdf4;
  --color-bg-secondary: #ffffff;
  --color-bg-sidebar: #dcfce7;
  --color-bg-header: #ffffff;
  --color-bg-card: #ffffff;
  --color-bg-input: #f0fdf4;
  --color-bg-hover: #bbf7d0;

  --color-text-primary: #14532d;
  --color-text-secondary: #166534;
  --color-text-muted: #4ade80;
  --color-text-accent: #059669;

  --color-accent: #10b981;
  --color-accent-hover: #059669;
  --color-accent-subtle: rgba(16, 185, 129, 0.08);

  --color-border: #bbf7d0;
  --color-border-focus: #10b981;

  --shadow-card: 0 1px 3px rgba(0, 0, 0, 0.06);
}

/* ---------- Rose Dark ---------- */
[data-theme="rose-dark"] {
  --color-bg-primary: #1a0a10;
  --color-bg-secondary: #2a1520;
  --color-bg-sidebar: #14080c;
  --color-bg-header: #2a1520;
  --color-bg-card: #2a1520;
  --color-bg-input: #3d1f2e;
  --color-bg-hover: #3d1f2e;

  --color-text-primary: #fff1f2;
  --color-text-secondary: #fda4af;
  --color-text-muted: #fb7185;
  --color-text-accent: #fb7185;

  --color-accent: #f43f5e;
  --color-accent-hover: #fb7185;
  --color-accent-subtle: rgba(244, 63, 94, 0.15);

  --color-border: #3d1f2e;
  --color-border-focus: #f43f5e;

  --color-success: #22c55e;
  --color-warning: #f59e0b;
  --color-danger: #ef4444;

  --shadow-card: 0 1px 3px rgba(0, 0, 0, 0.5);
}

/* ---------- Rose Light ---------- */
[data-theme="rose-light"] {
  --color-bg-primary: #fff1f2;
  --color-bg-secondary: #ffffff;
  --color-bg-sidebar: #ffe4e6;
  --color-bg-header: #ffffff;
  --color-bg-card: #ffffff;
  --color-bg-input: #fff1f2;
  --color-bg-hover: #fecdd3;

  --color-text-primary: #4c0519;
  --color-text-secondary: #881337;
  --color-text-muted: #fb7185;
  --color-text-accent: #e11d48;

  --color-accent: #f43f5e;
  --color-accent-hover: #e11d48;
  --color-accent-subtle: rgba(244, 63, 94, 0.08);

  --color-border: #fecdd3;
  --color-border-focus: #f43f5e;

  --shadow-card: 0 1px 3px rgba(0, 0, 0, 0.06);
}

/* ---------- Sky Dark ---------- */
[data-theme="sky-dark"] {
  --color-bg-primary: #0a1628;
  --color-bg-secondary: #0f2240;
  --color-bg-sidebar: #071020;
  --color-bg-header: #0f2240;
  --color-bg-card: #0f2240;
  --color-bg-input: #183058;
  --color-bg-hover: #183058;

  --color-text-primary: #e0f2fe;
  --color-text-secondary: #7dd3fc;
  --color-text-muted: #38bdf8;
  --color-text-accent: #38bdf8;

  --color-accent: #0ea5e9;
  --color-accent-hover: #38bdf8;
  --color-accent-subtle: rgba(14, 165, 233, 0.15);

  --color-border: #183058;
  --color-border-focus: #0ea5e9;

  --color-success: #22c55e;
  --color-warning: #f59e0b;
  --color-danger: #ef4444;

  --shadow-card: 0 1px 3px rgba(0, 0, 0, 0.5);
}

/* ---------- Sky Light ---------- */
[data-theme="sky-light"] {
  --color-bg-primary: #f0f9ff;
  --color-bg-secondary: #ffffff;
  --color-bg-sidebar: #e0f2fe;
  --color-bg-header: #ffffff;
  --color-bg-card: #ffffff;
  --color-bg-input: #f0f9ff;
  --color-bg-hover: #bae6fd;

  --color-text-primary: #0c4a6e;
  --color-text-secondary: #075985;
  --color-text-muted: #38bdf8;
  --color-text-accent: #0284c7;

  --color-accent: #0ea5e9;
  --color-accent-hover: #0284c7;
  --color-accent-subtle: rgba(14, 165, 233, 0.08);

  --color-border: #bae6fd;
  --color-border-focus: #0ea5e9;

  --shadow-card: 0 1px 3px rgba(0, 0, 0, 0.06);
}
/* =================================================================
   iEnTop Custom Themes — Paletas extraídas de capturas 02/04/2026
   ================================================================= */

/* ---------- iEnTop Dark (WebDev 2025 Dark inspired) ---------- */
[data-theme="ientop-dark"] {
  /* Backgrounds — IDE oscuro tipo #1e1e1e WebDev */
  --color-bg-primary:    #1e1e1e;
  --color-bg-secondary:  #252526;
  --color-bg-sidebar:    #1b1b1c;
  --color-bg-header:     #2d2d30;
  --color-bg-card:       #2d2d30;
  --color-bg-input:      #3c3c3c;
  --color-bg-hover:      #37373d;

  /* Texto */
  --color-text-primary:   #d4d4d4;
  --color-text-secondary: #a0a0a0;
  --color-text-muted:     #6e6e6e;
  --color-text-accent:    #60a5fa;  /* azul eléctrico claro */

  /* Acento: Azul Eléctrico */
  --color-accent:        #3b82f6;
  --color-accent-hover:  #2563eb;
  --color-accent-subtle: rgba(59, 130, 246, 0.12);

  /* Acento secundario: Naranja (badges, alertas) */
  --color-secondary-accent: #f39c12;

  /* Bordes */
  --color-border:       #3e3e42;
  --color-border-focus: #3b82f6;

  /* Estado */
  --color-success: #6db56d;
  --color-warning: #f39c12;
  --color-danger:  #f48771;

  --shadow-card:  0 1px 4px rgba(0, 0, 0, 0.5);
  --radius:       0.5rem;
  --transition:   all 0.2s ease;
  color-scheme: dark;
}

/* ---------- iEnTop Grey (WebDev Light / Silver) ---------- */
[data-theme="ientop-grey"] {
  /* Backgrounds — Grises medios */
  --color-bg-primary:    #c8c8c8;
  --color-bg-secondary:  #d4d4d4;
  --color-bg-sidebar:    #bdbdbd;
  --color-bg-header:     #e0e0e0;
  --color-bg-card:       #e8e8e8;
  --color-bg-input:      #ececec;
  --color-bg-hover:      #b8b8b8;

  /* Texto */
  --color-text-primary:   #1a1a1a;
  --color-text-secondary: #3c3c3c;
  --color-text-muted:     #666666;
  --color-text-accent:    #2a2a2a;  /* gris muy oscuro */

  /* Acento: gris muy oscuro (más oscuro que Light, máximo contraste sobre fondo gris medio) */
  --color-accent:        #333333;
  --color-accent-hover:  #111111;
  --color-accent-subtle: rgba(51, 51, 51, 0.12);

  /* Acento secundario: Naranja */
  --color-secondary-accent: #e8860e;

  /* Bordes */
  --color-border:       #a8a8a8;
  --color-border-focus: #333333;

  /* Estado */
  --color-success: #2e7d32;
  --color-warning: #e8860e;
  --color-danger:  #c62828;

  --shadow-card:  0 1px 3px rgba(0, 0, 0, 0.15);
  --radius:       0.5rem;
  --transition:   all 0.2s ease;
  color-scheme: light;
}

/* ---------- iEnTop Light (Blanco puro / Crema) ---------- */
[data-theme="ientop-light"] {
  /* Backgrounds — Blancos y cremas */
  --color-bg-primary:    #f4f4f4;
  --color-bg-secondary:  #ffffff;
  --color-bg-sidebar:    #efefef;
  --color-bg-header:     #ffffff;
  --color-bg-card:       #ffffff;
  --color-bg-input:      #f9f9f9;
  --color-bg-hover:      #e8e8e8;

  /* Texto */
  --color-text-primary:   #111111;
  --color-text-secondary: #3a3a3a;
  --color-text-muted:     #888888;
  --color-text-accent:    #444444;  /* gris oscuro */

  /* Acento: gris oscuro (contraste sobre fondo blanco) */
  --color-accent:        #555555;
  --color-accent-hover:  #333333;
  --color-accent-subtle: rgba(85, 85, 85, 0.09);

  /* Acento secundario: Naranja */
  --color-secondary-accent: #f39c12;

  /* Bordes */
  --color-border:       #dddddd;
  --color-border-focus: #555555;

  /* Estado */
  --color-success: #2e7d32;
  --color-warning: #f39c12;
  --color-danger:  #c62828;

  --shadow-card:  0 1px 3px rgba(0, 0, 0, 0.08);
  --radius:       0.5rem;
  --transition:   all 0.2s ease;
  color-scheme: light;
}

/* =================================================================
   Extended Themes - Premium Palettes (Apr 2026)
   ================================================================= */

/* ---------- Midnight Blue ---------- */
[data-theme="midnight-blue"] {
  --color-bg-primary: #0b1426; --color-bg-secondary: #131f3a; --color-bg-sidebar: #081020;
  --color-bg-header: #131f3a; --color-bg-card: #131f3a; --color-bg-input: #1c2d4f; --color-bg-hover: #1c2d4f;
  --color-text-primary: #e2e8f0; --color-text-secondary: #93c5fd; --color-text-muted: #60a5fa; --color-text-accent: #60a5fa;
  --color-accent: #3b82f6; --color-accent-hover: #60a5fa; --color-accent-subtle: rgba(59, 130, 246, 0.15);
  --color-border: #1c2d4f; --color-border-focus: #3b82f6;
  --color-success: #22c55e; --color-warning: #f59e0b; --color-danger: #ef4444;
  --shadow-card: 0 1px 3px rgba(0, 0, 0, 0.5); --radius: 0.5rem; --transition: all 0.2s ease; color-scheme: dark;
}

/* ---------- Slate Noir ---------- */
[data-theme="slate-noir"] {
  --color-bg-primary: #18181b; --color-bg-secondary: #27272a; --color-bg-sidebar: #141416;
  --color-bg-header: #27272a; --color-bg-card: #27272a; --color-bg-input: #3f3f46; --color-bg-hover: #3f3f46;
  --color-text-primary: #fafafa; --color-text-secondary: #a1a1aa; --color-text-muted: #71717a; --color-text-accent: #a1a1aa;
  --color-accent: #71717a; --color-accent-hover: #a1a1aa; --color-accent-subtle: rgba(113, 113, 122, 0.15);
  --color-border: #3f3f46; --color-border-focus: #a1a1aa;
  --color-success: #22c55e; --color-warning: #f59e0b; --color-danger: #ef4444;
  --shadow-card: 0 1px 3px rgba(0, 0, 0, 0.5); --radius: 0.5rem; --transition: all 0.2s ease; color-scheme: dark;
}

/* ---------- Ocean Teal ---------- */
[data-theme="ocean-teal"] {
  --color-bg-primary: #0a1418; --color-bg-secondary: #122128; --color-bg-sidebar: #071012;
  --color-bg-header: #122128; --color-bg-card: #122128; --color-bg-input: #1a3240; --color-bg-hover: #1a3240;
  --color-text-primary: #ecfeff; --color-text-secondary: #5eead4; --color-text-muted: #2dd4bf; --color-text-accent: #2dd4bf;
  --color-accent: #14b8a6; --color-accent-hover: #2dd4bf; --color-accent-subtle: rgba(20, 184, 166, 0.15);
  --color-border: #1a3240; --color-border-focus: #14b8a6;
  --color-success: #22c55e; --color-warning: #f59e0b; --color-danger: #ef4444;
  --shadow-card: 0 1px 3px rgba(0, 0, 0, 0.5); --radius: 0.5rem; --transition: all 0.2s ease; color-scheme: dark;
}

/* ---------- Forest Green ---------- */
[data-theme="forest-green"] {
  --color-bg-primary: #0a140a; --color-bg-secondary: #132213; --color-bg-sidebar: #060e06;
  --color-bg-header: #132213; --color-bg-card: #132213; --color-bg-input: #1e3a1e; --color-bg-hover: #1e3a1e;
  --color-text-primary: #f0fdf4; --color-text-secondary: #86efac; --color-text-muted: #4ade80; --color-text-accent: #4ade80;
  --color-accent: #22c55e; --color-accent-hover: #4ade80; --color-accent-subtle: rgba(34, 197, 94, 0.15);
  --color-border: #1e3a1e; --color-border-focus: #22c55e;
  --color-success: #22c55e; --color-warning: #f59e0b; --color-danger: #ef4444;
  --shadow-card: 0 1px 3px rgba(0, 0, 0, 0.5); --radius: 0.5rem; --transition: all 0.2s ease; color-scheme: dark;
}

/* ---------- Royal Purple ---------- */
[data-theme="royal-purple"] {
  --color-bg-primary: #120c1e; --color-bg-secondary: #1e1530; --color-bg-sidebar: #0e0918;
  --color-bg-header: #1e1530; --color-bg-card: #1e1530; --color-bg-input: #2e2248; --color-bg-hover: #2e2248;
  --color-text-primary: #f5f3ff; --color-text-secondary: #c4b5fd; --color-text-muted: #a78bfa; --color-text-accent: #c084fc;
  --color-accent: #a855f7; --color-accent-hover: #c084fc; --color-accent-subtle: rgba(168, 85, 247, 0.15);
  --color-border: #2e2248; --color-border-focus: #a855f7;
  --color-success: #22c55e; --color-warning: #f59e0b; --color-danger: #ef4444;
  --shadow-card: 0 1px 3px rgba(0, 0, 0, 0.5); --radius: 0.5rem; --transition: all 0.2s ease; color-scheme: dark;
}

/* ---------- Warm Sunset ---------- */
[data-theme="warm-sunset"] {
  --color-bg-primary: #1c0f08; --color-bg-secondary: #2a1810; --color-bg-sidebar: #150b06;
  --color-bg-header: #2a1810; --color-bg-card: #2a1810; --color-bg-input: #3d2518; --color-bg-hover: #3d2518;
  --color-text-primary: #fff7ed; --color-text-secondary: #fdba74; --color-text-muted: #fb923c; --color-text-accent: #fb923c;
  --color-accent: #f97316; --color-accent-hover: #fb923c; --color-accent-subtle: rgba(249, 115, 22, 0.15);
  --color-border: #3d2518; --color-border-focus: #f97316;
  --color-success: #22c55e; --color-warning: #f59e0b; --color-danger: #ef4444;
  --shadow-card: 0 1px 3px rgba(0, 0, 0, 0.5); --radius: 0.5rem; --transition: all 0.2s ease; color-scheme: dark;
}

/* ---------- Crimson Dark ---------- */
[data-theme="crimson-dark"] {
  --color-bg-primary: #1a0808; --color-bg-secondary: #2a1212; --color-bg-sidebar: #140606;
  --color-bg-header: #2a1212; --color-bg-card: #2a1212; --color-bg-input: #3d1c1c; --color-bg-hover: #3d1c1c;
  --color-text-primary: #fef2f2; --color-text-secondary: #fca5a5; --color-text-muted: #f87171; --color-text-accent: #f87171;
  --color-accent: #ef4444; --color-accent-hover: #f87171; --color-accent-subtle: rgba(239, 68, 68, 0.15);
  --color-border: #3d1c1c; --color-border-focus: #ef4444;
  --color-success: #22c55e; --color-warning: #f59e0b; --color-danger: #ef4444;
  --shadow-card: 0 1px 3px rgba(0, 0, 0, 0.5); --radius: 0.5rem; --transition: all 0.2s ease; color-scheme: dark;
}

/* ---------- Arctic Frost ---------- */
[data-theme="arctic-frost"] {
  --color-bg-primary: #ecfeff; --color-bg-secondary: #ffffff; --color-bg-sidebar: #cffafe;
  --color-bg-header: #ffffff; --color-bg-card: #ffffff; --color-bg-input: #ecfeff; --color-bg-hover: #a5f3fc;
  --color-text-primary: #164e63; --color-text-secondary: #0e7490; --color-text-muted: #22d3ee; --color-text-accent: #0891b2;
  --color-accent: #06b6d4; --color-accent-hover: #0891b2; --color-accent-subtle: rgba(6, 182, 212, 0.08);
  --color-border: #a5f3fc; --color-border-focus: #06b6d4;
  --color-success: #22c55e; --color-warning: #f59e0b; --color-danger: #ef4444;
  --shadow-card: 0 1px 3px rgba(0, 0, 0, 0.06); --radius: 0.5rem; --transition: all 0.2s ease; color-scheme: light;
}

/* ---------- Amber Glow ---------- */
[data-theme="amber-glow"] {
  --color-bg-primary: #1c1408; --color-bg-secondary: #2a2010; --color-bg-sidebar: #151006;
  --color-bg-header: #2a2010; --color-bg-card: #2a2010; --color-bg-input: #3d3018; --color-bg-hover: #3d3018;
  --color-text-primary: #fffbeb; --color-text-secondary: #fcd34d; --color-text-muted: #fbbf24; --color-text-accent: #fbbf24;
  --color-accent: #f59e0b; --color-accent-hover: #fbbf24; --color-accent-subtle: rgba(245, 158, 11, 0.15);
  --color-border: #3d3018; --color-border-focus: #f59e0b;
  --color-success: #22c55e; --color-warning: #f59e0b; --color-danger: #ef4444;
  --shadow-card: 0 1px 3px rgba(0, 0, 0, 0.5); --radius: 0.5rem; --transition: all 0.2s ease; color-scheme: dark;
}

/* ---------- Rose Gold ---------- */
[data-theme="rose-gold"] {
  --color-bg-primary: #fdf2f8; --color-bg-secondary: #ffffff; --color-bg-sidebar: #fce7f3;
  --color-bg-header: #ffffff; --color-bg-card: #ffffff; --color-bg-input: #fdf2f8; --color-bg-hover: #fbcfe8;
  --color-text-primary: #500724; --color-text-secondary: #9d174d; --color-text-muted: #f472b6; --color-text-accent: #db2777;
  --color-accent: #ec4899; --color-accent-hover: #db2777; --color-accent-subtle: rgba(236, 72, 153, 0.08);
  --color-border: #fbcfe8; --color-border-focus: #ec4899;
  --color-success: #22c55e; --color-warning: #f59e0b; --color-danger: #ef4444;
  --shadow-card: 0 1px 3px rgba(0, 0, 0, 0.06); --radius: 0.5rem; --transition: all 0.2s ease; color-scheme: light;
}

/* ---------- Carbon Light ---------- */
[data-theme="carbon-light"] {
  --color-bg-primary: #f4f4f5; --color-bg-secondary: #ffffff; --color-bg-sidebar: #e4e4e7;
  --color-bg-header: #ffffff; --color-bg-card: #ffffff; --color-bg-input: #f4f4f5; --color-bg-hover: #d4d4d8;
  --color-text-primary: #18181b; --color-text-secondary: #3f3f46; --color-text-muted: #a1a1aa; --color-text-accent: #4f46e5;
  --color-accent: #6366f1; --color-accent-hover: #4f46e5; --color-accent-subtle: rgba(99, 102, 241, 0.08);
  --color-border: #d4d4d8; --color-border-focus: #6366f1;
  --color-success: #22c55e; --color-warning: #f59e0b; --color-danger: #ef4444;
  --shadow-card: 0 1px 3px rgba(0, 0, 0, 0.08); --radius: 0.5rem; --transition: all 0.2s ease; color-scheme: light;
}

/* ---------- Graphite Pro ---------- */
[data-theme="graphite-pro"] {
  --color-bg-primary: #1e2024; --color-bg-secondary: #26282e; --color-bg-sidebar: #181a1e;
  --color-bg-header: #26282e; --color-bg-card: #26282e; --color-bg-input: #33363d; --color-bg-hover: #33363d;
  --color-text-primary: #e4e4e7; --color-text-secondary: #a1a1aa; --color-text-muted: #71717a; --color-text-accent: #a1a1aa;
  --color-accent: #52525b; --color-accent-hover: #71717a; --color-accent-subtle: rgba(82, 82, 91, 0.2);
  --color-border: #33363d; --color-border-focus: #71717a;
  --color-success: #22c55e; --color-warning: #f59e0b; --color-danger: #ef4444;
  --shadow-card: 0 1px 3px rgba(0, 0, 0, 0.5); --radius: 0.5rem; --transition: all 0.2s ease; color-scheme: dark;
}

/* ============================================================
   Base Styles
   ============================================================ */

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* La altura del shell nace en html y baja por PORCENTAJES, nunca por unidades
   de viewport. El body lleva zoom (navigation.js aplica la preferencia
   'ientop-zoom', 50%-150%) y vh/vw NO se escalan con el zoom: con zoom 0.9 un
   100vh/100vw se pinta al 90% del viewport (franja muerta a la derecha y
   abajo) y con 1.25 se sale de la pantalla. Un 100% contra html llena el
   viewport a cualquier zoom. Medido el 02-09-2026 con la plantilla real del
   shell en 0.9 / 1.0 / 1.25. */
html {
  height: 100%;
}

body {
  font-family: 'Inter', 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--color-bg-primary);
  color: var(--color-text-primary);
  transition: var(--transition);
  height: 100%;
  overflow: hidden;
}

/* ── Listas: fondo alterno de las filas (REGLA GENERAL, 10-10-2026) ──────────
   Pedido del usuario: todas las listas con las filas alternas, como los apuntes
   de los asientos del Diario. Vive solo aquí: este fichero lo cargan los cinco
   ERP (los verticales lo toman del base), el portal de Fichajes y AdminGlobalAccess.
   - El tono sale del texto principal del tema al 6 %: oscurece en los temas
     claros y aclara en los oscuros (medido en los 28: contraste entre filas de
     1,10 a 1,19 y el texto encima, de 8,1:1 o más). --color-bg-secondary no
     sirve: es igual que --color-bg-card en 26 de los 28 temas.
   - Especificidad CERO (:where): el fondo que una lista ponga a sus filas
     (seleccionada, :hover, totales, estados) manda sobre la franja.
   - Fuera: tablas con .cps-sin-cebra, el calendario (FullCalendar, .fc) y lo que
     edita el usuario (Jodit y [contenteditable]).
   Para pintar la franja en una lista que no es una tabla: var(--color-row-alt). */
:root {
  --color-row-alt: color-mix(in srgb, var(--color-text-primary) 6%, transparent);
}

:where(table:not(.cps-sin-cebra, .fc table, .jodit table, [contenteditable] table) > tbody > tr:nth-child(even)) {
  background-color: var(--color-row-alt);
}

/* ============================================================
   App Shell (Main Layout)
   Structure: Header (Top) + AppBody [Sidebar | Content]
   ============================================================ */
.app-shell {
  display: flex;
  /* 100% del body, NO 100vw/100vh (ver la nota de html/body arriba). Hasta el
     01-09-2026 este bloque lo pisaba la regla body>div{width/height:100%
     !important} de crm.css, que casaba con el propio .app-shell (TMS cuelga
     la plantilla del formulario directamente de body). Al acotarse esa regla
     al CRM standalone (Modulos ea06143) afloro el 100vw/100vh y aparecieron
     los margenes con zoom distinto de 1. position:relative conserva el
     contexto de posicionamiento que aquella regla le daba. */
  width: 100%;
  height: 100%;
  position: relative;
  background: var(--color-bg-primary);
  color: var(--color-text-primary);
  overflow: hidden;
  flex-direction: column;
  /* Header on top */
}

/* -- Header (Fixed Top) -- */
.header {
  height: 60px;
  /* or auto min-height */
  background: var(--color-bg-card);
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  padding: 0 1rem;
  gap: 1rem;
  flex-shrink: 0;
  z-index: 1000000 !important;
  position: relative !important;
  width: 100%;
}

/* -- App Body (Sidebar + Content) -- */
.app-body {
  display: flex;
  flex: 1;
  overflow: hidden;
  position: relative;
  z-index: 1 !important; /* Aísla los modulos para que nunca suban sobre el header */
  flex-direction: row;
}

/* -- Content Wrapper -- */
.content-wrapper {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
  background: var(--color-bg-primary);
  min-width: 0;
  /* Prevent flex overflow */
}

/* -- Content Host -- */
.content-host {
  flex: 1;
  overflow: auto;
  background: var(--color-bg-primary);
  position: relative;
}

#formarea {
  width: 100%;
  height: 100%;
  position: relative;
}

/* -- Sidebar Wrapper -- */
.sidebar-wrapper {
  display: flex;
  flex-direction: row;
  height: 100%;
  position: relative;
  z-index: 30;
  box-shadow: 1px 0 0 var(--color-border);
}

/* -- 1. Fixed Rail -- */
.sidebar-rail {
  width: 48px;
  background: var(--color-bg-sidebar);
  /* Or slightly darker if prefer */
  border-right: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0.5rem 0;
  gap: 0.5rem;
  flex-shrink: 0;
  z-index: 32;
}

.rail-btn {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-text-muted);
  background: transparent;
  border: none;
  border-radius: 0.375rem;
  cursor: pointer;
  transition: var(--transition);
}

.rail-btn:hover {
  background: var(--color-bg-hover);
  color: var(--color-text-primary);
}

.rail-btn svg {
  width: 20px;
  height: 20px;
}

.rail-shortcuts {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  padding-top: 1rem;
  border-top: 1px solid var(--color-border);
  margin-top: 0.5rem;
}
.rail-shortcuts::-webkit-scrollbar { display: none; }
.rail-shortcuts > .rail-btn { flex: 0 0 auto; }

.rail-footer {
  margin-top: auto;
  padding-top: 0.5rem;
  border-top: 1px solid var(--color-border);
  width: 100%;
  display: flex;
  justify-content: center;
}

.btn-danger-icon {
  color: var(--color-danger);
}

.btn-danger-icon:hover {
  background: rgba(239, 68, 68, 0.1);
}

/* -- 2. Collapsible Drawer -- */
.sidebar-drawer {
  width: fit-content;
  min-width: 200px;
  max-width: 380px;
  background: var(--color-bg-sidebar);
  border-right: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  transition: width 0.3s ease, min-width 0.3s ease, opacity 0.3s ease;
  overflow-y: auto;
  overflow-x: hidden;
  white-space: nowrap;
}

.sidebar-drawer.collapsed {
  width: 0;
  min-width: 0;
  opacity: 0;
  border-right: none;
}

.sidebar-logo {
  padding: 1rem 1rem;
  height: 52px;
  /* Match header height approx */
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-shrink: 0;
}

.sidebar-logo-icon {
  width: 28px;
  height: 28px;
  border-radius: 0.375rem;
  background: var(--color-accent);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.sidebar-logo-icon span {
  color: #fff;
  font-weight: 700;
  font-size: 0.8125rem;
}

.sidebar-logo h1 {
  font-size: 1rem;
  font-weight: 700;
  color: var(--color-text-accent);
  letter-spacing: -0.02em;
}

/* -- Search -- */
.sidebar-search {
  padding: 0.75rem 0.75rem;
  flex-shrink: 0;
}

.sidebar-search input {
  width: 100%;
  padding: 0.375rem 0.5rem 0.375rem 2rem;
  background: var(--color-bg-input);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  color: var(--color-text-primary);
  font-size: 0.8125rem;
  outline: none;
  transition: var(--transition);
}

.sidebar-search input:focus {
  border-color: var(--color-border-focus);
  box-shadow: 0 0 0 2px var(--color-accent-subtle);
}

.sidebar-search input::placeholder {
  color: var(--color-text-muted);
}

.sidebar-search .search-icon {
  position: absolute;
  left: 0.5rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--color-text-muted);
  pointer-events: none;
  width: 14px;
  height: 14px;
}

/* -- Menu Tree -- */
.menu-tree {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 0.5rem 0;
}

.menu-item {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  padding: 0.5rem 1rem 0.5rem 1.25rem;
  font-size: 0.8125rem;
  color: var(--color-text-secondary);
  cursor: pointer;
  transition: var(--transition);
  text-decoration: none;
  border-left: 2px solid transparent;
  user-select: none;
}

.menu-item:hover {
  background: var(--color-bg-hover);
  color: var(--color-text-primary);
}

.menu-item.active {
  background: var(--color-accent-subtle);
  color: var(--color-text-accent);
  border-left-color: var(--color-accent);
  font-weight: 500;
}

.menu-item .icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  opacity: 0.7;
}

.menu-item.active .icon {
  opacity: 1;
}

/* -- Main Content Area -- */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}

/* -- Header: Multi-Block Layout -- */
.header {
  background: var(--color-bg-header);
  border-bottom: 1px solid var(--color-border);
  padding: 0.5rem 1.5rem;
  /* More side padding */
  display: flex;
  align-items: stretch;
  gap: 0;
  flex-shrink: 0;
  z-index: 20;
  min-height: 80px;
  /* Increased from 68px */
}

/* ============================================================
   Header Elements
   ============================================================ */
.hdr-brand {
  display: flex;
  align-items: center;
  gap: 1rem;
  /* More gap */
  padding-right: 1rem;
}

.hdr-brand-icon {
  width: 48px;
  /* High & Square (was 36px) */
  height: 48px;
  border-radius: 0.75rem;
  /* Slightly more rounded */
  background: var(--color-accent);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: #fff;
  font-weight: 700;
  font-size: 1.25rem;
  /* Larger text */
}

.hdr-brand-title {
  font-size: 1.25rem;
  /* Larger title */
  font-weight: 700;
  color: var(--color-text-accent);
  letter-spacing: -0.02em;
  white-space: nowrap;
}

.hdr-block {
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 0 1rem;
  /* "Respirar" - More padding inside blocks */
  flex: 1;
  /* Repartir espacio */
}

/* Divider between blocks */
.hdr-divider {
  width: 1px;
  height: 48px;
  /* Taller divider for taller header */
  background: var(--color-border);
  margin: auto 0.5rem;
  /* Vertically centered */
}

/* -- Block 1: Company Info -- */
.hdr-company {
  flex: 1;
  /* Grow to share space */
  max-width: none;
  /* Remove constraint */
  gap: 0.25rem;
  padding-left: 1.5rem;
  /* More breathing room from divider */
  justify-content: center;
}

.hdr-company-row1 {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.hdr-company-logo {
  width: 40px;
  /* Slightly larger */
  height: 40px;
  border-radius: 0.375rem;
  object-fit: cover;
  flex-shrink: 0;
}

.hdr-company-name {
  font-weight: 700;
  font-size: 1rem;
  color: var(--color-text-primary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  white-space: nowrap;
  /* Limita ancho y corta con ellipsis: cuando no hay nombre_comercial el
     fallback usa la razon social, que en S.L./S.A./Cooperativas suele ser
     muy larga y, sin esto, se montaba sobre el botón "Asistente IA" a la
     derecha de la cabecera. JS aplica además un corte adicional para que
     el ellipsis no llegue a notarse en casos normales. */
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.hdr-company-meta {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  margin-left: 0.5rem;
}

.hdr-tag {
  font-size: 0.6875rem;
  color: var(--color-text-muted);
  background: var(--color-bg-input);
  padding: 0.125rem 0.5rem;
  border-radius: 0.25rem;
  font-weight: 500;
  letter-spacing: 0.02em;
}

.hdr-company-row2 {
  font-size: 0.75rem;
  color: var(--color-text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.hdr-company-row3 {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.75rem;
  color: var(--color-text-muted);
}

.hdr-user-icon {
  flex-shrink: 0;
  opacity: 0.6;
}

.hdr-date-sep {
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: var(--color-text-muted);
  opacity: 0.5;
}

.hdr-date {
  color: var(--color-text-secondary);
}

.hdr-year {
  font-size: 0.875rem;
  font-weight: 700;
  color: var(--color-text-primary);
}

/* Block 2: Quick Actions */
.hdr-actions {
  flex: 1;
  /* Share space */
  gap: 0.5rem;
  align-items: center;
  justify-content: center;
  /* Center content */
}

/* ... existing button styles ... */

.hdr-actions-buttons {
  display: flex;
  gap: 0.5rem;
}

/* ... existing btn internal style ... */

.hdr-theme-select {
  width: auto;
  /* Don't stretch */
  min-width: 140px;
  padding: 0.35rem 0.5rem;
  /* Taller input */
  /* ... */
}

/* ... existing activity ... */

/* Block 3: Active Module Context */
.hdr-context {
  flex: 1;
  gap: 0.25rem;
  align-items: flex-start;
  /* Align left */
  /* min-width removed or kept small */
  padding-left: 1.5rem;
}

.hdr-context-module {
  font-size: 0.875rem;
  /* ... */
}

/* Block 4: Extra Info */
.hdr-extra {
  flex: 0 0 auto;
  /* Keep compact or flex: 1? User said "repartirse el resto". But Extra usually is small */
  /* Let's make it flex: 1 but align right */
  flex: 1;
  align-items: flex-end;
  /* Align right side */
  gap: 0.25rem;
  padding-right: 0.5rem;
}


/* ============================================================
   Header Elements
   ============================================================ */
.hdr-brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding-right: 0.5rem;
}

.hdr-brand-icon {
  width: 36px;
  height: 36px;
  border-radius: 0.5rem;
  background: var(--color-accent);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: #fff;
  font-weight: 700;
  font-size: 1rem;
}

.hdr-brand-title {
  font-size: 1.125rem;
  font-weight: 700;
  color: var(--color-text-accent);
  letter-spacing: -0.02em;
  white-space: nowrap;
}

.hdr-block {
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 0 0.5rem;
}

/* Divider between blocks */
.hdr-divider {
  width: 1px;
  height: 32px;
  background: var(--color-border);
  margin: 0 0.5rem;
}

/* -- Block 1: Company Info -- */
.hdr-company {
  flex: 0 0 auto;
  max-width: 340px;
  gap: 0.125rem;
  padding-left: 0;
}

.hdr-company-row1 {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.hdr-company-logo {
  width: 32px;
  height: 32px;
  border-radius: 0.375rem;
  object-fit: cover;
  flex-shrink: 0;
}

.hdr-company-name {
  font-weight: 700;
  font-size: 0.9375rem;
  color: var(--color-text-primary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  white-space: nowrap;
  /* Misma red de seguridad de ellipsis que la primera regla (línea 958);
     ESTA es la que prevalece por cascada — sin estas 3 props, el nombre
     comercial largo (o el fallback de razón social) se monta sobre el botón
     Asistente IA. */
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.hdr-company-meta {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  margin-left: 0.25rem;
}

.hdr-tag {
  font-size: 0.625rem;
  color: var(--color-text-muted);
  background: var(--color-bg-input);
  padding: 0.0625rem 0.375rem;
  border-radius: 0.25rem;
  font-weight: 500;
  letter-spacing: 0.02em;
}

.hdr-company-row2 {
  font-size: 0.6875rem;
  color: var(--color-text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.hdr-company-row3 {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  font-size: 0.6875rem;
  color: var(--color-text-muted);
}

.hdr-user-icon {
  flex-shrink: 0;
  opacity: 0.6;
}

.hdr-date-sep {
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: var(--color-text-muted);
  opacity: 0.5;
}

.hdr-date {
  color: var(--color-text-secondary);
}

.hdr-year {
  font-size: 0.875rem;
  font-weight: 700;
  color: var(--color-text-primary);
}

/* Block 2: Quick Actions */
.hdr-actions {
  flex: 0 0 auto;
  gap: 0.375rem;
  align-items: center;
}

.hdr-actions-buttons {
  display: flex;
  gap: 0.25rem;
}

.hdr-action-btn {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.3125rem 0.5rem;
  font-size: 0.6875rem;
  font-weight: 500;
  background: var(--color-bg-input);
  border: 1px solid var(--color-border);
  border-radius: 0.375rem;
  color: var(--color-text-secondary);
  cursor: pointer;
  transition: var(--transition);
  white-space: nowrap;
}

.hdr-action-btn:hover {
  background: var(--color-accent-subtle);
  border-color: var(--color-accent);
  color: var(--color-text-accent);
}

.hdr-action-btn svg {
  flex-shrink: 0;
}

.hdr-theme-select {
  width: 100%;
  padding: 0.1875rem 0.375rem;
  font-size: 0.6875rem;
  background: var(--color-bg-input);
  border: 1px solid var(--color-border);
  border-radius: 0.375rem;
  color: var(--color-text-primary);
  cursor: pointer;
  outline: none;
  transition: var(--transition);
}

.hdr-theme-select:focus {
  border-color: var(--color-border-focus);
  box-shadow: 0 0 0 2px var(--color-accent-subtle);
}

/* Activity indicator */
.hdr-activity {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  font-size: 0.625rem;
  color: var(--color-text-accent);
}

.hdr-activity-spinner {
  width: 12px;
  height: 12px;
  border: 2px solid var(--color-accent-subtle);
  border-top-color: var(--color-accent);
  border-radius: 50%;
  animation: hdr-spin 0.8s linear infinite;
}

@keyframes hdr-spin {
  to {
    transform: rotate(360deg);
  }
}

/* Block 3: Active Module Context */
.hdr-context {
  flex: 1 1 auto;
  gap: 0.0625rem;
  min-width: 120px;
}

.hdr-context-module {
  font-size: 0.8125rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--color-text-accent);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.hdr-context-option {
  font-size: 0.75rem;
  color: var(--color-text-primary);
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.hdr-context-item {
  font-size: 0.6875rem;
  color: var(--color-text-muted);
  font-style: italic;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-height: 0.875rem;
}

/* Block 4: Extra Info */
.hdr-extra {
  flex: 0 0 auto;
  gap: 0.25rem;
  padding-right: 0.5rem;
}

.hdr-extra-slot {
  display: flex;
  align-items: center;
  gap: 0.375rem;
}

.hdr-extra-label {
  font-size: 0.625rem;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 600;
}

.hdr-extra-value {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--color-text-primary);
}

/* ============================================================
   Operations Toolbar
   ============================================================ */
.ops-toolbar {
  display: flex;
  align-items: center;
  gap: 0.125rem;
  padding: 0.25rem 1rem;
  background: var(--color-bg-secondary);
  border-bottom: 1px solid var(--color-border);
  flex-shrink: 0;
}

.ops-btn {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.3125rem 0.625rem;
  font-size: 0.75rem;
  font-weight: 500;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 0.375rem;
  color: var(--color-text-secondary);
  cursor: pointer;
  transition: var(--transition);
  white-space: nowrap;
}

.ops-btn:not(:disabled):hover {
  background: var(--color-accent-subtle);
  border-color: var(--color-accent);
  color: var(--color-text-accent);
}

.ops-btn:not(:disabled):active {
  transform: scale(0.97);
}

.ops-btn:disabled {
  opacity: 0.35;
  cursor: default;
}

.ops-btn svg {
  flex-shrink: 0;
  opacity: 0.7;
}

.ops-btn:not(:disabled):hover svg {
  opacity: 1;
}

.ops-separator {
  width: 1px;
  height: 20px;
  background: var(--color-border);
  margin: 0 0.375rem;
  flex-shrink: 0;
}

/* ============================================================
   Sidebar Toggle
   ============================================================ */
.sidebar-toggle-area {
  padding: 0.625rem 1rem 0.375rem;
  border-bottom: 1px solid var(--color-border);
  flex-shrink: 0;
  display: flex;
  align-items: center;
}

.btn-sidebar-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 32px;
  background: var(--color-bg-input);
  border: 1px solid var(--color-border);
  border-radius: 0.375rem;
  color: var(--color-text-secondary);
  cursor: pointer;
  transition: var(--transition);
  font-size: 1.125rem;
}

.btn-sidebar-toggle:hover {
  background: var(--color-bg-hover);
  color: var(--color-text-primary);
  border-color: var(--color-accent);
}

/* Sidebar footer */
.sidebar-footer {
  padding: 0.75rem 1rem;
  border-top: 1px solid var(--color-border);
  flex-shrink: 0;
}

.btn-logout {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.5rem;
  background: rgba(239, 68, 68, 0.1);
  color: var(--color-danger);
  border: 1px solid rgba(239, 68, 68, 0.2);
  border-radius: 0.375rem;
  cursor: pointer;
  font-size: 0.8125rem;
  font-weight: 500;
  transition: var(--transition);
}

.btn-logout:hover {
  background: rgba(239, 68, 68, 0.2);
  border-color: rgba(239, 68, 68, 0.4);
}

/* Search wrapper for icon positioning */
.search-wrapper {
  position: relative;
}

.search-wrapper .search-icon {
  position: absolute;
  left: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--color-text-muted);
  pointer-events: none;
}

/* ============================================================
   Dashboard Cards
   ============================================================ */
.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1.25rem;
  padding: 1.5rem;
}

.dash-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 1.75rem 1.25rem;
  text-align: center;
  position: relative;
  overflow: hidden;
}

.dash-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 40%;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--color-accent), transparent);
  opacity: 0.5;
}

.dash-card-icon {
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-accent-subtle);
  border-radius: 0.75rem;
  margin-bottom: 1rem;
  color: var(--color-text-accent);
}

.dash-card-value {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--color-text-primary);
  margin-bottom: 0.25rem;
}

.dash-card-label {
  font-size: 0.8125rem;
  color: var(--color-text-muted);
}

/* Buttons (keep existing) */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.375rem 0.75rem;
  font-size: 0.8125rem;
  font-weight: 500;
  border-radius: var(--radius);
  border: 1px solid var(--color-border);
  background: var(--color-bg-input);
  color: var(--color-text-secondary);
  cursor: pointer;
  transition: var(--transition);
  white-space: nowrap;
}

.btn:hover {
  background: var(--color-bg-hover);
  color: var(--color-text-primary);
}

.btn-icon {
  padding: 0.375rem;
  border: none;
  background: transparent;
  color: var(--color-text-muted);
  cursor: pointer;
  border-radius: var(--radius);
  transition: var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-icon:hover {
  background: var(--color-bg-hover);
  color: var(--color-text-primary);
}

.btn-accent {
  background: var(--color-accent);
  color: white;
  border-color: var(--color-accent);
}

.btn-accent:hover {
  background: var(--color-accent-hover);
}

.btn-danger {
  color: var(--color-danger);
}

.btn-danger:hover {
  background: rgba(239, 68, 68, 0.1);
}

/* Theme select (legacy support) */
.theme-select {
  padding: 0.25rem 0.5rem;
  font-size: 0.75rem;
  background: var(--color-bg-input);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  color: var(--color-text-primary);
  cursor: pointer;
  outline: none;
  min-width: 130px;
}

.theme-select:focus {
  border-color: var(--color-border-focus);
  box-shadow: 0 0 0 2px var(--color-accent-subtle);
}

/* -- Content Host -- */
.content-host {
  flex: 1;
  overflow: auto;
  background: var(--color-bg-primary);
  position: relative;
}

#formarea {
  width: 100%;
  height: 100%;
  position: relative;
}

/* ============================================================
   Frame Layout (replicates TFrameWork zones)
   ============================================================ */
.frame-container {
  display: flex;
  flex-direction: column;
  height: 100%;
  width: 100%;
}

.frame-header {
  background: var(--color-bg-card);
  border-bottom: 1px solid var(--color-border);
  padding: 0.75rem 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.frame-header h2 {
  font-size: 1rem;
  font-weight: 600;
  color: var(--color-text-primary);
}

.frame-work {
  flex: 1;
  padding: 1.25rem;
  overflow: auto;
}

.frame-footer {
  background: var(--color-bg-card);
  border-top: 1px solid var(--color-border);
  padding: 0.625rem 1.25rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}

/* Action buttons bar (matches TFrameWork buttons) */
.frame-actions {
  display: flex;
  gap: 0.375rem;
}

.frame-actions .btn {
  font-size: 0.75rem;
  padding: 0.3125rem 0.625rem;
}

/* ============================================================
   Cards
   ============================================================ */
.card {
  background: var(--color-bg-card);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
  padding: 1.25rem;
}

/* ============================================================
   Login Form
   ============================================================ */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: var(--color-bg-primary);
}

.login-card {
  position: fixed !important;
  z-index: 101;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 90%;
  max-width: 400px;
  height: auto !important;
  padding: 2.5rem;
  background: var(--color-bg-card);
  border: 1px solid var(--color-border);
  border-radius: calc(var(--radius) * 2);
  box-shadow: 0 25px 50px rgba(0, 0, 0, 0.25);
}

.login-card h2 {
  text-align: center;
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--color-text-accent);
  margin-bottom: 0.5rem;
}

.login-card p {
  text-align: center;
  color: var(--color-text-muted);
  font-size: 0.875rem;
  margin-bottom: 2rem;
}

.form-group {
  margin-bottom: 1.25rem;
}

.form-group label {
  display: block;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--color-text-secondary);
  margin-bottom: 0.375rem;
}

.form-group input {
  width: 100%;
  padding: 0.625rem 0.875rem;
  background: var(--color-bg-input);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  color: var(--color-text-primary);
  font-size: 0.875rem;
  outline: none;
  transition: var(--transition);
}

.form-group input:focus {
  border-color: var(--color-border-focus);
  box-shadow: 0 0 0 3px var(--color-accent-subtle);
}

.btn-login {
  width: 100%;
  padding: 0.75rem;
  background: var(--color-accent);
  color: white;
  border: none;
  border-radius: var(--radius);
  font-size: 0.9375rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
}

.btn-login:hover {
  background: var(--color-accent-hover);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px var(--color-accent-subtle);
}

.login-error {
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.3);
  border-radius: var(--radius);
  padding: 0.625rem;
  color: var(--color-danger);
  font-size: 0.8125rem;
  margin-bottom: 1rem;
  display: none;
}

/* ============================================================
   Status badge / misc
   ============================================================ */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.125rem 0.5rem;
  font-size: 0.6875rem;
  font-weight: 600;
  border-radius: 9999px;
  letter-spacing: 0.02em;
}

.badge-success {
  background: rgba(34, 197, 94, 0.15);
  color: var(--color-success);
}

.badge-warning {
  background: rgba(245, 158, 11, 0.15);
  color: var(--color-warning);
}

.badge-danger {
  background: rgba(239, 68, 68, 0.15);
  color: var(--color-danger);
}

/* ============================================================
   Transitions & Animations
   ============================================================ */
@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.animate-in {
  animation: fadeIn 0.3s ease forwards;
}

@keyframes pulse-accent {

  0%,
  100% {
    opacity: 1;
  }

  50% {
    opacity: 0.6;
  }
}

.pulse-accent {
  animation: pulse-accent 2s ease-in-out infinite;
}

/* Loading spinner */
.loading-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.3);
  z-index: 50;
  backdrop-filter: blur(2px);
}

.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--color-border);
  border-top-color: var(--color-accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ============================================================
   TreeMenu — JS equivalent of TFNCTreeMenu
   Replicates FMX TreeView dark look with expand/collapse,
   icons, search filter, and selection highlighting.
   ============================================================ */

/* Container */
.menu-tree {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  min-height: 0;
  padding: 0.375rem 0;
  scrollbar-width: thin;
  scrollbar-color: var(--color-border) transparent;
}

/* Lists */
.tm-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.tm-list:not(.tm-open) {
  display: none;
}

.tm-list.tm-open {
  display: block;
}

/* Node */
.tm-node {
  user-select: none;
}

/* Row: the clickable line */
.tm-row {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 5px 12px 5px 8px;
  cursor: pointer;
  color: var(--color-text-secondary);
  font-size: 0.8125rem;
  line-height: 1.3;
  border-left: 2px solid transparent;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.tm-row:hover {
  background: var(--color-bg-hover);
  color: var(--color-text-primary);
}

/* Selected */
.tm-row.tm-selected {
  background: var(--color-accent-subtle);
  color: var(--color-text-accent);
  border-left-color: var(--color-accent);
}

/* Leaf nodes have pointer cursor */
.tm-row.tm-leaf {
  cursor: pointer;
}

/* Indent spacer */
.tm-indent {
  flex-shrink: 0;
  display: inline-block;
}

/* Toggle (expand/collapse chevron) */
.tm-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  color: var(--color-text-muted);
  transition: transform 0.2s ease;
}

.tm-expanded>.tm-row>.tm-toggle {
  transform: rotate(90deg);
}

.tm-toggle-spacer {
  width: 18px;
  flex-shrink: 0;
}

/* Icon */
.tm-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  flex-shrink: 0;
  color: var(--color-warning);
  opacity: 0.85;
  transition: opacity 0.2s ease;
}

.tm-icon img {
  width: 20px;
  height: 20px;
  display: block;
}

/* CDN SVGs have fill:#273137 — tint to amber via CSS filter */
.tm-icon img.tm-icon-svg {
  filter: brightness(0) saturate(100%) invert(68%) sepia(63%) saturate(600%) hue-rotate(2deg) brightness(100%);
}

.tm-row:hover .tm-icon,
.tm-row.tm-selected .tm-icon {
  opacity: 1;
}

/* Caption */
.tm-caption {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Group headers (depth 0) */
.tm-depth-0>.tm-node>.tm-row {
  color: var(--color-text-primary);
  font-weight: 600;
  font-size: 0.8125rem;
  text-transform: lowercase;
  letter-spacing: 0.02em;
  padding-top: 10px;
  padding-bottom: 4px;
}

.tm-depth-0>.tm-node>.tm-row:hover {
  background: transparent;
}

/* Search highlight */
.tm-highlight {
  background: var(--color-warning);
  color: #000;
  border-radius: 2px;
  padding: 0 2px;
}

/* Subtle line separators between root groups (legacy, kept for compat) */
.tm-depth-0>.tm-node+.tm-node {
  border-top: 1px solid var(--color-border);
  margin-top: 4px;
  padding-top: 2px;
}

/* ═══════════════════════════════════════════════════════════════════════
   ACCORDION ROOT CARDS
   Root-level modules rendered as card buttons with exclusive toggle
   ═══════════════════════════════════════════════════════════════════════ */

.tm-accordion {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 4px 8px;
}

/* ── Group Container — Super-Accordion (| prefix) ── */
.tm-group-container {
  border-radius: 10px;
  overflow: hidden;
  margin-top: 2px;
}

/* Group header button — same style as .tm-root-header */
.tm-group-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  cursor: pointer;
  border-radius: 8px;
  border: 1px solid var(--color-border);
  background: var(--color-bg-secondary);
  transition: all 0.2s ease;
  user-select: none;
  color: var(--color-text-secondary);
  font-weight: 700;
  font-size: 0.6875rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.tm-group-header:hover {
  border-color: color-mix(in srgb, var(--color-accent) 40%, transparent);
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--color-accent) 15%, transparent);
}

.tm-group-container.tm-group-open > .tm-group-header {
  border-color: var(--color-accent);
  background: color-mix(in srgb, var(--color-accent) 8%, var(--color-bg-secondary));
  border-bottom-left-radius: 0;
  border-bottom-right-radius: 0;
}

.tm-group-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  flex-shrink: 0;
  color: var(--color-warning);
  background: color-mix(in srgb, var(--color-warning) 12%, transparent);
  border-radius: 6px;
  transition: background 0.2s ease;
}

.tm-group-container.tm-group-open > .tm-group-header > .tm-group-icon {
  background: color-mix(in srgb, var(--color-accent) 15%, transparent);
  color: var(--color-accent);
}

/* Tint group SVG icons same as child icons for visibility */
.tm-group-icon img.tm-icon-svg {
  filter: brightness(0) saturate(100%) invert(68%) sepia(63%) saturate(600%) hue-rotate(2deg) brightness(100%);
}

.tm-group-container.tm-group-open > .tm-group-header > .tm-group-icon > img.tm-icon-svg {
  filter: brightness(0) saturate(100%) invert(50%) sepia(90%) saturate(400%) hue-rotate(210deg) brightness(105%);
}

.tm-group-icon img {
  width: 22px;
  height: 22px;
  display: block;
}

.tm-group-icon svg {
  color: inherit;
}

.tm-group-caption {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tm-group-container.tm-group-open .tm-group-caption {
  color: var(--color-text-accent);
}

.tm-group-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  font-size: 0.6875rem;
  font-weight: 600;
  color: var(--color-text-muted);
  background: color-mix(in srgb, var(--color-text-muted) 15%, transparent);
  border-radius: 10px;
  flex-shrink: 0;
  transition: color 0.2s ease, background 0.2s ease;
}

.tm-group-container.tm-group-open .tm-group-badge {
  color: var(--color-accent);
  background: color-mix(in srgb, var(--color-accent) 15%, transparent);
}

.tm-group-chevron {
  display: flex;
  align-items: center;
  color: var(--color-text-muted);
  transition: transform 0.25s ease;
}

.tm-group-container.tm-group-open .tm-group-chevron {
  transform: rotate(180deg);
  color: var(--color-text-accent);
}

/* Collapsible body */
.tm-group-body {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease;
  border: none;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 0;
}

.tm-group-container.tm-group-open > .tm-group-body {
  max-height: 2000px;
  border-color: var(--color-border);
  padding: 8px 10px;
  background: rgba(255, 255, 255, 0.015);
}

.tm-group-body .tm-root-card {
  border: 1px solid rgba(255, 255, 255, 0.04);
}

/* ── Root Card ── */
.tm-root-card {
  border-radius: 8px;
  border: 1px solid var(--color-border);
  background: var(--color-bg-secondary);
  overflow: hidden;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.tm-root-card:hover {
  border-color: color-mix(in srgb, var(--color-accent) 40%, transparent);
}

.tm-root-card.tm-root-expanded {
  border-color: var(--color-accent);
  box-shadow: 0 0 0 1px var(--color-accent-subtle), var(--shadow-card);
}

/* ── Header (the clickable module button) ── */
.tm-root-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  cursor: pointer;
  color: var(--color-text-secondary);
  font-weight: 700;
  font-size: 0.6875rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  transition: background 0.15s ease;
  user-select: none;
}

.tm-root-header:hover {
  background: var(--color-bg-hover);
}

.tm-root-expanded > .tm-root-header {
  background: var(--color-accent-subtle);
  color: var(--color-text-accent);
}

/* Selected state for direct (leaf) root items */
.tm-root-card:has(> .tm-root-header.tm-selected) {
  border-color: var(--color-accent);
  box-shadow: 0 0 0 1px var(--color-accent-subtle), var(--shadow-card);
}

.tm-root-header.tm-selected {
  background: var(--color-accent-subtle);
  color: var(--color-text-accent);
}

.tm-root-header.tm-selected > .tm-root-icon {
  background: color-mix(in srgb, var(--color-accent) 15%, transparent);
  color: var(--color-accent);
}

.tm-root-header.tm-selected > .tm-root-icon > img.tm-icon-svg {
  filter: brightness(0) saturate(100%) invert(50%) sepia(90%) saturate(400%) hue-rotate(210deg) brightness(105%);
}

/* ── Root Icon ── */
.tm-root-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  flex-shrink: 0;
  color: var(--color-warning);
  background: color-mix(in srgb, var(--color-warning) 12%, transparent);
  border-radius: 6px;
  transition: background 0.2s ease;
}

.tm-root-expanded > .tm-root-header > .tm-root-icon {
  background: color-mix(in srgb, var(--color-accent) 15%, transparent);
  color: var(--color-accent);
}

.tm-root-icon img {
  width: 22px;
  height: 22px;
  display: block;
}

.tm-root-icon img.tm-icon-svg {
  filter: brightness(0) saturate(100%) invert(68%) sepia(63%) saturate(600%) hue-rotate(2deg) brightness(100%);
}

.tm-root-expanded > .tm-root-header > .tm-root-icon > img.tm-icon-svg {
  filter: brightness(0) saturate(100%) invert(50%) sepia(90%) saturate(400%) hue-rotate(210deg) brightness(105%);
}

/* ── Root Caption ── */
.tm-root-caption {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── Child Count Badge ── */
.tm-root-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  font-size: 0.6875rem;
  font-weight: 600;
  color: var(--color-text-muted);
  background: color-mix(in srgb, var(--color-text-muted) 15%, transparent);
  border-radius: 10px;
  flex-shrink: 0;
  transition: color 0.2s ease, background 0.2s ease;
}

.tm-root-expanded > .tm-root-header > .tm-root-badge {
  color: var(--color-accent);
  background: color-mix(in srgb, var(--color-accent) 15%, transparent);
}

/* ── Chevron ── */
.tm-root-chevron {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  color: var(--color-text-muted);
  transition: transform 0.25s ease, color 0.2s ease;
}

.tm-root-expanded > .tm-root-header > .tm-root-chevron {
  transform: rotate(180deg);
  color: var(--color-accent);
}

/* ── Body (submenu, animated slide) ── */
.tm-root-body {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease;
  border: none;
}

.tm-root-expanded > .tm-root-body {
  max-height: 2000px; /* generous max for animation */
}

.tm-root-body .tm-list {
  padding: 4px 0;
}

.tm-root-body .tm-row {
  padding-left: 16px;
}

/* ── Search wrapper + clear button ── */
.tm-search-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.tm-search-wrap > input {
  width: 100%;
  padding-right: 32px; /* room for X button (clear) DENTRO del input */
}

.tm-search-clear {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  padding: 0;
  border: none;
  background: color-mix(in srgb, var(--color-text-muted) 20%, transparent);
  color: var(--color-text-secondary);
  border-radius: 50%;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.tm-search-clear:hover {
  background: color-mix(in srgb, var(--color-danger) 25%, transparent);
  color: var(--color-danger);
}

/* Container externo: input + pin a la derecha como sibling */
.tm-search-row {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
}
.tm-search-row > .tm-search-wrap {
  flex: 1; /* el input ocupa todo el espacio sobrante */
}

/* Pin button (chincheta) FUERA del input — toggle "auto-cerrar tras seleccionar" */
.tm-search-pin {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 1px solid var(--color-border);
  background: var(--color-bg-input, var(--color-bg-secondary));
  color: var(--color-text-muted);
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}
.tm-search-pin:hover {
  background: color-mix(in srgb, var(--color-accent) 18%, transparent);
  color: var(--color-accent);
  border-color: var(--color-accent);
}
/* Estado fijo (chincheta clavada) — el menu permanece abierto al seleccionar */
.tm-search-pin.tm-pin-active {
  color: var(--color-accent);
  background: color-mix(in srgb, var(--color-accent) 18%, transparent);
  border-color: var(--color-accent);
}

/* Loading state */
.tm-loading {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 16px;
  color: var(--color-text-muted, #9ca3af);
  font-size: 0.875rem;
}

.tm-spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid var(--color-border, #4b5563);
  border-top-color: var(--color-warning, #f59e0b);
  border-radius: 50%;
  animation: tm-spin 0.6s linear infinite;
}

@keyframes tm-spin {
  to {
    transform: rotate(360deg);
  }
}

/* Error state */
.tm-error {
  padding: 12px 16px;
  color: var(--color-danger, #ef4444);
  font-size: 0.8rem;
  opacity: 0.85;
}

/* Empty state */
.tm-empty {
  padding: 16px;
  color: var(--color-text-muted, #9ca3af);
  font-size: 0.8rem;
  text-align: center;
}

/* ============================================================
   Responsive: Header & Toolbar
   ============================================================ */

/* ≤1200px: header wraps to 2 rows */
@media (max-width: 1200px) {
  .header {
    flex-wrap: wrap;
    min-height: auto;
    padding: 0.375rem 0.75rem;
  }

  .hdr-company {
    max-width: none;
    flex: 1 1 45%;
  }

  .hdr-actions {
    flex: 0 0 auto;
  }

  .hdr-context {
    flex: 1 1 45%;
    order: 10;
    padding-top: 0.25rem;
  }

  .hdr-extra {
    flex: 0 0 auto;
    order: 11;
  }

  .hdr-divider:nth-child(6) {
    display: none;
  }
}

/* Mobile Toggle (Hidden by default) */
.btn-mobile-toggle {
  display: none;
  background: transparent;
  border: none;
  color: var(--color-text-secondary);
  cursor: pointer;
  padding: 0.25rem;
  margin-right: 0.5rem;
}

.btn-mobile-toggle:hover {
  color: var(--color-text-primary);
  background: var(--color-bg-hover);
  border-radius: 0.375rem;
}

/* ≤900px: Compact Layout */
@media (max-width: 900px) {
  .header {
    flex-wrap: wrap;
    min-height: 60px;
    height: auto;
    padding: 0 0.5rem 0 0.5rem;
    gap: 0.5rem;
    align-items: center;
    justify-content: space-between;
  }

  /* Reset dividers */
  .hdr-divider {
    display: none;
  }

  /* 1. Brand (Compact) */
  .hdr-brand {
    flex: 0 1 auto;
    /* Allow shrinking */
    width: auto;
    border-bottom: none;
    padding-bottom: 0;
    margin-bottom: 0;
    gap: 0.5rem;
  }

  /* Show Mobile Toggle */
  /* Show Mobile Toggle (Right Side) */
  .btn-mobile-toggle {
    display: flex;
    order: 100;
    margin-right: 0;
    width: 36px;
    height: 36px;
    align-items: center;
    justify-content: center;
    color: var(--color-text-primary);
  }

  /* Shrink Logo/Text */
  .hdr-brand-icon {
    width: 32px;
    height: 32px;
    font-size: 0.8rem;
    border-radius: 0.375rem;
  }

  .hdr-brand-title {
    font-size: 1rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 120px;
    /* Limit width */
    display: block;
  }

  /* 2. Actions (Visible & Compact) */
  .hdr-actions {
    order: 2;
    flex: 1 1 auto;
    width: auto;
    justify-content: flex-end;
    padding: 0;
    margin-right: 0.25rem;
  }

  .hdr-actions-buttons {
    width: auto;
    /* Auto width */
    justify-content: flex-end;
    gap: 0.25rem;
  }

  .hdr-action-btn {
    flex: 0 0 auto;
    /* Don't grow */
    padding: 0.375rem;
    width: 32px;
    height: 32px;
  }

  .hdr-action-btn span {
    display: none;
    /* Icon only */
  }

  /* Theme selector hide on super small? */
  .hdr-theme-select {
    display: none;
    /* Hide theme selector to save space */
  }

  /* Hide Company */
  .hdr-company {
    display: none;
  }

  /* Hide Context (or show small?) */
  .hdr-context {
    display: none;
  }

  /* Hide context to prioritize Actions */

  .hdr-extra {
    display: none;
  }

  /* HIDE RAIL on Mobile to prevent double hamburger */
  .sidebar-rail {
    display: none;
  }

  /* Adjust Sidebar Drawer positioning for mobile */
  .sidebar-drawer {
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 100;
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.3);

  }

  .dashboard-grid {
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 0.75rem;
    padding: 1rem;
  }
}

/* ≤400px: Super small tweaks */
@media (max-width: 400px) {
  .hdr-brand-title {
    display: none;
    /* Hide title on very small screens, show only logo */
  }
}

/* ════════════════════════════════════════════════════════════════
   ERP Frame Component Library (.erp-*)
   Shared reusable classes for all frame modules.
   Each frame only needs its own layout + module-specific CSS.
   ════════════════════════════════════════════════════════════════ */

/* ── Frame Wrappers ──────────────────────────────────────────── */
.frame-container {
  display: flex;
  flex-direction: column;
  height: 100%;
  width: 100%;
  overflow: hidden;
  font-family: 'Inter', 'Segoe UI', system-ui, -apple-system, sans-serif;
  color: var(--color-text-primary, #374151);
}

.frame-container.animate-in {
  animation: erp-fadeIn .3s ease-out;
}

.frame-work {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.frame-footer {
  padding: 6px 14px;
  font-size: 11px;
  color: var(--color-text-muted, #64748b);
  border-top: 1px solid var(--color-border, #e2e8f0);
  background: var(--color-bg-secondary, #fff);
  display: flex;
  align-items: center;
  flex-shrink: 0;
}

@keyframes erp-fadeIn {
  from {
    opacity: 0;
    transform: translateY(6px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ── Panel ───────────────────────────────────────────────────── */
.erp-panel {
  display: flex;
  flex-direction: column;
  background: var(--color-bg-card, #fff);
  border-radius: 10px;
  border: 1.5px solid var(--color-border, #e2e8f0);
  box-shadow: var(--shadow-card, 0 1px 3px rgba(0, 0, 0, .08)), 0 1px 2px rgba(0, 0, 0, .04);
  overflow: hidden;
  min-height: 0;
}

.erp-panel-header {
  padding: 10px 14px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .8px;
  color: var(--color-text-secondary, #475569);
  border-bottom: 1.5px solid var(--color-border, #e2e8f0);
  background: var(--color-bg-secondary, #fff);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-shrink: 0;
}

.erp-panel-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--color-text-primary, #374151);
  letter-spacing: -.2px;
}

.erp-panel-subtitle {
  font-size: 11px;
  color: var(--color-text-secondary, #475569);
}

.erp-panel-footer {
  padding: 8px 14px;
  font-size: 11px;
  color: var(--color-text-muted, #64748b);
  border-top: 1px solid var(--color-border, #e2e8f0);
  background: var(--color-bg-secondary, #fff);
  flex-shrink: 0;
  text-align: center;
}

/* ── Search ──────────────────────────────────────────────────── */
.erp-search {
  padding: 8px 10px;
  border-bottom: 1px solid var(--color-border, #e2e8f0);
  background: var(--color-bg-secondary, #fff);
  flex-shrink: 0;
}

.erp-search-input {
  width: 100%;
  background: var(--color-bg-primary, #f8fafc);
  color: var(--color-text-primary, #374151);
  border: 1.5px solid var(--color-border, #e2e8f0);
  border-radius: 6px;
  padding: 7px 10px;
  font-size: 12px;
  outline: none;
  font-family: inherit;
  transition: border-color .2s, box-shadow .2s;
}

.erp-search-input:focus {
  border-color: var(--color-accent, #6366f1);
  box-shadow: 0 0 0 3px var(--color-accent-subtle, rgba(99, 102, 241, .15));
}

.erp-search-input::placeholder {
  color: var(--color-text-muted, #94a3b8);
}

/* ── Scrollable List ─────────────────────────────────────────── */
.erp-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 0;
  min-height: 0;
}

.erp-list::-webkit-scrollbar {
  width: 6px;
}

.erp-list::-webkit-scrollbar-track {
  background: var(--color-bg-primary, #f8fafc);
}

.erp-list::-webkit-scrollbar-thumb {
  background: var(--color-border, #e2e8f0);
  border-radius: 3px;
}

/* ── List Item ───────────────────────────────────────────────── */
.erp-list-item {
  padding: 9px 14px;
  cursor: pointer;
  border-bottom: 1px solid var(--color-border, #e2e8f0);
  transition: background .15s;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  user-select: none;
  color: var(--color-text-primary, #374151);
}

.erp-list-item:hover {
  background: var(--color-bg-hover, #e2e8f0);
}

.erp-list-item.selected {
  background: var(--color-accent-subtle, rgba(99, 102, 241, .15));
  border-left: 3px solid var(--color-accent, #6366f1);
}

.erp-list-item .item-main {
  flex: 1;
  min-width: 0;
}

.erp-list-item .item-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--color-text-primary, #374151);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.erp-list-item .item-sub {
  font-size: 11px;
  color: var(--color-text-secondary, #475569);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 1px;
}

/* ── Badges ──────────────────────────────────────────────────── */
.erp-badge {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
  flex-shrink: 0;
}

.erp-badge--count {
  background: var(--color-accent, #6366f1);
  color: #fff;
}

.erp-badge--admin {
  background: #f97316;
  color: #fff;
  font-size: 10px;
}

/* ── Status Bar ──────────────────────────────────────────────── */
.erp-status-bar {
  padding: 6px 16px;
  font-size: 12px;
  color: var(--color-text-secondary, #475569);
  display: flex;
  align-items: center;
  gap: 8px;
  border-bottom: 1px solid var(--color-border, #e2e8f0);
  flex-shrink: 0;
  background: var(--color-bg-secondary, #fff);
}

.erp-status-bar.loading .erp-spinner {
  display: inline-block;
}

.erp-spinner {
  display: none;
  width: 14px;
  height: 14px;
  border: 2px solid var(--color-border, #e2e8f0);
  border-top-color: var(--color-accent, #6366f1);
  border-radius: 50%;
  animation: erp-spin .8s linear infinite;
}

@keyframes erp-spin {
  to {
    transform: rotate(360deg);
  }
}

/* ── Command Bar ─────────────────────────────────────────────── */
.erp-cmd-bar {
  display: flex;
  gap: 8px;
  padding: 8px 16px;
  border-bottom: 1px solid var(--color-border, #e2e8f0);
  flex-shrink: 0;
  align-items: center;
  background: var(--color-bg-secondary, #fff);
}

.erp-cmd-hint {
  color: var(--color-text-muted, #94a3b8);
  font-size: 11px;
  margin-left: 8px;
}

/* ── Buttons ─────────────────────────────────────────────────── */
.erp-btn {
  border: none;
  border-radius: 6px;
  padding: 7px 16px;
  cursor: pointer;
  font-weight: 600;
  font-size: 12px;
  white-space: nowrap;
  transition: filter .15s, transform .1s;
}

.erp-btn:hover {
  filter: brightness(1.15);
}

.erp-btn:active {
  transform: scale(.97);
}

.erp-btn:disabled {
  opacity: .4;
  cursor: not-allowed;
}

.erp-btn--add {
  background: var(--color-success, #22c55e);
  color: #fff;
}

.erp-btn--remove {
  background: var(--color-danger, #ef4444);
  color: #fff;
}

.erp-btn--reload {
  background: var(--color-accent, #6366f1);
  color: #fff;
  margin-left: auto;
}

.erp-btn--sm {
  padding: 4px 10px;
  font-size: 11px;
}

/* ── Empty State ─────────────────────────────────────────────── */
.erp-empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 16px;
  color: var(--color-text-muted, #94a3b8);
  font-size: 13px;
  text-align: center;
}

.erp-empty-icon {
  font-size: 32px;
  margin-bottom: 8px;
  opacity: .5;
}

/* ── Toast ────────────────────────────────────────────────────── */
.erp-toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: var(--color-bg-card, #fff);
  color: var(--color-text-primary, #374151);
  border: 1px solid var(--color-border, #e2e8f0);
  border-radius: 8px;
  padding: 10px 18px;
  font-size: 12px;
  z-index: 1000;
  opacity: 0;
  transform: translateY(20px);
  transition: opacity .3s, transform .3s;
  pointer-events: none;
  box-shadow: var(--shadow-card, 0 1px 3px rgba(0, 0, 0, .08));
}

.erp-toast.show {
  opacity: 1;
  transform: translateY(0);
}

.erp-toast.error {
  border-color: var(--color-danger, #ef4444);
  color: var(--color-danger, #ef4444);
}

/* ── Filter Group (for toolbars) ─────────────────────────────── */
.erp-filter-group {
  display: flex;
  align-items: center;
  gap: 0.3rem;
}

.erp-filter-label {
  font-size: 0.7rem;
  color: var(--color-text-muted, #94a3b8);
  white-space: nowrap;
}

.erp-filter-input {
  padding: 0.2rem 0.4rem;
  font-size: 0.7rem;
  background: var(--color-bg-input, #f1f5f9);
  border: 1px solid var(--color-border, #e2e8f0);
  border-radius: var(--radius, .5rem);
  color: var(--color-text-primary, #374151);
}

.erp-filter-input::placeholder {
  color: var(--color-text-muted, #64748b);
  opacity: 0.7;
  font-size: 0.65rem;
}
/* =================================================================
   MULTI-ISLAND NOTIFICATION SYSTEM (cps-islands.js) v2.0
   ================================================================= */

#erp-islands-container,
.hdr-islands {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    flex: 3;
    min-width: 0;
    overflow: visible;
    position: relative;
    height: auto; /* IMPORTANTE: Dejar que tome su altura, si es 100% se sale de la linea al hacer wrap */
    padding: 6px 6px;
}

.dynamic-island {
    background: rgba(0, 0, 0, 0.35);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid rgba(255, 255, 255, 0.09);
    border-radius: 999px;
    height: 30px;
    padding: 0 12px;
    display: flex;
    align-items: center;
    cursor: pointer;
    overflow: visible;
    transition: border-color 0.4s ease, background 0.3s ease, box-shadow 0.4s ease;
    position: relative;
    box-shadow: 0 2px 10px rgba(0,0,0,0.2);
    user-select: none;
    white-space: nowrap;
    flex-shrink: 0;
}

.dynamic-island:hover {
    background: rgba(255, 255, 255, 0.06);
    border-color: rgba(255,255,255,0.18);
}

@keyframes islandPulse {
    0%   { box-shadow: 0 0 0 0px rgba(255,255,255,0.2); }
    50%  { box-shadow: 0 0 0 8px rgba(255,255,255,0);   }
    100% { box-shadow: 0 0 0 0px rgba(255,255,255,0);   }
}

.dynamic-island.alerting {
    animation: islandPulse 0.7s ease-out;
}

.di-compact {
    display: flex;
    align-items: center;
    gap: 7px;
}

.di-indicator {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    flex-shrink: 0;
    transition: background 0.4s ease, box-shadow 0.4s ease;
}

.di-compact svg {
    flex-shrink: 0;
    opacity: 0.7;
    transition: opacity 0.2s;
}
.dynamic-island:hover .di-compact svg { opacity: 1; }

.di-text {
    font-size: 0.76rem;
    font-weight: 500;
    letter-spacing: 0.01em;
    white-space: nowrap;
    transition: color 0.3s ease;
    max-width: 130px;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Panel flotante expandido */
.di-expanded-panel {
    display: none;
    position: absolute;
    top: calc(100% + 14px);
    left: 50%;
    transform: translateX(-50%);
    width: 290px;
    background: var(--color-bg-sidebar, #0c1222);
    border: 1px solid var(--color-border, #334155);
    border-radius: 14px;
    box-shadow: 0 24px 56px rgba(0,0,0,0.55);
    z-index: 9999;
    padding: 12px;
    flex-direction: column;
    gap: 8px;
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
}

.dynamic-island.expanded .di-expanded-panel {
    display: flex;
    animation: panelSlideIn 0.22s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

@keyframes panelSlideIn {
    from { opacity: 0; transform: translateX(-50%) translateY(-6px) scale(0.97); }
    to   { opacity: 1; transform: translateX(-50%) translateY(0) scale(1); }
}

.di-panel-header {
    font-size: 0.67rem;
    color: var(--color-text-muted, #64748b);
    text-transform: uppercase;
    letter-spacing: 1.1px;
    font-weight: 600;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--color-border, #334155);
}

.di-list-container {
    display: flex;
    flex-direction: column;
    gap: 5px;
    overflow-y: auto;
    overflow-x: hidden;
    max-height: 210px;
    padding-right: 2px;
}

.di-list-container::-webkit-scrollbar { width: 3px; }
.di-list-container::-webkit-scrollbar-thumb {
    background: var(--color-border, #334155);
    border-radius: 3px;
}

.history-item {
    display: flex;
    flex-direction: column;
    padding: 7px 9px;
    border-radius: 8px;
    background: rgba(255,255,255,0.03);
    cursor: pointer;
    transition: background 0.18s, border-left-color 0.18s;
    border-left: 2px solid transparent;
    gap: 3px;
}

.history-item:hover {
    background: rgba(255,255,255,0.08);
    border-left-color: var(--color-accent, #6366f1);
}

/* ================================================================
   HEADER RESPONSIVE OVERRIDES
   ================================================================ */

/* Rebalance flex weights */
.hdr-company  { flex: 3; }
.hdr-actions  { flex: 2; flex-direction: row; align-items: center; gap: 0.4rem; }
.hdr-context  { flex: 2; }
.hdr-extra    { display: none; } /* Removed - year shown in company block */


/* 800px: Mobile strict — solo brand + company-row1 + hamburguesa */
@media (max-width: 800px) {
    /* Ocultar todo lo que no sea esencial */
    .hdr-actions,
    .hdr-context,
    .hdr-divider,
    .hdr-company-row2,
    .hdr-company-row3,
    .hdr-company-meta        { display: none !important; }

    /* Mostrar hamburguesa */
    .btn-mobile-toggle       { display: flex !important; }

    /* Header: permite wrap para que las islas caigan a una segunda fila */
    .header {
        flex-wrap: wrap !important;
        min-height: 56px !important;
        height: auto !important;
        padding: 0 0.75rem !important;
        overflow: visible !important;
    }

    /* Company: ocupa el resto entre brand y toggle */
    .hdr-company {
        flex: 1 !important;
        min-width: 0 !important;
        max-width: none !important;
    }

    /* Solo mostrar nombre en row1 */
    .hdr-company-row1 {
        display: flex !important;
    }
}
/* =================================================================
   HEADER WRAP LAYOUT — Bloques independientes que saltan de linea
   ================================================================= */

/* El header pasa a flex-wrap: wrap */
.header {
    flex-wrap: wrap;
    align-items: center;
    min-height: 72px;
    height: auto;         /* Crece hacia abajo si hay 2 filas */
    row-gap: 0;
    padding: 6px 1.25rem;
    overflow: visible;
}

/* Cada bloque: flex: 0 1 auto = no crece, puede encoger, tamaño por contenido */
/* min-width garantiza que NUNCA se comprime por debajo de su contenido natural */

.hdr-brand {
    flex: 0 0 auto;
    min-width: 120px;
    padding-right: 0.5rem;
    order: 1;
}

.hdr-divider {
    flex: 0 0 1px;
    height: 36px;
    align-self: center;
    order: 2;             /* Dividers mismos order que el siguiente bloque */
}

/* === Bloque 2: Empresa === */
.hdr-block.hdr-company,
.hdr-company {
    flex: 0 1 auto;
    min-width: 220px;
    max-width: 320px;
    order: 3;
    padding: 4px 0.75rem;
}

/* === Bloque 3: Acciones === */
.hdr-block.hdr-actions,
.hdr-actions {
    flex: 0 1 auto;
    min-width: 280px;
    order: 5;
    flex-direction: row;
    align-items: center;
    gap: 0.4rem;
    padding: 4px 0.75rem;
}

/* === Bloque 4: Contexto === */
.hdr-block.hdr-context,
.hdr-context {
    flex: 0 1 auto;
    min-width: 150px;
    order: 7;
    padding: 4px 0.75rem;
}

/* === Bloque 5: Islands === */
#erp-islands-container,
.hdr-islands {
    flex: 1 1 auto;       /* Ocupa el resto de la fila */
    min-width: 320px;     /* Al menos las 4 pastillas en modo icono */
    order: 9;
    justify-content: flex-end;
}

/* Los dividers entre bloques siguen el order de sus bloques adyacentes */
.hdr-block.hdr-company + .hdr-divider  { order: 4; }
.hdr-block.hdr-actions + .hdr-divider  { order: 6; }
.hdr-block.hdr-context + .hdr-divider  { order: 8; }

/* Mobile toggle: siempre al final */
.btn-mobile-toggle { order: 99; flex-shrink: 0; }

/* Cuando la pantalla sea estrecha y algún bloque salte de linea,
   el separador vertical no tiene sentido — lo ocultamos en ese caso */
@media (max-width: 900px) {
    .hdr-divider       { display: none; }
    .hdr-actions       { min-width: 100%; order: 20; }
    #erp-islands-container,
    .hdr-islands       { min-width: 100%; order: 100; justify-content: flex-start; flex-wrap: wrap; gap: 8px; }
    .hdr-context       { min-width: 100%; order: 19; }
    .btn-mobile-toggle { display: flex; order: 50 !important; } /* Ahora el propio container lo empujará a la dcha */
}

@media (max-width: 600px) {
    .hdr-context      { display: none; }
    /* #erp-islands-container now handled by 800px forcing display: flex */
    .hdr-actions      { display: none; }
    .hdr-company      { min-width: 0; max-width: none; flex: 1; }
}
/* =================================================================
   SHELL LAYOUT GRID FIX — Header auto-height, body fills rest
   El header crece con flex-wrap; el body siempre ocupa el resto.
   ================================================================= */

/* Sustituir flex-column por Grid: fila 1 = header (auto), fila 2 = body (1fr) */
.app-shell {
    display: grid !important;
    grid-template-rows: auto 1fr;
    grid-template-columns: 100%;
    width: 100%;   /* no 100vw: el body lleva zoom (ver Base Styles) */
    height: 100%;  /* no 100vh */
    overflow: hidden;
}

/* Header: altura auto (crece si sus bloques hacen wrap) */
.header {
    grid-row: 1;
    height: auto !important;
    min-height: 72px;
    flex-shrink: 0;
    /* flex-wrap ya definido en bloque anterior */
}

/* Body: ocupa exactamente el espacio restante */
.app-body {
    grid-row: 2;
    overflow: hidden;
    min-height: 0;   /* Importante en grid para que scroll funcione */
}
/* =================================================================
   ISLANDS ROW 2 FIX — Alineacion y visibilidad de las 4 islas
   ================================================================= */

/* Cuando las islas saltan a la 2a fila ocupan 100% del header-row,
   las alineamos a la derecha y eliminamos el flex: 1 que las estiraba */
#erp-islands-container,
.hdr-islands {
    flex: 1 1 0px !important;     /* Estira absorbiendo huecos base 0: evita que la pastilla salte entera demasiado pronto */
    flex-wrap: wrap !important;   /* Permite que el wrap ocurra DENTRO del contenedor */
    min-width: 380px !important;  /* Rompe la fila ANTES de superponer a los titulos del ERP */
    width: auto;
    justify-content: flex-end;    /* Pastillas pegadas a la derecha */
    gap: 6px;
    margin-left: auto;            /* Empuja hacia la derecha cuando esta en fila 1 */
    padding: 4px 0;
}

/* Cada pastilla tiene un minimo garantizado para verse el icono + LED */
.dynamic-island {
    flex-shrink: 0;
    min-width: 34px;              /* Siempre se ve al menos el icono + LED */
    position: relative;
    z-index: 10;
}
.dynamic-island:hover,
.dynamic-island:focus-within,
.dynamic-island.expanded,
.dynamic-island.active {
    z-index: 99 !important;
}


/* =================================================================
   ISLANDS BAR — Wrap naturally inside the header
   ================================================================= */

/* We allow the header to wrap naturally */
.header {
    height: auto;
    min-height: 72px;
    flex-wrap: wrap; /* IMPORTANT: Allows wrapping */
}

/* La barra de islas se mimetiza con el header cuando comparte fila */
#erp-islands-container {
    background: transparent !important;
    border-bottom: none !important;
    padding: 0 1.25rem;
    align-items: center;
    justify-content: flex-end;
}

/* Las pastillas individuales */
#erp-islands-container .dynamic-island {
    flex-shrink: 0;
}

/* Mobile: mostrar islas en segunda fila */
@media (max-width: 800px) {
    #erp-islands-container  { 
        display: flex !important; 
        flex-wrap: wrap !important;
        gap: 8px !important;
        min-width: 100% !important; 
        order: 100 !important; /* Las islas deben ir al FINAL de todo */
        padding-top: 8px !important;
        padding-bottom: 8px !important;
        margin-top: 4px !important;
        border-top: 1px solid var(--color-border) !important;
        justify-content: flex-start !important;
    }
}
/* =================================================================
   ISLANDS BAR + PASTILLAS — Adaptacion al tema seleccionado
   Sustituye colores hardcodeados por variables CSS del tema.
   ================================================================= */

/* Pastillas: usan variables del tema en lugar de rgba hardcoded */
.dynamic-island {
    background: var(--color-bg-input) !important;
    border: 1px solid var(--color-border) !important;
    color: var(--color-text-primary) !important;
    box-shadow: var(--shadow-card) !important;
}
.dynamic-island:hover {
    background: var(--color-bg-hover) !important;
    border-color: var(--color-border-focus) !important;
}

/* Texto dentro de la pastilla */
.di-text {
    color: var(--color-text-secondary) !important;
}

/* SVG icono: color del texto del tema */
.di-compact svg {
    color: var(--color-text-muted) !important;
    stroke: var(--color-text-muted) !important;
}
.dynamic-island:hover .di-compact svg {
    color: var(--color-text-accent) !important;
    stroke: var(--color-text-accent) !important;
}

/* Temas oscuros: glassmorphism suave en lugar del fondo plano */
[data-theme="indigo-deep"] .dynamic-island,
[data-theme="emerald-dark"] .dynamic-island,
[data-theme="rose-dark"] .dynamic-island,
[data-theme="sky-dark"] .dynamic-island,
[data-theme="slate-neutral"] .dynamic-island,
[data-theme="ientop-dark"] .dynamic-island {
    background: rgba(255, 255, 255, 0.06) !important;
    border: 1px solid rgba(255, 255, 255, 0.1) !important;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
}
[data-theme="indigo-deep"] .dynamic-island:hover,
[data-theme="emerald-dark"] .dynamic-island:hover,
[data-theme="rose-dark"] .dynamic-island:hover,
[data-theme="sky-dark"] .dynamic-island:hover,
[data-theme="slate-neutral"] .dynamic-island:hover,
[data-theme="ientop-dark"] .dynamic-island:hover {
    background: rgba(255, 255, 255, 0.12) !important;
    border-color: var(--color-accent) !important;
}

/* Temas oscuros: texto claro */
[data-theme="indigo-deep"] .di-text,
[data-theme="emerald-dark"] .di-text,
[data-theme="rose-dark"] .di-text,
[data-theme="sky-dark"] .di-text,
[data-theme="slate-neutral"] .di-text,
[data-theme="ientop-dark"] .di-text {
    color: var(--color-text-primary) !important;
}

/* Panel expandido: fondo del tema */
.di-expanded-panel {
    background: var(--color-bg-sidebar) !important;
    border-color: var(--color-border) !important;
}

.di-panel-header {
    color: var(--color-text-muted) !important;
    border-bottom-color: var(--color-border) !important;
}

.history-item {
    background: var(--color-accent-subtle) !important;
}
.history-item:hover {
    background: var(--color-bg-hover) !important;
    border-left-color: var(--color-accent) !important;
}

/* LED indicador: siempre el color de acento del tema */
.di-indicator.idle   { background: var(--color-text-muted); }
.di-indicator.active { background: var(--color-accent); box-shadow: 0 0 6px var(--color-accent); }

/* =================================================================
   MENU FROSTED GLASS (Concept 5) — Tarjetas glassmorphism premium
   Fiel al concepto: grupos como cards, glow accent en abierto,
   items con bullet indicator animado
   ================================================================= */

/* ── Acordeon contenedor: sin márgenes extras ── */
.tm-accordion {
    display: flex;
    flex-direction: column;
    gap: 6px;        /* espacio entre cards */
    padding: 8px 0;
}

/* ── Base: TODOS los cards (grupos y acceso directo) son iguales ── */
.tm-group-container,
.tm-root-card {
    border-radius: 10px;
    border: 1px solid var(--color-border);
    background: var(--color-bg-secondary);
    overflow: hidden;
    transition: border-color 0.25s ease, box-shadow 0.25s ease, background 0.25s ease;
}

/* ── Cabecera compartida: grupo y root ── */
.tm-group-header,
.tm-root-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 11px 14px;
    cursor: pointer;
    background: transparent;
    border: none;
    width: 100%;
    /* Sin transición propia, hereda del container */
}

/* ── Captions ── */
.tm-group-caption,
.tm-root-caption {
    flex: 1;
    font-size: 0.8125rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    color: var(--color-text-primary);
    text-transform: uppercase;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ── Badges ── */
.tm-group-badge,
.tm-root-badge {
    font-size: 0.6875rem;
    font-weight: 700;
    background: var(--color-accent-subtle);
    color: var(--color-accent);
    border-radius: 20px;
    padding: 2px 8px;
    min-width: 22px;
    text-align: center;
    flex-shrink: 0;
}

/* ── Chevrons ── */
.tm-group-chevron,
.tm-root-chevron {
    flex-shrink: 0;
    color: var(--color-text-muted);
    transition: transform 0.25s ease, color 0.25s ease;
    display: flex;
    align-items: center;
}

/* ── Iconos ── */
.tm-group-icon,
.tm-root-icon {
    width: 28px;
    height: 28px;
    border-radius: 7px;
    background: var(--color-accent-subtle);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    overflow: hidden;
}
.tm-group-icon img,
.tm-root-icon img {
    width: 18px;
    height: 18px;
    object-fit: contain;
}
.tm-icon-svg {
    filter: var(--icon-filter, none);
}

/* ── Hover en inactivos ── */
.tm-group-container:not(.tm-group-open):hover,
.tm-root-card:not(.tm-root-expanded):not(:has(.tm-root-header.tm-selected)):hover {
    border-color: color-mix(in srgb, var(--color-accent) 35%, transparent);
    background: var(--color-bg-hover);
}

/* ============================================================
   ESTADO ACTIVO ── FROSTED GLASS con GLOW del acento
   ============================================================ */
.tm-group-container.tm-group-open,
.tm-root-card.tm-root-expanded {
    background: color-mix(in srgb, var(--color-accent) 10%, var(--color-bg-primary));
    border-color: color-mix(in srgb, var(--color-accent) 45%, transparent);
    box-shadow:
        0 0 0 1px color-mix(in srgb, var(--color-accent) 25%, transparent),
        0 4px 24px color-mix(in srgb, var(--color-accent) 20%, transparent),
        inset 0 1px 0 rgba(255, 255, 255, 0.06);
    overflow: visible;  /* para que el glow no se recorte */
}
/* Fallback para navegadores sin color-mix */
@supports not (color: color-mix(in srgb, red 10%, blue)) {
    .tm-group-container.tm-group-open,
    .tm-root-card.tm-root-expanded {
        background: var(--color-accent-subtle);
        border-color: var(--color-border-focus);
        box-shadow: 0 4px 20px rgba(0,0,0,0.25);
    }
}

/* Cuando está activo: la cabecera interna hereda el fondo */
.tm-group-container.tm-group-open > .tm-group-header,
.tm-root-card.tm-root-expanded > .tm-root-header {
    background: transparent;
}

/* Cabecera activa: texto e iconos en color acento */
.tm-group-container.tm-group-open > .tm-group-header .tm-group-caption,
.tm-root-card.tm-root-expanded > .tm-root-header .tm-root-caption {
    color: var(--color-accent) !important;
}

/* Icono del card activo: fondo más intenso */
.tm-group-container.tm-group-open > .tm-group-header .tm-group-icon,
.tm-root-card.tm-root-expanded > .tm-root-header .tm-root-icon {
    background: color-mix(in srgb, var(--color-accent) 22%, transparent);
}

/* Badge en activo: fondo y texto más prominentes */
.tm-group-container.tm-group-open > .tm-group-header .tm-group-badge,
.tm-root-card.tm-root-expanded > .tm-root-header .tm-root-badge {
    background: var(--color-accent);
    color: #ffffff;
}

/* Chevron rotado cuando abierto */
.tm-group-container.tm-group-open > .tm-group-header .tm-group-chevron,
.tm-root-card.tm-root-expanded > .tm-root-header .tm-root-chevron {
    transform: rotate(180deg);
    color: var(--color-accent);
}

/* ── Cuerpo del grupo: sin borde ni padding cuando colapsado ──
   El padding/borde solo aplica al estado expandido (ver .tm-group-open y .tm-root-expanded) */
.tm-group-body {
    background: transparent;
}

/* ROOT BODY */
.tm-root-body {
    background: transparent;
}

/* ── Filas de items hijos ── */
.tm-list .tm-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 7px 14px 7px 20px;
    cursor: pointer;
    border-radius: 6px;
    margin: 1px 6px;
    position: relative;
    transition: background 0.2s ease;
}

/* Bullet indicator (Concepto 5) */
.tm-list .tm-row::before {
    content: '';
    flex-shrink: 0;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--color-text-muted);
    opacity: 0.45;
    transition: all 0.25s ease;
    margin-right: 2px;
}

/* Hover en item hijo */
.tm-list .tm-row:hover {
    background: var(--color-accent-subtle);
}
.tm-list .tm-row:hover::before {
    background: var(--color-accent);
    opacity: 0.75;
}

/* Item hijo seleccionado */
.tm-list .tm-row.tm-selected {
    background: var(--color-accent-subtle);
}
.tm-list .tm-row.tm-selected::before {
    background: var(--color-accent);
    opacity: 1;
    box-shadow: 0 0 6px var(--color-accent);
}
.tm-list .tm-row.tm-selected .tm-row-label,
.tm-list .tm-row.tm-selected .tm-row-icon img {
    color: var(--color-accent);
    opacity: 1;
}

/* Iconos muted en items no seleccionados */
.tm-list .tm-row .tm-row-icon {
    opacity: 0.55;
    transition: opacity 0.2s ease;
}
.tm-list .tm-row:hover .tm-row-icon,
.tm-list .tm-row.tm-selected .tm-row-icon {
    opacity: 1;
}

/* Texto filas */
.tm-list .tm-row .tm-row-label {
    flex: 1;
    font-size: 0.8rem;
    color: var(--color-text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ── Sub-acordeón en hijos (si tienen sub-hijos) ── */
.tm-sub-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 7px 14px 7px 28px;
    cursor: pointer;
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--color-text-secondary);
    opacity: 0.9;
}
.tm-sub-header:hover { background: var(--color-accent-subtle); }
.tm-sub-chevron { color: var(--color-text-muted); transition: transform 0.2s ease; }
.tm-sub-card.tm-sub-open .tm-sub-chevron { transform: rotate(180deg); }

/* ── Eliminar trazas antiguas: bordes pseudo, pulse ── */
.tm-group-header::before,
.tm-group-header::after,
.tm-root-header::before,
.tm-root-header::after,
.tm-pulse {
    content: none !important;
    display: none !important;
}

/* ── Adaptación a temas claros (grey / light) ── */
[data-theme="ientop-grey"] .tm-group-container.tm-group-open,
[data-theme="ientop-grey"] .tm-root-card.tm-root-expanded,
[data-theme="ientop-light"] .tm-group-container.tm-group-open,
[data-theme="ientop-light"] .tm-root-card.tm-root-expanded,
[data-theme="indigo-light"] .tm-group-container.tm-group-open,
[data-theme="indigo-light"] .tm-root-card.tm-root-expanded,
[data-theme="amber-warm"] .tm-group-container.tm-group-open,
[data-theme="amber-warm"] .tm-root-card.tm-root-expanded {
    box-shadow:
        0 0 0 1px color-mix(in srgb, var(--color-accent) 35%, transparent),
        0 4px 20px color-mix(in srgb, var(--color-accent) 12%, transparent);
}

/* =================================================================
   MENU — Solo margen lateral (sin mejoras adicionales)
   ================================================================= */

/* Padding lateral en el acordeón para separar del borde del sidebar */
.tm-accordion {
    padding: 8px 10px !important;
    gap: 5px !important;
}

/* Eliminar completamente border-top de todos los body del menú
   (incluso colapsados, para evitar líneas fantasma) */
.tm-root-body,
.tm-root-expanded > .tm-root-body,
.tm-group-body,
.tm-group-container.tm-group-open > .tm-group-body {
    border: none !important;
    border-top: none !important;
    border-top-color: transparent !important;
}
.tm-group-body::before,
.tm-group-body::after,
.tm-root-body::before,
.tm-root-body::after {
    content: none !important;
    display: none !important;
}

/* =================================================================
   FIX — Espaciado vertical uniforme v3 (sin bloquear apertura)
   Solución: gap uniforme + quitar margin residual en todos los items
   ================================================================= */

/* Gap uniforme y sin margen en todos los elementos del acordeón */
.tm-accordion {
    gap: 6px !important;
}
.tm-accordion > .tm-group-container,
.tm-accordion > .tm-root-card {
    margin-top: 0 !important;
    margin-bottom: 0 !important;
}

/* =================================================================
   MÁRGENES Y SCROLL — Frames Contabilidad en #formarea
   Los paneles se inyectan DIRECTAMENTE en #formarea sin .ctb-content
   (contabilidad_engine.js: area.innerHTML = _sectionHTML(section)),
   así que aquí hay que darles el contenedor que en el standalone aporta
   .ctb-content y que Almacén y VeriFactu tienen en .alc-content/.vf-content.
   ================================================================= */

/* Contabilidad Fiscal: paneles de sección inyectados directamente.
   Sin overflow propio el contenido se recorta sin remedio: #formarea es
   `overflow:visible` y .app-body es `overflow:hidden`, de modo que todo lo
   que sobresale queda inalcanzable — no hay barra en ninguno de los dos.
   Medido en el dashboard: 1.401 px de contenido imposibles de ver. */
#formarea > .ctb-panel {
    padding: 20px 24px;
    box-sizing: border-box;
}

#formarea > .ctb-panel.active {
    padding: 20px 24px;
    box-sizing: border-box;
    height: 100%;        /* del #formarea, que ya es height:100% — no 100vh */
    min-height: 0;       /* sin esto el hijo no encoge y el scroll no aparece */
    overflow-y: auto;
    overflow-x: hidden;  /* el ancho lo resuelve el grid, no una barra lateral */
}

/* =================================================================
   PREMIUM HEADER OVERHAUL (Ajustes Popover & IA Drawer & Global Search)
   ================================================================= */
.hdr-actions-container {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 8px;
    position: relative; /* For the popovers */
    width: 280px; /* Ancho fijo para que el cuadrao de busqueda mantenga proporcion */
    order: 5;     /* IMPORTANT: Keeps it to the right of Company Info */
    flex: 0 1 auto;
    padding: 4px 0.75rem;
}

/* Fila de Arriba: Botones */
.hdr-actions-buttons {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    justify-content: flex-end;
}

/* Boton Estandar */
.btn-action {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--color-border);
    border-radius: 8px;
    color: var(--color-text-primary);
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.3s ease;
}
.btn-action:hover {
    background: rgba(255, 255, 255, 0.1);
}
.btn-action svg {
    transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}
.btn-action:hover svg {
    transform: rotate(45deg);
}
.btn-action svg, .btn-action span {
    pointer-events: none;
}

/* Boton Agente IA */
.btn-ia {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    background: linear-gradient(145deg, rgba(139, 92, 246, 0.15), rgba(217, 70, 239, 0.15));
    border: 1px solid rgba(217, 70, 239, 0.3);
    border-radius: 8px;
    color: var(--color-text-primary); /* Adaptable al tema claro/oscuro */
    font-size: 0.80rem; /* Reducido para evitar saltos */
    font-weight: 600;
    white-space: nowrap; /* Fuerza una sola linea */
    cursor: pointer;
    position: relative;
    overflow: hidden;
    transition: all 0.3s ease;
    animation: ia-pulse 3s infinite;
}
.btn-ia::before {
    content: '';
    position: absolute;
    top: 0; left: -100%;
    width: 50%; height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.2), transparent);
    transform: skewX(-20deg);
    transition: none;
}
.btn-ia:hover {
    background: linear-gradient(145deg, rgba(139, 92, 246, 0.25), rgba(217, 70, 239, 0.25));
    border-color: rgba(217, 70, 239, 0.6);
    box-shadow: 0 0 15px rgba(217, 70, 239, 0.4);
}
.btn-ia:hover::before {
    left: 200%;
    transition: left 0.7s ease-in-out;
}
@keyframes ia-pulse {
    0% { box-shadow: 0 0 0 0 rgba(217, 70, 239, 0.4); }
    70% { box-shadow: 0 0 0 8px rgba(217, 70, 239, 0); }
    100% { box-shadow: 0 0 0 0 rgba(217, 70, 239, 0); }
}

/* POPOVER PREFERENCIAS */
.settings-popover {
    position: absolute;
    top: 42px; /* Just below the buttons */
    right: 0;
    width: min(380px, calc(100vw - 20px)); /* responsive: nunca mas ancho que viewport */
    /* Limita altura al viewport. SOLO .theme-grid scrollea (via flex layout
       abajo). El resto de secciones (fechas Contexto Operativo, footer info)
       quedan SIEMPRE visibles. */
    max-height: calc(100vh - 60px);
    overflow: hidden;
    /* Flex column: las secciones fijas mantienen su altura natural,
       la seccion con theme-grid crece/encoge dinamicamente. */
    display: flex;
    flex-direction: column;
    background: color-mix(in srgb, var(--color-bg-header) 85%, transparent);
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
    border: 1px solid var(--color-border);
    border-radius: 12px;
    box-shadow: 0 20px 40px rgba(0,0,0,0.5);
    padding: 16px;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-10px) scale(0.95);
    transform-origin: top right;
    transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
    z-index: 999999 !important;
}

/* Por defecto las secciones tienen altura natural y NO se encogen */
.settings-popover > .popover-section { flex: 0 0 auto; }

/* La seccion que contiene .theme-grid es la unica flexible: ocupa lo sobrante
   y permite overflow del hijo. min-height:0 es CRITICO para que el hijo
   pueda hacer scroll dentro del flex item.
   Usa :has() (Chrome 105+, Edge 105+, Safari 15.4+, Firefox 121+). */
.settings-popover > .popover-section:has(.theme-grid) {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
}
.settings-popover.open {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
}
.popover-section { margin-bottom: 20px; }
.popover-section:last-child { margin-bottom: 0; }
.popover-header {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--color-text-secondary);
    display: block;
    border-bottom: 1px solid var(--color-border);
    padding-bottom: 6px;
    margin-bottom: 10px;
}

/* Theme Selector Grid */
.theme-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    /* Scroll vertical SOLO de la lista de temas, gestionado por flex del popover.
       min-height:0 + flex:1 1 auto permite que el grid encoja y muestre scroll
       cuando no cabe todo. Sin max-height fija (el flex calcula el espacio real). */
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    /* Pequeno padding-right para que el scrollbar no monte sobre los cards */
    padding-right: 4px;
}

/* Scrollbar discreto coherente con el tema */
.theme-grid::-webkit-scrollbar { width: 8px; }
.theme-grid::-webkit-scrollbar-track { background: transparent; }
.theme-grid::-webkit-scrollbar-thumb {
    background: var(--color-border);
    border-radius: 4px;
}
.theme-grid::-webkit-scrollbar-thumb:hover { background: var(--color-accent); }
/* Firefox */
.theme-grid { scrollbar-width: thin; scrollbar-color: var(--color-border) transparent; }
.theme-card {
    background: var(--color-bg-primary);
    border: 1px solid var(--color-border);
    border-radius: 8px;
    padding: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: all 0.2s;
}
.theme-card:hover { border-color: var(--color-accent); }
.theme-card.active {
    border-color: var(--color-accent);
    background: var(--color-accent-subtle);
}
.theme-circle { width: 12px; height: 12px; border-radius: 50%; border: 1px solid rgba(0,0,0,0.2); }

/* Contexto Operativo controls */
.popover-field {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 8px;
    font-size: 0.85rem;
    color: var(--color-text-primary);
}
.popover-field label { flex-shrink: 0; width: 75px; color: var(--color-text-secondary); }
.erp-date-input {
    flex: 1;
    background: var(--color-bg-input);
    border: 1px solid var(--color-border);
    color: var(--color-text-primary);
    padding: 4px 8px;
    border-radius: 6px;
    font-family: inherit;
    font-size: 0.85rem;
}
.exercise-segments {
    flex: 1;
    display: flex;
    align-items: stretch;
    background: var(--color-bg-primary);
    border-radius: 6px;
    padding: 4px;
    border: 1px solid var(--color-border);
    min-height: 30px;
}
.seg-btn {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    color: var(--color-text-secondary);
    padding: 0 8px;
    border-radius: 4px;
    font-family: inherit;
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.2s;
}
.seg-btn.active { background: var(--color-bg-secondary); color: var(--color-text-primary); box-shadow: var(--shadow-card); font-weight: 500; }

/* Switch iOS style */
.erp-switch { position: relative; display: inline-block; width: 34px; height: 20px; }
.erp-switch input { opacity: 0; width: 0; height: 0; }
.erp-slider {
    position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0;
    background-color: var(--color-bg-primary); transition: .4s;
    border: 1px solid var(--color-border);
}
.erp-slider:before {
    position: absolute; content: ""; height: 14px; width: 14px; left: 2px; bottom: 2px;
    background-color: var(--color-text-secondary); transition: .4s;
}
.erp-switch input:checked + .erp-slider { background-color: var(--color-accent); border-color: var(--color-accent); }
.erp-switch input:checked + .erp-slider:before { transform: translateX(14px); background-color: #fff; }
.erp-slider.round { border-radius: 20px; }
.erp-slider.round:before { border-radius: 50%; }

/* Status */
.popover-status { font-size: 0.8rem; color: var(--color-text-secondary); display: flex; align-items: center; gap: 8px;}
.status-led { display: inline-block; width: 8px; height: 8px; background: #10b981; border-radius: 50%; box-shadow: 0 0 8px #10b981;}

/* GLOBAL SEARCH */
.global-search-wrapper {
    position: relative;
    width: 100%;
}
/* Fila buscador + Ayuda (2026-07-12). En escritorio, el buscador ("Buscar") y
   Ayuda toman el MISMO tamaño que Asistente IA y Preferencias, formando una
   rejilla 2x2 alineada a la derecha (buscar = Asistente IA, Ayuda =
   Preferencias). En móvil (<=900px) se mantiene el comportamiento existente:
   botones a icono + buscador oculto (barra del menú lateral). */
.global-search-row {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    justify-content: flex-end;
}
.btn-help {
    text-decoration: none;
    white-space: nowrap;
}
@media (min-width: 901px) {
    /* El bloque de acciones se ajusta al contenido del 2x2 (antes width:280px
       FIJO, pensado para el buscador ancho de una sola columna). Con el 2x2 de
       botones de 150px ese ancho se quedaba corto y el contenido desbordaba
       hacia la izquierda pisando las badges (tamaño BD / versión) de la
       empresa. Con width:auto el bloque abraza los botones y queda limpio
       después del separador. */
    .hdr-actions-container { width: auto; }
    .hdr-actions-buttons { width: auto; }
    .global-search-row { width: auto; }
    .hdr-actions-buttons > .btn-ia,
    .hdr-actions-buttons > .btn-action { flex: 0 0 150px; justify-content: center; }
    .global-search-row .global-search-wrapper { flex: 0 0 150px; }
    .global-search-row .btn-help { flex: 0 0 150px; justify-content: center; }
}
.global-search-wrapper .search-icon {
    position: absolute;
    left: 10px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--color-text-secondary);
}
.erp-global-search {
    width: 100%;
    background: color-mix(in srgb, var(--color-bg-primary) 80%, black);
    border: 1px solid var(--color-border);
    color: var(--color-text-primary);
    padding: 6px 12px 6px 34px;
    border-radius: 8px;
    font-size: 0.85rem;
    transition: all 0.2s;
    box-sizing: border-box;
}
.erp-global-search:focus {
    outline: none;
    border-color: var(--color-accent);
    box-shadow: 0 0 0 2px var(--color-accent-subtle);
    background: var(--color-bg-secondary);
}
.btn-clear-search {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    background: transparent;
    border: none;
    color: var(--color-text-muted);
    cursor: pointer;
    padding: 2px;
    display: none;
    align-items: center;
    justify-content: center;
}
.btn-clear-search:hover { color: var(--color-text-primary); }

/* RESULTS POPOVER OMNIBOX */
.search-results-popover {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    width: 100%;
    min-width: 300px;
    background: color-mix(in srgb, var(--color-bg-header) 85%, transparent);
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
    border: 1px solid var(--color-border);
    border-radius: 12px;
    box-shadow: 0 20px 40px rgba(0,0,0,0.5);
    padding: 8px;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-5px);
    transition: all 0.2s;
    z-index: 999999 !important;
}
.search-results-popover.open {
    opacity: 1; visibility: visible; transform: translateY(0);
}
.search-results-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.search-result-item {
    padding: 8px 12px;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    gap: 2px;
    transition: background 0.2s;
}
.search-result-item:hover {
    background: var(--color-bg-hover);
}
.search-result-title { font-size: 0.85rem; font-weight: 500; color: var(--color-text-primary); display: flex; align-items: center; justify-content: space-between;}
.search-result-title span.badge { font-size: 0.65rem; background: var(--color-border); padding: 2px 6px; border-radius: 10px; color: var(--color-text-secondary);}
.search-result-desc { font-size: 0.75rem; color: var(--color-text-muted); }

/* IA DRAWER — centrado, ancho generoso pero no full-screen. */
.ia-drawer {
    position: fixed !important;
    top: 60px !important;
    left: 50% !important;
    transform: translateX(-50%) !important;
    width: 1200px !important;
    /* Porcentajes, no vw/vh: es position:fixed, asi que el 100% es el viewport,
       y a diferencia de 100vh se escala con el zoom del body. Con 100vh el
       drawer se quedaba ~100px corto con zoom 0.9 y se salia con 1.25
       (medido 02-09-2026: bottom 621 -> 693 de 720). */
    max-width: 90% !important;
    height: calc(100% - 90px) !important;
    max-height: calc(100% - 90px) !important;
    z-index: 999999 !important;
    background: color-mix(in srgb, var(--color-bg-secondary) 92%, transparent);
    backdrop-filter: blur(30px);
    -webkit-backdrop-filter: blur(30px);
    border: 1px solid rgba(217, 70, 239, 0.4);
    border-radius: 12px;
    box-shadow: 0 20px 50px rgba(0,0,0,0.55);
    display: none !important;
    flex-direction: column !important;
    align-items: stretch !important;             /* hijos al 100% ancho */
    overflow: hidden;
    padding: 0 !important;
    box-sizing: border-box !important;
}
/* .ia-body: contenedor del chat — siempre 100% ancho, sin padding, block layout. */
.ia-drawer > .ia-body {
    width: 100% !important;
    flex: 1 1 auto !important;
    min-height: 0 !important;
    padding: 0 !important;
    margin: 0 !important;
    display: block !important;
    box-sizing: border-box !important;
    align-items: stretch !important;
    justify-content: flex-start !important;
    text-align: left !important;
}
.ia-drawer.open { display: flex !important; }
.ia-header {
    padding: 20px; border-bottom: 1px solid var(--color-border);
    display: flex; align-items: center; justify-content: space-between;
}
.ia-title { display: flex; align-items: center; gap: 10px; font-weight: 500; font-size: 1.1rem; background: -webkit-linear-gradient(45deg, #a78bfa, #f472b6); -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent;}
.btn-close-ia { background: transparent; border: none; color: var(--color-text-secondary); cursor: pointer; padding: 4px; }
.btn-close-ia:hover { color: var(--color-text-primary); }
/* .ia-body por defecto: placeholder centrado con padding (estado vacío). */
.ia-body { flex: 1; padding: 20px; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; color: var(--color-text-secondary); min-height: 0; }
/* Cuando el chat IA ya está montado dentro, el .ia-body es solo contenedor:
   sin padding, sin centrar, dejar que el engine maneje su layout. */
.ia-body:has(.cps-asistente-root-flex) {
    padding: 0 !important;
    align-items: stretch !important;
    justify-content: flex-start !important;
    text-align: left !important;
}
.ia-body svg { opacity: 0.2; margin-bottom: 20px; }

/* REGLAS ESTRICTAS PARA MODO COMPACTO <= 900px (Evitar que el bloque IA y Ajustes desaparezca o desborde) */
@media (max-width: 900px) {
    .hdr-actions-container {
        display: flex !important;
        flex-direction: row !important;
        width: auto !important;
        min-width: 0 !important;
        order: 10 !important; 
        padding: 0 4px !important;
        gap: 8px !important;
        align-items: center !important;
        margin-left: auto !important;
    }
    .hdr-actions-buttons {
        gap: 8px !important;
    }
    /* Mantenemos el texto visible para los botones */
    .btn-ia span, 
    .btn-action span {
        display: inline-block !important; 
    }
    .btn-ia, 
    .btn-action {
        width: auto !important;
        height: auto !important;
        padding: 6px 12px !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
    }
    .global-search-wrapper {
        display: none !important; /* Ocultamos la barra global ancha, se usará la del menú lateral (hamburguesa) */
    }
}
/* =================================================================
   GLOBAL MODAL CONTAINMENT FIX (2026-04-18)
   Los modales se appendean dentro de #content-host con position:absolute,
   centrados en la zona del frame (no en toda la pantalla).
   content-host ya tiene position:relative y overflow:auto.
   ================================================================= */
.content-host {
    /* Asegurar que es el containing block para modales absolutos */
    position: relative !important;
}

/* Cuando un modal esta abierto dentro de content-host,
   el overlay cubre exactamente el area visible del frame */
.content-host > .cps-address-root,
.content-host > .ter-overlay {
    position: absolute !important;
    top: 0 !important;
    left: 0 !important;
    width: 100% !important;
    min-height: 100% !important;
    z-index: 9999 !important;
}

/* =================================================================
   SHELL MÓVIL (≤ 900 px: teléfono y tableta en vertical) — 10-11-2026
   Una sola fila de cabecera (≈56 px) en todos los ERP: hamburguesa, logo,
   campana, «Actividad» (las cuatro islas en un panel), Asistente IA,
   Preferencias y Ayuda, solo con icono. Antes la cabecera medía 317 px en un
   móvil de 412×915 (logo de 75 px, botones con texto, fila propia para la
   hamburguesa y las cuatro pastillas apiladas) y el menú lateral arrancaba
   abierto encima del trabajo.
   Desde 900 px hacia abajo el carril lateral desaparece y el menú pasa a ser
   una capa: es el tramo «móvil» del shell (las PANTALLAS cortan en 760 px,
   bloque siguiente). Este bloque va AL FINAL a propósito: manda sobre los
   parches de 600/800/900 px de arriba. Piezas JS: el botón y el
   panel de actividad (Sistema/js/cps-islands.js), el menú cerrado al arrancar
   (navigation.js) y el cierre al navegar (cps-treemenu.js).
   ================================================================= */

/* Tableta vertical (761-900 px): hay sitio para un logo algo mayor */
@media (min-width: 761px) and (max-width: 900px) {
    .hdr-brand img { height: 38px !important; max-width: 132px !important; }
}

/* Escritorio: el panel de actividad es transparente y su botón no existe */
.di-sheet { display: contents; }
.di-mobile-toggle,
.di-sheet-inbox { display: none; }

@media (max-width: 900px) {
    :root { --shell-hdr-h: 56px; }

    /* ── Cabecera: una sola fila ─────────────────────────────── */
    .header {
        display: flex !important;
        flex-wrap: nowrap !important;
        align-items: center !important;
        gap: 2px !important;
        height: var(--shell-hdr-h) !important;
        min-height: var(--shell-hdr-h) !important;
        padding: 0 6px 0 4px !important;
        row-gap: 0 !important;
    }
    .header > .hdr-divider,
    .header > .hdr-company,
    .header > .hdr-context,
    .header > .hdr-extra { display: none !important; }

    .btn-mobile-toggle {
        display: inline-flex !important;
        order: 0 !important;
        flex: 0 0 40px !important;
        width: 40px !important;
        height: 40px !important;
        margin: 0 !important;
        padding: 0 !important;
        align-items: center;
        justify-content: center;
        border-radius: 10px;
        color: var(--color-text-primary);
    }
    .btn-mobile-toggle svg { width: 22px; height: 22px; }

    .hdr-brand {
        order: 1 !important;
        flex: 0 1 auto !important;
        min-width: 0 !important;
        width: auto !important;
        padding: 0 4px 0 2px !important;
        margin: 0 !important;
        border: none !important;
    }
    /* El logo lleva su altura en línea (75px) */
    .hdr-brand img { height: 30px !important; max-width: 104px !important; }
    /* Cabeceras sin islas (el panel de Fichajes, Admin.html): la marca va junto al
       menú y con su nombre entero, no empujada al otro extremo y cortada a 120 px.
       En los ERP no cambia nada: las islas (flex 1) ocupan el hueco igualmente. */
    .header { justify-content: flex-start !important; }
    .hdr-brand-title { max-width: none; }

    /* ── Fila de iconos a la derecha: campana + actividad ─────── */
    #erp-islands-container,
    .hdr-islands {
        order: 2 !important;
        display: flex !important;
        flex: 1 1 auto !important;
        flex-wrap: nowrap !important;
        justify-content: flex-end !important;
        align-items: center !important;
        min-width: 0 !important;
        width: auto !important;
        gap: 2px !important;
        margin: 0 !important;
        padding: 0 !important;
        border: none !important;
        background: transparent !important;
    }
    #erp-islands-container > *:not(.di-sheet) { flex: 0 0 auto; }
    /* La campana no se pinta aparte: su bandeja se abre desde el pie del panel */
    #cps-ntf-bell-btn { display: none !important; }

    .di-mobile-toggle {
        display: inline-flex;
        position: relative;
        align-items: center;
        justify-content: center;
        width: 38px;
        height: 38px;
        padding: 0;
        border-radius: 8px;
        border: 1px solid transparent;
        background: transparent;
        color: var(--color-text-secondary);
        cursor: pointer;
    }
    .di-mobile-toggle:hover,
    #erp-islands-container.di-sheet-open .di-mobile-toggle {
        background: var(--color-bg-hover);
        border-color: var(--color-border);
        color: var(--color-text-primary);
    }
    .di-mobile-badge {
        position: absolute;
        top: 0;
        right: 0;
        min-width: 18px;
        height: 18px;
        padding: 0 5px;
        border-radius: 9px;
        background: var(--color-accent);
        color: #fff;
        font-size: 10px;
        font-weight: 700;
        line-height: 1;
        display: flex;
        align-items: center;
        justify-content: center;
        border: 2px solid var(--color-bg-card);
    }
    .di-mobile-badge.hidden { display: none; }

    /* ── Panel de actividad: las cuatro islas en una lista ───── */
    .di-sheet {
        display: none;
        position: fixed;
        top: calc(var(--shell-hdr-h) + 6px);
        left: 8px;
        right: 8px;
        max-height: calc(100% - var(--shell-hdr-h) - 16px);
        overflow-y: auto;
        flex-direction: column;
        gap: 6px;
        padding: 10px;
        background: var(--color-bg-sidebar);
        border: 1px solid var(--color-border);
        border-radius: 14px;
        box-shadow: 0 18px 48px rgba(0, 0, 0, 0.5);
        z-index: 10;
    }
    #erp-islands-container.di-sheet-open .di-sheet {
        display: flex;
        animation: diSheetIn 0.18s ease-out;
    }
    @keyframes diSheetIn {
        from { opacity: 0; transform: translateY(-6px); }
        to   { opacity: 1; transform: translateY(0); }
    }
    .di-sheet .dynamic-island {
        width: 100%;
        min-width: 0 !important;
        height: auto !important;
        min-height: 46px;
        padding: 0 14px !important;
        border-radius: 12px !important;
        flex-direction: column;
        align-items: stretch;
        justify-content: center;
        white-space: normal;
        box-shadow: none !important;
    }
    .di-sheet .di-compact { min-height: 44px; gap: 10px; }
    .di-sheet .di-compact svg { width: 18px; height: 18px; }
    .di-sheet .di-text { max-width: none; font-size: 0.875rem; }
    .di-sheet-inbox {
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 8px;
        min-height: 44px;
        margin-top: 4px;
        border-radius: 12px;
        border: 1px solid var(--color-border);
        background: transparent;
        color: var(--color-text-primary);
        font: inherit;
        font-size: 0.875rem;
        font-weight: 600;
        cursor: pointer;
    }
    .di-sheet-inbox:hover { background: var(--color-bg-hover); }
    /* El historial de cada isla se despliega dentro de la lista, no flotando */
    .di-sheet .di-expanded-panel {
        position: static !important;
        transform: none !important;
        width: auto !important;
        margin: 2px 0 10px;
        box-shadow: none !important;
        animation: none !important;
    }

    /* ── Acciones: solo icono ────────────────────────────────── */
    .hdr-actions-container,
    #hdr-block-actions {
        order: 3 !important;
        flex: 0 0 auto !important;
        width: auto !important;
        min-width: 0 !important;
        margin: 0 !important;
        padding: 0 !important;
        display: flex !important;
        flex-direction: row !important;
        align-items: center !important;
        gap: 2px !important;
    }
    .hdr-actions-buttons,
    .global-search-row {
        display: flex !important;
        flex-direction: row !important;
        width: auto !important;
        gap: 2px !important;
        margin: 0 !important;
        padding: 0 !important;
    }
    .global-search-wrapper { display: none !important; }
    .btn-ia,
    .btn-action {
        flex: 0 0 38px !important;
        width: 38px !important;
        height: 38px !important;
        min-width: 0 !important;
        padding: 0 !important;
        justify-content: center !important;
        gap: 0 !important;
        border-radius: 8px !important;
    }
    .btn-ia span,
    .btn-action span { display: none !important; }

    /* Preferencias: panel a lo ancho bajo la cabecera */
    .settings-popover {
        position: fixed !important;
        top: calc(var(--shell-hdr-h) + 6px) !important;
        left: 8px !important;
        right: 8px !important;
        width: auto !important;
        max-height: calc(100% - var(--shell-hdr-h) - 16px) !important;
    }

    /* Preferencias con el dedo: el selector de ejercicio medía 20 px de alto y el zoom
       22×22 (estilo en línea de navigation.js, de ahí el !important) */
    .settings-popover .seg-btn { min-height: 36px; }
    #ui-zoom-dec, #ui-zoom-inc { width: 36px !important; height: 36px !important; }
    #ui-zoom-controls { padding: 0 2px !important; }

    /* Asistente IA: pantalla completa bajo la cabecera */
    .ia-drawer {
        top: var(--shell-hdr-h) !important;
        left: 0 !important;
        transform: none !important;
        width: 100% !important;
        max-width: 100% !important;
        height: calc(100% - var(--shell-hdr-h)) !important;
        max-height: calc(100% - var(--shell-hdr-h)) !important;
        border-radius: 0 !important;
        border-left: none !important;
        border-right: none !important;
    }

    /* ── Menú lateral: capa sobre el trabajo, con fondo ─────── */
    .sidebar-drawer {
        position: absolute !important;
        top: 0;
        bottom: 0;
        left: 0;
        width: min(86vw, 340px) !important;
        max-width: none !important;
        z-index: 101 !important;
        box-shadow: 8px 0 32px rgba(0, 0, 0, 0.45);
    }
    .sidebar-drawer.collapsed {
        width: 0 !important;
        min-width: 0 !important;
        box-shadow: none;
    }
    /* El cajón vive dentro de .sidebar-wrapper, que con su z-index:30 es un contexto de
       apilamiento propio: sin esto el fondo (z 100, abajo) quedaba ENCIMA del menú y en un
       móvil ningún toque llegaba a las opciones (medido con elementFromPoint, 10-11-2026) */
    .app-body > .sidebar-wrapper { z-index: 101; }
    .app-body:has(> .sidebar-wrapper .sidebar-drawer:not(.collapsed))::after {
        content: "";
        position: absolute;
        inset: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 100;
    }
}

/* =================================================================
   PANTALLAS EN MÓVIL (≤ 760 px) — capa común, 10-11-2026
   Lo que se repite en todos los motores y no merece una regla en cada
   uno. Lo propio de cada pantalla va en el CSS de su módulo, en su bloque
   «TELÉFONO (≤ 760 px)», que manda sobre esto.
   ================================================================= */
@media (max-width: 760px) {
    /* Rejillas con las columnas escritas en línea (muy usado en los motores):
       tres columnas → una; cuatro o más → dos. Las rejillas auto-fit/auto-fill
       ya se adaptan solas y no se tocan. «html > div»: las ventanas de los
       motores se montan en <html>, fuera de #formarea (patrón de modales). */
    :is(#formarea, #adminContentMount) [style*="grid-template-columns: 1fr 1fr 1fr"],
    html > div [style*="grid-template-columns: 1fr 1fr 1fr"],
    :is(#formarea, #adminContentMount) [style*="grid-template-columns:1fr 1fr 1fr"],
    html > div [style*="grid-template-columns:1fr 1fr 1fr"],
    :is(#formarea, #adminContentMount) [style*="grid-template-columns: repeat(3,"],
    html > div [style*="grid-template-columns: repeat(3,"],
    :is(#formarea, #adminContentMount) [style*="grid-template-columns:repeat(3,"],
    html > div [style*="grid-template-columns:repeat(3,"],
    :is(#formarea, #adminContentMount) [style*="grid-template-columns: repeat(3 ,"] ,
    html > div [style*="grid-template-columns: repeat(3 ,"] {
        grid-template-columns: minmax(0, 1fr) !important;
    }
    :is(#formarea, #adminContentMount) [style*="grid-template-columns: 1fr 1fr 1fr 1fr"],
    html > div [style*="grid-template-columns: 1fr 1fr 1fr 1fr"],
    :is(#formarea, #adminContentMount) [style*="grid-template-columns:1fr 1fr 1fr 1fr"],
    html > div [style*="grid-template-columns:1fr 1fr 1fr 1fr"],
    :is(#formarea, #adminContentMount) [style*="grid-template-columns: repeat(4,"],
    html > div [style*="grid-template-columns: repeat(4,"],
    :is(#formarea, #adminContentMount) [style*="grid-template-columns:repeat(4,"],
    html > div [style*="grid-template-columns:repeat(4,"],
    :is(#formarea, #adminContentMount) [style*="grid-template-columns: repeat(5,"],
    html > div [style*="grid-template-columns: repeat(5,"],
    :is(#formarea, #adminContentMount) [style*="grid-template-columns:repeat(5,"],
    html > div [style*="grid-template-columns:repeat(5,"],
    :is(#formarea, #adminContentMount) [style*="grid-template-columns: repeat(6,"],
    html > div [style*="grid-template-columns: repeat(6,"],
    :is(#formarea, #adminContentMount) [style*="grid-template-columns:repeat(6,"] ,
    html > div [style*="grid-template-columns:repeat(6,"] {
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    }

    /* Tablas anchas: se desplazan de lado dentro de su caja, en vez de
       cortarse contra el borde (el shell no deja desplazar la página). */
    :is(#formarea, #adminContentMount) *:has(> table),
    html > div *:has(> table) {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        max-width: 100%;
    }
    /* Encabezados en una línea: ninguna columna más estrecha que su título
       (sin esto las celdas partían las palabras letra a letra) */
    :is(#formarea, #adminContentMount) table th,
    html > div table th { white-space: nowrap; }

    /* Contenedor estándar de pantalla (.frame-*, el Home y los frames de la
       librería común): los bloques no encogen dentro de la columna con scroll
       (la tarjeta de suscripción del Home quedaba en 48 px de 107) y la
       cabecera cabe en una fila. */
    :is(#formarea, #adminContentMount) .frame-work > * { flex-shrink: 0; }
    :is(#formarea, #adminContentMount) .frame-header {
        flex-wrap: nowrap;
        gap: 8px;
        padding: 10px 12px;
    }
    :is(#formarea, #adminContentMount) .frame-header h2 {
        min-width: 0;
        font-size: 1.05rem;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
    :is(#formarea, #adminContentMount) .frame-header .frame-actions { flex: 0 0 auto; gap: 6px; }
    :is(#formarea, #adminContentMount) .frame-work { padding-left: 12px; padding-right: 12px; }

    /* Home: KPIs de dos en dos (en línea con auto-fit de 220 px salían de uno en
       uno) e importes que no se salen de la tarjeta */
    #kpi-banner { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; gap: 0.625rem !important; }
    #kpi-banner > .card { padding: 0.75rem 0.875rem !important; min-width: 0; }
    #kpi-banner span[id^="kpi-"][style*="1.75rem"] {
        font-size: clamp(1rem, 4.6vw, 1.3rem) !important;
        font-variant-numeric: tabular-nums;
        white-space: nowrap;
    }
    /* «Refrescar» del Home solo con su icono: el título cabe entero */
    #btn-refresh-home { font-size: 0; gap: 0; width: 36px; height: 36px; padding: 0; justify-content: center; }
    #btn-refresh-home svg, #btn-refresh-home i { width: 16px !important; height: 16px !important; }

    /* Editor transversal de terceros (cps-tercero-editor.js): razón social a lo
       ancho, CIF y país debajo; móvil y email de uno en uno */
    .cte-fila-ident {
        grid-template-columns: minmax(0, 1fr) 84px !important;
        gap: 10px !important;
    }
    .cte-fila-ident > div:first-child { grid-column: 1 / -1; }
    .cte-fila-contacto { grid-template-columns: minmax(0, 1fr) !important; gap: 10px !important; }
    /* el aspa del editor medía 28×35: objetivo táctil de 40 px */
    #cte-close { min-width: 40px; min-height: 40px; }

    /* Imágenes y lienzos nunca más anchos que la pantalla */
    :is(#formarea, #adminContentMount) img,
    :is(#formarea, #adminContentMount) canvas,
    :is(#formarea, #adminContentMount) svg:not([width]) { max-width: 100%; }
}

/* Tableta vertical (761-900 px): las pantallas usan su maqueta de escritorio
   compacto, pero las tablas anchas también se desplazan dentro de su caja en vez
   de cortarse contra el borde (mismo criterio que el teléfono). */
@media (min-width: 761px) and (max-width: 900px) {
    /* !important: muchos motores envuelven la tabla en una caja con
       overflow:hidden en línea (para las esquinas), que la recortaba */
    :is(#formarea, #adminContentMount) *:has(> table),
    html > div *:has(> table) {
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch;
        max-width: 100%;
    }
    :is(#formarea, #adminContentMount) table th,
    html > div table th { white-space: nowrap; }
}

/* Tableta táctil (761-900 px con dedo): el aspa del editor de terceros, 40 px como en el
   teléfono (10-11-2026). Con ratón no cambia nada. */
@media (min-width: 761px) and (max-width: 900px) and (pointer: coarse) {
    #cte-close { min-width: 40px; min-height: 40px; }
}

/* Campos a 16 px en teléfono y en tableta táctil (10-11-2026; antes solo ≤ 760 px) */
@media (max-width: 760px), (max-width: 900px) and (pointer: coarse) {
    /* Campos de 16 px: con menos, el iPhone (y el iPad) amplían la página al escribir.
       En teléfono siempre; en tableta solo con dedo (pointer: coarse), con ratón no cambia. */
    :is(#formarea, #adminContentMount) input[type="text"],
    html > div input[type="text"],
    :is(#formarea, #adminContentMount) input[type="search"],
    html > div input[type="search"],
    :is(#formarea, #adminContentMount) input[type="email"],
    html > div input[type="email"],
    :is(#formarea, #adminContentMount) input[type="tel"],
    html > div input[type="tel"],
    :is(#formarea, #adminContentMount) input[type="number"],
    html > div input[type="number"],
    :is(#formarea, #adminContentMount) input[type="password"],
    html > div input[type="password"],
    :is(#formarea, #adminContentMount) input[type="date"],
    html > div input[type="date"],
    :is(#formarea, #adminContentMount) input:not([type]),
    html > div input:not([type]),
    :is(#formarea, #adminContentMount) select,
    html > div select,
    :is(#formarea, #adminContentMount) textarea,
    html > div textarea { font-size: 16px !important; }
}
