:root {
  --primary: #7c3aed;
  --primary-dark: #6d28d9;
  --primary-light: #ede9fe;
  --accent: #f59e0b;
  --danger: #dc2626;
  --success: #16a34a;
  --bg: #f6f5fa;
  --card: #ffffff;
  --text: #1f2333;
  --text-muted: #7a7f94;
  --border: #e8e6f0;
  --radius: 14px;
  --shadow: 0 6px 24px rgba(79, 60, 160, .10);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

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

.screen { display: none; padding: calc(var(--safe-top) + 16px) 16px calc(var(--safe-bottom) + 16px); }
.screen.active { display: block; }

/* ---------- gate ---------- */
.gate { text-align: center; padding-top: 8vh; }
.gate .logo { font-size: 64px; line-height: 1; }
.gate h1 { margin: 18px 0 8px; font-size: 26px; }
.gate .sub { color: var(--text-muted); font-size: 14px; line-height: 1.6; margin: 0 0 28px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: none; border-radius: var(--radius); font-size: 16px; font-weight: 600;
  padding: 14px 20px; cursor: pointer; transition: transform .08s ease, opacity .2s;
  touch-action: manipulation; text-decoration: none;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .45; pointer-events: none; }

.btn-primary { background: linear-gradient(135deg, var(--primary), var(--primary-dark)); color: #fff; box-shadow: 0 6px 18px rgba(124, 58, 237, .35); }
.btn-primary:hover { opacity: .94; }
.btn-ghost { background: transparent; color: var(--text-muted); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--primary-light); }
.btn-lg { width: 100%; }
.btn-sm { padding: 8px 12px; font-size: 13px; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-success { background: var(--success); color: #fff; }

.input {
  width: 100%; padding: 15px 16px; border-radius: var(--radius);
  border: 2px solid var(--border); background: var(--card);
  font-size: 17px; text-align: center; letter-spacing: 1px; outline: none;
  transition: border-color .2s;
}
.input:focus { border-color: var(--primary); }

.gate .input { margin-bottom: 14px; }
.gate .btn-lg { margin-top: 6px; }

.link-btn {
  background: none; border: none; color: var(--text-muted);
  text-decoration: underline; font-size: 13px; margin-top: 20px; cursor: pointer;
}

.divider { display: flex; align-items: center; gap: 12px; color: var(--text-muted); font-size: 13px; margin: 22px 0; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--border); }

/* ---------- topbar ---------- */
.topbar {
  display: flex; justify-content: space-between; align-items: center;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: #fff; border-radius: var(--radius); padding: 14px 16px;
  box-shadow: var(--shadow); margin-bottom: 18px;
}
.topbar-title { display: flex; align-items: center; gap: 12px; min-width: 0; }
.room-icon { font-size: 30px; }
.topbar-title h2 { margin: 0; font-size: 17px; }
.topbar-title p { margin: 2px 0 0; font-size: 12px; opacity: .85; }
.topbar-right { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
.topbar-btns { display: flex; gap: 6px; }
.unit-badge {
  background: rgba(255,255,255,.2); border: 1px solid rgba(255,255,255,.35);
  border-radius: 999px; padding: 4px 12px; font-size: 13px; font-weight: 700; letter-spacing: .5px;
}
.topbar .btn-ghost { border-color: rgba(255,255,255,.4); color: #fff; background: transparent; }
.topbar .btn-ghost:hover { background: rgba(255,255,255,.15); }
.topbar .btn-ghost.active { background: rgba(255,255,255,.28); border-color: #fff; }

/* ---------- calendar ---------- */
.month-nav { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.month-nav h3 { margin: 0; font-size: 18px; }
.nav-btn {
  width: 40px; height: 40px; border-radius: 12px; border: 1px solid var(--border);
  background: var(--card); font-size: 22px; line-height: 1; color: var(--primary);
  cursor: pointer; box-shadow: 0 2px 8px rgba(79,60,160,.08);
}
.nav-btn:active { transform: scale(.95); }

.calendar {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 10px; display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px;
}
.calendar .dow {
  text-align: center; font-size: 12px; color: var(--text-muted); font-weight: 700;
  padding: 6px 0; letter-spacing: 1px;
}
.calendar .dow.sat, .calendar .dow.sun { color: var(--accent); }

.day {
  position: relative; aspect-ratio: 1; border-radius: 12px; display: flex;
  flex-direction: column; align-items: center; justify-content: center;
  gap: 3px; min-height: 0;
  font-size: 16px; font-weight: 600; cursor: pointer; border: none;
  background: transparent; transition: background .15s; color: var(--text);
  line-height: 1;
}
.day > span:first-child { margin-top: -4px; }
.day > span:last-child { margin-bottom: -2px; }
.day:hover { background: var(--primary-light); }
.day:active { transform: scale(.93); }
.day.empty { visibility: hidden; }
.day.today { border: 2px solid var(--primary); }
.day.selected { background: var(--primary); color: #fff; box-shadow: 0 4px 12px rgba(124, 58, 237, .35); }
.day.today.selected { border-color: #fff; }
.day.selected .dot-booked { background: #fff; }
.day.selected .dot-free { background: rgba(255, 255, 255, .45); }
.day.past { color: #c3c6d4; cursor: default; }
.day.past:hover { background: transparent; }
.day.full { background: repeating-linear-gradient(45deg, #fef2f2, #fef2f2 6px, #fde8e8 6px, #fde8e8 12px); color: #991b1b; }
.day.full:hover { background: repeating-linear-gradient(45deg, #fef2f2, #fef2f2 6px, #fde8e8 6px, #fde8e8 12px); }

.dots { display: flex; gap: 3px; margin-top: 4px; height: 6px; }
.dot { width: 6px; height: 6px; border-radius: 50%; }
.dot-free { background: #d5d9e6; }
.dot-booked { background: var(--primary); }
.dot-full { background: var(--danger); }

.legend {
  display: flex; flex-wrap: wrap; gap: 8px 16px;
  justify-content: center; align-items: center;
  margin: 14px 0 6px; font-size: 12px; color: var(--text-muted);
  line-height: 1.4;
}
.legend span { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.legend .dot {
  display: inline-block; flex: 0 0 auto;
  width: 9px; height: 9px; border-radius: 50%;
  vertical-align: middle; position: static;
}
.legend .dot-free { background: #d5d9e6; }
.legend .dot-partial { background: #a78bfa; }
.legend .dot-full { background: var(--danger); }
.legend .dot-past { background: #c3c6d4; }

/* ---------- management list ---------- */
.my-bookings { margin-top: 18px; }
.mgmt-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.mgmt-head h4 { margin: 0; font-size: 15px; color: var(--text-muted); }
.booking-list { display: flex; flex-direction: column; gap: 10px; }
.booking-card {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 12px 14px; display: flex; justify-content: space-between; align-items: center; gap: 10px;
  border-left: 4px solid var(--primary);
}
.booking-card .b-date { font-weight: 700; font-size: 15px; }
.booking-card .b-slot { color: var(--text-muted); font-size: 13px; margin-top: 2px; }
.booking-card .b-owner { font-size: 12px; color: var(--primary-dark); font-weight: 600; margin-top: 2px; }
.empty-state { color: var(--text-muted); font-size: 13px; text-align: center; padding: 18px 0; background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); }

.foot { text-align: center; color: #b4b8c8; font-size: 12px; margin-top: 26px; }
.foot code { background: #eef0f8; padding: 2px 6px; border-radius: 6px; }

/* ---------- sheets ---------- */
.backdrop {
  position: fixed; inset: 0; background: rgba(20, 15, 40, .45);
  z-index: 40; animation: fadeIn .18s ease;
}
.sheet {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--safe-bottom) + 12px); z-index: 50;
  width: calc(100% - 24px); max-width: 496px;
  background: var(--card); border-radius: 20px; padding: 10px 18px calc(var(--safe-bottom) + 14px);
  box-shadow: 0 -8px 40px rgba(20,15,40,.25); animation: slideUp .22s ease;
}
.sheet-handle { width: 40px; height: 4px; border-radius: 2px; background: #e0e2ec; margin: 6px auto 12px; }
.sheet h3 { margin: 0; font-size: 18px; }
.sheet-date { color: var(--text-muted); font-size: 13px; margin: 4px 0 14px; }
.slot-list { display: flex; flex-direction: column; gap: 10px; max-height: 46vh; overflow-y: auto; }
.slot-item {
  display: flex; justify-content: space-between; align-items: center;
  border: 2px solid var(--border); border-radius: var(--radius); padding: 13px 14px;
  cursor: pointer; transition: border-color .15s, background .15s;
}
.slot-item:active { transform: scale(.98); }
.slot-item .s-time { font-weight: 700; }
.slot-item .s-sub { font-size: 13px; color: var(--text-muted); margin-top: 1px; }
.slot-item .s-owner { font-size: 12px; color: var(--primary-dark); font-weight: 600; margin-top: 2px; }
.slot-item .s-state { font-size: 13px; color: var(--text-muted); flex-shrink: 0; }
.slot-item.taken { background: #f7f6fa; border-color: var(--border); opacity: .75; cursor: default; }
.slot-item.taken:active { transform: none; }
.slot-item.taken .s-state { color: var(--danger); }
.slot-item.taken.clickable { cursor: pointer; }
.slot-item.selected { border-color: var(--primary); background: var(--primary-light); }
.slot-item.free:hover { border-color: var(--primary); }
.sheet-hint { color: var(--text-muted); font-size: 13px; text-align: center; padding: 10px 0 2px; }
.admin-book-row { display: none; }
.admin-book-row:not([hidden]) { display: flex; flex-direction: column; gap: 10px; margin-top: 14px; }
.admin-book-row .input { text-align: center; }
.sheet .btn { width: 100%; margin-top: 14px; }
#login-sheet .input { margin-top: 4px; }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--safe-bottom) + 24px);
  background: rgba(28, 25, 45, .92); color: #fff; padding: 12px 22px; border-radius: 999px;
  font-size: 14px; z-index: 60; box-shadow: 0 6px 24px rgba(0,0,0,.3);
  animation: fadeIn .2s ease; max-width: 90%; text-align: center;
}

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { transform: translate(-50%, 30px); opacity: 0; } to { transform: translate(-50%, 0); opacity: 1; } }

@media (display-mode: standalone) {
  .topbar { margin-top: 4px; }
}
