/* ==========================================================================
   Table of Contents (ToC)
   ========================================================================== */

.am-toc {
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 20px;
    margin: 32px 0;
    font-family: inherit;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.am-toc__header {
    font-size: 1.25rem;
    font-weight: 600;
    color: #1e293b;
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 1px solid #e2e8f0;
}

.am-toc__body ul {
    list-style: none;
    padding-left: 0;
    margin: 0;
}

.am-toc__body ul ul {
    padding-left: 1.5rem;
    margin-top: 6px;
}

.am-toc__body li {
    margin-bottom: 8px;
    line-height: 1.5;
}

.am-toc__body li:last-child {
    margin-bottom: 0;
}

.am-toc__body a {
    color: #3b82f6;
    text-decoration: none;
    transition: color 0.2s;
}

.am-toc__body a:hover {
    color: #1d4ed8;
    text-decoration: underline;
}

/* Sticky Variant Container */
.am-toc-container {
    display: flex;
    flex-direction: row-reverse;
    align-items: flex-start;
    gap: 32px;
}

.am-toc-content {
    flex: 1;
    min-width: 0;
}

/* Sticky Variant ToC */
.am-toc--sticky {
    position: -webkit-sticky;
    position: sticky;
    top: 24px;
    z-index: 10;
    width: 320px;
    flex-shrink: 0;
    max-height: calc(100vh - 48px);
    overflow-y: auto;
    margin: 0;
}

@media (max-width: 768px) {
    .am-toc-container {
        flex-direction: column;
        gap: 0;
    }

    .am-toc--sticky {
        width: 100%;
        position: static;
        max-height: none;
        overflow-y: visible;
        margin-bottom: 32px;
    }
}

/* ==========================================================================
   Internal Link Buttons
   ========================================================================== */

.am-links-container {
    display: flex;
    flex-direction: column;
    gap: 16px;
    margin-top: 32px;
    padding-top: 24px;
    border-top: 1px solid #e2e8f0;
}

/* Grid Columns */
.am-links-cols-2 {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
}

.am-links-cols-3 {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
}

@media (max-width: 992px) {
    .am-links-cols-3 {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 768px) {

    .am-links-cols-2,
    .am-links-cols-3 {
        grid-template-columns: 1fr;
    }
}

/* Preset: Button (should wrap) */
.am-links--button {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
}

.am-btn {
    display: inline-flex;
    align-items: center;
    font-size: 16px;
    font-weight: 500;
    text-decoration: none;
    color: #3b82f6;
    transition: all 0.2s ease-in-out;
}

/* Preset: Default Link */
.am-links--link .am-btn::before {
    content: "→";
    margin-right: 8px;
    transition: transform 0.2s ease;
}

.am-links--link .am-btn:hover {
    color: #1d4ed8;
    text-decoration: underline;
}

.am-links--link .am-btn:hover::before {
    transform: translateX(4px);
}

/* Preset: Bordered Card */
.am-links--bordered .am-btn {
    padding: 0;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    background: #ffffff;
    color: #1e293b;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
    overflow: hidden;
    display: flex;
    align-items: stretch;
    height: 100%;
}

/* Thumbnail Position: Right */
.am-links-thumb--right .am-btn {
    flex-direction: row-reverse;
}

/* Thumbnail Position: Top */
.am-links-thumb--top .am-btn {
    flex-direction: column;
}

/* Vertical Adjustment (Top position selected) */
.am-links-thumb--top .am-btn-thumb {
    width: 100%;
    height: 200px;
}

.am-btn-thumb {
    width: 160px;
    flex-shrink: 0;
    background: #f1f5f9;
    position: relative;
    overflow: hidden;
}

@media (max-width: 768px) {

    /* On mobile, always force vertical stack for cards */
    .am-links--bordered .am-btn {
        flex-direction: column !important;
    }

    .am-links--bordered .am-btn-thumb {
        width: 100% !important;
        height: 180px !important;
    }
}

body .am-btn-thumb img {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.am-btn-thumb--placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    color: #94a3b8;
    background: linear-gradient(135deg, #f8fafc 0%, #f1f5f9 100%);
}

.am-btn-thumb--placeholder .dashicons {
    font-size: 40px;
    width: 40px;
    height: 40px;
}

.am-btn-content {
    padding: 16px 20px;
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.am-btn-title {
    font-size: 16px;
    font-weight: 600;
    display: block;
}

.am-btn-excerpt {
    font-size: 14px;
    color: #64748b;
    margin-top: 6px;
    line-height: 1.4;
}

.am-links--bordered .am-btn:hover {
    border-color: #3b82f6;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    transform: translateY(-1px);
}

.am-links--bordered .am-btn:hover .am-btn-title {
    color: #3b82f6;
}

/* Preset: Solid Button */
.am-links--button .am-btn {
    padding: 10px 20px;
    background-color: #3b82f6;
    color: #ffffff;
    border-radius: 6px;
    font-size: 14px;
}

.am-links--button .am-btn:hover {
    background-color: #1d4ed8;
    transform: translateY(-1px);
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

/* ==========================================================================
   Related Posts (Phase 5)
   ========================================================================== */

.am-related {
    margin: 48px 0;
    padding-top: 32px;
    border-top: 1px solid #e2e8f0;
}

.am-related-title {
    font-size: 20px;
    font-weight: 700;
    color: #1e293b;
    margin-bottom: 24px;
}

.am-related-inner {
    display: grid;
    gap: 24px;
}

/* Style: Columns */
.am-related-cols-1 .am-related-inner {
    grid-template-columns: 1fr;
}

.am-related-cols-2 .am-related-inner {
    grid-template-columns: repeat(2, 1fr);
}

.am-related-cols-3 .am-related-inner {
    grid-template-columns: repeat(3, 1fr);
}

.am-related-cols-4 .am-related-inner {
    grid-template-columns: repeat(4, 1fr);
}

@media (max-width: 1024px) {
    .am-related-cols-4 .am-related-inner {
        grid-template-columns: repeat(2, 1fr);
    }

    .am-related-cols-3 .am-related-inner {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 640px) {
    .am-related-inner {
        grid-template-columns: 1fr !important;
    }
}

.am-related-item {
    display: flex;
    flex-direction: column;
    text-decoration: none;
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    overflow: hidden;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    height: 100%;
}

/* Style: Minimal */
.am-related--minimal .am-related-item {
    background: transparent;
    border: none;
    border-radius: 0;
    box-shadow: none;
    padding: 0;
}

.am-related--minimal .am-related-item:hover {
    transform: none;
    box-shadow: none;
}

.am-related--minimal .am-related-item:hover .am-related-item-title {
    color: #3b82f6;
    text-decoration: underline;
}

/* Thumbnail Position: Top (Default) */
.am-related-thumb-top .am-related-item {
    flex-direction: column;
}

/* Thumbnail Position: Left */
.am-related-thumb-left .am-related-item {
    flex-direction: row;
    align-items: stretch;
}

.am-related-thumb-left .am-related-thumb {
    width: 140px;
    height: auto;
    aspect-ratio: auto;
}

.am-related-thumb-left .am-related-content,
.am-related-thumb-right .am-related-content {
    display: flex;
    flex-direction: column;
    justify-content: center;
}

/* Thumbnail Position: Right */
.am-related-thumb-right .am-related-item {
    flex-direction: row-reverse;
    align-items: stretch;
}

.am-related-thumb-right .am-related-thumb {
    width: 140px;
    height: auto;
    aspect-ratio: auto;
}

@media (max-width: 640px) {

    .am-related-thumb-left .am-related-item,
    .am-related-thumb-right .am-related-item {
        flex-direction: column;
    }

    .am-related-thumb-left .am-related-thumb,
    .am-related-thumb-right .am-related-thumb {
        width: 100%;
        aspect-ratio: 16 / 9;
    }
}

.am-related-item:hover {
    border-color: #3b82f6;
    box-shadow: 0 10px 15px -3px rgba(59, 130, 246, 0.1);
    transform: translateY(-4px);
}

.am-related-thumb {
    width: 100%;
    background: #f1f5f9;
    overflow: hidden;
    flex-shrink: 0;
}

.am-related-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.am-related-img--placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    color: #94a3b8;
    height: 100%;
}

.am-related--list .am-related-thumb {
    width: 120px;
    height: 80px;
    aspect-ratio: auto;
}

.am-related-thumb .am-related-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.am-related-img--placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    color: #94a3b8;
}

.am-related-content {
    padding: 16px;
    flex: 1;
}

.am-related-item-title {
    font-size: 16px;
    font-weight: 600;
    color: #1e293b;
    line-height: 1.4;
    margin-bottom: 8px;
    transition: color 0.2s;
}

.am-related-excerpt {
    font-size: 14px;
    color: #64748b;
    line-height: 1.5;
    margin-bottom: 12px;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-overflow: ellipsis;
}

.am-related-item:hover .am-related-item-title {
    color: #3b82f6;
}

.am-related-meta {
    font-size: 13px;
    color: #64748b;
}

@media (max-width: 640px) {
    .am-related--list .am-related-item {
        flex-direction: column;
        align-items: flex-start;
    }

    .am-related--list .am-related-thumb {
        width: 100%;
        height: auto;
        aspect-ratio: 16 / 9;
    }
}