/* Guardian Chat UI — Dark theme */

:root {
  --bg-primary: #0f1117;
  --bg-secondary: #161922;
  --bg-tertiary: #1c1f2e;
  --bg-hover: #232738;
  --bg-active: #2a2e42;
  --bg-user-msg: #2a2e42;
  --bg-guardian-msg: #0d2d3a;
  --border: #2a2e42;
  --border-focus: #38bdf8;
  --text-primary: #e2e8f0;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --accent: #22d3ee;
  --accent-dim: #0e7490;
  --accent-glow: rgba(34, 211, 238, 0.12);
  --danger: #ef4444;
  --success: #22c55e;
  --radius: 8px;
  --radius-lg: 12px;
  --sidebar-width: 280px;
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', monospace;
  --transition: 150ms ease;
}

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

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

body {
  font-family: var(--font-sans);
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* ─── Auth Screen ─── */

#auth-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
  background: var(--bg-primary);
}

.auth-container {
  width: 100%;
  max-width: 400px;
  padding: 2rem;
}

.auth-header {
  text-align: center;
  margin-bottom: 2rem;
}

.auth-logo {
  font-size: 2rem;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 0.25rem;
  letter-spacing: -0.02em;
}

.auth-subtitle {
  color: var(--text-secondary);
  font-size: 0.9rem;
}

.auth-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
}

.auth-tabs {
  display: flex;
  gap: 0;
  margin-bottom: 1.5rem;
  border-bottom: 1px solid var(--border);
}

.auth-tab {
  flex: 1;
  padding: 0.75rem;
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: color var(--transition), border-color var(--transition);
  font-family: var(--font-sans);
}

.auth-tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.auth-tab:hover:not(.active) {
  color: var(--text-primary);
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.form-group label {
  font-size: 0.8rem;
  color: var(--text-secondary);
  font-weight: 500;
}

.form-group input {
  padding: 0.65rem 0.75rem;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-size: 0.9rem;
  font-family: var(--font-sans);
  outline: none;
  transition: border-color var(--transition);
}

.form-group input:focus {
  border-color: var(--border-focus);
}

.auth-btn {
  padding: 0.7rem 1rem;
  background: var(--accent-dim);
  color: white;
  border: none;
  border-radius: var(--radius);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  font-family: var(--font-sans);
  transition: background var(--transition);
  margin-top: 0.25rem;
}

.auth-btn:hover {
  background: var(--accent);
  color: var(--bg-primary);
}

.auth-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.auth-error {
  color: var(--danger);
  font-size: 0.8rem;
  text-align: center;
  min-height: 1.2rem;
}

/* ─── Chat Layout ─── */

#chat-screen {
  display: none;
  height: 100vh;
}

#chat-screen.visible {
  display: flex;
}

/* ─── Sidebar ─── */

.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

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

.sidebar-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: -0.01em;
}

.new-chat-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 1.1rem;
  transition: all var(--transition);
}

.new-chat-btn:hover {
  background: var(--bg-hover);
  color: var(--accent);
  border-color: var(--accent-dim);
}

.conversation-list {
  flex: 1;
  overflow-y: auto;
  padding: 0.5rem;
}

.conversation-list::-webkit-scrollbar {
  width: 4px;
}

.conversation-list::-webkit-scrollbar-track {
  background: transparent;
}

.conversation-list::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 2px;
}

.conversation-item {
  padding: 0.65rem 0.75rem;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background var(--transition);
  margin-bottom: 2px;
}

.conversation-item:hover {
  background: var(--bg-hover);
}

.conversation-item.active {
  background: var(--bg-active);
}

.conversation-item-title {
  font-size: 0.85rem;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.conversation-item-meta {
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.sidebar-footer {
  padding: 0.75rem 1rem;
  border-top: 1px solid var(--border);
}

.user-info {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.user-email {
  font-size: 0.75rem;
  color: var(--text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 170px;
}

.logout-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 0.75rem;
  cursor: pointer;
  padding: 0.25rem 0.5rem;
  border-radius: var(--radius);
  transition: all var(--transition);
  font-family: var(--font-sans);
}

.logout-btn:hover {
  color: var(--danger);
  background: rgba(239, 68, 68, 0.1);
}

/* ─── Chat Area ─── */

.chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.chat-header {
  padding: 0.75rem 1.25rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-height: 52px;
}

.mobile-menu-btn {
  display: none;
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 1.25rem;
  cursor: pointer;
  padding: 0.25rem;
}

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

/* ─── Messages ─── */

.messages-container {
  flex: 1;
  overflow-y: auto;
  padding: 1rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.messages-container::-webkit-scrollbar {
  width: 6px;
}

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

.messages-container::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

.message {
  display: flex;
  gap: 0.75rem;
  max-width: 80%;
  animation: messageIn 200ms ease-out;
}

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

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

.message.assistant {
  align-self: flex-start;
}

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

.message.user .message-avatar {
  background: var(--bg-active);
  color: var(--text-secondary);
}

.message.assistant .message-avatar {
  background: var(--accent-dim);
  color: white;
}

.message-bubble {
  padding: 0.65rem 0.9rem;
  border-radius: var(--radius-lg);
  font-size: 0.9rem;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
}

.message.user .message-bubble {
  background: var(--bg-user-msg);
  border-bottom-right-radius: 4px;
}

.message.assistant .message-bubble {
  background: var(--bg-guardian-msg);
  border: 1px solid rgba(34, 211, 238, 0.1);
  border-bottom-left-radius: 4px;
}

/* ─── Typing Indicator ─── */

.typing-indicator {
  display: none;
  align-self: flex-start;
  gap: 0.75rem;
  max-width: 80%;
  padding: 0 0 0.5rem;
}

.typing-indicator.visible {
  display: flex;
}

.typing-dots {
  padding: 0.75rem 1rem;
  background: var(--bg-guardian-msg);
  border: 1px solid rgba(34, 211, 238, 0.1);
  border-radius: var(--radius-lg);
  border-bottom-left-radius: 4px;
  display: flex;
  gap: 4px;
  align-items: center;
}

.typing-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  animation: typingPulse 1.4s infinite ease-in-out;
}

.typing-dot:nth-child(2) {
  animation-delay: 0.2s;
}

.typing-dot:nth-child(3) {
  animation-delay: 0.4s;
}

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

/* ─── Empty State ─── */

.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  text-align: center;
}

.empty-state-icon {
  font-size: 3rem;
  margin-bottom: 1rem;
  opacity: 0.6;
}

.empty-state-title {
  font-size: 1.25rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
  color: var(--text-primary);
}

.empty-state-text {
  color: var(--text-secondary);
  font-size: 0.9rem;
  max-width: 360px;
}

/* ─── Input Area ─── */

.input-area {
  padding: 0.75rem 1.25rem 1rem;
  border-top: 1px solid var(--border);
}

.input-wrapper {
  display: flex;
  gap: 0.5rem;
  align-items: flex-end;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 0.5rem 0.5rem 0.5rem 0.85rem;
  transition: border-color var(--transition);
}

.input-wrapper:focus-within {
  border-color: var(--border-focus);
}

#message-input {
  flex: 1;
  background: none;
  border: none;
  color: var(--text-primary);
  font-size: 0.9rem;
  font-family: var(--font-sans);
  line-height: 1.5;
  resize: none;
  outline: none;
  max-height: 150px;
  min-height: 24px;
}

#message-input::placeholder {
  color: var(--text-muted);
}

.send-btn {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--accent-dim);
  border: none;
  border-radius: var(--radius);
  color: white;
  cursor: pointer;
  flex-shrink: 0;
  transition: all var(--transition);
}

.send-btn:hover:not(:disabled) {
  background: var(--accent);
  color: var(--bg-primary);
}

.send-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

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

/* ─── Mobile Overlay ─── */

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 9;
}

/* ─── Responsive ─── */

@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    z-index: 10;
    transform: translateX(-100%);
    transition: transform 200ms ease;
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .sidebar.open ~ .sidebar-overlay {
    display: block;
  }

  .mobile-menu-btn {
    display: block;
  }

  .message {
    max-width: 90%;
  }
}
