/* ============================================================
   MEDTRACKER — Global Styles
   Palette: Navy #0D1B4B · Royal Blue #4169E1 · Baby Pink #F4C2C2
   ============================================================ */

:root {
  --navy:        #0D1B4B;
  --navy-dark:   #060D2B;
  --navy-mid:    #1B3A6B;
  --royal:       #4169E1;
  --royal-light: #5B85FF;
  --royal-pale:  #EEF2FF;
  --pink:        #F4C2C2;
  --pink-light:  #FBE8E8;
  --pink-dark:   #D98A8A;
  --white:       #FFFFFF;
  --bg:          #F0F4FF;
  --card-bg:     #FFFFFF;
  --gray-100:    #F5F7FF;
  --gray-200:    #E8EDF8;
  --gray-400:    #A0AECB;
  --gray-600:    #5A6A8A;
  --success:     #22C55E;
  --success-bg:  #DCFCE7;
  --warning:     #F59E0B;
  --danger:      #EF4444;
  --danger-bg:   #FEE2E2;
  --text-primary:#0D1B4B;
  --text-muted:  #7A8BAD;
  --shadow-sm:   0 1px 4px rgba(13,27,75,0.08);
  --shadow-md:   0 4px 16px rgba(13,27,75,0.12);
  --shadow-lg:   0 8px 32px rgba(13,27,75,0.18);
  --radius:      14px;
  --radius-sm:   8px;
  --radius-lg:   20px;
  --nav-h:       70px;
  --header-h:    60px;
}

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

html { font-size: 16px; -webkit-tap-highlight-color: transparent; }

body {
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text-primary);
  min-height: 100vh;
  max-width: 480px;
  margin: 0 auto;
  position: relative;
  overflow-x: hidden;
}

/* ---- Utilities ---- */
.hidden { display: none !important; }
.full-width { width: 100%; }

/* ---- Overlay & Modals ---- */
.overlay {
  position: fixed; inset: 0; z-index: 1000;
  background: rgba(6, 13, 43, 0.75);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  backdrop-filter: blur(4px);
}

.modal-card {
  background: var(--white);
  border-radius: var(--radius-lg);
  padding: 32px 24px;
  width: 100%; max-width: 420px;
  box-shadow: var(--shadow-lg);
  animation: slideUp 0.3s ease;
}

.setup-card {
  text-align: center;
}

.setup-icon {
  font-size: 48px;
  margin-bottom: 12px;
  display: block;
}

.setup-card h1 {
  font-size: 28px; font-weight: 800;
  color: var(--navy); letter-spacing: -0.5px;
}

.setup-sub {
  color: var(--text-muted);
  margin: 6px 0 24px;
  font-size: 14px;
}

.med-modal-card {
  max-height: 90vh;
  overflow-y: auto;
}

.modal-top {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 20px;
}

.modal-top h2 { font-size: 18px; font-weight: 700; color: var(--navy); }

.close-btn {
  background: var(--gray-100);
  border: none; cursor: pointer;
  border-radius: 50%;
  width: 30px; height: 30px;
  font-size: 14px; color: var(--gray-600);
  display: flex; align-items: center; justify-content: center;
}

.modal-actions {
  display: flex; flex-direction: column; gap: 10px;
  margin-top: 24px;
}

/* ---- Role Selector ---- */
.role-selector {
  display: flex; gap: 10px;
}

.role-btn {
  flex: 1;
  padding: 10px 8px;
  border: 2px solid var(--gray-200);
  background: var(--white);
  border-radius: var(--radius-sm);
  font-size: 14px; font-weight: 500;
  color: var(--gray-600);
  cursor: pointer;
  transition: all 0.2s;
}

.role-btn.active {
  border-color: var(--royal);
  background: var(--royal-pale);
  color: var(--royal);
}

/* ---- Header ---- */
.app-header {
  position: fixed; top: 0; left: 50%; transform: translateX(-50%);
  width: 100%; max-width: 480px;
  height: var(--header-h);
  background: linear-gradient(135deg, var(--navy-dark) 0%, var(--navy-mid) 100%);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 16px;
  z-index: 100;
  box-shadow: var(--shadow-md);
}

.header-brand {
  display: flex; align-items: center; gap: 8px;
}

.brand-icon { font-size: 22px; }

.brand-name {
  font-size: 18px; font-weight: 700;
  color: var(--white);
  letter-spacing: -0.3px;
}

.header-actions {
  display: flex; align-items: center; gap: 10px;
}

.greeting-chip {
  background: rgba(255,255,255,0.15);
  color: var(--pink);
  font-size: 12px; font-weight: 500;
  padding: 4px 10px;
  border-radius: 20px;
  max-width: 120px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.icon-btn {
  position: relative;
  background: rgba(255,255,255,0.12);
  border: none; cursor: pointer;
  border-radius: 50%;
  width: 36px; height: 36px;
  display: flex; align-items: center; justify-content: center;
  color: var(--white);
  transition: background 0.2s;
}
.icon-btn:hover { background: rgba(255,255,255,0.2); }

/* ---- Bottom Nav ---- */
.bottom-nav {
  position: fixed; bottom: 0; left: 50%; transform: translateX(-50%);
  width: 100%; max-width: 480px;
  height: var(--nav-h);
  background: var(--white);
  display: flex; align-items: center;
  border-top: 1px solid var(--gray-200);
  z-index: 100;
  box-shadow: 0 -4px 16px rgba(13,27,75,0.1);
}

.nav-btn {
  flex: 1;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 4px;
  background: none; border: none; cursor: pointer;
  color: var(--gray-400);
  font-size: 11px; font-weight: 500;
  padding: 8px 4px;
  transition: color 0.2s;
  position: relative;
}

.nav-btn.active { color: var(--royal); }
.nav-btn.active svg { stroke: var(--royal); }

.nav-btn span:first-of-type { font-size: 11px; }

/* ---- Tab Content ---- */
.tab-content {
  display: none;
  margin-top: var(--header-h);
  margin-bottom: var(--nav-h);
  padding: 16px;
  min-height: calc(100vh - var(--header-h) - var(--nav-h));
}

.tab-content.active {
  display: block;
}

#tab-chat.active {
  display: flex;
  flex-direction: column;
}

/* ---- Today Tab ---- */
.today-hero {
  background: linear-gradient(135deg, var(--navy) 0%, var(--royal) 100%);
  border-radius: var(--radius-lg);
  padding: 20px;
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 12px;
  box-shadow: var(--shadow-md);
}

.today-date {
  font-size: 22px; font-weight: 800;
  color: var(--white);
  letter-spacing: -0.5px;
}

.today-dayname {
  font-size: 13px; color: rgba(255,255,255,0.7);
  margin-top: 2px;
}

.progress-ring-wrap {
  position: relative;
  width: 70px; height: 70px;
  display: flex; align-items: center; justify-content: center;
}

.progress-ring { transform: rotate(-90deg); }

.ring-bg {
  fill: none;
  stroke: rgba(255,255,255,0.2);
  stroke-width: 6;
}

.ring-fill {
  fill: none;
  stroke: var(--pink);
  stroke-width: 6;
  stroke-linecap: round;
  transition: stroke-dashoffset 0.5s ease;
}

.ring-label {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
}

#ring-pct {
  font-size: 14px; font-weight: 700;
  color: var(--white);
}

.progress-stats {
  display: flex; align-items: center; gap: 8px;
  font-size: 13px; color: var(--text-muted);
  margin-bottom: 14px;
  padding: 0 4px;
}

.stat-divider { color: var(--gray-400); }

/* ---- Filter Pills ---- */
.filter-row, .meds-filter-row {
  display: flex; gap: 8px;
  overflow-x: auto; padding-bottom: 4px;
  margin-bottom: 16px;
  scrollbar-width: none;
}
.filter-row::-webkit-scrollbar,
.meds-filter-row::-webkit-scrollbar { display: none; }

.filter-pill {
  flex-shrink: 0;
  padding: 7px 14px;
  border-radius: 20px;
  border: 1.5px solid var(--gray-200);
  background: var(--white);
  font-size: 13px; font-weight: 500;
  color: var(--gray-600);
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}

.filter-pill.active {
  background: var(--royal);
  border-color: var(--royal);
  color: var(--white);
  box-shadow: 0 2px 8px rgba(65,105,225,0.3);
}

/* ---- Medication Cards (Today) ---- */
.med-grid {
  display: flex; flex-direction: column; gap: 12px;
}

.time-section-label {
  font-size: 12px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.8px;
  color: var(--text-muted);
  margin: 8px 0 4px;
  display: flex; align-items: center; gap: 6px;
}

.med-card {
  background: var(--white);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: flex; align-items: flex-start; gap: 14px;
  box-shadow: var(--shadow-sm);
  border: 1.5px solid var(--gray-200);
  transition: all 0.2s;
  position: relative;
}

.med-card.taken {
  background: var(--success-bg);
  border-color: var(--success);
  opacity: 0.85;
}

.med-card.sos-card {
  border-left: 4px solid var(--pink-dark);
}

.med-check {
  flex-shrink: 0;
  width: 28px; height: 28px;
  border-radius: 50%;
  border: 2px solid var(--gray-200);
  background: var(--white);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: all 0.2s;
  font-size: 14px;
}

.med-card.taken .med-check {
  background: var(--success);
  border-color: var(--success);
  color: var(--white);
}

.med-info { flex: 1; min-width: 0; }

.med-name {
  font-size: 15px; font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.med-card.taken .med-name { text-decoration: line-through; color: var(--text-muted); }

.med-dosage {
  font-size: 13px; color: var(--text-muted);
  margin: 2px 0;
}

.med-instructions {
  font-size: 12px; color: var(--royal);
  font-weight: 500;
}

.med-tags { display: flex; gap: 6px; margin-top: 6px; flex-wrap: wrap; }

.tag {
  font-size: 11px; font-weight: 500;
  padding: 2px 8px;
  border-radius: 10px;
}

.tag-med { background: var(--royal-pale); color: var(--royal); }
.tag-supp { background: var(--pink-light); color: var(--pink-dark); }
.tag-sos { background: #FFF3F3; color: var(--danger); }

.med-taken-by {
  font-size: 11px; color: var(--text-muted);
  margin-top: 4px;
}

.med-actions { display: flex; flex-direction: column; gap: 6px; align-items: flex-end; }

.sos-take-btn {
  font-size: 11px; font-weight: 600;
  padding: 4px 10px;
  border: 1.5px solid var(--pink-dark);
  background: var(--pink-light);
  color: var(--pink-dark);
  border-radius: 8px; cursor: pointer;
  white-space: nowrap;
}

.sos-count {
  font-size: 11px; color: var(--text-muted);
  text-align: right;
}

/* ---- Chat Tab ---- */
.chat-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 12px;
}

.chat-header h2 { font-size: 18px; font-weight: 700; }

.chat-messages {
  flex: 1;
  height: calc(100vh - var(--header-h) - var(--nav-h) - 80px);
  overflow-y: auto;
  display: flex; flex-direction: column; gap: 10px;
  padding-bottom: 60px;
}

.chat-empty {
  text-align: center;
  color: var(--text-muted);
  font-size: 14px;
  padding: 40px 20px;
}

.chat-bubble-wrap {
  display: flex; flex-direction: column;
}

.chat-bubble-wrap.me { align-items: flex-end; }
.chat-bubble-wrap.them { align-items: flex-start; }

.chat-meta {
  font-size: 11px; color: var(--text-muted);
  margin-bottom: 3px;
  padding: 0 4px;
}

.chat-bubble {
  max-width: 75%;
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 14px; line-height: 1.5;
  word-break: break-word;
}

.me .chat-bubble {
  background: linear-gradient(135deg, var(--royal) 0%, var(--royal-light) 100%);
  color: var(--white);
  border-bottom-right-radius: 4px;
}

.them .chat-bubble {
  background: var(--white);
  color: var(--text-primary);
  border: 1.5px solid var(--gray-200);
  border-bottom-left-radius: 4px;
}

.reminder-bubble .chat-bubble {
  background: linear-gradient(135deg, var(--pink-dark), #C0706E);
  color: var(--white);
  font-weight: 500;
}

.chat-time {
  font-size: 10px;
  color: var(--text-muted);
  margin-top: 2px;
  padding: 0 4px;
}

.chat-input-bar {
  position: fixed;
  bottom: var(--nav-h);
  left: 50%; transform: translateX(-50%);
  width: 100%; max-width: 480px;
  display: flex; gap: 10px;
  padding: 10px 16px;
  background: var(--white);
  border-top: 1px solid var(--gray-200);
  z-index: 90;
}

#chat-input {
  flex: 1;
  padding: 10px 14px;
  border-radius: 22px;
  border: 1.5px solid var(--gray-200);
  background: var(--gray-100);
  font-size: 14px; color: var(--text-primary);
  outline: none;
  font-family: inherit;
}

#chat-input:focus { border-color: var(--royal); background: var(--white); }

.btn-send {
  width: 40px; height: 40px;
  border-radius: 50%;
  background: var(--royal);
  border: none; cursor: pointer;
  color: var(--white);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  transition: background 0.2s;
}
.btn-send:hover { background: var(--royal-light); }

/* ---- Medications Management Tab ---- */
.section-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 14px;
}
.section-header h2 { font-size: 18px; font-weight: 700; }

.meds-manage-list {
  display: flex; flex-direction: column; gap: 10px;
  padding-bottom: 16px;
}

.manage-med-card {
  background: var(--white);
  border-radius: var(--radius);
  padding: 14px 16px;
  border: 1.5px solid var(--gray-200);
  box-shadow: var(--shadow-sm);
  display: flex; align-items: flex-start; gap: 12px;
}

.manage-med-icon {
  font-size: 24px;
  width: 40px; height: 40px;
  background: var(--royal-pale);
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}

.manage-med-icon.supplement { background: var(--pink-light); }

.manage-med-info { flex: 1; min-width: 0; }

.manage-med-name {
  font-size: 15px; font-weight: 600;
  color: var(--text-primary);
}

.manage-med-detail {
  font-size: 13px; color: var(--text-muted);
  margin-top: 2px;
}

.manage-med-slots {
  display: flex; gap: 4px; flex-wrap: wrap; margin-top: 6px;
}

.slot-chip {
  font-size: 11px; font-weight: 500;
  padding: 2px 8px;
  background: var(--royal-pale);
  color: var(--royal);
  border-radius: 10px;
}
.slot-chip.sos { background: #FFF3F3; color: var(--danger); }

.manage-med-actions {
  display: flex; flex-direction: column; gap: 6px;
}

.btn-icon {
  width: 30px; height: 30px;
  border-radius: var(--radius-sm);
  border: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px;
  transition: all 0.2s;
}

.btn-edit { background: var(--royal-pale); color: var(--royal); }
.btn-delete { background: var(--danger-bg); color: var(--danger); }
.btn-edit:hover { background: var(--royal); color: var(--white); }
.btn-delete:hover { background: var(--danger); color: var(--white); }

/* ---- Settings Tab ---- */
.section-title { font-size: 22px; font-weight: 800; margin-bottom: 16px; color: var(--navy); }

.settings-card {
  background: var(--white);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 14px;
  border: 1.5px solid var(--gray-200);
  box-shadow: var(--shadow-sm);
}

.settings-card h3 {
  font-size: 15px; font-weight: 700;
  color: var(--navy);
  margin-bottom: 14px;
}

.settings-hint {
  font-size: 13px; color: var(--text-muted);
  margin-bottom: 14px;
  line-height: 1.5;
}

.reminder-grid { display: flex; flex-direction: column; gap: 10px; margin-bottom: 14px; }

.reminder-row {
  display: flex; align-items: center; justify-content: space-between;
  font-size: 14px; color: var(--text-primary);
}

.reminder-row input[type="time"] {
  padding: 6px 10px;
  border: 1.5px solid var(--gray-200);
  border-radius: var(--radius-sm);
  font-size: 14px; color: var(--navy);
  outline: none; font-family: inherit;
  background: var(--gray-100);
}

.reminder-row input[type="time"]:focus { border-color: var(--royal); }

.share-row {
  display: flex; gap: 8px; align-items: center;
}

.share-input {
  flex: 1;
  font-size: 12px;
  background: var(--gray-100);
}

.danger-zone h3 { color: var(--danger); }

/* ---- Forms ---- */
.form-group { margin-bottom: 14px; }

.form-group label {
  display: block;
  font-size: 13px; font-weight: 600;
  color: var(--navy);
  margin-bottom: 6px;
}

.form-group input[type="text"],
.form-group select {
  width: 100%;
  padding: 10px 12px;
  border: 1.5px solid var(--gray-200);
  border-radius: var(--radius-sm);
  font-size: 14px; color: var(--text-primary);
  background: var(--white);
  outline: none;
  font-family: inherit;
  transition: border-color 0.2s;
}

.form-group input:focus,
.form-group select:focus { border-color: var(--royal); }

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.required { color: var(--danger); }

/* ---- Timeslot Checkboxes ---- */
.timeslot-checkboxes {
  display: grid; grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.checkbox-pill {
  display: flex; align-items: center; gap: 6px;
  padding: 8px 12px;
  border: 1.5px solid var(--gray-200);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 13px; font-weight: 500;
  color: var(--gray-600);
  transition: all 0.2s;
  user-select: none;
}

.checkbox-pill:has(input:checked) {
  border-color: var(--royal);
  background: var(--royal-pale);
  color: var(--royal);
}

.checkbox-pill input { display: none; }

/* ---- Toggle Switch ---- */
.toggle-label {
  display: flex; align-items: center; justify-content: space-between;
  cursor: pointer;
}

.toggle-switch { position: relative; display: inline-block; width: 44px; height: 24px; }
.toggle-switch input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
  position: absolute; inset: 0;
  background: var(--gray-200);
  border-radius: 12px;
  transition: background 0.2s;
}
.toggle-slider::before {
  content: '';
  position: absolute;
  width: 18px; height: 18px;
  left: 3px; top: 3px;
  background: var(--white);
  border-radius: 50%;
  transition: transform 0.2s;
  box-shadow: var(--shadow-sm);
}
.toggle-switch input:checked + .toggle-slider { background: var(--royal); }
.toggle-switch input:checked + .toggle-slider::before { transform: translateX(20px); }

/* ---- Buttons ---- */
.btn-primary {
  background: linear-gradient(135deg, var(--royal) 0%, var(--royal-light) 100%);
  color: var(--white);
  border: none; cursor: pointer;
  padding: 12px 20px;
  border-radius: var(--radius-sm);
  font-size: 14px; font-weight: 600;
  font-family: inherit;
  transition: all 0.2s;
  box-shadow: 0 2px 8px rgba(65,105,225,0.3);
}

.btn-primary:hover { box-shadow: 0 4px 12px rgba(65,105,225,0.4); transform: translateY(-1px); }
.btn-primary:active { transform: none; box-shadow: none; }

.btn-primary.small { padding: 8px 16px; font-size: 13px; }

.btn-secondary {
  background: var(--white);
  color: var(--royal);
  border: 1.5px solid var(--royal);
  cursor: pointer;
  padding: 12px 20px;
  border-radius: var(--radius-sm);
  font-size: 14px; font-weight: 600;
  font-family: inherit;
  transition: all 0.2s;
}

.btn-secondary:hover { background: var(--royal-pale); }
.btn-secondary.small { padding: 7px 14px; font-size: 12px; }

.btn-danger {
  background: var(--danger-bg);
  color: var(--danger);
  border: 1.5px solid var(--danger);
  cursor: pointer;
  padding: 12px 20px;
  border-radius: var(--radius-sm);
  font-size: 14px; font-weight: 600;
  font-family: inherit;
  transition: all 0.2s;
}

.btn-danger:hover { background: var(--danger); color: var(--white); }

/* ---- Badge ---- */
.badge {
  position: absolute;
  top: -4px; right: -4px;
  min-width: 18px; height: 18px;
  background: var(--pink-dark);
  color: var(--white);
  border-radius: 10px;
  font-size: 10px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  padding: 0 4px;
  border: 2px solid var(--navy-dark);
}

.nav-btn .badge {
  top: 2px; right: 50%; transform: translateX(18px);
  border-color: var(--white);
}

/* ---- Toast ---- */
.toast {
  position: fixed;
  bottom: calc(var(--nav-h) + 12px);
  left: 50%; transform: translateX(-50%);
  background: var(--navy);
  color: var(--white);
  padding: 10px 20px;
  border-radius: 22px;
  font-size: 13px; font-weight: 500;
  z-index: 2000;
  box-shadow: var(--shadow-lg);
  animation: fadeInUp 0.3s ease;
  max-width: 320px; text-align: center;
}

.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }

/* ---- Loading ---- */
.loading-spinner {
  text-align: center;
  color: var(--text-muted);
  font-size: 14px;
  padding: 40px 20px;
}

/* ---- Empty state ---- */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
}

.empty-state-icon { font-size: 40px; margin-bottom: 12px; }
.empty-state p { font-size: 14px; line-height: 1.6; }

/* ---- Animations ---- */
@keyframes slideUp {
  from { opacity: 0; transform: translateY(30px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes fadeInUp {
  from { opacity: 0; transform: translateX(-50%) translateY(10px); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ---- Scrollbars ---- */
* { scrollbar-width: thin; scrollbar-color: var(--gray-200) transparent; }

/* ---- Desktop centering ---- */
@media (min-width: 481px) {
  body { border-left: 1px solid var(--gray-200); border-right: 1px solid var(--gray-200); box-shadow: var(--shadow-lg); }
}
