/* ============================================================
   Sistema de Facturación — Estilos globales
   ============================================================ */

/* Variables */
:root {
  --primary:       #4F46E5;
  --primary-dark:  #3730A3;
  --primary-light: #EEF2FF;
  --success:       #059669;
  --success-light: #ECFDF5;
  --danger:        #DC2626;
  --danger-light:  #FEF2F2;
  --warning:       #D97706;
  --text:          #111827;
  --text-muted:    #6B7280;
  --border:        #E5E7EB;
  --bg:            #F9FAFB;
  --card:          #FFFFFF;
  --shadow:        0 1px 3px rgba(0,0,0,.1), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md:     0 4px 6px -1px rgba(0,0,0,.1), 0 2px 4px -1px rgba(0,0,0,.06);
  --radius:        8px;
  --radius-lg:     12px;
}

/* Reset */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

/* ─── Tipografía ─────────────────────────────────────────── */
h1 { font-size: 1.75rem; font-weight: 700; }
h2 { font-size: 1.35rem; font-weight: 600; }
h3 { font-size: 1.1rem;  font-weight: 600; }
p  { color: var(--text-muted); }

/* ─── Layout ─────────────────────────────────────────────── */
.container { max-width: 1100px; margin: 0 auto; padding: 0 1.5rem; }

/* ─── Navbar ─────────────────────────────────────────────── */
.navbar {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow);
  position: sticky; top: 0; z-index: 100;
}
.navbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 56px;
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 1.5rem;
}
.navbar-brand {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--primary);
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: .45rem;
}
.navbar-nav {
  display: flex;
  align-items: center;
  gap: .25rem;
  list-style: none;
}
.navbar-nav a {
  text-decoration: none;
  color: var(--text-muted);
  font-size: .9rem;
  font-weight: 500;
  padding: .4rem .75rem;
  border-radius: var(--radius);
  transition: background .15s, color .15s;
}
.navbar-nav a:hover,
.navbar-nav a.active {
  background: var(--primary-light);
  color: var(--primary);
}
.navbar-user {
  display: flex;
  align-items: center;
  gap: .75rem;
  font-size: .875rem;
  color: var(--text-muted);
}

/* ─── Botones ────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  font-size: .875rem;
  font-weight: 500;
  padding: .5rem 1rem;
  border-radius: var(--radius);
  border: none;
  cursor: pointer;
  transition: opacity .15s, transform .1s;
  text-decoration: none;
  white-space: nowrap;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.btn-primary   { background: var(--primary);   color: #fff; }
.btn-primary:hover   { background: var(--primary-dark); }
.btn-success   { background: var(--success);   color: #fff; }
.btn-success:hover   { opacity: .88; }
.btn-danger    { background: var(--danger);    color: #fff; }
.btn-danger:hover    { opacity: .88; }
.btn-outline   {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
}
.btn-outline:hover { background: var(--bg); }
.btn-ghost  {
  background: transparent;
  color: var(--text-muted);
  padding: .35rem .6rem;
}
.btn-ghost:hover { background: var(--bg); color: var(--text); }
.btn-icon  {
  background: none;
  border: none;
  cursor: pointer;
  padding: .25rem;
  border-radius: var(--radius);
  color: var(--text-muted);
  transition: background .15s, color .15s;
  display: inline-flex;
  align-items: center;
}
.btn-icon:hover { background: var(--primary-light); color: var(--primary); }
.btn-sm { padding: .35rem .7rem; font-size: .8rem; }
.btn-lg { padding: .7rem 1.4rem; font-size: 1rem; }

/* ─── Formularios ────────────────────────────────────────── */
.form-group        { display: flex; flex-direction: column; gap: .35rem; }
.form-label        { font-size: .875rem; font-weight: 500; color: var(--text); }
.form-control {
  width: 100%;
  padding: .5rem .75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: .9rem;
  color: var(--text);
  background: #fff;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.form-control:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79,70,229,.12);
}
.form-row {
  display: grid;
  gap: 1rem;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}

/* ─── Tarjetas ───────────────────────────────────────────── */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
}
.card-body { padding: 1.25rem; }

/* ─── Tablas ─────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
table {
  width: 100%;
  border-collapse: collapse;
  font-size: .875rem;
}
thead th {
  background: var(--bg);
  color: var(--text-muted);
  font-weight: 600;
  font-size: .775rem;
  text-transform: uppercase;
  letter-spacing: .05em;
  padding: .65rem 1rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
}
tbody td {
  padding: .75rem 1rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #FAFAFA; }
.text-right { text-align: right; }
.text-center { text-align: center; }

/* ─── Badges ─────────────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: .15rem .55rem;
  border-radius: 9999px;
  font-size: .75rem;
  font-weight: 600;
}
.badge-success { background: var(--success-light); color: var(--success); }
.badge-primary { background: var(--primary-light); color: var(--primary); }
.badge-danger  { background: #FEF2F2; color: #DC2626; }
.badge-info    { background: #EFF6FF; color: #1D4ED8; }
.badge-warning { background: #FFFBEB; color: #D97706; }

/* ─── Login ──────────────────────────────────────────────── */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #EEF2FF 0%, #F9FAFB 60%);
}
.login-card {
  width: 100%;
  max-width: 380px;
  background: #fff;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  padding: 2rem;
}
.login-logo {
  text-align: center;
  margin-bottom: 1.5rem;
}
.login-logo .icon {
  font-size: 2.5rem;
  display: block;
}
.login-logo h1 {
  font-size: 1.4rem;
  color: var(--text);
  margin-top: .5rem;
}
.login-logo p { font-size: .85rem; margin-top: .2rem; }

/* ─── Página principal ───────────────────────────────────── */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.5rem 0 1rem;
}
.page-header h1 { font-size: 1.4rem; }

/* ─── Panel nuevo pedido ─────────────────────────────────── */
.order-panel {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  overflow: hidden;
  margin-bottom: 1.5rem;
  display: none;
}
.order-panel.open { display: block; }
.order-panel-header {
  background: var(--primary);
  color: #fff;
  padding: .9rem 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-weight: 600;
}
.order-panel-header button {
  background: rgba(255,255,255,.2);
  border: none;
  color: #fff;
  border-radius: var(--radius);
  padding: .25rem .6rem;
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
}
.order-panel-header button:hover { background: rgba(255,255,255,.3); }
.order-panel-body { padding: 1.25rem; }

/* ─── Autocomplete ───────────────────────────────────────── */
.autocomplete-wrap { position: relative; }
.autocomplete-dropdown {
  position: absolute;
  top: calc(100% + 4px);
  left: 0; right: 0;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  z-index: 200;
  max-height: 220px;
  overflow-y: auto;
  display: none;
}
.autocomplete-dropdown.open { display: block; }
.autocomplete-item {
  padding: .6rem .9rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .5rem;
  font-size: .875rem;
}
.autocomplete-item:hover { background: var(--primary-light); }
.autocomplete-item .ref  { color: var(--text-muted); font-size: .78rem; }
.autocomplete-item .price { font-weight: 600; color: var(--primary); white-space: nowrap; }
.autocomplete-empty {
  padding: .8rem .9rem;
  color: var(--text-muted);
  font-size: .875rem;
  text-align: center;
}

/* ─── Tabla de items del pedido ──────────────────────────── */
.item-total-row {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 1rem;
  padding: .75rem 1rem .25rem;
  font-weight: 600;
}
.item-total-row .label  { color: var(--text-muted); font-size: .875rem; }
.item-total-row .amount { font-size: 1.25rem; color: var(--primary); }

.order-actions {
  display: flex;
  justify-content: flex-end;
  gap: .75rem;
  padding: .75rem 1rem 1rem;
  border-top: 1px solid var(--border);
}

/* ─── Modales ────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 500;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s;
}
.modal-backdrop.open {
  opacity: 1;
  pointer-events: all;
}
.modal {
  background: #fff;
  border-radius: var(--radius-lg);
  box-shadow: 0 20px 60px rgba(0,0,0,.2);
  width: 100%;
  max-width: 420px;
  padding: 1.5rem;
  transform: translateY(-10px);
  transition: transform .2s;
}
.modal-backdrop.open .modal { transform: translateY(0); }
.modal-title    { font-size: 1.1rem; font-weight: 600; margin-bottom: .75rem; }
.modal-body     { color: var(--text-muted); font-size: .9rem; margin-bottom: 1.25rem; line-height: 1.6; }
.modal-actions  { display: flex; justify-content: flex-end; gap: .6rem; }
.modal-edit-fields { margin: 1rem 0; }

/* ─── Alertas ────────────────────────────────────────────── */
.alert {
  display: none;
  padding: .75rem 1rem;
  border-radius: var(--radius);
  font-size: .875rem;
  margin-bottom: 1rem;
}
.alert.show { display: flex; align-items: center; gap: .5rem; }
.alert-danger  { background: var(--danger-light);  color: var(--danger); }
.alert-success { background: var(--success-light); color: var(--success); }

/* ─── Empty state ────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-muted);
}
.empty-state .icon { font-size: 2.5rem; margin-bottom: .75rem; display: block; }

/* ─── Filtros (página de pedidos) ────────────────────────── */
.filters-bar {
  display: flex;
  align-items: flex-end;
  gap: .75rem;
  flex-wrap: wrap;
  margin-bottom: 1.25rem;
}
.filters-bar .form-group { flex: 1; min-width: 150px; }

/* ─── Spinner ────────────────────────────────────────────── */
.spinner {
  display: inline-block;
  width: 18px; height: 18px;
  border: 2px solid rgba(255,255,255,.4);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ─── Utilidades ─────────────────────────────────────────── */
.mt-1  { margin-top: .5rem; }
.mt-2  { margin-top: 1rem; }
.mt-3  { margin-top: 1.5rem; }
.mb-2  { margin-bottom: 1rem; }
.flex  { display: flex; }
.items-center { align-items: center; }
.gap-2 { gap: .5rem; }
.w-full { width: 100%; }
.font-bold { font-weight: 700; }
.text-sm { font-size: .875rem; }
.text-muted { color: var(--text-muted); }

/* ─── Impresión ──────────────────────────────────────────── */
@media print {
  body { background: #fff; font-size: 11px; }
  .navbar, .filters-bar, .no-print, .btn, .btn-icon { display: none !important; }
  .card { box-shadow: none; border: 1px solid #ccc; page-break-inside: avoid; }
  table { font-size: 10px; border-collapse: collapse; }
  thead th { background: #f0f0f0; border: 1px solid #ccc; padding: 8px; text-align: left; font-weight: 600; }
  tbody td { border: 1px solid #ccc; padding: 8px; }
  tbody tr:hover { background: transparent; }

  .print-title {
    display: block !important;
    text-align: center;
    font-size: 18px;
    font-weight: 700;
    margin-bottom: 15px;
    border-bottom: 2px solid #333;
    padding-bottom: 10px;
  }

  .page-header { margin-bottom: 20px; }
  .page-header h1 { font-size: 24px; margin-bottom: 5px; }

  /* Encabezado de detalle para impresión */
  .print-header {
    margin-bottom: 15px;
    padding-bottom: 10px;
    border-bottom: 1px solid #999;
  }
  .print-header-item { margin-bottom: 5px; font-size: 11px; }
  .print-header-label { font-weight: 600; display: inline-block; width: 100px; }

  .detail-row { display: table-row !important; }
  .modal { display: none !important; }
}

.print-title { display: none; }

/* ─── Paginación ─────────────────────────────────────────── */
.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: .5rem;
  padding: .75rem 0;
}
.pagination-info { font-size: .825rem; color: var(--text-muted); }
.pagination-buttons { display: flex; align-items: center; gap: .25rem; flex-wrap: wrap; }
.pagination-btn {
  min-width: 2rem;
  height: 2rem;
  padding: 0 .6rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--card);
  color: var(--text);
  font-size: .825rem;
  cursor: pointer;
  transition: background .15s, color .15s, border-color .15s;
}
.pagination-btn:hover:not(:disabled) {
  background: var(--primary-light);
  border-color: var(--primary);
  color: var(--primary);
}
.pagination-btn.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
  font-weight: 600;
}
.pagination-btn:disabled { opacity: .4; cursor: not-allowed; }
.pagination-ellipsis { padding: 0 .2rem; color: var(--text-muted); font-size: .825rem; }
