/* ============================================================
   Health Agent PWA — Soft Light Medical Theme
   ============================================================ */
:root {
  --bg: #f8faff;
  --bg-soft: #ffffff;
  --surface: #ffffff;
  --border: #e2e8f0;
  --text: #1a2444;
  --dim: #7c8ab5;
  --accent: #5b7fff;
  --accent-dim: #4a6ae8;
  --accent-soft: #eef1ff;
  --pink: #f472b6;
  --pink-soft: #fce7f3;
  --green: #22c55e;
  --yellow: #f59e0b;
  --red: #ef4444;
  --radius: 14px;
  --shadow: 0 2px 12px rgba(91, 127, 255, 0.08);
  --header-bg: linear-gradient(135deg, #f8faff, #eef1ff);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Noto Sans SC', sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100dvh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  -webkit-user-select: none;
  user-select: none;
}

/* ── Tab Bar ── */
.tab-bar {
  display: flex;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  box-shadow: 0 1px 4px rgba(0,0,0,0.02);
}
.tab-btn {
  flex: 1;
  padding: 12px 8px 8px;
  text-align: center;
  font-size: 12px;
  font-weight: 600;
  color: var(--dim);
  background: none;
  border: none;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  position: relative;
}
.tab-btn svg { width: 22px; height: 22px; }
.tab-btn.active { color: var(--accent); }
.tab-btn.active::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 20%; right: 20%;
  height: 2.5px;
  background: linear-gradient(90deg, var(--accent), var(--pink));
  border-radius: 2px;
}
.tab-btn:active { opacity: 0.6; }

/* ── Views ── */
.view { display: none; flex: 1; flex-direction: column; overflow: hidden; }
.view.active { display: flex; }

/* ── Chat View ── */
.chat-header {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 16px;
  background: var(--header-bg);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.chat-header .avatar {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--pink));
  display: flex; align-items: center; justify-content: center;
  font-size: 16px;
  color: white;
  box-shadow: 0 2px 8px rgba(91, 127, 255, 0.25);
}
.chat-header h1 { font-size: 16px; font-weight: 700; flex: 1; color: var(--text); }
.chat-header .status {
  font-size: 11px; color: var(--dim);
  display: flex; align-items: center; gap: 4px;
}
.chat-header .dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--dim);
}
.chat-header .dot.on { background: var(--green); box-shadow: 0 0 6px var(--green); }

.messages {
  flex: 1; overflow-y: auto; padding: 12px 16px;
  display: flex; flex-direction: column; gap: 10px;
}
.msg {
  max-width: 88%; padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 14px; line-height: 1.65;
  animation: fadeIn 0.25s;
}
.msg.user {
  background: linear-gradient(135deg, #eef1ff, #fce7f3);
  color: var(--text);
  align-self: flex-end;
  border-bottom-right-radius: 4px;
  box-shadow: 0 1px 4px rgba(91, 127, 255, 0.08);
}
.msg.assistant {
  background: var(--surface);
  border: 1px solid var(--border);
  align-self: flex-start;
  border-bottom-left-radius: 4px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.02);
}
.msg.system {
  background: transparent;
  align-self: center;
  color: var(--dim);
  font-size: 12px;
  border: 1px solid var(--border);
  padding: 6px 14px;
}
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
.msg .time { font-size: 11px; color: var(--dim); margin-top: 6px; }

/* Measurement card */
.meas-card {
  background: linear-gradient(135deg, #eef1ff, #fce7f3);
  border: 1px solid #dbe4ff;
  border-radius: var(--radius);
  padding: 14px; margin: 6px 0;
}
.meas-card .value { font-size: 28px; font-weight: 700; color: var(--accent); }
.meas-card .unit { font-size: 13px; color: var(--dim); margin-left: 4px; }
.meas-card .meta {
  font-size: 12px; color: var(--dim); margin-top: 6px;
  display: flex; gap: 12px; flex-wrap: wrap;
}

/* Lottie waiting animation */
.meas-wait {
  display: flex; align-items: center; gap: 12px;
  padding: 12px;
  background: linear-gradient(135deg, #eef1ff, #fce7f3);
  border: 1px solid #dbe4ff;
  border-radius: var(--radius);
}
.meas-wait .lottie-box { width: 80px; height: 80px; flex-shrink: 0; }
.meas-wait .msg-text { font-size: 14px; font-weight: 600; color: var(--text); }
.meas-wait .msg-sub { font-size: 12px; color: var(--dim); margin-top: 2px; }
.dots::after { content: ''; animation: dotAnim 1.5s infinite; }
@keyframes dotAnim { 0%,20%{content:'.'}40%{content:'..'}60%,100%{content:'...'} }

/* Input area */
.input-area {
  display: flex; gap: 8px;
  padding: 10px 12px 14px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
.input-area input {
  flex: 1;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 24px;
  padding: 10px 16px;
  color: var(--text);
  font-size: 14px;
  outline: none;
  transition: border-color 0.2s;
}
.input-area input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(91, 127, 255, 0.1); }
.send-btn {
  width: 40px; height: 40px;
  border-radius: 50%;
  border: none;
  background: linear-gradient(135deg, var(--accent), var(--pink));
  color: white;
  font-size: 18px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  transition: opacity 0.2s;
  box-shadow: 0 2px 8px rgba(91, 127, 255, 0.25);
}
.send-btn:disabled { opacity: 0.4; cursor: not-allowed; box-shadow: none; }
.send-btn:active { opacity: 0.8; }

/* Quick actions */
.quick-actions {
  padding: 8px 12px;
  display: flex; gap: 8px; overflow-x: auto;
  flex-shrink: 0;
}
.quick-actions button {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 6px 14px;
  color: var(--text);
  font-size: 12px;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  transition: all 0.2s;
  box-shadow: 0 1px 3px rgba(0,0,0,0.02);
}
.quick-actions button:active {
  background: var(--accent-soft);
  border-color: var(--accent);
}

/* ── Dashboard ── */
.dash-scroll { flex: 1; overflow-y: auto; padding: 16px; }

/* Device card */
.device-card {
  background: linear-gradient(135deg, #eef1ff, #fce7f3);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
  display: flex; align-items: center; gap: 14px;
}
.device-card .icon {
  width: 48px; height: 48px; border-radius: 50%;
  background: var(--surface);
  display: flex; align-items: center; justify-content: center;
  font-size: 24px;
  box-shadow: 0 2px 8px rgba(91, 127, 255, 0.12);
}
.device-card .info { flex: 1; }
.device-card .name { font-size: 16px; font-weight: 700; }
.device-card .detail { font-size: 12px; color: var(--dim); margin-top: 2px; }
.device-card .btn-connect {
  padding: 8px 16px; border-radius: 20px; border: none;
  background: linear-gradient(135deg, var(--accent), var(--pink));
  color: white; font-size: 13px; font-weight: 600;
  cursor: pointer; box-shadow: 0 2px 8px rgba(91, 127, 255, 0.2);
}
.device-card .btn-connect:active { opacity: 0.8; }

.dash-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 12px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.02);
}
.dash-card h3 {
  font-size: 13px; font-weight: 700; margin-bottom: 10px;
  display: flex; align-items: center; gap: 6px;
  color: var(--dim);
  text-transform: uppercase;
  letter-spacing: 0.3px;
}
.dash-row { display: flex; justify-content: space-between; padding: 5px 0; font-size: 13px; border-bottom: 1px solid #f1f4f9; }
.dash-row:last-child { border-bottom: none; }
.dash-row .label { color: var(--dim); }
.dash-row .val { font-weight: 600; }
.status-ok { color: var(--green); }
.status-warn { color: var(--yellow); }
.status-bad { color: var(--red); }

.stats-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 8px;
}
.stat-box {
  background: var(--bg);
  border-radius: 10px;
  padding: 12px; text-align: center;
}
.stat-box .num { font-size: 22px; font-weight: 700; color: var(--accent); }
.stat-box .label { font-size: 11px; color: var(--dim); margin-top: 2px; }

/* ── History View ── */
.history-view-header {
  padding: 12px 16px;
  background: var(--header-bg);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.history-view-header h2 { font-size: 16px; font-weight: 700; }

.history-list { flex: 1; overflow-y: auto; padding: 16px; }
.history-item {
  padding: 10px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 8px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.02);
}
.history-item .top { display: flex; justify-content: space-between; font-size: 12px; color: var(--dim); }
.history-item .conc { font-size: 18px; font-weight: 700; color: var(--accent); margin: 4px 0; }
.history-item .detail { font-size: 12px; color: var(--dim); }

/* ── Settings ── */
.settings-scroll { flex: 1; overflow-y: auto; padding: 16px; }
.setting-group { margin-bottom: 20px; }
.setting-group h3 {
  font-size: 12px; color: var(--dim);
  text-transform: uppercase; letter-spacing: 0.5px;
  margin-bottom: 8px; padding-left: 4px;
}
.setting-item {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 6px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.02);
}
.setting-item .label { font-size: 14px; font-weight: 500; }
.setting-item .desc { font-size: 12px; color: var(--dim); margin-top: 2px; }
.setting-item input, .setting-item select {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 10px;
  color: var(--text);
  font-size: 13px;
  width: 160px;
  outline: none;
}
.setting-item input:focus { border-color: var(--accent); }

/* ── Utility ── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px;
  border-radius: 10px;
  border: none;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}
.btn:active { opacity: 0.7; }
.btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--pink));
  color: white; box-shadow: 0 2px 8px rgba(91, 127, 255, 0.2);
}
.btn-outline { background: transparent; border: 1px solid var(--border); color: var(--text); }

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 3px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
