:root {
  --ink: #12261f;
  --paper: #f6f4ee;
  --teal: #0b4f42;
  --teal-light: #e4efe9;
  --gold: #d9a441;
  --line: #d8d2c3;
  --danger: #a4402f;
  --bubble-user: #0b4f42;
  --bubble-agent: #ffffff;
  font-size: 16px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--paper);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  /* system fonts only: no font downloads needed on slow/rural connections */
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  max-width: 480px;
  margin: 0 auto;
  background: var(--paper);
}

header {
  background: var(--teal);
  color: white;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-shrink: 0;
}

header .brand {
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: 0.2px;
}
header .brand small {
  display: block;
  font-weight: 400;
  font-size: 0.7rem;
  opacity: 0.8;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.back-btn {
  background: rgba(255,255,255,0.15);
  border: none;
  color: white;
  font-size: 1.2rem;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  flex-shrink: 0;
  line-height: 1;
}
.back-btn.hidden { display: none; }
.back-btn:active { background: rgba(255,255,255,0.3); }

.status-pill {
  font-size: 0.72rem;
  padding: 4px 9px;
  border-radius: 20px;
  font-weight: 600;
  white-space: nowrap;
}
.status-wifi, .status-data { background: #1f7a5c; color: white; }
.status-sms { background: var(--gold); color: #4a3200; }
.status-offline { background: var(--danger); color: white; }

.hidden { display: none !important; }

.patient-header {
  background: white;
  border-bottom: 1px solid var(--line);
  padding: 10px 14px;
  flex-shrink: 0;
}
.patient-header-name {
  font-weight: 700;
  font-size: 1rem;
  color: var(--teal);
}
.patient-header-meta {
  font-size: 0.78rem;
  color: #5a5346;
  margin-top: 1px;
}
.patient-header-participants {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 6px;
}
.participant-chip {
  font-size: 0.7rem;
  background: var(--teal-light);
  color: var(--teal);
  padding: 3px 9px;
  border-radius: 12px;
  font-weight: 600;
}

.home-view {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
}
.home-section-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: #8a8270;
  font-weight: 700;
  margin: 14px 4px 6px;
}
.home-section-label:first-child { margin-top: 0; }

.home-item {
  background: white;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
  margin-bottom: 8px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.home-item:active { background: var(--teal-light); }
.home-item .title { font-weight: 700; font-size: 0.92rem; }
.home-item .subtitle { font-size: 0.76rem; color: #8a8270; margin-top: 2px; }
.home-item .badge {
  font-size: 0.68rem;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 10px;
  flex-shrink: 0;
  margin-left: 8px;
}
.badge.active { background: #e4efe9; color: #1f7a5c; }
.badge.exited { background: #efece2; color: #8a8270; }

.login-bar {
  display: flex;
  gap: 6px;
  padding: 8px 12px;
  background: var(--teal-light);
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
  align-items: center;
  font-size: 0.8rem;
}
.login-bar select {
  flex: 1;
  padding: 6px 8px;
  border-radius: 8px;
  border: 1px solid var(--line);
  font-size: 0.85rem;
}

#thread {
  flex: 1;
  overflow-y: auto;
  padding: 14px 12px 8px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.bubble-row { display: flex; }
.bubble-row.user { justify-content: flex-end; }
.bubble-row.agent { justify-content: flex-start; }

.bubble {
  max-width: 82%;
  padding: 10px 13px;
  border-radius: 14px;
  font-size: 0.92rem;
  line-height: 1.42;
  white-space: pre-wrap;
  word-wrap: break-word;
}
.bubble.user {
  background: var(--bubble-user);
  color: white;
  border-bottom-right-radius: 4px;
}
.bubble.agent {
  background: var(--bubble-agent);
  border: 1px solid var(--line);
  border-bottom-left-radius: 4px;
}
.bubble.system {
  background: transparent;
  border: 1px dashed var(--line);
  color: #5a5346;
  font-size: 0.78rem;
  margin: 0 auto;
  text-align: center;
}

.quickbar {
  display: flex;
  gap: 6px;
  padding: 8px 10px;
  overflow-x: auto;
  border-top: 1px solid var(--line);
  background: var(--paper);
  flex-shrink: 0;
}
.quickbar button {
  flex-shrink: 0;
  background: white;
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 6px 12px;
  font-size: 0.78rem;
  color: var(--teal);
  font-weight: 600;
}
.quickbar button:active { background: var(--teal-light); }

form#composer {
  display: flex;
  gap: 8px;
  padding: 10px 12px 14px;
  border-top: 1px solid var(--line);
  background: var(--paper);
  flex-shrink: 0;
}
#composer input {
  flex: 1;
  padding: 12px 14px;
  border-radius: 22px;
  border: 1px solid var(--line);
  font-size: 0.95rem;
  background: white;
}
#composer button {
  background: var(--teal);
  color: white;
  border: none;
  border-radius: 22px;
  padding: 0 20px;
  font-weight: 700;
  font-size: 0.9rem;
}
#composer button:disabled { opacity: 0.5; }

::placeholder { color: #9c9585; }
