:root {
  --brand: #1a56db;
  --brand-dark: #1547c0;
  --brand-light: #e1effe;
  --bg: #f9fafb;
  --surface: #ffffff;
  --border: #e5e7eb;
  --text: #111827;
  --text-muted: #6b7280;
  --danger: #ef4444;
  --danger-light: #fee2e2;
  --success: #10b981;
  --success-light: #d1fae5;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.1), 0 2px 4px -1px rgba(0,0,0,0.06);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

input[type=number]::-webkit-inner-spin-button,
input[type=number]::-webkit-outer-spin-button { -webkit-appearance: none; appearance: none; margin: 0; }
input[type=number] { -moz-appearance: textfield; appearance: textfield; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

/* ── NAV ─────────────────────────────────────────────── */
nav {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 1.5rem;
  display: flex;
  align-items: center;
  gap: 2rem;
  height: 56px;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow);
}

.nav-brand {
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--brand);
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

nav a {
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 500;
  padding: 0.25rem 0;
  border-bottom: 2px solid transparent;
  transition: color 0.15s, border-color 0.15s;
}

nav a:hover, nav a.active {
  color: var(--brand);
  border-bottom-color: var(--brand);
}

/* ── LAYOUT ──────────────────────────────────────────── */
main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1.5rem;
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.5rem;
}

.page-title {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--text);
}

/* ── CARDS ───────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow);
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow);
}

.kpi-label {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.5rem;
}

.kpi-value {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--text);
}

.kpi-value.brand { color: var(--brand); }

.kpi-secret-wrap {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.btn-eye {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  padding: 0;
  line-height: 1;
  flex-shrink: 0;
}

.btn-eye:hover { color: var(--text); }

/* ── BUTTONS ─────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.5rem 1rem;
  font-size: 0.875rem;
  font-weight: 500;
  border-radius: var(--radius);
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s, box-shadow 0.15s;
  white-space: nowrap;
}

.btn-primary {
  background: var(--brand);
  color: #fff;
}

.btn-primary:hover { background: var(--brand-dark); }

.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
}

.btn-secondary:hover { background: var(--bg); }

.btn-danger {
  background: var(--danger);
  color: #fff;
}

.btn-danger:hover { background: #dc2626; }

.btn-warning { background: #f59e0b; color: #fff; }
.btn-warning:hover { background: #d97706; }

.btn-success { background: #059669; color: #fff; }
.btn-success:hover { background: #047857; }

.btn-danger-outline {
  background: transparent;
  color: var(--danger);
  border-color: var(--danger);
}

.btn-danger-outline:hover {
  background: var(--danger);
  color: #fff;
}

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border-color: transparent;
}

.btn-ghost:hover { background: var(--bg); }
.btn-ghost.active { background: #fee2e2; color: #991b1b; border-color: #fca5a5; }

.btn-sm {
  padding: 0.3rem 0.6rem;
  font-size: 0.8rem;
}

.btn-pdf {
  background: #fff7ed;
  color: #c2410c;
  border-color: #fed7aa;
}

.btn-pdf:hover { background: #ffedd5; }

/* ── TABLES ──────────────────────────────────────────── */
.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

thead th {
  text-align: left;
  padding: 0.75rem 1rem;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}

tbody td {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

tbody tr:last-child td { border-bottom: none; }

tbody tr:hover { background: #f9fafb; }

/* ── BADGES ──────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.2rem 0.6rem;
  border-radius: 9999px;
  font-size: 0.75rem;
  font-weight: 600;
  white-space: nowrap;
}

.badge-pending      { background: #f3f4f6; color: #374151; }
.badge-reprogramado { background: #fef3c7; color: #92400e; }
.badge-delivered    { background: #def7ec; color: #057a55; }
.badge-saldo        { background: #fee2e2; color: #991b1b; }

/* ── FORMS ───────────────────────────────────────────── */
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.form-grid.cols-3 { grid-template-columns: 1fr 1fr 1fr; }
.form-grid.cols-1 { grid-template-columns: 1fr; }

.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.form-group.span-2 { grid-column: span 2; }
.form-group.span-3 { grid-column: span 3; }

label {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-muted);
}

input:not([type="checkbox"]), select, textarea {
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.875rem;
  color: var(--text);
  background: var(--surface);
  width: 100%;
  transition: border-color 0.15s, box-shadow 0.15s;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(26, 86, 219, 0.1);
}

.field-error {
  border-color: var(--danger) !important;
  box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.15) !important;
}

textarea { resize: vertical; min-height: 80px; }

.field-hint {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* ── SECTION HEADINGS IN FORMS ───────────────────────── */
.form-section-title {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--brand);
  border-bottom: 1px solid var(--brand-light);
  padding-bottom: 0.4rem;
  margin-top: 0.5rem;
  margin-bottom: 0.5rem;
  grid-column: 1 / -1;
}

/* ── MODAL ───────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  z-index: 1000;
  padding: 1.5rem;
  overflow-y: auto;
}

.modal-overlay.hidden { display: none; }

.modal {
  background: var(--surface);
  border-radius: 12px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.2);
  width: 100%;
  max-width: 760px;
  animation: fadeUp 0.2s ease;
}

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border);
}

.modal-title {
  font-size: 1.1rem;
  font-weight: 700;
}

.modal-close {
  background: none;
  border: none;
  font-size: 1.3rem;
  cursor: pointer;
  color: var(--text-muted);
  line-height: 1;
  padding: 0.2rem;
}

.modal-body {
  padding: 1.5rem;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border);
}

/* ── SEARCHABLE DROPDOWN ─────────────────────────────── */
.dropdown-wrap {
  position: relative;
}

.dropdown-list {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  max-height: 220px;
  overflow-y: auto;
  z-index: 500;
  display: none;
}

.dropdown-list.open { display: block; }

.dropdown-item {
  padding: 0.5rem 0.75rem;
  font-size: 0.85rem;
  cursor: pointer;
  transition: background 0.1s;
}

.dropdown-item:hover { background: var(--brand-light); color: var(--brand); }
.dropdown-item.custom { color: var(--brand); font-weight: 600; }

/* ── ITEMS LIST ──────────────────────────────────────── */
#items-container {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.item-row {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem;
}

.item-row-grid {
  display: grid;
  grid-template-columns: 1fr 80px 110px 32px;
  gap: 0.5rem;
  align-items: start;
}

.item-custom-name {
  margin-top: 0.5rem;
}

.remove-item-btn {
  background: none;
  border: none;
  color: var(--danger);
  font-size: 1.1rem;
  cursor: pointer;
  padding: 0.35rem;
  border-radius: 4px;
  line-height: 1;
  align-self: center;
}

.remove-item-btn:hover { background: var(--danger-light); }

/* ── FINANCE BOX ─────────────────────────────────────── */
.finance-box {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.finance-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.6rem 1rem;
  font-size: 0.875rem;
  border-bottom: 1px solid var(--border);
}

.finance-row:last-child { border-bottom: none; }

.finance-row.total {
  background: var(--brand);
  color: #fff;
  font-weight: 700;
  font-size: 1rem;
}

.finance-row.saldo { background: #fef3c7; font-weight: 600; }

/* ── TOAST ───────────────────────────────────────────── */
#toast-container {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  z-index: 2000;
}

.toast {
  background: #1f2937;
  color: #fff;
  padding: 0.75rem 1.25rem;
  border-radius: var(--radius);
  font-size: 0.875rem;
  box-shadow: var(--shadow-md);
  animation: slideIn 0.2s ease;
  max-width: 320px;
}

.toast.success { background: #065f46; }
.toast.error   { background: #991b1b; }

@keyframes slideIn {
  from { opacity: 0; transform: translateX(12px); }
  to   { opacity: 1; transform: translateX(0); }
}

/* ── BATCH BAR ───────────────────────────────────────── */
.batch-bar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem 1rem;
  background: var(--brand-light);
  border: 1px solid var(--brand);
  border-radius: var(--radius);
  margin-bottom: 1rem;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--brand);
}

.batch-bar.hidden { display: none; }

/* ── ORDER CHECKBOXES ────────────────────────────────── */
.order-checkbox, #select-all-cb {
  width: 35px;
  height: 35px;
  cursor: pointer;
  accent-color: var(--brand);
}

/* ── STATUS FILTER ───────────────────────────────────── */
.filter-bar {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}

.filter-btn {
  padding: 0.35rem 0.8rem;
  border-radius: 9999px;
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  color: var(--text-muted);
}

.filter-btn:hover, .filter-btn.active {
  background: var(--brand);
  color: #fff;
  border-color: var(--brand);
}

/* ── DETAIL LAYOUT ───────────────────────────────────── */
.detail-grid {
  display: grid;
  grid-template-columns: 1fr 360px;
  gap: 1.25rem;
  align-items: start;
}

.detail-section {
  margin-bottom: 1.25rem;
}

.detail-section-title {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 0.6rem;
}

.detail-row {
  display: flex;
  justify-content: space-between;
  font-size: 0.875rem;
  padding: 0.35rem 0;
  border-bottom: 1px solid var(--border);
}

.detail-row:last-child { border-bottom: none; }

.detail-label { color: var(--text-muted); }

.pdf-buttons {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
}

/* ── COLUMN FILTERS (Excel-style) ───────────────────── */
.th-filterable { vertical-align: top; }

.col-filter-select,
.col-filter-input {
  display: block;
  margin-top: 4px;
  width: 100%;
  padding: 3px 6px;
  font-size: 0.72rem;
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  cursor: pointer;
  transition: border-color 0.15s;
}

.col-filter-select:focus,
.col-filter-input:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 2px rgba(26,86,219,0.1);
}

.col-filter-select.active,
.col-filter-input.active {
  border-color: var(--brand);
  background: var(--brand-light);
}

.product-count-badge {
  display: inline-block;
  margin-left: 5px;
  font-size: 0.7rem;
  font-weight: 500;
  color: var(--text-muted);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 9999px;
  padding: 1px 7px;
  text-transform: none;
  letter-spacing: 0;
  vertical-align: middle;
}

/* ── WHATSAPP BUTTON ─────────────────────────────────── */
.btn-wa {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: none;
  background: #25D366;
  color: #fff;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s, transform 0.1s;
}
.btn-wa:hover { background: #1ebe5d; transform: scale(1.1); }

/* ── RESPONSIVE ──────────────────────────────────────── */
@media (max-width: 640px) {
  .form-grid { grid-template-columns: 1fr; }
  .form-group.span-2, .form-group.span-3 { grid-column: span 1; }
  .detail-grid { grid-template-columns: 1fr; }
  .item-row-grid { grid-template-columns: 1fr 70px 95px 32px; }
  .kpi-grid { grid-template-columns: 1fr 1fr; }
}

/* ── PRINT ───────────────────────────────────────────── */
@media print {
  nav, .no-print { display: none !important; }
  body { background: #fff; }
  main { max-width: 100%; padding: 0; margin: 0; }
  .card { box-shadow: none; border: 1px solid #ccc; break-inside: avoid; }
  a { text-decoration: none; color: inherit; }
}
