:root {
    --background: #f5f7fb;
    --surface: #ffffff;
    --surface-alt: #f8fafc;
    --text: #172033;
    --muted: #64748b;
    --border: #e2e8f0;
    --border-strong: #cbd5e1;
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --primary-soft: #e8f0ff;
    --success: #16a34a;
    --success-soft: #ecfdf3;
    --warning: #a16207;
    --warning-soft: #fffbeb;
    --danger: #b91c1c;
    --danger-soft: #fef2f2;
    --radius: 16px;
    --shadow: 0 8px 30px rgba(15, 23, 42, 0.06);
}

* {
    box-sizing: border-box;
}

html {
    background: var(--background);
}

body {
    margin: 0;
    font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: var(--background);
    color: var(--text);
}

button,
input {
    font: inherit;
}

button,
label {
    -webkit-tap-highlight-color: transparent;
}

.page-shell {
    width: min(100% - 32px, 1100px);
    margin: 0 auto;
    padding: 26px 0 38px;
}

.hero {
    display: flex;
    align-items: center;
    gap: 24px;
    margin-bottom: 16px;
}

.brand-link {
    display: block;
    flex: 0 0 auto;
}

.site-logo {
    display: block;
    width: 230px;
    max-width: 34vw;
    height: auto;
}

.hero-copy {
    min-width: 0;
}

.hero h1 {
    margin: 0 0 5px;
    font-size: 24px;
    line-height: 1.15;
}

.hero p,
.card-header p,
.result-header p {
    margin: 0;
    color: var(--muted);
    font-size: 13px;
}

.site-badge {
    display: inline-block;
    margin-top: 8px;
    padding: 5px 9px;
    border-radius: 999px;
    background: var(--primary-soft);
    color: var(--primary-dark);
    font-size: 12px;
    font-weight: 700;
}

.tool-card,
.result-card,
.api-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.tool-card {
    margin-bottom: 14px;
    overflow: hidden;
}

.card-header,
.result-header {
    padding: 17px 20px 10px;
}

.card-header h2,
.result-header h2 {
    margin: 0 0 5px;
    font-size: 18px;
}

.control-panel {
    padding: 10px 20px 20px;
}

.form-group {
    margin-bottom: 14px;
}

.field-label {
    display: block;
    margin-bottom: 7px;
    color: #475569;
    font-size: 11px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: .075em;
}

.segmented-control {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px;
    border: 1px solid var(--border);
    border-radius: 11px;
    background: var(--surface-alt);
}

.segmented-control input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.segmented-control label {
    min-width: 92px;
    padding: 9px 14px;
    border-radius: 8px;
    color: #475569;
    font-size: 13px;
    font-weight: 700;
    text-align: center;
    cursor: pointer;
    transition: background .15s ease, color .15s ease, box-shadow .15s ease;
}

.segmented-control input:checked + label {
    background: var(--surface);
    color: var(--primary);
    box-shadow: 0 1px 5px rgba(15, 23, 42, .10);
}

.segmented-control input:focus-visible + label {
    outline: 3px solid rgba(37, 99, 235, .18);
    outline-offset: 1px;
}

.target-group input {
    width: 100%;
    min-height: 46px;
    padding: 11px 13px;
    border: 1px solid var(--border-strong);
    border-radius: 10px;
    background: #fff;
    color: var(--text);
    font-size: 15px;
    outline: none;
    transition: border-color .15s ease, box-shadow .15s ease;
}

.target-group input:hover,
.target-group input:focus {
    border-color: var(--primary);
}

.target-group input:focus {
    box-shadow: 0 0 0 3px rgba(37, 99, 235, .11);
}

.form-row {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 18px;
}

.form-row .form-group {
    margin-bottom: 0;
}

.af-control label {
    min-width: 68px;
    padding-left: 12px;
    padding-right: 12px;
}

.button-group {
    display: flex;
    align-items: center;
    gap: 8px;
    padding-bottom: 1px;
}

.button {
    min-height: 42px;
    padding: 10px 18px;
    border-radius: 9px;
    font-size: 13px;
    font-weight: 800;
    cursor: pointer;
    transition: background .15s ease, border-color .15s ease, transform .1s ease;
}

.button:active {
    transform: translateY(1px);
}

.button-primary {
    min-width: 112px;
    border: 1px solid var(--primary);
    background: var(--primary);
    color: #fff;
}

.button-primary:hover {
    background: var(--primary-dark);
    border-color: var(--primary-dark);
}

.button-secondary {
    border: 1px solid var(--border-strong);
    background: #fff;
    color: #475569;
}

.button-secondary:hover {
    background: var(--surface-alt);
    border-color: #94a3b8;
}

.result-card {
    overflow: hidden;
    margin-bottom: 14px;
}

.result-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border);
}

.status-pill {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 6px 9px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--surface-alt);
    font-size: 12px;
    white-space: nowrap;
}

.status-label {
    color: var(--muted);
    font-weight: 600;
}

.status-null,
.status-error,
.status-done,
.status-working {
    font-weight: 800;
}

.status-null {
    color: var(--muted);
}

.status-error {
    color: var(--danger);
}

.status-done {
    color: var(--success);
}

.status-working {
    color: var(--warning);
}

.result-console {
    min-height: 235px;
    padding: 16px 18px 18px;
    background: #0f172a;
    color: #dbeafe;
    overflow: auto;
}

.monospace {
    font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
}

#output {
    min-height: 130px;
    margin: 0;
    color: #dbeafe;
    font-size: 12.5px;
    line-height: 1.55;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

#output:empty::before {
    content: "Run a test to display the result here.";
    color: #64748b;
}

.mtr-scroll {
    overflow-x: auto;
}

#mtr_output {
    width: 100%;
    margin-top: 8px;
    border-collapse: collapse;
    color: #dbeafe;
    font-size: 12px;
}

#mtr_output:empty {
    display: none;
}

#mtr_output th,
#mtr_output td {
    padding: 7px 9px;
    border-bottom: 1px solid rgba(148, 163, 184, .18);
    text-align: left;
    vertical-align: top;
    white-space: nowrap;
}

#mtr_output th {
    color: #93c5fd;
    font-weight: 800;
}

.copyable {
    text-decoration: underline;
    text-decoration-style: dotted;
    text-decoration-color: #64748b;
    text-underline-offset: 3px;
    cursor: pointer;
}

.mtr-stale-hop {
    opacity: .48;
}

.api-card {
    margin-bottom: 18px;
    overflow: hidden;
}

.api-card summary {
    padding: 14px 18px;
    color: #475569;
    font-size: 13px;
    font-weight: 800;
    cursor: pointer;
    user-select: none;
}

.api-card[open] summary {
    border-bottom: 1px solid var(--border);
}

.api-content {
    padding: 14px 18px 16px;
    color: var(--muted);
    font-size: 12.5px;
}

.api-content p {
    margin: 0 0 12px;
}

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

.api-content li + li {
    margin-top: 8px;
}

.api-content code {
    margin-right: 7px;
}

.api-content a,
.footer a {
    color: var(--primary);
    text-decoration: none;
}

.api-content a:hover,
.footer a:hover {
    text-decoration: underline;
}

.footer {
    padding: 6px 0 0;
    text-align: center;
    color: var(--muted);
    font-size: 12px;
    line-height: 1.65;
}

.footer-meta {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 6px;
}

.noscript-message {
    padding: 12px 14px;
    border: 1px solid #fecaca;
    border-radius: 10px;
    background: var(--danger-soft);
}

@media (max-width: 760px) {
    .page-shell {
        width: min(100% - 22px, 1100px);
        padding-top: 18px;
    }

   .hero {
        align-items: flex-start;
        flex-direction: column;
        gap: 12px;
    }

    .site-logo {
        width: 210px;
        max-width: 72vw;
    }

    .hero h1 {
        font-size: 22px;
    }

    .form-row,
    .result-header {
        align-items: stretch;
        flex-direction: column;
    }

    .button-group {
        width: 100%;
    }

    .button {
        flex: 1 1 0;
    }

    .status-pill {
        align-self: flex-start;
    }
}

@media (max-width: 520px) {
    .card-header,
    .result-header {
        padding-left: 15px;
        padding-right: 15px;
    }

    .control-panel {
        padding-left: 15px;
        padding-right: 15px;
    }

    .segmented-control {
        display: grid;
        width: 100%;
        grid-template-columns: repeat(3, 1fr);
    }

    .segmented-control label {
        min-width: 0;
        padding-left: 8px;
        padding-right: 8px;
    }

    .result-console {
        min-height: 210px;
        padding: 14px;
    }
}

/* =========================================================
   LOCATION SELECTOR - SAME STYLE AS MAIN PORTAL
   ========================================================= */
.hero {
    display: block;
}

.hero-top {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 20px;
    margin-bottom: 10px;
}

.hero-brand {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
}

.hero-brand .site-logo {
    margin-bottom: 6px;
}

.hero-brand h1 {
    margin: 0;
    font-size: 22px;
    line-height: 1.15;
}

.hero-copy {
    margin-top: 0;
}

.location-box {
    flex: 0 0 auto;
}

.location-label {
    padding-left: 4px;
    margin-bottom: 6px;
    color: var(--muted);
    font-size: 11px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: .075em;
}

.location-select {
    display: none;
}

.location-custom-select {
    position: relative;
    min-width: 280px;
}

.location-custom-button {
    width: 100%;
    min-height: 44px;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 42px 10px 14px;
    border: 1px solid #cbd5e1;
    border-radius: 10px;
    background: #fff;
    color: #172033;
    font: inherit;
    font-size: 14px;
    text-align: left;
    cursor: pointer;
    position: relative;
}

.location-custom-button::after {
    content: "";
    position: absolute;
    right: 15px;
    top: 50%;
    width: 8px;
    height: 8px;
    border-right: 2px solid #64748b;
    border-bottom: 2px solid #64748b;
    transform: translateY(-65%) rotate(45deg);
}

.location-custom-button:hover,
.location-custom-button:focus {
    border-color: var(--primary);
    outline: none;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, .10);
}

#locationCustomCurrent {
    display: flex;
    align-items: center;
    gap: 10px;
}

.location-custom-flag {
    width: 22px;
    height: 15px;
    flex: 0 0 auto;
    object-fit: cover;
    border-radius: 2px;
    box-shadow: 0 0 0 1px rgba(15, 23, 42, .12);
}

.location-custom-menu {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    right: 0;
    z-index: 100;
    display: none;
    padding: 5px;
    border: 1px solid #dbe2ea;
    border-radius: 10px;
    background: #fff;
    box-shadow: 0 12px 30px rgba(15, 23, 42, .14);
}

.location-custom-select.open .location-custom-menu {
    display: block;
}

.location-custom-option {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 10px;
    border: 0;
    border-radius: 7px;
    background: transparent;
    color: #172033;
    font: inherit;
    font-size: 14px;
    text-align: left;
    cursor: pointer;
}

.location-custom-option:hover,
.location-custom-option:focus,
.location-custom-option.selected {
    background: #f1f5f9;
    outline: none;
}

@media (max-width: 800px) {
    .hero-top {
        flex-direction: column;
    }

    .location-box,
    .location-custom-select {
        width: 100%;
        min-width: 0;
    }
}


/* =========================================================
   HEADER ALIGNMENT + CENTER HOME BUTTON
   ========================================================= */
.hero-top {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
    align-items: start;
    gap: 20px;
}

.hero-brand,
.hero-copy {
    margin-left: 0;
    padding-left: 0;
}

.hero-brand {
    justify-self: start;
}

.hero-home {
    justify-self: center;
    align-self: center;
    padding-top: 17px;
}

.home-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 40px;
    padding: 9px 18px;
    border: 1px solid var(--border-strong);
    border-radius: 10px;
    background: #fff;
    color: var(--text);
    font-size: 13px;
    font-weight: 800;
    text-decoration: none;
    box-shadow: 0 2px 8px rgba(15, 23, 42, .04);
    transition: border-color .15s ease, box-shadow .15s ease, color .15s ease;
}

.home-button:hover,
.home-button:focus {
    border-color: var(--primary);
    color: var(--primary);
    outline: none;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, .10);
}

.location-box {
    justify-self: end;
}

@media (max-width: 800px) {
    .hero-top {
        display: flex;
        flex-direction: column;
        align-items: stretch;
        gap: 12px;
    }

    .hero-home {
        align-self: stretch;
        padding-top: 0;
    }

    .home-button {
        width: 100%;
    }

    .location-box {
        justify-self: auto;
    }
}

/* =========================================================
   ALIGN HEADER CONTENT WITH CARD INNER CONTENT
   ========================================================= */
.hero {
    padding-left: 10px;
    padding-right: 10px;
}

@media (max-width: 520px) {
    .hero {
        padding-left: 5px;
        padding-right: 5px;
    }
}

/* =========================================================
   TEST LOCATION CARD - MATCH MAIN PORTAL
   ========================================================= */
.location-box {
    justify-self: end;
    min-width: 320px;
    padding: 13px 15px 15px;
    border: 1px solid #cbd5e1;
    border-radius: 12px;
    background: #ffffff;
    box-shadow: 0 2px 8px rgba(15, 23, 42, .03);
}

.location-label {
    padding-left: 3px;
    margin-bottom: 7px;
}

.location-custom-select {
    width: 100%;
    min-width: 288px;
}

.location-custom-button {
    min-height: 44px;
    padding: 10px 42px 10px 14px;
    border: 1px solid #cbd5e1;
    border-radius: 10px;
    background: #fff;
    box-shadow: none;
}

@media (max-width: 800px) {
    .location-box {
        width: 100%;
        min-width: 0;
        padding: 13px 15px 15px;
    }

    .location-custom-select {
        width: 100%;
        min-width: 0;
    }
}

/* =========================================================
   FINAL HEADER TUNING
   - Keep the v5 header dimensions
   - Move subtitle + site badge slightly upward
   - Match Test location label typography with the home page
   ========================================================= */
.hero-top {
    margin-bottom: 4px;
}

.location-label {
    color: var(--text);
    font-size: 12px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.08em;
}
