/**
 * TGWV Rich Editor — Typography & content styles (admin + frontend)
 *
 * Scope: .tgwv-editor-body (vùng nội dung HTML từ trình soạn thảo).
 */

.tgwv-editor-body {
    --tgwv-content-font-size: var(--tgwv-font-size-body, 14px);
    --tgwv-content-font-size-sm: var(--tgwv-font-size-body, 14px);
    --tgwv-content-line-height: 1.3;
    --tgwv-content-color: var(--tgwv-color-dark);
    --tgwv-content-color-muted: #495057;
    --tgwv-content-link: #0d6efd;
    --tgwv-content-link-hover: #0a58ca;
    --tgwv-content-border: #dee2e6;
    --tgwv-content-bg-soft: #f8f9fa;
    --tgwv-content-radius: 6px;
    --tgwv-content-space: 1.25rem;

    font-size: var(--tgwv-content-font-size);
    line-height: var(--tgwv-content-line-height);
    color: var(--tgwv-content-color);
    word-wrap: break-word;
    overflow-wrap: break-word;
}

/* Headings */
.tgwv-editor-body h1,
.tgwv-editor-body h2,
.tgwv-editor-body h3,
.tgwv-editor-body h4,
.tgwv-editor-body h5,
.tgwv-editor-body h6 {
    font-weight: 600;
    color: var(--tgwv-color-dark);
    line-height: 1.4;
    margin-top: 10px;
    margin-bottom: 10px;
}

.tgwv-editor-body h1 {
    font-size: clamp(22px, 2vw + 14px, 28px);
}

.tgwv-editor-body h2 {
    font-size: clamp(20px, 1.5vw + 14px, 24px);
}

.tgwv-editor-body h3 {
    font-size: clamp(18px, 1vw + 14px, 20px);
}

.tgwv-editor-body h4 {
    font-size: clamp(16px, 1vw + 14px, 17px);
}

.tgwv-editor-body h5 {
    font-size: 15px;
}

.tgwv-editor-body h6 {
    font-size: 14px;
    color: var(--tgwv-content-color-muted);
}

/* Paragraphs */
.tgwv-editor-body p {
    margin-top: 10px;
    margin-bottom: 10px;
    line-height: 1.4;
}

/* Links */
.tgwv-editor-body a {
    color: var(--tgwv-content-link);
    text-decoration: underline;
    text-underline-offset: 2px;
    transition: color 0.15s ease;
}

.tgwv-editor-body a:hover {
    color: var(--tgwv-content-link-hover);
}

.tgwv-editor-body a[target="_blank"]::after {
    content: "";
    display: inline-block;
    width: 0.85em;
    height: 0.85em;
    margin-left: 0.15em;
    vertical-align: -0.1em;
    opacity: 0.65;
    background: currentColor;
    mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2'%3E%3Cpath d='M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6'/%3E%3Cpolyline points='15 3 21 3 21 9'/%3E%3Cline x1='10' y1='14' x2='21' y2='3'/%3E%3C/svg%3E") center / contain no-repeat;
}

/* Lists */
.tgwv-editor-body ul,
.tgwv-editor-body ol {
    margin: 0 0 var(--tgwv-content-space);
    padding-left: 1.5em;
}

.tgwv-editor-body li {
    margin-bottom: 0.4em;
}

.tgwv-editor-body ul {
    list-style-type: disc;
}

.tgwv-editor-body ol {
    list-style-type: decimal;
}

.tgwv-editor-body ul ul,
.tgwv-editor-body ol ol {
    margin-top: 0.35em;
    margin-bottom: 0.35em;
}

/* Blockquote */
.tgwv-editor-body blockquote {
    margin: 0 0 var(--tgwv-content-space);
    padding: 0.85em 1.1em;
    border-left: 4px solid var(--tgwv-content-link);
    background: var(--tgwv-content-bg-soft);
    color: var(--tgwv-content-color-muted);
    border-radius: 0 var(--tgwv-content-radius) var(--tgwv-content-radius) 0;
}

.tgwv-editor-body blockquote p:last-child {
    margin-bottom: 0;
}

/* Horizontal rule */
.tgwv-editor-body hr {
    border: 0;
    border-top: 1px solid var(--tgwv-content-border);
    margin: 1.5em 0;
}

/* Inline text */
.tgwv-editor-body strong,
.tgwv-editor-body b {
    font-weight: 700;
}

.tgwv-editor-body em,
.tgwv-editor-body i {
    font-style: italic;
}

.tgwv-editor-body u {
    text-decoration: underline;
}

.tgwv-editor-body s,
.tgwv-editor-body strike {
    text-decoration: line-through;
}

.tgwv-editor-body sub,
.tgwv-editor-body sup {
    font-size: 12px;
    line-height: 0;
}

.tgwv-editor-body sub {
    vertical-align: sub;
}

.tgwv-editor-body sup {
    vertical-align: super;
}

.tgwv-editor-body address {
    font-style: normal;
    margin-bottom: var(--tgwv-content-space);
}

/* Code */
.tgwv-editor-body code {
    font-size: 15px;
    padding: 0.15em 0.4em;
    background: var(--tgwv-content-bg-soft);
    border-radius: 4px;
    color: #c7254e;
}

.tgwv-editor-body p.tgwv-block-host,
.tgwv-editor-body figure.tgwv-block-host:not(.tgwv-youtube) {
    margin: 0 0 var(--tgwv-content-space);
}

.tgwv-editor-body p.tgwv-block-host > pre {
    margin: 0;
}

.tgwv-editor-body p.tgwv-block-host > img,
.tgwv-editor-body figure.tgwv-block-host > img,
.tgwv-editor-body figure.tgwv-block-host > a > img {
    display: block;
}

.tgwv-editor-body img.tgwv-img-selected,
.tgwv-editor-body p.tgwv-block-host.tgwv-img-selected > img,
.tgwv-editor-body p.tgwv-block-host.tgwv-img-selected > a > img,
.tgwv-editor-body figure.tgwv-block-host.tgwv-img-selected img,
.tgwv-editor-body figure.tgwv-img-selected img {
    outline: 2px solid #000;
    outline-offset: 2px;
    cursor: pointer;
}

.tgwv-editor-body figure.tgwv-youtube.tgwv-youtube-selected,
.tgwv-editor-body figure.tgwv-block-host.tgwv-youtube.tgwv-youtube-selected {
    outline: 2px solid #000;
    outline-offset: 4px;
    cursor: pointer;
}

.tgwv-editor-body figure.tgwv-youtube.tgwv-youtube-selected iframe,
.tgwv-editor-body figure.tgwv-youtube.tgwv-youtube-selected .tgwv-youtube-poster {
    cursor: pointer;
}

.tgwv-editor-body p.tgwv-block-host > a,
.tgwv-editor-body figure.tgwv-block-host:not(.tgwv-youtube) > a {
    display: inline-block;
    max-width: 100%;
}

.tgwv-editor-body p.tgwv-block-host > a > img,
.tgwv-editor-body figure.tgwv-block-host > a > img,
.tgwv-editor-body figure a > img {
    display: block;
}

.tgwv-editor-body pre {
    margin: 0 0 var(--tgwv-content-space);
    padding: 1em 1.15em;
    background: #1e1e1e;
    color: #f8f8f2;
    border-radius: var(--tgwv-content-radius);
    overflow-x: auto;
    font-size: var(--tgwv-content-font-size-sm);
    line-height: 1.55;
}

.tgwv-editor-body pre code {
    padding: 0;
    background: transparent;
    color: inherit;
    font-size: inherit;
}

/* Images & media */
.tgwv-editor-body img {
    max-width: 100%;
    height: auto;
    border-radius: var(--tgwv-content-radius);
}

.tgwv-editor-body figure:not(.tgwv-block-host) {
    margin: 0 0 var(--tgwv-content-space);
    max-width: 100%;
}

.tgwv-editor-body figure.tgwv-block-host:not(.tgwv-youtube) {
    max-width: 100%;
}

.tgwv-editor-body figure img,
.tgwv-editor-body figure.tgwv-block-host img {
    display: block;
    margin: 0 auto;
}

.tgwv-editor-body figcaption {
    margin-top: 0.5em;
    font-size: var(--tgwv-content-font-size-sm);
    color: var(--tgwv-content-color-muted);
    text-align: center;
    outline: none;
}

.tgwv-editor-body figcaption:focus {
    box-shadow: 0 0 0 2px rgba(74, 134, 232, 0.25);
    border-radius: 4px;
}

.tgwv-editor-body iframe,
.tgwv-editor-body video {
    max-width: 100%;
    border: 0;
    border-radius: var(--tgwv-content-radius);
}

/* Video file (.mp4) */
.tgwv-editor-body figure.tgwv-block-host.tgwv-native-video,
.tgwv-native-video {
    display: block;
    margin: 0 0 var(--tgwv-content-space, 1.25rem);
    padding: 0;
    position: relative;
}

.tgwv-editor-body figure.tgwv-native-video > video,
.tgwv-native-video > video {
    display: block;
    width: 100%;
    max-width: 100%;
}

.tgwv-editor-body figure.tgwv-native-video.tgwv-native-video-selected {
    outline: 2px solid rgba(74, 134, 232, 0.65);
    outline-offset: 3px;
    border-radius: var(--tgwv-content-radius, 6px);
}

/* Video không controls: poster + nút Play */
.tgwv-editor-body figure.tgwv-native-video[data-tgwv-show-controls="0"],
figure.tgwv-native-video[data-tgwv-show-controls="0"],
.tgwv-editor-body figure.tgwv-native-video.tgwv-native-video--poster-inline,
figure.tgwv-native-video.tgwv-native-video--poster-inline,
.tgwv-editor-body figure.tgwv-native-video.tgwv-native-video--poster-modal,
figure.tgwv-native-video.tgwv-native-video--poster-modal,
.tgwv-editor-body figure.tgwv-native-video:not([data-tgwv-show-controls="1"]) > video:not([controls]),
figure.tgwv-native-video:not([data-tgwv-show-controls="1"]) > video:not([controls]) {
    position: relative;
    line-height: 0;
}

.tgwv-editor-body figure.tgwv-native-video[data-tgwv-show-controls="0"] > video,
figure.tgwv-native-video[data-tgwv-show-controls="0"] > video {
    border-radius: var(--tgwv-content-radius, 6px);
    background: #000;
}

.tgwv-editor-body .tgwv-native-video-overlay,
.tgwv-native-video-overlay {
    position: absolute;
    inset: 0;
    z-index: 2;
    display: flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    border-radius: var(--tgwv-content-radius, 6px);
    cursor: pointer;
    background: rgba(0, 0, 0, 0.12);
}

.tgwv-editor-body figure.tgwv-native-video.tgwv-native-video-is-playing .tgwv-native-video-overlay,
figure.tgwv-native-video.tgwv-native-video-is-playing .tgwv-native-video-overlay {
    display: none;
}

.tgwv-editor-body .tgwv-native-video-play,
.tgwv-native-video-play {
    position: relative;
    width: 68px;
    height: 48px;
    border-radius: 12px;
    background: rgba(255, 0, 0, 0.9);
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.35);
    pointer-events: none;
}

.tgwv-editor-body .tgwv-native-video-play::after,
.tgwv-native-video-play::after {
    content: '';
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-40%, -50%);
    border-style: solid;
    border-width: 10px 0 10px 18px;
    border-color: transparent transparent transparent #fff;
}

.tgwv-editor-body .tgwv-native-video-overlay:hover .tgwv-native-video-play,
.tgwv-native-video-overlay:hover .tgwv-native-video-play {
    background: rgba(220, 0, 0, 1);
}

.tgwv-native-video-modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 10050;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    background: rgba(0, 0, 0, 0.75);
}

.tgwv-native-video-modal-inner {
    position: relative;
    width: min(960px, 100%);
    max-height: 90vh;
    background: #000;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 12px 48px rgba(0, 0, 0, 0.45);
}

.tgwv-native-video-modal-inner video {
    display: block;
    width: 100%;
    max-height: 90vh;
}

.tgwv-native-video-modal-close {
    position: absolute;
    top: 12px;
    right: 12px;
    z-index: 2;
    width: 40px;
    height: 40px;
    border: 0;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.55);
    color: #fff;
    font-size: 26px;
    line-height: 1;
    cursor: pointer;
}

body.tgwv-native-video-modal-open {
    overflow: hidden;
}

.tgwv-editor-body iframe {
    aspect-ratio: 16 / 9;
    width: 100%;
    min-height: 200px;
}

/* YouTube embed blocks */
.tgwv-editor-body figure.tgwv-block-host.tgwv-youtube,
.tgwv-youtube {
    position: relative;
    display: block;
    box-sizing: border-box;
    margin-top: 0;
    margin-bottom: var(--tgwv-content-space, 1.25rem);
    padding: 0;
    border: 0;
    background: transparent;
}

.tgwv-editor-body figure.tgwv-block-host.tgwv-youtube.tgwv-youtube--align-left,
.tgwv-youtube.tgwv-youtube--align-left {
    margin-left: 0;
    margin-right: auto;
}

.tgwv-editor-body figure.tgwv-block-host.tgwv-youtube.tgwv-youtube--align-center,
.tgwv-youtube.tgwv-youtube--align-center {
    margin-left: auto;
    margin-right: auto;
}

.tgwv-editor-body figure.tgwv-block-host.tgwv-youtube.tgwv-youtube--align-right,
.tgwv-youtube.tgwv-youtube--align-right {
    margin-left: auto;
    margin-right: 0;
}

.tgwv-editor-body figure.tgwv-block-host.tgwv-youtube > a.tgwv-youtube-poster,
.tgwv-youtube > a.tgwv-youtube-poster {
    display: block;
    width: 100%;
    max-width: 100%;
}

.tgwv-editor-body .tgwv-youtube iframe,
.tgwv-youtube iframe {
    display: block;
    width: 100%;
    max-width: 100%;
    aspect-ratio: 16 / 9;
    min-height: 200px;
    border: 0;
    border-radius: var(--tgwv-content-radius, 6px);
}

/* Chỉ trong vùng soạn thảo (admin): iframe không nhận click — dùng double-click để sửa khối */
.tgwv-editor-wrap .tgwv-editor-body figure.tgwv-youtube.tgwv-youtube--embed > iframe {
    pointer-events: none;
}

.tgwv-editor-wrap .tgwv-editor-body figure.tgwv-youtube.tgwv-youtube--embed {
    cursor: pointer;
}

.tgwv-editor-body .tgwv-youtube-poster,
.tgwv-youtube-poster {
    position: relative;
    display: block;
    line-height: 0;
    text-decoration: none;
    border-radius: var(--tgwv-content-radius, 6px);
    overflow: hidden;
    cursor: pointer;
}

.tgwv-editor-body .tgwv-youtube-poster img,
.tgwv-youtube-poster img {
    display: block;
    width: 100%;
    height: auto;
    aspect-ratio: 16 / 9;
    object-fit: cover;
    margin: 0;
    border-radius: var(--tgwv-content-radius, 6px);
}

.tgwv-editor-body .tgwv-youtube-play,
.tgwv-youtube-play {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    width: 68px;
    height: 48px;
    border-radius: 12px;
    background: rgba(255, 0, 0, 0.9);
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.35);
    pointer-events: none;
}

.tgwv-editor-body .tgwv-youtube-play::after,
.tgwv-youtube-play::after {
    content: '';
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-40%, -50%);
    border-style: solid;
    border-width: 10px 0 10px 18px;
    border-color: transparent transparent transparent #fff;
}

.tgwv-editor-body .tgwv-youtube-poster:hover .tgwv-youtube-play,
.tgwv-youtube-poster:hover .tgwv-youtube-play {
    background: rgba(220, 0, 0, 1);
}

.tgwv-youtube-modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 10050;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    background: rgba(0, 0, 0, 0.75);
}

.tgwv-youtube-modal-inner {
    position: relative;
    width: min(960px, 100%);
    aspect-ratio: 16 / 9;
    background: #000;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 12px 48px rgba(0, 0, 0, 0.45);
}

.tgwv-youtube-modal-inner iframe {
    width: 100%;
    height: 100%;
    border: 0;
    display: block;
}

.tgwv-youtube-modal-close {
    position: absolute;
    top: 12px;
    right: 12px;
    z-index: 2;
    width: 40px;
    height: 40px;
    border: 0;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.55);
    color: #fff;
    font-size: 26px;
    line-height: 1;
    cursor: pointer;
}

.tgwv-youtube-modal-close:hover {
    background: rgba(0, 0, 0, 0.8);
}

body.tgwv-youtube-modal-open {
    overflow: hidden;
}

/* Tables */
.tgwv-editor-body table {
    width: 100%;
    max-width: 100%;
    border-collapse: collapse;
    margin: 0 0 var(--tgwv-content-space);
    font-size: inherit;
}

.tgwv-editor-body .tgwv-table-scroll {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin-bottom: var(--tgwv-content-space);
}

.tgwv-editor-body caption {
    caption-side: top;
    padding: 0 0 0.65em;
    font-weight: 600;
    text-align: left;
    color: var(--tgwv-content-color-muted);
}

.tgwv-editor-body th,
.tgwv-editor-body td {
    padding: 0.6em 0.75em;
    border: 1px solid var(--tgwv-content-border);
    vertical-align: top;
    text-align: left;
}

.tgwv-editor-body th {
    font-weight: 600;
    background: var(--tgwv-content-bg-soft);
}

.tgwv-editor-body thead th {
    border-bottom-width: 2px;
}

/* Text alignment (editor inline styles) */
.tgwv-editor-body [style*="text-align: center"] {
    text-align: center;
}

.tgwv-editor-body [style*="text-align: right"] {
    text-align: right;
}

.tgwv-editor-body [style*="text-align: justify"] {
    text-align: justify;
}

/* Responsive */
@media (max-width: 991.98px) {
    .tgwv-editor-body {
        --tgwv-content-space: 1.1rem;
    }
}

@media (max-width: 767.98px) {
    .tgwv-editor-body {
        font-size: 14px;
        --tgwv-content-space: 1rem;
    }

    .tgwv-editor-body table {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .tgwv-editor-body th,
    .tgwv-editor-body td {
        padding: 0.5em 0.6em;
    }

    .tgwv-editor-body blockquote {
        padding: 0.75em 0.9em;
    }
}

@media (max-width: 575.98px) {
    .tgwv-editor-body ul,
    .tgwv-editor-body ol {
        padding-left: 1.25em;
    }

    .tgwv-editor-body iframe {
        min-height: 160px;
    }
}

@media print {
    .tgwv-editor-body {
        color: #000;
    }

    .tgwv-editor-body a {
        color: #000;
        text-decoration: underline;
    }

    .tgwv-editor-body img {
        max-width: 100% !important;
        page-break-inside: avoid;
    }
}
