/* =========================================
   ClassMate - 공통 스타일
   ========================================= */

/* ---- 폰트 (@font-face) ---- */
@font-face { font-family: 'NanumGothic';       src: url('/font/NanumGothic.ttf') format('truetype');       font-weight: 400; }
@font-face { font-family: 'NanumGothic';       src: url('/font/NanumGothicBold.ttf') format('truetype');   font-weight: 700; }
@font-face { font-family: 'NanumBarunGothic';  src: url('/font/NanumBarunGothic.ttf') format('truetype');  font-weight: 400; }
@font-face { font-family: 'NanumBarunGothic';  src: url('/font/NanumBarunGothicBold.ttf') format('truetype'); font-weight: 700; }
@font-face { font-family: 'NanumMyeongjo';     src: url('/font/NanumMyeongjo.ttf') format('truetype');     font-weight: 400; }
@font-face { font-family: 'NanumMyeongjo';     src: url('/font/NanumMyeongjoBold.ttf') format('truetype'); font-weight: 700; }
@font-face { font-family: 'NanumSquare';       src: url('/font/NanumSquareR.ttf') format('truetype');      font-weight: 400; }
@font-face { font-family: 'NanumSquare';       src: url('/font/NanumSquareB.ttf') format('truetype');      font-weight: 700; }
@font-face { font-family: 'NanumSquareRound';  src: url('/font/NanumSquareRoundR.ttf') format('truetype'); font-weight: 400; }
@font-face { font-family: 'NanumSquareRound';  src: url('/font/NanumSquareRoundB.ttf') format('truetype'); font-weight: 700; }
@font-face { font-family: 'GgyeonggiCheonnyon'; src: url('/font/%EA%B2%BD%EA%B8%B0%EC%B2%9C%EB%85%84%EB%B0%94%ED%83%95_Regular.ttf') format('truetype'); font-weight: 400; }
@font-face { font-family: 'GgyeonggiCheonnyon'; src: url('/font/%EA%B2%BD%EA%B8%B0%EC%B2%9C%EB%85%84%EB%B0%94%ED%83%95_Bold.ttf') format('truetype'); font-weight: 700; }
@font-face { font-family: 'A2J';               src: url('/font/%EC%97%90%EC%9D%B4%ED%88%AC%EC%A7%80%EC%B2%B4-4Regular.ttf') format('truetype');  font-weight: 400; }
@font-face { font-family: 'A2J';               src: url('/font/%EC%97%90%EC%9D%B4%ED%88%AC%EC%A7%80%EC%B2%B4-7Bold.ttf') format('truetype');    font-weight: 700; }

:root {
  --primary: #7c3aed;
  --primary-hover: #6d28d9;
  --primary-light: #f5f3ff;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --bg: #f1f5f9;
  --card: #ffffff;
  --text: #0f172a;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --shadow: 0 1px 3px rgba(0,0,0,.1), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md: 0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.06);
  --radius: 12px;
  --radius-sm: 8px;
}

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

body {
  font-family: var(--font-body, 'A2J', 'Apple SD Gothic Neo', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  font-size: 15px;
  line-height: 1.6;
}

/* ---- 레이아웃 ---- */
.container { max-width: 1100px; margin: 0 auto; padding: 0 20px; }

/* ---- 헤더 ---- */
.app-header {
  background: #fff;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow);
}
.app-header .inner {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 20px;
  max-width: 1100px;
  margin: 0 auto;
}
.app-header .logo { font-size: 1.2rem; font-weight: 700; color: var(--primary); text-decoration: none; }
.app-header .logo span { font-size: 1.3rem; }
.app-header .spacer { flex: 1; }
.app-header .user-info { color: var(--text-muted); font-size: .9rem; }
.btn-back {
  background: none; border: none; cursor: pointer;
  color: var(--text-muted); font-size: .9rem;
  padding: 6px 10px; border-radius: 6px; display: flex; align-items: center; gap: 4px;
}
.btn-back:hover { background: var(--bg); color: var(--text); }

/* ---- 카드 ---- */
.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
}
.card-title {
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ---- 버튼 ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 20px; border-radius: var(--radius-sm);
  font-size: .95rem; font-weight: 600;
  border: none; cursor: pointer; transition: all .15s;
  text-decoration: none;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); transform: translateY(-1px); box-shadow: 0 4px 12px rgba(124,58,237,.35); }
.btn-secondary { background: var(--bg); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--border); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #dc2626; }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { background: #059669; }
.btn-sm { padding: 6px 14px; font-size: .85rem; }
.btn-lg { padding: 14px 28px; font-size: 1.1rem; border-radius: 10px; }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none !important; }

/* ---- 폼 ---- */
.form-group { margin-bottom: 16px; }
.form-label { display: block; font-size: .85rem; font-weight: 600; color: var(--text-muted); margin-bottom: 6px; }
.form-control {
  width: 100%; padding: 10px 14px;
  border: 1.5px solid var(--border); border-radius: var(--radius-sm);
  font-size: .95rem; transition: border-color .15s;
  background: #fff; color: var(--text);
}
.form-control:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(124,58,237,.12); }
select.form-control { cursor: pointer; }

/* ---- 알림 ---- */
.alert {
  padding: 12px 16px; border-radius: var(--radius-sm);
  font-size: .9rem; margin-bottom: 16px;
}
.alert-error { background: #fef2f2; color: #dc2626; border: 1px solid #fecaca; }
.alert-success { background: #f0fdf4; color: #16a34a; border: 1px solid #bbf7d0; }
.alert-info { background: var(--primary-light); color: var(--primary); border: 1px solid rgba(124,58,237,.25); }

/* ---- 페이지 래퍼 ---- */
.page { padding: 28px 0 60px; }
.page-title { font-size: 1.5rem; font-weight: 700; margin-bottom: 6px; }
.page-sub { color: var(--text-muted); font-size: .9rem; margin-bottom: 24px; }

/* ---- 그리드 ---- */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px; }

/* ---- 반응형 ---- */
@media (max-width: 768px) {
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .card { padding: 18px; }
}

/* ---- 로딩 스피너 ---- */
.spinner {
  width: 24px; height: 24px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%; animation: spin .6s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- 태그/배지 ---- */
.badge {
  display: inline-block; padding: 2px 10px;
  border-radius: 100px; font-size: .78rem; font-weight: 600;
}
.badge-blue { background: #dbeafe; color: #1e40af; }
.badge-green { background: #d1fae5; color: #065f46; }
.badge-orange { background: #ffedd5; color: #9a3412; }
.badge-purple { background: #ede9fe; color: #5b21b6; }

/* =========================================
   로그인 페이지
   ========================================= */
.login-page {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #ede9fe 0%, #faf5ff 100%);
  padding: 20px;
}
.login-card {
  background: #fff;
  border-radius: 20px;
  box-shadow: 0 20px 60px rgba(0,0,0,.12);
  padding: 44px 40px;
  width: 100%; max-width: 420px;
}
.login-logo {
  text-align: center; margin-bottom: 32px;
}
.login-logo .icon { font-size: 3rem; }
.login-logo h1 { font-size: 1.8rem; font-weight: 800; color: var(--primary); margin-top: 8px; }
.login-logo p { color: var(--text-muted); font-size: .9rem; margin-top: 4px; }
.login-tabs { display: flex; gap: 4px; background: var(--bg); padding: 4px; border-radius: 8px; margin-bottom: 24px; }
.login-tab {
  flex: 1; padding: 8px; text-align: center; border-radius: 6px;
  font-size: .9rem; font-weight: 600; cursor: pointer; border: none;
  background: transparent; color: var(--text-muted); transition: all .15s;
}
.login-tab.active { background: #fff; color: var(--primary); box-shadow: var(--shadow); }

/* =========================================
   대시보드
   ========================================= */
.dashboard-header { margin-bottom: 28px; }
.dashboard-header h2 { font-size: 1.4rem; font-weight: 700; }
.dashboard-header p { color: var(--text-muted); margin-top: 4px; }
.tools-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 18px;
}
.tool-card {
  background: #fff;
  border-radius: 16px;
  padding: 28px 20px;
  text-align: center;
  cursor: pointer;
  transition: all .2s;
  text-decoration: none;
  color: var(--text);
  box-shadow: var(--shadow);
  border: 2px solid transparent;
  display: flex; flex-direction: column; align-items: center; gap: 14px;
}
.tool-card:hover { transform: translateY(-4px); box-shadow: var(--shadow-md); border-color: var(--primary); }
.tool-card .tool-icon { font-size: 3rem; line-height: 1; }
.tool-card .tool-name { font-weight: 700; font-size: 1rem; }
.tool-card .tool-desc { font-size: .8rem; color: var(--text-muted); line-height: 1.4; }

/* =========================================
   학급 선택 공통
   ========================================= */
.class-selector {
  display: flex; align-items: center; gap: 12px;
  background: #fff; border-radius: var(--radius);
  padding: 16px 20px; box-shadow: var(--shadow);
  margin-bottom: 20px; flex-wrap: wrap;
}
.class-selector label { font-weight: 600; font-size: .9rem; white-space: nowrap; }
.class-selector select { flex: 1; min-width: 150px; }

/* =========================================
   발표자 뽑기
   ========================================= */
.picker-stage {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  min-height: 240px; background: linear-gradient(135deg, var(--primary-hover), var(--primary));
  border-radius: var(--radius); color: #fff; text-align: center; padding: 32px;
}
.picker-result-name {
  font-weight: 800; letter-spacing: -.02em;
  animation: popIn .4s cubic-bezier(.34, 1.56, .64, 1);
  width: 100%; text-align: center; white-space: nowrap; line-height: 1.1;
}
@keyframes popIn { from { transform: scale(0.5); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.picker-result-num { font-size: 1rem; opacity: .8; margin-top: 4px; }
.picker-placeholder { font-size: 1.2rem; opacity: .7; }

.history-list { list-style: none; max-height: calc(100vh - 260px); overflow-y: auto; }
.history-list li {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 0; border-bottom: 1px solid var(--border); font-size: .9rem;
}
.history-list li:last-child { border-bottom: none; }
.history-num { color: var(--text-muted); min-width: 28px; }

/* =========================================
   자리 배정
   ========================================= */
.seat-grid-wrapper { overflow-x: auto; }
.seat-grid {
  display: inline-grid;
  gap: 6px;
  grid-template-columns: repeat(var(--cols), 72px);
}
.seat-cell {
  width: 72px; height: 68px;
  border: 2px solid var(--border); border-radius: 8px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  font-size: .82rem; font-weight: 600; background: #fff; gap: 2px;
  transition: all .15s;
}
.seat-cell.filled { border-color: var(--primary); background: var(--primary-light); }
.seat-cell.empty { border-style: dashed; background: var(--bg); }
.seat-cell .s-num { font-size: .7rem; color: var(--text-muted); }

.board-label {
  text-align: center; padding: 10px 40px;
  background: var(--primary); color: #fff; border-radius: 8px;
  font-weight: 700; margin-bottom: 12px; display: inline-block;
}
.seat-layout-container { text-align: center; }

@media print {
  .app-header, .no-print { display: none !important; }
  body { background: #fff; }
  .seat-cell { border: 1.5px solid #999; }
}

/* =========================================
   청소 당번
   ========================================= */
.zone-row {
  display: flex; align-items: center; gap: 10px;
  margin-bottom: 10px;
}
.zone-row input { flex: 1; }
.zone-row .count-input { width: 70px; text-align: center; }

.cleaning-result { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 14px; margin-top: 20px; }
.cleaning-zone-card {
  background: #fff; border-radius: var(--radius-sm);
  padding: 16px; box-shadow: var(--shadow);
  border-left: 4px solid var(--primary);
}
.cleaning-zone-name { font-weight: 700; margin-bottom: 10px; font-size: .95rem; }
.cleaning-student { font-size: .9rem; padding: 4px 0; color: var(--text); }

/* =========================================
   타이머/스톱워치
   ========================================= */
.timer-page { min-height: 100vh; }

.timer-display {
  font-size: clamp(4rem, 15vw, 10rem);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  letter-spacing: -.02em;
  line-height: 1;
  text-align: center;
  padding: 40px 0;
  color: var(--text);
  transition: color .3s;
}
.timer-display.warning { color: var(--warning); }
.timer-display.danger  { color: var(--danger); animation: pulse 1s infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .6; } }

.timer-controls { display: flex; gap: 14px; justify-content: center; flex-wrap: wrap; }
.timer-mode-tabs { display: flex; gap: 4px; background: var(--bg); padding: 4px; border-radius: 8px; margin-bottom: 32px; }
.timer-mode-tab {
  flex: 1; padding: 10px 20px; text-align: center;
  border-radius: 6px; font-size: .95rem; font-weight: 600;
  cursor: pointer; border: none; background: transparent;
  color: var(--text-muted); transition: all .15s;
}
.timer-mode-tab.active { background: var(--card); color: var(--primary); box-shadow: var(--shadow); }

.laps-list { max-height: 250px; overflow-y: auto; }
.lap-item { display: flex; justify-content: space-between; padding: 8px 0; border-bottom: 1px solid var(--border); font-size: .9rem; color: var(--text-muted); }
.lap-item .lap-time { color: var(--text); font-weight: 600; }

.timer-set-row { display: flex; gap: 10px; justify-content: center; align-items: center; margin-bottom: 20px; }
.timer-set-row input { width: 80px; text-align: center; background: var(--card); color: var(--text); border-color: var(--border); }
.timer-set-row label { font-size: .9rem; color: var(--text-muted); }

/* =========================================
   급식
   ========================================= */
.meal-card {
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}
.meal-card-header {
  background: linear-gradient(135deg, #dc2626, #f97316);
  color: #fff; padding: 20px 24px;
  display: flex; align-items: center; gap: 10px;
}
.meal-card-header .date { font-size: 1rem; font-weight: 700; }
.meal-card-header .type { font-size: .85rem; opacity: .85; }
.meal-menu {
  background: #fff; padding: 20px 24px;
}
.menu-item {
  padding: 6px 0; border-bottom: 1px solid var(--border); font-size: .95rem;
  display: flex; align-items: baseline; gap: 6px;
}
.menu-item:last-child { border-bottom: none; }
.menu-allergy { font-size: .75rem; color: var(--text-muted); }
.meal-cal { padding: 12px 24px; background: var(--bg); font-size: .85rem; color: var(--text-muted); font-weight: 600; }

.school-search-result {
  list-style: none; border: 1.5px solid var(--border); border-radius: var(--radius-sm);
  max-height: 200px; overflow-y: auto; background: #fff;
}
.school-search-result li { padding: 10px 14px; cursor: pointer; border-bottom: 1px solid var(--border); font-size: .9rem; }
.school-search-result li:hover { background: var(--primary-light); }
.school-search-result li:last-child { border-bottom: none; }

/* =========================================
   고입 상담자료
   ========================================= */
.table-wrapper { overflow-x: auto; border-radius: var(--radius-sm); box-shadow: var(--shadow); }
.data-table { width: 100%; border-collapse: collapse; background: #fff; font-size: .88rem; }
.data-table th {
  background: var(--primary); color: #fff;
  padding: 10px 14px; text-align: left;
  font-weight: 600; white-space: nowrap;
  cursor: pointer; user-select: none;
  position: sticky; top: 0;
}
.data-table th:hover { background: var(--primary-hover); }
.data-table th .sort-icon { opacity: .5; margin-left: 4px; }
.data-table th.asc .sort-icon::after { content: '↑'; }
.data-table th.desc .sort-icon::after { content: '↓'; }
.data-table th:not(.asc):not(.desc) .sort-icon::after { content: '↕'; }
.data-table td { padding: 9px 14px; border-bottom: 1px solid var(--border); white-space: nowrap; max-width: 200px; overflow: hidden; text-overflow: ellipsis; }
.data-table tr:hover td { background: var(--primary-light); }

.filter-row { display: flex; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.filter-row input { flex: 1; min-width: 200px; }

.file-item {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 18px; background: #fff;
  border-radius: var(--radius-sm); box-shadow: var(--shadow);
  margin-bottom: 10px; cursor: pointer; transition: all .15s;
}
.file-item:hover { box-shadow: var(--shadow-md); transform: translateX(2px); }
.file-icon { font-size: 2rem; }
.file-info { flex: 1; }
.file-name { font-weight: 600; font-size: .95rem; }
.file-meta { font-size: .8rem; color: var(--text-muted); margin-top: 2px; }
.file-actions { display: flex; gap: 8px; }

/* =========================================
   다크 모드
   ========================================= */
[data-theme="dark"] {
  --bg: #0f172a;
  --card: #1e293b;
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --border: #334155;
  color-scheme: dark;
}
[data-theme="dark"] body { background: var(--bg); }

[data-theme="dark"] .app-header { background: #1e293b; }
[data-theme="dark"] .login-page { background: linear-gradient(135deg, #1e293b 0%, #0f172a 100%); }
[data-theme="dark"] .login-card,
[data-theme="dark"] .modal,
[data-theme="dark"] .card,
[data-theme="dark"] .tool-card,
[data-theme="dark"] .class-selector,
[data-theme="dark"] .meal-menu,
[data-theme="dark"] .cleaning-zone-card,
[data-theme="dark"] .file-item,
[data-theme="dark"] .data-table,
[data-theme="dark"] .school-search-result { background: var(--card); }

[data-theme="dark"] .school-search-result li { background: var(--card); }
[data-theme="dark"] .school-search-result li:hover { background: #334155; }
[data-theme="dark"] .meal-cal { background: #0f172a; }

[data-theme="dark"] .form-control {
  background: #1e293b;
  color: var(--text);
  border-color: var(--border);
}
[data-theme="dark"] .btn-secondary {
  background: #1e293b;
  color: var(--text);
  border-color: var(--border);
}
[data-theme="dark"] .btn-secondary:hover { background: #334155; }
[data-theme="dark"] .class-list-item { border-color: var(--border); }
[data-theme="dark"] .class-list-item:hover { background: #334155; }
[data-theme="dark"] .data-table td { color: var(--text); }
[data-theme="dark"] .history-list li { border-bottom-color: var(--border); }
[data-theme="dark"] .tool-card { color: var(--text); }
[data-theme="dark"] .tool-card:hover { background: #334155; }
[data-theme="dark"] .student-textarea {
  background: #1e293b;
  color: var(--text);
  border-color: var(--border);
}
