/* Quiet Index — global application layer.
   Loaded after every page stylesheet. The goal is containment and a calm,
   consistent surface for all authenticated and public screens. */
.main-area {
  --qi-radius: 16px;
  --qi-radius-sm: 10px;
  --qi-gap: 16px;
  min-width: 0;
}
.main-area :where(div, section, article, header, footer, aside, main, form, fieldset) { min-width: 0; }
.main-area :where(h1, h2, h3, h4, p, li, dt, dd, th, td, label, legend, figcaption) {
  overflow-wrap: anywhere;
  word-break: normal;
}
.main-area :where(a, button, .button, .text-link) {
  overflow-wrap: anywhere;
  max-width: 100%;
}
.main-area :where(img, video, svg, canvas) { max-width: 100%; height: auto; }

/* Page headings: one editorial level, no heavy panels. */
.main-area .page-heading {
  align-items: flex-end;
  gap: 18px;
  padding: 0 0 18px;
  margin: 0 0 22px;
  border: 0;
  border-bottom: 1px solid var(--color-border);
  border-radius: 0;
  background: transparent;
  box-shadow: none;
}
.main-area .page-heading .page-heading-copy { min-width: 0; max-width: 900px; }
.main-area .page-heading h1,
.main-area .form-intro h1 {
  max-width: 100%;
  margin: 5px 0 8px;
  color: var(--color-text-primary);
  font-size: clamp(27px, 3.8vw, 42px);
  font-weight: 800;
  letter-spacing: -.05em;
  line-height: 1.02;
  text-wrap: balance;
}
.main-area .page-heading .muted,
.main-area .form-intro .muted { max-width: 760px; line-height: 1.55; }
.main-area .page-heading .heading-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.main-area .page-heading .heading-actions form { margin: 0; }
.main-area .eyebrow { font-size: 10px; line-height: 1.35; letter-spacing: .11em; }

/* Surfaces and cards */
.main-area :where(.panel, .stat-card, .catalog-card, .organization-card-row,
  .admission-result, .student-summary, .student-next-action, .parent-children,
  .portfolio-result-card, .queue-panel, .notice-panel) {
  border: 1px solid var(--color-border);
  border-radius: var(--qi-radius);
  background: var(--color-surface);
  box-shadow: none;
  min-width: 0;
}
.main-area .panel { padding: 22px; }
.main-area .panel-header,
.main-area .form-section-head {
  align-items: flex-start;
  flex-wrap: wrap;
  gap: 8px 16px;
  min-width: 0;
}
.main-area .panel-header > *,
.main-area .form-section-head > * { min-width: 0; }
.main-area .panel-header h2,
.main-area .form-section-head h2 { font-size: clamp(18px, 2vw, 23px); letter-spacing: -.03em; line-height: 1.15; }
.main-area .panel p,
.main-area .panel li { line-height: 1.55; }

/* Common grids: keep columns shrinkable. */
.main-area :where(.stat-grid, .student-dash-grid, .school-grid, .portfolio-grid,
  .admission-center-goals, .organization-card-list, .detail-layout, .catalog-cards,
  .routes-grid, .parent-grid, .queue-stats) { min-width: 0; }
.main-area :where(.stat-grid, .portfolio-grid, .admission-center-goals, .organization-card-list) > * { min-width: 0; }
.main-area .stat-card { min-height: 0; padding: 18px; }
.main-area .stat-card :where(strong, b) { overflow-wrap: anywhere; }
.main-area .stat-label,
.main-area .stat-card > span,
.main-area .stat-card small { overflow-wrap: anywhere; }

/* Buttons: one flat, readable action style. */
.main-area .button,
.main-area .heading-actions .button,
.main-area .form-actions .button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  max-width: 100%;
  min-height: 40px;
  padding: 0 14px;
  border-radius: var(--qi-radius-sm);
  white-space: normal;
  line-height: 1.2;
  text-align: center;
  box-shadow: none;
}
.main-area .button-primary,
.main-area .button-dark {
  border-color: var(--color-brand);
  background: var(--color-brand);
  color: var(--color-text-on-brand);
}
.main-area .button-primary:hover,
.main-area .button-dark:hover { background: var(--color-brand-strong); }
.main-area .button-outline { background: var(--color-surface); }
.main-area .button-outline:hover { background: var(--color-brand-soft); }
.main-area .button-wide { width: 100%; }
.main-area .button-sm { min-height: 34px; padding-inline: 11px; }

/* Forms: controls fit, borders remain visible, labels never collide. */
.main-area :where(.form-stack, .form-page, .form-panel, .admission-filter-form,
  .admission-search-form, .queue-filters, .audit-filters, .calendar-filters) { min-width: 0; }
.main-area :where(.field, .form-stack label, .admission-filter-form label,
  .queue-filters label, .audit-filters label) { min-width: 0; }
.main-area :where(.field label, .form-stack label, .admission-filter-form label,
  .queue-filters label, .audit-filters label) { overflow-wrap: anywhere; line-height: 1.35; }
.main-area :where(.field input, .field select, .field textarea,
  .admission-filter-form input, .admission-filter-form select,
  .admission-search-form input, .admission-search-form select,
  .queue-filters input, .queue-filters select, .audit-filters input, .audit-filters select) {
  max-width: 100%;
  min-width: 0;
  min-height: 42px;
  border-color: #8E8E93;
  box-sizing: border-box;
}
.main-area :where(.field input, .field select, .field textarea,
  .admission-filter-form input, .admission-filter-form select,
  .admission-search-form input, .admission-search-form select,
  .queue-filters input, .queue-filters select, .audit-filters input, .audit-filters select):focus {
  border-color: var(--color-brand);
  outline: none;
  box-shadow: 0 0 0 3px var(--color-focus-ring);
}
.main-area .help-text,
.main-area .error,
.main-area .form-errors { overflow-wrap: anywhere; line-height: 1.45; }
.main-area .form-actions { display: flex; flex-wrap: wrap; gap: 9px; align-items: center; }

/* Tables and dense data: scroll the container, never the page. */
.main-area :where(.compare-scroll, .table-scroll, .table-wrap) {
  max-width: 100%;
  overflow-x: auto;
  overscroll-behavior-inline: contain;
  -webkit-overflow-scrolling: touch;
}
.main-area :where(table, .compare-table) { max-width: 100%; }
.main-area :where(th, td) { overflow-wrap: anywhere; }
.main-area .queue-panel { overflow-x: auto; }
.main-area .queue-table { min-width: 760px; }
.main-area .compare-table { min-width: 760px; }

/* Badges and states should wrap instead of leaving the card. */
.main-area :where(.status, .badge, .category-badge, .publication-label,
  .participation-label, .child-chip, .route-type, .roadmap-chip) {
  max-width: 100%;
  white-space: normal;
  overflow-wrap: anywhere;
}

/* List rows: let the text column shrink before it pushes actions out. */
.main-area :where(.organization-card-row, .admission-result, .activity-row,
  .review-row, .notification, .child-chip-row) { min-width: 0; }
.main-area :where(.organization-card-row, .admission-result, .activity-row,
  .review-row) > * { min-width: 0; }
.main-area :where(.organization-card-actions, .row-right, .review-tools) { flex-wrap: wrap; min-width: 0; }

/* Empty / status panels */
.main-area :where(.empty-state, .catalog-empty, .route-empty, .notification-empty) {
  max-width: 100%;
  height: auto;
  min-height: 0;
  padding: clamp(20px, 4vw, 36px);
  overflow-wrap: anywhere;
}

/* Shell / page content must not create a horizontal page scroll. */
html, body { overflow-x: clip; }
.main-area { overflow-x: clip; }

@media (max-width: 980px) {
  .main-area .page-heading { align-items: flex-start; flex-direction: column; }
  .main-area .page-heading .heading-actions { width: 100%; }
  .main-area :where(.stat-grid, .queue-stats) { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 680px) {
  .main-area { padding-inline: 14px; }
  .main-area .page-heading { padding-bottom: 14px; margin-bottom: 18px; }
  .main-area .page-heading h1,
  .main-area .form-intro h1 { font-size: 28px; }
  .main-area .page-heading .heading-actions .button { flex: 1 1 160px; }
  .main-area .panel { padding: 16px; border-radius: 14px; }
  .main-area :where(.stat-grid, .queue-stats, .portfolio-grid,
    .admission-center-goals) { grid-template-columns: minmax(0, 1fr); }
  .main-area .stat-card { min-height: 0; }
  .main-area .form-actions .button { flex: 1 1 100%; }
}
@media (prefers-reduced-motion: reduce) {
  .main-area *, .main-area *::before, .main-area *::after { scroll-behavior: auto !important; }
}

/* Explicit flattening of the old elevated stat surfaces. */
.main-area .stat-card {
  background: var(--color-surface);
  border-color: var(--color-border);
  box-shadow: none;
}
.main-area .stat-card::after { display: none; }
.main-area .panel {
  background: var(--color-surface);
  border-color: var(--color-border);
  box-shadow: none;
}
[data-theme="dark"] .main-area .stat-card,
[data-theme="dark"] .main-area .panel { background: var(--color-surface); }

/* Mobile topbar: breadcrumb and controls get their own lines, never chase each other. */
@media (max-width: 680px) {
  .main-area > .topbar {
    height: auto;
    min-height: 0;
    flex-wrap: wrap;
    align-items: flex-start;
    gap: 8px 12px;
    padding: 10px 0;
  }
  .main-area > .topbar .breadcrumb {
    flex: 1 1 100%;
    width: 100%;
    min-width: 0;
    font-size: 11px;
    line-height: 1.4;
    overflow-wrap: anywhere;
  }
  .main-area > .topbar .topbar-right {
    width: 100%;
    margin-left: 0;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 8px 12px;
  }
  .main-area > .topbar .today-label { white-space: normal; }
}

/* Analytics and legacy filter forms: labels and controls stack before they collide. */
.main-area .filter-form {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 9px 12px;
  min-width: 0;
}
.main-area .filter-form label { flex: 0 1 auto; min-width: 0; }
.main-area .filter-form input,
.main-area .filter-form select { flex: 1 1 150px; min-width: 0; max-width: 100%; min-height: 42px; }
.main-area .filter-form button { flex: 0 0 auto; }
@media (max-width: 620px) {
  .main-area .filter-form { display: grid; grid-template-columns: minmax(0, 1fr); align-items: stretch; gap: 6px; }
  .main-area .filter-form label { margin-top: 3px; }
  .main-area .filter-form input,
  .main-area .filter-form select,
  .main-area .filter-form button { width: 100%; }
  .main-area .panel-header { flex-direction: column; align-items: stretch; }
  .main-area .panel-header > * { width: 100%; }
  .main-area .panel-header h1 { font-size: clamp(26px, 7vw, 33px); }
}

/* The calendar drawer button must stay visible on every calendar page. */
.main-area .gcal-drawer-toggle {
  width: 48px;
  height: 48px;
  padding: 0;
  font-size: 0;
  background: var(--color-brand) !important;
  border-color: var(--color-brand) !important;
  color: #fff !important;
  box-shadow: 0 8px 22px rgba(0, 113, 227, .22) !important;
}
.main-area .gcal-drawer-toggle:hover { background: var(--color-brand-strong) !important; }
.main-area .gcal-drawer-toggle :where(svg, .ui-icon) { color: #fff !important; fill: currentColor; }

/* Long text in dense list rows should not push a sibling control outside its card. */
.main-area :where(.activity-row, .admission-result, .organization-card-row, .review-row) {
  overflow-wrap: anywhere;
}
.main-area :where(.activity-row, .admission-result, .organization-card-row, .review-row) > :first-child { min-width: 0; flex: 1 1 auto; }

/* Panel titles that are page-level h1s (admission, university and queue screens). */
.main-area .panel-header h1 {
  margin: 3px 0 7px;
  font-size: clamp(27px, 3.4vw, 39px);
  line-height: 1.04;
  letter-spacing: -.045em;
  text-wrap: balance;
}
.main-area .panel-header p { margin-bottom: 0; }

/* New cabinet components (bookmarks, diagnostic, consent notice) — same tokens. */
.bookmark-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 12px; }
.bookmark-row { display: flex; justify-content: space-between; align-items: center; gap: 14px; padding: 14px 16px; border: 1px solid var(--color-border); border-radius: var(--radius-md); background: var(--color-surface); }
.bookmark-row h2 { margin: 0 0 4px; font-size: 17px; }
.bookmark-row form { margin: 0; }
.diagnostic-options { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.diagnostic-option { display: inline-flex; align-items: center; gap: 7px; padding: 8px 12px; border: 1px solid var(--color-border-strong); border-radius: 10px; cursor: pointer; font-size: 14px; }
.diagnostic-option:has(input:checked) { border-color: var(--color-brand); background: var(--color-brand-soft); }
.consent-notice { border-left: 4px solid var(--color-warning-strong); }
