html {
    font-size: 14px;
}

@media (min-width: 768px) {
    html {
        font-size: 15px;
    }
}

body {
    margin: 0;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: #f4f6f9;
}

/* Sidebar */
.sidebar {
    height: 100vh;
    width: 260px;
    transition: all 0.3s;
    overflow-y: auto;
    position: fixed;
    top: 0;
    left: 0;
    z-index: 1000;
}

/* Ensure sidebar controls and links remain clickable and sit above page content */
.sidebar {
    z-index: 2000; /* higher than content so links are reachable */
    pointer-events: auto;
}

.sidebar .collapse .nav-link,
.sidebar-group-toggle {
    position: relative;
    z-index: 2100;
    pointer-events: auto;
}

.sidebar.collapsed {
    margin-left: -260px;
}

.sidebar-header {
    background-color: #1a1a2e;
}

.sidebar-nav {
    padding-bottom: 30px !important;
}

.sidebar-link {
    color: #adb5bd !important;
    padding: 8px 16px;
    border-radius: 6px;
    margin: 2px 0;
    font-size: 0.9rem;
    transition: all 0.2s;
}

.sidebar-link:hover, .sidebar-link.active {
    color: #fff !important;
    background-color: rgba(255, 255, 255, 0.1);
}

.sidebar-link.active {
    background-color: rgba(13, 110, 253, 0.3);
    border-left: 3px solid #0d6efd;
}

.sidebar-sub {
    padding-left: 36px !important;
    font-size: 0.84rem;
}

/* Sidebar collapsible groups */
.sidebar-group {
    margin: 2px 0;
}

.sidebar-group-toggle {
    display: flex;
    align-items: center;
    color: #e0e0e0 !important;
    text-decoration: none;
    padding: 9px 16px;
    font-size: 0.8rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-radius: 6px;
    transition: all 0.2s;
}

.sidebar-group-toggle:hover {
    color: #fff !important;
    background: rgba(255, 255, 255, 0.05);
}

.sidebar-chevron {
    font-size: 0.65rem;
    transition: transform 0.3s;
}

.sidebar-group-toggle[aria-expanded="false"] .sidebar-chevron {
    transform: rotate(-90deg);
}

/* Sidebar scrollbar */
.sidebar::-webkit-scrollbar {
    width: 4px;
}

.sidebar::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.15);
    border-radius: 4px;
}

#page-content {
    margin-left: 260px;
    transition: all 0.3s;
    min-height: 100vh;
}

#page-content.expanded {
    margin-left: 0;
}

/* Dashboard Tiles */
.dashboard-tile {
    border: none;
    border-radius: 12px;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    overflow: hidden;
}

.dashboard-tile:hover {
    transform: translateY(-6px) scale(1.02);
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.18);
}

.tile-body {
    padding: 1rem;
    position: relative;
    min-height: 120px;
}

.tile-title {
    font-weight: 700;
    margin-bottom: 6px;
    font-size: 0.95rem;
}

.tile-stat {
    font-size: 0.78rem;
    opacity: 0.9;
}

.tile-footer {
    background: #fff;
    padding: 8px 12px;
    display: flex;
    justify-content: space-between;
}

.tile-icon {
    font-size: 2.5rem;
    opacity: 0.2;
    position: absolute;
    right: 15px;
    top: 15px;
    transition: transform 0.4s ease;
}

.dashboard-tile:hover .tile-icon {
    transform: scale(1.2) rotate(-10deg);
    opacity: 0.35;
}

/* KPI Cards */
.kpi-card {
    border-radius: 16px;
    overflow: hidden;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    position: relative;
}

.kpi-card:hover {
    transform: translateY(-6px);
    box-shadow: 0 12px 35px rgba(0, 0, 0, 0.15);
}

.kpi-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
}

.kpi-income::before { background: linear-gradient(90deg, #28a745, #20c997); }
.kpi-expense::before { background: linear-gradient(90deg, #dc3545, #e74c3c); }
.kpi-savings::before { background: linear-gradient(90deg, #0d6efd, #6610f2); }
.kpi-invest::before { background: linear-gradient(90deg, #fd7e14, #ffc107); }

.kpi-content {
    padding: 20px 20px 10px;
    background: #fff;
}

.kpi-label {
    font-size: 0.78rem;
    text-transform: uppercase;
    font-weight: 700;
    letter-spacing: 0.5px;
    color: #6c757d;
}

.kpi-value {
    font-size: 1.5rem;
    font-weight: 800;
    margin: 4px 0;
    color: #212529;
    font-family: 'Segoe UI', system-ui, sans-serif;
}

.kpi-sub {
    font-size: 0.78rem;
    color: #adb5bd;
}

.kpi-icon-wrap {
    position: absolute;
    top: 18px;
    right: 20px;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.3rem;
    z-index: 1;
}

.kpi-income .kpi-icon-wrap { background: rgba(40, 167, 69, 0.12); color: #28a745; }
.kpi-expense .kpi-icon-wrap { background: rgba(220, 53, 69, 0.12); color: #dc3545; }
.kpi-savings .kpi-icon-wrap { background: rgba(13, 110, 253, 0.12); color: #0d6efd; }
.kpi-invest .kpi-icon-wrap { background: rgba(253, 126, 20, 0.12); color: #fd7e14; }

.kpi-footer {
    background: #f8f9fa;
    padding: 10px 20px;
    font-size: 0.78rem;
    color: #6c757d;
    border-top: 1px solid #eee;
}

/* Chart Card */
.chart-card {
    overflow: hidden;
}

.chart-card .card-header {
    border-bottom: 2px solid #f0f0f0;
}

/* Recent Activity */
.activity-list {
    max-height: 400px;
    overflow-y: auto;
}

.activity-item {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    border-bottom: 1px solid #f0f0f0;
    transition: background 0.2s;
}

.activity-item:hover {
    background: #f8f9fa;
}

.activity-item:last-child {
    border-bottom: none;
}

.activity-icon {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-right: 12px;
    font-size: 0.85rem;
    flex-shrink: 0;
}

.activity-icon.text-success { background: rgba(40, 167, 69, 0.12); }
.activity-icon.text-danger { background: rgba(220, 53, 69, 0.12); }

.activity-details {
    flex: 1;
    min-width: 0;
}

.activity-desc {
    display: block;
    font-weight: 600;
    font-size: 0.85rem;
    color: #212529;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.activity-amount {
    font-size: 0.85rem;
    white-space: nowrap;
    margin-left: 10px;
}

/* Animations */
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(30px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.04); }
}

.animate-in {
    opacity: 0;
    animation: fadeInUp 0.6s ease forwards;
}

/* Scrollbar for activity */
.activity-list::-webkit-scrollbar {
    width: 4px;
}

.activity-list::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 4px;
}

/* Cards */
.card {
    border: none;
    border-radius: 10px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.08);
    /* Ensure cards sit above floating widgets so their buttons remain clickable */
    position: relative;
    z-index: 3000;
}

.card-header {
    border-radius: 10px 10px 0 0 !important;
}

/* Tables */
.table th {
    font-weight: 600;
    font-size: 0.85rem;
    text-transform: uppercase;
    color: #6c757d;
    border-bottom: 2px solid #dee2e6;
}

.table td {
    vertical-align: middle;
}

/* Buttons */
.btn {
    border-radius: 8px;
    font-weight: 500;
}

.btn-lg {
    padding: 12px 24px;
    font-size: 1.1rem;
}

/* Forms */
.form-control, .form-select {
    border-radius: 8px;
    padding: 10px 14px;
}

.form-label {
    font-weight: 600;
    color: #495057;
    font-size: 0.9rem;
}

/* Alert */
.alert {
    border-radius: 10px;
}

/* Amount formatting */
.amount {
    font-weight: 600;
    font-family: 'Consolas', monospace;
}

.amount-positive { color: #28a745; }
.amount-negative { color: #dc3545; }

/* Login Page */
.login-page {
    min-height: 100vh;
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
    display: flex;
    align-items: center;
    justify-content: center;
}

.login-card {
    max-width: 420px;
    width: 100%;
    border-radius: 16px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}

/* Print */
@media print {
    .sidebar, #sidebarToggle, .btn, .no-print {
        display: none !important;
    }

    #page-content {
        margin-left: 0 !important;
    }

    .card {
        box-shadow: none;
        border: 1px solid #ddd;
    }
}

/* Global floating print button */
.global-print-btn {
    position: fixed;
    bottom: 28px;
    right: 120px;
    z-index: 1000;
    border-radius: 10px;
    padding: 10px 16px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.global-print-btn.small {
    padding: 8px 12px;
    right: 100px;
}

/* Report Cards */
.report-card {
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    border: 1px solid #eee;
}

.report-card:hover {
    transform: translateY(-8px);
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.12);
}

.report-icon {
    width: 70px;
    height: 70px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.3s ease;
}

.report-card:hover .report-icon {
    transform: scale(1.15);
}

/* Mobile responsive */
@media (max-width: 768px) {
    .sidebar {
        margin-left: -260px;
    }

    .sidebar.show {
        margin-left: 0;
    }

    #page-content {
        margin-left: 0;
    }

    .dashboard-tile {
        margin-bottom: 10px;
    }
}

/* Section Headers */
.section-header {
    display: flex;
    align-items: center;
    margin-bottom: 12px;
    padding-bottom: 8px;
    border-bottom: 2px solid #e9ecef;
}

.section-header i {
    font-size: 1.1rem;
    margin-right: 8px;
}

.section-header span {
    font-weight: 700;
    font-size: 1rem;
    color: #212529;
}

/* Section Stat Cards */
.section-stat-card {
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.section-stat-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.1);
}

.stat-icon-lg {
    width: 52px;
    height: 52px;
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

/* ═══════ Chatbot Widget ═══════ */
.chatbot-fab {
    position: fixed;
    bottom: 28px;
    right: 28px;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, #0d6efd 0%, #6610f2 100%);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    cursor: pointer;
    box-shadow: 0 6px 25px rgba(13, 110, 253, 0.4);
    z-index: 1100;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    animation: chatPulse 2s ease-in-out infinite;
}

.chatbot-fab:hover {
    transform: scale(1.12);
    box-shadow: 0 8px 35px rgba(13, 110, 253, 0.55);
}

@keyframes chatPulse {
    0%, 100% { box-shadow: 0 6px 25px rgba(13, 110, 253, 0.4); }
    50% { box-shadow: 0 6px 35px rgba(13, 110, 253, 0.65); }
}

.chatbot-window {
    position: fixed;
    bottom: 100px;
    right: 28px;
    width: 390px;
    max-height: 520px;
    background: #fff;
    border-radius: 18px;
    box-shadow: 0 12px 50px rgba(0, 0, 0, 0.2);
    z-index: 1100;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: chatSlideUp 0.3s ease;
}

/* Ensure bootstrap modal appears above sidebar, cards and floating widgets */
.modal-backdrop {
    z-index: 4500 !important;
}
.modal {
    z-index: 4600 !important;
}
.modal .modal-content {
    overflow: visible;
}

/* Ensure card footers and forms are interactive above other fixed elements */
.card-footer, form, .dashboard-tile {
    position: relative;
    z-index: 3001;
    pointer-events: auto;
}

@keyframes chatSlideUp {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

.chatbot-header {
    background: linear-gradient(135deg, #0d6efd 0%, #6610f2 100%);
    color: #fff;
    padding: 14px 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.chatbot-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
}

.chatbot-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    max-height: 360px;
    background: #f8f9fa;
}

.chatbot-messages::-webkit-scrollbar { width: 4px; }
.chatbot-messages::-webkit-scrollbar-thumb { background: #ccc; border-radius: 4px; }

.chat-msg {
    display: flex;
    margin-bottom: 12px;
    animation: msgFadeIn 0.3s ease;
}

@keyframes msgFadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

.chat-msg.user {
    justify-content: flex-end;
}

.chat-bubble {
    max-width: 85%;
    padding: 10px 14px;
    border-radius: 16px;
    font-size: 0.87rem;
    line-height: 1.5;
    word-wrap: break-word;
}

.bot-bubble {
    background: #fff;
    color: #212529;
    border: 1px solid #e9ecef;
    border-top-left-radius: 4px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}

.user-bubble {
    background: linear-gradient(135deg, #0d6efd, #6610f2);
    color: #fff;
    border-top-right-radius: 4px;
}

.chatbot-input {
    display: flex;
    padding: 10px 12px;
    border-top: 1px solid #e9ecef;
    background: #fff;
    gap: 8px;
}

.chatbot-input input {
    flex: 1;
    border-radius: 20px !important;
    font-size: 0.9rem;
    padding: 8px 16px !important;
}

.chatbot-input button {
    border-radius: 50% !important;
    width: 40px;
    height: 40px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.chat-typing {
    display: flex;
    gap: 4px;
    padding: 8px 14px;
}

.chat-typing span {
    width: 8px;
    height: 8px;
    background: #adb5bd;
    border-radius: 50%;
    animation: typingDot 1.4s infinite ease-in-out both;
}

.chat-typing span:nth-child(2) { animation-delay: 0.2s; }
.chat-typing span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingDot {
    0%, 80%, 100% { transform: scale(0.4); opacity: 0.5; }
    40% { transform: scale(1); opacity: 1; }
}

/* Chat link styling */
.bot-bubble a {
    color: #0d6efd;
    text-decoration: underline;
    font-weight: 500;
}

.bot-bubble strong {
    color: #0d6efd;
}

@media (max-width: 480px) {
    .chatbot-window {
        width: calc(100vw - 20px);
        right: 10px;
        bottom: 80px;
        max-height: 70vh;
    }
}