/* ==========================================================
   Inspecta AI — Design System & Styles
   ========================================================== */

/* --- CSS Variables (Design Tokens) --- */
:root {
  --color-bg: #0f0f14;
  --color-surface: #1a1a24;
  --color-surface-hover: #22222e;
  --color-border: #2a2a3a;
  --color-text: #e4e4ed;
  --color-text-muted: #8888a0;
  --color-primary: #6366f1;
  --color-primary-hover: #818cf8;
  --color-primary-glow: rgba(99, 102, 241, 0.15);
  --color-accent: #8b5cf6;
  --color-success: #22c55e;
  --color-error: #ef4444;
  --color-warning: #f59e0b;
  --font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.4);
  --transition: 150ms ease;
}

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

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

/* --- Screens --- */
.screen { display: none; min-height: 100vh; }
.screen.active { display: flex; }
.hidden { display: none !important; }

/* --- Auth Screen --- */
.auth-container {
  margin: auto;
  width: 100%;
  max-width: 400px;
  padding: 2rem;
}

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

.auth-header .logo { margin-bottom: 1rem; }

.auth-header h1 {
  font-size: 1.75rem;
  font-weight: 700;
  background: linear-gradient(135deg, var(--color-primary), var(--color-accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.auth-header .subtitle {
  color: var(--color-text-muted);
  font-size: 0.9rem;
  margin-top: 0.25rem;
}

/* --- Forms --- */
.form-group {
  margin-bottom: 1rem;
}

.form-group label {
  display: block;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--color-text-muted);
  margin-bottom: 0.4rem;
}

.form-group input {
  width: 100%;
  padding: 0.75rem 1rem;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  color: var(--color-text);
  font-family: var(--font-family);
  font-size: 0.95rem;
  transition: border-color var(--transition);
}

.form-group input:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--color-primary-glow);
}

/* --- Buttons --- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.75rem 1.5rem;
  border: none;
  border-radius: var(--radius-sm);
  font-family: var(--font-family);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  width: 100%;
}

.btn-primary {
  background: linear-gradient(135deg, var(--color-primary), var(--color-accent));
  color: white;
}

.btn-primary:hover {
  opacity: 0.9;
  transform: translateY(-1px);
  box-shadow: 0 4px 20px var(--color-primary-glow);
}

.btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.btn-ghost {
  background: transparent;
  color: var(--color-text-muted);
  padding: 0.5rem;
}

.btn-ghost:hover { color: var(--color-text); }

.btn-sm { padding: 0.4rem 0.8rem; width: auto; font-size: 0.8rem; }

.btn-icon {
  width: 44px;
  height: 44px;
  padding: 0;
  border-radius: 50%;
  flex-shrink: 0;
}

.error-msg {
  margin-top: 1rem;
  padding: 0.75rem 1rem;
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.3);
  border-radius: var(--radius-sm);
  color: var(--color-error);
  font-size: 0.85rem;
  text-align: center;
}

/* --- App Header --- */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1.5rem;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  position: sticky;
  top: 0;
  z-index: 10;
  backdrop-filter: blur(12px);
}

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

.header-title {
  font-weight: 700;
  font-size: 1.1rem;
  background: linear-gradient(135deg, var(--color-primary), var(--color-accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.user-email {
  color: var(--color-text-muted);
  font-size: 0.8rem;
}

/* --- Chat --- */
#chat-screen {
  flex-direction: column;
}

.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  max-width: 800px;
  margin: 0 auto;
  width: 100%;
  padding: 0 1rem;
}

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

.welcome-msg {
  text-align: center;
  margin: auto 0;
  padding: 2rem;
}

.welcome-msg h2 {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
}

.welcome-msg p {
  color: var(--color-text-muted);
}

/* Message bubbles */
.message {
  max-width: 85%;
  padding: 1rem 1.25rem;
  border-radius: var(--radius-md);
  font-size: 0.95rem;
  line-height: 1.7;
  animation: fadeIn 200ms ease;
}

.message.user {
  align-self: flex-end;
  background: linear-gradient(135deg, var(--color-primary), var(--color-accent));
  color: white;
  border-bottom-right-radius: 4px;
}

.message.assistant {
  align-self: flex-start;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-bottom-left-radius: 4px;
}

.message .provider-badge {
  display: inline-block;
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.15rem 0.5rem;
  border-radius: 20px;
  margin-top: 0.5rem;
  background: rgba(255,255,255,0.08);
  color: var(--color-text-muted);
}

.typing-indicator {
  display: flex;
  gap: 4px;
  padding: 1rem 1.25rem;
}

.typing-indicator span {
  width: 8px;
  height: 8px;
  background: var(--color-text-muted);
  border-radius: 50%;
  animation: bounce 1.2s infinite;
}

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

/* --- Chat Input Bar --- */
.chat-input-bar {
  display: flex;
  align-items: flex-end;
  gap: 0.75rem;
  padding: 1rem 0 1.5rem;
  border-top: 1px solid var(--color-border);
}

.chat-input-bar textarea {
  flex: 1;
  padding: 0.75rem 1rem;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  color: var(--color-text);
  font-family: var(--font-family);
  font-size: 0.95rem;
  resize: none;
  max-height: 150px;
  line-height: 1.5;
  transition: border-color var(--transition);
}

.chat-input-bar textarea:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--color-primary-glow);
}

/* --- Animations --- */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes bounce {
  0%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-6px); }
}

/* --- Responsive --- */
@media (max-width: 640px) {
  .auth-container { padding: 1rem; }
  .chat-main { padding: 0 0.5rem; }
  .message { max-width: 92%; }
  .user-email { display: none; }
  .rate-limit-pill { display: none; }
}

/* ==========================================================
   Reactive UI Additions (HTMX + Store Integration)
   ========================================================== */

/* --- Rate Limit Pill (Header) --- */
.rate-limit-pill {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--color-text-muted);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 20px;
  padding: 0.25rem 0.75rem;
  letter-spacing: 0.02em;
}

.rate-limit-bar {
  width: 48px;
  height: 4px;
  background: var(--color-border);
  border-radius: 2px;
  overflow: hidden;
}

.rate-limit-fill {
  height: 100%;
  width: 100%;
  background: var(--color-success);
  border-radius: 2px;
  transition: width 300ms ease, background 300ms ease;
}

.rate-limit-fill.medium { background: var(--color-warning); }
.rate-limit-fill.low { background: var(--color-error); }

/* --- Rate Limit Warning Bar --- */
.rate-limit-warning {
  padding: 0.5rem 1rem;
  background: rgba(245, 158, 11, 0.1);
  border: 1px solid rgba(245, 158, 11, 0.3);
  border-radius: var(--radius-sm);
  color: var(--color-warning);
  font-size: 0.8rem;
  text-align: center;
  margin-bottom: 0.5rem;
  animation: fadeIn 200ms ease;
}

/* --- Streaming Message Cursor --- */
.message.streaming .message-content::after {
  content: '▊';
  display: inline;
  color: var(--color-primary);
  animation: blink 0.8s step-end infinite;
}

.message.typing .message-content::before {
  content: '';
}

.message.typing::after {
  content: '';
  display: flex;
  gap: 4px;
}

/* --- Processing Spinner --- */
.spinner {
  width: 18px;
  height: 18px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

.btn-processing {
  pointer-events: none;
  opacity: 0.8;
}

/* --- Message Content (within streaming container) --- */
.message-content {
  white-space: pre-wrap;
  word-break: break-word;
}

.message-content code {
  background: rgba(255, 255, 255, 0.06);
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
  font-size: 0.85em;
  font-family: 'Fira Code', 'Cascadia Code', monospace;
}

.message-content pre {
  background: rgba(0, 0, 0, 0.3);
  padding: 0.75rem 1rem;
  border-radius: var(--radius-sm);
  overflow-x: auto;
  margin: 0.5rem 0;
}

.message-content pre code {
  background: none;
  padding: 0;
}

.message-content strong { font-weight: 700; }
.message-content em { font-style: italic; color: var(--color-text-muted); }

/* --- Error Message State --- */
.message.error .message-content {
  color: var(--color-error);
  font-style: italic;
}

/* --- Toast Enhancement (slide-up + fade) --- */
.toast {
  animation: toastIn 300ms cubic-bezier(0.16, 1, 0.3, 1) forwards;
  box-shadow: var(--shadow-md);
}

/* --- New Animations --- */
@keyframes blink {
  50% { opacity: 0; }
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

@keyframes toastIn {
  from {
    opacity: 0;
    transform: translateX(-50%) translateY(16px);
  }
  to {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
  }
}

/* --- HTMX Loading Indicator --- */
.htmx-request .htmx-indicator {
  display: inline-block;
}

.htmx-indicator {
  display: none;
}
