/* ======================== CSS VARIABLES ======================== */
:root {
  /* Base palette — light & airy */
  --bg-base:       #F4F6FA;
  --bg-white:      #FFFFFF;
  --bg-elevated:   #FFFFFF;
  --bg-hover:      #EEF0F4;
  --border-subtle: rgba(0, 0, 0, 0.06);
  --border-medium: rgba(0, 0, 0, 0.10);

  /* Brand gradient */
  --brand-cyan:    #00BCD4;
  --brand-teal:    #3AB78D;
  --brand-gradient: linear-gradient(135deg, #06b7ff 0%, #32f7ff 100%);

  /* Primary */
  --primary:       #3AB78D;
  --primary-light: rgba(58, 183, 141, 0.10);

  /* Text */
  --text-primary:   #1A1A2E;
  --text-secondary: #5F6B7A;
  --text-tertiary:  #9CA3AF;
  --text-on-brand:  #FFFFFF;

  /* Accent / Nav */
  --amber-800:     #FFB74D;
  --grey:          #5F6B7A;

  /* Shadows */
  --shadow-sm:     0 1px 3px rgba(0, 0, 0, 0.05);
  --shadow-card:   0 1px 4px rgba(0, 0, 0, 0.06), 0 0 0 1px rgba(0, 0, 0, 0.02);
  --shadow-md:     0 4px 20px rgba(0, 0, 0, 0.08);
  --shadow-lg:     0 8px 30px rgba(0, 0, 0, 0.10);
  --card-radius:   14px;
  --card-shadow:   var(--shadow-card);

  /* Font */
  --font-family: 'Nexa', Arial, sans-serif;

  /* Nav */
  --selected-nav-bg: rgba(0, 188, 212, 0.10);

  /* Severity */
  --severity-high-bg:   rgba(239, 68, 68, 0.08);
  --severity-medium-bg: rgba(245, 158, 11, 0.08);
  --severity-low-bg:    rgba(34, 197, 94, 0.08);
  --risk-high:    #EF4444;
  --risk-medium:  #F59E0B;
  --risk-low:     #22C55E;

  /* Summary card colors */
  --card-key-deviations: rgba(59, 130, 246, 0.10);
  --card-dietary:        rgba(234, 179, 8, 0.10);
  --card-supplements:    rgba(239, 68, 68, 0.10);
  --card-exercise:       rgba(249, 115, 22, 0.10);
  --card-followup:       rgba(34, 197, 94, 0.10);
  --card-medical:        rgba(168, 85, 247, 0.10);
}

/* ======================== FONTS ======================== */
@font-face {
  font-family: 'Nexa';
  src: url('/assets/font/Nexa-Regular.ttf') format('truetype');
  font-weight: normal;
  font-style: normal;
}
@font-face {
  font-family: 'Nexa';
  src: url('/assets/font/Nexa-Bold.ttf') format('truetype');
  font-weight: 700;
  font-style: normal;
}

/* ======================== RESET & BASE ======================== */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  height: 100%;
  font-family: var(--font-family);
  background: var(--bg-base);
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a {
  text-decoration: none;
  color: inherit;
}

/* ======================== LAYOUT ======================== */
.page-wrapper {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  max-width: none;
  margin: 0 auto;
  background: var(--bg-base);
}

.app-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  background: var(--bg-white);
  border-bottom: 2px solid transparent;
  border-image: var(--brand-gradient) 1;
  position: sticky;
  top: 0;
  z-index: 50;
}

.app-bar-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.app-bar-back {
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 22px;
  color: var(--text-primary);
  background: none;
  border: none;
  padding: 4px 8px;
  min-width: 44px;
  min-height: 44px;
}

.app-bar-title {
  font-size: 20px;
  font-weight: bold;
  color: var(--text-primary);
}

.app-bar-icon {
  height: 28px;
}

.app-bar-logo {
  height: 28px;
  width: auto;
}

/* Sidebar-only elements — hidden on mobile */
.sidebar-header,
.sidebar-spacer,
.sidebar-logout {
  display: none;
}

.logout-btn {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  padding: 6px 14px;
  border: 1px solid var(--border-medium);
  border-radius: 8px;
  cursor: pointer;
  background: transparent;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.logout-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
  border-color: var(--brand-teal);
}

.patient-selector {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 20px;
  padding: 12px 16px;
  background: var(--bg-white);
  border-radius: var(--card-radius);
  box-shadow: var(--card-shadow);
}

.patient-selector label {
  font-weight: 600;
  font-size: 14px;
  color: var(--text-secondary);
  white-space: nowrap;
}

.patient-selector select {
  flex: 1;
  font-family: var(--font-family);
  font-size: 14px;
  padding: 6px 10px;
  border: 1px solid var(--border-medium);
  border-radius: 8px;
  background: var(--bg-base);
  color: var(--text-primary);
  cursor: pointer;
}

.page-content {
  flex: 1;
  padding: 20px 16px;
  padding-bottom: 100px;
  overflow-y: auto;
}

/* ======================== HERO BANNER ======================== */
.hero-banner {
  background: var(--brand-gradient);
  border-radius: 18px;
  padding: 28px 24px;
  margin-bottom: 20px;
  color: white;
}

.hero-title {
  font-size: 26px;
  font-weight: 700;
  margin-bottom: 4px;
}

.hero-subtitle {
  font-size: 14px;
  opacity: 0.85;
}

/* ======================== AGE STAT CARDS ======================== */
.age-stats-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
  margin-bottom: 28px;
}

.age-stat-card {
  background: var(--bg-white);
  border-radius: var(--card-radius);
  padding: 16px;
  box-shadow: var(--card-shadow);
}

.age-stat-value {
  font-size: 32px;
  font-weight: 700;
  line-height: 1;
  margin-bottom: 4px;
}

.age-stat-label {
  font-size: 12px;
  color: var(--text-secondary);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 10px;
}

.age-stat-bar {
  height: 5px;
  background: var(--bg-base);
  border-radius: 3px;
  overflow: hidden;
}

.age-stat-bar-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.6s ease;
}

/* ======================== SECTION HEADING ======================== */
.section-heading {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 14px;
}

/* ======================== SUMMARY GRID ======================== */
.summary-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.summary-card {
  background: var(--bg-white);
  border-radius: var(--card-radius);
  padding: 18px 14px;
  box-shadow: var(--card-shadow);
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 10px;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
  position: relative;
  border-left: 3px solid var(--card-accent, var(--brand-teal));
  min-height: 120px;
}

.summary-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.summary-card-icon-wrap {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.summary-card-icon {
  width: 26px;
  height: 26px;
  object-fit: contain;
}

.summary-card-label {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1.3;
}

.summary-card-arrow {
  position: absolute;
  top: 16px;
  right: 14px;
  font-size: 20px;
  color: var(--text-tertiary);
  font-weight: 300;
}

/* ======================== BOTTOM NAV ======================== */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  max-width: none;
  margin: 0 auto;
  display: flex;
  justify-content: space-around;
  align-items: center;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid var(--border-subtle);
  padding: 6px 0 max(6px, env(safe-area-inset-bottom));
  z-index: 100;
}

.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  text-decoration: none;
  color: var(--text-tertiary);
  font-size: 11px;
  font-weight: 500;
  padding: 6px 14px;
  transition: color 0.2s;
  min-width: 60px;
  min-height: 48px;
  justify-content: center;
}

.nav-item.active {
  color: var(--brand-teal);
}

.nav-icon {
  width: 24px;
  height: 24px;
  object-fit: contain;
}

.nav-icon-tinted {
  width: 24px;
  height: 24px;
  -webkit-mask-size: contain;
  mask-size: contain;
  -webkit-mask-repeat: no-repeat;
  mask-repeat: no-repeat;
  -webkit-mask-position: center;
  mask-position: center;
}

.nav-item .material-info-icon {
  font-size: 24px;
  line-height: 24px;
}

.nav-item .nav-icon {
  -webkit-mask-size: contain;
  mask-size: contain;
  -webkit-mask-repeat: no-repeat;
  mask-repeat: no-repeat;
  -webkit-mask-position: center;
  mask-position: center;
}

/* ======================== TITLE TEXT ======================== */
.title-text {
  font-size: 20px;
  font-weight: bold;
  margin-bottom: 12px;
  color: var(--text-primary);
}

.title-text.no-margin {
  margin-bottom: 0;
}

/* ======================== LOADING ======================== */
.loading-spinner {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 200px;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 4px solid var(--border-subtle);
  border-top-color: var(--brand-teal);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ======================== UTILITY ======================== */
.spacer { flex: 1; }
.text-grey { color: var(--text-secondary); }
.text-red { color: var(--risk-high); }
.text-bold { font-weight: bold; }
.text-center { text-align: center; }

.mb-10 { margin-bottom: 10px; }
.mb-20 { margin-bottom: 20px; }
.mb-25 { margin-bottom: 25px; }
.mb-50 { margin-bottom: 50px; }
.mt-20 { margin-top: 20px; }
.p-16 { padding: 16px; }

.flex-row { display: flex; flex-direction: row; align-items: center; }
.flex-col { display: flex; flex-direction: column; }
.gap-10 { gap: 10px; }
.gap-20 { gap: 20px; }

/* ======================== SMALL MOBILE ======================== */
@media (max-width: 480px) {
  .page-content {
    padding: 16px 12px;
    padding-bottom: 100px;
  }

  .app-bar-title { font-size: 18px; }

  .summary-card {
    padding: 14px 12px;
    min-height: 110px;
  }
}

@media (max-width: 360px) {
  .summary-grid {
    grid-template-columns: 1fr;
  }

  .age-stats-row {
    grid-template-columns: 1fr;
  }
}

/* ======================== TABLET (641px - 960px) ======================== */
@media (min-width: 641px) {
  .page-content {
    padding: 28px 32px;
    padding-bottom: 100px;
  }

  .app-bar {
    padding: 16px 32px;
  }

  .hero-banner {
    padding: 36px 32px;
  }

  .hero-title {
    font-size: 30px;
  }

  .summary-grid {
    grid-template-columns: 1fr 1fr 1fr;
    gap: 16px;
  }

  .section-heading {
    font-size: 20px;
    margin-bottom: 16px;
  }

  .nav-item {
    padding: 8px 20px;
    font-size: 12px;
  }
}

/* ======================== DESKTOP (961px+) ======================== */
@media (min-width: 961px) {
  /* Grid layout: sidebar | content (no app-bar row) */
  .page-wrapper {
    display: grid;
    grid-template-columns: 220px 1fr;
    grid-template-rows: 1fr;
    max-width: none;
    min-height: 100vh;
    background: var(--bg-base);
  }

  /* Hide the app-bar on desktop — logo/logout live in sidebar */
  .app-bar {
    display: none;
  }

  /* ── Sidebar nav (was bottom-nav) ── */
  .bottom-nav {
    position: sticky;
    top: 0;
    bottom: auto;
    left: auto;
    right: auto;
    height: 100vh;
    height: 100dvh;
    width: 220px;
    max-width: none;
    flex-direction: column;
    justify-content: flex-start;
    align-items: stretch;
    padding: 12px 12px;
    gap: 4px;
    background: #ffffff;
    border-top: none;
    border-right: 1px solid var(--border-subtle);
    backdrop-filter: none;
    z-index: 50;
    grid-column: 1;
    grid-row: 1 / -1; /* span all rows */
    overflow-y: auto;
  }

  /* ── Sidebar header (logo + brand) ── */
  .sidebar-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px 16px;
    margin-bottom: 8px;
    border-bottom: 1px solid var(--border-subtle);
  }

  .sidebar-logo {
    height: 26px;
    width: auto;
  }

  .sidebar-brand {
    font-size: 18px;
    font-weight: 700;
    letter-spacing: 4px;
    background: linear-gradient(135deg, #32f7ff, #06b7ff);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
  }

  /* ── Sidebar spacer + logout ── */
  .sidebar-spacer {
    display: block;
    flex: 1;
  }

  .sidebar-logout {
    display: flex;
    margin-top: 4px;
    border-top: 1px solid var(--border-subtle);
    padding-top: 12px;
    color: var(--text-tertiary);
  }

  .sidebar-logout:hover {
    color: var(--risk-high);
    background: rgba(239, 68, 68, 0.06);
  }

  .nav-item {
    flex-direction: row;
    justify-content: flex-start;
    padding: 12px 16px;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 500;
    gap: 12px;
    min-width: auto;
    min-height: auto;
    transition: background 0.15s, color 0.15s;
  }

  .nav-item:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
  }

  .nav-item.active {
    background: var(--selected-nav-bg);
    color: var(--brand-teal);
    font-weight: 600;
  }

  .nav-icon, .nav-icon-tinted {
    width: 22px;
    height: 22px;
    flex-shrink: 0;
  }

  /* ── Main content area ── */
  .page-content {
    grid-column: 2;
    grid-row: 1;
    padding: 32px 48px;
    padding-bottom: 48px;
    overflow-y: auto;
    min-width: 0;
  }

  .hero-banner {
    padding: 40px 40px;
    border-radius: 20px;
  }

  .hero-title {
    font-size: 34px;
  }

  .hero-subtitle {
    font-size: 16px;
  }

  .summary-grid {
    grid-template-columns: 1fr 1fr 1fr;
    gap: 20px;
  }

  .summary-card {
    padding: 22px 18px;
    min-height: 140px;
  }

  .summary-card-label {
    font-size: 15px;
  }

  .age-stat-value {
    font-size: 36px;
  }

  .section-heading {
    font-size: 22px;
    margin-bottom: 18px;
  }

  .modal-content {
    max-width: 600px;
    min-width: 400px;
  }
}

/* ── Mobile-only: safe area for bottom nav ── */
@media (max-width: 960px) {
  @supports (padding-bottom: env(safe-area-inset-bottom)) {
    .bottom-nav {
      padding-bottom: max(6px, env(safe-area-inset-bottom));
    }
    .page-content {
      padding-bottom: calc(100px + env(safe-area-inset-bottom));
    }
  }
}

.horizontal-scroll {
  -webkit-overflow-scrolling: touch;
  scroll-snap-type: x proximity;
}

.scroll-item {
  scroll-snap-align: start;
}
