:root {
  --bg: #fafafa;
  --surface: #ffffff;
  --surface-2: #f4f4f5;
  --surface-3: #ebebed;
  --border: #e4e4e7;
  --border-2: #d4d4d8;
  --text: #18181b;
  --text-2: #52525b;
  --text-3: #8f8f99;
  --accent: #16694a;
  --accent-soft: #e8f3ee;
  --danger: #b4291f;
  --danger-soft: #fdecea;
  --warn: #9a5b00;
  --warn-soft: #fdf3e3;
  --info: #1d4ed8;
  --info-soft: #eef2fd;
  --radius: 6px;
  --shadow: 0 1px 2px rgba(24, 24, 27, .06), 0 1px 3px rgba(24, 24, 27, .04);
  --shadow-lg: 0 8px 24px rgba(24, 24, 27, .12);
  --topbar-h: 52px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 13px/1.45 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }

/* ---------- top bar ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 0 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.brand { display: flex; align-items: baseline; gap: 7px; }
.brand b { font-size: 14px; font-weight: 600; letter-spacing: -.01em; }
.brand span { font-size: 11px; color: var(--text-3); }

.tabs { display: flex; gap: 2px; }
.tabs button {
  border: 0;
  background: none;
  padding: 6px 10px;
  border-radius: var(--radius);
  color: var(--text-2);
  cursor: pointer;
}
.tabs button:hover { background: var(--surface-2); color: var(--text); }
.tabs button.on {
  background: var(--surface-2);
  color: var(--text);
  font-weight: 600;
  box-shadow: inset 0 0 0 1px var(--border-2), inset 0 -2px 0 var(--accent);
}

.spacer { flex: 1; }

.search {
  width: 220px;
  padding: 6px 10px;
  border: 1px solid var(--border-2);
  border-radius: var(--radius);
  background: var(--surface);
}
.search:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }

.btn {
  border: 1px solid var(--border-2);
  background: var(--surface);
  padding: 6px 12px;
  border-radius: var(--radius);
  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 { background: #125a3f; }
.btn.quiet { border-color: transparent; background: none; color: var(--text-2); }
.btn.quiet:hover { background: var(--surface-2); color: var(--text); }
.btn.danger { color: var(--danger); border-color: var(--border-2); }
.btn.danger:hover { background: var(--danger-soft); border-color: #f3c3bf; }
.btn.sm { padding: 3px 8px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: default; }

/* ---------- toolbar ---------- */

.toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: nowrap;
  padding: 8px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
/* Department chips get their own scrolling rail so the controls never wrap to a second row. */
.rail {
  display: flex;
  gap: 8px;
  flex: 1 1 auto;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: thin;
  padding-bottom: 1px;
}
.rail::-webkit-scrollbar { height: 6px; }
.rail::-webkit-scrollbar-thumb { background: var(--border-2); border-radius: 3px; }
/* Chips must not shrink, or long department names wrap inside the pill. */
.rail > * { flex: 0 0 auto; white-space: nowrap; }
.toolbar .fixed { display: flex; align-items: center; gap: 8px; flex: 0 0 auto; }
/* Toolbars that carry an explanatory line wrap instead of scrolling. */
.toolbar.wrap { flex-wrap: wrap; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 9px;
  border: 1px solid var(--border-2);
  border-radius: 999px;
  background: var(--surface);
  cursor: pointer;
  color: var(--text-2);
  font-size: 12px;
}
.chip:hover { background: var(--surface-2); }
.chip.on { background: var(--text); border-color: var(--text); color: #fff; }
.chip .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.chip.on .dot { background: #fff; opacity: .85; }

select.plain {
  padding: 5px 8px;
  border: 1px solid var(--border-2);
  border-radius: var(--radius);
  background: var(--surface);
}

.count { color: var(--text-3); font-size: 12px; white-space: nowrap; }

/* ---------- table ---------- */

.tablewrap { padding: 0 0 60px; }
table.grid {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
}
.grid th {
  position: sticky;
  top: var(--topbar-h);
  z-index: 10;
  text-align: left;
  font-weight: 500;
  font-size: 11px;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--text-3);
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  padding: 8px 12px;
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}
.grid th:hover { color: var(--text-2); }
.grid td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.grid tbody tr { cursor: pointer; }
.grid tbody tr:hover { background: var(--surface-2); }
.grid tbody tr.active { background: var(--accent-soft); box-shadow: inset 3px 0 0 var(--accent); }
.grid tbody tr.done .title { color: var(--text-3); text-decoration: line-through; }
.grid td.title { font-weight: 500; max-width: 380px; }
.grid td.title .sub { display: block; font-weight: 400; color: var(--text-3); font-size: 12px; }
.grid td.nowrap { white-space: nowrap; }
.grid td.right { text-align: right; }

/* ---------- bits ---------- */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 7px;
  border-radius: 999px;
  font-size: 12px;
  line-height: 18px;
  background: var(--surface-2);
  color: var(--text-2);
  white-space: nowrap;
}
.badge .dot { width: 6px; height: 6px; border-radius: 50%; }
.badge.outline { background: none; border: 1px solid var(--border-2); }

.pill { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; line-height: 18px; }
.pill .dot { width: 6px; height: 6px; border-radius: 50%; }

.status-Todo { color: var(--text-2); }
.status-Progress { color: var(--info); }
.status-Blocked { color: var(--warn); }
.status-Done { color: var(--accent); }

.due { color: var(--text-2); font-size: 12px; white-space: nowrap; }
.due.soon { color: var(--warn); }
.due.over { color: var(--danger); font-weight: 500; }
.muted { color: var(--text-3); }
.mono { font-variant-numeric: tabular-nums; }

.empty {
  padding: 48px 16px;
  text-align: center;
  color: var(--text-3);
}

.checklist { list-style: none; margin: 0; padding: 0; }
.checklist li { display: flex; align-items: flex-start; gap: 8px; padding: 4px 0; }
.checklist li.done span { color: var(--text-3); text-decoration: line-through; }
.checklist input[type=checkbox] { margin-top: 2px; accent-color: var(--accent); }
input[type=checkbox] { accent-color: var(--accent); }

.trail { list-style: none; margin: 0; padding: 0; }
.trail li { padding: 7px 0 7px 14px; border-left: 1px solid var(--border-2); position: relative; }
.trail li::before {
  content: "";
  position: absolute;
  left: -3.5px;
  top: 13px;
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--border-2);
}
.trail li:first-child::before { background: var(--accent); }
.trail .meta { color: var(--text-3); font-size: 12px; }

/* ---------- board ---------- */

.board {
  display: flex;
  gap: 12px;
  padding: 16px;
  overflow-x: auto;
  align-items: flex-start;
  min-height: calc(100vh - var(--topbar-h) - 90px);
}
.col {
  flex: 0 0 272px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 140px);
}
.col.dragover { border-color: var(--accent); background: var(--accent-soft); }
.col header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 11px;
  border-bottom: 1px solid var(--border);
}
.col header b { font-weight: 500; }
.col header .n { color: var(--text-3); font-size: 12px; }
.col .cards { overflow-y: auto; padding: 8px; display: flex; flex-direction: column; gap: 7px; }
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--border-2);
  border-radius: var(--radius);
  padding: 9px 10px;
  box-shadow: var(--shadow);
  cursor: grab;
}
.card:hover { border-color: var(--border-2); }
.card .t { font-weight: 500; margin-bottom: 6px; }
.card .row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.card .sub { font-size: 11px; color: var(--text-3); }
.col .add { padding: 6px 10px 10px; }

/* ---------- drawer + modal ---------- */

.scrim {
  position: fixed;
  inset: 0;
  background: rgba(24, 24, 27, .35);
  z-index: 40;
}
.drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(460px, 100vw);
  background: var(--surface);
  border-left: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  z-index: 50;
  display: flex;
  flex-direction: column;
}
.drawer .head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}
.drawer .body { padding: 14px 14px 34px; overflow-y: auto; flex: 1; }
.drawer .foot {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 14px;
  border-top: 1px solid var(--border);
  background: var(--surface);
}
.drawer h2 { font-size: 15px; margin: 0; font-weight: 600; }

.field { margin-bottom: 12px; }
.field label {
  display: block;
  font-size: 11px;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--text-2);
  margin-bottom: 4px;
}
.field input[type=text], .field input[type=date], .field select, .field textarea {
  width: 100%;
  padding: 7px 9px;
  border: 1px solid var(--border-2);
  border-radius: var(--radius);
  background: var(--surface);
}
.field textarea { resize: vertical; min-height: 60px; }
.field input:focus, .field select:focus, .field textarea:focus {
  outline: 2px solid var(--accent-soft);
  border-color: var(--accent);
}
.field.inline { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.field.inline label { margin: 0; width: 92px; flex: 0 0 92px; }
.field.inline input, .field.inline select { flex: 1; }

.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.three { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; }

.modal {
  position: fixed;
  top: 10vh;
  left: 50%;
  transform: translateX(-50%);
  width: min(520px, calc(100vw - 32px));
  max-height: 80vh;
  overflow-y: auto;
  background: var(--surface);
  border-radius: 10px;
  box-shadow: var(--shadow-lg);
  z-index: 60;
}
.modal .head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 13px 16px;
  border-bottom: 1px solid var(--border);
}
.modal .head b { font-weight: 600; }
.modal .body { padding: 16px; }
.modal .foot {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
}

.deptpick { max-height: 260px; overflow-y: auto; border: 1px solid var(--border); border-radius: var(--radius); }
.deptpick .group { padding: 6px 10px; background: var(--surface-2); font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--text-3); }
.deptpick button {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  text-align: left;
  border: 0;
  background: none;
  padding: 7px 10px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}
.deptpick button:hover { background: var(--surface-2); }
.deptpick button.on { background: var(--accent-soft); }
.deptpick .hint { margin-left: auto; font-size: 11px; color: var(--text-3); }

.toast {
  position: fixed;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: #fff;
  padding: 8px 14px;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  z-index: 80;
  max-width: 80vw;
}
.toast.err { background: var(--danger); }

@media (max-width: 720px) {
  .search { width: 130px; }
  .topbar { gap: 10px; padding: 0 10px; overflow-x: auto; }
  .grid td.col-hide, .grid th.col-hide { display: none; }
}

/* ---------- sign-in gate ---------- */

.who { color: var(--text-2); font-size: 12px; white-space: nowrap; }

.btn.wide { width: 100%; display: flex; justify-content: center; align-items: center; }

.authgate {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
}
/* display:flex above outranks the UA's [hidden] rule — restore the switch. */
.authgate[hidden] { display: none; }

.authcard {
  width: min(340px, calc(100vw - 32px));
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow-lg);
  padding: 22px 20px 16px;
}

.authcard .logo {
  width: 40px;
  height: 40px;
  border-radius: 9px;
  background: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 12px;
}

.authcard h1 { font-size: 15px; margin: 0 0 2px; font-weight: 600; }
.authcard .sub { color: var(--text-3); font-size: 12px; margin: 0 0 16px; }
.authcard input {
  width: 100%;
  padding: 7px 9px;
  border: 1px solid var(--border-2);
  border-radius: var(--radius);
  background: var(--surface);
}
.authcard input:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.autherr { color: var(--danger); font-size: 12px; min-height: 16px; margin: 2px 0 8px; }
.authcard .foot { color: var(--text-3); font-size: 11px; margin: 12px 0 0; text-align: center; }
