/**
 * AJKAI Hub - Production CSS & Standalone Fallback Stylesheet
 */

:root {
    --brand-primary: #4f46e5;
    --brand-primary-hover: #4338ca;
    --brand-dark: #0f172a;
    --brand-light: #f8fafc;
}

/* Typography & Thai Font Smoothing */
body, input, textarea, select, button {
    font-family: 'Sarabun', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Noto Sans Thai', Thonburi, Tahoma, sans-serif;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}

h1, h2, h3, h4, h5, h6, .font-heading {
    font-family: 'Prompt', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Noto Sans Thai', Thonburi, Tahoma, sans-serif;
    line-height: 1.35;
    letter-spacing: -0.015em;
}

p, span, a, label, li, td, th {
    line-height: 1.65;
}

/* Selection Color */
::selection {
    background-color: #4f46e5;
    color: #ffffff;
}

/* Smooth Scrolling */
html {
    scroll-behavior: smooth;
}

/* Custom Scrollbars */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: rgba(148, 163, 184, 0.4);
    border-radius: 9999px;
}
::-webkit-scrollbar-thumb:hover {
    background: rgba(100, 116, 139, 0.7);
}

/* Base Print Styles */
@media print {
    header, footer, nav, aside, .no-print {
        display: none !important;
    }
    body {
        background: #ffffff !important;
        color: #000000 !important;
    }
}

/* 🖼️ WordPress Gallery & Image Grid Styling */
.wp-block-gallery,
.gallery,
.blocks-gallery-grid,
[data-gallery-grid="true"] {
    display: grid !important;
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 0.75rem !important;
    margin: 1.75rem 0 !important;
    padding: 0 !important;
    list-style: none !important;
    width: 100% !important;
}

@media (min-width: 640px) {
    .wp-block-gallery,
    .gallery,
    .blocks-gallery-grid,
    [data-gallery-grid="true"] {
        grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
        gap: 1rem !important;
    }
}

@media (min-width: 1024px) {
    .wp-block-gallery,
    .gallery,
    .blocks-gallery-grid,
    [data-gallery-grid="true"] {
        grid-template-columns: repeat(4, minmax(0, 1fr)) !important;
        gap: 1.25rem !important;
    }
}

.wp-block-gallery.columns-1, .gallery-columns-1 { grid-template-columns: 1fr !important; }
.wp-block-gallery.columns-2, .gallery-columns-2 { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; }
.wp-block-gallery.columns-3, .gallery-columns-3 { grid-template-columns: repeat(3, minmax(0, 1fr)) !important; }
.wp-block-gallery.columns-4, .gallery-columns-4 { grid-template-columns: repeat(4, minmax(0, 1fr)) !important; }

.wp-block-gallery .wp-block-image,
.gallery .gallery-item,
.blocks-gallery-item {
    margin: 0 !important;
    position: relative;
    border-radius: 1rem;
    overflow: hidden;
    background: rgba(15, 23, 42, 0.04);
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -2px rgba(0, 0, 0, 0.05);
    aspect-ratio: 4 / 3;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.wp-block-gallery .wp-block-image:hover,
.gallery .gallery-item:hover,
.blocks-gallery-item:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -4px rgba(0, 0, 0, 0.1);
}

.wp-block-gallery .wp-block-image img,
.gallery .gallery-item img,
.blocks-gallery-item img,
[data-gallery-grid="true"] img {
    width: 100% !important;
    height: 100% !important;
    object-fit: cover !important;
    margin: 0 !important;
    border-radius: 1rem !important;
    cursor: zoom-in;
    transition: transform 0.4s cubic-bezier(0.16, 1, 0.3, 1), filter 0.3s ease;
}

.wp-block-gallery .wp-block-image:hover img,
.gallery .gallery-item:hover img,
.blocks-gallery-item:hover img,
[data-gallery-grid="true"] img:hover {
    transform: scale(1.06);
    filter: brightness(1.05);
}

/* Image zoom cursor utility */
.cursor-zoom-in {
    cursor: zoom-in !important;
}
.cursor-zoom-out {
    cursor: zoom-out !important;
}

/* 🔗 Post & Page Content Link Styling with Interactive Hover Effects */
#articleBody a,
#pageBody a,
.prose a {
    color: #4f46e5;
    font-weight: 600;
    text-decoration: underline;
    text-decoration-color: rgba(99, 102, 241, 0.4);
    text-decoration-thickness: 1.5px;
    text-underline-offset: 4px;
    border-radius: 0.375rem;
    padding: 0.05rem 0.25rem;
    margin: -0.05rem -0.25rem;
    transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
    display: inline;
}

/* Dark mode link colors */
.dark #articleBody a,
.dark #pageBody a,
.dark .prose a {
    color: #818cf8;
    text-decoration-color: rgba(129, 140, 248, 0.45);
}

/* 🌟 Hover state for content links */
#articleBody a:hover,
#pageBody a:hover,
.prose a:hover {
    color: #3730a3;
    background-color: rgba(99, 102, 241, 0.1);
    text-decoration-color: #4f46e5;
    text-decoration-thickness: 2.5px;
    text-underline-offset: 5px;
    box-shadow: 0 1px 4px rgba(79, 70, 229, 0.15);
}

.dark #articleBody a:hover,
.dark #pageBody a:hover,
.dark .prose a:hover {
    color: #a5b4fc;
    background-color: rgba(99, 102, 241, 0.22);
    text-decoration-color: #818cf8;
    box-shadow: 0 1px 6px rgba(129, 140, 248, 0.25);
}

/* Active / Click state */
#articleBody a:active,
#pageBody a:active,
.prose a:active {
    transform: scale(0.98);
}

/* 🚫 Exclude images inside links from getting text-underline or background highlights */
#articleBody a:has(img),
#pageBody a:has(img),
.prose a:has(img),
#articleBody a.image-link,
#pageBody a.image-link {
    background: transparent !important;
    text-decoration: none !important;
    padding: 0 !important;
    margin: 0 !important;
    box-shadow: none !important;
    border-radius: 0 !important;
}

#articleBody a:has(img):hover,
#pageBody a:has(img):hover,
.prose a:has(img):hover {
    background: transparent !important;
    box-shadow: none !important;
}

#articleBody a > img,
#pageBody a > img,
.prose a > img {
    text-decoration: none !important;
}

/* 🔘 WordPress Block Button Link Styles (.wp-block-button__link) */
#articleBody .wp-block-button__link,
#pageBody .wp-block-button__link,
.prose .wp-block-button__link {
    display: inline-flex !important;
    align-items: center !important;
    gap: 0.5rem !important;
    padding: 0.75rem 1.5rem !important;
    margin: 0.5rem 0 !important;
    border-radius: 1rem !important;
    background: linear-gradient(135deg, #4f46e5, #6366f1) !important;
    color: #ffffff !important;
    font-weight: 700 !important;
    text-decoration: none !important;
    box-shadow: 0 4px 14px rgba(79, 70, 229, 0.3) !important;
    transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1) !important;
}

#articleBody .wp-block-button__link:hover,
#pageBody .wp-block-button__link:hover,
.prose .wp-block-button__link:hover {
    background: linear-gradient(135deg, #4338ca, #4f46e5) !important;
    color: #ffffff !important;
    transform: translateY(-2px) !important;
    box-shadow: 0 8px 20px rgba(79, 70, 229, 0.4) !important;
}

/* Headings link styling */
#articleBody h1 a, #articleBody h2 a, #articleBody h3 a, #articleBody h4 a,
#pageBody h1 a, #pageBody h2 a, #pageBody h3 a, #pageBody h4 a {
    color: inherit;
    text-decoration: none;
    padding: 0;
    margin: 0;
    background: transparent;
}
#articleBody h1 a:hover, #articleBody h2 a:hover, #articleBody h3 a:hover, #articleBody h4 a:hover,
#pageBody h1 a:hover, #pageBody h2 a:hover, #pageBody h3 a:hover, #pageBody h4 a:hover {
    color: #4f46e5;
    background: transparent;
    text-decoration: underline;
}
.dark #articleBody h1 a:hover, .dark #articleBody h2 a:hover, .dark #articleBody h3 a:hover, .dark #articleBody h4 a:hover,
.dark #pageBody h1 a:hover, .dark #pageBody h2 a:hover, .dark #pageBody h3 a:hover, .dark #pageBody h4 a:hover {
    color: #818cf8;
}



/* ===== UX / accessibility improvements ===== */

/* Visible keyboard focus (mouse users are not affected) */
:focus-visible {
    outline: 2px solid #6366f1;
    outline-offset: 2px;
}
input:focus-visible, textarea:focus-visible, select:focus-visible {
    outline-offset: 0;
}

/* Anchors must not hide under the sticky header */
html {
    scroll-padding-top: 5.5rem;
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

/* Respect "reduce motion" system setting */
@media (prefers-reduced-motion: reduce) {
    html { scroll-behavior: auto !important; }
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Comfortable touch targets on phones */
@media (pointer: coarse) {
    button, [type="button"], [type="submit"], select {
        min-height: 2.5rem;
    }
}

/* Disabled / loading buttons */
button[aria-disabled="true"], button:disabled {
    cursor: not-allowed;
}

/* Never let media overflow the layout on small screens */
img, video, iframe, canvas { max-width: 100%; }
img { height: auto; }
.prose iframe, article iframe { width: 100%; aspect-ratio: 16 / 9; height: auto; }

/* Long Thai words / URLs should wrap instead of breaking the page */
.prose, article { overflow-wrap: anywhere; }

/* Print: show where a link points and keep content readable */
@media print {
    a[href^="http"]:not(.no-print-url)::after {
        content: " (" attr(href) ")";
        font-size: 0.8em;
        word-break: break-all;
    }
    img { max-width: 100% !important; page-break-inside: avoid; }
    h1, h2, h3 { page-break-after: avoid; }
}
