:root {
  --bg: #f6f5f1;
  --surface: #ffffff;
  --surface-2: #f1efe9;
  --border: #e4e1d8;
  --text: #1d2233;
  --muted: #6b6f7d;
  --navy: #1f2a44;
  --navy-2: #2a3758;
  --accent: #f5b942;
  --primary: #3b5bdb;
  --primary-h: #2f4ac0;
  --danger: #d9363e;
  --ok: #2f9e44;
  --warn: #e8590c;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(20, 24, 40, .06), 0 4px 16px rgba(20, 24, 40, .06);
  font-synthesis: none;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg); color: var(--text); -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
.boot { display: grid; place-items: center; height: 100vh; color: var(--muted); }

/* ---------- Buttons & inputs */
.btn {
  display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--border); background: var(--surface);
  padding: 8px 14px; border-radius: 9px; cursor: pointer; font-weight: 500; white-space: nowrap;
  transition: background .12s, border-color .12s;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-h); }
.btn.danger { color: var(--danger); }
.btn.danger:hover { background: #fdecec; border-color: #f3c2c4; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.sm { padding: 5px 10px; font-size: 13px; }
.btn:disabled { opacity: .6; cursor: default; }
.input, select.input, textarea.input {
  width: 100%; padding: 9px 12px; border: 1px solid var(--border); border-radius: 9px; background: var(--surface);
  outline: none; transition: border-color .12s, box-shadow .12s;
}
.input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(59, 91, 219, .15); }
textarea.input { resize: vertical; min-height: 90px; }
label.field { display: block; margin-bottom: 12px; }
label.field > span { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 5px; }
.row { display: flex; gap: 10px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.err { color: var(--danger); font-size: 14px; min-height: 20px; margin: 4px 0 8px; }

/* ---------- Auth */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px;
  background: radial-gradient(1200px 600px at 10% -10%, #e5e9f8 0, transparent 60%), var(--bg); }
.auth-card { width: 100%; max-width: 400px; background: var(--surface); border-radius: 18px; padding: 32px; box-shadow: var(--shadow); border: 1px solid var(--border); }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 20px; letter-spacing: -.02em; }
.brand img { width: 32px; height: 32px; }
.auth-card h1 { font-size: 22px; margin: 22px 0 4px; letter-spacing: -.02em; }
.auth-card p { margin: 0 0 20px; color: var(--muted); }
.auth-card .btn.primary { width: 100%; justify-content: center; padding: 11px; margin-top: 6px; }

/* ---------- Layout */
.layout { display: grid; grid-template-columns: 250px 1fr; min-height: 100vh; }
.sidebar { background: var(--navy); color: #d6dbea; padding: 18px 12px; display: flex; flex-direction: column; gap: 4px;
  position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.sidebar .brand { color: #fff; padding: 4px 10px 18px; font-size: 18px; }
.nav-item { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; color: #c7cde0; cursor: pointer; font-size: 14.5px; }
.nav-item:hover { background: var(--navy-2); color: #fff; }
.nav-item.active { background: rgba(255, 255, 255, .12); color: #fff; font-weight: 600; }
.nav-item .count { margin-left: auto; font-size: 12px; background: rgba(255, 255, 255, .12); padding: 1px 8px; border-radius: 99px; }
.nav-section { font-size: 11.5px; letter-spacing: .08em; text-transform: uppercase; color: #8590ad; padding: 16px 10px 6px; display: flex; align-items: center; }
.nav-section button { margin-left: auto; background: none; border: 0; color: #b4bbd0; cursor: pointer; font-size: 18px; line-height: 1; padding: 0 4px; border-radius: 6px; }
.nav-section button:hover { background: var(--navy-2); color: #fff; }
.dot { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.sidebar .me { margin-top: auto; padding: 12px 10px 4px; border-top: 1px solid rgba(255, 255, 255, .08); display: flex; align-items: center; gap: 10px; }
.sidebar .me .name { color: #fff; font-weight: 600; font-size: 14px; }
.sidebar .me .role { font-size: 12px; color: #8f98b3; }
.sidebar .me button { margin-left: auto; background: none; border: 0; color: #b4bbd0; cursor: pointer; font-size: 13px; padding: 4px 6px; border-radius: 6px; }
.sidebar .me button:hover { background: var(--navy-2); color: #fff; }

.layout > div { min-width: 0; }
.main { padding: 28px 36px 60px; min-width: 0; }
.page-head { display: flex; align-items: flex-start; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.page-head h1 { margin: 0; font-size: 26px; letter-spacing: -.025em; }
.page-head .sub { color: var(--muted); margin-top: 2px; }
.page-head .actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }
.topbar { display: none; }

.avatar { width: 28px; height: 28px; border-radius: 50%; display: inline-grid; place-items: center; color: #fff; font-size: 12px; font-weight: 700; flex: none; }
.avatar.sm { width: 22px; height: 22px; font-size: 10px; }
.avatar.lg { width: 40px; height: 40px; font-size: 15px; }
.avatars { display: flex; }
.avatars .avatar { border: 2px solid var(--surface); margin-left: -6px; }
.avatars .avatar:first-child { margin-left: 0; }

/* ---------- Cards */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 18px 20px; }
.card h2 { font-size: 16px; margin: 0 0 12px; letter-spacing: -.01em; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 22px; }
.stat { padding: 16px 18px; }
.stat .num { font-size: 28px; font-weight: 800; letter-spacing: -.03em; }
.stat .lbl { color: var(--muted); font-size: 13px; }
.stat.red .num { color: var(--danger); }
.stat.orange .num { color: var(--warn); }
.stat.green .num { color: var(--ok); }
.grid-2 { display: grid; grid-template-columns: 1.4fr 1fr; gap: 18px; align-items: start; }

/* ---------- Task list */
.quick-add { display: flex; gap: 8px; margin-bottom: 16px; }
.quick-add .input { padding: 11px 14px; }
.group { margin-bottom: 22px; }
.group-title { font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 0 0 8px 4px; display: flex; gap: 8px; align-items: center; }
.group-title.red { color: var(--danger); }
.task-list { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.task-row { display: flex; align-items: center; gap: 12px; padding: 11px 14px; border-top: 1px solid var(--border); cursor: pointer; }
.task-row:first-child { border-top: 0; }
.task-row:hover { background: #fbfaf7; }
.task-row .title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.task-row.done .title { text-decoration: line-through; color: var(--muted); }
.check { width: 20px; height: 20px; border-radius: 6px; border: 2px solid #c3c7d3; background: var(--surface); flex: none; cursor: pointer; display: grid; place-items: center; padding: 0; }
.check:hover { border-color: var(--ok); }
.check.on { background: var(--ok); border-color: var(--ok); }
.check.on::after { content: ""; width: 5px; height: 10px; border: solid #fff; border-width: 0 2px 2px 0; transform: rotate(45deg) translate(-1px, -1px); }
.meta { display: flex; align-items: center; gap: 8px; flex: none; font-size: 13px; color: var(--muted); }
.tag { display: inline-flex; align-items: center; gap: 5px; padding: 2px 8px; border-radius: 99px; font-size: 12px; font-weight: 600; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.tag.proj { background: transparent; border: 1px solid var(--border); font-weight: 500; }
.tag.due.over { background: #fdecec; color: var(--danger); }
.tag.due.today { background: #fff4e0; color: #b35c00; }
.tag.st-doing { background: #e7efff; color: #2f4ac0; }
.tag.st-review { background: #f3e8ff; color: #7c3aed; }
.tag.st-done { background: #e6f6ea; color: #2b8a3e; }
.prio { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.prio.low { background: #adb5bd; }
.prio.normal { background: transparent; }
.prio.high { background: #f59f00; }
.prio.urgent { background: var(--danger); box-shadow: 0 0 0 3px #fdecec; }
.empty { padding: 30px; text-align: center; color: var(--muted); }

/* ---------- Kanban */
.board { display: grid; grid-template-columns: repeat(4, minmax(240px, 1fr)); gap: 14px; align-items: start; overflow-x: auto; padding-bottom: 10px; }
.col { background: var(--surface-2); border-radius: var(--radius); padding: 10px; min-height: 140px; border: 1px solid var(--border); }
.col-head { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 14px; padding: 4px 6px 10px; }
.col-head .n { font-weight: 600; color: var(--muted); font-size: 12px; background: var(--surface); border-radius: 99px; padding: 0 8px; }
.col.drag-over { outline: 2px dashed var(--primary); outline-offset: -4px; background: #eef2ff; }
.kcard { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; margin-bottom: 8px; cursor: pointer; box-shadow: 0 1px 2px rgba(0, 0, 0, .04); }
.kcard:hover { border-color: #c9cede; }
.kcard.dragging { opacity: .4; }
.kcard .t { font-weight: 500; margin-bottom: 8px; word-break: break-word; }
.kcard .m { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; font-size: 12px; color: var(--muted); }
.kcard .m .avatar { margin-left: auto; }
.col-add { width: 100%; background: transparent; border: 1px dashed #cfd2db; border-radius: 9px; padding: 7px; color: var(--muted); cursor: pointer; }
.col-add:hover { background: var(--surface); color: var(--text); }
.col-add-input { margin-bottom: 8px; }

/* ---------- Activity */
.feed { list-style: none; margin: 0; padding: 0; }
.feed li { display: flex; gap: 10px; padding: 9px 0; border-top: 1px solid var(--border); font-size: 14px; }
.feed li:first-child { border-top: 0; padding-top: 0; }
.feed .when { font-size: 12px; color: var(--muted); }
.feed b { font-weight: 600; }
.feed .link { color: var(--primary); cursor: pointer; }
.feed .quote { color: var(--muted); font-style: italic; }

/* ---------- Tables */
table.tbl { width: 100%; border-collapse: collapse; }
.tbl th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 10px 14px; border-bottom: 1px solid var(--border); font-weight: 700; }
.tbl td { padding: 11px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl tr.click { cursor: pointer; }
.tbl tr.click:hover td { background: #fbfaf7; }
.tbl .num { font-variant-numeric: tabular-nums; font-weight: 600; }
.tbl .num.red { color: var(--danger); }
.tbl-wrap { overflow-x: auto; }
.badge { font-size: 11.5px; font-weight: 700; padding: 2px 8px; border-radius: 99px; background: #fff4d6; color: #8a5a00; }
.badge.off { background: #eee; color: #888; }

/* ---------- Projects grid */
.proj-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.proj-card { padding: 16px 18px; cursor: pointer; border-top: 4px solid var(--c, var(--primary)); transition: transform .12s; }
.proj-card:hover { transform: translateY(-2px); }
.proj-card h3 { margin: 0 0 4px; font-size: 16px; }
.proj-card .desc { color: var(--muted); font-size: 13.5px; min-height: 20px; margin-bottom: 12px; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.progress { height: 6px; background: var(--surface-2); border-radius: 99px; overflow: hidden; margin: 8px 0 12px; }
.progress > div { height: 100%; background: var(--ok); border-radius: 99px; }

/* ---------- Modal */
.modal-bg { position: fixed; inset: 0; background: rgba(18, 22, 36, .45); display: flex; align-items: flex-start; justify-content: center; padding: 6vh 16px; z-index: 50; overflow-y: auto; animation: fade .12s; }
.modal { background: var(--surface); border-radius: 16px; width: 100%; max-width: 560px; box-shadow: 0 20px 60px rgba(0, 0, 0, .25); animation: pop .15s; }
.modal.wide { max-width: 780px; }
.modal-head { display: flex; align-items: center; gap: 10px; padding: 18px 22px 0; }
.modal-head h2 { margin: 0; font-size: 18px; flex: 1; }
.modal-body { padding: 16px 22px 22px; }
.modal-foot { display: flex; gap: 8px; justify-content: flex-end; padding: 0 22px 20px; }
.x { background: none; border: 0; font-size: 24px; line-height: 1; cursor: pointer; color: var(--muted); padding: 2px 8px; border-radius: 8px; }
.x:hover { background: var(--surface-2); }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { transform: translateY(8px) scale(.98); opacity: 0; } }
.task-title-input { font-size: 20px; font-weight: 700; border: 1px solid transparent; padding: 6px 8px; margin-left: -8px; width: calc(100% + 8px); border-radius: 8px; background: transparent; }
.task-title-input:hover { border-color: var(--border); }
.task-title-input:focus { border-color: var(--primary); outline: none; background: #fff; }
.task-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; margin: 12px 0 4px; }
.comments { margin-top: 18px; border-top: 1px solid var(--border); padding-top: 14px; }
.comment { display: flex; gap: 10px; margin-bottom: 14px; }
.comment .bubble { background: var(--surface-2); padding: 8px 12px; border-radius: 4px 12px 12px 12px; flex: 1; min-width: 0; }
.comment .bubble .h { font-size: 13px; display: flex; gap: 8px; align-items: center; }
.comment .bubble .b { white-space: pre-wrap; word-break: break-word; margin-top: 2px; }
.comment .del { margin-left: auto; background: none; border: 0; color: var(--muted); cursor: pointer; font-size: 12px; }
.comment .del:hover { color: var(--danger); }
.checklist { max-height: 220px; overflow-y: auto; border: 1px solid var(--border); border-radius: 9px; padding: 6px; }
.checklist label { display: flex; align-items: center; gap: 10px; padding: 6px 8px; border-radius: 6px; cursor: pointer; }
.checklist label:hover { background: var(--surface-2); }
.swatches { display: flex; gap: 8px; flex-wrap: wrap; }
.swatch { width: 26px; height: 26px; border-radius: 8px; border: 2px solid transparent; cursor: pointer; padding: 0; }
.swatch.on { border-color: var(--text); box-shadow: inset 0 0 0 2px #fff; }

/* ---------- Toast */
#toast-root { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 100; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast { background: var(--navy); color: #fff; padding: 10px 16px; border-radius: 10px; box-shadow: var(--shadow); font-size: 14px; animation: pop .15s; }
.toast.error { background: var(--danger); }

.tabs { display: flex; gap: 4px; background: var(--surface-2); padding: 4px; border-radius: 10px; border: 1px solid var(--border); }
.tabs button { border: 0; background: transparent; padding: 6px 12px; border-radius: 7px; cursor: pointer; font-size: 14px; color: var(--muted); font-weight: 500; }
.tabs button.on { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgba(0, 0, 0, .08); }
.search { max-width: 260px; }

/* ---------- Responsive */
@media (max-width: 1100px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
  .grid-2 { grid-template-columns: 1fr; }
}
@media (max-width: 820px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: 0; top: 0; bottom: 0; width: 270px; z-index: 40; transform: translateX(-100%); transition: transform .2s; }
  .layout.nav-open .sidebar { transform: none; box-shadow: 0 0 0 100vmax rgba(0, 0, 0, .35); }
  .topbar { display: flex; align-items: center; gap: 10px; padding: 12px 16px; background: var(--navy); color: #fff; position: sticky; top: 0; z-index: 30; }
  .topbar button { background: none; border: 0; color: #fff; font-size: 22px; cursor: pointer; padding: 0 4px; }
  .main { padding: 18px 14px 60px; }
  .page-head h1 { font-size: 22px; }
  .board { grid-template-columns: repeat(4, 82vw); scroll-snap-type: x mandatory; }
  .col { scroll-snap-align: start; }
  .task-grid { grid-template-columns: 1fr; }
  .meta .tag.proj { display: none; }
  .search { max-width: none; }
  .page-head .actions { margin-left: 0; width: 100%; }
  .page-head .actions .input { flex: 1; min-width: 0; }
  .feed li { word-break: break-word; }
}
