:root {
  --bg: var(--tg-theme-bg-color, #f6f7fb);
  --surface: var(--tg-theme-secondary-bg-color, #ffffff);
  --fg: var(--tg-theme-text-color, #16181d);
  --hint: var(--tg-theme-hint-color, #8b90a0);
  --accent: var(--tg-theme-button-color, #4f7df9);
  --accent-fg: var(--tg-theme-button-text-color, #ffffff);
  --line: color-mix(in srgb, var(--hint) 22%, transparent);
  --red: #ff5a5f;
  --green: #34c77b;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.05), 0 6px 20px rgba(0, 0, 0, 0.06);
}

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

html, body { height: 100%; }

body {
  margin: 0;
  font-family: -apple-system, "SF Pro Text", system-ui, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  background: var(--bg);
  color: var(--fg);
}

button { font: inherit; color: inherit; cursor: pointer; }

.hidden { display: none !important; }

/* ---------- header / tabs ---------- */

header {
  position: sticky;
  top: 0;
  z-index: 5;
  padding: calc(10px + env(safe-area-inset-top)) 12px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

#tabs {
  display: flex;
  gap: 4px;
  padding: 4px;
  background: color-mix(in srgb, var(--hint) 14%, transparent);
  border-radius: 12px;
}

.tab {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 4px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--hint);
  font-size: 13.5px;
  font-weight: 600;
  letter-spacing: -0.01em;
  transition: background 0.18s, color 0.18s, box-shadow 0.18s;
}

.tab.active {
  background: var(--surface);
  color: var(--fg);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.tab-count {
  min-width: 19px;
  padding: 0 5px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--hint) 18%, transparent);
  font-size: 11.5px;
  font-variant-numeric: tabular-nums;
  line-height: 19px;
  text-align: center;
}

.tab.active .tab-count { background: var(--accent); color: var(--accent-fg); }

/* ---------- branch bar ---------- */

#branches {
  display: flex;
  gap: 6px;
  margin-top: 8px;
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}

#branches::-webkit-scrollbar { display: none; }

.bchip {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--hint);
  font-size: 12.5px;
  font-weight: 600;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.bchip.active { background: var(--fg); border-color: var(--fg); color: var(--bg); }

.bchip-new { border-style: dashed; background: transparent; }

.b-dot {
  flex: none;
  width: 7px;
  height: 7px;
  border-radius: 50%;
}

/* ---------- branch tag on card ---------- */

.card-branch {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  margin-bottom: 4px;
  font-size: 11.5px;
  font-weight: 650;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--hint);
}

/* ---------- cards ---------- */

main {
  padding: 6px 12px calc(96px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.card {
  position: relative;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 13px 14px 12px 17px;
  box-shadow: var(--shadow);
  overflow: hidden;
  animation: rise 0.22s ease both;
}

@keyframes rise {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

.card::before {
  content: "";
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 4px;
  background: transparent;
}

.card.prio-high::before { background: var(--red); }
.card.prio-normal::before { background: color-mix(in srgb, var(--accent) 55%, transparent); }
.card.prio-low::before { background: color-mix(in srgb, var(--hint) 40%, transparent); }

.card:active { transform: scale(0.985); }

.card-title {
  font-weight: 650;
  font-size: 15.5px;
  letter-spacing: -0.01em;
  overflow-wrap: anywhere;
}

.card.is-done .card-title {
  color: var(--hint);
  text-decoration: line-through;
  text-decoration-color: color-mix(in srgb, var(--hint) 55%, transparent);
}

.card-desc {
  margin-top: 3px;
  color: var(--hint);
  font-size: 13.5px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-foot {
  margin-top: 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.assignee {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 13px;
  font-weight: 550;
  min-width: 0;
}

.assignee .asg-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.assignee.nobody { color: var(--hint); font-weight: 450; }

.avatar {
  flex: none;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: color-mix(in srgb, var(--accent) 82%, #000 6%);
  color: var(--accent-fg);
  font-size: 11.5px;
  font-weight: 700;
  line-height: 22px;
  text-align: center;
}

.avatar-stack { display: inline-flex; }

.avatar-stack .avatar + .avatar {
  margin-left: -7px;
  box-shadow: 0 0 0 2px var(--surface);
}

/* ---------- status track (signature) ---------- */

.track { display: inline-flex; align-items: center; flex: none; }

.track-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: color-mix(in srgb, var(--hint) 30%, transparent);
}

.track-dot.past { background: color-mix(in srgb, var(--accent) 60%, transparent); }
.track-dot.now { background: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent); }
.track-dot.now.done { background: var(--green); box-shadow: 0 0 0 3px color-mix(in srgb, var(--green) 22%, transparent); }
.track-dot.past.done { background: color-mix(in srgb, var(--green) 60%, transparent); }

.track-bar {
  width: 12px;
  height: 2px;
  background: color-mix(in srgb, var(--hint) 25%, transparent);
}

.track-bar.on { background: color-mix(in srgb, var(--accent) 55%, transparent); }

/* ---------- empty state ---------- */

.empty {
  margin: 18vh 32px 0;
  text-align: center;
  color: var(--hint);
  font-size: 14.5px;
  white-space: pre-line;
  line-height: 1.6;
}

/* ---------- FAB ---------- */

#add {
  position: fixed;
  right: 18px;
  bottom: calc(20px + env(safe-area-inset-bottom));
  z-index: 5;
  width: 54px;
  height: 54px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 18px;
  background: var(--accent);
  color: var(--accent-fg);
  box-shadow: 0 6px 18px color-mix(in srgb, var(--accent) 42%, transparent);
  transition: transform 0.15s;
}

#add:active { transform: scale(0.92); }

/* ---------- bottom sheet ---------- */

#overlay, #b-overlay {
  position: fixed;
  inset: 0;
  z-index: 10;
  visibility: hidden;
  transition: visibility 0s 0.28s;
}

#overlay.open, #b-overlay.open { visibility: visible; transition: none; }

.backdrop {
  position: absolute;
  inset: 0;
  background: rgba(10, 12, 20, 0.45);
  opacity: 0;
  transition: opacity 0.25s;
}

#overlay.open .backdrop, #b-overlay.open .backdrop { opacity: 1; }

.sheet {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  max-height: 88vh;
  overflow-y: auto;
  background: var(--surface);
  border-radius: 20px 20px 0 0;
  padding: 8px 16px calc(16px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 12px;
  transform: translateY(105%);
  transition: transform 0.3s cubic-bezier(0.32, 0.72, 0.24, 1);
}

#overlay.open .sheet, #b-overlay.open .sheet { transform: none; }

.grab {
  width: 36px;
  height: 4px;
  margin: 2px auto 0;
  border-radius: 999px;
  background: color-mix(in srgb, var(--hint) 35%, transparent);
}

.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 30px;
}

.sheet-head h2 {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.icon-btn {
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 10px;
  background: color-mix(in srgb, var(--hint) 12%, transparent);
}

.icon-btn.danger { color: var(--red); background: color-mix(in srgb, var(--red) 12%, transparent); }

/* status segmented control in sheet */

#status-track {
  display: flex;
  gap: 4px;
  padding: 4px;
  background: color-mix(in srgb, var(--hint) 12%, transparent);
  border-radius: 11px;
}

.seg {
  flex: 1;
  padding: 8px 2px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--hint);
  font-size: 13px;
  font-weight: 600;
  transition: background 0.18s, color 0.18s;
}

.seg.active {
  background: var(--accent);
  color: var(--accent-fg);
}

/* fields */

.sheet input,
.sheet textarea {
  width: 100%;
  padding: 11px 13px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--bg);
  color: var(--fg);
  font: inherit;
  resize: none;
}

.sheet input:focus,
.sheet textarea:focus {
  outline: none;
  border-color: color-mix(in srgb, var(--accent) 65%, transparent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 15%, transparent);
}

#f-title { font-weight: 600; font-size: 16px; }

.field { display: flex; flex-direction: column; gap: 7px; }

.field-label {
  font-size: 12px;
  font-weight: 650;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--hint);
}

.chips { display: flex; flex-wrap: wrap; gap: 7px; }

.chip {
  padding: 7px 13px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: transparent;
  color: var(--fg);
  font-size: 13.5px;
  font-weight: 550;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.chip.active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-fg);
}

.chip.prio-chip-high.active { background: var(--red); border-color: var(--red); }
.chip.prio-chip-low.active {
  background: var(--hint);
  border-color: var(--hint);
  color: var(--surface);
}

/* actions */

.sheet-actions { display: flex; gap: 10px; margin-top: 2px; }

.btn {
  flex: 1;
  padding: 13px;
  border: 0;
  border-radius: 13px;
  font-size: 15px;
  font-weight: 650;
  transition: transform 0.12s, filter 0.15s;
}

.btn:active { transform: scale(0.97); }

.btn.primary { background: var(--accent); color: var(--accent-fg); flex: 1.6; }

.btn.ghost { background: color-mix(in srgb, var(--hint) 13%, transparent); color: var(--fg); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
