/* Master Stylesheet for Personal Finance App */

:root {
    /* --- LIGHT MODE --- */
    --bg-app: #F5F7FA;
    --bg-surface: #FFFFFF;
    --text-primary: #252A34;
    --text-secondary: #788195;
    --brand-pos: #08D9D6;
    --text-brand-pos-readable: #009E9B;
    /* Readable Teal for Light Mode */
    --brand-neg: #FF2E63;

    /* Mapping to BS variables where possible, or using custom */
    --bg-body: var(--bg-app);
    --bg-card: var(--bg-surface);
    --text-main: var(--text-primary);
    --text-muted: var(--text-secondary);
    --border-color: var(--text-secondary);
    /* Defined border */
    --shadow-color: rgba(0, 0, 0, 0.05);

    /* Bootstrap Overrides */
    --bs-primary: var(--brand-pos);
    --bs-danger: var(--brand-neg);
}

[data-bs-theme="dark"] {
    /* --- DARK MODE --- */
    --bg-app: #252A34;
    --bg-surface: #2F3640;
    --text-primary: #EAEAEA;
    --text-secondary: #959FA8;
    --brand-pos: #08D9D6;
    /* Same Neon Cyan */
    --text-brand-pos-readable: #08D9D6;
    /* Keep Neon in Dark Mode */
    --brand-neg: #FF2E63;
    /* Same Neon Pink */

    --bg-body: var(--bg-app);
    --bg-card: var(--bg-surface);
    --text-main: var(--text-primary);
    --text-muted: var(--text-secondary);
    --border-color: var(--text-secondary);
    --shadow-color: rgba(0, 0, 0, 0.25);

    /* Bootstrap Overrides */
    --bs-primary: var(--brand-pos);
    --bs-danger: var(--brand-neg);
    --bs-body-bg: var(--bg-app);
    --bs-body-color: var(--text-primary);
}

/* --- COMPONENT STYLES --- */

/* Primary Button: Cyan Background, Dark Text */
.btn-primary {
    background-color: var(--brand-pos) !important;
    border-color: var(--brand-pos) !important;
    color: #252A34 !important;
    /* Always dark */
    font-weight: 600;
}

/* Button Outline Primary Override (Cyan) */
.btn-outline-primary {
    color: var(--brand-pos);
    border-color: var(--brand-pos);
}

.btn-outline-primary:hover {
    background-color: var(--brand-pos);
    border-color: var(--brand-pos);
    color: #252A34;
    /* Dark text on hover */
}

.btn-primary:hover {
    filter: brightness(0.9);
}

/* Secondary Button: Outline Style */
.btn-secondary {
    background-color: transparent !important;
    border: 1px solid var(--text-secondary) !important;
    color: var(--text-secondary) !important;
}

.btn-secondary:hover {
    background-color: transparent !important;
    border-color: var(--brand-pos) !important;
    color: var(--brand-pos) !important;
}

/* Sidebar / Nav: Always Dark */
.navbar {
    background-color: #252A34 !important;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1) !important;
}

.navbar-brand,
.navbar {
    background-color: #252A34;
    /* Dark Gunmetal */
}

.navbar-nav .nav-link {
    color: #EAEAEA !important;
    /* Force Light Text */
}

.navbar-nav .nav-link:hover {
    color: #08D9D6 !important;
    /* Glow Cyan on hover */
}

.navbar-nav .nav-link.active {
    color: #08D9D6 !important;
    /* Brand Cyan */
    font-weight: bold;
}

.navbar-toggler-icon {
    filter: invert(1);
}

.navbar-toggler {
    border-color: #788195;
    /* Make the box visible */
}

.btn-link {
    color: #FFFFFF !important;
}

.nav-link.active {
    color: var(--brand-pos) !important;
    font-weight: 700;
}

/* Text Secondary Override */
.text-secondary {
    color: var(--text-secondary) !important;
}

/* Force topnav to dark even in light mode contexts if needed */
[data-bs-theme="light"] .navbar {
    background-color: #252A34 !important;
}

/* Input Fields */
.form-control,
.form-select {
    background-color: var(--bg-surface) !important;
    border: 1px solid var(--text-secondary) !important;
    color: var(--text-primary) !important;
}

.form-control:focus,
.form-select:focus {
    border-color: var(--brand-pos) !important;
    box-shadow: 0 0 0 0.25rem rgba(8, 217, 214, 0.25) !important;
}

.form-check-input:checked {
    background-color: var(--brand-pos);
    border-color: var(--brand-pos);
}

/* Cards / Containers */
.card {
    background-color: var(--bg-surface);
    border: none;
    box-shadow: 0 2px 8px var(--shadow-color);
}

/* Text & Brand Utilities */
.text-brand-pos {
    color: var(--brand-pos) !important;
}

.text-brand-pos-readable {
    color: var(--text-brand-pos-readable) !important;
}

.text-brand-neg {
    color: var(--brand-neg) !important;
}

.bg-brand-pos {
    background-color: var(--brand-pos) !important;
}

.bg-brand-neg {
    background-color: var(--brand-neg) !important;
}

/* Widgets Styling */
.widget-income {
    border-top: 4px solid var(--brand-pos);
}

.widget-expense {
    border-top: 4px solid var(--brand-neg);
}

.border-brand-pos {
    border-color: var(--brand-pos) !important;
}

.border-brand-neg {
    border-color: var(--brand-neg) !important;
}

/* Border Top Utilities */
.border-top-brand-pos {
    border-top: 4px solid var(--brand-pos) !important;
}

.border-top-brand-neg {
    border-top: 4px solid var(--brand-neg) !important;
}

.border-start-brand-pos {
    border-left: 4px solid var(--brand-pos) !important;
}

/* Hover Text Utilities */
.text-hover-brand-pos:hover {
    color: var(--brand-pos) !important;
}

.text-hover-brand-neg:hover {
    color: var(--brand-neg) !important;
}

/* Global Styles */
body {
    background-color: var(--bg-body);
    color: var(--text-main);
    padding-bottom: 80px;
    /* Ensure content doesn't get hidden behind the fixed footer widget */
}

/* Utility Classes */
.cursor-pointer {
    cursor: pointer;
}

/* Dashboard Styles */
.spark-dot:hover {
    opacity: 1 !important;
    r: 5;
}

/* Horizontal Scroll for Widgets */
.widget-scroll-container {
    display: flex;
    flex-wrap: nowrap;
    overflow-x: auto;
    padding-bottom: 1rem;
    gap: 1rem;
    -webkit-overflow-scrolling: touch;
    /* Smooth scroll on iOS */
}

.widget-card-wrapper {
    flex: 0 0 auto;
    width: 85%;
    /* Mobile: 1 card + peek */
}

@media (min-width: 768px) {
    .widget-card-wrapper {
        width: 19%;
        /* Desktop: ~5 cards */
    }
}

/* Alert Overrides (Card Style) */
.alert {
    background-color: var(--bg-surface) !important;
    border: none !important;
    border-left: 4px solid var(--brand-pos) !important;
    color: var(--text-primary) !important;
    box-shadow: 0 2px 8px var(--shadow-color) !important;
    border-radius: 0.375rem !important;
}

.alert-danger {
    border-left-color: var(--brand-neg) !important;
}

/* Input Icon Wrapper */
.input-icon-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}

.input-icon-wrapper .form-control {
    padding-right: 2rem;
    /* Make room for the icon */
}

/* The overlay button */
.input-icon-wrapper .action-icon {
    position: absolute;
    right: 5px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-secondary);
    opacity: 0.5;
    transition: all 0.2s ease-in-out;
    background: transparent;
    border: none;
    padding: 0;
    pointer-events: auto;
    /* clickable */
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.input-icon-wrapper .form-control:focus+.action-icon,
.input-icon-wrapper .action-icon:hover {
    color: var(--brand-pos);
    opacity: 1;
}

/* Progress Bar Track Visibility Fix */
.progress {
    background-color: rgba(0, 0, 0, 0.1);
}

[data-bs-theme="light"] .progress {
    background-color: #D1D5DB;
    /* Darker grey to contrast with table hover */
}

[data-bs-theme="dark"] .progress {
    background-color: rgba(255, 255, 255, 0.1);
}

/* Transactions Styles - Responsive Table */
@media (max-width: 768px) {
    .table-responsive table {
        background: transparent !important;
    }

    .table-responsive thead {
        display: none;
    }

    .table-responsive tbody tr {
        display: block;
        margin-bottom: 0.5rem;
        background: var(--bg-card) !important;
        /* Override striped rows */
        border: 1px solid var(--border-color);
        border-radius: 0.5rem;
        box-shadow: 0 1px 2px var(--shadow-color);
        padding: 0.5rem;
        /* Compact padding */
    }

    .table-responsive td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        border: none;
        padding: 0.25rem 0;
        /* Compact row spacing */
        border-bottom: 1px solid var(--border-light);
    }

    .table-responsive td:last-child {
        border-bottom: none;
        justify-content: flex-end;
        padding-top: 0.5rem;
    }

    .table-responsive td::before {
        content: attr(data-label);
        font-weight: 600;
        color: var(--text-muted);
        font-size: 0.8rem;
        margin-right: 1rem;
    }

    /* Hide empty labels if needed */
    .table-responsive td[data-label="Actions"]::before {
        display: none;
    }
}

/* Portfolio Styles - Responsive Table (Shared with Transactions but kept for clarity/specificity if needed) */
/* Note: The styles are identical to transactions, so we can rely on the shared media query above. */
/* If specific portfolio overrides are needed, add them here. */

/* Planning Styles - Responsive Table */
@media (max-width: 768px) {

    /* Reuse shared table styles where possible, add specific overrides */
    .table-responsive td form {
        width: 100%;
        justify-content: flex-end;
    }

    .table-responsive td form input {
        width: auto !important;
        max-width: 120px;
    }

    /* Hide tfoot on mobile as it doesn't fit the card layout well */
    .table-responsive tfoot {
        display: none;
    }
}

/* Accounts Styles - Responsive Table */
@media (max-width: 768px) {

    /* Force table to not be like tables anymore */
    #accountsTable,
    #accountsTable tbody,
    #accountsTable th,
    #accountsTable td,
    #accountsTable tr {
        display: block;
    }

    /* Hide table headers (but not display: none;, for accessibility) */
    #accountsTable thead {
        display: none;
    }

    #accountsTable tr {
        margin-bottom: 1rem;
        border: 1px solid var(--border-color);
        border-radius: 0.5rem;
        background-color: var(--bg-card);
        box-shadow: 0 0.125rem 0.25rem var(--shadow-color);
    }

    #accountsTable td {
        /* Behave  like a "row" */
        border: none;
        border-bottom: 1px solid var(--border-light);
        position: relative;
        padding-left: 50%;
        text-align: right;
        padding-top: 0.5rem;
        padding-bottom: 0.5rem;
    }

    #accountsTable td:last-child {
        border-bottom: 0;
    }

    #accountsTable td:before {
        /* Now like a table header */
        position: absolute;
        /* Top/left values mimic padding */
        top: 0.5rem;
        left: 1rem;
        width: 45%;
        padding-right: 10px;
        white-space: nowrap;
        text-align: left;
        font-weight: bold;
        content: attr(data-label);
        color: var(--text-muted);
    }

    /* Adjust actions column */
    #accountsTable td:last-child {
        text-align: center;
        padding-left: 0;
    }

    #accountsTable td:last-child:before {
        display: none;
    }
}

/* Chat Widget Styles */
#chat-widget-container {
    position: fixed;
    bottom: 0;
    right: 20px;
    z-index: 1050;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
}

#chat-fab {
    display: none !important;
}

#chat-window {
    width: 380px;
    border-radius: 10px 10px 0 0;
    overflow: hidden;
    margin-bottom: 0;
    transition: height 0.4s cubic-bezier(0.16, 1, 0.3, 1), transform 0.3s;
    height: 50px;
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
    display: flex;
    flex-direction: column;
}


/* Tab Toggles (Segmented/Outline Style) */
/* Tab Toggles (Segmented/Outline Style) */
.btn-tab {
    display: inline-block;
    background: transparent !important;
    border: none !important;
    border-bottom: 3px solid transparent !important;
    color: var(--text-secondary) !important;
    font-weight: 500;
    padding: 0.25rem 0.6rem;
    border-radius: 0 !important;
    transition: all 0.2s ease-in-out;
    opacity: 0.6;
}

.btn-tab.active,
.btn-tab:active,
.btn-tab:hover {
    color: var(--text-primary) !important;
    opacity: 1;
}

.btn-tab.active {
    font-weight: 700;
}

/* Specific Active Colors */
.btn-tab-cyan.active {
    border-bottom-color: var(--brand-pos) !important;
}

.btn-tab-pink.active {
    border-bottom-color: var(--brand-neg) !important;
}

/* Support for btn-check + btn-tab (Segmented Control Logic) */
.btn-check:checked+.btn-tab {
    color: var(--text-primary) !important;
    font-weight: 700;
    opacity: 1;
}

.btn-check:checked+.btn-tab-cyan {
    border-bottom-color: var(--brand-pos) !important;
}

.btn-check:checked+.btn-tab-pink {
    border-bottom-color: var(--brand-neg) !important;
}

/* Chat Widget Styling (Finance Assistant) */
#chat-window .card-header {
    background-color: #252A34 !important;
    /* Dark Gunmetal */
    color: var(--brand-pos) !important;
    /* Neon Cyan */
    border-bottom: 1px solid var(--brand-pos) !important;
    /* Border for glow */
    height: 50px;
    padding-bottom: 16px;
    padding-top: 16px;
    border-radius: 10px 10px 0 0 !important;
    /* Match container radius to prevent corners */
}

#chat-window.chat-open .card-header {
    border-bottom: 1px solid rgba(8, 217, 214, 0.3) !important;
}

/* Adjust icons inside chat header */
#chat-window .card-header i {
    color: var(--brand-pos) !important;
}

/* Override close button to be cyan-ish or white */
#chat-window .btn-close-white {
    filter: invert(1) grayscale(100%) brightness(200%);
}

#chat-window.chat-open {
    height: 600px;
    box-shadow: 0 -5px 30px rgba(0, 0, 0, 0.2) !important;
}

#chat-window.chat-open .chat-controls {
    display: block;
}

#chat-window.chat-open .chat-collapsed-icon {
    display: none;
}

#chat-window .card-body {
    display: none;
    flex: 1;
    height: auto !important;
    opacity: 0;
    transition: opacity 0.3s;
}

#chat-window.chat-open .card-body {
    display: flex;
    opacity: 1;
    min-height: 0;
}

#chat-messages {
    overflow-y: auto;
    min-height: 0;
    scroll-behavior: smooth;
}

.chat-collapsed-icon {
    display: block;
}

.chat-controls {
    display: none;
}

/* Message Bubbles */
.chat-message.user-message {
    text-align: right;
}

.chat-message.user-message .d-inline-block {
    background-color: var(--brand-pos) !important;
    color: #252A34 !important;
    /* Dark text on Cyan */
}

.chat-message.bot-message {
    text-align: left;
}

.chat-bubble-content p {
    margin-bottom: 0.5rem;
}

.chat-bubble-content p:last-child {
    margin-bottom: 0;
}

.chat-bubble-content ul,
.chat-bubble-content ol {
    margin-bottom: 0.5rem;
    padding-left: 1.2rem;
}

.spinner-dots>span {
    display: inline-block;
    width: 8px;
    height: 8px;
    margin: 0 2px;
    background-color: #333;
    border-radius: 50%;
    animation: bounce 1.4s infinite ease-in-out both;
}

.spinner-dots .bounce1 {
    animation-delay: -0.32s;
}

.spinner-dots .bounce2 {
    animation-delay: -0.16s;
}

@keyframes bounce {

    0%,
    80%,
    100% {
        transform: scale(0);
    }

    40% {
        transform: scale(1.0);
    }
}

/* Sidebar List Group Active State */
.list-group-item.active {
    background-color: var(--brand-pos) !important;
    border-color: var(--brand-pos) !important;
    color: #252A34 !important;
    font-weight: 600;
}