body {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    /* Bootstrap's theme-aware colours, so light and dark mode both work. */
    background-color: var(--bs-bg-1);
    color: var(--bs-fg-body);
}

.app-header {
    background-color: #1f2a37;
}

.app-header .nav-link {
    color: rgba(255, 255, 255, 0.7);
    padding: 0.5rem 0.75rem;
    border-radius: 0.375rem;
}

.app-header .nav-link:hover,
.app-header .nav-link.active {
    color: #fff;
    background-color: rgba(255, 255, 255, 0.1);
}

.app-brand {
    color: #fff;
    font-weight: 600;
    text-decoration: none;
    margin-right: 1rem;
}

.app-user {
    color: rgba(255, 255, 255, 0.7);
    font-size: 0.875rem;
}

.app-main {
    flex: 1;
}

.app-footer {
    color: var(--bs-fg-3);
    font-size: 0.875rem;
    text-align: center;
}

.centered-page {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.narrow-card {
    width: 100%;
    max-width: 400px;
}

.narrow-form {
    max-width: 560px;
}

.address-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

/* The header is dark in both themes. */
.header-btn,
.header-btn:not(:hover):not(:focus-visible) {
    color: #fff;
    background-color: transparent;
    border: 1px solid rgba(255, 255, 255, 0.5);
}

.header-btn:hover,
.header-btn:focus-visible {
    color: #1f2a37;
    background-color: #fff;
}

[data-bs-theme=dark] .app-header {
    background-color: #111827;
    border-bottom: 1px solid var(--bs-border-color);
}

/* Theme toggle: show the moon in light mode and the sun in dark mode. */
.theme-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.375rem;
    line-height: 1;
}

.theme-toggle .icon-sun,
[data-bs-theme=dark] .theme-toggle .icon-moon {
    display: none;
}

[data-bs-theme=dark] .theme-toggle .icon-sun {
    display: inline;
}

.floating-theme-toggle {
    position: fixed;
    top: 1rem;
    right: 1rem;
    z-index: 10;
}

.role-form {
    display: flex;
    gap: 0.375rem;
    align-items: center;
    max-width: 16rem;
}

/* Logs page */
.log-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem;
    border-bottom: 1px solid var(--bs-border-color);
}

.log-tab {
    padding: 0.5rem 0.75rem;
    color: var(--bs-fg-2);
    text-decoration: none;
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
}

.log-tab:hover {
    color: var(--bs-fg-body);
}

.log-tab.active {
    color: var(--bs-fg-body);
    font-weight: 600;
    border-bottom-color: currentColor;
}

.log-view {
    max-height: 70vh;
    overflow: auto;
    padding: 0.75rem 1rem;
    font-size: 0.8125rem;
    line-height: 1.45;
    white-space: pre-wrap;
    word-break: break-word;
    background-color: var(--bs-bg-body);
    border: 1px solid var(--bs-border-color);
    border-radius: 0.5rem;
}

.log-error {
    color: light-dark(#b42318, #ff8a80);
}

.log-warning {
    color: light-dark(#a15c00, #ffcc66);
}

/* ---------------------------------------------------------------------------
   Phones
   ------------------------------------------------------------------------- */

/* Tables use Bootstrap's sm:table-stacked: below 576px each row becomes a
   card. These rules make the cards compact: the first cell is the heading,
   labelled cells show "Label  value" on one line, actions wrap below. */
@container (width < 576px) {
    .sm\:table-stacked > tbody > tr > td.cell-primary {
        overflow-wrap: anywhere;
        padding-bottom: 0.25rem;
    }

    .sm\:table-stacked > tbody > tr > td[data-cell]:not(:first-child) {
        display: flex;
        flex-wrap: wrap;
        align-items: center;
        gap: 0.25rem 0.75rem;
        overflow-wrap: anywhere;
    }

    .sm\:table-stacked > tbody > tr > td[data-cell]:not(:first-child)::before {
        flex: 0 0 7.5rem;
        margin: 0;
        color: var(--bs-fg-3);
        font-size: 0.875rem;
        font-weight: 500;
    }

    .sm\:table-stacked > tbody > tr > td.cell-actions {
        display: flex;
        flex-wrap: wrap;
        gap: 0.375rem;
        justify-content: flex-start;
        text-align: start;
        white-space: normal;
        padding-top: 0.5rem;
    }

    .sm\:table-stacked > tbody > tr > td.cell-actions:empty {
        display: none;
    }

    .sm\:table-stacked > tbody > tr > td.cell-actions > * {
        margin: 0 !important;
    }

    .sm\:table-stacked .role-form {
        flex: 1 1 12rem;
        max-width: none;
    }
}

@media (width < 576px) {
    /* Navbar: brand, theme toggle and log out on the first row; page links on
       a second row that scrolls sideways if it doesn't fit. */
    .app-header nav {
        flex-wrap: wrap;
        row-gap: 0.25rem !important;
    }

    .app-header .app-brand {
        margin-right: auto;
    }

    .app-header .app-nav-links {
        order: 3;
        flex: 1 0 100%;
        overflow-x: auto;
        scrollbar-width: none;
        margin: 0 -0.5rem;
    }

    .app-header .app-nav-links .nav-link {
        white-space: nowrap;
        padding: 0.4rem 0.55rem;
        font-size: 0.95rem;
    }

    .app-main {
        padding-top: 1rem !important;
    }

    /* "name @ domain" inputs: let the domain show in full; the name field shrinks. */
    .address-input > input {
        flex: 1 1 5rem;
        min-width: 5rem;
    }

    .address-input > select {
        flex: 0 1 auto;
        width: auto;
        max-width: 70%;
    }

    /* Logs: one row of tabs that scrolls sideways instead of wrapping. */
    .log-tabs {
        flex-wrap: nowrap;
        overflow-x: auto;
        scrollbar-width: none;
    }

    .log-tab {
        white-space: nowrap;
        padding: 0.5rem 0.6rem;
    }

    .log-view {
        font-size: 0.75rem;
        padding: 0.5rem 0.625rem;
    }
}

/* Security page */
.stat-value {
    font-size: 1.75rem;
    font-weight: 600;
    line-height: 1.2;
}

.issue-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.issue-list > li + li {
    border-top: 1px solid var(--bs-border-color);
    margin-top: 0.75rem;
    padding-top: 0.75rem;
}

.issue-detail {
    margin: 0.25rem 0 0;
    padding-left: 1.25rem;
}

.window-switch {
    display: flex;
    gap: 0.375rem;
}

.window-switch .active {
    background-color: var(--bs-theme-bg, var(--bs-bg-2));
    color: var(--bs-theme-contrast, inherit);
}

/* Bootstrap 6 lays out a flex card header as a centred column; headers with
   a title and buttons need a row. */
.card-header.d-flex {
    flex-direction: row;
    text-align: start;
}

.account-facts dt {
    font-weight: 600;
}

.account-facts dd {
    margin-bottom: 0.75rem;
}

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

/* Mail */
.mail-layout {
    display: grid;
    grid-template-columns: 13rem minmax(0, 1fr);
    gap: 1.5rem;
    align-items: start;
}

.mail-folders {
    display: flex;
    flex-direction: column;
    gap: 0.125rem;
}

.mail-folder {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.5rem;
    padding: 0.4rem 0.75rem;
    border-radius: 0.375rem;
    color: inherit;
    text-decoration: none;
}

.mail-folder:hover {
    background-color: rgba(127, 127, 127, 0.1);
}

.mail-folder.active {
    background-color: rgba(127, 127, 127, 0.18);
    font-weight: 600;
}

.mail-row {
    display: block;
    padding: 0.6rem 1rem;
    border-bottom: 1px solid var(--bs-border-color);
    border-left: 3px solid transparent;
    color: inherit;
    text-decoration: none;
}

.mail-row:last-child {
    border-bottom: 0;
}

.mail-row:hover {
    background-color: rgba(127, 127, 127, 0.08);
}

.mail-row.unread {
    border-left-color: #0d6efd;
}

.mail-row-top {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
}

.mail-from,
.mail-subject {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.mail-subject,
.mail-date {
    color: var(--bs-fg-3);
}

.mail-date {
    flex-shrink: 0;
    font-size: 0.85rem;
}

.mail-row.unread .mail-from,
.mail-row.unread .mail-subject {
    font-weight: 600;
    color: inherit;
}

.mail-flag {
    color: #e0a800;
}

.mail-title {
    overflow-wrap: anywhere;
}

.mail-headers {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    gap: 0.25rem 1rem;
    margin: 0;
}

.mail-headers dt {
    font-weight: 400;
    color: var(--bs-fg-3);
}

.mail-headers dd {
    margin: 0;
    overflow-wrap: anywhere;
}

.mail-attachments {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: 0.75rem;
}

/* Email HTML assumes a white page, in dark mode too. */
.mail-frame {
    display: block;
    width: 100%;
    min-height: 12rem;
    border: 0;
    background: #fff;
}

.mail-text {
    margin: 0;
    padding: 1rem;
    font-family: inherit;
    font-size: 0.95rem;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

@media (width < 768px) {
    .mail-layout {
        grid-template-columns: minmax(0, 1fr);
        gap: 0.75rem;
    }

    .mail-folders {
        flex-direction: row;
        overflow-x: auto;
        scrollbar-width: none;
    }

    .mail-folder {
        white-space: nowrap;
    }
}

.mail-clip-icon {
    vertical-align: -0.125em;
}
