/* Socratic Math Tutor (Grades 5 & 6) CSS Stylesheet */

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

:root {
  /* Colors - Sleek Violet & Indigo Tech Palette */
  --primary-color: #6366f1;
  --primary-hover: #4f46e5;
  --secondary-color: #8b5cf6;
  --accent-color: #ec4899; /* Pink Accent */
  
  --bg-gradient: linear-gradient(135deg, #0f172a 0%, #1e1b4b 100%); /* Premium Dark */
  --panel-bg: rgba(30, 27, 75, 0.45);
  --panel-border: rgba(255, 255, 255, 0.08);
  
  --text-primary: #f8fafc;
  --text-secondary: #cbd5e1;
  --text-muted: #64748b;
  
  --whiteboard-bg: #ffffff;
  
  /* Borders & Shadows */
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --shadow-lg: 0 10px 30px -10px rgba(0, 0, 0, 0.5), 0 1px 1px 0 rgba(255, 255, 255, 0.05) inset;
  --shadow-glow: 0 0 20px rgba(99, 102, 241, 0.15);
}

[data-theme="light"] {
  --bg-gradient: linear-gradient(135deg, #e0e7ff 0%, #f3e8ff 100%);
  --panel-bg: rgba(255, 255, 255, 0.7);
  --panel-border: rgba(99, 102, 241, 0.15);
  
  --text-primary: #1e1b4b;
  --text-secondary: #475569;
  --text-muted: #64748b;
  
  --whiteboard-bg: #f8fafc;
  --shadow-glow: 0 4px 20px rgba(99, 102, 241, 0.08);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  transition: background-color 0.3s ease, border-color 0.3s ease, color 0.2s ease;
}

body {
  font-family: 'Outfit', 'Noto Sans SC', sans-serif;
  background: var(--bg-gradient);
  color: var(--text-primary);
  min-height: 100vh;
  height: 100vh;
  overflow: hidden;
  padding: 16px;
  display: flex;
  flex-direction: column;
}

/* Header Config */
header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 24px;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  backdrop-filter: blur(20px);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  margin-bottom: 16px;
}

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

.logo-icon {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  background: linear-gradient(135deg, var(--primary-color) 0%, var(--secondary-color) 100%);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  font-weight: 700;
}

.logo-section h1 {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.5px;
  background: linear-gradient(90deg, #818cf8 0%, #c084fc 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

/* Controls row (Selectors) */
.tutor-selectors {
  display: flex;
  gap: 12px;
  align-items: center;
}

select {
  background: rgba(0, 0, 0, 0.2);
  border: 1px solid var(--panel-border);
  color: var(--text-primary);
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 600;
  outline: none;
  cursor: pointer;
}

[data-theme="light"] select {
  background: rgba(255, 255, 255, 0.8);
}

select:focus {
  border-color: var(--primary-color);
  box-shadow: var(--shadow-glow);
}

.btn-pill {
  border: none;
  background: linear-gradient(135deg, var(--primary-color) 0%, var(--secondary-color) 100%);
  color: white;
  padding: 8px 16px;
  border-radius: 99px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 4px 10px rgba(99, 102, 241, 0.2);
}

.btn-pill:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 14px rgba(99, 102, 241, 0.3);
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--panel-border);
  color: var(--text-primary);
}

[data-theme="light"] .btn-secondary {
  background: rgba(0, 0, 0, 0.05);
}

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

/* Layout Grid */
.main-workspace {
  display: grid;
  grid-template-columns: 50% 50%;
  gap: 16px;
  flex: 1;
  min-height: 0; /* important for inner scroll */
  height: calc(100vh - 100px);
}

/* Left Column - Math Whiteboard */
.whiteboard-panel {
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  backdrop-filter: blur(20px);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  height: 100%;
}

.whiteboard-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: rgba(0, 0, 0, 0.15);
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  gap: 8px;
}

[data-theme="light"] .whiteboard-toolbar {
  background: rgba(255, 255, 255, 0.6);
}

.toolbar-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.color-option {
  width: 20px;
  height: 20px;
  border-radius: 99px;
  cursor: pointer;
  border: 2px solid transparent;
  transition: transform 0.15s ease;
}

.color-option.active {
  border-color: var(--text-primary);
  transform: scale(1.15);
}

.color-black { background: #1e293b; }
.color-red { background: #ef4444; }
.color-blue { background: #3b82f6; }
.color-green { background: #10b981; }

.canvas-container {
  flex: 1;
  background: var(--whiteboard-bg);
  border-radius: var(--radius-md);
  border: 1px solid rgba(0, 0, 0, 0.05);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.03) inset;
  position: relative;
  overflow: hidden;
  min-height: 0;
}

canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  cursor: crosshair;
}

/* Right Column - Socratic Dialogue */
.chat-panel {
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  backdrop-filter: blur(20px);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  height: 100%;
  position: relative;
}

.chat-header {
  padding: 16px 20px;
  background: rgba(0, 0, 0, 0.1);
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
  display: flex;
  align-items: center;
  gap: 12px;
}

.chat-avatar-large {
  width: 44px;
  height: 44px;
  border-radius: 99px;
  background: linear-gradient(135deg, var(--primary-color) 0%, var(--secondary-color) 100%);
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 24px;
  box-shadow: var(--shadow-glow);
}

.tutor-info h2 {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-primary);
}

.tutor-info p {
  font-size: 11px;
  color: var(--text-muted);
}

/* Chat bubble stream */
.chat-history {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* Custom Scrollbar for Chat Room */
.chat-history::-webkit-scrollbar {
  width: 6px;
}
.chat-history::-webkit-scrollbar-track {
  background: transparent;
}
.chat-history::-webkit-scrollbar-thumb {
  background: rgba(99, 102, 241, 0.25);
  border-radius: 99px;
}
.chat-history::-webkit-scrollbar-thumb:hover {
  background: rgba(99, 102, 241, 0.45);
}

/* KaTeX custom style overrides */
.katex-display {
  margin: 8px 0 !important;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 4px 0;
}
.katex {
  font-size: 1.05em;
  text-rendering: auto;
}

.bubble {
  display: flex;
  gap: 12px;
  max-width: 85%;
  align-items: flex-start;
  animation: slide-up 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

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

.bubble-ai { align-self: flex-start; }
.bubble-student { align-self: flex-end; flex-direction: row-reverse; }

.avatar {
  width: 34px;
  height: 34px;
  border-radius: 99px;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 14px;
  font-weight: 700;
  color: white;
  flex-shrink: 0;
}

.avatar-ai {
  background: linear-gradient(135deg, var(--primary-color) 0%, var(--secondary-color) 100%);
}

.avatar-student {
  background: linear-gradient(135deg, #0284c7 0%, #0369a1 100%);
}

.bubble-content {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.bubble-sender {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-muted);
}

.bubble-student .bubble-sender { text-align: right; }

.bubble-text {
  padding: 12px 16px;
  border-radius: var(--radius-md);
  font-size: 14px;
  line-height: 1.5;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.bubble-ai .bubble-text {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.04);
  color: var(--text-primary);
  border-top-left-radius: 2px;
}

[data-theme="light"] .bubble-ai .bubble-text {
  background: #ffffff;
  border-color: rgba(99, 102, 241, 0.1);
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.04);
}

.bubble-student .bubble-text {
  background: var(--primary-color);
  color: white;
  border-top-right-radius: 2px;
}

/* Chat Input and Pills */
.chat-input-bar {
  padding: 16px 20px;
  background: rgba(0, 0, 0, 0.15);
  border-top: 1px solid rgba(255, 255, 255, 0.04);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

[data-theme="light"] .chat-input-bar {
  background: rgba(255, 255, 255, 0.5);
  border-top-color: rgba(99, 102, 241, 0.1);
}

.pills-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.pill {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.05);
  color: var(--text-secondary);
  padding: 6px 12px;
  border-radius: 99px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
}

[data-theme="light"] .pill {
  background: #ffffff;
  border-color: rgba(0, 0, 0, 0.06);
  color: var(--text-secondary);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.02);
}

.pill:hover {
  background: var(--primary-color);
  color: white;
  border-color: var(--primary-color);
  transform: translateY(-1px);
}

.input-row {
  display: flex;
  gap: 10px;
  align-items: center;
}

.chat-input {
  flex: 1;
  padding: 12px 18px;
  border-radius: var(--radius-md) !important;
  background: rgba(0, 0, 0, 0.2);
  border: 1px solid rgba(255, 255, 255, 0.05);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 14.5px;
  outline: none;
}

[data-theme="light"] .chat-input {
  background: #ffffff;
  border-color: rgba(99, 102, 241, 0.2);
}

.chat-input:focus {
  border-color: var(--primary-color);
  box-shadow: var(--shadow-glow);
}

.action-btn {
  width: 44px;
  height: 44px;
  border-radius: 99px;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.15);
  transition: all 0.2s ease;
}

.btn-mic {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.05);
  color: var(--text-primary);
}

[data-theme="light"] .btn-mic {
  background: #ffffff;
  border-color: rgba(99, 102, 241, 0.2);
}

.btn-mic.recording {
  background: #ef4444 !important;
  color: white !important;
  border-color: #ef4444 !important;
  animation: pulse-red 1.5s infinite;
}

.btn-send {
  background: linear-gradient(135deg, var(--primary-color) 0%, var(--secondary-color) 100%);
  color: white;
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.35);
}

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

/* Modals */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(8px);
  z-index: 1000;
  display: flex;
  justify-content: center;
  align-items: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.modal-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.modal-card {
  width: 100%;
  max-width: 500px;
  background: rgba(20, 16, 50, 0.8);
  border: 1px solid rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(24px);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 28px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  transform: translateY(20px);
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

[data-theme="light"] .modal-card {
  background: #ffffff;
  border-color: rgba(99, 102, 241, 0.15);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  padding-bottom: 12px;
}

[data-theme="light"] .modal-header {
  border-bottom-color: rgba(0, 0, 0, 0.05);
}

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

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

.form-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
}

input[type="text"], input[type="password"] {
  width: 100%;
  padding: 10px 14px;
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: inherit;
  outline: none;
}

[data-theme="light"] input[type="text"], [data-theme="light"] input[type="password"] {
  background: #ffffff;
  border-color: rgba(0, 0, 0, 0.1);
  color: var(--text-primary);
}

input:focus {
  border-color: var(--primary-color);
  box-shadow: var(--shadow-glow);
}

/* Loading Panel Overlay */
.loading-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(15, 23, 42, 0.85);
  backdrop-filter: blur(8px);
  z-index: 100;
  display: none;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  border-radius: var(--radius-lg);
  gap: 16px;
}

[data-theme="light"] .loading-overlay {
  background: rgba(255, 255, 255, 0.85);
}

.spinner {
  width: 44px;
  height: 44px;
  border: 4px solid rgba(99, 102, 241, 0.1);
  border-left-color: var(--primary-color);
  border-radius: 99px;
  animation: spin 1s linear infinite;
}

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

.loading-text {
  font-size: 15px;
  font-weight: 600;
  color: var(--primary-color);
}

/* Toast Message */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: #1e293b;
  color: white;
  padding: 12px 24px;
  border-radius: var(--radius-md);
  font-size: 14px;
  font-weight: 500;
  box-shadow: 0 10px 20px rgba(0, 0, 0, 0.2);
  z-index: 10000;
  opacity: 0;
  transform: translateY(10px);
  transition: all 0.3s ease;
  pointer-events: none;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

@keyframes pulse-red {
  0% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.6); }
  70% { box-shadow: 0 0 0 10px rgba(239, 68, 68, 0); }
  100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0); }
}

/* Canvas preset options buttons */
.btn-preset {
  padding: 4px 8px;
  font-size: 11px;
  font-weight: 600;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: var(--text-primary);
  border-radius: 4px;
  cursor: pointer;
}

[data-theme="light"] .btn-preset {
  background: #ffffff;
  border-color: rgba(0, 0, 0, 0.08);
  color: var(--text-primary);
}

.btn-preset:hover {
  background: var(--primary-color);
  color: white;
  border-color: var(--primary-color);
}

/* Responsive */
@media (max-width: 900px) {
  .main-workspace {
    grid-template-columns: 1fr;
    height: auto;
  }
  body {
    overflow-y: auto;
    height: auto;
  }
  .canvas-container {
    height: 350px;
  }
  .chat-panel {
    height: 500px;
  }
}
