* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: "Segoe UI", "Microsoft JhengHei", Arial, sans-serif;
    background: #f3f6fb;
    color: #1f2937;
}

a {
    text-decoration: none;
}

input,
button,
select {
    font: inherit;
}

img {
    display: block;
    max-width: 100%;
}

.card {
    background: #fff;
    border-radius: 18px;
    padding: 24px;
    box-shadow: 0 8px 24px rgba(15, 23, 42, 0.06);
    margin-bottom: 24px;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 46px;
    min-width: 100px;
    padding: 0 18px;
    border-radius: 12px;
    font-size: 15px;
    font-weight: 700;
    border: 0;
    cursor: pointer;
    transition: 0.2s ease;
    white-space: nowrap;
}

.btn-primary {
    background: linear-gradient(135deg, #2563eb, #1d4ed8);
    color: #fff;
}

.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 10px 20px rgba(37, 99, 235, 0.18);
}

.btn-secondary {
    background: #e5e7eb;
    color: #111827;
}

.btn-secondary:hover {
    background: #d1d5db;
}

.btn-danger {
    background: #ef4444;
    color: #fff;
}

.btn-danger:hover {
    background: #dc2626;
    transform: translateY(-1px);
    box-shadow: 0 10px 20px rgba(239, 68, 68, 0.18);
}

.copy-btn {
    min-width: 84px;
    height: 38px;
    padding: 0 14px;
    border: 0;
    border-radius: 10px;
    background: #2563eb;
    color: #fff;
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
}

.copy-btn:hover {
    background: #1d4ed8;
}

.copy-btn.done {
    background: #16a34a;
}

.agentprofit-row-actions,
.flowassist-row-actions,
.directweek-row-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.flowassist-row-actions,
.directweek-row-actions {
    justify-content: center;
}

.detail-open-btn {
    min-width: 72px;
    height: 38px;
    padding: 0 14px;
    font-size: 14px;
}

.detail-current-row {
    background: #eff6ff;
}

.detail-current-row:hover {
    background: #dbeafe;
}

.detail-current-row td {
    background: #eff6ff;
}

.detail-current-row:hover td {
    background: #dbeafe;
}

.alert {
    margin-top: 20px;
    padding: 14px 16px;
    border-radius: 12px;
    font-size: 14px;
    line-height: 1.6;
    border: 1px solid transparent;
}

.alert-error {
    background: #fef2f2;
    color: #b91c1c;
    border-color: #fecaca;
}

.alert-success {
    margin-top: 20px;
    padding: 14px 16px;
    border-radius: 12px;
    font-size: 14px;
    line-height: 1.6;
    background: #ecfdf5;
    color: #166534;
    border: 1px solid #a7f3d0;
}

.layout {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: 260px;
    background: #111827;
    color: #fff;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    padding: 24px 18px;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
}

.sidebar-logo {
    text-align: center;
    margin-bottom: 28px;
}

.logo-circle {
    width: 72px;
    height: 72px;
    margin: 0 auto 14px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    padding: 10px;
}

.sidebar-logo h2 {
    font-size: 20px;
    font-weight: 700;
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.nav-btn {
    display: block;
    padding: 14px 16px;
    border-radius: 12px;
    color: #d1d5db;
    background: rgba(255, 255, 255, 0.04);
    transition: 0.2s ease;
    font-size: 15px;
    font-weight: 600;
}

.nav-btn:hover {
    background: rgba(59, 130, 246, 0.18);
    color: #fff;
}

.nav-btn.active {
    background: linear-gradient(135deg, #2563eb, #1d4ed8);
    color: #fff;
}

.main-content {
    margin-left: 260px;
    flex: 1;
    padding: 32px;
}

.page-header {
    margin-bottom: 24px;
}

.page-header h1 {
    font-size: 30px;
    font-weight: 800;
    margin-bottom: 8px;
    color: #111827;
}

.page-header p {
    color: #6b7280;
    font-size: 15px;
}

.search-form-inline {
    display: grid;
    grid-template-columns: 180px minmax(320px, 1fr) 250px 32px 250px auto;
    gap: 16px;
    align-items: end;
}

.search-form-inline .field {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.search-form-inline label {
    margin-bottom: 8px;
    font-size: 14px;
    font-weight: 700;
    color: #374151;
    line-height: 1.4;
    white-space: nowrap;
}

.search-form-inline input,
.search-form-inline select {
    width: 100%;
    height: 46px;
    border: 1px solid #d1d5db;
    border-radius: 12px;
    padding: 0 14px;
    font-size: 15px;
    outline: none;
    transition: 0.2s ease;
    background: #fff;
    color: #1f2937;
}

.search-form-inline input:focus,
.search-form-inline select:focus {
    border-color: #2563eb;
    box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.12);
}

.search-form-inline input::placeholder {
    color: #9ca3af;
}

.field-search-type {
    min-width: 180px;
}

.field-keyword {
    min-width: 320px;
}

.field-datetime {
    min-width: 250px;
}

.date-range-separator {
    height: 46px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    font-weight: 700;
    color: #6b7280;
}

.search-form-inline .actions {
    display: flex;
    gap: 10px;
    align-items: flex-end;
    height: 46px;
}

.search-hint-row {
    grid-column: 1 / -1;
    margin-top: -4px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.input-hint {
    font-size: 12px;
    color: #6b7280;
    line-height: 1.5;
}

.input-hint-error {
    color: #b91c1c;
    font-weight: 700;
}

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

.table-header h2 {
    font-size: 22px;
    color: #111827;
}

.table-note {
    font-size: 13px;
    color: #6b7280;
}

.table-wrap {
    width: 100%;
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    min-width: 1200px;
    background: #fff;
}

.simple-table {
    min-width: 900px;
}

thead th {
    background: #f9fafb;
    color: #374151;
    font-size: 14px;
    font-weight: 700;
    text-align: left;
    padding: 14px 16px;
    border-bottom: 1px solid #e5e7eb;
    white-space: nowrap;
}

tbody td {
    padding: 14px 16px;
    border-bottom: 1px solid #e5e7eb;
    font-size: 14px;
    color: #1f2937;
    vertical-align: middle;
}

tbody tr:hover {
    background: #f8fbff;
}

.search-tip {
    text-align: center;
    color: #2563eb;
    font-weight: 700;
    background: #eff6ff;
    border-radius: 10px;
    padding: 14px;
}

.badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 4px 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 700;
    white-space: nowrap;
}

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

.badge-danger {
    background: #fee2e2;
    color: #991b1b;
}

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

.fund-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 62px;
    padding: 6px 12px;
    border-radius: 999px;
    font-size: 13px;
    font-weight: 700;
    line-height: 1;
    white-space: nowrap;
}

.badge-fund-in {
    background: #ef4444;
    color: #fff;
}

.badge-fund-out {
    background: #22c55e;
    color: #fff;
}

.badge-fund-default {
    background: #e5e7eb;
    color: #374151;
}

.money-in {
    background: #ef4444;
    color: #fff;
}

.money-out {
    background: #22c55e;
    color: #fff;
}

.money-default {
    background: #e5e7eb;
    color: #374151;
}

.money-cell {
    text-align: right;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.flow-id-cell,
.order-no-cell,
.plat-code-cell,
.remark-cell {
    word-break: break-all;
}

.info-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    margin-top: 12px;
}

.info-item {
    background: #f9fafb;
    padding: 12px;
    border-radius: 10px;
    border: 1px solid #e5e7eb;
}

.info-item .label {
    font-size: 12px;
    color: #6b7280;
    margin-bottom: 6px;
    font-weight: 700;
}

.info-item .value {
    font-size: 14px;
    font-weight: 700;
    color: #111827;
    word-break: break-all;
}

.loading-overlay {
    position: fixed;
    inset: 0;
    background: rgba(17, 24, 39, 0.38);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    padding: 20px;
}

.loading-overlay.show {
    display: flex;
}

.loading-modal {
    width: 100%;
    max-width: 340px;
    background: #fff;
    border-radius: 20px;
    padding: 28px 24px;
    box-shadow: 0 20px 40px rgba(15, 23, 42, 0.18);
    text-align: center;
}

.loading-spinner {
    width: 42px;
    height: 42px;
    margin: 0 auto 16px;
    border-radius: 50%;
    border: 4px solid #dbeafe;
    border-top-color: #2563eb;
    animation: spin 0.9s linear infinite;
}

.loading-title {
    font-size: 18px;
    font-weight: 800;
    color: #111827;
    margin-bottom: 8px;
}

.loading-desc,
.loading-text {
    font-size: 14px;
    color: #6b7280;
    line-height: 1.6;
}

.flow-remark-stack {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.flow-remark-details {
    display: block;
    padding: 0;
    border: 0;
    background: transparent;
}

.flow-remark-summary {
    list-style: none;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
}

.flow-remark-summary::-webkit-details-marker {
    display: none;
}

.flow-remark-panel {
    margin-top: 8px;
    padding: 10px 12px;
    border-radius: 10px;
    background: #f8fafc;
    border: 1px solid #e5e7eb;
    min-width: 220px;
}

.flow-remark-line {
    font-size: 13px;
    line-height: 1.6;
    color: #334155;
    word-break: break-all;
}

.flow-remark-line+.flow-remark-line {
    margin-top: 6px;
}

.flow-remark-stack .flow-remark-details {
    margin-top: 2px;
}

.inline-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    min-height: 72px;
    padding: 16px;
    border-radius: 12px;
    background: #f8fafc;
    border: 1px solid #e5e7eb;
    color: #475569;
    font-size: 14px;
    font-weight: 700;
}

.inline-loading-spinner {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    border: 3px solid #dbeafe;
    border-top-color: #2563eb;
    animation: spin 0.9s linear infinite;
    flex: 0 0 auto;
}

.inline-loading-text {
    line-height: 1;
}

.detail-inline-loading-row td {
    background: #f8fafc;
    padding: 16px 18px;
}

.detail-inline-loading-row:hover td {
    background: #f8fafc;
}

.fund-flow-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 14px;
}

.fund-flow-toolbar-left,
.fund-flow-toolbar-right {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.toolbar-label {
    font-size: 13px;
    color: #6b7280;
    font-weight: 700;
}

.toolbar-select {
    height: 38px;
    min-width: 82px;
    border: 1px solid #d1d5db;
    border-radius: 10px;
    padding: 0 10px;
    background: #fff;
    color: #111827;
    font-size: 14px;
}

.fund-flow-table-wrap {
    max-height: 70vh;
    overflow: auto;
    border: 1px solid #e5e7eb;
    border-radius: 14px;
}

#fundFlowTable thead th {
    position: sticky;
    top: 0;
    z-index: 5;
    background: #f9fafb;
}

.pagination-bar {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    flex-wrap: wrap;
    margin-top: 16px;
}

.pagination-bar:empty {
    display: none;
}

.pagination-btn {
    min-width: 40px;
    height: 36px;
    padding: 0 12px;
    border: 1px solid #d1d5db;
    border-radius: 10px;
    background: #fff;
    color: #111827;
    cursor: pointer;
    font-size: 14px;
    font-weight: 700;
    transition: 0.2s ease;
}

.pagination-btn:hover:not(:disabled) {
    border-color: #2563eb;
    color: #2563eb;
}

.pagination-btn:focus-visible {
    outline: 3px solid rgba(37, 99, 235, 0.22);
    outline-offset: 2px;
}

.pagination-btn.active {
    background: #2563eb;
    color: #fff;
    border-color: #2563eb;
}

.pagination-btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.pagination-ellipsis {
    min-width: 24px;
    color: #6b7280;
    font-size: 14px;
    font-weight: 800;
    text-align: center;
}

.merged-open-btn {
    height: 32px;
    min-width: auto;
    padding: 0 12px;
    font-size: 13px;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

@media (max-width: 1400px) {
    .search-form-inline {
        grid-template-columns: 180px 1fr 250px 32px 250px;
    }

    .search-form-inline .actions {
        grid-column: 1 / -1;
        height: auto;
    }
}

@media (max-width: 1200px) {
    .search-form-inline {
        grid-template-columns: 180px 1fr;
    }

    .field-search-type {
        grid-column: 1 / 2;
    }

    .field-keyword {
        grid-column: 2 / 3;
    }

    .field-datetime {
        grid-column: auto;
    }

    .date-range-separator {
        display: none;
    }

    .search-form-inline .actions {
        grid-column: 1 / -1;
        height: auto;
    }
}

@media (max-width: 900px) {
    .sidebar {
        width: 220px;
    }

    .main-content {
        margin-left: 220px;
        padding: 20px;
    }

    .search-form-inline {
        grid-template-columns: 1fr 1fr;
    }

    .field-search-type,
    .field-keyword,
    .field-datetime,
    .search-form-inline .actions,
    .search-hint-row {
        grid-column: auto;
    }

    .field-keyword {
        grid-column: 1 / -1;
    }

    .date-range-separator {
        display: none;
    }

    .search-form-inline .actions {
        grid-column: 1 / -1;
        height: auto;
    }

    .search-hint-row {
        grid-column: 1 / -1;
        margin-top: -4px;
    }

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

@media (max-width: 768px) {
    .layout {
        flex-direction: column;
    }

    .sidebar {
        position: static;
        width: 100%;
        height: auto;
    }

    .main-content {
        margin-left: 0;
    }

    .search-form-inline {
        grid-template-columns: 1fr;
    }

    .search-form-inline .field {
        max-width: 100%;
        width: 100%;
    }

    .field-datetime,
    .field-apply-date,
    .field-keyword,
    .field-search-type {
        min-width: 0;
        width: 100%;
    }

    .search-form-inline input[type="date"],
    .search-form-inline input[type="datetime-local"] {
        display: block;
        box-sizing: border-box;
        -webkit-appearance: none;
        appearance: none;
        inline-size: 100%;
        min-width: 0;
        min-inline-size: 0;
        max-width: 100%;
        max-inline-size: 100%;
        width: 100%;
    }

    .search-form-inline input[type="date"]::-webkit-date-and-time-value,
    .search-form-inline input[type="datetime-local"]::-webkit-date-and-time-value {
        display: block;
        min-width: 0;
        max-width: 100%;
        width: 100%;
    }

    .search-form-inline input[type="date"]::-webkit-calendar-picker-indicator,
    .search-form-inline input[type="datetime-local"]::-webkit-calendar-picker-indicator {
        margin: 0;
    }

    .date-range-separator {
        display: none;
    }

    .search-form-inline .actions {
        justify-content: stretch;
        flex-wrap: wrap;
        height: auto;
    }

    .search-hint-row {
        grid-column: auto;
        margin-top: -2px;
    }

    .btn {
        width: 100%;
    }

    .agentprofit-row-actions,
    .flowassist-row-actions,
    .directweek-row-actions {
        flex-direction: column;
        align-items: stretch;
    }

    .agentprofit-row-actions .copy-btn,
    .agentprofit-row-actions .detail-open-btn,
    .flowassist-row-actions .copy-btn,
    .flowassist-row-actions .detail-open-btn,
    .directweek-row-actions .copy-btn,
    .directweek-row-actions .detail-open-btn {
        width: 100%;
    }

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

    .fund-flow-table-wrap {
        max-height: 60vh;
    }
}
