/* principal.css — Principal & District Admin Dashboard styles
 * Scoped under .p-* prefix to avoid collision with teacher.css
 */

:root {
  --p-bg: #0f1117;
  --p-surface: #1a1f2e;
  --p-surface-hover: #222840;
  --p-border: #2a3050;
  --p-border-light: #1e2640;
  --p-text: #e2e8f0;
  --p-text-muted: #64748b;
  --p-text-dim: #94a3b8;
  --p-accent: #00d4ff;
  --p-accent-district: #f59e0b;
  --p-green: #22c55e;
  --p-amber: #f59e0b;
  --p-red: #ef4444;
  --p-radius: 10px;
  --p-nav-height: 64px;
}

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

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--p-bg);
  color: var(--p-text);
  min-height: 100vh;
  font-size: 14px;
  line-height: 1.5;
}

/* ── Nav ──────────────────────────────────────────────────────────────────── */

.p-nav {
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--p-nav-height);
  background: rgba(15,17,23,0.95);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--p-border);
}

.p-nav--district { border-bottom-color: rgba(245,158,11,0.3); }

.p-nav-inner {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 24px;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.p-nav-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--p-text);
  font-weight: 700;
  font-size: 16px;
  flex-shrink: 0;
}

.p-brand-icon { font-size: 20px; }
.p-nav-sub { font-size: 11px; font-weight: 500; color: var(--p-accent); background: rgba(0,212,255,0.1); padding: 2px 8px; border-radius: 20px; }
.p-nav--district .p-nav-sub { color: var(--p-accent-district); background: rgba(245,158,11,0.12); }

.p-nav-right {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.p-nav-school {
  font-size: 13px;
  color: var(--p-text-dim);
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.p-school-code-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(34,197,94,0.1);
  border: 1px solid rgba(34,197,94,0.3);
  border-radius: 6px;
  padding: 4px 10px;
}

.p-school-code-badge--district {
  background: rgba(245,158,11,0.1);
  border-color: rgba(245,158,11,0.3);
}

.p-code-label { font-size: 10px; color: var(--p-text-muted); text-transform: uppercase; letter-spacing: 0.5px; }
.p-code-val { font-family: 'Courier New', monospace; font-weight: 700; font-size: 13px; color: var(--p-green); letter-spacing: 1px; }
.p-school-code-badge--district .p-code-val { color: var(--p-accent-district); }

.p-copy-btn {
  background: none;
  border: none;
  color: var(--p-accent);
  cursor: pointer;
  font-size: 11px;
  padding: 2px 6px;
  border-radius: 4px;
  transition: background 0.15s;
}
.p-copy-btn:hover { background: rgba(0,212,255,0.1); }

.p-btn-report, .p-btn-logout, .p-btn-secondary {
  display: inline-flex;
  align-items: center;
  padding: 7px 14px;
  border-radius: 7px;
  font-size: 13px;
  font-weight: 500;
  text-decoration: none;
  transition: all 0.15s;
  white-space: nowrap;
}

.p-btn-report {
  background: rgba(0,212,255,0.1);
  border: 1px solid rgba(0,212,255,0.3);
  color: var(--p-accent);
}
.p-btn-report:hover { background: rgba(0,212,255,0.2); }
.p-btn-report--district {
  background: rgba(245,158,11,0.1);
  border-color: rgba(245,158,11,0.3);
  color: var(--p-accent-district);
}
.p-btn-report--district:hover { background: rgba(245,158,11,0.2); }

.p-btn-logout {
  background: rgba(239,68,68,0.08);
  border: 1px solid rgba(239,68,68,0.2);
  color: #f87171;
}
.p-btn-logout:hover { background: rgba(239,68,68,0.15); }

.p-btn-secondary {
  background: var(--p-surface);
  border: 1px solid var(--p-border);
  color: var(--p-text-dim);
}
.p-btn-secondary:hover { border-color: var(--p-accent); color: var(--p-accent); }

/* ── Main layout ──────────────────────────────────────────────────────────── */

.p-main { padding: 32px 0 80px; }
.p-container { max-width: 1400px; margin: 0 auto; padding: 0 24px; }

/* ── Page header ──────────────────────────────────────────────────────────── */

.p-page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 28px;
}

.p-page-title { font-size: 26px; font-weight: 800; color: var(--p-text); }
.p-page-sub { color: var(--p-text-muted); font-size: 13px; margin-top: 4px; }
.p-school-code-inline { font-family: monospace; background: rgba(34,197,94,0.1); color: var(--p-green); padding: 1px 6px; border-radius: 4px; font-size: 12px; }
.p-breadcrumb { font-size: 12px; color: var(--p-text-muted); margin-bottom: 6px; }
.p-breadcrumb a { color: var(--p-accent); text-decoration: none; }
.p-breadcrumb a:hover { text-decoration: underline; }
.p-read-only-badge { background: rgba(100,116,139,0.2); color: var(--p-text-muted); padding: 2px 8px; border-radius: 4px; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px; }

.p-header-actions { display: flex; gap: 10px; align-items: center; flex-shrink: 0; }

/* ── Buttons ──────────────────────────────────────────────────────────────── */

.p-btn-primary, .p-btn-district {
  display: inline-flex;
  align-items: center;
  padding: 10px 20px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  border: none;
  transition: all 0.15s;
  white-space: nowrap;
}

.p-btn-primary {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
}
.p-btn-primary:hover { opacity: 0.9; transform: translateY(-1px); }

.p-btn-district {
  background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
  color: white;
}
.p-btn-district:hover { opacity: 0.9; transform: translateY(-1px); }

.p-btn-full { width: 100%; justify-content: center; }
.p-btn-sm { padding: 6px 12px; font-size: 12px; background: var(--p-surface); border: 1px solid var(--p-border); color: var(--p-text-dim); border-radius: 6px; cursor: pointer; white-space: nowrap; }
.p-btn-sm:hover { border-color: var(--p-accent); color: var(--p-accent); }

/* ── Metric cards ─────────────────────────────────────────────────────────── */

.p-metrics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 16px;
  margin-bottom: 28px;
}

.p-metrics-grid--5 { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }

.p-metric-card {
  background: var(--p-surface);
  border: 1px solid var(--p-border);
  border-radius: var(--p-radius);
  padding: 20px;
  transition: border-color 0.15s;
}
.p-metric-card:hover { border-color: rgba(0,212,255,0.3); }

.p-metric-icon { font-size: 24px; margin-bottom: 10px; }
.p-metric-val { font-size: 32px; font-weight: 800; color: var(--p-text); line-height: 1; }
.p-metric-label { font-size: 12px; color: var(--p-text-muted); margin-top: 6px; text-transform: uppercase; letter-spacing: 0.5px; }
.p-metric-delta { font-size: 11px; margin-top: 6px; font-weight: 600; }
.p-metric-delta--up { color: var(--p-green); }
.p-metric-delta--down { color: var(--p-red); }

/* ── Sections ─────────────────────────────────────────────────────────────── */

.p-section {
  background: var(--p-surface);
  border: 1px solid var(--p-border);
  border-radius: var(--p-radius);
  padding: 24px;
  margin-bottom: 24px;
}

.p-section-header {
  display: flex;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 18px;
}
.p-section-header h2 { font-size: 16px; font-weight: 700; color: var(--p-text); }
.p-section-meta { font-size: 12px; color: var(--p-text-muted); }

.p-two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
  margin-bottom: 24px;
}

@media (max-width: 900px) { .p-two-col { grid-template-columns: 1fr; } }

.p-section--chart .p-chart-wrap { height: 220px; }

/* ── Table ────────────────────────────────────────────────────────────────── */

.p-table-wrap { overflow-x: auto; }

.p-table {
  width: 100%;
  border-collapse: collapse;
}

.p-table th {
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  color: var(--p-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--p-border);
}

.p-table td {
  padding: 12px;
  border-bottom: 1px solid var(--p-border-light);
  color: var(--p-text);
  font-size: 13px;
}

.p-table tbody tr:last-child td { border-bottom: none; }
.p-table-row-link { cursor: pointer; transition: background 0.12s; }
.p-table-row-link:hover { background: var(--p-surface-hover); }

.p-th-num, .p-td-num { text-align: right; }
.p-muted { color: var(--p-text-muted); font-size: 12px; }
.p-td-teacher { font-weight: 600; }

.p-join-code {
  font-family: 'Courier New', monospace;
  font-size: 12px;
  background: rgba(0,212,255,0.07);
  color: var(--p-accent);
  padding: 2px 6px;
  border-radius: 4px;
  letter-spacing: 1px;
}

/* ── Accuracy chips ───────────────────────────────────────────────────────── */

.p-accuracy-chip {
  display: inline-flex;
  align-items: center;
  padding: 3px 8px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 700;
}
.p-accuracy-chip--green { background: rgba(34,197,94,0.15); color: #4ade80; }
.p-accuracy-chip--amber { background: rgba(245,158,11,0.15); color: #fbbf24; }
.p-accuracy-chip--red { background: rgba(239,68,68,0.15); color: #f87171; }

/* ── Leaderboard ──────────────────────────────────────────────────────────── */

.p-leaderboard {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.p-leaderboard-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  background: rgba(255,255,255,0.02);
  border: 1px solid var(--p-border-light);
  border-radius: 8px;
  transition: border-color 0.12s;
}
.p-leaderboard-row:hover { border-color: rgba(0,212,255,0.2); }

.p-medal { font-size: 18px; min-width: 28px; text-align: center; }
.p-leaderboard-info { flex: 1; min-width: 0; }
.p-hero-name { font-weight: 600; font-size: 13px; color: var(--p-text); }
.p-classroom-tag { display: block; font-size: 11px; color: var(--p-text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.p-leaderboard-stats { text-align: right; flex-shrink: 0; }
.p-xp { display: block; font-weight: 700; font-size: 13px; color: var(--p-accent); }
.p-missions-done { font-size: 11px; color: var(--p-text-muted); }

/* ── Heat map ─────────────────────────────────────────────────────────────── */

.p-section--heatmap .p-section-meta { font-size: 11px; }
.p-heatmap-scroll { overflow-x: auto; }

.p-heatmap-table {
  border-collapse: collapse;
  font-size: 11px;
  min-width: 500px;
}

.p-hm-mission-col { width: 200px; min-width: 160px; }
.p-hm-classroom-col { min-width: 80px; text-align: center; font-size: 10px; color: var(--p-text-muted); padding: 6px 4px; }
.p-hm-mission-label { padding: 6px 8px 6px 0; color: var(--p-text-dim); font-size: 11px; white-space: nowrap; }

.p-hm-cell {
  text-align: center;
  padding: 5px 4px;
  font-weight: 600;
  font-size: 11px;
  border: 1px solid rgba(255,255,255,0.03);
}
.p-hm-cell--green { background: rgba(34,197,94,0.25); color: #4ade80; }
.p-hm-cell--amber { background: rgba(245,158,11,0.2); color: #fbbf24; }
.p-hm-cell--red { background: rgba(239,68,68,0.2); color: #f87171; }
.p-hm-cell--empty { background: transparent; color: transparent; }

/* ── Callout ──────────────────────────────────────────────────────────────── */

.p-callout {
  display: flex;
  align-items: center;
  gap: 14px;
  background: rgba(0,212,255,0.06);
  border: 1px solid rgba(0,212,255,0.2);
  border-radius: var(--p-radius);
  padding: 16px 20px;
  margin-bottom: 24px;
}
.p-callout--district {
  background: rgba(245,158,11,0.06);
  border-color: rgba(245,158,11,0.2);
}
.p-callout-icon { font-size: 22px; flex-shrink: 0; }
.p-callout-body { flex: 1; font-size: 13px; color: var(--p-text-dim); }
.p-code-inline { font-family: monospace; background: rgba(34,197,94,0.12); color: var(--p-green); padding: 2px 8px; border-radius: 4px; font-weight: 700; font-size: 13px; letter-spacing: 1px; }

/* ── Empty state ──────────────────────────────────────────────────────────── */

.p-empty-state {
  text-align: center;
  padding: 48px 24px;
}
.p-empty-state--sm { padding: 24px; }
.p-empty-icon { font-size: 40px; margin-bottom: 12px; }
.p-empty-state h3 { font-size: 16px; color: var(--p-text); margin-bottom: 8px; }
.p-empty-state p { font-size: 13px; color: var(--p-text-muted); max-width: 400px; margin: 0 auto; line-height: 1.6; }

/* ── Activity feed ────────────────────────────────────────────────────────── */

.p-activity-feed { list-style: none; display: flex; flex-direction: column; gap: 8px; }
.p-activity-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  background: rgba(255,255,255,0.02);
  border-radius: 6px;
  font-size: 12px;
}
.p-activity-icon { font-size: 14px; flex-shrink: 0; }
.p-activity-body { flex: 1; color: var(--p-text-dim); }
.p-activity-body .p-hero-name { font-size: 12px; }
.p-activity-time { font-size: 11px; color: var(--p-text-muted); flex-shrink: 0; }
.p-score-tag { background: rgba(34,197,94,0.15); color: #4ade80; padding: 1px 6px; border-radius: 4px; font-size: 11px; margin-left: 4px; }

/* ── Engagement bar ───────────────────────────────────────────────────────── */

.p-engagement-bar {
  width: 80px;
  height: 6px;
  background: var(--p-border);
  border-radius: 3px;
  overflow: hidden;
  display: inline-block;
  vertical-align: middle;
  margin-right: 6px;
}
.p-engagement-fill { height: 100%; background: linear-gradient(90deg, #667eea, #00d4ff); border-radius: 3px; }

/* ── Auth pages ───────────────────────────────────────────────────────────── */

.p-auth-page {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 1fr 1fr;
  align-items: stretch;
}

.p-auth-page--login { grid-template-columns: 1fr; align-items: center; justify-items: center; }
.p-auth-page--login .p-auth-card { width: 100%; max-width: 460px; margin: 40px auto; }

.p-auth-card {
  padding: 48px 40px;
  display: flex;
  flex-direction: column;
  gap: 24px;
  justify-content: center;
  max-width: 520px;
  margin: 0 auto;
  width: 100%;
}

.p-auth-card--narrow { max-width: 420px; }

.p-auth-header { text-align: center; }
.p-auth-icon {
  width: 64px; height: 64px;
  background: linear-gradient(135deg, rgba(102,126,234,0.3), rgba(118,75,162,0.3));
  border-radius: 16px;
  display: flex; align-items: center; justify-content: center;
  font-size: 32px;
  margin: 0 auto 16px;
  border: 1px solid rgba(102,126,234,0.4);
}
.p-auth-icon--district {
  background: linear-gradient(135deg, rgba(245,158,11,0.2), rgba(217,119,6,0.2));
  border-color: rgba(245,158,11,0.3);
}
.p-auth-header h1 { font-size: 24px; font-weight: 800; color: var(--p-text); }
.p-auth-header p { font-size: 14px; color: var(--p-text-muted); margin-top: 6px; }

.p-auth-aside {
  background: linear-gradient(135deg, #1a1f2e 0%, #0f1117 100%);
  border-left: 1px solid var(--p-border);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 48px 40px;
}
.p-auth-aside--district { border-left-color: rgba(245,158,11,0.2); }

.p-aside-inner { max-width: 400px; }
.p-aside-inner h2 { font-size: 20px; font-weight: 700; color: var(--p-text); margin-bottom: 20px; }
.p-feature-list { list-style: none; display: flex; flex-direction: column; gap: 12px; margin-bottom: 32px; }
.p-feature-list li { display: flex; gap: 10px; align-items: flex-start; font-size: 14px; color: var(--p-text-dim); line-height: 1.5; }
.p-aside-quote { background: rgba(255,255,255,0.04); border-left: 3px solid var(--p-accent); padding: 16px 20px; border-radius: 0 8px 8px 0; }
.p-auth-aside--district .p-aside-quote { border-left-color: var(--p-accent-district); }
.p-aside-quote blockquote { font-style: italic; font-size: 14px; color: var(--p-text-dim); margin: 0 0 8px; line-height: 1.6; }
.p-aside-quote cite { font-size: 12px; color: var(--p-text-muted); font-style: normal; }

.p-auth-footer { text-align: center; }
.p-auth-footer p { font-size: 13px; color: var(--p-text-muted); margin-bottom: 6px; }
.p-auth-footer a { color: var(--p-accent); text-decoration: none; }
.p-auth-footer a:hover { text-decoration: underline; }

/* ── Form ─────────────────────────────────────────────────────────────────── */

.p-form { display: flex; flex-direction: column; gap: 16px; }
.p-form-group { display: flex; flex-direction: column; gap: 6px; }
.p-form-group label { font-size: 13px; font-weight: 500; color: var(--p-text-dim); }
.p-label-opt { font-weight: 400; color: var(--p-text-muted); }

.p-form-group input {
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--p-border);
  border-radius: 8px;
  padding: 10px 14px;
  color: var(--p-text);
  font-size: 14px;
  font-family: inherit;
  transition: border-color 0.15s;
  outline: none;
  width: 100%;
}
.p-form-group input:focus { border-color: var(--p-accent); background: rgba(0,212,255,0.04); }
.p-form-group input::placeholder { color: var(--p-text-muted); }

.p-auth-page--district .p-form-group input:focus { border-color: var(--p-accent-district); }

/* ── Alert ────────────────────────────────────────────────────────────────── */

.p-alert {
  padding: 12px 16px;
  border-radius: 8px;
  font-size: 13px;
}
.p-alert-error {
  background: rgba(239,68,68,0.12);
  border: 1px solid rgba(239,68,68,0.3);
  color: #fca5a5;
}

/* ── Modal ────────────────────────────────────────────────────────────────── */

.p-modal {
  background: var(--p-surface);
  border: 1px solid var(--p-border);
  border-radius: var(--p-radius);
  color: var(--p-text);
  padding: 0;
  max-width: 500px;
  width: 90vw;
}
.p-modal::backdrop { background: rgba(0,0,0,0.7); }
.p-modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 24px;
  border-bottom: 1px solid var(--p-border);
}
.p-modal-header h3 { font-size: 16px; font-weight: 700; }
.p-modal-close { background: none; border: none; color: var(--p-text-muted); cursor: pointer; font-size: 18px; padding: 4px 8px; border-radius: 4px; }
.p-modal-close:hover { color: var(--p-text); background: rgba(255,255,255,0.05); }
.p-modal-body { padding: 24px; display: flex; flex-direction: column; gap: 16px; font-size: 14px; color: var(--p-text-dim); line-height: 1.6; }

.p-code-display {
  display: flex;
  align-items: center;
  gap: 12px;
  background: rgba(34,197,94,0.08);
  border: 1px solid rgba(34,197,94,0.25);
  border-radius: 8px;
  padding: 14px 18px;
}
.p-code-display span {
  font-family: monospace;
  font-size: 28px;
  font-weight: 900;
  color: var(--p-green);
  letter-spacing: 3px;
  flex: 1;
}
.p-btn-copy {
  background: none;
  border: 1px solid var(--p-green);
  color: var(--p-green);
  border-radius: 6px;
  padding: 8px 14px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  transition: all 0.15s;
}
.p-btn-copy:hover { background: rgba(34,197,94,0.15); }

.p-code-steps { font-size: 13px; color: var(--p-text-dim); }
.p-code-steps strong { color: var(--p-text); }
.p-code-steps ol { padding-left: 18px; display: flex; flex-direction: column; gap: 6px; margin-top: 8px; }
.p-code-steps a { color: var(--p-accent); text-decoration: none; }
.p-code-steps a:hover { text-decoration: underline; }
.p-code-steps code { font-family: monospace; background: rgba(0,212,255,0.1); color: var(--p-accent); padding: 2px 6px; border-radius: 4px; }

/* ── Responsive ───────────────────────────────────────────────────────────── */

@media (max-width: 768px) {
  .p-auth-page { grid-template-columns: 1fr; }
  .p-auth-aside { display: none; }
  .p-auth-card { padding: 32px 24px; }
  .p-nav-inner { gap: 8px; }
  .p-school-code-badge { display: none; }
  .p-metrics-grid { grid-template-columns: repeat(2, 1fr); }
  .p-container { padding: 0 16px; }
  .p-page-header { flex-direction: column; }
}

/* ── Small phones (≤480px) ────────────────────────────────────────────────── */
@media (max-width: 480px) {
  .p-metrics-grid { grid-template-columns: 1fr; }
  .p-container { padding: 0 12px; }
  .p-nav-inner { padding: 0 12px; }
  .p-card { padding: 16px; }
  .p-page-header h1 { font-size: 1.25rem; }
  /* Prevent iOS auto-zoom on inputs */
  input, select, textarea { font-size: 16px !important; }
}
