/* Shared responsive layout foundation for every authenticated CRM workspace. */
#app,
#app * { box-sizing: border-box; }

#app :is(.panel, .page-shell, .detail-main, .workspace-card, .assistant-card),
#app :is(.panel, .page-shell, .detail-main, .workspace-card, .assistant-card) > * { min-width: 0; }

#app :is(h1, h2, h3, h4, p, small, span, td, th, label, .muted) {
  overflow-wrap: anywhere;
}

/* Keep form fields and action rows inside their cards at every viewport width. */
#app :is(.form-grid, .detail-grid, .profile-grid, .filters-grid, .application-grid, .course-grid) {
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 250px), 1fr));
  gap: 16px;
}

#app :is(.form-grid, .detail-grid, .profile-grid, .filters-grid, .application-grid, .course-grid) > * { min-width: 0; }

#app :is(label, .field, .form-field) { min-width: 0; }

#app :is(input, select, textarea) { max-width: 100%; }

#app :is(.toolbar, .panel-head, .page-actions, .action-row, .button-row) {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

#app :is(.toolbar, .panel-head, .page-actions, .action-row, .button-row) > * { min-width: 0; }

/* Tables retain their columns but scroll inside a deliberate viewport instead of breaking cards. */
#app :is(.table-wrap, .table-scroll, .table-responsive, .application-table, .document-centre-table) {
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: 14px;
}

#app :is(.table-wrap, .table-scroll, .table-responsive, .application-table, .document-centre-table) table {
  width: 100%;
  min-width: 680px;
  border-collapse: separate;
  border-spacing: 0;
}

#app :is(.table-wrap, .table-scroll, .table-responsive, .application-table, .document-centre-table) :is(th, td) {
  padding: 13px 16px;
  vertical-align: top;
  line-height: 1.45;
  white-space: normal;
}

/* Lead 360°: isolate profile information, metrics, tabs and right-hand coaching panel. */
#app .lead360-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(290px, 340px);
  align-items: start;
  gap: 16px 24px;
  padding: 4px 0 20px;
  margin-bottom: 20px;
  border-bottom: 1px solid #e7e9f2;
}

#app .lead360-head > div { min-width: 0; }

#app .lead360-head :is(h1, h2, h3) {
  margin: 4px 0 8px;
  line-height: 1.16;
}

#app .lead360-head .muted {
  margin: 0;
  max-width: 68ch;
  line-height: 1.55;
}

/* Ownership belongs with the student identity, not in a permanent side rail.
   That keeps every Lead 360° workspace—including history—full width. */
#app .lead360-ownership {
  display: grid;
  gap: 7px;
  padding: 16px;
  border: 1px solid #ddd4fa;
  border-radius: 16px;
  background: linear-gradient(135deg, #faf8ff 0%, #f3efff 100%);
  box-shadow: 0 8px 22px rgba(68, 42, 140, .08);
}

#app .lead360-ownership :is(h3, p) { margin: 0; }
#app .lead360-ownership h3 { font-size: 1.04rem; }
#app .lead360-status { justify-self: start; }
#app .lead360-ownership-meta {
  display: grid;
  gap: 5px;
  padding-top: 9px;
  border-top: 1px solid #dfd8f4;
  color: #525a70;
  font-size: .88rem;
  line-height: 1.4;
}
#app .lead360-ownership .primary { width: 100%; margin-top: 5px; }

#app .lead360-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) minmax(280px, .55fr);
  align-items: start;
  gap: 22px;
}

#app .lead360-layout > * { min-width: 0; }
#app .lead360-layout--full { grid-template-columns: minmax(0, 1fr); }

#app .lead360-tabs {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin: 0 0 18px;
  padding: 0 0 14px;
  border-bottom: 1px solid #e7e9f2;
}

#app .lead360-tabs button {
  min-height: 38px;
  padding: 8px 13px;
  white-space: normal;
}

#app .lead360-metrics {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin: 0 0 20px;
}

#app .lead360-identity .lead360-metrics {
  margin: 18px 0 0;
}

#app .lead360-metrics > div {
  display: grid;
  align-content: start;
  gap: 6px;
  min-height: 92px;
  padding: 15px;
  border: 1px solid #dce8ff;
  border-radius: 14px;
  background: #f6f9ff;
}

#app .lead360-metrics strong {
  display: block;
  font-size: clamp(1.3rem, 2vw, 1.75rem);
  line-height: 1.05;
}

#app :is(.lead360-form-grid, .lead360-detail-grid) {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 230px), 1fr));
  gap: 14px 16px;
}

#app :is(.lead360-form-grid, .lead360-detail-grid) > * { min-width: 0; }

#app .session-card,
#app .history-row {
  padding: 14px 16px;
  margin: 12px 0;
  line-height: 1.5;
}

/* Lead 360° processing history: keep operational columns legible instead of
   shrinking them until dates and statuses split character-by-character. */
#app .lead360-section[data-section="history"] .processing-history {
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 12px 0 18px;
  border: 1px solid #e4e7f0;
  border-radius: 14px;
}

#app .lead360-section[data-section="history"] .processing-history table {
  width: 100%;
  /* Four operational columns need room for real dates and status names. */
  min-width: 980px;
  margin: 0;
  table-layout: fixed;
  border-collapse: separate;
  border-spacing: 0;
}

#app .lead360-section[data-section="history"] .processing-history :is(th, td) {
  padding: 16px 18px;
  vertical-align: top;
  line-height: 1.5;
  overflow-wrap: normal;
  word-break: normal;
}

#app .lead360-section[data-section="history"] .processing-history :is(th, td):nth-child(1) {
  width: 220px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#app .lead360-section[data-section="history"] .processing-history :is(th, td):nth-child(2) {
  width: 280px;
}

#app .lead360-section[data-section="history"] .processing-history :is(th, td):nth-child(3) {
  overflow-wrap: anywhere;
}

#app .lead360-section[data-section="history"] .processing-history :is(th, td):nth-child(4) {
  width: 170px;
}

#app .lead360-section[data-section="history"] .processing-history td:nth-child(2) :is(.badge, .pill, .status) {
  display: inline-flex;
  width: max-content;
  max-width: 100%;
  min-height: 32px;
  align-items: center;
  padding: 6px 10px;
  line-height: 1.3;
  text-align: left;
}

#app .lead360-layout aside :is(.assistant-card, .panel) {
  width: 100%;
  max-width: 100%;
}

@media (max-width: 980px) {
  #app .lead360-layout { grid-template-columns: 1fr; }
  #app .lead360-layout aside { order: 2; }
}

@media (max-width: 680px) {
  #app :is(.panel, .page-shell, .detail-main) { padding-inline: 16px; }

  #app .lead360-head { grid-template-columns: 1fr; gap: 12px; }
  #app .lead360-head > :last-child { width: 100%; }
  #app .lead360-head > :last-child :is(button, a) { width: 100%; justify-content: center; }
  #app .lead360-metrics { grid-template-columns: 1fr; }
  #app .lead360-tabs { gap: 7px; }
  #app .lead360-tabs button { flex: 1 1 auto; }
  #app :is(.toolbar, .panel-head, .page-actions, .action-row, .button-row) > :is(button, a) { flex: 1 1 auto; text-align: center; justify-content: center; }
}
