/* ================================================================
   custom.css — Claymorphism + Quality Audit & Roles Module
   Hospital de Villarrica — Oficina de Calidad y Seguridad Asistencial
   ================================================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800;900&display=swap');

html, body {
  font-family: 'Inter', system-ui, sans-serif;
  background-color: #f3f4f8;
  color: #0f172a;
  min-height: 100vh;
  margin: 0;
}

/* ── Hero Gradient Card ──────────────────────────────── */
.clay-card-hero {
  background: linear-gradient(135deg, #1e3a8a 0%, #1d4ed8 50%, #2563eb 100%);
  color: white;
  border-radius: 2rem;
  box-shadow:
    0 25px 50px -12px rgba(29, 78, 216, 0.35),
    0 10px 20px -5px rgba(30, 58, 138, 0.2),
    inset 0 2px 3px rgba(255, 255, 255, 0.35);
  border: 1px solid rgba(255, 255, 255, 0.25);
  position: relative;
  overflow: hidden;
}

/* ── Floating Clay Card ──────────────────────────────── */
.clay-card {
  background: #ffffff;
  border-radius: 1.75rem;
  box-shadow:
    0 20px 40px -15px rgba(15, 23, 42, 0.07),
    0 8px 20px -6px rgba(15, 23, 42, 0.03),
    inset 0 1px 2px rgba(255, 255, 255, 0.95);
  border: 1.5px solid rgba(255, 255, 255, 0.9);
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.3s ease;
  position: relative;
  z-index: 10;
}

.clay-card:hover {
  transform: translateY(-3px);
  box-shadow:
    0 30px 60px -20px rgba(37, 99, 235, 0.12),
    0 12px 24px -8px rgba(15, 23, 42, 0.05),
    inset 0 1px 2px rgba(255, 255, 255, 1);
}

/* Interactive KPI Card */
.kpi-clickable {
  cursor: pointer;
  transition: all 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.kpi-clickable:hover {
  transform: translateY(-4px) scale(1.02);
  box-shadow: 0 16px 32px -4px rgba(37, 99, 235, 0.2);
}

.kpi-clickable.active-filter {
  border-color: #2563eb !important;
  background: #eff6ff !important;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.25) !important;
}

.section-title-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.75rem;
  background: #eff6ff;
  color: #1e40af;
  font-weight: 800;
  font-size: 1rem;
  padding: 0.5rem 1.25rem;
  border-radius: 9999px;
  box-shadow: 0 4px 12px -2px rgba(37, 99, 235, 0.15), inset 0 1px 1px rgba(255, 255, 255, 0.8);
  border: 1px solid #bfdbfe;
  margin-bottom: 1.25rem;
}

.section-icon-3d {
  width: 32px;
  height: 32px;
  background: linear-gradient(135deg, #3b82f6, #1d4ed8);
  color: white;
  border-radius: 9999px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  box-shadow: 0 4px 10px rgba(29, 78, 216, 0.3);
}

.clay-input, .clay-select, .clay-textarea {
  width: 100%;
  background: #f8fafc;
  border-radius: 1.25rem;
  border: 1.5px solid #e2e8f0;
  box-shadow: inset 0 2px 4px rgba(15, 23, 42, 0.03);
  padding: 0.75rem 1.25rem;
  font-family: inherit;
  font-size: 0.875rem;
  color: #0f172a;
  outline: none;
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.clay-input:focus, .clay-select:focus, .clay-textarea:focus {
  background: #ffffff;
  border-color: #2563eb;
  box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.12), 0 4px 12px -2px rgba(37, 99, 235, 0.1);
}

.clay-select {
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='18' height='18' viewBox='0 0 24 24' fill='none' stroke='%232563eb' stroke-width='2.5'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 1rem center;
  padding-right: 2.75rem;
}

.clay-textarea { resize: vertical; min-height: 85px; }

.clay-pill-group { display: flex; gap: 0.75rem; }

.clay-pill-btn {
  flex: 1;
  padding: 0.625rem 1.25rem;
  border-radius: 9999px;
  background: #f1f5f9;
  color: #475569;
  font-weight: 700;
  font-size: 0.8125rem;
  border: 1.5px solid #e2e8f0;
  box-shadow: 0 4px 10px rgba(15, 23, 42, 0.04);
  cursor: pointer;
  transition: all 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
  text-align: center;
}

.clay-pill-btn:hover {
  transform: translateY(-2px);
  background: #ffffff;
  border-color: #3b82f6;
  color: #1d4ed8;
}

.clay-pill-btn.active {
  background: linear-gradient(135deg, #ef4444, #dc2626) !important;
  color: white !important;
  border-color: #dc2626 !important;
  box-shadow: 0 10px 20px -4px rgba(239, 68, 68, 0.4), inset 0 2px 2px rgba(255, 255, 255, 0.3) !important;
}

.clay-btn-main {
  background: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%);
  color: white;
  font-weight: 800;
  font-size: 0.95rem;
  padding: 0.875rem 2.5rem;
  border-radius: 9999px;
  border: none;
  cursor: pointer;
  box-shadow: 0 14px 28px -6px rgba(37, 99, 235, 0.45), inset 0 2px 3px rgba(255, 255, 255, 0.4);
  transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  display: inline-flex;
  align-items: center;
  gap: 0.625rem;
}

.clay-btn-main:hover {
  transform: translateY(-3px) scale(1.02);
  box-shadow: 0 20px 36px -6px rgba(37, 99, 235, 0.55), inset 0 2px 3px rgba(255, 255, 255, 0.5);
}

.floating-bottom-bar {
  position: fixed;
  bottom: 1.25rem;
  left: 50%;
  transform: translateX(-50%);
  width: min(90%, 46rem);
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(16px);
  border-radius: 9999px;
  padding: 0.75rem 2rem;
  box-shadow: 0 20px 50px -10px rgba(15, 23, 42, 0.18), inset 0 1px 2px rgba(255, 255, 255, 0.9);
  border: 1.5px solid rgba(255, 255, 255, 0.9);
  z-index: 90;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.conditional-block { display: none; animation: clayPopIn 0.35s cubic-bezier(0.34, 1.56, 0.64, 1) forwards; }
.conditional-block.visible { display: block; }

@keyframes clayPopIn {
  from { opacity: 0; transform: translateY(-12px) scale(0.98); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* Caja de Auditoría Exclusiva Oficina de Calidad */
.audit-quality-box {
  background: linear-gradient(135deg, #fefce8 0%, #fef9c3 100%);
  border-radius: 1.75rem;
  padding: 1.75rem;
  border: 2px solid #fde047;
  box-shadow: 0 16px 32px -8px rgba(202, 138, 4, 0.2), inset 0 1px 2px rgba(255, 255, 255, 0.9);
}

.score-badge {
  display: inline-flex; align-items: center; gap: .5rem;
  padding: .5rem 1.25rem; border-radius: 9999px;
  font-weight: 800; font-size: .8125rem;
  box-shadow: 0 4px 12px rgba(0,0,0,0.06);
}

.score-bajo    { background: #dcfce7; color: #15803d; border: 1px solid #86efac; }
.score-mediano { background: #fef3c7; color: #b45309; border: 1px solid #fcd34d; }
.score-alto    { background: #fee2e2; color: #b91c1c; border: 1px solid #fca5a5; }

/* ================================================================
   1. GLASSMORPHISM LOGIN PORTAL (LANDING / GATEKEEPER)
   ================================================================ */
.glass-login-screen {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  background: linear-gradient(135deg, rgba(15, 23, 42, 0.75), rgba(30, 58, 138, 0.65)),
              url('https://images.unsplash.com/photo-1506744038136-46273834b3fb?auto=format&fit=crop&w=1920&q=80') center/cover no-repeat;
  animation: fadeIn .3s ease-out;
}

.glass-card {
  width: 100%;
  max-width: 390px;
  background: rgba(255, 255, 255, 0.18);
  backdrop-filter: blur(25px) saturate(180%);
  -webkit-backdrop-filter: blur(25px) saturate(180%);
  border-radius: 2.25rem;
  border: 1.5px solid rgba(255, 255, 255, 0.4);
  box-shadow: 0 30px 60px -12px rgba(0, 0, 0, 0.4), inset 0 1px 2px rgba(255, 255, 255, 0.6);
  padding: 2.5rem 2rem;
  color: white;
}

.glass-input-wrapper {
  position: relative;
  margin-bottom: 1.25rem;
}

.glass-input-wrapper input {
  width: 100%;
  background: rgba(255, 255, 255, 0.15);
  border: 1.5px solid rgba(255, 255, 255, 0.35);
  border-radius: 1.25rem;
  padding: 0.875rem 3rem 0.875rem 1.25rem;
  font-family: inherit;
  font-size: 0.9375rem;
  color: #ffffff;
  outline: none;
  transition: all 0.25s ease;
}

.glass-input-wrapper input::placeholder { color: rgba(255, 255, 255, 0.7); }

.glass-input-wrapper input:focus {
  background: rgba(255, 255, 255, 0.25);
  border-color: rgba(255, 255, 255, 0.8);
  box-shadow: 0 0 0 4px rgba(255, 255, 255, 0.2);
}

.glass-icon {
  position: absolute;
  right: 1.25rem;
  top: 50%;
  transform: translateY(-50%);
  color: rgba(255, 255, 255, 0.8);
  font-size: 1.1rem;
}

.glass-btn-green {
  width: 100%;
  background: linear-gradient(135deg, #84cc16 0%, #16a34a 100%);
  color: white;
  font-weight: 800;
  font-size: 1.1rem;
  padding: 0.95rem;
  border-radius: 1.25rem;
  border: none;
  cursor: pointer;
  box-shadow: 0 12px 25px -4px rgba(22, 163, 74, 0.5), inset 0 2px 2px rgba(255, 255, 255, 0.4);
  transition: all 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
  margin-top: 1rem;
}

.glass-btn-green:hover {
  transform: translateY(-2px);
  box-shadow: 0 16px 30px -4px rgba(22, 163, 74, 0.65);
}

/* ================================================================
   2. SIDEBAR FLOTANTE VERTICAL LATERAL (HOVER AUTO-EXPANDIBLE ORIGINAL)
   ================================================================ */
.floating-sidebar {
  position: fixed;
  left: 1.25rem;
  top: 50%;
  transform: translateY(-50%);
  width: 4.5rem;
  height: max-content;
  max-height: 92vh;
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-radius: 2.25rem;
  border: 1.5px solid rgba(255, 255, 255, 0.95);
  box-shadow:
    0 25px 60px -10px rgba(15, 23, 42, 0.18),
    0 10px 25px -4px rgba(37, 99, 235, 0.12),
    inset 0 2px 3px rgba(255, 255, 255, 1);
  padding: 0.75rem 0.5rem;
  z-index: 900;
  transition: width 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
  overflow-x: hidden;
  overflow-y: auto;
  white-space: nowrap;
  display: flex;
  flex-direction: column;
}

.floating-sidebar:hover {
  width: 22rem;
  box-shadow:
    0 30px 70px -10px rgba(15, 23, 42, 0.25),
    0 15px 35px -5px rgba(37, 99, 235, 0.2),
    inset 0 2px 3px rgba(255, 255, 255, 1);
}

.sidebar-item {
  display: flex;
  align-items: center;
  gap: 0.875rem;
  padding: 0.625rem;
  border-radius: 9999px;
  color: #334155;
  font-weight: 700;
  font-size: 0.8125rem;
  cursor: pointer;
  transition: all 0.2s ease;
  margin-bottom: 0.5rem;
  user-select: none;
  width: 100%;
  box-sizing: border-box;
}

.sidebar-item:last-child {
  margin-bottom: 0;
}

.sidebar-item:hover {
  background: #eff6ff;
  color: #1d4ed8;
}

.sidebar-item.active {
  background: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%) !important;
  color: #ffffff !important;
  box-shadow: 0 10px 20px -4px rgba(37, 99, 235, 0.38), inset 0 2px 2px rgba(255, 255, 255, 0.35) !important;
}

.sidebar-icon {
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 9999px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  background: #f1f5f9;
  color: #1e40af;
  box-shadow: inset 0 2px 4px rgba(15, 23, 42, 0.05);
  transition: all 0.25s ease;
}

.sidebar-item.active .sidebar-icon {
  background: rgba(255, 255, 255, 0.22);
  color: #ffffff;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.15);
}

.sidebar-text {
  opacity: 0;
  transition: opacity 0.25s ease 0.05s;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 0.8125rem;
  font-weight: 700;
}

.floating-sidebar:hover .sidebar-text {
  opacity: 1;
}

/* Modal Overlay General — Centrado Popup Flotante sobre Sidebar y Pantalla */
.modal-overlay, .audit-modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  width: 100vw;
  height: 100vh;
  z-index: 9999;
  background: rgba(15, 23, 42, 0.7);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.25rem;
  overflow-y: auto;
  animation: modalFadeIn 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.modal-overlay > div, .audit-modal-overlay > div {
  margin: auto !important;
  transform-origin: center center;
  animation: modalPopUp 0.3s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
  max-height: 90vh !important;
}

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

@keyframes modalPopUp {
  from { opacity: 0; transform: scale(0.92) translateY(10px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

/* Formato de Impresión PDF Tamaño Carta (Derivaciones y Manual Operativo v1.0) */
@media print {
  @page {
    size: letter portrait;
    margin: 10mm 12mm;
  }

  body, html {
    background: #ffffff !important;
    color: #000000 !important;
    margin: 0 !important;
    padding: 0 !important;
    width: 100% !important;
    height: auto !important;
    overflow: visible !important;
  }

  /* Ocultar elementos generales de UI durante impresión */
  body * {
    visibility: hidden !important;
  }

  .floating-sidebar,
  .toast-container,
  .no-print {
    display: none !important;
  }

  /* MODOS DE IMPRESIÓN EXCLUSIVOS */
  
  /* 1. MODO IMPRESIÓN DERIVACIÓN DE EVENTO (FORMULARIO 1 HOJA CARTA) */
  body.printing-derivacion #print-derivacion-area,
  body.printing-derivacion #print-derivacion-area * {
    visibility: visible !important;
  }

  body.printing-derivacion #print-derivacion-area {
    display: block !important;
    position: absolute !important;
    left: 0 !important;
    top: 0 !important;
    width: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
    background: #ffffff !important;
    color: #000000 !important;
    z-index: 999999 !important;
  }

  body.printing-derivacion #manual-uso-modal {
    display: none !important;
  }

  /* 2. MODO IMPRESIÓN MANUAL OPERATIVO (DOCUMENTO OFICIAL V1.0) */
  body.printing-manual #print-derivacion-area {
    display: none !important;
  }

  body.printing-manual #manual-uso-modal {
    display: block !important;
    position: absolute !important;
    top: 0 !important;
    left: 0 !important;
    width: 100% !important;
    height: auto !important;
    background: #ffffff !important;
    z-index: 999999 !important;
    padding: 0 !important;
    margin: 0 !important;
    overflow: visible !important;
  }

  body.printing-manual #manual-uso-modal .clay-card {
    max-height: none !important;
    height: auto !important;
    border: none !important;
    box-shadow: none !important;
    padding: 0 !important;
    margin: 0 !important;
    width: 100% !important;
    max-width: 100% !important;
    overflow: visible !important;
    background: #ffffff !important;
  }

  body.printing-manual #printable-manual-container,
  body.printing-manual #printable-manual-container * {
    visibility: visible !important;
  }

  body.printing-manual #printable-manual-container {
    display: block !important;
    position: static !important;
    width: 100% !important;
    height: auto !important;
    overflow: visible !important;
    padding: 0 !important;
    margin: 0 !important;
    background: #ffffff !important;
    color: #000000 !important;
  }

  /* PREVENCIÓN ESTRICTA DE ENTRECORTADO DE PÁGINAS Y TARJETAS EN IMPRESIÓN */
  .manual-page-card,
  .print-no-break,
  .rounded-xl,
  .border,
  h1, h2, h3, h4 {
    page-break-inside: avoid !important;
    break-inside: avoid !important;
    box-shadow: none !important;
  }

  .manual-page-card {
    border: 1px solid #cbd5e1 !important;
    border-radius: 12px !important;
    padding: 18px !important;
    margin-bottom: 20px !important;
    background: #ffffff !important;
  }

  .page-break {
    page-break-before: always !important;
    break-before: page !important;
  }
}

.manual-page-card {
  background: #ffffff;
  border-radius: 1.5rem;
  border: 1px solid #e2e8f0;
  box-shadow: 0 4px 12px rgba(15, 23, 42, 0.05);
  padding: 2rem;
  margin-bottom: 1.5rem;
}

.manual-section-title {
  font-size: 1.25rem;
  font-weight: 900;
  color: #1e3a8a;
  border-bottom: 2.5px solid #2563eb;
  padding-bottom: 0.5rem;
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.manual-badge-tech {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.35rem 0.75rem;
  border-radius: 9999px;
  font-size: 0.75rem;
  font-weight: 800;
  background: #eff6ff;
  color: #1d4ed8;
  border: 1px solid #bfdbfe;
}

.field-error { font-size: 0.75rem; color: #ef4444; margin-top: 0.25rem; font-weight: 700; }
.toast-container { position: fixed; top: 1.5rem; right: 1.5rem; z-index: 9999; }
