/* ============================================================
   ficha-referencia.css - Estilos Ficha Referencia (~200 lin)
   Modal overlay centrado en desktop, fullscreen en movil
   Tabla editable, formulario con grid responsive
   ============================================================ */

/* --- Container principal (ya no usa drawer) --- */
.ref-container { display: flex; flex-direction: column; }
.ref-main { flex: 1; min-width: 0; overflow-y: auto; }

/* --- Modal overlay + modal box --- */
.ref-modal-overlay {
  display: none; position: fixed; inset: 0; z-index: 1000;
  background: rgba(0,0,0,0.45); backdrop-filter: blur(2px);
  align-items: center; justify-content: center; padding: 24px;
}
.ref-modal-overlay.open { display: flex; }

.ref-modal {
  width: 100%; max-width: 720px; max-height: 88vh;
  background: var(--brand-surface); border-radius: 14px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3); display: flex; flex-direction: column;
  overflow: hidden; animation: refModalIn 0.2s ease;
}
@keyframes refModalIn {
  from { opacity: 0; transform: translateY(16px) scale(0.97); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* --- Modal header --- */
.ref-modal-header {
  display: flex; align-items: flex-start; justify-content: space-between;
  padding: 20px 24px 16px; border-bottom: 1px solid var(--brand-border);
  flex-shrink: 0;
}
.ref-modal-title h3 {
  font-size: 1.05rem; margin: 0; color: var(--brand-text); line-height: 1.3;
}
.ref-modal-title span { font-size: 0.75rem; }
.ref-modal-title code { font-size: 0.72rem; background: rgba(0,0,0,0.04); padding: 1px 6px; border-radius: 4px; }
.ref-modal-header-actions { display: flex; gap: 6px; flex-shrink: 0; margin-left: 12px; }
.ref-modal-close {
  width: 34px; height: 34px; border-radius: 8px; border: 1px solid var(--brand-border);
  background: none; cursor: pointer; color: var(--brand-text-muted);
  font-size: 1.1rem; display: flex; align-items: center; justify-content: center;
  transition: all 0.15s;
}
.ref-modal-close:hover { background: rgba(239,68,68,0.08); color: var(--brand-error); border-color: var(--brand-error); }

/* --- Modal tabs --- */
.ref-modal-tabs {
  display: flex; border-bottom: 1px solid var(--brand-border); padding: 0 16px;
  flex-shrink: 0;
}
.ref-tab {
  flex: 1; padding: 11px 10px; border: none; background: none; cursor: pointer;
  font-size: 0.76rem; font-weight: 600; font-family: var(--font-family);
  color: var(--brand-text-muted); border-bottom: 2.5px solid transparent;
  transition: all 0.15s; display: flex; align-items: center; gap: 5px; justify-content: center;
}
.ref-tab:hover { color: var(--brand-text); }
.ref-tab.active { color: var(--brand-accent); border-bottom-color: var(--brand-accent); }

/* --- Modal body (scrollable) --- */
.ref-modal-body {
  flex: 1; overflow-y: auto; padding: 20px 24px;
  -webkit-overflow-scrolling: touch;
}

/* --- Modal footer --- */
.ref-modal-footer {
  display: flex; gap: 10px; padding: 14px 24px;
  border-top: 1px solid var(--brand-border); flex-shrink: 0;
}
.ref-modal-footer .btn-save { flex: 1; justify-content: center; }
.ref-modal-footer .btn-del { flex-shrink: 0; }

/* --- Form grid system --- */
.ref-form { display: flex; flex-direction: column; gap: 12px; }
.ref-form-grid {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px;
}
.ref-form-grid.tri { grid-template-columns: repeat(3, 1fr); }
.ref-form-grid.quad { grid-template-columns: repeat(4, 1fr); }
.ref-form-grid .full { grid-column: 1 / -1; }
.ref-field { min-width: 0; }
.ref-field.full { grid-column: 1 / -1; }
.ref-field label {
  display: block; font-size: 0.68rem; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.3px; color: var(--brand-text-muted); margin-bottom: 4px;
}
.ref-input {
  width: 100%; height: 36px; border: 1.5px solid var(--brand-border); border-radius: 7px;
  padding: 0 10px; font-size: 0.82rem; font-family: var(--font-family);
  color: var(--brand-text); background: var(--brand-bg); transition: border-color 0.15s;
  box-sizing: border-box;
}
.ref-input:focus { outline: none; border-color: var(--brand-accent); background: #fff; box-shadow: 0 0 0 3px rgba(147,193,31,0.1); }
textarea.ref-input { height: auto; padding: 8px 10px; resize: vertical; line-height: 1.4; }
select.ref-input { appearance: auto; }

.ref-section-title {
  font-size: 0.78rem; font-weight: 700; color: var(--brand-text);
  margin: 4px 0 0; padding-bottom: 6px; border-bottom: 1px solid var(--brand-border);
}

/* --- Stock table inside modal --- */
.ref-stock-table { width: 100%; border-collapse: collapse; font-size: 0.8rem; margin-top: 8px; }
.ref-stock-table th {
  padding: 8px 10px; font-size: 0.7rem; text-transform: uppercase;
  color: var(--brand-text-muted); border-bottom: 1.5px solid var(--brand-border); text-align: left;
}
.ref-stock-table td { padding: 8px 10px; border-bottom: 1px solid var(--brand-border); }

/* ====== Botones de accion (compartidos tabla + modal) ====== */
.btn-ref-action {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px; border-radius: 8px; border: 1.5px solid var(--brand-border);
  background: var(--brand-surface); color: var(--brand-text);
  font-size: 0.8rem; font-weight: 600; cursor: pointer;
  font-family: var(--font-family); transition: all 0.15s;
}
.btn-ref-action:hover { border-color: var(--brand-accent); }
.btn-add { border-color: var(--brand-accent); background: rgba(147,193,31,0.08); color: var(--brand-accent-dark, #5a7a0f); }
.btn-add:hover { background: var(--brand-accent); color: #fff; }
.btn-save { border-color: var(--brand-accent); background: var(--brand-accent); color: #fff; }
.btn-save:hover { opacity: 0.9; }
.btn-del { border-color: var(--brand-error); background: rgba(239,68,68,0.06); color: var(--brand-error); }
.btn-del:hover { background: var(--brand-error); color: #fff; }

/* ====== Tabla editable ====== */
.ref-table td { font-size: 0.78rem; }
.ref-editable { cursor: pointer; position: relative; }
.ref-editable:hover { background: rgba(147,193,31,0.06); }
.ref-editable::after {
  content: '\f303'; font-family: 'Font Awesome 6 Free'; font-weight: 900;
  position: absolute; right: 4px; top: 50%; transform: translateY(-50%);
  font-size: 0.6rem; color: var(--brand-text-muted); opacity: 0; transition: opacity 0.15s;
}
.ref-editable:hover::after { opacity: 0.5; }
.ref-inline-input {
  width: 100%; border: 1.5px solid var(--brand-accent); border-radius: 4px;
  padding: 4px 6px; font-size: 0.78rem; font-family: var(--font-family);
  background: #fff; color: var(--brand-text); outline: none;
}
.ref-num { font-variant-numeric: tabular-nums; }
.ref-estado {
  display: inline-block; padding: 2px 8px; border-radius: 10px;
  font-size: 0.72rem; font-weight: 600;
}
.ref-estado.activo { background: rgba(34,197,94,0.1); color: #16a34a; }
.ref-estado.inactivo { background: rgba(156,163,175,0.15); color: #6b7280; }
.row-selected td { background: rgba(147,193,31,0.08) !important; }

/* --- Botones tabla inline --- */
.ref-btn-detail, .ref-btn-dup, .ref-btn-del {
  width: 28px; height: 28px; border-radius: 6px; border: 1px solid var(--brand-border);
  background: var(--brand-surface); cursor: pointer; color: var(--brand-text-muted);
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 0.7rem; transition: all 0.15s;
}
.ref-btn-detail:hover { border-color: var(--brand-accent); color: var(--brand-accent); }
.ref-btn-dup:hover { border-color: #3b82f6; color: #3b82f6; }
.ref-btn-del:hover { border-color: var(--brand-error); color: var(--brand-error); }
.ref-actions-cell { white-space: nowrap; }
.ref-actions-cell button + button { margin-left: 4px; }

/* --- Mobile cards ficha --- */
.ref-card .card-top { margin-bottom: 6px; }
.ref-card .card-ref { display: block; margin-top: 2px; }
.ref-card-actions { display: flex; gap: 6px; }

/* ====== Responsive ====== */
@media (max-width: 768px) {
  .ref-modal-overlay { padding: 0; align-items: flex-end; }
  .ref-modal {
    max-width: 100%; max-height: 95vh; border-radius: 16px 16px 0 0;
    animation: refModalSlideUp 0.25s ease;
  }
  @keyframes refModalSlideUp {
    from { transform: translateY(100%); }
    to   { transform: translateY(0); }
  }
  .ref-modal-header { padding: 16px 16px 12px; }
  .ref-modal-body { padding: 16px; }
  .ref-modal-footer { padding: 12px 16px; }
  .ref-form-grid { grid-template-columns: 1fr; }
  .ref-form-grid.tri { grid-template-columns: repeat(2, 1fr); }
  .ref-form-grid.quad { grid-template-columns: repeat(2, 1fr); }
  .ref-tab { font-size: 0.7rem; padding: 10px 6px; }
  .ref-tab i { display: none; }
  .ref-editable::after { display: none; }
}

@media (min-width: 769px) and (max-width: 1024px) {
  .ref-modal { max-width: 620px; }
  .ref-form-grid.quad { grid-template-columns: repeat(2, 1fr); }
}
