/* ---------- Reset / variáveis (tema claro como default) ---------- */
:root {
  --bg: #f6f7fb;
  --bg-elev: #ffffff;
  --panel: #ffffff;
  --panel-2: #f2f3f8;
  --input-bg: #ffffff;
  --border: #e3e6ee;
  --text: #1a1d24;
  --muted: #6b7280;
  --primary: #4f46e5;
  --primary-2: #4338ca;
  --primary-soft: rgba(79, 70, 229, .08);
  --ok: #16a34a;
  --warn: #f59e0b;
  --warn-text: #1f2937;
  --danger: #dc2626;
  --shadow: 0 4px 14px rgba(15, 23, 42, .08);
  --topbar-bg: rgba(246, 247, 251, .85);
  --history-item-bg: #f2f3f8;
  --ai-user-bg: #eef2ff;
  --ai-bot-bg: #f5f3ff;
  --ai-bot-border: #c4b5fd;
  --priority-low-bg:    #d1fae5; --priority-low-text:    #047857;
  --priority-medium-bg: #dbeafe; --priority-medium-text: #1e40af;
  --priority-high-bg:   #fee2e2; --priority-high-text:   #b91c1c;
  --role-admin-bg:  #fed7aa; --role-admin-text:  #7c2d12;
  --role-member-bg: #dbeafe; --role-member-text: #1e40af;
  --radius: 12px;
}

/* Tema escuro explícito (clicou no toggle e escolheu dark) */
:root[data-theme="dark"] {
  --bg: #0b1224;
  --bg-elev: #0f172a;
  --panel: #111c33;
  --panel-2: #182645;
  --input-bg: #0c1530;
  --border: #1f2d50;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --primary: #6366f1;
  --primary-2: #4f46e5;
  --primary-soft: rgba(99, 102, 241, .12);
  --ok: #16a34a;
  --warn: #f59e0b;
  --warn-text: #1f2937;
  --danger: #ef4444;
  --shadow: 0 10px 30px rgba(0, 0, 0, .35);
  --topbar-bg: rgba(15, 23, 42, .85);
  --history-item-bg: #0c1530;
  --ai-user-bg: #1e293b;
  --ai-bot-bg: #2a1959;
  --ai-bot-border: #4c1d95;
  --priority-low-bg:    #064e3b; --priority-low-text:    #6ee7b7;
  --priority-medium-bg: #1e3a8a; --priority-medium-text: #93c5fd;
  --priority-high-bg:   #7f1d1d; --priority-high-text:   #fca5a5;
  --role-admin-bg:  #7c2d12; --role-admin-text:  #fed7aa;
  --role-member-bg: #1e3a8a; --role-member-text: #93c5fd;
}

/* Sem escolha manual ⇒ segue preferência do SO */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]):not([data-theme="dark"]) {
    --bg: #0b1224;
    --bg-elev: #0f172a;
    --panel: #111c33;
    --panel-2: #182645;
    --input-bg: #0c1530;
    --border: #1f2d50;
    --text: #e2e8f0;
    --muted: #94a3b8;
    --primary: #6366f1;
    --primary-2: #4f46e5;
    --primary-soft: rgba(99, 102, 241, .12);
    --shadow: 0 10px 30px rgba(0, 0, 0, .35);
    --topbar-bg: rgba(15, 23, 42, .85);
    --history-item-bg: #0c1530;
    --ai-user-bg: #1e293b;
    --ai-bot-bg: #2a1959;
    --ai-bot-border: #4c1d95;
    --priority-low-bg:    #064e3b; --priority-low-text:    #6ee7b7;
    --priority-medium-bg: #1e3a8a; --priority-medium-text: #93c5fd;
    --priority-high-bg:   #7f1d1d; --priority-high-text:   #fca5a5;
    --role-admin-bg:  #7c2d12; --role-admin-text:  #fed7aa;
    --role-member-bg: #1e3a8a; --role-member-text: #93c5fd;
  }
}

* { box-sizing: border-box; }
html, body { margin:0; padding:0; height:100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

.hidden { display: none !important; }
.muted { color: var(--muted); font-size: .9rem; }
.error { color: #fca5a5; font-size: .9rem; min-height: 1.2em; margin: .25rem 0 0; }

/* ---------- Buttons / inputs ---------- */
button {
  font: inherit; cursor: pointer; border: 1px solid var(--border);
  background: var(--panel-2); color: var(--text);
  padding: .55rem .9rem; border-radius: 8px;
  transition: background .15s, transform .05s;
}
button:hover { background: var(--primary-soft); }
button:active { transform: translateY(1px); }
button.primary  { background: var(--primary); border-color: var(--primary-2); }
button.primary:hover { background: var(--primary-2); }
button.ok       { background: var(--ok); border-color: #15803d; }
button.warn     { background: var(--warn); border-color: #d97706; color: var(--warn-text); }
button.danger   { background: var(--danger); border-color: #b91c1c; }
button.ghost    { background: transparent; }

input, textarea, select {
  font: inherit; color: var(--text);
  background: var(--input-bg); border: 1px solid var(--border);
  border-radius: 8px; padding: .55rem .7rem; width: 100%;
}
input:focus, textarea:focus, select:focus {
  outline: 2px solid var(--primary); outline-offset: 1px;
}
label { display: block; margin-bottom: .75rem; }
label > span { display: block; margin-bottom: .25rem; font-size: .85rem; color: var(--muted); }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; }

/* ---------- Login ---------- */
.auth-screen {
  min-height: 100vh; display: grid; place-items: center; padding: 1rem;
}
.auth-card {
  width: 100%; max-width: 380px; background: var(--panel);
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1.5rem; box-shadow: var(--shadow);
}
.auth-card h1 { margin-top: 0; }
.brand-ai {
  background: linear-gradient(90deg, #818cf8, #c084fc);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}

/* ---------- Topbar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; justify-content: space-between; align-items: center;
  gap: 1rem; padding: .75rem 1rem;
  background: var(--topbar-bg); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.topbar-left { display: flex; align-items: center; gap: 1rem; }
.topbar h1 { margin: 0; font-size: 1.1rem; }
.topbar-right { display: flex; align-items: center; gap: .5rem; }
.tabs { display: flex; gap: .25rem; }
.tab {
  background: transparent; border: 1px solid transparent; color: var(--muted);
  padding: .35rem .75rem; border-radius: 999px;
}
.tab.active { background: var(--panel-2); color: var(--text); border-color: var(--border); }

.topbar-center {
  display: flex; align-items: center; gap: .5rem;
  flex: 1; justify-content: center;
}
.kanban-picker {
  display: flex; align-items: center; gap: .35rem;
  margin: 0;
}
.kanban-picker select {
  width: auto; min-width: 180px; padding: .4rem .6rem;
}
.kanban-label {
  font-weight: 600; color: var(--text);
}
@media (max-width: 800px) {
  .topbar-center { order: 3; width: 100%; justify-content: flex-start; }
}

.view { padding: 1rem; }

/* ---------- Kanban ---------- */
.board {
  display: grid; gap: .75rem;
  grid-template-columns: repeat(5, minmax(260px, 1fr));
  overflow-x: auto;
  padding-bottom: .5rem;
}
.column {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); padding: .75rem;
  display: flex; flex-direction: column; min-height: 60vh;
}
.column.drag-over { outline: 2px dashed var(--primary); background: var(--primary-soft); }
.column.drag-over .col-list::after {
  content: "Solte aqui";
  display: block; padding: .5rem; text-align: center;
  border: 1px dashed var(--primary); border-radius: 8px;
  color: var(--muted); font-size: .8rem; margin-top: .25rem;
}
.col-head {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: .5rem;
}
.col-title { font-weight: 600; font-size: .95rem; }
.col-count {
  font-size: .75rem; background: var(--panel-2); border-radius: 999px;
  padding: .1rem .5rem; color: var(--muted);
}
.col-list { display: flex; flex-direction: column; gap: .5rem; flex: 1; }

.task-card {
  background: var(--panel-2); border: 1px solid var(--border);
  border-radius: 10px; padding: .65rem .75rem;
  cursor: grab; transition: transform .08s, border-color .15s;
  touch-action: none; /* deixa o polyfill cuidar do gesto sem rolagem atrapalhar */
}
.task-card:active { cursor: grabbing; }
.task-card:hover { border-color: var(--primary); }
.task-card.dragging { opacity: .5; }
.task-card .title { font-weight: 600; margin-bottom: .25rem; }
.task-meta {
  display: flex; flex-wrap: wrap; gap: .35rem .6rem;
  font-size: .75rem; color: var(--muted);
}
.priority-pill {
  display: inline-block; padding: .05rem .45rem; border-radius: 999px;
  font-size: .7rem; font-weight: 600;
}
.priority-low    { background: var(--priority-low-bg); color: var(--priority-low-text); }
.priority-medium { background: var(--priority-medium-bg); color: var(--priority-medium-text); }
.priority-high   { background: var(--priority-high-bg); color: var(--priority-high-text); }

/* ---------- Modal ---------- */
.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,.6);
  display: grid; place-items: center; z-index: 50; padding: 1rem;
}
.modal-card {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); width: 100%; max-width: 520px;
  box-shadow: var(--shadow); max-height: 92vh; overflow: auto;
}
.modal-card.large { max-width: 980px; }
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: .9rem 1rem; border-bottom: 1px solid var(--border);
}
.modal-head h2 { margin: 0; font-size: 1.05rem; }
.modal-body { padding: 1rem; }
.modal .actions {
  display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin-top: .5rem;
}
.grid-2 {
  display: grid; gap: 1rem;
  grid-template-columns: 1.4fr 1fr;
}
.history {
  background: var(--panel-2); border: 1px solid var(--border);
  border-radius: 10px; padding: .75rem; max-height: 70vh; overflow: auto;
}
.history h3 { margin-top: 0; }
.history-list { display: flex; flex-direction: column; gap: .5rem; font-size: .85rem; color: var(--text); }
.history-item {
  border-left: 3px solid var(--primary);
  padding: .35rem .6rem; background: var(--history-item-bg); border-radius: 6px;
}
.history-item .when { color: var(--muted); font-size: .75rem; display:block; }
.history-item.ai { border-left-color: #c084fc; }

/* IA */
.ai-block {
  margin-top: 1rem; padding: .75rem; background: var(--panel-2);
  border: 1px dashed #5b21b6; border-radius: 10px;
}
.task-actions {
  margin-top: 1rem; padding-top: .75rem;
  border-top: 1px solid var(--border);
}
.ai-block h3 { margin: 0 0 .25rem; }
.ai-thread { display: flex; flex-direction: column; gap: .5rem; margin-top: .75rem; max-height: 40vh; overflow: auto; }
.ai-msg { padding: .5rem .7rem; border-radius: 8px; font-size: .9rem; white-space: pre-wrap; }
.ai-msg.user { background: var(--ai-user-bg); border: 1px solid var(--border); }
.ai-msg.bot  { background: var(--ai-bot-bg); border: 1px solid var(--ai-bot-border); }
.ai-msg .who { font-size: .7rem; color: var(--muted); display: block; margin-bottom: .25rem; }

/* ---------- Users ---------- */
.users-header {
  display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem;
}
.users-list {
  display: grid; gap: .5rem; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
}
.user-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: .75rem;
}
.user-card .row-actions {
  display: flex; gap: .35rem; flex-wrap: wrap; margin-top: .5rem;
}
.role-tag {
  display: inline-block; padding: .05rem .45rem; border-radius: 999px;
  font-size: .7rem; font-weight: 600; margin-left: .35rem;
}
.role-admin { background: var(--role-admin-bg); color: var(--role-admin-text); }
.role-member { background: var(--role-member-bg); color: var(--role-member-text); }
.inactive { opacity: .5; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; bottom: 1rem; left: 50%; transform: translateX(-50%);
  background: var(--panel); border: 1px solid var(--border);
  padding: .65rem 1rem; border-radius: 8px; box-shadow: var(--shadow);
  z-index: 100;
}
.toast.error { border-color: var(--danger); }

/* ---------- Mobile ---------- */
@media (max-width: 800px) {
  .topbar { flex-wrap: wrap; gap: .5rem; }
  .topbar h1 { font-size: 1rem; }
  .grid-2 { grid-template-columns: 1fr; }
  .row { grid-template-columns: 1fr; }
  .board {
    grid-template-columns: repeat(5, 85vw);
    scroll-snap-type: x mandatory;
  }
  .column { scroll-snap-align: start; }
  .modal-card.large { max-width: 100%; }
}

/* ---------- Theme toggle ---------- */
#theme-toggle {
  background: transparent;
  border: 1px solid var(--border);
  padding: .4rem .6rem;
  font-size: 1.05rem;
  line-height: 1;
}
#theme-toggle:hover { background: var(--primary-soft); }

.empty-state {
  padding: 3rem 1rem;
  text-align: center;
  font-size: 1rem;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  margin: 1rem 0;
}

/* ---------- Modal tabs ---------- */
.modal-tabs {
  display: flex; gap: .25rem; padding: .5rem 1rem 0; border-bottom: 1px solid var(--border);
}
.mtab {
  background: transparent; border: 1px solid transparent; color: var(--muted);
  padding: .4rem .8rem; border-radius: 8px 8px 0 0;
}
.mtab.active { background: var(--panel-2); color: var(--text); border-color: var(--border); border-bottom-color: var(--panel-2); margin-bottom: -1px; }
.mtab-pane { padding-top: .75rem; }
