/*** Utility classes ***/

.container {
  margin: 0 auto;
}

.block { display: block; }
.inline-block { display: inline-block; }

.card {
  width: fit-content;
  background-color: var(--card-bg);
  padding: 1rem;
  border-radius: 10px;
  box-shadow:
    0 20px 25px -5px var(--shadow-color, rgba(0, 0, 0, 0.1)),
    0 8px 10px -6px var(--shadow-color, rgba(0, 0, 0, 0.1));

  border: 1px solid var(--border-color);
}
.border-radius-sm { border-radius: 2px; }
.border-radius { border-radius: 6px; }
.border-radius-lg { border-radius: 10px; }

.float-left { float: left; }
.float-right { float: right; }

.text-left { text-align: left; }
.text-center { text-align: center; }
.text-right { text-align: right; }

.text-xlarge { font-size: x-large; }
.text-large { font-size: large; }
.text-larger { font-size: larger; }
.text-small { font-size: small; }
.text-smaller { font-size: smaller; }

.white-space-pre-line { white-space: pre-line; }

.ellipsis { overflow-x: auto; text-overflow: ellipsis; white-space: nowrap; }

.list-style-disc { list-style: disc; }
.list-style-none { list-style: none; }

.font-monospace { font-style: monospace; }
.font-italic { font-style: italic; }
.font-thin { font-weight: 200; }
.font-semithin { font-weight: 300; }
.font-normal { font-weight: 400; }
.font-semibold { font-weight: 500; }
.font-bold { font-weight: 600; }

.flex {
  display: flex;
  flex-flow: column nowrap;

  &.flex-nowrap { flex-wrap: nowrap; }
  &.flex-wrap { flex-wrap: wrap; }
  &.flex-row { flex-direction: row; }
}
.flex\! { display: flex !important; }

.flex-column { flex-direction: column; }
.flex-grow-0 { flex-grow: 0; }
.flex-grow-1 { flex-grow: 1; }

.justify-around { justify-content: space-around; }
.justify-around\! { justify-content: space-around !important; }
.justify-between { justify-content: space-between; }
.justify-between\! { justify-content: space-between !important; }
.justify-evenly { justify-content: space-evenly; }
.justify-evenly\! { justify-content: space-evenly !important; }
.justify-center { justify-content: center; }
.justify-center\! { justify-content: center !important; }
.justify-end { justify-content: flex-end; }
.justify-end\! { justify-content: flex-end !important; }
.justify-start { justify-content: flex-start; }
.justify-start\! { justify-content: flex-start !important; }

.items-baseline { align-items: baseline; }
.items-center { align-items: center; }
.items-start { align-items: start; }

.align-self-end { align-self: end; }
.align-self-start { align-self: start; }

.notice {
  background: var(--green);
  color: var(--white);
  text-align: center;
  padding: 1rem;
  font-size: large;
}

/*** Main site navbar ***/

.topnav {
  background: var(--topnav-bg);
  display: flex;
  flex-flow: row nowrap;
  justify-content: space-between;
  align-items: start;

  .logo img {
    display: inline-block;
    max-width: 100%;
    margin: 0;
  }

  ul {
    display: flex;
    flex-flow: column nowrap;
    align-items: end;
    list-style-type: none;
    margin: 0;

    li {
      font-weight: 600;
    }
  }
}

@media (max-width: 639px) {
  .container {
    padding: 0.75rem;

    &.mobile-no-padding {
      padding: 0;
    }
  }
}

@media (min-width: 640px) {
  .container {
    max-width: 80vw;
  }

  .flex {
    flex-flow: row nowrap;
  }

  .topnav {
    align-items: center;

    .logo img {
      margin: 1em 0;
    }

    ul {
      font-size: larger;
      flex-flow: row nowrap;
      align-items: center;
      padding: 0;

      li {
        &:not(:last-child) {
          margin-right: 1em;
        }
      }
    }
  }

  .non-mobile { visibility: visible; }
  .mobile-only { visibility: collapse; }
}

@media (max-width: 639px) {
  .non-mobile { visibility: collapse; }
  .mobile-only { visibility: visible; }
}

/**
 * @see https://stackoverflow.com/questions/26032089/in-html-how-can-i-have-text-that-is-only-accessible-for-screen-readers-i-e-fo
 */
.sr-only {
  position: absolute !important; /* Outside the DOM flow */
  height: 1px;
  width: 1px; /* Nearly collapsed */
  overflow: hidden;
  clip: rect(1px 1px 1px 1px); /* IE 7+ only support clip without commas */
  clip: rect(1px, 1px, 1px, 1px); /* All other browsers */
}

/*** Forms ***/

button[type=submit],
input[type=submit],
.btn {
  background: var(--btn-bg-color, #ddd);
  color: var(--btn-fg-color, #111);
  font-weight: 600;
  padding: 0.5em 0.75em;
  border: 1px solid var(--btn-border-color, #888);
  border-radius: var(--btn-radius, 6px);
  cursor: pointer;

  &.danger {
    --btn-bg-color: var(--danger);
    --btn-fg-color: var(--white);
    --btn-border-color: var(--red-1);
  }
}

label[for] {
  cursor: pointer;
}

input[readonly],
select[readonly] {
  --outline-color: var(--danger);
  background-color: var(--input-disabled-bg);
  color: var(--shadow-color);
  cursor: not-allowed;
}

button:focus,
button:focus-visible,
input:focus,
input:focus-visible,
select:focus,
select:focus-visible,
textarea:focus,
textarea:focus-visible {
  outline: var(--outline-color) dotted medium;
}

fieldset {
  border: 1px solid var(--border-color, #333);
  border-radius: 6px;
  width: calc(100% - 1.5em);
}

.field {
  label {
    font-weight: 500;
    display: block;
    margin: 0.75em 0 0.5em;
  }

  input,
  input[type="tel"],
  input[type="url"],
  input[type="date"],
  input[type="text"],
  input[type="time"],
  input[type="email"],
  input[type="number"],
  input[type="datetime"],
  input[type="datetime-local"],
  select,
  textarea {
    font-size: 100%;
    display: block;
    background-color: var(--input-bg);

    width: calc(100% - 8px - 2px); /* calc(100% - paddingX*2 - borderX-width*2) */
    padding: 6px;
    border: 1px solid var(--border-color, #333);
    border-bottom: 3px solid var(--border-color, #333);
    border-radius: 6px;
  }

  select {
    width: calc(100% + 0.25em);
  }

  textarea {
    min-height: 7rem;
    resize: vertical;
  }

  &.checkbox {
    display: flex;
    flex-flow: row wrap;
    justify-content: flex-start;
    align-items: baseline;

    label {
      flex: 1 1;
    }
    input {
      flex: 1 0 2em;
    }
  }

  .hint {
    margin-top: 0.5em;
    font-size: 1.125em;
  }
}

.fields {
  display: flex;
  flex-flow: row nowrap;
  justify-content: space-between;
  align-items: start;

  &.two {
    .field { width: 50%; }
  }

  &.three {
    .field { width: 33%; }
  }

  &.four {
    .field { width: 25%; }
  }

  .field {
    &:not(:first-child) {
      padding-left: 0.25em;
    }
    &:not(:last-child) {
      padding-right: 0.25em;
    }
  }
}

.form-errors {
  background: var(--danger);
  color: var(--white-1);
  border: 1px solid var(--red);
  padding: 0.5em;
  border-radius: var(--border-radius);
}

form.inline {
  display: flex;
  flex-flow: row nowrap;
  justify-content: space-around;
  align-items: center;

  .field {
    display: flex;
    flex-flow: row nowrap;
    align-items: center;

    label {
      margin: initial;
      text-wrap: nowrap;
      padding-right: 0.5em;
    }
  }

  button[type=submit],
  input[type=submit] {
    margin-left: 0.5em;
  }
}

/*** Tables ***/

.table {
  width: 100%;
  margin: 1em 0;
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius);
  border-collapse: separate;
  border-spacing: 0px;
  background: var(--bg-table);
  box-shadow:
    0 20px 25px -5px var(--shadow-color, rgba(0, 0, 0, 0.1)),
    0 8px 10px -6px var(--shadow-color, rgba(0, 0, 0, 0.1));

  &:first-child {
    margin-top: 0;
  }

  &:last-child {
    margin-bottom: 0;
  }

  thead th {
    cursor: auto;
    background: var(--bg-contrast);
    color: var(--fg-contrast);
    font-weight: bold;
    border-bottom: 1px solid var(--border-color);
    border-left: none;
    padding: 0.5em 1em;
    text-align: left;

    &:first-child {
      border-top-left-radius: var(--border-radius);
    }

    &:last-child {
      border-top-right-radius: var(--border-radius);
    }
  }

  td {
    padding: 0.5em 1em;
  }
}

/***** margin *****/

.m-0 { margin: 0 !important; }
.m-1 { margin: 0.25rem !important; }
.m-2 { margin: 0.5rem !important; }
.m-3 { margin: 0.75rem !important; }
.m-4 { margin: 1rem !important; }

.my-0 { margin-top: 0 !important; margin-bottom: 0 !important; }
.my-1 { margin-top: 0.25rem !important; margin-bottom: 0.25rem !important; }
.my-2 { margin-top: 0.5rem !important; margin-bottom: 0.5rem !important; }
.my-3 { margin-top: 0.75rem !important; margin-bottom: 0.75rem !important; }
.my-4 { margin-top: 1rem !important; margin-bottom: 1rem !important; }
.mx-0 { margin-left: 0 !important; margin-right: 0 !important; }
.mx-1 { margin-left: 0.25rem !important; margin-right: 0.25rem !important; }
.mx-2 { margin-left: 0.5rem !important; margin-right: 0.5rem !important; }
.mx-3 { margin-left: 0.75rem !important; margin-right: 0.75rem !important; }
.mx-4 { margin-left: 1rem !important; margin-right: 1rem !important; }

.mt-0 { margin-top: 0 !important; }
.mt-1 { margin-top: 0.25rem !important; }
.mt-2 { margin-top: 0.5rem !important; }
.mt-3 { margin-top: 0.75rem !important; }
.mt-4 { margin-top: 1rem !important; }
.mr-0 { margin-right: 0 !important; }
.mr-1 { margin-right: 0.25rem !important; }
.mr-2 { margin-right: 0.5rem !important; }
.mr-3 { margin-right: 0.75rem !important; }
.mr-4 { margin-right: 1rem !important; }
.mb-0 { margin-bottom: 0 !important; }
.mb-1 { margin-bottom: 0.25rem !important; }
.mb-2 { margin-bottom: 0.5rem !important; }
.mb-3 { margin-bottom: 0.75rem !important; }
.mb-4 { margin-bottom: 1rem !important; }
.ml-0 { margin-left: 0 !important; }
.ml-1 { margin-left: 0.25rem !important; }
.ml-2 { margin-left: 0.5rem !important; }
.ml-3 { margin-left: 0.75rem !important; }
.ml-4 { margin-left: 1rem !important; }

.mx-auto { margin-right: auto; margin-left: auto; }
.my-auto { margin-top: auto; margin-bottom: auto; }

/***** padding *****/

.p-0 { padding: 0 !important; }
.p-1 { padding: 0.25rem !important; }
.p-2 { padding: 0.5rem !important; }
.p-3 { padding: 0.75rem !important; }
.p-4 { padding: 1rem !important; }

.py-0 { padding-top: 0 !important; padding-bottom: 0 !important; }
.py-1 { padding-top: 0.25rem !important; padding-bottom: 0.25rem !important; }
.py-2 { padding-top: 0.5rem !important; padding-bottom: 0.5rem !important; }
.py-3 { padding-top: 0.75rem !important; padding-bottom: 0.75rem !important; }
.py-4 { padding-top: 1rem !important; padding-bottom: 1rem !important; }
.px-0 { padding-left: 0 !important; padding-right: 0 !important; }
.px-1 { padding-left: 0.25rem !important; padding-right: 0.25rem !important; }
.px-2 { padding-left: 0.5rem !important; padding-right: 0.5rem !important; }
.px-3 { padding-left: 0.75rem !important; padding-right: 0.75rem !important; }
.px-4 { padding-left: 1rem !important; padding-right: 1rem !important; }

.pt-0 { padding-top: 0 !important; }
.pt-1 { padding-top: 0.25rem !important; }
.pt-2 { padding-top: 0.5rem !important; }
.pt-3 { padding-top: 0.75rem !important; }
.pt-4 { padding-top: 1rem !important; }
.pr-0 { padding-right: 0 !important; }
.pr-1 { padding-right: 0.25rem !important; }
.pr-2 { padding-right: 0.5rem !important; }
.pr-3 { padding-right: 0.75rem !important; }
.pr-4 { padding-right: 1rem !important; }
.pb-0 { padding-bottom: 0 !important; }
.pb-1 { padding-bottom: 0.25rem !important; }
.pb-2 { padding-bottom: 0.5rem !important; }
.pb-3 { padding-bottom: 0.75rem !important; }
.pb-4 { padding-bottom: 1rem !important; }
.pl-0 { padding-left: 0 !important; }
.pl-1 { padding-left: 0.25rem !important; }
.pl-2 { padding-left: 0.5rem !important; }
.pl-3 { padding-left: 0.75rem !important; }
.pl-4 { padding-left: 1rem !important; }
