/* ══════════════════════════════════════════
 MAI Deal - Chat & Sidebar Styles
 ══════════════════════════════════════════ */

/* ══════════════════════════════════════════
   MAI Deal - Conversation Sidebar
   ══════════════════════════════════════════ */

/* ── Sidebar Layout ── */
.chat-layout {
  display: flex;
  width: 100%;
  height: 100%;
}

.chat-sidebar {
  width: 280px;
  min-width: 280px;
  background: #0a0a0a;
  border-right: 1px solid var(--dark-border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1), width 0.3s;
}

.chat-sidebar-header {
  padding: 1rem 1rem 0.75rem;
  border-bottom: 1px solid var(--dark-border);
  flex-shrink: 0;
}

.chat-sidebar-new-btn {
  width: 100%;
  padding: 0.65rem 1rem;
  background: transparent;
  border: 1px solid var(--gold-dim);
  color: var(--gold);
  font-family: 'Instrument Sans', sans-serif;
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  transition: all 0.2s;
}

.chat-sidebar-new-btn:hover {
  background: rgba(200, 170, 110, 0.08);
  border-color: var(--gold);
}

.chat-sidebar-new-btn svg {
  width: 16px;
  height: 16px;
}

.chat-sidebar-footer {
  padding: 0.5rem 1rem;
  border-top: 1px solid var(--dark-border);
  flex-shrink: 0;
}
.chat-sidebar-email {
  font-size: 0.7rem;
  color: var(--text-secondary);
  padding: 4px 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-switch-btn {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 0.65rem;
  cursor: pointer;
  padding: 0;
  text-decoration: underline;
  transition: color 0.15s;
}
.chat-switch-btn:hover { color: var(--text-primary); }
.chat-sidebar-list {
  flex: 1;
  overflow-y: auto;
  padding: 0.5rem 0;
}

.chat-sidebar-list::-webkit-scrollbar { width: 3px; }
.chat-sidebar-list::-webkit-scrollbar-thumb { background: var(--dark-border); border-radius: 2px; }

.chat-sidebar-section-label {
  padding: 0.75rem 1rem 0.35rem;
  font-size: 0.6rem;
  font-weight: 700;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--text-muted);
  font-family: 'Instrument Sans', sans-serif;
}

.chat-sidebar-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.6rem 1rem;
  cursor: pointer;
  transition: background 0.15s;
  position: relative;
  border-left: 2px solid transparent;
}

.chat-sidebar-item:hover { background: rgba(255, 255, 255, 0.03); }
.chat-sidebar-item.active { background: rgba(200, 170, 110, 0.06); border-left-color: var(--gold); }

.chat-sidebar-item-icon {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.04);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 0.7rem;
}

.chat-sidebar-item-icon.buyer { color: #6BC5A0; }
.chat-sidebar-item-icon.seller { color: #F0A05E; }
.chat-sidebar-item-icon.valuation { color: #7EB1E0; }
.chat-sidebar-item-icon.deal { color: #C09AE0; }

.chat-sidebar-item-content { flex: 1; min-width: 0; }

.chat-sidebar-item-title {
  font-size: 0.78rem;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-family: 'Instrument Sans', sans-serif;
  line-height: 1.3;
}

.chat-sidebar-item-meta {
  font-size: 0.62rem;
  color: var(--text-muted);
  margin-top: 0.15rem;
}

.chat-sidebar-item-pin {
  opacity: 0;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0.2rem;
  transition: all 0.15s;
  flex-shrink: 0;
}

.chat-sidebar-item:hover .chat-sidebar-item-pin { opacity: 0.6; }
.chat-sidebar-item-pin:hover { opacity: 1 !important; color: var(--gold); }
.chat-sidebar-item-pin.pinned { opacity: 1; color: var(--gold-dim); }

.chat-ctx-menu {
  position: fixed;
  z-index: 99999;
  background: #141414;
  border: 1px solid var(--dark-border);
  border-radius: 6px;
  padding: 0.3rem 0;
  min-width: 160px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.6);
  display: none;
  font-family: 'Instrument Sans', sans-serif;
}

.chat-ctx-menu.visible { display: block; }

.chat-ctx-menu-item {
  padding: 0.5rem 1rem;
  font-size: 0.78rem;
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  transition: background 0.1s;
}

.chat-ctx-menu-item:hover { background: rgba(255, 255, 255, 0.05); color: var(--text-primary); }
.chat-ctx-menu-item.danger { color: #e05555; }
.chat-ctx-menu-item.danger:hover { background: rgba(224, 85, 85, 0.08); }
.chat-ctx-menu-divider { height: 1px; background: var(--dark-border); margin: 0.25rem 0; }
.chat-ctx-menu-item svg { width: 14px; height: 14px; }

.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
}

.chat-sidebar-toggle {
  display: none;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0.3rem;
  transition: color 0.2s;
}

.chat-sidebar-toggle:hover { color: var(--text-primary); }
.chat-sidebar-toggle svg { width: 20px; height: 20px; }

.chat-sidebar-empty {
  text-align: center;
  padding: 2rem 1rem;
  color: var(--text-muted);
  font-size: 0.75rem;
  line-height: 1.6;
}

/* ── Chat Widget ── */
.chat-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 10000;
  background: rgba(0,0,0,0.8);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.chat-overlay.open {
  display: flex;
  opacity: 1;
}

.chat-overlay.closing {
  opacity: 0;
}

.chat-container {
  width: 1020px;
  max-width: 98vw;
  height: 80vh;
  max-height: 700px;
  background: var(--dark);
  border: 1px solid var(--dark-border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform: translateY(20px) scale(0.97);
  transition: transform 0.35s cubic-bezier(0.16, 1, 0.3, 1);
  box-shadow: 0 40px 100px rgba(0,0,0,0.5);
}

.chat-overlay.open .chat-container {
  transform: translateY(0) scale(1);
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--dark-border);
  flex-shrink: 0;
}

.chat-header-left {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.chat-header-logo {
  width: 28px;
  height: 28px;
}

.chat-header-logo img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.chat-header-title {
  font-family: 'Instrument Sans', sans-serif;
  font-weight: 700;
  font-size: 0.9rem;
  color: var(--text-primary);
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.chat-header-status {
  font-size: 0.65rem;
  color: var(--gold-dim);
  letter-spacing: 0.08em;
  margin-left: 0.75rem;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.chat-header-status::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--gold);
  display: inline-block;
  animation: pulse-dot 2s ease infinite;
}

@keyframes pulse-dot {
  0%, 100% { opacity: 0.5; }
  50% { opacity: 1; }
}

.chat-close {
  background: none;
  border: 1px solid transparent;
  color: var(--text-muted);
  font-size: 1.3rem;
  cursor: pointer;
  padding: 0.3rem 0.5rem;
  transition: all 0.2s;
  line-height: 1;
}

.chat-close:hover {
  color: var(--text-primary);
  border-color: var(--dark-border);
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  scroll-behavior: smooth;
}

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

.chat-messages::-webkit-scrollbar-track {
  background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb {
  background: var(--dark-border);
  border-radius: 2px;
}

.chat-msg {
  display: flex;
  gap: 0.75rem;
  max-width: 85%;
  animation: msgIn 0.3s ease;
}

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

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

.chat-msg-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  font-weight: 700;
  margin-top: 2px;
}

.chat-msg.assistant .chat-msg-avatar {
  background: linear-gradient(135deg, var(--gold-dim), var(--gold));
  color: var(--black);
}

.chat-msg.user .chat-msg-avatar {
  background: var(--dark-border);
  color: var(--text-secondary);
}

.chat-msg-bubble {
  padding: 0.75rem 1rem;
  font-size: 0.9rem;
  line-height: 1.65;
  color: var(--text-primary);
}

.chat-msg.assistant .chat-msg-bubble {
  background: var(--dark-surface);
  border: 1px solid var(--dark-border);
  border-radius: 2px 12px 12px 12px;
}

.chat-msg.user .chat-msg-bubble {
  background: rgba(201,168,76,0.12);
  border: 1px solid rgba(201,168,76,0.2);
  border-radius: 12px 2px 12px 12px;
  color: var(--text-primary);
}

.chat-msg-actions {
  display: flex;
  gap: 4px;
  margin-top: 4px;
  opacity: 0;
  transition: opacity 0.15s;
}
.chat-msg:hover .chat-msg-actions { opacity: 1; }
.chat-msg-copy-btn {
  background: none;
  border: 1px solid var(--dark-border);
  border-radius: 5px;
  padding: 3px 6px;
  cursor: pointer;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 0.7rem;
  transition: color 0.15s, border-color 0.15s;
}
.chat-msg-copy-btn:hover {
  color: var(--text-primary);
  border-color: var(--text-secondary);
}

.md-table {
  width: 100%;
  border-collapse: collapse;
  margin: 8px 0;
  font-size: 0.85rem;
}
.md-table th, .md-table td {
  border: 1px solid var(--dark-border);
  padding: 6px 10px;
  text-align: left;
}
.md-table th {
  background: rgba(255,255,255,0.06);
  font-weight: 600;
}
.md-table tr:nth-child(even) td {
  background: rgba(255,255,255,0.02);
}

/* Typing indicator */
.typing-indicator {
  display: flex;
  gap: 4px;
  padding: 0.85rem 1rem;
  align-items: center;
}

.typing-indicator span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: typing 1.4s ease infinite;
}

.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing {
  0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-4px); }
}
@keyframes spin { to { transform: rotate(360deg); } }

.chat-input-area {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--dark-border);
  display: flex;
  align-items: flex-end;
  gap: 0.75rem;
  flex-shrink: 0;
}

.chat-input-wrap {
  flex: 1;
  position: relative;
}

.chat-input {
  width: 100%;
  resize: none;
  border: 1px solid var(--dark-border);
  background: var(--black);
  color: var(--text-primary);
  font-family: 'Instrument Sans', sans-serif;
  font-size: 0.9rem;
  padding: 0.75rem 1rem;
  outline: none;
  line-height: 1.5;
  min-height: 44px;
  max-height: 120px;
  transition: border-color 0.2s;
  overflow-y: auto;
}

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

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

.chat-send {
  background: var(--gold);
  border: none;
  color: var(--black);
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s;
  flex-shrink: 0;
}

.chat-send:hover:not(:disabled) {
  background: var(--gold-light);
  transform: translateY(-1px);
}

.chat-send:disabled {
  opacity: 0.4;
  cursor: default;
}

.chat-send svg {
  width: 18px;
  height: 18px;
}

/* Attachment button */
.chat-attach-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  width: 36px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: color 0.2s;
}
.chat-attach-btn:hover { color: var(--gold); }
.chat-attach-btn svg { width: 20px; height: 20px; }

/* File preview bar */
.chat-file-preview {
  display: none;
  padding: 6px 1.5rem;
  border-top: 1px solid var(--dark-border);
  background: var(--dark-surface);
  flex-wrap: wrap;
  gap: 6px;
}
.chat-file-preview.has-files { display: flex; }
.chat-file-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  background: var(--dark);
  border: 1px solid var(--dark-border);
  border-radius: 6px;
  font-size: 0.78rem;
  color: var(--text-secondary);
  max-width: 200px;
}
.chat-file-chip span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.chat-file-chip .remove-file {
  cursor: pointer;
  color: var(--text-muted);
  font-size: 1rem;
  line-height: 1;
}
.chat-file-chip .remove-file:hover { color: #e55; }
.chat-file-chip.uploading { opacity: 0.5; }

/* Welcome state */
.chat-welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  text-align: center;
  padding: 2rem;
  gap: 1rem;
}

.chat-welcome-icon {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--gold-dim), var(--gold));
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 0.5rem;
}

.chat-welcome-icon img {
  width: 28px;
  height: 28px;
  object-fit: contain;
  filter: brightness(0);
}

.chat-welcome h3 {
  font-family: 'DM Serif Display', serif;
  font-size: 1.3rem;
  color: var(--text-primary);
}

.chat-welcome p {
  font-size: 0.85rem;
  color: var(--text-muted);
  max-width: 360px;
  line-height: 1.6;
}

/* Agent Selection Cards */
.chat-welcome-agents {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  margin-top: 20px;
  width: 100%;
  max-width: 480px;
}
.chat-welcome-agent-card {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 12px 14px;
  background: var(--dark-surface);
  border: 1px solid var(--dark-border);
  border-radius: 10px;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
  width: calc(50% - 5px);
  box-sizing: border-box;
  min-height: 60px;
}
.chat-welcome-agent-card:hover {
  background: #222;
  border-color: var(--gold-dim);
}
.chat-welcome-agent-card.selected {
  border-color: var(--gold);
  background: rgba(201,168,76,0.08);
}
.chat-welcome-agent-icon {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.85rem;
  color: #fff;
  flex-shrink: 0;
}
.chat-welcome-agent-card h4 {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 2px;
}
.chat-welcome-agent-card p {
  font-size: 0.75rem;
  color: var(--text-secondary);
  line-height: 1.3;
  max-width: none;
}
@media (max-width: 480px) {
  .chat-welcome-agent-card { width: 100%; }
}

@media (max-width: 768px) {
  .chat-container {
    width: 100vw;
    height: 100vh;
    max-height: 100vh;
    border: none;
  }
  .chat-layout { position: relative; }
  .chat-header-status { display: none; }
  .chat-sidebar {
    position: absolute;
    left: 0; top: 0; bottom: 0;
    z-index: 100;
    transform: translateX(-100%);
    box-shadow: 8px 0 32px rgba(0, 0, 0, 0.5);
  }
  .chat-sidebar.mobile-open { transform: translateX(0); }
  .chat-sidebar-toggle { display: flex; }
  .chat-sidebar-backdrop {
    display: none;
    position: absolute;
    inset: 0;
    z-index: 99;
    background: rgba(0, 0, 0, 0.5);
  }
  .chat-sidebar-backdrop.visible { display: block; }
}

/* Mobile language toggle */
.mobile-lang-switch {
  display: none;
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 101;
}

@media (max-width: 768px) {
  .mobile-lang-switch { display: flex; }
}

/* ── Watchlist Watch Buttons (in chat messages) ── */
.chat-watch-companies {
  display: flex; flex-wrap: wrap; gap: 6px;
  margin-top: 10px; padding-top: 10px;
  border-top: 1px solid var(--dark-border);
}
.chat-watch-btn {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 4px 12px; background: transparent;
  border: 1px solid var(--dark-border); border-radius: 20px;
  color: var(--text-secondary); font-size: 0.78rem;
  cursor: pointer; transition: all 0.2s; font-family: inherit;
}
.chat-watch-btn:hover { border-color: var(--gold-dim); color: var(--gold); }
.chat-watch-btn.watched {
  background: rgba(201,168,76,0.12);
  border-color: var(--gold-dim); color: var(--gold);
}
.chat-watch-btn.watched:hover {
  background: rgba(201,168,76,0.05);
  border-color: var(--dark-border); color: var(--text-secondary);
}
.chat-watch-btn svg { flex-shrink: 0; }

/* ── Sidebar Tabs ── */
.chat-sidebar-tabs {
  display: flex; border-bottom: 1px solid var(--dark-border); margin: 0 12px;
}
.chat-sidebar-tab {
  flex: 1; padding: 10px 8px; text-align: center;
  font-size: 0.75rem; font-weight: 500; letter-spacing: 0.05em;
  text-transform: uppercase; color: var(--text-muted);
  cursor: pointer; border-bottom: 2px solid transparent;
  transition: all 0.2s; background: none;
  border-top: none; border-left: none; border-right: none; font-family: inherit;
}
.chat-sidebar-tab:hover { color: var(--text-secondary); }
.chat-sidebar-tab.active { color: var(--gold); border-bottom-color: var(--gold); }

/* ── Watchlist Panel ── */
.watchlist-panel { display: none; padding: 8px 0; overflow-y: auto; flex: 1; }
.watchlist-panel.visible { display: block; }
.watchlist-item {
  display: flex; align-items: center; padding: 10px 16px; gap: 10px;
  cursor: default; transition: background 0.15s;
}
.watchlist-item:hover { background: rgba(255,255,255,0.03); }
.watchlist-item-info { flex: 1; min-width: 0; }
.watchlist-item-name {
  font-size: 0.85rem; color: var(--text-primary);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.watchlist-item-meta { font-size: 0.72rem; color: var(--text-muted); margin-top: 2px; }
.watchlist-item-score {
  font-size: 0.8rem; font-weight: 600; padding: 2px 8px; border-radius: 4px; flex-shrink: 0;
}
.watchlist-item-score.hot { background: rgba(239,68,68,0.15); color: #f87171; }
.watchlist-item-score.warm { background: rgba(245,158,11,0.15); color: #fbbf24; }
.watchlist-item-score.monitor { background: rgba(59,130,246,0.15); color: #60a5fa; }
.watchlist-item-score.cold { background: rgba(107,114,128,0.15); color: #9ca3af; }
.watchlist-item-remove {
  color: var(--text-muted); cursor: pointer; padding: 4px;
  opacity: 0; transition: opacity 0.15s, color 0.15s;
}
.watchlist-item:hover .watchlist-item-remove { opacity: 1; }
.watchlist-item-remove:hover { color: #f87171; }
.watchlist-empty { text-align: center; padding: 40px 16px; color: var(--text-muted); font-size: 0.85rem; }
.watchlist-empty p:first-child { margin-bottom: 6px; }

/* ── Sidebar Dashboard Mini ── */
.dash-mini-stat {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 0; border-bottom: 1px solid var(--dark-border);
}
.dash-mini-stat:last-child { border-bottom: none; }
.dash-mini-label { font-size: 0.75rem; color: var(--text-muted); }
.dash-mini-value { font-size: 0.85rem; font-weight: 600; color: var(--text-primary); }
.dash-mini-value.hot { color: #f87171; }
.dash-mini-value.gold { color: var(--gold); }
.dash-mini-section { margin-bottom: 16px; }
.dash-mini-section-title {
  font-size: 0.7rem; font-weight: 600; letter-spacing: 0.08em;
  text-transform: uppercase; color: var(--gold-dim); margin-bottom: 6px;
}
.dash-mini-company {
  display: flex; justify-content: space-between; align-items: center;
  padding: 6px 0; font-size: 0.8rem;
}
.dash-mini-company-name {
  color: var(--text-primary); white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis; max-width: 140px;
}
.dash-mini-link {
  display: block; text-align: center; margin-top: 12px; padding: 8px;
  font-size: 0.78rem; color: var(--gold); text-decoration: none;
  border: 1px solid var(--gold-dim); border-radius: 4px; transition: all 0.2s;
}
.dash-mini-link:hover { background: var(--gold); color: var(--black); }
