/* ============================================================
   assets/css/app.css
   Sistema Pañol — Hoja de estilos principal
   ============================================================ */

/* ── Reset y base ──────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --blue-900: #0a1f38;
  --blue-800: #0f2d52;
  --blue-700: #1a4a80;
  --blue-500: #1a7aff;
  --blue-100: #e6f1fb;
  --blue-50:  #f0f7ff;

  --green-800: #166534;
  --green-600: #16a34a;
  --green-100: #dcfce7;
  --green-50:  #f0fdf4;

  --red-800:  #991b1b;
  --red-600:  #dc2626;
  --red-100:  #fee2e2;
  --red-50:   #fef2f2;

  --amber-800: #92400e;
  --amber-100: #fef3c7;
  --amber-50:  #fffbeb;

  --gray-900: #111827;
  --gray-700: #374151;
  --gray-600: #4b5563;
  --gray-500: #6b7280;
  --gray-300: #d1d5db;
  --gray-200: #e5e7eb;
  --gray-100: #f3f4f6;
  --gray-50:  #f9fafb;
  --white:    #ffffff;

  --sidebar-w: 210px;
  --topbar-h:  50px;
  --radius:    8px;
  --radius-lg: 12px;
  --shadow-sm: 0 1px 3px rgba(0,0,0,.08);
  --shadow-md: 0 4px 16px rgba(0,0,0,.12);

  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Helvetica Neue', Arial, sans-serif;
  --font-mono: 'SF Mono', 'Fira Code', Consolas, monospace;
}

html, body {
  height: 100%;
  font-family: var(--font);
  font-size: 14px;
  color: var(--gray-900);
  background: var(--gray-100);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--blue-500); text-decoration: none; }
a:hover { text-decoration: underline; }

img { max-width: 100%; display: block; }

/* ── Layout general ────────────────────────────────────────── */
.topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--topbar-h);
  background: var(--blue-800);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 18px;
  z-index: 100;
  box-shadow: 0 1px 4px rgba(0,0,0,.3);
}

.app-layout {
  display: flex;
  min-height: 100vh;
  padding-top: var(--topbar-h);
}

.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--white);
  border-right: 1px solid var(--gray-200);
  padding: 10px 0 20px;
  overflow-y: auto;
  position: fixed;
  top: var(--topbar-h);
  bottom: 0;
  left: 0;
  z-index: 50;
}

.main-content {
  flex: 1;
  margin-left: var(--sidebar-w);
  padding: 20px 22px 40px;
  min-width: 0;
}

/* ── Topbar ────────────────────────────────────────────────── */
.topbar-logo-link {
  display: flex;
  align-items: center;
  gap: 9px;
  text-decoration: none;
}
.topbar-app-name {
  font-size: 15px;
  font-weight: 600;
  color: #fff;
  letter-spacing: .3px;
}
.topbar-badge {
  background: var(--blue-500);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 4px;
  letter-spacing: .5px;
}
.topbar-nav { display: flex; gap: 2px; }
.topbar-link {
  color: rgba(255,255,255,.72);
  padding: 6px 12px;
  border-radius: var(--radius);
  font-size: 13px;
  text-decoration: none;
  transition: background .12s, color .12s;
}
.topbar-link:hover, .topbar-link.active {
  background: rgba(255,255,255,.15);
  color: #fff;
  text-decoration: none;
}
.topbar-user {
  display: flex;
  align-items: center;
  gap: 10px;
}
.user-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--blue-500);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.user-info {
  display: flex;
  flex-direction: column;
  line-height: 1.3;
}
.user-name { font-size: 13px; color: #fff; font-weight: 500; }
.user-rol  { font-size: 10px; color: rgba(255,255,255,.55); }
.btn-logout {
  color: rgba(255,255,255,.6);
  display: flex;
  align-items: center;
  padding: 4px;
  border-radius: 4px;
  transition: color .12s;
  text-decoration: none;
}
.btn-logout:hover { color: #fff; text-decoration: none; }

/* ── Sidebar ────────────────────────────────────────────────── */
.sidebar-section { padding: 4px 0; }
.sidebar-label {
  font-size: 10px;
  font-weight: 700;
  color: var(--gray-500);
  padding: 8px 14px 4px;
  letter-spacing: .8px;
  text-transform: uppercase;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 14px;
  color: var(--gray-600);
  font-size: 13px;
  border-left: 2px solid transparent;
  transition: all .1s;
  text-decoration: none;
  cursor: pointer;
}
.nav-item:hover {
  background: var(--gray-50);
  color: var(--gray-900);
  text-decoration: none;
}
.nav-item.active {
  background: var(--blue-50);
  color: var(--blue-700);
  border-left-color: var(--blue-500);
  font-weight: 600;
}
.nav-icon {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  opacity: .7;
}
.nav-item.active .nav-icon { opacity: 1; }

/* Alertas sidebar */
.sidebar-alerts { padding: 4px 10px 8px; }
.alert-stock {
  border-radius: 6px;
  padding: 6px 8px;
  font-size: 11px;
  margin-bottom: 4px;
}
.alert-stock strong { display: block; font-size: 11px; }
.alert-min { color: inherit; opacity: .7; }
.alert-sin_stock { background: var(--red-100); color: var(--red-800); }
.alert-stock_bajo { background: var(--amber-100); color: var(--amber-800); }
.alert-link { font-size: 11px; color: var(--blue-500); display: block; margin-top: 6px; padding: 0 2px; }

/* ── Flash messages ─────────────────────────────────────────── */
.flash {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 13px;
  margin-bottom: 16px;
}
.flash-error   { background: var(--red-50);   color: var(--red-800);   border: 1px solid #fecaca; }
.flash-success { background: var(--green-50);  color: var(--green-800); border: 1px solid #bbf7d0; }
.flash-close   { margin-left: auto; background: none; border: none; cursor: pointer; font-size: 16px; line-height: 1; opacity: .6; }
.flash-close:hover { opacity: 1; }

/* ── Encabezados de página ──────────────────────────────────── */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 20px;
  gap: 12px;
  flex-wrap: wrap;
}
.page-header-text h1 {
  font-size: 20px;
  font-weight: 600;
  color: var(--gray-900);
}
.page-header-text p {
  font-size: 13px;
  color: var(--gray-500);
  margin-top: 2px;
}

/* ── Cards ──────────────────────────────────────────────────── */
.card {
  background: var(--white);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
}
.card-title {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 14px;
  color: var(--gray-700);
}

/* ── Buttons ────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
  font-family: var(--font);
  cursor: pointer;
  border: 1px solid transparent;
  text-decoration: none;
  transition: all .12s;
  line-height: 1;
}
.btn svg { width: 15px; height: 15px; }
.btn-primary   { background: var(--blue-800); color: #fff; border-color: var(--blue-800); }
.btn-primary:hover { background: var(--blue-700); text-decoration: none; color: #fff; }
.btn-success   { background: var(--green-600); color: #fff; border-color: var(--green-600); }
.btn-success:hover { background: var(--green-800); text-decoration: none; color: #fff; }
.btn-danger    { background: var(--red-600);  color: #fff; border-color: var(--red-600); }
.btn-danger:hover  { background: var(--red-800); text-decoration: none; color: #fff; }
.btn-outline   { background: transparent; color: var(--gray-700); border-color: var(--gray-300); }
.btn-outline:hover { background: var(--gray-50); text-decoration: none; color: var(--gray-900); }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-icon { padding: 6px; border-radius: 6px; }

/* ── Formularios ────────────────────────────────────────────── */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 14px; }
.form-full { grid-column: 1 / -1; }

.field { display: flex; flex-direction: column; gap: 5px; }
.field label {
  font-size: 12px;
  font-weight: 600;
  color: var(--gray-600);
  letter-spacing: .3px;
}
.field input, .field select, .field textarea {
  padding: 8px 11px;
  font-size: 13px;
  font-family: var(--font);
  color: var(--gray-900);
  background: var(--gray-50);
  border: 1px solid var(--gray-300);
  border-radius: var(--radius);
  outline: none;
  transition: border-color .12s, box-shadow .12s, background .12s;
  width: 100%;
}
.field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--blue-500);
  box-shadow: 0 0 0 3px rgba(26,122,255,.12);
  background: var(--white);
}
.field input[readonly] {
  background: var(--gray-100);
  color: var(--gray-600);
  cursor: default;
}
.field input.is-invalid,
.field select.is-invalid { border-color: var(--red-600); }
.field-error { font-size: 11px; color: var(--red-600); margin-top: 2px; }
.field-hint  { font-size: 11px; color: var(--gray-500); margin-top: 2px; }

/* Toggle entrada/salida */
.tipo-toggle {
  display: grid;
  grid-template-columns: 1fr 1fr;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--gray-300);
}
.tipo-btn {
  padding: 9px;
  text-align: center;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  font-family: var(--font);
  background: var(--gray-50);
  color: var(--gray-500);
  border: none;
  transition: all .12s;
}
.tipo-btn.entrada.sel { background: var(--green-100); color: var(--green-800); }
.tipo-btn.salida.sel  { background: var(--red-100);   color: var(--red-800); }

/* ── Tablas ─────────────────────────────────────────────────── */
.table-wrap {
  background: var(--white);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-lg);
  overflow: hidden;
}
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
thead th {
  background: var(--gray-50);
  padding: 9px 12px;
  text-align: left;
  font-size: 11px;
  font-weight: 700;
  color: var(--gray-500);
  letter-spacing: .5px;
  text-transform: uppercase;
  border-bottom: 1px solid var(--gray-200);
  white-space: nowrap;
}
tbody td {
  padding: 9px 12px;
  border-bottom: 1px solid var(--gray-100);
  color: var(--gray-700);
  vertical-align: middle;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: var(--blue-50); }

.table-actions { display: flex; gap: 4px; }

/* ── Badges y pills ─────────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .3px;
}
.badge-entrada { background: var(--green-100); color: var(--green-800); }
.badge-salida  { background: var(--red-100);   color: var(--red-800); }
.badge-ok      { background: var(--green-100); color: var(--green-800); }
.badge-low     { background: var(--amber-100); color: var(--amber-800); }
.badge-sin     { background: var(--red-100);   color: var(--red-800); }
.badge-admin        { background: #ede9fe; color: #4c1d95; }
.badge-responsable  { background: var(--blue-100); color: var(--blue-700); }
.badge-consultor    { background: var(--gray-100); color: var(--gray-600); }

/* ── KPIs / Metric cards ────────────────────────────────────── */
.kpi-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 18px; }
.kpi-card {
  background: var(--white);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-lg);
  padding: 14px 16px;
}
.kpi-label { font-size: 11px; color: var(--gray-500); margin-bottom: 4px; display: flex; justify-content: space-between; align-items: center; }
.kpi-value { font-size: 24px; font-weight: 700; color: var(--gray-900); line-height: 1.2; }
.kpi-sub   { font-size: 11px; color: var(--gray-500); margin-top: 3px; }

/* ── Charts ─────────────────────────────────────────────────── */
.charts-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-bottom: 14px; }
.charts-row.cols-3 { grid-template-columns: 1fr 1fr 1fr; }
.chart-card {
  background: var(--white);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-lg);
  padding: 16px 18px;
}
.chart-card.full { grid-column: 1 / -1; }
.chart-header-title { font-size: 13px; font-weight: 600; color: var(--gray-700); }
.chart-header-sub   { font-size: 11px; color: var(--gray-500); margin-top: 2px; margin-bottom: 12px; }
.chart-legend { display: flex; gap: 14px; margin-bottom: 8px; flex-wrap: wrap; }
.chart-legend-item { display: flex; align-items: center; gap: 5px; font-size: 11px; color: var(--gray-500); }
.chart-legend-dot  { width: 10px; height: 10px; border-radius: 2px; flex-shrink: 0; }
.chart-wrap { position: relative; }
.chart-wrap-200 { height: 200px; }
.chart-wrap-160 { height: 160px; }

/* ── Toast ──────────────────────────────────────────────────── */
#toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 16px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
  box-shadow: var(--shadow-md);
  animation: toast-in .2s ease;
  max-width: 340px;
}
.toast-success { background: var(--green-100); color: var(--green-800); border: 1px solid #bbf7d0; }
.toast-error   { background: var(--red-100);   color: var(--red-800);   border: 1px solid #fecaca; }
.toast-info    { background: var(--blue-100);  color: var(--blue-700);  border: 1px solid #bae6fd; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ── Paginación ─────────────────────────────────────────────── */
.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-top: 1px solid var(--gray-100);
  font-size: 12px;
  color: var(--gray-500);
}
.pagination-links { display: flex; gap: 4px; }
.page-link {
  padding: 4px 9px;
  border-radius: 5px;
  border: 1px solid var(--gray-200);
  color: var(--gray-700);
  text-decoration: none;
  font-size: 12px;
  transition: all .1s;
}
.page-link:hover { background: var(--gray-100); text-decoration: none; }
.page-link.active { background: var(--blue-800); color: #fff; border-color: var(--blue-800); }

/* ── Foto insumo ────────────────────────────────────────────── */
.foto-preview {
  width: 80px; height: 80px;
  border-radius: var(--radius);
  object-fit: cover;
  border: 1px solid var(--gray-200);
  background: var(--gray-100);
}
.foto-preview-lg {
  width: 120px; height: 120px;
  border-radius: var(--radius-lg);
  object-fit: cover;
  border: 1px solid var(--gray-200);
}
.foto-upload-zone {
  border: 2px dashed var(--gray-300);
  border-radius: var(--radius-lg);
  padding: 20px;
  text-align: center;
  cursor: pointer;
  transition: all .15s;
  background: var(--gray-50);
}
.foto-upload-zone:hover { border-color: var(--blue-500); background: var(--blue-50); }
.foto-upload-zone p { font-size: 13px; color: var(--gray-500); margin-top: 8px; }

/* ── Modal ──────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal {
  background: var(--white);
  border-radius: var(--radius-lg);
  padding: 24px 26px;
  width: 100%;
  max-width: 560px;
  box-shadow: var(--shadow-md);
  max-height: 90vh;
  overflow-y: auto;
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}
.modal-title { font-size: 16px; font-weight: 600; }
.modal-close {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 20px;
  color: var(--gray-400);
  line-height: 1;
  padding: 2px;
}
.modal-close:hover { color: var(--gray-700); }
.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--gray-100);
}
.modal-overlay.hidden { display: none; }

/* ── Filtros de consulta ────────────────────────────────────── */
.filtros-card {
  background: var(--white);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-lg);
  padding: 16px 18px;
  margin-bottom: 14px;
}
.filtros-card form { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.filtros-actions {
  grid-column: 1 / -1;
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 4px;
}

/* ── Totalizadores de listado ───────────────────────────────── */
.totales-bar {
  background: var(--blue-50);
  border-top: 1px solid var(--blue-100);
  padding: 9px 14px;
  display: flex;
  gap: 24px;
  font-size: 13px;
  font-weight: 600;
  color: var(--blue-700);
}

/* ── Insumo search autocomplete ─────────────────────────────── */
.search-wrap { position: relative; }
.autocomplete-list {
  position: absolute;
  top: 100%; left: 0; right: 0;
  background: var(--white);
  border: 1px solid var(--gray-300);
  border-top: none;
  border-radius: 0 0 var(--radius) var(--radius);
  z-index: 50;
  max-height: 200px;
  overflow-y: auto;
  box-shadow: var(--shadow-md);
}
.ac-item {
  padding: 8px 12px;
  cursor: pointer;
  border-bottom: 1px solid var(--gray-100);
  transition: background .08s;
}
.ac-item:last-child { border-bottom: none; }
.ac-item:hover, .ac-item.activo { background: var(--blue-50); }
.ac-item-name  { font-size: 13px; font-weight: 500; color: var(--gray-900); }
.ac-item-meta  { font-size: 11px; color: var(--gray-500); }
.ac-item-stock { display: inline-block; font-size: 11px; font-weight: 600; margin-top: 2px; }

.insumo-preview {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--gray-50);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  padding: 10px 12px;
  margin-top: 8px;
}
.insumo-preview-img {
  width: 52px; height: 52px;
  object-fit: cover;
  border-radius: var(--radius);
  border: 1px solid var(--gray-200);
  flex-shrink: 0;
}

/* ── Registrar: panel lateral ───────────────────────────────── */
.reg-layout { display: grid; grid-template-columns: 1fr 320px; gap: 16px; align-items: start; }
.last-movs-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 0;
  border-bottom: 1px solid var(--gray-100);
}
.last-movs-item:last-child { border: none; }
.last-movs-badge { width: 22px; height: 22px; border-radius: 4px; display: flex; align-items: center; justify-content: center; font-size: 10px; font-weight: 700; flex-shrink: 0; }
.compra-item { padding: 7px 0; border-bottom: 1px solid var(--gray-100); }
.compra-item:last-child { border: none; }

/* ── Responsive básico ──────────────────────────────────────── */
@media (max-width: 900px) {
  .kpi-grid    { grid-template-columns: 1fr 1fr; }
  .charts-row  { grid-template-columns: 1fr; }
  .form-grid   { grid-template-columns: 1fr; }
  .reg-layout  { grid-template-columns: 1fr; }
  .filtros-card form { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 640px) {
  .sidebar { display: none; }
  .main-content { margin-left: 0; padding: 12px; }
  .kpi-grid { grid-template-columns: 1fr; }
  .filtros-card form { grid-template-columns: 1fr; }
}
