/* App-specific styles on top of Pico.css (pico.min.css, v2.1.1).
   Colors only via Pico's custom properties, so light and dark mode keep working.
   Breakpoints: below 1024px the nav collapses into a menu and tables become cards
   (two columns of cards from 640px), below 576px phone tweaks. */

/* --- Layout --- */

body > header nav {
  border-bottom: 1px solid var(--pico-muted-border-color);
  margin-bottom: 1rem;
}

/* Logo (favicon.svg) and app name; alt="" because the name stands right next to it. */
.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}

.brand img {
  flex: 0 0 auto;
}

/* Pico redefines --pico-color on links, so the neutral text color comes from --pico-contrast. */
nav li a.brand {
  font-weight: 700;
  color: var(--pico-contrast);
  text-decoration: none;
}

nav a[aria-current="page"] {
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 0.3em;
}

/* Full nav on wide screens, a "Menu" dropdown below 1024px (no JavaScript: <details>). */
nav .nav-menu {
  display: none;
}

@media (max-width: 1023px) {
  nav .nav-links {
    display: none;
  }

  nav .nav-menu {
    display: flex;
  }
}

nav .nav-menu details.dropdown summary::after {
  margin-left: 0.25rem;
}

nav .nav-menu form {
  margin: 0;
  text-align: right;
  padding: var(--pico-form-element-spacing-vertical) var(--pico-form-element-spacing-horizontal);
}

body > footer {
  padding-top: 0;
}

/* --- Buttons and forms --- */

/* Buttons take their natural width instead of filling the form (Pico: button[type=submit] 100%). */
button,
button[type="submit"],
input[type="submit"],
[role="button"] {
  width: auto;
}

form.inline {
  display: inline;
  margin: 0;
}

form.inline button {
  margin: 0;
}

/* Small buttons for table rows, flash messages and the nav. */
td.actions button,
.flash button,
nav form button {
  margin: 0;
  padding: 0.25rem 0.75rem;
  font-size: 0.875rem;
}

/* A row of controls that wraps on small screens (filters, bulk actions, save + test buttons). */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 0.75rem;
  align-items: flex-end;
  margin-bottom: var(--pico-spacing);
}

.toolbar > * {
  margin-bottom: 0;
}

.toolbar > label,
.toolbar > input,
.toolbar > select {
  flex: 1 1 12rem;
  width: auto;
}

.toolbar > label > select,
.toolbar > label > input {
  margin-bottom: 0;
}

.toolbar input,
.toolbar select,
.toolbar button,
.toolbar [role="button"] {
  margin-bottom: 0;
}

/* --- Tables --- */

/* Wide tables scroll inside their box; the page itself never scrolls sideways. */
.table-wrap {
  overflow-x: auto;
  margin-bottom: var(--pico-spacing);
}

.table-wrap > table {
  margin-bottom: 0;
}

td.actions {
  white-space: nowrap;
  text-align: right;
}

td.actions > * + * {
  margin-left: 0.5rem;
}

.nowrap {
  white-space: nowrap;
}

/* Below 1024px, tables with class "cards" turn into one card per row; each cell shows its
   data-label. The cell with class "title" becomes the card heading. */
@media (max-width: 1023px) {
  table.cards,
  table.cards tbody,
  table.cards tr,
  table.cards td {
    display: block;
    width: 100%;
  }

  table.cards thead {
    display: none;
  }

  table.cards tr {
    margin-bottom: 0.75rem;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--pico-muted-border-color);
    border-radius: var(--pico-border-radius);
    background: var(--pico-card-background-color);
  }

  /* Label floats left, the value flows right-aligned beside it, so values made of several
     parts (date + status, subject + time) stay together. */
  table.cards td {
    padding: 0.25rem 0;
    border: none;
    background: transparent;
    text-align: right;
    overflow-wrap: anywhere;
  }

  table.cards td::after {
    content: "";
    display: block;
    clear: both;
  }

  table.cards td::before {
    content: attr(data-label);
    float: left;
    margin-right: 1rem;
    color: var(--pico-muted-color);
    text-align: left;
  }

  table.cards td:not([data-label])::before {
    content: none;
  }

  table.cards td:empty {
    display: none;
  }

  table.cards td.title {
    font-weight: 600;
    text-align: left;
  }

  table.cards td.actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 0.5rem;
    padding-top: 0.5rem;
    white-space: normal;
  }

  table.cards td.actions::after {
    content: none;
  }

  table.cards td.actions > * + * {
    margin-left: 0;
  }
}

/* Tablets: two columns of cards. */
@media (min-width: 640px) and (max-width: 1023px) {
  table.cards tbody {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.75rem;
  }

  table.cards tr {
    margin-bottom: 0;
  }
}

/* --- Messages and text --- */

.flash {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
  align-items: center;
  padding: 0.75rem 1rem;
  border-left: 4px solid var(--pico-ins-color);
  background: var(--pico-card-background-color);
}

.flash {
  margin-bottom: var(--pico-spacing);
}

.flash form {
  margin: 0;
}

.error {
  color: var(--pico-del-color);
}

small.error {
  display: block;
  margin-top: -0.5rem;
  margin-bottom: 1rem;
}

.notice {
  color: var(--pico-ins-color);
}

.muted {
  color: var(--pico-muted-color);
}

/* Addresses, subjects and patterns can be long; let them wrap instead of widening the page. */
td,
code,
.flash {
  overflow-wrap: break-word;
}

code {
  white-space: normal;
}

/* Key figures (run detail). */
.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(8rem, 1fr));
  gap: 0.75rem;
  margin-bottom: var(--pico-spacing);
}

.stats > div {
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--pico-muted-border-color);
  border-radius: var(--pico-border-radius);
  background: var(--pico-card-background-color);
}

.stats strong {
  display: block;
  font-size: 1.5rem;
}

.stats span {
  color: var(--pico-muted-color);
  font-size: 0.875rem;
}

/* --- Page-specific --- */

article.login {
  max-width: 24rem;
  margin: 4rem auto;
}

details.problems summary {
  font-weight: bold;
}

/* --- Phones --- */

/* Pico's grid adds a row gap on top of the fields' own bottom margin once it stacks. */
@media (max-width: 767px) {
  .grid {
    row-gap: 0;
  }
}

@media (max-width: 575px) {
  h1 {
    font-size: 1.6rem;
  }

  article {
    padding: 1rem;
  }

  article.login {
    margin: 1.5rem auto;
  }
}

/* Checkbox and sender in one cell (Recently delivered). */
label.pick {
  display: flex;
  gap: 0.75rem;
  align-items: flex-start;
  margin: 0;
  font-weight: inherit;
}

label.pick input[type="checkbox"] {
  flex: 0 0 auto;
  margin-top: 0.2rem;
}
