/* ==========================================================================
   Wattpad-Style Inline Comments
   Sử dụng lại CSS custom properties của theme Webnovel (--bg-elevated,
   --fg-1, --accent, --border, --r-md, --sp-*, --font-ui, v.v.) nên tự động
   ăn theo dark/light mode. Có giá trị fallback để vẫn chạy được trên theme
   khác không định nghĩa các biến này.
   ========================================================================== */

:root {
    --wic-bg: var(--bg-elevated, #1e1e1e);
    --wic-bg-2: var(--bg-2, #17181a);
    --wic-fg: var(--fg-1, #f2f2f2);
    --wic-fg-muted: var(--fg-3, #9a9a9a);
    --wic-border: var(--border, #2c2c2c);
    --wic-accent: var(--accent, #d99a4e);
    --wic-accent-subtle: var(--accent-subtle, rgba(217, 154, 78, 0.15));
    --wic-radius: var(--r-md, 10px);
    --wic-radius-sm: var(--r-sm, 6px);
    --wic-font: var(--font-ui, system-ui, sans-serif);
    --wic-shadow: var(--shadow-lg, 0 12px 40px rgba(0,0,0,0.35));
    --wic-panel-width: 380px;
}

/* Đoạn văn được đánh dấu để hỗ trợ đặt nút bình luận */
.wn-reader__content p.wic-para {
    position: relative;
}

.wn-reader__content p.wic-para.wic-para--active {
    background: var(--wic-accent-subtle);
    border-radius: var(--wic-radius-sm);
    transition: background var(--dur-normal, 300ms) var(--ease-out, ease);
}

/* Nút bong bóng bình luận, neo ở lề phải đoạn văn (giống Wattpad) */
.wic-bubble {
    position: absolute;
    top: 0.15em;
    right: -44px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 3px;
    width: 34px;
    height: 28px;
    padding: 0 6px;
    border-radius: 999px;
    border: 1px solid var(--wic-border);
    background: var(--wic-bg);
    color: var(--wic-fg-muted);
    font-family: var(--wic-font);
    font-size: 0.72rem;
    cursor: pointer;
    opacity: 0;
    transform: translateX(-4px);
    transition: opacity 150ms ease, transform 150ms ease, color 150ms ease, border-color 150ms ease;
    z-index: 2;
}

.wn-reader__content p.wic-para:hover .wic-bubble,
.wic-bubble--has-comments,
.wic-bubble--active {
    opacity: 1;
    transform: translateX(0);
}

.wic-bubble--has-comments {
    color: var(--wic-accent);
    border-color: var(--wic-accent);
}

.wic-bubble--active {
    background: var(--wic-accent);
    color: var(--accent-fg, #1a1a1a);
    border-color: var(--wic-accent);
}

.wic-bubble svg {
    width: 14px;
    height: 14px;
    flex-shrink: 0;
}

.wic-bubble__count {
    line-height: 1;
    font-weight: 600;
}

/* Trên màn hình hẹp (viewport không đủ chỗ để đặt bubble ở lề), chuyển
   bubble vào cuối đoạn văn dạng inline pill thay vì absolute ở lề phải. */
@media (max-width: 1100px) {
    .wic-bubble {
        position: static;
        display: inline-flex;
        margin-left: 8px;
        opacity: 1;
        transform: none;
        vertical-align: middle;
    }
}

/* ─── Panel bình luận (slide-over) ─── */
.wic-overlay {
    position: fixed;
    inset: 0;
    background: var(--overlay, rgba(0,0,0,0.5));
    z-index: 9998;
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--dur-normal, 300ms) var(--ease-out, ease);
}

.wic-overlay--open {
    opacity: 1;
    pointer-events: auto;
}

.wic-panel {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: var(--wic-panel-width);
    max-width: 92vw;
    background: var(--wic-bg);
    border-left: 1px solid var(--wic-border);
    box-shadow: var(--wic-shadow);
    z-index: 9999;
    display: flex;
    flex-direction: column;
    transform: translateX(100%);
    transition: transform var(--dur-normal, 300ms) var(--ease-out-expo, ease);
    font-family: var(--wic-font);
}

.wic-panel--open {
    transform: translateX(0);
}

.wic-panel__header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: var(--sp-3, 12px);
    padding: var(--sp-4, 16px) var(--sp-4, 16px) var(--sp-3, 12px);
    border-bottom: 1px solid var(--wic-border);
}

.wic-panel__title {
    font-size: var(--text-sm, 0.875rem);
    font-weight: 700;
    color: var(--wic-fg);
    margin: 0 0 4px;
}

.wic-panel__quote {
    font-size: var(--text-xs, 0.75rem);
    color: var(--wic-fg-muted);
    font-style: italic;
    line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.wic-panel__close {
    flex-shrink: 0;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: none;
    background: transparent;
    color: var(--wic-fg-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    line-height: 1;
}

.wic-panel__close:hover {
    background: var(--bg-hover, rgba(255,255,255,0.06));
    color: var(--wic-fg);
}

.wic-panel__list {
    flex: 1;
    overflow-y: auto;
    padding: var(--sp-4, 16px);
    display: flex;
    flex-direction: column;
    gap: var(--sp-4, 16px);
}

.wic-panel__empty {
    color: var(--wic-fg-muted);
    font-size: var(--text-sm, 0.875rem);
    text-align: center;
    padding: var(--sp-8, 32px) var(--sp-4, 16px);
}

.wic-comment {
    display: flex;
    gap: var(--sp-3, 12px);
}

.wic-comment__avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    flex-shrink: 0;
    background: var(--wic-bg-2);
    object-fit: cover;
}

.wic-comment__body {
    flex: 1;
    min-width: 0;
}

.wic-comment__meta {
    display: flex;
    align-items: baseline;
    gap: 6px;
    margin-bottom: 2px;
}

.wic-comment__author {
    font-size: var(--text-sm, 0.875rem);
    font-weight: 600;
    color: var(--wic-fg);
}

.wic-comment__date {
    font-size: var(--text-xs, 0.75rem);
    color: var(--wic-fg-muted);
}

.wic-comment__text {
    font-size: var(--text-sm, 0.875rem);
    color: var(--wic-fg);
    line-height: 1.55;
    white-space: pre-wrap;
    word-break: break-word;
}

.wic-comment__delete {
    background: none;
    border: none;
    color: var(--wic-fg-muted);
    font-size: var(--text-xs, 0.75rem);
    cursor: pointer;
    padding: 2px 0;
    margin-top: 2px;
}

.wic-comment__delete:hover {
    color: var(--danger, #d33);
    text-decoration: underline;
}

.wic-panel__footer {
    border-top: 1px solid var(--wic-border);
    padding: var(--sp-3, 12px) var(--sp-4, 16px) var(--sp-4, 16px);
}

.wic-panel__textarea {
    width: 100%;
    resize: vertical;
    min-height: 64px;
    max-height: 160px;
    background: var(--wic-bg-2);
    border: 1px solid var(--wic-border);
    border-radius: var(--wic-radius-sm);
    color: var(--wic-fg);
    font-family: var(--font-body, inherit);
    font-size: var(--text-sm, 0.875rem);
    padding: var(--sp-3, 12px);
    box-sizing: border-box;
}

.wic-panel__textarea:focus {
    outline: none;
    border-color: var(--wic-accent);
}

.wic-panel__actions {
    display: flex;
    justify-content: flex-end;
    margin-top: var(--sp-2, 8px);
}

.wic-btn-send {
    background: var(--wic-accent);
    color: var(--accent-fg, #1a1a1a);
    border: none;
    border-radius: var(--wic-radius-sm);
    padding: 8px 18px;
    font-size: var(--text-sm, 0.875rem);
    font-weight: 600;
    font-family: var(--wic-font);
    cursor: pointer;
    transition: opacity 150ms ease;
}

.wic-btn-send:disabled {
    opacity: 0.5;
    cursor: default;
}

.wic-btn-send:not(:disabled):hover {
    opacity: 0.9;
}

.wic-login-prompt {
    text-align: center;
    font-size: var(--text-sm, 0.875rem);
    color: var(--wic-fg-muted);
}

.wic-login-prompt a {
    color: var(--wic-accent);
    font-weight: 600;
    text-decoration: none;
}

.wic-login-prompt a:hover {
    text-decoration: underline;
}

.wic-panel__error {
    color: var(--danger, #d33);
    font-size: var(--text-xs, 0.75rem);
    margin-top: 6px;
}

/* Mobile: panel biến thành bottom sheet chiếm khoảng 80% màn hình */
@media (max-width: 640px) {
    .wic-panel {
        width: 100%;
        max-width: 100%;
        top: auto;
        height: 82vh;
        border-left: none;
        border-top: 1px solid var(--wic-border);
        border-radius: var(--r-lg, 16px) var(--r-lg, 16px) 0 0;
        transform: translateY(100%);
    }
    .wic-panel--open {
        transform: translateY(0);
    }
}
