/* ======================================================
   FileShare PWA — Mobile-First Styles
   ====================================================== */

/* ── CSS Custom Properties ── */
:root {
    --fs-primary: #0d6efd;
    --fs-primary-dark: #0a58ca;
    --fs-dark: #1a1d21;
    --fs-nav-height: 56px;
    --fs-bottom-nav-height: 64px;
    --fs-safe-bottom: env(safe-area-inset-bottom, 0px);
    --fs-radius: 0.75rem;
    --fs-radius-lg: 1rem;
    --fs-shadow: 0 2px 8px rgba(0,0,0,0.08);
    --fs-shadow-lg: 0 4px 16px rgba(0,0,0,0.12);
    --fs-transition: 0.2s ease;
}

/* ── Reset & Base ── */
*,
*::before,
*::after {
    -webkit-tap-highlight-color: transparent;
}

html {
    text-size-adjust: 100%;
    scroll-behavior: smooth;
}

body {
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    -webkit-font-smoothing: antialiased;
    overscroll-behavior-y: contain;
}

main {
    flex: 1;
}

/* Safe area padding for PWA standalone mode */
.pwa-standalone main.has-bottom-nav {
    padding-top: env(safe-area-inset-top, 0px);
}

/* ── Top Navbar ── */
.top-navbar {
    position: sticky;
    top: 0;
    z-index: 1030;
}

.navbar-brand {
    font-weight: 700;
    font-size: 1.15rem;
    letter-spacing: -0.01em;
}

/* ── Mobile Bottom Navigation ── */
.mobile-bottom-nav {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: calc(var(--fs-bottom-nav-height) + var(--fs-safe-bottom));
    padding-bottom: var(--fs-safe-bottom);
    background: #fff;
    border-top: 1px solid rgba(0,0,0,0.08);
    box-shadow: 0 -2px 10px rgba(0,0,0,0.06);
    z-index: 1040;
    align-items: center;
    justify-content: space-around;
}

.mobile-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
    padding: 6px 0;
    color: #6c757d;
    text-decoration: none;
    font-size: 0.65rem;
    font-weight: 500;
    transition: color var(--fs-transition);
    min-width: 0;
    position: relative;
}

.mobile-nav-item i {
    font-size: 1.35rem;
    margin-bottom: 2px;
    line-height: 1;
}

.mobile-nav-item.active {
    color: var(--fs-primary);
}

.mobile-nav-item.active::before {
    content: '';
    position: absolute;
    top: 0;
    left: 25%;
    right: 25%;
    height: 3px;
    background: var(--fs-primary);
    border-radius: 0 0 3px 3px;
}

.mobile-nav-upload i {
    font-size: 1.7rem;
    color: var(--fs-primary);
}

.mobile-nav-upload.active i {
    color: var(--fs-primary-dark);
}

/* Mobile "More" Menu */
.mobile-more-menu {
    max-height: 60vh;
    border-radius: var(--fs-radius-lg) var(--fs-radius-lg) 0 0;
}

.mobile-more-menu .list-group-item {
    padding: 0.875rem 1.25rem;
    font-size: 1rem;
    border: none;
    border-bottom: 1px solid rgba(0,0,0,0.05);
}

.mobile-more-menu .list-group-item i {
    font-size: 1.2rem;
    width: 1.5rem;
    text-align: center;
}

/* ── PWA Install Banner ── */
.pwa-install-banner {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 1060;
    padding: 0 12px 12px;
    transform: translateY(100%);
    opacity: 0;
    transition: transform 0.35s cubic-bezier(0.22, 1, 0.36, 1),
                opacity 0.35s ease;
    pointer-events: none;
}

.pwa-install-banner.show {
    transform: translateY(0);
    opacity: 1;
    pointer-events: auto;
}

.has-bottom-nav ~ .pwa-install-banner,
.pwa-install-banner.has-nav-offset {
    bottom: calc(var(--fs-bottom-nav-height) + var(--fs-safe-bottom) + 4px);
}

.pwa-install-banner-content {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    background: #fff;
    border-radius: var(--fs-radius-lg);
    box-shadow: 0 4px 24px rgba(0,0,0,0.15), 0 0 0 1px rgba(0,0,0,0.05);
}

.pwa-install-banner-icon {
    width: 44px;
    height: 44px;
    border-radius: var(--fs-radius);
    background: linear-gradient(135deg, var(--fs-primary), var(--fs-primary-dark));
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.3rem;
    flex-shrink: 0;
}

.pwa-install-banner-text {
    flex: 1;
    min-width: 0;
    line-height: 1.3;
}

.pwa-install-banner-text strong {
    display: block;
    font-size: 0.95rem;
}

.pwa-install-banner-text small {
    display: block;
    color: #6c757d;
    font-size: 0.78rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.pwa-install-banner-actions {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
}

.pwa-install-btn {
    white-space: nowrap;
    font-weight: 600;
    border-radius: 20px;
    padding: 6px 18px;
    font-size: 0.85rem;
}

.pwa-dismiss-btn {
    padding: 4px 6px;
    font-size: 1rem;
    line-height: 1;
    text-decoration: none;
}

/* ── iOS Install Instructions ── */
.ios-install-steps {
    text-align: left;
    margin: 0 auto;
    max-width: 260px;
}

.ios-step {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 0;
    font-size: 0.92rem;
}

.ios-step + .ios-step {
    border-top: 1px solid rgba(0,0,0,0.06);
}

.ios-step-num {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--fs-primary);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    font-weight: 700;
    flex-shrink: 0;
}

/* Bottom nav spacing for content */
.has-bottom-nav {
    /* Replaced by JS/media query below */
}

/* ── Card Improvements ── */
.card {
    border: none;
    box-shadow: var(--fs-shadow);
    border-radius: var(--fs-radius);
    overflow: hidden;
}

.card-header {
    background-color: #f8f9fa;
    border-bottom: 1px solid rgba(0,0,0,0.06);
    font-weight: 600;
}

.card.border-danger {
    border: 1px solid #dc3545 !important;
}

/* ── Upload Zone ── */
.upload-zone {
    cursor: pointer;
    transition: all 0.3s ease;
    background-color: #f8f9fa;
    border-radius: var(--fs-radius);
}

.upload-zone:hover,
.upload-zone.dragover {
    border-color: var(--fs-primary) !important;
    background-color: #e7f1ff;
    transform: scale(1.01);
}

.upload-zone input[type="file"] {
    position: absolute;
    left: -9999px;
}

.border-dashed {
    border-style: dashed !important;
}

/* ── File Icons ── */
.file-icon {
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
}

/* ── Table Improvements ── */
.table th {
    font-weight: 600;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    white-space: nowrap;
}

.table td {
    vertical-align: middle;
}

/* Prevent table cell overflow on all screens */
.table td {
    max-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Name/title column should use available space */
.table .col-name {
    max-width: none;
}

/* Detail info tables: prevent overflow */
.table-sm td {
    word-break: break-all;
    max-width: none;
}

.table-sm code {
    word-break: break-all;
    font-size: 0.75em;
}

/* Actions column: prevent wrapping */
.table .col-actions {
    white-space: nowrap;
    max-width: none;
    overflow: visible;
}

/* ── Mobile Meta Line (shown inside name cell on small screens) ── */
.file-meta {
    display: none;
    margin-top: 0.25rem;
    font-size: 0.72rem;
    color: #6c757d;
    gap: 0.15rem 0.5rem;
    flex-wrap: wrap;
    align-items: center;
    line-height: 1.4;
}

.file-meta span::before {
    content: '·';
    margin-right: 0.5rem;
    color: #adb5bd;
}

.file-meta span:first-child::before {
    content: none;
}

@media (max-width: 767.98px) {
    .file-meta {
        display: flex;
    }
}

/* ── Login Page ── */
.card.shadow {
    box-shadow: var(--fs-shadow-lg) !important;
}

/* ── Filter Panel ── */
.filter-panel {
    background-color: #f8f9fa;
}

/* ── Pagination ── */
.pagination {
    margin-bottom: 0;
}

/* ── Alerts ── */
.alert {
    border-radius: var(--fs-radius);
    border: none;
    box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}

/* ── Buttons ── */
.btn {
    border-radius: 0.5rem;
    font-weight: 500;
    transition: all var(--fs-transition);
}

.btn-group-sm > .btn {
    padding: 0.3rem 0.55rem;
    border-radius: 0.375rem;
}

.btn-primary {
    box-shadow: 0 2px 4px rgba(13, 110, 253, 0.3);
}

.btn-primary:active {
    transform: scale(0.97);
}

.btn-danger {
    box-shadow: 0 2px 4px rgba(220, 53, 69, 0.3);
}

/* ── Footer ── */
.footer {
    margin-top: auto;
}

/* ── Code Styling ── */
code {
    font-size: 0.85em;
    color: #d63384;
    background-color: #f8f9fa;
    padding: 0.125rem 0.25rem;
    border-radius: 0.25rem;
}

/* ── Badge Improvements ── */
.badge {
    font-weight: 500;
    border-radius: 0.375rem;
}

/* ── Form Styling ── */
.form-control,
.form-select {
    border-radius: 0.5rem;
    padding: 0.5rem 0.875rem;
    border-color: #dee2e6;
    transition: border-color var(--fs-transition), box-shadow var(--fs-transition);
}

.form-control:focus,
.form-select:focus {
    border-color: #86b7fe;
    box-shadow: 0 0 0 0.2rem rgba(13, 110, 253, 0.15);
}

/* Larger touch targets for form controls on mobile */
@media (pointer: coarse) {
    .form-control,
    .form-select {
        min-height: 44px;
        font-size: 1rem;
    }
}

/* ── Empty State ── */
.empty-state {
    padding: 3rem 1.5rem;
    text-align: center;
}

.empty-state i {
    font-size: 4rem;
    color: #dee2e6;
}

/* ── Breadcrumbs ── */
.breadcrumb {
    font-size: 0.875rem;
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    -ms-overflow-style: none;
    white-space: nowrap;
    padding: 0.5rem 0.75rem;
}

.breadcrumb::-webkit-scrollbar {
    display: none;
}

.breadcrumb-item + .breadcrumb-item::before {
    padding: 0 0.35rem;
}

/* ── Preview Containers ── */
.ratio-1x1 {
    --bs-aspect-ratio: 100%;
}

/* ── Bulk Actions Bar ── */
.bulk-actions-bar .card-body {
    background: #fff3cd;
    border-radius: var(--fs-radius);
}

/* ── Drag and Drop ── */
.drag-item {
    cursor: grab;
}

.drag-item:active {
    cursor: grabbing;
}

.drop-target.drag-over {
    outline: 2px dashed #ffc107;
    background-color: #fff8e1 !important;
}

.drag-item.dragging {
    opacity: 0.4;
}

.folder-option:hover,
.folder-option.active {
    background-color: #fff3cd;
}

/* ── Note Content ── */
.note-content {
    line-height: 1.7;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

/* ── Offcanvas for mobile ── */
.offcanvas-bottom {
    border-radius: var(--fs-radius-lg) var(--fs-radius-lg) 0 0;
}

/* ======================================================
   RESPONSIVE: Mobile-first breakpoints
   ====================================================== */

/* ── Small screens (< 576px) ── */
@media (max-width: 575.98px) {
    .container {
        padding-left: 1rem;
        padding-right: 1rem;
    }

    h2 {
        font-size: 1.35rem;
    }

    /* Page headers: stack on mobile */
    .d-flex.justify-content-between.align-items-center.mb-3,
    .d-flex.justify-content-between.align-items-center.mb-4 {
        flex-direction: column;
        align-items: flex-start !important;
        gap: 0.75rem;
    }

    /* Make action buttons full width on mobile */
    .d-flex.justify-content-between.align-items-center.mb-3 > .d-flex.gap-2,
    .d-flex.justify-content-between.align-items-center.mb-4 > a.btn {
        width: 100%;
    }

    .d-flex.justify-content-between.align-items-center.mb-3 > .d-flex.gap-2 .btn,
    .d-flex.justify-content-between.align-items-center.mb-4 > a.btn {
        flex: 1;
    }

    /* Table responsive improvements */
    .table-responsive {
        font-size: 0.8rem;
        margin-left: -1rem;
        margin-right: -1rem;
        padding-left: 0;
        padding-right: 0;
        border: none;
        overflow-x: hidden;
    }

    .table td, .table th {
        padding: 0.5rem 0.4rem;
    }

    /* Compact action buttons on small screens */
    .btn-group-sm > .btn {
        padding: 0.25rem 0.35rem;
        font-size: 0.75rem;
    }

    /* Hide button text on mobile, keep icons */
    .btn-group-sm > .btn .btn-text {
        display: none;
    }

    /* Filter panel: stack fields */
    .card-body .row.g-3 > [class*="col-md"] {
        flex: 0 0 100%;
        max-width: 100%;
    }

    /* Bulk actions: stack on mobile */
    .bulk-actions-bar .card-body {
        flex-direction: column;
        gap: 0.5rem;
        padding: 0.5rem !important;
    }

    .bulk-actions-bar .btn-group {
        width: 100%;
        flex-wrap: wrap;
    }

    .bulk-actions-bar .btn-group .btn {
        flex: 1;
        font-size: 0.75rem;
    }

    /* Cards */
    .card {
        border-radius: 0.625rem;
    }

    /* File detail: stack columns */
    .row > .col-md-8,
    .row > .col-md-4 {
        padding-left: 0;
        padding-right: 0;
    }

    /* Login card: improve sizing */
    .col-md-4 .card.shadow {
        margin-top: 1rem !important;
    }

    /* Alerts */
    .alert {
        font-size: 0.875rem;
        padding: 0.75rem 1rem;
    }

    /* Upload zone */
    .upload-zone {
        padding: 2rem 1rem !important;
    }

    .upload-zone .fs-1 {
        font-size: 2.5rem !important;
    }
}

/* ── Medium screens (< 768px) — Tablet portrait ── */
@media (max-width: 767.98px) {
    /* Show bottom nav, hide top nav toggler items */
    .mobile-bottom-nav {
        display: flex;
    }

    /* Space for bottom nav */
    main.has-bottom-nav {
        padding-bottom: calc(var(--fs-bottom-nav-height) + var(--fs-safe-bottom) + 1rem);
    }

    footer.has-bottom-nav {
        padding-bottom: calc(var(--fs-bottom-nav-height) + var(--fs-safe-bottom));
    }

    /* Hide desktop navbar toggler content on mobile — keep brand visible */
    .top-navbar .navbar-toggler {
        display: none;
    }

    .top-navbar .collapse.navbar-collapse {
        display: none !important;
    }

    /* Make navbar simpler on mobile */
    .top-navbar {
        padding: 0.5rem 0;
    }

    .top-navbar .container {
        justify-content: center;
    }

    .top-navbar .navbar-brand {
        margin: 0;
        font-size: 1.1rem;
    }

    /* File list: hide less important columns — handled by d-none d-md-table-cell in templates */

    /* Note/secret list: hide less important columns — handled by d-none d-md-table-cell in templates */

    /* Detail pages: stack layout */
    .col-md-8 {
        margin-bottom: 1rem;
    }

    /* Modal: nearly full width */
    .modal-dialog {
        margin: 0.5rem;
    }

    /* Card header action buttons */
    .card-header .btn-group {
        display: flex;
        gap: 0.25rem;
    }

    .card-header .btn-sm {
        padding: 0.35rem 0.6rem;
        font-size: 0.8rem;
    }

    /* Card header: allow wrapping so filename + buttons don't overflow */
    .card-header.d-flex {
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    .card-header.d-flex h5 {
        min-width: 0;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        flex: 1 1 0;
    }

    /* Breadcrumbs: prevent overflow */
    .breadcrumb {
        flex-wrap: wrap;
        font-size: 0.85rem;
    }
}

/* ── Medium+ screens (>= 768px) ── */
@media (min-width: 768px) {
    /* Bottom nav hidden on desktop */
    .mobile-bottom-nav {
        display: none !important;
    }

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

    /* Install banner sits at bottom on desktop (no nav offset) */
    .pwa-install-banner {
        bottom: 0 !important;
        padding: 0 1rem 1rem;
        max-width: 420px;
        left: auto;
        right: 1rem;
    }
}

/* ── Large screens (>= 992px) ── */
@media (min-width: 992px) {
    .top-navbar .navbar-toggler {
        display: inline-flex;
    }

    .top-navbar .collapse.navbar-collapse {
        display: flex !important;
    }

    .table th,
    .table td {
        padding: 0.75rem;
    }
}

/* ── PWA Standalone enhancements ── */
.pwa-standalone .top-navbar {
    padding-top: env(safe-area-inset-top, 0px);
}

.pwa-standalone .mobile-bottom-nav {
    padding-bottom: env(safe-area-inset-bottom, 0px);
}

/* ── Touch-friendly improvements ── */
@media (pointer: coarse) {
    /* Larger tap targets */
    .btn {
        min-height: 42px;
        min-width: 42px;
    }

    .btn-sm,
    .btn-group-sm > .btn {
        min-height: 36px;
        min-width: 36px;
    }

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

    .list-group-item {
        padding: 0.875rem 1.25rem;
    }

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

    /* Larger pagination buttons */
    .page-link {
        padding: 0.625rem 1rem;
    }

    /* Table rows taller for touch */
    .table td {
        padding-top: 0.65rem;
        padding-bottom: 0.65rem;
    }
}

/* ── Pull-to-refresh prevention in standalone ── */
.pwa-standalone body {
    overscroll-behavior-y: contain;
}

/* ── iOS rubber-banding fix ── */
@supports (min-height: -webkit-fill-available) {
    body {
        min-height: -webkit-fill-available;
    }

    html {
        height: -webkit-fill-available;
    }
}

/* ── Dark mode support (follows system) ── */
@media (prefers-color-scheme: dark) {
    :root {
        color-scheme: dark;
    }

    /* Only apply dark mode for the offline page or when the user has dark system preference */
    .offline-container {
        background: linear-gradient(135deg, #0d1117 0%, #161b22 100%);
    }
}

/* ── Print Styles ── */
@media print {
    .mobile-bottom-nav,
    .top-navbar,
    .btn-group,
    .bulk-actions-bar,
    footer {
        display: none !important;
    }

    main {
        padding: 0 !important;
        margin: 0 !important;
    }

    .card {
        box-shadow: none;
        border: 1px solid #dee2e6;
    }
}

/* ── Animation: Smooth page transitions ── */
.main-content {
    animation: fadeIn 0.2s ease-out;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(4px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ── Accessibility ── */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }
}

:focus-visible {
    outline: 2px solid var(--fs-primary);
    outline-offset: 2px;
}
