/*
 * Election Desk — internal newsroom styling.
 *
 * No framework, no webfont. System font stack only, so nothing is fetched
 * from a third party and the Content-Security-Policy can stay strict.
 */

:root {
  --ink:            #16191d;
  --ink-soft:       #4a5058;
  --ink-faint:      #6b727b;
  --rule:           #d6dae0;
  --rule-soft:      #e7eaee;
  --page:           #f7f8fa;
  --surface:        #ffffff;

  --accent:         #1c4f8b;
  --accent-dark:    #143a67;
  --accent-wash:    #eaf1f9;

  --danger:         #a3252b;
  --danger-wash:    #fdecec;
  --success:        #1b6b45;
  --success-wash:   #e8f5ee;
  --warning:        #8a5a09;
  --warning-wash:   #fdf3e1;

  --focus:          #b8500f;

  --radius:         4px;
  --shadow:         0 1px 2px rgba(20, 25, 32, 0.07), 0 1px 6px rgba(20, 25, 32, 0.05);

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

*,
*::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.55;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.container {
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 1.5rem;
}

main.container {
  flex: 1 0 auto;
  padding-top: 2rem;
  padding-bottom: 3rem;
}

/* ---------------------------------------------------------------- Focus */

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

/* Keep a visible ring for browsers without :focus-visible. */
a:focus,
button:focus,
input:focus,
select:focus,
textarea:focus {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

a:focus:not(:focus-visible),
button:focus:not(:focus-visible),
input:focus:not(:focus-visible),
select:focus:not(:focus-visible),
textarea:focus:not(:focus-visible) {
  outline: none;
}

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  background: var(--ink);
  color: #fff;
  padding: 0.75rem 1rem;
  z-index: 100;
}

.skip-link:focus {
  left: 0;
}

.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* --------------------------------------------------------------- Typography */

h1, h2, h3 {
  line-height: 1.25;
  margin: 0 0 0.5rem;
  font-weight: 650;
  letter-spacing: -0.01em;
}

h1 { font-size: 1.75rem; }
h2 { font-size: 1.2rem; }

a {
  color: var(--accent);
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
}

a:hover {
  color: var(--accent-dark);
}

.lede {
  font-size: 1.05rem;
  color: var(--ink-soft);
  max-width: 60ch;
}

.muted {
  color: var(--ink-faint);
}

.note {
  margin-top: 2rem;
  color: var(--ink-faint);
  font-size: 0.9rem;
  max-width: 65ch;
}

.slug {
  display: block;
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--ink-faint);
  font-weight: 400;
}

/* ------------------------------------------------------------------ Header */

.site-header {
  background: var(--surface);
  border-bottom: 1px solid var(--rule);
}

.site-header__inner {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  min-height: 60px;
  flex-wrap: wrap;
}

.site-header__brand {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--ink);
  text-decoration: none;
  letter-spacing: -0.01em;
}

.site-header__mark {
  width: 10px;
  height: 20px;
  background: var(--accent);
  border-radius: 1px;
}

.site-nav ul {
  display: flex;
  gap: 1.25rem;
  list-style: none;
  margin: 0;
  padding: 0;
}

.site-nav a {
  color: var(--ink-soft);
  text-decoration: none;
  font-size: 0.94rem;
  padding: 0.35rem 0;
  border-bottom: 2px solid transparent;
}

.site-nav a:hover {
  color: var(--ink);
}

.site-nav a[aria-current="page"] {
  color: var(--ink);
  font-weight: 600;
  border-bottom-color: var(--accent);
}

.site-header__user {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-size: 0.88rem;
}

.site-header__name {
  color: var(--ink-soft);
}

.logout-form {
  margin: 0;
}

/* ------------------------------------------------------------------ Footer */

.site-footer {
  flex-shrink: 0;
  border-top: 1px solid var(--rule);
  background: var(--surface);
  padding: 1rem 0;
  font-size: 0.85rem;
  color: var(--ink-faint);
}

.site-footer p {
  margin: 0;
}

/* --------------------------------------------------------------- Page head */

.page-head {
  margin-bottom: 1.75rem;
  padding-bottom: 1rem;
  border-bottom: 2px solid var(--ink);
}

.page-head--with-action {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.page-head__meta {
  margin: 0;
  color: var(--ink-faint);
  font-size: 0.9rem;
}

.breadcrumb {
  font-size: 0.85rem;
  color: var(--ink-faint);
  margin-bottom: 0.75rem;
}

.section-heading {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--ink-faint);
  margin: 2rem 0 0.75rem;
}

.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.section-head .section-heading {
  margin-bottom: 0.75rem;
}

.section-head a {
  font-size: 0.88rem;
}

/* ------------------------------------------------------------------- Stats */

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1rem;
  max-width: 640px;
}

.stat {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 1.1rem 1.25rem;
  box-shadow: var(--shadow);
}

.stat__value {
  display: block;
  font-size: 2rem;
  font-weight: 700;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

.stat__label {
  display: block;
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--ink-faint);
  margin-top: 0.2rem;
}

/* ------------------------------------------------------------------ Tables */

.table-wrap {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  overflow-x: auto;
  box-shadow: var(--shadow);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}

caption {
  text-align: left;
}

th, td {
  text-align: left;
  padding: 0.7rem 0.9rem;
  border-bottom: 1px solid var(--rule-soft);
  vertical-align: top;
}

thead th {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-faint);
  background: #fafbfc;
  border-bottom: 1px solid var(--rule);
  white-space: nowrap;
}

tbody tr:last-child th,
tbody tr:last-child td {
  border-bottom: none;
}

tbody tr:hover {
  background: #fbfcfd;
}

tbody th[scope="row"] {
  font-weight: 600;
}

.row-actions {
  white-space: nowrap;
}

/* ------------------------------------------------------------------ Badges */

.badge {
  display: inline-block;
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.15rem 0.45rem;
  border-radius: 2px;
  vertical-align: middle;
  white-space: nowrap;
}

.badge--role   { background: var(--accent-wash); color: var(--accent-dark); }
.badge--test   { background: var(--warning-wash); color: var(--warning); }
.badge--live   { background: var(--success-wash); color: var(--success); }
.badge--public { background: var(--accent-wash); color: var(--accent-dark); }
.badge--env    { background: var(--warning-wash); color: var(--warning); }

.status {
  display: inline-block;
  font-size: 0.78rem;
  font-weight: 600;
  padding: 0.15rem 0.5rem;
  border-radius: 2px;
  border: 1px solid transparent;
  white-space: nowrap;
}

.status--draft     { background: #f0f2f5; color: var(--ink-soft); border-color: var(--rule); }
.status--setup     { background: var(--accent-wash); color: var(--accent-dark); }
.status--live      { background: var(--success-wash); color: var(--success); }
.status--closed    { background: var(--warning-wash); color: var(--warning); }
.status--certified { background: var(--success-wash); color: var(--success); }
.status--archived  { background: #f0f2f5; color: var(--ink-faint); border-color: var(--rule); }

/* ------------------------------------------------------------------ Alerts */

.alert {
  padding: 0.8rem 1rem;
  border-radius: var(--radius);
  border-left: 4px solid;
  margin-bottom: 1.25rem;
  font-size: 0.94rem;
}

.alert--error   { background: var(--danger-wash);  border-color: var(--danger);  color: #7d1c21; }
.alert--success { background: var(--success-wash); border-color: var(--success); color: #145235; }
.alert--info    { background: var(--accent-wash);  border-color: var(--accent);  color: var(--accent-dark); }

.empty {
  background: var(--surface);
  border: 1px dashed var(--rule);
  border-radius: var(--radius);
  padding: 1.5rem;
  color: var(--ink-faint);
  text-align: center;
}

/* ---------------------------------------------------------------- Activity */

.activity {
  list-style: none;
  margin: 0;
  padding: 0;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.activity li {
  display: flex;
  gap: 1rem;
  padding: 0.6rem 0.9rem;
  border-bottom: 1px solid var(--rule-soft);
  font-size: 0.88rem;
  flex-wrap: wrap;
}

.activity li:last-child {
  border-bottom: none;
}

.activity__when {
  color: var(--ink-faint);
  font-variant-numeric: tabular-nums;
  min-width: 11rem;
}

.activity__what {
  flex: 1 1 20rem;
}

.activity__who {
  color: var(--ink-faint);
}

/* ------------------------------------------------------------------- Forms */

.form {
  max-width: 46rem;
}

fieldset {
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 1.25rem 1.5rem 1.5rem;
  margin: 0 0 1.5rem;
  box-shadow: var(--shadow);
}

legend {
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--ink-faint);
  padding: 0 0.4rem;
}

.field {
  margin-bottom: 1.15rem;
}

.field:last-child {
  margin-bottom: 0;
}

.field-row {
  display: flex;
  gap: 1.25rem;
  flex-wrap: wrap;
}

.field-row .field {
  flex: 1 1 14rem;
}

label {
  display: block;
  font-weight: 600;
  font-size: 0.9rem;
  margin-bottom: 0.3rem;
}

.required {
  color: var(--danger);
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="date"],
select {
  width: 100%;
  font: inherit;
  font-size: 0.95rem;
  padding: 0.5rem 0.6rem;
  border: 1px solid #b9bfc7;
  border-radius: var(--radius);
  background: #fff;
  color: var(--ink);
}

input[size="4"] {
  width: 6rem;
}

select {
  /* Keep the native control so the keyboard behavior stays standard. */
  padding-right: 2rem;
}

input:disabled,
select:disabled {
  background: #f1f3f5;
  color: var(--ink-faint);
}

.field--invalid input,
.field--invalid select {
  border-color: var(--danger);
  background: #fffafa;
}

.field--check label {
  display: flex;
  align-items: flex-start;
  gap: 0.55rem;
  font-weight: 500;
  font-size: 0.95rem;
  cursor: pointer;
}

.field--check input[type="checkbox"] {
  width: 1.05rem;
  height: 1.05rem;
  margin-top: 0.18rem;
  flex-shrink: 0;
  accent-color: var(--accent);
}

.field__hint {
  margin: 0.3rem 0 0;
  font-size: 0.83rem;
  color: var(--ink-faint);
}

.field--check .field__hint {
  margin-left: 1.6rem;
}

.field__error {
  margin: 0.3rem 0 0;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--danger);
}

.form-actions {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  flex-wrap: wrap;
}

/* ----------------------------------------------------------------- Buttons */

.button {
  display: inline-block;
  font: inherit;
  font-size: 0.92rem;
  font-weight: 600;
  line-height: 1.2;
  padding: 0.55rem 1.1rem;
  border-radius: var(--radius);
  border: 1px solid var(--rule);
  background: var(--surface);
  color: var(--ink);
  text-decoration: none;
  cursor: pointer;
}

.button:hover {
  background: #f3f5f7;
  color: var(--ink);
}

.button--primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.button--primary:hover {
  background: var(--accent-dark);
  border-color: var(--accent-dark);
  color: #fff;
}

.button--quiet {
  background: transparent;
  border-color: transparent;
  color: var(--ink-soft);
  text-decoration: underline;
  padding-left: 0.4rem;
  padding-right: 0.4rem;
}

.button--quiet:hover {
  background: transparent;
  color: var(--ink);
}

.button--block {
  display: block;
  width: 100%;
  text-align: center;
}

.button[aria-disabled="true"],
.button:disabled {
  opacity: 0.6;
  cursor: progress;
}

/* -------------------------------------------------------------- Sign-in page */

.auth {
  display: flex;
  justify-content: center;
  padding: 3rem 0;
}

.auth__card {
  width: 100%;
  max-width: 24rem;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 2rem;
  box-shadow: var(--shadow);
}

.auth__title {
  font-size: 1.4rem;
  margin-bottom: 0.15rem;
}

.auth__subtitle {
  margin: 0 0 1.5rem;
  color: var(--ink-faint);
  font-size: 0.9rem;
}

.auth__note {
  margin: 1.25rem 0 0;
  font-size: 0.82rem;
  color: var(--ink-faint);
  text-align: center;
}

.auth .field {
  margin-bottom: 1rem;
}

/* ------------------------------------------------------------- Responsive */

@media (max-width: 720px) {
  .container {
    padding: 0 1rem;
  }

  .site-header__inner {
    padding-top: 0.75rem;
    padding-bottom: 0.75rem;
  }

  .site-header__user {
    margin-left: 0;
    width: 100%;
    order: 3;
  }

  h1 { font-size: 1.45rem; }

  .field-row {
    gap: 0;
  }

  .field-row .field {
    flex: 1 1 100%;
  }

  .activity__when {
    min-width: 100%;
  }
}

/* ------------------------------------------------------- Reduced motion */

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

/* ------------------------------------------------------------ Print */

@media print {
  .site-header,
  .site-footer,
  .form-actions,
  .skip-link {
    display: none;
  }

  body {
    background: #fff;
  }
}
