/* v2.2. Mejora progresiva: el CSS cubre el primer render; device.js administra
   foco, teclado y cambios de orientacion sin volver a crear el iframe. */
:root { --safe-top: env(safe-area-inset-top,0px); --safe-bottom: env(safe-area-inset-bottom,0px); --app-height: 100dvh; }
.drawer-head,.drawer-search,.mobile-tabbar,.mobile-search-toggle,.search-close,.frame-menu { display: none; }
.connection-banner { position: fixed; z-index: 75; bottom: 22px; left: 50%; transform: translateX(-50%); width: max-content; max-width: calc(100% - 32px); padding: 12px 18px; border-radius: 12px; background: #813f13; color: white; font-size: 13px; box-shadow: var(--shadow); }
body[data-view=embedded] { overflow: hidden; }
.workspace-focus .topbar,.workspace-focus .mobile-tabbar { display: none !important; }
.workspace-focus .workspace.workspace-embedded { position: fixed; inset: 0; height: var(--app-height); min-height: 0; margin: 0; padding: max(8px,var(--safe-top)) max(8px,env(safe-area-inset-right,0px)) max(8px,var(--safe-bottom)) max(8px,env(safe-area-inset-left,0px)); z-index: 24; }
.workspace-focus .embedded-panel { border-radius: 12px; }
.workspace-focus .sidebar { z-index: 46; }
/* Desktop focus keeps the sidebar available rather than hiding it. */
@media (min-width: 981px) and (pointer: fine), (min-width: 1181px) {
  .workspace-focus .workspace.workspace-embedded { margin-left: calc(var(--sidebar) + 24px); }
  .workspace-focus .sidebar { top: 8px; }
}
.touch-device .button,.touch-device .icon-button,.touch-device .icon-option,.touch-device .table-inline-button { min-height: 44px; }
.touch-device .icon-button,.touch-device .icon-option { min-width: 44px; }
.touch-device .permission-item { min-height: 52px; }
@media (hover: none) { .module-card:hover { transform: none; } }

@media (max-width: 980px), (max-width: 1180px) and (pointer: coarse) {
  :root { --compact-top: calc(66px + var(--safe-top)); --compact-bottom: calc(66px + var(--safe-bottom)); --sidebar: 320px; }
  html { scroll-padding-top: calc(var(--compact-top) + 10px); -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
  body { min-height: var(--app-height); }
  body::before { background-image: linear-gradient(115deg,rgba(20,29,35,.33),rgba(20,29,35,.14)),url('./assets/fondo.jpg'); }
  body.sidebar-open { overflow: hidden; }
  .shell { min-height: var(--app-height); }
  .button,.button.small,.button.compact,.admin-toolbar .button,.admin-heading .button,.icon-button,.icon-option,.table-inline-button { min-height: 44px; }
  .icon-button,.icon-option,.table-actions .icon-button,.embedded-actions .button { min-width: 44px; width: 44px; height: 44px; }
  .button { font-size: 14px; }
  .text-button { min-height: 44px; display: inline-flex; align-items: center; }
  input:not([type=checkbox]),select,textarea,.global-search input { font-size: 16px; min-height: 48px; }
  .field label { font-size: 13px; }
  input[type=checkbox] { width: 20px; height: 20px; }
  .checkbox { min-height: 44px; font-size: 14px; }
  .login-screen { min-height: var(--app-height); padding: max(24px,var(--safe-top)) 18px max(24px,var(--safe-bottom)); }
  .login-card { width: min(100%,440px); padding: 30px 26px 25px; border-radius: 23px; }
  .login-logo { height: auto; width: 215px; margin-bottom: 24px; }
  .login-heading h1 { font-size: 27px; }
  .login-heading p { font-size: 14px; }
  .login-form { margin-top: 24px; }
  .input-wrap input { min-height: 52px; padding-right: 50px; }
  .input-wrap > .icon-button { width: 44px; height: 44px; right: 4px; }
  .login-submit { min-height: 52px; font-size: 16px; }
  .login-options { margin: 10px 0 16px; }
  .login-options .checkbox { font-size: 14px; }
  .login-note { font-size: 11px; margin-top: 21px; }
  .topbar { position: fixed; top: 0; left: 0; right: 0; height: var(--compact-top); min-height: 0; padding: calc(var(--safe-top) + 7px) max(14px,env(safe-area-inset-right,0px)) 7px max(10px,env(safe-area-inset-left,0px)); gap: 8px; flex-wrap: nowrap; border-radius: 0 0 18px 18px; box-shadow: 0 4px 20px rgba(20,30,40,.09); }
  .mobile-menu,.mobile-search-toggle { display: inline-flex; }
  .brand { width: auto; margin-right: auto; justify-content: flex-start; }
  .brand img { width: 112px; height: 49px; }
  .top-title { display: none; }
  .account { margin: 0; }
  .account summary { padding: 3px; min-width: 44px; min-height: 44px; gap: 0; }
  .account summary > .icon,.account-name,.account-role { display: none; }
  .avatar { width: 36px; height: 36px; font-size: 12px; }
  .account-popup { width: min(285px,calc(100vw - 28px)); top: calc(100% + 14px); }
  .account-popup .nav-button { min-height: 48px; }
  .global-search { display: none; position: absolute; top: calc(100% + 8px); left: 12px; right: 12px; margin: 0; max-width: none; width: auto; background: white; border-radius: 13px; box-shadow: 0 6px 24px rgba(20,30,40,.13); }
  .global-search input { height: 50px; padding-right: 50px; border-radius: 13px; background: white; }
  .global-search > .icon { top: 16px; left: 15px; width: 19px; height: 19px; }
  .global-search kbd { display: none; }
  .search-open .global-search { display: block; }
  .search-close { display: inline-flex; position: absolute; right: 4px; top: 3px; }
  .search-open { --compact-top: calc(126px + var(--safe-top)); }
  .search-open .topbar { height: calc(66px + var(--safe-top)); }
  .sidebar { top: 0; bottom: 0; left: 0; width: min(340px,calc(100vw - 36px)); padding: calc(var(--safe-top) + 16px) 16px max(16px,var(--safe-bottom)); border: 0; border-radius: 0 24px 24px 0; background: #fff; z-index: 46; transform: translateX(-105%); visibility: hidden; transition: transform .2s ease,visibility .2s; overflow: hidden; box-shadow: 8px 0 40px rgba(20,30,40,.18); }
  .sidebar-open .sidebar { left: 0; transform: translateX(0); visibility: visible; }
  .drawer-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-shrink: 0; margin-bottom: 16px; padding: 0 4px; }
  .drawer-head strong { display: block; font-size: 22px; letter-spacing: -.04em; }
  .drawer-head span { display: block; color: var(--muted); font-size: 13px; margin-top: 5px; max-width: 225px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
  .drawer-search { position: relative; display: block; flex-shrink: 0; margin-bottom: 12px; }
  .drawer-search > .icon { position: absolute; left: 13px; top: 15px; width: 19px; height: 19px; color: var(--muted); }
  .drawer-search input { padding-left: 40px; background: #f7f8fa; }
  .nav-caption { padding: 6px 12px 10px; font-size: 10px; }
  .sidebar .nav-button { min-height: 48px; font-size: 14px; gap: 13px; }
  .sidebar .access-caption { padding-top: 15px; }
  .sidebar-accesses { min-height: 0; flex: 1 1 auto; overscroll-behavior-y: contain; }
  .sidebar .sidebar-bottom { margin-top: 10px; padding-top: 8px; }
  .sidebar .sidebar-bottom .nav-button { font-size: 13px; min-height: 44px; }
  .sidebar-meta { display: none; }
  .mobile-overlay { position: fixed; inset: 0; z-index: 45; background: rgba(18,26,35,.43); backdrop-filter: blur(2px); border: 0; }
  .sidebar-open .mobile-overlay { display: block; }
  .mobile-tabbar { display: grid; grid-template-columns: repeat(4,minmax(0,1fr)); align-items: start; position: fixed; bottom: 0; left: 0; right: 0; z-index: 22; min-height: var(--compact-bottom); padding: 5px max(8px,env(safe-area-inset-right,0px)) max(5px,var(--safe-bottom)) max(8px,env(safe-area-inset-left,0px)); border-top: 1px solid #ece7e1; background: rgba(255,255,255,.985); border-radius: 17px 17px 0 0; box-shadow: 0 -5px 25px rgba(22,30,40,.08); }
  .mobile-tab { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; min-height: 54px; background: none; border: 0; border-radius: 12px; color: #69717f; font-size: 11px; font-weight: 500; padding: 4px; }
  .mobile-tab .icon { width: 22px; height: 22px; }
  .mobile-tab.active { color: #a44b09; background: #fff3e6; }
  .workspace { margin-left: 0; padding: calc(var(--compact-top) + 24px) max(20px,env(safe-area-inset-right,0px)) calc(var(--compact-bottom) + 24px) max(20px,env(safe-area-inset-left,0px)); }
  .workspace::before { left: 0; top: var(--compact-top); }
  .page-inner { max-width: 860px; }
  .welcome { min-height: 0; margin-bottom: 21px; }
  .welcome h1 { font-size: clamp(25px,4vw,32px); line-height: 1.22; }
  .welcome p { font-size: 14px; margin-top: 9px; }
  .date-pill { display: none; }
  .menu-toolbar { display: block; margin-bottom: 15px; }
  .category-list { display: flex; flex-wrap: nowrap; gap: 7px; overflow-x: auto; scrollbar-width: thin; padding: 2px 1px 5px; overscroll-behavior-x: contain; }
  .chip { font-size: 12px; padding: 10px 14px; min-height: 44px; flex: 0 0 auto; }
  .menu-total { display: block; margin: 9px 0 0; font-size: 12px; }
  .modules-grid { grid-template-columns: repeat(2,minmax(0,1fr)); gap: 13px; }
  .module-card { backdrop-filter: none; border-radius: 16px; }
  .card-link { padding: 20px 18px 17px; }
  .card-top { flex-direction: row; gap: 13px; }
  .module-icon { width: 48px; height: 48px; border-radius: 12px; }
  .card-text h2 { font-size: 17px; margin-bottom: 6px; }
  .card-text p { font-size: 13px; min-height: 0; line-height: 1.45; }
  .card-bottom { margin-top: 17px; padding-right: 40px; font-size: 11px; min-height: 25px; }
  .card-bottom .card-category { display: inline; }
  .favorite { bottom: 7px; right: 8px; width: 44px; height: 44px; }
  .favorite .icon { width: 19px; height: 19px; }
  .menu-footer { margin-top: 18px; padding-top: 0; color: #334052; font-size: 12px; }
  .menu-footer .text-button { font-size: 12px; }
  .workspace.workspace-embedded { padding: calc(var(--compact-top) + 8px) max(8px,env(safe-area-inset-right,0px)) calc(var(--compact-bottom) + 8px) max(8px,env(safe-area-inset-left,0px)); height: var(--app-height); min-height: 0; }
  .workspace-embedded .page-inner { height: 100%; max-width: none; }
  .embedded-toolbar { padding: 9px 12px 8px; display: flex; flex-wrap: wrap; gap: 7px; }
  .embedded-heading { gap: 9px; width: 100%; }
  .embedded-heading .module-icon { display: inline-flex; width: 28px; height: 28px; border-radius: 8px; }
  .embedded-heading .module-icon .icon { width: 18px; height: 18px; }
  .embedded-heading h1 { font-size: 18px; margin: 0; }
  .embedded-heading p,.embedded-eyebrow { display: none; }
  .embedded-actions { width: 100%; display: grid; grid-template-columns: repeat(4,minmax(0,1fr)); gap: 6px; }
  .embedded-actions .button { width: auto; min-height: 44px; padding: 5px; display: flex; flex-direction: row; gap: 4px; border-radius: 8px; }
  .embedded-actions .button span { display: inline; font-size: 10px; }
  .embedded-actions .button .icon { width: 16px; height: 16px; }
  .embedded-actions [data-action=navigate] { display: none; }
  .frame-menu { display: inline-flex; }
  .embedded-info { padding: 2px 12px; min-height: 40px; gap: 8px; }
  .embedded-info .text-button { font-size: 10px; min-height: 36px; max-width: 155px; }
  .frame-status { font-size: 11px; }
  .frame-help { max-height: min(180px,35dvh); padding: 12px; font-size: 12px; }
  .frame-restriction { justify-content: flex-start; padding: 22px 16px; }
  .frame-restriction p { font-size: 14px; }
  .workspace-focus .workspace.workspace-embedded { padding: var(--safe-top) env(safe-area-inset-right,0px) var(--safe-bottom) env(safe-area-inset-left,0px); margin: 0; }
  .workspace-focus .embedded-panel { border-radius: 0; border: 0; }
  .workspace-focus .embedded-info { display: none; }
  .workspace-focus .embedded-toolbar { padding-top: 8px; }
  .admin-heading h1 { font-size: 29px; }
  .admin-heading p { font-size: 13px; }
  .admin-heading .button { width: 44px; padding: 8px; }
  .admin-heading .button span { display: none; }
  .admin-stats { gap: 9px; }
  .stat-card { display: block; padding: 14px 12px; }
  .stat-card .module-icon { display: none; }
  .stat-value { font-size: 24px; }
  .stat-label { font-size: 11px; line-height: 1.35; }
  .admin-tabs { padding: 0 16px; gap: 22px; scrollbar-width: thin; }
  .admin-tab { min-height: 56px; font-size: 13px; }
  .admin-toolbar { padding: 20px 16px; flex-wrap: wrap; }
  .admin-toolbar h2 { font-size: 19px; }
  .admin-toolbar p { font-size: 12px; }
  .admin-toolbar .button { font-size: 13px; }
  .table-actions { gap: 7px; }
  .table-inline-button { font-size: 13px; }
  .detail-row { font-size: 13px; }
  .config-grid { grid-template-columns: 1fr; }
  .config-body { padding: 17px; }
  .notice { font-size: 13px; }
  .dialog { max-height: calc(var(--app-height) - var(--safe-top) - 22px); width: min(720px,calc(100vw - 24px)); border-radius: 20px; }
  .dialog-head { padding: 18px 20px; align-items: center; }
  .dialog-head h2 { font-size: 23px; }
  .dialog-head p { font-size: 13px; }
  .dialog-body { padding: 20px; overscroll-behavior: contain; }
  .dialog-foot { padding: 14px 20px; }
  .dialog-foot .button { min-height: 48px; }
  .dialog-body .field small { font-size: 12px; }
  .permission-item { min-height: 56px; padding: 13px; }
  .permission-item strong { font-size: 13px; }
  .permission-item small { font-size: 11px; }
  .permissions-grid { max-height: none; overflow: visible; }
  .form-section-head { flex-wrap: wrap; }
  .form-section-head .text-button { font-size: 13px; }
  .keyboard-open { --compact-bottom: 0px; }
  .keyboard-open .mobile-tabbar { display: none; }
  .toast,.connection-banner { bottom: calc(var(--compact-bottom) + 12px); font-size: 13px; }
  .workspace-focus .toast,.workspace-focus .connection-banner { bottom: calc(var(--safe-bottom) + 12px); }
}
@media (max-width: 600px) {
  .modules-grid { grid-template-columns: minmax(0,1fr); }
  .workspace { padding-left: max(16px,env(safe-area-inset-left,0px)); padding-right: max(16px,env(safe-area-inset-right,0px)); }
  .form-grid,.permissions-grid { grid-template-columns: 1fr; }
  .form-grid .span-2 { grid-column: auto; }
  .dialog:not(.confirm-dialog) { width: 100%; max-width: none; margin: auto 0 0; border-radius: 22px 22px 0 0; max-height: calc(var(--app-height) - var(--safe-top) - 12px); }
  .dialog-foot { padding-bottom: max(16px,var(--safe-bottom)); }
  .dialog:not(.confirm-dialog) .dialog-foot .button { flex: 1; }
  .responsive-table { display: block; padding: 0 13px 6px; }
  .responsive-table thead { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
  .responsive-table tbody { display: grid; gap: 12px; }
  .responsive-table tbody tr { display: grid; grid-template-columns: minmax(0,1fr) minmax(0,1fr); border: 1px solid var(--line); border-radius: 13px; padding: 12px; background: #fff; gap: 0 10px; }
  .responsive-table td { display: block; padding: 8px 0; border: 0; font-size: 13px; min-width: 0; overflow-wrap: anywhere; }
  .responsive-table td::before { content: attr(data-label); display: block; font-size: 11px; color: var(--muted); margin-bottom: 7px; }
  .responsive-table td:first-child { grid-column: 1 / -1; border-bottom: 1px solid var(--line); padding: 2px 0 14px; margin-bottom: 7px; }
  .responsive-table td:first-child::before { display: none; }
  .responsive-table td:last-child { grid-column: 1 / -1; display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 7px 0 0; }
  .responsive-table td:last-child::before { margin: 0; }
  .responsive-table td:has(.table-actions) { border-top: 1px solid var(--line); margin-top: 7px; }
  .responsive-table .cell-title { min-width: 0; }
  .responsive-table .cell-title > div { min-width: 0; }
  .responsive-table .cell-title strong { font-size: 15px; }
  .responsive-table .cell-title small { max-width: 100%; font-size: 12px; }
  .responsive-table .badge { font-size: 11px; white-space: normal; }
  .responsive-table .table-empty { grid-column: 1 / -1; }
  .responsive-table .table-empty::before { display: none; }
  .toolbar-actions { width: 100%; }
  .toolbar-actions .button.primary { flex: 1; }
  .empty-state { padding: 34px 20px; }
  .empty-state h2 { font-size: 23px; }
  .account-summary p { overflow-wrap: anywhere; }
}
@media (max-width: 370px) {
  .topbar { gap: 3px; padding-left: 7px; padding-right: 9px; }
  .brand img { width: 99px; }
  .card-link { padding-left: 14px; padding-right: 14px; }
  .card-top { gap: 11px; }
  .card-bottom .card-category { display: none; }
  .embedded-actions .button { flex-direction: column; gap: 2px; }
  .embedded-actions .button span { font-size: 9px; }
}
@media (max-height: 500px) and (max-width: 980px), (max-height: 500px) and (max-width: 1180px) and (pointer: coarse) {
  :root { --compact-top: calc(56px + var(--safe-top)); --compact-bottom: calc(54px + var(--safe-bottom)); }
  .topbar { padding-top: calc(var(--safe-top) + 3px); padding-bottom: 3px; }
  .brand img { height: 43px; }
  .mobile-tabbar { padding-top: 2px; }
  .mobile-tab { min-height: 46px; flex-direction: row; gap: 7px; }
  .sidebar { overflow-y: auto; }
  .drawer-head { margin-bottom: 8px; }
  .sidebar-accesses { min-height: 130px; flex-shrink: 0; }
  .sidebar .sidebar-bottom { flex-shrink: 0; }
  .embedded-toolbar { flex-wrap: nowrap; padding: 4px 10px; }
  .embedded-heading { width: auto; flex: 1; }
  .embedded-actions { width: auto; display: flex; }
  .embedded-actions .button { width: 44px; }
  .embedded-actions .button span { display: none; }
  .embedded-info { min-height: 30px; }
  .embedded-info .text-button { min-height: 30px; }
  .login-screen { align-items: flex-start; }
}
@media (prefers-reduced-motion: reduce) {
  .sidebar { transition: none; }
}

.filter-summary { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 13px; margin: 0 0 13px; background: rgba(255,255,255,.96); border-radius: 10px; font-size: 13px; }
.filter-summary span { overflow-wrap: anywhere; min-width: 0; }
.filter-summary .text-button { gap: 5px; flex-shrink: 0; }
.filter-summary .icon { width: 16px; height: 16px; }
