* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --azul: #2c7be5;
  --azul-oscuro: #1a5bb8;
  --fondo: #f4f6f8;
  --texto: #2b3440;
  --borde: #d6dee6;
  --verde: #2bb673;
  --rojo: #e74c3c;
  --amarillo: #ffc107;
}

html { font-size: 16px; }

body {
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, Arial, sans-serif;
  background: var(--fondo);
  color: var(--texto);
  padding-bottom: calc(80px + env(safe-area-inset-bottom, 0px));
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

header {
  background: linear-gradient(135deg, var(--azul), var(--azul-oscuro));
  color: white;
  padding: 18px 20px;
  padding-top: calc(18px + env(safe-area-inset-top, 0px));
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  box-shadow: 0 2px 8px rgba(0,0,0,.15);
}
header h1 { font-size: 1.25rem; font-weight: 700; letter-spacing: .3px; }

.header-user { display: flex; align-items: center; gap: 10px; font-size: .85rem; }

.badge {
  background: rgba(255,255,255,.2);
  padding: 2px 8px;
  border-radius: 10px;
  font-size: .75rem;
  text-transform: uppercase;
  letter-spacing: .5px;
}

.logout {
  background: rgba(255,255,255,.15);
  border: 1px solid rgba(255,255,255,.4);
  padding: 5px 12px;
  font-size: .8rem;
  border-radius: 6px;
}
.logout:hover { background: rgba(255,255,255,.3); }

.pantalla { display: none; padding: 20px; max-width: 720px; margin: 0 auto; }
.pantalla.activa { display: block; animation: fade .25s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

h2 { margin-bottom: 15px; color: var(--azul); font-size: 1.35rem; font-weight: 700; }
h3 { margin: 20px 0 10px; font-size: 1.05rem; color: #444; }

form {
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: white;
  padding: 18px;
  border-radius: 10px;
  margin-bottom: 22px;
  box-shadow: 0 1px 4px rgba(0,0,0,.06);
}

fieldset {
  border: 1px solid var(--borde);
  border-radius: 8px;
  padding: 12px 14px 14px;
  margin-bottom: 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
fieldset legend { font-weight: 600; color: var(--azul); padding: 0 6px; font-size: .9rem; }

label { font-size: .9rem; font-weight: 500; color: #45505e; }
.req { color: var(--rojo); font-weight: 700; }

input, select, textarea {
  width: 100%;
  padding: 10px;
  margin-top: 5px;
  border: 1px solid var(--borde);
  border-radius: 6px;
  font-size: 1rem;
  font-family: inherit;
  color: var(--texto);
  background: #fbfcfd;
  transition: border-color .15s;
  resize: vertical;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--azul); background: white; }

button {
  background: var(--azul);
  color: white;
  border: none;
  padding: 11px;
  border-radius: 7px;
  cursor: pointer;
  font-size: .95rem;
  font-weight: 600;
  font-family: inherit;
  transition: background .15s, transform .05s;
}
button:hover { background: var(--azul-oscuro); }
button:active { transform: scale(.985); }
button:disabled { opacity: .6; cursor: not-allowed; }
button.secundario { background: #eef2f6; color: var(--azul-oscuro); }
button.secundario:hover { background: #dde6ee; }

.link-btn {
  background: none;
  color: var(--azul-oscuro);
  padding: 4px;
  font-size: .85rem;
  font-weight: 500;
  text-decoration: underline;
}
.link-btn:hover { background: none; color: var(--azul); }

/* ===== CITAS ===== */
#lista-citas { list-style: none; }
#lista-citas li {
  background: white;
  padding: 14px;
  margin-bottom: 10px;
  border-radius: 9px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  border-left: 4px solid var(--azul);
  box-shadow: 0 1px 3px rgba(0,0,0,.05);
}
#lista-citas li.pasada { border-left-color: var(--borde); opacity: .65; }
#lista-citas li.vacio { border-left-color: var(--borde); color: #778; }
#lista-citas button { background: var(--rojo); padding: 6px 10px; font-size: .8rem; flex-shrink: 0; }
#lista-citas button:hover { background: #c0392b; }
.cita-fecha { text-transform: capitalize; }

/* ===== NAVEGACIÓN ===== */
.tabs {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  display: flex;
  background: white;
  border-top: 1px solid var(--borde);
  box-shadow: 0 -2px 8px rgba(0,0,0,.06);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
.tab { flex: 1; background: white; color: #667; border-radius: 0; padding: 15px; font-size: .9rem; font-weight: 600; }
.tab.activo { color: var(--azul); border-top: 3px solid var(--azul); background: #f8fbff; }
.tab:hover { background: #f0f4f9; }

/* ===== AVISOS ===== */
.aviso {
  background: #fff8e1;
  border-left: 5px solid var(--amarillo);
  padding: 12px 14px;
  margin-bottom: 15px;
  border-radius: 6px;
  font-size: .9rem;
}
.aviso.borrador { background: #e8f5ff; border-left-color: var(--azul); }

.oculto { display: none !important; }

/* ===== EXPEDIENTE ===== */
#datos-expediente {
  background: white;
  padding: 18px;
  border-radius: 10px;
  margin-top: 15px;
  box-shadow: 0 1px 4px rgba(0,0,0,.06);
  line-height: 1.7;
}
#datos-expediente p { margin-bottom: 6px; overflow-wrap: anywhere; }
#datos-expediente small { color: #778; }
#datos-expediente h4 { margin-top: 14px; color: var(--azul); font-size: .95rem; }
.exp-grid { display: grid; grid-template-columns: 1fr; gap: 4px; }
@media (min-width: 600px) { .exp-grid { grid-template-columns: 1fr 1fr; } }
#exp-resumen-wrap h3 { margin-top: 22px; }

.campo-error {
  border-color: var(--rojo) !important;
  background: #fff5f5 !important;
  box-shadow: 0 0 0 2px rgba(231,76,60,.15);
}

/* ===== PERFIL ===== */
.perfil-card {
  background: white;
  padding: 18px;
  border-radius: 10px;
  margin-bottom: 15px;
  box-shadow: 0 1px 4px rgba(0,0,0,.06);
  line-height: 1.9;
  overflow-wrap: anywhere;
}

.panel-admin {
  margin-top: 25px;
  padding: 18px;
  background: #fffbe6;
  border: 1px solid #f0e0a0;
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
#lista-admins { list-style: none; margin-top: 10px; }
#lista-admins li {
  background: white; padding: 8px 12px; border-radius: 6px;
  margin-bottom: 6px; font-size: .85rem;
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
}
#lista-admins li span { overflow-wrap: anywhere; }
#lista-admins button { background: var(--rojo); padding: 4px 9px; font-size: .75rem; flex-shrink: 0; }

/* ===== PANTALLAS SUPERPUESTAS ===== */
.overlay {
  position: fixed; inset: 0;
  background: linear-gradient(160deg, #2c7be5 0%, #1a4a99 100%);
  display: flex; align-items: center; justify-content: center;
  padding: 20px; z-index: 100;
  overflow-y: auto;
}
.card-login {
  background: white;
  padding: 30px 26px;
  border-radius: 14px;
  max-width: 400px;
  width: 100%;
  margin: auto;
  box-shadow: 0 10px 40px rgba(0,0,0,.25);
}
.card-login.centrado { text-align: center; color: #667; }
.card-login h1, .card-login h2 { color: var(--azul); margin-bottom: 8px; font-size: 1.4rem; }
.card-login .subtitulo { color: #667; margin-bottom: 20px; font-size: .9rem; }
.card-login form { box-shadow: none; padding: 0; background: transparent; margin-bottom: 0; }

.auth-tabs { display: flex; gap: 6px; margin-bottom: 16px; background: #eef2f6; padding: 4px; border-radius: 9px; }
.auth-tab { flex: 1; background: transparent; color: #556; padding: 9px; font-size: .9rem; }
.auth-tab:hover { background: rgba(255,255,255,.6); }
.auth-tab.activo { background: white; color: var(--azul); box-shadow: 0 1px 3px rgba(0,0,0,.1); }

.lista-onboarding { list-style: none; margin: 15px 0; line-height: 2; font-size: .92rem; }
.lista-onboarding li { padding-left: 4px; }
.nota { font-size: .82rem; color: #778; margin-bottom: 18px; }

.error-msg { color: var(--rojo); font-size: .85rem; min-height: 1.1em; margin-top: 4px; }
.ok-msg { color: #1f9a5f; font-size: .85rem; min-height: 1.1em; }
.error-msg.ok { color: #1f9a5f; }

@media (max-width: 480px) {
  html { font-size: 15px; }
  header h1 { font-size: 1.1rem; }
  .pantalla { padding: 15px; }
  fieldset { padding: 10px; }
}
