/*
 * Shared styling for every signed-in page.
 *
 * Two layers, deliberately separated:
 *   - the palette and the top navigation apply everywhere, including the
 *     dashboard, which has its own dense layout on top;
 *   - everything scoped to `body.page` is the plain "settings page" chrome
 *     (cards, forms, tables). The dashboard does NOT carry that class, so it
 *     keeps its own body rules without having to fight these.
 */

:root {
    --bg: #0f1420;
    --card: #161c2b;
    --card-2: #1c2436;
    --border: #263049;
    --text: #e6ebf5;
    --muted: #8b98b5;
    --accent: #4f8cff;
    --green: #35c98b;
    --amber: #f0b429;
    --red: #ef5f6b;
    --grey: #6b7793;
}

/* The scrollbar's width is always reserved, whether or not there is anything to
   scroll. Without this, anything that makes a page taller — opening one of the
   recovery actions, a message appearing — brings the scrollbar with it and
   shifts the whole layout sideways as it arrives. */
html {
    scrollbar-gutter: stable;
}

/* ---- Top navigation (all pages) ---- */

.page-nav {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 18px;
}

.page-nav a {
    color: var(--muted);
    background: var(--card-2);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 8px 16px;
    text-decoration: none;
    font: inherit;
    font-weight: 600;
}

.page-nav a.active {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

.page-nav .spacer {
    flex: 1;
}

/* ---- User menu ----
   A <details> rather than a scripted dropdown: it opens, closes and takes
   keyboard focus on its own. nav.js only adds the two behaviours the element
   does not have — closing on an outside click and on Escape. */

.user-menu {
    position: relative;
}

.user-menu > summary {
    display: flex;
    align-items: center;
    gap: 8px;
    /* The default triangle would sit next to our own caret. */
    list-style: none;
    cursor: pointer;
    user-select: none;
    color: var(--text);
    background: var(--card-2);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 7px 14px;
    font-weight: 600;
}

.user-menu > summary::-webkit-details-marker {
    display: none;
}

.user-menu > summary:hover,
.user-menu[open] > summary {
    border-color: var(--accent);
}

.user-menu > summary:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* Initials disc, so the control reads as an account menu at a glance. */
.user-menu .avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    font-size: 11px;
    text-transform: uppercase;
}

.user-menu .caret {
    color: var(--muted);
    font-size: 10px;
}

.user-menu-panel {
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    z-index: 40;
    min-width: 210px;
    background: var(--card-2);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 6px;
    box-shadow: 0 12px 32px rgba(0, 0, 0, .45);
}

.user-menu-panel .who {
    padding: 8px 10px 10px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 6px;
}

.user-menu-panel .who strong {
    display: block;
    font-size: 14px;
    /* Long usernames must not stretch the panel. */
    overflow-wrap: anywhere;
}

.user-menu-panel .who span {
    color: var(--muted);
    font-size: 12px;
}

/* Links and the logout button share one look, so the panel reads as one list. */
.user-menu-panel a,
.user-menu-panel button {
    display: block;
    width: 100%;
    text-align: left;
    background: none;
    border: none;
    border-radius: 7px;
    padding: 9px 10px;
    color: var(--text);
    text-decoration: none;
    font: inherit;
    cursor: pointer;
}

.user-menu-panel a:hover,
.user-menu-panel button:hover {
    background: rgba(79, 140, 255, .14);
}

.user-menu-panel form {
    margin: 0;
}

.user-menu-panel button {
    color: var(--red);
}

/* ---- Account settings: rail on the left, one section on the right ----
   The account area is half a dozen small pages rather than one long one, so
   the menu is what holds them together. Every settings page lays out the same
   way:

       <div class="settings">
           <nav th:replace="~{fragments/nav :: settingsNav('password')}"></nav>
           <main class="settings-main"> … </main>
       </div>

   The rules below are scoped to `body.page` where they have to out-rank the
   settings-page chrome further down (h2 in particular) — plain `.settings-nav
   h2` would lose to `body.page h2`. */

.settings {
    display: grid;
    /* Narrow on purpose: it holds six short labels, and the section beside it
       is the page. */
    grid-template-columns: 220px minmax(0, 1fr);
    gap: 28px;
    /* Out of body.page's 24px padding on three sides, so the rail reaches the
       window edge and runs to the bottom. */
    margin: 0 -24px -24px;
}

.settings-nav {
    background: var(--card);
    border-right: 1px solid var(--border);
    padding: 22px 14px 30px;
    /* Reaches the foot of the window on a short page: 24px of body padding,
       the ~39px top navigation and the 18px below it. Longer content stretches
       the rail past this on its own. */
    min-height: calc(100vh - 81px);
}

body.page .settings-nav h2 {
    margin: 0 0 6px;
    padding: 0 12px;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--muted);
}

/* A heading and its items are one block; the gap belongs between the groups. */
.settings-nav h2 + ul {
    margin: 0 0 22px;
}

.settings-nav ul {
    list-style: none;
    padding: 0;
    margin: 0;
}

.settings-nav a {
    display: block;
    color: var(--muted);
    border-radius: 8px;
    padding: 7px 12px;
    text-decoration: none;
    font-weight: 600;
}

.settings-nav a:hover {
    color: var(--text);
    background: var(--card-2);
}

.settings-nav a.active {
    color: #fff;
    background: var(--card-2);
    /* The rail is flush against the content, so the marker sits inside it. */
    box-shadow: inset 2px 0 0 var(--accent);
}

.settings-main {
    /* Forms are unreadable at monitor width; the section stops before that and
       stays against the rail rather than drifting into the middle. */
    max-width: 900px;
    padding: 0 24px 24px 0;
}

/* Cards down the page rather than the two columns of `.grid`: beside the rail
   there is no room for those until the window is very wide indeed. */
body.page .cards {
    display: grid;
    gap: 18px;
}

/* ---- Settings-page chrome (opt in with <body class="page">) ---- */

body.page {
    margin: 0;
    padding: 24px;
    background: var(--bg);
    color: var(--text);
    font: 14px/1.5 -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

body.page * {
    box-sizing: border-box;
}

body.page h1,
body.page h2 {
    margin: 0 0 16px;
}

body.page h1 {
    font-size: 22px;
}

body.page h2 {
    font-size: 17px;
}

body.page .muted {
    color: var(--muted);
}

body.page .grid {
    display: grid;
    grid-template-columns: minmax(300px, 430px) minmax(420px, 1fr);
    gap: 18px;
}

body.page .card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 20px;
}

body.page label {
    display: block;
    color: var(--muted);
    margin: 13px 0 5px;
}

body.page input,
body.page select {
    width: 100%;
    color: var(--text);
    background: var(--card-2);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px 12px;
    font: inherit;
}

body.page input:focus,
body.page select:focus {
    outline: none;
    border-color: var(--accent);
}

/* ---- Password box with a show/hide toggle inside its right edge ----
   Markup is fragments/forms :: revealPassword, behaviour is js/password-reveal.js.
   The wrapper holds nothing but the input, so the button can be sized against
   it; a margin below the input collapses out and does not stretch the hit area. */

body.page .field {
    position: relative;
}

body.page .field input {
    padding-right: 42px;
}

body.page .reveal {
    position: absolute;
    top: 0;
    right: 0;
    width: 40px;
    height: 100%;
    margin: 0;
    padding: 0;
    background: none;
    border: none;
    border-radius: 0 8px 8px 0;
    color: var(--muted);
    display: flex;
    align-items: center;
    justify-content: center;
}

/* `hidden` alone would lose to the display above, and the button is meant to
   stay away until the script has something to attach to it. */
body.page .reveal[hidden] {
    display: none;
}

body.page .reveal:hover {
    color: var(--text);
}

body.page .reveal:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: -2px;
}

body.page .reveal svg {
    width: 18px;
    height: 18px;
    display: block;
}

/* Which eye shows follows the button's own pressed state, so the script has
   one thing to set rather than three. */
body.page .reveal .eye-closed,
body.page .reveal[aria-pressed="true"] .eye-open {
    display: none;
}

body.page .reveal[aria-pressed="true"] .eye-closed {
    display: block;
}

/* Buttons outside the nav; .page-nav and .user-menu style their own. */
body.page button {
    color: var(--muted);
    background: var(--card-2);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 8px 16px;
    cursor: pointer;
    font: inherit;
    font-weight: 600;
}

body.page button.primary {
    width: 100%;
    margin-top: 18px;
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

body.page button.danger {
    color: var(--red);
}

body.page button[disabled] {
    opacity: .55;
    cursor: default;
}

body.page .message {
    border-radius: 8px;
    padding: 10px 12px;
    margin-bottom: 14px;
}

body.page .success {
    color: var(--green);
    border: 1px solid rgba(53, 201, 139, .45);
    background: rgba(53, 201, 139, .10);
}

body.page .error {
    color: var(--red);
    border: 1px solid rgba(239, 95, 107, .45);
    background: rgba(239, 95, 107, .10);
}

body.page table {
    width: 100%;
    border-collapse: collapse;
}

body.page th,
body.page td {
    padding: 10px 8px;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

body.page th {
    color: var(--muted);
}

body.page td.stamp {
    color: var(--muted);
    white-space: nowrap;
}

/* A pill carrying a yes/no state: two-factor on, email verified, and so on. */
body.page .status {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 999px;
    border: 1px solid var(--border);
}

body.page .status.on {
    color: var(--green);
    border-color: rgba(53, 201, 139, .45);
}

body.page .status.off {
    color: var(--muted);
}

body.page .inline-form {
    display: flex;
    align-items: center;
    gap: 8px;
}

body.page .inline-form select {
    width: auto;
    min-width: 105px;
    padding: 6px 8px;
}

body.page .inline-form button {
    padding: 6px 10px;
}

@media (max-width: 850px) {
    body.page .grid {
        grid-template-columns: 1fr;
    }

    /* No room for a rail: the menu becomes a strip above the section, and the
       group headings go — six labels in a row explain themselves. */
    .settings {
        grid-template-columns: 1fr;
        gap: 0;
    }

    .settings-nav {
        min-height: 0;
        border-right: none;
        border-bottom: 1px solid var(--border);
        padding: 12px;
        margin-bottom: 20px;
    }

    body.page .settings-nav h2 {
        display: none;
    }

    .settings-nav ul,
    .settings-nav h2 + ul {
        display: flex;
        flex-wrap: wrap;
        gap: 4px;
        margin: 0;
    }

    .settings-nav a.active {
        box-shadow: none;
        border-bottom: 2px solid var(--accent);
    }

    .settings-main {
        padding: 0 24px 24px;
    }
}
