/* ==========================================================================
   CSS Design System - Dashboard Monitoring Sulingjar Kota Pekalongan
   ========================================================================== */

:root {
  --font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  
  /* Primary Theme Colors */
  --bg-main: #ffffff;
  --bg-surface: #ffffff;
  --bg-card: #ffffff;
  --border-color: rgba(136, 136, 136, 0.3);
  --border-color-hover: rgba(136, 136, 136, 0.3);
  
  --text-main: #242424;
  --text-muted: #3f3f3f;
  --text-dim: #64748b;
  
  --primary-accent: #91bd17;
  --primary-gradient: linear-gradient(135deg, #0284c7 0%, #0369a1 100%);
  
  /* Progress Color Scale Tokens */
  --scale-red: #ef4444;
  --scale-red-glow: rgba(239, 68, 68, 0.25);
  
  --scale-orange: #f97316;
  --scale-orange-glow: rgba(249, 115, 22, 0.25);
  
  --scale-yellow: #eab308;
  --scale-yellow-glow: rgba(234, 179, 8, 0.25);
  
  --scale-lime: #84cc16;
  --scale-lime-glow: rgba(132, 204, 22, 0.25);
  
  --scale-green: #10b981;
  --scale-green-glow: rgba(16, 185, 129, 0.25);

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  
  --shadow-card: 0 4px 20px -2px rgba(0, 0, 0, 0.0);
  --shadow-hover: 0 10px 30px -4px rgba(0, 0, 0, 0.0);
  
  --transition-fast: 0.15s ease;
  --transition-normal: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

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

body {
  font-family: var(--font-family);
  background-color: var(--bg-main);
  color: var(--text-main);
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
}

/* App Header */
.app-header {
  background: rgba(255, 255, 255, 0.8);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-color);
  position: sticky;
  top: 0;
  z-index: 100;
  padding: 16px 24px;
}

.header-container {
  max-width: 1400px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.brand-group {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-logo {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-md);
  background: var(--primary-gradient);
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 0 20px rgba(2, 132, 199, 0.4);
}

.app-header h1 {
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text-main);
}

.app-header .subtitle {
  font-size: 0.875rem;
  color: var(--text-muted);
  font-weight: 400;
}

.header-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: #879b3015;
  border: 1px solid #cbe947;
  color: #2e2e2e;
  padding: 6px 14px;
  border-radius: 9999px;
  font-size: 0.8rem;
  font-weight: 500;
}

.live-dot {
  width: 8px;
  height: 8px;
  background-color: #34d399;
  border-radius: 50%;
  box-shadow: 0 0 10px #34d399;
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.4; transform: scale(1.2); }
  100% { opacity: 1; transform: scale(1); }
}

/* Main Container */
.main-container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 24px;
  width: 100%;
  flex: 1;
}

/* Summary Stats Grid */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 16px;
  display: flex;
  align-items: center;
  gap: 16px;
  box-shadow: var(--shadow-card);
  transition: transform var(--transition-fast), border-color var(--transition-fast);
}

.stat-card:hover {
  transform: translateY(-2px);
  border-color: var(--border-color-hover);
}

.stat-icon {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.icon-blue { background: rgba(56, 189, 248, 0.15); color: #38bdf8; }
.icon-purple { background: rgba(168, 85, 247, 0.15); color: #c084fc; }
.icon-emerald { background: rgba(52, 211, 153, 0.15); color: #34d399; }
.icon-amber { background: rgba(251, 191, 36, 0.15); color: #fbbf24; }
.icon-green { background: rgba(34, 197, 94, 0.15); color: #4ade80; }

.stat-info {
  display: flex;
  flex-direction: column;
}

.stat-label {
  font-size: 0.775rem;
  color: var(--text-muted);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.stat-value {
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--text-main);
  margin-top: 2px;
}

/* Control Panel (Search & Filters) */
.control-panel {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 20px;
  margin-bottom: 20px;
  box-shadow: var(--shadow-card);
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.search-box-wrapper {
  position: relative;
  width: 100%;
}

.search-icon {
  position: absolute;
  left: 16px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
}

#searchInput {
  width: 100%;
  background: rgba(255, 255, 255, 0.6);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 14px 44px 14px 48px;
  color: var(--text-main);
  font-size: 0.95rem;
  font-family: inherit;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

#searchInput:focus {
  outline: none;
  border-color: var(--primary-accent);
  box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.15);
}

#searchInput::placeholder {
  color: var(--text-dim);
}

.clear-search-btn {
  position: absolute;
  right: 14px;
  top: 50%;
  transform: translateY(-50%);
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 1.25rem;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
}

.clear-search-btn:hover {
  color: var(--text-main);
  background: rgba(255, 255, 255, 0.1);
}

.filters-wrapper {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 14px;
}

.filter-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.filter-group label {
  font-size: 0.775rem;
  color: var(--text-muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.filter-group select {
  background: rgba(255, 255, 255, 0.6);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  color: var(--text-main);
  font-size: 0.875rem;
  font-family: inherit;
  cursor: pointer;
  transition: border-color var(--transition-fast);
}

.filter-group select:focus {
  outline: none;
  border-color: var(--primary-accent);
}

/* Results Status Bar */
.results-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
  padding: 0 4px;
  font-size: 0.875rem;
  color: var(--text-muted);
}

.reset-btn {
  font-family: inherit;
  text-transform: uppercase;
  background: #c94141;
  border: 0;
  color: white;
  padding: 10px 16px;
  border-radius: 200px;
  font-size: 0.8rem;
  font-weight: bold;
  cursor: pointer;
  transition: background var(--transition-fast);
}

.reset-btn:hover {
  background: #e05858;
}

/* Cards Grid */
.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(330px, 1fr));
  gap: 20px;
}

/* Madrasah Card Styling */
.madrasah-card {
  position: relative;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 20px;
  overflow: hidden;
  box-shadow: var(--shadow-card);
  transition: transform var(--transition-normal), border-color var(--transition-normal), box-shadow var(--transition-normal);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  min-height: 200px;
  z-index: 1;
}

.madrasah-card:hover {
  transform: translateY(-4px);
  border-color: var(--card-scale-border, var(--border-color-hover));
  box-shadow: var(--shadow-hover);
}

/* Full Horizontal Background Progress Bar */
.card-bg-progress {
  position: absolute;
  bottom: 0;
  left: 0;
  height: 64px;
  width: var(--bg-progress-width, 0%);
  background-color: var(--bg-progress-color, var(--scale-red));
  opacity: 0.1;
  z-index: 0;
  transition: width 0.6s cubic-bezier(0.4, 0, 0.2, 1), background-color 0.4s ease;
  pointer-events: none;
}

/* Subtly glowing top line on background progress bar */
.card-bg-progress::after {
  content: '';
  position: absolute;
  right: 0;
  top: 0;
  bottom: 0;
  width: 3px;
  background-color: var(--bg-progress-color, var(--scale-red));
  box-shadow: 0 0 12px var(--bg-progress-color, var(--scale-red));
}

/* Card Content Wrapper (on top of background progress) */
.card-header-top {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin-bottom: 12px;
  padding-right: 70px; /* Leave space for absolute top-right percentage badge */
}

/* Absolute Positioned Percentage Badge (Top-Right) */
.percentage-badge-absolute {
  position: absolute;
  top: 0;
  right: 0;
  z-index: 3;
  font-size: 1.15rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--scale-badge-color, var(--text-main));
  background: white;
  padding: 4px 12px;
  border-radius: 0 0 0 20px;
  backdrop-filter: blur(8px);
}

/* Card Badges (Bentuk & NPSN) */
.card-badges {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.badge-bentuk {
  font-size: 0.725rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 3px 8px;
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--primary-accent);
  /* border: 1px solid rgba(56, 189, 248, 0.2); */
}

.badge-bentuk.bentuk-ra { color: #f472b6; border-color: rgba(244, 114, 182, 0.3); background: rgba(244, 114, 182, 0.1); }
.badge-bentuk.bentuk-mi { color: #38bdf8; border-color: rgba(56, 189, 248, 0.3); background: rgba(56, 189, 248, 0.1); }
.badge-bentuk.bentuk-mts { color: #fbbf24; border-color: rgba(251, 191, 36, 0.3); background: rgba(251, 191, 36, 0.1); }
.badge-bentuk.bentuk-ma { color: #a78bfa; border-color: rgba(167, 139, 250, 0.3); background: rgba(167, 139, 250, 0.1); }

.badge-npsn {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  background: rgba(255, 255, 255, 0.3);
  padding: 3px 8px;
  border-radius: 20px;
  border: 1px solid rgba(0, 0, 0, 0.05);
}

/* Card Titles & Location */
.card-body {
  position: relative;
  z-index: 2;
  margin-bottom: 16px;
}

.madrasah-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-main);
  line-height: 1.4;
  margin-bottom: 6px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.madrasah-kecamatan {
  font-size: 0.8rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 4px;
}

/* Breakdown Numbers Section (Kepsek & Guru ratios) */
.card-progress-section {
  position: relative;
  z-index: 2;
  margin-top: auto;
  background: rgba(255, 255, 255, 0.65);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  backdrop-filter: blur(6px);
}

.progress-ratios-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.ratio-box {
  display: flex;
  flex-direction: column;
}

.ratio-label {
  font-size: 0.725rem;
  color: var(--text-muted);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.ratio-value {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-main);
  margin-top: 2px;
}

.ratio-value .ratio-complete {
  color: var(--scale-badge-color, var(--primary-accent));
}

.ratio-value .ratio-total {
  color: var(--text-dim);
  font-size: 0.85rem;
  font-weight: 500;
}

/* Visual Progress Bar (Inner Detail) */
.inner-progress-bar-bg {
  width: 100%;
  height: 6px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 9999px;
  margin-top: 10px;
  overflow: hidden;
}

.inner-progress-bar-fill {
  height: 100%;
  border-radius: 9999px;
  background-color: var(--bg-progress-color, var(--scale-red));
  width: var(--bg-progress-width, 0%);
  transition: width 0.5s ease;
}

/* Empty State */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  background: var(--bg-surface);
  border: 1px border-color;
  border-radius: var(--radius-lg);
  color: var(--text-muted);
}

.empty-state svg {
  color: var(--text-dim);
  margin-bottom: 16px;
}

.empty-state h3 {
  font-size: 1.15rem;
  color: var(--text-main);
  margin-bottom: 6px;
}

/* Footer */
.app-footer {
  background: var(--bg-surface);
  border-top: 1px solid var(--border-color);
  padding: 24px;
  margin-top: 40px;
  text-align: center;
}

.footer-content {
  max-width: 1400px;
  margin: 0 auto;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.admin-tip {
  margin-top: 8px;
  font-size: 0.775rem;
  color: var(--text-dim);
}

.admin-tip code {
  background: rgba(255, 255, 255, 0.08);
  padding: 2px 6px;
  border-radius: 4px;
  color: var(--primary-accent);
  font-family: monospace;
}

/* Responsive Adjustments */
@media (max-width: 768px) {
  .app-header { padding: 14px 16px; }
  .main-container { padding: 16px; }
  .control-panel { padding: 16px; }
  .filters-wrapper { grid-template-columns: 1fr; }
  .cards-grid { grid-template-columns: 1fr; }
}

/* ==========================================================================
   View Switcher & Table View Additions (Non-destructive)
   ========================================================================== */

.results-left {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.view-switcher {
  display: inline-flex;
  align-items: center;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 4px;
  gap: 4px;
}

.view-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.view-btn:hover {
  color: var(--text-main);
  background: rgba(0, 0, 0, 0.04);
}

.view-btn.active {
  background: var(--primary-accent);
  color: #ffffff;
  /* box-shadow: 0 2px 8px rgba(56, 189, 248, 0.3); */
}

/* Table View Container */
.table-container {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-card);
  margin-bottom: 24px;
}

.table-responsive {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.madrasah-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 0.875rem;
}

.madrasah-table th {
  background: rgba(0, 0, 0, 0.03);
  color: var(--text-muted);
  font-weight: 700;
  font-size: 0.775rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border-color);
  white-space: nowrap;
}

.madrasah-table td {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border-color);
  color: var(--text-main);
  vertical-align: middle;
}

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

.madrasah-table tbody tr {
  transition: background-color var(--transition-fast);
}

.madrasah-table tbody tr:hover {
  background-color: rgba(0, 0, 0, 0.025);
}

.table-col-num {
  font-weight: 600;
  color: var(--text-dim);
  text-align: center;
  width: 48px;
}

.table-npsn-code {
  font-family: monospace;
  font-weight: 600;
  font-size: 0.825rem;
  color: var(--text-muted);
  background: rgba(0, 0, 0, 0.04);
  padding: 2px 6px;
  border-radius: 4px;
}

.table-instansi-name {
  font-weight: 700;
  color: var(--text-main);
}

.table-ratio {
  font-weight: 600;
  text-align: center;
  white-space: nowrap;
}

.table-ratio-comp {
  color: var(--text-main);
}

.table-ratio-tot {
  color: var(--text-dim);
  font-size: 0.8rem;
}

.table-progress-cell {
  min-width: 140px;
}

.table-progress-wrapper {
  display: flex;
  align-items: center;
  gap: 10px;
}

.table-progress-bar-bg {
  flex: 1;
  height: 8px;
  background: rgba(0, 0, 0, 0.08);
  border-radius: 9999px;
  overflow: hidden;
}

.table-progress-bar-fill {
  height: 100%;
  border-radius: 9999px;
  transition: width 0.4s ease;
}

.table-pct-text {
  font-weight: 800;
  font-size: 0.85rem;
  min-width: 48px;
  text-align: right;
}

@media (max-width: 768px) {
  .results-bar {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
  }
  .view-switcher {
    width: 100%;
    justify-content: center;
  }
  .view-btn {
    flex: 1;
    justify-content: center;
  }
}
