:root {
  --bg: #f3f4f6;
  --card: #ffffff;
  --ink: #111827;
  --muted: #6b7280;
  --line: #e5e7eb;
  --brand: #2563eb;
  --brand-d: #1d4ed8;
  --ok: #059669;
  --warn: #d97706;
  --bad: #dc2626;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: Inter, system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
  overflow-x: hidden;
}
a { color: var(--brand); }
button {
  font: inherit;
  cursor: pointer;
  border: none;
  border-radius: 8px;
  padding: 9px 16px;
  background: var(--brand);
  color: #fff;
  transition: background .15s;
}
button:hover { background: var(--brand-d); }
button.ghost { background: transparent; color: var(--ink); border: 1px solid var(--line); }
button.ghost:hover { background: #f9fafb; }
button.danger { background: var(--bad); }
button.sm { padding: 6px 12px; font-size: 13px; }
input, select {
  font: inherit;
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}
input:focus, select:focus { outline: 2px solid #bfdbfe; border-color: var(--brand); }
label { display: block; font-size: 13px; color: var(--muted); margin: 0 0 4px; }
.field { margin-bottom: 14px; }

/* ---- Login / cards centrais ---- */
.center { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 28px;
}
.auth { width: 100%; max-width: 380px; }
.auth-brand { display: flex; justify-content: center; margin: 0 0 18px; }
.auth-brand img { height: 38px; object-fit: contain; }
.auth h1 { margin: 0 0 4px; font-size: 22px; }
.auth .sub { color: var(--muted); margin: 0 0 22px; }
.full { width: 100%; }
.msg { font-size: 13px; margin-top: 12px; min-height: 18px; }
.msg.err { color: var(--bad); }
.msg.ok { color: var(--ok); }
.row-between { display: flex; justify-content: space-between; align-items: center; }
.mt { margin-top: 14px; }

/* ---- App shell ---- */
.shell { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.side {
  background: #0f172a;
  color: #cbd5e1;
  padding: 18px 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.side .brand { display: flex; align-items: center; gap: 10px; padding: 6px 10px 16px; }
.side .brand-logo { width: 30px; height: 30px; object-fit: contain; flex: none; }
.side .brand-name { color: #fff; font-weight: 700; font-size: 17px; line-height: 1.1; }
.side .brand-name small { display:block; font-weight:400; color:#64748b; font-size:11px; }
.side a {
  color: #cbd5e1; text-decoration: none; padding: 9px 12px; border-radius: 8px;
  display: flex; align-items: center; gap: 8px; font-size: 14px;
}
.side a:hover { background: #1e293b; color: #fff; }
.side a.active { background: var(--brand); color: #fff; }
.side .spacer { flex: 1; }
.side .tenant { padding: 8px 10px; }
.side .tenant select { background:#1e293b; color:#fff; border-color:#334155; }
.main { padding: 24px 28px; overflow: auto; }
.topbar { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 20px; }
.topbar h2 { margin: 0; font-size: 20px; }

/* ---- User chip / perfil ---- */
.user-chip {
  display: flex; align-items: center; gap: 10px;
  background: var(--card); border: 1px solid var(--line); border-radius: 999px;
  padding: 5px 14px 5px 5px; color: var(--ink); box-shadow: var(--shadow);
}
.user-chip:hover { background: #f9fafb; }
.user-avatar {
  width: 32px; height: 32px; border-radius: 50%; flex: none;
  display: grid; place-items: center; color: #fff; font-weight: 700; font-size: 13px;
  background: var(--brand);
}
.user-meta { display: flex; flex-direction: column; line-height: 1.15; text-align: left; }
.user-name { font-size: 13px; font-weight: 600; }
.user-role { font-size: 11px; color: var(--muted); }
@media (max-width: 480px) { .user-meta { display: none; } .user-chip { padding: 4px; } }

/* ---- KPIs ---- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px,1fr)); gap: 14px; margin-bottom: 22px; }
.kpi { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 18px; }
.kpi .n { font-size: clamp(22px, 6vw, 28px); font-weight: 700; word-break: break-word; }
.kpi .l { color: var(--muted); font-size: 13px; }

/* ---- Tabela ---- */
.table-wrap { overflow-x: auto; background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 11px 14px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
tr:last-child td { border-bottom: none; }
.avatar { width: 36px; height: 36px; border-radius: 50%; object-fit: cover; background: #e5e7eb; }

/* ---- Badges (Title Case nos estados) ---- */
.badge {
  display: inline-block; padding: 3px 10px; border-radius: 999px;
  font-size: 12px; font-weight: 600; text-transform: capitalize;
}
.badge.ativo, .badge.online, .badge.sincronizado, .badge.autorizado { background: #d1fae5; color: #065f46; }
.badge.bloqueado, .badge.offline, .badge.erro, .badge.negado { background: #fee2e2; color: #991b1b; }
.badge.desconhecido, .badge.pendente { background: #fef3c7; color: #92400e; }
.badge.admin { background:#ede9fe; color:#5b21b6; }
.badge.sindico { background:#dbeafe; color:#1e40af; }
.badge.portaria { background:#f3f4f6; color:#374151; }

/* ---- Modal ---- */
.overlay { position: fixed; inset: 0; background: rgba(15,23,42,.5); display: none; place-items: center; padding: 20px; z-index: 50; }
.overlay.open { display: grid; }
.modal { background: #fff; border-radius: var(--radius); padding: 24px; width: 100%; max-width: 460px; box-shadow: var(--shadow); max-height: calc(100vh - 40px); overflow-y: auto; }
.modal h3 { margin: 0 0 18px; }
.modal .actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 18px; }

.toolbar { display: flex; gap: 10px; margin-bottom: 16px; align-items: center; flex-wrap: wrap; }
.toolbar input { flex: 1 1 200px; max-width: 280px; min-width: 0; }
.empty { padding: 40px; text-align: center; color: var(--muted); }
.hint { font-size: 12px; color: var(--muted); margin-top: 6px; }

@media (max-width: 720px) {
  .shell { grid-template-columns: 1fr; }
  .side { flex-direction: row; flex-wrap: wrap; align-items: center; }
  .side .brand { padding: 6px 10px; }
  .side .spacer { display: none; }
}

/* ---- Ações de dispositivo + toast ---- */
.acoes-dev { white-space: nowrap; }
.acoes-dev button { margin-left: 4px; }
.acoes-dev button:first-child { margin-left: 0; }
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: #111827; color: #fff; padding: 12px 20px; border-radius: 10px;
  font-size: 14px; font-weight: 500; box-shadow: 0 8px 24px rgba(0,0,0,.25);
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 9999;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.err { background: #991b1b; }
