/* ═══════════════════════════════════════════════════════════════════════════
   LegalDefense AI — Krilax Innovations Pvt. Ltd.
   Clean, modern light theme. Mobile-first responsive.
   ═══════════════════════════════════════════════════════════════════════════ */

/* Force light theme regardless of OS preference */
:root {
  color-scheme: light only;
  --bg: #fafaf8;
  --surface: #ffffff;
  --primary: #1c1917;
  --accent: #b45309;
  --accent-dark: #92400e;
  --accent-light: #fef3c7;
  --accent-glow: rgba(180,83,9,0.1);
  --text: #1c1917;
  --text-secondary: #57534e;
  --text-tertiary: #a8a29e;
  --border: #e7e5e4;
  --border-light: #f5f5f4;
  --shadow-xs: 0 1px 2px rgba(0,0,0,0.04);
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.07), 0 2px 4px -2px rgba(0,0,0,0.05);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.08), 0 4px 6px -4px rgba(0,0,0,0.04);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 24px;
  --max-width: 800px;
  --header-height: 56px;
  --input-area-height: 140px;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: light only;
  }
}

/* ── Reset & Base ────────────────────────────────────────────────────────── */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  height: 100%;
  -webkit-text-size-adjust: 100%;
}

body {
  height: 100%;
  font-family: 'Inter', 'Noto Sans Devanagari', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 15px;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow: hidden;
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
}

textarea {
  font-family: inherit;
  font-size: inherit;
  border: none;
  outline: none;
  resize: none;
}

/* ── Icon Button ─────────────────────────────────────────────────────────── */
.icon-btn {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  transition: all 0.15s ease;
}
.icon-btn:hover {
  background: var(--border-light);
  color: var(--text);
}

/* ── Sidebar ─────────────────────────────────────────────────────────────── */
.sidebar-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.3);
  z-index: 900;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}
.sidebar-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: 300px;
  height: 100%;
  background: var(--surface);
  border-right: 1px solid var(--border);
  z-index: 1000;
  transform: translateX(-100%);
  transition: transform 0.25s ease;
  display: flex;
  flex-direction: column;
}
.sidebar.open {
  transform: translateX(0);
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.sidebar-header h3 {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text);
}

.new-chat-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 12px 16px;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  border: 1px dashed var(--border);
  color: var(--text-secondary);
  font-size: 0.875rem;
  font-weight: 500;
  transition: all 0.15s ease;
}
.new-chat-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-light);
}

.conversation-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px 12px;
}

.conversation-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.conversation-item:hover {
  background: var(--border-light);
  color: var(--text);
}
.conversation-item.active {
  background: var(--accent-light);
  color: var(--accent);
  font-weight: 500;
}

.conversation-item .conv-delete {
  margin-left: auto;
  flex-shrink: 0;
  opacity: 0;
  transition: opacity 0.15s;
}
.conversation-item:hover .conv-delete {
  opacity: 1;
}

/* ── App Container ───────────────────────────────────────────────────────── */
.app-container {
  display: flex;
  flex-direction: column;
  height: 100%;
  max-width: 100%;
}

/* ── Header ──────────────────────────────────────────────────────────────── */
.app-header {
  height: var(--header-height);
  background: rgba(255,253,247,0.92);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  z-index: 100;
  flex-shrink: 0;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 8px;
}

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

.brand-icon {
  color: var(--accent);
}

.brand-name {
  font-weight: 600;
  font-size: 1rem;
  color: var(--primary);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #94a3b8;
  transition: background 0.3s;
}
.status-dot.online {
  background: #10b981;
  box-shadow: 0 0 6px rgba(16,185,129,0.4);
  animation: pulse 2s ease-in-out infinite;
}
.status-dot.offline {
  background: #ef4444;
}

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

.header-right {
  display: flex;
  align-items: center;
  gap: 4px;
}

/* ── Language Switcher ───────────────────────────────────────────────────── */
.lang-switcher {
  display: flex;
  gap: 2px;
  background: var(--border-light);
  border-radius: 6px;
  padding: 2px;
  margin-right: 4px;
}
.lang-btn {
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--text-tertiary);
  transition: all 0.15s ease;
  letter-spacing: 0.03em;
}
.lang-btn:hover {
  color: var(--text);
}
.lang-btn.active {
  background: var(--surface);
  color: var(--accent-dark);
  box-shadow: var(--shadow-xs);
}

/* ── Chat Area ───────────────────────────────────────────────────────────── */
.chat-area {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
}

/* ── Welcome Screen ──────────────────────────────────────────────────────── */
.welcome-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 24px 120px;
  min-height: 100%;
}

.welcome-icon {
  width: 72px;
  height: 72px;
  border-radius: 20px;
  background: var(--accent-light);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent);
  margin-bottom: 20px;
}

.welcome-title {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 8px;
}

.welcome-subtitle {
  font-size: 0.925rem;
  color: var(--text-secondary);
  margin-bottom: 36px;
  text-align: center;
}

/* ── Role Tabs ───────────────────────────────────────────────────────────── */
.role-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 24px;
  background: var(--border-light);
  border-radius: var(--radius-sm);
  padding: 3px;
}

.role-tab {
  padding: 8px 20px;
  border-radius: 6px;
  font-size: 0.825rem;
  font-weight: 500;
  color: var(--text-secondary);
  transition: all 0.2s ease;
}
.role-tab:hover {
  color: var(--text);
}
.role-tab.active {
  background: var(--surface);
  color: var(--accent-dark);
  font-weight: 600;
  box-shadow: var(--shadow-xs);
}

/* ── Quick Actions Grid ──────────────────────────────────────────────────── */
.quick-actions {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  max-width: 640px;
  width: 100%;
}

.action-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
  padding: 16px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--surface);
  text-align: left;
  transition: all 0.2s ease;
  cursor: pointer;
}
.action-card:hover {
  border-color: var(--accent);
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

.action-icon {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  background: var(--accent-light);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent);
}

.action-title {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text);
}

.action-desc {
  font-size: 0.75rem;
  color: var(--text-tertiary);
  line-height: 1.4;
}

/* ── Messages ────────────────────────────────────────────────────────────── */
.messages {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 24px 20px 140px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.message {
  display: flex;
  gap: 12px;
  animation: messageIn 0.3s ease-out;
}
.message.user {
  flex-direction: row-reverse;
}

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

.avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  flex-shrink: 0;
}
.avatar.bot {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--accent);
}
.avatar.user {
  background: var(--accent-dark);
  color: #fffbeb;
  font-size: 13px;
  font-weight: 600;
}

.bubble {
  max-width: 80%;
  padding: 12px 16px;
  border-radius: var(--radius-md);
  font-size: 0.925rem;
  line-height: 1.65;
  position: relative;
}
.bubble.bot {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  box-shadow: var(--shadow-xs);
  border-top-left-radius: 4px;
}
.bubble.user {
  background: var(--accent-dark);
  color: #fffbeb;
  box-shadow: var(--shadow-sm);
  border-top-right-radius: 4px;
}

/* ── Markdown in bot bubbles ─────────────────────────────────────────────── */
.bubble.bot h1, .bubble.bot h2, .bubble.bot h3, .bubble.bot h4 {
  margin-top: 0.8em;
  margin-bottom: 0.4em;
  font-weight: 600;
  color: var(--primary);
  line-height: 1.3;
}
.bubble.bot h1 { font-size: 1.2em; }
.bubble.bot h2 { font-size: 1.1em; }
.bubble.bot h3 { font-size: 1em; }

.bubble.bot p { margin-bottom: 0.6em; }
.bubble.bot p:last-child { margin-bottom: 0; }

.bubble.bot ul, .bubble.bot ol {
  padding-left: 1.4em;
  margin-bottom: 0.6em;
}
.bubble.bot li { margin-bottom: 0.2em; }

.bubble.bot code {
  background: #f1f5f9;
  padding: 2px 6px;
  border-radius: 4px;
  font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
  font-size: 0.875em;
  color: #b45309;
}

.bubble.bot pre {
  background: #1e293b;
  color: #e2e8f0;
  padding: 14px 16px;
  border-radius: var(--radius-sm);
  overflow-x: auto;
  margin: 10px 0;
  font-size: 0.85em;
  line-height: 1.5;
}
.bubble.bot pre code {
  background: none;
  padding: 0;
  color: inherit;
  font-size: inherit;
}

.bubble.bot blockquote {
  border-left: 3px solid var(--accent);
  padding-left: 14px;
  color: var(--text-secondary);
  font-style: italic;
  margin: 8px 0;
}

.bubble.bot table {
  border-collapse: collapse;
  width: 100%;
  margin: 10px 0;
  font-size: 0.875em;
}
.bubble.bot th, .bubble.bot td {
  border: 1px solid var(--border);
  padding: 8px 12px;
  text-align: left;
}
.bubble.bot th {
  background: var(--border-light);
  font-weight: 600;
}

.bubble.bot strong { font-weight: 600; }

.bubble.bot a {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 2px;
}

/* ── Suggestion Chips ────────────────────────────────────────────────────── */
.suggestion-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 4px 56px 8px;
  animation: chipIn 0.3s ease-out;
}

.suggestion-chip {
  padding: 8px 14px;
  border-radius: var(--radius-xl);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-secondary);
  font-size: 0.8rem;
  line-height: 1.4;
  cursor: pointer;
  transition: all 0.15s ease;
  text-align: left;
  max-width: 100%;
}
.suggestion-chip:hover {
  border-color: var(--accent);
  color: var(--accent-dark);
  background: var(--accent-light);
  box-shadow: var(--shadow-sm);
}

@media (max-width: 640px) {
  .suggestion-chips {
    padding: 4px 12px 8px;
  }
  .suggestion-chip {
    font-size: 0.75rem;
    padding: 6px 12px;
  }
}

/* ── Copy Button ─────────────────────────────────────────────────────────── */
.copy-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-top: 8px;
  padding: 4px 8px;
  border-radius: 6px;
  color: var(--text-tertiary);
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  transition: all 0.15s ease;
}
.copy-btn:hover {
  background: var(--border-light);
  color: var(--accent);
}

/* ── Typing Indicator ────────────────────────────────────────────────────── */
.typing-indicator {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 0;
}
.typing-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-tertiary);
  animation: typingBounce 1.4s ease-in-out infinite;
}
.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }

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

/* ── File Chip ───────────────────────────────────────────────────────────── */
.file-chip {
  position: fixed;
  bottom: 110px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface);
  padding: 8px 12px 8px 14px;
  border-radius: var(--radius-xl);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-md);
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.825rem;
  z-index: 200;
  animation: chipIn 0.2s ease-out;
  color: var(--accent);
  max-width: 90%;
}

.file-chip-name {
  color: var(--text);
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 200px;
}

.file-chip-remove {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-tertiary);
  transition: all 0.15s ease;
  flex-shrink: 0;
}
.file-chip-remove:hover {
  background: #fee2e2;
  color: #ef4444;
}

@keyframes chipIn {
  from { opacity: 0; transform: translate(-50%, 8px); }
  to   { opacity: 1; transform: translate(-50%, 0); }
}

/* ── Input Area ──────────────────────────────────────────────────────────── */
.input-area {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 0 16px 12px;
  background: linear-gradient(to top, var(--bg) 80%, transparent);
  z-index: 100;
}

.input-container {
  max-width: var(--max-width);
  margin: 0 auto;
  display: flex;
  align-items: flex-end;
  gap: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  padding: 6px 6px 6px 4px;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
.input-container:focus-within {
  border-color: var(--accent);
  box-shadow: var(--shadow-lg), 0 0 0 3px var(--accent-glow);
}

.attach-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-tertiary);
  flex-shrink: 0;
  transition: all 0.15s ease;
}
.attach-btn:hover {
  color: var(--accent);
  background: var(--accent-light);
}

/* ── Mic Button ──────────────────────────────────────────────────────────── */
.mic-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-tertiary);
  flex-shrink: 0;
  transition: all 0.15s ease;
  position: relative;
}
.mic-btn:hover {
  color: var(--accent);
  background: var(--accent-light);
}
.mic-btn.recording {
  color: #ef4444;
  background: #fef2f2;
  animation: micPulse 1.5s ease-in-out infinite;
}
.mic-btn.recording .mic-icon { display: none; }
.mic-btn.recording .mic-stop-icon { display: block !important; }
.mic-btn.unsupported { display: none; }

@keyframes micPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(239,68,68,0.3); }
  50% { box-shadow: 0 0 0 8px rgba(239,68,68,0); }
}

/* ── Recording Chip ──────────────────────────────────────────────────────── */
.recording-chip {
  position: fixed;
  bottom: 110px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface);
  padding: 8px 16px;
  border-radius: var(--radius-xl);
  border: 1px solid #fecaca;
  box-shadow: var(--shadow-md);
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.825rem;
  z-index: 200;
  animation: chipIn 0.2s ease-out;
  color: var(--text);
}

.recording-pulse {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #ef4444;
  animation: recPulse 1s ease-in-out infinite;
  flex-shrink: 0;
}

@keyframes recPulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.5; transform: scale(0.8); }
}

.recording-text {
  font-weight: 500;
  color: #dc2626;
}

.recording-time {
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
  font-size: 0.8rem;
}

#messageInput {
  flex: 1;
  padding: 10px 4px;
  max-height: 150px;
  min-height: 40px;
  line-height: 1.5;
  color: var(--text);
  background: transparent;
}
#messageInput::placeholder {
  color: var(--text-tertiary);
}

.send-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--accent);
  color: white;
  flex-shrink: 0;
  transition: all 0.2s ease;
  opacity: 0.4;
}
.send-btn:not(:disabled) {
  opacity: 1;
}
.send-btn:not(:disabled):hover {
  background: var(--accent-dark);
  transform: scale(1.05);
}
.send-btn:disabled {
  cursor: not-allowed;
}

.input-disclaimer {
  text-align: center;
  font-size: 0.7rem;
  color: var(--text-tertiary);
  margin-top: 8px;
}

/* ── Responsive: Tablet ──────────────────────────────────────────────────── */
@media (max-width: 1024px) {
  .quick-actions {
    grid-template-columns: repeat(2, 1fr);
    max-width: 480px;
  }
}

/* ── Responsive: Mobile ──────────────────────────────────────────────────── */
@media (max-width: 640px) {
  :root {
    --header-height: 52px;
    --max-width: 100%;
  }

  body { font-size: 14px; }

  .welcome-screen {
    padding: 24px 16px 120px;
  }

  .welcome-title { font-size: 1.3rem; }
  .welcome-subtitle { font-size: 0.85rem; }

  .quick-actions {
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
    max-width: 100%;
  }

  .action-card {
    padding: 12px;
  }
  .action-desc {
    display: none;
  }

  .messages {
    padding: 16px 12px 140px;
    gap: 16px;
  }

  .bubble {
    max-width: 88%;
    padding: 10px 14px;
    font-size: 0.875rem;
  }

  .avatar {
    width: 28px;
    height: 28px;
    font-size: 12px;
  }

  .input-area {
    padding: 0 8px 8px;
  }

  .input-container {
    border-radius: 20px;
  }

  .brand-name {
    font-size: 0.9rem;
  }

  .sidebar {
    width: 85%;
    max-width: 300px;
  }
}

/* ── Small phones ────────────────────────────────────────────────────────── */
@media (max-width: 380px) {
  .quick-actions {
    grid-template-columns: 1fr;
  }

  .action-desc {
    display: block;
  }
}

/* ── Scrollbar ───────────────────────────────────────────────────────────── */
.chat-area::-webkit-scrollbar {
  width: 6px;
}
.chat-area::-webkit-scrollbar-track {
  background: transparent;
}
.chat-area::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}
.chat-area::-webkit-scrollbar-thumb:hover {
  background: var(--text-tertiary);
}

/* ── Selection ───────────────────────────────────────────────────────────── */
::selection {
  background: rgba(180,83,9,0.15);
}

/* ── Krilax Branding ─────────────────────────────────────────────────────── */
.krilax-brand {
  position: fixed;
  bottom: 4px;
  right: 12px;
  font-size: 0.6rem;
  color: var(--text-tertiary);
  opacity: 0.6;
  letter-spacing: 0.02em;
  z-index: 50;
  pointer-events: none;
}

/* ── iOS Safe Area ───────────────────────────────────────────────────────── */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
  .input-area {
    padding-bottom: calc(12px + env(safe-area-inset-bottom));
  }
}
