:root {
  --fb-bg: #ffffff; --fb-bg2: #f2f4f7; --fb-text: #14181f; --fb-hint: #7a8494; --fb-accent: #2f7cf6;
  --bg: var(--tg-theme-bg-color, var(--fb-bg));
  --bg2: var(--tg-theme-secondary-bg-color, var(--fb-bg2));
  --text: var(--tg-theme-text-color, var(--fb-text));
  --hint: var(--tg-theme-hint-color, var(--fb-hint));
  --accent: var(--tg-theme-button-color, var(--fb-accent));
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --link: var(--tg-theme-link-color, var(--fb-accent));
  --line: color-mix(in srgb, var(--hint) 22%, transparent);
  --danger: #d93a3a;
  --ok: #1f9d63;
  --s-new: #8a97ad;
  --s-in_progress: #2f7cf6;
  --s-review: #e8a317;
  --s-done: #1f9d63;
  --s-blocked: #8b7fd4;
  --s-cancelled: #9aa3b2;
  --radius: 12px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root { --fb-bg: #1c2431; --fb-bg2: #121821; --fb-text: #e8ecf2; --fb-hint: #8b96a8; --fb-accent: #4c93ff; }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg2);
  color: var(--text);
  font: 15px/1.4 -apple-system, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--link); }

#app { min-height: 100%; display: flex; flex-direction: column; }

/* ---------- шапка и вкладки ---------- */
.top {
  position: sticky; top: 0; z-index: 20;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
  padding: 10px 16px 0;
}
.top-row { display: flex; align-items: center; gap: 10px; }
.title { font-size: 17px; font-weight: 650; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.title select { font-weight: 650; font-size: 17px; background: transparent; border: 0; max-width: 100%; padding: 0; }
.tabs { display: flex; gap: 4px; margin-top: 8px; }
.tab {
  flex: 1; text-align: center; padding: 9px 0 10px; border: 0; background: none;
  color: var(--hint); font-weight: 600; border-bottom: 2px solid transparent; cursor: pointer;
}
.tab.on { color: var(--text); border-bottom-color: var(--accent); }

.content { padding: 12px 16px 96px; flex: 1; }

/* ---------- фильтры ---------- */
.search {
  width: 100%; border: 0; background: var(--bg); border-radius: var(--radius);
  padding: 11px 14px; margin-bottom: 10px; outline: none;
}
.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 10px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; border: 0; background: var(--bg); color: var(--text);
  padding: 7px 13px; border-radius: 999px; font-size: 14px; cursor: pointer;
}
.chip.on { background: var(--accent); color: var(--accent-text); }
.person {
  background: var(--bg); border: 0; border-radius: 999px; padding: 7px 12px; font-size: 14px; max-width: 46%;
}

/* ---------- список ---------- */
.list { background: var(--bg); border-radius: var(--radius); overflow: hidden; }
.row {
  display: flex; gap: 12px; padding: 12px 14px; border-bottom: 1px solid var(--line); cursor: pointer;
  align-items: flex-start;
}
.row:last-child { border-bottom: 0; }
.row:active { background: var(--bg2); }
.row.sub { padding-left: 34px; position: relative; }
.row.sub::before { content: "↳"; position: absolute; left: 15px; top: 12px; color: var(--hint); }
.dot { width: 10px; height: 10px; border-radius: 50%; margin-top: 6px; flex: none; background: var(--s-new); }
.row-main { min-width: 0; flex: 1; }
.row-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.row-meta { color: var(--hint); font-size: 13px; margin-top: 2px; }
.row-meta .late { color: var(--danger); font-weight: 600; }
.badge {
  display: inline-block; font-size: 12px; padding: 1px 8px; border-radius: 999px;
  background: var(--bg2); color: var(--hint); margin-left: 6px; vertical-align: 1px;
}
.badge.urgent { background: color-mix(in srgb, var(--danger) 16%, transparent); color: var(--danger); }
.badge.high { background: color-mix(in srgb, #e8a317 20%, transparent); color: #b87a00; }
.empty { text-align: center; color: var(--hint); padding: 48px 16px; }

/* ---------- кнопки ---------- */
.btn {
  border: 0; border-radius: var(--radius); padding: 12px 16px; font-weight: 600; cursor: pointer;
  background: var(--accent); color: var(--accent-text);
}
.btn.ghost { background: var(--bg); color: var(--text); }
.btn.warn { background: var(--bg); color: var(--danger); }
.btn:disabled { opacity: .5; }
.btn.small { padding: 8px 12px; font-size: 14px; }
.fab {
  position: fixed; right: 16px; bottom: calc(18px + env(safe-area-inset-bottom));
  width: 56px; height: 56px; border-radius: 50%; border: 0; z-index: 30;
  background: var(--accent); color: var(--accent-text); font-size: 30px; line-height: 1;
  box-shadow: 0 6px 18px rgba(0,0,0,.22); cursor: pointer;
}
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 12px 0; }
.actions .full { grid-column: 1 / -1; }

/* ---------- карточка ---------- */
.card { background: var(--bg); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 12px; }
.card h1 { font-size: 20px; margin: 0 0 6px; line-height: 1.25; }
.status-pill {
  display: inline-flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 600;
  padding: 3px 10px; border-radius: 999px; color: #fff; background: var(--s-new);
}
.kv { display: grid; grid-template-columns: 104px 1fr; gap: 6px 10px; margin-top: 12px; font-size: 14px; }
.kv dt { color: var(--hint); }
.kv dd { margin: 0; word-break: break-word; }
.late { color: var(--danger); font-weight: 600; }
.h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--hint); margin: 18px 4px 8px; }
.assignee { display: inline-flex; gap: 6px; align-items: center; background: var(--bg2); border-radius: 999px; padding: 3px 10px; margin: 2px 4px 2px 0; font-size: 13px; }
.note { color: var(--hint); font-size: 13px; margin: 8px 2px; }
.log { font-size: 14px; }
.log div { padding: 6px 0; border-bottom: 1px solid var(--line); }
.log div:last-child { border-bottom: 0; }
.log small { color: var(--hint); display: block; }

/* ---------- форма ---------- */
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; color: var(--hint); margin: 0 4px 6px; }
.input, .field select, .field textarea {
  width: 100%; background: var(--bg); border: 1px solid transparent; border-radius: var(--radius);
  padding: 11px 13px; outline: none;
}
.input:focus, .field select:focus, .field textarea:focus { border-color: var(--accent); }
.field textarea { min-height: 84px; resize: vertical; }
.two { display: grid; grid-template-columns: 1.4fr 1fr; gap: 8px; }
.pick { background: var(--bg); border-radius: var(--radius); overflow: hidden; }
.pick label {
  display: flex; align-items: center; gap: 10px; padding: 11px 13px; margin: 0;
  border-bottom: 1px solid var(--line); color: var(--text); font-size: 15px;
}
.pick label:last-child { border-bottom: 0; }
.pick input { width: 18px; height: 18px; accent-color: var(--accent); }
.pick small { color: var(--hint); margin-left: auto; }
.seg { display: flex; background: var(--bg); border-radius: var(--radius); padding: 3px; gap: 3px; }
.seg button { flex: 1; border: 0; background: none; padding: 9px 0; border-radius: 9px; cursor: pointer; font-weight: 600; color: var(--hint); }
.seg button.on { background: var(--accent); color: var(--accent-text); }
details.fold { background: var(--bg); border-radius: var(--radius); margin-bottom: 14px; }
details.fold summary { padding: 12px 14px; cursor: pointer; font-weight: 600; }
details.fold .pick { border-radius: 0 0 var(--radius) var(--radius); background: transparent; }
.savebar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
  background: var(--bg); border-top: 1px solid var(--line); display: flex; gap: 8px;
}
.savebar .btn { flex: 1; }

/* ---------- диалоги и уведомления ---------- */
.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 50; display: flex; align-items: flex-end; }
.modal { width: 100%; background: var(--bg); border-radius: 18px 18px 0 0; padding: 16px 16px calc(16px + env(safe-area-inset-bottom)); }
.modal h3 { margin: 0 0 10px; font-size: 17px; }
.modal textarea { width: 100%; min-height: 92px; border-radius: var(--radius); border: 1px solid var(--line); background: var(--bg2); padding: 10px 12px; outline: none; }
.modal .actions { margin-bottom: 0; }
.toast {
  position: fixed; left: 16px; right: 16px; top: 12px; z-index: 60; padding: 12px 14px; border-radius: var(--radius);
  background: #1d2430; color: #fff; font-size: 14px; box-shadow: 0 8px 24px rgba(0,0,0,.28);
}
.toast.err { background: var(--danger); }

/* ---------- диаграмма Ганта ---------- */
.gtools { display: flex; gap: 8px; align-items: center; margin-bottom: 10px; }
.gtools .person { max-width: 42%; min-width: 0; }
.zoom { width: 36px; height: 36px; padding: 0; text-align: center; font-size: 18px; line-height: 1; }
.gtools .grow { flex: 1; }
.gwrap { background: var(--bg); border-radius: var(--radius); overflow: auto; max-height: calc(100vh - 190px); position: relative; }
.ginner { display: flex; min-width: max-content; }
.glabels { position: sticky; left: 0; z-index: 5; background: var(--bg); border-right: 1px solid var(--line); width: 148px; flex: none; }
.glabel { height: 34px; padding: 0 10px; display: flex; align-items: center; font-size: 13px; border-bottom: 1px solid var(--line); overflow: hidden; white-space: nowrap; text-overflow: ellipsis; cursor: pointer; }
.glabel.head { height: 44px; color: var(--hint); font-size: 12px; position: sticky; top: 0; background: var(--bg); z-index: 6; }
.glabel.sub { padding-left: 22px; color: var(--hint); }
.gchart { position: relative; }
.glegend { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 10px; font-size: 12px; color: var(--hint); }
.glegend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }
