/* ============================================================
   Election Results Component — results.css
   A standalone, opinionated stylesheet for the front-end
   results page. Designed to look great in any Joomla template
   while inheriting the template's base font and colours.

   Load order: your template CSS → electionresults.css → results.css
   results.css adds richer visual treatment on top of the base.
   ============================================================ */

/* ── Page wrapper ─────────────────────────────────────────── */
.er-results-page {
    max-width: 860px;
    margin: 0 auto;
    padding: 0 1rem 3rem;
}

/* ── Election header card ─────────────────────────────────── */
.er-header-card {
    background: linear-gradient(135deg, var(--er-primary, #1a56db) 0%, #0e3fa0 100%);
    color: #ffffff;
    border-radius: .75rem;
    padding: 1.5rem 1.75rem;
    margin-bottom: 1.5rem;
    box-shadow: 0 4px 20px rgba(26, 86, 219, .25);
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    flex-wrap: wrap;
    gap: 1rem;
}

.er-header-card__title {
    font-size: 1.5rem;
    font-weight: 700;
    margin: 0 0 .3rem;
    color: #ffffff;
    line-height: 1.25;
}

.er-header-card__date {
    font-size: .875rem;
    opacity: .8;
    margin-bottom: .5rem;
}

.er-header-card__badges {
    display: flex;
    flex-wrap: wrap;
    gap: .4rem;
    margin-top: .4rem;
}

/* Counting badge — inside header (white on primary) */
.er-header-card .er-counting-badge {
    background: rgba(255, 255, 255, .18);
    color: #ffffff;
    border-color: rgba(255, 255, 255, .35);
}

.er-header-card .er-counting-dot {
    background: #fbbf24;
}

/* Certified badge — inside header */
.er-header-card .er-certified-badge {
    background: rgba(255, 255, 255, .18);
    color: #ffffff;
    border-color: rgba(255, 255, 255, .35);
}

/* Enter Votes button inside header */
.er-header-card .er-btn--primary {
    background: rgba(255, 255, 255, .2);
    color: #ffffff;
    border: 1.5px solid rgba(255, 255, 255, .5);
    padding: .45rem 1.1rem;
    border-radius: .4rem;
    font-size: .9rem;
    font-weight: 600;
    text-decoration: none;
    white-space: nowrap;
    transition: background .15s;
}

.er-header-card .er-btn--primary:hover {
    background: rgba(255, 255, 255, .32);
    color: #ffffff;
    text-decoration: none;
}

/* ── Stats row ────────────────────────────────────────────── */
.er-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: .75rem;
    margin-bottom: 1.4rem;
}

.er-stat-card {
    background: var(--er-surface, #f9fafb);
    border: 1px solid var(--er-border, rgba(0,0,0,.1));
    border-radius: .6rem;
    padding: .75rem 1rem;
    text-align: center;
}

.er-stat-card__value {
    font-size: 1.6rem;
    font-weight: 700;
    line-height: 1;
    color: var(--er-primary, #1a56db);
    margin-bottom: .2rem;
}

.er-stat-card__label {
    font-size: .72rem;
    text-transform: uppercase;
    letter-spacing: .06em;
    opacity: .6;
}

/* ── Legend / anchor nav ──────────────────────────────────── */
.er-legend {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: .35rem .5rem;
    background: var(--er-surface, #f9fafb);
    border: 1px solid var(--er-border, rgba(0,0,0,.1));
    border-radius: .5rem;
    padding: .6rem .9rem;
    margin-bottom: 1.4rem;
    font-size: .875rem;
}

.er-legend__label {
    font-size: .7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .07em;
    opacity: .55;
    margin-right: .25rem;
    flex-shrink: 0;
}

.er-legend__link {
    display: inline-flex;
    align-items: center;
    gap: .3rem;
    padding: .25em .8em;
    border-radius: 999px;
    border: 1.5px solid var(--er-primary, #1a56db);
    color: var(--er-primary, #1a56db) !important;
    font-weight: 600;
    font-size: .8rem;
    text-decoration: none !important;
    transition: all .14s;
    white-space: nowrap;
}

.er-legend__link:hover,
.er-legend__link:focus {
    background: var(--er-primary, #1a56db);
    color: #ffffff !important;
    text-decoration: none !important;
}

.er-legend__arrow {
    font-size: .7em;
    opacity: .7;
    transition: transform .14s;
}

.er-legend__link:hover .er-legend__arrow {
    transform: translateY(2px);
    opacity: 1;
}

/* ── Office section ───────────────────────────────────────── */
.er-office {
    background: var(--er-bg, transparent);
    border: 1px solid var(--er-border, rgba(0,0,0,.1));
    border-radius: .7rem;
    margin-bottom: 1.4rem;
    overflow: hidden;
    scroll-margin-top: 5rem;
    box-shadow: 0 2px 8px rgba(0,0,0,.04);
}

.er-office__header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: .5rem;
    padding: .85rem 1.1rem;
    background: var(--er-surface, #f9fafb);
    border-bottom: 1px solid var(--er-border, rgba(0,0,0,.1));
}

.er-office__title {
    font-size: 1rem;
    font-weight: 700;
    color: var(--er-primary, #1a56db);
    margin: 0;
}

.er-office__header-right {
    display: flex;
    align-items: center;
    gap: .6rem;
    flex-wrap: wrap;
}

.er-office__total {
    font-size: .8rem;
    opacity: .6;
}

.er-office__precinct-count {
    font-size: .75rem;
    font-weight: 600;
    padding: .2em .65em;
    border-radius: 999px;
    background: var(--er-primary, #1a56db);
    color: #ffffff;
    opacity: .85;
}

/* ── Candidate rows ───────────────────────────────────────── */
.er-candidates {
    padding: .6rem .8rem;
    display: flex;
    flex-direction: column;
    gap: .5rem;
}

.er-candidate {
    border-radius: .5rem;
    border: 1.5px solid var(--er-border, rgba(0,0,0,.1));
    overflow: hidden;
    transition: box-shadow .15s;
}

.er-candidate:hover {
    box-shadow: 0 2px 10px rgba(0,0,0,.08);
}

.er-candidate--leading {
    background: var(--er-leading-row-bg, #92400e);
    border-color: var(--er-leading-row-bg, #92400e);
}

.er-candidate--winner {
    background: var(--er-winner-row-bg, #065f46);
    border-color: var(--er-winner-row-bg, #065f46);
}

.er-candidate__summary {
    display: flex;
    align-items: center;
    gap: .85rem;
    padding: .7rem .9rem;
    flex-wrap: wrap;
}

/* Avatar */
.er-candidate__photo {
    width: 2.2rem;
    height: 2.2rem;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
    border: 2px solid rgba(0,0,0,.1);
}

.er-candidate__avatar {
    width: 2.2rem;
    height: 2.2rem;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: .9rem;
    font-weight: 700;
    color: #ffffff;
    flex-shrink: 0;
    border: 2px solid rgba(255,255,255,.25);
}

/* Name + party */
.er-candidate__identity {
    flex: 1;
    min-width: 0;
}

.er-candidate__name-row {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: .35rem;
}

.er-candidate__name {
    font-weight: 700;
    font-size: .95rem;
    color: var(--er-text, inherit);
}

.er-candidate--leading .er-candidate__name,
.er-candidate--winner  .er-candidate__name {
    color: var(--er-leading-row-text, #ffffff);
}

.er-candidate--winner .er-candidate__name {
    color: var(--er-winner-row-text, #ffffff);
}

.er-candidate__party {
    font-size: .78rem;
    opacity: .7;
    padding-left: .4rem;
    border-left: 2.5px solid currentColor;
    margin-top: .15rem;
    display: block;
}

.er-candidate--leading .er-candidate__party,
.er-candidate--winner  .er-candidate__party {
    opacity: .65;
    color: rgba(255,255,255,.85);
}

/* Badges */
.er-badge {
    display: inline-flex;
    align-items: center;
    gap: .25rem;
    padding: .2em .65em;
    border-radius: 999px;
    font-size: .72rem;
    font-weight: 700;
    white-space: nowrap;
}

.er-badge--leading {
    background: rgba(255,255,255,.2);
    color: #ffffff;
}

.er-badge--winner {
    background: rgba(255,255,255,.2);
    color: #ffffff;
}

/* Pulse dot */
.er-pulse-dot {
    display: inline-block;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #fbbf24;
    animation: er-pulse 1.3s ease-in-out infinite;
}

.er-candidate--leading .er-pulse-dot { background: rgba(255,255,255,.9); }

@keyframes er-pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50%       { opacity: .3; transform: scale(.65); }
}

/* Progress bar */
.er-candidate__results {
    flex: 2;
    min-width: 120px;
}

.er-progress-bar {
    height: .45rem;
    background: rgba(0,0,0,.08);
    border-radius: 999px;
    overflow: hidden;
    margin-bottom: .3rem;
}

.er-candidate--leading .er-progress-bar,
.er-candidate--winner  .er-progress-bar {
    background: rgba(255,255,255,.2);
}

.er-progress-bar__fill {
    height: 100%;
    border-radius: 999px;
    transition: width .4s ease;
}

.er-candidate__vote-info {
    display: flex;
    justify-content: space-between;
    font-size: .78rem;
}

.er-candidate__votes { opacity: .7; }

.er-candidate__pct {
    font-weight: 700;
    font-size: .85rem;
}

.er-candidate--leading .er-candidate__votes,
.er-candidate--leading .er-candidate__pct,
.er-candidate--winner  .er-candidate__votes,
.er-candidate--winner  .er-candidate__pct {
    color: rgba(255,255,255,.9);
}

/* ── Precinct breakdown table ─────────────────────────────── */
.er-precinct-breakdown {
    margin: 0;
    padding: .5rem .9rem .75rem;
    border-top: 1px dashed var(--er-border, rgba(0,0,0,.12));
    background: var(--er-surface, #f9fafb);
    overflow-x: auto;
}

.er-candidate--leading .er-precinct-breakdown,
.er-candidate--winner  .er-precinct-breakdown {
    background: rgba(0, 0, 0, .1);
    border-top-color: rgba(255, 255, 255, .2);
}

.er-precinct-table {
    width: 100%;
    border-collapse: collapse;
    font-size: .78rem;
    min-width: 280px;
}

.er-precinct-table__head {
    padding: .3em .7em;
    text-align: center;
    font-size: .68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .05em;
    background: var(--er-surface, #f9fafb);
    border: 1px solid var(--er-border, rgba(0,0,0,.1));
    color: var(--er-text-muted, rgba(0,0,0,.5));
    white-space: nowrap;
}

.er-precinct-table__head.er-precinct-table__total {
    background: var(--er-border, rgba(0,0,0,.1));
    color: var(--er-text, inherit);
}

.er-precinct-table__cell {
    padding: .35em .7em;
    text-align: center;
    border: 1px solid var(--er-border, rgba(0,0,0,.1));
    font-variant-numeric: tabular-nums;
    background: var(--er-bg, transparent);
}

.er-precinct-table__cell--empty {
    color: var(--er-text-muted, rgba(0,0,0,.4));
    font-style: italic;
}

.er-precinct-table__total-cell {
    font-weight: 700;
    background: var(--er-surface, #f9fafb);
    border-left: 2px solid var(--er-border, rgba(0,0,0,.15));
}

/* Precinct table on coloured rows */
.er-candidate--leading .er-precinct-table__head,
.er-candidate--leading .er-precinct-table__cell,
.er-candidate--winner  .er-precinct-table__head,
.er-candidate--winner  .er-precinct-table__cell {
    background: rgba(255,255,255,.08);
    border-color: rgba(255,255,255,.15);
    color: rgba(255,255,255,.85);
}

.er-candidate--leading .er-precinct-table__head.er-precinct-table__total,
.er-candidate--leading .er-precinct-table__total-cell,
.er-candidate--winner  .er-precinct-table__head.er-precinct-table__total,
.er-candidate--winner  .er-precinct-table__total-cell {
    background: rgba(255,255,255,.18);
    color: #ffffff;
    border-left-color: rgba(255,255,255,.3);
}

.er-candidate--leading .er-precinct-table__cell--empty,
.er-candidate--winner  .er-precinct-table__cell--empty {
    color: rgba(255,255,255,.35);
}

/* ── Recent submissions table ─────────────────────────────── */
.er-recent-submissions {
    margin-top: 1.5rem;
    border: 1px solid var(--er-border, rgba(0,0,0,.1));
    border-radius: .6rem;
    overflow: hidden;
}

.er-recent-submissions__title {
    font-size: .72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .07em;
    padding: .65rem 1rem;
    background: var(--er-surface, #f9fafb);
    border-bottom: 1px solid var(--er-border, rgba(0,0,0,.1));
    margin: 0;
    opacity: .65;
}

.er-submissions-table {
    width: 100%;
    border-collapse: collapse;
    font-size: .82rem;
}

.er-submissions-table th {
    padding: .5rem .8rem;
    text-align: left;
    font-size: .7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .05em;
    opacity: .55;
    border-bottom: 1px solid var(--er-border, rgba(0,0,0,.1));
    background: var(--er-surface, #f9fafb);
}

.er-submissions-table td {
    padding: .5rem .8rem;
    border-bottom: 1px solid var(--er-border, rgba(0,0,0,.06));
}

.er-submissions-table tr:last-child td {
    border-bottom: none;
}

.er-submissions-table tr:hover td {
    background: var(--er-surface, #f9fafb);
}

/* ── Responsive ───────────────────────────────────────────── */
@media (max-width: 640px) {
    .er-header-card {
        padding: 1.1rem 1rem;
    }
    .er-header-card__title {
        font-size: 1.2rem;
    }
    .er-stats {
        grid-template-columns: repeat(2, 1fr);
    }
    .er-candidate__summary {
        gap: .5rem;
    }
    .er-candidate__results {
        flex: 1 0 100%;
    }
}

@media (max-width: 400px) {
    .er-stats {
        grid-template-columns: 1fr;
    }
}

/* ── Dark theme override ──────────────────────────────────── */
.er-theme-dark .er-header-card {
    background: linear-gradient(135deg, #1e3a5f 0%, #0f1f33 100%);
    box-shadow: 0 4px 20px rgba(0,0,0,.4);
}

.er-theme-dark .er-office {
    background: #1f2937;
    border-color: #374151;
}

.er-theme-dark .er-office__header {
    background: #111827;
    border-color: #374151;
}

.er-theme-dark .er-candidate {
    border-color: #374151;
}

.er-theme-dark .er-progress-bar {
    background: rgba(255,255,255,.12);
}

.er-theme-dark .er-precinct-breakdown {
    background: #111827;
    border-top-color: #374151;
}

.er-theme-dark .er-precinct-table__head,
.er-theme-dark .er-precinct-table__cell {
    background: #1f2937;
    border-color: #374151;
    color: #d1d5db;
}

.er-theme-dark .er-precinct-table__head.er-precinct-table__total,
.er-theme-dark .er-precinct-table__total-cell {
    background: #374151;
    color: #f9fafb;
}

.er-theme-dark .er-stat-card {
    background: #1f2937;
    border-color: #374151;
}

.er-theme-dark .er-stat-card__value {
    color: #60a5fa;
}

.er-theme-dark .er-legend {
    background: #1f2937;
    border-color: #374151;
}
