/**
 * UI Enhancements - Shared styles for Låda
 * Hover effects, transitions, loading states, and visual feedback
 */

/* ==========================================================================
   Table Layout Fixes
   ========================================================================== */

/* Ensure table-responsive doesn't cause horizontal overflow */
.table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* Constrain table to container with fixed layout */
.table {
    width: 100%;
    table-layout: fixed;
}

/* Column proportions (total ~100%):
   - Checkbox: 4%
   - Drag handle: 3%
   - Filename: 45%
   - Size: 10%
   - Type: 15%
   - Date: 10%
   - Actions: 13%
*/

.table .checkbox-cell {
    width: 4%;
}

.table .drag-cell {
    width: 3%;
}

.table .filename-cell {
    width: 40%;
    max-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.table .size-cell {
    width: 10%;
    white-space: nowrap;
}

.table .type-cell {
    width: 12%;
    max-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.table .date-cell {
    width: 10%;
    white-space: nowrap;
}

.table .status-cell {
    width: 12%;
    white-space: nowrap;
}

.table .actions-cell {
    width: 13%;
    white-space: nowrap;
}

/* Prevent card content from overflowing */
.card {
    max-width: 100%;
}

/* Ensure card header content wraps properly */
.card-header {
    flex-wrap: wrap;
}

/* ==========================================================================
   Table Row Hover Effects
   ========================================================================== */

.table tbody tr {
    transition: background-color 0.15s ease-in-out;
}

.table tbody tr:hover {
    background-color: rgba(0, 0, 0, 0.02);
}

.table-hover tbody tr:hover {
    background-color: rgba(32, 107, 196, 0.06);
}

/* Clickable table rows */
.table tbody tr.clickable {
    cursor: pointer;
}

.table tbody tr.clickable:hover {
    background-color: rgba(32, 107, 196, 0.08);
}

/* Selected row state */
.table tbody tr.selected {
    background-color: rgba(32, 107, 196, 0.1);
}

.table tbody tr.selected:hover {
    background-color: rgba(32, 107, 196, 0.14);
}

/* ==========================================================================
   Button Enhancements
   ========================================================================== */

.btn {
    transition: all 0.15s ease-in-out;
}

.btn:hover:not(:disabled):not(.disabled) {
    transform: translateY(-1px);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.btn:active:not(:disabled):not(.disabled) {
    transform: translateY(0);
    box-shadow: none;
}

/* Button loading state */
.btn.is-loading {
    pointer-events: none;
    opacity: 0.85;
    cursor: wait;
}

.btn.is-loading .btn-spinner {
    display: inline-block;
}

/* Button success state */
.btn.is-success {
    pointer-events: none;
}

/* Icon buttons (no lift effect) */
.btn-icon:hover:not(:disabled) {
    transform: none;
    box-shadow: none;
}

/* ==========================================================================
   Card Hover Effects
   ========================================================================== */

.card.card-link {
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    cursor: pointer;
}

.card.card-link:hover {
    transform: translateY(-4px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.card.card-link:active {
    transform: translateY(-2px);
}

/* ==========================================================================
   Focus States (Accessibility)
   ========================================================================== */

.btn:focus-visible,
.form-control:focus-visible,
.form-select:focus-visible {
    outline: 2px solid rgba(32, 107, 196, 0.5);
    outline-offset: 2px;
}

/* ==========================================================================
   Form Validation States
   ========================================================================== */

.form-control.is-valid {
    border-color: #2fb344;
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 8 8'%3e%3cpath fill='%232fb344' d='M2.3 6.73.6 4.53c-.4-1.04.46-1.4 1.1-.8l1.1 1.4 3.4-3.8c.6-.63 1.6-.27 1.2.7l-4 4.6c-.43.5-.8.4-1.1.1z'/%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right 0.75rem center;
    background-size: 1rem 1rem;
    padding-right: 2.5rem;
}

.form-control.is-invalid {
    border-color: #d63939;
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12' width='12' height='12' fill='none' stroke='%23d63939'%3e%3ccircle cx='6' cy='6' r='4.5'/%3e%3cpath stroke-linejoin='round' d='M5.8 3.6h.4L6 6.5z'/%3e%3ccircle cx='6' cy='8.2' r='.6' fill='%23d63939' stroke='none'/%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right 0.75rem center;
    background-size: 1rem 1rem;
    padding-right: 2.5rem;
}

.valid-feedback {
    display: block;
    width: 100%;
    margin-top: 0.25rem;
    font-size: 0.875rem;
    color: #2fb344;
}

.invalid-feedback {
    display: block;
    width: 100%;
    margin-top: 0.25rem;
    font-size: 0.875rem;
    color: #d63939;
}

/* ==========================================================================
   Toast Container
   ========================================================================== */

.toast-container {
    z-index: 1080;
}

.toast-container .toast {
    animation: slideInDown 0.3s ease-out;
}

.toast-container .toast.hiding {
    animation: slideOutUp 0.3s ease-out forwards;
}

@keyframes slideInDown {
    from {
        transform: translateY(-100%);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

@keyframes slideOutUp {
    from {
        transform: translateY(0);
        opacity: 1;
    }
    to {
        transform: translateY(-100%);
        opacity: 0;
    }
}

/* ==========================================================================
   Modal Loading Overlay
   ========================================================================== */

.modal-loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.95);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 10;
    border-radius: inherit;
}

/* Modal success state */
.modal-success-state {
    text-align: center;
    padding: 2rem;
}

.modal-success-state .icon-success {
    width: 64px;
    height: 64px;
    color: #2fb344;
    margin-bottom: 1rem;
    animation: scaleIn 0.3s ease-out;
}

@keyframes scaleIn {
    from {
        transform: scale(0);
        opacity: 0;
    }
    to {
        transform: scale(1);
        opacity: 1;
    }
}

/* ==========================================================================
   Dropdown Enhancements
   ========================================================================== */

.dropdown-item {
    transition: background-color 0.15s ease;
}

/* ==========================================================================
   Progress Bar Enhancements
   ========================================================================== */

.progress-bar {
    transition: width 0.3s ease;
}

/* ==========================================================================
   Badge Hover Effects
   ========================================================================== */

.badge.badge-hover {
    transition: transform 0.15s ease, box-shadow 0.15s ease;
    cursor: pointer;
}

.badge.badge-hover:hover {
    transform: scale(1.05);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.15);
}

/* ==========================================================================
   List Group Enhancements
   ========================================================================== */

.list-group-item {
    transition: background-color 0.15s ease;
}

.list-group-item-action:hover {
    background-color: rgba(32, 107, 196, 0.06);
}

/* ==========================================================================
   Skeleton Loading (for future use)
   ========================================================================== */

.skeleton {
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: skeleton-loading 1.5s infinite;
    border-radius: 4px;
}

@keyframes skeleton-loading {
    0% {
        background-position: 200% 0;
    }
    100% {
        background-position: -200% 0;
    }
}

/* ==========================================================================
   Utility Classes
   ========================================================================== */

/* Fade in animation */
.fade-in {
    animation: fadeIn 0.3s ease-out;
}

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

/* Pulse animation for attention */
.pulse {
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.6;
    }
}

/* Smooth collapse transition */
.collapse-smooth {
    transition: max-height 0.3s ease-out, opacity 0.3s ease-out;
    overflow: hidden;
}

/* ==========================================================================
   Mobile Responsive Styles
   ========================================================================== */

/* Mobile folder sidebar toggle button */
.mobile-sidebar-toggle {
    display: none;
    width: 100%;
    margin-bottom: 1rem;
}

/* Mobile-specific header adjustments */
@media (max-width: 767.98px) {
    /* Page header layout */
    .page-header .row.g-2 {
        flex-wrap: wrap;
    }

    .page-header .col-auto.ms-auto {
        width: 100%;
        margin-top: 0.75rem;
        margin-left: 0 !important;
        justify-content: flex-start;
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    /* Hide text labels in header buttons on mobile, show only icons */
    .page-header .btn-text-mobile {
        display: none;
    }

    /* Upload button - keep compact on mobile */
    .page-header .btn-upload-mobile {
        padding: 0.375rem 0.75rem;
    }

    /* Dashboard link - icon only on mobile */
    .page-header .btn-dashboard-mobile .btn-text-mobile {
        display: none;
    }

    /* Show mobile sidebar toggle */
    .mobile-sidebar-toggle {
        display: flex;
        align-items: center;
        justify-content: center;
    }

    /* Mobile sidebar - slide down drawer */
    .col-md-3.mobile-sidebar {
        flex: 0 0 100%;
        max-width: 100%;
        width: 100%;
        margin-bottom: 0.5rem;
        position: relative;
    }

    .mobile-sidebar-collapse {
        position: absolute;
        top: 100%;
        left: 0;
        right: 0;
        z-index: 1050;
        margin-top: 0.25rem;
        box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
        border-radius: 0.5rem;
        overflow: hidden;
        max-height: 0;
        opacity: 0;
        transform: translateY(-10px);
        transition: max-height 0.3s ease-out, opacity 0.2s ease-out, transform 0.3s ease-out;
        pointer-events: none;
    }

    .mobile-sidebar-collapse.show {
        max-height: 70vh;
        opacity: 1;
        transform: translateY(0);
        pointer-events: auto;
    }

    .mobile-sidebar-collapse .card {
        margin: 0;
        border: none;
        border-radius: 0.5rem;
    }

    .mobile-sidebar-collapse .card-header {
        padding: 0.5rem;
    }

    .mobile-sidebar-collapse .card-body {
        padding: 0.75rem;
        max-height: calc(70vh - 60px);
        overflow-y: auto;
    }

    .mobile-sidebar-collapse .folder-tree {
        max-height: none;
    }

    /* Backdrop when drawer is open */
    .mobile-sidebar-backdrop {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.3);
        z-index: 1040;
        opacity: 0;
        visibility: hidden;
        transition: opacity 0.3s ease-out, visibility 0.3s ease-out;
    }

    .mobile-sidebar-backdrop.show {
        opacity: 1;
        visibility: visible;
    }

    /* Make main content full width on mobile */
    .col-md-9 {
        flex: 0 0 100%;
        max-width: 100%;
        width: 100%;
    }

    /* Breadcrumb text size */
    .breadcrumb {
        font-size: 0.8125rem;
    }

    /* Card header tabs - make scrollable */
    .card-header-tabs {
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .card-header-tabs .nav-link {
        white-space: nowrap;
        padding: 0.5rem 0.75rem;
        font-size: 0.875rem;
    }

    /* Hide tab text on very small screens, show icons */
    .nav-tabs .nav-link .tab-text-mobile {
        display: none;
    }

    /* File search in card header - full width on mobile */
    .card-header .ms-auto {
        width: 100%;
        margin-top: 0.75rem;
        margin-left: 0 !important;
        flex-direction: column;
        align-items: stretch !important;
    }

    .card-header #fileSearch {
        width: 100% !important;
        margin-bottom: 0.5rem;
    }

    /* Search scope toggle - compact */
    #searchScopeToggle {
        width: 100%;
    }

    #searchScopeToggle .btn {
        flex: 1;
        font-size: 0.75rem;
        padding: 0.25rem 0.5rem;
    }

    /* Table cells - compact on mobile */
    .table th,
    .table td {
        padding: 0.5rem 0.25rem;
        font-size: 0.8125rem;
    }

    /* Hide less important columns on mobile */
    .table .hide-mobile {
        display: none;
    }

    /* Truncate filename on mobile */
    .table .filename-cell {
        max-width: 120px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    /* Action buttons in table - icon only */
    .table .btn-action-mobile .btn-text {
        display: none;
    }

    .table .btn-action-mobile {
        padding: 0.25rem 0.5rem;
    }

    /* Multi-select indicator - stack elements */
    .multi-select-indicator,
    .multi-select-actions {
        flex-direction: column;
        align-items: stretch !important;
        text-align: center;
    }

    .multi-select-indicator .flex-grow-1,
    .multi-select-actions .flex-grow-1 {
        margin-bottom: 0.5rem;
    }

    .multi-select-actions .btn {
        width: 100%;
        margin-bottom: 0.25rem;
    }

    /* Folder tree - compact on mobile */
    .folder-tree {
        max-height: 200px;
        overflow-y: auto;
    }

    .folder-item {
        padding: 0.375rem;
        font-size: 0.875rem;
    }

    /* Sidebar card - compact on mobile */
    .mobile-sidebar .card {
        min-height: auto !important;
    }

    .mobile-sidebar .card-body {
        padding: 0.75rem;
    }

    /* Modal adjustments */
    .modal-dialog {
        margin: 0.5rem;
    }

    .modal-body {
        padding: 1rem;
    }

    /* Form selectgroup - stack on mobile */
    .form-selectgroup {
        flex-direction: column;
    }

    .form-selectgroup-item {
        margin-bottom: 0.5rem;
    }

    /* Dashboard cards - full width on mobile */
    .col-md-6 {
        padding-left: 0.5rem;
        padding-right: 0.5rem;
    }

    /* Page title - smaller on mobile */
    .page-title {
        font-size: 1.25rem;
    }

    /* Folder action buttons - stack and full width */
    .folder-actions-mobile .btn-group {
        flex-direction: column;
        width: 100%;
    }

    .folder-actions-mobile .btn-group .btn {
        border-radius: 0.25rem !important;
        margin-bottom: 0.25rem;
    }

    .folder-actions-mobile .btn-group .dropdown-toggle-split {
        display: none;
    }

    /* Archive folder buttons - smaller text */
    .archive-folder-buttons .btn {
        font-size: 0.75rem;
        padding: 0.375rem 0.5rem;
    }

    .archive-folder-buttons .btn .icon {
        width: 16px;
        height: 16px;
    }

    /* Search results info - compact */
    #searchResultsInfo {
        padding: 0.5rem;
        font-size: 0.8125rem;
    }

    #searchResultsInfo .d-flex {
        flex-direction: column;
        gap: 0.5rem;
    }

    /* Admin stats cards - 2 per row on mobile */
    .col-lg-3 {
        flex: 0 0 50%;
        max-width: 50%;
    }

    .col-lg-3 .card-body {
        padding: 0.75rem;
    }

    .col-lg-3 .subheader {
        font-size: 0.6875rem;
    }

    .col-lg-3 .h1 {
        font-size: 1.5rem;
    }
}

/* Extra small screens (< 576px) */
@media (max-width: 575.98px) {
    /* Even more compact table */
    .table th,
    .table td {
        padding: 0.375rem 0.25rem;
        font-size: 0.75rem;
    }

    /* Filename column - even shorter */
    .table .filename-cell {
        max-width: 80px;
    }

    /* Page title */
    .page-title {
        font-size: 1.125rem;
    }

    /* Logo smaller */
    .page-header img[alt="Låda"] {
        height: 20px !important;
    }

    /* Buttons in header - icon only, smaller */
    .page-header .btn {
        padding: 0.25rem 0.5rem;
    }

    .page-header .btn .icon {
        width: 18px;
        height: 18px;
    }

    /* Admin stats - 1 per row on very small */
    .col-lg-3.col-sm-6 {
        flex: 0 0 100%;
        max-width: 100%;
    }

    /* Card headers */
    .card-header {
        padding: 0.75rem;
    }

    .card-title {
        font-size: 1rem;
    }

    /* Modals - full screen on very small devices */
    .modal-dialog {
        margin: 0;
        max-width: 100%;
        height: 100%;
    }

    .modal-content {
        height: 100%;
        border: 0;
        border-radius: 0;
    }

    /* Tab navigation - icons only */
    .nav-tabs .nav-link {
        padding: 0.5rem;
    }

    .nav-tabs .nav-link .icon {
        margin: 0;
    }
}

/* Tablet landscape and up - ensure sidebar shows */
@media (min-width: 768px) {
    .mobile-sidebar-collapse {
        display: block !important;
    }

    .mobile-sidebar-toggle {
        display: none !important;
    }
}

/* ==========================================================================
   Preview Modal (Lightbox)
   ========================================================================== */

#previewModal .modal-content {
    overflow: hidden;
}

#previewModal .modal-body {
    padding: 0;
}

#previewModal .modal-body img,
#previewModal .modal-body video {
    max-width: 100%;
    max-height: 80vh;
    object-fit: contain;
}

#previewModal .modal-body iframe {
    width: 100%;
    height: 80vh;
    border: none;
}

#previewModal .modal-body pre {
    width: 100%;
    height: 80vh;
    overflow: auto;
    margin: 0;
    padding: 1rem;
    font-size: 13px;
    line-height: 1.5;
    white-space: pre-wrap;
    word-wrap: break-word;
}

#previewModal .modal-body audio {
    width: 100%;
    max-width: 400px;
}

/* Mobile fullscreen adjustments */
@media (max-width: 991.98px) {
    #previewModal .modal-dialog {
        margin: 0;
        max-width: 100%;
        height: 100%;
    }

    #previewModal .modal-content {
        height: 100%;
        border: 0;
        border-radius: 0;
    }

    #previewModal .modal-body {
        min-height: calc(100vh - 60px);
        height: calc(100vh - 60px);
    }

    #previewModal .modal-body img,
    #previewModal .modal-body video {
        max-height: calc(100vh - 80px);
    }

    #previewModal .modal-body iframe,
    #previewModal .modal-body pre {
        height: calc(100vh - 60px);
    }

    #previewModal .modal-header {
        padding: 0.75rem 1rem;
    }

    #previewModal .modal-title {
        font-size: 0.9375rem;
        max-width: calc(100% - 100px) !important;
    }
}

/* Touch-friendly tap targets */
@media (hover: none) and (pointer: coarse) {
    .btn {
        min-height: 44px;
        min-width: 44px;
    }

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

    .dropdown-item {
        padding: 0.75rem 1rem;
    }

    .form-check-input {
        width: 1.25rem;
        height: 1.25rem;
    }

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

    .nav-link {
        padding: 0.75rem 1rem;
    }
}
