:root {
  --bg-page: #ffffff;
  --bg-app: #ffffff;
  --bg-card: #ffffff;
  --bg-input: #f8fafc;
  --border-subtle: #e2e8f0;
  --border-hover: #cbd5e1;
  --border-focus: #ffcc00;

  /* Accent: Yellow #FFCC00 */
  --primary: #ffcc00;
  --primary-hover: #f5c400;
  --primary-glow: rgba(255, 204, 0, 0.35);
  --primary-subtle: rgba(255, 204, 0, 0.15);

  --user-bubble: #ffcc00;
  --user-text: #111827;
  
  --poc-bubble: #f1f5f9;
  --poc-text: #0f172a;
  --vault-bubble: #f1f5f9;
  --vault-text: #0f172a;

  --accent-green: #10b981;
  --accent-amber: #d97706;
  --accent-rose: #e11d48;

  --text-main: #0f172a;
  --text-muted: #64748b;
  --text-dim: #94a3b8;

  --font-family: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --radius-lg: 22px;
  --radius-md: 14px;
  --radius-sm: 8px;
}

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

body {
  font-family: var(--font-family);
  background-color: var(--bg-page);
  color: var(--text-main);
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow-x: hidden;
}

/* --- Clean App Shell (No bulky fake phone frame) --- */
.app-shell {
  width: 100%;
  max-width: 520px;
  height: min(92vh, 880px);
  display: flex;
  flex-direction: column;
  padding: 12px;
}

.chat-app {
  flex: 1;
  background: var(--bg-app);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  box-shadow: 0 16px 45px -12px rgba(15, 23, 42, 0.08), 0 0 0 1px rgba(0, 0, 0, 0.02);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}

/* --- Top Navigation Header --- */
.chat-header {
  padding: 16px 20px;
  background: #ffffff;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  z-index: 20;
}

.chat-contact {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
  min-width: 0;
}

.avatar-wrap {
  position: relative;
  flex-shrink: 0;
}

.avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  color: #111827;
  box-shadow: 0 3px 10px var(--primary-glow);
}

.online-indicator {
  position: absolute;
  bottom: 0;
  right: 0;
  width: 12px;
  height: 12px;
  background-color: var(--accent-green);
  border: 2px solid #ffffff;
  border-radius: 50%;
}

.contact-info {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.contact-name-row {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.contact-name {
  font-weight: 700;
  font-size: 16px;
  color: var(--text-main);
  letter-spacing: -0.01em;
}

.verified-badge {
  background: var(--primary);
  color: #111827;
  font-size: 10px;
  font-weight: 900;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* AI Mode Badge in Header */
.mode-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  font-family: inherit;
  transition: all 0.2s ease;
}

.mode-badge .badge-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
}

.mode-badge.offline {
  background: #f1f5f9;
  color: #475569;
  border-color: #e2e8f0;
}

.mode-badge.offline .badge-dot {
  background: #94a3b8;
}

.mode-badge.live {
  background: rgba(16, 185, 129, 0.12);
  color: #059669;
  border-color: rgba(16, 185, 129, 0.25);
}

.mode-badge.live .badge-dot {
  background: var(--accent-green);
  box-shadow: 0 0 6px var(--accent-green);
  animation: pulseDot 2s infinite ease-in-out;
}

@keyframes pulseDot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.5; transform: scale(0.85); }
}

.contact-status {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.header-btn {
  background: #f8fafc;
  border: 1px solid var(--border-subtle);
  color: var(--text-main);
  padding: 7px 11px;
  border-radius: 10px;
  font-size: 12px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  transition: all 0.15s ease;
}

.header-btn:hover {
  background: #f1f5f9;
  border-color: #cbd5e1;
}

.header-btn.primary {
  background: var(--primary-subtle);
  border-color: rgba(255, 204, 0, 0.4);
}

.header-btn.primary:hover {
  background: rgba(255, 204, 0, 0.25);
  border-color: var(--primary);
}

/* --- Minimalist Context Bar --- */
.minimal-hud {
  background: #ffffff;
  border-bottom: 1px solid var(--border-subtle);
  padding: 8px 18px;
  display: flex;
  align-items: center;
  gap: 12px;
  overflow-x: auto;
}

.minimal-hud::-webkit-scrollbar {
  display: none;
}

.hud-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: #f8fafc;
  border: 1px solid var(--border-subtle);
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 11.5px;
  white-space: nowrap;
}

.hud-label {
  color: var(--text-muted);
  font-weight: 500;
}

.hud-value {
  font-weight: 700;
  color: var(--text-main);
}

.hud-value.yellow {
  color: #b45309;
  background: rgba(255, 204, 0, 0.2);
  padding: 2px 6px;
  border-radius: 4px;
}

/* --- Chat Stream Messages --- */
.chat-stream {
  flex: 1;
  overflow-y: auto;
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  background: #ffffff;
  scroll-behavior: smooth;
}

.chat-stream::-webkit-scrollbar {
  width: 5px;
}

.chat-stream::-webkit-scrollbar-thumb {
  background: #e2e8f0;
  border-radius: 5px;
}

.date-divider {
  text-align: center;
  margin: 4px 0 10px;
}

.date-divider span {
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-dim);
  background: #f1f5f9;
  padding: 4px 14px;
  border-radius: 999px;
}

/* Message Bubble Styles */
.message-row {
  display: flex;
  gap: 8px;
  max-width: 86%;
  animation: messageIn 0.2s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

@keyframes messageIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.message-row.user {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.message-row.vault,
.message-row.poc {
  align-self: flex-start;
}

.bubble {
  padding: 12px 16px;
  border-radius: 18px;
  font-size: 14.5px;
  line-height: 1.5;
  position: relative;
  word-break: break-word;
}

/* User Bubble: Vibrant Yellow #FFCC00 */
.message-row.user .bubble {
  background: var(--user-bubble);
  color: var(--user-text);
  font-weight: 500;
  border-bottom-right-radius: 4px;
  box-shadow: 0 3px 12px rgba(255, 204, 0, 0.25);
}

/* POC Bubble: Clean Off-White */
.message-row.vault .bubble,
.message-row.poc .bubble {
  background: var(--poc-bubble);
  color: var(--poc-text);
  border-bottom-left-radius: 4px;
  border: 1px solid #e2e8f0;
}

.message-time {
  font-size: 10px;
  color: var(--text-dim);
  margin-top: 4px;
  text-align: right;
  display: block;
}

.message-row.user .message-time {
  color: rgba(17, 24, 39, 0.6);
  font-weight: 600;
}

/* In-Chat Action Cards */
.chat-card {
  background: #ffffff;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  padding: 12px;
  margin-top: 10px;
  font-size: 13px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.03);
}

.card-heading {
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
  color: var(--text-main);
}

.tradeoff-options {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 8px;
}

.tradeoff-item {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  padding: 8px 10px;
  border-radius: 8px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.tradeoff-item strong {
  color: var(--accent-amber);
}

.progress-pill-box {
  margin-top: 8px;
}

.mini-progress-bar {
  background: #e2e8f0;
  height: 8px;
  border-radius: 999px;
  overflow: hidden;
  margin-top: 4px;
}

.mini-progress-fill {
  background: var(--primary);
  height: 100%;
  border-radius: 999px;
  transition: width 0.4s ease;
}

/* Typing Indicator */
.typing-indicator {
  display: none;
  align-items: center;
  gap: 8px;
  padding: 4px 20px 10px;
  align-self: flex-start;
}

.typing-indicator.active {
  display: flex;
}

.avatar-mini {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  color: #111827;
}

.typing-bubble {
  background: #f1f5f9;
  border: 1px solid #e2e8f0;
  padding: 10px 14px;
  border-radius: 16px;
  display: flex;
  gap: 4px;
  align-items: center;
}

.typing-bubble .dot {
  width: 6px;
  height: 6px;
  background: var(--text-muted);
  border-radius: 50%;
  animation: typingBounce 1.4s infinite ease-in-out both;
}

.typing-bubble .dot:nth-child(1) { animation-delay: -0.32s; }
.typing-bubble .dot:nth-child(2) { animation-delay: -0.16s; }

@keyframes typingBounce {
  0%, 80%, 100% { transform: scale(0); opacity: 0.4; }
  40% { transform: scale(1); opacity: 1; }
}

.typing-label {
  font-size: 11.5px;
  color: var(--text-muted);
}

/* --- Quick Suggestion Chips --- */
.quick-chips-wrapper {
  background: #ffffff;
  border-top: 1px solid #f1f5f9;
  padding: 8px 16px;
  overflow-x: auto;
  white-space: nowrap;
}

.quick-chips-wrapper::-webkit-scrollbar {
  display: none;
}

.quick-chips {
  display: inline-flex;
  gap: 8px;
}

.chip {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  color: var(--text-main);
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 12.5px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s ease;
  font-family: inherit;
}

.chip:hover {
  background: var(--primary-subtle);
  border-color: var(--primary);
  transform: translateY(-1px);
}

/* --- Message Input Bar --- */
.chat-input-bar {
  padding: 12px 16px 16px;
  background: #ffffff;
  border-top: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  gap: 10px;
}

.chat-input-bar input {
  flex: 1;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  color: var(--text-main);
  padding: 12px 18px;
  border-radius: 24px;
  font-size: 14.5px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.chat-input-bar input:focus {
  border-color: var(--primary);
  background: #ffffff;
  box-shadow: 0 0 0 3px rgba(255, 204, 0, 0.2);
}

.send-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--primary);
  border: none;
  color: #111827;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.15s ease;
  flex-shrink: 0;
  box-shadow: 0 3px 10px rgba(255, 204, 0, 0.3);
}

.send-btn:hover {
  background: var(--primary-hover);
  transform: scale(1.05);
}

/* --- AI Memory Drawer --- */
.memory-drawer {
  position: fixed;
  top: 0;
  right: -420px;
  width: 380px;
  max-width: 90vw;
  height: 100vh;
  background: #ffffff;
  border-left: 1px solid var(--border-subtle);
  box-shadow: -10px 0 30px rgba(0, 0, 0, 0.08);
  z-index: 1000;
  transition: right 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  display: flex;
  flex-direction: column;
}

.memory-drawer.open {
  right: 0;
}

.drawer-header {
  padding: 20px;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.drawer-title {
  display: flex;
  align-items: center;
  gap: 12px;
}

.drawer-icon {
  font-size: 24px;
}

.drawer-title h3 {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-main);
}

.drawer-title p {
  font-size: 12px;
  color: var(--text-muted);
}

.close-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 26px;
  cursor: pointer;
  line-height: 1;
}

.drawer-content {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.memory-card {
  background: #f8fafc;
  border: 1px solid var(--border-subtle);
  border-radius: 14px;
  padding: 14px;
}

.card-tag {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #b45309;
  margin-bottom: 10px;
}

.form-row {
  margin-bottom: 12px;
}

.form-row label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.label-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
}

.label-row label {
  margin-bottom: 0;
}

.text-btn {
  background: none;
  border: none;
  color: #b45309;
  font-size: 11.5px;
  font-weight: 600;
  cursor: pointer;
  padding: 0;
}

.form-row input,
.form-row select {
  width: 100%;
  background: #ffffff;
  border: 1px solid var(--border-subtle);
  color: var(--text-main);
  padding: 9px 12px;
  border-radius: 8px;
  font-family: inherit;
  font-size: 13px;
  outline: none;
  transition: border-color 0.2s ease;
}

.form-row select {
  cursor: pointer;
}

.form-row input:focus,
.form-row select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(255, 204, 0, 0.25);
}

.form-row-split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 10px;
}

.habits-list {
  list-style: none;
  font-size: 12.5px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  color: var(--text-muted);
}

.habits-list strong {
  color: var(--text-main);
}

.save-profile-btn {
  background: var(--primary);
  color: #111827;
  border: none;
  padding: 12px;
  border-radius: 10px;
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.15s ease;
}

.save-profile-btn:hover {
  background: var(--primary-hover);
  transform: translateY(-1px);
}

.secondary-btn {
  background: #ffffff;
  border: 1px solid var(--border-subtle);
  color: var(--text-main);
  padding: 12px;
  border-radius: 10px;
  font-weight: 600;
  font-size: 13.5px;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.15s ease;
}

.secondary-btn:hover {
  background: #f8fafc;
  border-color: #cbd5e1;
}

.danger-btn {
  background: #fff1f2;
  border: 1px solid #fecdd3;
  color: #e11d48;
  padding: 12px;
  border-radius: 10px;
  font-weight: 600;
  font-size: 13.5px;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.15s ease;
}

/* --- API Key Settings Modal --- */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(15, 23, 42, 0.4);
  backdrop-filter: blur(4px);
  z-index: 1100;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-overlay.open {
  display: flex;
}

.modal-card {
  background: #ffffff;
  border: 1px solid var(--border-subtle);
  border-radius: 18px;
  width: 100%;
  max-width: 440px;
  overflow: hidden;
  box-shadow: 0 20px 40px -10px rgba(0, 0, 0, 0.15);
  animation: modalPop 0.15s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

@keyframes modalPop {
  from { opacity: 0; transform: scale(0.96); }
  to { opacity: 1; transform: scale(1); }
}

.modal-header {
  padding: 18px 20px;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-title-wrap {
  display: flex;
  align-items: center;
  gap: 12px;
}

.modal-icon {
  font-size: 22px;
}

.modal-title-wrap h3 {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-main);
}

.modal-title-wrap p {
  font-size: 12px;
  color: var(--text-muted);
}

.modal-body {
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.key-status-banner {
  background: #f8fafc;
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 12.5px;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-muted);
}

.key-status-banner.active {
  background: rgba(16, 185, 129, 0.08);
  border-color: rgba(16, 185, 129, 0.3);
  color: #047857;
}

.test-result-box {
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 12.5px;
  line-height: 1.4;
}

.test-result-box.success {
  background: #ecfdf5;
  border: 1px solid #a7f3d0;
  color: #065f46;
}

.test-result-box.error {
  background: #fff1f2;
  border: 1px solid #fecdd3;
  color: #9f1239;
}

.key-helper-box {
  background: #fffbeb;
  border: 1px solid #fde68a;
  border-radius: 12px;
  padding: 14px;
  font-size: 12px;
  color: #92400e;
  line-height: 1.5;
}

.key-helper-box ol {
  margin: 6px 0 10px 18px;
}

.key-helper-box a {
  color: #b45309;
  font-weight: 600;
  text-decoration: underline;
}

.privacy-note {
  font-size: 11px;
  color: #b45309;
  border-top: 1px solid rgba(180, 83, 9, 0.15);
  padding-top: 8px;
  margin-top: 4px;
}

.modal-footer {
  padding: 14px 20px 20px;
  border-top: 1px solid var(--border-subtle);
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.drawer-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(15, 23, 42, 0.3);
  z-index: 999;
  display: none;
}

.drawer-backdrop.open {
  display: block;
}

/* Mobile Fullscreen Adaptation */
@media (max-width: 600px) {
  body {
    background: #ffffff;
  }

  .app-shell {
    padding: 0;
    max-width: 100%;
    height: 100vh;
  }

  .chat-app {
    border-radius: 0;
    border: none;
    box-shadow: none;
  }

  .chat-header {
    padding-top: max(14px, env(safe-area-inset-top));
  }

  .btn-label {
    display: none;
  }
}
