:root {
  --grad: linear-gradient(135deg, #6d28d9 0%, #4f46e5 55%, #2563eb 100%);
  --primary: #4f46e5;
  --primary-dark: #4338ca;
  --bg: #f1f2f9;
  --card: #ffffff;
  --text: #1e1b34;
  --muted: #6f6c8a;
  --border: #e6e4f2;
  --danger: #dc2626;
  --ok: #16a34a;
  --warn: #d97706;
  --radius: 16px;
  --shadow: 0 4px 20px rgba(79, 70, 229, .08);
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: 'Segoe UI', system-ui, sans-serif; background: var(--bg); color: var(--text); min-height: 100vh; }

/* ===== Susun atur sidebar ===== */
.shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 250px; flex-shrink: 0; position: sticky; top: 0; height: 100vh;
  background: linear-gradient(135deg, #6d28d9 0%, #4f46e5 55%, #2563eb 100%);
  color: #fff; padding: 22px 16px; display: flex; flex-direction: column; gap: 20px;
}
.side-brand { font-size: 1.25rem; font-weight: 300; letter-spacing: .5px; padding: 0 8px; }
.side-brand b { font-weight: 800; }
.side-user { display: flex; align-items: center; gap: 10px; background: rgba(255,255,255,.14); border-radius: 14px; padding: 10px 12px; }
.avatar {
  width: 40px; height: 40px; border-radius: 50%; flex-shrink: 0;
  background: rgba(255,255,255,.25); display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 1.1rem;
}
.side-user-name { font-weight: 600; font-size: .88rem; line-height: 1.2; margin-bottom: 3px; }
.side-nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.side-nav a, .side-bottom a {
  display: flex; align-items: center; gap: 12px; color: rgba(255,255,255,.88);
  text-decoration: none; padding: 11px 14px; border-radius: 12px;
  font-size: .92rem; font-weight: 600; transition: background .15s;
}
.side-nav a:hover, .side-bottom a:hover { background: rgba(255,255,255,.14); color: #fff; }
.side-nav a.active { background: rgba(255,255,255,.22); color: #fff; box-shadow: inset 0 0 0 1px rgba(255,255,255,.25); }
.nav-ico { width: 22px; text-align: center; }
.side-bottom { border-top: 1px solid rgba(255,255,255,.2); padding-top: 10px; }

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.main-public { min-height: 100vh; background: linear-gradient(135deg, #6d28d9 0%, #4f46e5 55%, #2563eb 100%); }
.topbar { background: var(--card); border-bottom: 1px solid var(--border); padding: 16px 28px; position: sticky; top: 0; z-index: 10; }
.page-title { font-size: 1.15rem; font-weight: 700; color: var(--primary-dark); }
.content { padding: 24px 28px; max-width: 1200px; width: 100%; margin: 0 auto; flex: 1; }
.footer { text-align: center; padding: 14px; color: var(--muted); font-size: .82rem; }

/* ===== Kad ===== */
.card {
  background: var(--card); border-radius: var(--radius); padding: 22px;
  box-shadow: var(--shadow); border: 1px solid var(--border); margin-bottom: 20px;
}
.auth-card { max-width: 470px; margin: 7vh auto; border: none; box-shadow: 0 20px 60px rgba(0,0,20,.35); }
.auth-card h1 { text-align: center; font-size: 1.6rem; color: var(--primary); }
.auth-card p.muted { text-align: center; margin-bottom: 16px; }

h1 { margin-bottom: 12px; font-size: 1.35rem; }
.content h1 { display: none; } /* tajuk dipaparkan dalam topbar */
h2 { font-size: 1rem; margin-bottom: 14px; color: var(--primary-dark); }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; align-items: start; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }
@media (max-width: 900px) {
  .shell { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
}

.nav-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px; margin-bottom: 20px; }
.nav-card { text-decoration: none; color: var(--text); transition: transform .12s, box-shadow .12s; }
.nav-card:hover { transform: translateY(-3px); box-shadow: 0 10px 26px rgba(79,70,229,.18); }

/* ===== Borang ===== */
label { display: block; margin-bottom: 12px; font-size: .85rem; font-weight: 600; color: #3d3a5c; }
input, select, textarea {
  width: 100%; padding: 10px 14px; margin-top: 5px;
  border: 1.5px solid var(--border); border-radius: 12px; font-size: .95rem; font-family: inherit;
  background: #fafaff; transition: border .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(79,70,229,.12); background: #fff;
}
.checkbox-list { display: flex; flex-wrap: wrap; gap: 10px 18px; margin: 6px 0 14px; }
label.checkbox { display: flex; align-items: center; gap: 6px; font-weight: 400; }
label.checkbox input { width: auto; margin: 0; }

/* ===== Butang ===== */
.btn {
  display: inline-block; padding: 10px 18px; border: none; border-radius: 12px;
  background: #eceafd; color: var(--primary-dark); font-size: .9rem; font-weight: 700;
  cursor: pointer; text-decoration: none; font-family: inherit; transition: filter .15s;
}
.btn:hover { filter: brightness(.96); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: linear-gradient(135deg, #6d28d9, #4f46e5, #2563eb); color: #fff; box-shadow: 0 4px 14px rgba(79,70,229,.35); }
.btn-primary:hover { filter: brightness(1.08); }
.btn-danger { background: linear-gradient(135deg, #ef4444, #dc2626); color: #fff; }
.btn-sm { padding: 6px 12px; font-size: .8rem; border-radius: 10px; }
.btn-block { width: 100%; margin-top: 6px; }
.actions form { display: inline-flex; gap: 6px; }

/* ===== Jadual ===== */
table { width: 100%; border-collapse: collapse; font-size: .86rem; }
th { text-align: left; padding: 10px; background: #f6f5fd; border-bottom: 2px solid var(--border); font-size: .74rem; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); }
td { padding: 10px; border-bottom: 1px solid #f1effa; vertical-align: top; }
tr:hover td { background: #faf9ff; }

/* ===== Alert & tag ===== */
.alert { padding: 13px 16px; border-radius: 12px; margin-bottom: 14px; font-size: .9rem; border: 1px solid transparent; }
.alert-success { background: #e8faf0; color: #14532d; border-color: #bbf0d3; }
.alert-error { background: #feecec; color: #7f1d1d; border-color: #fbcfcf; }
.alert-info { background: #eef0ff; color: #312e81; border-color: #d8dcff; }

.muted { color: var(--muted); font-size: .9rem; }
.tag { display: inline-block; padding: 3px 11px; border-radius: 999px; font-size: .74rem; font-weight: 700; background: #eceafd; color: var(--primary-dark); }
.tag-ok { background: #e8faf0; color: #14532d; }
.tag-warn { background: #fef6e0; color: #92400e; }
.tag-expired { background: #feecec; color: #7f1d1d; }
.role-admin { background: rgba(255,255,255,.25); color: #fff; }
.role-organizer { background: #fef6e0; color: #92400e; }
.role-staff { background: #e8faf0; color: #14532d; }

/* ===== Statistik ===== */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 14px; margin-bottom: 20px; }
.stat {
  background: var(--card); border-radius: var(--radius); padding: 18px; text-align: center;
  box-shadow: var(--shadow); border: 1px solid var(--border); font-size: .82rem; color: var(--muted);
  position: relative; overflow: hidden;
}
.stat::before { content: ''; position: absolute; top: 0; left: 0; right: 0; height: 4px; background: linear-gradient(90deg, #6d28d9, #2563eb); }
.stat b { display: block; font-size: 1.7rem; margin: 4px 0; color: var(--primary); }

/* ===== QR ===== */
.qr-card { text-align: center; background: linear-gradient(180deg, #fbfaff, #fff); }
#qrcode { display: inline-block; margin: 12px 0; padding: 12px; background: #fff; border: 1.5px solid var(--border); border-radius: 14px; }
details { margin-top: 12px; text-align: left; }
summary { cursor: pointer; color: var(--primary); font-weight: 600; font-size: .9rem; }
hr { border: none; border-top: 1px solid var(--border); margin: 16px 0; }

/* ===== AJAX IC & modal ===== */
.ic-status { min-height: 18px; font-size: .82rem; margin-top: 4px; }
.ic-warn { color: #dc2626; }
.ic-ok { color: #16a34a; }

.modal-overlay { position: fixed; inset: 0; background: rgba(20,16,50,.5); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 16px; }
.modal { position: relative; max-width: 470px; width: 100%; max-height: 85vh; overflow: auto; }
.modal-close { position: absolute; top: 8px; right: 10px; border: none; background: none; font-size: 1.4rem; cursor: pointer; color: var(--muted); }
.detail-table { width: 100%; margin-top: 8px; }
.detail-table th { width: 38%; }
.p-link { color: var(--primary); text-decoration: none; border-bottom: 1px dashed var(--primary); cursor: pointer; }
.p-link:hover { opacity: .75; }
