/* Shared form controls and buttons.

   This replaces four divergent copies of the same input rule:

     .bld-row input          12.5px / 6px 8px / --bg  / focus --border3 (grey)
     .bld-pixel-control      a verbatim copy-paste of the above
     select.sel, input.srch  12px   / 5px 8px / --bg2 / focus --blue-text
     .review-field input     a fourth set, in agent-actions.css

   So the builder focused grey and the toolbar focused blue on the same
   screen, and heights were unset (except one hard-coded 32px) so controls in
   a row never lined up. Everything here is one 30px height, one focus
   treatment, and one error treatment that reuses the focus ring geometry.

   Markup shape:

     <label class="fld c-3">
       <span class="fld-label">daily budget</span>
       <input class="ctrl" type="number">
       <span class="fld-hint">Minimum $5 on this account.</span>
     </label>

   A <select> needs nothing extra — .ctrl draws its own chevron as a background
   image, so adopting the control on existing markup is just adding the class.
   .ctrl-wrap is optional, for the rare case something needs to be positioned
   against the control. */

/* ── field ──────────────────────────────────────────────────────────────
   Labels are sentence case on purpose. When every label is uppercase they
   compete with the section headers and the form flattens to one volume;
   micro-caps belong to .bld-section h3 alone. */

.fld {
    display: flex;
    flex-direction: column;
    gap: 5px;
    min-width: 0;
}

.fld-label {
    font-size: 12px;
    font-weight: 500;
    color: var(--text-label);
    display: flex;
    align-items: center;
    gap: 6px;
}

.fld-hint {
    font-size: 10.5px;
    color: var(--text3);
}

.fld-hint.is-error {
    color: var(--red-text);
}

.ctrl-wrap {
    position: relative;
    display: block;
}

/* ── control ────────────────────────────────────────────────────────────
   30px matches .btn in components.css, so a button sitting beside a field
   lands on the same baseline. */

/* Legacy control selectors from before this file existed. They are listed
   alongside .ctrl rather than restyled in their own files, so the appearance
   has exactly one definition. Each had drifted: different backgrounds (--bg2
   vs --bg3 vs --bg), paddings, font sizes, and in one case a hard-coded 6px
   radius. Their own files keep only genuinely local properties — widths and
   placement. Migrate the markup to .ctrl and these can be dropped. */

.ctrl {
    display: block;
    width: 100%;
}

.ctrl,
select.sel,
input.srch,
.rv-tb-select,
.adspy-filter-search,
.adspy-filter-select {
    height: 30px;
    padding: 0 9px;
    font-family: var(--mono);
    font-size: 12.5px;
    color: var(--text);
    background-color: var(--bg);
    border: 1px solid var(--border2);
    border-radius: var(--r);
    outline: none;
    box-shadow: 0 0 0 0 transparent;
    transition: border-color var(--t-fast) var(--e-out),
    box-shadow var(--t-fast) var(--e-out),
    background-color var(--t-fast) var(--e-out);
}

.ctrl::placeholder,
input.srch::placeholder,
.adspy-filter-search::placeholder {
    color: var(--text3);
}

.ctrl:hover:not(:disabled),
select.sel:hover,
input.srch:hover,
.rv-tb-select:hover,
.adspy-filter-search:hover,
.adspy-filter-select:hover {
    border-color: var(--border3);
}

/* One focus treatment everywhere. The builder's copy stepped --border2 (13%
   white) to --border3 (20%) — a change you cannot see on a dark ground — while
   the toolbar's copy went blue, so the app answered "where is my cursor" two
   different ways on the same screen. */
.ctrl:focus,
select.sel:focus,
input.srch:focus,
.rv-tb-select:focus,
.adspy-filter-search:focus,
.adspy-filter-select:focus {
    border-color: var(--blue-text);
    box-shadow: 0 0 0 3px rgba(46, 95, 168, 0.24);
}

.ctrl:disabled {
    opacity: 0.45;
    cursor: not-allowed;
    background-color: var(--bg2);
}

textarea.ctrl {
    height: auto;
    min-height: 62px;
    padding: 7px 9px;
    line-height: 1.55;
    resize: vertical;
}

/* Drawn chevron, so the control inherits the theme instead of whatever the OS
   decides a dark dropdown arrow should look like. It is a background image
   rather than a pseudo-element on a wrapper, which means adopting .ctrl on an
   existing <select> needs no extra markup. The stroke is --text2 (#8a8880)
   hard-coded, since custom properties can't cross into a data URI. */
select.ctrl,
select.sel,
select.rv-tb-select,
select.adspy-filter-select,
select.brand-team-select {
    appearance: none;
    -webkit-appearance: none;
    padding-right: 26px;
    cursor: pointer;
    background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%238a8880' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 9px center;
}

/* The native popup list is drawn by the OS and inherits nothing, so give the
   options an explicit dark ground rather than leaving them white-on-white. */
select.ctrl option,
select.sel option,
select.rv-tb-select option,
select.adspy-filter-select option,
select.brand-team-select option,
select.finput option {
    background: var(--bg2);
    color: var(--text);
}

/* Denser variant for toolbar filter rows, which sit tighter than a form. */
.ctrl-sm {
    height: 27px;
    font-size: 12px;
}

/* Error reuses the focus ring's width and radius so the two read as one
   system. The old rule needed !important and a different ring width. */
.fld.is-error .ctrl,
.ctrl.is-error {
    border-color: var(--red-text);
    box-shadow: 0 0 0 3px rgba(168, 58, 58, 0.22);
}

/* ── checkbox / radio ───────────────────────────────────────────────────
   Drawn rather than native: the OS-rendered controls were the loudest
   non-minimal element on a dark monospace page. The real input stays in the
   DOM and keeps all its keyboard behaviour. */

.chk {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 12.5px;
    color: var(--text);
    cursor: pointer;
    user-select: none;
}

.chk input {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
    margin: 0;
}

.chk-box {
    width: 15px;
    height: 15px;
    flex-shrink: 0;
    border: 1px solid var(--border3);
    border-radius: 3px;
    background: var(--bg);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background-color var(--t-fast) var(--e-out),
    border-color var(--t-fast) var(--e-out),
    box-shadow var(--t-fast) var(--e-out);
}

.chk-box.round {
    border-radius: 50%;
}

.chk-box svg {
    width: 9px;
    height: 9px;
    opacity: 0;
    transform: scale(0.5);
    transition: opacity var(--t-fast) var(--e-out),
    transform var(--t-fast) var(--e-spring);
}

.chk-box .dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--bg);
    opacity: 0;
    transform: scale(0.3);
    transition: opacity var(--t-fast) var(--e-out),
    transform var(--t-fast) var(--e-spring);
}

.chk input:checked + .chk-box {
    background: var(--green);
    border-color: var(--green);
}

.chk input:checked + .chk-box svg,
.chk input:checked + .chk-box .dot {
    opacity: 1;
    transform: none;
}

.chk input:focus-visible + .chk-box {
    box-shadow: 0 0 0 3px rgba(46, 95, 168, 0.30);
    border-color: var(--blue-text);
}

.chk:hover .chk-box {
    border-color: var(--text2);
}

/* ── buttons ────────────────────────────────────────────────────────────
   The app already had one button — .btn in components.css, used in 150-odd
   places with primary / danger / success / ghost variants. It has been brought
   up to this system (30px to match .ctrl, token transitions, a focus ring)
   rather than duplicated here, so there is one button rather than two. */

/* ── help bubble ────────────────────────────────────────────────────── */

.help {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--bg4);
    color: var(--text2);
    font-size: 9.5px;
    cursor: help;
    flex-shrink: 0;
    transition: background-color var(--t-instant) linear,
    color var(--t-instant) linear;
}

.help:hover {
    background: var(--border3);
    color: var(--text);
}

/* ── 12-column form grid ────────────────────────────────────────────────
   Fields declare a span, so every row shares the same column edges and the
   form lines up vertically all the way down.

   The rule this replaces was repeat(auto-fit, minmax(200px, 1fr)), which let
   each row pick its own column count from whatever width was available: a
   five-field row broke to four across plus one orphan at quarter width, and
   no two rows agreed on where a column started. */

.fgrid {
    display: grid;
    grid-template-columns: repeat(12, minmax(0, 1fr));
    gap: 11px 12px;
    align-items: end;
}

.c-2 { grid-column: span 2; }
.c-3 { grid-column: span 3; }
.c-4 { grid-column: span 4; }
.c-5 { grid-column: span 5; }
.c-6 { grid-column: span 6; }
.c-8 { grid-column: span 8; }
.c-9 { grid-column: span 9; }
.c-12 { grid-column: 1 / -1; }

@media (max-width: 1000px) {
    .fgrid > .c-2,
    .fgrid > .c-3 {
        grid-column: span 4;
    }

    .fgrid > .c-5,
    .fgrid > .c-8,
    .fgrid > .c-9 {
        grid-column: span 6;
    }
}

@media (max-width: 680px) {
    .fgrid > [class*="c-"] {
        grid-column: 1 / -1;
    }
}
