:root {
  --bg: #ffffff;
  --bg-soft: #f7f7f8;
  --bg-sidebar: #f9f9fa;
  --border: #e5e5e7;
  --text: #1e1e1e;
  --text-muted: #6b6b6f;
  --accent: #10a37f;
  --accent-hover: #0d8f6f;
  --bubble-user: #f0f4ff;
  --bubble-assistant: #ffffff;
  --danger: #d93025;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.08), 0 1px 2px rgba(0, 0, 0, 0.04);
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", -apple-system, BlinkMacSystemFont, Helvetica, Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
}

button { font-family: inherit; cursor: pointer; }

/* ---------- App shell ---------- */
.app-shell {
  display: flex;
  height: 100vh;
  width: 100%;
}

/* ---------- Sidebar ---------- */
.sidebar {
  width: 260px;
  flex-shrink: 0;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 12px;
}

.sidebar-top { display: flex; flex-direction: column; gap: 14px; }

.brand { display: flex; align-items: center; gap: 8px; padding: 4px 6px 8px; }
.brand .shield { width: 24px; height: 27px; }
.brand-name { font-weight: 600; font-size: 15px; color: var(--text); }

.new-chat-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  font-weight: 500;
  transition: background .15s;
}
.new-chat-btn:hover { background: var(--bg-soft); }
.new-chat-btn .plus { font-size: 16px; font-weight: 400; }

.conversation-list {
  list-style: none;
  margin: 12px 0 0;
  padding: 0;
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.conversation-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding: 9px 10px;
  border-radius: 8px;
  cursor: pointer;
  color: var(--text);
  transition: background .12s;
}
.conversation-item:hover { background: var(--bg-soft); }
.conversation-item.active { background: #e9ecf3; }
.conv-title { flex: 1; min-width: 0; overflow: hidden; }
.conv-title b { font-weight: 400; font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; cursor: text; }
.conv-actions { display: none; gap: 2px; flex-shrink: 0; }
.conversation-item:hover .conv-actions { display: flex; }
.conv-actions button {
  border: 0; background: transparent; color: var(--text-muted); font-size: 12px;
  padding: 4px; border-radius: 6px;
}
.conv-actions button:hover { background: #dfe2ea; color: var(--text); }
.empty-conv-hint { padding: 10px; color: var(--text-muted); font-size: 13px; }

.sidebar-bottom {
  border-top: 1px solid var(--border);
  padding-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.tool-btn, .account-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px 10px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  font-size: 13.5px;
  text-align: left;
  text-decoration: none;
}
.tool-btn:hover, .account-btn:hover { background: var(--bg-soft); }
.tool-btn .icon { font-size: 15px; width: 18px; text-align: center; }
a.tool-btn { cursor: pointer; }

.account-btn { margin-top: 6px; border-top: 1px solid var(--border); border-radius: 0; padding-top: 12px; }
.avatar-circle {
  width: 26px; height: 26px; border-radius: 50%;
  background: var(--accent); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 600; flex-shrink: 0;
}

/* ---------- Chat main ---------- */
.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--bg);
}

.chat-thread {
  flex: 1;
  overflow-y: auto;
  padding: 24px 0 12px;
}

.empty-state {
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 6px;
  padding: 20px;
}
.empty-state[hidden] { display: none; }
.empty-state .ai-face { width: 84px; height: 84px; border-radius: 50%; object-fit: cover; margin-bottom: 10px; }
.empty-state h1 { font-size: 26px; margin: 0; font-weight: 600; }
.empty-state p { color: var(--text-muted); margin: 2px 0; font-size: 14.5px; }
.empty-state .login-hint { font-size: 13px; margin-top: 10px; }

.chat-bubble {
  max-width: 760px;
  margin: 0 auto 18px;
  padding: 0 20px;
  display: flex;
}
.chat-bubble.user { justify-content: flex-end; }
.chat-bubble.assistant { justify-content: flex-start; }
.bubble-content {
  max-width: 100%;
  padding: 10px 16px;
  border-radius: 16px;
  white-space: pre-wrap;
  word-wrap: break-word;
  font-size: 15px;
}
.chat-bubble.user .bubble-content { background: var(--bubble-user); color: var(--text); border-bottom-right-radius: 4px; }
.chat-bubble.assistant .bubble-content { background: var(--bubble-assistant); border: 1px solid var(--border); color: var(--text); border-bottom-left-radius: 4px; }

.grounding-sources {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 10px;
  margin-top: 10px;
  padding-top: 9px;
  border-top: 1px solid var(--border);
  font-size: 12px;
}
.grounding-sources span { color: var(--text-muted); width: 100%; }
.grounding-sources a { color: var(--accent); text-decoration: none; }
.grounding-sources a:hover { text-decoration: underline; }
.google-search-entry-point { margin-top: 8px; max-width: 100%; overflow-x: auto; }

.chat-bubble.typing .bubble-content {
  display: flex; align-items: center; gap: 8px;
}
.thinking-label {
  color: var(--text-muted); font-size: 14px; font-weight: 500;
}
.typing-dots { display: inline-flex; align-items: center; }
.typing-dot {
  display: inline-block; width: 6px; height: 6px; margin-right: 4px;
  border-radius: 50%; background: var(--text-muted);
  animation: typingPulse 1.2s infinite ease-in-out;
}
.typing-dot:nth-child(2) { animation-delay: .2s; }
.typing-dot:nth-child(3) { animation-delay: .4s; }
@keyframes typingPulse { 0%, 60%, 100% { opacity: .3; transform: translateY(0); } 30% { opacity: 1; transform: translateY(-3px); } }

.chat-input-bar {
  max-width: 760px;
  width: calc(100% - 40px);
  margin: 0 auto 6px;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--bg);
  box-shadow: var(--shadow);
}
.chat-input-bar textarea {
  flex: 1;
  min-width: 0;
  border: 0;
  outline: 0;
  resize: none;
  background: transparent;
  color: var(--text);
  font-family: inherit;
  font-size: 15px;
  line-height: 1.4;
  max-height: 220px;
  padding: 6px 4px;
}
.chat-input-bar textarea::placeholder { color: var(--text-muted); }

.icon-btn {
  border: 0;
  background: transparent;
  border-radius: 50%;
  width: 34px;
  height: 34px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  color: var(--text-muted);
}
.icon-btn:hover { background: var(--bg-soft); }
.icon-btn.send-btn { background: var(--accent); color: #fff; }
.icon-btn.send-btn:hover { background: var(--accent-hover); }
.icon-btn.mic-btn.listening { background: var(--danger); color: #fff; }

.senses-bar {
  display: flex;
  align-items: center;
  gap: 1px;
  flex-shrink: 0;
}
.senses-bar .icon-btn {
  width: 28px;
  height: 28px;
  font-size: 13px;
}
.sense-btn.active-mouth {
  background: #e8f8f2;
  color: var(--accent);
}
.sense-btn.seeing {
  background: #fff4e5;
  color: #b86b00;
}

.perm-toggles {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: min(720px, 100%);
  margin: 0 auto 2px;
  padding: 0 2px;
}
.perm-switch {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: #fafafa;
  padding: 2px 3px 2px 6px;
  min-width: 0;
  box-shadow: none;
}
.perm-switch.is-on {
  border-color: #b7e5d4;
  background: #f3fbf7;
}
.perm-switch.is-blocked {
  border-color: #f0c2bf;
  background: #fff8f7;
}
.perm-switch .perm-icon {
  width: auto;
  height: auto;
  border-radius: 0;
  display: inline;
  background: transparent;
  font-size: 11px;
  line-height: 1;
  flex-shrink: 0;
}
.perm-switch.is-on .perm-icon { background: transparent; }
.perm-switch .perm-name {
  font-size: 10px;
  font-weight: 700;
  color: var(--text-muted);
  min-width: 0;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}
.perm-seg {
  display: inline-flex;
  border: 0;
  border-radius: 999px;
  overflow: hidden;
  background: #ececef;
  padding: 1px;
  gap: 1px;
}
.perm-opt {
  border: 0;
  background: transparent;
  color: var(--text-muted);
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  padding: 3px 7px;
  min-width: 0;
  border-radius: 999px;
  line-height: 1.2;
}
.perm-opt:hover { background: rgba(255,255,255,0.7); color: var(--text); }
.perm-opt.is-active[data-on="0"] {
  background: var(--danger);
  color: #fff;
}
.perm-opt.is-active[data-on="1"] {
  background: var(--accent);
  color: #fff;
}
.perm-live { display: none; }

.sense-modal { max-width: 480px; }
.sense-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}
.camera-stage {
  margin-top: 12px;
  border-radius: 12px;
  overflow: hidden;
  background: #111;
  aspect-ratio: 4 / 3;
}
.camera-stage video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  background: #000;
}
.bubble-snap {
  display: block;
  max-width: min(280px, 70%);
  margin: 8px 0 4px;
  border-radius: 10px;
  border: 1px solid var(--border);
}
.bubble-media {
  display: block;
  max-width: min(360px, 85%);
  margin: 10px 0 4px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #111;
}
.bubble-video {
  width: 100%;
  max-height: 320px;
}

.input-footnote {
  text-align: center;
  font-size: 12px;
  color: var(--text-muted);
  margin: 0 0 10px;
}

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: #1e1e1e;
  color: #fff;
  padding: 10px 18px;
  border-radius: 8px;
  font-size: 13.5px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
  z-index: 200;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- Modals ---------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity .15s;
  z-index: 100;
  padding: 20px;
}
.modal-backdrop.open { opacity: 1; pointer-events: auto; }

.modal {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.15);
  padding: 24px;
  width: 100%;
  max-width: 480px;
  max-height: 85vh;
  overflow-y: auto;
  position: relative;
}
.knowledge-modal { max-width: 560px; }

.modal h2 { margin: 0 0 8px; font-size: 19px; font-weight: 600; }
.modal-subtitle { color: var(--text-muted); font-size: 13.5px; margin: 0 0 14px; }
.modal-section-heading { font-size: 14px; font-weight: 600; margin: 20px 0 8px; }

.modal-close {
  position: absolute;
  top: 14px;
  right: 14px;
  border: 0;
  background: transparent;
  font-size: 20px;
  color: var(--text-muted);
  width: 30px;
  height: 30px;
  border-radius: 50%;
}
.modal-close:hover { background: var(--bg-soft); }

.field-box {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  margin-bottom: 10px;
}
.field-box input, .field-box select, select.field-box {
  width: 100%;
  border: 0;
  outline: 0;
  background: transparent;
  padding: 10px 12px;
  font-size: 14px;
  color: var(--text);
  font-family: inherit;
}

.auth-field label { display: block; font-size: 13px; color: var(--text-muted); margin-bottom: 4px; }
.auth-error { color: var(--danger); font-size: 13px; margin: 4px 0 10px; }
.auth-switch { text-align: center; font-size: 13.5px; color: var(--text-muted); margin-top: 16px; }
.auth-switch button { border: 0; background: transparent; color: var(--accent); font-weight: 600; margin-left: 4px; }

.primary-btn {
  width: 100%;
  padding: 10px 16px;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  transition: background .15s;
}
.primary-btn:hover { background: var(--accent-hover); }
.primary-btn:disabled { opacity: .6; cursor: not-allowed; }

.export-btn {
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 13px;
  margin-top: 10px;
}
.export-btn:hover { background: var(--bg-soft); }

.item-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 260px;
  overflow-y: auto;
}
.item-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13.5px;
}
.item-list button {
  border: 0;
  background: transparent;
  color: var(--text-muted);
  font-size: 13px;
  padding: 4px 8px;
  border-radius: 6px;
}
.item-list button:hover { background: var(--bg-soft); color: var(--text); }

.knowledge-upload-form, .automation-form { display: flex; flex-direction: column; }
.memory-add-form { flex-direction: row; gap: 8px; align-items: flex-start; }
.memory-add-form .field-box { flex: 1; margin-bottom: 0; }
.memory-add-form .primary-btn { width: auto; padding: 10px 18px; }

.agent-controls { display: flex; gap: 8px; margin-top: 8px; }
.agent-controls .export-btn { margin-top: 0; }

.pairing-box {
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  font-size: 13px;
  margin: 12px 0;
}
.pairing-box code {
  display: block;
  margin-top: 8px;
  padding: 8px;
  background: #eef0f2;
  border-radius: 6px;
  font-size: 12.5px;
  word-break: break-all;
}

.api-key-secret {
  margin: 14px 0;
  padding: 12px;
  border: 1px solid #f0c36d;
  border-radius: 8px;
  background: #fff8e8;
  font-size: 13px;
}
.api-key-secret code, .api-connection-details code {
  display: block;
  margin-top: 7px;
  padding: 8px;
  border-radius: 6px;
  background: #eef0f2;
  color: var(--text);
  font-family: Consolas, "Courier New", monospace;
  font-size: 12.5px;
  overflow-wrap: anywhere;
  user-select: all;
}
.api-key-secret .export-btn { margin-top: 8px; }
.api-connection-details {
  margin-top: 14px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-soft);
}
.api-connection-details p { margin: 0 0 10px; font-size: 13px; }
.api-connection-details p:last-child { margin-bottom: 0; }

/* ---------- Scrollbars (subtle) ---------- */
.conversation-list::-webkit-scrollbar, .chat-thread::-webkit-scrollbar, .item-list::-webkit-scrollbar, .modal::-webkit-scrollbar {
  width: 8px;
}
.conversation-list::-webkit-scrollbar-thumb, .chat-thread::-webkit-scrollbar-thumb, .item-list::-webkit-scrollbar-thumb, .modal::-webkit-scrollbar-thumb {
  background: #d5d5d8;
  border-radius: 4px;
}

/* ---------- Responsive ---------- */
@media (max-width: 780px) {
  .sidebar { position: fixed; z-index: 50; height: 100%; transform: translateX(-100%); transition: transform .2s; }
  .sidebar.open { transform: translateX(0); }
  .chat-input-bar, .chat-bubble { width: calc(100% - 24px); padding-left: 12px; padding-right: 12px; }
}
