/**
 * Estimate, storefront styles.
 *
 * The quote page reads like an estimator's worksheet: a ruled ledger of
 * requested items totted up by hand, then signed off with the request form.
 * The accent is a pencil-ruled ledger ochre (not a stock SaaS blue) and the
 * single crafted moment is the "tally rule", the under-total stroke a
 * quantity surveyor draws beneath a column of figures, which sweeps in under
 * the submit button the instant the request is sent.
 *
 * Everything is driven by themeable --estimate-* tokens with theme-inheriting
 * fallbacks, so it sits naturally in any theme. Motion is guarded by
 * prefers-reduced-motion and colours adapt to a dark colour-scheme. There is
 * no layout shift: the tally rule is a transform on a pseudo-element.
 */

.estimate-quote {
    /* Ledger ochre, the colour of a pencil-ruled worksheet, not stock blue.
       Deepened to clear WCAG AA: as text on the paper surface it reaches
       5.5:1 (>=4.5), and the header rule alpha is raised so the 2px ledger
       hairline holds >=3:1. */
    --estimate-accent: #8a5a12;
    --estimate-accent-soft: rgba(138, 90, 18, 0.14);
    --estimate-ink: var(--wp--preset--color--contrast, #2b2722);
    --estimate-rule: rgba(138, 90, 18, 0.7);
    --estimate-paper: rgba(138, 90, 18, 0.05);
    --estimate-radius: 8px;
    --estimate-gap: 1.5rem;
    --estimate-border: rgba(0, 0, 0, 0.12);
    --estimate-muted: rgba(0, 0, 0, 0.6);
    --estimate-success-bg: #ecfdf5;
    --estimate-success-fg: #065f46;
    --estimate-error-bg: #fef2f2;
    --estimate-error-fg: #991b1b;

    max-width: 760px;
    color: var(--estimate-ink);
}

/* Dark values follow the page's color-scheme (set by the theme), not the OS.
   Custom properties accept any value, so the light-dark() tokens sit behind
   @supports: older browsers keep the plain light tokens above. */
@supports (color: light-dark(white, black)) {
    .estimate-quote {
        --estimate-accent: light-dark(#8a5a12, #e0a94a);
        --estimate-accent-soft: light-dark(rgba(138, 90, 18, 0.14), rgba(224, 169, 74, 0.16));
        --estimate-ink: var(--wp--preset--color--contrast, light-dark(#2b2722, #ece7df));
        --estimate-rule: light-dark(rgba(138, 90, 18, 0.7), rgba(224, 169, 74, 0.6));
        --estimate-paper: light-dark(rgba(138, 90, 18, 0.05), rgba(224, 169, 74, 0.06));
        --estimate-border: light-dark(rgba(0, 0, 0, 0.12), rgba(255, 255, 255, 0.18));
        --estimate-muted: light-dark(rgba(0, 0, 0, 0.6), rgba(255, 255, 255, 0.65));
        --estimate-success-bg: light-dark(#ecfdf5, rgba(6, 95, 70, 0.25));
        --estimate-success-fg: light-dark(#065f46, #6ee7b7);
        --estimate-error-bg: light-dark(#fef2f2, rgba(153, 27, 27, 0.25));
        --estimate-error-fg: light-dark(#991b1b, #fca5a5);
    }
}

/* Fallback for browsers without light-dark(): the previous OS-based dark mode. */
@supports not (color: light-dark(white, black)) {
    @media (prefers-color-scheme: dark) {
        .estimate-quote {
            --estimate-accent: #e0a94a;
            --estimate-accent-soft: rgba(224, 169, 74, 0.16);
            --estimate-ink: var(--wp--preset--color--contrast, #ece7df);
            --estimate-rule: rgba(224, 169, 74, 0.6);
            --estimate-paper: rgba(224, 169, 74, 0.06);
            --estimate-border: rgba(255, 255, 255, 0.18);
            --estimate-muted: rgba(255, 255, 255, 0.65);
            --estimate-success-bg: rgba(6, 95, 70, 0.25);
            --estimate-success-fg: #6ee7b7;
            --estimate-error-bg: rgba(153, 27, 27, 0.25);
            --estimate-error-fg: #fca5a5;
        }
    }
}

/* The list reads as an estimator's worksheet: a titled slip on ruled paper. */
.estimate-quote__list-form {
    position: relative;
    border: 1px solid var(--estimate-border);
    border-top: 3px solid var(--estimate-accent);
    border-radius: var(--estimate-radius);
    background: var(--estimate-paper);
    padding: 1.25rem 1.25rem 0.75rem;
    margin-bottom: var(--estimate-gap);
}

.estimate-quote__slip-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 0.75rem;
    margin: 0 0 0.75rem;
    font-size: 0.78rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    font-weight: 700;
    color: var(--estimate-accent);
}

.estimate-quote__slip-count {
    font-weight: 600;
    letter-spacing: 0.04em;
    color: var(--estimate-muted);
}

.estimate-quote__table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 1.25rem;
}

.estimate-quote__table th,
.estimate-quote__table td {
    text-align: left;
    padding: 0.75rem 0.5rem;
    border-bottom: 1px solid var(--estimate-border);
    vertical-align: middle;
}

/* Ledger rule: the ochre baseline drawn under the column headers. */
.estimate-quote__table thead th {
    font-size: 0.74rem;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: var(--estimate-muted);
    border-bottom: 2px solid var(--estimate-rule);
}

.estimate-quote__qty {
    width: 5rem;
    max-width: 100%;
}

.estimate-quote__remove-cell {
    text-align: right;
    width: 3rem;
}

.estimate-quote__remove {
    background: none;
    border: 0;
    font-size: 1.25rem;
    line-height: 1;
    cursor: pointer;
    color: var(--estimate-muted);
    padding: 0.25rem 0.5rem;
    border-radius: var(--estimate-radius);
    transition: color 0.15s ease, background-color 0.15s ease;
}

.estimate-quote__remove:hover,
.estimate-quote__remove:focus-visible {
    color: var(--estimate-error-fg);
    background: var(--estimate-error-bg);
}

.estimate-quote__list-actions {
    margin: 0;
}

.estimate-quote__form {
    padding-top: 0.5rem;
}

.estimate-quote__form > h2 {
    margin-top: 0;
}

.estimate-quote__field {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    margin-bottom: 1rem;
}

.estimate-quote__field input,
.estimate-quote__field textarea,
.estimate-quote__field select {
    width: 100%;
    max-width: 480px;
}

.estimate-quote__field input:focus,
.estimate-quote__field textarea:focus,
.estimate-quote__field select:focus {
    outline: 2px solid var(--estimate-accent);
    outline-offset: 1px;
}

/* Add-on checkbox fields keep the box next to its label, not above it. */
.estimate-quote__check {
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
}

.estimate-quote__check input {
    width: auto;
    margin-top: 0.2rem;
}

.estimate-quote__hint {
    color: var(--estimate-muted);
    font-size: 0.875em;
}

.estimate-quote__req {
    color: var(--estimate-error-fg);
}

.estimate-quote__error {
    color: var(--estimate-error-fg);
    font-size: 0.875em;
}

.estimate-quote__notice {
    border-radius: var(--estimate-radius);
    padding: 1rem 1.25rem;
    margin-bottom: 1.5rem;
}

.estimate-quote__notice--success {
    background: var(--estimate-success-bg);
    color: var(--estimate-success-fg);
}

.estimate-quote__notice--error {
    background: var(--estimate-error-bg);
    color: var(--estimate-error-fg);
}

.estimate-quote__empty {
    text-align: center;
    padding: 2rem 1rem;
    color: var(--estimate-muted);
}

/*
 * THE MOMENT: "Send quote request" is an estimate being signed off. The submit
 * sits on a baseline; pressing it draws the tally rule, the under-total stroke
 * an estimator rules beneath a column of figures before writing the total, 
 * left to right beneath the button. No layout shift: the rule is a scaleX
 * transform on a pseudo-element that already occupies its space.
 */
.estimate-quote__submit {
    position: relative;
    display: inline-block;
    margin: 0.5rem 0 0;
}

.estimate-quote__submit::after {
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    bottom: -7px;
    height: 2px;
    background: var(--estimate-accent);
    border-radius: 2px;
    transform: scaleX(0);
    transform-origin: left center;
    transition: transform 0.42s cubic-bezier(0.22, 0.61, 0.36, 1);
    pointer-events: none;
}

.estimate-quote__submit .button {
    position: relative;
}

/* The rule is drawn the moment the figures are totted up (button pressed). */
.estimate-quote__submit.is-tallying::after {
    transform: scaleX(1);
}

/* A second, fainter pencil ghost-line under the main rule for hand-ruled feel. */
.estimate-quote__submit::before {
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    bottom: -11px;
    height: 1px;
    background: var(--estimate-rule);
    border-radius: 1px;
    transform: scaleX(0);
    transform-origin: left center;
    transition: transform 0.42s cubic-bezier(0.22, 0.61, 0.36, 1) 0.06s;
    pointer-events: none;
}

.estimate-quote__submit.is-tallying::before {
    transform: scaleX(0.96);
}

/* Storefront "Add to quote" button feedback. */
.estimate-add-to-quote {
    transition: opacity 0.15s ease;
}

.estimate-add-to-quote.estimate-added {
    opacity: 0.75;
}

/* Option picker on a variable product page. */
.estimate-variation-form__field {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    margin-bottom: 1rem;
}

.estimate-variation-form__field select {
    max-width: 320px;
}

.estimate-variation-form__notice,
.estimate-quote__privacy {
    font-size: 0.9em;
}

@media (max-width: 600px) {
    .estimate-quote__table thead {
        display: none;
    }

    .estimate-quote__table,
    .estimate-quote__table tbody,
    .estimate-quote__table tr,
    .estimate-quote__table td {
        display: block;
        width: 100%;
    }

    .estimate-quote__table td {
        border-bottom: 0;
        padding: 0.35rem 0.5rem;
    }

    .estimate-quote__table tr {
        border-bottom: 1px solid var(--estimate-border);
        padding: 0.5rem 0;
    }

    .estimate-quote__table td[data-label]::before {
        content: attr(data-label) ": ";
        font-weight: 600;
        color: var(--estimate-muted);
    }
}

@media (prefers-reduced-motion: reduce) {
    .estimate-add-to-quote,
    .estimate-quote__remove {
        transition: none;
    }

    /* Honour the rule as a static mark, no sweep. */
    .estimate-quote__submit::after,
    .estimate-quote__submit::before {
        transition: none;
    }
}
