/* ── Reset & Base ─────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --blue:        #1A73E8;
  --blue-dark:   #1557B0;
  --blue-light:  #EBF3FE;
  --green:       #34C759;
  --red:         #FF3B30;
  --yellow:      #FF9500;
  --bg:          #F2F4F7;
  --card:        #FFFFFF;
  --text:        #1C1C1E;
  --text-sub:    #6E6E73;
  --border:      #E5E5EA;
  --nav-height:  64px;
  --header-height: 56px;
  --radius:      16px;
  --radius-sm:   10px;
  --shadow:      0 2px 12px rgba(0,0,0,0.08);
  --shadow-lg:   0 8px 32px rgba(0,0,0,0.12);
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

/* ── App Shell ────────────────────────────────────────── */
#app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 430px;
  margin: 0 auto;
  position: relative;
  overflow: hidden;
  background: var(--bg);
  box-shadow: var(--shadow-lg);
}

/* ── Header ───────────────────────────────────────────── */
#header {
  height: var(--header-height);
  background: var(--card);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 10px;
  z-index: 100;
  flex-shrink: 0;
}

#dog-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--blue-light);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
  overflow: hidden;
}

#dog-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

#dog-selector {
  display: flex;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  user-select: none;
}

#dog-selector-name {
  font-size: 17px;
  font-weight: 600;
  color: var(--text);
}

#dog-selector-chevron {
  color: var(--text-sub);
  font-size: 12px;
  transition: transform 0.2s;
}

#dog-selector-chevron.open { transform: rotate(180deg); }

.header-spacer { flex: 1; }

.header-status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-sub);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--green);
}

.status-dot.offline { background: var(--text-sub); }

.battery-icon {
  color: var(--text-sub);
  flex-shrink: 0;
}

.battery-pct {
  font-size: 13px;
  color: var(--text-sub);
  font-weight: 500;
}

/* ── Dog Dropdown ─────────────────────────────────────── */
#dog-dropdown {
  position: absolute;
  top: var(--header-height);
  left: 0;
  right: 0;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  z-index: 200;
  display: none;
  box-shadow: var(--shadow);
}

#dog-dropdown.open { display: block; }

.dog-option {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background 0.15s;
}

.dog-option:last-child { border-bottom: none; }
.dog-option:hover { background: var(--blue-light); }
.dog-option.active { background: var(--blue-light); }

.dog-option-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--blue-light);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  flex-shrink: 0;
  overflow: hidden;
}

.dog-option-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.dog-option-info { flex: 1; }
.dog-option-name { font-size: 15px; font-weight: 600; }
.dog-option-sub  { font-size: 13px; color: var(--text-sub); margin-top: 1px; }

.dog-option-check { color: var(--blue); font-size: 18px; }

/* ── Page Container ───────────────────────────────────── */
#pages {
  flex: 1;
  overflow: hidden;
  position: relative;
}

.page {
  position: absolute;
  inset: 0;
  overflow-y: auto;
  display: none;
  -webkit-overflow-scrolling: touch;
}

.page.active { display: block; }

/* ── Bottom Nav ───────────────────────────────────────── */
#nav {
  height: var(--nav-height);
  background: var(--card);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  z-index: 100;
  flex-shrink: 0;
}

.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  cursor: pointer;
  padding: 8px 0;
  color: var(--text-sub);
  transition: color 0.15s;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.nav-item.active { color: var(--blue); }

.nav-icon {
  font-size: 22px;
  line-height: 1;
}

.nav-label {
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.2px;
}

/* ── Cards ────────────────────────────────────────────── */
.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}

.card + .card { margin-top: 12px; }

.card-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-sub);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 12px;
}

/* ── Stat Row ─────────────────────────────────────────── */
.stat-row {
  display: flex;
  gap: 0;
  background: var(--card);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}

.stat-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 14px 8px;
  gap: 4px;
  border-right: 1px solid var(--border);
}

.stat-item:last-child { border-right: none; }

.stat-value {
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
  line-height: 1;
}

.stat-unit {
  font-size: 11px;
  color: var(--text-sub);
}

.stat-icon {
  font-size: 18px;
  margin-bottom: 2px;
}

/* ── Button ───────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 14px 28px;
  border-radius: 100px;
  font-size: 16px;
  font-weight: 700;
  border: none;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.1s;
  -webkit-tap-highlight-color: transparent;
}

.btn:active { transform: scale(0.97); opacity: 0.9; }

.btn-primary { background: var(--blue); color: #fff; }
.btn-danger  { background: var(--red);  color: #fff; }
.btn-outline {
  background: transparent;
  border: 1.5px solid var(--blue);
  color: var(--blue);
}

/* ── Map Page ─────────────────────────────────────────── */
#page-map {
  display: none;
  flex-direction: column;
}

#page-map.active { display: flex; }

#map-container {
  flex: 1;
  position: relative;
  min-height: 0;
}

#mapbox-main {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
}

.map-fab-group {
  position: absolute;
  right: 12px;
  bottom: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.map-fab {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--card);
  border: none;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  cursor: pointer;
  transition: box-shadow 0.15s;
}

.map-fab:hover { box-shadow: var(--shadow-lg); }

#map-bottom {
  background: var(--card);
  padding: 14px 16px 16px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

#map-stats {
  display: flex;
  align-items: center;
  gap: 0;
  margin-bottom: 14px;
}

.map-stat {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.map-stat-value {
  font-size: 22px;
  font-weight: 700;
  line-height: 1;
}

.map-stat-unit {
  font-size: 12px;
  color: var(--text-sub);
  margin-top: 2px;
}

.map-stat-icon {
  color: var(--text-sub);
  margin-bottom: 2px;
  flex-shrink: 0;
}

.map-stat-divider {
  width: 1px;
  height: 36px;
  background: var(--border);
}

#live-btn {
  width: 100%;
}

#live-btn.tracking {
  background: var(--red);
}

/* ── History Page ─────────────────────────────────────── */
#page-history {
  display: none;
  flex-direction: column;
}

#page-history.active { display: flex; }

#history-map-container {
  flex: 1;
  position: relative;
  min-height: 0;
}

#history-map {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
}

#history-bottom {
  background: var(--card);
  padding: 16px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.history-badge {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--card);
  border-radius: 100px;
  padding: 6px 16px;
  font-size: 13px;
  font-weight: 600;
  box-shadow: var(--shadow);
  white-space: nowrap;
}

.walks-btn {
  position: absolute;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--card);
  border-radius: 100px;
  padding: 10px 20px;
  font-size: 14px;
  font-weight: 600;
  box-shadow: var(--shadow);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
}

.date-range {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 12px;
}

.date-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.date-label {
  font-size: 11px;
  color: var(--text-sub);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

.date-input {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
}

.date-input input[type="datetime-local"] {
  border: none;
  background: transparent;
  font-size: 13px;
  font-family: inherit;
  color: var(--text);
  width: 100%;
  cursor: pointer;
  outline: none;
}

/* ── Week Bar (History/Health) ────────────────────────── */
.week-bar {
  display: flex;
  gap: 4px;
  align-items: center;
  padding: 12px 16px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  scrollbar-width: none;
}

.week-bar::-webkit-scrollbar { display: none; }

.week-day {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  flex: 1;
  min-width: 36px;
  cursor: pointer;
}

.week-day-num {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-sub);
  transition: background 0.15s, color 0.15s;
}

.week-day-num.active {
  background: var(--blue);
  color: #fff;
}

.week-day-label {
  font-size: 11px;
  color: var(--text-sub);
  font-weight: 500;
}

/* ── Health Page ──────────────────────────────────────── */
.page-content {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.ring-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 20px 16px;
}

.ring-wrap {
  position: relative;
  width: 140px;
  height: 140px;
  margin-bottom: 12px;
}

.ring-svg {
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
}

.ring-bg {
  fill: none;
  stroke: var(--blue-light);
  stroke-width: 10;
}

.ring-progress {
  fill: none;
  stroke: var(--blue);
  stroke-width: 10;
  stroke-linecap: round;
  transition: stroke-dashoffset 1s ease;
}

.ring-avatar {
  position: absolute;
  inset: 14px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--blue-light);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 36px;
  overflow: hidden;
}

.ring-avatar img { width: 100%; height: 100%; object-fit: cover; }

.ring-badge {
  position: absolute;
  bottom: 4px;
  right: 4px;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--blue);
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid #fff;
}

.ring-value {
  font-size: 28px;
  font-weight: 700;
}

.ring-goal {
  font-size: 18px;
  color: var(--text-sub);
  font-weight: 400;
}

.ring-label {
  font-size: 14px;
  color: var(--text-sub);
  margin-top: 2px;
}

/* Bar chart */
.bar-chart {
  display: flex;
  align-items: flex-end;
  gap: 4px;
  height: 80px;
  padding: 8px 0 0;
}

.bar-chart-labels {
  display: flex;
  justify-content: space-between;
  padding: 4px 0 0;
}

.bar-chart-label {
  font-size: 11px;
  color: var(--text-sub);
}

.bar {
  flex: 1;
  background: var(--blue);
  border-radius: 3px 3px 0 0;
  min-height: 4px;
  opacity: 0.85;
  transition: height 0.5s ease;
}

.bar.dim { opacity: 0.3; }

/* Health insight rows */
.insight-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.insight-item {
  background: var(--bg);
  border-radius: var(--radius-sm);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  cursor: pointer;
  transition: background 0.15s;
}

.insight-item:hover { background: var(--blue-light); }

.insight-label { font-size: 12px; color: var(--text-sub); font-weight: 500; }
.insight-value { font-size: 14px; font-weight: 600; }
.insight-icon  { font-size: 24px; }
.insight-arrow { font-size: 12px; color: var(--text-sub); align-self: flex-end; }

/* Stats pair */
.stats-pair {
  display: flex;
  gap: 10px;
}

.stats-pair .stat-card {
  flex: 1;
  background: var(--bg);
  border-radius: var(--radius-sm);
  padding: 14px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.stat-card-icon { font-size: 22px; }

.stat-card-text {}
.stat-card-label { font-size: 12px; color: var(--text-sub); }
.stat-card-value { font-size: 15px; font-weight: 700; }

/* ── Profile Page ─────────────────────────────────────── */
.profile-hero {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 28px 16px 20px;
  gap: 10px;
}

.profile-avatar {
  width: 88px;
  height: 88px;
  border-radius: 50%;
  background: var(--blue-light);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 48px;
  overflow: hidden;
  border: 3px solid var(--blue);
}

.profile-avatar img { width: 100%; height: 100%; object-fit: cover; }

.profile-name {
  font-size: 22px;
  font-weight: 700;
}

.profile-breed {
  font-size: 14px;
  color: var(--text-sub);
}

.profile-row {
  display: flex;
  align-items: center;
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
  gap: 12px;
}

.profile-row:last-child { border-bottom: none; }

.profile-row-icon { font-size: 20px; width: 28px; text-align: center; }
.profile-row-label { font-size: 14px; color: var(--text-sub); flex: 1; }
.profile-row-value { font-size: 14px; font-weight: 500; }

/* ── Loading / Error ──────────────────────────────────── */
.loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  gap: 14px;
  color: var(--text-sub);
}

.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.error-msg {
  background: #FFF2F1;
  border: 1px solid #FFCDD2;
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  font-size: 14px;
  color: var(--red);
  margin: 16px;
}

/* ── Toast ────────────────────────────────────────────── */
#toast {
  position: absolute;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: #1C1C1E;
  color: #fff;
  padding: 10px 20px;
  border-radius: 100px;
  font-size: 14px;
  font-weight: 500;
  opacity: 0;
  transition: opacity 0.3s, transform 0.3s;
  pointer-events: none;
  white-space: nowrap;
  z-index: 999;
}

#toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ── Mapbox overrides ─────────────────────────────────── */
.mapboxgl-ctrl-logo { display: none !important; }
.mapboxgl-ctrl-attrib { display: none !important; }

.dog-marker {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: 3px solid var(--blue);
  background: var(--card);
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(0,0,0,0.25);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
}

.dog-marker img { width: 100%; height: 100%; object-fit: cover; }

.you-marker {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--blue);
  border: 3px solid #fff;
  box-shadow: 0 0 0 3px rgba(26,115,232,0.3);
}

/* ── Alert Badge ──────────────────────────────────────── */
.alert-badge {
  position: absolute;
  top: -4px;
  right: -6px;
  min-width: 16px;
  height: 16px;
  border-radius: 8px;
  background: var(--red);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
  line-height: 1;
}

/* ── Alerts Page ──────────────────────────────────────── */
.alerts-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 0 8px;
}

.alerts-title {
  font-size: 20px;
  font-weight: 700;
}

.alerts-dismiss-all {
  font-size: 13px;
  color: var(--blue);
  font-weight: 600;
  cursor: pointer;
  padding: 4px 8px;
  border: none;
  background: none;
}

.alert-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  margin-bottom: 10px;
  display: flex;
  gap: 12px;
  position: relative;
  transition: opacity 0.3s, transform 0.3s;
}

.alert-card.dismissing {
  opacity: 0;
  transform: translateX(100px);
}

.alert-icon-wrap {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.alert-icon-wrap svg {
  width: 22px;
  height: 22px;
}

.alert-icon-wrap.critical {
  background: #FFEBEE;
  color: var(--red);
}

.alert-icon-wrap.warning {
  background: #FFF3E0;
  color: var(--yellow);
}

.alert-icon-wrap.info {
  background: var(--blue-light);
  color: var(--blue);
}

.alert-body {
  flex: 1;
  min-width: 0;
}

.alert-title {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 4px;
}

.alert-message {
  font-size: 13px;
  color: var(--text-sub);
  line-height: 1.4;
}

.alert-time {
  font-size: 11px;
  color: var(--text-sub);
  margin-top: 8px;
}

.alert-dismiss {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: none;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
  color: var(--text-sub);
  transition: background 0.15s;
}

.alert-dismiss:hover {
  background: var(--border);
}

.alert-dismiss svg {
  width: 14px;
  height: 14px;
}

.alert-type-tag {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 100px;
  margin-top: 8px;
}

.alert-type-tag.activity_drop {
  background: #FFF3E0;
  color: #E65100;
}

.alert-type-tag.sleep_change {
  background: #E8EAF6;
  color: #283593;
}

.alert-type-tag.location_anomaly {
  background: #FFEBEE;
  color: #C62828;
}

.alerts-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  text-align: center;
  gap: 12px;
  color: var(--text-sub);
}

.alerts-empty svg {
  width: 48px;
  height: 48px;
  color: var(--border);
}

.alerts-empty-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
}

.alerts-empty-sub {
  font-size: 14px;
  color: var(--text-sub);
}
