:root {
  --bg: #f5f6f4;
  --panel: #ffffff;
  --ink: #1f2521;
  --muted: #6b736d;
  --line: #e2e5e1;
  --accent: #2f6f4f;
  --accent-soft: #e6f0ea;
  --warn: #b26a00;
  --danger: #b3261e;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 16px rgba(0,0,0,.05);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #151816; --panel: #1d211e; --ink: #e7ebe8; --muted: #9aa39c; --line: #2d332f;
    --accent: #5fb488; --accent-soft: #22342a; --warn: #e0a24a; --danger: #ef7b72;
    --shadow: 0 1px 2px rgba(0,0,0,.3); color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 14px/1.45 "Segoe UI", system-ui, -apple-system, sans-serif;
  display: flex; flex-direction: column;
}
button, input, select, textarea { font: inherit; color: inherit; }
.hidden { display: none !important; }

/* top bar */
.topbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 12px 18px;
  padding: 10px 18px; background: var(--panel); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; }
.logo {
  width: 32px; height: 32px; border-radius: 8px; background: var(--accent); color: #fff;
  display: grid; place-items: center; font-weight: 700;
}
.title { font-weight: 650; font-size: 15px; }
.day { color: var(--muted); font-size: 13px; }
.counts { display: flex; gap: 8px; }
.pill { padding: 3px 10px; border-radius: 999px; background: var(--accent-soft); font-size: 12.5px; white-space: nowrap; }
.pill b { font-weight: 650; }
.filters { display: flex; gap: 8px; flex: 1; min-width: 260px; }
.filters input { flex: 1; min-width: 140px; }
input, select, textarea {
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 6px 9px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.actions { display: flex; gap: 6px; }
.btn {
  border: 1px solid var(--line); background: var(--panel); border-radius: 8px; padding: 6px 12px;
  cursor: pointer; white-space: nowrap;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); }
.btn:disabled { opacity: .45; cursor: default; }

.banner { padding: 8px 18px; background: #fff4e0; color: #6b4200; border-bottom: 1px solid #f0d9a8; }
@media (prefers-color-scheme: dark) { .banner { background: #3a2c12; color: #f4d49a; border-color: #5a4520; } }

/* layout */
.layout { flex: 1; display: grid; grid-template-columns: 1fr 380px; min-height: 0; }
.tasks { overflow-y: auto; padding: 14px 18px 40px; }
.chat { display: flex; flex-direction: column; border-left: 1px solid var(--line); background: var(--panel); min-height: 0; }
.layout > * { min-width: 0; }
@media (max-width: 900px) {
  .filters { flex: 1 1 100%; flex-wrap: wrap; min-width: 0; }
  .topbar > * { min-width: 0; }
  .task .line1 { min-width: 0; }
  .filters select { flex: 1 1 30%; min-width: 0; }
  .filters input { flex: 1 1 100%; }
  .actions { flex-wrap: wrap; }
  .topbar { padding: 10px 16px; }
  .tasks { padding: 12px 16px 30px; }
  .layout { grid-template-columns: minmax(0, 1fr); grid-template-rows: 1fr 45vh; }
  .chat { border-left: 0; border-top: 1px solid var(--line); }
}

/* person groups */
.group { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 14px; box-shadow: var(--shadow); }
.group-head {
  display: flex; align-items: center; gap: 8px; padding: 9px 14px; cursor: pointer; user-select: none;
  border-bottom: 1px solid var(--line); font-weight: 650;
}
.group.collapsed .group-head { border-bottom: 0; }
.group.collapsed .task { display: none; }
.group-head .caret { color: var(--muted); transition: transform .15s; }
.group.collapsed .caret { transform: rotate(-90deg); }
.group-head .sub { color: var(--muted); font-weight: 400; font-size: 12.5px; }
.group-head .core-tag { font-size: 11px; color: var(--muted); font-weight: 400; margin-left: auto; }

.task { display: grid; grid-template-columns: 26px 1fr; gap: 4px 8px; padding: 9px 14px; border-top: 1px solid var(--line); }
.task:first-of-type { border-top: 0; }
.task:hover { background: color-mix(in srgb, var(--accent-soft) 45%, transparent); }
.task input[type=checkbox] { width: 18px; height: 18px; margin: 2px 0 0; accent-color: var(--accent); cursor: pointer; }
.task .body { cursor: pointer; min-width: 0; }
.task .line1 { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.task .name { font-weight: 600; }
.task.done .name { text-decoration: line-through; color: var(--muted); }
.task .note { color: var(--ink); opacity: .85; margin-top: 2px; overflow-wrap: anywhere; }
.task .meta { color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.task .today { color: var(--accent); font-weight: 600; }
.chip { font-size: 11.5px; padding: 1px 7px; border-radius: 6px; border: 1px solid var(--line); color: var(--muted); }
.badge { font-size: 11.5px; padding: 1px 8px; border-radius: 999px; font-weight: 600; white-space: nowrap; }
.prio { font-size: 11px; color: var(--danger); font-weight: 700; letter-spacing: .02em; }
.s-pending { background: #eef0f2; color: #4a5560; }
.s-in-progress { background: #e3eefc; color: #1d5bb8; }
.s-awaiting-review, .s-awaiting-input { background: #fff1d6; color: #8a5a00; }
.s-development-done { background: #e6f4ff; color: #0b6aa2; }
.s-partially-completed { background: #efe8fb; color: #6a3fb5; }
.s-scheduled { background: #e0f5f3; color: #0c7468; }
.s-on-hold, .s-not-confirmed { background: #f1ede6; color: #75634a; }
.s-blocked { background: #fde4e2; color: #a3261d; }
.s-completed { background: #dff3e6; color: #1f7a45; }
.s-dropped { background: #ececec; color: #777; }
@media (prefers-color-scheme: dark) {
  .s-pending { background: #2b3136; color: #b9c3cc; }
  .s-in-progress { background: #1c2d45; color: #8cb8f5; }
  .s-awaiting-review, .s-awaiting-input { background: #3a2f18; color: #f1c26e; }
  .s-development-done { background: #16303f; color: #7cc4ee; }
  .s-partially-completed { background: #2c2440; color: #c3a6f1; }
  .s-scheduled { background: #16332f; color: #74d3c6; }
  .s-on-hold, .s-not-confirmed { background: #332d24; color: #cdb996; }
  .s-blocked { background: #3d1f1d; color: #f19b93; }
  .s-completed { background: #1b3325; color: #7fd3a0; }
  .s-dropped { background: #2a2a2a; color: #999; }
}
.empty { color: var(--muted); padding: 30px; text-align: center; }

/* chat */
.chat-head { display: flex; align-items: center; justify-content: space-between; padding: 10px 14px; border-bottom: 1px solid var(--line); font-weight: 650; }
.mode { font-size: 12px; font-weight: 400; color: var(--muted); }
.chat-log { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.msg { max-width: 92%; padding: 7px 11px; border-radius: 12px; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.user { align-self: flex-end; background: var(--accent); color: #fff; border-bottom-right-radius: 4px; }
.msg.bot { align-self: flex-start; background: var(--bg); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.msg .opts { display: flex; flex-direction: column; gap: 5px; margin-top: 7px; }
.msg .opts button { text-align: left; font-size: 13px; white-space: normal; }
.chat-log { overflow-x: hidden; }
.msg .opts.used { opacity: .5; pointer-events: none; }
.msg.typing { color: var(--muted); font-style: italic; }
.chat-input { display: flex; gap: 8px; padding: 10px; border-top: 1px solid var(--line); }
.chat-input textarea { flex: 1; resize: none; }

/* dialogs */
.dlg { border: 1px solid var(--line); border-radius: 14px; padding: 0; width: min(760px, 94vw); max-height: 90vh; background: var(--panel); color: var(--ink); box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.dlg::backdrop { background: rgba(20,25,22,.45); }
.dlg-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--panel); z-index: 1; }
.dlg-head h2 { margin: 0; font-size: 16px; }
.dlg-body { padding: 16px 18px; overflow-y: auto; max-height: calc(90vh - 130px); }
.dlg-foot { display: flex; gap: 8px; justify-content: flex-end; padding: 12px 18px; border-top: 1px solid var(--line); position: sticky; bottom: 0; background: var(--panel); }
.dlg-foot .left { margin-right: auto; display: flex; gap: 8px; }
.form { display: grid; grid-template-columns: 130px 1fr; gap: 10px 12px; align-items: center; }
.form label { color: var(--muted); font-size: 13px; }
.form textarea { min-height: 90px; resize: vertical; }
.form .full { grid-column: 1 / -1; }
.x { background: none; border: 0; font-size: 20px; cursor: pointer; color: var(--muted); }
.people-pick { display: flex; flex-wrap: wrap; gap: 6px; }
.people-pick label { display: inline-flex; align-items: center; gap: 4px; border: 1px solid var(--line); padding: 3px 9px; border-radius: 999px; cursor: pointer; color: var(--ink); font-size: 13px; }
.people-pick label.on { background: var(--accent-soft); border-color: var(--accent); }
.people-pick input { display: none; }
.people-pick .order { font-size: 11px; color: var(--accent); font-weight: 700; }
.hint { color: var(--muted); font-size: 12.5px; }
.hist { margin-top: 14px; border-top: 1px solid var(--line); padding-top: 10px; }
.hist-item { font-size: 13px; padding: 5px 0; border-bottom: 1px dashed var(--line); }
.hist-item .when { color: var(--muted); font-size: 12px; }
.hist-item.undone { opacity: .5; text-decoration: line-through; }
.section-title { font-weight: 650; margin: 14px 0 6px; display: flex; gap: 8px; align-items: center; }
.section-title:first-child { margin-top: 0; }
.mini { list-style: none; margin: 0; padding: 0; }
.mini li { padding: 4px 0; border-bottom: 1px dashed var(--line); font-size: 13px; }
.mini li .who { color: var(--muted); }
.email { width: 100%; min-height: 360px; font: 13px/1.5 Consolas, "Cascadia Mono", monospace; white-space: pre-wrap; }
.summary-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 8px; }
.stat { border: 1px solid var(--line); border-radius: 10px; padding: 10px; text-align: center; }
.stat b { display: block; font-size: 22px; }
.stat span { color: var(--muted); font-size: 12px; }
@media (max-width: 600px) { .summary-grid { grid-template-columns: repeat(2, 1fr); } .form { grid-template-columns: 1fr; } }
table.snap { width: 100%; border-collapse: collapse; font-size: 13px; }
table.snap th, table.snap td { border-bottom: 1px solid var(--line); padding: 5px 6px; text-align: left; vertical-align: top; }
table.snap th { color: var(--muted); font-weight: 600; position: sticky; top: 0; background: var(--panel); }
.error { color: var(--danger); }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 9px 16px; border-radius: 10px; box-shadow: var(--shadow); z-index: 50; max-width: 90vw; }
.toast.err { background: var(--danger); color: #fff; }
.people-table td { padding: 4px 6px; }

/* ---------- login / invite / setup pages ---------- */
.auth-page { align-items: center; justify-content: center; padding: 24px 16px; }
.auth-card { width: min(420px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 26px; box-shadow: var(--shadow); }
.auth-card .brand { margin-bottom: 18px; }
.auth-card h1 { font-size: 20px; margin: 0 0 8px; }
.auth-card form { display: grid; gap: 12px; margin: 14px 0; }
.auth-card label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
.auth-card input { width: 100%; padding: 9px 11px; color: var(--ink); }
.auth-card .btn { padding: 9px 12px; }

/* ---------- user menu, tabs, admin ---------- */
.usermenu { position: relative; }
.usermenu > button { display: inline-flex; align-items: center; gap: 6px; }
.avatar { width: 24px; height: 24px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; font-weight: 700; font-size: 12px; }
.menu { position: absolute; right: 0; top: calc(100% + 6px); background: var(--panel); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow); min-width: 200px; z-index: 20; padding: 6px; }
.menu button { display: block; width: 100%; text-align: left; background: none; border: 0; padding: 7px 10px; border-radius: 6px; cursor: pointer; }
.menu button:hover { background: var(--accent-soft); }
.menu .who { padding: 6px 10px 8px; border-bottom: 1px solid var(--line); margin-bottom: 4px; font-size: 12.5px; color: var(--muted); }
.tabs { display: flex; gap: 4px; }
.tabs button { background: none; border: 0; padding: 4px 10px; border-radius: 7px; cursor: pointer; color: var(--muted); font-weight: 600; }
.tabs button.on { background: var(--accent-soft); color: var(--accent); }
.unread { background: var(--danger); color: #fff; border-radius: 999px; font-size: 10.5px; padding: 0 6px; margin-left: 4px; }
.msg .from { font-size: 11.5px; font-weight: 700; margin-bottom: 2px; color: var(--accent); }
.msg.user .from { color: #e6f0ea; }
.msg .time { font-size: 10.5px; opacity: .6; margin-left: 6px; font-weight: 400; }
.msg.system { align-self: center; background: none; border: 0; color: var(--muted); font-size: 12px; text-align: center; }
.users-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.users-table th, .users-table td { border-bottom: 1px solid var(--line); padding: 6px; text-align: left; vertical-align: middle; }
.users-table th { color: var(--muted); font-weight: 600; }
.tag { font-size: 11px; padding: 1px 7px; border-radius: 999px; background: var(--bg); border: 1px solid var(--line); white-space: nowrap; }
.tag.admin { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.tag.disabled { color: var(--danger); }
.tag.invited { color: var(--warn); }
.linkbox { display: flex; gap: 8px; margin: 8px 0; }
.linkbox input { flex: 1; font-family: Consolas, monospace; font-size: 12.5px; }
.act-item { padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 13px; }
.act-item .when { color: var(--muted); font-size: 12px; }
.act-item.undone { opacity: .5; }
.subtabs { display: flex; gap: 6px; border-bottom: 1px solid var(--line); margin: -4px 0 14px; padding-bottom: 8px; flex-wrap: wrap; }
.warnbox { background: #fff4e0; border: 1px solid #f0d9a8; color: #6b4200; padding: 8px 10px; border-radius: 8px; font-size: 13px; }
@media (prefers-color-scheme: dark) { .warnbox { background: #3a2c12; color: #f4d49a; border-color: #5a4520; } }
.row-actions { display: flex; flex-wrap: wrap; gap: 4px; }
.row-actions .btn { padding: 3px 8px; font-size: 12px; }

/* filters get their own row under the title and buttons */
.filters { order: 5; flex: 1 1 100%; min-width: 0; }
.actions { margin-left: auto; flex-wrap: wrap; }
.form input:not([type=checkbox]), .form select { width: 100%; }

/* ---------- comments, mentions, files ---------- */
.latest-comment { color: var(--muted); font-size: 12.5px; margin-top: 3px; overflow-wrap: anywhere;
  border-left: 2px solid var(--line); padding-left: 7px; }
.latest-comment b { color: var(--ink); font-weight: 600; }
.ccount { white-space: nowrap; }
.comments { margin-top: 14px; border-top: 1px solid var(--line); padding-top: 10px; }
.composer { border: 1px solid var(--line); border-radius: 10px; padding: 8px; background: var(--bg); }
.composer.drop { outline: 2px dashed var(--accent); }
.composer textarea { width: 100%; resize: vertical; min-height: 54px; }
.composer-foot { display: flex; align-items: center; gap: 8px; margin-top: 6px; }
.composer-foot .hint { margin-left: auto; }
.fchips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.fchip { display: inline-flex; align-items: center; gap: 4px; border: 1px solid var(--line); background: var(--panel);
  border-radius: 8px; padding: 2px 4px 2px 8px; font-size: 12.5px; max-width: 100%; }
.fchip.busy { opacity: .7; }
.fchip.removed { opacity: .45; text-decoration: line-through; }
.fchip .x { font-size: 16px; padding: 0 4px; line-height: 1; }
.fsize { color: var(--muted); font-size: 11.5px; white-space: nowrap; }
.clist { margin-top: 10px; display: flex; flex-direction: column; gap: 8px; }
.comment { border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; }
.chead { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; font-size: 13px; }
.cacts { margin-left: auto; display: flex; gap: 10px; }
.ctext { margin-top: 4px; white-space: pre-wrap; overflow-wrap: anywhere; }
.avatar { display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 50%;
  background: var(--accent-soft); color: var(--accent); font-size: 11.5px; font-weight: 700; flex: none; }
button.link { background: none; border: 0; padding: 0; color: var(--accent); cursor: pointer; font-size: 12.5px; }
button.link:hover { text-decoration: underline; }
button.link.danger { color: var(--danger); }
.mention { background: var(--accent-soft); color: var(--accent); border-radius: 5px; padding: 0 3px; font-weight: 600; }
.mention.me { background: #fff1c7; color: #8a5a00; }
.msg.user .mention { background: rgba(255,255,255,.22); color: #fff; }
.msg.user a { color: #fff; }
.msg.user .files .file { color: var(--ink); }
.files { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.files .thumb img { display: block; max-width: 160px; max-height: 120px; border-radius: 8px; border: 1px solid var(--line); object-fit: cover; }
.files .file { display: inline-flex; align-items: center; gap: 5px; max-width: 100%; border: 1px solid var(--line);
  border-radius: 8px; padding: 4px 9px; text-decoration: none; color: var(--ink); background: var(--panel); font-size: 12.5px; }
.files .file:hover { border-color: var(--accent); }
.files .fname { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 220px; }
.mention-pop { position: absolute; left: 8px; top: 100%; z-index: 20; min-width: 200px; max-width: 280px; background: var(--panel);
  border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow); padding: 4px; }
.chat-box .mention-pop { top: auto; bottom: 100%; margin-bottom: 4px; }
.mention-pop .opt { display: flex; align-items: center; gap: 8px; padding: 5px 8px; border-radius: 7px; cursor: pointer; }
.mention-pop .opt.on, .mention-pop .opt:hover { background: var(--accent-soft); }
.chat-input.composer { border: 0; border-top: 1px solid var(--line); border-radius: 0; background: transparent; align-items: flex-end; }
.chat-box { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.chat-box textarea { width: 100%; resize: none; }
.mention-item { border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; margin-bottom: 8px; cursor: pointer; }
.mention-item:hover { border-color: var(--accent); }
.mention-item.new { border-left: 3px solid var(--danger); }
.mtext { margin-top: 3px; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.flash { outline: 3px solid #f1c26e; }
@media (prefers-color-scheme: dark) { .mention.me { background: #3a2f18; color: #f1c26e; } }
