/**
 * TrueGadget Blog - Advanced Features CSS
 * Includes: Analytics, Search, Personalization, Admin, Performance Optimizations
 * Supports: Dark & Light Mode | Responsive Design | Touch-friendly
 */

/* ============================================================================
   ROOT CSS VARIABLES (Already defined in main CSS)
   ========================================================================== */
:root {
    --bg: #050505;
    --card: #0f0f11;
    --border: #1f1f22;
    --text: #ededed;
    --text-muted: #a1a1aa;
    --accent: #06b6d4;
    --accent2: #3b82f6;
    
    /* Additional variables for enhancements */
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --orange-red: #ff6b35;
    --transition: 0.3s ease;
}

.light {
    --bg: #f8fafc;
    --card: #ffffff;
    --border: #e2e8f0;
    --text: #1e293b;
    --text-muted: #64748b;
    --accent: #06b6d4;
    --accent2: #3b82f6;
    --success: #059669;
    --warning: #d97706;
    --danger: #dc2626;
    --orange-red: #ff5722;
}

/* ============================================================================
   SECTION 1: POST ANALYTICS BADGES
   ========================================================================== */

/* Base badge styling */
.badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.375rem 0.75rem;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.5px;
    transition: all var(--transition);
    white-space: nowrap;
    gap: 0.375rem;
}

/* Trending Badge - Orange-Red Gradient */
.badge-trending {
    background: linear-gradient(135deg, #ff6b35 0%, #f7931e 100%);
    color: #ffffff;
    box-shadow: 0 4px 12px rgba(255, 107, 53, 0.3);
    animation: pulse-trending 2s ease-in-out infinite;
}

.badge-trending::before {
    content: "🔥";
    font-size: 0.875rem;
}

@keyframes pulse-trending {
    0%, 100% {
        box-shadow: 0 4px 12px rgba(255, 107, 53, 0.3);
    }
    50% {
        box-shadow: 0 4px 20px rgba(255, 107, 53, 0.5);
    }
}

/* New Badge - Green with Sparkle */
.badge-new {
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
    color: #ffffff;
    box-shadow: 0 4px 12px rgba(16, 185, 129, 0.3);
}

.badge-new::before {
    content: "✨";
    font-size: 0.875rem;
    animation: twinkle 1.5s ease-in-out infinite;
}

@keyframes twinkle {
    0%, 100% {
        opacity: 1;
        transform: scale(1);
    }
    50% {
        opacity: 0.6;
        transform: scale(1.1);
    }
}

/* Draft Badge - Grey */
.badge-draft {
    background-color: var(--border);
    color: var(--text-muted);
}

.badge-draft::before {
    content: "📝";
}

/* Scheduled Badge - Yellow */
.badge-scheduled {
    background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
    color: #ffffff;
    box-shadow: 0 4px 12px rgba(245, 158, 11, 0.3);
}

.badge-scheduled::before {
    content: "⏰";
}

/* Reading Time */
.reading-time {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    font-size: 0.875rem;
    color: var(--text-muted);
    transition: color var(--transition);
}

.reading-time::before {
    content: "⏱️";
    font-size: 0.75rem;
}

.reading-time:hover {
    color: var(--accent);
}

/* Stats Bar */
.stats-bar {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.75rem 1rem;
    background-color: var(--card);
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    font-size: 0.875rem;
    flex-wrap: wrap;
}

.stats-bar-item {
    display: flex;
    align-items: center;
    gap: 0.375rem;
    color: var(--text);
    transition: color var(--transition);
}

.stats-bar-item:hover {
    color: var(--accent);
}

.stats-bar-item:not(:last-child)::after {
    content: "";
    width: 1px;
    height: 1rem;
    background-color: var(--border);
    margin-left: 1rem;
}

.stats-bar-value {
    font-weight: 600;
    color: var(--accent);
}

.stats-bar-label {
    color: var(--text-muted);
    font-size: 0.75rem;
}

/* ============================================================================
   SECTION 2: SEARCH OVERLAY & MODAL
   ========================================================================== */

/* Search Overlay - Full Screen Backdrop */
.search-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    opacity: 0;
    visibility: hidden;
    transition: opacity var(--transition), visibility var(--transition);
    z-index: 999;
}

.search-overlay.active {
    opacity: 1;
    visibility: visible;
}

.light .search-overlay {
    background-color: rgba(0, 0, 0, 0.3);
}

/* Search Modal - Centered Container */
.search-modal {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0.95);
    width: 90%;
    max-width: 600px;
    background-color: var(--card);
    border: 1px solid var(--border);
    border-radius: 1rem;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
    padding: 2rem;
    transition: transform var(--transition);
    opacity: 0;
    z-index: 1000;
}

.search-overlay.active .search-modal {
    transform: translate(-50%, -50%) scale(1);
    opacity: 1;
}

/* Search Input Container */
.search-input-wrapper {
    position: relative;
    margin-bottom: 1.5rem;
}

.search-input {
    width: 100%;
    padding: 1rem 1rem 1rem 2.75rem;
    font-size: 1.125rem;
    background-color: var(--bg);
    border: 2px solid var(--border);
    border-radius: 0.75rem;
    color: var(--text);
    transition: all var(--transition);
    outline: none;
}

.search-input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(6, 182, 212, 0.1);
}

.search-input::placeholder {
    color: var(--text-muted);
}

.search-input-icon {
    position: absolute;
    left: 0.75rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    font-size: 1.125rem;
    pointer-events: none;
}

/* Search Results Container */
.search-results {
    max-height: 400px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

/* Search Result Item */
.search-result {
    padding: 1rem;
    background-color: var(--bg);
    border: 1px solid var(--border);
    border-radius: 0.625rem;
    cursor: pointer;
    transition: all var(--transition);
}

.search-result:hover {
    background-color: var(--card);
    border-color: var(--accent);
    transform: translateX(4px);
}

.search-result-title {
    display: block;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 0.25rem;
}

.search-result-excerpt {
    display: block;
    font-size: 0.875rem;
    color: var(--text-muted);
    line-height: 1.4;
}

.search-result-meta {
    display: flex;
    gap: 1rem;
    margin-top: 0.5rem;
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* Search Highlight - Matched Text */
.search-highlight {
    background-color: rgba(6, 182, 212, 0.25);
    color: var(--accent);
    font-weight: 600;
    padding: 0 0.25rem;
    border-radius: 0.25rem;
}

/* Search Empty State */
.search-empty {
    text-align: center;
    padding: 2rem 1rem;
    color: var(--text-muted);
}

.search-empty-icon {
    font-size: 3rem;
    margin-bottom: 1rem;
    opacity: 0.5;
}

/* Search Loading State */
.search-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    padding: 2rem;
    color: var(--text-muted);
}

.search-spinner {
    width: 20px;
    height: 20px;
    border: 2px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* ============================================================================
   SECTION 3: PERSONALIZATION PANEL
   ========================================================================== */

/* Personalization Overlay */
.persona-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.3);
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
    opacity: 0;
    visibility: hidden;
    transition: opacity var(--transition), visibility var(--transition);
    z-index: 998;
}

.persona-overlay.active {
    opacity: 1;
    visibility: visible;
}

/* Personalization Panel - Slide from Right */
.persona-panel {
    position: fixed;
    top: 0;
    right: 0;
    height: 100vh;
    width: 100%;
    max-width: 380px;
    background-color: var(--card);
    border-left: 1px solid var(--border);
    box-shadow: -10px 0 30px rgba(0, 0, 0, 0.2);
    transform: translateX(100%);
    transition: transform var(--transition);
    overflow-y: auto;
    z-index: 999;
}

.persona-panel.open {
    transform: translateX(0);
}

.persona-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.5rem;
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    background-color: var(--card);
    z-index: 10;
}

.persona-panel-title {
    font-size: 1.125rem;
    font-weight: 700;
    color: var(--text);
}

.persona-panel-close {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 1.5rem;
    padding: 0.5rem;
    transition: color var(--transition);
}

.persona-panel-close:hover {
    color: var(--text);
}

.persona-panel-body {
    padding: 1.5rem;
}

/* Personalization Tabs */
.persona-tabs {
    display: flex;
    gap: 0.5rem;
    border-bottom: 1px solid var(--border);
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.persona-tab {
    padding: 0.75rem 1rem;
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-weight: 500;
    font-size: 0.875rem;
    border-bottom: 2px solid transparent;
    transition: all var(--transition);
    white-space: nowrap;
}

.persona-tab:hover {
    color: var(--text);
}

.persona-tab.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
}

/* Persona Section */
.persona-section {
    display: none;
}

.persona-section.active {
    display: block;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

/* Persona Section Title */
.persona-section-title {
    font-size: 0.875rem;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--text-muted);
    letter-spacing: 0.5px;
    margin-bottom: 1rem;
    margin-top: 1.5rem;
}

.persona-section-title:first-child {
    margin-top: 0;
}

/* Preference Items */
.pref-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.875rem 0;
    border-bottom: 1px solid var(--border);
}

.pref-item:last-child {
    border-bottom: none;
}

.pref-label {
    font-size: 0.938rem;
    color: var(--text);
    font-weight: 500;
}

.pref-description {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 0.25rem;
}

/* Toggle Switch */
.toggle-switch {
    position: relative;
    display: inline-flex;
    width: 44px;
    height: 24px;
    background-color: var(--border);
    border: none;
    border-radius: 12px;
    cursor: pointer;
    transition: background-color var(--transition);
    padding: 2px;
}

.toggle-switch.active {
    background-color: var(--accent);
}

.toggle-switch-slider {
    position: absolute;
    top: 2px;
    left: 2px;
    width: 20px;
    height: 20px;
    background-color: var(--card);
    border-radius: 50%;
    transition: left var(--transition);
}

.toggle-switch.active .toggle-switch-slider {
    left: 22px;
}

/* Bookmark Button */
.bookmark-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    background-color: var(--card);
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    cursor: pointer;
    transition: all var(--transition);
    font-size: 1.25rem;
    color: var(--text-muted);
}

.bookmark-btn:hover {
    background-color: var(--bg);
    border-color: var(--accent);
}

.bookmark-btn.active {
    background-color: rgba(239, 68, 68, 0.1);
    border-color: #ef4444;
    color: #ef4444;
}

.bookmark-btn.active::before {
    content: "❤️";
}

/* Font Size Controls */
.font-size-controls {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.font-size-btn {
    padding: 0.5rem 0.75rem;
    background-color: var(--bg);
    border: 1px solid var(--border);
    border-radius: 0.375rem;
    color: var(--text-muted);
    cursor: pointer;
    font-weight: 500;
    transition: all var(--transition);
    min-width: 36px;
    text-align: center;
}

.font-size-btn:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.font-size-btn.active {
    background-color: var(--accent);
    border-color: var(--accent);
    color: white;
}

/* Category Tags */
.category-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.category-tag {
    padding: 0.5rem 0.875rem;
    background-color: var(--bg);
    border: 1px solid var(--border);
    border-radius: 9999px;
    font-size: 0.75rem;
    color: var(--text-muted);
    cursor: pointer;
    transition: all var(--transition);
    white-space: nowrap;
}

.category-tag:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.category-tag.active {
    background-color: var(--accent);
    border-color: var(--accent);
    color: white;
}

/* ============================================================================
   SECTION 4: PERFORMANCE OPTIMIZATIONS
   ========================================================================== */

/* Lazy Loading Images */
.lazy-img {
    background-color: var(--bg);
    background-image: linear-gradient(
        90deg,
        var(--bg) 0%,
        var(--border) 50%,
        var(--bg) 100%
    );
    background-size: 200% 100%;
    animation: loading-shimmer 2s infinite;
    opacity: 0.6;
    transition: opacity var(--transition), filter var(--transition);
    filter: blur(10px);
    aspect-ratio: 16/9;
}

.lazy-img.loaded {
    opacity: 1;
    filter: blur(0);
    animation: none;
    background-image: none;
}

@keyframes loading-shimmer {
    0% {
        background-position: 200% 0;
    }
    100% {
        background-position: -200% 0;
    }
}

/* Skeleton Loading */
.skeleton {
    background: linear-gradient(
        90deg,
        var(--bg) 0%,
        var(--border) 50%,
        var(--bg) 100%
    );
    background-size: 200% 100%;
    animation: skeleton-loading 2s infinite;
}

@keyframes skeleton-loading {
    0% {
        background-position: 200% 0;
    }
    100% {
        background-position: -200% 0;
    }
}

.skeleton-text {
    height: 1rem;
    margin-bottom: 0.5rem;
    border-radius: 0.25rem;
}

.skeleton-title {
    height: 1.5rem;
    margin-bottom: 1rem;
    border-radius: 0.375rem;
    width: 80%;
}

.skeleton-avatar {
    width: 3rem;
    height: 3rem;
    border-radius: 50%;
}

/* Content Fade In */
.content-fade-in {
    animation: fadeInUp 0.5s ease;
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ============================================================================
   SECTION 5: COUNTER ANIMATIONS
   ========================================================================== */

.counter-animate {
    display: inline-block;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

.counter-value {
    animation: countUp 1s ease-out forwards;
}

@keyframes countUp {
    0% {
        opacity: 0;
        transform: translateY(10px);
    }
    50% {
        opacity: 1;
    }
    100% {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ============================================================================
   SECTION 6: RESPONSIVE DESIGN
   ========================================================================== */

/* Tablets */
@media (max-width: 768px) {
    /* Search Modal */
    .search-modal {
        width: 95%;
        max-width: none;
        padding: 1.5rem;
    }

    /* Personalization Panel */
    .persona-panel {
        max-width: 100%;
        border-left: none;
        border-top: 1px solid var(--border);
    }

    /* Stats Bar */
    .stats-bar {
        gap: 0.5rem;
    }

    .stats-bar-item:not(:last-child)::after {
        display: none;
    }

    .stats-bar-item {
        flex: 1;
        justify-content: center;
        flex-direction: column;
        text-align: center;
    }

    /* Persona Tabs */
    .persona-tabs {
        padding-bottom: 0.75rem;
        gap: 0.25rem;
    }

    .persona-tab {
        padding: 0.5rem 0.75rem;
        font-size: 0.8125rem;
    }
}

/* Mobile Phones */
@media (max-width: 480px) {
    /* Search Modal */
    .search-modal {
        width: 95%;
        max-width: none;
        padding: 1rem;
        top: 20%;
        transform: translate(-50%, 0) scale(0.95);
    }

    .search-overlay.active .search-modal {
        transform: translate(-50%, 0) scale(1);
    }

    .search-input {
        padding: 0.75rem 0.75rem 0.75rem 2.5rem;
        font-size: 1rem;
    }

    .search-results {
        max-height: 300px;
    }

    /* Personalization Panel */
    .persona-panel {
        max-width: 100%;
        border-left: none;
        border-top: 1px solid var(--border);
        animation: slideUp 0.3s ease;
    }

    .persona-panel.open {
        animation: slideUp 0.3s ease;
    }

    @keyframes slideUp {
        from {
            transform: translateY(100%);
        }
        to {
            transform: translateY(0);
        }
    }

    .persona-panel-header {
        padding: 1rem;
    }

    .persona-panel-body {
        padding: 1rem;
    }

    /* Badge */
    .badge {
        padding: 0.3125rem 0.625rem;
        font-size: 0.6875rem;
    }

    /* Stats Bar */
    .stats-bar {
        padding: 0.5rem 0.75rem;
        gap: 0.25rem;
    }

    .stats-bar-item {
        font-size: 0.75rem;
    }

    .stats-bar-item:not(:last-child)::after {
        display: none;
    }

    /* Category Tags */
    .category-tags {
        gap: 0.375rem;
    }

    .category-tag {
        padding: 0.375rem 0.625rem;
        font-size: 0.6875rem;
    }

    /* Font Size Controls */
    .font-size-controls {
        gap: 0.375rem;
    }

    .font-size-btn {
        padding: 0.375rem 0.5rem;
        font-size: 0.75rem;
        min-width: 32px;
    }

    /* Persona Tabs */
    .persona-tabs {
        gap: 0;
        padding-bottom: 0.5rem;
    }

    .persona-tab {
        padding: 0.5rem 0.625rem;
        font-size: 0.75rem;
        border-radius: 0.25rem 0.25rem 0 0;
    }

    /* Touch-friendly tap targets */
    .bookmark-btn,
    .persona-tab,
    .toggle-switch {
        min-width: 44px;
        min-height: 44px;
    }
}

/* ============================================================================
   SECTION 7: LIGHT MODE SPECIFIC ADJUSTMENTS
   ========================================================================== */

.light .badge-trending {
    box-shadow: 0 4px 12px rgba(255, 107, 53, 0.2);
}

.light .badge-new {
    box-shadow: 0 4px 12px rgba(16, 185, 129, 0.2);
}

.light .badge-scheduled {
    box-shadow: 0 4px 12px rgba(245, 158, 11, 0.2);
}

.light .search-overlay {
    background-color: rgba(0, 0, 0, 0.2);
    backdrop-filter: blur(3px);
}

.light .search-modal {
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.1);
}

.light .persona-panel {
    box-shadow: -10px 0 30px rgba(0, 0, 0, 0.1);
}

.light .persona-overlay {
    background-color: rgba(0, 0, 0, 0.2);
}

.light .search-input:focus {
    box-shadow: 0 0 0 3px rgba(6, 182, 212, 0.08);
}

/* ============================================================================
   SECTION 8: ACCESSIBILITY & FOCUS STATES
   ========================================================================== */

/* Focus visible for keyboard navigation */
.badge:focus-visible,
.bookmark-btn:focus-visible,
.persona-tab:focus-visible,
.search-result:focus-visible,
.category-tag:focus-visible,
.font-size-btn:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    * {
        animation: none !important;
        transition: none !important;
    }

    .lazy-img {
        background: none;
    }

    .skeleton {
        background: var(--bg);
    }
}

/* High contrast mode */
@media (prefers-contrast: more) {
    .badge {
        border: 2px solid currentColor;
    }

    .search-input {
        border-width: 3px;
    }

    .persona-panel {
        border-left-width: 3px;
    }
}

/* ============================================================================
   SECTION 9: UTILITY CLASSES
   ========================================================================== */

/* Hide/Show based on theme */
.show-dark {
    display: inherit;
}

.light .show-dark {
    display: none;
}

.show-light {
    display: none;
}

.light .show-light {
    display: inherit;
}

/* Truncate text */
.truncate {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.truncate-lines {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* Text selection */
.text-selectable {
    user-select: text;
    -webkit-user-select: text;
}

.text-unselectable {
    user-select: none;
    -webkit-user-select: none;
}

/* ============================================================================
   SECTION 10: PRINT STYLES
   ========================================================================== */

@media print {
    .search-overlay,
    .persona-overlay,
    .persona-panel,
    .search-modal {
        display: none !important;
    }

    .badge-scheduled,
    .badge-draft {
        display: none !important;
    }
}

/* ============================================================================
   SECTION 11: ANIMATION HELPERS
   ========================================================================== */

/* Smooth scroll behavior */
html {
    scroll-behavior: smooth;
}

@supports not (scroll-behavior: smooth) {
    html {
        scroll-behavior: auto;
    }
}

/* Transform debugging (uncomment when needed) */
/*
.debug-transform {
    outline: 2px dashed var(--accent);
}
*/

/* End of enhancements.css */
