:root {
  color-scheme: light;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: #26322b;
  background: #f6f5f1;
  line-height: 1.5;
}

* { box-sizing: border-box; }

body {
  min-height: 100vh;
  margin: 0;
  background: radial-gradient(circle at 12% 0%, rgba(225, 238, 224, 0.8), transparent 32rem), linear-gradient(180deg, #faf9f6 0%, #f3f4ef 100%);
}

@supports (padding: env(safe-area-inset-top)) {
  body {
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
  }
}

h1, h2, p, dl, dd { margin-top: 0; }

.page-shell {
  width: min(100% - 2.5rem, 88rem);
  margin: 0 auto;
  padding: 2.2rem 0 4rem;
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 2rem;
  margin-bottom: 2rem;
}

.brand { display: flex; align-items: center; gap: 0.9rem; }

.brand-logo {
  display: grid;
  width: 3.25rem;
  height: 3.25rem;
  place-items: center;
  border-radius: 1rem;
  background: #a95969;
  box-shadow: 0 0.5rem 1.2rem rgba(120, 54, 68, 0.2);
  color: #fff;
  font-size: 1.65rem;
}

h1 {
  margin-bottom: 0.1rem;
  font-size: clamp(1.8rem, 5vw, 2.6rem);
  line-height: 1;
  letter-spacing: -0.045em;
}

.tagline { margin-bottom: 0; color: #718076; font-size: 0.95rem; font-weight: 600; }

.last-refresh {
  flex: 0 0 auto;
  margin-bottom: 0;
  padding: 0.5rem 0.8rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.85);
  box-shadow: 0 0.25rem 1rem rgba(51, 66, 56, 0.07);
  color: #52645a;
  font-size: 0.83rem;
  font-weight: 650;
}

.last-refresh::before { content: "●"; margin-right: 0.4rem; color: #5b9a68; }

.notice {
  margin: 0 0 1.25rem;
  padding: 0.85rem 1rem;
  border-radius: 0.8rem;
  background: rgba(255, 255, 255, 0.9);
  color: #55635a;
}

.notice--error { background: #fff1ec; color: #853e2e; }

.people-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-items: start;
  gap: 1.5rem;
}

.person-card {
  overflow: visible;
  border-radius: 1.4rem;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 1rem 3rem rgba(48, 61, 51, 0.09);
}

.person-card--priority-alert {
  outline: 3px solid #c95a42;
  outline-offset: 3px;
  box-shadow: 0 1rem 3rem rgba(151, 55, 38, 0.2);
}

.person-card--priority-alert .person-header::after {
  content: "⚠ Alerta";
  margin-left: auto;
  padding: 0.35rem 0.6rem;
  border-radius: 999px;
  background: #9c3828;
  color: #fff;
  font-size: 0.72rem;
  font-weight: 850;
}

.person-header { display: flex; align-items: center; gap: 0.9rem; padding: 1.4rem 1.4rem 0.9rem; }

.location-indicator-wrap {
  position: relative;
  margin-left: auto;
}

.location-indicator {
  display: grid;
  width: 2.75rem;
  height: 2.75rem;
  padding: 0;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: #f1f4f1;
  color: #7b8580;
  cursor: pointer;
}

.location-indicator:hover { background: #e9eeea; }
.location-indicator:focus-visible { outline: 3px solid #e9b850; outline-offset: 2px; }
.location-indicator-symbol { font-size: 1rem; line-height: 1; }
.location-indicator--active { background: #eaf5ec; color: #4f9660; }
.location-indicator--inactive { background: #fff1dd; color: #a46113; }
.location-indicator--unknown { background: #eff1ef; color: #7c8580; }

.location-popover {
  position: absolute;
  z-index: 1300;
  top: calc(100% + 0.45rem);
  right: 0;
  display: none;
  width: min(19rem, calc(100vw - 2rem));
  padding: 0.8rem 0.9rem;
  border: 1px solid #dce3dc;
  border-radius: 0.75rem;
  background: #fff;
  box-shadow: 0 0.8rem 2rem rgba(37, 50, 41, 0.18);
  color: #536158;
  font-size: 0.78rem;
  line-height: 1.4;
}

.location-popover strong,
.location-popover span { display: block; }
.location-popover strong { margin-bottom: 0.3rem; color: #34453a; font-size: 0.84rem; }
.location-popover span { color: #707a73; }
.location-indicator-wrap:hover .location-popover,
.location-indicator:focus-visible + .location-popover,
.location-indicator-wrap[data-open="true"] .location-popover { display: block; }

.person-avatar {
  display: grid;
  width: 3.5rem;
  height: 3.5rem;
  flex: 0 0 auto;
  place-items: center;
  border: 3px solid #fff;
  border-radius: 50%;
  box-shadow: 0 0.35rem 1rem rgba(48, 61, 51, 0.13);
  font-size: 2rem;
}

.person-avatar--abuela { background: #f8e9ed; }
.person-avatar--abuelo { background: #e6f0f4; }

.person-role, .eyebrow {
  margin: 0 0 0.15rem;
  color: #7a887f;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.09em;
  text-transform: uppercase;
}

.person-header h2 { margin-bottom: 0; font-size: 1.65rem; line-height: 1.1; }
.person-status { padding: 0 1.4rem 0.8rem; }
.person-status p { margin-bottom: 0.3rem; }
.current-place { color: #34483b; font-size: 1.08rem; font-weight: 780; }
.current-place > span:first-child { color: #78947e; font-size: 1.2rem; }
.location-context { color: #78837c; font-size: 0.84rem; font-weight: 650; }
.home-status { color: #456c50; font-size: 1rem; font-weight: 800; }
.home-status::before { content: "●"; margin-right: 0.4rem; color: #59a269; font-size: 0.75rem; }

.external-map-link {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  margin-top: 0.2rem;
  color: #587665;
  font-size: 0.78rem;
  font-weight: 700;
  text-underline-offset: 0.18em;
}
.external-map-link:hover { color: #365843; }
.external-map-link:focus-visible { outline: 3px solid #e9b850; outline-offset: 3px; border-radius: 0.15rem; }

.health-status { margin-top: 0.8rem; padding: 0.75rem 0.85rem; border-radius: 0.75rem; background: #f2f6f4; }
.hospital-name { margin-bottom: 0; color: #40544a; font-weight: 700; }
.hospital-alert { margin-bottom: 0.3rem; padding: 0.45rem 0.55rem; border-radius: 0.5rem; background: #ffe6df; color: #922f1e; font-weight: 850; }
.person-metrics {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.35rem;
  margin-bottom: 0;
  padding: 0 1.4rem 0.8rem;
}

.person-metrics--with-wifi { grid-template-columns: repeat(3, minmax(0, 1fr)); }

.person-metrics > div {
  min-width: 0;
  padding: 0.4rem 0.3rem;
  border-radius: 0.5rem;
  background: rgba(247, 248, 245, 0.55);
  text-align: center;
}
.person-metrics dt { margin-bottom: 0.08rem; color: #89928c; font-size: 0.64rem; font-weight: 600; }
.person-metrics dd { margin-bottom: 0; overflow-wrap: anywhere; color: #59665e; font-size: 0.76rem; font-weight: 650; line-height: 1.25; }

.map-card { overflow: hidden; background: #e8ece5; }
.person-map-card { border-radius: 0 0 1.4rem 1.4rem; }
.history-controls {
  display: flex;
  min-height: 3.2rem;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.55rem;
  padding: 0.65rem 0.8rem;
  background: #f5f7f3;
  color: #526158;
  font-size: 0.78rem;
  font-weight: 700;
  border-top: 1px solid rgba(202, 212, 203, 0.55);
}
.history-controls select,
.history-controls button {
  min-height: 2rem;
  border: 1px solid #cad4cb;
  border-radius: 0.5rem;
  background: #fff;
  color: #35483c;
  font: inherit;
}
.history-controls select { padding: 0.25rem 0.4rem; }
.history-controls button { padding: 0.35rem 0.65rem; cursor: pointer; }
.history-controls button:disabled { cursor: wait; opacity: 0.65; }
.history-status { flex: 1 1 10rem; font-weight: 600; }
.history-status--error { color: #853e2e; }
.map-frame { position: relative; background: #e8ece5; }
.map { width: 100%; height: clamp(20rem, 31vw, 27rem); background: #e8ece5; }

.map-actions {
  position: absolute;
  z-index: 1000;
  top: 0.65rem;
  right: 0.65rem;
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.4rem;
  max-width: calc(100% - 4rem);
  pointer-events: none;
}

.map-actions button {
  padding: 0.45rem 0.65rem;
  border: 0;
  border-radius: 0.45rem;
  background: rgba(255, 255, 255, 0.95);
  box-shadow: 0 2px 8px rgba(35, 45, 37, 0.2);
  color: #33463a;
  font: inherit;
  font-size: 0.75rem;
  font-weight: 750;
  cursor: pointer;
  pointer-events: auto;
}

.map-actions button:hover { background: #fff; }
.map-actions button:focus-visible { outline: 3px solid #e9b850; outline-offset: 2px; }

.map-card--expanded {
  position: relative;
  z-index: 1100;
  left: 50%;
  width: min(calc(100vw - 2rem), 90rem);
  transform: translateX(-50%);
}

.map-card--expanded .map { height: min(74vh, 50rem); }
.map-frame:fullscreen { width: 100vw; height: 100vh; background: #e8ece5; }
.map-frame:fullscreen .map { width: 100%; height: 100%; }
.map-marker-wrapper { background: transparent; border: 0; }

.person-map-marker {
  display: grid;
  width: 2.75rem;
  height: 2.75rem;
  place-items: center;
  border: 3px solid #fff;
  border-radius: 50%;
  box-shadow: 0 4px 12px rgba(31, 42, 34, 0.38);
  font-size: 1.65rem;
  line-height: 1;
}

.person-avatar img,
.person-map-marker img {
  width: 100%;
  height: 100%;
  border-radius: inherit;
  object-fit: cover;
}

.map-marker--abuela { background: #f4dce3; }
.map-marker--abuelo { background: #dbeaf0; }

.joint-view {
  margin-top: 2rem;
  padding: 1.4rem;
  border-radius: 1.4rem;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 1rem 3rem rgba(48, 61, 51, 0.08);
}

.joint-header { display: flex; align-items: center; justify-content: space-between; gap: 1.5rem; margin-bottom: 1rem; }
.joint-header h2 { margin-bottom: 0; font-size: 1.6rem; }
.family-summary { display: flex; align-items: center; gap: 1rem; color: #46564c; }
#summary-label, .summary-distance { margin-bottom: 0; font-weight: 750; }
#summary-label::before { content: "👥"; margin-right: 0.35rem; }
.summary-distance::before { content: "📍"; margin-right: 0.25rem; }
.combined-map-card { border-radius: 1rem; }
.combined-map-card .map { height: clamp(22rem, 45vw, 34rem); }

[hidden] { display: none !important; }

.header-actions { display: flex; align-items: center; gap: 0.75rem; }
.header-actions form { margin: 0; }
.logout-button {
  padding: 0.48rem 0.75rem;
  border: 1px solid #d7ded7;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.8);
  color: #526158;
  font: inherit;
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
}
.logout-button:hover { background: #fff; }

.login-page { min-height: 100vh; background: linear-gradient(145deg, #f4f7f1, #fff8f1); }
.login-shell { display: grid; min-height: 100vh; padding: 1rem; place-items: center; }
.login-card {
  width: min(100%, 25rem);
  padding: 2rem;
  border-radius: 1.5rem;
  background: rgba(255, 255, 255, 0.95);
  box-shadow: 0 1rem 3rem rgba(48, 61, 51, 0.12);
}
.login-brand { display: grid; justify-items: center; margin-bottom: 1.6rem; text-align: center; }
.login-brand .brand-logo { margin-bottom: 0.7rem; }
.login-brand h1 { margin-bottom: 0.15rem; font-size: 1.8rem; }
.login-form { display: grid; gap: 0.55rem; }
.login-form label { margin-top: 0.45rem; color: #48584e; font-weight: 750; }
.login-form input:not([type="hidden"]) {
  width: 100%;
  padding: 0.78rem 0.85rem;
  border: 1px solid #cfd8d0;
  border-radius: 0.7rem;
  background: #fff;
  color: #26362c;
  font: inherit;
}
.login-form input:focus { outline: 3px solid rgba(223, 164, 83, 0.3); border-color: #bf8640; }
.login-form button {
  margin-top: 1rem;
  padding: 0.8rem;
  border: 0;
  border-radius: 0.7rem;
  background: #4f765c;
  color: #fff;
  font: inherit;
  font-weight: 800;
  cursor: pointer;
}
.login-form button:hover { background: #3f664d; }
.login-error { padding: 0.75rem; border-radius: 0.65rem; background: #fff0ea; color: #873d2e; text-align: center; }

@media (max-width: 44rem) {
  .page-shell { width: min(100% - 1rem, 88rem); padding-top: 1.1rem; }
  .page-header { align-items: flex-start; flex-direction: column; gap: 1rem; margin-bottom: 1.4rem; }
  .header-actions { width: 100%; justify-content: space-between; }
  .last-refresh { align-self: flex-start; }
  .people-grid { grid-template-columns: 1fr; }
  .person-header, .person-status, .person-metrics { padding-right: 1rem; padding-left: 1rem; }
  .map, .combined-map-card .map { height: 22rem; }
  .map-card--expanded { width: calc(100vw - 0.5rem); }
  .map-card--expanded .map { height: min(78vh, 42rem); }
  .map-actions { top: 0.5rem; right: 0.5rem; max-width: calc(100% - 3.5rem); }
  .joint-view { padding: 1rem; }
  .joint-header, .family-summary { align-items: flex-start; flex-direction: column; gap: 0.35rem; }
}

@media (max-width: 24rem) {
  .brand-logo { width: 2.8rem; height: 2.8rem; }
  .person-metrics { gap: 0.2rem; }
  .person-metrics > div { padding-inline: 0.15rem; }
  .person-metrics dt { font-size: 0.59rem; }
  .person-metrics dd { font-size: 0.7rem; }
  .location-popover { width: min(17rem, calc(100vw - 1.5rem)); }
}
