:root {
    --bg: #f5f7fb;
    --surface: #ffffff;
    --surface-soft: #f9fafb;
    --text: #1f2937;
    --muted: #6b7280;
    --line: #d9dee8;
    --line-strong: #c2cad8;
    --accent: #2563eb;
    --accent-dark: #1d4ed8;
    --green: #138a62;
    --red: #c4473d;
    --amber: #c98213;
    --violet: #7c3aed;
    --shadow: 0 12px 28px rgba(31, 41, 55, 0.08);
}

* {
    box-sizing: border-box;
}

html {
    min-width: 320px;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: Arial, "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
    font-size: 15px;
    line-height: 1.45;
}

button,
input,
select {
    font: inherit;
}

.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
    padding: 26px clamp(18px, 4vw, 42px);
    border-bottom: 1px solid var(--line);
    background: var(--surface);
}

.eyebrow {
    margin: 0 0 4px;
    color: var(--accent-dark);
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
}

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

h1 {
    font-size: clamp(26px, 3vw, 38px);
    line-height: 1.15;
}

h2 {
    font-size: 18px;
}

h3 {
    font-size: 16px;
}

.run-status {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: min(100%, 260px);
    padding: 12px 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface-soft);
}

.status-dot {
    flex: 0 0 12px;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--muted);
}

.status-idle {
    background: var(--muted);
}

.status-loading {
    background: var(--amber);
    box-shadow: 0 0 0 5px rgba(201, 130, 19, 0.15);
}

.status-success {
    background: var(--green);
}

.status-error {
    background: var(--red);
}

.status-label,
.run-status small,
.section-heading span,
.metric-card span {
    color: var(--muted);
    font-size: 12px;
}

.run-status strong {
    display: block;
    margin-top: 1px;
    font-size: 16px;
}

.run-status small {
    display: block;
    margin-top: 2px;
}

.page-layout {
    display: grid;
    grid-template-columns: minmax(280px, 360px) minmax(0, 1fr);
    gap: 20px;
    align-items: start;
    width: min(1680px, 100%);
    margin: 0 auto;
    padding: 22px clamp(16px, 3vw, 32px) 42px;
}

.settings-panel,
.summary-panel,
.chart-panel,
.table-panel,
.error-panel {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    box-shadow: var(--shadow);
}

.settings-panel {
    position: sticky;
    top: 16px;
    max-height: calc(100vh - 32px);
    overflow-y: auto;
    scrollbar-gutter: stable;
    padding: 18px;
}

.results-stack {
    display: grid;
    gap: 18px;
    min-width: 0;
}

.summary-panel,
.chart-panel,
.table-panel,
.error-panel {
    padding: 18px;
}

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

.sub-heading {
    margin-top: 22px;
}

form {
    display: grid;
    gap: 16px;
}

fieldset {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 11px;
    margin: 0;
    padding: 0 0 16px;
    border: 0;
    border-bottom: 1px solid var(--line);
}

fieldset:last-of-type {
    border-bottom: 0;
    padding-bottom: 0;
}

legend {
    margin-bottom: 10px;
    color: var(--text);
    font-weight: 700;
}

label {
    display: grid;
    gap: 6px;
}

label span,
.take-profit-grid span {
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
}

input,
select {
    width: 100%;
    min-height: 38px;
    padding: 8px 10px;
    border: 1px solid var(--line-strong);
    border-radius: 6px;
    background: var(--surface);
    color: var(--text);
}

input:focus,
select:focus,
button:focus-visible {
    outline: 3px solid rgba(37, 99, 235, 0.2);
    outline-offset: 1px;
    border-color: var(--accent);
}

.check-row {
    display: flex;
    align-items: center;
    gap: 9px;
    min-height: 38px;
}

.check-row input {
    width: 17px;
    min-height: 17px;
}

.check-row span {
    color: var(--text);
    font-size: 14px;
    font-weight: 600;
}

.take-profit-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 8px;
}

.form-actions {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 0.75fr);
    gap: 10px;
}

button {
    min-height: 42px;
    border: 1px solid var(--line-strong);
    border-radius: 6px;
    cursor: pointer;
    font-weight: 700;
}

button[type="submit"] {
    border-color: var(--accent);
    background: var(--accent);
    color: #fff;
}

button[type="submit"]:hover {
    background: var(--accent-dark);
}

button[type="button"] {
    background: var(--surface-soft);
    color: var(--text);
}

button:disabled {
    cursor: wait;
    opacity: 0.65;
}

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

.metric-card {
    min-height: 88px;
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface-soft);
}

.metric-card strong {
    display: block;
    margin-top: 9px;
    overflow-wrap: anywhere;
    font-size: clamp(18px, 2vw, 24px);
    line-height: 1.15;
}

.positive {
    color: var(--green);
}

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

.legend {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 10px 14px;
    color: var(--muted);
    font-size: 12px;
}

.legend span {
    display: inline-flex;
    align-items: center;
    gap: 5px;
}

.legend i {
    width: 18px;
    height: 3px;
    border-radius: 999px;
}

.legend .legend-marker {
    width: 10px;
    height: 10px;
    border-radius: 50%;
}

.legend-bb-upper {
    background: #2563eb;
}

.legend-bb-basis {
    background: #6b7280;
}

.legend-bb-lower {
    background: #c98213;
}

.legend-st {
    background: #7c3aed;
}

.legend-be-pro {
    background: #c98213;
}

.legend-st-exit {
    background: #7c3aed;
}

.chart-box {
    position: relative;
    width: 100%;
    height: 520px;
    min-height: 320px;
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface-soft);
}

.equity-chart-box {
    height: 300px;
}

.chart-placeholder {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    padding: 18px;
    color: var(--muted);
    text-align: center;
}

.chart-tooltip {
    position: absolute;
    z-index: 3;
    min-width: 210px;
    padding: 10px 11px;
    border: 1px solid var(--line-strong);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.96);
    box-shadow: 0 10px 24px rgba(31, 41, 55, 0.14);
    pointer-events: none;
}

.tooltip-title {
    margin-bottom: 7px;
    color: var(--text);
    font-size: 12px;
    font-weight: 700;
}

.tooltip-grid {
    display: grid;
    grid-template-columns: auto auto;
    gap: 4px 14px;
    font-size: 12px;
}

.tooltip-grid span:nth-child(odd) {
    color: var(--muted);
}

.tooltip-grid span:nth-child(even) {
    color: var(--text);
    font-weight: 700;
    text-align: right;
}

.tooltip-grid .positive {
    color: var(--green);
}

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

.table-scroll {
    overflow-x: auto;
    border: 1px solid var(--line);
    border-radius: 8px;
}

table {
    width: 100%;
    min-width: 980px;
    border-collapse: collapse;
    background: var(--surface);
}

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

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

th:first-child,
td:first-child,
td:nth-child(2),
th:nth-child(2),
td:nth-child(3),
th:nth-child(3) {
    text-align: left;
}

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

.empty-table {
    height: 58px;
    color: var(--muted);
    text-align: center;
}

.error-panel {
    border-color: rgba(196, 71, 61, 0.35);
    background: #fffafa;
}

.error-panel h2 {
    color: var(--red);
}

.error-message {
    margin-bottom: 12px;
    font-weight: 700;
}

.field-errors {
    display: grid;
    gap: 7px;
    margin: 0;
    padding-left: 18px;
    color: var(--text);
}

@media (max-width: 1180px) {
    .summary-grid {
        grid-template-columns: repeat(2, minmax(130px, 1fr));
    }
}

@media (max-width: 980px) {
    .app-header {
        align-items: stretch;
        flex-direction: column;
    }

    .page-layout {
        grid-template-columns: 1fr;
    }

    .settings-panel {
        position: static;
        max-height: none;
        overflow-y: visible;
    }
}

@media (max-width: 640px) {
    .app-header {
        padding: 20px 16px;
    }

    .page-layout {
        padding: 16px 12px 28px;
    }

    .settings-panel,
    .summary-panel,
    .chart-panel,
    .table-panel,
    .error-panel {
        padding: 14px;
    }

    .section-heading {
        align-items: flex-start;
        flex-direction: column;
        gap: 6px;
    }

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

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

    .chart-box {
        height: 380px;
    }

    .equity-chart-box {
        height: 260px;
    }
}
