/* =====================================================================
   Mercurio Advisor Bot - Design System & Modern Responsive UI Stylesheet
   Built with Vanilla CSS, CSS Custom Properties, and HSL Color Palette
   ===================================================================== */

:root {
  /* Design Tokens - Color Palette */
  --bg-primary: #090d16;
  --bg-secondary: #0f172a;
  --bg-card: rgba(30, 41, 59, 0.7);
  --bg-glass: rgba(15, 23, 42, 0.75);
  --bg-hover: rgba(51, 65, 85, 0.6);
  
  --border-color: rgba(255, 255, 255, 0.08);
  --border-active: rgba(56, 189, 248, 0.4);
  
  --accent-primary: #0284c7;
  --accent-secondary: #38bdf8;
  --accent-gradient: linear-gradient(135deg, #0284c7 0%, #38bdf8 100%);
  --accent-glow: rgba(56, 189, 248, 0.25);
  
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --text-subtle: #64748b;
  
  --user-msg-bg: linear-gradient(135deg, #0369a1 0%, #0284c7 100%);
  --bot-msg-bg: rgba(30, 41, 59, 0.85);
  
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.2);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 16px 40px rgba(0, 0, 0, 0.5);
  
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  
  --transition-fast: 0.15s ease;
  --transition-normal: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  --font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

/* Light Theme Variables Toggle Support */
[data-theme="light"] {
  --bg-primary: #f1f5f9;
  --bg-secondary: #ffffff;
  --bg-card: rgba(241, 245, 249, 0.9);
  --bg-glass: rgba(255, 255, 255, 0.85);
  --bg-hover: #e2e8f0;
  
  --border-color: rgba(0, 0, 0, 0.08);
  --border-active: #0284c7;
  
  --text-main: #0f172a;
  --text-muted: #475569;
  --text-subtle: #94a3b8;
  
  --user-msg-bg: linear-gradient(135deg, #0284c7 0%, #38bdf8 100%);
  --bot-msg-bg: #ffffff;
}

/* Base Reset & Global Styles */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: var(--font-family);
  -webkit-font-smoothing: antialiased;
}

body, html {
  height: 100%;
  width: 100%;
  background-color: var(--bg-primary);
  color: var(--text-main);
  overflow: hidden;
}

/* App Layout Grid */
.app-container {
  display: flex;
  height: 100vh;
  width: 100vw;
  background-color: var(--bg-primary);
}

/* Sidebar Navigation Drawer (Desktop & Mobile Responsive) */
.sidebar {
  width: 320px;
  min-width: 320px;
  background-color: var(--bg-secondary);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  height: 100%;
  transition: transform var(--transition-normal);
  z-index: 100;
}

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

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

.brand-icon {
  width: 38px;
  height: 38px;
  background: var(--accent-gradient);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: bold;
  font-size: 20px;
  box-shadow: 0 0 15px var(--accent-glow);
}

.brand-title {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.3px;
  color: var(--text-main);
}

.brand-subtitle {
  font-size: 11px;
  color: var(--text-muted);
}

/* Sidebar Balance Card Widget */
.sidebar-balance-card {
  margin: 14px 20px 4px 20px;
  padding: 12px 16px;
  background: var(--bg-card);
  border: 1px solid var(--border-active);
  border-radius: var(--radius-md);
  display: flex;
  flex-direction: column;
  gap: 4px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.15);
}

.balance-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-subtle);
}

.balance-amount {
  font-size: 18px;
  font-weight: 700;
  color: #22c55e;
  letter-spacing: -0.3px;
}

.new-chat-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin: 16px 20px;
  padding: 12px;
  background: var(--accent-gradient);
  color: #ffffff;
  border: none;
  border-radius: var(--radius-md);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: transform var(--transition-fast), box-shadow var(--transition-fast);
}

.new-chat-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px var(--accent-glow);
}

.new-chat-btn:active {
  transform: translateY(0);
}

.sessions-list-container {
  flex: 1;
  overflow-y: auto;
  padding: 10px 14px;
}

.sessions-section-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-subtle);
  margin: 12px 8px 8px 8px;
}

.session-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  cursor: pointer;
  color: var(--text-muted);
  font-size: 13.5px;
  margin-bottom: 6px;
  transition: background var(--transition-fast), color var(--transition-fast);
  border: 1px solid transparent;
}

.session-item:hover {
  background: var(--bg-hover);
  color: var(--text-main);
}

.session-item.active {
  background: var(--bg-card);
  color: var(--accent-secondary);
  border-color: var(--border-active);
  font-weight: 600;
}

.session-item-title {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 220px;
}

/* Main Chat Area */
.chat-wrapper {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100%;
  position: relative;
  background-color: var(--bg-primary);
  min-width: 0;
  width: 100%;
  max-width: 100%;
  overflow: hidden;
}

.chat-header {
  height: 64px;
  padding: 0 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-glass);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-color);
  z-index: 10;
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  min-width: 0;
}

.chat-header-left {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.mobile-menu-toggle {
  display: none;
  background: none;
  border: none;
  color: var(--text-main);
  font-size: 22px;
  cursor: pointer;
  padding: 4px;
}

.agent-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 13px;
  min-width: 0;
}

.status-dot {
  width: 8px;
  height: 8px;
  background-color: #22c55e;
  border-radius: 50%;
  box-shadow: 0 0 8px rgba(34, 197, 94, 0.6);
  flex-shrink: 0;
}

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

.icon-btn {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  width: 38px;
  height: 38px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all var(--transition-fast);
  flex-shrink: 0;
}

.icon-btn:hover {
  background: var(--bg-hover);
  border-color: var(--border-active);
  color: var(--accent-secondary);
}

/* Chat Messages Box */
.messages-container {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  scroll-behavior: smooth;
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  min-width: 0;
}

.message-row {
  display: flex;
  gap: 14px;
  max-width: 85%;
  min-width: 0;
  animation: fadeIn 0.3s ease;
  box-sizing: border-box;
}

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

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

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

.avatar {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 700;
  flex-shrink: 0;
}

.avatar.user {
  background: #475569;
  color: #fff;
}

.avatar.bot {
  background: var(--accent-gradient);
  color: #fff;
  box-shadow: 0 0 10px var(--accent-glow);
}

.message-bubble {
  padding: 14px 18px;
  border-radius: var(--radius-lg);
  font-size: 14.5px;
  line-height: 1.6;
  box-shadow: var(--shadow-sm);
  position: relative;
  word-break: break-word;
  overflow-wrap: anywhere;
  word-wrap: break-word;
  min-width: 0;
  max-width: 100%;
  box-sizing: border-box;
}

.message-row.user .message-bubble {
  background: var(--user-msg-bg);
  color: #ffffff;
  border-bottom-right-radius: 4px;
}

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

/* Typography and Markdown rendering inside messages */
.message-bubble * {
  max-width: 100%;
  box-sizing: border-box;
}
.message-bubble p {
  margin-bottom: 10px;
  word-break: break-word;
  overflow-wrap: anywhere;
}
.message-bubble p:last-child {
  margin-bottom: 0;
}
.message-bubble h1,
.message-bubble h2,
.message-bubble h3,
.message-bubble h4 {
  color: var(--accent-secondary);
  margin: 14px 0 8px 0;
  font-weight: 600;
  line-height: 1.3;
  word-break: break-word;
}
.message-bubble h1 { font-size: 1.25em; border-bottom: 1px solid var(--border-color); padding-bottom: 4px; }
.message-bubble h2 { font-size: 1.15em; }
.message-bubble h3 { font-size: 1.05em; }
.message-bubble h4 { font-size: 1.0em; }

.message-bubble ul,
.message-bubble ol {
  margin: 8px 0 12px 22px;
  padding: 0;
}
.message-bubble li {
  margin-bottom: 4px;
  word-break: break-word;
}
.message-bubble blockquote {
  border-left: 3px solid var(--accent-secondary);
  background: rgba(56, 189, 248, 0.08);
  padding: 8px 12px;
  margin: 10px 0;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  word-break: break-word;
}
.message-bubble code {
  background: rgba(0, 0, 0, 0.35);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 13px;
  color: #38bdf8;
  word-break: break-word;
  white-space: pre-wrap;
}
.message-bubble pre {
  background: #090d16;
  border: 1px solid var(--border-color);
  padding: 12px 14px;
  border-radius: var(--radius-md);
  overflow-x: auto;
  margin: 10px 0;
  max-width: 100%;
  box-sizing: border-box;
  white-space: pre-wrap;
  word-break: break-word;
}
.message-bubble pre code {
  background: transparent;
  padding: 0;
  border-radius: 0;
  display: block;
  color: #f8fafc;
  font-size: 13px;
  white-space: pre-wrap;
}
.message-bubble table {
  display: block;
  max-width: 100%;
  overflow-x: auto;
  width: 100%;
  border-collapse: collapse;
}
.message-bubble img {
  max-width: 100%;
  height: auto;
}
.message-bubble a {
  color: var(--accent-secondary);
  text-decoration: underline;
  word-break: break-all;
}
.message-bubble a:hover {
  color: #7dd3fc;
}
.message-bubble hr {
  border: none;
  border-top: 1px solid var(--border-color);
  margin: 14px 0;
}

/* Chat Input Footer Area */
.chat-footer {
  padding: 16px 24px 24px 24px;
  background: var(--bg-primary);
  border-top: 1px solid var(--border-color);
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  min-width: 0;
}

.input-box-wrapper {
  max-width: 900px;
  margin: 0 auto;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 8px 12px 8px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  box-shadow: var(--shadow-md);
  transition: border-color var(--transition-fast);
}

.input-box-wrapper:focus-within {
  border-color: var(--border-active);
  box-shadow: 0 0 16px var(--accent-glow);
}

.chat-input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text-main);
  font-size: 15px;
  resize: none;
  max-height: 150px;
  min-height: 24px;
  line-height: 1.5;
}

.send-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--accent-gradient);
  border: none;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform var(--transition-fast);
  flex-shrink: 0;
}

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

/* Search Modal Drawer overlay */
.modal-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(8px);
  z-index: 1000;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

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

.modal-content {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 700px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}

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

.modal-body {
  padding: 24px;
  overflow-y: auto;
}

/* Scrollbar Customization */
::-webkit-scrollbar {
  width: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.15);
  border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.3);
}

.sidebar-close-btn {
  display: none;
  background: none;
  border: none;
  color: var(--text-main);
  font-size: 20px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  transition: background var(--transition-fast);
}

.sidebar-close-btn:hover {
  background: var(--bg-hover);
  color: var(--accent-secondary);
}

.sidebar-backdrop {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 90;
  display: none;
  opacity: 0;
  transition: opacity var(--transition-normal);
}

.sidebar-backdrop.active {
  display: block;
  opacity: 1;
}

/* Responsive Media Queries & Mobile Adaptations */
@media (max-width: 768px) {
  body, html, .app-container {
    height: 100dvh;
    height: var(--app-height, 100vh);
  }

  .sidebar {
    position: fixed;
    top: 0; bottom: 0; left: 0;
    width: 85vw;
    max-width: 320px;
    min-width: auto;
    height: 100dvh;
    height: var(--app-height, 100vh);
    transform: translateX(-100%);
    box-shadow: var(--shadow-lg);
    z-index: 200;
  }
  
  .sidebar.open {
    transform: translateX(0);
  }

  .sidebar-close-btn {
    display: block;
  }
  
  .mobile-menu-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border-radius: var(--radius-md);
    background: var(--bg-card);
    border: 1px solid var(--border-color);
  }
  
  .chat-header {
    height: 56px;
    padding: 0 12px;
    padding-top: env(safe-area-inset-top);
  }

  .chat-header-left {
    gap: 8px;
  }

  .agent-badge {
    padding: 4px 10px;
    font-size: 12px;
  }

  .agent-badge-text {
    max-width: 140px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .chat-header-actions {
    gap: 6px;
  }

  .icon-btn {
    width: 36px;
    height: 36px;
    font-size: 15px;
  }

  .user-badge {
    font-size: 11px;
    padding: 3px 7px;
    max-width: 100px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .messages-container {
    padding: 12px 10px;
    gap: 14px;
    -webkit-overflow-scrolling: touch;
  }

  .message-row {
    max-width: 95%;
    gap: 8px;
  }

  .avatar {
    width: 32px;
    height: 32px;
    font-size: 12px;
    border-radius: 10px;
  }

  .message-bubble {
    padding: 10px 14px;
    font-size: 14px;
    line-height: 1.5;
    border-radius: 16px;
  }

  .chat-footer {
    padding: 8px 10px calc(8px + env(safe-area-inset-bottom, 0px)) 10px;
    width: 100%;
    max-width: 100vw;
    box-sizing: border-box;
    overflow: hidden;
  }

  .input-box-wrapper {
    width: 100%;
    max-width: 100%;
    padding: 6px 8px 6px 12px;
    border-radius: 24px;
    box-sizing: border-box;
    min-width: 0;
  }

  /* 16px font-size prevents iOS Safari from auto-zooming on focus */
  .chat-input {
    font-size: 16px;
    min-height: 22px;
    max-height: 120px;
    width: 100%;
    min-width: 0;
    box-sizing: border-box;
    flex: 1;
  }

  .send-btn {
    width: 36px;
    height: 36px;
    min-width: 36px;
  }

  .modal-overlay {
    padding: 10px;
    align-items: flex-end;
  }

  .modal-content {
    max-height: 90dvh;
    border-radius: 20px 20px 0 0;
  }

  .modal-header {
    padding: 14px 18px;
  }

  .modal-body {
    padding: 16px;
  }

  .auth-card {
    padding: 24px 18px;
    border-radius: 16px;
  }
}

@media (max-width: 480px) {
  .agent-badge-text {
    display: none;
  }

  .brand-title {
    font-size: 14px;
  }

  .brand-subtitle {
    font-size: 10px;
  }

  .user-badge {
    display: none !important;
  }
}

/* =====================================================================
   Auth Screen & User Accounts Management Styles
   ===================================================================== */
.auth-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: radial-gradient(circle at center, #1e293b 0%, #0f172a 100%);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.auth-card {
  width: 100%;
  max-width: 420px;
  background: rgba(30, 41, 59, 0.85);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 20px;
  padding: 35px 30px;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.5);
  animation: authCardFadeIn 0.3s ease-out;
}

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

.auth-header {
  text-align: center;
  margin-bottom: 25px;
}

.auth-brand-icon {
  width: 52px;
  height: 52px;
  background: linear-gradient(135deg, var(--accent-color), var(--accent-secondary));
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 24px;
  color: #fff;
  margin: 0 auto 12px;
  box-shadow: 0 4px 12px rgba(2, 132, 199, 0.4);
}

.auth-header h2 {
  margin: 0 0 6px 0;
  font-size: 22px;
  font-weight: 700;
  color: var(--text-main);
}

.auth-header p {
  margin: 0;
  font-size: 14px;
  color: var(--text-subtle);
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.auth-error-alert {
  background: rgba(244, 63, 94, 0.15);
  border: 1px solid rgba(244, 63, 94, 0.4);
  color: #f43f5e;
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 13px;
  text-align: center;
}

.form-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-field label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-subtle);
}

.form-field input {
  padding: 12px 14px;
  background: rgba(15, 23, 42, 0.8);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  font-size: 14px;
  color: var(--text-main);
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.form-field input:focus {
  border-color: var(--accent-secondary);
  box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.15);
}

.auth-submit-btn {
  padding: 14px;
  background: linear-gradient(135deg, var(--accent-color), #0369a1);
  color: #fff;
  border: none;
  border-radius: 12px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  margin-top: 8px;
  transition: transform 0.15s ease, background 0.2s;
  box-shadow: 0 4px 12px rgba(2, 132, 199, 0.3);
}

.auth-submit-btn:hover {
  transform: translateY(-1px);
  background: linear-gradient(135deg, #0369a1, #075985);
}

.auth-submit-btn:active {
  transform: translateY(0);
}

.user-badge {
  background: rgba(2, 132, 199, 0.15);
  border: 1px solid rgba(56, 189, 248, 0.3);
  padding: 4px 10px;
  border-radius: 8px;
}

.users-table th, .users-table td {
  border-bottom: 1px solid var(--border-color);
  padding: 10px 8px;
}

.users-table tbody tr:hover {
  background: var(--bg-hover);
}

