/* =====================================================================
   Speed Checker Starter - site styles (on top of Bootstrap 5.3)
   Colours are tokens: change them here to re-brand. Dark theme below.
   ===================================================================== */
:root,
[data-bs-theme="light"] {
    --app-bg: #f5f7fb;
    --app-surface: #ffffff;
    --app-surface-2: #f0f3f9;
    --app-border: #dfe4ee;
    --app-text: #1b2233;
    --app-muted: #5a6478;
    --app-brand: #3d5afe;
    --app-brand-strong: #2a44d8;
    --app-brand-soft: #e8ecff;
    --app-accent: #11a683;
    --app-good: #0b8043;
    --app-good-soft: #e3f5ea;
    --app-average: #b35c00;
    --app-average-soft: #fff1dd;
    --app-poor: #c62828;
    --app-poor-soft: #fde7e7;
    --app-none: #7a8499;
    --app-shadow: 0 1px 2px rgba(20, 30, 60, .06), 0 6px 24px rgba(20, 30, 60, .06);
    --bs-body-bg: var(--app-bg);
    --bs-body-color: var(--app-text);
    --bs-primary: var(--app-brand);
    --bs-primary-rgb: 61, 90, 254;
    --bs-link-color: var(--app-brand-strong);
    --bs-link-color-rgb: 42, 68, 216;
    --bs-link-hover-color: var(--app-brand);
    --bs-border-color: var(--app-border);
    --bs-secondary-color: var(--app-muted);
}

[data-bs-theme="dark"] {
    --app-bg: #0f1420;
    --app-surface: #171d2b;
    --app-surface-2: #1f2637;
    --app-border: #2c3448;
    --app-text: #e6e9f2;
    --app-muted: #a3acc0;
    --app-brand: #7d93ff;
    --app-brand-strong: #9eaeff;
    --app-brand-soft: #232c4d;
    --app-accent: #3dd6ae;
    --app-good: #3ccf7f;
    --app-good-soft: #133224;
    --app-average: #ffab40;
    --app-average-soft: #3a2a12;
    --app-poor: #ff6b6b;
    --app-poor-soft: #3d1a1d;
    --app-none: #8a93a8;
    --app-shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .25);
    --bs-body-bg: var(--app-bg);
    --bs-body-color: var(--app-text);
    --bs-primary-rgb: 125, 147, 255;
    --bs-link-color: var(--app-brand-strong);
    --bs-link-color-rgb: 158, 174, 255;
    --bs-link-hover-color: #c3ccff;
    --bs-border-color: var(--app-border);
    --bs-secondary-color: var(--app-muted);
}

/* ---- Base: large readable text ---- */
html { font-size: 18px; }
body {
    background: var(--app-bg);
    color: var(--app-text);
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", "Noto Sans", "Noto Sans Thai", Arial, sans-serif;
    line-height: 1.6;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}
main { flex: 1 0 auto; }
.narrow { max-width: 860px; }
.eyebrow { text-transform: uppercase; letter-spacing: .06em; font-size: .78rem; font-weight: 700; color: var(--app-muted); margin-bottom: .25rem; }
.text-body-secondary { color: var(--app-muted) !important; }
.skip-link { position: absolute; left: 1rem; top: .5rem; z-index: 1000; background: var(--app-surface); padding: .5rem 1rem; border-radius: .5rem; }

.btn { font-weight: 600; border-radius: .7rem; }
.btn-primary { --bs-btn-bg: var(--app-brand); --bs-btn-border-color: var(--app-brand); --bs-btn-hover-bg: var(--app-brand-strong); --bs-btn-hover-border-color: var(--app-brand-strong); --bs-btn-active-bg: var(--app-brand-strong); --bs-btn-disabled-bg: var(--app-brand); --bs-btn-disabled-border-color: var(--app-brand); }
[data-bs-theme="dark"] .btn-primary { --bs-btn-color: #0f1420; --bs-btn-hover-color: #0f1420; --bs-btn-active-color: #0f1420; --bs-btn-disabled-color: #0f1420; }
.form-control { border-radius: .7rem; background-color: var(--app-surface); border-color: var(--app-border); color: var(--app-text); }
.form-control:focus { border-color: var(--app-brand); box-shadow: 0 0 0 .25rem rgba(var(--bs-primary-rgb), .2); }
:focus-visible { outline: 3px solid var(--app-brand); outline-offset: 2px; }
.card { background: var(--app-surface); border: 1px solid var(--app-border); border-radius: 1rem; box-shadow: var(--app-shadow); }

/* ---- Header / footer ---- */
.demo-banner { background: #ffe08a; color: #3d2e00; text-align: center; font-weight: 600; padding: .45rem 1rem; font-size: .9rem; }
.site-header { background: var(--app-surface); border-bottom: 1px solid var(--app-border); position: sticky; top: 0; z-index: 20; }
.brand { display: flex; align-items: center; gap: .6rem; font-weight: 800; font-size: 1.15rem; color: var(--app-text); text-decoration: none; }
.brand:hover { color: var(--app-text); }
.nav-link-plain { color: var(--app-muted); text-decoration: none; font-weight: 600; padding: .4rem .6rem; border-radius: .5rem; font-size: .95rem; }
.nav-link-plain:hover { color: var(--app-text); background: var(--app-surface-2); }
.btn-icon { border: 1px solid var(--app-border); background: transparent; color: var(--app-text); border-radius: .6rem; width: 42px; height: 42px; display: inline-flex; align-items: center; justify-content: center; }
.btn-icon:hover { background: var(--app-surface-2); }
[data-bs-theme="dark"] .icon-moon, [data-bs-theme="light"] .icon-sun { display: none; }
.site-footer { margin-top: 3rem; padding: 2rem 0; border-top: 1px solid var(--app-border); color: var(--app-muted); font-size: .85rem; background: var(--app-surface); }
@media (max-width: 575.98px) {
    .brand span { font-size: 1rem; }
    .nav-link-plain { font-size: .85rem; padding: .35rem .4rem; }
}

/* ---- Home ---- */
.hero {
    padding: 4.5rem 0 3.5rem;
    background:
        radial-gradient(900px 400px at 15% -10%, rgba(61, 90, 254, .14), transparent 70%),
        radial-gradient(700px 380px at 95% 10%, rgba(17, 166, 131, .13), transparent 70%);
}
.hero-inner { max-width: 820px; margin: 0 auto; text-align: center; }
.hero-title { font-size: clamp(2.1rem, 5vw, 3.3rem); font-weight: 800; letter-spacing: -.02em; line-height: 1.15; margin-bottom: 1rem; }
.hero-lead { font-size: 1.15rem; color: var(--app-muted); margin: 0 auto 2rem; max-width: 680px; }
.test-form, .progress-card { text-align: left; background: var(--app-surface); border: 1px solid var(--app-border); border-radius: 1.2rem; padding: 1.5rem; box-shadow: var(--app-shadow); }
.test-form-row { display: flex; gap: .75rem; }
.test-form-row .form-control { font-size: 1.15rem; padding: .85rem 1.1rem; }
.btn-analyze { padding-left: 2rem; padding-right: 2rem; white-space: nowrap; }
.limit-note { margin: .9rem 0 0; font-size: .85rem; color: var(--app-muted); }
@media (max-width: 575.98px) {
    .test-form-row { flex-direction: column; }
    .hero { padding-top: 2.5rem; }
}
.progress-url { font-weight: 600; word-break: break-all; }
.progress { height: .8rem; border-radius: 1rem; background: var(--app-surface-2); }
.progress-bar { background-color: var(--app-brand); transition: width .6s ease; }
.steps { list-style: none; padding: 0; margin: 0 0 1.25rem; }
.steps li { display: flex; align-items: center; gap: .75rem; padding: .35rem 0; color: var(--app-muted); }
.step-dot { width: 1.1rem; height: 1.1rem; border-radius: 50%; border: 2px solid var(--app-border); flex: none; position: relative; }
.steps li.active { color: var(--app-text); font-weight: 600; }
.steps li.active .step-dot { border-color: var(--app-brand); border-top-color: transparent; animation: spin .9s linear infinite; }
.steps li.done { color: var(--app-text); }
.steps li.done .step-dot { background: var(--app-good); border-color: var(--app-good); }
.steps li.done .step-dot::after { content: ""; position: absolute; left: .3rem; top: .1rem; width: .3rem; height: .55rem; border: solid #fff; border-width: 0 2px 2px 0; transform: rotate(45deg); }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .steps li.active .step-dot { animation: none; border-top-color: var(--app-brand); } }

.features { padding-top: 1rem; }
.feature { height: 100%; background: var(--app-surface); border: 1px solid var(--app-border); border-radius: 1rem; padding: 1.5rem; }
.feature p { color: var(--app-muted); margin: 0; }
.feature-icon { width: 3rem; height: 3rem; border-radius: .8rem; display: flex; align-items: center; justify-content: center; background: var(--app-brand-soft); color: var(--app-brand); margin-bottom: 1rem; }

/* ---- Ratings ---- */
.rating-good { color: var(--app-good) !important; }
.rating-average { color: var(--app-average) !important; }
.rating-poor { color: var(--app-poor) !important; }
.rating-none { color: var(--app-none) !important; }
.bg-rating-good { background: var(--app-good); }
.bg-rating-average { background: var(--app-average); }
.bg-rating-poor { background: var(--app-poor); }
.bg-rating-none { background: var(--app-none); }
.fill-good { fill: var(--app-good); }
.fill-average { fill: var(--app-average); }
.fill-poor { fill: var(--app-poor); }

/* ---- Result header ---- */
.report-head { display: flex; flex-wrap: wrap; gap: 1.5rem; align-items: flex-end; justify-content: space-between; margin-bottom: 1.5rem; }
.report-head-main { min-width: 0; flex: 1 1 380px; }
.report-url { font-size: clamp(1.3rem, 3vw, 1.9rem); font-weight: 800; word-break: break-all; margin-bottom: .35rem; }
.report-url a { color: var(--app-text); text-decoration: none; }
.report-url a:hover { text-decoration: underline; }
.report-meta { color: var(--app-muted); font-size: .9rem; margin: 0; }
.report-meta .sep { margin: 0 .4rem; }
.report-actions { display: flex; flex-direction: column; gap: .6rem; flex: 0 1 520px; }
.share-box { display: flex; gap: .5rem; }
.share-box .form-control { font-size: .9rem; }
.share-box .btn { white-space: nowrap; }

.device-tabs { border-bottom: 2px solid var(--app-border); gap: .25rem; margin-bottom: 1.5rem; }
.device-tabs .nav-link { display: flex; align-items: center; gap: .55rem; font-weight: 700; font-size: 1.05rem; color: var(--app-muted); border: none; border-bottom: 3px solid transparent; margin-bottom: -2px; padding: .8rem 1.2rem; background: none; }
.device-tabs .nav-link:hover { color: var(--app-text); }
.device-tabs .nav-link.active { color: var(--app-text); border-bottom-color: var(--app-brand); background: none; }
@media (max-width: 575.98px) {
    .device-tabs { flex-wrap: nowrap; }
    .device-tabs .nav-item { flex: 1 1 0; }
    .device-tabs .nav-link { width: 100%; justify-content: center; padding: .7rem .4rem; font-size: 1rem; }
    .report-actions .btn { font-size: .9rem; }
}
.nav-link-plain { white-space: nowrap; }
.tab-score { display: inline-flex; align-items: center; justify-content: center; min-width: 2.3rem; height: 2.3rem; padding: 0 .4rem; border-radius: 50%; border: 3px solid currentColor; font-weight: 800; font-size: .9rem; }

/* ---- Verdict ---- */
.verdict-card { display: flex; flex-direction: row; align-items: center; gap: 2rem; padding: 1.75rem 2rem; margin-bottom: 1.5rem; }
.verdict-good { background: linear-gradient(135deg, var(--app-good-soft), var(--app-surface) 60%); }
.verdict-average { background: linear-gradient(135deg, var(--app-average-soft), var(--app-surface) 60%); }
.verdict-poor { background: linear-gradient(135deg, var(--app-poor-soft), var(--app-surface) 60%); }
.gauge { position: relative; width: 160px; height: 160px; flex: none; }
.gauge-track { stroke: var(--app-surface-2); }
.verdict-good .gauge-value { stroke: var(--app-good); }
.verdict-average .gauge-value { stroke: var(--app-average); }
.verdict-poor .gauge-value { stroke: var(--app-poor); }
.gauge-number { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 3.4rem; font-weight: 800; letter-spacing: -.03em; }
.verdict-good .gauge-number, .verdict-good .verdict-label { color: var(--app-good); }
.verdict-average .gauge-number, .verdict-average .verdict-label { color: var(--app-average); }
.verdict-poor .gauge-number, .verdict-poor .verdict-label { color: var(--app-poor); }
.verdict-label { font-size: 2rem; font-weight: 800; line-height: 1.2; margin-bottom: .35rem; }
.verdict-sentence { font-size: 1.1rem; margin-bottom: .6rem; }
@media (max-width: 767.98px) {
    .verdict-card { flex-direction: column; text-align: center; padding: 1.5rem; gap: 1rem; }
}

/* ---- Sections / metrics ---- */
.section-card { padding: 1.75rem 2rem; margin-bottom: 1.5rem; }
@media (max-width: 575.98px) { .section-card { padding: 1.25rem; } }
.section-head { margin-bottom: 1.25rem; }
.metric-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 1rem; }
.metric-grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
@media (max-width: 767.98px) { .metric-grid-3 { grid-template-columns: 1fr; } }
.metric-tile { background: var(--app-surface-2); border-radius: .9rem; padding: 1.1rem 1.2rem; border-top: 4px solid var(--app-none); }
.rating-border-good { border-top-color: var(--app-good); }
.rating-border-average { border-top-color: var(--app-average); }
.rating-border-poor { border-top-color: var(--app-poor); }
.metric-top { display: flex; align-items: center; gap: .5rem; font-size: .88rem; font-weight: 600; color: var(--app-muted); }
.metric-name abbr { text-decoration: none; color: var(--app-text); font-weight: 800; }
.metric-full { font-weight: 500; }
.metric-dot { width: .7rem; height: .7rem; border-radius: 50%; flex: none; }
.metric-value { font-size: 2.1rem; font-weight: 800; letter-spacing: -.02em; line-height: 1.2; margin-top: .35rem; }
.metric-rating { font-size: .85rem; font-weight: 700; margin-bottom: .5rem; }
.metric-help { font-size: .83rem; color: var(--app-muted); margin: .5rem 0 0; line-height: 1.45; }
.dist-bar { display: block; width: 100%; height: 8px; border-radius: 4px; overflow: hidden; }
.dist-legend { font-size: .72rem; color: var(--app-muted); margin-top: .3rem; }

.assessment { display: flex; flex-wrap: wrap; gap: .25rem .75rem; align-items: baseline; padding: .8rem 1.1rem; border-radius: .8rem; margin-bottom: .75rem; }
.assessment-pass { background: var(--app-good-soft); }
.assessment-pass strong { color: var(--app-good); }
.assessment-fail { background: var(--app-poor-soft); }
.assessment-fail strong { color: var(--app-poor); }
.scope-note { font-size: .88rem; color: var(--app-muted); }
.no-field { display: flex; gap: 1rem; align-items: flex-start; background: var(--app-surface-2); border-radius: .9rem; padding: 1.2rem 1.3rem; color: var(--app-muted); }
.no-field h4 { color: var(--app-text); }
.no-field svg { flex: none; color: var(--app-brand); }

/* ---- Recommendations ---- */
.rec-group-title { font-size: 1.05rem; font-weight: 800; margin: 1.5rem 0 .75rem; display: flex; align-items: center; flex-wrap: wrap; gap: .75rem; }
.rec-group-title:first-of-type { margin-top: .25rem; }
.fix-first-badge { background: var(--app-poor); color: #fff; font-size: .85rem; padding: .45em .8em; border-radius: 2rem; }
[data-bs-theme="dark"] .fix-first-badge { color: #1a0d0d; }
.rec-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: .75rem; counter-reset: rec; }
.rec-item { border: 1px solid var(--app-border); border-radius: .9rem; padding: 1rem 1.2rem; background: var(--app-surface); }
.rec-highlight { border: 2px solid var(--app-poor); background: linear-gradient(90deg, var(--app-poor-soft), var(--app-surface) 40%); }
.rec-list-numbered .rec-item { counter-increment: rec; }
.rec-list-numbered .rec-title::before { content: counter(rec) ". "; }
.rec-head { display: flex; align-items: baseline; gap: .7rem; flex-wrap: wrap; }
.rec-icon { width: .75rem; height: .75rem; border-radius: 3px; flex: none; transform: translateY(-.05rem); }
.rec-title { font-size: 1.08rem; font-weight: 700; margin: 0; flex: 1 1 260px; }
.rec-savings { font-weight: 700; font-size: .88rem; color: var(--app-poor); background: var(--app-poor-soft); padding: .2rem .65rem; border-radius: 2rem; white-space: nowrap; }
.rec-savings-muted { color: var(--app-muted); background: var(--app-surface-2); }
.rec-plain { margin: .45rem 0 .35rem 1.45rem; }
.rec-details { margin-left: 1.45rem; }
.rec-details summary { cursor: pointer; color: var(--bs-link-color); font-weight: 600; font-size: .92rem; width: fit-content; }
.rec-details-body { margin-top: .75rem; padding: 1rem; background: var(--app-surface-2); border-radius: .7rem; font-size: .9rem; }
.audit-id { font-size: .78rem; color: var(--app-muted); }
.details-table { --bs-table-bg: transparent; --bs-table-color: var(--app-text); font-size: .82rem; margin-bottom: .5rem; }
.details-table td { max-width: 420px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.details-table th { color: var(--app-muted); font-weight: 700; white-space: nowrap; }
.checklist { padding-left: 1.1rem; }
.all-good { font-size: 1.1rem; font-weight: 600; color: var(--app-good); }
.cached-note { font-size: .92rem; }
.report-foot { margin-top: 1rem; }

/* ---- Help ---- */
.help-block { margin-bottom: 2.5rem; }
.score-scale { display: flex; border-radius: .6rem; overflow: hidden; font-weight: 700; text-align: center; color: #fff; max-width: 520px; }
.score-scale span { padding: .5rem; }
.scale-poor { background: var(--app-poor); flex: 49; }
.scale-average { background: var(--app-average); flex: 40; }
.scale-good { background: var(--app-good); flex: 11; min-width: 90px; }
[data-bs-theme="dark"] .score-scale { color: #111; }
.vitals-table { --bs-table-bg: var(--app-surface); --bs-table-color: var(--app-text); border-radius: .8rem; overflow: hidden; }
.metric-defs dt { font-weight: 700; margin-top: .75rem; }
.metric-defs dd { color: var(--app-muted); margin-bottom: 0; }
.faq { border: 1px solid var(--app-border); border-radius: .8rem; padding: .9rem 1.1rem; margin-bottom: .6rem; background: var(--app-surface); }
.faq summary { font-weight: 700; cursor: pointer; }
.faq p { margin: .6rem 0 0; color: var(--app-muted); }
.message-page { padding-top: 5rem !important; }

/* ---- Print / Save as PDF: both devices, no buttons ---- */
.print-only { display: none; }
@media print {
    html { font-size: 12pt; }
    body { background: #fff !important; color: #000 !important; display: block; }
    .site-header, .site-footer, .demo-banner, .no-print, .skip-link { display: none !important; }
    .print-only { display: block; }
    .tab-content > .tab-pane { display: block !important; opacity: 1 !important; }
    .tab-pane + .tab-pane { break-before: page; }
    .print-device { font-size: 1.6rem; font-weight: 800; border-bottom: 2px solid #000; padding-bottom: .3rem; margin: 0 0 1rem; }
    .card, .rec-item, .metric-tile { box-shadow: none !important; break-inside: avoid; }
    .section-card { break-inside: auto; }
    .rec-details-body { background: #f4f4f4; }
    a[href^="http"]::after { content: ""; }
    .container { max-width: 100% !important; }
}
