.komita-layout-grid {
    display: grid;
    grid-template-columns: minmax(0, 2fr) minmax(260px, 1fr);
    gap: 1.5rem;
}

.komita-card {
    border: 1px solid rgb(229 231 235);
    border-radius: 0.75rem;
    background: white;
    padding: 1rem;
    box-shadow: 0 1px 2px rgb(0 0 0 / 0.05);
}

.komita-summary-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 1rem;
}

.komita-form-row,
.komita-heading-row,
.komita-actions {
    display: flex;
    gap: 1rem;
}

.komita-simulator-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding-top: 1rem;
    border-top: 1px solid rgb(229 231 235);
}

.komita-card-title {
    margin-bottom: 1rem;
    color: rgb(17 24 39);
    font-size: 1rem;
    font-weight: 600;
}

.komita-calculation-summary th,
.komita-calculation-summary td {
    padding: 0.3rem 0.75rem 0.3rem 0;
    text-align: left;
}

.komita-calculation-summary th {
    min-width: 220px;
    font-weight: 500;
}

.komita-calculation-summary td::before {
    margin-right: 0.75rem;
    content: '=';
}

.komita-total-row {
    background: rgb(249 250 251);
    color: rgb(17 24 39);
    font-weight: 700;
}

.komita-form-row {
    align-items: flex-end;
}

.komita-form-row > :first-child {
    min-width: 0;
    flex: 1;
}

.komita-heading-row {
    align-items: center;
    justify-content: space-between;
}

.komita-actions {
    flex-wrap: wrap;
    justify-content: flex-end;
}

.komita-section-stack {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.komita-table-container {
    width: 100%;
    overflow-x: auto;
    border: 1px solid rgb(229 231 235);
    border-radius: 0.75rem;
    background: white;
    box-shadow: 0 1px 2px rgb(0 0 0 / 0.05);
}

.komita-data-table {
    width: 100%;
    min-width: 1000px;
    border-collapse: collapse;
    color: rgb(55 65 81);
    font-size: 0.875rem;
    line-height: 1.4;
}

.komita-data-table thead {
    background: rgb(249 250 251);
    color: rgb(55 65 81);
}

.komita-data-table th,
.komita-data-table td {
    padding: 0.75rem;
    border-bottom: 1px solid rgb(229 231 235);
    vertical-align: top;
}

.komita-data-table th {
    white-space: nowrap;
    font-weight: 600;
    text-align: left;
}

.komita-data-table tbody tr:last-child td {
    border-bottom: 0;
}

.komita-data-table th:nth-child(n + 5):not(:last-child),
.komita-data-table td:nth-child(n + 5):not(:last-child) {
    text-align: right;
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}

.komita-recap-table th:nth-child(n + 4),
.komita-recap-table td:nth-child(n + 4) {
    text-align: right;
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}

.komita-recap-container {
    max-width: 1000px;
    margin-inline: auto;
    overflow-x: hidden;
}

.komita-recap-table {
    min-width: 0;
    table-layout: fixed;
    font-size: 0.75rem;
}

.komita-recap-table th,
.komita-recap-table td {
    padding: 0.625rem 0.4rem;
}

.komita-recap-table th:nth-child(1),
.komita-recap-table td:nth-child(1) {
    width: 6%;
}

.komita-recap-table th:nth-child(2),
.komita-recap-table td:nth-child(2) {
    width: 13%;
}

.komita-recap-table th:nth-child(3),
.komita-recap-table td:nth-child(3) {
    width: 10%;
}

.komita-recap-table th:nth-child(n + 4),
.komita-recap-table td:nth-child(n + 4) {
    width: 14.2%;
}

.komita-balance-detail-card {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    width: 100%;
}

.komita-balance-actions {
    justify-content: flex-start;
}

.komita-member-meta-table {
    width: auto;
    border-collapse: collapse;
}

.komita-member-meta-table td {
    padding-block: 0.2rem;
}

.komita-member-meta-table td:first-child {
    width: 110px;
}

.komita-member-meta-table td:nth-child(2) {
    width: 22px;
}

.komita-balance-detail-container {
    max-width: none;
    margin-inline: 0;
}

.komita-print-title {
    display: none;
}

.komita-loan-table th:nth-child(n + 2),
.komita-loan-table td:nth-child(n + 2) {
    text-align: right;
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}

.komita-installment-container {
    overflow-x: hidden;
}

.komita-installment-table {
    min-width: 0;
    table-layout: fixed;
}

.komita-installment-table th:nth-child(n + 2):nth-child(-n + 4),
.komita-installment-table td:nth-child(n + 2):nth-child(-n + 4) {
    text-align: right;
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}

.komita-installment-table th:nth-child(1),
.komita-installment-table td:nth-child(1) {
    width: 8%;
}

.komita-installment-table th:nth-child(2),
.komita-installment-table td:nth-child(2) {
    width: 18%;
}

.komita-installment-table th:nth-child(3),
.komita-installment-table td:nth-child(3) {
    width: 22%;
}

.komita-installment-table th:nth-child(4),
.komita-installment-table td:nth-child(4) {
    width: 18%;
}

.komita-installment-table th:nth-child(5),
.komita-installment-table td:nth-child(5) {
    width: 16%;
}

.komita-installment-table th:nth-child(6),
.komita-installment-table td:nth-child(6) {
    width: 18%;
}

.komita-installment-table .komita-row-actions {
    flex-wrap: wrap;
}

.komita-row-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    white-space: nowrap;
}

.komita-validation-cell {
    min-width: 280px;
    white-space: normal;
}

.dark .komita-card,
.dark .komita-table-container {
    border-color: rgb(255 255 255 / 0.1);
    background: rgb(17 24 39);
}

.dark .komita-data-table {
    color: rgb(229 231 235);
}

.dark .komita-data-table thead {
    background: rgb(255 255 255 / 0.05);
    color: rgb(229 231 235);
}

.dark .komita-data-table th,
.dark .komita-data-table td {
    border-color: rgb(255 255 255 / 0.1);
}

.dark .komita-card-title,
.dark .komita-total-row {
    color: white;
}

.dark .komita-simulator-actions {
    border-color: rgb(255 255 255 / 0.1);
}

.dark .komita-total-row {
    background: rgb(255 255 255 / 0.05);
}

@media (max-width: 1024px) {
    .komita-layout-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 640px) {
    .komita-form-row,
    .komita-heading-row {
        align-items: stretch;
        flex-direction: column;
    }

    .komita-actions {
        justify-content: stretch;
    }

    .komita-recap-table {
        font-size: 0.625rem;
    }

    .komita-recap-table th,
    .komita-recap-table td {
        padding: 0.45rem 0.2rem;
    }

    .komita-recap-table th:nth-child(n + 4),
    .komita-recap-table td:nth-child(n + 4) {
        overflow-wrap: anywhere;
        white-space: normal;
    }
}

@media print {
    @page {
        size: A4 portrait;
        margin: 12mm;
    }

    body:has(#member-balance-detail) * {
        visibility: hidden !important;
    }

    body:has(#member-balance-detail) #member-balance-detail,
    body:has(#member-balance-detail) #member-balance-detail * {
        visibility: visible !important;
    }

    body:has(#member-balance-detail) #member-balance-detail {
        position: absolute !important;
        inset: 0 auto auto 0 !important;
        display: block !important;
        width: 100% !important;
        margin: 0 !important;
    }

    body:has(#member-balance-detail) .komita-print-title {
        display: block !important;
        margin: 0 0 12px;
        color: black;
        font-size: 20px;
        font-weight: 700;
    }

    body:has(#member-balance-detail) .komita-balance-detail-card {
        display: block;
        padding: 0;
        border: 0;
        box-shadow: none;
    }

    body:has(#member-balance-detail) .komita-balance-actions {
        display: none !important;
    }

    body:has(#member-balance-detail) .komita-member-meta-table {
        margin-bottom: 12px;
        color: black;
    }

    body:has(#member-balance-detail) .komita-balance-detail-container {
        width: 100%;
        overflow: visible;
        border: 1px solid #bbb;
    }

    body:has(#member-balance-detail) .komita-balance-detail-container table {
        width: 100%;
        table-layout: fixed;
        font-size: 8px;
    }

    body:has(#member-balance-detail) .komita-balance-detail-container th,
    body:has(#member-balance-detail) .komita-balance-detail-container td {
        padding: 4px 3px;
    }

    .komita-table-container {
        overflow: visible;
        border: 0;
        box-shadow: none;
    }

    .komita-data-table {
        min-width: 0;
        color: black;
        font-size: 10px;
    }

    .komita-card {
        border-color: #bbb;
        box-shadow: none;
    }
}
