/* Цвета берутся из темы Telegram, с запасными значениями для обычного браузера */
:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --bg2: var(--tg-theme-secondary-bg-color, #f1f1f4);
  --text: var(--tg-theme-text-color, #111111);
  --hint: var(--tg-theme-hint-color, #8a8a8e);
  --link: var(--tg-theme-link-color, #2a7de1);
  --btn: var(--tg-theme-button-color, #2a7de1);
  --btn-text: var(--tg-theme-button-text-color, #ffffff);
  --danger: var(--tg-theme-destructive-text-color, #e53935);
  --sep: color-mix(in srgb, var(--hint) 25%, transparent);
  --radius: 12px;
}
@media (prefers-color-scheme: dark) {
  :root:not(.tg) {
    --bg: #17181c; --bg2: #0f1013; --text: #f2f2f4; --hint: #8d8e93;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg2); color: var(--text); }
body {
  font: 16px/1.35 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  padding: 12px 16px calc(24px + env(safe-area-inset-bottom));
  max-width: 640px; margin: 0 auto;
}
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
.hidden { display: none !important; }

.h { font-size: 22px; font-weight: 700; margin: 8px 4px 12px; word-break: break-word; }
.editable { cursor: text; }
.hint { color: var(--hint); text-align: center; margin: 24px 8px; }

.status {
  position: fixed; top: 0; left: 0; right: 0; z-index: 10;
  background: var(--hint); color: #fff; text-align: center; font-size: 13px; padding: 4px;
}

/* Поле добавления */
.add { display: flex; gap: 8px; margin: 0 0 12px; }
.add.sticky { position: sticky; top: 0; z-index: 2; padding-top: 4px; background: var(--bg2); }
.add input {
  flex: 1; min-width: 0; font: inherit; color: var(--text); background: var(--bg);
  border: 1px solid var(--sep); border-radius: var(--radius); padding: 12px 14px; outline: none;
}
.add input:focus { border-color: var(--btn); }
.add button {
  width: 48px; border-radius: var(--radius); background: var(--btn); color: var(--btn-text);
  font-size: 24px; line-height: 1;
}

/* Списки на главной */
.lists, .items { list-style: none; margin: 0; padding: 0; background: var(--bg); border-radius: var(--radius); overflow: hidden; }
.lists:empty, .items:empty { display: none; }
.lists li { display: flex; align-items: center; gap: 12px; padding: 14px 16px; cursor: pointer; }
.lists li + li, .items li + li { border-top: 1px solid var(--sep); }
.lists .title { flex: 1; font-weight: 500; }
.lists .meta { color: var(--hint); font-size: 14px; white-space: nowrap; }
.lists li:active { background: var(--bg2); }
#lists { margin-bottom: 16px; }

.list-head { margin-bottom: 4px; }
.members { color: var(--hint); font-size: 13px; margin: -8px 4px 12px; }

/* Пункты списка */
.items li { display: flex; align-items: center; gap: 12px; padding: 4px 8px 4px 14px; min-height: 52px; }
.items li.pending { opacity: .5; }
.items li.flash { animation: flash .8s ease-out; }
@keyframes flash { from { background: color-mix(in srgb, var(--btn) 18%, transparent); } }

.check {
  appearance: none; flex: none; width: 24px; height: 24px; margin: 0; cursor: pointer;
  border: 2px solid var(--hint); border-radius: 50%; display: grid; place-content: center;
  transition: background .15s, border-color .15s;
}
.check:checked { background: var(--btn); border-color: var(--btn); }
.check:checked::after { content: ""; width: 6px; height: 11px; border: solid var(--btn-text); border-width: 0 2px 2px 0; transform: translateY(-1px) rotate(45deg); }

.items .text { flex: 1; min-width: 0; padding: 12px 0; word-break: break-word; cursor: text; }
.items .by { color: var(--hint); font-size: 12px; display: block; margin-top: 2px; }
.items .edit {
  flex: 1; min-width: 0; font: inherit; color: var(--text); background: var(--bg2);
  border: 0; border-radius: 8px; padding: 10px; outline: none;
}
.items .del { flex: none; width: 40px; height: 40px; color: var(--danger); font-size: 20px; }
#done .text { color: var(--hint); }
#done .name { text-decoration: line-through; }

.done-head { display: flex; justify-content: space-between; align-items: center; margin: 20px 4px 8px; color: var(--hint); font-size: 14px; }

.link { color: var(--link); padding: 6px 4px; }
.danger { color: var(--danger); }
.btn { width: 100%; padding: 14px; border-radius: var(--radius); background: var(--btn); color: var(--btn-text); font-weight: 600; }
.footer-actions { display: flex; flex-direction: column; align-items: center; gap: 12px; margin-top: 28px; }

/* Количество */
.qty { flex: none; display: flex; align-items: center; gap: 2px; }
.qty button {
  width: 34px; height: 34px; border-radius: 50%; font-size: 20px; line-height: 1;
  color: var(--btn); background: color-mix(in srgb, var(--btn) 12%, transparent);
  touch-action: manipulation; /* без задержки и зума при быстрых нажатиях */
}
.qty button:disabled { opacity: .35; cursor: default; }
.qty button:not(:disabled):active { background: color-mix(in srgb, var(--btn) 25%, transparent); }
.qty .qty-val {
  width: auto; min-width: 38px; padding: 0 4px; border-radius: 8px; background: none;
  color: var(--text); font-size: 16px; font-weight: 600; font-variant-numeric: tabular-nums;
}
.qty .qty-input {
  width: 56px; height: 34px; font: inherit; font-weight: 600; text-align: center;
  color: var(--text); background: var(--bg2); border: 1px solid var(--btn); border-radius: 8px; outline: none;
}
.qty-tag { font-variant-numeric: tabular-nums; }
