:root {
  --bg-1: #eef1f8;
  --bg-2: #e7ecf7;
  --surface: #ffffff;
  --surface-2: #f7f8fc;
  --border: #e6e8f0;
  --text: #1c2333;
  --muted: #6b7280;
  --faint: #9aa1b1;

  --brand-1: #6366f1;
  --brand-2: #8b5cf6;
  --brand-ink: #4f46e5;

  --green: #16a34a;
  --green-soft: #dcfce7;
  --yellow: #d97706;
  --yellow-soft: #fef3c7;
  --red: #dc2626;
  --red-soft: #fee2e2;
  --blue: #2563eb;
  --blue-soft: #dbeafe;
  --gray-soft: #eef0f4;

  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.06);
  --shadow: 0 6px 20px rgba(16, 24, 40, 0.08);
  --shadow-lg: 0 16px 40px rgba(16, 24, 40, 0.12);
  --radius: 14px;
  --radius-sm: 9px;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: "Segoe UI", -apple-system, Roboto, Helvetica, Arial, sans-serif;
  color: var(--text);
  background:
    radial-gradient(1200px 600px at 100% -10%, rgba(139, 92, 246, 0.10), transparent 60%),
    radial-gradient(1000px 500px at -10% 10%, rgba(99, 102, 241, 0.10), transparent 55%),
    linear-gradient(180deg, var(--bg-1), var(--bg-2));
  background-attachment: fixed;
  font-size: 15px;
  line-height: 1.5;
}

a { color: var(--brand-ink); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- top nav ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  background: linear-gradient(120deg, #4f46e5, #7c3aed 55%, #9333ea);
  color: #fff;
  box-shadow: var(--shadow);
}
.topbar-inner {
  max-width: 1120px;
  margin: 0 auto;
  padding: 0 20px;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.brand {
  display: flex; align-items: center; gap: 10px;
  font-weight: 700; font-size: 1.08rem; color: #fff;
}
.brand:hover { text-decoration: none; }
.brand .logo {
  width: 30px; height: 30px; border-radius: 9px;
  background: rgba(255,255,255,0.16);
  display: grid; place-items: center; font-size: 1rem;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.25);
}
.nav-links { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.nav-links a {
  color: rgba(255,255,255,0.88);
  padding: 7px 12px; border-radius: 8px; font-weight: 500; font-size: 0.92rem;
  transition: background 0.15s, color 0.15s;
}
.nav-links a:hover { background: rgba(255,255,255,0.14); color: #fff; text-decoration: none; }
.nav-links a.active { background: rgba(255,255,255,0.20); color: #fff; }
.nav-right { display: flex; align-items: center; gap: 12px; }
.user-chip { display: flex; align-items: center; gap: 8px; color: #fff; font-size: 0.9rem; }

/* ---------- layout ---------- */
.container { max-width: 1120px; margin: 0 auto; padding: 26px 20px 60px; }
.page-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; margin-bottom: 20px; flex-wrap: wrap;
}
.page-head h1 { margin: 0; font-size: 1.5rem; letter-spacing: -0.01em; }
.page-head .sub { color: var(--muted); font-size: 0.9rem; margin-top: 2px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 20px;
  margin-bottom: 18px;
}
.card h2 { margin: 0 0 14px; font-size: 1.05rem; }
.card h2.tight { margin-bottom: 6px; }
.grid { display: grid; gap: 16px; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.small { font-size: 0.85rem; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 7px;
  background: linear-gradient(120deg, var(--brand-1), var(--brand-2));
  color: #fff; border: none; border-radius: 10px;
  padding: 9px 16px; font-size: 0.92rem; font-weight: 600; cursor: pointer;
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.35);
  transition: transform 0.12s, box-shadow 0.12s, filter 0.12s;
  text-decoration: none;
}
.btn:hover { transform: translateY(-1px); box-shadow: 0 8px 18px rgba(99,102,241,0.42); text-decoration: none; filter: brightness(1.03); }
.btn:active { transform: translateY(0); }
.btn.ghost {
  background: var(--surface); color: var(--brand-ink);
  border: 1px solid var(--border); box-shadow: var(--shadow-sm);
}
.btn.ghost:hover { background: var(--surface-2); box-shadow: var(--shadow-sm); }
.btn.small { padding: 6px 12px; font-size: 0.82rem; border-radius: 8px; }
.btn.danger { background: linear-gradient(120deg, #ef4444, #dc2626); box-shadow: 0 4px 12px rgba(220,38,38,0.32); }

/* ---------- forms ---------- */
label { display: block; margin: 14px 0 5px; font-size: 0.82rem; font-weight: 600; color: var(--muted); }
input, textarea, select {
  width: 100%; padding: 10px 12px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  font-size: 0.95rem; font-family: inherit; background: #fff; color: var(--text);
  transition: border-color 0.15s, box-shadow 0.15s;
}
input:focus, textarea:focus, select:focus {
  outline: none; border-color: var(--brand-1);
  box-shadow: 0 0 0 3px rgba(99,102,241,0.18);
}
textarea { min-height: 92px; resize: vertical; }
.form-row { display: flex; gap: 14px; flex-wrap: wrap; }
.form-row > div { flex: 1; min-width: 160px; }
.actions { margin-top: 20px; display: flex; gap: 10px; align-items: center; }

.alert { padding: 11px 14px; border-radius: var(--radius-sm); margin-bottom: 14px; font-size: 0.9rem; }
.alert.error { background: var(--red-soft); color: #991b1b; }
.alert.success { background: var(--green-soft); color: #14532d; }
.alert.info { background: var(--blue-soft); color: #1e3a8a; }

/* ---------- badges / pills ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 10px; border-radius: 999px;
  font-size: 0.75rem; font-weight: 600; white-space: nowrap;
}
.badge.pending { background: var(--gray-soft); color: #4b5563; }
.badge.in_progress { background: var(--yellow-soft); color: #92400e; }
.badge.done { background: var(--green-soft); color: #166534; }
.badge.blocked { background: var(--red-soft); color: #991b1b; }
.badge.role { background: #ede9fe; color: #5b21b6; }
.badge.grouptag { background: var(--blue-soft); color: #1e40af; }
.badge.neutral { background: var(--gray-soft); color: #4b5563; }

.priority { font-weight: 600; font-size: 0.82rem; }
.priority.high { color: var(--red); }
.priority.medium { color: var(--yellow); }
.priority.low { color: var(--faint); }

/* ---------- flag dots ---------- */
.flag-dot { width: 11px; height: 11px; border-radius: 50%; display: inline-block; box-shadow: inset 0 0 0 1px rgba(0,0,0,0.08); }
.flag-dot.green { background: var(--green); }
.flag-dot.yellow { background: #eab308; }
.flag-dot.red { background: var(--red); }
.flag-dot.none { background: #d1d5db; }
.flag-pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 10px; border-radius: 999px; font-size: 0.75rem; font-weight: 600;
}
.flag-pill.green { background: var(--green-soft); color: #166534; }
.flag-pill.yellow { background: var(--yellow-soft); color: #92400e; }
.flag-pill.red { background: var(--red-soft); color: #991b1b; }
.flag-pill.none { background: var(--gray-soft); color: #6b7280; }

/* ---------- avatars ---------- */
.avatar {
  width: 32px; height: 32px; border-radius: 50%;
  display: inline-grid; place-items: center;
  color: #fff; font-size: 0.78rem; font-weight: 700; flex: none;
  box-shadow: var(--shadow-sm);
}
.avatar.sm { width: 26px; height: 26px; font-size: 0.68rem; }
.avatar.lg { width: 42px; height: 42px; font-size: 0.95rem; }
.person { display: inline-flex; align-items: center; gap: 8px; }

/* ---------- tabs (group selector) ---------- */
.tabs { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 18px; }
.tab {
  padding: 8px 15px; border-radius: 999px; font-size: 0.88rem; font-weight: 600;
  background: var(--surface); border: 1px solid var(--border); color: var(--muted);
  box-shadow: var(--shadow-sm); transition: all 0.15s;
}
.tab:hover { color: var(--text); text-decoration: none; transform: translateY(-1px); }
.tab.active {
  background: linear-gradient(120deg, var(--brand-1), var(--brand-2));
  color: #fff; border-color: transparent; box-shadow: 0 4px 12px rgba(99,102,241,0.35);
}
.tab .count { opacity: 0.8; font-weight: 500; }

/* ---------- stat tiles ---------- */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 14px; margin-bottom: 18px; }
.tile {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow-sm);
  position: relative; overflow: hidden;
}
.tile .label { font-size: 0.8rem; color: var(--muted); font-weight: 600; }
.tile .value { font-size: 1.9rem; font-weight: 700; margin-top: 4px; letter-spacing: -0.02em; }
.tile.accent-red .value { color: var(--red); }
.tile.accent-yellow .value { color: #b45309; }
.tile.accent-green .value { color: var(--green); }
.tile.accent-blue .value { color: var(--blue); }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
th, td { text-align: left; padding: 11px 12px; border-bottom: 1px solid var(--border); }
th { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--faint); font-weight: 700; }
tbody tr:hover { background: var(--surface-2); }
td.num { text-align: center; font-variant-numeric: tabular-nums; }
.count-chip {
  display: inline-block; min-width: 26px; padding: 2px 7px; border-radius: 7px;
  font-weight: 600; font-size: 0.8rem;
}
.count-chip.zero { color: var(--faint); background: transparent; }
.count-chip.pending { background: var(--gray-soft); color: #4b5563; }
.count-chip.in_progress { background: var(--yellow-soft); color: #92400e; }
.count-chip.done { background: var(--green-soft); color: #166534; }
.count-chip.blocked { background: var(--red-soft); color: #991b1b; }

/* ---------- task list ---------- */
.task-row {
  display: flex; align-items: center; gap: 14px;
  padding: 13px 4px; border-bottom: 1px solid var(--border);
}
.task-row:last-child { border-bottom: none; }
.task-row .main { flex: 1; min-width: 0; }
.task-row .title { font-weight: 600; }
.task-row .title a { color: var(--text); }
.task-row .title a:hover { color: var(--brand-ink); }
.task-row .meta { color: var(--muted); font-size: 0.82rem; margin-top: 3px; display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.task-row .meta .dot-sep::before { content: "·"; margin-right: 8px; color: var(--faint); }

.filters { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; }
.filters select { width: auto; min-width: 130px; }

/* ---------- feed / conversation ---------- */
.feed-item {
  display: flex; gap: 12px; padding: 12px 0; border-bottom: 1px dashed var(--border);
}
.feed-item:last-child { border-bottom: none; }
.feed-body { flex: 1; min-width: 0; }
.feed-body .who { font-weight: 600; }
.feed-body .when { color: var(--faint); font-size: 0.78rem; margin-top: 2px; }
.feed-body .text { margin-top: 4px; white-space: pre-wrap; word-wrap: break-word; }
.feed-body .sys { color: var(--muted); font-size: 0.9rem; }
.feed-item.type-status { }
.feed-item.type-flag .feed-body .sys { }

.empty { color: var(--muted); padding: 18px 0; text-align: center; }

/* ---------- login ---------- */
.auth-wrap { min-height: calc(100vh - 0px); display: grid; place-items: center; padding: 24px; }
.auth-card {
  width: 100%; max-width: 380px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 18px; box-shadow: var(--shadow-lg); padding: 30px;
}
.auth-logo {
  width: 52px; height: 52px; border-radius: 14px; margin: 0 auto 14px;
  background: linear-gradient(120deg, var(--brand-1), var(--brand-2));
  display: grid; place-items: center; font-size: 1.5rem; color: #fff;
  box-shadow: 0 8px 20px rgba(99,102,241,0.4);
}
.auth-card h1 { text-align: center; margin: 0 0 4px; font-size: 1.35rem; }
.auth-card .sub { text-align: center; color: var(--muted); margin: 0 0 18px; font-size: 0.9rem; }

/* ---------- misc ---------- */
.divider { height: 1px; background: var(--border); margin: 16px 0; }
.pill-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.inline-form { display: inline; }
.stack { display: flex; flex-direction: column; gap: 4px; }
.right { margin-left: auto; }
code.token { background: #f1f0fb; color: #6d28d9; padding: 2px 7px; border-radius: 6px; font-size: 0.9rem; }

/* ---------- priority flag ---------- */
.prio {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 9px; border-radius: 7px; font-size: 0.74rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.03em;
}
.prio .tri { width: 0; height: 0; border-left: 5px solid transparent; border-right: 5px solid transparent; }
.prio.high { background: var(--red-soft); color: #991b1b; }
.prio.high .tri { border-bottom: 9px solid var(--red); }
.prio.medium { background: var(--yellow-soft); color: #92400e; }
.prio.medium .tri { border-bottom: 9px solid #eab308; }
.prio.low { background: var(--gray-soft); color: #4b5563; }
.prio.low .tri { border-bottom: 9px solid #94a3b8; }

/* ---------- deadline pill ---------- */
.due {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 9px; border-radius: 999px; font-size: 0.75rem; font-weight: 600; white-space: nowrap;
}
.due::before { content: "🕑"; font-size: 0.8em; }
.due.due-red { background: var(--red-soft); color: #991b1b; }
.due.due-red::before { content: "⚠️"; }
.due.due-orange { background: #ffedd5; color: #9a3412; }
.due.due-blue { background: var(--blue-soft); color: #1e40af; }
.due.due-soft { background: #f1f5f9; color: #475569; }
.due.due-none { background: var(--gray-soft); color: #64748b; }

/* ---------- tag chips ---------- */
.tag-chip {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 9px 2px 3px; border-radius: 999px;
  background: var(--surface-2); border: 1px solid var(--border);
  font-size: 0.78rem; color: var(--text);
}
.tag-chip .avatar { width: 20px; height: 20px; font-size: 0.6rem; }
.tags-inline { display: inline-flex; gap: 5px; flex-wrap: wrap; align-items: center; }

select[multiple] { min-height: 92px; padding: 4px; }
select[multiple] option { padding: 5px 8px; border-radius: 5px; }
.hint { font-size: 0.78rem; color: var(--faint); margin-top: 4px; }

/* ---------- dashboard split (list + right panel) ---------- */
.dash-split { display: grid; grid-template-columns: 1fr 380px; gap: 16px; align-items: start; }
.dash-panel { position: sticky; top: 78px; }
.panel-card { max-height: calc(100vh - 100px); overflow-y: auto; }
.panel-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; margin-bottom: 10px; }
.panel-title { font-weight: 700; font-size: 1.05rem; line-height: 1.3; }
.panel-open { font-size: 1.15rem; text-decoration: none; color: var(--muted); flex: none; }
.panel-open:hover { color: var(--brand-ink); text-decoration: none; }

.task-line { display: flex; align-items: center; gap: 10px; padding: 9px 8px; border-bottom: 1px solid var(--border); cursor: pointer; border-radius: 8px; }
.task-line:last-child { border-bottom: none; }
.task-line:hover { background: var(--surface-2); }
.task-line.selected { background: #eef0ff; box-shadow: inset 3px 0 0 var(--brand-1); }
.task-line-title { flex: 1; min-width: 0; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.person-block { border-bottom: 1px solid var(--border); }
.person-block:last-child { border-bottom: none; }
.person-row { display: flex; align-items: center; gap: 10px; padding: 11px 8px; cursor: pointer; user-select: none; border-radius: 8px; }
.person-row:hover { background: var(--surface-2); }
.person-tasks { display: none; padding-left: 18px; padding-bottom: 6px; }
.person-block.open .person-tasks { display: block; }

@media (max-width: 900px) {
  .dash-split { grid-template-columns: 1fr; }
  .dash-panel { position: static; }
  .panel-card { max-height: none; }
}

@media (max-width: 760px) {
  .grid[style*="1fr 1fr"], .grid[style*="1.4fr"], .grid[style*="1.4fr 1fr"] { grid-template-columns: 1fr !important; }
}
@media (max-width: 640px) {
  .topbar-inner { height: auto; padding: 10px 16px; flex-wrap: wrap; }
  .user-chip span.name { display: none; }
  .page-head h1 { font-size: 1.3rem; }
}
