/* =========================================================
   FINANCE PAGE — Professional Agro Insights Style
   ========================================================= */

/* ── Group-by dropdown ── */

/* ── Date range picker ── */
.finance-date-range .DateRangePicker,
.finance-date-range .DateRangePickerInput {
    height: 34px !important;
    border-radius: 6px !important;
}

.finance-date-range .DateInput,
.finance-date-range .DateInput_input {
    height: 34px !important;
    line-height: 34px !important;
    padding-top: 0 !important;
    padding-bottom: 0 !important;
    font-size: 0.85rem !important;
}

/* ── Accumulated switch ── */

/* ── Tabs ── */
#finance-tabs .nav-tabs {
    border-bottom: 2px solid #dde2ea;
}

#finance-tabs .nav-link {
    font-size: 0.88rem;
    font-weight: 500;
    color: #64748b;
    border: none;
    border-bottom: 2px solid transparent;
    border-radius: 0;
    padding: 0.5rem 1.25rem;
    transition: color 0.15s ease, border-color 0.15s ease;
    margin-bottom: -2px;
}

#finance-tabs .nav-link:hover {
    color: #177da5;
    border-bottom-color: #177da5;
    background: transparent;
}

#finance-tabs .nav-link.active {
    color: #177da5 !important;
    border-bottom: 2px solid #177da5 !important;
    font-weight: 600 !important;
    background: transparent !important;
}

/* ── Graph cards ── */
#finance-tabs .card {
    border: 1px solid #dde2ea !important;
    border-radius: 10px !important;
    box-shadow: 0 1px 4px rgba(15,23,42,0.07) !important;
}

#finance-tabs .card-body {
    padding: 0.75rem !important;
}

/* ── Finance inline toolbar (inside tab, not a Navbar) ── */

/* agro-toolbar-section-label, agro-toolbar-pill, agro-toolbar-divider
   → defined globally in app.css */

/* ── Sales metric toggle (Hectares / $) ── */

/* Graph controls match the other improved pages. */
#finance-tabs .js-plotly-plot .plotly .modebar {
    opacity: 1;
    background: rgba(255,255,255,0.96) !important;
    border: 1px solid #dbe5df;
    border-radius: 6px;
}
#finance-tabs .js-plotly-plot .plotly .modebar-group {
    background: transparent !important;
}
#finance-tabs .js-plotly-plot .plotly .modebar-btn path { fill: #52665b !important; }
#finance-tabs .js-plotly-plot .plotly .modebar-btn:hover path,
#finance-tabs .js-plotly-plot .plotly .modebar-btn.active path { fill: #2d7a46 !important; }

#finance-kpi-accordion .finance-kpi-grid { margin: 0; }
#finance-kpi-accordion .finance-kpi-card {
    border: 1px solid #dbe5df;
    border-radius: 9px;
    background: #fff;
    box-shadow: 0 1px 4px rgba(15, 23, 42, 0.06);
}
#finance-kpi-accordion .finance-kpi-card .card-body {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 82px;
    padding: 14px;
}
#finance-kpi-accordion .finance-kpi-card-label {
    color: #29463b;
    font-size: 1rem;
    font-weight: 600;
    text-align: center;
    overflow-wrap: anywhere;
}

#finance-kpi-accordion > .accordion-item > .accordion-collapse > .accordion-body {
    max-height: 65vh;
    overflow-y: auto;
    overscroll-behavior: contain;
}

.finance-kpi-usage-layout > .finance-kpi-chart-card {
    margin-bottom: 1rem;
}

.finance-kpi-chart-card {
    border-color: #d4e2dc;
    box-shadow: 0 1px 4px rgba(34, 72, 56, 0.08);
}

.finance-kpi-chart-title {
    color: #29463b;
    background: #f3f8f5;
    font-weight: 600;
}

.finance-kpi-chart {
    width: 100%;
}

.finance-kpi-delay-note {
    margin: 0 0 0.5rem;
    padding: 0.35rem 0.65rem;
    font-size: 0.78rem;
    line-height: 1.25;
}

/* Budget transaction workspace */
.finance-budget-root,
.finance-budget-workspace { min-height: 0; }
.finance-budget-root { height: 100%; }
.finance-budget-workspace { display: flex; flex-direction: column; gap: .75rem; }
.finance-budget-hero {
    display: flex; align-items: center; gap: 14px; padding: 16px 20px;
    border: 1px solid #d9e6de; border-radius: 12px;
    background: linear-gradient(110deg, #f2f8f4 0%, #ffffff 72%);
}
.finance-budget-hero-icon {
    display: grid; place-items: center; flex: 0 0 46px; height: 46px;
    color: #197b50; background: #e0f1e7; border-radius: 12px; font-size: 1.2rem;
}
.finance-budget-hero h4 { color: #234b39; font-weight: 700; }
.finance-budget-tabs { min-height: 0; }
.finance-budget-tabs > .tab-content { padding-top: 12px; }
.finance-budget-config-tabs > .nav-tabs { flex-wrap: nowrap; overflow-x: auto; overflow-y: hidden; }
.finance-budget-config-tabs > .nav-tabs .nav-link { white-space: nowrap; }
.finance-budget-panel { min-height: 0; }
.finance-budget-card {
    border: 1px solid #dbe5df; border-radius: 12px;
    box-shadow: 0 2px 8px rgba(28, 58, 42, .06);
}
.finance-budget-card > .card-body { padding: 16px; }
.finance-budget-heading h5 { color: #234b39; font-weight: 700; }
.finance-budget-heading { margin-bottom: 0.45rem; }
.finance-budget-controls-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 10px; }
.finance-budget-actions { display: flex; align-items: center; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
.finance-budget-button-group { border: 1px solid #d5e2d9; border-radius: 8px; padding: 3px; background: #f7faf8; }
.finance-budget-filter-group { background: #f2f8fb; border-color: #c9dce5; }
.finance-budget-action {
    min-height: 38px; border-radius: 7px; white-space: nowrap; font-weight: 500; font-size: 0.86rem;
    display: inline-flex; align-items: center; justify-content: center;
    transition: background-color .15s ease, box-shadow .15s ease, transform .1s ease;
}
.finance-budget-action .bi { font-size: 1rem; line-height: 1; }
.finance-budget-action:not(:disabled):hover { box-shadow: 0 2px 6px rgba(35, 70, 50, .18); }
.finance-budget-action:not(:disabled):active { transform: translateY(1px); }
.finance-budget-action:disabled { opacity: .45; cursor: not-allowed; }
.finance-budget-button-group { box-shadow: 0 1px 2px rgba(35, 70, 50, .08); }
.finance-budget-actions { gap: 10px; }
#finance-budget-bank-import-modal .modal-footer .btn { min-width: 130px; border-radius: 7px; font-weight: 500; }
#finance-budget-bank-import-modal .modal-footer .bi,
#finance-budget-modal .modal-footer .bi { font-size: 1rem; vertical-align: -0.1em; }
.finance-budget-selection-summary { flex: 0 0 auto; margin-bottom: 0; }
.finance-budget-summary-content { display: flex; flex-wrap: wrap; gap: 0.55rem; }
.finance-budget-summary-item {
    display: flex; flex-direction: column; justify-content: center; gap: 0.1rem;
    min-width: 145px; min-height: 58px; padding: 0.45rem 0.75rem;
    border: 1px solid #d7e3da; border-radius: 0.55rem; background: #f8fbf9;
}
.finance-budget-summary-label { color: #63756a; font-size: 0.76rem; line-height: 1.1; }
.finance-budget-summary-value { color: #173c2a; font-size: 1rem; line-height: 1.25; font-variant-numeric: tabular-nums; }
.finance-budget-table-wrap { display: flex; flex-direction: column; height: calc(100vh - 380px); min-height: 420px; max-height: none; overflow: hidden; border: 1px solid #e0e8e3; border-radius: 8px; }
.finance-budget-table-wrap .dash-table-container { display: flex; flex: 1 1 auto; height: 100%; min-width: 100%; min-height: 0; }
.finance-budget-table-wrap .dash-spreadsheet-container { flex: 1 1 auto; height: 100% !important; max-height: 100% !important; min-height: 0; overflow-y: auto !important; }
.finance-budget-field { margin-bottom: 2px; }
.finance-budget-field-label { color: #334b40; font-weight: 600; font-size: .88rem; }
.finance-budget-field .form-control,
.finance-budget-field .Select-control,
.finance-budget-field .DateInput_input { min-height: 40px; border-color: #cbd8d0; border-radius: 7px; }
.finance-budget-select { width: 100%; }
.finance-budget-date .DateInput, .finance-budget-date .DateInput_input { width: 100%; }
.finance-budget-modal .modal-dialog { max-width: min(1140px, calc(100vw - 2rem)); }
.finance-budget-date .SingleDatePicker { position: relative; }
.finance-budget-date .SingleDatePicker_picker { left: auto !important; right: 0 !important; }
.finance-budget-modal .modal-body { max-height: 68vh; overflow-y: auto; }
@media (max-width: 767px) {
    .finance-budget-modal .modal-dialog { max-width: calc(100vw - 1rem); margin: .5rem auto; }
    .finance-budget-hero { padding: 12px; }
    .finance-budget-controls-row { align-items: flex-start; flex-direction: column; }
    .finance-budget-actions { width: 100%; justify-content: flex-start; }
    .finance-budget-action { flex: 1 1 calc(50% - 8px); }
    .finance-budget-table-wrap { height: calc(100vh - 300px); min-height: 300px; max-height: none; }
    .finance-budget-table-wrap-sales,
    .finance-budget-table-wrap-payments { height: calc(100vh - 260px) !important; min-height: 340px !important; }
}

.finance-reports-workspace {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    min-height: 0;
    padding-top: 0.75rem;
    overflow: visible;
}

.finance-report-filters-card,
.finance-report-content-card {
    border: 1px solid #d7e3da;
    border-radius: 0.65rem;
    box-shadow: 0 1px 3px rgba(31, 70, 48, 0.06);
}

.finance-report-filters-card {
    position: relative;
    z-index: 2;
    overflow: visible !important;
}

.finance-reports-workspace,
.finance-report-filters-card .card-body,
.finance-report-filters-card .row { overflow: visible !important; }
.finance-report-filter-dropdown-col { position: relative; z-index: 3; }
.finance-report-filter-dropdown-col:has(.Select.is-open) { z-index: 1300; }
.finance-report-filter-dropdown-col .Select.is-open { z-index: 1301; }
.finance-report-filters-card .Select-menu-outer {
    z-index: 1302 !important;
    max-height: min(45vh, 320px);
    overflow-y: auto;
}
.finance-report-content-card { position: relative; z-index: 1; }

.finance-report-date-range {
    display: flex;
    width: 100%;
    position: relative;
    z-index: 10;
}

.finance-report-date-range .DateRangePicker,
.finance-report-date-range .DateRangePickerInput {
    width: 100%;
}

.finance-report-date-range .DateRangePicker_picker {
    z-index: 1100 !important;
}

.finance-report-currency {
    font-size: 0.85rem;
    padding: 0.4rem 0.65rem;
}

.finance-report-content-card {
    min-height: 300px;
}
.finance-report-content-card > .card-body,
#finance-report-content {
    width: 100%;
}
.finance-report-content-card > .card-body {
    max-height: calc(100vh - 380px);
    min-height: 300px;
    overflow-x: hidden;
    overflow-y: auto;
    padding: 1rem 1.1rem;
    scrollbar-width: thin;
    scrollbar-color: #b9cdbf transparent;
}

.finance-report-balance-card {
    border: 1px solid #d7e3da;
    border-radius: 0.55rem;
    background: #f8fbf9;
}

.finance-report-balance { display: block; margin-top: 0.2rem; color: #173c2a; font-size: 1.4rem; }
.finance-report-component-balance { font-size: 1rem; overflow-wrap: anywhere; }
.finance-report-chart {
    display: block;
    width: 100%;
    min-width: 0;
}
.finance-report-chart > div,
.finance-report-chart .js-plotly-plot,
.finance-report-chart .plot-container,
.finance-report-chart .svg-container {
    display: block;
    width: 100% !important;
    min-width: 0;
}

.finance-report-empty-state {
    display: grid;
    min-height: 260px;
    place-items: center;
    color: #65766b;
    text-align: center;
}

/* Keep the existing Finance page usable inside the phone navigation shell. */
@media (max-width: 800px) {
    .finance-report-chart { height: 55vh !important; min-height: 420px !important; }
    .finance-report-content-card > .card-body { max-height: calc(100vh - 300px); }
    .finance-mobile {
        width: 100%;
        max-width: 100%;
        padding: 0.5rem 0.35rem 1rem !important;
        overflow: visible;
    }

    .finance-mobile > .row,
    .finance-mobile > .row > .col,
    .finance-mobile #finance-tabs,
    .finance-mobile #finance-tabs .tab-content,
    .finance-mobile #finance-tabs .tab-pane,
    .finance-mobile #finance-tabs .card,
    .finance-mobile #finance-tabs .card-body {
        min-width: 0;
        max-width: 100%;
    }

    .finance-mobile #finance-tabs .nav-tabs {
        flex-wrap: nowrap;
        overflow-x: auto;
        overflow-y: hidden;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: thin;
    }

    .finance-mobile #finance-tabs .nav-link {
        flex: 0 0 auto;
        white-space: nowrap;
        padding: 0.5rem 0.75rem;
    }

    .finance-mobile #finance-tabs .js-plotly-plot,
    .finance-mobile #finance-tabs .plot-container,
    .finance-mobile #finance-tabs .svg-container {
        max-width: 100%;
    }
}

/* ---- Reports tab: filters, summary cards and chart ---- */
.finance-report-filters-card { background: #fbfdfb; }
.finance-report-filters-card .card-body { padding: 0.9rem 1.1rem 0.8rem; }
.finance-report-filters-title {
    display: flex; align-items: center; margin-bottom: 0.7rem; padding-bottom: 0.55rem;
    border-bottom: 1px solid #e3ece6; color: #244b38; font-size: 0.95rem; font-weight: 700;
    letter-spacing: 0.05em; text-transform: uppercase;
}
.finance-report-filters-title .bi { font-size: 1.15rem; color: #2e7d54; }
.finance-report-filters-card .form-label {
    margin-bottom: 0.3rem; color: #4f6357; font-size: 0.82rem; font-weight: 600;
    letter-spacing: 0.05em; text-transform: uppercase;
}
.finance-report-filters-card .Select-control,
.finance-report-filters-card .Select--single > .Select-control .Select-value,
.finance-report-filters-card .DateRangePickerInput {
    min-height: 44px; height: 44px; border-radius: 7px; border-color: #cfdcd3; background: #fff;
}
.finance-report-filters-card .Select-control:hover,
.finance-report-filters-card .DateRangePickerInput:hover { border-color: #8fb79d; box-shadow: 0 1px 4px rgba(46, 125, 84, 0.12); }
.finance-report-filters-card .Select.is-focused > .Select-control { border-color: #2e7d54; box-shadow: 0 0 0 3px rgba(46, 125, 84, 0.15); }
.finance-report-filters-card .Select-placeholder,
.finance-report-filters-card .Select--single > .Select-control .Select-value { line-height: 42px; font-size: 1rem; }
.finance-report-filters-card .Select-input { height: 42px; }
.finance-report-filters-card .Select-menu-outer .Select-option { font-size: 0.98rem; padding: 9px 12px; }
.finance-report-filters-card .DateInput_input { height: 42px; padding: 0 10px; font-size: 1rem; line-height: 42px; border-bottom: 0; background: transparent; }
.finance-report-filters-card .DateRangePickerInput_arrow { color: #8fa398; }
.finance-report-description {
    margin-top: 0.7rem; padding: 0.4rem 0.7rem; border-radius: 6px; background: #f1f7f3;
    color: #4f6357; font-size: 0.92rem;
}
.finance-report-description::before { content: "\2139\00a0\00a0"; color: #2e7d54; font-weight: 700; }

.finance-report-balance-card {
    border: 1px solid #d9e6dd; border-left: 4px solid #2e7d54; border-radius: 0.6rem;
    background: linear-gradient(180deg, #ffffff 0%, #f6faf7 100%);
    box-shadow: 0 1px 3px rgba(31, 70, 48, 0.07);
}
.finance-report-balance-card > .card-body { padding: 0.9rem 1.1rem 0.7rem; }
.finance-report-balance-card > .card-body > .text-muted.small:first-child {
    margin-bottom: 0.7rem !important; padding-bottom: 0.45rem; border-bottom: 1px solid #e3ece6;
    color: #244b38 !important; font-size: 0.85rem !important; font-weight: 700;
    letter-spacing: 0.05em; text-transform: uppercase;
}
.finance-report-balance-card .row > [class*="col"] > .text-muted.small {
    display: flex; align-items: center; gap: 0.45rem; color: #596e60 !important; font-size: 0.88rem !important;
}
.finance-report-balance-card .row > [class*="col"] > .text-muted.small::before {
    content: ""; flex: 0 0 auto; width: 10px; height: 10px; border-radius: 50%; background: #208454;
}
.finance-report-balance-card .row > [class*="col"]:nth-child(2) > .text-muted.small::before { background: #2878b5; }
.finance-report-balance-card .row > [class*="col"]:nth-child(3) > .text-muted.small::before { background: #d95f02; }
.finance-report-balance-card .row > [class*="col"]:nth-child(4) > .text-muted.small::before { background: #8e44ad; }
.finance-report-balance { font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }
.finance-report-component-balance { font-size: 1.35rem; font-weight: 700; }

/* the chart fills the remaining viewport, so neither the card nor the chart needs a scrollbar */
.finance-report-chart {
    height: clamp(420px, calc(100vh - 570px), 820px) !important;
    margin: 0.5rem 0 1.25rem;
    padding: 0.35rem;
    border: 1px solid #d9e6dd;
    border-radius: 0.65rem;
    background: #fff;
    box-shadow: 0 1px 4px rgba(31, 70, 48, 0.08);
}
.finance-report-chart:last-child { margin-bottom: 0; }

.finance-report-content-card .alert { font-size: 0.98rem; }
.finance-report-chart .modebar { top: 4px !important; }
