/* ==========================================================================
   DWR Vote & Poll — Frontend Styles
   Design system-aligned: dwr-shared typography, neutral tokens, accessible focus, WCAG AA.
   ========================================================================== */

/* ---------- Design tokens ---------- */
:root {
  --dwr-font:        var(--dwr-font-prompt);

  /* Colour */
  --dwr-primary:        #4f46e5;
  --dwr-primary-hover:  #4338ca;
  --dwr-primary-light:  #eef2ff;
  --dwr-primary-ring:   rgba(79, 70, 229, 0.35);

  /* Neutrals (WCAG-safe at body text size) */
  --dwr-text:        #111827;
  --dwr-text-muted:  #6b7280;
  --dwr-text-faint:  #9ca3af;

  /* Surfaces */
  --dwr-bg:          #ffffff;
  --dwr-bg-subtle:   #f9fafb;
  --dwr-border:      #e5e7eb;
  --dwr-border-dark: #d1d5db;

  /* Semantic */
  --dwr-danger:      #dc2626;
  --dwr-success:     #16a34a;
  --dwr-info:        #2563eb;

  /* Component */
  --dwr-shadow-sm:   0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
  --dwr-shadow-md:   0 4px 12px rgba(0,0,0,.08), 0 2px 4px rgba(0,0,0,.04);
  --dwr-radius-sm:   6px;
  --dwr-radius:      10px;
  --dwr-radius-lg:   14px;
  --dwr-transition:  150ms ease;
}

/* ---------- Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration:   0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration:  0.01ms !important;
  }
}

/* ---------- Dark mode ---------- */
@media (prefers-color-scheme: dark) {
  :root {
    --dwr-bg:           #0f172a;
    --dwr-bg-subtle:    #1e293b;
    --dwr-border:       #334155;
    --dwr-border-dark:  #475569;
    --dwr-text:         #f1f5f9;
    --dwr-text-muted:   #94a3b8;
    --dwr-text-faint:   #64748b;
    --dwr-primary-light: #1e1b4b;
    --dwr-primary-ring:  rgba(99, 102, 241, 0.4);
    --dwr-shadow-sm:    0 1px 3px rgba(0,0,0,.3);
    --dwr-shadow-md:    0 4px 12px rgba(0,0,0,.4);
  }
}

/* ---------- Poll card ---------- */
.dwr-poll-card {
  font-family:  var(--dwr-font);
  background:   var(--dwr-bg);
  border:       1px solid var(--dwr-border);
  border-radius: var(--dwr-radius-lg);
  box-shadow:   var(--dwr-shadow-md);
  padding:      1.75rem;
  max-width:    520px;
  margin:       1.5rem auto;
  color:        var(--dwr-text);
}

/* ---------- Header ---------- */
.dwr-poll-header {
  margin-bottom: 1.25rem;
}

.dwr-poll-question {
  font-size:    1.125rem;
  font-weight:  700;
  line-height:  1.45;
  margin:       0;
  color:        var(--dwr-text);
  text-wrap:    balance;
}

/* ---------- Badge ---------- */
.dwr-poll-badge {
  display:        inline-flex;
  align-items:    center;
  gap:            .3rem;
  font-size:      .6875rem;
  font-weight:    600;
  text-transform: uppercase;
  letter-spacing: .07em;
  padding:        2px 8px;
  border-radius:  4px;
  margin-bottom:  .625rem;
}

.dwr-poll-badge--closed {
  background: #fee2e2;
  color:      var(--dwr-danger);
}

@media (prefers-color-scheme: dark) {
  .dwr-poll-badge--closed { background: #450a0a; color: #fca5a5; }
}

/* ---------- Options (form) ---------- */
.dwr-poll-options {
  display:        flex;
  flex-direction: column;
  gap:            .5rem;
  margin-bottom:  1.125rem;
}

.dwr-poll-option {
  display:         flex;
  align-items:     center;
  gap:             .75rem;
  padding:         .75rem 1rem;
  background:      var(--dwr-bg-subtle);
  border:          1.5px solid var(--dwr-border);
  border-radius:   var(--dwr-radius-sm);
  cursor:          pointer;
  transition:      background var(--dwr-transition),
                   border-color var(--dwr-transition),
                   box-shadow var(--dwr-transition);
  user-select:     none;
  touch-action:    manipulation;
  -webkit-tap-highlight-color: transparent;
}

.dwr-poll-option:hover {
  background:    var(--dwr-primary-light);
  border-color:  var(--dwr-primary);
}

/* Focus ring on keyboard navigation */
.dwr-poll-option:focus-within {
  outline:     2px solid var(--dwr-primary);
  outline-offset: 2px;
}

.dwr-poll-option input[type="radio"],
.dwr-poll-option input[type="checkbox"] {
  /* Keep in DOM for accessibility — visually replaced by checkmark */
  position: absolute;
  opacity:  0;
  width:    1px;
  height:   1px;
  overflow: hidden;
  clip:     rect(0 0 0 0);
  white-space: nowrap;
}

/* Custom indicator */
.dwr-option-checkmark {
  width:         18px;
  height:        18px;
  flex-shrink:   0;
  border-radius: 50%;
  border:        2px solid var(--dwr-border-dark);
  background:    var(--dwr-bg);
  transition:    border-color var(--dwr-transition),
                 background var(--dwr-transition);
  position:      relative;
}

.dwr-poll-option input[type="checkbox"] ~ .dwr-option-checkmark {
  border-radius: 4px;
}

.dwr-poll-option input:checked ~ .dwr-option-checkmark {
  background:   var(--dwr-primary);
  border-color: var(--dwr-primary);
}

.dwr-poll-option input:checked ~ .dwr-option-checkmark::after {
  content:    '';
  position:   absolute;
  top:        50%;
  left:       50%;
  transform:  translate(-50%, -56%) rotate(45deg);
  width:      4px;
  height:     8px;
  border:     2px solid #fff;
  border-top:  none;
  border-left: none;
}

.dwr-poll-option input:checked ~ .dwr-option-label {
  font-weight: 600;
  color:       var(--dwr-primary);
}

.dwr-poll-option:has(input:checked) {
  background:   var(--dwr-primary-light);
  border-color: var(--dwr-primary);
}

.dwr-option-label {
  font-size:   .9375rem;
  font-weight: 500;
  transition:  color var(--dwr-transition);
  min-width:   0;
  overflow:    hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------- Submit button ---------- */
.dwr-poll-submit {
  display:       inline-flex;
  align-items:   center;
  justify-content: center;
  gap:           .4rem;
  padding:       .625rem 1.5rem;
  background:    var(--dwr-primary);
  color:         #fff;
  border:        1.5px solid transparent;
  border-radius: var(--dwr-radius-sm);
  font-family:   var(--dwr-font);
  font-size:     .9375rem;
  font-weight:   600;
  cursor:        pointer;
  touch-action:  manipulation;
  -webkit-tap-highlight-color: transparent;
  transition:    background var(--dwr-transition),
                 box-shadow var(--dwr-transition),
                 opacity var(--dwr-transition);
}

.dwr-poll-submit:hover:not(:disabled) {
  background:  var(--dwr-primary-hover);
}

.dwr-poll-submit:focus-visible {
  outline:        2px solid var(--dwr-primary);
  outline-offset: 2px;
  box-shadow:     0 0 0 4px var(--dwr-primary-ring);
}

.dwr-poll-submit:active:not(:disabled) {
  opacity: .92;
}

.dwr-poll-submit:disabled {
  opacity: .5;
  cursor:  not-allowed;
}

/* Loading spinner (CSS, no emoji) */
.dwr-submit-spinner {
  display:         inline-block;
  width:           14px;
  height:          14px;
  border:          2px solid rgba(255,255,255,.35);
  border-top-color: #fff;
  border-radius:   50%;
  animation:       dwr-spin .6s linear infinite;
  flex-shrink:     0;
}

@keyframes dwr-spin {
  to { transform: rotate(360deg); }
}

/* ---------- Messages ---------- */
.dwr-poll-message {
  margin-top:    .875rem;
  padding:       .625rem .875rem;
  border-radius: var(--dwr-radius-sm);
  font-size:     .875rem;
  font-weight:   500;
  border-left:   3px solid transparent;
}

.dwr-poll-message[data-type="error"] {
  background:   #fee2e2;
  color:        var(--dwr-danger);
  border-color: var(--dwr-danger);
}

.dwr-poll-message[data-type="success"] {
  background:   #dcfce7;
  color:        var(--dwr-success);
  border-color: var(--dwr-success);
}

.dwr-poll-message[data-type="info"] {
  background:   #eff6ff;
  color:        var(--dwr-info);
  border-color: var(--dwr-info);
}

@media (prefers-color-scheme: dark) {
  .dwr-poll-message[data-type="error"]   { background: #450a0a; color: #fca5a5; }
  .dwr-poll-message[data-type="success"] { background: #052e16; color: #86efac; }
  .dwr-poll-message[data-type="info"]    { background: #172554; color: #93c5fd; }
}

/* ---------- Results ---------- */
.dwr-poll-results {
  animation: dwr-fade-slide .3s ease both;
}

@keyframes dwr-fade-slide {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.dwr-results-total {
  font-size:            .8125rem;
  color:                var(--dwr-text-muted);
  margin-bottom:        .875rem;
  font-weight:          500;
  font-variant-numeric: tabular-nums;
  border-bottom:        1px solid var(--dwr-border);
  padding-bottom:       .625rem;
}

.dwr-results-list {
  list-style:     none;
  margin:         0;
  padding:        0;
  display:        flex;
  flex-direction: column;
  gap:            .875rem;
}

.dwr-result-label-row {
  display:         flex;
  justify-content: space-between;
  align-items:     baseline;
  gap:             .5rem;
  margin-bottom:   .3rem;
}

.dwr-result-label {
  font-size:     .9rem;
  font-weight:   600;
  min-width:     0;
  overflow:      hidden;
  text-overflow: ellipsis;
  white-space:   nowrap;
}

.dwr-result-stat {
  font-size:            .8rem;
  color:                var(--dwr-text-muted);
  font-weight:          500;
  white-space:          nowrap;
  flex-shrink:          0;
  font-variant-numeric: tabular-nums;
}

/* Animated bar */
.dwr-result-bar-track {
  background:    var(--dwr-bg-subtle);
  border:        1px solid var(--dwr-border);
  border-radius: 4px;
  height:        8px;
  overflow:      hidden;
}

.dwr-result-bar-fill {
  height:        100%;
  background:    var(--dwr-primary);
  border-radius: 4px;
  width:         0%;
  transition:    width .9s cubic-bezier(.4, 0, .2, 1);
}

/* ---------- Status notes ---------- */
.dwr-poll-status-note {
  display:       flex;
  align-items:   center;
  gap:           .4rem;
  margin-top:    .875rem;
  padding:       .5rem .75rem;
  font-size:     .8125rem;
  font-weight:   500;
  color:         var(--dwr-text-muted);
  background:    var(--dwr-bg-subtle);
  border:        1px solid var(--dwr-border);
  border-radius: var(--dwr-radius-sm);
}

/* Inline SVG icon within status note */
.dwr-poll-status-note svg {
  width:      14px;
  height:     14px;
  flex-shrink: 0;
  stroke:     currentColor;
}

/* ---------- Error state ---------- */
.dwr-poll-error {
  font-family:  var(--dwr-font);
  color:        var(--dwr-danger);
  background:   #fee2e2;
  border:       1px solid #fecaca;
  border-left:  3px solid var(--dwr-danger);
  padding:      .75rem 1rem;
  border-radius: var(--dwr-radius-sm);
  font-size:    .875rem;
  font-weight:  500;
  max-width:    520px;
  margin:       1rem auto;
}

@media (prefers-color-scheme: dark) {
  .dwr-poll-error { background: #450a0a; border-color: #991b1b; color: #fca5a5; }
}

/* ---------- Responsive ---------- */
@media (max-width: 560px) {
  .dwr-poll-card {
    padding:       1.25rem;
    border-radius: var(--dwr-radius);
    margin:        .75rem;
    width:         auto;
    max-width:     none;
  }

  .dwr-poll-question {
    font-size: 1rem;
  }
}
