:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f1f3f6;
  --border: #e3e6eb;
  --text: #1a1d23;
  --muted: #646b78;
  --accent: #4f46e5;
  --accent-soft: #eef0ff;
  --danger: #dc2626;
  --danger-soft: #fdecec;
  --warn: #b45309;
  --warn-soft: #fef3e2;
  --ok: #15803d;
  --ok-soft: #e7f6ec;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --shadow-lg: 0 12px 32px rgba(16, 24, 40, .18);
  --radius: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --surface: #171a20;
    --surface-2: #1e222a;
    --border: #2a2f39;
    --text: #e7e9ee;
    --muted: #9aa1ae;
    --accent: #8b85ff;
    --accent-soft: #24233f;
    --danger: #f87171;
    --danger-soft: #3a1d1f;
    --warn: #fbbf24;
    --warn-soft: #3a2e14;
    --ok: #4ade80;
    --ok-soft: #16301f;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow-lg: 0 12px 32px rgba(0, 0, 0, .5);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
h1 { font-size: 22px; margin: 0; letter-spacing: -.01em; }
h2 { font-size: 15px; margin: 0 0 12px; }
h3 { font-size: 14px; margin: 0; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.error { color: var(--danger); margin: 0; }

/* ---------- buttons & inputs ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 34px; padding: 0 14px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: inherit; font-weight: 500; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--danger); }
.btn.danger:hover { background: var(--danger-soft); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.small { height: 28px; padding: 0 10px; font-size: 13px; }
.btn.icon { width: 34px; padding: 0; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .6; cursor: default; }

label { display: grid; gap: 4px; font-size: 13px; font-weight: 500; color: var(--muted); }
input, select, textarea {
  width: 100%; font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 8px; padding: 7px 10px; min-height: 34px;
}
textarea { resize: vertical; min-height: 90px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
input[type="color"] { padding: 2px; height: 34px; cursor: pointer; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-grid .full { grid-column: 1 / -1; }

/* ---------- login ---------- */
.login { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: 100%; max-width: 360px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 14px; padding: 28px; display: grid; gap: 14px; box-shadow: var(--shadow);
}
.login-card p { margin: 0; }

/* ---------- layout ---------- */
.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; font-size: 15px; }
.brand-lg { font-size: 18px; }
.logo {
  width: 28px; height: 28px; border-radius: 8px; background: var(--accent); color: #fff;
  display: grid; place-items: center; font-weight: 700; font-size: 14px; flex: none;
}
.app { display: flex; min-height: 100%; }
.sidebar {
  width: 220px; flex: none; background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 18px 12px; position: sticky; top: 0; height: 100vh;
}
.sidebar .brand { padding: 0 8px 18px; }
.sidebar nav { display: grid; gap: 2px; }
.sidebar nav a, .sidebar .me {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; color: var(--text); font-weight: 500;
}
.sidebar nav a:hover, .sidebar .me:hover { background: var(--surface-2); }
.sidebar a.active { background: var(--accent-soft); color: var(--accent); }
.sidebar-foot { margin-top: auto; display: grid; gap: 6px; border-top: 1px solid var(--border); padding-top: 12px; }
.main-wrap { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { display: none; }
.view { padding: 28px 32px 48px; max-width: 1400px; width: 100%; }

.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 22px; flex-wrap: wrap; }
.page-head .sub { margin: 2px 0 0; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.toolbar input, .toolbar select { width: auto; min-width: 140px; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.grid { display: grid; gap: 16px; }
.cols-2 { grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); }

/* ---------- stats ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { padding: 16px 18px; }
.stat .num { font-size: 26px; font-weight: 650; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.stat .lbl { color: var(--muted); font-size: 13px; }
.stat.alert .num { color: var(--danger); }

/* ---------- lists ---------- */
.list { display: grid; }
.row {
  display: flex; align-items: center; gap: 12px; padding: 10px 4px; border-bottom: 1px solid var(--border); cursor: pointer;
}
.row:last-child { border-bottom: 0; }
a.row { color: inherit; }
.row:hover { background: var(--surface-2); }
.row .grow { flex: 1; min-width: 0; }
.row .title { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.empty { color: var(--muted); padding: 18px 4px; text-align: center; }

.dot { width: 10px; height: 10px; border-radius: 3px; flex: none; display: inline-block; }
.avatar {
  width: 26px; height: 26px; border-radius: 50%; display: inline-grid; place-items: center; flex: none;
  background: var(--accent-soft); color: var(--accent); font-size: 11px; font-weight: 650;
}
.avatar.empty-av { background: var(--surface-2); color: var(--muted); }

.pill { display: inline-flex; align-items: center; height: 22px; padding: 0 8px; border-radius: 999px; font-size: 12px; font-weight: 500; white-space: nowrap; background: var(--surface-2); color: var(--muted); }
.pill.urgent { background: var(--danger-soft); color: var(--danger); }
.pill.high { background: var(--warn-soft); color: var(--warn); }
.pill.medium { background: var(--accent-soft); color: var(--accent); }
.pill.overdue { background: var(--danger-soft); color: var(--danger); }
.pill.done, .pill.completed { background: var(--ok-soft); color: var(--ok); }
.pill.in_progress { background: var(--accent-soft); color: var(--accent); }
.pill.review { background: var(--warn-soft); color: var(--warn); }
.pill.on_hold { background: var(--warn-soft); color: var(--warn); }
.pill.active { background: var(--accent-soft); color: var(--accent); }

.progress { height: 6px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--accent); border-radius: 999px; }

/* ---------- projects ---------- */
.project-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 14px; }
.project-card { display: grid; gap: 12px; cursor: pointer; border-top: 4px solid var(--c, var(--accent)); color: inherit; }
.project-card:hover { box-shadow: var(--shadow-lg); }
.project-card .meta { display: flex; justify-content: space-between; gap: 8px; color: var(--muted); font-size: 13px; }
.project-card p { margin: 0; color: var(--muted); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; min-height: 2.6em; }

/* ---------- board ---------- */
.board { display: grid; grid-template-columns: repeat(4, minmax(240px, 1fr)); gap: 14px; overflow-x: auto; padding-bottom: 8px; align-items: start; }
.column { background: var(--surface-2); border-radius: var(--radius); padding: 10px; min-height: 200px; display: flex; flex-direction: column; gap: 8px; }
.column.drag-over { outline: 2px dashed var(--accent); outline-offset: -2px; }
.column-head { display: flex; justify-content: space-between; align-items: center; padding: 2px 4px 4px; font-weight: 600; font-size: 13px; }
.column-head .count { color: var(--muted); font-weight: 500; }
.task-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; cursor: pointer;
  display: grid; gap: 8px; box-shadow: var(--shadow);
}
.task-card:hover { border-color: var(--accent); }
.task-card.dragging { opacity: .4; }
.task-card .t { font-weight: 500; word-break: break-word; }
.task-card .foot { display: flex; align-items: center; justify-content: space-between; gap: 6px; flex-wrap: wrap; }
.task-card .foot .left { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.add-task { justify-content: flex-start; color: var(--muted); }

.project-head { display: flex; gap: 14px; align-items: flex-start; }
.project-head .swatch { width: 14px; height: 14px; border-radius: 4px; margin-top: 7px; flex: none; }
.project-meta { display: flex; gap: 16px; flex-wrap: wrap; color: var(--muted); font-size: 13px; margin-top: 4px; }
.desc { white-space: pre-wrap; margin: 0 0 18px; color: var(--muted); max-width: 80ch; }

/* ---------- activity ---------- */
.activity { display: grid; gap: 12px; }
.activity .item { display: flex; gap: 10px; font-size: 13px; }
.activity .item b { font-weight: 600; }

/* ---------- workload ---------- */
.workload { display: grid; gap: 12px; }
.wl-row { display: grid; grid-template-columns: 130px 1fr; gap: 10px; align-items: center; font-size: 13px; }
.wl-bar { display: flex; height: 18px; border-radius: 5px; overflow: hidden; background: var(--surface-2); gap: 2px; }
.wl-bar span { display: block; height: 100%; }
.wl-legend { display: flex; gap: 14px; font-size: 12px; color: var(--muted); flex-wrap: wrap; }
.wl-legend i { display: inline-block; width: 9px; height: 9px; border-radius: 2px; margin-right: 5px; }
.s-todo { background: #94a3b8; }
.s-in_progress { background: #4f46e5; }
.s-review { background: #d97706; }
.s-done { background: #16a34a; }

/* ---------- table ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
tbody tr { cursor: pointer; }
tbody tr:hover { background: var(--surface-2); }
td.wrap { white-space: normal; min-width: 200px; }

/* ---------- modal ---------- */
.overlay {
  position: fixed; inset: 0; background: rgba(10, 12, 16, .5); display: flex; align-items: flex-start; justify-content: center;
  padding: 6vh 16px 16px; z-index: 50; overflow-y: auto;
}
.modal {
  background: var(--surface); border-radius: 14px; width: 100%; max-width: 560px; box-shadow: var(--shadow-lg);
  border: 1px solid var(--border);
}
.modal.wide { max-width: 860px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal-body { padding: 20px; display: grid; gap: 14px; }
.modal-foot { display: flex; justify-content: space-between; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--border); }
.modal-foot .right { display: flex; gap: 8px; margin-left: auto; }
.task-layout { display: grid; grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); gap: 20px; }
.comments { display: grid; gap: 12px; align-content: start; }
.comment { display: flex; gap: 10px; }
.comment .bubble { background: var(--surface-2); border-radius: 8px; padding: 8px 10px; flex: 1; min-width: 0; }
.comment .bubble p { margin: 2px 0 0; white-space: pre-wrap; word-break: break-word; }
.comment .del { visibility: hidden; }
.comment:hover .del { visibility: visible; }

/* ---------- toast ---------- */
.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg);
  padding: 10px 16px; border-radius: 8px; font-weight: 500; z-index: 100; box-shadow: var(--shadow-lg); max-width: calc(100% - 32px);
}
.toast.err { background: var(--danger); color: #fff; }

/* ---------- responsive ---------- */
@media (max-width: 900px) {
  .cols-2, .task-layout { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
  .sidebar {
    position: fixed; left: 0; top: 0; z-index: 40; transform: translateX(-100%); transition: transform .2s;
  }
  .sidebar.open { transform: none; box-shadow: var(--shadow-lg); }
  .topbar {
    display: flex; align-items: center; gap: 8px; padding: 10px 16px; background: var(--surface);
    border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 30;
  }
  .view { padding: 18px 16px 40px; }
  .form-grid { grid-template-columns: 1fr; }
  .board { grid-template-columns: repeat(4, 82vw); scroll-snap-type: x mandatory; }
  .column { scroll-snap-align: start; }
  .toolbar input, .toolbar select { min-width: 0; flex: 1; }
  .wl-row { grid-template-columns: 90px 1fr; }
}
