*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --paper: #fafaf9;
  --surface: #f5f5f4;
  --surface-2: #e7e5e4;
  --border: #d6d3d1;
  --text: #292524;
  --text-2: #78716c;
  --text-3: #a8a29e;
  --accent: #0284c7;
  --accent-hover: #0369a1;
  --accent-light: #e0f2fe;
  --success: #16a34a;
  --success-light: #dcfce7;
  --warning: #d97706;
  --warning-light: #fef3c7;
  --danger: #dc2626;
  --danger-light: #fee2e2;
  --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.07), 0 2px 4px rgba(0,0,0,0.06);
  --radius: 8px;
  --radius-sm: 6px;
  --sidebar-width: 240px;
  --topbar-height: 56px;
  --bottom-nav-height: 64px;
}

html, body {
  height: 100%;
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  color: var(--text);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  overflow-x: hidden;
}

#app {
  display: flex;
  min-height: 100vh;
  width: 100%;
  max-width: 100vw;
  overflow-x: hidden;
}

/* ===== LOGIN SCREEN ===== */
.login-screen {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--paper);
  padding: 24px;
  z-index: 300;
}

.login-card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 32px;
  width: 100%;
  max-width: 400px;
  box-shadow: var(--shadow-md);
}

.login-header {
  text-align: center;
  margin-bottom: 24px;
}

.login-header svg {
  margin-bottom: 12px;
}

.login-header h1 {
  font-size: 24px;
  font-weight: 700;
  color: var(--text);
}

.login-subtitle {
  font-size: 14px;
  color: var(--text-3);
  margin-top: 4px;
}

.login-tabs {
  display: flex;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  margin-bottom: 20px;
}

.login-tab {
  flex: 1;
  padding: 10px;
  border: none;
  background: #fff;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-2);
  cursor: pointer;
  transition: all 0.15s;
}

.login-tab.active {
  background: var(--accent);
  color: #fff;
}

.login-form {
  transition: opacity 0.15s;
}

.login-hint {
  font-size: 12px;
  color: var(--text-3);
  margin-top: -8px;
  margin-bottom: 16px;
}

.login-error {
  color: var(--danger);
  font-size: 13px;
  font-weight: 500;
  margin-top: 12px;
  text-align: center;
}

.btn-block {
  width: 100%;
  justify-content: center;
}

/* ===== SIDEBAR ===== */
.sidebar {
  width: var(--sidebar-width);
  background: #fff;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  height: 100vh;
  z-index: 100;
  transition: transform 0.25s ease;
  -webkit-overflow-scrolling: touch;
}

.sidebar-header {
  padding: 16px;
  border-bottom: 1px solid var(--border);
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
}

.sidebar-nav {
  flex: 1;
  padding: 8px;
  overflow-y: auto;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-2);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  transition: all 0.15s;
  margin-bottom: 2px;
  min-height: 44px;
}

.nav-item:hover {
  background: var(--surface);
  color: var(--text);
}

.nav-item.active {
  background: var(--accent-light);
  color: var(--accent);
  font-weight: 600;
}

/* ===== MAIN CONTENT ===== */
.main-content {
  margin-left: var(--sidebar-width);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  max-width: calc(100vw - var(--sidebar-width));
}

.topbar {
  height: var(--topbar-height);
  display: flex;
  align-items: center;
  padding: 0 24px;
  background: #fff;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 50;
  gap: 8px;
}

.topbar-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.menu-toggle {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-2);
  padding: 8px;
  margin-right: 4px;
  border-radius: var(--radius-sm);
  flex-shrink: 0;
}

.menu-toggle:hover { background: var(--surface); }

.page-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex-shrink: 1;
  min-width: 0;
}

.role-badge {
  font-size: 12px;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 999px;
  white-space: nowrap;
}

.role-badge-admin {
  background: var(--accent-light);
  color: var(--accent);
}

.role-badge-warga {
  background: var(--surface-2);
  color: var(--text-2);
}

.logout-btn {
  flex-shrink: 0;
}

.page-content {
  flex: 1;
  padding: 24px;
  max-width: 1200px;
  width: 100%;
  overflow-x: hidden;
}

/* ===== BOTTOM NAV (mobile) ===== */
.bottom-nav {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--bottom-nav-height);
  background: #fff;
  border-top: 1px solid var(--border);
  z-index: 100;
  justify-content: space-around;
  align-items: center;
  padding: 4px 0 env(safe-area-inset-bottom, 4px);
}

.bottom-nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  text-decoration: none;
  color: var(--text-3);
  font-size: 10px;
  font-weight: 500;
  padding: 4px 4px;
  border-radius: var(--radius-sm);
  transition: color 0.15s;
  -webkit-tap-highlight-color: transparent;
  min-width: 0;
  max-width: 72px;
}

.bottom-nav-item svg {
  display: block;
  width: 22px;
  height: 22px;
}

.bottom-nav-item span {
  display: block;
  line-height: 1.2;
  text-align: center;
  font-size: 10px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  width: 100%;
}

.bottom-nav-item.active {
  color: var(--accent);
}

/* ===== CARDS ===== */
.card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  flex-wrap: wrap;
  gap: 8px;
}

.card-title {
  font-size: 16px;
  font-weight: 700;
}

/* ===== GRID ===== */
.grid {
  display: grid;
  gap: 16px;
}

.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }

/* ===== STATS CARDS ===== */
.stat-card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}

.stat-card .stat-label {
  font-size: 13px;
  color: var(--text-2);
  font-weight: 500;
  margin-bottom: 4px;
}

.stat-card .stat-value {
  font-size: 28px;
  font-weight: 700;
  color: var(--text);
  word-break: break-word;
}

.stat-card .stat-sub {
  font-size: 12px;
  color: var(--text-3);
  margin-top: 4px;
}

/* ===== TABLES ===== */
.table-container {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 0 -4px;
  padding: 0 4px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
  min-width: 600px;
}

th {
  text-align: left;
  padding: 10px 12px;
  font-weight: 600;
  color: var(--text-2);
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
}

th:hover { color: var(--text); }

td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--surface-2);
  word-break: break-word;
}

tr:hover { background: var(--surface); }

/* ===== BADGES ===== */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}

.badge-success { background: var(--success-light); color: var(--success); }
.badge-warning { background: var(--warning-light); color: var(--warning); }
.badge-danger { background: var(--danger-light); color: var(--danger); }
.badge-info { background: var(--accent-light); color: var(--accent); }

/* ===== BUTTONS ===== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.15s;
  text-decoration: none;
  white-space: nowrap;
  min-height: 44px;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.btn-primary:hover { background: var(--accent-hover); }

.btn-secondary {
  background: #fff;
  color: var(--text);
  border-color: var(--border);
}
.btn-secondary:hover { background: var(--surface); }

.btn-danger {
  background: var(--danger);
  color: #fff;
  border-color: var(--danger);
}
.btn-danger:hover { background: #b91c1c; }

.btn-sm {
  padding: 4px 10px;
  font-size: 13px;
  min-height: 32px;
}

.btn-icon {
  padding: 6px;
  border: none;
  background: none;
  cursor: pointer;
  color: var(--text-2);
  border-radius: var(--radius-sm);
  min-height: 36px;
  min-width: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.btn-icon:hover { background: var(--surface); color: var(--text); }
.btn-icon.danger:hover { background: var(--danger-light); color: var(--danger); }

/* ===== FORMS ===== */
.form-group {
  margin-bottom: 16px;
}

.form-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 4px;
}

.form-input, .form-select, .form-textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-family: inherit;
  color: var(--text);
  background: #fff;
  transition: border-color 0.15s;
  min-height: 44px;
}

.form-input:focus, .form-select:focus, .form-textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-light);
}

.form-textarea {
  resize: vertical;
  min-height: 80px;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.form-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 20px;
  flex-wrap: wrap;
}

/* ===== MODAL ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal {
  background: #fff;
  border-radius: var(--radius);
  width: 100%;
  max-width: 520px;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: var(--shadow-md);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  gap: 8px;
}

.modal-title {
  font-size: 16px;
  font-weight: 700;
}

.modal-body {
  padding: 20px;
}

.modal-footer {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  padding: 12px 20px;
  border-top: 1px solid var(--border);
  flex-wrap: wrap;
}

/* ===== EMPTY STATE ===== */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-3);
}

.empty-state svg {
  margin-bottom: 12px;
  opacity: 0.5;
}

.empty-state h3 {
  font-size: 16px;
  color: var(--text-2);
  margin-bottom: 4px;
}

.empty-state p {
  font-size: 14px;
  margin-bottom: 16px;
}

/* ===== FILTER BAR ===== */
.filter-bar {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  flex-wrap: wrap;
  align-items: center;
}

.filter-bar .form-input,
.filter-bar .form-select {
  width: auto;
  min-width: 160px;
}

/* ===== PENGATURAN (settings) page ===== */
.pengaturan-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 12px;
}

.pengaturan-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 24px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  text-decoration: none;
  color: var(--text);
  font-weight: 500;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.15s;
  box-shadow: var(--shadow);
}

.pengaturan-card:hover {
  border-color: var(--accent);
  color: var(--accent);
  box-shadow: var(--shadow-md);
}

/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
  }
  .sidebar.open {
    transform: translateX(0);
  }
  .sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.3);
    z-index: 99;
  }
  .sidebar-overlay.visible {
    display: block;
  }
  .main-content {
    margin-left: 0;
    padding-bottom: calc(var(--bottom-nav-height) + env(safe-area-inset-bottom, 0px));
    max-width: 100vw;
  }
  .menu-toggle { display: block; }
  .bottom-nav { display: flex; }
  .page-content {
    padding: 16px;
  }
  .page-title {
    font-size: 16px;
  }
  .grid-2, .grid-3, .grid-4 {
    grid-template-columns: 1fr;
  }
  .form-row {
    grid-template-columns: 1fr;
  }
  .filter-bar .form-input, .filter-bar .form-select {
    width: 100%;
    min-width: unset;
  }
  .filter-bar {
    flex-direction: column;
  }
  .stat-card .stat-value {
    font-size: 24px;
  }
  .stat-card {
    padding: 16px;
  }
  .card {
    padding: 16px;
  }
  .login-card {
    padding: 24px 20px;
  }
  .table-container {
    margin: 0 -8px;
    padding: 0 8px;
  }
  table {
    font-size: 13px;
  }
  th, td {
    padding: 8px 10px;
  }
  .topbar {
    padding: 0 12px;
  }
  .role-badge {
    font-size: 11px;
    padding: 2px 8px;
  }
  .btn {
    min-height: 40px;
    font-size: 13px;
  }
  .btn-sm {
    min-height: 30px;
    font-size: 12px;
  }
}

@media (min-width: 769px) and (max-width: 1024px) {
  .grid-3, .grid-4 {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 360px) {
  .bottom-nav-item {
    max-width: 56px;
  }
  .bottom-nav-item span {
    font-size: 9px;
  }
  .bottom-nav-item svg {
    width: 20px;
    height: 20px;
  }
  .page-content {
    padding: 12px;
  }
  .stat-card .stat-value {
    font-size: 20px;
  }
  .login-card {
    padding: 20px 16px;
  }
}

/* ===== UTILITY ===== */
.hidden { display: none !important; }
.mt-2 { margin-top: 8px; }
.mt-4 { margin-top: 16px; }
.mb-4 { margin-bottom: 16px; }
.text-center { text-align: center; }
.text-2 { color: var(--text-2); }
.text-3 { color: var(--text-3); }
.gap-2 { gap: 8px; }
.flex { display: flex; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.w-full { width: 100%; }
