* { box-sizing: border-box; }
html, body {
  margin: 0;
  min-height: 100%;
  background: #000;
  color: #e8e8e8;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
}

a { color: #ff9a3c; }

.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  background: #0a0b0d;
  padding: 10px 16px;
  border-bottom: 1px solid #1c1e22;
}
.topbar__logo { height: 28px; }
.topbar__title { font-weight: 600; }
.topbar__spacer { flex: 1; }
.topbar__user { color: #999; font-size: 13px; }

button, input, select {
  font-family: inherit;
  font-size: 14px;
}
button {
  background: #16181d;
  color: #e8e8e8;
  border: 1px solid #2a2d33;
  border-radius: 6px;
  padding: 8px 14px;
  cursor: pointer;
}
button:hover { border-color: #ff9a3c; }
button:disabled { opacity: 0.4; cursor: not-allowed; }
button.primary { background: #ff9a3c; color: #1a1a1a; border-color: #ff9a3c; font-weight: 600; }
button.small { padding: 4px 10px; font-size: 12px; }

/* El boton "Descargar PDF" del modal de informe es un <a>, no un <button> --
   mismo look que .small para que no desentone en .modal__actions. */
a.small {
  display: inline-block;
  background: #16181d;
  color: #e8e8e8;
  border: 1px solid #2a2d33;
  border-radius: 6px;
  padding: 4px 10px;
  font-size: 12px;
  text-decoration: none;
  cursor: pointer;
  margin-right: auto;
}
a.small:hover { border-color: #ff9a3c; }
button.danger { border-color: #e05555; color: #ff8080; }

input, select {
  background: #16181d;
  color: #e8e8e8;
  border: 1px solid #2a2d33;
  border-radius: 6px;
  padding: 8px 10px;
}
input:focus, select:focus { outline: none; border-color: #ff9a3c; }

label { display: block; font-size: 13px; color: #999; margin-bottom: 4px; }
.field { margin-bottom: 12px; }

/* ---- Login ---- */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}
.login-card {
  background: #0a0b0d;
  border: 1px solid #1c1e22;
  border-radius: 10px;
  padding: 32px;
  width: 320px;
}
.login-card__logo { display: block; height: 40px; margin: 0 auto 20px; }
.login-error { color: #ff8080; font-size: 13px; min-height: 18px; margin-top: 8px; }

/* ---- Panel ---- */
.layout { display: flex; min-height: calc(100vh - 49px); }
.nav {
  width: 180px;
  flex: 0 0 auto;
  background: #0a0b0d;
  border-right: 1px solid #1c1e22;
  padding: 12px 0;
}
.nav__item {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  border-radius: 0;
  padding: 10px 16px;
  color: #999;
}
.nav__item:hover { border-color: transparent; color: #e8e8e8; }
.nav__item.active { color: #ff9a3c; border-left: 3px solid #ff9a3c; background: #16181d; }

.content { flex: 1; padding: 20px; overflow-x: auto; }
.section { display: none; }
.section.active { display: block; }
h2 { margin-top: 0; font-size: 18px; }

.summary { display: flex; gap: 16px; margin-bottom: 16px; flex-wrap: wrap; }
.summary__card {
  background: #0a0b0d;
  border: 1px solid #1c1e22;
  border-radius: 8px;
  padding: 12px 16px;
  min-width: 140px;
}
.summary__card b { display: block; font-size: 20px; color: #ff9a3c; }
.summary__card span { font-size: 12px; color: #999; }

.filters { display: flex; gap: 10px; align-items: end; margin-bottom: 16px; flex-wrap: wrap; }

table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid #1c1e22; white-space: nowrap; }
th { color: #999; font-weight: 500; }
td.wrap { white-space: normal; }
tr:hover td { background: #0a0b0d; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 11px; }
.badge--ok { background: #123; color: #6f6; background-color: #103a10; }
.badge--error { background: #3a1010; color: #ff8080; }
.badge--pending { background: #16181d; color: #999; }
.badge--emergencia { background: #3a2410; color: #ff9a3c; font-weight: 600; }

.actions { display: flex; gap: 6px; }

.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.6);
  display: flex; align-items: center; justify-content: center; z-index: 10;
}
.modal-backdrop.hidden { display: none; }
.modal {
  background: #0a0b0d;
  border: 1px solid #1c1e22;
  border-radius: 10px;
  padding: 24px;
  width: 360px;
}
.modal h3 { margin-top: 0; }
.modal__actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.modal--ancho { width: 440px; max-height: 85vh; overflow-y: auto; }

.error-msg { color: #ff8080; font-size: 13px; }
.hint { color: #666; font-size: 12px; margin-top: 4px; }

/* ---- Verificacion de medico contra el SACS (alta/edicion de usuario) ---- */
.sacs-block {
  background: #16181d;
  border: 1px solid #2a2d33;
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 12px;
}
.sacs-block__titulo {
  display: block;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: #ff9a3c;
  margin-bottom: 8px;
}
.sacs-block__fila { display: flex; gap: 8px; align-items: end; }
.sacs-block__fila .field { margin-bottom: 0; }
.sacs-estado { font-size: 12px; color: #999; min-height: 16px; margin-top: 8px; }
.sacs-estado--verificando { color: #6fc4ff; }
.sacs-estado--error { color: #ff8080; }
.sacs-estado--caido { color: #ffb454; }
.sacs-reintentar-btn { margin-left: 8px; }

.sacs-resultado {
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 12px;
  font-size: 13px;
}
.sacs-resultado--ok {
  background: #10240f;
  border: 1px solid #1d5c1a;
  color: #d7f5d4;
}
.sacs-resultado--pendiente {
  background: #2a2110;
  border: 1px solid #6b4a12;
  color: #ffe2b0;
}
.sacs-resultado__titulo { font-weight: 700; margin-bottom: 6px; }
.sacs-resultado dl { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; }
.sacs-resultado dt { color: #9aa0a8; }
.sacs-resultado dd { margin: 0; }

/* ---- Rediseño tabla de Estudios (paginación, iconos, estado unico) ----
   Reglas propias con sus propias clases -- a proposito NO se tocan las
   reglas genericas table/td/th/.badge/.actions de arriba, que siguen
   usando Clientes/Usuarios/Doctores/Alquiler tal cual estaban. */

.field--buscar { min-width: 220px; flex: 1 1 220px; }
.input-icon { position: relative; }
.input-icon__icon {
  position: absolute; left: 10px; top: 50%; transform: translateY(-50%);
  color: #666; pointer-events: none;
}
.input-icon input { padding-left: 32px; width: 100%; }

.btn-icon { display: inline-flex; align-items: center; gap: 6px; }
.btn-icon svg { flex: 0 0 auto; }

.badge--info { background: #102a3a; color: #6fc4ff; }

.estudios-table-wrap {
  /* A diferencia de las otras tablas del panel, esta NUNCA debe scrollear
     horizontal -- table-layout:fixed + colgroup de arriba reparten el
     ancho disponible, y las celdas largas truncan con ellipsis en vez de
     empujar el ancho. */
  width: 100%;
  overflow-x: hidden;
}
table.estudios-table { table-layout: fixed; width: 100%; }
table.estudios-table th, table.estudios-table td { white-space: normal; vertical-align: top; }

.cell-primary {
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-weight: 500;
}
.cell-secondary {
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-size: 12px; color: #999; margin-top: 2px;
}

.actions-icons { display: flex; gap: 4px; align-items: center; flex-wrap: wrap; position: relative; }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 30px; height: 30px; padding: 0;
  background: #16181d; border: 1px solid #2a2d33; border-radius: 6px;
  color: #ccc; cursor: pointer;
}
.icon-btn:hover:not(:disabled) { border-color: #ff9a3c; color: #fff; }
.icon-btn:focus-visible {
  outline: 2px solid #ff9a3c; outline-offset: 1px;
}
.icon-btn:disabled { opacity: 0.35; cursor: not-allowed; }
.icon-btn--accent { color: #ff9a3c; border-color: #6b4a12; }
.icon-btn--accent:hover:not(:disabled) { color: #ffb454; }
.icon-btn--whatsapp { color: #4fce5d; border-color: #1d5c1a; }
.icon-btn--whatsapp:hover:not(:disabled) { color: #7be888; }

.dropdown-menu {
  position: fixed;
  z-index: 30;
  background: #16181d;
  border: 1px solid #2a2d33;
  border-radius: 8px;
  padding: 4px;
  min-width: 190px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}
.dropdown-menu.hidden { display: none; }
.dropdown-menu__item {
  display: block; width: 100%; text-align: left;
  background: none; border: none; border-radius: 5px;
  padding: 8px 10px; font-size: 13px; color: #e8e8e8; cursor: pointer;
}
.dropdown-menu__item:hover { background: #0a0b0d; border-color: transparent; color: #ff9a3c; }
.dropdown-menu__item:disabled { opacity: 0.4; cursor: not-allowed; }

.table-pagination {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; flex-wrap: wrap; margin-top: 12px; font-size: 13px; color: #999;
}
.table-pagination__info { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
#paginaTamano { padding: 6px 8px; font-size: 12px; }
.pagination { display: flex; align-items: center; gap: 4px; }
.pagination__btn, .pagination__page {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 30px; height: 30px; padding: 0 6px;
  background: #16181d; border: 1px solid #2a2d33; border-radius: 6px;
  color: #ccc; cursor: pointer; font-size: 13px;
}
.pagination__btn:hover:not(:disabled), .pagination__page:hover:not(.pagination__page--activa) { border-color: #ff9a3c; color: #fff; }
.pagination__btn:disabled { opacity: 0.35; cursor: not-allowed; }
.pagination__page--activa { background: #ff9a3c; border-color: #ff9a3c; color: #1a1a1a; font-weight: 700; }
.pagination__ellipsis { padding: 0 4px; color: #666; }

/* Tablet: ya no hace falta bajar a tarjetas todavia, pero la info
   secundaria (cedula/correo debajo del dato principal) deja de aportar y
   compite por espacio -- se oculta, sigue disponible via el titulo (tooltip
   nativo) de la celda completa. */
@media (max-width: 980px) and (min-width: 721px) {
  .cell-secondary { display: none; }
  table.estudios-table col:nth-child(3) { width: 12% !important; }
  table.estudios-table col:nth-child(2) { width: 27% !important; }
}

/* ---- Mobile ---- */
@media (max-width: 720px) {
  .topbar { padding: 10px 12px; gap: 10px; }
  .topbar__title { font-size: 14px; }
  .topbar__user { display: none; }

  .layout { flex-direction: column; }
  .nav {
    width: 100%; display: flex; gap: 4px; padding: 8px 12px;
    border-right: none; border-bottom: 1px solid #1c1e22;
    overflow-x: auto;
  }
  .nav__item {
    width: auto; flex: 0 0 auto; border-radius: 6px; padding: 8px 12px;
    white-space: nowrap;
  }
  .nav__item.active { border-left: none; background: #16181d; }

  .content { padding: 14px; overflow-x: visible; }
  .summary { gap: 10px; }
  .summary__card { flex: 1 1 calc(50% - 10px); min-width: 0; }

  .filters { flex-direction: column; align-items: stretch; }
  .filters .field, .filters button { width: 100%; }

  table { display: block; width: 100%; border-collapse: collapse; }
  table thead { display: none; }
  table tbody { display: block; }
  table tr {
    display: block; margin-bottom: 12px; padding: 4px 12px;
    background: #0a0b0d; border: 1px solid #1c1e22; border-radius: 8px;
  }
  table td {
    display: flex; align-items: center; justify-content: space-between; gap: 14px;
    white-space: normal; text-align: right; padding: 10px 0;
    border-bottom: 1px solid #1c1e22;
  }
  table td:last-child { border-bottom: none; }
  table td::before {
    content: attr(data-label); color: #999; text-align: left; flex: 0 0 auto;
  }
  table td.actions { flex-direction: column; align-items: stretch; }
  table td.actions::before { text-align: left; margin-bottom: 6px; }
  table td .email-input { width: 100% !important; }

  .modal { width: calc(100vw - 32px); }

  /* Estudios: la celda de Paciente/Contacto pasa a columna (nombre arriba,
     dato secundario debajo, como en escritorio) en vez de la fila
     "etiqueta ... valor" generica -- se ve mejor con dos lineas de texto. */
  table.estudios-table td[data-label="Paciente"],
  table.estudios-table td[data-label="Contacto"] {
    flex-direction: column; align-items: flex-start; gap: 2px;
  }
  table.estudios-table td[data-label="Paciente"]::before,
  table.estudios-table td[data-label="Contacto"]::before {
    margin-bottom: 2px;
  }
  .cell-primary, .cell-secondary { white-space: normal; }

  table.estudios-table td.td-acciones {
    flex-direction: row; flex-wrap: wrap; justify-content: flex-start;
  }
  .actions-icons { flex-wrap: wrap; }

  .table-pagination { flex-direction: column; align-items: stretch; }
  .table-pagination__info { justify-content: space-between; }
  .pagination { justify-content: center; flex-wrap: wrap; }
}

/* ---- Doctores (medicos con acceso) ---- */
/* A diferencia de la tabla de Estudios, esta tiene muchas columnas de ancho
   variable (SACS/centros/estado) -- se deja scrollear horizontal adentro de
   su propio contenedor en vez de forzar table-layout:fixed. */
.table-wrap-x { width: 100%; overflow-x: auto; }
#medicosTabla { white-space: nowrap; }
#medicosTabla td, #medicosTabla th { padding: 8px 10px; }

.badge--estado {
  display: inline-block; padding: 2px 8px; border-radius: 999px;
  font-size: 11px; font-weight: 600; white-space: nowrap;
}
.badge--estado.ok { background: #103a1e; color: #6fdb8f; }
.badge--estado.pendiente { background: #3a2f10; color: #e8c368; }
.badge--estado.espera { background: #102a3a; color: #6fc4ff; }
.badge--estado.error { background: #3a1010; color: #ff8080; }
.badge--estado.apagado { background: #26282e; color: #999; }

.checklist {
  display: flex; flex-direction: column; gap: 6px; max-height: 160px;
  overflow-y: auto; border: 1px solid #2a2d33; border-radius: 6px; padding: 8px;
}
.checklist label { display: flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 400; }
.checklist input[type="checkbox"], .checklist input[type="radio"] { width: auto; }
.checklist__principal { margin-left: auto; font-size: 11px; color: #999; display: flex; align-items: center; gap: 4px; }

/* Permisos de operador (Fase 2): interruptor con nombre + explicacion en la
   misma linea/label, en vez de un checklist de una sola palabra por fila. */
.permiso-toggle { display: flex; align-items: flex-start; gap: 8px; font-size: 13px; font-weight: 400; padding: 4px 0; }
.permiso-toggle input[type="checkbox"] { width: auto; margin-top: 2px; }
.permiso-toggle .hint { display: inline; margin: 0; color: #999; }

.firmantes-legacy { color: #ccc; }
.firmantes-legacy > summary { cursor: pointer; color: #999; font-size: 13px; padding: 6px 0; }
.firmantes-legacy > summary:hover { color: #ccc; }
