/**
 * GetClassroom — Main Stylesheet
 * Mobile-first. WCAG 2.1 AA. Light/dark mode.
 * Clean, approachable, student-friendly.
 *
 * (c) 15988730 Canada Inc. All rights reserved.
 */

/* ============================================================
   CSS CUSTOM PROPERTIES
   ============================================================ */

:root {
  /* Colors — Light */
  --bg-primary: #ffffff;
  --bg-secondary: #f8f9fa;
  --bg-tertiary: #e9ecef;
  --bg-card: #ffffff;
  --bg-hover: #f1f3f5;

  --text-primary: #212529;
  --text-secondary: #495057;
  --text-muted: #868e96;
  --text-inverse: #ffffff;

  --accent: #1a73e8;
  --accent-hover: #1557b0;
  --accent-light: #e8f0fe;

  --success: #0f9d58;
  --success-light: #e6f4ea;
  --warning: #f9ab00;
  --warning-light: #fef7e0;
  --error: #d93025;
  --error-light: #fce8e6;

  --border: #dee2e6;
  --border-light: #e9ecef;

  --shadow-sm: 0 1px 2px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.07);
  --shadow-lg: 0 10px 15px rgba(0,0,0,0.1);

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-full: 9999px;

  --sidebar-width: 240px;
  --header-height: 56px;

  --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
  --font-mono: 'SF Mono', 'Fira Code', 'Fira Mono', 'Roboto Mono', monospace;
}

/* Dark mode */
[data-theme="dark"] {
  --bg-primary: #1a1a2e;
  --bg-secondary: #16213e;
  --bg-tertiary: #0f3460;
  --bg-card: #1a1a2e;
  --bg-hover: #16213e;

  --text-primary: #e4e6eb;
  --text-secondary: #b0b3b8;
  --text-muted: #8a8d91;
  --text-inverse: #1a1a2e;

  --accent: #4d9ff0;
  --accent-hover: #6db3ff;
  --accent-light: #1a3a5c;

  --success: #34a853;
  --success-light: #1a3a2a;
  --warning: #fbbc04;
  --warning-light: #3a3520;
  --error: #ea4335;
  --error-light: #3a1a1a;

  --border: #2d3748;
  --border-light: #1e2a3a;

  --shadow-sm: 0 1px 2px rgba(0,0,0,0.3);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.4);
  --shadow-lg: 0 10px 15px rgba(0,0,0,0.5);
}

/* ============================================================
   RESET & BASE
   ============================================================ */

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

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-sans);
  background-color: var(--bg-secondary);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

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

a:hover {
  text-decoration: underline;
}

a:focus-visible,
button:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

img {
  max-width: 100%;
  height: auto;
}

/* ============================================================
   PAGE MANAGEMENT
   ============================================================ */

.page {
  display: none;
}

.page.active {
  display: block;
}

/* ============================================================
   CONTAINER
   ============================================================ */

.container {
  width: 100%;
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 16px;
}

/* ============================================================
   BUTTONS
   ============================================================ */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 20px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
  font-family: inherit;
  line-height: 1.4;
  white-space: nowrap;
}

.btn-primary {
  background: var(--accent);
  color: var(--text-inverse);
}

.btn-primary:hover {
  background: var(--accent-hover);
}

.btn-secondary {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

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

.btn-ghost {
  background: transparent;
  color: var(--text-primary);
}

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

.btn-danger {
  background: var(--error);
  color: white;
}

.btn-danger:hover {
  background: #c5221f;
}

.btn-success {
  background: var(--success);
  color: white;
}

.btn-full {
  width: 100%;
}

.btn-large {
  padding: 14px 32px;
  font-size: 1.1rem;
}

.btn-small {
  padding: 6px 12px;
  font-size: 0.85rem;
}

.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-primary);
  cursor: pointer;
  transition: background 0.15s ease;
}

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

/* ============================================================
   FORMS
   ============================================================ */

.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  margin-bottom: 6px;
  font-weight: 500;
  font-size: 0.9rem;
  color: var(--text-secondary);
}

.form-group input,
.form-group textarea,
.form-group select {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 1rem;
  font-family: inherit;
  background: var(--bg-primary);
  color: var(--text-primary);
  transition: border-color 0.15s ease;
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
  border-color: var(--accent);
  outline: none;
  box-shadow: 0 0 0 3px var(--accent-light);
}

.form-group textarea {
  resize: vertical;
  min-height: 100px;
}

.form-group input::placeholder,
.form-group textarea::placeholder {
  color: var(--text-muted);
}

.form-error {
  color: var(--error);
  font-size: 0.85rem;
  margin-top: 4px;
  margin-bottom: 12px;
  padding: 8px 12px;
  background: var(--error-light);
  border-radius: var(--radius-sm);
}

/* ============================================================
   LANDING PAGE
   ============================================================ */

.landing-header {
  padding: 16px 0;
  background: var(--bg-primary);
  border-bottom: 1px solid var(--border-light);
  position: sticky;
  top: 0;
  z-index: 100;
}

.landing-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

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

.logo-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  background: var(--accent);
  color: white;
  border-radius: var(--radius-sm);
  font-weight: 700;
  font-size: 0.85rem;
}

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

.nav-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.landing-hero {
  padding: 80px 0 60px;
  text-align: center;
  background: var(--bg-primary);
}

.landing-hero h1 {
  font-size: 2.4rem;
  font-weight: 800;
  line-height: 1.2;
  margin-bottom: 16px;
  color: var(--text-primary);
}

.hero-sub {
  font-size: 1.15rem;
  color: var(--text-secondary);
  max-width: 540px;
  margin: 0 auto 32px;
  line-height: 1.6;
}

.hero-price {
  margin-bottom: 8px;
}

.price-amount {
  font-size: 3rem;
  font-weight: 800;
  color: var(--accent);
}

.price-period {
  font-size: 1.2rem;
  color: var(--text-muted);
}

.hero-note {
  font-size: 0.9rem;
  color: var(--text-muted);
  margin-bottom: 32px;
}

/* Features Grid */
.landing-features {
  padding: 60px 0;
  background: var(--bg-secondary);
}

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

.feature-card {
  background: var(--bg-card);
  padding: 28px 24px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-light);
  transition: box-shadow 0.2s ease;
}

.feature-card:hover {
  box-shadow: var(--shadow-md);
}

.feature-icon {
  font-size: 2rem;
  margin-bottom: 12px;
}

.feature-card h3 {
  font-size: 1.1rem;
  margin-bottom: 8px;
}

.feature-card p {
  font-size: 0.95rem;
  color: var(--text-secondary);
  line-height: 1.5;
}

/* How it works */
.landing-how {
  padding: 60px 0;
  background: var(--bg-primary);
}

.landing-how h2 {
  text-align: center;
  font-size: 1.8rem;
  margin-bottom: 40px;
}

.steps {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 32px;
  max-width: 900px;
  margin: 0 auto;
}

.step {
  text-align: center;
}

.step-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  background: var(--accent);
  color: white;
  border-radius: 50%;
  font-size: 1.3rem;
  font-weight: 700;
  margin-bottom: 16px;
}

.step h3 {
  font-size: 1.05rem;
  margin-bottom: 8px;
}

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

/* Footer */
.landing-footer {
  padding: 32px 0;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border-light);
  text-align: center;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.footer-links {
  margin-top: 8px;
}

.footer-links a {
  color: var(--text-muted);
}

.footer-links a:hover {
  color: var(--accent);
}

/* ============================================================
   AUTH PAGES
   ============================================================ */

.auth-container {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 24px;
  background: var(--bg-secondary);
}

.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--bg-card);
  padding: 36px 28px;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  border: 1px solid var(--border-light);
}

.logo-center {
  text-align: center;
  margin-bottom: 28px;
}

.logo-center .logo-icon {
  width: 48px;
  height: 48px;
  font-size: 1.1rem;
  margin-bottom: 12px;
}

.logo-center h2 {
  font-size: 1.4rem;
  color: var(--text-primary);
}

.auth-switch {
  text-align: center;
  font-size: 0.9rem;
  color: var(--text-muted);
  margin-top: 16px;
}

/* ============================================================
   APP HEADER
   ============================================================ */

.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: var(--header-height);
  padding: 0 16px;
  background: var(--bg-primary);
  border-bottom: 1px solid var(--border-light);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.header-title {
  font-weight: 700;
  font-size: 1.1rem;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 4px;
}

/* ============================================================
   SIDEBAR
   ============================================================ */

.sidebar {
  position: fixed;
  top: var(--header-height);
  left: 0;
  width: var(--sidebar-width);
  height: calc(100vh - var(--header-height));
  background: var(--bg-primary);
  border-right: 1px solid var(--border-light);
  overflow-y: auto;
  transform: translateX(-100%);
  transition: transform 0.2s ease;
  z-index: 90;
}

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

.sidebar-nav {
  list-style: none;
  padding: 8px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 0.95rem;
  font-weight: 500;
  transition: all 0.15s ease;
  text-decoration: none;
}

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

.nav-item.active {
  background: var(--accent-light);
  color: var(--accent);
}

/* ============================================================
   MAIN CONTENT
   ============================================================ */

.main-content {
  padding: 24px 16px;
  max-width: 900px;
  margin: 0 auto;
}

/* ============================================================
   CARDS LAYOUT
   ============================================================ */

.view-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
  flex-wrap: wrap;
  gap: 12px;
}

.view-header h2 {
  font-size: 1.5rem;
  font-weight: 700;
}

/* Item cards (list items for courses, notes, etc.) */
.item-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.item-card {
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  padding: 16px 20px;
  cursor: pointer;
  transition: box-shadow 0.15s ease;
}

.item-card:hover {
  box-shadow: var(--shadow-sm);
}

.item-card h3 {
  font-size: 1.05rem;
  margin-bottom: 4px;
}

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

.item-card .item-meta {
  display: flex;
  gap: 16px;
  margin-top: 8px;
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* ============================================================
   FLASH CARD UI
   ============================================================ */

.flashcard-container {
  perspective: 1000px;
  max-width: 500px;
  margin: 0 auto;
}

.flashcard {
  position: relative;
  width: 100%;
  min-height: 280px;
  cursor: pointer;
  transform-style: preserve-3d;
  transition: transform 0.5s ease;
}

.flashcard.flipped {
  transform: rotateY(180deg);
}

.flashcard-face {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px 24px;
  background: var(--bg-card);
  border: 2px solid var(--border);
  border-radius: var(--radius-lg);
  backface-visibility: hidden;
  font-size: 1.2rem;
  text-align: center;
  line-height: 1.5;
}

.flashcard-back {
  transform: rotateY(180deg);
  background: var(--accent-light);
  border-color: var(--accent);
}

.flashcard-hint {
  text-align: center;
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-top: 12px;
}

.rating-buttons {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-top: 20px;
  flex-wrap: wrap;
}

.rating-btn {
  padding: 8px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.15s ease;
}

.rating-btn:hover {
  border-color: var(--accent);
  background: var(--accent-light);
}

.rating-btn.easy {
  border-color: var(--success);
  color: var(--success);
}

.rating-btn.hard {
  border-color: var(--error);
  color: var(--error);
}

/* ============================================================
   TUTOR CHAT UI
   ============================================================ */

.tutor-chat {
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-width: 600px;
  margin: 0 auto;
  min-height: 400px;
}

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

.chat-bubble {
  max-width: 80%;
  padding: 12px 16px;
  border-radius: var(--radius-md);
  font-size: 0.95rem;
  line-height: 1.5;
}

.chat-bubble.tutor {
  background: var(--accent-light);
  color: var(--text-primary);
  align-self: flex-start;
  border-bottom-left-radius: 4px;
}

.chat-bubble.student {
  background: var(--accent);
  color: var(--text-inverse);
  align-self: flex-end;
  border-bottom-right-radius: 4px;
}

.chat-bubble .bloom-tag {
  display: inline-block;
  font-size: 0.7rem;
  background: var(--bg-tertiary);
  color: var(--text-muted);
  padding: 2px 8px;
  border-radius: var(--radius-full);
  margin-bottom: 6px;
}

.chat-input-row {
  display: flex;
  gap: 8px;
}

.chat-input-row input {
  flex: 1;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  font-size: 1rem;
  background: var(--bg-primary);
  color: var(--text-primary);
}

.chat-input-row input:focus {
  border-color: var(--accent);
  outline: none;
}

/* ============================================================
   SCANNER UI
   ============================================================ */

.scanner-area {
  text-align: center;
  max-width: 500px;
  margin: 0 auto;
}

.camera-preview {
  width: 100%;
  max-height: 400px;
  border-radius: var(--radius-md);
  border: 2px dashed var(--border);
  background: var(--bg-tertiary);
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 250px;
  overflow: hidden;
}

.camera-preview video {
  width: 100%;
  border-radius: var(--radius-md);
}

.camera-preview img {
  max-width: 100%;
  max-height: 400px;
  border-radius: var(--radius-md);
}

.scanner-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
  margin-top: 16px;
  flex-wrap: wrap;
}

/* ============================================================
   PROVENANCE UI
   ============================================================ */

.provenance-status {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  background: var(--success-light);
  border-radius: var(--radius-sm);
  margin-bottom: 20px;
  font-size: 0.9rem;
}

.provenance-status.invalid {
  background: var(--error-light);
}

.chain-entry {
  padding: 12px 16px;
  border-left: 3px solid var(--accent);
  background: var(--bg-card);
  margin-bottom: 8px;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  font-size: 0.85rem;
}

.chain-entry .entry-type {
  font-weight: 600;
  color: var(--accent);
  text-transform: uppercase;
  font-size: 0.75rem;
  letter-spacing: 0.5px;
}

.chain-entry .entry-hash {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--text-muted);
  word-break: break-all;
}

.chain-entry .entry-time {
  color: var(--text-muted);
  font-size: 0.8rem;
}

/* ============================================================
   PROGRESS BAR
   ============================================================ */

.progress-bar {
  height: 8px;
  background: var(--bg-tertiary);
  border-radius: var(--radius-full);
  overflow: hidden;
}

.progress-bar .progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: var(--radius-full);
  transition: width 0.3s ease;
}

/* ============================================================
   STATS GRID
   ============================================================ */

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  padding: 16px;
  text-align: center;
}

.stat-card .stat-value {
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--accent);
}

.stat-card .stat-label {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 4px;
}

/* ============================================================
   MODAL
   ============================================================ */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 16px;
}

.modal {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: 28px 24px;
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
}

.modal h3 {
  font-size: 1.2rem;
  margin-bottom: 20px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 20px;
}

/* ============================================================
   EMPTY STATE
   ============================================================ */

.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-muted);
}

.empty-state .empty-icon {
  font-size: 3rem;
  margin-bottom: 16px;
}

.empty-state h3 {
  font-size: 1.1rem;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.empty-state p {
  font-size: 0.9rem;
  margin-bottom: 20px;
}

/* ============================================================
   TOAST NOTIFICATIONS
   ============================================================ */

.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 300;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  padding: 12px 20px;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  box-shadow: var(--shadow-md);
  animation: slideIn 0.3s ease;
  max-width: 360px;
}

.toast.success {
  background: var(--success);
  color: white;
}

.toast.error {
  background: var(--error);
  color: white;
}

.toast.info {
  background: var(--accent);
  color: white;
}

@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* ============================================================
   LOADING SPINNER
   ============================================================ */

.spinner {
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

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

/* ============================================================
   RESPONSIVE — TABLET & DESKTOP
   ============================================================ */

@media (min-width: 768px) {
  .sidebar {
    transform: translateX(0);
  }

  .main-content {
    margin-left: var(--sidebar-width);
    padding: 32px;
  }

  .menu-toggle {
    display: none;
  }

  .landing-hero h1 {
    font-size: 3.2rem;
  }

  .container {
    padding: 0 24px;
  }
}

@media (min-width: 1024px) {
  .landing-hero h1 {
    font-size: 3.6rem;
  }
}

/* ============================================================
   ACCESSIBILITY
   ============================================================ */

/* Reduce motion for users who prefer it */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* High contrast for better readability */
@media (prefers-contrast: high) {
  :root {
    --border: #000000;
    --text-muted: #333333;
  }
}

/* Skip link for keyboard navigation */
.skip-link {
  position: absolute;
  top: -40px;
  left: 0;
  background: var(--accent);
  color: white;
  padding: 8px 16px;
  z-index: 1000;
  transition: top 0.2s ease;
}

.skip-link:focus {
  top: 0;
}

/* Screen reader only */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
