/* --- 폰트 및 기본 설정 --- */
@font-face {
  font-family: 'Source Han Sans K';
  src: url('/Fonts/어도비본고딕B.otf') format('opentype');
}

:root {
  /* 라이트 모드 (기본) */
  --bg-color: #f0f2f5;
  --card-bg: #ffffff;
  --text-primary: #333333;
  --text-secondary: #666666;
  --accent-color: #FFD700; /* 황금빛 옐로우 */
  --accent-hover: #ffc800;
  --primary-btn: #333333;
  --primary-btn-text: #ffffff;
  --border-color: #e0e0e0;
  --shadow-sm: 0 2px 4px rgba(0,0,0,0.05);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
  --status-on: #2e7d32; /* Green */
  --status-off: #d32f2f; /* Red */
  --sat-color: #1976d2; /* Blue */
  --sun-color: #d32f2f; /* Red */
}

/* 다크 모드 변수 재정의 */
body.dark-mode {
  --bg-color: #121212;
  --card-bg: #1e1e1e;
  --text-primary: #e0e0e0;
  --text-secondary: #aaaaaa;
  --accent-color: #FFD700;
  --accent-hover: #ffc800;
  --primary-btn: #FFD700;
  --primary-btn-text: #121212;
  --border-color: #333333;
  --shadow-sm: 0 2px 4px rgba(0,0,0,0.2);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.4);
  --sat-color: #64b5f6; /* 연한 파랑 */
  --sun-color: #e57373; /* 연한 빨강 */
}

* { box-sizing: border-box; }

body {
  font-family: 'Source Han Sans K', sans-serif;
  background-color: var(--bg-color);
  color: var(--text-primary);
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 100vh;
  transition: background-color 0.3s, color 0.3s;
}

/* --- 헤더 --- */
.dashboard-header {
  width: 100%;
  max-width: 900px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px;
  margin-bottom: 10px;
}

.logo {
  font-size: 24px;
  font-weight: bold;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 10px;
}

#serverIndicator {
  width: 12px; height: 12px; border-radius: 50%;
  background-color: var(--status-off);
  display: inline-block; transition: all 0.3s;
}
#serverIndicator.online { background-color: var(--status-on); box-shadow: 0 0 8px var(--status-on); }
#serverIndicator.offline { background-color: var(--status-off); box-shadow: none; }

#darkModeContainer {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--card-bg);
  padding: 5px 10px;
  border-radius: 20px;
  box-shadow: var(--shadow-sm);
}

#darkModeSelect {
  border: none;
  background: transparent;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 14px;
  cursor: pointer;
  outline: none;
}

/* --- 메인 컨테이너 --- */
.main-container {
  width: 100%;
  max-width: 900px;
  padding: 0 20px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* --- 카드 공통 스타일 --- */
.card {
  background-color: var(--card-bg);
  border-radius: 16px;
  padding: 20px;
  box-shadow: var(--shadow-md);
  transition: transform 0.2s;
}

/* 1. 상태 섹션 (Status Section) */
.status-section {
  display: grid;
  grid-template-columns: 1fr 1.5fr 1fr;
  gap: 15px;
  align-items: stretch;
}

.toggle-card {
  display: flex;
}

/* 토글 버튼 색상 반전 스타일 */
#toggleButton {
  width: 100%; font-size: 22px; font-weight: bold;
  border: none; border-radius: 12px; cursor: pointer;
  transition: all 0.3s; box-shadow: var(--shadow-sm);
  color: white;
}
#toggleButton.toggle-off { background-color: var(--status-off); } /* OFF = Red */
#toggleButton.toggle-on { background-color: var(--status-on); }   /* ON = Green */
#toggleButton:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }

.status-info-group {
  display: flex;
  gap: 10px;
}

.info-card {
  flex: 1;
  background-color: var(--card-bg);
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 10px;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border-color);
}

.info-card .label { font-size: 12px; color: var(--text-secondary); margin-bottom: 4px; }
.info-card .value { font-size: 20px; font-weight: bold; }
#statusValue { color: var(--status-off); }
#broadcastStatusValue { color: var(--text-secondary); }

/* 관리자 컨트롤 */
.admin-controls {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.segmented-control {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  background: transparent;
  padding: 0;
}

.segment-btn {
  flex: 1;
  border: 1px solid var(--border-color);
  background: var(--card-bg);
  color: var(--text-secondary);
  padding: 8px 0;
  border-radius: 8px;
  cursor: pointer;
  font-weight: bold;
  font-size: 14px;
  transition: all 0.2s;
}

#adminStatusButton {
  width: 100%;
  background: transparent;
  border: 1px solid var(--status-off);
  color: var(--status-off);
  padding: 8px;
  border-radius: 8px;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.2s;
}
#adminStatusButton.active { background: var(--status-off); color: white; }

/* 2. 주간 계획표 (Table) */
.schedule-card { padding: 0; overflow: hidden; }
.card-header {
  padding: 15px 20px;
  background-color: rgba(0,0,0,0.03);
  border-bottom: 1px solid var(--border-color);
  display: flex; justify-content: space-between; align-items: center;
}
.card-header h2, .card-header h3 { margin: 0; font-size: 18px; display: flex; align-items: center; gap: 10px; }

.table-wrapper { overflow-x: auto; }
#weeklyPlanTable {
  width: 100%;
  border-collapse: collapse;
  min-width: 700px;
}

#weeklyPlanTable th, #weeklyPlanTable td {
  padding: 12px;
  text-align: center;
  border-bottom: 1px solid var(--border-color);
  border-right: 1px solid var(--border-color);
  font-size: 15px;
}
.date-row td { border-bottom: 1px solid var(--border-color) !important; }
#weeklyPlanTable th:last-child, #weeklyPlanTable td:last-child { border-right: none; }
#weeklyPlanTable tr:last-child td { border-bottom: none; }

#weeklyPlanTable th { background-color: var(--bg-color); font-weight: bold; color: var(--text-secondary); }
#weeklyPlanTable .sticky-col { position: sticky; left: 0; background-color: var(--bg-color); z-index: 1; }

/* 주간 계획표 요일 색상 */
#weeklyPlanTable th#sat, #weeklyPlanTable td:nth-last-child(2) { color: var(--sat-color); }
#weeklyPlanTable th#sun, #weeklyPlanTable td:last-child { color: var(--sun-color); }
.holiday { color: var(--sun-color) !important; font-weight: bold; }
.status-x { color: var(--status-off) !important; font-weight: bold; }

/*- 주간 계획표 오늘 날짜 강조 -*/
.weekly-today-top, 
.weekly-today-mid, 
.weekly-today-bottom {
  background-color: rgba(255, 215, 0, 0.15) !important; /* 연한 골드 배경 */
  
  /* 폰트는 굵게 강조 */
  font-weight: bold !important;
  
  /* 좌우는 굵은 골드색 */
  border-left: 3px solid var(--accent-color) !important;
  border-right: 3px solid var(--accent-color) !important;
}

.weekly-today-top {
  border-top: 3px solid var(--accent-color) !important; /* 위쪽 굵게 */
  border-bottom: 1px solid rgba(0, 0, 0, 0.2) !important; /* 내부 구분선 얇게 */
}

.weekly-today-mid {
  border-top: none !important;
  border-bottom: 1px solid rgba(0, 0, 0, 0.2) !important; /* 내부 구분선 얇게 */
}

.weekly-today-bottom {
  border-top: none !important;
  border-bottom: 3px solid var(--accent-color) !important; /* 아래쪽 굵게 */
}

/* --- 다크모드 대응 --- */
body.dark-mode .weekly-today-top, 
body.dark-mode .weekly-today-mid, 
body.dark-mode .weekly-today-bottom {
  background-color: rgba(255, 215, 0, 0.1) !important;
  border-left-color: var(--accent-color) !important;
  border-right-color: var(--accent-color) !important;
}

body.dark-mode .weekly-today-top {
  border-top-color: var(--accent-color) !important;
  border-bottom: 1px solid rgba(255, 255, 255, 0.3) !important;
}

body.dark-mode .weekly-today-mid {
  border-bottom: 1px solid rgba(255, 255, 255, 0.3) !important;
}

body.dark-mode .weekly-today-bottom {
  border-bottom-color: var(--accent-color) !important;
}

/* 3. BGM & 입력창 공통 */
.input-group {
  display: flex;
  gap: 10px;
  margin-top: 15px;
}
.input-group.full-width { margin-top: 0; margin-bottom: 15px; }

input[type="text"], textarea {
  flex: 1;
  padding: 12px 15px;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  background-color: var(--bg-color);
  color: var(--text-primary);
  font-size: 16px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.2s;
}
input[type="text"]:focus, textarea:focus { border-color: var(--accent-color); }

.action-btn {
  padding: 0 20px;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-weight: bold;
  font-size: 16px;
  background-color: var(--card-bg);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  transition: all 0.2s;
  white-space: nowrap; /* 버튼 줄바꿈 방지 */
}
.action-btn.primary { background-color: var(--accent-color); border: none; color: #121212; }
.action-btn:hover { filter: brightness(0.95); transform: translateY(-1px); }

#bgmList { padding: 0 20px 10px 20px; margin: 0; list-style: none; }
#bgmList li { padding: 8px 0; border-bottom: 1px solid var(--border-color); display: flex; justify-content: space-between; align-items: center; }
/* BGM 수정/삭제 버튼 */
#bgmList button {
  padding: 4px 10px; font-size: 13px; border-radius: 6px;
  border: 1px solid var(--border-color); background: var(--card-bg);
  cursor: pointer; color: var(--text-primary); margin-left: 5px;
  white-space: nowrap;
}
#bgmList button:hover { background-color: var(--accent-color); color: #121212; border-color: var(--accent-color); }

/* 4. 탭 & 리스트 */
.main-content-card { padding: 0; overflow: hidden; min-height: 400px; display: flex; flex-direction: column; }

.tabs {
  display: flex;
  background-color: var(--bg-color);
  border-bottom: 1px solid var(--border-color);
}

.tab-button {
  flex: 1;
  padding: 15px;
  border: none;
  background: transparent;
  font-size: 16px;
  font-weight: bold;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.2s;
  border-bottom: 3px solid transparent;
}
.tab-button.active {
  background-color: var(--card-bg);
  color: var(--text-primary);
  border-bottom-color: var(--accent-color);
}

.tab-body { padding: 20px; flex: 1; display: flex; flex-direction: column; }
.tab-content { display: none; height: 100%; }
.tab-content.active { display: flex; flex-direction: column; height: 100%; }

.list-view {
  list-style: none;
  padding: 0;
  margin: 0;
  flex: 1;
  overflow-y: auto;
}

.list-view li {
  background-color: var(--bg-color);
  margin-bottom: 10px;
  padding: 12px 15px;
  border-radius: 8px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: var(--shadow-sm);
  transition: background-color 0.2s;
}
/* 스크롤바 방지: 배경색 변경 */
.list-view li:hover { background-color: rgba(0,0,0,0.05); } 
body.dark-mode .list-view li:hover { background-color: rgba(255,255,255,0.05); }

/* 연주 중 강조 스타일 */
.list-view li.playing {
    background-color: rgba(255, 215, 0, 0.15) !important;
    border: 1px solid #FFD700;
    color: #FFD700;
    font-weight: bold;
}
body.dark-mode .list-view li.playing {
    background-color: rgba(255, 215, 0, 0.1) !important;
}
/* 연주 중일 때 버튼도 강조 */
.list-view li.playing .play-button {
    background-color: #FFD700;
    color: #121212;
    border: none;
}

/* 텍스트 영역 가변 너비 설정 */
.notice-text, .song-text { 
  padding: 5px; 
  padding-left: 10px;
  user-select: text; 
  cursor: auto;
  flex: 1; 
  min-width: 0; 
  margin-right: 10px; 
  font-size: 16px; 
  font-weight: 500; 
}

/* 신청곡 버튼 그룹 */
.button-group { 
  display: flex; 
  gap: 5px; 
  flex-shrink: 0; 
}
.button-container .button-group:first-child { margin-bottom: 5px; }

.button-group button, .small-btn {
  padding: 5px 12px; font-size: 13px; border-radius: 6px;
  border: 1px solid var(--border-color); background: var(--card-bg);
  cursor: pointer; color: var(--text-primary);
  white-space: nowrap; 
}
.button-group button:hover, .small-btn:hover { background-color: var(--accent-color); color: #121212; border-color: var(--accent-color); }

.yumakase-button, .play-button { 
  min-width: 80px; 
  text-align: center;
  justify-content: center;
}

.footer-actions {
  margin-top: 20px;
  padding-top: 15px;
  border-top: 1px solid var(--border-color);
  display: flex;
  gap: 15px;
}
.text-btn {
  background: none; border: none; color: var(--text-secondary); cursor: pointer; font-size: 14px; display: flex; align-items: center; gap: 5px; white-space: nowrap;
}
.text-btn:hover { color: var(--accent-color); }

/* --- 푸터 --- */
.footer { text-align: center; padding: 30px 0; color: var(--text-secondary); font-size: 12px; }
.footer .credits { margin-top: 5px; opacity: 0.7; }

/* --- 팝업 (모달) --- */
.popup, .modal {
  display: none; position: fixed; z-index: 1000; left: 0; top: 0; width: 100%; height: 100%;
  background-color: rgba(0,0,0,0.5); backdrop-filter: blur(4px);
}
.popup-content, .modal-content {
  background-color: var(--card-bg);
  margin: 5% auto;
  padding: 0;
  border-radius: 16px;
  width: 90%; max-width: 800px;
  max-height: 85vh;
  display: flex; flex-direction: column;
  box-shadow: 0 10px 25px rgba(0,0,0,0.2);
  position: relative;
  overflow: hidden;
}
.modal-content { max-width: 400px; padding: 30px; text-align: center; margin-top: 20vh; }

.popup-content h2 { margin: 0; padding: 20px; background: var(--bg-color); font-size: 18px; border-bottom: 1px solid var(--border-color); }

/* 닫기 버튼 스타일 */
.popup .close {
  position: absolute;
  right: 20px;
  top: 15px;
  font-size: 28px;
  cursor: pointer;
  color: var(--text-secondary);
  background: transparent;
  border: none;
  width: 40px; height: 40px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%;
  transition: background 0.2s;
  z-index: 10;
}
.popup .close:hover { background-color: rgba(0,0,0,0.1); color: var(--text-primary); }
body.dark-mode .popup .close:hover { background-color: rgba(255,255,255,0.1); }


.popup-toolbar, .history-controls {
  padding: 15px 20px;
  display: flex; justify-content: space-between; align-items: center;
  border-bottom: 1px solid var(--border-color);
  background-color: var(--card-bg);
  flex-wrap: wrap; gap: 10px;
}

.table-scroll-container {
  overflow: auto; flex: 1; padding: 20px;
}

/* 팝업 테이블 스타일 */
.popup table { width: 100%; border-collapse: collapse; }
.popup th, .popup td { padding: 10px; border-bottom: 1px solid var(--border-color); text-align: center; }
.popup th { background-color: var(--bg-color); position: sticky; top: 0; color: var(--text-secondary); font-size: 14px; }

/* 다운로드 버튼 */
#downloadHistoryButton {
  font-size: 14px; padding: 8px 15px; border-radius: 6px;
  background-color: var(--accent-color); border: none;
  cursor: pointer; font-weight: bold; color: #121212;
  transition: all 0.2s;
  white-space: nowrap;
}
#downloadHistoryButton:hover { filter: brightness(0.95); transform: translateY(-1px); }

/* 작은 버튼들 */
.small-btn {
  padding: 6px 12px; border-radius: 6px; border: 1px solid var(--border-color);
  background: var(--bg-color); cursor: pointer; color: var(--text-primary); white-space: nowrap;
}
.small-btn.primary { background: var(--accent-color); border: none; color: #121212; }
.small-btn.success { background: #2e7d32; color: white; border: none; }

/* 월간 계획표 팝업 헤더 */
#monthlyPlanHeader {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 20px;
  padding: 15px;
  background-color: var(--card-bg);
}
#monthlyPlanHeader h2 {
  margin: 0; padding: 0; border: none; background: transparent; font-size: 20px;
}

#monthlyCalendarContainer { padding: 20px; overflow-x: auto; }
/* 월간 캘린더 테이블 고정 레이아웃 적용 */
#monthlyCalendarTable { 
  width: 100%; 
  min-width: 600px; 
  border-collapse: collapse; 
  table-layout: fixed; /* 폭 고정 */
}
#monthlyCalendarTable th, #monthlyCalendarTable td {
  border: 1px solid var(--border-color); 
  padding: 5px; 
  vertical-align: top;
  word-break: break-all; /* 내용이 길면 줄바꿈 */
}
#monthlyCalendarTable th { 
  background: var(--bg-color); 
  text-align: center; 
  padding: 10px; 
  font-weight: bold; 
  width: 14.28%; /* 7등분 */
}
#monthlyCalendarTable td { height: 100px; }
#monthlyCalendarTable .day-header { font-weight: bold; margin-bottom: 5px; display: block; }

/* 월간 캘린더 색상 */
#monthlyCalendarTable .day-sat { color: var(--sat-color); }
#monthlyCalendarTable .day-sun { color: var(--sun-color); }
#monthlyCalendarTable .day-today { 
  background-color: rgba(255, 215, 0, 0.15); /* 연한 노란색 배경 */
  border: 2px solid var(--accent-color) !important; 
}
body.dark-mode #monthlyCalendarTable .day-today { background-color: rgba(255, 215, 0, 0.1); }

/* 지난달/다음달 날짜 흐리게 처리 */
#monthlyCalendarTable .day-other-month {
  background-color: #f9f9f9; /* 살짝 어두운 배경 */
  opacity: 0.5; /* 흐리게 */
  color: #ccc; /* 글자색도 연하게 */
  pointer-events: none;
}

body.dark-mode #monthlyCalendarTable .day-other-month {
  background-color: rgba(0, 0, 0, 0.3); /* 다크모드에선 더 어둡게 */
  opacity: 0.4;
  color: #666;
}

.plan-item { background: var(--bg-color); padding: 2px 5px; margin-top: 2px; border-radius: 4px; font-size: 12px; display: block; }

/* 월간 팝업 버튼 스타일 */
.round-icon-btn {
  width: 36px; height: 36px; border-radius: 50%; border: 1px solid var(--border-color);
  background: var(--bg-color); color: var(--text-primary); cursor: pointer;
  display: flex; align-items: center; justify-content: center; font-size: 16px;
  transition: all 0.2s;
}
.round-icon-btn:hover { background-color: var(--border-color); }
.icon-btn { 
  border: none; background: transparent; color: var(--text-secondary); 
  cursor: pointer; font-size: 14px; display: flex; align-items: center; gap: 5px; 
}
.icon-btn:hover { color: var(--text-primary); }

/* ✅ 모바일 화면 강제 정렬 (BGM, 신청곡 UI 통일) */
@media (max-width: 768px) {
  
  /* 1. 기본 레이아웃 및 가로 스크롤 방지 */
  body, html {
    overflow-x: hidden !important;
    width: 100% !important;
    max-width: 100vw !important;
  }

  .main-container, .card { 
    width: 100% !important;
    box-sizing: border-box !important;
    overflow: hidden !important;
  }

  /* 2. 테이블 스크롤 격리 */
  .table-wrapper {
    display: block !important;
    width: 100% !important;
    overflow-x: auto !important;
  }
  
  #weeklyPlanTable {
    width: max-content !important;
    min-width: 600px; 
  }

  /* 3. 입력창과 버튼 세로 배치 강제 */
  .input-group, 
  .input-group.full-width {
    display: flex !important;
    flex-direction: column !important;
    width: 100% !important;
    gap: 10px !important;
    margin: 10px 0 !important;
  }
  
  input[type="text"], textarea {
    width: 100% !important;
    margin: 0 !important;
  }

  .action-btn, 
  .input-group button {
    width: 100% !important;
    margin: 0 !important;
    padding: 12px 0 !important;
  }

  /* 4. [수정됨] 리스트 아이템 (신청곡 + BGM) 스타일 통일 */
  /* 신청곡(.list-view li)과 BGM(#bgmList li) 모두 적용 */
  .list-view li, 
  #bgmList li {
    display: flex !important;
    flex-direction: column !important; /* 세로 정렬 */
    align-items: stretch !important; /* 가로 꽉 채우기 */
    padding: 15px !important;
    height: auto !important;
    gap: 10px !important; /* 텍스트와 버튼 사이 간격 */
  }
  
  /* 텍스트 영역 스타일 */
  .song-text, 
  .notice-text,
  #bgmList li > span { /* BGM 텍스트도 포함 */
    display: block !important;
    width: 100% !important;
    margin-bottom: 5px !important;
    white-space: pre-wrap !important;
    word-break: break-all !important;
  }

  /* 버튼 컨테이너 */
  .button-container,
  #bgmList .button-group {
    width: 100% !important;
    display: flex !important;
    flex-direction: row !important; /* 버튼끼리는 가로로 */
    justify-content: space-between !important;
    gap: 5px !important;
    margin-top: 0 !important;
  }
  
  /* 신청곡 버튼 그룹 (2단 분리 대응) */
  .button-container {
     flex-direction: column !important; /* 신청곡은 버튼 줄이 많아서 세로 */
  }

  /* 모든 버튼 꽉 차게 */
  .button-group, .button-container .button-group {
    display: flex !important;
    width: 100% !important;
    gap: 5px !important;
  }
  
  .button-group button, .small-btn {
    flex: 1 !important; /* 버튼 크기 균등 분할 */
    padding: 10px 0 !important;
    text-align: center;
  }
}