/* Custom styles for DashDork */

/* Animations */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

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

/* Widget drag and drop animations */
.sortable-ghost {
    opacity: 0.5 !important;
    background: #f3f4f6 !important;
    box-shadow: 0 0 0 2px #4338ca !important;
}

.sortable-drag {
    opacity: 0.8;
    transform: rotate(1deg);
}

/* Spinner animation */
@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

.spinner {
    animation: spin 1s linear infinite;
}

/* Custom scrollbar for widgets */
.widget-content::-webkit-scrollbar {
    width: 6px;
}

.widget-content::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 6px;
}

.widget-content::-webkit-scrollbar-thumb {
    background: #c7d2fe;
    border-radius: 6px;
}

.widget-content::-webkit-scrollbar-thumb:hover {
    background: #4338ca;
}

/* Finger-friendly scrollbars for mobile */
@media (max-width: 767px) {
    /* Auto-hide scrollbars on mobile for cleaner look */
    .widget-content::-webkit-scrollbar {
        width: 8px; /* Slightly wider for touch */
        opacity: 0;
        transition: opacity 0.3s ease;
    }

    .widget-content:hover::-webkit-scrollbar,
    .widget-content:focus::-webkit-scrollbar,
    .widget-content:active::-webkit-scrollbar {
        opacity: 1;
    }

    .widget-content::-webkit-scrollbar-track {
        background: rgba(241, 241, 241, 0.5);
        border-radius: 8px;
    }

    .widget-content::-webkit-scrollbar-thumb {
        background: rgba(199, 210, 254, 0.7);
        border-radius: 8px;
        min-height: 40px; /* Minimum touch target for scrollbar */
    }

    .widget-content::-webkit-scrollbar-thumb:hover {
        background: rgba(67, 56, 202, 0.8);
    }

    /* Enhanced RSS widget scrollbars - applied to all RSS scroll containers */
    [id^="scroll-container-"]::-webkit-scrollbar {
        width: 12px; /* Even wider for RSS content */
        opacity: 0;
        transition: opacity 0.3s ease;
    }

    [id^="scroll-container-"]:hover::-webkit-scrollbar,
    [id^="scroll-container-"]:focus::-webkit-scrollbar,
    [id^="scroll-container-"]:active::-webkit-scrollbar {
        opacity: 1;
    }

    [id^="scroll-container-"]::-webkit-scrollbar-track {
        background: rgba(241, 241, 241, 0.3);
        border-radius: 12px;
    }

    [id^="scroll-container-"]::-webkit-scrollbar-thumb {
        background: rgba(199, 210, 254, 0.6);
        border-radius: 12px;
        min-height: 48px; /* Larger touch target */
    }

    [id^="scroll-container-"]::-webkit-scrollbar-thumb:hover {
        background: rgba(67, 56, 202, 0.7);
    }

    /* Mobile menu scrollbar */
    #mobile-menu-panel::-webkit-scrollbar {
        width: 6px;
    }

    #mobile-menu-panel::-webkit-scrollbar-track {
        background: rgba(255, 255, 255, 0.1);
        border-radius: 6px;
    }

    #mobile-menu-panel::-webkit-scrollbar-thumb {
        background: rgba(255, 255, 255, 0.3);
        border-radius: 6px;
    }

    #mobile-menu-panel::-webkit-scrollbar-thumb:hover {
        background: rgba(255, 255, 255, 0.5);
    }

    /* Dashboard tabs scrollbar */
    .dashboard-tabs::-webkit-scrollbar {
        height: 4px; /* Thin horizontal scrollbar */
        opacity: 0;
        transition: opacity 0.3s ease;
    }

    .dashboard-tabs:hover::-webkit-scrollbar,
    .dashboard-tabs:focus::-webkit-scrollbar,
    .dashboard-tabs:active::-webkit-scrollbar {
        opacity: 1;
    }

    .dashboard-tabs::-webkit-scrollbar-track {
        background: rgba(241, 241, 241, 0.3);
        border-radius: 4px;
    }

    .dashboard-tabs::-webkit-scrollbar-thumb {
        background: rgba(199, 210, 254, 0.6);
        border-radius: 4px;
        min-width: 40px;
    }

    .dashboard-tabs::-webkit-scrollbar-thumb:hover {
        background: rgba(67, 56, 202, 0.7);
    }
}

/* Color input styling */
.color-input {
    width: 60px;
    height: 40px;
    padding: 0;
    border: 1px solid #d1d5db;
    border-radius: 4px;
    cursor: pointer;
    background: none;
}

.color-input:focus {
    outline: none;
    border-color: #4338ca;
    box-shadow: 0 0 0 2px rgba(67, 56, 202, 0.2);
}

/* Improved tab styles */
.dashboard-tabs .dashboard-tab {
    transition: all 0.2s ease;
}

.dashboard-tabs .dashboard-tab:hover:not(.active) {
    background-color: #f3f4f6;
}

/* Widget hover effect */
.widget {
    transition: box-shadow 0.2s ease, transform 0.2s ease;
}

.widget:hover {
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
}

/* Widget actions visibility */
.widget-control-buttons {
    opacity: 0.5;
    transition: opacity 0.2s ease;
}

.widget-header:hover .widget-control-buttons {
    opacity: 1;
}

/* Mobile widget actions default state */
.widget-actions {
    display: none !important;
}

/* Ensure icon doesn't block click on button */
.widget-actions svg { pointer-events: none; }

/* Ensure kebab dropdown is hidden by default; shown when not 'hidden' */
.widget-actions-menu {
    display: none;
}
.widget-actions-menu:not(.hidden) {
    display: block;
}

/* Enhanced Mobile Touch Targets and Typography (48px minimum) */
@media (max-width: 767px) {
    .dashboard-tabs {
        flex-wrap: wrap;
    }

    .dashboard-tab {
        padding: 0.75rem 1rem; /* Increased padding for 48px+ touch targets */
        font-size: 0.875rem;
        min-height: 48px; /* Explicit minimum height */
        display: flex;
        align-items: center;
        line-height: 1.4; /* Improved line height for readability */
    }

    /* Enhanced mobile typography */
    body {
        font-size: 16px; /* Prevent zoom on iOS */
        line-height: 1.6; /* Better readability */
        -webkit-text-size-adjust: 100%; /* Prevent text scaling */
    }

    h1, h2, h3, h4, h5, h6 {
        line-height: 1.3; /* Tighter headings for mobile */
    }

    p, li {
        line-height: 1.6; /* Better paragraph spacing */
    }

    /* Improved spacing for mobile content */
    main {
        padding-top: 1rem; /* Reduced from 1rem to give more space */
        padding-bottom: 1rem;
    }

    .widget {
        margin-bottom: 1rem; /* Increased spacing between widgets */
    }

    .widget-content {
        padding: 0.75rem; /* Slightly more padding for breathing room */
    }

    /* Better form spacing on mobile */
    .form-group {
        margin-bottom: 1.25rem; /* More space between form elements */
    }

    .form-control {
        padding: 0.75rem; /* Larger input padding */
        font-size: 16px; /* Prevent zoom on iOS */
    }

    /* Improved button spacing */
    .btn {
        padding: 0.75rem 1.5rem; /* Larger button padding */
        min-height: 48px; /* Minimum touch target */
        font-size: 1rem; /* Consistent sizing */
    }

    /* Mobile widget actions (kebab menu) - Enhanced touch targets */
    .widget-header {
        position: relative;
        display: flex;
        align-items: center;
        min-height: 3rem; /* Increased from 2.75rem */
        padding: 0.5rem 0; /* Add vertical padding */
    }
    .widget-control-buttons { display: none !important; }
    .widget-actions {
        display: inline-flex !important;
        align-items: center;
        justify-content: center;
        position: absolute;
        top: 50%;
        right: 0.25rem;
        transform: translateY(-50%);
        width: 48px; /* Increased from 2.75rem (44px) to 48px */
        height: 48px; /* Increased from 2.75rem (44px) to 48px */
        border-radius: 0.5rem;
        color: var(--color-text-secondary);
        background: transparent;
        touch-action: manipulation; /* Prevent zoom on double-tap */
        -webkit-tap-highlight-color: transparent; /* Remove tap highlight on iOS */
        transition: background-color 0.15s ease;
    }
    .widget-actions:hover {
        background-color: rgba(0, 0, 0, 0.05);
    }
    .widget-actions:active {
        background-color: rgba(0, 0, 0, 0.1);
        transform: translateY(-50%) scale(0.95);
    }
    .widget-actions:focus {
        outline: 2px solid #c7d2fe;
        outline-offset: 2px;
    }

    /* Mobile menu backdrop */
    .widget-menu-backdrop {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.3);
        z-index: 999;
        opacity: 0;
        visibility: hidden;
        transition: all 0.2s ease;
    }
    .widget-menu-backdrop.active {
        opacity: 1;
        visibility: visible;
    }

    .widget-actions-menu {
        position: fixed;
        background: var(--color-bg-surface, #fff);
        border: 1px solid #e5e7eb;
        border-radius: 0.75rem;
        min-width: 220px;
        max-width: calc(100vw - 2rem);
        box-shadow: 0 20px 25px -5px rgba(0,0,0,0.1), 0 10px 10px -5px rgba(0,0,0,0.04);
        z-index: 1000;
        transform: scale(0.95);
        opacity: 0;
        visibility: hidden;
        transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
        overflow: hidden;
    }
    .widget-actions-menu.active {
        transform: scale(1);
        opacity: 1;
        visibility: visible;
    }
    .widget-actions-menu .item {
        display: flex;
        align-items: center;
        gap: 0.75rem;
        padding: 1rem 1.25rem;
        min-height: 52px; /* Larger touch target */
        font-size: 1rem; /* Better readability */
        color: #111827;
        touch-action: manipulation;
        -webkit-tap-highlight-color: transparent;
        transition: background-color 0.15s ease;
        border: none;
        background: transparent;
        width: 100%;
        text-align: left;
        cursor: pointer;
        font-weight: 500;
    }
    .widget-actions-menu .item:first-child {
        border-top-left-radius: 0.75rem;
        border-top-right-radius: 0.75rem;
    }
    .widget-actions-menu .item:last-child {
        border-bottom-left-radius: 0.75rem;
        border-bottom-right-radius: 0.75rem;
    }
    .widget-actions-menu .item:hover {
        background-color: rgba(0, 0, 0, 0.05);
    }
    .widget-actions-menu .item:active {
        background-color: rgba(0, 0, 0, 0.08);
        transform: scale(0.98);
    }
    .widget-actions-menu .item.delete {
        color: #ef4444;
        border-top: 1px solid #f3f4f6;
    }
    .widget-actions-menu .item svg {
        width: 20px;
        height: 20px;
        flex-shrink: 0;
    }

    /* Ensure title doesn't overlap kebab */
    .widget-header-title { padding-right: 3.5rem; } /* Increased from 3rem */

    .tab-actions {
        position: static;
        padding: 0.5rem;
        background: none;
        width: 100%;
        justify-content: center;
        border-top: 1px solid #e5e7eb;
    }

    /* Enhanced RSS scroll buttons */
    .rss-scroll-btn {
        min-width: 48px !important; /* Ensure minimum 48px width */
        min-height: 48px !important; /* Ensure minimum 48px height */
        touch-action: manipulation;
    }

    /* Mobile menu button enhancement */
    #mobile-menu-button {
        min-width: 48px;
        min-height: 48px;
        display: flex;
        align-items: center;
        justify-content: center;
        touch-action: manipulation;
    }

    /* Theme buttons in mobile menu */
    .theme-btn {
        min-width: 48px;
        min-height: 48px;
        touch-action: manipulation;
    }

    /* Header links and buttons */
    .header-link, .header-tab {
        min-height: 48px;
        display: flex;
        align-items: center;
        touch-action: manipulation;
    }

    /* Modal close buttons */
    .modal-close {
        min-width: 48px;
        min-height: 48px;
        display: flex;
        align-items: center;
        justify-content: center;
        touch-action: manipulation;
    }

    /* Mobile Bottom Scroll Bar */
    .mobile-scroll-bar {
        position: fixed;
        bottom: 20px;
        left: 50%;
        transform: translateX(-50%);
        display: flex; /* Show on mobile */
        align-items: center;
        gap: 12px;
        background: var(--color-bg-surface, #fff);
        border: 1px solid var(--color-border, #e5e7eb);
        border-radius: 24px;
        padding: 8px 16px;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
        z-index: 1000;
        opacity: 0;
        transform: translateX(-50%) translateY(100px);
        transition: all 0.3s ease;
        backdrop-filter: blur(8px);
    }

    .mobile-scroll-bar.visible {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }

    .scroll-arrow {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 40px;
        height: 40px;
        border: none;
        background: transparent;
        color: var(--color-text-secondary);
        border-radius: 50%;
        cursor: pointer;
        transition: all 0.2s ease;
        touch-action: manipulation;
    }

    .scroll-arrow:hover {
        background: var(--color-bg-primary, #f9fafb);
        color: var(--color-text-primary, #111827);
    }

    .scroll-arrow:active {
        transform: scale(0.95);
    }

    .scroll-indicator {
        flex: 1;
        height: 4px;
        background: var(--color-border, #e5e7eb);
        border-radius: 2px;
        position: relative;
        min-width: 80px;
        max-width: 120px;
    }

    .scroll-progress {
        height: 100%;
        background: var(--color-primary, #4338ca);
        border-radius: 2px;
        width: 0%;
        transition: width 0.3s ease;
    }
}

/* Hide mobile scroll bar on desktop/full screen mode */
@media (min-width: 768px) {
    .mobile-scroll-bar {
        display: none !important;
    }
}
