/* ==========================================================================
   Dealer Management System (DMS) — GV Forge™
   Sistema de Diseño CSS & Theme Responsive
   ========================================================================== */

:root {
  --bg-dark: #0f172a;
  --bg-card: #1e293b;
  --bg-card-hover: #334155;
  --bg-input: #0f172a;
  --border-color: #334155;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --accent-cyan: #06b6d4;
  --accent-teal: #14b8a6;
  --accent-hover: #0891b2;
  --accent-glow: rgba(6, 182, 212, 0.25);
  
  --status-green: #10b981;
  --status-yellow: #f59e0b;
  --status-red: #ef4444;
  --status-blue: #3b82f6;

  --font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --shadow-main: 0 10px 25px -5px rgba(0, 0, 0, 0.4), 0 8px 10px -6px rgba(0, 0, 0, 0.4);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-family);
  background-color: var(--bg-dark);
  color: var(--text-main);
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ==========================================================================
   Controles Globales de Texto y Transformaciones
   ========================================================================== */

/* Todos los campos de formulario de texto se muestran visualmente en MAYÚSCULAS */
input[type="text"],
input[type="search"],
textarea,
select {
  text-transform: uppercase;
}

/* Excepción para login (usuario y contraseña) */
input.no-uppercase,
input[type="password"],
input[type="email"] {
  text-transform: none !important;
}

::placeholder {
  text-transform: none;
  color: var(--text-muted);
}

/* ==========================================================================
   Header & Navegación Principal — App Shell & Sidebar Layout
   ========================================================================== */

.app-layout {
  display: flex;
  min-height: 100vh;
  width: 100%;
  position: relative;
  background-color: var(--bg-dark);
}

.app-main-wrapper {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

/* Sidebar Styling */
.app-sidebar {
  background: var(--bg-card);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  box-shadow: 4px 0 20px rgba(0,0,0,0.35);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.sidebar-header {
  padding: 1.25rem 1.25rem 1rem 1.25rem;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.mobile-close-btn {
  display: none;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.25rem;
  cursor: pointer;
  padding: 0.25rem;
}
.mobile-close-btn:hover { color: var(--text-main); }

.sidebar-nav {
  flex: 1;
  padding: 1rem 0.75rem;
  overflow-y: auto;
}

.nav-links-vertical {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.nav-links-vertical li {
  width: 100%;
}

.nav-links-vertical .nav-link {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.7rem 1rem;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 0.92rem;
  font-weight: 600;
  text-decoration: none;
  transition: all 0.2s ease;
  border-left: 3px solid transparent;
}

.nav-links-vertical .nav-link i {
  width: 20px;
  text-align: center;
  font-size: 1.1rem;
}

.nav-links-vertical .nav-link:hover {
  color: var(--text-main);
  background: rgba(255, 255, 255, 0.06);
}

.nav-links-vertical .nav-link.active {
  color: var(--text-main);
  background: linear-gradient(90deg, rgba(6, 182, 212, 0.18), rgba(6, 182, 212, 0.03));
  border-left-color: var(--accent-cyan);
}
.nav-links-vertical .nav-link.active i {
  color: var(--accent-cyan);
}

.nav-divider {
  height: 1px;
  background: var(--border-color);
  margin: 0.75rem 0;
}

/* Sidebar User Footer */
.sidebar-user-footer {
  padding: 1rem 1.25rem;
  border-top: 1px solid var(--border-color);
  background: rgba(15, 23, 42, 0.5);
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.user-info-box {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.user-avatar {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  background: rgba(6, 182, 212, 0.15);
  color: var(--accent-cyan);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.05rem;
  border: 1px solid rgba(6, 182, 212, 0.3);
  flex-shrink: 0;
}

.user-details {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  overflow: hidden;
}

.user-name {
  font-weight: 700;
  font-size: 0.85rem;
  color: var(--text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-actions-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.lang-switch-pill {
  display: flex;
  align-items: center;
  background: var(--bg-dark);
  border-radius: 9999px;
  border: 1px solid var(--border-color);
  padding: 2px;
}

.lang-btn {
  padding: 2px 10px;
  font-size: 0.75rem;
  font-weight: 800;
  border-radius: 9999px;
  text-decoration: none;
  color: var(--text-muted);
}

.lang-btn.active {
  color: #000;
  background: var(--accent-cyan);
}

.btn-logout {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  background: rgba(239, 68, 68, 0.1);
  color: var(--status-red);
  border: 1px solid rgba(239, 68, 68, 0.25);
  display: flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  transition: all 0.2s;
}

.btn-logout:hover {
  background: var(--status-red);
  color: #fff;
}

.brand-badge {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  text-decoration: none;
  color: var(--text-main);
}

.brand-logo {
  height: 36px;
  width: auto;
  border-radius: var(--radius-sm);
  object-fit: contain;
}

.brand-title {
  font-size: 1.2rem;
  font-weight: 800;
  background: linear-gradient(135deg, var(--accent-cyan), var(--accent-teal));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  letter-spacing: -0.5px;
}

.role-pill {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  padding: 0.15rem 0.45rem;
  border-radius: 4px;
  display: inline-block;
  width: fit-content;
}

.role-admin {
  background: rgba(6, 182, 212, 0.2);
  color: var(--accent-cyan);
  border: 1px solid var(--accent-cyan);
}

.role-limitado {
  background: rgba(245, 158, 11, 0.2);
  color: var(--status-yellow);
  border: 1px solid var(--status-yellow);
}

/* App Mobile Topbar */
.app-mobile-topbar {
  display: none;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border-color);
  padding: 0.75rem 1rem;
  position: sticky;
  top: 0;
  z-index: 90;
}

.brand-title-mobile {
  font-size: 1.1rem;
  font-weight: 800;
  background: linear-gradient(135deg, var(--accent-cyan), var(--accent-teal));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.mobile-toggle {
  display: none;
  background: none;
  border: none;
  color: var(--text-main);
  font-size: 1.4rem;
  cursor: pointer;
}

/* ==========================================================================
   Layout Principal y Contenedores
   ========================================================================== */

.main-content {
  flex: 1;
  max-width: 1600px;
  width: 100%;
  margin: 0 auto;
  padding: 1.75rem 2rem;
}

.app-footer {
  text-align: center;
  padding: 1.25rem 1rem;
  color: var(--text-muted);
  font-size: 0.75rem;
  border-top: 1px solid var(--border-color);
  margin-top: auto;
  width: 100%;
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
  gap: 1rem;
}

.page-title {
  font-size: 1.5rem;
  font-weight: 700;
}

/* Tarjetas y Paneles (Glassmorphism Sleek) */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  box-shadow: var(--shadow-main);
  margin-bottom: 1.5rem;
}

.card-title {
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--accent-cyan);
}

/* Grid de métricas KPI */
.metrics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1.25rem;
  margin-bottom: 1.5rem;
}

.metric-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  box-shadow: var(--shadow-main);
}

.metric-icon {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  background: rgba(255, 255, 255, 0.05);
}

.metric-val {
  font-size: 1.75rem;
  font-weight: 800;
  line-height: 1.2;
}

.metric-lbl {
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* ==========================================================================
   Formularios y Elementos de Entrada
   ========================================================================== */

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 1rem;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.form-label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
}

.form-control {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  padding: 0.6rem 0.85rem;
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.form-control:focus {
  border-color: var(--accent-cyan);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

/* Layout Compacto de Filtros de Búsqueda (2 Columnas en móvil) */
.filter-bar-compact {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}

@media (max-width: 768px) {
  .filter-bar-compact {
    grid-template-columns: repeat(2, 1fr) !important;
  }
}

/* ==========================================================================
   Botones y Acciones Compactas
   ========================================================================== */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.6rem 1.1rem;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  text-decoration: none;
  transition: all 0.2s ease;
}

.btn-primary {
  background: var(--accent-cyan);
  color: #000;
}
.btn-primary:hover {
  background: var(--accent-hover);
}

.btn-secondary {
  background: #334155;
  color: var(--text-main);
}
.btn-secondary:hover {
  background: #475569;
}

.btn-success {
  background: var(--status-green);
  color: #000;
}
.btn-danger {
  background: var(--status-red);
  color: #fff;
}
.btn-warning {
  background: var(--status-yellow);
  color: #000;
}

/* Botones de Ícono Compactos (Siempre Visibles, Sin Desplegables Que Apilen) */
.btn-icon {
  width: 34px;
  height: 34px;
  padding: 0;
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  border: 1px solid var(--border-color);
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-main);
}
.btn-icon:hover {
  background: rgba(255, 255, 255, 0.15);
  border-color: var(--accent-cyan);
}

.actions-cell {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  white-space: nowrap;
}

/* ==========================================================================
   Tablas Estilizadas y Sticky Columns
   ========================================================================== */

.table-responsive {
  width: 100%;
  overflow-x: auto;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
}

.table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 0.9rem;
}

.table th {
  background: rgba(15, 23, 42, 0.9);
  color: var(--text-muted);
  font-weight: 700;
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--border-color);
  white-space: nowrap;
}

.table td {
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--border-color);
  vertical-align: middle;
}

.table tbody tr:hover {
  background: rgba(255, 255, 255, 0.03);
}

/* Columna de Acciones Fija (Sticky) a la Derecha en Móviles */
@media (max-width: 900px) {
  .table th.sticky-right,
  .table td.sticky-right {
    position: sticky;
    right: 0;
    background: var(--bg-card);
    z-index: 10;
    box-shadow: -4px 0 8px rgba(0, 0, 0, 0.3);
  }
}

/* Costo Difuminado (Blur) con Reveal en Hover/Touch */
.costo-blur {
  filter: blur(5px);
  user-select: none;
  cursor: pointer;
  transition: filter 0.3s ease;
  background: rgba(255, 255, 255, 0.05);
  padding: 0.2rem 0.4rem;
  border-radius: 4px;
}

.costo-blur:hover,
.costo-blur:active,
.costo-blur.revealed {
  filter: blur(0);
  user-select: text;
}

/* ==========================================================================
   Badges y Semáforos de Cobranza
   ========================================================================== */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.25rem 0.6rem;
  border-radius: 9999px;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
}

.badge-green {
  background: rgba(16, 185, 129, 0.2);
  color: var(--status-green);
  border: 1px solid var(--status-green);
}

.badge-yellow {
  background: rgba(245, 158, 11, 0.2);
  color: var(--status-yellow);
  border: 1px solid var(--status-yellow);
}

.badge-orange {
  background: rgba(249, 115, 22, 0.2);
  color: #f97316;
  border: 1px solid #f97316;
}

.badge-red {
  background: rgba(239, 68, 68, 0.2);
  color: var(--status-red);
  border: 1px solid var(--status-red);
}

.badge-blue {
  background: rgba(59, 130, 246, 0.2);
  color: var(--status-blue);
  border: 1px solid var(--status-blue);
}

/* Layout de 2 Columnas para Cobranza */
.cobranza-layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
}

@media (max-width: 992px) {
  .cobranza-layout {
    grid-template-columns: 1fr;
  }
}

/* ==========================================================================
   Alertas y Notificaciones Flash
   ========================================================================== */

.alert {
  padding: 0.85rem 1.25rem;
  border-radius: var(--radius-sm);
  margin-bottom: 1.25rem;
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.alert-success {
  background: rgba(16, 185, 129, 0.15);
  border: 1px solid var(--status-green);
  color: #a7f3d0;
}

.alert-danger {
  background: rgba(239, 68, 68, 0.15);
  border: 1px solid var(--status-red);
  color: #fecaca;
}

/* Modales */
.modal-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}

.modal-backdrop.show {
  opacity: 1;
  pointer-events: auto;
}

.modal-dialog {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  width: 100%;
  max-width: 600px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 1.5rem;
  box-shadow: var(--shadow-main);
}

/* ==========================================================================
   Reglas de Responsividad Móvil (Mobile First & Adaptaciones)
   ========================================================================== */

/* ==========================================================================
   Media Queries — Desktop Sidebar vs Mobile/Tablet Layout
   ========================================================================== */

/* DESKTOP RULES (min-width: 1024px) */
@media (min-width: 1024px) {
  .app-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 260px;
    z-index: 100;
    height: 100vh;
  }

  .app-main-wrapper {
    margin-left: 260px;
    width: calc(100% - 260px);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
  }

  .main-content {
    max-width: 1600px;
    padding: 1.75rem 2rem 4rem 2rem;
    flex: 1;
  }

  .app-footer {
    position: fixed;
    bottom: 0;
    left: 260px;
    right: 0;
    z-index: 99;
    background: var(--bg-card);
    border-top: 1px solid var(--border-color);
    box-shadow: 0 -4px 12px rgba(0,0,0,0.3);
  }

  .app-mobile-topbar {
    display: none !important;
  }

  .sidebar-backdrop {
    display: none !important;
  }
}

/* MOBILE & TABLET RULES (max-width: 1023px) */
@media (max-width: 1023px) {
  .app-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 280px;
    z-index: 1000;
    height: 100vh;
    transform: translateX(-100%);
    box-shadow: 10px 0 25px rgba(0,0,0,0.5);
  }

  .app-sidebar.show {
    transform: translateX(0);
  }

  .mobile-close-btn {
    display: block;
  }

  .app-main-wrapper {
    margin-left: 0;
    width: 100%;
  }

  .app-mobile-topbar {
    display: flex;
  }

  .mobile-toggle {
    display: block !important;
  }

  .sidebar-backdrop {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    z-index: 999;
  }

  .sidebar-backdrop.show {
    display: block;
  }

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

  .main-content {
    padding: 1rem 0.75rem;
  }
}

@media (max-width: 768px) {
  .metrics-grid {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 0.75rem;
  }

  .metric-card {
    padding: 0.85rem;
    gap: 0.75rem;
  }

  .metric-icon {
    width: 38px;
    height: 38px;
    font-size: 1.2rem;
  }

  .metric-val {
    font-size: 1.35rem;
  }

  .filter-bar-compact {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 0.5rem;
  }

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

  .modal-dialog {
    max-width: 95vw !important;
    padding: 1rem !important;
    margin: 0.5rem;
  }

  .btn {
    padding: 0.6rem 0.85rem;
    font-size: 0.85rem;
  }

  .actions-cell {
    gap: 0.25rem;
  }
}

@media (max-width: 480px) {
  .metrics-grid {
    grid-template-columns: 1fr !important;
  }

  .page-header {
    flex-direction: column;
    align-items: flex-start;
  }
}

/* ==========================================================================
   Reglas de Impresión (@media print)
   ========================================================================== */

@media print {
  body {
    background: #fff !important;
    color: #000 !important;
    font-size: 12pt;
  }
  
  .app-sidebar,
  .app-mobile-topbar,
  .btn,
  .no-print,
  .filter-bar-compact,
  .mobile-toggle {
    display: none !important;
  }

  .app-main-wrapper {
    margin-left: 0 !important;
    width: 100% !important;
  }

  .main-content {
    max-width: 100% !important;
    padding: 0 !important;
    margin: 0 !important;
  }

  .card {
    background: transparent !important;
    border: none !important;
    box-shadow: none !important;
    padding: 0 !important;
  }

  .table th, .table td {
    border-color: #000 !important;
    color: #000 !important;
  }

  .print-page-break {
    page-break-before: always;
  }
}

