:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --surface: var(--tg-theme-secondary-bg-color, #f4f5f7);
  --text: var(--tg-theme-text-color, #101114);
  --muted: var(--tg-theme-hint-color, #7b7f8a);
  --link: var(--tg-theme-link-color, #2f6fed);
  --accent: var(--tg-theme-button-color, #2f6fed);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --line: color-mix(in srgb, var(--text) 10%, transparent);
  --open: #6b7280;
  --progress: #2563eb;
  --blocked: #dc2626;
  --done: #16a34a;
  --urgent: #dc2626;
  --high: #ea580c;
  --radius: 16px;
}

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

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;
  font-size: 15px;
  line-height: 1.4;
  overscroll-behavior-y: contain;
}

#app { padding: 0 14px calc(96px + env(safe-area-inset-bottom)); max-width: 720px; margin: 0 auto; }

.topbar { padding: calc(14px + env(safe-area-inset-top)) 0 6px; }

.brand { display: flex; align-items: center; gap: 10px; }

.logo {
  width: 40px; height: 40px; border-radius: 12px;
  background: linear-gradient(140deg, #2f6fed, #7c3aed);
  color: #fff; font-weight: 800; font-size: 13px; letter-spacing: .5px;
  display: grid; place-items: center; flex: none;
}

.titles { min-width: 0; flex: 1; }
.titles h1 { font-size: 17px; margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.titles h1 .board-title { display: block; }
.muted { color: var(--muted); margin: 2px 0 0; font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.icon-btn {
  flex: none; width: 38px; height: 38px; border-radius: 50%;
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
  display: grid; place-items: center; cursor: pointer;
}
.icon-btn:active { transform: scale(.95); }
.icon-btn.spinning svg { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 14px; }
.stat {
  background: var(--surface); border-radius: 14px; padding: 10px 12px;
  display: flex; flex-direction: column; gap: 2px;
}
.stat span { font-size: 21px; font-weight: 700; letter-spacing: -.3px; }
.stat label { font-size: 11px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); }
.stat.alert span { color: var(--blocked); }

.tabs { display: flex; gap: 6px; overflow-x: auto; margin: 14px 0 10px; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab {
  border: 1px solid var(--line); background: transparent; color: var(--muted);
  padding: 8px 13px; border-radius: 999px; font-size: 13.5px; font-weight: 600;
  white-space: nowrap; cursor: pointer; font-family: inherit;
}
.tab.active { background: var(--text); color: var(--bg); border-color: transparent; }

.toolbar { display: flex; gap: 8px; margin-bottom: 12px; }
.toolbar[hidden] { display: none; }
.search {
  flex: 1; display: flex; align-items: center; gap: 8px;
  background: var(--surface); border-radius: 12px; padding: 0 12px; color: var(--muted);
  border: 1px solid transparent;
}
.search:focus-within { border-color: color-mix(in srgb, var(--accent) 45%, transparent); }
.search input {
  border: 0; background: transparent; color: var(--text); font: inherit;
  padding: 11px 0; width: 100%; outline: none;
}
.search input::placeholder { color: var(--muted); }
.select {
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
  border-radius: 12px; padding: 0 10px; font: inherit; font-size: 13px; max-width: 42%;
  outline: none; appearance: none; -webkit-appearance: none;
}

.list { display: flex; flex-direction: column; gap: 9px; }

.card {
  background: var(--surface); border-radius: var(--radius); padding: 13px 14px;
  display: flex; gap: 12px; align-items: flex-start; cursor: pointer;
  border: 1px solid transparent; transition: transform .08s ease;
}
.card:active { transform: scale(.994); }
.card.done { opacity: .62; }
.card.done .card-title { text-decoration: line-through; }

.check {
  flex: none; width: 23px; height: 23px; margin-top: 1px; border-radius: 50%;
  border: 2px solid color-mix(in srgb, var(--text) 25%, transparent);
  background: transparent; display: grid; place-items: center; cursor: pointer; padding: 0;
  color: transparent;
}
.check:hover { border-color: var(--done); color: var(--done); }
.check.is-done { background: var(--done); border-color: var(--done); color: #fff; }

.card-body { min-width: 0; flex: 1; }
.card-title { font-weight: 600; font-size: 15px; word-break: break-word; }
.card.done .card-title { color: var(--muted); }
.card-meta { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 7px; align-items: center; }

.tag {
  display: inline-flex; align-items: center; gap: 5px; font-size: 12px; color: var(--muted);
  background: color-mix(in srgb, var(--text) 5%, transparent); border-radius: 8px; padding: 3px 8px;
  max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.tag.due-overdue { color: var(--blocked); background: color-mix(in srgb, var(--blocked) 12%, transparent); font-weight: 600; }
.tag.due-soon { color: var(--high); }
.tag.status-open { color: var(--open); }
.tag.status-in_progress { color: var(--progress); }
.tag.status-blocked { color: var(--blocked); }
.tag.status-done { color: var(--done); }
.dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.prio-high { color: var(--high); }
.prio-urgent { color: var(--urgent); }

.section-label {
  font-size: 11px; text-transform: uppercase; letter-spacing: .8px; color: var(--muted);
  margin: 18px 2px 8px; font-weight: 700;
}

.empty { text-align: center; padding: 44px 18px; color: var(--muted); }
.empty strong { display: block; color: var(--text); font-size: 16px; margin-bottom: 4px; }
.empty p { margin: 0; font-size: 13.5px; }

.person {
  display: flex; align-items: center; gap: 12px; background: var(--surface);
  border-radius: var(--radius); padding: 12px 14px;
}
.avatar {
  width: 38px; height: 38px; border-radius: 50%; flex: none;
  display: grid; place-items: center; font-weight: 700; font-size: 14px; color: #fff;
  background: linear-gradient(140deg, #2f6fed, #7c3aed);
}
.person-info { flex: 1; min-width: 0; }
.person-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.person-sub { color: var(--muted); font-size: 12.5px; }
.person-count { font-weight: 700; font-size: 18px; }
.person-count small { display: block; font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; font-weight: 600; text-align: right; }
.role-badge { font-size: 10px; text-transform: uppercase; letter-spacing: .5px; color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, transparent); border-radius: 6px; padding: 2px 6px; margin-left: 6px; }

.fab {
  position: fixed; right: 18px; bottom: calc(18px + env(safe-area-inset-bottom));
  width: 56px; height: 56px; border-radius: 18px; border: 0; cursor: pointer;
  background: var(--accent); color: var(--accent-text);
  display: grid; place-items: center;
  box-shadow: 0 10px 24px rgba(47, 111, 237, .34);
}
.fab:active { transform: scale(.94); }

.sheet { position: fixed; inset: 0; z-index: 40; display: flex; align-items: flex-end; justify-content: center; }
.sheet[hidden] { display: none; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.42); backdrop-filter: blur(2px); }
.sheet-panel {
  position: relative; width: 100%; max-width: 720px;
  background: var(--bg); border-radius: 22px 22px 0 0;
  padding: 8px 18px calc(20px + env(safe-area-inset-bottom));
  max-height: 88vh; overflow-y: auto;
  animation: rise .18s ease-out;
}
@keyframes rise { from { transform: translateY(24px); opacity: .6; } }
.sheet-handle { width: 38px; height: 4px; border-radius: 2px; background: var(--line); margin: 4px auto 16px; }

.sheet h2 { font-size: 19px; margin: 0 0 8px; line-height: 1.3; }
.sheet .detail-text { color: var(--muted); font-size: 14px; margin: 0 0 14px; white-space: pre-wrap; }
.sheet .row { display: flex; justify-content: space-between; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line); font-size: 14px; }
.sheet .row .k { color: var(--muted); }
.sheet .row .v { text-align: right; word-break: break-word; }
.sheet .actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 16px; }
.btn {
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
  border-radius: 12px; padding: 12px 14px; font: inherit; font-weight: 600; cursor: pointer;
}
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: transparent; }
.btn.danger { color: var(--blocked); }
.btn.wide { grid-column: 1 / -1; }
.btn:disabled { opacity: .5; }

.timeline { margin-top: 16px; }
.timeline-item { display: flex; gap: 10px; padding: 7px 0; font-size: 13px; }
.timeline-item .when { color: var(--muted); font-size: 12px; white-space: nowrap; min-width: 74px; }

.form { display: flex; flex-direction: column; gap: 10px; margin-top: 6px; }
.field label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 5px; font-weight: 600; }
.field input, .field select, .field textarea {
  width: 100%; border: 1px solid var(--line); background: var(--surface); color: var(--text);
  border-radius: 12px; padding: 11px 12px; font: inherit; outline: none;
}
.field textarea { resize: vertical; min-height: 70px; }
.field input:focus, .field select:focus, .field textarea:focus { border-color: color-mix(in srgb, var(--accent) 55%, transparent); }

.toast {
  position: fixed; left: 50%; bottom: calc(88px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 999px;
  font-size: 13px; font-weight: 600; z-index: 60; max-width: 88vw; text-align: center;
}

.fatal { padding: 28vh 24px; text-align: center; max-width: 520px; margin: 0 auto; }
.fatal h2 { font-size: 20px; }
.fatal p { color: var(--muted); }

.loading-line { height: 76px; border-radius: var(--radius); background: var(--surface); opacity: .6; animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .3; } }

@media (min-width: 620px) {
  .stats { grid-template-columns: repeat(3, 160px); }
  .list { gap: 10px; }
  #app { padding-left: 20px; padding-right: 20px; }
}
