/* CareMate — Apple-inspired glassmorphism */

* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --glass: rgba(255, 255, 255, 0.05);
  --glass-strong: rgba(255, 255, 255, 0.09);
  --border: rgba(255, 255, 255, 0.1);
  --text: #f5f5f7;
  --text-dim: rgba(245, 245, 247, 0.55);
  --accent: #0a84ff;
  --accent2: #0060df;
  --good: #30d158;
  --warn: #ffd60a;
  --bad: #ff453a;
  --radius: 22px;
}

html, body { height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: radial-gradient(1100px 700px at 50% -20%, #0d1420 0%, transparent 60%),
              radial-gradient(900px 900px at 100% 110%, #0a0f18 0%, transparent 55%),
              #000;
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

/* single subtle ambient glow */
.bg-orbs span {
  position: fixed; border-radius: 50%; filter: blur(110px); opacity: 0.14;
  pointer-events: none; z-index: 0;
  animation: drift 30s ease-in-out infinite alternate;
}
.bg-orbs span:nth-child(1) { width: 460px; height: 460px; background: #0a84ff; top: -160px; left: -120px; }
.bg-orbs span:nth-child(2) { width: 380px; height: 380px; background: #1c3a5e; top: 40%; right: -160px; animation-delay: -10s; }
.bg-orbs span:nth-child(3) { display: none; }
@keyframes drift { to { transform: translate(50px, 30px) scale(1.1); } }

.glass {
  background: var(--glass);
  backdrop-filter: blur(28px) saturate(140%);
  -webkit-backdrop-filter: blur(28px) saturate(140%);
  border: 1px solid var(--border);
  box-shadow: 0 10px 36px rgba(0, 0, 0, 0.6), inset 0 1px 0 rgba(255, 255, 255, 0.06);
}

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 12px; z-index: 20;
  margin: 12px 16px 0;
  border-radius: var(--radius);
  padding: 12px 18px;
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-icon {
  width: 42px; height: 42px; border-radius: 13px; font-size: 20px;
  display: grid; place-items: center; color: #fff;
  background: linear-gradient(135deg, #0a84ff, #0050c8);
  box-shadow: 0 4px 18px rgba(10, 132, 255, 0.35);
}
.brand h1 { font-size: 19px; font-weight: 700; letter-spacing: -0.02em; }
.brand p { font-size: 12px; color: var(--text-dim); }
.context-chips { display: flex; gap: 8px; flex: 1; justify-content: center; flex-wrap: wrap; }
.chip { border-radius: 999px; padding: 7px 14px; font-size: 13px; white-space: nowrap; }

.btn-primary {
  border: none; cursor: pointer; color: #fff; font-weight: 600; font-size: 14px;
  padding: 10px 18px; border-radius: 999px;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  box-shadow: 0 4px 16px rgba(10, 132, 255, 0.4);
  transition: transform 0.15s, box-shadow 0.15s;
}
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 6px 22px rgba(10, 132, 255, 0.55); }
.btn-ghost {
  border: 1px solid var(--border); background: transparent; color: var(--text);
  padding: 10px 18px; border-radius: 999px; cursor: pointer; font-size: 14px;
}
.btn-ghost:hover { background: var(--glass); }

/* ---------- layout ---------- */
/* Netlify injects a fixed badge (/.netlify/scripts/hud, ~200x64, maximum
   z-index) into the bottom-right corner of every deployed page. It sat right
   on top of the chat box and the 🎙 button, so the page keeps that strip clear. */
:root { --hud-space: 76px; }
.layout {
  position: relative; z-index: 1;
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) minmax(340px, 1fr);
  gap: 16px; padding: 16px;
  /* padding, not margin: body is viewport-tall and the page's scroll extent
     ignores a trailing margin on content that overflows it */
  padding-bottom: calc(16px + var(--hud-space));
  box-sizing: border-box;
  height: calc(100vh - 90px);
}
/* camera on top, the five readings in one row underneath */
.col-left { display: flex; flex-direction: column; gap: 12px; min-height: 0; }
.col-chat { min-height: 0; }
.tiles { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 10px; flex-shrink: 0; }

.card { border-radius: var(--radius); padding: 16px; display: flex; flex-direction: column; min-height: 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.card-head h2 { font-size: 14px; font-weight: 600; letter-spacing: -0.01em; color: var(--text-dim); text-transform: uppercase; }
.tag {
  font-size: 10px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase;
  padding: 3px 9px; border-radius: 999px; background: rgba(10, 132, 255, 0.18); color: #7cc0ff;
}

/* ---------- camera ---------- */
.camera-card { flex: 1; min-height: 0; }
.video-wrap {
  position: relative; flex: 1; min-height: 200px;
  border-radius: 16px; overflow: hidden; background: #000;
}
#video, #overlay { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
#overlay { pointer-events: none; }
.cam-placeholder {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 10px;
  background: rgba(10, 10, 18, 0.7); font-size: 15px; color: var(--text-dim);
}
.cam-placeholder p:first-child { font-size: 42px; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: #555; }
.dot.live { background: var(--good); box-shadow: 0 0 10px var(--good); animation: pulse 1.6s infinite; }
@keyframes pulse { 50% { opacity: 0.5; } }
.scene-line { margin-top: 8px; font-size: 13px; color: #9fceff; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.model-status { margin-top: 2px; font-size: 11px; color: var(--text-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.span-all { grid-column: 1 / -1; }
.span-rest { grid-column: 2 / -1; }
.row-gap { display: flex; gap: 8px; align-items: center; }
.btn-small { padding: 8px 12px; font-size: 12px; white-space: nowrap; }
.tag-btn { cursor: pointer; border: none; transition: background 0.15s; }
.tag-btn:hover { background: rgba(10, 132, 255, 0.35); }
.tag-btn.calibrated { background: rgba(48, 209, 88, 0.2); color: #7ce39a; }

/* segmented control (safety sensitivity) */
.seg { display: flex; gap: 2px; background: rgba(255, 255, 255, 0.07); border-radius: 999px; padding: 2px; }
.seg button {
  border: none; background: transparent; color: var(--text-dim); cursor: pointer;
  font-size: 10px; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase;
  padding: 3px 8px; border-radius: 999px; transition: background 0.15s, color 0.15s;
}
.seg button.active { background: var(--accent); color: #fff; }
.scan-line { font-size: 10.5px; color: var(--text-dim); margin-top: 2px; }

/* ---------- status cards ---------- */
.status-card { padding: 12px 12px 10px; gap: 4px; overflow: hidden; min-width: 0; }
.status-card .card-head { margin-bottom: 2px; }
.status-card .card-head h2 { font-size: 11px; letter-spacing: 0.04em; white-space: nowrap; }
.tile-main { display: flex; align-items: center; gap: 8px; min-width: 0; }
.status-icon { font-size: 20px; line-height: 1; flex-shrink: 0; }
.status-value { font-size: 17px; font-weight: 700; letter-spacing: -0.02em; text-transform: capitalize; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
/* a short line on the tile; the whole story is in the tooltip */
.status-sub { font-size: 11.5px; line-height: 1.35; color: var(--text-dim); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; min-height: 2.7em; }
.status-card.state-good { border-color: rgba(48, 209, 88, 0.4); }
.status-card.state-warn { border-color: rgba(255, 214, 10, 0.5); }
.status-card.state-bad  { border-color: rgba(255, 69, 58, 0.65); box-shadow: 0 0 24px rgba(255, 69, 58, 0.25); }

.emotion-bars {
  width: 100%; display: grid; grid-template-columns: 1fr;
  gap: 2px; min-height: 0;
}
.ebar { display: flex; align-items: center; gap: 5px; font-size: 10px; color: var(--text-dim); min-width: 0; }
.ebar span:first-child { width: 58px; flex-shrink: 0; text-transform: capitalize; white-space: nowrap; overflow: hidden; }
.ebar .track { flex: 1; height: 3px; border-radius: 2px; background: rgba(255, 255, 255, 0.1); overflow: hidden; }
.ebar .fill { display: block; height: 100%; border-radius: 2px; background: linear-gradient(90deg, var(--accent), var(--accent2)); transition: width 0.3s; }

/* ---------- chat ---------- */
.chat-card { height: 100%; }
.chat-log { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; padding: 4px 2px; min-height: 0; }
.chat-log::-webkit-scrollbar { width: 5px; }
.chat-log::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.15); border-radius: 3px; }
.msg { max-width: 84%; padding: 10px 14px; border-radius: 18px; font-size: 14px; line-height: 1.45; white-space: pre-wrap; word-break: break-word; }
.msg.user { align-self: flex-end; background: linear-gradient(135deg, var(--accent), var(--accent2)); color: #fff; border-bottom-right-radius: 6px; }
.msg.bot { align-self: flex-start; background: var(--glass-strong); border: 1px solid var(--border); border-bottom-left-radius: 6px; }
.msg.system { align-self: center; background: rgba(255, 214, 10, 0.14); border: 1px solid rgba(255, 214, 10, 0.3); color: #ffe58a; font-size: 12.5px; }
.msg.alert { align-self: center; background: rgba(255, 69, 58, 0.16); border: 1px solid rgba(255, 69, 58, 0.4); color: #ff9f97; font-size: 12.5px; }
.msg.typing { color: var(--text-dim); font-style: italic; }

.chat-input {
  margin-top: 12px; display: flex; gap: 8px; border-radius: 999px; padding: 6px 6px 6px 16px;
}
.chat-input input { flex: 1; background: transparent; border: none; outline: none; color: var(--text); font-size: 14px; }
.chat-input input::placeholder { color: var(--text-dim); }
.chat-input button {
  width: 38px; height: 38px; border-radius: 50%; border: none; cursor: pointer;
  background: linear-gradient(135deg, var(--accent), var(--accent2)); color: #fff; font-size: 15px;
}
.chat-input .chat-mic { background: var(--glass-strong); border: 1px solid var(--border); flex-shrink: 0; }
.chat-input .chat-mic.on { background: rgba(48, 209, 88, 0.22); border-color: rgba(48, 209, 88, 0.6); }
.msg.user.spoken::before { content: "🎙 "; opacity: 0.75; }

/* ---------- voice bubble ---------- */
.voice-bubble {
  margin-top: 10px; align-self: center; display: flex; align-items: center; gap: 10px;
  border-radius: 999px; padding: 6px 6px 6px 10px; font-size: 13px;
}
.voice-orb {
  --lvl: 0; --c: var(--accent);
  width: 22px; height: 22px; border-radius: 50%; flex-shrink: 0;
  background: radial-gradient(circle at 35% 35%, #fff 0 8%, var(--c) 45%);
  box-shadow: 0 0 calc(4px + var(--lvl) * 22px) calc(var(--lvl) * 7px) var(--c);
  transform: scale(calc(1 + var(--lvl) * 0.35));
  transition: transform 0.08s, box-shadow 0.08s;
}
.voice-bubble[data-state="listening"] .voice-orb { --c: var(--good); }
.voice-bubble[data-state="hearing"] .voice-orb { --c: var(--good); }
.voice-bubble[data-state="speaking"] .voice-orb { --c: var(--accent); }
.voice-bubble[data-state="thinking"] .voice-orb,
.voice-bubble[data-state="transcribing"] .voice-orb,
.voice-bubble[data-state="starting"] .voice-orb { --c: var(--warn); animation: pulse 1s infinite; }
.voice-label { color: var(--text); white-space: nowrap; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.voice-stop {
  width: 26px; height: 26px; border-radius: 50%; border: 1px solid var(--border); cursor: pointer;
  background: transparent; color: var(--text-dim); font-size: 12px; flex-shrink: 0;
}
.voice-stop:hover { background: rgba(255, 69, 58, 0.2); color: #fff; }
@media (prefers-reduced-motion: reduce) { .voice-orb { transition: none; animation: none !important; } }

/* ---------- memory tab ---------- */
.tabs button { font-size: 11px; padding: 4px 12px; }
.pane { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.pane.hidden { display: none !important; }

.mem-toolbar { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; }
.mem-toolbar input {
  flex: 1; font-size: 13px; padding: 7px 12px; border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
}
.mem-stats { font-size: 10.5px; color: var(--text-dim); white-space: nowrap; }

.mem-body { flex: 1; display: grid; grid-template-columns: 45% 1fr; gap: 10px; min-height: 0; }
.mem-tree, .mem-note {
  overflow-y: auto; min-height: 0; padding-right: 4px;
  border-radius: 14px; background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.07); padding: 8px;
}
.mem-tree::-webkit-scrollbar, .mem-note::-webkit-scrollbar { width: 5px; }
.mem-tree::-webkit-scrollbar-thumb, .mem-note::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.15); border-radius: 3px;
}

.mem-folder { margin-bottom: 6px; }
.mem-folder > summary {
  cursor: pointer; list-style: none; font-size: 11px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-dim);
  padding: 4px 6px; border-radius: 8px; display: flex; align-items: center; gap: 6px;
}
.mem-folder > summary::-webkit-details-marker { display: none; }
.mem-folder > summary:hover { background: rgba(255, 255, 255, 0.05); color: var(--text); }
.mem-folder > summary::before { content: "▸"; transition: transform 0.15s; font-size: 9px; }
.mem-folder[open] > summary::before { transform: rotate(90deg); }
.mem-count { margin-left: auto; opacity: 0.6; font-weight: 500; }

.mem-item {
  display: flex; align-items: center; gap: 6px; width: 100%;
  padding: 5px 8px 5px 20px; border: none; background: transparent; cursor: pointer;
  color: var(--text); font-size: 12.5px; text-align: left; border-radius: 8px;
  font-family: inherit;
}
.mem-item:hover { background: rgba(255, 255, 255, 0.06); }
.mem-item.active { background: rgba(10, 132, 255, 0.2); color: #9fceff; }
.mem-item .n { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mem-item .c { font-size: 10px; opacity: 0.55; }

.mem-note h3 { font-size: 15px; margin-bottom: 2px; letter-spacing: -0.01em; }
.mem-note .meta { font-size: 10.5px; color: var(--text-dim); margin-bottom: 10px; }
.mem-fact {
  display: flex; gap: 8px; align-items: flex-start; font-size: 12.5px;
  line-height: 1.45; padding: 6px 8px; border-radius: 8px;
}
.mem-fact:hover { background: rgba(255, 255, 255, 0.05); }
.mem-fact .x {
  background: none; border: none; color: var(--text-dim); cursor: pointer;
  font-size: 14px; line-height: 1; padding: 0 2px; opacity: 0; flex-shrink: 0;
}
.mem-fact:hover .x { opacity: 1; }
.mem-fact .x:hover { color: var(--bad); }
.mem-empty { font-size: 12px; color: var(--text-dim); line-height: 1.6; padding: 10px; }
.mem-empty code { background: rgba(255, 255, 255, 0.08); padding: 1px 5px; border-radius: 5px; }
.mem-del {
  margin-top: 12px; width: 100%; padding: 7px; font-size: 11.5px;
  border-radius: 10px; cursor: pointer; font-family: inherit;
  background: rgba(255, 69, 58, 0.12); border: 1px solid rgba(255, 69, 58, 0.3); color: #ff9f97;
}
.mem-del:hover { background: rgba(255, 69, 58, 0.22); }
.mem-hit { font-size: 12px; padding: 6px 8px; border-radius: 8px; cursor: pointer; }
.mem-hit:hover { background: rgba(255, 255, 255, 0.06); }
.mem-hit b { color: #9fceff; font-weight: 600; }

/* ---------- modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(5, 5, 10, 0.55); backdrop-filter: blur(8px);
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.modal {
  width: min(620px, 100%); max-height: 88vh; overflow-y: auto;
  border-radius: 26px; padding: 26px;
  background: rgba(16, 16, 20, 0.88);
}
.modal h2 { font-size: 22px; letter-spacing: -0.02em; }
.modal-sub { font-size: 13px; color: var(--text-dim); margin: 6px 0 18px; }
.form-grid { display: grid; grid-template-columns: 2fr 1fr 1fr; gap: 12px; margin-bottom: 16px; }
.form-grid label, .tag-field label { font-size: 12px; color: var(--text-dim); display: flex; flex-direction: column; gap: 6px; }
input, select {
  background: rgba(255, 255, 255, 0.07); border: 1px solid var(--border); border-radius: 12px;
  padding: 10px 12px; color: var(--text); font-size: 14px; outline: none; width: 100%;
}
input:focus, select:focus { border-color: var(--accent); }
select option { background: #1c1c28; }
.tag-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.tag-field { display: flex; flex-direction: column; gap: 6px; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; min-height: 8px; }
.tag-pill {
  display: inline-flex; align-items: center; gap: 6px;
  background: rgba(10, 132, 255, 0.18); color: #9fceff;
  border-radius: 999px; padding: 4px 10px; font-size: 12px;
}
.tag-pill button { background: none; border: none; color: inherit; cursor: pointer; font-size: 13px; padding: 0; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 22px; }

.hidden { display: none !important; }

/* ---------- responsive ---------- */
@media (max-width: 1100px) {
  .layout { grid-template-columns: 1fr; height: auto; }
  .camera-card { min-height: 52vh; }
  .tiles { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .chat-card { height: 70vh; }
}
@media (max-width: 700px) {
  .layout { grid-template-columns: 1fr; }
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .tag-fields, .form-grid { grid-template-columns: 1fr; }
  .context-chips { order: 3; width: 100%; }
}

/* ---------- face enrolment + presence ---------- */
.face-enroll { margin-top: 16px; }
.face-enroll > label { font-size: 12px; color: var(--text-dim); display: block; margin-bottom: 8px; }
.face-hint { opacity: 0.7; font-style: italic; }
.face-row { display: flex; gap: 14px; align-items: flex-start; }
.face-shot {
  position: relative; width: 132px; height: 132px; flex-shrink: 0;
  border-radius: 16px; overflow: hidden; background: #000;
  border: 1px solid var(--border);
}
.face-shot video { width: 100%; height: 100%; object-fit: cover; transform: scaleX(-1); }
.face-badge {
  position: absolute; bottom: 6px; left: 6px; font-size: 10px; font-weight: 700;
  padding: 3px 8px; border-radius: 999px; background: rgba(0,0,0,0.6);
  text-transform: uppercase; letter-spacing: 0.04em;
}
.face-badge.live { background: rgba(48,209,88,0.85); color: #04210d; }
.face-side { flex: 1; display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.face-step { font-size: 13px; line-height: 1.45; min-height: 34px; }
.face-dots { display: flex; gap: 6px; }
.face-dots i {
  width: 26px; height: 5px; border-radius: 3px; background: rgba(255,255,255,0.14);
  transition: background 0.25s;
}
.face-dots i.done { background: var(--good); }
.face-dots i.active { background: var(--accent); }
.face-people { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 2px; }
.face-chip {
  display: inline-flex; align-items: center; gap: 6px; font-size: 11.5px;
  background: rgba(10,132,255,0.16); color: #9fceff; padding: 3px 10px; border-radius: 999px;
}
.face-chip button { background: none; border: none; color: inherit; cursor: pointer; font-size: 13px; padding: 0; }
.face-chip button:hover { color: var(--bad); }
.face-chip.primary { background: rgba(48,209,88,0.16); color: #7ce39a; }

#card-who .status-sub { white-space: normal; }
.who-line { display: flex; align-items: center; gap: 5px; font-size: 11.5px; }
.who-line .eye { font-size: 11px; }


/* what the server actually stored, shown after Save */
.save-report {
  margin: 14px 0 4px;
  padding: 12px 14px;
  border-radius: 12px;
  font-size: 13px;
  line-height: 1.55;
  border: 1px solid rgba(255, 255, 255, .08);
  background: rgba(255, 255, 255, .03);
}
.save-report p { margin: 0 0 8px; font-weight: 600; }
.save-report ul { margin: 0; padding-left: 18px; }
.save-report li { margin: 2px 0; }
.save-report li.unset { opacity: .55; }
.save-report li.warn { color: #ffcf6b; }
.save-report li i { opacity: .7; }
.save-report.good { border-color: rgba(64, 156, 255, .45); }
.save-report.warn { border-color: rgba(255, 207, 107, .5); }
.save-report.bad { border-color: rgba(255, 107, 107, .55); color: #ff9c9c; }


/* whose profile is being edited, and who CareMate is talking to */
.who-picker {
  display: block;
  margin: 0 0 16px;
  font-size: 12px;
  letter-spacing: .04em;
  text-transform: uppercase;
  opacity: .75;
}
.who-picker select {
  display: block;
  width: 100%;
  margin: 6px 0 4px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, .12);
  background: rgba(255, 255, 255, .04);
  color: inherit;
  font: inherit;
  text-transform: none;
  letter-spacing: 0;
}
.who-picker .face-hint { text-transform: none; letter-spacing: 0; }
.tag.tag-guest {
  background: rgba(255, 176, 32, .16);
  border-color: rgba(255, 176, 32, .45);
  color: #ffc978;
}


/* housekeeping, not something CareMate said */
.msg.note {
  align-self: center;
  max-width: 92%;
  background: none;
  border: 1px dashed rgba(255, 255, 255, .14);
  color: rgba(255, 255, 255, .55);
  font-size: 11.5px;
  text-align: center;
  padding: 6px 12px;
  border-radius: 999px;
}

/* heart-rate card: the pulse itself, drawn under the number */
.pulse-wave {
  display: block;
  width: 100%;
  height: 36px;
  margin: 8px 0 2px;
  opacity: .9;
}
