:root {
  --fg: #111; --dim: #8a8a8a; --line: #e6e6e6; --bg: #fff; --soft: #f5f5f5;
}
@media (prefers-color-scheme: dark) {
  :root { --fg: #eee; --dim: #777; --line: #262626; --bg: #0b0b0b; --soft: #161616; }
}
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--fg);
  font-family: "Pretendard", -apple-system, "Segoe UI", "Malgun Gothic", sans-serif;
  -webkit-font-smoothing: antialiased;
}
#app { max-width: 720px; margin: 0 auto; padding: 64px 24px 96px; }
.hidden { display: none !important; }
.dim { color: var(--dim); }
.small { font-size: 13px; }
.err { color: #c33; font-size: 13px; min-height: 1em; }
h1 { font-size: 56px; letter-spacing: -0.04em; margin: 0 0 8px; font-weight: 700; }
h2 { font-size: 22px; margin: 0; font-weight: 600; letter-spacing: -0.02em; }
h3 { font-size: 15px; margin: 0 0 16px; font-weight: 600; }

.btn {
  font: inherit; font-size: 14px; padding: 10px 16px; border-radius: 8px; cursor: pointer;
  border: 1px solid var(--fg); background: var(--fg); color: var(--bg);
}
.btn.ghost { background: transparent; color: var(--fg); border-color: var(--line); }
.btn.small { padding: 6px 10px; font-size: 12px; }
.icon { font: inherit; font-size: 22px; background: none; border: 0; color: var(--fg); cursor: pointer; padding: 0 8px; }

#login { display: flex; flex-direction: column; gap: 14px; max-width: 340px; margin-top: 12vh; }
#email-form { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
input {
  font: inherit; font-size: 14px; padding: 10px 12px; border-radius: 8px;
  border: 1px solid var(--line); background: transparent; color: var(--fg);
}

.top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 48px; }
.me { display: flex; gap: 14px; align-items: center; }
.me img { width: 44px; height: 44px; border-radius: 50%; object-fit: cover; background: var(--soft); }
.name { font-weight: 600; font-size: 17px; }

.month-bar { display: flex; align-items: center; gap: 4px; margin-bottom: 16px; }
.month-bar #today { margin-left: auto; }

.calendar { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; margin-bottom: 48px; }
.calendar .wd { font-size: 11px; color: var(--dim); text-align: center; padding-bottom: 6px; }
.cell {
  aspect-ratio: 1; border-radius: 10px; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 4px; cursor: pointer; font-size: 13px;
  border: 1px solid transparent; user-select: none;
}
.cell:hover { background: var(--soft); }
.cell.out { visibility: hidden; }
.cell.today .n { font-weight: 700; text-decoration: underline; text-underline-offset: 3px; }
.cell.sel { border-color: var(--fg); }
.cell .dot { font-size: 10px; color: var(--dim); min-height: 12px; }
.cell .dot.all { color: var(--fg); }

.goal { margin-bottom: 28px; }
.goal-title { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 600;
  padding: 4px 10px; border-radius: 999px; background: var(--soft); margin-bottom: 10px; }
.goal-title i { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.todo { display: flex; gap: 12px; align-items: flex-start; padding: 8px 2px; border-bottom: 1px solid var(--line); }
.todo .box { width: 18px; height: 18px; border: 1.5px solid var(--dim); border-radius: 5px; flex: none; margin-top: 1px;
  display: flex; align-items: center; justify-content: center; font-size: 12px; }
.todo.done .box { background: var(--fg); border-color: var(--fg); color: var(--bg); }
.todo.done .txt { color: var(--dim); text-decoration: line-through; }
.todo .memo { font-size: 12px; color: var(--dim); margin-top: 2px; white-space: pre-wrap; }
.diary { border: 1px solid var(--line); border-radius: 12px; padding: 16px; white-space: pre-wrap; line-height: 1.6; }
.empty { color: var(--dim); font-size: 14px; }

.raw { margin-top: 64px; font-size: 12px; color: var(--dim); }
.raw pre { max-height: 360px; overflow: auto; background: var(--soft); padding: 12px; border-radius: 8px; font-size: 11px; }

/* ---- v2: editing ---- */
.row { display: flex; gap: 8px; align-items: center; }
.status { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); margin: 0;
  background: var(--bg); border: 1px solid var(--line); padding: 8px 14px; border-radius: 999px; z-index: 20;
  max-width: 90vw; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.status:empty { display: none; }
.day { margin-bottom: 48px; }
.goal-head { display: flex; align-items: center; justify-content: space-between; }
button.goal-title { border: 0; font: inherit; font-size: 13px; font-weight: 600; color: var(--fg); cursor: pointer; }
.goal-title .plus { color: var(--dim); margin-left: 2px; }
.todo .box { background: transparent; cursor: pointer; padding: 0; color: inherit; }
.todo .main { flex: 1; min-width: 0; }
.todo .txt { cursor: text; word-break: break-word; }
.more { background: none; border: 0; color: var(--dim); cursor: pointer; font-size: 16px; padding: 0 4px; opacity: .5; }
.todo:hover .more, .goal-head:hover .more { opacity: 1; }
form.add input { width: 100%; margin-top: 8px; }
.diary-wrap { margin-top: 40px; }
.diary-edit { display: flex; flex-direction: column; gap: 8px; }
.diary-edit .emoji { width: 64px; text-align: center; font-size: 20px; }
textarea { font: inherit; font-size: 14px; line-height: 1.6; padding: 12px; border-radius: 8px; resize: vertical;
  border: 1px solid var(--line); background: transparent; color: var(--fg); }
.menu { position: absolute; z-index: 30; background: var(--bg); border: 1px solid var(--line); border-radius: 10px;
  padding: 4px; display: flex; flex-direction: column; min-width: 160px; box-shadow: 0 8px 24px rgba(0,0,0,.08); }
.menu button { font: inherit; font-size: 13px; text-align: left; background: none; border: 0; color: var(--fg);
  padding: 8px 10px; border-radius: 6px; cursor: pointer; }
.menu button:hover { background: var(--soft); }
.menu button.danger { color: #c33; }

/* ---- v3: tabs / social / chat / crew / stickers ---- */
.tiny { font-size: 11px; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin: -24px 0 32px; }
.tabs button { font: inherit; font-size: 14px; background: none; border: 0; color: var(--dim); padding: 10px 14px; cursor: pointer;
  border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs button.sel { color: var(--fg); border-bottom-color: var(--fg); font-weight: 600; }
.goal.finished, .goal-head.finished { opacity: .45; }
details.fold summary { list-style: none; cursor: pointer; }
details.fold summary::-webkit-details-marker { display: none; }
details.fold summary h3::before { content: "▸ "; color: var(--dim); }
details.fold[open] summary h3::before { content: "▾ "; }
#finished .goal-head { padding: 6px 0; }
.av { border-radius: 50%; object-fit: cover; background: var(--soft); flex: none; }
.card { border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; margin-bottom: 12px; }
.card .row { gap: 8px; }
.card-body { margin: 8px 0 4px; }
.profile-card { display: flex; justify-content: space-between; align-items: center; }
.diary-txt { white-space: pre-wrap; line-height: 1.6; margin-top: 6px; }
.friends { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 24px; }
.friend { display: inline-flex; align-items: center; gap: 6px; font: inherit; font-size: 13px; padding: 6px 12px; border-radius: 999px;
  border: 1px solid var(--line); background: transparent; color: var(--fg); cursor: pointer; }
.friend.sel { background: var(--fg); color: var(--bg); border-color: var(--fg); }
.likebar { display: flex; align-items: center; gap: 4px; margin-top: 6px; }
.likebar button { background: none; border: 0; cursor: pointer; color: var(--dim); font: inherit; padding: 2px 4px; }
.likebar .lk { font-size: 16px; }
.likebar .lk.on { color: #e0245e; }
.user-row { padding: 8px 0; border-bottom: 1px solid var(--line); gap: 10px; }
.like-row { padding: 10px 0; border-bottom: 1px solid var(--line); }
.like-row .row { gap: 8px; }
.like-row .msg { margin: 6px 0 0 36px; }
.like-row .comments { margin: 4px 0 0 36px; }
.like-row form input { width: calc(100% - 36px); margin: 6px 0 0 36px; padding: 6px 10px; font-size: 12px; }
.noti { padding: 10px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.noti img { vertical-align: middle; }

.modal-back { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 40; display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal { background: var(--bg); border: 1px solid var(--line); border-radius: 14px; width: min(520px, 100%); max-height: 85vh; display: flex; flex-direction: column; }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.modal-body { padding: 16px 18px; overflow: auto; }

.sticker-set { margin-bottom: 18px; }
.sticker-grid { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.sticker-btn { background: none; border: 1px solid transparent; border-radius: 8px; padding: 2px; cursor: pointer; }
.sticker-btn:hover { border-color: var(--line); background: var(--soft); }
img.sticker { object-fit: contain; vertical-align: middle; }

.chat { display: grid; grid-template-columns: 240px 1fr; gap: 16px; height: 68vh; }
.rooms { overflow: auto; border-right: 1px solid var(--line); padding-right: 8px; }
.room-item { display: flex; gap: 10px; align-items: center; width: 100%; text-align: left; background: none; border: 0; color: var(--fg);
  font: inherit; padding: 8px; border-radius: 10px; cursor: pointer; position: relative; }
.room-item:hover, .room-item.sel { background: var(--soft); }
.ri-main { flex: 1; min-width: 0; }
.ri-prev { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.badge { background: var(--fg); color: var(--bg); font-size: 11px; border-radius: 999px; padding: 1px 7px; }
.room { display: flex; flex-direction: column; min-height: 0; }
.room-head { display: flex; justify-content: space-between; padding-bottom: 8px; border-bottom: 1px solid var(--line); }
.msgs { flex: 1; overflow: auto; padding: 12px 0; display: flex; flex-direction: column; gap: 8px; }
.msg { display: flex; gap: 8px; align-items: flex-end; max-width: 80%; }
.msg.mine { align-self: flex-end; flex-direction: row-reverse; }
.bubble { display: inline-block; padding: 8px 12px; border-radius: 14px; background: var(--soft); white-space: pre-wrap; word-break: break-word; }
.msg.mine .bubble { background: var(--fg); color: var(--bg); }
.msg-sys { align-self: center; font-size: 12px; color: var(--dim); }
.chat-img { max-width: 220px; border-radius: 10px; }
.c-form { display: flex; gap: 8px; padding-top: 8px; border-top: 1px solid var(--line); }
.c-form input { flex: 1; }
@media (max-width: 640px) { .chat { grid-template-columns: 1fr; height: auto; } .rooms { border-right: 0; max-height: 30vh; } .room { height: 60vh; } }

/* ---- v4: 첫 화면 프로필 스트립 ---- */
.people { display: flex; gap: 18px; overflow-x: auto; padding: 4px 2px 20px; margin-bottom: 20px; border-bottom: 1px solid var(--line); scrollbar-width: none; }
.people::-webkit-scrollbar { display: none; }
.person { display: flex; flex-direction: column; align-items: center; gap: 6px; background: none; border: 0; color: var(--dim);
  font: inherit; font-size: 12px; cursor: pointer; padding: 0; flex: none; width: 64px; }
.person span { max-width: 64px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.person .av { border: 2px solid transparent; outline: 2px solid transparent; outline-offset: 1px; transition: outline-color .15s; }
.person:hover .av { outline-color: var(--line); }
.person.sel { color: var(--fg); font-weight: 600; }
.person.sel .av { outline-color: var(--fg); }
.plus-av { width: 52px; height: 52px; display: flex; align-items: center; justify-content: center; font-size: 20px; color: var(--dim); border: 1px dashed var(--line) !important; }
.viewing-bar { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 24px; }
.viewing-bar .row { gap: 10px; }

/* ================= v5: 데스크탑 전체 화면 레이아웃 ================= */
html, body { height: 100%; }
#app { max-width: none; margin: 0; padding: 0; height: 100%; }
#login { margin: 18vh auto 0; }

.shell { display: grid; grid-template-columns: 232px 1fr; height: 100vh; }
.side { border-right: 1px solid var(--line); padding: 28px 18px; display: flex; flex-direction: column; gap: 28px; position: sticky; top: 0; height: 100vh; }
.brand { font-size: 22px; font-weight: 700; letter-spacing: -0.03em; padding: 0 8px; }
.side .me { padding: 0 8px; gap: 12px; }
.side .me img { width: 40px; height: 40px; }
.me-txt { min-width: 0; }
.me-txt .name, .me-txt .small { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.tabs { flex-direction: column; border: 0; margin: 0; gap: 2px; }
.tabs button { display: flex; align-items: center; gap: 12px; text-align: left; border: 0; border-radius: 8px; padding: 10px 12px; margin: 0; font-size: 15px; }
.tabs button:hover { background: var(--soft); color: var(--fg); }
.tabs button.sel { background: var(--soft); color: var(--fg); border: 0; }
.tabs .ic { width: 18px; text-align: center; color: var(--dim); }
.tabs button.sel .ic { color: var(--fg); }
.side-foot { margin-top: auto; display: flex; flex-direction: column; gap: 2px; }
.side-link { font: inherit; font-size: 13px; color: var(--dim); background: none; border: 0; text-align: left; padding: 8px 12px; border-radius: 8px; cursor: pointer; }
.side-link:hover { background: var(--soft); color: var(--fg); }

.content { overflow: auto; height: 100vh; padding: 28px 40px 80px; }
.tab { max-width: none; }

/* 홈: 프로필 스트립 + [달력 | 하루] 2단 */
.people { gap: 22px; margin-bottom: 24px; padding-bottom: 18px; }
.home-grid { display: grid; grid-template-columns: minmax(0, 1fr) 440px; gap: 40px; align-items: start; }
.col-day { position: sticky; top: 0; max-height: calc(100vh - 56px); overflow: auto; padding-right: 4px; }
.month-bar { gap: 6px; margin-bottom: 14px; }
.month-bar h2 { font-size: 26px; margin-right: 8px; }
.viewing-bar { padding: 14px 16px; border: 1px solid var(--line); border-radius: 12px; }

.calendar { gap: 0; margin-bottom: 24px; border-top: 1px solid var(--line); border-left: 1px solid var(--line); }
.calendar .wd { padding: 8px 0; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); font-size: 12px; }
.cell { aspect-ratio: auto; height: clamp(96px, calc((100vh - 300px) / 6), 150px); border-radius: 0; border: 0;
  border-right: 1px solid var(--line); border-bottom: 1px solid var(--line);
  display: flex; flex-direction: column; align-items: stretch; justify-content: flex-start; gap: 4px; padding: 6px 8px; overflow: hidden; }
.cell.out { visibility: visible; background: transparent; cursor: default; }
.cell.out:hover { background: transparent; }
.cell.sel { box-shadow: inset 0 0 0 2px var(--fg); }
.cell-top { display: flex; align-items: center; gap: 6px; font-size: 13px; }
.cell-top .dot { margin-left: auto; min-height: 0; }
.cell.today .n { background: var(--fg); color: var(--bg); text-decoration: none; border-radius: 999px; padding: 0 7px; }
.cell-items { display: flex; flex-direction: column; gap: 2px; min-height: 0; }
.ci { font-size: 11.5px; line-height: 1.35; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: flex; align-items: center; gap: 5px; }
.ci i { width: 6px; height: 6px; border-radius: 50%; flex: none; }
.ci.done { color: var(--dim); text-decoration: line-through; }
.ci.more-n { color: var(--dim); }

.day-title { font-size: 20px; letter-spacing: -0.02em; margin-bottom: 20px; }
.col-day .day { margin-bottom: 36px; }
.raw { margin-top: 24px; }

/* 피드 / 크루 / 알림: 넓은 화면에서 카드 그리드 */
#tab-feed, #tab-crew, #tab-noti { max-width: 1280px; }
#f-body, #cr-members { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 16px; align-items: start; }
#f-body > .card, #cr-members > .card { margin: 0; }
#f-body > .month-bar, #f-body > #fr-day, #f-body > .profile-card { grid-column: 1 / -1; }
#n-body { max-width: 760px; }

/* 채팅: 화면 높이 전체 */
#tab-chat { height: calc(100vh - 108px); display: flex; flex-direction: column; }
.chat { flex: 1; height: auto; min-height: 0; grid-template-columns: 320px 1fr; gap: 0; border: 1px solid var(--line); border-radius: 14px; overflow: hidden; }
.rooms { padding: 8px; border-right: 1px solid var(--line); }
.room { padding: 14px 20px; }
.msg { max-width: 60%; }

.modal { width: min(640px, 92vw); }
.status { bottom: 24px; left: calc(50% + 116px); }
@media (max-width: 1100px) { .home-grid { grid-template-columns: 1fr; } .col-day { position: static; max-height: none; } }

/* ---- v6: 미룬 할 일 날짜 / 표시할 친구 ---- */
.bl-date { display: inline-block; min-width: 46px; margin-right: 6px; }
.pick { cursor: pointer; }
.pick input { width: 16px; height: 16px; accent-color: var(--fg); }
.star { background: none; border: 0; font-size: 18px; color: var(--dim); cursor: pointer; }
.star.on { color: var(--fg); }

/* ================= v7: 반응형 ================= */
.c-back { display: none; }
.room-head { align-items: center; gap: 8px; }
.room-head b { flex: 1; }

/* 노트북 (≤1280): 날짜 패널 폭 줄임 */
@media (max-width: 1280px) {
  .home-grid { grid-template-columns: minmax(0, 1fr) 360px; gap: 28px; }
  .content { padding: 24px 28px 80px; }
}

/* 태블릿 (≤1100): 달력/하루 패널 세로 쌓기 */
@media (max-width: 1100px) {
  .home-grid { grid-template-columns: 1fr; gap: 32px; }
  .col-day { position: static; max-height: none; overflow: visible; }
  .cell { height: 104px; }
  .chat { grid-template-columns: 260px 1fr; }
}

/* 좁은 태블릿 (≤900): 사이드바 → 상단 바 */
@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; grid-template-rows: auto 1fr; height: auto; min-height: 100vh; }
  .side { position: sticky; top: 0; z-index: 20; height: auto; flex-direction: row; align-items: center; gap: 16px;
    padding: 10px 16px; border-right: 0; border-bottom: 1px solid var(--line); background: var(--bg); }
  .brand { font-size: 18px; padding: 0; }
  .side .me { display: none; }
  .tabs { flex-direction: row; gap: 2px; overflow-x: auto; flex: 1; scrollbar-width: none; }
  .tabs::-webkit-scrollbar { display: none; }
  .tabs button { padding: 8px 10px; font-size: 14px; white-space: nowrap; }
  .tabs .ic { display: none; }
  .side-foot { margin: 0; flex-direction: row; }
  .side-link { padding: 6px 8px; white-space: nowrap; }
  .content { height: auto; overflow: visible; padding: 20px 20px 80px; }
  .status { left: 50%; }
  #tab-chat { height: calc(100vh - 140px); }
}

/* 모바일 (≤640) */
@media (max-width: 640px) {
  body { font-size: 15px; }
  .side { flex-wrap: wrap; gap: 8px; padding: 8px 12px 0; }
  .brand { flex: 1; }
  .side-foot { order: 2; }
  .tabs { order: 3; flex-basis: 100%; justify-content: space-between; border-top: 1px solid var(--line); margin: 0 -12px; padding: 0 4px; }
  .tabs button { flex: 1; justify-content: center; border-radius: 0; padding: 10px 0; background: none !important; border-bottom: 2px solid transparent; }
  .tabs button.sel { border-bottom-color: var(--fg); }
  .side-link { font-size: 12px; padding: 4px 6px; }
  .content { padding: 16px 12px 72px; }

  .people { gap: 14px; margin-bottom: 16px; padding-bottom: 14px; }
  .person { width: 54px; }
  .person .av { width: 44px !important; height: 44px !important; }
  .plus-av { width: 44px; height: 44px; }

  .month-bar h2 { font-size: 22px; }
  .calendar .wd { font-size: 11px; padding: 6px 0; }
  .cell { height: 60px; padding: 4px; gap: 2px; }
  .cell-top { flex-direction: column; align-items: center; gap: 1px; font-size: 12px; }
  .cell-top .dot { margin: 0; font-size: 9px; }
  .cell-top .tiny { display: none; }
  .cell-items { display: none; }
  .cell.today .n { padding: 0 5px; }

  .day-title { font-size: 18px; }
  .viewing-bar { flex-direction: column; align-items: flex-start; }
  .todo { padding: 10px 2px; }
  .more { opacity: 1; padding: 4px 8px; }

  #f-body, #cr-members { grid-template-columns: 1fr; }
  .profile-card { flex-direction: column; align-items: flex-start; gap: 10px; }
  .friends { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
  .friend { flex: none; }

  /* 채팅: 목록 ↔ 대화 전환 */
  #tab-chat { height: calc(100vh - 150px); }
  .chat { grid-template-columns: 1fr; border-radius: 10px; }
  .rooms { border-right: 0; max-height: none; }
  .room { display: none; height: auto; padding: 10px 12px; }
  .chat.has-room .rooms { display: none; }
  .chat.has-room .room { display: flex; }
  .c-back { display: inline-block; }
  .msg { max-width: 85%; }

  .modal-back { padding: 0; align-items: flex-end; }
  .modal { width: 100%; max-height: 90vh; border-radius: 16px 16px 0 0; }
  .menu { min-width: 180px; }
  .menu button { padding: 11px 12px; font-size: 14px; }
  .status { max-width: calc(100vw - 24px); bottom: 16px; }
}

/* v7.1: 가로 넘침 방지 */
.shell, .content, .home-grid > *, .tab { min-width: 0; }
.calendar { grid-template-columns: repeat(7, minmax(0, 1fr)); }
@media (max-width: 900px) { .side { min-width: 0; width: 100%; } .content { overflow-x: hidden; } }
@media (max-width: 640px) {
  .side-foot { min-width: 0; overflow-x: auto; scrollbar-width: none; }
  .side-foot::-webkit-scrollbar { display: none; }
  .tabs { margin: 0 -12px; width: calc(100% + 24px); }
  .tabs button { min-width: 0; font-size: 13px; }
}
