/* Comments in the margin ("Kommentarer"): the panel, cards, highlights and the "Kommentér"
   buttons. Built by comments.js; only existing tokens, plus the highlight tint. The script page is
   paper white in both themes (--page-bg), so the tint is the same in both. */

:root {
    --comment-mark: rgba(214, 168, 64, .28);
    --comment-mark-active: rgba(214, 168, 64, .55);
    --comments-panel-width: 320px;
}

::highlight(cw-comment) {
    background-color: var(--comment-mark);
}
::highlight(cw-comment-active) {
    background-color: var(--comment-mark-active);
    text-decoration: underline 2px;
    text-decoration-color: rgba(150, 110, 20, .9);
    text-underline-offset: 3px;
}
::highlight(cw-comment-draft) {
    background-color: var(--comment-mark-active);
}

/* Without the Highlight API: tinted boxes in a layer beside the pages that never take a click */
.comment-marks-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 0;
    height: 0;
    overflow: visible;
    pointer-events: none;
    z-index: 1;
}
.comment-mark {
    position: absolute;
    background: var(--comment-mark);
    mix-blend-mode: multiply;
    border-radius: 1px;
}
.comment-mark.is-active,
.comment-mark.is-draft {
    background: var(--comment-mark-active);
}
.comment-mark.is-active {
    box-shadow: inset 0 -2px 0 rgba(150, 110, 20, .9);
}

/* ---------- Nav button ---------- */
/* The button keeps one width whether the panel is open or not, so the nav row never re-wraps
   when it is toggled: the label reserves the room of its bold (active) form, and the count has
   a fixed width for one or two digits. */
.comments-nav-label {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
}
.comments-nav-label::after {
    content: attr(data-label);
    content: attr(data-label) / "";
    height: 0;
    overflow: hidden;
    visibility: hidden;
    font-weight: 600;
    pointer-events: none;
    user-select: none;
}
.comments-count {
    display: inline-block;
    min-width: 2ch;
    margin-left: 6px;
    font-family: var(--font-editor);
    font-variant-numeric: tabular-nums;
    text-align: left;
    color: var(--ink);
}
/* A dot on "Mere" while there are open comments, where the comments live below 1440px.
   Positioned, so it never widens the button. */
.comments-more-dot {
    display: none;
}
.comments-menu-item.hidden {
    display: none;
}

/* ---------- Panel (desktop: docked between the script and the AI panel) ---------- */
.comments-panel {
    width: var(--comments-panel-width);
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    min-height: 0;
    background: var(--surface-2);
    border-left: 1px solid var(--line);
    font-family: var(--font-ui);
    color: var(--ink);
}
.comments-panel.collapsed,
.comments-panel.is-dormant {
    display: none;
}

.comments-header {
    flex: none;
    min-height: 56px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 0 8px 0 20px;
    border-bottom: 1px solid var(--line);
}
.comments-header h4 {
    flex: 1;
    min-width: 0;
    margin: 0;
    font-family: var(--font-title);
    font-size: 24px;
    font-weight: 400;
    line-height: 1.1;
    color: var(--ink);
}

.comments-tools {
    flex: none;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 8px;
    padding: 8px 12px;
    border-bottom: 1px solid var(--line);
}
.comments-tools.hidden,
.comments-mode.hidden {
    display: none;
}
.comments-mode {
    display: inline-flex;
    border: 1px solid var(--line);
    border-radius: 4px;
    overflow: hidden;
}
.comments-mode-btn {
    min-height: 32px;
    padding: 0 10px;
    background: transparent;
    border: none;
    color: var(--muted);
    font-family: var(--font-ui);
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
}
.comments-mode-btn + .comments-mode-btn {
    border-left: 1px solid var(--line);
}
.comments-mode-btn:hover {
    background: var(--fill);
    color: var(--ink);
}
.comments-mode-btn.active {
    background: var(--surface);
    color: var(--ink);
    font-weight: 600;
}

/* Quiet text buttons: Vis løste, Redigér, Slet, Prøv igen, "2 svar" */
.comments-link-btn {
    min-height: 32px;
    padding: 0 6px;
    background: transparent;
    border: none;
    border-radius: 4px;
    color: var(--ink);
    font-family: var(--font-ui);
    font-size: 12px;
    font-weight: 500;
    text-decoration: underline;
    text-underline-offset: 0.2em;
    cursor: pointer;
}
.comments-link-btn:hover {
    text-decoration-thickness: 2px;
}
.comments-link-btn.hidden {
    display: none;
}

.comments-status {
    flex: none;
    padding: 16px 20px;
}
.comments-status.hidden {
    display: none;
}
.comments-message {
    margin: 0 0 8px;
    font-size: 14px;
    line-height: 1.45;
    color: var(--muted);
}
.comments-message:last-child {
    margin-bottom: 0;
}

.comments-detached {
    flex: none;
    max-height: 40%;
    overflow-y: auto;
    border-bottom: 1px solid var(--line);
}
.comments-detached.hidden {
    display: none;
}
.comments-detached-toggle {
    display: flex;
    align-items: center;
    gap: 6px;
    width: 100%;
    min-height: 40px;
    padding: 0 20px;
    background: transparent;
    border: none;
    color: var(--ink);
    font-family: var(--font-ui);
    font-size: 13px;
    font-weight: 600;
    text-align: left;
    cursor: pointer;
}
.comments-detached-toggle::before {
    content: '';
    width: 0;
    height: 0;
    border-left: 5px solid currentColor;
    border-top: 4px solid transparent;
    border-bottom: 4px solid transparent;
    transition: transform var(--transition-speed);
}
.comments-detached-toggle[aria-expanded="true"]::before {
    transform: rotate(90deg);
}
.comments-detached-toggle:hover {
    background: var(--fill);
}
.comments-detached-body {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 0 12px 12px;
}
.comments-detached-info {
    margin: 0;
    padding: 0 8px;
    font-size: 12px;
    line-height: 1.4;
    color: var(--muted);
}

.comments-list {
    flex: 1 1 auto;
    min-height: 0;
    position: relative;
    overflow-y: auto;
}
.comments-track {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 12px;
}
/* Aligned: the cards sit level with their text and follow the script's scrolling (comments.js) */
.comments-panel.is-aligned .comments-list {
    overflow: hidden;
}
.comments-panel.is-aligned .comments-track {
    display: block;
    position: relative;
    padding: 0;
    will-change: transform;
}
.comments-panel.is-aligned .comments-track > .comment-card {
    position: absolute;
    left: 12px;
    right: 12px;
}

.comments-footnote {
    flex: none;
    margin: 0;
    padding: 12px 20px;
    border-top: 1px solid var(--line);
    font-size: 12px;
    line-height: 1.4;
    color: var(--muted);
}
.comments-footnote.hidden {
    display: none;
}

/* ---------- Cards ---------- */
.comment-card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 4px;
    padding: 12px;
    font-size: 14px;
    line-height: 1.45;
    color: var(--ink);
    cursor: default;
    transition: border-color var(--transition-speed);
}
.comment-card:not(.is-active):hover {
    border-color: var(--line-strong);
    cursor: pointer;
}
.comment-card:focus-visible {
    outline: 2px solid var(--ink);
    outline-offset: 2px;
}
.comment-card.is-active {
    border-color: var(--ink);
}
.comment-card.is-resolved {
    color: var(--muted);
}
.comment-card.is-pending {
    opacity: .7;
}
.comment-card.is-failed {
    border-color: var(--red);
}

.comment-quote {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    margin: 0 0 8px;
    padding: 2px 0 2px 8px;
    border-left: 2px solid var(--line-strong);
    font-family: var(--font-editor);
    font-size: 12.5px;
    line-height: 1.35;
    color: var(--muted);
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}
.comment-quote-btn {
    width: 100%;
    background: transparent;
    border-top: none;
    border-right: none;
    border-bottom: none;
    border-radius: 0;
    text-align: left;
    cursor: pointer;
}
.comment-quote-btn:hover {
    color: var(--ink);
    border-left-color: var(--ink);
}
.comment-card.is-collapsed .comment-quote {
    -webkit-line-clamp: 1;
}
.comment-changed,
.comment-page {
    margin: -4px 0 8px;
    font-size: 12px;
    color: var(--muted);
}

.comment-meta {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 4px 8px;
    margin-bottom: 2px;
}
.comment-author {
    font-weight: 600;
    color: inherit;
}
.comment-time {
    font-size: 12px;
    color: var(--muted);
}
.comment-body {
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}
.comment-card.is-collapsed .comment-root .comment-body {
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.comment-replies .comment-item {
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid var(--line);
}
.comment-reply-count {
    margin-top: 4px;
    padding: 0;
    color: var(--muted);
}
.comment-item-actions {
    display: flex;
    gap: 4px;
    margin: 2px 0 0 -6px;
}
.comment-card.is-collapsed .comment-item-actions {
    display: none;
}
.comment-state {
    margin: 4px 0 0;
    font-size: 12px;
    color: var(--muted);
}
.comment-state.is-failed {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 4px;
    color: var(--red);
}
.comment-state.is-failed .comments-link-btn {
    color: var(--ink);
}
.comment-resolved-note {
    margin: 8px 0 0;
    font-size: 12px;
    color: var(--muted);
}
.comment-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    margin-top: 10px;
}
.comment-actions .btn-sm {
    min-height: 36px;
    padding: 0 12px;
}
.comment-goto {
    margin-left: auto;
}
.comment-hint {
    margin: 8px 0 0;
    font-size: 12px;
    color: var(--muted);
}
.comment-input {
    display: block;
    width: 100%;
    min-height: 64px;
    margin-top: 8px;
    padding: 8px 10px;
    resize: vertical;
    background: var(--surface);
    color: var(--ink);
    border: 1px solid var(--line);
    border-radius: 4px;
    font-family: var(--font-ui);
    font-size: 14px;
    line-height: 1.45;
}
.comment-input:focus {
    outline: none;
    border-color: var(--ink);
}
.comment-composer .comment-quote {
    -webkit-line-clamp: 3;
}

/* ---------- "Kommentér" beside a selection ---------- */
.comment-select-btn {
    position: absolute;
    z-index: 6;
    min-height: 32px;
    padding: 0 12px;
    background: var(--surface);
    color: var(--ink);
    border: 1px solid var(--ink);
    border-radius: 4px;
    box-shadow: 0 1px 2px rgba(30, 27, 22, .06);
    font-family: var(--font-ui);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
}
.comment-select-btn:hover {
    background: var(--fill);
}
.comment-select-btn.hidden,
.comment-select-btn-mobile.hidden {
    display: none;
}
.comment-select-btn-mobile {
    position: fixed;
    left: 50%;
    bottom: 96px;
    transform: translateX(-50%);
    z-index: 1300;
    min-height: 44px;
    padding: 0 18px;
    background: var(--ink);
    color: var(--on-ink);
    border: 1px solid var(--ink);
    border-radius: 4px;
    box-shadow: 0 8px 24px rgba(30, 27, 22, .14);
    font-family: var(--font-ui);
    font-size: 14px;
    font-weight: 600;
    white-space: nowrap;
    cursor: pointer;
}

.comments-backdrop {
    display: none;
}

/* ---------- Drawer (phones and touch tablets; .is-drawer is set by comments.js) ---------- */
.comments-panel.is-drawer {
    position: fixed;
    top: 0;
    right: 0;
    width: 85vw;
    max-width: 360px;
    height: 100vh;
    height: 100dvh;
    z-index: 1500;
    border-left: 1px solid var(--ink);
    transition: transform var(--transition-speed) ease, visibility var(--transition-speed);
}
/* Opening: visible at once, so focus can move into the drawer straight away; closing keeps the delayed hide */
.comments-panel.is-drawer:not(.collapsed) {
    transition: transform var(--transition-speed) ease, visibility 0s;
}
.comments-panel.is-drawer.collapsed {
    display: flex;
    transform: translateX(105%);
    visibility: hidden;
    pointer-events: none;
}
.comments-panel.is-drawer .btn,
.comments-panel.is-drawer .comments-link-btn,
.comments-panel.is-drawer .comments-detached-toggle,
.comments-panel.is-drawer .btn-close-sidebar,
.comments-panel.is-drawer .comment-quote-btn {
    min-height: 44px;
}
.comments-panel.is-drawer .comment-actions .btn-sm {
    min-height: 44px;
}
.comments-panel.is-drawer .comment-quote-btn {
    padding-top: 8px;
    padding-bottom: 8px;
}
.comments-backdrop:not(.hidden) {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 1400;
    background: var(--backdrop);
}

/* ---------- Dashboard ---------- */
.script-comment-badge {
    display: inline-flex;
    align-items: center;
    margin-left: 0.75rem;
    color: var(--ink);
    font-family: var(--font-editor);
    font-weight: 400;
    white-space: nowrap;
}
.script-comment-badge.is-new {
    font-weight: 700;
}

/* ---------- Phones ---------- */
@media screen and (max-width: 850px) {
    /* The nav row has no room left: on phones comments are under "Mere" (and the button that
       appears with a selection) */
    #btn-toggle-comments {
        display: none !important;
    }
    .script-comment-badge {
        display: inline;
        margin-left: 0;
        white-space: normal;
        overflow-wrap: anywhere;
    }
}
/* Laptop widths: the nav row is full (Del, the profile name and the title already take it), so
   the button would push "Mere" onto a second row. Comments sit in "Mere" there, as on phones,
   with the open count on "Mere" itself. */
@media screen and (min-width: 851px) and (max-width: 1439px) {
    #btn-toggle-comments {
        display: none !important;
    }
    #btn-file-ops {
        position: relative;
    }
    .comments-more-dot:not(.hidden) {
        display: block;
        position: absolute;
        top: 6px;
        right: 6px;
        width: 6px;
        height: 6px;
        border-radius: 50%;
        background: var(--ink);
        pointer-events: none;
    }
}
@media screen and (min-width: 1440px) {
    .comments-menu-item {
        display: none !important;
    }
}

@media (prefers-reduced-motion: reduce) {
    .comment-card,
    .comments-panel.is-drawer,
    .comments-detached-toggle::before {
        transition: none;
    }
}

/* ---------- Print and PDF: no comments anywhere ---------- */
@media print {
    .comments-panel,
    .comments-backdrop,
    .comment-select-btn,
    .comment-select-btn-mobile,
    .comment-marks-layer,
    .comments-more-dot,
    #btn-toggle-comments {
        display: none !important;
    }
    ::highlight(cw-comment),
    ::highlight(cw-comment-active),
    ::highlight(cw-comment-draft) {
        background-color: transparent;
        text-decoration: none;
    }
}
