:root {
  --ps-red: #C8102E;
  --ps-red-dark: #9B0D22;
  --ps-red-light: #E8354A;
  --bg: #F5F6F8;
  --surface: #FFFFFF;
  --surface-alt: #F0F1F3;
  --text: #1A1A1A;
  --text-secondary: #6B7280;
  --text-muted: #9CA3AF;
  --border: #E5E7EB;
  --border-light: #F3F4F6;
  --success: #059669;
  --success-bg: #D1FAE5;
  --warning: #D97706;
  --warning-bg: #FEF3C7;
  --error: #DC2626;
  --error-bg: #FEE2E2;
  --info: #2563EB;
  --info-bg: #DBEAFE;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --shadow: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.07), 0 2px 4px rgba(0,0,0,0.06);
  --radius: 8px;
  --radius-lg: 12px;
  --sidebar-width: 260px;
  --topbar-height: 64px;
  --transition: 0.2s ease;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  min-height: 100vh;
  min-height: -webkit-fill-available;
  overflow-x: hidden;
}

html {
  height: -webkit-fill-available;
}

.sidebar {
  width: var(--sidebar-width);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 100;
  transition: transform var(--transition);
}

.sidebar-header {
  padding: 24px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
}

.sidebar-logo {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.sidebar-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  line-height: 1.3;
}

.sidebar-nav {
  flex: 1;
  padding: 12px 8px;
  overflow-y: auto;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: var(--radius);
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  transition: all var(--transition);
  margin-bottom: 2px;
}

.nav-item svg {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}

.nav-item:hover {
  background: var(--surface-alt);
  color: var(--text);
}

.nav-item.active {
  background: #FEE2E2;
  color: var(--ps-red);
  font-weight: 600;
}

.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--border);
}

.sidebar-status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-muted);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--success);
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

.main-content {
  flex: 1;
  margin-left: var(--sidebar-width);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: -webkit-fill-available;
  overflow-y: auto;
}

.topbar {
  height: var(--topbar-height);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  position: sticky;
  top: 0;
  z-index: 50;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 16px;
}

.menu-toggle {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
  padding: 8px;
  border-radius: var(--radius);
  color: var(--text-secondary);
}

.menu-toggle svg { width: 24px; height: 24px; }

.topbar-title {
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 16px;
}

.congress-status-badge {
  padding: 6px 12px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  background: var(--warning-bg);
  color: var(--warning);
}

.congress-status-badge.active {
  background: var(--success-bg);
  color: var(--success);
}

.congress-status-badge.closed {
  background: var(--error-bg);
  color: var(--error);
}

.topbar-clock {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
}

.content-area {
  flex: 1;
  padding: 24px;
}

.section { display: block; }
.section.hidden { display: none; }

.grid { display: grid; gap: 20px; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow-sm);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.card-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.card-value {
  font-size: 36px;
  font-weight: 800;
  color: var(--text);
  line-height: 1;
}

.card-subtitle {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 4px;
}

.card-icon {
  width: 48px;
  height: 48px;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
}

.card-icon svg { width: 24px; height: 24px; }

.card-icon.red { background: #FEE2E2; color: var(--ps-red); }
.card-icon.green { background: var(--success-bg); color: var(--success); }
.card-icon.blue { background: var(--info-bg); color: var(--info); }
.card-icon.orange { background: var(--warning-bg); color: var(--warning); }

.stat-card {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
}

.quorum-gauge {
  position: relative;
  width: 100%;
  max-width: 200px;
  margin: 0 auto;
}

.quorum-gauge svg { width: 100%; height: auto; }

.quorum-text {
  text-align: center;
  margin-top: 8px;
}

.quorum-percent {
  font-size: 32px;
  font-weight: 800;
  color: var(--text);
}

.quorum-label {
  font-size: 13px;
  color: var(--text-muted);
}

.progress-bar {
  width: 100%;
  height: 8px;
  background: var(--surface-alt);
  border-radius: 4px;
  overflow: hidden;
  margin-top: 12px;
}

.progress-fill {
  height: 100%;
  border-radius: 4px;
  transition: width 0.6s ease;
}

.progress-fill.red { background: var(--ps-red); }
.progress-fill.green { background: var(--success); }
.progress-fill.blue { background: var(--info); }

.table-container {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th {
  text-align: left;
  padding: 12px 16px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
}

td {
  padding: 12px 16px;
  font-size: 14px;
  border-bottom: 1px solid var(--border-light);
  vertical-align: middle;
}

tr:hover td { background: var(--surface-alt); }

.badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.badge.eligible { background: var(--success-bg); color: var(--success); }
.badge.checked-in { background: var(--info-bg); color: var(--info); }
.badge.credentialed { background: #E0E7FF; color: #4338CA; }
.badge.validated { background: #FEF3C7; color: #92400E; }
.badge.pre-registered { background: var(--surface-alt); color: var(--text-secondary); }
.badge.suspended { background: var(--error-bg); color: var(--error); }
.badge.inactive { background: var(--surface-alt); color: var(--text-muted); }

.badge.open { background: var(--success-bg); color: var(--success); }
.badge.closed { background: var(--error-bg); color: var(--error); }
.badge.upcoming { background: var(--info-bg); color: var(--info); }

.toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.search-input {
  flex: 1;
  min-width: 200px;
  padding: 10px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  background: var(--surface);
  color: var(--text);
  outline: none;
  transition: border-color var(--transition);
}

.search-input:focus { border-color: var(--ps-red); }

select.filter-select {
  padding: 10px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  background: var(--surface);
  color: var(--text);
  outline: none;
  cursor: pointer;
  min-width: 160px;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 18px;
  border: none;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
}

.btn-primary {
  background: var(--ps-red);
  color: white;
}

.btn-primary:hover { background: var(--ps-red-dark); }

.btn-secondary {
  background: var(--surface-alt);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-secondary:hover { background: var(--border); }

.btn-success {
  background: var(--success);
  color: white;
}

.btn-success:hover { background: #047857; }

.btn-danger {
  background: var(--error);
  color: white;
}

.btn-danger:hover { background: #B91C1C; }

.btn-sm {
  padding: 6px 12px;
  font-size: 12px;
}

.btn-icon {
  padding: 8px;
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-secondary);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.btn-icon:hover { background: var(--surface-alt); }

.btn-icon svg { width: 18px; height: 18px; }

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.section-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
}

.motion-card {
  border-left: 4px solid var(--ps-red);
  padding: 16px 20px;
}

.motion-card.open { border-left-color: var(--success); }
.motion-card.closed { border-left-color: var(--error); }
.motion-card.upcoming { border-left-color: var(--info); }

.motion-title {
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 4px;
}

.motion-meta {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.motion-summary {
  font-size: 14px;
  color: var(--text-secondary);
  line-height: 1.5;
  margin-bottom: 12px;
}

.motion-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.vote-bar {
  display: flex;
  height: 32px;
  border-radius: var(--radius);
  overflow: hidden;
  margin: 8px 0;
}

.vote-bar-segment {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  color: white;
  transition: width 0.6s ease;
  min-width: 0;
}

.vote-bar-segment.favor { background: var(--success); }
.vote-bar-segment.contra { background: var(--error); }
.vote-bar-segment.abstencao { background: var(--warning); }

.vote-legend {
  display: flex;
  gap: 16px;
  font-size: 13px;
  margin-top: 8px;
}

.vote-legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
}

.vote-legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

.vote-legend-dot.favor { background: var(--success); }
.vote-legend-dot.contra { background: var(--error); }
.vote-legend-dot.abstencao { background: var(--warning); }

.chart-container {
  position: relative;
  height: 250px;
}

.projection-controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.projection-mode-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.mode-btn {
  padding: 12px;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  cursor: pointer;
  text-align: center;
  transition: all var(--transition);
  font-size: 13px;
  font-weight: 500;
}

.mode-btn:hover { border-color: var(--ps-red-light); }

.mode-btn.active {
  border-color: var(--ps-red);
  background: #FEE2E2;
  color: var(--ps-red);
  font-weight: 700;
}

.projection-preview {
  background: #1A1A1A;
  border-radius: var(--radius-lg);
  padding: 24px;
  color: white;
  min-height: 200px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.projection-preview h3 {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 8px;
}

.projection-preview p {
  font-size: 14px;
  color: #9CA3AF;
}

.audit-timeline {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.audit-item {
  display: flex;
  gap: 16px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border-light);
}

.audit-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--ps-red);
  margin-top: 5px;
  flex-shrink: 0;
}

.audit-dot.vote { background: var(--success); }
.audit-dot.credential { background: var(--info); }
.audit-dot.motion { background: var(--warning); }
.audit-dot.congress { background: var(--ps-red); }

.audit-content { flex: 1; }

.audit-details {
  font-size: 14px;
  color: var(--text);
}

.audit-time {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

.audit-type-badge {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 10px;
  background: var(--surface-alt);
  color: var(--text-secondary);
}

.form-group {
  margin-bottom: 16px;
}

.form-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.form-input {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  background: var(--surface);
  color: var(--text);
  outline: none;
}

.form-input:focus { border-color: var(--ps-red); }

textarea.form-input {
  resize: vertical;
  min-height: 80px;
}

.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  padding: 12px 20px;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
  color: white;
  box-shadow: var(--shadow-md);
  animation: slideIn 0.3s ease;
  max-width: 400px;
}

.toast.success { background: var(--success); }
.toast.error { background: var(--error); }
.toast.info { background: var(--info); }
.toast.warning { background: var(--warning); }

@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-muted);
}

.empty-state-icon { font-size: 48px; margin-bottom: 12px; opacity: 0.5; }
.empty-state-text { font-size: 16px; font-weight: 500; }

.cred-summary-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 20px;
}

.cred-summary-item {
  text-align: center;
  padding: 12px;
  background: var(--surface-alt);
  border-radius: var(--radius);
}

.cred-summary-item .count {
  font-size: 28px;
  font-weight: 800;
}

.cred-summary-item .label {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-top: 2px;
}

.delegate-actions { display: flex; gap: 4px; }

.inline-actions { display: flex; gap: 4px; flex-wrap: wrap; }

@media (max-width: 1024px) {
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
  .grid-3 { grid-template-columns: repeat(2, 1fr); }
  .cred-summary-grid { grid-template-columns: repeat(2, 1fr); }
  .projection-controls { grid-template-columns: 1fr; }
  .projection-mode-grid { grid-template-columns: repeat(2, 1fr); }
}

.sidebar-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 99;
}

.sidebar-overlay.visible { display: block; }

@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .main-content { margin-left: 0; }
  .menu-toggle { display: flex; }
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
  .cred-summary-grid { grid-template-columns: repeat(2, 1fr); }
  .content-area {
    padding: 16px 12px;
    overflow-y: auto;
    flex: 1;
    -webkit-overflow-scrolling: touch;
  }
  .sidebar-nav {
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    flex: 1;
    min-height: 0;
  }
  .topbar {
    padding: 0 12px;
    min-height: var(--topbar-height);
    height: auto;
    flex-wrap: wrap;
  }
  .topbar-title { font-size: 16px; }
  .topbar-right { gap: 8px; }
  .congress-status-badge { font-size: 10px; padding: 4px 8px; }
}

@media (max-width: 768px) and (orientation: landscape) {
  .sidebar {
    width: min(260px, 70vw);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
  .sidebar-nav {
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    flex: 1;
    min-height: 0;
  }
  .sidebar-header { padding: 12px 16px; }
  .nav-item { padding: 8px 12px; font-size: 13px; }
  .nav-item svg { width: 18px; height: 18px; }
  .sidebar-footer { padding: 8px 16px; }
  .topbar { min-height: 48px; }
  .content-area {
    padding: 12px;
    overflow-y: auto;
    flex: 1;
    -webkit-overflow-scrolling: touch;
  }
}

@media (max-width: 480px) {
  .content-area { padding: 12px; }
  .topbar-title { font-size: 14px; }
  .topbar-clock { font-size: 12px; }
  .card { padding: 14px; }
  .card-value { font-size: 28px; }
  .section-title { font-size: 16px; }
  .toolbar { gap: 8px; }
  .search-input { min-width: 140px; padding: 8px 12px; }
  .btn { padding: 8px 14px; font-size: 13px; }
  .motion-actions { gap: 4px; }
  .projection-mode-grid { grid-template-columns: repeat(2, 1fr); }
}
