/* =========================================================
   우리반 플래너 — 디자인 시스템
   ========================================================= */
:root {
  --brand: #2f6df6;
  --brand-dark: #1f54d0;
  --brand-soft: #e8f0ff;
  --accent: #19b89b;
  --warn: #e8871e;
  --danger: #e2475a;

  --ink: #1b2130;
  --ink-soft: #6b7384;
  --line: #e6eaf2;
  --bg: #f3f6fc;
  --surface: #ffffff;

  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 24px; --s6: 32px;
  --radius: 14px; --radius-lg: 20px;
  --shadow: 0 6px 20px rgba(47, 109, 246, 0.12);
  --shadow-sm: 0 2px 8px rgba(47, 109, 246, 0.08);
  --max: 480px;
  --tabbar-h: 64px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Apple SD Gothic Neo", "Noto Sans KR", sans-serif;
  color: var(--ink); background: var(--bg); line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}

.app {
  max-width: var(--max); margin: 0 auto; min-height: 100%;
  background: var(--bg); display: flex; flex-direction: column;
}

/* ---------- 공통 버튼/폼 ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s2);
  border: 0; border-radius: 12px; padding: 12px var(--s4);
  font: inherit; font-weight: 600; cursor: pointer;
}
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:active { background: var(--brand-dark); }
.btn-ghost { background: var(--brand-soft); color: var(--brand); }
.btn-outline { background: var(--surface); color: var(--brand); border: 1px solid var(--line); }
.btn-block { width: 100%; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.link { background: none; border: 0; color: var(--brand); font: inherit; cursor: pointer; text-decoration: underline; }

.field { margin-bottom: var(--s4); }
.field label { display: block; font-size: 13.5px; font-weight: 600; margin-bottom: var(--s2); }
.field .hint { font-weight: 400; color: var(--ink-soft); font-size: 12px; }
.field input, .field textarea, .field select {
  width: 100%; border: 1px solid var(--line); border-radius: 10px;
  padding: 11px var(--s3); font: inherit; color: inherit; background: var(--surface); outline: none;
}
.field input:focus, .field textarea:focus { border-color: var(--brand); }
.field textarea { resize: vertical; min-height: 72px; }

/* 비밀번호 보기 버튼 */
.pw-wrap { position: relative; }
.pw-wrap input { padding-right: 44px; }
.pw-toggle {
  position: absolute; top: 50%; right: 6px; transform: translateY(-50%);
  border: 0; background: none; cursor: pointer; font-size: 18px;
  width: 34px; height: 34px; border-radius: 8px; opacity: 0.6;
}
.pw-toggle:hover { opacity: 1; }
.pw-toggle.on { opacity: 1; }

.search {
  display: flex; align-items: center; gap: var(--s2);
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 12px; padding: 10px var(--s3);
}
.search input { flex: 1; min-width: 0; border: 0; background: none; font: inherit; color: inherit; outline: none; }

.muted { color: var(--ink-soft); }
.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: var(--s4); box-shadow: var(--shadow-sm);
}
.card + .card { margin-top: var(--s3); }
.section-title { margin: var(--s5) 0 var(--s3); }
.section-title h2 { font-size: 15px; margin: 0; }

/* ---------- 인증 화면 ---------- */
.auth-hero { text-align: center; padding: var(--s4) var(--s4) var(--s2); }
.auth-hero .logo {
  width: 52px; height: 52px; margin: 0 auto var(--s2);
  background: var(--brand-soft); border-radius: 16px;
  display: flex; align-items: center; justify-content: center; font-size: 26px;
}
.auth-hero h1 { margin: 0 0 2px; font-size: 19px; color: var(--brand); }
.auth-hero p { margin: 0; color: var(--ink-soft); font-size: 12.5px; }

.auth-card {
  margin: var(--s2) var(--s4) var(--s4); padding: var(--s4);
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius-lg); box-shadow: var(--shadow);
}
.tabs { display: flex; background: var(--bg); border-radius: 12px; padding: 4px; margin-bottom: var(--s3); }
.tabs .tab { flex: 1; border: 0; background: none; padding: 8px; border-radius: 9px; font: inherit; font-weight: 600; color: var(--ink-soft); cursor: pointer; }
.tabs .tab.active { background: var(--surface); color: var(--brand); box-shadow: var(--shadow-sm); }

/* 인증 화면 안에서는 간격을 좁혀 한 화면에 들어오게 */
#auth-view .field { margin-bottom: var(--s3); }
#auth-view .field label { margin-bottom: var(--s1); }
#auth-view .field input { padding: 9px var(--s3); }

.row3 { display: flex; gap: var(--s2); }
.row3 .field { flex: 1; }

.picked {
  display: flex; align-items: center; justify-content: space-between; gap: var(--s2);
  background: var(--brand-soft); color: var(--brand);
  border-radius: 10px; padding: 11px var(--s3); font-weight: 600; font-size: 14px;
}
.results { margin-top: var(--s2); max-height: 180px; overflow-y: auto; }
.results .result {
  width: 100%; text-align: left; border: 1px solid var(--line); background: var(--surface);
  border-radius: 10px; padding: 10px var(--s3); font: inherit; cursor: pointer; margin-top: var(--s2);
}
.results .result b { display: block; font-size: 14px; }
.results .result span { font-size: 12px; color: var(--ink-soft); }

.nick-preview {
  background: var(--brand-soft); color: var(--brand-dark);
  border-radius: 10px; padding: 8px var(--s3); font-size: 12.5px; margin-bottom: var(--s3);
}
.nick-preview b { font-weight: 700; }

.auth-msg {
  margin: var(--s2) 0 0; padding: 10px var(--s3); border-radius: 10px;
  font-size: 13px; background: #fde3e7; color: #c23047;
}
.auth-msg.ok { background: #e2f7f2; color: #0f8d77; }

/* ---------- 앱 상단바 ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  padding: var(--s4); background: var(--brand); color: #fff;
}
.topbar .title { font-size: 18px; font-weight: 700; margin: 0; }
.topbar .sub { font-size: 12px; opacity: 0.85; margin: 2px 0 0; }

.content { flex: 1; padding: var(--s4); padding-bottom: calc(var(--tabbar-h) + var(--s5)); }
.screen { display: none; }
.screen.active { display: block; }

/* ---------- 날짜 이동 ---------- */
.date-nav { display: flex; align-items: center; gap: var(--s2); margin-bottom: var(--s4); }
.date-btn {
  width: 40px; height: 40px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface); font-size: 20px; cursor: pointer; color: var(--brand);
}
.date-today {
  flex: 1; height: 40px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface); font: inherit; font-weight: 700; cursor: pointer;
}

/* ---------- 시간표 ---------- */
.period {
  display: flex; align-items: center; gap: var(--s3);
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 12px; padding: var(--s3) var(--s4); margin-bottom: var(--s2);
}
.period .num {
  width: 34px; height: 34px; flex-shrink: 0; border-radius: 10px;
  background: var(--brand-soft); color: var(--brand);
  display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 13px;
}
.period .subj { font-weight: 600; }

/* ---------- 급식 ---------- */
.meal-card { margin-bottom: var(--s3); }
.meal-card h3 {
  margin: 0 0 var(--s2); font-size: 15px; color: var(--brand);
  display: flex; align-items: center; gap: var(--s2);
}
.meal-card ul { margin: 0; padding-left: 18px; }
.meal-card li { padding: 2px 0; }

/* ---------- 일정 / 칩 ---------- */
.chips { display: flex; gap: var(--s2); overflow-x: auto; padding-bottom: var(--s2); margin-bottom: var(--s3); scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex-shrink: 0; border: 1px solid var(--line); background: var(--surface); color: var(--ink-soft);
  border-radius: 999px; padding: 6px 14px; font-size: 13px; cursor: pointer;
}
.chip[aria-pressed="true"] { background: var(--brand); border-color: var(--brand); color: #fff; }

.event {
  background: var(--surface); border: 1px solid var(--line);
  border-left: 4px solid var(--brand); border-radius: 12px;
  padding: var(--s3) var(--s4); margin-bottom: var(--s2);
}
.event.cat-수행평가 { border-left-color: #f5b400; }
.event.cat-학사일정 { border-left-color: #19b89b; }
.event.cat-시험 { border-left-color: #e2475a; }
.event .e-top { display: flex; align-items: center; justify-content: space-between; gap: var(--s2); }
.event .e-date { font-size: 12.5px; color: var(--ink-soft); }
.event .e-title { font-weight: 700; margin: 4px 0; }
.event .e-memo { font-size: 13px; color: var(--ink-soft); white-space: pre-wrap; }
.event .e-foot { display: flex; align-items: center; justify-content: space-between; margin-top: var(--s2); }
.event .e-author { font-size: 12px; color: var(--ink-soft); }
.event .e-del { background: none; border: 0; color: var(--danger); font: inherit; font-size: 12.5px; cursor: pointer; }

.badge { display: inline-block; font-size: 12px; font-weight: 600; padding: 3px 9px; border-radius: 999px; }
.badge-수행평가 { background: #fff3cc; color: #946200; }
.badge-학사일정 { background: #e2f7f2; color: #0f8d77; }
.badge-시험 { background: #fde3e7; color: #c23047; }

/* ---------- 상태 (로딩/빈/오류) ---------- */
.state { text-align: center; padding: var(--s6) var(--s4); color: var(--ink-soft); }
.state .emoji { font-size: 34px; display: block; margin-bottom: var(--s3); }
.state h3 { margin: 0 0 var(--s1); color: var(--ink); font-size: 15px; }
.state p { margin: 0; font-size: 13.5px; }
.skeleton {
  border-radius: 12px; height: 56px; margin-bottom: var(--s2);
  background: linear-gradient(90deg, #e9eef8 25%, #f4f7fd 37%, #e9eef8 63%);
  background-size: 400% 100%; animation: shimmer 1.3s ease infinite;
}
@keyframes shimmer { 0% { background-position: 100% 0; } 100% { background-position: 0 0; } }

/* ---------- FAB ---------- */
.fab {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--tabbar-h) + var(--s3)); z-index: 20;
  width: calc(var(--max) - 2 * var(--s4)); max-width: calc(100vw - 2 * var(--s4));
  box-shadow: var(--shadow);
}
/* 활성화된 화면(일정)에서만 FAB 표시 */
.screen:not(.active) .fab { display: none !important; }

/* ---------- 마이페이지 ---------- */
.me-head { display: flex; align-items: center; gap: var(--s4); }
.me-head .avatar-lg {
  width: 60px; height: 60px; border-radius: 18px; background: var(--brand-soft);
  display: flex; align-items: center; justify-content: center; font-size: 28px; flex-shrink: 0;
}
.me-nick { font-weight: 700; font-size: 15px; }
.me-sub { font-size: 13px; color: var(--ink-soft); margin-top: 2px; }

/* ---------- 모달 ---------- */
.modal {
  position: fixed; inset: 0; z-index: 40; background: rgba(27, 33, 48, 0.45);
  display: flex; align-items: flex-end; justify-content: center;
}
/* hidden 속성이 있으면 무조건 숨긴다 (display:flex가 덮어쓰지 않도록) */
.modal[hidden] { display: none; }
.modal-card {
  width: 100%; max-width: var(--max); background: var(--surface);
  border-radius: 20px 20px 0 0; padding: var(--s5) var(--s4) var(--s4);
  max-height: 90vh; overflow-y: auto;
}
.modal-card h3 { margin: 0 0 var(--s4); }
.seg { display: flex; gap: var(--s2); }
.seg button {
  flex: 1; border: 1px solid var(--line); background: var(--surface); color: var(--ink-soft);
  border-radius: 10px; padding: 10px; font: inherit; font-weight: 600; cursor: pointer;
}
.seg button.active { background: var(--brand); border-color: var(--brand); color: #fff; }
/* 공개 범위 선택은 세로로 쌓아 글씨가 잘 보이게 */
#vis-seg { flex-direction: column; }
#vis-seg button { text-align: left; }
.modal-actions { display: flex; gap: var(--s3); margin-top: var(--s2); }
.modal-actions .btn { flex: 1; }

/* ---------- 하단 탭 ---------- */
.tabbar {
  position: fixed; bottom: 0; left: 50%; transform: translateX(-50%);
  width: 100%; max-width: var(--max); height: var(--tabbar-h);
  display: flex; background: var(--surface); border-top: 1px solid var(--line); z-index: 30;
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar button {
  flex: 1; border: 0; background: none; color: var(--ink-soft); font-size: 11px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; cursor: pointer;
}
.tabbar button .ico { font-size: 20px; line-height: 1; }
.tabbar button[aria-current="true"] { color: var(--brand); font-weight: 700; }

/* ---------- 홈 ---------- */
.home-hello { display: flex; align-items: center; gap: var(--s3); }
.home-hello .hello-emoji { font-size: 32px; }
.home-hello .hello-nick { font-weight: 700; font-size: 15px; }
.home-hello .hello-sub { font-size: 13px; color: var(--ink-soft); margin-top: 2px; }

.home-grid { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s3); margin-top: var(--s4); }
.home-tile {
  display: flex; flex-direction: column; align-items: flex-start; gap: 2px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: var(--s4); cursor: pointer; text-align: left; box-shadow: var(--shadow-sm);
}
.home-tile.wide { grid-column: 1 / -1; }
.home-tile .t-ico { font-size: 26px; }
.home-tile .t-name { font-weight: 700; font-size: 15px; margin-top: var(--s1); }
.home-tile .t-desc { font-size: 12px; color: var(--ink-soft); }

/* ---------- 체크박스(나만 보기) ---------- */
.check { display: flex; align-items: flex-start; gap: var(--s2); font-size: 13.5px; margin: var(--s2) 0 var(--s4); cursor: pointer; }
.check input { width: 18px; height: 18px; margin-top: 2px; flex-shrink: 0; }
.check .hint { display: block; color: var(--ink-soft); font-size: 11.5px; }

/* 일정 카드에 '나만 보기' 표시 */
.badge-private { background: #f0eafc; color: #7a46d4; }
.badge-neis { background: #eef5ff; color: #2f6df6; }
.badge-gray { background: #eceef3; color: #6b7384; }

/* ---------- 내 시간표 ---------- */
.tt-tabs { margin-bottom: var(--s4); }
.my-tt-actions { display: flex; gap: var(--s2); margin-bottom: var(--s3); }
.my-tt-actions .btn { flex: 1; }
.my-tt-edit-actions { display: flex; gap: var(--s3); margin-top: var(--s3); }
.my-tt-edit-actions .btn { flex: 1; }

.tt-grid-wrap { overflow-x: auto; margin-top: var(--s2); }
.tt-grid { width: 100%; border-collapse: collapse; font-size: 13px; }
.tt-grid th, .tt-grid td {
  border: 1px solid var(--line); text-align: center; padding: 0;
}
.tt-grid th {
  background: var(--brand-soft); color: var(--brand);
  font-weight: 700; padding: 8px 4px; font-size: 12.5px;
}
.tt-grid td.period-head {
  background: #f7f8fc; color: var(--ink-soft); font-weight: 600;
  width: 38px; font-size: 12px;
}
.tt-grid td input {
  width: 100%; border: 0; background: none; text-align: center;
  padding: 10px 2px; font: inherit; font-size: 12.5px; color: var(--ink); outline: none; min-width: 52px;
}
.tt-grid td input:focus { background: var(--brand-soft); }

/* 보기 모드 격자(읽기 전용) */
.tt-grid td.cell { padding: 10px 4px; font-size: 12.5px; min-width: 52px; }
.tt-grid td.cell.empty { color: #cfd4de; }

/* 반 친구 시간표 목록 */
.friend-item {
  display: flex; align-items: center; justify-content: space-between; gap: var(--s2);
  width: 100%; text-align: left; background: var(--surface); border: 1px solid var(--line);
  border-radius: 12px; padding: 12px var(--s4); margin-bottom: var(--s2); cursor: pointer; font: inherit;
}
.friend-item .f-nick { font-weight: 600; font-size: 14px; }
.friend-item .f-cnt { font-size: 12px; color: var(--ink-soft); }
.friend-item .f-go { color: var(--brand); font-size: 13px; }

/* ---------- 월 캘린더 ---------- */
.cal-head { display: flex; align-items: center; justify-content: space-between; gap: var(--s3); margin-bottom: var(--s3); }
.cal-head h2 { margin: 0; font-size: 16px; }
.cal-legend { display: flex; gap: var(--s4); font-size: 12px; color: var(--ink-soft); margin-bottom: var(--s3); }
.cal-legend span { display: inline-flex; align-items: center; gap: 5px; }
.cal-legend .dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }

.cal-hint {
  display: block; width: 100%; text-align: left; cursor: pointer; font: inherit;
  background: #fff7e6; border: 1px solid #f3d9a6; color: #8a5a12;
  border-radius: 10px; padding: 10px var(--s3); margin-bottom: var(--s3); font-size: 13px;
}
.dot.d-수행평가 { background: #f5b400; }
.dot.d-시험 { background: #e2475a; }
.dot.d-학사일정 { background: #19b89b; }

.calendar { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: var(--s2); }
.cal-weekdays, .cal-days { display: grid; grid-template-columns: repeat(7, 1fr); }
.cal-weekdays span { text-align: center; font-size: 12px; color: var(--ink-soft); padding: 6px 0; font-weight: 600; }
.cal-weekdays span:first-child { color: var(--danger); }
.cal-cell {
  min-height: 56px; border: 0; background: none; cursor: pointer;
  display: flex; flex-direction: column; align-items: stretch; justify-content: flex-start;
  padding: 4px 3px; border-radius: 10px; font: inherit; color: var(--ink); position: relative; overflow: hidden;
}
.cal-cell.empty { cursor: default; }
.cal-cell .d { font-size: 12px; text-align: center; }
.cal-cell.sun .d { color: var(--danger); }
.cal-cell.today { background: var(--brand-soft); }
.cal-cell.today .d { color: var(--brand); font-weight: 700; }
.cal-cell.selected { outline: 2px solid var(--brand); }

/* 날짜 칸 안의 일정 제목(글씨) */
.cal-evs { display: flex; flex-direction: column; gap: 2px; margin-top: 2px; }
.cal-ev {
  font-size: 9.5px; line-height: 1.25; border-radius: 4px;
  padding: 1px 3px; text-align: left;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.cal-ev.c-수행평가 { background: #fff3cc; color: #946200; }
.cal-ev.c-시험 { background: #fde3e7; color: #c23047; }
.cal-ev.c-학사일정 { background: #e2f7f2; color: #0f8d77; }
.cal-more { font-size: 9px; color: var(--ink-soft); padding-left: 3px; }

/* ---------- 레이아웃(모바일 기본) ---------- */
.layout { display: flex; }
.main-col { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.sidebar { display: none; }

@media (min-width: 520px) {
  body { padding: var(--s5) 0; }
  .app { min-height: calc(100vh - 2 * var(--s5)); border-radius: 24px; overflow: hidden; box-shadow: var(--shadow); }
}

/* ---------- 노트북: 왼쪽 사이드바 ---------- */
@media (min-width: 768px) {
  :root { --max: 960px; }
  body { padding: var(--s5); }
  .app { max-width: 960px; border-radius: 24px; overflow: hidden; box-shadow: var(--shadow); }
  .sidebar {
    display: flex; flex-direction: column; gap: var(--s2);
    width: 210px; flex-shrink: 0; background: var(--surface);
    border-right: 1px solid var(--line); padding: var(--s4) var(--s3);
  }
  .side-brand { font-size: 15px; padding: var(--s2) var(--s3) var(--s4); }
  .side-nav { display: flex; flex-direction: column; gap: 4px; }
  .side-nav button {
    display: flex; align-items: center; gap: var(--s3);
    border: 0; background: none; border-radius: 12px; padding: 11px var(--s3);
    font: inherit; font-weight: 600; color: var(--ink-soft); cursor: pointer; text-align: left;
  }
  .side-nav button .ico { font-size: 18px; }
  .side-nav button[aria-current="true"] { background: var(--brand-soft); color: var(--brand); }
  /* 노트북에선 하단 탭과 FAB 숨기고, 추가 버튼은 일반 버튼처럼 */
  .tabbar { display: none; }
  .content { padding-bottom: var(--s5); }
  .fab {
    position: static; transform: none; width: auto; box-shadow: none;
    display: inline-flex; margin-top: var(--s4);
  }
  .home-grid { grid-template-columns: 1fr 1fr 1fr; }
  .home-tile.wide { grid-column: auto; }
  .modal { align-items: center; }
  .modal-card { border-radius: 20px; max-width: 420px; }
}
