/* === 페이지영어학원 관리시스템 === */
:root {
  --bg: #f5f6fa;
  --surface: #ffffff;
  --border: #e5e7eb;
  --text: #1f2937;
  --text-mute: #6b7280;
  --primary: #4f46e5;
  --primary-soft: #eef2ff;
  --success: #10b981;
  --warn: #f59e0b;
  --danger: #ef4444;
  --info: #3b82f6;
  --radius: 10px;
  --sb-w: 220px;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; font-family: 'Segoe UI', 'Malgun Gothic', sans-serif; background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.5; }
button { font-family: inherit; cursor: pointer; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* === Layout === */
.layout { display: flex; min-height: 100vh; }
.sidebar { width: var(--sb-w); background: #111827; color: #e5e7eb; flex: 0 0 var(--sb-w); display: flex; flex-direction: column; }
.sidebar .brand { padding: 18px 20px; border-bottom: 1px solid #1f2937; }
.sidebar .brand .name { font-size: 16px; font-weight: 700; color: #fff; }
.sidebar .brand .sub { font-size: 11px; color: #9ca3af; margin-top: 2px; }
.sidebar nav { flex: 1; padding: 10px 0; }
.sidebar nav a { display: flex; align-items: center; gap: 10px; padding: 10px 20px; color: #d1d5db; font-size: 13px; }
.sidebar nav a:hover { background: #1f2937; color: #fff; text-decoration: none; }
.sidebar nav a.active { background: var(--primary); color: #fff; }
.sidebar nav a .icon { width: 18px; text-align: center; }
.sidebar nav a .badge { margin-left: auto; background: var(--danger); color: #fff; border-radius: 10px; padding: 1px 7px; font-size: 11px; }
.sidebar .foot { padding: 14px 20px; border-top: 1px solid #1f2937; font-size: 11px; color: #6b7280; }
/* 브랜드 영역 동기화 정보 (상단 고정 표시) */
.sidebar .brand-sync {
  margin-top: 10px; padding-top: 9px; border-top: 1px solid #1f2937;
  font-size: 11px; color: #9ca3af; line-height: 1.6;
}
.sidebar .brand-sync .brand-ver { color: #6b7280; margin-top: 3px; font-size: 10px; }

.main { flex: 1; min-width: 0; padding: 24px 32px; }

/* === 전역 상단바 (검색 + 즐겨찾기) — 스크롤해도 상단 고정 === */
.global-bar {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  background: #fff; border: 1px solid var(--border); border-radius: 10px;
  padding: 8px 12px; margin-bottom: 16px;
  position: sticky; top: 0; z-index: 150;
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}

/* === 맨 위로(TOP) 버튼 — 우측 하단 고정 === */
.scroll-top-btn {
  position: fixed; right: 22px; bottom: 24px; z-index: 300;
  width: 46px; height: 46px; border-radius: 50%;
  background: #4f46e5; color: #fff; border: none; cursor: pointer;
  font-size: 18px; font-weight: 700;
  box-shadow: 0 4px 14px rgba(79,70,229,0.4);
  display: none; align-items: center; justify-content: center;
  transition: opacity .2s, transform .15s;
}
.scroll-top-btn:hover { transform: translateY(-2px); background: #4338ca; }
.scroll-top-btn.show { display: flex; }
@media print { .scroll-top-btn { display: none !important; } }
.gbar-search { position: relative; flex: 0 0 320px; max-width: 320px; }
.gbar-input {
  width: 100%; padding: 7px 12px; border: 1px solid #d1d5db;
  border-radius: 8px; font-size: 13px; box-sizing: border-box;
}
.gbar-input:focus { outline: 2px solid #c7d2fe; border-color: #6366f1; }
.gbar-dropdown {
  position: absolute; top: 38px; left: 0; right: 0; z-index: 200;
  background: #fff; border: 1px solid #d1d5db; border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.14); max-height: 360px; overflow-y: auto;
}
.gbar-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 7px 12px; font-size: 13px; border-bottom: 1px solid #f3f4f6;
}
.gbar-item:last-child { border-bottom: none; }
.gbar-item.muted { color: #9ca3af; justify-content: center; }
.gbar-item-go { flex: 1; cursor: pointer; }
.gbar-item-go:hover { color: #4f46e5; font-weight: 600; }
.gbar-star { cursor: pointer; font-size: 16px; color: #d1d5db; padding: 0 4px; }
.gbar-star.on { color: #f59e0b; }
.gbar-favs { display: flex; gap: 6px; flex-wrap: wrap; flex: 1; align-items: center; }
.gbar-fav-hint { font-size: 11.5px; color: #9ca3af; }
.gbar-fav-chip {
  background: #eef2ff; color: #4338ca; border: 1px solid #c7d2fe;
  border-radius: 14px; padding: 4px 11px; font-size: 12px; font-weight: 600;
  cursor: pointer; white-space: nowrap;
}
.gbar-fav-chip:hover { background: #4f46e5; color: #fff; }
.gbar-undo {
  background: #fef3c7; color: #92400e; border: 1px solid #fcd34d;
  border-radius: 8px; padding: 5px 12px; font-size: 12px; font-weight: 700; cursor: pointer;
}
.gbar-undo:hover { background: #f59e0b; color: #fff; }
@media (max-width: 720px) {
  .gbar-search { flex: 1 1 100%; max-width: none; }
}

.topbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.topbar h1 { margin: 0; font-size: 20px; }
.topbar .actions { display: flex; gap: 8px; }

/* === Common === */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; margin-bottom: 16px; }
.card h2 { margin: 0 0 12px; font-size: 15px; }
.card h3 { margin: 0 0 10px; font-size: 13px; color: var(--text-mute); font-weight: 600; }
.grid { display: grid; gap: 16px; }
.grid.cols-2 { grid-template-columns: repeat(2, 1fr); }
.grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
.grid.cols-4 { grid-template-columns: repeat(4, 1fr); }
.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }
.row.between { justify-content: space-between; }

.btn { padding: 8px 14px; border: 1px solid var(--border); background: #fff; border-radius: 8px; font-size: 13px; }
.btn:hover { background: #f9fafb; }
.btn.primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn.primary:hover { background: #4338ca; }
.btn.success { background: var(--success); color: #fff; border-color: var(--success); }
.btn.danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn.ghost { background: transparent; }
.btn.sm { padding: 4px 10px; font-size: 12px; }
.btn.xs { padding: 2px 8px; font-size: 11px; }

input, select, textarea { font-family: inherit; font-size: 13px; padding: 7px 10px; border: 1px solid var(--border); border-radius: 6px; background: #fff; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary-soft); border-color: var(--primary); }
textarea { resize: vertical; min-height: 60px; }
label.field { display: block; margin-bottom: 10px; }
label.field > span { display: block; font-size: 12px; color: var(--text-mute); margin-bottom: 4px; }
label.field input, label.field select, label.field textarea { width: 100%; }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
table th, table td { padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
table th { background: #f9fafb; font-weight: 600; font-size: 12px; color: var(--text-mute); position: sticky; top: 0; }
table tr:hover { background: #fafbfc; }
.table-wrap { overflow: auto; max-height: 70vh; border: 1px solid var(--border); border-radius: var(--radius); background: #fff; }

.tag { display: inline-block; padding: 2px 8px; border-radius: 99px; font-size: 11px; background: #f3f4f6; color: var(--text); }
.tag.success { background: #d1fae5; color: #065f46; }
.tag.warn { background: #fef3c7; color: #92400e; }
.tag.danger { background: #fee2e2; color: #991b1b; }
.tag.info { background: #dbeafe; color: #1e40af; }
.tag.muted { background: #f3f4f6; color: var(--text-mute); }

.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
.kpi .label { font-size: 12px; color: var(--text-mute); margin-bottom: 6px; }
.kpi .value { font-size: 24px; font-weight: 700; }
.kpi .delta { font-size: 12px; margin-top: 4px; }
.kpi .delta.up { color: var(--success); }
.kpi .delta.down { color: var(--danger); }
.kpi.danger .value { color: var(--danger); }
.kpi.success .value { color: var(--success); }
.kpi.warn .value { color: var(--warn); }

.dropzone { border: 2px dashed #cbd5e1; border-radius: var(--radius); padding: 30px; text-align: center; background: #f9fafb; transition: all 0.2s; cursor: pointer; }
.dropzone:hover, .dropzone.over { border-color: var(--primary); background: var(--primary-soft); }
.dropzone .big { font-size: 18px; font-weight: 600; margin-bottom: 6px; }
.dropzone .small { font-size: 12px; color: var(--text-mute); }

.muted { color: var(--text-mute); }
.right { text-align: right; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }
.mt-0 { margin-top: 0; } .mt-8 { margin-top: 8px; } .mt-16 { margin-top: 16px; }
.mb-0 { margin-bottom: 0; } .mb-8 { margin-bottom: 8px; } .mb-16 { margin-bottom: 16px; }
.mono { font-family: 'Consolas', monospace; }
.amount { font-family: 'Consolas', monospace; font-weight: 600; }
.amount.pos { color: var(--success); }
.amount.neg { color: var(--danger); }

/* === Login === */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); }
.login-box { background: #fff; padding: 36px 40px; border-radius: 16px; min-width: 360px; box-shadow: 0 20px 50px rgba(0,0,0,0.2); }
.login-box h1 { margin: 0 0 6px; font-size: 22px; }
.login-box .sub { color: var(--text-mute); margin-bottom: 24px; }

/* === Onboarding === */
.onboard { background: var(--surface); border-radius: var(--radius); padding: 40px; max-width: 720px; margin: 40px auto; }
.onboard h1 { margin: 0 0 8px; }
.onboard .step { display: flex; gap: 16px; margin: 20px 0; align-items: flex-start; }
.onboard .step .num { background: var(--primary); color: #fff; border-radius: 50%; width: 32px; height: 32px; flex: 0 0 32px; display: flex; align-items: center; justify-content: center; font-weight: 700; }
.onboard .step .body strong { display: block; margin-bottom: 4px; }
.onboard .step .body .desc { color: var(--text-mute); font-size: 13px; }

/* === Modal === */
.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,0.4); display: flex; align-items: center; justify-content: center; z-index: 100; }
.modal { background: #fff; border-radius: var(--radius); padding: 24px; max-width: 600px; width: 92%; max-height: 86vh; overflow: auto; }
.modal h2 { margin: 0 0 14px; font-size: 18px; }
.modal .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }

/* === Student Card === */
.student-head { display: flex; gap: 24px; align-items: center; margin-bottom: 20px; }
.student-head .avatar { width: 70px; height: 70px; border-radius: 50%; background: var(--primary); color: #fff; display: flex; align-items: center; justify-content: center; font-size: 24px; font-weight: 700; }
.student-head .info h2 { margin: 0; font-size: 22px; }
.student-head .info .meta { color: var(--text-mute); font-size: 13px; margin-top: 4px; }

.note { padding: 10px 14px; border-left: 3px solid var(--primary); background: #f9fafb; border-radius: 4px; margin-bottom: 8px; }
.note .meta { font-size: 11px; color: var(--text-mute); margin-bottom: 4px; }

/* === Attendance grid === */
.att-table { font-size: 11px; }
.att-table th, .att-table td { padding: 4px 6px; text-align: center; min-width: 24px; border: 1px solid #e5e7eb; }
.att-table .name { text-align: left; min-width: 80px; font-weight: 600; }
.att-table .class { text-align: left; min-width: 140px; }
.att-table td.day { cursor: pointer; }
.att-table td.day:hover { background: var(--primary-soft); }
.att-table td.holiday { background: #fee2e2; color: #991b1b; }
.att-table td.weekend { background: #f3f4f6; }
.att-table .mark-O { color: var(--success); font-weight: 700; }
.att-table .mark-X { color: var(--danger); font-weight: 700; }
.att-table .mark-S { color: var(--warn); font-weight: 700; }
.att-table .mark-T { color: var(--info); font-weight: 700; }

/* === Action queue === */
.action-item { display: flex; gap: 12px; padding: 12px 14px; border: 1px solid var(--border); border-radius: 8px; margin-bottom: 8px; background: #fff; }
.action-item .ico { font-size: 20px; }
.action-item .body { flex: 1; }
.action-item .body .title { font-weight: 600; margin-bottom: 4px; }
.action-item .body .desc { color: var(--text-mute); font-size: 12px; }
.action-item .body .copy-box { margin-top: 8px; padding: 8px 12px; background: #f9fafb; border: 1px solid var(--border); border-radius: 6px; font-size: 12px; white-space: pre-wrap; }
.action-item .actions-r { display: flex; flex-direction: column; gap: 4px; }

/* === Print (학부모 리포트 인쇄 전용) === */
@media print {
  .sidebar, .topbar, .no-print, .modal-bg { display: none !important; }
  .main { padding: 0 !important; }
  body, html { background: #fff !important; margin: 0; padding: 0; }
  .layout { display: block !important; }
  .card { border: none !important; box-shadow: none !important; page-break-inside: avoid; margin-bottom: 8px !important; padding: 0 !important; }
  .report-body { max-width: 100% !important; padding: 0 !important; }
  .kpi { border: 1px solid #e5e7eb !important; padding: 8px !important; }
  canvas { max-width: 100% !important; max-height: 200px !important; }
  table { font-size: 11px !important; }
  h1 { font-size: 18px !important; }
  h2 { font-size: 14px !important; margin-top: 12px !important; }
  h3 { font-size: 12px !important; }
}

/* === Responsive === */
/* === 모바일 햄버거 메뉴 === */
.mobile-topbar { display: none; }
.sidebar-backdrop { display: none; }

@media (max-width: 900px) {
  /* 상단 모바일 바 (햄버거 + 학원명) */
  .mobile-topbar {
    display: flex; align-items: center; gap: 12px;
    position: sticky; top: 0; z-index: 1200;
    background: #111827; color: #fff; padding: 10px 14px;
  }
  .mobile-topbar .hamburger {
    background: none; border: 1px solid #374151; color: #fff;
    width: 38px; height: 38px; border-radius: 8px; font-size: 18px; cursor: pointer;
  }
  .mobile-topbar .mt-title { font-size: 15px; font-weight: 700; }

  /* 사이드바 — 기본 숨김, 열리면 슬라이드 인 */
  .sidebar {
    display: flex;
    position: fixed; top: 0; left: 0; bottom: 0; z-index: 1300;
    transform: translateX(-100%); transition: transform 0.25s ease;
    width: 260px; flex: 0 0 260px; overflow-y: auto;
    box-shadow: 4px 0 24px rgba(0,0,0,0.3);
  }
  body.sidebar-open .sidebar { transform: translateX(0); }
  body.sidebar-open .sidebar-backdrop {
    display: block; position: fixed; inset: 0; z-index: 1250;
    background: rgba(0,0,0,0.5);
  }

  .grid.cols-4 { grid-template-columns: repeat(2, 1fr); }
  .grid.cols-3 { grid-template-columns: 1fr; }
  .grid.cols-2 { grid-template-columns: 1fr; }
  .main { padding: 16px; }
}

/* ═══════════════════════════════════════════════════════════════
   모바일 UX 보강 — 터치 영역, 가상키보드, 입력 폼
   ═══════════════════════════════════════════════════════════════ */
@media (max-width: 900px) {
  /* 모든 클릭 가능한 요소는 최소 44×44px (애플 HIG / 구글 머터리얼 기준) */
  button, .btn, a.btn, input[type="button"], input[type="submit"], select {
    min-height: 44px;
  }
  /* 사이즈 small/xs 는 예외적으로 36px */
  button.xs, .btn.xs { min-height: 36px; }

  /* 폼 입력 — 가로 한 줄에 강제로 욱여넣지 않고 세로로 흐르게 */
  .form-row, .form-group {
    flex-direction: column !important;
    align-items: stretch !important;
  }
  input[type="text"], input[type="email"], input[type="tel"], input[type="number"],
  input[type="password"], input[type="date"], input[type="search"], textarea, select {
    width: 100%;
    box-sizing: border-box;
    font-size: 16px;       /* iOS Safari 자동 줌 방지 (16px 미만이면 입력 시 줌인) */
    min-height: 44px;
  }
  textarea { min-height: 80px; }

  /* 모달 — 화면 꽉 채우되 여백, 가상키보드 대응 */
  .modal-bg .modal {
    max-width: 100vw;
    max-height: 100vh;
    width: 100vw;
    border-radius: 0;
    padding-bottom: env(safe-area-inset-bottom, 24px);
  }

  /* 표 — 모바일에선 가로 스크롤 허용 */
  .table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* 글로벌 바 — 줄바꿈 허용 (검색 + 새로고침 같이 안 보일 때) */
  .global-bar {
    flex-wrap: wrap;
    gap: 6px;
  }
}

/* 노치/안전영역 대응 (아이폰 X 이상) */
@supports (padding: max(0px)) {
  body { padding-bottom: env(safe-area-inset-bottom); }
}
