/* ==========================================================================
   SIPENDUK - Modern Population Management System Design System
   Dual Interface: Admin Desktop & Petugas Mobile-Friendly
   ========================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@300;400;500;600;700;800&display=swap');

:root {
  /* Color Palette - Emerald & Modern Slate */
  --primary: #059669;
  --primary-hover: #047857;
  --primary-light: #ecfdf5;
  --primary-glow: rgba(5, 150, 105, 0.2);
  
  --secondary: #0284c7;
  --secondary-hover: #0369a1;
  --secondary-light: #f0f9ff;

  --accent: #f59e0b;
  --accent-light: #fffbeb;

  --danger: #ef4444;
  --danger-light: #fef2f2;
  --danger-hover: #dc2626;

  --bg-main: #f8fafc;
  --bg-card: #ffffff;
  --bg-surface: #ffffff;
  --border-color: #e2e8f0;
  --border-focus: #10b981;

  --text-main: #0f172a;
  --text-muted: #64748b;
  --text-light: #94a3b8;

  /* Elevation Shadows */
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.07), 0 2px 4px -2px rgba(0, 0, 0, 0.05);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.08), 0 4px 6px -4px rgba(0, 0, 0, 0.04);
  --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.08), 0 8px 10px -6px rgba(0, 0, 0, 0.04);

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-full: 9999px;

  --transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

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

body {
  font-family: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  background-color: var(--bg-main);
  color: var(--text-main);
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ==========================================================================
   LOGIN SCREEN STYLES
   ========================================================================== */
.login-overlay {
  position: fixed;
  inset: 0;
  background: linear-gradient(135deg, #064e3b 0%, #0f172a 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  padding: 1.25rem;
}

.login-card {
  background: #ffffff;
  width: 100%;
  max-width: 520px;
  border-radius: var(--radius-lg);
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
  overflow: hidden;
  animation: modalPop 0.3s ease-out;
}

.login-header {
  background: linear-gradient(135deg, #059669 0%, #047857 100%);
  color: #ffffff;
  padding: 2rem 1.75rem 1.75rem 1.75rem;
  text-align: center;
}

.login-header .logo-badge {
  width: 56px;
  height: 56px;
  background: rgba(255, 255, 255, 0.2);
  backdrop-filter: blur(8px);
  border-radius: var(--radius-md);
  margin: 0 auto 0.75rem auto;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.75rem;
}

.login-header h2 {
  font-size: 1.45rem;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.login-header p {
  font-size: 0.85rem;
  opacity: 0.9;
  margin-top: 0.25rem;
}

.login-body {
  padding: 1.75rem;
}

.login-tabs {
  display: flex;
  border-radius: var(--radius-sm);
  background: #f1f5f9;
  padding: 4px;
  margin-bottom: 1.5rem;
}

.login-tab-btn {
  flex: 1;
  padding: 0.6rem;
  text-align: center;
  font-size: 0.85rem;
  font-weight: 600;
  border: none;
  background: transparent;
  color: var(--text-muted);
  border-radius: 6px;
  cursor: pointer;
  transition: var(--transition);
}

.login-tab-btn.active {
  background: #ffffff;
  color: var(--primary);
  box-shadow: var(--shadow-sm);
}

/* Quick User Selector Grid */
.quick-users-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.85rem;
}

.quick-user-btn {
  background: #ffffff;
  border: 1.5px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1rem 0.85rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  cursor: pointer;
  transition: var(--transition);
}

.quick-user-btn:hover {
  border-color: var(--primary);
  background-color: var(--primary-light);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.quick-user-btn.is-admin {
  grid-column: span 2;
  background: #f0fdf4;
  border-color: #86efac;
}

.quick-user-btn .user-icon {
  font-size: 1.6rem;
  margin-bottom: 0.35rem;
}

.quick-user-btn .user-name {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--text-main);
}

.quick-user-btn .user-tag {
  font-size: 0.72rem;
  padding: 2px 8px;
  border-radius: var(--radius-full);
  margin-top: 0.25rem;
  font-weight: 600;
}

.tag-desktop {
  background: #e0f2fe;
  color: #0369a1;
}

.tag-mobile {
  background: #fef3c7;
  color: #b45309;
}

/* User Profile Badge in Header */
.user-profile-badge {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  background: #f8fafc;
  padding: 0.4rem 0.85rem;
  border-radius: var(--radius-full);
  border: 1px solid var(--border-color);
}

.user-avatar-circle {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--primary);
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 700;
}

.user-profile-name {
  font-size: 0.825rem;
  font-weight: 700;
  color: var(--text-main);
  line-height: 1.1;
}

.user-profile-role {
  font-size: 0.7rem;
  color: var(--text-muted);
}

.btn-logout {
  background: var(--danger-light);
  color: var(--danger);
  border: 1px solid rgba(239, 68, 68, 0.2);
  padding: 0.4rem 0.75rem;
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.35rem;
  transition: var(--transition);
}

.btn-logout:hover {
  background: var(--danger);
  color: #ffffff;
}

/* ==========================================================================
   DESKTOP VIEW CONTAINER
   ========================================================================== */
#desktopLayout {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* Header & Top Navigation */
.header-bar {
  background: #ffffff;
  border-bottom: 1px solid var(--border-color);
  position: sticky;
  top: 0;
  z-index: 40;
  backdrop-filter: blur(8px);
}

.header-inner {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0.85rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.brand-section {
  display: flex;
  align-items: center;
  gap: 0.85rem;
}

.brand-logo {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, var(--primary) 0%, #047857 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #ffffff;
  box-shadow: 0 4px 10px var(--primary-glow);
}

.brand-info h1 {
  font-size: 1.2rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--text-main);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.brand-info h1 span.badge-version {
  font-size: 0.7rem;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: var(--radius-full);
  background: var(--primary-light);
  color: var(--primary);
  border: 1px solid rgba(5, 150, 105, 0.2);
}

.brand-info p {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

/* Navigation Tabs */
.nav-tabs-wrapper {
  background: #ffffff;
  border-bottom: 1px solid var(--border-color);
}

.nav-tabs {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 1.5rem;
  display: flex;
  gap: 0.5rem;
  overflow-x: auto;
  scrollbar-width: none;
}

.nav-tabs::-webkit-scrollbar {
  display: none;
}

.nav-tab-btn {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.9rem 1.1rem;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-muted);
  border: none;
  background: transparent;
  border-bottom: 3px solid transparent;
  cursor: pointer;
  transition: var(--transition);
  white-space: nowrap;
}

.nav-tab-btn:hover {
  color: var(--primary);
  background-color: var(--primary-light);
}

.nav-tab-btn.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

.nav-tab-btn .tab-count {
  background: #f1f5f9;
  color: var(--text-muted);
  font-size: 0.75rem;
  padding: 2px 8px;
  border-radius: var(--radius-full);
  font-weight: 700;
}

.nav-tab-btn.active .tab-count {
  background: var(--primary);
  color: #ffffff;
}

/* Main Content Container */
.app-container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 1.5rem;
  width: 100%;
  flex: 1;
}

/* Tab Views */
.tab-view {
  display: none;
  animation: fadeIn 0.25s ease-out;
}

.tab-view.active {
  display: block;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.6rem 1.1rem;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  transition: var(--transition);
  font-family: inherit;
}

.btn-primary {
  background-color: var(--primary);
  color: #ffffff;
  box-shadow: 0 2px 4px var(--primary-glow);
}

.btn-primary:hover {
  background-color: var(--primary-hover);
  box-shadow: 0 4px 8px var(--primary-glow);
}

.btn-secondary {
  background-color: #ffffff;
  color: var(--text-main);
  border-color: var(--border-color);
}

.btn-secondary:hover {
  background-color: #f8fafc;
  border-color: #cbd5e1;
}

.btn-danger {
  background-color: var(--danger-light);
  color: var(--danger);
  border-color: rgba(239, 68, 68, 0.2);
}

.btn-danger:hover {
  background-color: var(--danger);
  color: #ffffff;
}

.btn-sm {
  padding: 0.4rem 0.75rem;
  font-size: 0.8rem;
  border-radius: 6px;
}

/* Stats Cards Section */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 1.25rem;
  margin-bottom: 1.75rem;
}

.stat-card {
  background: var(--bg-card);
  padding: 1.35rem;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-sm);
  display: flex;
  align-items: center;
  justify-content: space-between;
  transition: var(--transition);
}

.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
  border-color: #cbd5e1;
}

.stat-info .stat-label {
  font-size: 0.825rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 0.25rem;
}

.stat-info .stat-value {
  font-size: 1.85rem;
  font-weight: 800;
  color: var(--text-main);
  letter-spacing: -0.02em;
}

.stat-info .stat-sub {
  font-size: 0.78rem;
  color: var(--text-light);
  margin-top: 0.2rem;
}

.stat-icon-wrapper {
  width: 52px;
  height: 52px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
}

.icon-emerald { background: var(--primary-light); color: var(--primary); }
.icon-blue    { background: var(--secondary-light); color: var(--secondary); }
.icon-amber   { background: var(--accent-light); color: var(--accent); }
.icon-purple  { background: #faf5ff; color: #9333ea; }

/* Search and Filter Control Bar */
.filter-bar {
  background: var(--bg-card);
  padding: 1rem 1.25rem;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-color);
  margin-bottom: 1.5rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  box-shadow: var(--shadow-sm);
}

.search-input-group {
  flex: 1;
  min-width: 280px;
  position: relative;
  display: flex;
  align-items: center;
}

.search-icon {
  position: absolute;
  left: 12px;
  color: var(--text-light);
  pointer-events: none;
}

.search-input {
  width: 100%;
  padding: 0.65rem 1rem 0.65rem 2.6rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  font-family: inherit;
  font-size: 0.9rem;
  background: #f8fafc;
  transition: var(--transition);
}

.search-input:focus {
  outline: none;
  background: #ffffff;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-glow);
}

.filter-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
}

.select-filter {
  padding: 0.65rem 1.75rem 0.65rem 0.85rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  font-family: inherit;
  font-size: 0.875rem;
  background-color: #ffffff;
  color: var(--text-main);
  cursor: pointer;
  font-weight: 500;
  transition: var(--transition);
}

.select-filter:focus {
  outline: none;
  border-color: var(--primary);
}

/* Section Headers */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.section-header h2 {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text-main);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.section-header .section-desc {
  font-size: 0.825rem;
  color: var(--text-muted);
}

/* Table Design */
.table-card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-color);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

.table-responsive {
  width: 100%;
  overflow-x: auto;
}

table.data-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 0.875rem;
}

table.data-table th {
  background: #f8fafc;
  padding: 0.85rem 1rem;
  font-weight: 700;
  color: var(--text-muted);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--border-color);
  white-space: nowrap;
}

table.data-table td {
  padding: 0.95rem 1rem;
  border-bottom: 1px solid #f1f5f9;
  vertical-align: middle;
}

table.data-table tbody tr:hover {
  background-color: #f8fafc;
}

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.25rem 0.65rem;
  border-radius: var(--radius-full);
  font-size: 0.75rem;
  font-weight: 700;
  white-space: nowrap;
}

.badge-primary   { background: var(--primary-light); color: var(--primary); border: 1px solid rgba(5, 150, 105, 0.2); }
.badge-secondary { background: var(--secondary-light); color: var(--secondary); border: 1px solid rgba(2, 132, 199, 0.2); }
.badge-male      { background: #eff6ff; color: #2563eb; border: 1px solid rgba(37, 99, 235, 0.2); }
.badge-female    { background: #fdf2f8; color: #db2777; border: 1px solid rgba(219, 39, 119, 0.2); }
.badge-head      { background: #fef3c7; color: #b45309; border: 1px solid rgba(180, 83, 9, 0.2); }
.badge-house     { background: #f3e8ff; color: #7e22ce; border: 1px solid rgba(126, 34, 206, 0.2); font-family: monospace; font-size: 0.8rem; }
.badge-rt        { background: #e2e8f0; color: #334155; font-weight: 600; }

/* Grid Cards */
.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(360px, 1fr));
  gap: 1.25rem;
}

.kk-card, .house-card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-sm);
  padding: 1.35rem;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  transition: var(--transition);
}

.kk-card:hover, .house-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-lg);
  border-color: #cbd5e1;
}

.card-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 0.85rem;
  gap: 0.5rem;
}

.card-title-group h3 {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text-main);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.card-title-group .sub-id {
  font-family: monospace;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.card-details-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.detail-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.85rem;
  padding-bottom: 0.4rem;
  border-bottom: 1px dashed #f1f5f9;
}

.detail-row .label { color: var(--text-muted); }
.detail-row .val { font-weight: 600; color: var(--text-main); }

.member-chips {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-top: 0.5rem;
  background: #f8fafc;
  padding: 0.75rem;
  border-radius: var(--radius-sm);
  border: 1px solid #edf2f7;
}

.member-chip-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.8rem;
}

.card-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 1rem;
  padding-top: 0.85rem;
  border-top: 1px solid #f1f5f9;
}

/* Hierarchy Tree */
.tree-container {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-color);
  padding: 1.5rem;
  box-shadow: var(--shadow-sm);
}

.tree-house-node {
  margin-bottom: 1.25rem;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  overflow: hidden;
  background: #ffffff;
  box-shadow: var(--shadow-sm);
}

.tree-house-header {
  background: #f1f5f9;
  padding: 0.85rem 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  user-select: none;
  transition: var(--transition);
}

.tree-house-header:hover { background: #e2e8f0; }

.tree-house-title {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-weight: 700;
  font-size: 0.95rem;
}

.tree-kk-list {
  padding: 1rem 1.25rem 1rem 2.5rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  border-top: 1px solid var(--border-color);
  background: #ffffff;
}

.tree-kk-node {
  border-left: 3px solid var(--primary);
  padding-left: 1rem;
}

.tree-kk-header {
  font-weight: 700;
  font-size: 0.9rem;
  color: var(--text-main);
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.5rem;
}

.tree-resident-table {
  width: 100%;
  font-size: 0.8rem;
  border-collapse: collapse;
  margin-top: 0.35rem;
}

.tree-resident-table th {
  background: #f8fafc;
  padding: 0.4rem 0.6rem;
  color: var(--text-muted);
  text-align: left;
  font-weight: 600;
}

.tree-resident-table td {
  padding: 0.5rem 0.6rem;
  border-bottom: 1px solid #f1f5f9;
}

/* ==========================================================================
   MOBILE-FRIENDLY WEB UI FOR PETUGAS RW
   ========================================================================== */
#mobileLayout {
  display: none;
  width: 100%;
  max-width: 500px;
  margin: 0 auto;
  min-height: 100vh;
  background: #f8fafc;
  position: relative;
  box-shadow: 0 0 40px rgba(0, 0, 0, 0.08);
  padding-bottom: 85px; /* Space for bottom nav */
}

/* Mobile Top Header */
.mobile-top-bar {
  background: linear-gradient(135deg, #059669 0%, #047857 100%);
  color: #ffffff;
  padding: 1.1rem 1.25rem 1.25rem 1.25rem;
  position: sticky;
  top: 0;
  z-index: 50;
  box-shadow: 0 4px 12px rgba(5, 150, 105, 0.25);
}

.mobile-top-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.mobile-officer-info {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.mobile-avatar {
  width: 42px;
  height: 42px;
  background: rgba(255, 255, 255, 0.2);
  backdrop-filter: blur(4px);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  border: 1.5px solid rgba(255, 255, 255, 0.4);
}

.mobile-officer-text h3 {
  font-size: 1.05rem;
  font-weight: 800;
  line-height: 1.1;
}

.mobile-officer-text p {
  font-size: 0.75rem;
  opacity: 0.85;
}

.mobile-badge-rw {
  background: rgba(255, 255, 255, 0.25);
  padding: 3px 10px;
  border-radius: var(--radius-full);
  font-size: 0.75rem;
  font-weight: 700;
  border: 1px solid rgba(255, 255, 255, 0.3);
}

/* Mobile Content Container */
.mobile-content {
  padding: 1rem;
}

/* Mobile Quick Stats */
.m-stats-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 0.65rem;
  margin-bottom: 1.25rem;
}

.m-stat-box {
  background: #ffffff;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 0.85rem 0.6rem;
  text-align: center;
  box-shadow: var(--shadow-sm);
}

.m-stat-box .num {
  font-size: 1.45rem;
  font-weight: 800;
  color: var(--primary);
  line-height: 1;
}

.m-stat-box .lbl {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-top: 0.3rem;
  text-transform: uppercase;
}

/* Mobile Quick Actions Grid */
.m-action-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}

.m-action-btn {
  background: #ffffff;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 0.9rem 0.85rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-main);
  cursor: pointer;
  transition: var(--transition);
  box-shadow: var(--shadow-sm);
}

.m-action-btn:active {
  transform: scale(0.98);
}

.m-action-icon {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  flex-shrink: 0;
}

/* Mobile Search Bar */
.m-search-bar {
  position: relative;
  margin-bottom: 1rem;
}

.m-search-bar input {
  width: 100%;
  padding: 0.75rem 1rem 0.75rem 2.6rem;
  border-radius: var(--radius-full);
  border: 1.5px solid var(--border-color);
  font-family: inherit;
  font-size: 0.9rem;
  background: #ffffff;
  box-shadow: var(--shadow-sm);
}

.m-search-bar input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-glow);
}

.m-search-bar .m-search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-light);
  pointer-events: none;
}

/* Mobile Resident & House Cards */
.m-cards-list {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.m-card {
  background: #ffffff;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.1rem;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  transition: var(--transition);
}

.m-card:active {
  border-color: var(--primary);
}

.m-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.5rem;
}

.m-card-title {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-main);
}

.m-card-sub {
  font-family: monospace;
  font-size: 0.78rem;
  color: var(--text-muted);
}

.m-card-body {
  font-size: 0.825rem;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.m-card-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.4rem;
  padding-top: 0.65rem;
  border-top: 1px solid #f1f5f9;
}

.m-card-actions .btn {
  flex: 1;
  padding: 0.5rem;
  font-size: 0.8rem;
}

/* Bottom Navigation Bar for Mobile */
.mobile-bottom-nav {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 500px;
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-around;
  padding: 0.4rem 0.5rem 0.6rem 0.5rem;
  z-index: 100;
  box-shadow: 0 -4px 15px rgba(0, 0, 0, 0.05);
}

.m-nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.2rem;
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 0.4rem 0.65rem;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 0.72rem;
  font-weight: 600;
  transition: var(--transition);
  min-width: 58px;
}

.m-nav-item .nav-icon {
  font-size: 1.35rem;
  line-height: 1;
}

.m-nav-item.active {
  color: var(--primary);
  font-weight: 800;
}

.m-nav-item.active .nav-icon {
  transform: scale(1.1);
}

/* Floating Action Button (FAB) */
.mobile-fab {
  position: fixed;
  bottom: 80px;
  right: 1.5rem;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary) 0%, #047857 100%);
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.75rem;
  border: none;
  cursor: pointer;
  box-shadow: 0 8px 16px var(--primary-glow), 0 4px 8px rgba(0, 0, 0, 0.15);
  z-index: 90;
  transition: var(--transition);
}

.mobile-fab:active {
  transform: scale(0.92);
}

/* Speed dial menu popover */
.mobile-speed-dial {
  position: fixed;
  bottom: 145px;
  right: 1.5rem;
  display: none;
  flex-direction: column;
  gap: 0.65rem;
  z-index: 95;
  align-items: flex-end;
}

.mobile-speed-dial.active {
  display: flex;
  animation: fadeIn 0.2s ease-out;
}

.speed-dial-btn {
  background: #ffffff;
  border: 1px solid var(--border-color);
  padding: 0.65rem 1rem;
  border-radius: var(--radius-full);
  box-shadow: var(--shadow-lg);
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-main);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  white-space: nowrap;
}

.speed-dial-btn:hover {
  background-color: var(--primary-light);
  color: var(--primary);
}

/* ==========================================================================
   MODALS AND DRAWERS
   ========================================================================== */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  backdrop-filter: blur(4px);
  z-index: 1000;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  overflow-y: auto;
}

.modal-backdrop.active {
  display: flex;
}

.modal-dialog {
  background: #ffffff;
  width: 100%;
  max-width: 650px;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xl);
  overflow: hidden;
  animation: modalPop 0.25s ease-out;
}

@keyframes modalPop {
  from {
    transform: scale(0.95) translateY(10px);
    opacity: 0;
  }
  to {
    transform: scale(1) translateY(0);
  }
}

.modal-header {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-header h3 {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text-main);
}

.btn-close {
  background: transparent;
  border: none;
  font-size: 1.25rem;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0.25rem;
  border-radius: var(--radius-sm);
  line-height: 1;
}

.btn-close:hover {
  color: var(--danger);
  background: var(--danger-light);
}

.modal-body {
  padding: 1.5rem;
  max-height: 75vh;
  overflow-y: auto;
}

.modal-footer {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.75rem;
  background: #f8fafc;
}

/* Forms and Inputs */
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.form-group.col-span-2 { grid-column: span 2; }

.form-label {
  font-size: 0.8rem;
  font-weight: 700;
  color: #334155;
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.form-label span.req { color: var(--danger); }

.form-control {
  padding: 0.65rem 0.85rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  font-family: inherit;
  font-size: 0.875rem;
  background: #ffffff;
  color: var(--text-main);
  transition: var(--transition);
}

.form-control:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-glow);
}

.form-control:disabled, .form-control[readonly] {
  background-color: #f1f5f9;
  cursor: not-allowed;
  color: #64748b;
}

.input-with-action {
  display: flex;
  gap: 0.5rem;
}

.input-with-action .form-control { flex: 1; }
.form-hint { font-size: 0.72rem; color: var(--text-muted); }

/* Empty States */
.empty-state {
  text-align: center;
  padding: 2.5rem 1.25rem;
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  border: 1px dashed var(--border-color);
}

.empty-icon {
  font-size: 2.5rem;
  margin-bottom: 0.5rem;
  opacity: 0.7;
}

.empty-state h3 {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-main);
  margin-bottom: 0.2rem;
}

.empty-state p {
  font-size: 0.8rem;
  color: var(--text-muted);
  max-width: 360px;
  margin: 0 auto 1rem auto;
}

mark.search-highlight {
  background-color: #fef08a;
  color: #854d0e;
  padding: 1px 3px;
  border-radius: 3px;
  font-weight: 700;
}

/* Toast Notifications */
.toast-container {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 10000;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.toast {
  padding: 0.85rem 1.25rem;
  border-radius: var(--radius-md);
  font-size: 0.875rem;
  font-weight: 600;
  box-shadow: var(--shadow-lg);
  background: #1e293b;
  color: #ffffff;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  animation: slideToast 0.25s ease-out;
}

.toast.toast-success { background: #065f46; border-left: 4px solid #34d399; }
.toast.toast-error   { background: #991b1b; border-left: 4px solid #f87171; }

@keyframes slideToast {
  from { transform: translateX(100%); opacity: 0; }
  to   { transform: translateX(0); opacity: 1; }
}

/* Backup Cards */
.backup-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 1.25rem;
}

.backup-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 1rem;
}

.backup-card h4 { font-size: 1rem; font-weight: 700; margin-bottom: 0.25rem; }
.backup-card p { font-size: 0.85rem; color: var(--text-muted); }

/* Print Styles */
@media print {
  .header-bar, .nav-tabs-wrapper, .filter-bar, .header-actions, .card-actions, .btn, .modal-backdrop, .mobile-bottom-nav, .mobile-fab, .mobile-speed-dial {
    display: none !important;
  }
  body { background: #ffffff; color: #000000; }
  .app-container, .mobile-content { padding: 0; }
  .table-card { box-shadow: none; border: 1px solid #000000; }
}

/* Responsive adjustments */
@media (max-width: 768px) {
  .header-inner { flex-direction: column; align-items: flex-start; }
  .header-actions { width: 100%; justify-content: flex-start; }
  .form-grid { grid-template-columns: 1fr; }
  .form-group.col-span-2 { grid-column: span 1; }
  .filter-bar { flex-direction: column; align-items: stretch; }
}

/* ==========================================================================
   KK FAMILY MEMBER BUILDER & DATABASE SEARCH PICKER
   ========================================================================== */
.kk-builder-card {
  background: #f8fafc;
  border: 1.5px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.2rem;
  margin-top: 1rem;
}

.kk-builder-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.85rem;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.kk-builder-title {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-main);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.kk-search-box-wrapper {
  background: #ffffff;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 0.9rem;
  margin-bottom: 1rem;
  box-shadow: var(--shadow-sm);
}

.kk-search-results-list {
  max-height: 220px;
  overflow-y: auto;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background: #ffffff;
  margin-top: 0.6rem;
}

.kk-search-result-item {
  padding: 0.65rem 0.85rem;
  border-bottom: 1px solid #f1f5f9;
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  transition: var(--transition);
  gap: 0.5rem;
}

.kk-search-result-item:hover {
  background-color: var(--primary-light);
}

.kk-search-result-item.is-selected {
  background-color: #ecfdf5;
  border-left: 4px solid var(--primary);
}

.kk-search-empty-banner {
  padding: 1.15rem;
  text-align: center;
  background: #fffbeb;
  border: 1px dashed #f59e0b;
  border-radius: var(--radius-sm);
  margin-top: 0.6rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
}

.kk-search-empty-banner p {
  font-size: 0.825rem;
  color: #92400e;
  margin: 0;
}

.kk-selected-card {
  background: #ecfdf5;
  border: 1.5px solid #a7f3d0;
  border-radius: var(--radius-sm);
  padding: 0.75rem 1rem;
  margin: 0.75rem 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.kk-selected-info {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.kk-selected-info strong {
  color: var(--primary-hover);
  font-size: 0.9rem;
}

.kk-draft-table-wrapper {
  overflow-x: auto;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background: #ffffff;
}

.kk-action-btn-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-top: 0.75rem;
}

