:root {
  --bg: #e5e9f0;
  --card: #ffffff;
  --ink: #1a1c23;
  --muted: #8b92a5;
  --line: #f0f2f5;
  --accent: #4a72ff; 
  --accent-hover: #3b5bcc;
  --soft: #f4f6f9;
  --warn: #fff9e6;
  --highlight: #d2f669;
}

body.dark-mode {
  --bg: #0f1117;
  --card: #181b26;
  --ink: #f0f3f8;
  --muted: #8e96aa;
  --line: #262a3b;
  --accent: #5c82ff;
  --accent-hover: #4a72ff;
  --soft: #1f2333;
  --warn: #2c2616;
  --highlight: #b6e338;
}

* { box-sizing: border-box; }
body { 
  margin: 0; 
  background: var(--bg); 
  color: var(--ink); 
  font: 14px/1.5 Inter, ui-sans-serif, system-ui, -apple-system, sans-serif; 
  transition: background 0.3s, color 0.3s;
}
.wrap { max-width: 1100px; margin: auto; padding: 30px 20px 80px; }
.top { display: flex; justify-content: space-between; align-items: flex-start; gap: 18px; margin-bottom: 24px; }
.eyebrow { text-transform: uppercase; letter-spacing: .12em; font-size: 11px; font-weight: 800; color: var(--accent); }
h1 { font-size: clamp(24px, 3vw, 32px); line-height: 1.1; letter-spacing: -0.03em; margin: 8px 0; font-weight: 600; }
p { color: var(--muted); margin: 6px 0 0; }
.badge { background: var(--card); border-radius: 999px; padding: 8px 14px; font-size: 12px; color: var(--muted); box-shadow: 0 2px 10px rgba(0,0,0,0.03); white-space: nowrap; }

/* Layout en cascada */
.cascade { display: flex; flex-direction: column; gap: 24px; }
.card { 
  background: var(--card); 
  border-radius: 14px; 
  padding: 24px; 
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.04); 
}
.card-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 15px; margin-bottom: 18px; flex-wrap: wrap; }
.card h2 { font-size: 18px; font-weight: 600; margin: 0 0 4px; }
.sub { font-size: 13px; color: var(--muted); margin: 0; }

.fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; }
.field label { display: block; font-size: 12px; color: var(--muted); margin: 0 0 6px; font-weight: 600; }
select option {
  background-color: var(--card);
  color: var(--ink);
}
.field input, .field select, .field textarea { 
  width: 100%; 
  border: 1px solid var(--line); 
  border-radius: 8px; 
  padding: 10px 12px; 
  font: inherit; 
  background: var(--soft); 
  color: var(--ink); 
  outline: none; 
  transition: all 0.2s;
}
.field textarea { resize: vertical; min-height: 60px; }
.field input:focus, .field select:focus, .field textarea:focus { background: var(--card); border-color: var(--accent); box-shadow: 0 0 0 3px rgba(74,114,255,0.15); }

.results { background: var(--soft); border-radius: 10px; padding: 18px; margin-top: 20px; display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 15px; }
.metric small { display: block; color: var(--muted); font-size: 12px; margin-bottom: 4px; }
.metric strong { font-size: 22px; font-weight: 600; letter-spacing: -0.02em; }
.metric.primary strong { color: var(--accent); }

.actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 18px; align-items: center; }
.btn { 
  border: none; 
  background: var(--soft); 
  color: var(--ink); 
  border-radius: 8px; 
  padding: 10px 16px; 
  font: inherit; 
  font-weight: 600; 
  cursor: pointer; 
  transition: all 0.2s;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  text-decoration: none;
}
.btn.primary { background: var(--accent); color: white; }
.btn.secondary { background: var(--highlight); color: #2d3b0e; }
.btn.dark { background: #1a1c23; color: white; }
body.dark-mode .btn.dark { background: #3b4256; color: white; }
.btn.danger { background: #fff0f0; color: #d93838; }
body.dark-mode .btn.danger { background: #3d1c1c; color: #ff6b6b; }
.btn:hover { filter: brightness(0.95); transform: translateY(-1px); }

/* Switch de Modo Oscuro */
.theme-switch-wrapper { display: flex; align-items: center; gap: 8px; font-size: 12px; font-weight: 600; color: var(--muted); }
.theme-switch { position: relative; display: inline-block; width: 44px; height: 24px; }
.theme-switch input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background-color: #ccc; transition: .3s; border-radius: 24px; }
.slider:before { position: absolute; content: ""; height: 18px; width: 18px; left: 3px; bottom: 3px; background-color: white; transition: .3s; border-radius: 50%; }
input:checked + .slider { background-color: var(--accent); }
input:checked + .slider:before { transform: translateX(20px); }

/* Tablas */
.table-wrap { overflow-x: auto; margin-top: 15px; border-radius: 8px; border: 1px solid var(--line); }
table { border-collapse: collapse; width: 100%; min-width: 750px; background: var(--card); }
th, td { text-align: left; padding: 12px 14px; border-bottom: 1px solid var(--line); font-size: 13px; vertical-align: middle; }
th { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .08em; font-weight: 600; background: var(--soft); }
td strong { font-size: 14px; font-weight: 600; }
.num-badge { display: inline-flex; align-items: center; justify-content: center; background: var(--soft); border-radius: 6px; width: 26px; height: 26px; font-size: 12px; color: var(--muted); font-weight: 600; }
.delete { border: 0; background: #fff0f0; border-radius: 6px; padding: 6px 10px; color: #d93838; cursor: pointer; font-weight: 600; transition: background 0.2s; }
body.dark-mode .delete { background: #3d1c1c; color: #ff6b6b; }
.delete:hover { background: #ffd6d6; }

.table-input { width: 100%; border: 1px solid transparent; background: transparent; color: var(--ink); padding: 6px; font: inherit; outline: none; border-radius: 6px; transition: all 0.2s; }
.table-input:hover, .table-input:focus { border-color: var(--line); background: var(--soft); }
.table-num-input { width: 75px; border: 1px solid var(--line); background: var(--soft); color: var(--ink); border-radius: 6px; padding: 6px; font: inherit; outline: none; text-align: center; }
.table-num-input:focus { border-color: var(--accent); background: var(--card); }

/* Drag and Drop reordering */
.drag-handle {
  cursor: grab;
  user-select: none;
  color: var(--muted);
  font-size: 16px;
  margin-right: 6px;
}
.drag-handle:active { cursor: grabbing; }
tr.drag-over { border-top: 2px solid var(--accent) !important; background: var(--soft); }

/* Modales / Popups */
.modal-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
}
.modal-box {
  background: var(--card);
  color: var(--ink);
  border-radius: 14px;
  width: 100%;
  max-width: 500px;
  padding: 24px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.25);
  animation: modalFadeIn 0.2s ease-out;
}
@keyframes modalFadeIn {
  from { opacity: 0; transform: translateY(-10px); }
  to { opacity: 1; transform: translateY(0); }
}
.modal-box h3 {
  margin: 0 0 16px;
  font-size: 18px;
  font-weight: 600;
  color: var(--accent);
}

/* Estilo para fila de descuento */
.discount-row {
  background-color: rgba(210, 246, 105, 0.25) !important;
}
body.dark-mode .discount-row {
  background-color: rgba(182, 227, 56, 0.15) !important;
}
.discount-badge {
  display: inline-block;
  background: var(--highlight);
  color: #2d3b0e;
  font-weight: bold;
  font-size: 11px;
  padding: 2px 6px;
  border-radius: 4px;
  margin-right: 6px;
}

.note { font-size: 12px; color: var(--muted); margin-top: 16px; line-height: 1.5; }
.notice { background: var(--warn); border-radius: 10px; padding: 14px; font-size: 13px; color: #856a20; margin-top: 24px; line-height: 1.5; border: 1px solid #f2e4b6; }
body.dark-mode .notice { color: #f5d77f; border-color: #52441a; }
footer { color: var(--muted); font-size: 12px; text-align: center; margin-top: 30px; }

/* Vista para Impresión / PDF estilizado en formato Light con Paleta de Colores Katio */
@media print {
  .wrap { display: none !important; }
  .pdf-container { display: block !important; }
}
.pdf-container {
  display: none;
  background: #ffffff;
  color: #1f2421;
  font-family: Arial, Helvetica, sans-serif;
  padding: 40px;
  max-width: 800px;
  margin: auto;
  border-radius: 8px;
}
.pdf-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 25px; border-bottom: 2px solid #4a72ff; padding-bottom: 20px; }
.pdf-brand-title { font-size: 24px; font-weight: 800; line-height: 1.1; letter-spacing: 1px; color: #4a72ff; }
.pdf-brand-sub { font-size: 12px; color: #555; margin-top: 6px; line-height: 1.4; }
.pdf-meta { text-align: right; font-size: 13px; line-height: 1.5; }
.pdf-quote-num { font-size: 18px; font-weight: bold; margin-bottom: 4px; color: #1a1c23; }
.pdf-client-title { font-size: 13px; font-weight: 700; margin: 20px 0 10px; text-transform: uppercase; letter-spacing: 0.05em; background: #f4f6f9; padding: 10px 14px; border-left: 4px solid #4a72ff; border-radius: 4px; }
.pdf-intro-text { font-size: 12px; color: #444; margin-bottom: 15px; line-height: 1.5; }
.pdf-table { width: 100%; border-collapse: collapse; margin-bottom: 20px; }
.pdf-table th { background: #f4f6f9; border-top: 1px solid #e5e9f0; border-bottom: 2px solid #4a72ff; padding: 10px 8px; font-size: 11px; text-align: left; color: #4a72ff; font-weight: 700; }
.pdf-table td { border-bottom: 1px solid #eee; padding: 10px 8px; font-size: 12px; vertical-align: top; }
.pdf-item-desc { font-size: 11px; color: #666; margin-top: 3px; font-style: italic; }

/* Fila especial para descuento en el PDF */
.pdf-table tr.pdf-discount-row td {
  background-color: #d2f669 !important;
  color: #4a72ff !important;
  font-size: 13px !important;
  font-weight: bold !important;
  border-top: 2px solid #4a72ff !important;
  border-bottom: 2px solid #4a72ff !important;
  padding: 12px 8px !important;
}

.pdf-totals-container { margin-top: 15px; display: flex; justify-content: flex-end; }
.pdf-totals-box { width: 280px; font-size: 13px; }
.pdf-total-row { display: flex; justify-content: space-between; padding: 5px 0; border-bottom: 1px solid #eee; }
.pdf-total-row.grand { border-top: 2px solid #4a72ff; border-bottom: none; font-size: 16px; font-weight: bold; color: #4a72ff; padding-top: 8px; margin-top: 4px; }

.pdf-validity { font-size: 11px; color: #666; margin-top: 15px; font-weight: 600; }
.pdf-terms { margin-top: 25px; font-size: 11px; line-height: 1.6; border-top: 1px dashed #ccc; padding-top: 15px; color: #444; }
.pdf-terms ol { padding-left: 18px; margin-top: 6px; }

.pdf-bank-info { 
  margin-top: 25px; 
  background: #f7f9fc; 
  border: 1px solid #e1e8f5; 
  border-radius: 8px; 
  padding: 16px; 
}
.pdf-bank-title { font-size: 12px; font-weight: bold; color: #4a72ff; text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 8px; }
.pdf-bank-details { font-size: 12px; color: #333; line-height: 1.6; }
.pdf-bank-badges { display: flex; gap: 15px; margin-top: 8px; flex-wrap: wrap; }
.bank-badge { background: #ffffff; border: 1px solid #c5d4fb; border-radius: 6px; padding: 6px 12px; font-weight: 600; color: #1a1c23; font-size: 12px; box-shadow: 0 1px 3px rgba(0,0,0,0.04); }

.pdf-footer-social { text-align: center; margin-top: 30px; font-size: 12px; font-weight: bold; color: #666; }
