/* ==========================================================================
   Olive Members: the form renderer (Views/Shared/Forms) and its runtime
   (js/om-forms.js). Builds on the synced Olive sheets: cards, form controls,
   .ol-error and the public shell come from there; this adds sections, rows,
   choices, ratings, signatures, files, the wizard and read-only answers.
   ========================================================================== */

[data-hidden] { display: none !important; }
.om-step-off { display: none !important; }

/* ===== Sections ============================================================ */
.om-form { display: flex; flex-direction: column; gap: 1rem; }
.om-form > .card, .om-section { margin-bottom: 0; }
.om-intro .card-body p:last-child { margin-bottom: 0; }
.om-intro .card-body { color: var(--ink-700); line-height: 1.6; }
.om-section-head { display: flex; gap: .85rem; align-items: flex-start; margin-bottom: 1.1rem; }
.om-section-n {
  flex: 0 0 auto; width: 30px; height: 30px; border-radius: 10px; display: grid; place-items: center;
  background: var(--plum-50); color: var(--plum-900); font-weight: 700; font-size: .9rem; font-variant-numeric: tabular-nums;
}
.om-section-title { margin: .2rem 0 0; font-size: 1.05rem; font-weight: 700; color: var(--ink-900); letter-spacing: -.01em; }
.om-section-desc { margin: .3rem 0 0; color: var(--ink-500); font-size: .92rem; }
.om-section.has-error { box-shadow: 0 0 0 2px rgba(192, 57, 43, .25); }

/* ===== Fields ============================================================== */
.om-field .form-label { font-weight: 600; }
.om-field.has-error .form-control, .om-field.has-error .form-select { border-color: #C0392B; }
.om-heading { margin: .5rem 0 0; font-size: .8rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-500); }
.om-paragraph { background: var(--cream, #FFF8F1); border: 1px solid var(--line); border-radius: 12px; padding: .9rem 1rem; color: var(--ink-700); font-size: .93rem; line-height: 1.6; }
.om-paragraph p:last-child { margin-bottom: 0; }
.om-divider { margin: .25rem 0; border-color: var(--line); opacity: 1; }
.om-calc { background: var(--plum-50) !important; font-weight: 700; font-variant-numeric: tabular-nums; }

/* Yes / No as a pair of pills */
.om-choice-row { display: flex; gap: .5rem; flex-wrap: wrap; }
.om-choice {
  min-width: 96px; border: 1px solid var(--line-2); background: #fff; color: var(--ink-700); font-weight: 600; border-radius: 999px; padding: .5rem 1.1rem;
}
.btn-check:checked + .om-choice { background: var(--plum-900); border-color: var(--plum-900); color: #fff; }
.btn-check:focus-visible + .om-choice { box-shadow: 0 0 0 4px rgba(var(--om-secondary-rgb), .2); }

/* Lists of options as tappable rows */
.om-options { display: grid; gap: .45rem; }
.om-options .form-check.border {
  margin: 0; min-height: 44px; display: flex; align-items: center; padding: .5rem .85rem .5rem 2.4rem; border-radius: 10px;
  border-color: var(--line-2) !important; background: #fff; transition: background-color .12s ease, border-color .12s ease;
}
.om-options .form-check.border:hover { background: var(--plum-50); }
.om-options .form-check.border:has(:checked) { background: var(--plum-50); border-color: var(--plum-500) !important; }
.om-options .form-check-input { margin-left: -1.6rem; }

/* Rating: stars filled from the left (inputs are in reverse order for the CSS sibling trick) */
.om-rating { display: inline-flex; flex-direction: row-reverse; gap: .15rem; }
.om-rating input { position: absolute; opacity: 0; pointer-events: none; }
.om-rating label { font-size: 1.9rem; line-height: 1; color: var(--line-2); cursor: pointer; transition: color .1s ease, transform .1s ease; }
.om-rating label:hover, .om-rating label:hover ~ label, .om-rating input:checked ~ label { color: #E0A526; }
.om-rating label:hover { transform: scale(1.08); }
.om-rating input:focus-visible + label { outline: 2px solid var(--plum-500); outline-offset: 2px; border-radius: 4px; }

/* Files */
.om-file { display: grid; gap: .5rem; }
.om-file-kept { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }
.om-file-chip {
  display: inline-flex; align-items: center; gap: .4rem; max-width: 100%; padding: .3rem .7rem; border-radius: 999px;
  background: var(--plum-50); color: var(--plum-900); font-weight: 600; font-size: .86rem; text-decoration: none;
}
.om-file-chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
a.om-file-chip:hover { background: var(--plum-100, #E6E1F7); color: var(--plum-900); }

/* Signature pad */
.om-signature { border: 1px dashed var(--line-2); border-radius: 12px; background: #fff; overflow: hidden; }
.om-signature canvas { display: block; width: 100%; height: 150px; touch-action: none; cursor: crosshair;
  background: linear-gradient(to top, transparent 34px, var(--line) 34px, var(--line) 35px, transparent 35px); }
.om-signature.signed { border-style: solid; border-color: var(--plum-300, #B7A9E0); }
.om-signature-bar { display: flex; justify-content: space-between; align-items: center; gap: .5rem; padding: .4rem .6rem; border-top: 1px solid var(--line); background: var(--cream, #FFF8F1); }
.om-signature-image { max-height: 70px; max-width: 260px; background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 4px; }

/* ===== Repeated sections =================================================== */
.om-rows { display: grid; gap: .75rem; }
.om-row { border: 1px solid var(--line); border-radius: 14px; padding: .9rem 1rem 1rem; background: rgba(255, 255, 255, .6); }
.om-row-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: .6rem; }
.om-row-n { width: 26px; height: 26px; border-radius: 999px; display: grid; place-items: center; background: var(--ink-900, #1F1A2E); color: #fff; font-size: .78rem; font-weight: 700; }
.om-add-row { margin-top: .75rem; }
.om-rows-table th { font-size: .75rem; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-500); }

/* ===== Wizard =============================================================== */
.om-steps { list-style: none; margin: 0; padding: 0; display: flex; gap: .4rem; flex-wrap: wrap; }
.om-steps li { display: inline-flex; align-items: center; gap: .45rem; padding: .35rem .75rem .35rem .4rem; border-radius: 999px; background: rgba(255, 255, 255, .7); border: 1px solid var(--line); color: var(--ink-500); font-size: .84rem; font-weight: 600; }
.om-steps li .n { width: 22px; height: 22px; border-radius: 999px; display: grid; place-items: center; background: var(--line); color: var(--ink-700); font-size: .75rem; }
.om-steps li.active { border-color: var(--plum-500); color: var(--plum-900); background: #fff; }
.om-steps li.active .n { background: var(--plum-900); color: #fff; }
.om-steps li.done { cursor: pointer; color: var(--ink-700); }
.om-steps li.done .n { background: var(--lime-300); color: #1F2306; }
@media (max-width: 767.98px) { .om-steps li:not(.active) .t { display: none; } }
.om-wizard-nav { display: flex; justify-content: space-between; align-items: center; gap: .75rem; }
.om-wizard-count { color: var(--ink-500); font-size: .85rem; font-weight: 600; }

/* ===== Read-only answers ==================================================== */
.om-form-view .om-section-head { margin-bottom: .75rem; }
.om-answers { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: .9rem 1.5rem; margin: 0; }
.om-answer.wide { grid-column: 1 / -1; }
.om-answers dt { font-size: .72rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--ink-500); margin-bottom: .2rem; }
.om-answers dd { margin: 0; color: var(--ink-900); font-weight: 500; word-break: break-word; }
.om-answer-text { white-space: pre-wrap; }

/* ===== Designer ============================================================ */
.om-designer { display: grid; grid-template-columns: 250px minmax(0, 1fr) 340px; gap: 1rem; align-items: start; }
.om-designer .om-palette, .om-designer .om-props { position: sticky; top: calc(var(--topbar-h, 64px) + 1rem); max-height: calc(100vh - var(--topbar-h, 64px) - 2rem); overflow: auto; }
/* The palette is Olive Data's: tiles in two columns, dragged into a section (olive-ui.css has the .fd-* rules). */
.om-palette .fd-palette { margin-bottom: 0; padding: .9rem; background: #fff; border: 1px solid var(--line); border-radius: 16px; }
.om-palette .rail-title { font-size: .95rem; font-weight: 700; margin-bottom: .25rem; }
.om-palette .fd-tile-section { border-style: dashed; }
/* Questions carry a drag handle on the left; the section header drags the section. */
.om-canvas .d-field.fd-control { padding-left: 30px; }
.om-canvas .d-field .fd-handle { top: 50%; transform: translateY(-50%); }
.om-canvas .d-section-head .fd-section-handle { position: static; width: 18px; height: 20px; margin-left: -.35rem; opacity: .55; }
.om-canvas .d-section-head:hover .fd-section-handle { opacity: 1; color: var(--plum-700); }
.om-canvas .fd-section.fd-chosen { border-color: var(--plum-500); }
.om-canvas .d-fields > .fd-tile { padding: .9rem; margin: 0; border: 2px dashed var(--plum-300); border-radius: 10px; background: var(--plum-50); color: var(--plum-900); font-weight: 700; display: flex; }
.om-canvas .d-fields > .fd-tile i { font-size: 1.1rem; }
.om-canvas .d-fields.fd-section-body:empty { min-height: 56px; }
.om-canvas .d-add-section { margin-top: .25rem; }
.om-canvas .d-move button i { font-size: 1rem; }
body.fd-preview-open .om-designer { grid-template-columns: 210px minmax(0, 1fr) 300px; }
@media (max-width: 1599.98px) { body.fd-preview-open .om-designer { grid-template-columns: 1fr; } body.fd-preview-open .om-designer .om-palette, body.fd-preview-open .om-designer .om-props { position: static; max-height: none; } }
.om-palette .grp { font-size: .7rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-500); margin: .8rem 0 .35rem; }
.om-palette .grp:first-child { margin-top: 0; }
.om-palette button { display: flex; align-items: center; gap: .5rem; width: 100%; text-align: left; border: 1px solid transparent; background: transparent; border-radius: 10px; padding: .4rem .55rem; font-weight: 600; font-size: .88rem; color: var(--ink-700); }
.om-palette button:hover { background: var(--plum-50); border-color: var(--plum-100, #E6E1F7); color: var(--plum-900); }
.om-palette button i { font-size: 1.1rem; color: var(--plum-500); }
.om-canvas .d-section { border: 1px solid var(--line); border-radius: 16px; background: #fff; margin-bottom: 1rem; }
.om-canvas .d-section.selected { border-color: var(--plum-500); box-shadow: 0 0 0 3px rgba(var(--om-secondary-rgb), .15); }
.om-canvas .d-section-head { display: flex; align-items: center; gap: .6rem; padding: .75rem 1rem; border-bottom: 1px solid var(--line); cursor: pointer; }
.om-canvas .d-section-head h6 { margin: 0; flex: 1; font-weight: 700; }
.om-canvas .d-section-head .badges { display: flex; gap: .3rem; }
.om-canvas .d-fields { padding: .6rem; min-height: 56px; display: grid; gap: .45rem; }
.om-canvas .d-field { display: flex; align-items: center; gap: .6rem; padding: .55rem .7rem; border: 1px solid var(--line); border-radius: 10px; background: var(--cream, #FFF8F1); cursor: pointer; }
.om-canvas .d-field:hover { border-color: var(--plum-300, #B7A9E0); }
.om-canvas .d-field.selected { border-color: var(--plum-500); background: var(--plum-50); }
.om-canvas .d-field .ic { width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center; background: #fff; color: var(--plum-700); flex: 0 0 auto; }
.om-canvas .d-field .lbl { flex: 1; min-width: 0; }
.om-canvas .d-field .lbl strong { display: block; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.om-canvas .d-field .lbl small { color: var(--ink-500); }
.om-canvas .d-field { flex-wrap: wrap; }
.om-canvas .d-field .tags { display: flex; gap: .25rem; flex-wrap: wrap; order: 3; width: 100%; padding-left: 40px; }
.om-canvas .d-field .tags:empty { display: none; }
.om-canvas .d-field .tag, .om-canvas .d-section .tag { font-size: .68rem; }
.om-canvas .d-empty { color: var(--ink-500); font-size: .88rem; text-align: center; padding: .9rem; border: 1px dashed var(--line-2); border-radius: 10px; }
.om-canvas .d-move { display: flex; gap: .15rem; }
.om-canvas .d-move button { border: 0; background: transparent; color: var(--ink-500); padding: .1rem .25rem; border-radius: 6px; }
.om-canvas .d-move button:hover { background: #fff; color: var(--plum-900); }
.om-props .form-label { font-size: .82rem; }
.om-props .opt-row, .om-props .rule-row { display: grid; gap: .35rem; grid-template-columns: 1fr 1fr auto; align-items: center; margin-bottom: .35rem; }
.om-props .rule-row { grid-template-columns: 1fr 110px 1fr auto; }
.om-problems { border: 1px solid var(--warn-line); background: var(--warn-bg); color: var(--warn-fg); border-radius: 12px; padding: .75rem 1rem; }
.om-problems ul { margin: .35rem 0 0; padding-left: 1.1rem; }
@media (max-width: 1399.98px) { .om-designer { grid-template-columns: 210px minmax(0, 1fr) 300px; } }
@media (max-width: 1199.98px) { .om-designer { grid-template-columns: 1fr; } .om-designer .om-palette, .om-designer .om-props { position: static; max-height: none; } }

/* ---- Member questions: the picker ------------------------------------------------------------------------------ */
.om-lookup { position: relative; }
.om-lookup-chosen { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
.om-lookup-results { position: absolute; z-index: 30; left: 0; right: 0; margin-top: .25rem; background: #fff; border: 1px solid var(--line-2, #DAD6E6);
    border-radius: var(--radius, 10px); box-shadow: 0 12px 32px rgba(31, 35, 74, .14); max-height: 280px; overflow-y: auto; padding: .25rem; }
.om-lookup-item { display: flex; flex-direction: column; align-items: flex-start; width: 100%; border: 0; background: none; text-align: left;
    padding: .45rem .65rem; border-radius: calc(var(--radius, 10px) - 4px); }
.om-lookup-item .n { font-weight: 600; color: var(--ink-900, #1F234A); }
.om-lookup-item .d { font-size: .8rem; color: var(--ink-500, #6B6F8E); }
.om-lookup-item:hover, .om-lookup-item.active { background: var(--plum-50, #F4F1FB); }
.om-lookup-message { margin-top: .35rem; min-height: 1.1em; }
.om-contents { display: contents; }
.om-contents[hidden] { display: none; }
