/* ========================================
   Modern AI Tutor Platform - 2025 Design
   ======================================== */

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

:root {
  /* Modern Color Palette */
  --bg-primary: #ffffff;
  --bg-secondary: #f8fafc;
  --bg-card: #ffffff;
  --bg-hover: #f1f5f9;

  /* Accent Colors */
  --accent-primary: #3b82f6;
  --accent-secondary: #6366f1;
  --accent-success: #10b981;
  --accent-warning: #f59e0b;
  --accent-error: #ef4444;

  /* Text Colors */
  --text-primary: #0f172a;
  --text-secondary: #64748b;
  --text-muted: #94a3b8;

  /* Borders */
  --border-color: #e2e8f0;
  --border-hover: #cbd5e1;

  /* Shadows */
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.1);
  --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.07);
  --shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.1);

  /* Dimensions */
  --header-height: 64px;
  --sidebar-width: 280px;

  /* Transitions */
  --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Dark Mode */
@media (prefers-color-scheme: dark) {
  :root {
    --bg-primary: #0f172a;
    --bg-secondary: #1e293b;
    --bg-card: #1e293b;
    --bg-hover: #334155;

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

    --border-color: #334155;
    --border-hover: #475569;

    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.2);
    --shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.3);
  }
}

/* ========================================
   Reset & Base
   ======================================== */

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

html {
  font-size: 16px;
  scroll-behavior: smooth;
}

body {
  font-family: "Inter", -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ========================================
   Typography
   ======================================== */

h1,
h2,
h3,
h4,
h5,
h6 {
  font-weight: 600;
  line-height: 1.3;
}

h1 {
  font-size: 2rem;
}
h2 {
  font-size: 1.5rem;
}
h3 {
  font-size: 1.25rem;
}
h4 {
  font-size: 1.1rem;
}

/* ========================================
   Layout
   ======================================== */

.app {
  display: flex;
  min-height: 100vh;
}

/* ========================================
   Sidebar
   ======================================== */

.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-secondary);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  transition: transform var(--transition);
}

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

.logo {
  width: 36px;
  height: 36px;
  background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
}

.logo-text {
  font-size: 1.125rem;
  font-weight: 700;
  color: var(--text-primary);
}

.sidebar-content {
  flex: 1;
  overflow-y: auto;
  padding: 1.25rem;
}

.sidebar-section {
  margin-bottom: 1.5rem;
}

.section-title {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 0.75rem;
  padding-left: 0.5rem;
}

/* New Chat Button */
.new-chat-btn {
  width: 100%;
  padding: 0.75rem 1rem;
  background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
  border: none;
  border-radius: 12px;
  color: white;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  transition: var(--transition);
  margin-bottom: 1rem;
  box-shadow: 0 2px 8px rgba(59, 130, 246, 0.3);
}

.new-chat-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.4);
}

/* Chat History */
.chat-history {
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
}

.history-group-title {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  padding: 0.75rem 0.5rem 0.5rem;
  margin-top: 0.5rem;
}

.history-group-title:first-child {
  margin-top: 0;
}

.history-item {
  padding: 0.75rem;
  border-radius: 10px;
  cursor: pointer;
  transition: var(--transition);
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.history-item:hover {
  background: var(--bg-hover);
}

.history-item.active {
  background: rgba(59, 130, 246, 0.1);
  color: var(--accent-primary);
}

.history-item-icon {
  width: 32px;
  height: 32px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.875rem;
  flex-shrink: 0;
}

.history-item-content {
  flex: 1;
  min-width: 0;
}

.history-item-title {
  font-size: 0.875rem;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text-primary);
}

.history-item-time {
  font-size: 0.7rem;
  color: var(--text-muted);
}

.history-delete-btn {
  display: none;
  width: 28px;
  height: 28px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: 6px;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: var(--transition);
}

.history-item:hover .history-delete-btn {
  display: flex;
}

.history-delete-btn:hover {
  background: rgba(239, 68, 68, 0.1);
  color: var(--accent-error);
}

/* Voice Selector */
.voice-selector {
  display: flex;
  gap: 0.5rem;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  padding: 0.25rem;
}

.voice-btn {
  flex: 1;
  padding: 0.625rem;
  border-radius: 8px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
}

.voice-btn:hover {
  background: var(--bg-hover);
}

.voice-btn.active {
  background: var(--accent-primary);
  color: white;
}

/* Subject Grid */
.subject-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
}

.subject-btn {
  padding: 0.625rem 0.75rem;
  border-radius: 10px;
  border: 1px solid var(--border-color);
  background: var(--bg-card);
  color: var(--text-secondary);
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
  text-align: center;
}

.subject-btn:hover {
  border-color: var(--accent-primary);
  background: var(--bg-hover);
}

.subject-btn.active {
  border-color: var(--accent-primary);
  background: rgba(59, 130, 246, 0.1);
  color: var(--accent-primary);
}

/* Status */
.status-container {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.status-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.625rem 0.75rem;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  font-size: 0.8rem;
}

.status-label {
  color: var(--text-secondary);
}

.status-badge {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  color: var(--text-primary);
  font-weight: 500;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent-error);
}

.status-dot.online {
  background: var(--accent-success);
  box-shadow: 0 0 8px var(--accent-success);
  animation: pulse 2s infinite;
}

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

/* Sidebar Footer */
.sidebar-footer {
  padding: 1rem 1.25rem;
  border-top: 1px solid var(--border-color);
}

.user-info {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.625rem;
  border-radius: 10px;
  cursor: pointer;
  transition: var(--transition);
}

.user-info:hover {
  background: var(--bg-hover);
}

.user-avatar {
  width: 36px;
  height: 36px;
  background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.user-avatar svg {
  width: 18px;
  height: 18px;
  stroke: white;
}

.user-details {
  flex: 1;
  min-width: 0;
}

.user-name {
  font-size: 0.875rem;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text-primary);
}

.user-role {
  font-size: 0.7rem;
  color: var(--text-muted);
}

/* ========================================
   Main Content
   ======================================== */

.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--bg-primary);
}

.main-header {
  height: var(--header-height);
  padding: 0 1.5rem;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-card);
  flex-shrink: 0;
}

.main-title {
  font-size: 1rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 0.625rem;
}

.uzbek-badge {
  background: linear-gradient(135deg, var(--accent-success), #059669);
  color: white;
  padding: 0.25rem 0.625rem;
  border-radius: 6px;
  font-size: 0.7rem;
  font-weight: 600;
}

/* Main Area */
.main-area {
  flex: 1;
  display: flex;
  overflow: hidden;
}

/* Video Section */
.video-section {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--bg-secondary);
}

.video-container {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
}

.video-wrapper {
  position: relative;
  width: 100%;
  max-width: 500px;
  aspect-ratio: 1;
  background: var(--bg-card);
  border-radius: 24px;
  overflow: hidden;
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-lg);
}

.video-wrapper video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.video-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #f8fafc 0%, #e2e8f0 100%);
}

@media (prefers-color-scheme: dark) {
  .video-placeholder {
    background: linear-gradient(135deg, #1e293b 0%, #0f172a 100%);
  }
}

.video-placeholder.hidden {
  display: none;
}

.placeholder-avatar {
  width: 120px;
  height: 120px;
  background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 4rem;
  margin-bottom: 1.5rem;
  box-shadow: 0 8px 24px rgba(59, 130, 246, 0.3);
}

.placeholder-text {
  text-align: center;
}

.placeholder-text h3 {
  font-size: 1.25rem;
  margin-bottom: 0.5rem;
  color: var(--text-primary);
}

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

/* Video Controls */
.video-controls {
  display: flex;
  gap: 0.75rem;
  justify-content: center;
  padding: 1.5rem;
  flex-wrap: wrap;
}

/* ========================================
   Chat Section
   ======================================== */

.chat-section {
  width: 420px;
  display: flex;
  flex-direction: column;
  background: var(--bg-card);
  border-left: 1px solid var(--border-color);
}

.chat-header {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border-color);
}

.chat-header h3 {
  font-size: 1rem;
  margin-bottom: 0.25rem;
  color: var(--text-primary);
}

.chat-header p {
  color: var(--text-secondary);
  font-size: 0.8rem;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.875rem;
}

.message {
  max-width: 85%;
  padding: 0.875rem 1rem;
  border-radius: 16px;
  font-size: 0.9rem;
  line-height: 1.5;
  animation: slideIn 0.3s ease;
}

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

.message.user {
  background: var(--accent-primary);
  color: white;
  align-self: flex-end;
  border-bottom-right-radius: 4px;
}

.message.assistant {
  background: var(--bg-secondary);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  align-self: flex-start;
  border-bottom-left-radius: 4px;
}

.message.system {
  background: rgba(59, 130, 246, 0.1);
  color: var(--text-secondary);
  align-self: center;
  text-align: center;
  font-size: 0.8rem;
  border-radius: 12px;
  max-width: 90%;
}

.message-time {
  font-size: 0.7rem;
  color: rgba(255, 255, 255, 0.7);
  margin-top: 0.375rem;
  display: block;
}

.message.assistant .message-time {
  color: var(--text-muted);
}

/* Quick Actions */
.quick-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  padding: 0.75rem 1.25rem;
  border-bottom: 1px solid var(--border-color);
}

.quick-action {
  padding: 0.5rem 0.875rem;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 20px;
  color: var(--text-secondary);
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
  white-space: nowrap;
}

.quick-action:hover {
  border-color: var(--accent-primary);
  background: rgba(59, 130, 246, 0.05);
  color: var(--accent-primary);
}

/* Chat Input */
.chat-input-container {
  padding: 1rem 1.25rem;
  border-top: 1px solid var(--border-color);
  background: var(--bg-card);
}

.chat-input-wrapper {
  display: flex;
  gap: 0.625rem;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 16px;
  padding: 0.5rem;
  transition: var(--transition);
}

.chat-input-wrapper:focus-within {
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

#chat-input {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.9rem;
  padding: 0.5rem 0.75rem;
  outline: none;
  resize: none;
  min-height: 24px;
  max-height: 100px;
}

#chat-input::placeholder {
  color: var(--text-muted);
}

.input-actions {
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
}

/* ========================================
   Buttons
   ======================================== */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.75rem 1.25rem;
  border-radius: 12px;
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
  border: none;
  outline: none;
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
  color: white;
  box-shadow: 0 2px 8px rgba(59, 130, 246, 0.3);
}

.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.4);
}

.btn-secondary {
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
}

.btn-secondary:hover {
  background: var(--bg-hover);
  border-color: var(--border-hover);
}

.btn-icon {
  width: 44px;
  height: 44px;
  padding: 0;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-icon svg {
  width: 20px;
  height: 20px;
  stroke: currentColor;
  flex-shrink: 0;
}

.btn-icon.recording {
  background: var(--accent-error);
  animation: pulse-record 1.5s infinite;
}

@keyframes pulse-record {
  0%,
  100% {
    box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.5);
  }
  50% {
    box-shadow: 0 0 0 12px rgba(239, 68, 68, 0);
  }
}

/* ========================================
   Loading States
   ======================================== */

.loading-dots {
  display: flex;
  gap: 4px;
  padding: 0.75rem;
}

.loading-dots span {
  width: 8px;
  height: 8px;
  background: var(--accent-primary);
  border-radius: 50%;
  animation: bounce 1.4s infinite ease-in-out both;
}

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

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

/* ========================================
   Modals
   ======================================== */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 0;
  visibility: hidden;
  transition: var(--transition);
}

.modal-overlay.active {
  opacity: 1;
  visibility: visible;
}

.modal {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 20px;
  padding: 1.5rem;
  max-width: 400px;
  width: 90%;
  text-align: center;
  transform: scale(0.9);
  transition: transform 0.2s ease;
  box-shadow: var(--shadow-lg);
}

.modal-overlay.active .modal {
  transform: scale(1);
}

.modal-icon {
  font-size: 3rem;
  margin-bottom: 1rem;
}

.modal-title {
  font-size: 1.25rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
  color: var(--text-primary);
}

.modal-text {
  font-size: 0.9rem;
  color: var(--text-secondary);
  margin-bottom: 1.5rem;
  line-height: 1.6;
}

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

.modal-btn {
  flex: 1;
  padding: 0.875rem 1rem;
  border-radius: 12px;
  border: none;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
}

.modal-btn.cancel {
  background: var(--bg-secondary);
  color: var(--text-secondary);
  border: 1px solid var(--border-color);
}

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

.modal-btn.delete {
  background: var(--accent-error);
  color: white;
}

.modal-btn.delete:hover {
  background: #dc2626;
  transform: translateY(-1px);
}

.modal-btn.primary {
  background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
  color: white;
}

.modal-btn.primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.4);
}

/* ========================================
   Scrollbar
   ======================================== */

::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

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

::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--border-hover);
}

/* ========================================
   Utilities
   ======================================== */

.hidden {
  display: none !important;
}

/* ========================================
   Responsive Design
   ======================================== */

/* Tablet */
@media (max-width: 1024px) {
  :root {
    --sidebar-width: 240px;
  }

  .chat-section {
    width: 360px;
  }
}

/* Mobile */
@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    z-index: 1000;
    transform: translateX(-100%);
  }

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

  .main {
    width: 100%;
  }

  .main-area {
    flex-direction: column;
  }

  .video-section {
    flex: 0 0 50vh;
  }

  .video-container {
    padding: 1rem;
  }

  .chat-section {
    width: 100%;
    flex: 1;
    border-left: none;
    border-top: 1px solid var(--border-color);
  }

  .main-header {
    padding: 0 1rem;
  }

  /* Mobile Menu Toggle */
  .menu-toggle {
    display: flex;
    width: 40px;
    height: 40px;
    border: none;
    background: transparent;
    color: var(--text-primary);
    cursor: pointer;
    align-items: center;
    justify-content: center;
    border-radius: 10px;
    transition: var(--transition);
  }

  .menu-toggle:hover {
    background: var(--bg-hover);
  }

  /* Mobile Overlay */
  .mobile-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 999;
    opacity: 0;
    visibility: hidden;
    transition: var(--transition);
  }

  .mobile-overlay.active {
    opacity: 1;
    visibility: visible;
  }
}

/* Landscape Mobile */
@media (max-width: 768px) and (orientation: landscape) {
  .main-area {
    flex-direction: row;
  }

  .video-section {
    flex: 1;
  }

  .chat-section {
    width: 50%;
    flex: none;
    border-left: 1px solid var(--border-color);
    border-top: none;
  }
}

/* Small Mobile */
@media (max-width: 480px) {
  .subject-grid {
    grid-template-columns: 1fr;
  }

  .video-controls {
    padding: 1rem;
    gap: 0.5rem;
  }

  .btn {
    padding: 0.625rem 1rem;
    font-size: 0.85rem;
  }
}
