/* Bestof back office. Colors follow the apps and the watch page (iOS system colors + Bestof's
   brand red and blue). Content sits on the page, separated by space and hairlines: no cards. */
:root {
  color-scheme: light dark;
  --page: #ffffff;
  --well: #f5f5f7;
  --ink: #111113;
  --muted: #5c5c66;
  --line: rgb(17 17 19 / 0.1);
  --line-strong: rgb(17 17 19 / 0.2);
  --brand: #c42131;
  --action: #2159c7;
  --action-ink: #ffffff;
  --danger: #b3261e;
  --good: #1f7a3d;
  --focus: #2159c7;
  /* Chart series, checked for color-blind separation against each surface. */
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --grid: rgb(17 17 19 / 0.08);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --gutter: 16px;
  --radius: 8px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --page: #111113;
    --well: #1c1c1f;
    --ink: #f4f4f6;
    --muted: #a5a5b0;
    --line: rgb(255 255 255 / 0.12);
    --line-strong: rgb(255 255 255 / 0.24);
    --brand: #ff5a68;
    --action: #5b8ff5;
    --action-ink: #0b1220;
    --danger: #ff8078;
    --good: #5fd08a;
    --focus: #8db1ff;
    --series-1: #3987e5;
    --series-2: #d95926;
    --grid: rgb(255 255 255 / 0.1);
  }
}

@media (min-width: 640px) {
  :root { --gutter: 24px; }
}
@media (min-width: 1024px) {
  :root { --gutter: 32px; }
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
}
@media (min-width: 640px) {
  body { font-size: 14px; line-height: 1.55; }
}

a { color: var(--action); text-decoration: none; }
a:hover { text-decoration: underline; }
a:focus-visible, button:focus-visible, summary:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 4px; }

h1, h2 { margin: 0; font-weight: 600; text-wrap: balance; }
h1 { font-size: 1.6rem; letter-spacing: -0.015em; line-height: 1.2; }
h2 { font-size: 1.1rem; line-height: 1.3; }
p { margin: 0; text-wrap: pretty; }
.muted { color: var(--muted); }
.num { text-align: right; font-variant-numeric: tabular-nums; }

/* Header */
.top {
  display: flex;
  align-items: center;
  gap: 8px 20px;
  flex-wrap: wrap;
  padding: 12px var(--gutter);
  border-bottom: 1px solid var(--line);
}
.logo { font-size: 1.05rem; font-weight: 700; color: var(--brand); letter-spacing: -0.01em; }
.logo:hover { text-decoration: none; }
.logo span { color: var(--muted); font-weight: 500; }
.top nav { display: flex; gap: 4px; flex: 1; min-width: 0; overflow-x: auto; }
.top nav a { padding: 6px 10px; border-radius: 6px; color: var(--muted); white-space: nowrap; }
.top nav a:hover { color: var(--ink); text-decoration: none; }
.top nav a[aria-current="page"] { color: var(--ink); background: var(--well); }
.account { display: flex; align-items: center; gap: 12px; margin: 0; }
.who { display: none; }
@media (min-width: 640px) {
  .who { display: inline; }
}

/* Page */
.page { max-width: 1040px; margin: 0 auto; padding: 32px var(--gutter) 80px; display: grid; gap: 32px; }
.page > section { display: grid; gap: 16px; }
.narrow { max-width: 22rem; margin: 5vh auto 0; display: grid; gap: 16px; width: 100%; }
.narrow.wide { max-width: 34rem; margin-top: 0; margin-left: 0; }
.heading-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px 16px; flex-wrap: wrap; }
.heading-row > div { display: grid; gap: 4px; min-width: 0; }
.stack { display: grid; gap: 20px; }
.form { max-width: 36rem; }
.empty { color: var(--muted); padding: 24px 0; }

/* Buttons: two sizes, one primary a page */
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 36px;
  padding: 0 12px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  font: inherit;
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
  text-decoration: none;
}
.button:hover { text-decoration: none; }
.button.small { height: 30px; padding: 0 10px; }
.button.primary { background: var(--action); color: var(--action-ink); }
.button.primary:hover { filter: brightness(1.08); }
.button.primary.danger { background: var(--danger); color: var(--page); }
.button.secondary { background: transparent; color: var(--ink); border-color: var(--line-strong); }
.button.secondary:hover { background: var(--well); }
.button.ghost { background: transparent; color: var(--muted); }
.button.ghost:hover { color: var(--ink); background: var(--well); }
.button.ghost.danger { color: var(--danger); }
.actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.danger-zone { margin: 0; padding-top: 24px; border-top: 1px solid var(--line); }

/* Forms */
.field { display: grid; gap: 6px; }
label { font-weight: 500; }
.hint { color: var(--muted); }
input[type="text"], input[type="email"], input[type="number"], input[type="datetime-local"], select, textarea {
  width: 100%;
  min-height: 36px;
  padding: 7px 10px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--page);
  color: var(--ink);
  font: inherit;
  font-size: 16px; /* below 16px a phone zooms the page on focus */
}
@media (min-width: 640px) {
  input[type="text"], input[type="email"], input[type="number"], input[type="datetime-local"], select, textarea { font-size: 14px; }
}
textarea { resize: vertical; line-height: 1.5; }
input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 2px solid var(--focus); outline-offset: -1px; }
input[readonly] { background: var(--well); }
.check { display: flex; gap: 10px; align-items: flex-start; }
.check input { width: 18px; height: 18px; margin: 2px 0 0; accent-color: var(--action); flex-shrink: 0; }
.check label { font-weight: 400; }
.copy-row { display: flex; gap: 8px; align-items: center; }
.copy-row input { min-width: 0; }
.inline-form { display: flex; gap: 8px; align-items: center; margin: 0; }
.inline-form input { width: 7rem; min-height: 30px; padding: 4px 8px; }
/* The draft form shows the field that fits the kind of vote. */
form:has(#vote_type option[value="top_list"]:checked) .only-winner,
form:has(#vote_type option[value="winner"]:checked) .only-top-list { display: none; }

.error { color: var(--danger); }
.error-box { padding: 12px 16px; border-radius: var(--radius); background: var(--well); border-left: 3px solid var(--danger); display: grid; gap: 4px; }
.error-box ul { margin: 0; padding-left: 20px; }
.notice, .well { padding: 12px 16px; border-radius: var(--radius); background: var(--well); }

/* Badges */
.badge { display: inline-flex; align-items: center; height: 24px; padding: 0 8px; border-radius: 999px; font-size: 12px; font-weight: 500; background: var(--well); color: var(--muted); white-space: nowrap; }
.badge-open { color: var(--good); }
.badge-cancelled { color: var(--danger); }

/* Tables: on the page, rows divided by hairlines only */
.table-scroll { overflow-x: auto; margin: 0 calc(-1 * var(--gutter)); padding: 0 var(--gutter); }
table { width: 100%; border-collapse: collapse; white-space: nowrap; }
th, td { padding: 10px 16px 10px 0; text-align: left; border-bottom: 1px solid var(--line); vertical-align: top; }
th:last-child, td:last-child { padding-right: 0; }
thead th { font-weight: 500; color: var(--muted); }
tbody th { font-weight: 500; }
td.num, th.num { text-align: right; }
td.wrap { white-space: normal; min-width: 14rem; }
.matrix .ahead { font-weight: 600; }
tbody tr:last-child td, tbody tr:last-child th { border-bottom: 0; }

/* Details */
.details { margin: 0; display: grid; }
.details > div { display: grid; gap: 2px 16px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.details > div:last-child { border-bottom: 0; }
@media (min-width: 640px) {
  .details > div { grid-template-columns: 12rem 1fr; }
}
.details dt { font-weight: 500; }
.details dd { margin: 0; color: var(--muted); min-width: 0; overflow-wrap: anywhere; }
.choices, .ranking, .notes { margin: 0; padding-left: 1.4em; }
.notes { color: var(--muted); display: grid; gap: 4px; }

/* Stats: plain figures divided by hairlines */
.stats { margin: 0; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.stat { padding: 16px 16px 16px 0; min-width: 0; }
.stat:nth-child(2n) { padding: 16px 0 16px 16px; border-left: 1px solid var(--line); }
.stat:nth-child(n + 3) { border-top: 1px solid var(--line); }
@media (min-width: 800px) {
  .stats { grid-template-columns: none; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); }
  .stat, .stat:nth-child(2n), .stat:nth-child(n + 3) { padding: 16px; border-left: 1px solid var(--line); border-top: 0; }
  .stat:first-child { padding-left: 0; border-left: 0; }
  .stat:last-child { padding-right: 0; }
}
.stat dt { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat dd { margin: 2px 0 0; font-size: 1.75rem; font-weight: 600; letter-spacing: -0.02em; line-height: 1.2; font-variant-numeric: tabular-nums; }
.stat-note { color: var(--muted); font-size: 0.9em; }

/* Share */
.page > .share { display: flex; gap: 24px; align-items: flex-start; justify-content: space-between; flex-wrap: wrap; }
.share-links { display: grid; gap: 16px; flex: 1 1 20rem; min-width: 0; max-width: 36rem; }
.qr { width: 148px; height: 148px; flex-shrink: 0; border-radius: var(--radius); }

/* Results */
.winner { display: grid; gap: 8px; }
.eyebrow { color: var(--muted); font-weight: 500; }
.winner-name { font-size: 2.2rem; font-weight: 600; letter-spacing: -0.025em; line-height: 1.15; text-wrap: balance; }

/* Charts */
.chart { margin: 0; display: grid; gap: 8px; }
.chart svg { width: 100%; height: auto; display: block; overflow: visible; }
.chart .grid { stroke: var(--grid); stroke-width: 1; }
.chart .axis { fill: var(--muted); font-size: 12px; font-family: var(--font); }
.chart .line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .line-1 { stroke: var(--series-1); }
.chart .line-2 { stroke: var(--series-2); }
.chart .dot { stroke: var(--page); stroke-width: 2; }
.chart .dot-1 { fill: var(--series-1); }
.chart .dot-2 { fill: var(--series-2); }
/* On a phone the drawing is scaled to about half size: keep its text and lines readable. */
@media (max-width: 640px) {
  .chart .axis { font-size: 22px; }
  .chart .line { stroke-width: 3.5; }
}
.chart .hit { fill: transparent; }
.chart .hit:hover { fill: var(--grid); }
.legend { display: flex; flex-wrap: wrap; gap: 4px 16px; margin: 0; padding: 0; list-style: none; color: var(--muted); }
.legend li { display: inline-flex; align-items: center; gap: 6px; }
.key { width: 14px; height: 3px; border-radius: 2px; }
.key-1 { background: var(--series-1); }
.key-2 { background: var(--series-2); }
details summary { cursor: pointer; color: var(--muted); width: fit-content; }
details[open] summary { margin-bottom: 8px; }
.tip { position: fixed; z-index: 10; pointer-events: none; padding: 6px 10px; border-radius: 6px; background: var(--ink); color: var(--page); font-size: 12px; line-height: 1.4; max-width: 16rem; }
.tip[hidden] { display: none; }

/* Bar lists: name, bar, figure */
.bars { margin: 0; padding: 0; list-style: none; display: grid; gap: 10px; }
.bars li { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 16px; align-items: center; }
.bar-label { overflow-wrap: anywhere; }
.bar-value { font-variant-numeric: tabular-nums; white-space: nowrap; }
.bars meter { grid-column: 1 / -1; width: 100%; height: 10px; border: 0; background: none; }
@media (min-width: 640px) {
  .bars li { grid-template-columns: 14rem minmax(0, 1fr) 11rem; }
  .bars meter { grid-column: auto; }
}
meter.bar { appearance: none; -webkit-appearance: none; -moz-appearance: none; display: block; }
meter.bar::-webkit-meter-bar { background: var(--well); border: 0; border-radius: 0 4px 4px 0; height: 10px; }
meter.bar::-webkit-meter-optimum-value { background: var(--series-1); border-radius: 0 4px 4px 0; }
meter.bar::-moz-meter-bar { background: var(--series-1); border-radius: 0 4px 4px 0; }
meter.bar:-moz-meter-optimum { background: var(--well); border-radius: 0 4px 4px 0; }

.pager { display: flex; gap: 8px; }
