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

:root {
  --saffron: #FF6B1A;
  --saffron-light: #FF8C42;
  --deep-navy: #0D1B2A;
  --navy: #1B2D3E;
  --navy-mid: #243447;
  --navy-light: #2E4260;
  --cream: #FFF8F0;
  --cream-dark: #F5EBD8;
  --gold: #C8960C;
  --gold-light: #F0B429;
  --green: #2DD4A0;
  --sidebar-w: 280px;
  --text-primary: #0D1B2A;
  --text-muted: #5A6878;
  --border: rgba(13,27,42,0.1);
  --border-dark: rgba(255,255,255,0.08);
}

html, body { height: 100%; overflow: hidden; }

body {
  font-family: 'DM Sans', sans-serif;
  background: var(--cream);
  display: flex;
  color: var(--text-primary);
}

/* ====== SIDEBAR ====== */
.sidebar {
  width: var(--sidebar-w);
  background: var(--deep-navy);
  height: 100vh;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow: hidden;
  position: relative;
  z-index: 100;
  transition: transform 0.3s ease;
}

.sidebar-header {
  padding: 1.2rem 1.2rem 1rem;
  border-bottom: 1px solid var(--border-dark);
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-family: 'Playfair Display', serif;
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--cream);
  text-decoration: none;
}

.sidebar-logo-text { color: var(--cream); }

.acc { color: var(--saffron-light); }

.new-chat-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  width: 100%;
  padding: 0.7rem;
  background: var(--saffron);
  color: white;
  border: none;
  border-radius: 10px;
  font-family: 'DM Sans', sans-serif;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.new-chat-btn:hover { background: var(--saffron-light); transform: translateY(-1px); }

/* Quick section */
.quick-section {
  padding: 1rem 1rem 0.5rem;
  border-bottom: 1px solid var(--border-dark);
}

.quick-label, .history-label {
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: rgba(255,248,240,0.35);
  margin-bottom: 0.5rem;
  padding: 0 0.2rem;
}

.quick-items { display: flex; flex-direction: column; gap: 0.25rem; }

.quick-item {
  text-align: left;
  background: none;
  border: none;
  color: rgba(255,248,240,0.65);
  font-family: 'DM Sans', sans-serif;
  font-size: 0.78rem;
  padding: 0.5rem 0.6rem;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.15s;
  line-height: 1.4;
}

.quick-item:hover {
  background: rgba(255,107,26,0.12);
  color: var(--saffron-light);
}

/* History section */
.history-section {
  flex: 1;
  overflow-y: auto;
  padding: 0.8rem 1rem;
}

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

.history-loading {
  font-size: 0.78rem;
  color: rgba(255,248,240,0.3);
  text-align: center;
  padding: 1rem 0;
}

.history-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.6rem;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.15s;
  margin-bottom: 0.2rem;
  position: relative;
}

.history-item:hover { background: rgba(255,255,255,0.05); }

.history-item.active { background: rgba(255,107,26,0.15); }

.history-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: rgba(255,248,240,0.2);
  flex-shrink: 0;
}

.history-dot.traffic { background: #60A5FA; }
.history-dot.criminal { background: #F87171; }
.history-dot.consumer { background: #34D399; }
.history-dot.labour { background: #FBBF24; }
.history-dot.property { background: #A78BFA; }
.history-dot.family { background: #F472B6; }
.history-dot.constitutional { background: #FB923C; }
.history-dot.general { background: #94A3B8; }

.history-title {
  font-size: 0.78rem;
  color: rgba(255,248,240,0.6);
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-item.active .history-title { color: rgba(255,248,240,0.9); }

.history-delete {
  background: none;
  border: none;
  color: rgba(255,248,240,0.2);
  cursor: pointer;
  padding: 2px;
  border-radius: 4px;
  opacity: 0;
  transition: all 0.15s;
  font-size: 14px;
  line-height: 1;
}

.history-item:hover .history-delete { opacity: 1; }
.history-delete:hover { color: #F87171; background: rgba(248,113,113,0.1); }

/* Sidebar footer */
.sidebar-footer {
  padding: 1rem 1.2rem;
  border-top: 1px solid var(--border-dark);
  display: flex;
  align-items: center;
}

.sidebar-note {
  font-size: 0.7rem;
  color: rgba(255,248,240,0.3);
  line-height: 1.4;
}

/* Mobile toggle */
.mobile-sidebar-toggle {
  display: none;
  position: fixed;
  top: 1rem;
  left: 1rem;
  z-index: 200;
  background: var(--deep-navy);
  color: var(--cream);
  border: none;
  width: 40px;
  height: 40px;
  border-radius: 10px;
  cursor: pointer;
  align-items: center;
  justify-content: center;
}

/* ====== CHAT MAIN ====== */
.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
  position: relative;
}

/* Welcome screen */
.welcome-screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  text-align: center;
  overflow-y: auto;
}

.welcome-icon {
  font-size: 3.5rem;
  margin-bottom: 1rem;
  animation: float 3s ease-in-out infinite;
}

.welcome-title {
  font-family: 'Playfair Display', serif;
  font-size: 2rem;
  font-weight: 700;
  color: var(--deep-navy);
  margin-bottom: 0.6rem;
}

.welcome-sub {
  font-size: 0.95rem;
  color: var(--text-muted);
  max-width: 460px;
  line-height: 1.7;
  margin-bottom: 2rem;
}

.welcome-chips {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.6rem;
  margin-bottom: 2rem;
}

.chip {
  background: white;
  border: 1.5px solid var(--border);
  color: var(--navy);
  font-size: 0.82rem;
  font-weight: 500;
  padding: 0.5rem 1rem;
  border-radius: 100px;
  cursor: pointer;
  transition: all 0.2s;
}

.chip:hover {
  border-color: var(--saffron);
  background: rgba(255,107,26,0.04);
  color: var(--saffron);
  transform: translateY(-1px);
}

.disclaimer-box {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  background: rgba(200,150,12,0.08);
  border: 1px solid rgba(200,150,12,0.25);
  border-radius: 10px;
  padding: 0.8rem 1.1rem;
  font-size: 0.78rem;
  color: var(--text-muted);
  max-width: 480px;
  text-align: left;
  line-height: 1.5;
}

/* Messages container */
.messages-container {
  flex: 1;
  overflow-y: auto;
  padding: 1.5rem 1.5rem 0;
  scroll-behavior: smooth;
}

.messages-container::-webkit-scrollbar { width: 4px; }
.messages-container::-webkit-scrollbar-track { background: transparent; }
.messages-container::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.messages-list { display: flex; flex-direction: column; gap: 1.2rem; max-width: 820px; margin: 0 auto; }

/* Message bubbles */
.message { display: flex; gap: 0.8rem; animation: msgIn 0.3s ease; }

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

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

.message.assistant .msg-avatar {
  background: var(--deep-navy);
  color: var(--saffron-light);
  font-size: 1rem;
}

.message.user .msg-avatar {
  overflow: hidden;
  border: 2px solid rgba(255,107,26,0.3);
}

.message.user .msg-avatar img { width: 100%; height: 100%; object-fit: cover; }

.msg-bubble {
  max-width: 75%;
  padding: 1rem 1.2rem;
  border-radius: 16px;
  line-height: 1.7;
  font-size: 0.9rem;
}

.message.user .msg-bubble {
  background: var(--deep-navy);
  color: var(--cream);
  border-bottom-right-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.message.assistant .msg-bubble {
  background: white;
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.05);
}

/* Markdown-like formatting in AI responses */
.msg-bubble strong { font-weight: 600; color: var(--deep-navy); }
.message.user .msg-bubble strong { color: var(--cream); }

.msg-bubble .msg-section { margin: 0.6rem 0; }

.msg-bubble h3 {
  font-family: 'Playfair Display', serif;
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--deep-navy);
  margin: 0.8rem 0 0.3rem;
}

.msg-bubble ul, .msg-bubble ol {
  padding-left: 1.2rem;
  margin: 0.4rem 0;
}

.msg-bubble li { margin: 0.25rem 0; }

.msg-bubble code {
  font-family: 'DM Mono', monospace;
  background: rgba(13,27,42,0.06);
  padding: 0.15em 0.4em;
  border-radius: 4px;
  font-size: 0.85em;
}

.msg-bubble .law-cite {
  display: inline-flex;
  align-items: center;
  gap: 0.3em;
  background: rgba(255,107,26,0.08);
  color: var(--saffron);
  border: 1px solid rgba(255,107,26,0.2);
  border-radius: 5px;
  padding: 0.1em 0.5em;
  font-size: 0.8em;
  font-weight: 600;
}

.msg-time {
  font-size: 0.68rem;
  color: var(--text-muted);
  margin-top: 0.4rem;
  padding: 0 0.2rem;
}

.message.user .msg-time { text-align: right; }

/* Category badge in message */
.category-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  background: rgba(13,27,42,0.06);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 0.2rem 0.6rem;
  border-radius: 100px;
  margin-bottom: 0.5rem;
  display: block;
}

/* Typing indicator */
.typing-indicator {
  display: flex;
  gap: 0.8rem;
  align-items: center;
  animation: msgIn 0.3s ease;
}

.typing-bubble {
  background: white;
  border: 1px solid var(--border);
  border-radius: 16px;
  border-bottom-left-radius: 4px;
  padding: 0.8rem 1rem;
  display: flex;
  gap: 5px;
  align-items: center;
}

.typing-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--saffron);
  animation: typingPulse 1.2s ease infinite;
}

.typing-dot:nth-child(2) { animation-delay: 0.2s; background: var(--gold-light); }
.typing-dot:nth-child(3) { animation-delay: 0.4s; background: var(--deep-navy); }

/* Input area */
.input-area {
  padding: 1rem 1.5rem 1.2rem;
  border-top: 1px solid var(--border);
  background: rgba(255,248,240,0.95);
  backdrop-filter: blur(8px);
}

.input-wrapper {
  max-width: 820px;
  margin: 0 auto;
  background: white;
  border: 1.5px solid var(--border);
  border-radius: 14px;
  display: flex;
  align-items: flex-end;
  padding: 0.5rem 0.5rem 0.5rem 1rem;
  gap: 0.5rem;
  transition: border-color 0.2s;
  box-shadow: 0 2px 12px rgba(0,0,0,0.06);
}

.input-wrapper:focus-within {
  border-color: var(--saffron);
  box-shadow: 0 0 0 3px rgba(255,107,26,0.1);
}

.message-input {
  flex: 1;
  border: none;
  outline: none;
  resize: none;
  font-family: 'DM Sans', sans-serif;
  font-size: 0.9rem;
  line-height: 1.6;
  color: var(--text-primary);
  background: transparent;
  max-height: 160px;
  overflow-y: auto;
  padding: 0.3rem 0;
}

.message-input::placeholder { color: rgba(90,104,120,0.5); }

.input-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}

.char-count {
  font-size: 0.65rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.send-btn {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  border: none;
  background: var(--deep-navy);
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  flex-shrink: 0;
}

.send-btn:enabled:hover { background: var(--saffron); transform: translateY(-1px); }
.send-btn:disabled { opacity: 0.35; cursor: not-allowed; }

.input-note {
  font-size: 0.7rem;
  color: var(--text-muted);
  text-align: center;
  margin-top: 0.5rem;
  max-width: 820px;
  margin-left: auto;
  margin-right: auto;
}

.input-note strong { color: var(--text-primary); }

/* Animations */
@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}

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

@keyframes typingPulse {
  0%, 60%, 100% { transform: scale(0.8); opacity: 0.4; }
  30% { transform: scale(1.2); opacity: 1; }
}

/* Mobile */
@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    left: 0; top: 0; bottom: 0;
    transform: translateX(-100%);
  }
  .sidebar.open { transform: translateX(0); }
  .mobile-sidebar-toggle { display: flex; }
  .mobile-sidebar-toggle.hidden { display: none; }
  .chat-main { width: 100%; padding-top: 56px; }
  .welcome-screen { padding-top: 1rem; }
  .input-area { padding: 0.8rem 1rem 1rem; }
  .messages-container { padding: 1rem; }
  .msg-bubble { max-width: 88%; }
  .welcome-title { font-size: 1.5rem; }
}

/* ====== LANGUAGE DROPDOWN ====== */
.lang-dropdown-wrapper {
  display: flex;
  align-items: center;
  margin-top: 0.4rem;
}

.lang-dropdown {
  background: var(--navy-mid, rgba(255,255,255,0.07));
  border: 1.5px solid rgba(255,255,255,0.12);
  border-radius: 8px;
  color: rgba(255,255,255,0.7);
  font-size: 0.78rem;
  font-weight: 600;
  padding: 0.3rem 0.55rem;
  cursor: pointer;
  font-family: 'DM Sans', sans-serif;
  transition: all 0.18s ease;
  outline: none;
  appearance: auto;
  width: 100%;
}

.lang-dropdown option {
  background: #0D1B2A;
  color: #fff;
}

.lang-dropdown:hover,
.lang-dropdown:focus {
  border-color: var(--saffron, #FF6B1A);
  color: #fff;
}