:root {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --column: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --border: #cbd5e1;
  --primary: #6366f1;
  --primary-text: #ffffff;
  --danger: #dc2626;
  --warn: #d97706;
  --ok: #16a34a;
  --shadow: 0 1px 2px rgba(15, 23, 42, .08), 0 1px 3px rgba(15, 23, 42, .06);
  --radius: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1120;
    --surface: #1e293b;
    --column: #111827;
    --text: #e2e8f0;
    --muted: #94a3b8;
    --border: #334155;
    --primary: #818cf8;
    --primary-text: #0b1120;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
}
button, input, select, textarea { font: inherit; color: inherit; }
input, select, textarea {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 10px;
  width: 100%;
}
textarea { resize: vertical; min-height: 80px; }
input[type=checkbox] { width: auto; }
input[type=color] { padding: 2px; height: 36px; }

.btn {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 8px;
  padding: 7px 12px;
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
  white-space: nowrap;
}
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-text); font-weight: 600; }
.btn.danger { color: var(--danger); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover { color: var(--text); }
.muted { color: var(--muted); }
.error { color: var(--danger); }

/* ---------- topo ---------- */
.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; white-space: nowrap; }
.tabs { display: flex; gap: 4px; background: var(--bg); padding: 3px; border-radius: 9px; }
.tabs button {
  border: 0; background: transparent; padding: 6px 12px; border-radius: 7px; cursor: pointer; color: var(--muted);
}
.tabs button.active { background: var(--surface); color: var(--text); font-weight: 600; box-shadow: var(--shadow); }
.top-actions { margin-left: auto; display: flex; align-items: center; gap: 4px; }
.avatar {
  --c: #6366f1;
  width: 26px; height: 26px; border-radius: 50%;
  background: var(--c); color: #fff; border: 0;
  font-size: 12px; font-weight: 700;
  display: inline-flex; align-items: center; justify-content: center;
  flex: none;
}
button.avatar { width: 32px; height: 32px; cursor: pointer; }
.me-menu { position: relative; }
.dropdown {
  position: absolute; right: 0; top: 40px; z-index: 20;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  box-shadow: var(--shadow); min-width: 170px; padding: 4px;
}
.dropdown-head { padding: 8px 10px; font-weight: 600; border-bottom: 1px solid var(--border); margin-bottom: 4px; }
.dropdown button, .dropdown a {
  display: block; width: 100%; text-align: left; padding: 8px 10px; border: 0; background: none;
  border-radius: 6px; cursor: pointer; color: var(--text); text-decoration: none;
}
.dropdown button:hover, .dropdown a:hover { background: var(--bg); }

/* ---------- filtros ---------- */
.filters {
  display: flex; gap: 8px; align-items: center; flex-wrap: wrap;
  padding: 10px 16px;
}
.filters input[type=search] { max-width: 220px; }
.filters select { width: auto; max-width: 200px; }
.chk { display: inline-flex; gap: 6px; align-items: center; white-space: nowrap; color: var(--muted); }

/* ---------- quadro ---------- */
.board {
  flex: 1;
  display: flex; gap: 12px; align-items: flex-start;
  padding: 0 16px 16px;
  overflow-x: auto;
  scroll-snap-type: x proximity;
}
.column {
  flex: 0 0 280px;
  background: var(--column);
  border-radius: var(--radius);
  display: flex; flex-direction: column;
  max-height: 100%;
  scroll-snap-align: start;
}
.column-head {
  display: flex; align-items: center; gap: 6px;
  padding: 10px 12px 6px;
  font-weight: 600;
  cursor: grab;
}
.column-head .count { color: var(--muted); font-weight: 500; font-size: 12px; }
.column-head .role { font-size: 11px; color: var(--muted); font-weight: 500; }
.column-head .col-menu { margin-left: auto; border: 0; background: none; cursor: pointer; color: var(--muted); padding: 2px 6px; font-size: 16px; }
.cards { padding: 4px 8px; display: flex; flex-direction: column; gap: 8px; overflow-y: auto; min-height: 30px; }
.add-card { margin: 4px 8px 10px; text-align: left; color: var(--muted); background: transparent; border: 0; padding: 8px; border-radius: 8px; cursor: pointer; }
.add-card:hover { background: var(--surface); color: var(--text); }
.add-column { flex: 0 0 200px; }

.card {
  background: var(--surface);
  border-radius: 8px;
  padding: 10px;
  box-shadow: var(--shadow);
  cursor: pointer;
  border-left: 3px solid transparent;
}
.card.prio-alta { border-left-color: var(--warn); }
.card.prio-urgente { border-left-color: var(--danger); }
.card-code {
  display: inline-block; font-size: 11px; font-weight: 700; letter-spacing: .02em;
  padding: 1px 7px; border-radius: 999px; margin-bottom: 6px;
  background: var(--chip, #64748b); color: #fff;
}
.card-title { word-wrap: break-word; }
.card-meta { display: flex; align-items: center; gap: 8px; margin-top: 8px; font-size: 12px; color: var(--muted); flex-wrap: wrap; }
.card-meta .avatar { margin-left: auto; width: 22px; height: 22px; font-size: 11px; }
.due.overdue { color: var(--danger); font-weight: 600; }
.due.today { color: var(--warn); font-weight: 600; }
.sortable-ghost { opacity: .4; }
.sortable-drag { transform: rotate(2deg); }

/* ---------- modal ---------- */
dialog {
  border: 0; padding: 0; border-radius: 14px;
  width: min(640px, calc(100vw - 24px));
  max-height: calc(100vh - 40px);
  background: var(--surface); color: var(--text);
  box-shadow: 0 20px 50px rgba(0, 0, 0, .3);
}
dialog::backdrop { background: rgba(15, 23, 42, .55); }
.modal-body { padding: 20px; display: flex; flex-direction: column; gap: 14px; }
.modal-body h2 { margin: 0; font-size: 18px; }
.modal-head { display: flex; align-items: center; gap: 8px; }
.modal-head .close { margin-left: auto; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
label > input, label > select, label > textarea { color: var(--text); font-size: 14px; }
.title-input { font-size: 17px; font-weight: 600; }
.section-title { font-weight: 600; font-size: 13px; margin-top: 4px; }
.checklist { display: flex; flex-direction: column; gap: 4px; }
.check-item { display: flex; align-items: center; gap: 8px; }
.check-item span { flex: 1; }
.check-item.done span { text-decoration: line-through; color: var(--muted); }
.check-item .x { border: 0; background: none; color: var(--muted); cursor: pointer; }
.inline-add { display: flex; gap: 6px; }
.comments { display: flex; flex-direction: column; gap: 10px; }
.comment { display: flex; gap: 8px; }
.comment .bubble { background: var(--bg); border-radius: 10px; padding: 8px 10px; flex: 1; white-space: pre-wrap; word-wrap: break-word; }
.comment .who { font-size: 12px; color: var(--muted); margin-bottom: 2px; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
.modal-actions .left { margin-right: auto; }
.list-row { display: flex; align-items: center; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--border); }
.list-row:last-child { border-bottom: 0; }
.list-row .grow { flex: 1; min-width: 0; }
.dot { width: 12px; height: 12px; border-radius: 50%; flex: none; }
.tag { font-size: 11px; padding: 1px 7px; border-radius: 999px; background: var(--bg); color: var(--muted); }

.toast {
  position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%);
  background: var(--text); color: var(--bg);
  padding: 10px 16px; border-radius: 10px; z-index: 100; max-width: calc(100vw - 32px);
}

/* ---------- ficha do canal ---------- */
dialog.wide { width: min(1000px, calc(100vw - 24px)); }
.chk { flex-direction: row; }
.btn.small { padding: 3px 8px; font-size: 12px; }
.small { font-size: 12px; }
.ficha-btn { text-align: left; white-space: normal; }
.ficha-tag { display: inline-block; margin: 0 0 6px 4px; }
.card-progress { display: flex; align-items: center; gap: 8px; margin-top: 8px; font-size: 12px; color: var(--muted); }
.card-progress .bar { flex: 1; height: 6px; background: var(--bg); border-radius: 999px; overflow: hidden; }
.card-progress .bar span { display: block; height: 100%; background: var(--ok); border-radius: 999px; transition: width .3s; }
.card-progress.big { font-size: 14px; color: var(--text); margin: 0; }
.card-progress.big .bar { height: 10px; }
.dossier-tools { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.dossier { display: flex; flex-direction: column; gap: 8px; }
.dsec { border: 1px solid var(--border); border-radius: 10px; background: var(--surface); }
.dsec > summary {
  display: flex; align-items: center; gap: 8px; padding: 10px 12px; cursor: pointer; font-weight: 600; list-style: none;
  position: sticky; top: -20px; background: var(--surface); border-radius: 10px; z-index: 1;
}
.dsec > summary::-webkit-details-marker { display: none; }
.dsec > summary::before { content: '▸'; color: var(--muted); transition: transform .15s; }
.dsec[open] > summary::before { transform: rotate(90deg); }
.sec-title { flex: 1; }
.sec-count { font-size: 12px; color: var(--muted); font-weight: 600; background: var(--bg); padding: 2px 8px; border-radius: 999px; }
.sec-count.complete { background: var(--ok); color: #fff; }
.sec-intro { margin: 0 12px 4px; white-space: pre-wrap; }
.sec-actions { display: flex; gap: 4px; justify-content: flex-end; padding: 0 8px; }
.ditem { border-top: 1px solid var(--border); padding: 10px 12px; display: flex; flex-direction: column; gap: 6px; border-left: 3px solid transparent; }
.ditem.done { border-left-color: var(--ok); }
.ditem.na { opacity: .6; }
.ditem.weak textarea { border-color: var(--warn); }
.ditem.flash { animation: flash 1.6s ease-out; }
@keyframes flash { from { background: color-mix(in srgb, var(--primary) 25%, transparent); } to { background: transparent; } }
.ditem-head { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.icode { font-weight: 700; font-size: 12px; color: var(--primary); min-width: 32px; }
.iq { font-size: 13px; }
.ditem textarea { min-height: 38px; overflow: hidden; }
.ditem-foot { display: flex; align-items: center; gap: 4px; }
.ditem-foot .muted { margin-right: auto; }
.task-form { display: flex; gap: 8px; align-items: flex-end; flex-wrap: wrap; }
.task-form label { flex: 1; min-width: 140px; }
.task-form[hidden] { display: none; }
.task-links { display: flex; flex-direction: column; gap: 4px; }
.task-link {
  display: flex; align-items: center; gap: 8px; text-align: left; border: 1px dashed var(--border);
  background: transparent; border-radius: 8px; padding: 5px 8px; cursor: pointer; font-size: 12px;
}
.task-link .avatar { width: 20px; height: 20px; font-size: 10px; }
.only-pending .ditem.done { display: none; }
.only-pending .dsec:has(.sec-count.complete) { display: none; }

.stage {
  display: flex; flex-direction: column; gap: 10px;
  background: var(--bg); border-radius: 12px; padding: 12px;
}
.card-details { display: flex; flex-direction: column; gap: 14px; }
details.card-details > summary { cursor: pointer; font-weight: 600; font-size: 13px; color: var(--muted); }
details.card-details[open] > summary { margin-bottom: 4px; }
.sec-picker { display: flex; flex-direction: column; gap: 6px; max-height: 300px; overflow-y: auto; }
.sec-picker .chk { color: var(--text); font-size: 13px; }
.column-head > span:first-child { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.column-head { flex-wrap: wrap; }

/* ---------- login/setup ---------- */
.auth-page { align-items: center; justify-content: center; padding: 16px; }
.auth-box {
  background: var(--surface); padding: 28px; border-radius: 14px; box-shadow: var(--shadow);
  width: min(360px, 100%); display: flex; flex-direction: column; gap: 14px;
}
.auth-box.wide { width: min(640px, 100%); }
.auth-box h1 { margin: 0; font-size: 20px; }
.setup-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
fieldset { border: 1px solid var(--border); border-radius: 10px; display: flex; flex-direction: column; gap: 10px; }

/* ---------- celular ---------- */
@media (max-width: 640px) {
  .topbar { flex-wrap: wrap; padding: 8px 12px; }
  .brand { display: none; }
  .filters { padding: 8px 12px; }
  .filters input[type=search] { max-width: none; flex: 1 1 100%; }
  .filters select { flex: 1; max-width: none; }
  .board { padding: 0 12px 12px; scroll-snap-type: x mandatory; }
  .column { flex-basis: 85vw; }
  .grid2, .setup-grid { grid-template-columns: 1fr; }
}
