:root {
  --primary-color: #5a2fc0;
  --primary-light: #7b52d8;
  --secondary-color: #1a73e8;
  --success-color: #34a853;
  --warning-color: #e67700;
  --error-color: #ea4335;
  --background-color: #f8f9fa;
  --card-color: #ffffff;
  --text-color: #202124;
  --text-secondary: #5f6368;
  --border-color: #dadce0;
  --hover-color: #f1f3f4;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.12), 0 1px 2px rgba(0, 0, 0, 0.24);
  --shadow-hover: 0 3px 6px rgba(0, 0, 0, 0.16), 0 3px 6px rgba(0, 0, 0, 0.23);
}

[data-theme="dark"] {
  --primary-color: #7452d8;
  --primary-light: #9c7bea;
  --secondary-color: #4285f4;
  --success-color: #55c36e;
  --warning-color: #fcd251;
  --error-color: #f16b60;
  --background-color: #1e1e1e;
  --card-color: #2d2d2d;
  --text-color: #e8eaed;
  --text-secondary: #9aa0a6;
  --border-color: #3c4043;
  --hover-color: #3c3c3c;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, "Open Sans", "Helvetica Neue", sans-serif;
}

body {
  background-color: var(--background-color);
  color: var(--text-color);
  transition: all 0.3s ease;
  line-height: 1.6;
}

/* Main header */
.main-header {
  background-color: var(--primary-color);
  color: white;
  padding: 16px 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: var(--shadow);
  position: sticky;
  top: 0;
  z-index: 100;
}

.title {
  font-size: 1.5rem;
  font-weight: 600;
}

.header-controls {
  display: flex;
  align-items: center;
  gap: 16px;
}

.last-updated {
  margin-right: 20px;
  font-size: 0.9rem;
  opacity: 0.8;
}

.auto-refresh-indicator {
  font-size: 0.9rem;
  opacity: 0.8;
}

.auto-refresh-indicator.disabled {
  color: var(--error-color);
}

#refresh-countdown {
  font-weight: bold;
}

/* Toggle components (shared styles) */
.theme-toggle,
.autorefresh-toggle {
  display: flex;
  align-items: center;
}

.theme-toggle-label {
  margin-right: 8px;
  font-size: 0.9rem;
}

/* Switch base styles (shared between theme and autorefresh) */
.theme-switch,
.toggle-switch {
  position: relative;
  display: inline-block;
  cursor: pointer;
}

.theme-switch {
  width: 60px;
  height: 28px;
}

.toggle-switch {
  display: inline-flex;
  align-items: center;
  min-width: 120px;
}

/* Hide the checkbox */
.theme-switch input,
.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

/* Slider styles */
.slider,
.toggle-slider {
  display: flex;
  align-items: center;
  transition: 0.4s;
}

.slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #ccc;
  border-radius: 34px;
  justify-content: space-between;
  padding: 0 6px;
}

.toggle-slider {
  gap: 8px;
  color: white;
}

/* Toggle indicator elements */
.slider:before,
.toggle-slider:before {
  content: "";
  transition: 0.4s;
}

.slider:before {
  position: absolute;
  height: 20px;
  width: 20px;
  left: 4px;
  bottom: 4px;
  background-color: white;
  border-radius: 50%;
  z-index: 2;
}

.toggle-slider:before {
  position: relative;
  height: 18px;
  width: 36px;
  border-radius: 34px;
  background-color: rgba(255, 255, 255, 0.4);
  display: inline-block;
}

.toggle-slider:after {
  position: absolute;
  content: "";
  height: 14px;
  width: 14px;
  left: 2px;
  border-radius: 50%;
  background-color: white;
  transition: 0.3s;
}

/* Checked states */
input:checked + .slider,
input:checked + .toggle-slider:before {
  background-color: var(--primary-light);
}

input:checked + .slider:before {
  transform: translateX(32px);
}

input:checked + .toggle-slider:after {
  transform: translateX(18px);
}

.slider-icon {
  z-index: 1;
  font-size: 12px;
}

/* Dashboard layout */
.dashboard {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 20px;
  padding: 20px;
  max-width: 1800px;
  margin: 0 auto;
}

/* Stats panel */
.stats-panel {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.card {
  background-color: var(--card-color);
  border-radius: 8px;
  padding: 16px;
  box-shadow: var(--shadow);
  transition: box-shadow 0.3s ease;
}

.card:hover {
  box-shadow: var(--shadow-hover);
}

.card-title {
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: 16px;
  color: var(--primary-color);
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 8px;
}

/* Ballots section */
.ballots-section {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 100px);
  overflow-y: hidden;
}

/* Ballot filters */
.ballot-filters {
  display: flex;
  gap: 10px;
  margin-bottom: 15px;
}

.ballot-filters select {
  padding: 8px 12px;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  background-color: var(--card-color);
  color: var(--text-color);
  cursor: pointer;
}

.ballots-container {
  display: flex;
  flex-direction: column;
  gap: 16px;
  overflow-y: auto !important;
  padding-bottom: 300px; /* Add extra space at bottom */
}

.ballot {
  background-color: var(--card-color);
  border-radius: 8px;
  box-shadow: var(--shadow);
  overflow: hidden;
  transition: all 0.3s ease;
  height: auto !important;
  overflow: visible;
  margin-bottom: 30px; /* Space between ballots */
}

.ballot-header {
  padding: 12px 16px;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border-color);
  background-color: rgba(90, 47, 192, 0.05);
}

.ballot:hover .ballot-header {
  background-color: rgba(90, 47, 192, 0.1);
}

.ballot-id {
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ballot-meta {
  display: flex;
  align-items: center;
  gap: 12px;
}

.ballot-type,
.ballot-status {
  font-size: 0.85rem;
  padding: 4px 8px;
  border-radius: 4px;
  color: white;
}

.ballot-type {
  background-color: var(--secondary-color);
}

.ballot-content {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease;
  padding: 0 16px;
}

.ballot-content.open {
  max-height: none !important;
  height: auto !important;
  overflow: visible !important;
  padding: 16px;
  position: relative; /* Make sure content doesn't get clipped */
  z-index: 10; /* Ensure content appears above other elements */
}

.ballot-content.open .voter-table {
  margin-bottom: 15px;
  display: table !important;
  width: 100%;
}

.ballot-content.open .voter-table tbody tr {
  display: table-row;
  visibility: visible !important;
}

/* Voter table */
.voter-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 12px;
  font-size: 0.9rem;
  max-height: none;
  overflow: visible;
}

.voter-table th,
.voter-table td {
  padding: 8px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border-color);
}

.voter-table th {
  font-weight: 600;
  color: var(--text-secondary);
}

/* Ensure the table body isn't constrained */
.voter-table tbody {
  max-height: none;
  overflow: visible;
}

.validator-name,
.voter-address {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 200px;
}

/* Vote status classes */
.vote-success {
  background-color: var(--success-color);
}

.vote-pending {
  background-color: var(--warning-color);
}

.vote-failed {
  background-color: var(--error-color);
}

/* Loading and error states */
.loading {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 20px;
  color: var(--text-secondary);
  font-style: italic;
}

.error-message {
  color: var(--error-color);
  text-align: center;
  padding: 20px;
}

/* Stats display */
.stat-item {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid var(--border-color);
}

.stat-item:last-child {
  border-bottom: none;
}

.sub-item {
  padding-left: 16px;
  font-size: 0.9em;
}

/* Underperforming validators styling */
.stat-item sub-item .stat-value {
  font-weight: 500;
}

.sub-item:nth-child(2) .stat-value {
  color: var(--error-color);
}

.sub-item:nth-child(3) .stat-value,
.sub-item:nth-child(4) .stat-value {
  color: var(--warning-color);
}

/* Search form */
.lookup-form {
  display: flex;
  margin-bottom: 12px;
  gap: 8px;
}

.search-input {
  flex: 1;
  padding: 8px 12px;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  background-color: var(--card-color);
  color: var(--text-color);
}

.search-btn {
  padding: 8px 16px;
  background-color: var(--primary-color);
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  transition: background-color 0.3s;
}

.search-btn:hover {
  background-color: var(--primary-light);
}

.lookup-results {
  max-height: 300px;
  overflow-y: auto;
}

.search-info {
  text-align: center;
  color: var(--text-secondary);
  padding: 12px;
}

/* Refresh button */
.refresh-btn {
  padding: 6px 12px;
  background-color: var(--primary-color);
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-weight: 600;
  transition: background-color 0.3s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 28px; /* Match height with the theme toggle */
}

.refresh-btn:hover {
  background-color: var(--primary-light);
}

.refresh-icon {
  font-size: 16px;
}

/* Pagination */
.pagination-controls {
  display: flex;
  justify-content: center;
  margin-top: 20px;
  gap: 5px;
}

.pagination-btn {
  padding: 6px 12px;
  border: 1px solid var(--border-color);
  background-color: var(--card-color);
  color: var(--text-color);
  border-radius: 4px;
  cursor: pointer;
  transition: background-color 0.2s;
}

.pagination-btn:hover:not([disabled]) {
  background-color: var(--hover-color);
}

.pagination-btn.active {
  background-color: var(--primary-color);
  color: white;
  border-color: var(--primary-color);
}

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

/* Styling for pruned ballots */
.pruned-label {
  color: var(--error-color);
  font-weight: bold;
  font-size: 0.85rem;
}

.pruned-ballot {
  opacity: 0.8;
  border-left: 3px solid var(--error-color);
}

.pruned-ballot .ballot-header {
  background-color: rgba(234, 67, 53, 0.1); /* Using error-color with transparency */
}

.pruned-ballot:hover .ballot-header {
  background-color: rgba(234, 67, 53, 0.2); /* Slightly darker on hover */
}

/* CCTX data styling */
.cctx-data {
  margin: 12px 0;
  border-top: 1px solid var(--border-color);
  border-bottom: 1px solid var(--border-color);
  padding: 12px 0;
}

.cctx-content {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.cctx-item {
  display: flex;
  align-items: center;
  gap: 8px;
}

.cctx-label {
  font-weight: 600;
  color: var(--primary-color);
  white-space: nowrap;
}

.cctx-value {
  font-family: monospace;
  background-color: var(--hover-color);
  padding: 2px 6px;
  border-radius: 4px;
  max-width: 300px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Direction labels with vote counts */
.inbound-label,
.outbound-label {
  font-size: 0.85rem;
  font-weight: 600;
  margin-left: 4px;
}

.inbound-label {
  color: var(--secondary-color);
}

.outbound-label {
  color: var(--warning-color);
}

.cctx-note {
  grid-column: 1 / -1;
  margin-top: 8px;
  font-style: italic;
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.cctx-note-text {
  width: 100%;
  border-top: 1px dashed var(--border-color);
  padding-top: 6px;
}

/* Custom scrollbar */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: var(--background-color);
}

::-webkit-scrollbar-thumb {
  background: var(--primary-light);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--primary-color);
}

/* Responsive adjustments */
@media screen and (max-width: 1024px) {
  .dashboard {
    grid-template-columns: 1fr;
    display: flex;
    flex-direction: column-reverse; /* Reverse the order on mobile */
  }
  
  .ballots-section {
    margin-bottom: 20px;
    height: auto; /* Allow natural height */
    max-height: calc(100vh - 200px);
  }
  
  .stats-panel {
    margin-top: 20px;
  }
}

@media screen and (max-width: 768px) {
  .main-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 16px;
    padding: 12px 16px;
  }
  
  .header-controls {
    width: 100%;
    flex-wrap: wrap;
    gap: 12px;
  }
  
  .last-updated {
    width: 100%;
    margin-right: 0;
  }
  
  /* Make controls wrap properly on small screens */
  .refresh-btn, .theme-toggle, .autorefresh-toggle {
    flex-grow: 1;
  }
  
  .refresh-btn {
    justify-content: center;
    padding: 8px;
  }
  
  .theme-toggle, .autorefresh-toggle {
    justify-content: flex-end;
  }
  
  .ballot-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }
  
  .ballot-meta {
    width: 100%;
    justify-content: flex-start;
  }
  
  .ballot-filters {
    flex-direction: column;
  }
  
  .pagination-controls {
    flex-wrap: wrap;
  }
  
  .cctx-content {
    grid-template-columns: 1fr;
  }
}
