/* Tools: client-side calculators and the printable protocol. */

/*
 * Loaded after page.css. The shared .tool-table and .tool-note rules live in
 * page.css, because the guides use both and load page.css on its own.
 */

.tool-disclaimer {
    margin: 0 0 40px;
    padding: 24px 28px;
    border-left: 2px solid var(--brand);
    background: var(--surface);
    font-size: 17px;
    line-height: 1.6;
}

.tool-disclaimer p {
    max-width: 66ch;
    margin-bottom: 12px;
}

.tool-disclaimer p:last-child {
    margin-bottom: 0;
}

.tool-panel {
    margin: 24px 0 0;
    padding: 28px;
    border: 1px solid var(--line);
    background: var(--white);
}

.tool-panel > *:last-child {
    margin-bottom: 0;
}

.tool-panel h3 {
    margin-top: 30px;
    margin-bottom: 12px;
    font-size: 19px;
}

/* Forms. */

.tool-form {
    margin: 0;
}

.tool-field {
    margin-bottom: 22px;
}

fieldset.tool-field {
    min-width: 0;
    margin-inline: 0;
    margin-bottom: 26px;
    padding: 0 0 22px;
    border: 0;
    border-bottom: 1px solid var(--line);
}

.tool-field > label,
.tool-field > legend {
    display: block;
    width: 100%;
    margin-bottom: 8px;
    padding: 0;
    color: var(--ink);
    font-size: 16px;
    font-weight: 600;
    line-height: 1.4;
}

.tool-field > legend {
    font-size: 17px;
}

.tool-field > p {
    max-width: 66ch;
    margin-bottom: 14px;
    font-size: 16px;
}

.tool-field-row {
    display: flex;
    align-items: flex-start;
    flex-wrap: wrap;
    gap: 14px 26px;
}

.tool-field-row > .tool-field {
    flex: 1 1 220px;
    min-width: 0;
    margin-bottom: 0;
}

/* Radio choices sit in the same row wrapper, so they are styled as inline pairs. */

.tool-field-row > label {
    display: inline-flex;
    min-height: 44px;
    align-items: center;
    gap: 9px;
    color: var(--ink);
    font-size: 16px;
    font-weight: 400;
    line-height: 1.4;
    cursor: pointer;
}

.tool-field-row input[type="radio"] {
    display: inline-block;
    width: 19px;
    height: 19px;
    min-height: 0;
    flex: 0 0 auto;
    margin: 0;
    padding: 0;
    border: 0;
    background: transparent;
    accent-color: var(--brand);
}

.tool-field-row input[type="radio"]:focus-visible {
    outline: 2px solid var(--brand);
    outline-offset: 2px;
    box-shadow: 0 0 0 4px var(--focus-ring);
}

/* Buttons. The secondary treatment is scoped here and does not touch .button globally. */

.tool-actions {
    display: flex;
    margin-top: 24px;
    margin-bottom: 20px;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px 16px;
}

.tool-actions .button:not(.button--primary),
.tool-entry .button {
    border: 1px solid var(--brand);
    background: transparent;
    color: var(--brand);
}

.tool-actions .button:not(.button--primary):hover,
.tool-entry .button:hover {
    border-color: var(--brand-dark);
    background: var(--surface);
    color: var(--brand-dark);
}

/* Saved entries. */

.tool-entries {
    margin: 0 0 4px;
    padding: 0;
    border-top: 1px solid var(--line);
    list-style: none;
}

.tool-entries:empty {
    border-top: 0;
}

.tool-entry {
    display: grid;
    padding-block: 16px;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: start;
    gap: 4px 20px;
    border-bottom: 1px solid var(--line);
}

.tool-entry > p {
    max-width: none;
    margin-bottom: 0;
    grid-column: 1;
}

.tool-entry > p:first-child {
    font-size: 17px;
    font-weight: 600;
}

.tool-entry > p + p {
    color: var(--muted);
    font-size: 15px;
}

.tool-entry > .button {
    width: auto;
    min-height: 38px;
    padding: 6px 14px;
    grid-row: 1;
    grid-column: 2;
    align-self: start;
    font-size: 15px;
    line-height: 22px;
}

/* Results. */

.tool-result {
    margin-top: 32px;
    padding-top: 24px;
    border-top: 3px solid var(--brand);
}

.tool-result > *:last-child {
    margin-bottom: 0;
}

.tool-result h3 {
    margin-top: 26px;
    margin-bottom: 12px;
    font-size: 19px;
}

.tool-result__figure {
    margin-bottom: 10px;
    color: var(--ink);
    font-family: var(--heading-font);
    font-size: 40px;
    font-weight: 600;
    line-height: 1.1;
}

.tool-result__figure strong {
    font-weight: 600;
}

.tool-result__figure span {
    display: block;
    margin-top: 10px;
    color: var(--muted);
    font-family: var(--body-font);
    font-size: 14px;
    font-weight: 400;
    line-height: 1.5;
}

/* The security index score. */

.score-summary {
    margin-bottom: 30px;
}

.score-summary .tool-result__figure + p {
    margin-bottom: 14px;
    color: var(--muted);
    font-size: 14px;
    line-height: 1.5;
}

.score-band {
    max-width: 66ch;
    margin-bottom: 0;
    font-size: 17px;
    font-weight: 600;
}

.score-areas {
    margin: 0 0 24px;
    padding: 0;
    border-top: 1px solid var(--line);
    list-style: none;
}

.score-area {
    padding-block: 15px;
    border-bottom: 1px solid var(--line);
}

.score-area > p {
    max-width: none;
    margin-bottom: 0;
}

.score-area > p:first-child {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 8px 20px;
    font-size: 17px;
}

.score-area > p:first-child span {
    flex: 0 0 auto;
    color: var(--muted);
    font-size: 15px;
    text-align: right;
    white-space: nowrap;
}

.score-area > p + p {
    max-width: 66ch;
    margin-top: 7px;
    color: var(--muted);
    font-size: 15px;
}

/*
 * Printable record sheets. The residence record sheet and the security index
 * score sheet need nothing on screen beyond keeping their print headers out of
 * sight. Their printed presentation is set out in the print block at the foot
 * of this file, and .record-sheet__title / .score-sheet__title are styled there
 * only, because they never appear on screen.
 */

.print-only {
    display: none;
}

/* The printable protocol sheet. */

.protocol-sheet {
    max-width: 680px;
    margin: 24px 0 0;
    padding: 32px;
    border: 1px solid var(--line);
    background: var(--white);
}

.protocol-sheet h3 {
    margin-bottom: 14px;
    font-size: 22px;
}

.protocol-sheet > p {
    max-width: none;
    margin-bottom: 14px;
    font-size: 16px;
}

.protocol-sheet span[aria-hidden="true"] {
    overflow: hidden;
    border-bottom: 1px solid var(--ink);
    color: transparent;
    user-select: none;
}

.protocol-sheet > p > span[aria-hidden="true"] {
    display: inline-block;
    min-width: 150px;
}

.protocol-rules {
    margin-top: 24px;
    padding-top: 22px;
    border-top: 1px solid var(--line);
}

.protocol-rules ol {
    max-width: none;
    margin: 0;
    padding-left: 24px;
    font-size: 17px;
    line-height: 1.6;
}

.protocol-rules li {
    margin-bottom: 14px;
    padding-left: 4px;
}

.protocol-rules li:last-child {
    margin-bottom: 0;
}

.protocol-fields {
    margin-top: 28px;
    padding-top: 22px;
    border-top: 1px solid var(--line);
}

.protocol-field {
    display: flex;
    max-width: none;
    margin-bottom: 20px;
    align-items: baseline;
    flex-wrap: wrap;
    gap: 6px 14px;
    font-size: 16px;
    font-weight: 600;
}

.protocol-field span[aria-hidden="true"] {
    flex: 1 1 140px;
    min-width: 100px;
}

.protocol-fields .tool-note {
    margin-bottom: 20px;
}

.protocol-signoff {
    margin-top: 26px;
    padding-top: 22px;
    border-top: 1px solid var(--line);
}

.protocol-signoff p {
    display: flex;
    max-width: none;
    margin-bottom: 24px;
    align-items: baseline;
    flex-wrap: wrap;
    gap: 8px 14px;
    font-size: 16px;
    font-weight: 600;
}

.protocol-signoff p:last-child {
    margin-bottom: 0;
}

.protocol-signoff span[aria-hidden="true"] {
    flex: 1 1 170px;
    min-width: 130px;
}

@media (max-width: 620px) {
    .tool-disclaimer {
        margin-bottom: 32px;
        padding: 20px 22px;
        font-size: 16px;
    }

    .tool-panel,
    .protocol-sheet {
        padding: 20px;
    }

    .tool-result__figure {
        font-size: 34px;
    }

    .protocol-rules ol,
    .score-band,
    .score-area > p:first-child {
        font-size: 16px;
    }
}

@media (max-width: 560px) {
    .tool-field-row {
        flex-direction: column;
        gap: 10px;
    }

    .tool-field-row > .tool-field {
        width: 100%;
    }

    .tool-field-row > label {
        min-height: 40px;
    }
}

@media (max-width: 430px) {
    .tool-entry {
        grid-template-columns: minmax(0, 1fr);
    }

    .tool-entry > .button {
        grid-row: auto;
        grid-column: 1;
        margin-top: 10px;
        justify-self: start;
    }
}

/*
 * Printing. Three tool pages carry a sheet that is the only thing worth putting
 * on paper: the verification protocol, the residence day record and the security
 * index score. Each of the three has its own block below, and every rule that
 * hides or reveals anything is scoped with body.tool-page:has(<its own sheet
 * class>). A page holding none of the three therefore matches none of the
 * hiding rules and prints normally, and no block can reach into another block's
 * sheet. A browser without :has() support drops the lot and prints the whole
 * page, which is a readable fallback rather than a broken one.
 */

@media print {
    @page {
        margin: 15mm;
    }

    .tool-actions {
        display: none !important;
    }

    .tool-disclaimer {
        border-left-color: #000;
        background: #fff;
    }

    .tool-panel {
        border-color: #000;
    }

    body.tool-page:has(.protocol-sheet) > *:not(.page-main),
    body.tool-page:has(.protocol-sheet) .page-main > *:not(.page-article),
    body.tool-page:has(.protocol-sheet) .page-article > *:not(:has(.protocol-sheet)),
    body.tool-page:has(.protocol-sheet) .page-article > section:has(.protocol-sheet) > *:not(.protocol-sheet) {
        display: none !important;
    }

    body.tool-page:has(.protocol-sheet) .protocol-sheet {
        width: 100%;
        max-width: none;
        margin: 0;
        padding: 0;
        border: 0;
        background: #fff;
        color: #000;
        font-size: 12pt;
        line-height: 1.4;
    }

    body.tool-page:has(.protocol-sheet) .protocol-sheet h3 {
        margin-bottom: 7pt;
        color: #000;
        font-size: 15pt;
    }

    body.tool-page:has(.protocol-sheet) .protocol-sheet > p,
    body.tool-page:has(.protocol-sheet) .protocol-field,
    body.tool-page:has(.protocol-sheet) .protocol-signoff p {
        margin-bottom: 5pt;
        color: #000;
        font-size: 12pt;
    }

    body.tool-page:has(.protocol-sheet) .protocol-rules ol {
        font-size: 12pt;
        line-height: 1.3;
    }

    body.tool-page:has(.protocol-sheet) .protocol-rules li {
        margin-bottom: 3pt;
    }

    body.tool-page:has(.protocol-sheet) .protocol-sheet .tool-note {
        color: #000;
        font-size: 10pt;
    }

    body.tool-page:has(.protocol-sheet) .protocol-rules,
    body.tool-page:has(.protocol-sheet) .protocol-fields,
    body.tool-page:has(.protocol-sheet) .protocol-signoff {
        margin-top: 6pt;
        padding-top: 4pt;
        border-top-color: #000;
    }

    body.tool-page:has(.protocol-sheet) .protocol-sheet span[aria-hidden="true"] {
        border-bottom-color: #000;
    }

    body.tool-page:has(.protocol-sheet) .protocol-signoff span[aria-hidden="true"] {
        min-width: 110px;
    }

    /*
     * The residence day record sheet. The sheet sits inside a tool panel inside
     * a section, so the siblings are hidden a level at a time: everything that
     * is neither the sheet nor an ancestor of it goes.
     */

    body.tool-page:has(.record-sheet) > *:not(.page-main),
    body.tool-page:has(.record-sheet) .page-main > *:not(.page-article),
    body.tool-page:has(.record-sheet) .page-article > *:not(.record-sheet):not(:has(.record-sheet)),
    body.tool-page:has(.record-sheet) .page-article > section:has(.record-sheet) > *:not(.record-sheet):not(:has(.record-sheet)),
    body.tool-page:has(.record-sheet) .tool-panel:has(.record-sheet) > *:not(.record-sheet):not(:has(.record-sheet)) {
        display: none !important;
    }

    /* Inside the sheet: the controls, the entry form and the noscript note. */

    body.tool-page:has(.record-sheet) .record-sheet form,
    body.tool-page:has(.record-sheet) .record-sheet noscript,
    body.tool-page:has(.record-sheet) .record-sheet button,
    body.tool-page:has(.record-sheet) .record-sheet .button,
    body.tool-page:has(.record-sheet) .record-sheet .tool-actions {
        display: none !important;
    }

    body.tool-page:has(.record-sheet) .tool-panel:has(.record-sheet) {
        margin: 0;
        padding: 0;
        border: 0;
        background: #fff;
    }

    body.tool-page:has(.record-sheet) .record-sheet {
        width: 100%;
        margin: 0;
        padding: 0;
        background: #fff;
        color: #000;
        font-size: 12pt;
        line-height: 1.4;
    }

    body.tool-page:has(.record-sheet) .record-sheet .print-only {
        display: block !important;
        margin-bottom: 8pt;
        padding-bottom: 6pt;
        border-bottom: 1px solid #000;
    }

    body.tool-page:has(.record-sheet) .record-sheet__title {
        margin-bottom: 4pt;
        color: #000;
        font-family: var(--heading-font);
        font-size: 15pt;
        font-weight: 600;
        line-height: 1.2;
    }

    body.tool-page:has(.record-sheet) .record-sheet .print-only p + p {
        max-width: none;
        margin-bottom: 0;
        color: #000;
        font-size: 10pt;
        line-height: 1.35;
    }

    body.tool-page:has(.record-sheet) .record-sheet h3 {
        margin-top: 0;
        margin-bottom: 5pt;
        color: #000;
        font-size: 13pt;
    }

    body.tool-page:has(.record-sheet) .record-sheet .tool-note {
        color: #000;
        font-size: 10pt;
    }

    body.tool-page:has(.record-sheet) .record-sheet .tool-entries {
        margin-bottom: 0;
        border-top: 1px solid #000;
    }

    body.tool-page:has(.record-sheet) .record-sheet .tool-entry {
        display: block;
        padding-block: 5pt;
        border-bottom: 1px solid #000;
        break-inside: avoid;
    }

    body.tool-page:has(.record-sheet) .record-sheet .tool-entry > p:first-child {
        color: #000;
        font-size: 12pt;
    }

    body.tool-page:has(.record-sheet) .record-sheet .tool-entry > p + p {
        color: #000;
        font-size: 10pt;
    }

    body.tool-page:has(.record-sheet) .record-sheet .tool-result {
        margin-top: 10pt;
        padding-top: 8pt;
        border-top: 1px solid #000;
    }

    body.tool-page:has(.record-sheet) .record-sheet .tool-result__figure {
        margin-bottom: 6pt;
        color: #000;
        font-size: 20pt;
    }

    body.tool-page:has(.record-sheet) .record-sheet .tool-result__figure span {
        margin-top: 3pt;
        color: #000;
        font-size: 10pt;
    }

    /* The table prints in full rather than scrolling, so it is allowed to shrink. */

    body.tool-page:has(.record-sheet) .record-sheet .tool-table {
        margin: 8pt 0 0;
        overflow: visible;
    }

    body.tool-page:has(.record-sheet) .record-sheet .tool-table table {
        width: 100%;
        min-width: 0;
        font-size: 10pt;
        table-layout: auto;
    }

    body.tool-page:has(.record-sheet) .record-sheet .tool-table caption {
        margin-bottom: 4pt;
        color: #000;
        font-size: 10pt;
    }

    body.tool-page:has(.record-sheet) .record-sheet .tool-table th,
    body.tool-page:has(.record-sheet) .record-sheet .tool-table td {
        padding: 4pt 8pt 4pt 0;
        border-bottom: 1px solid #000;
        color: #000;
        font-size: 10pt;
    }

    body.tool-page:has(.record-sheet) .record-sheet .tool-table thead th {
        padding-bottom: 4pt;
        border-bottom: 1px solid #000;
        color: #000;
        font-size: 10pt;
        font-weight: 600;
        letter-spacing: .04em;
    }

    /*
     * The security index score sheet. It sits directly inside its section, so
     * there is one level fewer to clear than on the record sheet.
     */

    body.tool-page:has(.score-sheet) > *:not(.page-main),
    body.tool-page:has(.score-sheet) .page-main > *:not(.page-article),
    body.tool-page:has(.score-sheet) .page-article > *:not(.score-sheet):not(:has(.score-sheet)),
    body.tool-page:has(.score-sheet) .page-article > section:has(.score-sheet) > *:not(.score-sheet):not(:has(.score-sheet)) {
        display: none !important;
    }

    /* Inside the sheet: the print button the script appends, and any control. */

    body.tool-page:has(.score-sheet) .score-sheet form,
    body.tool-page:has(.score-sheet) .score-sheet noscript,
    body.tool-page:has(.score-sheet) .score-sheet button,
    body.tool-page:has(.score-sheet) .score-sheet .button,
    body.tool-page:has(.score-sheet) .score-sheet .tool-actions {
        display: none !important;
    }

    body.tool-page:has(.score-sheet) .score-sheet {
        width: 100%;
        margin: 0;
        padding: 0;
        background: #fff;
        color: #000;
        font-size: 12pt;
        line-height: 1.4;
    }

    body.tool-page:has(.score-sheet) .score-sheet .print-only {
        display: block !important;
        margin-bottom: 8pt;
        padding-bottom: 6pt;
        border-bottom: 1px solid #000;
    }

    body.tool-page:has(.score-sheet) .score-sheet__title {
        margin-bottom: 4pt;
        color: #000;
        font-family: var(--heading-font);
        font-size: 15pt;
        font-weight: 600;
        line-height: 1.2;
    }

    body.tool-page:has(.score-sheet) .score-sheet .print-only p + p {
        max-width: none;
        margin-bottom: 0;
        color: #000;
        font-size: 10pt;
        line-height: 1.35;
    }

    body.tool-page:has(.score-sheet) .score-sheet .tool-result {
        margin-top: 0;
        padding-top: 0;
        border-top: 0;
    }

    body.tool-page:has(.score-sheet) .score-sheet .score-summary {
        margin-bottom: 10pt;
    }

    body.tool-page:has(.score-sheet) .score-sheet .tool-result__figure {
        margin-bottom: 4pt;
        color: #000;
        font-size: 24pt;
    }

    body.tool-page:has(.score-sheet) .score-sheet .score-summary .tool-result__figure + p {
        margin-bottom: 6pt;
        color: #000;
        font-size: 10pt;
    }

    body.tool-page:has(.score-sheet) .score-sheet .score-band {
        max-width: none;
        color: #000;
        font-size: 12pt;
    }

    body.tool-page:has(.score-sheet) .score-sheet h3 {
        margin-top: 10pt;
        margin-bottom: 5pt;
        color: #000;
        font-size: 13pt;
    }

    body.tool-page:has(.score-sheet) .score-sheet .score-areas {
        margin-bottom: 8pt;
        border-top: 1px solid #000;
    }

    body.tool-page:has(.score-sheet) .score-sheet .score-area {
        padding-block: 5pt;
        border-bottom: 1px solid #000;
        break-inside: avoid;
    }

    body.tool-page:has(.score-sheet) .score-sheet .score-area > p:first-child {
        color: #000;
        font-size: 12pt;
    }

    body.tool-page:has(.score-sheet) .score-sheet .score-area > p:first-child span {
        color: #000;
        font-size: 10pt;
    }

    body.tool-page:has(.score-sheet) .score-sheet .score-area > p + p {
        max-width: none;
        margin-top: 3pt;
        color: #000;
        font-size: 10pt;
    }

    body.tool-page:has(.score-sheet) .score-sheet .tool-note {
        color: #000;
        font-size: 10pt;
    }

    /* A table on the score sheet shrinks rather than clipping, as above. */

    body.tool-page:has(.score-sheet) .score-sheet .tool-table {
        margin: 8pt 0 0;
        overflow: visible;
    }

    body.tool-page:has(.score-sheet) .score-sheet .tool-table table {
        width: 100%;
        min-width: 0;
        font-size: 10pt;
        table-layout: auto;
    }

    body.tool-page:has(.score-sheet) .score-sheet .tool-table caption {
        margin-bottom: 4pt;
        color: #000;
        font-size: 10pt;
    }

    body.tool-page:has(.score-sheet) .score-sheet .tool-table th,
    body.tool-page:has(.score-sheet) .score-sheet .tool-table td {
        padding: 4pt 8pt 4pt 0;
        border-bottom: 1px solid #000;
        color: #000;
        font-size: 10pt;
    }

    body.tool-page:has(.score-sheet) .score-sheet .tool-table thead th {
        padding-bottom: 4pt;
        border-bottom: 1px solid #000;
        color: #000;
        font-size: 10pt;
        font-weight: 600;
        letter-spacing: .04em;
    }
}
