/* ============================================================
   MICRO SAAS — Estilos compartidos
   Todos los módulos importan este archivo.
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=DM+Sans:wght@400;500;600;700;800&family=DM+Mono:wght@400;500&display=swap');

/* ── Variables ─────────────────────────────────────────────── */
:root {
  --bg:           #f0f2f7;
  --panel:        #ffffff;
  --panel-2:      #f8fafc;
  --text:         #0f172a;
  --muted:        #64748b;
  --line:         #e2e8f0;
  --primary:      #2563eb;
  --primary-soft: #dbeafe;
  --success:      #16a34a;
  --success-soft: #dcfce7;
  --warning:      #d97706;
  --warning-soft: #fef3c7;
  --danger:       #dc2626;
  --danger-soft:  #fee2e2;
  --sidebar-bg:   #0f172a;
  --shadow:       0 8px 24px rgba(15,23,42,.08);
  --shadow-lg:    0 20px 48px rgba(15,23,42,.12);
  --radius:       18px;
  --radius-sm:    12px;
  --font:         'DM Sans', system-ui, sans-serif;
  --font-mono:    'DM Mono', monospace;
}

/* ── Reset ─────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; }
img { display: block; max-width: 100%; }

/* ── Layout principal ──────────────────────────────────────── */
.app {
  display: grid;
  grid-template-columns: 256px 1fr;
  min-height: 100vh;
}

/* ── Sidebar ───────────────────────────────────────────────── */
.sidebar {
  background: var(--sidebar-bg);
  color: #fff;
  padding: 24px 16px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 4px 8px 16px;
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.brand-logo {
  width: 38px;
  height: 38px;
  border-radius: 12px;
  background: linear-gradient(135deg, #3b82f6, #1d4ed8);
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 17px;
  box-shadow: 0 6px 16px rgba(37,99,235,.35);
  flex-shrink: 0;
}
.brand-text strong { display: block; font-size: 15px; font-weight: 700; }
.brand-text small  { color: #94a3b8; font-size: 12px; }

.nav { display: flex; flex-direction: column; gap: 4px; }
.nav a {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 14px;
  border-radius: var(--radius-sm);
  color: #cbd5e1;
  font-size: 14px;
  font-weight: 500;
  transition: background .15s, color .15s;
}
.nav a:hover, .nav a.active {
  background: rgba(255,255,255,.08);
  color: #fff;
}
.nav a.active { font-weight: 700; }
.nav-icon { font-size: 17px; flex-shrink: 0; }

.sidebar-footer {
  margin-top: auto;
  background: rgba(255,255,255,.05);
  border: 1px solid rgba(255,255,255,.08);
  border-radius: var(--radius-sm);
  padding: 14px;
  font-size: 12px;
  line-height: 1.55;
  color: #94a3b8;
}
.sidebar-footer strong { display: block; color: #cbd5e1; margin-bottom: 6px; font-size: 13px; }

/* ── Contenido principal ───────────────────────────────────── */
.content { padding: 28px; }

/* ── Topbar ────────────────────────────────────────────────── */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}
.page-title h1 { margin: 0; font-size: 28px; font-weight: 800; letter-spacing: -.03em; }
.page-title p  { margin: 6px 0 0; color: var(--muted); font-size: 14px; }
.topbar-actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-start; }

/* ── Botones ───────────────────────────────────────────────── */
.btn {
  border: none;
  border-radius: var(--radius-sm);
  padding: 11px 16px;
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
  transition: transform .15s, box-shadow .15s, opacity .15s;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0); }

.btn-primary  { background: var(--primary); color: #fff; box-shadow: 0 6px 16px rgba(37,99,235,.25); }
.btn-success  { background: var(--success); color: #fff; box-shadow: 0 6px 16px rgba(22,163,74,.25); }
.btn-light    { background: #fff; color: var(--text); border: 1px solid var(--line); }
.btn-ghost    { background: transparent; color: var(--primary); border: 1px solid var(--primary-soft); }

/* ── Cards / Panels ────────────────────────────────────────── */
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card-pad { padding: 22px; }

/* ── KPI grid ──────────────────────────────────────────────── */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 22px;
}
.kpi-card { padding: 20px; }
.kpi-label { font-size: 13px; color: var(--muted); font-weight: 600; margin-bottom: 12px; }
.kpi-value { font-size: 28px; font-weight: 800; letter-spacing: -.04em; line-height: 1; }
.kpi-sub   { margin-top: 8px; font-size: 12px; color: var(--muted); }

/* ── Section title ─────────────────────────────────────────── */
.section-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.section-head h2 { margin: 0; font-size: 18px; font-weight: 700; }
.section-head p  { margin: 4px 0 0; color: var(--muted); font-size: 13px; }
.ghost-link { color: var(--primary); font-size: 13px; font-weight: 700; white-space: nowrap; }

/* ── Tabla ─────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius-sm); }
table { width: 100%; border-collapse: collapse; background: #fff; }
th, td { padding: 13px 14px; text-align: left; border-bottom: 1px solid var(--line); font-size: 14px; vertical-align: middle; }
th { background: #f8fafc; color: #334155; font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .03em; position: sticky; top: 0; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: #fafcff; }

/* ── Badges / Pills ────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 5px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}
.badge-success  { background: var(--success-soft); color: #166534; }
.badge-warning  { background: var(--warning-soft); color: #92400e; }
.badge-danger   { background: var(--danger-soft); color: #991b1b; }
.badge-primary  { background: var(--primary-soft); color: #1d4ed8; }
.badge-neutral  { background: #e2e8f0; color: #334155; }

/* ── Formularios ───────────────────────────────────────────── */
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; }
.field { display: grid; gap: 7px; }
.field.full { grid-column: 1 / -1; }
label { font-size: 13px; font-weight: 600; color: #374151; }
input[type=text], input[type=number], input[type=url], input[type=date],
input[type=email], select, textarea {
  width: 100%;
  padding: 11px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #fff;
  color: var(--text);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus {
  border-color: #93c5fd;
  box-shadow: 0 0 0 3px rgba(37,99,235,.1);
}
textarea { resize: vertical; min-height: 80px; }

/* ── Modal / Dialog ────────────────────────────────────────── */
dialog {
  border: none;
  border-radius: 22px;
  padding: 0;
  max-width: 680px;
  width: 95%;
  box-shadow: var(--shadow-lg);
}
dialog::backdrop { background: rgba(15,23,42,.5); backdrop-filter: blur(4px); }
.modal-head {
  padding: 18px 22px;
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.modal-head h3 { margin: 0; font-size: 18px; }
.modal-body { padding: 22px; }
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 20px;
  flex-wrap: wrap;
}

/* ── Flash / Alerts ────────────────────────────────────────── */
.flash { display: none; padding: 13px 16px; border-radius: var(--radius-sm); font-size: 14px; font-weight: 600; }
.flash.show { display: block; }
.flash-success { background: var(--success-soft); color: #166534; }
.flash-warning { background: var(--warning-soft); color: #92400e; }
.flash-danger  { background: var(--danger-soft); color: #991b1b; }
.flash-info    { background: var(--primary-soft); color: #1d4ed8; }

.alert-box { border-radius: var(--radius-sm); padding: 13px 16px; font-size: 14px; }
.alert-info    { background: var(--primary-soft); color: #1d4ed8; }
.alert-success { background: var(--success-soft); color: #166534; }
.alert-warning { background: var(--warning-soft); color: #92400e; }
.alert-danger  { background: var(--danger-soft); color: #991b1b; }

/* ── Empty state ───────────────────────────────────────────── */
.empty {
  padding: 24px;
  border: 1px dashed #cbd5e1;
  border-radius: var(--radius-sm);
  background: #f8fafc;
  color: var(--muted);
  text-align: center;
  font-size: 14px;
}

/* ── Bar chart simple ──────────────────────────────────────── */
.bar-row { display: grid; grid-template-columns: 130px 1fr 100px; gap: 12px; align-items: center; font-size: 14px; }
.bar-track { height: 10px; background: var(--line); border-radius: 999px; overflow: hidden; }
.bar-fill  { height: 100%; border-radius: 999px; background: linear-gradient(90deg, var(--primary), #60a5fa); }

/* ── Metric list ───────────────────────────────────────────── */
.metric-list { display: grid; gap: 0; }
.metric-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
}
.metric-row:last-child { border-bottom: none; }

/* ── Tabs ──────────────────────────────────────────────────── */
.tabs { display: flex; gap: 6px; flex-wrap: wrap; }
.tab {
  border: 1px solid var(--line);
  background: #fff;
  color: #334155;
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: background .15s, color .15s;
}
.tab.active, .tab:hover { background: var(--primary-soft); color: var(--primary); border-color: #bfdbfe; }

/* ── Row actions ───────────────────────────────────────────── */
.row-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.mini-btn {
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background .12s;
}
.mini-btn:hover { background: var(--primary-soft); color: var(--primary); border-color: #bfdbfe; }

/* ── Utility ───────────────────────────────────────────────── */
.text-muted   { color: var(--muted); }
.text-success { color: var(--success); }
.text-danger  { color: var(--danger); }
.fw-bold      { font-weight: 700; }
.mt-4         { margin-top: 4px; }
.mt-8         { margin-top: 8px; }
.mt-12        { margin-top: 12px; }
.mt-16        { margin-top: 16px; }
.mt-22        { margin-top: 22px; }

/* ── Responsive ────────────────────────────────────────────── */
@media (max-width: 1100px) {
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: relative; height: auto; flex-direction: row; flex-wrap: wrap; }
  .nav { flex-direction: row; flex-wrap: wrap; }
  .sidebar-footer { display: none; }
  .content { padding: 18px; }
  .form-grid { grid-template-columns: 1fr; }
}
@media (max-width: 600px) {
  .kpi-grid { grid-template-columns: 1fr; }
  .topbar { flex-direction: column; }
  .topbar-actions { width: 100%; justify-content: flex-end; }
}

/* ============================================================
   FIX MÓVIL: Bloqueo de scroll lateral y ajustes de espacio
   ============================================================ */

/* 1. Bloqueo estricto del ancho de la pantalla */
html, body {
  max-width: 100vw;
  overflow-x: hidden;
}

.app {
  max-width: 100vw;
  overflow-x: hidden;
}

/* 2. Las tablas se deslizan por dentro, sin empujar la pantalla */
.table-wrap {
  width: 100%;
  max-width: 100vw;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch; /* Hace que el deslizamiento sea suave en iPhone */
  border: 1px solid var(--line);
}

/* 3. Ajustes de espacio específicos para celulares */
@media (max-width: 900px) {
  /* Reducimos los márgenes enormes en celular para ganar espacio vital */
  .content {
    padding: 12px;
    width: 100%;
    overflow-x: hidden;
  }
  
  .card-pad {
    padding: 14px;
  }

  /* La botonera superior ocupa el ancho total */
  .topbar-actions {
    width: 100%;
    display: flex;
    flex-direction: column; /* Apila los botones de a uno */
    gap: 8px;
  }

  .topbar-actions .btn {
    width: 100%;
    justify-content: center;
  }

  /* Los modales/popups no deben salirse de la pantalla */
  dialog {
    width: 90%;
    margin: auto;
  }

  .form-grid {
    grid-template-columns: 1fr; /* Todo a 1 columna en celulares */
  }
}

/* ==========================================================================
   DISEÑO RESPONSIVE GLOBAL (Móviles y Tablets)
   ========================================================================== */

/* 1. Botón de menú y fondo oscuro (Overlay) por defecto ocultos */
.mobile-toggle { display: none; background: none; border: none; font-size: 26px; cursor: pointer; color: var(--text); padding: 0; margin-right: 15px; }
.sidebar-overlay { display: none; position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,0.6); z-index: 998; backdrop-filter: blur(2px); }

/* Contenedor flexible para tablas largas */
.table-responsive { overflow-x: auto; width: 100%; -webkit-overflow-scrolling: touch; }

/* ── PANTALLAS MEDIANAS (Tablets - hasta 1000px) ── */
@media (max-width: 1000px) {
    /* Apilamos los diseños de múltiples columnas */
    .layout-2col, .three-col, .two-col, .two-col-eq { 
        grid-template-columns: 1fr !important; 
    }
    
    /* Los formularios en línea se dividen a 2 columnas en vez de 3 o 4 */
    .form-grid-horizontal, .checkout-footer { 
        grid-template-columns: 1fr 1fr !important; 
    }
}

/* ── PANTALLAS PEQUEÑAS (Celulares - hasta 768px) ── */
@media (max-width: 768px) {
    /* 1. Transformar el layout principal */
    .app { display: block !important; }
    
    /* 2. Barra lateral (Sidebar) flotante */
    .sidebar { 
        position: fixed !important; 
        left: -300px; /* Oculta por defecto */
        top: 0; 
        height: 100vh !important; 
        width: 260px !important; 
        z-index: 999; 
        flex-direction: column !important; 
        transition: left 0.3s ease; 
        box-shadow: 4px 0 25px rgba(0,0,0,0.5); 
    }
    .sidebar.open { left: 0; }
    .sidebar-overlay.open { display: block; }
    .nav { flex-direction: column !important; }
    
    /* 3. Mostrar el botón hamburguesa */
    .mobile-toggle { display: block; }
    .topbar { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 10px; padding: 15px; }
    .topbar-left { display: flex; align-items: center; }
    .topbar-actions { width: 100%; justify-content: flex-start; }
    
    /* 4. Redimensionar elementos internos */
    .content { padding: 15px !important; width: 100%; box-sizing: border-box; }
    .page-title h1 { font-size: 20px !important; }
    
    /* 5. Colapsar todos los formularios y grillas a 1 sola columna */
    .form-grid-horizontal, .checkout-footer, .kpi-grid { 
        grid-template-columns: 1fr !important; 
    }
    .col-span-2, .col-span-4 { grid-column: span 1 !important; }
    
    /* 6. Ajustar modales para que no se salgan de la pantalla */
    dialog { width: 95% !important; max-width: 95% !important; margin: auto; }
    .modal-content { padding: 15px !important; }
    
    /* 7. Ajustar botones del POS (Facturación) */
    #payMethodsB2C, #payMethodsB2B { flex-direction: column; }
    .pay-btn { width: 100%; margin-bottom: 5px; }
}


/* =========================================
   MENÚ LATERAL CLARO (LIGHT THEME)
   ========================================= */
.sidebar {
  background: #ffffff !important;
  border-right: 1px solid var(--line);
}
.sidebar .brand-text strong {
  color: var(--text) !important;
}
.sidebar .brand-text span {
  color: var(--muted) !important;
}
.sidebar .nav a {
  color: var(--muted) !important;
}
.sidebar .nav a:hover {
  color: var(--text) !important;
  background: var(--panel-hover) !important;
}
.sidebar .nav a.active {
  color: var(--primary) !important;
  background: rgba(14, 165, 233, 0.05) !important;
  border-right: 3px solid var(--primary) !important;
}

/* MicroSaaS v3 - sidebar session/logout fix */
.sidebar .sidebar-logout {
  margin-top: auto !important;
  width: 100% !important;
  padding: 13px 16px !important;
  border: 1px solid var(--line) !important;
  border-radius: 14px !important;
  background: #f8fafc !important;
  color: #334155 !important;
  font-weight: 800 !important;
  cursor: pointer !important;
  align-items: center !important;
  justify-content: flex-start !important;
  gap: 10px !important;
  flex-shrink: 0 !important;
}
.sidebar .sidebar-logout:hover {
  background: #eaf2ff !important;
  color: var(--primary) !important;
}
.sidebar .brand-text small {
  color: var(--muted) !important;
}


/* MicroSaaS v4 - sidebar final */
.sidebar {
  box-sizing: border-box !important;
  min-height: 100vh !important;
  display: flex !important;
  flex-direction: column !important;
}
.sidebar .nav {
  flex: 1 1 auto !important;
  min-height: 0 !important;
  overflow-y: auto !important;
  padding-bottom: 12px !important;
}
.sidebar .sidebar-logout {
  display: flex !important;
  position: sticky !important;
  bottom: 0 !important;
  margin-top: 12px !important;
  z-index: 5 !important;
}

/* MicroSaaS v19 - performance UX: loader no bloqueante */
#loadingOverlay {
  position: fixed !important;
  inset: auto 22px 22px auto !important;
  top: auto !important;
  left: auto !important;
  width: auto !important;
  height: auto !important;
  min-width: 180px !important;
  max-width: 320px !important;
  padding: 12px 16px !important;
  border-radius: 16px !important;
  background: rgba(255,255,255,.96) !important;
  border: 1px solid #dbe4f0 !important;
  box-shadow: 0 18px 45px rgba(15,23,42,.14) !important;
  color: #2563eb !important;
  font-size: 15px !important;
  font-weight: 900 !important;
  z-index: 999999 !important;
  pointer-events: none !important;
  justify-content: center !important;
  align-items: center !important;
  backdrop-filter: blur(8px) !important;
}
#loadingOverlay::before {
  content: '';
  width: 14px;
  height: 14px;
  margin-right: 10px;
  border-radius: 999px;
  border: 2px solid #bfdbfe;
  border-top-color: #2563eb;
  animation: msSpin .75s linear infinite;
}
@keyframes msSpin { to { transform: rotate(360deg); } }
body.page-changing::after {
  content: 'Abriendo...';
  position: fixed;
  right: 22px;
  bottom: 22px;
  padding: 12px 16px;
  border-radius: 16px;
  background: rgba(255,255,255,.96);
  border: 1px solid #dbe4f0;
  box-shadow: 0 18px 45px rgba(15,23,42,.14);
  color: #2563eb;
  font-size: 15px;
  font-weight: 900;
  z-index: 999999;
  pointer-events: none;
}


/* MicroSaaS v20 - loader no bloqueante forzado */
#loadingOverlay,
.loading-overlay,
.loader-overlay,
.global-loader,
.processing-overlay {
  position: fixed !important;
  inset: auto 22px 22px auto !important;
  top: auto !important;
  left: auto !important;
  right: 22px !important;
  bottom: 22px !important;
  width: auto !important;
  height: auto !important;
  min-width: 170px !important;
  max-width: 340px !important;
  padding: 12px 16px !important;
  border-radius: 16px !important;
  background: rgba(255,255,255,.96) !important;
  border: 1px solid #dbe4f0 !important;
  box-shadow: 0 18px 45px rgba(15,23,42,.14) !important;
  color: #2563eb !important;
  font-size: 15px !important;
  font-weight: 900 !important;
  z-index: 999999 !important;
  pointer-events: none !important;
  align-items: center !important;
  justify-content: center !important;
  opacity: 1 !important;
  backdrop-filter: blur(8px) !important;
}
body.ms-loading-active #loadingOverlay,
body.ms-loading-active .loading-overlay,
body.ms-loading-active .loader-overlay,
body.ms-loading-active .global-loader,
body.ms-loading-active .processing-overlay {
  display: flex !important;
}
