@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@600;700&family=Inter:wght@400;500;600&display=swap');

:root {
  --bg: #12141C;
  --bg-raised: #1B1E29;
  --ink: #F0EDE6;
  --ink-dim: #9A9CAB;
  --amber: #E8A33D;
  --teal: #4FB0A8;
  --danger: #D9634A;
  --gray: #5A5D6B;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: 'Inter', sans-serif;
  overflow: hidden;
}

/* ---------- Floating bubble ---------- */
.bubble {
  position: fixed;
  width: 44px;
  height: 44px;
  right: 20px;
  bottom: 40px;
  z-index: 50;
  cursor: grab;
  touch-action: none;
  display: flex;
  align-items: center;
  justify-content: center;
}
.bubble:active { cursor: grabbing; }

.bubble-core {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: #FFFFFF;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 10px rgba(0,0,0,0.35), 0 0 0 1.5px rgba(0,0,0,0.15);
  position: relative;
  z-index: 2;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--teal);
  position: absolute;
  top: 1px;
  right: 1px;
  border: 2px solid #FFFFFF;
}
.status-dot.offline { background: var(--gray); }

.bubble-ring {
  position: absolute;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 2px solid #FFFFFF;
  opacity: 0;
  box-shadow: 0 0 0 1px rgba(0,0,0,0.15);
}

.bubble.active .bubble-ring {
  animation: wave 1.4s ease-out infinite;
}
.bubble.active .bubble-ring:nth-child(1) { animation-delay: 0s; }

@keyframes wave {
  0% { transform: scale(1); opacity: 0.7; }
  100% { transform: scale(1.9); opacity: 0; }
}

/* ---------- Expanded panel ---------- */
.panel {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 40;
  display: none;
  flex-direction: column;
}
.panel.open { display: flex; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: 'Space Grotesk', sans-serif;
  font-weight: 700;
  font-size: 17px;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--teal);
  box-shadow: 0 0 8px var(--teal);
}
.dot.offline { background: var(--gray); box-shadow: none; }

.topbar-actions { display: flex; gap: 8px; }

.icon-btn {
  background: none;
  border: 1px solid rgba(255,255,255,0.12);
  color: var(--ink-dim);
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 13px;
  cursor: pointer;
}
.icon-btn:hover { color: var(--ink); border-color: rgba(255,255,255,0.25); }
.icon-btn.on { color: var(--bg); background: var(--teal); border-color: var(--teal); }
.icon-btn:disabled { opacity: 0.4; cursor: not-allowed; }

.stage {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.msg {
  max-width: 80%;
  padding: 12px 16px;
  border-radius: 14px;
  font-size: 15px;
  line-height: 1.5;
  white-space: pre-wrap;
}

.msg.user {
  align-self: flex-end;
  background: var(--amber);
  color: #1A1300;
  border-bottom-right-radius: 4px;
}

.msg.agent {
  align-self: flex-start;
  background: var(--bg-raised);
  border-bottom-left-radius: 4px;
}

.msg.system {
  align-self: center;
  color: var(--ink-dim);
  font-size: 13px;
  text-align: center;
}

.msg.error {
  align-self: center;
  color: var(--danger);
  font-size: 13px;
}

.composer {
  display: flex;
  gap: 8px;
  padding: 16px 20px;
  padding-bottom: max(16px, env(safe-area-inset-bottom));
  border-top: 1px solid rgba(255,255,255,0.06);
}

#textInput {
  flex: 1;
  background: var(--bg-raised);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 12px;
  padding: 12px 14px;
  color: var(--ink);
  font-family: 'Inter', sans-serif;
  font-size: 15px;
  outline: none;
}
#textInput:focus { border-color: var(--amber); }

#sendBtn {
  background: var(--amber);
  border: none;
  color: #1A1300;
  font-weight: 600;
  padding: 0 20px;
  border-radius: 12px;
  cursor: pointer;
}
#sendBtn:disabled { opacity: 0.5; cursor: default; }

::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 3px; }

/* ---------- Install overlay (iOS instructions) ---------- */
.install-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 60;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.install-overlay.open { display: flex; }

.install-card {
  background: var(--bg-raised);
  border-radius: 16px;
  padding: 20px;
  max-width: 320px;
  border: 1px solid rgba(255,255,255,0.08);
}

.install-title {
  font-family: 'Space Grotesk', sans-serif;
  font-weight: 700;
  font-size: 16px;
  margin: 0 0 12px;
}

.install-step {
  font-size: 14px;
  color: var(--ink-dim);
  margin: 0 0 8px;
  line-height: 1.4;
}

#installOverlayClose {
  margin-top: 8px;
  width: 100%;
  text-align: center;
}

/* ---------- Settings & Activity panels ---------- */
.settings-card, .activity-card {
  max-width: 340px;
  width: 100%;
  max-height: 80vh;
  overflow-y: auto;
}

.settings-label {
  font-size: 13px;
  font-weight: 600;
  margin: 0 0 6px;
}

.settings-sublabel {
  font-weight: 400;
  color: var(--ink-dim);
  font-size: 11px;
}

.settings-row {
  display: flex;
  gap: 6px;
}

.settings-select {
  background: var(--bg-raised);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 8px;
  padding: 8px;
  color: var(--ink);
  font-size: 12px;
  flex: 0 0 40%;
}

.settings-input {
  background: var(--bg-raised);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 8px;
  padding: 8px;
  color: var(--ink);
  font-size: 12px;
  flex: 1;
  min-width: 0;
}

.settings-hint {
  font-size: 11px;
  color: var(--ink-dim);
  margin: 6px 0 0;
}

.save-btn {
  width: 100%;
  background: var(--amber);
  border: none;
  color: #1A1300;
  font-weight: 600;
  padding: 10px;
  border-radius: 10px;
  cursor: pointer;
  margin-top: 16px;
  font-size: 13px;
}

.activity-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 8px;
}

.activity-item {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 0;
  border-bottom: 0.5px solid rgba(255,255,255,0.06);
  font-size: 12px;
}

.activity-item .activity-text {
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.activity-item .activity-time {
  color: var(--ink-dim);
  flex-shrink: 0;
}

/* ---------- Idle glow, greeting, clock ---------- */
.bubble-glow {
  position: absolute;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: #FFFFFF;
  opacity: 0.25;
  filter: blur(10px);
  animation: breathe 3.4s ease-in-out infinite;
  z-index: 1;
}

@keyframes breathe {
  0%, 100% { transform: scale(1); opacity: 0.18; }
  50% { transform: scale(1.6); opacity: 0.32; }
}

.clock {
  position: fixed;
  bottom: 16px;
  left: 16px;
  font-family: 'Space Grotesk', sans-serif;
  font-size: 12px;
  color: rgba(240, 237, 230, 0.35);
  letter-spacing: 0.02em;
  z-index: 10;
}

.greeting {
  position: fixed;
  top: 40%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-family: 'Space Grotesk', sans-serif;
  font-size: 15px;
  color: rgba(240, 237, 230, 0.55);
  opacity: 0;
  z-index: 10;
  text-align: center;
  pointer-events: none;
}

.greeting.show {
  animation: greetingFade 4.5s ease-in-out forwards;
}

@keyframes greetingFade {
  0% { opacity: 0; }
  20% { opacity: 1; }
  75% { opacity: 1; }
  100% { opacity: 0; }
}

/* ---------- Login ---------- */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-card {
  background: var(--bg-raised);
  border-radius: 16px;
  padding: 24px;
  max-width: 300px;
  width: 100%;
  border: 1px solid rgba(255,255,255,0.08);
  text-align: center;
}

.login-error {
  color: var(--danger);
  font-size: 13px;
  margin: 0 0 10px;
}

.settings-textarea {
  width: 100%;
  min-height: 64px;
  resize: vertical;
  font-family: 'Inter', sans-serif;
}

.attach-btn {
  font-size: 20px;
  font-weight: 400;
  padding: 0 14px;
  line-height: 1;
}

.attachment-preview {
  padding: 0 20px;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.attachment-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-raised);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 8px;
  padding: 4px 8px;
  font-size: 12px;
  color: var(--ink-dim);
  margin-bottom: 8px;
}

.attachment-chip button {
  background: none;
  border: none;
  color: var(--ink-dim);
  cursor: pointer;
  font-size: 14px;
  padding: 0;
}

/* ---------- Idle art: heart + brains, glowing, rotating in 3D ---------- */
.idle-art {
  position: fixed;
  inset: 0;
  z-index: 1;
  overflow: hidden;
  perspective: 1400px;
  pointer-events: none;
}

.constellation-bg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  opacity: 0.7;
}

.idle-heart {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 20vmin;
  max-width: 160px;
  transform: translate(-50%, -50%);
  transform-style: preserve-3d;
  animation: idleSpin 15s linear infinite;
}

.idle-heart img {
  width: 100%;
  display: block;
  filter: drop-shadow(0 0 16px rgba(110, 200, 210, 0.55));
}

.idle-brain {
  position: absolute;
  width: 10vmin;
  max-width: 82px;
  transform: translate(-50%, -50%);
  transform-style: preserve-3d;
  animation-name: idleSpin;
  animation-timing-function: linear;
  animation-iteration-count: infinite;
}

.idle-brain img {
  width: 100%;
  display: block;
  filter: drop-shadow(0 0 10px rgba(110, 200, 210, 0.5));
}

@keyframes idleSpin {
  from { transform: translate(-50%, -50%) rotateY(0deg); }
  to   { transform: translate(-50%, -50%) rotateY(360deg); }
}

@media (max-width: 480px) {
  .idle-heart { width: 24vmin; }
  .idle-brain { width: 13vmin; }
}
