@font-face {
    font-family: "IBM Plex Sans";
    src: url("fonts/ibm-plex-sans.woff2") format("woff2");
    font-weight: 100 700;
    font-display: swap;
}

@font-face {
    font-family: "IBM Plex Mono";
    src: url("fonts/ibm-plex-mono-medium.woff2") format("woff2");
    font-weight: 400 600;
    font-display: swap;
}

/* Every colour has one meaning, in the customer area and the admin panel alike: ink is the text
   and what is selected, the accent what can be clicked, the dark panel a package that waits for
   pick-up, the warm warn colours a waiting one whose free storage time is over, green one that
   was collected (and a success message), red what failed or deletes.
   Each token holds a light and a dark value; the theme follows the system unless the toggle
   (js/theme.js) set data-theme on the root. */
:root {
    color-scheme: light dark;

    --ground: light-dark(#f3f1ec, #121416);
    --surface: light-dark(#ffffff, #1b1e21);
    --text: light-dark(#17191c, #eceae6);
    --text-2: light-dark(#3f444a, #c5c9ce);
    --muted: light-dark(#5f646a, #a3a8ae);
    --line: light-dark(#e2ded6, #33373c);
    --line-soft: light-dark(#ece9e3, #2a2e32);
    --line-strong: light-dark(#cfcac0, #474c52);
    --field-line: light-dark(#8f8a80, #6a7077);
    --hover: light-dark(#e9e5dd, #2a2e32);
    --th: light-dark(#faf9f6, #202327);
    --sunken: light-dark(#eae6de, #22262a);
    --panel: light-dark(#17191c, #2b2f34);
    --panel-2: light-dark(#26292d, #202327);
    --on-panel: #e7e3dc;
    --on-panel-soft: #c9c5bd;
    --accent: #c2410c;
    --accent-deep: #9a3412;
    --link: light-dark(#9a3412, #ffb892);
    --link-hover: light-dark(#7c2d12, #ffd9c4);
    --focus: light-dark(#c2410c, #ff8a50);
    --warn-bg: light-dark(#fdebdd, #3a2016);
    --warn-border: light-dark(#f3c6a5, #6b3a22);
    --warn-text: light-dark(#9a3412, #ffb892);
    --warn-strong: light-dark(#7c2d12, #ffd9c4);
    --ok-bg: light-dark(#ddf1e4, #173524);
    --ok-text: light-dark(#166534, #8fd4a8);
    --red: light-dark(#b42318, #ff9c92);
    --red-bg: light-dark(#fde8e6, #3b1714);

    --sans: "IBM Plex Sans", system-ui, "Segoe UI", "Helvetica Neue", Arial, sans-serif;
    --mono: "IBM Plex Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;
    --sidebar-width: 16rem;
    --radius: 8px;
    --radius-card: 16px;
}

:root[data-theme="light"] {
    color-scheme: light;
}

:root[data-theme="dark"] {
    color-scheme: dark;
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

html {
    scrollbar-color: var(--line-strong) transparent;
}

body {
    margin: 0;
    background: var(--ground);
    color: var(--text);
    font-family: var(--sans);
    font-size: 0.9375rem;
    line-height: 1.5;
    caret-color: var(--accent);
    accent-color: var(--accent);
}

::selection {
    background: var(--accent);
    color: #ffffff;
}

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

/* The brand: a dark tile with a parcel, the name, and the location name below it (see
   SettingsService.getLocationName) */

.shell-brand-label,
.auth-brand {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    align-items: center;
    column-gap: 0.625rem;
    font-size: 1.125rem;
    font-weight: 700;
    letter-spacing: -0.01em;
    line-height: 1.2;
}

.shell-brand-label::before,
.auth-brand::before {
    content: "";
    grid-row: span 2;
    width: 2.125rem;
    height: 2.125rem;
    border-radius: 8px;
    background: var(--panel) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23fff' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M21 8 12 3 3 8v8l9 5 9-5V8Z'/%3E%3Cpath d='m3 8 9 5 9-5'/%3E%3Cpath d='M12 13v8'/%3E%3C/svg%3E") center / 1.25rem no-repeat;
}

.brand-location {
    display: block;
    grid-column: 2;
    color: var(--muted);
    font-family: var(--sans);
    font-size: 0.8125rem;
    font-weight: 400;
    letter-spacing: 0;
    line-height: 1.3;
}

/* Theme toggle: shown once js/theme.js has set the theme, which also tells which icon applies */

[hidden] {
    display: none !important;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: 0;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
}

.theme-toggle,
.shell-content .theme-toggle {
    display: inline-grid;
    flex: none;
    place-items: center;
    width: 2.75rem;
    min-height: 0;
    height: 2.75rem;
    padding: 0;
    border: 1px solid var(--line-strong);
    border-radius: 50%;
    background: transparent;
    color: var(--text);
    font: inherit;
    cursor: pointer;
}

.theme-toggle:hover,
.shell-content .theme-toggle:hover {
    border-color: var(--line-strong);
    background: var(--hover);
    color: var(--text);
}

:root:not([data-theme]) .theme-toggle,
:root[data-theme="dark"] .theme-toggle .fa-moon,
:root[data-theme="light"] .theme-toggle .fa-sun {
    display: none;
}

/* Content */

.shell-content > section > * {
    max-width: 74.5rem;
}

.shell-content h2,
.auth-box h1 {
    margin: 0 0 1.5rem;
    font-size: 2rem;
    font-weight: 600;
    letter-spacing: -0.015em;
    line-height: 1.2;
    text-wrap: balance;
}

.shell-content h3 {
    margin: 0 0 0.875rem;
    font-size: 1.125rem;
    font-weight: 600;
    line-height: 1.3;
}

.shell-content section > h3:not(:first-child) {
    margin-top: 2.5rem;
}

.shell-content section > div {
    margin-top: 2.5rem;
}

.shell-content section > h2 + div {
    margin-top: 0;
}

.shell-content section > div > h3:not(:first-child) {
    margin-top: 2.5rem;
}

.shell-content section > div > form {
    max-width: 36rem;
}

.shell-content section p {
    margin: 0 0 1rem;
    max-width: 44rem;
}

.shell-content section a:not(.button) {
    color: var(--link);
    text-decoration-thickness: 1px;
    text-underline-offset: 0.2em;
}

.shell-content section a:not(.button):hover {
    color: var(--link-hover);
}

/* A white box with a hairline frame; forms directly in an area are one too */

.shell-content .card,
.shell-content section > form:not(.filters) {
    padding: 1.5rem 1.75rem;
    border: 1px solid var(--line);
    border-radius: var(--radius-card);
    background: var(--surface);
}

.shell-content .card > :last-child,
.shell-content section > form:not(.filters) > :last-child {
    margin-bottom: 0;
}

/* Sub-navigation inside an area */

.shell-content section nav {
    display: flex;
    flex-wrap: wrap;
    gap: 0.375rem;
    margin-bottom: 1.5rem;
}

.shell-content section nav a:not(.button) {
    padding: 0.5rem 0.875rem;
    border: 1px solid var(--line-strong);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text);
    font-weight: 500;
    text-decoration: none;
}

.shell-content section nav a:not(.button):hover {
    background: var(--hover);
    color: var(--text);
}

.shell-content section nav a:not(.button)[aria-current] {
    border-color: var(--text);
    background: var(--text);
    color: var(--surface);
}

/* Tables */

.shell-content table {
    width: 100%;
    margin-bottom: 1.5rem;
    border-collapse: separate;
    border-spacing: 0;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius-card);
    font-size: 0.875rem;
    font-variant-numeric: tabular-nums;
}

.shell-content caption {
    padding: 0 0 0.5rem;
    color: var(--muted);
    text-align: left;
}

.shell-content th,
.shell-content td {
    padding: 0.875rem 1.25rem;
    border-bottom: 1px solid var(--line-soft);
    text-align: left;
    vertical-align: middle;
}

.shell-content thead th {
    padding-block: 0.8125rem;
    border-bottom-color: var(--line);
    background: var(--th);
    color: var(--muted);
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    white-space: nowrap;
}

.shell-content thead th:first-child {
    border-top-left-radius: calc(var(--radius-card) - 1px);
}

.shell-content thead th:last-child {
    border-top-right-radius: calc(var(--radius-card) - 1px);
}

.shell-content tbody tr:last-child td {
    border-bottom: 0;
}

.shell-content tbody tr:hover {
    background: var(--th);
}

.shell-content td.actions {
    white-space: nowrap;
}

.shell-content td.actions > * {
    display: inline-block;
    margin: 0 0.75rem 0 0;
    vertical-align: middle;
}

/* Free storage time drawn as one cell per day; the days that have passed are filled.
   --days and --used come from the row. Beyond a month the cells would be slivers, so `many`
   draws a plain bar. --ink and --stock are the colours of the package's state. */

@property --filled {
    syntax: "<number>";
    inherits: false;
    initial-value: 0;
}

.storage-days {
    --ink: var(--text);
    --stock: var(--surface);
    --filled: var(--used);
    --cell: calc(100% / var(--days));
    display: block;
    height: 0.5rem;
    border-radius: 2px;
    background:
        repeating-linear-gradient(90deg, transparent 0 calc(var(--cell) - 2px), var(--stock) calc(var(--cell) - 2px) var(--cell)),
        linear-gradient(90deg, var(--ink) calc(var(--filled) / var(--days) * 100%), color-mix(in srgb, var(--ink) 16%, transparent) 0);
    animation: storage-days-fill 700ms cubic-bezier(0.16, 1, 0.3, 1) backwards;
}

.storage-days.many {
    background: linear-gradient(90deg, var(--ink) calc(var(--filled) / var(--days) * 100%), color-mix(in srgb, var(--ink) 16%, transparent) 0);
}

@keyframes storage-days-fill {
    from {
        --filled: 0;
    }
}

@media (prefers-reduced-motion: reduce) {
    .storage-days {
        animation: none;
    }
}

/* Buttons */

.shell-content button,
.shell-content a.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    min-height: 2.75rem;
    padding: 0.5rem 1.25rem;
    border: 1px solid var(--accent);
    border-radius: 10px;
    background: var(--accent);
    color: #ffffff;
    font: inherit;
    font-weight: 600;
    line-height: 1.25;
    text-decoration: none;
    cursor: pointer;
    transition: background-color 120ms ease-out, border-color 120ms ease-out;
}

.shell-content button:hover,
.shell-content a.button:hover {
    border-color: var(--accent-deep);
    background: var(--accent-deep);
    color: #ffffff;
}

.shell-content button:active,
.shell-content a.button:active {
    translate: 0 1px;
}

.shell-content button.secondary,
.shell-content a.button.secondary,
.shell-content button.danger {
    border-color: var(--line-strong);
    background: var(--surface);
    color: var(--text);
    font-weight: 500;
}

.shell-content button.secondary:hover,
.shell-content a.button.secondary:hover {
    background: var(--ground);
    color: var(--text);
}

.shell-content button.danger {
    color: var(--red);
}

.shell-content button.danger:hover {
    border-color: var(--red);
    background: var(--red-bg);
    color: var(--red);
}

.shell-content td button,
.shell-content td a.button {
    min-height: 2.25rem;
    padding: 0.25rem 0.75rem;
    border-radius: var(--radius);
    font-size: 0.8125rem;
}

/* Forms */

.shell-content section > form {
    max-width: 36rem;
}

.shell-content label {
    display: block;
    margin-bottom: 0.375rem;
    font-size: 0.875rem;
    font-weight: 600;
}

.shell-content input:not([type="checkbox"], [type="radio"]),
.shell-content select,
.shell-content textarea {
    width: 100%;
    min-height: 2.75rem;
    padding: 0.5625rem 0.75rem;
    border: 1px solid var(--field-line);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text);
    font: inherit;
}

.shell-content input:not([type="checkbox"], [type="radio"]):hover,
.shell-content select:hover,
.shell-content textarea:hover {
    border-color: var(--text-2);
}

.shell-content input:not([type="checkbox"], [type="radio"]):focus-visible,
.shell-content select:focus-visible,
.shell-content textarea:focus-visible {
    border-color: var(--focus);
    outline-offset: 1px;
}

.shell-content input[readonly] {
    border-color: var(--line);
    background: var(--ground);
    color: var(--text);
}

.shell-content input[readonly]:hover {
    border-color: var(--line);
}

.shell-content input[type="checkbox"],
.shell-content input[type="radio"] {
    width: 1.125rem;
    height: 1.125rem;
    margin: 0 0.625rem 0 0;
    vertical-align: -0.1875rem;
}

.shell-content input[type="checkbox"] + label,
.shell-content input[type="checkbox"] + input[type="hidden"] + label,
.shell-content fieldset label {
    display: inline;
    font-size: inherit;
    font-weight: 400;
}

.shell-content fieldset {
    margin: 0 0 1.25rem;
    padding: 0.875rem 1rem 0.25rem;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--surface);
}

.shell-content fieldset > label {
    display: block;
    margin-bottom: 0.625rem;
}

.shell-content fieldset p {
    margin-bottom: 0.625rem;
}

.shell-content fieldset p > label[for] {
    display: block;
    font-size: 0.875rem;
    font-weight: 600;
}

.shell-content legend {
    padding: 0 0.375rem;
    font-size: 0.875rem;
    font-weight: 600;
}

.shell-content form button + a,
.shell-content form p > input + button {
    margin-left: 0.75rem;
}

.shell-content form p > input[type="search"] {
    width: calc(100% - 7rem);
}

/* Fields that belong together share a row; with narrow-first the first one is the short one.
   On phones they are below each other again. */

.shell-content .form-row {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0 1.25rem;
}

.shell-content .form-row.narrow-first {
    grid-template-columns: minmax(0, 1fr) minmax(0, 2fr);
}

/* Label, field and error message of the fields in a row sit on shared lines, so the fields
   stay level when one label wraps or one field has an error */
.shell-content .form-row > p {
    display: grid;
    grid-row: span 3;
    grid-template-rows: subgrid;
}

.shell-content .form-row > p > label {
    align-self: end;
}

.shell-content .hint {
    display: block;
    margin-top: 0.375rem;
    color: var(--muted);
    font-size: 0.875rem;
    font-weight: 400;
}

/* Details of a single record */

.shell-content dl {
    display: grid;
    grid-template-columns: max-content 1fr;
    gap: 0.5rem 1.5rem;
    max-width: 36rem;
    margin: 0 0 1.5rem;
    padding: 1.25rem 1.5rem;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius-card);
}

.shell-content dt {
    color: var(--muted);
}

.shell-content dd {
    margin: 0;
    white-space: pre-line;
    font-variant-numeric: tabular-nums;
    font-weight: 500;
}

.shell-content textarea {
    display: block;
    resize: vertical;
}

.shell-content p.notice {
    max-width: 44rem;
    padding: 1.25rem 1.5rem;
    border-radius: var(--radius-card);
    background: var(--sunken);
    color: var(--text-2);
}

.shell-content p.notice strong {
    display: block;
    margin-bottom: 0.25rem;
    color: var(--text);
}

/* Messages */

.shell-content p[role="alert"],
.shell-content p[role="status"] {
    max-width: 36rem;
    padding: 0.875rem 1.125rem;
    border: 1px solid color-mix(in srgb, var(--red) 35%, transparent);
    border-radius: 12px;
    background: var(--red-bg);
    color: var(--red);
    font-weight: 500;
}

.shell-content p[role="status"] {
    border-color: color-mix(in srgb, var(--ok-text) 30%, transparent);
    background: var(--ok-bg);
    color: var(--ok-text);
}

.shell-content span[role="alert"] {
    display: block;
    margin-top: 0.375rem;
    color: var(--red);
    font-size: 0.875rem;
}

.shell-content input[readonly] + span,
.shell-content form p:not(:has(label, input, select, button)) {
    color: var(--muted);
    font-size: 0.875rem;
}

/* Login, registration, the start page and the maintenance page: a white box on the ground of
   the shell. The box carries .shell-content too, so its form elements are styled like those in
   the dashboard. */

body.auth {
    display: grid;
    place-items: center;
    min-height: 100dvh;
    padding: 1.5rem 1rem;
}

.auth-box {
    width: 100%;
    max-width: 26rem;
    padding: 2rem 2rem 1.75rem;
    border: 1px solid var(--line);
    border-radius: var(--radius-card);
    background: var(--surface);
    box-shadow: 0 12px 32px rgb(23 25 28 / 6%);
}

.auth-box-wide {
    max-width: 34rem;
}

.auth-box .auth-brand {
    margin: 0 0 1.75rem;
}

.auth-box h1.auth-brand {
    font-size: 1.125rem;
    letter-spacing: -0.01em;
}

.auth-box p {
    margin: 0 0 1rem;
}

.auth-box a:not(.button) {
    color: var(--link);
    text-underline-offset: 0.2em;
}

.auth-box a:not(.button):hover {
    color: var(--link-hover);
}

.auth-box form {
    margin-bottom: 1.25rem;
}

.auth-box form > button {
    width: 100%;
}

.auth-box i {
    margin-right: 0.125rem;
}

.auth-box > p:last-child {
    margin-bottom: 0;
}

#login-error:empty {
    display: none;
}

/* Small screens: tables become lists and form controls grow to a size a finger can hit */

@media (max-width: 48rem) {
    .shell-content h2 {
        font-size: 1.625rem;
    }

    /* 16px keeps iOS from zooming into a focused field */
    .shell-content input:not([type="checkbox"], [type="radio"]),
    .shell-content select,
    .shell-content textarea {
        font-size: 1rem;
    }

    .shell-content td button,
    .shell-content td a.button {
        min-height: 2.75rem;
        padding: 0.5rem 1rem;
        font-size: 0.9375rem;
    }

    .shell-content .card,
    .shell-content section > form:not(.filters) {
        padding: 1.25rem;
    }

    /* Tables become a list of records: each row a block, each cell a line with its column
       name in front, taken from data-label */
    .shell-content table,
    .shell-content tbody,
    .shell-content tr,
    .shell-content td {
        display: block;
    }

    .shell-content thead {
        position: absolute;
        width: 1px;
        height: 1px;
        overflow: hidden;
        clip-path: inset(50%);
    }

    .shell-content caption {
        display: block;
    }

    .shell-content table {
        border: 0;
        background: none;
    }

    .shell-content tbody tr {
        margin-bottom: 0.75rem;
        padding: 0.625rem 0;
        background: var(--surface);
        border: 1px solid var(--line);
        border-radius: 12px;
    }

    .shell-content tbody tr:hover {
        background: var(--surface);
    }

    .shell-content td {
        display: grid;
        grid-template-columns: 7.5rem minmax(0, 1fr);
        gap: 0.75rem;
        width: auto;
        padding: 0.3125rem 1rem;
        border: 0;
        text-align: left;
        overflow-wrap: anywhere;
    }

    .shell-content td::before {
        content: attr(data-label);
        color: var(--muted);
        font-size: 0.8125rem;
        font-weight: 600;
    }

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

    .shell-content td.actions::before {
        content: none;
    }

    .shell-content td.actions > * {
        margin: 0;
    }

    .shell-content td.actions > a:not(.button) {
        padding: 0.625rem 0.25rem;
    }

    .shell-content td:empty,
    .shell-content td.actions:not(:has(*)) {
        display: none;
    }
}

/* Phones: the fields of a row are below each other again */

@media (max-width: 36rem) {
    .shell-content .form-row,
    .shell-content .form-row.narrow-first {
        grid-template-columns: minmax(0, 1fr);
    }

    .shell-content .form-row > p {
        display: block;
    }

    .auth-box {
        padding: 1.5rem 1.25rem 1.25rem;
    }
}
