:root {
  --bg: var(--tg-theme-bg-color, #17212b);
  --card: var(--tg-theme-secondary-bg-color, #232e3c);
  --text: var(--tg-theme-text-color, #f5f5f5);
  --muted: var(--tg-theme-hint-color, #8b9aa8);
  --accent: var(--tg-theme-button-color, #3390ec);
  --accent-text: var(--tg-theme-button-text-color, #fff);
  --danger: #e5484d;
  --danger-soft: rgba(229, 72, 77, .14);
  --done: #3fb950;
  --line: rgba(140, 155, 170, .18);
  --radius: 14px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

/* Атрибут hidden обязан побеждать любой display из правил ниже.
   Без !important `.sheet { display: flex }` перекрывает браузерное
   `[hidden] { display: none }` — шторки залипают открытыми поверх списка. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 -apple-system, "SF Pro Text", system-ui, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior-y: none;
}

.boot {
  display: grid;
  place-items: center;
  height: 100vh;
  color: var(--muted);
}

.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
}

/* ---------- шапка ---------- */

.head {
  padding: calc(12px + var(--safe-top)) 16px 0;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
  flex: none;
}

.head-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.head-title {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -.3px;
}

.head-sub {
  color: var(--muted);
  font-size: 13px;
  margin-top: 2px;
  min-height: 18px;
}

.icon-btn {
  border: 0;
  background: var(--card);
  color: var(--text);
  width: 36px;
  height: 36px;
  border-radius: 50%;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  flex: none;
}

.icon-btn:active { opacity: .6; }

/* ---------- полоска дней ---------- */

.strip {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 12px 0;
  scrollbar-width: none;
  scroll-snap-type: x proximity;
}

.strip::-webkit-scrollbar { display: none; }

.day {
  flex: none;
  width: 48px;
  padding: 7px 0 6px;
  border-radius: 12px;
  background: var(--card);
  text-align: center;
  cursor: pointer;
  border: 1.5px solid transparent;
  scroll-snap-align: center;
  transition: background .12s, border-color .12s;
}

.day-wd { font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }
.day-num { font-size: 17px; font-weight: 600; margin-top: 1px; }

.day-dots {
  display: flex;
  gap: 3px;
  justify-content: center;
  height: 5px;
  margin-top: 3px;
}

.dot { width: 4px; height: 4px; border-radius: 50%; background: var(--muted); }
.dot.is-overdue { background: var(--danger); }
.dot.is-clear { background: var(--done); }

.day.is-today { border-color: var(--accent); }
.day.is-active { background: var(--accent); }
.day.is-active .day-wd, .day.is-active .day-num { color: var(--accent-text); }
.day.is-past .day-num { opacity: .5; }

/* ---------- список ---------- */

.list {
  flex: 1;
  overflow-y: auto;
  padding: 8px 16px 24px;
  -webkit-overflow-scrolling: touch;
}

.group-head {
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .6px;
  margin: 18px 0 8px;
}

.group-head:first-child { margin-top: 6px; }
.group-head.is-danger { color: var(--danger); }

.item {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  background: var(--card);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 8px;
  border-left: 3px solid transparent;
  cursor: pointer;
  transition: opacity .15s, transform .1s;
}

.item:active { transform: scale(.985); }
.item.is-overdue { border-left-color: var(--danger); background: var(--danger-soft); }
.item.is-done { opacity: .45; }

.box {
  flex: none;
  width: 22px;
  height: 22px;
  margin-top: 1px;
  border-radius: 7px;
  border: 2px solid var(--muted);
  display: grid;
  place-items: center;
  font-size: 13px;
  color: transparent;
  transition: background .12s, border-color .12s, color .12s;
}

.item.is-overdue .box { border-color: var(--danger); }
.item.is-done .box { background: var(--done); border-color: var(--done); color: #fff; }

.item-body { min-width: 0; flex: 1; }

.item-title { font-size: 15px; word-wrap: break-word; }
.item.is-done .item-title { text-decoration: line-through; }

.item-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 5px;
}

.chip {
  font-size: 11px;
  padding: 2px 7px;
  border-radius: 6px;
  background: rgba(140, 155, 170, .18);
  color: var(--muted);
  white-space: nowrap;
}

.chip.is-danger { background: var(--danger); color: #fff; }
.chip.is-accent { background: rgba(51, 144, 236, .2); color: var(--accent); }

.empty {
  text-align: center;
  color: var(--muted);
  padding: 56px 20px;
  font-size: 15px;
}

.empty-emoji { font-size: 40px; display: block; margin-bottom: 10px; }

/* ---------- вкладки ---------- */

.tabs {
  display: flex;
  flex: none;
  border-top: 1px solid var(--line);
  background: var(--bg);
  padding-bottom: var(--safe-bottom);
}

.tab {
  flex: 1;
  border: 0;
  background: none;
  color: var(--muted);
  padding: 11px 4px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  position: relative;
}

.tab.is-active { color: var(--accent); }

.tab-badge {
  display: inline-grid;
  place-items: center;
  min-width: 17px;
  height: 17px;
  padding: 0 4px;
  border-radius: 9px;
  background: var(--danger);
  color: #fff;
  font-size: 10px;
  margin-left: 3px;
  vertical-align: 1px;
}

/* ---------- шторки ---------- */

.sheet {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .5);
  display: flex;
  align-items: flex-end;
  z-index: 50;
}

.sheet-body {
  width: 100%;
  max-height: 92vh;
  overflow-y: auto;
  background: var(--bg);
  border-radius: 18px 18px 0 0;
  padding: 18px 16px calc(18px + var(--safe-bottom));
  animation: rise .22s ease;
}

@keyframes rise { from { transform: translateY(100%); } }

.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.sheet-head h2 { margin: 0; font-size: 18px; font-weight: 700; }

.hint { color: var(--muted); font-size: 13px; margin: 0 0 12px; }
.hint code { background: var(--card); padding: 1px 5px; border-radius: 4px; font-size: 12px; }

textarea, input[type=text], input[type=time] {
  width: 100%;
  background: var(--card);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 12px;
  padding: 12px;
  font: inherit;
  font-size: 15px;
  resize: vertical;
}

textarea { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; }
input:focus, textarea:focus { outline: none; border-color: var(--accent); }

.row-2 { display: flex; gap: 8px; margin-top: 8px; }
.row-2 input { flex: 1; }

.check {
  display: flex;
  gap: 9px;
  align-items: flex-start;
  margin: 12px 0 0;
  font-size: 13px;
  color: var(--muted);
}

.check input { margin-top: 2px; accent-color: var(--accent); }

.sheet-actions { display: flex; gap: 8px; margin-top: 16px; }

.btn {
  flex: 1;
  border: 0;
  border-radius: 12px;
  padding: 13px;
  font: inherit;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}

.btn:active { opacity: .7; }
.btn-primary { background: var(--accent); color: var(--accent-text); }
.btn-ghost { background: var(--card); color: var(--text); }
.btn-danger { background: var(--danger-soft); color: var(--danger); }

.move-row { display: flex; gap: 8px; margin-top: 14px; }
.move-row .btn { font-size: 13px; padding: 10px 6px; }

.task-meta { display: flex; flex-wrap: wrap; gap: 6px; }
.task-notes { color: var(--muted); font-size: 14px; margin-top: 10px; white-space: pre-wrap; }

.preview { margin-top: 14px; border-top: 1px solid var(--line); padding-top: 14px; }
.preview-day { font-size: 13px; font-weight: 600; color: var(--muted); margin: 12px 0 6px; }
.preview-item { font-size: 14px; padding: 6px 10px; background: var(--card); border-radius: 8px; margin-bottom: 5px; }
