@import url('https://cdn.jsdelivr.net/gh/orioncactus/pretendard@v1.3.8/dist/web/static/pretendard.css');

/* ==========================================
   1. 통합 Variables & Reset
========================================== */
:root {
  --primary: #4B7C86; 
  --primary-dark: #3A626A; 
  --primary-light: #EBF3F4;
  --bg: #F2F4F6; 
  --white: #FFFFFF; 
  --border: #E5E8EB;
  --text-main: #191F28; 
  --text-sub: #8B95A1;
  --red: #EF4444; 
  --green: #10B981; 
  --blue: #3B82F6;
  --radius: 16px;
  --shadow: 0 4px 20px rgba(0, 0, 0, 0.04);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
body { font-family: 'Pretendard', sans-serif; margin: 0; background: var(--bg); color: var(--text-main); overflow-x: hidden; }
.hidden { display: none !important; }
.text-green { color: var(--green); font-weight: 800;} 
.text-red { color: var(--red); font-weight: 800;} 
.text-blue { color: var(--blue); font-weight: 800;}

/* ==========================================
   2. App Shell (Header & Bottom Nav)
========================================== */
.app-header {
  position: fixed; top: 0; left: 0; right: 0; z-index: 1000;
  background: var(--white); border-bottom: 1px solid var(--border);
  box-shadow: 0 2px 10px rgba(0,0,0,0.03);
}
.header-main { display: flex; justify-content: space-between; align-items: center; height: 56px; padding: 0 16px; }
.header-main h2 { margin: 0; font-size: 1.15rem; font-weight: 800; color: var(--text-main); }

.header-date { 
  font-size: 0.9rem; font-weight: 700; color: var(--primary-dark);
  background: var(--primary-light); padding: 4px 10px; border-radius: 8px; border: none; font-family: inherit;
  height: 32px; line-height: 32px; outline: none;
}

.top-tabs-wrapper { background: var(--bg); border-top: 1px solid var(--border); overflow-x: auto; scrollbar-width: none; }
.top-tabs-wrapper::-webkit-scrollbar { display: none; }
.top-tabs { display: flex; padding: 0 8px; }
.top-tab-btn {
  padding: 10px 16px; background: none; border: none; font-size: 0.9rem; font-weight: 700;
  color: var(--text-sub); border-bottom: 3px solid transparent; cursor: pointer; white-space: nowrap; transition: 0.2s;
}
.top-tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); }

/* 하단 고정 메뉴 */
.bottom-nav { 
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 1000;
  background: rgba(255,255,255,0.95); backdrop-filter: blur(10px);
  border-top: 1px solid var(--border); display: flex; height: 65px;
  padding-bottom: env(safe-area-inset-bottom); box-shadow: 0 -4px 20px rgba(0,0,0,0.03);
}
.b-nav-item { 
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; 
  font-size: 0.7rem; color: #B0B8C1; text-decoration: none; transition: 0.2s; gap: 4px;
}
.b-nav-item.active { color: var(--primary); font-weight: 700; }
.b-nav-icon { width: 24px; height: 24px; fill: #B0B8C1; transition: 0.2s; }
.b-nav-item.active .b-nav-icon { fill: var(--primary); transform: translateY(-2px); }

/* 메인 영역 패딩 (헤더와 푸터에 안 가려지게) */
.app-main { padding-top: 110px; padding-bottom: 90px; }
.container { max-width: 1400px; margin: 0 auto; padding-left: 16px; padding-right: 16px; }

/* ==========================================
   3. Common Components (Cards, Forms, Buttons)
========================================== */
.card { background: var(--white); border-radius: var(--radius); padding: 20px 16px; margin-bottom: 16px; box-shadow: var(--shadow); border: 1px solid rgba(0,0,0,0.02); }
.card h3 { margin: 0 0 16px 0; font-size: 1.1rem; color: var(--text-main); font-weight: 800; display: flex; align-items: center; gap: 6px; }

.form-group { width: 100%; margin-bottom: 12px; }
.form-group label { display: block; margin-bottom: 6px; font-size: 0.85rem; font-weight: 700; color: var(--text-sub); }
.form-control { width: 100%; height: 44px; padding: 0 14px; background: var(--bg); border: 1px solid var(--border); border-radius: 12px; font-size: 0.95rem; color: var(--text-main); outline: none; transition: 0.2s; -webkit-appearance: none; }
.form-control:focus { border-color: var(--primary); background: var(--white); }

select.form-control { background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2364748B' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e"); background-repeat: no-repeat; background-position: right 12px center; background-size: 16px; padding-right: 32px; }

.btn { display: inline-flex; align-items: center; justify-content: center; height: 44px; padding: 0 16px; border-radius: 12px; font-size: 0.95rem; font-weight: 700; cursor: pointer; transition: 0.2s; border: none; gap: 6px; width: 100%; }
.btn-main { background: var(--primary); color: white; box-shadow: 0 4px 12px rgba(75, 124, 134, 0.2); }
.btn-main:active { transform: scale(0.98); background: var(--primary-dark); }
.btn-outline { background: var(--white); color: var(--primary); border: 1px solid var(--primary); }
.btn-danger { background: #FF5F5F; box-shadow: 0 4px 12px rgba(255, 95, 95, 0.2); }
.btn-action { padding: 6px 12px; background: white; border: 1px solid var(--border); border-radius: 6px; font-size: 0.8rem; font-weight: 700; color: var(--text-sub); }

/* ==========================================
   4. UI Elements (Attendance & Finance)
========================================== */
/* 가로 스크롤 칩 */
.event-selector { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: none; }
.event-selector::-webkit-scrollbar { display: none; }
.chip { padding: 8px 14px; background: var(--bg); border-radius: 18px; font-size: 0.9rem; font-weight: 600; color: var(--text-sub); white-space: nowrap; cursor: pointer; transition: 0.2s; border: 1px solid transparent; }
.chip.active { background: var(--primary); color: var(--white); font-weight: 700; box-shadow: 0 4px 10px rgba(75, 124, 134, 0.3); }

/* 스티키 헤더 (출석체크 시 현재 진행중인 정보 표시) */
.sticky-wrapper { position: sticky; top: 110px; z-index: 90; margin: 0 -16px 12px -16px; padding: 0 16px; }
.sticky-card { background: rgba(255, 255, 255, 0.95); backdrop-filter: blur(10px); border-radius: var(--radius); padding: 12px 16px; box-shadow: 0 4px 12px rgba(0,0,0,0.08); border: 1px solid var(--primary-light); display: flex; justify-content: space-between; align-items: center; }
.btn-refresh { width: 36px; height: 36px; border-radius: 12px; background: var(--primary-light); color: var(--primary); border: none; display: flex; justify-content: center; align-items: center; font-size: 1.2rem; cursor: pointer; transition: all 0.2s; box-shadow: 0 2px 5px rgba(0,0,0,0.05); }
.btn-refresh.spinning { animation: spin 0.8s linear infinite; }

/* 리스트 아이템 (출석부, 명단) */
.att-list-grid { display: grid; grid-template-columns: 1fr; gap: 10px; }
@media (min-width: 768px) { .att-list-grid { grid-template-columns: 1fr 1fr; } }
.att-item { display: flex; align-items: center; justify-content: space-between; padding: 12px; border: 1px solid var(--border); border-radius: 12px; background: var(--white); }
.att-item .info .name { font-size: 1rem; font-weight: 700; color: var(--text-main); margin-bottom: 2px; }
.att-item .info .group { font-size: 0.75rem; color: var(--text-sub); font-weight: 500; }
.btn-check { min-width: 50px; padding: 8px 0; border-radius: 8px; background: var(--bg); color: var(--text-sub); border: none; font-weight: 700; font-size: 0.85rem; transition: 0.2s; }
.btn-check.checked { background: var(--primary); color: var(--white); box-shadow: 0 2px 6px rgba(75, 124, 134, 0.3); }
.list-divider { grid-column: 1 / -1; margin-top: 16px; margin-bottom: 8px; font-size: 0.95rem; font-weight: 700; color: var(--primary-dark); background: var(--primary-light); padding: 10px 14px; border-radius: 8px; display: flex; justify-content: space-between; align-items: center; }

/* 재정 요약 대시보드 */
.summary-dashboard { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 16px; }
.summary-item { padding: 16px 12px; background: var(--white); border: 1px solid var(--border); border-radius: 12px; text-align: center; }
.summary-item:last-child { grid-column: 1 / -1; } 
.summary-item .label { display: block; margin-bottom: 6px; font-size: 0.8rem; font-weight: 700; color: var(--text-sub); }
.summary-item .value { font-size: 1.3rem; font-weight: 900; }

/* 초압축 재정 장부 (모바일 우선 적용) */
.budget-table-wrapper { width: 100%; overflow-x: hidden; }
.budget-grid, .budget-grid tbody { display: block; width: 100%; }
.budget-grid thead { display: none; }

.tx-grid tr { display: grid; grid-template-columns: 1fr auto; row-gap: 2px; column-gap: 8px; padding: 12px; margin-bottom: 8px; background: white; border: 1px solid var(--border); border-radius: 10px; box-shadow: 0 2px 4px rgba(0,0,0,0.02); }
.tx-grid td { padding: 0; border: none; }
.tx-grid td:nth-child(1) { grid-column: 1; grid-row: 1; font-size: 0.75rem; color: var(--text-sub); }
.tx-grid td:nth-child(2) { grid-column: 1; grid-row: 2; font-size: 0.85rem; font-weight: 800; color: var(--primary-dark); }
.tx-grid td:nth-child(3) { grid-column: 1; grid-row: 3; font-size: 0.85rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; width: 180px; }
.tx-grid td:nth-child(4), .tx-grid td:nth-child(5) { grid-column: 2; grid-row: 1 / span 2; text-align: right; font-size: 1.15rem; font-weight: 900; }
.tx-grid td.col-manage { grid-column: 2; grid-row: 3; display: flex; justify-content: flex-end; gap: 4px; }
.tx-grid td:nth-child(4):not(:has(span)), .tx-grid td:nth-child(5):not(:has(span)) { display: none; }
.tx-grid td[colspan] { grid-column: 1 / -1; text-align: center; padding: 10px; font-size: 0.85rem; }

/* 예산 관리 그리드 */
.budget-grid tr { display: grid; grid-template-columns: 1fr auto; gap: 4px 8px; padding: 12px 16px; margin-bottom: 8px; background: white; border: 1px solid var(--border); border-radius: 10px; box-shadow: 0 2px 4px rgba(0,0,0,0.02); }
.budget-row-main td:first-child { grid-column: 1 / -1; font-size: 1rem; font-weight: 800; color: var(--primary-dark); padding-bottom: 6px; border-bottom: 1px solid var(--border); }
.budget-row-sub td:first-child { grid-column: 1 / -1; font-size: 0.9rem; padding-bottom: 6px; border-bottom: 1px dashed var(--border); }
.budget-grid td:nth-child(2) { grid-column: 1; grid-row: 2; font-size: 0.75rem; color: var(--text-sub); display: flex; flex-direction: column; justify-content: center; }
.budget-grid td[data-label="현재 예산"] { grid-column: 2; grid-row: 2; display: flex; flex-direction: column; align-items: flex-end; }
input.comma-input { height: 34px; width: 120px; text-align: right; font-size: 1rem; font-weight: 800; border: 1px solid var(--border); border-radius: 6px; padding: 0 8px; }
.budget-section-divider { background: transparent !important; border: none !important; box-shadow: none !important; padding: 0 !important; margin-top: 24px !important; margin-bottom: 0 !important; display: block !important;}
.budget-section-divider td { background: var(--primary-dark) !important; color: white !important; font-size: 1.15rem !important; font-weight: 800 !important; border-radius: 8px !important; padding: 14px !important; text-align: center !important; width: 100% !important; display: block !important; }

/* ==========================================
   5. Modals & Utilities
========================================== */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.6); backdrop-filter: blur(2px); z-index: 2000; display: flex; align-items: center; justify-content: center; }
.modal-content { width: calc(100% - 32px); max-width: 500px; max-height: 85vh; padding: 24px 20px; background: var(--white); border-radius: 16px; overflow-y: auto; }
#loading { position: fixed; inset: 0; background: rgba(242, 244, 246, 0.9); z-index: 9999; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.spinner { width: 48px; height: 48px; border: 5px solid var(--border); border-top-color: var(--primary); border-radius: 50%; animation: spin 1s linear infinite; }
@keyframes spin { 100% { transform: rotate(360deg); } }

/* PC Responsive overriding */
@media (min-width: 769px) {
  .app-main { padding-top: 80px; padding-bottom: 40px; }
  .bottom-nav { display: none; }
  .top-tabs-wrapper { position: fixed; top: 0; left: 200px; right: 0; height: 56px; background: transparent; border: none; display: flex; align-items: center; z-index: 1001; }
  .top-tab-btn { color: rgba(255,255,255,0.7); border-bottom: 3px solid transparent; padding: 16px; }
  .top-tab-btn.active { color: white; border-bottom-color: white; }
  .sticky-wrapper { top: 60px; }
}

/* ==========================================
   7. UI/UX 고도화 (애니메이션 및 터치 최적화)
========================================== */
/* 화면 전환 시 부드러운 페이드인 효과 */
.view {
    animation: fadeIn 0.3s ease-in-out;
}
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(5px); }
    to { opacity: 1; transform: translateY(0); }
}

/* 상단/하단 탭 터치 영역(Hitbox) 확대 및 클릭 피드백 */
.top-tab-btn, .b-nav-item {
    position: relative;
    overflow: hidden;
}
.top-tab-btn:active, .b-nav-item:active {
    opacity: 0.7;
    transform: scale(0.95);
}

/* 입력창(Input) 포커스 시 모바일 화면 자동 확대 방지 (iOS 사파리 최적화) */
input[type="text"], input[type="number"], input[type="date"], input[type="time"], input[type="month"], select {
    font-size: 16px !important; 
}

/* 아이폰 하단 홈 인디케이터 여백(Safe Area) 완벽 대응 */
.bottom-nav {
    padding-bottom: env(safe-area-inset-bottom, 20px);
    height: calc(65px + env(safe-area-inset-bottom, 20px));
}
.app-main {
    padding-bottom: calc(90px + env(safe-area-inset-bottom, 20px));
}