/* ==========================================================================
   NEXUS AI CHAT STUDIO - DESIGN SYSTEM & STYLESHEET
   Module 3: LLM APIs & Application Development
   ========================================================================== */

:root {
  --bg-canvas: #090d16;
  --bg-sidebar: #0f1523;
  --bg-card: rgba(20, 27, 44, 0.7);
  --bg-input: #151d30;
  
  --border-subtle: rgba(255, 255, 255, 0.08);
  --border-focus: rgba(99, 102, 241, 0.5);
  
  --accent-indigo: #6366f1;
  --accent-cyan: #06b6d4;
  --accent-emerald: #10b981;
  --accent-amber: #f59e0b;
  --accent-rose: #f43f5e;
  
  --gradient-brand: linear-gradient(135deg, #6366f1 0%, #06b6d4 100%);
  --gradient-glow: linear-gradient(135deg, rgba(99, 102, 241, 0.15) 0%, rgba(6, 182, 212, 0.15) 100%);
  
  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', monospace;
  
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 18px;
  --radius-full: 9999px;
  
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.25);
  --shadow-lg: 0 10px 30px -10px rgba(0, 0, 0, 0.5);
  --shadow-glow: 0 0 25px rgba(99, 102, 241, 0.25);
  
  --transition-fast: 0.15s ease;
  --transition-normal: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

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

body {
  font-family: var(--font-sans);
  background-color: var(--bg-canvas);
  color: var(--text-primary);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background-image: 
    radial-gradient(at 0% 0%, rgba(99, 102, 241, 0.12) 0px, transparent 50%),
    radial-gradient(at 100% 100%, rgba(6, 182, 212, 0.08) 0px, transparent 50%);
}

/* ==========================================================================
   HEADER
   ========================================================================== */

.app-header {
  height: 64px;
  border-bottom: 1px solid var(--border-subtle);
  background: rgba(15, 21, 35, 0.85);
  backdrop-filter: blur(16px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  z-index: 40;
}

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

.brand-logo {
  width: 36px;
  height: 36px;
  filter: drop-shadow(0 0 8px rgba(99, 102, 241, 0.5));
}

.brand-title {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  background: var(--gradient-brand);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.badge-module {
  font-size: 0.7rem;
  padding: 3px 8px;
  border-radius: var(--radius-full);
  background: rgba(99, 102, 241, 0.15);
  color: #a5b4fc;
  border: 1px solid rgba(99, 102, 241, 0.3);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

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

.hud-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(20, 27, 44, 0.8);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-full);
  padding: 6px 14px;
  font-size: 0.82rem;
  color: var(--text-secondary);
  cursor: pointer;
  transition: var(--transition-fast);
}

.hud-pill:hover {
  border-color: var(--accent-indigo);
  color: var(--text-primary);
  background: rgba(99, 102, 241, 0.1);
}

.hud-pill .stat-highlight {
  color: var(--accent-emerald);
  font-weight: 600;
  font-family: var(--font-mono);
}

.btn-icon {
  background: rgba(20, 27, 44, 0.8);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  width: 38px;
  height: 38px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: var(--transition-fast);
}

.btn-icon:hover {
  background: rgba(99, 102, 241, 0.15);
  border-color: var(--accent-indigo);
  color: var(--text-primary);
}

/* ==========================================================================
   APP LAYOUT (SPLIT VIEW)
   ========================================================================== */

.app-container {
  display: flex;
  flex: 1;
  height: calc(100vh - 64px);
  overflow: hidden;
}

/* SIDEBAR */
.sidebar {
  width: 330px;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  padding: 18px;
  gap: 20px;
  flex-shrink: 0;
}

.btn-new-chat {
  background: var(--gradient-brand);
  color: #ffffff;
  border: none;
  border-radius: var(--radius-md);
  padding: 12px 18px;
  font-weight: 600;
  font-size: 0.92rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  box-shadow: 0 4px 15px rgba(99, 102, 241, 0.35);
  transition: var(--transition-normal);
}

.btn-new-chat:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(99, 102, 241, 0.5);
}

.sidebar-section-title {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  font-weight: 700;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.control-group {
  display: flex;
  flex-direction: column;
  gap: 14px;
  background: var(--bg-card);
  padding: 14px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
}

.control-item {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.control-label {
  display: flex;
  justify-content: space-between;
  font-size: 0.8rem;
  color: var(--text-secondary);
  font-weight: 500;
}

.control-value {
  font-family: var(--font-mono);
  color: var(--accent-cyan);
  font-size: 0.75rem;
}

.form-select, .form-input {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  color: var(--text-primary);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  font-size: 0.85rem;
  outline: none;
  transition: var(--transition-fast);
}

.form-select:focus, .form-input:focus {
  border-color: var(--accent-indigo);
  box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.2);
}

.form-range {
  width: 100%;
  accent-color: var(--accent-indigo);
  cursor: pointer;
}

/* Chat Sessions List in Sidebar */
.sessions-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 180px;
  overflow-y: auto;
}

.session-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid transparent;
  cursor: pointer;
  font-size: 0.82rem;
  color: var(--text-secondary);
  transition: var(--transition-fast);
}

.session-item:hover {
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-primary);
}

.session-item.active {
  background: rgba(99, 102, 241, 0.12);
  border-color: rgba(99, 102, 241, 0.4);
  color: #c7d2fe;
}

.session-title {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}

.session-del-btn {
  opacity: 0;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 2px 6px;
  font-size: 0.75rem;
  transition: var(--transition-fast);
}

.session-item:hover .session-del-btn {
  opacity: 1;
}

.session-del-btn:hover {
  color: var(--accent-rose);
}

/* Sidebar Budget Bar */
.budget-meter-card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.progress-bar-bg {
  width: 100%;
  height: 6px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 4px;
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  background: var(--gradient-brand);
  width: 0%;
  transition: width 0.3s ease;
}

/* ==========================================================================
   CHAT VIEWPORT
   ========================================================================== */

.chat-viewport {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: transparent;
  position: relative;
  overflow: hidden;
}

.chat-subbar {
  padding: 10px 24px;
  border-bottom: 1px solid var(--border-subtle);
  background: rgba(15, 21, 35, 0.4);
  backdrop-filter: blur(10px);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.chat-context-info {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.persona-tag {
  background: rgba(6, 182, 212, 0.12);
  border: 1px solid rgba(6, 182, 212, 0.3);
  color: #67e8f9;
  padding: 3px 10px;
  border-radius: var(--radius-full);
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 6px;
}

.toggle-group {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.8rem;
  color: var(--text-secondary);
}

/* Switch */
.switch {
  position: relative;
  display: inline-block;
  width: 36px;
  height: 20px;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  top: 0; left: 0; right: 0; bottom: 0;
  background-color: #334155;
  transition: .3s;
  border-radius: 20px;
}

.slider:before {
  position: absolute;
  content: "";
  height: 14px;
  width: 14px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  transition: .3s;
  border-radius: 50%;
}

input:checked + .slider {
  background-color: var(--accent-indigo);
}

input:checked + .slider:before {
  transform: translateX(16px);
}

/* Messages Scroll Container */
.messages-container {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* Welcome Empty State */
.welcome-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  margin: auto;
  max-width: 650px;
  text-align: center;
  gap: 18px;
  padding: 40px 20px;
}

.welcome-icon-ring {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: var(--gradient-glow);
  border: 1px solid rgba(99, 102, 241, 0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-glow);
}

.welcome-title {
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--text-primary);
}

.welcome-subtitle {
  font-size: 0.92rem;
  color: var(--text-secondary);
  line-height: 1.5;
}

.starter-chips-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  width: 100%;
  margin-top: 10px;
}

.starter-chip {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  text-align: left;
  cursor: pointer;
  transition: var(--transition-normal);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.starter-chip:hover {
  border-color: var(--accent-indigo);
  transform: translateY(-2px);
  background: rgba(99, 102, 241, 0.1);
}

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

.starter-chip-desc {
  font-size: 0.74rem;
  color: var(--text-muted);
}

/* Chat Bubbles */
.message-row {
  display: flex;
  gap: 14px;
  max-width: 880px;
  width: 100%;
  margin: 0 auto;
}

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

.avatar-badge {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  flex-shrink: 0;
}

.avatar-badge.ai-avatar {
  background: var(--gradient-glow);
  border: 1px solid rgba(99, 102, 241, 0.4);
}

.avatar-badge.user-avatar {
  background: rgba(6, 182, 212, 0.2);
  border: 1px solid rgba(6, 182, 212, 0.4);
}

.message-card {
  padding: 14px 18px;
  border-radius: var(--radius-lg);
  line-height: 1.6;
  font-size: 0.92rem;
  position: relative;
  max-width: 82%;
  box-shadow: var(--shadow-sm);
}

.user-row .message-card {
  background: #1e293b;
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: var(--text-primary);
  border-bottom-right-radius: 4px;
}

.assistant-row .message-card {
  background: var(--bg-card);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border-subtle);
  color: #e2e8f0;
  border-bottom-left-radius: 4px;
}

.message-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 8px;
  padding-top: 6px;
  border-top: 1px solid rgba(255, 255, 255, 0.05);
  font-size: 0.72rem;
  color: var(--text-muted);
  gap: 12px;
}

.meta-stats {
  display: flex;
  align-items: center;
  gap: 10px;
}

.stat-tag {
  background: rgba(255, 255, 255, 0.04);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: var(--font-mono);
}

.btn-msg-action {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 4px;
  transition: var(--transition-fast);
}

.btn-msg-action:hover {
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.08);
}

/* Markdown styling inside assistant message */
.message-card pre {
  background: #0b0f19;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius-sm);
  padding: 12px;
  margin: 10px 0;
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: 0.82rem;
  color: #38bdf8;
  position: relative;
}

.message-card code {
  font-family: var(--font-mono);
  font-size: 0.84em;
  background: rgba(255, 255, 255, 0.08);
  padding: 2px 6px;
  border-radius: 4px;
  color: #38bdf8;
}

.message-card pre code {
  background: transparent;
  padding: 0;
  color: inherit;
}

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

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

.message-card p:last-child {
  margin-bottom: 0;
}

/* Typing / Loading indicator */
.typing-indicator {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
}

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

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

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

/* ==========================================================================
   INPUT BAR
   ========================================================================== */

.input-section {
  padding: 16px 24px;
  background: rgba(15, 21, 35, 0.85);
  backdrop-filter: blur(16px);
  border-top: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.input-box-wrapper {
  max-width: 880px;
  width: 100%;
  margin: 0 auto;
  position: relative;
  display: flex;
  align-items: flex-end;
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 8px 12px;
  transition: var(--transition-fast);
  box-shadow: var(--shadow-sm);
}

.input-box-wrapper:focus-within {
  border-color: var(--accent-indigo);
  box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.25);
}

.chat-textarea {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 0.92rem;
  resize: none;
  outline: none;
  max-height: 160px;
  min-height: 24px;
  line-height: 1.5;
  padding: 4px 6px;
}

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

.btn-send {
  background: var(--gradient-brand);
  border: none;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: var(--transition-normal);
  flex-shrink: 0;
  margin-left: 8px;
}

.btn-send:hover:not(:disabled) {
  transform: scale(1.05);
  box-shadow: 0 0 12px rgba(99, 102, 241, 0.5);
}

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

.input-hints {
  display: flex;
  justify-content: space-between;
  align-items: center;
  max-width: 880px;
  width: 100%;
  margin: 0 auto;
  font-size: 0.72rem;
  color: var(--text-muted);
}

/* ==========================================================================
   MODALS
   ========================================================================== */

.modal-backdrop {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(4, 7, 14, 0.75);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition-normal);
}

.modal-backdrop.open {
  opacity: 1;
  pointer-events: auto;
}

.modal-dialog {
  background: #111827;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  width: 90%;
  max-width: 580px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: var(--shadow-lg);
  transform: scale(0.96);
  transition: transform var(--transition-normal);
}

.modal-backdrop.open .modal-dialog {
  transform: scale(1);
}

.modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-primary);
}

.modal-body {
  padding: 20px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
  font-size: 0.88rem;
  color: var(--text-secondary);
}

.modal-footer {
  padding: 14px 20px;
  border-top: 1px solid var(--border-subtle);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--border-subtle);
  color: var(--text-primary);
  padding: 8px 16px;
  border-radius: var(--radius-md);
  font-size: 0.85rem;
  cursor: pointer;
  transition: var(--transition-fast);
}

.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.14);
}

.btn-primary {
  background: var(--gradient-brand);
  border: none;
  color: #fff;
  padding: 8px 18px;
  border-radius: var(--radius-md);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition-fast);
}

.btn-primary:hover {
  opacity: 0.92;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
  margin-top: 8px;
}

.data-table th, .data-table td {
  padding: 8px 10px;
  text-align: left;
  border-bottom: 1px solid var(--border-subtle);
}

.data-table th {
  color: var(--text-muted);
  font-weight: 600;
  text-transform: uppercase;
  font-size: 0.7rem;
}

.data-table td {
  font-family: var(--font-mono);
  color: var(--text-secondary);
}

/* Responsive adjustments */
@media (max-width: 900px) {
  .sidebar {
    position: fixed;
    top: 64px;
    bottom: 0;
    left: 0;
    transform: translateX(-100%);
    z-index: 50;
    box-shadow: 10px 0 30px rgba(0, 0, 0, 0.6);
    transition: transform var(--transition-normal);
  }
  
  .sidebar.open {
    transform: translateX(0);
  }
  
  .starter-chips-grid {
    grid-template-columns: 1fr;
  }
}
