/* Design tokens. Every color, size and radius comes from here. */
:root {
    --color-bg: #f7f7f8;
    --color-surface: #ffffff;
    --color-text: #1d1d1f;
    --color-muted: #6b6b73;
    --color-border: #e2e2e6;
    --color-accent: #2f6fde;
    --color-on-accent: #ffffff;
    --color-danger: #c62828;

    --font-sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    --font-size-base: 1rem;
    --font-size-small: 0.85rem;

    --space-1: 0.25rem;
    --space-2: 0.5rem;
    --space-3: 1rem;
    --space-4: 1.5rem;
    --space-5: 2.5rem;

    --radius: 8px;
    --content-width: 72rem;
}

@media (prefers-color-scheme: dark) {
    :root {
        --color-bg: #151517;
        --color-surface: #1f1f23;
        --color-text: #ececf0;
        --color-muted: #9a9aa3;
        --color-border: #2e2e34;
        --color-accent: #6b9cf0;
        --color-on-accent: #10131a;
        --color-danger: #ef6b6b;
    }
}

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

/* The search hides cards and links with the hidden attribute: it must win over any display rule */
[hidden] {
    display: none !important;
}

body {
    margin: 0;
    background: var(--color-bg);
    color: var(--color-text);
    font-family: var(--font-sans);
    font-size: var(--font-size-base);
    line-height: 1.5;
}

a {
    color: var(--color-accent);
}

.site-header {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-3);
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
}

.brand {
    font-weight: 700;
    color: var(--color-text);
    text-decoration: none;
}

.container {
    max-width: var(--content-width);
    margin: 0 auto;
    padding: var(--space-4) var(--space-3);
}

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

.site-header .session {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: var(--space-3);
}

.container.narrow {
    max-width: 40rem;
}

.prose h2 {
    margin-top: var(--space-5);
    font-size: 1.15rem;
}

.button {
    display: inline-block;
    padding: var(--space-2) var(--space-4);
    border-radius: var(--radius);
    background: var(--color-accent);
    color: var(--color-on-accent);
    font-weight: 600;
    text-decoration: none;
}

.button-link {
    padding: 0;
    border: 0;
    background: none;
    color: var(--color-accent);
    font: inherit;
    font-size: var(--font-size-small);
    cursor: pointer;
}

.notice {
    padding: var(--space-2) var(--space-3);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    background: var(--color-surface);
}

.notice-error {
    border-color: var(--color-danger);
    color: var(--color-danger);
}

/* A message that floats over the page for a few seconds (app.js) */
.toast {
    position: fixed;
    left: 50%;
    bottom: var(--space-4);
    transform: translateX(-50%);
    z-index: 10;
    width: max-content;
    max-width: calc(100vw - 2 * var(--space-4));
    box-shadow: 0 2px 8px rgb(0 0 0 / 0.2);
}

.toast[hidden] {
    display: none;
}

.fine-print {
    margin-top: var(--space-4);
    color: var(--color-muted);
    font-size: var(--font-size-small);
}

.site-footer {
    padding: var(--space-4) var(--space-3);
    text-align: center;
    font-size: var(--font-size-small);
}

.board {
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
}

.collection input[type="text"] {
    flex: 1;
    min-width: 0;
    padding: var(--space-2) var(--space-3);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    background: var(--color-surface);
    color: var(--color-text);
    font: inherit;
}

.form-actions .button {
    border: 0;
    font: inherit;
    cursor: pointer;
}

/* One column on phones, a grid on wider screens */
/* "New collection": a square "+" under the last card, on the left */
.add-collection {
    align-self: flex-start;
    width: 2.75rem;
    height: 2.75rem;
    padding: 0;
    border: 1px solid var(--color-accent);
    background: var(--color-surface);
    color: var(--color-accent);
    font-size: 1.75rem;
    line-height: 1;
    cursor: pointer;
}

.collections {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 18rem), 1fr));
    gap: var(--space-3);
    /* Each card as tall as its content, not as the tallest card in its row */
    align-items: start;
}

/* Masonry (set up by app.js): thin rows, each card spans what its height needs */
.collections.masonry {
    grid-auto-rows: 4px;
    row-gap: 0;
}

.collection {
    padding: var(--space-3);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    background: var(--color-surface);
    /* Partly see-through: only the background, so text and icons stay solid */
    background: color-mix(in srgb, var(--color-surface) 75%, transparent);
    backdrop-filter: blur(6px);
}

/* The blur gives each card its own stacking context, so a menu can only rise
   above the other cards if its whole card does */
.collection:has(.menu[open]) {
    z-index: 1;
}

.collection-header {
    display: flex;
    align-items: flex-start;
    gap: var(--space-2);
}

.collection-name {
    margin: 0;
    font-size: 1.05rem;
    overflow-wrap: anywhere;
}


.links {
    margin: var(--space-2) 0 0;
    padding: 0;
    list-style: none;
}

.links li {
    padding: var(--space-1) 0;
    overflow-wrap: anywhere;
}

.links a {
    text-decoration: none;
}

.links a:hover {
    text-decoration: underline;
}

.collection label {
    display: block;
    margin-bottom: var(--space-1);
    font-size: var(--font-size-small);
    color: var(--color-muted);
}

.collection.editing input[type="text"] {
    width: 100%;
}

.form-actions {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    margin-top: var(--space-2);
}

.empty {
    color: var(--color-muted);
    font-size: var(--font-size-small);
}

.button-link.danger {
    color: var(--color-danger);
}

.button.danger {
    background: var(--color-danger);
}

.link {
    display: flex;
    align-items: flex-start;
    gap: var(--space-2);
}

.favicon {
    flex: none;
    margin-top: 0.2rem;
    /* Icons come in any shape; keep theirs inside the square */
    object-fit: contain;
}

/* Border and padding inside the 32px, so identicons line up with favicons */
.favicon.identicon {
    box-sizing: border-box;
    padding: 2px;
    border: 1px solid var(--color-border);
    border-radius: 4px;
}

.link-body {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

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

.link-meta {
    color: var(--color-muted);
    font-size: var(--font-size-small);
}

.link.editing {
    display: block;
}

.link.editing input[type="text"] {
    width: 100%;
    margin-bottom: var(--space-2);
}

.add-link {
    display: flex;
    gap: var(--space-2);
    margin-top: var(--space-3);
}

.add-link input {
    flex: 1;
    min-width: 0;
    padding: var(--space-1) var(--space-2);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    background: var(--color-bg);
    color: var(--color-text);
    font: inherit;
}

.add-link .button {
    padding: var(--space-1) var(--space-3);
    border: 0;
    font: inherit;
    cursor: pointer;
}

.notice.duplicate {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
    align-items: baseline;
    margin-top: var(--space-2);
}



.members {
    margin-top: var(--space-3);
    padding-top: var(--space-3);
    border-top: 1px solid var(--color-border);
}

.members-header {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
}

.members h3 {
    margin: 0 0 var(--space-2);
    font-size: var(--font-size-base);
}

.member-list {
    margin: 0 0 var(--space-3);
    padding: 0;
    list-style: none;
}

.member {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-1) var(--space-2);
    padding: var(--space-1) 0;
}

.member-who {
    display: flex;
    flex-direction: column;
    min-width: 0;
    overflow-wrap: anywhere;
}

.member-email,
.member-role {
    color: var(--color-muted);
    font-size: var(--font-size-small);
}

.member-controls {
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.inline-form {
    margin: 0;
}

.members select,
.share-form input {
    padding: var(--space-1) var(--space-2);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    background: var(--color-bg);
    color: var(--color-text);
    font: inherit;
}

.share-form {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
}

.share-form input {
    flex: 1 1 12rem;
    min-width: 0;
}

.share-form .button {
    padding: var(--space-1) var(--space-3);
    border: 0;
    font: inherit;
    cursor: pointer;
}

/* Shown while htmx waits for the server, which visits the link (up to 5 s) */
.add-link .busy {
    display: none;
    align-self: center;
    color: var(--color-muted);
    font-size: var(--font-size-small);
}

.add-link.htmx-request .busy {
    display: inline;
}

.search {
    margin-bottom: var(--space-3);
}

.search input {
    width: 100%;
    padding: var(--space-2) var(--space-3);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    background: var(--color-surface);
    color: var(--color-text);
    font: inherit;
}

.search .empty {
    margin: var(--space-2) 0 0;
}

/* Ordering is for mouse users only: drag a collection by its name, a link by its title */
@media (hover: hover) and (pointer: fine) {
    [data-sortable="board"] .collection-name {
        cursor: grab;
    }

    .board.searching [data-sortable="board"] .collection-name {
        cursor: auto;
    }
}

.sortable-ghost {
    opacity: 0.4;
}

.sortable-chosen .collection-name {
    cursor: grabbing;
}

/* Header: brand, search, then "New collection" and the session on the right */
.site-header {
    flex-wrap: wrap;
}

.header-search {
    width: 16rem;
    max-width: 100%;
    padding: var(--space-1) var(--space-2);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    background: var(--color-bg);
    color: var(--color-text);
    font: inherit;
    font-size: var(--font-size-small);
}

.button-small {
    padding: var(--space-1) var(--space-3);
    border: 0;
    font: inherit;
    font-size: var(--font-size-small);
    cursor: pointer;
}

/* Phones: the search takes its own row under the brand and buttons */
@media (max-width: 40rem) {
    .header-search {
        order: 3;
        width: 100%;
    }
}

#search-empty {
    margin: 0 0 var(--space-3);
}

.modal {
    width: min(26rem, calc(100% - 2 * var(--space-3)));
    padding: var(--space-4);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    background: var(--color-surface);
    color: var(--color-text);
}

.modal::backdrop {
    background: rgb(0 0 0 / 0.4);
}

.modal h2 {
    margin: 0 0 var(--space-3);
    font-size: 1.1rem;
}

.modal label {
    display: block;
    margin-bottom: var(--space-1);
    color: var(--color-muted);
    font-size: var(--font-size-small);
}

.modal input[type="text"] {
    width: 100%;
    padding: var(--space-2) var(--space-3);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    background: var(--color-bg);
    color: var(--color-text);
    font: inherit;
}

.modal .notice {
    margin: var(--space-2) 0 0;
}

.modal .form-actions {
    margin-top: var(--space-3);
}

.site-footer .version {
    color: var(--color-muted);
}

/* Computer-only features (PRD): hidden on touch screens */
@media not ((hover: hover) and (pointer: fine)) {
    .desktop-only {
        display: none;
    }
}

.account-delete .decision {
    margin: 0 0 var(--space-3);
    padding: var(--space-2) var(--space-3);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
}

.account-delete .decision.missing {
    border-color: var(--color-danger);
}

.account-delete legend {
    padding: 0 var(--space-1);
    font-weight: 600;
}

.decision-users {
    margin-left: var(--space-2);
    color: var(--color-muted);
    font-size: var(--font-size-small);
    font-weight: normal;
}

.account-delete .decision label {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
    margin-right: var(--space-4);
}

.account-delete #confirm-email {
    width: 100%;
    margin-top: var(--space-1);
    padding: var(--space-2) var(--space-3);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    background: var(--color-surface);
    color: var(--color-text);
    font: inherit;
}

/* Collection menu: the ⋮ button at the top right of each card */
.collection-name {
    flex: 1;
    min-width: 0;
}

.menu {
    position: relative;
    flex: none;
}

.menu-button {
    list-style: none;
    padding: 0 var(--space-2);
    border-radius: var(--radius);
    color: var(--color-muted);
    font-size: 1.2rem;
    line-height: 1.4;
    cursor: pointer;
    user-select: none;
}

.menu-button::-webkit-details-marker {
    display: none;
}

.menu-button:hover,
.menu[open] .menu-button {
    background: var(--color-bg);
    color: var(--color-text);
}

.menu-items {
    position: absolute;
    top: 100%;
    right: 0;
    z-index: 10;
    display: flex;
    flex-direction: column;
    min-width: 13rem;
    margin-top: var(--space-1);
    padding: var(--space-1) 0;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    background: var(--color-surface);
    box-shadow: 0 6px 18px rgb(0 0 0 / 0.15);
}

.menu-items form {
    margin: 0;
}

.menu-items button {
    width: 100%;
    padding: var(--space-2) var(--space-3);
    border: 0;
    background: none;
    color: var(--color-text);
    font: inherit;
    text-align: left;
    cursor: pointer;
}

.menu-items button:hover {
    background: var(--color-bg);
}

.menu-items button.danger {
    color: var(--color-danger);
}

.menu-info {
    margin: 0;
    padding: var(--space-1) var(--space-3) var(--space-2);
    border-bottom: 1px solid var(--color-border);
    color: var(--color-muted);
    font-size: var(--font-size-small);
}

/* Links: the menu sits quietly at the end of the row */
.link-menu .menu-button {
    font-size: 1rem;
}

.link:not(:hover) .link-menu:not([open]) .menu-button {
    opacity: 0.5;
}

@media not ((hover: hover) and (pointer: fine)) {
    .link:not(:hover) .link-menu:not([open]) .menu-button {
        opacity: 1;
    }
}

/* User menu: the name in the header opens it */
.user-button {
    list-style: none;
    padding: var(--space-1) var(--space-2);
    border-radius: var(--radius);
    color: var(--color-text);
    font-size: var(--font-size-small);
    cursor: pointer;
    user-select: none;
}

.user-button::-webkit-details-marker {
    display: none;
}

.user-button::after {
    content: " \25BE";
    color: var(--color-muted);
}

.user-button:hover,
.user-menu[open] .user-button {
    background: var(--color-bg);
}

.menu-items a {
    display: block;
    padding: var(--space-2) var(--space-3);
    color: var(--color-text);
    text-decoration: none;
}

.menu-items a:hover {
    background: var(--color-bg);
}

/* Account page */
.account-section {
    margin-top: var(--space-4);
}

.account-section h2 {
    font-size: 1.1rem;
}

.account-section label {
    display: block;
    margin: var(--space-3) 0 var(--space-1);
    color: var(--color-muted);
    font-size: var(--font-size-small);
}

.account-section input {
    width: 100%;
    padding: var(--space-2) var(--space-3);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    background: var(--color-surface);
    color: var(--color-text);
    font: inherit;
}

.account-section input[readonly] {
    background: var(--color-bg);
    color: var(--color-muted);
}

.account-section .fine-print {
    margin-top: var(--space-1);
}

.inline-field {
    display: flex;
    gap: var(--space-2);
}

.inline-field .button {
    border: 0;
    font: inherit;
    cursor: pointer;
}

.stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(10rem, 1fr));
    gap: var(--space-3);
    margin: 0;
}

.stats div {
    padding: var(--space-3);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    background: var(--color-surface);
}

.stats dt {
    color: var(--color-muted);
    font-size: var(--font-size-small);
}

.stats dd {
    margin: var(--space-1) 0 0;
    font-size: 1.5rem;
    font-weight: 600;
}

/* Administration pages */
.admin-nav {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
    border-bottom: 1px solid var(--color-border);
    padding-bottom: var(--space-2);
}

.admin-nav a {
    padding: var(--space-1) var(--space-3);
    border-radius: var(--radius);
    color: var(--color-muted);
    text-decoration: none;
}

.admin-nav a.current {
    background: var(--color-surface);
    color: var(--color-text);
    font-weight: 600;
}

.admin-list {
    margin: var(--space-3) 0 0;
    padding: 0;
    list-style: none;
}

.admin-list li {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-2) 0;
    border-bottom: 1px solid var(--color-border);
}

.admin-list-text {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    overflow-wrap: anywhere;
}

.icon-row {
    flex-wrap: wrap;
}

.icon-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-2) var(--space-3);
}

.icon-actions form {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-2);
}

.icon-actions input[type="file"] {
    max-width: 14rem;
    font-size: var(--font-size-small);
}

.pending {
    color: var(--color-danger);
}

.stats-table {
    width: 100%;
    margin-top: var(--space-3);
    border-collapse: collapse;
    font-variant-numeric: tabular-nums;
}

.stats-table th,
.stats-table td {
    padding: var(--space-2) var(--space-3);
    border-bottom: 1px solid var(--color-border);
    text-align: right;
}

.stats-table th:first-child {
    text-align: left;
    font-weight: normal;
    color: var(--color-muted);
}

.stats-table thead th {
    color: var(--color-muted);
    font-size: var(--font-size-small);
    font-weight: 600;
}
