:root {
  --azul: #4f46e5;
  --azul-oscuro: #3730a3;
  --azul-suave: #eef2ff;
  --verde: #059669;
  --rojo: #e11d48;
  --gris-fondo: #f8fafc;
  --gris-borde: #e2e8f0;
  --texto: #0f172a;
  --texto-suave: #64748b;
  --sombra-suave: 0 1px 2px rgba(15, 23, 42, 0.06), 0 1px 3px rgba(15, 23, 42, 0.06);
  --sombra-media: 0 8px 24px rgba(15, 23, 42, 0.12);
  --radio: 12px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--gris-fondo);
  color: var(--texto);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

nav.topbar {
  background: var(--azul-oscuro);
  color: white;
  padding: 0.9rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  box-shadow: 0 2px 10px rgba(15, 23, 42, 0.18);
  position: sticky;
  top: 0;
  z-index: 40;
}

nav.topbar a {
  color: rgba(255, 255, 255, 0.9);
  text-decoration: none;
  font-weight: 500;
}

nav.topbar .brand {
  font-size: 1.2rem;
  font-weight: 700;
  color: white;
  letter-spacing: -0.01em;
}

nav.topbar .links {
  display: flex;
  gap: 1.2rem;
  align-items: center;
}

nav.topbar .links a {
  padding: 0.4rem 0.2rem;
  border-radius: 6px;
  transition: color 0.15s ease;
}

nav.topbar .links a:hover {
  color: white;
  text-decoration: none;
}

.dropdown {
  position: relative;
}

.dropdown-toggle {
  cursor: pointer;
  font-weight: 500;
  user-select: none;
}

/* .dropdown-menu cubre también el espacio entre el texto "Consultas" y el
   menú visible (vía padding-top, no margin-top) para que ese hueco siga
   contando como parte del área con :hover y el menú no se cierre al bajar
   el cursor hacia las opciones. El recuadro blanco visible vive en
   .dropdown-menu-inner. */
.dropdown-menu {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  padding-top: 0.6rem;
  min-width: 210px;
  z-index: 30;
}

.dropdown:hover .dropdown-menu,
.dropdown:focus-within .dropdown-menu,
.dropdown.open .dropdown-menu {
  display: block;
}

.dropdown-menu-inner {
  background: white;
  border: 1px solid var(--gris-borde);
  border-radius: var(--radio);
  box-shadow: var(--sombra-media);
  padding: 0.4rem 0;
  overflow: hidden;
}

.dropdown-menu a {
  display: block;
  padding: 0.6rem 1.1rem;
  color: var(--texto) !important;
  font-weight: 500;
  transition: background-color 0.12s ease;
}

.dropdown-menu a:hover {
  background: var(--azul-suave);
  text-decoration: none !important;
}

.container {
  max-width: 1000px;
  margin: 0 auto;
  padding: 1.5rem;
}

.card {
  background: white;
  border: 1px solid var(--gris-borde);
  border-radius: var(--radio);
  box-shadow: var(--sombra-suave);
  padding: 1.5rem;
  margin-bottom: 1.2rem;
}

.consulta-dialog {
  background: white;
  border: none;
  border-radius: var(--radio);
  box-shadow: var(--sombra-media);
  padding: 1.5rem;
  max-width: 560px;
  width: 90vw;
}

.consulta-dialog::backdrop {
  background: rgba(15, 23, 42, 0.5);
  backdrop-filter: blur(2px);
}

h1, h2, h3 {
  color: var(--texto);
  letter-spacing: -0.01em;
}

.flash {
  padding: 0.7rem 1rem;
  border-radius: var(--radio);
  margin-bottom: 1rem;
}

.flash.success {
  background: #dcfce7;
  color: #166534;
  border: 1px solid #86efac;
}

.flash.error {
  background: #fee2e2;
  color: #991b1b;
  border: 1px solid #fca5a5;
}

.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 0 -0.2rem;
  padding: 0 0.2rem;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th, td {
  text-align: left;
  padding: 0.7rem 0.6rem;
  border-bottom: 1px solid var(--gris-borde);
}

th {
  color: var(--texto-suave);
  font-weight: 600;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

tr {
  transition: background-color 0.1s ease;
}

tr:hover {
  background: var(--azul-suave);
}

a.btn, button.btn {
  display: inline-block;
  background: var(--azul);
  color: white;
  border: none;
  padding: 0.6rem 1.15rem;
  border-radius: 9px;
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.08);
  transition: background-color 0.15s ease, transform 0.1s ease, box-shadow 0.15s ease;
}

a.btn:hover, button.btn:hover {
  background: var(--azul-oscuro);
  transform: translateY(-1px);
  box-shadow: 0 4px 10px rgba(55, 48, 163, 0.25);
}

a.btn:active, button.btn:active {
  transform: translateY(0);
}

button.btn.danger, a.btn.danger {
  background: var(--rojo);
}

button.btn.danger:hover, a.btn.danger:hover {
  background: #9f1239;
  box-shadow: 0 4px 10px rgba(159, 18, 57, 0.25);
}

.btn-row {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
  margin-top: 1rem;
}

form.inline {
  display: inline;
}

label {
  display: block;
  font-weight: 600;
  margin-top: 0.9rem;
  margin-bottom: 0.35rem;
  font-size: 0.88rem;
  color: var(--texto);
}

input, select, textarea {
  width: 100%;
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--gris-borde);
  border-radius: 9px;
  font-size: 0.95rem;
  font-family: inherit;
  background: white;
  color: var(--texto);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--azul);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.15);
}

textarea {
  min-height: 90px;
  resize: vertical;
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 1.2rem;
}

.search-bar {
  display: flex;
  gap: 0.6rem;
  margin-bottom: 1rem;
}

.search-bar input {
  flex: 1;
}

.badge {
  display: inline-block;
  padding: 0.25rem 0.65rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
}

.badge.medico {
  background: var(--azul-suave);
  color: var(--azul-oscuro);
}

.badge.personal {
  background: #fef3c7;
  color: #92400e;
}

.section-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 2rem;
}

.login-wrap {
  max-width: 400px;
  margin: 4rem auto;
}

.login-card {
  text-align: center;
}

.login-logo {
  width: 110px;
  height: auto;
  margin: 0 auto 0.8rem;
  display: block;
}

.login-title {
  margin: 0 0 0.4rem;
  font-size: 1.3rem;
  line-height: 1.3;
}

.login-subtitle {
  color: var(--texto-suave);
  font-size: 0.92rem;
  margin: 0 0 1rem;
}

.login-card form {
  text-align: left;
}

.login-card .btn-row {
  justify-content: center;
}

.login-verse {
  margin-top: 1.6rem;
  padding-top: 1rem;
  border-top: 1px solid var(--gris-borde);
  color: var(--texto-suave);
  font-style: italic;
  font-size: 0.85rem;
  line-height: 1.5;
}

.muted {
  color: var(--texto-suave);
  font-size: 0.88rem;
}

.empty {
  color: var(--texto-suave);
  font-style: italic;
  padding: 1rem 0;
}

/* ---------------------------------------------------------------------- */
/* Chat interno (widget flotante)                                          */
/* ---------------------------------------------------------------------- */

.chat-widget {
  position: fixed;
  right: 1.5rem;
  bottom: 1.5rem;
  z-index: 1000;
  font-family: inherit;
}

.chat-bubble {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: none;
  background: var(--azul);
  color: white;
  font-size: 1.5rem;
  cursor: pointer;
  box-shadow: 0 6px 18px rgba(79, 70, 229, 0.35);
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.15s ease, transform 0.15s ease;
}

.chat-bubble:hover {
  background: var(--azul-oscuro);
  transform: translateY(-2px);
}

.chat-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  background: var(--rojo);
  color: white;
  font-size: 0.7rem;
  font-weight: 700;
  min-width: 20px;
  height: 20px;
  border-radius: 999px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
}

.chat-panel {
  position: absolute;
  bottom: 68px;
  right: 0;
  width: 330px;
  max-width: calc(100vw - 2rem);
  height: 440px;
  max-height: calc(100vh - 8rem);
  background: white;
  border: 1px solid var(--gris-borde);
  border-radius: var(--radio);
  box-shadow: var(--sombra-media);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.chat-panel-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.6rem 0.7rem;
  background: var(--azul-oscuro);
  color: white;
}

.chat-panel-header select {
  flex: 1;
  padding: 0.35rem 0.5rem;
  border-radius: 6px;
  border: none;
  font-size: 0.85rem;
}

.chat-panel-header button {
  background: none;
  border: none;
  color: white;
  font-size: 1.3rem;
  line-height: 1;
  cursor: pointer;
  padding: 0 0.2rem;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 0.7rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  background: var(--gris-fondo);
}

.chat-messages::-webkit-scrollbar {
  width: 6px;
}

.chat-messages::-webkit-scrollbar-thumb {
  background: var(--gris-borde);
  border-radius: 999px;
}

.chat-message {
  max-width: 80%;
  padding: 0.5rem 0.7rem;
  border-radius: 12px;
  background: white;
  border: 1px solid var(--gris-borde);
  font-size: 0.88rem;
  align-self: flex-start;
  box-shadow: var(--sombra-suave);
}

.chat-message.mine {
  align-self: flex-end;
  background: var(--azul-suave);
  border-color: #c7d2fe;
}

.chat-message .chat-message-sender {
  font-weight: 700;
  font-size: 0.75rem;
  color: var(--azul-oscuro);
  display: block;
  margin-bottom: 0.15rem;
}

.chat-message .chat-message-time {
  display: block;
  font-size: 0.68rem;
  color: var(--texto-suave);
  margin-top: 0.2rem;
}

.chat-message img.chat-attachment-image {
  max-width: 100%;
  border-radius: 8px;
  margin-top: 0.3rem;
  display: block;
}

.chat-message a.chat-attachment-file {
  display: inline-block;
  margin-top: 0.3rem;
  font-size: 0.82rem;
}

.chat-form {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem;
  border-top: 1px solid var(--gris-borde);
}

.chat-form input[type="text"] {
  flex: 1;
  padding: 0.45rem 0.65rem;
  font-size: 0.88rem;
}

.chat-form .btn {
  padding: 0.45rem 0.75rem;
  font-size: 0.85rem;
}

.chat-attach-btn {
  background: none;
  border: none;
  font-size: 1.2rem;
  cursor: pointer;
  padding: 0.2rem;
}

.chat-file-preview {
  padding: 0.3rem 0.7rem 0.5rem;
  font-size: 0.8rem;
  color: var(--texto-suave);
  border-top: 1px solid var(--gris-borde);
}

/* ---------------------------------------------------------------------- */
/* Responsive: tablets (iPad) y celulares                                  */
/* ---------------------------------------------------------------------- */

/* Objetivos táctiles más grandes en cualquier tamaño de pantalla, para que
   sea cómodo tocar botones y campos desde un iPad o celular. */
a.btn, button.btn {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

input, select, textarea {
  min-height: 44px;
}

textarea {
  min-height: 90px;
}

@media (max-width: 900px) {
  nav.topbar {
    padding: 0.8rem 1rem;
  }

  nav.topbar .links {
    gap: 0.9rem;
  }

  .container {
    padding: 1rem;
  }

  .grid-2 {
    grid-template-columns: 1fr;
    gap: 0;
  }
}

@media (max-width: 640px) {
  nav.topbar {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.6rem;
  }

  nav.topbar .links {
    width: 100%;
    flex-wrap: wrap;
    row-gap: 0.5rem;
  }

  .dropdown-menu {
    left: auto;
    right: 0;
  }

  .section-title {
    flex-wrap: wrap;
    gap: 0.6rem;
  }

  .card {
    padding: 1.1rem;
  }

  table {
    font-size: 0.88rem;
  }

  .table-scroll table {
    min-width: 480px;
  }
}

/* El menú "Consultas" funciona con :hover en escritorio (mouse) y además
   con la clase .open, que nav.js agrega al tocar/hacer clic, para que
   también funcione en pantallas táctiles (iPad) donde no existe :hover. */

/* En pantallas de tablet/celular, el chat deja de ser un recuadro flotante
   y pasa a ocupar toda la pantalla mientras está abierto, como cualquier
   app de mensajería (WhatsApp, Messenger, etc.). */
@media (max-width: 820px) {
  .chat-widget {
    right: 1rem;
    bottom: 1rem;
  }

  .chat-panel {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    max-width: 100%;
    height: 100%;
    max-height: 100%;
    border-radius: 0;
  }

  .chat-panel-header {
    padding: 0.9rem 1rem;
    padding-top: max(0.9rem, env(safe-area-inset-top));
  }

  .chat-panel-header select {
    font-size: 1rem;
    padding: 0.5rem 0.6rem;
  }

  .chat-panel-header button {
    font-size: 1.6rem;
  }

  .chat-messages {
    padding: 1rem;
  }

  .chat-message {
    max-width: 88%;
    font-size: 0.95rem;
  }

  .chat-form {
    padding: 0.7rem;
    padding-bottom: max(0.7rem, env(safe-area-inset-bottom));
  }

  .chat-form input[type="text"] {
    font-size: 1rem;
  }

  /* Con el chat a pantalla completa, la burbuja flotante se oculta para no
     quedar encima del panel mientras está abierto. */
  .chat-widget.chat-open .chat-bubble {
    display: none;
  }
}
