/* ============================================================================
   Articles — List (Grid) + Detail
   Follows tokens.css / base.css / layout.css / components.css conventions
   ========================================================================= */

/* --- Page shell -------------------------------------------------------- */
.articles-page {
    min-height: calc(100vh - var(--nav-h));
    padding: 32px 0 56px;
    background:
        radial-gradient(820px 420px at 18% 0%, rgba(252, 213, 53, 0.06) 0%, transparent 60%),
        radial-gradient(700px 400px at 92% 8%, rgba(14, 203, 129, 0.04) 0%, transparent 60%),
        var(--bg-body);
}

.articles-head {
    margin-bottom: 22px;
}

.articles-head h1 {
    font-size: clamp(26px, 3.2vw, 34px);
    font-weight: 800;
    letter-spacing: -0.02em;
}

.articles-head p {
    margin-top: 8px;
    max-width: 64ch;
    font-size: 14px;
    line-height: 1.65;
    color: var(--text-secondary);
}

/* --- Toolbar ----------------------------------------------------------- */
.articles-toolbar {
    display: flex;
    flex-direction: column;
    gap: 14px;
    margin-bottom: 20px;
    padding: 16px;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
}

.toolbar-row {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    align-items: center;
}

.toolbar-row--filters {
    gap: 10px;
}

/* Search */
.search-wrap {
    position: relative;
    flex: 1;
    min-width: 240px;
}

.search-wrap .search-icon {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-secondary);
    pointer-events: none;
    display: grid;
    place-items: center;
}

.search-wrap input {
    width: 100%;
    height: 42px;
    padding: 0 14px 0 38px;
    border-radius: var(--radius);
    border: 1px solid var(--border-strong);
    background: var(--bg-surface-2);
    color: var(--text-primary);
    font-size: 14px;
    transition: border-color 0.15s var(--ease), background 0.15s var(--ease);
}

.search-wrap input::placeholder {
    color: var(--text-disabled);
}

.search-wrap input:focus {
    outline: none;
    border-color: var(--brand);
    background: var(--bg-surface);
}

/* Select + date inputs */
.field-inline {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.field-inline label {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    letter-spacing: 0.02em;
}

.articles-toolbar select,
.articles-toolbar input[type="date"] {
    height: 40px;
    padding: 0 12px;
    border-radius: var(--radius);
    border: 1px solid var(--border-strong);
    background: var(--bg-surface-2);
    color: var(--text-primary);
    font-size: 13px;
    min-width: 160px;
}

.articles-toolbar select:focus,
.articles-toolbar input[type="date"]:focus {
    outline: none;
    border-color: var(--brand);
    background: var(--bg-surface);
}

.articles-toolbar input[type="date"]::-webkit-calendar-picker-indicator {
    filter: invert(0.6);
}

:root[data-theme="light"] .articles-toolbar input[type="date"]::-webkit-calendar-picker-indicator {
    filter: none;
}

.date-group {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    align-items: flex-end;
}

.date-group[hidden] {
    display: none !important;
}

/* Buttons in toolbar */
.toolbar-actions {
    display: flex;
    gap: 8px;
    margin-left: auto;
    flex-wrap: wrap;
}

.btn-sm {
    height: 40px;
    padding: 0 16px;
    font-size: 13px;
}

.btn-outline {
    background: transparent;
    border: 1px solid var(--border-strong);
    color: var(--text-primary);
}

.btn-outline:hover {
    background: var(--bg-surface-2);
    border-color: var(--border-strong);
}

/* --- Grid -------------------------------------------------------------- */
.articles-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 18px;
}

@media (max-width: 980px) {
    .articles-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 560px) {
    .articles-grid {
        grid-template-columns: 1fr;
    }
}

/* Card */
.article-card {
    display: flex;
    flex-direction: column;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
    transition: transform 0.18s var(--ease), border-color 0.18s var(--ease), box-shadow 0.18s var(--ease);
    cursor: pointer;
    text-decoration: none;
    color: inherit;
}

.article-card:hover,
.article-card:focus-visible {
    transform: translateY(-3px);
    border-color: var(--border-strong);
    box-shadow: var(--shadow);
    outline: none;
}

.article-card:focus-visible {
    border-color: var(--brand);
}

.card-media {
    position: relative;
    aspect-ratio: 16 / 9.2;
    background: var(--bg-surface-2);
    overflow: hidden;
    flex-shrink: 0;
}

.card-media img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    transition: transform 0.35s var(--ease);
}

.article-card:hover .card-media img {
    transform: scale(1.03);
}

.card-media .media-placeholder {
    width: 100%;
    height: 100%;
    display: grid;
    place-items: center;
    color: var(--text-disabled);
    background:
        radial-gradient(420px 220px at 50% 30%, var(--brand-soft), transparent 60%),
        var(--bg-elevated);
}

.card-media .media-placeholder svg {
    opacity: 0.9;
}

.card-body {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 14px 16px 16px;
    flex: 1;
}

.card-title {
    font-size: 15px;
    font-weight: 700;
    line-height: 1.45;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.card-desc {
    font-size: 13px;
    line-height: 1.6;
    color: var(--text-secondary);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    min-height: 42px;
}

.card-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-items: center;
}

.tag-pill {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 8px;
    border-radius: var(--radius-pill);
    background: var(--bg-surface-2);
    border: 1px solid var(--border);
    font-size: 11px;
    font-weight: 600;
    color: var(--text-secondary);
    white-space: nowrap;
}

.tag-pill em {
    font-style: normal;
    font-weight: 700;
    color: var(--text-primary);
}

.tag-more {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-disabled);
}

.card-date {
    margin-top: auto;
    padding-top: 8px;
    font-size: 12px;
    color: var(--text-disabled);
    display: flex;
    align-items: center;
    gap: 6px;
}

/* --- Skeleton ---------------------------------------------------------- */
.skeleton-card {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
}

.skeleton-media {
    aspect-ratio: 16 / 9.2;
    background: var(--bg-surface-2);
    position: relative;
    overflow: hidden;
}

.skeleton-line {
    height: 12px;
    border-radius: var(--radius-pill);
    background: var(--bg-surface-2);
    position: relative;
    overflow: hidden;
}

.skeleton-line::after,
.skeleton-media::after {
    content: '';
    position: absolute;
    inset: 0;
    transform: translateX(-100%);
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.06), transparent);
    animation: shimmer 1.4s infinite;
}

:root[data-theme="light"] .skeleton-line::after,
:root[data-theme="light"] .skeleton-media::after {
    background: linear-gradient(90deg, transparent, rgba(0, 0, 0, 0.05), transparent);
}

/* --- States ------------------------------------------------------------ */
.state-box {
    grid-column: 1 / -1;
    display: grid;
    place-items: center;
    text-align: center;
    padding: 56px 20px;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
}

.state-box h3 {
    font-size: 16px;
    margin: 12px 0 6px;
}

.state-box p {
    font-size: 13px;
    color: var(--text-secondary);
    max-width: 48ch;
    line-height: 1.6;
}

.state-box .btn {
    margin-top: 16px;
}

.state-icon {
    width: 48px;
    height: 48px;
    display: grid;
    place-items: center;
    border-radius: 50%;
    background: var(--bg-surface-2);
    border: 1px solid var(--border);
    color: var(--text-secondary);
}

.state-box--error .state-icon {
    color: var(--down);
    background: var(--down-bg);
    border-color: rgba(246, 70, 93, 0.22);
}

/* --- Pagination -------------------------------------------------------- */
.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    margin-top: 24px;
    flex-wrap: wrap;
}

.pagination button,
.pagination .page-num {
    min-width: 38px;
    height: 38px;
    display: inline-grid;
    place-items: center;
    padding: 0 10px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--bg-surface);
    color: var(--text-primary);
    font-size: 13px;
    font-weight: 600;
    transition: background 0.15s var(--ease), border-color 0.15s var(--ease), color 0.15s var(--ease);
}

.pagination button:hover:not(:disabled),
.pagination .page-num:hover:not([aria-current="true"]) {
    background: var(--bg-surface-2);
    border-color: var(--border-strong);
}

.pagination button:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.pagination .page-num[aria-current="true"] {
    background: var(--brand);
    border-color: var(--brand);
    color: var(--brand-text);
}

.pagination .page-ellipsis {
    min-width: 20px;
    text-align: center;
    color: var(--text-disabled);
    font-weight: 600;
}

/* Loading overlay for filtering/paging */
.articles-grid[data-loading="true"] {
    opacity: 0.55;
    pointer-events: none;
}

/* ============================================================================
   News section — below articles (§news_section_in_articles_screen.plan)
   List rows (thumb left, text right), single column, dividers between rows.
   ========================================================================= */
.news-section {
    margin-top: 40px;
    padding-top: 28px;
    border-top: 1px solid var(--border);
}

.news-head {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 8px;
}

.news-head-text {
    min-width: 0;
}

.news-title {
    font-size: clamp(20px, 2.4vw, 24px);
    font-weight: 800;
    letter-spacing: -0.02em;
}

.news-sub {
    margin-top: 6px;
    font-size: 13px;
    color: var(--text-secondary);
}

.news-head-link {
    flex-shrink: 0;
    font-weight: 600;
}

@media (max-width: 639px) {
    .news-head-link {
        display: none;
    }
}

/* List: vertical stack of horizontal rows */
.news-list {
    display: flex;
    flex-direction: column;
}

.news-item {
    border-bottom: 1px solid var(--border);
}

.news-item:last-child {
    border-bottom: none;
}

.news-link {
    display: flex;
    gap: 16px;
    padding: 14px 8px;
    border-radius: var(--radius);
    text-decoration: none;
    color: inherit;
}

.news-link:hover {
    background: var(--bg-surface);
}

.news-link:focus-visible {
    outline: 2px solid var(--brand);
    outline-offset: 2px;
}

.news-thumb {
    flex: 0 0 200px;
    aspect-ratio: 16 / 10;
    border-radius: var(--radius);
    overflow: hidden;
    background: var(--bg-surface-2);
    align-self: center;
}

.news-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    transition: transform 0.3s var(--ease);
}

.news-item:hover .news-thumb img {
    transform: scale(1.04);
}

.news-body {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 2px 0;
}

.news-item-title {
    font-size: 16px;
    font-weight: 700;
    line-height: 1.45;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.news-link:hover .news-item-title {
    color: var(--brand-hover);
}

.news-item-desc {
    font-size: 13px;
    line-height: 1.6;
    color: var(--text-secondary);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    min-height: 42px;
}

.news-item-desc--empty {
    opacity: 0.6;
}

.news-item-meta {
    margin-top: 8px;
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--text-disabled);
}

/* Footer: count left, see-more right */
.news-foot {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-top: 12px;
    padding: 4px 2px 0;
}

.news-count {
    font-size: 12px;
    color: var(--text-disabled);
}

.news-foot-link {
    font-weight: 600;
}

.news-head-link[hidden],
.news-foot-link[hidden] {
    display: none !important;
}

/* Error banner: independent from articles states */
.news-error {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-top: 12px;
    padding: 12px 14px;
    background: var(--down-bg);
    border: 1px solid rgba(246, 70, 93, 0.22);
    border-radius: var(--radius);
    font-size: 13px;
    color: var(--text-primary);
}

.news-error[hidden] {
    display: none !important;
}

.news-error span {
    flex: 1;
    min-width: 0;
}

/* Skeleton rows: thumb block + lines, reuse shimmer */
.news-skeleton {
    display: flex;
    gap: 16px;
    padding: 14px 8px;
    border-bottom: 1px solid var(--border);
}

.news-skeleton-thumb {
    flex: 0 0 200px;
    aspect-ratio: 16 / 10;
    border-radius: var(--radius);
    background: var(--bg-surface-2);
    position: relative;
    overflow: hidden;
}

.news-skeleton-lines {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 2px 0;
}

.news-skeleton-thumb::after,
.news-skeleton-lines .skeleton-line::after {
    content: '';
    position: absolute;
    inset: 0;
    transform: translateX(-100%);
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.06), transparent);
    animation: shimmer 1.4s infinite;
}

:root[data-theme="light"] .news-skeleton-thumb::after,
:root[data-theme="light"] .news-skeleton-lines .skeleton-line::after {
    background: linear-gradient(90deg, transparent, rgba(0, 0, 0, 0.05), transparent);
}

@media (max-width: 980px) {
    .news-thumb {
        flex-basis: 160px;
    }

    .news-skeleton-thumb {
        flex-basis: 160px;
    }
}

@media (max-width: 639px) {
    .news-thumb {
        flex-basis: 112px;
    }

    .news-skeleton-thumb {
        flex-basis: 112px;
    }

    .news-item-title {
        font-size: 14px;
    }

    .news-link {
        gap: 12px;
        padding: 12px 4px;
    }

    .news-skeleton {
        gap: 12px;
        padding: 12px 4px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .news-thumb img {
        transition: none;
    }

    .news-skeleton-thumb::after,
    .news-skeleton-lines .skeleton-line::after {
        animation: none;
    }
}

/* ============================================================================
   Detail
   ========================================================================= */
.article-detail-page {
    min-height: calc(100vh - var(--nav-h));
    padding: 24px 0 64px;
    background: var(--bg-body);
}

.article-detail-page .container {
    max-width: 100%;
    padding-left: 16px;
    padding-right: 16px;
}

.detail-shell {
    width: 100%;
    max-width: 50vw;
    margin: 0 auto;
}

.back-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 18px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    padding: 8px 10px;
    border-radius: var(--radius);
    border: 1px solid transparent;
    transition: color 0.15s var(--ease), background 0.15s var(--ease), border-color 0.15s var(--ease);
}

.back-link:hover {
    color: var(--text-primary);
    background: var(--bg-surface);
    border-color: var(--border);
}

.detail-card {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
}

.detail-head {
    padding: 24px 20px 0;
}

.detail-title {
    font-size: clamp(22px, 3vw, 30px);
    font-weight: 800;
    line-height: 1.28;
    letter-spacing: -0.02em;
}

.detail-subtitle {
    margin-top: 8px;
    font-size: 14px;
    line-height: 1.6;
    color: var(--text-secondary);
    font-weight: 400;
}

.detail-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 10px 16px;
    margin-top: 12px;
    font-size: 12.5px;
    color: var(--text-secondary);
}

.detail-meta span {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.detail-media {
    margin-top: 20px;
    border-radius: var(--radius);
    overflow: hidden;
    background: var(--bg-surface-2);
}

.detail-media img {
    width: 100%;
    height: auto;
    max-height: 520px;
    object-fit: cover;
    display: block;
}

.detail-body {
    padding: 20px 20px 28px;
}

.detail-desc {
    font-size: 15px;
    line-height: 1.75;
    color: var(--text-secondary);
    padding: 14px 16px;
    background: var(--bg-surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 20px;
}

.detail-content {
    font-size: 15px;
    line-height: 1.85;
    color: var(--text-primary);
    white-space: pre-wrap;
    word-break: break-word;
}

.detail-content--html {
    white-space: normal;
}

.detail-content--html p {
    margin: 0 0 14px;
}

.detail-content--html h2,
.detail-content--html h3 {
    margin: 22px 0 10px;
}

.detail-content--html a {
    color: var(--brand-hover);
    text-decoration: underline;
}

.detail-content--html ul,
.detail-content--html ol {
    margin: 0 0 14px 20px;
}

.detail-content--html blockquote {
    margin: 16px 0;
    padding: 12px 16px;
    border-left: 3px solid var(--brand);
    background: var(--bg-surface-2);
    border-radius: 0 var(--radius) var(--radius) 0;
    color: var(--text-secondary);
}

.detail-content--html pre {
    margin: 16px 0;
    padding: 14px;
    background: var(--bg-body);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow-x: auto;
    font-family: var(--font-mono);
    font-size: 13px;
}

.detail-tags--head {
    margin-top: 12px;
}

.detail-tags--head:empty {
    display: none;
}

.detail-tags--head .detail-tags-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.detail-tags--head .tag-pill {
    max-width: 240px;
    overflow: hidden;
    text-overflow: ellipsis;
}

.tag-pill--up {
    color: var(--up);
    border-color: rgba(14, 203, 129, 0.35);
    background: var(--up-bg);
}

.tag-pill--up em {
    color: var(--up);
}

.tag-pill--down {
    color: var(--down);
    border-color: rgba(246, 70, 93, 0.35);
    background: var(--down-bg);
}

.tag-pill--down em {
    color: var(--down);
}

.tag-pill--flat {
    color: var(--text-secondary);
}

/* --- Media chi tiet: anh hoac video YouTube ----------------------------- */
/* Facade (.yt-preview button) va player (.detail-video + iframe) deu 16:9,
   khong layout shift. Iframe chi duoc tao bang YT.Player, khong qua innerHTML. */
.detail-media--video .yt-preview,
.detail-media--video .detail-video,
.detail-media--video iframe {
    display: block;
    width: 100%;
    aspect-ratio: 16 / 9;
    border: 0;
}

.detail-media--video .yt-preview {
    position: relative;
    overflow: hidden;
    background: var(--bg-surface-2);
    padding: 0;
    border: 0;
    cursor: pointer;
    font: inherit;
    color: inherit;
    appearance: none;
    -webkit-appearance: none;
}

.detail-media--video .detail-video {
    background: #000;
    overflow: hidden;
}

.detail-media--video .detail-video iframe {
    aspect-ratio: auto;
    height: 100%;
}

.detail-media--video .yt-preview img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.detail-media--video .yt-preview:hover img {
    opacity: 0.85;
}

.detail-media--video .yt-play {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: rgba(230, 33, 23, 0.92);
    transition: transform 0.15s var(--ease), background 0.15s var(--ease);
}

.detail-media--video .yt-play::before {
    content: "";
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-38%, -50%);
    border-style: solid;
    border-width: 12px 0 12px 20px;
    border-color: transparent transparent transparent #fff;
}

.detail-media--video .yt-preview:hover .yt-play {
    transform: translate(-50%, -50%) scale(1.08);
    background: #e62117;
}

.detail-media--video .yt-link {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    width: 100%;
    padding: 10px 14px;
    font-size: 13px;
    font-weight: 600;
    color: var(--brand-hover);
    background: var(--bg-surface-2);
    border-top: 1px solid var(--border);
    text-decoration: none;
    transition: background 0.15s var(--ease);
}

.detail-media--video .yt-link:hover {
    background: var(--bg-surface);
}

.detail-media--video .yt-link:first-child {
    color: var(--text-secondary);
}

.detail-skeleton {
    padding: 24px 20px;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.detail-error,
.detail-notfound {
    width: 100%;
    max-width: 50vw;
    margin: 0 auto;
    text-align: center;
    padding: 56px 20px;
}

.detail-error h2,
.detail-notfound h2 {
    font-size: 22px;
    margin: 12px 0 8px;
}

.detail-error p,
.detail-notfound p {
    color: var(--text-secondary);
    font-size: 14px;
    line-height: 1.6;
}

@media (max-width: 768px) {

    .detail-shell,
    .detail-error,
    .detail-notfound {
        max-width: 100%;
    }
}

@media (max-width: 640px) {
    .articles-toolbar {
        padding: 14px;
    }

    .article-detail-page .container {
        padding-left: 12px;
        padding-right: 12px;
    }

    .detail-head,
    .detail-body {
        padding-left: 14px;
        padding-right: 14px;
    }

    .detail-head {
        padding-top: 18px;
    }

    .detail-skeleton {
        padding-left: 14px;
        padding-right: 14px;
    }
}