/* ============================================================
   Portal Peneira Imóveis — folha de estilos
   Tema claro/escuro via variáveis CSS (data-theme em <html>).
   Paleta sóbria: um único acento (azul) + tons neutros.
   ============================================================ */

/* ---------- Reset ---------- */
*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
img, svg { display: block; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; text-decoration: none; }
ul, ol { list-style: none; }

/* ---------- Variáveis: tema claro ---------- */
:root {
  color-scheme: light;
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f7f8fa;
  --surface-3: #eef0f3;
  --border: #e6e8ec;
  --border-strong: #d6dae1;
  --text: #171a1f;
  --text-muted: #6a7280;
  --text-faint: #9aa1ad;

  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-soft: rgba(37, 99, 235, 0.10);
  --accent-ring: rgba(37, 99, 235, 0.28);

  --success: #16a34a;
  --success-soft: rgba(22, 163, 74, 0.12);
  --warning: #b45309;
  --warning-soft: rgba(217, 119, 6, 0.14);
  --danger: #dc2626;
  --danger-soft: rgba(220, 38, 38, 0.12);
  --info: #2563eb;
  --info-soft: rgba(37, 99, 235, 0.12);

  --sidebar-bg: #ffffff;
  --sidebar-border: #e6e8ec;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.05);
  --shadow: 0 1px 3px rgba(16, 24, 40, 0.07), 0 6px 20px rgba(16, 24, 40, 0.05);
  --shadow-lg: 0 12px 40px rgba(16, 24, 40, 0.16);
  --radius: 12px;
  --radius-sm: 8px;
  --radius-lg: 16px;
  --sidebar-w: 260px;
  --topbar-h: 64px;
  --transition: 160ms cubic-bezier(0.4, 0, 0.2, 1);
}

/* ---------- Variáveis: tema escuro ---------- */
[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0b0e13;
  --surface: #14181f;
  --surface-2: #1a1f28;
  --surface-3: #232a35;
  --border: #232a35;
  --border-strong: #333c49;
  --text: #e6e9ee;
  --text-muted: #9aa3b2;
  --text-faint: #6b7482;

  --accent: #3b82f6;
  --accent-hover: #60a5fa;
  --accent-soft: rgba(59, 130, 246, 0.16);
  --accent-ring: rgba(59, 130, 246, 0.35);

  --success: #34d399;
  --success-soft: rgba(52, 211, 153, 0.14);
  --warning: #fbbf24;
  --warning-soft: rgba(251, 191, 36, 0.14);
  --danger: #f87171;
  --danger-soft: rgba(248, 113, 113, 0.14);
  --info: #60a5fa;
  --info-soft: rgba(96, 165, 250, 0.14);

  --sidebar-bg: #10141b;
  --sidebar-border: #1c222c;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.5), 0 6px 24px rgba(0, 0, 0, 0.45);
  --shadow-lg: 0 16px 48px rgba(0, 0, 0, 0.6);
}

/* ---------- Ícones SVG ---------- */
.icon { width: 20px; height: 20px; flex: none; stroke-width: 1.8; }
.icon-sm { width: 16px; height: 16px; }
.icon-lg { width: 24px; height: 24px; }

/* alternância sol/lua no botão de tema */
.theme-icon-sun { display: none; }
.theme-icon-moon { display: block; }
[data-theme="dark"] .theme-icon-sun { display: block; }
[data-theme="dark"] .theme-icon-moon { display: none; }

/* ---------- Botões ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 40px; padding: 0 16px;
  border: 1px solid transparent; border-radius: var(--radius-sm);
  background: var(--surface-3); color: var(--text);
  font-weight: 600; font-size: 14px; cursor: pointer;
  transition: background var(--transition), border-color var(--transition), color var(--transition), transform var(--transition), box-shadow var(--transition);
  white-space: nowrap; user-select: none;
}
.btn:hover { background: var(--border); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--accent-ring); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-outline { background: transparent; border-color: var(--border-strong); }
.btn-outline:hover { background: var(--surface-2); }
.btn-ghost { background: transparent; }
.btn-ghost:hover { background: var(--surface-3); }
.btn-danger { background: var(--danger-soft); color: var(--danger); }
.btn-danger:hover { background: var(--danger); color: #fff; }
.btn-sm { height: 34px; padding: 0 12px; font-size: 13px; }
.btn-block { width: 100%; }
.btn.loading { pointer-events: none; opacity: 0.7; }
.btn.loading::before {
  content: ""; width: 14px; height: 14px; flex: none;
  border: 2px solid currentColor; border-right-color: transparent;
  border-radius: 50%; animation: spin 0.7s linear infinite;
}
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 38px; height: 38px; border: none; border-radius: var(--radius-sm);
  background: transparent; color: var(--text-muted); cursor: pointer;
  transition: background var(--transition), color var(--transition);
}
.icon-btn:hover { background: var(--surface-3); color: var(--text); }
.icon-btn:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--accent-ring); }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Formulários ---------- */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.field > label { font-size: 13px; font-weight: 600; color: var(--text-muted); }
.input, .select, .textarea {
  width: 100%; height: 42px; padding: 0 14px;
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text);
  transition: border-color var(--transition), box-shadow var(--transition);
}
.textarea { height: auto; min-height: 96px; padding: 12px 14px; resize: vertical; }
.input::placeholder, .textarea::placeholder { color: var(--text-faint); }
.input:focus, .select:focus, .textarea:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-ring);
}
.input-wrap { position: relative; }
.input-wrap .input { padding-right: 44px; }
.input-wrap .icon-btn { position: absolute; top: 2px; right: 2px; width: 38px; height: 38px; }
.hint { font-size: 12px; color: var(--text-faint); }
.field-error { font-size: 12px; color: var(--danger); display: none; }
.field.has-error .input { border-color: var(--danger); }
.field.has-error .field-error { display: block; }

/* ---------- Badges de status ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  height: 24px; padding: 0 10px; border-radius: 999px;
  font-size: 12px; font-weight: 600; line-height: 1;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-success { background: var(--success-soft); color: var(--success); }
.badge-warning { background: var(--warning-soft); color: var(--warning); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }
.badge-info { background: var(--info-soft); color: var(--info); }
.badge-muted { background: var(--surface-3); color: var(--text-muted); }

/* ---------- Cartões ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-sm);
}
.card-pad { padding: 20px; }
.card-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 16px 20px; border-bottom: 1px solid var(--border);
}
.card-title { font-size: 15px; font-weight: 650; }
.card-sub { font-size: 13px; color: var(--text-muted); }

/* ---------- Tabelas ---------- */
.table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.table th {
  text-align: left; padding: 10px 20px; font-size: 12px; font-weight: 600;
  color: var(--text-faint); text-transform: uppercase; letter-spacing: 0.04em;
  border-bottom: 1px solid var(--border); background: var(--surface-2);
}
.table td { padding: 14px 20px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr:last-child td { border-bottom: none; }
.table tbody tr { transition: background var(--transition); }
.table tbody tr:hover { background: var(--surface-2); }
.table .cell-main { font-weight: 600; }
.table .cell-sub { font-size: 12px; color: var(--text-muted); }

/* ---------- Estatísticas (cards de números) ---------- */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 16px; }
.stat {
  display: flex; align-items: flex-start; gap: 14px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow-sm);
}
.stat-icon {
  display: flex; align-items: center; justify-content: center;
  width: 44px; height: 44px; border-radius: var(--radius-sm);
  background: var(--accent-soft); color: var(--accent); flex: none;
}
.stat-icon .icon { width: 22px; height: 22px; }
.stat-value { font-size: 24px; font-weight: 700; letter-spacing: -0.02em; line-height: 1.15; }
.stat-label { font-size: 13px; color: var(--text-muted); margin-top: 2px; }

/* ---------- Layout do painel ---------- */
.app { display: flex; min-height: 100vh; }

.sidebar {
  position: fixed; inset: 0 auto 0 0; z-index: 40;
  width: var(--sidebar-w); display: flex; flex-direction: column;
  background: var(--sidebar-bg); border-right: 1px solid var(--sidebar-border);
  transition: transform var(--transition);
}
.sidebar-brand {
  display: flex; align-items: center; gap: 12px;
  height: var(--topbar-h); padding: 0 20px;
  border-bottom: 1px solid var(--sidebar-border);
}
.brand-logo { width: 34px; height: 34px; color: var(--accent); flex: none; }
.brand-name { font-size: 16px; font-weight: 700; letter-spacing: -0.01em; }
.brand-sub { font-size: 11px; color: var(--text-faint); font-weight: 500; }

.sidebar-nav { flex: 1; padding: 12px 10px; overflow-y: auto; }
.nav-label { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-faint); padding: 14px 12px 6px; }
.nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px; margin-bottom: 2px; border-radius: var(--radius-sm);
  color: var(--text-muted); font-weight: 550; cursor: pointer; border: none; background: transparent;
  width: 100%; text-align: left; font-size: 14px;
  transition: background var(--transition), color var(--transition);
}
.nav-item:hover { background: var(--surface-3); color: var(--text); }
.nav-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav-item .icon { width: 19px; height: 19px; }

.sidebar-foot { padding: 12px 10px; border-top: 1px solid var(--sidebar-border); }

.main {
  flex: 1; margin-left: var(--sidebar-w);
  display: flex; flex-direction: column; min-width: 0;
}
.topbar {
  position: sticky; top: 0; z-index: 30;
  height: var(--topbar-h); display: flex; align-items: center; gap: 12px;
  padding: 0 24px; background: color-mix(in srgb, var(--surface) 86%, transparent);
  backdrop-filter: blur(10px); border-bottom: 1px solid var(--border);
}
.topbar-title { font-size: 17px; font-weight: 700; }
.topbar-spacer { flex: 1; }
.avatar {
  display: flex; align-items: center; justify-content: center;
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--accent-soft); color: var(--accent); font-weight: 700; font-size: 14px;
  flex: none;
}

.content { padding: 24px; max-width: 1280px; width: 100%; margin: 0 auto; }

/* ---------- Barra de impersonate ---------- */
.impersonation-banner {
  display: flex; align-items: center; gap: 10px;
  margin: 12px 24px 0; padding: 10px 16px;
  background: var(--warning-soft); color: var(--warning);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  font-size: 13.5px; font-weight: 600;
}
.impersonation-banner .icon { width: 18px; height: 18px; flex: none; }
.impersonation-banner .btn { margin-left: auto; }
@media (max-width: 560px) {
  .impersonation-banner { margin: 12px 16px 0; flex-wrap: wrap; }
  .impersonation-banner .btn { margin-left: 0; }
}
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-title { font-size: 22px; font-weight: 700; letter-spacing: -0.02em; }
.page-desc { color: var(--text-muted); margin-top: 4px; font-size: 14px; }
.section { margin-top: 20px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }

/* ---------- Menu de usuário (dropdown) ---------- */
.dropdown { position: relative; }
.dropdown-menu {
  position: absolute; right: 0; top: calc(100% + 8px); min-width: 210px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-lg);
  padding: 6px; display: none; z-index: 60;
}
.dropdown.open .dropdown-menu { display: block; }
.dropdown-item {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 9px 10px; border-radius: var(--radius-sm); border: none;
  background: transparent; color: var(--text); font-size: 13.5px; font-weight: 500;
  cursor: pointer; text-align: left;
}
.dropdown-item:hover { background: var(--surface-3); }
.dropdown-item.danger { color: var(--danger); }
.dropdown-item .icon { width: 17px; height: 17px; }
.dropdown-head { padding: 10px; border-bottom: 1px solid var(--border); margin-bottom: 4px; }
.dropdown-head .name { font-weight: 650; }
.dropdown-head .email { font-size: 12px; color: var(--text-muted); }

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed; inset: 0; z-index: 80;
  background: rgba(8, 11, 16, 0.5); backdrop-filter: blur(2px);
  display: flex; align-items: center; justify-content: center; padding: 20px;
  opacity: 0; pointer-events: none; transition: opacity var(--transition);
}
.modal-overlay.open { opacity: 1; pointer-events: auto; }
.modal {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
  width: 100%; max-width: 560px; max-height: 90vh; overflow: auto;
  transform: translateY(8px); transition: transform var(--transition);
}
.modal-overlay.open .modal { transform: translateY(0); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 20px; border-bottom: 1px solid var(--border); }
.modal-title { font-size: 16px; font-weight: 700; }
.modal-body { padding: 20px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 16px 20px; border-top: 1px solid var(--border); }

/* ---------- Toast ---------- */
#toast-host {
  position: fixed; right: 20px; bottom: 20px; z-index: 100;
  display: flex; flex-direction: column; gap: 10px; pointer-events: none;
}
.toast {
  display: flex; align-items: center; gap: 10px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); box-shadow: var(--shadow-lg);
  padding: 12px 16px; max-width: 360px; font-size: 13.5px; font-weight: 500;
  opacity: 0; transform: translateY(8px); transition: all var(--transition);
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast-icon { width: 18px; height: 18px; flex: none; }
.toast-success .toast-icon { color: var(--success); }
.toast-error .toast-icon { color: var(--danger); }
.toast-info .toast-icon { color: var(--info); }

/* ---------- Estado vazio ---------- */
.empty { text-align: center; padding: 48px 20px; color: var(--text-muted); }
.empty .icon { width: 40px; height: 40px; color: var(--text-faint); margin: 0 auto 12px; }
.empty-title { font-weight: 650; color: var(--text); margin-bottom: 4px; }
.empty-sub { font-size: 13px; }

/* ---------- Skeleton ---------- */
.skeleton { background: linear-gradient(90deg, var(--surface-3) 25%, var(--border) 50%, var(--surface-3) 75%); background-size: 200% 100%; animation: shimmer 1.3s infinite; border-radius: var(--radius-sm); }
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

/* ---------- Gráficos ---------- */
.chart-card { padding: 20px; }
.chart-box { position: relative; height: 300px; }

/* ---------- Páginas de autenticação ---------- */
.auth {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  padding: 24px; position: relative;
}
.auth-panel { width: 100%; max-width: 420px; }
.auth-card { padding: 32px; }
.auth-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 28px; }
.auth-brand .brand-logo { width: 40px; height: 40px; }
.auth-title { font-size: 22px; font-weight: 700; letter-spacing: -0.02em; margin-bottom: 4px; }
.auth-sub { color: var(--text-muted); font-size: 14px; margin-bottom: 24px; }
.auth-foot { text-align: center; margin-top: 18px; font-size: 13px; color: var(--text-muted); }
.auth-foot a { color: var(--accent); font-weight: 600; }
.auth-theme { position: absolute; top: 20px; right: 20px; }
.auth-links { display: flex; justify-content: space-between; margin-top: 14px; font-size: 13px; }
.auth-links a { color: var(--accent); font-weight: 600; }
.auth-alert {
  display: flex; align-items: flex-start; gap: 10px;
  background: var(--info-soft); color: var(--info);
  padding: 12px 14px; border-radius: var(--radius-sm); font-size: 13px; margin-bottom: 18px;
}
.auth-alert .icon { width: 18px; height: 18px; flex: none; margin-top: 1px; }

/* ---------- Badge do papel ---------- */
.role-chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: 6px; font-size: 12px; font-weight: 600;
  background: var(--accent-soft); color: var(--accent);
}
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.cell-actions { display: flex; align-items: center; justify-content: flex-end; gap: 8px; white-space: nowrap; }
.btn .icon { width: 16px; height: 16px; }

/* ---------- Detalhe (lista de propriedades) ---------- */
.kv { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 20px; }
.kv-item { display: flex; flex-direction: column; gap: 2px; }
.kv-key { font-size: 12px; color: var(--text-faint); font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }
.kv-val { font-size: 14px; font-weight: 550; }
.people-list { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 4px; }

/* ---------- Filtros / barra de ferramentas ---------- */
.toolbar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.toolbar .search { position: relative; flex: 1; min-width: 220px; max-width: 360px; }
.toolbar .search .icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); width: 17px; height: 17px; color: var(--text-faint); }
.toolbar .search .input { padding-left: 40px; }
.toolbar .select { width: auto; min-width: 160px; }

/* ---------- Paginação ---------- */
.pagination { display: flex; align-items: center; justify-content: space-between; padding: 14px 20px; border-top: 1px solid var(--border); font-size: 13px; color: var(--text-muted); }
.pagination-controls { display: flex; gap: 8px; }

/* ---------- Responsivo ---------- */
.sidebar-backdrop {
  position: fixed; inset: 0; z-index: 35; background: rgba(8, 11, 16, 0.5);
  display: none; border: none;
}
@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); box-shadow: var(--shadow-lg); }
  .sidebar-backdrop.show { display: block; }
  .main { margin-left: 0; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .kv { grid-template-columns: 1fr; }
}
@media (max-width: 560px) {
  .content { padding: 16px; }
  .topbar { padding: 0 16px; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
}

/* ---------- Thread de mensagens (solicitações) ---------- */
.tk-thread { display: flex; flex-direction: column; gap: 10px; max-height: 340px; overflow-y: auto; padding: 4px 2px; }
.tk-msg { max-width: 88%; padding: 10px 14px; border-radius: 12px; font-size: 13.5px; }
.tk-msg-meta { font-size: 11px; font-weight: 600; color: var(--text-faint); margin-bottom: 4px; }
.tk-msg-body { white-space: pre-wrap; word-break: break-word; }
.tk-bubble-admin { align-self: flex-start; background: var(--surface-3); color: var(--text); border-top-left-radius: 4px; }
.tk-bubble-user { align-self: flex-end; background: var(--accent-soft); color: var(--text); border-top-right-radius: 4px; }
.tk-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.tk-att-title { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-faint); margin: 14px 0 8px; }
.tk-atts { display: flex; flex-direction: column; gap: 8px; }
.tk-attach { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface-2); cursor: pointer; transition: background var(--transition); }
.tk-attach:hover { background: var(--surface-3); }
.tk-attach > .icon { color: var(--accent); }
.modal-foot { align-items: flex-end; flex-wrap: wrap; }
.modal-foot .textarea { min-height: 44px; max-width: 100%; }
.tk-foot { display: flex; flex-direction: column; gap: 10px; width: 100%; }
.tk-foot .textarea { min-height: 68px; width: 100%; }
.tk-foot-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.tk-foot-actions { display: flex; align-items: center; gap: 8px; margin-left: auto; }
