/* Polls (minibb#162): the card in a post (js/polls.js), the form that makes
   one in the editor, and the «Опросы» list (bb_polls.php).

   Built on default.css's tokens, so dark mode is the [data-theme="dark"]
   block there plus the two button colours below, the pair css/forum_stats.css
   uses. Every box sets its own font-size and line-height: the card lives
   inside .postedText (body line-height) and, in the editor, inside a
   figure.post-embed that inner_posts.css gives line-height: 0. */

.bbp, .bbp-builder, .bpl {
    --bbp-card: var(--cell-bg-1);
    --bbp-band: var(--tb-surface);
    --bbp-line: var(--border-color);
    --bbp-muted: var(--secondary-text);
    --bbp-accent: var(--link-color);
    --bbp-soft: color-mix(in srgb, var(--link-color) 11%, transparent);
    --bbp-track: color-mix(in srgb, var(--link-color) 8%, var(--cell-bg-1));
    --bbp-bar: color-mix(in srgb, var(--link-color) 22%, var(--cell-bg-1));
    --bbp-bar-mine: color-mix(in srgb, var(--link-color) 40%, var(--cell-bg-1));
    --bbp-btn-bg: #775454;
    --bbp-btn-ink: #FFFFFF;
    --bbp-danger: #b03a2e;
}
[data-theme="dark"] .bbp, [data-theme="dark"] .bbp-builder, [data-theme="dark"] .bpl {
    --bbp-btn-bg: #bb8f8f;
    --bbp-btn-ink: #1a1a1a;
    --bbp-bar: color-mix(in srgb, var(--link-color) 26%, var(--cell-bg-1));
    --bbp-bar-mine: color-mix(in srgb, var(--link-color) 48%, var(--cell-bg-1));
    --bbp-danger: #e0786c;
}

/* ---------------- the card ---------------- */

.bb-poll { display: block; margin: 10px 0; }
.bbp {
    box-sizing: border-box;
    max-width: 640px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 14px 14px 12px;
    border: 1px solid var(--bbp-line);
    border-radius: 10px;
    background: var(--bbp-band);
    color: var(--text-color);
    font-size: 14px;
    line-height: 20px;
    text-align: left;
    white-space: normal;
}
.bbp-loading, .bbp-gone { color: var(--bbp-muted); font-size: 13px; padding: 10px 14px; }
.bbp-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.bbp-head { min-width: 0; }
.bbp-q { font-size: 16px; line-height: 22px; font-weight: 700; overflow-wrap: anywhere; }
.bbp-kind { font-size: 12px; line-height: 16px; color: var(--bbp-muted); margin-top: 2px; }
.bbp-chip {
    flex-shrink: 0;
    padding: 2px 8px;
    border: 1px solid var(--bbp-line);
    border-radius: 999px;
    font-size: 12px;
    line-height: 16px;
    color: var(--bbp-muted);
    white-space: nowrap;
}

.bbp-opts { display: flex; flex-direction: column; gap: 6px; }
.bbp .bbp-opt {
    position: relative;
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    min-height: 38px;
    margin: 0;
    padding: 8px 12px;
    box-sizing: border-box;
    border: 1px solid var(--bbp-line);
    border-radius: 8px;
    background: var(--bbp-card);
    color: var(--text-color);
    font: inherit;
    font-size: 14px;
    line-height: 20px;
    text-align: left;
    cursor: pointer;
    overflow: hidden;
    transition: border-color .12s ease;
}
.bbp .bbp-opt:hover:not(:disabled) { border-color: var(--bbp-accent); }
.bbp .bbp-opt:disabled { cursor: default; opacity: 1; }
.bbp-mark {
    flex-shrink: 0;
    display: grid;
    place-items: center;
    width: 16px;
    height: 16px;
    box-sizing: border-box;
    border: 1.5px solid var(--bbp-muted);
    border-radius: 50%;
}
.bbp-multi .bbp-mark { border-radius: 4px; }
.bbp-opt[aria-checked="true"] .bbp-mark { border-color: var(--bbp-accent); background: var(--bbp-accent); }
.bbp-opt[aria-checked="true"] .bbp-mark::after {
    content: "";
    width: 8px;
    height: 4px;
    border: 2px solid var(--bbp-btn-ink);
    border-top: 0;
    border-right: 0;
    transform: translateY(-1px) rotate(-45deg);
}
.bbp-t { position: relative; flex: 1; min-width: 0; overflow-wrap: anywhere; }

/* Results: each answer is its own bar. */
.bbp-res .bbp-opt { border-color: transparent; background: var(--bbp-track); }
.bbp-fill {
    position: absolute;
    inset: 0 auto 0 0;
    background: var(--bbp-bar);
    transition: width .45s ease;
}
.bbp-mine .bbp-fill { background: var(--bbp-bar-mine); }
.bbp-mine .bbp-t { font-weight: 700; }
.bbp-tick { position: relative; color: var(--bbp-accent); font-weight: 700; }
.bbp-n { position: relative; min-width: 2em; text-align: right; color: var(--bbp-muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.bbp-pct { position: relative; min-width: 3.2em; text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; }
.bbp-who { margin: -2px 0 2px 12px; font-size: 12px; line-height: 16px; color: var(--bbp-muted); overflow-wrap: anywhere; }

.bbp-foot { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 14px; font-size: 12px; line-height: 16px; color: var(--bbp-muted); }
.bbp-sp { flex: 1; }
.bbp .bbp-link {
    margin: 0;
    padding: 0;
    border: 0;
    background: none;
    color: var(--bbp-accent);
    font: inherit;
    cursor: pointer;
}
.bbp .bbp-link:hover { text-decoration: underline; }
.bbp-guest a { color: var(--bbp-accent); }
.bbp-err { font-size: 12px; line-height: 16px; color: var(--bbp-danger); }

.bbp .bbp-btn, .bbp-builder .bbp-btn {
    margin: 0;
    padding: 7px 16px;
    border: 0;
    border-radius: 8px;
    background: var(--bbp-btn-bg);
    color: var(--bbp-btn-ink);
    font: inherit;
    font-size: 14px;
    line-height: 20px;
    font-weight: 500;
    cursor: pointer;
}
.bbp .bbp-btn:disabled, .bbp-builder .bbp-btn:disabled { opacity: .45; cursor: default; }
.bbp-builder .bbp-btn-ghost { background: transparent; color: var(--bbp-accent); border: 1px solid var(--bbp-line); }

.bbp button:focus-visible, .bbp-builder button:focus-visible, .bbp-builder input:focus-visible, .bpl button:focus-visible {
    outline: 2px solid var(--bbp-accent);
    outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
    .bbp-fill, .bbp .bbp-opt { transition: none; }
}

/* In the editor: read-only, room on the right for the figure's ×. */
.wysiwyg-editor figure.post-embed > .poll-embed { line-height: 20px; }
.bbp-ed .bbp-top { padding-right: 34px; }
.bbp .bbp-edit {
    flex-shrink: 0;
    margin: 0;
    padding: 3px 10px;
    border: 1px solid var(--bbp-line);
    border-radius: 6px;
    background: var(--bbp-card);
    color: var(--bbp-accent);
    font: inherit;
    font-size: 12px;
    line-height: 16px;
    cursor: pointer;
}
.bbp-ed .bbp-opt:disabled { cursor: default; }

/* ---------------- the builder ---------------- */

/* The editor gives up its empty writing space while the form is open
   (pollFormOpen() in simple-wysiwyg.js), so the form sits under the text. */
.wysiwyg-container.bbp-open .wysiwyg-editor { min-height: 0; padding-bottom: 4px; }
.wysiwyg-container.bbp-open .wysiwyg-editor > [data-bbp-fold] { display: none; }
.wysiwyg-container.bbp-open .wysiwyg-editor > [data-bbp-last] { margin-bottom: 0; }
.wysiwyg-container.bbp-open .bbp-builder { margin-top: 4px; }

.bbp-builder {
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin: 8px 10px;
    padding: 12px 14px;
    border: 1.5px solid var(--bbp-accent);
    border-radius: 10px;
    background: var(--bbp-card);
    color: var(--text-color);
    font-size: 14px;
    line-height: 20px;
}
.bbp-b-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 12px; }
.bbp-b-title { font-weight: 700; }
.bbp-b-note { font-size: 12px; color: var(--bbp-muted); }
.bbp-builder .bbp-in {
    width: 100%;
    min-width: 0;
    box-sizing: border-box;
    margin: 0;
    padding: 7px 10px;
    border: 1px solid var(--bbp-line);
    border-radius: 8px;
    background: var(--bg-color);
    color: var(--text-color);
    font: inherit;
    font-size: 14px;
    line-height: 20px;
}
.bbp-builder .bbp-in-q { font-weight: 700; font-size: 15px; }
.bbp-b-opts { display: flex; flex-direction: column; gap: 6px; }
.bbp-b-row { display: flex; align-items: center; gap: 8px; }
.bbp-b-row .bbp-mark { opacity: .55; }
.bbp-builder .bbp-b-x, .bbp-b-xgap { flex-shrink: 0; width: 28px; height: 28px; }
.bbp-builder .bbp-b-x {
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: 6px;
    background: transparent;
    color: var(--bbp-muted);
    font-size: 18px;
    line-height: 28px;
    cursor: pointer;
}
.bbp-builder .bbp-b-x:hover { background: var(--bbp-soft); color: var(--bbp-accent); }
.bbp-b-switch { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; cursor: pointer; user-select: none; }
.bbp-b-switch input[type="checkbox"] { width: 16px; height: 16px; margin: 0; accent-color: var(--bbp-accent); }
.bbp-b-upto { color: var(--bbp-muted); margin-left: 4px; }
.bbp-builder .bbp-in-max { width: 64px; padding: 3px 8px; }
.bbp-b-acts { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.bbp-b-hint { font-size: 12px; color: var(--bbp-muted); }

/* ---------------- «Опросы» ---------------- */

.bpl {
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    gap: 10px;
    width: 95%;
    max-width: 1000px;
    margin: 4px auto 20px;
    color: var(--text-color);
    font-size: 14px;
    line-height: 20px;
}
.bpl a { color: var(--bbp-accent); text-decoration: none; }
.bpl a:hover { text-decoration: underline; }
.bpl-hero {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 8px 16px;
    padding: 10px 14px;
    border: 1px solid var(--bbp-line);
    border-radius: 10px;
    background: var(--bbp-card);
}
.bpl-hero-id { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; min-width: 0; }
.bpl-badge {
    display: grid;
    place-items: center;
    flex-shrink: 0;
    width: 36px;
    height: 36px;
    border-radius: 9px;
    background: var(--bbp-btn-bg);
    color: var(--bbp-btn-ink);
}
.bpl .bpl-title { margin: 0; font-size: 18px; line-height: 24px; font-weight: 700; color: var(--text-color); }
.bpl-chip {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    border: 1px solid var(--bbp-line);
    border-radius: 999px;
    font-size: 12px;
    line-height: 16px;
    color: var(--bbp-muted);
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}
.bpl-chip-soft { border-color: transparent; background: var(--bbp-soft); color: var(--bbp-accent); font-weight: 500; }
.bpl-hint { font-size: 12px; line-height: 16px; color: var(--bbp-muted); }

.bpl-list {
    margin: 0;
    padding: 0;
    list-style: none;
    border: 1px solid var(--bbp-line);
    border-radius: 10px;
    background: var(--bbp-card);
}
.bpl-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 6px 16px;
    margin: 0;
    padding: 12px 16px;
    border-top: 1px solid var(--bbp-line);
}
.bpl-row:first-child { border-top: 0; }
.bpl-empty { padding: 16px; color: var(--bbp-muted); }
.bpl-main { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.bpl-line { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; min-width: 0; }
.bpl .bpl-q { color: var(--text-color); font-weight: 500; overflow-wrap: anywhere; }
.bpl a.bpl-q:hover { color: var(--bbp-accent); }
.bpl-lead { display: flex; align-items: center; gap: 8px; min-width: 0; font-size: 12px; line-height: 16px; color: var(--bbp-muted); }
.bpl-track { flex-shrink: 0; width: 90px; height: 6px; border-radius: 3px; background: var(--bbp-track); overflow: hidden; }
.bpl-track > span { display: block; height: 100%; background: var(--bbp-bar-mine); }
.bpl-lead-t { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bpl-side { display: flex; align-items: center; gap: 14px; justify-self: end; }
.bpl-voters { text-align: right; }
.bpl-voters b { display: block; font-size: 18px; line-height: 20px; font-variant-numeric: tabular-nums; }
.bpl-voters span { font-size: 12px; line-height: 14px; color: var(--bbp-muted); }
.bpl-meta { min-width: 92px; font-size: 12px; line-height: 16px; color: var(--bbp-muted); text-align: right; white-space: nowrap; }
.bpl-more { position: relative; }
.bpl .bpl-more-btn {
    width: 28px;
    height: 28px;
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: 6px;
    background: transparent;
    color: var(--bbp-muted);
    font-size: 18px;
    line-height: 28px;
    cursor: pointer;
}
.bpl .bpl-more-btn:hover { background: var(--bbp-soft); color: var(--bbp-accent); }
.bpl-menu {
    position: absolute;
    right: 0;
    top: 32px;
    z-index: 20;
    display: flex;
    flex-direction: column;
    min-width: 190px;
    padding: 4px;
    border: 1px solid var(--bbp-line);
    border-radius: 8px;
    background: var(--bbp-card);
    box-shadow: 0 6px 20px rgb(0 0 0 / .18);
}
.bpl-menu[hidden] { display: none; }
.bpl-menu button {
    margin: 0;
    padding: 6px 10px;
    border: 0;
    border-radius: 6px;
    background: transparent;
    color: var(--text-color);
    font: inherit;
    font-size: 13px;
    line-height: 18px;
    text-align: left;
    cursor: pointer;
}
.bpl-menu button:hover { background: var(--bbp-soft); }
.bpl-menu .bpl-danger { color: var(--bbp-danger); }
.bpl-pager { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; }
.bpl-page { min-width: 28px; padding: 3px 8px; border: 1px solid var(--bbp-line); border-radius: 6px; text-align: center; font-size: 13px; }
.bpl-page-on { background: var(--bbp-soft); color: var(--bbp-accent); border-color: transparent; font-weight: 600; }

@media (max-width: 600px) {
    .bpl { width: auto; margin: 4px 10px 20px; }
    .bpl-row { grid-template-columns: minmax(0, 1fr); }
    .bpl-side { justify-self: start; }
    .bpl-voters, .bpl-meta { text-align: left; }
    .bpl-voters b { display: inline; margin-right: 4px; }
    .bpl-menu { left: 0; right: auto; }
}
