/* forms.css - fillable PDF form fields (.ff-* inside each page's .form-layer, built by
   forms.js), the placeholder look of new "field" objects (.obj-field) and the field
   properties section.

   Everything on a page lives in page space: 1 CSS px = 1 pt and zoom is a transform on
   .page-space, so field text, fills and borders (document data, set inline by forms.js)
   scale with the page. Editing chrome that must keep a constant on-screen size (focus rings,
   hairlines, tags) divides by var(--s). Pages stay white in dark mode, so on-page chrome
   uses the light "ink on paper" colours in both themes. */

/* ------------------------------------------------------------------ form layer */

.ff-page {
    position: absolute;
    inset: 0;
    pointer-events: none;
    color-scheme: light;                 /* native popups (select, datalist) match the white page */
    --ff-hair: calc(1px / var(--s, 1));
    --ff-ink: var(--ink);
    --ff-ink-line: var(--ink-line);
}

:root[data-theme="dark"] .ff-page,
:root[data-theme="dark"] .obj-field {
    --ff-ink: var(--ink-soft);           /* near-black: legible on the white page */
    --ff-ink-line: var(--text-3);        /* (--ink is white in dark mode) */
}

.ff-w {
    position: absolute;
    box-sizing: border-box;
    pointer-events: none;
}

.ff-box {
    position: absolute;
    box-sizing: border-box;
    transform-origin: 50% 50%;
}

.ff-face,
.ff-cover {
    position: absolute;
    inset: 0;
    box-sizing: border-box;
    pointer-events: none;
    transition: box-shadow var(--dur-fast) var(--ease), background-color var(--dur-fast) var(--ease);
}

/* Hides the page's own "checked" artwork of a pre-checked box so it can be unchecked. */
.ff-cover { background: var(--paper); transition: none; }

.ff-clip {
    position: absolute;
    inset: 0;
    overflow: hidden;
}

/* ------------------------------------------------------------------ controls */

.ff-ctl {
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    min-width: 0;
    min-height: 0;
    box-sizing: border-box;
    margin: 0;
    padding: 0 2px;
    border: 0;
    border-radius: 0;
    background: transparent;
    color: inherit;
    font: inherit;
    line-height: normal;
    outline: none;
    box-shadow: none;
    -webkit-appearance: none;
    appearance: none;
    pointer-events: auto;
    cursor: text;
}

.ff-ctl::placeholder { color: transparent; }
.ff-ctl::-ms-reveal,
.ff-ctl::-ms-clear { display: none; }
.ff-ctl::-webkit-calendar-picker-indicator { display: none !important; }   /* datalist arrow: .ff-caret instead */

textarea.ff-ctl {
    padding: 2px;
    resize: none;
    overflow: auto;
    scrollbar-width: none;
    line-height: 1.15;
    white-space: pre-wrap;
    overflow-wrap: break-word;
}
textarea.ff-ctl::-webkit-scrollbar { display: none; }

select.ff-ctl {
    cursor: pointer;
    text-overflow: ellipsis;
}

select.ff-ctl[size] {
    padding: 0;
    overflow-y: auto;
    scrollbar-width: thin;
}

select.ff-ctl option {
    font: inherit;
    padding: 0 2px;
}

.ff-checkbox .ff-ctl,
.ff-radio .ff-ctl,
.ff-sign {
    padding: 0;
    cursor: pointer;
}

.ff-ctl:disabled { cursor: default; }

/* Check / radio glyph, drawn in the field's text colour. */
.ff-glyph {
    position: absolute;
    left: 50%;
    top: 50%;
    display: none;
    transform: translate(-50%, -50%);
    fill: currentColor;
    pointer-events: none;
}
.ff-on .ff-glyph { display: block; }

.ff-caret {
    position: absolute;
    right: 1px;
    top: 50%;
    transform: translateY(-50%);
    opacity: 0.6;
    pointer-events: none;
}

/* Read-only fields: the page canvas already shows them. */
.ff-w.ff-ro .ff-ctl {
    color: transparent;
    pointer-events: none;
}
.ff-w.ff-ro .ff-glyph,
.ff-w.ff-ro .ff-caret { display: none; }

/* Required marker: sits in the gutter directly to the LEFT of its own field, vertically centred
   on it (top-aligned for multi-line boxes and lists), where it reads as a prefix of that field
   and can't be mistaken for part of the next field's label or run into the label above it.
   Sized to actually read as an asterisk, not a speck (a 12px asterisk glyph is mostly empty). */
.ff-req {
    position: absolute;
    top: 50%;
    right: calc(100% + 2px / var(--s, 1));
    display: none;
    transform: translateY(-40%);
    font: 700 calc(18px / var(--s, 1)) / 1 var(--font-ui);
    color: var(--red-paper);
    text-shadow: 0 0 calc(2px / var(--s, 1)) var(--paper);
    pointer-events: none;
}
.ff-multi > .ff-req,
.ff-list > .ff-req {
    top: calc(1px / var(--s, 1));
    transform: none;
}
body[data-mode="fill"] .ff-req { display: block; }

/* Bigger hit area for small boxes on touch screens. */
@media (pointer: coarse) {
    .ff-checkbox .ff-ctl,
    .ff-radio .ff-ctl {
        left: calc(-6px / var(--s, 1));
        top: calc(-6px / var(--s, 1));
        width: calc(100% + 12px / var(--s, 1));
        height: calc(100% + 12px / var(--s, 1));
    }
}

/* ------------------------------------------------------------------ states */

/* Fill mode "Highlight fields": a tint and hairline on every fillable field. */
.forms-highlight .ff-w:not(.ff-ro) > .ff-box > .ff-face {
    background-image: linear-gradient(var(--field-tint), var(--field-tint));
    box-shadow: inset 0 0 0 var(--ff-hair) var(--field-line);
}

body:not(.forms-passthrough) .ff-w:not(.ff-ro):not(.ff-focus):hover > .ff-box > .ff-face {
    box-shadow: inset 0 0 0 var(--ff-hair) var(--select);
}

.ff-w.ff-focus > .ff-box > .ff-face,
.forms-highlight .ff-w.ff-focus:not(.ff-ro) > .ff-box > .ff-face {
    box-shadow: 0 0 0 calc(2px / var(--s, 1)) var(--select);
}

/* A drawing / placing tool is active: pointer goes through the fields to the page. */
.forms-passthrough .ff-ctl { pointer-events: none; }

/* ------------------------------------------------------------------ signature fields */

.ff-signature:not(.ff-ro) > .ff-box > .ff-face {
    border: var(--ff-hair) dashed var(--ff-ink-line);
    border-radius: calc(3px / var(--s, 1));
}

body:not(.forms-passthrough) .ff-signature:hover > .ff-box > .ff-face {
    background-color: var(--field-tint);
}

.ff-sign {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.3em;
    padding: 0 0.35em;
    overflow: hidden;
    white-space: nowrap;
    font-family: var(--font-ui);
    font-weight: 600;
    letter-spacing: 0.01em;
    color: var(--ff-ink);
}

.ff-sign-icon {
    flex: none;
    width: 1.35em;
    height: 1.35em;
}

.ff-sign-label {
    padding: 0 0.12em;
    background: var(--swipe);
}

.ff-sign-compact .ff-sign-label { display: none; }

.ff-signed { display: none; }

/* ------------------------------------------------------------------ new fields (field objects) */

/* Shown in every mode (Edit adds the outline and name tag). */
body .object-layer .obj.obj-field {
    display: block;
    visibility: visible;
    overflow: visible;
}

.ff-o-face {
    position: absolute;
    inset: 0;
    box-sizing: border-box;
    border: 1px solid var(--ff-o-border);   /* 1 pt, as it will be in the PDF */
    pointer-events: none;
}

.forms-highlight .obj-field .ff-o-face {
    background-image: linear-gradient(var(--field-tint), var(--field-tint));
}

body[data-mode="edit"] .obj-field .ff-o-face {
    border: calc(1px / var(--s, 1)) dashed var(--select);
    background: var(--select-soft);
}

.ff-o-text {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    box-sizing: border-box;
    padding: 0 2px;
    overflow: hidden;
    white-space: pre;
    line-height: 1.15;
    pointer-events: none;
}

.ff-o-text.ff-o-multi {
    align-items: flex-start;
    padding: 2px;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.ff-o-glyph {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    fill: currentColor;
    pointer-events: none;
}

.obj-field .ff-caret { right: 2px; }

/* Name tag above the field (Edit mode), constant size on screen. */
.ff-o-chip {
    position: absolute;
    left: 0;
    bottom: 100%;
    display: none;
    align-items: center;
    gap: calc(3px / var(--s, 1));
    max-width: calc(220px / var(--s, 1));
    margin-bottom: calc(2px / var(--s, 1));
    padding: calc(1px / var(--s, 1)) calc(5px / var(--s, 1));
    border-radius: calc(4px / var(--s, 1));
    background: var(--select);
    color: var(--marker-text);           /* white on orange fails AA; near-black is 5.9:1 */
    font: 600 calc(10.5px / var(--s, 1)) / 1.35 var(--font-ui);
    white-space: nowrap;
    pointer-events: none;
}

.ff-o-chip svg {
    flex: none;
    width: calc(11px / var(--s, 1));
    height: calc(11px / var(--s, 1));
}

.ff-o-chip span {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ff-o-req { font-weight: 700; }

body[data-mode="edit"] .obj-field .ff-o-chip { display: flex; }

/* ------------------------------------------------------------------ properties section */

.ff-props {
    display: grid;
    gap: 10px;
    min-width: 0;
}

.ff-p-stack {
    display: grid;
    gap: 6px;
    min-width: 0;
}

.ff-p-row {
    display: flex;
    align-items: center;
    min-height: 32px;
}

.ff-p-options {
    display: grid;
    gap: 4px;
}

.ff-p-opt {
    display: flex;
    align-items: center;
    gap: 4px;
}

.ff-p-opt .input {
    flex: 1;
    min-width: 0;
}

.ff-p-err {
    color: var(--red);
    font-size: var(--fs-xs);
    line-height: 1.35;
}
.ff-p-err:empty { display: none; }

.ff-p-note {
    margin: 0;
    color: var(--text-3);
    font-size: var(--fs-xs);
    line-height: 1.4;
}

.ff-props textarea.input {
    min-height: 64px;
    resize: vertical;
}

.ff-props .input[aria-invalid="true"] {
    border-color: var(--red);
}
