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

:root {
  --bg: #f5f3ef;
  --header: #1d2733;
  --accent: #3f8efc;
  --green: #2fbf71;
  --red: #e5484d;
  --bubble-user: #3f8efc;
  --bubble-agent: #ffffff;
}

html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  height: 100dvh;
}

header {
  background: var(--header);
  color: #fff;
  padding: calc(env(safe-area-inset-top) + 12px) 16px 12px;
  flex: none;
}
.header-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.logo { font-size: 18px; font-weight: 700; letter-spacing: 0.5px; }
.logo span { font-weight: 300; opacity: 0.85; }
.device-title { font-size: 13px; opacity: 0.7; margin-top: 2px; }

.status-btn {
  flex: none;
  background: rgba(255,255,255,0.14);
  color: #fff;
  border: 1px solid rgba(255,255,255,0.3);
  border-radius: 999px;
  padding: 7px 13px;
  font-size: 13px;
  white-space: nowrap;
}

/* --- Activation / device-status modal --- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(20, 25, 32, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 50;
}
.modal {
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 8px 30px rgba(0,0,0,0.25);
  width: 100%;
  max-width: 400px;
  max-height: 90dvh;
  overflow-y: auto;
  padding: 22px 20px 18px;
}
.modal h2 { font-size: 19px; font-weight: 700; }
.modal-device { font-size: 13px; color: #7a7f87; margin-top: 3px; }

.modal-status { margin: 16px 0 0; }
.modal-status .lights-card { max-width: 100%; margin: 0; box-shadow: none; background: #f7f5f1; }
.modal-loading { color: #8b9098; font-size: 14px; padding: 10px 0; }

.modal-note { font-size: 13px; color: #7a7f87; margin-top: 12px; line-height: 1.45; }

.modal-actions { display: flex; gap: 10px; margin-top: 18px; }
.modal-actions button { flex: 1; border: 0; border-radius: 10px; padding: 13px 14px; font-size: 15px; font-weight: 600; }
.btn-primary { background: var(--green); color: #fff; }
.btn-primary:disabled { opacity: 0.6; }
.btn-secondary { background: #eceae5; color: #4a4f57; }

.activate-bar {
  flex: none;
  background: #fff7e0;
  border-bottom: 1px solid #eadfb8;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 14px;
}
.activate-bar button {
  background: var(--green);
  color: #fff;
  border: 0;
  border-radius: 8px;
  padding: 10px 16px;
  font-size: 15px;
  font-weight: 600;
  white-space: nowrap;
}
.activate-bar button:disabled { opacity: 0.6; }

main {
  flex: 1;
  overflow-y: auto;
  padding: 16px 12px 8px;
  -webkit-overflow-scrolling: touch;
}

.msg {
  max-width: 85%;
  margin-bottom: 10px;
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 15px;
  line-height: 1.45;
  white-space: pre-wrap;
  word-wrap: break-word;
}
.msg.agent { background: var(--bubble-agent); border-bottom-left-radius: 4px; box-shadow: 0 1px 2px rgba(0,0,0,0.06); }
.msg.user { background: var(--bubble-user); color: #fff; margin-left: auto; border-bottom-right-radius: 4px; }
.msg.notice { background: transparent; color: #7a7f87; font-size: 13px; text-align: center; max-width: 100%; box-shadow: none; }

.typing { display: inline-block; color: #9aa0a8; }
.typing::after { content: '…'; animation: blink 1.2s infinite; }
@keyframes blink { 50% { opacity: 0.3; } }

.lights-card {
  background: #fff;
  border-radius: 14px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
  padding: 14px 16px;
  margin: 4px 0 12px;
  max-width: 85%;
}
.lights-card h4 { font-size: 13px; text-transform: uppercase; letter-spacing: 0.6px; color: #7a7f87; margin-bottom: 10px; }
.light-row { display: flex; align-items: center; gap: 10px; padding: 5px 0; font-size: 15px; }
.dot { width: 13px; height: 13px; border-radius: 50%; flex: none; }
.dot.green { background: var(--green); box-shadow: 0 0 6px rgba(47,191,113,0.6); }
.dot.red { background: var(--red); box-shadow: 0 0 6px rgba(229,72,77,0.5); }
.dot.unknown { background: #c9ccd1; }
.light-note { color: #9aa0a8; font-size: 13px; }

.options-bar {
  flex: none;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 0 12px 8px;
}
.options-bar button {
  background: #fff;
  border: 1.5px solid var(--accent);
  color: var(--accent);
  border-radius: 999px;
  padding: 9px 16px;
  font-size: 15px;
  font-weight: 500;
}
.options-bar button:disabled { opacity: 0.45; }

footer {
  flex: none;
  background: #fff;
  border-top: 1px solid #e5e2dc;
  padding: 10px 12px calc(env(safe-area-inset-bottom) + 10px);
}
.composer-label { font-size: 13px; color: #5c626a; margin-bottom: 7px; font-weight: 600; }
#composer { display: flex; gap: 8px; }
#input {
  flex: 1;
  border: 1.5px solid #d8d4cc;
  border-radius: 999px;
  padding: 11px 16px;
  font-size: 16px;
  outline: none;
}
#input:focus { border-color: var(--accent); }
#send-btn {
  background: var(--accent);
  color: #fff;
  border: 0;
  border-radius: 50%;
  width: 44px;
  height: 44px;
  font-size: 17px;
  flex: none;
}
#send-btn:disabled { opacity: 0.5; }

.hidden { display: none !important; }
