/* ─────────────────────────────────────────────────────────────
   Stocgle Chat UI — Sidebar layout styles
   ───────────────────────────────────────────────────────────── */

:root {
  --sidebar-w: 240px;
  --bg: #f9fafb;
  --surface: #ffffff;
  --border: #e5e7eb;
  --text: #111827;
  --text-muted: #6b7280;
  --primary: #0ea5e9;
  --primary-hover: #0284c7;
  --radius: 10px;
  --radius-sm: 7px;
  --font: 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  height: 100vh;
  height: 100dvh;   /* dynamic viewport height — accounts for mobile browser chrome */
  overflow: hidden;
}

/* ── Two-column layout ─────────────────────────────────────── */
.layout {
  display: flex;
  height: 100vh;
  height: 100dvh;
  width: 100%;
}

/* ── Sidebar ───────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: #0f172a;
  display: flex;
  flex-direction: column;
  padding: 16px 12px;
  gap: 12px;
  overflow: hidden;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 6px 12px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  text-decoration: none;
  cursor: pointer;
}

.sidebar-logo .logo-img {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  object-fit: contain;
}

.sidebar-logo .logo-text {
  font-size: 15px;
  font-weight: 700;
  color: #f1f5f9;
  letter-spacing: -0.01em;
}

.btn-new-chat {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 9px 12px;
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: var(--radius-sm);
  color: #e2e8f0;
  font-size: 13px;
  font-family: var(--font);
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s;
}

.btn-new-chat:hover {
  background: rgba(255,255,255,0.12);
}

.sidebar-history {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-top: 4px;
}

.sidebar-history::-webkit-scrollbar { width: 4px; }
.sidebar-history::-webkit-scrollbar-track { background: transparent; }
.sidebar-history::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 4px; }

/* Empty sidebar placeholder */
.history-empty {
  padding: 10px;
  color: rgba(255,255,255,0.2);
  font-size: 12px;
  text-align: center;
}

/* History items injected by app.js */
.history-item {
  padding: 7px 10px;
  border-radius: var(--radius-sm);
  color: #94a3b8;
  font-size: 12.5px;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: background 0.12s, color 0.12s;
}
.history-item:hover { background: rgba(255,255,255,0.06); color: #e2e8f0; }
.history-item.active { background: rgba(14,165,233,0.15); color: #38bdf8; }

/* ── Main area ─────────────────────────────────────────────── */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--surface);
}

/* ── Chat header ───────────────────────────────────────────── */
.chat-header {
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
}

.chat-header .header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.header-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
}

/* Company lock banner (injected by app.js) */
.lock-banner {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-muted);
  background: #f0f9ff;
  border: 1px solid #bae6fd;
  border-radius: var(--radius-sm);
  padding: 6px 12px;
}
.lock-clear {
  margin-left: auto;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 16px;
  line-height: 1;
}
.lock-clear:hover { color: var(--text); }

/* ── Messages ──────────────────────────────────────────────── */
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px 20px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  scroll-behavior: smooth;
}

.messages::-webkit-scrollbar { width: 5px; }
.messages::-webkit-scrollbar-track { background: transparent; }
.messages::-webkit-scrollbar-thumb { background: #d1d5db; border-radius: 4px; }

/* ── Welcome screen ────────────────────────────────────────── */
.welcome {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 48px 24px;
  gap: 12px;
}

.welcome-logo {
  width: 64px;
  height: 64px;
  border-radius: 16px;
  object-fit: contain;
  margin-bottom: 8px;
}

.welcome h2 {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.02em;
}

.welcome-hint {
  font-size: 14px;
  color: var(--text-muted);
  max-width: 380px;
}

/* ── Message bubbles ───────────────────────────────────────── */
.msg {
  display: flex;
  flex-direction: column;
  max-width: 100%;
}

.msg-user {
  align-items: flex-end;
}

.msg-user .msg-bubble {
  background: #0ea5e9;
  color: #ffffff;
  padding: 10px 14px;
  border-radius: 14px 14px 4px 14px;
  font-size: 14px;
  max-width: 75%;
}

.msg-assistant {
  align-items: flex-start;
}

.msg-body {
  font-size: 14.5px;
  line-height: 1.7;
  color: var(--text);
  max-width: 100%;
}

.msg-body p { margin: 0 0 10px; }
.msg-body p:last-child { margin-bottom: 0; }
.msg-body strong { font-weight: 600; }
.msg-body ul, .msg-body ol { padding-left: 20px; margin: 8px 0; }
.msg-body li { margin: 4px 0; }
.msg-body h3 { font-size: 15px; font-weight: 700; margin: 14px 0 6px; }
.msg-body code { background: #f3f4f6; padding: 1px 5px; border-radius: 4px; font-size: 13px; }

/* Thinking card */
.thinking-card {
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  margin-bottom: 12px;
}
.thinking-header {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
}
.thinking-dots {
  display: inline-flex;
  align-items: center;
  gap: 3px;
}
.thinking-dots span {
  display: inline-block;
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--primary);
  animation: dot-bounce 1.2s infinite;
}
.thinking-dots span:nth-child(2) { animation-delay: 0.2s; }
.thinking-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes dot-bounce {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.5; }
  40% { transform: translateY(-5px); opacity: 1; }
}

/* Live step items */
.thinking-steps { margin: 8px 0 0; padding-left: 0; list-style: none; display: flex; flex-direction: column; gap: 4px; }
.thinking-step-live {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  color: var(--text-muted);
  animation: step-fade-in 0.25s ease;
}
.step-icon { font-size: 13px; }
@keyframes step-fade-in {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* Done state */
.thinking-done { background: #f0fdf4; border-color: #bbf7d0; }
.thinking-done .thinking-header { color: #15803d; }
.thinking-check { color: #16a34a; font-size: 14px; }

/* ── Charts wrap – side-by-side when multiple ──────────────── */
.charts-wrap {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 14px;
}
.chart-card {
  flex: 1 1 280px;
  min-width: 240px;
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.chart-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px 6px;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
}
.chart-ticker { font-size: 13px; color: var(--text); font-weight: 700; letter-spacing: 0.04em; }
.chart-body { height: 140px; padding: 0 8px 8px; }
.chart-loading { font-size: 12px; color: var(--text-muted); text-align: center; padding: 8px; }

/* ── Error text ───────────────────────────────────────────── */
.error-text {
  color: #dc2626;
  font-size: 13.5px;
  padding: 8px 0;
}

/* ── Input bar ─────────────────────────────────────────────── */
.input-bar {
  padding: 14px 20px 18px;
  border-top: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
}

.input-wrap {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: #f9fafb;
  border: 1.5px solid var(--border);
  border-radius: 14px;
  padding: 8px 10px;
  transition: border-color 0.15s;
}

.input-wrap:focus-within {
  border-color: var(--primary);
  background: var(--surface);
}

.input-wrap textarea {
  flex: 1;
  border: none;
  background: transparent;
  resize: none;
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  max-height: 140px;
  outline: none;
  padding: 2px 0;
}

.input-wrap textarea::placeholder { color: var(--text-muted); }

.btn-icon {
  flex-shrink: 0;
  width: 34px;
  height: 34px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.12s, color 0.12s;
}
.btn-icon:hover { background: #f3f4f6; color: var(--text); }

.btn-send {
  flex-shrink: 0;
  width: 34px;
  height: 34px;
  border: none;
  background: var(--primary);
  color: white;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}
.btn-send:hover { background: var(--primary-hover); }
.btn-send:disabled { background: #d1d5db; cursor: not-allowed; }

/* ── Message actions ───────────────────────────────────────── */
.msg-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  opacity: 0;
  transition: opacity 0.15s;
}
.msg:hover .msg-actions { opacity: 1; }
.msg-actions button, .msg-actions .action-link {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 12px;
  padding: 3px 6px;
  border-radius: 5px;
  font-family: var(--font);
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 4px;
}
.msg-actions button:hover, .msg-actions .action-link:hover {
  background: #f3f4f6;
  color: var(--text);
}

/* ── Related questions ─────────────────────────────────────── */
.related { margin-top: 16px; }
.related-title {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 8px;
}
.related-list { display: flex; flex-direction: column; gap: 6px; }
.related-q {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  background: #f9fafb;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
  transition: background 0.12s;
}
.related-q:hover { background: #f0f9ff; border-color: #bae6fd; }
.related-q .plus { color: var(--text-muted); font-size: 16px; }

/* ── Data tables & snippets ────────────────────────────────── */
.snippet {
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  margin: 12px 0;
}
.snippet-title {
  padding: 10px 14px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  background: #f1f5f9;
  border-bottom: 1px solid var(--border);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.snippet-body { padding: 14px; }

.metrics-table, .data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.metrics-table th, .metrics-table td,
.data-table th, .data-table td {
  padding: 8px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}
.metrics-table th, .data-table th {
  font-weight: 600;
  color: var(--text-muted);
  background: #f8fafc;
}
.metrics-table tr:last-child td,
.data-table tr:last-child td { border-bottom: none; }

/* ── Auth modal ────────────────────────────────────────────── */
.auth-modal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.6);
  backdrop-filter: blur(4px);
  z-index: 1000;
  align-items: center;
  justify-content: center;
}
.auth-modal.visible {
  display: flex;
}

.auth-modal-box {
  background: #ffffff;
  border-radius: 16px;
  padding: 32px 28px 28px;
  width: 100%;
  max-width: 380px;
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.18);
  animation: modal-pop 0.2s ease;
}
@keyframes modal-pop {
  from { opacity: 0; transform: scale(0.95) translateY(8px); }
  to   { opacity: 1; transform: scale(1)    translateY(0); }
}

.auth-modal-close {
  position: absolute;
  top: 14px;
  right: 16px;
  background: none;
  border: none;
  font-size: 18px;
  color: var(--text-muted);
  cursor: pointer;
  line-height: 1;
  padding: 4px;
  border-radius: 6px;
}
.auth-modal-close:hover { background: #f3f4f6; color: var(--text); }

.auth-modal-logo {
  width: 52px;
  height: 52px;
  border-radius: 12px;
  object-fit: contain;
}

.auth-modal-heading {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--text);
  margin: 0;
  letter-spacing: -0.01em;
  text-align: center;
}

.auth-modal-sub {
  font-size: 13.5px;
  color: var(--text-muted);
  text-align: center;
  margin: 0;
  line-height: 1.5;
}

/* Preview of the message the user was trying to send */
.auth-pending-preview {
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  width: 100%;
  font-size: 13px;
}
.auth-pending-label {
  display: block;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 4px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.auth-pending-text {
  color: var(--text);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* Google sign-in button */
.auth-google-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  padding: 11px 16px;
  background: #fff;
  border: 1.5px solid #dadce0;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  color: #3c4043;
  font-family: var(--font);
  cursor: pointer;
  margin-top: 4px;
  transition: background 0.12s, box-shadow 0.12s;
}
.auth-google-btn:hover {
  background: #f8fafc;
  box-shadow: 0 1px 4px rgba(0,0,0,0.12);
}

/* ── Header user info ──────────────────────────────────────── */
#chat-user-info {
  display: flex;
  align-items: center;
  gap: 10px;
}

.chat-user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
  overflow: hidden;
  flex-shrink: 0;
}
.chat-user-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.chat-signout-btn,
.chat-signin-header-btn {
  font-size: 12px;
  font-family: var(--font);
  font-weight: 500;
  padding: 5px 12px;
  border-radius: 6px;
  cursor: pointer;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text-muted);
  transition: background 0.12s, color 0.12s;
}
.chat-signout-btn:hover,
.chat-signin-header-btn:hover {
  background: #f3f4f6;
  color: var(--text);
}

/* ── Sidebar auth prompt (guest state) ─────────────────────── */
.sidebar-auth-prompt {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 8px 4px;
}
.sidebar-auth-hint {
  font-size: 11.5px;
  color: rgba(255,255,255,0.35);
  line-height: 1.4;
  margin: 0;
}
.sidebar-signin-btn {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(255,255,255,0.12);
  background: rgba(255,255,255,0.07);
  color: #e2e8f0;
  font-size: 12.5px;
  font-family: var(--font);
  font-weight: 500;
  cursor: pointer;
  transition: background 0.12s;
}
.sidebar-signin-btn:hover { background: rgba(255,255,255,0.14); }

/* ── Mobile drawer overlay ─────────────────────────────────── */
.mobile-drawer-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  z-index: 200;
  opacity: 0;
  transition: opacity 0.25s ease;
}
.mobile-drawer-overlay.visible {
  display: block;
  opacity: 1;
}

/* ── Mobile drawer panel ───────────────────────────────────── */
.mobile-drawer {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: 280px;
  max-width: 85vw;
  background: #0f172a;
  z-index: 300;
  display: flex;
  flex-direction: column;
  padding: 16px 12px;
  gap: 10px;
  transform: translateX(-100%);
  transition: transform 0.28s cubic-bezier(0.22, 1, 0.36, 1);
  overflow: hidden;
}
.mobile-drawer.open {
  transform: translateX(0);
}

.mobile-drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  margin-bottom: 4px;
}

.btn-close-drawer {
  width: 32px;
  height: 32px;
  border: none;
  background: rgba(255, 255, 255, 0.07);
  border-radius: 8px;
  color: #94a3b8;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.12s, color 0.12s;
}
.btn-close-drawer:hover {
  background: rgba(255, 255, 255, 0.14);
  color: #e2e8f0;
}

.drawer-section-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.25);
  padding: 4px 4px 0;
  margin-top: 4px;
}

/* ── Safe area support (notched phones) ───────────────────── */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
  .input-bar {
    padding-bottom: calc(14px + env(safe-area-inset-bottom));
  }
  .mobile-drawer {
    padding-bottom: calc(16px + env(safe-area-inset-bottom));
  }
}

/* ── Responsive ────────────────────────────────────────────── */
@media (max-width: 640px) {
  .sidebar { display: none; }
  .main { width: 100%; }
  .auth-modal-box { margin: 16px; }

  /* Mobile hamburger button — only visible on mobile */
  .btn-mobile-menu {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    border-radius: 8px;
    cursor: pointer;
    flex-shrink: 0;
    -webkit-tap-highlight-color: transparent;
    transition: background 0.12s, color 0.12s;
  }
  .btn-mobile-menu:hover { background: #f3f4f6; color: var(--text); }

  /* Mobile home logo link — visible on mobile */
  .mobile-home-link {
    display: flex;
    align-items: center;
    gap: 7px;
    text-decoration: none;
    flex: 1;
    padding-left: 4px;
  }
  .mobile-header-logo {
    width: 24px;
    height: 24px;
    border-radius: 6px;
    object-fit: contain;
  }
  .mobile-header-brand {
    font-size: 15px;
    font-weight: 700;
    color: var(--text);
    letter-spacing: -0.01em;
  }

  /* Hide desktop-only title on mobile */
  .desktop-only { display: none; }

  /* Tighter header on mobile */
  .chat-header { padding: 10px 14px; }
  .messages { padding: 16px 14px; gap: 16px; }
  .input-bar { padding: 10px 12px 14px; }
  .msg-user .msg-bubble { max-width: 88%; }

  /* Bigger touch targets on mobile */
  .btn-icon, .btn-send {
    width: 40px;
    height: 40px;
  }

  /* Prevent iOS Safari auto-zoom on input focus (requires >= 16px) */
  .input-wrap textarea {
    font-size: 16px;
  }

  /* Welcome: center vertically in available space.
     The layout is bounded by 100dvh so input bar stays visible. */
  .welcome {
    flex: 1;
    justify-content: center;
    padding: 24px;
  }
  .welcome-logo {
    width: 56px;
    height: 56px;
  }
  .welcome h2 {
    font-size: 1.3rem;
  }
}

/* Desktop: hide mobile-only elements */
@media (min-width: 641px) {
  .btn-mobile-menu  { display: none; }
  .mobile-home-link { display: none; }
  .mobile-drawer    { display: none; }
  .mobile-drawer-overlay { display: none !important; }
}
