/* =============================================================================
   style.css — Sistema de diseño DOCTRIX.
   Hoja base para la SPA: tema claro/oscuro, responsive, toasts y componentes.
   Incluye: glassmorphism, dark mode, responsive, animaciones, toasts.
   ============================================================================= */

/* ── FUENTES ─────────────────────────────────────────────────────────────────── */
@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;500;600;700;800&family=Poppins:wght@400;500;600;700&display=swap');

/* ── TOKENS DE DISEÑO ────────────────────────────────────────────────────────── */
:root {
  --bg-main:             #f8fafc;
  --bg-card:             #ffffff;
  --bg-sidebar:          #ffffff;
  --surface-glass:       rgba(15,23,42,0.02);
  --surface-glass-hover: rgba(15,23,42,0.05);
  --border-glass:        rgba(15,23,42,0.08);
  --border-glass-active: rgba(15,23,42,0.18);
  --primary:             #4f46e5;
  --primary-hover:       #3730a3;
  --primary-accent:      #818cf8;
  --primary-soft:        rgba(79,70,229,0.08);
  --primary-glow:        rgba(79,70,229,0.25);
  --success:             #027a48;
  --success-soft:        #ecfdf3;
  --danger:              #b42318;
  --danger-soft:         #fef3f2;
  --warning:             #b54708;
  --warning-soft:        #fffaeb;
  --text-main:           #0f172a;
  --text-muted:          #475569;
  --text-faint:          #94a3b8;
  --border:              rgba(15,23,42,0.12);
  --input-bg:            #ffffff;
  --bg-input:            var(--input-bg);
  --bg-hover:            var(--surface-glass-hover);
  --text-primary:        var(--text-main);
  --text-color:          var(--text-main);
  --border-color:        var(--border);
  --shadow-sm:           0 1px 2px rgba(15,23,42,0.04), 0 1px 8px rgba(15,23,42,0.03);
  --shadow-md:           0 8px 22px rgba(15,23,42,0.07);
  --shadow-lg:           0 16px 38px rgba(15,23,42,0.09);
  --shadow-xl:           0 24px 60px rgba(15,23,42,0.14);
  --radius-sm:           10px;
  --radius-md:           12px;
  --radius-lg:           18px;
  --radius-xl:           24px;
  --font:                'Outfit','Poppins',sans-serif;
  --transition:          all 0.3s cubic-bezier(0.4,0,0.2,1);
  --blur:                12px;
  --sidebar-w:           270px;
  --space-xs:            0.35rem;
  --space-sm:            0.65rem;
  --space-md:            1rem;
  --space-lg:            1.5rem;
  --space-xl:            2rem;
  --text:                var(--text-main);
  --bg-secondary:        var(--surface-glass);
  --bg-primary:          var(--bg-card);
  --bg-body:             var(--bg-main);
  --radius:              var(--radius-md);
  --primary-light:       var(--primary-accent);
  --accent:              var(--primary-accent);
}

/* ── DARK MODE ───────────────────────────────────────────────────────────────── */
body.dark {
  --bg-main:             #08090e;
  --bg-card:             rgba(15,23,42,0.60);
  --bg-sidebar:          #0d1117;
  --surface-glass:       rgba(255,255,255,0.03);
  --surface-glass-hover: rgba(255,255,255,0.07);
  --border-glass:        rgba(255,255,255,0.06);
  --border-glass-active: rgba(255,255,255,0.14);
  --primary:             #6366f1;
  --primary-hover:       #4f46e5;
  --primary-accent:      #818cf8;
  --primary-soft:        rgba(99,102,241,0.12);
  --primary-glow:        rgba(99,102,241,0.35);
  --text-main:           #f1f5f9;
  --text-muted:          #94a3b8;
  --text-faint:          #64748b;
  --border:              rgba(255,255,255,0.07);
  --input-bg:            #111520;
  --bg-input:            var(--input-bg);
  --bg-hover:            var(--surface-glass-hover);
  --text-primary:        var(--text-main);
  --text-color:          var(--text-main);
  --border-color:        var(--border);
  --shadow-sm:           0 1px 3px rgba(0,0,0,0.3);
  --shadow-md:           0 4px 12px rgba(0,0,0,0.4);
  --shadow-lg:           0 10px 30px rgba(0,0,0,0.5);
  --shadow-xl:           0 20px 50px rgba(0,0,0,0.6);
  --text:                var(--text-main);
  --bg-secondary:        var(--surface-glass);
  --bg-primary:          var(--bg-card);
  --bg-body:             var(--bg-main);
  --primary-light:       var(--primary-accent);
  --accent:              var(--primary-accent);
}

@media (prefers-color-scheme:dark) {
  body:not(.light) { /* mismos tokens que body.dark */ }
}

/* ── RESET Y BASE ────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 16px; scroll-behavior: smooth; }

/* ── TOUCH UX GLOBAL ─────────────────────────────────────────────────────────── */
* { -webkit-tap-highlight-color: transparent; }
button, [role="button"], a, .nav-item, .btn, .modal-close, .btn-theme {
  touch-action: manipulation;
}
input, select, textarea { touch-action: manipulation; }

/* Feedback táctil al presionar */
.btn:active:not(:disabled) { transform: scale(0.97); }
.nav-item:active { opacity: 0.75; }

/* Fuente mínima 16px en móvil para evitar zoom en iOS Safari */
@media (max-width: 767px) {
  input[type="text"],
  input[type="email"],
  input[type="password"],
  input[type="date"],
  input[type="number"],
  select, textarea { font-size: 16px !important; }
}

body {
  font-family: var(--font);
  background: var(--bg-main);
  color: var(--text-main);
  min-height: 100vh;
  transition: background 0.4s, color 0.3s;
  line-height: 1.6;
  background-image:
    radial-gradient(at 15% 25%, rgba(99,102,241,0.05) 0, transparent 55%),
    radial-gradient(at 85% 75%, rgba(6,182,212,0.04) 0, transparent 55%);
}
body.dark {
  color-scheme: dark;
  background-image:
    radial-gradient(at 15% 25%, rgba(99,102,241,0.10) 0, transparent 55%),
    radial-gradient(at 85% 75%, rgba(6,182,212,0.07) 0, transparent 55%);
}

/* ═══════════════════════════════════════════════════════════════════════════════
   PANTALLA DE LOGIN
   ═══════════════════════════════════════════════════════════════════════════════ */
#login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}

.login-card {
  background: var(--bg-card);
  backdrop-filter: blur(var(--blur));
  -webkit-backdrop-filter: blur(var(--blur));
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-xl);
  padding: 2.8rem 2.5rem;
  width: 100%;
  max-width: 420px;
  box-shadow: var(--shadow-xl);
  animation: fadeSlideUp 0.5s ease both;
}

.login-logo {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 2rem;
  justify-content: center;
}

.login-logo-icon {
  width: 52px;
  height: 52px;
  background: linear-gradient(135deg, var(--primary), var(--primary-accent));
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 8px 24px var(--primary-glow);
  font-size: 1.6rem;
}
.login-logo-icon.has-image {
  background: var(--bg-card);
  padding: 5px;
}

.brand-logo-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  border-radius: inherit;
}

/*
  Logos en modo oscuro:
  - Evita una placa blanca tipo “parche”.
  - Convierte trazos/fondos negros a claros.
  - `hue-rotate(180deg)` compensa la inversión para conservar mejor colores como azul.
*/
body.dark .brand-logo-img,
body.dark .logo-preview-img {
  filter: invert(1) hue-rotate(180deg) saturate(1.08) contrast(1.05);
}

body.dark .login-logo-icon.has-image,
body.dark .brand-icon.has-image {
  background: transparent;
  box-shadow: 0 0 0 1px var(--border-glass), 0 8px 22px var(--primary-glow);
}

.login-brand h1 {
  font-size: 1.3rem;
  font-weight: 800;
  background: linear-gradient(135deg, var(--primary), var(--primary-accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.login-brand p { font-size: 0.78rem; color: var(--text-muted); }

.login-title {
  text-align: center;
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text-main);
  margin-bottom: 0.4rem;
}
.login-sub {
  text-align: center;
  font-size: 0.875rem;
  color: var(--text-muted);
  margin-bottom: 2rem;
}

.login-options {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 0.2rem;
  font-size: 0.8rem;
  color: var(--text-muted);
}
.login-remember {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  user-select: none;
}
.login-support {
  color: var(--primary);
  text-decoration: none;
  font-weight: 600;
}
.login-support:hover { text-decoration: underline; }

/* ═══════════════════════════════════════════════════════════════════════════════
   APP SHELL (post-login)
   ═══════════════════════════════════════════════════════════════════════════════ */
#app {
  display: none;
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
}
#app.visible { display: flex; }

/* ── SIDEBAR ─────────────────────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border-glass);
  display: flex;
  flex-direction: column;
  height: 100%;
  padding: 1.4rem 1rem;
  transition: var(--transition);
  z-index: 50;
  overflow-y: auto;
  overflow-x: hidden;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0.4rem 0.6rem 1.8rem;
  border-bottom: 1px solid var(--border-glass);
  margin-bottom: 1.2rem;
}

.brand-icon {
  width: 40px;
  height: 40px;
  background: linear-gradient(135deg, var(--primary), var(--primary-accent));
  border-radius: 11px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  box-shadow: 0 4px 12px var(--primary-glow);
  flex-shrink: 0;
}
.brand-icon.has-image {
  background: var(--bg-card);
  padding: 4px;
  border: 1px solid var(--border-glass);
}

.logo-preview-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.brand-text h2 {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-main);
  white-space: nowrap;
}
.brand-text span {
  font-size: 0.68rem;
  color: var(--text-muted);
  font-weight: 500;
}

/* ── MENÚ LATERAL ─────────────────────────────────────────────────────────────── */
.nav-group { margin-bottom: 1.4rem; }
.nav-group-label {
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--text-faint);
  padding: 0 0.8rem;
  margin-bottom: 0.5rem;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: var(--radius-md);
  color: var(--text-muted);
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
  border: 1px solid transparent;
  text-decoration: none;
  white-space: nowrap;
  overflow: hidden;
  user-select: none;
}
.nav-item:hover {
  background: var(--surface-glass-hover);
  color: var(--text-main);
}
.nav-item.active {
  background: linear-gradient(135deg, var(--primary-soft), transparent);
  color: var(--primary);
  border-color: rgba(99,102,241,0.18);
  font-weight: 600;
}
.nav-item .nav-icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  opacity: 0.8;
  transition: var(--transition);
}
.nav-item.active .nav-icon { opacity: 1; filter: drop-shadow(0 0 4px var(--primary)); }

/* ── BADGE DE CONTEO EN MENÚ ──────────────────────────────────────────────────── */
.nav-badge {
  margin-left: auto;
  background: var(--primary);
  color: #fff;
  font-size: 0.65rem;
  font-weight: 700;
  padding: 1px 7px;
  border-radius: 20px;
  min-width: 20px;
  text-align: center;
}

/* ── FOOTER SIDEBAR ───────────────────────────────────────────────────────────── */
.sidebar-footer {
  margin-top: auto;
  padding-top: 1rem;
  border-top: 1px solid var(--border-glass);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.user-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-md);
  background: var(--surface-glass);
  border: 1px solid var(--border-glass);
  cursor: default;
  transition: var(--transition);
}
.user-card:hover { background: var(--surface-glass-hover); }

.user-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--primary-accent));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
}
.user-info-text .user-name {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-main);
  white-space: nowrap;
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  display: block;
}
.user-info-text .user-role {
  font-size: 0.7rem;
  color: var(--text-muted);
  display: block;
}

.btn-logout {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 9px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-glass);
  background: var(--surface-glass);
  color: var(--text-muted);
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
  font-family: var(--font);
  width: 100%;
}
.btn-logout:hover { background: rgba(180,35,24,0.08); border-color: var(--danger); color: var(--danger); }

/* ═══════════════════════════════════════════════════════════════════════════════
   ÁREA PRINCIPAL
   ═══════════════════════════════════════════════════════════════════════════════ */
.main-area {
  flex: 1;
  min-width: 0;
  height: 100%;
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  background: var(--bg-main);
}

/* ── HEADER TOPBAR ───────────────────────────────────────────────────────────── */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 2rem;
  border-bottom: 1px solid var(--border-glass);
  background: var(--bg-card);
  backdrop-filter: blur(var(--blur));
  position: sticky;
  top: 0;
  z-index: 40;
  gap: 12px;
}

.topbar-title h2 {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text-main);
}
.topbar-title p { font-size: 0.78rem; color: var(--text-muted); }

.topbar-actions { display: flex; align-items: center; gap: 10px; }

/* ── TOGGLE DARK MODE ─────────────────────────────────────────────────────────── */
.btn-theme {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 1px solid var(--border-glass);
  background: var(--surface-glass);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  transition: var(--transition);
  color: var(--text-muted);
}
.btn-theme:hover { background: var(--primary-soft); color: var(--primary); }

/* ── CONTENIDO DE PÁGINAS ─────────────────────────────────────────────────────── */
.page-content {
  padding: 2rem;
  flex: 1;
  align-self: stretch;
  display: none;
  flex-direction: column;
  gap: 1.5rem;
  width: 100%;
  min-width: 0;
  box-sizing: border-box;
  overflow-x: hidden;
}
.page-content.active { display: flex; }

/* ── CARDS ────────────────────────────────────────────────────────────────────── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-lg);
  padding: 1.6rem;
  box-shadow: var(--shadow-sm);
  transition: var(--transition);
}
.card:hover { box-shadow: var(--shadow-md); }

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.4rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border-glass);
}
.card-header h3 {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-main);
  display: flex;
  align-items: center;
  gap: 8px;
}
.card-header h3 span.card-icon { color: var(--primary); font-size: 1.1rem; }

/* ── STAT CARDS (dashboard) ───────────────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1.2rem;
}
.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-lg);
  padding: 1.4rem 1.6rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  box-shadow: var(--shadow-sm);
  transition: var(--transition);
  cursor: default;
}
.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.stat-icon-wrap {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  flex-shrink: 0;
}
.stat-icon-wrap.blue   { background: rgba(79,70,229,0.1); }
.stat-icon-wrap.green  { background: rgba(2,122,72,0.1);  }
.stat-icon-wrap.orange { background: rgba(181,71,8,0.1);  }
.stat-icon-wrap.purple { background: rgba(126,34,206,0.1);}
.stat-value { font-size: 1.8rem; font-weight: 800; color: var(--text-main); line-height: 1; }
.stat-label { font-size: 0.8rem; color: var(--text-muted); margin-top: 2px; }

/* ═══════════════════════════════════════════════════════════════════════════════
   FORMULARIOS
   ═══════════════════════════════════════════════════════════════════════════════ */
.form-section-title {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  font-weight: 700;
  color: var(--primary);
  border-bottom: 1px solid var(--border-glass);
  padding-bottom: 6px;
  margin: 1.6rem 0 1rem;
}
.form-section-title:first-child { margin-top: 0; }

.input-block { margin-bottom: 1rem; }

label {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-main);
  margin-bottom: 5px;
}
label .req { color: var(--danger); margin-left: 2px; }

input[type="text"],
input[type="email"],
input[type="password"],
input[type="date"],
input[type="number"],
select,
textarea {
  width: 100%;
  padding: 10px 13px;
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 0.9rem;
  color: var(--text-main);
  transition: border-color 0.2s, box-shadow 0.2s;
  outline: none;
}
input:focus,select:focus,textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}

.password-field {
  position: relative;
}
.password-field input {
  padding-right: 46px;
}
.password-toggle {
  position: absolute;
  top: 50%;
  right: 8px;
  transform: translateY(-50%);
  width: 34px;
  height: 34px;
  border: 1px solid transparent;
  border-radius: 9px;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.95rem;
  transition: var(--transition);
}
.password-toggle:hover,
.password-toggle:focus-visible {
  background: var(--primary-soft);
  color: var(--primary);
  outline: none;
}
.password-toggle[aria-pressed="true"] {
  background: var(--primary-soft);
  color: var(--primary);
}

/* Fix para autofill de navegadores (evitar fondo blanco/amarillo) */
input:-webkit-autofill,
input:-webkit-autofill:hover, 
input:-webkit-autofill:focus, 
input:-webkit-autofill:active {
    -webkit-box-shadow: 0 0 0 30px var(--input-bg) inset !important;
    -webkit-text-fill-color: var(--text-main) !important;
    transition: background-color 5000s ease-in-out 0s;
}

textarea { resize: vertical; min-height: 100px; }
select { cursor: pointer; appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
}
select option {
  background: var(--bg-card);
  color: var(--text-main);
}

input.invalid, select.invalid, textarea.invalid {
  border-color: var(--danger) !important;
  box-shadow: 0 0 0 3px rgba(180,35,24,0.12) !important;
  animation: shake 0.3s ease;
}
.field-error { font-size: 0.75rem; color: var(--danger); margin-top: 3px; display: block; }

.split-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.split-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 1rem; }

.color-input-row {
  display: grid;
  grid-template-columns: 52px 1fr;
  gap: 0.6rem;
  align-items: center;
}
.color-input-row input[type="color"] {
  width: 52px;
  height: 42px;
  padding: 3px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--input-bg);
  cursor: pointer;
}

/* ── CAMPO BLOQUEADO (encargado automático) ──────────────────────────────────── */
.field-locked {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 13px;
  background: var(--primary-soft);
  border: 1px solid rgba(99,102,241,0.25);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--primary);
  cursor: not-allowed;
}

/* ── QUILL EDITOR ─────────────────────────────────────────────────────────────── */
.ql-toolbar {
  border-radius: var(--radius-sm) var(--radius-sm) 0 0 !important;
  border-color: var(--border) !important;
  background: var(--surface-glass) !important;
}
.ql-container {
  border-radius: 0 0 var(--radius-sm) var(--radius-sm) !important;
  border-color: var(--border) !important;
  background: var(--input-bg) !important;
  min-height: 250px;
  font-family: var(--font) !important;
}
.ql-editor {
  color: var(--text-main) !important;
  font-size: 0.9rem;
  min-height: 230px;
}
.ql-editor.ql-blank::before { color: var(--text-muted) !important; font-style: italic; opacity: 0.7; }
.ql-snow .ql-stroke { stroke: var(--text-muted) !important; }
.ql-snow .ql-fill  { fill:   var(--text-muted) !important; }
.ql-snow .ql-picker { color:  var(--text-muted) !important; }
.ql-container:focus-within { border-color: var(--primary) !important; box-shadow: 0 0 0 3px var(--primary-soft); }

/* --- DISEÑO DE EMISIÓN DE DOCUMENTOS (DOBLE COLUMNA) --- */
.emitir-columns {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  width: 100%;
}

/* Ocultar botones de navegación wizard en desktop (ambas columnas visibles) */
.wizard-actions-mobile-only { display: none !important; }

/* Topbar plan badge */
#topbar-plan-badge { display: flex !important; }
#topbar-plan-badge[style*="display:none"] { display: none !important; }
.emitir-column-params {
  display: flex;
  flex-direction: column;
  gap: 1.2rem;
  width: 100%;
}
.emitir-column-editor {
  display: flex;
  flex-direction: column;
  gap: 1.2rem;
  width: 100%;
}
@media (min-width: 901px) {
  .emitir-columns {
    flex-direction: row;
    align-items: stretch;
    gap: 2.5rem;
  }
  .emitir-column-params {
    width: 450px;
    flex-shrink: 0;
    border-right: 1px solid var(--border-glass);
    padding-right: 2.5rem;
  }
  .emitir-column-editor {
    flex: 1;
    min-width: 0;
  }
  .ql-container {
    min-height: 380px !important;
  }
}

.emitir-columns.single-column {
  flex-direction: column !important;
  max-width: 700px;
  margin: 0 auto;
  gap: 1.5rem !important;
}
.emitir-columns.single-column .emitir-column-params {
  width: 100% !important;
  border-right: none !important;
  padding-right: 0 !important;
}
.emitir-columns.single-column .emitir-column-editor {
  flex: none;
  width: 100%;
}

/* ═══════════════════════════════════════════════════════════════════════════════
   BOTONES
   ═══════════════════════════════════════════════════════════════════════════════ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 10px 20px;
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  border: 1px solid transparent;
  outline: none;
  white-space: nowrap;
  text-decoration: none;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; pointer-events: none; }

.btn-primary {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 2px 8px var(--primary-glow);
}
.btn-primary:hover { background: var(--primary-hover); box-shadow: 0 4px 16px var(--primary-glow); transform: translateY(-1px); }

.btn-generate-special,
.btn-generate-confirm {
  position: relative;
  isolation: isolate;
  overflow: hidden;
  background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 48%, #06b6d4 100%);
  border: 1px solid rgba(255,255,255,0.18);
  box-shadow: 0 10px 26px rgba(79,70,229,0.28), 0 2px 8px rgba(6,182,212,0.16);
}
.btn-generate-special > *,
.btn-generate-confirm > * { position: relative; z-index: 1; }
.btn-generate-special::after,
.btn-generate-confirm::after {
  content: '';
  position: absolute;
  inset: 0;
  z-index: 0;
  background: linear-gradient(110deg, transparent 0%, rgba(255,255,255,0.34) 45%, transparent 62%);
  transform: translateX(-125%);
  animation: docButtonSheen 3.4s ease-in-out infinite;
  pointer-events: none;
}
.btn-generate-special:hover,
.btn-generate-confirm:hover {
  background: linear-gradient(135deg, #4338ca 0%, #6d28d9 48%, #0891b2 100%);
  box-shadow: 0 14px 34px rgba(79,70,229,0.38), 0 4px 18px rgba(6,182,212,0.24);
  transform: translateY(-2px);
}
.btn-generate-special.is-generating,
.btn-generate-special.is-generating:disabled {
  opacity: 1;
  cursor: wait;
  animation: generateButtonPulse 1.45s ease-in-out infinite;
}
.btn-generate-icon { filter: drop-shadow(0 0 8px rgba(255,255,255,0.55)); }
.doc-gen-spinner {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.38);
  border-top-color: #fff;
  box-shadow: 0 0 12px rgba(255,255,255,0.5);
  animation: spin 0.72s linear infinite;
}

.btn-success {
  background: var(--success);
  color: #fff;
  box-shadow: 0 2px 8px rgba(2,122,72,0.25);
}
.btn-success:hover { background: #025a34; transform: translateY(-1px); }

.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #8c1a11; transform: translateY(-1px); }

.btn-ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--text-muted);
}
.btn-ghost:hover { background: var(--surface-glass-hover); color: var(--text-main); border-color: var(--border-glass-active); }

.btn-outline-primary {
  background: var(--primary-soft);
  border-color: var(--primary);
  color: var(--primary);
}
.btn-outline-primary:hover { background: var(--primary); color: #fff; }

.btn-sm { padding: 6px 14px; font-size: 0.8rem; }
.btn-lg { padding: 13px 28px; font-size: 0.95rem; }
.btn-full { width: 100%; }

/* ── BOTONES IA ───────────────────────────────────────────────────────────────── */
.btn-ia {
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  color: #fff;
  box-shadow: 0 2px 12px rgba(99,102,241,0.35);
}
.btn-ia:hover { transform: translateY(-1px); box-shadow: 0 4px 18px rgba(99,102,241,0.45); }

.ia-spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  vertical-align: middle;
}

/* ═══════════════════════════════════════════════════════════════════════════════
   TABLAS
   ═══════════════════════════════════════════════════════════════════════════════ */
.table-wrap { overflow-x: auto; border-radius: var(--radius-md); border: 1px solid var(--border-glass); }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}
thead {
  background: var(--surface-glass);
  border-bottom: 1px solid var(--border-glass);
}
th {
  padding: 10px 14px;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-muted);
  text-align: left;
  white-space: nowrap;
}
td { padding: 11px 14px; color: var(--text-main); border-bottom: 1px solid var(--border-glass); vertical-align: middle; }
tbody tr:hover { background: var(--surface-glass); }
tbody tr:last-child td { border-bottom: none; }

.td-nomen {
  font-family: monospace;
  font-size: 0.82rem;
  color: var(--primary);
  font-weight: 600;
  background: var(--primary-soft);
  padding: 3px 8px;
  border-radius: 4px;
  white-space: nowrap;
}

/* ── BADGES / CHIPS ───────────────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 0.72rem;
  font-weight: 600;
  white-space: nowrap;
}
.badge-success { background: rgba(2,122,72,0.12); color: var(--success); }
.badge-danger  { background: rgba(180,35,24,0.10); color: var(--danger); }
.badge-warning { background: rgba(181,71,8,0.10);  color: var(--warning);}
.badge-primary { background: var(--primary-soft);  color: var(--primary); }
.badge-gray    { background: var(--surface-glass-hover); color: var(--text-muted); }

/* ═══════════════════════════════════════════════════════════════════════════════
   TOAST / NOTIFICACIONES
   ═══════════════════════════════════════════════════════════════════════════════ */
#toast-container {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  z-index: 99999;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 10px;
  pointer-events: none;
}
@media (max-width: 767px) {
  /* En móvil el toast queda sobre la bottom-nav */
  #toast-container {
    bottom: calc(70px + 1rem);
    right: 1rem;
    left: 1rem;
    align-items: stretch;
  }
  .toast { min-width: unset; width: 100%; max-width: unset; }
}
.toast {
  min-width: 300px;
  max-width: 500px;
  padding: 16px 22px;
  border-radius: 14px;
  font-size: 0.9rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 12px;
  pointer-events: all;
  animation: toastIn 0.35s cubic-bezier(.34,1.56,.64,1) both;
  box-shadow: var(--shadow-xl);
  border-bottom: 3px solid rgba(255,255,255,0.25);
  line-height: 1.4;
}
.toast-success { background: var(--success); color: #fff; }
.toast-error   { background: var(--danger);  color: #fff; }
.toast-info    { background: var(--primary); color: #fff; }
.toast-warning { background: #b54708;        color: #fff; }
.toast-icon    { font-size: 1.2rem; flex-shrink: 0; }

/* ═══════════════════════════════════════════════════════════════════════════════
   MODAL
   ═══════════════════════════════════════════════════════════════════════════════ */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  backdrop-filter: blur(4px);
  z-index: 1000;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  animation: fadeIn 0.2s ease;
}
.modal-backdrop.open { display: flex; }

/* Compatibilidad para modales antiguos que usan .modal-overlay/.modal-content
   y se abren/cerran cambiando style.display desde JavaScript inline. */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  backdrop-filter: blur(4px);
  z-index: 1000;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  animation: fadeIn 0.2s ease;
}
.modal-overlay.open { display: flex; }

.modal-content {
  background: var(--bg-card);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-xl);
  padding: 2rem;
  width: 100%;
  max-width: 520px;
  box-shadow: var(--shadow-xl);
  animation: fadeSlideUp 0.3s ease both;
  max-height: 90vh;
  overflow-y: auto;
  color: var(--text-main);
}

.modal {
  background: var(--bg-card);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-xl);
  padding: 2rem;
  width: 100%;
  max-width: 520px;
  box-shadow: var(--shadow-xl);
  animation: fadeSlideUp 0.3s ease both;
  max-height: 90vh;
  overflow-y: auto;
}

/* ── BOTTOM SHEET en móvil ───────────────────────────────────────────────────── */
@media (max-width: 767px) {
  .modal-overlay {
    align-items: flex-end;
    padding: 0;
  }
  .modal {
    max-width: 100%;
    width: 100%;
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    border-bottom: none;
    padding: 1.5rem 1.2rem 2rem;
    max-height: 92dvh;
    animation: bottomSheetUp 0.32s cubic-bezier(0.32, 0.72, 0, 1) both;
    /* Handle visual */
    background-image:
      radial-gradient(ellipse 40px 4px at 50% 12px, var(--border-glass) 100%, transparent 0);
    padding-top: 2rem;
  }
}

@keyframes bottomSheetUp {
  from { transform: translateY(100%); opacity: 0.6; }
  to   { transform: translateY(0);    opacity: 1; }
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.4rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border-glass);
}
.modal-header h3 { font-size: 1.05rem; font-weight: 700; color: var(--text-main); }
.modal-close { background: none; border: none; font-size: 1.3rem; cursor: pointer; color: var(--text-muted); padding: 4px; border-radius: 6px; transition: var(--transition); }
.modal-close:hover { background: var(--surface-glass-hover); color: var(--text-main); }

/* ═══════════════════════════════════════════════════════════════════════════════
   BARRA DE PROGRESO
   ═══════════════════════════════════════════════════════════════════════════════ */
.progress-wrap {
  background: var(--border-glass);
  border-radius: 20px;
  height: 6px;
  overflow: hidden;
  margin: 0.5rem 0;
}
.progress-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), #818cf8);
  border-radius: 20px;
  transition: width 0.4s ease;
  width: 0%;
}

/* ── EXPERIENCIA PREMIUM DE GENERACIÓN DE DOCUMENTO ─────────────────────────── */
.generation-progress {
  position: relative;
  overflow: hidden;
  margin-top: 1rem;
  padding: 1rem;
  border-radius: var(--radius-lg);
  background: linear-gradient(135deg, rgba(79,70,229,0.10), rgba(6,182,212,0.08));
  border: 1px solid rgba(99,102,241,0.20);
  box-shadow: 0 12px 32px rgba(79,70,229,0.12);
}
.generation-progress::before {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 18% 18%, rgba(255,255,255,0.52), transparent 28%),
              linear-gradient(110deg, transparent 0%, rgba(255,255,255,0.18) 45%, transparent 64%);
  transform: translateX(-110%);
  animation: progressShimmer 2.4s ease-in-out infinite;
  pointer-events: none;
}
.generation-progress.is-visible { animation: premiumReveal 0.38s ease both; }
.generation-progress-head {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  gap: 0.8rem;
  margin-bottom: 0.75rem;
}
.generation-progress-head p {
  margin: 0;
  color: var(--text-main);
  font-weight: 700;
  font-size: 0.92rem;
}
.generation-progress-head small {
  display: block;
  color: var(--text-muted);
  font-size: 0.76rem;
  line-height: 1.3;
}
.generation-orb {
  position: relative;
  width: 36px;
  height: 36px;
  flex-shrink: 0;
  border-radius: 50%;
  background: linear-gradient(135deg, #4f46e5, #06b6d4);
  box-shadow: 0 0 0 7px rgba(79,70,229,0.10), 0 0 24px rgba(79,70,229,0.42);
  animation: generateOrbPulse 1.25s ease-in-out infinite;
}
.generation-orb::after {
  content: '📄';
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
}
.generation-progress-track {
  position: relative;
  z-index: 1;
  height: 8px;
  background: rgba(79,70,229,0.12);
}
.generation-progress .progress-bar {
  position: relative;
  overflow: hidden;
  background: linear-gradient(90deg, #4f46e5, #8b5cf6, #06b6d4);
  box-shadow: 0 0 16px rgba(79,70,229,0.38);
}
.generation-progress .progress-bar::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.55), transparent);
  animation: progressBarGlow 1.15s ease-in-out infinite;
}

.generation-result-card {
  position: relative;
  overflow: hidden;
  margin-top: 1rem;
  padding: 1.1rem !important;
  border-radius: var(--radius-lg) !important;
  background: linear-gradient(135deg, rgba(236,253,243,0.98), rgba(240,253,250,0.96)) !important;
  border: 1px solid rgba(2,122,72,0.22) !important;
  box-shadow: 0 16px 42px rgba(2,122,72,0.15), 0 0 0 1px rgba(255,255,255,0.55) inset;
  opacity: 0;
  transform: translateY(12px) scale(0.985);
}
body.dark .generation-result-card {
  background: linear-gradient(135deg, rgba(2,122,72,0.20), rgba(15,23,42,0.82)) !important;
  border-color: rgba(52,211,153,0.26) !important;
  box-shadow: 0 18px 46px rgba(0,0,0,0.45), 0 0 30px rgba(52,211,153,0.10);
}
.generation-result-card.is-visible { animation: documentWowIn 0.72s cubic-bezier(.2,1.28,.34,1) both; }
.generation-result-card.is-celebrating::after {
  content: '';
  position: absolute;
  inset: -55%;
  background:
    radial-gradient(circle, rgba(255,255,255,0.95) 0 2px, transparent 3px) 15% 25% / 120px 120px,
    radial-gradient(circle, rgba(34,197,94,0.55) 0 2px, transparent 3px) 65% 30% / 150px 150px,
    radial-gradient(circle, rgba(6,182,212,0.42) 0 2px, transparent 3px) 35% 75% / 140px 140px;
  animation: successSparkle 1.85s ease-out both;
  pointer-events: none;
}
.generation-result-glow {
  position: absolute;
  width: 190px;
  height: 190px;
  right: -70px;
  top: -90px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(52,211,153,0.32), transparent 68%);
  pointer-events: none;
}
.generation-result-content {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  gap: 0.85rem;
}
.generation-success-icon {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  background: linear-gradient(135deg, #027a48, #22c55e);
  color: #fff;
  font-size: 1.45rem;
  font-weight: 800;
  box-shadow: 0 8px 22px rgba(2,122,72,0.32);
  animation: successPop 0.58s cubic-bezier(.34,1.56,.64,1) both;
}
.generation-result-title {
  margin: 0 0 0.15rem;
  color: var(--success);
  font-size: 1rem;
  font-weight: 800;
}
.generation-result-subtitle {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.82rem;
}
.generation-result-actions {
  position: relative;
  z-index: 1;
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  margin-top: 0.95rem;
}
.btn-open-document {
  box-shadow: 0 8px 22px rgba(2,122,72,0.28);
}

/* ═══════════════════════════════════════════════════════════════════════════════
   BUSCADOR DE HISTORIAL
   ═══════════════════════════════════════════════════════════════════════════════ */
.search-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  transition: var(--transition);
}
.search-bar:focus-within { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.search-bar input {
  border: none !important;
  background: transparent !important;
  outline: none !important;
  box-shadow: none !important;
  flex: 1;
  font-family: var(--font);
  font-size: 0.88rem;
  color: var(--text-main);
  padding: 0;
}
.search-bar input:focus {
  border: none !important;
  box-shadow: none !important;
}
.search-bar .search-icon { color: var(--text-faint); font-size: 1rem; }

/* ═══════════════════════════════════════════════════════════════════════════════
   UPLOAD DE ARCHIVOS (zona de arrastre)
   ═══════════════════════════════════════════════════════════════════════════════ */
.drop-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius-md);
  padding: 2rem;
  text-align: center;
  cursor: pointer;
  transition: var(--transition);
  background: var(--surface-glass);
}
.drop-zone:hover, .drop-zone.drag-over {
  border-color: var(--primary);
  background: var(--primary-soft);
}
.drop-zone .drop-icon { font-size: 2rem; margin-bottom: 0.5rem; opacity: 0.6; }
.drop-zone p { font-size: 0.85rem; color: var(--text-muted); }
.drop-zone strong { color: var(--primary); }

/* ═══════════════════════════════════════════════════════════════════════════════
   SECCIÓN VACÍA (empty state)
   ═══════════════════════════════════════════════════════════════════════════════ */
.empty-state {
  text-align: center;
  padding: 4rem 2rem;
  color: var(--text-muted);
}
.empty-state .empty-icon { font-size: 3rem; margin-bottom: 1rem; opacity: 0.4; }
.empty-state h4 { font-size: 1rem; color: var(--text-main); margin-bottom: 0.5rem; }
.empty-state p { font-size: 0.85rem; }

/* ═══════════════════════════════════════════════════════════════════════════════
   TABS (pestañas dentro de página)
   ═══════════════════════════════════════════════════════════════════════════════ */
.tabs {
  display: flex;
  gap: 4px;
  background: var(--surface-glass);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-md);
  padding: 4px;
  width: fit-content;
}
.tab-btn {
  padding: 7px 18px;
  border-radius: calc(var(--radius-md) - 2px);
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  border: none;
  background: transparent;
  transition: var(--transition);
  font-family: var(--font);
}
.tab-btn.active {
  background: var(--bg-card);
  color: var(--primary);
  font-weight: 600;
  box-shadow: var(--shadow-sm);
}

/* ═══════════════════════════════════════════════════════════════════════════════
   ANIMACIONES
   ═══════════════════════════════════════════════════════════════════════════════ */
@keyframes fadeSlideUp {
  from { opacity: 0; transform: translateY(18px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes fadeIn {
  from { opacity: 0; } to { opacity: 1; }
}
@keyframes toastIn {
  from { opacity: 0; transform: scale(0.85); }
  to   { opacity: 1; transform: scale(1); }
}
@keyframes spin {
  to { transform: rotate(360deg); }
}
@keyframes shake {
  0%,100% { transform: translateX(0); }
  25%      { transform: translateX(-4px); }
  75%      { transform: translateX(4px); }
}
@keyframes pulse {
  0%,100% { opacity: 0.6; } 50% { opacity: 1; }
}

@keyframes docButtonSheen {
  0%, 42% { transform: translateX(-125%); }
  68%, 100% { transform: translateX(125%); }
}
@keyframes generateButtonPulse {
  0%, 100% { box-shadow: 0 10px 26px rgba(79,70,229,0.30), 0 0 0 0 rgba(99,102,241,0.36); }
  50% { box-shadow: 0 16px 38px rgba(79,70,229,0.44), 0 0 0 8px rgba(99,102,241,0); }
}
@keyframes premiumReveal {
  from { opacity: 0; transform: translateY(10px) scale(0.985); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes progressShimmer {
  0% { transform: translateX(-110%); }
  65%, 100% { transform: translateX(110%); }
}
@keyframes progressBarGlow {
  from { transform: translateX(-100%); }
  to { transform: translateX(100%); }
}
@keyframes generateOrbPulse {
  0%, 100% { transform: scale(1); box-shadow: 0 0 0 7px rgba(79,70,229,0.10), 0 0 24px rgba(79,70,229,0.42); }
  50% { transform: scale(1.06); box-shadow: 0 0 0 11px rgba(6,182,212,0.08), 0 0 30px rgba(6,182,212,0.46); }
}
@keyframes documentWowIn {
  0% { opacity: 0; transform: translateY(16px) scale(0.96); filter: blur(4px); }
  58% { opacity: 1; transform: translateY(-3px) scale(1.015); filter: blur(0); }
  100% { opacity: 1; transform: translateY(0) scale(1); filter: blur(0); }
}
@keyframes successPop {
  0% { transform: scale(0.55) rotate(-12deg); opacity: 0; }
  70% { transform: scale(1.12) rotate(3deg); opacity: 1; }
  100% { transform: scale(1) rotate(0); opacity: 1; }
}
@keyframes successSparkle {
  0% { opacity: 0; transform: translateY(10px) rotate(0deg) scale(0.9); }
  18% { opacity: 1; }
  100% { opacity: 0; transform: translateY(-18px) rotate(18deg) scale(1.08); }
}

/* ═══════════════════════════════════════════════════════════════════════════════
   RESPONSIVE
   ═══════════════════════════════════════════════════════════════════════════════ */
/* =============================================================================
   SISTEMA RESPONSIVE MOBILE-FIRST — 5 Breakpoints
   sm: 480px | md: 768px | lg: 1024px | xl: 1280px | 2xl: 1440px
   ============================================================================= */

/* ── Touch targets mínimos (44px) ─────────────────────────────────────────── */
.btn { min-height: 44px; }
.nav-item { min-height: 44px; }
.btn-theme, .modal-close, .btn-logout { min-height: 44px; min-width: 44px; }

/* ─── < 480px : Teléfonos muy pequeños (iPhone SE) ───────────────────────── */
@media (max-width: 479px) {
  :root { --sidebar-w: 0px; }

  .sidebar {
    position: fixed;
    left: -290px;
    top: 0;
    height: 100%;
    width: 290px;
    z-index: 200;
    transition: left 0.28s ease;
  }
  .sidebar.open { left: 0; }

  .topbar { padding: 0.7rem 0.9rem; }
  .topbar-title h2 { font-size: 0.95rem; }
  .topbar-title p { display: none; }

  .page-content { padding: 0.8rem; padding-bottom: 80px; }
  .card { padding: 1rem; }

  .split-2, .split-3 { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: 1fr; }

  #btn-menu-mobile { display: flex; }

  .generation-result-actions { flex-direction: column; align-items: stretch; }
  .generation-result-actions .btn { width: 100%; }

  .emitir-columns { gap: 1rem; }
  .emitir-column-params { border-right: none !important; padding-right: 0 !important; }

  /* Tabla responsive: card mode */
  .table-wrap { border: none; overflow-x: visible; }
  table thead { display: none; }
  table, tbody, tr, td { display: block; width: 100%; }
  tbody tr {
    background: var(--bg-card);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-md);
    margin-bottom: 0.75rem;
    padding: 0.9rem;
    box-shadow: var(--shadow-sm);
  }
  tbody tr:last-child td { border-bottom: 1px solid var(--border-glass); }
  td {
    padding: 0.3rem 0;
    border-bottom: none;
    display: flex;
    gap: 0.5rem;
    align-items: center;
    font-size: 0.85rem;
  }
  td::before {
    content: attr(data-label);
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-faint);
    min-width: 80px;
    flex-shrink: 0;
  }
  td:empty { display: none; }
  /* Acciones al final del card */
  td:last-child {
    margin-top: 0.5rem;
    padding-top: 0.6rem;
    border-top: 1px solid var(--border-glass);
    gap: 0.5rem;
    flex-wrap: wrap;
  }
  td:last-child::before { display: none; }

  /* WIZARD MÓVIL */
  .wizard-header { display: block !important; margin-bottom: 1.5rem; padding-bottom: 1rem; border-bottom: 1px solid var(--border-glass); }
  .wizard-steps { display: flex; align-items: center; justify-content: space-between; max-width: 300px; margin: 0 auto; }
  .wizard-step { display: flex; align-items: center; gap: 8px; font-size: 0.85rem; font-weight: 600; color: var(--text-muted); transition: var(--transition); }
  .wizard-step.active { color: var(--primary); }
  .wizard-step .w-num { width: 24px; height: 24px; border-radius: 50%; background: var(--surface-glass); display: flex; align-items: center; justify-content: center; font-size: 0.75rem; }
  .wizard-step.active .w-num { background: var(--primary); color: #fff; }
  .wizard-line { flex: 1; height: 2px; background: var(--border-glass); margin: 0 15px; }
  .wizard-actions { display: block; margin-top: 1.5rem; }
  .wizard-actions-top { margin-top: 0; margin-bottom: 1rem; }
  
  .emitir-columns { display: block; }
  .emitir-column-editor { display: none; }
  .emitir-columns.step-2 .emitir-column-params { display: none; }
  .emitir-columns.step-2 .emitir-column-editor { display: block; }
}

/* ─── 480px – 767px : Teléfonos medianos y grandes ────────────────────────── */
@media (min-width: 480px) and (max-width: 767px) {
  :root { --sidebar-w: 0px; }

  .sidebar {
    position: fixed;
    left: -290px;
    top: 0;
    height: 100%;
    width: 290px;
    z-index: 200;
    transition: left 0.28s ease;
  }
  .sidebar.open { left: 0; }

  .topbar { padding: 0.8rem 1.1rem; }
  .page-content { padding: 1rem; padding-bottom: 80px; }

  .split-2, .split-3 { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: 1fr 1fr; }

  #btn-menu-mobile { display: flex; }

  /* Tabla responsive: card mode */
  .table-wrap { border: none; overflow-x: visible; }
  table thead { display: none; }
  table, tbody, tr, td { display: block; width: 100%; }
  tbody tr {
    background: var(--bg-card);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-md);
    margin-bottom: 0.75rem;
    padding: 0.9rem;
    box-shadow: var(--shadow-sm);
  }
  tbody tr:last-child td { border-bottom: 1px solid var(--border-glass); }
  td {
    padding: 0.3rem 0;
    border-bottom: none;
    display: flex;
    gap: 0.5rem;
    align-items: center;
  }
  td::before {
    content: attr(data-label);
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-faint);
    min-width: 85px;
    flex-shrink: 0;
  }
  td:empty { display: none; }
  td:last-child {
    margin-top: 0.5rem;
    padding-top: 0.6rem;
    border-top: 1px solid var(--border-glass);
    gap: 0.5rem;
    flex-wrap: wrap;
  }
  td:last-child::before { display: none; }

  .generation-result-actions { flex-direction: column; align-items: stretch; }
  .generation-result-actions .btn { width: 100%; }

  /* WIZARD MÓVIL */
  .wizard-header { display: block !important; margin-bottom: 1.5rem; padding-bottom: 1rem; border-bottom: 1px solid var(--border-glass); }
  .wizard-steps { display: flex; align-items: center; justify-content: space-between; max-width: 300px; margin: 0 auto; }
  .wizard-step { display: flex; align-items: center; gap: 8px; font-size: 0.85rem; font-weight: 600; color: var(--text-muted); transition: var(--transition); }
  .wizard-step.active { color: var(--primary); }
  .wizard-step .w-num { width: 24px; height: 24px; border-radius: 50%; background: var(--surface-glass); display: flex; align-items: center; justify-content: center; font-size: 0.75rem; }
  .wizard-step.active .w-num { background: var(--primary); color: #fff; }
  .wizard-line { flex: 1; height: 2px; background: var(--border-glass); margin: 0 15px; }
  .wizard-actions { display: block; margin-top: 1.5rem; }
  .wizard-actions-top { margin-top: 0; margin-bottom: 1rem; }
  
  .emitir-columns { display: block; }
  .emitir-column-editor { display: none; }
  .emitir-columns.step-2 .emitir-column-params { display: none; }
  .emitir-columns.step-2 .emitir-column-editor { display: block; }
}

/* ─── 768px – 1023px : iPad y tablets ─────────────────────────────────────── */
@media (min-width: 768px) and (max-width: 1023px) {
  :root { --sidebar-w: 70px; }

  /* Sidebar colapsado (solo iconos) */
  .sidebar {
    width: 70px;
    padding: 1.2rem 0.6rem;
    overflow: visible;
  }
  .sidebar-brand .brand-text,
  .nav-group-label,
  .nav-item span,
  .sidebar-footer .user-info-text,
  .user-card { display: none; }
  .nav-badge { display: none; }

  /* Ocultar el badge de plan en sidebar en tablet (poco espacio) */
  #sidebar-plan-badge { display: none !important; }

  /* Botones footer del sidebar en modo icono */
  .sidebar-footer { padding: 0.5rem 0; gap: 4px; }
  .btn-logout {
    width: 44px;
    height: 44px;
    min-width: 44px;
    min-height: 44px;
    padding: 0;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-md);
    position: relative;
  }
  .btn-logout svg { flex-shrink: 0; }
  /* Tooltip para botones del footer */
  .btn-logout:hover::after {
    content: attr(title);
    position: absolute;
    left: calc(100% + 10px);
    top: 50%;
    transform: translateY(-50%);
    background: var(--bg-card);
    border: 1px solid var(--border-glass);
    color: var(--text-main);
    padding: 6px 10px;
    border-radius: var(--radius-sm);
    font-size: 0.8rem;
    white-space: nowrap;
    z-index: 300;
    box-shadow: var(--shadow-md);
  }

  .nav-item {
    justify-content: center;
    padding: 10px;
    border-radius: var(--radius-md);
    position: relative;
  }
  /* Tooltip al hacer hover en modo colapsado */
  .nav-item[data-tooltip]:hover::after {
    content: attr(data-tooltip);
    position: absolute;
    left: calc(100% + 10px);
    top: 50%;
    transform: translateY(-50%);
    background: var(--bg-card);
    border: 1px solid var(--border-glass);
    color: var(--text-main);
    padding: 6px 10px;
    border-radius: var(--radius-sm);
    font-size: 0.8rem;
    white-space: nowrap;
    z-index: 300;
    box-shadow: var(--shadow-md);
  }

  .brand-icon { margin: 0 auto; }
  .sidebar-brand { justify-content: center; padding: 0.4rem 0 1.5rem; }

  .page-content { padding: 1.4rem; }
  .split-2 { grid-template-columns: 1fr 1fr; }
  .split-3 { grid-template-columns: 1fr 1fr; }
  .stats-grid { grid-template-columns: 1fr 1fr; }

  #btn-menu-mobile { display: none; }
  #bottom-nav { display: none !important; }
}

/* ─── ≥ 1024px : Desktop normal ────────────────────────────────────────────── */
@media (min-width: 1024px) {
  :root { --sidebar-w: 270px; }
  #btn-menu-mobile { display: none; }
  #bottom-nav { display: none !important; }
  .page-content { padding: 2rem; }
  .split-2 { grid-template-columns: 1fr 1fr; }
  .split-3 { grid-template-columns: 1fr 1fr 1fr; }
  .stats-grid { grid-template-columns: repeat(4, 1fr); }
}

/* ─── ≥ 1280px : Desktop grande ────────────────────────────────────────────── */
@media (min-width: 1280px) {
  :root { --sidebar-w: 290px; }
  .page-content { padding: 2.5rem; }
}

/* ─── Compatibilidad con modo mobile anterior ─────────────────────────────── */
#btn-menu-mobile {
  display: none;
}

.sidebar-backdrop {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.5);
  z-index: 150;
  backdrop-filter: blur(2px);
  opacity: 0;
  transition: opacity 0.3s ease;
}
.sidebar-backdrop.show {
  display: block;
  opacity: 1;
}

body.dark input[type="date"] { color-scheme: dark; }
body:not(.dark) input[type="date"] { color-scheme: light; }

/* =============================================================================
   BOTTOM NAVIGATION BAR — Solo visible en < 768px
   ============================================================================= */
#bottom-nav {
  display: none; /* oculto por defecto; JS lo muestra en móvil */
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 64px;
  background: var(--bg-sidebar);
  border-top: 1px solid var(--border-glass);
  z-index: 180;
  padding: 0 0.25rem;
  align-items: stretch;
  justify-content: space-around;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  box-shadow: 0 -4px 16px rgba(0,0,0,0.12);
  /* Safe area para notch de iPhone */
  padding-bottom: env(safe-area-inset-bottom, 0);
  box-sizing: content-box;
}

@media (max-width: 767px) {
  #bottom-nav { display: flex; }
}

.bottom-nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  flex: 1;
  padding: 6px 4px;
  cursor: pointer;
  border: none;
  background: none;
  color: var(--text-faint);
  font-family: var(--font);
  font-size: 0.62rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  transition: color 0.2s ease;
  border-radius: var(--radius-md);
  user-select: none;
  -webkit-user-select: none;
  position: relative;
  min-height: 48px;
}
.bottom-nav-item:active { opacity: 0.6; }
.bottom-nav-item.active {
  color: var(--primary);
}
.bottom-nav-item.active .bnav-icon {
  background: var(--primary-soft);
  transform: translateY(-2px);
}
.bnav-icon {
  width: 36px;
  height: 32px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.15rem;
  transition: background 0.2s, transform 0.2s;
}
.bnav-badge {
  position: absolute;
  top: 4px;
  right: calc(50% - 26px);
  background: var(--danger);
  color: #fff;
  font-size: 0.6rem;
  font-weight: 700;
  padding: 1px 5px;
  border-radius: 10px;
  min-width: 16px;
  text-align: center;
}

/* =============================================================================
   CAPA DE PULIDO UI/UX PREMIUM — Consistencia responsive DOCTRIX
   ============================================================================= */
.page-content {
  max-width: 1440px;
  margin-inline: auto;
}

.page-content.active {
  animation: fadeSlideUp 0.28s ease both;
}

.topbar,
.sidebar,
.modal,
.modal-content,
.card,
.table-wrap,
.bottom-nav-item,
.search-bar,
input,
select,
textarea,
.field-locked,
.profile-info-value {
  backdrop-filter: saturate(1.15) blur(var(--blur));
  -webkit-backdrop-filter: saturate(1.15) blur(var(--blur));
}

.card,
.stat-card,
.pricing-card,
.modal,
.modal-content {
  box-shadow: var(--shadow-sm);
}

.card:hover,
.pricing-card:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="date"],
input[type="number"],
select,
textarea,
.search-bar,
.field-locked,
.profile-info-value {
  background: var(--bg-input);
  min-height: 44px;
}

body:not(.dark) input[type="text"],
body:not(.dark) input[type="email"],
body:not(.dark) input[type="password"],
body:not(.dark) input[type="date"],
body:not(.dark) input[type="number"],
body:not(.dark) select,
body:not(.dark) textarea,
body:not(.dark) .search-bar {
  --input-bg: #f8fafc;
}

label,
.form-section-title,
th,
.tab-btn,
.bottom-nav-item span,
.nav-group-label {
  letter-spacing: 0.015em;
}

.form-section-title {
  margin-top: var(--space-lg);
  padding-bottom: var(--space-sm);
}

.input-block small,
.text-muted,
small {
  color: var(--text-muted);
}

.btn {
  border-radius: var(--radius-md);
  box-shadow: none;
}

.btn-primary,
.btn-ia {
  box-shadow: 0 8px 20px var(--primary-glow);
}

.btn-primary:hover,
.btn-ia:hover,
.btn-success:hover,
.btn-danger:hover,
.btn-outline-primary:hover {
  transform: translateY(-1px);
}

.table-wrap {
  background: var(--bg-card);
}

thead {
  position: sticky;
  top: 0;
  z-index: 1;
  backdrop-filter: blur(var(--blur));
}

tbody tr {
  transition: background 0.18s ease, transform 0.18s ease;
}

tbody tr:hover {
  background: var(--surface-glass-hover);
}

td[data-label="Acciones"],
td:last-child[style*="flex"] {
  align-items: center;
}

.filters-container,
.filters-panel,
.admin-toolbar,
.document-summary-box,
.preview-chip,
.plan-badge {
  border: 1px solid var(--border-glass) !important;
  border-radius: var(--radius-lg) !important;
  background: var(--surface-glass) !important;
}

#preview-nomenclatura,
.preview-chip,
.td-nomen,
code {
  border-radius: var(--radius-sm) !important;
}

.modal-header {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--bg-card);
}

.modal-close {
  border-radius: 999px;
}

.empty-state {
  border-radius: var(--radius-lg);
}

.empty-state .empty-icon,
.card-icon,
.stat-icon-wrap,
.drop-icon,
.firma-icon,
.search-icon,
.toast-icon,
.bnav-icon {
  filter: saturate(0.85);
}

/* Sidebar tablet: tooltip visible también con foco para teclado */
@media (min-width: 768px) and (max-width: 1023px) {
  :root { --sidebar-w: 84px; }
  .sidebar { width: 84px; padding-inline: 0.7rem; }
  .nav-item { min-height: 52px; }
  .nav-item:focus-visible::after,
  .nav-item[data-tooltip]:hover::after {
    content: attr(data-tooltip);
  }
  .nav-item:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
  }
}

/* Bottom nav más institucional y limpio en móvil */
@media (max-width: 767px) {
  #bottom-nav {
    height: 68px;
    padding-inline: 0.5rem;
    background: var(--bg-sidebar);
    background: color-mix(in srgb, var(--bg-sidebar) 92%, transparent);
    box-shadow: 0 -10px 30px rgba(15,23,42,0.10);
  }

  .bottom-nav-item {
    text-transform: none;
    font-size: 0.68rem;
    letter-spacing: 0;
    border-radius: 16px;
    margin-block: 6px;
  }

  .bottom-nav-item.active {
    background: var(--primary-soft);
  }

  .bottom-nav-item.active .bnav-icon {
    background: transparent;
    transform: translateY(-1px) scale(1.03);
  }

  .wizard-header {
    position: sticky;
    top: 0;
    z-index: 10;
    background: var(--bg-card);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-lg);
    padding: 0.85rem !important;
    box-shadow: var(--shadow-sm);
  }

  #botones-generar-wrap {
    position: sticky;
    bottom: calc(68px + env(safe-area-inset-bottom, 0px) + 0.6rem);
    z-index: 20;
    padding: 0.75rem;
    margin-inline: -0.25rem;
    border-radius: var(--radius-lg);
    background: var(--bg-card);
    background: color-mix(in srgb, var(--bg-card) 92%, transparent);
    border: 1px solid var(--border-glass);
    box-shadow: var(--shadow-lg);
    backdrop-filter: blur(var(--blur));
  }

  td:not([data-label])::before {
    display: none;
  }
}

/* ═══════════════════════════════════════════════════════════════════════════════
   SELECTOR TIPO FIRMA
   ═══════════════════════════════════════════════════════════════════════════════ */
.firma-tipo-selector {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.8rem;
  margin-bottom: 1rem;
}

.firma-tipo-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 1rem;
  border: 2px solid var(--border);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: var(--transition);
  background: var(--bg-card);
  text-align: center;
  font-weight: 500;
  color: var(--text-muted);
  font-size: 0.9rem;
  user-select: none;
}

.firma-tipo-btn input[type="radio"] {
  display: none;
}

.firma-tipo-btn .firma-icon {
  font-size: 1.6rem;
  margin-bottom: 0.2rem;
}

.firma-tipo-btn small {
  font-size: 0.75rem;
  color: var(--text-faint);
  font-weight: 400;
}

.firma-tipo-btn:hover {
  border-color: var(--primary);
  background: var(--primary-soft);
  color: var(--primary);
}

.firma-tipo-btn.active {
  border-color: var(--primary);
  background: var(--primary-soft);
  color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-glow);
}

.firma-tipo-btn.active small {
  color: var(--primary);
  opacity: 0.8;
}

/* Info box de firma que se muestra quien firmara */
.firma-info-box {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.7rem 1rem;
  background: var(--primary-soft);
  border: 1px solid var(--primary-glow);
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  color: var(--primary);
  margin-bottom: 0.5rem;
}

.firma-info-box .firma-info-icon {
  font-size: 1.2rem;
  flex-shrink: 0;
}

/* ─── CORRECCIONES ADICIONALES PARA DISPOSITIVOS MÓVILES (<= 767px) ────────── */
@media (max-width: 767px) {
  /* 1. Encabezado de Tarjetas y Botones (Conectar y Guardar) */
  .card-header {
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 0.75rem !important;
  }
  .card-header h3 {
    margin-bottom: 0.2rem;
  }
  .card-header > div {
    display: flex !important;
    gap: 0.5rem !important;
    flex-wrap: wrap !important;
    width: 100% !important;
    justify-content: stretch !important;
  }
  .card-header > div .btn {
    flex: 1 !important;
    min-width: 120px !important;
    margin-right: 0 !important; /* Eliminar el margen derecho inline */
  }

  /* 2. Celdas de Tabla y Alineación de Valores */
  td {
    justify-content: space-between !important;
  }
  td:last-child {
    justify-content: flex-end !important;
  }

  /* Evitar desbordamiento de nomenclaturas largas */
  .td-nomen {
    font-size: 0.75rem !important;
    white-space: normal !important;
    word-break: break-all !important;
    text-align: right !important;
    max-width: 200px !important;
  }

  /* 3. Organización de Correlativos en Admin */
  td.td-seq-title {
    font-size: 0.95rem !important;
    border-bottom: 1px solid var(--border-glass) !important;
    margin-bottom: 0.5rem !important;
    padding-bottom: 0.5rem !important;
    color: var(--primary) !important;
    justify-content: flex-start !important;
    font-weight: 700 !important;
  }
  td.td-seq-title::before {
    display: none !important;
  }
}

/* ═══════════════════════════════════════════════════════════════════════════════
   PANTALLA PERFIL
   ═══════════════════════════════════════════════════════════════════════════════ */
.profile-info-value {
  padding: 0.6rem 0.8rem;
  background: var(--bg-hover);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-sm);
  color: var(--text-main);
  font-weight: 500;
  font-size: 0.9rem;
}

/* ═══════════════════════════════════════════════════════════════════════════════
   HARDENING RESPONSIVE MÓVIL — evita desbordes en pantallas pequeñas
   ═══════════════════════════════════════════════════════════════════════════════ */

/* Base anti-overflow para textos largos, badges, botones y contenidos dinámicos */
#app,
.main-area,
.page-content,
.card,
.modal,
.modal-content,
.table-wrap,
.input-block,
.field-locked,
.search-bar,
.tabs,
.pricing-card,
.stat-card,
.generation-result-card {
  min-width: 0;
}

.card,
.modal,
.modal-content,
td,
.profile-info-value,
.field-locked,
.badge,
.toast,
.generation-result-title,
.generation-result-subtitle {
  overflow-wrap: anywhere;
  word-break: normal;
}

/* Los elementos embebidos nunca deben empujar el viewport */
img,
svg,
canvas,
video,
iframe {
  max-width: 100%;
}

@media (max-width: 767px) {
  html,
  body {
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
  }

  #app.visible {
    width: 100%;
    max-width: 100vw;
  }

  .main-area {
    width: 100%;
    max-width: 100vw;
  }

  .page-content {
    width: 100%;
    max-width: 100vw;
    gap: 1rem;
  }

  .card {
    width: 100%;
    max-width: 100%;
    border-radius: 14px;
  }

  /* Topbar: conserva título y acciones sin romper el ancho */
  .topbar {
    width: 100%;
    min-width: 0;
    align-items: center;
  }

  .topbar > div:first-child {
    min-width: 0;
    flex: 1 1 auto;
  }

  .topbar-title {
    min-width: 0;
  }

  .topbar-title h2 {
    max-width: 52vw;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .topbar-actions {
    flex: 0 0 auto;
    min-width: 0;
    gap: 6px;
  }

  /* En celular el plan completo queda en el sidebar; en topbar ocupa demasiado */
  #topbar-plan-badge {
    display: none !important;
  }

  /* Login y opciones: que no queden apretadas en iPhone SE */
  #login-screen {
    align-items: flex-start;
    padding: 1rem;
    overflow-y: auto;
  }

  .login-card {
    padding: 1.6rem 1.15rem;
    border-radius: 18px;
    margin: auto 0;
  }

  .login-logo {
    align-items: center;
    flex-wrap: wrap;
    margin-bottom: 1.4rem;
  }

  .login-options {
    flex-direction: column;
    align-items: stretch;
    gap: 0.45rem;
  }

  .login-support {
    text-align: left;
  }

  /* Formularios y grids: neutraliza columnas o anchos fijos inline */
  .split-2,
  .split-3,
  .campo-dinamico-row,
  .subunidad-row {
    grid-template-columns: 1fr !important;
  }

  .filters-container,
  #bloque-lote > div:first-child,
  #botones-generar-wrap,
  .modal-footer,
  #modal-confirmacion-generico .modal > div:last-child,
  #modal-confirmacion .modal > div:last-child {
    flex-direction: column !important;
    align-items: stretch !important;
  }

  .filters-container > *,
  .filters-container .search-bar,
  #inp-fecha-historial,
  #inp-tipo-historial,
  #botones-generar-wrap .btn,
  #bloque-lote .btn,
  .modal-footer .btn,
  #modal-confirmacion-generico .btn,
  #modal-confirmacion .btn {
    width: 100% !important;
    min-width: 0 !important;
  }

  .btn {
    white-space: normal;
    text-align: center;
    line-height: 1.25;
  }

  .btn-sm {
    padding-left: 12px;
    padding-right: 12px;
  }

  /* El wizard móvil necesita sobreescribir el ocultamiento desktop con !important */
  .wizard-actions-mobile-only {
    display: block !important;
  }

  /* Modales nuevos y antiguos como bottom sheet real */
  .modal-backdrop,
  .modal-overlay {
    align-items: flex-end !important;
    justify-content: center !important;
    padding: 0 !important;
  }

  .modal,
  .modal-content {
    width: 100% !important;
    max-width: 100% !important;
    max-height: 92dvh;
    border-radius: var(--radius-xl) var(--radius-xl) 0 0 !important;
    border-bottom: none;
    padding: 1.45rem 1.05rem calc(1.6rem + env(safe-area-inset-bottom, 0px)) !important;
    overflow-y: auto;
    animation: bottomSheetUp 0.32s cubic-bezier(0.32, 0.72, 0, 1) both;
  }

  .modal-header {
    gap: 0.75rem;
    align-items: flex-start;
  }

  .modal-header h2,
  .modal-header h3 {
    font-size: 1.05rem !important;
    line-height: 1.25;
  }

  /* Drop zones y previews de imágenes */
  .drop-zone,
  .logo-upload-box,
  label.drop-zone {
    width: 100% !important;
    max-width: 100% !important;
    padding: 1rem !important;
  }

  #logo-preview,
  #firma-preview-box,
  #op-firma-preview,
  #prof-firma-preview {
    max-width: 100% !important;
  }

  /* Quill: herramientas envolventes y editor más cómodo en móvil */
  .ql-toolbar.ql-snow {
    white-space: normal;
  }

  .ql-toolbar.ql-snow .ql-formats {
    margin-right: 6px !important;
    margin-bottom: 4px;
  }

  .ql-container,
  .ql-editor {
    min-height: 220px !important;
  }

  /* Firma: dos tarjetas se vuelven una bajo la otra */
  .firma-tipo-selector {
    grid-template-columns: 1fr !important;
  }

  .firma-info-box {
    align-items: flex-start;
  }

  /* Tabs: si no caben, hacen scroll horizontal controlado */
  .tabs {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .tab-btn {
    flex: 1 0 auto;
    white-space: nowrap;
  }

  /* Tablas en modo tarjeta: corrige celdas con estilos inline de desktop */
  .table-wrap,
  div[style*="overflow-x:auto"] {
    width: 100%;
    max-width: 100%;
    overflow-x: visible !important;
  }

  table {
    table-layout: fixed;
  }

  tbody tr {
    overflow: hidden;
  }

  td,
  td[style] {
    max-width: none !important;
    white-space: normal !important;
    overflow: visible !important;
    text-overflow: clip !important;
  }

  td::before {
    min-width: 92px;
    max-width: 42%;
  }

  td > *:not(:first-child),
  td > span,
  td > a,
  td > button,
  td > div {
    min-width: 0;
  }

  td:last-child .btn,
  td[data-label="Acciones"] .btn {
    flex: 1 1 120px;
  }

  /* Admin centro: acciones superiores y conexión Drive */
  #drive-connection-container {
    align-items: stretch !important;
    width: 100%;
  }

  #drive-connected-options {
    text-align: left !important;
  }

  .card-header div[style*="width:1px"] {
    display: none !important;
  }

  /* Secciones de precios/billing con grid fijo en el HTML */
  #page-root-pagos div[style*="grid-template-columns:repeat(4,1fr)"] {
    grid-template-columns: 1fr !important;
  }

  #page-root-pagos div[style*="grid-template-columns:repeat(auto-fit"] {
    grid-template-columns: 1fr !important;
  }

  .pricing-grid {
    grid-template-columns: 1fr !important;
  }

  /* Vista previa de nomenclaturas largas */
  #preview-nomenclatura,
  #pl-preview-modal,
  #pl-preview-distrito,
  code {
    white-space: normal !important;
    overflow-wrap: anywhere;
  }

  .empty-state {
    padding: 2.2rem 1rem;
  }
}

@media (max-width: 360px) {
  .page-content {
    padding-left: 0.65rem;
    padding-right: 0.65rem;
  }

  .card {
    padding: 0.85rem;
  }

  .topbar-title h2 {
    max-width: 46vw;
  }

  .wizard-step {
    font-size: 0.78rem !important;
    gap: 5px !important;
  }

  .wizard-line {
    margin: 0 8px !important;
  }

  td {
    flex-direction: column;
    align-items: flex-start !important;
    justify-content: flex-start !important;
  }

  td::before {
    min-width: 0;
    max-width: 100%;
  }

  td:last-child,
  td[data-label="Acciones"] {
    align-items: stretch !important;
  }
}

