:root {
  --bg-desktop: #070a13;
  --bg-app: #0d121f;
  --bg-card: #151d30;
  --bg-input: #1a233a;
  --border-subtle: #24304d;
  --border-focus: #38bdf8;
  
  --primary: #38bdf8;
  --primary-glow: rgba(56, 189, 248, 0.25);
  --user-bubble: linear-gradient(135deg, #2563eb 0%, #0284c7 100%);
  --vault-bubble: #172033;
  
  --accent-green: #10b981;
  --accent-green-glow: rgba(16, 185, 129, 0.25);
  --accent-amber: #f59e0b;
  --accent-rose: #f43f5e;
  --accent-purple: #8b5cf6;
  
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --text-dim: #64748b;
  
  --font-family: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  --radius-lg: 20px;
  --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-desktop);
  color: var(--text-main);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  overflow-x: hidden;
}

/* --- Desktop Banner & Controls --- */
.desktop-banner {
  width: 100%;
  max-width: 900px;
  padding: 14px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
  z-index: 10;
}

.desktop-badge {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--primary);
  background: rgba(56, 189, 248, 0.1);
  border: 1px solid rgba(56, 189, 248, 0.25);
  padding: 6px 14px;
  border-radius: 999px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.desktop-controls {
  display: flex;
  gap: 10px;
}

.control-btn {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  color: var(--text-main);
  padding: 8px 16px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: all 0.2s ease;
}

.control-btn:hover {
  background: #1e2942;
  border-color: var(--primary);
  transform: translateY(-1px);
}

.control-btn.primary {
  background: linear-gradient(135deg, rgba(56, 189, 248, 0.15), rgba(139, 92, 246, 0.2));
  border-color: rgba(56, 189, 248, 0.4);
  color: #e0f2fe;
}

/* --- Device Mockup Wrapper --- */
.device-container {
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 10px;
  transition: all 0.3s ease;
}

body.phone-frame-active .device-frame {
  width: 420px;
  height: 840px;
  max-height: calc(100vh - 100px);
  background: var(--bg-app);
  border-radius: 46px;
  box-shadow: 0 25px 60px -15px rgba(0, 0, 0, 0.8), 0 0 0 10px #1e293b, 0 0 0 12px #334155;
  border: 4px solid #000;
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

body:not(.phone-frame-active) .device-frame {
  width: 100%;
  max-width: 800px;
  height: calc(100vh - 90px);
  border-radius: 24px;
  background: var(--bg-app);
  border: 1px solid var(--border-subtle);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* Dynamic Island */
.dynamic-island {
  position: absolute;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  width: 110px;
  height: 24px;
  background: #000;
  border-radius: 20px;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
}

body:not(.phone-frame-active) .dynamic-island {
  display: none;
}

.island-camera {
  width: 10px;
  height: 10px;
  background: #111;
  border-radius: 50%;
  border: 1px solid #222;
}

/* --- Messenger App Layout --- */
.messenger-app {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
  position: relative;
}

/* Top Navigation Header */
.chat-header {
  padding: 44px 16px 12px;
  background: rgba(13, 18, 31, 0.9);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  z-index: 20;
}

body:not(.phone-frame-active) .chat-header {
  padding: 16px 20px;
}

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

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

.avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: linear-gradient(135deg, #0284c7 0%, #8b5cf6 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  box-shadow: 0 4px 12px var(--primary-glow);
}

.online-indicator {
  position: absolute;
  bottom: 0;
  right: 0;
  width: 12px;
  height: 12px;
  background-color: var(--accent-green);
  border: 2px solid var(--bg-app);
  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: 15px;
  color: var(--text-main);
}

.verified-badge {
  background: var(--primary);
  color: #042f2e;
  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: 10.5px;
  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: rgba(148, 163, 184, 0.12);
  color: #cbd5e1;
  border-color: rgba(148, 163, 184, 0.25);
}

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

.mode-badge.live {
  background: rgba(16, 185, 129, 0.15);
  color: #34d399;
  border-color: rgba(16, 185, 129, 0.35);
}

.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: 11.5px;
  color: var(--text-muted);
  margin-top: 2px;
}

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

/* Prominent Settings Button in Header */
.settings-pill-btn {
  background: rgba(56, 189, 248, 0.12);
  border: 1px solid rgba(56, 189, 248, 0.3);
  color: var(--text-main);
  padding: 6px 10px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  transition: all 0.2s ease;
}

.settings-pill-btn:hover {
  background: rgba(56, 189, 248, 0.25);
  border-color: var(--primary);
  transform: translateY(-1px);
}

.icon-btn {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  font-size: 15px;
  padding: 6px 9px;
  border-radius: 8px;
  cursor: pointer;
  color: var(--text-main);
  transition: all 0.2s ease;
}

.icon-btn:hover {
  background: #1e2942;
  border-color: var(--primary);
}

/* Pinned Context HUD */
.pinned-hud {
  background: rgba(21, 29, 48, 0.95);
  border-bottom: 1px solid var(--border-subtle);
  padding: 8px 16px;
  display: flex;
  align-items: center;
  justify-content: space-around;
  font-size: 11px;
  z-index: 10;
}

.hud-item {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.hud-label {
  color: var(--text-dim);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 600;
}

.hud-value {
  font-weight: 700;
  font-size: 13px;
}

.hud-value.green {
  color: var(--accent-green);
}

.hud-value.blue {
  color: var(--primary);
}

.hud-divider {
  width: 1px;
  height: 20px;
  background: var(--border-subtle);
}

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

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

.chat-stream::-webkit-scrollbar-thumb {
  background: var(--border-subtle);
  border-radius: 4px;
}

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

.date-divider span {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-dim);
  background: rgba(255, 255, 255, 0.04);
  padding: 4px 12px;
  border-radius: 999px;
}

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

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

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

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

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

.message-row.user .bubble {
  background: var(--user-bubble);
  color: #fff;
  border-bottom-right-radius: 4px;
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.25);
}

.message-row.vault .bubble {
  background: var(--vault-bubble);
  color: var(--text-main);
  border-bottom-left-radius: 4px;
  border: 1px solid var(--border-subtle);
}

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

.message-row.user .message-time {
  color: rgba(255, 255, 255, 0.7);
}

/* In-Chat Action Cards */
.chat-card {
  background: rgba(11, 15, 25, 0.85);
  border: 1px solid var(--border-subtle);
  border-radius: 14px;
  padding: 12px;
  margin-top: 10px;
  font-size: 13px;
}

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

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

.tradeoff-item {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.06);
  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: rgba(255, 255, 255, 0.08);
  height: 8px;
  border-radius: 999px;
  overflow: hidden;
  margin-top: 4px;
}

.mini-progress-fill {
  background: linear-gradient(90deg, var(--primary), var(--accent-green));
  height: 100%;
  border-radius: 999px;
  transition: width 0.4s ease;
}

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

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

.avatar-mini {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: linear-gradient(135deg, #0284c7 0%, #8b5cf6 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
}

.typing-bubble {
  background: var(--vault-bubble);
  border: 1px solid var(--border-subtle);
  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: 11px;
  color: var(--text-dim);
}

/* --- Quick Suggestion Chips --- */
.quick-chips-wrapper {
  background: rgba(13, 18, 31, 0.95);
  border-top: 1px solid rgba(255, 255, 255, 0.05);
  padding: 8px 12px;
  overflow-x: auto;
  white-space: nowrap;
}

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

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

.chip {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  color: var(--text-main);
  padding: 6px 13px;
  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: #1e2942;
  border-color: var(--primary);
  color: var(--primary);
  transform: translateY(-1px);
}

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

body.phone-frame-active .chat-input-bar {
  padding-bottom: 24px;
}

.chat-input-bar input {
  flex: 1;
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  color: var(--text-main);
  padding: 12px 16px;
  border-radius: 24px;
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.2s ease;
}

.chat-input-bar input:focus {
  border-color: var(--border-focus);
}

.send-btn {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--primary);
  border: none;
  color: #042f2e;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
  flex-shrink: 0;
}

.send-btn:hover {
  transform: scale(1.05);
  box-shadow: 0 0 14px var(--primary-glow);
}

/* --- AI Memory Drawer --- */
.memory-drawer {
  position: fixed;
  top: 0;
  right: -420px;
  width: 380px;
  max-width: 90vw;
  height: 100vh;
  background: var(--bg-app);
  border-left: 1px solid var(--border-subtle);
  box-shadow: -10px 0 40px rgba(0, 0, 0, 0.7);
  z-index: 1000;
  transition: right 0.3s 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: 26px;
}

.drawer-title h3 {
  font-size: 16px;
  font-weight: 700;
}

.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: var(--bg-card);
  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: var(--primary);
  margin-bottom: 10px;
}

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

.form-row label {
  display: block;
  font-size: 12px;
  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: var(--primary);
  font-size: 11.5px;
  font-weight: 600;
  cursor: pointer;
  padding: 0;
}

.form-row input {
  width: 100%;
  background: var(--bg-input);
  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 input:focus {
  border-color: var(--border-focus);
}

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

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

.form-row-split input {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  color: var(--text-main);
  padding: 8px 12px;
  border-radius: 8px;
  font-family: inherit;
  font-size: 13px;
  outline: none;
}

.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: linear-gradient(135deg, var(--primary), #0284c7);
  color: #042f2e;
  border: none;
  padding: 12px;
  border-radius: 10px;
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.2s ease;
}

.save-profile-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 14px var(--primary-glow);
}

.secondary-btn {
  background: var(--bg-card);
  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.2s ease;
}

.secondary-btn:hover {
  background: #1e2942;
  border-color: var(--primary);
}

.danger-btn {
  background: rgba(244, 63, 94, 0.15);
  border: 1px solid rgba(244, 63, 94, 0.35);
  color: #fb7185;
  padding: 12px;
  border-radius: 10px;
  font-weight: 600;
  font-size: 13.5px;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.2s ease;
}

.danger-btn:hover {
  background: rgba(244, 63, 94, 0.25);
}

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

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

.modal-card {
  background: var(--bg-app);
  border: 1px solid var(--border-subtle);
  border-radius: 20px;
  width: 100%;
  max-width: 460px;
  overflow: hidden;
  box-shadow: 0 25px 60px rgba(0, 0, 0, 0.85);
  animation: modalPop 0.2s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

@keyframes modalPop {
  from { opacity: 0; transform: scale(0.95); }
  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: 24px;
}

.modal-title-wrap h3 {
  font-size: 16px;
  font-weight: 700;
}

.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: rgba(255, 255, 255, 0.04);
  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.1);
  border-color: rgba(16, 185, 129, 0.3);
  color: #34d399;
}

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

.test-result-box.success {
  background: rgba(16, 185, 129, 0.15);
  border: 1px solid rgba(16, 185, 129, 0.4);
  color: #a7f3d0;
}

.test-result-box.error {
  background: rgba(244, 63, 94, 0.15);
  border: 1px solid rgba(244, 63, 94, 0.4);
  color: #fecdd3;
}

.key-helper-box {
  background: rgba(56, 189, 248, 0.05);
  border: 1px solid rgba(56, 189, 248, 0.18);
  border-radius: 12px;
  padding: 14px;
  font-size: 12px;
  color: #cbd5e1;
  line-height: 1.5;
}

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

.key-helper-box a {
  color: var(--primary);
  text-decoration: underline;
}

.privacy-note {
  font-size: 11px;
  color: var(--text-dim);
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  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(0, 0, 0, 0.5);
  z-index: 999;
  display: none;
}

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

/* Mobile Responsive Optimizations */
@media (max-width: 600px) {
  .desktop-banner {
    display: none;
  }
  
  body {
    padding: 0;
    justify-content: flex-start;
  }

  .device-container {
    padding: 0;
    height: 100vh;
  }

  body.phone-frame-active .device-frame {
    width: 100%;
    height: 100vh;
    max-height: 100vh;
    border-radius: 0;
    box-shadow: none;
    border: none;
  }

  .dynamic-island {
    display: none;
  }

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

  .btn-label {
    display: none;
  }
}
