* { 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-button-color, #2481cc);
  color: var(--tg-theme-button-text-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%;
  scroll-margin-top: 120px;
}

/* ── Modal ───────────────────────────────────────────────── */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,.45);
  z-index: 200;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
}

.modal.hidden { display: none; }

.modal-wrapper {
  width: 100%;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  background: var(--tg-theme-bg-color, #fff);
  border-radius: 16px 16px 0 0;
  overflow: hidden;
  flex-shrink: 0;
}

.modal-headers {
  padding: 16px 16px 0;
  flex-shrink: 0;
}

.modal-inner {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 0 16px 16px;
}

/* ── Modal header ────────────────────────────────────────── */
.modal-header-default {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.modal-header-select {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.modal-header-default.hidden,
.modal-header-select.hidden { display: none; }


#modal-date {
  font-size: 13px;
  font-weight: 600;
}

#modal-close,
#worker-modal-close,
#worker-self-btn {
  background: none;
  border: none;
  font-size: 18px;
  cursor: pointer;
  color: #888;
  padding: 2px;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

#worker-self-btn:disabled {
  opacity: 0.45;
  cursor: default;
}

#modal-select-btn {
  background: none;
  border: none;
  font-size: 14px;
  cursor: pointer;
  color: var(--tg-theme-link-color, #2481cc);
  padding: 2px;
}

#modal-cancel-select {
  background: none;
  border: none;
  font-size: 14px;
  cursor: pointer;
  color: var(--tg-theme-link-color, #2481cc);
}

#modal-select-all {
  background: none;
  border: none;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  color: var(--tg-theme-link-color, #2481cc);
}

/* ── 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;
  transition: outline 0.1s;
}

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

.record-field {
  margin-bottom: 8px;
}

.record-field:last-of-type {
  margin-bottom: 0;
}

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

/* Report link styled as button */
.record-report-btn {
  display: inline-block;
  padding: 5px 12px;
  background: var(--tg-theme-button-color, #2481cc);
  color: var(--tg-theme-button-text-color, #fff) !important;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  text-decoration: none !important;
}

/* Copy button on each card */
.record-copy-btn {
  display: block;
  width: 100%;
  margin-top: 10px;
  padding: 7px;
  background: none;
  border: 1px solid rgba(0,0,0,.12);
  border-radius: 8px;
  font-size: 13px;
  cursor: pointer;
  color: var(--tg-theme-link-color, #2481cc);
}

/* Selection checkbox */
.record-check {
  display: none;
  align-items: center;
  margin-bottom: 8px;
}

.check-circle {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid #ccc;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
  flex-shrink: 0;
}

/* Selection mode */
.select-mode .record-check { display: flex; }
.select-mode .record-copy-btn { display: none; }
.record-delete-btn {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 7px;
  background: none;
  border: 1px solid #e74c3c;
  border-radius: 8px;
  color: #e74c3c;
  font-size: 14px;
  cursor: pointer;
}
.select-mode .record-delete-btn { display: none; }
.select-mode .record-card { cursor: pointer; }

.record-card.selected {
  outline: 2px solid var(--tg-theme-button-color, #2481cc);
  outline-offset: 1px;
}

.record-card.selected .check-circle {
  background: var(--tg-theme-button-color, #2481cc);
  border-color: var(--tg-theme-button-color, #2481cc);
}

.record-card.search-match {
  outline: 2px solid #e53935;
  outline-offset: 1px;
}

.record-card.selected .check-circle::after {
  content: '✓';
  color: #fff;
  font-size: 12px;
  font-weight: bold;
}

/* ── Bottom send bar ─────────────────────────────────────── */
#modal-send-bar {
  padding: 10px 16px;
  border-top: 1px solid rgba(0,0,0,.08);
  background: var(--tg-theme-bg-color, #fff);
  flex-shrink: 0;
}

#modal-send-bar.hidden { display: none; }

#modal-send-selected {
  width: 100%;
  padding: 12px;
  background: var(--tg-theme-button-color, #2481cc);
  color: var(--tg-theme-button-text-color, #fff);
  border: none;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}

#modal-send-selected:disabled {
  opacity: 0.45;
  cursor: default;
}

/* ── Worker modal ────────────────────────────────────────── */
.modal-wrapper-small {
  max-height: 60vh;
}

.worker-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  border-bottom: 1px solid rgba(0,0,0,.07);
  cursor: pointer;
  transition: background 0.1s;
}

.worker-item:active {
  background: rgba(0,0,0,.05);
}

.worker-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--tg-theme-button-color, #2481cc);
  color: var(--tg-theme-button-text-color, #fff);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 17px;
  font-weight: 600;
  flex-shrink: 0;
}

.worker-avatar img {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
  display: block;
}

.worker-info {
  flex: 1;
  min-width: 0;
}

.worker-name {
  font-size: 15px;
  font-weight: 500;
  color: var(--tg-theme-text-color, #000);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.worker-username {
  font-size: 13px;
  color: var(--tg-theme-hint-color, #888);
  margin-top: 1px;
}

.worker-check {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid #ccc;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.worker-item.selected .worker-check {
  background: var(--tg-theme-button-color, #2481cc);
  border-color: var(--tg-theme-button-color, #2481cc);
}

.worker-item.selected .worker-check::after {
  content: '✓';
  color: #fff;
  font-size: 12px;
  font-weight: bold;
}

#worker-send-bar {
  padding: 10px 16px;
  border-top: 1px solid rgba(0,0,0,.08);
  background: var(--tg-theme-bg-color, #fff);
  flex-shrink: 0;
}

#worker-confirm-btn {
  width: 100%;
  padding: 12px;
  background: var(--tg-theme-button-color, #2481cc);
  color: var(--tg-theme-button-text-color, #fff);
  border: none;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}

#worker-confirm-btn:disabled {
  opacity: 0.45;
  cursor: default;
}

/* ── Search match counter ────────────────────────────────── */
#search-match-counter {
  padding: 8px 16px;
  background: #e53935;
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  text-align: center;
  flex-shrink: 0;
}

#search-match-counter.hidden { display: none; }
