/* ==========================================================================
   SISTEM PEMILIHAN BPD PASIRANGIN - COMPACT & CLEAN LIGHT DESIGN SYSTEM
   Modern, Simple, Responsive, High Legibility, Light Theme
   ========================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600;700;800&family=JetBrains+Mono:wght@400;500;600&display=swap');

:root {
  --font-main: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;

  /* Primary Brand (Clean Cyan-Blue Government Official) */
  --primary: #0284c7;
  --primary-hover: #0369a1;
  --primary-active: #075985;
  --primary-light: #f0f9ff;
  --primary-border: #bae6fd;
  --primary-text: #0369a1;

  /* Semantic Palettes (Clean & Subdued) */
  --success: #059669;
  --success-hover: #047857;
  --success-light: #ecfdf5;
  --success-border: #a7f3d0;
  --success-text: #047857;

  --warning: #d97706;
  --warning-hover: #b45309;
  --warning-light: #fffbeb;
  --warning-border: #fde68a;
  --warning-text: #b45309;

  --danger: #dc2626;
  --danger-hover: #b91c1c;
  --danger-light: #fef2f2;
  --danger-border: #fecaca;
  --danger-text: #b91c1c;

  --info: #2563eb;
  --info-light: #eff6ff;
  --info-border: #bfdbfe;
  --info-text: #1d4ed8;

  /* Base Light Theme Colors */
  --bg-body: #f8fafc;
  --bg-surface: #ffffff;
  --bg-surface-elevated: #f1f5f9;
  --bg-surface-hover: #f8fafc;
  --bg-glass: rgba(255, 255, 255, 0.96);

  /* Subtle Borders & Dividers */
  --border-color: #e2e8f0;
  --border-color-light: #f1f5f9;
  --border-focus: #0284c7;

  /* High Legibility Typography Colors */
  --text-main: #0f172a;        /* Deep slate for high contrast */
  --text-secondary: #334155;   /* Medium slate */
  --text-muted: #64748b;       /* Subtle slate for secondary info */
  --text-dim: #94a3b8;         /* Light slate for placeholders/disabled */
  --text-inverse: #ffffff;

  /* Refined Compact Shadows */
  --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.05), 0 1px 2px rgba(0, 0, 0, 0.03);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.06), 0 2px 4px -2px rgba(0, 0, 0, 0.03);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.07), 0 4px 6px -4px rgba(0, 0, 0, 0.03);

  /* Compact Radii */
  --radius-xs: 4px;
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-full: 9999px;

  --transition: all 0.15s ease-in-out;
}

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

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

body {
  font-family: var(--font-main);
  background-color: var(--bg-body);
  color: var(--text-main);
  line-height: 1.45;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

h1, h2, h3, h4, h5, h6 {
  color: var(--text-main);
  font-weight: 700;
  line-height: 1.25;
  letter-spacing: -0.015em;
}

h1 { font-size: 1.35rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 0.98rem; }
h4 { font-size: 0.88rem; }

p {
  color: var(--text-secondary);
  font-size: 0.85rem;
}

a {
  color: var(--primary);
  text-decoration: none;
  transition: var(--transition);
}

a:hover {
  color: var(--primary-hover);
}

code, pre, .font-mono {
  font-family: var(--font-mono);
}

/* ==========================================================================
   LAYOUT CONTAINERS & GLASS PANELS
   ========================================================================== */
.container {
  width: 100%;
  max-width: 1280px;
  margin: 0 auto;
  padding: 1rem 1.25rem;
}

.glass-panel {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  transition: var(--transition);
}

/* ==========================================================================
   COMPACT RESPONSIVE NAVBAR
   ========================================================================== */
.navbar {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-color);
  box-shadow: var(--shadow-xs);
  padding: 0.5rem 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.nav-brand {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  text-decoration: none;
  flex-shrink: 0;
}

.nav-logo-badge {
  width: 32px;
  height: 32px;
  background: linear-gradient(135deg, #0284c7, #0d9488);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #ffffff;
  font-size: 1rem;
  font-weight: 800;
  flex-shrink: 0;
}

.nav-title-group h1 {
  font-size: 0.95rem;
  font-weight: 800;
  color: var(--text-main);
  letter-spacing: -0.01em;
  margin: 0;
  line-height: 1.15;
}

.nav-title-group p {
  font-size: 0.72rem;
  color: var(--text-muted);
  margin: 0;
  line-height: 1.15;
}

.nav-links {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  list-style: none;
  margin: 0;
  padding: 0;
}

.nav-item a {
  padding: 0.35rem 0.65rem;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-weight: 600;
  font-size: 0.82rem;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  transition: var(--transition);
  border: 1px solid transparent;
}

.nav-item a:hover {
  background: var(--bg-surface-elevated);
  color: var(--text-main);
}

.nav-item a.active {
  background: var(--primary-light);
  color: var(--primary);
  border-color: var(--primary-border);
  font-weight: 700;
}

/* ==========================================================================
   COMPACT BUTTONS
   ========================================================================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  padding: 0.38rem 0.75rem;
  font-family: var(--font-main);
  font-size: 0.82rem;
  font-weight: 600;
  border-radius: var(--radius-sm);
  cursor: pointer;
  border: 1px solid transparent;
  transition: var(--transition);
  text-decoration: none;
  white-space: nowrap;
  line-height: 1.25;
}

.btn:active {
  transform: scale(0.98);
}

.btn-primary {
  background: var(--primary);
  color: #ffffff;
  border-color: var(--primary);
}
.btn-primary:hover {
  background: var(--primary-hover);
  border-color: var(--primary-hover);
  color: #ffffff;
}

.btn-secondary {
  background: var(--bg-surface);
  border-color: var(--border-color);
  color: var(--text-secondary);
}
.btn-secondary:hover {
  background: var(--bg-surface-elevated);
  border-color: #cbd5e1;
  color: var(--text-main);
}

.btn-success {
  background: var(--success);
  color: #ffffff;
  border-color: var(--success);
}
.btn-success:hover {
  background: var(--success-hover);
  border-color: var(--success-hover);
  color: #ffffff;
}

.btn-danger {
  background: var(--danger-light);
  color: var(--danger-text);
  border-color: var(--danger-border);
}
.btn-danger:hover {
  background: var(--danger);
  color: #ffffff;
  border-color: var(--danger);
}

.btn-warning {
  background: var(--warning-light);
  color: var(--warning-text);
  border-color: var(--warning-border);
}
.btn-warning:hover {
  background: var(--warning);
  color: #ffffff;
  border-color: var(--warning);
}

.btn-sm {
  padding: 0.25rem 0.55rem;
  font-size: 0.76rem;
  border-radius: var(--radius-xs);
}

.btn-lg {
  padding: 0.55rem 1.15rem;
  font-size: 0.92rem;
  border-radius: var(--radius-md);
}

/* ==========================================================================
   COMPACT STAT CARDS
   ========================================================================== */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.stat-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 0.75rem 0.9rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  box-shadow: var(--shadow-xs);
  transition: var(--transition);
  position: relative;
  overflow: hidden;
}

.stat-card:hover {
  border-color: #cbd5e1;
  box-shadow: var(--shadow-sm);
}

.stat-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 3px;
  height: 100%;
  background: var(--border-color);
}

.stat-card.primary::before { background: var(--primary); }
.stat-card.success::before { background: var(--success); }
.stat-card.warning::before { background: var(--warning); }
.stat-card.info::before { background: var(--info); }
.stat-card.danger::before { background: var(--danger); }

.stat-icon {
  width: 34px;
  height: 34px;
  border-radius: var(--radius-sm);
  background: var(--primary-light);
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  flex-shrink: 0;
}

.stat-card.success .stat-icon { background: var(--success-light); color: var(--success); }
.stat-card.warning .stat-icon { background: var(--warning-light); color: var(--warning); }
.stat-card.info .stat-icon { background: var(--info-light); color: var(--info); }
.stat-card.danger .stat-icon { background: var(--danger-light); color: var(--danger); }

.stat-content {
  flex: 1;
  min-width: 0;
}

.stat-content h3 {
  font-size: 0.72rem;
  color: var(--text-muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 0.15rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.stat-value {
  font-size: 1.35rem;
  font-weight: 800;
  line-height: 1.1;
  color: var(--text-main);
  letter-spacing: -0.02em;
}

.stat-sub {
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-top: 0.15rem;
}

/* ==========================================================================
   COMPACT BADGES & STATUS TAGS
   ========================================================================== */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.18rem 0.5rem;
  border-radius: var(--radius-full);
  font-size: 0.72rem;
  font-weight: 600;
  line-height: 1;
}

.badge-primary {
  background: var(--primary-light);
  color: var(--primary-text);
  border: 1px solid var(--primary-border);
}

.badge-success {
  background: var(--success-light);
  color: var(--success-text);
  border: 1px solid var(--success-border);
}

.badge-warning {
  background: var(--warning-light);
  color: var(--warning-text);
  border: 1px solid var(--warning-border);
}

.badge-danger {
  background: var(--danger-light);
  color: var(--danger-text);
  border: 1px solid var(--danger-border);
}

.badge-secondary {
  background: var(--bg-surface-elevated);
  color: var(--text-secondary);
  border: 1px solid var(--border-color);
}

/* Match badge for search */
.badge-member-match {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.74rem;
  color: #0369a1;
  background: #f0f9ff;
  border: 1px solid #bae6fd;
  padding: 2px 6px;
  border-radius: var(--radius-xs);
  margin-top: 3px;
}

/* Live pulse dot */
.live-dot {
  width: 8px;
  height: 8px;
  background-color: var(--success);
  border-radius: 50%;
  display: inline-block;
  box-shadow: 0 0 0 0 rgba(5, 150, 105, 0.6);
  animation: pulse-live 1.8s infinite;
}

@keyframes pulse-live {
  0% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(5, 150, 105, 0.6); }
  70% { transform: scale(1); box-shadow: 0 0 0 6px rgba(5, 150, 105, 0); }
  100% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(5, 150, 105, 0); }
}

/* ==========================================================================
   COMPACT FORMS, INPUTS, SELECTS
   ========================================================================== */
.form-group {
  margin-bottom: 0.75rem;
}

.form-label {
  display: block;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-main);
  margin-bottom: 0.25rem;
}

.form-control {
  width: 100%;
  padding: 0.42rem 0.65rem;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-main);
  font-family: var(--font-main);
  font-size: 0.82rem;
  line-height: 1.35;
  transition: var(--transition);
}

.form-control:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(2, 132, 199, 0.12);
}

.form-control::placeholder {
  color: var(--text-dim);
}

select.form-control {
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%2364748b'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M19 9l-7 7-7-7'%3E%3C/path%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.5rem center;
  background-size: 1rem;
  padding-right: 1.75rem;
  appearance: none;
  -webkit-appearance: none;
}

/* Filter bar */
.filter-bar {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  align-items: center;
}

/* ==========================================================================
   COMPACT CLEAN TABLES
   ========================================================================== */
.table-responsive {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  background: var(--bg-surface);
}

.custom-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
}

.custom-table th {
  background: var(--bg-surface-elevated);
  color: var(--text-muted);
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 0.55rem 0.75rem;
  border-bottom: 1px solid var(--border-color);
  white-space: nowrap;
}

.custom-table td {
  padding: 0.55rem 0.75rem;
  border-bottom: 1px solid var(--border-color-light);
  color: var(--text-main);
  font-size: 0.82rem;
  vertical-align: middle;
}

.custom-table tbody tr:last-child td {
  border-bottom: none;
}

.custom-table tbody tr:hover td {
  background: var(--bg-surface-hover);
}

/* ==========================================================================
   COMPACT MODALS
   ========================================================================== */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  opacity: 0;
  visibility: hidden;
  transition: var(--transition);
}

.modal-backdrop.show {
  opacity: 1;
  visibility: visible;
}

.modal-content {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  max-width: 580px;
  width: 100%;
  box-shadow: var(--shadow-lg);
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform: translateY(10px);
  transition: var(--transition);
}

.modal-backdrop.show .modal-content {
  transform: translateY(0);
}

.modal-header {
  padding: 0.85rem 1.25rem;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-surface);
}

.modal-header h3 {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text-main);
}

.modal-body {
  padding: 1rem 1.25rem;
  overflow-y: auto;
}

.modal-footer {
  padding: 0.75rem 1.25rem;
  border-top: 1px solid var(--border-color);
  background: var(--bg-surface-elevated);
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
}

/* ==========================================================================
   CARDS (CANDIDATE, POS, DUSUN)
   ========================================================================== */
.candidate-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 0.85rem;
  margin-top: 0.75rem;
}

.candidate-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  overflow: hidden;
  transition: var(--transition);
  box-shadow: var(--shadow-xs);
}

.candidate-card:hover {
  border-color: var(--primary);
  box-shadow: var(--shadow-md);
}

.candidate-card.is-elected {
  border-color: var(--success);
  background: linear-gradient(180deg, #ecfdf5 0%, #ffffff 100%);
}

.candidate-header {
  padding: 0.75rem 0.9rem;
  display: flex;
  align-items: center;
  gap: 0.65rem;
  border-bottom: 1px solid var(--border-color-light);
}

.candidate-number {
  width: 32px;
  height: 32px;
  background: var(--primary);
  border-radius: var(--radius-sm);
  color: #ffffff;
  font-weight: 800;
  font-size: 1.1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.candidate-body {
  padding: 0.75rem 0.9rem;
}

.vote-bar-wrap {
  background: var(--bg-surface-elevated);
  height: 8px;
  border-radius: var(--radius-full);
  overflow: hidden;
  margin: 0.45rem 0 0.3rem 0;
}

.vote-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, #0284c7, #059669);
  border-radius: var(--radius-full);
  transition: width 0.4s ease-out;
}

/* KK Card in Pos Operator */
.kk-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 0.85rem 1rem;
  margin-bottom: 0.65rem;
  transition: var(--transition);
}

.kk-card:hover {
  border-color: #cbd5e1;
}

.kk-card.sudah-memilih {
  border-left: 3px solid var(--success);
  background: #f0fdf4;
}

.kk-card.belum-memilih {
  border-left: 3px solid var(--warning);
}

/* Toast notifications */
.toast-container {
  position: fixed;
  bottom: 1rem;
  right: 1rem;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  pointer-events: none;
}

.toast {
  pointer-events: auto;
  background: var(--text-main);
  color: #ffffff;
  padding: 0.5rem 0.85rem;
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  animation: slide-in 0.2s ease-out;
}

.toast.success { background: #065f46; color: #ecfdf5; }
.toast.error { background: #991b1b; color: #fef2f2; }
.toast.warning { background: #92400e; color: #fffbeb; }

@keyframes slide-in {
  from { transform: translateY(15px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

/* ==========================================================================
   RESPONSIVE OPTIMIZATION (MOBILE & TABLET)
   ========================================================================== */
@media (max-width: 768px) {
  html {
    font-size: 13px;
  }

  .container {
    padding: 0.75rem;
  }

  /* Compact Navbar for Mobile */
  .navbar {
    padding: 0.4rem 0.75rem;
    flex-wrap: wrap;
  }

  .nav-links {
    width: 100%;
    order: 3;
    overflow-x: auto;
    white-space: nowrap;
    padding-top: 0.4rem;
    padding-bottom: 0.15rem;
    border-top: 1px solid var(--border-color);
    margin-top: 0.35rem;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .nav-links::-webkit-scrollbar {
    display: none;
  }

  .nav-item a {
    padding: 0.28rem 0.55rem;
    font-size: 0.76rem;
  }

  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 0.5rem;
  }

  .stat-card {
    padding: 0.65rem 0.75rem;
    gap: 0.5rem;
  }

  .stat-icon {
    width: 28px;
    height: 28px;
    font-size: 0.95rem;
  }

  .stat-value {
    font-size: 1.15rem;
  }

  .filter-bar {
    flex-direction: column;
    align-items: stretch;
  }

  .filter-bar > div,
  .filter-bar > button {
    width: 100%;
    min-width: 100% !important;
  }

  .custom-table th,
  .custom-table td {
    padding: 0.45rem 0.55rem;
    font-size: 0.78rem;
  }

  .modal-content {
    max-height: 95vh;
    border-radius: var(--radius-md);
  }
}
