* {
    box-sizing: border-box;
}

:root {
    --bg: #f5f7fb;
    --card: #ffffff;
    --border: #e4e8ef;
    --text: #172033;
    --muted: #6b7280;
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --green: #16a34a;
    --red: #dc2626;
    --orange: #ea580c;
    --purple: #7c3aed;
    --yellow: #eab308;
    --shadow: 0 3px 15px rgba(15, 23, 42, 0.06);
}

html {
    scroll-behavior: smooth;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
}

button,
input,
textarea,
select {
    font: inherit;
}

button {
    cursor: pointer;
}

.container {
    max-width: 1100px;
    margin: 0 auto;
    padding: 28px 20px 70px;
}

/* =========================================
   HEADER
======================================== */
.header {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    gap: 20px;
    margin-bottom: 24px;
}

h1 {
    margin: 0 0 6px;
    font-size: 31px;
    line-height: 1.15;
}

.subtitle {
    color: var(--muted);
    font-size: 14px;
}

.month-box {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--muted);
    font-size: 14px;
}

.month-box input {
    border: 1px solid var(--border);
    background: white;
    border-radius: 8px;
    padding: 9px 11px;
    color: var(--text);
}

/* =========================================
   SUMMARY
======================================== */
.summary {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 13px;
    margin-bottom: 18px;
}

.summary-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 17px;
    box-shadow: var(--shadow);
}

.summary-card.highlight-blue {
    border-left: 4px solid var(--primary);
}

.summary-card.highlight-green {
    border-left: 4px solid var(--green);
}

.summary-card.highlight-purple {
    border-left: 4px solid var(--purple);
}

.summary-label {
    color: var(--muted);
    font-size: 12px;
    margin-bottom: 7px;
}

.summary-value {
    font-size: 23px;
    font-weight: 750;
}

/* =========================================
   TOOLBAR
======================================== */
.toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 24px;
    align-items: center;
}

.toolbar-separator {
    width: 1px;
    height: 24px;
    background: var(--border);
    margin: 0 8px;
}

.btn {
    border: 0;
    border-radius: 8px;
    padding: 10px 14px;
    background: var(--primary);
    color: white;
    font-weight: 650;
    transition: .15s;
}

.btn:hover {
    background: var(--primary-dark);
}

.btn.secondary {
    background: #64748b;
}

.btn.secondary:hover {
    background: #475569;
}

.btn.green {
    background: var(--green);
}

.btn.green:hover {
    background: #15803d;
}

.btn.red {
    background: var(--red);
}

.btn.red:hover {
    background: #b91c1c;
}

.btn.orange {
    background: var(--orange);
}

.btn.orange:hover {
    background: #c2410c;
}

.btn.small {
    padding: 7px 10px;
    font-size: 12px;
}

.file-label {
    display: inline-flex;
    align-items: center;
    border-radius: 8px;
    padding: 10px 14px;
    background: #64748b;
    color: white;
    font-weight: 650;
    cursor: pointer;
}

.file-label:hover {
    background: #475569;
}

.file-label input {
    display: none;
}

/* =========================================
   TABS NAVIGATION (НОВОЕ)
======================================== */
.tabs-nav {
    display: flex;
    gap: 4px;
    margin-bottom: 24px;
    border-bottom: 2px solid var(--border);
    overflow-x: auto;
    scrollbar-width: thin;
}

.tabs-nav::-webkit-scrollbar {
    height: 4px;
}

.tabs-nav::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 2px;
}

.tab-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 12px 18px;
    background: transparent;
    border: 0;
    border-bottom: 3px solid transparent;
    margin-bottom: -2px;
    color: var(--muted);
    font-weight: 650;
    font-size: 14px;
    white-space: nowrap;
    transition: all .15s ease;
    border-radius: 8px 8px 0 0;
}

.tab-btn:hover {
    background: #f1f5f9;
    color: var(--text);
}

.tab-btn.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
    background: #eff6ff;
}

.tab-icon {
    font-size: 16px;
    line-height: 1;
}

.tab-label {
    font-size: 14px;
}

.tab-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 22px;
    height: 22px;
    padding: 0 6px;
    background: var(--border);
    color: var(--muted);
    border-radius: 11px;
    font-size: 11px;
    font-weight: 750;
}

.tab-btn.active .tab-count {
    background: var(--primary);
    color: white;
}

/* =========================================
   TAB CONTENT (НОВОЕ)
======================================== */
.tab-content {
    display: none;
    animation: fadeIn .2s ease;
}

.tab-content.active {
    display: block;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(4px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* =========================================
   ACCOUNTS
======================================== */
.accounts-grid {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.account-group {
    background: var(--card);
    border: 2px solid var(--primary);
    border-radius: 13px;
    padding: 16px;
    box-shadow: var(--shadow);
}

.account-group-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--border);
}

.account-group-name {
    font-size: 16px;
    font-weight: 750;
    color: var(--primary);
}

.account-group-total {
    font-size: 18px;
    font-weight: 750;
    color: var(--text);
}

.account-group-children {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 10px;
    margin-left: 10px;
}

.account-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 16px;
    box-shadow: var(--shadow);
    position: relative;
}

.account-card.child {
    background: #f8fafc;
}

.account-card-actions {
    position: absolute;
    top: 12px;
    right: 12px;
    display: flex;
    gap: 4px;
}

.account-name {
    font-weight: 750;
    font-size: 15px;
    margin-bottom: 4px;
}

.account-type {
    color: var(--muted);
    font-size: 11px;
    margin-bottom: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.account-balance-row {
    display: flex;
    justify-content: space-between;
    font-size: 12px;
    margin-bottom: 4px;
    color: var(--muted);
}

.account-balance-row.current {
    font-size: 18px;
    font-weight: 750;
    color: var(--text);
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid var(--border);
}

/* =========================================
   INCOMES
======================================== */
.incomes-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.income-item {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 14px 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: var(--shadow);
}

.income-left {
    min-width: 0;
}

.income-source {
    font-weight: 700;
    font-size: 15px;
}

.income-meta {
    color: var(--muted);
    font-size: 12px;
    margin-top: 4px;
}

.income-right {
    text-align: right;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    gap: 12px;
}

.income-amount {
    font-size: 18px;
    font-weight: 750;
    color: var(--green);
}

.income-distributions-preview {
    font-size: 11px;
    color: var(--muted);
    margin-top: 4px;
    max-width: 300px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* =========================================
   FUNDS
======================================== */
.funds {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.fund {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 13px;
    overflow: hidden;
    box-shadow: var(--shadow);
}

.fund-top {
    padding: 19px;
    border-bottom: 1px solid var(--border);
}

.fund-header {
    display: flex;
    justify-content: space-between;
    gap: 20px;
}

.fund-title {
    font-size: 20px;
    font-weight: 750;
    margin-bottom: 5px;
}

.fund-description {
    color: var(--muted);
    font-size: 13px;
    line-height: 1.45;
}

.fund-total {
    text-align: right;
    flex-shrink: 0;
}

.fund-total-label {
    color: var(--muted);
    font-size: 11px;
}

.fund-total-value {
    font-size: 22px;
    font-weight: 750;
    margin-top: 3px;
}

/* =========================================
   STATUS BADGE
======================================== */
.status-badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 4px 10px;
    border-radius: 6px;
    font-size: 11px;
    font-weight: 700;
    margin-bottom: 8px;
}

.status-draft {
    background: #f3f4f6;
    color: #6b7280;
}

.status-discussion {
    background: #fef3c7;
    color: #92400e;
}

.status-approved {
    background: #dbeafe;
    color: #1e40af;
}

.status-tracking {
    background: #d1fae5;
    color: #065f46;
}

.status-completed {
    background: #e0e7ff;
    color: #3730a3;
}

/* =========================================
   MONTH NOTE & PROGRESS
======================================== */
.month-note {
    background: #fef3c7;
    border-left: 3px solid #f59e0b;
    padding: 10px 12px;
    margin-top: 12px;
    border-radius: 6px;
    font-size: 12px;
    line-height: 1.5;
    color: #78350f;
}

.month-note::before {
    content: "💬 ";
    font-size: 14px;
}

.progress-container {
    margin-top: 17px;
}

.progress {
    width: 100%;
    height: 8px;
    background: #e9edf3;
    border-radius: 99px;
    overflow: hidden;
}

.progress-bar {
    height: 100%;
    background: var(--primary);
    border-radius: 99px;
    transition: width .2s ease;
}

.progress-info {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    margin-top: 6px;
    color: var(--muted);
    font-size: 11px;
}

.fund-allocation-info {
    margin-top: 8px;
    font-size: 12px;
    color: var(--muted);
    display: flex;
    justify-content: space-between;
}

.allocation-status {
    font-weight: 700;
}

.allocation-status.ok {
    color: var(--green);
}

.allocation-status.low {
    color: var(--orange);
}

/* =========================================
   FUND SECTIONS & ITEMS
======================================== */
.fund-section {
    padding: 17px 19px;
    border-bottom: 1px solid var(--border);
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    margin-bottom: 11px;
}

.section-title {
    font-size: 14px;
    font-weight: 750;
}

.section-description {
    color: var(--muted);
    font-size: 11px;
    margin-top: 3px;
    line-height: 1.4;
}

.item {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 15px;
    padding: 11px 12px;
    margin-bottom: 7px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #fbfcfe;
}

.item:last-child {
    margin-bottom: 0;
}

.item-main {
    min-width: 0;
}

.item-name {
    font-weight: 650;
    font-size: 13px;
}

.item-note {
    color: var(--muted);
    font-size: 11px;
    margin-top: 3px;
    line-height: 1.4;
}

.item-right {
    display: flex;
    align-items: center;
    gap: 5px;
    flex-shrink: 0;
}

.item-amount {
    font-size: 13px;
    font-weight: 700;
    white-space: nowrap;
}

.item-action {
    border: 0;
    background: transparent;
    color: var(--muted);
    padding: 4px 5px;
    border-radius: 5px;
}

.item-action:hover {
    background: #eef2f7;
    color: var(--text);
}

.item-action.delete:hover {
    color: var(--red);
}

.fund-footer {
    padding: 13px 19px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.planning-type {
    color: var(--muted);
    font-size: 11px;
}

.fund-actions {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

/* =========================================
   COLLAPSED FUND
======================================== */
.fund.collapsed .fund-top {
    border-bottom: 0;
    padding: 12px 15px;
}

.collapsed-summary {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 15px;
}

.collapsed-left {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.collapse-icon {
    width: 29px;
    height: 29px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    border-radius: 7px;
    background: #eff6ff;
    color: var(--primary);
    font-size: 13px;
    font-weight: 700;
}

.collapsed-info {
    min-width: 0;
}

.collapsed-name {
    font-size: 14px;
    font-weight: 750;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.collapsed-meta {
    color: var(--muted);
    font-size: 11px;
    margin-top: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.collapsed-right {
    display: flex;
    align-items: center;
    gap: 11px;
    flex-shrink: 0;
}

.collapsed-total {
    font-size: 15px;
    font-weight: 750;
    white-space: nowrap;
}

/* =========================================
   COMPARISON
======================================== */
.comparison {
    display: flex;
    gap: 15px;
    margin-top: 12px;
    padding: 10px 12px;
    background: #f8fafc;
    border-radius: 8px;
    font-size: 12px;
}

.comparison-item {
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.comparison-label {
    color: var(--muted);
    font-size: 10px;
}

.comparison-value {
    font-weight: 700;
    font-size: 14px;
}

.green-text {
    color: var(--green);
}

.red-text {
    color: var(--red);
}

.orange-text {
    color: var(--orange);
}

.detailed-comparison {
    padding: 17px 19px;
    border-bottom: 1px solid var(--border);
    background: #f8fafc;
}

.comparison-header {
    font-size: 14px;
    font-weight: 750;
    margin-bottom: 12px;
    color: var(--text);
}

.comparison-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
}

.comparison-table th {
    text-align: left;
    padding: 8px 10px;
    background: #e2e8f0;
    font-weight: 700;
    border: 1px solid #cbd5e1;
}

.comparison-table td {
    padding: 8px 10px;
    border: 1px solid #e2e8f0;
    background: white;
}

.comparison-table tbody tr:hover {
    background: #f1f5f9;
}

.subtotal-row td {
    background: #fef3c7 !important;
    border-top: 2px solid #f59e0b;
}

.unplanned-header td {
    background: #fee2e2 !important;
    border-top: 2px solid #ef4444;
    padding: 10px;
}

.unplanned-row td {
    background: #fef2f2 !important;
}

.total-row td {
    background: #dbeafe !important;
    border-top: 3px solid #3b82f6;
    font-size: 13px;
}

.comparison-table th:nth-child(2),
.comparison-table th:nth-child(3),
.comparison-table th:nth-child(4),
.comparison-table td:nth-child(2),
.comparison-table td:nth-child(3),
.comparison-table td:nth-child(4) {
    text-align: right;
    white-space: nowrap;
}

/* =========================================
   EMPTY
======================================== */
.empty {
    background: white;
    border: 1px dashed var(--border);
    border-radius: 13px;
    text-align: center;
    padding: 55px 20px;
    color: var(--muted);
}

.empty h2 {
    color: var(--text);
    margin: 0 0 7px;
    font-size: 20px;
}

.empty p {
    margin: 5px 0;
    font-size: 13px;
}

/* =========================================
   MODAL
======================================== */
.modal {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: rgba(15, 23, 42, .5);
}

.modal.active {
    display: flex;
}

.modal-content {
    width: 100%;
    max-width: 520px;
    max-height: 90vh;
    overflow-y: auto;
    padding: 23px;
    background: white;
    border-radius: 13px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, .18);
}

.modal-content h2 {
    margin: 0 0 20px;
    font-size: 20px;
}

.form-group {
    margin-bottom: 15px;
}

.form-group label {
    display: block;
    margin-bottom: 6px;
    font-size: 12px;
    font-weight: 700;
}

.form-group input,
.form-group textarea,
.form-group select {
    width: 100%;
    padding: 10px 11px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: white;
    color: var(--text);
    outline: none;
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
    border-color: var(--primary);
}

.form-group textarea {
    min-height: 85px;
    resize: vertical;
}

.hint {
    color: var(--muted);
    font-size: 11px;
    line-height: 1.4;
    margin-top: 5px;
}

.modal-buttons {
    display: flex;
    justify-content: flex-end;
    gap: 7px;
    margin-top: 20px;
}

/* Distributions in Modal */
.distributions-container {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.distribution-row {
    display: flex;
    gap: 8px;
    align-items: center;
}

.distribution-row select {
    flex: 2;
}

.distribution-row input {
    flex: 1;
}

.distribution-row .btn.red {
    padding: 8px;
    font-size: 16px;
    line-height: 1;
}

/* =========================================
   RESPONSIVE
======================================== */
@media (max-width: 800px) {
    .summary {
        grid-template-columns: repeat(2, 1fr);
    }

    .header {
        align-items: flex-start;
        flex-direction: column;
    }

    .account-group-children {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 580px) {
    .container {
        padding: 20px 12px 50px;
    }

    h1 {
        font-size: 27px;
    }

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

    .fund-header {
        flex-direction: column;
    }

    .fund-total {
        text-align: left;
    }

    .fund-footer {
        align-items: flex-start;
        flex-direction: column;
    }

    .fund-actions {
        justify-content: flex-start;
    }

    .collapsed-summary {
        align-items: flex-start;
    }

    .collapsed-right {
        align-items: flex-end;
        flex-direction: column;
        gap: 5px;
    }

    .collapsed-total {
        font-size: 13px;
    }

    .comparison {
        flex-direction: column;
        gap: 8px;
    }

    .toolbar-separator {
        display: none;
    }

    .distribution-row {
        flex-direction: column;
        align-items: stretch;
    }

    .tabs-nav {
        gap: 2px;
        margin-bottom: 18px;
    }

    .tab-btn {
        padding: 10px 12px;
        font-size: 13px;
    }

    .tab-label {
        font-size: 13px;
    }
}

/* =========================================
   JOURNAL TABLE (Аналитика как в 1С)
======================================== */
.journal-table-container {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 12px;
    overflow-x: auto;
    box-shadow: var(--shadow);
}

.journal-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
    min-width: 800px;
}

.journal-table th {
    text-align: left;
    padding: 12px 16px;
    background: #f8fafc;
    font-weight: 700;
    color: var(--muted);
    border-bottom: 2px solid var(--border);
    white-space: nowrap;
}

.journal-table td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    color: var(--text);
}

.journal-table tbody tr:hover {
    background: #f1f5f9;
}

.journal-table tbody tr:last-child td {
    border-bottom: none;
}

.modal.active~#accountStatementModal {
    opacity: 0.3;
    pointer-events: none;
}

/* =========================================
   UNIFIED INCOME DISTRIBUTION
======================================== */
.unified-distributions-container {
    max-height: 350px;
    overflow-y: auto;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #f8fafc;
    padding: 8px;
}

.unified-dist-header {
    display: grid;
    grid-template-columns: 1fr 100px 1fr;
    gap: 8px;
    padding: 0 8px 8px;
    font-size: 11px;
    font-weight: 700;
    color: var(--muted);
    border-bottom: 1px solid var(--border);
    margin-bottom: 8px;
    position: sticky;
    top: 0;
    background: #f8fafc;
}

.unified-dist-row {
    display: grid;
    grid-template-columns: 1fr 100px 1fr;
    gap: 8px;
    align-items: center;
    padding: 6px 8px;
    border-bottom: 1px solid #e2e8f0;
    background: white;
    border-radius: 6px;
    transition: background .1s;
}

.unified-dist-row:hover {
    background: #f1f5f9;
}

.unified-dist-row:last-child {
    border-bottom: none;
}

.unified-dist-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.unified-dist-row input,
.unified-dist-row select {
    padding: 6px 8px;
    font-size: 13px;
    border: 1px solid var(--border);
    border-radius: 6px;
}

.unified-dist-row input:focus,
.unified-dist-row select:focus {
    border-color: var(--primary);
    outline: none;
}

/* Обновляем сетку для добавления колонки чекбокса */
.unified-dist-header {
    grid-template-columns: 40px 1fr 100px 1fr;
}

.unified-dist-row {
    grid-template-columns: 40px 1fr 100px 1fr;
}

.unified-dist-check {
    display: flex;
    align-items: center;
    justify-content: center;
}

.unified-dist-check input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
    accent-color: var(--primary);
}

/* Визуально выделяем активные строки */
.unified-dist-row.active-row {
    background: #eff6ff;
    border-left: 3px solid var(--primary);
}