/* ============================================================
   FONT IMPORTS
   ============================================================ */
@import url('https://fonts.googleapis.com/css2?family=Playfair+Display:wght@700;800;900&family=DM+Sans:ital,opsz,wght@0,9..40,300;0,9..40,400;0,9..40,500;0,9..40,600;0,9..40,700;1,9..40,400&family=DM+Mono:wght@400;500&display=swap');


/* ============================================================
   DESIGN TOKENS — LIGHT MODE (default)
   ============================================================ */
:root {
  /* Backgrounds */
  --cream:        #e4e2dd;
  --cream2:       #d8d6d1;     /* fixed: was defined twice */
  --white:        #f0eeea;

  /* Sidebar / nav */
  --navy:         #056449;
  --navy2:        #162847;
  --navy3:        #1e3560;

  /* Text */
  --text:         #0d1f3c;
  --text-2:       #2d4166;
  --text-muted:   #596070;     /* bumped slightly for WCAG contrast */
  --text-dim:     #8c9099;     /* bumped for contrast on light bg */

  /* Green palette */
  --green:        #0a7c5c;
  --green-bright: #0d9e76;
  --green-light:  #e6f7f2;
  --green-glow:   rgba(10, 124, 92, 0.15);

  /* Gold palette */
  --gold:         #c8870a;
  --gold-bright:  #e09b12;
  --gold-light:   #fef3dc;

  /* Danger */
  --red:          #c0392b;
  --red-light:    #fdecea;

  /* Borders & Shadows */
  --border:       #c0beba;
  --border2:      #ccc8c0;
  --shadow-sm:    0 2px 8px rgba(13, 31, 60, 0.07);
  --shadow:       0 4px 24px rgba(13, 31, 60, 0.12);
  --shadow-lg:    0 12px 48px rgba(13, 31, 60, 0.18);

  /* Layout */
  --sidebar-w:    264px;
  --content-max:  1280px;      /* new: prevents over-stretch on 4K */

  /* Shape */
  --radius:       8px;
  --radius-lg:    14px;
  --radius-xl:    20px;

  /* Motion */
  --transition:   0.18s ease;

  /* Typography */
  --font-display: 'Playfair Display', Georgia, serif;
  --font:         'DM Sans', system-ui, sans-serif;
  --mono:         'DM Mono', 'Courier New', monospace;

  /* Base font size — scales with root for accessibility zoom */
  font-size: 15px;
}


/* ============================================================
   DESIGN TOKENS — DARK MODE
   ============================================================ */
[data-theme="dark"] {
  --cream:        #0f1520;
  --cream2:       #161e2d;
  --white:        #1a2436;

  --navy:         #070d18;
  --navy2:        #0d1422;
  --navy3:        #111929;

  --text:         #e8edf5;
  --text-2:       #b8c4d8;
  --text-muted:   #8090b0;
  --text-dim:     #4e5e7a;

  --green:        #0d9e76;
  --green-bright: #11c490;
  --green-light:  rgba(13, 158, 118, 0.12);
  --green-glow:   rgba(13, 158, 118, 0.2);

  --gold:         #e09b12;
  --gold-bright:  #f0ad1c;
  --gold-light:   rgba(224, 155, 18, 0.12);

  --red:          #e05050;
  --red-light:    rgba(224, 80, 80, 0.12);

  --border:       #1e2d45;
  --border2:      #2a3a58;
  --shadow-sm:    0 2px 8px rgba(0, 0, 0, 0.3);
  --shadow:       0 4px 24px rgba(0, 0, 0, 0.45);
  --shadow-lg:    0 12px 48px rgba(0, 0, 0, 0.6);
}


/* ============================================================
   RESET & BASE
   ============================================================ */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  scroll-behavior: smooth;
  /* Prevent horizontal scroll globally */
  overflow-x: hidden;
  /* Allow accessibility zoom without clipping */
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font);
  background: var(--cream);
  color: var(--text);
  line-height: 1.65;
  min-height: 100vh;
  font-size: 1rem;           /* relative to :root font-size */
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  transition: background 0.25s ease, color 0.25s ease;
  overflow-x: hidden;
}

/* Inherited font for interactive elements */
button, input, select, textarea { font: inherit; }
button { cursor: pointer; border: 0; background: none; }

/* Tap targets — at least 44px on touch devices */
@media (pointer: coarse) {
  button, .nav-tab, .ep-item, .primary-btn, .ghost-btn, .danger-btn {
    min-height: 44px;
  }
}

/* Smooth focus for keyboard users, hidden for mouse */
:focus-visible {
  outline: 2px solid var(--green-bright);
  outline-offset: 2px;
}

:focus:not(:focus-visible) { outline: none; }

/* Utility */
.mono        { font-family: var(--mono); }
.hidden      { display: none !important; }
.muted       { color: var(--text-muted); }


/* ============================================================
   APP SHELL  (sidebar + main)
   ============================================================ */
.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  min-height: 100vh;
}


/* ============================================================
   SIDEBAR
   ============================================================ */
.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  overflow-x: hidden;
  background: var(--navy);
  display: flex;
  flex-direction: column;
  box-shadow: 4px 0 32px rgba(13, 31, 60, 0.25);
  transition: background 0.25s ease;
  /* Thin scrollbar inside sidebar */
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,0.12) transparent;
}

.sidebar::before {
  content: "";
  display: block;
  height: 4px;
  flex-shrink: 0;
  background: linear-gradient(
    90deg,
    var(--green-bright),
    var(--gold-bright),
    var(--green-bright)
  );
}

/* ── Brand ── */
.brand {
  display: flex;
  align-items: center;
  gap: 0.875rem;
  padding: 1.25rem 1.25rem 1.125rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  flex-shrink: 0;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--green-bright) 0%, #065c43 100%);
  color: #fff;
  flex-shrink: 0;
  box-shadow: 0 4px 16px rgba(10, 124, 92, 0.4);
}

.brand strong {
  display: block;
  font-size: 0.9375rem;
  font-weight: 700;
  color: #fff;
  letter-spacing: 0.01em;
  font-family: var(--font-display);
  line-height: 1.2;
}

.brand small {
  display: block;
  color: rgba(255, 255, 255, 0.4);
  font-size: 0.625rem;
  margin-top: 0.125rem;
  font-family: var(--mono);
  letter-spacing: 0.06em;
}

/* ── Nav tabs ── */
.nav-tabs {
  display: flex;
  flex-direction: column;
  padding: 1rem 0.75rem;
  flex: 1;
  gap: 0.1875rem;
}

.nav-tab {
  width: 100%;
  border-radius: var(--radius);
  padding: 0.6875rem 0.875rem;
  color: rgba(219, 211, 211, 0.83);
  background: transparent;
  text-align: left;
  font-size: 0.8125rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 0.6875rem;
  transition: background var(--transition), color var(--transition);
  position: relative;
  letter-spacing: 0.01em;
  font-family: var(--font);
}

.tab-icon {
  font-size: 0.9375rem;
  width: 1.25rem;
  text-align: center;
  flex-shrink: 0;
}

.nav-tab:hover {
  background: rgba(255, 255, 255, 0.07);
  color: rgba(255, 255, 255, 0.85);
}

.nav-tab.active {
  background: rgba(10, 124, 92, 0.2);
  color: #fff;
  font-weight: 700;
}

.nav-tab.active::before {
  content: "";
  position: absolute;
  left: 0;
  top: 8px;
  bottom: 8px;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: var(--green-bright);
  box-shadow: 0 0 10px rgba(13, 158, 118, 0.6);
}

/* ── Theme toggle ── */
.theme-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.8125rem 1.25rem;
  border-top: 1px solid rgba(255, 255, 255, 0.07);
  flex-shrink: 0;
}

.theme-row span {
  font-size: 0.625rem;
  font-family: var(--mono);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.3);
  display: flex;
  align-items: center;
  gap: 0.375rem;
}

.theme-switch {
  position: relative;
  width: 44px;
  height: 24px;
  flex-shrink: 0;
}

.theme-switch input {
  opacity: 0;
  width: 0;
  height: 0;
  position: absolute;
}

.theme-track {
  position: absolute;
  inset: 0;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.15);
  cursor: pointer;
  transition: background 0.25s ease, border-color 0.25s ease;
}

.theme-track::after {
  content: "";
  position: absolute;
  left: 3px;
  top: 3px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.75);
  transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.theme-switch input:checked + .theme-track {
  background: rgba(13, 158, 118, 0.35);
  border-color: var(--green-bright);
}

.theme-switch input:checked + .theme-track::after {
  transform: translateX(20px);
  background: var(--green-bright);
}

/* ── Sidebar footer ── */
.sidebar-footer {
  padding: 1rem 1.25rem;
  font-size: 0.625rem;
  color: rgba(255, 255, 255, 0.2);
  border-top: 1px solid rgba(255, 255, 255, 0.07);
  letter-spacing: 0.08em;
  font-family: var(--mono);
  flex-shrink: 0;
}


/* ============================================================
   CONTENT AREA
   ============================================================ */
.content {
  padding: 2rem 2.25rem;
  min-width: 0;
  background: var(--cream);
  transition: background 0.25s ease;
  /* Removed the broken height: 200vh */
}

/* Cap width on very large screens */
.content > * {
  max-width: var(--content-max);
}


/* ============================================================
   PANELS
   ============================================================ */
.panel { display: none; }
.panel.active { display: grid; gap: 1.5rem; }


/* ============================================================
   PAGE HEADER
   ============================================================ */
.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  padding-bottom: 1.5rem;
  border-bottom: 2px solid var(--border);
  position: relative;
}

.page-head::after {
  content: "";
  position: absolute;
  bottom: -2px;
  left: 0;
  width: 60px;
  height: 2px;
  background: var(--green);
}

.page-head h1 {
  font-family: var(--font-display);
  font-size: clamp(1.375rem, 3vw, 2.125rem);
  font-weight: 800;
  color: var(--navy);
  letter-spacing: -0.03em;
  line-height: 1.2;
  margin-top: 4px;
}

[data-theme="dark"] .page-head h1,
[data-theme="dark"] h2,
[data-theme="dark"] h3 {
  color: var(--text);
}

.eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  margin: 0 0 0.375rem;
  color: var(--green);
  font-weight: 700;
  text-transform: uppercase;
  font-size: 0.625rem;
  letter-spacing: 0.14em;
  font-family: var(--mono);
}

.eyebrow::before {
  content: "";
  display: inline-block;
  width: 16px;
  height: 2px;
  background: var(--green);
  border-radius: 2px;
}

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

/* Layout helpers */
.vstack        { display: flex; flex-direction: column; }
.hstack        { display: flex; align-items: center; flex-wrap: wrap; }
.gap-8         { gap: 0.5rem; }
.gap-16        { gap: 1rem; }
.admin-section { display: grid; gap: 1rem; }

/* Two-column editor grid */
.editor-grid {
  display: grid;
  grid-template-columns: minmax(0, 0.85fr) minmax(0, 1.15fr);
  gap: 1.125rem;
  align-items: start;
}


/* ============================================================
   SURFACE (card wrapper)
   ============================================================ */
.surface {
  background: var(--white);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  box-shadow: var(--shadow-sm);
  position: relative;
  transition: background 0.25s ease, border-color 0.25s ease;
}

.surface.narrow { max-width: 30rem; }

/* Headings inside surfaces */
h2 {
  font-family: var(--font-display);
  font-size: 1.125rem;
  font-weight: 700;
  color: var(--navy);
  letter-spacing: -0.015em;
  margin-bottom: 1rem;
}

h3 {
  font-size: 0.8125rem;
  font-weight: 700;
  color: var(--navy);
  margin-bottom: 0.625rem;
}


/* ============================================================
   FORMS
   ============================================================ */
label {
  display: grid;
  gap: 0.375rem;
  margin-bottom: 1rem;
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.6875rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

input[type="text"],
input[type="password"],
input[type="email"],
input[type="number"],
input[type="file"],
select,
textarea {
  width: 100%;
  min-height: 2.75rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 0.625rem 0.875rem;
  color: var(--text);
  background: var(--cream);
  font-size: 0.9375rem;
  font-weight: 500;
  transition: border-color var(--transition), box-shadow var(--transition),
              background 0.25s ease, color 0.25s ease;
  font-family: var(--font);
  /* Prevent zoom on iOS when font-size < 16px */
  font-size: max(1rem, 16px);
}

input::placeholder,
textarea::placeholder { color: var(--text-dim); }

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--green);
  background: var(--white);
  box-shadow: 0 0 0 3px var(--green-glow);
}

/* Custom select arrow */
select {
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%236b7a99' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.875rem center;
  background-color: var(--cream);
  padding-right: 2.25rem;
  cursor: pointer;
}

select option { background: var(--white); color: var(--text); }

/* Toggle / checkbox row */
.toggle-row {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  text-transform: none;
  letter-spacing: 0;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 1rem;
  cursor: pointer;
}

.toggle-row input[type="checkbox"] {
  width: 18px;
  min-height: 18px;
  accent-color: var(--green);
  cursor: pointer;
  flex-shrink: 0;
}


/* ============================================================
   BUTTONS
   ============================================================ */
.primary-btn,
.ghost-btn,
.danger-btn {
  min-height: 2.5rem;
  border-radius: var(--radius);
  border: 1.5px solid transparent;
  padding: 0.5625rem 1.25rem;
  font-weight: 700;
  font-size: 0.8125rem;
  transition: background var(--transition), border-color var(--transition),
              box-shadow var(--transition), transform var(--transition);
  letter-spacing: 0.02em;
  font-family: var(--font);
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.375rem;
  /* Prevent text from being super tiny on mobile */
  font-size: clamp(0.75rem, 2vw, 0.8125rem);
}

.primary-btn {
  background: var(--green);
  color: #fff;
  border-color: var(--green);
  box-shadow: 0 2px 12px rgba(10, 124, 92, 0.3);
}

.primary-btn:hover {
  background: var(--green-bright);
  border-color: var(--green-bright);
  box-shadow: 0 4px 20px rgba(10, 124, 92, 0.4);
  transform: translateY(-1px);
}

.primary-btn:active { transform: translateY(0); }

.ghost-btn {
  background: var(--white);
  border-color: var(--border2);
  color: var(--text-2);
}

.ghost-btn:hover {
  background: var(--cream2);
  border-color: var(--navy3);
  color: var(--navy);
}

.danger-btn {
  background: var(--red-light);
  color: var(--red);
  border-color: rgba(192, 57, 43, 0.2);
}

.danger-btn:hover {
  background: #f9d5d2;
  border-color: rgba(192, 57, 43, 0.4);
}

.full-btn { width: 100%; }


/* ============================================================
   PILLS / BADGES
   ============================================================ */
.pill {
  display: inline-flex;
  align-items: center;
  min-height: 1.5rem;
  border-radius: 999px;
  background: var(--cream2);
  color: var(--text-muted);
  border: 1px solid var(--border);
  padding: 0.1875rem 0.75rem;
  font-size: 0.6875rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  font-family: var(--mono);
}

.accent-pill {
  background: var(--green-light);
  border-color: rgba(10, 124, 92, 0.2);
  color: var(--green);
  font-size: 0.875rem;
  letter-spacing: 0.25em;
}

.live-badge {
  font-size: 0.6875rem;
  font-weight: 700;
  color: var(--text-muted);
  transition: all 0.3s ease;
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

.live-badge.active {
  color: var(--green);
  background: var(--green-light);
  border-color: rgba(10, 124, 92, 0.2);
  box-shadow: 0 0 0 3px var(--green-glow);
}


/* ============================================================
   STATUS DOTS
   ============================================================ */
.status-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
  background: var(--text-dim);
}

.status-dot.live {
  background: var(--green);
  box-shadow: 0 0 0 3px var(--green-glow);
  animation: pulse 2s infinite;
}

.status-dot.closed { background: var(--red); }
.status-dot.draft  { background: var(--text-dim); }
.status-dot.result { background: var(--gold); }

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 3px rgba(10, 124, 92, 0.15); }
  50%       { box-shadow: 0 0 0 6px rgba(10, 124, 92, 0.05); }
}


/* ============================================================
   STAT GRID
   ============================================================ */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.75rem;
}

.stat-grid div {
  min-height: 5.5rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 0.875rem 1rem;
  background: var(--cream);
  position: relative;
  overflow: hidden;
  transition: border-color var(--transition), box-shadow var(--transition),
              background 0.25s ease;
}

.stat-grid div:hover {
  border-color: var(--green);
  box-shadow: 0 4px 16px var(--green-glow);
}

.stat-grid div::after {
  content: "";
  position: absolute;
  bottom: 0; left: 0; right: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--green), transparent);
}

.stat-grid span {
  display: block;
  font-family: var(--font-display);
  font-size: clamp(1.375rem, 3vw, 1.75rem);
  font-weight: 800;
  color: var(--navy);
  line-height: 1.1;
}

[data-theme="dark"] .stat-grid span { color: var(--text); }

.stat-grid small {
  color: var(--text-muted);
  font-size: 0.6875rem;
  font-weight: 600;
  font-family: var(--mono);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}


/* ============================================================
   LOGIN CARD
   ============================================================ */
.login-card {
  background: linear-gradient(145deg, var(--white) 0%, var(--cream2) 100%);
  border: 1.5px solid var(--border);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.login-card::after {
  content: "";
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 4px;
  background: linear-gradient(90deg, var(--green), var(--gold-bright));
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}

.login-icon {
  font-size: 2rem;
  margin-bottom: 0.875rem;
  display: block;
}


/* ============================================================
   ELECTION LIST
   ============================================================ */
.election-list { display: grid; gap: 0.625rem; }

.election-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.875rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1rem 1.25rem;
  background: var(--white);
  transition: border-color var(--transition), box-shadow var(--transition),
              transform var(--transition);
  box-shadow: var(--shadow-sm);
  flex-wrap: wrap;
}

.election-item:hover {
  border-color: var(--green);
  box-shadow: 0 4px 20px var(--green-glow);
  transform: translateY(-1px);
}

.election-item .e-info { flex: 1; min-width: 0; }

.election-item .e-info h3 {
  margin: 0 0 0.3125rem;
  font-size: 0.9375rem;
  font-weight: 700;
  color: var(--navy);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

[data-theme="dark"] .election-item .e-info h3 { color: var(--text); }

.election-item .e-info p {
  color: var(--text-muted);
  font-size: 0.75rem;
  font-family: var(--mono);
}


/* ============================================================
   ELECTION PICKER
   ============================================================ */
.election-picker { display: grid; gap: 0.625rem; }

.ep-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.875rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1rem 1.25rem;
  background: var(--white);
  cursor: pointer;
  transition: border-color var(--transition), background var(--transition),
              box-shadow var(--transition), transform var(--transition);
  box-shadow: var(--shadow-sm);
}

.ep-item:hover {
  border-color: var(--green);
  background: var(--green-light);
  box-shadow: 0 4px 20px var(--green-glow);
  transform: translateY(-1px);
}

.ep-item .ep-info { flex: 1; min-width: 0; }
.ep-item h3 { margin: 0 0 0.25rem; font-size: 0.875rem; font-weight: 700; color: var(--navy); }
[data-theme="dark"] .ep-item h3 { color: var(--text); }
.ep-item p  { color: var(--text-muted); font-size: 0.75rem; font-family: var(--mono); }

.ep-arrow {
  color: var(--green);
  font-size: 1.25rem;
  font-weight: 900;
  flex-shrink: 0;
  transition: transform var(--transition);
}

.ep-item:hover .ep-arrow { transform: translateX(4px); }


/* ============================================================
   VOTER ACCESS FORM
   ============================================================ */
.code-header {
  display: flex;
  align-items: center;
  gap: 0.875rem;
  margin-bottom: 1.375rem;
  padding-bottom: 1.125rem;
  border-bottom: 1.5px solid var(--border);
}

.code-icon { font-size: 1.625rem; flex-shrink: 0; }
.code-header h2 { margin: 0; font-size: 1.0625rem; }

/* Mono-style code input */
.code-input {
  font-family: var(--mono) !important;
  font-size: 1.625rem !important;
  letter-spacing: 0.35em;
  text-align: center;
  font-weight: 600;
  background: var(--navy) !important;
  color: #fff !important;
  border-color: var(--navy) !important;
}

.code-input::placeholder { color: rgba(255, 255, 255, 0.25) !important; }

.code-input:focus {
  box-shadow: 0 0 0 3px rgba(13, 31, 60, 0.15) !important;
  border-color: var(--navy2) !important;
}


/* ============================================================
   IMAGE PREVIEW
   ============================================================ */
.image-preview {
  display: grid;
  place-items: center;
  width: 160px;
  min-height: 220px;
  max-width: 100%;
  border: 2px dashed var(--border2);
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: var(--cream2);
  color: var(--text-dim);
  margin-bottom: 1rem;
  font-size: 0.75rem;
  text-align: center;
  transition: border-color var(--transition), background 0.25s ease;
}

.image-preview img {
  width: 100%;
  height: 100%;
  max-height: 220px;
  object-fit: cover;
  display: block;
}

.image-preview:not(.empty) {
  border-style: solid;
  border-color: var(--green);
}

#voterImagePreview {
  width: 200px;
  min-height: 160px;
  max-width: 100%;
  margin-bottom: 0;
}

#voterImagePreview img { height: 160px; max-height: none; }


/* ============================================================
   SCROLLABLE LISTS
   ============================================================ */
.list, .audit-list { display: grid; gap: 0.5rem; }

#candidateList,
#voteAudit {
  max-height: 24rem;
  overflow-y: auto;
  padding-right: 0.25rem;
  scrollbar-gutter: stable;
}

#voteCandidateList {
  max-height: 32.5rem;
  overflow-y: auto;
  padding-right: 0.25rem;
  scrollbar-gutter: stable;
}

/* Thin scrollbars */
#candidateList::-webkit-scrollbar,
#voteAudit::-webkit-scrollbar,
#voteCandidateList::-webkit-scrollbar { width: 5px; }

#candidateList::-webkit-scrollbar-thumb,
#voteAudit::-webkit-scrollbar-thumb,
#voteCandidateList::-webkit-scrollbar-thumb {
  background: var(--border2);
  border-radius: 999px;
}


/* ============================================================
   ITEM CARDS
   ============================================================ */
.item, .audit-item {
  display: grid;
  gap: 0.625rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem 0.875rem;
  background: var(--cream);
  transition: border-color var(--transition), background var(--transition),
              box-shadow var(--transition);
}

.item:hover {
  border-color: var(--border2);
  background: var(--white);
  box-shadow: var(--shadow-sm);
}

.item {
  grid-template-columns: 52px 1fr auto;
  align-items: center;
}

/* Avatar */
.avatar {
  width: 52px;
  height: 52px;
  border-radius: var(--radius);
  object-fit: cover;
  background: var(--cream2);
  border: 1.5px solid var(--border);
  flex-shrink: 0;
  display: block;
}

.item h3 { margin: 0; font-size: 0.8125rem; font-weight: 700; color: var(--navy); }
[data-theme="dark"] .item h3 { color: var(--text); }
.item p  { margin: 2px 0 0; color: var(--text-muted); font-size: 0.75rem; }

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.375rem;
  justify-content: flex-end;
}

/* Audit item */
.audit-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.875rem;
  flex-wrap: wrap;
}

.audit-item h3 { margin: 0; font-size: 0.8125rem; font-weight: 700; color: var(--navy); }
[data-theme="dark"] .audit-item h3 { color: var(--text); }
.audit-item p  { margin: 2px 0 0; color: var(--text-muted); font-size: 0.75rem; }


/* ============================================================
   CAMERA / CAPTURE
   ============================================================ */
.capture-grid {
  display: grid;
  grid-template-columns: 1fr 120px 120px;
  gap: 0.625rem;
  align-items: center;
}

.camera {
  width: 100%;
  min-height: 160px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--navy);
  object-fit: cover;
  display: block;
}


/* ============================================================
   CANDIDATE VOTE CARDS
   ============================================================ */
.candidate-grid {
  display: grid;
  /* At least 2 columns, never narrower than 160px */
  grid-template-columns: repeat(auto-fill, minmax(clamp(140px, 22%, 200px), 1fr));
  gap: 0.875rem;
}

.candidate-card {
  min-height: 16rem;
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
  border: 2px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 0.875rem;
  background: var(--white);
  transition: border-color var(--transition), box-shadow var(--transition),
              transform var(--transition);
  box-shadow: var(--shadow-sm);
}

.candidate-card:hover {
  border-color: var(--green);
  box-shadow: 0 8px 28px var(--green-glow);
  transform: none;
}

.candidate-card img {
  width: 110px;
  height: 140px;
  flex-shrink: 0;
  border-radius: var(--radius);
  object-fit: contain;
  object-position: center;
  background: var(--cream2);
  border: 1.5px solid var(--border);
  display: block;
}

.candidate-card h3 { margin: 0; font-size: 0.875rem; font-weight: 700; color: var(--navy); }
[data-theme="dark"] .candidate-card h3 { color: var(--text); }
.candidate-card p  { margin: 0; color: var(--text-muted); font-size: 0.75rem; }
.candidate-card .primary-btn { margin-top: auto; }


/* ============================================================
   RESULTS
   ============================================================ */
.result-list { display: grid; gap: 0.625rem; }

.result-item {
  display: grid;
  grid-template-columns: 54px minmax(120px, 1fr) minmax(100px, 2fr) 56px;
  align-items: center;
  gap: 0.875rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 0.875rem 1.125rem;
  background: var(--white);
  transition: border-color var(--transition), box-shadow var(--transition);
  box-shadow: var(--shadow-sm);
}

.result-item:hover {
  border-color: var(--border2);
  box-shadow: var(--shadow);
}

.result-item h3 { margin: 0; font-size: 0.875rem; font-weight: 700; color: var(--navy); }
[data-theme="dark"] .result-item h3 { color: var(--text); }
.result-item p  { margin: 0; color: var(--text-muted); font-size: 0.75rem; }

.result-item strong {
  font-family: var(--font-display);
  font-size: 1.25rem;
  color: var(--navy);
}

[data-theme="dark"] .result-item strong { color: var(--text); }

/* Progress bar */
.bar {
  height: 10px;
  border-radius: 999px;
  background: var(--cream2);
  overflow: hidden;
  border: 1px solid var(--border);
}

.bar span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--green), var(--green-bright));
  box-shadow: 0 0 8px var(--green-glow);
  transition: width 0.7s cubic-bezier(0.4, 0, 0.2, 1);
  min-width: 0;
}


/* ============================================================
   WINNER BANNER
   ============================================================ */
.winner-banner {
  border-radius: var(--radius-xl);
  background: linear-gradient(135deg, var(--gold-light) 100%, #ece1cd 100%);
  border: 2px solid rgba(224, 156, 37, 0.849);
  padding: 1.25rem 1.5rem;
  font-size: 1rem;
  font-weight: 700;
  color: var(--gold);
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1.125rem;
  box-shadow: 0 4px 24px rgba(247, 158, 4, 0.911);
  font-family: var(--font-display);
  flex-wrap: wrap;
}


/* ============================================================
   TOAST NOTIFICATION
   ============================================================ */
.toast {
  position: fixed;
  right: 1.5rem;
  bottom: 1.5rem;
  max-width: min(23.75rem, calc(100vw - 3rem));
  border-radius: var(--radius-lg);
  background: var(--navy);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.1);
  padding: 0.875rem 1.125rem;
  font-size: 0.8125rem;
  font-weight: 600;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  transform: translateY(0.75rem) scale(0.97);
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 9999;
  font-family: var(--font);
}

.toast.show { opacity: 1; transform: translateY(0) scale(1); }


/* ============================================================
   EMPTY STATE
   ============================================================ */
.empty-state {
  border: 2px dashed var(--border);
  border-radius: var(--radius-lg);
  padding: 1.75rem 1.25rem;
  color: var(--text-dim);
  text-align: center;
  font-size: 0.8125rem;
  background: var(--cream);
}


/* ============================================================
   GLOBAL SCROLLBAR
   ============================================================ */
::-webkit-scrollbar          { width: 5px; height: 5px; }
::-webkit-scrollbar-track    { background: var(--cream); }
::-webkit-scrollbar-thumb    { background: var(--border2); border-radius: 999px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-dim); }


/* ============================================================
   RESPONSIVE — TABLET & MOBILE  (≤ 900px)
   The sidebar becomes a COMPACT TOP NAVBAR — not a big green block.
   Layout: [logo + brand] on left | [nav tabs] in center | [theme] on right
   ============================================================ */
@media (max-width: 900px) {

  /* ── Switch to single-column layout ── */
  .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
  }

  /* ── Sidebar becomes a slim top bar ── */
  .sidebar {
    position: fixed;           /* always fixed at top */
    left: 0;
    right: 0;
    top: 0;
    height: 56px;             /* fixed height for top bar */
    overflow: visible;         /* MUST be visible so absolute child (.theme-row) isn't clipped */
    overflow-x: visible;
    overflow-y: visible;
    z-index: 1000;
    box-shadow: 0 2px 16px rgba(0, 0, 0, 0.25);

    /* Horizontal flex layout */
    flex-direction: row;
    align-items: center;
    flex-wrap: nowrap;
    padding: 0 0.75rem 0 0.75rem;
    padding-right: 130px;      /* leave room for theme toggle */
    gap: 0;
    min-width: 0;
    width: 100%;
  }

  /* Hide the top accent stripe — not needed in row mode */
  .sidebar::before { display: none; }

  /* ── Brand: compact, left-aligned ── */
  .brand {
    padding: 0.5rem 0.5rem 0.5rem 0;
    border-bottom: none;
    border-right: 1px solid rgba(255, 255, 255, 0.1);
    margin-right: 0.5rem;
    flex-shrink: 0;
    gap: 0.5rem;
  }

  .brand-mark {
    width: 34px;
    height: 34px;
    border-radius: 8px;
  }

  .brand strong { font-size: 0.8125rem; }
  .brand small  { display: none; }    /* hide subtitle — saves space */

  /* ── Nav tabs: horizontal, centred, flex row ── */
  .nav-tabs {
    flex-direction: row;
    flex-wrap: nowrap;
    padding: 0;
    gap: 2px;
    flex: 1;
    justify-content: flex-start;
    align-items: center;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    /* leave extra space on right for fixed theme toggle */
    padding-right: 140px;
    margin-right: 0;
    min-width: 0;
    width: 100%;
  }

  .nav-tabs::-webkit-scrollbar { display: none; }

  .nav-tab {
    width: auto;
    flex: 0 1 auto;
    font-size: 0.75rem;
    padding: 0.5rem 0.875rem;
    min-height: 40px;
    min-width: 48px;
    justify-content: center;
    border-radius: var(--radius);
    white-space: nowrap;
  }

  /* Active indicator: bottom border instead of left bar */
  .nav-tab.active::before {
    display: block;
    left: 8px;
    right: 8px;
    top: auto;
    bottom: 0;
    width: auto;
    height: 2px;
    border-radius: 2px 2px 0 0;
  }

  /* ── Theme toggle: anchored inside top navbar, right side ── */
  .theme-row {
    position: absolute;
    top: 0;
    right: 0;
    left: auto;
    bottom: auto;
    z-index: 101;
    height: 56px;              /* matches navbar height */
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 10px;
    background: var(--navy);
    border-left: 1px solid rgba(255,255,255,0.12);
    gap: 6px;
    min-width: 80px;
    width: auto;
    /* no bottom pill styling */
    border-radius: 0;
    box-shadow: none;
  }

  /* Show emoji label */
  .theme-row span {
    display: flex;
    align-items: center;
    gap: 4px;
    color: rgba(255,255,255,0.7);
    font-size: 10px;
    font-family: var(--mono);
    letter-spacing: 0.06em;
    text-transform: uppercase;
    white-space: nowrap;
  }

  .theme-switch {
    width: 38px;
    height: 20px;
    flex-shrink: 0;
  }

  .theme-track {
    background: rgba(255,255,255,0.15);
    border: 1.2px solid rgba(255,255,255,0.45);
  }

  .theme-track::after {
    background: #ffffff;
    width: 14px;
    height: 14px;
    top: 3px;
    left: 3px;
  }

  .theme-switch input:checked + .theme-track {
    background: rgba(13,158,118,0.55);
    border-color: var(--green-bright);
  }

  .theme-switch input:checked + .theme-track::after {
    background: var(--green-bright);
    transform: translateX(20px);
  }

  /* ── Hide sidebar footer ── */
  .sidebar-footer { display: none; }

  /* ── Content area ── */
  .content { padding: 1.25rem 1rem 1rem; margin-top: 56px; }

  /* ── Two-column layouts collapse to single ── */
  .editor-grid  { grid-template-columns: 1fr; }
.capture-grid {
  grid-template-columns: 1fr 100px 100px;
  gap: 0.5rem;
}
  /* ── Result items reflow ── */
  .result-item {
    grid-template-columns: 48px 1fr;
    grid-template-rows: auto auto;
  }

  .result-item .bar,
  .result-item strong { grid-column: 2; }

  /* ── Page & section heads stack ── */
  .page-head,
  .section-head {
    flex-direction: column;
    align-items: stretch;
  }

  /* ── Item action buttons span full row ── */
  .item { grid-template-columns: 48px 1fr; }

  .actions {
    grid-column: 1 / -1;
    justify-content: flex-start;
  }
}


/* ============================================================
   RESPONSIVE — MOBILE  (≤ 600px)
   ============================================================ */
@media (max-width: 600px) {

  .stat-grid { grid-template-columns: 1fr 1fr; }

  .page-head h1 { font-size: 1.25rem; }

  /* Even slimmer nav tabs on phones */
  .nav-tab {
    font-size: 0.6875rem;
    padding: 0.4375rem 0.625rem;
  }

  /* Icon-only nav: shrink text to 0, keep icons readable */
  .tab-icon { display: block !important; font-size: 1.125rem; }
  .nav-tab  { font-size: 0; gap: 0; padding: 0.4375rem 0.75rem; }
  .nav-tab .tab-icon { font-size: 1.125rem; }

  /* Smaller surfaces */
  .surface { padding: 0.875rem; }

  .sidebar { padding-right: 100px; }
  .nav-tabs { padding-right: 110px; }
  .nav-tab { min-width: 42px; }
  .theme-row {
    padding: 0 6px;
    min-width: 72px;
  }
  .theme-row > span {
    display: none;
  }

  /* Full-width toast */
  .toast {
    right: 0.75rem;
    bottom: 0.75rem;
    left: 0.75rem;
    max-width: none;
  }

  /* Candidate cards: 2-up */
  .candidate-grid { grid-template-columns: repeat(2, 1fr); }

  /* Winner banner: stacked */
  .winner-banner {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.5rem;
    font-size: 0.875rem;
  }

  /* Full-width image previews */
  .image-preview,
  #voterImagePreview {
    width: 100%;
    max-width: 100%;
  }

  /* Smaller code input */
  .code-input {
    font-size: 1.25rem !important;
    letter-spacing: 0.2em;
  }
}




/* ============================================================
   RESPONSIVE — SMALL MOBILE  (≤ 380px)
   ============================================================ */
@media (max-width: 380px) {

  .candidate-grid { grid-template-columns: 1fr; }

  .stat-grid span { font-size: 1.125rem; }

  .brand strong { font-size: 0.75rem; }

  .nav-tab { padding: 0.375rem 0.5rem; }
}


/* ============================================================
   WIDE SCREEN — CENTER & CAP  (≥ 1440px)
   ============================================================ */
@media (min-width: 1440px) {

  :root { --sidebar-w: 280px; }

  .content {
    padding: 2.5rem 3rem;
  }
}