@import url('https://fonts.googleapis.com/css2?family=Playfair+Display:ital,wght@0,400;0,600;1,400&family=Lora:ital,wght@0,400;0,500;1,400&display=swap');

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

:root {
  --cream: #fdf8f0;
  --brown: #8b5e3c;
  --brown-dark: #6e4a2e;
  --brown-light: #c8a882;
  --text: #3d2b1f;
  --text-muted: #9a7a60;
  --border: #e8ddd0;
  --white: #ffffff;
}

html, body { height: 100%; overflow: hidden; background: var(--cream); }
body { font-family: 'Lora', Georgia, serif; color: var(--text); }

/* ── VIEWS ── */
.view {
  position: absolute; inset: 0;
  overflow-y: auto; overflow-x: hidden;
  display: none; flex-direction: column;
  background: var(--cream);
}
.view.active { display: flex; }

/* ── TYPOGRAPHY ── */
.display { font-family: 'Playfair Display', Georgia, serif; }

/* ── BUTTONS ── */
button { font-family: 'Lora', Georgia, serif; cursor: pointer; border: none; background: none; }
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: 8px; border-radius: 14px; font-size: 15px;
  padding: 14px 24px; font-weight: 500; transition: all 0.15s;
}
.btn-primary { background: var(--brown); color: white; }
.btn-primary:hover { background: var(--brown-dark); }
.btn-primary:disabled { opacity: 0.45; pointer-events: none; }
.btn-ghost { background: transparent; color: var(--brown); border: 2px solid var(--border); }
.btn-ghost:hover { background: #f5ede0; }
.btn-block { width: 100%; }

/* ── INPUTS ── */
input, textarea, select {
  font-family: 'Lora', Georgia, serif;
  width: 100%; padding: 13px 16px;
  border: 2px solid var(--border); border-radius: 12px;
  font-size: 15px; color: var(--text); background: #fffdf9;
  outline: none; transition: border-color 0.2s;
  -webkit-appearance: none;
}
input:focus, textarea:focus { border-color: var(--brown-light); }
textarea { resize: none; line-height: 1.65; }
label {
  font-style: italic; font-size: 13px;
  color: var(--text-muted); display: block; margin-bottom: 8px;
}

/* ── HERO HEADER ── */
.hero {
  background: linear-gradient(135deg, var(--brown) 0%, var(--brown-light) 100%);
  padding: 52px 24px 32px;
  position: relative; overflow: hidden; flex-shrink: 0;
}
.hero::before {
  content: ''; position: absolute; top: -40px; right: -40px;
  width: 160px; height: 160px; border-radius: 50%;
  background: rgba(255,255,255,0.07);
}
.hero::after {
  content: ''; position: absolute; bottom: -25px; left: 50px;
  width: 90px; height: 90px; border-radius: 50%;
  background: rgba(255,255,255,0.05);
}

/* ── LOGO AREA ── */
.logo-row {
  display: flex; align-items: center; gap: 12px; margin-bottom: 16px;
}
.logo-mark {
  width: 44px; height: 44px; flex-shrink: 0;
}
.logo-name {
  font-family: 'Playfair Display', Georgia, serif;
  font-size: 15px; font-weight: 600;
  color: rgba(255,255,255,0.9);
  letter-spacing: 0.04em;
  line-height: 1.2;
}
.logo-tagline {
  font-size: 11px; font-style: italic;
  color: rgba(255,255,255,0.55);
  letter-spacing: 0.06em;
}

.hero-eyebrow {
  font-style: italic; color: rgba(255,255,255,0.7);
  font-size: 13px; letter-spacing: 0.07em; margin-bottom: 6px;
}
.hero-title {
  font-family: 'Playfair Display', Georgia, serif;
  font-size: 30px; font-weight: 600; color: white; line-height: 1.2;
}
.hero-sub {
  font-style: italic; color: rgba(255,255,255,0.65);
  font-size: 13px; margin-top: 8px;
}

/* ── PERSON CARDS ── */
.person-card {
  background: white; border-radius: 20px;
  box-shadow: 0 2px 12px rgba(80,50,20,0.07);
  padding: 18px 20px; display: flex; align-items: center; gap: 15px;
  cursor: pointer; transition: transform 0.15s, box-shadow 0.15s;
  margin-bottom: 12px;
}
.person-card:hover { transform: translateY(-2px); box-shadow: 0 6px 24px rgba(80,50,20,0.12); }
.person-card:active { transform: translateY(0); }

/* ── AVATARS ── */
.avatar {
  width: 58px; height: 58px; border-radius: 50%; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-family: 'Playfair Display', Georgia, serif;
  font-size: 22px; font-weight: 600; color: var(--brown-dark); overflow: hidden;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar-lg {
  width: 88px; height: 88px; border-radius: 50%;
  margin: 0 auto 12px;
  display: flex; align-items: center; justify-content: center;
  font-family: 'Playfair Display', Georgia, serif;
  font-size: 34px; font-weight: 600; color: var(--brown-dark); overflow: hidden;
  background: rgba(255,255,255,0.55);
}
.avatar-lg img { width: 100%; height: 100%; object-fit: cover; }

/* ── TAGS ── */
.tag {
  display: inline-block; padding: 3px 11px; border-radius: 20px;
  font-size: 12px; font-style: italic;
  background: #f0e6d8; color: #7a5c40; margin: 2px;
}

/* ── NOTES ── */
.note-card {
  background: #fffdf7; border-left: 3px solid var(--brown-light);
  border-radius: 0 12px 12px 0; padding: 14px 16px; margin-bottom: 12px;
}
.note-date { font-size: 11px; color: #c4a882; font-style: italic; margin-bottom: 5px; }
.note-text { font-size: 15px; line-height: 1.65; color: #4a3428; }

/* ── BACK BUTTON ── */
.back-btn {
  position: absolute; top: 16px; left: 16px;
  font-style: italic; color: rgba(255,255,255,0.85); font-size: 14px;
  display: flex; align-items: center; gap: 4px; padding: 6px;
}
.back-btn:hover { color: white; }

/* ── LAYOUT HELPERS ── */
.pad { padding: 20px; }
.field { margin-bottom: 18px; }
.pb { padding-bottom: 110px; }
#searchWrap { padding: 16px 20px 8px; }

/* ── COLOR SWATCHES ── */
.swatches { display: flex; gap: 10px; flex-wrap: wrap; }
.swatch {
  width: 30px; height: 30px; border-radius: 50%;
  cursor: pointer; border: 3px solid transparent; transition: border-color 0.15s;
}
.swatch.sel { border-color: var(--brown); }

/* ── FAB ── */
.fab {
  position: fixed; bottom: 28px; left: 50%; transform: translateX(-50%);
  background: var(--brown); color: white; border-radius: 50px;
  padding: 16px 30px; font-size: 15px; font-weight: 500;
  box-shadow: 0 8px 28px rgba(80,40,10,0.28);
  display: flex; align-items: center; gap: 8px;
  white-space: nowrap; z-index: 50;
}
.fab:hover { background: var(--brown-dark); }

/* ── PHOTO CAPTURE ── */
#photoSection { display: flex; flex-direction: column; gap: 12px; }
#photoPreview {
  width: 100%; aspect-ratio: 4/3; border-radius: 16px;
  object-fit: cover; display: none; border: 2px solid var(--border);
}
#captureCam {
  width: 100%; aspect-ratio: 4/3; border-radius: 16px;
  object-fit: cover; display: none;
}
#captureCanvas { display: none; }
.photo-placeholder {
  width: 100%; aspect-ratio: 4/3; border-radius: 16px;
  background: #f0e8dc; border: 2px dashed var(--brown-light);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  color: var(--text-muted); font-style: italic; font-size: 14px; gap: 8px;
}
.photo-placeholder .ph-icon { font-size: 36px; }
.photo-btns { display: flex; gap: 10px; }
.photo-btns button { flex: 1; }

/* ── CAMERA VIEW ── */
#cameraView { background: #000; }
#cameraWrap { position: relative; width: 100%; flex: 1; overflow: hidden; }
#video { width: 100%; height: 100%; object-fit: cover; display: block; }
#overlayCanvas {
  position: absolute; top: 0; left: 0; width: 100%; height: 100%;
  pointer-events: none;
}
.cam-ui {
  position: absolute; bottom: 0; left: 0; right: 0;
  background: linear-gradient(transparent, rgba(0,0,0,0.7));
  padding: 20px 20px 36px;
  display: flex; flex-direction: column; align-items: center; gap: 12px;
}
.cam-status {
  background: rgba(0,0,0,0.55); backdrop-filter: blur(8px);
  border-radius: 20px; padding: 8px 18px;
  font-style: italic; font-size: 13px; color: rgba(255,255,255,0.8);
  border: 1px solid rgba(255,255,255,0.1);
}
.cam-fab {
  background: var(--brown); color: white; border-radius: 50px;
  padding: 14px 28px; font-size: 15px; font-weight: 500;
  box-shadow: 0 6px 20px rgba(0,0,0,0.35);
  display: flex; align-items: center; gap: 8px;
}
#camBackBtn {
  position: absolute; top: 52px; left: 16px;
  background: rgba(0,0,0,0.5); backdrop-filter: blur(6px);
  color: white; border-radius: 20px; padding: 8px 16px;
  font-style: italic; font-size: 14px;
  border: 1px solid rgba(255,255,255,0.15);
}

/* ── RECOGNITION OVERLAY CARDS ── */
.rec-card {
  position: absolute;
  background: rgba(253,248,240,0.97); backdrop-filter: blur(12px);
  border-radius: 16px; padding: 12px 14px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.35);
  min-width: 160px; max-width: 200px;
  border: 1.5px solid rgba(200,168,130,0.4);
  pointer-events: none;
  animation: popIn 0.25s cubic-bezier(0.34,1.56,0.64,1);
  z-index: 10;
}
.rec-name { font-family: 'Playfair Display', Georgia, serif; font-size: 17px; font-weight: 600; color: var(--text); }
.rec-rel  { font-style: italic; font-size: 12px; color: var(--text-muted); margin: 2px 0 6px; }
.rec-last { font-size: 11px; color: var(--brown); }
.rec-note {
  font-size: 11px; color: #5a4030; margin-top: 5px;
  line-height: 1.4; font-style: italic;
  border-top: 1px solid #f0e0d0; padding-top: 5px;
}

.unknown-badge {
  position: absolute;
  background: rgba(139,94,60,0.92); backdrop-filter: blur(8px);
  color: white; border-radius: 12px; padding: 8px 14px;
  font-size: 13px; font-style: italic;
  box-shadow: 0 4px 16px rgba(0,0,0,0.3);
  pointer-events: none; white-space: nowrap;
  border: 1px solid rgba(255,255,255,0.15);
  animation: popIn 0.2s ease;
}

/* ── MODEL LOADER ── */
#modelLoader {
  position: fixed; inset: 0; background: rgba(61,43,31,0.92);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  z-index: 1000; gap: 16px;
}
.loader-title { font-family: 'Playfair Display'; font-size: 22px; color: #f5e8d5; }
.loader-sub { font-style: italic; font-size: 14px; color: rgba(245,232,213,0.65); }
.spinner {
  width: 44px; height: 44px;
  border: 3px solid rgba(200,168,130,0.25);
  border-top-color: var(--brown-light);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

/* ── RE-ENCODE SECTION ── */
.reencode-box {
  background: #fff8f0; border: 1.5px solid #f0dcc8;
  border-radius: 14px; padding: 14px 16px; text-align: center;
}
.reencode-hint {
  font-style: italic; font-size: 13px;
  color: var(--text-muted); margin-bottom: 10px;
}

/* ── ANIMATIONS ── */
@keyframes popIn {
  from { opacity: 0; transform: scale(0.8) translateY(6px); }
  to   { opacity: 1; transform: scale(1)   translateY(0); }
}
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes toastIn {
  from { opacity: 0; transform: translateX(-50%) translateY(10px); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ── HAMBURGER ── */
.hamburger {
  background: rgba(255,255,255,0.15); border: none; border-radius: 10px;
  padding: 9px 10px; cursor: pointer; display: flex; flex-direction: column;
  gap: 5px; z-index: 10;
}
.hamburger span {
  display: block; width: 22px; height: 2px;
  background: rgba(255,255,255,0.9); border-radius: 2px; transition: all 0.2s;
}
.hamburger:hover { background: rgba(255,255,255,0.25); }

/* ── SIDEBAR OVERLAY ── */
#sidebarOverlay {
  position: fixed; inset: 0; background: rgba(61,43,31,0.45);
  z-index: 200; display: none; backdrop-filter: blur(2px);
}
#sidebarOverlay.active { display: block; }

/* ── SIDEBAR ── */
#sidebar {
  position: fixed; top: 0; left: 0; bottom: 0; width: 270px;
  background: var(--cream); z-index: 300;
  display: flex; flex-direction: column;
  transform: translateX(-100%);
  transition: transform 0.28s cubic-bezier(0.4,0,0.2,1);
  box-shadow: 4px 0 32px rgba(61,43,31,0.18);
}
#sidebar.open { transform: translateX(0); }

.sidebar-header {
  display: flex; align-items: center; gap: 12px;
  padding: 52px 20px 20px;
  border-bottom: 1px solid var(--border);
}

.sidebar-nav {
  flex: 1; padding: 16px 12px; display: flex; flex-direction: column; gap: 4px;
}

.sidebar-item {
  display: flex; align-items: center; gap: 12px;
  padding: 13px 16px; border-radius: 14px; width: 100%;
  font-family: 'Lora', Georgia, serif; font-size: 15px; color: var(--text);
  background: none; border: none; cursor: pointer; text-align: left;
  transition: background 0.15s;
}
.sidebar-item:hover { background: #f0e8dc; }
.sidebar-item.active { background: #f5ede0; color: var(--brown); font-weight: 500; }
.sidebar-icon { font-size: 18px; width: 26px; text-align: center; }

.sidebar-footer {
  padding: 16px 20px 32px;
  border-top: 1px solid var(--border);
}

/* ── MEDICATIONS ── */
.med-card {
  background: white; border-radius: 16px;
  box-shadow: 0 2px 10px rgba(80,50,20,0.06);
  padding: 16px 18px; margin-bottom: 12px;
}
.med-name {
  font-family: 'Playfair Display', Georgia, serif;
  font-size: 17px; font-weight: 600; color: var(--text);
}
.med-dosage {
  font-size: 13px; color: var(--brown); font-style: italic; margin: 2px 0 6px;
}
.med-times { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 6px; }
.med-time-chip {
  background: #f5ede0; color: var(--brown-dark);
  border-radius: 20px; padding: 3px 11px; font-size: 12px;
}
.med-note-text {
  font-size: 12px; color: var(--text-muted); font-style: italic;
}
.med-actions { display: flex; gap: 8px; margin-top: 10px; }

/* Daily dose slot */
.dose-group { margin-bottom: 20px; }
.dose-group-label {
  font-style: italic; font-size: 12px; color: var(--text-muted);
  letter-spacing: 0.06em; margin-bottom: 8px; text-transform: uppercase;
}
.dose-item {
  background: white; border-radius: 14px; padding: 14px 16px;
  display: flex; align-items: center; gap: 14px; margin-bottom: 8px;
  box-shadow: 0 2px 8px rgba(80,50,20,0.05);
  transition: opacity 0.2s;
}
.dose-item.done { opacity: 0.5; }
.dose-check {
  width: 26px; height: 26px; border-radius: 50%; flex-shrink: 0;
  border: 2px solid var(--brown-light); background: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; transition: all 0.15s;
}
.dose-check.checked { background: var(--brown); border-color: var(--brown); color: white; }
.dose-info { flex: 1; min-width: 0; }
.dose-med-name { font-size: 15px; font-weight: 500; }
.dose-detail { font-size: 12px; color: var(--text-muted); font-style: italic; margin-top: 2px; }
.dose-time { font-size: 13px; color: var(--brown); font-weight: 500; flex-shrink: 0; }

.meds-empty {
  text-align: center; font-style: italic; color: #b89878;
  padding: 30px 20px; font-size: 14px;
}

/* ── AUTH / LOGIN ── */
.auth-tab {
  flex: 1; padding: 10px; border-radius: 10px; font-size: 14px;
  font-family: 'Lora', Georgia, serif; cursor: pointer;
  border: none; background: none; color: var(--text-muted);
  transition: all 0.15s;
}
.auth-tab.active {
  background: white; color: var(--brown); font-weight: 500;
  box-shadow: 0 2px 8px rgba(80,50,20,0.1);
}

/* User badge in home hero */
.user-badge {
  position: absolute; top: 16px; right: 16px;
  background: rgba(255,255,255,0.15); border-radius: 20px;
  padding: 6px 12px 6px 8px; display: flex; align-items: center; gap: 7px;
  cursor: pointer; border: 1px solid rgba(255,255,255,0.2);
  transition: background 0.15s;
}
.user-badge:hover { background: rgba(255,255,255,0.25); }
.user-avatar-sm {
  width: 26px; height: 26px; border-radius: 50%;
  background: rgba(255,255,255,0.3); display: flex; align-items: center;
  justify-content: center; font-size: 12px; font-weight: 600; color: white;
  overflow: hidden; flex-shrink: 0;
}
.user-avatar-sm img { width: 100%; height: 100%; object-fit: cover; }
.user-name-sm { font-size: 12px; color: rgba(255,255,255,0.9); max-width: 90px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
