/*
 * A skoðanakönnun's chart (templates/vaa/opinionpoll/chart.html, vaa/opinionpolls.py): in an article's block and
 * on the poll's embed page (/kosningar/konnun/<pk>/embed/) alike. In the family of Graf's charts (article.scss
 * .inline-graphic), which took much from it: the outlet's accent in the square before the sans headline, a rule
 * under the head, a grey subtitle, a faint line between the options (none across their names: the owner, "textinn
 * klesstur við línuna"), the axis under them, the source under the chart; each name above its bar and the value
 * just past the bar's end, as Graf's columns on their side. The poll's own: each option's logo, the parties' colours. Colours and type from the page's tokens (each
 * outlet's, dark too); the embed page, which has none, has Heimildin's.
 */
.opinionpoll {
    --op-font: var(--st-font-sans, var(--font-ui, "sanomattextsans_web", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif));
    --op-ink: var(--st-text-color, var(--text-color, #141414));
    --op-soft: var(--st-text-color-light, #5c5c5c);
    --op-accent: var(--st-accent, #d60000);
    --op-rule: var(--st-line-color, #141414);
    --op-line: #dcdcdc;
    --op-logo: 44px;
    --op-gutter: 56px;
    /* Room past the longest bar for its value. */
    --op-room: 3.75em;
    font-family: var(--op-font);
    font-size: 1rem;
    line-height: 1.25;
    color: var(--op-ink);
    text-align: left;
}

[data-theme="dark"] .opinionpoll {
    --op-line: #3a3a3a;
}

/* The head, as Graf's: the accent's square, the sans headline; who asked and when beside it, in grey. */
.opinionpoll__head {
    margin-bottom: 1rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--op-rule);
}

.opinionpoll__title {
    margin: 0;
    font-size: 1.25em;
    font-weight: 700;
    line-height: 1.25;
}

@media (min-width: 768px) {
    .opinionpoll__title { font-size: 1.5em; }
    figure.inline-opinionpoll.position-block .opinionpoll__title { font-size: 2em; }
}

.opinionpoll__title::before {
    content: "";
    display: inline-block;
    width: .5em;
    height: .5em;
    margin-right: .25em;
    background: var(--op-accent);
}

.opinionpoll__title span {
    margin-left: .125em;
    color: var(--op-soft);
    font-size: .75em;
    font-weight: 400;
}

.opinionpoll__subtitle {
    margin-top: .5rem;
    color: var(--op-soft);
    font-size: 1rem;
    line-height: 1.4;
}

@media (min-width: 768px) {
    .opinionpoll__subtitle { font-size: 1.125em; }
}

/* The chart: the logos in a gutter at the left, a faint line between the options, the axis under them. */
.opinionpoll__graf {
    padding-left: var(--op-gutter);
    padding-right: var(--op-room);
}

.opinionpoll__options {
    position: relative;
    isolation: isolate;
    padding-top: .25rem;
}

/* The 5% a list needs for seats in Alþingi: a dashed mark by each bar, never across the names (the caption says it). */
.opinionpoll__track { position: relative; }

.opinionpoll__threshold {
    position: absolute;
    top: -4px;
    bottom: -4px;
    z-index: 1;
    width: 0;
    border-left: 1px dashed var(--op-soft);
    pointer-events: none;
}

.opinionpoll__option {
    display: flow-root;
    min-height: var(--op-logo);
    margin-bottom: .75rem;
    padding-bottom: .75rem;
    border-bottom: 1px solid var(--op-line);
}

.opinionpoll__option:last-of-type { margin-bottom: 0; }

.opinionpoll__logo {
    float: left;
    display: flex;
    align-items: center;
    justify-content: center;
    width: var(--op-logo);
    height: var(--op-logo);
    margin-left: calc(-1 * var(--op-gutter));
    border-radius: 50%;
    overflow: hidden;
    color: #fff;
    font-size: .875rem;
    font-weight: 700;
}

.opinionpoll__logo img {
    display: block;
    width: 100%;
    height: 100%;
    max-width: none;
    margin: 0;
    object-fit: cover;
    background: #fff;
}

/* As Graf's columns on their side: the name above in the grey, the bar's end rounded, its value past it in the ink. */
.opinionpoll__name {
    margin-bottom: 4px;
    overflow: hidden;
    color: var(--op-soft);
    font-size: .875rem;
    font-weight: 700;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.opinionpoll__bar {
    position: relative;
    min-width: 2px;
    height: 20px;
    border-radius: 0 4px 4px 0;
}

/* (Its place, left, set on it: the bar's end, or past the 5% mark for one that doesn't reach it.) */
.opinionpoll__value {
    position: absolute;
    top: 50%;
    margin-left: .4em;
    transform: translateY(-50%);
    color: var(--op-ink);
    font-size: .9375rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

/* The axis, under the bars, each label on its mark. */
.opinionpoll__axis {
    position: relative;
    height: 1.25rem;
    margin-top: .5rem;
    color: var(--op-soft);
    font-size: .75rem;
    font-variant-numeric: tabular-nums;
}

.opinionpoll__axis span {
    position: absolute;
    top: 0;
    transform: translateX(-50%);
    white-space: nowrap;
}

.opinionpoll__axis span:first-child { transform: none; }

/* A narrow column: every other label of a long axis left out (its line stays). */
@media (max-width: 575.98px) {
    .opinionpoll__axis span.is-minor { display: none; }
}

/* The source, as Graf's caption. */
.opinionpoll__caption {
    margin-top: 1rem;
    color: var(--op-soft);
    font-size: .9375rem;
    line-height: 1.4;
}

/* A question's answers (Já, Nei…): no logos, the bars from the left edge. */
.opinionpoll--plain { --op-gutter: 0px; }

/* In an article: the block as wide as the text (Í textabreidd) or the page's wide column (Breitt), no frame. */
figure.inline-opinionpoll > .inline-wrap {
    border: 0;
    background: none;
    padding: 0;
}
