:root {
  --primary: #6366f1;
  --primary-dark: #4f46e5;
  --primary-light: #eef2ff;
  --green: #10b981;
  --orange: #f59e0b;
  --purple: #8b5cf6;
  --red: #ef4444;
  --bg: #f8fafc;
  --card-bg: #ffffff;
  --border: #e2e8f0;
  --text: #1e293b;
  --text-muted: #64748b;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(0,0,0,.06), 0 1px 2px rgba(0,0,0,.04);
  --shadow-lg: 0 10px 25px -5px rgba(0,0,0,.1), 0 8px 10px -6px rgba(0,0,0,.05);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
}

/* ---------- Layout ---------- */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 240px;
  background: linear-gradient(180deg, #1e1b4b 0%, #312e81 100%);
  color: #e0e7ff;
  display: flex;
  flex-direction: column;
  padding: 20px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand { display: flex; align-items: center; gap: 10px; padding: 8px 10px 24px; }
.brand-icon { font-size: 26px; }
.brand-text { font-size: 20px; font-weight: 700; color: #fff; }

.nav-link {
  display: flex; align-items: center; gap: 12px;
  color: #c7d2fe; text-decoration: none;
  padding: 11px 14px; border-radius: 10px; margin-bottom: 4px;
  font-size: 14.5px; font-weight: 500;
  transition: background .15s, color .15s, transform .1s;
}
.nav-link:hover { background: rgba(255,255,255,.08); color: #fff; transform: translateX(2px); }
.nav-link.active { background: #fff; color: var(--primary-dark); font-weight: 600; }
.nav-icon { font-size: 17px; }

.sidebar-footer { margin-top: auto; padding-top: 16px; border-top: 1px solid rgba(255,255,255,.12); }
.user-chip { display: flex; align-items: center; gap: 8px; padding: 8px 10px; }
.avatar { width: 28px; height: 28px; border-radius: 50%; object-fit: cover; }
.avatar-wrap { position: relative; flex-shrink: 0; }
.avatar-initials {
  width: 28px; height: 28px; border-radius: 50%;
  background: #4caf50; /* fallback hijau Google — di-override JS */
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700; text-transform: uppercase;
  flex-shrink: 0; user-select: none;
}
.user-name { font-size: 13px; color: #e0e7ff; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.logout-btn {
  display: block; text-align: center; margin-top: 8px;
  color: #fca5a5; text-decoration: none; font-size: 13px; padding: 8px;
  border-radius: 8px; transition: background .15s;
}
.logout-btn:hover { background: rgba(239,68,68,.15); }

.content { flex: 1; padding: 32px 40px; max-width: 1100px; }

.mobile-menu-btn { display: none; }

/* ---------- Page header ---------- */
.page-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 24px; flex-wrap: wrap; gap: 12px;
}
.page-header h1 { margin: 0 0 4px; font-size: 26px; }
.page-subtitle { margin: 0; color: var(--text-muted); font-size: 14.5px; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  border: none; border-radius: 10px; padding: 10px 18px;
  font-size: 14px; font-weight: 600; cursor: pointer;
  transition: transform .1s ease, box-shadow .15s ease, background .15s ease;
  text-decoration: none;
}
.btn:active { transform: scale(.96); }
.btn-primary { background: var(--primary); color: #fff; box-shadow: 0 2px 8px rgba(99,102,241,.35); }
.btn-primary:hover { background: var(--primary-dark); box-shadow: 0 4px 14px rgba(99,102,241,.45); }
.btn-ghost { background: var(--primary-light); color: var(--primary-dark); }
.btn-ghost:hover { background: #e0e7ff; }
.btn-danger { background: #fef2f2; color: var(--red); }
.btn-danger:hover { background: #fee2e2; }
.btn-sm { padding: 6px 12px; font-size: 12.5px; }
.btn-lg { padding: 16px 32px; font-size: 17px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.btn-draw {
  background: linear-gradient(135deg, var(--primary), var(--purple));
  width: 100%; margin-top: 14px; font-size: 18px;
  box-shadow: 0 4px 16px rgba(139,92,246,.35);
}
.btn-draw:hover:not(:disabled) { transform: translateY(-2px); box-shadow: 0 8px 24px rgba(139,92,246,.45); }
.btn-draw.drawing { animation: shake .4s infinite; }
@keyframes shake {
  0%,100% { transform: rotate(0deg); }
  25% { transform: rotate(-4deg); }
  75% { transform: rotate(4deg); }
}

/* ---------- Cards ---------- */
.card {
  background: var(--card-bg); border-radius: var(--radius);
  padding: 22px 24px; box-shadow: var(--shadow); margin-bottom: 24px;
  border: 1px solid var(--border);
  overflow-x: auto;          /* tabel tidak melewati bingkai di mobile */
}
.card-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.card-header h2 { margin: 0; font-size: 17px; }
.highlight-card { border: 2px solid var(--primary); box-shadow: 0 0 0 4px var(--primary-light); }
.muted { color: var(--text-muted); font-weight: 400; font-size: 13px; }

/* ---------- Stat grid ---------- */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px,1fr)); gap: 18px; margin-bottom: 24px; }
.stat-card {
  background: var(--card-bg); border-radius: var(--radius); padding: 20px;
  box-shadow: var(--shadow); border: 1px solid var(--border);
  border-left: 4px solid var(--primary);
}
.stat-blue { border-left-color: var(--primary); }
.stat-green { border-left-color: var(--green); }
.stat-purple { border-left-color: var(--purple); }
.stat-orange { border-left-color: var(--orange); }
.stat-icon { font-size: 24px; margin-bottom: 6px; }
.stat-value { font-size: 24px; font-weight: 700; }
.stat-label { color: var(--text-muted); font-size: 13px; margin-top: 2px; }

.fade-in { animation: fadeIn .4s ease both; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

/* ---------- Tables ---------- */
.table { width: 100%; border-collapse: collapse; min-width: 480px; }
.table th {
  text-align: left; font-size: 12.5px; text-transform: uppercase; letter-spacing: .03em;
  color: var(--text-muted); padding: 10px 12px; border-bottom: 2px solid var(--border);
}
.table td { padding: 12px; border-bottom: 1px solid var(--border); font-size: 14.5px; }
.table tr:last-child td { border-bottom: none; }
.table tr:hover td { background: #fafbff; }
.col-actions { text-align: right; white-space: nowrap; }
.inline-form { display: inline-block; margin-left: 6px; }

.badge {
  background: var(--primary-light); color: var(--primary-dark);
  padding: 3px 10px; border-radius: 20px; font-size: 12.5px; font-weight: 600;
}

.empty-state { color: var(--text-muted); text-align: center; padding: 30px 10px; font-size: 14.5px; }

/* ---------- Forms ---------- */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 13.5px; font-weight: 600; margin-bottom: 6px; color: var(--text); }
.form-group input, .form-group select {
  width: 100%; padding: 10px 12px; border-radius: 9px; border: 1.5px solid var(--border);
  font-size: 14.5px; transition: border-color .15s, box-shadow .15s;
  font-family: inherit;
}
.form-group input:focus, .form-group select:focus {
  outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-light);
}
.checkbox-row { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--text-muted); margin-bottom: 6px; }
.checkbox-row input { width: auto; }

.search-bar { display: flex; gap: 10px; margin-bottom: 18px; max-width: 420px; }
.search-bar input {
  flex: 1; padding: 10px 14px; border-radius: 9px; border: 1.5px solid var(--border); font-size: 14px;
}
.search-bar input:focus { outline: none; border-color: var(--primary); }

.hint-text { font-size: 13px; color: var(--text-muted); margin-top: 8px; text-align: center; }

.jumlah-form { display: flex; gap: 6px; align-items: center; }
.jumlah-input { width: 130px; padding: 6px 10px; border-radius: 8px; border: 1.5px solid var(--border); }

/* ---------- Modal ---------- */
.modal-overlay {
  display: none; position: fixed; inset: 0; background: rgba(15,23,42,.5);
  align-items: center; justify-content: center; z-index: 300; padding: 20px;
  animation: overlayIn .15s ease;
}
.modal-overlay.open { display: flex; }
@keyframes overlayIn { from { opacity: 0; } to { opacity: 1; } }
.modal {
  background: #fff; border-radius: 16px; padding: 24px; width: 100%; max-width: 420px;
  box-shadow: var(--shadow-lg); animation: modalIn .18s ease;
}
@keyframes modalIn { from { opacity: 0; transform: scale(.94) translateY(10px); } to { opacity: 1; transform: scale(1) translateY(0); } }
.modal-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.modal-header h3 { margin: 0; font-size: 18px; }
.modal-close { background: none; border: none; font-size: 18px; cursor: pointer; color: var(--text-muted); padding: 4px 8px; border-radius: 6px; }
.modal-close:hover { background: var(--bg); }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }

/* ---------- Draw panel ---------- */
.draw-panel { text-align: center; }
.draw-info { display: flex; justify-content: center; gap: 36px; margin-bottom: 20px; flex-wrap: wrap; }
.draw-info-item { display: flex; flex-direction: column; }
.draw-info-label { font-size: 12.5px; color: var(--text-muted); }
.draw-info-value { font-size: 26px; font-weight: 700; color: var(--primary); }

/* ---------- Quick actions ---------- */
.quick-actions { display: flex; gap: 14px; flex-wrap: wrap; }
.quick-action {
  flex: 1; min-width: 160px; text-align: center; padding: 16px;
  background: #fff; border: 1.5px solid var(--border); border-radius: var(--radius);
  text-decoration: none; color: var(--text); font-weight: 600; font-size: 14.5px;
  box-shadow: var(--shadow); transition: transform .15s, box-shadow .15s;
}
.quick-action:hover { transform: translateY(-3px); box-shadow: var(--shadow-lg); }
.quick-action-primary { background: linear-gradient(135deg, var(--primary), var(--purple)); color: #fff; }

/* ---------- Login page ---------- */
.login-page {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #1e1b4b 0%, #6366f1 50%, #8b5cf6 100%);
  padding: 20px;
}
.login-card {
  background: #fff; border-radius: 20px; padding: 40px 36px; max-width: 380px; width: 100%;
  text-align: center; box-shadow: var(--shadow-lg); animation: modalIn .3s ease;
}
.login-icon { font-size: 48px; margin-bottom: 8px; }
.login-card h1 { margin: 0 0 8px; font-size: 26px; }
.subtitle { color: var(--text-muted); font-size: 14.5px; margin-bottom: 26px; }
.google-btn {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  background: #fff; border: 1.5px solid var(--border); border-radius: 10px;
  padding: 12px; font-weight: 600; font-size: 14.5px; color: var(--text);
  text-decoration: none; transition: box-shadow .15s, transform .1s;
}
.google-btn:hover { box-shadow: var(--shadow-lg); transform: translateY(-1px); }
.alert { padding: 10px 14px; border-radius: 9px; font-size: 13.5px; margin-bottom: 16px; text-align: left; }
.alert-error { background: #fef2f2; color: var(--red); }
.alert-warn { background: #fffbeb; color: #92400e; }
.alert-warn code { background: rgba(0,0,0,.06); padding: 2px 5px; border-radius: 4px; }

/* ---------- Responsive ---------- */
@media (max-width: 860px) {
  .sidebar {
    position: fixed; left: -260px; top: 0; z-index: 200; transition: left .2s ease;
    box-shadow: var(--shadow-lg);
  }
  .sidebar.open { left: 0; }
  .content { padding: 20px 16px; width: 100%; }
  .mobile-menu-btn {
    display: inline-flex; background: var(--card-bg); border: 1px solid var(--border);
    border-radius: 8px; padding: 8px 12px; font-size: 18px; margin-bottom: 16px; cursor: pointer;
  }

  /* Tabel responsive di mobile */
  .card { padding: 14px 12px; }
  .table th { font-size: 11px; padding: 8px 8px; }
  .table td { font-size: 13px; padding: 8px 8px; }
  .table .col-actions { white-space: nowrap; }

  /* Stat grid 2 kolom di mobile */
  .stat-grid { grid-template-columns: repeat(2, 1fr); gap: 12px; }
  .stat-value { font-size: 20px; }

  /* Form search bar full width */
  .search-bar { max-width: 100%; }

  /* Page header stack di mobile */
  .page-header { flex-direction: column; align-items: flex-start; gap: 8px; }
}

/* ===== Periode Selector (sidebar) ===== */
.periode-selector {
  margin-bottom: 14px;
  padding: 10px 10px 12px;
  background: rgba(255,255,255,.06);
  border-radius: 10px;
  border: 1px solid rgba(255,255,255,.1);
}
.periode-label {
  font-size: 11px; color: #a5b4fc; text-transform: uppercase;
  letter-spacing: .07em; margin-bottom: 6px; font-weight: 600;
}
.periode-select {
  width: 100%; padding: 7px 10px; border-radius: 8px;
  border: 1.5px solid rgba(255,255,255,.2);
  background: rgba(255,255,255,.1); color: #e0e7ff;
  font-size: 13.5px; font-family: inherit; cursor: pointer;
}
.periode-select:focus { outline: none; border-color: #a5b4fc; }
.periode-select option { background: #1e1b4b; color: #e0e7ff; }
.periode-closed-badge {
  margin-top: 6px; font-size: 11.5px; color: #fca5a5;
  text-align: center; font-weight: 600;
}
