:root {
  --bg: #f6f8fc;
  --card: #ffffff;
  --text: #1f2430;
  --muted: #6b7385;
  --line: #e3e8f1;
  --accent: #3b82f6;
  --accent-soft: #e2edff;
  --consult-soft: #dbe8ff;
  --consult-ink: #1d4fb8;
  --block: #8a93a6;
  --block-soft: #e8eaf0;
  --block-ink: #4a5266;
  --free: #16a34a;
  --free-soft: #dcf5e4;
  --free-ink: #0f6b31;
  --busy-soft: #eceef3;
  --busy-ink: #5a6275;
  --sun: #e5484d;
  --sat: #3b6fd8;
  --danger: #e5484d;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14171f;
    --card: #1e222d;
    --text: #eef1f7;
    --muted: #9aa3b8;
    --line: #333a4a;
    --accent-soft: #23365c;
    --consult-soft: #243d6b;
    --consult-ink: #c3d6ff;
    --block-soft: #343a49;
    --block-ink: #cfd4e0;
    --free-soft: #17402a;
    --free-ink: #a8efc2;
    --busy-soft: #2b303c;
    --busy-ink: #aab1c2;
    --sun: #ff7b7f;
    --sat: #7fa4ff;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Pretendard", "Noto Sans KR", "Malgun Gothic", sans-serif;
  font-size: 16px;
}

button, .btn { font: inherit; color: inherit; cursor: pointer; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.error { color: var(--danger); font-size: 14px; }

.screen { max-width: 520px; margin: 0 auto; min-height: 100dvh; }

/* ---------- 시작 · 로그인 ---------- */
.splash { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; }
#login { display: grid; place-items: center; padding: 24px 16px; }
.login-box { text-align: center; width: 100%; }
.logo { font-size: 60px; }
.login-box h1 { margin: 8px 0 4px; font-size: 26px; }
.btn-google {
  margin-top: 32px; width: 100%; max-width: 320px;
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  padding: 14px 18px; border-radius: 14px;
  border: 1px solid var(--line); background: var(--card); font-weight: 600;
}
.divider {
  display: flex; align-items: center; gap: 10px; max-width: 320px; margin: 24px auto 16px;
  color: var(--muted); font-size: 13px;
}
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.email-form, .verify-box { display: flex; flex-direction: column; gap: 10px; max-width: 320px; margin: 0 auto; }
.email-form input {
  width: 100%; font: inherit; font-size: 16px; color: var(--text);
  padding: 13px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--card);
}
.email-form .btn, .verify-box .btn { flex: none; }
.email-links { display: flex; justify-content: space-between; }
.link { border: 0; background: none; color: var(--muted); font-size: 13px; padding: 6px 2px; text-decoration: underline; }
.verify-box { margin-top: 24px; background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 16px; }
.verify-box p { margin: 0; font-size: 14px; line-height: 1.5; word-break: keep-all; }
.info { color: var(--muted); font-size: 14px; word-break: keep-all; }
.login-box .error, .login-box .info { max-width: 320px; margin: 12px auto 0; }
.demo-note {
  margin: 24px auto 0; max-width: 320px; font-size: 13px; color: var(--muted);
  background: var(--accent-soft); padding: 10px 12px; border-radius: 10px;
}

/* ---------- 상단바 ---------- */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 4px;
  padding: calc(env(safe-area-inset-top, 0px) + 10px) 12px 10px;
  background: var(--bg);
}
.topbar.plain { position: static; padding-top: 4px; }
.icon-btn {
  width: 44px; height: 44px; border: 0; background: transparent;
  font-size: 28px; line-height: 1; border-radius: 50%;
}
.icon-btn:active { background: var(--accent-soft); }
.month-label {
  border: 0; background: transparent; font-size: 20px; font-weight: 700;
  padding: 6px 8px; margin-right: auto;
}
.avatar {
  width: 36px; height: 36px; border-radius: 50%; border: 2px solid var(--accent);
  background: var(--accent-soft) center / cover no-repeat; font-weight: 700; font-size: 14px;
}

/* ---------- 달력 ---------- */
.weekdays, .grid { display: grid; grid-template-columns: repeat(7, 1fr); padding: 0 8px; }
.weekdays span { text-align: center; font-size: 12px; color: var(--muted); padding: 6px 0; }
.weekdays .sun { color: var(--sun); }
.weekdays .sat { color: var(--sat); }

.grid { row-gap: 2px; }
.cell {
  min-height: 78px; min-width: 0; border: 0; background: transparent;
  display: flex; flex-direction: column; align-items: stretch; justify-content: flex-start;
  padding: 4px 1px; gap: 2px; border-radius: 10px; position: relative;
}
.cell .num {
  width: 26px; height: 26px; display: grid; place-items: center; align-self: center;
  border-radius: 50%; font-size: 14px;
}
.cell.other { opacity: .35; }
.cell.sun .num { color: var(--sun); }
.cell.sat .num { color: var(--sat); }
.cell.today .num { background: var(--accent); color: #fff; font-weight: 700; }
.cell.selected { background: var(--accent-soft); }
.chips { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.chip {
  display: block; overflow: hidden; white-space: nowrap; text-overflow: clip;
  font-size: 10px; line-height: 15px; letter-spacing: -0.05em; text-align: left;
  padding: 0 2px; border-radius: 4px;
  background: var(--consult-soft); color: var(--consult-ink);
}
.chip.block { background: var(--block-soft); color: var(--block-ink); }
.more { font-size: 10px; line-height: 13px; color: var(--muted); }

/* ---------- 선택한 날 목록 (관리) ---------- */
.day-panel {
  margin: 8px 12px 0; padding: 16px 16px calc(96px + var(--safe-bottom));
  background: var(--card); border-radius: 20px 20px 0 0; min-height: 40dvh;
  scroll-margin-top: calc(env(safe-area-inset-top, 0px) + 64px);
}
.day-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.day-head h2, .day-panel > h2 { font-size: 17px; margin: 0; }
.legend { display: flex; gap: 10px; font-size: 12px; color: var(--muted); }
.legend i { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 4px; background: var(--accent); }
.legend i.block { background: var(--block); }

.day-list { list-style: none; margin: 12px 0 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.day-list .empty { color: var(--muted); font-size: 14px; padding: 24px 0; text-align: center; }
.event {
  width: 100%; text-align: left; border: 0; background: var(--bg);
  display: flex; gap: 12px; padding: 12px; border-radius: 14px;
  border-left: 4px solid var(--accent);
}
.event.block { border-left-color: var(--block); }
.event:active { filter: brightness(.96); }
.event .time { font-size: 14px; font-weight: 700; min-width: 48px; padding-top: 1px; white-space: pre-line; line-height: 1.35; }
.event .body { flex: 1; min-width: 0; }
.event .content { font-weight: 600; word-break: break-word; }
.event .memo { font-size: 13px; color: var(--muted); margin-top: 4px; white-space: pre-wrap; word-break: break-word; }

.fab {
  position: fixed; right: max(20px, calc(50% - 240px)); bottom: calc(24px + var(--safe-bottom));
  width: 60px; height: 60px; border-radius: 50%; border: 0;
  background: var(--accent); color: #fff; font-size: 30px;
  box-shadow: 0 6px 18px rgba(59, 130, 246, .45); z-index: 6;
}
.fab:active { transform: scale(.95); }

/* ---------- 바텀 시트 ---------- */
.backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 10; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 11;
  max-width: 520px; margin: 0 auto;
  background: var(--card); border-radius: 22px 22px 0 0;
  padding: 10px 20px calc(20px + var(--safe-bottom));
  display: flex; flex-direction: column; gap: 12px;
  max-height: 94dvh; overflow-y: auto;
  animation: up .2s ease-out;
}
@keyframes up { from { transform: translateY(100%); } to { transform: none; } }
.sheet-grip { width: 40px; height: 4px; border-radius: 2px; background: var(--line); margin: 0 auto 4px; flex: none; }
.sheet h3 { margin: 0; font-size: 18px; }
.sheet label { display: flex; flex-direction: column; gap: 6px; font-size: 14px; color: var(--muted); }
.sheet label.row { flex-direction: row; justify-content: space-between; align-items: center; }
.kind-group { display: flex; gap: 6px; }
.sheet label.kind { flex: 1; flex-direction: row; gap: 0; position: relative; }
.kind input { position: absolute; opacity: 0; pointer-events: none; }
.kind span {
  flex: 1; text-align: center; padding: 11px 0; border-radius: 12px;
  border: 1.5px solid var(--line); color: var(--text); font-weight: 600; font-size: 15px;
}
.kind.consult input:checked + span { background: var(--accent); border-color: var(--accent); color: #fff; }
.kind.block input:checked + span { background: var(--block); border-color: var(--block); color: #fff; }
.kind input:focus-visible + span { outline: 2px solid var(--text); outline-offset: 2px; }
.time-row { display: flex; align-items: flex-end; gap: 8px; margin-top: -6px; }
.time-row label { flex: 1; min-width: 0; gap: 4px; }
.time-row .tilde { padding-bottom: 14px; color: var(--muted); }
.allday { display: inline-flex; align-items: center; gap: 6px; color: var(--text); }
.sheet input[type=date], .sheet input[type=time], .sheet input[type=text], .sheet textarea {
  width: 100%; font: inherit; font-size: 16px; color: var(--text);
  padding: 12px; border-radius: 12px; border: 1px solid var(--line); background: var(--bg);
}
.sheet input[type=checkbox] { width: 20px; height: 20px; accent-color: var(--accent); }
.sheet textarea { resize: none; }
.sheet-actions { display: flex; gap: 8px; margin-top: 4px; }
.btn {
  flex: 1; padding: 14px; border-radius: 14px; border: 0; font-weight: 600;
  text-align: center; text-decoration: none; display: block;
}
.btn.primary { background: var(--accent); color: #fff; }
.btn.ghost { background: var(--bg); color: var(--text); }
.btn.danger { background: transparent; color: var(--danger); flex: 0 0 auto; padding: 14px 16px; }
.btn:disabled { opacity: .5; }

/* ---------- 계정 메뉴 / 토스트 ---------- */
.user-menu {
  position: fixed; top: calc(env(safe-area-inset-top, 0px) + 58px); right: max(12px, calc(50% - 248px));
  background: var(--card); border: 1px solid var(--line); border-radius: 14px;
  padding: 12px; z-index: 12; box-shadow: 0 8px 24px rgba(0,0,0,.12); min-width: 220px;
}
.user-menu p { margin: 0 0 10px; word-break: break-all; }
.user-menu .btn { width: 100%; }
.user-menu .btn + .btn { margin-top: 6px; }
.toast {
  position: fixed; left: 50%; bottom: calc(100px + var(--safe-bottom)); transform: translateX(-50%);
  background: #1f2430; color: #fff; padding: 10px 16px; border-radius: 20px; font-size: 14px; z-index: 20;
  max-width: 90vw; text-align: center;
}

/* ---------- 고객용 화면 ---------- */
.pub-head { padding: calc(env(safe-area-inset-top, 0px) + 20px) 16px 4px; }
.pub-head h1 { margin: 0 0 4px; font-size: 22px; }
.pub-head p { margin: 0; font-size: 15px; word-break: keep-all; }
.public .day-panel { padding-bottom: calc(32px + var(--safe-bottom)); min-height: 30dvh; margin-top: 12px; }
.public .cell { min-height: 62px; }
.public .cell .tag {
  align-self: center; font-size: 11px; font-weight: 700; line-height: 16px;
  padding: 0 6px; border-radius: 8px; min-height: 16px;
}
.pub-free .tag { background: var(--free-soft); color: var(--free-ink); }
.pub-busy .tag { background: var(--busy-soft); color: var(--busy-ink); }
.pub-free .num { font-weight: 700; }
.pub-busy, .pub-off { background: var(--busy-soft); opacity: .8; }
.pub-past { opacity: .35; }
.public .cell.selected { outline: 2px solid var(--accent); outline-offset: -2px; }
.pub-legend { display: flex; gap: 16px; justify-content: center; padding: 10px 12px 0; font-size: 13px; color: var(--muted); }
.pub-legend i { display: inline-block; width: 12px; height: 12px; border-radius: 4px; margin-right: 5px; vertical-align: -1px; }
.pub-legend i.free { background: var(--free-soft); border: 1.5px solid var(--free); }
.pub-legend i.busy { background: var(--busy-soft); border: 1.5px solid var(--block); }
.day-status { font-size: 17px; font-weight: 700; margin: 10px 0 4px; }
.day-status.free { color: var(--free-ink); }
.day-status.past, .day-status.off { color: var(--muted); font-weight: 600; }
.pub-times { list-style: none; margin: 8px 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.pub-times li {
  background: var(--busy-soft); border-radius: 12px; padding: 12px 14px; font-size: 16px; font-weight: 600;
}
.contact { margin-top: 16px; }
