/* ==========================================================================
   Learnify — Global Styles
   Shared design tokens, resets, and base components used on every page.
   ========================================================================== */

:root {
  /* Tells the browser to render its OWN native UI (select dropdown
     popups, focus rings, checkboxes, scrollbars) using the light
     scheme by default. This is separate from our custom --color-*
     variables — those only paint things we draw ourselves. */
  color-scheme: light;

  /* Brand colors */
  --color-purple: #6D3DF5;
  --color-purple-dark: #5A2FE0;
  --color-purple-light: #F3EEFE;
  --color-blue: #3B82F6;
  --color-blue-light: #EFF6FF;

  /* Text */
  --color-text: #111827;
  --color-text-muted: #6B7280;
  --color-text-subtle: #9CA3AF;

  /* Surfaces */
  --color-bg: #F8FAFC;
  --color-surface: #FFFFFF;
  --color-border: #E5E7EB;

  /* Status */
  --color-success: #22C55E;
  --color-success-bg: #ECFDF5;
  --color-danger: #EF4444;
  --color-danger-bg: #FEF2F2;
  --color-warning: #F59E0B;

  /* Gradient */
  --gradient-purple: linear-gradient(135deg, #6D3DF5 0%, #3B82F6 100%);

  /* Radius */
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-full: 999px;

  /* Shadow */
  --shadow-sm: 0 1px 2px rgba(17, 24, 39, 0.04);
  --shadow-md: 0 4px 12px rgba(17, 24, 39, 0.06);
  --shadow-lg: 0 12px 32px rgba(17, 24, 39, 0.08);

  /* Spacing scale */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;
  --space-10: 40px;
  --space-12: 48px;
  --space-16: 64px;

  /* Layout */
  --sidebar-width: 240px;
  --topbar-height: 72px;
  --header-height: 76px;

  /* Type */
  --font-body: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;

  /* Fixed-dark chip color: used for elements (toast, video thumbs) that stay
     dark regardless of theme, so they don't invert along with --color-text */
  --color-ink: #111827;
}

/* ---------- Dark theme ----------
   Toggled by main.js via document.documentElement.setAttribute('data-theme','dark').
   Because every component in this file uses the tokens above instead of
   hard-coded colors, overriding them here is enough to re-skin the whole app. */
:root[data-theme="dark"] {
  color-scheme: dark;

  --color-purple-light: rgba(109, 61, 245, 0.18);
  --color-blue: #60A5FA;
  --color-blue-light: rgba(59, 130, 246, 0.18);

  --color-text: #F3F4F6;
  --color-text-muted: #9CA3AF;
  --color-text-subtle: #8B93A1;

  --color-bg: #0F1115;
  --color-surface: #1A1D24;
  --color-border: #2C2F38;

  --color-success: #34D399;
  --color-success-bg: rgba(34, 197, 94, 0.15);
  --color-danger: #F87171;
  --color-danger-bg: rgba(239, 68, 68, 0.15);
  --color-warning: #FBBF24;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.25);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.45);
}

:root[data-theme="dark"] .field input,
:root[data-theme="dark"] .field select {
  background: var(--color-surface);
  color: var(--color-text);
}

:root[data-theme="dark"] .btn-secondary {
  background: var(--color-surface);
}

body {
  transition: background-color 0.2s ease, color 0.2s ease;
}

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

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  max-width: 100vw;
  overflow-x: hidden;
}

body {
  font-family: var(--font-body);
  color: var(--color-text);
  background: var(--color-bg);
  line-height: 1.5;
  max-width: 100vw;
  overflow-x: hidden;
  position: relative;
}

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

a {
  color: inherit;
  text-decoration: none;
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
}

input, select, textarea {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}

ul, ol {
  list-style: none;
}

/* Visible keyboard focus everywhere */
a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
[tabindex]:focus-visible {
  outline: 2px solid var(--color-purple);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}

/* ---------- Typography helpers ---------- */
h1, h2, h3, h4 {
  font-weight: 700;
  color: var(--color-text);
  line-height: 1.25;
}

.text-muted { color: var(--color-text-muted); }
.text-subtle { color: var(--color-text-subtle); }
.text-purple { color: var(--color-purple); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: 12px 22px;
  border-radius: var(--radius-md);
  font-size: 0.9375rem;
  font-weight: 600;
  white-space: nowrap;
  transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.15s ease, border-color 0.15s ease;
}

.btn-primary {
  background: var(--color-purple);
  color: #fff;
  box-shadow: var(--shadow-sm);
}
.btn-primary:hover {
  background: var(--color-purple-dark);
  box-shadow: var(--shadow-md);
}

.btn-secondary {
  background: #fff;
  color: var(--color-text);
  border: 1px solid var(--color-border);
}
.btn-secondary:hover {
  border-color: var(--color-purple);
  color: var(--color-purple);
}

.btn-danger-outline {
  background: #fff;
  color: var(--color-danger);
  border: 1px solid #FCA5A5;
}
.btn-danger-outline:hover {
  background: var(--color-danger-bg);
}

.btn-sm { padding: 8px 14px; font-size: 0.8125rem; }
.btn-block { width: 100%; }

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

/* ---------- Cards ---------- */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

/* ---------- Form fields ---------- */
.field {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  margin-bottom: var(--space-5);
}

.field label {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--color-text);
}

.field input,
.field select {
  padding: 12px 14px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: #fff;
  font-size: 0.9375rem;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.field input::placeholder {
  color: var(--color-text-subtle);
}

.field input:focus,
.field select:focus {
  outline: none;
  border-color: var(--color-purple);
  box-shadow: 0 0 0 3px var(--color-purple-light);
}

.field-error {
  font-size: 0.8125rem;
  color: var(--color-danger);
  display: none;
}

.field.has-error input {
  border-color: var(--color-danger);
}
.field.has-error .field-error {
  display: block;
}

.password-field {
  position: relative;
}
.password-field input {
  width: 100%;
  padding-right: 44px;
}
.password-toggle {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--color-text-subtle);
  padding: 4px;
  display: flex;
}
.password-toggle:hover {
  color: var(--color-text-muted);
}

/* ---------- Empty states ---------- */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: var(--space-10) var(--space-6);
  color: var(--color-text-muted);
}

.empty-state .empty-icon {
  width: 56px;
  height: 56px;
  border-radius: var(--radius-md);
  background: var(--color-purple-light);
  color: var(--color-purple);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: var(--space-4);
}

.empty-state h4 {
  font-size: 0.9375rem;
  margin-bottom: var(--space-1);
}

.empty-state p {
  font-size: 0.875rem;
  max-width: 260px;
  margin-bottom: var(--space-4);
}

/* ---------- Toast (used for logout, save confirms, etc.) ---------- */
.toast {
  position: fixed;
  bottom: var(--space-6);
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--color-ink);
  color: #fff;
  padding: 12px 20px;
  border-radius: var(--radius-md);
  font-size: 0.875rem;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 1000;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
  pointer-events: auto;
}

/* ---------- Utility ---------- */
.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 var(--space-6);
}

/* ==========================================================================
   App shell — sidebar + topbar (generated by js/main.js renderShell())
   Shared by every authenticated page: dashboard, library, summary, quiz,
   flashcards, progress, settings.
   ========================================================================== */

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

.sidebar {
  width: var(--sidebar-width);
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  height: 100vh;
  z-index: 100;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-6) var(--space-5);
  font-weight: 700;
  font-size: 1.0625rem;
  color: var(--color-text);
}

.logo-mark {
  color: var(--color-purple);
  flex-shrink: 0;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: var(--space-2) var(--space-3);
  flex: 1;
  overflow-y: auto;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: 11px var(--space-3);
  border-radius: var(--radius-md);
  color: var(--color-text-muted);
  font-size: 0.9375rem;
  font-weight: 500;
  transition: background 0.15s ease, color 0.15s ease;
}

.nav-link:hover {
  background: var(--color-bg);
  color: var(--color-text);
}

.nav-link.active {
  background: var(--color-purple-light);
  color: var(--color-purple);
  font-weight: 600;
}

.nav-icon {
  display: flex;
  flex-shrink: 0;
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-5);
  border-top: 1px solid var(--color-border);
}

.sidebar-user-info {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

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

.sidebar-user-role {
  font-size: 0.75rem;
  color: var(--color-text-subtle);
}

.avatar {
  border-radius: 50%;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-purple-light);
  color: var(--color-purple);
  font-weight: 700;
  flex-shrink: 0;
}

.avatar-sm { width: 36px; height: 36px; font-size: 0.8125rem; }
.avatar-md { width: 56px; height: 56px; font-size: 1.25rem; }
.avatar-lg { width: 88px; height: 88px; font-size: 1.75rem; }

.avatar-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.app-main {
  margin-left: var(--sidebar-width);
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  height: var(--topbar-height);
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  gap: var(--space-4);
  padding: 0 var(--space-6);
  position: sticky;
  top: 0;
  z-index: 50;
}

.hamburger-btn {
  display: none;
  background: none;
  border: none;
  color: var(--color-text);
  padding: var(--space-2);
  cursor: pointer;
  border-radius: var(--radius-sm);
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease, color 0.15s ease;
}
.hamburger-btn:hover {
  background: var(--color-bg);
  color: var(--color-purple);
}

.topbar-search {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  color: var(--color-text-subtle);
  width: 320px;
  max-width: 100%;
}

.topbar-search input {
  border: none;
  background: none;
  outline: none;
  width: 100%;
  color: var(--color-text);
  font-size: 0.875rem;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin-left: auto;
}

.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-text-muted);
  transition: background 0.15s ease;
}
.icon-btn:hover {
  background: var(--color-bg);
  color: var(--color-text);
}

.profile-dropdown {
  position: relative;
}

.profile-trigger {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: 6px 10px 6px 6px;
  border-radius: var(--radius-md);
  transition: background 0.15s ease;
}
.profile-trigger:hover {
  background: var(--color-bg);
}

.profile-name {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--color-text);
}

.profile-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  min-width: 160px;
  padding: var(--space-2);
  display: none;
  flex-direction: column;
  gap: 2px;
}
.profile-menu.open {
  display: flex;
}

.profile-menu-item {
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  text-align: left;
  color: var(--color-text);
  width: 100%;
}
.profile-menu-item:hover {
  background: var(--color-bg);
}
.profile-menu-logout {
  color: var(--color-danger);
}

.app-content {
  padding: var(--space-6);
  flex: 1;
}

/* ==========================================================================
   Global Persistent Background Job Widget
   Keeps track of active AI generation across all page navigations
   ========================================================================== */

.global-job-widget {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 320px;
  max-width: calc(100vw - 32px);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.2), 0 8px 10px -6px rgba(0, 0, 0, 0.1);
  padding: 14px 16px;
  z-index: 1100;
  display: flex;
  flex-direction: column;
  gap: 8px;
  transition: opacity 0.25s ease, transform 0.25s ease;
  animation: slideUpWidget 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

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

.job-widget-header {
  display: flex;
  align-items: center;
  gap: 10px;
}

.job-widget-spinner {
  width: 18px;
  height: 18px;
  border: 2.5px solid var(--color-purple-light);
  border-top-color: var(--color-purple);
  border-radius: 50%;
  animation: spinWidget 0.8s linear infinite;
  flex-shrink: 0;
}

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

.job-widget-title-wrap {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.job-widget-label {
  font-size: 0.6875rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--color-purple);
}

.job-widget-name {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--color-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.job-widget-pct {
  font-size: 0.8125rem;
  font-weight: 700;
  color: var(--color-purple);
}

.job-widget-close {
  background: none;
  border: none;
  font-size: 1.25rem;
  line-height: 1;
  color: var(--color-text-muted);
  cursor: pointer;
  padding: 0 4px;
  border-radius: 4px;
  transition: color 0.15s ease, background 0.15s ease;
}
.job-widget-close:hover {
  color: var(--color-text);
  background: var(--color-bg);
}

.job-widget-bar {
  width: 100%;
  height: 4px;
  background: var(--color-bg);
  border-radius: 999px;
  overflow: hidden;
}

.job-widget-bar-fill {
  height: 100%;
  background: var(--color-purple);
  border-radius: 999px;
  transition: width 0.3s ease;
}

.job-widget-step {
  font-size: 0.75rem;
  color: var(--color-text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Toast action button */
.toast-action-btn {
  display: inline-block;
  margin-left: 8px;
  padding: 3px 8px;
  background: var(--color-purple);
  color: #fff !important;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 600;
  text-decoration: none;
  transition: opacity 0.15s ease;
}
.toast-action-btn:hover {
  opacity: 0.9;
}


