:root {
  --bg: #14161a;
  --surface: #1c1f26;
  --surface-2: #232833;
  --border: #2c313b;
  --text: #e8eaed;
  --muted: #9aa1ac;
  --accent: #4c8dff;
  --accent-strong: #2f6fe0;
  --agent: #21262f;
  --user: #2f6fe0;
  --ok: #2fbf71;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0; height: 100%;
  background: var(--bg); color: var(--text);
  font-family: -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  font-size: 16px;
  overscroll-behavior: none;
}

body {
  display: flex; flex-direction: column; height: 100dvh;
}

.hidden { display: none !important; }

/* Topbar */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; padding: 12px 14px;
  padding-top: calc(12px + env(safe-area-inset-top, 0px));
  background: var(--surface); border-bottom: 1px solid var(--border);
  flex: none;
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.brand-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); }
.brand-name { font-size: 17px; }
.icon-btn {
  border: none; background: var(--surface-2); color: var(--text);
  width: 40px; height: 40px; border-radius: 10px; font-size: 18px; cursor: pointer;
}
.status-pill {
  display: flex; align-items: center; gap: 8px; margin-left: auto; margin-right: 8px;
  background: var(--surface-2); color: var(--muted);
  padding: 6px 12px; border-radius: 999px; font-size: 13px; max-width: 55%;
}
.status-pill #status-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.spinner {
  width: 13px; height: 13px; border-radius: 50%;
  border: 2px solid var(--border); border-top-color: var(--accent);
  animation: spin 0.8s linear infinite; flex: none;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Menu sheet */
.menu-sheet {
  position: fixed; inset: 0; background: rgba(0,0,0,.5);
  display: flex; justify-content: flex-end; align-items: flex-start; z-index: 20;
}
.menu-card {
  margin: calc(64px + env(safe-area-inset-top,0px)) 12px 0 0;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 14px; padding: 10px; width: 260px; max-width: 80vw;
  box-shadow: 0 12px 40px rgba(0,0,0,.5);
}
.menu-title { font-size: 12px; color: var(--muted); padding: 6px 8px; text-transform: uppercase; letter-spacing: .04em; }
.menu-link {
  display: block; padding: 12px 10px; border-radius: 10px; color: var(--text);
  text-decoration: none; font-size: 15px;
}
.menu-link:active { background: var(--surface-2); }
.menu-divider { height: 1px; background: var(--border); margin: 8px 4px; }
.menu-field { display: flex; flex-direction: column; gap: 6px; padding: 6px 8px; font-size: 12px; color: var(--muted); }
.menu-field input {
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text);
  border-radius: 10px; padding: 10px; font-size: 15px;
}
.menu-reset {
  width: 100%; margin-top: 8px; padding: 12px; border-radius: 10px;
  border: 1px solid var(--border); background: transparent; color: var(--muted); font-size: 14px;
}

/* Feed */
.feed {
  flex: 1; overflow-y: auto; padding: 16px 12px 8px;
  display: flex; flex-direction: column; gap: 10px;
  -webkit-overflow-scrolling: touch;
}
.welcome { text-align: center; margin: auto; max-width: 320px; color: var(--muted); }
.welcome-emoji { font-size: 40px; }
.welcome h1 { color: var(--text); font-size: 22px; margin: 10px 0; }
.welcome p { line-height: 1.5; font-size: 15px; }

.msg {
  max-width: 86%; padding: 11px 14px; border-radius: 16px; line-height: 1.45;
  white-space: pre-wrap; word-wrap: break-word; font-size: 15.5px;
  animation: pop .12s ease-out;
}
@keyframes pop { from { transform: translateY(4px); opacity: 0; } }
.msg.user { align-self: flex-end; background: var(--user); color: #fff; border-bottom-right-radius: 5px; }
.msg.agent { align-self: flex-start; background: var(--agent); color: var(--text); border-bottom-left-radius: 5px; }
.msg.agent.typing::after { content: "…"; color: var(--muted); }
.msg .details {
  display: block; margin-top: 8px; font-size: 12px; color: var(--muted);
}
.msg .details summary { cursor: pointer; }

/* Confirm bar */
.confirm-bar {
  flex: none; margin: 0 10px 6px; padding: 12px 14px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 14px;
}
.confirm-text { font-size: 15px; margin-bottom: 10px; }
.confirm-actions { display: flex; gap: 10px; }
.btn-yes, .btn-no {
  flex: 1; padding: 15px; border-radius: 12px; border: none;
  font-size: 16px; font-weight: 600; cursor: pointer;
}
.btn-yes { background: var(--ok); color: #06210f; }
.btn-no { background: transparent; color: var(--muted); border: 1px solid var(--border); flex: 0 0 40%; }

/* Chips */
.chips {
  flex: none; display: flex; gap: 8px; overflow-x: auto; padding: 6px 12px 8px;
  -webkit-overflow-scrolling: touch; scrollbar-width: none;
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; padding: 9px 14px; border-radius: 999px; white-space: nowrap;
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text);
  font-size: 14px; cursor: pointer;
}
.chip:active { background: var(--surface); }

/* Composer (thumb zone) */
.composer {
  flex: none; display: flex; align-items: flex-end; gap: 8px;
  padding: 8px 10px calc(8px + var(--safe-bottom));
  background: var(--surface); border-top: 1px solid var(--border);
}
#input {
  flex: 1; resize: none; max-height: 140px;
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 20px;
  padding: 13px 16px; font-size: 16px; font-family: inherit; line-height: 1.35;
}
#input:focus { outline: none; border-color: var(--accent); }
.send-btn {
  flex: none; width: 48px; height: 48px; border-radius: 50%; border: none;
  background: var(--accent); color: #fff; font-size: 19px; cursor: pointer;
}
.send-btn:disabled { background: var(--surface-2); color: var(--muted); }
