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

:root {
  /* MODO CLARO PREMIUM */
  --bg-main: #f8fafc;
  --bg-sidebar: rgba(255, 255, 255, 0.7);
  --bg-card: rgba(255, 255, 255, 0.7);
  --bg-soft: rgba(226, 232, 240, 0.5);
  --text-main: #0f172a;
  --text-secondary: #64748b;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --border-color: rgba(15, 23, 42, 0.08);
  --glass-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.05);
}

body.dark {
  /* MODO OSCURO SAAS (Black & Gold) */
  --bg-main: #0A0A0A;
  --bg-sidebar: rgba(10, 10, 10, 0.7);
  --bg-card: rgba(20, 20, 20, 0.6);
  --bg-soft: rgba(40, 40, 40, 0.5);
  --text-main: #f8fafc;
  --text-secondary: #a3a3a3;
  --accent: #d4af37;
  /* Dorado Elegante (Ratio 4.5:1 validado) */
  --accent-hover: #fcd34d;
  --border-color: rgba(212, 175, 55, 0.15);
  /* Bordes con tinte dorado sutil */
  --glass-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.5);
}

/* =====================================================
   BASE & FONDOS ANIMADOS
===================================================== */
body {
  margin: 0;
  font-family: 'Inter', sans-serif;
  background-color: var(--bg-main);
  background-image:
    radial-gradient(at 0% 0%, rgba(212, 175, 55, 0.08) 0px, transparent 40%),
    radial-gradient(at 100% 100%, rgba(255, 255, 255, 0.03) 0px, transparent 50%);
  background-attachment: fixed;
  color: var(--text-main);
  transition: background 0.4s ease, color 0.4s ease;
  min-height: 100vh;
}

::-webkit-scrollbar {
  width: 8px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--bg-soft);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-secondary);
}

.app {
  display: flex;
  min-height: 100vh;
}

/* =====================================================
   SIDEBAR (GLASSMORPHISM)
===================================================== */
.sidebar {
  width: 260px;
  background: var(--bg-sidebar);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  transition: all 0.3s ease;
  z-index: 10;
}

.sidebar-header {
  padding: 2rem 1.5rem;
}

.sidebar-header h2 {
  margin: 0;
  font-size: 1.8rem;
  font-weight: 800;
  letter-spacing: -0.5px;
  background: linear-gradient(90deg, var(--accent), #fef08a);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.sidebar-menu {
  list-style: none;
  padding: 0 1rem;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.sidebar-menu li {
  padding: 0.9rem 1.2rem;
  border-radius: 12px;
  cursor: pointer;
  font-weight: 500;
  color: var(--text-secondary);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  display: flex;
  align-items: center;
}

.sidebar-menu li:hover {
  background: var(--bg-soft);
  color: var(--text-main);
  transform: translateX(5px);
}

.sidebar-menu li.active {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 4px 15px rgba(139, 92, 246, 0.3);
  font-weight: 600;
}

/* =====================================================
   MAIN CONTENT & ANIMACIONES
===================================================== */
.main-content {
  flex: 1;
  padding: 2.5rem 3.5rem;
  height: 100vh;
  overflow-y: auto;
  box-sizing: border-box;
}

h2 {
  font-size: 2.2rem;
  font-weight: 700;
  margin-top: 0;
  margin-bottom: 2rem;
  letter-spacing: -0.5px;
}

h3 {
  font-size: 1.3rem;
  font-weight: 600;
  margin-top: 1.5rem;
  color: var(--text-main);
}

#contenido>div,
.section,
form,
table {
  animation: slideUpFade 0.5s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

@keyframes slideUpFade {
  0% {
    opacity: 0;
    transform: translateY(15px);
  }

  100% {
    opacity: 1;
    transform: translateY(0);
  }
}

/* =====================================================
   TARJETAS GLASS (CARDS)
===================================================== */
.config-card,
.calc-normal,
.calc-bloque,
.resumen-ventas>div,
.card-finanza,
.grafico-container,
.kpi-card,
.login-container {
  background: var(--bg-card);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--border-color);
  border-radius: 16px;
  box-shadow: var(--glass-shadow);
  padding: 1.5rem;
  transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.card-finanza,
.kpi-card {
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.card-finanza:hover,
.kpi-card:hover {
  transform: translateY(-5px);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.15);
  border-color: rgba(255, 255, 255, 0.12);
}

/* =====================================================
   INPUTS & BOTONES MODERNOS
===================================================== */
input,
select {
  background: var(--bg-soft);
  color: var(--text-main);
  border: 1px solid var(--border-color);
  padding: 0.85rem 1.2rem;
  border-radius: 10px;
  font-family: inherit;
  font-size: 0.95rem;
  outline: none;
  transition: all 0.3s ease;
  margin: 0.3rem;
}

input:focus,
select:focus {
  border-color: var(--accent);
  background: var(--bg-card);
  box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.2);
}

button {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 0.85rem 1.5rem;
  border-radius: 10px;
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow: 0 4px 15px rgba(139, 92, 246, 0.25);
  margin: 0.3rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

button:hover {
  background: var(--accent-hover);
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(139, 92, 246, 0.35);
}

button:active {
  transform: translateY(0);
}

.btnEliminar {
  background: rgba(239, 68, 68, 0.1);
  color: #ef4444;
  box-shadow: none;
  padding: 0.5rem 0.8rem;
  margin: 0;
}

.btnEliminar:hover {
  background: #ef4444;
  color: #fff;
}

/* =====================================================
   TABLAS (DATA GRID)
===================================================== */
table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  margin-top: 1.5rem;
  background: var(--bg-card);
  backdrop-filter: blur(12px);
  border-radius: 16px;
  overflow: hidden;
  border: 1px solid var(--border-color);
  box-shadow: var(--glass-shadow);
}

th,
td {
  padding: 1.1rem;
  text-align: left;
  border-bottom: 1px solid var(--border-color);
  font-size: 0.95rem;
}

th {
  background: var(--bg-soft);
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  font-size: 0.8rem;
  letter-spacing: 0.5px;
}

tr:last-child td {
  border-bottom: none;
}

tr:hover td {
  background: rgba(255, 255, 255, 0.03);
}

/* =====================================================
   GRILLAS FINANZAS Y STATS
===================================================== */
.finanzas-grid,
.kpis-container {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1.5rem;
  margin-top: 1rem;
}

.filtros-finanzas,
.estadisticas-filtros {
  display: flex;
  gap: 0.8rem;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
}

.filtros-finanzas button,
.estadisticas-filtros button {
  background: var(--bg-soft);
  color: var(--text-secondary);
  box-shadow: none;
  border: 1px solid transparent;
}

.filtros-finanzas button:hover,
.filtros-finanzas button.active {
  background: var(--bg-card);
  color: var(--text-main);
  border-color: var(--border-color);
  box-shadow: var(--glass-shadow);
}

/* =====================================================
   UTILERIAS
===================================================== */
hr {
  border: 0;
  height: 1px;
  background: var(--border-color);
  margin: 2rem 0;
}

/* 🔥 SECCIÓN DE LOGIN CORREGIDA 🔥 */
#login-wrapper {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: #050505;
  z-index: 99999;
}

.login-container {
  width: 90%;
  max-width: 420px;
  background: var(--bg-card);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--border-color);
  border-radius: 24px;
  box-shadow: 0 25px 50px rgba(0, 0, 0, 0.8);
  padding: 3rem 2.5rem;
  text-align: center;
  margin: 0;
}

/* FIN LOGIN CORREGIDO */

.login-container input {
  display: block;
  width: calc(100% - 2.5rem);
  margin: 1rem auto;
}

.login-container button {
  width: calc(100% - 2.5rem);
}

/* =====================================================
   CALCULADORA ORDENADA Y CENTRADA CON HISTORIAL
===================================================== */
.calculadora-layout {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  gap: 2.5rem;
  margin: 2rem auto;
  max-width: 900px;
  flex-wrap: wrap;
  /* responsive */
}

.calc-historial-container {
  flex: 1;
  min-width: 280px;
  max-width: 340px;
  background: var(--bg-card);
  padding: 1.8rem;
  border-radius: 24px;
  box-shadow: var(--glass-shadow);
  border: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  height: 520px;
  /* match calculator height approx */
}

.calc-historial-container h3 {
  margin-top: 0;
  margin-bottom: 1rem;
  font-size: 1.2rem;
  color: var(--text-main);
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 0.8rem;
}

#listaHistorial {
  list-style: none;
  padding: 0;
  margin: 0;
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
}

#listaHistorial li {
  background: rgba(0, 0, 0, 0.03);
  padding: 0.8rem;
  border-radius: 12px;
  font-size: 1.1rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border: 1px solid rgba(0, 0, 0, 0.02);
}

body.dark #listaHistorial li {
  background: rgba(255, 255, 255, 0.03);
  border-color: rgba(255, 255, 255, 0.05);
}

#listaHistorial li .op {
  color: var(--text-secondary);
  font-size: 0.95rem;
}

#listaHistorial li .res {
  color: var(--text-main);
  font-size: 1.1rem;
}

.empty-historial {
  justify-content: center !important;
  color: var(--text-secondary) !important;
  background: transparent !important;
  border: none !important;
  font-size: 0.95rem !important;
  font-style: italic;
}

#btnLimpiarHistorial {
  margin-top: 1rem;
  background: transparent;
  color: #ef4444;
  border: 1px solid #ef4444;
  width: 100%;
}

#btnLimpiarHistorial:hover {
  background: #ef4444;
  color: white;
}

.calculadora-normal {
  width: 340px;
  margin: 0;
  /* no auto margin, flex handles centering */
  background: var(--bg-card);
  padding: 1.8rem;
  border-radius: 24px;
  box-shadow: var(--glass-shadow);
  border: 1px solid var(--border-color);
}

#calcDisplay {
  width: 100%;
  box-sizing: border-box;
  text-align: right;
  font-size: 2.5rem;
  font-weight: 300;
  padding: 1.2rem;
  margin-bottom: 1.5rem;
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.05);
  color: var(--text-main);
  border: 1px solid var(--border-color);
  box-shadow: inset 0 2px 10px rgba(0, 0, 0, 0.05);
}

body.dark #calcDisplay {
  background: rgba(255, 255, 255, 0.03);
  box-shadow: inset 0 2px 10px rgba(0, 0, 0, 0.2);
}

.calc-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-gap: 12px;
}

.calc-grid button {
  margin: 0;
  padding: 0;
  font-size: 1.5rem;
  border-radius: 16px;
  /* modern rounded rectangles */
  height: 65px;
  /* taller buttons */
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-soft);
  color: var(--text-main);
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.05);
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  border: 1px solid rgba(255, 255, 255, 0.05);
  font-weight: 500;
}

.calc-grid button:hover {
  background: var(--bg-card);
  transform: scale(1.05) translateY(-2px);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.1);
}

.calc-grid button[data-op],
.calc-grid #btnClear {
  background: var(--bg-card);
  color: var(--accent);
  font-weight: 600;
}

.calc-grid #btnClear {
  background: rgba(239, 68, 68, 0.15);
  color: #ef4444;
}

.calc-grid #btnClear:hover {
  background: #ef4444;
  color: #fff;
}

.calc-grid .btn-igual {
  background: #3b82f6;
  /* Blue like the image */
  color: #fff;
  grid-row: span 2;
  height: calc(130px + 12px);
  /* 2 rows of 65px + 12px gap to make it consistently taller */
  box-shadow: 0 8px 20px rgba(59, 130, 246, 0.3);
}

.calc-grid .btn-igual:hover {
  background: #2563eb;
}

.calc-grid .btn-cero {
  grid-column: span 2;
}

/* =====================================================
   CENTRO DE CONTROL (ACCORDION Y CHECKBOXES)
===================================================== */
.accordion-container {
  display: flex;
  flex-direction: column;
  gap: 1.2rem;
  margin-top: 1rem;
}

.accordion-item {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 16px;
  overflow: hidden;
  box-shadow: var(--glass-shadow);
  transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.accordion-item.active {
  border-color: var(--accent);
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.15);
}

.accordion-header {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1.5rem;
  background: transparent;
  color: var(--text-main);
  box-shadow: none;
  border-radius: 0;
  margin: 0;
}

.accordion-header:hover {
  background: var(--bg-soft);
  transform: none;
  box-shadow: none;
}

.accordion-header .acc-title {
  font-size: 1.15rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 10px;
}

.accordion-header .acc-icon {
  font-size: 0.9rem;
  color: var(--text-secondary);
  transition: transform 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

.accordion-item.active .acc-icon {
  transform: rotate(180deg);
  color: var(--accent);
}

.accordion-content {
  max-height: 0;
  padding: 0 1.5rem;
  opacity: 0;
  visibility: hidden;
  transition: all 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

.accordion-item.active .accordion-content {
  max-height: 1000px;
  padding: 0 1.5rem 1.5rem 1.5rem;
  opacity: 1;
  visibility: visible;
}

.config-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1.5rem;
  margin-top: 1rem;
}

.config-card {
  background: rgba(0, 0, 0, 0.02);
  border-radius: 12px;
  padding: 1.2rem;
  border: 1px solid var(--border-color);
  box-shadow: none;
}

body.dark .config-card {
  background: rgba(255, 255, 255, 0.02);
}

.config-card.full-width {
  grid-column: 1 / -1;
}

.config-card h3 {
  margin-top: 0;
  font-size: 1rem;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 0.5rem;
  margin-bottom: 1rem;
}

/* Checkboxes modernos */
.custom-checkbox {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  user-select: none;
  width: fit-content;
}

/* Sobrescribe estilos globales de input */
input[type="checkbox"].custom-checkbox-input,
.custom-checkbox input[type="checkbox"] {
  appearance: none;
  background-color: transparent !important;
  width: 22px !important;
  height: 22px !important;
  border: 2px solid var(--text-secondary) !important;
  border-radius: 6px !important;
  display: flex !important;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  cursor: pointer;
  margin: 0 !important;
  padding: 0 !important;
  box-shadow: none !important;
}

.custom-checkbox input[type="checkbox"]::after {
  content: "✔";
  color: white;
  font-size: 13px;
  opacity: 0;
  transform: scale(0);
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.custom-checkbox input[type="checkbox"]:checked {
  background-color: var(--accent) !important;
  border-color: var(--accent) !important;
}

.custom-checkbox input[type="checkbox"]:checked::after {
  opacity: 1;
  transform: scale(1);
}

.custom-checkbox span {
  font-size: 0.95rem;
  color: var(--text-main);
  opacity: 0.9;
}

/* Toggle Buttons */
button.btn-active {
  background: var(--accent);
  color: white;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
}

button:not(.btn-active) {
  opacity: 0.8;
}

/* ===============================
   SPLASH SCREEN (PWA / NATIVE APP)
   =============================== */
.splash-screen {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background-color: #121212;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  z-index: 99999;
  transition: opacity 0.5s ease-out, visibility 0.5s;
}

.splash-logo {
  font-size: 4rem;
  font-weight: 900;
  letter-spacing: 4px;
  color: var(--accent);
  animation: pulseLogo 1.5s infinite alternate;
  margin: 0;
}

.splash-loader {
  margin-top: 20px;
  width: 40px;
  height: 40px;
  border: 4px solid rgba(255, 255, 255, 0.1);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spinLoader 1s linear infinite;
}

@keyframes pulseLogo {
  from {
    transform: scale(1);
    opacity: 0.8;
  }

  to {
    transform: scale(1.05);
    opacity: 1;
  }
}

@keyframes spinLoader {
  to {
    transform: rotate(360deg);
  }
}

.splash-hidden {
  opacity: 0;
  visibility: hidden;
}

/* FORZADO DE CENTRADO TENO - FINAL */
#login-wrapper {
  position: fixed !important;
  inset: 0 !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  background-color: #050505 !important;
  z-index: 999999 !important;
}

.login-container {
  margin: 0 auto !important;
  float: none !important;
  position: relative !important;
  left: 0 !important;
  transform: none !important;
}

/* =====================================================
   MÓVIL & RESPONSIVE (Táctica & Estética de Élite)
===================================================== */
.btn-menu-mobile {
  display: none;
  position: fixed;
  top: 15px;
  left: 15px;
  width: 44px;
  height: 44px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--accent);
  border-radius: 12px;
  z-index: 999; /* Debajo de la sidebar para no superponerse */
  cursor: pointer;
  box-shadow: var(--glass-shadow);
  padding: 0;
  align-items: center;
  justify-content: center;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
}

.btn-menu-mobile svg {
  stroke-width: 2.5px;
  transition: transform 0.3s;
}

.btn-menu-mobile:hover, .btn-menu-mobile:active {
  background: var(--accent);
  color: #fff;
  transform: translateY(-2px);
}

.btn-menu-mobile.btn-oculto {
  opacity: 0 !important;
  visibility: hidden !important;
  transform: translateX(-100px) scale(0.8) !important; /* Desplazamiento total fuera de pantalla + encogimiento */
  pointer-events: none !important;
  backdrop-filter: none !important;
  -webkit-backdrop-filter: none !important;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1) !important;
}

.sidebar-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0,0,0,0.5);
  backdrop-filter: blur(8px); /* Overlay borroso pedido (backdrop-blur) */
  -webkit-backdrop-filter: blur(8px);
  z-index: 998;
  opacity: 0;
  visibility: hidden;
  transition: all 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

.sidebar-overlay.active {
  opacity: 1;
  visibility: visible;
}

/* Permitir que el botón de cerrar sesión se pegue al fondo (Desktop y Móvil) */
.sidebar-menu {
  flex: 1;
}

#btnCerrarSesion {
  margin-top: auto !important;
  margin-bottom: 20px;
  border: 1px solid rgba(239, 68, 68, 0.2);
}

#btnCerrarSesion:hover {
  background: rgba(239, 68, 68, 0.15) !important;
  color: #ef4444 !important;
  transform: none;
}

@media (max-width: 768px) {
  .btn-menu-mobile {
    display: flex;
  }

  .sidebar {
    position: fixed;
    top: 0;
    left: -280px; /* Colapsado por defecto */
    height: 100vh;
    width: 260px;
    z-index: 1000;
  }

  .sidebar.active {
    left: 0;
    box-shadow: 30px 0 60px rgba(0,0,0,0.6);
  }

  .main-content {
    /* Espacio arriba para que no colisione con el botón fijo */
    padding: 85px 1rem 1.5rem 1rem !important; 
    width: 100%;
    margin: 0;
  }

  /* Asegurar tamaño táctil mínimo (44px) */
  input, select, button, .sidebar-menu li {
    min-height: 44px;
    box-sizing: border-box;
  }

  /* El contenido ocupa el 100% en móvil para operación a una mano */
  .config-grid, .finanzas-grid, .kpis-container, .calc-historial-container, .calculadora-normal {
    width: 100%;
    max-width: 100%;
  }

  /* Ajuste específico para la calculadora a 100% de ancho */
  .calculadora-layout {
    flex-direction: column;
    padding: 0;
    gap: 1.5rem;
  }

  .login-container {
    width: 92%;
    padding: 2.5rem 1.5rem;
  }
}

/* =====================================================
   MÓDULO DE BITÁCORA DIGITAL
===================================================== */
.notas-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 20px;
  margin-top: 20px;
}
.nota-post-it {
  transition: transform 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}
.nota-post-it:hover {
  transform: translateY(-5px) scale(1.01);
}
.btn-borrar-nota:hover {
  filter: brightness(1.2);
  transform: scale(1.1);
}