@layer base {
/* Base body styles with CSS nesting */

/* Typography */
h1, h2 {
  text-align: center;
  margin: 0;
}

h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-family-heading);
}

/* Base layout elements */
body,
form,
ul {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 0;
  margin: 0;
}

/* Form elements */
input,
textarea,
select {
  background-color: var(--surface-sunken);
  line-height: 100%;
  font-weight: var(--font-weight-medium);
  color: var(--text);
  text-align: center;
  padding: var(--spacing-1);
  border: var(--border-width) solid var(--border);
  border-radius: var(--radius);
  min-height: var(--tap-min);

  &[type="email"],
  &[type="password"],
  &[type="tel"] {
    direction: ltr;
  }
}

label {
  font-size: var(--font-size-lg);
}

/* Body styles — app shell: sidebar | app-main (row on desktop, single column
   on mobile since the sidebar hides itself below 900px). */
body {
  font-family: var(--font-family-base);
  background-color: var(--bg);
  font-size: var(--font-size-base);
  line-height: var(--line-height-base);
  color: var(--text);
  margin: 0;
  padding: 0;
  flex-direction: row;
  align-items: stretch;
  justify-content: flex-start;
  min-height: 100dvh;

  & #app-main {
    /* Full-height flex column so the sticky #bottom_nav (margin-block-start:
       auto) sits at the bottom even on short pages. min-width: 0 stops wide
       content from pushing the shell beyond the viewport. */
    flex: 1 1 auto;
    min-width: 0;
    display: flex;
    flex-direction: column;
    min-height: 100dvh;
  }

  & #main-content {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
  }
}

/* Devise shared links */
#devise_shared_links {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-top: var(--spacing-4);

  & a {
    line-height: 2em;
    color: var(--brand);
  }
}

/* Utility classes */
.hide {
  display: none !important;
  transition: all var(--transition-slow) ease;
}

.ltr {
  direction: ltr;
}

/* Form inputs */
input,
select,
textarea {
  background-color: var(--surface-sunken);
  border: var(--border-width) solid var(--border);
  border-radius: var(--radius);
  line-height: 2em;

  &:focus {
    border-color: var(--brand);
    outline: none;
    box-shadow: 0 0 0 3px var(--focus-ring);
  }
}

/* New button */
.new {
  margin-inline: var(--spacing-2) var(--spacing-4);
  margin-block: 0;
  width: var(--tap-min);
  height: var(--tap-min);
  font-size: 2em;
  padding: 0.3em;
  outline: var(--border-width) solid var(--border);
  border-radius: var(--radius-full);
  display: flex;
  justify-content: center;
  align-items: center;
  text-decoration: none;
  background-color: var(--surface);
  color: var(--brand);

  &:hover {
    background-color: var(--blue-50);
    color: var(--brand-hover);
  }

  &:focus-visible {
    outline: 3px solid var(--focus-ring);
    outline-offset: 2px;
  }
}

/* Table-like layouts */
.header {
  font-weight: var(--font-weight-bold);
  border-bottom: var(--border-width-thick) solid var(--border);
  padding: var(--spacing-2) 0;
}

.row {
  width: 100%;
  display: flex;
  flex-direction: row;
  align-items: center;

  & .col {
    flex: 1;
  }

  & img {
    width: 100%;
    height: 100%;
  }

  & > * {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
  }
}

.extended {
  width: 100%;
  outline: var(--border-width) solid var(--border);
}

/* Canvas element */
canvas {
  border: none;
  padding: 0;
  margin: 0;
  transform: none;
}

/* New instance link */
.new-instance-href {
  margin: var(--spacing-4) auto;
  font-size: var(--font-size-lg);
}

/* Trix editor customizations */
.trix-button--icon-link,
.trix-button--icon-strike,
.trix-button--icon-code {
  display: none;
}

/* Dialog/Modal styles */
dialog {
  position: fixed;
  z-index: var(--z-index-50);
  inset-inline-start: 0;
  top: 0;
  width: 100%;
  height: 100%;
  overflow: auto;
  background-color: rgb(0 0 0 / 40%);
  padding: var(--spacing-6) var(--spacing-4);
  box-sizing: border-box;

  & .close {
    display: inline-block;
    margin-bottom: var(--spacing-4);

    & .close-button {
      color: var(--on-brand);
      float: inline-end;
      font-size: var(--font-size-2xl);
      font-weight: var(--font-weight-bold);
      background-color: var(--red-700);
      border: none;
      cursor: pointer;
      border-radius: var(--radius-full);
      min-width: var(--tap-min);
      min-height: var(--tap-min);
      line-height: var(--tap-min);

      &:hover,
      &:focus {
        background-color: var(--red-900);
        text-decoration: none;
        cursor: pointer;
      }

      &:focus-visible {
        outline: 3px solid var(--focus-ring);
        outline-offset: 2px;
      }
    }
  }

  & #modal-content {
    box-sizing: border-box;
    background-color: var(--surface);
    margin: 5% auto;
    padding: var(--spacing-4);
    border: var(--border-width) solid var(--border);
    width: 100%;
    max-height: 80%;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
    animation: animatetop 0.4s;
  }

  @keyframes animatetop {
    from {
      top: -300px;
      opacity: 0;
    }
    to {
      top: 0;
      opacity: 1;
    }
  }

  & .field {
    display: flex;
    flex-direction: row;
    justify-content: space-between;
    margin-bottom: var(--spacing-2);
    border-bottom: var(--border-width) solid var(--border);
    padding: var(--spacing-1) var(--spacing-3);
    align-items: center;
  }

  & .label {
    font-weight: var(--font-weight-bold);
    margin-inline-end: var(--spacing-2);
  }
}

/* Dialog backdrop */
::backdrop {
  background-color: rgb(0 0 0 / 75%);
}

/* Flex utility classes */
.flex-row {
  width: 100%;
  display: flex;
  flex-direction: row;
  align-items: center;
}

.flex-col {
  width: 100%;
  display: flex;
  flex-direction: column;
}

/* Table row styling */
.table-row {
  width: 100%;
  display: flex;
  flex-direction: row;
  justify-content: space-around;
  align-items: center;
  margin: var(--spacing-1) 0;
  position: relative;

  & .col {
    flex-grow: 1;
    text-align: center;
    min-width: 0;
    padding: var(--spacing-2);
    box-sizing: border-box;
    border-bottom: var(--border-width) solid var(--border);
    white-space: nowrap;
  }

  & img {
    width: 100%;
    height: 100%;
  }

  & > * {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
  }
}

/* Styling for file input in employment form */
input[type="file"] {
  border: var(--border-width) solid var(--border);
  border-radius: var(--radius);
  padding: var(--spacing-2);
  background-color: var(--surface-sunken);
  cursor: pointer;
  min-height: var(--tap-min);

  &::file-selector-button {
    background-color: var(--brand);
    color: var(--on-brand);
    border: none;
    padding: var(--spacing-1) var(--spacing-2);
    border-radius: var(--radius);
    cursor: pointer;
    min-height: var(--tap-min);
    transition: background-color var(--transition-fast);

    &:hover {
      background-color: var(--brand-hover);
    }
  }

  &:focus {
    border-color: var(--brand);
    box-shadow: 0 0 0 3px var(--focus-ring);
  }
}

/* thin scrollbar for all elements */
* {
  scrollbar-width: thin; /* Firefox */
  scrollbar-color: var(--border-strong) var(--surface-sunken); /* Firefox */
}

/* Chrome, Edge, and Safari */
::-webkit-scrollbar {
  width: 10px;
  height: 10px; /* For horizontal scrollbars */
}

::-webkit-scrollbar-thumb {
  background-color: var(--border-strong);
  border-radius: var(--radius-full);
}

::-webkit-scrollbar-track {
  background-color: var(--surface-sunken);
}

/* Apply to all scrollable elements */
div, textarea, pre, code, body {
  &::-webkit-scrollbar {
    width: 10px;
    height: 10px;
  }

  &::-webkit-scrollbar-thumb {
    background-color: var(--border-strong);
    border-radius: var(--radius-full);
  }

  &::-webkit-scrollbar-track {
    background-color: var(--surface-sunken);
  }
}
}
