/* ============================================================
   Contract Assistant Chat — with History Sidebar
   ============================================================ */

.chat-wrap {
  min-height: calc(100vh - var(--nav-height, 68px));
  background: var(--surface, #F5F7FA);
  display: flex;
  flex-direction: column;
}

/* ═══ Layout: sidebar + main ═══ */
.chat-layout {
  display: flex;
  flex: 1;
  min-height: calc(100vh - var(--nav-height, 68px));
  max-width: 1400px;
  width: 100%;
  margin: 0 auto;
  position: relative;
}

/* ═══ LEFT SIDEBAR ═══ */
.chat-sidebar {
  width: 300px;
  min-width: 300px;
  background: var(--white, #fff);
  border-right: 1px solid var(--border, #DDE2EA);
  display: flex;
  flex-direction: column;
  height: calc(100vh - var(--nav-height, 68px));
  position: sticky;
  top: var(--nav-height, 68px);
}

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

.chat-sidebar-header h2 {
  font-family: var(--font-sans, 'Poppins', system-ui, sans-serif);
  font-size: .9rem;
  font-weight: 700;
  color: var(--text-primary);
  margin: 0;
}

.chat-new-btn {
  display: flex;
  align-items: center;
  gap: .35rem;
  padding: .4rem .7rem;
  background: var(--gold, #2563EB);
  color: #fff;
  border: none;
  border-radius: 6px;
  font-family: inherit;
  font-size: .78rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .2s;
}

.chat-new-btn:hover { background: var(--gold-dark, #1d4ed8); }

.chat-sidebar-search {
  padding: .65rem .75rem;
  display: flex;
  align-items: center;
  gap: .5rem;
  border-bottom: 1px solid var(--border);
}

.chat-sidebar-search svg {
  color: var(--text-muted);
  flex-shrink: 0;
}

.chat-sidebar-search input {
  flex: 1;
  border: none;
  outline: none;
  background: transparent;
  font-family: inherit;
  font-size: .82rem;
  color: var(--text-primary);
}

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

.chat-history-list {
  flex: 1;
  overflow-y: auto;
  padding: .5rem;
}

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

.chat-history-item {
  padding: .65rem .75rem;
  border-radius: 8px;
  cursor: pointer;
  transition: background .15s;
  margin-bottom: 2px;
}

.chat-history-item:hover { background: var(--surface, #F5F7FA); }
.chat-history-item.active { background: var(--surface-alt, #EDF0F5); }

.chat-history-title {
  font-size: .82rem;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: .15rem;
}

.chat-history-meta {
  font-size: .7rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.chat-history-delete {
  opacity: 0;
  border: none;
  background: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 2px;
  font-size: .75rem;
  transition: opacity .15s, color .15s;
}

.chat-history-item:hover .chat-history-delete { opacity: 1; }
.chat-history-delete:hover { color: var(--red-breaking, #C8231E); }

/* Mobile sidebar toggle */
.chat-sidebar-toggle {
  display: none;
  position: absolute;
  top: 1rem;
  left: 1rem;
  width: 38px;
  height: 38px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--white, #fff);
  color: var(--text-primary);
  cursor: pointer;
  align-items: center;
  justify-content: center;
  z-index: 10;
}

/* ═══ MAIN CHAT AREA ═══ */
.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: calc(100vh - var(--nav-height, 68px));
  padding: 0 1.5rem;
  max-width: 860px;
  margin: 0 auto;
  width: 100%;
}

/* Header */
.chat-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 3.5rem 0 1.5rem;
  margin-top: 1rem;
}

.chat-header-icon {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-md, 8px);
  background: var(--gold, #2563EB);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.chat-header h1 {
  font-family: var(--font-display, 'Poppins', system-ui, sans-serif);
  font-size: 1.6rem;
  font-weight: 800;
  color: var(--text-primary);
  margin: 0;
  line-height: 1.2;
}

.chat-header-sub {
  font-size: .85rem;
  color: var(--text-secondary);
  margin: .15rem 0 0;
}

/* Suggestions */
.chat-suggestions {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: .75rem;
  padding: .5rem 0 2rem;
}

.chat-suggestion {
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: .85rem 1rem;
  background: var(--white, #fff);
  border: 1px solid var(--border);
  border-radius: var(--radius-md, 8px);
  cursor: pointer;
  font-family: var(--font-sans, 'Poppins', system-ui, sans-serif);
  font-size: .85rem;
  font-weight: 500;
  color: var(--text-primary);
  text-align: left;
  transition: var(--transition, all .22s ease);
  line-height: 1.3;
}

.chat-suggestion:hover {
  border-color: var(--gold);
  box-shadow: var(--shadow-sm);
  transform: translateY(-1px);
}

.suggestion-icon { font-size: 1.1rem; flex-shrink: 0; }

/* Messages */
.chat-messages {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  padding-bottom: 1rem;
  overflow-y: auto;
}

.chat-msg {
  display: flex;
  gap: .75rem;
  max-width: 100%;
  animation: chatFadeIn .3s ease;
}

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

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

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

.chat-msg--assistant .chat-avatar { background: var(--gold); color: #fff; }
.chat-msg--user .chat-avatar { background: var(--text-primary); color: #fff; }

.chat-bubble {
  padding: .85rem 1.1rem;
  border-radius: 12px;
  font-size: .9rem;
  line-height: 1.6;
  max-width: 75%;
  word-wrap: break-word;
}

.chat-msg--user .chat-bubble {
  background: var(--gold);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.chat-msg--assistant .chat-bubble {
  background: var(--white, #fff);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

.chat-bubble p { margin: 0 0 .5rem; }
.chat-bubble p:last-child { margin-bottom: 0; }
.chat-bubble ul, .chat-bubble ol { margin: .5rem 0; padding-left: 1.25rem; }
.chat-bubble li { margin-bottom: .25rem; }
.chat-bubble strong { font-weight: 600; }
.chat-bubble code { background: var(--surface-alt, #EDF0F5); padding: .15rem .35rem; border-radius: 3px; font-size: .82rem; }

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

.chat-typing-dot {
  width: 8px; height: 8px;
  background: var(--text-muted);
  border-radius: 50%;
  animation: typingBounce 1.4s infinite;
}
.chat-typing-dot:nth-child(2) { animation-delay: .2s; }
.chat-typing-dot:nth-child(3) { animation-delay: .4s; }

@keyframes typingBounce {
  0%, 60%, 100% { transform: translateY(0); opacity: .4; }
  30% { transform: translateY(-6px); opacity: 1; }
}

/* Input area */
.chat-input-area {
  position: sticky;
  bottom: 0;
  background: var(--surface, #F5F7FA);
  padding: .75rem 0 1.25rem;
  border-top: 1px solid var(--border);
}

.chat-form { max-width: 100%; }

.chat-input-wrap {
  display: flex;
  align-items: flex-end;
  gap: .5rem;
  background: var(--white, #fff);
  border: 2px solid var(--border);
  border-radius: 12px;
  padding: .5rem .5rem .5rem .85rem;
  transition: border-color .2s;
}

.chat-input-wrap:focus-within {
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, .1);
}

.chat-input {
  flex: 1;
  border: none;
  outline: none;
  font-family: var(--font-sans, 'Poppins', system-ui, sans-serif);
  font-size: .9rem;
  color: var(--text-primary);
  background: transparent;
  resize: none;
  max-height: 120px;
  line-height: 1.5;
  padding: .35rem 0;
}

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

.chat-send {
  width: 38px; height: 38px;
  border-radius: 10px;
  border: none;
  background: var(--gold);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: var(--transition, all .22s ease);
}

.chat-send:hover:not(:disabled) { background: var(--gold-dark, #1d4ed8); transform: scale(1.05); }
.chat-send:disabled { opacity: .4; cursor: not-allowed; }

.chat-disclaimer {
  font-size: .72rem;
  color: var(--text-muted);
  text-align: center;
  margin-top: .5rem;
}

/* ═══ ACCESS GATE ═══ */
.access-gate {
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 4rem 2rem;
  min-height: 60vh;
  width: 100%;
}

.access-gate h2 {
  font-family: var(--font-display, 'Poppins', system-ui, sans-serif);
  font-size: 1.8rem;
  font-weight: 800;
  color: var(--text-primary);
  margin: 1rem 0 .5rem;
}

.access-gate p { color: var(--text-secondary); font-size: .95rem; margin-bottom: 1.5rem; max-width: 400px; }

.gate-icon { font-size: 3rem; }

.access-gate .btn--primary {
  display: inline-block;
  padding: .75rem 2rem;
  background: var(--gold);
  color: #fff;
  border-radius: var(--radius-md, 8px);
  text-decoration: none;
  font-weight: 600;
  font-size: .95rem;
  transition: var(--transition, all .22s ease);
}

.access-gate .btn--primary:hover { background: var(--gold-dark, #1d4ed8); transform: translateY(-1px); box-shadow: var(--shadow-md); }

/* ═══ RESPONSIVE ═══ */
@media (max-width: 768px) {
  .chat-sidebar {
    position: fixed;
    top: var(--nav-height, 68px);
    left: 0;
    bottom: 0;
    z-index: 100;
    transform: translateX(-100%);
    transition: transform .25s ease;
    box-shadow: none;
  }

  .chat-sidebar.open {
    transform: translateX(0);
    box-shadow: 4px 0 24px rgba(0,0,0,.15);
  }

  .chat-sidebar-toggle { display: flex; }

  .chat-main { padding: 0 1rem; }

  .chat-header { padding-top: 1.5rem; padding-left: 3rem; }

  .chat-suggestions { grid-template-columns: 1fr; }

  .chat-bubble { max-width: 88%; }
}

/* ═══ DARK MODE ═══ */
[data-theme="dark"] .chat-wrap { background: var(--navy, #0a0a0a); }

[data-theme="dark"] .chat-sidebar {
  background: var(--navy-mid, #141414);
  border-right-color: #222;
}

[data-theme="dark"] .chat-sidebar-header { border-bottom-color: #222; }
[data-theme="dark"] .chat-sidebar-search { border-bottom-color: #222; }
[data-theme="dark"] .chat-sidebar-search input { color: #e0e0e0; }

[data-theme="dark"] .chat-history-item:hover { background: #1a1a1a; }
[data-theme="dark"] .chat-history-item.active { background: #1e1e1e; }
[data-theme="dark"] .chat-history-title { color: #e0e0e0; }

[data-theme="dark"] .chat-header h1 { color: #e0e0e0; }
[data-theme="dark"] .chat-header-sub { color: #888; }

[data-theme="dark"] .chat-suggestion {
  background: var(--navy-mid, #141414);
  border-color: #222;
  color: #e0e0e0;
}
[data-theme="dark"] .chat-suggestion:hover { border-color: var(--gold); background: #1a1a1a; }

[data-theme="dark"] .chat-msg--assistant .chat-bubble {
  background: var(--navy-mid, #141414);
  border-color: #222;
  color: #e0e0e0;
}

[data-theme="dark"] .chat-msg--user .chat-avatar { background: #e0e0e0; color: #0a0a0a; }

[data-theme="dark"] .chat-bubble code { background: rgba(255,255,255,.08); }

[data-theme="dark"] .chat-input-area { background: var(--navy, #0a0a0a); border-top-color: #222; }

[data-theme="dark"] .chat-input-wrap { background: var(--navy-mid, #141414); border-color: #222; }
[data-theme="dark"] .chat-input { color: #e0e0e0; }

[data-theme="dark"] .chat-sidebar-toggle { background: var(--navy-mid, #141414); border-color: #222; color: #e0e0e0; }

[data-theme="dark"] .access-gate h2 { color: #e0e0e0; }
[data-theme="dark"] .access-gate p { color: #888; }

[data-theme="dark"] .chat-history-empty { color: #666; }
