/* ============================================================
   Study Portal -- Global styles (mobile-first)
   ============================================================ */

:root {
  --physics:   #4A90D9;
  --chemistry: #7B68EE;
  --maths:     #50C878;
  --ip:        #FF8C00;
  --english:   #DC143C;

  --success:   #27AE60;
  --good:      #3498DB;
  --warning:   #F39C12;
  --danger:    #E74C3C;

  --bg:        #F8F9FA;
  --surface:   #FFFFFF;
  --text:      #212529;
  --muted:     #6C757D;
  --border:    #DEE2E6;
}

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

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.6;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

a { color: var(--good); text-decoration: none; }
a:hover { text-decoration: underline; }

h1 { font-size: 1.6rem; margin-bottom: 0.75rem; }
h2 { font-size: 1.3rem; margin: 1.25rem 0 0.5rem; }
h3 { font-size: 1.1rem; margin: 1rem 0 0.4rem; }

ul, ol { margin: 0.4rem 0 0.8rem 1.25rem; }
strong { color: var(--text); }

/* ---------- Layout ---------- */

.page-main {
  max-width: 760px;
  margin: 0 auto;
  padding: 16px;
  padding-bottom: 90px; /* room for bottom nav on mobile */
  min-height: calc(100vh - 120px);
}

.role-admin .page-main { padding-bottom: 32px; }

.page-footer {
  text-align: center;
  padding: 16px;
  color: var(--muted);
  font-size: 0.85rem;
  padding-bottom: 90px; /* room for bottom nav on mobile */
}

.role-admin .page-footer { padding-bottom: 16px; }

/* ---------- Student header (mobile) ---------- */

.student-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 12px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 50;
}
.student-header-brand { font-weight: 700; font-size: 1.05rem; }
.student-header-logout {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 48px;
  min-height: 48px;
  font-size: 1.3rem;
  color: var(--muted);
}

/* ---------- Student bottom nav ---------- */

.student-bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 64px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  z-index: 100;
  box-shadow: 0 -2px 10px rgba(0,0,0,0.04);
}
.student-bottom-nav-tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 500;
  text-decoration: none;
}
.student-bottom-nav-tab:hover { text-decoration: none; }
.student-bottom-nav-tab.active { color: var(--good); font-weight: 700; }
.student-bottom-nav-icon { font-size: 1.3rem; line-height: 1; margin-bottom: 2px; }

/* ---------- Admin header + nav ---------- */

.admin-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 12px 16px;
  position: sticky;
  top: 0;
  z-index: 50;
}
.admin-header-brand { font-weight: 700; font-size: 1.1rem; margin-bottom: 10px; }

.admin-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.admin-nav-link {
  display: inline-block;
  padding: 10px 14px;
  min-height: 48px;
  line-height: 28px;
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 500;
  white-space: nowrap;
}
.admin-nav-link:hover { background: var(--border); text-decoration: none; }
.admin-nav-link.active { background: var(--good); color: #fff; }

/* ---------- Forms ---------- */

.form-group { margin-bottom: 16px; }
.form-group label {
  display: block;
  font-size: 0.9rem;
  font-weight: 600;
  margin-bottom: 8px;
  color: var(--text);
}
.form-group input,
.form-group select,
.form-group textarea {
  display: block;
  width: 100%;
  height: 48px;
  padding: 0 16px;
  font-size: 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
}
.form-group textarea { min-height: 120px; padding: 12px 16px; resize: vertical; }
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: 2px solid var(--good);
  outline-offset: 0;
  border-color: var(--good);
}

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 12px 20px;
  border: none;
  border-radius: 8px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  font-family: inherit;
  transition: background 0.15s, opacity 0.15s;
}
.btn:hover { text-decoration: none; opacity: 0.92; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; cursor: default; }

.btn-primary { background: var(--success); color: #fff; }
.btn-primary:hover { background: #1f8a4c; }

.btn-good { background: var(--good); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-warning { background: var(--warning); color: #fff; }

.btn-outline {
  background: transparent;
  border: 2px solid var(--good);
  color: var(--good);
}
.btn-outline.danger { border-color: var(--danger); color: var(--danger); }

.btn-full { width: 100%; }
.btn-small { min-height: 36px; padding: 6px 12px; font-size: 14px; }

/* ---------- Cards ---------- */

.card {
  background: var(--surface);
  border-radius: 12px;
  padding: 16px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
  margin-bottom: 16px;
}
.card h2, .card h3 { margin-top: 0; }

/* ---------- Status badges ---------- */

.badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  vertical-align: middle;
}

.status-pending    { background: #E0E0E0; color: #495057; }
.status-generating { background: var(--good); color: #fff; animation: pulse 1.8s ease-in-out infinite; }
.status-ready      { background: var(--success); color: #fff; }
.status-error      { background: var(--danger); color: #fff; }
.status-done       { background: var(--success); color: #fff; }
.status-in_progress{ background: var(--good); color: #fff; }
.status-queued     { background: #E0E0E0; color: #495057; }
.status-analysed   { background: var(--success); color: #fff; }
.status-processing { background: var(--good); color: #fff; animation: pulse 1.8s ease-in-out infinite; }

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

/* ---------- Subject color classes ---------- */

.subject-physics   { background: var(--physics);   color: #fff; }
.subject-chemistry { background: var(--chemistry); color: #fff; }
.subject-maths     { background: var(--maths);     color: #fff; }
.subject-ip        { background: var(--ip);        color: #fff; }
.subject-english   { background: var(--english);   color: #fff; }

.subject-border-physics   { border-left: 6px solid var(--physics); }
.subject-border-chemistry { border-left: 6px solid var(--chemistry); }
.subject-border-maths     { border-left: 6px solid var(--maths); }
.subject-border-ip        { border-left: 6px solid var(--ip); }
.subject-border-english   { border-left: 6px solid var(--english); }

/* ---------- Difficulty badges ---------- */

.diff-board-basic       { background: #C8E6C9; color: #1B5E20; }
.diff-board-application { background: #FFF9C4; color: #F57F17; }
.diff-jee-mains         { background: #FFE0B2; color: #E65100; }
.diff-jee-advanced      { background: #FFCDD2; color: #B71C1C; }

/* ---------- Urgency badges (schedule) ---------- */

.urgency-red    { background: var(--danger);  color: #fff; }
.urgency-orange { background: var(--warning); color: #fff; }
.urgency-green  { background: var(--success); color: #fff; }

/* ---------- Admin tables ---------- */

.table-wrap {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--surface);
  border-radius: 12px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
  margin-bottom: 16px;
}
table.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
  min-width: 640px;
}
.admin-table th,
.admin-table td {
  padding: 12px 14px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.admin-table th {
  background: var(--bg);
  font-weight: 700;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}
.admin-table tbody tr:nth-child(even) { background: #FAFBFC; }
.admin-table tbody tr:hover { background: #F1F3F5; }

/* ---------- Alerts ---------- */

.alert {
  padding: 12px 16px;
  border-radius: 8px;
  margin-bottom: 16px;
  font-size: 0.95rem;
}
.alert-success { background: #D4EDDA; color: #155724; border-left: 4px solid var(--success); }
.alert-warning { background: #FFF3CD; color: #856404; border-left: 4px solid var(--warning); }
.alert-danger  { background: #F8D7DA; color: #721C24; border-left: 4px solid var(--danger); }
.alert-info    { background: #D1ECF1; color: #0C5460; border-left: 4px solid var(--good); }

/* ---------- Login ---------- */

.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  padding: 32px 24px;
  border-radius: 12px;
  box-shadow: 0 6px 24px rgba(0,0,0,0.1);
}
.login-card h1 {
  text-align: center;
  margin-bottom: 8px;
  color: var(--text);
}
.login-card p.login-sub {
  text-align: center;
  color: var(--muted);
  font-size: 0.9rem;
  margin-bottom: 24px;
}

/* ---------- Toasts ---------- */

#toast-container {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 9999;
  pointer-events: none;
  width: calc(100% - 32px);
  max-width: 420px;
}
.toast {
  background: var(--text);
  color: #fff;
  padding: 12px 18px;
  border-radius: 8px;
  margin-bottom: 8px;
  font-size: 0.95rem;
  box-shadow: 0 4px 16px rgba(0,0,0,0.2);
  animation: toastIn 0.25s ease-out;
  pointer-events: auto;
}
.toast.toast-success { background: var(--success); }
.toast.toast-error   { background: var(--danger); }
.toast.toast-info    { background: var(--good); }
@keyframes toastIn {
  from { opacity: 0; transform: translateY(-12px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ---------- Modal (custom confirm) ---------- */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9000;
  padding: 16px;
}
.modal-panel {
  background: var(--surface);
  border-radius: 12px;
  padding: 24px;
  max-width: 420px;
  width: 100%;
  box-shadow: 0 10px 40px rgba(0,0,0,0.3);
}
.modal-panel h3 { margin-top: 0; }
.modal-panel .modal-actions {
  display: flex;
  gap: 8px;
  margin-top: 20px;
}
.modal-panel .modal-actions .btn { flex: 1; }

/* ---------- Utility ---------- */

.muted { color: var(--muted); }
.text-center { text-align: center; }
.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.mt-3 { margin-top: 24px; }
.mb-1 { margin-bottom: 8px; }
.mb-2 { margin-bottom: 16px; }
.mb-3 { margin-bottom: 24px; }
.flex { display: flex; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.gap-1 { gap: 8px; }
.gap-2 { gap: 16px; }
.hidden { display: none !important; }

/* ---------- Desktop / large screens ---------- */

@media (min-width: 768px) {
  .page-main { padding: 24px; padding-bottom: 90px; }
  h1 { font-size: 2rem; }
  h2 { font-size: 1.5rem; }
}

@media (min-width: 1024px) {
  .page-main { padding-bottom: 32px; }
  .role-student .student-bottom-nav { display: flex; } /* keep bottom nav on desktop too */
  .role-student .page-footer { padding-bottom: 90px; }
}

/* ============================================================
   Study page -- immersive single-module view
   ============================================================ */
.role-study { padding: 0; margin: 0; background: var(--bg); }
.role-study main.page-main { padding: 0; }

/* Fixed top bar (60px) */
.study-top-bar {
  position: fixed; top: 0; left: 0; right: 0;
  height: 60px;
  display: flex; align-items: center;
  padding: 0 12px;
  color: #fff;
  z-index: 200;
  /* background is inlined per subject */
}
.study-top-bar-back {
  flex: 0 0 auto;
  min-width: 48px; height: 48px;
  display: inline-flex; align-items: center; justify-content: center;
  color: #fff; font-size: 1.4rem; text-decoration: none;
  border-radius: 6px;
}
.study-top-bar-back:hover { background: rgba(255,255,255,0.12); text-decoration: none; }
.study-top-bar-center {
  flex: 1 1 auto; min-width: 0;
  text-align: center;
  font-size: 0.95rem; font-weight: 500;
  padding: 0 6px;
  overflow: hidden;
}
.study-top-bar-subject { opacity: 0.9; }
.study-top-bar-sep { margin: 0 6px; opacity: 0.55; }
.study-top-bar-chapter {
  display: inline-block;
  max-width: 20ch;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  vertical-align: bottom;
}
.study-top-bar-right {
  flex: 0 0 auto;
  font-size: 0.82rem;
  padding: 0 6px;
  white-space: nowrap;
}

/* Progress bar (6px) directly under top bar */
.study-progress-bar {
  position: fixed; top: 60px; left: 0; right: 0;
  height: 6px;
  background: var(--border);
  z-index: 199;
}
.study-progress-fill {
  height: 100%;
  opacity: 0.8;
  transition: width 0.4s ease;
  /* background set inline */
}

/* Scrollable content area */
.study-content-area {
  padding-top: 80px;   /* 60 top-bar + 6 progress + 14 breathing */
  padding-bottom: 150px;
  padding-left: 16px;
  padding-right: 16px;
  min-height: 100vh;
}
.study-content {
  max-width: 800px;
  margin: 0 auto;
}
.study-content .module {
  display: block !important;
}

/* Fixed action bar (70px) -- sits above the 60px bottom nav */
.study-action-bar {
  position: fixed; left: 0; right: 0;
  bottom: 60px;
  height: 70px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex; flex-direction: column; justify-content: center;
  padding: 4px 12px 6px;
  z-index: 150;
}
.study-skips-remaining {
  font-size: 0.72rem; color: var(--muted);
  text-align: center; margin-bottom: 4px;
}
.study-action-buttons {
  display: flex; gap: 8px; align-items: stretch;
}
.btn-skip {
  flex: 1;
  min-height: 44px;
  background: transparent;
  border: 2px solid var(--study-subject-color, var(--muted));
  color: var(--study-subject-color, var(--muted));
  border-radius: 8px;
  font-size: 0.78rem; font-weight: 600;
  cursor: pointer;
  padding: 8px 4px;
}
.btn-skip:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-skip:active { transform: translateY(1px); }
.btn-mark-complete-study {
  flex: 1.4;
  min-height: 44px;
  background: var(--study-subject-color, var(--success));
  color: #fff;
  border: none; border-radius: 8px;
  font-size: 0.95rem; font-weight: 700;
  cursor: pointer;
  padding: 8px 4px;
}
.btn-mark-complete-study:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-mark-complete-study:active { transform: translateY(1px); }

/* Error state shown if module cannot be loaded */
.study-error {
  max-width: 480px; margin: 80px auto 0;
  padding: 24px; text-align: center;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px;
}
.study-error h2 { margin-bottom: 12px; color: var(--danger); }

/* On study page, keep the student bottom nav visible above the action bar */
.role-study .student-bottom-nav { z-index: 140; }

@media (max-width: 360px) {
  .study-top-bar { padding: 0 8px; }
  .study-top-bar-center { font-size: 0.85rem; }
  .study-top-bar-right { font-size: 0.72rem; }
  .btn-skip { font-size: 0.68rem; }
  .btn-mark-complete-study { font-size: 0.85rem; }
}
@media (min-width: 768px) {
  .study-top-bar-chapter { max-width: 40ch; }
}

/* ============================================================
   "A Note For You" tab -- smaller, slightly muted, heart icon
   ============================================================ */
.student-bottom-nav-tab[href="/note"] {
  font-size: 0.7rem;
  opacity: 0.75;
}
.student-bottom-nav-tab[href="/note"] .student-bottom-nav-icon {
  font-size: 1.05rem;
}
.student-bottom-nav-tab[href="/note"].active {
  opacity: 1;
}
.student-bottom-nav-tab[href="/note"] .student-bottom-nav-label {
  /* Long label -- ensure it fits on narrow screens */
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 9ch;
}
