:root {
    --bg: #f8fafc;
    --surface: #ffffff;
    --surface-soft: #f1f5f9;
    --text: #111827;
    --muted: #64748b;
    --line: #e5e7eb;
    --accent: #4f46e5;
    --accent-strong: #4338ca;
    --accent-soft: #eef2ff;
    --amber: #a16207;
    --red: #dc2626;
    --blue: #2563eb;
    --green: #059669;
    --shadow: 0 2px 15px -3px rgba(0, 0, 0, 0.07), 0 10px 20px -2px rgba(0, 0, 0, 0.04);
    --radius: 12px;
}

* {
    box-sizing: border-box;
}

html {
    min-height: 100%;
    background: var(--bg);
    overflow-x: hidden;
}

body {
    margin: 0;
    color: var(--text);
    font-family: Tahoma, "Segoe UI", ui-sans-serif, system-ui, sans-serif;
    font-size: 14px;
    line-height: 1.75;
    background: var(--bg);
    overflow-x: hidden;
}

button,
input,
select {
    font: inherit;
}

button {
    cursor: pointer;
}

.app-shell {
    width: min(1680px, calc(100% - 32px));
    margin: 0 auto;
    padding: 18px 0 36px;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    min-height: 82px;
    padding: 12px 16px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: rgba(255, 255, 255, 0.95);
    box-shadow: var(--shadow);
}

.brand {
    display: flex;
    align-items: center;
    gap: 14px;
    min-width: 0;
}

.brand > div:last-child {
    min-width: 0;
}

.brand-logo {
    flex: 0 0 52px;
    width: 52px;
    height: 52px;
    object-fit: contain;
}

h1,
h2,
h3,
p {
    margin: 0;
}

h1 {
    color: var(--accent-strong);
    font-size: 1.35rem;
    font-weight: 800;
    letter-spacing: 0;
    overflow-wrap: anywhere;
}

h2 {
    font-size: 1.08rem;
    font-weight: 800;
}

h3 {
    font-size: 1rem;
}

.brand p,
.section-head p {
    color: var(--muted);
    margin-top: 2px;
    overflow-wrap: anywhere;
}

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

.status-pill {
    min-width: 150px;
    padding: 8px 12px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: var(--surface-soft);
    color: var(--muted);
    text-align: center;
    white-space: nowrap;
}

.status-pill.is-open {
    color: #166534;
    border-color: #bbf7d0;
    background: #f0fdf4;
}

.icon-button {
    display: inline-grid;
    place-items: center;
    width: 40px;
    height: 40px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text);
    font-size: 1.1rem;
}

.icon-button:hover {
    border-color: #c7d2fe;
    background: var(--accent-soft);
    color: var(--accent-strong);
}

.control-band,
.section-head,
.tabs,
.kpi-grid {
    margin-top: 18px;
}

.control-band {
    display: grid;
    grid-template-columns: minmax(260px, 1.4fr) minmax(170px, 0.7fr) minmax(170px, 0.7fr) auto;
    align-items: end;
    gap: 12px;
    padding: 16px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: var(--shadow);
}

.field {
    display: grid;
    gap: 6px;
}

.field span,
.toggle-field {
    color: var(--muted);
    font-size: 0.86rem;
}

.field input,
.field select {
    width: 100%;
    height: 40px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text);
    padding: 0 10px;
}

.field input:focus,
.field select:focus {
    outline: 2px solid rgba(79, 70, 229, 0.16);
    border-color: var(--accent);
}

.wide-field {
    min-width: 0;
}

.compact-field {
    min-width: 170px;
}

.money-field {
    min-width: 230px;
}

.money-field input {
    direction: ltr;
    text-align: left;
    font-variant-numeric: tabular-nums;
}

.apply-capital-button {
    align-self: end;
    min-height: 40px;
}

.toggle-field {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 40px;
    padding: 0 12px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
    white-space: nowrap;
}

.toggle-field input {
    width: 16px;
    height: 16px;
    accent-color: var(--accent);
}

.kpi-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 12px;
}

.kpi-card {
    display: grid;
    gap: 4px;
    min-height: 88px;
    padding: 16px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

.kpi-card span {
    color: var(--muted);
}

.kpi-card strong {
    font-size: 1.55rem;
    font-weight: 800;
}

.kpi-card.accent {
    border-color: #c7d2fe;
    background: var(--accent-soft);
    color: #312e81;
}

.tabs {
    display: inline-flex;
    gap: 4px;
    padding: 5px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: var(--surface);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

.tab {
    min-width: 150px;
    min-height: 38px;
    border: 0;
    border-radius: 999px;
    background: transparent;
    color: var(--muted);
    padding: 7px 16px;
    transition: background-color 150ms ease, color 150ms ease, box-shadow 150ms ease;
}

.tab.is-active {
    color: #fff;
    background: var(--accent);
    font-weight: 700;
    box-shadow: 0 8px 18px rgba(79, 70, 229, 0.22);
}

.panel {
    display: none;
    padding-top: 18px;
}

.panel.is-active {
    display: block;
}

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

.strategy-controls {
    display: flex;
    gap: 10px;
    align-items: end;
}

.notice {
    margin-top: 12px;
    padding: 10px 12px;
    border: 1px solid #fde68a;
    border-radius: var(--radius);
    background: #fefce8;
    color: #6e4b12;
}

.table-wrap {
    margin-top: 12px;
    overflow: auto;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: var(--shadow);
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    min-width: 1120px;
}

.data-table th,
.data-table td {
    padding: 10px;
    border-bottom: 1px solid var(--line);
    text-align: right;
    vertical-align: top;
}

.data-table th {
    position: sticky;
    top: 0;
    z-index: 1;
    background: #f8fafc;
    color: #475569;
    font-weight: 700;
    white-space: nowrap;
}

.data-table tbody tr:hover {
    background: #f8fafc;
}

.symbol-cell {
    display: grid;
    gap: 2px;
}

.symbol-cell strong {
    font-size: 0.96rem;
}

.symbol-cell span,
.muted {
    color: var(--muted);
    font-size: 0.82rem;
}

.price-line {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-items: center;
}

.quote-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    min-height: 24px;
    padding: 2px 7px;
    border-radius: 999px;
    border: 1px solid var(--line);
    background: #f8fafc;
    white-space: nowrap;
}

.quote-badge.buy {
    color: var(--red);
    border-color: #fecaca;
    background: #fef2f2;
}

.quote-badge.sell {
    color: #047857;
    border-color: #bbf7d0;
    background: #f0fdf4;
}

.quote-badge.neutral {
    color: var(--blue);
    border-color: #bfdbfe;
    background: #eff6ff;
}

.edge-positive {
    color: var(--green);
    font-weight: 700;
}

.edge-negative {
    color: var(--red);
}

.mini-button {
    min-height: 34px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--accent-strong);
    padding: 5px 10px;
    white-space: nowrap;
    font-weight: 700;
}

.mini-button:hover {
    border-color: #c7d2fe;
    background: var(--accent-soft);
}

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

.endpoint-card,
.field-map {
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
    padding: 14px;
}

.endpoint-card {
    display: grid;
    gap: 8px;
}

.endpoint-card code {
    direction: ltr;
    display: block;
    overflow-wrap: anywhere;
    padding: 8px;
    border-radius: 6px;
    background: #f8fafc;
    color: #334155;
    font-family: Consolas, "Liberation Mono", monospace;
    font-size: 0.82rem;
}

.field-map {
    margin-top: 12px;
}

.field-list {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
    margin-top: 10px;
}

.field-item {
    padding: 10px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: #f8fafc;
}

.field-item code {
    direction: ltr;
    unicode-bidi: plaintext;
    color: var(--blue);
}

.drawer {
    position: fixed;
    inset: 0;
    display: none;
    background: rgba(15, 23, 42, 0.42);
    z-index: 20;
}

.drawer.is-open {
    display: block;
}

.drawer-panel {
    position: absolute;
    inset: 0 0 0 auto;
    width: min(760px, 100%);
    overflow: auto;
    padding: 18px;
    background: var(--surface);
    box-shadow: -10px 0 40px rgba(15, 23, 42, 0.18);
}

.drawer-head {
    display: flex;
    align-items: start;
    justify-content: space-between;
    gap: 16px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--line);
}

.drawer-head p {
    color: var(--muted);
    margin-top: 2px;
}

.order-grid {
    display: grid;
    gap: 14px;
    margin-top: 14px;
}

.order-book {
    border: 1px solid var(--line);
    border-radius: var(--radius);
    overflow: hidden;
}

.order-book h3 {
    padding: 10px 12px;
    background: #f8fafc;
    border-bottom: 1px solid var(--line);
}

.order-book table {
    width: 100%;
    border-collapse: collapse;
}

.order-book th,
.order-book td {
    padding: 8px 10px;
    border-bottom: 1px solid var(--line);
    text-align: right;
}

.toast {
    position: fixed;
    left: 18px;
    bottom: 18px;
    max-width: min(460px, calc(100% - 36px));
    padding: 10px 12px;
    border-radius: var(--radius);
    background: #111827;
    color: #fff;
    opacity: 0;
    transform: translateY(8px);
    pointer-events: none;
    transition: opacity 160ms ease, transform 160ms ease;
    z-index: 30;
}

.toast.is-visible {
    opacity: 1;
    transform: translateY(0);
}

.empty-row {
    text-align: center;
    color: var(--muted);
    padding: 22px !important;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    border: 0;
}

@media (max-width: 980px) {
    .app-shell {
        width: calc(100% - 20px);
    }

    .topbar,
    .section-head {
        align-items: stretch;
        flex-direction: column;
    }

    .brand {
        width: 100%;
        align-items: flex-start;
    }

    .control-band {
        grid-template-columns: 1fr 1fr;
    }

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

    .strategy-controls {
        flex-wrap: wrap;
    }
}

@media (max-width: 640px) {
    body {
        font-size: 13px;
    }

    .control-band,
    .kpi-grid,
    .field-list {
        grid-template-columns: 1fr;
    }

    .tabs {
        overflow-x: auto;
    }

    .tab {
        flex: 0 0 auto;
    }

    .top-actions {
        justify-content: space-between;
    }
}
