:root {
    --primary: #1a5276;
    --primary-dark: #154360;
    --sell: #c0392b;
    --buy: #27ae60;
    --warn: #e67e22;
    --muted: #7f8c8d;
    --bg-soft: #eaf2f8;
    --border: #ccc;
}

* { box-sizing: border-box; }

body {
    font-family: 'Segoe UI', Arial, sans-serif;
    color: #333;
    margin: 0;
    background: #f7f9fb;
}

.container {
    max-width: 900px;
    margin: 40px auto;
    padding: 20px;
}

h2 { color: var(--primary); }
h3 { color: var(--primary); margin: 0; }

.asset-group {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    margin: 16px 0;
    flex-wrap: wrap;
}

.asset-item { flex: 1 1 140px; }

label {
    display: block;
    font-size: 14px;
    font-weight: bold;
    margin-bottom: 4px;
}

input {
    width: 100%;
    padding: 8px;
    font-size: 16px;
    border: 1px solid var(--border);
    border-radius: 4px;
}

.actions {
    display: flex;
    gap: 12px;
    margin-top: 20px;
    flex-wrap: wrap;
}

button {
    padding: 12px 24px;
    font-size: 16px;
    background-color: var(--primary);
    color: #fff;
    border: none;
    border-radius: 4px;
    cursor: pointer;
}

button:hover { background-color: var(--primary-dark); }
button:disabled { background-color: #aab7c4; cursor: not-allowed; }

button.secondary { background-color: #5d6d7e; }
button.secondary:hover:not(:disabled) { background-color: #4a5763; }

.link-btn {
    background: none;
    color: var(--primary);
    padding: 4px 8px;
    font-size: 14px;
    text-decoration: underline;
}
.link-btn:hover { background: none; color: var(--primary-dark); }

.result { margin-top: 30px; }

table { width: 100%; border-collapse: collapse; }
th, td { border: 1px solid var(--border); padding: 12px; text-align: right; }
th { background-color: #f2f2f2; text-align: center; }
td:first-child, th:first-child { text-align: left; }

.sell { color: var(--sell); font-weight: bold; }
.buy { color: var(--buy); font-weight: bold; }

.trigger-info { margin: 15px 0; font-weight: bold; font-size: 16px; }
.no-trigger { color: var(--muted); }
.trigger-yes { color: var(--warn); }

.total-asset {
    background-color: var(--bg-soft);
    font-weight: bold;
    padding: 10px;
    margin-bottom: 15px;
    border-radius: 4px;
}

.history { margin-top: 40px; border-top: 1px solid var(--border); padding-top: 20px; }
.history-head { display: flex; align-items: center; justify-content: space-between; }

.db-status {
    font-size: 13px;
    color: var(--muted);
    margin: 10px 0;
}
.db-status.error { color: var(--sell); }
.db-status.ok { color: var(--buy); }

.history-item {
    border: 1px solid #e1e8ed;
    border-radius: 6px;
    padding: 10px 14px;
    margin: 10px 0;
    background: #fff;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}
.history-item .meta { font-size: 13px; color: var(--muted); }
.history-item .summary { font-size: 14px; }
.history-item .del {
    background: none;
    color: var(--sell);
    padding: 4px 8px;
    font-size: 13px;
}
.history-item .del:hover { background: #fdecea; }

.panel {
    background: #fff;
    border: 1px solid #e1e8ed;
    border-radius: 8px;
    padding: 16px 18px;
    margin: 20px 0;
}
.panel h3 { margin: 0 0 8px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.panel-head h3 { margin: 0; }
.hint { font-size: 13px; color: var(--muted); margin: 0 0 12px; }

.holdings-actions { display: flex; gap: 12px; align-items: center; margin-top: 10px; flex-wrap: wrap; }
.baseline-field { max-width: 280px; margin-bottom: 12px; }
.holdings-grid, #dca-grid { display: flex; flex-direction: column; gap: 12px; }
.holding-row, .dca-row {
    display: grid;
    grid-template-columns: 1.2fr repeat(4, minmax(88px, 1fr));
    gap: 10px;
    align-items: end;
    padding: 10px;
    background: #f9fbfd;
    border-radius: 6px;
}
.holding-name, .dca-name { font-weight: bold; font-size: 14px; }
.holding-name small, .dca-name small, .code { display: block; font-weight: normal; color: var(--muted); font-size: 12px; }

.field label { font-size: 12px; margin-bottom: 2px; }
.field select { width: 100%; padding: 8px; font-size: 14px; border: 1px solid var(--border); border-radius: 4px; }

.lump-form {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: flex-end;
}
.lump-form .field { flex: 1 1 140px; }

.mini-list { margin-top: 12px; }
.mini-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 0;
    border-bottom: 1px solid #eee;
    font-size: 14px;
}

.profit-summary {
    margin-top: 12px;
    padding: 10px 12px;
    background: var(--bg-soft);
    border-radius: 4px;
    font-size: 14px;
}
.profit-row { display: flex; flex-wrap: wrap; gap: 16px; }
.profit-up { color: var(--sell); font-weight: bold; }
.profit-down { color: var(--buy); font-weight: bold; }
.total-asset.sub { font-size: 14px; margin-top: -8px; background: #f4f6f7; }

@media (max-width: 640px) {
    .holding-row, .dca-row { grid-template-columns: 1fr; }
    .profit-row { flex-direction: column; gap: 6px; }
}

/* 折叠面板 */
.panel.collapsible { padding: 0; overflow: hidden; }
.panel.collapsible summary {
    padding: 16px 18px;
    cursor: pointer;
    font-weight: bold;
    color: var(--primary);
    list-style: none;
    user-select: none;
}
.panel.collapsible summary::-webkit-details-marker { display: none; }
.panel.collapsible summary::before {
    content: '▸ ';
    display: inline-block;
    transition: transform 0.15s;
}
.panel.collapsible[open] summary::before { transform: rotate(90deg); }
.panel.collapsible .panel-body { padding: 0 18px 16px; }

/* 收益曲线 */
.curve-chart-wrap { margin: 8px 0 16px; }
.curve-chart { width: 100%; max-width: 100%; height: auto; display: block; background: #fafcfd; border-radius: 6px; border: 1px solid #e8eef3; }
.chart-line { stroke-width: 2; vector-effect: non-scaling-stroke; }
.chart-total { stroke: var(--primary); }
.chart-profit { stroke: var(--sell); stroke-dasharray: 5 3; }
.chart-zero { stroke: #ddd; stroke-width: 1; }
.chart-label { font-size: 11px; fill: var(--muted); }
.chart-legend { display: flex; gap: 20px; font-size: 13px; color: var(--muted); margin-bottom: 12px; }
.chart-legend .dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 4px; vertical-align: middle; }
.dot-total { background: var(--primary); }
.dot-profit { background: var(--sell); }
.curve-table-title { font-size: 15px; color: var(--primary); margin: 16px 0 8px; }
.curve-table-wrap { overflow-x: auto; max-height: 360px; overflow-y: auto; }
.curve-table { font-size: 13px; }
.curve-table th { font-size: 12px; padding: 8px; }
.curve-table td { padding: 8px; }
.row-backtrack { background: #fafbfc; }
.tag-back { display: block; font-size: 10px; color: var(--muted); font-weight: normal; }

/* 组合配置 */
.asset-config-row {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)) auto;
    gap: 10px;
    align-items: end;
    padding: 12px 0;
    border-bottom: 1px solid #e8eef3;
}
.asset-config-row .field label { font-size: 12px; }
.asset-config-row .ac-check { display: flex; flex-direction: column; align-items: center; }
.asset-config-row .ac-check input { margin-top: 4px; }
.asset-config-actions { display: flex; gap: 12px; align-items: center; margin-top: 12px; flex-wrap: wrap; }
.hint.warn { color: var(--warn); }
.hint.ok { color: var(--buy); }
