/*
 * modules/notes/assets/notes.css — the Notes module's own classes.
 *
 * Only `note-*` names, so nothing here can redefine a shared structural class
 * (panel, card, table, btn, pill, field, flash) that another module or theme
 * depends on.
 *
 * Rendered note bodies and colour swatches deliberately live here rather than
 * in Tailwind utilities: they have to look right without depending on
 * somebody having rebuilt assets/css/app.css. Everything is expressed through
 * the design tokens in assets/css/tokens.css, so a re-skin carries.
 *
 * Light only — no prefers-color-scheme block. See AGENTS.md rule 5.
 */

/* ── Colour accents ──────────────────────────────────────────────────────── */

.note-colour-default { --note-accent: hsl(var(--border)); }
.note-colour-yellow  { --note-accent: #e0b23c; }
.note-colour-blue    { --note-accent: #4a7fd4; }
.note-colour-green   { --note-accent: #3f9c6a; }
.note-colour-pink    { --note-accent: #d1618f; }
.note-colour-purple  { --note-accent: #8464c4; }

.note-card {
    border-left: 4px solid var(--note-accent, hsl(var(--border)));
}

.note-head {
    border-left: 4px solid var(--note-accent, hsl(var(--border)));
    padding-left: 1rem;
}

/* A row in the block on the paper search page. */
.note-hit {
    border-left: 3px solid var(--note-accent, transparent);
}

.note-colour-default.note-hit {
    border-left-color: transparent;
}

/* Colourless notes should not read as a heavy rule down the page. */
.note-colour-default.note-head {
    border-left-color: hsl(var(--border));
}

/* ── Tags ────────────────────────────────────────────────────────────────── */

.note-tag {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.125rem 0.5rem;
    border: 1px solid hsl(var(--border));
    border-radius: 9999px;
    font-size: 0.75rem;
    line-height: 1.25rem;
    color: hsl(var(--muted-foreground));
    text-decoration: none;
    transition: background-color 0.15s, color 0.15s;
}

.note-tag:hover {
    background: hsl(var(--accent));
    color: hsl(var(--accent-foreground));
}

.note-tag.is-active {
    background: hsl(var(--primary));
    border-color: hsl(var(--primary));
    color: hsl(var(--primary-foreground));
}

.note-tag.is-active span {
    color: inherit;
    opacity: 0.8;
}

/* ── Tabs ────────────────────────────────────────────────────────────────── */

.note-tab {
    color: hsl(var(--muted-foreground));
    text-decoration: none;
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    transition: color 0.15s, border-color 0.15s;
}

.note-tab:hover {
    color: hsl(var(--foreground));
}

.note-tab.is-current {
    color: hsl(var(--foreground));
    border-bottom-color: hsl(var(--primary));
}

.note-tab-count {
    display: inline-block;
    min-width: 1.25rem;
    padding: 0 0.375rem;
    border-radius: 9999px;
    background: hsl(var(--muted));
    color: hsl(var(--muted-foreground));
    font-size: 0.6875rem;
    line-height: 1.25rem;
    text-align: center;
}

.note-tab.is-current .note-tab-count {
    background: hsl(var(--primary));
    color: hsl(var(--primary-foreground));
}

/* ── Pin ─────────────────────────────────────────────────────────────────── */

.note-pin.is-pinned {
    color: hsl(var(--primary));
}

/* ── Colour swatches, in the composer ────────────────────────────────────── */

.note-swatch {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.375rem 0.75rem;
    border: 1px solid hsl(var(--border));
    border-radius: var(--radius);
    cursor: pointer;
    transition: border-color 0.15s, background-color 0.15s;
}

.note-swatch:hover {
    background: hsl(var(--accent));
}

/* :has() so the checked state needs no JavaScript to show. */
.note-swatch:has(input:checked) {
    border-color: var(--note-accent, hsl(var(--primary)));
    box-shadow: inset 0 0 0 1px var(--note-accent, hsl(var(--primary)));
}

.note-swatch:has(input:focus-visible) {
    outline: 2px solid hsl(var(--ring));
    outline-offset: 2px;
}

.note-swatch-dot {
    width: 0.875rem;
    height: 0.875rem;
    border-radius: 9999px;
    background: var(--note-accent, hsl(var(--border)));
    border: 1px solid rgba(0, 0, 0, 0.12);
}

/* ── Write / Preview toggle ──────────────────────────────────────────────── */

.note-modetab {
    padding: 0.25rem 0.625rem;
    border-radius: calc(var(--radius) - 4px);
    font-size: 0.75rem;
    font-weight: 500;
    color: hsl(var(--muted-foreground));
    background: transparent;
    border: 1px solid transparent;
    cursor: pointer;
}

.note-modetab:hover {
    color: hsl(var(--foreground));
}

.note-modetab.is-current {
    background: hsl(var(--muted));
    border-color: hsl(var(--border));
    color: hsl(var(--foreground));
}

/* ── Selects ─────────────────────────────────────────────────────────────── */

/*
 * A dropdown that always looks like one.
 *
 * The utility strings these controls inherited start with `flex`, and
 * `display: flex` on a <select> makes the browser stop drawing its own
 * chevron — leaving a control that looks like a text box and gives the reader
 * no clue it opens. `display: block` restores normal behaviour, and the
 * background chevron below makes the affordance explicit on every platform
 * rather than trusting each one's default.
 */
.note-select {
    display: block;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    padding-right: 2.25rem;
    background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%235b6472' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.625rem center;
    background-size: 1rem 1rem;
}

/* Chrome and Firefox both need this or the arrow doubles up on Windows. */
.note-select::-ms-expand {
    display: none;
}

/* ── Formatting toolbar ──────────────────────────────────────────────────── */

.note-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.125rem;
    padding: 0.25rem;
    border: 1px solid hsl(var(--border));
    border-radius: var(--radius);
    background: hsl(var(--muted));
}

.note-tool {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2rem;
    height: 2rem;
    border: 1px solid transparent;
    border-radius: calc(var(--radius) - 4px);
    background: transparent;
    color: hsl(var(--muted-foreground));
    cursor: pointer;
    transition: background-color 0.15s, color 0.15s;
}

.note-tool svg {
    width: 1rem;
    height: 1rem;
}

.note-tool:hover {
    background: hsl(var(--background));
    color: hsl(var(--foreground));
}

.note-tool:focus-visible {
    outline: 2px solid hsl(var(--ring));
    outline-offset: 1px;
}

.note-tool.is-current {
    background: hsl(var(--background));
    border-color: hsl(var(--border));
    color: hsl(var(--foreground));
}

.note-tool-sep {
    width: 1px;
    height: 1.25rem;
    margin: 0 0.25rem;
    background: hsl(var(--border));
}

.note-upload-status {
    min-height: 1.25rem;
    font-size: 0.75rem;
    color: hsl(var(--muted-foreground));
}

.note-upload-status.is-error {
    color: hsl(var(--destructive));
}

/* Drop target feedback while an image is dragged over the textarea. */
textarea.is-dropping {
    border-color: hsl(var(--primary));
    box-shadow: inset 0 0 0 1px hsl(var(--primary));
}

/* ── The drawing pad ─────────────────────────────────────────────────────── */

.note-draw {
    width: min(60rem, 94vw);
    max-width: 94vw;
    padding: 0;
    border: 1px solid hsl(var(--border));
    border-radius: var(--radius);
    background: hsl(var(--card));
    color: hsl(var(--card-foreground));
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.18);
}

.note-draw::backdrop {
    background: rgba(0, 0, 0, 0.5);
}

.note-draw-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid hsl(var(--border));
}

.note-draw-close {
    display: inline-flex;
    padding: 0.25rem;
    border: 0;
    border-radius: calc(var(--radius) - 4px);
    background: transparent;
    color: hsl(var(--muted-foreground));
    cursor: pointer;
}

.note-draw-close:hover {
    background: hsl(var(--accent));
    color: hsl(var(--accent-foreground));
}

.note-draw-tools {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.75rem;
    padding: 0.625rem 1.25rem;
    border-bottom: 1px solid hsl(var(--border));
    background: hsl(var(--muted));
}

.note-draw-group {
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.note-draw-group-end {
    margin-left: auto;
}

.note-ink {
    width: 1.5rem;
    height: 1.5rem;
    padding: 0;
    border: 2px solid hsl(var(--border));
    border-radius: 9999px;
    background: var(--note-ink, #000);
    cursor: pointer;
    transition: transform 0.1s, border-color 0.15s;
}

.note-ink:hover {
    transform: scale(1.1);
}

.note-ink.is-current {
    border-color: hsl(var(--foreground));
    box-shadow: 0 0 0 2px hsl(var(--background)), 0 0 0 4px var(--note-ink, #000);
}

.note-ink:focus-visible {
    outline: 2px solid hsl(var(--ring));
    outline-offset: 2px;
}

.note-draw-surface {
    height: min(60vh, 32rem);
    padding: 0.75rem 1.25rem;
    background: hsl(var(--card));
}

.note-draw-surface canvas {
    display: block;
    width: 100%;
    height: 100%;
    border: 1px solid hsl(var(--border));
    border-radius: calc(var(--radius) - 4px);
    background: #fff;
    /* Stops the browser treating a drag on the canvas as a scroll gesture,
       which on a touch screen makes drawing impossible. */
    touch-action: none;
    cursor: crosshair;
}

.note-draw-foot {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.875rem 1.25rem;
    border-top: 1px solid hsl(var(--border));
}

.note-draw-actions {
    display: flex;
    gap: 0.5rem;
    margin-left: auto;
}

/* ── The paper combobox ──────────────────────────────────────────────────── */

.note-combo {
    position: relative;
}

.note-combo-input {
    padding-right: 2.25rem;
}

.note-combo-clear {
    position: absolute;
    top: 50%;
    right: 0.5rem;
    display: inline-flex;
    padding: 0.25rem;
    transform: translateY(-50%);
    border: 0;
    border-radius: 9999px;
    background: transparent;
    color: hsl(var(--muted-foreground));
    cursor: pointer;
}

.note-combo-clear:hover {
    background: hsl(var(--accent));
    color: hsl(var(--accent-foreground));
}

.note-combo-list {
    position: absolute;
    z-index: 30;
    top: calc(100% + 0.25rem);
    right: 0;
    left: 0;
    max-height: 17rem;
    margin: 0;
    padding: 0.25rem;
    overflow-y: auto;
    list-style: none;
    border: 1px solid hsl(var(--border));
    border-radius: var(--radius);
    background: hsl(var(--popover));
    color: hsl(var(--popover-foreground));
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
}

.note-combo-option {
    display: flex;
    flex-direction: column;
    gap: 0.125rem;
    padding: 0.5rem 0.625rem;
    border-radius: calc(var(--radius) - 4px);
    cursor: pointer;
}

.note-combo-option:hover,
.note-combo-option.is-active {
    background: hsl(var(--accent));
    color: hsl(var(--accent-foreground));
}

.note-combo-title {
    font-size: 0.875rem;
    line-height: 1.35;
}

.note-combo-meta {
    font-size: 0.75rem;
    color: hsl(var(--muted-foreground));
}

.note-combo-option.is-active .note-combo-meta {
    color: inherit;
    opacity: 0.75;
}

.note-combo-empty {
    padding: 0.75rem 0.625rem;
    font-size: 0.875rem;
    color: hsl(var(--muted-foreground));
}

/* ── Rendered note bodies ────────────────────────────────────────────────── */

.note-prose {
    /* A measure, so a full-width viewport does not produce 200-character
       lines of somebody's prose. */
    max-width: 72ch;
    color: hsl(var(--foreground));
    overflow-wrap: break-word;
}

.note-prose > *:first-child { margin-top: 0; }
.note-prose > *:last-child  { margin-bottom: 0; }

.note-p {
    margin: 0 0 0.875rem;
    line-height: 1.65;
}

.note-h2,
.note-h3,
.note-h4 {
    margin: 1.5rem 0 0.5rem;
    font-weight: 600;
    line-height: 1.3;
    letter-spacing: -0.01em;
}

.note-h2 { font-size: 1.375rem; }
.note-h3 { font-size: 1.125rem; }
.note-h4 { font-size: 1rem; }

.note-ul,
.note-ol {
    margin: 0 0 0.875rem;
    padding-left: 1.5rem;
}

.note-ul { list-style: disc; }
.note-ol { list-style: decimal; }

.note-ul li,
.note-ol li {
    margin-bottom: 0.25rem;
    line-height: 1.6;
}

.note-quote {
    margin: 0 0 0.875rem;
    padding: 0.25rem 0 0.25rem 1rem;
    border-left: 3px solid hsl(var(--border));
    color: hsl(var(--muted-foreground));
    font-style: italic;
}

.note-pre {
    margin: 0 0 0.875rem;
    padding: 0.875rem 1rem;
    background: hsl(var(--muted));
    border: 1px solid hsl(var(--border));
    border-radius: var(--radius);
    overflow-x: auto;
}

.note-pre code {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.8125rem;
    line-height: 1.55;
    background: none;
    padding: 0;
}

.note-code {
    padding: 0.1rem 0.3rem;
    background: hsl(var(--muted));
    border-radius: calc(var(--radius) - 6px);
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.85em;
}

.note-link {
    color: hsl(var(--primary));
    text-decoration: underline;
    text-underline-offset: 2px;
}

.note-link:hover {
    text-decoration-thickness: 2px;
}

.note-hr {
    margin: 1.5rem 0;
    border: 0;
    border-top: 1px solid hsl(var(--border));
}

/* Checklists. */

.note-tasklist {
    margin: 0 0 0.875rem;
    padding-left: 0;
    list-style: none;
}

.note-task {
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
    margin-bottom: 0.25rem;
    line-height: 1.6;
}

/* Inside a mixed list the item keeps its bullet, so pull the box in. */
.note-ul .note-task {
    margin-left: -0.25rem;
}

.note-task-box {
    flex: 0 0 auto;
    width: 1rem;
    height: 1rem;
    margin-top: 0.28rem;
    accent-color: hsl(var(--primary));
}

.note-task-box:not(:disabled) {
    cursor: pointer;
}

.note-task-box:disabled {
    /* Read-only, not broken: still legible, plainly not clickable. */
    opacity: 0.65;
}

.note-task-label.is-done {
    color: hsl(var(--muted-foreground));
    text-decoration: line-through;
    text-decoration-thickness: 1px;
}

/* Draft recovery bar. */

.note-draft {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    border: 1px solid hsl(var(--border));
    border-left: 3px solid hsl(var(--primary));
    border-radius: var(--radius);
    background: hsl(var(--muted));
    font-size: 0.875rem;
}

.note-draft-action {
    padding: 0.25rem 0.625rem;
    border: 1px solid hsl(var(--border));
    border-radius: calc(var(--radius) - 4px);
    background: hsl(var(--background));
    font-size: 0.8125rem;
    font-weight: 500;
    cursor: pointer;
}

.note-draft-action:hover {
    background: hsl(var(--accent));
    color: hsl(var(--accent-foreground));
}

/* The composer's image library. */

.note-imagelist {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin: 0;
    padding: 0;
    list-style: none;
    max-height: 20rem;
    overflow-y: auto;
}

.note-imageitem {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.375rem;
    border: 1px solid hsl(var(--border));
    border-radius: calc(var(--radius) - 4px);
}

.note-imagethumb {
    flex: 0 0 auto;
    width: 2.5rem;
    height: 2.5rem;
    object-fit: cover;
    border-radius: calc(var(--radius) - 6px);
    background: #fff;
    border: 1px solid hsl(var(--border));
}

.note-imagemeta {
    display: flex;
    flex-direction: column;
    min-width: 0;
    flex: 1 1 auto;
}

.note-imagename {
    font-size: 0.75rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.note-imageuses {
    font-size: 0.6875rem;
    color: hsl(var(--muted-foreground));
}

.note-imageactions {
    display: flex;
    flex: 0 0 auto;
    gap: 0.25rem;
}

.note-imagedelete {
    color: hsl(var(--destructive));
}

/* Images inside a rendered note. */

.note-figure {
    margin: 1.25rem 0;
}

.note-figure-img,
.note-img {
    max-width: 100%;
    height: auto;
    border-radius: calc(var(--radius) - 4px);
}

.note-figure-img {
    display: block;
    border: 1px solid hsl(var(--border));
    /* A drawing is exported on a white ground; keeping that ground here means
       a picture never sits on a surface that fights it. */
    background: #fff;
}

.note-img {
    /* Inline, in a line of text: cap the height so a screenshot dropped into
       a sentence does not set that line 400px tall. */
    max-height: 1.6em;
    vertical-align: text-bottom;
}

.note-figcaption {
    margin-top: 0.5rem;
    font-size: 0.8125rem;
    line-height: 1.5;
    color: hsl(var(--muted-foreground));
}

/* ── Print ───────────────────────────────────────────────────────────────── */

/*
 * A note on paper is the title, the body and who wrote it. Everything else on
 * the page is navigation to somewhere you cannot go from a sheet of paper.
 *
 * Scoped to elements this module owns plus the theme's chrome landmarks, so
 * printing any other page is unaffected.
 */
@media print {
    .note-noprint,
    .note-toolbar,
    .note-tab,
    .note-tabs,
    .note-draft,
    .note-images,
    .note-draw,
    .note-pin,
    .topic-save {
        display: none !important;
    }

    /* The sharing panel is a control surface, not content. */
    details.rounded-xl {
        display: none !important;
    }

    .note-prose {
        max-width: none;
    }

    .note-head {
        border-left: 0;
        padding-left: 0;
    }

    /* Let a long note break across pages, but never mid-picture or
       mid-heading with the text orphaned on the next sheet. */
    .note-figure,
    .note-pre,
    .note-quote {
        break-inside: avoid;
    }

    .note-h2,
    .note-h3,
    .note-h4 {
        break-after: avoid;
    }

    /* Links are useless as underlined blue text on paper; show where they go. */
    .note-link::after {
        content: " (" attr(href) ")";
        font-size: 0.75em;
        word-break: break-all;
    }

    /* Except our own image routes, which are not readable addresses. */
    .note-figure-img,
    .note-img {
        max-width: 100%;
    }
}
