/* ==========================================================================
   STUDYBUDDY - ULTRA-PROFESSIONAL MONOCHROME (BLACK & WHITE) DESIGN SYSTEM
   Precision typography, high contrast, clean hairlines, 100% mobile-friendly.
   ========================================================================== */

/* --- Clean Monochrome Variables --- */
:root {
  /* Light Theme (Default: High-end White & Jet Black) */
  --bg-app: #ffffff;
  --bg-surface: #ffffff;
  --bg-subtle: #f4f4f5;
  --bg-hover: #ebebeb;
  
  --border-subtle: #e4e4e7;
  --border-strong: #d4d4d8;
  --border-focus: #09090b;

  --text-primary: #09090b;
  --text-secondary: #52525b;
  --text-muted: #71717a;
  --text-inverse: #ffffff;

  --btn-primary-bg: #09090b;
  --btn-primary-text: #ffffff;
  --btn-primary-hover: #27272a;

  --btn-secondary-bg: #ffffff;
  --btn-secondary-text: #09090b;
  --btn-secondary-border: #e4e4e7;
  --btn-secondary-hover: #f4f4f5;

  --badge-bg: #f4f4f5;
  --badge-text: #18181b;
  --badge-border: #e4e4e7;

  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.04);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.04), 0 2px 4px -2px rgba(0, 0, 0, 0.02);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.06), 0 4px 6px -4px rgba(0, 0, 0, 0.03);

  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-full: 9999px;

  --font-sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;

  --max-width: 1120px;
  --header-height: 60px;
  --bottom-nav-height: 56px;

  /* Safe Area Insets for Mobile Notches & Gesture Bars */
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

/* Dark Theme (Obsidian & Crisp White) */
[data-theme="dark"] {
  --bg-app: #000000;
  --bg-surface: #09090b;
  --bg-subtle: #18181b;
  --bg-hover: #27272a;
  
  --border-subtle: #27272a;
  --border-strong: #3f3f46;
  --border-focus: #f4f4f5;

  --text-primary: #fafafa;
  --text-secondary: #a1a1aa;
  --text-muted: #71717a;
  --text-inverse: #09090b;

  --btn-primary-bg: #fafafa;
  --btn-primary-text: #09090b;
  --btn-primary-hover: #e4e4e7;

  --btn-secondary-bg: #09090b;
  --btn-secondary-text: #fafafa;
  --btn-secondary-border: #27272a;
  --btn-secondary-hover: #18181b;

  --badge-bg: #18181b;
  --badge-text: #f4f4f5;
  --badge-border: #27272a;

  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.6);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.7);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.8);
}

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

html {
  font-size: 15px;
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  overflow-x: hidden;
  width: 100%;
}

body {
  font-family: var(--font-sans);
  background-color: var(--bg-app);
  color: var(--text-primary);
  line-height: 1.55;
  letter-spacing: -0.011em;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  transition: background-color 0.15s ease, color 0.15s ease;
  overflow-x: hidden;
  width: 100%;
  -webkit-tap-highlight-color: transparent;
  padding-left: var(--safe-left);
  padding-right: var(--safe-right);
}

body.modal-open {
  overflow: hidden;
  touch-action: none;
}

a {
  color: inherit;
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
}

button, input, select, textarea {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

/* Tactile touch-press effect for mobile buttons */
button:active:not(:disabled),
.btn:active:not(:disabled),
.nav-link-btn:active,
.icon-btn:active {
  transform: scale(0.97);
  transition: transform 0.05s ease;
}

/* --- Top Navigation Header --- */
.site-header {
  position: sticky;
  top: 0;
  z-index: 50;
  height: var(--header-height);
  background-color: var(--bg-surface);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
}

.header-container {
  width: 100%;
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.brand-wrapper {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  cursor: pointer;
  user-select: none;
  min-width: 0;
}

.brand-logo-img-wrapper {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border-subtle);
  background-color: var(--bg-surface);
}

.brand-logo-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: none;
}

[data-theme="light"] .brand-logo-light {
  display: block;
}

[data-theme="dark"] .brand-logo-dark {
  display: block;
}

.brand-logo-monochrome {
  width: 28px;
  height: 28px;
  border-radius: var(--radius-sm);
  background-color: var(--btn-primary-bg);
  color: var(--btn-primary-text);
  display: none;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  flex-shrink: 0;
}

.brand-text-group {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  min-width: 0;
}

.brand-title {
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: -0.025em;
  color: var(--text-primary);
  white-space: nowrap;
}

.brand-tag {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 2px 6px;
  background-color: var(--bg-subtle);
  color: var(--text-muted);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  font-weight: 600;
  white-space: nowrap;
}

/* Header Actions & Nav Links */
.header-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.nav-link-btn {
  background: transparent;
  border: 1px solid transparent;
  padding: 0.4rem 0.75rem;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  transition: all 0.15s ease;
}

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

.icon-btn {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--text-secondary);
  font-size: 0.95rem;
  transition: all 0.15s ease;
}

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

.user-profile-badge {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.25rem 0.6rem;
  border-radius: var(--radius-full);
  background-color: var(--bg-subtle);
  border: 1px solid var(--border-subtle);
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-primary);
}

.user-profile-avatar {
  width: 22px;
  height: 22px;
  border-radius: var(--radius-full);
  object-fit: cover;
  background-color: var(--border-subtle);
}

/* --- Breadcrumb Navigation Strip --- */
.breadcrumb-bar {
  background-color: var(--bg-surface);
  border-bottom: 1px solid var(--border-subtle);
  padding: 0.5rem 0;
  font-size: 0.8rem;
}

.breadcrumb-container {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 1.25rem;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  color: var(--text-muted);
  overflow-x: auto;
  white-space: nowrap;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.breadcrumb-container::-webkit-scrollbar {
  display: none;
}

.breadcrumb-item {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-shrink: 0;
}

.breadcrumb-link {
  color: var(--text-secondary);
  cursor: pointer;
  transition: color 0.15s ease;
}

.breadcrumb-link:hover {
  color: var(--text-primary);
  text-decoration: underline;
}

.breadcrumb-current {
  color: var(--text-primary);
  font-weight: 600;
}

/* --- Main Layout Container --- */
.main-content {
  flex: 1;
  max-width: var(--max-width);
  width: 100%;
  margin: 0 auto;
  padding: 2rem 1.25rem;
}

/* --- View Panels --- */
.view-panel {
  display: none;
}

.view-panel.active {
  display: block;
  animation: fadeIn 0.15s ease;
}

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

/* --- Typography & Section Headers --- */
.section-header {
  margin-bottom: 1.75rem;
}

.section-eyebrow {
  font-size: 0.725rem;
  text-transform: uppercase;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 0.35rem;
}

.section-title {
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.025em;
  margin-bottom: 0.35rem;
}

.section-subtitle {
  color: var(--text-secondary);
  font-size: 0.925rem;
  line-height: 1.5;
  max-width: 640px;
}

/* --- Buttons System --- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.55rem 1.1rem;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.15s ease;
  user-select: none;
  white-space: nowrap;
}

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

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

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

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

.btn-google {
  width: 100%;
  background-color: var(--bg-surface);
  color: var(--text-primary);
  border: 1px solid var(--border-subtle);
  padding: 0.65rem 1rem;
  font-size: 0.9rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn-google:hover {
  background-color: var(--bg-subtle);
  border-color: var(--border-strong);
}

.btn-sm {
  padding: 0.35rem 0.65rem;
  font-size: 0.8rem;
}

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.2rem 0.55rem;
  border-radius: var(--radius-sm);
  font-size: 0.725rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  background-color: var(--badge-bg);
  color: var(--badge-text);
  border: 1px solid var(--badge-border);
}

/* ==========================================================================
   VIEW 1: AUTHENTICATION (PROFESSIONAL GOOGLE & EMAIL LOGIN)
   ========================================================================== */
.auth-wrapper {
  max-width: 400px;
  width: 100%;
  margin: 3.5rem auto;
  background-color: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 2.25rem 2rem;
  box-shadow: var(--shadow-sm);
}

.auth-header {
  text-align: center;
  margin-bottom: 1.75rem;
}

.auth-logo-container {
  width: 72px;
  height: 72px;
  margin: 0 auto 1.1rem;
  border-radius: var(--radius-md);
  overflow: hidden;
  border: 1px solid var(--border-subtle);
  box-shadow: var(--shadow-sm);
  background-color: var(--bg-surface);
  display: flex;
  align-items: center;
  justify-content: center;
}

.auth-logo-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: none;
}

[data-theme="light"] .auth-logo-light {
  display: block;
}

[data-theme="dark"] .auth-logo-dark {
  display: block;
}

.auth-logo-badge {
  display: none;
}

.auth-title {
  font-size: 1.4rem;
  font-weight: 700;
  letter-spacing: -0.025em;
  color: var(--text-primary);
}

.auth-desc {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-top: 0.25rem;
}

.auth-tabs {
  display: flex;
  background-color: var(--bg-subtle);
  padding: 3px;
  border-radius: var(--radius-sm);
  margin-bottom: 1.25rem;
  border: 1px solid var(--border-subtle);
}

.auth-tab-btn {
  flex: 1;
  background: transparent;
  border: none;
  padding: 0.45rem 0;
  font-size: 0.825rem;
  font-weight: 600;
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s ease;
}

.auth-tab-btn.active {
  background-color: var(--bg-surface);
  color: var(--text-primary);
  box-shadow: var(--shadow-sm);
}

.auth-divider {
  display: flex;
  align-items: center;
  text-align: center;
  margin: 1.25rem 0;
  color: var(--text-muted);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.auth-divider::before, .auth-divider::after {
  content: '';
  flex: 1;
  border-bottom: 1px solid var(--border-subtle);
}

.auth-divider span {
  padding: 0 0.65rem;
}

.form-group {
  margin-bottom: 1rem;
}

.form-label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 0.35rem;
}

.form-input, .form-select, .form-textarea {
  width: 100%;
  padding: 0.6rem 0.8rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
  background-color: var(--bg-surface);
  color: var(--text-primary);
  outline: none;
  font-size: 0.875rem;
  transition: border-color 0.15s ease;
}

.form-input:focus, .form-select:focus, .form-textarea:focus {
  border-color: var(--border-focus);
}

/* ==========================================================================
   VIEW 2: DASHBOARD (5 SUBJECTS)
   ========================================================================== */
.dashboard-banner {
  background-color: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 1.75rem;
  margin-bottom: 2rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 1.5rem;
}

.dashboard-banner-text h2 {
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text-primary);
  margin-bottom: 0.25rem;
}

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

.dashboard-stats-strip {
  display: flex;
  gap: 1.25rem;
}

.stat-item {
  text-align: center;
  padding: 0 0.5rem;
}

.stat-number {
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  color: var(--text-primary);
}

.stat-label {
  font-size: 0.7rem;
  color: var(--text-muted);
  text-transform: uppercase;
  font-weight: 600;
  letter-spacing: 0.05em;
}

/* 5 Subjects Grid */
.subjects-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 1.25rem;
}

.subject-card {
  background-color: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 1.5rem;
  cursor: pointer;
  transition: all 0.15s ease;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.subject-card:hover {
  border-color: var(--border-focus);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.subject-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 1rem;
}

.subject-card-icon-monochrome {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-sm);
  background-color: var(--bg-subtle);
  border: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.15rem;
}

.subject-card-title {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text-primary);
  margin-bottom: 0.35rem;
}

.subject-card-tagline {
  color: var(--text-secondary);
  font-size: 0.85rem;
  margin-bottom: 1.25rem;
  line-height: 1.45;
}

.subject-card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: 0.85rem;
  border-top: 1px solid var(--border-subtle);
  font-size: 0.8rem;
  color: var(--text-muted);
}

.subject-card-btn {
  color: var(--text-primary);
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
}

/* ==========================================================================
   VIEW 3: SUBJECT & CHAPTERS LIST
   ========================================================================== */
.subject-banner {
  background-color: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 1.75rem;
  margin-bottom: 1.75rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 1.25rem;
}

.subject-banner-info {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.subject-large-icon {
  font-size: 1.75rem;
  width: 52px;
  height: 52px;
  border-radius: var(--radius-md);
  background-color: var(--bg-subtle);
  border: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: center;
}

.search-filter-bar {
  margin-bottom: 1.5rem;
  display: flex;
  gap: 1rem;
}

.search-input-wrapper {
  position: relative;
  flex: 1;
}

.search-input {
  width: 100%;
  padding: 0.65rem 1rem 0.65rem 2.4rem;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  background-color: var(--bg-surface);
  color: var(--text-primary);
  font-size: 0.875rem;
}

.search-input:focus {
  border-color: var(--border-focus);
  outline: none;
}

.search-icon-fixed {
  position: absolute;
  left: 0.85rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  font-size: 0.85rem;
}

/* Chapters Table / List */
.chapters-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.chapter-card {
  background-color: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 1.25rem 1.4rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1.25rem;
  cursor: pointer;
  transition: all 0.15s ease;
}

.chapter-card:hover {
  border-color: var(--border-focus);
  background-color: var(--bg-subtle);
}

.chapter-card-main {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex: 1;
}

.chapter-number-badge {
  width: 34px;
  height: 34px;
  border-radius: var(--radius-sm);
  background-color: var(--bg-subtle);
  border: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.85rem;
  color: var(--text-primary);
  flex-shrink: 0;
}

.chapter-details h3 {
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: -0.015em;
  color: var(--text-primary);
  margin-bottom: 0.2rem;
}

.chapter-details p {
  color: var(--text-secondary);
  font-size: 0.825rem;
  line-height: 1.4;
  margin-bottom: 0.45rem;
}

.chapter-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.topic-tag {
  background-color: var(--bg-subtle);
  border: 1px solid var(--border-subtle);
  color: var(--text-muted);
  font-size: 0.7rem;
  padding: 1px 6px;
  border-radius: var(--radius-sm);
}

.chapter-card-actions {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  flex-shrink: 0;
}

/* ==========================================================================
   VIEW 4: VIDEO PAGE (DISTRACTION-FREE YOUTUBE LECTURE)
   ========================================================================== */
.video-view-layout {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.video-top-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.chapter-nav-btns {
  display: flex;
  gap: 0.4rem;
}

.video-player-container {
  position: relative;
  width: 100%;
  background-color: #000000;
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-md);
  aspect-ratio: 16 / 9;
  border: 1px solid var(--border-subtle);
}

.video-player-container iframe {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  border: none;
}

/* Cinema / Theater Mode */
body.cinema-mode .site-header,
body.cinema-mode .breadcrumb-bar,
body.cinema-mode .notes-section-wrapper {
  opacity: 0.15;
  transition: opacity 0.25s ease;
}

body.cinema-mode .site-header:hover,
body.cinema-mode .notes-section-wrapper:hover {
  opacity: 1;
}

.video-meta-bar {
  background-color: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 1.25rem;
}

.video-meta-left {
  max-width: 680px;
}

.video-chapter-title {
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -0.025em;
  color: var(--text-primary);
  margin: 0.35rem 0;
}

.video-meta-actions {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  flex-wrap: wrap;
}

.update-video-hint {
  font-size: 0.75rem;
  background-color: var(--bg-subtle);
  color: var(--text-secondary);
  border: 1px solid var(--border-subtle);
  padding: 0.4rem 0.65rem;
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  margin-top: 0.5rem;
}

/* ==========================================================================
   VIEW 5: NOTES & SCHOOL WORK SECTION
   ========================================================================== */
.notes-section-wrapper {
  margin-top: 1.5rem;
  background-color: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 1.75rem;
}

.notes-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 1rem;
  margin-bottom: 1.25rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border-subtle);
}

.notes-tabs {
  display: flex;
  gap: 0.4rem;
  overflow-x: auto;
  white-space: nowrap;
  scrollbar-width: none;
}

.notes-tabs::-webkit-scrollbar {
  display: none;
}

.notes-tab-btn {
  background: transparent;
  border: 1px solid var(--border-subtle);
  padding: 0.45rem 0.85rem;
  border-radius: var(--radius-sm);
  font-size: 0.825rem;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  transition: all 0.15s ease;
}

.notes-tab-btn.active {
  background-color: var(--btn-primary-bg);
  color: var(--btn-primary-text);
  border-color: var(--btn-primary-bg);
}

.resources-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 1rem;
}

.resource-card {
  background-color: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  transition: border-color 0.15s ease;
}

.resource-card:hover {
  border-color: var(--border-focus);
}

.resource-card-top {
  display: flex;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.resource-file-icon {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  background-color: var(--bg-subtle);
  border: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 700;
  font-family: var(--font-mono);
  color: var(--text-primary);
  flex-shrink: 0;
}

.resource-card-info h4 {
  font-size: 0.925rem;
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1.35;
  margin-bottom: 0.2rem;
}

.resource-desc {
  font-size: 0.8rem;
  color: var(--text-secondary);
  line-height: 1.4;
  margin-bottom: 0.75rem;
}

.resource-card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border-subtle);
  font-size: 0.75rem;
  color: var(--text-muted);
}

.resource-meta-author {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.resource-actions {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.empty-resources-box {
  grid-column: 1 / -1;
  text-align: center;
  padding: 2.5rem 1rem;
  background-color: var(--bg-subtle);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-md);
}

.empty-resources-box h4 {
  font-size: 1rem;
  color: var(--text-primary);
  margin: 0.4rem 0 0.2rem;
}

.empty-resources-box p {
  color: var(--text-secondary);
  font-size: 0.825rem;
  margin-bottom: 1rem;
}

/* ==========================================================================
   MODAL DIALOG (UPLOAD & VIDEO EDIT)
   ========================================================================== */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background-color: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(2px);
  z-index: 100;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.modal-overlay.open {
  display: flex;
  animation: modalFadeIn 0.15s ease;
}

@keyframes modalFadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal-dialog {
  background-color: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  max-width: 500px;
  width: 100%;
  padding: 1.75rem;
  box-shadow: var(--shadow-lg);
  max-height: 90vh;
  overflow-y: auto;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.25rem;
}

.modal-title {
  font-size: 1.2rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text-primary);
}

.modal-close-btn {
  background: transparent;
  border: none;
  font-size: 1.15rem;
  cursor: pointer;
  color: var(--text-muted);
  padding: 0.25rem;
  line-height: 1;
}

.modal-close-btn:hover {
  color: var(--text-primary);
}

.dropzone-area {
  border: 2px dashed var(--border-strong);
  border-radius: var(--radius-md);
  padding: 1.75rem 1rem;
  text-align: center;
  background-color: var(--bg-subtle);
  cursor: pointer;
  margin-bottom: 1rem;
  transition: all 0.15s ease;
}

.dropzone-area:hover, .dropzone-area.dragover {
  border-color: var(--border-focus);
  background-color: var(--bg-hover);
}

.dropzone-icon {
  font-size: 1.75rem;
  margin-bottom: 0.35rem;
}

.dropzone-text {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-primary);
}

.dropzone-subtext {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 0.2rem;
}

.selected-file-preview {
  display: none;
  align-items: center;
  justify-content: space-between;
  background-color: var(--bg-subtle);
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
  margin-bottom: 1rem;
}

.selected-file-preview.has-file {
  display: flex;
}

.modal-sheet-handle {
  display: none;
}

.modal-actions-footer {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 1.25rem;
}

/* ==========================================================================
   MOBILE BOTTOM APP NAVIGATION BAR
   ========================================================================== */
.mobile-bottom-nav {
  display: none;
}

.mobile-nav-item {
  flex: 1;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 0.65rem;
  font-weight: 600;
  cursor: pointer;
  padding: 6px 0;
  transition: color 0.15s ease, transform 0.1s ease;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.mobile-nav-item:active {
  transform: scale(0.92);
}

.mobile-nav-item.active {
  color: var(--text-primary);
}

.mobile-nav-item.active svg {
  stroke-width: 2.5;
}

/* Toast Notifications */
.toast-container {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-width: 90vw;
}

.toast {
  background-color: var(--btn-primary-bg);
  color: var(--btn-primary-text);
  border: 1px solid var(--border-subtle);
  padding: 0.65rem 1.1rem;
  border-radius: var(--radius-sm);
  font-size: 0.825rem;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  animation: slideInUp 0.15s ease-out;
}

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

/* ==========================================================================
   100% COMPREHENSIVE MULTI-SCREEN & MOBILE-FIRST RESPONSIVE SYSTEM
   Optimized for phones (320px–480px), phablets (480px–768px), tablets (768px–1024px)
   ========================================================================== */

/* --- TABLETS & SMALL LAPTOPS (769px - 1024px) --- */
@media (min-width: 769px) and (max-width: 1024px) {
  .main-content {
    padding: 1.75rem 1.25rem;
  }

  .subjects-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 1.15rem;
  }

  .resources-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .dashboard-banner {
    padding: 1.5rem;
  }
}

/* --- MOBILE PHONES & PORTRAIT TABLETS (<= 768px) --- */
@media (max-width: 768px) {
  html {
    font-size: 14.5px;
  }

  body.has-bottom-nav .main-content {
    padding-bottom: calc(var(--bottom-nav-height) + var(--safe-bottom) + 1.75rem);
  }

  .main-content {
    padding: 1rem 0.85rem;
    width: 100%;
    min-width: 0;
  }

  /* Sticky Mobile Bottom Navigation Bar */
  .mobile-bottom-nav {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: calc(var(--bottom-nav-height) + var(--safe-bottom));
    padding-bottom: var(--safe-bottom);
    background-color: var(--bg-surface);
    border-top: 1px solid var(--border-subtle);
    z-index: 90;
    align-items: center;
    justify-content: space-around;
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    background-color: rgba(255, 255, 255, 0.94);
    box-shadow: 0 -3px 12px rgba(0, 0, 0, 0.05);
  }

  [data-theme="dark"] .mobile-bottom-nav {
    background-color: rgba(9, 9, 11, 0.94);
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.7);
  }

  /* Compact Top Header on Mobile */
  .site-header {
    height: auto;
    min-height: 52px;
    padding: 0.45rem 0;
  }

  .header-container {
    padding: 0 0.85rem;
    gap: 0.4rem;
  }

  .brand-title {
    font-size: 0.98rem;
  }

  .nav-btn-text {
    display: none;
  }

  .user-name-text {
    display: none;
  }

  .user-profile-badge {
    padding: 0.2rem;
    border-radius: var(--radius-full);
  }

  .user-profile-avatar {
    width: 24px;
    height: 24px;
  }

  .nav-link-btn {
    padding: 0.45rem;
    min-width: 36px;
    min-height: 36px;
    justify-content: center;
    border-radius: var(--radius-sm);
  }

  .icon-btn {
    width: 36px;
    height: 36px;
    min-width: 36px;
  }

  /* Touch-friendly inputs & prevention of iOS Safari auto-zoom */
  .form-input,
  .form-select,
  .form-textarea,
  .search-input {
    font-size: 16px !important;
    padding: 0.65rem 0.85rem;
  }

  .search-input {
    padding-left: 2.3rem;
  }

  /* Touch targets */
  .btn {
    min-height: 38px;
    padding: 0.5rem 0.85rem;
  }

  .btn-sm {
    min-height: 34px;
    padding: 0.35rem 0.65rem;
    font-size: 0.8rem;
  }

  /* Breadcrumbs with smooth touch scrolling */
  .breadcrumb-bar {
    padding: 0.4rem 0;
    font-size: 0.775rem;
  }

  .breadcrumb-container {
    padding: 0 0.85rem;
    gap: 0.35rem;
    -webkit-overflow-scrolling: touch;
  }

  /* Auth View on Mobile */
  .auth-wrapper {
    margin: 1rem auto;
    padding: 1.5rem 1rem;
    border: none;
    background: transparent;
    box-shadow: none;
  }

  .auth-title {
    font-size: 1.25rem;
  }

  /* Dashboard View on Mobile */
  .dashboard-banner {
    padding: 1.15rem 1rem;
    flex-direction: column;
    align-items: stretch;
    gap: 1rem;
    margin-bottom: 1.5rem;
  }

  .dashboard-banner-text h2 {
    font-size: 1.2rem;
    line-height: 1.35;
  }

  .dashboard-stats-strip {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    width: 100%;
    padding: 0.65rem 0.5rem;
    background-color: var(--bg-subtle);
    border-radius: var(--radius-md);
    border: 1px solid var(--border-subtle);
    border-top: 1px solid var(--border-subtle);
  }

  .stat-item {
    padding: 0 0.25rem;
    text-align: center;
    border-right: 1px solid var(--border-subtle);
  }

  .stat-item:last-child {
    border-right: none;
  }

  .stat-number {
    font-size: 1.2rem;
  }

  .stat-label {
    font-size: 0.65rem;
  }

  .section-title {
    font-size: 1.35rem;
  }

  /* 1-column responsive subjects */
  .subjects-grid {
    grid-template-columns: 1fr;
    gap: 0.85rem;
  }

  .subject-card {
    padding: 1.15rem;
    min-width: 0;
  }

  /* Subject View on Mobile */
  .subject-banner {
    padding: 1.15rem 1rem;
    flex-direction: column;
    align-items: stretch;
    gap: 0.85rem;
    margin-bottom: 1.25rem;
  }

  .subject-banner-info {
    width: 100%;
    gap: 0.75rem;
  }

  .subject-large-icon {
    width: 44px;
    height: 44px;
    font-size: 1.35rem;
    flex-shrink: 0;
  }

  .chapter-card {
    flex-direction: column;
    align-items: stretch;
    padding: 1rem;
    gap: 0.75rem;
  }

  .chapter-card-main {
    width: 100%;
    gap: 0.75rem;
  }

  .chapter-details h3 {
    font-size: 0.975rem;
  }

  .chapter-card-actions {
    width: 100%;
    justify-content: space-between;
    padding-top: 0.65rem;
    border-top: 1px solid var(--border-subtle);
  }

  /* Video View on Mobile */
  .video-top-nav {
    width: 100%;
    justify-content: space-between;
    align-items: center;
    gap: 0.4rem;
  }

  .chapter-nav-btns {
    gap: 0.35rem;
  }

  .video-player-container {
    border-radius: var(--radius-md);
  }

  .video-meta-bar {
    padding: 1rem;
    flex-direction: column;
    align-items: stretch;
    gap: 0.85rem;
  }

  .video-chapter-title {
    font-size: 1.15rem;
    line-height: 1.35;
  }

  #theater-mode-btn {
    display: none !important;
  }

  .video-meta-actions {
    width: 100%;
  }

  #scroll-to-notes-btn {
    width: 100%;
    justify-content: center;
    min-height: 38px;
  }

  .update-video-hint {
    font-size: 0.725rem;
    flex-wrap: wrap;
    line-height: 1.4;
  }

  /* Notes & School Work Section on Mobile */
  .notes-section-wrapper {
    padding: 1.15rem 0.85rem;
    margin-top: 1rem;
    border-radius: var(--radius-md);
  }

  .notes-section-header {
    flex-direction: column;
    align-items: stretch;
    gap: 0.85rem;
  }

  #open-upload-modal-btn {
    width: 100%;
    justify-content: center;
    min-height: 40px;
    font-size: 0.85rem;
  }

  .notes-tabs {
    display: flex;
    gap: 0.35rem;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 0.35rem;
    scrollbar-width: none;
  }

  .notes-tab-btn {
    flex-shrink: 0;
    padding: 0.45rem 0.75rem;
    font-size: 0.78rem;
    min-height: 36px;
  }

  .resources-grid {
    grid-template-columns: 1fr;
    gap: 0.85rem;
  }

  .resource-card {
    padding: 1rem;
    word-break: break-word;
    overflow-wrap: break-word;
    min-width: 0;
  }

  .resource-card-info h4 {
    font-size: 0.9rem;
  }

  .resource-card-footer {
    flex-wrap: wrap;
    gap: 0.5rem;
  }

  /* Mobile Bottom Sheet Modals */
  .modal-overlay {
    padding: 0;
    align-items: flex-end;
  }

  .modal-dialog {
    max-width: 100%;
    width: 100%;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    border-bottom: none;
    max-height: 86dvh;
    max-height: 86vh;
    padding: 1.25rem 1.15rem calc(1.25rem + var(--safe-bottom));
    animation: modalSheetUp 0.22s cubic-bezier(0.16, 1, 0.3, 1);
  }

  .modal-sheet-handle {
    display: block;
    width: 40px;
    height: 4px;
    background-color: var(--border-strong);
    border-radius: 9999px;
    margin: -0.35rem auto 1rem;
  }

  .modal-actions-footer {
    display: flex;
    gap: 0.5rem;
    margin-top: 1.25rem;
  }

  .modal-actions-footer button {
    flex: 1;
    min-height: 40px;
  }

  .dropzone-area {
    padding: 1.25rem 0.75rem;
  }

  /* Mobile Toast positioning above bottom nav */
  .toast-container {
    bottom: calc(var(--bottom-nav-height) + var(--safe-bottom) + 0.75rem);
    left: 1rem;
    right: 1rem;
    max-width: none;
    justify-content: center;
  }

  .toast {
    width: 100%;
    max-width: 420px;
    margin: 0 auto;
    justify-content: center;
  }
}

/* Modal Bottom Sheet Slide-Up Animation */
@keyframes modalSheetUp {
  from {
    transform: translateY(100%);
    opacity: 0.5;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

/* --- COMPACT PHONES (<= 480px: iPhone SE, Galaxy S) --- */
@media (max-width: 480px) {
  .brand-tag {
    display: none;
  }

  .nav-chapters-word {
    display: none;
  }

  .breadcrumb-container {
    font-size: 0.725rem;
  }

  .auth-wrapper {
    margin: 0.75rem auto;
    padding: 1.25rem 0.5rem;
  }

  .btn-google {
    font-size: 0.85rem;
    padding: 0.6rem 0.75rem;
  }
}

/* --- ULTRA-COMPACT / FOLDED SCREENS (<= 340px) --- */
@media (max-width: 340px) {
  .brand-title {
    font-size: 0.9rem;
  }

  .brand-logo-img-wrapper {
    width: 26px;
    height: 26px;
  }

  .modal-actions-footer {
    flex-direction: column-reverse;
  }

  .modal-actions-footer button {
    width: 100%;
  }

  .dashboard-banner-text h2 {
    font-size: 1.1rem;
  }

  .stat-number {
    font-size: 1.05rem;
  }

  .stat-label {
    font-size: 0.6rem;
  }
}
