:root {
    --bg: #f7f8fc;
    --panel: #ffffff;
    --line: #d9deeb;
    --text: #1b2440;
    --muted: #5a6480;
    --accent: #2563eb;
    --danger: #c23a3a;
    --success: #117d39;
}

* { box-sizing: border-box; }
body {
    margin: 0;
    font-family: Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
}

.launch-warning {
    margin: 12px 24px 0;
    border: 1px solid #ffd39f;
    background: #fff7ed;
    color: #7a3b00;
    border-radius: 8px;
    padding: 10px 12px;
    font-size: 14px;
}

.page-header {
    padding: 16px 24px;
    background: #111b3a;
    color: #fff;
}
.page-header h1 { margin: 0; font-size: 24px; }
.page-header p { margin: 6px 0 0 0; opacity: 0.9; }

.tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 12px 24px;
    border-bottom: 1px solid var(--line);
    background: #fff;
    position: sticky;
    top: 0;
    z-index: 5;
}
.tab-btn {
    border: 1px solid var(--line);
    background: #fff;
    color: var(--text);
    padding: 8px 14px;
    border-radius: 8px;
    cursor: pointer;
}
.tab-btn.active {
    background: #eaf0ff;
    border-color: #bfd2ff;
    color: #123b9f;
}

.fy-filter-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 24px;
    background: #f5f8ff;
    border-bottom: 1px solid #dbe3f6;
}

.fy-filter-bar select {
    border: 1px solid #c8d2ea;
    border-radius: 6px;
    padding: 5px 8px;
    font-size: 13px;
}

main { padding: 16px 24px 24px; }
.tab-content { display: none; }
.tab-content.active { display: block; }

.panel {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 16px;
    margin-bottom: 16px;
}

.hint {
    color: var(--muted);
    margin-top: 0;
    font-size: 13px;
}

.upload-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}
.file-label {
    display: inline-block;
    margin: 8px 0;
    background: #edf2ff;
    color: #1d3f9c;
    border: 1px solid #bdd0ff;
    padding: 7px 12px;
    border-radius: 8px;
    cursor: pointer;
}
input[type="file"] { display: block; margin-top: 6px; }

.import-mode-box {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
    font-size: 13px;
    color: #3f4a6a;
    margin: 8px 0;
}
.import-mode-box label {
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.button-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}
.btn {
    border: 1px solid #b6c5eb;
    background: #eaf0ff;
    color: #123b9f;
    padding: 8px 12px;
    border-radius: 8px;
    cursor: pointer;
}
.btn-secondary { background: #f0f3fa; color: #2d3a62; }
.btn-danger { background: #ffe9e9; border-color: #ffc7c7; color: #8f1b1b; }

.status-msg {
    min-height: 18px;
    margin-top: 8px;
    font-size: 13px;
}
.status-msg.error { color: var(--danger); }
.status-msg.success { color: var(--success); }
.status-msg.info { color: #3752a5; }

.loading, .empty-state {
    color: var(--muted);
    padding: 8px 0;
}

.acc-table, .tx-table, .rules-table {
    width: 100%;
    border-collapse: collapse;
}
.acc-table th, .acc-table td,
.tx-table th, .tx-table td,
.rules-table th, .rules-table td {
    border-bottom: 1px solid #e5e9f4;
    padding: 8px;
    text-align: left;
    vertical-align: top;
}
.acc-row { cursor: pointer; }
.acc-row:hover { background: #f8faff; }
.acc-row.selected { background: #edf2ff; }
.num { text-align: right !important; white-space: nowrap; }
.positive { color: #0f6e2a; }
.negative { color: #9c1d1d; }

.badge {
    display: inline-block;
    border-radius: 999px;
    padding: 2px 8px;
    font-size: 12px;
    border: 1px solid transparent;
}
.badge-asset { background: #e7f4ff; border-color: #b8ddff; }
.badge-liability { background: #fff5e8; border-color: #ffe1b3; }
.badge-equity { background: #eceaff; border-color: #cec8ff; }
.badge-income { background: #e9fff1; border-color: #bff3d1; }
.badge-expense { background: #ffecec; border-color: #ffc7c7; }

.leaf-icon, .toggle-icon {
    display: inline-block;
    width: 16px;
    color: #66708e;
}
.desc { color: #46506d; }

.ledger-panel { overflow: auto; }
.ledger-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 10px;
}
.ledger-title h2 {
    margin: 0 8px 0 0;
    display: inline-block;
}
.shortcode-badge {
    background: #f0f2fb;
    padding: 2px 6px;
    border-radius: 6px;
}
.ledger-meta {
    display: flex;
    gap: 16px;
    flex-wrap: wrap;
    margin-bottom: 10px;
    color: #3e4866;
    font-size: 14px;
}
.table-scroll { overflow: auto; }
.opening-row td { background: #fafbff; }

.ledger-filters {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: end;
    margin-bottom: 8px;
}
.ledger-filters label {
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 13px;
    color: #435072;
}
.ledger-filters input,
.ledger-filters select {
    border: 1px solid #c8d2ea;
    border-radius: 6px;
    padding: 6px 8px;
    min-width: 170px;
    font-size: 13px;
}

.report-table {
    width: 100%;
    border-collapse: collapse;
}
.report-table th,
.report-table td {
    border-bottom: 1px solid #e5e9f4;
    padding: 8px;
    text-align: left;
}
.report-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
}

.reports-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 12px;
}

.reports-export-bar {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 10px;
}

.reports-export-bar .status-msg {
    margin-top: 0;
}

.report-btn.active {
    background: #dfe9ff;
    border-color: #abc3ff;
}

.report-filters-wrap {
    border: 1px solid #e1e7f5;
    border-radius: 8px;
    background: #fafcff;
    padding: 10px;
    margin-bottom: 12px;
}

.report-filter-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    flex-wrap: wrap;
}

.report-filter-row label {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: #445075;
}

.report-filter-row select {
    border: 1px solid #c8d2ea;
    border-radius: 6px;
    padding: 5px 8px;
}

.report-filter-tree {
    margin-top: 8px;
    max-height: 220px;
    overflow: auto;
    border: 1px solid #e5e9f4;
    border-radius: 6px;
    background: #fff;
    padding: 8px;
}

.report-account-option {
    display: block;
    font-size: 13px;
    line-height: 1.8;
    color: #2d395f;
    white-space: nowrap;
}

.pie-wrap {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    align-items: center;
}

.pie-legend {
    min-width: 260px;
}

.pie-item {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 6px;
}

.pie-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    display: inline-block;
}

.kpi-row {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    margin-bottom: 12px;
}
.kpi-card {
    border: 1px solid #e1e7f5;
    border-radius: 8px;
    background: #fbfcff;
    padding: 10px;
}
.kpi-card h3 {
    margin: 0 0 8px 0;
    font-size: 14px;
    color: #445075;
}
.kpi-card p {
    margin: 0;
    font-size: 20px;
    font-weight: 600;
}

.kpi-value {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
    color: #1b2440;
}

@media (max-width: 980px) {
    .upload-grid { grid-template-columns: 1fr; }
    .report-grid,
    .kpi-row { grid-template-columns: 1fr; }
}

.hdfc-form {
    max-width: 560px;
}
.hdfc-label {
    display: block;
    font-size: 14px;
    color: var(--text);
}
.hdfc-select {
    display: block;
    width: 100%;
    max-width: 420px;
    border: 1px solid #c8d2ea;
    border-radius: 6px;
    padding: 8px 10px;
    font-size: 14px;
    color: var(--text);
    background: #fff;
    margin-top: 4px;
}

.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(18, 29, 59, 0.45);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    z-index: 50;
}

.modal-backdrop[hidden] {
    display: none !important;
}

.modal-card {
    width: min(1100px, 96vw);
    max-height: 90vh;
    overflow: auto;
    background: #fff;
    border: 1px solid #ced7ef;
    border-radius: 10px;
    padding: 14px;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
}

.modal-header h3 {
    margin: 0;
}

.modal-table-wrap {
    max-height: 52vh;
}

.row-error {
    background: #fff0f0;
}

.row-ok {
    background: #f4fff7;
}

.edit-table {
    width: 100%;
    border-collapse: collapse;
}

.edit-table th,
.edit-table td {
    border-bottom: 1px solid #e5e9f4;
    padding: 6px 8px;
    text-align: left;
    vertical-align: middle;
}

.edit-table th {
    background: #f0f3fa;
    font-weight: 600;
    color: #2d3a62;
}

.edit-table tbody tr:hover {
    background: #fafcff;
}

.cell-input,
.cell-select {
    width: 100%;
    border: 1px solid #c8d2ea;
    border-radius: 4px;
    padding: 4px 6px;
    font-size: 13px;
    font-family: inherit;
}

.cell-input:focus,
.cell-select:focus {
    outline: none;
    border-color: #2563eb;
    box-shadow: 0 0 3px rgba(37, 99, 235, 0.2);
}

.filter-bar {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px;
    background: #f8faff;
    border: 1px solid #dbe3f6;
    border-radius: 6px;
    margin-bottom: 12px;
}

.filter-bar label {
    font-weight: 600;
    color: #2d3a62;
    white-space: nowrap;
}

.filter-bar select {
    border: 1px solid #c8d2ea;
    border-radius: 4px;
    padding: 6px 8px;
    font-size: 13px;
    background: #fff;
    color: var(--text);
    min-width: 220px;
}

.target-account-cell {
    display: flex;
    align-items: center;
    gap: 4px;
}

.target-account-name {
    white-space: nowrap;
    flex-shrink: 0;
}

.sample-download-row {
    margin-top: 8px;
}

.sample-download-link {
    display: inline-block;
    font-size: 13px;
    color: #1d3f9c;
    text-decoration: none;
    border-bottom: 1px dashed #1d3f9c;
}

.sample-download-link:hover {
    color: #12337d;
    border-bottom-color: #12337d;
}

.bank-subtotal {
    background: #f0f3fa;
    border-top: 2px solid #cbd5e1;
    border-bottom: 2px solid #cbd5e1;
    font-weight: 500;
}

.bank-subtotal td {
    padding: 8px 12px;
    color: #1b2440;
}

.tx-target-perspective {
    background: #f8fbff;
}

.split-entry-row {
    border-left: 3px solid #f59e0b;
}

.tx-entry-note {
    display: inline-block;
    font-size: 12px;
    color: #8a5a00;
    background: #fff7e6;
    border: 1px solid #f5d9a8;
    border-radius: 999px;
    padding: 2px 8px;
    white-space: nowrap;
}

/* Cashflow Report Styles */
.cashflow-filters {
    border: 1px solid #e1e7f5;
    border-radius: 8px;
    background: #fafcff;
    padding: 12px;
    margin-bottom: 12px;
}

.cashflow-filters .filter-row {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 10px;
}

.cashflow-filters .filter-row label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 14px;
    color: #2d3a62;
    white-space: nowrap;
}

.cashflow-date-input {
    border: 1px solid #c8d2ea;
    border-radius: 6px;
    padding: 6px 8px;
    font-size: 13px;
    background: #fff;
    color: var(--text);
}

.cashflow-account-selector {
    margin-top: 10px;
    border-top: 1px solid #dbe3f6;
    padding-top: 10px;
}

.cashflow-account-selector label {
    display: block;
    font-size: 13px;
    color: #2d3a62;
    margin-bottom: 6px;
}

.cashflow-account-selector > div {
    max-height: 250px;
    overflow-y: auto;
    border: 1px solid #e5e9f4;
    border-radius: 6px;
    background: #fff;
    padding: 8px;
}

.cashflow-account-option {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px;
    font-size: 13px;
    line-height: 1.6;
    color: #2d395f;
}

.cashflow-account-option input[type="checkbox"] {
    cursor: pointer;
}

.cashflow-account-option span {
    flex: 1;
}

.cashflow-table {
    width: 100%;
    border-collapse: collapse;
}

.cashflow-table th,
.cashflow-table td {
    border-bottom: 1px solid #e5e9f4;
    padding: 10px 8px;
    text-align: left;
}

.cashflow-table th {
    background: #f0f3fa;
    font-weight: 600;
    color: #2d3a62;
}

.cashflow-table tbody tr:hover {
    background: #fafcff;
}

.cashflow-table tfoot tr {
    border-top: 2px solid #1b2440;
    font-weight: 600;
    background: #f0f3fa;
}

.cashflow-table tfoot td {
    padding: 10px 8px;
    color: #1b2440;
}
