/* ============================================
   BS Task Manager - Mobile-First Styles v1.2
   ============================================ */

:root {
    --mobile-nav-height: 64px;
    --mobile-topbar-height: 52px;
    --mobile-fab-size: 56px;
    --touch-min: 44px;
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-top: env(safe-area-inset-top, 0px);
}

/* Touch-friendly global */
@media (max-width: 991.98px) {
    .btn, .form-control, .form-select, .page-link, .nav-link, .dropdown-item {
        min-height: var(--touch-min);
    }

    .btn-sm {
        min-height: 38px;
        padding: 0.5rem 0.75rem;
    }

    .form-control, .form-select {
        font-size: 16px !important; /* prevent iOS zoom on focus */
        padding: 0.65rem 0.85rem;
    }

    textarea.form-control {
        font-size: 16px !important;
    }

    /* Hide desktop navbar on mobile — use bottom nav */
    .navbar.d-mobile-compact {
        display: none !important;
    }

    /* Page padding for bottom nav + FAB */
    body.has-mobile-nav {
        padding-bottom: calc(var(--mobile-nav-height) + var(--safe-bottom) + 16px);
    }

    .page-content {
        padding-top: 0.75rem !important;
        padding-bottom: calc(var(--mobile-nav-height) + var(--mobile-fab-size) / 2 + 8px) !important;
    }

    .footer {
        display: none !important;
    }

    /* Compact page headers */
    .page-header-desktop h4 {
        font-size: 1.1rem;
    }

    .breadcrumb {
        font-size: 0.8rem;
        margin-bottom: 0.5rem !important;
    }

    /* Hide desktop-only elements */
    .desktop-only { display: none !important; }

    /* Quick filters horizontal scroll */
    .quick-filters {
        display: flex !important;
        flex-wrap: nowrap !important;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        padding-bottom: 4px;
        margin-left: -0.5rem;
        margin-right: -0.5rem;
        padding-left: 0.5rem;
        padding-right: 0.5rem;
    }

    .quick-filters::-webkit-scrollbar { display: none; }

    .quick-filters .btn {
        flex-shrink: 0;
        white-space: nowrap;
    }

    /* Collapsible filter on mobile */
    .filter-bar-mobile-toggle {
        display: flex !important;
    }

    .filter-bar.collapsed-mobile .filter-form-body {
        display: none;
    }

    /* Table → hidden, cards shown */
    .table-desktop { display: none !important; }
    .mobile-card-list { display: block !important; }

    /* Charts smaller on mobile */
    .chart-container { height: 180px; }

    /* Stat cards 2x2 grid */
    .stat-card .fs-2 { font-size: 1.5rem !important; }

    /* Modal full-screen on mobile */
    .modal-fullscreen-sm-down {
        margin: 0;
    }

    #searchModal .modal-dialog {
        margin: 0;
        max-width: 100%;
        height: 100%;
    }

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

    #searchModal .modal-body {
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    #searchResults .search-item {
        padding: 1rem;
        min-height: var(--touch-min);
    }

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

    /* Task detail sticky actions */
    .mobile-sticky-actions {
        display: flex !important;
    }

    /* Pagination touch friendly */
    .pagination .page-link {
        min-width: var(--touch-min);
        text-align: center;
    }

    /* Select status full width on cards */
    .mobile-task-card .status-select {
        width: 100%;
        min-width: unset;
    }
}

@media (min-width: 992px) {
    .mobile-only,
    .mobile-topbar,
    .mobile-bottom-nav,
    .mobile-fab,
    .mobile-card-list,
    .filter-bar-mobile-toggle,
    .mobile-sticky-actions,
    .pull-refresh {
        display: none !important;
    }

    .table-desktop { display: block !important; }
}

/* ---- Mobile Top Bar ---- */
.mobile-topbar {
    position: sticky;
    top: 0;
    z-index: 1030;
    background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 55%, #06b6d4 100%);
    padding-top: var(--safe-top);
    box-shadow: 0 4px 20px rgba(79, 70, 229, 0.25);
}

.mobile-topbar-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: var(--mobile-topbar-height);
    padding: 0 0.5rem 0 1rem;
}

.mobile-page-title {
    color: #fff;
    font-weight: 700;
    font-size: 1.05rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 60vw;
}

.mobile-topbar-actions .btn-link {
    text-decoration: none;
    min-height: var(--touch-min);
    min-width: var(--touch-min);
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

/* ---- Bottom Navigation ---- */
.mobile-bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 1040;
    display: flex;
    align-items: stretch;
    justify-content: space-around;
    height: calc(var(--mobile-nav-height) + var(--safe-bottom));
    padding-bottom: var(--safe-bottom);
    background: rgba(255, 255, 255, 0.92);
    border-top: 1px solid var(--app-border, #e2e8f0);
    box-shadow: 0 -8px 32px rgba(15, 23, 42, 0.08);
    backdrop-filter: blur(16px);
}

.bottom-nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    text-decoration: none;
    color: var(--bs-text-muted);
    font-size: 0.65rem;
    font-weight: 500;
    border: none;
    background: none;
    padding: 6px 4px;
    min-height: var(--touch-min);
    transition: color 0.15s;
    -webkit-tap-highlight-color: transparent;
}

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

.bottom-nav-item.active {
    color: #4f46e5;
}

.bottom-nav-item.active i {
    transform: scale(1.15);
    filter: drop-shadow(0 2px 4px rgba(79, 70, 229, 0.3));
}

.bottom-nav-item:active {
    opacity: 0.7;
}

[data-theme="dark"] .mobile-bottom-nav {
    background: #25282c;
}

/* ---- FAB ---- */
.mobile-fab {
    position: fixed;
    bottom: calc(var(--mobile-nav-height) + var(--safe-bottom) + 12px);
    left: 50%;
    transform: translateX(-50%);
    z-index: 1045;
    width: var(--mobile-fab-size);
    height: var(--mobile-fab-size);
    border-radius: 50%;
    background: linear-gradient(135deg, #4f46e5, #7c3aed);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    box-shadow: 0 8px 24px rgba(79, 70, 229, 0.45);
    text-decoration: none;
    transition: transform 0.2s, box-shadow 0.2s;
    -webkit-tap-highlight-color: transparent;
}

.mobile-fab:active {
    transform: translateX(-50%) scale(0.92);
}

/* ---- Mobile Task Cards ---- */
.mobile-card-list {
    display: none;
    padding: 0.5rem;
}

.mobile-task-card {
    background: var(--bs-card-bg);
    border-radius: 0.75rem;
    padding: 1rem;
    margin-bottom: 0.75rem;
    box-shadow: 0 1px 4px rgba(0,0,0,0.08);
    border-right: 4px solid #6c757d;
    position: relative;
    -webkit-tap-highlight-color: transparent;
}

.mobile-task-card.priority-urgent { border-right-color: #dc3545; }
.mobile-task-card.priority-high   { border-right-color: #fd7e14; }
.mobile-task-card.priority-medium { border-right-color: #0dcaf0; }
.mobile-task-card.priority-low    { border-right-color: #6c757d; }

.mobile-task-card.overdue-row { background: #fff5f5; }
.mobile-task-card.today-row   { background: #fffbeb; }

[data-theme="dark"] .mobile-task-card.overdue-row { background: rgba(220,53,69,0.12); }
[data-theme="dark"] .mobile-task-card.today-row   { background: rgba(255,193,7,0.08); }

.mobile-task-card .card-title-link {
    font-weight: 700;
    font-size: 1rem;
    color: inherit;
    text-decoration: none;
    display: block;
    margin-bottom: 0.5rem;
    line-height: 1.4;
}

.mobile-task-card .card-meta {
    font-size: 0.8rem;
    color: var(--bs-text-muted);
    margin-bottom: 0.5rem;
}

.mobile-task-card .card-badges {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    margin-bottom: 0.65rem;
}

.mobile-task-card .card-actions {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.mobile-task-card .card-actions .btn {
    flex: 1;
}

/* Financial mobile card (legacy fallback) */
.mobile-fin-card {
    display: none;
}

/* ============================================
   Financial Mobile UI
   ============================================ */

.fin-segment-nav {
    display: flex;
    gap: 0.35rem;
    background: var(--bs-card-bg);
    border-radius: 0.875rem;
    padding: 0.35rem;
    margin-bottom: 1rem;
    box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}

.fin-segment-item {
    flex: 1;
    text-align: center;
    padding: 0.65rem 0.5rem;
    border-radius: 0.625rem;
    text-decoration: none;
    color: var(--bs-text-muted);
    font-size: 0.875rem;
    font-weight: 600;
    transition: background 0.15s, color 0.15s;
    -webkit-tap-highlight-color: transparent;
}

.fin-segment-item.active {
    background: #0d6efd;
    color: #fff;
    box-shadow: 0 2px 8px rgba(13,110,253,0.35);
}

.fin-hero-card {
    background: linear-gradient(135deg, #0d6efd 0%, #6610f2 100%);
    border-radius: 1.125rem;
    padding: 1.25rem;
    color: #fff;
    margin-bottom: 1rem;
    box-shadow: 0 8px 24px rgba(13,110,253,0.25);
}

.fin-hero-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
}

.fin-hero-label {
    font-size: 0.875rem;
    opacity: 0.9;
}

.fin-hero-badge {
    background: rgba(220,53,69,0.9);
    font-size: 0.75rem;
    padding: 0.25rem 0.6rem;
    border-radius: 2rem;
    white-space: nowrap;
}

.fin-hero-amount {
    font-size: 1.75rem;
    font-weight: 800;
    line-height: 1.3;
}

.fin-hero-empty {
    opacity: 0.85;
    margin: 0;
    font-size: 0.95rem;
}

.fin-quick-grid {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.fin-quick-card {
    display: flex;
    align-items: center;
    gap: 0.875rem;
    padding: 1rem 1.125rem;
    border-radius: 1rem;
    text-decoration: none;
    color: inherit;
    background: var(--bs-card-bg);
    box-shadow: 0 2px 10px rgba(0,0,0,0.06);
    transition: transform 0.15s;
    -webkit-tap-highlight-color: transparent;
}

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

.fin-quick-icon {
    width: 48px;
    height: 48px;
    border-radius: 0.875rem;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.35rem;
    flex-shrink: 0;
}

.fin-quick-card.primary .fin-quick-icon {
    background: rgba(13,110,253,0.12);
    color: #0d6efd;
}

.fin-quick-card.warning .fin-quick-icon {
    background: rgba(253,126,20,0.12);
    color: #fd7e14;
}

.fin-quick-body {
    flex: 1;
    min-width: 0;
}

.fin-quick-body strong {
    display: block;
    font-size: 1rem;
    margin-bottom: 0.15rem;
}

.fin-quick-body span {
    font-size: 0.8rem;
    color: var(--bs-text-muted);
}

.fin-quick-arrow {
    color: var(--bs-text-muted);
    opacity: 0.6;
}

.fin-action-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.65rem;
    margin-bottom: 1.25rem;
}

.fin-action-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    padding: 0.85rem;
    border-radius: 0.875rem;
    text-decoration: none;
    font-weight: 600;
    font-size: 0.9rem;
    border: 2px solid #0d6efd;
    color: #0d6efd;
    background: transparent;
    -webkit-tap-highlight-color: transparent;
}

.fin-action-btn.primary {
    background: #0d6efd;
    color: #fff;
    border-color: #0d6efd;
}

.fin-action-btn:active { opacity: 0.85; }

.fin-overdue-section {
    margin-top: 0.5rem;
}

.fin-section-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.75rem;
}

.fin-section-head h5 {
    font-size: 1rem;
    margin: 0;
}

.fin-section-head a {
    font-size: 0.875rem;
    text-decoration: none;
}

.fin-filter-pills {
    display: flex;
    gap: 0.5rem;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    margin-bottom: 0.75rem;
    padding-bottom: 2px;
}

.fin-filter-pills::-webkit-scrollbar { display: none; }

.fin-pill {
    flex-shrink: 0;
    padding: 0.5rem 1rem;
    border-radius: 2rem;
    text-decoration: none;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--bs-text-muted);
    background: var(--bs-card-bg);
    border: 1px solid var(--bs-border-color);
    -webkit-tap-highlight-color: transparent;
}

.fin-pill.active {
    background: #0d6efd;
    color: #fff;
    border-color: #0d6efd;
}

.fin-list-card {
    border: none;
    box-shadow: none;
    background: transparent;
}

.fin-list-card .card-body {
    background: transparent;
}

.fin-card-list {
    padding-bottom: 0.5rem !important;
}

/* Financial item card */
.fin-card {
    background: var(--bs-card-bg);
    border-radius: 1rem;
    margin-bottom: 0.75rem;
    box-shadow: 0 2px 8px rgba(0,0,0,0.06);
    overflow: hidden;
    border-right: 4px solid transparent;
}

.fin-card-overdue { border-right-color: #dc3545; }
.fin-card-today   { border-right-color: #ffc107; }
.fin-card-paid    { opacity: 0.6; }

.fin-card-main {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    padding: 1rem 1rem 0.75rem;
    text-decoration: none;
    color: inherit;
    -webkit-tap-highlight-color: transparent;
}

.fin-card-main:active { background: rgba(13,110,253,0.04); }

.fin-card-icon {
    width: 42px;
    height: 42px;
    border-radius: 0.75rem;
    background: rgba(13,110,253,0.1);
    color: #0d6efd;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.15rem;
    flex-shrink: 0;
}

.fin-card-body {
    flex: 1;
    min-width: 0;
}

.fin-card-title {
    font-size: 1rem;
    font-weight: 700;
    margin: 0 0 0.2rem;
    line-height: 1.35;
}

.fin-card-meta {
    font-size: 0.8rem;
    color: var(--bs-text-muted);
    margin: 0;
}

.fin-card-desc {
    font-size: 0.78rem;
    color: var(--bs-text-muted);
    margin: 0.35rem 0 0;
    opacity: 0.85;
}

.fin-card-amount {
    font-weight: 800;
    font-size: 0.95rem;
    white-space: nowrap;
    color: #0d6efd;
    flex-shrink: 0;
    text-align: left;
}

.fin-card-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0 0.75rem 0.75rem;
    border-top: 1px solid var(--bs-border-color);
    margin-top: 0;
}

.fin-paid-toggle {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    padding: 0.6rem;
    border: none;
    border-radius: 0.625rem;
    background: rgba(25,135,84,0.08);
    color: #198754;
    font-size: 0.875rem;
    font-weight: 600;
    min-height: var(--touch-min);
    -webkit-tap-highlight-color: transparent;
}

.fin-paid-toggle.is-paid {
    background: rgba(25,135,84,0.18);
}

.fin-edit-btn {
    width: var(--touch-min);
    height: var(--touch-min);
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 0.625rem;
    border: 1px solid var(--bs-border-color);
    color: var(--bs-text-muted);
    text-decoration: none;
    flex-shrink: 0;
    -webkit-tap-highlight-color: transparent;
}

.fin-edit-btn:active { background: rgba(0,0,0,0.04); }

.fin-recurring {
    color: #0dcaf0;
}

/* ---- Offcanvas bottom menu ---- */
.mobile-offcanvas {
    border-radius: 1.25rem 1.25rem 0 0 !important;
    max-height: 70vh;
}

.mobile-offcanvas .offcanvas-body {
    padding-bottom: calc(1rem + var(--safe-bottom));
}

.mobile-menu-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0.75rem;
}

.mobile-menu-tile {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
    padding: 0.85rem 0.5rem;
    border-radius: 0.75rem;
    background: var(--bs-body-bg);
    text-decoration: none;
    color: inherit;
    font-size: 0.75rem;
    min-height: 72px;
    -webkit-tap-highlight-color: transparent;
}

.mobile-menu-tile i { font-size: 1.5rem; color: #0d6efd; }
.mobile-menu-tile.text-danger i { color: #dc3545; }
.mobile-menu-tile:active { opacity: 0.7; }

[data-theme="dark"] .mobile-menu-tile { background: #1a1d21; }

/* ---- Filter toggle button ---- */
.filter-bar-mobile-toggle {
    display: none;
    width: 100%;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
}

/* ---- Sticky actions (task detail) ---- */
.mobile-sticky-actions {
    display: none;
    position: fixed;
    bottom: calc(var(--mobile-nav-height) + var(--safe-bottom));
    left: 0;
    right: 0;
    padding: 0.5rem 1rem;
    background: var(--bs-card-bg);
    border-top: 1px solid var(--bs-border-color);
    z-index: 1035;
    gap: 0.5rem;
}

.mobile-sticky-actions .btn { flex: 1; }

/* ---- Pull to refresh ---- */
.pull-refresh {
    position: fixed;
    top: calc(var(--mobile-topbar-height) + var(--safe-top));
    left: 50%;
    transform: translateX(-50%) translateY(-120%);
    z-index: 1020;
    background: var(--bs-card-bg);
    padding: 0.5rem 1rem;
    border-radius: 2rem;
    box-shadow: 0 2px 12px rgba(0,0,0,0.15);
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.85rem;
    transition: transform 0.2s;
    pointer-events: none;
}

.pull-refresh.visible {
    transform: translateX(-50%) translateY(8px);
}

.pull-refresh.spin i {
    animation: spin 0.8s linear infinite;
}

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

/* ---- Financial hub ---- */
.fin-hub-tile {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 2rem 1rem;
    border-radius: 1rem;
    text-decoration: none;
    color: inherit;
    background: var(--bs-card-bg);
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
    min-height: 140px;
    transition: transform 0.15s;
    -webkit-tap-highlight-color: transparent;
}

.fin-hub-tile:active { transform: scale(0.97); }

.fin-hub-tile i {
    font-size: 2.5rem;
    margin-bottom: 0.75rem;
}

.fin-hub-tile.primary i { color: #0d6efd; }
.fin-hub-tile.warning i { color: #fd7e14; }

.fin-hub-tile small {
    display: block;
    margin-top: 0.35rem;
    font-size: 0.8rem;
}

/* ---- Offcanvas bottom menu ---- */
@media (max-width: 991.98px) {
    .login-wrapper {
        padding: 1rem;
        align-items: flex-start;
        padding-top: max(2rem, var(--safe-top));
    }

    .login-card {
        margin-top: 10vh;
    }

    .login-card .form-control {
        font-size: 16px !important;
    }
}

/* ---- Swipe hint ---- */
.swipe-scroll-x {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}

.swipe-scroll-x::-webkit-scrollbar { display: none; }

/* Reduce motion */
@media (prefers-reduced-motion: reduce) {
    .page-content, .mobile-task-card, .note-item { animation: none; }
}

@media (max-width: 991.98px) {
    body.has-mobile-sticky .page-content {
        padding-bottom: calc(var(--mobile-nav-height) + 60px + var(--safe-bottom)) !important;
    }

    .table-responsive { font-size: 0.875rem; }
    .quick-filters { overflow-x: auto; flex-wrap: nowrap !important; }
}
