* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
:root {
  --primary: #1e6091;
  --primary-dark: #134b75;
  --accent: #2ca58d;
  --bg: #f4f6fa;
  --card: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --border: #e5e7eb;
  --danger: #dc2626;
  --warning: #d97706;
  --success: #059669;
}
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}
.hidden { display: none !important; }

/* LOGIN */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--primary) 0%, var(--accent) 100%);
  padding: 20px;
}
.login-card {
  background: #fff;
  padding: 40px;
  border-radius: 16px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.2);
  width: 100%;
  max-width: 400px;
}
.brand { text-align: center; margin-bottom: 30px; }
.logo {
  width: 72px; height: 72px;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  color: #fff;
  border-radius: 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 22px;
  letter-spacing: 1px;
  margin-bottom: 12px;
  box-shadow: 0 8px 20px rgba(30,96,145,0.3);
}
.brand h1 { font-size: 26px; color: var(--primary); letter-spacing: 2px; font-weight: 800; }
.brand p { color: var(--muted); font-size: 13px; margin-top: 4px; }
.login-card label {
  display: block;
  margin: 14px 0 6px;
  font-size: 13px;
  font-weight: 600;
}
.login-card input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
}
.login-card button {
  width: 100%;
  padding: 12px;
  background: var(--primary);
  color: #fff;
  border: 0;
  border-radius: 8px;
  font-weight: 600;
  font-size: 14px;
  margin-top: 20px;
  cursor: pointer;
}
.login-card button:hover { background: var(--primary-dark); }
.hint { text-align: center; color: var(--muted); font-size: 12px; margin-top: 14px; }
.install-btn {
  width: 100%;
  padding: 12px;
  margin-top: 14px;
  background: linear-gradient(135deg, var(--accent), #20917c);
  color: #fff;
  border: 0;
  border-radius: 8px;
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
  animation: pulse-install 2s infinite;
}
.install-btn:hover { opacity: 0.9; }
@keyframes pulse-install {
  0%,100% { box-shadow: 0 0 0 0 rgba(44,165,141,0.5); }
  50% { box-shadow: 0 0 0 8px rgba(44,165,141,0); }
}

@media (display-mode: standalone) {
  .install-btn { display: none !important; }
}

/* APP LAYOUT */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: 240px;
  background: #fff;
  border-right: 1px solid var(--border);
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
}
.sidebar-brand {
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 0 8px 20px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 14px;
}
.logo-sm {
  width: 42px; height: 42px;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  color: #fff;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-weight: 800;
  font-size: 13px;
  letter-spacing: 0.5px;
}
.sidebar-brand strong { display: block; font-size: 14px; }
.sidebar-brand small { color: var(--muted); font-size: 12px; }
.sidebar nav { flex: 1; display: flex; flex-direction: column; gap: 4px; }
.nav-item {
  display: block;
  padding: 10px 12px;
  border-radius: 8px;
  color: var(--text);
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
}
.nav-item:hover { background: var(--bg); }
.nav-item.active {
  background: var(--primary);
  color: #fff;
}
.logout {
  margin-top: 14px;
  padding: 10px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  color: var(--danger);
  font-weight: 600;
}

.main { flex: 1; display: flex; flex-direction: column; }
.topbar {
  background: #fff;
  padding: 16px 28px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.topbar h2 { font-size: 20px; }
.topbar small { color: var(--muted); }
.topbar-right { display: flex; align-items: center; gap: 20px; }
.bell { position: relative; font-size: 20px; cursor: pointer; }
.badge {
  position: absolute;
  top: -4px; right: -8px;
  background: var(--danger);
  color: #fff;
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 10px;
  font-weight: bold;
}
.user { display: flex; gap: 10px; align-items: center; }
.avatar {
  width: 40px; height: 40px;
  background: var(--accent);
  color: #fff;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-weight: bold;
}
.user strong { display: block; font-size: 13px; }
.user small { color: var(--muted); font-size: 11px; }

.content { padding: 24px 28px; flex: 1; }
.card {
  background: var(--card);
  border-radius: 12px;
  padding: 20px;
  margin-bottom: 20px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}
.card h3 { font-size: 16px; margin-bottom: 14px; }
.card-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
}
.card-head h3 { margin: 0; }

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}
@media (max-width: 900px) {
  .grid-2 { grid-template-columns: 1fr; }
  .sidebar { width: 70px; }
  .sidebar-brand small, .sidebar-brand strong { display: none; }
  .nav-item { text-align: center; font-size: 18px; padding: 12px 6px; }
}

/* STATS */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 20px;
}
.stat {
  background: #fff;
  border-radius: 12px;
  padding: 18px;
  display: flex;
  gap: 14px;
  align-items: center;
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}
.stat-ic {
  width: 48px; height: 48px;
  border-radius: 12px;
  background: var(--bg);
  display: flex; align-items: center; justify-content: center;
  font-size: 22px;
}
.stat small { color: var(--muted); font-size: 12px; }
.stat h3 { font-size: 18px; margin-top: 2px; }

/* LIST */
.list { list-style: none; }
.list li {
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.list li:last-child { border-bottom: 0; }
.list .time { color: var(--muted); font-size: 11px; display: block; margin-top: 2px; }

/* BUTTONS */
.btn {
  padding: 8px 14px;
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
}
.btn:hover { background: var(--bg); }
.btn-primary {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}
.btn-primary:hover { background: var(--primary-dark); }
.btn-sm { padding: 4px 10px; font-size: 12px; }

/* FORM */
label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin: 12px 0 6px;
}
input, select, textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
  font-family: inherit;
}
textarea { resize: vertical; }

/* CCTV */
.cctv-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 14px;
}
.cctv-cam {
  background: #000;
  border-radius: 10px;
  aspect-ratio: 16/9;
  position: relative;
  overflow: hidden;
  color: #fff;
}
.cctv-cam .overlay {
  position: absolute;
  top: 10px; left: 10px;
  background: rgba(0,0,0,0.6);
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 11px;
  display: flex; gap: 6px; align-items: center;
}
.cctv-cam .live-dot {
  width: 8px; height: 8px;
  background: var(--danger);
  border-radius: 50%;
  animation: blink 1s infinite;
}
@keyframes blink { 50% { opacity: 0.3; } }
.cctv-cam .stamp {
  position: absolute;
  bottom: 10px; right: 10px;
  background: rgba(0,0,0,0.6);
  padding: 3px 7px;
  border-radius: 4px;
  font-size: 11px;
  font-family: monospace;
}
.cctv-cam video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #000;
}
.cctv-cam .placeholder {
  width: 100%; height: 100%;
  background: repeating-linear-gradient(
    45deg,
    #1a1a1a,
    #1a1a1a 10px,
    #222 10px,
    #222 20px
  );
  display: flex; align-items: center; justify-content: center;
  font-size: 40px;
  opacity: 0.5;
}
.cctv-cam.offline .placeholder::after {
  content: "📵 OFFLINE";
  font-size: 14px;
  color: #888;
}
.cctv-cam.offline .live-dot { background: #666; animation: none; }

/* TABLE */
.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl th, .tbl td {
  padding: 10px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}
.tbl th { background: var(--bg); font-weight: 600; }

/* BADGES */
.badge-status {
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
}
.badge-status.lunas { background: #d1fae5; color: var(--success); }
.badge-status.belum { background: #fee2e2; color: var(--danger); }
.badge-status.proses { background: #fef3c7; color: var(--warning); }
.badge-status.selesai { background: #dbeafe; color: var(--primary); }

/* IURAN */
.iuran-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  gap: 10px;
  margin-top: 10px;
}
.iuran-month {
  padding: 12px;
  border-radius: 8px;
  text-align: center;
  border: 1px solid var(--border);
  font-size: 12px;
}
.iuran-month.lunas { background: #d1fae5; border-color: var(--success); color: var(--success); }
.iuran-month.belum { background: #fee2e2; border-color: var(--danger); color: var(--danger); }
.iuran-month.menunggu { background: #fef3c7; border-color: var(--warning); color: var(--warning); }
.iuran-month strong { display: block; font-size: 14px; margin-bottom: 4px; }

/* PAY METHODS */
.pay-methods { display: flex; gap: 10px; margin-top: 8px; }
.pay {
  flex: 1;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  text-align: center;
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
}
.pay input { display: none; }
.pay:has(input:checked) {
  border-color: var(--primary);
  background: #e0f2fe;
  color: var(--primary);
}

/* ANNOUNCEMENT / LAPORAN */
.announce-item, .lapor-item, .agenda-item, .surat-item {
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 10px;
}
.announce-item h4, .lapor-item h4, .agenda-item h4, .surat-item h4 {
  font-size: 14px;
  margin-bottom: 6px;
}
.meta { color: var(--muted); font-size: 11px; margin-bottom: 8px; }
.muted { color: var(--muted); font-size: 12px; }

/* MODAL */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}
.modal-card {
  background: #fff;
  border-radius: 16px;
  padding: 28px;
  max-width: 380px;
  width: 90%;
  text-align: center;
}
.modal-card h3 { margin-bottom: 16px; }
.qris-box { margin: 20px 0; }
.qris-mock {
  width: 200px; height: 200px;
  margin: 0 auto 12px;
  padding: 16px;
  background: #fff;
  border: 2px solid var(--primary);
  border-radius: 12px;
}
.qr-pattern {
  width: 100%;
  height: 160px;
  background:
    repeating-conic-gradient(#000 0% 25%, #fff 0% 50%) 0 0 / 16px 16px,
    repeating-linear-gradient(90deg, #000 0 4px, transparent 4px 8px);
  background-blend-mode: multiply;
  margin-bottom: 6px;
}
.modal-actions { display: flex; gap: 10px; justify-content: center; }

.admin-only { display: none; }
body.is-admin .admin-only { display: inline-block; }

/* SPONSOR FOOTER */
.sponsor-footer {
  background: #fff;
  border-top: 1px solid var(--border);
  padding: 24px 28px 20px;
  margin-top: auto;
}
.sponsor-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}
.sponsor-head h4 {
  font-size: 13px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 1px;
  font-weight: 600;
}
.sponsor-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}
.sponsor-item {
  aspect-ratio: 16/9;
  background: var(--bg);
  border: 1px dashed var(--border);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10px;
  text-align: center;
  overflow: hidden;
  position: relative;
  transition: all 0.2s;
}
.sponsor-item:hover {
  border-style: solid;
  border-color: var(--primary);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0,0,0,0.08);
}
.sponsor-item a {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  text-decoration: none;
}
.sponsor-item img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}
.sponsor-item.empty {
  color: var(--muted);
  font-size: 11px;
  opacity: 0.6;
}
.copyright {
  text-align: center;
  color: var(--muted);
  font-size: 11px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.logout-mobile {
  display: none;
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 8px;
  font-size: 16px;
  cursor: pointer;
  color: var(--danger);
}

/* ============================================================
   MOBILE RESPONSIVE — harus di paling bawah supaya override
   ============================================================ */
@media (max-width: 768px) {
  /* Layout: sidebar jadi bottom tab bar */
  .app {
    flex-direction: column-reverse;
    min-height: 100vh;
    min-height: 100dvh;
  }
  .sidebar {
    width: 100%;
    flex-direction: row;
    padding: 4px 4px calc(4px + env(safe-area-inset-bottom, 0px));
    border-right: 0;
    border-top: 1px solid var(--border);
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 100;
    background: #fff;
    box-shadow: 0 -2px 10px rgba(0,0,0,0.08);
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
  }
  .sidebar-brand { display: none; }
  .sidebar nav {
    flex-direction: row;
    gap: 0;
    flex-shrink: 0;
    min-width: max-content;
  }
  .nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 6px 10px;
    font-size: 20px;
    white-space: nowrap;
    border-radius: 8px;
    text-align: center;
    min-width: 52px;
    flex-shrink: 0;
  }
  .nav-item.active {
    background: #e0f2fe;
    color: var(--primary);
  }
  .logout {
    display: none;
  }
  .logout-mobile {
    display: block;
  }

  /* Main content needs bottom padding for tab bar */
  .main {
    padding-bottom: 70px;
  }

  /* Top bar compact */
  .topbar {
    padding: 10px 16px;
    padding-top: calc(10px + env(safe-area-inset-top, 0px));
    flex-wrap: wrap;
    gap: 8px;
  }
  .topbar h2 { font-size: 16px; }
  .topbar small { font-size: 11px; }
  .topbar-right { gap: 12px; }
  .user strong { font-size: 12px; }
  .user small { font-size: 10px; }
  .avatar { width: 32px; height: 32px; font-size: 13px; }

  /* Content */
  .content { padding: 12px 14px; }

  /* Stats 2x2 grid */
  .stat-grid { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .stat { padding: 12px; gap: 10px; }
  .stat-ic { width: 36px; height: 36px; font-size: 18px; }
  .stat h3 { font-size: 15px; }
  .stat small { font-size: 11px; }

  /* Cards */
  .card { padding: 14px; margin-bottom: 14px; }
  .card h3 { font-size: 14px; }
  .card-head { flex-direction: column; gap: 8px; align-items: flex-start; }

  /* Two column to single */
  .grid-2 { grid-template-columns: 1fr; gap: 14px; }
  .cctv-grid { grid-template-columns: 1fr; }

  /* Pay methods */
  .pay-methods { flex-direction: column; gap: 8px; }

  /* Tables scroll */
  .tbl { font-size: 11px; }
  .tbl th, .tbl td { padding: 7px 6px; }
  table.tbl { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; }

  /* Iuran grid */
  .iuran-grid { grid-template-columns: repeat(4, 1fr); gap: 6px; }
  .iuran-month { padding: 8px 4px; font-size: 11px; }
  .iuran-month strong { font-size: 12px; }

  /* Sponsors */
  .sponsor-footer { padding: 16px 14px 12px; }
  .sponsor-grid { grid-template-columns: repeat(3, 1fr); gap: 8px; }
  .sponsor-head h4 { font-size: 11px; }

  /* Modal full-width on mobile */
  .modal-card { max-width: 95vw; padding: 16px; }

  /* Forms */
  input, select, textarea { font-size: 16px; padding: 10px 12px; }

  /* Login adjustments */
  .login-card { padding: 28px 24px; }
  .brand h1 { font-size: 22px; }
}

/* Extra small phones */
@media (max-width: 380px) {
  .stat-grid { grid-template-columns: 1fr; }
  .iuran-grid { grid-template-columns: repeat(3, 1fr); }
  .sponsor-grid { grid-template-columns: repeat(2, 1fr); }
  .nav-item { font-size: 18px; padding: 4px 1px; }
}
