/* ============================================================
 * notes.css — Chat Notepad Panel Styles
 * Self-contained: all selectors are scoped under .chat-notes-*
 * Loaded after chat.css (see AI_RULES.md CSS load order)
 *
 * Color strategy: all colors use CSS variables from variables.css
 * (--text, --text-2, --text-3, --surface, --surface-2, --surface-3,
 *  --border, --border-2, --accent-color).
 * No hardcoded rgba() — no body.light duplication needed.
 * ============================================================ */

/* ── Local semantic tokens ───────────────────────────────────────────────── */
/*
 * Map design-system tokens to local intent names.
 * Fallbacks use dark-theme values for environments without body.dark/light.
 */
:root {
    --notes-bg:           #13151a;
    --notes-bg-hover:     #1a1c23;
    --notes-border:       var(--border,    rgba(255,255,255,0.05));
    --notes-border-2:     var(--border-2,  rgba(255,255,255,0.08));
    --notes-text:         #f0f0f3;
    --notes-text-dim:     #9ca3af;
    --notes-text-faint:   #6b7280;
    --notes-accent:       var(--accent-color, #3aae7a);
}

/* Theme tokens live on body, not :root. Resolve the notepad aliases in the
 * same scope so it follows Katomu surfaces instead of freezing root fallbacks. */
body.dark,
body.light {
    --notes-bg:           var(--surface);
    --notes-bg-hover:     var(--surface-2);
    --notes-border:       var(--border);
    --notes-border-2:     var(--border-2);
    --notes-text:         var(--text);
    --notes-text-dim:     var(--text-2);
    --notes-text-faint:   var(--text-3);
    --notes-accent:       var(--accent-color);
}

/* ── Trigger button in chat header ──────────────────────────────────────── */

#chat-notes-btn {
    display: none; /* shown by ChatNotes.showButton() when isPinnedRoom */
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border: none;
    border-radius: 10px;
    background: transparent;
    color: var(--notes-text-dim);
    cursor: pointer;
    transition: background var(--duration, 0.15s), color var(--duration, 0.15s);
    flex-shrink: 0;
    position: relative; /* stacking context for notification dot */
}

#chat-notes-btn:hover {
    background: var(--notes-bg-hover);
    color: var(--notes-text);
}

#chat-notes-btn.is-active {
    background: color-mix(in srgb, var(--notes-accent) 15%, transparent);
    color: var(--notes-accent);
}

/* ── Notification dot ────────────────────────────────────────────────────── */

.chat-notes-notif-dot {
    position: absolute;
    top: 5px;
    right: 5px;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--notes-accent);
    border: 2px solid var(--notes-bg);
    opacity: 0;
    transform: scale(0.5);
    transition: opacity 0.2s, transform 0.2s;
    pointer-events: none;
}

.chat-notes-notif-dot.is-visible {
    opacity: 1;
    transform: scale(1);
}

/* ── Panel ───────────────────────────────────────────────────────────────── */

.chat-notes-panel {
    /* Desktop: fixed in the empty space to the RIGHT of the chat column */
    position: fixed;
    top: 0;
    left: calc(50% + 300px); /* 300px = half of --max-w (600px) */
    width: min(340px, calc(50vw - 300px));  /* don't overflow viewport */
    height: 100dvh;
    z-index: 25;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--notes-bg);
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
    border-left: 1px solid var(--notes-border-2);
    box-shadow: var(--shadow-lg, -6px 0 28px rgba(0,0,0,0.45));
    /* Slide in from the right */
    transform: translateX(calc(100% + 20px));
    opacity: 0;
    transition: transform 0.25s var(--ease, cubic-bezier(0.4, 0, 0.2, 1)),
                opacity   0.2s  var(--ease, cubic-bezier(0.4, 0, 0.2, 1));
    pointer-events: none;
}

.chat-notes-panel.is-open {
    transform: translateX(0);
    opacity: 1;
    pointer-events: auto;
}


/* ── Mobile: full-screen tab replacing the chat ──────────────────────────── */
@media (max-width: 767px) {
    .chat-notes-panel {
        position: fixed;
        inset: 0;
        left: 0;
        width: 100%;
        height: 100dvh;
        border-left: none;
        box-shadow: none;
        border-radius: 0;
        /* Slide up from below */
        transform: translateY(6%) scale(0.97);
        opacity: 0;
        transition: transform 0.25s var(--ease, cubic-bezier(0.4, 0, 0.2, 1)),
                    opacity   0.22s var(--ease, cubic-bezier(0.4, 0, 0.2, 1));
    }

    .chat-notes-panel.is-open {
        transform: translateY(0) scale(1);
        opacity: 1;
    }

    /* Hide chat messages + input while notepad tab is active on mobile */
    body.notes-tab-active #messages,
    body.notes-tab-active .input-area,
    body.notes-tab-active #reply-message-bar,
    body.notes-tab-active #edit-message-bar,
    body.notes-tab-active #pinned-messages-bar {
        display: none !important;
    }

    /* Search bar is always visible on mobile — override the is-hidden toggle */
    #chat-notes-search-bar.is-hidden {
        display: flex !important;
    }

    /* The header toggle button is redundant when search is always shown */
    #chat-notes-search-btn {
        display: none !important;
    }

    /* The search-bar close (×) button is irrelevant when bar cannot be hidden */
    #chat-notes-search-close-btn {
        display: none !important;
    }
}



/* ── Panel header ────────────────────────────────────────────────────────── */

.chat-notes-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 14px 0;
    flex-shrink: 0;
    position: relative; /* stays above the editor stacking context */
    z-index: 2;
}

.chat-notes-title {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--notes-text-dim);
    letter-spacing: 0.02em;
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-notes-close {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: var(--notes-text-faint);
    cursor: pointer;
    flex-shrink: 0;
    transition: background var(--duration, 0.15s), color var(--duration, 0.15s);
}

.chat-notes-close:hover {
    background: var(--notes-bg-hover);
    color: var(--notes-text);
}

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

.chat-notes-tabs {
    display: flex;
    gap: 4px;
    padding: 10px 14px 0;
    flex-shrink: 0;
    position: relative; /* own stacking context above the editor */
    z-index: 2;
}

.chat-notes-tab {
    flex: 1;
    padding: 6px 8px;
    border: none;
    border-radius: 8px;
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    cursor: pointer;
    transition: background var(--duration, 0.15s), color var(--duration, 0.15s);
    background: transparent;
    color: var(--notes-text-faint);
}

.chat-notes-tab:hover {
    background: var(--notes-bg-hover);
    color: var(--notes-text-dim);
}

.chat-notes-tab.is-active {
    background: color-mix(in srgb, var(--notes-accent) 15%, transparent);
    color: var(--notes-accent);
}

/* ── Conflict banner ─────────────────────────────────────────────────────── */

.chat-notes-conflict-banner {
    margin: 6px 14px 0;
    padding: 6px 10px;
    border-radius: 8px;
    /* Warning yellow — semantic, not theme-dependent */
    background: rgba(251, 191, 36, 0.1);
    border: 1px solid rgba(251, 191, 36, 0.2);
    font-size: 0.72rem;
    color: rgba(251, 191, 36, 0.9);
    line-height: 1.4;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    gap: 4px;
}

.chat-notes-conflict-banner.is-hidden {
    display: none;
}

/* ── Context menu (formatting, clipboard) ───────────────────────────────── */

.notes-ctx-menu {
    position: absolute;
    z-index: 200;
    min-width: 140px;
    background: var(--surface-2, #202b36);
    border: 1px solid var(--notes-border-2);
    border-radius: 10px;
    box-shadow: 0 8px 22px rgba(0,0,0,0.34);
    padding: 4px;
    display: flex;
    flex-direction: column;
    gap: 1px;
}

.notes-ctx-menu.is-hidden { display: none; }

.notes-ctx-fmt-row {
    display: flex;
    gap: 2px;
    padding: 4px;
}

.notes-ctx-fmt-btn {
    flex: 1;
    min-width: 28px;
    height: 28px;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: var(--notes-text-dim);
    font-size: 0.82rem;
    font-weight: 700;
    cursor: pointer;
    transition: background 0.12s, color 0.12s;
}

.notes-ctx-fmt-btn:hover {
    background: var(--notes-bg-hover);
    color: var(--notes-text);
}

.notes-ctx-sep {
    border: none;
    border-top: 1px solid var(--notes-border);
    margin: 2px 4px;
}

.notes-ctx-item {
    display: block;
    width: 100%;
    padding: 7px 12px;
    text-align: left;
    background: transparent;
    border: none;
    border-radius: 7px;
    color: var(--notes-text);
    font-size: 0.8rem;
    cursor: pointer;
    transition: background 0.12s;
}

.notes-ctx-item:hover {
    background: var(--notes-bg-hover);
}

/* ── Editor body (contenteditable WYSIWYG) ───────────────────────────────── */

.chat-notes-body {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    padding: 10px 14px 4px;
    position: relative; /* context menu positioning context */
}

.chat-notes-editor {
    flex: 1;
    width: 100%;
    border: none;
    outline: none;
    background: transparent;
    color: var(--notes-text);
    font-size: 0.84rem;
    line-height: 1.6;
    font-family: inherit;
    caret-color: var(--notes-accent);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    scrollbar-color: var(--notes-border-2) transparent;
    word-break: break-word;
    white-space: pre-wrap;
    cursor: text;
    /* Establish a stacking context so .katomu-spoiler (z-index:5) renders   */
    /* above sibling panel elements (tabs, header) that share the same parent */
    position: relative;
    z-index: 1;
}

.chat-notes-editor:empty::before {
    content: attr(data-placeholder);
    color: var(--notes-text-faint);
    pointer-events: none;
}

.chat-notes-editor::-webkit-scrollbar { width: 4px; }
.chat-notes-editor::-webkit-scrollbar-thumb {
    background: var(--notes-border-2);
    border-radius: 2px;
}

/* Inline formatting inside contenteditable */
.chat-notes-editor strong { font-weight: 700; }
.chat-notes-editor em     { font-style: italic; }
.chat-notes-editor s      { text-decoration: line-through; }





/* ── Footer ──────────────────────────────────────────────────────────────── */

.chat-notes-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 14px 12px;
    flex-shrink: 0;
    min-height: 32px;
    gap: 8px;
}

.chat-notes-footer-right {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}

/* Save status */
.chat-notes-status {
    font-size: 0.7rem;
    color: var(--notes-text-faint);
    transition: color 0.2s;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-notes-status.is-saving {
    color: var(--notes-text-dim);
}

.chat-notes-status.is-saved {
    /* Soft green — semantic success, same across themes */
    color: #4ade80;
    opacity: 0.75;
}

.chat-notes-status.is-error {
    /* Soft red — semantic error, same across themes */
    color: #f87171;
    opacity: 0.8;
}

/* Partner typing indicator */
.chat-notes-partner-typing {
    font-size: 0.68rem;
    color: var(--notes-accent);
    opacity: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: opacity 0.25s;
    flex-shrink: 0;
}

.chat-notes-partner-typing.is-visible {
    opacity: 0.6;
}

/* ── Char counter ────────────────────────────────────────────────────────── */

.chat-notes-char-counter {
    font-size: 0.68rem;
    color: var(--notes-text-faint);
    flex-shrink: 0;
    user-select: none;
}

.chat-notes-char-counter.is-near-limit {
    /* Warning yellow — semantic */
    color: rgba(251, 191, 36, 0.75);
}

.chat-notes-char-counter.is-at-limit {
    /* Error red — semantic */
    color: #f87171;
    opacity: 0.8;
}

/* ── Copy button ─────────────────────────────────────────────────────────── */

.chat-notes-copy-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: var(--notes-text-faint);
    cursor: pointer;
    transition: background 0.12s, color 0.12s;
    padding: 0;
    flex-shrink: 0;
}

.chat-notes-copy-btn:hover {
    background: var(--notes-bg-hover);
    color: var(--notes-text);
}

/* ── Header search button ────────────────────────────────────────────────── */

.chat-notes-header-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: var(--notes-text-faint);
    cursor: pointer;
    flex-shrink: 0;
    transition: background var(--duration, 0.15s), color var(--duration, 0.15s);
}

.chat-notes-header-btn:hover {
    background: var(--notes-bg-hover);
    color: var(--notes-text);
}

.chat-notes-header-btn.is-active {
    background: color-mix(in srgb, var(--notes-accent) 15%, transparent);
    color: var(--notes-accent);
}

/* ── Search bar ──────────────────────────────────────────────────────────── */

.chat-notes-search-bar {
    display: flex;
    align-items: center;
    gap: 4px;
    margin: 6px 14px 0;
    padding: 5px 8px;
    background: var(--notes-bg-hover);
    border: 1px solid var(--notes-border-2);
    border-radius: 10px;
    flex-shrink: 0;
}

.chat-notes-search-bar.is-hidden {
    display: none;
}

.chat-notes-search-icon {
    flex-shrink: 0;
    color: var(--notes-text-faint);
}

.chat-notes-search-input {
    flex: 1;
    border: none;
    outline: none;
    background: transparent;
    color: var(--notes-text);
    font-size: 0.8rem;
    font-family: inherit;
    min-width: 0;
    /* Remove native ✕ in search inputs */
}
.chat-notes-search-input::-webkit-search-cancel-button { display: none; }
.chat-notes-search-input::placeholder { color: var(--notes-text-faint); }

.chat-notes-search-count {
    font-size: 0.7rem;
    color: var(--notes-text-faint);
    white-space: nowrap;
    flex-shrink: 0;
    min-width: 44px;
    text-align: center;
}

.chat-notes-search-count.is-no-match {
    color: #f87171;
    opacity: 0.8;
}

.chat-notes-search-nav,
.chat-notes-search-close-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: var(--notes-text-faint);
    cursor: pointer;
    flex-shrink: 0;
    transition: background 0.12s, color 0.12s;
    padding: 0;
}

.chat-notes-search-nav:hover,
.chat-notes-search-close-btn:hover {
    background: var(--notes-border-2);
    color: var(--notes-text);
}

/* ── Search match highlights ─────────────────────────────────────────────── */

mark.notes-search-match {
    background: rgba(251, 191, 36, 0.30);
    color: inherit;
    border-radius: 2px;
    padding: 0 1px;
}

mark.notes-search-match.is-active {
    background: rgba(251, 191, 36, 0.75);
    color: #1a1a1a;
    border-radius: 2px;
    outline: 1px solid rgba(251, 191, 36, 0.9);
}



/* ── Pins / Bookmarks panel ──────────────────────────────────────────────── */

.chat-notes-pins {
    margin: 4px 14px 0;
    border-left: 2px solid var(--notes-border-2);
    flex-shrink: 0;
    max-height: 100px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.chat-notes-pins.is-hidden { display: none; }

/* Hide decorative header */
.chat-notes-pins-header { display: none; }

.chat-notes-pins-list {
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    scrollbar-color: var(--notes-border-2) transparent;
    padding: 2px 0;
    display: flex;
    flex-direction: column;
}

.chat-notes-pins-list::-webkit-scrollbar { width: 3px; }
.chat-notes-pins-list::-webkit-scrollbar-thumb {
    background: var(--notes-border-2);
    border-radius: 2px;
}

.chat-notes-pin-card {
    display: flex;
    align-items: center;
}

.chat-notes-pin-text {
    flex: 1;
    border: none;
    background: transparent;
    color: var(--notes-text-faint);
    font-size: 0.74rem;
    font-family: inherit;
    text-align: left;
    padding: 2px 10px;
    cursor: pointer;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.7;
    transition: color 0.1s;
}

.chat-notes-pin-text:hover { color: var(--notes-text); }

.chat-notes-pin-remove {
    display: none; /* shown only on card hover */
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    border: none;
    border-radius: 3px;
    background: transparent;
    color: var(--notes-text-faint);
    font-size: 0.7rem;
    cursor: pointer;
    flex-shrink: 0;
    margin-right: 6px;
    transition: color 0.1s;
}

.chat-notes-pin-card:hover .chat-notes-pin-remove {
    display: flex;
}

.chat-notes-pin-remove:hover { color: var(--notes-text); }

/* Pinned block — subtle left marker only, no emoji, no animation */
.chat-notes-editor [data-pinned] {
    border-left: 2px solid var(--notes-border-2);
    padding-left: 8px;
    margin-left: -10px;
}

/* ── Pin button in context menu ──────────────────────────────────────────── */
.notes-ctx-item--pin { color: var(--notes-text-dim) !important; }

/* ── Slash command palette ───────────────────────────────────────────────── */

.notes-slash-palette {
    position: fixed;
    z-index: 10000;
    min-width: 180px;
    background: var(--notes-bg);
    border: 1px solid var(--notes-border-2);
    border-radius: 8px;
    box-shadow: 0 3px 12px rgba(0,0,0,0.28);
    padding: 4px;
    display: flex;
    flex-direction: column;
}

.notes-slash-palette.is-hidden { display: none; }

/* Remove 'Тип блока' hint — unnecessary noise */
.notes-slash-palette::before { display: none; }

.notes-slash-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 5px 8px;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.1s;
}

.notes-slash-item:hover,
.notes-slash-item.is-selected { background: var(--notes-bg-hover); }

.notes-slash-icon {
    font-size: 0.7rem;
    font-weight: 700;
    color: var(--notes-text-faint);
    width: 20px;
    text-align: center;
    flex-shrink: 0;
    font-family: monospace;
}

.notes-slash-label {
    font-size: 0.78rem;
    color: var(--notes-text-dim);
}

/* ── Hover pin button ────────────────────────────────────────────────────── */

.notes-hover-pin-btn {
    position: fixed;
    z-index: 9999;
    width: 16px;
    height: 16px;
    border: none;
    border-radius: 3px;
    background: transparent;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.15s;
    padding: 0;
    color: var(--notes-text-faint);
    font-size: 0.62rem;
}

/* Show on hover via JS adding class */
.notes-hover-pin-btn:hover { opacity: 1 !important; }
.notes-hover-pin-btn.is-pinned { opacity: 0.5; }
.notes-hover-pin-btn.is-hidden { display: none; }
