/* Custom CSS for Animal News Platform */

/* ============================================
   ACCESSIBILITY IMPROVEMENTS
   ============================================ */

/* Skip to main content link */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
}

.focus\:not-sr-only:focus {
    position: static;
    width: auto;
    height: auto;
    padding: 1rem;
    margin: 0;
    overflow: visible;
    clip: auto;
    white-space: normal;
}

/* Enhanced focus indicators */
a:focus,
button:focus,
input:focus,
textarea:focus,
select:focus {
    outline: 2px solid #059669;
    outline-offset: 2px;
    box-shadow: 0 0 0 3px rgba(5, 150, 105, 0.1);
}

/* Focus visible for keyboard navigation only */
a:focus:not(:focus-visible),
button:focus:not(:focus-visible),
input:focus:not(:focus-visible) {
    outline: none;
    box-shadow: none;
}

/* Reduced motion for users who prefer it */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* ============================================
   DARK MODE VARIABLES & STYLES
   ============================================ */

:root {
    --bg-primary: #f9fafb;
    --bg-secondary: #ffffff;
    --bg-tertiary: #f3f4f6;
    --text-primary: #111827;
    --text-secondary: #6b7280;
    --border-color: #e5e7eb;
    --card-bg: #ffffff;
    --header-bg: #ffffff;
    --footer-bg: #1f2937;
}

[data-theme="dark"] {
    --bg-primary: #0f172a;
    --bg-secondary: #1e293b;
    --bg-tertiary: #334155;
    --text-primary: #f1f5f9;
    --text-secondary: #cbd5e1;
    --border-color: #334155;
    --card-bg: #1e293b;
    --header-bg: #1e293b;
    --footer-bg: #020617;
}

[data-theme="dark"] body {
    background-color: var(--bg-primary);
    color: var(--text-primary);
}

[data-theme="dark"] .bg-white {
    background-color: var(--bg-secondary) !important;
}

[data-theme="dark"] .bg-gray-50 {
    background-color: var(--bg-primary) !important;
}

[data-theme="dark"] .bg-gray-100 {
    background-color: var(--bg-tertiary) !important;
}

[data-theme="dark"] .text-gray-800,
[data-theme="dark"] .text-gray-900 {
    color: var(--text-primary) !important;
}

[data-theme="dark"] .text-gray-600,
[data-theme="dark"] .text-gray-700 {
    color: var(--text-secondary) !important;
}

[data-theme="dark"] .border-gray-200,
[data-theme="dark"] .border-gray-300 {
    border-color: var(--border-color) !important;
}

[data-theme="dark"] .shadow-md,
[data-theme="dark"] .shadow-lg {
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.4), 0 2px 4px -1px rgba(0, 0, 0, 0.3);
}

[data-theme="dark"] header {
    background-color: var(--header-bg);
    border-bottom: 1px solid var(--border-color);
}

[data-theme="dark"] footer {
    background-color: var(--footer-bg);
}

/* ============================================
   BASE STYLES
   ============================================ */

/* Typography */
body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

/* Khmer Font Support */
@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+Khmer:wght@400;700&display=swap');

body {
    font-family: 'Noto Sans Khmer', 'Segoe UI', sans-serif;
    overflow-x: hidden; /* Prevent horizontal scroll */
}

/* Responsive Container */
.container {
    width: 100%;
    max-width: 100%;
}

@media (min-width: 640px) {
    .container {
        max-width: 640px;
    }
}

@media (min-width: 768px) {
    .container {
        max-width: 768px;
    }
}

@media (min-width: 1024px) {
    .container {
        max-width: 1024px;
    }
}

@media (min-width: 1280px) {
    .container {
        max-width: 1280px;
    }
}

@media (min-width: 1536px) {
    .container {
        max-width: 1536px;
    }
}

/* Line Clamp Utilities */
.line-clamp-2 {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    word-break: break-word;
}

.line-clamp-3 {
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
    word-break: break-word;
}

/* Responsive Card Styles */
.card-responsive {
    width: 100%;
    height: auto;
}

@media (max-width: 640px) {
    .card-responsive .card-image {
        height: 10rem;
    }
    
    .card-responsive .card-title {
        font-size: 0.95rem;
    }
    
    .card-responsive .card-text {
        font-size: 0.85rem;
    }
}

/* Flexible Images in Cards */
.card img,
.article img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center;
}

/* Responsive Grid Gaps */
.gap-responsive {
    gap: 0.75rem;
}

@media (min-width: 640px) {
    .gap-responsive {
        gap: 1rem;
    }
}

@media (min-width: 768px) {
    .gap-responsive {
        gap: 1.5rem;
    }
}

@media (min-width: 1024px) {
    .gap-responsive {
        gap: 2rem;
    }
}

/* Smooth Transitions */
a, button {
    transition: all 0.3s ease;
}

/* Ensure clickable elements are properly sized */
a, button, input, select, textarea {
    -webkit-tap-highlight-color: rgba(0, 0, 0, 0.1);
}

/* Prevent text overflow */
.text-truncate {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Responsive padding helper */
.responsive-padding {
    padding: 1rem;
}

@media (min-width: 768px) {
    .responsive-padding {
        padding: 1.5rem;
    }
}

@media (min-width: 1024px) {
    .responsive-padding {
        padding: 2rem;
    }
}

/* Article Content Styling */
.prose img {
    border-radius: 8px;
    margin: 1.5rem auto;
    max-width: 100%;
    height: auto;
}

@media (max-width: 640px) {
    .prose img {
        margin: 1rem auto;
        border-radius: 4px;
    }
}

.prose h2 {
    margin-top: 2rem;
    margin-bottom: 1rem;
    color: #1f2937;
    font-weight: 700;
}

@media (max-width: 640px) {
    .prose h2 {
        margin-top: 1.5rem;
        margin-bottom: 0.75rem;
        font-size: 1.25rem;
    }
}

.prose h3 {
    margin-top: 1.5rem;
    margin-bottom: 0.75rem;
    color: #374151;
    font-weight: 600;
}

@media (max-width: 640px) {
    .prose h3 {
        margin-top: 1.25rem;
        margin-bottom: 0.5rem;
        font-size: 1.125rem;
    }
}

.prose p {
    margin-bottom: 1rem;
    line-height: 1.75;
}

@media (max-width: 640px) {
    .prose p {
        margin-bottom: 0.875rem;
        line-height: 1.65;
        font-size: 0.95rem;
    }
}

.prose ul, .prose ol {
    margin: 1rem 0;
    padding-left: 2rem;
}

@media (max-width: 640px) {
    .prose ul, .prose ol {
        margin: 0.75rem 0;
        padding-left: 1.5rem;
    }
}

.prose li {
    margin: 0.5rem 0;
}

@media (max-width: 640px) {
    .prose li {
        margin: 0.375rem 0;
        font-size: 0.95rem;
    }
}

.prose a {
    color: #059669;
    text-decoration: underline;
    word-break: break-word;
}

.prose a:hover {
    color: #047857;
}

/* Responsive iframe/video embeds */
.prose iframe,
.prose video {
    max-width: 100%;
    height: auto;
    aspect-ratio: 16/9;
}

@media (max-width: 640px) {
    .prose iframe,
    .prose video {
        width: 100%;
        height: auto;
    }
}

/* Custom Scrollbar */
::-webkit-scrollbar {
    width: 10px;
}

::-webkit-scrollbar-track {
    background: #f1f1f1;
}

::-webkit-scrollbar-thumb {
    background: #059669;
    border-radius: 5px;
}

::-webkit-scrollbar-thumb:hover {
    background: #047857;
}

/* Loading Animation */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.fade-in {
    animation: fadeIn 0.5s ease-in;
}

/* Responsive Images */
img {
    max-width: 100%;
    height: auto;
}

/* Print Styles */
@media print {
    header, footer, .sidebar, .ads {
        display: none !important;
    }
    
    .article-content {
        width: 100% !important;
        margin: 0 !important;
    }
}

/* Dropdown Menu Styles */
.nav-dropdown {
    position: relative;
    display: inline-block;
}

/* Desktop dropdown behavior */
@media (min-width: 1024px) {
    .nav-dropdown:hover .dropdown-content,
    .dropdown-content:hover {
        opacity: 1 !important;
        visibility: visible !important;
        pointer-events: auto;
    }
}

.dropdown-content {
    position: absolute;
    left: 0;
    top: 100%;
    min-width: 200px;
    background-color: #0d9488;
    box-shadow: 0 8px 16px rgba(0,0,0,0.2);
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 0.2s ease, visibility 0.2s ease;
    margin-top: 0;
    padding-top: 0.25rem;
}

.dropdown-content::before {
    content: '';
    position: absolute;
    top: -0.25rem;
    left: 0;
    right: 0;
    height: 0.25rem;
    background: transparent;
}

.dropdown-content a {
    color: white;
    text-decoration: none;
    display: block;
    transition: background-color 0.2s ease;
    padding: 0.75rem 1rem;
}

.dropdown-content a:hover {
    background-color: #0f766e;
}

/* Mobile Menu Improvements */
@media (max-width: 1023px) {
    .dropdown-content {
        position: static;
        opacity: 1;
        visibility: visible;
        box-shadow: none;
        background-color: rgba(15, 118, 110, 0.5);
        margin-top: 0.5rem;
        border-radius: 0.5rem;
    }
    
    /* Mobile menu spacing */
    #mobile-menu {
        max-height: calc(100vh - 200px);
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    /* Improve touch targets */
    #mobile-menu a,
    #mobile-menu button {
        min-height: 48px;
        padding: 0.75rem 1rem;
        font-size: 1rem;
    }
}

/* ============================================
   RESPONSIVE DESIGN - MOBILE FIRST APPROACH
   ============================================ */

/* Base Mobile Styles (320px and up) */
* {
    box-sizing: border-box;
}

body {
    -webkit-text-size-adjust: 100%;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    overflow-x: hidden;
}

/* Prevent horizontal scroll on all elements */
html, body {
    max-width: 100%;
    overflow-x: hidden;
}

/* Container Responsiveness */
.container {
    width: 100%;
    max-width: 100%;
    margin-left: auto;
    margin-right: auto;
    padding-left: 1rem;
    padding-right: 1rem;
}

@media (max-width: 640px) {
    .container {
        padding-left: 0.75rem;
        padding-right: 0.75rem;
    }
}

/* Image Responsiveness */
img {
    max-width: 100%;
    height: auto;
    display: block;
}

/* Flexible embeds (videos, iframes) */
iframe,
embed,
object,
video {
    max-width: 100%;
    height: auto;
}

/* Flexible Grid System */
.grid {
    display: grid;
    gap: 1rem;
}

/* Touch Targets for Mobile */
button, 
a.btn,
input[type="submit"],
input[type="button"],
.mobile-touch-target {
    min-height: 44px;
    min-width: 44px;
}

/* Better tap highlighting */
a, button, input, select, textarea {
    -webkit-tap-highlight-color: rgba(13, 148, 136, 0.2);
}

/* Responsive Typography */
html {
    font-size: 16px;
}

h1 {
    font-size: 1.75rem;
    line-height: 1.2;
    word-wrap: break-word;
}

h2 {
    font-size: 1.5rem;
    line-height: 1.3;
    word-wrap: break-word;
}

h3 {
    font-size: 1.25rem;
    line-height: 1.4;
    word-wrap: break-word;
}

h4 {
    font-size: 1.125rem;
    line-height: 1.4;
}

p, li {
    font-size: 1rem;
    line-height: 1.6;
    word-wrap: break-word;
}

/* Responsive Tables */
@media (max-width: 640px) {
    table {
        display: block;
        overflow-x: auto;
        white-space: nowrap;
        -webkit-overflow-scrolling: touch;
    }
    
    thead {
        display: none;
    }
    
    tbody, tr, td {
        display: block;
    }
    
    tr {
        margin-bottom: 1rem;
        border: 1px solid #e5e7eb;
        border-radius: 0.5rem;
        padding: 0.5rem;
    }
    
    td {
        text-align: left;
        padding: 0.5rem;
        position: relative;
        padding-left: 50%;
    }
    
    td:before {
        content: attr(data-label);
        position: absolute;
        left: 0.5rem;
        font-weight: bold;
        text-transform: uppercase;
    }
}

/* Mobile Specific (up to 640px) */
@media (max-width: 640px) {
    /* Container padding */
    .container {
        padding-left: 0.75rem;
        padding-right: 0.75rem;
    }
    
    /* Article cards */
    .grid-cols-1 {
        grid-template-columns: 1fr;
    }
    
    /* Reduce spacing */
    .space-y-8 > * + * {
        margin-top: 1.5rem;
    }
    
    /* Typography adjustments */
    h1 {
        font-size: 1.5rem;
    }
    
    h2 {
        font-size: 1.25rem;
    }
    
    h3 {
        font-size: 1.125rem;
    }
    
    /* Header adjustments */
    header .text-xl {
        font-size: 1.125rem;
    }
    
    /* Button text */
    button, .btn {
        font-size: 0.875rem;
        padding: 0.5rem 1rem;
    }
    
    /* Hide non-essential elements */
    .hidden-mobile {
        display: none !important;
    }
    
    /* Stack social icons */
    .flex.space-x-3,
    .flex.space-x-4 {
        flex-wrap: wrap;
        gap: 0.5rem;
    }
    
    /* Sidebar full width */
    .lg\:col-span-1 {
        display: block;
        width: 100%;
    }
    
    /* Article images */
    .h-48 {
        height: 10rem;
    }
    
    /* Prose content */
    .prose {
        font-size: 0.95rem;
    }
    
    .prose img {
        margin: 1rem 0;
    }
    
    .prose h2 {
        font-size: 1.25rem;
        margin-top: 1.5rem;
    }
    
    .prose h3 {
        font-size: 1.125rem;
        margin-top: 1.25rem;
    }
    
    /* Forms */
    input[type="text"],
    input[type="email"],
    input[type="search"],
    textarea {
        font-size: 16px; /* Prevents zoom on iOS */
    }
}

/* Tablet Portrait (641px to 768px) */
@media (min-width: 641px) and (max-width: 768px) {
    .container {
        padding-left: 1rem;
        padding-right: 1rem;
    }
    
    h1 {
        font-size: 2rem;
    }
    
    h2 {
        font-size: 1.75rem;
    }
    
    /* Two column grid for tablets */
    .grid.md\:grid-cols-3 {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* Tablet Landscape (769px to 1023px) */
@media (min-width: 769px) and (max-width: 1023px) {
    .container {
        padding-left: 1.5rem;
        padding-right: 1.5rem;
    }
    
    h1 {
        font-size: 2.25rem;
    }
    
    h2 {
        font-size: 2rem;
    }
    
    /* Grid adjustments */
    .grid {
        gap: 1.5rem;
    }
}

/* Desktop (1024px and up) */
@media (min-width: 1024px) {
    .container {
        padding-left: 2rem;
        padding-right: 2rem;
    }
    
    h1 {
        font-size: 2.5rem;
    }
    
    h2 {
        font-size: 2.25rem;
    }
    
    h3 {
        font-size: 1.875rem;
    }
    
    .grid {
        gap: 2rem;
    }
}

/* Large Desktop (1280px and up) */
@media (min-width: 1280px) {
    .container {
        max-width: 1280px;
    }
}

/* Extra Large Desktop (1536px and up) */
@media (min-width: 1536px) {
    .container {
        max-width: 1536px;
    }
}

/* Landscape Orientation */
@media (orientation: landscape) and (max-height: 500px) {
    /* Reduce header height in landscape mode */
    header {
        padding-top: 0.5rem;
        padding-bottom: 0.5rem;
    }
    
    .py-8 {
        padding-top: 1rem;
        padding-bottom: 1rem;
    }
}

/* Print Styles */
@media print {
    header, footer, .sidebar, .ads, nav, .social-share {
        display: none !important;
    }
    
    .article-content {
        width: 100% !important;
        margin: 0 !important;
    }
    
    a {
        text-decoration: underline;
    }
    
    a[href]:after {
        content: " (" attr(href) ")";
    }
}

/* Accessibility - Reduced Motion */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* High Contrast Mode Support */
@media (prefers-contrast: high) {
    body {
        color: #000;
        background: #fff;
    }
    
    a {
        text-decoration: underline;
    }
}

/* Dark Mode Support */
@media (prefers-color-scheme: dark) {
    /* Add dark mode styles if needed in future */
}
