/* ============ BASE ============ */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --blue-50: #eff6ff;
  --blue-100: #dbeafe;
  --blue-200: #bfdbfe;
  --blue-500: #3b82f6;
  --blue-600: #2563eb;
  --blue-700: #1d4ed8;
  --gray-50: #f9fafb;
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-300: #d1d5db;
  --gray-500: #6b7280;
  --gray-600: #4b5563;
  --gray-700: #374151;
  --gray-900: #111827;
  --dark: #0a0e1a;
  --red-50: #fef2f2;
  --red-500: #ef4444;
  --red-600: #dc2626;
  --green-50: #ecfdf5;
  --green-500: #10b981;
  --green-600: #059669;
  --radius: 12px;
  --radius-lg: 16px;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --shadow: 0 4px 6px -1px rgba(0,0,0,0.07), 0 2px 4px -1px rgba(0,0,0,0.04);
  --shadow-lg: 0 20px 40px -10px rgba(15,23,42,0.15);
}

html { scroll-behavior: smooth; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  color: var(--gray-900);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  background: white;
  min-height: 100vh;
  padding-bottom: 120px;
}

/* ============ NAV ============ */
.nav {
  position: sticky;
  top: 0;
  z-index: 50;
  background: rgba(255,255,255,0.85);
  backdrop-filter: saturate(180%) blur(12px);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--gray-200);
}
.nav-inner {
  max-width: 1000px;
  margin: 0 auto;
  padding: 0.9rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1.5rem;
}
.logo {
  font-weight: 800;
  font-size: 1.3rem;
  color: var(--gray-900);
  text-decoration: none;
  letter-spacing: -0.02em;
}
.logo span { color: var(--blue-600); }

.nav-right {
  display: flex;
  align-items: center;
  gap: 1rem;
}
.nav-back {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  color: var(--gray-600);
  text-decoration: none;
  font-size: 0.88rem;
  font-weight: 500;
  transition: color 0.15s;
}
.nav-back:hover { color: var(--gray-900); }

.contador {
  background: var(--blue-50);
  color: var(--blue-700);
  padding: 0.4rem 0.85rem;
  border-radius: 20px;
  font-weight: 600;
  font-size: 0.82rem;
  white-space: nowrap;
}
.contador.limite {
  background: var(--red-50);
  color: var(--red-600);
}

/* ============ PROGRESS BAR ============ */
.progress-bar {
  position: sticky;
  top: 60px;
  z-index: 49;
  height: 3px;
  background: var(--gray-100);
}
.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--blue-500), var(--blue-600));
  width: 0%;
  transition: width 0.4s ease;
}
.progress-fill.full {
  background: linear-gradient(90deg, var(--red-500), var(--red-600));
}

/* ============ LAYOUT ============ */
.container {
  max-width: 900px;
  margin: 0 auto;
  padding: 2rem 1.5rem 4rem;
}

.page-header {
  text-align: center;
  margin-bottom: 2rem;
}
.page-header h1 {
  font-size: 2rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  margin-bottom: 0.4rem;
}
.page-header p {
  color: var(--gray-600);
  font-size: 1rem;
}

/* ============ CARDS ============ */
.card {
  background: white;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-lg);
  padding: 1.8rem;
  margin-bottom: 1.2rem;
  box-shadow: var(--shadow-sm);
  transition: box-shadow 0.2s;
}
.card:hover {
  box-shadow: var(--shadow);
}

.card-header {
  display: flex;
  align-items: flex-start;
  gap: 0.9rem;
  margin-bottom: 1.5rem;
}
.card-num {
  width: 32px;
  height: 32px;
  background: linear-gradient(135deg, var(--blue-600), var(--blue-500));
  color: white;
  border-radius: 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
  font-weight: 700;
  flex-shrink: 0;
  box-shadow: 0 4px 10px -3px rgba(37,99,235,0.4);
}
.card-num.icon-folder {
  background: var(--gray-100);
  font-size: 1rem;
  box-shadow: none;
}
.card-header h2 {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--gray-900);
  line-height: 1.3;
}
.card-sub {
  font-size: 0.85rem;
  color: var(--gray-500);
  margin-top: 0.15rem;
}

/* ============ FORM ============ */
.row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin-bottom: 1rem;
}
.row:last-child { margin-bottom: 0; }
.row-3 {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 1rem;
  margin-bottom: 1rem;
}
.field {
  display: flex;
  flex-direction: column;
}
.field label {
  font-size: 0.83rem;
  color: var(--gray-700);
  margin-bottom: 0.35rem;
  font-weight: 500;
}
.field input,
.field select {
  padding: 0.7rem 0.9rem;
  border: 1.5px solid var(--gray-200);
  border-radius: 10px;
  font-size: 0.95rem;
  font-family: inherit;
  color: var(--gray-900);
  background: white;
  transition: all 0.15s;
}
.field input:hover,
.field select:hover {
  border-color: var(--gray-300);
}
.field input:focus,
.field select:focus {
  outline: none;
  border-color: var(--blue-600);
  box-shadow: 0 0 0 4px rgba(37,99,235,0.1);
}
.field input[readonly] {
  background: var(--gray-50);
  color: var(--gray-600);
}

/* ============ LINEAS ============ */
.linea-item {
  display: grid;
  grid-template-columns: 3fr 1fr 1.2fr 1.2fr auto;
  gap: 0.6rem;
  margin-bottom: 0.6rem;
  align-items: center;
}
.linea-item input {
  padding: 0.65rem 0.8rem;
  border: 1.5px solid var(--gray-200);
  border-radius: 10px;
  font-size: 0.92rem;
  font-family: inherit;
  width: 100%;
  transition: border-color 0.15s;
}
.linea-item input:focus {
  outline: none;
  border-color: var(--blue-600);
  box-shadow: 0 0 0 4px rgba(37,99,235,0.1);
}
.linea-item .total-linea {
  font-weight: 700;
  text-align: right;
  font-size: 0.95rem;
  color: var(--gray-900);
}
.btn-remove {
  background: var(--gray-100);
  color: var(--gray-500);
  border: none;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 1.1rem;
  transition: all 0.15s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.btn-remove:hover {
  background: var(--red-50);
  color: var(--red-600);
}
.btn-add {
  background: var(--blue-50);
  color: var(--blue-700);
  border: 1.5px dashed var(--blue-200);
  padding: 0.75rem 1rem;
  border-radius: 10px;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.9rem;
  width: 100%;
  margin-top: 0.5rem;
  font-family: inherit;
  transition: all 0.15s;
}
.btn-add:hover {
  background: var(--blue-100);
  border-color: var(--blue-500);
}

/* ============ TOTALES ============ */
.totales {
  background: linear-gradient(135deg, var(--gray-50), var(--blue-50));
  border: 1px solid var(--blue-100);
  border-radius: 12px;
  padding: 1.3rem;
  margin-top: 1.2rem;
}
.totales .fila {
  display: flex;
  justify-content: space-between;
  padding: 0.4rem 0;
  font-size: 0.95rem;
  color: var(--gray-700);
}
.totales .fila.total {
  border-top: 2px solid var(--blue-200);
  margin-top: 0.6rem;
  padding-top: 1rem;
  font-size: 1.35rem;
  font-weight: 800;
  color: var(--blue-700);
  letter-spacing: -0.02em;
}

/* ============ FACTURAS GUARDADAS ============ */
.factura-guardada {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.1rem;
  border: 1px solid var(--gray-200);
  border-radius: 10px;
  margin-bottom: 0.6rem;
  background: white;
  transition: all 0.15s;
}
.factura-guardada:hover {
  border-color: var(--blue-200);
  background: var(--blue-50);
}
.factura-guardada .info strong {
  display: block;
  font-size: 0.95rem;
  color: var(--gray-900);
}
.factura-guardada .info small {
  color: var(--gray-500);
  font-size: 0.83rem;
}
.factura-guardada .acciones-mini {
  display: flex;
  gap: 0.4rem;
}
.factura-guardada button {
  padding: 0.4rem 0.75rem;
  font-size: 0.8rem;
  border-radius: 7px;
  border: 1px solid var(--gray-200);
  background: white;
  cursor: pointer;
  font-family: inherit;
  font-weight: 500;
  color: var(--gray-700);
  transition: all 0.15s;
}
.factura-guardada button:hover {
  border-color: var(--blue-600);
  color: var(--blue-700);
  background: white;
}

.empty {
  text-align: center;
  padding: 2rem 1rem;
  color: var(--gray-500);
  font-size: 0.92rem;
  background: var(--gray-50);
  border-radius: 10px;
  border: 1px dashed var(--gray-200);
}

/* ============ ACTION BAR (sticky bottom) ============ */
.action-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(255,255,255,0.92);
  backdrop-filter: saturate(180%) blur(12px);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
  border-top: 1px solid var(--gray-200);
  padding: 0.85rem 1.5rem;
  z-index: 40;
  box-shadow: 0 -10px 30px -15px rgba(15,23,42,0.15);
}
.action-bar-inner {
  max-width: 900px;
  margin: 0 auto;
  display: flex;
  gap: 0.6rem;
  justify-content: flex-end;
  flex-wrap: wrap;
}

/* ============ BOTONES ============ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.75rem 1.3rem;
  border-radius: 10px;
  font-weight: 600;
  font-size: 0.92rem;
  text-decoration: none;
  cursor: pointer;
  border: none;
  font-family: inherit;
  transition: all 0.2s ease;
  white-space: nowrap;
}
.btn-primary {
  background: var(--blue-600);
  color: white;
  box-shadow: 0 1px 2px rgba(37,99,235,0.3), 0 4px 12px -4px rgba(37,99,235,0.4);
}
.btn-primary:hover {
  background: var(--blue-700);
  transform: translateY(-1px);
  box-shadow: 0 4px 8px rgba(37,99,235,0.3), 0 8px 20px -4px rgba(37,99,235,0.5);
}
.btn-secondary {
  background: white;
  color: var(--gray-900);
  border: 1.5px solid var(--gray-300);
}
.btn-secondary:hover {
  border-color: var(--gray-500);
  transform: translateY(-1px);
}
.btn-ghost-action {
  background: transparent;
  color: var(--gray-600);
}
.btn-ghost-action:hover {
  background: var(--gray-100);
  color: var(--gray-900);
}

/* ============ MODAL ============ */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(10,14,26,0.6);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 100;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  animation: fadeIn 0.2s ease;
}
.modal-overlay.active {
  display: flex;
}
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal {
  background: white;
  border-radius: 20px;
  padding: 2.2rem;
  max-width: 420px;
  width: 100%;
  text-align: center;
  box-shadow: 0 30px 60px -15px rgba(15,23,42,0.4);
  animation: slideUp 0.3s ease;
}
@keyframes slideUp {
  from { transform: translateY(20px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.modal-icon {
  font-size: 3rem;
  margin-bottom: 1rem;
}
.modal h3 {
  font-size: 1.3rem;
  font-weight: 800;
  margin-bottom: 0.7rem;
  letter-spacing: -0.02em;
}
.modal p {
  color: var(--gray-600);
  margin-bottom: 1.5rem;
  font-size: 0.95rem;
  line-height: 1.55;
}
.modal-acciones {
  display: flex;
  gap: 0.6rem;
  justify-content: center;
}

/* ============ RESPONSIVE ============ */
@media (max-width: 700px) {
  .row, .row-3 { grid-template-columns: 1fr; }
  .linea-item {
    grid-template-columns: 1fr 1fr;
    padding-bottom: 0.8rem;
    border-bottom: 1px solid var(--gray-100);
    margin-bottom: 0.8rem;
  }
  .linea-item .total-linea {
    grid-column: span 2;
    text-align: left;
    font-size: 1.05rem;
    color: var(--blue-600);
  }
  .nav-inner { padding: 0.75rem 1rem; }
  .nav-back span { display: none; }
  .contador { font-size: 0.75rem; padding: 0.35rem 0.7rem; }
  .container { padding: 1.5rem 1rem 4rem; }
  .card { padding: 1.3rem; }
  .page-header h1 { font-size: 1.6rem; }
  .action-bar { padding: 0.7rem 1rem; }
  .action-bar-inner { gap: 0.4rem; }
  .action-bar .btn {
    padding: 0.65rem 1rem;
    font-size: 0.85rem;
    flex: 1;
  }
  .action-bar .btn svg { display: none; }
  .totales .fila.total { font-size: 1.15rem; }
}