:root {
  --bg-color: #0f172a;
  --surface-color: rgba(30, 41, 59, 0.7);
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --accent: #8b5cf6;
  --success: #10b981;
  --danger: #ef4444;
  --border-color: rgba(255, 255, 255, 0.1);
  --font-family: 'Inter', sans-serif;
  --border-radius: 12px;
  --transition: all 0.3s ease;
}

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

body {
  font-family: var(--font-family);
  background-color: var(--bg-color);
  color: var(--text-main);
  background-image: 
    radial-gradient(at 0% 0%, rgba(59, 130, 246, 0.15) 0px, transparent 50%),
    radial-gradient(at 100% 0%, rgba(139, 92, 246, 0.15) 0px, transparent 50%);
  background-attachment: fixed;
  min-height: 100vh;
  display: flex;
}

/* Sidebar */
.sidebar {
  width: 260px;
  background: var(--surface-color);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-right: 1px solid var(--border-color);
  padding: 2rem 1.5rem;
  display: flex;
  flex-direction: column;
  position: fixed;
  height: 100vh;
  z-index: 100;
}

.brand {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text-main);
  margin-bottom: 2.5rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.brand span {
  background: linear-gradient(135deg, var(--primary), var(--accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.875rem 1rem;
  color: var(--text-muted);
  text-decoration: none;
  border-radius: var(--border-radius);
  margin-bottom: 0.5rem;
  transition: var(--transition);
  font-weight: 500;
}

.nav-link:hover, .nav-link.active {
  background: rgba(255,255,255,0.05);
  color: var(--text-main);
}

.nav-link.active {
  border-left: 4px solid var(--primary);
  background: linear-gradient(90deg, rgba(59, 130, 246, 0.1) 0%, transparent 100%);
}

/* Main Content */
.main-content {
  flex: 1;
  margin-left: 260px;
  padding: 2.5rem 3rem;
}

.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 2.5rem;
}

.page-title {
  font-size: 1.875rem;
  font-weight: 600;
  letter-spacing: -0.025em;
}

/* Cards */
.grid-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 1.5rem;
  margin-bottom: 2.5rem;
}

.card {
  background: var(--surface-color);
  border: 1px solid var(--border-color);
  backdrop-filter: blur(12px);
  border-radius: var(--border-radius);
  padding: 1.5rem;
  transition: var(--transition);
}

.card:hover {
  transform: translateY(-4px);
  box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.3);
  border-color: rgba(255, 255, 255, 0.2);
}

.card-title {
  color: var(--text-muted);
  font-size: 0.875rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.5rem;
}

.card-value {
  font-size: 2rem;
  font-weight: 700;
  color: var(--text-main);
}

/* Tables */
.table-container {
  background: var(--surface-color);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius);
  overflow-x: auto;
  backdrop-filter: blur(12px);
}

table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
}

th, td {
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border-color);
}

th {
  color: var(--text-muted);
  font-weight: 500;
  font-size: 0.875rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

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

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

/* Forms & Buttons */
.btn {
  background: var(--primary);
  color: white;
  border: none;
  padding: 0.625rem 1.25rem;
  border-radius: 8px;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  text-decoration: none;
}

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

.btn-sync {
  background: var(--accent);
}

.btn-sync:hover {
  background: #7c3aed;
}

.input, select {
  background: rgba(15, 23, 42, 0.5);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  padding: 0.5rem 0.75rem;
  border-radius: 6px;
  width: 100%;
  transition: var(--transition);
  font-family: inherit;
}

.input:focus, select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2);
}

/* Utilities */
.badge {
  padding: 0.25rem 0.75rem;
  border-radius: 9999px;
  font-size: 0.75rem;
  font-weight: 500;
}

.badge.success { background: rgba(16, 185, 129, 0.2); color: var(--success); }
.badge.primary { background: rgba(59, 130, 246, 0.2); color: var(--primary); }
.badge.danger { background: rgba(239, 68, 68, 0.2); color: var(--danger); }

/* Skeleton Loading Animation */
@keyframes shimmer {
  0% { background-position: -1000px 0; }
  100% { background-position: 1000px 0; }
}

.skeleton {
  background: linear-gradient(90deg, rgba(255,255,255,0.05) 25%, rgba(255,255,255,0.1) 50%, rgba(255,255,255,0.05) 75%);
  background-size: 1000px 100%;
  animation: shimmer 2s infinite linear;
  border-radius: 4px;
}

/* ===================== MOBILE / RESPONSIVE ===================== */

/* Hamburger button — solo visible en mobile */
.mobile-menu-btn {
  display: none;
  position: fixed;
  top: 1rem;
  left: 1rem;
  z-index: 9999;
  background: #1e293b;
  border: 1px solid rgba(255,255,255,0.2);
  color: #f8fafc;
  width: 46px;
  height: 46px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 1.5rem;
  line-height: 1;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 12px rgba(0,0,0,.3);
  padding: 0;
}

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 90;
  backdrop-filter: blur(2px);
}

/* === Tablet (<= 1024px): reducir paddings y grids === */
@media (max-width: 1024px) {
  .main-content { padding: 2rem 1.5rem; }
  .grid-cards { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 1rem; }
  th, td { padding: .75rem 1rem; }
}

/* === Mobile (<= 900px): sidebar deslizable, todo a 1 col === */
@media (max-width: 900px) {
  body { display: block !important; }

  .mobile-menu-btn { display: inline-flex !important; }

  .sidebar {
    transform: translateX(-100%);
    transition: transform .3s ease;
    width: 260px;
    padding: 4rem 1rem 1.25rem;
    z-index: 9998;
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-overlay.show { display: block !important; }

  .brand { margin-bottom: 1.5rem; font-size: 1.25rem; }
  .nav-link { padding: .7rem .85rem; font-size: .9rem; }

  .main-content {
    margin-left: 0;
    padding: 4rem 1rem 2rem;
    width: 100%;
  }

  .header {
    flex-direction: column;
    align-items: flex-start;
    gap: .75rem;
    margin-bottom: 1.25rem;
  }
  .page-title { font-size: 1.35rem; }

  .grid-cards {
    grid-template-columns: 1fr;
    gap: .75rem;
    margin-bottom: 1.25rem;
  }

  .card { padding: 1rem; }
  .card-value { font-size: 1.5rem; }

  /* Tablas con scroll horizontal */
  .table-container { border-radius: 8px; }
  table { font-size: .8rem; min-width: 600px; }
  th, td { padding: .55rem .65rem; white-space: nowrap; }

  /* Forms / inputs */
  .btn { padding: .55rem 1rem; font-size: .85rem; }
  .input, select { font-size: 16px; padding: .6rem .75rem; } /* 16px evita zoom iOS */

  /* KPI grids (index.php usa inline grid-template-columns) */
  .kpi-grid { grid-template-columns: 1fr !important; }

  /* validate.php */
  .val-grid { grid-template-columns: 1fr !important; gap: 1rem !important; }
  .val-card { padding: 1rem !important; }
  .upload-zone { padding: 1.5rem 1rem !important; }
  .summary-bar { flex-direction: column !important; }
  .sum-cell { border-right: none !important; border-bottom: 1px solid rgba(99,102,241,.12); }

  /* Modal de boletas (legacy) */
  .modal-bg .modal { width: 95% !important; max-height: 90vh !important; }

  /* Forms de costos extras en orders.php */
  .add-form { flex-direction: column; }
  .add-form .input { width: 100% !important; }
  .add-form .btn { width: 100%; justify-content: center; }
}

/* === Mobile pequeño (<= 480px): ajustes finos === */
@media (max-width: 480px) {
  .main-content { padding: 3.75rem .75rem 1.5rem; }
  .page-title { font-size: 1.15rem; }
  table { font-size: .75rem; }
  th, td { padding: .45rem .55rem; }
  .btn { padding: .5rem .85rem; font-size: .8rem; }
}
