:root {
  --navy: #12377A;
  --navy-light: #2463C7;
  --navy-dark: #081D42;
  --silver: #C8D0DC;
  --red: #FF3B30;
  --red-light: #FF6E58;
  --red-dark: #D3241A;
  --green: #1EA35E;
  --amber: #FFB020;
  --bg: #EEF3FC;
  --card-bg: #FFFFFF;
  --text: #12213D;
  --text-muted: #5A6478;
  --border: #DCE3F0;
  --focus: #1E6FEB;

  --radius-lg: 28px;
  --radius-md: 18px;
  --radius-sm: 12px;

  --tap-min: 56px;
  --step-scale: 1;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

body:not(.high-contrast) {
  background: radial-gradient(1100px 700px at 12% -8%, #DCE9FF 0%, var(--bg) 45%);
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: contain;
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
}

button, input, a { font-family: inherit; }

/* ---------- Barra superior ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: linear-gradient(120deg, var(--navy) 0%, var(--navy-light) 100%);
  color: #fff;
  flex-shrink: 0;
}
.logo-badge {
  width: 40px;
  height: 40px;
  flex-shrink: 0;
  border-radius: 50%;
  object-fit: contain;
}
.topbar-title {
  flex: 1;
  font-weight: 700;
  font-size: 1.05rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.icon-btn {
  width: var(--tap-min);
  height: var(--tap-min);
  min-width: 44px;
  min-height: 44px;
  border: none;
  border-radius: 14px;
  background: rgba(255,255,255,0.12);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.icon-btn svg { width: 26px; height: 26px; }
.icon-btn:active { background: rgba(255,255,255,0.28); }
.lang-btn { font-size: 1.4rem; line-height: 1; }
#btn-back::before { content: ''; }
#btn-contrast::after { content: attr(data-label); }

/* ---------- Layout general de vistas ---------- */
#app {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}
.view {
  display: none;
  flex-direction: column;
  flex: 1;
  padding: 20px 18px calc(24px + env(safe-area-inset-bottom));
}
.view.active { display: flex; }

.section-title {
  font-size: 1.3rem;
  margin: 18px 0 10px;
  color: var(--text);
}

.link-button {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1rem;
  padding: 14px;
  margin-top: 8px;
  cursor: pointer;
  text-decoration: underline;
}

/* ---------- VISTA INICIO ---------- */
.view-home {
  background: radial-gradient(1000px 700px at 50% -10%, var(--navy-light) 0%, var(--navy) 55%, var(--navy-dark) 100%);
}

.home-wrap {
  flex: 1;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 30px;
}

.home-logo {
  width: min(64vw, 245px);
  height: auto;
  filter: drop-shadow(0 12px 26px rgba(0,0,0,0.4));
}

.sos-button {
  width: 100%;
  max-width: 380px;
  min-height: 108px;
  border-radius: 26px;
  background: radial-gradient(circle at 30% 25%, #FF9A6E 0%, var(--red-light) 25%, var(--red) 62%, var(--red-dark) 100%);
  border: 5px solid #ffffff;
  box-shadow: 0 16px 36px rgba(0,0,0,0.4), 0 0 0 8px rgba(255,255,255,0.14);
  color: #fff;
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  gap: 18px;
  padding: 14px 26px;
  cursor: pointer;
  animation: sos-breathe 2.4s ease-in-out infinite;
}
.sos-button:active { transform: scale(0.97); animation: none; }
@keyframes sos-breathe {
  0%, 100% { box-shadow: 0 16px 36px rgba(0,0,0,0.4), 0 0 0 8px rgba(255,255,255,0.14); }
  50% { box-shadow: 0 16px 42px rgba(0,0,0,0.45), 0 0 0 16px rgba(255,255,255,0.06); }
}
.sos-icon {
  width: 56px; height: 56px;
  flex-shrink: 0;
  border-radius: 50%;
  background: #fff;
  position: relative;
}
.sos-icon::before, .sos-icon::after {
  content: '';
  position: absolute;
  background: var(--red);
  border-radius: 4px;
}
.sos-icon::before { width: 26px; height: 9px; top: 23.5px; left: 15px; }
.sos-icon::after { width: 9px; height: 26px; top: 15px; left: 23.5px; }

.sos-label {
  font-size: 1.55rem;
  font-weight: 800;
  letter-spacing: 0.5px;
}
.home-hint {
  text-align: center;
  color: rgba(255,255,255,0.85);
  font-size: 1.05rem;
  max-width: 32ch;
  margin: 0;
}
.disclaimer {
  text-align: center;
  font-size: 0.82rem;
  color: rgba(255,255,255,0.65);
  border-top: 1px solid rgba(255,255,255,0.25);
  padding-top: 14px;
  margin: 0;
  line-height: 1.4;
}

/* ---------- VISTA SOS ---------- */
.sos-status {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--navy);
  color: #fff;
  padding: 12px 16px;
  border-radius: var(--radius-md);
  font-weight: 700;
  font-size: 1.05rem;
}
.pulse-dot {
  width: 12px; height: 12px;
  border-radius: 50%;
  background: #ff6b6b;
  flex-shrink: 0;
  animation: pulse 1.2s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.4; transform: scale(0.7); }
}

.call-button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-top: 14px;
  background: linear-gradient(135deg, var(--red-light) 0%, var(--red) 55%, var(--red-dark) 100%);
  color: #fff;
  font-size: 1.35rem;
  font-weight: 800;
  text-decoration: none;
  padding: 20px;
  border-radius: var(--radius-lg);
  min-height: 72px;
  box-shadow: 0 10px 22px rgba(255,59,48,0.4);
}
.call-button:active { background: var(--red-dark); }
.icon-inline { width: 26px; height: 26px; display: inline-flex; flex-shrink: 0; }
.icon-inline svg { width: 100%; height: 100%; }

.location-row {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 16px;
}
.location-status {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-muted);
  font-size: 0.95rem;
}
.location-status svg { width: 20px; height: 20px; flex-shrink: 0; }
.location-status.ready { color: var(--green); }
.location-status.failed { color: var(--red); }

.share-button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: linear-gradient(135deg, var(--navy-light) 0%, var(--navy) 100%);
  color: #fff;
  border: none;
  padding: 16px;
  border-radius: var(--radius-md);
  font-size: 1.05rem;
  font-weight: 700;
  min-height: var(--tap-min);
  cursor: pointer;
  box-shadow: 0 8px 18px rgba(18,55,122,0.3);
}
.share-button:disabled { opacity: 0.5; }

.contacts-quickrow {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  margin-top: 14px;
  padding-bottom: 4px;
}
.contact-chip {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  background: var(--card-bg);
  border: 2px solid var(--border);
  border-radius: var(--radius-md);
  padding: 10px 16px;
  text-decoration: none;
  color: var(--text);
  min-width: 92px;
  text-align: center;
}
.contact-chip .chip-name { font-weight: 700; font-size: 0.9rem; }
.contact-chip .chip-call { font-size: 0.78rem; color: var(--green); font-weight: 700; }

.emergency-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 8px;
}
.emergency-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: var(--card-bg);
  border: 2px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px 8px;
  min-height: 118px;
  cursor: pointer;
  color: var(--text);
}
.emergency-card:active { background: #EEF1F6; border-color: var(--navy); }
body.high-contrast .emergency-card:active { background: #1a1a1a; border-color: var(--text); }
.emergency-card .card-icon {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--navy-light) 0%, var(--navy) 100%);
  border: 2px solid transparent;
}
body.high-contrast .emergency-card .card-icon { border-color: #FFE066; }
.emergency-card .card-icon svg { width: 32px; height: 32px; color: #fff; }
.emergency-card span { font-weight: 700; font-size: 1rem; text-align: center; }
.emergency-card.branch-card { grid-column: 1 / -1; }
.emergency-card.branch-card .card-icon { background: linear-gradient(135deg, var(--red-light) 0%, var(--red) 100%); }

.branch-panel {
  grid-column: 1 / -1;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: var(--card-bg);
  border: 2px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px;
}
.branch-hint {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.88rem;
  line-height: 1.4;
}
.branch-question {
  margin: 0;
  color: var(--text);
  font-weight: 800;
  font-size: 1.05rem;
  text-align: center;
}
.branch-option {
  min-height: var(--tap-min);
  padding: 14px;
  border-radius: var(--radius-md);
  border: 2px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-weight: 700;
  font-size: 1rem;
  cursor: pointer;
}
.branch-option:active { background: #EEF1F6; }
.branch-option.urgent {
  background: linear-gradient(135deg, var(--red-light) 0%, var(--red) 100%);
  color: #fff;
  border-color: transparent;
}
body.high-contrast .branch-option.urgent { border-color: #FFE066; }

/* ---------- VISTA GUÍA ---------- */
.guide-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.guide-title {
  font-size: 1.2rem;
  font-weight: 800;
  color: var(--text);
}

.guide-stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 26px;
  text-align: center;
  padding: 10px 0;
}
.guide-icon {
  width: 160px; height: 160px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--navy-light) 0%, var(--navy) 100%);
  box-shadow: 0 12px 28px rgba(18,55,122,0.35);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
}
.guide-icon svg { width: 88px; height: 88px; }
.guide-icon.beat { animation: beat 0.55s ease-in-out infinite; }
@keyframes beat {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.08); }
}

.guide-text {
  font-size: 1.5rem;
  font-weight: 700;
  line-height: 1.35;
  max-width: 28ch;
  margin: 0;
  color: var(--text);
}

.guide-progress {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin: 10px 0;
}
.progress-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--border);
}
.progress-dot.done { background: var(--navy); }
body.high-contrast .progress-dot.done { background: var(--text); }
.progress-dot.current { background: var(--red); width: 14px; height: 14px; }

.guide-nav {
  display: flex;
  align-items: center;
  gap: 10px;
}
.nav-button {
  width: 56px; height: 56px;
  border-radius: 50%;
  border: 2px solid var(--border);
  background: var(--card-bg);
  font-size: 1.4rem;
  color: var(--text);
  cursor: pointer;
  flex-shrink: 0;
}
.nav-button:active { background: #EEF1F6; }
.nav-call-button {
  flex: 1;
  text-align: center;
  background: var(--red);
  color: #fff;
  text-decoration: none;
  font-weight: 800;
  padding: 16px 10px;
  border-radius: var(--radius-md);
  min-height: var(--tap-min);
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ---------- VISTA CONFIGURACIÓN ---------- */
.settings-block {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px;
  margin-bottom: 14px;
}
.settings-block h3 {
  margin: 0 0 10px;
  font-size: 1rem;
  color: var(--text);
}
.field-help { color: var(--text-muted); font-size: 0.88rem; margin: -4px 0 12px; }
.field-label { display: block; font-size: 0.9rem; color: var(--text-muted); margin-bottom: 6px; }

.text-field {
  width: 100%;
  padding: 14px;
  font-size: 1.05rem;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--card-bg);
  color: var(--text);
}
.text-field:focus { outline: 3px solid var(--focus); border-color: var(--focus); }

.contact-row {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}
.contact-row .text-field { flex: 1; }
.contact-row .text-field.phone { flex: 0 0 40%; }
.btn-remove-contact {
  width: 48px; height: 48px;
  flex-shrink: 0;
  border: none;
  border-radius: var(--radius-sm);
  background: #FBEAEA;
  color: var(--red);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.btn-remove-contact svg { width: 20px; height: 20px; }
.btn-add-contact {
  width: 100%;
  padding: 14px;
  border: 2px dashed var(--border);
  background: none;
  border-radius: var(--radius-sm);
  color: var(--text);
  font-weight: 700;
  cursor: pointer;
}

.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 1.05rem;
  gap: 12px;
}
.switch-row input[type="checkbox"] { width: 26px; height: 26px; }

.save-button {
  width: 100%;
  padding: 18px;
  font-size: 1.15rem;
  font-weight: 800;
  color: #fff;
  background: var(--navy);
  border: none;
  border-radius: var(--radius-lg);
  min-height: var(--tap-min);
  cursor: pointer;
  margin-bottom: 6px;
}
.save-button:active { background: var(--navy-dark); }

.legal-text {
  font-size: 0.9rem;
  color: var(--text-muted);
  line-height: 1.5;
  margin: 0;
}

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: var(--navy);
  color: #fff;
  padding: 12px 20px;
  border-radius: 999px;
  font-size: 0.95rem;
  font-weight: 600;
  box-shadow: 0 8px 20px rgba(0,0,0,0.25);
  z-index: 50;
  max-width: 88vw;
  text-align: center;
}

/* ---------- Modo alto contraste / texto grande ---------- */
body.high-contrast {
  --navy: #000000;
  --navy-dark: #000000;
  --bg: #000000;
  --card-bg: #000000;
  --text: #FFFFFF;
  --text-muted: #FFE066;
  --border: #FFFFFF;
  --red: #FF3B30;
  --red-dark: #C81E14;
  --green: #4CD964;
  --focus: #FFE066;
}
body.high-contrast .topbar { background: #000; border-bottom: 3px solid #fff; }
body.high-contrast .icon-btn { background: #1a1a1a; border: 2px solid #fff; }
body.high-contrast .sos-button { border-color: #FFE066; }
body.high-contrast .emergency-card,
body.high-contrast .contact-chip,
body.high-contrast .settings-block,
body.high-contrast .text-field { border-width: 3px; }
body.high-contrast .guide-icon { border: 3px solid #FFE066; }
body.high-contrast .save-button,
body.high-contrast .share-button,
body.high-contrast .call-button,
body.high-contrast .nav-call-button,
body.high-contrast .sos-status,
body.high-contrast .toast,
body.high-contrast .nav-button {
  border: 2px solid #FFE066;
}

body.large-text { font-size: 1.18rem; }
body.large-text .sos-label { font-size: 2rem; }
body.large-text .guide-text { font-size: 1.8rem; }
body.large-text .call-button { font-size: 1.55rem; }
body.large-text .emergency-card span { font-size: 1.12rem; }
body.large-text .home-hint { font-size: 1.2rem; }

/* Pantallas pequeñas: evita que el botón SOS empuje el disclaimer fuera */
@media (max-height: 640px) {
  .home-logo { width: min(42vw, 150px); }
  .sos-button { min-height: 84px; padding: 10px 20px; }
  .sos-icon { width: 44px; height: 44px; }
  .sos-icon::before { width: 20px; height: 7px; top: 18.5px; left: 12px; }
  .sos-icon::after { width: 7px; height: 20px; top: 12px; left: 18.5px; }
  .sos-label { font-size: 1.2rem; }
  .home-wrap { gap: 18px; }
  .guide-icon { width: 120px; height: 120px; }
  .guide-icon svg { width: 64px; height: 64px; }
}

@media (min-width: 560px) {
  .view { max-width: 480px; margin: 0 auto; width: 100%; }
  .topbar > * { max-width: 480px; }
}
