/*
 * Global page structure and the reading surface.
 * Mobile-first; desktop is an enhancement.
 */

.layout {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.layout__main {
    flex: 1;
    width: 100%;
    max-width: var(--measure);
    margin: 0 auto;
    padding: var(--space-lg) var(--space-md) var(--space-3xl);
}

/*
 * On desktop the reading column would otherwise float in a wide empty field.
 * Hairline rules down each side give it a defined edge — the margins of a page
 * — running full height because the main region already fills the viewport.
 * Extra inner padding keeps the text off the rules.
 */
@media (min-width: 768px) {
    .layout__main {
        padding-left: var(--space-xl);
        padding-right: var(--space-xl);
        border-inline: 1px solid var(--color-border);
    }
}

.skip-link {
    position: absolute;
    top: var(--space-sm);
    left: var(--space-sm);
    z-index: 100;
    padding: var(--space-sm) var(--space-md);
    background-color: var(--color-surface);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
    transform: translateY(-200%);
}

.skip-link:focus {
    transform: translateY(0);
}

/* ---------------------------------------------------------- note prose -- */

/*
 * The note is the page. No card, no chrome — the reading column sits directly
 * on the background so nothing competes with the text.
 */
.note {
    font-family: var(--font-reading);
    font-size: 1.0625rem;
    line-height: 1.7;
    color: var(--color-text);
}

@media (min-width: 768px) {
    .note {
        font-size: 1.125rem;
    }
}

.note > * + * {
    margin-top: var(--space-md);
}

.note h1,
.note h2,
.note h3,
.note h4 {
    font-family: var(--font-ui);
    line-height: 1.25;
    letter-spacing: -0.011em;
    color: var(--color-text);
}

.note h1 {
    font-size: 1.5rem;
    font-weight: 700;
}

.note h2 {
    font-size: 1.25rem;
    font-weight: 700;
    margin-top: var(--space-xl);
}

.note h3 {
    font-size: 1.125rem;
    font-weight: 600;
    margin-top: var(--space-lg);
}

.note h4 {
    font-size: 1rem;
    font-weight: 600;
}

@media (min-width: 768px) {
    .note h1 {
        font-size: 1.75rem;
    }

    .note h2 {
        font-size: 1.375rem;
    }
}

/*
 * Heading anchors are wikilink targets (FR-007). The permalink is an empty
 * inline anchor carrying the id; the offset keeps the heading clear of the
 * sticky bar when jumped to.
 */
.note .heading-permalink {
    scroll-margin-top: 4.5rem;
}

.note ul,
.note ol {
    padding-left: var(--space-lg);
}

.note li + li {
    margin-top: var(--space-xs);
}

.note blockquote {
    padding-left: var(--space-md);
    border-left: 3px solid var(--color-border);
    color: var(--color-text-secondary);
    font-style: italic;
}

.note code {
    font-family: var(--font-mono);
    font-size: 0.875em;
    padding: 0.15em 0.35em;
    background-color: var(--color-border-subtle);
    border-radius: var(--radius-sm);
}

.note pre {
    padding: var(--space-md);
    background-color: var(--color-surface-raised);
    border: 1px solid var(--color-border-subtle);
    border-radius: var(--radius-md);
    overflow-x: auto;
}

.note pre code {
    padding: 0;
    background: none;
    font-size: 0.875rem;
}

.note img {
    border-radius: var(--radius-md);
}

.note hr {
    height: 1px;
    border: 0;
    margin: var(--space-xl) 0;
    background-color: var(--color-border-subtle);
}

/* Tables must scroll inside themselves, never widen the page. */
.note__table-scroll {
    overflow-x: auto;
}

.note table {
    width: 100%;
    border-collapse: collapse;
    font-family: var(--font-ui);
    font-size: 0.9375rem;
}

.note th,
.note td {
    padding: var(--space-sm) var(--space-md);
    text-align: left;
    border-bottom: 1px solid var(--color-border-subtle);
}

.note th {
    font-weight: 600;
    color: var(--color-text-secondary);
}

/* Task lists render as content, not form controls. */
.note input[type="checkbox"] {
    margin-right: var(--space-xs);
    accent-color: var(--color-primary);
}

.note li:has(> input[type="checkbox"]) {
    list-style: none;
    margin-left: calc(var(--space-lg) * -1);
}

/* ------------------------------------------------------------ wikilinks -- */

/*
 * The signature of this reader.
 *
 * A resolved link is quiet — it is the normal state and most of a note is
 * links. A dead link is NOT an error: in a personal vault an unresolved
 * `[[name]]` is a note not yet written. It reads as deferred, not broken,
 * so it takes muted text and a dotted rule rather than an alarm colour.
 */

.wikilink {
    color: var(--color-primary);
    text-decoration: underline;
    text-decoration-color: color-mix(in srgb, var(--color-primary) 35%, transparent);
    text-decoration-thickness: 1px;
    text-underline-offset: 2px;
    transition: text-decoration-color var(--transition-fast);
}

.wikilink:hover {
    text-decoration-color: var(--color-primary);
}

.wikilink--dead {
    color: var(--color-text-muted);
    text-decoration: underline dotted;
    text-decoration-thickness: 1px;
    text-underline-offset: 3px;
    cursor: default;
}

/* An embedded PDF is a link, never an inline embed (FR-009). */
.embed-link {
    display: inline-flex;
    align-items: center;
    gap: var(--space-xs);
    font-family: var(--font-ui);
    font-size: 0.9375rem;
}

.embed-link::before {
    content: "";
    flex: none;
    width: 0.75rem;
    height: 0.9375rem;
    background-color: currentcolor;
    clip-path: polygon(0 0, 68% 0, 100% 30%, 100% 100%, 0 100%);
    opacity: 0.55;
}

/* ------------------------------------------------------------- listings -- */

/*
 * A folder listing has three kinds in it, and they are three different verbs:
 * a folder you go into, a note you read, an attachment you open elsewhere.
 *
 * The distinction is typographic rather than iconographic. A note row is set
 * in the reading serif — the face it will actually render in — so the row is a
 * preview of its own destination. Folders stay in the interface sans and carry
 * a chevron, because they continue the journey rather than ending it.
 *
 * No icons: a folder glyph is what every file browser reaches for, and it
 * would say nothing the type is not already saying.
 */

.listing {
    padding: 0;
    list-style: none;
}

.listing__item {
    border-bottom: 1px solid var(--color-border-subtle);
}

.listing__link {
    display: flex;
    align-items: baseline;
    gap: var(--space-md);
    /* 44px minimum touch target. */
    min-height: 2.75rem;
    padding: var(--space-sm) var(--space-xs);
    color: var(--color-text);
    text-decoration: none;
    transition: color var(--transition-fast);
}

.listing__link:hover {
    color: var(--color-primary);
}

.listing__name {
    flex: 1;
    min-width: 0;
    overflow-wrap: anywhere;
}

/* --- folder: sans, medium, chevron ---------------------------------------- */

.listing__item--folder .listing__name {
    font-family: var(--font-ui);
    font-weight: 500;
}

/*
 * Drawn rather than an icon font or SVG, so it inherits colour and needs no
 * asset. Points the way in.
 */
.listing__item--folder .listing__link::after {
    content: "";
    flex: none;
    align-self: center;
    width: 0.4rem;
    height: 0.4rem;
    border-top: 1.5px solid currentcolor;
    border-right: 1.5px solid currentcolor;
    transform: rotate(45deg);
    opacity: 0.35;
    transition: opacity var(--transition-fast), transform var(--transition-fast);
}

.listing__link:hover::after {
    opacity: 1;
    transform: rotate(45deg) translate(1px, -1px);
}

/* --- note: the reading serif, and nothing else ---------------------------- */

.listing__item--note .listing__name {
    font-family: var(--font-reading);
    font-size: 1.0625rem;
    line-height: 1.4;
}

/* --- attachment: what it is and how big ----------------------------------- */

.listing__item--asset .listing__name {
    font-family: var(--font-ui);
    color: var(--color-text-secondary);
}

.listing__meta {
    flex: none;
    display: flex;
    align-items: baseline;
    gap: var(--space-sm);
    font-family: var(--font-mono);
    font-size: 0.6875rem;
    letter-spacing: 0.02em;
    color: var(--color-text-muted);
}

.listing__ext {
    padding: 0.1em 0.4em;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
}

.listing__size {
    /* Fixed width so sizes align down the column and can be compared. */
    min-width: 4.5ch;
    text-align: right;
}

@media (max-width: 480px) {
    .listing__size {
        display: none;
    }
}

/* ---------------------------------------------------------------- empty -- */

.empty {
    padding: var(--space-2xl) 0;
    font-family: var(--font-ui);
}

.empty__title {
    font-size: 1.125rem;
    font-weight: 600;
    margin-bottom: var(--space-sm);
}

.empty__body {
    color: var(--color-text-secondary);
    max-width: 46ch;
}

.empty__body a {
    white-space: nowrap;
}

/* ---------------------------------------------------------------- search -- */

.search__form {
    position: relative;
    margin-bottom: var(--space-lg);
}

/* The magnifier sits inside the field, so the box reads as a search box even
   before you type. */
.search__icon {
    position: absolute;
    left: var(--space-md);
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    color: var(--color-text-muted);
    pointer-events: none;
}

.search__icon svg { width: 1.125rem; height: 1.125rem; }

/* Compound selector so this wins over the .form-input padding shorthand. */
.form-input.search__input {
    /* Room for the icon; a touch larger than a normal field, since it is the
       point of the page. */
    padding: var(--space-md) var(--space-md) var(--space-md) calc(var(--space-md) * 2 + 1.125rem);
}

.search__count {
    font-family: var(--font-ui);
    font-size: 0.8125rem;
    color: var(--color-text-muted);
    margin-bottom: var(--space-sm);
}

/* Search results are always notes, so they take the note treatment. */
.listing__link--stacked {
    flex-direction: column;
    align-items: stretch;
    gap: var(--space-xs);
    padding-top: var(--space-md);
    padding-bottom: var(--space-md);
}

.listing__link--stacked .listing__name {
    font-family: var(--font-reading);
    font-size: 1.0625rem;
}

.listing__excerpt {
    font-size: 0.875rem;
    color: var(--color-text-secondary);
    overflow-wrap: anywhere;
}

/* Folder heading — a folder is a listing, not prose, so it uses the UI face. */
.folder__title {
    font-family: var(--font-ui);
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: -0.011em;
    margin-bottom: var(--space-md);
}

/*
 * Folders always sort first, so this sibling selector finds the exact point
 * where navigating stops and reading begins — a real boundary in the content,
 * marked with space rather than a heading.
 */
.listing__item--folder + .listing__item:not(.listing__item--folder) {
    border-top: 1px solid var(--color-border);
    margin-top: var(--space-md);
}

/* Escape hatch on empty and error states — no page is a dead-end (FR-006, FR-008). */
.empty__action {
    margin-top: var(--space-lg);
    font-family: var(--font-ui);
    font-size: 0.9375rem;
}

/* -------------------------------------------------------------- inputs -- */

/*
 * The shared text/search field. Lives here rather than in a module sheet so
 * every page has it — the search page was falling back to the raw browser
 * control plus the global focus outline, which is the "ugly" state.
 */
.form-input {
    width: 100%;
    padding: var(--space-sm) var(--space-md);
    background-color: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    /* 16px minimum, or iOS zooms the page on focus. */
    font-size: 1rem;
    color: var(--color-text);
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.form-input::placeholder {
    color: var(--color-text-muted);
}

/* A calm indigo ring on focus — replaces the hard 2px outline the global
   :focus-visible would otherwise draw around the field. */
.form-input:focus-visible {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--color-primary) 20%, transparent);
}

/* Strip the native search chrome: the inset shadow, the magnifier, the clear
   cross that Safari and Chrome add to type="search". */
.form-input[type="search"] {
    -webkit-appearance: none;
    appearance: none;
}

.form-input[type="search"]::-webkit-search-decoration,
.form-input[type="search"]::-webkit-search-cancel-button,
.form-input[type="search"]::-webkit-search-results-button {
    -webkit-appearance: none;
    appearance: none;
}
