/* ==========================================================================
   Metrics page
   Requires site.css to be loaded first.
   ========================================================================== */

body.modal-open {
    overflow: hidden;
}

.metrics-wrap {
    width: min(var(--max), calc(100% - 40px));
    margin-inline: auto;
}

.metrics-page {
    min-height: 100vh;
    padding: 72px 0 100px;
}

.metrics-intro {
    max-width: 860px;
    margin-bottom: 54px;
}

.metrics-intro h1 {
    margin: 0.35rem 0 1.5rem;
    font-size: clamp(3.4rem, 7vw, 6.6rem);
}

.metrics-intro p {
    max-width: 790px;
    color: var(--brown-soft);
    font-size: 1.03rem;
}

.metrics-intro .metrics-lead {
    margin: 1.6rem 0;
    color: var(--brown);
    font-family:
        Georgia,
        "Times New Roman",
        serif;
    font-size: clamp(1.7rem, 3vw, 2.5rem);
    line-height: 1.2;
    letter-spacing: -0.02em;
}

.privacy-note {
    margin-top: 2rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--line);
}


/* ==========================================================================
   Robot selector
   ========================================================================== */

.robot-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin: 0 0 1.5rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--line);
}

.robot-tab {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 44px;
    padding: 0.65rem 1rem;
    border: 1px solid transparent;
    border-radius: 999px;
    color: var(--muted);
    font-size: 0.9rem;
    font-weight: 800;
    text-decoration: none;
    transition:
        background var(--transition),
        border-color var(--transition),
        color var(--transition),
        transform var(--transition);
}

.robot-tab:hover {
    transform: translateY(-1px);
    border-color: var(--line);
    background: rgba(255, 255, 255, 0.42);
    color: var(--brown);
}

.robot-tab.active {
    border-color: var(--brown);
    background: var(--brown);
    color: var(--gold-soft);
    box-shadow: 0 8px 22px rgba(43, 27, 18, 0.1);
}

.robot-tab:focus-visible,
.view-result:focus-visible,
.modal-close:focus-visible {
    outline: 3px solid rgba(199, 147, 50, 0.32);
    outline-offset: 3px;
}


/* ==========================================================================
   Broker filter
   ========================================================================== */

.metrics-filter {
    display: flex;
    align-items: end;
    gap: 1rem;
    margin: 0 0 3.75rem;
}

.metrics-filter label {
    display: block;
    margin-bottom: 0.45rem;
    color: var(--muted);
    font-size: 0.72rem;
    font-weight: 800;
    letter-spacing: 0.12em;
    text-transform: uppercase;
}

.metrics-filter select {
    min-width: 190px;
    padding: 0.78rem 2.6rem 0.78rem 0.9rem;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--paper);
    color: var(--brown);
    font-weight: 700;
    cursor: pointer;
    box-shadow: 0 7px 22px rgba(43, 27, 18, 0.035);
}


/* ==========================================================================
   Results heading
   ========================================================================== */

.results-heading {
    display: flex;
    align-items: end;
    justify-content: space-between;
    gap: 1.25rem;
    margin-bottom: 1.15rem;
}

.results-heading h2 {
    margin: 0.15rem 0 0;
    font-size: clamp(2rem, 4vw, 3.45rem);
}

.result-count {
    padding-bottom: 0.35rem;
    color: var(--muted);
    font-size: 0.88rem;
    font-weight: 650;
}


/* ==========================================================================
   Metrics table
   ========================================================================== */

.table-scroll,
.daily-scroll {
    overflow-x: auto;
    border: 1px solid var(--line);
    border-radius: 18px;
    background: rgba(255, 250, 242, 0.7);
    box-shadow: 0 14px 40px rgba(43, 27, 18, 0.04);
}

.metrics-table,
.daily-table {
    width: 100%;
    border-collapse: collapse;
}

.metrics-table th,
.metrics-table td,
.daily-table th,
.daily-table td {
    padding: 1rem 0.95rem;
    border-bottom: 1px solid var(--line-soft);
    text-align: right;
    white-space: nowrap;
}

.metrics-table th,
.daily-table th {
    background: rgba(43, 27, 18, 0.025);
    color: var(--muted);
    font-size: 0.7rem;
    font-weight: 850;
    letter-spacing: 0.095em;
    text-transform: uppercase;
}

.metrics-table th:first-child,
.metrics-table td:first-child,
.daily-table th:first-child,
.daily-table td:first-child {
    text-align: left;
}

.metrics-table tbody tr:last-child td,
.daily-table tbody tr:last-child td {
    border-bottom: 0;
}

.metrics-table tbody tr {
    transition: background var(--transition);
}

.metrics-table tbody tr:hover {
    background: rgba(199, 147, 50, 0.055);
}

.market-name {
    color: var(--brown);
    font-weight: 850;
}

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

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

.view-cell {
    text-align: right;
}

.view-result {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 38px;
    padding: 0.48rem 0.8rem;
    border: 1px solid var(--brown);
    border-radius: 999px;
    background: transparent;
    color: var(--brown);
    font-size: 0.82rem;
    font-weight: 850;
    cursor: pointer;
    transition:
        transform var(--transition),
        background var(--transition),
        border-color var(--transition),
        color var(--transition);
}

.view-result:hover {
    transform: translateY(-1px);
    border-color: var(--gold);
    background: var(--gold);
    color: var(--brown);
}

.no-results {
    padding: 2.5rem !important;
    color: var(--muted);
    text-align: center !important;
}

.metrics-footnote {
    max-width: 760px;
    margin-top: 1.35rem;
    color: var(--muted);
    font-size: 0.82rem;
}


/* ==========================================================================
   Modal
   ========================================================================== */

.result-modal {
    position: fixed;
    inset: 0;
    z-index: 9999;
    display: none;
    width: 100%;
    height: 100%;
}

.result-modal.open {
    display: block;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(27, 17, 11, 0.74);
    backdrop-filter: blur(5px);
    animation: modalFade 160ms ease-out;
}

.modal-panel {
    position: absolute;
    top: 4vh;
    right: 4vw;
    bottom: 4vh;
    left: 4vw;
    z-index: 1;
    overflow-y: auto;
    padding: clamp(2rem, 4vw, 3.8rem);
    border: 1px solid rgba(255, 255, 255, 0.55);
    border-radius: 24px;
    background:
        linear-gradient(
            180deg,
            rgba(255, 250, 242, 1) 0%,
            rgba(251, 245, 235, 1) 100%
        );
    box-shadow: var(--shadow-lg);
    animation: modalRise 190ms ease-out;
    overscroll-behavior: contain;
}

.modal-panel::-webkit-scrollbar {
    width: 11px;
}

.modal-panel::-webkit-scrollbar-track {
    background: transparent;
}

.modal-panel::-webkit-scrollbar-thumb {
    border: 3px solid transparent;
    border-radius: 999px;
    background: rgba(43, 27, 18, 0.2);
    background-clip: padding-box;
}

.modal-close {
    position: sticky;
    top: 0;
    z-index: 5;
    float: right;
    display: grid;
    width: 44px;
    height: 44px;
    place-items: center;
    margin-top: -0.6rem;
    margin-right: -0.6rem;
    border: 1px solid var(--line);
    border-radius: 50%;
    background: rgba(255, 250, 242, 0.94);
    color: var(--brown);
    font-size: 1.8rem;
    line-height: 1;
    cursor: pointer;
    box-shadow: 0 8px 24px rgba(43, 27, 18, 0.08);
    transition:
        transform var(--transition),
        border-color var(--transition),
        background var(--transition);
}

.modal-close:hover {
    transform: rotate(5deg) scale(1.04);
    border-color: var(--gold);
    background: var(--gold-pale);
}

.modal-header {
    max-width: 820px;
    margin-bottom: 2rem;
    padding-right: 3.25rem;
}

.modal-header h2 {
    margin: 0.2rem 0 0;
    font-size: clamp(2.4rem, 5vw, 4.7rem);
    letter-spacing: -0.04em;
}

.modal-loading,
.modal-error {
    padding: 5rem 0;
    color: var(--muted);
    text-align: center;
}

.modal-loading::after {
    display: block;
    width: 28px;
    height: 28px;
    margin: 1rem auto 0;
    border: 3px solid rgba(199, 147, 50, 0.22);
    border-top-color: var(--gold);
    border-radius: 50%;
    content: "";
    animation: spin 700ms linear infinite;
}

.modal-error {
    color: var(--negative);
    font-weight: 700;
}

.modal-content[hidden],
.modal-loading[hidden],
.modal-error[hidden] {
    display: none !important;
}


/* ==========================================================================
   Chart area
   ========================================================================== */

.chart-wrap {
    position: relative;
    width: 100%;
    height: min(54vh, 500px);
    margin: 0 0 2rem;
    padding: 1.2rem 1rem 0.75rem;
    border: 1px solid var(--line);
    border-radius: 18px;
    background: rgba(255, 255, 255, 0.56);
    box-shadow: 0 12px 32px rgba(43, 27, 18, 0.035);
}

.chart-wrap canvas {
    display: block;
}


/* ==========================================================================
   Modal metric strip
   ========================================================================== */

.metric-strip {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    margin: 0 0 3rem;
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: 18px;
    background: rgba(255, 255, 255, 0.46);
}

.metric-strip > div {
    min-width: 0;
    padding: 1.3rem 1.4rem;
    border-right: 1px solid var(--line);
}

.metric-strip > div:last-child {
    border-right: 0;
}

.metric-label {
    display: block;
    margin-bottom: 0.3rem;
    color: var(--muted);
    font-size: 0.68rem;
    font-weight: 850;
    letter-spacing: 0.1em;
    text-transform: uppercase;
}

.metric-strip strong {
    display: block;
    color: var(--brown);
    font-family:
        Georgia,
        "Times New Roman",
        serif;
    font-size: clamp(1.55rem, 2.5vw, 2.1rem);
    font-weight: 500;
    line-height: 1.1;
}


/* ==========================================================================
   Daily results inside modal
   ========================================================================== */

.daily-section {
    margin-top: 1rem;
}

.daily-heading {
    display: flex;
    align-items: end;
    justify-content: space-between;
    gap: 2rem;
    margin-bottom: 1rem;
}

.daily-heading h3 {
    margin: 0.15rem 0 0;
    font-size: clamp(1.8rem, 3vw, 2.45rem);
}

.daily-heading p {
    max-width: 420px;
    margin: 0 0 0.2rem;
    color: var(--muted);
    font-size: 0.88rem;
    text-align: right;
}

.daily-table td {
    background: rgba(255, 255, 255, 0.24);
}

.daily-table tbody tr:hover td {
    background: rgba(199, 147, 50, 0.045);
}


/* ==========================================================================
   Motion
   ========================================================================== */

@keyframes modalFade {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

@keyframes modalRise {
    from {
        opacity: 0;
        transform: translateY(12px) scale(0.992);
    }

    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

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


/* ==========================================================================
   Tablet
   ========================================================================== */

@media (max-width: 900px) {
    .metric-strip {
        grid-template-columns: repeat(2, 1fr);
    }

    .metric-strip > div:nth-child(2) {
        border-right: 0;
    }

    .metric-strip > div:nth-child(-n + 2) {
        border-bottom: 1px solid var(--line);
    }

    .modal-panel {
        top: 2.5vh;
        right: 2.5vw;
        bottom: 2.5vh;
        left: 2.5vw;
    }
}


/* ==========================================================================
   Mobile
   ========================================================================== */

@media (max-width: 620px) {
    .metrics-wrap {
        width: min(100% - 28px, var(--max));
    }

    .metrics-page {
        padding: 46px 0 72px;
    }

    .metrics-intro {
        margin-bottom: 2.6rem;
    }

    .metrics-intro h1 {
        font-size: clamp(3rem, 15vw, 4.8rem);
    }

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

    .robot-tab {
        width: 100%;
    }

    .metrics-filter {
        margin-bottom: 2.8rem;
    }

    .metrics-filter select {
        width: 100%;
        min-width: 0;
    }

    .metrics-filter > div {
        width: 100%;
    }

    .results-heading {
        display: block;
    }

    .result-count {
        margin-top: 0.6rem;
    }

    .table-scroll,
    .daily-scroll {
        border-radius: 14px;
    }

    .metrics-table th,
    .metrics-table td,
    .daily-table th,
    .daily-table td {
        padding: 0.85rem 0.75rem;
    }

    .modal-panel {
        top: 1.5vh;
        right: 1.5vw;
        bottom: 1.5vh;
        left: 1.5vw;
        padding: 2.8rem 1rem 1.2rem;
        border-radius: 18px;
    }

    .modal-close {
        width: 40px;
        height: 40px;
        margin-top: -1.9rem;
        margin-right: -0.15rem;
        font-size: 1.55rem;
    }

    .modal-header {
        padding-right: 0;
    }

    .modal-header h2 {
        font-size: clamp(2.3rem, 12vw, 3.4rem);
    }

    .chart-wrap {
        height: 320px;
        padding: 0.8rem 0.45rem 0.55rem;
    }

    .metric-strip {
        grid-template-columns: 1fr;
    }

    .metric-strip > div,
    .metric-strip > div:nth-child(2) {
        border-right: 0;
        border-bottom: 1px solid var(--line);
    }

    .metric-strip > div:last-child {
        border-bottom: 0;
    }

    .daily-heading {
        display: block;
    }

    .daily-heading p {
        margin-top: 0.55rem;
        text-align: left;
    }
}


/* ==========================================================================
   Reduced motion
   ========================================================================== */

@media (prefers-reduced-motion: reduce) {
    .result-modal *,
    .result-modal *::before,
    .result-modal *::after {
        transition-duration: 0.01ms !important;
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
    }
}

