/* ============================================
   TEC Election Tool — Mobile-First Stylesheet
   ============================================ */

/* --- Reset & Base --- */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  line-height: 1.5;
  color: #1a1a1a;
  background: #f5f5f5;
  min-width: 320px;
  overflow-x: hidden;
}

/* --- Typography --- */
h1 { font-size: 1.5rem; margin-bottom: 0.75rem; }
h2 { font-size: 1.25rem; margin-bottom: 0.5rem; }
h3 { font-size: 1.1rem; margin-bottom: 0.5rem; }
p  { margin-bottom: 0.75rem; }
a  { color: #0066cc; }

/* --- Layout --- */
.header {
  background: #1a1a1a;
  color: #fff;
  padding: 0.75rem 1rem;
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 48px;
}

.header__title {
  font-size: 1rem;
  font-weight: 600;
  color: #fff;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
}

.header__logo {
  height: 32px;
  width: auto;
}

.header__nav {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.header__nav a {
  color: #ccc;
  text-decoration: none;
  font-size: 0.875rem;
  min-height: 44px;
  min-width: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 0.5rem;
  border-radius: 4px;
}

.header__nav a:hover,
.header__nav a:focus {
  color: #fff;
  background: rgba(255, 255, 255, 0.1);
}

.container {
  max-width: 600px;
  margin: 0 auto;
  padding: 1rem;
}

.page-title {
  font-size: 1.5rem;
  margin-bottom: 1rem;
}

/* --- Touch-Friendly Tap Targets (44x44 min) --- */
button,
a,
input,
select,
textarea,
[role="button"],
label.candidate-option {
  min-height: 44px;
}

button,
a,
input[type="submit"],
input[type="button"],
[role="button"] {
  min-width: 44px;
}

/* --- Forms --- */
.form-group {
  margin-bottom: 1rem;
}

.form-group label {
  display: block;
  font-weight: 600;
  font-size: 0.875rem;
  margin-bottom: 0.25rem;
  color: #333;
}

input[type="text"],
input[type="email"],
input[type="number"],
input[type="password"],
input[type="tel"],
textarea,
select {
  display: block;
  width: 100%;
  padding: 0.625rem 0.75rem;
  font-size: 1rem;
  line-height: 1.5;
  color: #1a1a1a;
  background: #fff;
  border: 1px solid #ccc;
  border-radius: 6px;
  appearance: none;
  -webkit-appearance: none;
}

input:focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: #0066cc;
  box-shadow: 0 0 0 2px rgba(0, 102, 204, 0.25);
}

input.input-error,
textarea.input-error {
  border-color: #cc0000;
}

textarea {
  resize: vertical;
  min-height: 88px;
}

/* OTP input — large centered digits */
.otp-input {
  text-align: center;
  font-size: 1.5rem;
  letter-spacing: 0.5rem;
  font-weight: 600;
}

/* --- Buttons --- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  min-width: 44px;
  padding: 0.625rem 1.25rem;
  font-size: 1rem;
  font-weight: 600;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  text-decoration: none;
  text-align: center;
  transition: background 0.15s, opacity 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-block {
  display: flex;
  width: 100%;
}

.btn-primary {
  background: #0066cc;
  color: #fff;
}

.btn-primary:hover:not(:disabled) {
  background: #0052a3;
}

.btn-secondary {
  background: #e8e8e8;
  color: #1a1a1a;
}

.btn-secondary:hover:not(:disabled) {
  background: #d4d4d4;
}

.btn-danger {
  background: #cc0000;
  color: #fff;
}

.btn-danger:hover:not(:disabled) {
  background: #a30000;
}

.btn-sm {
  min-height: 44px;
  padding: 0.375rem 0.75rem;
  font-size: 0.875rem;
}

.btn-group {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

/* --- Card / Panel --- */
.card {
  background: #fff;
  border-radius: 8px;
  padding: 1rem;
  margin-bottom: 1rem;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.card__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.75rem;
}

.card__title {
  font-size: 1.1rem;
  font-weight: 600;
}

/* --- Status Badges --- */
.badge {
  display: inline-block;
  padding: 0.2rem 0.6rem;
  font-size: 0.75rem;
  font-weight: 600;
  border-radius: 12px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  white-space: nowrap;
}

.badge-draft {
  background: #e8e8e8;
  color: #555;
}

.badge-open {
  background: #d4edda;
  color: #155724;
}

.badge-closed {
  background: #fff3cd;
  color: #856404;
}

.badge-finalized {
  background: #cce5ff;
  color: #004085;
}

/* --- Candidate Selection (Ballot Page) --- */
.candidate-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.candidate-option {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem;
  background: #fff;
  border: 2px solid #e0e0e0;
  border-radius: 8px;
  cursor: pointer;
  min-height: 44px;
  transition: border-color 0.15s, background 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.candidate-option:hover {
  border-color: #0066cc;
}

.candidate-option.selected {
  border-color: #0066cc;
  background: #eef5ff;
}

.candidate-option__check {
  width: 24px;
  height: 24px;
  border: 2px solid #ccc;
  border-radius: 4px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.875rem;
  color: transparent;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.candidate-option.selected .candidate-option__check {
  background: #0066cc;
  border-color: #0066cc;
  color: #fff;
}

.candidate-option__name {
  font-weight: 600;
  font-size: 1rem;
}

.candidate-option__desc {
  font-size: 0.875rem;
  color: #555;
}

/* --- Selection Counter Bar (sticky) --- */
.selection-bar {
  position: sticky;
  bottom: 0;
  left: 0;
  right: 0;
  background: #fff;
  border-top: 1px solid #e0e0e0;
  padding: 0.75rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  z-index: 50;
  box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.06);
}

.selection-bar__count {
  font-weight: 600;
  font-size: 1rem;
  white-space: nowrap;
}

.selection-bar__count .count-current {
  font-size: 1.25rem;
}

.selection-bar .btn {
  flex-shrink: 0;
}

/* --- Messages (Error / Success) --- */
.msg {
  padding: 0.75rem 1rem;
  border-radius: 6px;
  font-size: 0.9rem;
  margin-bottom: 1rem;
}

.msg-error {
  background: #fdecea;
  color: #611a15;
  border: 1px solid #f5c6cb;
}

.msg-success {
  background: #d4edda;
  color: #155724;
  border: 1px solid #c3e6cb;
}

.msg-info {
  background: #cce5ff;
  color: #004085;
  border: 1px solid #b8daff;
}

/* --- Loading Indicator --- */
.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  color: #666;
  font-size: 0.9rem;
}

.spinner {
  width: 24px;
  height: 24px;
  border: 3px solid #e0e0e0;
  border-top-color: #0066cc;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  margin-right: 0.5rem;
}

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

/* --- Tables (Audit Log, Voter Roll) --- */
.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin-bottom: 1rem;
}

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

thead th {
  text-align: left;
  padding: 0.5rem 0.75rem;
  background: #f0f0f0;
  font-weight: 600;
  white-space: nowrap;
  border-bottom: 2px solid #ddd;
}

tbody td {
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid #eee;
  vertical-align: top;
}

tbody tr:hover {
  background: #fafafa;
}

/* Monospace for hashes */
.mono {
  font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
  font-size: 0.8rem;
  word-break: break-all;
}

/* --- Election List (Admin Dashboard) --- */
.election-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.election-list__item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.75rem;
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
  text-decoration: none;
  color: inherit;
  min-height: 44px;
}

.election-list__item:hover {
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.12);
}

/* --- Confirmation Page --- */
.confirm-summary {
  list-style: none;
  margin-bottom: 1rem;
}

.confirm-summary li {
  padding: 0.375rem 0;
  border-bottom: 1px solid #eee;
}

.confirm-hash {
  background: #f0f0f0;
  padding: 0.75rem;
  border-radius: 6px;
  margin-bottom: 1rem;
}

/* --- Utility --- */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.text-center { text-align: center; }
.text-muted  { color: #666; }
.text-sm     { font-size: 0.875rem; }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }

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

/* Tablet (768px+) */
@media (min-width: 768px) {
  .container {
    max-width: 720px;
    padding: 1.5rem;
  }

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

  .card {
    padding: 1.25rem;
  }

  .btn-group {
    flex-wrap: nowrap;
  }

  .selection-bar {
    padding: 0.75rem 1.5rem;
  }
}

/* Desktop (1024px+) */
@media (min-width: 1024px) {
  .container {
    max-width: 800px;
    padding: 2rem;
  }

  h1 { font-size: 2rem; }

  .header {
    padding: 0.75rem 2rem;
  }
}
