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

:root {
  /* Brand Colors */
  --brand-primary: #00d2ff;
  --brand-secondary: #3a7bd5;
  --brand-purple: #8b5cf6;
  --brand-teal: #14b8a6;
  --brand-green: #10b981;
  --brand-warning: #f59e0b;
  --brand-danger: #ef4444;

  /* Backgrounds (Dark Mode) */
  --bg-base: #0b0f19;
  --bg-surface: rgba(23, 29, 45, 0.7);
  /* Glass effect */
  --bg-surface-hover: rgba(35, 45, 65, 0.8);
  --bg-surface-active: rgba(45, 60, 85, 0.9);
  --bg-sidebar: #111827;
  --bg-panel: #1e293b;

  /* Text */
  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --text-inverse: #020617;

  /* Borders */
  --border-color: rgba(255, 255, 255, 0.1);
  --border-focus: var(--brand-primary);

  /* Shadow / Blur */
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.3), 0 4px 6px -2px rgba(0, 0, 0, 0.15);
  --glow-primary: 0 0 15px rgba(0, 210, 255, 0.3);
  --blur-strength: blur(16px);

  /* Typography */
  --font-heading: 'Inter', system-ui, sans-serif;
  --font-body: 'Inter', system-ui, sans-serif;
  --font-mono: 'Fira Code', monospace;

  /* Layout Spacing */
  --header-height: 70px;
  --sidebar-width: 280px;
  --right-panel-width: 350px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-full: 9999px;
}

/* Base Reset & Typography */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  background-color: var(--bg-base);
  background-image:
    radial-gradient(circle at 15% 50%, rgba(139, 92, 246, 0.08), transparent 25%),
    radial-gradient(circle at 85% 30%, rgba(0, 210, 255, 0.08), transparent 25%);
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.6;
  overflow: hidden;
  /* App container handles scrolling */
}

h1,
h2,
h3,
h4,
h5 {
  font-family: var(--font-heading);
  font-weight: 600;
  line-height: 1.2;
  color: var(--text-primary);
}

a {
  color: var(--brand-primary);
  text-decoration: none;
  transition: color 0.2s ease;
}

a:hover {
  color: #fff;
}

/* App Layout Grid */
.app-layout {
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr var(--right-panel-width);
  grid-template-rows: 100dvh;
  height: 100dvh;
  width: 100vw;
}

/* Utility: Glassmorphism Panel */
.glass-panel {
  background: var(--bg-surface);
  backdrop-filter: var(--blur-strength);
  -webkit-backdrop-filter: var(--blur-strength);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-lg);
}

/* --- Left Sidebar --- */
.left-sidebar {
  background-color: var(--bg-sidebar);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  padding: 24px 16px;
  overflow-y: auto;
  z-index: 10;
}

.brand-logo {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 1.25rem;
  font-weight: 700;
  background: linear-gradient(135deg, var(--brand-primary), var(--brand-purple));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  margin-bottom: 32px;
  padding: 0 8px;
}

.brand-logo svg {
  width: 28px;
  height: 28px;
  fill: url(#gradient);
}

.sidebar-nav-section {
  margin-bottom: 32px;
}

.sidebar-label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 12px;
  padding: 0 8px;
  font-weight: 600;
}

.nav-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  font-weight: 500;
  transition: all 0.2s ease;
  margin-bottom: 4px;
  cursor: pointer;
}

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

.nav-item.active {
  background: rgba(0, 210, 255, 0.1);
  color: var(--brand-primary);
  border-left: 3px solid var(--brand-primary);
}

.nav-item .icon {
  width: 20px;
  height: 20px;
  margin-right: 12px;
  opacity: 0.7;
}

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

.nav-item .badge {
  font-size: 0.7rem;
  padding: 2px 6px;
  border-radius: var(--radius-full);
  background: var(--bg-panel);
  color: var(--text-muted);
}

.nav-item.active .badge {
  background: var(--brand-primary);
  color: var(--bg-base);
}

/* Setup Progress Bar in Sidebar */
.nav-progress {
  margin-top: 24px;
  padding: 16px;
  background: var(--bg-surface);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
}

.progress-header {
  display: flex;
  justify-content: space-between;
  font-size: 0.85rem;
  margin-bottom: 8px;
  color: var(--text-secondary);
}

.progress-track {
  height: 6px;
  background: var(--bg-panel);
  border-radius: var(--radius-full);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--brand-primary), var(--brand-teal));
  border-radius: var(--radius-full);
  width: 0%;
  transition: width 0.5s ease;
  box-shadow: var(--glow-primary);
}


/* --- Center Content Area --- */
.center-area {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  position: relative;
  overflow: hidden;
  /* Handled by inner scroll containers */
}

/* Top Navigation Bar */
.top-nav {
  height: var(--header-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 40px;
  border-bottom: 1px solid var(--border-color);
  background: rgba(11, 15, 25, 0.6);
  backdrop-filter: var(--blur-strength);
  -webkit-backdrop-filter: var(--blur-strength);
  z-index: 20;
}

.search-bar {
  display: flex;
  align-items: center;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-full);
  padding: 8px 16px;
  width: 300px;
  transition: all 0.2s ease;
}

.search-bar:focus-within {
  border-color: var(--brand-primary);
  box-shadow: 0 0 0 2px rgba(0, 210, 255, 0.2);
}

.search-bar input {
  background: transparent;
  border: none;
  outline: none;
  color: var(--text-primary);
  width: 100%;
  margin-left: 8px;
  font-family: var(--font-body);
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 16px;
}

.icon-btn {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 8px;
  border-radius: var(--radius-full);
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

.icon-btn:hover {
  background: var(--bg-surface-hover);
  color: var(--text-primary);
}


/* Main Scrolling Content */
.content-scrollable {
  flex: 1;
  overflow-y: auto;
  padding: 40px;
  scroll-behavior: smooth;
  padding-bottom: 300px;
  /* Space for the terminal */
}

/* Dashboard Specifics */
.hero-section {
  margin-bottom: 48px;
}

.hero-title {
  font-size: 2.5rem;
  margin-bottom: 16px;
  background: linear-gradient(to right, #fff, var(--text-secondary));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.hero-subtitle {
  font-size: 1.1rem;
  color: var(--text-secondary);
  max-width: 600px;
}

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

.module-card {
  border-radius: var(--radius-lg);
  padding: 24px;
  display: flex;
  flex-direction: column;
  transition: all 0.3s ease;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}

.module-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 4px;
  background: var(--bg-panel);
  transition: all 0.3s ease;
}

.module-card:hover {
  transform: translateY(-4px);
  border-color: rgba(255, 255, 255, 0.2);
}

.module-card:hover::before {
  background: linear-gradient(90deg, var(--brand-primary), var(--brand-purple));
}

.mc-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 16px;
}

.mc-subtitle {
  font-size: 0.8rem;
  color: var(--brand-primary);
  text-transform: uppercase;
  font-weight: 600;
  letter-spacing: 0.05em;
  margin-bottom: 4px;
}

.mc-title {
  font-size: 1.25rem;
  margin-bottom: 8px;
}

.mc-desc {
  color: var(--text-secondary);
  font-size: 0.95rem;
  margin-bottom: 24px;
  flex: 1;
}

.mc-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-top: 16px;
  border-top: 1px solid var(--border-color);
}

/* Module Lesson Content Styling */
.lesson-header {
  margin-bottom: 40px;
}

.lesson-meta {
  display: flex;
  gap: 16px;
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-bottom: 16px;
  font-weight: 500;
}

.lesson-meta span {
  display: flex;
  align-items: center;
  gap: 6px;
}

.content-block {
  background: transparent;
  margin-bottom: 40px;
}

.content-block h2 {
  font-size: 1.5rem;
  margin-bottom: 16px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border-color);
  color: #fff;
}

.content-block h3 {
  font-size: 1.2rem;
  margin-top: 24px;
  margin-bottom: 12px;
  color: #e2e8f0;
}

.content-block p {
  margin-bottom: 16px;
  font-size: 1.05rem;
  color: var(--text-secondary);
}

.content-block ul {
  margin-bottom: 16px;
  padding-left: 24px;
  color: var(--text-secondary);
}

.content-block li {
  margin-bottom: 8px;
}

/* Code Snippets */
.code-window {
  background: #0f172a;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  margin: 24px 0;
  overflow: hidden;
}

.code-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  background: rgba(255, 255, 255, 0.05);
  border-bottom: 1px solid var(--border-color);
}

.window-controls {
  display: flex;
  gap: 6px;
}

.wc-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
}

.wc-red {
  background: #ef4444;
}

.wc-yellow {
  background: #f59e0b;
}

.wc-green {
  background: #10b981;
}

.code-lang {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-family: var(--font-mono);
}

.code-window pre {
  padding: 16px;
  margin: 0;
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: 0.9rem;
  color: #cbd5e1;
  line-height: 1.5;
}

.inline-code {
  background: rgba(255, 255, 255, 0.1);
  color: var(--brand-primary);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 0.9em;
}

/* Checkbox Tasks (Labs) */
.task-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin: 24px 0;
}

.task-item {
  display: flex;
  align-items: flex-start;
  gap: 16px;
  padding: 16px;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  transition: all 0.2s ease;
}

.task-item:hover {
  border-color: rgba(255, 255, 255, 0.2);
}

.task-item.completed {
  border-color: var(--brand-green);
  background: rgba(16, 185, 129, 0.05);
}

.task-checkbox {
  width: 24px;
  height: 24px;
  border-radius: 6px;
  border: 2px solid var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: all 0.2s ease;
}

.task-item.completed .task-checkbox {
  background: var(--brand-green);
  border-color: var(--brand-green);
}

.task-checkbox svg {
  width: 14px;
  height: 14px;
  fill: none;
  stroke: white;
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
  opacity: 0;
  transform: scale(0.5);
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.task-item.completed .task-checkbox svg {
  opacity: 1;
  transform: scale(1);
}

.task-content {
  flex: 1;
}

.task-title {
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 4px;
}

.task-desc {
  color: var(--text-secondary);
  font-size: 0.9rem;
  margin-bottom: 12px;
}

.task-item.completed .task-title {
  color: var(--brand-green);
  text-decoration: line-through;
  opacity: 0.8;
}

/* Built-in Terminal Area */
.terminal-dock {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 250px;
  background: #0f172a;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  display: flex;
  flex-direction: column;
  z-index: 30;
  transition: height 0.3s ease;
}

.terminal-dock.expanded {
  height: 60vh;
}

.terminal-dock.minimized {
  height: 40px;
}

.terminal-header {
  height: 40px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 16px;
  background: #1e293b;
  border-bottom: 1px solid #334155;
  cursor: pointer;
  user-select: none;
}

.term-title {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  color: #94a3b8;
  display: flex;
  align-items: center;
  gap: 8px;
}

.terminal-body {
  flex: 1;
  padding: 16px;
  overflow-y: auto;
  font-family: var(--font-mono);
  font-size: 0.9rem;
  color: #e2e8f0;
}

.term-prompt {
  color: var(--brand-green);
  margin-right: 8px;
}

.term-input-line {
  display: flex;
  align-items: center;
  margin-top: 8px;
}

.term-input {
  background: transparent;
  border: none;
  color: #fff;
  font-family: var(--font-mono);
  font-size: 0.9rem;
  outline: none;
  flex: 1;
}

.term-output {
  color: #94a3b8;
  margin-bottom: 8px;
  white-space: pre-wrap;
}

.term-output.error {
  color: var(--brand-danger);
}

.term-output.success {
  color: var(--brand-primary);
}


/* --- Right Panel (AI Tutor Chat) --- */
.right-panel {
  border-left: 1px solid var(--border-color);
  background: var(--bg-sidebar);
  display: flex;
  flex-direction: column;
  z-index: 10;
}

.chat-header {
  height: var(--header-height);
  display: flex;
  align-items: center;
  padding: 0 20px;
  border-bottom: 1px solid var(--border-color);
  background: rgba(11, 15, 25, 0.6);
}

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

.tutor-avatar {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, var(--brand-purple), var(--brand-primary));
  display: flex;
  align-items: center;
  justify-content: center;
  filter: drop-shadow(0 0 8px rgba(139, 92, 246, 0.5));
}

.tutor-avatar svg {
  width: 20px;
  height: 20px;
  fill: white;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.message {
  max-width: 85%;
  padding: 12px 16px;
  border-radius: var(--radius-lg);
  font-size: 0.95rem;
  line-height: 1.5;
  animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.msg-ai {
  align-self: flex-start;
  background: var(--bg-surface);
  border: 1px solid rgba(255, 255, 255, 0.05);
  color: var(--text-primary);
  border-top-left-radius: 4px;
}

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

.chat-input-area {
  padding: 20px;
  padding-bottom: max(20px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--border-color);
  background: var(--bg-sidebar);
  margin-top: auto;
  /* Force to bottom */
}

.chat-config {
  margin-bottom: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.chat-config input,
.chat-config select {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 0.8rem;
  outline: none;
  font-family: inherit;
}

.chat-config input:focus,
.chat-config select:focus {
  border-color: var(--brand-purple);
}

.input-wrapper {
  display: flex;
  align-items: flex-end;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 8px;
  transition: border-color 0.2s ease;
}

.input-wrapper:focus-within {
  border-color: var(--brand-purple);
  box-shadow: 0 0 0 2px rgba(139, 92, 246, 0.2);
}

.chat-textarea {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text-primary);
  resize: none;
  max-height: 120px;
  padding: 8px;
  font-family: var(--font-body);
  font-size: 0.95rem;
  outline: none;
  overflow-y: auto;
}

.chat-send-btn {
  background: var(--brand-purple);
  color: white;
  border: none;
  border-radius: var(--radius-md);
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
  flex-shrink: 0;
}

.chat-send-btn:hover {
  background: #7c3aed;
  transform: scale(1.05);
}

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


/* --- Buttons & Inputs --- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 20px;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  border-radius: var(--radius-md);
  font-weight: 500;
  font-size: 0.95rem;
  cursor: pointer;
  transition: all 0.2s ease;
  font-family: var(--font-body);
}

.btn:hover {
  background: var(--bg-surface-hover);
  border-color: rgba(255, 255, 255, 0.2);
}

.btn-primary {
  background: linear-gradient(135deg, var(--brand-primary), var(--brand-secondary));
  border: none;
  color: white;
  box-shadow: 0 4px 12px rgba(0, 210, 255, 0.3);
}

.btn-primary:hover {
  background: linear-gradient(135deg, #0ce1ff, #478dec);
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(0, 210, 255, 0.4);
}

.btn-sm {
  padding: 6px 12px;
  font-size: 0.85rem;
  border-radius: 6px;
}

/* Scrollbars */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

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

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

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

/* Specific Modals (Search, Shortcuts) overlay the whole grid */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.8);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 1000;
  display: none;
  align-items: center;
  justify-content: center;
}

.modal-content {
  background: var(--bg-panel);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: var(--radius-lg);
  width: 90%;
  max-width: 600px;
  padding: 32px;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
  animation: modalSlideIn 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes modalSlideIn {
  from {
    opacity: 0;
    transform: scale(0.95) translateY(20px);
  }

  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

.search-input-large {
  width: 100%;
  background: var(--bg-surface);
  border: 2px solid var(--border-color);
  padding: 16px 24px;
  border-radius: var(--radius-md);
  color: white;
  font-size: 1.2rem;
  outline: none;
  transition: border-color 0.2s;
  font-family: inherit;
}

.search-input-large:focus {
  border-color: var(--brand-primary);
}

/* --- Mobile Responsiveness --- */
.mobile-toggle-btn {
  display: none;
  background: transparent;
  border: none;
  color: var(--text-primary);
  font-size: 1.5rem;
  cursor: pointer;
  padding: 8px;
  border-radius: var(--radius-md);
  transition: background 0.2s ease;
}

.mobile-toggle-btn:hover {
  background: var(--bg-surface-hover);
}

.mobile-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100dvh;
  background: rgba(0, 0, 0, 0.7);
  z-index: 40;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.mobile-overlay.active {
  display: block;
  opacity: 1;
}

@media (max-width: 992px) {
  :root {
    --blur-strength: none;
  }

  * {
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
  }

  .app-layout {
    display: block;
  }

  .left-sidebar {
    position: fixed;
    left: 0;
    top: 0;
    height: 100dvh;
    width: 280px;
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    z-index: 50;
    background: rgba(17, 24, 39, 0.95);
  }

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

  .right-panel {
    position: fixed;
    right: 0;
    top: 0;
    height: 100dvh;
    width: 350px;
    transform: translateX(100%);
    transition: transform 0.3s ease;
    z-index: 50;
    background: rgba(17, 24, 39, 0.95);
  }

  .right-panel.ai-open {
    transform: translateX(0);
  }

  .mobile-toggle-btn {
    display: flex;
    align-items: center;
    justify-content: center;
  }

  button.mobile-toggle-btn {
    display: flex !important;
    /* Force override inline display:none on mobile */
  }

  .top-nav {
    padding: 0 16px;
  }

  .search-bar {
    width: 200px;
  }
}

@media (max-width: 600px) {
  .search-bar {
    width: 140px;
  }

  .hero-title {
    font-size: 1.8rem;
  }

  .content-scrollable {
    padding: 20px;
    padding-bottom: 250px;
  }

  .dashboard-grid {
    grid-template-columns: 1fr;
  }

  .right-panel {
    width: 100%;
  }
}