/* =====================================================
   SchoolBuddy — CSS
   ===================================================== */

:root {
  --primary: #4f46e5;
  --primary-dark: #4338ca;
  --primary-light: #eef2ff;
  --success: #10b981;
  --success-light: #d1fae5;
  --danger: #ef4444;
  --danger-light: #fee2e2;
  --warning: #f59e0b;
  --bg: #f8f7ff;
  --surface: #ffffff;
  --border: #e5e7eb;
  --text: #1f2937;
  --text-dim: #6b7280;
  --radius: 12px;
  --shadow: 0 4px 24px rgba(79, 70, 229, 0.12);
  --font: 'Nunito', -apple-system, sans-serif;
}

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

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}

/* ---- Landing ---- */
#landing {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: linear-gradient(135deg, #eef2ff 0%, #fce7f3 50%, #fef3c7 100%);
}

.hero { text-align: center; margin-bottom: 32px; }

.logo {
  font-size: 72px;
  line-height: 1;
  margin-bottom: 16px;
  animation: bounce 2s ease-in-out infinite;
}

@keyframes bounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}

h1 {
  font-size: 40px;
  font-weight: 800;
  color: var(--primary);
  letter-spacing: -1px;
}

.tagline {
  color: var(--text-dim);
  font-size: 18px;
  margin-top: 8px;
}

/* ---- Auth Card ---- */
.auth-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 40px;
  width: 100%;
  max-width: 420px;
}

.auth-card h2 {
  font-size: 24px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 4px;
}

.subtitle {
  color: var(--text-dim);
  font-size: 14px;
  margin-bottom: 24px;
}

.step { animation: fadeIn 0.3s ease; }

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

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

.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 6px;
}

.hint { font-weight: 400; color: var(--text-dim); }

input[type="text"],
input[type="email"],
input[type="password"],
input[type="date"],
input[type="number"],
select {
  width: 100%;
  padding: 10px 14px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: 15px;
  font-family: var(--font);
  transition: border-color 0.2s, box-shadow 0.2s;
  background: var(--surface);
  color: var(--text);
}

input:focus, select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.15);
}

.error-msg {
  color: var(--danger);
  font-size: 13px;
  min-height: 18px;
  margin-bottom: 8px;
}

.auth-tabs {
  display: flex;
  gap: 0;
  margin-bottom: 20px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}

.auth-tab {
  flex: 1;
  padding: 10px 8px;
  border: none;
  background: transparent;
  color: var(--text-dim);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  border-radius: 0;
  transition: background 0.2s, color 0.2s;
  font-family: var(--font);
}

.auth-tab.active {
  background: var(--primary);
  color: white;
}

.auth-tab:not(.active):hover {
  background: rgba(79, 70, 229, 0.06);
  color: var(--text);
}

.magic-desc {
  font-size: 14px;
  color: var(--text-dim);
  margin-bottom: 16px;
  line-height: 1.5;
}

.success-msg {
  color: var(--success);
  font-size: 13px;
  margin-top: 8px;
}

/* ---- Buttons ---- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 20px;
  border: none;
  border-radius: 8px;
  font-size: 15px;
  font-weight: 600;
  font-family: var(--font);
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}

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

.btn-primary:hover { background: var(--primary-dark); transform: translateY(-1px); }
.btn-primary:active { transform: translateY(0); }
.btn-primary:disabled { opacity: 0.6; cursor: not-allowed; transform: none; }

.btn-ghost {
  background: transparent;
  color: var(--text-dim);
  padding: 6px 12px;
}

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

.btn-outline {
  background: transparent;
  border: 1.5px solid var(--border);
  color: var(--text);
}

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

.btn-sm { padding: 6px 14px; font-size: 13px; }
.btn-full { width: 100%; }

.link-btn {
  background: none;
  border: none;
  color: var(--primary);
  font-size: 13px;
  cursor: pointer;
  font-family: var(--font);
  margin-top: 12px;
  text-decoration: underline;
  text-decoration-style: dotted;
}

.link-btn:hover { color: var(--primary-dark); }

.auth-links {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 16px;
  text-align: center;
}

.auth-links a {
  color: var(--text-dim);
  font-size: 13px;
  text-decoration: none;
}

.auth-links a:hover { color: var(--primary); }

.child-access-link { margin-top: 16px; text-align: center; }

/* ---- Child Login Card ---- */
#child-login-card { text-align: center; }
.child-login-icon { font-size: 48px; margin-bottom: 8px; }

/* ---- PIN Gate Overlay ---- */
#pin-gate-overlay { position: fixed; inset: 0; z-index: 1000; display: flex; align-items: center; justify-content: center; }

/* ---- Child Dashboard ---- */
.child-dashboard { min-height: 100vh; background: var(--bg); }
.subject-section { margin-bottom: 32px; }
.subject-title { font-size: 18px; font-weight: 700; color: var(--text); margin-bottom: 12px; padding-left: 4px; }
.books-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 16px; }
.book-card { background: var(--surface); border-radius: var(--radius); padding: 16px; cursor: pointer; transition: transform 0.15s, box-shadow 0.15s; }
.book-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.book-cover { height: 80px; border-radius: 8px; display: flex; align-items: center; justify-content: center; margin-bottom: 8px; font-size: 32px; color: white; overflow: hidden; }
.book-cover img { width: 100%; height: 100%; object-fit: cover; }
.book-info h4 { font-size: 14px; font-weight: 700; margin-bottom: 4px; }
.book-progress { font-size: 11px; color: var(--text-dim); margin-bottom: 6px; }
.loading-state { text-align: center; padding: 40px; color: var(--text-dim); }

/* ---- OTP ---- */
.otp-info {
  background: var(--primary-light);
  border-radius: 8px;
  padding: 14px;
  text-align: center;
  font-size: 14px;
  margin-bottom: 20px;
}

.otp-inputs {
  display: flex;
  gap: 8px;
  justify-content: center;
  margin-bottom: 16px;
}

.otp-digit {
  width: 48px;
  height: 56px;
  text-align: center;
  font-size: 22px;
  font-weight: 700;
  border: 2px solid var(--border);
  border-radius: 10px;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.otp-digit:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.15);
}

.remember-row {
  margin-bottom: 16px;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-dim);
  cursor: pointer;
}

input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--primary);
}

/* ---- Invite Card ---- */
.invite-icon { font-size: 48px; text-align: center; margin-bottom: 12px; }
.invite-header { text-align: center; margin-bottom: 24px; }

/* ---- Dashboard ---- */
#dashboard { min-height: 100vh; }

.dash-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 12px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 10;
}

.dash-logo {
  font-size: 20px;
  font-weight: 800;
  color: var(--primary);
}

.dash-logo span { color: var(--text); }

.dash-user {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 13px;
  color: var(--text-dim);
}

.dash-content {
  max-width: 800px;
  margin: 0 auto;
  padding: 24px;
}

.welcome-banner {
  background: linear-gradient(135deg, var(--primary) 0%, #7c3aed 100%);
  color: white;
  border-radius: var(--radius);
  padding: 24px 28px;
  margin-bottom: 28px;
}

.welcome-banner h2 { font-size: 20px; margin-bottom: 4px; }
.welcome-banner p { opacity: 0.85; font-size: 14px; }

.section { margin-bottom: 32px; }

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.section h3 {
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
}

/* ---- Children Grid ---- */
.children-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
}

.child-card {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  cursor: pointer;
  transition: all 0.2s;
  position: relative;
  overflow: hidden;
}

.child-card:hover {
  border-color: var(--primary);
  box-shadow: var(--shadow);
  transform: translateY(-2px);
}

.child-avatar {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--primary-light);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  margin-bottom: 12px;
}

.child-card h4 { font-size: 16px; font-weight: 700; }
.child-card .grade { font-size: 12px; color: var(--text-dim); margin-bottom: 10px; }

.child-progress-bar {
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
}

.child-progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), #10b981);
  border-radius: 3px;
  transition: width 0.5s ease;
}

.child-meta {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--text-dim);
  margin-top: 6px;
}

/* ---- Settings ---- */
.settings-card {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.setting-row:last-child { border-bottom: none; }

.setting-label { font-weight: 600; font-size: 14px; }
.setting-value { font-size: 13px; color: var(--text-dim); margin-top: 2px; }

/* ---- Empty State ---- */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  background: var(--surface);
  border: 2px dashed var(--border);
  border-radius: var(--radius);
}

.empty-icon { font-size: 48px; margin-bottom: 12px; }
.empty-state p { color: var(--text-dim); margin-bottom: 16px; }

/* ---- Modal ---- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.4);
  backdrop-filter: blur(4px);
}

.modal-content {
  position: relative;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: 0 20px 60px rgba(0,0,0,0.2);
  width: 100%;
  max-width: 460px;
  animation: modalIn 0.3s ease;
}

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

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
}

.modal-header h3 { font-size: 18px; font-weight: 700; }

.modal-close {
  background: none;
  border: none;
  font-size: 18px;
  cursor: pointer;
  color: var(--text-dim);
  padding: 4px;
}

.modal-body { padding: 24px; }

/* ---- Toast ---- */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: var(--text);
  color: white;
  padding: 12px 24px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  box-shadow: 0 4px 20px rgba(0,0,0,0.2);
  z-index: 9999;
  transition: transform 0.3s ease;
  pointer-events: none;
  max-width: 90vw;
  text-align: center;
}

.toast.show { transform: translateX(-50%) translateY(0); }
.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }

/* ---- Spinner ---- */
.spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

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

/* ---- Utility ---- */
.hidden { display: none !important; }

/* ---- Responsive ---- */
@media (max-width: 600px) {
  h1 { font-size: 32px; }
  .auth-card { padding: 28px 24px; }
  .dash-content { padding: 16px; }
  .children-grid { grid-template-columns: 1fr; }
}

/* ---- Service Worker ---- */
.iframe-placeholder { display: none; }