/*
 * The app bar: templates/partials/_nav.html, behaviour in static/js/app-header.js.
 *
 * One layout at every width: the menu button and brand on the left, the theme
 * and account buttons on the right, and a menu that slides in from the left.
 *
 * Every colour is a variable set on .app-header and set again under
 * body.dark-mode, and nothing else decides the header's colours. The old
 * navbar took its colour from the session's theme through Bootstrap's
 * bg-light, which is !important, while the page took dark mode from the
 * device's saved choice -- so after a login, or in the installed app, the page
 * could go dark under a white header.
 *
 * Class names are all ah-* so Bootstrap's navbar, nav-link and collapse rules
 * never reach it, and the rules below set what Bootstrap's reboot would
 * otherwise change on a, button and label.
 */

.app-header {
    --ah-h: 56px;
    --ah-bg: #ffffff;
    --ah-fg: #1f2937;
    --ah-muted: #5b6472;
    --ah-border: #e5e7eb;
    --ah-hover: #f1f3f6;
    --ah-active-bg: #e8f0fe;
    --ah-active-fg: #1a56db;
    --ah-accent: #2563eb;
    --ah-panel: #ffffff;
    --ah-shadow: 0 12px 32px rgba(16, 24, 40, .14), 0 2px 6px rgba(16, 24, 40, .08);
    --ah-danger: #c62828;
    --ah-avatar-bg: #dbe7fe;
    --ah-avatar-fg: #1e3a8a;
    --ah-word-a: #334155;
    --ah-word-b: #0891b2;
    --ah-switch-off: #c5cad3;

    position: relative;
    display: block;
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 15px;
    line-height: 1.25;
    color: var(--ah-fg);
    background: var(--ah-bg);
    border-bottom: 1px solid var(--ah-border);
    box-shadow: 0 1px 2px rgba(16, 24, 40, .04);
}

body.dark-mode .app-header {
    --ah-bg: #17191e;
    --ah-fg: #e6e8eb;
    --ah-muted: #a3aab6;
    --ah-border: #282c33;
    --ah-hover: #23272e;
    --ah-active-bg: rgba(96, 165, 250, .15);
    --ah-active-fg: #93c5fd;
    --ah-accent: #3b82f6;
    --ah-panel: #1d2026;
    --ah-shadow: 0 12px 32px rgba(0, 0, 0, .5), 0 2px 6px rgba(0, 0, 0, .35);
    --ah-danger: #f87171;
    --ah-avatar-bg: #1e3a8a;
    --ah-avatar-fg: #dbeafe;
    --ah-word-a: #e5e7eb;
    --ah-word-b: #22d3ee;
    --ah-switch-off: #4a505c;
}

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

.app-header [hidden] { display: none !important; }

.app-header :is(a, button, label):focus { outline: none; }
.app-header :is(a, button, label):focus-visible { outline: 2px solid var(--ah-accent); outline-offset: 2px; }

.ah-icon {
    width: 20px;
    height: 20px;
    flex: none;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
}

/* ------------------------------------------------------------------ the bar */

.ah-bar {
    height: var(--ah-h);
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 0 12px 0 8px;
}

.ah-brand {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    flex: none;
    min-width: 0;
    color: inherit;
    text-decoration: none !important;
}
.ah-brand:hover { color: inherit; }
.ah-mark { display: block; height: 30px; width: auto; }
.ah-word {
    font-size: 19px;
    font-weight: 800;
    letter-spacing: -.01em;
    white-space: nowrap;
}
.ah-word-a { color: var(--ah-word-a); }
.ah-word-b { color: var(--ah-word-b); }

.ah-actions {
    display: flex;
    align-items: center;
    gap: 4px;
    flex: none;
    margin-left: auto;
}

.ah-iconbtn {
    display: inline-grid;
    place-items: center;
    flex: none;
    width: 40px;
    height: 40px;
    padding: 0;
    border: 0;
    border-radius: 10px;
    background: transparent;
    color: var(--ah-muted);
    cursor: pointer;
    transition: background-color .15s, color .15s;
}
.ah-iconbtn:hover { background: var(--ah-hover); color: var(--ah-fg); }

/* One button, two icons: a moon offers dark mode, a sun offers light. */
.ah-theme .i-sun { display: none; }
body.dark-mode .ah-theme .i-sun { display: block; }
body.dark-mode .ah-theme .i-moon { display: none; }

/* Signed out: sign in / register. */
.ah-btn {
    display: inline-flex;
    align-items: center;
    height: 36px;
    padding: 0 14px;
    border: 1px solid var(--ah-border);
    border-radius: 8px;
    color: var(--ah-fg);
    font-size: 14.5px;
    font-weight: 600;
    white-space: nowrap;
    text-decoration: none !important;
}
.ah-btn:hover { background: var(--ah-hover); color: var(--ah-fg); }
.ah-btn.is-primary { background: var(--ah-accent); border-color: var(--ah-accent); color: #fff; }
.ah-btn.is-primary:hover { filter: brightness(1.08); color: #fff; }

/* ------------------------------------------------------------ account menu */

.ah-account { position: relative; }

.ah-user {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    height: 40px;
    padding: 0 8px 0 4px;
    border: 0;
    border-radius: 999px;
    background: transparent;
    color: var(--ah-fg);
    font: inherit;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background-color .15s;
}
.ah-user:hover,
.ah-user[aria-expanded="true"] { background: var(--ah-hover); }
.ah-user > .ah-icon { width: 16px; height: 16px; color: var(--ah-muted); }
.ah-user-name { max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.ah-avatar {
    display: inline-grid;
    place-items: center;
    flex: none;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--ah-avatar-bg);
    color: var(--ah-avatar-fg);
    font-size: 13px;
    font-weight: 700;
    letter-spacing: .02em;
}

.ah-menu {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    z-index: 1060;
    min-width: 240px;
    max-width: calc(100vw - 16px);
    padding: 6px;
    background: var(--ah-panel);
    color: var(--ah-fg);
    border: 1px solid var(--ah-border);
    border-radius: 12px;
    box-shadow: var(--ah-shadow);
}
.ah-menu-head {
    padding: 10px 10px 12px;
    margin-bottom: 6px;
    border-bottom: 1px solid var(--ah-border);
}
.ah-menu-name { font-size: 15px; font-weight: 700; }
.ah-menu-sub {
    margin-top: 2px;
    color: var(--ah-muted);
    font-size: 13px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.ah-menu-roles { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.ah-menu-role {
    padding: 2px 9px;
    border-radius: 999px;
    background: var(--ah-hover);
    color: var(--ah-muted);
    font-size: 12px;
    font-weight: 600;
}

.ah-item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    min-height: 40px;
    margin: 0;
    padding: 8px 10px;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: var(--ah-fg);
    font: inherit;
    font-size: 14.5px;
    text-align: left;
    text-decoration: none !important;
    cursor: pointer;
}
.ah-item:hover { background: var(--ah-hover); color: var(--ah-fg); }
.ah-item > .ah-icon { color: var(--ah-muted); }
.ah-item.is-danger,
.ah-item.is-danger > .ah-icon { color: var(--ah-danger); }

/* ------------------------------------------------------------------ the menu

   A plain list sliding in from the left: rows, not buttons. */

html.ah-lock,
html.ah-lock body { overflow: hidden; }

.ah-scrim {
    position: fixed;
    inset: 0;
    z-index: 1070;
    background: rgba(15, 23, 42, .45);
    opacity: 0;
    visibility: hidden;
    transition: opacity .2s, visibility 0s linear .2s;
}
.ah-drawer {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 1080;
    display: flex;
    flex-direction: column;
    width: min(320px, 86vw);
    overflow-y: auto;
    overscroll-behavior: contain;
    padding-bottom: env(safe-area-inset-bottom);
    background: var(--ah-panel);
    color: var(--ah-fg);
    box-shadow: var(--ah-shadow);
    transform: translateX(-102%);
    visibility: hidden;
    transition: transform .22s ease, visibility 0s linear .22s;
}
.ah-drawer:focus { outline: none; }

/* Visible the moment it opens (so focus can move into it at once), and hidden
   only once it has slid away. */
.app-header[data-drawer="open"] .ah-scrim {
    opacity: 1;
    visibility: visible;
    transition: opacity .2s, visibility 0s;
}
.app-header[data-drawer="open"] .ah-drawer {
    transform: none;
    visibility: visible;
    transition: transform .22s ease, visibility 0s;
}

.ah-drawer-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    height: var(--ah-h);
    flex: none;
    padding: 0 8px 0 16px;
    border-bottom: 1px solid var(--ah-border);
}

.app-header .ah-drawer-nav {
    display: flex;
    flex-direction: column;
    padding: 8px 0;
}
.ah-drawer-foot {
    display: flex;
    flex-direction: column;
    margin-top: auto;
    padding: 8px 0 12px;
    border-top: 1px solid var(--ah-border);
}
/* Nothing to show (an escort, with no install offer made): no empty band. */
.ah-drawer-foot:not(:has(> :not([hidden]))) { display: none; }

.ah-dlink {
    position: relative;
    display: flex;
    align-items: center;
    gap: 16px;
    width: 100%;
    min-height: 48px;
    margin: 0;
    padding: 0 20px;
    border: 0;
    border-radius: 0;
    background: transparent;
    color: var(--ah-fg);
    font: inherit;
    font-size: 15.5px;
    font-weight: 500;
    text-align: left;
    text-decoration: none !important;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}
.ah-dlink:hover,
.ah-dlink:active { background: var(--ah-hover); color: var(--ah-fg); }
.ah-dlink > .ah-icon { width: 22px; height: 22px; color: var(--ah-muted); }
.ah-dlink.is-active { background: var(--ah-active-bg); color: var(--ah-active-fg); font-weight: 600; }
.ah-dlink.is-active > .ah-icon { color: var(--ah-active-fg); }
.ah-dlink.is-active::before {
    content: '';
    position: absolute;
    top: 10px;
    bottom: 10px;
    left: 0;
    width: 3px;
    border-radius: 0 3px 3px 0;
    background: var(--ah-accent);
}

/* The language: a row like the others, with a two-way choice at its end. */
.ah-lang { cursor: default; }
.ah-lang:hover,
.ah-lang:active { background: transparent; }
.ah-seg {
    display: inline-flex;
    margin-left: auto;
    border: 1px solid var(--ah-border);
    border-radius: 8px;
    overflow: hidden;
}
.ah-seg button {
    padding: 5px 12px;
    border: 0;
    background: transparent;
    color: var(--ah-muted);
    font: inherit;
    font-size: 13px;
    font-weight: 700;
    letter-spacing: .03em;
    cursor: pointer;
}
.ah-seg button + button { border-left: 1px solid var(--ah-border); }
.ah-seg button:hover { background: var(--ah-hover); color: var(--ah-fg); }
.ah-seg button[aria-pressed="true"] { background: var(--ah-accent); color: #fff; cursor: default; }

/* The classic/new interface switch: a real checkbox, drawn as a switch. */
.ah-switch-row input {
    position: absolute;
    width: 1px;
    height: 1px;
    opacity: 0;
    pointer-events: none;
}
.ah-switch {
    position: relative;
    flex: none;
    width: 36px;
    height: 20px;
    margin-left: auto;
    border-radius: 999px;
    background: var(--ah-switch-off);
    transition: background-color .2s;
}
.ah-switch::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 1px 2px rgba(0, 0, 0, .25);
    transition: transform .2s;
}
.ah-switch-row input:checked + .ah-switch { background: var(--ah-accent); }
.ah-switch-row input:checked + .ah-switch::after { transform: translateX(16px); }
.ah-switch-row input:focus-visible + .ah-switch { outline: 2px solid var(--ah-accent); outline-offset: 2px; }

/* ------------------------------------------------------------ narrow screens */

@media (max-width: 599.98px) {
    .ah-bar { gap: 4px; padding: 0 6px; }
    .ah-mark { height: 26px; }
    .ah-word { font-size: 18px; }
    .ah-user { padding: 0 4px; }
    .ah-user-name,
    .ah-user > .ah-icon { display: none; }
}

@media (prefers-reduced-motion: reduce) {
    .app-header *,
    .app-header *::before,
    .app-header *::after { transition: none !important; }
}
