/*
 * The chart builder: the form beside a live preview on a wide screen, the
 * preview above the form on a phone so the chart is the first thing seen.
 */

.content { max-width: 1240px; }

.builder {
    display: grid;
    grid-template-columns: minmax(320px, 400px) 1fr;
    gap: 2rem;
    align-items: start;
}

/* The preview stays in view while a long form scrolls past it. */
.builder-preview { position: sticky; top: 1rem; }

@media (max-width: 860px) {
    .builder { grid-template-columns: 1fr; gap: 1.5rem; }
    .builder-preview { position: static; order: -1; }
}

.builder-form h1 { margin-bottom: 1.25rem; }

/* ── Fields ── */
.field {
    display: block;
    border: 0;
    margin: 0 0 1.25rem;
    min-width: 0;
}
.field[hidden] { display: none; }
.field-label, .field legend {
    display: block;
    font-weight: 700;
    font-size: 0.9rem;
    color: var(--text-head);
    margin-bottom: 0.4rem;
    padding: 0;
}
.field-hint { color: var(--text-muted); font-size: 0.85rem; margin-top: 0.5rem; }

.field-pair {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
}

.builder-form input[type="text"],
.builder-form input[type="search"],
.builder-form select,
.icon-picker input[type="search"] {
    width: 100%;
    font: inherit;
    color: var(--text);
    background: var(--input-bg);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 0.55rem 0.7rem;
}
.builder-form input:focus-visible,
.builder-form select:focus-visible,
.icon-picker input:focus-visible {
    outline: 2px solid var(--brand);
    outline-offset: 1px;
}

.builder-form input[type="range"] { width: 100%; accent-color: var(--brand); }

/* Radio and checkbox choices drawn as pills; the input stays in the
   accessibility tree, only visually replaced. */
.choice-row { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.choice { position: relative; cursor: pointer; }
.choice input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.choice span {
    display: inline-block;
    padding: 0.45rem 0.85rem;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--surface);
    font-size: 0.9rem;
    font-weight: 600;
}
.choice--small span { padding: 0.35rem 0.6rem; min-width: 3rem; text-align: center; }
.choice input:checked + span {
    background: var(--brand);
    border-color: var(--brand);
    color: var(--on-brand);
}
.choice input:focus-visible + span { outline: 2px solid var(--brand); outline-offset: 2px; }

/* A theme's swatch is its own colours, passed from the template, because it
   previews what will print rather than the site's chrome. */
.choice--theme span::before {
    content: "";
    display: inline-block;
    width: 0.8rem;
    height: 0.8rem;
    margin-right: 0.4rem;
    vertical-align: -0.05rem;
    border-radius: 50%;
    background: var(--swatch);
    box-shadow: 0 0 0 2px var(--swatch-tint);
}

/* ── Rows ── */
.row-list { list-style: none; margin-bottom: 0.6rem; }
.row-item {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    margin-bottom: 0.4rem;
}
.row-item input { flex: 1; min-width: 0; }
.row-tools { display: flex; gap: 0.15rem; }

.icon-button, .tool-button {
    flex-shrink: 0;
    display: inline-grid;
    place-items: center;
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text-soft);
    font: inherit;
    cursor: pointer;
}
.icon-button { width: 2.6rem; height: 2.6rem; border-radius: 10px; }
.icon-button svg { width: 1.8rem; height: 1.8rem; }
.icon-button.is-empty svg { display: none; }
.icon-button.is-empty::after { content: "+"; font-size: 1.3rem; color: var(--text-muted); }
.tool-button { width: 2rem; height: 2rem; border-radius: 8px; font-size: 1rem; line-height: 1; }
.tool-button:disabled { opacity: 0.35; cursor: default; }
.icon-button:hover, .tool-button:not(:disabled):hover { border-color: var(--brand); }
.icon-button:focus-visible, .tool-button:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; }

.button--quiet {
    background: var(--surface);
    color: var(--brand);
    border: 1px solid var(--border);
    box-shadow: 0 3px 0 var(--border);
    padding: 0.55rem 1.1rem;
}
.button--quiet:hover, .button--quiet:focus-visible { background: var(--surface-2); color: var(--brand); }
.button--quiet:active { box-shadow: 0 0 0 var(--border); }
.button:disabled { opacity: 0.5; cursor: default; }

.builder-actions { display: flex; flex-wrap: wrap; gap: 0.6rem; margin-top: 0.5rem; }

/* ── Icon picker ── */
.icon-picker {
    border: 0;
    padding: 0;
    margin: auto;
    width: min(92vw, 34rem);
    max-height: min(85vh, 40rem);
    border-radius: 16px;
    background: var(--surface);
    color: var(--text);
    box-shadow: var(--shadow-card), 0 20px 50px rgba(0, 0, 0, 0.3);
}
.icon-picker::backdrop { background: rgba(0, 0, 0, 0.45); }
.icon-picker-body { padding: 1rem 1.1rem 1.25rem; }
.icon-picker-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.75rem;
}
.icon-picker-head h2 { margin: 0; font-size: 1.15rem; }
.icon-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(5.2rem, 1fr));
    gap: 0.4rem;
    margin-top: 0.75rem;
}
.icon-option {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.25rem;
    padding: 0.5rem 0.25rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    color: var(--text-soft);
    font: inherit;
    font-size: 0.75rem;
    line-height: 1.2;
    text-align: center;
    cursor: pointer;
}
.icon-option[hidden] { display: none; }
.icon-option svg { width: 2.2rem; height: 2.2rem; }
.icon-option:hover, .icon-option:focus-visible { border-color: var(--brand); background: var(--surface-2); }
.icon-none {
    width: 2.2rem;
    height: 2.2rem;
    border: 2px dashed var(--border);
    border-radius: 50%;
}

@media (max-width: 600px) {
    .field-pair { grid-template-columns: 1fr; }
}

/* On paper only the chart remains: the form is .no-print, and the grid would
   otherwise keep its column widths around the sheet. */
@media print {
    .builder { display: block; }
    .builder-preview { position: static; }
}
