:root {
    --bg: #f5f7fb;
    --panel: #ffffff;
    --panel-soft: #f8fafc;
    --text: #18212f;
    --muted: #64748b;
    --line: #dbe3ee;
    --accent: #2563eb;
    --positive: #15803d;
    --negative: #b91c1c;
    --shadow: 0 10px 30px rgba(15, 23, 42, 0.08);
    color-scheme: light;
}

html[data-theme="dark"] {
    --bg: #0f172a;
    --panel: #111827;
    --panel-soft: #1e293b;
    --text: #e5e7eb;
    --muted: #94a3b8;
    --line: #334155;
    --accent: #3b82f6;
    --positive: #22c55e;
    --negative: #ef4444;
    --shadow: 0 10px 28px rgba(0, 0, 0, 0.32);
    color-scheme: dark;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
    font-size: 13px;
    line-height: 1.35;
}

button,
input {
    font: inherit;
}

.shell {
    width: 100%;
    margin: 0 auto;
    padding: 12px 14px 18px;
}

.topbar {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 20px;
    margin-bottom: 10px;
}

h1 {
    margin: 0;
    font-size: 22px;
    line-height: 1.2;
    letter-spacing: 0;
}

.subtitle {
    margin: 4px 0 0;
    color: var(--muted);
}

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

.status-pill,
.chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-height: 28px;
    padding: 3px 8px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: var(--panel);
    color: var(--muted);
    font-size: 11px;
    white-space: nowrap;
}

.chip-reference {
    border-color: #bfdbfe;
    background: #eff6ff;
    color: #1d4ed8;
    font-weight: 700;
}

html[data-theme="dark"] .chip-reference {
    border-color: #1d4ed8;
    background: #172554;
    color: #93c5fd;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 30px;
    padding: 5px 10px;
    border: 1px solid #1d4ed8;
    border-radius: 6px;
    background: var(--accent);
    color: #ffffff;
    cursor: pointer;
    font-weight: 700;
    box-shadow: 0 8px 18px rgba(37, 99, 235, 0.18);
}

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

.btn-secondary {
    border-color: var(--line);
    background: var(--panel);
    color: var(--text);
    box-shadow: none;
}

.btn-secondary:hover {
    background: var(--panel-soft);
}

.btn:disabled {
    cursor: wait;
    opacity: 0.7;
}

.btn svg {
    width: 16px;
    height: 16px;
}

.message {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    padding: 12px;
    color: var(--muted);
    box-shadow: var(--shadow);
}

.message-error {
    border-color: #fecaca;
    background: #fff1f2;
    color: #b91c1c;
}

html[data-theme="dark"] .message-error {
    border-color: #7f1d1d;
    background: #2a1216;
    color: #fca5a5;
}

.sections {
    display: grid;
    gap: 10px;
}

.section-head {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 6px;
}

h2 {
    margin: 0;
    font-size: 17px;
    letter-spacing: 0;
}

.section-note {
    margin: 2px 0 0;
    color: var(--muted);
    font-size: 11px;
}

.cards-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
}

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

.market-card {
    min-width: 0;
    border: 1px solid var(--line);
    border-radius: 7px;
    background: var(--panel);
    box-shadow: 0 3px 12px rgba(15, 23, 42, 0.05);
    overflow: hidden;
}

.card-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 8px 10px;
    border-bottom: 1px solid var(--line);
    background: var(--panel-soft);
}

.card-title {
    min-width: 0;
}

.card-title strong {
    display: block;
    font-size: 15px;
    line-height: 1.2;
}

.card-title span {
    color: var(--muted);
    font-size: 11px;
}

.reference-box {
    text-align: right;
    color: var(--muted);
    font-size: 11px;
    white-space: nowrap;
}

.reference-box strong {
    display: block;
    color: var(--text);
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    font-size: 15px;
    line-height: 1.1;
}

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

table {
    width: 100%;
    table-layout: fixed;
    border-collapse: collapse;
    font-size: 12px;
}

th,
td {
    padding: 5px 6px;
    border-bottom: 1px solid var(--line);
    text-align: right;
    vertical-align: middle;
    white-space: nowrap;
}

th {
    position: sticky;
    top: 0;
    z-index: 1;
    background: var(--panel-soft);
    color: var(--muted);
    font-size: 11px;
    font-weight: 800;
}

th:first-child,
td:first-child {
    text-align: left;
    width: 23%;
}

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

th:nth-child(3),
td:nth-child(3),
th:nth-child(5),
td:nth-child(5),
th:nth-child(6),
td:nth-child(6) {
    width: 15%;
}

th:nth-child(4),
td:nth-child(4) {
    width: 14%;
}

tbody tr:hover {
    background: #f8fbff;
}

.base-row {
    background: #eff6ff;
}

html[data-theme="dark"] tbody tr:hover {
    background: #172033;
}

html[data-theme="dark"] .base-row {
    background: #172554;
}

.contract-code {
    font-size: 13px;
}

.mono {
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    font-variant-numeric: tabular-nums;
}

.positive {
    color: var(--positive);
    font-weight: 800;
}

.negative {
    color: var(--negative);
    font-weight: 800;
}

.neutral {
    color: var(--muted);
}

.hidden {
    display: none !important;
}

@media (max-width: 1100px) {
    .cards-grid {
        grid-template-columns: minmax(0, 1fr);
    }

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

    table {
        min-width: 520px;
    }
}

@media (max-width: 700px) {
    .shell {
        padding: 16px;
    }

    .topbar,
    .card-head {
        align-items: flex-start;
        flex-direction: column;
    }

    .actions {
        justify-content: flex-start;
        width: 100%;
    }

    h1 {
        font-size: 20px;
    }

    .reference-box {
        text-align: left;
    }
}
