:root {
  --primary: #e50914;
  --primary-hover: #b90710;
  --primary-light: #fef2f2;
  --dark: #0f172a;
  --dark-surface: #1e293b;
  --gray-bg: #f8fafc;
  --card-bg: #ffffff;
  --border: #e2e8f0;
  --text-main: #0f172a;
  --text-muted: #64748b;
  --success: #10b981;
  --success-bg: #ecfdf5;
  --warning: #f59e0b;
  --warning-bg: #fffbeb;
  --shadow: 0 4px 20px -2px rgba(15, 23, 42, 0.06);
  --shadow-lg: 0 10px 30px -4px rgba(15, 23, 42, 0.12);
  --radius: 10px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

body {
  background-color: var(--gray-bg);
  color: var(--text-main);
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* SIDEBAR */
.sidebar {
  width: 260px;
  background-color: var(--dark);
  color: #fff;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  border-right: 1px solid rgba(255, 255, 255, 0.08);
}

.sidebar-header {
  padding: 24px 20px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  display: flex;
  align-items: center;
  gap: 12px;
}

.sidebar-header img {
  max-height: 38px;
  width: auto;
}

.sidebar-badge {
  background: var(--primary);
  color: #fff;
  font-size: 10px;
  font-weight: 800;
  padding: 2px 6px;
  border-radius: 4px;
  letter-spacing: 0.5px;
}

.sidebar-menu {
  list-style: none;
  padding: 16px 12px;
  flex: 1;
  overflow-y: auto;
}

.sidebar-menu li {
  margin-bottom: 4px;
}

.sidebar-menu a {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  color: #94a3b8;
  text-decoration: none;
  font-size: 14px;
  font-weight: 600;
  border-radius: 8px;
  transition: all 0.2s ease;
}

.sidebar-menu a:hover {
  color: #fff;
  background-color: rgba(255, 255, 255, 0.05);
}

.sidebar-menu a.active {
  color: #fff;
  background-color: var(--primary);
  box-shadow: 0 4px 12px rgba(229, 9, 20, 0.35);
}

.sidebar-menu a .icon {
  font-size: 18px;
  width: 22px;
  text-align: center;
}

.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  font-size: 12px;
  color: #64748b;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

/* MAIN CONTENT */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--gray-bg);
}

/* TOPBAR */
.topbar {
  height: 68px;
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 32px;
  flex-shrink: 0;
}

.topbar-title h1 {
  font-size: 20px;
  font-weight: 800;
  color: var(--text-main);
  letter-spacing: -0.5px;
}

.topbar-title p {
  font-size: 12px;
  color: var(--text-muted);
}

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

/* BUTTONS */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 18px;
  font-size: 13px;
  font-weight: 700;
  border-radius: 6px;
  border: none;
  cursor: pointer;
  transition: all 0.2s ease;
  text-decoration: none;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 2px 8px rgba(229, 9, 20, 0.25);
}

.btn-primary:hover {
  background: var(--primary-hover);
  transform: translateY(-1px);
}

.btn-outline {
  background: #fff;
  border: 1px solid var(--border);
  color: var(--text-main);
}

.btn-outline:hover {
  border-color: #cbd5e1;
  background: #f1f5f9;
}

.btn-sm {
  padding: 6px 12px;
  font-size: 12px;
}

.btn-success {
  background: var(--success);
  color: #fff;
}

/* CONTENT VIEW SCROLLABLE */
.view-container {
  flex: 1;
  overflow-y: auto;
  padding: 32px;
}

.tab-pane {
  display: none;
}

.tab-pane.active {
  display: block;
  animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

/* CARDS & GRIDS */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 20px;
  margin-bottom: 28px;
}

.stat-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  gap: 16px;
}

.stat-icon {
  width: 50px;
  height: 50px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
}

.stat-icon.red { background: var(--primary-light); color: var(--primary); }
.stat-icon.blue { background: #eff6ff; color: #3b82f6; }
.stat-icon.green { background: var(--success-bg); color: var(--success); }
.stat-icon.amber { background: var(--warning-bg); color: var(--warning); }

.stat-info h3 {
  font-size: 24px;
  font-weight: 800;
  color: var(--text-main);
  line-height: 1.1;
}

.stat-info p {
  font-size: 13px;
  color: var(--text-muted);
  font-weight: 600;
  margin-top: 4px;
}

/* TABLE SECTION */
.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  margin-bottom: 24px;
}

.card-header {
  padding: 18px 24px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.card-title {
  font-size: 16px;
  font-weight: 800;
  color: var(--text-main);
}

.search-box {
  display: flex;
  align-items: center;
  gap: 10px;
}

.search-input {
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  width: 260px;
  outline: none;
  transition: border-color 0.2s;
}

.search-input:focus {
  border-color: var(--primary);
}

table.data-table {
  width: 100%;
  border-collapse: collapse;
}

table.data-table th {
  background: #f8fafc;
  color: #475569;
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 12px 18px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

table.data-table td {
  padding: 14px 18px;
  font-size: 13px;
  border-bottom: 1px solid #f1f5f9;
  color: var(--text-main);
}

table.data-table tr:hover {
  background-color: #f8fafc;
}

.badge {
  display: inline-block;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.badge-green { background: var(--success-bg); color: var(--success); }
.badge-red { background: var(--primary-light); color: var(--primary); }
.badge-amber { background: var(--warning-bg); color: var(--warning); }
.badge-gray { background: #f1f5f9; color: #475569; }

/* MODALS */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(15, 23, 42, 0.6);
  backdrop-filter: blur(4px);
  z-index: 9999;
  display: none;
  align-items: center;
  justify-content: center;
}

.modal-overlay.open {
  display: flex;
}

.modal {
  background: #ffffff;
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
  width: 90%;
  max-width: 800px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-header {
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-header h3 {
  font-size: 18px;
  font-weight: 800;
}

.modal-close {
  background: none;
  border: none;
  font-size: 24px;
  color: var(--text-muted);
  cursor: pointer;
}

.modal-body {
  padding: 24px;
  overflow-y: auto;
  flex: 1;
}

.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  background: #f8fafc;
}

/* FORM ELEMENTS */
.form-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
}

.form-group {
  margin-bottom: 16px;
}

.form-group.col-span-2 {
  grid-column: span 2;
}

.form-group label {
  display: block;
  font-size: 12px;
  font-weight: 700;
  color: #334155;
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.form-control {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
  color: var(--text-main);
  outline: none;
  transition: border-color 0.2s;
}

.form-control:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(229, 9, 20, 0.1);
}

/* COTIZADOR ITEMS TABLE */
.items-table {
  width: 100%;
  border-collapse: collapse;
  margin: 16px 0;
}

.items-table th {
  background: #f1f5f9;
  padding: 10px 12px;
  font-size: 11px;
  font-weight: 800;
  text-align: left;
  border: 1px solid var(--border);
}

.items-table td {
  padding: 8px 12px;
  border: 1px solid var(--border);
  font-size: 13px;
}

.items-table input {
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 4px;
  width: 100%;
}

.btn-remove-row {
  color: var(--primary);
  background: none;
  border: none;
  cursor: pointer;
  font-size: 16px;
  font-weight: bold;
}

/* DOCUMENT VIEWER (PRESUPUESTOS Y FACTURAS OFICIALES) */
.doc-sheet {
  background: #ffffff;
  padding: 40px;
  border-radius: 8px;
  border: 1px solid var(--border);
  max-width: 850px;
  margin: 0 auto;
}

/* DRAG & DROP ZONE */
.dropzone {
  border: 2px dashed #cbd5e1;
  border-radius: 12px;
  padding: 40px 20px;
  text-align: center;
  background: #f8fafc;
  cursor: pointer;
  transition: all 0.2s;
}

.dropzone:hover, .dropzone.dragover {
  border-color: var(--primary);
  background: var(--primary-light);
}

.dropzone .icon {
  font-size: 48px;
  margin-bottom: 12px;
}

/* ======================================================== */
/* ELEMENTOS Y RESPONSIVE DESIGN PARA MÓVILES               */
/* ======================================================== */
.dashboard-two-cols {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
}

.table-responsive {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.card-import {
  max-width: 800px;
  margin: 0 auto;
  padding: 32px;
}

.quote-totals-grid {
  display: flex;
  justify-content: space-between;
  margin-top: 20px;
  gap: 24px;
}

.quote-shipping-card {
  flex: 1;
  background: #fffbeb;
  border: 1px solid #fde68a;
  border-radius: 8px;
  padding: 16px;
}

.quote-summary-card {
  width: 320px;
}

.sidebar-backdrop {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(3px);
  z-index: 998;
}
.sidebar-backdrop.open {
  display: block;
}

.mobile-toggle {
  display: none;
  background: #ffffff;
  border: 1px solid var(--border);
  color: var(--dark);
  font-size: 22px;
  line-height: 1;
  padding: 8px 12px;
  border-radius: 8px;
  cursor: pointer;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}
.mobile-toggle:active {
  background: #f1f5f9;
}

.mobile-close-btn {
  display: none;
  margin-left: auto;
  background: rgba(255, 255, 255, 0.12);
  color: #ffffff;
  border: none;
  border-radius: 6px;
  font-size: 16px;
  padding: 4px 10px;
  cursor: pointer;
}

@media (max-width: 1024px) {
  body {
    flex-direction: column !important;
    height: 100vh !important;
    overflow: hidden !important;
    width: 100% !important;
  }

  /* Cajón lateral deslizante (Drawer) */
  .sidebar {
    position: fixed !important;
    top: 0 !important;
    bottom: 0 !important;
    left: -320px !important;
    width: 280px !important;
    max-width: 82vw !important;
    z-index: 9999 !important;
    transform: none !important;
    transition: left 0.28s cubic-bezier(0.4, 0, 0.2, 1) !important;
    box-shadow: none !important;
    visibility: hidden;
    display: flex !important;
  }

  .sidebar.open {
    left: 0 !important;
    visibility: visible !important;
    box-shadow: 4px 0 25px rgba(0, 0, 0, 0.4) !important;
  }

  .main-content {
    width: 100% !important;
    max-width: 100vw !important;
    flex: 1 1 auto !important;
    overflow-x: hidden !important;
    margin-left: 0 !important;
  }

  .mobile-toggle {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
  }

  .mobile-close-btn {
    display: inline-block !important;
  }

  /* Cabecera optimizada para pantallas táctiles */
  .topbar {
    height: auto !important;
    min-height: unset !important;
    padding: 12px 14px !important;
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 10px !important;
    flex-shrink: 0 !important;
    background: #ffffff !important;
    border-bottom: 1px solid var(--border) !important;
    box-shadow: 0 2px 6px rgba(0,0,0,0.03) !important;
  }

  .topbar-left {
    display: flex !important;
    align-items: center !important;
    gap: 12px !important;
    width: 100% !important;
  }

  .topbar-title h1 {
    font-size: 17px !important;
    line-height: 1.2 !important;
  }

  .topbar-title p {
    display: none !important;
  }

  .topbar-actions {
    width: 100% !important;
    display: flex !important;
    gap: 8px !important;
  }

  .topbar-actions .btn {
    flex: 1 !important;
    text-align: center !important;
    justify-content: center !important;
    font-size: 13px !important;
    font-weight: 700 !important;
    padding: 10px 8px !important;
  }

  .view-container {
    padding: 12px !important;
  }

  /* Tarjetas KPI del dashboard en cuadrícula de 2 columnas */
  .stats-grid {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 10px !important;
    margin-bottom: 16px !important;
  }

  .stat-card {
    padding: 12px !important;
    gap: 10px !important;
  }

  .stat-icon {
    width: 38px !important;
    height: 38px !important;
    font-size: 18px !important;
  }

  .stat-info h3 {
    font-size: 18px !important;
  }

  .stat-info p {
    font-size: 11px !important;
  }

  .dashboard-two-cols {
    grid-template-columns: 1fr !important;
    gap: 16px !important;
  }

  .card-header {
    padding: 12px 14px !important;
    flex-direction: column !important;
    align-items: flex-start !important;
    gap: 10px !important;
  }

  .card-header .btn {
    width: 100% !important;
    justify-content: center !important;
  }

  /* Filtros y barras de búsqueda en columna completa */
  .filter-bar {
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 8px !important;
    padding: 12px 14px !important;
  }

  .filter-bar input,
  .filter-bar select,
  .filter-bar .btn {
    width: 100% !important;
  }

  /* Tablas: scroll horizontal suave para que no se apiñen los datos */
  .card {
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch !important;
  }

  table.data-table,
  .items-table {
    min-width: 580px !important;
  }

  /* Modales adaptados a smartphone */
  .modal {
    width: 95% !important;
    max-width: 95% !important;
    margin: auto !important;
    max-height: 94vh !important;
    border-radius: 8px !important;
  }

  .modal-body {
    padding: 14px 12px !important;
    max-height: calc(94vh - 120px) !important;
  }

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

  .col-span-2 {
    grid-column: span 1 !important;
  }

  .quote-totals-grid {
    flex-direction: column !important;
    gap: 14px !important;
  }

  .quote-summary-card {
    width: 100% !important;
  }

  .modal-footer {
    flex-direction: column-reverse !important;
    gap: 8px !important;
    padding: 12px 14px !important;
  }

  .modal-footer .btn {
    width: 100% !important;
    justify-content: center !important;
    padding: 10px !important;
  }

  /* Importador de Excel */
  .card-import {
    padding: 16px !important;
  }

  .dropzone {
    padding: 24px 12px !important;
  }

  .dropzone .icon {
    font-size: 36px !important;
  }

  /* Vista previa de documento (Presupuesto / Factura) */
  .doc-sheet {
    padding: 16px !important;
    border-radius: 6px !important;
  }

  .doc-header {
    flex-direction: column !important;
    gap: 12px !important;
  }

  .doc-columns {
    flex-direction: column !important;
    gap: 12px !important;
  }

  .doc-summary {
    width: 100% !important;
  }
}

