/* ===================================================================
   Stylish Order Form Builder — Front-end (Shopify Polaris style)
   Flat, clean surfaces; subtle borders; compact controls; the signature
   Polaris button depth (inset bottom shadow). Brand colors are set inline
   on the wrapper from admin Settings; the .sofb-theme-light /
   .sofb-theme-dark class chooses the surface + text palette so the form
   looks right on both white and black/dark websites.
   Scoped under .sofb-public so the host theme can't break it.
   =================================================================== */

.sofb-public {
    /* Brand tokens (overridden inline from settings). */
    --sofb-primary: #2c6ecb;
    --sofb-accent: #1f5199;
    --sofb-btn-text: #ffffff;

    /* Surface + text tokens — Polaris light palette (dark theme overrides below). */
    --sofb-text: #202223;
    --sofb-bg: #ffffff;
    --sofb-form-bg: #ffffff;
    --sofb-subdued: #f6f6f7;
    --sofb-line: #e1e3e5;
    --sofb-line-strong: #c9cccf;
    --sofb-line-soft: #ebebeb;
    --sofb-muted: #6d7175;
    --sofb-ring: rgba(44, 110, 203, .25);
    --sofb-card-shadow: 0 0 0 1px rgba(22, 29, 37, .02), 0 1px 0 rgba(22, 29, 37, .05);
    --sofb-radius-card: 12px;
    --sofb-radius: 8px;

    box-sizing: border-box;
    width: 100%;
    max-width: 1000px;
    margin: 0 auto 40px;
    color: var(--sofb-text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Inter, Roboto, sans-serif;
    font-size: 14px;
    line-height: 1.5;
    text-align: left;
}

/* ---- Dark theme: for sites with black / dark backgrounds ---- */
.sofb-public.sofb-theme-dark {
    --sofb-text: #e3e5e7;
    --sofb-bg: #1a1c1d;
    --sofb-form-bg: #202223;
    --sofb-subdued: #2a2c2e;
    --sofb-line: #3a3d40;
    --sofb-line-strong: #4a4d50;
    --sofb-line-soft: #303234;
    --sofb-muted: #a7acb1;
    --sofb-ring: rgba(120, 170, 255, .35);
    --sofb-card-shadow: 0 0 0 1px rgba(0, 0, 0, .4), 0 1px 0 rgba(0, 0, 0, .3);
}

/* Reset only what commonly breaks embedded widgets, scoped to our tree. */
.sofb-public *,
.sofb-public *::before,
.sofb-public *::after { box-sizing: border-box; }
.sofb-public h2,
.sofb-public h3,
.sofb-public h4,
.sofb-public p,
.sofb-public ul,
.sofb-public li { margin: 0; padding: 0; }
.sofb-public table { border-collapse: collapse; width: 100%; }
.sofb-public input,
.sofb-public textarea,
.sofb-public button,
.sofb-public select { font-family: inherit; font-size: inherit; color: inherit; }

.sofb-order-form-wrap {
    background: var(--sofb-form-bg);
    border: 1px solid var(--sofb-line);
    border-radius: var(--sofb-radius-card);
    padding: clamp(16px, 2.5vw, 24px);
    box-shadow: var(--sofb-card-shadow);
}

/* ---- Header ---- */
.sofb-fhead {
    padding-bottom: 16px;
    margin-bottom: 4px;
    border-bottom: 1px solid var(--sofb-line);
}
.sofb-fhead h2 { font-size: 20px; font-weight: 600; line-height: 1.25; letter-spacing: -.01em; color: var(--sofb-text); }
.sofb-fhead p { margin-top: 4px; color: var(--sofb-muted); font-size: 14px; }

/* ---- Polaris text field (search) ---- */
.sofb-search { position: relative; margin: 18px 0 16px; }
.sofb-search-icon { position: absolute; left: 14px; top: 50%; transform: translateY(-50%) rotate(45deg); color: var(--sofb-muted); font-size: 15px; pointer-events: none; }
.sofb-search-input {
    width: 100%; padding: 8px 12px 8px 38px; min-height: 36px;
    color: var(--sofb-text);
    background: var(--sofb-bg);
    border: 1px solid var(--sofb-line-strong);
    border-radius: var(--sofb-radius);
    box-shadow: inset 0 1px 0 rgba(22, 29, 37, .03);
    outline: none; transition: border-color .12s, box-shadow .12s;
}
.sofb-search-input::placeholder { color: var(--sofb-muted); }
.sofb-search-input:focus { border-color: var(--sofb-primary); box-shadow: 0 0 0 2px var(--sofb-ring); }

/* ---- Polaris data table ---- */
.sofb-table-scroll {
    overflow: auto;
    max-height: 60vh;
    background: var(--sofb-bg);
    border: 1px solid var(--sofb-line);
    border-radius: var(--sofb-radius-card);
}
.sofb-ptable { min-width: 640px; }
.sofb-ptable th {
    text-align: left; font-size: 13px; font-weight: 600; color: var(--sofb-muted);
    text-transform: none; letter-spacing: normal;
    padding: 12px 16px;
    background: var(--sofb-subdued);
    border-bottom: 1px solid var(--sofb-line);
    position: sticky; top: 0; z-index: 2;
    white-space: nowrap;
}
.sofb-ptable td { padding: 12px 16px; border-bottom: 1px solid var(--sofb-line-soft); vertical-align: middle; }
.sofb-ptable tbody tr { transition: background .1s; }
.sofb-ptable tbody tr:hover { background: var(--sofb-subdued); }
.sofb-ptable tbody tr:last-child td { border-bottom: 0; }
.sofb-ptable .sofb-num { text-align: right; }
.sofb-pname { font-weight: 600; color: var(--sofb-text); }
.sofb-pdesc { color: var(--sofb-muted); font-size: 13px; max-width: 340px; }
.sofb-cat { display: inline-block; font-size: 12px; font-weight: 500; padding: 2px 10px; background: var(--sofb-subdued); border: 1px solid var(--sofb-line); border-radius: 999px; color: var(--sofb-text); }

/* ---- Polaris numeric field ---- */
.sofb-qty-input {
    width: 72px; padding: 7px 8px; text-align: center; font-weight: 500;
    color: var(--sofb-text);
    background: var(--sofb-bg);
    border: 1px solid var(--sofb-line-strong);
    border-radius: var(--sofb-radius);
    box-shadow: inset 0 1px 0 rgba(22, 29, 37, .03);
    outline: none; transition: border-color .12s, box-shadow .12s;
}
.sofb-qty-input:focus { border-color: var(--sofb-primary); box-shadow: 0 0 0 2px var(--sofb-ring); }
.sofb-line-total { font-weight: 600; font-variant-numeric: tabular-nums; }

.sofb-no-results { padding: 20px 16px; text-align: center; color: var(--sofb-muted); }

/* ---- Apparel variant grid ---- */
.sofb-apparel-card { background: var(--sofb-bg); border: 1px solid var(--sofb-line); border-radius: var(--sofb-radius-card); padding: 16px; margin-bottom: 12px; box-shadow: var(--sofb-card-shadow); }
.sofb-apparel-head { display: flex; align-items: flex-start; gap: 16px; margin-bottom: 12px; }
.sofb-apparel-info { flex: 1; }
.sofb-apparel-media { flex: 0 0 auto; }
.sofb-apparel-media .sofb-thumb { width: 64px; height: 64px; }
.sofb-apparel-head h4 { font-size: 15px; font-weight: 600; }
.sofb-apparel-head p { color: var(--sofb-muted); font-size: 13px; margin-top: 3px; }
.sofb-apparel-price { font-weight: 600; white-space: nowrap; color: var(--sofb-text); }
.sofb-grid-scroll { overflow-x: auto; border: 1px solid var(--sofb-line); border-radius: var(--sofb-radius); }
.sofb-variant-grid { min-width: 420px; }
.sofb-variant-grid th { text-align: left; font-size: 12px; font-weight: 600; color: var(--sofb-muted); padding: 9px 10px; background: var(--sofb-subdued); border-bottom: 1px solid var(--sofb-line); }
.sofb-variant-grid td { padding: 8px 10px; border-bottom: 1px solid var(--sofb-line-soft); font-weight: 500; }
.sofb-variant-grid .sofb-num { text-align: center; }
.sofb-variant-grid .sofb-qty-input { width: 58px; }
.sofb-apparel-foot { display: flex; justify-content: flex-end; gap: 12px; align-items: baseline; margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--sofb-line); }
.sofb-apparel-foot strong { font-size: 16px; color: var(--sofb-text); }

/* ---- Summary (clean Polaris surface, not a gradient) ---- */
.sofb-summary {
    display: flex; align-items: center; justify-content: space-between;
    margin-top: 16px; padding: 16px 20px;
    background: var(--sofb-subdued);
    border: 1px solid var(--sofb-line);
    border-radius: var(--sofb-radius-card);
}
.sofb-summary span { font-size: 14px; font-weight: 600; color: var(--sofb-muted); }
.sofb-grand-total { font-size: 22px; font-weight: 700; color: var(--sofb-text); font-variant-numeric: tabular-nums; }

/* ---- Customer panel ---- */
.sofb-customer { margin-top: 24px; }
.sofb-customer h3 { font-size: 15px; font-weight: 600; margin-bottom: 14px; }
.sofb-field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.sofb-field-grid label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; font-weight: 500; color: var(--sofb-text); }
.sofb-req { color: #d72c0d; }
.sofb-col-full { grid-column: 1 / -1; }
.sofb-field {
    width: 100%; padding: 8px 12px; min-height: 36px;
    color: var(--sofb-text);
    background: var(--sofb-bg);
    border: 1px solid var(--sofb-line-strong);
    border-radius: var(--sofb-radius);
    box-shadow: inset 0 1px 0 rgba(22, 29, 37, .03);
    outline: none; transition: border-color .12s, box-shadow .12s;
}
.sofb-field::placeholder { color: var(--sofb-muted); }
.sofb-field:focus { border-color: var(--sofb-primary); box-shadow: 0 0 0 2px var(--sofb-ring); }
.sofb-field.sofb-invalid { border-color: #d72c0d; box-shadow: 0 0 0 2px rgba(215, 44, 13, .2); }
textarea.sofb-field { resize: vertical; min-height: 92px; padding-top: 10px; }

/* ---- Actions — Polaris primary button ----
   Declared with extra specificity + !important on the properties host themes
   most often override (background / color / border / size), so the submit
   button keeps its look on any theme. */
.sofb-actions { margin-top: 22px; display: flex; flex-direction: column; gap: 10px; }
.sofb-public .sofb-public-btn,
.sofb-public button.sofb-public-btn {
    align-self: flex-start;
    display: inline-flex !important;
    align-items: center; justify-content: center;
    width: auto !important;
    margin: 0 !important;
    padding: 10px 20px !important; min-height: 38px !important;
    font-family: inherit !important;
    font-size: 14px !important; font-weight: 600 !important; line-height: 1 !important;
    text-transform: none !important; letter-spacing: normal !important;
    text-decoration: none !important;
    color: var(--sofb-btn-text) !important;
    background: var(--sofb-primary) !important;
    border: 1px solid rgba(0, 0, 0, .12) !important;
    border-radius: var(--sofb-radius) !important;
    cursor: pointer;
    box-shadow: 0 1px 0 rgba(22, 29, 37, .05), inset 0 -1px 0 rgba(0, 0, 0, .2) !important;
    transition: background .12s, box-shadow .12s, opacity .12s, transform .06s;
}
.sofb-public .sofb-public-btn:hover,
.sofb-public button.sofb-public-btn:hover { background: var(--sofb-accent) !important; color: var(--sofb-btn-text) !important; }
.sofb-public .sofb-public-btn:focus-visible { outline: none; box-shadow: 0 0 0 2px var(--sofb-form-bg), 0 0 0 4px var(--sofb-ring) !important; }
.sofb-public .sofb-public-btn:active { transform: translateY(1px); box-shadow: inset 0 1px 2px rgba(0, 0, 0, .25) !important; }
.sofb-public .sofb-public-btn.is-busy { opacity: .65; pointer-events: none; }
.sofb-notice { min-height: 20px; font-size: 13px; font-weight: 600; }
.sofb-notice.is-error { color: #d72c0d; }
.sofb-notice.is-success { color: #008060; }

/* ---- Standalone message ---- */
.sofb-message { max-width: 1000px; margin: 0 auto; padding: 14px 18px; background: #fff5ea; border: 1px solid #e1b878; border-radius: var(--sofb-radius-card); color: #5e4200; }

/* ---- Free-plan branding (do not hide without a Pro licence) ---- */
.sofb-powered { margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--sofb-line-soft); text-align: center; font-size: 13px; color: var(--sofb-muted); }
.sofb-powered a { color: var(--sofb-primary); font-weight: 600; text-decoration: none; }
.sofb-powered a:hover { text-decoration: underline; }

/* ---- Guard message shown only if branding is removed/hidden ---- */
.sofb-guard-error { display: flex; flex-direction: column; gap: 6px; align-items: center; text-align: center; padding: 28px 20px; color: var(--sofb-muted); }
.sofb-guard-error strong { font-size: 16px; color: var(--sofb-text); }
/* The [hidden] attribute must win over the display rules above. */
.sofb-form-body[hidden],
.sofb-guard-error[hidden] { display: none !important; }

/* ===================================================================
   Theme-proofing + new components (image / size / color / dropdown).
   Inputs are re-declared with .sofb-public specificity and !important on
   the few properties themes love to override (bg / color / border).
   =================================================================== */
.sofb-public .sofb-search-input,
.sofb-public .sofb-qty-input,
.sofb-public .sofb-opt-select,
.sofb-public .sofb-field {
    background-color: var(--sofb-bg) !important;
    color: var(--sofb-text) !important;
    border: 1px solid var(--sofb-line-strong) !important;
    border-radius: var(--sofb-radius) !important;
    font-family: inherit !important;
    line-height: 1.4 !important;
    box-shadow: inset 0 1px 0 rgba(22, 29, 37, .03);
}
.sofb-public .sofb-search-input:focus,
.sofb-public .sofb-qty-input:focus,
.sofb-public .sofb-opt-select:focus,
.sofb-public .sofb-field:focus {
    border-color: var(--sofb-primary) !important;
    box-shadow: 0 0 0 2px var(--sofb-ring) !important;
    outline: none;
}

/* ---- Image column ---- */
.sofb-col-img { width: 64px; }
.sofb-thumb {
    display: block; width: 48px; height: 48px;
    object-fit: cover; border-radius: 8px;
    border: 1px solid var(--sofb-line);
    background: var(--sofb-subdued);
}
.sofb-thumb-empty {
    background: var(--sofb-subdued) repeating-linear-gradient(45deg, transparent, transparent 6px, rgba(125,131,137,.12) 6px, rgba(125,131,137,.12) 12px);
}

/* ---- Size / Color pickers + Qty dropdown (Polaris select) ---- */
.sofb-public select.sofb-qty-input,
.sofb-public .sofb-opt-select {
    -webkit-appearance: none; -moz-appearance: none; appearance: none;
    min-height: 36px; padding: 7px 30px 7px 12px; font-weight: 500;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath stroke='%236d7175' stroke-width='1.6' fill='none' d='M1 1.5L6 6.5 11 1.5'/%3E%3C/svg%3E");
    background-repeat: no-repeat; background-position: right 10px center;
    cursor: pointer;
}
.sofb-public select.sofb-qty-input { width: 82px; text-align: left; }
.sofb-public .sofb-opt-select { min-width: 96px; max-width: 150px; }
.sofb-opt-empty { color: var(--sofb-muted); }

/* ===================================================================
   Table background option (admin-selectable): white / transparent / black
   =================================================================== */
.sofb-tablebg-transparent .sofb-table-scroll { background: transparent; }
.sofb-tablebg-transparent .sofb-ptable th { background: transparent; }

.sofb-tablebg-black .sofb-table-scroll { background: #16181a; border-color: #3a3d40; }
.sofb-tablebg-black .sofb-ptable th { background: #1f2123; color: #a7acb1; border-bottom-color: #3a3d40; }
.sofb-tablebg-black .sofb-ptable td { border-bottom-color: #2a2c2e; color: #e3e5e7; }
.sofb-tablebg-black .sofb-pname { color: #ffffff; }
.sofb-tablebg-black .sofb-pdesc,
.sofb-tablebg-black .sofb-ptable .sofb-num { color: #c5c8cc; }
.sofb-tablebg-black .sofb-ptable tbody tr:hover { background: #1f2123; }
.sofb-tablebg-black .sofb-cat { background: #2a2c2e; border-color: #3a3d40; color: #e3e5e7; }
.sofb-tablebg-black .sofb-public .sofb-qty-input,
.sofb-tablebg-black .sofb-public .sofb-opt-select,
.sofb-tablebg-black.sofb-public .sofb-qty-input,
.sofb-tablebg-black.sofb-public .sofb-opt-select {
    background-color: #1f2123 !important; color: #e3e5e7 !important; border-color: #4a4d50 !important;
}

@media (max-width: 760px) {
    .sofb-field-grid { grid-template-columns: 1fr; }
    .sofb-public-btn { align-self: stretch; }
    .sofb-summary { flex-direction: column; align-items: flex-start; gap: 4px; }
}
