.topbar,
.familybar,
.graph-view,
.family-surface,
.layout {
  flex: 0 0 auto;
}

body {
  display: flex;
  flex-direction: column;
}

.topbar {
  min-height: 72px;
  padding: 12px 24px;
}

.graph-view {
  flex: 1 0 560px;
  height: auto;
}

.topbar h1 {
  font-size: 21px;
}

.topbar .eyebrow {
  margin-bottom: 2px;
}

.view-switch {
  grid-template-columns: repeat(3, minmax(104px, 1fr));
}

.workspace-switch {
  display: inline-grid;
  grid-template-columns: repeat(2, max-content);
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #ffffff;
}

.workspace-switch button {
  min-width: 120px;
  border: 0;
  border-radius: 0;
  color: var(--muted);
}

.workspace-switch button + button {
  border-left: 1px solid var(--line);
}

.workspace-switch button.active {
  background: var(--ink);
  color: #ffffff;
}

.parent-tools-menu {
  position: relative;
}

.parent-tools-menu summary {
  min-width: 104px;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--muted);
  background: #ffffff;
  cursor: pointer;
  font-size: 14px;
  font-weight: 650;
  list-style: none;
  text-align: center;
}

.parent-tools-menu summary::-webkit-details-marker {
  display: none;
}

.parent-tools-menu summary::after {
  content: "";
  display: inline-block;
  width: 6px;
  height: 6px;
  margin: 0 0 3px 8px;
  border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  transform: rotate(45deg);
}

.parent-tools-menu.active summary,
.parent-tools-menu[open] summary {
  border-color: var(--ink);
  color: var(--ink);
}

.parent-tools-popover {
  position: absolute;
  z-index: 30;
  top: calc(100% + 8px);
  right: 0;
  display: grid;
  width: 280px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #ffffff;
  box-shadow: 0 14px 32px rgb(23 32 30 / 14%);
}

.parent-tools-popover button {
  border: 0;
  border-radius: 0;
  text-align: left;
}

.parent-tools-popover button + button {
  border-top: 1px solid var(--line);
}

.parent-tools-status {
  border: 0;
  border-top: 1px solid var(--line);
  border-radius: 0;
  padding: 12px 14px;
  background: var(--surface-subtle);
  font-size: 12px;
  line-height: 1.45;
  white-space: normal;
}

.familybar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  min-height: 58px;
  padding: 9px 24px;
  border-bottom: 1px solid var(--line);
  background: #ffffff;
}

.learner-switch,
.familybar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.familybar-actions {
  margin-left: auto;
}

.learner-switch {
  min-width: 0;
  overflow-x: auto;
}

.learner-chip {
  display: inline-flex;
  align-items: center;
  flex: 0 0 auto;
  gap: 8px;
  min-height: 38px;
  border-color: transparent;
  color: var(--muted);
}

.learner-chip.active {
  border-color: var(--line-strong);
  background: var(--surface-subtle);
  color: var(--ink);
}

.learner-avatar {
  display: inline-grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--ink);
  color: #ffffff;
  font-size: 11px;
}

.family-surface {
  min-height: calc(100dvh - 130px);
  background: var(--bg);
}

.family-page {
  width: min(1280px, 100%);
  margin: 0 auto;
  padding: 34px 28px 56px;
}

.family-page-heading {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  padding-bottom: 24px;
}

.family-page-heading h2 {
  margin: 0;
  font-size: 30px;
  line-height: 1.2;
}

.family-page-heading p {
  max-width: 620px;
  margin: 7px 0 0;
  color: var(--muted);
  line-height: 1.5;
}

.family-page-heading p span {
  margin-left: 8px;
  color: var(--ink-soft);
  font-weight: 700;
}

.family-heading-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.family-metrics {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  border-top: 1px solid var(--line-strong);
  border-bottom: 1px solid var(--line-strong);
  background: #ffffff;
}

.ai-health-strip {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 52px;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-left: 4px solid #7b8794;
  border-radius: 6px;
  background: var(--panel);
}

.ai-health-strip.status-ready { border-left-color: #25855a; }
.ai-health-strip.status-model_missing,
.ai-health-strip.status-unavailable { border-left-color: #b85f2a; }

.ai-health-dot {
  width: 9px;
  height: 9px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: #7b8794;
}

.status-ready .ai-health-dot { background: #25855a; }
.status-model_missing .ai-health-dot,
.status-unavailable .ai-health-dot { background: #b85f2a; }

.ai-health-copy {
  display: grid;
  gap: 2px;
  min-width: 0;
  flex: 1;
}

.ai-health-copy small { color: var(--muted); }

.ai-health-strip button { flex: 0 0 auto; }

.family-metrics div {
  min-width: 0;
  padding: 20px 22px;
}

.family-metrics div + div {
  border-left: 1px solid var(--line);
}

.family-metrics strong,
.family-metrics span {
  display: block;
}

.family-metrics strong {
  font-size: 27px;
  font-variant-numeric: tabular-nums;
}

.family-metrics span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.dashboard-columns {
  display: grid;
  grid-template-columns: minmax(0, 1.8fr) minmax(280px, 1fr);
  gap: 36px;
  padding-top: 34px;
}

.family-section h3 {
  margin: 0 0 14px;
  font-size: 18px;
}

.plan-rows,
.activity-list {
  margin: 0;
  padding: 0;
  list-style: none;
  background: #ffffff;
  border-top: 1px solid var(--line);
}

.plan-row {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) auto auto;
  gap: 14px;
  align-items: center;
  min-height: 78px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}

.plan-index,
.today-task-number {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border: 1px solid var(--line-strong);
  border-radius: 50%;
  color: var(--ink-soft);
  font-size: 13px;
  font-weight: 800;
}

.plan-copy {
  display: grid;
  gap: 5px;
  min-width: 0;
}

.plan-copy strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.plan-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 12px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.plan-time {
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

.activity-list li {
  display: grid;
  grid-template-columns: 10px minmax(0, 1fr);
  gap: 10px;
  align-items: start;
  padding: 13px 4px;
  border-bottom: 1px solid var(--line);
}

.activity-list strong,
.activity-list small {
  display: block;
}

.activity-list small {
  margin-top: 4px;
  color: var(--muted);
}

.activity-mark {
  width: 8px;
  height: 8px;
  margin-top: 5px;
  border-radius: 50%;
  background: var(--muted);
}

.activity-mark.status-mastered {
  background: var(--green);
}

.activity-mark.status-learning {
  background: var(--blue);
}

.activity-mark.status-needs_practice {
  background: var(--orange);
}

.family-empty {
  margin: 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  padding: 24px 4px;
  color: var(--muted);
}

.today-page {
  width: min(1040px, 100%);
}

.today-task-list {
  display: grid;
  gap: 12px;
}

.today-task {
  display: grid;
  grid-template-columns: 40px minmax(0, 1fr) auto;
  gap: 18px;
  align-items: center;
  min-height: 152px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 20px;
  background: #ffffff;
}

.today-task-body {
  min-width: 0;
}

.today-task h3 {
  margin: 7px 0;
  font-size: 20px;
}

.today-task p {
  margin: 0;
  color: var(--ink-soft);
  line-height: 1.5;
}

.today-outcome {
  margin-top: 12px;
  border-left: 3px solid var(--accent);
  padding-left: 10px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.today-learner.experience-guided {
  width: min(820px, 100%);
}

.today-learner.experience-guided .today-task {
  grid-template-columns: 42px minmax(0, 1fr);
}

.today-learner.experience-guided .today-task > button {
  grid-column: 2;
  min-height: 44px;
  width: 100%;
}

.today-learner.experience-guided .today-task-body > p {
  display: none;
}

.today-learner.experience-guided .today-outcome {
  font-size: 15px;
  line-height: 1.6;
}

body[data-family-mode="learner"] .parent-only {
  display: none !important;
}

body[data-family-mode="parent"] .learner-only {
  display: none !important;
}

body[data-has-learner="false"] .requires-learner {
  display: none !important;
}

.onboarding-page {
  display: grid;
  min-height: calc(100dvh - 132px);
  place-items: center;
}

.onboarding-intro {
  width: min(780px, 100%);
  padding: 36px 0;
}

.onboarding-intro h2 {
  margin: 0 0 12px;
  font-size: 34px;
}

.onboarding-intro > p:not(.eyebrow) {
  max-width: 620px;
  margin: 0 0 24px;
  color: var(--ink-soft);
  font-size: 17px;
  line-height: 1.65;
}

.onboarding-roles {
  margin: 30px 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  padding: 18px 0 20px;
}

.onboarding-roles h3 {
  margin: 0 0 16px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
}

.onboarding-roles ol {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin: 0;
  padding: 0;
  list-style: none;
}

.onboarding-roles li {
  min-width: 0;
  padding: 0 20px;
}

.onboarding-roles li:first-child {
  padding-left: 0;
}

.onboarding-roles li + li {
  border-left: 1px solid var(--line);
}

.onboarding-roles li > span,
.onboarding-roles li > strong {
  display: block;
}

.onboarding-roles li > span {
  margin-bottom: 7px;
  color: var(--accent-dark);
  font-size: 12px;
  font-weight: 750;
}

.onboarding-roles li > strong {
  margin-bottom: 5px;
  font-size: 16px;
}

.onboarding-roles li > p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

body[data-family-mode="learner"] .view-switch {
  grid-template-columns: repeat(2, minmax(120px, 1fr));
}

@media (max-width: 900px) {
  .topbar,
  .familybar {
    align-items: stretch;
    flex-direction: column;
  }

  .top-actions,
  .familybar-actions {
    width: 100%;
  }

  .workspace-switch {
    max-width: 100%;
  }

  .view-switch {
    width: 100%;
    order: 0;
  }

  .language-toggle {
    flex: 0 0 auto;
  }

  .parent-tools-menu {
    margin-left: auto;
  }

  .familybar-actions {
    justify-content: space-between;
    margin-left: 0;
  }

  .dashboard-columns {
    grid-template-columns: 1fr;
  }

  .family-surface {
    min-height: 0;
  }
}

@media (max-width: 640px) {
  .onboarding-roles ol {
    grid-template-columns: 1fr;
  }

  .onboarding-roles li,
  .onboarding-roles li:first-child {
    padding: 12px 0;
  }

  .onboarding-roles li + li {
    border-top: 1px solid var(--line);
    border-left: 0;
  }
}

@media (max-width: 620px) {
  .topbar {
    position: relative;
  }

  .topbar,
  .familybar {
    padding-left: 14px;
    padding-right: 14px;
  }

  .top-actions {
    flex-direction: row;
    flex-wrap: wrap;
  }

  .workspace-switch {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    width: 100%;
  }

  .workspace-switch button {
    min-width: 0;
  }

  .language-toggle {
    position: absolute;
    top: 14px;
    right: 14px;
  }

  .view-switch {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  body[data-family-mode="learner"] .view-switch {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .view-switch button {
    min-width: 0;
  }

  .familybar-actions {
    flex-wrap: wrap;
  }

  .family-page {
    padding: 24px 14px 40px;
  }

  .family-page-heading {
    align-items: stretch;
    flex-direction: column;
  }

  .family-heading-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .family-page-heading h2 {
    font-size: 25px;
  }

  .family-metrics {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .family-metrics div:nth-child(n + 3) {
    border-top: 1px solid var(--line);
  }

  .family-metrics div:nth-child(odd) {
    border-left: 0;
  }

  .family-metrics div:nth-child(even) {
    border-left: 1px solid var(--line);
  }

  .plan-row {
    grid-template-columns: 32px minmax(0, 1fr) auto;
  }

  .plan-time {
    display: none;
  }

  .plan-row button {
    grid-column: 2 / -1;
  }

  .today-task {
    grid-template-columns: 34px minmax(0, 1fr);
    align-items: start;
    padding: 16px;
  }

  .today-task > button {
    grid-column: 2;
  }

}
