/* ================= Тема Telegram + фолбэки ================= */
:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --secondary-bg: var(--tg-theme-secondary-bg-color, #f0f0f4);
  --text: var(--tg-theme-text-color, #000000);
  --hint: var(--tg-theme-hint-color, #8e8e93);
  --button: var(--tg-theme-button-color, #2481cc);
  --button-text: var(--tg-theme-button-text-color, #ffffff);
  --link: var(--tg-theme-link-color, #2481cc);

  --overdue: #E5484D;
  --sep: color-mix(in srgb, var(--hint) 20%, transparent);
  --radius-card: 12px;
  --radius-sheet: 16px;
  --pad: 16px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", Roboto, "Segoe UI", sans-serif;

  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --tabbar-h: 56px;
}

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

html, body {
  margin: 0;
  padding: 0;
  background: var(--secondary-bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.35;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

.hidden { display: none !important; }

button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input, select, textarea { font-family: inherit; font-size: 16px; color: var(--text); }

/* ================= Каркас ================= */
.app { min-height: 100vh; }

.screen {
  padding-bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 12px);
  min-height: 100vh;
}
#screen-project { padding-bottom: calc(96px + var(--safe-bottom)); }

.screen-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 14px var(--pad) 6px;
  position: sticky;
  top: 0;
  background: var(--secondary-bg);
  z-index: 5;
}
.screen-title { font-size: 22px; font-weight: 600; margin: 0; }
.project-title { display: flex; align-items: center; gap: 8px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.icon-btn {
  min-width: 44px; min-height: 44px;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px; border-radius: 10px;
}
.icon-btn:active { background: var(--sep); }

.list-wrap { padding: 0 var(--pad); }

/* ================= Фильтр Все/Мои ================= */
.filter-toggle {
  display: flex; gap: 4px;
  margin: 4px var(--pad) 12px;
  background: var(--sep);
  padding: 3px; border-radius: 10px;
  width: max-content;
}
.filter-btn {
  padding: 6px 16px; border-radius: 8px;
  font-size: 14px; font-weight: 500; color: var(--hint);
  min-height: 32px;
}
.filter-btn.active { background: var(--bg); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.08); }

.project-filter { margin-top: 0; }
.pf-btn { padding: 6px 16px; border-radius: 8px; font-size: 14px; font-weight: 500; color: var(--hint); min-height: 32px; }
.pf-btn.active { background: var(--bg); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.08); }
.sub-row .assignee { margin-left: auto; }
.sub-row .sub-del { margin-left: 4px; }

/* ================= Баннер цели ================= */
.goal-banner {
  display: flex; align-items: center; gap: 12px;
  margin: 4px 16px 12px;
  padding: 13px 15px;
  border-radius: 14px;
  background: color-mix(in srgb, var(--button) 13%, var(--bg));
  border: 1px solid color-mix(in srgb, var(--button) 22%, transparent);
  transition: transform .12s ease, opacity .12s ease;
}
.goal-banner:active { transform: scale(.99); opacity: .85; }
.goal-banner .goal-icon {
  font-size: 22px; flex-shrink: 0;
  width: 40px; height: 40px; border-radius: 11px;
  display: flex; align-items: center; justify-content: center;
  background: color-mix(in srgb, var(--button) 18%, var(--bg));
}
.goal-banner .goal-body { flex: 1; min-width: 0; }
.goal-banner .goal-label {
  font-size: 11px; font-weight: 700; letter-spacing: .07em; text-transform: uppercase;
  color: var(--button); margin-bottom: 2px;
}
.goal-banner .goal-text {
  font-size: 15px; font-weight: 600; line-height: 1.3; color: var(--text);
  white-space: pre-wrap; word-break: break-word;
}
.goal-banner.empty .goal-text { font-weight: 500; color: var(--hint); }
.goal-banner .goal-edit { color: var(--button); font-size: 16px; flex-shrink: 0; opacity: .7; }

/* ================= Группы (Сегодня) ================= */
.group-head {
  font-size: 13px; font-weight: 600; letter-spacing: .06em;
  text-transform: uppercase; color: var(--hint);
  padding: 18px 2px 8px;
}
.group-head.overdue { color: var(--overdue); }

.proj-group-head {
  display: flex; align-items: center; gap: 6px;
  font-size: 14px; font-weight: 500; color: var(--hint);
  padding: 10px 2px 4px;
}
.proj-group-head:active { opacity: .6; }

/* ================= Карточки проектов ================= */
.project-card {
  background: var(--bg);
  border-radius: var(--radius-card);
  padding: 14px 16px;
  margin-bottom: 10px;
  display: flex; align-items: center; gap: 12px;
  min-height: 60px;
  transition: transform .15s ease, box-shadow .15s ease;
}
.project-card .p-emoji { font-size: 24px; flex-shrink: 0; }
.project-card .p-body { flex: 1; min-width: 0; }
.project-card .p-title { font-size: 16px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.project-card .p-sub { font-size: 13px; color: var(--hint); margin-top: 2px; }
.project-card .p-sub .over { color: var(--overdue); }
.project-card .p-count {
  font-size: 16px; color: var(--hint); font-weight: 500;
  min-width: 22px; text-align: right;
}
.project-card .p-menu {
  min-width: 40px; min-height: 40px; margin: -8px -8px -8px 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px; color: var(--hint);
}

.archive-link {
  display: block; text-align: center; color: var(--link);
  padding: 16px; font-size: 15px;
}
.back-return { color: var(--link); font-size: 15px; }

/* ================= Строка задачи ================= */
.task-row {
  display: flex; align-items: center; gap: 10px;
  min-height: 48px;
  padding: 6px 2px;
  background: var(--bg);
  border-bottom: .5px solid var(--sep);
}
.task-list { background: var(--bg); border-radius: var(--radius-card); overflow: hidden; padding: 0 12px; }
.task-list .task-row:last-child { border-bottom: none; }

.checkbox {
  width: 22px; height: 22px; flex-shrink: 0;
  border: 2px solid var(--hint);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  position: relative;
  transition: background .15s ease, border-color .15s ease;
  margin: 0 8px 0 0;
}
.checkbox::after {
  content: ""; width: 11px; height: 6px;
  border-left: 2px solid var(--button-text);
  border-bottom: 2px solid var(--button-text);
  transform: rotate(-45deg) scale(0);
  transition: transform .15s ease;
  margin-top: -2px;
}
.task-row.done .checkbox { background: var(--button); border-color: var(--button); }
.task-row.done .checkbox::after { transform: rotate(-45deg) scale(1); }
/* увеличенная зона нажатия чекбокса */
.check-hit { padding: 11px; margin: -11px; display: flex; flex-shrink: 0; }

.task-main { flex: 1; min-width: 0; display: flex; align-items: center; gap: 6px; }
.task-title {
  font-size: 16px; font-weight: 400;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden;
}
.task-row.done .task-title { text-decoration: line-through; color: var(--hint); }
.note-mark { font-size: 12px; color: var(--hint); flex-shrink: 0; }

.assignee {
  width: 20px; height: 20px; border-radius: 50%; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 600; color: #fff;
  background-size: cover; background-position: center;
}
.assignee.empty { display: none; }

.deadline {
  width: 72px; text-align: right; flex-shrink: 0;
  font-size: 14px; color: var(--hint);
}
.deadline.overdue { color: var(--overdue); }
.deadline.today { color: var(--button); }
.deadline.future { color: var(--hint); }

.task-row.vanishing { opacity: 0; transform: translateX(8px); transition: opacity .3s ease, transform .3s ease; }

/* Блок «Выполнено» */
.done-toggle {
  display: flex; align-items: center; gap: 6px;
  color: var(--hint); font-size: 15px; font-weight: 500;
  padding: 16px 2px 8px;
}
.done-toggle .caret { transition: transform .15s ease; display: inline-block; }
.done-toggle.open .caret { transform: rotate(90deg); }

/* ================= Быстрый ввод ================= */
.quick-add-wrap {
  position: fixed; left: 0; right: 0; bottom: 0;
  padding: 8px var(--pad) calc(8px + var(--safe-bottom));
  background: var(--secondary-bg);
  border-top: .5px solid var(--sep);
}
.quick-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 6px; }
.quick-chips:empty { display: none; }
.quick-add {
  display: flex; align-items: center; gap: 4px;
  background: var(--bg); border-radius: var(--radius-card);
  padding: 4px 6px 4px 14px;
}
.quick-input { flex: 1; border: none; outline: none; background: none; padding: 10px 0; min-height: 44px; }
.quick-icon {
  min-width: 44px; min-height: 44px; font-size: 18px;
  display: flex; align-items: center; justify-content: center; border-radius: 10px;
}
.quick-icon.active { background: var(--sep); }
.quick-send {
  min-width: 40px; height: 40px; width: 40px; border-radius: 50%;
  background: var(--button); color: var(--button-text); font-size: 20px; font-weight: 700;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
  transition: transform .12s ease, opacity .12s ease;
}
.quick-send:active { transform: scale(.9); }
.quick-send:disabled { opacity: .35; }

/* Подзадачи */
.subtask-badge {
  display: inline-flex; align-items: center; gap: 3px;
  font-size: 12px; color: var(--hint); flex-shrink: 0;
  padding: 1px 7px; border-radius: 999px; background: var(--sep);
}
.subtask-badge.done { color: var(--button); }
.sub-list { margin: 4px 0 8px; }
.sub-row {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 0; min-height: 40px; border-bottom: .5px solid var(--sep);
}
.sub-row:last-child { border-bottom: none; }
.sub-row .checkbox { width: 20px; height: 20px; margin: 0; }
.sub-row.done .checkbox { background: var(--button); border-color: var(--button); }
.sub-row.done .checkbox::after { transform: rotate(-45deg) scale(1); }
.sub-title { flex: 1; min-width: 0; font-size: 15px; }
.sub-row.done .sub-title { text-decoration: line-through; color: var(--hint); }
.sub-del { color: var(--hint); font-size: 18px; min-width: 36px; min-height: 36px; display: flex; align-items: center; justify-content: center; }
.sub-add { display: flex; align-items: center; gap: 6px; margin-top: 6px; }
.sub-add input { flex: 1; background: var(--secondary-bg); border: none; border-radius: 10px; padding: 10px 12px; min-height: 40px; outline: none; }
.sub-add button { min-width: 40px; height: 40px; border-radius: 50%; background: var(--button); color: var(--button-text); font-size: 20px; font-weight: 700; }

/* Подзадачи прямо в списке задач проекта */
.task-block { border-bottom: .5px solid var(--sep); }
.task-block:last-child { border-bottom: none; }
.task-block .task-row { border-bottom: none; }
.subblock { padding: 0 0 8px 40px; }
.sub-row.inline { min-height: 34px; padding: 4px 0; border-bottom: none; }
.sub-row.inline .checkbox { width: 18px; height: 18px; }
.sub-row.inline .checkbox::after { width: 9px; height: 5px; }
.sub-row.inline .sub-title { font-size: 14px; }
.add-sub-btn {
  color: var(--hint); font-size: 13px; padding: 6px 2px;
  display: inline-flex; align-items: center; min-height: 32px;
}
.add-sub-btn:active { opacity: .6; }
.sub-add-inline .sub-add { margin-top: 2px; }
.sub-add-inline .sub-add input { min-height: 36px; padding: 8px 12px; font-size: 14px; }
.sub-add-inline .sub-add button { min-width: 36px; height: 36px; font-size: 18px; }

.chip {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 5px 12px; border-radius: 999px;
  font-size: 13px; background: var(--sep); color: var(--text);
  min-height: 30px;
}
.chip .chip-x { color: var(--hint); font-size: 15px; margin-left: 2px; }
.chip.selectable:active { opacity: .6; }
.chip.selected { background: var(--button); color: var(--button-text); }

/* ================= Мысли (лента) ================= */
#screen-thoughts { display: flex; flex-direction: column; }
.thoughts-feed {
  padding: 8px 16px 0;
  padding-bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 64px);
  display: flex; flex-direction: column; gap: 4px;
}
.thought-day {
  align-self: center; margin: 14px 0 8px;
  font-size: 12px; font-weight: 600; color: var(--hint);
  background: var(--sep); padding: 3px 12px; border-radius: 999px;
}
.thought {
  max-width: 82%; padding: 9px 13px; border-radius: 16px;
  background: var(--bg); position: relative;
  word-break: break-word; white-space: pre-wrap;
  font-size: 15px; line-height: 1.35;
}
.thought.mine { align-self: flex-end; background: var(--button); color: var(--button-text); border-bottom-right-radius: 5px; }
.thought.theirs { align-self: flex-start; border-bottom-left-radius: 5px; }
.thought .t-author { font-size: 12px; font-weight: 600; color: var(--link); margin-bottom: 2px; }
.thought .t-time { display: block; text-align: right; font-size: 11px; opacity: .6; margin-top: 3px; }
.thought.mine .t-time { color: var(--button-text); }
.thought.deleting { opacity: 0; transform: scale(.9); transition: opacity .2s, transform .2s; }

.thought-input-wrap {
  position: fixed; left: 0; right: 0;
  bottom: calc(var(--tabbar-h) + var(--safe-bottom));
  display: flex; align-items: center; gap: 6px;
  padding: 8px 16px;
  background: var(--secondary-bg);
  border-top: .5px solid var(--sep);
}
.thought-input {
  flex: 1; border: none; outline: none;
  background: var(--bg); border-radius: 20px;
  padding: 11px 16px; min-height: 44px;
}
.thoughts-empty { text-align: center; color: var(--hint); padding: 64px 24px; font-size: 16px; }

/* ================= Таб-бар ================= */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0;
  height: calc(var(--tabbar-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  display: flex;
  background: var(--bg);
  border-top: .5px solid var(--sep);
  z-index: 10;
}
.tab {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; font-size: 11px; color: var(--hint);
}
.tab .tab-ico { font-size: 20px; filter: grayscale(1); opacity: .6; }
.tab.active { color: var(--button); }
.tab.active .tab-ico { filter: none; opacity: 1; }

/* ================= Пустые состояния ================= */
.empty {
  text-align: center; color: var(--hint);
  padding: 64px 24px; font-size: 16px;
}

/* ================= Шторки ================= */
.backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.4);
  opacity: 0; transition: opacity .2s ease; z-index: 50;
}
.backdrop.show { opacity: 1; }

.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 51;
  background: var(--bg);
  border-radius: var(--radius-sheet) var(--radius-sheet) 0 0;
  padding: 8px var(--pad) calc(20px + var(--safe-bottom));
  max-height: 92vh; overflow-y: auto;
  transform: translateY(100%); transition: transform .25s ease;
}
.sheet.show { transform: translateY(0); }
.sheet-grabber { width: 36px; height: 4px; border-radius: 2px; background: var(--sep); margin: 6px auto 14px; }

.sheet h2 { font-size: 18px; font-weight: 600; margin: 0 0 12px; }
.sheet-label { font-size: 13px; font-weight: 600; color: var(--hint); text-transform: uppercase; letter-spacing: .04em; margin: 16px 0 8px; }

.field {
  width: 100%; background: var(--secondary-bg); border: none; border-radius: 10px;
  padding: 12px 14px; outline: none; resize: none;
}
textarea.field { min-height: 44px; line-height: 1.4; }
.title-field { font-size: 18px; font-weight: 500; padding: 8px 0; background: none; }

.chip-row { display: flex; flex-wrap: wrap; gap: 8px; }

.emoji-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; margin: 8px 0; }
.emoji-cell {
  aspect-ratio: 1; display: flex; align-items: center; justify-content: center;
  font-size: 24px; border-radius: 10px; background: var(--secondary-bg);
}
.emoji-cell.selected { outline: 2px solid var(--button); }

.menu-item {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 4px; font-size: 16px; min-height: 48px;
  border-bottom: .5px solid var(--sep);
}
.menu-item:last-child { border-bottom: none; }
.menu-item.danger { color: var(--overdue); }
.menu-item .m-check { margin-left: auto; color: var(--button); }

.wide-btn {
  display: block; width: 100%;
  background: var(--button); color: var(--button-text);
  border-radius: var(--radius-card); padding: 14px; font-size: 16px; font-weight: 500;
  min-height: 48px; margin-top: 12px;
}
.wide-btn.secondary { background: var(--secondary-bg); color: var(--text); }
.danger-text { color: var(--overdue); text-align: center; padding: 14px; font-size: 16px; }

.sheet .row {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 12px 0; min-height: 44px;
}
.settings-card {
  background: var(--bg); border-radius: var(--radius-card);
  padding: 4px 16px; margin: 8px 0;
}
.settings-card .row { border-bottom: .5px solid var(--sep); }
.settings-card .row:last-child { border-bottom: none; }
.time-input, .select { background: var(--secondary-bg); border: none; border-radius: 8px; padding: 8px 10px; min-height: 36px; }
.select { max-width: 60%; }

.switch { appearance: none; width: 50px; height: 30px; border-radius: 999px; background: var(--sep); position: relative; transition: background .2s; flex-shrink: 0; }
.switch:checked { background: var(--button); }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; transition: transform .2s; }
.switch:checked::after { transform: translateX(20px); }

.proj-select { width: 100%; background: var(--secondary-bg); border: none; border-radius: 10px; padding: 12px 14px; min-height: 44px; }

/* ================= Тосты ================= */
#toast-root { position: fixed; left: 0; right: 0; bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 16px); z-index: 100; display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; }
.toast {
  background: rgba(0,0,0,.85); color: #fff; padding: 10px 18px; border-radius: 999px;
  font-size: 14px; max-width: 80%; text-align: center;
  opacity: 0; transform: translateY(8px); transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: translateY(0); }

/* ================= Sortable ================= */
.sortable-ghost { opacity: .3; }
.sortable-chosen { box-shadow: 0 6px 20px rgba(0,0,0,.18); transform: scale(1.02); }
.sortable-drag { opacity: .95; }

/* ================= Нет доступа ================= */
.denied { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 24px; gap: 8px; }
.denied-emoji { font-size: 56px; }
.denied-title { font-size: 22px; font-weight: 600; }
.denied-text { color: var(--hint); max-width: 280px; }
.denied-id { color: var(--hint); font-size: 13px; margin-top: 8px; }
