/* ============================================================
   ficha-360.css - Drawer Ficha 360° de referencia (~280 lin)
   Drawer lateral 60% desktop / 100% mobile slide-up
   Tabs: Info / Stock / Movimientos / Compras / Ventas
   Reemplaza ficha-referencia.css legacy
   ============================================================ */

/* ═══════ OVERLAY (backdrop) ═══════ */
.f360-overlay {
  position: fixed; inset: 0; z-index: 10050;
  background: rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(2px);
  opacity: 0; pointer-events: none;
  transition: opacity 0.22s ease;
}
.f360-overlay.open { opacity: 1; pointer-events: auto; }

/* ═══════ DRAWER (panel lateral) ═══════ */
.f360-drawer {
  position: fixed; top: 0; right: 0; bottom: 0;
  z-index: 10051;
  width: 60%; max-width: 1100px; min-width: 720px;
  background: var(--brand-surface);
  box-shadow: -8px 0 32px rgba(0, 0, 0, 0.18);
  display: flex; flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.28s cubic-bezier(.2, .8, .2, 1);
}
.f360-drawer.open { transform: translateX(0); }

/* ═══════ HEADER ═══════ */
.f360-header {
  flex: 0 0 auto;
  padding: 18px 24px 14px;
  border-bottom: 1px solid var(--brand-border);
  background: var(--brand-surface);
}
.f360-header-row {
  display: flex; align-items: flex-start;
  justify-content: space-between; gap: 16px;
}
.f360-title-block { flex: 1; min-width: 0; }
.f360-codigo {
  display: inline-block;
  font-family: 'Courier New', monospace;
  font-size: 0.78rem; font-weight: 700;
  color: var(--brand-accent);
  background: rgba(147, 193, 31, 0.12);
  padding: 3px 10px; border-radius: 4px;
  margin-bottom: 6px;
}
.f360-nombre {
  font-size: 1.18rem; font-weight: 700;
  color: var(--brand-text);
  line-height: 1.3;
  display: -webkit-box; -webkit-line-clamp: 2;
  -webkit-box-orient: vertical; overflow: hidden;
}
.f360-subtitle {
  font-size: 0.82rem; color: var(--brand-text-muted);
  margin-top: 4px;
}
.f360-subtitle .sep { margin: 0 6px; opacity: 0.5; }
.f360-close {
  flex: 0 0 auto;
  width: 36px; height: 36px; border-radius: 50%;
  border: none; background: transparent;
  color: var(--brand-text-muted);
  cursor: pointer; font-size: 1rem;
  display: flex; align-items: center; justify-content: center;
  transition: all 0.15s ease;
}
.f360-close:hover {
  background: var(--brand-bg);
  color: var(--brand-error);
}

/* Mini KPIs en header */
.f360-mini-kpis {
  display: grid; grid-template-columns: repeat(4, 1fr);
  gap: 10px; margin-top: 14px;
}
.f360-mini-kpi {
  background: var(--brand-bg);
  border: 1px solid var(--brand-border);
  border-radius: 6px;
  padding: 8px 10px;
  text-align: center;
}
.f360-mini-kpi-label {
  font-size: 0.68rem; color: var(--brand-text-muted);
  text-transform: uppercase; letter-spacing: 0.4px;
}
.f360-mini-kpi-value {
  font-size: 0.95rem; font-weight: 700;
  color: var(--brand-text); margin-top: 2px;
}
.f360-mini-kpi-value.is-warning { color: var(--brand-warning); }
.f360-mini-kpi-value.is-error { color: var(--brand-error); }
.f360-mini-kpi-value.is-success { color: var(--brand-success); }

/* ═══════ TABS ═══════ */
.f360-tabs {
  flex: 0 0 auto;
  display: flex;
  border-bottom: 1px solid var(--brand-border);
  background: var(--brand-surface);
  position: sticky; top: 0; z-index: 2;
  overflow-x: auto;
}
.f360-tab {
  flex: 0 0 auto;
  padding: 12px 18px;
  border: none; background: none;
  font-size: 0.85rem; font-weight: 500;
  color: var(--brand-text-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all 0.15s ease;
  display: inline-flex; align-items: center; gap: 6px;
  white-space: nowrap;
}
.f360-tab:hover { color: var(--brand-text); background: var(--brand-bg); }
.f360-tab.active {
  color: var(--brand-accent);
  border-bottom-color: var(--brand-accent);
  font-weight: 600;
}
.f360-tab-badge {
  font-size: 0.68rem; padding: 1px 6px;
  border-radius: 8px; background: var(--brand-border);
  color: var(--brand-text);
}
.f360-tab.active .f360-tab-badge {
  background: var(--brand-accent); color: white;
}

/* ═══════ BODY (contenido tab) ═══════ */
.f360-body {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 20px 24px;
  background: var(--brand-bg);
}
.f360-tab-pane { display: none; animation: f360-fadein 0.2s ease; }
.f360-tab-pane.active { display: block; }
@keyframes f360-fadein {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Loading / empty / error */
.f360-loading, .f360-empty, .f360-error {
  text-align: center; padding: 48px 20px;
  color: var(--brand-text-muted); font-size: 0.9rem;
}
.f360-loading i { font-size: 1.5rem; margin-right: 8px; }
.f360-empty i { font-size: 2rem; opacity: 0.4; display: block; margin-bottom: 10px; }
.f360-error { color: var(--brand-error); }

/* ═══════ TAB INFO ═══════ */
.f360-grid-2 {
  display: grid; grid-template-columns: repeat(2, 1fr);
  gap: 8px 20px;
}
.f360-field {
  display: flex; justify-content: space-between;
  padding: 8px 0; border-bottom: 1px dashed var(--brand-border);
  font-size: 0.85rem;
}
.f360-field-label { color: var(--brand-text-muted); }
.f360-field-value { color: var(--brand-text); font-weight: 500; text-align: right; }
.f360-section-title {
  font-size: 0.78rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.5px;
  color: var(--brand-text-muted);
  margin: 18px 0 10px; padding-bottom: 6px;
  border-bottom: 2px solid var(--brand-accent);
}
.f360-section-title:first-child { margin-top: 0; }

/* ═══════ TAB STOCK ═══════ */
.f360-stock-card {
  background: var(--brand-surface);
  border: 1px solid var(--brand-border);
  border-radius: 8px;
  padding: 14px 16px; margin-bottom: 10px;
  display: grid; grid-template-columns: 1fr auto auto auto;
  gap: 16px; align-items: center;
}
.f360-stock-bodega {
  font-weight: 600; color: var(--brand-text); font-size: 0.92rem;
}
.f360-stock-num {
  font-size: 1.3rem; font-weight: 700; color: var(--brand-text);
  font-variant-numeric: tabular-nums;
}
.f360-stock-num small { font-size: 0.7rem; font-weight: 400; color: var(--brand-text-muted); }
.f360-stock-badge {
  padding: 4px 10px; border-radius: 12px;
  font-size: 0.72rem; font-weight: 600;
}
.f360-stock-badge.ok { background: rgba(34, 197, 94, 0.15); color: #15803d; }
.f360-stock-badge.bajo { background: rgba(234, 179, 8, 0.15); color: #a16207; }
.f360-stock-badge.agotado { background: rgba(239, 68, 68, 0.15); color: #b91c1c; }

/* ═══════ TAB MOVIMIENTOS / COMPRAS / VENTAS (tablas) ═══════ */
.f360-table {
  width: 100%; border-collapse: collapse;
  background: var(--brand-surface);
  border-radius: 6px; overflow: hidden;
  font-size: 0.83rem;
}
.f360-table thead th {
  background: var(--brand-primary);
  color: white; padding: 10px 12px;
  text-align: left; font-weight: 600; font-size: 0.76rem;
  text-transform: uppercase; letter-spacing: 0.3px;
}
.f360-table tbody td {
  padding: 9px 12px;
  border-bottom: 1px solid var(--brand-border);
  color: var(--brand-text);
}
.f360-table tbody tr:hover { background: var(--brand-bg); }
.f360-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.f360-doc-tipo {
  display: inline-block;
  font-family: 'Courier New', monospace;
  font-size: 0.7rem; font-weight: 700;
  padding: 2px 6px; border-radius: 3px;
}
.f360-doc-tipo.entrada { background: rgba(34, 197, 94, 0.15); color: #15803d; }
.f360-doc-tipo.salida { background: rgba(239, 68, 68, 0.15); color: #b91c1c; }
.f360-doc-tipo.traslado { background: rgba(59, 130, 246, 0.15); color: #1d4ed8; }
.f360-doc-tipo.ajuste { background: rgba(234, 179, 8, 0.15); color: #a16207; }

/* ═══════ FOOTER (acciones rápidas) ═══════ */
.f360-footer {
  flex: 0 0 auto;
  padding: 12px 24px;
  border-top: 1px solid var(--brand-border);
  background: var(--brand-surface);
  display: flex; gap: 10px; flex-wrap: wrap;
  justify-content: flex-end;
}
.f360-action-btn {
  padding: 8px 14px; border-radius: 5px;
  border: 1px solid var(--brand-border);
  background: var(--brand-bg);
  color: var(--brand-text); font-size: 0.82rem;
  cursor: pointer; font-weight: 500;
  display: inline-flex; align-items: center; gap: 6px;
  transition: all 0.15s ease;
}
.f360-action-btn:hover {
  border-color: var(--brand-accent);
  color: var(--brand-accent);
  background: var(--brand-surface);
}
.f360-action-btn.primary {
  background: var(--brand-accent); color: white;
  border-color: var(--brand-accent);
}
.f360-action-btn.primary:hover {
  background: var(--brand-primary);
  border-color: var(--brand-primary); color: white;
}
.f360-action-btn[disabled] {
  opacity: 0.5; cursor: not-allowed;
}

/* ═══════ MODO PAGE (ruta /inventario/ficha/:codigo) ═══════ */
.f360-drawer.is-page {
  position: relative;
  width: 100%; max-width: none; min-width: 0;
  transform: none; box-shadow: none;
}
.f360-drawer.is-page + .f360-overlay { display: none; }

/* ═══════ RESPONSIVE: mobile (full-screen slide-up) ═══════ */
@media (max-width: 768px) {
  .f360-drawer {
    width: 100%; max-width: none; min-width: 0;
    top: auto; bottom: 0; right: 0; left: 0;
    height: 92vh; border-radius: 16px 16px 0 0;
    transform: translateY(100%);
  }
  .f360-drawer.open { transform: translateY(0); }
  .f360-header { padding: 14px 16px 10px; }
  .f360-mini-kpis { grid-template-columns: repeat(2, 1fr); }
  .f360-body { padding: 14px 16px; }
  .f360-grid-2 { grid-template-columns: 1fr; }
  .f360-stock-card { grid-template-columns: 1fr auto; gap: 8px; }
  .f360-stock-num { font-size: 1.1rem; }
  .f360-footer { padding: 10px 16px; }
  .f360-action-btn { font-size: 0.78rem; padding: 7px 10px; }
  .f360-table { font-size: 0.76rem; }
  .f360-table thead th, .f360-table tbody td { padding: 7px 8px; }
  /* Hint visual de swipe entre tabs */
  .f360-tabs::after {
    content: '\f061';
    font-family: 'Font Awesome 6 Free'; font-weight: 900;
    position: absolute; right: 6px; top: 50%;
    transform: translateY(-50%);
    color: var(--brand-text-muted); opacity: 0.4;
    font-size: 0.65rem; pointer-events: none;
  }
  .f360-tabs { position: sticky; }
}

/* Skeleton de carga (mejorado) */
.f360-skeleton {
  display: flex; flex-direction: column; gap: 12px;
  padding: 8px 0;
}
.f360-skeleton-row {
  height: 14px; border-radius: 4px;
  background: linear-gradient(90deg,
    var(--brand-border) 0%,
    var(--brand-bg) 50%,
    var(--brand-border) 100%);
  background-size: 200% 100%;
  animation: f360-shimmer 1.4s ease infinite;
}
.f360-skeleton-row.lg { height: 22px; width: 60%; }
.f360-skeleton-row.md { width: 80%; }
.f360-skeleton-row.sm { width: 40%; }
@keyframes f360-shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ═══════ FILAS CLICKABLES (integracion en tablas) ═══════ */
.inv-row-clickable, .ref-row-clickable {
  cursor: pointer;
  transition: background 0.12s ease;
}
.inv-row-clickable:hover, .ref-row-clickable:hover {
  background: rgba(147, 193, 31, 0.08);
}
.inv-card-clickable, .ref-card-clickable {
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}
.inv-card-clickable:active, .ref-card-clickable:active {
  transform: scale(0.98);
}

/* Tabla limpia de Ficha Referencia (8 cols) */
.ref-table-clean code {
  background: var(--brand-bg);
  padding: 2px 6px; border-radius: 3px;
  font-size: 0.78rem; color: var(--brand-accent);
}

/* ═══════ MODALES DE ACCIONES (Ajuste / Traslado / Precios) ═══════ */
.f360-modal-backdrop {
  position: fixed; inset: 0; z-index: 10100;
  background: rgba(0, 0, 0, 0.55);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  opacity: 0; transition: opacity 0.2s ease;
}
.f360-modal-backdrop.open { opacity: 1; }
.f360-modal {
  background: var(--brand-surface);
  border-radius: 10px;
  width: 100%; max-width: 560px; max-height: 90vh;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
  display: flex; flex-direction: column;
  transform: scale(0.96); transition: transform 0.2s ease;
}
.f360-modal-backdrop.open .f360-modal { transform: scale(1); }
.f360-modal-header {
  flex: 0 0 auto;
  padding: 16px 20px;
  border-bottom: 1px solid var(--brand-border);
  display: flex; align-items: flex-start; justify-content: space-between; gap: 12px;
}
.f360-modal-title {
  font-size: 1.05rem; font-weight: 700; color: var(--brand-text);
}
.f360-modal-title i { color: var(--brand-accent); margin-right: 6px; }
.f360-modal-subtitle {
  font-size: 0.78rem; color: var(--brand-text-muted); margin-top: 4px;
}
.f360-modal-subtitle code {
  background: rgba(147, 193, 31, 0.12);
  color: var(--brand-accent);
  padding: 1px 6px; border-radius: 3px;
  font-size: 0.74rem; font-weight: 600;
}
.f360-modal-close {
  width: 32px; height: 32px; border-radius: 50%;
  border: none; background: transparent;
  color: var(--brand-text-muted); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: all 0.15s ease;
}
.f360-modal-close:hover { background: var(--brand-bg); color: var(--brand-error); }
.f360-modal-body {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 18px 20px;
}
.f360-modal-footer {
  flex: 0 0 auto;
  padding: 12px 20px;
  border-top: 1px solid var(--brand-border);
  display: flex; gap: 10px; justify-content: flex-end;
}
.f360-modal-label {
  display: block;
  font-size: 0.78rem; font-weight: 600;
  color: var(--brand-text); margin: 12px 0 6px;
}
.f360-modal-label:first-child { margin-top: 0; }
.f360-modal-input {
  width: 100%; padding: 9px 12px;
  border: 1px solid var(--brand-border);
  border-radius: 6px;
  background: var(--brand-bg); color: var(--brand-text);
  font-size: 0.88rem; font-family: inherit;
  outline: none; transition: border-color 0.15s ease;
}
.f360-modal-input:focus { border-color: var(--brand-accent); }
.f360-modal-input.f360-money { font-variant-numeric: tabular-nums; font-weight: 600; }

/* Preview area */
.f360-modal-preview { margin-top: 14px; }
.f360-preview-ok, .f360-preview-warn, .f360-preview-error {
  padding: 10px 14px; border-radius: 6px; font-size: 0.84rem;
}
.f360-preview-ok { background: rgba(34, 197, 94, 0.12); color: #15803d; border-left: 3px solid #22c55e; }
.f360-preview-warn { background: rgba(234, 179, 8, 0.12); color: #a16207; border-left: 3px solid #eab308; }
.f360-preview-error { background: rgba(239, 68, 68, 0.12); color: #b91c1c; border-left: 3px solid #ef4444; }

/* AJUSTE: grid de motivos */
.f360-motivos-grid {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px;
}
.f360-motivo-card {
  display: flex; flex-direction: column; align-items: center;
  gap: 4px; padding: 10px 6px;
  border: 2px solid var(--brand-border);
  border-radius: 7px; background: var(--brand-bg);
  cursor: pointer; transition: all 0.15s ease; text-align: center;
}
.f360-motivo-card:hover { border-color: var(--brand-accent); }
.f360-motivo-card.selected {
  border-color: var(--brand-accent);
  background: rgba(147, 193, 31, 0.08);
}
.f360-motivo-card input[type="radio"] { display: none; }
.f360-motivo-card i { font-size: 1.1rem; color: var(--brand-accent); }
.f360-motivo-card span:not(.f360-motivo-tipo) { font-size: 0.78rem; font-weight: 500; color: var(--brand-text); }
.f360-motivo-tipo {
  font-size: 0.65rem; font-weight: 700;
  padding: 1px 6px; border-radius: 8px;
  text-transform: uppercase; letter-spacing: 0.3px;
}
.f360-motivo-tipo.entrada { background: rgba(34, 197, 94, 0.18); color: #15803d; }
.f360-motivo-tipo.salida { background: rgba(239, 68, 68, 0.18); color: #b91c1c; }

/* TRASLADO: flow origen → destino */
.f360-trs-flow {
  display: grid; grid-template-columns: 1fr auto 1fr;
  gap: 10px; align-items: end;
  margin-bottom: 10px;
}
.f360-trs-arrow {
  color: var(--brand-accent); font-size: 1.2rem;
  padding-bottom: 9px;
}

/* PRECIOS: grid 2x2 + margenes */
.f360-precios-grid {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px 14px;
}
.f360-margen-info {
  margin-top: 14px; padding: 10px 12px;
  background: var(--brand-bg);
  border: 1px dashed var(--brand-border);
  border-radius: 6px;
}
.f360-margen-row {
  display: flex; gap: 14px; flex-wrap: wrap;
  font-size: 0.78rem; color: var(--brand-text-muted);
}
.f360-margen-row strong, .f360-margen-row span span { font-weight: 700; }
.f360-margen-ok { color: #15803d; }
.f360-margen-warn { color: #a16207; }
.f360-margen-error { color: #b91c1c; }

.f360-modal-checks {
  margin-top: 14px;
  display: flex; flex-direction: column; gap: 8px;
}
.f360-check {
  display: flex; align-items: center; gap: 8px;
  font-size: 0.82rem; color: var(--brand-text); cursor: pointer;
  flex-wrap: wrap;
}
.f360-check input[type="checkbox"] { cursor: pointer; }
.f360-check small { color: var(--brand-text-muted); font-size: 0.72rem; }

/* Responsive móvil */
@media (max-width: 600px) {
  .f360-modal { max-height: 95vh; }
  .f360-motivos-grid { grid-template-columns: 1fr; }
  .f360-precios-grid { grid-template-columns: 1fr; }
  .f360-trs-flow { grid-template-columns: 1fr; gap: 8px; }
  .f360-trs-arrow { display: none; }
}

/* Dark mode */
[data-theme="dark"] .f360-modal { background: #1a2028; }
[data-theme="dark"] .f360-modal-input { background: #0f1419; border-color: #2d3740; color: #e4e8ec; }
[data-theme="dark"] .f360-motivo-card { background: #0f1419; border-color: #2d3740; }
[data-theme="dark"] .f360-margen-info { background: #0f1419; border-color: #2d3740; }

/* ═══════ DARK MODE (filas clickables) ═══════ */
[data-theme="dark"] .inv-row-clickable:hover,
[data-theme="dark"] .ref-row-clickable:hover { background: rgba(147, 193, 31, 0.12); }
[data-theme="dark"] .f360-drawer { background: #1a2028; }
[data-theme="dark"] .f360-header,
[data-theme="dark"] .f360-tabs,
[data-theme="dark"] .f360-footer { background: #1a2028; border-color: #2d3740; }
[data-theme="dark"] .f360-body { background: #0f1419; }
[data-theme="dark"] .f360-mini-kpi,
[data-theme="dark"] .f360-stock-card,
[data-theme="dark"] .f360-table { background: #1a2028; border-color: #2d3740; }
[data-theme="dark"] .f360-table tbody td { border-color: #2d3740; }
[data-theme="dark"] .f360-table tbody tr:hover { background: #0f1419; }
[data-theme="dark"] .f360-action-btn { background: #0f1419; border-color: #2d3740; }
