/* ==========================================================================
   GRIHA AI Assistant - Modern Design System & Stylesheet
   Theme: Eco-Tech Glassmorphism & Emerald Accents
   ========================================================================== */

:root {
  --bg-primary: #0b0f17;
  --bg-secondary: #111827;
  --bg-card: rgba(17, 24, 39, 0.75);
  --bg-card-hover: rgba(31, 41, 55, 0.85);
  --bg-input: #1e293b;
  --border-color: rgba(255, 255, 255, 0.08);
  --border-glow: rgba(16, 185, 129, 0.3);

  --accent-primary: #10b981;
  --accent-primary-hover: #059669;
  --accent-gradient: linear-gradient(135deg, #10b981 0%, #06b6d4 100%);
  --accent-glow: 0 0 20px rgba(16, 185, 129, 0.25);

  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;

  --user-bubble-bg: linear-gradient(135deg, #0f766e 0%, #047857 100%);
  --assistant-bubble-bg: rgba(30, 41, 59, 0.85);

  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.2);
  --shadow-md: 0 4px 20px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 10px 30px rgba(0, 0, 0, 0.5);

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 18px;
  --radius-full: 9999px;

  --transition-fast: 0.15s cubic-bezier(0.4, 0, 0.2, 1);
  --transition-normal: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Base & Reset */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-family: 'Outfit', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
}

body {
  background-color: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  display: flex;
  overflow: hidden;
}

/* App Container Layout */
.app-container {
  display: flex;
  width: 100vw;
  height: 100vh;
  position: relative;
}

/* Sidebar */
.sidebar {
  width: 280px;
  background-color: var(--bg-secondary);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  padding: 1.25rem;
  z-index: 20;
  transition: transform var(--transition-normal);
}

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

.brand-icon {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  background: var(--accent-gradient);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 1.25rem;
  box-shadow: var(--accent-glow);
}

.brand-title {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: #ffffff;
}

.brand-subtitle {
  font-size: 0.75rem;
  color: var(--accent-primary);
  font-weight: 500;
}

.btn-new-chat {
  margin-top: 1.25rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  width: 100%;
  padding: 0.75rem 1rem;
  background: rgba(16, 185, 129, 0.12);
  border: 1px solid rgba(16, 185, 129, 0.3);
  border-radius: var(--radius-md);
  color: #34d399;
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.btn-new-chat:hover {
  background: var(--accent-primary);
  color: #0b0f17;
  box-shadow: var(--accent-glow);
  transform: translateY(-1px);
}

.sidebar-section-title {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin: 1.5rem 0 0.6rem 0.25rem;
  font-weight: 600;
}

.session-badge {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  padding: 0.6rem 0.8rem;
  border-radius: var(--radius-md);
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.session-id-text {
  font-family: monospace;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 150px;
}

.btn-copy-session {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
  font-size: 0.85rem;
  transition: color var(--transition-fast);
}

.btn-copy-session:hover {
  color: var(--accent-primary);
}

.sidebar-links {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  border-top: 1px solid var(--border-color);
  padding-top: 1rem;
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 0.85rem;
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius-sm);
  transition: all var(--transition-fast);
}

.sidebar-link:hover {
  background: var(--bg-card-hover);
  color: var(--text-primary);
}

/* Chat Main View */
.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100vh;
  position: relative;
  background: radial-gradient(circle at 50% 0%, rgba(16, 185, 129, 0.05) 0%, transparent 60%);
}

/* Chat Header */
.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.75rem;
  background: rgba(11, 15, 23, 0.85);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-color);
  z-index: 10;
}

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

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

.chat-title-group h1 {
  font-size: 1.1rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.status-indicator {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.75rem;
  color: #34d399;
  font-weight: 500;
  margin-top: 2px;
}

.status-dot {
  width: 7px;
  height: 7px;
  background-color: #10b981;
  border-radius: 50%;
  box-shadow: 0 0 8px #10b981;
}

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

.badge-grounded {
  font-size: 0.75rem;
  background: rgba(16, 185, 129, 0.15);
  color: #34d399;
  padding: 0.3rem 0.65rem;
  border-radius: var(--radius-full);
  border: 1px solid rgba(16, 185, 129, 0.3);
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

/* Chat Messages Stream Area */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1.5rem 1.75rem 6rem 1.75rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  scroll-behavior: smooth;
}

/* Scrollbar Customization */
.chat-messages::-webkit-scrollbar {
  width: 6px;
}
.chat-messages::-webkit-scrollbar-track {
  background: transparent;
}
.chat-messages::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 3px;
}
.chat-messages::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.2);
}

/* Empty State / Welcome Screen */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  margin: auto;
  max-width: 650px;
  text-align: center;
  padding: 2rem 1rem;
  animation: fadeIn 0.4s ease-out;
}

.welcome-logo {
  width: 64px;
  height: 64px;
  border-radius: 20px;
  background: var(--accent-gradient);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  color: white;
  margin-bottom: 1.25rem;
  box-shadow: var(--accent-glow);
}

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

.empty-state p {
  color: var(--text-secondary);
  font-size: 0.95rem;
  line-height: 1.5;
  margin-bottom: 2rem;
}

.suggestions-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 0.85rem;
  width: 100%;
}

.suggestion-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  padding: 0.9rem 1.1rem;
  border-radius: var(--radius-md);
  text-align: left;
  cursor: pointer;
  transition: all var(--transition-fast);
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.88rem;
  color: var(--text-primary);
}

.suggestion-card:hover {
  background: var(--bg-card-hover);
  border-color: var(--border-glow);
  transform: translateY(-2px);
  box-shadow: var(--shadow-sm);
}

.suggestion-icon {
  color: var(--accent-primary);
  font-size: 1.1rem;
}

/* Chat Message Row */
.message-row {
  display: flex;
  gap: 1rem;
  width: 100%;
  max-width: 850px;
  margin: 0 auto;
  animation: slideUp 0.25s ease-out;
}

.message-row.user-row {
  justify-content: flex-end;
}

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

.assistant-avatar {
  background: var(--accent-gradient);
  color: #ffffff;
  box-shadow: var(--accent-glow);
}

.user-avatar {
  background: #3b82f6;
  color: white;
}

/* Message Content Box */
.message-body {
  max-width: calc(100% - 50px);
  display: flex;
  flex-direction: column;
}

.user-row .message-body {
  align-items: flex-end;
}

.message-bubble {
  padding: 0.9rem 1.25rem;
  border-radius: var(--radius-lg);
  line-height: 1.6;
  font-size: 0.95rem;
  position: relative;
  word-break: break-word;
}

.user-bubble {
  background: var(--user-bubble-bg);
  color: #ffffff;
  border-bottom-right-radius: 4px;
  box-shadow: var(--shadow-sm);
}

.assistant-bubble {
  background: var(--assistant-bubble-bg);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  border-bottom-left-radius: 4px;
  box-shadow: var(--shadow-md);
}

/* Markdown Rendering Inside Assistant Bubbles */
.assistant-bubble h1, 
.assistant-bubble h2, 
.assistant-bubble h3 {
  color: #ffffff;
  margin-top: 0.75rem;
  margin-bottom: 0.35rem;
  font-weight: 600;
}

.assistant-bubble h1 { font-size: 1.2rem; }
.assistant-bubble h2 { font-size: 1.1rem; }
.assistant-bubble h3 { font-size: 1.0rem; }

.assistant-bubble p {
  margin-bottom: 0.6rem;
}

.assistant-bubble p:last-child {
  margin-bottom: 0;
}

.assistant-bubble ul, 
.assistant-bubble ol {
  margin: 0.4rem 0 0.6rem 1.4rem;
}

.assistant-bubble li {
  margin-bottom: 0.3rem;
}

.assistant-bubble strong {
  color: #34d399;
  font-weight: 600;
}

.assistant-bubble code {
  background: rgba(0, 0, 0, 0.35);
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
  font-family: 'Consolas', 'Courier New', monospace;
  font-size: 0.88em;
  color: #6ee7b7;
}

.assistant-bubble pre {
  background: #090d14;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 0.75rem 1rem;
  overflow-x: auto;
  margin: 0.6rem 0;
}

.assistant-bubble pre code {
  background: transparent;
  padding: 0;
  color: #e2e8f0;
}

.assistant-bubble table {
  border-collapse: collapse;
  width: 100%;
  margin: 0.75rem 0;
  font-size: 0.88rem;
}

.assistant-bubble th, 
.assistant-bubble td {
  border: 1px solid var(--border-color);
  padding: 0.5rem 0.75rem;
  text-align: left;
}

.assistant-bubble th {
  background: rgba(16, 185, 129, 0.1);
  color: #34d399;
  font-weight: 600;
}

/* Message Action Bar (Feedback & Copy) */
.message-actions {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin-top: 0.4rem;
  padding-left: 0.25rem;
}

.action-btn {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  transition: all var(--transition-fast);
}

.action-btn:hover {
  background: var(--bg-card-hover);
  color: var(--text-primary);
  border-color: var(--border-color);
}

.action-btn.active-up {
  color: #34d399;
  background: rgba(16, 185, 129, 0.15);
  border-color: rgba(16, 185, 129, 0.4);
}

.action-btn.active-down {
  color: #f87171;
  background: rgba(239, 68, 68, 0.15);
  border-color: rgba(239, 68, 68, 0.4);
}

/* Typing / Streaming Cursor */
.streaming-cursor {
  display: inline-block;
  width: 6px;
  height: 14px;
  background: var(--accent-primary);
  margin-left: 3px;
  vertical-align: middle;
  animation: blink 0.8s infinite;
}

/* Typing Indicator (Dots) */
.typing-bubble {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 0.8rem 1.1rem;
}

.dot {
  width: 7px;
  height: 7px;
  background: var(--text-muted);
  border-radius: 50%;
  animation: dotPulse 1.4s infinite ease-in-out both;
}

.dot:nth-child(1) { animation-delay: -0.32s; }
.dot:nth-child(2) { animation-delay: -0.16s; }

/* Sticky Bottom Input Bar */
.chat-input-wrapper {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 1.25rem 1.75rem;
  background: linear-gradient(to top, var(--bg-primary) 70%, transparent 100%);
  display: flex;
  justify-content: center;
}

.input-container {
  width: 100%;
  max-width: 850px;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  display: flex;
  align-items: flex-end;
  padding: 0.5rem 0.75rem;
  gap: 0.5rem;
  box-shadow: var(--shadow-lg);
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.input-container:focus-within {
  border-color: var(--accent-primary);
  box-shadow: 0 0 16px rgba(16, 185, 129, 0.2);
}

.chat-textarea {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-size: 0.95rem;
  resize: none;
  max-height: 150px;
  min-height: 24px;
  padding: 0.35rem 0.25rem;
  line-height: 1.5;
}

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

.send-btn {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-md);
  background: var(--accent-gradient);
  border: none;
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 1rem;
  flex-shrink: 0;
  transition: all var(--transition-fast);
}

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

.send-btn:not(:disabled):hover {
  box-shadow: var(--accent-glow);
  transform: scale(1.04);
}

/* Feedback Modal Dialog */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
  animation: fadeIn 0.2s ease-out;
}

.modal-overlay.open {
  display: flex;
}

.feedback-modal {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  width: 90%;
  max-width: 440px;
  box-shadow: var(--shadow-lg);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}

.modal-title {
  font-size: 1.1rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.close-modal-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 1.25rem;
  cursor: pointer;
}

.feedback-modal textarea {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 0.75rem;
  color: var(--text-primary);
  font-size: 0.9rem;
  min-height: 90px;
  resize: vertical;
  outline: none;
  margin-bottom: 1rem;
}

.feedback-modal textarea:focus {
  border-color: var(--accent-primary);
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
}

.btn-secondary {
  background: transparent;
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  padding: 0.55rem 1rem;
  border-radius: var(--radius-md);
  cursor: pointer;
  font-weight: 500;
}

.btn-primary {
  background: var(--accent-gradient);
  border: none;
  color: #ffffff;
  padding: 0.55rem 1.25rem;
  border-radius: var(--radius-md);
  cursor: pointer;
  font-weight: 600;
  box-shadow: var(--accent-glow);
}

/* Animations */
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

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

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

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

/* Responsive Mobile Layout */
@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    transform: translateX(-100%);
    box-shadow: var(--shadow-lg);
  }

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

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

  .chat-messages {
    padding: 1rem 1rem 6rem 1rem;
  }

  .chat-input-wrapper {
    padding: 0.75rem 1rem;
  }

  .badge-grounded span {
    display: none;
  }
}
