/**
 * Responsive Design System
 * Cross-browser and cross-device compatible styles
 * Supports: Desktop, Tablet, Mobile
 * Browsers: Chrome, Firefox, Safari, Edge
 */

/* ===================================
   BASE RESPONSIVE UTILITIES
   =================================== */

/* Ensure box-sizing is consistent across browsers */
*, *::before, *::after {
    box-sizing: border-box;
    -webkit-box-sizing: border-box;
    -moz-box-sizing: border-box;
}

/* Prevent horizontal scrolling */
html, body {
    overflow-x: hidden;
    width: 100%;
    max-width: 100%;
}

body {
    -webkit-text-size-adjust: 100%;
    -moz-text-size-adjust: 100%;
    -ms-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

/* Images and media are responsive by default */
img, video, iframe {
    max-width: 100%;
    height: auto;
}

/* ===================================
   TABLET AND BELOW (< 1024px)
   =================================== */

@media (max-width: 1024px) {
    /* Header adjustments */
    .app-header {
        padding: 15px 20px;
        flex-wrap: wrap;
        gap: 10px;
    }

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

    /* Search bar full width on tablet */
    .search-container {
        flex: 1 1 100%;
        max-width: 100%;
        margin: 10px 0;
    }

    /* Table adjustments */
    .table-container {
        padding: 10px;
    }

    /* Button groups wrap better */
    .btn-group {
        gap: 6px;
    }

    /* Navigation menu */
    .nav-menu {
        flex-wrap: wrap;
        gap: 10px;
    }

    .nav-menu a {
        padding: 8px 16px;
        font-size: 14px;
    }
}

/* ===================================
   MOBILE DEVICES (< 768px)
   =================================== */

@media (max-width: 768px) {
    /* Header - Stack vertically */
    .app-header {
        padding: 12px 15px;
        flex-direction: column;
        align-items: stretch;
    }

    .app-title {
        font-size: 18px;
        text-align: center;
        margin-bottom: 10px;
    }

    .logout-btn {
        width: 100%;
        text-align: center;
        justify-content: center;
    }

    /* Search container */
    .search-container {
        margin: 10px 0;
    }

    .search-input {
        font-size: 16px; /* Prevents iOS zoom */
        padding: 12px 40px 12px 15px;
    }

    /* Selection toolbar - Stack buttons */
    .selection-toolbar {
        padding: 12px 15px;
        flex-direction: column;
        gap: 10px;
    }

    .selection-info {
        width: 100%;
        text-align: center;
        margin-bottom: 8px;
    }

    .toolbar-actions {
        width: 100%;
        display: flex;
        flex-direction: column;
        gap: 8px;
    }

    .toolbar-actions .btn {
        width: 100%;
    }

    /* Table - Card layout on mobile */
    .table-responsive {
        border: 0;
    }

    .table-responsive table {
        border: 0;
    }

    .table-responsive table thead {
        display: none; /* Hide table headers */
    }

    .table-responsive table tbody {
        display: block;
    }

    .table-responsive table tr {
        display: block;
        margin-bottom: 15px;
        border: 1px solid #ddd;
        border-radius: 8px;
        background: #fff;
        box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
        overflow: hidden;
    }

    body[data-theme="dark"] .table-responsive table tr {
        border-color: #444;
        background: #2d2d2d;
    }

    .table-responsive table td {
        display: block;
        text-align: right;
        padding: 10px 15px;
        border: none;
        border-bottom: 1px solid #f0f0f0;
        position: relative;
    }

    body[data-theme="dark"] .table-responsive table td {
        border-bottom-color: #3d3d3d;
    }

    .table-responsive table td:last-child {
        border-bottom: none;
    }

    .table-responsive table td::before {
        content: attr(data-label);
        float: left;
        font-weight: bold;
        color: #667eea;
        margin-right: 10px;
    }

    body[data-theme="dark"] .table-responsive table td::before {
        color: #8b9cff;
    }

    /* Checkbox cell - special layout */
    .table-responsive table td:first-child {
        text-align: center;
        padding: 15px;
        background: #f8f9fa;
        border-bottom: 2px solid #667eea;
    }

    body[data-theme="dark"] .table-responsive table td:first-child {
        background: #3d3d3d;
    }

    .table-responsive table td:first-child::before {
        display: none;
    }

    /* Icon cell - special layout */
    .icon-cell {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
        text-align: left;
    }

    .icon-thumbnail {
        width: 100%;
        max-width: 200px;
        height: auto;
        margin: 0 auto;
        display: block;
    }

    .icon-name {
        font-size: 14px;
        text-align: center;
        width: 100%;
    }

    /* Control buttons - Better mobile layout */
    .btn-group {
        display: flex;
        justify-content: center;
        gap: 8px;
        flex-wrap: wrap;
    }

    .btn-copy, .btn-rename, .btn-delete {
        min-width: 44px; /* Touch target size */
        min-height: 44px;
        padding: 12px;
    }

    /* Link cell - Break long URLs */
    .icon-link {
        word-break: break-all;
        font-size: 12px;
    }

    /* Navigation menu - Full width buttons */
    .nav-menu {
        flex-direction: column;
        gap: 8px;
    }

    .nav-menu a {
        width: 100%;
        text-align: center;
        padding: 12px 20px;
    }

    /* Stats info */
    .stats-info {
        font-size: 13px;
        padding: 10px 15px;
        flex-wrap: wrap;
        justify-content: center;
        gap: 8px;
    }

    /* Footer */
    .footer-content {
        font-size: 11px;
        padding: 15px 10px;
    }

    /* Modals - Full screen on mobile */
    .rename-modal-content,
    .delete-modal-content {
        width: 95%;
        max-width: 95%;
        max-height: 90vh;
        overflow-y: auto;
        margin: 10px;
    }

    .rename-modal-header h3,
    .delete-modal-header h3 {
        font-size: 16px;
    }

    .rename-modal-body,
    .delete-modal-body {
        padding: 20px;
    }

    .rename-modal-footer,
    .delete-modal-footer {
        flex-direction: column;
        gap: 8px;
    }

    .rename-modal-footer .btn,
    .delete-modal-footer .btn {
        width: 100%;
        min-height: 44px;
    }

    /* Forms - Better mobile UX */
    .form-control {
        font-size: 16px; /* Prevents iOS zoom */
        padding: 12px 15px;
        min-height: 44px;
    }

    input[type="text"],
    input[type="password"],
    input[type="email"],
    textarea {
        font-size: 16px; /* Prevents iOS zoom */
    }

    /* Toast notifications */
    .toast {
        width: calc(100% - 30px);
        left: 15px;
        right: 15px;
        max-width: none;
    }

    /* Dropzone adjustments */
    .dropzone {
        padding: 20px;
        min-height: 200px;
    }

    .dropzone .dz-message {
        font-size: 16px;
    }

    .dropzone .dz-message i {
        font-size: 36px;
        margin-bottom: 15px;
    }

    /* Settings containers */
    .settings-container,
    .upload-container,
    .login-container {
        padding: 15px;
    }

    .settings-section,
    .upload-section {
        padding: 20px 15px;
    }

    /* Login page */
    .login-box {
        width: 95%;
        max-width: 95%;
        padding: 25px 20px;
    }

    .pin-input {
        font-size: 24px;
        padding: 15px;
        min-height: 60px;
    }

    /* Theme and language switches */
    .toggle-switch {
        width: 100%;
    }

    .toggle-option {
        padding: 12px 8px;
        font-size: 13px;
    }

    .toggle-option i {
        font-size: 16px;
    }
}

/* ===================================
   SMALL MOBILE (< 480px)
   =================================== */

@media (max-width: 480px) {
    .app-title {
        font-size: 16px;
    }

    .btn-group {
        gap: 5px;
    }

    .btn-copy, .btn-rename, .btn-delete {
        min-width: 40px;
        min-height: 40px;
        padding: 10px;
    }

    .btn-copy i, .btn-rename i, .btn-delete i {
        font-size: 13px;
    }

    .icon-link {
        font-size: 11px;
    }

    .stats-info {
        font-size: 12px;
    }

    .nav-menu a {
        padding: 10px 15px;
        font-size: 13px;
    }
}

/* ===================================
   LANDSCAPE MODE (Mobile/Tablet)
   =================================== */

@media (max-height: 500px) and (orientation: landscape) {
    .app-header {
        padding: 8px 15px;
    }

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

    .logout-btn {
        padding: 6px 12px;
        font-size: 13px;
    }

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

    .selection-toolbar {
        padding: 8px 15px;
    }
}

/* ===================================
   CROSS-BROWSER COMPATIBILITY
   =================================== */

/* Flexbox fallbacks */
.app-header,
.btn-group,
.nav-menu,
.selection-toolbar {
    display: -webkit-box;
    display: -webkit-flex;
    display: -moz-box;
    display: -ms-flexbox;
    display: flex;
}

/* Flex properties with vendor prefixes */
.search-container {
    -webkit-box-flex: 1;
    -webkit-flex: 1;
    -moz-box-flex: 1;
    -ms-flex: 1;
    flex: 1;
}

/* Transform with vendor prefixes */
.btn-copy:hover,
.btn-rename:hover,
.btn-delete:hover {
    -webkit-transform: translateY(-2px);
    -moz-transform: translateY(-2px);
    -ms-transform: translateY(-2px);
    transform: translateY(-2px);
}

/* Transition with vendor prefixes */
.btn, .form-control, .icon-row {
    -webkit-transition: all 0.3s;
    -moz-transition: all 0.3s;
    -ms-transition: all 0.3s;
    -o-transition: all 0.3s;
    transition: all 0.3s;
}

/* Border radius for older browsers */
.btn, .form-control, .icon-row {
    -webkit-border-radius: 4px;
    -moz-border-radius: 4px;
    border-radius: 4px;
}

/* Box shadow for older browsers */
.icon-row:hover {
    -webkit-box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
    -moz-box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
}

/* Appearance reset for form elements (cross-browser) */
input, textarea, select, button {
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
}

/* Select dropdowns - add custom arrow */
select {
    background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right 10px center;
    background-size: 16px;
    padding-right: 35px;
}

/* Smooth scrolling for all browsers */
html {
    -webkit-overflow-scrolling: touch;
    scroll-behavior: smooth;
}

/* User select for better UX */
.btn, .icon-checkbox, #select-all-checkbox {
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

/* Tap highlight color (mobile) */
* {
    -webkit-tap-highlight-color: rgba(102, 126, 234, 0.2);
}

/* ===================================
   TOUCH DEVICE OPTIMIZATIONS
   =================================== */

/* Enhanced checkbox visibility for all themes */
.icon-checkbox, #select-all-checkbox {
    position: relative;
    vertical-align: middle;
    margin: 0;
}

/* Ensure checkboxes are visible on all backgrounds */
@supports not (accent-color: #667eea) {
    /* Fallback for older browsers */
    .icon-checkbox, #select-all-checkbox {
        filter: contrast(1.2) brightness(1.1);
    }
}

@media (hover: none) and (pointer: coarse) {
    /* Increase touch targets */
    .btn, .icon-checkbox, #select-all-checkbox, a {
        min-width: 44px;
        min-height: 44px;
    }

    /* Larger checkboxes for touch */
    .icon-checkbox, #select-all-checkbox {
        width: 24px;
        height: 24px;
        min-width: 24px;
        min-height: 24px;
    }

    /* Remove hover effects on touch devices */
    .btn:hover,
    .icon-row:hover {
        transform: none;
        -webkit-transform: none;
    }

    /* Add active state instead */
    .btn:active {
        opacity: 0.7;
    }

    .icon-row:active {
        background: rgba(102, 126, 234, 0.05);
    }
}

/* ===================================
   PRINT STYLES
   =================================== */

@media print {
    .app-header,
    .search-container,
    .selection-toolbar,
    .nav-menu,
    .btn-group,
    .footer-content {
        display: none;
    }

    .table-responsive table {
        border: 1px solid #000;
    }

    .icon-row {
        page-break-inside: avoid;
    }
}

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

/* Focus visible for keyboard navigation */
button:focus-visible,
input:focus-visible,
select:focus-visible,
a:focus-visible {
    outline: 2px solid #667eea;
    outline-offset: 2px;
}

/* Skip to content link for screen readers */
.skip-to-content {
    position: absolute;
    left: -9999px;
    z-index: 999;
}

.skip-to-content:focus {
    left: 50%;
    transform: translateX(-50%);
    top: 10px;
    background: #667eea;
    color: white;
    padding: 10px 20px;
    border-radius: 4px;
    text-decoration: none;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .btn {
        border-width: 2px;
    }

    .icon-row {
        border: 2px solid currentColor;
    }
}

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