:root {
    color-scheme: light;
    --bg: #f6f8fb;
    --surface: #ffffff;
    --surface-raised: #fdfefe;
    --surface-muted: #eef3f7;
    --border: #d8e1ea;
    --border-strong: #b8c7d6;
    --text: #17212b;
    --muted: #5c6b78;
    --faint: #82909d;
    --accent: #0f766e;
    --accent-strong: #0b5f59;
    --accent-soft: #d7f3ee;
    --success: #137a42;
    --success-soft: #dcf7e8;
    --warning: #9a5b00;
    --warning-soft: #fff1cb;
    --error: #b42318;
    --error-soft: #ffe3df;
    --info: #2457a6;
    --info-soft: #e1ecff;
    --shadow: 0 10px 24px rgba(23, 33, 43, 0.07);
}

* {
    box-sizing: border-box;
}

html {
    min-width: 320px;
}

body {
    margin: 0;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    background: linear-gradient(180deg, #fbfcfe 0%, var(--bg) 280px);
    color: var(--text);
    font-size: 15px;
    line-height: 1.5;
}

a {
    color: inherit;
}

button,
input,
select,
textarea {
    font: inherit;
}

.page-header,
.page-shell {
    max-width: 1260px;
    margin: 0 auto;
    padding: 24px;
}

.page-header {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 20px;
    align-items: end;
}

.page-header h1 {
    margin: 2px 0 4px;
    font-size: clamp(1.9rem, 3vw, 2.9rem);
    line-height: 1.05;
    letter-spacing: 0;
}

.page-header nav {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.page-header nav a,
.button-link,
button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 38px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    padding: 9px 13px;
    border-radius: 8px;
    text-decoration: none;
    cursor: pointer;
    font-weight: 700;
    line-height: 1.1;
    box-shadow: 0 1px 0 rgba(23, 33, 43, 0.04);
    transition: border-color 0.15s ease, box-shadow 0.15s ease, color 0.15s ease, background 0.15s ease;
}

.page-header nav a:hover,
.button-link:hover,
button:hover {
    border-color: var(--accent);
    color: var(--accent-strong);
    box-shadow: 0 8px 18px rgba(15, 118, 110, 0.12);
}

.page-header nav a.active,
.page-header nav a[aria-current="page"] {
    background: var(--accent);
    border-color: var(--accent);
    color: #ffffff;
}

.eyebrow {
    margin: 0;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    font-size: 0.72rem;
    font-weight: 800;
    color: var(--accent);
}

h1,
h2,
h3 {
    margin-top: 0;
    line-height: 1.15;
    letter-spacing: 0;
}

h2 {
    margin-bottom: 10px;
    font-size: 1.05rem;
}

h3 {
    margin-bottom: 8px;
    font-size: 0.95rem;
}

.subtle {
    margin-bottom: 0;
    color: var(--muted);
    max-width: 66ch;
}

.page-shell {
    display: grid;
    gap: 18px;
    padding-top: 4px;
    padding-bottom: 42px;
}

.page-shell > *,
.detail-grid > *,
.stats-grid > *,
.metrics-grid > * {
    min-width: 0;
}

.journal-shell {
    max-width: 100%;
    padding-left: 16px;
    padding-right: 16px;
}

.action-strip,
.summary-strip {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    align-items: center;
}

.action-strip {
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.78);
}

.detail-grid {
    display: grid;
    gap: 18px;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
}

.stats-grid,
.metrics-grid {
    display: grid;
    gap: 14px;
    grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
}

.stat-card {
    min-height: 118px;
}

.stat-card h2,
.metrics-grid .card .eyebrow {
    margin-bottom: 8px;
    color: var(--muted);
    font-size: 0.78rem;
    font-weight: 800;
    text-transform: uppercase;
}

.stat-card p,
.metrics-grid .card h2 {
    margin: 0;
    font-size: clamp(1.5rem, 2.3vw, 2.2rem);
    font-weight: 800;
    color: var(--text);
}

.equity-chart {
    width: 100%;
    height: 220px;
    display: block;
    margin-bottom: 16px;
    background: var(--surface-muted);
    border: 1px solid var(--border);
    border-radius: 8px;
}

.pager,
.button-row {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    align-items: center;
}

.pager {
    margin-top: 16px;
}

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 18px;
    box-shadow: var(--shadow);
    min-width: 0;
}

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

.section-heading h2 {
    margin-bottom: 0;
}

.badge,
.pill,
.status-badge {
    display: inline-flex;
    align-items: center;
    width: fit-content;
    min-height: 26px;
    padding: 5px 9px;
    border-radius: 999px;
    background: var(--surface-muted);
    color: var(--muted);
    font-size: 0.78rem;
    font-weight: 800;
    white-space: nowrap;
}

.badge.neutral {
    background: var(--info-soft);
    color: var(--info);
}

.pill.LONG,
.status-badge.LONG,
.status-badge.TRADE,
.status-badge.APPROVED,
.status-badge.OPEN,
.status-badge.EXECUTED,
.status-badge.CLOSED,
.status-badge.WIN,
.status-badge.ANALYZED {
    background: var(--success-soft);
    color: var(--success);
}

.pill.SHORT,
.status-badge.SHORT,
.status-badge.REJECT,
.status-badge.REJECTED,
.status-badge.SKIP,
.status-badge.FAILED,
.status-badge.LOSS,
.status-badge.CANCELLED,
.status-badge.EXPIRED {
    background: var(--error-soft);
    color: var(--error);
}

.status-badge.WAIT,
.status-badge.PENDING,
.status-badge.PENDING_APPROVAL,
.status-badge.READY_FOR_REVIEW,
.status-badge.BREAKEVEN {
    background: var(--warning-soft);
    color: var(--warning);
}

.table-wrap {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    overflow-x: auto;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface-raised);
    overscroll-behavior-x: contain;
}

.journal-table {
    min-width: 1520px;
}

.journal-detail-row:hover {
    background: transparent;
}

.journal-detail-cell {
    padding: 0;
    background: var(--surface-raised);
}

.journal-detail-panel {
    position: sticky;
    left: 0;
    width: min(100%, calc(100vw - 48px));
    max-width: calc(100vw - 48px);
    margin: 8px;
    overflow-x: auto;
    overscroll-behavior-x: contain;
}

.journal-detail-grid {
    margin-top: 1rem;
    min-width: 0;
}

.journal-detail-grid p,
.journal-detail-grid span {
    overflow-wrap: anywhere;
}

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

.selected-row {
    background: rgba(46, 125, 50, 0.08);
}

th,
td {
    padding: 11px 12px;
    border-bottom: 1px solid rgba(92, 107, 120, 0.16);
    text-align: left;
    vertical-align: top;
}

thead th {
    position: sticky;
    top: 0;
    z-index: 1;
    background: var(--surface-muted);
    color: var(--muted);
    font-size: 0.74rem;
    text-transform: uppercase;
    font-weight: 800;
}

tbody tr:hover {
    background: rgba(15, 118, 110, 0.045);
}

tbody tr:last-child td {
    border-bottom: 0;
}

td a {
    color: var(--accent-strong);
    font-weight: 800;
    text-decoration: none;
}

td a:hover {
    text-decoration: underline;
}

.compact-table th,
.compact-table td {
    padding: 9px 10px;
    font-size: 0.9rem;
}

.empty-state {
    text-align: center;
    color: var(--muted);
    padding: 30px 12px;
}

.empty-state .button-link {
    margin-top: 12px;
}

.detail-list {
    display: grid;
    gap: 0;
    margin: 0;
}

.detail-list div {
    display: flex;
    justify-content: space-between;
    gap: 20px;
    padding: 10px 0;
    border-bottom: 1px solid rgba(92, 107, 120, 0.15);
}

.detail-list div:first-child {
    padding-top: 0;
}

.detail-list div:last-child {
    border-bottom: 0;
    padding-bottom: 0;
}

dt {
    color: var(--muted);
    font-weight: 700;
}

dd {
    margin: 0;
    text-align: right;
    font-weight: 750;
}

.stack > div + div,
.stack > form + form,
.stack > h3 + form {
    margin-top: 16px;
}

.analysis-text,
.note-box,
details {
    padding: 13px 14px;
    border-radius: 8px;
    background: var(--surface-muted);
}

details {
    border: 1px solid var(--border);
}

details summary {
    cursor: pointer;
    font-weight: 800;
}

.collapsible-card {
    padding: 18px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
    box-shadow: var(--shadow);
}

.collapsible-card[open] > .collapsible-summary {
    margin-bottom: 16px;
    padding-bottom: 14px;
    border-bottom: 1px solid rgba(92, 107, 120, 0.15);
}

.collapsible-summary {
    display: grid;
    gap: 4px;
    color: var(--text);
}

.collapsible-summary::marker {
    color: var(--accent);
}

.collapsible-title {
    font-size: 1.05rem;
    line-height: 1.15;
}

.collapsible-description,
.metric-note,
.section-description {
    color: var(--muted);
    font-weight: 500;
}

.collapsible-description,
.metric-note {
    font-size: 0.88rem;
}

.metric-note {
    display: block;
    margin-top: 8px;
}

.section-description {
    margin: -2px 0 12px;
    font-size: 0.9rem;
}

pre {
    max-width: 100%;
    overflow: auto;
    margin: 10px 0 0;
    padding: 12px;
    border-radius: 8px;
    background: #111827;
    color: #eef7ff;
    font-size: 0.82rem;
}

.decision-form,
.runtime-config-form {
    display: grid;
    gap: 14px;
}

.filter-grid,
.config-grid {
    display: grid;
    gap: 14px;
    grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
}

.filter-grid label,
.config-field {
    display: grid;
    gap: 7px;
    align-content: start;
    color: var(--muted);
    font-weight: 800;
}

.config-section {
    scroll-margin-top: 18px;
}

.config-label {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    align-items: center;
    color: var(--text);
    font-weight: 800;
}

.config-field .subtle {
    font-weight: 500;
    font-size: 0.9rem;
}

.config-field input[type="checkbox"] {
    width: 22px;
    height: 22px;
}

.sticky-actions {
    position: sticky;
    bottom: 12px;
    display: flex;
    justify-content: flex-end;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: rgba(246, 248, 251, 0.88);
    backdrop-filter: blur(10px);
}

input,
select,
textarea {
    width: 100%;
    padding: 11px 12px;
    border-radius: 8px;
    border: 1px solid var(--border-strong);
    background: #ffffff;
    color: var(--text);
}

input:focus,
select:focus,
textarea:focus,
button:focus-visible,
a:focus-visible {
    outline: 3px solid rgba(15, 118, 110, 0.22);
    outline-offset: 2px;
}

textarea {
    resize: vertical;
}

.alert {
    margin-bottom: 0;
    padding: 13px 14px;
    border-radius: 8px;
    border: 1px solid transparent;
    font-weight: 700;
}

.alert.success {
    background: var(--success-soft);
    border-color: rgba(19, 122, 66, 0.22);
    color: var(--success);
}

.alert.error {
    background: var(--error-soft);
    border-color: rgba(180, 35, 24, 0.22);
    color: var(--error);
}

.error-card {
    max-width: 680px;
    margin: 56px auto;
}

ul {
    margin: 0;
    padding-left: 18px;
}

li + li {
    margin-top: 6px;
}

@media (max-width: 860px) {
    .page-header {
        grid-template-columns: 1fr;
        align-items: start;
    }

    .page-header nav {
        justify-content: flex-start;
    }
}

@media (max-width: 640px) {
    .page-header,
    .page-shell {
        padding-left: 14px;
        padding-right: 14px;
    }

    .page-header nav {
        display: grid;
        grid-template-columns: repeat(3, minmax(0, 1fr));
        width: 100%;
    }

    .page-header nav a {
        padding-left: 8px;
        padding-right: 8px;
    }

    .card {
        padding: 14px;
    }

    .journal-detail-panel {
        width: calc(100vw - 28px);
        max-width: calc(100vw - 28px);
    }

    .detail-list div,
    .section-heading {
        flex-direction: column;
        align-items: flex-start;
    }

    dd {
        text-align: left;
    }

    .sticky-actions {
        justify-content: stretch;
    }

    .sticky-actions button {
        width: 100%;
    }
}
