/* ==========================================================================
   Design System & Tokens (Corporate/Enterprise Aesthetics)
   Theme: FaithOn (Samsung CI-inspired Blue & White)
   ========================================================================== */
@import url("https://cdn.jsdelivr.net/gh/orioncactus/pretendard@v1.3.9/dist/web/static/pretendard.css");
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&display=swap');

:root {
  /* Colors */
  --bg-color: #f4f6f9; /* Crisp clean light gray background */
  --surface-color: #ffffff; /* White cards */
  --surface-hover: #f8f9fa;
  --text-primary: #1e293b; /* High-contrast slate */
  --text-secondary: #64748b;
  --text-muted: #94a3b8;
  
  /* FaithOn Corporate Colors (Samsung CI Blue inspired) */
  --accent-color: #1428A0;
  --accent-hover: #0d1e7c;
  --accent-light: rgba(20, 40, 160, 0.08);
  --accent-glow: rgba(20, 40, 160, 0.2);
  
  --success-color: #059669;
  --success-light: rgba(5, 150, 105, 0.1);
  --danger-color: #e11d48;
  --danger-light: rgba(225, 29, 72, 0.1);
  --warning-color: #d97706;
  --warning-light: rgba(217, 119, 6, 0.1);
  
  /* Gradients */
  --gradient-primary: linear-gradient(135deg, #1428A0 0%, #2563eb 100%);
  
  /* Shadows */
  --shadow-xs: 0 1px 2px 0 rgba(0, 0, 0, 0.04);
  --shadow-sm: 0 2px 4px -1px rgba(0, 0, 0, 0.06), 0 1px 2px -1px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 6px 12px -2px rgba(0, 0, 0, 0.06), 0 3px 6px -2px rgba(0, 0, 0, 0.04);
  --shadow-lg: 0 12px 24px -4px rgba(0, 0, 0, 0.08), 0 4px 8px -2px rgba(0, 0, 0, 0.03);
  --border-color: #e2e8f0;
  
  /* Typography - Standardized with Pretendard */
  --font-family: 'Pretendard', -apple-system, BlinkMacSystemFont, system-ui, Roboto, "Segoe UI", sans-serif;
  
  /* Transitions */
  --transition-fast: 0.15s ease;
  --transition-normal: 0.25s ease;
}

.brand-img {
  width: 120px;
  height: auto;
  max-height: 90px;
  object-fit: contain;
  margin: 0 auto 1rem auto;
  display: block;
}

/* ==========================================================================
   Base Styles
   ========================================================================== */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: var(--font-family);
  background-color: var(--bg-color);
  color: var(--text-primary);
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

a {
  text-decoration: none;
  color: inherit;
}

ul {
  list-style: none;
}

button {
  cursor: pointer;
  border: none;
  background: none;
  font-family: inherit;
}

/* ==========================================================================
   Layout & Navigation
   ========================================================================== */
.app-container {
  display: flex;
  flex: 1;
  min-height: 100vh;
}

/* Desktop Sidebar */
.sidebar {
  width: 250px;
  background: var(--surface-color);
  border-right: 1px solid var(--border-color);
  padding: 1.75rem 1.25rem;
  display: flex;
  flex-direction: column;
  transition: var(--transition-normal);
  z-index: 100;
  box-shadow: 2px 0 12px rgba(0, 0, 0, 0.02);
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 2rem;
  padding-bottom: 1.25rem;
  border-bottom: 1px solid var(--border-color);
}

.brand-icon {
  width: 52px;
  height: 52px;
  min-width: 52px;
  background: #ffffff;
  border: 1.5px solid #cbd5e1;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 12px rgba(20, 40, 160, 0.12);
  overflow: hidden;
  padding: 4px;
}

.brand-img-logo {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.brand-text {
  font-size: 1.45rem;
  font-weight: 800;
  color: var(--accent-color);
  letter-spacing: -0.5px;
}

.nav-menu {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  padding: 0.75rem 1rem;
  border-radius: 8px;
  color: var(--text-secondary);
  font-weight: 500;
  font-size: 0.95rem;
  transition: var(--transition-fast);
}

.nav-item i {
  font-size: 1.1rem;
  width: 20px;
  text-align: center;
}

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

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

/* Sidebar Group Headers & Sub-links */
.nav-group-header {
  font-size: 0.72rem;
  font-weight: 800;
  color: #94a3b8;
  letter-spacing: 0.5px;
  padding: 0.65rem 0.75rem 0.25rem 0.75rem;
}

.sidebar-sub-links {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding-left: 0.5rem;
  margin-bottom: 0.35rem;
}

.sub-nav-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0.35rem 0.65rem;
  font-size: 0.82rem;
  font-weight: 600;
  color: #64748b;
  text-decoration: none;
  border-radius: 6px;
  transition: all 0.15s ease;
}

.sub-nav-item:hover {
  color: var(--accent-color);
  background: #f1f5f9;
}

.sub-nav-item.active {
  color: var(--accent-color);
  background: #eff6ff;
  font-weight: 700;
}

.main-content {
  flex: 1;
  padding: 2rem 2.5rem;
  overflow-y: auto;
  position: relative;
  max-width: 1600px;
  margin: 0 auto;
  width: 100%;
}

/* Mobile Top Bar (Hidden on Desktop) */
.mobile-top-bar {
  display: none;
  background: var(--surface-color);
  border-bottom: 1px solid var(--border-color);
  padding: 0.65rem 0.85rem;
  flex-direction: column;
  gap: 0.5rem;
  position: sticky;
  top: 0;
  z-index: 99;
}

.mobile-quick-nav {
  display: flex;
  width: 100%;
  gap: 6px;
  background: #f1f5f9;
  padding: 4px;
  border-radius: 10px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.mobile-quick-nav::-webkit-scrollbar {
  display: none;
}

.mobile-quick-item {
  flex: 1;
  min-width: fit-content;
  text-align: center;
  padding: 0.42rem 0.65rem;
  font-size: 0.82rem;
  font-weight: 600;
  border-radius: 7px;
  color: #64748b;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  white-space: nowrap;
  transition: all 0.15s ease;
}

#mobNavStats {
  display: none !important;
}

.mobile-quick-item.active {
  background: #ffffff;
  color: var(--accent-color);
  font-weight: 800;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

/* Mobile Bottom Navigation Bar */
.mobile-bottom-nav {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  width: 100%;
  background: #ffffff;
  border-top: 1.5px solid #e2e8f0;
  padding: 0.5rem 0.5rem calc(0.6rem + env(safe-area-inset-bottom));
  z-index: 99999;
  box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.08);
}

.mobile-bottom-nav-inner {
  display: flex;
  justify-content: space-around;
  align-items: center;
  max-width: 600px;
  margin: 0 auto;
}

.mobile-nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.3rem;
  padding: 0.4rem 0.6rem;
  color: #64748b;
  font-size: 0.78rem;
  font-weight: 600;
  border-radius: 10px;
  flex: 1;
  text-align: center;
  transition: all 0.15s ease;
  text-decoration: none;
}

.mobile-nav-item i {
  font-size: 1.25rem;
}

.mobile-nav-item:hover {
  color: var(--accent-color);
  background: rgba(20, 40, 160, 0.04);
}

.mobile-nav-item.active {
  color: var(--accent-color);
  font-weight: 800;
  background: rgba(20, 40, 160, 0.08);
}

/* ==========================================================================
   Components (Cards, Buttons, Inputs)
   ========================================================================== */
.page-header {
  margin-bottom: 1.75rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 1.25rem;
  gap: 1rem;
}

.page-title {
  font-size: 1.65rem;
  font-weight: 800;
  letter-spacing: -0.5px;
  color: var(--text-primary);
}

.page-subtitle {
  color: var(--text-secondary);
  font-size: 0.9rem;
  margin-top: 0.25rem;
}

.card {
  background: var(--surface-color);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 1.5rem;
  box-shadow: var(--shadow-xs);
  transition: var(--transition-normal);
}

.card:hover {
  box-shadow: var(--shadow-sm);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.55rem 1.15rem;
  border-radius: 8px;
  font-weight: 600;
  transition: var(--transition-fast);
  font-size: 0.9rem;
  white-space: nowrap;
}

.btn-primary {
  background: var(--gradient-primary);
  color: white;
  border: 1px solid var(--accent-color);
  box-shadow: 0 2px 6px rgba(20, 40, 160, 0.2);
}

.btn-primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
  box-shadow: 0 4px 10px rgba(20, 40, 160, 0.3);
}

.btn-outline {
  background: var(--surface-color);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
}

.btn-outline:hover {
  background: var(--surface-hover);
  border-color: #cbd5e1;
}

.form-input, .form-select {
  width: 100%;
  padding: 0.65rem 0.9rem;
  border-radius: 8px;
  background: var(--surface-color);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.95rem;
  transition: var(--transition-fast);
}

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

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.25rem 0.55rem;
  border-radius: 6px;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: -0.2px;
  background: var(--surface-hover);
  color: var(--text-secondary);
  border: 1px solid var(--border-color);
}

.badge-success {
  background: var(--success-light);
  color: var(--success-color);
  border-color: rgba(5, 150, 105, 0.2);
}

.badge-area {
  padding: 0.18rem 0.4rem;
  font-size: 0.72rem;
  letter-spacing: -0.3px;
  border-radius: 5px;
  white-space: nowrap;
  box-sizing: border-box;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* Uniform Fixed Size Duty Badges (모든 직책 뱃지 외형 크기 100% 동일: 46px x 20px) */
.duty-badge, .badge-leader {
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  width: 48px !important;
  min-width: 48px !important;
  max-width: 48px !important;
  height: 20px !important;
  min-height: 20px !important;
  max-height: 20px !important;
  border-radius: 5px !important;
  font-weight: 800 !important;
  white-space: nowrap !important;
  flex-shrink: 0 !important;
  text-align: center !important;
  box-sizing: border-box !important;
  padding: 0 !important;
  line-height: 1 !important;
  vertical-align: middle !important;
  font-size: 0.68rem;
  letter-spacing: -0.2px;
}

/* 글자 수에 따른 폰트 크기 자동 최적화 */
.duty-badge.len-2, .badge-leader.len-2, .badge-leader.badge-leader-main, .badge-leader.badge-leader-group {
  font-size: 0.68rem !important;
  letter-spacing: -0.2px !important;
}

.duty-badge.len-3, .badge-leader.len-3 {
  font-size: 0.58rem !important;
  letter-spacing: -0.4px !important;
}

.duty-badge.len-4, .badge-leader.len-4, .badge-leader.badge-leader-deputy {
  font-size: 0.50rem !important;
  letter-spacing: -0.6px !important;
}

/* 직책별 색상 테마 */
.duty-badge.duty-district, .badge-leader.badge-leader-main, .badge-leader.badge-leader-deputy {
  background: #ecfdf5 !important;
  color: #059669 !important;
  border: 1px solid rgba(5, 150, 105, 0.35) !important;
}

.duty-badge.duty-jo, .badge-leader.badge-leader-jo {
  background: #fdf2f8 !important;
  color: #db2777 !important;
  border: 1px solid rgba(219, 39, 119, 0.35) !important;
}

.duty-badge.duty-manager, .badge-leader.badge-leader-manager {
  background: #eff6ff !important;
  color: #2563eb !important;
  border: 1px solid rgba(37, 99, 235, 0.35) !important;
}

.duty-badge.duty-clerk, .badge-leader.badge-leader-clerk {
  background: #f0fdf4 !important;
  color: #16a34a !important;
  border: 1px solid rgba(22, 163, 74, 0.35) !important;
}

.duty-badge.duty-pastor {
  background: #faf5ff !important;
  color: #7e22ce !important;
  border: 1px solid rgba(126, 34, 206, 0.35) !important;
}

.duty-badge.duty-deacon {
  background: #eff6ff !important;
  color: #1d4ed8 !important;
  border: 1px solid rgba(29, 78, 216, 0.35) !important;
}

.duty-badge.duty-newcomer {
  background: #ecfeff !important;
  color: #0891b2 !important;
  border: 1px solid rgba(8, 145, 178, 0.35) !important;
}

.duty-badge.duty-default {
  background: #f8fafc !important;
  color: #475569 !important;
  border: 1px solid #cbd5e1 !important;
}

.table-container {
  overflow-x: auto;
  overflow-y: auto;
  max-height: calc(100vh - 280px);
  min-height: 320px;
  -webkit-overflow-scrolling: touch;
  border-radius: 8px;
  margin-top: 0.75rem;
  position: relative;
  scrollbar-width: thin;
  border: 1px solid var(--border-color);
}

.table-container::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

.table-container::-webkit-scrollbar-thumb {
  background-color: #cbd5e1;
  border-radius: 4px;
}

.data-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  text-align: left;
}

/* Sticky Column Utilities for Dashboard Matrix */
.matrix-scroll-wrapper {
  position: relative;
  width: 100%;
}

.matrix-nav-btn {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 44px;
  height: 76px;
  border-radius: 38px;
  background: rgba(255, 255, 255, 0.95);
  border: 2px solid var(--accent-color);
  color: var(--accent-color);
  box-shadow: 0 8px 24px rgba(20, 40, 160, 0.28);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 25;
  transition: opacity 0.2s ease, background-color 0.2s ease, color 0.2s ease, transform 0.2s ease, box-shadow 0.2s ease;
  opacity: 0;
  pointer-events: none;
  font-size: 1.5rem;
}

.matrix-scroll-wrapper:hover .matrix-nav-btn.visible {
  opacity: 1;
  pointer-events: auto;
}

.matrix-nav-btn:hover {
  background: var(--accent-color);
  color: #ffffff;
  transform: translateY(-50%) scale(1.08);
  box-shadow: 0 10px 30px rgba(20, 40, 160, 0.45);
}

.matrix-nav-btn.btn-prev {
  left: 240px;
}

.matrix-nav-btn.btn-next {
  right: 235px;
}

/* Sticky Classes */
.data-table th.sticky-col-seq,
.data-table td.sticky-col-seq {
  position: sticky;
  left: 0;
  z-index: 10;
  background: #ffffff;
  width: 45px;
  min-width: 45px;
  max-width: 45px;
  text-align: center;
}

.data-table th.sticky-col-area,
.data-table td.sticky-col-area {
  position: sticky;
  left: 45px;
  z-index: 10;
  background: #ffffff;
  width: 68px;
  min-width: 68px;
  max-width: 68px;
  text-align: center;
}

.data-table th.sticky-col-info,
.data-table td.sticky-col-info {
  position: sticky;
  z-index: 10;
  background: #ffffff;
  min-width: 135px;
  border-right: 2px solid #e2e8f0;
  box-shadow: 4px 0 8px -3px rgba(0, 0, 0, 0.05);
}

.data-table th.sticky-col-rate,
.data-table td.sticky-col-rate {
  position: sticky;
  right: 0;
  z-index: 10;
  background: #ffffff;
  width: 220px;
  min-width: 220px;
  border-left: 2px solid #e2e8f0;
  box-shadow: -4px 0 8px -3px rgba(0, 0, 0, 0.05);
}

.data-table th.sticky-col-seq,
.data-table th.sticky-col-area,
.data-table th.sticky-col-info,
.data-table th.sticky-col-rate {
  background: #f8fafc;
  z-index: 25;
}

.data-table tr:hover td.sticky-col-seq,
.data-table tr:hover td.sticky-col-area,
.data-table tr:hover td.sticky-col-info,
.data-table tr:hover td.sticky-col-rate {
  background: #f8fafc;
}

/* Matrix Service Tabs (주일 / 수요 / 전체) */
.matrix-tab-group {
  display: inline-flex;
  background: #f1f5f9;
  padding: 3px;
  border-radius: 9px;
  border: 1px solid #e2e8f0;
  gap: 3px;
}

.matrix-tab {
  padding: 0.35rem 0.75rem;
  border-radius: 7px;
  border: none;
  background: transparent;
  color: var(--text-secondary, #64748b);
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.matrix-tab:hover {
  color: #0f172a;
  background: rgba(255, 255, 255, 0.7);
}

.matrix-tab.active {
  background: #1e293b;
  color: #ffffff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
  font-weight: 700;
}

/* Area Navigation Tabs (11구역 ~ 20구역 스와이프/책장 넘김 탭) */
.area-tabs-nav {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  margin-bottom: 0.85rem;
  padding: 2px 0 6px 0;
}

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

.area-tabs-list {
  display: flex;
  gap: 6px;
  min-width: fit-content;
  align-items: center;
}

.area-tab-pill {
  padding: 0.42rem 0.85rem;
  border-radius: 8px;
  font-size: 0.88rem;
  font-weight: 800;
  border: 1.5px solid var(--border-color);
  background: #f8fafc;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.15s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  white-space: nowrap;
  user-select: none;
}

.area-tab-pill:hover {
  border-color: var(--accent-color);
  color: var(--accent-color);
  background: rgba(20, 40, 160, 0.04);
}

.area-tab-pill.active {
  background: var(--accent-color);
  color: #ffffff;
  border-color: var(--accent-color);
  box-shadow: 0 2px 8px rgba(20, 40, 160, 0.28);
}

.data-table thead {
  position: sticky;
  top: 0;
  z-index: 20;
}

.data-table th {
  position: sticky;
  top: 0;
  z-index: 20;
  background: #f8fafc;
  padding: 0.85rem 1rem;
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--text-secondary);
  border-bottom: 2px solid #cbd5e1;
  white-space: nowrap;
  box-shadow: 0 2px 4px -2px rgba(0, 0, 0, 0.06);
}

.data-table td {
  padding: 0.95rem 1rem;
  font-size: 0.92rem;
  border-bottom: 1px solid var(--border-color);
  color: var(--text-primary);
  vertical-align: middle;
}

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

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

.avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--accent-light);
  color: var(--accent-color);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.95rem;
  flex-shrink: 0;
}

/* ==========================================================================
   Custom Checkbox & Wide Attendance Button (3x Width)
   ========================================================================== */
.attend-btn-container {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  position: relative;
  cursor: pointer;
  user-select: none;
  width: 110px;
  height: 38px;
}

.attend-btn-container input {
  position: absolute;
  opacity: 0;
  cursor: pointer;
  height: 0;
  width: 0;
}

.attend-btn-pill {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
  height: 100%;
  border-radius: 20px;
  border: 1.5px solid #cbd5e1;
  background-color: #f8fafc;
  color: #64748b;
  font-size: 0.88rem;
  font-weight: 600;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

.attend-btn-container:hover .attend-btn-pill {
  border-color: var(--accent-color);
  background-color: var(--accent-light);
  color: var(--accent-color);
}

.attend-btn-container input:checked ~ .attend-btn-pill {
  background: var(--gradient-primary);
  border-color: var(--accent-color);
  color: #ffffff;
  box-shadow: 0 3px 8px rgba(20, 40, 160, 0.3);
}

.attend-btn-pill .btn-label-unchecked {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.attend-btn-pill .btn-label-checked {
  display: none;
}

.attend-btn-container input:checked ~ .attend-btn-pill .btn-label-unchecked {
  display: none;
}

.attend-btn-container input:checked ~ .attend-btn-pill .btn-label-checked {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.check-container {
  position: relative;
  cursor: pointer;
  user-select: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.check-container input {
  position: absolute;
  opacity: 0;
  cursor: pointer;
  height: 0;
  width: 0;
}

.checkmark {
  width: 32px;
  height: 32px;
  background-color: #f1f5f9;
  border: 2px solid #cbd5e1;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}

.check-container:hover input ~ .checkmark {
  border-color: var(--accent-color);
  background-color: var(--accent-light);
}

.check-container input:checked ~ .checkmark {
  background-color: var(--accent-color);
  border-color: var(--accent-color);
  box-shadow: 0 2px 6px rgba(20, 40, 160, 0.35);
}

.checkmark:after {
  content: "";
  display: none;
  width: 8px;
  height: 14px;
  border: solid white;
  border-width: 0 2.5px 2.5px 0;
  transform: rotate(45deg);
  margin-bottom: 2px;
}

.check-container input:checked ~ .checkmark:after {
  display: block;
}

/* ==========================================================================
   Dashboard Specifics
   ========================================================================== */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 0.85rem;
  margin-bottom: 1.5rem;
}

.stat-card {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  border-left: 4px solid var(--accent-color);
  padding: 0.95rem 1.1rem;
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
}

/* General District 2-Card Layout (성도, 새참자 2개 카드) */
.stats-grid-district {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1.15rem;
  margin-bottom: 1.5rem;
}

.district-stat-card {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  padding: 1.15rem 1.4rem;
  background: var(--surface-color);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  box-shadow: var(--shadow-xs);
}

.district-stat-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px dashed #e2e8f0;
  padding-bottom: 0.65rem;
}

.district-stat-row-group {
  display: flex;
  align-items: center;
  justify-content: space-around;
  gap: 1rem;
}

.district-stat-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.35rem;
}

.district-session-label {
  font-size: 0.84rem;
  font-weight: 700;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 5px;
}

.district-session-val {
  font-size: 1.55rem;
  font-weight: 800;
  color: var(--text-primary);
  letter-spacing: -0.5px;
  white-space: nowrap;
}

.district-stat-divider {
  width: 1px;
  height: 42px;
  background: #e2e8f0;
}

.stat-title {
  color: var(--text-secondary);
  font-size: 0.82rem;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.stat-value {
  font-size: 1.6rem;
  font-weight: 800;
  color: var(--text-primary);
  letter-spacing: -0.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.stat-desc {
  font-size: 0.75rem;
  display: flex;
  align-items: center;
  gap: 0.25rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.charts-grid {
  display: grid;
  grid-template-columns: 1.35fr 1.15fr;
  gap: 1.25rem;
  align-items: stretch;
}

.chart-container {
  min-height: 380px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  position: relative;
}

.chart-container h3 {
  color: var(--text-primary);
  font-size: 1.05rem;
  font-weight: 700;
  margin-bottom: 1rem;
}

/* Filter Bar */
.filter-bar {
  display: flex;
  gap: 1rem;
  margin-bottom: 1.25rem;
  flex-wrap: nowrap;
}

.select-group {
  flex: 1;
  min-width: 140px;
}

.select-label {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 0.4rem;
  white-space: nowrap;
}

/* ==========================================================================
   Responsive Adaptations (Tablet & Mobile)
   ========================================================================== */

/* Typography & Word-break protection */
h1, h2, h3, h4, .stat-title, .stat-desc, .badge, .btn, .nav-item, .mobile-nav-item, .data-table th, .data-table td, .area-tab-pill, .fellow-tab-pill, .badge-leader {
  word-break: keep-all !important;
  white-space: nowrap !important;
}

/* Tablets (1024px down) */
@media (max-width: 1024px) {
  .sidebar {
    width: 220px;
    padding: 1.5rem 1rem;
  }
  .main-content {
    padding: 1.5rem 1.5rem;
  }
  .charts-grid {
    grid-template-columns: 1fr;
  }
  .chart-container {
    min-height: 380px;
  }
  .stats-grid {
    grid-template-columns: repeat(3, 1fr);
    gap: 0.65rem;
  }
}

/* Mobile Phones (768px down) */
@media (max-width: 768px) {
  body {
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch;
  }

  .app-container {
    display: block !important;
    min-height: 100vh;
    height: auto !important;
  }

  .sidebar {
    display: none; /* Replaced by mobile top bar */
  }
  
  .mobile-top-bar {
    display: flex;
    padding: 0.65rem 0.85rem;
  }
  
  .mobile-bottom-nav {
    display: none !important; /* 모바일 상단 퀵 메뉴바로 완벽 일원화 */
  }
  
  .main-content {
    padding: 0.65rem 0.45rem 2.5rem 0.45rem !important;
    overflow-y: visible !important;
    height: auto !important;
  }
  
  .card {
    padding: 0.85rem 0.45rem !important;
  }
  
  .page-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.65rem;
    margin-bottom: 1rem;
    padding-bottom: 0.85rem;
  }
  
  .page-title {
    font-size: 1.35rem;
    word-break: keep-all;
    white-space: nowrap;
  }
  
  .page-subtitle {
    font-size: 0.82rem;
    word-break: keep-all;
    white-space: nowrap;
    line-height: 1.4;
  }
  
  .header-actions {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
  }
  
  .header-actions > div,
  .header-actions select,
  .header-actions button,
  .header-actions input {
    width: 100% !important;
  }
  
  .stats-grid {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    gap: 0.45rem !important;
    margin-bottom: 0.85rem !important;
    padding-bottom: 4px;
    scrollbar-width: none;
  }

  /* 관리자일 때만 모바일에서 flex 스크롤로 표시 */
  .stats-grid:not([style*="display: none"]) {
    display: flex !important;
  }

  .stats-grid::-webkit-scrollbar {
    display: none;
  }

  /* 일반 구역 담당자일 때만 모바일에서 2열 그리드로 표시 (관리자 접속 시 display: none 유지) */
  .stats-grid-district:not([style*="display: none"]) {
    display: grid !important;
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 0.6rem !important;
    margin-bottom: 0.85rem !important;
  }

  .district-stat-card {
    padding: 0.75rem 0.65rem !important;
    gap: 0.5rem !important;
  }

  .district-stat-card-header {
    padding-bottom: 0.45rem !important;
  }

  .district-session-label {
    font-size: 0.75rem !important;
  }

  .district-session-val {
    font-size: 1.25rem !important;
  }

  .district-stat-divider {
    height: 32px !important;
  }
  
  .stat-card {
    flex: 1 0 auto;
    min-width: 135px !important;
    padding: 0.55rem 0.55rem !important;
    border-left: 3.5px solid var(--accent-color) !important;
    border-radius: 8px !important;
    gap: 0.15rem !important;
    white-space: nowrap !important;
  }
  
  .stat-title {
    font-size: 0.72rem !important;
    white-space: nowrap !important;
  }
  
  .stat-value {
    font-size: 1.15rem !important;
    font-weight: 800;
    white-space: nowrap !important;
  }
  
  .stat-desc {
    font-size: 0.68rem !important;
    white-space: nowrap !important;
  }
  
  #btnToggleMobileCharts {
    display: inline-flex !important;
  }

  .charts-grid {
    display: none; /* 모바일에서는 기본적으로 차트를 접어 출석표가 1화면에 바로 보이게 함 */
    grid-template-columns: 1fr !important;
    gap: 1rem !important;
    margin-bottom: 1rem !important;
    width: 100% !important;
    max-width: 100% !important;
    overflow: hidden !important;
  }

  .chart-container {
    min-height: 280px !important;
    padding: 0.85rem !important;
    width: 100% !important;
    max-width: 100% !important;
    overflow: hidden !important;
    box-sizing: border-box !important;
  }

  .chart-wrapper {
    width: 100% !important;
    max-width: 100% !important;
    position: relative !important;
    overflow: hidden !important;
  }

  .chart-wrapper canvas {
    max-width: 100% !important;
    height: auto !important;
  }
  
  .filter-bar {
    flex-direction: column;
    gap: 0.65rem;
    margin-bottom: 1rem;
  }
  
  .select-group {
    width: 100%;
  }

  /* Table formatting & touch targets on mobile */
  .data-table th, .data-table td {
    padding: 0.75rem 0.65rem;
    font-size: 0.85rem;
    word-break: keep-all;
  }
  
  .attend-btn-container {
    width: 105px;
    height: 44px;
  }
  
  .attend-btn-pill {
    font-size: 0.9rem;
  }
  
  .avatar {
    width: 32px;
    height: 32px;
    font-size: 0.8rem;
  }

  /* Matrix table on mobile: Keep Seq, Area, and Member Info Sticky while Date columns scroll smoothly */
  .matrix-scroll-wrapper {
    position: relative;
    width: 100%;
    overflow: hidden;
  }

  .table-container {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    width: 100%;
  }

  /* 1. 순번 컬럼 (0px ~ 24px) */
  .data-table th.sticky-col-seq {
    position: sticky !important;
    left: 0 !important;
    z-index: 20 !important;
    background-color: #f8fafc !important;
    width: 24px !important;
    min-width: 24px !important;
    max-width: 24px !important;
    text-align: center;
    padding: 0.45rem 0.02rem !important;
    font-size: 0.72rem !important;
  }
  .data-table td.sticky-col-seq {
    position: sticky !important;
    left: 0 !important;
    z-index: 15 !important;
    background-color: #ffffff !important;
    width: 24px !important;
    min-width: 24px !important;
    max-width: 24px !important;
    text-align: center;
    padding: 0.45rem 0.02rem !important;
    font-size: 0.75rem !important;
  }

  /* 2. 구역 컬럼 (전체 조회 시에만 24px ~ 76px) - 52px 폭 완전 확보 */
  .data-table th.sticky-col-area {
    position: sticky !important;
    left: 24px !important;
    z-index: 20 !important;
    background-color: #f8fafc !important;
    width: 52px !important;
    min-width: 52px !important;
    max-width: 52px !important;
    text-align: center;
    padding: 0.45rem 0.05rem !important;
    font-size: 0.72rem !important;
  }
  .data-table td.sticky-col-area {
    position: sticky !important;
    left: 24px !important;
    z-index: 15 !important;
    background-color: #ffffff !important;
    width: 52px !important;
    min-width: 52px !important;
    max-width: 52px !important;
    text-align: center;
    padding: 0.45rem 0.05rem !important;
    font-size: 0.72rem !important;
  }

  .data-table .badge-area {
    padding: 2px 4px !important;
    font-size: 0.65rem !important;
    letter-spacing: -0.4px !important;
    border-radius: 5px !important;
    max-width: 46px !important;
    white-space: nowrap !important;
    box-sizing: border-box !important;
    display: inline-flex !important;
    justify-content: center !important;
    align-items: center !important;
  }

  /* 3. 이름(성도정보) 컬럼 (구역별 접속 시 left: 24px, 전체 조회 시 left: 72px) */
  .data-table th.sticky-col-info {
    position: sticky !important;
    z-index: 20 !important;
    background-color: #f8fafc !important;
    min-width: 90px !important;
    max-width: 115px !important;
    border-right: 2px solid #cbd5e1 !important;
    box-shadow: 3px 0 6px -2px rgba(0, 0, 0, 0.1) !important;
    padding: 0.45rem 0.15rem !important;
    font-size: 0.72rem !important;
  }
  .data-table td.sticky-col-info {
    position: sticky !important;
    z-index: 15 !important;
    background-color: #ffffff !important;
    min-width: 90px !important;
    max-width: 115px !important;
    border-right: 2px solid #cbd5e1 !important;
    box-shadow: 3px 0 6px -2px rgba(0, 0, 0, 0.1) !important;
    padding: 0.45rem 0.15rem !important;
    font-size: 0.75rem !important;
  }

  /* 4. 날짜 열 & 체크 셀 모바일 최적화 (4개 날짜가 가로 스크롤 없이 100% 핏) */
  .data-table th.matrix-date-col-th,
  .data-table td.matrix-date-cell {
    min-width: 34px !important;
    max-width: 40px !important;
    padding: 0.45rem 0.02rem !important;
    text-align: center !important;
  }

  .data-table tr:hover td.sticky-col-seq,
  .data-table tr:hover td.sticky-col-area,
  .data-table tr:hover td.sticky-col-info {
    background-color: #f1f5f9 !important;
  }

  .data-table th.sticky-col-rate, 
  .data-table td.sticky-col-rate {
    position: static !important;
    right: auto !important;
    min-width: 52px !important;
    max-width: 65px !important;
    border-left: none !important;
    box-shadow: none !important;
    padding: 0.45rem 0.1rem !important;
  }
  .data-table th.sticky-col-rate {
    font-size: 0.70rem !important;
    text-align: center !important;
  }

  .matrix-nav-btn {
    display: none !important; /* Swipe is natural on mobile */
  }

  .matrix-tab-group {
    width: 100%;
    display: flex;
    justify-content: space-between;
  }

  .matrix-tab {
    flex: 1;
    justify-content: center;
    padding: 0.35rem 0.2rem;
    font-size: 0.72rem;
    font-weight: 700;
  }

  /* Modal on mobile */
  .modal-content {
    margin: 1rem;
    padding: 1.25rem;
    max-height: 90vh;
    overflow-y: auto;
  }
}

/* Small Mobile Phones (480px down) */
@media (max-width: 480px) {
  .page-title {
    font-size: 1.15rem;
    white-space: nowrap !important;
  }
  .stat-value {
    font-size: 1.1rem !important;
    white-space: nowrap !important;
  }
  .stat-card {
    padding: 0.5rem 0.5rem !important;
    min-width: 125px !important;
    white-space: nowrap !important;
  }
  .stat-desc {
    font-size: 0.65rem !important;
    white-space: nowrap !important;
  }

  .matrix-nav-btn {
    width: 34px;
    height: 60px;
    font-size: 1.1rem;
  }
}

/* ============================================================
   Mode Switcher UI (Admin Mode ↔ District Mode)
   ============================================================ */
.btn-mode-switch {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0.4rem 0.85rem;
  border-radius: 9999px;
  font-size: 0.82rem;
  font-weight: 800;
  cursor: pointer;
  transition: all 0.2s ease;
  border: 1.5px solid transparent;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
}

.btn-to-district {
  background: linear-gradient(135deg, #0284c7 0%, #0369a1 100%);
  color: #ffffff;
  border-color: #38bdf8;
}

.btn-to-district:hover {
  background: linear-gradient(135deg, #0369a1 0%, #075985 100%);
  transform: translateY(-1px);
  box-shadow: 0 4px 10px rgba(2, 132, 199, 0.25);
}

.btn-to-admin {
  background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
  color: #ffffff;
  border-color: #fde68a;
}

.btn-to-admin:hover {
  background: linear-gradient(135deg, #d97706 0%, #b45309 100%);
  transform: translateY(-1px);
  box-shadow: 0 4px 10px rgba(217, 119, 6, 0.25);
}

.district-mode-admin-bar {
  background: linear-gradient(90deg, #fffbeb 0%, #fef3c7 100%);
  border: 1.5px solid #fde68a;
  border-radius: 12px;
  padding: 0.6rem 1rem;
  margin-bottom: 1rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  box-shadow: 0 2px 8px rgba(245, 158, 11, 0.1);
}

.district-mode-admin-bar .bar-title {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.85rem;
  font-weight: 800;
  color: #92400e;
}

.district-mode-admin-bar .bar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.district-mode-admin-bar .area-switcher-select {
  padding: 0.35rem 0.65rem;
  border-radius: 8px;
  border: 1.5px solid #d97706;
  background: #ffffff;
  color: #92400e;
  font-weight: 800;
  font-size: 0.82rem;
  outline: none;
  cursor: pointer;
}

/* Domain Meeting Top 2-Segment Tab Bar (출석체크 vs 통계) */
.domain-tab-nav {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin-bottom: 1.25rem;
  background: #ffffff;
  padding: 6px;
  border-radius: 14px;
  border: 1.5px solid #e2e8f0;
  box-shadow: 0 2px 8px rgba(0,0,0,0.04);
}

.domain-tab-nav.cols-3 {
  grid-template-columns: repeat(3, 1fr);
}

.domain-tab-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0.82rem 1rem;
  border-radius: 10px;
  font-size: 1rem;
  font-weight: 800;
  border: 1.5px solid transparent;
  background: #f8fafc;
  color: #64748b;
  text-decoration: none;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.domain-tab-btn:hover {
  background: #f1f5f9;
  color: #1e293b;
}

.domain-tab-btn.active.tab-theme-regular,
.domain-tab-btn.active.tab-theme-mother,
.domain-tab-btn.active.tab-theme-gathering,
.domain-tab-btn.active {
  background: #1e293b !important;
  color: #ffffff !important;
  border-color: #0f172a !important;
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.15) !important;
  font-weight: 800 !important;
}

/* Compact Mode Switcher (Header Inline next to User Display) */
.btn-mode-switch-compact {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 8px;
  font-size: 0.72rem;
  font-weight: 700;
  border-radius: 6px;
  border: 1px solid #93c5fd;
  background: #eff6ff;
  color: #1d4ed8;
  cursor: pointer;
  white-space: nowrap;
  line-height: 1.2;
  transition: all 0.15s ease;
  box-shadow: 0 1px 2px rgba(37, 99, 235, 0.08);
  text-decoration: none;
}
.btn-mode-switch-compact:hover {
  background: #dbeafe;
  border-color: #60a5fa;
  color: #1e40af;
  transform: translateY(-1px);
}
.btn-mode-switch-compact.btn-mode-to-admin {
  border-color: #fcd34d;
  background: #fffbeb;
  color: #b45309;
  box-shadow: 0 1px 2px rgba(217, 119, 6, 0.08);
}
.btn-mode-switch-compact.btn-mode-to-admin:hover {
  background: #fef3c7;
  border-color: #f59e0b;
  color: #92400e;
}

@media (max-width: 768px) {
  .domain-tab-nav {
    margin-bottom: 0.85rem;
    padding: 4px;
    gap: 6px;
  }
  .domain-tab-btn {
    padding: 0.65rem 0.6rem;
    font-size: 0.85rem;
    gap: 6px;
    border-radius: 8px;
  }
}

/* Unified Admin Sub-Tabs (.admin-view-nav-tabs) */
.admin-view-nav-tabs {
  display: flex;
  background: #f1f5f9;
  border-radius: 12px;
  padding: 4px;
  gap: 4px;
  margin-bottom: 1.25rem;
  border: 1px solid var(--border-color, #e2e8f0);
}

.admin-view-nav-tab {
  flex: 1;
  padding: 0.65rem 1rem;
  border-radius: 9px;
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-secondary, #64748b);
  background: transparent;
  border: none;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  white-space: nowrap;
}

.admin-view-nav-tab:hover {
  color: var(--text-primary, #1e293b);
  background: rgba(255, 255, 255, 0.6);
}

.admin-view-nav-tab.active {
  background: #ffffff;
  color: var(--accent-color, #2563eb);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
  font-weight: 800;
}

@media (max-width: 768px) {
  .admin-view-nav-tabs {
    margin-bottom: 0.85rem;
    padding: 3px;
    gap: 3px;
  }
  .admin-view-nav-tab {
    padding: 0.55rem 0.45rem;
    font-size: 0.82rem;
    gap: 4px;
    border-radius: 7px;
  }
}

/* ==================================================== */
/* Unified Minimal Admin Design (SaaS / Fintech Aesthetic) */
/* 2~3% Accent Restraint - dvsoft.kr / Toss Benchmark   */
/* ==================================================== */
.admin-status-summary {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.75rem;
  margin-bottom: 1.25rem;
  width: 100%;
  box-sizing: border-box;
}

.admin-summary-card {
  background: #ffffff !important;
  border: 1px solid #e2e8f0 !important;
  border-radius: 12px !important;
  padding: 0.85rem 1rem !important;
  display: flex !important;
  flex-direction: column !important;
  justify-content: center !important;
  gap: 4px !important;
  box-sizing: border-box !important;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.02) !important;
  transition: all 0.15s ease;
}

.admin-summary-card:hover {
  border-color: #cbd5e1 !important;
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.04) !important;
}

.admin-summary-card span {
  font-size: 0.74rem !important;
  font-weight: 600 !important;
  color: #64748b !important;
  letter-spacing: -0.2px !important;
}

.admin-summary-card strong {
  font-size: 1.35rem !important;
  font-weight: 800 !important;
  color: #0f172a !important;
  letter-spacing: -0.5px !important;
}

.admin-summary-card.kpi-pending strong {
  color: #e11d48 !important; /* Subtle restrained rose for pending urge */
}

@media (max-width: 768px) {
  .admin-status-summary {
    grid-template-columns: repeat(4, 1fr) !important;
    gap: 0.35rem !important;
    margin-bottom: 0.75rem !important;
  }
  .admin-summary-card {
    padding: 0.5rem 0.25rem !important;
    border-radius: 8px !important;
    text-align: center !important;
    align-items: center !important;
  }
  .admin-summary-card span {
    font-size: 0.65rem !important;
    white-space: nowrap !important;
  }
  .admin-summary-card strong {
    font-size: 1.05rem !important;
  }
}

/* Call & Message Action Buttons - Soft Minimal Slate */
.btn-call-leader {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  min-width: 30px;
  min-height: 30px;
  background: #f1f5f9 !important;
  color: #475569 !important;
  border: 1px solid #e2e8f0 !important;
  border-radius: 8px !important;
  font-size: 0.8rem;
  text-decoration: none;
  transition: all 0.15s ease;
  box-sizing: border-box;
  padding: 0;
}

.btn-call-leader:hover {
  background: #e2e8f0 !important;
  color: #0f172a !important;
  border-color: #cbd5e1 !important;
}
