/* retoor <retoor@molodetz.nl> */

:root {
    --touch-target-min: 44px;
    --touch-target-comfortable: 48px;
    --sidebar-width-mobile: 280px;
    --header-height-mobile: 56px;
    --safe-area-inset-top: env(safe-area-inset-top, 0);
    --safe-area-inset-bottom: env(safe-area-inset-bottom, 0);
    --safe-area-inset-left: env(safe-area-inset-left, 0);
    --safe-area-inset-right: env(safe-area-inset-right, 0);
}

.hamburger-btn {
    display: none;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    width: var(--touch-target-min);
    height: var(--touch-target-min);
    padding: 8px;
    background: transparent;
    border: none;
    cursor: pointer;
    gap: 5px;
    margin-right: 8px;
    border-radius: 8px;
    -webkit-tap-highlight-color: transparent;
}

.hamburger-btn span {
    display: block;
    width: 24px;
    height: 2px;
    background-color: var(--primary-color);
    border-radius: 2px;
    transition: transform 0.3s ease, opacity 0.3s ease;
}

.hamburger-btn.active span:nth-child(1) {
    transform: translateY(7px) rotate(45deg);
}

.hamburger-btn.active span:nth-child(2) {
    opacity: 0;
}

.hamburger-btn.active span:nth-child(3) {
    transform: translateY(-7px) rotate(-45deg);
}

.hamburger-btn:active {
    background-color: rgba(0, 51, 153, 0.1);
}

.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 149;
    opacity: 0;
    transition: opacity 0.3s ease;
    -webkit-tap-highlight-color: transparent;
    pointer-events: none;
}

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

.pull-to-refresh-indicator {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    height: 0;
    overflow: hidden;
    background-color: var(--background-color);
    transition: height 0.2s ease;
    opacity: 0;
}

.pull-spinner {
    width: 24px;
    height: 24px;
    border: 2px solid var(--border-color);
    border-top-color: var(--primary-color);
    border-radius: 50%;
}

.pull-to-refresh-indicator.refreshing .pull-spinner {
    animation: spin 0.8s linear infinite;
}

.pull-to-refresh-indicator.ready .pull-spinner {
    border-color: var(--primary-color);
    border-top-color: var(--primary-color);
}

.pull-text {
    font-size: 0.875rem;
    color: var(--text-color-light);
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.context-menu {
    position: fixed;
    min-width: 200px;
    max-width: 280px;
    background-color: var(--accent-color);
    border-radius: 12px;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.15);
    z-index: 1000;
    padding: 8px 0;
    opacity: 0;
    transform: scale(0.95);
    transition: opacity 0.2s ease, transform 0.2s ease;
    overflow: hidden;
}

.context-menu.visible {
    opacity: 1;
    transform: scale(1);
}

.context-menu-item {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 14px 16px;
    background: none;
    border: none;
    font-size: 1rem;
    color: var(--text-color);
    text-align: left;
    cursor: pointer;
    min-height: var(--touch-target-min);
    -webkit-tap-highlight-color: transparent;
}

.context-menu-item:active {
    background-color: rgba(0, 51, 153, 0.1);
}

.context-menu-item.destructive {
    color: #d32f2f;
}

.context-menu-icon {
    width: 24px;
    text-align: center;
    font-size: 1.1rem;
}

.context-menu-separator {
    height: 1px;
    background-color: var(--border-color);
    margin: 8px 0;
}

.mobile-more-btn {
    display: none;
    width: 36px;
    height: 36px;
    min-width: 36px;
    background: transparent;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    font-size: 1.25rem;
    color: var(--text-color-light);
    -webkit-tap-highlight-color: transparent;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.mobile-more-btn:active {
    background-color: rgba(0, 51, 153, 0.1);
}

@media (max-width: 767px) {
    .hamburger-btn {
        display: flex;
    }

    .sidebar-overlay {
        display: block;
    }

    .app-header {
        height: var(--header-height-mobile);
        padding: 0 8px;
        padding-top: var(--safe-area-inset-top);
        flex-wrap: nowrap;
    }

    .header-left {
        flex-shrink: 0;
        display: flex;
        align-items: center;
    }

    .app-title {
        font-size: 1.125rem;
    }

    .header-center {
        flex: 1;
        min-width: 0;
        max-width: none;
        margin: 0 8px;
    }

    .search-input {
        height: var(--touch-target-min);
        font-size: 16px;
    }

    .header-right {
        flex-shrink: 0;
        gap: 4px;
    }

    .header-right .user-info {
        display: none;
    }

    .header-right .button {
        min-width: var(--touch-target-min);
        min-height: var(--touch-target-min);
        padding: 8px 12px;
        font-size: 0.875rem;
    }

    .app-body {
        flex-direction: column;
    }

    .app-sidebar {
        position: fixed;
        top: 0;
        left: 0;
        width: var(--sidebar-width-mobile);
        height: 100vh;
        height: 100dvh;
        transform: translateX(-100%);
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        z-index: 150;
        background-color: var(--accent-color);
        box-shadow: none;
        padding-top: var(--safe-area-inset-top);
        overflow-y: auto;
    }

    .app-sidebar.open {
        transform: translateX(0);
        box-shadow: 4px 0 24px rgba(0, 0, 0, 0.15);
    }

    .sidebar-nav {
        padding: 16px;
    }

    .nav-title {
        font-size: 0.75rem;
        text-transform: uppercase;
        letter-spacing: 0.5px;
        color: var(--text-color-light);
        margin: 16px 0 8px;
    }

    .nav-title:first-child {
        margin-top: 0;
    }

    .nav-list {
        list-style: none;
        padding: 0;
        margin: 0;
    }

    .nav-link {
        display: flex;
        align-items: center;
        min-height: var(--touch-target-comfortable);
        padding: 12px 16px;
        color: var(--text-color);
        text-decoration: none;
        border-radius: 8px;
        font-size: 1rem;
        -webkit-tap-highlight-color: transparent;
    }

    .nav-link:active {
        background-color: rgba(0, 51, 153, 0.1);
    }

    .nav-link.active {
        background-color: rgba(0, 51, 153, 0.1);
        color: var(--primary-color);
        font-weight: 500;
    }

    .app-main {
        flex: 1;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        padding: 12px;
    }

    body.logged-in .app-footer {
        display: none;
    }

    .app-footer {
        padding: 8px 12px;
        padding-bottom: calc(8px + var(--safe-area-inset-bottom));
    }

    .footer-links {
        flex-wrap: wrap;
        gap: 2px 8px;
        justify-content: center;
    }

    .footer-links li a {
        font-size: 0.6rem;
        min-height: 28px;
        display: flex;
        align-items: center;
        padding: 2px 0;
    }

    .footer-text {
        font-size: 0.6rem;
        margin-top: 4px;
    }

    .file-list-container {
        padding: 0;
        background: transparent;
    }

    .file-list-header {
        padding: 8px 0;
        flex-direction: column;
        align-items: stretch;
        gap: 12px;
        border-bottom: none;
        margin-bottom: 8px;
    }

    .file-list-header .header-left {
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
        width: 100%;
    }

    .file-list-title,
    .file-list-header h2 {
        font-size: 1.25rem;
        margin: 0;
    }

    .selection-controls {
        flex-shrink: 0;
    }

    .selection-controls label {
        font-size: 0.75rem;
    }

    .file-actions {
        display: flex;
        gap: 8px;
        width: 100%;
    }

    .file-actions .button {
        min-height: var(--touch-target-min);
        flex: 1;
        justify-content: center;
        font-size: 0.875rem;
        padding: 10px 12px;
    }

    .file-grid {
        display: flex;
        flex-direction: column;
        gap: 1px;
        background-color: var(--border-color);
        border-radius: 8px;
        overflow: hidden;
    }

    .file-item {
        display: flex;
        flex-direction: row;
        align-items: center;
        min-height: 60px;
        padding: 10px 12px;
        background-color: var(--accent-color);
        gap: 10px;
        border-radius: 0;
        border: none;
        cursor: pointer;
    }

    .file-item:first-child {
        border-radius: 8px 8px 0 0;
    }

    .file-item:last-child {
        border-radius: 0 0 8px 8px;
    }

    .file-item:only-child {
        border-radius: 8px;
    }

    .file-item .select-item {
        position: relative;
        top: auto;
        left: auto;
        width: 20px;
        height: 20px;
        min-width: 20px;
        opacity: 1;
        cursor: pointer;
        flex-shrink: 0;
    }

    .file-icon {
        width: 40px;
        height: 40px;
        min-width: 40px;
        font-size: 2rem;
        display: flex;
        align-items: center;
        justify-content: center;
        margin: 0;
        flex-shrink: 0;
    }

    .file-item-info,
    .file-item .file-name {
        flex: 1;
        min-width: 0;
        overflow: hidden;
    }

    .file-name {
        font-size: 0.9rem;
        font-weight: 500;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        margin: 0;
        text-align: left;
    }

    .file-size {
        font-size: 0.75rem;
        color: var(--text-color-light);
        margin: 0;
        flex-shrink: 0;
        min-width: 50px;
        text-align: right;
    }

    .file-actions-menu {
        display: none;
    }

    .mobile-more-btn {
        display: flex;
    }

    .batch-actions {
        display: flex;
        flex-wrap: wrap;
        gap: 6px;
        padding: 10px;
        background-color: var(--accent-color);
        border-radius: 8px;
        margin-bottom: 12px;
    }

    .batch-actions .button,
    .batch-actions .button-small {
        min-height: 36px;
        padding: 6px 12px;
        font-size: 0.75rem;
        flex: 0 0 auto;
    }

    .breadcrumb-nav {
        padding: 8px 0;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        white-space: nowrap;
        margin-bottom: 8px;
        font-size: 0.8rem;
    }

    .breadcrumb-item {
        min-height: var(--touch-target-min);
        display: inline-flex;
        align-items: center;
        padding: 0 4px;
    }

    .modal-overlay,
    .file-upload-overlay,
    .file-preview-overlay,
    .code-editor-overlay {
        padding: 0;
    }

    .modal-content,
    .upload-content,
    .preview-content,
    .editor-content {
        width: 100%;
        height: 100%;
        max-width: none;
        max-height: none;
        border-radius: 0;
        margin: 0;
    }

    .bottom-sheet {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        max-height: 85vh;
        border-radius: 16px 16px 0 0;
        padding-bottom: var(--safe-area-inset-bottom);
        transform: translateY(100%);
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        background-color: var(--accent-color);
        z-index: 1001;
    }

    .bottom-sheet.visible {
        transform: translateY(0);
    }

    .bottom-sheet-handle {
        width: 36px;
        height: 4px;
        background-color: var(--border-color);
        border-radius: 2px;
        margin: 8px auto 16px;
    }

    .bottom-sheet-header {
        padding: 16px;
        border-bottom: 1px solid var(--border-color);
    }

    .bottom-sheet-title {
        margin: 0;
        font-size: 1rem;
        font-weight: 600;
    }

    .bottom-sheet-content {
        padding: 8px 0;
        max-height: 60vh;
        overflow-y: auto;
    }

    .bottom-sheet-item {
        display: flex;
        align-items: center;
        gap: 16px;
        padding: 14px 20px;
        background: none;
        border: none;
        width: 100%;
        text-align: left;
        font-size: 1rem;
        color: var(--text-color);
        cursor: pointer;
        -webkit-tap-highlight-color: transparent;
    }

    .bottom-sheet-item:active {
        background-color: var(--background-color);
    }

    .bottom-sheet-item.destructive {
        color: #d32f2f;
    }

    .bottom-sheet-icon {
        font-size: 1.25rem;
        width: 28px;
        text-align: center;
    }

    .login-container {
        padding: 16px;
        padding-top: calc(16px + var(--safe-area-inset-top));
    }

    .auth-tabs {
        min-height: var(--touch-target-comfortable);
    }

    .auth-tab {
        min-height: var(--touch-target-comfortable);
        font-size: 1rem;
    }

    .auth-form input {
        height: var(--touch-target-comfortable);
        font-size: 16px;
        padding: 12px 16px;
    }

    .auth-form .button {
        min-height: var(--touch-target-comfortable);
        font-size: 1rem;
    }

    .gallery-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 2px;
    }

    .gallery-item,
    .photo-item {
        aspect-ratio: 1;
    }

    .photo-item img {
        height: 100%;
    }

    .toast-notification {
        left: 12px;
        right: 12px;
        bottom: calc(12px + var(--safe-area-inset-bottom));
        max-width: none;
        transform: translateY(100px);
    }

    .toast-notification.visible {
        transform: translateY(0);
    }

    .billing-container {
        padding: 12px;
    }

    .billing-cards {
        flex-direction: column;
    }

    .billing-card {
        width: 100%;
    }

    .invoice-table-container,
    .user-table-container {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .invoice-table,
    .user-table {
        min-width: 500px;
    }

    .settings-container {
        padding: 12px;
    }

    .settings-section .button {
        width: 100%;
        min-height: var(--touch-target-comfortable);
    }

    .share-modal {
        top: auto;
        bottom: 0;
        left: 0;
        right: 0;
        transform: translateY(100%);
        max-height: 85vh;
        border-radius: 16px 16px 0 0;
        padding-bottom: var(--safe-area-inset-bottom);
    }

    .share-modal.visible {
        transform: translateY(0);
    }

    .share-modal-content {
        padding: 16px;
    }

    .share-form input,
    .share-form select {
        height: var(--touch-target-comfortable);
        font-size: 16px;
    }

    .share-form .button {
        min-height: var(--touch-target-comfortable);
        width: 100%;
    }

    .cookie-consent {
        left: 8px;
        right: 8px;
        bottom: calc(8px + var(--safe-area-inset-bottom));
        padding: 16px;
    }

    .cookie-consent-buttons {
        flex-direction: column;
        gap: 8px;
    }

    .cookie-consent-buttons .button {
        width: 100%;
        min-height: var(--touch-target-min);
    }

    .upload-modal-content,
    .share-modal-content {
        max-height: 90vh;
    }

    .admin-dashboard-container {
        padding: 12px;
    }
}

@media (max-width: 479px) {
    .app-title {
        font-size: 1rem;
    }

    .header-right .button {
        padding: 8px 10px;
        font-size: 0.8rem;
    }

    .file-actions .button {
        font-size: 0.8rem;
        padding: 8px 10px;
    }

    .file-name {
        font-size: 0.85rem;
    }

    .file-size {
        font-size: 0.7rem;
        min-width: 40px;
    }

    .file-icon {
        width: 36px;
        height: 36px;
        min-width: 36px;
        font-size: 1.75rem;
    }

    .batch-actions .button {
        font-size: 0.7rem;
        padding: 5px 8px;
    }

    .gallery-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 1px;
    }

    .breadcrumb-nav {
        font-size: 0.75rem;
    }

    .footer-links li a {
        font-size: 0.55rem;
    }

    .footer-text {
        font-size: 0.55rem;
    }
}

@media (max-width: 359px) {
    .app-header {
        padding: 0 4px;
    }

    .app-title {
        font-size: 0.9rem;
    }

    .header-center {
        margin: 0 4px;
    }

    .search-input {
        font-size: 14px;
        padding: 6px;
    }

    .header-right .button {
        padding: 6px 8px;
        font-size: 0.75rem;
        min-width: 38px;
    }

    .app-main {
        padding: 8px;
    }

    .file-item {
        padding: 8px;
        gap: 8px;
        min-height: 52px;
    }

    .file-icon {
        width: 32px;
        height: 32px;
        min-width: 32px;
        font-size: 1.5rem;
    }

    .file-name {
        font-size: 0.8rem;
    }

    .file-size {
        font-size: 0.65rem;
        min-width: 35px;
    }

    .mobile-more-btn {
        width: 32px;
        height: 32px;
        min-width: 32px;
    }

    .file-actions {
        flex-direction: column;
    }

    .file-actions .button {
        width: 100%;
    }

    .batch-actions {
        padding: 8px;
    }

    .batch-actions .button {
        font-size: 0.65rem;
        padding: 4px 6px;
        min-height: 32px;
    }

    .selection-controls label {
        font-size: 0.7rem;
    }
}

@media (min-width: 480px) and (max-width: 767px) {
    .gallery-grid {
        grid-template-columns: repeat(3, 1fr);
    }

    .file-actions .button {
        flex: 0 1 auto;
    }
}

@media (min-width: 768px) {
    .hamburger-btn {
        display: none;
    }

    .sidebar-overlay {
        display: none;
    }

    .app-sidebar {
        position: relative;
        transform: none;
        width: var(--sidebar-width);
    }

    .file-grid {
        display: grid;
        grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
        background-color: transparent;
        gap: calc(var(--spacing-unit) * 2);
    }

    .file-item {
        flex-direction: column;
        border: 1px solid var(--border-color);
        border-radius: 8px;
    }

    .file-actions-menu {
        display: flex;
    }

    .mobile-more-btn {
        display: none;
    }

    .gallery-grid {
        grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    }
}

@media (min-width: 1024px) {
    .file-grid {
        grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    }

    .gallery-grid {
        grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    }
}

@media (hover: none) and (pointer: coarse) {
    .button:hover,
    .nav-link:hover,
    .file-item:hover {
        background-color: inherit;
        box-shadow: none;
        border-color: var(--border-color);
    }

    .button:active,
    .nav-link:active {
        background-color: rgba(0, 51, 153, 0.1);
    }

    .file-item:active {
        background-color: rgba(0, 51, 153, 0.05);
    }

    * {
        -webkit-tap-highlight-color: transparent;
    }
}

body.dark-mode .hamburger-btn span {
    background-color: var(--text-color);
}

body.dark-mode .hamburger-btn:active {
    background-color: rgba(255, 255, 255, 0.1);
}

body.dark-mode .nav-link:active,
body.dark-mode .button:active {
    background-color: rgba(255, 255, 255, 0.1);
}

body.dark-mode .context-menu,
body.dark-mode .bottom-sheet {
    background-color: #333;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
}

body.dark-mode .context-menu-item:active,
body.dark-mode .bottom-sheet-item:active {
    background-color: rgba(255, 255, 255, 0.1);
}

body.dark-mode .pull-to-refresh-indicator {
    background-color: var(--background-color);
}

body.dark-mode .file-item {
    background-color: var(--accent-color);
}
