/* ==========================================================================
   LEDGERLY DARK THEME - Space gray with blue accents
   ========================================================================== */

html, body {
    height: 100%;
}

body {
    background-color: #181A1B;
    color: #E2E8F0; /* High contrast light gray for body text */
    min-height: 100vh;
}

.dashboard-main {
    width: 100%;
    padding-bottom: 1.5rem;
}

/* ==========================================================================
   TUG-OF-WAR PROGRESS BAR - Visual balance indicator (Income vs Expenses)
   ========================================================================== */

.tug-bar-wrapper {
    margin-bottom: 1rem;
}

.tug-bar {
    /* Visual balance indicator between income/expense */
    position: relative;
    height: 24px;
    border-radius: 999px;
    background: rgba(24, 26, 27, 0.75);
    overflow: hidden;
    box-shadow: inset 0 0 0 1px rgba(59, 130, 246, 0.35);
}

@media (min-width: 992px) and (max-width: 1399.98px) {
    .dashboard-main {
        padding-bottom: 0.5rem;
    }
}

/* ==========================================================================
   COMPONENT STYLING - Cards, Navigation, Modals
   ========================================================================== */

.navbar, .card, .dropdown-menu, .modal-content {
    background-color: #23272A !important;
    color: #E2E8F0 !important; /* High contrast light gray */
    border-color: rgba(59, 130, 246, 0.35) !important;
}

.card {
    box-shadow:
        0 18px 36px rgba(15, 23, 42, 0.45),
        0 0 18px rgba(59, 130, 246, 0.18),
        inset 0 1px 0 rgba(255, 255, 255, 0.05),
        inset 0 -1px 0 rgba(15, 23, 42, 0.55);
    border-radius: 18px;
    border-width: 1px !important;
}

.card-title, .navbar-brand, .navbar-text, h1, h2, h3, h4, h5, h6 {
    color: #3B82F6 !important;
}

.btn-primary, .btn-outline-primary {
    background-color: #3B82F6 !important;
    border-color: #3B82F6 !important;
    color: #fff !important;
}

.btn-outline-secondary, .btn-secondary {
    background-color: #23272A !important;
    border-color: #3B82F6 !important;
    color: #3B82F6 !important;
}

/* Enhanced button focus and hover states for accessibility */
.btn:focus,
.btn:focus-visible {
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.6) !important;
    outline: none !important;
}

.btn-outline-secondary:hover,
.btn-outline-secondary:focus {
    background-color: #3B82F6 !important;
    border-color: #3B82F6 !important;
    color: #ffffff !important;
}

.btn-outline-secondary:active {
    background-color: #2563EB !important;
    border-color: #2563EB !important;
    color: #ffffff !important;
}

.list-group-item {
    background-color: #23272A !important;
    color: #E2E8F0 !important; /* High contrast light gray */
    border-color: #3B82F6 !important;
}

input, select, textarea {
    background-color: #23272A !important;
    color: #E2E8F0 !important; /* High contrast light gray */
    border-color: #3B82F6 !important;
    transition: border-color 0.2s ease, box-shadow 0.2s ease !important;
}

/* Enhanced form control focus states */
input:focus,
select:focus,
textarea:focus {
    border-color: #60A5FA !important;
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.25) !important;
    outline: none !important;
}

hr, .dropdown-divider {
    border-top: 1px solid #3B82F6 !important;
}

a, .text-decoration-none {
    color: #3B82F6 !important;
    transition: color 0.2s ease !important;
}

/* Enhanced link focus and hover states */
a:hover,
a:focus,
.text-decoration-none:hover,
.text-decoration-none:focus {
    color: #60A5FA !important; /* Lighter blue on hover */
    text-decoration: underline !important;
}

a:focus,
.text-decoration-none:focus {
    outline: 2px solid rgba(59, 130, 246, 0.6) !important;
    outline-offset: 2px !important;
}

::-webkit-input-placeholder { color: #CBD5E1; } /* Lighter gray for placeholders */
::-moz-placeholder { color: #CBD5E1; }
:-ms-input-placeholder { color: #CBD5E1; }
::placeholder { color: #CBD5E1; }

/* WCAG compliant text color overrides */
.text-secondary {
    color: #CBD5E1 !important; /* Lighter gray for secondary text */
}

.text-muted {
    color: #9CA3AF !important; /* Accessible muted text */
}

/* Ensure all small text has good contrast */
.small {
    color: inherit;
}

/* Override Bootstrap text utilities for better contrast */
.text-dark {
    color: #E2E8F0 !important;
}

/* Alert styling: keep text dark and close button steady for readability */
.alert {
    color: #0f172a !important;
}

.alert a {
    color: #0f172a !important;
    font-weight: 600;
    text-decoration: underline;
}

.btn-close {
    filter: none !important;
    opacity: 0.75 !important;
    background-size: 1em !important;
    width: 1.25em !important;
    height: 1.25em !important;
    transition: opacity 0.2s ease !important;
}

.modal .btn-close {
    filter: invert(92%) sepia(12%) saturate(356%) hue-rotate(182deg)
        brightness(112%) contrast(96%) !important;
    opacity: 0.85 !important;
}

.modal .btn-close:hover,
.modal .btn-close:focus {
    opacity: 1 !important;
}

.btn-close:hover,
.btn-close:focus {
    opacity: 1 !important;
}

.btn-close:focus {
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.5) !important;
}

.alert.alert-dismissible {
    position: relative;
}

.alert.alert-dismissible .btn-close {
    position: absolute;
    top: 50%;
    right: 0.75rem;
    transform: translateY(-50%);
}

/* I tweak the scrollbars so they match the theme. */
::-webkit-scrollbar {
    width: 8px;
    height: 6px;
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: #3B82F6;
    border-radius: 9999px;
}
::-webkit-scrollbar-track {
    background: transparent;
    border-radius: 9999px;
}

* {
    scrollbar-width: thin;
    scrollbar-color: #3B82F6 transparent;
}

.dashboard-scroll-320 {
    max-height: 320px;
    overflow-y: auto;
}

.dashboard-scroll-260 {
    height: 260px;
    overflow-y: auto;
}

.dashboard-top-grid {
    display: grid;
    gap: 1.25rem;
    grid-auto-rows: minmax(0, 1fr);
    width: 100%;
}

.dashboard-top-grid__item {
    min-width: 0;
    width: 100%;
}

.dashboard-top-grid__chart {
    order: -1;
}

/* ==========================================================================
   TRANSACTION CHART COMPONENT - Chart.js income/expense visualization
   ========================================================================== */

.dashboard-chart {
    /* Fixed height container for Chart.js canvas */
    position: relative;
    width: 100%;
    min-height: 240px;
    height: 240px;
}

.dashboard-chart__canvas {
    width: 100%;
    height: 240px !important;
    min-height: 240px;
}

.dashboard-chart__empty {
    position: absolute;
    inset: 0;
    padding: 1.75rem;
    text-align: center;
    background: rgba(15, 23, 42, 0.55);
    border: 1px dashed rgba(59, 130, 246, 0.22);
    border-radius: 1rem;
    backdrop-filter: blur(4px);
}

.dashboard-chart--empty .dashboard-chart__canvas {
    display: none;
}

.dashboard-chart-toggle {
    width: 100%;
}

.dashboard-chart-toggle .btn {
    white-space: nowrap;
    width: 50%;
}

/* Mobile separator between Spend History and Top Expenses */
.dashboard-mobile-separator {
    height: 1px;
    background: linear-gradient(90deg, transparent 0%, rgba(59, 130, 246, 0.35) 50%, transparent 100%);
    border: none;
    margin: 1.5rem 0;
}



@media (max-width: 420px) {
    .dashboard-mobile-separator {
        margin: 2rem 0;
        background: linear-gradient(90deg, transparent 10%, rgba(59, 130, 246, 0.5) 50%, transparent 90%);
    }
}

/* Make quick action buttons tall enough for two lines of text at all screen sizes */
.btn[data-bs-target="#addIncomeModal"],
.btn[data-bs-target="#addExpenseModal"],
.btn[data-bs-target="#cycleStartModal"] {
    padding: 1rem 1rem;
    height: 72px;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    line-height: 1.2;
}

/* Rotate chart x-axis labels for better spacing */
.dashboard-chart__canvas {
    font-size: 12px;
}

/* Chart.js x-axis label rotation - this will be handled in JavaScript */

/* Hide mobile digest sections at 991px and below */
@media (max-width: 991px) {
    .dashboard-mobile-digest.d-lg-none {
        display: none !important;
    }
}


.dashboard-chart-toggle__button {
    background-color: rgba(15, 23, 42, 0.45) !important;
    color: #E2E8F0 !important;
    border-width: 1px;
    transition: transform 0.2s ease, box-shadow 0.2s ease, background-color 0.2s ease, color 0.2s ease;
}

.dashboard-chart-toggle__button--income {
    border-color: rgba(59, 130, 246, 0.55) !important;
    background-color: rgba(59, 130, 246, 0.18) !important;
    color: rgba(219, 234, 254, 0.9) !important;
    box-shadow: inset 0 0 12px rgba(59, 130, 246, 0.18);
}

.dashboard-chart-toggle__button--expense {
    border-color: rgba(239, 68, 68, 0.65) !important;
    background-color: rgba(239, 68, 68, 0.2) !important;
    color: rgba(254, 226, 226, 0.92) !important;
    box-shadow: inset 0 0 12px rgba(239, 68, 68, 0.18);
}

.dashboard-chart-toggle__button--income.active {
    background-color: #3B82F6 !important;
    color: #0f172a !important;
    box-shadow:
        0 12px 24px rgba(59, 130, 246, 0.28),
        inset 0 0 0 1px rgba(15, 23, 42, 0.25);
    transform: translateY(-1px);
}

.dashboard-chart-toggle__button--expense.active {
    background-color: #EF4444 !important;
    color: #fff !important;
    box-shadow:
        0 12px 24px rgba(239, 68, 68, 0.28),
        inset 0 0 0 1px rgba(15, 23, 42, 0.25);
    transform: translateY(-1px);
}

.dashboard-chart-toggle__button:not(.active):hover,
.dashboard-chart-toggle__button:not(.active):focus-visible {
    transform: translateY(-1px);
}

/* Enhanced focus rings for chart toggle buttons */
.dashboard-chart-toggle__button:focus,
.dashboard-chart-toggle__button:focus-visible {
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.6) !important;
    outline: none !important;
}

.dashboard-chart-toggle__button--income:not(.active):hover,
.dashboard-chart-toggle__button--income:not(.active):focus-visible {
    background-color: rgba(59, 130, 246, 0.22) !important;
}

.dashboard-chart-toggle__button--expense:not(.active):hover,
.dashboard-chart-toggle__button--expense:not(.active):focus-visible {
    background-color: rgba(239, 68, 68, 0.24) !important;
}

.dashboard-chart-toggle.is-disabled {
    opacity: 0.65;
    pointer-events: none;
}

.dashboard-mobile-digest {
    margin-top: 0;
    padding-top: 0.75rem;
    border-top: 1px solid rgba(148, 163, 184, 0.25);
    height: 100%;
}

.dashboard-mobile-digest__columns {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 1.25rem;
    position: relative;
}

.dashboard-mobile-digest__columns::before {
    content: "";
    position: absolute;
    top: 0;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 1px;
    background: linear-gradient(
        180deg,
        rgba(148, 163, 184, 0.45) 0%,
        rgba(148, 163, 184, 0.05) 100%
    );
}

.dashboard-mobile-digest__section {
    gap: 0.75rem;
    padding-right: 0.5rem;
    padding-left: 0.5rem;
}

.dashboard-mobile-digest__list {
    max-height: 260px;
    overflow-y: auto;
    padding-right: 0.25rem;
}

@media (max-width: 767.98px) {
    .dashboard-chart,
    .dashboard-chart__canvas {
        min-height: 180px;
    }

    .dashboard-chart-toggle {
        width: 100%;
        justify-content: center;
    }

    .dashboard-chart-toggle__button {
        width: 50%;
        display: inline-block;
    }
}

@media (max-width: 420px) {
    .dashboard-mobile-digest__columns {
        grid-template-columns: 1fr;
    }

    .dashboard-mobile-digest__columns::before {
        display: none;
    }

    .dashboard-mobile-digest__section {
        padding-left: 0;
        padding-right: 0;
    }
}

.dashboard-top-grid:last-of-type {
    grid-template-columns: 1fr;
}

@media (min-width: 768px) {
    .dashboard-bottom-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (min-width: 768px) and (max-width: 1023.98px) {
    .dashboard-top-grid:first-of-type {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }

    .dashboard-top-grid:first-of-type .dashboard-top-grid__chart {
        grid-column: 1 / -1;
    }
}

@media (min-width: 1024px) {
    .dashboard-top-grid:first-of-type {
        grid-template-columns: minmax(0, 2fr) repeat(3, minmax(0, 1fr));
    }

    .dashboard-top-grid:first-of-type .dashboard-top-grid__chart {
        grid-column: 1;
    }
}

.min-w-0 {
    min-width: 0;
}

.tug-bar-wrapper {
    width: 100%;
}

.tug-bar {
    position: relative;
    height: 24px;
    border-radius: 999px;
    background: rgba(24, 26, 27, 0.75);
    overflow: hidden;
    box-shadow: inset 0 0 0 1px rgba(59, 130, 246, 0.35);
}

.tug-bar__income,
.tug-bar__expense {
    position: absolute;
    top: 0;
    bottom: 0;
    width: var(--percent, 0);
    transition: width 0.4s ease;
}

.tug-bar__income {
    right: 0;
    background: linear-gradient(
        270deg,
        rgba(59, 130, 246, 0.9) 0%,
        rgba(59, 130, 246, 0.45) 100%
    );
    box-shadow: 0 0 18px rgba(59, 130, 246, 0.35);
}

.tug-bar__expense {
    left: 0;
    background: linear-gradient(
        90deg,
        rgba(239, 68, 68, 0.9) 0%,
        rgba(239, 68, 68, 0.45) 100%
    );
    box-shadow: 0 0 18px rgba(239, 68, 68, 0.35);
}

.tug-bar__empty {
    position: absolute;
    inset: 0;
    text-align: center;
    background: rgba(24, 26, 27, 0.65);
    backdrop-filter: blur(2px);
    border-radius: inherit;
    padding-top: 4px;
}

.calendar-button-icon {
    width: 1.125rem;
    height: 1.125rem;
    filter: invert(88%) sepia(12%) saturate(321%) hue-rotate(182deg)
        brightness(114%) contrast(95%);
    transition: filter 0.2s ease;
}

.btn:hover .calendar-button-icon,
.btn:focus .calendar-button-icon {
    filter: invert(99%) sepia(6%) saturate(218%) hue-rotate(175deg)
        brightness(120%) contrast(100%);
}

.calendar-modal {
    background: rgba(15, 23, 42, 0.95);
    border: 1px solid rgba(59, 130, 246, 0.35);
    box-shadow:
        0 28px 60px rgba(8, 47, 73, 0.55),
        0 0 24px rgba(59, 130, 246, 0.25),
        inset 0 1px 0 rgba(255, 255, 255, 0.05);
    color: #E2E8F0;
    backdrop-filter: blur(16px);
}

.calendar-modal .modal-header,
.calendar-modal .modal-body {
    background: transparent;
}

.calendar-modal .btn-close {
    filter: invert(1);
}

.calendar-modal__content {
    color: inherit;
}

.calendar-modal .btn-outline-secondary,
.calendar-modal .btn-outline-success,
.calendar-modal .btn-outline-danger {
    color: #E2E8F0 !important;
    border-color: rgba(148, 163, 184, 0.35) !important;
    background-color: rgba(15, 23, 42, 0.3) !important;
}

.calendar-modal .btn-outline-secondary:hover,
.calendar-modal .btn-outline-success:hover,
.calendar-modal .btn-outline-danger:hover {
    background-color: rgba(59, 130, 246, 0.12) !important;
    border-color: rgba(59, 130, 246, 0.6) !important;
}

.modal-content input[type="date"] {
    color-scheme: light;
    position: relative;
}

.modal-content input[type="date"]::-webkit-calendar-picker-indicator {
    filter: invert(66%) sepia(78%) saturate(748%) hue-rotate(179deg) brightness(105%) contrast(102%);
    opacity: 0.95;
    cursor: pointer;
    transition: filter 0.2s ease, opacity 0.2s ease;
}

.modal-content input[type="date"]:hover::-webkit-calendar-picker-indicator,
.modal-content input[type="date"]:focus-visible::-webkit-calendar-picker-indicator {
    filter: invert(86%) sepia(37%) saturate(847%) hue-rotate(352deg) brightness(110%) contrast(105%);
    opacity: 1;
}

.form-control[type="date"]::-webkit-calendar-picker-indicator {
    filter: invert(72%) sepia(32%) saturate(612%) hue-rotate(188deg)
        brightness(112%) contrast(98%);
    opacity: 0.9;
    cursor: pointer;
    transition: filter 0.2s ease, opacity 0.2s ease;
}

.form-control[type="date"]:hover::-webkit-calendar-picker-indicator,
.form-control[type="date"]:focus-visible::-webkit-calendar-picker-indicator {
    filter: invert(88%) sepia(28%) saturate(834%) hue-rotate(182deg)
        brightness(120%) contrast(102%);
    opacity: 1;
}

.calendar-weekdays {
    display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr));
    gap: 0.5rem;
    text-transform: uppercase;
    font-size: 0.7rem;
    letter-spacing: 0.12em;
    color: #94A3B8;
    text-align: center;
}

.calendar-grid {
    display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr));
    gap: 0.75rem;
    width: 100%;
}

@media (max-width: 576px) {
    .calendar-grid {
        gap: 0.5rem;
    }
}

.calendar-day {
    position: relative;
    min-height: 4.25rem;
    width: 100%;
    border-radius: 1rem;
    background: linear-gradient(160deg, rgba(30, 41, 59, 0.78) 0%, rgba(15, 23, 42, 0.6) 100%);
    border: 1px solid rgba(148, 163, 184, 0.22);
    padding: 0.7rem 0.6rem;
    text-align: left;
    color: #E2E8F0;
    cursor: pointer;
    transition: border-color 0.2s ease, box-shadow 0.2s ease, transform 0.2s ease;
}
.calendar-day:hover {
    border-color: rgba(59, 130, 246, 0.55);
    box-shadow: 0 8px 18px rgba(30, 64, 175, 0.2);
    transform: translateY(-1px);
}

.calendar-day:focus-visible {
    outline: none;
    border-color: rgba(59, 130, 246, 0.9);
    box-shadow:
        0 0 0 1px rgba(59, 130, 246, 0.9),
        0 12px 28px rgba(59, 130, 246, 0.35);
}

.calendar-day.is-selected {
    border-color: rgba(59, 130, 246, 0.85);
    box-shadow:
        0 0 0 1px rgba(59, 130, 246, 0.85),
        0 12px 28px rgba(59, 130, 246, 0.35);
}

.calendar-day.is-today::after {
    content: "";
    position: absolute;
    inset: 6px;
    border-radius: 0.75rem;
    border: 1px dashed rgba(148, 163, 184, 0.65);
    pointer-events: none;
}

.calendar-day.is-selected.is-today::after {
    border-color: rgba(59, 130, 246, 0.85);
}

.calendar-day__number {
    font-size: 1rem;
    font-weight: 600;
    letter-spacing: 0.02em;
}

.calendar-day__badge {
    position: absolute;
    top: 0.55rem;
    right: 0.6rem;
    padding: 0.1rem 0.45rem;
    border-radius: 999px;
    background: rgba(59, 130, 246, 0.85);
    color: #0f172a;
    font-size: 0.7rem;
    font-weight: 600;
    box-shadow: 0 0 10px rgba(59, 130, 246, 0.4);
}

.calendar-day--empty {
    background: transparent;
    border: none;
    pointer-events: none;
}

.calendar-transactions__list {
    background: rgba(15, 23, 42, 0.55);
    border: 1px solid rgba(148, 163, 184, 0.25);
    border-radius: 1rem;
    padding: 0.75rem;
    max-height: 45vh;
    overflow-y: auto;
}

.calendar-transactions__list .list-group-item {
    border-color: rgba(148, 163, 184, 0.18) !important;
}

.calendar-modal .js-calendar-empty {
    color: #94A3B8;
}

.calendar-transactions__list .list-group-item:last-child {
    border-bottom: none;
}

.site-footer {
    background: rgba(17, 20, 24, 0.9);
    border-top: 1px solid rgba(59, 130, 246, 0.35);
    color: #94A3B8;
    padding: 1.5rem 0;
    margin-top: auto;
}

.site-footer__brand {
    font-size: 1rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: #3B82F6;
}

.site-footer__social {
    padding: 0;
}

.site-footer__link {
    color: #E2E8F0 !important;
    text-decoration: none;
    font-size: 0.85rem;
    font-weight: 500;
    letter-spacing: 0.04em;
    transition: color 0.2s ease, transform 0.2s ease, opacity 0.2s ease;
    display: inline-block;
}

.site-footer__link:hover,
.site-footer__link:focus-visible {
    color: #3B82F6 !important;
    transform: translateY(-1px);
    opacity: 0.9;
}

.site-footer__link span[aria-hidden="true"] {
    font-weight: 600;
    font-size: 0.85rem;
}
