/* SBSA School legal documents and first-login acceptance UI */
body.legal-open {
  overflow: hidden;
  overscroll-behavior: none;
}

.legal-modal[hidden] {
  display: none !important;
}

.legal-modal {
  position: fixed;
  inset: 0;
  z-index: 10000;
  display: grid;
  place-items: center;
  padding: 22px;
  overflow: hidden;
}

.legal-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(5, 22, 20, 0.84);
  backdrop-filter: blur(7px);
}

.legal-modal-dialog {
  position: relative;
  width: min(1080px, 100%);
  height: min(860px, calc(100vh - 44px));
  height: min(860px, calc(100dvh - 44px));
  max-height: calc(100vh - 44px);
  max-height: calc(100dvh - 44px);
  min-height: 0;
  overflow: hidden;
  background: #fff;
  border-radius: 24px;
  box-shadow: 0 28px 90px rgba(0, 0, 0, 0.35);
  display: flex;
  flex-direction: column;
}

#sbsa-legal-content {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.legal-modal-header {
  flex: 0 0 auto;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  padding: 28px 32px 20px;
  border-bottom: 1px solid #dce7e4;
}

.legal-modal-header h1 {
  margin: 5px 0 0;
  color: #0b2f2c;
  font-size: clamp(1.55rem, 3vw, 2.25rem);
}

.legal-modal-header p {
  max-width: 780px;
  margin: 10px 0 0;
  color: #506863;
  line-height: 1.65;
}

.legal-close {
  flex: 0 0 auto;
  border: 0;
  background: #edf4f1;
  color: #0b2f2c;
  border-radius: 999px;
  width: 42px;
  height: 42px;
  font-size: 28px;
  line-height: 1;
  cursor: pointer;
}

.legal-document-tabs {
  flex: 0 0 auto;
  display: flex;
  gap: 8px;
  padding: 14px 32px;
  border-bottom: 1px solid #e2ebe8;
  background: #f7faf9;
}

.legal-document-tabs button,
.legal-language-switch button {
  border: 1px solid #b9d0ca;
  background: #fff;
  color: #0b2f2c;
  border-radius: 999px;
  padding: 9px 16px;
  font-weight: 800;
  cursor: pointer;
}

.legal-document-tabs button.is-active,
.legal-language-switch button.is-active {
  background: #0b5a50;
  color: #fff;
  border-color: #0b5a50;
}

.legal-document-body {
  flex: 1 1 auto;
  min-height: 0;
  padding: 26px 34px 38px;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
  color: #263b37;
  line-height: 1.72;
  scrollbar-gutter: stable;
}

.legal-document-body h2 {
  color: #0b4f47;
  margin: 28px 0 10px;
  font-size: 1.18rem;
}

.legal-document-body h2:first-of-type {
  margin-top: 12px;
}

.legal-document-body p {
  margin: 0 0 14px;
}

.legal-document-body ul {
  margin: 6px 0 18px;
  padding-left: 22px;
}

.legal-document-body li {
  margin: 0 0 8px;
}

.legal-document-body a {
  color: #0b6b5f;
  font-weight: 700;
}

.legal-document-intro {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 28px;
  padding: 14px 18px;
  background: #edf6f2;
  border-left: 4px solid #9dcc67;
  border-radius: 10px;
}

.legal-document-intro p {
  margin: 0;
}

.legal-acceptance-header {
  align-items: center;
}

.legal-language-switch {
  display: flex;
  gap: 6px;
  flex: 0 0 auto;
}

.legal-acceptance-document {
  flex: 1 1 auto;
  min-height: 110px;
  max-height: none;
  border-bottom: 1px solid #dce7e4;
}

.legal-acceptance-panel {
  flex: 0 0 auto;
  min-height: 0;
  max-height: none;
  padding: 14px 32px 18px;
  overflow: visible;
  background: #f8fbfa;
  border-top: 1px solid #dce7e4;
  box-shadow: 0 -10px 28px rgba(11, 47, 44, 0.08);
}

.legal-confirmations {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.legal-acceptance-panel label {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  min-width: 0;
  margin: 0;
  padding: 12px 14px;
  border: 1px solid #cbdcd7;
  border-radius: 12px;
  background: #fff;
  color: #163d36;
  font-weight: 700;
  line-height: 1.38;
}

.legal-acceptance-panel input {
  width: 20px;
  height: 20px;
  accent-color: #0b6b5f;
  flex: 0 0 auto;
  margin-top: 1px;
}

.legal-version-note {
  margin: 0 0 9px;
  color: #5f726e;
  font-size: 0.86rem;
}

.legal-acceptance-footer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px 20px;
  margin-top: 10px;
}

.legal-acceptance-message {
  min-height: 20px;
  color: #a13232;
  font-weight: 800;
  margin: 0;
}

.legal-acceptance-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: nowrap;
}

.legal-acceptance-actions button {
  border-radius: 12px;
  padding: 12px 18px;
  font-weight: 900;
  cursor: pointer;
}

.legal-decline {
  background: #fff;
  border: 1px solid #b7c8c3;
  color: #415a55;
}

.legal-accept {
  background: #0b5a50;
  border: 1px solid #0b5a50;
  color: #fff;
}

.legal-link-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px 18px;
  flex-wrap: wrap;
}

.legal-link-button {
  border: 0;
  background: transparent;
  color: inherit;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
  font: inherit;
  font-weight: 700;
  padding: 0;
}

.sidebar-legal-links {
  display: grid;
  gap: 5px;
  margin-top: auto;
  padding-top: 14px;
}

.sidebar-legal-links button {
  border: 0;
  background: rgba(255, 255, 255, 0.08);
  color: #dfeeea;
  border-radius: 8px;
  padding: 8px 10px;
  text-align: left;
  cursor: pointer;
  font-size: 0.78rem;
}

.sidebar-legal-links button:hover {
  background: rgba(255, 255, 255, 0.15);
}

.dashboard-sidebar .sidebar-legal-links {
  margin-top: 10px;
}

.provider-admin-sidebar .sidebar-legal-links {
  margin-top: auto;
}

.provider-admin-sidebar .provider-admin-sidebar-actions {
  margin-top: 8px;
}

.account-legal-links {
  justify-content: flex-start;
  margin-top: 2px;
  color: #0b5a50;
}

@media (max-width: 960px) {
  .dashboard-sidebar .sidebar-legal-links {
    display: flex;
    margin-top: 14px;
    padding-top: 0;
  }

  .dashboard-sidebar .sidebar-legal-links button {
    flex: 1;
    text-align: center;
  }
}

@media (min-width: 721px) and (max-height: 760px) {
  .legal-modal {
    padding: 12px;
  }

  .legal-modal-dialog {
    height: calc(100vh - 24px);
    height: calc(100dvh - 24px);
    max-height: calc(100vh - 24px);
    max-height: calc(100dvh - 24px);
  }

  .legal-modal-header {
    padding: 18px 24px 14px;
  }

  .legal-modal-header p {
    margin-top: 6px;
    line-height: 1.45;
  }

  .legal-document-tabs {
    padding: 10px 24px;
  }

  .legal-document-body {
    padding: 18px 26px 24px;
  }

  .legal-acceptance-panel {
    padding: 10px 24px 12px;
  }

  .legal-acceptance-panel label {
    padding: 9px 11px;
    font-size: 0.9rem;
  }

  .legal-acceptance-actions button {
    padding: 10px 14px;
  }
}

@media (max-width: 720px) {
  .legal-modal {
    padding: 0;
  }

  .legal-modal-dialog {
    width: 100%;
    height: 100vh;
    height: 100dvh;
    max-height: 100vh;
    max-height: 100dvh;
    border-radius: 0;
  }

  #sbsa-legal-content {
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-y;
  }

  .legal-modal-header {
    padding: 16px 18px 14px;
    gap: 12px;
    flex-direction: column;
  }

  .legal-acceptance-header {
    align-items: stretch;
  }

  .legal-language-switch {
    position: static;
    align-self: flex-end;
    order: -1;
  }

  .legal-modal-header h1 {
    font-size: 1.55rem;
    padding-right: 0;
  }

  .legal-modal-header p {
    font-size: 0.92rem;
    line-height: 1.5;
  }

  .legal-document-tabs {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 8px;
    padding: 10px 18px;
    overflow: visible;
  }

  .legal-document-tabs button {
    min-width: 0;
    padding: 9px 10px;
    white-space: normal;
    line-height: 1.2;
  }

  .legal-document-body {
    padding: 18px 20px 30px;
  }

  /* The whole document view scrolls on mobile. */
  .legal-document-body:not(.legal-acceptance-document) {
    flex: 0 0 auto;
    min-height: auto;
    overflow: visible;
  }

  /* The legal text remains independently readable while the outer modal can
     still be scrolled down to the acceptance controls. */
  .legal-acceptance-document {
    flex: 0 0 auto;
    width: 100%;
    height: clamp(170px, 30vh, 260px);
    height: clamp(170px, 30dvh, 260px);
    min-height: 170px;
    max-height: 260px;
    overflow-x: hidden;
    overflow-y: auto;
  }

  .legal-acceptance-panel {
    flex: 0 0 auto;
    max-height: none;
    padding: 16px 18px calc(20px + env(safe-area-inset-bottom));
    overflow: visible;
    box-shadow: none;
  }

  .legal-confirmations {
    grid-template-columns: 1fr;
  }

  .legal-acceptance-panel label {
    font-size: 0.92rem;
  }

  .legal-acceptance-footer {
    grid-template-columns: 1fr;
  }

  .legal-version-note {
    font-size: 0.82rem;
  }

  .legal-acceptance-actions {
    display: grid;
    grid-template-columns: 1fr;
  }

  .legal-acceptance-actions button {
    width: 100%;
    padding: 12px 10px;
  }

  .legal-document-intro {
    display: block;
  }

  .legal-document-intro p + p {
    margin-top: 6px;
  }
}
