/* ─────────────────────────────────────────────────────────────────────────────
   KAHA TAHI PĀNGARAU — DESIGN SYSTEM & STYLESHEET
   Cohesive with Kaha Tahi Accounts & kahatahi.co.nz
   ───────────────────────────────────────────────────────────────────────────── */

@font-face {
  font-family: 'Kaha Sans';
  src: url('assets/fonts/KahaSans-Regular.woff2') format('woff2');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

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

:root {
  /* Kaha Tahi Styleguide Colors */
  --bg:           #0b0f19; /* Obsidian Navy background */
  --surface:      #161e2e; /* Slate-blue card panel */
  --border:       #242f41; /* Fine steel border */
  --border2:      #2d3d54; /* Active/thick steel border */
  --text:         #d4dbe8; /* Primary light gray text */
  --text-bright:  #f8fafc; /* Pure bright ivory */
  --muted:        #64748b; /* Muted cool gray text */
  --dim:          #1e293b; /* Dark hover highlight background */
  
  /* Brand Specific accents */
  --accent:       #C46D28; /* Kaha Tahi Brand Orange */
  --accent2:      #142F56; /* Kaha Tahi Brand Navy */
  --accent-light: #e88d53; /* Warm peach */
  
  /* Status indicators */
  --red:          #f05252;
  --amber:        #f5a623;
  --green:        #10b981;
  --blue:         #3b82f6;

  /* Font stacks */
  --sans:         'Inter', 'IBM Plex Sans', sans-serif;
  --mono:         'IBM Plex Mono', 'JetBrains Mono', monospace;
  
  --radius:       8px;
  --radius-lg:    14px;
  --control-h:    40px;
  --sidebar-w:    210px;
  
  font-family: var(--sans);
  background-color: var(--bg);
  color: var(--text);
}

body {
  height: 100vh;
  overflow: hidden;
  line-height: 1.5;
}

/* Custom Scrollbars */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: var(--radius);
}
::-webkit-scrollbar-thumb:hover {
  background: var(--border2);
}

/* App Skeleton */
.app {
  display: flex;
  height: 100vh;
  overflow: hidden;
  background: var(--bg);
}

/* Sidebar Styling (Cohesive with Accounts App) */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 0;
  z-index: 20;
}

.sidebar-logo {
  padding: 20px 18px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.sidebar-logo-name {
  font-family: 'Kaha Sans', var(--sans);
  font-size: 15px;
  font-weight: 400;
  color: var(--accent);
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.sidebar-logo-sub {
  font-size: 10px;
  color: var(--muted);
  font-family: var(--mono);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.nav {
  padding: 12px 8px;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius);
  font-size: 13px;
  color: var(--muted);
  cursor: pointer;
  transition: all 0.12s ease;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
  font-family: var(--sans);
  font-weight: 500;
}

.nav-item:hover {
  color: var(--text-bright);
  background: var(--dim);
}

.nav-item.active {
  color: var(--text-bright);
  background: rgba(196, 109, 40, 0.09); /* Subtle brand orange background */
  border-left: 2px solid var(--accent);
  border-radius: 0 var(--radius) var(--radius) 0;
}

.nav-item .icon {
  font-size: 14px;
  width: 18px;
  text-align: center;
  flex-shrink: 0;
}

.nav-badge {
  margin-left: auto;
  font-family: var(--mono);
  font-size: 9px;
  background: var(--accent);
  color: var(--text-bright);
  padding: 1px 6px;
  border-radius: 10px;
  font-weight: 600;
}

.sidebar-footer {
  padding: 12px 8px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

/* Main Viewport */
.main {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.page-header {
  padding: 20px 28px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 10;
}

.page-title {
  font-size: 18px;
  font-weight: 600;
  color: var(--text-bright);
}

.page-sub {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--muted);
  margin-top: 2px;
}

.page-body {
  padding: 20px 28px;
  flex: 1;
}

/* Metrics Dashboard Grid (Slick cards) */
.metrics {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}

.metric-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  position: relative;
  overflow: hidden;
  transition: border-color 0.12s;
}

.metric-card:hover {
  border-color: var(--border2);
}

.metric-label {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--muted);
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.metric-value {
  font-family: var(--mono);
  font-size: 24px;
  font-weight: 600;
  margin-top: 6px;
  color: var(--text-bright);
}

.metric-value.orange { color: var(--accent); }
.metric-value.blue { color: var(--blue); }
.metric-value.green { color: var(--green); }
.metric-value.amber { color: var(--amber); }

.metric-sub {
  font-size: 11px;
  color: var(--muted);
  margin-top: 4px;
}

/* Grids and Columns */
.dashboard-grid {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 20px;
  margin-bottom: 20px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 20px;
}

.card-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-bright);
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

/* Role Switcher Button */
.role-badge {
  background: var(--accent2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 4px 10px;
  border-radius: 4px;
  font-size: 11px;
  cursor: pointer;
  font-weight: 600;
  transition: all 0.12s ease;
  display: flex;
  align-items: center;
  gap: 6px;
}

.role-badge:hover {
  background: var(--accent);
  color: var(--text-bright);
}

/* Smart Input & Forms */
.smart-wrap {
  position: relative;
  width: 100%;
}

.smart-input {
  width: 100%;
  padding: 10px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-bright);
  font-family: var(--sans);
  font-size: 13px;
  outline: none;
  transition: all 0.12s ease;
  resize: none;
}

.smart-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(196, 109, 40, 0.15);
}

.smart-input.mono {
  font-family: var(--mono);
}

/* Buttons */
.btn {
  height: var(--control-h);
  padding: 0 16px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.12s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  font-family: var(--sans);
}

.btn:hover {
  color: var(--text-bright);
  border-color: var(--border2);
}

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

.btn-primary:hover {
  background: var(--accent-light);
  border-color: var(--accent-light);
  transform: translateY(-1px);
}

.btn-secondary {
  background: var(--accent2);
  color: var(--text-bright);
}

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

.btn-sm {
  height: 30px;
  padding: 0 10px;
  font-size: 11px;
}

/* Table Design System */
.table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

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

th {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 12px 16px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  font-weight: 500;
  background: rgba(0, 0, 0, 0.1);
}

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

tr:last-child td {
  border-bottom: none;
}

tr:hover td {
  background: var(--dim);
}

/* Status Pills */
.status-pill {
  display: inline-block;
  font-family: var(--mono);
  font-size: 9px;
  padding: 2px 8px;
  border-radius: 10px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  font-weight: 600;
}

.pill-achieved { background: rgba(16, 185, 129, 0.15); color: var(--green); }
.pill-merit { background: rgba(59, 130, 246, 0.15); color: var(--blue); }
.pill-excellence { background: rgba(196, 109, 40, 0.15); color: var(--accent); }
.pill-progress { background: rgba(245, 166, 35, 0.15); color: var(--amber); }

/* LaTeX Renderings and Math Display */
.math-block {
  padding: 16px;
  background: rgba(0, 0, 0, 0.15);
  border-radius: var(--radius);
  margin: 12px 0;
  border-left: 3px solid var(--accent);
  overflow-x: auto;
  font-size: 15px;
}

/* Multi-role Display logic */
.role-student, .role-teacher {
  display: none;
}

body[data-role="student"] .role-student {
  display: block;
}

body[data-role="student"] .role-student-flex {
  display: flex;
}

body[data-role="teacher"] .role-teacher {
  display: block;
}

body[data-role="teacher"] .role-teacher-flex {
  display: flex;
}

/* Interactive Canvas Board for Drawing Working */
.board-container {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 10px;
}

.canvas-wrap {
  position: relative;
  background: #fbfbfb; /* White drawing board */
  border-radius: var(--radius);
  border: 1px solid var(--border);
  aspect-ratio: 16 / 9;
  overflow: hidden;
}

canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  cursor: crosshair;
}

.canvas-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 12px;
  background: var(--surface);
  border-top: 1px solid var(--border);
}

.canvas-tools {
  display: flex;
  gap: 6px;
}

/* Floating Help Chat Widget */
.chat-widget {
  position: fixed;
  bottom: 24px;
  right: 28px;
  width: 320px;
  height: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.5);
  display: flex;
  flex-direction: column;
  z-index: 100;
  overflow: hidden;
  transition: all 0.2s ease-key;
  transform: translateY(0);
}

.chat-widget.collapsed {
  height: 48px;
  width: 160px;
  border-radius: 24px;
  cursor: pointer;
}

.chat-header {
  background: var(--accent2);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
  color: var(--text-bright);
}

.chat-widget.collapsed .chat-header {
  background: var(--accent);
  height: 100%;
  border-radius: 24px;
  padding: 0 16px;
}

.chat-title {
  font-size: 13px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
}

.chat-title .pulse {
  width: 8px;
  height: 8px;
  background: var(--green);
  border-radius: 50%;
  animation: pulse 1.5s infinite;
}

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

.chat-msg {
  max-width: 80%;
  padding: 8px 12px;
  border-radius: var(--radius);
  font-size: 12px;
  line-height: 1.4;
}

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

.chat-msg.teacher {
  background: var(--dim);
  color: var(--text);
  align-self: flex-start;
  border-bottom-left-radius: 2px;
  border-left: 2px solid var(--accent);
}

.chat-footer {
  padding: 8px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 6px;
}

/* WebRTC Video Call Area */
.video-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 12px;
}

.video-feed {
  position: relative;
  background: #000;
  border-radius: var(--radius);
  aspect-ratio: 4 / 3;
  overflow: hidden;
  border: 1px solid var(--border);
}

.video-feed video, .video-feed .mock-video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.video-label {
  position: absolute;
  bottom: 8px;
  left: 8px;
  background: rgba(0, 0, 0, 0.6);
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 10px;
  font-family: var(--mono);
  color: var(--text-bright);
}

/* Overlay Modals */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s ease;
}

.overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  width: 90%;
  max-width: 600px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.6);
}

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

.modal-body {
  padding: 20px;
  overflow-y: auto;
  flex: 1;
}

.modal-footer {
  padding: 12px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

/* Highlight box for math debug feedback */
.debug-box {
  background: rgba(240, 82, 82, 0.05);
  border: 1px solid rgba(240, 82, 82, 0.2);
  border-radius: var(--radius);
  padding: 16px;
  margin: 12px 0;
}

.debug-box.correct {
  background: rgba(16, 185, 129, 0.05);
  border-color: rgba(16, 185, 129, 0.2);
}

/* Animations */
@keyframes pulse {
  0% { transform: scale(1); opacity: 0.8; }
  50% { transform: scale(1.2); opacity: 1; }
  100% { transform: scale(1); opacity: 0.8; }
}

@keyframes flash {
  0% { background-color: var(--surface); }
  50% { background-color: var(--dim); }
  100% { background-color: var(--surface); }
}

.flash-alert {
  animation: flash 1s ease-in-out 2;
}

/* ── Math (KaTeX) legibility ───────────────────────────────────────────────
   The default rule thickness (fraction bars, √ vinculum, x̄ / recurring-decimal
   overlines) is ~0.04em and near-invisible on the dark theme. Thicken every
   rule element and nudge the overall size up. */
.katex { font-size: 1.12em; }
.katex .mord.text { font-size: 0.95em; }
.katex .frac-line,
.katex .overline .overline-line,
.katex .underline .underline-line,
.katex .hline,
.katex .sqrt > .root ~ .hide-tail > .sqrt-line,
.katex .sqrt .sqrt-line {
  border-bottom-width: 0.08em !important;
  min-height: 1px;
}
.katex .rule {
  border-width: 0.08em !important;
  min-height: 1px;
}
.katex .accent .accent-body > span { /* dot / bar accents */
  font-weight: 700;
}

/* Question diagrams (bar models, number lines — inline SVG using currentColor) */
.task-diagram { margin: 6px 0 18px; color: var(--text-bright); }
.task-diagram svg { max-width: 100%; height: auto; }
