/* Site-wide styles on top of Bootstrap. Mobile first: base rules target phones, media queries widen. */
html {
  font-size: 16px;
}

body {
  background-color: var(--bs-tertiary-bg);
}

/* The public pages are a single column, comfortable to read on a computer too. */
main.narrow {
  max-width: 40rem;
}

/* Fields the server refused (the tag helpers add this class). */
.input-validation-error {
  border-color: var(--bs-form-invalid-border-color);
}

/* No double posts while htmx waits for the next step; the server ignores a repeated submit anyway. */
form.htmx-request button[type="submit"] {
  pointer-events: none;
  opacity: 0.65;
}

/* Grade choices: the belt and its name side by side. */
.list-group-item .belt {
  flex-shrink: 0;
}

/* A certificate photo on the admin side: about ID-card size. */
.application-photo {
  max-width: 12rem;
}

/* The uploaded photo's preview on the application form's review step. */
.review-photo {
  width: 7.5rem;
  height: auto;
}

/* Date fields (date-fields.js): the input with its calendar button, and the calendar below them. */
.date-field {
  position: relative;
  max-width: 13rem;
}

.date-field .input-group {
  flex-wrap: nowrap;
}

.date-calendar {
  position: absolute;
  top: 100%;
  left: 0;
  z-index: 1050;
  width: 18rem;
  margin-top: 0.25rem;
}

.date-calendar td .btn {
  padding-left: 0;
  padding-right: 0;
}

/* Big enough to tap: previous and next month, close. */
.date-calendar-nav {
  min-width: 2.5rem;
  min-height: 2.5rem;
  font-size: 1.25rem;
  line-height: 1;
}

.date-calendar-today {
  font-weight: 700;
  text-decoration: underline;
}

/* The time beside a deadline's date. */
.deadline-time {
  max-width: 6rem;
}

/* The Simsa logo (심사, Korean for grading): black ink on a transparent background, white on the dark header. */
.site-logo {
  width: auto;
  height: 2rem;
  filter: invert(1);
}

/* SIMSA in Latin letters: in the header and under the logo on the login page. */
.brand-name {
  font-weight: 600;
  letter-spacing: 0.4em;
}

/* Above the login form, with the name in Latin letters under it. */
.login-logo {
  width: 10rem;
  height: auto;
}

.login-brand {
  font-size: 1.5rem;
  /* Letter spacing also follows the last letter: indent as much so the word stays centred. */
  text-indent: 0.4em;
}

/* The user menu (_UserMenu): a <details> styled as a Bootstrap dropdown, so it needs no Bootstrap JavaScript. */
.user-menu > summary {
  list-style: none;
  max-width: 14rem;
}

.user-menu > summary::-webkit-details-marker {
  display: none;
}

.user-menu .dropdown-menu {
  min-width: 12rem;
}

/* The admin pages (_AdminLayout) use the whole width: the side menu's column and the page fill the window under the
   header. Stacked on phones (the menu a toggle above the page), side by side from lg. */
.has-admin-menu {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.admin-shell {
  display: flex;
  flex: 1 0 auto;
  flex-direction: column;
}

.admin-sidebar {
  padding: 1rem 0.75rem 0;
}

.admin-main {
  min-width: 0;
  padding: 1.5rem 0.75rem;
}

/* The side menu (_AdminMenu) on grey, so it reads as a menu: the whole column on wide screens, a panel on phones.
   Entries are an icon and a name. */
.admin-menu-panel {
  padding: 0.5rem;
  background-color: var(--bs-secondary-bg);
  border-radius: var(--bs-border-radius-lg);
}

.admin-menu .nav-link,
.admin-menu-collapse .nav-link {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  color: var(--bs-emphasis-color);
}

.admin-menu .nav-link:hover,
.admin-menu-collapse .nav-link:hover {
  background-color: rgba(var(--bs-emphasis-color-rgb), 0.075);
}

.admin-menu .nav-link.active {
  color: var(--bs-nav-pills-link-active-color);
  background-color: var(--bs-nav-pills-link-active-bg);
}

/* The section whose submenu is open. */
.admin-menu .admin-menu-open {
  font-weight: 600;
}

.menu-icon {
  flex-shrink: 0;
}

.admin-submenu {
  margin-top: 0.125rem;
  margin-left: 1rem;
  font-size: 0.9375rem;
}

/* The collapse button under the menu. */
.admin-menu-collapse {
  margin-top: 0.5rem;
  padding-top: 0.5rem;
  border-top: 1px solid var(--bs-border-color);
}

.admin-menu-collapse .nav-link {
  width: 100%;
  font-size: 0.875rem;
  color: var(--bs-secondary-color);
}

/* On phones the menu is a <details> above the content. */
.admin-menu-toggle > summary {
  list-style: none;
}

.admin-menu-toggle > summary::-webkit-details-marker {
  display: none;
}

.admin-menu-toggle[open] > summary {
  margin-bottom: 0.5rem;
}

@media (min-width: 992px) {
  .admin-shell {
    flex-direction: row;
  }

  .admin-sidebar {
    flex: 0 0 15rem;
    padding: 0;
    background-color: var(--bs-secondary-bg);
    border-right: 1px solid var(--bs-border-color);
  }

  /*
   * The menu stays in view while a long page scrolls; the grey column goes on to the bottom. Being sticky, it is a
   * stacking context of its own: its z-index keeps it, and the collapsed menu's tooltips, above the page's positioned
   * content (cards).
   */
  .admin-sidebar-menu {
    position: sticky;
    top: 0;
    z-index: 1020;
    padding: 1rem 0.5rem;
  }

  .admin-main {
    flex: 1 1 0;
    padding: 1.5rem 2rem;
  }

  /*
   * Collapsed: only the icons. The open section is tinted and its submenu's icons follow on a lighter band, so they
   * read as the section's; the current page is marked as when expanded.
   */
  .admin-menu-collapsed .admin-sidebar {
    flex-basis: auto;
  }

  .admin-menu-collapsed .admin-submenu {
    margin-left: 0;
    padding: 0.125rem 0;
    background-color: rgba(var(--bs-emphasis-color-rgb), 0.05);
    border-radius: var(--bs-border-radius);
  }

  .admin-menu-collapsed .admin-menu .admin-menu-open {
    background-color: rgba(var(--bs-primary-rgb), 0.15);
  }

  .admin-menu-collapsed .admin-menu-collapse .menu-icon {
    transform: scaleX(-1);
  }

  /* The names become tooltips beside the icons; they stay in the page for screen readers. */
  .admin-menu-collapsed .admin-sidebar-menu .nav-link {
    position: relative;
    justify-content: center;
  }

  .admin-menu-collapsed .admin-sidebar-menu .menu-label {
    position: absolute;
    top: 50%;
    left: calc(100% + 0.75rem);
    z-index: 1030;
    padding: 0.25rem 0.5rem;
    font-size: 0.875rem;
    font-weight: 400;
    white-space: nowrap;
    color: var(--bs-white);
    background-color: var(--bs-gray-900);
    border-radius: var(--bs-border-radius);
    opacity: 0;
    pointer-events: none;
    transform: translateY(-50%);
    transition: opacity 0.15s;
  }

  .admin-menu-collapsed .admin-sidebar-menu .nav-link:hover .menu-label,
  .admin-menu-collapsed .admin-sidebar-menu .nav-link:focus-visible .menu-label {
    opacity: 1;
  }
}

@media (prefers-reduced-motion: reduce) {
  .admin-menu-collapsed .admin-sidebar-menu .menu-label {
    transition: none;
  }
}

/*
 * A scrolling table is the containing block of what it positions, so visually hidden text in its cells (absolutely
 * positioned) scrolls with it instead of widening the page on phones.
 */
.table-responsive {
  position: relative;
}

/* Sortable column headers in the application list: the header text links to the sort, with an arrow for it. */
.sort-link {
  color: inherit;
  text-decoration: none;
  white-space: nowrap;
}

.sort-link:hover,
.sort-link:focus-visible {
  text-decoration: underline;
}

.sort-indicator {
  margin-left: 0.25rem;
  font-size: 0.75em;
}

th:not([aria-sort]) .sort-indicator {
  color: var(--bs-secondary-color);
}

/* Statistics on the admin overview: big numbers, a gauge and tables with bars. */
.stat-number {
  font-size: 2.5rem;
  font-weight: 600;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.stats-table .stat-count {
  font-variant-numeric: tabular-nums;
}

.stats-table .stat-bar-cell {
  width: 40%;
}

.stat-bar {
  display: block;
  width: 100%;
  min-width: 3rem;
  height: 0.75rem;
}

.stat-bar-track {
  fill: var(--bs-secondary-bg);
}

.stat-bar-value {
  fill: var(--bs-primary);
}

.stats-table .belt {
  width: 48px;
  height: 8px;
  flex-shrink: 0;
}

@media (min-width: 576px) {
  .stats-table .belt {
    width: 72px;
    height: 12px;
  }
}

.gauge {
  display: block;
  max-width: 100%;
  height: auto;
}

.gauge-track,
.gauge-value {
  fill: none;
  stroke-width: 12;
}

.gauge-track {
  stroke: var(--bs-secondary-bg);
}

.gauge-value {
  stroke: var(--bs-success);
}

.gauge-text {
  font-size: 18px;
  font-weight: 600;
  fill: var(--bs-body-color);
}
