:root {
  --bg: var(--tg-theme-secondary-bg-color, #f1f2f6);
  --card: var(--tg-theme-section-bg-color, var(--tg-theme-bg-color, #ffffff));
  --text: var(--tg-theme-text-color, #111418);
  --hint: var(--tg-theme-hint-color, #8a9099);
  --sub: var(--tg-theme-subtitle-text-color, var(--tg-theme-hint-color, #6d737c));
  --link: var(--tg-theme-link-color, #2481cc);
  --accent: var(--tg-theme-button-color, #2481cc);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --danger: var(--tg-theme-destructive-text-color, #e5484d);
  --sep: color-mix(in srgb, var(--hint) 22%, transparent);
  --soft: color-mix(in srgb, var(--hint) 12%, transparent);

  --c-new: #2f80ed;
  --c-progress: #f2994a;
  --c-done: #27ae60;
  --c-failed: #e5484d;
  --c-cancelled: #9aa0a6;

  --r: 14px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
  :root:not(.tg) {
    --bg: #0f1115; --card: #1b1e24; --text: #eef0f3; --hint: #7d8590; --sub: #9aa2ad;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text); }
body {
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  min-height: 100vh;
  overscroll-behavior-y: none;
}
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; padding: 0; }
input, textarea { font: inherit; color: var(--text); }
a { color: var(--link); text-decoration: none; }

#app { padding: 12px 12px calc(96px + var(--safe-bottom)); max-width: 640px; margin: 0 auto; }

/* ---------- header ---------- */
.top { display: flex; align-items: center; gap: 10px; padding: 4px 4px 12px; }
.top h1 { font-size: 22px; line-height: 1.2; margin: 0; flex: 1; font-weight: 700; letter-spacing: -0.01em; }
.top .sub { color: var(--hint); font-size: 13px; font-weight: 400; margin-top: 2px; }
.icon-btn {
  width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center;
  background: var(--card); color: var(--accent); font-size: 22px; line-height: 1; flex: none;
}
.icon-btn.primary { background: var(--accent); color: var(--accent-text); }

/* ---------- stats ---------- */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 12px; }
.stats.three { grid-template-columns: repeat(3, 1fr); }
.stat {
  background: var(--card); border-radius: var(--r); padding: 10px 10px 9px; text-align: left;
  display: flex; flex-direction: column; gap: 2px; min-width: 0;
}
.stat b { font-size: 22px; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat span { font-size: 11.5px; line-height: 1.2; color: var(--hint); overflow-wrap: anywhere; }
.stat.active { outline: 2px solid var(--accent); outline-offset: -2px; }
.stat.warn b { color: var(--danger); }
.stat.good b { color: var(--c-done); }

/* ---------- chips ---------- */
.chips { display: flex; gap: 6px; overflow-x: auto; padding: 2px 2px 10px; margin: 0 -12px; padding-left: 14px; padding-right: 14px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; padding: 7px 12px; border-radius: 999px; background: var(--card); font-size: 14px;
  white-space: nowrap; color: var(--text);
}
.chip .n { color: var(--hint); margin-left: 4px; font-variant-numeric: tabular-nums; }
.chip.on { background: var(--accent); color: var(--accent-text); }
.chip.on .n { color: inherit; opacity: .75; }

.search {
  width: 100%; border: 0; outline: 0; background: var(--card); border-radius: 12px;
  padding: 10px 12px 10px 36px; margin-bottom: 10px; font-size: 15px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' stroke='%238a9099' stroke-width='2' stroke-linecap='round'%3E%3Ccircle cx='7' cy='7' r='5'/%3E%3Cpath d='m11 11 3.5 3.5'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: 12px center;
}
.search::placeholder { color: var(--hint); }

/* ---------- task list ---------- */
.list { display: flex; flex-direction: column; gap: 8px; }
.group-title { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--sub); margin: 14px 6px 6px; font-weight: 600; }
.task {
  position: relative; background: var(--card); border-radius: var(--r); padding: 12px 14px 11px 18px;
  text-align: left; width: 100%; display: block; overflow: hidden;
}
.task::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--status-c, var(--hint)); }
.task:active { opacity: .7; }
.task .t-title { font-weight: 600; font-size: 15.5px; line-height: 1.3; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.task .t-id { color: var(--hint); font-weight: 400; font-size: 13px; margin-right: 4px; }
.task .t-row { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; margin-top: 7px; font-size: 13px; color: var(--sub); }
.task .t-row .over { color: var(--danger); font-weight: 600; }
.task .t-row .soon { color: var(--c-progress); font-weight: 600; }
.task.closed .t-title { color: var(--sub); }

.pill {
  display: inline-flex; align-items: center; gap: 5px; padding: 2px 8px; border-radius: 999px; font-size: 12.5px; font-weight: 600;
  background: color-mix(in srgb, var(--status-c) 14%, transparent); color: var(--status-c);
}
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.s-new { --status-c: var(--c-new); }
.s-in_progress { --status-c: var(--c-progress); }
.s-done { --status-c: var(--c-done); }
.s-failed { --status-c: var(--c-failed); }
.s-cancelled { --status-c: var(--c-cancelled); }
.prio-high { color: var(--danger); font-weight: 600; }

.empty { text-align: center; color: var(--hint); padding: 40px 20px; }
.empty .big { font-size: 44px; margin-bottom: 8px; }
.empty b { display: block; color: var(--text); font-size: 17px; margin-bottom: 4px; }

/* ---------- team ---------- */
.person { display: flex; align-items: center; gap: 12px; background: var(--card); padding: 11px 14px; width: 100%; text-align: left; }
.person:first-child { border-radius: var(--r) var(--r) 0 0; }
.person:last-child { border-radius: 0 0 var(--r) var(--r); }
.person:only-child { border-radius: var(--r); }
.person + .person { border-top: 1px solid var(--sep); }
.persons { display: flex; flex-direction: column; }
.avatar {
  width: 42px; height: 42px; border-radius: 50%; flex: none; display: grid; place-items: center;
  color: #fff; font-weight: 600; font-size: 16px; background: var(--av, #6c8cd5);
}
.avatar.big { width: 72px; height: 72px; font-size: 28px; }
.person .p-main { flex: 1; min-width: 0; }
.person .p-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.person .p-meta { font-size: 13px; color: var(--hint); margin-top: 1px; }
.person .p-meta .over { color: var(--danger); }
.badge { min-width: 22px; height: 22px; padding: 0 7px; border-radius: 11px; background: var(--accent); color: var(--accent-text); font-size: 12.5px; font-weight: 600; display: grid; place-items: center; }
.badge.red { background: var(--danger); color: #fff; }
.chev { color: var(--hint); font-size: 20px; }

.profile { text-align: center; padding: 6px 0 16px; }
.profile .avatar { margin: 0 auto 8px; }
.profile h2 { margin: 0; font-size: 21px; }
.profile .sub { color: var(--hint); font-size: 14px; }

/* ---------- task detail ---------- */
.card { background: var(--card); border-radius: var(--r); padding: 14px; margin-bottom: 10px; }
.detail-title { font-size: 20px; font-weight: 700; line-height: 1.25; margin: 0 0 10px; word-break: break-word; }
.kv { display: grid; grid-template-columns: 22px 1fr; gap: 9px 8px; font-size: 14.5px; align-items: start; }
.kv .k { text-align: center; }
.kv .v small { color: var(--hint); display: block; font-size: 12.5px; }
.kv .over { color: var(--danger); font-weight: 600; }
.desc { white-space: pre-wrap; word-break: break-word; font-size: 15px; line-height: 1.45; }
.desc:empty::before { content: "Без описания"; color: var(--hint); }
.section-label { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--sub); margin: 16px 6px 6px; font-weight: 600; }
.note { margin-top: 10px; padding: 9px 11px; border-radius: 10px; background: var(--soft); font-size: 14px; }

.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 10px; }
.btn {
  display: flex; align-items: center; justify-content: center; gap: 6px; padding: 12px 10px; border-radius: 12px;
  background: var(--card); color: var(--accent); font-weight: 600; font-size: 15px; text-align: center;
}
.btn.full { grid-column: 1 / -1; }
.btn.primary { background: var(--accent); color: var(--accent-text); }
.btn.green { background: var(--c-done); color: #fff; }
.btn.danger { color: var(--danger); }
.btn.ghost { background: var(--soft); color: var(--text); }
.btn:disabled { opacity: .5; }
.btn:active { opacity: .75; }

.files-btn { display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; }
.files-btn .grow { flex: 1; }
.files-btn small { color: var(--hint); display: block; }

/* timeline */
.timeline { display: flex; flex-direction: column; gap: 8px; }
.ev { display: flex; gap: 10px; align-items: flex-start; font-size: 13.5px; color: var(--sub); padding: 0 6px; }
.ev .ico { width: 22px; text-align: center; flex: none; }
.ev .when { color: var(--hint); font-size: 12px; }
.ev b { color: var(--text); font-weight: 600; }
.bubble-row { display: flex; }
.bubble-row.mine { justify-content: flex-end; }
.bubble { max-width: 85%; background: var(--card); border-radius: 16px 16px 16px 4px; padding: 8px 12px 6px; }
.mine .bubble { background: color-mix(in srgb, var(--accent) 16%, var(--card)); border-radius: 16px 16px 4px 16px; }
.bubble .who { font-size: 12.5px; font-weight: 600; color: var(--accent); margin-bottom: 1px; }
.bubble .txt { white-space: pre-wrap; word-break: break-word; font-size: 15px; }
.bubble .when { font-size: 11.5px; color: var(--hint); text-align: right; margin-top: 2px; }

.composer {
  position: fixed; left: 0; right: 0; bottom: 0; padding: 8px 10px calc(8px + var(--safe-bottom));
  background: var(--card); border-top: 1px solid var(--sep); display: flex; gap: 8px; align-items: flex-end; z-index: 5;
}
.composer textarea {
  flex: 1; resize: none; border: 0; outline: 0; background: var(--bg); border-radius: 18px; padding: 9px 14px;
  max-height: 120px; min-height: 38px; line-height: 1.35;
}
.composer button { width: 38px; height: 38px; border-radius: 50%; background: var(--accent); color: var(--accent-text); display: grid; place-items: center; flex: none; }
.composer button:disabled { opacity: .4; }

/* ---------- form ---------- */
.field { background: var(--card); border-radius: var(--r); margin-bottom: 10px; overflow: hidden; }
.field input, .field textarea {
  width: 100%; border: 0; outline: 0; background: transparent; padding: 13px 14px; font-size: 16px; display: block;
}
.field textarea { min-height: 110px; resize: vertical; border-top: 1px solid var(--sep); line-height: 1.4; }
.field input::placeholder, .field textarea::placeholder { color: var(--hint); }
.label { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--sub); margin: 16px 6px 8px; font-weight: 600; }
.opts { display: flex; flex-wrap: wrap; gap: 6px; }
.opts .chip { padding: 9px 13px; }
.dt-input { width: 100%; margin-top: 8px; background: var(--card); border: 0; border-radius: 12px; padding: 11px 12px; font-size: 16px; outline: 0; color-scheme: light dark; }
.seg { display: grid; grid-template-columns: repeat(3, 1fr); background: var(--card); border-radius: 12px; padding: 3px; gap: 3px; }
.seg button { padding: 9px 4px; border-radius: 9px; font-size: 14.5px; }
.seg button.on { background: var(--accent); color: var(--accent-text); font-weight: 600; }
.hint-text { color: var(--hint); font-size: 13px; margin: 8px 6px 0; }

/* ---------- tab bar ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; display: flex; background: var(--card);
  border-top: 1px solid var(--sep); padding-bottom: var(--safe-bottom); z-index: 5;
}
.tabbar button { flex: 1; padding: 8px 0 7px; display: flex; flex-direction: column; align-items: center; gap: 1px; color: var(--hint); font-size: 11.5px; position: relative; }
.tabbar button .i { font-size: 21px; line-height: 1.1; filter: grayscale(1); opacity: .7; }
.tabbar button.on { color: var(--accent); font-weight: 600; }
.tabbar button.on .i { filter: none; opacity: 1; }
.tabbar .dot { position: absolute; top: 4px; left: calc(50% + 8px); min-width: 17px; height: 17px; border-radius: 9px; background: var(--danger); color: #fff; font-size: 11px; display: grid; place-items: center; padding: 0 4px; font-weight: 600; }

.fallback-main {
  position: fixed; left: 12px; right: 12px; bottom: calc(12px + var(--safe-bottom)); z-index: 6;
  padding: 14px; border-radius: 14px; background: var(--accent); color: var(--accent-text); font-weight: 600; font-size: 16px;
  box-shadow: 0 6px 20px color-mix(in srgb, var(--accent) 35%, transparent);
}

/* ---------- sheet ---------- */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 20; animation: fade .15s ease; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 21; background: var(--bg);
  border-radius: 18px 18px 0 0; padding: 8px 14px calc(16px + var(--safe-bottom)); max-height: 85vh; overflow: auto;
  animation: up .2s ease; max-width: 640px; margin: 0 auto;
}
.sheet .grab { width: 36px; height: 5px; border-radius: 3px; background: var(--sep); margin: 0 auto 10px; }
.sheet h3 { margin: 0 0 12px; font-size: 18px; text-align: center; }
.sheet textarea { width: 100%; min-height: 90px; border: 0; outline: 0; border-radius: 12px; background: var(--card); padding: 11px 12px; font-size: 16px; resize: vertical; margin-bottom: 10px; }
.sheet .actions { margin: 12px 0 0; }
@keyframes up { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes fade { from { opacity: 0; } }

.toast {
  position: fixed; left: 50%; top: 14px; transform: translateX(-50%); z-index: 30; max-width: 90vw;
  background: rgba(20,22,26,.92); color: #fff; padding: 10px 16px; border-radius: 12px; font-size: 14px;
  animation: fade .15s ease;
}

.loader { display: grid; place-items: center; height: 70vh; }
.spinner { width: 30px; height: 30px; border-radius: 50%; border: 3px solid var(--sep); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.demo-bar { font-size: 12.5px; color: var(--hint); text-align: center; margin: -4px 0 10px; }
.demo-bar a { margin: 0 4px; }
