/* ==========================================================================
   vowlt — the one stylesheet. Order: tokens → base → controls → shell →
   forms → messages → lists → motion → pages. Every colour is a token and
   every token is a light-dark() pair, so nothing below the tokens knows which
   theme it is in. One column, one width, on every page: the rail sits beside
   it on a wide screen and becomes the bottom bar on a phone.
   ========================================================================== */

/* ---- Tokens ------------------------------------------------------------ */

:root {
    color-scheme: light dark;

    --bg:        light-dark(oklch(99% 0 0),       oklch(17% 0.01 260));
    --surface:   light-dark(oklch(96.5% 0 0),     oklch(21% 0.01 260));
    --border:    light-dark(oklch(90% 0 0),       oklch(29% 0.01 260));
    --text:      light-dark(oklch(22% 0.01 260),  oklch(93% 0 0));
    --muted:     light-dark(oklch(50% 0.01 260),  oklch(68% 0.01 260));
    --accent:    light-dark(oklch(52% 0.18 265),  oklch(75% 0.15 265));
    --on-accent: light-dark(white,                oklch(15% 0.02 265));
    --danger:    light-dark(oklch(52% 0.19 25),   oklch(72% 0.17 25));
    --success:   light-dark(oklch(52% 0.15 150),  oklch(75% 0.14 150));

    --radius: 8px;
    --space-1: 0.25rem;
    --space-2: 0.5rem;
    --space-3: 0.75rem;
    --space-4: 1rem;
    --space-6: 1.5rem;
    --space-8: 2rem;
    --measure: 40rem;                 /* the column — every page */
    --form-measure: 36rem;            /* a form inside it */
    --rail: 13rem;                    /* the nav beside it, wide screens */
    --bar: 4.25rem;                   /* the nav under it, phones */

    --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
    --font-mono: ui-monospace, "Cascadia Code", Menlo, Consolas, monospace;
}

/* The cookie override (Theme.cs). Absent attribute = follow the OS. */
:root[data-theme="light"] { color-scheme: light; }
:root[data-theme="dark"]  { color-scheme: dark; }

/* ---- Base -------------------------------------------------------------- */

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

html {
    font-family: var(--font);
    font-size: 15px;
    line-height: 1.5;
    -webkit-text-size-adjust: 100%;
}

body {
    margin: 0;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    background: var(--bg);
    color: var(--text);
}

h1, h2, h3 {
    margin: 0 0 var(--space-3);
    line-height: 1.2;
    letter-spacing: -0.01em;
    font-weight: 650;
}

h1 { font-size: 1.5rem; }
h2 { font-size: 1.15rem; margin-top: var(--space-8); }
h3 { font-size: 1rem; }

h1:focus { outline: none; }         /* FocusOnNavigate lands here */

p, ul, ol {
    margin: 0 0 var(--space-3);
}

a {
    color: var(--accent);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

small {
    font-size: 0.85rem;
    color: var(--muted);
}

code {
    font-family: var(--font-mono);
    font-size: 0.9em;
    padding: 0.1em 0.35em;
    border-radius: 4px;
    background: var(--surface);
}

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

/* Off-screen but read out: a page's h1 where the visible top is something else
   (the vault's tabs, a bookmark's card). */
.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
    border: 0;
}

/* ---- Controls ---------------------------------------------------------- */

button, .button, input, select, textarea {
    font: inherit;
    color: inherit;
    padding: 0.45rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
}

input, select, textarea {
    width: 100%;
    min-width: 0;                     /* may shrink inside a grid or flex track */
    background: var(--bg);
}

input:focus, select:focus, textarea:focus {
    outline: 2px solid var(--accent);
    outline-offset: -1px;
    border-color: var(--accent);
}

input[type="checkbox"], input[type="radio"] {
    width: auto;
    margin: 0;
    accent-color: var(--accent);
}

textarea {
    resize: vertical;
}

/* Chromium 135+: the select's picker is part of the page — themed with the tokens
   and inside the viewport (the native one is an OS window, which in device
   emulation lands off-screen). Browsers without it keep their native picker. */
select, ::picker(select) {
    appearance: base-select;
}

::picker(select) {
    margin-top: var(--space-1);
    padding: var(--space-1);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg);
    color: var(--text);
    box-shadow: 0 16px 40px -16px oklch(0% 0 0 / 0.45);
}

option {
    padding: 0.4rem 0.6rem;
    border-radius: 4px;
}

option:hover, option:focus-visible {
    background: var(--surface);
    outline: none;
}

option:checked {
    color: var(--accent);
    font-weight: 600;
}

option::checkmark {
    display: none;
}

button, .button {
    display: inline-flex;
    align-items: center;
    gap: 0.4em;
    cursor: pointer;
    font-weight: 500;
    white-space: nowrap;
    text-decoration: none;
}

button:hover, .button:hover {
    border-color: var(--muted);
    text-decoration: none;
}

.primary, .button {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--on-accent);
}

.primary:hover, .button:hover {
    border-color: var(--accent);
    filter: brightness(1.08);
}

.danger {
    color: var(--danger);
    border-color: color-mix(in oklch, var(--danger) 40%, var(--border));
    background: transparent;
}

.danger:hover {
    background: color-mix(in oklch, var(--danger) 10%, transparent);
    border-color: var(--danger);
}

/* ---- Shell ------------------------------------------------------------- */

/* Phone first: the column fills the width, the rail is a bar along the bottom. */
.shell {
    flex: 1;
    display: grid;
    grid-template-columns: minmax(0, 1fr);
}

main {
    width: 100%;
    max-width: var(--measure);
    margin: 0 auto;
    padding: var(--space-6) var(--space-4) calc(var(--bar) + var(--space-8));
}

main.bare {
    max-width: var(--form-measure);
    padding: 10vh var(--space-4) var(--space-8);
}

.rail {
    position: fixed;
    inset: auto 0 0 0;
    z-index: 10;
    display: flex;
    justify-content: space-around;
    align-items: center;
    height: var(--bar);
    padding: 0 var(--space-2);
    background: var(--bg);
    border-top: 1px solid var(--border);
}

.rail .brand {
    display: none;
}

/* Every rail item — links and the account button — is one shape. Direct children
   only: the menu lives inside the rail and has its own rows. */
.rail > a, .rail > .account {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.15rem;
    padding: 0.4rem 0.6rem;
    border: 0;
    border-radius: var(--radius);
    background: transparent;
    font-size: 0.7rem;
    font-weight: 500;
    line-height: 1;
    color: var(--muted);
}

.rail > a:hover, .rail > .account:hover {
    color: var(--text);
    text-decoration: none;
}

.rail > a.current {
    color: var(--accent);
}

.rail > a svg, .rail > .account svg {
    width: 1.5rem;
    height: 1.5rem;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

/* The one accent action: Save, or Log in. A round button on the bar. */
.rail .save {
    padding: 0.6rem;
    border-radius: 50%;
    color: var(--on-accent);
    background: var(--accent);
}

.rail .save span {
    display: none;
}

.rail .save:hover {
    color: var(--on-accent);
    filter: brightness(1.08);
}

/* The account button says "Account" on the bar and @handle in the rail. */
.rail .account .handle {
    display: none;
}

/* The account menu: a native popover, so the browser owns open/close. */
.menu {
    position: fixed;
    inset: auto var(--space-3) calc(var(--bar) + var(--space-2)) auto;
    margin: 0;
    min-width: 13rem;
    padding: var(--space-2);
    border: 1px solid var(--border);
    border-radius: calc(var(--radius) * 1.5);
    background: var(--bg);
    color: var(--text);
    box-shadow: 0 16px 40px -16px oklch(0% 0 0 / 0.45);
}

.menu:popover-open {
    display: grid;
    gap: var(--space-1);
}

.menu form {
    margin: 0;
}

/* Who is signed in, then the rows. */
.menu .me {
    margin: 0;
    padding: 0.5rem 0.75rem 0.25rem;
    font-weight: 600;
}

/* Menu rows: links and the Log out button look the same. */
.menu > a, .menu form:not(.theme) button {
    display: block;
    width: 100%;
    padding: 0.5rem 0.75rem;
    border: 0;
    border-radius: var(--radius);
    background: transparent;
    font-weight: 500;
    color: var(--text);
    text-align: left;
}

.menu > a:hover, .menu form:not(.theme) button:hover {
    background: var(--surface);
    text-decoration: none;
}

/* Theme switch: three submit buttons drawn as one segmented control. */
.theme {
    display: inline-flex;
    margin: var(--space-1) 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

.theme button {
    padding: 0.3rem 0.65rem;
    border: 0;
    border-radius: 0;
    background: transparent;
    color: var(--muted);
    line-height: 1;
}

.theme button + button {
    border-left: 1px solid var(--border);
}

.theme button[aria-pressed="true"] {
    background: var(--surface);
    color: var(--text);
}

/* Wide: rail on the left, the column beside it, both centred as one block. */
@media (min-width: 48rem) {
    .shell {
        grid-template-columns: var(--rail) minmax(0, var(--measure));
        justify-content: center;
        gap: var(--space-8);
    }

    main {
        margin: 0;
        padding-bottom: var(--space-8);
    }

    .rail {
        position: sticky;
        top: 0;
        inset: auto;
        height: 100dvh;
        flex-direction: column;
        justify-content: flex-start;
        align-items: stretch;
        gap: var(--space-1);
        padding: var(--space-4) var(--space-2);
        border-top: 0;
    }

    .rail .brand {
        display: block;
        margin: 0 0.9rem var(--space-4);
        font-weight: 700;
        font-size: 1.3rem;
        letter-spacing: -0.02em;
        color: var(--text);
    }

    .rail .brand:hover {
        color: var(--accent);
        text-decoration: none;
    }

    .rail > a, .rail > .account {
        flex-direction: row;
        gap: var(--space-3);
        padding: 0.6rem 0.9rem;
        border-radius: 999px;
        font-size: 1.05rem;
        line-height: 1.5;
        color: var(--text);
    }

    .rail > a:hover, .rail > .account:hover {
        background: var(--surface);
    }

    .rail > a.current {
        font-weight: 700;
        color: var(--text);
    }

    .rail .save {
        justify-content: center;
        margin-top: var(--space-3);
        padding: 0.6rem 0.9rem;
        border-radius: 999px;
        font-weight: 600;
    }

    .rail .save span {
        display: inline;
    }

    .rail .account {
        margin-top: auto;
    }

    .rail .account .handle {
        display: inline;
    }

    .rail .account .handle + .generic {    /* only when there is a handle to show instead */
        display: none;
    }

    .menu {
        inset: auto auto var(--space-8) var(--space-3);
    }
}

/* ---- Forms ------------------------------------------------------------- */

/* Any form in the page body is a stacked column; one-line forms opt out below.
   minmax(0, …) everywhere a grid holds a control: an implicit auto track refuses to
   shrink below a <select>'s intrinsic width and spills off a phone screen. */
main form {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: var(--space-4);
    max-width: var(--form-measure);
    margin: 0 0 var(--space-6);
}

main form label {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: var(--space-1);
    font-size: 0.9rem;
    font-weight: 500;
}

main form label small {
    font-weight: 400;
}

main form > button {
    justify-self: start;
}

/* One-line forms: the vault's capture bar, the search box, "add a member". */
.capture {
    display: flex;
    gap: var(--space-2);
}

.capture input {
    flex: 1;
    min-width: 0;
}

.add-member {
    grid-template-columns: 1fr auto;
    align-items: end;
}

/* Composers — the capture bar, create-a-group — span the list they feed, not the form column. */
.add-bookmark, .create-group {
    max-width: none;
}

.options summary {
    cursor: pointer;
    user-select: none;
    font-size: 0.9rem;
    color: var(--muted);
}

.options summary:hover {
    color: var(--text);
}

.options .fields {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: var(--space-4);
    margin-top: var(--space-3);
}

/* Wide enough: the three option fields sit side by side. */
@media (min-width: 40rem) {
    .options .fields {
        grid-template-columns: repeat(auto-fit, minmax(10rem, 1fr));
    }
}

/* The search box on /search: input, the "everyone" switch, the button, one line. */
main form[role="search"] {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    max-width: none;
}

main form[role="search"] input[type="search"] {
    flex: 1;
    min-width: 0;
}

main form[role="search"] .everyone {
    display: flex;
    align-items: center;
    gap: 0.35em;
    font-size: 0.85rem;
    font-weight: 400;
    color: var(--muted);
    white-space: nowrap;
}

/* ---- Messages ---------------------------------------------------------- */

/* One shape, tinted by --tone: warnings and the service's validation messages,
   inline where the form is. */
.warning, .errors {
    --tone: var(--danger);
    max-width: var(--form-measure);
    margin: 0 0 var(--space-4);
    padding: var(--space-3) var(--space-4);
    border: 1px solid color-mix(in oklch, var(--tone) 40%, var(--border));
    border-radius: var(--radius);
    background: color-mix(in oklch, var(--tone) 8%, var(--bg));
    color: var(--tone);
}

.errors {
    list-style: none;
}

.errors li + li {
    margin-top: var(--space-1);
}

/* The flash (Flash.cs): one message for the page just landed on, as a toast above
   the bar. A notice fades; a warning stays until the next navigation. */
.toast {
    position: fixed;
    left: 50%;
    bottom: calc(var(--bar) + var(--space-4));
    z-index: 20;
    transform: translateX(-50%);
    max-width: min(90vw, 28rem);
    margin: 0;
    padding: var(--space-3) var(--space-6);
    border-radius: 999px;
    background: var(--accent);
    color: var(--on-accent);
    font-weight: 500;
    text-align: center;
    box-shadow: 0 16px 40px -16px oklch(0% 0 0 / 0.45);
    animation: toast-out 0.4s ease-in 4s forwards;
}

.toast.warning {
    background: var(--danger);
    color: white;
    animation: none;
}

@keyframes toast-out {
    to {
        opacity: 0;
        visibility: hidden;
    }
}

@media (min-width: 48rem) {
    .toast {
        bottom: var(--space-6);
    }
}

.subtitle {
    margin-top: calc(-1 * var(--space-2));
    margin-bottom: var(--space-6);
    color: var(--muted);
}

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

.empty {
    padding: var(--space-8) var(--space-4);
    border: 1px dashed var(--border);
    border-radius: var(--radius);
    text-align: center;
    color: var(--muted);
}

.empty label {
    color: var(--accent);
    cursor: pointer;
}

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

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

/* ---- Lists ------------------------------------------------------------- */

.bookmarks, .hits, .people {
    list-style: none;
    padding: 0;
    margin: 0 0 var(--space-6);
    border-top: 1px solid var(--border);
}

.bookmarks > li, .hits > li, .people > li {
    padding: var(--space-4) 0;
    border-bottom: 1px solid var(--border);
}

/* Card anatomy (BookmarkCard): title + domain / bodies / meta line. */
.bookmark .title {
    font-weight: 600;
    color: var(--text);
    overflow-wrap: anywhere;
}

.bookmark .title:hover {
    color: var(--accent);
    text-decoration: none;
}

.bookmark .domain {
    margin-left: var(--space-2);
    font-size: 0.85rem;
    color: var(--muted);
    white-space: nowrap;
}

.bookmark .description, .bookmark .snippet {
    margin: var(--space-1) 0 0;
    color: var(--muted);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.bookmark .snippet {
    -webkit-line-clamp: 3;
}

.bookmark .notes {
    margin: var(--space-2) 0 0;
    padding-left: var(--space-3);
    border-left: 2px solid var(--accent);
}

.meta {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-1) var(--space-3);
    margin: var(--space-2) 0 0;
    font-size: 0.85rem;
    color: var(--muted);
}

.meta a {
    color: var(--muted);
}

.meta a:hover {
    color: var(--accent);
}

.meta .action {
    margin-left: auto;
}

.tag {
    padding: 0 0.55em;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--surface);
}

a.tag:hover {
    border-color: var(--accent);
    color: var(--accent);
    text-decoration: none;
}

.chip {
    padding: 0 0.55em;
    border-radius: 999px;
    font-weight: 500;
    color: var(--accent);
    background: color-mix(in oklch, var(--accent) 12%, var(--bg));
}

.status {
    display: inline-flex;
    align-items: center;
    gap: 0.4em;
}

.status::before {
    content: "";
    width: 0.5em;
    height: 0.5em;
    border-radius: 50%;
    background: currentColor;
}

.status.pending {
    color: var(--accent);
}

.status.pending::before {
    animation: pulse 1.2s ease-in-out infinite;
}

.status.failed, .status.gone {
    color: var(--danger);
}

@keyframes pulse {
    50% { opacity: 0.25; }
}

/* People and groups (PersonRow): avatar | name + handle + facts | one action. */
.people > li {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: center;
    column-gap: var(--space-3);
}

.people .avatar {
    width: 2.5rem;
    height: 2.5rem;
    font-size: 1.1rem;
}

.people .name {
    display: block;
    font-weight: 600;
    color: var(--text);
}

.people .facts {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-1) var(--space-3);
    margin: 0;
    font-size: 0.85rem;
    color: var(--muted);
}

.people form {
    margin: 0;
}

/* ---- Motion ------------------------------------------------------------ */

/* Full-page navigations crossfade (Chromium, Safari; others just navigate). */
@view-transition {
    navigation: auto;
}

::view-transition-old(root), ::view-transition-new(root) {
    animation-duration: 0.12s;
}

/* htmx: the results dim while a search is in flight (hx-indicator on /search). */
#search-results {
    transition: opacity 0.15s;
}

#search-results.htmx-request {
    opacity: 0.6;
}

@media (prefers-reduced-motion: reduce) {
    @view-transition {
        navigation: none;
    }

    .status.pending::before {
        animation: none;
    }
}

/* ---- Pages ------------------------------------------------------------- */

/* Landing: pitch, then a still of the product, in the one column. */
.hero {
    display: grid;
    gap: var(--space-6);
    padding: var(--space-6) 0 var(--space-8);
}

.hero h1 {
    font-size: 2.2rem;
    letter-spacing: -0.03em;
}

.pitch > p {
    max-width: 32rem;
    font-size: 1.1rem;
    color: var(--muted);
}

.actions {
    display: flex;
    align-items: center;
    gap: var(--space-4);
}

.demo {
    padding: var(--space-4);
    border: 1px solid var(--border);
    border-radius: calc(var(--radius) * 1.5);
    background: var(--surface);
    box-shadow: 0 24px 48px -32px oklch(0% 0 0 / 0.5);
}

.demo-search {
    margin-bottom: var(--space-3);
    padding: 0.45rem 0.75rem;
    border: 1px solid var(--accent);
    border-radius: var(--radius);
    background: var(--bg);
    outline: 2px solid var(--accent);
    outline-offset: -1px;
}

.demo-search::after {
    content: "";
    display: inline-block;
    width: 1px;
    height: 1em;
    margin-left: 1px;
    vertical-align: text-bottom;
    background: var(--text);
    animation: blink 1s steps(2) infinite;
}

@keyframes blink {
    to { opacity: 0; }
}

.demo .hits {
    margin: 0;
    border-top: 0;
}

.demo .hits > li:last-child {
    border-bottom: 0;
}

.how ol {
    list-style: none;
    padding: 0;
    display: grid;
    gap: var(--space-4);
    grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr));
    counter-reset: step;
}

.how li {
    padding: var(--space-4);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    counter-increment: step;
    color: var(--muted);
}

.how li::before {
    content: counter(step);
    display: inline-grid;
    place-items: center;
    width: 1.6rem;
    height: 1.6rem;
    margin-bottom: var(--space-2);
    border-radius: 50%;
    background: var(--accent);
    color: var(--on-accent);
    font-size: 0.8rem;
    font-weight: 600;
}

.how li strong {
    display: block;
    color: var(--text);
}

/* Vault: the owner switch is a tab strip over the list. */
.owners {
    margin-bottom: var(--space-4);
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-1);
    border-bottom: 1px solid var(--border);
}

.owners a {
    padding: 0.5rem 0.75rem;
    margin-bottom: -1px;
    border-bottom: 2px solid transparent;
    font-weight: 500;
    color: var(--muted);
}

.owners a:hover {
    color: var(--text);
    text-decoration: none;
}

.owners a.current {
    color: var(--text);
    border-bottom-color: var(--accent);
}

.owners a:last-child {
    margin-left: auto;
}

/* Who a page is about (ProfileHeader): avatar | name + handle | action,
   then bio and a line of facts across the full width. */
header.profile {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: center;
    column-gap: var(--space-4);
    row-gap: var(--space-2);
    padding: var(--space-4) 0 var(--space-6);
    margin-bottom: var(--space-4);
    border-bottom: 1px solid var(--border);
}

.avatar {
    display: grid;
    place-items: center;
    width: 3.5rem;
    height: 3.5rem;
    border-radius: 50%;
    background: color-mix(in oklch, var(--accent) 15%, var(--bg));
    color: var(--accent);
    font-size: 1.5rem;
    font-weight: 700;
}

header.profile h1 {
    margin: 0;
    font-size: 1.5rem;
}

header.profile .handle {
    color: var(--muted);
}

header.profile .handle:hover {
    color: var(--accent);
    text-decoration: none;
}

header.profile .bio, header.profile .facts {
    grid-column: 1 / -1;
    margin: 0;
}

header.profile .bio {
    font-size: 1.05rem;
}

header.profile .facts {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-1) var(--space-4);
    font-size: 0.9rem;
    color: var(--muted);
}

/* Bookmark detail: the card on its own page shows its whole description. */
.detail .description {
    display: block;
    -webkit-line-clamp: unset;
}

/* Welcome (BareLayout) */
.welcome {
    padding: var(--space-8);
    border: 1px solid var(--border);
    border-radius: calc(var(--radius) * 1.5);
    background: var(--surface);
}

.welcome > p {
    color: var(--muted);
}
