/* ProActive AI — WhatsApp-style Personal AI Operating System */
@import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap');

:root {
  /* Dark Theme (Default WhatsApp Slate / Emerald) */
  --bg-app: #0b141a;
  --bg-sidebar: #111b21;
  --bg-header: #202c33;
  --bg-chat: #0b141a;
  --bg-card: #182229;
  --bg-input: #2a3942;
  --bg-bubble-incoming: #202c33;
  --bg-bubble-outgoing: #005c4b;
  --bg-bubble-proactive: linear-gradient(135deg, #182c25 0%, #152422 100%);
  --border-proactive: #00a884;
  
  --text-primary: #e9edef;
  --text-secondary: #8696a0;
  --text-muted: #667781;
  --text-link: #53bdeb;
  
  --accent-emerald: #00a884;
  --accent-teal: #25d366;
  --accent-blue: #34b7f1;
  --accent-amber: #f59e0b;
  --accent-rose: #ef4444;
  
  --border-color: #222d34;
  --border-subtle: #1f2c34;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.5);
  --shadow-lg: 0 12px 28px rgba(0, 0, 0, 0.6);

  --font-sans: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
  
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-full: 9999px;

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

[data-theme="light"] {
  --bg-app: #efeae2;
  --bg-sidebar: #ffffff;
  --bg-header: #f0f2f5;
  --bg-chat: #efeae2;
  --bg-card: #ffffff;
  --bg-input: #f0f2f5;
  --bg-bubble-incoming: #ffffff;
  --bg-bubble-outgoing: #d9fdd3;
  --bg-bubble-proactive: linear-gradient(135deg, #e7f7ed 0%, #d5f3e4 100%);
  --border-proactive: #128c7e;

  --text-primary: #111b21;
  --text-secondary: #667781;
  --text-muted: #8696a0;
  --text-link: #027eb5;

  --border-color: #e9edef;
  --border-subtle: #f0f2f5;
  --shadow-sm: 0 1px 2px rgba(11, 20, 26, 0.08);
  --shadow-md: 0 4px 10px rgba(11, 20, 26, 0.12);
  --shadow-lg: 0 10px 24px rgba(11, 20, 26, 0.16);
}

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

body {
  font-family: var(--font-sans);
  background-color: var(--bg-app);
  color: var(--text-primary);
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  user-select: none;
  -webkit-font-smoothing: antialiased;
}

/* App Container */
#app-root {
  display: flex;
  height: 100%;
  width: 100%;
  position: relative;
  background-color: var(--bg-app);
}

/* Auth View */
.auth-wrapper {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  padding: 20px;
  background: radial-gradient(circle at top center, #182229 0%, #0b141a 100%);
}

.auth-card {
  background: var(--bg-sidebar);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 36px 32px;
  width: 100%;
  max-width: 440px;
  text-align: center;
  position: relative;
}

.auth-logo {
  width: 68px;
  height: 68px;
  margin: 0 auto 16px;
  border-radius: var(--radius-lg);
  box-shadow: 0 4px 20px rgba(0, 168, 132, 0.3);
}

.auth-title {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-bottom: 6px;
}

.auth-subtitle {
  font-size: 0.88rem;
  color: var(--text-secondary);
  margin-bottom: 24px;
}

.user-switcher {
  display: flex;
  gap: 12px;
  margin-bottom: 24px;
}

.user-switch-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 12px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all 0.2s ease;
  color: var(--text-primary);
}

.user-switch-btn.active {
  border-color: var(--accent-emerald);
  background: rgba(0, 168, 132, 0.1);
}

.user-avatar-sm {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: #2a3942;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  color: #fff;
  margin-bottom: 6px;
}

.form-group {
  text-align: left;
  margin-bottom: 16px;
}

.form-label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.form-input {
  width: 100%;
  padding: 12px 14px;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 0.95rem;
  font-family: inherit;
  outline: none;
  transition: border-color 0.2s ease;
}

.form-input:focus {
  border-color: var(--accent-emerald);
}

.btn-primary {
  width: 100%;
  padding: 14px;
  background: var(--accent-emerald);
  color: #111b21;
  font-weight: 700;
  font-size: 0.95rem;
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: opacity 0.2s, transform 0.1s;
}

.btn-primary:hover {
  opacity: 0.92;
}

.btn-primary:active {
  transform: scale(0.99);
}

/* Main Layout */
.app-layout {
  display: flex;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

/* Sidebar */
.app-sidebar {
  width: 380px;
  min-width: 320px;
  max-width: 440px;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  height: 100%;
  z-index: 10;
  transition: transform 0.3s ease;
}

.sidebar-header {
  height: 60px;
  padding: 0 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-header);
  border-bottom: 1px solid var(--border-color);
}

.profile-badge {
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
}

.profile-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: #00a884;
  color: #111b21;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
}

.profile-info {
  display: flex;
  flex-direction: column;
}

.profile-name {
  font-weight: 600;
  font-size: 0.95rem;
}

.gateway-pill {
  font-size: 0.72rem;
  color: var(--accent-emerald);
  display: flex;
  align-items: center;
  gap: 4px;
}

.gateway-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent-emerald);
  box-shadow: 0 0 6px var(--accent-emerald);
}

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

.icon-btn {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s;
}

.icon-btn:hover {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-primary);
}

/* Nav Tabs */
.sidebar-tabs {
  display: flex;
  background: var(--bg-sidebar);
  border-bottom: 1px solid var(--border-color);
  padding: 6px 12px;
  gap: 6px;
  overflow-x: auto;
}

.tab-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 12px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-full);
  color: var(--text-secondary);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.2s;
}

.tab-btn:hover {
  background: var(--bg-card);
  color: var(--text-primary);
}

.tab-btn.active {
  background: var(--bg-input);
  color: var(--accent-emerald);
  border-color: rgba(0, 168, 132, 0.3);
}

/* Search Container */
.sidebar-search {
  padding: 8px 14px;
  background: var(--bg-sidebar);
  border-bottom: 1px solid var(--border-color);
}

.search-bar {
  display: flex;
  align-items: center;
  background: var(--bg-input);
  border-radius: var(--radius-md);
  padding: 6px 12px;
  gap: 8px;
}

.search-input {
  background: transparent;
  border: none;
  outline: none;
  color: var(--text-primary);
  width: 100%;
  font-size: 0.88rem;
  font-family: inherit;
}

/* List Content */
.sidebar-content {
  flex: 1;
  overflow-y: auto;
}

.list-item {
  display: flex;
  align-items: center;
  padding: 12px 16px;
  gap: 12px;
  border-bottom: 1px solid var(--border-subtle);
  cursor: pointer;
  transition: background 0.15s ease;
}

.list-item:hover {
  background: var(--bg-header);
}

.list-item.active {
  background: var(--bg-card);
}

.item-avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--bg-input);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  flex-shrink: 0;
}

.item-details {
  flex: 1;
  min-width: 0;
}

.item-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 4px;
}

.item-title {
  font-weight: 600;
  font-size: 0.95rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.item-time {
  font-size: 0.72rem;
  color: var(--text-muted);
}

.item-subtitle {
  font-size: 0.82rem;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Main Viewport / Chat Area */
.app-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100%;
  background-color: var(--bg-chat);
  position: relative;
}

.chat-header {
  height: 60px;
  padding: 0 16px;
  background: var(--bg-header);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  z-index: 5;
}

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

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px 24px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background-image: radial-gradient(rgba(255, 255, 255, 0.03) 1px, transparent 1px);
  background-size: 20px 20px;
}

/* Message Bubbles */
.message-row {
  display: flex;
  width: 100%;
}

.message-row.user {
  justify-content: flex-end;
}

.message-row.assistant,
.message-row.proactive_task {
  justify-content: flex-start;
}

.message-bubble {
  max-width: 75%;
  min-width: 120px;
  padding: 10px 14px 6px;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  position: relative;
  font-size: 0.93rem;
  line-height: 1.45;
  user-select: text;
  word-break: break-word;
}

.message-row.user .message-bubble {
  background: var(--bg-bubble-outgoing);
  border-top-right-radius: 2px;
}

.message-row.assistant .message-bubble {
  background: var(--bg-bubble-incoming);
  border-top-left-radius: 2px;
}

.message-row.proactive_task .message-bubble {
  background: var(--bg-bubble-proactive);
  border: 1px solid var(--border-proactive);
  border-top-left-radius: 2px;
}

.proactive-badge-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  background: rgba(0, 168, 132, 0.2);
  color: var(--accent-emerald);
  font-size: 0.72rem;
  font-weight: 700;
  border-radius: var(--radius-full);
  margin-bottom: 6px;
}

.message-meta {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
  margin-top: 4px;
  font-size: 0.68rem;
  color: var(--text-muted);
}

.double-tick {
  color: var(--accent-blue);
  font-size: 0.85rem;
}

/* Markdown formatting inside bubbles */
.message-content p {
  margin-bottom: 8px;
}
.message-content p:last-child {
  margin-bottom: 0;
}
.message-content pre {
  background: rgba(0, 0, 0, 0.35);
  padding: 10px;
  border-radius: var(--radius-sm);
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  margin: 6px 0;
}
.message-content code {
  font-family: var(--font-mono);
  background: rgba(0, 0, 0, 0.2);
  padding: 2px 4px;
  border-radius: 4px;
  font-size: 0.88rem;
}
.message-content ul, .message-content ol {
  padding-left: 20px;
  margin: 6px 0;
}

/* Chat Input Area */
.chat-input-bar {
  padding: 10px 16px calc(10px + var(--safe-bottom));
  background: var(--bg-header);
  border-top: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  gap: 10px;
  z-index: 5;
}

.chat-input-wrapper {
  flex: 1;
  background: var(--bg-input);
  border-radius: var(--radius-lg);
  padding: 8px 14px;
  display: flex;
  align-items: center;
}

.chat-textarea {
  width: 100%;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-size: 0.95rem;
  font-family: inherit;
  resize: none;
  max-height: 120px;
  line-height: 1.4;
}

.btn-send {
  background: var(--accent-emerald);
  color: #111b21;
  border: none;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.15s ease;
  flex-shrink: 0;
}

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

.btn-send:active {
  transform: scale(0.95);
}

/* Modals */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 16px;
}

.modal-content {
  background: var(--bg-sidebar);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 24px;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.modal-title {
  font-size: 1.25rem;
  font-weight: 700;
}

/* Mobile Responsive */
@media (max-width: 768px) {
  .app-sidebar {
    width: 100%;
    max-width: 100%;
    position: absolute;
    inset: 0;
  }

  .app-main {
    position: absolute;
    inset: 0;
  }

  .app-layout.view-chat .app-sidebar {
    display: none;
  }

  .app-layout:not(.view-chat) .app-main {
    display: none;
  }

  .back-btn-mobile {
    display: flex !important;
  }
}

.back-btn-mobile {
  display: none;
}

/* Notification Permission Banner */
.notification-banner {
  background: linear-gradient(135deg, rgba(0, 168, 132, 0.18) 0%, rgba(37, 211, 102, 0.08) 100%);
  border-bottom: 1px solid rgba(0, 168, 132, 0.3);
  padding: 10px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  animation: slideDown 0.3s ease;
  z-index: 10;
}

.notification-banner.hidden {
  display: none !important;
}

.banner-left {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
}

.banner-icon {
  font-size: 1.3rem;
  line-height: 1;
}

.banner-title {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-primary);
}

.banner-desc {
  font-size: 0.75rem;
  color: var(--text-secondary);
  line-height: 1.3;
}

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

.btn-banner-enable {
  background: var(--accent-emerald);
  color: #ffffff;
  border: none;
  border-radius: var(--radius-full);
  padding: 6px 14px;
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.2s ease;
  box-shadow: 0 2px 6px rgba(0, 168, 132, 0.4);
}

.btn-banner-enable:hover {
  background: #02906f;
  transform: scale(1.02);
}

.btn-banner-dismiss {
  background: transparent;
  color: var(--text-muted);
  border: none;
  font-size: 1rem;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-banner-dismiss:hover {
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.08);
}

.notification-toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--bg-card);
  border: 1px solid var(--accent-emerald);
  color: var(--text-primary);
  padding: 12px 18px;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  font-size: 0.85rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 10px;
  z-index: 1000;
  animation: slideUp 0.3s ease;
}

@keyframes slideDown {
  from { transform: translateY(-100%); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

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