/* ===================================================================
   MEV Backtest Dashboard — Dark Theme
   =================================================================== */

/* --- Reset & Variables -------------------------------------------- */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    /* Surfaces */
    --bg: #0d1117;
    --surface: #161b22;
    --surface-2: #1c2128;
    --border: #30363d;
    --border-light: #3d444d;

    /* Text */
    --text: #e6edf3;
    --text-2: #8b949e;
    --text-3: #6e7681;

    /* Accent */
    --blue: #58a6ff;
    --green: #3fb950;
    --red: #f85149;
    --yellow: #d29922;
    --purple: #bc8cff;
    --cyan: #76d9e6;

    /* Misc */
    --radius: 8px;
    --radius-sm: 4px;
    --shadow: 0 2px 8px rgba(0, 0, 0, .3);
    --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --mono: 'JetBrains Mono', 'Fira Code', 'SF Mono', monospace;
    --max-w: 960px;
    --transition: 150ms ease;
}

html {
    font-size: 15px;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
}

body {
    min-height: 100vh;
}

a {
    color: var(--blue);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

/* --- App shell ---------------------------------------------------- */
.app {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.main {
    flex: 1;
    width: 100%;
    max-width: var(--max-w);
    margin: 0 auto;
    padding: 2rem 1.25rem 4rem;
}

/* --- Header ------------------------------------------------------- */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: .75rem 1.25rem;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
}

.header__brand {
    display: flex;
    align-items: center;
    gap: .6rem;
}

.header__icon {
    font-size: 1.3rem;
}

.header__title {
    font-size: 1.05rem;
    font-weight: 600;
    letter-spacing: -.01em;
}

.header__badge {
    font-size: .65rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .06em;
    padding: 2px 6px;
    border-radius: var(--radius-sm);
    background: var(--purple);
    color: #fff;
}

.header__meta {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.header__step {
    font-size: .8rem;
    color: var(--text-2);
}

.header__github {
    font-size: .8rem;
    padding: 4px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-2);
    transition: border-color var(--transition), color var(--transition);
}

.header__github:hover {
    color: var(--text);
    border-color: var(--blue);
    text-decoration: none;
}

/* --- Footer ------------------------------------------------------- */
.footer {
    text-align: center;
    padding: 1.5rem;
    font-size: .78rem;
    color: var(--text-3);
    border-top: 1px solid var(--border);
}

/* --- Cards -------------------------------------------------------- */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem;
    margin-bottom: 1.25rem;
}

.card__title {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: .35rem;
}

.card__desc {
    font-size: .82rem;
    color: var(--text-2);
    margin-bottom: 1rem;
}

.card__hint {
    font-size: .78rem;
    color: var(--text-3);
    margin-top: .75rem;
    font-family: var(--mono);
}

/* --- Form fields -------------------------------------------------- */
.field {
    display: flex;
    flex-direction: column;
    gap: .3rem;
    margin-bottom: .85rem;
}

.field__label {
    font-size: .78rem;
    font-weight: 500;
    color: var(--text-2);
    text-transform: uppercase;
    letter-spacing: .04em;
}

.field__input,
.field__select {
    width: 100%;
    padding: .55rem .7rem;
    font-size: .88rem;
    background: var(--bg);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    outline: none;
    transition: border-color var(--transition);
    font-family: var(--font);
}

.field__input:focus,
.field__select:focus {
    border-color: var(--blue);
    box-shadow: 0 0 0 2px rgba(88, 166, 255, .15);
}

.field__input--mono {
    font-family: var(--mono);
    font-size: .85rem;
}

.field__select {
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%238b949e' viewBox='0 0 16 16'%3E%3Cpath d='M4.427 7.427l3.396 3.396a.25.25 0 00.354 0l3.396-3.396A.25.25 0 0011.396 7H4.604a.25.25 0 00-.177.427z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right .7rem center;
    padding-right: 2rem;
}

.field-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

/* --- Preset buttons ----------------------------------------------- */
.preset-grid {
    display: flex;
    flex-wrap: wrap;
    gap: .5rem;
    margin-bottom: 1rem;
}

.preset-btn {
    padding: .4rem .85rem;
    font-size: .8rem;
    font-weight: 500;
    background: var(--surface-2);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition);
    font-family: var(--font);
}

.preset-btn:hover {
    background: var(--blue);
    color: #fff;
    border-color: var(--blue);
}

/* --- Buttons ------------------------------------------------------ */
.btn {
    display: inline-flex;
    align-items: center;
    gap: .45rem;
    padding: .55rem 1.2rem;
    font-size: .88rem;
    font-weight: 600;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    cursor: pointer;
    transition: all var(--transition);
    font-family: var(--font);
}

.btn--primary {
    background: var(--blue);
    color: #fff;
}

.btn--primary:hover {
    background: #79bbff;
}

.btn--primary:disabled {
    opacity: .5;
    cursor: not-allowed;
}

.btn--secondary {
    background: transparent;
    color: var(--text);
    border-color: var(--border);
}

.btn--secondary:hover {
    border-color: var(--blue);
    color: var(--blue);
}

.btn--lg {
    padding: .7rem 2rem;
    font-size: .95rem;
    width: 100%;
    justify-content: center;
    margin-top: .5rem;
}

/* --- Alerts ------------------------------------------------------- */
.alert {
    display: flex;
    align-items: flex-start;
    gap: .5rem;
    padding: .75rem 1rem;
    border-radius: var(--radius-sm);
    font-size: .85rem;
    margin-bottom: 1rem;
}

.alert--error {
    background: rgba(248, 81, 73, .1);
    border: 1px solid rgba(248, 81, 73, .3);
    color: var(--red);
}

.alert__icon {
    flex-shrink: 0;
}

/* --- Progress bar ------------------------------------------------- */
.progress {
    position: relative;
    height: 28px;
    background: var(--bg);
    border-radius: var(--radius-sm);
    overflow: hidden;
    border: 1px solid var(--border);
    margin-bottom: 1.25rem;
}

.progress__bar {
    height: 100%;
    background: linear-gradient(90deg, var(--blue), var(--cyan));
    transition: width 300ms ease;
    border-radius: var(--radius-sm);
}

.progress__label {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: .78rem;
    font-weight: 600;
    color: var(--text);
    text-shadow: 0 1px 2px rgba(0, 0, 0, .5);
}

/* --- Running page ------------------------------------------------- */
.running {
    max-width: 640px;
    margin: 0 auto;
}

.running__card {
    text-align: center;
}

.running__stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
    margin-bottom: 1.25rem;
}

.stat {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.stat__value {
    font-size: 1.4rem;
    font-weight: 700;
    font-family: var(--mono);
    color: var(--blue);
}

.stat__label {
    font-size: .72rem;
    color: var(--text-3);
    text-transform: uppercase;
    letter-spacing: .04em;
}

/* --- Log area ----------------------------------------------------- */
.log {
    text-align: left;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    overflow: hidden;
}

.log__header {
    padding: .4rem .7rem;
    font-size: .72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--text-3);
    background: var(--surface-2);
    border-bottom: 1px solid var(--border);
}

.log__body {
    max-height: 220px;
    overflow-y: auto;
    padding: .5rem .7rem;
    background: var(--bg);
    font-family: var(--mono);
    font-size: .75rem;
    line-height: 1.6;
}

.log__line {
    color: var(--text-2);
}

.log__line--dim {
    color: var(--text-3);
    font-style: italic;
}

/* --- Summary cards ------------------------------------------------ */
.summary-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1rem;
    margin-bottom: 1.25rem;
}

.summary-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
    text-align: center;
}

.summary-card--accent {
    border-color: var(--blue);
    background: rgba(88, 166, 255, .06);
}

.summary-card__value {
    display: block;
    font-size: 1.6rem;
    font-weight: 700;
    font-family: var(--mono);
    color: var(--text);
    line-height: 1.2;
}

.summary-card--accent .summary-card__value {
    color: var(--blue);
}

.summary-card__label {
    display: block;
    margin-top: .3rem;
    font-size: .7rem;
    color: var(--text-3);
    text-transform: uppercase;
    letter-spacing: .04em;
}

/* --- Tags / Badges ------------------------------------------------ */
.tag {
    display: inline-block;
    padding: 2px 8px;
    font-size: .72rem;
    font-weight: 600;
    border-radius: var(--radius-sm);
    letter-spacing: .02em;
}

.tag--arb {
    background: rgba(63, 185, 80, .12);
    color: var(--green);
}

.tag--sand {
    background: rgba(248, 81, 73, .12);
    color: var(--red);
}

.tag--liq {
    background: rgba(210, 153, 34, .12);
    color: var(--yellow);
}

.tag--unk {
    background: rgba(139, 148, 158, .12);
    color: var(--text-2);
}

.tag--order {
    background: rgba(188, 140, 255, .12);
    color: var(--purple);
}

.breakdown {
    display: flex;
    gap: .5rem;
    margin-bottom: 1.25rem;
    flex-wrap: wrap;
}

/* --- Tabs --------------------------------------------------------- */
.tabs {
    display: flex;
    border-bottom: 1px solid var(--border);
    gap: 0;
    margin-bottom: 0;
}

.tab {
    padding: .6rem 1rem;
    font-size: .82rem;
    font-weight: 500;
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    color: var(--text-2);
    cursor: pointer;
    transition: all var(--transition);
    font-family: var(--font);
}

.tab:hover {
    color: var(--text);
}

.tab--active {
    color: var(--blue);
    border-bottom-color: var(--blue);
}

.tab-content {
    margin-top: 1rem;
    margin-bottom: 1.5rem;
}

/* --- Tables ------------------------------------------------------- */
.table-wrap {
    overflow-x: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.table {
    width: 100%;
    border-collapse: collapse;
    font-size: .82rem;
}

.table thead {
    background: var(--surface-2);
}

.table th {
    padding: .55rem .75rem;
    text-align: left;
    font-weight: 600;
    font-size: .72rem;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--text-2);
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

.table td {
    padding: .5rem .75rem;
    border-bottom: 1px solid var(--border);
    vertical-align: top;
}

.table tbody tr:hover {
    background: rgba(88, 166, 255, .04);
}

.table tbody tr:last-child td {
    border-bottom: none;
}

.cell--mono {
    font-family: var(--mono);
    font-size: .8rem;
}

.cell--dim {
    color: var(--text-3);
}

.cell--link {
    font-family: var(--mono);
    font-size: .78rem;
}

.cell--detail {
    font-size: .75rem;
    color: var(--text-2);
    max-width: 260px;
}

.cell--positive {
    color: var(--green);
    font-weight: 600;
    font-family: var(--mono);
}

.cell--negative {
    color: var(--red);
    font-weight: 600;
    font-family: var(--mono);
}

/* --- Gas usage bar (mini) ----------------------------------------- */
.gas-bar-wrap {
    display: flex;
    align-items: center;
    gap: .5rem;
    font-size: .75rem;
    font-family: var(--mono);
    color: var(--text-2);
}

.gas-bar {
    height: 6px;
    background: var(--green);
    border-radius: 3px;
    min-width: 2px;
    max-width: 80px;
}

/* --- Empty state -------------------------------------------------- */
.empty {
    text-align: center;
    padding: 2.5rem 1rem;
    color: var(--text-2);
}

.empty__hint {
    font-size: .82rem;
    color: var(--text-3);
    margin-top: .5rem;
}

/* --- Actions row -------------------------------------------------- */
.actions {
    display: flex;
    gap: .75rem;
    flex-wrap: wrap;
}

/* --- Spinner ------------------------------------------------------ */
.spinner {
    display: inline-block;
    width: 14px;
    height: 14px;
    border: 2px solid rgba(255, 255, 255, .3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin .6s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* --- Responsive --------------------------------------------------- */
@media (max-width: 700px) {
    .summary-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .field-row {
        grid-template-columns: 1fr;
    }

    .header {
        flex-direction: column;
        gap: .5rem;
        align-items: flex-start;
    }

    .header__meta {
        width: 100%;
        justify-content: space-between;
    }

    .running__stats {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 480px) {
    .summary-grid {
        grid-template-columns: 1fr 1fr;
    }

    .tabs {
        flex-wrap: wrap;
    }
}

/* --- Scrollbar (webkit) ------------------------------------------- */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: var(--bg);
}

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--border-light);
}