:root {
  --teal: #14746f;
  --teal-dark: #0f3d3a;
  --teal-soft: #e3f1ef;
  --ink: #14201f;
  --muted: #5d6b6a;
  --line: #d8e2e0;
  --bg: #f3f7f6;
  --bubble-bot: #ffffff;
  --bubble-user: #14746f;
  --urgent: #d64545;
  --monitor: #e0a100;
  --routine: #2e9e6b;
  --radius: 16px;
  --tap: 52px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

/* iOS standalone: pin to the real webview height so there's no dead space. */
html {
  height: -webkit-fill-available;
}
body {
  min-height: 100%;
  min-height: -webkit-fill-available;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  font-size: 17px;
  line-height: 1.4;
  overscroll-behavior-y: none;
}

.app {
  display: flex;
  flex-direction: column;
  /* height:100% off the html/body chain is reliable in an installed PWA;
     100dvh can under-shoot in iOS standalone and leave a gap at the bottom. */
  height: 100%;
  min-height: 100%;
  max-width: 560px;
  margin: 0 auto;
  background: var(--bg);
  overflow: hidden;
}

button {
  font-family: inherit;
  font-size: 17px;
  cursor: pointer;
  border: none;
  -webkit-tap-highlight-color: transparent;
}

/* ---------- App bar ---------- */
.appbar {
  flex: 0 0 auto;
  background: var(--teal);
  color: #fff;
  padding: calc(env(safe-area-inset-top, 0px) + 12px) 16px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.12);
  z-index: 5;
}
.appbar h1 {
  font-size: 18px;
  margin: 0;
  font-weight: 700;
}
.appbar .who {
  font-size: 13px;
  opacity: 0.92;
  margin-top: 2px;
}
.appbar .who-change {
  background: none;
  color: #fff;
  text-decoration: underline;
  font-size: 13px;
  padding: 2px 2px;
  min-height: 0;
  opacity: 0.95;
}
.appbar .restart {
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
  border-radius: 999px;
  padding: 8px 16px;
  font-size: 14px;
  min-height: 40px;
  white-space: nowrap;
}
.appbar .restart:active { background: rgba(255, 255, 255, 0.28); }

/* ---------- Generic content ---------- */
.scroll {
  flex: 1 1 auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 16px 16px 8px;
}

.center-pad {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 24px 20px calc(24px + var(--safe-bottom));
  display: flex;
  flex-direction: column;
  justify-content: center;
}

/* ---------- Identity screen ---------- */
.identity h2 {
  font-size: 24px;
  margin: 0 0 6px;
}
.identity p {
  color: var(--muted);
  margin: 0 0 24px;
}
.identity .names {
  display: grid;
  gap: 14px;
}
.name-btn {
  background: #fff;
  border: 2px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  font-size: 20px;
  font-weight: 600;
  color: var(--ink);
  min-height: 72px;
  display: flex;
  align-items: center;
  gap: 14px;
  transition: border-color 0.12s, background 0.12s;
}
.name-btn:active {
  border-color: var(--teal);
  background: var(--teal-soft);
}
.name-btn .avatar {
  width: 40px;
  height: 40px;
  border-radius: 999px;
  background: var(--teal);
  color: #fff;
  display: grid;
  place-items: center;
  font-size: 18px;
  font-weight: 700;
}

/* ---------- Home / start ---------- */
.home h2 {
  font-size: 22px;
  margin: 0 0 8px;
}
.home p {
  color: var(--muted);
  margin: 0 0 28px;
}

/* ---------- Chat ---------- */
.chat-progress {
  flex: 0 0 auto;
  height: 4px;
  background: var(--line);
}
.chat-progress > span {
  display: block;
  height: 100%;
  background: var(--teal);
  width: 0;
  transition: width 0.25s ease;
}

.divider {
  text-align: center;
  margin: 14px 0 6px;
}
.divider span {
  display: inline-block;
  background: var(--teal-soft);
  color: var(--teal-dark);
  font-size: 13px;
  font-weight: 600;
  padding: 6px 14px;
  border-radius: 999px;
}

.bubble {
  max-width: 86%;
  padding: 12px 14px;
  border-radius: 18px;
  margin: 6px 0;
  white-space: pre-wrap;
  word-wrap: break-word;
  animation: pop 0.18s ease;
}
@keyframes pop {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}
.bubble.bot {
  background: var(--bubble-bot);
  border: 1px solid var(--line);
  border-bottom-left-radius: 6px;
  align-self: flex-start;
}
.bubble.user {
  background: var(--bubble-user);
  color: #fff;
  border-bottom-right-radius: 6px;
  align-self: flex-end;
}
.turns {
  display: flex;
  flex-direction: column;
}

/* ---------- Input dock ---------- */
.dock {
  flex: 0 0 auto;
  background: #fff;
  border-top: 1px solid var(--line);
  padding: 12px 14px calc(12px + var(--safe-bottom));
  box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.04);
}
.dock .hint {
  font-size: 13px;
  color: var(--muted);
  margin: 0 0 10px;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 12px;
  max-height: 46vh;
  overflow-y: auto;
}
.chip {
  background: #fff;
  border: 1.5px solid var(--line);
  border-radius: 999px;
  padding: 8px 13px;
  font-size: 14px;
  color: var(--ink);
  min-height: 36px;
}
.chip[aria-pressed="true"] {
  background: var(--teal);
  border-color: var(--teal);
  color: #fff;
}
.chip.other[aria-pressed="true"] {
  background: var(--teal-dark);
  border-color: var(--teal-dark);
}

.concerns {
  display: grid;
  gap: 10px;
  margin-bottom: 12px;
}
.concern-btn {
  text-align: left;
  border: 2px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  background: #fff;
  min-height: var(--tap);
}
.concern-btn .lvl { font-weight: 700; display: block; }
.concern-btn .desc { font-size: 13px; color: var(--muted); margin-top: 2px; display: block; }
.concern-btn[aria-pressed="true"] { background: var(--teal-soft); }
.concern-btn.urgent[aria-pressed="true"] { border-color: var(--urgent); }
.concern-btn.monitor[aria-pressed="true"] { border-color: var(--monitor); }
.concern-btn.routine[aria-pressed="true"] { border-color: var(--routine); }

textarea, input[type="text"] {
  width: 100%;
  border: 1.5px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 16px;
  font-family: inherit;
  color: var(--ink);
  resize: vertical;
  margin-bottom: 12px;
  background: #fff;
}
textarea:focus, input[type="text"]:focus {
  outline: none;
  border-color: var(--teal);
}
.field-extra { margin-bottom: 12px; }
.field-extra label {
  display: block;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 6px;
}

.dock-actions {
  display: flex;
  gap: 10px;
}
.btn {
  flex: 1 1 auto;
  min-height: var(--tap);
  border-radius: 12px;
  font-weight: 600;
  font-size: 17px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.btn-primary {
  background: var(--teal);
  color: #fff;
}
.btn-primary:disabled {
  background: #a9c5c2;
  color: #eef5f4;
}
.btn-primary:active:not(:disabled) { background: var(--teal-dark); }
.btn-ghost {
  background: #fff;
  border: 1.5px solid var(--line);
  color: var(--ink);
  flex: 0 0 auto;
  padding: 0 18px;
}
.btn-ghost:active { background: var(--teal-soft); }
.btn-block { width: 100%; }
.error {
  color: var(--urgent);
  font-size: 14px;
  margin: 0 0 10px;
  min-height: 0;
}

/* ---------- Review ---------- */
.review h2 { font-size: 22px; margin: 4px 0 4px; }
.review .sub { color: var(--muted); margin: 0 0 18px; }
.review-card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 14px;
}
.review-card h3 {
  margin: 0 0 10px;
  font-size: 17px;
}
.review-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 9px 0;
  border-top: 1px solid var(--line);
}
.review-row:first-of-type { border-top: none; }
.review-row .rl { color: var(--muted); font-size: 14px; flex: 0 0 38%; }
.review-row .rv { font-size: 15px; flex: 1 1 auto; }
.review-row .edit {
  background: none;
  color: var(--teal);
  font-size: 14px;
  font-weight: 600;
  padding: 0 0 0 8px;
  flex: 0 0 auto;
}
.preview {
  background: #fff;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 16px;
  white-space: pre-wrap;
  font-size: 14px;
  color: var(--ink);
  max-height: 38vh;
  overflow-y: auto;
}
.preview-label {
  font-size: 13px;
  color: var(--muted);
  margin: 8px 0 6px;
  font-weight: 600;
}

/* ---------- Sent ---------- */
.sent { text-align: center; }
.sent .big {
  width: 84px; height: 84px;
  border-radius: 999px;
  background: var(--teal-soft);
  color: var(--teal);
  font-size: 44px;
  display: grid; place-items: center;
  margin: 0 auto 18px;
}
.sent h2 { font-size: 24px; margin: 0 0 8px; }
.sent p { color: var(--muted); margin: 0 auto 24px; max-width: 320px; }

.note {
  background: #fff8e6;
  border: 1px solid #f0deaa;
  color: #6b551c;
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 14px;
  margin-bottom: 16px;
}
.stack { display: grid; gap: 10px; }

/* ---------- Install gate ---------- */
.install-gate h2 {
  font-size: 24px;
  margin: 0 0 8px;
}
.gate-lead {
  color: var(--muted);
  margin: 0 0 24px;
  font-size: 16px;
}

/* ---------- Install card ---------- */
.install {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 22px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
}
.install-head {
  display: flex;
  gap: 12px;
  align-items: flex-start;
}
.install-ico {
  font-size: 26px;
  line-height: 1;
  flex: 0 0 auto;
}
.install-head strong {
  font-size: 17px;
  color: var(--ink);
}
.install-sub {
  margin: 4px 0 0;
  font-size: 14px;
  color: var(--muted);
}
.install-steps {
  margin: 12px 0 4px;
  padding-left: 22px;
  font-size: 14px;
  color: var(--ink);
}
.install-steps li { margin: 6px 0; }
.install-actions {
  display: flex;
  gap: 10px;
  margin-top: 14px;
}
.install-actions .btn { flex: 1 1 auto; }

/* ---------- Build-the-summary screen ---------- */
.summary { padding-bottom: 4px; }
.sum-head {
  display: flex;
  gap: 16px;
  justify-content: center;
  flex-wrap: wrap;
  color: var(--muted);
  font-size: 13px;
  margin: 0 0 12px;
}
.sum-empty {
  color: var(--muted);
  text-align: center;
  font-size: 15px;
  margin: 24px 0;
}
.sum-card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 4px 14px 8px;
  margin-bottom: 12px;
}
.sum-resident {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 18px;
  font-weight: 800;
  color: var(--teal-dark);
  padding: 12px 0 10px;
  border-bottom: 1px solid var(--line);
}
.sum-avatar {
  width: 32px; height: 32px;
  border-radius: 999px;
  background: var(--teal-soft);
  display: grid; place-items: center;
  font-size: 18px;
  flex: 0 0 auto;
}
.sum-name { min-width: 0; }
.sum-badge {
  margin-left: auto;
  flex: 0 0 auto;
  font-size: 12px;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 999px;
  white-space: nowrap;
}
.sum-badge.routine { background: #e4f4ec; color: var(--routine); }
.sum-badge.monitor { background: #fbf0d2; color: #9a7400; }
.sum-badge.urgent  { background: #fbe3e3; color: var(--urgent); }
.sum-row {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 9px 0;
  border-top: 1px solid var(--line);
}
.sum-row:first-of-type { border-top: none; }
.sum-row.editing {
  background: var(--teal-soft);
  border-top-color: transparent;
  border-radius: 10px;
  margin: 2px -8px;
  padding: 9px 8px;
}
.sum-row.editing + .sum-row { border-top-color: transparent; }
.sum-editing {
  flex: 0 0 auto;
  color: var(--teal);
  font-weight: 600;
  font-size: 13px;
  font-style: italic;
}
.sum-l { flex: 0 0 32%; color: var(--muted); font-size: 13px; }
.sum-v { flex: 1 1 auto; font-size: 15px; }
.sum-edit {
  flex: 0 0 auto;
  background: none;
  color: var(--teal);
  font-weight: 600;
  font-size: 14px;
  padding: 4px 4px 4px 8px;
  min-height: 32px;
}

/* Pinned question on top of the options */
.askdock {
  flex: 0 0 auto;
  background: #fff;
  border-top: 1px solid var(--line);
  box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.07);
}
.ask {
  padding: 14px 16px 2px;
}
.ask-resident {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 16px;
  font-weight: 800;
  color: var(--teal);
}
.ask-avatar {
  width: 36px; height: 36px;
  border-radius: 999px;
  background: var(--teal-soft);
  display: grid; place-items: center;
  font-size: 20px;
}
.ask-q {
  font-size: 21px;
  line-height: 1.3;
  font-weight: 700;
  color: var(--ink);
  margin-top: 10px;
}
.askdock > .dock {
  border-top: none;
  box-shadow: none;
  padding-top: 10px;
}

/* ---------- Confirmation modal ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 61, 58, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 100;
  animation: fade 0.15s ease;
}
@keyframes fade {
  from { opacity: 0; }
  to { opacity: 1; }
}
.modal {
  background: #fff;
  border-radius: var(--radius);
  padding: 22px 20px;
  width: 100%;
  max-width: 360px;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.28);
}
.modal-title {
  margin: 0 0 8px;
  font-size: 19px;
}
.modal-body {
  margin: 0 0 20px;
  font-size: 15px;
  color: var(--muted);
}
.modal-actions {
  display: flex;
  gap: 10px;
}
.modal-actions .btn {
  flex: 1 1 auto;
  min-height: 50px;
}
.btn-danger {
  background: var(--urgent);
  color: #fff;
}
.btn-danger:active { background: #b83a3a; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + var(--safe-bottom));
  transform: translateX(-50%) translateY(20px);
  background: var(--ink);
  color: #fff;
  padding: 12px 18px;
  border-radius: 999px;
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 50;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
