:root {
  /* Paleta da marca WANA (extraida da logo) */
  --card: #ffffff;
  --text: #1e293b;
  --muted: #64748b;
  --primary: #2585c4;        /* azul WANA */
  --primary-dark: #1c6aa3;   /* azul mais profundo */
  --accent: #19b1e3;         /* ciano claro da onda */
  --brand-grad: linear-gradient(135deg, #19b1e3 0%, #2470b4 100%);
  --danger: #dc2626;
  --border: #e2e8f0;
  --radius: 12px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: #f1f5f9;
  color: var(--text);
  line-height: 1.5;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- Topbar ---------- */
.topbar { background: #fff; border-bottom: 1px solid var(--border); box-shadow: 0 1px 3px rgba(0,0,0,.05); }
.topbar-inner {
  max-width: 1100px; margin: 0 auto; padding: 12px 20px;
  display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 10px;
}
.brand { display: inline-flex; align-items: center; }
.brand:hover { text-decoration: none; }
.brand-logo { height: 34px; width: auto; display: block; }
.topbar nav { display: flex; gap: 18px; flex-wrap: wrap; align-items: center; }
.topbar nav a { color: #475569; font-size: 14px; font-weight: 600; }
.topbar nav a:hover { color: var(--primary); text-decoration: none; }
.topbar nav a.logout { color: var(--danger); }

/* ---------- Layout ---------- */
.container { max-width: 1100px; margin: 0 auto; padding: 24px 20px 60px; }
.container.narrow { max-width: 640px; }
.page-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; gap: 12px; flex-wrap: wrap; }
.page-head h1 { margin: 0; font-size: 24px; }
.section-title { font-size: 16px; margin: 18px 0 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }

.card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px; margin-bottom: 18px;
  box-shadow: 0 1px 2px rgba(0,0,0,.04);
}
.muted { color: var(--muted); }
.small { font-size: 13px; }
.empty { text-align: center; color: var(--muted); padding: 40px 20px; }

/* ---------- Grids ---------- */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 16px; }
.two-col { display: grid; grid-template-columns: 1fr 360px; gap: 20px; align-items: start; }
@media (max-width: 820px) { .two-col { grid-template-columns: 1fr; } }

.panel-card { display: block; transition: transform .08s, box-shadow .08s; }
.panel-card:hover { transform: translateY(-2px); box-shadow: 0 6px 16px rgba(0,0,0,.08); text-decoration: none; }
.panel-card h3 { margin: 0 0 6px; color: var(--text); }
.badge { display: inline-block; background: #eff6ff; color: var(--primary-dark); font-size: 12px; padding: 3px 10px; border-radius: 999px; margin-top: 8px; }

/* ---------- Forms ---------- */
label { display: block; margin-bottom: 14px; font-weight: 600; font-size: 14px; }
input, textarea {
  width: 100%; margin-top: 6px; padding: 10px 12px;
  border: 1px solid var(--border); border-radius: 8px; font-size: 15px; font-family: inherit;
  font-weight: 400;
}
input:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,.15); }
.form-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 8px; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-block; padding: 10px 16px; border-radius: 8px; border: 1px solid transparent;
  font-size: 14px; font-weight: 600; cursor: pointer; background: #e2e8f0; color: var(--text);
}
.btn:hover { text-decoration: none; filter: brightness(.97); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-ghost { background: transparent; border-color: var(--border); color: var(--text); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-block { display: block; width: 100%; text-align: center; margin-top: 8px; }

/* ---------- Alerts ---------- */
.alert { padding: 12px 14px; border-radius: 8px; margin-bottom: 16px; font-size: 14px; }
.alert-error { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }
.alert-success { background: #f0fdf4; color: #166534; border: 1px solid #bbf7d0; }
.alert-info { background: #eff6ff; color: #1e40af; border: 1px solid #bfdbfe; }

/* ---------- Doc list ---------- */
.doc-list { list-style: none; padding: 0; margin: 0; }
.doc-item {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 0; border-bottom: 1px solid var(--border); flex-wrap: wrap;
}
.doc-item:last-child { border-bottom: none; }
.doc-info { display: flex; align-items: center; gap: 10px; min-width: 0; }
.doc-icon { font-size: 22px; }
.doc-name { display: block; font-weight: 600; word-break: break-word; }
.doc-meta { display: block; font-size: 12px; color: var(--muted); }
.doc-actions { display: flex; gap: 8px; align-items: center; }
.doc-actions form { margin: 0; }

/* ---------- QR card ---------- */
.qr-card { text-align: center; }
.qr-img { width: 100%; max-width: 260px; height: auto; background: #fff; border: 1px solid var(--border); border-radius: 8px; padding: 8px; margin: 0 auto 12px; display: block; }
.url-box { display: block; background: #f1f5f9; padding: 8px 10px; border-radius: 6px; font-size: 12px; word-break: break-all; margin: 6px 0 12px; }
.danger-zone { border-color: #fecaca; }

/* ---------- Breadcrumb ---------- */
.breadcrumb { font-size: 13px; color: var(--muted); margin-bottom: 14px; display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.breadcrumb .sep { color: #cbd5e1; }
.breadcrumb .current { font-weight: 600; color: var(--text); }

/* ---------- Section head (titulo + acao) ---------- */
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.section-head .section-title { margin: 18px 0 12px; }

/* ---------- Arvore de paineis (org chart / arvore genealogica) ---------- */
.org-tree-wrap { overflow-x: auto; padding: 8px 4px 16px; }
.org-tree { display: inline-block; min-width: 100%; text-align: center; }
.org-tree ul { position: relative; padding: 22px 0 0; margin: 0; list-style: none; white-space: nowrap; }
.org-tree > ul { padding-top: 0; }
.org-tree li {
  display: inline-block; vertical-align: top; list-style: none;
  text-align: center; position: relative; padding: 22px 12px 0;
}

/* Conectores: cada filho recebe meia-linha para a esquerda e outra para a direita,
   ligadas a uma linha vertical que sobe ate o pai. */
.org-tree li::before, .org-tree li::after {
  content: ''; position: absolute; top: 0; right: 50%;
  width: 50%; height: 22px; border-top: 2px solid var(--accent);
}
.org-tree li::after { right: auto; left: 50%; border-left: 2px solid var(--accent); }
/* Filho unico nao precisa das meias-linhas horizontais. */
.org-tree li:only-child::before, .org-tree li:only-child::after { display: none; }
.org-tree li:only-child { padding-top: 0; }
/* Limpa as pontas: o primeiro nao tem linha a esquerda; o ultimo nao tem a direita. */
.org-tree li:first-child::before, .org-tree li:last-child::after { border: 0 none; }
.org-tree li:last-child::before { border-right: 2px solid var(--accent); border-radius: 0 6px 0 0; }
.org-tree li:first-child::after { border-radius: 6px 0 0 0; }
/* Linha vertical que desce do pai ate a fileira de filhos. */
.org-tree ul ul::before {
  content: ''; position: absolute; top: 0; left: 50%;
  width: 0; height: 22px; border-left: 2px solid var(--accent);
}

/* Caixa de cada painel (no). */
.org-tree .node {
  display: inline-flex; flex-direction: column; align-items: center; gap: 4px;
  position: relative; background: #fff;
  border: 1px solid var(--border); border-radius: 10px;
  padding: 10px 16px; min-width: 130px; max-width: 220px;
  box-shadow: 0 1px 3px rgba(0,0,0,.06); white-space: normal;
}
.org-tree .node:hover { border-color: var(--primary); box-shadow: 0 6px 16px rgba(0,0,0,.12); }
.org-tree .node-link { display: block; color: var(--text); }
.org-tree .node-link:hover { text-decoration: none; }
.org-tree .node-link:hover .node-name { color: var(--primary); }
.org-tree .node-name { display: block; font-weight: 700; font-size: 15px; word-break: break-word; }
.org-tree .node-meta { display: block; font-size: 12px; color: var(--muted); margin-top: 2px; }
.org-tree .node-add {
  font-size: 12px; font-weight: 600; color: var(--primary);
  background: #eff6ff; border-radius: 999px; padding: 2px 10px; margin-top: 2px;
  opacity: 0; transition: opacity .12s;
}
.org-tree li:hover > .node > .node-add { opacity: 1; }
.org-tree .node-add:hover { text-decoration: none; background: #dbeafe; }

/* No raiz (rotulo "Todos os paineis"). */
.org-tree .node-root { background: var(--brand-grad); border: none; color: #fff; }
.org-tree .node-root .node-name { color: #fff; }

/* Seta (triangulo) apontando do pai para dentro de cada painel filho. */
.org-tree ul ul > li > .node::after {
  content: ''; position: absolute; top: -7px; left: 50%; transform: translateX(-50%);
  width: 0; height: 0;
  border-left: 6px solid transparent; border-right: 6px solid transparent;
  border-top: 7px solid var(--accent);
}

/* ---------- Lista de paineis ligados (filhos) ---------- */
.child-list { list-style: none; padding: 0; margin: 0; }
.child-item {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 10px 0; border-bottom: 1px solid var(--border);
}
.child-item:last-child { border-bottom: none; }
.child-link { display: flex; flex-direction: column; gap: 2px; color: var(--text); }
.child-link:hover { text-decoration: none; }
.child-link:hover .child-name { color: var(--primary); }
.child-name { font-weight: 600; }
.child-arrow { color: #cbd5e1; font-size: 20px; }

select {
  width: 100%; margin-top: 6px; padding: 10px 12px;
  border: 1px solid var(--border); border-radius: 8px; font-size: 15px; font-family: inherit;
  background: #fff;
}
select:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,.15); }

/* ---------- Auth ---------- */
.auth-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; background: var(--brand-grad); }
.auth-card { width: 100%; max-width: 380px; margin: 0; }
.auth-logo { display: block; height: 44px; width: auto; margin: 4px auto 14px; }
.auth-title { text-align: center; margin: 0 0 4px; font-size: 22px; }
.auth-sub { text-align: center; color: var(--muted); margin: 0 0 20px; }
.auth-foot { text-align: center; margin-top: 16px; font-size: 14px; }
