* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: #f5f7fb;
    color: #1f2937;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", Arial, sans-serif;
    font-size: 14px;
}

a {
    color: #2463eb;
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

.login-page {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
}

.login-box {
    width: min(420px, 100%);
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    box-shadow: 0 14px 40px rgba(31, 41, 55, .08);
    padding: 28px;
}

.login-box h1,
.page-title h1 {
    margin: 0;
    font-size: 24px;
    letter-spacing: 0;
}

.login-box p {
    color: #6b7280;
    margin: 8px 0 24px;
}

.login-remember {
    justify-content: flex-start;
    margin-top: 0;
}

.layout {
    min-height: 100vh;
    display: grid;
    grid-template-columns: 220px minmax(0, 1fr);
}

.sidebar {
    background: #111827;
    color: #d1d5db;
    padding: 20px 14px;
}

.brand {
    color: #fff;
    font-size: 18px;
    font-weight: 700;
    margin: 0 8px 20px;
}

.nav a {
    display: block;
    color: #d1d5db;
    padding: 11px 12px;
    border-radius: 6px;
    margin-bottom: 4px;
}

.nav a.active,
.nav a:hover {
    color: #fff;
    background: #263244;
    text-decoration: none;
}

.main {
    min-width: 0;
}

.topbar {
    height: 60px;
    background: #fff;
    border-bottom: 1px solid #e5e7eb;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
}

.content {
    padding: 24px;
}

.page-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 18px;
}

.page-title p {
    margin: 6px 0 0;
    color: #6b7280;
}

.panel {
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    padding: 18px;
    margin-bottom: 18px;
}

.panel h2 {
    margin: 0 0 14px;
    font-size: 17px;
}

.grid {
    display: grid;
    gap: 14px;
}

.grid-2 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.grid-3 {
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

.subsection {
    border-top: 1px solid #e5e7eb;
    margin-top: 18px;
    padding-top: 18px;
}

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

.section-title h2 {
    margin: 0;
}

.check-group {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
}

.check-item {
    display: flex;
    align-items: center;
    gap: 8px;
    min-height: 38px;
    padding: 8px 10px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    background: #fff;
    font-weight: 500;
    margin: 0;
}

.check-item.single {
    margin-top: 26px;
}

.check-item input {
    width: auto;
    margin: 0;
}

.payment-rows {
    display: grid;
    gap: 10px;
}

.payment-row {
    display: grid;
    grid-template-columns: 110px minmax(110px, .8fr) minmax(160px, 1fr) minmax(170px, 1.2fr) minmax(190px, 1.3fr) auto;
    gap: 10px;
    align-items: end;
    padding: 12px;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    background: #f9fafb;
}

.payment-order {
    align-self: center;
    color: #374151;
    font-weight: 700;
}

.row-action {
    display: flex;
    align-items: end;
}

.payment-proof-cell {
    min-width: 0;
}

.payment-preview {
    margin-top: 12px;
    padding: 12px;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    background: #f9fafb;
}

.preview-list {
    display: grid;
    gap: 6px;
    margin-top: 8px;
}

.preview-line {
    color: #374151;
    word-break: break-word;
}

.invoice-amount-panel {
    max-width: 320px;
    margin-top: 12px;
}

.stats {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 14px;
    margin-bottom: 18px;
}

.stat {
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    padding: 16px;
}

.stat strong {
    display: block;
    font-size: 28px;
    margin-bottom: 6px;
}

.stat span {
    color: #6b7280;
}

label {
    display: block;
    color: #374151;
    font-weight: 600;
    margin-bottom: 6px;
}

input,
select,
textarea {
    width: 100%;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    padding: 10px 11px;
    background: #fff;
    color: #111827;
    font: inherit;
}

textarea {
    min-height: 96px;
    resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: #2463eb;
    box-shadow: 0 0 0 3px rgba(36, 99, 235, .12);
}

.actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 36px;
    padding: 0 14px;
    border: 1px solid transparent;
    border-radius: 6px;
    background: #2463eb;
    color: #fff;
    cursor: pointer;
    font-weight: 600;
    text-decoration: none;
}

.btn:hover {
    background: #1d4ed8;
    color: #fff;
    text-decoration: none;
}

.btn.secondary {
    background: #fff;
    color: #374151;
    border-color: #d1d5db;
}

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

.btn.danger {
    background: #dc2626;
}

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

.btn.small {
    min-height: 30px;
    padding: 0 10px;
    font-size: 13px;
}

.btn.tiny {
    min-height: 24px;
    padding: 0 8px;
    font-size: 12px;
}

.table-wrap {
    overflow-x: auto;
}

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

th,
td {
    border-bottom: 1px solid #e5e7eb;
    padding: 11px 10px;
    text-align: left;
    vertical-align: middle;
    white-space: nowrap;
}

th {
    color: #6b7280;
    font-size: 13px;
    font-weight: 700;
    background: #f9fafb;
}

.badge {
    display: inline-flex;
    align-items: center;
    min-height: 24px;
    padding: 0 9px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 700;
}

.badge.muted {
    background: #f3f4f6;
    color: #4b5563;
}

.badge.warning {
    background: #fef3c7;
    color: #92400e;
}

.badge.info {
    background: #dbeafe;
    color: #1d4ed8;
}

.badge.success {
    background: #dcfce7;
    color: #166534;
}

.badge.danger {
    background: #fee2e2;
    color: #b91c1c;
}

.flash {
    padding: 12px 14px;
    border-radius: 6px;
    margin-bottom: 16px;
}

.flash.success {
    background: #ecfdf5;
    color: #065f46;
    border: 1px solid #a7f3d0;
}

.flash.error {
    background: #fef2f2;
    color: #991b1b;
    border: 1px solid #fecaca;
}

.muted-text {
    color: #6b7280;
}

.detail-list {
    display: grid;
    grid-template-columns: 130px minmax(0, 1fr);
    gap: 10px 12px;
}

.detail-list dt {
    color: #6b7280;
}

.detail-list dd {
    margin: 0;
    min-width: 0;
    word-break: break-word;
}

.invoice-detail-grid,
.invoice-secondary-grid {
    gap: 10px;
}

.invoice-detail-grid .panel,
.invoice-secondary-grid .panel,
.invoice-finance-panel {
    padding: 12px;
    margin-bottom: 10px;
}

.invoice-detail-grid .panel h2,
.invoice-secondary-grid .panel h2,
.invoice-finance-panel h2 {
    margin-bottom: 8px;
    font-size: 15px;
}

.invoice-detail-grid .detail-list {
    grid-template-columns: 104px minmax(0, 1fr);
    gap: 6px 8px;
    font-size: 13px;
    line-height: 1.35;
}

.copyable-value {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 8px;
}

.copyable-value span {
    min-width: 0;
    word-break: break-word;
}

.copyable-value .copy-trigger {
    flex: 0 0 auto;
}

.invoice-key-label {
    color: #111827;
    font-weight: 700;
}

.invoice-key-value {
    padding: 5px 8px;
    border-radius: 6px;
    background: #fff7ed;
    color: #111827;
    font-size: 14px;
    font-weight: 700;
}

.invoice-key-value .copy-trigger {
    min-height: 24px;
    padding: 0 8px;
    font-weight: 600;
}

.invoice-secondary-grid {
    grid-template-columns: minmax(0, 1.35fr) minmax(260px, .65fr);
    align-items: start;
}

.invoice-secondary-grid th,
.invoice-secondary-grid td {
    padding: 7px 8px;
    font-size: 13px;
}

.invoice-secondary-grid .btn.small {
    min-height: 26px;
    padding: 0 8px;
    font-size: 12px;
}

.invoice-attachment-panel .attachment {
    padding: 8px;
}

.invoice-finance-panel {
    border-color: #bfdbfe;
    background: #f8fbff;
}

.compact-finance-grid {
    gap: 10px;
}

.invoice-finance-panel label {
    margin-bottom: 4px;
}

.invoice-finance-panel input,
.invoice-finance-panel textarea {
    padding: 8px 10px;
}

.readonly-money {
    min-height: 38px;
    display: flex;
    align-items: center;
    padding: 8px 10px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    background: #f9fafb;
    color: #111827;
    font-weight: 700;
}

.compact-textarea-row {
    margin-top: 10px;
}

.compact-textarea-row textarea {
    min-height: 54px;
}

.invoice-file-upload-panel {
    margin-top: 10px;
    padding: 12px;
    border: 2px solid #2563eb;
    border-radius: 8px;
    background: #eff6ff;
}

.invoice-file-upload-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 8px;
}

.invoice-file-upload-head label {
    margin: 0;
    color: #1d4ed8;
    font-size: 16px;
}

.invoice-file-upload-head span {
    color: #1e40af;
    font-size: 13px;
}

.invoice-file-upload-panel .upload-control {
    grid-template-columns: auto minmax(0, 1fr);
    align-items: start;
}

.invoice-file-upload-panel .file-preview {
    min-width: 0;
}

.filter {
    display: grid;
    grid-template-columns: repeat(5, minmax(120px, 1fr));
    gap: 12px;
    align-items: end;
}

.attachment-list {
    display: grid;
    gap: 8px;
}

.upload-control {
    display: grid;
    gap: 8px;
}

.file-input {
    display: none;
}

.file-preview {
    display: grid;
    gap: 8px;
}

.file-preview-item {
    display: flex;
    align-items: center;
    min-width: 0;
    gap: 8px;
    padding: 8px;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    background: #f9fafb;
}

.file-preview-item img {
    width: 56px;
    height: 56px;
    flex: 0 0 auto;
    object-fit: cover;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
}

.proof-preview-card {
    align-items: flex-start;
}

.proof-preview-image,
.file-preview-item .proof-preview-image {
    width: 140px;
    height: 100px;
    flex: 0 0 auto;
    object-fit: contain;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    background: #fff;
}

.file-type-badge {
    width: 72px;
    height: 56px;
    flex: 0 0 auto;
    display: grid;
    place-items: center;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    background: #fff;
    color: #991b1b;
    font-weight: 700;
}

.file-preview-item span {
    min-width: 0;
    word-break: break-all;
}

.existing-files {
    display: grid;
    gap: 6px;
}

.existing-file-item,
.proof-links {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
}

.proof-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 8px;
}

.bank-file-panel,
.bank-file-card {
    display: grid;
    gap: 12px;
    padding: 16px;
    border: 2px solid #2563eb;
    border-radius: 8px;
    background: #eff6ff;
}

.bank-file-section {
    border-color: #bfdbfe;
}

.bank-file-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
}

.bank-file-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.bank-file-title strong {
    font-size: 17px;
    color: #1d4ed8;
}

.bank-file-title span {
    color: #1f2937;
    font-weight: 600;
}

.bank-file-preview {
    min-height: 74px;
}

.bank-new-row td {
    background: #fff7ed;
    border-bottom-color: #fed7aa;
}

.bank-new-row td:first-child {
    border-left: 4px solid #f97316;
}

.bank-code-cell {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.bank-new-badge {
    background: #f97316;
    color: #fff;
}

.bank-row-actions {
    gap: 6px;
}

.existing-file-item span {
    min-width: 0;
    word-break: break-all;
}

.image-modal[hidden] {
    display: none;
}

.image-modal {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: grid;
    place-items: center;
    padding: 24px;
}

.image-modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(17, 24, 39, .72);
}

.image-modal-body {
    position: relative;
    z-index: 1;
    width: min(960px, 100%);
    max-height: calc(100vh - 48px);
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
    gap: 12px;
    padding: 14px;
    border-radius: 8px;
    background: #fff;
    box-shadow: 0 24px 80px rgba(17, 24, 39, .28);
}

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

.image-modal-body img {
    max-width: 100%;
    max-height: calc(100vh - 140px);
    object-fit: contain;
    justify-self: center;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    background: #fff;
}

.image-modal-body iframe {
    width: 100%;
    height: calc(100vh - 140px);
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    background: #fff;
}

.center-toast[hidden] {
    display: none;
}

.center-toast {
    position: fixed;
    left: 50%;
    top: 50%;
    z-index: 1200;
    transform: translate(-50%, -50%);
    min-width: 220px;
    max-width: calc(100vw - 48px);
    padding: 14px 20px;
    border-radius: 8px;
    background: rgba(17, 24, 39, .92);
    color: #fff;
    text-align: center;
    box-shadow: 0 18px 60px rgba(17, 24, 39, .28);
}

.attachment {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    padding: 10px;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    background: #f9fafb;
}

.empty {
    color: #6b7280;
    padding: 18px;
    text-align: center;
}

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

    .sidebar {
        position: static;
    }

    .stats,
    .grid-2,
    .grid-3,
    .filter,
    .bank-file-grid,
    .payment-row,
    .check-group {
        grid-template-columns: 1fr;
    }

    .invoice-file-upload-panel .upload-control {
        grid-template-columns: 1fr;
    }

    .page-title,
    .topbar {
        align-items: flex-start;
        flex-direction: column;
        height: auto;
        padding-top: 14px;
        padding-bottom: 14px;
    }
}
