/* --- Account Summaries Section --- */
.account-summaries-container {
    display: flex;
    flex-wrap: nowrap;
    gap: 30px;
    margin-top: 30px;
    align-items: flex-start;
}
#fd-current-summary-table {
    flex: 1 1 0;
    min-width: 320px;
    max-width: 600px;
}
#fd-savings-summary-and-tables {
    flex: 1 1 0;
    min-width: 320px;
    max-width: 700px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}
.finance-dashboard-tables {
    display: flex;
    flex-direction: column;
    gap: 20px;
}
#fd-current-summary-table, #fd-savings-summary-table {
    flex: 1;
    min-width: 300px;
    min-height: 180px;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
}
#fd-current-summary-table, #fd-savings-summary-table {
    flex: 1;
    min-width: 300px;
}
/* _finance_year-end-dashboard.css - Modern & Slick Styles */

/* --- Global & Container --- */
.finance-dashboard-container {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
    margin: 20px auto;
    padding: 20px;
    max-width: 1200px;
    background-color: #f9fafb;
    border-radius: 8px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
}

.finance-dashboard-container h2 {
    font-size: 1.75em;
    color: #1f2937;
    margin-bottom: 25px;
    text-align: left;
    border-bottom: 1px solid #e5e7eb;
    padding-bottom: 15px;
}

/* --- Filter & Export Section --- */
#finance-dashboard-filter-form {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 15px;
    margin-bottom: 20px;
    padding: 20px;
    background-color: #ffffff;
    border-radius: 8px;
    box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06);
}

#finance-dashboard-filter-form label {
    font-weight: 600;
    color: #374151;
    margin-right: 5px;
}

#finance-dashboard-filter-form select,
#finance-dashboard-filter-form button[type="submit"] {
    padding: 10px 15px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-size: 0.95em;
    background-color: #fff;
    color: #374151;
    transition: border-color 0.2s ease-in-out, box-shadow 0.2s ease-in-out;
}

#finance-dashboard-filter-form select:focus,
#finance-dashboard-filter-form button[type="submit"]:focus {
    outline: none;
    border-color: #2563eb;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.3);
}

#finance-dashboard-filter-form select[multiple] {
    min-height: 100px;
}

#finance-dashboard-filter-form button[type="submit"] {
    background-color: #2563eb;
    color: #ffffff;
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.2s ease-in-out;
}

#finance-dashboard-filter-form button[type="submit"]:hover {
    background-color: #1d4ed8;
}

.fd-export-buttons {
    margin-left: auto; /* Pushes export buttons to the right */
    margin-bottom: 20px; /* Add space below the buttons */
}

.fd-export-buttons .button {
    padding: 10px 15px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-size: 0.95em;
    background-color: #f9fafb;
    color: #374151;
    text-decoration: none;
    cursor: pointer;
    transition: background-color 0.2s ease-in-out, border-color 0.2s ease-in-out;
}

.fd-export-buttons .button:hover {
    background-color: #f3f4f6;
    border-color: #c7cdd4;
}

/* --- KPI Summary Section --- */
.kpi-grid-container {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 15px;
    margin-bottom: 30px;
}
.kpi-card[title] {
    position: relative;
    cursor: help;
}


.kpi-card {
    background-color: #ffffff;
    padding: 15px;
    border-radius: 8px;
    box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06);
    text-align: center;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    min-height: 90px;
}

.kpi-account-name {
    display: block;
    font-size: 0.75em;
    font-weight: 500;
    color: #6b7280;
    margin-bottom: 2px;
}

.kpi-metric-label {
    display: block;
    font-size: 0.85em;
    font-weight: 600;
    color: #4b5563;
    margin-bottom: 8px;
}

.kpi-value {
    display: block;
    font-size: 1.5em;
    font-weight: 700;
    color: #1f2937;
}

.kpi-total-funds {
    grid-column: 5 / 6; /* Position on the right (5th column) */
    border: 2px solid #2563eb;
}

.kpi-shop-profit {
    grid-column: 5 / 6; /* Position on the right (5th column) under Closing Stock */
    border: 2px solid #2563eb;
}

.kpi-shop-profit .kpi-value.positive-movement {
    color: #16a34a;
}

.kpi-shop-profit .kpi-value.negative-movement {
    color: #dc2626;
}


/* --- Main Income/Expense Tables --- */
.finance-dashboard-tables {
    overflow-x: auto; /* Allow horizontal scrolling on small screens if needed */
}

/* Ensure negative-movement always applies red to Society Operational P/L */
.kpi-operational-pl .kpi-value.negative-movement {
     color: #dc2626 !important;
}

.dashboard-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    margin-bottom: 30px;
    font-size: 0.9em;
    table-layout: auto;
    background-color: #ffffff;
    border-radius: 8px;
    box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06);
    overflow: hidden;
}

.dashboard-table th,
.dashboard-table td {
    padding: 12px 15px;
    vertical-align: middle;
    border-bottom: 1px solid #e5e7eb;
    text-align: left; /* Default to left for all in these tables */
}

.dashboard-table td:first-child,
.dashboard-table th:first-child {
    padding-left: 20px;
}
.dashboard-table td:last-child,
.dashboard-table th:last-child {
    padding-right: 20px;
}

.dashboard-table thead th {
    background-color: #f3f4f6;
    color: #374151;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    border-bottom: 2px solid #d1d5db;
    border-top: none;
}

.dashboard-table thead tr:first-child th.section-header {
    background-color: #1f2937;
    color: #ffffff;
    font-size: 1.2em;
    padding: 15px 20px;
    text-align: left;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    border-bottom: none;
}

.dashboard-table thead tr:nth-child(2) th {
    background-color: #f9fafb;
}

/* Right-align year and total headers & data for main income/expense tables */
.dashboard-table thead tr:nth-child(2) th:nth-child(n+3),
.dashboard-table tbody td:nth-child(n+3) {
    text-align: right;
    white-space: nowrap;
}

.dashboard-table tbody td:nth-child(1), /* Category data */
.dashboard-table tbody td:nth-child(2) { /* Subcategory data */
    text-align: left;
}

.income-category-row,
.expense-category-row {
    background-color: #fdfdfe;
}

.income-category-row td:first-child,
.expense-category-row td:first-child {
    font-weight: 600;
    color: #111827;
}

.income-subcategory-row td,
.expense-subcategory-row td {
    color: #4b5563;
    padding-left: 30px;
}
.income-subcategory-row td:nth-child(2),
.expense-subcategory-row td:nth-child(2) {
    padding-left: 35px !important;
}

.income-total-row td,
.expense-total-row td {
    font-weight: 700;
    color: #1f2937;
    background-color: #f3f4f6;
    border-top: 2px solid #d1d5db;
}

.dashboard-table tr.spacer-row td {
    height: 10px;
    border: none;
    background-color: #f9fafb;
}


/* --- Shop Performance Section --- */
#shop-performance-summary-section {
    margin-bottom: 30px;
    padding: 20px;
    background-color: #ffffff;
    border-radius: 8px;
    box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06);
}

#shop-performance-summary-section h3 {
    font-size: 1.5em;
    color: #1f2937;
    margin-top: 0;
    margin-bottom: 20px;
    padding-bottom: 10px;
    border-bottom: 1px solid #e5e7eb;
}

/* Container for the shop table (will enable scrolling on mobile) */
#fd-shop-performance-table {
    /* No overflow-x here by default, will be added in media query */
}

.shop-performance-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    /* margin-bottom: 30px; /* Removed, as section has margin */
    font-size: 0.9em;
    /* background-color: #ffffff; /* Already on section */
    /* border-radius: 8px; /* Section has radius */
    /* box-shadow: ... /* Section has shadow */
    /* overflow: hidden; /* Section handles clipping */
    table-layout: auto; /* Allow table to size based on content */
}

.shop-performance-table th,
.shop-performance-table td {
    padding: 12px 15px;
    vertical-align: middle;
    border-bottom: 1px solid #e5e7eb;
    /* text-align: left; /* Default, will be overridden by specific rules below */
}

.shop-performance-table thead th {
    background-color: #f9fafb; /* Slightly different header for this summary table */
    color: #374151;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    border-bottom-width: 2px; /* Thicker border for header */
}

/* ALIGNMENT RULES FOR SHOP PERFORMANCE TABLE */
/* Year column (first child) - explicitly left-aligned */
.shop-performance-table thead th:first-child,
.shop-performance-table tbody td:first-child {
    text-align: left;
    white-space: normal; /* Allow year to wrap if needed, though usually short */
}

/* Numerical columns (from 2nd child onwards) - explicitly right-aligned */
.shop-performance-table thead th:nth-child(n+2),
.shop-performance-table tbody td:nth-child(n+2) {
    text-align: right;
    white-space: nowrap; /* Keep numbers on one line */
}

/* Styles for positive/negative profit/loss in shop table */
.shop-performance-table .positive-movement {
    color: #16a34a; /* Green */
    font-weight: bold;
}
.shop-performance-table .negative-movement {
    color: #dc2626; /* Red */
    font-weight: bold;
}


/* --- Responsive Adjustments --- */
@media (max-width: 768px) {
    .finance-dashboard-container {
        margin: 10px;
        padding: 15px;
    }

    .finance-dashboard-container h2 {
        font-size: 1.5em;
        margin-bottom: 20px;
    }

    #finance-dashboard-filter-form {
        flex-direction: column;
        align-items: stretch;
        padding: 15px;
    }

    #finance-dashboard-filter-form label {
        margin-bottom: 5px;
    }

    #finance-dashboard-filter-form select,
    #finance-dashboard-filter-form button {
        width: 100%;
        margin-right: 0;
    }

    .finance-dashboard-summary .finance-totals {
        grid-template-columns: 1fr;
    }

    /* Styles for main income/expense tables on mobile */
    .dashboard-table {
        font-size: 0.85em;
    }

    .dashboard-table th,
    .dashboard-table td {
        padding: 8px 10px;
    }

    .dashboard-table td:first-child,
    .dashboard-table th:first-child {
        padding-left: 10px;
    }
    .dashboard-table td:last-child,
    .dashboard-table th:last-child {
        padding-right: 10px;
    }

    .income-subcategory-row td:nth-child(2),
    .expense-subcategory-row td:nth-child(2) {
        padding-left: 20px !important;
    }

    /* Styles for shop performance table on mobile */
    #shop-performance-summary-section h3 {
        font-size: 1.3em;
    }

    /* Enable horizontal scrolling for the shop performance table's container on mobile */
    #fd-shop-performance-table {
        overflow-x: auto;
        display: block; /* Helps overflow-x work reliably on a div */
    }

    /* Optional: Give the table inside the scrollable div a minimum width 
       if its content might otherwise try to wrap too aggressively.
       The nowrap on numerical cells should already prevent them from wrapping.
    */
    #fd-shop-performance-table .shop-performance-table {
        min-width: 700px; /* Adjust this value as needed based on your column content and padding */
                           /* Ensures there's something to scroll if screen is narrower */
    }
    
    .shop-performance-table th,
    .shop-performance-table td {
        padding: 8px 10px; /* Consistent padding for mobile tables */
        /* white-space: normal; /* General rule, but nowrap on numerical cells will override */
    }
}
.tooltip-hover {
    position: relative;
}

.kpi-tooltip {
    display: none;
    position: absolute;
    top: 110%;
    left: 50%;
    transform: translateX(-50%);
    background: #333;
    color: #fff;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 13px;
    white-space: nowrap;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    z-index: 999;
}

.tooltip-hover:hover .kpi-tooltip {
    display: block;
}

.tooltip-hover:hover {
    background-color: #0073aa;
    color: white;
}

.shop-summary-note {
    grid-column: 1 / -1;
    background-color: #fef3c7;
    color: #92400e;
    padding: 12px 18px;
    border-left: 4px solid #facc15;
    border-radius: 6px;
    margin-bottom: 15px;
    font-size: 0.9em;
}


.kpi-operational-pl {
    grid-column: 5 / 6;
    border: 2px solid #2563eb; /* Default blue border */
}
.kpi-operational-pl.negative-border {
    border: 2px solid #dc2626 !important; /* Red border if negative */
}

.kpi-shop-profit {
    grid-column: 5 / 6;
    border: 2px solid #2563eb; /* Default blue border */
}
.kpi-shop-profit.negative-border {
    border: 2px solid #dc2626 !important; /* Red border if negative */
}


/* Responsive adjustments for KPI grid */
@media (max-width: 768px) {
    .kpi-grid-container {
        overflow-x: auto;
        padding: 0 10px;
        min-width: 100%;
        width: max-content; /* Allow grid to be wider than container */
    }
    
    /* Keep the grid but make it scrollable */
    .kpi-grid-container {
        grid-template-columns: repeat(5, minmax(180px, 1fr));
        gap: 15px;
    }
}

/* ===========================================================================
 * Treasurer Report view
 * ========================================================================= */

.fd-view-toggle {
    margin: 12px 0 18px;
    padding: 8px 12px;
    background: #f3f4f6;
    border-radius: 6px;
    display: inline-flex;
    gap: 24px;
    align-items: center;
}
.fd-view-toggle .fd-view-option {
    cursor: pointer;
    font-weight: 500;
}
.fd-view-toggle input[type="radio"] {
    margin-right: 6px;
}

#fd-treasurer-view {
    margin-top: 20px;
}

.treasurer-ie-table,
.treasurer-recon-table {
    width: 100%;
    max-width: 760px;
    margin: 0 auto 24px;
    border-collapse: collapse;
    font-family: Georgia, 'Times New Roman', serif;
    background: #fff;
    box-shadow: 0 1px 4px rgba(0,0,0,0.05);
}

.treasurer-ie-table .treas-table-title,
.treasurer-recon-table .treas-table-title {
    text-align: center;
    font-size: 1.15rem;
    padding: 14px 8px 4px;
    border-bottom: none;
    font-weight: 700;
}
.treas-table-sub {
    font-size: 0.85rem;
    font-weight: 400;
    color: #555;
}
.treas-currency {
    font-size: 0.85rem;
    font-weight: 400;
    color: #555;
}

.treasurer-ie-table thead th,
.treasurer-recon-table thead th {
    padding: 8px 12px;
    background: transparent;
    border-bottom: 2px solid #333;
}

.treasurer-ie-table tbody td,
.treasurer-recon-table tbody td {
    padding: 6px 12px;
    border: none;
    font-size: 0.95rem;
}

/* Section sub-headings ("INCOME", "EXPENDITURE", "Opening balance"...) */
.treas-section-row td {
    font-weight: 700;
    padding-top: 14px !important;
    padding-bottom: 4px !important;
    text-transform: uppercase;
    font-size: 0.85rem;
    letter-spacing: 0.05em;
    color: #444;
}

/* Category row */
.treas-cat-row td {
    padding-left: 24px !important;
}
.treas-cat-cell {
    /* parent of toggle + cat name */
}
.treas-expandable {
    cursor: pointer;
}
.treas-expandable:hover td {
    background: #f9fafb;
}
.treas-toggle {
    display: inline-block;
    width: 12px;
    color: #2563eb;
    font-size: 0.85rem;
    user-select: none;
}

/* Subcategory rows (drill-down) */
.treas-sub-row td {
    padding-left: 48px !important;
    color: #555;
    font-size: 0.9rem;
    font-style: italic;
}
.treas-sub-cell {
    padding-left: 48px !important;
}

/* Always-visible sub-rows for the reconciliation table (no drill-down) */
.treas-sub-row-visible td {
    padding-left: 48px !important;
    color: #555;
}

/* Subtotal: single rule above */
.treas-subtotal-row td {
    border-top: 1px solid #999;
    padding-top: 4px !important;
    font-weight: 600;
}

/* Total: double rule above (the accounting "thick line") */
.treas-total-row td {
    border-top: 1px solid #333;
    padding-top: 6px !important;
    padding-bottom: 6px !important;
    font-weight: 600;
}

/* Grand total: double rule below */
.treas-grand-total-row td {
    border-top: 1px solid #333;
    border-bottom: 3px double #333;
    padding-top: 6px !important;
    padding-bottom: 6px !important;
    font-weight: 700;
}

.treas-check-row td {
    padding-top: 12px !important;
    color: #666;
    font-size: 0.85rem;
    border-top: 1px dotted #ccc;
}

.fd-dash {
    color: #aaa;
}

.treas-empty {
    padding: 20px;
    color: #666;
    font-style: italic;
    text-align: center;
}

/* Print styles for the Treasurer view */
@media print {
    .fd-view-toggle,
    #finance-dashboard-filter-form,
    .fd-export-buttons,
    #fd-detailed-view {
        display: none !important;
    }
    .treasurer-ie-table,
    .treasurer-recon-table {
        page-break-inside: avoid;
        box-shadow: none;
    }
}
