:root {
  --bg: #f2f4f6;
  --card: #ffffff;
  --text: #191f28;
  --sub: #6b7684;
  --line: #e5e8eb;
  --primary: #3182f6;
  --primary-dark: #1b64da;
  --danger: #f04452;
  --radius: 18px;
  --shadow: 0 1px 2px rgba(0, 0, 0, .04), 0 4px 16px rgba(0, 0, 0, .04);
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Pretendard", "Noto Sans KR", "Malgun Gothic", "Segoe UI", sans-serif;
  font-size: 16px;
  line-height: 1.45;
  padding-bottom: calc(96px + var(--safe-b));
}
body.lock { overflow: hidden; }

button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3, p { margin: 0; }

/* ---------- 상단 앱바 ---------- */
.appbar {
  position: sticky; top: 0; z-index: 20;
  background: rgba(255, 255, 255, .92);
  backdrop-filter: saturate(180%) blur(12px);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--line);
}
.appbar-in {
  max-width: 1100px; margin: 0 auto;
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px;
}
.logo {
  width: 40px; height: 40px; border-radius: 12px;
  background: linear-gradient(135deg, #5ba2ff, #3182f6);
  display: grid; place-items: center; font-size: 22px; flex: none;
}
.titles { flex: 1; min-width: 0; }
.titles h1 { font-size: 18px; font-weight: 800; letter-spacing: -.02em; }
.titles p { font-size: 12.5px; color: var(--sub); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 12px; border: 0;
  background: #f2f4f6; font-size: 20px; line-height: 1; flex: none;
}
.icon-btn:active { background: #e5e8eb; }
.icon-btn.spin { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.banner {
  max-width: 1100px; margin: 12px auto 0; padding: 12px 16px;
  background: #fff1f2; color: #b4232f; border-radius: 12px;
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  font-size: 14px;
}
.banner button { border: 0; background: #b4232f; color: #fff; border-radius: 8px; padding: 6px 12px; flex: none; }

/* ---------- 레이아웃 (모바일 기본) ---------- */
.layout {
  max-width: 1100px; margin: 0 auto;
  padding: 12px 12px 0;
  display: flex; flex-direction: column; gap: 12px;
}
.content { display: flex; flex-direction: column; gap: 12px; min-width: 0; }

.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
}
.card h2 { font-size: 16px; font-weight: 800; letter-spacing: -.01em; }

/* ---------- 월 달력 ---------- */
.date-top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.month-nav { display: flex; align-items: center; gap: 4px; }
.month { font-size: 19px; font-weight: 800; letter-spacing: -.02em; min-width: 7.2em; text-align: center; }
.nav-arrow {
  flex: none; width: 36px; height: 36px; border: 0; background: #f2f4f6;
  font-size: 22px; line-height: 1; color: #4e5968; border-radius: 12px;
}
.nav-arrow:active { background: #e5e8eb; }
.chip-btn {
  border: 0; background: #f2f4f6; color: #4e5968;
  border-radius: 999px; padding: 8px 14px; font-size: 13.5px; font-weight: 700;
}
.chip-btn:active { background: #e5e8eb; }

.cal-week, .cal { display: grid; grid-template-columns: repeat(7, 1fr); }
.cal-week { margin-bottom: 4px; }
.cal-week span { text-align: center; font-size: 12px; font-weight: 700; color: var(--sub); padding: 4px 0; }
.cal-week .sun { color: #f04452; }
.cal-week .sat { color: #3182f6; }
.cal { gap: 2px; }

.cd {
  border: 0; background: transparent; border-radius: 14px;
  min-height: 58px; padding: 5px 0 4px;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
}
.cd:active { background: #f2f4f6; }
.cd .n {
  width: 32px; height: 32px; border-radius: 50%;
  display: grid; place-items: center; font-size: 15.5px; font-weight: 600;
}
.cd.sun .n { color: #f04452; }
.cd.sat .n { color: #3182f6; }
.cd.out { opacity: .35; }
.cd.today .n { box-shadow: inset 0 0 0 2px var(--primary); font-weight: 800; }
.cd.sel { background: #eef4ff; }
.cd.sel .n { background: var(--primary); color: #fff; box-shadow: none; font-weight: 800; }
.cd.has .n { font-weight: 800; }
.cd { overflow: visible; }
.dots { display: flex; justify-content: center; flex-wrap: wrap; gap: 2px; min-height: 6px; max-width: 100%; padding: 0 2px; }
.dots i { width: 6px; height: 6px; border-radius: 50%; background: var(--c); display: block; }

/* 여러 날 예약: 날짜를 가로질러 이어지는 선 */
.lines { width: 100%; display: flex; flex-direction: column; align-items: stretch; gap: 2px; }
.ln { display: block; height: 5px; margin: 0 -1px; background: var(--c); }
.ln.sp { background: transparent; }
.ln.l { margin-left: 7px; border-radius: 3px 0 0 3px; }
.ln.r { margin-right: 7px; border-radius: 0 3px 3px 0; }
.ln.l.r { border-radius: 3px; }

.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--line); }
.legend span { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; color: #4e5968; }
.legend i { width: 9px; height: 9px; border-radius: 50%; background: var(--c); display: block; }
.legend .note { flex-basis: 100%; color: var(--sub); font-size: 12px; }

/* ---------- 선택한 날 ---------- */
.day-head { margin-bottom: 14px; }
.day-title { font-size: 19px; font-weight: 800; letter-spacing: -.02em; }
.day-sub { font-size: 14px; color: var(--sub); margin-top: 2px; }
.day-sub b { color: var(--primary); }

.groups { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 12px; }
.group { --c: var(--primary); }
.ghead { display: flex; align-items: center; gap: 8px; min-height: 36px; }
.ghead .gico {
  width: 30px; height: 30px; border-radius: 10px; flex: none;
  display: grid; place-items: center; font-size: 16px;
  background: color-mix(in srgb, var(--c) 14%, white);
}
.ghead .gnm { font-weight: 800; font-size: 15px; letter-spacing: -.01em; }
.ghead .gst { font-size: 12.5px; color: var(--sub); flex: 1; }
.ghead .gst.has { color: var(--c); font-weight: 700; }
.book {
  flex: none; border: 0; border-radius: 999px; padding: 6px 12px;
  background: color-mix(in srgb, var(--c) 12%, white); color: var(--c);
  font-size: 13px; font-weight: 800;
}
.book:active { filter: brightness(.95); }
.group.none .ghead { opacity: .8; }
.group.none { padding-bottom: 2px; }

.usebar {
  position: relative; height: 8px; border-radius: 999px; background: #eef1f4;
  margin: 6px 0 10px;
}
.usebar .blk {
  position: absolute; top: 0; bottom: 0; background: var(--c); border-radius: 999px; min-width: 6px;
}
.usebar .now {
  position: absolute; top: -3px; bottom: -3px; width: 2px; background: var(--text); border-radius: 2px;
}

.list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.item {
  --c: var(--primary);
  display: flex; gap: 12px; align-items: center;
  padding: 12px 12px 12px 14px;
  background: #f9fafb; border-radius: 14px;
  border-left: 5px solid var(--c);
}
.item.past { opacity: .55; }
.item .body { flex: 1; min-width: 0; }
.item .body[data-jump] { cursor: pointer; }
.item .time { font-size: 14px; font-weight: 800; color: var(--c); letter-spacing: -.01em; }
.item .who { font-size: 15.5px; font-weight: 700; margin-top: 1px; word-break: break-all; }
.item .why { font-size: 13.5px; color: var(--sub); word-break: break-all; }
.item .meta { font-size: 12px; color: var(--sub); margin-bottom: 1px; }
.acts { flex: none; display: flex; flex-direction: column; gap: 6px; }
.del, .edit {
  border: 0; font-size: 13px; font-weight: 700; padding: 8px 12px; border-radius: 10px; min-width: 52px;
}
.del { background: #fff0f1; color: var(--danger); }
.del:active { background: #ffdde0; }
.edit { background: #eef4ff; color: var(--primary); }
.edit:active { background: #dce9ff; }
.cancel-edit {
  width: 100%; height: 48px; margin-top: 8px; border: 0; border-radius: 16px;
  background: #f2f4f6; color: #4e5968; font-size: 16px; font-weight: 700;
}
.cancel-edit:active { background: #e5e8eb; }

.empty {
  text-align: center; color: var(--sub); font-size: 14px;
  padding: 22px 8px; background: #f9fafb; border-radius: 14px;
}
.empty b { display: block; font-size: 15px; color: var(--text); margin-bottom: 2px; }

/* ---------- 탭 메뉴 ---------- */
.tabs-in { max-width: 1100px; margin: 0 auto; display: flex; gap: 4px; padding: 0 12px; }
.tab {
  flex: 1; text-align: center; text-decoration: none; color: var(--sub);
  font-size: 15px; font-weight: 700; padding: 10px 6px 11px;
  border-bottom: 3px solid transparent;
}
.tab.on { color: var(--primary); border-bottom-color: var(--primary); }
.tab:active { background: #f2f4f6; }
@media (min-width: 640px) {
  .tabs-in { padding: 0 20px; }
  .tab { flex: none; padding: 10px 26px 11px; }
}
@media (min-width: 1024px) { .tabs-in { padding: 0 24px; } }

/* ---------- 게이트 / 관리자 ---------- */
.narrow { max-width: 520px; margin: 0 auto; width: 100%; }
.center-card { text-align: center; padding: 28px 20px; }
.center-card .big-ico { font-size: 44px; line-height: 1; margin-bottom: 10px; }
.center-card h2 { font-size: 20px; margin-bottom: 6px; }
.center-card p { color: var(--sub); font-size: 14px; margin-bottom: 20px; }
.center-card .field { text-align: left; }
.pill {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  padding: 13px 14px; border-radius: 14px; font-size: 14.5px; font-weight: 700;
  background: #fff1f2; color: #b4232f; margin-bottom: 10px;
}
.pill.ok { background: #e8f7ef; color: #167a4a; }
.pill.wait { background: #fff7e0; color: #9a6a00; }
.gate-light {
  width: 120px; height: 120px; border-radius: 50%; margin: 6px auto 22px;
  border: 5px solid #3a4250; background: #5c6573;
  box-shadow: inset 0 0 20px rgba(0, 0, 0, .5); transition: all .3s ease;
}
.gate-light.on {
  background: radial-gradient(circle, #FFD700, #FFA500);
  box-shadow: 0 0 30px #FFD700, 0 0 60px #FFD700, inset 0 0 20px rgba(255, 215, 0, .5);
}
.gate-btn {
  width: 100%; height: 72px; border: 0; border-radius: 20px;
  background: var(--primary); color: #fff; font-size: 21px; font-weight: 800;
  box-shadow: 0 8px 24px rgba(49, 130, 246, .35);
}
.gate-btn:active { background: var(--primary-dark); }
.gate-btn:disabled { background: #b0c9f5; box-shadow: none; cursor: not-allowed; }
.link-btn { border: 0; background: transparent; color: var(--sub); font-size: 14px; font-weight: 600; text-decoration: underline; padding: 14px 8px 0; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.stack .card h2 { margin-bottom: 4px; }
.stack .card .hint { color: var(--sub); font-size: 13.5px; margin-bottom: 16px; }

/* ---------- 예약 입력 ---------- */
.formwrap {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  max-height: 92vh; max-height: 92dvh;
  transform: translateY(105%); transition: transform .28s cubic-bezier(.2, .8, .2, 1);
  visibility: hidden;
}
.formwrap.open { transform: none; visibility: visible; }
.formwrap .form {
  border-radius: 24px 24px 0 0; padding: 18px 18px calc(18px + var(--safe-b));
  max-height: inherit; overflow-y: auto; overscroll-behavior: contain;
  box-shadow: 0 -8px 30px rgba(0, 0, 0, .18);
}
.form-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.form-head h2 { font-size: 19px; }

.respick { display: flex; flex-wrap: wrap; gap: 8px; }
.rp {
  --c: var(--primary);
  display: inline-flex; align-items: center; gap: 6px;
  padding: 9px 13px; border-radius: 999px;
  background: #f9fafb; border: 1.5px solid var(--line);
  font-size: 14.5px; font-weight: 700; color: #4e5968;
}
.rp.on { border-color: var(--c); background: color-mix(in srgb, var(--c) 12%, white); color: var(--text); }
.field.bad .respick { outline: 2px solid #fcc; outline-offset: 4px; border-radius: 14px; }

.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: 13px; font-weight: 700; color: #4e5968; margin-bottom: 6px; }
.field input, .field select {
  width: 100%; height: 50px; padding: 0 14px;
  border: 1.5px solid var(--line); border-radius: 14px; background: #f9fafb;
  font-size: 16px; /* iOS 확대 방지 */
  outline: none; appearance: none; -webkit-appearance: none;
}
.field select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5l5 5 5-5' fill='none' stroke='%238b95a1' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 14px center; padding-right: 36px;
}
.field input:focus, .field select:focus { border-color: var(--primary); background: #fff; box-shadow: 0 0 0 4px rgba(49, 130, 246, .15); }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.check { display: flex; align-items: center; gap: 10px; margin: 2px 0 14px; font-size: 14px; color: #4e5968; }
.check input { width: 20px; height: 20px; accent-color: var(--primary); }

.msg { padding: 11px 13px; border-radius: 12px; font-size: 13.5px; margin-bottom: 12px; background: #fff1f2; color: #b4232f; }
.msg.ok { background: #e8f7ef; color: #167a4a; }

.primary {
  width: 100%; height: 54px; border: 0; border-radius: 16px;
  background: var(--primary); color: #fff; font-size: 17px; font-weight: 800;
}
.primary:active { background: var(--primary-dark); }
.primary:disabled { background: #b0c9f5; cursor: not-allowed; }

.fab {
  position: fixed; z-index: 30; left: 50%; transform: translateX(-50%);
  bottom: calc(18px + var(--safe-b));
  height: 54px; padding: 0 28px; border: 0; border-radius: 999px;
  background: var(--primary); color: #fff; font-size: 17px; font-weight: 800;
  box-shadow: 0 8px 24px rgba(49, 130, 246, .45);
}
.fab:active { background: var(--primary-dark); }

.scrim {
  position: fixed; inset: 0; z-index: 35; background: rgba(0, 0, 0, .45);
  opacity: 0; pointer-events: none; transition: opacity .25s;
}
.scrim.show { opacity: 1; pointer-events: auto; }

/* ---------- 확인 창 ---------- */
.modal {
  position: fixed; inset: 0; z-index: 60; background: rgba(0, 0, 0, .5);
  display: grid; place-items: center; padding: 24px;
}
.modal-box { background: #fff; border-radius: 22px; padding: 24px 20px 16px; width: 100%; max-width: 340px; }
.modal-box h3 { font-size: 18px; font-weight: 800; margin-bottom: 8px; }
.modal-box p { color: var(--sub); font-size: 14.5px; margin-bottom: 20px; word-break: break-all; }
.modal-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.modal-actions button { height: 50px; border: 0; border-radius: 14px; font-size: 16px; font-weight: 700; }
.ghost { background: #f2f4f6; color: #4e5968; }
.danger { background: var(--danger); color: #fff; }

.toast {
  position: fixed; z-index: 70; left: 50%; bottom: calc(90px + var(--safe-b));
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: rgba(25, 31, 40, .92); color: #fff; padding: 12px 18px; border-radius: 14px;
  font-size: 14.5px; font-weight: 600; transition: all .25s; max-width: calc(100vw - 32px); text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- 태블릿 (640px~) ---------- */
@media (min-width: 640px) {
  .layout { padding: 16px 20px 0; gap: 16px; }
  .content { gap: 16px; }
  .appbar-in { padding: 14px 20px; }
  .titles h1 { font-size: 20px; }

  .card { padding: 22px; }
  .cd { min-height: 70px; }
  .cd .n { width: 38px; height: 38px; font-size: 17px; }
  .dots { gap: 3px; }
  .dots i { width: 8px; height: 8px; }
  .ln { height: 6px; }

  .formwrap { left: 50%; right: auto; width: 100%; max-width: 560px; margin-left: -280px; }
  .formwrap .form { padding: 24px; padding-bottom: calc(24px + var(--safe-b)); }
}

/* ---------- PC (1024px~) : 왼쪽 달력/현황, 오른쪽 예약 입력 ---------- */
@media (min-width: 1024px) {
  body { padding-bottom: 40px; }
  .layout {
    display: grid; grid-template-columns: minmax(0, 1fr) 380px;
    align-items: start; gap: 20px; padding-top: 24px;
  }

  .formwrap {
    position: sticky; top: 130px; left: auto; right: auto; bottom: auto; width: auto; max-width: none;
    margin: 0; transform: none; visibility: visible; transition: none; max-height: none;
  }
  .formwrap .form { border-radius: var(--radius); box-shadow: var(--shadow); padding: 22px; max-height: calc(100vh - 150px); }
  .close-btn, .fab, .scrim { display: none !important; }

  .appbar-in { padding: 14px 24px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
