:root {
  --danger: #ef4444;
  --warning: #f59e0b;
  --radius: 12px;
  --sidebar-width: 260px;
  --sidebar-width-collapsed: 72px;
  --app-topbar-inner: 2.125rem;
  --app-topbar-padding-y: 7px;
  --app-topbar-border: 1px;
  --app-topbar-height: calc(var(--app-topbar-inner) + (var(--app-topbar-padding-y) * 2) + var(--app-topbar-border));
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body { font-family: var(--app-font-family, Inter, system-ui, sans-serif); background: var(--bg); color: var(--text); }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.form-error[role="alert"] {
  color: var(--danger);
}

/* Scrollbar discreta — modales, tablas y paneles con scroll */
.ui-scrollbar {
  scrollbar-width: thin;
  scrollbar-color: var(--scrollbar-thumb) var(--scrollbar-track);
}
.ui-scrollbar::-webkit-scrollbar {
  width: var(--scrollbar-size, 8px);
  height: var(--scrollbar-size, 8px);
}
.ui-scrollbar::-webkit-scrollbar-track {
  background: var(--scrollbar-track);
}
.ui-scrollbar::-webkit-scrollbar-thumb {
  background-color: var(--scrollbar-thumb);
  border-radius: 999px;
  border: 2px solid transparent;
  background-clip: padding-box;
}
.ui-scrollbar::-webkit-scrollbar-thumb:hover {
  background-color: var(--scrollbar-thumb-hover);
}
a { color: var(--accent-2); text-decoration: none; }
.muted { color: var(--muted); }

.app-shell { display: grid; grid-template-columns: var(--sidebar-width) 1fr; min-height: 100vh; transition: grid-template-columns .2s ease; }
.app-shell.sidebar-collapsed { grid-template-columns: var(--sidebar-width-collapsed) 1fr; }
.app-main { min-width: 0; display: flex; flex-direction: column; }
.app-sidebar {
  background: var(--bg-elevated);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  position: sticky;
  top: 0;
  height: 100vh;
  width: var(--sidebar-width);
  transition: width .2s ease;
  z-index: 40;
}
.app-sidebar.is-collapsed { width: var(--sidebar-width-collapsed); overflow: visible; }

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: .65rem;
  padding: var(--app-topbar-padding-y) .85rem;
  border-bottom: var(--app-topbar-border) solid var(--border);
  height: var(--app-topbar-height);
  min-height: var(--app-topbar-height);
  max-height: var(--app-topbar-height);
  flex-shrink: 0;
  box-sizing: border-box;
}
.sidebar-brand-link {
  display: flex;
  align-items: center;
  gap: .65rem;
  flex: 1;
  min-width: 0;
  height: 100%;
  min-height: 0;
  color: inherit;
  text-decoration: none;
}
.sidebar-brand-link:hover .sidebar-brand-logo,
.sidebar-brand-link:focus-visible .sidebar-brand-logo { opacity: 0.88; }
.sidebar-brand-link:focus-visible {
  outline: 2px solid var(--accent-2);
  outline-offset: 2px;
  border-radius: 6px;
}
.sidebar-brand-text { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; transition: opacity .15s ease; }
.sidebar-brand-logo {
  display: none;
  height: auto;
  max-height: var(--app-topbar-inner);
  width: auto;
  max-width: min(100%, 132px);
  object-fit: contain;
  object-position: left center;
  flex: 0 1 auto;
  min-width: 0;
  background: transparent !important;
}
.sidebar-brand-logo--only,
html[data-theme-mode="light"] .sidebar-brand-logo--light,
html[data-theme-mode="dark"] .sidebar-brand-logo--dark {
  display: block;
}
.sidebar-brand-favicon {
  display: none;
  width: 28px;
  height: 28px;
  max-width: 28px;
  max-height: 28px;
  object-fit: contain;
  flex-shrink: 0;
  background: transparent !important;
}
.sidebar-brand-favicon--only,
html[data-theme-mode="light"] .sidebar-brand-favicon--light,
html[data-theme-mode="dark"] .sidebar-brand-favicon--dark {
  display: none;
}
.app-sidebar.is-collapsed .sidebar-brand-logo-full {
  display: none !important;
}
.app-sidebar.is-collapsed .sidebar-brand-favicon--only,
html[data-theme-mode="light"] .app-sidebar.is-collapsed .sidebar-brand-favicon--light,
html[data-theme-mode="dark"] .app-sidebar.is-collapsed .sidebar-brand-favicon--dark {
  display: block;
}
.app-sidebar.is-collapsed .sidebar-brand-link {
  flex: 1;
  justify-content: center;
  min-width: 0;
}

.sidebar-collapse-btn {
  margin-left: auto;
  border: 0;
  background: transparent;
  color: var(--muted);
  border-radius: 8px;
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
}
.sidebar-collapse-btn:hover { background: var(--accent-soft); color: var(--text); }
.app-sidebar.is-collapsed .sidebar-collapse-btn { margin-left: 0; }
.app-sidebar.is-collapsed .sidebar-collapse-btn .sidebar-icon { transform: rotate(180deg); }
.app-sidebar.is-collapsed .sidebar-brand-text,
.app-sidebar.is-collapsed .sidebar-label,
.app-sidebar.is-collapsed .sidebar-chevron,
.app-sidebar.is-collapsed .sidebar-user-meta { opacity: 0; width: 0; overflow: hidden; white-space: nowrap; pointer-events: none; }
.app-sidebar.is-collapsed .sidebar-brand { justify-content: center; padding-inline: .65rem; gap: 0; }
.app-sidebar.is-collapsed .logo-dot { display: none; }

.logo-dot { width: 12px; height: 12px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 12px color-mix(in srgb, var(--accent) 60%, transparent); flex-shrink: 0; }
.logo-dot.lg { width: 18px; height: 18px; }

.sidebar-nav { padding: .65rem; flex: 1; overflow: auto; display: flex; flex-direction: column; gap: .12rem; }
.sidebar-nav-spacer { flex: 1; min-height: .5rem; }

.sidebar-icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  transition: transform .2s ease;
}
.sidebar-group-toggle .sidebar-icon,
.sidebar-nav .sidebar-link-root:not(:first-child) .sidebar-icon {
  width: 16px;
  height: 16px;
}
.sidebar-chevron {
  width: 14px;
  height: 14px;
  margin-left: auto;
  flex-shrink: 0;
  opacity: .65;
  transition: transform .2s ease, opacity .15s ease;
}
.sidebar-group.is-open .sidebar-chevron { transform: rotate(180deg); }

.sidebar-nav > .sidebar-link-root:first-child {
  font-size: .9rem;
  padding: .52rem .65rem;
  margin-bottom: .15rem;
}

.sidebar-group-toggle {
  display: flex;
  align-items: center;
  gap: .5rem;
  width: 100%;
  padding: .38rem .55rem;
  border: 0;
  background: transparent;
  color: var(--muted);
  text-align: left;
  border-radius: 8px;
  cursor: pointer;
  font: inherit;
  font-size: .78rem;
  font-weight: 500;
  text-decoration: none;
  line-height: 1.25;
  overflow: hidden;
}
.sidebar-label {
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sidebar-link-root:hover,
.sidebar-link-root.active,
.sidebar-group-toggle:hover,
.sidebar-group-toggle.active {
  background: var(--accent-soft);
  color: var(--text);
}
.sidebar-link-root {
  display: flex;
  align-items: center;
  gap: .55rem;
  width: 100%;
  padding: .42rem .6rem;
  border: 0;
  background: transparent;
  color: var(--muted);
  text-align: left;
  border-radius: 8px;
  cursor: pointer;
  font: inherit;
  font-size: .78rem;
  font-weight: 500;
  text-decoration: none;
  line-height: 1.25;
  overflow: hidden;
}
.sidebar-link-btn { margin-top: .25rem; }

.sidebar-group { position: relative; }

.sidebar-submenu {
  display: none;
  padding: .12rem 0 .25rem;
}
.sidebar-group.is-open > .sidebar-submenu {
  display: block;
}
.sidebar-submenu-inner {
  display: flex;
  flex-direction: column;
  gap: .08rem;
  margin-left: 1.85rem;
  padding-left: .55rem;
  border-left: 1px solid var(--border);
}

.sidebar-sublink {
  display: block;
  padding: .3rem .5rem;
  border-radius: 6px;
  color: var(--muted);
  font-size: .73rem;
  font-weight: 400;
  line-height: 1.3;
  text-decoration: none;
}
.sidebar-sublink:hover,
.sidebar-sublink.active {
  background: var(--accent-soft);
  color: var(--text);
}

.app-sidebar.is-collapsed .sidebar-submenu { display: none; }
.app-sidebar.is-collapsed .sidebar-link-root,
.app-sidebar.is-collapsed .sidebar-group-toggle {
  justify-content: center;
  padding-inline: .65rem;
}

.sidebar-flyout {
  display: none;
  position: fixed;
  left: calc(var(--sidebar-width-collapsed) + 4px);
  min-width: 180px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: .35rem;
  box-shadow: 0 12px 32px var(--shadow);
  z-index: 100;
}
.sidebar-flyout.is-visible { display: block; }
.sidebar-flyout .sidebar-sublink {
  margin-left: 0;
  border-left: 0;
  padding-left: .75rem;
}

.sidebar-bottom { padding: .85rem 1rem; border-top: 1px solid var(--border); }
.sidebar-user {
  display: flex;
  align-items: center;
  gap: .65rem;
  min-width: 0;
}
.sidebar-user-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--accent-soft-2);
  color: var(--accent-2);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: .85rem;
  flex-shrink: 0;
}
.sidebar-user-meta { min-width: 0; transition: opacity .15s ease; }
.sidebar-user-meta .sidebar-label { display: block; font-size: .9rem; color: var(--text); }
.sidebar-user small { display: block; color: var(--muted); font-size: .78rem; }
.app-sidebar.is-collapsed .sidebar-bottom { padding-inline: .65rem; }
.app-sidebar.is-collapsed .sidebar-user { justify-content: center; }

/* Section labels in sidebar navigation */
.sidebar-section {
  display: block;
  margin: 1rem 0 .32rem;
  padding: 0 .55rem;
  font-size: .875rem;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: color-mix(in srgb, var(--text) 88%, var(--muted));
}
.sidebar-section:first-of-type { margin-top: .45rem; }
.app-sidebar.is-collapsed .sidebar-section { display: none; }

/* Legacy selectors kept for compatibility */
.sidebar-link { display: flex; align-items: center; gap: .65rem; width: 100%; padding: .6rem .75rem; border: 0; background: transparent; color: var(--muted); text-align: left; border-radius: 8px; cursor: pointer; font: inherit; }
.sidebar-link:hover, .sidebar-link.active { background: var(--accent-soft); color: var(--text); }

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  height: var(--app-topbar-height);
  min-height: var(--app-topbar-height);
  max-height: var(--app-topbar-height);
  padding: var(--app-topbar-padding-y) 25px;
  border-bottom: var(--app-topbar-border) solid var(--border);
  position: sticky;
  top: 0;
  z-index: 35;
  background: var(--bg);
  flex-shrink: 0;
  box-sizing: border-box;
}
.mobile-nav-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  padding: 0;
  flex-shrink: 0;
  border-radius: 8px;
}
.mobile-nav-toggle svg { width: 22px; height: 22px; }
.mobile-topbar-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  padding: 0;
  flex-shrink: 0;
  border-radius: 8px;
}
.mobile-topbar-toggle svg { width: 20px; height: 20px; }
.topbar-drawer-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  border: 0;
  padding: 0;
  background: rgba(15, 23, 42, 0.5);
  z-index: 104;
  cursor: pointer;
}
body.mobile-topbar-open .topbar-drawer-backdrop { display: block; }
.mobile-topbar-drawer-head {
  display: none;
  align-items: center;
  justify-content: space-between;
  gap: .75rem;
  margin-bottom: .25rem;
  padding-bottom: .75rem;
  border-bottom: 1px solid var(--border);
}
.mobile-topbar-drawer-head strong {
  font-size: .95rem;
}
.mobile-topbar-close {
  min-width: 2rem;
  width: 2rem;
  height: 2rem;
  padding: 0;
  font-size: 1.15rem;
  line-height: 1;
}

.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  z-index: 90;
  border: 0;
  padding: 0;
  cursor: pointer;
}

.page-header > h1,
.page-header-title { flex: 1; min-width: 0; margin: 0; font-size: 1.4rem; line-height: 1; }
.page-header-title h1 { margin: 0; font-size: 1.4rem; line-height: 1; }
.page-header-end {
  display: flex;
  align-items: center;
  gap: .75rem;
  margin-left: auto;
  flex-shrink: 0;
}
/* Altura uniforme en toda la topbar */
.page-header-end .btn,
.page-header-end a.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .35rem;
  min-height: var(--app-topbar-inner);
  height: var(--app-topbar-inner);
  max-height: var(--app-topbar-inner);
  padding: 0 .75rem;
  font-size: .82rem;
  line-height: 1;
  white-space: nowrap;
}
.page-header-end .btn svg,
.page-header-end .btn .quick-actions-toggle-icon,
.page-header-end .btn .doc-dropdown-toggle-icon {
  width: 1rem;
  height: 1rem;
  flex-shrink: 0;
}
.page-header-end .period-filter select {
  height: var(--app-topbar-inner);
  min-height: var(--app-topbar-inner);
  max-height: var(--app-topbar-inner);
  padding: 0 .65rem;
  line-height: 1.2;
  font-size: .82rem;
}
.page-header-end .topbar-user-toggle {
  min-height: var(--app-topbar-inner);
  height: var(--app-topbar-inner);
  max-height: var(--app-topbar-inner);
  padding-block: 0;
  padding-inline: .45rem;
}
.page-header-end .topbar-user-avatar {
  width: 28px;
  height: 28px;
  font-size: .78rem;
}
.page-header-end .header-actions {
  display: flex;
  align-items: center;
  gap: .5rem;
  flex-wrap: wrap;
}
.page-content {
  padding: 1.25rem 1.5rem 2rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
.page-content > .stats-grid,
.page-content > .toolbar {
  margin-bottom: 0;
}
.page-content > .tab-panel {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
.page-content > .tab-panel .panel-toolbar,
.page-content > .tab-panel .datatable-footer {
  margin-top: 0;
  margin-bottom: 0;
}
.page-content-intro {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: .75rem 1rem;
  margin-bottom: 1rem;
}
.page-content-intro-main { flex: 1; min-width: 0; }
.page-entity-title {
  margin: 0 0 .25rem;
  font-size: 1.15rem;
  font-weight: 700;
}
.page-content-intro > .muted,
.page-content-intro > p.muted {
  margin: 0;
  flex: 1;
  min-width: 200px;
}
.header-actions { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.doc-header-actions .doc-action-dropdown {
  position: relative;
  flex-shrink: 0;
}
.doc-header-actions .doc-action-dropdown .dropdown-menu {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  z-index: 1050;
  min-width: 12rem;
  margin: .35rem 0 0;
  padding: .35rem;
  list-style: none;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg-panel);
  box-shadow: 0 10px 28px rgba(0, 0, 0, .18);
}
.doc-header-actions .doc-action-dropdown .dropdown-menu.dropdown-menu-end {
  left: auto;
  right: 0;
}
.doc-header-actions .doc-action-dropdown .dropdown-menu.show {
  display: block;
}
.doc-header-actions .dropdown-menu > li {
  list-style: none;
  margin: 0;
  padding: 0;
}
.doc-header-actions .dropdown-item {
  display: flex;
  align-items: center;
  gap: .5rem;
  width: 100%;
  border: 0;
  border-radius: 6px;
  background: transparent;
  font-size: .88rem;
  font-weight: 500;
  padding: .45rem .65rem;
  color: var(--text);
  text-align: left;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
}
.doc-header-actions .doc-dropdown-toggle,
.doc-header-actions .doc-dropdown-save {
  gap: .35rem;
}
.doc-header-actions .doc-dropdown-toggle-icon {
  width: 1rem;
  height: 1rem;
  flex-shrink: 0;
}
.doc-header-actions .doc-dropdown-item-icon {
  width: 1rem;
  height: 1rem;
  flex-shrink: 0;
  opacity: .85;
}
.doc-header-actions .dropdown-item[hidden] {
  display: none !important;
}
.doc-header-actions .dropdown-item:hover,
.doc-header-actions .dropdown-item:focus {
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  color: var(--text);
  outline: none;
}
.doc-header-actions .dropdown-divider {
  margin: .35rem 0;
  border: 0;
  border-top: 1px solid var(--border);
  opacity: 1;
}
.doc-header-actions .dropdown-divider[hidden] {
  display: none !important;
}
.doc-header-actions .dropdown-toggle {
  display: inline-flex;
  align-items: center;
  gap: .25rem;
}
.doc-header-actions .dropdown-toggle::after {
  display: inline-block;
  margin-left: .15em;
  vertical-align: middle;
  content: "";
  border-top: .35em solid currentColor;
  border-right: .3em solid transparent;
  border-left: .3em solid transparent;
  opacity: .65;
}

.topbar-user { position: relative; flex-shrink: 0; }
.topbar-user-toggle {
  display: inline-flex;
  align-items: center;
  gap: .65rem;
  border: 0;
  background: transparent;
  color: var(--accent-2);
  cursor: pointer;
  padding: .35rem .5rem;
  border-radius: 999px;
  font: inherit;
  max-width: min(280px, 36vw);
}
.topbar-user-toggle:hover,
.topbar-user.is-open .topbar-user-toggle {
  background: var(--accent-soft);
}
.topbar-user-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--accent-soft-2);
  color: var(--accent-2);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: .85rem;
  flex-shrink: 0;
  overflow: hidden;
}
.topbar-user-avatar-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.user-avatar-row {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}
.user-avatar-preview {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: var(--accent-soft-2);
  color: var(--accent-2);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 1.5rem;
  flex-shrink: 0;
  overflow: hidden;
}
.user-avatar-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.user-avatar-actions {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: .45rem;
}
.user-avatar-hint {
  margin: 0;
  font-size: .82rem;
}
.topbar-user-name {
  font-weight: 600;
  font-size: .92rem;
  color: var(--accent-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.topbar-user-chevron {
  width: 16px;
  height: 16px;
  color: var(--muted);
  flex-shrink: 0;
  transition: transform .2s ease;
}
.topbar-user.is-open .topbar-user-chevron { transform: rotate(180deg); }
.topbar-user-menu {
  position: absolute;
  top: calc(100% + .45rem);
  right: 0;
  min-width: 278px;
  width: 278px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: .35rem;
  box-shadow: 0 16px 40px var(--shadow);
  z-index: 120;
}
.topbar-user-menu[hidden] { display: none; }
.topbar-user-item {
  display: flex;
  align-items: center;
  gap: .65rem;
  width: 100%;
  padding: .6rem .75rem;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  text-decoration: none;
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.topbar-user-item svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}
.topbar-user-item:hover {
  background: var(--accent-soft);
  color: var(--text);
}
.topbar-user-separator {
  height: 1px;
  background: var(--border);
  margin: .35rem .25rem;
}
.topbar-user-item-btn { color: var(--muted); }

.theme-picker {
  display: flex;
  flex-direction: column;
  gap: .45rem;
  padding: .3rem .4rem .4rem;
}

.theme-picker-group {
  display: flex;
  flex-direction: column;
  gap: .32rem;
  padding: .4rem .4rem .45rem;
  border-radius: 8px;
  background: color-mix(in srgb, var(--bg-panel) 72%, transparent);
  border: 1px solid color-mix(in srgb, var(--border) 65%, transparent);
}

.theme-picker-label {
  display: block;
  padding: 0 .1rem;
  font-size: .65rem;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--muted);
  line-height: 1.2;
}

.theme-picker-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 5px;
}

.theme-swatch {
  width: 100%;
  height: 21.6px;
  border-radius: 4px;
  border: 1.5px solid transparent;
  background: var(--swatch);
  cursor: pointer;
  padding: 0;
  transition: transform .12s ease, border-color .12s ease, box-shadow .12s ease;
}

.theme-swatch:hover { transform: scaleY(1.12); }

.theme-swatch.is-active {
  border-color: var(--accent-2);
  box-shadow: 0 0 0 1px var(--bg-elevated), 0 0 0 2px color-mix(in srgb, var(--accent-2) 55%, transparent);
}

.theme-swatch[data-mode="light"] {
  border-color: color-mix(in srgb, var(--border) 85%, #94a3b8);
}

.theme-swatch[data-mode="light"]:hover,
.theme-swatch[data-mode="light"].is-active {
  border-color: var(--accent-2);
}

.font-picker {
  display: flex;
  flex-direction: column;
  gap: .35rem;
  padding: .15rem .4rem .35rem;
}

.font-picker-label {
  display: block;
  padding: 0 .1rem;
  font-size: .65rem;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--muted);
  line-height: 1.2;
}

.font-picker-select {
  width: 100%;
}

.topbar-user-menu .select2-container {
  width: 100% !important;
}

.topbar-user-menu .select2-container--default .select2-selection--single {
  min-height: 2rem;
  height: 2rem;
}

.topbar-user-menu .select2-container--default .select2-selection--single .select2-selection__rendered {
  line-height: 2rem;
  padding-left: .55rem;
  padding-right: 1.75rem;
}

.topbar-user-menu .select2-container--default .select2-selection--single .select2-selection__arrow {
  height: 2rem;
}

.brand-default-font {
  margin-top: 1rem;
}

.brand-default-font .font-picker-select {
  max-width: 420px;
}

.font-option-preview {
  display: block;
  font-size: .92rem;
  line-height: 1.35;
}

@media (max-width: 640px) {
  .topbar-user-name { display: none; }
  .topbar-user-chevron { display: none; }
}

.btn { border: 0; border-radius: 8px; padding: .55rem .9rem; cursor: pointer; font-weight: 600; }
.btn-primary { background: var(--accent); color: var(--accent-on); }
.btn-secondary { background: var(--bg-panel); color: var(--text); border: 1px solid var(--border); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-block { width: 100%; }

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: .65rem;
  align-items: center;
  margin-bottom: 0;
}
.toolbar input,
.toolbar select {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: .55rem .75rem;
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-elevated);
}
.page-content > .table-wrap:has(+ .datatable-footer),
.tab-panel > .table-wrap:has(+ .datatable-footer) {
  border-bottom-left-radius: 0;
  border-bottom-right-radius: 0;
  border-bottom-color: transparent;
}
.page-content > .table-wrap + .datatable-footer,
.tab-panel > .table-wrap + .datatable-footer {
  margin-top: 0;
  padding: .7rem 1rem;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-top: 0;
  border-radius: 0 0 var(--radius) var(--radius);
}
.data-table { width: 100%; border-collapse: collapse; }
.data-table.datatable { min-width: max-content; }
.data-table th, .data-table td { padding: .75rem; border-bottom: 1px solid var(--border); text-align: left; font-size: .92rem; vertical-align: middle; }
.data-table th { background: var(--bg-panel); color: var(--muted); }
.badge { display: inline-block; padding: .15rem .5rem; border-radius: 999px; font-size: .75rem; background: var(--accent-soft); color: var(--accent-2); }
.badge.success { background: var(--accent-soft-2); color: var(--accent); }
.badge.warning { background: rgba(245,158,11,.15); color: var(--warning); }
.badge.danger { background: rgba(239,68,68,.15); color: var(--danger); }

.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 1rem; margin-bottom: 0; }
.stat-card { background: var(--bg-elevated); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; }
.stat-card strong { display: block; font-size: 1.5rem; margin-top: .35rem; }
.stat-card small { display: block; margin-top: .35rem; font-size: .78rem; }
.text-danger { color: var(--danger); }
.text-success { color: var(--accent); }

.stat-card-kpi-link {
  display: block;
  text-decoration: none;
  color: inherit;
  border-radius: var(--radius);
  transition: transform .15s ease, box-shadow .15s ease;
}
.stat-card-kpi-link:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 24px var(--shadow);
}
.stat-card-kpi-link:focus-visible {
  outline: 2px solid var(--accent-2);
  outline-offset: 2px;
}

.time-tracking-page .stats-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1rem;
  margin-bottom: 1rem;
}
.time-tracking-page .charts-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
  margin-bottom: 1rem;
}
.clock-panel {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 1.25rem;
  padding: 1.25rem 1.5rem;
  margin-bottom: 1rem;
}
.clock-panel-main {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 1.25rem;
  flex: 1;
  min-width: 260px;
}
.clock-status-wrap { min-width: 180px; }
.clock-status-badge {
  display: inline-block;
  padding: .2rem .65rem;
  border-radius: 999px;
  font-size: .78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
  margin-bottom: .5rem;
}
.clock-status-badge.is-in { background: var(--accent-soft-2); color: var(--accent); }
.clock-status-badge.is-out { background: rgba(100,116,139,.18); color: #94a3b8; }
.clock-live-time {
  display: block;
  font-size: 2rem;
  line-height: 1.1;
}
.clock-status-meta { margin: .35rem 0 0; font-size: .88rem; }
.clock-actions {
  display: flex;
  align-items: flex-end;
  gap: .65rem;
  flex-wrap: wrap;
}
.clock-project-label {
  margin: 0;
  font-size: .78rem;
  gap: .25rem;
}
.clock-project-label select {
  min-width: 200px;
  min-height: 2.5rem;
  padding: .55rem .75rem;
}
.btn-clock { min-width: 150px; min-height: 2.5rem; }
.clock-panel-stats {
  display: flex;
  gap: 1.5rem;
  flex-wrap: wrap;
}
.clock-stat span {
  display: block;
  font-size: .78rem;
  color: var(--muted);
  margin-bottom: .2rem;
}
.clock-stat strong { font-size: 1.1rem; }
.time-user-select {
  min-width: 220px;
  padding: .55rem .75rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text);
  font: inherit;
}
.legal-note {
  font-size: .82rem;
  margin: 0 0 1rem;
  padding: .65rem .85rem;
  border-left: 3px solid var(--accent-2);
  background: var(--accent-soft);
  border-radius: 0 8px 8px 0;
}

.online-toolbar { align-items: flex-start; }
.online-fetched-at { margin: .25rem 0 0; font-size: .82rem; }
.online-stats-grid { margin-bottom: 1rem; }
.online-user-cell {
  display: inline-flex;
  align-items: center;
  gap: .65rem;
}
.online-user-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--accent-soft-2);
  color: var(--accent);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: .85rem;
  flex-shrink: 0;
}
.online-user-role { display: block; font-size: .78rem; margin-top: .1rem; }
.online-contact-cell { font-size: .88rem; line-height: 1.45; min-width: 160px; }
.online-contact-cell a { word-break: break-all; }

@media (max-width: 1200px) {
  .time-tracking-page .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 768px) {
  .time-tracking-page .stats-grid,
  .time-tracking-page .charts-grid { grid-template-columns: 1fr; }
  .clock-panel-stats { width: 100%; justify-content: space-between; }
}

.dashboard-page .stats-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 1rem;
}

.list-kpi-page .stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.stat-card-kpi {
  display: flex;
  align-items: flex-start;
  gap: .85rem;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1rem 1rem .95rem;
  min-width: 0;
}
.stat-card-kpi-icon {
  width: 44px;
  height: 44px;
  border-radius: 11px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.stat-card-kpi-icon svg {
  width: 22px;
  height: 22px;
}
.stat-card-kpi-body {
  min-width: 0;
  flex: 1;
}
.stat-card-kpi-label {
  display: block;
  font-size: .82rem;
  color: var(--muted);
  line-height: 1.3;
}
.stat-card-kpi-title-link {
  color: inherit;
  text-decoration: none;
  transition: color .15s ease;
}
.stat-card-kpi-title-link:hover {
  color: var(--accent-2);
}
.stat-card-kpi-value {
  display: block;
  margin-top: .25rem;
  font-size: 1.45rem;
  font-weight: 700;
  line-height: 1.15;
  word-break: break-word;
}
.stat-card-kpi-meta {
  display: block;
  margin-top: .35rem;
  font-size: .78rem;
  color: var(--muted);
  line-height: 1.35;
}
.stat-card-kpi.tone-green .stat-card-kpi-icon { background: var(--accent-soft-2); color: var(--accent); }
.stat-card-kpi.tone-blue .stat-card-kpi-icon { background: var(--accent-soft); color: var(--accent-2); }
.stat-card-kpi.tone-amber .stat-card-kpi-icon { background: rgba(245,158,11,.14); color: var(--warning); }
.stat-card-kpi.tone-purple .stat-card-kpi-icon { background: rgba(167,139,250,.14); color: #a78bfa; }
.stat-card-kpi.tone-cyan .stat-card-kpi-icon { background: rgba(20,184,166,.14); color: #14b8a6; }
.stat-card-kpi.tone-red .stat-card-kpi-icon { background: rgba(239,68,68,.14); color: var(--danger); }
.stat-card-kpi.tone-orange .stat-card-kpi-icon { background: rgba(251,146,60,.14); color: #fb923c; }
.stat-card-kpi.tone-slate .stat-card-kpi-icon { background: rgba(100,116,139,.18); color: #94a3b8; }

@media (max-width: 1200px) {
  .dashboard-page .stats-grid,
  .sales-dashboard-page .stats-grid,
  .purchases-dashboard-page .stats-grid,
  .list-kpi-page .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 560px) {
  .dashboard-page .stats-grid,
  .sales-dashboard-page .stats-grid,
  .purchases-dashboard-page .stats-grid,
  .list-kpi-page .stats-grid { grid-template-columns: 1fr; }
}

.charts-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
  margin: 1rem 0;
}

.dashboard-page .charts-grid,
.dashboard-page .details-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.dashboard-page .chart-panel-wide { grid-column: auto; }

.chart-panel-wide { grid-column: 1 / -1; }
.chart-wrap { position: relative; height: 280px; }
.chart-wrap-donut { height: 220px; }
.chart-legend, .chart-meta {
  padding: 0 1rem 1rem;
  display: grid;
  gap: .35rem;
  font-size: .85rem;
  color: var(--muted);
}
.legend-item { display: flex; align-items: center; gap: .5rem; }
.legend-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.chart-meta code { font-size: .72rem; word-break: break-all; }

.sales-dashboard-page .stats-grid,
.purchases-dashboard-page .stats-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}
@media (max-width: 900px) {
  /* Móvil: listados primero, KPIs después, gráficas al final */
  .sales-dashboard-page,
  .purchases-dashboard-page {
    display: flex;
    flex-direction: column;
  }
  .sales-dashboard-page #sales-details { order: 2; }
  .sales-dashboard-page #sales-kpis { order: 3; }
  .sales-dashboard-page #sales-charts { order: 4; }
  .purchases-dashboard-page #purchases-details { order: 2; }
  .purchases-dashboard-page #purchases-kpis { order: 3; }
  .purchases-dashboard-page #purchases-charts { order: 4; }
  #sales-invoices,
  #sales-quotes,
  #sales-open-quotes,
  #sales-expiring,
  #sales-overdue,
  #sales-charts,
  #sales-kpis,
  #purchases-recent,
  #purchases-drafts,
  #purchases-pending,
  #purchases-due-soon,
  #purchases-suppliers,
  #purchases-charts,
  #purchases-kpis {
    scroll-margin-top: calc(var(--app-topbar-height, 3.5rem) - 35px);
  }
  .sales-dashboard-page .datatable-view-switch,
  .purchases-dashboard-page .datatable-view-switch {
    display: none !important;
  }
}

.details-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
}

.table-wrap.compact .data-table th,
.table-wrap.compact .data-table td { padding: .55rem .65rem; font-size: .84rem; }

.data-table tfoot.table-sum-footer td {
  background: var(--bg-panel);
  border-top: 2px solid var(--border);
  padding: .7rem .75rem;
  font-size: .92rem;
}
.data-table tfoot.table-sum-footer .table-footer-label {
  text-align: right;
  color: var(--muted);
}
.data-table tfoot.table-sum-footer .table-footer-sum {
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.panel-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 1rem; }
.panel { background: var(--bg-elevated); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.panel-head { padding: .85rem 1rem; border-bottom: 1px solid var(--border); }
.panel-head h2 { margin: 0; font-size: 1rem; }
.panel-head-with-action {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .75rem;
}
.panel-head-with-action h2 {
  min-width: 0;
}
.panel-head-link {
  flex-shrink: 0;
  white-space: nowrap;
}
.panel-body {
  padding: 1.15rem 1.25rem;
}
.panel-body:not(.table-wrap):not(.chart-wrap):not(.dashboard-ops-list) {
  display: flex;
  flex-direction: column;
  gap: .85rem;
}
.panel-body > .muted:first-child,
.panel-body > p.muted:first-child {
  margin: 0;
}

/* Evitar “card dentro de card” cuando hay tabla dentro de un panel */
.panel > .panel-body.table-wrap {
  padding: 0;
  border: 0;
  border-radius: 0;
  overflow: auto;
}
.panel > .panel-body.table-wrap .data-table { border: 0; }
.panel > .panel-body.table-wrap .data-table tr:last-child td { border-bottom: 0; }

.dashboard-page .charts-grid .panel-body.chart-wrap { padding: .75rem 1rem 1rem; }
.dashboard-page .details-grid .panel { display: flex; flex-direction: column; min-height: 0; }
.dashboard-page .details-grid .panel > .panel-body.table-wrap { flex: 1; }

.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: .75rem; }
label { display: flex; flex-direction: column; gap: .35rem; font-size: .85rem; color: var(--muted); }
input, select, textarea { background: var(--bg-panel); border: 1px solid var(--border); color: var(--text); border-radius: 8px; padding: .55rem .65rem; font: inherit; }
.checkbox {
  flex-direction: row;
  align-items: center;
  gap: .5rem;
  color: var(--text);
  cursor: pointer;
  user-select: none;
}
.form-grid .checkbox,
.form-grid-3 .checkbox,
.form-grid-4 .checkbox {
  align-self: end;
  min-height: 2.45rem;
}
.checkbox input[type="checkbox"] {
  width: 1rem;
  height: 1rem;
  margin: 0;
  flex-shrink: 0;
  accent-color: var(--accent);
  cursor: pointer;
}
.form-error { color: var(--danger); font-size: .85rem; }
.form-sections {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
.form-sections fieldset { border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 0; padding: 1rem; }
.form-sections .form-section {
  margin-bottom: 0;
}
.form-sections legend { padding: 0 .5rem; color: var(--accent-2); }

/* Espaciado uniforme en modales */
.modal-body,
dialog.form-modal-open > form.modal-body,
dialog.form-modal-open > .modal-body {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}
.modal-body .form-grid,
.modal-body .form-grid-3,
.modal-body .form-grid-4 {
  gap: 1rem;
}
.modal-body label:not(.checkbox) {
  gap: .45rem;
}
.modal-subsection {
  display: flex;
  flex-direction: column;
  gap: .85rem;
  padding: 1.15rem 1.25rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.modal-subsection > h3 {
  margin: 0;
  font-size: .9rem;
  font-weight: 600;
  color: var(--accent-2);
}
.modal-subsection > .btn {
  align-self: flex-start;
}

.login-page { display: grid; place-items: center; min-height: 100vh; background: radial-gradient(circle at top, var(--accent-soft), transparent 40%), var(--bg); }
.login-card { width: min(420px, 92vw); background: var(--bg-elevated); border: 1px solid var(--border); border-radius: 16px; padding: 1.5rem; }
.login-header { text-align: center; margin-bottom: 1rem; }
.login-form label { margin-bottom: .75rem; }
.login-form .login-remember {
  margin: .15rem 0 .85rem;
  font-size: .88rem;
}
.login-form .login-remember small {
  font-weight: 400;
}

.modal { border: 1px solid var(--border); border-radius: 12px; background: var(--bg-elevated); color: var(--text); padding: 0; max-width: 92vw; }
.modal-lg { width: min(760px, 92vw); }
.modal-user,
.modal-client,
.modal-product {
  width: min(1140px, calc(100vw - 2rem));
  max-width: none;
  max-height: none;
  height: auto;
  overflow: visible;
  border: 1px solid var(--border);
  margin: 2rem auto 3rem;
  top: 0;
  bottom: auto;
}
.modal-user[open],
.modal-client[open],
.modal-product[open] {
  overflow: visible;
}
.modal-user .modal-body,
.modal-client .modal-body,
.modal-product .modal-body {
  padding: 1.25rem 1.5rem 1.5rem;
  overflow: visible;
  max-height: none;
}
.modal-user .modal-actions,
.modal-client .modal-actions,
.modal-product .modal-actions {
  position: static;
  background: transparent;
  padding-top: 1rem;
  margin-top: 0;
  border-top: 1px solid var(--border);
}
.modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0;
}
.modal-header h2 { margin: 0 0 .25rem; }
.modal-header .muted { margin: 0; }
.modal-header .btn { min-width: 2.5rem; padding: .35rem .65rem; font-size: 1.2rem; line-height: 1; }
.form-section {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.15rem 1.25rem 1.25rem;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
.form-section legend {
  padding: 0 .45rem;
  color: var(--accent-2);
  font-size: .9rem;
  font-weight: 600;
}
.form-section > .muted {
  margin: 0;
}
.form-field-span {
  display: flex;
  flex-direction: column;
  gap: .45rem;
  grid-column: 1 / -1;
}
.field-help {
  margin: 0;
  font-size: .85rem;
}
.rich-text-editor-field {
  width: 100%;
  min-height: 220px;
  resize: vertical;
}
.form-field-span .tox-tinymce {
  border: 1px solid var(--border) !important;
  border-radius: var(--radius);
  overflow: hidden;
}
.form-field-span .tox .tox-editor-header {
  background: var(--bg-elevated) !important;
  border-bottom: 1px solid var(--border) !important;
  box-shadow: none !important;
}
.form-field-span .tox .tox-toolbar,
.form-field-span .tox .tox-toolbar__overflow,
.form-field-span .tox .tox-toolbar__primary {
  background: var(--bg-elevated) !important;
}
.form-field-span .tox:not(.tox-tinymce-inline) .tox-editor-header {
  padding: 0 !important;
}
.form-field-span .tox .tox-statusbar {
  border-top: 1px solid var(--border) !important;
  background: var(--bg-elevated) !important;
}
.form-field-span .tox .tox-statusbar__text-container {
  color: var(--text-muted) !important;
}
.form-grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.form-grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.form-grid .span-2 { grid-column: span 2; }
.modal-body { padding: 1.25rem; }
.modal-actions,
.modal-footer {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  flex-wrap: wrap;
  gap: .65rem;
  margin-top: 0;
  position: sticky;
  bottom: 0;
  background: var(--bg-elevated);
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}
.scan-review-footer,
.form-modal-open .modal-actions {
  position: static;
  background: transparent;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

.form-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.72);
  z-index: 10000;
}
body.has-form-modal-open {
  overflow: hidden !important;
}
body.has-form-modal-open .data-table th.col-actions,
body.has-form-modal-open .data-table td.table-actions,
body.has-form-modal-open .data-table:has(tbody td.table-actions) thead th:last-child {
  z-index: auto;
}
dialog.form-modal-open {
  z-index: 10001;
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  margin: 0;
  display: flex;
  flex-direction: column;
  width: min(1140px, calc(100vw - 2rem));
  max-width: calc(100vw - 2rem);
  max-height: calc(100dvh - 2rem);
  min-height: 0;
  height: auto;
  overflow: hidden;
  border: 1px solid var(--border);
  padding: 0;
  overscroll-behavior: contain;
}
dialog.form-modal-open.modal-client,
dialog.form-modal-open.modal-product,
dialog.form-modal-open.modal-user,
dialog.form-modal-open.modal-client[open],
dialog.form-modal-open.modal-product[open],
dialog.form-modal-open.modal-user[open] {
  max-height: calc(100dvh - 2rem);
  overflow: hidden;
}
dialog.form-modal-open > .modal-body,
dialog.form-modal-open > form.modal-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  max-height: none;
  overscroll-behavior: contain;
}
dialog.form-modal-open::backdrop {
  display: none;
}
dialog[open].modal,
dialog[open].confirm-delete-modal,
dialog[open].app-message-modal,
dialog[open].app-confirm-modal,
dialog[open].app-form-modal,
dialog[open].app-loading-modal {
  z-index: 10001;
  max-height: calc(100dvh - 2rem);
  overflow-x: hidden;
  overflow-y: auto;
}
dialog[open].modal:not(.form-modal-open),
dialog[open].app-form-modal {
  overscroll-behavior: contain;
}
dialog.form-modal-open,
dialog.form-modal-open > .modal-body,
dialog.form-modal-open > form.modal-body,
dialog[open].modal:not(.form-modal-open) {
  scrollbar-width: thin;
  scrollbar-color: var(--scrollbar-thumb) var(--scrollbar-track);
}
dialog.form-modal-open::-webkit-scrollbar,
dialog.form-modal-open > .modal-body::-webkit-scrollbar,
dialog.form-modal-open > form.modal-body::-webkit-scrollbar,
dialog[open].modal:not(.form-modal-open)::-webkit-scrollbar {
  width: var(--scrollbar-size, 8px);
  height: var(--scrollbar-size, 8px);
}
dialog.form-modal-open::-webkit-scrollbar-thumb,
dialog.form-modal-open > .modal-body::-webkit-scrollbar-thumb,
dialog.form-modal-open > form.modal-body::-webkit-scrollbar-thumb,
dialog[open].modal:not(.form-modal-open)::-webkit-scrollbar-thumb {
  background-color: var(--scrollbar-thumb);
  border-radius: 999px;
  border: 2px solid transparent;
  background-clip: padding-box;
}
dialog.form-modal-open::-webkit-scrollbar-thumb:hover,
dialog.form-modal-open > .modal-body::-webkit-scrollbar-thumb:hover,
dialog.form-modal-open > form.modal-body::-webkit-scrollbar-thumb:hover,
dialog[open].modal:not(.form-modal-open)::-webkit-scrollbar-thumb:hover {
  background-color: var(--scrollbar-thumb-hover);
}
dialog.form-modal-open::-webkit-scrollbar-track,
dialog.form-modal-open > .modal-body::-webkit-scrollbar-track,
dialog.form-modal-open > form.modal-body::-webkit-scrollbar-track,
dialog[open].modal:not(.form-modal-open)::-webkit-scrollbar-track {
  background: var(--scrollbar-track);
}
.modal-actions-spacer { flex: 1; }
.table-actions {
  white-space: nowrap;
  text-align: right;
  vertical-align: middle;
}
.table-actions .btn {
  display: inline-block;
  vertical-align: middle;
  flex-shrink: 0;
}
.table-actions .btn + .btn { margin-left: .35rem; }

/* Columna Acciones — mismo aspecto que el resto de columnas */
.data-table th.col-actions,
.data-table:has(tbody td.table-actions) thead th:last-child {
  text-align: right;
  white-space: nowrap;
  vertical-align: middle;
  background: var(--bg-panel);
  box-shadow: none;
  position: static;
  z-index: auto;
}

.data-table td.table-actions,
.data-table td.table-actions.col-actions {
  text-align: right;
  white-space: nowrap;
  vertical-align: middle;
  background: transparent;
  box-shadow: none;
  position: static;
  z-index: auto;
  min-width: 0;
  padding-left: .75rem;
  padding-right: .75rem;
}

.data-table th.col-thumb,
.data-table td.col-thumb {
  width: 3.25rem;
  min-width: 3.25rem;
  padding-left: .5rem;
  padding-right: .35rem;
  text-align: center;
}

.confirm-delete-modal {
  width: min(480px, calc(100vw - 2rem));
  border: 1px solid var(--border);
}
.confirm-delete-modal .modal-body { padding: 1.25rem 1.5rem 1.5rem; display: flex; flex-direction: column; gap: 1rem; }
.confirm-delete-modal .modal-actions { position: static; background: transparent; padding-top: 1rem; margin-top: 0; border-top: 1px solid var(--border); }
.confirm-delete-icon {
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(239, 68, 68, .15);
  color: #f87171;
  font-size: 1.25rem;
  margin-bottom: .75rem;
}

.app-message-modal {
  width: min(520px, calc(100vw - 2rem));
  border: 1px solid var(--border);
}
.app-message-modal .modal-body { padding: 1.25rem 1.5rem 1.5rem; display: flex; flex-direction: column; gap: 1rem; }
.app-message-modal .modal-actions {
  position: static;
  background: transparent;
  padding-top: 1rem;
  margin-top: 0;
  border-top: 1px solid var(--border);
  justify-content: flex-end;
}
}
.app-message-modal h2 { margin: 0 0 .5rem; font-size: 1.15rem; }
.app-message-text {
  margin: 0;
  color: var(--text);
  white-space: pre-wrap;
  line-height: 1.5;
  max-height: min(50vh, 420px);
  overflow: auto;
}
.app-message-icon {
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.15rem;
  font-weight: 700;
  margin-bottom: .75rem;
}
.app-message-modal.is-info .app-message-icon {
  background: var(--accent-soft);
  color: var(--accent-2);
}
.app-message-modal.is-success .app-message-icon {
  background: var(--accent-soft-2);
  color: var(--accent);
}
.app-message-modal.is-error .app-message-icon {
  background: rgba(239, 68, 68, .15);
  color: #f87171;
}

.app-toast-container {
  position: fixed;
  bottom: 1.25rem;
  right: 1.25rem;
  z-index: 10050;
  display: flex;
  flex-direction: column-reverse;
  gap: .75rem;
  pointer-events: none;
  width: min(420px, calc(100vw - 2rem));
}
.app-toast {
  pointer-events: auto;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 16px 40px var(--shadow);
  overflow: hidden;
  opacity: 0;
  transform: translateY(.75rem);
  transition: opacity .28s ease, transform .28s ease;
}
.app-toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}
.app-toast.is-leaving {
  opacity: 0;
  transform: translateY(-.35rem);
}
.app-toast-body {
  padding: .9rem 1rem .8rem;
}
.app-toast-title {
  display: block;
  font-size: .78rem;
  font-weight: 600;
  letter-spacing: .02em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: .2rem;
}
.app-toast-message {
  margin: 0;
  font-size: .95rem;
  color: var(--text);
  line-height: 1.45;
}
.app-toast-footer {
  height: 3px;
  background: color-mix(in srgb, var(--border) 70%, transparent);
}
.app-toast-progress {
  height: 100%;
  width: 100%;
  transform-origin: left center;
  animation: app-toast-progress-shrink linear forwards;
}
.app-toast.is-success .app-toast-progress {
  background: var(--accent);
}
.app-toast.is-info .app-toast-progress {
  background: var(--accent-2);
}
.app-toast.is-error .app-toast-progress {
  background: #f87171;
}
@keyframes app-toast-progress-shrink {
  from { transform: scaleX(1); }
  to { transform: scaleX(0); }
}
@media (max-width: 640px) {
  .app-toast-container {
    left: 1rem;
    right: 1rem;
    bottom: 1rem;
    width: auto;
  }
}

@media (max-width: 768px) {
  .app-message-modal {
    width: 100vw;
    max-width: 100vw;
    min-height: auto;
    margin: auto 0 0;
    border-radius: 12px 12px 0 0;
  }
}

.app-confirm-modal,
.app-form-modal {
  width: min(520px, calc(100vw - 2rem));
  border: 1px solid var(--border);
}
.app-confirm-modal .modal-body,
.app-form-modal .modal-body { padding: 1.25rem 1.5rem 1.5rem; display: flex; flex-direction: column; gap: 1rem; }
.app-confirm-modal .modal-actions,
.app-form-modal .modal-actions {
  position: static;
  background: transparent;
  padding-top: 1rem;
  margin-top: 0;
  border-top: 1px solid var(--border);
  justify-content: flex-end;
  gap: .65rem;
}
.app-confirm-modal h2,
.app-form-modal h2 { margin: 0 0 .5rem; font-size: 1.15rem; }
.app-confirm-modal.is-danger #app-confirm-icon {
  background: rgba(239, 68, 68, .15);
  color: #f87171;
}
.app-form-field { display: block; margin-top: 0; }
.app-form-input {
  width: 100%;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: .55rem .75rem;
  font: inherit;
}
.app-choice-list {
  display: flex;
  flex-direction: column;
  gap: .5rem;
  margin-top: .75rem;
}
.app-choice-btn {
  width: 100%;
  justify-content: flex-start;
  text-align: left;
}
.app-link-copy {
  display: flex;
  gap: .5rem;
  margin-top: .75rem;
  align-items: stretch;
}
.app-link-copy .app-form-input { flex: 1; min-width: 0; }
.app-form-message { margin: 0 0 .25rem; line-height: 1.45; }

.app-loading-modal {
  width: auto;
  min-width: 220px;
  max-width: min(360px, calc(100vw - 2rem));
  border: 1px solid var(--border);
  margin: auto;
  padding: 0;
}
.app-loading-modal::backdrop {
  background: rgba(0, 0, 0, .45);
}
.app-loading-body {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  padding: 2rem 2.5rem;
  text-align: center;
}
.app-loading-spinner {
  width: 42px;
  height: 42px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: app-loading-spin .75s linear infinite;
}
.app-loading-text {
  margin: 0;
  color: var(--text);
  font-size: .95rem;
  line-height: 1.4;
}
@keyframes app-loading-spin {
  to { transform: rotate(360deg); }
}

@media (max-width: 768px) {
  .app-confirm-modal,
  .app-form-modal {
    width: 100vw;
    max-width: 100vw;
    margin: auto 0 0;
    border-radius: 12px 12px 0 0;
  }
  .app-link-copy { flex-direction: column; }
}

@media (max-width: 768px) {
  .confirm-delete-modal {
    width: 100vw;
    max-width: 100vw;
    min-height: auto;
    margin: auto 0 0;
    border-radius: 12px 12px 0 0;
  }
}

.tabs {
  display: flex;
  gap: .35rem;
  margin-bottom: 1rem;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0px;
}
.tab {
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: .55rem 1rem;
  border-radius: 8px 8px 0 0;
  cursor: pointer;
  font: inherit;
  font-weight: 600;
}
.tab:hover { color: var(--text); background: var(--accent-soft); }
.tab.active {
  color: var(--text);
  background: var(--accent-soft-2);
  box-shadow: inset 0 -2px 0 var(--accent);
}
.tab-panel[hidden] { display: none !important; }

@media (max-width: 900px) {
  .tabs {
    overflow-x: auto;
    overflow-y: hidden;
    flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    overscroll-behavior-x: contain;
    max-width: 100%;
    min-width: 0;
  }
  .tabs::-webkit-scrollbar {
    display: none;
  }
  .tabs .tab {
    flex: 0 0 auto;
    white-space: nowrap;
  }
}

.client-detail-page .stats-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1rem;
  margin-bottom: 1rem;
}
.client-detail-page .charts-grid,
.client-detail-page .details-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
  margin-bottom: 1rem;
}
.client-info-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 1rem 1.5rem;
}
.client-info-item {
  display: flex;
  flex-direction: column;
  gap: .25rem;
}
.client-info-label {
  font-size: .78rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .03em;
}
.client-info-item strong {
  font-size: .95rem;
  font-weight: 600;
  word-break: break-word;
}
.prospect-link-wrap { margin-top: 1rem; }

@media (max-width: 1200px) {
  .client-detail-page .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 768px) {
  .client-detail-page .stats-grid,
  .client-detail-page .charts-grid,
  .client-detail-page .details-grid { grid-template-columns: 1fr; }
}

.prospect-list { display: grid; gap: .75rem; }

.toolbar-datatable {
  display: flex;
  flex-wrap: nowrap;
  gap: .65rem;
  align-items: center;
}
.toolbar-datatable > .toolbar-filter {
  display: flex;
  flex-direction: column;
  gap: .2rem;
  font-size: .78rem;
  color: var(--muted);
  flex: 0 0 auto;
}
.toolbar-filter-search {
  flex: 1 1 220px;
  min-width: 200px;
}
.toolbar-filter input[type="search"],
.toolbar-filter select {
  width: 100%;
  min-width: 0;
  flex: 0 0 auto;
}
.toolbar-datatable > input[type="search"] {
  flex: 1 1 220px;
  min-width: 200px;
  width: auto;
  max-width: none;
}
.toolbar-datatable > select {
  flex: 0 0 auto;
  width: auto;
  min-width: 9.5rem;
}
.toolbar-datatable .select2-container {
  flex: 0 0 auto;
  min-width: 11rem;
  max-width: 16rem;
}

@media (max-width: 900px) {
  .toolbar-datatable .select2-container {
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    flex: 1 1 100%;
  }
}

.datatable th.sortable {
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}
.datatable th.sortable:hover { color: var(--text); }
.datatable th.sortable.is-sorted { color: var(--accent-2); }
.datatable th.sortable.is-sorted[data-dir="asc"]::after { content: ' ↑'; font-size: .75rem; }
.datatable th.sortable.is-sorted[data-dir="desc"]::after { content: ' ↓'; font-size: .75rem; }

.datatable-footer {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: .75rem;
  margin-top: 0;
}
.datatable-pagination {
  display: flex;
  flex-wrap: wrap;
  gap: .35rem;
  align-items: center;
}
.btn-sm { padding: .35rem .65rem; font-size: .82rem; }
.datatable-pagination .btn.is-active {
  background: var(--accent-soft-2);
  border-color: var(--accent);
  color: var(--text);
}

.datatable-view-switch {
  display: none;
  grid-template-columns: 1fr 1fr;
  gap: .5rem;
  width: 100%;
  margin-bottom: .65rem;
}
.datatable-view-btn {
  width: 100%;
  min-height: 2.35rem;
  padding: .5rem .75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-panel);
  color: var(--text);
  font-weight: 600;
  font-size: .84rem;
  cursor: pointer;
  transition: border-color .15s, background .15s, color .15s;
}
.datatable-view-btn.is-active {
  background: var(--accent-soft-2);
  border-color: var(--accent);
  color: var(--accent-2);
}
.datatable-cards {
  display: none;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: .55rem;
  align-content: start;
}
.entity-card-empty {
  grid-column: 1 / -1;
  margin: .5rem 0;
  text-align: center;
}
.entity-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: .6rem;
  display: flex;
  flex-direction: column;
  gap: .35rem;
  min-width: 0;
}
.entity-card-head strong {
  display: block;
  font-size: .8rem;
  line-height: 1.25;
  word-break: break-word;
}
.entity-card-body {
  display: flex;
  flex-direction: column;
  gap: .35rem;
}
.entity-card-row {
  display: flex;
  gap: .4rem;
  align-items: flex-start;
  min-width: 0;
}
.entity-card-icon {
  flex-shrink: 0;
  width: 1rem;
  height: 1rem;
  color: var(--accent);
  margin-top: .12rem;
}
.entity-card-icon svg {
  width: 1rem;
  height: 1rem;
  display: block;
}
.entity-card-field {
  flex: 1;
  min-width: 0;
}
.entity-card-label {
  display: block;
  font-size: .62rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .03em;
  line-height: 1.2;
}
.entity-card-value {
  display: block;
  font-size: .74rem;
  line-height: 1.25;
  word-break: break-word;
}
.entity-card-value .badge,
.entity-card-value code {
  font-size: .68rem;
}
.entity-card-value .product-thumb {
  width: 2.75rem;
  height: 2.75rem;
  object-fit: cover;
  border-radius: 6px;
  display: block;
}
.entity-card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: .3rem;
  margin-top: .2rem;
  padding-top: .45rem;
  border-top: 1px solid var(--border);
}
.entity-card-actions .btn {
  flex: 1 1 calc(50% - .2rem);
  min-width: 0;
  padding: .32rem .35rem;
  font-size: .68rem;
  text-align: center;
  justify-content: center;
}

@media (max-width: 900px) {
  .toolbar-datatable {
    flex-direction: column;
    align-items: stretch;
    flex-wrap: nowrap;
    gap: .55rem;
  }
  .toolbar-datatable > input[type="search"],
  .toolbar-datatable > select,
  .toolbar-datatable > input:not([type="checkbox"]):not([type="radio"]),
  .toolbar-datatable > .toolbar-filter {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    flex: 1 1 auto;
    box-sizing: border-box;
  }
  .toolbar-datatable .select2-container {
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    flex: 1 1 100%;
  }
  .datatable-shell.has-card-view .datatable-view-switch {
    display: grid;
  }
  .datatable-shell.is-cards-view > .table-wrap {
    display: none;
  }
  .datatable-shell.is-cards-view > .datatable-cards {
    display: grid;
    grid-template-columns: 1fr;
    gap: .75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius) var(--radius) 0 0;
    background: var(--bg-elevated);
    padding: .65rem .75rem;
  }
  .entity-card {
    padding: .85rem 1rem;
    gap: .5rem;
    border-radius: 12px;
  }
  .entity-card-head strong {
    font-size: .95rem;
    line-height: 1.3;
  }
  .entity-card-body {
    gap: .45rem;
  }
  .entity-card-row {
    gap: .55rem;
    align-items: center;
  }
  .entity-card-icon {
    width: 1.15rem;
    height: 1.15rem;
    margin-top: 0;
  }
  .entity-card-icon svg {
    width: 1.15rem;
    height: 1.15rem;
  }
  .entity-card-label {
    font-size: .68rem;
    letter-spacing: .04em;
    margin-bottom: .1rem;
  }
  .entity-card-value {
    font-size: .88rem;
    line-height: 1.35;
  }
  .entity-card-value .badge,
  .entity-card-value code {
    font-size: .76rem;
  }
  .entity-card-value .product-thumb {
    width: 3.25rem;
    height: 3.25rem;
  }
  .entity-card-actions {
    gap: .45rem;
    margin-top: .35rem;
    padding-top: .55rem;
  }
  .entity-card-actions .btn {
    flex: 1 1 auto;
    min-height: 2.1rem;
    padding: .45rem .75rem;
    font-size: .78rem;
  }
  .datatable-shell.is-cards-view > .table-wrap + .datatable-cards + .datatable-footer,
  .datatable-shell.is-cards-view > .datatable-cards + .datatable-footer {
    margin-top: 0;
    border: 1px solid var(--border);
    border-top: 0;
    border-radius: 0 0 var(--radius) var(--radius);
    background: var(--bg-elevated);
  }
}

.kanban-board {
  display: grid;
  grid-template-columns: repeat(7, minmax(220px, 1fr));
  gap: .75rem;
  overflow-x: auto;
  padding-bottom: .5rem;
}
.kanban-column {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  min-height: 420px;
  display: flex;
  flex-direction: column;
}
.kanban-column-head {
  padding: .75rem .85rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: .2rem;
  font-weight: 600;
}
.kanban-column-head small { color: var(--muted); font-weight: 500; }
.kanban-column-body {
  padding: .65rem;
  display: flex;
  flex-direction: column;
  gap: .65rem;
  flex: 1;
  min-height: 120px;
  transition: background .15s ease;
}
.kanban-column-body.is-drop-target {
  background: var(--accent-soft);
  outline: 2px dashed var(--accent-2);
  outline-offset: -4px;
}
.kanban-empty { font-size: .82rem; text-align: center; margin: .5rem 0; }

.prospect-card {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: .85rem;
  cursor: pointer;
}
.prospect-card:hover { border-color: var(--accent-2); }
.prospect-card.is-dragging { opacity: .55; }
.prospect-card.priority-high { border-left: 3px solid var(--danger); }
.prospect-card.priority-low { border-left: 3px solid var(--muted); }
.prospect-card-meta { margin-top: .35rem; font-size: .9rem; }
.prospect-card-date, .prospect-card-assignee { margin-top: .25rem; font-size: .78rem; color: var(--muted); }

.lines-table { width: 100%; border-collapse: collapse; margin-top: .75rem; }
.lines-toolbar { display: flex; flex-wrap: wrap; gap: .5rem; margin-bottom: .5rem; }
.lines-table th, .lines-table td { padding: .45rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
.lines-table tfoot.table-sum-footer td {
  background: var(--bg-panel);
  border-top: 2px solid var(--border);
  padding: .55rem .45rem;
}
.lines-table tfoot.table-sum-footer .table-footer-label { text-align: right; color: var(--muted); }
.lines-table input, .lines-table select { width: 100%; min-width: 70px; padding: .4rem; }

.panel-toolbar {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: .75rem;
  margin-bottom: 0;
}

.brand-help { margin: 0 0 1rem; font-size: .88rem; }
.brand-upload-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1rem;
}
.brand-upload-card {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: .75rem;
}
.brand-preview {
  min-height: 96px;
  border: 1px dashed var(--border);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: .75rem;
  overflow: hidden;
}
.brand-preview img {
  max-width: 100%;
  max-height: 72px;
  object-fit: contain;
}
.brand-preview-light { background: #f8fafc; }
.brand-preview-dark { background: #0b1220; }
.brand-preview-favicon img { max-height: 32px; max-width: 32px; }
.brand-upload-actions { display: flex; flex-wrap: wrap; gap: .5rem; }
.brand-default-theme {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}
.brand-default-theme > strong { display: block; margin-bottom: .25rem; }
.theme-picker-settings {
  width: 100%;
  max-width: none;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
  position: relative;
  z-index: 1;
}
.theme-picker-settings .theme-picker-group {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
}
.theme-picker-settings .theme-picker-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
}
.theme-picker-settings .theme-swatch {
  display: block;
  width: 100%;
  height: 28px;
  min-height: 28px;
  cursor: pointer;
  box-sizing: border-box;
  pointer-events: auto;
}
.theme-picker-settings .theme-swatch.is-active {
  border-color: var(--accent-2) !important;
  box-shadow: 0 0 0 1px var(--bg-panel), 0 0 0 3px color-mix(in srgb, var(--accent-2) 55%, transparent);
  transform: scaleY(1.06);
}
.theme-picker-settings .theme-swatch:hover {
  transform: scaleY(1.08);
}
.brand-file-btn { cursor: pointer; margin: 0; }

@media (max-width: 900px) {
  .brand-upload-grid { grid-template-columns: 1fr; }
  .theme-picker-settings { grid-template-columns: 1fr; }
}

.product-thumb {
  width: 40px;
  height: 40px;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid var(--border);
  display: block;
}
.product-thumb-placeholder {
  display: inline-flex;
  width: 40px;
  height: 40px;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  border: 1px dashed var(--border);
  color: var(--muted);
  font-size: .75rem;
}
.product-images-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: .75rem;
  margin-top: .75rem;
}
.product-images-toolbar { margin-top: .5rem; display: flex; flex-wrap: wrap; gap: .65rem; align-items: center; }
.product-image-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .5rem;
  display: flex;
  flex-direction: column;
  gap: .35rem;
  cursor: grab;
}
.product-image-card.is-dragging { opacity: .55; cursor: grabbing; }
.product-image-card-head {
  display: flex;
  align-items: center;
  gap: .4rem;
  flex-wrap: wrap;
}
.product-image-grip {
  color: var(--muted);
  font-size: 1rem;
  line-height: 1;
  user-select: none;
}
.product-image-card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: .35rem;
}
.product-image-card img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: 6px;
}

.product-picker-layout {
  display: grid;
  grid-template-columns: minmax(240px, 1fr) minmax(280px, 1.2fr);
  gap: 1rem;
  min-height: 320px;
}
.product-picker-list {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: auto;
  max-height: 360px;
  padding: .35rem;
  display: flex;
  flex-direction: column;
  gap: .35rem;
}
.product-picker-item {
  display: flex;
  gap: .65rem;
  align-items: center;
  text-align: left;
  border: 1px solid var(--border);
  background: var(--bg-panel);
  border-radius: 8px;
  padding: .55rem;
  cursor: pointer;
  color: inherit;
  font: inherit;
}
.product-picker-item:hover,
.product-picker-item.is-selected {
  border-color: var(--accent);
  background: var(--accent-soft-2);
}
.product-picker-item img,
.product-picker-item .product-thumb-placeholder {
  width: 48px;
  height: 48px;
  flex-shrink: 0;
}
.product-picker-item strong { display: block; }
.product-picker-item small { color: var(--muted); }
.product-picker-detail {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
}
.variant-picker-list { display: grid; gap: .5rem; margin-top: .75rem; }
.variant-picker-option {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: .15rem .65rem;
  align-items: start;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: .65rem;
  cursor: pointer;
}
.variant-picker-option.is-selected { border-color: var(--accent); background: var(--accent-soft-2); }
.variant-picker-option small { grid-column: 2; color: var(--muted); }

.variant-type-picker {
  display: grid;
  gap: .5rem;
}
.variant-type-option {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: .15rem;
  width: 100%;
  text-align: left;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: .75rem .85rem;
  background: var(--bg-panel);
  color: var(--text);
  cursor: pointer;
  font: inherit;
}
.variant-type-option:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.variant-type-option strong {
  font-size: .92rem;
}
.variant-type-option .muted {
  font-size: .82rem;
}

@media (max-width: 768px) {
  .product-picker-layout { grid-template-columns: 1fr; }
}
.doc-totals { margin: 1rem 0; text-align: right; font-size: 1rem; }
.doc-totals strong { font-size: 1.2rem; color: var(--accent); }
.verifactu-panel { margin-top: 1rem; }
.verifactu-body code { word-break: break-all; font-size: .75rem; }
#vf-qr { margin-top: .75rem; background: #fff; padding: .5rem; border-radius: 8px; }

@media (max-width: 900px) {
  .mobile-nav-toggle { display: inline-flex; }
  .mobile-topbar-toggle { display: inline-flex; }

  html, body { overflow-x: hidden; }
  .app-main { max-width: 100vw; overflow-x: hidden; }

  .page-header {
    flex-wrap: nowrap;
    gap: .5rem;
    height: var(--app-topbar-height);
    min-height: var(--app-topbar-height);
    max-height: var(--app-topbar-height);
    padding: var(--app-topbar-padding-y) .75rem;
  }
  .page-header > h1,
  .page-header-title {
    flex: 1;
    min-width: 0;
    font-size: 1.05rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .page-header-title h1 {
    font-size: 1.05rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .page-header-title .muted {
    display: none;
  }

  .page-header-end {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100vw;
    max-width: 100vw;
    margin-left: 0;
    flex-direction: column;
    align-items: stretch;
    align-content: stretch;
    gap: .75rem;
    padding: 1.15rem 1.15rem;
    padding-top: calc(1.15rem + env(safe-area-inset-top, 0px));
    padding-bottom: calc(1.15rem + env(safe-area-inset-bottom, 0px));
    background: var(--bg-elevated);
    border-left: 0;
    box-shadow: none;
    z-index: 105;
    transform: translateX(100%);
    transition: transform .25s ease, box-shadow .25s ease;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    pointer-events: none;
    box-sizing: border-box;
  }
  body.mobile-topbar-open .page-header-end {
    transform: translateX(0);
    box-shadow: none;
    pointer-events: auto;
  }
  /* El drawer está dentro de .page-header (z-index 35); hay que elevarlo por encima del backdrop (104) */
  body.mobile-topbar-open .page-header {
    z-index: 110;
  }
  body.mobile-topbar-open { overflow: hidden; }

  .mobile-topbar-drawer-head { display: flex; }

  .page-header-end .header-actions,
  .page-header-end .doc-header-actions {
    flex-direction: column;
    align-items: stretch;
    flex-wrap: nowrap;
    width: 100%;
    gap: .5rem;
    margin: 0;
  }
  .page-header-end .header-actions > .dropdown,
  .page-header-end .doc-header-actions > .dropdown,
  .page-header-end .doc-action-dropdown,
  .page-header-end .add-menu-dropdown,
  .page-header-end .quick-actions-dropdown {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    width: 100%;
    max-width: 100%;
    margin: 0;
    flex-shrink: 0;
  }
  .page-header-end .add-menu-dropdown,
  .page-header-end .quick-actions-dropdown {
    display: none !important;
  }
  .page-header-end .add-menu-dropdown,
  .page-header-end .quick-actions-dropdown,
  .page-header-end > .btn,
  .page-header-end > a.btn {
    width: 100%;
  }
  .page-header-end .doc-action-dropdown .dropdown-toggle,
  .page-header-end .add-menu-dropdown .btn,
  .page-header-end .quick-actions-dropdown .btn,
  .page-header-end .header-actions > .btn,
  .page-header-end .doc-header-actions > .btn,
  .page-header-end .header-actions .btn.btn-sm,
  .page-header-end .doc-header-actions .btn.btn-sm {
    width: 100%;
    max-width: 100%;
    justify-content: flex-start;
    min-height: 3rem;
    height: auto;
    padding: .75rem 1rem;
    box-sizing: border-box;
    border-radius: 10px;
    font-size: 1rem;
    font-weight: 600;
  }
  .page-header-end .doc-action-dropdown .dropdown-menu,
  .page-header-end .add-menu-dropdown .dropdown-menu,
  .page-header-end .quick-actions-dropdown .dropdown-menu {
    position: static !important;
    inset: auto !important;
    display: none;
    float: none;
    width: 100%;
    min-width: 0;
    max-width: none;
    margin: 0;
    box-shadow: none;
  }
  .page-header-end .doc-action-dropdown .dropdown-menu {
    padding: 0;
    border: 0;
    background: transparent;
  }
  .page-header-end .add-menu-dropdown .dropdown-menu,
  .page-header-end .quick-actions-dropdown .dropdown-menu {
    padding: .85rem;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--bg-panel);
    margin-top: .4rem;
    box-sizing: border-box;
  }
  .page-header-end .doc-action-dropdown .dropdown-menu.show {
    display: flex;
    flex-direction: column;
    gap: .5rem;
  }
  .page-header-end .add-menu-dropdown .dropdown-menu.show,
  .page-header-end .quick-actions-dropdown .dropdown-menu.show {
    display: block;
  }
  .page-header-end .doc-action-dropdown {
    gap: .5rem;
  }
  .page-header-end .quick-actions-megamenu,
  .page-header-end .add-menu-megamenu {
    min-width: 0 !important;
    width: 100% !important;
    max-width: none !important;
  }
  .page-header-end .quick-actions-grid {
    grid-template-columns: 1fr;
  }
  .page-header-end .period-filter {
    flex-direction: column;
    align-items: stretch;
    width: 100%;
    white-space: normal;
  }
  .page-header-end .period-filter select {
    width: 100%;
  }
  .page-header-end > .topbar-user {
    margin-left: 0;
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: .5rem;
  }
  .page-header-end .topbar-user-toggle {
    width: 100%;
    max-width: none;
    justify-content: flex-start;
    min-height: 3rem;
    height: auto;
    padding: .75rem 1rem;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: var(--bg-panel);
    box-sizing: border-box;
    font-size: 1rem;
  }
  .page-header-end .topbar-user-avatar {
    width: 34px;
    height: 34px;
    font-size: .88rem;
  }
  .page-header-end .topbar-user-menu {
    position: static;
    width: 100%;
    margin: 0;
    padding: 0;
    box-shadow: none;
    border: 0;
    background: transparent;
    display: flex;
    flex-direction: column;
    gap: .5rem;
  }

  .page-content {
    padding: .75rem .85rem 1.25rem;
    max-width: 100%;
  }
  .dashboard-v2 .dashboard-hero-kpis,
  .dashboard-page .stats-grid,
  .list-kpi-page .stats-grid,
  .sales-dashboard-page .stats-grid,
  .purchases-dashboard-page .stats-grid {
    grid-template-columns: 1fr;
    gap: .75rem;
  }
  .stat-card-kpi {
    padding: .85rem;
  }
  .stat-card-kpi-value {
    font-size: 1.25rem;
    word-break: break-word;
  }
  .table-wrap {
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  .dashboard-v2 .dashboard-tables-grid {
    grid-template-columns: 1fr;
    gap: .75rem;
  }
  .dashboard-v2 .dashboard-tables-grid > .panel {
    min-width: 0;
    max-width: 100%;
  }
  .dashboard-v2 .dashboard-tables-grid .panel > .panel-body.table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    max-width: 100%;
  }
  /* Dashboard móvil: tablas primero, KPIs/gráficas al final */
  .dashboard-v2 .dashboard-tables-grid { order: 1; }
  .dashboard-v2 .dashboard-hero-kpis { order: 2; }
  .dashboard-v2 .dashboard-ops-panel { order: 3; }
  .dashboard-v2 .dashboard-charts-primary { order: 4; }
  .dashboard-v2 .dashboard-secondary-grid { order: 5; }
  .panel { max-width: 100%; min-width: 0; }

  .app-shell,
  .app-shell.sidebar-collapsed { grid-template-columns: 1fr; }

  body.mobile-nav-open .sidebar-backdrop { display: block; }

  .app-sidebar,
  .app-sidebar.is-collapsed {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    height: 100dvh;
    width: 100vw;
    max-width: 100vw;
    min-height: 0;
    transform: translateX(-100%);
    transition: transform .25s ease;
    z-index: 100;
    overflow: hidden;
    box-shadow: none;
    box-sizing: border-box;
  }

  .app-shell.is-mobile-nav-open .app-sidebar,
  .app-shell.is-mobile-nav-open .app-sidebar.is-collapsed {
    transform: translateX(0);
    box-shadow: none;
  }

  .app-sidebar .sidebar-brand {
    min-height: 3.75rem;
    padding: 1rem 1.15rem;
  }
  .app-sidebar .sidebar-nav {
    padding: .75rem 1rem;
    gap: .2rem;
  }
  .app-sidebar .sidebar-nav > .sidebar-link-root:first-child {
    font-size: 1rem;
    padding: .85rem 1rem;
    min-height: 3rem;
    margin-bottom: .25rem;
  }
  .app-sidebar .sidebar-link-root,
  .app-sidebar .sidebar-group-toggle {
    font-size: 1rem;
    padding: .85rem 1rem;
    min-height: 3rem;
    border-radius: 10px;
    gap: .75rem;
  }
  .app-sidebar .sidebar-icon {
    width: 1.35rem;
    height: 1.35rem;
    flex-shrink: 0;
  }
  .app-sidebar .sidebar-chevron {
    width: 18px;
    height: 18px;
  }
  .app-sidebar .sidebar-section {
    font-size: .78rem;
    padding: 1rem 1rem .45rem;
  }
  .app-sidebar .sidebar-submenu-inner {
    margin-left: 2.15rem;
    padding-left: .65rem;
    gap: .12rem;
  }
  .app-sidebar .sidebar-sublink {
    font-size: .95rem;
    padding: .72rem 1rem;
    min-height: 2.75rem;
    border-radius: 8px;
  }
  .app-sidebar .sidebar-search-btn {
    min-height: 3rem;
    padding: .85rem 1rem;
    margin: .5rem 1rem 1rem;
    font-size: 1rem;
    border-radius: 10px;
    gap: .75rem;
  }

  .app-sidebar.is-collapsed .sidebar-brand-text,
  .app-sidebar.is-collapsed .sidebar-label,
  .app-sidebar.is-collapsed .sidebar-chevron,
  .app-sidebar.is-collapsed .sidebar-user-meta {
    opacity: 1;
    width: auto;
    overflow: visible;
    pointer-events: auto;
  }

  .app-sidebar.is-collapsed .logo-dot { display: block; }
  .app-shell.is-mobile-nav-open .app-sidebar .sidebar-brand-logo-full,
  html[data-theme-mode="light"] .app-shell.is-mobile-nav-open .app-sidebar .sidebar-brand-logo--light,
  html[data-theme-mode="dark"] .app-shell.is-mobile-nav-open .app-sidebar .sidebar-brand-logo--dark,
  .app-shell.is-mobile-nav-open .app-sidebar .sidebar-brand-logo--only {
    display: block !important;
  }
  .app-shell.is-mobile-nav-open .app-sidebar .sidebar-brand-favicon {
    display: none !important;
  }
  .app-sidebar.is-collapsed .sidebar-brand { justify-content: flex-start; padding-inline: 1rem; gap: .65rem; }
  .app-sidebar.is-collapsed .sidebar-link-root,
  .app-sidebar.is-collapsed .sidebar-group-toggle { justify-content: flex-start; padding-inline: .75rem; }
  .app-sidebar.is-collapsed .sidebar-group.is-open > .sidebar-submenu { display: block !important; }
  .sidebar-flyout { display: none !important; }
  .sidebar-collapse-btn { display: none; }
  .app-sidebar.is-collapsed .sidebar-search-btn .sidebar-label { display: inline; }

  body.mobile-nav-open { overflow: hidden; }

  .dashboard-page .charts-grid,
  .dashboard-page .details-grid { grid-template-columns: 1fr; }
  .charts-grid, .details-grid { grid-template-columns: 1fr; }
  .chart-panel-wide { grid-column: auto; }
  .form-grid,
  .form-grid-3,
  .form-grid-4 { grid-template-columns: 1fr; }
  .form-grid .span-2,
  .form-grid-3 .span-2,
  .form-grid-4 .span-2 { grid-column: span 1; }
  .kanban-board { grid-template-columns: repeat(7, minmax(260px, 1fr)); }
}

@media (max-width: 768px) {
  .modal-user,
  .modal-client,
  .modal-product {
    width: 100vw;
    max-width: 100vw;
    min-height: 100dvh;
    height: auto;
    max-height: none;
    margin: 0;
    border-radius: 0;
    border-left: 0;
    border-right: 0;
  }
  dialog.form-modal-open.modal-client,
  dialog.form-modal-open.modal-product,
  dialog.form-modal-open.modal-user {
    width: calc(100vw - 1.5rem);
    max-width: calc(100vw - 1.5rem);
    min-height: 0;
    border-radius: 12px;
    border: 1px solid var(--border);
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    margin: 0;
    max-height: calc(100dvh - 1.5rem);
  }
  dialog.form-modal-open > .modal-body,
  dialog.form-modal-open > form.modal-body {
    max-height: calc(100dvh - 1.5rem);
  }
  .modal-user .modal-body,
  .modal-client .modal-body,
  .modal-product .modal-body {
    padding: 1rem;
    max-height: none;
    overflow: visible;
    min-height: calc(100dvh - 1rem);
  }
}

/* Búsqueda global */
.sidebar-search-btn {
  display: flex;
  align-items: center;
  gap: .75rem;
  width: calc(100% - 1rem);
  margin: .5rem .5rem 1rem;
  padding: .65rem .85rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg-panel);
  color: var(--muted);
  cursor: pointer;
}
.sidebar-search-btn:hover { border-color: var(--accent); color: var(--text); }
.app-sidebar.is-collapsed .sidebar-search-btn .sidebar-label { display: none; }

/* Búsqueda global (overlay) */
#global-search-modal {
  position: fixed;
  inset: 0;
  z-index: 10002;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: min(10vh, 4rem) 1rem 1rem;
  margin: 0;
  border: none;
  background: transparent;
  max-width: none;
  width: auto;
  height: auto;
  overflow: hidden;
  box-sizing: border-box;
}
#global-search-modal[hidden] {
  display: none !important;
}
#global-search-modal .modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.72);
  border: none;
}
#global-search-modal .modal-dialog {
  position: relative;
  z-index: 1;
  width: min(560px, calc(100vw - 2rem));
  max-width: 560px;
  max-height: calc(100dvh - 6rem);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.45);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
#global-search-modal .modal-dialog .modal-header {
  padding: 1rem 1.25rem 0;
  margin-bottom: 0;
  flex-shrink: 0;
}
#global-search-modal .modal-dialog .modal-body {
  padding: 0.75rem 1.25rem 1.25rem;
  overflow-y: auto;
  min-height: 0;
}
.modal-search input[type="search"] { width: 100%; margin-bottom: .75rem; }
.global-search-results {
  display: grid;
  gap: .35rem;
  max-height: min(360px, calc(100dvh - 14rem));
  overflow: auto;
}
.global-search-item {
  display: grid;
  gap: .15rem;
  padding: .65rem .75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  text-decoration: none;
  color: inherit;
}
.global-search-item:hover { border-color: var(--accent); background: rgba(34,197,94,.06); }
.global-search-type { font-size: .72rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }

/* Páginas públicas */
.public-page { background: var(--bg); color: var(--text); min-height: 100vh; }
.public-shell { max-width: 820px; margin: 0 auto; padding: 2rem 1rem 3rem; }
.public-header { margin-bottom: 1.5rem; }
.public-main .data-table { width: 100%; margin: 1rem 0; }
.public-meta { display: grid; gap: .35rem; margin-bottom: 1rem; }
.public-actions { display: flex; gap: .75rem; margin-top: 1.5rem; flex-wrap: wrap; }
.public-result { text-align: center; padding-top: 4rem; }
.payments-form { margin-bottom: 1rem; align-items: end; }
.bank-import-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .75rem;
}
.bank-import-actions label.btn { cursor: pointer; margin: 0; }
.bank-import-status { font-size: .9rem; }

.import-help { margin: 0 0 1rem; font-size: .9rem; }
.import-actions { margin-bottom: 1rem; }
.import-drop {
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  text-align: center;
  background: var(--bg-elevated);
  margin-bottom: 1rem;
}
.import-file-label {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .5rem;
  cursor: pointer;
  color: var(--text-muted);
  font-size: .92rem;
}
.import-file-label:hover { color: var(--accent-2); }
.import-file-icon { font-size: 2rem; line-height: 1; }
.import-status-success { color: var(--accent) !important; }
.import-status-error { color: var(--danger) !important; }

.whatsapp-qr-wrap { margin-top: 1rem; }
.whatsapp-qr {
  display: block;
  max-width: 280px;
  width: 100%;
  margin-top: .75rem;
  border-radius: 8px;
  background: #fff;
  padding: .5rem;
}
.modal-import .modal-body { max-width: 520px; }

dialog.modal-fullscreen[open],
dialog.modal-fullscreen.form-modal-open {
  position: fixed;
  inset: 0;
  top: 0 !important;
  left: 0 !important;
  right: 0 !important;
  bottom: 0 !important;
  transform: none !important;
  width: 100% !important;
  max-width: 100% !important;
  height: 100dvh !important;
  max-height: 100dvh !important;
  min-height: 100dvh !important;
  margin: 0 !important;
  border-radius: 0 !important;
  border: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 10001;
}
dialog.modal-fullscreen > .modal-body {
  flex: 1 1 auto;
  min-height: 0;
  max-width: none;
  width: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 1rem 1.25rem 1.25rem;
  box-sizing: border-box;
}
.prestashop-import-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: .75rem 1rem;
  margin-bottom: .75rem;
}
.prestashop-import-toolbar label {
  display: flex;
  flex-direction: column;
  gap: .25rem;
  font-size: .78rem;
  color: var(--muted);
}
.prestashop-import-toolbar input[type="number"] {
  min-width: 8rem;
  height: 2.125rem;
  padding: 0 .65rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-panel);
  color: var(--text);
}
.prestashop-import-batch {
  flex-direction: row !important;
  align-items: center;
  gap: .45rem !important;
  color: var(--text) !important;
  font-size: .82rem !important;
  margin-bottom: .15rem;
}
.prestashop-import-status {
  margin: 0 0 .75rem;
}
.prestashop-import-status-error { color: var(--danger); }
.prestashop-import-status-success { color: var(--accent); }
.prestashop-import-table-wrap {
  flex: 1 1 auto;
  min-height: 12rem;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-elevated);
}
.modal-prestashop-import .modal-actions {
  flex-shrink: 0;
  margin-top: .85rem;
}
#prestashop-preview-table .col-check {
  width: 2.5rem;
  text-align: center;
}
.prestashop-preview-footer {
  flex-shrink: 0;
  margin-top: .65rem;
}
.prestashop-preview-page-size,
.prestashop-preview-filter {
  display: flex;
  flex-direction: column;
  gap: .25rem;
  font-size: .78rem;
  color: var(--muted);
}
.prestashop-preview-page-size select,
.prestashop-preview-filter select {
  min-width: 5.5rem;
  height: 2.125rem;
  padding: 0 .65rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-panel);
  color: var(--text);
}
.prestashop-preview-filter select {
  min-width: 14rem;
  max-width: 22rem;
}
.prestashop-preview-page-size select {
  min-width: 5.5rem;
}

dialog.modal-prestashop-progress[open],
dialog.modal-woocommerce-progress[open] {
  z-index: 10002;
  width: auto;
  min-width: 280px;
  max-width: min(420px, calc(100vw - 2rem));
  margin: auto;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 12px;
}
dialog.modal-prestashop-progress[open]::backdrop,
dialog.modal-woocommerce-progress[open]::backdrop {
  background: rgba(0, 0, 0, .55);
}
.modal-prestashop-progress .modal-body,
.modal-woocommerce-progress .modal-body {
  display: flex;
  flex-direction: column;
  gap: .75rem;
  padding: 1.35rem 1.5rem 1.5rem;
  max-width: none;
}
.modal-prestashop-progress #prestashop-progress-title,
.modal-woocommerce-progress #woocommerce-progress-title {
  margin: 0;
  font-size: .95rem;
  font-weight: 600;
  text-align: center;
}
.prestashop-progress-bar,
.woocommerce-progress-bar {
  width: 100%;
  height: .65rem;
  border-radius: 999px;
  background: color-mix(in srgb, var(--muted) 18%, var(--bg-panel));
  overflow: hidden;
}
.prestashop-progress-fill,
.woocommerce-progress-fill {
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent), color-mix(in srgb, var(--accent) 70%, var(--accent-2)));
  transition: width .25s ease;
}
.prestashop-progress-label,
.woocommerce-progress-label {
  margin: 0;
  text-align: center;
  font-size: .88rem;
  font-weight: 600;
  color: var(--accent);
}

.woocommerce-import-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: .75rem 1rem;
  margin-bottom: .75rem;
}
.woocommerce-import-toolbar label {
  display: flex;
  flex-direction: column;
  gap: .25rem;
  font-size: .78rem;
  color: var(--muted);
}
.woocommerce-import-toolbar input[type="number"] {
  min-width: 8rem;
  height: 2.125rem;
  padding: 0 .65rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-panel);
  color: var(--text);
}
.woocommerce-import-batch {
  flex-direction: row !important;
  align-items: center;
  gap: .45rem !important;
  color: var(--text) !important;
  font-size: .82rem !important;
  margin-bottom: .15rem;
}
.woocommerce-import-status { margin: 0 0 .75rem; }
.woocommerce-import-status-error { color: var(--danger); }
.woocommerce-import-status-success { color: var(--accent); }
.woocommerce-import-table-wrap {
  flex: 1 1 auto;
  min-height: 12rem;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-elevated);
}
.modal-woocommerce-import .modal-actions {
  flex-shrink: 0;
  margin-top: .85rem;
}
#woocommerce-preview-table .col-check {
  width: 2.5rem;
  text-align: center;
}
.woocommerce-preview-footer {
  flex-shrink: 0;
  margin-top: .65rem;
}
.woocommerce-preview-page-size,
.woocommerce-preview-filter {
  display: flex;
  flex-direction: column;
  gap: .25rem;
  font-size: .78rem;
  color: var(--muted);
}
.woocommerce-preview-page-size select,
.woocommerce-preview-filter select {
  min-width: 5.5rem;
  height: 2.125rem;
  padding: 0 .65rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-panel);
  color: var(--text);
}
.woocommerce-preview-filter select {
  min-width: 14rem;
  max-width: 22rem;
}
.woocommerce-preview-page-size select {
  min-width: 5.5rem;
}

.bank-import-toolbar { margin-bottom: .75rem; }

.bank-match-list {
  display: flex;
  flex-direction: column;
  gap: .5rem;
  max-height: 240px;
  overflow-y: auto;
  margin-top: .5rem;
}

.bank-match-item {
  display: grid;
  grid-template-columns: 1fr 1.2fr auto auto;
  gap: .75rem;
  align-items: center;
  text-align: left;
  padding: .65rem .85rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  cursor: pointer;
}

.bank-match-item:hover { border-color: var(--primary); background: var(--bg-elevated); }

.bank-match-score {
  font-size: .8rem;
  color: var(--primary);
  white-space: nowrap;
}

.permission-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: .35rem .75rem;
  margin-top: .75rem;
}

.permission-item { font-size: .9rem; }

.public-shell-narrow { max-width: 420px; margin: 0 auto; }

.btn-block { width: 100%; margin-top: .5rem; }

.verifactu-cert-upload {
  display: flex;
  align-items: center;
  gap: .75rem;
  margin: .75rem 0;
}

.period-filter {
  display: inline-flex;
  flex-direction: row;
  align-items: center;
  gap: .5rem;
  font-size: .9rem;
  margin: 0;
  color: var(--muted);
  white-space: nowrap;
}
.period-filter select {
  min-width: 120px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: .45rem .65rem;
  font-size: .9rem;
  line-height: 1.2;
}
.page-header-end .period-filter {
  align-self: center;
}

/* Accesos rápidos (megamenú) — orden solo en escritorio */
@media (min-width: 901px) {
  .page-header-end .add-menu-dropdown {
    order: -2;
    flex-shrink: 0;
  }
  .page-header-end .quick-actions-dropdown {
    order: -1;
    flex-shrink: 0;
  }
  .page-header-end > .topbar-user {
    margin-left: auto;
    flex-shrink: 0;
  }
}
.quick-actions-dropdown { position: relative; }
.quick-actions-dropdown .dropdown-menu {
  display: none;
  position: absolute;
  inset: auto 0 auto auto;
  z-index: 1050;
}
.quick-actions-dropdown .dropdown-menu.show {
  display: block;
}
.quick-actions-toggle {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
}
.quick-actions-toggle::after {
  display: none;
}
.quick-actions-toggle-icon {
  width: 1rem;
  height: 1rem;
  flex-shrink: 0;
}
.quick-actions-toggle-label {
  font-size: .85rem;
}
.quick-actions-megamenu {
  --bs-dropdown-min-width: 0;
  min-width: 0;
  max-width: none;
  width: 100%;
  padding: .85rem;
  margin-top: .45rem !important;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg-panel);
  box-shadow: 0 18px 40px rgba(0, 0, 0, .22);
  max-height: min(78vh, 640px);
  overflow: auto;
  box-sizing: border-box;
  scrollbar-width: thin;
  scrollbar-color: color-mix(in srgb, var(--muted) 30%, var(--bg-panel)) transparent;
}
.quick-actions-megamenu::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
.quick-actions-megamenu::-webkit-scrollbar-track {
  background: transparent;
}
.quick-actions-megamenu::-webkit-scrollbar-thumb {
  background-color: color-mix(in srgb, var(--muted) 26%, var(--bg-panel));
  border-radius: 999px;
  border: 2px solid transparent;
  background-clip: padding-box;
}
.quick-actions-megamenu::-webkit-scrollbar-thumb:hover {
  background-color: color-mix(in srgb, var(--muted) 40%, var(--bg-panel));
}
.quick-actions-megamenu::-webkit-scrollbar-corner {
  background: transparent;
}
.quick-actions-megamenu-header {
  display: flex;
  flex-direction: column;
  gap: .15rem;
  padding: 0 .15rem .65rem;
  margin-bottom: .35rem;
  border-bottom: 1px solid var(--border);
}
.quick-actions-megamenu-header strong {
  font-size: .95rem;
  color: var(--text);
}
.quick-actions-megamenu-header .muted {
  font-size: .78rem;
  line-height: 1.35;
}
.quick-actions-section + .quick-actions-section {
  margin-top: .75rem;
  padding-top: .65rem;
  border-top: 1px solid var(--border);
}
.quick-actions-section-title {
  margin: 0 0 .5rem;
  padding: 0 .15rem;
  font-size: .68rem;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--muted);
}
.quick-actions-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: .35rem;
}
.quick-action-item {
  display: flex;
  align-items: flex-start;
  gap: .6rem;
  padding: .55rem .6rem;
  border-radius: 10px;
  color: var(--text);
  text-decoration: none;
  transition: background .15s ease, transform .15s ease;
}
.quick-action-item:hover,
.quick-action-item:focus-visible {
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  color: var(--text);
  text-decoration: none;
}
.quick-action-item:focus-visible {
  outline: 2px solid var(--accent-2);
  outline-offset: 1px;
}
.quick-action-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  border-radius: 9px;
  flex-shrink: 0;
}
.quick-action-icon svg {
  width: 1.1rem;
  height: 1.1rem;
}
.quick-action-icon.tone-green { background: color-mix(in srgb, #22c55e 18%, transparent); color: #22c55e; }
.quick-action-icon.tone-amber { background: color-mix(in srgb, #f59e0b 18%, transparent); color: #f59e0b; }
.quick-action-icon.tone-blue { background: color-mix(in srgb, #3b82f6 18%, transparent); color: #3b82f6; }
.quick-action-icon.tone-purple { background: color-mix(in srgb, #a855f7 18%, transparent); color: #a855f7; }
.quick-action-icon.tone-cyan { background: color-mix(in srgb, #06b6d4 18%, transparent); color: #06b6d4; }
.quick-action-icon.tone-orange { background: color-mix(in srgb, #f97316 18%, transparent); color: #f97316; }
.quick-action-icon.tone-slate { background: color-mix(in srgb, var(--muted) 22%, transparent); color: var(--text); }
.quick-action-text {
  display: flex;
  flex-direction: column;
  gap: .1rem;
  min-width: 0;
}
.quick-action-text strong {
  font-size: .84rem;
  font-weight: 600;
  line-height: 1.25;
}
.quick-action-text small {
  font-size: .72rem;
  line-height: 1.3;
  color: var(--muted);
}
@media (min-width: 901px) {
  .page-header-end .add-menu-dropdown,
  .page-header-end .quick-actions-dropdown {
    position: relative;
  }
  .page-header-end .add-menu-dropdown .dropdown-menu,
  .page-header-end .quick-actions-dropdown .dropdown-menu {
    position: fixed !important;
    inset: var(--app-topbar-height) 0 auto var(--sidebar-width) !important;
    transform: none !important;
    width: auto !important;
    min-width: 0 !important;
    max-width: none !important;
    margin: 0 !important;
    padding: .85rem 25px !important;
    border: 1px solid var(--border) !important;
    border-top: 0 !important;
    border-radius: 0 0 12px 12px !important;
    background: var(--bg-panel) !important;
    box-shadow: 0 18px 40px rgba(0, 0, 0, .22) !important;
    z-index: 1060;
    max-height: min(78vh, 640px);
    overflow: auto;
    box-sizing: border-box;
  }
  .app-shell.sidebar-collapsed .page-header-end .add-menu-dropdown .dropdown-menu,
  .app-shell.sidebar-collapsed .page-header-end .quick-actions-dropdown .dropdown-menu {
    left: var(--sidebar-width-collapsed) !important;
  }
  .page-header-end .quick-actions-grid {
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  }
}
@media (max-width: 1100px) {
  .quick-actions-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}
@media (max-width: 900px) {
  .quick-actions-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
@media (max-width: 640px) {
  .quick-actions-toggle-label { display: none; }
  .quick-actions-grid {
    grid-template-columns: 1fr;
  }
}

/* Prospección: calendario a altura de viewport */
.app-shell:has(.page-content-prospects #tab-calendar:not([hidden])) {
  height: 100dvh;
  max-height: 100dvh;
  overflow: hidden;
}

.app-shell:has(.page-content-prospects #tab-calendar:not([hidden])) .app-main {
  min-height: 0;
  overflow: hidden;
}

.page-content-prospects {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.page-content-prospects .tabs {
  flex-shrink: 0;
}

.page-content-prospects:has(#tab-calendar:not([hidden])) #tab-calendar {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.crm-fullcalendar {
  --fc-border-color: var(--border);
  --fc-page-bg-color: var(--bg);
  --fc-neutral-bg-color: var(--bg-elevated);
  --fc-neutral-text-color: var(--muted);
  --fc-button-bg-color: var(--bg-panel);
  --fc-button-border-color: var(--border);
  --fc-button-text-color: var(--text);
  --fc-button-hover-bg-color: color-mix(in srgb, var(--accent) 14%, var(--bg-elevated));
  --fc-button-hover-border-color: var(--accent);
  --fc-button-active-bg-color: var(--accent);
  --fc-button-active-border-color: var(--accent-dark);
  --fc-today-bg-color: color-mix(in srgb, var(--accent) 14%, transparent);
  --fc-event-text-color: #fff;
  --fc-list-event-hover-bg-color: color-mix(in srgb, var(--accent) 8%, var(--bg-elevated));
  flex: 1;
  min-height: 0;
  margin-bottom: .5rem;
}

.crm-fullcalendar .fc-daygrid-day.fc-day-today,
.crm-fullcalendar .fc-timegrid-col.fc-day-today {
  background: color-mix(in srgb, var(--accent) 10%, var(--bg-elevated));
}

.crm-fullcalendar .fc-button {
  font-size: .82rem;
  padding: .35rem .65rem;
  color: var(--text) !important;
  background: var(--bg-panel) !important;
  border-color: var(--border) !important;
  opacity: 1;
}

.crm-fullcalendar .fc-button:hover:not(:disabled) {
  color: var(--text) !important;
  background: color-mix(in srgb, var(--accent) 14%, var(--bg-elevated)) !important;
  border-color: var(--accent) !important;
}

.crm-fullcalendar .fc-button:focus {
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 35%, transparent);
}

.crm-fullcalendar .fc-button.fc-button-active,
.crm-fullcalendar .fc-button:active:not(:disabled) {
  color: var(--accent-on) !important;
  background: var(--accent) !important;
  border-color: var(--accent-dark) !important;
}

.crm-fullcalendar .fc-button:disabled {
  opacity: .45;
  color: var(--muted) !important;
}

.crm-fullcalendar .fc-button .fc-icon {
  color: inherit;
}

.crm-fullcalendar .fc-daygrid-week-number {
  color: var(--muted);
}

.crm-fullcalendar .fc {
  font-size: .9rem;
}

.crm-fullcalendar .fc-toolbar-title {
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--text);
}

.crm-fullcalendar .fc-col-header-cell-cushion,
.crm-fullcalendar .fc-daygrid-day-number,
.crm-fullcalendar .fc-list-day-text,
.crm-fullcalendar .fc-list-day-side-text,
.crm-fullcalendar .fc-timegrid-axis-cushion {
  color: var(--text);
}

.crm-fullcalendar .fc-scrollgrid,
.crm-fullcalendar .fc-theme-standard td,
.crm-fullcalendar .fc-theme-standard th {
  border-color: var(--border);
}

.crm-fullcalendar .fc-popover {
  background: var(--bg-elevated);
  border-color: var(--border);
}

.crm-fullcalendar .fc-popover-header {
  background: var(--bg);
  color: var(--text);
}

.crm-calendar-legend {
  display: flex;
  flex-wrap: wrap;
  gap: .75rem 1rem;
  align-items: center;
  font-size: .82rem;
  margin-bottom: .5rem;
  flex-shrink: 0;
}

.crm-calendar-legend .legend-dot {
  display: inline-block;
  width: .65rem;
  height: .65rem;
  border-radius: 50%;
  margin-right: .25rem;
  vertical-align: middle;
}

.crm-calendar-legend .status-new { background: #64748b; }
.crm-calendar-legend .status-contacted { background: #3b82f6; }
.crm-calendar-legend .status-qualified { background: #8b5cf6; }

.scan-upload-modal {
  width: min(560px, calc(100vw - 2rem));
  max-width: none;
}
.scan-upload-modal .modal-body {
  width: 100%;
  max-width: none;
  box-sizing: border-box;
}
.scan-upload-modal .modal-header { align-items: flex-start; margin-bottom: 0; }
.scan-upload-intro { margin: .35rem 0 0; font-size: .9rem; }
.scan-upload-content { margin-top: 1rem; width: 100%; }

.scan-dropzone {
  position: relative;
  width: 100%;
  box-sizing: border-box;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  background: var(--bg-elevated);
  transition: border-color .15s ease, background .15s ease;
}
.scan-dropzone--drag {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 8%, var(--bg-elevated));
}
.scan-dropzone--has-file {
  border-style: solid;
  border-color: var(--border);
  background: var(--surface);
}

.scan-dropzone-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .35rem;
  padding: 2rem 1.25rem 1.5rem;
  text-align: center;
  cursor: pointer;
}
.scan-dropzone-empty:hover { color: var(--accent-2); }
.scan-dropzone-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 3.25rem;
  height: 3.25rem;
  border-radius: 50%;
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  font-size: 1.65rem;
  line-height: 1;
  margin-bottom: .25rem;
}
.scan-dropzone-title {
  margin: 0;
  font-weight: 600;
  font-size: 1rem;
}
.scan-dropzone-hint { margin: 0; font-size: .88rem; }
.scan-formats {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: .35rem;
  margin: .65rem 0 .85rem;
}
.scan-formats span {
  padding: .15rem .55rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: .72rem;
  font-weight: 600;
  letter-spacing: .03em;
  color: var(--text-muted);
  background: var(--surface);
}
.scan-select-btn { pointer-events: none; position: relative; z-index: 0; }
.scan-file-input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
  z-index: 1;
}
.scan-dropzone--has-file .scan-file-input {
  display: none;
}

.scan-dropzone-filled { padding: .85rem; }
.scan-file-meta {
  display: flex;
  align-items: center;
  gap: .65rem;
  padding: .55rem .65rem;
  margin-bottom: .65rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-elevated);
}
.scan-file-type-icon {
  flex-shrink: 0;
  font-size: 1.35rem;
  line-height: 1;
}
.scan-file-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: .1rem;
}
.scan-file-info strong {
  font-size: .92rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.scan-file-info .muted { font-size: .8rem; }

.scan-preview {
  padding: .65rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  max-height: 260px;
  overflow: auto;
}
.scan-preview img,
.scan-preview iframe {
  display: block;
  max-width: 100%;
  max-height: 220px;
  margin: 0 auto;
  object-fit: contain;
}
.scan-preview iframe {
  width: 100%;
  min-height: 200px;
  border: 0;
  background: #fff;
  border-radius: var(--radius-sm);
}

.scan-status {
  margin: .75rem 0 0;
  padding: .55rem .75rem;
  border-radius: var(--radius-sm);
  font-size: .88rem;
  text-align: center;
}
.scan-status--error {
  color: var(--danger);
  background: color-mix(in srgb, var(--danger) 10%, transparent);
  border: 1px solid color-mix(in srgb, var(--danger) 25%, transparent);
}
.scan-status--loading {
  color: var(--accent-2);
  background: color-mix(in srgb, var(--accent) 10%, transparent);
  border: 1px solid color-mix(in srgb, var(--accent) 25%, transparent);
}
.input-inline {
  width: 100%;
  min-width: 0;
  padding: .35rem .5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: inherit;
  font: inherit;
}
.input-narrow { max-width: 5.5rem; }

.scan-lines-sum-row td { border-top: 2px solid var(--border); padding-top: .65rem; }
.text-right { text-align: right; }

/* Modal revisión escaneo */
.scan-review-modal .modal-header { align-items: center; margin-bottom: 0; }
.scan-review-intro { margin: 0; font-size: .9rem; }
.scan-review-block {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.15rem 1.25rem 1.25rem;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
.scan-review-block legend {
  padding: 0 .45rem;
  color: var(--accent-2);
  font-size: .9rem;
  font-weight: 600;
}
.scan-review-fields {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1rem;
  margin-bottom: 0;
}
.scan-field-span-2 { grid-column: span 2; }
.scan-field-full { grid-column: 1 / -1; }

.scan-lines-wrap { margin-bottom: 0; border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: auto; }
.scan-lines-table { table-layout: fixed; width: 100%; margin: 0; }
.scan-lines-table col.col-desc { width: auto; }
.scan-lines-table col.col-qty { width: 4.5rem; }
.scan-lines-table col.col-price { width: 6rem; }
.scan-lines-table col.col-tax { width: 4.5rem; }
.scan-lines-table col.col-total { width: 6.5rem; }
.scan-lines-table col.col-actions { width: 2.75rem; }
.scan-lines-table th,
.scan-lines-table td { vertical-align: middle; padding: .45rem .5rem; }
.scan-lines-table th.col-num,
.scan-lines-table td.col-num { text-align: right; }
.scan-lines-table .line-total-cell { text-align: right; font-weight: 600; white-space: nowrap; }
.scan-lines-table .line-action-cell { text-align: center; padding: .35rem .25rem; }
.scan-lines-table .scan-lines-empty { text-align: center; padding: 1rem; }
.scan-line-input {
  width: 100%;
  min-width: 0;
  box-sizing: border-box;
  padding: .45rem .5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-panel);
  color: inherit;
  font: inherit;
}
.scan-line-input--num { text-align: right; }

.scan-review-totals {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1rem;
  margin-top: 1rem;
  padding: 1rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.scan-review-total-box { display: flex; flex-direction: column; gap: .35rem; min-width: 0; }
.scan-review-total-label { font-size: .85rem; color: var(--muted); display: flex; flex-direction: column; gap: .35rem; }
.scan-review-total-value { font-size: 1.15rem; font-weight: 600; }
.scan-document-total-input {
  width: 100%;
  padding: .55rem .65rem;
  font-size: 1.15rem;
  font-weight: 700;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-panel);
  color: inherit;
  text-align: right;
}

.scan-review-add-line {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 5.5rem 6.5rem auto;
  gap: .75rem;
  align-items: end;
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}
.scan-review-add-action { display: flex; align-items: flex-end; padding-bottom: .1rem; }
.scan-review-add-action .btn { white-space: nowrap; }

.scan-total-warning {
  margin: .75rem 0 0;
  padding: .65rem .85rem;
  border-radius: var(--radius-sm);
  background: rgba(245, 158, 11, .12);
  color: #f59e0b;
  font-size: .9rem;
}
.scan-review-footer { margin-top: .5rem; }

/* Dashboard v2 */
.dashboard-v2 {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
.dashboard-v2 .dashboard-hero-kpis {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 1rem;
}
.dashboard-v2 .dashboard-charts-primary {
  display: grid;
  grid-template-columns: minmax(0, 2.2fr) minmax(260px, 1fr);
  gap: 1rem;
  align-items: stretch;
}
.dashboard-v2 .dashboard-charts-primary > .panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  height: 100%;
}
.dashboard-v2 .dashboard-charts-primary .panel-body.chart-wrap {
  flex: 1;
  min-height: 0;
  height: auto;
}
.dashboard-v2 .chart-wrap-primary { min-height: 300px; }
.dashboard-v2 .dashboard-chart-side .chart-wrap-donut { min-height: 200px; }
.dashboard-v2 .dashboard-secondary-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1rem;
  align-items: stretch;
}
.dashboard-v2 .dashboard-secondary-grid > .panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.dashboard-v2 .dashboard-secondary-grid .chart-wrap {
  flex: 1;
  min-height: 240px;
  height: auto;
}
.dashboard-v2 .dashboard-tables-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
  align-items: start;
}
.dashboard-ops-panel .panel-body.dashboard-ops-list {
  padding: 1rem;
  background: transparent;
  border: 0;
}
.dashboard-ops-list {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 1rem;
  align-items: stretch;
}
.dashboard-ops-list .stat-card-kpi {
  height: 100%;
}
.dashboard-ops-jornada {
  position: relative;
}
.dashboard-ops-jornada .stat-card-kpi-body {
  display: flex;
  flex-direction: column;
  min-width: 0;
  padding-right: 5.5rem;
}
.dashboard-ops-jornada .dashboard-ops-actions {
  position: absolute;
  top: 1rem;
  right: 1rem;
  margin-top: 0;
  z-index: 1;
}
.dashboard-ops-actions {
  display: flex;
  flex-wrap: wrap;
  gap: .45rem;
  margin-top: .5rem;
}
.dashboard-ops-actions .btn-sm {
  padding: .35rem .65rem;
  font-size: .78rem;
  min-height: auto;
}
.chart-meta-compact { padding: 0 1rem .85rem; font-size: .82rem; }

@media (max-width: 1200px) {
  .dashboard-v2 .dashboard-hero-kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .dashboard-v2 .dashboard-charts-primary { grid-template-columns: 1fr; }
  .dashboard-ops-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .dashboard-v2 .dashboard-secondary-grid { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 768px) {
  .dashboard-v2 .dashboard-hero-kpis,
  .dashboard-v2 .dashboard-secondary-grid,
  .dashboard-v2 .dashboard-tables-grid { grid-template-columns: 1fr; }
  .dashboard-ops-list { grid-template-columns: 1fr; }
}

@media (max-width: 900px) {
  .scan-review-fields { grid-template-columns: 1fr 1fr; }
  .scan-field-span-2 { grid-column: span 2; }
  .scan-review-totals { grid-template-columns: 1fr; }
  .scan-review-add-line {
    grid-template-columns: 1fr 1fr;
  }
  .scan-review-add-line label:first-child { grid-column: 1 / -1; }
  .scan-review-add-action { grid-column: 1 / -1; justify-content: flex-start; }
}

@media (max-width: 640px) {
  .scan-review-fields { grid-template-columns: 1fr; }
  .scan-field-span-2 { grid-column: span 1; }
  .scan-lines-table col.col-desc { width: 8rem; }
}

.purchase-receipt-thumb {
  display: block;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  cursor: zoom-in;
  overflow: hidden;
  width: 52px;
  height: 52px;
}
.purchase-receipt-thumb img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.purchase-receipt-thumb-pdf {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.purchase-receipt-pdf-label {
  font-size: .72rem;
  font-weight: 700;
  letter-spacing: .04em;
  color: var(--accent-2);
}
.modal-receipt .modal-body {
  width: min(900px, calc(100vw - 2rem));
}
.receipt-view-wrap {
  display: flex;
  justify-content: center;
  align-items: center;
  max-height: calc(100vh - 8rem);
  overflow: auto;
  padding: .5rem 0;
}
.receipt-view-wrap img {
  display: block;
  max-width: 100%;
  max-height: calc(100vh - 9rem);
  object-fit: contain;
  border-radius: var(--radius-sm);
}
.receipt-view-wrap iframe {
  display: block;
  width: min(860px, 100%);
  height: min(70vh, 720px);
  border: 0;
  background: #fff;
  border-radius: var(--radius-sm);
}
.crm-calendar-legend .status-proposal { background: #f59e0b; }
.crm-calendar-legend .status-negotiation { background: #f97316; }

.crm-calendar-legend .legend-hint { opacity: .85; }
.legend-hint-mobile { display: none; }

.crm-calendar-mobile-bar {
  display: none;
}

.crm-calendar-body {
  min-height: 0;
}

@media (max-width: 900px) {
  .app-shell:has(.page-content-prospects #tab-calendar:not([hidden])) {
    height: 100dvh;
    max-height: 100dvh;
    overflow: hidden;
  }

  .app-shell:has(.page-content-prospects #tab-calendar:not([hidden])) .app-main {
    min-height: 0;
    overflow: hidden;
  }

  .page-content-prospects:has(#tab-calendar:not([hidden])) {
    overflow: hidden;
    min-height: 0;
  }

  .page-content-prospects:has(#tab-calendar:not([hidden])) #tab-calendar {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    gap: .65rem;
    padding-bottom: .65rem;
  }

  .crm-calendar-mobile-bar {
    display: flex;
    flex-direction: column;
    gap: .55rem;
    flex-shrink: 0;
  }

  .crm-cal-nav {
    display: grid;
    grid-template-columns: 2.5rem 1fr 2.5rem;
    align-items: center;
    gap: .35rem;
  }

  .crm-cal-nav-btn {
    width: 2.5rem;
    height: 2.5rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg-panel);
    color: var(--text);
    font-size: 1.35rem;
    line-height: 1;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  .crm-cal-title {
    text-align: center;
    font-size: 1rem;
    font-weight: 700;
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    padding: 0 .25rem;
  }

  .crm-cal-today-btn {
    width: 100%;
    min-height: 2.35rem;
  }

  .crm-cal-view-switch {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: .45rem;
    width: 100%;
  }

  .crm-cal-view-btn {
    width: 100%;
    min-height: 2.35rem;
    padding: .5rem .4rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg-panel);
    color: var(--text);
    font-weight: 600;
    font-size: .8rem;
    cursor: pointer;
    transition: border-color .15s, background .15s, color .15s;
  }

  .crm-cal-view-btn.is-active {
    background: var(--accent-soft-2);
    border-color: var(--accent);
    color: var(--accent-2);
  }

  .crm-calendar-body {
    flex: 0 0 auto;
    min-height: 0;
  }

  .crm-fullcalendar.is-mobile {
    margin-bottom: 0;
  }

  .crm-fullcalendar.is-mobile .fc-header-toolbar,
  .crm-fullcalendar.is-mobile .fc-footer-toolbar {
    display: none !important;
  }

  .crm-fullcalendar.is-mobile .fc {
    font-size: .88rem;
  }

  .crm-fullcalendar.is-mobile .fc-list {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    background: var(--bg-elevated);
  }

  .crm-fullcalendar.is-mobile .fc-list-day-cushion {
    padding: .6rem .85rem;
    font-size: .8rem;
    font-weight: 700;
    background: var(--bg-panel);
  }

  .crm-fullcalendar.is-mobile .fc-list-event {
    cursor: pointer;
    padding: .15rem 0;
  }

  .crm-fullcalendar.is-mobile .fc-list-event-title {
    font-size: .92rem;
    font-weight: 600;
    line-height: 1.3;
    white-space: normal;
  }

  .crm-fullcalendar.is-mobile .fc-list-event-time {
    font-size: .78rem;
    color: var(--muted);
  }

  .crm-fullcalendar.is-mobile .fc-list-event-dot {
    border-width: 7px;
  }

  .crm-fullcalendar.is-mobile.is-month-view,
  .crm-fullcalendar.is-mobile.is-week-view {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    background: var(--bg-elevated);
  }

  .crm-fullcalendar.is-mobile.is-month-view .fc-daygrid-day-frame {
    min-height: 3.5rem;
  }

  .crm-fullcalendar.is-mobile.is-month-view .fc-col-header-cell-cushion {
    font-size: .64rem;
    padding: .35rem .1rem;
    text-transform: lowercase;
  }

  .crm-fullcalendar.is-mobile.is-month-view .fc-daygrid-day-number {
    font-size: .72rem;
    padding: .2rem .35rem;
  }

  .crm-fullcalendar.is-mobile.is-month-view .fc-daygrid-event {
    font-size: .62rem;
    margin-top: 1px;
    border-radius: 3px;
  }

  .crm-fullcalendar.is-mobile.is-month-view .fc-daygrid-event .fc-event-title {
    padding: 1px 2px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    line-height: 1.15;
  }

  .crm-fullcalendar.is-mobile.is-month-view .fc-daygrid-more-link {
    font-size: .62rem;
    font-weight: 700;
  }

  .crm-fullcalendar.is-mobile.is-week-view .fc-col-header-cell-cushion {
    font-size: .7rem;
    padding: .35rem .15rem;
  }

  .crm-fullcalendar.is-mobile.is-week-view .fc-daygrid-day-number {
    font-size: .76rem;
  }

  .crm-fullcalendar.is-mobile.is-week-view .fc-daygrid-event .fc-event-title {
    font-size: .72rem;
    white-space: normal;
    line-height: 1.2;
  }

  .crm-fullcalendar.is-mobile .fc-daygrid-week-number,
  .crm-fullcalendar.is-mobile .fc-scrollgrid-shrink {
    display: none !important;
  }

  .crm-fullcalendar.is-mobile .fc-col-header-cell-cushion {
    font-size: .72rem;
    padding: .4rem .2rem;
    font-weight: 600;
  }

  .crm-fullcalendar.is-mobile .fc-daygrid-day-number {
    font-size: .78rem;
    padding: .3rem .45rem;
  }

  .crm-fullcalendar.is-mobile .fc-daygrid-event {
    font-size: .72rem;
    border-radius: 4px;
  }

  .crm-fullcalendar.is-mobile .fc-daygrid-event .fc-event-title {
    padding: 2px 4px;
    white-space: normal;
    line-height: 1.2;
  }

  .crm-calendar-legend {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: .45rem .65rem;
    font-size: .76rem;
    padding: .65rem .75rem;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 0;
    flex-shrink: 0;
  }

  .crm-calendar-legend .legend-hint-desktop {
    display: none;
  }

  .crm-calendar-legend .legend-hint-mobile {
    display: block;
    grid-column: 1 / -1;
    font-size: .72rem;
    line-height: 1.35;
    margin-top: .15rem;
  }
}

/* Panel lateral derecho móvil — contenido */
@media (max-width: 900px) {
  .page-header-end {
    display: flex;
    flex-direction: column;
    align-items: stretch;
  }
  .mobile-topbar-drawer-head {
    order: 0;
    flex-shrink: 0;
    width: 100%;
    margin-bottom: .35rem;
    padding-bottom: .85rem;
  }
  .mobile-topbar-drawer-head strong {
    font-size: 1.15rem;
  }
  .mobile-topbar-close {
    min-width: 2.75rem;
    width: 2.75rem;
    height: 2.75rem;
    font-size: 1.35rem;
  }
  .mobile-topbar-drawer-body {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
    flex: 1;
    min-height: 0;
    width: 100%;
  }
  .mobile-topbar-drawer-section {
    display: flex;
    flex-direction: column;
    gap: .65rem;
    width: 100%;
  }
  .mobile-topbar-drawer-section + .mobile-topbar-drawer-section {
    padding-top: 1.15rem;
    border-top: 1px solid var(--border);
  }
  .mobile-topbar-drawer-section-title {
    margin: 0;
    font-size: .78rem;
    font-weight: 700;
    letter-spacing: .06em;
    text-transform: uppercase;
    color: var(--muted);
  }
  .mobile-topbar-drawer-section .header-actions,
  .mobile-topbar-drawer-section .doc-header-actions {
    width: 100%;
    flex-direction: column;
    align-items: stretch;
    flex-wrap: nowrap;
    gap: .5rem;
  }
  .page-header-end .add-menu-dropdown,
  .page-header-end .quick-actions-dropdown,
  .page-header-end .period-filter,
  .page-header-end > .topbar-user,
  .page-header-end .header-actions,
  .page-header-end .doc-header-actions {
    order: 0;
    width: 100%;
    flex-shrink: 0;
  }
  .page-header-end .quick-actions-toggle-label {
    display: inline !important;
  }
  .page-header-end .topbar-user-name {
    display: inline !important;
  }
  .page-header-end .topbar-user-chevron {
    display: none;
  }
  body.mobile-topbar-open .page-header-end .topbar-user--drawer {
    display: flex;
    flex-direction: column;
    gap: .5rem;
  }
  body.mobile-topbar-open .page-header-end .topbar-user--drawer .topbar-user-toggle {
    display: flex;
    pointer-events: none;
    cursor: default;
    min-height: auto;
    height: auto;
    padding: 0 0 .15rem;
    border: 0;
    background: transparent;
    border-radius: 0;
    color: var(--text);
  }
  body.mobile-topbar-open .page-header-end .topbar-user--drawer .topbar-user-name {
    color: var(--text);
    font-size: 1rem;
  }
  body.mobile-topbar-open .page-header-end .topbar-user--drawer .topbar-user-menu {
    display: flex !important;
    flex-direction: column;
    gap: .65rem;
  }
  body.mobile-topbar-open .page-header-end .topbar-user--drawer .topbar-user-item,
  body.mobile-topbar-open .page-header-end .topbar-user--drawer .topbar-user-item-btn {
    min-height: 3rem;
    height: auto;
    padding: .75rem 1rem;
    border: 1px solid var(--border);
    background: var(--bg-panel);
    color: var(--text);
    font-size: 1rem;
    font-weight: 600;
    border-radius: 10px;
    box-sizing: border-box;
  }
  body.mobile-topbar-open .page-header-end .topbar-user--drawer .topbar-user-separator {
    display: none;
  }
  body.mobile-topbar-open .page-header-end .topbar-user--drawer .theme-picker {
    padding: 0;
    gap: .5rem;
  }
  body.mobile-topbar-open .page-header-end .topbar-user--drawer .theme-picker-group {
    padding: .65rem .75rem;
    gap: .45rem;
    border-radius: 8px;
    background: var(--bg-panel);
    border: 1px solid var(--border);
  }
  .page-header-end .add-menu-dropdown .dropdown-menu,
  .page-header-end .quick-actions-dropdown .dropdown-menu,
  .page-header-end .doc-action-dropdown .dropdown-menu {
    position: static !important;
    inset: auto !important;
    transform: none !important;
    display: none;
    width: 100%;
    min-width: 0;
    max-width: none;
    margin: 0;
    box-sizing: border-box;
  }
  .page-header-end .doc-action-dropdown .dropdown-menu {
    padding: 0;
    box-shadow: none;
    border: 0;
    border-radius: 0;
    background: transparent;
  }
  .page-header-end .add-menu-dropdown .dropdown-menu,
  .page-header-end .quick-actions-dropdown .dropdown-menu {
    padding: .85rem;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--bg-panel);
    margin-top: .4rem;
    box-shadow: none;
  }
  .page-header-end .add-menu-dropdown .dropdown-menu.show,
  .page-header-end .quick-actions-dropdown .dropdown-menu.show {
    display: block;
  }
  .page-header-end .doc-action-dropdown .dropdown-menu.show {
    display: flex;
    flex-direction: column;
    gap: .5rem;
  }
  body.mobile-topbar-open .page-header-end .doc-action-dropdown .dropdown-toggle {
    pointer-events: none;
    cursor: default;
    min-height: auto;
    height: auto;
    padding: .15rem 0 0;
    border: 0;
    background: transparent;
    border-radius: 0;
    color: var(--muted);
    font-size: .72rem;
    font-weight: 700;
    letter-spacing: .06em;
    text-transform: uppercase;
    justify-content: flex-start;
  }
  body.mobile-topbar-open .page-header-end .doc-action-dropdown .dropdown-toggle svg,
  body.mobile-topbar-open .page-header-end .doc-action-dropdown .dropdown-toggle .doc-dropdown-toggle-icon {
    display: none;
  }
  body.mobile-topbar-open .page-header-end .doc-action-dropdown .dropdown-menu {
    display: flex !important;
    flex-direction: column;
    gap: .5rem;
  }
  body.mobile-topbar-open .page-header-end .doc-action-dropdown {
    gap: .35rem;
  }
  .page-header-end .doc-action-dropdown .dropdown-menu > li {
    width: 100%;
    margin: 0;
    padding: 0;
    list-style: none;
  }
  .page-header-end .doc-action-dropdown .dropdown-item {
    display: inline-flex;
    align-items: center;
    gap: .5rem;
    width: 100%;
    min-height: 3rem;
    height: auto;
    padding: .75rem 1rem;
    box-sizing: border-box;
    font-size: 1rem;
    font-weight: 600;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: var(--bg-panel);
    color: var(--text);
    white-space: nowrap;
  }
  .page-header-end .doc-action-dropdown .dropdown-item:hover,
  .page-header-end .doc-action-dropdown .dropdown-item:focus {
    background: var(--bg-panel);
    color: var(--text);
  }
  .page-header-end .quick-actions-megamenu,
  .page-header-end .add-menu-megamenu {
    min-width: 0 !important;
    width: 100% !important;
    max-width: none !important;
    max-height: min(52vh, 420px);
    overflow-y: auto;
    margin-top: .4rem !important;
  }
  .page-header-end .period-filter {
    gap: .5rem;
    font-size: .85rem;
    margin: 0;
  }
  .page-header-end .period-filter label {
    margin: 0;
    gap: .35rem;
  }
  .page-header-end .period-filter select {
    height: 3rem;
    min-height: 3rem;
    width: 100%;
    padding: 0 1rem;
    box-sizing: border-box;
    font-size: 1rem;
  }
  .page-header-end .topbar-user-item,
  .page-header-end .topbar-user-item-btn {
    display: inline-flex;
    align-items: center;
    gap: .5rem;
    width: 100%;
    min-height: 3rem;
    height: auto;
    padding: .75rem 1rem;
    box-sizing: border-box;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: var(--bg-panel);
    color: var(--text);
    font-size: 1rem;
    font-weight: 600;
  }
  .page-header-end .topbar-user-item svg {
    width: 1.15rem;
    height: 1.15rem;
  }
  .page-header-end .quick-action-item {
    padding: .85rem 1rem;
    min-height: 3.25rem;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: var(--bg-panel);
  }
  .page-header-end .quick-action-icon {
    width: 2.5rem;
    height: 2.5rem;
  }
  .page-header-end .quick-action-text strong {
    font-size: 1rem;
  }
  .page-header-end .quick-action-text small {
    font-size: .85rem;
  }
  .page-header-end .add-menu-megamenu .dropdown-item,
  .page-header-end .quick-actions-megamenu .dropdown-item {
    min-height: 3rem;
    padding: .75rem 1rem;
    font-size: 1rem;
    border-radius: 10px;
  }
  .page-header-end .topbar-user-separator {
    display: none;
  }
  .page-header-end .theme-picker {
    padding: 0;
    gap: .5rem;
  }
  .page-header-end .theme-picker-group {
    padding: .65rem .75rem;
    gap: .45rem;
    border-radius: 8px;
  }
  .page-header-end .theme-picker-label {
    padding: 0;
    margin: 0;
  }
  .page-header-end:empty,
  .mobile-topbar-drawer-section:empty {
    display: none;
  }
}

/* Móvil — formularios a ancho completo y modales pantalla completa */
@media (max-width: 900px) {
  .form-grid,
  .form-grid-3,
  .form-grid-4,
  .client-info-grid,
  .doc-meta.form-grid {
    grid-template-columns: 1fr;
  }
  .form-grid .span-2,
  .form-grid-3 .span-2,
  .form-grid-4 .span-2 {
    grid-column: span 1;
  }

  .page-content label:not(.checkbox),
  .document-editor > label,
  .modal-body label:not(.checkbox),
  .modal-body .form-section label:not(.checkbox) {
    width: 100%;
    min-width: 0;
  }

  .page-content input:not([type="checkbox"]):not([type="radio"]):not([type="file"]):not([type="hidden"]),
  .page-content select,
  .page-content textarea,
  .modal-body input:not([type="checkbox"]):not([type="radio"]):not([type="file"]):not([type="hidden"]),
  .modal-body select,
  .modal-body textarea {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    box-sizing: border-box;
  }

  .toolbar,
  .toolbar:not(.toolbar-datatable) {
    flex-direction: column;
    flex-wrap: nowrap;
    align-items: stretch;
    gap: .55rem;
    width: 100%;
  }

  .toolbar label,
  .toolbar:not(.toolbar-datatable) label {
    width: 100%;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: .35rem;
  }

  .toolbar input:not([type="checkbox"]):not([type="radio"]),
  .toolbar select,
  .toolbar:not(.toolbar-datatable) input:not([type="checkbox"]):not([type="radio"]),
  .toolbar:not(.toolbar-datatable) select {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    box-sizing: border-box;
  }

  .toolbar .btn,
  .toolbar:not(.toolbar-datatable) .btn,
  .toolbar > a.btn {
    width: 100%;
    max-width: 100%;
    justify-content: center;
    box-sizing: border-box;
  }

  .panel-toolbar {
    flex-direction: column;
    align-items: stretch;
    gap: .55rem;
    width: 100%;
  }

  .panel-toolbar .btn,
  .panel-toolbar > .btn,
  .panel-toolbar > a.btn,
  .panel-toolbar .clock-in-panel,
  .panel-toolbar .time-user-select,
  .panel-toolbar select,
  .panel-toolbar input:not([type="checkbox"]):not([type="radio"]) {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    box-sizing: border-box;
  }

  .online-toolbar {
    align-items: stretch;
  }

  .datatable-shell > .toolbar,
  .datatable-shell > .toolbar-datatable,
  .datatable-shell > .datatable-view-switch {
    width: 100%;
    max-width: 100%;
  }

  .datatable-shell.has-card-view .datatable-view-switch {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: .5rem;
    margin-bottom: .65rem;
  }

  .datatable-view-btn {
    min-height: 2.75rem;
    font-size: .92rem;
  }

  .toolbar-datatable {
    flex-direction: column;
    flex-wrap: nowrap;
    align-items: stretch;
    gap: .55rem;
  }

  .toolbar-datatable > input[type="search"],
  .toolbar-datatable > select,
  .toolbar-datatable > input:not([type="checkbox"]):not([type="radio"]),
  .toolbar-datatable > .toolbar-filter,
  .toolbar-filter.toolbar-filter-search {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    flex: 1 1 auto;
    box-sizing: border-box;
  }

  .toolbar-datatable .select2-container {
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    flex: 1 1 100%;
  }

  .toolbar-datatable > .toolbar-filter {
    flex: 1 1 100%;
  }

  .toolbar-datatable > .btn,
  .toolbar-datatable > button.btn,
  .toolbar-datatable > a.btn {
    width: 100%;
    max-width: 100%;
    justify-content: center;
    box-sizing: border-box;
  }

  .lines-toolbar {
    flex-direction: column;
    align-items: stretch;
    gap: .5rem;
  }
  .lines-toolbar .btn {
    width: 100%;
  }
  .lines-editor {
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  .lines-table {
    min-width: 640px;
  }

  dialog[open].modal:not(.app-loading-modal),
  dialog[open].confirm-delete-modal,
  dialog[open].app-message-modal,
  dialog[open].app-confirm-modal,
  dialog[open].app-form-modal,
  dialog[open].form-modal-open,
  dialog[open].modal-user,
  dialog[open].modal-client,
  dialog[open].modal-product,
  dialog[open].modal-import,
  dialog[open].modal-receipt,
  dialog[open].scan-review-modal {
    position: fixed;
    inset: 0;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    transform: none !important;
    width: 100% !important;
    max-width: 100% !important;
    height: 100dvh !important;
    max-height: 100dvh !important;
    min-height: 100dvh !important;
    margin: 0 !important;
    border-radius: 0 !important;
    border: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }

  dialog[open].form-modal-open > form.modal-body,
  dialog[open].form-modal-open > .modal-body,
  dialog[open].modal-user > form.modal-body,
  dialog[open].modal-client > form.modal-body,
  dialog[open].modal-product > form.modal-body,
  dialog[open].modal-product > .modal-body,
  dialog[open].modal-import > .modal-body,
  dialog[open].modal-receipt > .modal-body,
  dialog[open].scan-review-modal > .modal-body,
  dialog[open].modal:not(.app-loading-modal):not(.form-modal-open) > .modal-body,
  dialog[open].app-confirm-modal > .modal-body,
  dialog[open].app-form-modal > form.modal-body,
  dialog[open].app-message-modal > .modal-body,
  dialog[open].confirm-delete-modal > .modal-body {
    flex: 1 1 auto;
    min-height: 0;
    overflow-x: hidden;
    overflow-y: auto;
    max-height: none;
    width: 100%;
    box-sizing: border-box;
    padding: 1rem;
    padding-bottom: calc(1rem + env(safe-area-inset-bottom, 0px));
    -webkit-overflow-scrolling: touch;
  }

  dialog[open].form-modal-open .modal-header,
  dialog[open].modal-user .modal-header,
  dialog[open].modal-client .modal-header,
  dialog[open].modal-product .modal-header,
  dialog[open].modal-import .modal-header,
  dialog[open].modal-receipt .modal-header,
  dialog[open].scan-review-modal .modal-header,
  dialog[open].modal:not(.app-loading-modal) .modal-header {
    flex-shrink: 0;
  }

  dialog[open].form-modal-open .modal-actions,
  dialog[open].form-modal-open .modal-footer,
  dialog[open].modal-user .modal-actions,
  dialog[open].modal-client .modal-actions,
  dialog[open].modal-client .modal-footer,
  dialog[open].modal-product .modal-actions,
  dialog[open].modal-import .modal-actions,
  dialog[open].modal-receipt .modal-actions,
  dialog[open].scan-review-modal .modal-actions,
  dialog[open].app-confirm-modal .modal-actions,
  dialog[open].app-form-modal .modal-actions,
  dialog[open].app-message-modal .modal-actions,
  dialog[open].confirm-delete-modal .modal-actions {
    flex-shrink: 0;
    padding-bottom: calc(1rem + env(safe-area-inset-bottom, 0px));
  }

  #global-search-modal:not([hidden]) {
    padding: 0;
    align-items: stretch;
    justify-content: stretch;
  }
  #global-search-modal:not([hidden]) .modal-dialog {
    width: 100%;
    max-width: 100%;
    height: 100dvh;
    max-height: 100dvh;
    border-radius: 0;
    margin: 0;
  }
  #global-search-modal:not([hidden]) .modal-dialog .modal-header {
    padding-top: calc(1rem + env(safe-area-inset-top, 0px));
  }
  #global-search-modal:not([hidden]) .modal-dialog .modal-body {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
  }
  .global-search-results {
    max-height: none;
    flex: 1;
  }
}

/* PWA — banner de instalación */
.pwa-install-banner {
  position: fixed;
  left: .75rem;
  right: .75rem;
  bottom: calc(.75rem + env(safe-area-inset-bottom, 0px));
  z-index: 120;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .75rem;
  padding: .75rem .85rem;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, .28);
}
.pwa-install-banner-text {
  display: flex;
  flex-direction: column;
  gap: .15rem;
  min-width: 0;
}
.pwa-install-banner-text strong {
  font-size: .9rem;
}
.pwa-install-banner-text .muted {
  font-size: .78rem;
  line-height: 1.3;
}
.pwa-install-banner-actions {
  display: flex;
  align-items: center;
  gap: .35rem;
  flex-shrink: 0;
}
@media (min-width: 640px) {
  .pwa-install-banner {
    left: auto;
    max-width: 420px;
    right: 1rem;
  }
}

/* TPV — punto de venta */
.tpv-shell .tpv-main {
  min-height: 100vh;
  overflow: hidden;
}
.tpv-shell .page-content.tpv-page {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: .85rem;
  padding-bottom: .85rem;
}
.tpv-header {
  flex-shrink: 0;
}
.tpv-shell .tpv-session-bar {
  display: none !important;
}
.tpv-session-chip {
  display: none;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  gap: .2rem;
  min-width: 36px;
  height: 36px;
  padding: 0 .35rem;
  flex-shrink: 0;
  border-radius: 8px;
  border: 1px solid color-mix(in srgb, #0d9488 35%, var(--border));
  background: color-mix(in srgb, #14b8a6 14%, var(--surface));
  color: #0f766e;
  box-sizing: border-box;
  pointer-events: none;
  user-select: none;
}
.tpv-session-chip.is-active {
  border-color: color-mix(in srgb, #0d9488 45%, var(--border));
  background: color-mix(in srgb, #14b8a6 18%, var(--surface));
  color: #115e59;
}
.tpv-session-chip-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}
.tpv-session-chip-icon svg {
  width: 16px;
  height: 16px;
}
.tpv-session-chip-num {
  display: block;
  line-height: 1;
  font-size: .68rem;
  font-weight: 800;
  letter-spacing: -.02em;
  white-space: nowrap;
}
.tpv-session-chip:not(.is-active) {
  border-color: color-mix(in srgb, #d97706 35%, var(--border));
  background: color-mix(in srgb, #f59e0b 14%, var(--surface));
  color: #b45309;
}
.tpv-shell .tpv-session-chip {
  display: inline-flex;
}
@media (min-width: 901px) {
  .tpv-shell .tpv-header .tpv-session-chip {
    margin-left: auto;
    margin-right: .35rem;
  }
}
.tpv-header-actions {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
}
.tpv-header-actions .btn[hidden],
.tpv-header-actions .btn.is-hidden {
  display: none !important;
}
.tpv-workspace {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(360px, 420px);
  gap: 1rem;
  align-items: stretch;
}
.tpv-catalog-area {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}
.tpv-search-row {
  display: none;
}
.tpv-drawer-search {
  flex-shrink: 0;
  padding: 1rem 1rem 0;
  width: 100%;
  box-sizing: border-box;
}
.tpv-drawer-search .input,
.tpv-drawer-search input {
  width: 100%;
  box-sizing: border-box;
  display: block;
}
.tpv-drawer-search .input-lg {
  font-size: .95rem;
  padding: .7rem .9rem;
}
.tpv-products-toggle {
  display: none;
  flex-shrink: 0;
  white-space: nowrap;
}
.tpv-cart-head-actions {
  display: flex;
  align-items: center;
  gap: .35rem;
  flex-shrink: 0;
}
.tpv-cart-head-btn {
  min-height: 2rem;
  height: 2rem;
  padding: 0 .65rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: .78rem;
  line-height: 1;
  box-sizing: border-box;
}
.tpv-catalog-drawer-head {
  display: none;
  align-items: center;
  justify-content: space-between;
  gap: .75rem;
  padding: .85rem 1rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg-elevated, var(--surface));
  flex-shrink: 0;
}
.tpv-catalog-drawer-head h2 {
  margin: 0;
  font-size: 1rem;
}
.tpv-catalog-backdrop {
  display: none;
}
.tpv-catalog {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  padding: 0;
}
.tpv-catalog .tpv-toolbar {
  flex-shrink: 0;
  padding: .75rem 1rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: .75rem;
  background: var(--bg-elevated, var(--surface));
}
.tpv-search-wrap {
  width: 100%;
}
.tpv-search-wrap input {
  width: 100%;
  box-sizing: border-box;
  display: block;
}
.tpv-search-wrap .input-lg {
  font-size: .95rem;
  padding: .7rem .9rem;
}
.tpv-categories {
  display: flex;
  flex-wrap: wrap;
  gap: .45rem;
  width: 100%;
}
.tpv-cat-btn {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  border-radius: 999px;
  padding: .4rem .85rem;
  font-size: .82rem;
  font-weight: 500;
  cursor: pointer;
  transition: border-color .15s, background .15s, color .15s;
}
.tpv-cat-btn:hover { border-color: color-mix(in srgb, var(--accent) 40%, var(--border)); }
.tpv-cat-btn.is-active {
  border-color: var(--accent);
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 12%, var(--surface));
  font-weight: 600;
}
.tpv-products-grid {
  flex: 1;
  min-height: 0;
  overflow: auto;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  grid-auto-rows: auto;
  align-items: start;
  gap: .55rem;
  padding: .55rem .65rem .75rem;
  align-content: start;
}
.tpv-product-card {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  width: 100%;
  min-width: 0;
  text-align: left;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0;
  overflow: hidden;
  background: var(--bg-elevated, var(--surface));
  color: var(--text);
  cursor: pointer;
  transition: border-color .15s ease, background .15s ease, transform .15s ease, box-shadow .2s ease;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.tpv-product-card:active {
  transform: scale(0.97);
}
.tpv-product-card.is-in-cart {
  border-color: color-mix(in srgb, var(--accent) 58%, var(--border));
  background: color-mix(in srgb, var(--accent) 9%, var(--surface));
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--accent) 22%, transparent);
}
.tpv-product-card.is-in-cart:hover {
  border-color: color-mix(in srgb, var(--accent) 68%, var(--border));
}
.tpv-product-card.is-just-added {
  animation: tpv-product-added-flash .58s cubic-bezier(.22, 1, .36, 1);
}
@keyframes tpv-product-added-flash {
  0% {
    transform: scale(0.94);
    box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent) 45%, transparent);
  }
  45% {
    transform: scale(1.03);
    box-shadow: 0 0 0 5px color-mix(in srgb, var(--accent) 28%, transparent);
  }
  100% {
    transform: scale(1);
    box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--accent) 22%, transparent);
  }
}
.tpv-product-cart-qty {
  position: absolute;
  top: .35rem;
  right: .35rem;
  z-index: 2;
  min-width: 1.4rem;
  height: 1.4rem;
  padding: 0 .35rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: .72rem;
  font-weight: 800;
  line-height: 1;
  box-shadow: 0 2px 8px rgba(0, 0, 0, .22);
  pointer-events: none;
}
.tpv-product-card:hover {
  border-color: color-mix(in srgb, var(--accent) 45%, var(--border));
}
.tpv-product-card:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.tpv-product-media {
  position: relative;
  width: 100%;
  flex: none;
  height: 0;
  padding-bottom: 100%;
  overflow: hidden;
  background: color-mix(in srgb, var(--accent) 10%, var(--surface));
}
.tpv-product-media img.tpv-product-thumb,
.tpv-product-media .tpv-product-thumb-fallback {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  max-width: none;
  border-radius: 0;
  object-fit: cover;
  background: transparent;
}
.tpv-product-media img.tpv-product-thumb {
  display: block;
}
.tpv-product-thumb-fallback {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
  border-radius: 0;
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: .02em;
}
.tpv-product-body {
  display: block;
  width: 100%;
  flex-shrink: 0;
  position: relative;
  z-index: 1;
  min-height: 2.85rem;
  padding: .45rem .5rem .55rem;
  box-sizing: border-box;
  background: var(--bg-elevated, var(--surface));
}
.tpv-product-name {
  margin: 0 0 .25rem;
  font-size: .76rem;
  line-height: 1.25;
  font-weight: 600;
  color: var(--text);
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
@media (min-width: 901px) {
  .tpv-products-grid {
    grid-template-columns: repeat(6, minmax(0, 1fr));
    align-items: stretch;
    gap: .55rem;
    padding: .65rem .75rem;
  }
  .tpv-product-card {
    height: 100%;
  }
  .tpv-product-body {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    min-height: 3.35rem;
  }
  .tpv-product-name {
    min-height: calc(1.25em * 2);
  }
  .tpv-product-foot {
    margin-top: auto;
    min-height: 1.35rem;
  }
}

@media (min-width: 1500px) {
  .tpv-products-grid {
    grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  }
}
.tpv-product-meta {
  font-size: .68rem;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tpv-product-foot {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .3rem .45rem;
}
.tpv-product-price {
  display: inline-block;
  font-size: .92rem;
  font-weight: 700;
  color: var(--accent);
  line-height: 1.2;
}
.tpv-product-badge {
  font-size: .72rem;
  font-weight: 600;
  padding: .15rem .45rem;
  border-radius: 999px;
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  color: var(--accent);
}
.tpv-stock {
  font-size: .72rem;
  color: var(--text-dim);
}
.tpv-stock.is-low { color: var(--danger, #ef4444); font-weight: 600; }
.tpv-empty-grid {
  flex: 1 1 100%;
  width: 100%;
  padding: 2rem;
  text-align: center;
}

.tpv-cart {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
  padding: 0;
  border-radius: 16px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, .08);
}
.tpv-cart-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: .75rem;
  padding: 1rem 1rem .75rem;
  border-bottom: 1px solid var(--border);
}
.tpv-cart-head-main {
  flex: 1;
  min-width: 0;
}
.tpv-cart-head h2 {
  margin: 0;
  font-size: 1.15rem;
  display: flex;
  align-items: center;
  gap: .5rem;
  flex-wrap: wrap;
}
.tpv-client-toggle { display: none; flex-shrink: 0; }
.tpv-cart-body {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.tpv-client-selected {
  margin: .25rem 0 0;
  font-size: .82rem;
  color: var(--text-dim);
}
.tpv-cart-count {
  background: var(--accent);
  color: #fff;
  border-radius: 999px;
  min-width: 2rem;
  height: 2rem;
  padding: 0 .45rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: .85rem;
  font-weight: 700;
  flex-shrink: 0;
  transition: transform .2s ease;
}
.tpv-cart-count.is-pulse {
  animation: tpv-cart-count-pulse .48s cubic-bezier(.22, 1, .36, 1);
}
@keyframes tpv-cart-count-pulse {
  0%, 100% { transform: scale(1); }
  35% { transform: scale(1.22); }
  65% { transform: scale(0.94); }
}
.tpv-client {
  padding: .85rem 1rem;
  border-bottom: 1px solid var(--border);
}
.tpv-client label {
  display: block;
  margin-bottom: .35rem;
  font-size: .82rem;
  font-weight: 600;
  color: var(--text-muted);
}
.tpv-client input[type="search"],
.tpv-client #tpv-client-search {
  width: 100%;
  box-sizing: border-box;
  display: block;
}
.tpv-client-results {
  margin-top: .45rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  max-height: 180px;
  overflow: auto;
  background: var(--bg-elevated, var(--surface));
}
.tpv-client-option {
  display: block;
  width: 100%;
  text-align: left;
  padding: .65rem .85rem;
  border: 0;
  background: transparent;
  cursor: pointer;
  font-size: .88rem;
}
.tpv-client-option:hover { background: color-mix(in srgb, var(--accent) 8%, var(--surface)); }
.tpv-cart-lines {
  flex: 1;
  min-height: 120px;
  overflow: auto;
  padding: .75rem 1rem;
}
.tpv-empty {
  padding: 1.5rem .5rem;
  text-align: center;
  font-size: .9rem;
}
.tpv-cart-line {
  padding: .85rem 0;
  border-bottom: 1px solid var(--border);
}
.tpv-cart-line:last-child { border-bottom: 0; }
.tpv-cart-line-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: .5rem;
}
.tpv-cart-line-title {
  font-size: .92rem;
  line-height: 1.35;
}
.tpv-cart-line-meta {
  margin-top: .2rem;
  font-size: .82rem;
  color: var(--text-dim);
}
.tpv-cart-line-actions {
  display: flex;
  align-items: center;
  gap: .5rem;
  margin-top: .55rem;
}
.tpv-qty-btn {
  width: 2rem;
  height: 2rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.tpv-qty-btn:hover { border-color: var(--accent); color: var(--accent); }
.tpv-qty {
  min-width: 1.75rem;
  text-align: center;
  font-weight: 700;
  font-size: .95rem;
}
.tpv-line-total {
  margin-left: auto;
  font-size: 1rem;
  color: var(--text);
}
.tpv-checkout-block {
  flex-shrink: 0;
  border-top: 1px solid var(--border);
  background: color-mix(in srgb, var(--accent) 4%, var(--surface));
}
.tpv-totals {
  padding: .85rem 1rem .65rem;
  display: flex;
  flex-direction: column;
  gap: .4rem;
}
.tpv-total-row {
  display: flex;
  justify-content: space-between;
  font-size: .88rem;
  color: var(--text-muted);
}
.tpv-total-main {
  font-size: 1.2rem;
  color: var(--text);
  margin-top: .25rem;
  padding-top: .5rem;
  border-top: 1px dashed var(--border);
}
.tpv-total-main strong { color: var(--accent); font-size: 1.35rem; }
.tpv-pay-methods {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: .5rem;
  padding: 0 1rem .75rem;
}
.tpv-pay-btn {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text-muted);
  padding: .65rem .5rem;
  font-size: .82rem;
  font-weight: 600;
  cursor: pointer;
  transition: border-color .15s, color .15s, background .15s;
}
.tpv-pay-btn:hover { border-color: color-mix(in srgb, var(--accent) 35%, var(--border)); }
.tpv-pay-btn.is-active {
  border-color: var(--accent);
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 10%, var(--surface));
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--accent) 25%, transparent);
}
.tpv-cash-panel {
  padding: 0 1rem .85rem;
  display: flex;
  flex-direction: column;
  gap: .4rem;
}
.tpv-cash-panel label {
  font-size: .82rem;
  font-weight: 600;
  color: var(--text-muted);
}
.tpv-change {
  margin: 0;
  font-size: .92rem;
}
.tpv-change strong { color: var(--accent); font-size: 1.05rem; }
.tpv-checkout-btn {
  margin: 0 1rem 1rem;
  width: calc(100% - 2rem);
  min-height: 3rem;
  font-size: 1rem;
  font-weight: 700;
}

.tpv-recent {
  flex-shrink: 0;
  overflow: hidden;
}
.tpv-recent-summary {
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  padding: .85rem 1rem;
}
.tpv-recent-summary::-webkit-details-marker { display: none; }
.tpv-recent-summary h2 { margin: 0; font-size: 1rem; }
.tpv-recent-body {
  max-height: 180px;
  overflow: auto;
  padding-top: 0;
}

.tpv-modal {
  border: none;
  border-radius: 16px;
  padding: 0;
  width: min(520px, 92vw);
  max-height: 85vh;
  background: transparent;
  box-shadow: none;
  margin: 0;
  overflow: visible;
}
dialog[open].tpv-modal {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 10002;
  max-height: 90vh;
  overflow: visible;
}
.tpv-modal-wide {
  width: min(560px, 92vw);
}
.tpv-modal-form .tpv-modal-panel {
  min-width: min(480px, 92vw);
}
.tpv-modal::backdrop {
  background: rgba(8, 12, 20, .55);
  backdrop-filter: blur(4px);
}
.tpv-modal-panel {
  display: flex;
  flex-direction: column;
  max-height: 85vh;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--bg-elevated, var(--surface));
  box-shadow: 0 24px 64px rgba(0, 0, 0, .22);
  overflow: hidden;
}
.tpv-modal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.15rem 1.25rem;
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--accent) 4%, var(--bg-elevated, var(--surface)));
}
.tpv-modal-head .btn-ghost {
  flex-shrink: 0;
  min-width: 2.25rem;
  min-height: 2.25rem;
  padding: 0;
  font-size: 1.35rem;
  line-height: 1;
  border-radius: 8px;
}
.tpv-modal-kicker {
  margin: 0 0 .25rem;
  font-size: .75rem;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--accent);
}
.tpv-modal-head h2 {
  margin: 0;
  font-size: 1.25rem;
  line-height: 1.25;
}
.tpv-modal-body {
  padding: 1.25rem 1.25rem 1rem;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: .65rem;
}
.tpv-modal-body label {
  display: block;
  margin: 0 0 .4rem;
  font-size: .88rem;
  font-weight: 600;
  color: var(--text);
}
.tpv-modal-body .input,
.tpv-modal-body textarea {
  width: 100%;
  margin: 0;
}
.tpv-modal-body .input-lg {
  font-size: 1.05rem;
  padding: .75rem .9rem;
}
.tpv-modal-body textarea {
  min-height: 5.5rem;
  resize: vertical;
  line-height: 1.45;
}
.tpv-modal-hint {
  margin: .35rem 0 0;
  font-size: .82rem;
  color: var(--text-dim);
  line-height: 1.45;
}
.tpv-modal-foot {
  padding: 1rem 1.25rem 1.15rem;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: .65rem;
  background: color-mix(in srgb, var(--accent) 3%, var(--bg-elevated, var(--surface)));
}
.tpv-modal-foot .btn {
  min-height: 2.5rem;
  padding-left: 1.15rem;
  padding-right: 1.15rem;
}
.tpv-modal-foot .btn-primary {
  min-width: 9rem;
  font-weight: 700;
}
.tpv-close-summary {
  padding: .85rem 1rem;
  margin-bottom: .5rem;
  border-radius: 10px;
  background: color-mix(in srgb, var(--accent) 6%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--accent) 18%, var(--border));
}
.tpv-close-summary p { margin: 0 0 .35rem; }
.tpv-close-summary p:last-child { margin-bottom: 0; }
.tpv-success-body {
  text-align: center;
  padding: 1.5rem 1.25rem;
}
.tpv-variant-btn {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: .15rem .75rem;
  width: 100%;
  padding: 1rem 1.1rem;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  cursor: pointer;
  text-align: left;
  transition: border-color .15s, background .15s, transform .15s;
}
.tpv-variant-btn:hover {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 6%, var(--surface));
  transform: translateY(-1px);
}
.tpv-variant-btn.is-selected {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 14%, var(--surface));
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--accent) 25%, transparent);
}
.tpv-variant-name {
  grid-column: 1;
  font-size: .98rem;
  font-weight: 600;
  color: var(--text);
}
.tpv-variant-price {
  grid-column: 2;
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--accent);
  white-space: nowrap;
}
.tpv-variant-detail {
  grid-column: 1 / -1;
  font-size: .82rem;
  color: var(--text-dim);
}
.tpv-success-total {
  font-size: 1.75rem;
  font-weight: 800;
  color: var(--accent);
  margin: .5rem 0;
}

.tpv-checkout-hint {
  font-size: .78rem;
  margin: 0 0 .35rem;
  text-align: center;
}

.tpv-checkout-total-box {
  text-align: center;
  padding: 1rem;
  border-radius: .75rem;
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  border: 1px solid color-mix(in srgb, var(--accent) 35%, transparent);
  margin-bottom: .75rem;
}

.tpv-checkout-total-label {
  display: block;
  font-size: .72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--text-dim);
}

.tpv-checkout-total-value {
  display: block;
  margin-top: .25rem;
  font-size: 2rem;
  font-weight: 800;
  color: var(--accent);
}

.tpv-checkout-tendered {
  text-align: center;
  font-size: 1.35rem;
  font-weight: 700;
}

.tpv-tender-quick {
  display: flex;
  flex-wrap: wrap;
  gap: .4rem;
  margin: .65rem 0;
}

.tpv-checkout-change-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .75rem;
  padding: .65rem .85rem;
  border-radius: .55rem;
  background: var(--surface-2, rgba(0,0,0,.15));
  border: 1px solid var(--border);
  font-size: .875rem;
  margin: 0;
}

.tpv-checkout-change-row strong {
  font-size: 1.15rem;
  color: #fbbf24;
}

.tpv-checkout-change-row strong.is-insufficient {
  color: #f87171;
}

.tpv-checkout-field-hint {
  font-size: .75rem;
  text-align: center;
  color: var(--text-dim);
  margin: .35rem 0 0;
}

.tpv-checkout-field-hint.is-ok { color: #6ee7b7; }
.tpv-checkout-field-hint.is-warn { color: #fca5a5; }

.tpv-close-summary { margin-bottom: 1rem; }

.tpv-cart-toast {
  position: fixed;
  top: calc(env(safe-area-inset-top, 0px) + .55rem);
  left: 50%;
  z-index: 10050;
  transform: translateX(-50%) translateY(-4px);
  max-width: calc(100vw - 1.25rem);
  padding: .38rem .75rem;
  border-radius: 999px;
  background: color-mix(in srgb, var(--accent) 90%, #000);
  color: #fff;
  font-size: .78rem;
  font-weight: 700;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  box-shadow: 0 6px 18px rgba(0, 0, 0, .22);
  opacity: 0;
  pointer-events: none;
  user-select: none;
  transition: opacity .1s ease, transform .1s ease;
}
.tpv-cart-toast.is-visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.tpv-shell .app-toast-container,
body.tpv-products-open .app-toast-container {
  top: calc(env(safe-area-inset-top, 0px) + .65rem);
  bottom: auto;
  right: .65rem;
  left: auto;
  width: min(360px, calc(100vw - 1.3rem));
}

@media (max-width: 900px) {
  .tpv-shell .app-toast-container,
  body.tpv-products-open .app-toast-container {
    left: .65rem;
    right: .65rem;
    width: auto;
  }
}

@media (max-width: 1100px) and (min-width: 901px) {
  .tpv-workspace {
    grid-template-columns: minmax(0, 1fr) minmax(300px, 340px);
    grid-template-rows: 1fr;
  }
}

@media (max-width: 900px) {
  /* TPV a pantalla completa: altura = viewport real (barra URL / safe-area) */
  html:has(.tpv-shell),
  html:has(.tpv-shell) body {
    height: 100%;
    height: 100dvh;
    max-height: 100dvh;
    overflow: hidden;
    overscroll-behavior: none;
    touch-action: manipulation;
  }
  html:has(.tpv-shell) body {
    height: var(--tpv-app-height, 100dvh);
    max-height: var(--tpv-app-height, 100dvh);
  }
  /* Sin position:fixed en el shell: si no, el backdrop (z-index 90) tapa el menú. */
  .tpv-shell.app-shell {
    width: 100%;
    height: var(--tpv-app-height, 100dvh);
    max-height: var(--tpv-app-height, 100dvh);
    min-height: 0;
    overflow: hidden;
    display: grid;
    grid-template-columns: 1fr;
  }
  .tpv-shell.is-mobile-nav-open .app-sidebar,
  .tpv-shell.is-mobile-nav-open .app-sidebar.is-collapsed {
    z-index: 110;
  }

  .tpv-shell .tpv-header > h1 {
    flex: 1;
    min-width: 0;
  }

  .tpv-shell .app-main,
  .tpv-shell .tpv-main {
    height: 100%;
    max-height: 100%;
    min-height: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
  }
  .tpv-shell .page-content.tpv-page {
    flex: 1;
    min-height: 0;
    padding: 0;
    gap: 0;
    overflow: hidden;
  }
  .tpv-header {
    padding: .45rem .75rem;
    margin: 0;
    gap: .5rem;
    flex-shrink: 0;
  }
  .tpv-header h1 {
    margin: 0;
    font-size: 1.05rem;
  }
  .tpv-header-actions {
    gap: .35rem;
  }
  .tpv-header-actions .btn {
    padding: .35rem .55rem;
    font-size: .74rem;
  }

  .tpv-workspace {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    gap: 0;
    position: relative;
  }
  .tpv-catalog-area {
    position: static;
    flex: 0 0 0;
    height: 0;
    overflow: visible;
    z-index: auto;
  }
  .tpv-products-toggle,
  .tpv-client-toggle {
    display: inline-flex;
  }

  .tpv-catalog-backdrop {
    display: none !important;
  }

  .tpv-catalog,
  .tpv-catalog.panel {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    max-width: 100%;
    height: var(--tpv-app-height, 100dvh);
    max-height: var(--tpv-app-height, 100dvh);
    z-index: 300;
    transform: translateX(100%);
    transition: transform .32s cubic-bezier(.4, 0, .2, 1);
    border-radius: 0;
    border: 0;
    box-shadow: none;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-sizing: border-box;
  }
  .tpv-catalog.is-open {
    transform: translateX(0);
  }
  .tpv-catalog-drawer-head {
    display: flex;
    padding: .65rem .75rem;
  }
  .tpv-drawer-search {
    padding: 0 .75rem .65rem;
    border-bottom: 1px solid var(--border);
    background: var(--bg-elevated, var(--surface));
  }
  .tpv-drawer-search .input-lg {
    font-size: .88rem;
    padding: .55rem .75rem;
  }
  .tpv-catalog .tpv-toolbar {
    padding: .65rem .75rem .5rem;
    gap: .45rem;
    border-bottom: 0;
  }
  .tpv-categories {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    gap: .35rem;
    padding-bottom: .1rem;
  }
  .tpv-categories::-webkit-scrollbar { display: none; }
  .tpv-cat-btn {
    flex-shrink: 0;
    padding: .32rem .65rem;
    font-size: .76rem;
  }

  .tpv-products-grid {
    display: flex !important;
    flex-wrap: wrap !important;
    align-content: flex-start;
    align-items: flex-start;
    gap: .5rem;
    padding: .5rem;
    width: 100%;
    box-sizing: border-box;
    overflow-x: hidden;
    overflow-y: auto;
  }
  .tpv-product-card {
    flex: 0 0 calc(50% - .25rem);
    width: calc(50% - .25rem);
    max-width: calc(50% - .25rem);
    min-width: 0;
    height: auto;
    align-self: flex-start;
    box-sizing: border-box;
    border-radius: 10px;
  }
  .tpv-product-card:hover {
    box-shadow: none;
  }
  .tpv-product-card:active {
    transform: scale(0.97);
    border-color: var(--accent);
    background: color-mix(in srgb, var(--accent) 6%, var(--surface));
  }
  .tpv-product-body {
    display: block;
    flex: none;
    min-height: 0;
    padding: .4rem .45rem .5rem;
  }
  .tpv-product-name {
    font-size: .74rem;
    max-height: 2.4em;
    min-height: 0;
    margin-bottom: .25rem;
    word-break: break-word;
  }
  .tpv-product-foot {
    margin-top: 0;
    min-height: 0;
  }
  .tpv-product-price { font-size: .82rem; }
  .tpv-product-badge { font-size: .62rem; }

  .tpv-cart {
    flex: 1 1 auto;
    min-height: 0;
    height: 100%;
    border-radius: 0;
    box-shadow: none;
    border: 0;
    overflow: hidden;
  }
  .tpv-cart-head {
    padding: .5rem .75rem;
    flex-shrink: 0;
  }
  .tpv-cart-head h2 {
    font-size: .92rem;
    gap: .4rem;
  }
  .tpv-cart-count {
    min-width: 1.45rem;
    height: 1.45rem;
    font-size: .72rem;
  }
  .tpv-client-selected {
    font-size: .74rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .tpv-client.is-collapsed {
    display: none;
  }
  .tpv-client {
    padding: .45rem .75rem;
    flex-shrink: 0;
  }
  .tpv-cart-body {
    flex: 1 1 auto;
    min-height: 0;
    overflow: hidden;
  }
  .tpv-cart-lines {
    flex: 1 1 auto;
    min-height: 0 !important;
    max-height: none;
    padding: .35rem .75rem;
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
  .tpv-cart-line {
    padding: .55rem 0;
  }
  .tpv-cart-line-title { font-size: .84rem; }
  .tpv-cart-line-meta { font-size: .74rem; }
  .tpv-qty-btn {
    width: 1.75rem;
    height: 1.75rem;
    font-size: .9rem;
  }
  .tpv-line-total { font-size: .88rem; }
  .tpv-empty {
    padding: .75rem .25rem;
    font-size: .82rem;
  }

  .tpv-checkout-block {
    flex: 0 0 auto;
    padding-bottom: env(safe-area-inset-bottom, 0px);
    background: color-mix(in srgb, var(--accent) 4%, var(--surface));
  }
  .tpv-checkout-hint {
    display: none;
  }
  .tpv-totals {
    padding: .35rem .75rem .25rem;
    gap: .1rem;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    text-align: center;
  }
  .tpv-total-row {
    flex-direction: column;
    align-items: center;
    font-size: .68rem;
    gap: .05rem;
  }
  .tpv-total-row strong { font-size: .78rem; }
  .tpv-total-main {
    grid-column: 1 / -1;
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
    text-align: left;
    border-top: 1px solid var(--border);
    padding-top: .3rem;
    margin-top: .05rem;
    font-size: .95rem;
  }
  .tpv-total-main strong { font-size: 1.15rem; }
  .tpv-pay-methods {
    padding: 0 .75rem .35rem;
    gap: .35rem;
  }
  .tpv-pay-btn {
    padding: .4rem .2rem;
    font-size: .7rem;
    border-radius: 8px;
  }
  .tpv-cash-panel {
    padding: 0 .75rem .35rem;
  }
  .tpv-cash-panel .input-lg {
    padding: .45rem .6rem;
    font-size: .88rem;
  }
  .tpv-change {
    font-size: .82rem;
  }
  .tpv-checkout-btn {
    margin: 0 .75rem .45rem;
    width: calc(100% - 1.5rem);
    min-height: 2.45rem;
    font-size: .92rem;
  }

  .tpv-recent { display: none; }
}

/* Pantallas muy bajas: compactar checkout para que Cobrar no quede fuera */
@media (max-width: 900px) and (max-height: 700px) {
  .tpv-totals .tpv-total-row:not(.tpv-total-main) {
    display: none;
  }
  .tpv-totals {
    padding: .3rem .75rem .2rem;
    grid-template-columns: 1fr;
  }
  .tpv-total-main {
    border-top: 0;
    padding-top: 0;
    margin-top: 0;
  }
  .tpv-pay-btn {
    padding: .32rem .15rem;
    font-size: .66rem;
  }
  .tpv-checkout-btn {
    min-height: 2.25rem;
    margin-bottom: .35rem;
  }
  .tpv-cart-head {
    padding: .4rem .65rem;
  }
}

@media (max-width: 900px) {
  dialog[open].tpv-modal {
    top: 50% !important;
    left: 50% !important;
    right: auto !important;
    bottom: auto !important;
    transform: translate(-50%, -50%) !important;
    width: min(520px, calc(100vw - 1.5rem)) !important;
    max-width: calc(100vw - 1.5rem) !important;
    height: auto !important;
    max-height: 90dvh !important;
    min-height: 0 !important;
    margin: 0 !important;
    border-radius: 16px !important;
    display: block !important;
    overflow: visible !important;
  }
}


/* —— Dashboard mobile dock —— */
.dash-mobile-dock {
  display: none;
}
@media (max-width: 900px) {
  .dash-mobile-dock {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 90;
    display: flex;
    align-items: stretch;
    justify-content: space-around;
    gap: 0;
    min-height: 3.65rem;
    padding: 0.35rem 0.2rem calc(0.35rem + env(safe-area-inset-bottom, 0px));
    border-top: 1px solid var(--border);
    background: color-mix(in srgb, var(--bg-elevated) 92%, transparent);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    box-shadow: 0 -8px 24px rgba(0, 0, 0, 0.25);
  }
  body:has(.dash-mobile-dock) .app-main {
    padding-bottom: calc(4.75rem + env(safe-area-inset-bottom, 0px));
  }
  .dash-dock-item {
    flex: 1 1 0;
    min-width: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.15rem;
    padding: 0.25rem 0.1rem;
    border: 0;
    background: transparent;
    color: var(--muted);
    font-size: 0.62rem;
    font-weight: 600;
    line-height: 1.1;
    cursor: pointer;
    border-radius: 10px;
  }
  .dash-dock-item svg {
    width: 1.25rem;
    height: 1.25rem;
    flex-shrink: 0;
  }
  .dash-dock-item span {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .dash-dock-item.is-active {
    color: var(--accent);
    background: color-mix(in srgb, var(--accent) 14%, transparent);
  }
  .dash-dock-view-toggle .dash-dock-icon-cards[hidden],
  .dash-dock-view-toggle .dash-dock-icon-table[hidden] { display: none !important; }
  .dash-dock-view-toggle.is-cards,
  .dash-dock-view-toggle.is-table {
    color: var(--accent);
  }
  #hero-kpis,
  #dash-invoices,
  #dash-purchases,
  #dash-overdue,
  #dash-prospects {
    scroll-margin-top: calc(var(--app-topbar-height, 3.5rem) - 35px);
  }


  .dashboard-v2 .datatable-view-switch.is-dock-controlled,
  .dashboard-v2 .datatable-shell .datatable-view-switch {
    display: none !important;
  }
}

.subscription-layout {
  gap: 1rem;
}
.subscription-plan-label {
  margin: 0 0 .2rem;
  font-size: .72rem;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-muted);
}
.subscription-plan-name {
  margin: 0;
  font-size: 1.2rem;
  line-height: 1.25;
}
.subscription-plan-meta {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1rem 1.25rem;
  margin: 0;
}
.subscription-plan-meta dt {
  margin: 0 0 .2rem;
  font-size: .72rem;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text-muted);
}
.subscription-plan-meta dd {
  margin: 0;
  font-weight: 600;
}
.subscription-limits-table td,
.subscription-limits-table th {
  white-space: nowrap;
}
.subscription-limits-table td:first-child {
  white-space: normal;
  min-width: 10rem;
}
.subscription-row-at-limit {
  background: rgba(239, 68, 68, .08);
}
.subscription-usage {
  display: flex;
  align-items: center;
  gap: .55rem;
  min-width: 140px;
}
.subscription-usage-track {
  flex: 1;
  height: .45rem;
  border-radius: 999px;
  background: rgba(148, 163, 184, .18);
  overflow: hidden;
  max-width: 110px;
}
.subscription-usage-bar {
  height: 100%;
  border-radius: 999px;
  background: var(--accent);
}
.subscription-usage-bar.is-warning {
  background: #f59e0b;
}
.subscription-usage-bar.is-full {
  background: #ef4444;
}
.subscription-usage-pct {
  font-size: .78rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  min-width: 2.5rem;
}
.subscription-features-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: .75rem;
  width: 100%;
}
.subscription-feature-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .65rem;
  min-height: 3.25rem;
  padding: .9rem 1rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: rgba(148, 163, 184, .06);
  box-sizing: border-box;
}
.subscription-feature-item.is-enabled {
  border-color: rgba(34, 197, 94, .35);
  background: rgba(34, 197, 94, .08);
}
.subscription-feature-item.is-disabled {
  opacity: .9;
}
.subscription-feature-name {
  font-weight: 600;
  font-size: .92rem;
  line-height: 1.2;
}
.pill.status-past_due {
  background: rgba(245, 158, 11, .18);
  color: #fcd34d;
  border: 1px solid rgba(245, 158, 11, .35);
}
@media (max-width: 900px) {
  .subscription-plan-meta {
    grid-template-columns: 1fr;
  }
  .subscription-features-row {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
@media (max-width: 560px) {
  .subscription-features-row {
    grid-template-columns: 1fr;
  }
}
