:root {
  --paper: #f3eee4;
  --paper-2: #e8e0d2;
  --sheet: #fffaf1;
  --ink: #241e18;
  --ink-soft: #6a5f54;
  --line: #d9cfc0;
  --clay: #b85c38;
  --clay-deep: #8f3f24;
  --moss: #3f5c47;
  --moss-soft: #dce8de;
  --gold: #b0893e;
  --danger: #a33b32;
  --shadow: 0 18px 40px rgba(48, 32, 18, 0.08);
  --radius: 22px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  min-height: 100%;
}

[hidden] {
  display: none !important;
}

body {
  font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(1200px 500px at 10% -10%, #f7e7d4 0%, transparent 55%),
    radial-gradient(900px 420px at 100% 0%, #e7efe6 0%, transparent 50%),
    var(--paper);
  line-height: 1.45;
}

button, input, select {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  border: 0;
  background: none;
}

a {
  color: inherit;
}

.app {
  width: min(920px, calc(100% - 28px));
  margin: 0 auto;
  padding: 22px 0 80px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 22px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.mark {
  width: 42px;
  height: 42px;
  border-radius: 14px;
  background: var(--ink);
  color: var(--sheet);
  display: grid;
  place-items: center;
  font-family: "PingFang SC", "Hiragino Sans GB", "Songti SC", "Noto Serif SC", serif;
  font-weight: 600;
  letter-spacing: 0.08em;
}

.brand h1 {
  font-family: "PingFang SC", "Hiragino Sans GB", "Songti SC", "Noto Serif SC", serif;
  font-size: 28px;
  font-weight: 600;
  letter-spacing: 0.04em;
}

.brand p {
  color: var(--ink-soft);
  font-size: 13px;
}

.chip, .btn, .ghost {
  border-radius: 999px;
  padding: 10px 16px;
  transition: transform 0.15s ease, background 0.15s ease;
}

.chip, .ghost {
  background: var(--sheet);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.chip:hover, .ghost:hover, .btn:hover {
  transform: translateY(-1px);
}

.btn {
  background: var(--clay);
  color: #fffaf4;
  font-weight: 600;
}

.btn.secondary {
  background: var(--ink);
}

.btn.danger {
  background: var(--danger);
}

.btn:disabled, .chip:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
}

.month-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 8px 0 18px;
}

.month-nav h2 {
  font-family: "PingFang SC", "Hiragino Sans GB", "Songti SC", "Noto Serif SC", serif;
  font-size: 34px;
  font-weight: 500;
}

.nav-btn {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--sheet);
  border: 1px solid var(--line);
  font-size: 20px;
}

.legend {
  display: flex;
  gap: 16px;
  color: var(--ink-soft);
  font-size: 13px;
  margin-bottom: 14px;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
  margin-right: 6px;
}

.dot.open { background: var(--moss); }
.dot.busy { background: var(--clay); }
.dot.rest { background: #c4b8a8; }

.weekdays, .grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 8px;
}

.weekdays {
  margin-bottom: 8px;
  color: var(--ink-soft);
  font-size: 13px;
  text-align: center;
}

.day {
  min-height: 92px;
  background: var(--sheet);
  border: 1px solid transparent;
  border-radius: 18px;
  padding: 10px 8px 8px;
  text-align: left;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.day:hover:not(:disabled) {
  border-color: var(--ink);
}

.day:disabled {
  opacity: 0.42;
  cursor: default;
}

.day.empty {
  background: transparent;
  box-shadow: none;
  min-height: 0;
}

.day .num {
  font-family: "Songti SC", "PingFang SC", serif;
  font-size: 22px;
}

.day.today .num {
  color: var(--clay);
}

.day.mine {
  border-color: var(--clay);
}

.day .meta {
  font-size: 12px;
  color: var(--ink-soft);
}

.bar {
  height: 5px;
  border-radius: 99px;
  background: var(--paper-2);
  overflow: hidden;
}

.bar > span {
  display: block;
  height: 100%;
  background: var(--moss);
}

.bar.full > span {
  background: var(--clay);
}

.sheet-mask, .modal-mask {
  position: fixed;
  inset: 0;
  background: rgba(36, 30, 24, 0.38);
  display: none;
  z-index: 20;
}

.sheet-mask.show, .modal-mask.show {
  display: block;
}

.sheet, .modal {
  position: fixed;
  z-index: 21;
  background: var(--sheet);
  box-shadow: var(--shadow);
}

.sheet {
  left: 50%;
  bottom: 0;
  transform: translateX(-50%) translateY(110%);
  width: min(640px, 100%);
  border-radius: 28px 28px 0 0;
  padding: 18px 20px calc(20px + env(safe-area-inset-bottom));
  transition: transform 0.28s ease;
}

.sheet.show {
  transform: translateX(-50%) translateY(0);
}

.handle {
  width: 48px;
  height: 5px;
  border-radius: 99px;
  background: var(--line);
  margin: 0 auto 14px;
}

.sheet-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 16px;
}

.sheet-head h3 {
  font-family: "PingFang SC", "Hiragino Sans GB", "Songti SC", "Noto Serif SC", serif;
  font-size: 28px;
  font-weight: 500;
}

.slots {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 52vh;
  overflow: auto;
}

.slot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: #fff;
  width: 100%;
  text-align: left;
}

.slot .time {
  font-size: 18px;
  font-weight: 600;
}

.slot .state {
  font-size: 13px;
  color: var(--ink-soft);
}

.slot.open:hover {
  border-color: var(--moss);
}

.slot.mine {
  border-color: var(--clay);
  background: #f8ece4;
}

.slot.booked, .slot.past, .slot.closed {
  opacity: 0.55;
}

.modal {
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(420px, calc(100% - 28px));
  border-radius: var(--radius);
  padding: 22px;
  display: none;
}

.modal.show {
  display: block;
}

.student-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 50vh;
  overflow: auto;
  margin: 14px 0;
}

.student-list button {
  text-align: left;
  padding: 12px 14px;
  border-radius: 14px;
  background: var(--paper);
}

.student-list button.active,
.student-list button:hover {
  background: var(--moss-soft);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 12px;
}

.field label {
  font-size: 13px;
  color: var(--ink-soft);
}

.field input, .field select {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 12px;
  padding: 11px 12px;
  outline: none;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%) translateY(20px);
  background: var(--ink);
  color: #fffaf1;
  padding: 10px 16px;
  border-radius: 999px;
  opacity: 0;
  pointer-events: none;
  transition: 0.2s ease;
  z-index: 40;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.admin-login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.card {
  width: min(420px, 100%);
  background: var(--sheet);
  border-radius: 28px;
  padding: 28px;
  box-shadow: var(--shadow);
}

.tabs {
  display: flex;
  gap: 8px;
  margin: 8px 0 18px;
  flex-wrap: wrap;
}

.tabs button {
  padding: 8px 14px;
  border-radius: 999px;
  color: var(--ink-soft);
}

.tabs button.active {
  background: var(--ink);
  color: var(--sheet);
}

.panel {
  display: none;
}

.panel.show {
  display: block;
}

.list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: var(--sheet);
  border-radius: 16px;
  padding: 12px 14px;
  box-shadow: var(--shadow);
}

.muted {
  color: var(--ink-soft);
  font-size: 13px;
}

.templates {
  display: grid;
  gap: 12px;
}

.template-card {
  background: var(--sheet);
  border-radius: 20px;
  padding: 16px;
  box-shadow: var(--shadow);
}

.slot-edit input[type="time"] {
  width: 118px;
}

.slot-edit {
  display: flex;
  gap: 8px;
  align-items: center;
  margin: 8px 0;
}

.slot-edit input {
  width: 92px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px;
  background: #fff;
}

.add-row {
  display: flex;
  gap: 8px;
  margin-top: 12px;
  flex-wrap: wrap;
}

.add-row input {
  flex: 1;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 12px;
  padding: 11px 12px;
  outline: none;
}

.admin-login .btn {
  width: 100%;
}

.roster {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.gantt,
.student-card {
  background: var(--sheet);
  border-radius: 22px;
  padding: 16px 16px 14px;
  box-shadow: var(--shadow);
}

.gantt-scale {
  position: relative;
  height: 22px;
  margin: 0 2px 6px 2px;
  color: var(--ink-soft);
  font-size: 12px;
}

.gantt-scale span {
  position: absolute;
  transform: translateX(-50%);
  white-space: nowrap;
}

.gantt-scale span:first-child {
  transform: none;
}

.gantt-scale span:last-child {
  transform: translateX(-100%);
}

.gantt-row {
  padding: 14px 0 16px;
  border-top: 1px solid var(--line);
}

.gantt-row:first-of-type {
  border-top: 0;
  padding-top: 8px;
}

.gantt-track {
  position: relative;
  height: 28px;
  margin-top: 10px;
  background:
    repeating-linear-gradient(
      90deg,
      transparent 0,
      transparent calc(25% - 1px),
      var(--line) calc(25% - 1px),
      var(--line) 25%
    ),
    var(--paper-2);
  border-radius: 999px;
  overflow: hidden;
}

.gantt-bar {
  height: 100%;
  min-width: 0;
  border-radius: 999px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding: 0 10px;
  color: #fffaf4;
  font-size: 12px;
  font-weight: 700;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.12);
}

.gantt-bar.ok {
  background: linear-gradient(90deg, #4e6f58, #7fa37c);
}

.gantt-bar.soon {
  background: linear-gradient(90deg, var(--clay), var(--gold));
}

.gantt-bar.overdue {
  background: linear-gradient(90deg, #8d2f2a, var(--danger));
}

.gantt-bar.none {
  background: transparent;
  box-shadow: none;
}

.gantt-row.overdue .roster-deadline {
  color: var(--danger);
}

.gantt-row.self {
  background: #f7efe4;
  margin: 0 -10px;
  padding-left: 10px;
  padding-right: 10px;
  border-radius: 18px;
}

.name-blur {
  filter: blur(7px);
  user-select: none;
  pointer-events: none;
  letter-spacing: 0.12em;
}

.booking-table {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 0 0 18px;
}

.booking-table .row {
  align-items: flex-start;
}

.booking-table .when {
  min-width: 150px;
  font-weight: 700;
}

.day .who {
  display: block;
  margin-top: 4px;
  font-size: 11px;
  line-height: 1.35;
  color: var(--ink);
  font-weight: 600;
  word-break: break-all;
}

.roster-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.roster-head h2,
.student-card strong {
  font-size: 20px;
  font-weight: 650;
}

.roster-days {
  margin-top: 10px;
  font-size: 22px;
  font-weight: 700;
}

.roster-deadline {
  margin-top: 2px;
  font-weight: 600;
  color: var(--ink-soft);
  font-size: 14px;
}

.gantt-row.overdue .roster-days {
  color: var(--danger);
}

.roster-remain,
.gantt-row.none .roster-deadline {
  margin-top: 4px;
  color: var(--ink-soft);
  font-size: 14px;
}

.student-card .field {
  margin: 12px 0 8px;
}

.student-card .field span {
  display: block;
  margin-bottom: 6px;
  color: var(--ink-soft);
  font-size: 13px;
}

.check {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  font-size: 14px;
}

.check input {
  width: 18px;
  height: 18px;
}

.add-row input[type="date"] {
  flex: 0 0 148px;
}

.share-box {
  background: var(--sheet);
  border-radius: 20px;
  padding: 16px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}

.share-box code {
  display: block;
  margin: 8px 0 12px;
  word-break: break-all;
  font-size: 14px;
}

.empty {
  padding: 28px 8px;
  text-align: center;
  color: var(--ink-soft);
}

@media (max-width: 720px) {
  .app {
    width: min(100% - 18px, 920px);
  }
  .month-nav h2 {
    font-size: 26px;
  }
  .day {
    min-height: 76px;
    padding: 8px 6px;
    border-radius: 14px;
  }
  .day .num {
    font-size: 18px;
  }
  .weekdays, .grid {
    gap: 5px;
  }
}
