/* Responsive Styles */

/* Desktop Large - 1280px+ */
@media (min-width: 1280px) {
    .sticker-grid {
        grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    }
}

/* Desktop - 1024px to 1279px */
@media (min-width: 1024px) and (max-width: 1279px) {
    .sticker-grid {
        grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    }
}

/* Tablet / iPad - 768px to 1023px */
@media (max-width: 1023px) {
    :root {
        --sidebar-width: 260px;
    }

    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        z-index: 100;
        transform: translateX(-100%);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .sidebar-backdrop {
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 99;
        opacity: 0;
        pointer-events: none;
        transition: opacity var(--transition);
    }

    .sidebar-backdrop.visible {
        opacity: 1;
        pointer-events: auto;
    }

    .mobile-only {
        display: flex;
    }

    #toggle-sidebar {
        display: none;
    }

    .toolbar {
        padding: 12px 16px;
    }

    .toolbar-center {
        max-width: 320px;
    }

    .sticker-container {
        padding: 16px;
    }

    .sticker-grid {
        grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
        gap: 12px;
    }
}

/* Mobile / iPhone - below 768px */
@media (max-width: 767px) {
    :root {
        --toolbar-height: 56px;
    }

    .app-title {
        font-size: 16px;
    }

    .sidebar-header {
        padding: 12px 16px;
    }

    .sidebar-actions {
        padding: 12px 16px;
    }

    .folder-item {
        padding: 10px 16px;
    }

    .folder-section-title {
        padding: 8px 16px;
    }

    .sidebar-footer {
        padding: 12px 16px;
        flex-direction: column;
    }

    .toolbar {
        flex-wrap: wrap;
        height: auto;
        padding: 12px;
        gap: 12px;
    }

    .toolbar-left {
        order: 1;
    }

    .toolbar-right {
        order: 2;
        margin-left: auto;
    }

    .toolbar-center {
        order: 3;
        width: 100%;
        max-width: none;
        margin: 0;
    }

    .current-folder-title {
        font-size: 16px;
    }

    .search-container {
        padding: 10px 12px;
    }

    /* Hide sort label on mobile */
    #sort-label {
        display: none;
    }

    .sort-dropdown .btn {
        padding: 8px 12px;
    }

    /* Upload button - icon only on mobile */
    #upload-btn span {
        display: none;
    }

    #upload-btn {
        padding: 8px 12px;
    }

    .sticker-container {
        padding: 12px;
    }

    .sticker-grid {
        grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
        gap: 10px;
    }

    .sticker-card {
        border-radius: 6px;
    }

    .sticker-image {
        padding: 8px;
    }

    /* List view adjustments */
    .sticker-container.list-view .sticker-image {
        width: 40px;
        height: 40px;
    }

    .sticker-container.list-view .sticker-meta {
        display: none;
    }

    /* Filter panel */
    .filter-panel {
        padding: 12px 16px;
    }

    .color-filter-btn {
        width: 28px;
        height: 28px;
    }

    /* Modal */
    .modal-content {
        width: 95%;
        margin: 16px;
    }

    .modal-header,
    .modal-body,
    .modal-footer {
        padding: 12px 16px;
    }

    /* Toast */
    .toast-container {
        bottom: 16px;
        left: 16px;
        right: 16px;
    }

    .toast {
        width: 100%;
    }

    /* Empty state */
    .empty-state {
        padding: 48px 16px;
    }

    .empty-state svg {
        width: 48px;
        height: 48px;
    }

    .empty-state h3 {
        font-size: 16px;
    }
}

/* Very small phones - below 375px */
@media (max-width: 374px) {
    .sticker-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 8px;
    }

    .view-toggle {
        display: none;
    }

    .toolbar-right {
        gap: 4px;
    }
}

/* iPad Landscape */
@media (min-width: 1024px) and (max-width: 1366px) and (orientation: landscape) {
    .sticker-grid {
        grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    }
}

/* iPad Portrait */
@media (min-width: 768px) and (max-width: 1023px) and (orientation: portrait) {
    .sticker-grid {
        grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
    }
}

/* Touch device optimizations */
@media (hover: none) and (pointer: coarse) {
    /* Always show overlay on touch devices */
    .sticker-overlay {
        opacity: 1;
    }

    .sticker-star,
    .sticker-menu-btn {
        padding: 8px;
        margin: -4px;
    }

    /* Larger tap targets */
    .btn {
        min-height: 44px;
        padding: 10px 18px;
    }

    .btn-icon {
        min-width: 44px;
        min-height: 44px;
    }

    .folder-item {
        min-height: 48px;
    }

    .dropdown-item,
    .context-menu-item {
        min-height: 48px;
        padding: 12px 16px;
    }

    /* Disable hover effects */
    .sticker-card:hover {
        transform: none;
    }

    .btn:hover,
    .btn-icon:hover,
    .folder-item:hover,
    .dropdown-item:hover,
    .context-menu-item:hover {
        background: inherit;
    }

    /* Active states instead */
    .btn:active {
        opacity: 0.8;
    }

    .btn-icon:active,
    .folder-item:active,
    .dropdown-item:active,
    .context-menu-item:active {
        background: var(--bg-hover);
    }

    .sticker-card:active {
        transform: scale(0.98);
    }

    /* Better scrolling */
    .folder-nav,
    .sticker-container {
        -webkit-overflow-scrolling: touch;
    }

    /* Context menu positioning */
    .context-menu {
        min-width: 200px;
    }
}

/* Landscape phones */
@media (max-height: 500px) and (orientation: landscape) {
    .toolbar {
        padding: 8px 16px;
    }

    .sticker-container {
        padding: 8px 16px;
    }

    .sticker-grid {
        grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
        gap: 8px;
    }

    .modal-content {
        max-height: 95vh;
    }

    .modal-body {
        max-height: 50vh;
        overflow-y: auto;
    }
}

/* Collection cards responsive */
@media (max-width: 767px) {
    .collections-grid {
        grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
        gap: 12px;
    }

    .collection-info {
        padding: 10px 12px;
    }

    .collection-name {
        font-size: 13px;
    }

    /* Preview modal on mobile */
    .sticker-preview-modal .modal-content.preview-content {
        max-width: 100%;
        width: 100%;
        height: 100%;
        max-height: 100%;
        border-radius: 0;
    }

    .preview-image-container {
        min-height: 150px;
        max-height: 50vh;
    }

    .preview-actions {
        flex-wrap: wrap;
    }

    .preview-actions .btn {
        flex: 1 1 calc(50% - 6px);
        min-width: calc(50% - 6px);
    }
}

/* Dark mode support (respects system preference) */
@media (prefers-color-scheme: dark) {
    :root {
        --bg-primary: #1f2937;
        --bg-secondary: #111827;
        --bg-tertiary: #374151;
        --bg-hover: #4b5563;

        --text-primary: #f9fafb;
        --text-secondary: #d1d5db;
        --text-tertiary: #9ca3af;

        --border-color: #374151;
    }

    .sticker-image {
        background: repeating-conic-gradient(#374151 0% 25%, transparent 0% 50%) 50% / 20px 20px;
    }

    .preview-image-container {
        background: repeating-conic-gradient(#374151 0% 25%, transparent 0% 50%) 50% / 20px 20px;
    }

    .search-container {
        background: var(--bg-tertiary);
    }

    .toast {
        background: var(--bg-tertiary);
    }

    .show-sidebar-btn {
        background: var(--bg-tertiary);
        border-color: var(--border-color);
    }

    .custom-color-btn {
        background: var(--bg-tertiary);
    }
}

/* 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 */
@media (prefers-contrast: high) {
    :root {
        --border-color: currentColor;
    }

    .btn,
    .sticker-card,
    .folder-item {
        border: 2px solid currentColor;
    }
}

/* Print styles */
@media print {
    .sidebar,
    .toolbar,
    .filter-panel,
    .toast-container,
    .modal,
    .context-menu {
        display: none !important;
    }

    .main-content {
        width: 100% !important;
    }

    .sticker-container {
        overflow: visible;
        padding: 0;
    }

    .sticker-grid {
        display: grid;
        grid-template-columns: repeat(4, 1fr);
        gap: 16px;
    }

    .sticker-card {
        break-inside: avoid;
        box-shadow: none;
        border: 1px solid #000;
    }

    .sticker-overlay {
        display: none;
    }
}
