/* base-ui.css — Componentes y utilidades del sistema de diseño.
   El layout base (.layout, .content, sidebar) viene de index-modern.css */
@import url('./tokens.css');

/* Accesibilidad */
.sr-only {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

/* Botones con estilo premium */
.am-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--spacing-sm);
  padding: 10px 18px;
  border-radius: var(--radius-md);
  font-weight: 600;
  font-size: 14px;
  border-radius: 10px; /* Refuerzo de redondeo */
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  border: 1px solid transparent;
  text-decoration: none;
}

.am-btn-primary {
  background: var(--color-primary);
  color: var(--color-white);
}

.am-btn-primary:hover {
  background: var(--color-primary-dark);
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

.am-btn-secondary {
  background: var(--color-secondary);
  color: var(--color-white);
}

.am-btn-outline {
  border-color: var(--color-border);
  background: var(--color-white);
  color: var(--color-text);
}

.am-btn-outline:hover {
  border-color: var(--color-primary);
  color: var(--color-primary);
}

.am-btn-danger {
  background: #fee2e2;
  color: #dc2626;
  border: 1px solid #fca5a5;
}

.am-btn-danger:hover {
  background: #fecaca;
}

.am-btn-icon {
  padding: 0;
  width: 38px;
  height: 38px;
  border-radius: 10px;
}

.am-btn-icon i {
  font-size: 16px;
}

/* Tarjetas (Cards) */
.am-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--spacing-lg);
  box-shadow: var(--shadow-sm);
  transition: box-shadow 0.3s ease;
}

.am-card:hover {
  box-shadow: var(--shadow-md);
}

/* Utilidades de Grid */
.am-grid {
  display: grid;
  gap: var(--spacing-md);
}

.am-grid-2 { grid-template-columns: repeat(2, 1fr); }
.am-grid-3 { grid-template-columns: repeat(3, 1fr); }
.am-grid-4 { grid-template-columns: repeat(4, 1fr); }

@media (max-width: 768px) {
  .am-grid-2, .am-grid-3, .am-grid-4 {
    grid-template-columns: 1fr;
  }
}

.am-badge[data-level="none"] { background: #f8fafc; border-color: #e2e8f0; color: #94a3b8; }

/* Indicadores y Etiquetas (Tags) Modernos */
.am-indicator-label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 600;
}

.am-indicator-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.am-label-green { color: #059669; } .am-label-green .am-indicator-dot { background: #059669; }
.am-label-red { color: #dc2626; }   .am-label-red .am-indicator-dot { background: #dc2626; }
.am-label-blue { color: #2563eb; }  .am-label-blue .am-indicator-dot { background: #2563eb; }
.am-label-gray { color: #94a3b8; }  .am-label-gray .am-indicator-dot { background: #94a3b8; }

.am-tag {
  display: inline-flex;
  align-items: center;
  padding: 3px 12px;
  border-radius: 20px;
  font-size: 11.5px;
  font-weight: 700;
  border: 1px solid transparent;
  line-height: 1;
}

.am-tag-teal { background: #0d948815; color: #0d9488; border-color: #0d948830; }
.am-tag-purple { background: #7c3aed15; color: #7c3aed; border-color: #7c3aed30; }
.am-tag-blue { background: #2563eb15; color: #2563eb; border-color: #2563eb30; }
.am-tag-amber { background: #f59e0b15; color: #f59e0b; border-color: #f59e0b30; }
.am-tag-orange { background: #d9770615; color: #d97706; border-color: #d9770630; }
.am-tag-slate { background: #64748b15; color: #64748b; border-color: #64748b30; }
.am-tag-gray { background: #f1f5f9; color: #94a3b8; border-color: #e2e8f0; }

/* Toasts Personalizados */
.am-toast-success { background: #059669 !important; font-weight: 600; border-radius: 12px !important; }
.am-toast-error { background: #dc2626 !important; font-weight: 600; border-radius: 12px !important; }

/* 
  ELIMINACIÓN DEFINITIVA DE MANCHAS ROJAS (TAP-TARGET / FEATURE DISCOVERY)
  Se suprimen todos los elementos y sus envoltorios e indicadores de animación.
*/
.tap-target-wrapper,
.tap-target,
.tap-target-wave,
.tap-target-origin,
.tap-target-content,
[class*="tap-target"] {
  display: none !important;
  visibility: hidden !important;
  opacity: 0 !important;
  pointer-events: none !important;
  z-index: -1000 !important;
  width: 0 !important;
  height: 0 !important;
}

/* Hero Section Premium */
.am-hero {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 32px 0;
  margin-bottom: 24px;
}

.am-hero-content h1 {
  margin: 0;
  font-size: 28px;
  font-weight: 800;
  color: #0f172a;
  letter-spacing: -0.025em;
}

.am-hero-content p {
  margin: 4px 0 0;
  color: #64748b;
  font-size: 15px;
  font-weight: 500;
}

/* Navegación por Pestañas Principal */
.am-tabs-main {
  display: flex;
  gap: 8px;
  margin-bottom: 24px;
  background: #f1f5f9;
  padding: 6px;
  border-radius: 14px;
  overflow-x: auto;
  scrollbar-width: none;
}

.am-tabs-main::-webkit-scrollbar {
  display: none;
}

.am-tab-btn {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 20px;
  border: none;
  background: transparent;
  color: #64748b;
  font-weight: 600;
  font-size: 14px;
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  white-space: nowrap;
}

.am-tab-btn i {
  font-size: 18px;
}

.am-tab-btn:hover {
  color: #0f172a;
  background: rgba(255, 255, 255, 0.5);
}

.am-tab-btn.active {
  background: #ffffff;
  color: var(--color-primary);
  box-shadow: 0 4px 12px rgba(0, 168, 168, 0.15);
}

/* Títulos de Sección */
.am-section-title h5 {
  margin: 0 0 4px;
  font-weight: 800;
  color: #0f172a;
}

.am-section-title p {
  margin: 0;
  color: #64748b;
  font-size: 14px;
}

/* Grupos de Enfoque (Filtros rápidos) */
.am-focus-group {
  margin-top: 16px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.am-focus-btn {
  padding: 6px 14px;
  border-radius: 20px;
  border: 1px solid #e2e8f0;
  background: #ffffff;
  color: #64748b;
  font-size: 12.5px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s ease;
}

.am-focus-btn:hover {
  background: #f8fafc;
  border-color: #cbd5e1;
}

.am-focus-btn.active {
  background: #0f172a;
  color: #ffffff;
  border-color: #0f172a;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
}

/* Grupos de Etapa (Muestras) */
.am-stage-group {
  margin-top: 12px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.am-stage-group.is-hidden { display: none; }

.am-stage-btn {
  padding: 4px 12px;
  border-radius: 8px;
  border: 1px solid rgba(0, 168, 168, 0.3);
  background: #f0fdfa;
  color: var(--color-primary-dark);
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s ease;
}

.am-stage-btn.active {
  background: var(--color-primary);
  color: #ffffff;
  border-color: var(--color-primary);
}

/* Barra de Filtros y Búsqueda */
.am-filter-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 20px;
  padding: 16px;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
}

.am-filter-left, .am-filter-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

/* Inputs y Selects Modernos */
.am-select,
.am-input,
select.modern-select,
select.act-select,
select.resumen-select {
  height: 38px;
  border: 1px solid #cbd5e1;
  border-radius: 10px;
  padding: 0 12px;
  background: #ffffff;
  font-size: 14px;
  color: #0f172a;
  transition: border-color 0.2s;
  outline: none;
  width: 100%;
  box-sizing: border-box;
}

.am-select,
select.modern-select,
select.act-select,
select.resumen-select {
  cursor: pointer;
  padding-right: 32px;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%2364748b'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M19 9l-7 7-7-7'%3E%3C/path%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-size: 16px;
}

.am-select:focus,
.am-input:focus,
select.modern-select:focus,
select.act-select:focus,
select.resumen-select:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(0, 168, 168, 0.12);
}

.am-search-field {
  position: relative;
  display: flex;
  align-items: center;
  flex: 1;
  min-width: 280px;
}

.am-search-field i {
  position: absolute;
  left: 12px;
  color: #94a3b8;
  font-size: 16px;
  pointer-events: none;
}

.am-search-field .am-input {
  width: 100%;
  padding-left: 38px;
}

/* Grupos de Exportación */
.am-export-group {
  display: flex;
  background: #ffffff;
  border: 1px solid #cbd5e1;
  border-radius: 10px;
  overflow: hidden;
}

.am-export-btn {
  padding: 0 12px;
  height: 36px;
  border: none;
  background: transparent;
  color: #64748b;
  font-size: 11px;
  font-weight: 800;
  cursor: pointer;
  border-right: 1px solid #e2e8f0;
  transition: all 0.2s;
}

.am-export-btn:last-child {
  border-right: none;
}

.am-export-btn:hover {
  background: #f1f5f9;
  color: #0f172a;
}

/* ══════════════════════════════════════════════════════════
   SISTEMA DE MODALES (CSS puro — reemplaza Materialize)
══════════════════════════════════════════════════════════ */
.am-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(2, 8, 23, 0.55);
  z-index: 3000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  animation: fadeIn .2s ease;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.am-modal {
  background: #ffffff;
  border-radius: 18px;
  border: 1px solid #dbe4f1;
  box-shadow: 0 24px 52px rgba(2, 8, 23, 0.35);
  width: 100%;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: slideUp .22s ease;
}

@keyframes slideUp {
  from { transform: translateY(16px); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}

.am-modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 18px 24px;
  border-bottom: 1px solid #e2e8f0;
  background: #f8fafc;
  flex-shrink: 0;
}

.am-modal-title {
  margin: 0;
  font-size: 20px;
  font-weight: 800;
  color: #0f172a;
}

.am-modal-close {
  width: 36px;
  height: 36px;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  background: #fff;
  color: #475569;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.am-modal-close:hover {
  background: #fee2e2;
  border-color: #fca5a5;
  color: #dc2626;
}

.am-modal-body {
  padding: 20px 24px;
  overflow-y: auto;
  flex: 1;
}

.am-modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 14px 24px;
  border-top: 1px solid #e2e8f0;
  background: #f8fafc;
  flex-shrink: 0;
}

/* ══════════════════════════════════════════════════════════
   FORMULARIOS MODERNOS
══════════════════════════════════════════════════════════ */
.am-form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
}

.am-form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.am-label {
  font-size: 13px;
  font-weight: 700;
  color: #475569;
}

.am-muted {
  font-size: 12px;
  color: #64748b;
}

.am-btn-sm {
  height: 32px;
  padding: 0 12px;
  font-size: 12px;
  border-radius: 8px;
}

/* ══════════════════════════════════════════════════════════
   TABLA UNIFICADA
══════════════════════════════════════════════════════════ */
.am-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.am-table th,
.am-table td {
  padding: 10px 12px;
  border-bottom: 1px solid #e2e8f0;
  text-align: left;
}

.am-table th {
  font-weight: 700;
  color: #475569;
  background: #f8fafc;
}

.am-table tbody tr:hover {
  background: #f1f5f9;
}

/* ══════════════════════════════════════════════════════════
   TOAST ANIMATION
══════════════════════════════════════════════════════════ */
@keyframes fadeInUp {
  from { opacity: 0; transform: translateX(-50%) translateY(8px); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ══════════════════════════════════════════════════════════
   UTILIDADES PREMIUM (Reemplazo de Inline Styles)
   ══════════════════════════════════════════════════════════ */
.am-p-24   { padding: 24px !important; }
.am-px-24  { padding-left: 24px !important; padding-right: 24px !important; }
.am-py-16  { padding-top: 16px !important; padding-bottom: 16px !important; }
.am-p-0    { padding: 0 !important; }

.am-mt-8   { margin-top: 8px !important; }
.am-mt-16  { margin-top: 16px !important; }
.am-mt-20  { margin-top: 20px !important; }
.am-mb-10  { margin-bottom: 10px !important; }
.am-mb-20  { margin-bottom: 20px !important; }

.am-flex-center { display: flex; align-items: center; justify-content: center; }
.am-flex-between { display: flex; align-items: center; justify-content: space-between; }
.am-gap-8   { gap: 8px !important; }
.am-gap-12  { gap: 12px !important; }

.am-border-base { 
  border: 1.5px solid #e2e8f0 !important; 
  border-radius: 10px !important; 
  overflow: hidden !important;
}

.am-font-bold { font-weight: 700 !important; }
.am-text-xs { font-size: 10px !important; }
.am-text-sm { font-size: 12px !important; }

/* Ocultación de elementos específicos de módulos */
.muestreo-hidden { display: none !important; }
.consulta-filter-state { font-size: 13px; color: #64748b; font-weight: 500; }

/* ── Modo solo lectura (rol: lectura) ──────────────────────────────────
   Se activa añadiendo .modo-lectura al <body> desde auth.js.
   Oculta todos los controles de escritura sin tocar cada página. */
body.modo-lectura [data-edit],
body.modo-lectura [data-toggle],
body.modo-lectura [data-nuevo],
body.modo-lectura [data-delete],
body.modo-lectura .write-only,
body.modo-lectura .js-edit,
body.modo-lectura .js-delete,
body.modo-lectura .mini-del,
body.modo-lectura .tbl-act-edit,
body.modo-lectura .tbl-act-delete,
body.modo-lectura .btn-edit,
body.modo-lectura .trato-btn-editar {
  display: none !important;
}

/* Banner sutil para que Gerencia sepa que está en modo lectura */
body.modo-lectura::after {
  content: '👁 Solo lectura';
  position: fixed;
  bottom: 16px;
  right: 16px;
  background: rgba(15,23,42,0.85);
  border: 1px solid rgba(20,184,166,0.3);
  color: #2dd4bf;
  font-size: 11px;
  font-weight: 600;
  padding: 5px 12px;
  border-radius: 20px;
  z-index: 9999;
  pointer-events: none;
  letter-spacing: 0.04em;
}
