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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--tg-theme-bg-color, #fff);
  color: var(--tg-theme-text-color, #000);
  min-height: 100vh;
}

/* ── Top bar ─────────────────────────────────────────────── */
#topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  background: var(--tg-theme-bg-color, #fff);
  border-bottom: 1px solid rgba(0,0,0,.08);
}

#month-label {
  flex: 1;
  text-align: center;
  font-weight: 600;
  font-size: 16px;
}

.nav-btn {
  background: none;
  border: none;
  font-size: 26px;
  line-height: 1;
  cursor: pointer;
  color: var(--tg-theme-link-color, #2481cc);
  padding: 0 4px;
}

.search-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--tg-theme-link-color, #2481cc);
  display: flex;
  align-items: center;
  padding: 4px;
}

/* ── Search bar ──────────────────────────────────────────── */
#search-bar {
  display: flex;
  align-items: center;
  padding: 8px 12px;
  gap: 8px;
  border-bottom: 1px solid rgba(0,0,0,.08);
  background: var(--tg-theme-bg-color, #fff);
  position: sticky;
  top: 49px;
  z-index: 99;
}

#search-bar.hidden { display: none; }

#search-input {
  flex: 1;
  border: 1px solid rgba(0,0,0,.15);
  border-radius: 8px;
  padding: 7px 10px;
  font-size: 14px;
  background: var(--tg-theme-secondary-bg-color, #f4f4f5);
  color: var(--tg-theme-text-color, #000);
  outline: none;
}

#search-clear {
  background: none;
  border: none;
  font-size: 16px;
  cursor: pointer;
  color: #888;
  padding: 4px;
}

/* ── Calendar container ───────────────────────────────────── */
#calendar-container {
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

/* ── Month block ─────────────────────────────────────────── */
.month-block { scroll-margin-top: 100px; }

.month-title {
  font-weight: 600;
  font-size: 15px;
  margin-bottom: 8px;
  color: var(--tg-theme-hint-color, #888);
  text-transform: capitalize;
}

.weekdays {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  margin-bottom: 4px;
}

.weekday-label {
  text-align: center;
  font-size: 11px;
  color: var(--tg-theme-hint-color, #888);
  font-weight: 500;
  padding: 2px 0;
}

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

/* ── Day cell ────────────────────────────────────────────── */
.day-cell {
  position: relative;
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  font-size: 14px;
  cursor: pointer;
  transition: background 0.15s;
}

.day-cell:hover { background: rgba(0,0,0,.06); }

.day-cell.empty { cursor: default; }
.day-cell.empty:hover { background: none; }

.day-cell.today {
  background: var(--tg-theme-link-color, #2481cc);
  color: #fff;
}

.day-cell.has-records { font-weight: 600; }

/* red badge */
.day-cell .badge {
  position: absolute;
  top: 1px;
  right: 1px;
  background: #e53935;
  color: #fff;
  border-radius: 50%;
  min-width: 16px;
  height: 16px;
  font-size: 9px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 3px;
  line-height: 1;
}

/* search highlight */
.day-cell.search-match {
  outline: 2px solid #e53935;
  outline-offset: 1px;
  border-radius: 50%;
}

/* ── Modal ───────────────────────────────────────────────── */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 200;
  display: flex;
  align-items: flex-end;
}

.modal.hidden { display: none; }

.modal-inner {
  background: var(--tg-theme-bg-color, #fff);
  width: 100%;
  max-height: 80vh;
  border-radius: 16px 16px 0 0;
  padding: 16px;
  overflow-y: auto;
}

#modal-close {
  float: right;
  background: none;
  border: none;
  font-size: 18px;
  cursor: pointer;
  color: #888;
  margin-top: -4px;
}

#modal-date {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 12px;
}

/* ── Record card ─────────────────────────────────────────── */
.record-card {
  background: var(--tg-theme-secondary-bg-color, #f4f4f5);
  border-radius: 10px;
  padding: 12px;
  margin-bottom: 10px;
  font-size: 13px;
  line-height: 1.6;
}

.record-card .field-label {
  color: var(--tg-theme-hint-color, #888);
  font-size: 11px;
}

.record-card a {
  color: var(--tg-theme-link-color, #2481cc);
  text-decoration: none;
}
