/* HighlightTools — text annotations, Ask AI, Anki suggestions */

/* Toggle button (sits below the audio-highlights toggle) */
.highlight-tools-toggle {
    position: fixed;
    /* Stack below the Audio (50%) and Sensemaker (65%) toggles, same cadence. */
    top: 80%;
    right: 0;
    transform: translateY(-50%);
    background: #6a1b9a;
    color: white;
    border: none;
    border-radius: 8px 0 0 8px;
    padding: 12px 8px;
    font-size: 14px;
    cursor: pointer;
    z-index: 999;
    transition: all 0.3s ease;
    box-shadow: -2px 0 8px rgba(0, 0, 0, 0.2);
    writing-mode: vertical-rl;
    text-orientation: mixed;
}

.highlight-tools-toggle:hover {
    background: #4a148c;
    transform: translateY(-50%) translateX(-5px);
}

.highlight-tools-toggle.sidebar-open {
    right: 340px;
    background: #d32f2f;
}

/* Sidebar */
.highlight-tools-sidebar {
    position: fixed;
    top: 0;
    right: -420px;
    width: 420px;
    height: 100vh;
    background: white;
    border-left: 2px solid #dee2e6;
    box-shadow: -2px 0 5px rgba(0, 0, 0, 0.1);
    z-index: 1051;
    transition: right 0.3s ease;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

.highlight-tools-sidebar.open {
    right: 0;
}

.ht-sidebar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 18px;
    border-bottom: 1px solid #e9ecef;
    background: #f8f5fb;
}

.ht-sidebar-header h5 {
    margin: 0;
    color: #4a148c;
}

.ht-tabs {
    display: flex;
    border-bottom: 1px solid #e9ecef;
    /* Eight tools no longer fit at a readable size; let the strip scroll rather
       than squeezing every label down to an ellipsis. */
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.ht-tabs::-webkit-scrollbar {
    height: 3px;
}

.ht-tabs::-webkit-scrollbar-thumb {
    background: #d5d5d5;
}

.ht-tab {
    flex: 1 0 auto;
    padding: 10px 8px;
    background: #f8f9fa;
    border: none;
    border-bottom: 3px solid transparent;
    cursor: pointer;
    font-size: 12px;
    white-space: nowrap;
}

.ht-tab.active {
    background: white;
    border-bottom-color: #6a1b9a;
    font-weight: 600;
}

.ht-tab-content {
    padding: 14px 16px;
    overflow-y: auto;
}

.ht-anki-toolbar {
    margin-bottom: 12px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.ht-selall {
    margin: 0;
    font-size: 13px;
    color: #4a148c;
    cursor: pointer;
}

.ht-selall input {
    margin-right: 4px;
}

.ht-card-select {
    margin: 0;
    cursor: pointer;
    display: flex;
    align-items: center;
}

.ht-card-select input {
    margin-right: 6px;
}

/* Flash when a note is opened by clicking its highlight */
.ht-item.ht-flash {
    animation: ht-flash-anim 1.6s ease;
}

@keyframes ht-flash-anim {
    0% { background: #ede7f6; box-shadow: 0 0 0 2px #8e24aa; }
    100% { background: #fff; box-shadow: none; }
}

/* List items */
.ht-item {
    border: 1px solid #e9ecef;
    border-radius: 6px;
    padding: 10px 12px;
    margin-bottom: 12px;
    background: #fff;
}

.ht-item-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 6px;
}

.ht-item-actions {
    display: flex;
    gap: 6px;
}

.ht-quote {
    font-style: italic;
    color: #6c757d;
    font-size: 12px;
    border-left: 3px solid #ce93d8;
    padding-left: 8px;
    margin-bottom: 6px;
}

.ht-body,
.ht-answer {
    font-size: 14px;
    white-space: normal;
}

.ht-question {
    font-size: 14px;
    margin-bottom: 4px;
}

.ht-answer {
    background: #f3e5f5;
    border-radius: 6px;
    padding: 8px 10px;
    margin-top: 6px;
}

/* Rendered markdown */
.ht-body > :first-child,
.ht-answer > :first-child { margin-top: 0; }

.ht-body > :last-child,
.ht-answer > :last-child { margin-bottom: 0; }

.ht-body p,
.ht-answer p { margin: 0 0 8px; }

.ht-md-h {
    font-weight: 700;
    line-height: 1.25;
    margin: 12px 0 6px;
}

h1.ht-md-h { font-size: 17px; }
h2.ht-md-h { font-size: 15px; }
h3.ht-md-h { font-size: 14px; }
h4.ht-md-h,
h5.ht-md-h,
h6.ht-md-h { font-size: 13px; }

.ht-body ul,
.ht-body ol,
.ht-answer ul,
.ht-answer ol {
    margin: 0 0 8px;
    padding-left: 20px;
}

.ht-body code,
.ht-answer code {
    background: rgba(74, 20, 140, 0.1);
    border-radius: 3px;
    padding: 1px 4px;
    font-size: 12px;
}

.ht-code {
    background: #2d2d2d;
    color: #f8f8f2;
    border-radius: 6px;
    padding: 10px;
    overflow-x: auto;
    font-size: 12px;
    margin: 0 0 8px;
}

.ht-code code {
    background: none;
    color: inherit;
    padding: 0;
}

/* An example's body is a trace, a table or a diagram — the alignment IS the content,
   so its blocks scroll sideways rather than wrapping and shearing the columns. */
.ht-example-body .ht-code {
    white-space: pre;
}

.ht-quote-md {
    border-left: 3px solid #ce93d8;
    margin: 0 0 8px;
    padding: 2px 10px;
    color: #555;
}

.ht-body hr,
.ht-answer hr {
    border: 0;
    border-top: 1px solid #e0d4ec;
    margin: 10px 0;
}

.ht-card-front,
.ht-card-back {
    font-size: 14px;
    margin-bottom: 4px;
}

.ht-card-notes {
    font-size: 13px;
    color: #444;
    background: #fffbea;
    border-left: 3px solid #ffd54f;
    border-radius: 4px;
    padding: 6px 10px;
    margin: 4px 0 6px;
}

.ht-card-notes.ht-muted {
    background: transparent;
    border-left-color: #e0e0e0;
    color: #aaa;
    font-style: italic;
}

.ht-quiz-stats {
    font-size: 11px;
    color: #777;
    margin-right: 6px;
    align-self: center;
}

.ht-tag {
    display: inline-block;
    background: #ede7f6;
    color: #4a148c;
    border-radius: 10px;
    padding: 1px 8px;
    font-size: 11px;
    margin-right: 4px;
}

/* Badges */
.ht-badge {
    font-size: 11px;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 10px;
    color: #fff;
}

.ht-badge-comment { background: #1976d2; }
.ht-badge-example { background: #283593; }
.ht-badge-idea { background: #2e7d32; }
.ht-badge-rebuttal { background: #c62828; }
.ht-badge-next_step { background: #ef6c00; }

/* Action toolbar on selection. The everyday four sit on the row; the rest live in a
   panel below it, so the bar stays one short line until you ask for more. */
.ht-action-toolbar {
    position: absolute;
    display: flex;
    flex-direction: column;
    gap: 4px;
    background: #fff;
    border: 1px solid #ce93d8;
    border-radius: 6px;
    padding: 4px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
    z-index: 1000;
}

.ht-action-row {
    display: flex;
    gap: 4px;
}

.ht-action-more-panel {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 4px;
    max-width: 340px;
    padding-top: 5px;
    border-top: 1px solid #e9ddf0;
}

.ht-action {
    background: #6a1b9a;
    color: #fff;
    border: none;
    border-radius: 4px;
    padding: 4px 8px;
    font-size: 12px;
    cursor: pointer;
    white-space: nowrap;
}

.ht-action:hover {
    background: #4a148c;
}

/* The panel's buttons share a grid track, so they line up rather than hug their text. */
.ht-action-more-panel .ht-action {
    text-align: left;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Amber, matching the in-document bookmark colour, when the button will clear one. */
.ht-action.ht-action-on {
    background: #e65100;
}

.ht-action.ht-action-on:hover {
    background: #bf360c;
}

.ht-action-toggle {
    background: #ede7f6;
    color: #4a148c;
    border: none;
    border-radius: 4px;
    padding: 4px 10px;
    font-size: 13px;
    line-height: 1;
    cursor: pointer;
}

.ht-action-toggle:hover,
.ht-action-toggle.open {
    background: #d1c4e9;
}

/* Resume pill — bottom left, because the right rail already carries three toggles. */
.ht-resume-pill {
    position: fixed;
    left: 16px;
    bottom: 16px;
    z-index: 1000;
    background: #e65100;
    color: #fff;
    border: none;
    border-radius: 20px;
    padding: 9px 16px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 3px 12px rgba(0, 0, 0, 0.25);
}

.ht-resume-pill:hover {
    background: #bf360c;
}

/* Bookmark sidebar rows */
.ht-badge-bookmark { background: #e65100; }

.ht-bookmark-label {
    margin-top: 6px;
    font-size: 12px;
}

.ht-bookmark-missing {
    margin-top: 6px;
    font-size: 12px;
    color: #c62828;
}

/* Modal */
.ht-modal {
    position: fixed;
    inset: 0;
    z-index: 1100;
}

.ht-modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
}

.ht-modal-dialog {
    position: relative;
    max-width: 560px;
    margin: 6vh auto;
}

.ht-modal-content {
    background: #fff;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 6px 30px rgba(0, 0, 0, 0.3);
}

.ht-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 18px;
    border-bottom: 1px solid #e9ecef;
    background: #f8f5fb;
}

.ht-modal-header h5 {
    margin: 0;
    color: #4a148c;
}

.ht-modal-body {
    padding: 18px;
    max-height: 70vh;
    overflow-y: auto;
}

.ht-selected-text {
    margin-bottom: 14px;
}

.ht-preview {
    background: #f8f9fa;
    border: 1px solid #e9ecef;
    border-radius: 6px;
    padding: 8px 10px;
    margin-top: 4px;
    font-style: italic;
    max-height: 120px;
    overflow-y: auto;
}

.ht-status {
    margin-top: 10px;
    color: #6c757d;
    font-size: 13px;
}

.ht-insert-row {
    margin-top: 8px;
}

/* Influence: advanced frame/device selectors */
.ht-advanced {
    margin-top: 10px;
}

.ht-advanced summary {
    cursor: pointer;
    color: #6a1b9a;
    font-size: 13px;
}

.ht-advanced-body {
    margin-top: 8px;
}

.ht-advanced-body select {
    margin-bottom: 8px;
}

/* Influence: generated phrasing cards inside the modal */
.ht-phrasing-card {
    border: 1px solid #e9ecef;
    border-radius: 6px;
    padding: 10px 12px;
    margin-top: 10px;
}

.ht-phrasing-badges {
    display: flex;
    gap: 6px;
    margin-bottom: 6px;
}

.ht-phrasing-text {
    font-size: 14px;
}

.ht-phrasing-rationale {
    font-size: 12px;
    margin-top: 4px;
}

/* Make: the five-rung ladder. The left border darkens as you climb, so the
   escalation is visible before you read a word of it. */
.ht-make-idea {
    font-size: 14px;
    background: #f6f2fb;
    border-left: 3px solid #7e57c2;
    padding: 8px 10px;
    border-radius: 4px;
    margin-bottom: 6px;
}

.ht-make-hint {
    font-size: 12px;
    margin-bottom: 10px;
}

.ht-make-rung {
    border: 1px solid #e9ecef;
    border-left-width: 4px;
    border-radius: 6px;
    padding: 10px 12px;
    margin-bottom: 10px;
}

.ht-make-level-1 { border-left-color: #b39ddb; }
.ht-make-level-2 { border-left-color: #9575cd; }
.ht-make-level-3 { border-left-color: #7e57c2; }
.ht-make-level-4 { border-left-color: #5e35b1; }
.ht-make-level-5 { border-left-color: #4527a0; }

.ht-make-rung-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 6px;
}

.ht-make-level-badge {
    display: inline-block;
    color: #fff;
    border-radius: 10px;
    padding: 2px 9px;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.02em;
}

.ht-make-level-badge-1 { background: #b39ddb; }
.ht-make-level-badge-2 { background: #9575cd; }
.ht-make-level-badge-3 { background: #7e57c2; }
.ht-make-level-badge-4 { background: #5e35b1; }
.ht-make-level-badge-5 { background: #4527a0; }

.ht-make-time {
    font-size: 12px;
    color: #6c757d;
}

.ht-make-artifact {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 4px;
}

.ht-make-brief {
    font-size: 13px;
    margin-bottom: 6px;
}

.ht-make-meta {
    font-size: 12px;
    color: #555;
    margin-top: 3px;
}

.ht-make-actions {
    margin-top: 8px;
}

.ht-make-footer {
    margin-top: 4px;
}

/* Make: the sidebar list — one card per ladder, five compact rungs inside. */
.ht-make-list-rungs {
    margin-top: 6px;
}

.ht-make-list-rung {
    display: flex;
    align-items: baseline;
    gap: 6px;
    font-size: 12px;
    padding: 2px 0;
}

.ht-make-list-artifact {
    flex: 1;
    color: #333;
}

/* Toast confirmation */
.ht-toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: #2e7d32;
    color: #fff;
    padding: 10px 18px;
    border-radius: 6px;
    font-size: 14px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease, transform 0.25s ease;
    z-index: 1200;
}

.ht-toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

.ht-spinner {
    color: #6a1b9a;
}

/* Anki modal: choose which end of the card you are writing.
   Same visual language as .ht-tab, scoped to the modal. */
.ht-anki-modes {
    display: flex;
    gap: 4px;
    margin-bottom: 16px;
    border-bottom: 1px solid #e0e0e0;
}

.ht-anki-mode {
    padding: 8px 14px;
    background: none;
    border: none;
    border-bottom: 3px solid transparent;
    cursor: pointer;
    font-size: 13px;
    color: #666;
}

.ht-anki-mode.active {
    border-bottom-color: #6a1b9a;
    font-weight: 600;
    color: #212529;
}

/* Anki modal: the cards this highlight has already produced. The two half-written
   directions autosave, so this list is a record of what is on disk, not a staging
   area — hence the sidebar's own .ht-item styling, reused wholesale. */
.ht-anki-mini-list {
    margin-top: 20px;
    border-top: 1px solid #e0e0e0;
    padding-top: 12px;
    /* No max-height: .ht-modal-body already scrolls, and the list sits below the form,
       so a long one can never push the form out of reach. A second nested scroller
       would only be something else to fight. */
}

.ht-mini-head {
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: #666;
    margin-bottom: 8px;
}

.ht-mini-item.ht-mini-open {
    border-color: #6a1b9a;
    background: #faf6fd;
}

.ht-mini-edit .form-group {
    margin-bottom: 8px;
}

.ht-mini-edit label {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: #777;
    margin-bottom: 2px;
}

.ht-mini-status:empty {
    display: none;
}

/* The save failed but the model was already paid for. Loud enough to be acted on. */
.ht-anki-recover {
    margin-top: 12px;
    padding: 12px;
    border: 1px solid #e57373;
    border-radius: 4px;
    background: #fff5f5;
}

.ht-anki-recover-msg {
    font-size: 13px;
    color: #c62828;
    margin-bottom: 10px;
}

.ht-modal-body .btn {
    margin-right: 8px;
}

/* Annotation images */
.ht-img-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.ht-img-grid:not(:empty) {
    margin: 8px 0;
}

.ht-img-thumb {
    position: relative;
    width: 96px;
    height: 96px;
    border: 1px solid #e0d4ec;
    border-radius: 6px;
    overflow: hidden;
    background: #faf7fd;
}

.ht-img-grid-sm .ht-img-thumb {
    width: 72px;
    height: 72px;
    cursor: zoom-in;
}

.ht-img-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.ht-img-remove {
    position: absolute;
    top: 2px;
    right: 2px;
    width: 20px;
    height: 20px;
    line-height: 18px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.6);
    color: #fff;
    font-size: 14px;
    cursor: pointer;
}

.ht-img-remove:hover {
    background: #c62828;
}

.ht-img-drop {
    border: 2px dashed #ce93d8;
    border-radius: 6px;
    padding: 12px;
    text-align: center;
    font-size: 13px;
    color: #6c757d;
    background: #faf7fd;
}

.ht-img-drop-over {
    border-color: #6a1b9a;
    background: #f3e5f5;
}

.ht-lightbox {
    display: none;
    position: fixed;
    inset: 0;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.85);
    align-items: center;
    justify-content: center;
    z-index: 1300;
    cursor: zoom-out;
}

.ht-lightbox img {
    max-width: 92vw;
    max-height: 92vh;
    border-radius: 4px;
}

@media (max-width: 768px) {
    .highlight-tools-sidebar {
        width: 100%;
        right: -100%;
    }
    .highlight-tools-toggle.sidebar-open {
        right: 0;
    }
}

/* ---------------------------------------------------------------- explain */

.ht-explain-selection {
    background: #f7f8fa;
    border-left: 3px solid #2f6df6;
    border-radius: 4px;
    padding: 0.7rem 0.9rem;
    margin-bottom: 1rem;
    font-size: 0.9rem;
    line-height: 1.5;
    color: #5b6371;
    max-height: 9rem;
    overflow-y: auto;
}

/* Read aloud ------------------------------------------------------------------

   The cursor is an overlay inside .ql-container, never a Quill format — the document is
   editable and both surfaces save editor.getContents(), so a paint would be baked in by the
   next save. pointer-events:none keeps it out of the way of selecting the text underneath. */
.ht-tts-cursor {
    position: absolute;
    display: none;
    background: rgba(106, 27, 154, 0.22);
    border-bottom: 2px solid #6a1b9a;
    border-radius: 2px;
    pointer-events: none;
    z-index: 5;                       /* above the text, far below the toolbar's 1000 */
    transition: left 90ms linear, top 90ms linear, width 90ms linear;
}

/* Bottom centre: the resume pill owns bottom-left and the right rail carries three toggles. */
.ht-tts-player {
    position: fixed;
    left: 50%;
    bottom: 16px;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: 10px;
    max-width: calc(100vw - 32px);
    background: #fff;
    border: 1px solid #ce93d8;
    border-radius: 24px;
    padding: 6px 14px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
    z-index: 1001;
}

.ht-tts-btn {
    background: #6a1b9a;
    color: #fff;
    border: none;
    border-radius: 50%;
    width: 30px;
    height: 30px;
    font-size: 13px;
    line-height: 1;
    cursor: pointer;
    flex: 0 0 auto;
}

.ht-tts-btn:hover {
    background: #4a148c;
}

.ht-tts-rate {
    display: flex;
    align-items: center;
    gap: 6px;
    margin: 0;
    font-size: 12px;
    color: #4a148c;
}

.ht-tts-rate input[type="range"] {
    width: 84px;
}

#ht-tts-rate-label {
    min-width: 34px;                  /* hold the width so the row doesn't twitch on drag */
}

.ht-tts-voice {
    max-width: 190px;
    font-size: 12px;
    padding: 3px 6px;
    border: 1px solid #d1c4e9;
    border-radius: 4px;
    background: #fff;
    color: #4a148c;
}

.ht-tts-note {
    font-size: 11px;
    color: #7b6f86;
}

.ht-tts-note:empty {
    display: none;
}
