/* ========================================
   MAIN.CSS — Design System & Dark Theme
   ======================================== */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&display=swap');

/* ── CSS Variables ── */
:root {
  /* Backgrounds */
  --bg-primary: #07070d;
  --bg-secondary: #0e0e18;
  --bg-card: #151524;
  --bg-card-hover: #1c1c32;
  --bg-elevated: #1e1e35;
  --bg-input: #12121f;
  --bg-sidebar: #0a0a14;

  /* Accent Colors */
  --accent-primary: #7c6cf0;
  --accent-primary-rgb: 124, 108, 240;
  --accent-secondary: #a89afa;
  --accent-green: #2dd4a8;
  --accent-green-rgb: 45, 212, 168;
  --accent-red: #f06c6c;
  --accent-red-rgb: 240, 108, 108;
  --accent-yellow: #f0c850;
  --accent-yellow-rgb: 240, 200, 80;
  --accent-blue: #6cb4f0;
  --accent-blue-rgb: 108, 180, 240;
  --accent-orange: #f0a06c;
  --accent-cyan: #50d4e8;
  --accent-pink: #e87cbc;

  /* Gradients */
  --gradient-primary: linear-gradient(135deg, #7c6cf0 0%, #a89afa 100%);
  --gradient-green: linear-gradient(135deg, #2dd4a8 0%, #50e8c8 100%);
  --gradient-red: linear-gradient(135deg, #f06c6c 0%, #f0a0a0 100%);
  --gradient-blue: linear-gradient(135deg, #6cb4f0 0%, #a0d0ff 100%);
  --gradient-hero: linear-gradient(135deg, rgba(124,108,240,0.15) 0%, rgba(45,212,168,0.08) 100%);
  --gradient-card: linear-gradient(145deg, rgba(255,255,255,0.03) 0%, rgba(255,255,255,0) 100%);

  /* Text */
  --text-primary: #eaeaf4;
  --text-secondary: #8585a8;
  --text-muted: #5a5a78;
  --text-inverse: #07070d;

  /* Borders & Glass */
  --border-color: rgba(255, 255, 255, 0.06);
  --border-light: rgba(255, 255, 255, 0.1);
  --glass-bg: rgba(255, 255, 255, 0.03);
  --glass-bg-strong: rgba(255, 255, 255, 0.06);

  /* Shadows */
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.2);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.4);
  --shadow-glow: 0 0 20px rgba(124, 108, 240, 0.15);
  --shadow-glow-green: 0 0 20px rgba(45, 212, 168, 0.15);

  /* Sizing */
  --sidebar-width: 260px;
  --header-height: 0px;
  --radius-xs: 6px;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  --radius-full: 9999px;

  /* Transitions */
  --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-base: 250ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-slow: 400ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-bounce: 500ms cubic-bezier(0.34, 1.56, 0.64, 1);

  /* Z-Index */
  --z-dropdown: 100;
  --z-sticky: 200;
  --z-modal-backdrop: 900;
  --z-modal: 1000;
  --z-toast: 1100;
}

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

html {
  font-size: 15px;
  scroll-behavior: smooth;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
  overflow-x: hidden;
}

a {
  color: var(--accent-primary);
  text-decoration: none;
}

img {
  max-width: 100%;
  display: block;
}

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

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

::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: var(--radius-full);
}

::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.18);
}

/* ── Layout ── */
.app-layout {
  display: flex;
  min-height: 100vh;
}

/* ── Sidebar ── */
.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: var(--z-sticky);
  transition: transform var(--transition-base);
}

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

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

.sidebar-logo-icon {
  width: 42px;
  height: 42px;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, #7c6cf0 0%, #50d4e8 50%, #2dd4a8 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  box-shadow: 0 0 24px rgba(124, 108, 240, 0.3), 0 0 8px rgba(45, 212, 168, 0.2);
  position: relative;
  overflow: hidden;
  animation: logoShine 3s ease-in-out infinite;
}

.sidebar-logo-icon::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, transparent 40%, rgba(255,255,255,0.25) 50%, transparent 60%);
  animation: logoGlint 3s ease-in-out infinite;
}

@keyframes logoShine {
  0%, 100% { box-shadow: 0 0 24px rgba(124, 108, 240, 0.3), 0 0 8px rgba(45, 212, 168, 0.2); }
  50% { box-shadow: 0 0 32px rgba(124, 108, 240, 0.45), 0 0 16px rgba(45, 212, 168, 0.3); }
}

@keyframes logoGlint {
  0%, 100% { transform: translateX(-100%); }
  50% { transform: translateX(100%); }
}

.sidebar-logo-text {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.sidebar-logo-title {
  font-size: 1.05rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  background: linear-gradient(135deg, #a89afa 0%, #50d4e8 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  line-height: 1.2;
}

.sidebar-logo-subtitle {
  font-size: 0.62rem;
  font-weight: 500;
  color: var(--text-muted);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  line-height: 1;
}

.sidebar-nav {
  flex: 1;
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  overflow-y: auto;
}

.sidebar-nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition-fast);
  user-select: none;
  position: relative;
  overflow: hidden;
}

.sidebar-nav-item::before {
  content: '';
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%) scaleY(0);
  width: 3px;
  height: 60%;
  border-radius: 0 3px 3px 0;
  background: var(--accent-primary);
  transition: transform var(--transition-base);
}

.sidebar-nav-item:hover {
  color: var(--text-primary);
  background: var(--glass-bg);
}

.sidebar-nav-item.active {
  color: var(--text-primary);
  background: rgba(var(--accent-primary-rgb), 0.1);
}

.sidebar-nav-item.active::before {
  transform: translateY(-50%) scaleY(1);
}

.sidebar-nav-item .nav-icon {
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  opacity: 0.65;
  transition: opacity var(--transition-fast);
}

.sidebar-nav-item:hover .nav-icon,
.sidebar-nav-item.active .nav-icon {
  opacity: 1;
}

.sidebar-nav-item .nav-badge {
  margin-left: auto;
  background: rgba(var(--accent-primary-rgb), 0.2);
  color: var(--accent-secondary);
  font-size: 0.7rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: var(--radius-full);
}

.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--border-color);
  display: flex;
  justify-content: center;
}

.sidebar-version {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.72rem;
  color: var(--text-muted);
  font-weight: 500;
}

.sidebar-version-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent-green);
  box-shadow: 0 0 6px rgba(var(--accent-green-rgb), 0.5);
}

/* ── Main Content ── */
.main-content {
  flex: 1;
  margin-left: var(--sidebar-width);
  min-height: 100vh;
  min-width: 0;
  padding: 28px 32px;
  overflow-x: hidden;
}

/* ── Tab Pages ── */
.tab-page {
  display: none;
  animation: fadeSlideIn 0.35s ease;
}

.tab-page.active {
  display: block;
}

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

/* ── Page Headers ── */
.page-header {
  margin-bottom: 28px;
}

.page-title {
  font-size: 1.65rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  margin-bottom: 4px;
}

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

/* ── Grid System ── */
.grid {
  display: grid;
  gap: 16px;
}

.grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }

.grid-auto {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}

/* ── Flex Helpers ── */
.flex { display: flex; }
.flex-col { flex-direction: column; }
.flex-wrap { flex-wrap: wrap; }
.items-center { align-items: center; }
.items-start { align-items: flex-start; }
.items-end { align-items: flex-end; }
.justify-between { justify-content: space-between; }
.justify-center { justify-content: center; }
.justify-end { justify-content: flex-end; }
.gap-4 { gap: 4px; }

/* ── Markdown Content ── */
.md-content {
  line-height: 1.5;
  white-space: normal;
  word-wrap: break-word;
}
.md-content strong {
  font-weight: 600;
  color: var(--text-primary);
}
.md-content em {
  font-style: italic;
  color: var(--text-primary);
}
.md-content del {
  text-decoration: line-through;
  opacity: 0.6;
}
.md-content .md-code {
  background: rgba(255, 255, 255, 0.1);
  padding: 2px 5px;
  border-radius: 4px;
  font-family: monospace;
  font-size: 0.85em;
  color: var(--accent-red);
}
.md-content .md-link {
  color: var(--accent-primary);
  text-decoration: none;
}
.md-content .md-link:hover {
  text-decoration: underline;
}

/* ── Markdown Editor (Textarea wrap) ── */
.md-editor-wrapper {
  position: relative;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  overflow: hidden;
  transition: all var(--transition-fast);
}

.md-editor-wrapper:focus-within {
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px rgba(var(--accent-primary-rgb), 0.15);
}

.md-editor-toolbar {
  display: flex;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border-color);
  padding: 4px;
  gap: 4px;
}

.md-editor-btn {
  background: transparent;
  color: var(--text-secondary);
  border: none;
  border-radius: 4px;
  min-width: 28px;
  height: 24px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition-fast);
}

.md-editor-btn:hover {
  background: var(--glass-bg-strong);
  color: var(--text-primary);
}

.md-editor-btn svg, .md-editor-btn .md-icon {
  width: 16px;
  height: 16px;
}

.md-editor-preview {
  padding: 12px;
  min-height: 80px;
  background: var(--bg-input);
  color: var(--text-primary);
  border-top: 1px solid var(--border-color);
}

/* ── Voice Assistant Floating Button ── */
.voice-btn-wrapper {
  position: fixed;
  bottom: 30px;
  right: 30px;
  width: 60px;
  height: 60px;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-voice-float {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent-primary), var(--accent-primary-hover));
  color: white;
  border: none;
  box-shadow: 0 8px 24px rgba(var(--accent-primary-rgb), 0.4);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  transition: all 0.3s ease;
}

.btn-voice-float:hover {
  transform: scale(1.05);
  box-shadow: 0 12px 30px rgba(var(--accent-primary-rgb), 0.6);
}

.btn-voice-float svg {
  transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.voice-ring {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  border-radius: 50%;
  border: 2px solid var(--accent-primary);
  opacity: 0;
  pointer-events: none;
}

/* Listening Mode Animations */
.voice-btn-wrapper.listening .btn-voice-float {
  background: linear-gradient(135deg, #ef4444, #dc2626); /* Red logic for listening */
  box-shadow: 0 8px 24px rgba(239, 68, 68, 0.5);
  animation: pulse-voice 2s infinite;
}

.voice-btn-wrapper.listening .btn-voice-float svg {
  transform: scale(1.1);
}

@keyframes pulse-voice {
  0% { transform: scale(1); box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.7); }
  50% { transform: scale(1.05); box-shadow: 0 0 0 15px rgba(239, 68, 68, 0); }
  100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(239, 68, 68, 0); }
}

.voice-btn-wrapper.listening .ring-1 {
  animation: voice-ripple 1.5s infinite linear;
}
.voice-btn-wrapper.listening .ring-2 {
  animation: voice-ripple 1.5s infinite linear 0.75s;
}

@keyframes voice-ripple {
  0% { transform: scale(1); opacity: 0.8; }
  100% { transform: scale(1.8); opacity: 0; }
}

/* Processing Spinner */
.voice-spinner {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background: rgba(0,0,0,0.6);
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
}

.voice-btn-wrapper.processing .voice-spinner {
  opacity: 1;
}

.voice-btn-wrapper.processing .btn-voice-float svg {
  opacity: 0;
}

.md-editor-wrapper .form-textarea {
  border: none !important;
  background: transparent !important;
  box-shadow: none !important;
  border-radius: 0;
  min-height: 80px;
}

.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.gap-16 { gap: 16px; }
.gap-20 { gap: 20px; }
.gap-24 { gap: 24px; }

/* ── Text Helpers ── */
.text-sm { font-size: 0.8rem; }
.text-base { font-size: 0.93rem; }
.text-lg { font-size: 1.1rem; }
.text-xl { font-size: 1.3rem; }
.text-2xl { font-size: 1.6rem; }
.text-muted { color: var(--text-secondary); }
.text-green { color: var(--accent-green); }
.text-red { color: var(--accent-red); }
.text-yellow { color: var(--accent-yellow); }
.text-blue { color: var(--accent-blue); }
.text-purple { color: var(--accent-primary); }
.font-medium { font-weight: 500; }
.font-semibold { font-weight: 600; }
.font-bold { font-weight: 700; }
.truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── Spacing ── */
.mt-4 { margin-top: 4px; }
.mt-8 { margin-top: 8px; }
.mt-12 { margin-top: 12px; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }
.mb-8 { margin-bottom: 8px; }
.mb-12 { margin-bottom: 12px; }
.mb-16 { margin-bottom: 16px; }
.mb-24 { margin-bottom: 24px; }

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

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

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

@keyframes scaleIn {
  from { opacity: 0; transform: scale(0.9); }
  to { opacity: 1; transform: scale(1); }
}

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

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

@keyframes shimmer {
  0% { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}

.animate-fade { animation: fadeIn var(--transition-base); }
.animate-slide-up { animation: slideUp var(--transition-slow); }
.animate-scale { animation: scaleIn var(--transition-base); }
.animate-pulse { animation: pulse 2s infinite; }

/* ── Responsive ── */
@media (max-width: 1024px) {
  .sidebar {
    transform: translateX(-100%);
  }
  .sidebar.open {
    transform: translateX(0);
  }
  .main-content {
    margin-left: 0;
    padding: 20px 16px;
  }
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
  .grid-3 { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 640px) {
  .grid-2, .grid-3, .grid-4 {
    grid-template-columns: 1fr;
  }
  .main-content {
    padding: 16px 12px;
  }
}
