:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --text: var(--tg-theme-text-color, #1a1a1a);
  --hint: var(--tg-theme-hint-color, #8a8a8a);
  --card: var(--tg-theme-secondary-bg-color, #f3f3f3);
  --sep: rgba(128, 128, 128, 0.22);
  --accent: var(--tg-theme-button-color, #2a78d6);
  /* 押金状态色(在深浅主题都可读) */
  --paid: #19a86f;
  --unpaid: #e0962a;
  --refunded: #9a9a9a;
}

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

body {
  margin: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  font-family: -apple-system, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}

.topbar {
  flex: 0 0 auto;
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 14px; background: var(--bg);
  border-bottom: 1px solid var(--sep);
}
.topbar .title { font-weight: 600; font-size: 16px; }
.nav button {
  border: 1px solid var(--sep); background: transparent; color: var(--text);
  border-radius: 8px; padding: 5px 11px; margin-left: 6px; font-size: 14px;
}
.nav button:active { background: var(--card); }

.legend {
  display: flex; flex-wrap: wrap; gap: 12px;
  padding: 8px 14px; font-size: 11px; color: var(--hint);
  border-bottom: 1px solid var(--sep);
}
.legend span { display: flex; align-items: center; gap: 5px; }
.sw { width: 11px; height: 11px; border-radius: 3px; display: inline-block; }
.sw-booked { background: var(--paid); }
.sw-free { border: 1px dashed var(--hint); }

.devhead {
  flex: 0 0 auto;
  display: grid; grid-template-columns: 48px 1fr 1fr 1fr;
  background: var(--bg); border-bottom: 1px solid var(--sep);
}
.devhead .cell {
  text-align: center; padding: 8px 2px; font-size: 12px;
  font-weight: 600; color: var(--hint);
}

.scroll { flex: 1 1 auto; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }
.legend { flex: 0 0 auto; }
.grid {
  display: grid;
  grid-template-columns: 44px 1fr 1fr 1fr;
  grid-auto-rows: 40px;
  position: relative;
}

.gridline { border-top: 1px solid var(--sep); }
.gridline.today { border-top: 2px solid var(--accent); }

.datecell { grid-column: 1; position: relative; }
.datelbl {
  position: absolute; top: 0; right: 8px; transform: translateY(-50%);
  font-size: 12px; color: var(--hint); background: var(--bg); padding-left: 3px;
  white-space: nowrap;
}
.datelbl.today {
  color: #fff; background: var(--accent); font-weight: 500;
  font-size: 11px; padding: 1px 6px; border-radius: 20px;
}

.ext-line {
  width: 2px; justify-self: center; border-radius: 2px;
  background: repeating-linear-gradient(to bottom, var(--hint) 0 5px, transparent 5px 9px);
}
.ext-label {
  position: absolute; top: 0; left: 50%; transform: translate(-50%, -50%);
  font-size: 10px; color: var(--hint); background: var(--bg);
  white-space: nowrap; padding: 0 5px; text-align: center;
}

.block {
  margin: 0 4px; border-radius: 12px; padding: 7px 10px;
  display: flex; flex-direction: column; justify-content: space-between;
  overflow: hidden; cursor: pointer; min-height: 0; position: relative;
  background: var(--card); border: 0.5px solid var(--sep);
}
.block .mid { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.block .name { font-weight: 500; font-size: 15px; color: var(--text); letter-spacing: -0.2px; }
.block .chip {
  display: inline-flex; align-items: center; font-size: 11px; color: var(--hint);
  background: var(--sep); padding: 2px 8px; border-radius: 20px; line-height: 1;
}
.block .edge { font-size: 10.5px; color: var(--hint); white-space: nowrap; line-height: 1.2; text-align: center; }

.empty-hint {
  text-align: center; color: var(--hint); padding: 40px 16px; font-size: 13px;
}

.sheet-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.4);
  opacity: 0; pointer-events: none; transition: opacity .15s; z-index: 9;
}
.sheet-backdrop.show { opacity: 1; pointer-events: auto; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  background: var(--bg); border-radius: 16px 16px 0 0;
  padding: 18px 18px calc(18px + env(safe-area-inset-bottom));
  transform: translateY(110%); transition: transform .2s ease;
  box-shadow: 0 -6px 24px rgba(0,0,0,0.2);
}
.sheet.show { transform: translateY(0); }
.sheet h3 { margin: 0 0 10px; font-size: 17px; }
.sheet .row { display: flex; justify-content: space-between; padding: 6px 0; border-top: 1px solid var(--sep); font-size: 14px; }
.sheet .row .k { color: var(--hint); }
.sheet .edit { width: 100%; margin-top: 14px; padding: 11px; border: 1px solid var(--sep); border-radius: 10px; background: transparent; color: var(--text); font-size: 15px; }
.sheet .edit:active { background: var(--card); }
.ed-row { display: flex; align-items: center; gap: 8px; padding: 8px 0; border-top: 1px solid var(--sep); }
.ed-row .k { color: var(--hint); width: 40px; flex: 0 0 auto; }
.ed-row input { flex: 1; min-width: 0; padding: 8px; border: 1px solid var(--sep); border-radius: 8px; background: var(--bg); color: var(--text); font-size: 15px; }
.ed-row input[type="time"] { flex: 0 0 auto; width: 100px; }
.ed-hint { font-size: 12px; color: var(--hint); margin: 8px 0 0; line-height: 1.5; }
.sheet-actions { display: flex; gap: 10px; margin-top: 16px; }
.sheet .close { flex: 1; padding: 11px; border: none; border-radius: 10px; background: var(--accent); color: #fff; font-size: 15px; }
.sheet .del { flex: 1; padding: 11px; border: none; border-radius: 10px; background: #e24b4a; color: #fff; font-size: 15px; }
.sheet .del:active { background: #c23a39; }
