/* =============================================================================
   CPF contribution calculator (sg/cpf-calculator.php)
   -----------------------------------------------------------------------------
   Built on the tokens in css/hisabooks.css. Flat and border-only: the tool,
   the tables and the questions are bounded by hairlines, never by fills or
   shadows. Sections alternate paper, mist, paper, night-soft.
   Design rules: docs/hisabooks_marketing_design_standards.md
   ============================================================================= */

/* ── Hero and the tool ─────────────────────────────────────────────────────── */
.cpfc-hero {
    padding-block: calc(var(--hb-nav-h) + var(--hb-s8)) var(--hb-s8);
    background: var(--hb-paper);
}

.cpfc-hero__head {
    display: grid;
    gap: var(--hb-s4);
    max-width: 62ch;
    margin-bottom: var(--hb-s7);
}

.cpfc-tool {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    border: 1px solid var(--hb-line);
    border-radius: var(--hb-r-lg);
}

.cpfc-form {
    display: grid;
    gap: var(--hb-s5);
    align-content: start;
    padding: var(--hb-s7);
}

.cpfc-field {
    display: grid;
    gap: var(--hb-s2);
    min-width: 0;
    margin: 0;
    padding: 0;
    border: 0;
}

.cpfc-label {
    padding: 0;
    font-size: var(--hb-t-sm);
    font-weight: 600;
    letter-spacing: -.01em;
    color: var(--hb-ink);
}

.cpfc-hint {
    font-size: var(--hb-t-xs);
    line-height: 1.5;
    color: var(--hb-muted);
}

.cpfc-input {
    width: 100%;
    min-height: 48px;
    padding: 0 var(--hb-s4);
    border: 1px solid var(--hb-line);
    border-radius: var(--hb-r-sm);
    background: var(--hb-paper);
    font-size: var(--hb-t-body);
    color: var(--hb-ink);
    transition: border-color var(--hb-fast) var(--hb-ease);
}
.cpfc-input:hover { border-color: var(--hb-blue-mist); }
.cpfc-input:focus { border-color: var(--hb-blue); }

.cpfc-money { position: relative; }
.cpfc-money .cpfc-input {
    padding-left: calc(var(--hb-s4) + 26px);
    font-variant-numeric: tabular-nums;
}
.cpfc-money__unit {
    position: absolute;
    top: 50%;
    left: var(--hb-s4);
    transform: translateY(-50%);
    font-size: var(--hb-t-sm);
    font-weight: 600;
    color: var(--hb-muted);
    pointer-events: none;
}

/* The year picker: radios drawn as one segmented control. */
.cpfc-years {
    display: inline-flex;
    flex-wrap: wrap;
    justify-self: start;
    border: 1px solid var(--hb-line);
    border-radius: var(--hb-r-sm);
    overflow: hidden;
}
.cpfc-year { position: relative; }
.cpfc-year + .cpfc-year { border-left: 1px solid var(--hb-line); }
.cpfc-year input {
    position: absolute;
    inset: 0;
    opacity: 0;
    margin: 0;
    cursor: pointer;
}
.cpfc-year span {
    display: block;
    padding: var(--hb-s3) var(--hb-s5);
    font-size: var(--hb-t-sm);
    font-weight: 600;
    color: var(--hb-ink-soft);
    font-variant-numeric: tabular-nums;
    transition: background-color var(--hb-fast) var(--hb-ease), color var(--hb-fast) var(--hb-ease);
}
.cpfc-year:hover span { background: var(--hb-blue-wash); color: var(--hb-blue); }
.cpfc-year input:checked + span { background: var(--hb-blue); color: #fff; }
.cpfc-year input:focus-visible + span { outline: 2px solid var(--hb-blue); outline-offset: -4px; }
.cpfc-year input:checked:focus-visible + span { outline-color: #fff; }

.cpfc-submit { justify-self: start; }

/* ── Result ────────────────────────────────────────────────────────────────── */
.cpfc-result {
    display: grid;
    align-content: start;
    gap: var(--hb-s5);
    padding: var(--hb-s7);
    border-left: 1px solid var(--hb-line);
    /* Calculate scrolls here on a phone; land below the floating nav. */
    scroll-margin-top: calc(var(--hb-nav-h) + var(--hb-s4));
}

.cpfc-result__label {
    font-size: var(--hb-t-sm);
    font-weight: 600;
    color: var(--hb-muted);
}

.cpfc-result__total {
    margin-top: calc(-1 * var(--hb-s4));
    font-size: var(--hb-t-h1);
    line-height: 1.05;
    letter-spacing: -.038em;
    font-weight: 660;
    color: var(--hb-ink);
    font-variant-numeric: tabular-nums;
}

.cpfc-result__split,
.cpfc-result__pay { display: grid; }

.cpfc-result__row {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: var(--hb-s4);
    padding-block: var(--hb-s3);
    border-top: 1px solid var(--hb-line);
}
.cpfc-result__row dt {
    flex: 1 1 auto;
    min-width: 0;
    font-size: var(--hb-t-sm);
    color: var(--hb-ink-soft);
}
.cpfc-result__row dd {
    flex: none;
    margin: 0;
    font-size: var(--hb-t-body);
    font-weight: 620;
    color: var(--hb-ink);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}
.cpfc-result__split .cpfc-result__row dd { font-size: var(--hb-t-h4); }
/* The shares close with a rule; the pay pair then starts under the gap rather
   than under a second rule, which read as an empty row. */
.cpfc-result__split .cpfc-result__row:last-child { border-bottom: 1px solid var(--hb-line); }
.cpfc-result__pay .cpfc-result__row:first-child { border-top: 0; padding-top: 0; }

.cpfc-result__explain {
    font-size: var(--hb-t-sm);
    line-height: 1.6;
    color: var(--hb-ink-soft);
}

.cpfc-result__notes {
    display: grid;
    gap: var(--hb-s2);
    margin: 0;
    padding: 0;
    font-size: var(--hb-t-sm);
    line-height: 1.55;
    color: var(--hb-ink-soft);
}

.cpfc-result__fine {
    font-size: var(--hb-t-xs);
    line-height: 1.55;
    color: var(--hb-faint);
}

.cpfc-sr {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
    border: 0;
}

/* ── Rate tables ───────────────────────────────────────────────────────────── */
.cpfc-rates {
    padding-block: var(--hb-section-tight);
    background: var(--hb-mist);
}

.cpfc-rates__head { display: grid; gap: var(--hb-s4); max-width: 62ch; }

.cpfc-tables {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 340px), 1fr));
    gap: var(--hb-s7) var(--hb-s6);
    margin-top: var(--hb-s7);
}

.cpfc-table { min-width: 0; }

.cpfc-table__title {
    font-size: var(--hb-t-h4);
    line-height: 1.35;
    letter-spacing: -.014em;
    font-weight: 600;
    color: var(--hb-ink);
}

.cpfc-table__years {
    margin-top: var(--hb-s1);
    font-size: var(--hb-t-xs);
    color: var(--hb-muted);
}

.cpfc-table table {
    width: 100%;
    margin-top: var(--hb-s4);
    border-collapse: collapse;
    font-size: var(--hb-t-sm);
}
.cpfc-table th,
.cpfc-table td {
    padding: var(--hb-s3) var(--hb-s2);
    border-bottom: 1px solid var(--hb-line);
    text-align: right;
    font-variant-numeric: tabular-nums;
}
.cpfc-table th:first-child,
.cpfc-table td:first-child { padding-left: 0; text-align: left; }
.cpfc-table th:last-child,
.cpfc-table td:last-child { padding-right: 0; }
.cpfc-table thead th {
    font-size: var(--hb-t-xs);
    font-weight: 600;
    color: var(--hb-muted);
    border-bottom-color: var(--hb-ink-soft);
}
.cpfc-table tbody th { font-weight: 500; color: var(--hb-ink-soft); }
.cpfc-table tbody td { color: var(--hb-ink); }
.cpfc-table tbody td:last-child { font-weight: 620; }

.cpfc-bands {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: var(--hb-s5);
    margin-top: var(--hb-s7);
    padding-top: var(--hb-s5);
    border-top: 1px solid var(--hb-line);
}
.cpfc-bands__item { display: grid; gap: var(--hb-s1); align-content: start; }
.cpfc-bands__item dt {
    font-size: var(--hb-t-sm);
    font-weight: 600;
    color: var(--hb-ink);
    font-variant-numeric: tabular-nums;
}
.cpfc-bands__item dd {
    font-size: var(--hb-t-sm);
    line-height: 1.55;
    color: var(--hb-muted);
}

/* ── Questions ─────────────────────────────────────────────────────────────── */
.cpfc-questions {
    padding-block: var(--hb-section-tight);
    background: var(--hb-paper);
}

.cpfc-faq {
    margin-top: var(--hb-s6);
    border-top: 1px solid var(--hb-line);
}

.cpfc-faq__item { border-bottom: 1px solid var(--hb-line); }

.cpfc-faq__item summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--hb-s4);
    padding: var(--hb-s5) 0;
    cursor: pointer;
    list-style: none;
    font-size: var(--hb-t-body);
    font-weight: 600;
    letter-spacing: -.012em;
    color: var(--hb-ink);
}
.cpfc-faq__item summary::-webkit-details-marker { display: none; }
.cpfc-faq__item summary::after {
    content: "+";
    flex: none;
    font-size: 1.35rem;
    font-weight: 400;
    line-height: 1;
    color: var(--hb-blue);
    transition: transform var(--hb-mid) var(--hb-ease);
}
.cpfc-faq__item[open] summary::after { transform: rotate(45deg); }
.cpfc-faq__item summary:hover { color: var(--hb-blue); }

.cpfc-faq__item p {
    padding-bottom: var(--hb-s5);
    max-width: 68ch;
    font-size: var(--hb-t-sm);
    line-height: 1.7;
    color: var(--hb-muted);
}

/* ── Close ─────────────────────────────────────────────────────────────────── */
.cpfc-close {
    padding-block: var(--hb-section-tight);
    background: var(--hb-night-soft);
    color: #fff;
}
.cpfc-close__inner { display: grid; gap: var(--hb-s5); justify-items: center; text-align: center; }
.cpfc-close__title { color: #fff; }
.cpfc-close__body { color: var(--hb-night-text); max-width: 54ch; }
.cpfc-close .hb-actions { justify-content: center; }

/* ── Narrow ────────────────────────────────────────────────────────────────── */
@media (max-width: 899px) {
    .cpfc-tool { grid-template-columns: minmax(0, 1fr); }
    .cpfc-form,
    .cpfc-result { padding: var(--hb-s6) var(--hb-s5); }
    .cpfc-result { border-left: 0; border-top: 1px solid var(--hb-line); }
    .cpfc-bands { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 519px) {
    .cpfc-hero { padding-block: calc(var(--hb-nav-h) + var(--hb-s6)) var(--hb-s7); }
    .cpfc-year span { padding-inline: var(--hb-s4); }
    .cpfc-bands { grid-template-columns: minmax(0, 1fr); }
}

@media (prefers-reduced-motion: reduce) {
    .cpfc-input,
    .cpfc-year span,
    .cpfc-faq__item summary::after { transition: none; }
}
