/* ===========================
   RevisaPrev Q&A — Design System
   =========================== */

:root {
  /* Colors - Dark Theme */
  --bg-primary: #0a0e17;
  --bg-secondary: #111827;
  --bg-tertiary: #1a2332;
  --bg-card: #151e2d;
  --bg-hover: #1e2a3d;
  --bg-input: #0d1321;
  
  --text-primary: #e8ecf4;
  --text-secondary: #8b95a8;
  --text-muted: #5a6578;
  
  --accent: #6366f1;
  --accent-hover: #818cf8;
  --accent-glow: rgba(99, 102, 241, 0.15);
  --accent-subtle: rgba(99, 102, 241, 0.08);
  
  --success: #10b981;
  --warning: #f59e0b;
  --error: #ef4444;
  --info: #3b82f6;
  
  --border: rgba(255, 255, 255, 0.06);
  --border-focus: rgba(99, 102, 241, 0.4);
  
  --sidebar-width: 320px;
  --radius: 12px;
  --radius-sm: 8px;
  --radius-lg: 16px;

  --shadow-sm: 0 1px 3px rgba(0,0,0,0.3);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.4);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.5);
}

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

html, body {
  height: 100%;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* ===========================
   Layout
   =========================== */
.app {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ===========================
   Sidebar
   =========================== */
.sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  transition: transform 0.3s ease;
}

.sidebar-header {
  padding: 20px;
  border-bottom: 1px solid var(--border);
}

.logo {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo-icon {
  width: 40px;
  height: 40px;
  background: linear-gradient(135deg, var(--accent), #a78bfa);
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.logo-icon svg {
  width: 22px;
  height: 22px;
  color: white;
}

.logo h1 {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.3px;
  background: linear-gradient(135deg, var(--text-primary), var(--accent-hover));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.logo-subtitle {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 400;
}

.sidebar-section {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.sidebar-title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-muted);
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* DB Status */
.db-status {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--bg-tertiary);
  border-radius: var(--radius-sm);
  font-size: 13px;
  color: var(--text-secondary);
}

.status-indicator {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.status-indicator.connected {
  background: var(--success);
  box-shadow: 0 0 8px rgba(16, 185, 129, 0.5);
}

.status-indicator.error {
  background: var(--error);
  box-shadow: 0 0 8px rgba(239, 68, 68, 0.5);
}

.status-indicator.loading {
  background: var(--warning);
  animation: pulse 1.5s infinite;
}

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

/* Suggestions */
.suggestions-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.suggestion-category {
  margin-bottom: 8px;
}

.suggestion-category-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
  padding-left: 4px;
}

.suggestion-btn {
  display: block;
  width: 100%;
  text-align: left;
  padding: 8px 12px;
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 12px;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.2s;
  line-height: 1.4;
}

.suggestion-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
  transform: translateX(4px);
}

/* Tables Info */
.tables-info {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 300px;
  overflow-y: auto;
}

.table-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  transition: background 0.2s;
}

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

.table-name {
  color: var(--text-secondary);
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 11px;
}

.table-count {
  font-size: 11px;
  color: var(--text-muted);
  background: var(--bg-tertiary);
  padding: 2px 8px;
  border-radius: 20px;
}

.loading-text {
  font-size: 12px;
  color: var(--text-muted);
  font-style: italic;
}

/* ===========================
   Main Content
   =========================== */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}

.chat-container {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  scroll-behavior: smooth;
}

/* Welcome Screen */
.welcome-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 60vh;
  text-align: center;
  padding: 40px 20px;
  animation: fadeInUp 0.6s ease;
}

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

.welcome-icon {
  width: 100px;
  height: 100px;
  background: linear-gradient(135deg, var(--accent), #a78bfa);
  border-radius: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 24px;
  box-shadow: 0 8px 32px rgba(99, 102, 241, 0.3);
}

.welcome-icon svg {
  color: white;
}

.welcome-screen h2 {
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 8px;
  max-width: 500px;
  background: linear-gradient(135deg, var(--text-primary), var(--accent-hover));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.welcome-screen p {
  color: var(--text-secondary);
  max-width: 460px;
  font-size: 14px;
  margin-bottom: 32px;
}

.quick-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  max-width: 600px;
}

.quick-action-btn {
  padding: 10px 16px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-secondary);
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.25s;
}

.quick-action-btn:hover {
  background: var(--accent-subtle);
  border-color: var(--border-focus);
  color: var(--accent-hover);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

/* Messages */
.messages {
  display: flex;
  flex-direction: column;
  gap: 20px;
  max-width: 900px;
  margin: 0 auto;
  width: 100%;
}

.message {
  display: flex;
  gap: 12px;
  animation: messageIn 0.35s ease;
}

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

.message-avatar {
  width: 36px;
  height: 36px;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 16px;
}

.message.user .message-avatar {
  background: linear-gradient(135deg, #3b82f6, #2563eb);
}

.message.assistant .message-avatar {
  background: linear-gradient(135deg, var(--accent), #a78bfa);
}

.message-body {
  flex: 1;
  min-width: 0;
}

.message-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.message-sender {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
}

.message-time {
  font-size: 11px;
  color: var(--text-muted);
}

.message-content {
  padding: 14px 18px;
  border-radius: var(--radius);
  font-size: 14px;
  line-height: 1.7;
  word-wrap: break-word;
}

.message.user .message-content {
  background: var(--bg-card);
  border: 1px solid var(--border);
}

.message.assistant .message-content {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
}

/* Markdown in messages */
.message-content h1, .message-content h2, .message-content h3 {
  margin-top: 12px;
  margin-bottom: 6px;
  font-weight: 600;
}

.message-content h1 { font-size: 18px; }
.message-content h2 { font-size: 16px; }
.message-content h3 { font-size: 14px; }

.message-content p { margin-bottom: 8px; }

.message-content ul, .message-content ol {
  margin: 8px 0;
  padding-left: 20px;
}

.message-content li { margin-bottom: 4px; }

.message-content strong { color: var(--text-primary); font-weight: 600; }

.message-content em { color: var(--text-secondary); }

.message-content code {
  background: rgba(99, 102, 241, 0.15);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 12px;
  color: var(--accent-hover);
}

.message-content pre {
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  overflow-x: auto;
  margin: 8px 0;
}

.message-content pre code {
  background: none;
  padding: 0;
  color: var(--text-secondary);
  font-size: 12px;
}

.message-content table {
  width: 100%;
  border-collapse: collapse;
  margin: 8px 0;
  font-size: 13px;
}

.message-content th {
  background: var(--bg-primary);
  padding: 8px 12px;
  text-align: left;
  font-weight: 600;
  border-bottom: 1px solid var(--border);
  color: var(--text-secondary);
}

.message-content td {
  padding: 6px 12px;
  border-bottom: 1px solid var(--border);
}

.message-content tr:hover td {
  background: var(--bg-hover);
}

/* SQL Accordion */
.sql-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 10px;
  padding: 6px 12px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 11px;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.2s;
}

.sql-toggle:hover {
  border-color: var(--accent);
  color: var(--accent-hover);
  background: var(--accent-subtle);
}

.sql-toggle svg {
  transition: transform 0.2s;
}

.sql-toggle.open svg {
  transform: rotate(90deg);
}

.sql-code {
  display: none;
  margin-top: 8px;
}

.sql-code.show {
  display: block;
}

/* Loading */
.loading-dots {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 14px 18px;
}

.loading-dots span {
  width: 8px;
  height: 8px;
  background: var(--accent);
  border-radius: 50%;
  animation: dotBounce 1.4s infinite ease-in-out both;
}

.loading-dots span:nth-child(1) { animation-delay: 0s; }
.loading-dots span:nth-child(2) { animation-delay: 0.16s; }
.loading-dots span:nth-child(3) { animation-delay: 0.32s; }

@keyframes dotBounce {
  0%, 80%, 100% {
    transform: scale(0.4);
    opacity: 0.4;
  }
  40% {
    transform: scale(1);
    opacity: 1;
  }
}

/* ===========================
   Input Area
   =========================== */
.input-area {
  padding: 16px 24px 20px;
  border-top: 1px solid var(--border);
  background: var(--bg-secondary);
}

.input-form {
  max-width: 900px;
  margin: 0 auto;
}

.input-wrapper {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 12px;
  transition: border-color 0.3s, box-shadow 0.3s;
}

.input-wrapper:focus-within {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.input-wrapper textarea {
  flex: 1;
  background: none;
  border: none;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 14px;
  line-height: 1.5;
  resize: none;
  outline: none;
  max-height: 120px;
  padding: 6px 4px;
}

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

.send-btn {
  width: 38px;
  height: 38px;
  background: linear-gradient(135deg, var(--accent), #818cf8);
  border: none;
  border-radius: var(--radius-sm);
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.25s;
}

.send-btn:hover {
  transform: scale(1.05);
  box-shadow: 0 4px 16px rgba(99, 102, 241, 0.4);
}

.send-btn:active {
  transform: scale(0.95);
}

.send-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.input-hint {
  text-align: center;
  margin-top: 8px;
  font-size: 11px;
  color: var(--text-muted);
}

.input-hint kbd {
  background: var(--bg-tertiary);
  padding: 1px 6px;
  border-radius: 4px;
  border: 1px solid var(--border);
  font-family: inherit;
  font-size: 10px;
}

/* ===========================
   Mobile Sidebar Toggle
   =========================== */
.sidebar-toggle {
  display: none;
  position: fixed;
  top: 16px;
  left: 16px;
  z-index: 1000;
  width: 40px;
  height: 40px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  cursor: pointer;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.sidebar-toggle:hover {
  background: var(--bg-hover);
}

/* ===========================
   Scrollbar
   =========================== */
::-webkit-scrollbar {
  width: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--bg-hover);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* ===========================
   Responsive
   =========================== */
@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    z-index: 999;
    transform: translateX(-100%);
  }

  .sidebar.open {
    transform: translateX(0);
    box-shadow: var(--shadow-lg);
  }

  .sidebar-toggle {
    display: flex;
  }

  .chat-container {
    padding: 16px;
    padding-top: 60px;
  }

  .input-area {
    padding: 12px 16px;
  }

  .welcome-screen h2 {
    font-size: 18px;
  }

  .quick-actions {
    flex-direction: column;
  }
}

/* ===========================
   Login Screen
   =========================== */
.login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
  background: var(--bg-primary);
  position: fixed;
  inset: 0;
  z-index: 9999;
}

.login-card {
  text-align: center;
  padding: 48px 40px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  max-width: 400px;
  width: 90%;
  animation: fadeInUp 0.6s ease;
}

.login-logo {
  width: 80px;
  height: 80px;
  background: linear-gradient(135deg, var(--accent), #a78bfa);
  border-radius: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 20px;
  box-shadow: 0 8px 32px rgba(99, 102, 241, 0.3);
}

.login-logo svg {
  color: white;
}

.login-card h1 {
  font-size: 24px;
  font-weight: 700;
  margin-bottom: 6px;
  background: linear-gradient(135deg, var(--text-primary), var(--accent-hover));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.login-card p {
  color: var(--text-secondary);
  margin-bottom: 32px;
  font-size: 14px;
}

.google-login-btn {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 12px 28px;
  background: white;
  color: #333;
  border: none;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  text-decoration: none;
  transition: all 0.25s;
  box-shadow: var(--shadow-sm);
}

.google-login-btn:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.login-hint {
  display: block;
  margin-top: 16px;
  font-size: 11px;
  color: var(--text-muted);
}

/* ===========================
   User Info (sidebar)
   =========================== */
.user-info {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
  padding: 8px 10px;
  background: var(--bg-tertiary);
  border-radius: var(--radius-sm);
}

.user-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  object-fit: cover;
}

.user-name {
  flex: 1;
  font-size: 12px;
  color: var(--text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.logout-btn {
  color: var(--text-muted);
  text-decoration: none;
  font-size: 14px;
  padding: 2px 6px;
  border-radius: 4px;
  transition: all 0.2s;
}

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