/* ======================================
   QuizTime Manager — Parent Portal (/account/)
   Derives strictly from the landing.css design system: flat grey-blue
   canvas, white bordered cards, serif display headings, square corners,
   navy as the only accent, no shadows and no ambient motion.
   Layout mirrors the macOS app: fixed left sidebar, swappable main panel.
   ====================================== */

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

:root {
  /* Primary — brand blue (#0B63CE) into deep navy (#073B82) */
  --primary-50: #ebf3fc;
  --primary-100: #d7e7f9;
  --primary-200: #aecff4;
  --primary-300: #7db2ec;
  --primary-400: #4a92e1;
  --primary-500: #1e78d8;
  --primary-600: #0b63ce;
  --primary-700: #0950a9;
  --primary-800: #073b82;
  --primary-900: #052c61;

  /* Success green — correctness signals only */
  --success-50: #f0fdf4;
  --success-100: #dcfce7;
  --success-600: #16a34a;
  --success-700: #15803d;

  /* Warnings */
  --warn-50: #fffbeb;
  --warn-100: #fef3c7;
  --warn-600: #d97706;
  --warn-700: #b45309;

  /* Cool neutrals */
  --gray-50: #f8fafc;
  --gray-100: #f1f5f9;
  --gray-200: #e2e8f0;
  --gray-300: #cbd5e1;
  --gray-400: #94a3b8;
  --gray-500: #64748b;
  --gray-600: #475569;
  --gray-700: #334155;
  --gray-800: #1e293b;
  --gray-900: #0f172a;

  /* Canvas & structure */
  --page-bg: #ecf1f6;
  --card: #ffffff;
  --line: #d3dde8;
  --line-strong: #b9c9da;
  --footer-bg: #0b1727;

  /* Type */
  --font-body: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-display: 'Source Serif 4', Georgia, 'Times New Roman', Times, serif;

  /* Radii — square by default; 2px only on small interactive elements */
  --radius-btn: 2px;

  --sidebar-width: 250px;
  --topbar-height: 56px;
}

html, body { height: 100%; }

body.portal-body {
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.6;
  color: var(--gray-700);
  background: var(--page-bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ── Layout ─────────────────────────── */
.portal-layout { display: flex; min-height: 100vh; }

.portal-main {
  flex: 1 1 auto;
  min-width: 0;
  padding: 2.25rem 2.5rem 4rem;
  margin-left: var(--sidebar-width);
}
.portal-main-inner { max-width: 860px; }

/* ── Sidebar ────────────────────────── */
.portal-sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: var(--sidebar-width);
  background: var(--card);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  z-index: 40;
}

.sidebar-brand {
  display: flex; align-items: center; gap: 0.5rem;
  padding: 1.125rem 1.25rem;
  border-bottom: 1px solid var(--line);
  text-decoration: none;
  color: var(--gray-900);
  font-weight: 700; font-size: 1rem;
}
.sidebar-brand img { height: 1.5rem; width: auto; display: block; }
.sidebar-brand .accent { color: var(--primary-700); }

.sidebar-scroll { flex: 1 1 auto; overflow-y: auto; padding: 1rem 0; }

.sidebar-label {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.375rem 1.25rem 0.25rem;
  font-size: 0.6875rem; font-weight: 700;
  letter-spacing: 0.1em; text-transform: uppercase;
  color: var(--gray-500);
}
.sidebar-label a {
  color: var(--primary-700); text-decoration: none;
  font-size: 1rem; line-height: 1; font-weight: 700;
  padding: 0 0.25rem;
}
.sidebar-label a:hover { color: var(--primary-900); }

.sidebar-group { margin-bottom: 1.25rem; }

.sidebar-item {
  display: flex; align-items: center; gap: 0.625rem;
  width: 100%;
  padding: 0.5rem 1.25rem 0.5rem 1.0625rem;
  border: none; border-left: 3px solid transparent;
  background: none; cursor: pointer;
  font-family: inherit; font-size: 0.9375rem; font-weight: 500;
  color: var(--gray-700); text-decoration: none; text-align: left;
}
.sidebar-item:hover { background: var(--gray-50); color: var(--gray-900); }
.sidebar-item.is-active {
  background: var(--primary-50);
  border-left-color: var(--primary-700);
  color: var(--primary-800);
  font-weight: 600;
}
.sidebar-item .avatar {
  flex: 0 0 auto;
  width: 1.625rem; height: 1.625rem;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--primary-50); color: var(--primary-700);
  border: 1px solid var(--primary-100);
  font-size: 0.75rem; font-weight: 700;
}
.sidebar-item .item-text { flex: 1 1 auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-item .issue-dot {
  flex: 0 0 auto;
  width: 0.5rem; height: 0.5rem; border-radius: 50%;
  background: var(--warn-600);
}
.sidebar-empty {
  padding: 0.25rem 1.25rem;
  font-size: 0.8125rem; color: var(--gray-500);
}

.sidebar-foot {
  border-top: 1px solid var(--line);
  padding: 0.875rem 1.25rem;
  font-size: 0.8125rem; color: var(--gray-500);
}
.sidebar-foot .who {
  display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  color: var(--gray-700); font-weight: 600; margin-bottom: 0.375rem;
}
.sidebar-foot button {
  background: none; border: none; padding: 0; cursor: pointer;
  font-family: inherit; font-size: 0.8125rem; font-weight: 600;
  color: var(--primary-700);
}
.sidebar-foot button:hover { color: var(--primary-900); }

/* ── Mobile top bar ─────────────────── */
.portal-topbar { display: none; }

@media (max-width: 900px) {
  .portal-topbar {
    display: flex; align-items: center; justify-content: space-between;
    position: fixed; top: 0; left: 0; right: 0; height: var(--topbar-height);
    background: var(--card); border-bottom: 1px solid var(--line);
    padding: 0 1rem; z-index: 50;
  }
  .portal-topbar .sidebar-brand { border-bottom: none; padding: 0; }
  .portal-topbar .menu-btn {
    background: none; border: 1px solid var(--line-strong);
    border-radius: var(--radius-btn);
    padding: 0.375rem 0.75rem; cursor: pointer;
    font-family: inherit; font-size: 0.875rem; font-weight: 600;
    color: var(--gray-700);
  }
  .portal-sidebar {
    top: var(--topbar-height);
    transform: translateX(-100%);
    transition: transform 0.15s ease;
  }
  .portal-sidebar.open { transform: translateX(0); }
  .portal-main { margin-left: 0; padding: calc(var(--topbar-height) + 1.25rem) 1.25rem 3rem; }
  .portal-scrim {
    position: fixed; inset: var(--topbar-height) 0 0 0;
    background: rgba(15, 23, 42, 0.35); z-index: 30;
  }
}

/* ── Section headings ───────────────── */
.section-head { margin-bottom: 1.5rem; }
.section-head .overline {
  display: block;
  font-size: 0.75rem; font-weight: 700;
  letter-spacing: 0.1em; text-transform: uppercase;
  color: var(--primary-700);
  margin-bottom: 0.25rem;
}
.section-head h1 {
  font-family: var(--font-display);
  font-weight: 600; font-size: 1.75rem; line-height: 1.2;
  letter-spacing: -0.01em; color: var(--gray-900);
}
.section-head .sub { color: var(--gray-500); font-size: 0.9375rem; margin-top: 0.25rem; }

/* ── Cards ──────────────────────────── */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  padding: 1.75rem 2rem;
  margin-bottom: 1.25rem;
}
.card.accent { border-top: 4px solid var(--primary-700); }
.card h2 {
  font-family: var(--font-display);
  font-size: 1.125rem; font-weight: 600; color: var(--gray-900);
  margin-bottom: 0.75rem;
}
.card h1 {
  font-family: var(--font-display);
  font-size: 1.5rem; font-weight: 600; color: var(--gray-900);
  margin-bottom: 0.25rem;
}
.muted { color: var(--gray-500); font-size: 0.9375rem; }

/* ── Buttons / forms ────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.5rem;
  padding: 0.625rem 1.25rem; font-size: 0.9375rem; font-weight: 600;
  color: #fff; background: var(--primary-700);
  border: 1px solid transparent; border-radius: var(--radius-btn);
  cursor: pointer; text-decoration: none; font-family: inherit;
  transition: background-color 0.15s ease, border-color 0.15s ease;
  white-space: nowrap;
}
.btn:hover { background: var(--primary-800); }
.btn:disabled { background: var(--gray-300); cursor: default; }
.btn.secondary {
  color: var(--primary-800); background: var(--card);
  border: 1px solid var(--line-strong);
}
.btn.secondary:hover { background: var(--card); border-color: var(--primary-600); }
.btn.secondary:disabled { color: var(--gray-400); border-color: var(--gray-200); background: var(--card); }
.btn.quiet {
  color: var(--gray-600); background: var(--card);
  border: 1px solid var(--gray-200);
}
.btn.quiet:hover { background: var(--card); border-color: var(--gray-400); }
.btn.danger {
  color: #b91c1c; background: var(--card); border: 1px solid #fecaca;
}
.btn.danger:hover { border-color: #b91c1c; background: var(--card); }
.btn.small { padding: 0.375rem 0.875rem; font-size: 0.8125rem; }
.btn-row { display: flex; flex-wrap: wrap; gap: 0.75rem; margin-top: 1.25rem; }

label.field-label {
  display: block; font-size: 0.8125rem; font-weight: 600;
  color: var(--gray-700); margin-bottom: 0.25rem;
}
.field { margin-bottom: 1rem; }
input[type="text"], input[type="email"], input[type="number"], select, textarea {
  width: 100%;
  padding: 0.5625rem 0.75rem;
  font-family: inherit; font-size: 0.9375rem; color: var(--gray-900);
  background: var(--card);
  border: 1px solid var(--line-strong); border-radius: var(--radius-btn);
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--primary-600);
}
.field-help { font-size: 0.8125rem; color: var(--gray-500); margin-top: 0.25rem; }
.check-row {
  display: flex; align-items: center; gap: 0.5rem;
  font-size: 0.9375rem; color: var(--gray-700);
  margin-bottom: 0.5rem;
}
.check-row input[type="checkbox"] { width: auto; accent-color: var(--primary-700); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 1.25rem; }
@media (max-width: 640px) { .form-grid { grid-template-columns: 1fr; } }

/* ── Notes / pills ──────────────────── */
.note {
  padding: 0.875rem 1rem; background: var(--primary-50);
  border: 1px solid var(--primary-100);
  border-left: 3px solid var(--primary-700);
  font-size: 0.875rem; margin: 1rem 0 0;
}
.note.success { background: var(--success-50); border-color: var(--success-100); border-left-color: var(--success-700); color: var(--success-700); }
.note.error { background: var(--warn-50); border-color: var(--warn-100); border-left-color: var(--warn-700); color: var(--warn-700); }
.note.warn { background: var(--warn-50); border-color: var(--warn-100); border-left-color: var(--warn-700); }
.note.warn a { color: var(--warn-700); }

.pill {
  display: inline-block; padding: 0.25rem 0.75rem;
  border-radius: var(--radius-btn); font-size: 0.8125rem; font-weight: 700;
  background: var(--success-50); color: var(--success-700);
  border: 1px solid var(--success-100);
}
.pill.none { background: var(--gray-100); color: var(--gray-600); border-color: var(--gray-200); }
.pill.warn { background: var(--warn-50); color: var(--warn-700); border-color: var(--warn-100); }
.pill.info { background: var(--primary-50); color: var(--primary-800); border-color: var(--primary-100); }

.chip {
  display: inline-block; padding: 0.125rem 0.5rem;
  font-size: 0.6875rem; font-weight: 700;
  letter-spacing: 0.04em; text-transform: uppercase;
  background: var(--gray-100); color: var(--gray-600);
  border: 1px solid var(--gray-200); border-radius: var(--radius-btn);
}
.chip.primary { background: var(--primary-50); color: var(--primary-800); border-color: var(--primary-100); }
.chip.warn { background: var(--warn-50); color: var(--warn-700); border-color: var(--warn-100); }
.chip.success { background: var(--success-50); color: var(--success-700); border-color: var(--success-100); }

/* ── Facts / rows (account section) ─── */
.facts { list-style: none; margin-top: 1rem; }
.facts li {
  display: flex; justify-content: space-between; gap: 1rem;
  padding: 0.625rem 0; border-bottom: 1px solid var(--gray-100);
  font-size: 0.9375rem;
}
.facts li:last-child { border-bottom: none; }
.facts .k { color: var(--gray-500); }
.facts .v { font-weight: 600; color: var(--gray-900); text-align: right; }

.manage-row {
  display: flex; flex-wrap: wrap; align-items: center; gap: 0.75rem 1rem;
  padding: 0.875rem 0; border-bottom: 1px solid var(--gray-100);
}
.manage-row:last-child { border-bottom: none; }
.manage-row .k { flex: 1 1 12rem; }
.manage-row .k small { display: block; color: var(--gray-500); }

.stepper {
  display: inline-flex; align-items: center; gap: 0.25rem;
  border: 1px solid var(--line-strong); border-radius: var(--radius-btn);
  padding: 0.125rem;
}
.stepper button {
  width: 1.875rem; height: 1.875rem; border: none; border-radius: var(--radius-btn);
  background: var(--primary-50); color: var(--primary-700);
  font-size: 1.125rem; font-weight: 700; cursor: pointer; font-family: inherit;
}
.stepper button:disabled { color: var(--gray-400); background: transparent; cursor: default; }
.stepper .count { min-width: 2rem; text-align: center; font-weight: 700; color: var(--gray-900); }

/* ── Tabs (child dashboard) ─────────── */
/* Six tabs since the Screen Time / Assignments / Usage panes landed, so the
   row must wrap rather than overflow on a 375px viewport. */
.tabs {
  display: flex; flex-wrap: wrap; gap: 0;
  border-bottom: 1px solid var(--line);
  margin-bottom: 1.25rem;
}
.tabs button {
  padding: 0.625rem 1.125rem;
  background: none; border: none; border-bottom: 3px solid transparent;
  margin-bottom: -1px;
  font-family: inherit; font-size: 0.9375rem; font-weight: 600;
  color: var(--gray-500); cursor: pointer;
}
.tabs button:hover { color: var(--gray-800); }
.tabs button.is-active { color: var(--primary-800); border-bottom-color: var(--primary-700); }

/* ── Entity rows (managers, devices, invitations, conversations) ── */
.entity-list { list-style: none; }
.entity-row {
  display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem 1rem;
  padding: 0.875rem 0; border-bottom: 1px solid var(--gray-100);
}
.entity-row:last-child { border-bottom: none; }
.entity-row .grow { flex: 1 1 14rem; min-width: 0; }
.entity-row .title { font-weight: 600; color: var(--gray-900); font-size: 0.9375rem; }
.entity-row .meta { font-size: 0.8125rem; color: var(--gray-500); }
.entity-row .actions { display: flex; flex-wrap: wrap; gap: 0.5rem; }

.issue-item {
  display: flex; gap: 0.625rem; align-items: baseline;
  padding: 0.5rem 0.75rem; margin-top: 0.5rem;
  background: var(--warn-50); border: 1px solid var(--warn-100);
  border-left: 3px solid var(--warn-600);
  font-size: 0.875rem;
}
.issue-item .t { font-weight: 600; color: var(--gray-900); }
.issue-item .d { color: var(--gray-600); }

.code-display {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.9375rem; font-weight: 600; letter-spacing: 0.06em;
  background: var(--gray-50); border: 1px solid var(--line);
  padding: 0.25rem 0.625rem; color: var(--gray-900);
}

.log-entry { border: 1px solid var(--line); margin-top: 0.75rem; }
.log-entry summary {
  padding: 0.625rem 0.875rem; cursor: pointer;
  font-size: 0.875rem; font-weight: 600; color: var(--gray-800);
  background: var(--gray-50);
}
.log-entry pre {
  padding: 0.875rem; overflow-x: auto;
  font-size: 0.75rem; line-height: 1.5;
  background: var(--footer-bg); color: var(--gray-200);
  max-height: 24rem; overflow-y: auto;
}

/* ── Support chat ───────────────────── */
.chat-box {
  border: 1px solid var(--line); background: var(--gray-50);
  padding: 1rem; max-height: 30rem; overflow-y: auto;
}
.chat-msg { margin-bottom: 0.875rem; max-width: 85%; }
.chat-msg .bubble {
  padding: 0.625rem 0.875rem; font-size: 0.9375rem;
  border: 1px solid var(--line); background: var(--card);
  color: var(--gray-800); white-space: pre-wrap; word-wrap: break-word;
}
.chat-msg .origin {
  font-size: 0.6875rem; font-weight: 700; letter-spacing: 0.06em;
  text-transform: uppercase; color: var(--gray-500);
  margin-bottom: 0.125rem;
}
.chat-msg.from-parent { margin-left: auto; }
.chat-msg.from-parent .bubble {
  background: var(--primary-700); border-color: var(--primary-700); color: #fff;
}
.chat-msg.from-parent .origin { text-align: right; }
.chat-pending {
  font-size: 0.8125rem; color: var(--gray-500); font-style: italic;
  padding: 0.25rem 0;
}
.action-card {
  border: 1px solid var(--primary-100); border-left: 3px solid var(--primary-700);
  background: var(--primary-50); padding: 0.75rem 0.875rem;
  margin-top: 0.5rem; font-size: 0.875rem;
}
.action-card .t { font-weight: 700; color: var(--gray-900); margin-bottom: 0.25rem; }
.chat-compose { display: flex; gap: 0.75rem; margin-top: 1rem; align-items: flex-end; }
.chat-compose textarea { flex: 1 1 auto; min-height: 4.5rem; resize: vertical; }

/* ── Filter bar (quiz catalog, worksheet + builder lists) ── */
.filter-bar {
  display: flex; flex-wrap: wrap; align-items: flex-end; gap: 0.75rem;
  padding-bottom: 1rem; margin-bottom: 0.25rem;
  border-bottom: 1px solid var(--line);
}
.filter-bar .field { margin-bottom: 0; flex: 1 1 9rem; min-width: 0; }
.filter-bar .field.wide { flex: 2 1 16rem; }

/* Two-column pane (assignments + playlist). Collapses to one on narrow. */
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 1.25rem; }
@media (max-width: 800px) { .two-col { grid-template-columns: 1fr; } }

/* ── Meter: one horizontal usage bar ── */
/* macOS draws a ring here. A ring is a new SVG component for a single
   number; a bar reads the same and is CSS only. */
.meter {
  height: 0.75rem; background: var(--gray-100);
  border: 1px solid var(--line); margin: 0.5rem 0 0.375rem;
}
.meter > span { display: block; height: 100%; background: var(--primary-600); }
.meter.over > span { background: var(--warn-600); }
.meter-legend {
  display: flex; justify-content: space-between; gap: 1rem;
  font-size: 0.8125rem; color: var(--gray-500);
}
.big-stat {
  font-family: var(--font-display);
  font-size: 2rem; font-weight: 600; line-height: 1.1; color: var(--gray-900);
}
.stat-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(8rem, 1fr));
  gap: 1rem; margin-top: 1rem;
}
.stat-grid .k {
  display: block; font-size: 0.75rem; font-weight: 700;
  letter-spacing: 0.08em; text-transform: uppercase; color: var(--gray-500);
}
.stat-grid .v { font-size: 1.25rem; font-weight: 700; color: var(--gray-900); }

/* ── Bar chart: 7-day history / 24-hour breakdown ── */
/* Inline height styles come from the view; no chart library — the portal
   ships htmx and Alpine and nothing else. */
.bar-chart {
  display: flex; align-items: flex-end; gap: 0.375rem;
  height: 8.5rem; margin: 1rem 0 0.5rem;
  padding-top: 0.5rem; border-bottom: 1px solid var(--line);
}
.bar-chart .bar { flex: 1 1 0; display: flex; flex-direction: column; justify-content: flex-end; height: 100%; min-width: 0; }
.bar-chart .bar > .fill { background: var(--primary-300); border: 1px solid var(--primary-400); border-bottom: none; min-height: 1px; }
.bar-chart .bar.over > .fill { background: var(--warn-100); border-color: var(--warn-600); }
.bar-chart .bar > .n { font-size: 0.6875rem; color: var(--gray-500); text-align: center; }
.bar-axis {
  display: flex; gap: 0.375rem;
  font-size: 0.6875rem; color: var(--gray-500); text-align: center;
}
.bar-axis span { flex: 1 1 0; min-width: 0; overflow: hidden; }
.bar-chart.hourly { height: 5rem; gap: 1px; }
.bar-chart.hourly .bar > .n { display: none; }
.bar-axis.hourly span:nth-child(even) { visibility: hidden; }

/* ── Modal (attempt detail) ─────────── */
.modal {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(15, 23, 42, 0.45);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 2rem 1rem; overflow-y: auto;
}
.modal-panel {
  background: var(--card); border: 1px solid var(--line-strong);
  width: 100%; max-width: 46rem;
}
.modal-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 1rem; padding: 1.25rem 1.5rem; border-bottom: 1px solid var(--line);
}
.modal-head h2 {
  font-family: var(--font-display); font-size: 1.125rem; font-weight: 600;
  color: var(--gray-900);
}
.modal-head button {
  background: none; border: none; cursor: pointer;
  font-family: inherit; font-size: 0.875rem; font-weight: 600;
  color: var(--primary-700);
}
.modal-body { padding: 1.25rem 1.5rem; max-height: 70vh; overflow-y: auto; }

/* ── Question / answer rows (attempt detail, worksheet grading) ── */
.qa-item {
  border: 1px solid var(--line); border-left: 3px solid var(--success-600);
  padding: 0.75rem 0.875rem; margin-bottom: 0.75rem;
}
.qa-item.wrong { border-left-color: var(--warn-600); }
.qa-item .prompt { font-weight: 600; color: var(--gray-900); font-size: 0.9375rem; }
.qa-item .ans { font-size: 0.875rem; margin-top: 0.25rem; }
.qa-item .ans .k { color: var(--gray-500); }
.qa-item .tutor {
  margin-top: 0.5rem; padding: 0.5rem 0.625rem;
  background: var(--gray-50); border: 1px solid var(--line);
  font-size: 0.8125rem;
}
.qa-item .tutor .who {
  font-size: 0.6875rem; font-weight: 700; letter-spacing: 0.06em;
  text-transform: uppercase; color: var(--gray-500);
}

/* ── Footer strip ───────────────────── */
.portal-footer {
  margin-top: 3rem; padding-top: 1.25rem;
  border-top: 1px solid var(--line);
  font-size: 0.8125rem; color: var(--gray-500);
}
.portal-footer a { color: var(--primary-700); text-decoration: none; }
.portal-footer a:hover { color: var(--primary-900); }

/* Alpine loads deferred, so x-cloak needs a rule or every x-show element is
   briefly visible before Alpine hides it. That flash was cosmetic while the
   child dashboard had three panes; it stopped being cosmetic when the new
   panes started loading on `intersect` — an unhidden pane intersects the
   viewport immediately and fetches whether or not its tab was ever picked. */
[x-cloak] { display: none !important; }

/* htmx request indicator: opacity only — no motion */
.htmx-request.htmx-indicated { opacity: 0.55; }
.htmx-indicator { display: none; }
.htmx-request .htmx-indicator, .htmx-request.htmx-indicator { display: inline; }
