:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --border: #e3e7f0;
  --text: #1f2937;
  --muted: #6b7280;
  --accent: #2563eb;
  --accent-soft: #dbeafe;
  --pns: #2563eb;
  --pppk: #16a34a;
  --pw: #f59e0b;
  --pens: #ef4444;
  --kontrak: #8b5cf6;
  --naik: #0d9488;
  --shortage: #dc2626;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.08);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  font-size: 14px;
}

.topbar {
  background: linear-gradient(135deg, #1e3a8a, #2563eb);
  color: white;
  padding: 1.25rem 1.5rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 1.25rem;
  box-shadow: var(--shadow);
}
.brand h1 { margin: 0; font-size: 1.4rem; letter-spacing: -0.01em; }
.brand p { margin: 0.15rem 0 0; opacity: 0.85; font-size: 0.85rem; }

.kpi-row {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-left: auto;
}
.kpi {
  background: rgba(255, 255, 255, 0.13);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 10px;
  padding: 0.55rem 0.9rem;
  min-width: 110px;
}
.kpi-label { font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.05em; opacity: 0.8; }
.kpi-value { font-size: 1.4rem; font-weight: 600; }

main {
  padding: 1rem 1.5rem 3rem;
  max-width: 1600px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem;
  box-shadow: var(--shadow);
}
.card h2 { margin: 0 0 0.75rem; font-size: 0.95rem; color: var(--muted); font-weight: 600; }

.charts {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 1rem;
}
.charts .card { display: flex; flex-direction: column; }
.charts canvas { max-height: 240px; flex: 1; }

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: end;
}
.filters > div { display: flex; flex-direction: column; gap: 0.2rem; min-width: 160px; }
.filters .grow { flex: 1; min-width: 200px; }
.filters label { font-size: 0.75rem; color: var(--muted); }
.filters select, .filters input {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.45rem 0.65rem;
  font: inherit;
  background: white;
}
.filters select:focus, .filters input:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.btn-reset {
  padding: 0.5rem 1rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: white;
  cursor: pointer;
  font: inherit;
}
.btn-reset:hover { background: #f9fafb; }

.table-wrap { padding: 0; }
.table-meta { padding: 0.75rem 1rem; color: var(--muted); font-size: 0.85rem; border-bottom: 1px solid var(--border); }
.table-scroll { overflow: auto; max-height: 70vh; }

table { border-collapse: collapse; width: 100%; min-width: 1300px; font-size: 12.5px; }
thead { position: sticky; top: 0; background: #f8fafc; z-index: 2; }
th, td {
  border-bottom: 1px solid var(--border);
  padding: 0.4rem 0.55rem;
  text-align: center;
  vertical-align: middle;
}
th { font-weight: 600; color: #334155; font-size: 11.5px; }
td.text { text-align: left; }
.th-group th { background: #eef2ff; }

tbody tr:hover { background: #fafbff; }

.cnt {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 26px;
  height: 24px;
  padding: 0 0.4rem;
  border-radius: 6px;
  font-variant-numeric: tabular-nums;
  font-weight: 500;
  background: transparent;
  color: #475569;
}
.cnt.zero { color: #cbd5e1; }
.cnt.click {
  cursor: pointer;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
  transition: all 0.15s ease;
}
.cnt.click:hover { background: var(--accent); color: white; }
.cnt.pns.click { background: #dbeafe; color: #1d4ed8; }
.cnt.pns.click:hover { background: #1d4ed8; color: white; }
.cnt.pppk.click { background: #dcfce7; color: #15803d; }
.cnt.pppk.click:hover { background: #15803d; color: white; }
.cnt.pw.click { background: #fef3c7; color: #b45309; }
.cnt.pw.click:hover { background: #b45309; color: white; }
.cnt.pens.click { background: #fee2e2; color: #b91c1c; }
.cnt.pens.click:hover { background: #b91c1c; color: white; }
.cnt.kontrak.click { background: #ede9fe; color: #6d28d9; }
.cnt.kontrak.click:hover { background: #6d28d9; color: white; }
.cnt.naik.click { background: #ccfbf1; color: #0f766e; }
.cnt.naik.click:hover { background: #0f766e; color: white; }

.kurang { font-weight: 600; }
.kurang.pos { color: var(--shortage); }
.kurang.zero { color: #16a34a; }
.kurang.neg { color: #6b7280; }

.badge {
  display: inline-block;
  padding: 0.05rem 0.45rem;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
}
.badge.JFT { background: #ddd6fe; color: #5b21b6; }
.badge.JFU { background: #fde68a; color: #92400e; }

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 1rem;
  animation: fadeIn 0.15s ease;
}
.modal-backdrop[hidden] { display: none; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal {
  background: white;
  border-radius: 14px;
  max-width: 1000px;
  width: 100%;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 25px 50px rgba(15, 23, 42, 0.25);
  animation: slideUp 0.2s ease;
}
@keyframes slideUp { from { transform: translateY(15px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

.modal-head {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  position: relative;
}
.modal-head h3 { margin: 0; font-size: 1.05rem; padding-right: 2rem; }
.modal-head p { margin: 0.25rem 0 0; color: var(--muted); font-size: 0.85rem; }
.btn-close {
  position: absolute;
  top: 0.75rem;
  right: 0.85rem;
  background: transparent;
  border: none;
  font-size: 1.2rem;
  width: 2rem;
  height: 2rem;
  border-radius: 8px;
  cursor: pointer;
  color: var(--muted);
  font-weight: 600;
}
.btn-close:hover { background: #f1f5f9; color: var(--text); }

.modal-body {
  overflow: auto;
  padding: 0.75rem 1.25rem 1.25rem;
}
.modal-body table { min-width: 0; font-size: 13px; }
.modal-body th { background: #f8fafc; }
.modal-body td.left { text-align: left; }
.modal-empty { color: var(--muted); padding: 1rem; text-align: center; }

@media (max-width: 720px) {
  .topbar { flex-direction: column; align-items: stretch; }
  .kpi-row { margin-left: 0; }
  main { padding: 0.75rem; }
  .filters > div { min-width: 0; flex: 1 1 45%; }
}
