/**
 * H2W Calculator Styles
 * Linear and rotary motion calculators (page-templates/*-motion-calculator.php)
 *
 * Light content on paper: white cards (1px line, 6px radius), brand tokens
 * from brand.css, numbers in mono with tabular figures.
 *
 * This file loads before the stock jQuery UI base theme, so every rule that
 * has to beat jQuery UI is scoped under .calculator-page for specificity.
 */

/* ---------- Page frame ---------- */
.calculator-page {
    --calc-radius: 6px;
    --calc-control-h: 44px;
    --calc-pad: clamp(16px, 3vw, 32px);
    --calc-tint: rgba(0, 50, 160, 0.05);

    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    gap: 24px;
    width: 100%;
    max-width: var(--h2w-max);
    margin-inline: auto;
    padding: 0;
    color: var(--h2w-ink);
    font-family: var(--h2w-font-body);
    font-size: 1rem;
    line-height: 1.55;
}

.calculator-page *,
.calculator-page *::before,
.calculator-page *::after {
    box-sizing: border-box;
}

.calculator-page p {
    margin: 0;
}

.calculator-page a {
    color: var(--h2w-blue);
    text-decoration: underline;
    text-decoration-thickness: 1px;
    text-underline-offset: 2px;
}

.calculator-page a:hover {
    color: var(--h2w-blue-hover);
}

.calculator-page :focus-visible {
    outline: 2px solid var(--h2w-blue);
    outline-offset: 2px;
}

.calculator-page h2,
.calculator-page h3,
.calculator-page h4,
.calculator-page h5 {
    margin: 0;
    color: var(--h2w-ink);
    font-family: var(--h2w-font-display);
    font-weight: 600;
    line-height: 1.25;
    letter-spacing: 0;
    text-transform: none;
}

/* ---------- Header and intro line ---------- */
.calculator-header {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}

/* The dark title band already shows the page title, so the h2 stays for
   screen readers only and the intro line leads the header row */
.calculator-header h2 {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.calculator-page .calculator-nav-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 44px;
    padding: 0.625rem 1.125rem;
    border: 1px solid var(--h2w-blue);
    border-radius: 3px;
    background: #fff;
    color: var(--h2w-blue);
    font-family: var(--h2w-font-display);
    font-size: 0.9375rem;
    font-weight: 600;
    line-height: 1.2;
    text-decoration: none;
    transition: background-color 0.15s ease, color 0.15s ease;
}

.calculator-page .calculator-nav-link:hover,
.calculator-page .calculator-nav-link:focus-visible {
    background: var(--h2w-blue);
    color: #fff;
}

.calculator-header .calculator-brief {
    flex: 1 1 420px;
}

.calculator-brief p {
    max-width: 72ch;
    color: var(--h2w-ink-muted);
    font-size: 1.0625rem;
}

/* ---------- Cards ---------- */
.unit-converter-section,
.calculator-introduction,
.calculator-page .calculator-tabs {
    min-width: 0;
    margin: 0;
    padding: var(--calc-pad);
    border: 1px solid var(--h2w-line-light);
    border-radius: var(--calc-radius);
    background: #fff;
}

.unit-converter-section > h3,
.calculator-introduction > h3 {
    margin-bottom: 16px;
    font-size: 1.25rem;
}

/* ---------- Force / torque introduction ---------- */
.calc-intro-lead {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(240px, 340px);
    gap: 24px;
    align-items: start;
    margin-bottom: 24px;
}

.calc-intro-lead > p {
    max-width: 72ch;
    color: var(--h2w-ink-muted);
}

/* Newton's second law / torque equation panel */
.newtons-law-equation,
.torque-equation {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 16px 20px;
    border: 1px solid var(--h2w-line-light);
    border-radius: 3px;
    background: var(--h2w-paper);
    text-align: center;
}

.newtons-law-equation p,
.torque-equation p {
    color: var(--h2w-ink-muted);
    font-size: 0.875rem;
}

.newtons-law-equation p strong,
.torque-equation p strong {
    color: var(--h2w-ink);
    font-family: var(--h2w-font-display);
    font-weight: 600;
}

.calculator-page .newtons-law-equation .mathjaxEquation1,
.calculator-page .torque-equation .mathjaxEquation1 {
    width: 100%;
    margin: 0;
    padding: 4px 0;
    border: 0;
    background: transparent;
}

/* ---------- Form controls ---------- */
.calculator-page .variables-table input,
.calculator-page .variables-table select {
    width: 100%;
    height: var(--calc-control-h);
    margin: 0;
    padding: 0 12px;
    border: 1px solid var(--h2w-line-light);
    border-radius: 3px;
    background-color: #fff;
    color: var(--h2w-ink);
    font-size: 0.9375rem;
    line-height: 1.2;
    box-shadow: none;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

/* Numeric entry reads as data: mono, tabular, right-aligned */
.calculator-page .variables-table input[type="number"],
.calculator-page .variables-table input[type="text"] {
    font-family: var(--h2w-font-mono);
    font-variant-numeric: tabular-nums;
    text-align: right;
    -moz-appearance: textfield;
    appearance: textfield;
}

.calculator-page .variables-table input::-webkit-outer-spin-button,
.calculator-page .variables-table input::-webkit-inner-spin-button {
    margin: 0;
    -webkit-appearance: none;
}

.calculator-page .variables-table input::placeholder {
    color: #8a93a3;
    font-family: var(--h2w-font-body);
    opacity: 1;
}

.calculator-page .variables-table select {
    padding-right: 34px;
    font-family: var(--h2w-font-body);
    cursor: pointer;
    -webkit-appearance: none;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5l5 5 5-5' fill='none' stroke='%235a6475' stroke-width='1.6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    background-size: 12px 8px;
}

.calculator-page .variables-table input:hover:not(:disabled),
.calculator-page .variables-table select:hover:not(:disabled) {
    border-color: #aab4c4;
}

.calculator-page .variables-table input:focus,
.calculator-page .variables-table select:focus {
    border-color: var(--h2w-blue);
    outline: 2px solid var(--h2w-blue);
    outline-offset: 0;
    box-shadow: none;
}

.calculator-page .variables-table input:disabled,
.calculator-page .variables-table select:disabled {
    border-style: dashed;
    background-color: var(--h2w-paper);
    color: var(--h2w-ink-muted);
    cursor: not-allowed;
    opacity: 1;
}

.calculator-page .variables-table input:disabled::placeholder {
    color: #a6aebb;
}

/* ---------- Variable tables ---------- */
.calculator-page .variables-table {
    width: 100%;
    margin: 0;
    border: 1px solid var(--h2w-line-light);
    border-collapse: separate;
    border-spacing: 0;
    border-radius: var(--calc-radius);
    background: #fff;
    font-size: 0.9375rem;
    overflow: hidden;
}

.calculator-page .variables-table th,
.calculator-page .variables-table td {
    padding: 10px 16px;
    border: 0;
    border-bottom: 1px solid var(--h2w-line-light);
    text-align: left;
    vertical-align: middle;
}

.calculator-page .variables-table tbody tr:last-child > td {
    border-bottom: 0;
}

.calculator-page .variables-table th {
    padding-block: 10px;
    background: var(--h2w-paper);
    color: var(--h2w-ink-muted);
    font-family: var(--h2w-font-body);
    font-size: 0.8125rem;
    font-weight: 600;
    letter-spacing: 0.02em;
}

/* Symbol column */
.calculator-page .variables-table tr > :first-child:nth-last-child(4) {
    width: 120px;
}

.calculator-page .variables-table td:first-child strong {
    color: var(--h2w-ink);
    font-weight: 600;
}

/* Units column (four-column tables) and fixed-width entry column */
.calculator-page .variables-table tr > :nth-child(3):not(:last-child) {
    width: 190px;
}

.calculator-page .variables-table td:nth-child(3):not(:last-child) {
    color: var(--h2w-ink-muted);
    font-family: var(--h2w-font-mono);
    font-size: 0.875rem;
    white-space: nowrap;
}

.calculator-page .variables-table tr > :nth-child(3):not(:last-child) select {
    font-family: var(--h2w-font-mono);
    font-size: 0.875rem;
}

.calculator-page .variables-table tr > :last-child:not(:first-child) {
    width: 280px;
}

.calculator-page .variables-table th:last-child:not(:first-child) {
    text-align: right;
}

/* Constants (G) shown as read-only values */
.calculator-page .variables-table td > span[id$="GValue"] {
    display: block;
    padding-right: 13px;
    font-family: var(--h2w-font-mono);
    font-variant-numeric: tabular-nums;
    text-align: right;
}

/* Computed results: a calm readout, row lightly tinted */
.calculator-page .variables-table tr:has(.result) > td {
    background: var(--calc-tint);
}

.calculator-page .variables-table tr:has(.result) > td:first-child {
    box-shadow: inset 3px 0 0 var(--h2w-blue);
}

.calculator-page .result {
    display: block;
    width: 100%;
    min-height: var(--calc-control-h);
    margin: 0;
    padding: 0 12px;
    border: 1px solid rgba(0, 50, 160, 0.3);
    border-radius: 3px;
    background: #fff;
    color: var(--h2w-blue);
    font-family: var(--h2w-font-mono);
    font-size: 1.125rem;
    font-variant-numeric: tabular-nums;
    font-weight: 500;
    line-height: calc(var(--calc-control-h) - 2px);
    text-align: right;
}

/* ---------- Unit converter ---------- */
.calculator-page #unitConverterTable th:nth-child(1),
.calculator-page #unitConverterTable td:nth-child(1) {
    width: 24%;
}

.calculator-page #unitConverterTable tr > * {
    width: auto;
    color: var(--h2w-ink);
    font-family: var(--h2w-font-body);
    text-align: left;
}

.calculator-page #unitConverterTable select {
    font-family: var(--h2w-font-body);
    font-size: 0.9375rem;
}

/* ---------- Tabs (overrides jQuery UI base theme) ---------- */
.calculator-page .calculator-tabs.ui-tabs {
    position: relative;
    padding: 0;
    font-family: var(--h2w-font-body);
    font-size: 1rem;
}

.calculator-page .calculator-tabs .ui-tabs-nav {
    display: flex;
    gap: 4px;
    margin: 0;
    padding: 0 calc(var(--calc-pad) - 12px);
    border: 0;
    border-bottom: 1px solid var(--h2w-line-light);
    border-radius: var(--calc-radius) var(--calc-radius) 0 0;
    background: #fff;
    overflow-x: auto;
    scrollbar-width: thin;
}

.calculator-page .calculator-tabs .ui-tabs-nav::before,
.calculator-page .calculator-tabs .ui-tabs-nav::after {
    display: none;
}

.calculator-page .calculator-tabs .ui-tabs-nav li {
    flex: 0 0 auto;
    float: none;
    position: static;
    top: auto;
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: 0;
    background: transparent;
    list-style: none;
    white-space: nowrap;
}

.calculator-page .calculator-tabs .ui-tabs-nav li.ui-tabs-active {
    margin: 0;
    padding: 0;
}

.calculator-page .calculator-tabs .ui-tabs-nav .ui-tabs-anchor {
    display: flex;
    align-items: center;
    float: none;
    min-height: 52px;
    padding: 0 12px;
    border-bottom: 3px solid transparent;
    color: var(--h2w-ink-muted);
    font-family: var(--h2w-font-display);
    font-size: 0.9375rem;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
    transition: color 0.15s ease, border-color 0.15s ease;
}

.calculator-page .calculator-tabs .ui-tabs-nav .ui-tabs-anchor:hover {
    border-bottom-color: var(--h2w-line-light);
    color: var(--h2w-ink);
}

.calculator-page .calculator-tabs .ui-tabs-nav li.ui-tabs-active .ui-tabs-anchor {
    border-bottom-color: var(--h2w-blue);
    color: var(--h2w-blue);
    cursor: default;
}

.calculator-page .calculator-tabs .ui-tabs-nav .ui-tabs-anchor:focus-visible {
    outline: 2px solid var(--h2w-blue);
    outline-offset: -4px;
}

.calculator-page .calculator-tabs .ui-tabs-panel {
    display: flex;
    flex-direction: column;
    gap: 20px;
    padding: var(--calc-pad);
    border: 0;
    border-radius: 0;
    background: transparent;
    color: var(--h2w-ink);
}

.calculator-page .calculator-tabs .ui-tabs-panel[aria-hidden="true"],
.calculator-page .calculator-tabs .ui-tabs-hide {
    display: none;
}

.calculator-page .calculator-tabs .ui-tabs-panel a {
    color: var(--h2w-blue);
}

.calculator-page .calculator-tabs h4 {
    font-size: 1.25rem;
}

.calculator-page .calculator-tabs h5 {
    margin-bottom: -10px;
    color: var(--h2w-ink-muted);
    font-family: var(--h2w-font-body);
    font-size: 0.8125rem;
    font-weight: 600;
    letter-spacing: 0.02em;
}

/* Known-variable choice as a segmented set */
.calculator-page .radio-group {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin: 0;
    padding: 0;
    border: 0;
    background: none;
}

.calculator-page .radio-group label {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    min-height: var(--calc-control-h);
    margin: 0;
    padding: 0 14px;
    border: 1px solid var(--h2w-line-light);
    border-radius: 3px;
    background: #fff;
    color: var(--h2w-ink);
    font-size: 0.9375rem;
    font-weight: 400;
    cursor: pointer;
    transition: border-color 0.15s ease, background-color 0.15s ease;
}

.calculator-page .radio-group label:hover {
    border-color: #aab4c4;
}

.calculator-page .radio-group label:has(input:checked) {
    border-color: var(--h2w-blue);
    background: var(--calc-tint);
    color: var(--h2w-blue);
    font-weight: 500;
}

.calculator-page .radio-group input[type="radio"] {
    width: 16px;
    height: 16px;
    margin: 0;
    accent-color: var(--h2w-blue);
}

/* ---------- Equations ---------- */
.equation-image-container {
    display: flex;
    align-items: stretch;
    gap: 16px;
}

.calculator-page .mathjaxEquationImage1 {
    display: flex;
    flex: 0 0 auto;
    align-items: center;
    justify-content: center;
    margin: 0;
    padding: 12px;
    border: 1px solid var(--h2w-line-light);
    border-radius: 3px;
    background: #fff;
}

.calculator-page .mathjaxEquationImage1 img {
    display: block;
    max-width: 100%;
    height: auto;
}

.calculator-page .mathjaxEquation1 {
    display: flex;
    flex: 1 1 auto;
    align-items: center;
    justify-content: center;
    min-width: 0;
    min-height: 96px;
    margin: 0;
    padding: 12px 20px;
    border: 1px solid var(--h2w-line-light);
    border-radius: 3px;
    background: var(--h2w-paper);
    color: var(--h2w-ink);
    overflow-x: auto;
    overflow-y: hidden;
}

.calculator-page .mathjaxEquation1 > div {
    max-width: 100%;
}

.calculator-page .MathJax_Display {
    margin: 0.5em 0 !important;
}

/* ---------- Notes and worked examples ---------- */
.performance-notes,
.duty-cycle-note,
.ac-duty-cycle-note {
    margin-top: 16px;
    padding: 12px 16px;
    border-left: 3px solid var(--h2w-gold-lit);
    border-radius: 0 3px 3px 0;
    background: var(--h2w-paper);
    color: var(--h2w-ink-muted);
    font-size: 0.875rem;
}

.calculator-tabs .duty-cycle-note,
.calculator-tabs .ac-duty-cycle-note {
    margin-top: 0;
}

.performance-notes small {
    font-size: inherit;
}

.performance-notes p + p,
.ac-duty-cycle-note p + p {
    margin-top: 2px;
}

.duty-cycle-example,
.force-duty-cycle-example,
.torque-duty-cycle-example,
.ac-duty-cycle-info {
    margin: 0;
    padding: 0;
}

.force-duty-cycle-example,
.torque-duty-cycle-example,
.ac-duty-cycle-info {
    padding: 14px 16px;
    border: 1px solid var(--h2w-line-light);
    border-radius: 3px;
    font-size: 0.9375rem;
}

.force-duty-cycle-example p:first-child,
.torque-duty-cycle-example p:first-child,
.ac-duty-cycle-info p:first-child {
    margin-bottom: 6px;
}

.force-duty-cycle-example p + p,
.torque-duty-cycle-example p + p,
.ac-duty-cycle-info li,
.duty-cycle-example td {
    font-family: var(--h2w-font-mono);
    font-size: 0.875rem;
    font-variant-numeric: tabular-nums;
}

.ac-duty-cycle-info ul {
    margin: 0;
    padding-left: 20px;
}

.ac-duty-cycle-info li + li {
    margin-top: 2px;
}

.calculator-page .duty-cycle-example .variables-table td {
    padding-block: 8px;
}

/* ---------- Tablet and phone ---------- */
@media (max-width: 900px) {
    .calc-intro-lead {
        grid-template-columns: minmax(0, 1fr);
        gap: 16px;
    }

    .equation-image-container {
        flex-direction: column;
    }

    .calculator-page .mathjaxEquationImage1 {
        align-self: flex-start;
    }

    /* Tables become stacked rows: symbol + description, then units + value */
    .calculator-page .variables-table thead {
        display: none;
    }

    .calculator-page .variables-table,
    .calculator-page .variables-table tbody {
        display: block;
        width: 100%;
    }

    .calculator-page .variables-table tbody tr {
        display: grid;
        grid-template-columns: 112px minmax(0, 1fr);
        gap: 6px 12px;
        align-items: center;
        padding: 12px 14px;
        border-bottom: 1px solid var(--h2w-line-light);
    }

    .calculator-page .variables-table tbody tr:last-child {
        border-bottom: 0;
    }

    .calculator-page .variables-table th,
    .calculator-page .variables-table td,
    .calculator-page .variables-table tr > :first-child:nth-last-child(4),
    .calculator-page .variables-table tr > :nth-child(3):not(:last-child),
    .calculator-page .variables-table tr > :last-child:not(:first-child) {
        display: block;
        width: auto;
        padding: 0;
        border: 0;
    }

    /* Two-cell rows (label + value) and single-cell rows stack full width */
    .calculator-page .variables-table td:first-child:nth-last-child(2),
    .calculator-page .variables-table td:nth-child(2):last-child,
    .calculator-page .variables-table td:only-child {
        grid-column: 1 / -1;
    }

    .calculator-page .variables-table tr:has(.result) {
        background: var(--calc-tint);
        box-shadow: inset 3px 0 0 var(--h2w-blue);
    }

    .calculator-page .variables-table tr:has(.result) > td,
    .calculator-page .variables-table tr:has(.result) > td:first-child {
        background: transparent;
        box-shadow: none;
    }

    .calculator-page .variables-table td > span[id$="GValue"] {
        padding-right: 0;
    }

    /* Unit converter: type, then from value + units, then to value + units */
    .calculator-page #unitConverterTable tbody tr {
        grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
        gap: 12px;
        padding: 14px;
    }

    .calculator-page #unitConverterTable tr > td {
        width: auto;
        grid-column: auto;
    }

    .calculator-page #unitConverterTable td:nth-child(1) {
        width: auto;
        grid-column: 1 / -1;
    }

    .calculator-page #unitConverterTable td::before {
        display: block;
        margin-bottom: 4px;
        color: var(--h2w-ink-muted);
        font-size: 0.8125rem;
        font-weight: 600;
    }

    .calculator-page #unitConverterTable td:nth-child(1)::before { content: "Conversion type"; }
    .calculator-page #unitConverterTable td:nth-child(2)::before { content: "From value"; }
    .calculator-page #unitConverterTable td:nth-child(3)::before { content: "From units"; }
    .calculator-page #unitConverterTable td:nth-child(4)::before { content: "To value"; }
    .calculator-page #unitConverterTable td:nth-child(5)::before { content: "To units"; }

    /* Even columns give long unit names (radians/s², kg-cm-s²) room */
    .calculator-page .variables-table tbody tr {
        grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    }

    .calculator-page .variables-table select {
        padding-left: 10px;
        padding-right: 30px;
        background-position: right 10px center;
    }

    .calculator-page .variables-table input::placeholder {
        font-size: 0.875rem;
    }

    /* Scale equations down so most fit without sideways scrolling.
       The JS sets an inline 16px on some equation wrappers. */
    .calculator-page .mathjaxEquation1 > div {
        font-size: 12px !important;
    }

    .calculator-page .mathjaxEquation1 {
        min-height: 72px;
        padding: 8px 12px;
    }

    /* Phones need 16px inputs so iOS does not zoom on focus */
    .calculator-page .variables-table input,
    .calculator-page .variables-table select,
    .calculator-page .variables-table tr > :nth-child(3):not(:last-child) select {
        font-family: var(--h2w-font-body);
        font-size: 1rem;
    }
}

@media (max-width: 600px) {
    .calculator-page {
        gap: 16px;
    }

    .calculator-header {
        align-items: flex-start;
        flex-direction: column;
        gap: 12px;
    }

    .calculator-header .calculator-brief {
        flex: 0 0 auto;
    }

    .calculator-brief p {
        font-size: 1rem;
    }

    .calculator-page .radio-group {
        flex-direction: column;
    }

    .calculator-page .radio-group label {
        width: 100%;
    }

    .calculator-page .calculator-tabs .ui-tabs-nav .ui-tabs-anchor {
        min-height: 48px;
        font-size: 0.875rem;
    }

    .calculator-page .calculator-tabs .ui-tabs-panel {
        padding: 20px 16px;
    }
}
