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

:root {
  --bg: var(--tg-theme-bg-color, #f4f5f8);
  --card: var(--tg-theme-secondary-bg-color, #ffffff);
  --text: var(--tg-theme-text-color, #1a1c22);
  --hint: var(--tg-theme-hint-color, #8a8f98);
  --accent: var(--tg-theme-button-color, #4f8ef7);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --shared: #34a86c;
  --line: rgba(128,128,128,.18);
}

html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--text);
  font-size: 16px; overscroll-behavior: none;
}
#app { max-width: 560px; margin: 0 auto; padding: 12px 12px 84px; }
.hidden { display: none !important; }

/* Шапка */
.top { display: flex; align-items: center; justify-content: space-between; padding: 4px 2px 10px; }
.top-title { font-size: 22px; font-weight: 700; }
.legend { display: flex; gap: 10px; font-size: 12px; color: var(--hint); }
.legend .dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 4px; }

/* Навигация по месяцам */
.cal-nav { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.cal-month { font-size: 17px; font-weight: 600; text-transform: capitalize; }
.nav-btn {
  width: 40px; height: 40px; border: none; border-radius: 12px;
  background: var(--card); color: var(--text); font-size: 22px; cursor: pointer;
  box-shadow: 0 1px 3px rgba(0,0,0,.06);
}

/* Сетка */
.weekdays { display: grid; grid-template-columns: repeat(7, 1fr); text-align: center;
  font-size: 12px; color: var(--hint); margin-bottom: 4px; }
.weekdays .wknd { color: #d66; }
.grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cell {
  aspect-ratio: 1 / 1.05; border-radius: 12px; background: var(--card);
  display: flex; flex-direction: column; align-items: center; justify-content: flex-start;
  padding-top: 6px; cursor: pointer; border: 2px solid transparent;
  box-shadow: 0 1px 2px rgba(0,0,0,.04); position: relative; font-size: 15px;
}
.cell.empty { background: transparent; box-shadow: none; cursor: default; }
.cell.today { border-color: var(--accent); font-weight: 700; }
.cell.sel { background: var(--accent); color: var(--accent-text); }
.cell .dots { display: flex; gap: 3px; margin-top: 4px; flex-wrap: wrap; justify-content: center; padding: 0 3px; }
.cell .dots i { width: 6px; height: 6px; border-radius: 50%; }

/* Список событий дня */
.day-panel { margin-top: 14px; }
.day-head { font-weight: 700; margin-bottom: 8px; font-size: 15px; }
.ev {
  display: flex; align-items: center; gap: 10px; background: var(--card);
  border-radius: 14px; padding: 12px; margin-bottom: 8px; cursor: pointer;
  box-shadow: 0 1px 3px rgba(0,0,0,.05); border-left: 4px solid var(--hint);
}
.ev .ev-time { font-size: 13px; color: var(--hint); min-width: 44px; text-align: center; }
.ev .ev-title { font-weight: 600; }
.ev .ev-sub { font-size: 12px; color: var(--hint); margin-top: 2px; }
.empty-note { color: var(--hint); font-size: 14px; text-align: center; padding: 16px 0; }

/* Задачи */
.task-add { display: flex; gap: 8px; margin: 10px 0 14px; }
.task-add input {
  flex: 1; border: none; border-radius: 12px; padding: 12px 14px; font-size: 16px;
  background: var(--card); color: var(--text); outline: none;
}
.task-add button {
  width: 46px; border: none; border-radius: 12px; background: var(--accent);
  color: var(--accent-text); font-size: 22px; cursor: pointer;
}
.task {
  display: flex; align-items: center; gap: 10px; background: var(--card);
  border-radius: 14px; padding: 12px; margin-bottom: 8px;
  border-left: 4px solid var(--hint); box-shadow: 0 1px 3px rgba(0,0,0,.05);
}
.task.done { opacity: .5; }
.task.done .t-title { text-decoration: line-through; }
.task .box {
  width: 24px; height: 24px; border-radius: 8px; border: 2px solid var(--hint);
  flex-shrink: 0; cursor: pointer; display: flex; align-items: center; justify-content: center;
  color: transparent; font-size: 15px; background: transparent;
}
.task.done .box { background: var(--shared); border-color: var(--shared); color: #fff; }
.task .t-mid { flex: 1; }
.task .t-sub { font-size: 12px; color: var(--hint); margin-top: 2px; }
.sphere-chips { margin-bottom: 12px; }
.sphere-chips .chip { font-size: 13px; padding: 6px 11px; }
.task .t-del { border: none; background: none; color: var(--hint); font-size: 17px; cursor: pointer; padding: 4px; }

/* Чипсы (фильтры и выборы) */
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 6px 0; }
.chip {
  border: 1.5px solid var(--line); background: var(--card); color: var(--text);
  border-radius: 999px; padding: 8px 14px; font-size: 14px; cursor: pointer;
}
.chip.on { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }

/* Нижнее меню */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; display: flex; align-items: center;
  justify-content: space-around; background: var(--card); padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line); max-width: 560px; margin: 0 auto;
}
.fab {
  width: 52px; height: 52px; border-radius: 50%; border: none; background: var(--accent);
  color: var(--accent-text); font-size: 26px; cursor: pointer; margin-top: -26px;
  box-shadow: 0 4px 12px rgba(0,0,0,.2);
}

/* Модальное окно */
.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,.45);
  display: flex; align-items: flex-end; justify-content: center; z-index: 50;
}
.sheet {
  background: var(--bg); width: 100%; max-width: 560px; border-radius: 18px 18px 0 0;
  padding: 16px 16px calc(20px + env(safe-area-inset-bottom)); max-height: 88vh; overflow-y: auto;
}
.sheet-head { display: flex; justify-content: space-between; align-items: center;
  font-size: 18px; font-weight: 700; margin-bottom: 12px; }
.close { border: none; background: none; font-size: 18px; color: var(--hint); cursor: pointer; padding: 6px; }
.sheet input[type=text] {
  width: 100%; border: none; border-radius: 12px; padding: 13px 14px; font-size: 16px;
  background: var(--card); color: var(--text); outline: none; margin-bottom: 10px;
}
.row2 { display: flex; gap: 10px; margin-bottom: 4px; }
.row2 label { flex: 1; font-size: 13px; color: var(--hint); display: flex; flex-direction: column; gap: 4px; }
.row2 input, .row2 select {
  border: none; border-radius: 12px; padding: 11px 12px; font-size: 16px;
  background: var(--card); color: var(--text); outline: none; width: 100%;
  -webkit-appearance: none; appearance: none;
}
.lbl { display: block; font-size: 13px; color: var(--hint); margin-top: 10px; }
.primary {
  width: 100%; border: none; border-radius: 14px; background: var(--accent);
  color: var(--accent-text); font-size: 17px; font-weight: 600; padding: 14px; margin-top: 14px; cursor: pointer;
}
.danger {
  width: 100%; border: none; border-radius: 14px; background: none;
  color: #d64545; font-size: 15px; padding: 12px; margin-top: 6px; cursor: pointer;
}

/* Карточка приглашения */
.invite-card {
  background: var(--card); border-radius: 16px; padding: 16px; margin-bottom: 14px;
  box-shadow: 0 1px 4px rgba(0,0,0,.06); border: 1.5px dashed var(--accent);
}
.inv-title { font-weight: 700; font-size: 16px; margin-bottom: 4px; }
.inv-sub { font-size: 14px; color: var(--hint); margin-bottom: 10px; }
.invite-card input[type=text] {
  width: 100%; border: none; border-radius: 12px; padding: 12px 14px; font-size: 16px;
  background: var(--bg); color: var(--text); outline: none; margin-bottom: 10px;
}
.invite-card .primary { margin-top: 0; margin-bottom: 8px; }
.invite-card .chip { margin-right: 8px; }

/* Всплывающее сообщение */
#toast {
  position: fixed; bottom: 96px; left: 50%; transform: translateX(-50%);
  background: rgba(30,30,35,.92); color: #fff; padding: 10px 18px; border-radius: 12px;
  font-size: 14px; z-index: 99; max-width: 90%; text-align: center;
}
