/* ============================================================
   Dash Imobiliário — Design System
   ============================================================ */

:root {
  --primary:       #2563eb;
  --primary-dark:  #1d4ed8;
  --primary-light: #eff6ff;
  --success:       #059669;
  --success-light: #ecfdf5;
  --warning:       #d97706;
  --warning-light: #fffbeb;
  --danger:        #dc2626;
  --danger-light:  #fef2f2;

  --white:    #ffffff;
  --gray-50:  #f8fafc;
  --gray-100: #f1f5f9;
  --gray-200: #e2e8f0;
  --gray-300: #cbd5e1;
  --gray-400: #94a3b8;
  --gray-500: #64748b;
  --gray-600: #475569;
  --gray-700: #334155;
  --gray-800: #1e293b;
  --gray-900: #0f172a;

  --radius-sm: 6px;
  --radius:    10px;
  --radius-lg: 14px;
  --radius-xl: 20px;

  --shadow-xs: 0 1px 2px 0 rgba(0,0,0,.05);
  --shadow-sm: 0 1px 3px 0 rgba(0,0,0,.07), 0 1px 2px -1px rgba(0,0,0,.05);
  --shadow:    0 4px 6px -1px rgba(0,0,0,.07), 0 2px 4px -2px rgba(0,0,0,.05);
  --shadow-md: 0 10px 15px -3px rgba(0,0,0,.07), 0 4px 6px -4px rgba(0,0,0,.04);

  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Inter', 'Helvetica Neue', Arial, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html  { font-size: 15px; -webkit-font-smoothing: antialiased; }
body  { font-family: var(--font); background: var(--gray-50); color: var(--gray-800); min-height: 100vh; line-height: 1.6; }

/* ── Navbar ────────────────────────────────────────────────── */
.navbar {
  background: var(--white);
  border-bottom: 1px solid var(--gray-200);
  height: 210px;
  display: flex;
  align-items: center;
  padding: 0 1.5rem;
  gap: 1.5rem;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow-xs);
}

.brand {
  display: flex;
  align-items: center;
  gap: .55rem;
  font-weight: 800;
  font-size: 1rem;
  color: var(--gray-900);
  text-decoration: none;
  white-space: nowrap;
  letter-spacing: -.02em;
}

.brand-icon {
  width: 30px;
  height: 30px;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: .9rem;
  flex-shrink: 0;
}

.brand-logo {
  height: 195px;
  width: auto;
  object-fit: contain;
  display: block;
}

.page-bg-icon {
  position: fixed;
  bottom: -60px;
  right: -60px;
  width: 340px;
  height: 340px;
  pointer-events: none;
  z-index: 0;
  opacity: .045;
}
.page-bg-icon img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}
.page-wrapper { position: relative; z-index: 1; }

nav {
  display: flex;
  gap: .2rem;
  flex: 1;
}

nav a {
  text-decoration: none;
  color: var(--gray-500);
  font-size: .85rem;
  font-weight: 500;
  padding: .4rem .8rem;
  border-radius: var(--radius-sm);
  transition: all .15s;
  white-space: nowrap;
}

nav a:hover  { background: var(--gray-100); color: var(--gray-800); }
nav a.active { background: var(--primary-light); color: var(--primary); font-weight: 600; }

.user-info {
  display: flex;
  align-items: center;
  gap: .6rem;
  font-size: .8rem;
  color: var(--gray-400);
  white-space: nowrap;
}

.user-info a { color: var(--primary); text-decoration: none; font-weight: 500; }
.user-info a:hover { text-decoration: underline; }

/* ── Page ──────────────────────────────────────────────────── */
.page-wrapper {
  max-width: 1300px;
  margin: 0 auto;
  padding: 1.75rem 1.5rem 3rem;
}

.page-title {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--gray-900);
  letter-spacing: -.02em;
  margin: 0 0 1.5rem;
}

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
  gap: .75rem;
}

.page-header-left h1 { margin: 0; }
.page-header-left p  { font-size: .84rem; color: var(--gray-500); margin-top: .2rem; }

/* ── Cards ─────────────────────────────────────────────────── */
.card {
  background: var(--white);
  border-radius: var(--radius);
  border: 1px solid var(--gray-200);
  box-shadow: var(--shadow-sm);
  padding: 1.25rem 1.5rem;
  margin-bottom: 1rem;
}

.card-title {
  font-size: .72rem;
  font-weight: 700;
  color: var(--gray-400);
  text-transform: uppercase;
  letter-spacing: .08em;
  margin-bottom: .9rem;
}

/* ── Alerts ────────────────────────────────────────────────── */
.alert-success {
  background: var(--success-light);
  border: 1px solid #a7f3d0;
  color: #065f46;
  border-radius: var(--radius);
  padding: .75rem 1rem;
  font-size: .88rem;
  margin-bottom: 1rem;
  font-weight: 500;
}

.alert-error {
  background: var(--danger-light);
  border: 1px solid #fecaca;
  color: #991b1b;
  border-radius: var(--radius);
  padding: .75rem 1rem;
  font-size: .88rem;
  margin-bottom: 1rem;
}

.alert-info {
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  color: #1e40af;
  border-radius: var(--radius);
  padding: .75rem 1rem;
  font-size: .88rem;
  margin-bottom: 1rem;
}

/* ── KPI Total ─────────────────────────────────────────────── */
.kpi-total-card {
  background: linear-gradient(135deg, #1a56db 0%, #1e3a8a 100%);
  color: white;
  border-radius: var(--radius-lg);
  padding: 1.4rem 1.75rem;
  margin-bottom: 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1.25rem;
  flex-wrap: wrap;
  box-shadow: 0 4px 16px rgba(37,99,235,.25);
}

.kpi-total-label {
  font-size: .74rem;
  font-weight: 600;
  opacity: .8;
  text-transform: uppercase;
  letter-spacing: .07em;
  margin-bottom: .35rem;
}

.kpi-total-valor {
  font-size: 2.1rem;
  font-weight: 800;
  letter-spacing: -.04em;
  line-height: 1;
}

.kpi-total-geral { font-size: .78rem; opacity: .7; margin-top: .35rem; }

.kpi-filtro-tags { display: flex; flex-wrap: wrap; gap: .35rem; }
.kpi-filtro-tag {
  background: rgba(255,255,255,.18);
  color: white;
  border-radius: 999px;
  padding: .18rem .65rem;
  font-size: .72rem;
  font-weight: 500;
  border: 1px solid rgba(255,255,255,.28);
}

/* ── KPI Grid (recebidos) ──────────────────────────────────── */
.kpi-grid-rec {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(195px, 1fr));
  gap: .875rem;
  margin-bottom: 1.25rem;
}

.kpi-rec-card {
  background: var(--white);
  border: 1px solid var(--gray-200);
  border-left: 4px solid var(--gray-300);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 1.1rem 1.35rem;
}

.kpi-rec-card.kv-green  { border-left-color: var(--success); }
.kpi-rec-card.kv-blue   { border-left-color: var(--primary); }
.kpi-rec-card.kv-yellow { border-left-color: var(--warning); }
.kpi-rec-card.kv-gray   { border-left-color: var(--gray-400); }

.kpi-rec-label { font-size: .72rem; font-weight: 600; color: var(--gray-400); text-transform: uppercase; letter-spacing: .07em; margin-bottom: .4rem; }
.kpi-rec-valor { font-size: 1.45rem; font-weight: 800; color: var(--gray-900); letter-spacing: -.03em; line-height: 1.1; }
.kpi-rec-sub   { font-size: .75rem; color: var(--gray-400); margin-top: .3rem; }

/* ── Aging ─────────────────────────────────────────────────── */
.aging-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: .875rem;
  margin-bottom: 1.25rem;
}

@media (max-width: 900px) { .aging-grid { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 500px) { .aging-grid { grid-template-columns: 1fr; } }

.aging-card {
  background: var(--white);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 1rem 1.2rem;
  position: relative;
  overflow: hidden;
}

.aging-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
}

.aging-card.mes-0::before   { background: var(--danger); }
.aging-card.mes-1::before   { background: var(--warning); }
.aging-card.mes-2::before   { background: #f59e0b; }
.aging-card.mes-ant::before { background: var(--gray-300); }

.aging-mes      { font-size: .72rem; font-weight: 700; color: var(--gray-400); text-transform: uppercase; letter-spacing: .05em; margin-bottom: .4rem; }
.aging-numero   { font-size: 1.9rem; font-weight: 800; color: var(--gray-900); line-height: 1; letter-spacing: -.04em; }
.aging-legenda  { font-size: .72rem; color: var(--gray-400); margin-top: .12rem; margin-bottom: .65rem; }
.aging-valor-wrap { border-top: 1px solid var(--gray-100); padding-top: .55rem; }
.aging-valor-num  { font-size: .9rem; font-weight: 700; color: var(--gray-700); }
.aging-valor-label{ font-size: .7rem; color: var(--gray-400); }

/* ── Charts ────────────────────────────────────────────────── */
.charts-grid {
  display: grid;
  grid-template-columns: 3fr 2fr;
  gap: .875rem;
  margin-bottom: 1rem;
}

@media (max-width: 900px) { .charts-grid { grid-template-columns: 1fr; } }

.chart-card {
  background: var(--white);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 1.25rem 1.5rem;
}

.chart-titulo {
  font-size: .72rem;
  font-weight: 700;
  color: var(--gray-400);
  text-transform: uppercase;
  letter-spacing: .08em;
  margin-bottom: 1rem;
}

.chart-container { position: relative; }

.evo-card {
  background: var(--white);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 1.25rem 1.5rem;
  margin-bottom: 1rem;
}

.evo-empty {
  text-align: center;
  padding: 2.5rem 1rem;
  color: var(--gray-400);
  font-size: .88rem;
  line-height: 1.7;
}

.evo-empty strong { color: var(--gray-700); font-size: 1rem; display: block; margin-bottom: .4rem; }

.chart-error {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 120px;
  color: var(--gray-400);
  font-size: .8rem;
  text-align: center;
}

/* ── Filtros ───────────────────────────────────────────────── */
.filtro-wrap {
  background: var(--white);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 1.1rem 1.4rem;
  margin-bottom: 1.25rem;
}

.filtro-relatorio {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: .65rem;
  margin-bottom: .9rem;
  padding-bottom: .9rem;
  border-bottom: 1px solid var(--gray-100);
}

.filtro-relatorio-label { font-size: .78rem; font-weight: 600; color: var(--gray-500); white-space: nowrap; }

.filtro-relatorio select {
  padding: .4rem .75rem;
  border: 1.5px solid var(--gray-200);
  border-radius: var(--radius-sm);
  font-size: .85rem;
  font-family: var(--font);
  color: var(--gray-700);
  background: white;
  cursor: pointer;
  transition: border-color .15s;
  outline: none;
  width: auto;
}

.filtro-relatorio select:focus { border-color: var(--primary); }

.filtro-corpo { display: flex; gap: 2rem; flex-wrap: wrap; }

.filtro-grupo-titulo {
  font-size: .72rem;
  font-weight: 700;
  color: var(--gray-400);
  text-transform: uppercase;
  letter-spacing: .07em;
  margin-bottom: .45rem;
}

.atalhos-row { display: flex; gap: .35rem; flex-wrap: wrap; margin-bottom: .4rem; }

.atalho {
  background: var(--gray-100);
  border: 1.5px solid var(--gray-200);
  border-radius: 999px;
  padding: .2rem .7rem;
  font-size: .74rem;
  font-weight: 600;
  color: var(--gray-600);
  cursor: pointer;
  transition: all .15s;
  font-family: var(--font);
}

.atalho:hover { background: var(--primary-light); color: var(--primary); border-color: var(--primary); }

.pill-natureza-wrap { display: flex; flex-wrap: wrap; gap: .35rem; }

.pill-nat {
  background: var(--gray-100);
  border: 1.5px solid var(--gray-200);
  border-radius: 999px;
  padding: .25rem .8rem;
  font-size: .78rem;
  font-weight: 500;
  color: var(--gray-600);
  cursor: pointer;
  transition: all .15s;
  font-family: var(--font);
}

.pill-nat.ativo { background: var(--primary-light); border-color: var(--primary); color: var(--primary); font-weight: 600; }
.pill-nat:hover:not(.ativo) { background: var(--gray-200); }

.dev-toggle {
  display: flex;
  align-items: center;
  gap: .5rem;
  background: var(--gray-100);
  border: 1.5px solid var(--gray-200);
  border-radius: var(--radius-sm);
  padding: .42rem .85rem;
  font-size: .82rem;
  font-family: var(--font);
  color: var(--gray-700);
  cursor: pointer;
  transition: all .15s;
  min-width: 200px;
}

.dev-toggle:hover  { border-color: var(--primary); }
.dev-toggle.aberto { border-color: var(--primary); background: var(--primary-light); color: var(--primary); }
.dev-toggle .seta  { margin-left: auto; font-size: .68rem; transition: transform .2s; }
.dev-toggle.aberto .seta { transform: rotate(180deg); }

.dev-panel {
  display: none;
  background: var(--white);
  border: 1.5px solid var(--gray-200);
  border-radius: var(--radius);
  padding: .4rem;
  margin-top: .35rem;
  max-height: 240px;
  overflow-y: auto;
  position: absolute;
  z-index: 50;
  min-width: 270px;
  box-shadow: var(--shadow-md);
}

.dev-panel.aberto { display: block; }

.dev-item {
  display: flex;
  align-items: center;
  gap: .55rem;
  padding: .42rem .6rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: .83rem;
  color: var(--gray-700);
  transition: background .1s;
}

.dev-item:hover { background: var(--gray-50); }
.dev-item.selecionado { background: var(--primary-light); color: var(--primary); }
.dev-item input[type=checkbox] { accent-color: var(--primary); width: 14px; height: 14px; cursor: pointer; flex-shrink: 0; }

.filtro-rodape {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: .875rem;
  margin-top: .875rem;
  padding-top: .875rem;
  border-top: 1px solid var(--gray-100);
}

.filtro-hint { font-size: .75rem; color: var(--gray-400); margin-right: auto; }

/* ── Buttons ───────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  padding: .52rem 1.05rem;
  border-radius: var(--radius-sm);
  font-size: .84rem;
  font-weight: 600;
  font-family: var(--font);
  cursor: pointer;
  border: none;
  text-decoration: none;
  transition: all .15s;
  white-space: nowrap;
  line-height: 1;
}

.btn-sm { padding: .36rem .78rem; font-size: .78rem; }
.btn-blue    { background: var(--primary); color: white; }
.btn-blue:hover { background: var(--primary-dark); }
.btn-gray    { background: var(--gray-100); color: var(--gray-700); border: 1.5px solid var(--gray-200); }
.btn-gray:hover { background: var(--gray-200); }
.btn-green   { background: var(--success); color: white; }
.btn-green:hover { background: #047857; }
.btn-outline { background: white; color: var(--primary); border: 1.5px solid var(--primary); }
.btn-outline:hover { background: var(--primary-light); }

/* ── Tables ────────────────────────────────────────────────── */
table { width: 100%; border-collapse: collapse; font-size: .875rem; }

th {
  text-align: left;
  font-size: .7rem;
  font-weight: 700;
  color: var(--gray-400);
  text-transform: uppercase;
  letter-spacing: .07em;
  padding: .55rem .9rem;
  border-bottom: 1.5px solid var(--gray-100);
  white-space: nowrap;
}

td {
  padding: .72rem .9rem;
  color: var(--gray-700);
  border-bottom: 1px solid var(--gray-100);
}

tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--gray-50); }

/* ── Badges ────────────────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: .18rem .58rem;
  border-radius: 999px;
  font-size: .7rem;
  font-weight: 600;
  line-height: 1.4;
  white-space: nowrap;
}

.badge-gray   { background: var(--gray-100);      color: var(--gray-600); }
.badge-blue   { background: var(--primary-light);  color: var(--primary); }
.badge-green  { background: var(--success-light);  color: var(--success); }
.badge-red    { background: var(--danger-light);   color: var(--danger); }
.badge-yellow { background: var(--warning-light);  color: var(--warning); }

/* ── Forms ─────────────────────────────────────────────────── */
.form-group { margin-bottom: 1.1rem; }

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .75rem;
}

label {
  display: block;
  font-size: .82rem;
  font-weight: 600;
  color: var(--gray-700);
  margin-bottom: .38rem;
}

input[type=text], input[type=email], input[type=password] {
  width: 100%;
  padding: .58rem .85rem;
  border: 1.5px solid var(--gray-200);
  border-radius: var(--radius-sm);
  font-size: .9rem;
  font-family: var(--font);
  color: var(--gray-800);
  background: white;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}

input[type=text]:focus,
input[type=email]:focus,
input[type=password]:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,.1);
}

/* ── Login ─────────────────────────────────────────────────── */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #0f2447 0%, #1a56db 100%);
  padding: 1.25rem;
}

.login-card {
  background: white;
  border-radius: var(--radius-xl);
  box-shadow: 0 25px 50px rgba(0,0,0,.25);
  padding: 2.5rem 2.25rem;
  width: 100%;
  max-width: 410px;
}

.login-logo { text-align: center; margin-bottom: 2rem; }

.login-logo-img {
  height: 72px;
  max-width: 240px;
  width: auto;
  object-fit: contain;
  display: block;
  margin: 0 auto 1rem;
}

.login-logo-title {
  font-size: 1.2rem;
  font-weight: 800;
  color: var(--gray-900);
  letter-spacing: -.03em;
}

.login-logo-sub { font-size: .82rem; color: var(--gray-400); margin-top: .2rem; }

.login-error {
  background: var(--danger-light);
  border: 1px solid #fecaca;
  color: #991b1b;
  border-radius: var(--radius-sm);
  padding: .65rem .9rem;
  font-size: .84rem;
  margin-bottom: 1.1rem;
  font-weight: 500;
}

/* ── Menu de Módulos ───────────────────────────────────────── */
.menu-page {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2.5rem 1.5rem;
  background: linear-gradient(160deg, #f0f6ff 0%, var(--gray-50) 60%);
}

.menu-header {
  text-align: center;
  margin-bottom: 3rem;
}

.menu-logo {
  height: 90px;
  width: auto;
  object-fit: contain;
  display: block;
  margin: 0 auto 1.5rem;
}

.menu-greeting {
  font-size: 1rem;
  color: var(--gray-500);
  margin-bottom: .25rem;
}

.menu-subtitle {
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--gray-800);
  letter-spacing: -.02em;
}

.menu-grid {
  display: grid;
  grid-template-columns: repeat(3, 200px);
  gap: 1.25rem;
  margin-bottom: 2.5rem;
}

@media (max-width: 680px) {
  .menu-grid { grid-template-columns: repeat(2, 1fr); }
}

.module-card {
  background: var(--white);
  border-radius: var(--radius-lg);
  border: 2px solid var(--gray-200);
  padding: 2rem 1.25rem 1.75rem;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .9rem;
  text-decoration: none;
  color: var(--gray-800);
  transition: all .2s ease;
  box-shadow: var(--shadow-sm);
}

.module-card-clickable { cursor: pointer; }
.module-card-clickable:hover {
  border-color: var(--primary);
  box-shadow: 0 8px 24px rgba(37,99,235,.15);
  transform: translateY(-3px);
}

.module-card-green:hover { border-color: var(--success); box-shadow: 0 8px 24px rgba(5,150,105,.15); }

.module-card-disabled {
  filter: grayscale(100%);
  opacity: .45;
  cursor: not-allowed;
  pointer-events: none;
}

.module-icon {
  width: 62px;
  height: 62px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.module-icon-blue  { background: var(--primary-light);  color: var(--primary); }
.module-icon-green { background: var(--success-light);  color: var(--success); }
.module-icon-gray  { background: var(--gray-100);       color: var(--gray-400); }

.module-title {
  font-weight: 700;
  font-size: .97rem;
  color: var(--gray-900);
}

.module-desc {
  font-size: .78rem;
  color: var(--gray-400);
  line-height: 1.45;
}

.menu-footer {
  font-size: .84rem;
  color: var(--gray-400);
}

.menu-footer a { color: var(--danger); text-decoration: none; font-weight: 600; }
.menu-footer a:hover { text-decoration: underline; }

.menu-back-link {
  font-size: .78rem !important;
  font-weight: 600 !important;
  color: var(--primary) !important;
  text-decoration: none;
  padding: .2rem .5rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--primary-light);
  background: var(--primary-light);
  transition: all .15s;
}
.menu-back-link:hover { background: var(--primary); color: white !important; }

/* ── Clientes ──────────────────────────────────────────────── */
.client-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(270px, 1fr));
  gap: .875rem;
  margin-bottom: 1rem;
}

.client-card {
  background: var(--white);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 1.1rem 1.25rem;
  text-decoration: none;
  color: inherit;
  display: block;
  transition: all .18s;
}

.client-card:hover {
  border-color: var(--primary);
  box-shadow: var(--shadow);
  transform: translateY(-1px);
}
.client-card-inad {
  border-left: 3px solid var(--danger);
}
.client-card-inativo {
  opacity: .72;
  border-left: 3px solid var(--gray-300);
}
.client-card-inativo:hover {
  opacity: 1;
}
.color-danger { color: var(--danger); }

.client-card-codigo { font-size: .7rem; font-weight: 600; color: var(--gray-400); text-transform: uppercase; letter-spacing: .05em; margin-bottom: .3rem; }
.client-card-nome   { font-size: .93rem; font-weight: 700; color: var(--gray-900); margin-bottom: .7rem; line-height: 1.3; }

.client-card-stats {
  display: flex;
  justify-content: space-between;
  padding-top: .7rem;
  border-top: 1px solid var(--gray-100);
  gap: .4rem;
}

.client-stat     { flex: 1; text-align: center; }
.client-stat-val { font-size: .85rem; font-weight: 700; color: var(--gray-800); }
.client-stat-lbl { font-size: .67rem; color: var(--gray-400); text-transform: uppercase; letter-spacing: .04em; }

/* ── Search ────────────────────────────────────────────────── */
.search-wrap {
  display: flex;
  gap: .75rem;
  align-items: center;
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
}

.search-input {
  position: relative;
  flex: 1;
  min-width: 220px;
}

.search-input input[type=text] {
  padding-left: 2.35rem;
  border-radius: var(--radius);
}

.search-icon {
  position: absolute;
  left: .78rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--gray-400);
  pointer-events: none;
  font-size: .85rem;
}

/* ── Tabs ──────────────────────────────────────────────────── */
.tab-bar {
  display: flex;
  gap: .25rem;
  border-bottom: 2px solid var(--gray-200);
  margin-bottom: 1.25rem;
}

.tab-btn {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  padding: .55rem 1.1rem;
  font-size: .86rem;
  font-weight: 600;
  font-family: var(--font);
  color: var(--gray-500);
  cursor: pointer;
  transition: all .15s;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
}

.tab-btn:hover { color: var(--gray-800); background: var(--gray-100); }
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); background: var(--primary-light); }

.tab-content { display: none; }
.tab-content.active { display: block; }

/* ── Modal ─────────────────────────────────────────────────── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15,23,42,.45);
  z-index: 200;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  overflow-y: auto; /* permite rolar o overlay em telas muito pequenas */
}

.modal-overlay.open { display: flex; }

/* Telas baixas: modal ocupa mais altura */
@media (max-height: 700px) {
  .modal-overlay { padding: .25rem; align-items: flex-start; padding-top: .5rem; }
  .modal-box { max-height: 98vh; border-radius: 8px; }
}

.modal-box {
  background: white;
  border-radius: var(--radius-lg);
  box-shadow: 0 20px 60px rgba(0,0,0,.25);
  width: 100%;
  max-width: 560px;
  max-height: 92vh;
  display: flex;
  flex-direction: column;
  overflow-y: auto;   /* permite rolar todo o conteúdo */
  overflow-x: hidden; /* evita scroll horizontal */
}

/* Modais com o padrão novo (modal-layout) têm header/footer fixos via flexbox */
.modal-box.modal-layout {
  overflow: hidden; /* overflow-y tratado por .modal-scroll */
}

/* Cabeçalho fixo do modal — título + botão fechar */
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.4rem;
  border-bottom: 1px solid var(--gray-100);
  flex-shrink: 0;
  background: white;
}
.modal-head h3 { margin: 0; font-size: .98rem; font-weight: 700; color: var(--gray-900); }

/* Área rolável do modal */
.modal-scroll {
  overflow-y: auto;
  flex: 1;
  min-height: 0;
  padding: 1.1rem 1.4rem 0;
}

/* Rodapé fixo com botões */
.modal-foot {
  display: flex;
  gap: .6rem;
  justify-content: flex-end;
  padding: .85rem 1.4rem;
  border-top: 1px solid var(--gray-100);
  flex-shrink: 0;
  background: white;
}

/* Modal com layout header/scroll/foot */
.modal-box.modal-layout { padding: 0; }

/* Form que preenche o espaço restante no modal */
.modal-form {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
}

/* Padding interno do scroll — substitui o padding do modal-box */
.modal-scroll { padding: 1rem 1.4rem 0; }

/* Em modais estreitos, form-row vira coluna única */
@media (max-width: 500px) {
  .form-row { grid-template-columns: 1fr !important; }
  .modal-overlay { padding: .25rem; }
  .modal-box { border-radius: 8px; max-height: 99vh; }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.4rem;
  border-bottom: 1px solid var(--gray-200);
}

.modal-header h3 { font-size: .98rem; font-weight: 700; color: var(--gray-900); margin: 0; }

.modal-close {
  background: none;
  border: none;
  font-size: 1.2rem;
  cursor: pointer;
  color: var(--gray-400);
  padding: .2rem .4rem;
  border-radius: var(--radius-sm);
  line-height: 1;
  transition: color .15s;
  /* Em modais sem modal-layout, o botão flutua no canto direito */
  float: right;
  margin: -.25rem -.25rem 0 .5rem;
}

/* Dentro do modal-head (novo padrão) o float não é necessário */
.modal-head .modal-close {
  float: none;
  margin: 0;
}

.modal-close:hover { color: var(--gray-700); }

.modal-body {
  padding: 1.25rem 1.4rem;
  overflow-y: auto;
  flex: 1;
}

.modal-footer {
  padding: .9rem 1.4rem;
  border-top: 1px solid var(--gray-200);
  display: flex;
  gap: .5rem;
  justify-content: flex-end;
  flex-wrap: wrap;
}

/* ── Message options (modal) ───────────────────────────────── */
.msg-opts { display: flex; flex-direction: column; gap: .6rem; margin-bottom: 1rem; }

.msg-opt {
  border: 2px solid var(--gray-200);
  border-radius: var(--radius);
  padding: .75rem 1rem;
  cursor: pointer;
  transition: all .15s;
}

.msg-opt:hover { border-color: var(--primary); background: var(--primary-light); }
.msg-opt.selected { border-color: var(--primary); background: var(--primary-light); }

.msg-opt-titulo { font-size: .78rem; font-weight: 700; color: var(--gray-600); margin-bottom: .35rem; }
.msg-opt.selected .msg-opt-titulo { color: var(--primary); }

.msg-opt-texto {
  font-size: .83rem;
  color: var(--gray-700);
  white-space: pre-wrap;
  line-height: 1.5;
  max-height: 80px;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── Tom selector (AI modal) ───────────────────────────────── */
.tom-btn {
  background: var(--gray-100);
  border: 1.5px solid var(--gray-200);
  border-radius: 999px;
  padding: .22rem .7rem;
  font-size: .76rem;
  font-weight: 600;
  font-family: var(--font);
  color: var(--gray-600);
  cursor: pointer;
  transition: all .15s;
  white-space: nowrap;
}

.tom-btn:hover { background: var(--primary-light); border-color: var(--primary); color: var(--primary); }
.tom-btn.active { background: var(--primary-light); border-color: var(--primary); color: var(--primary); }

.btn-ia {
  background: linear-gradient(135deg, #7c3aed, #4f46e5);
  color: white;
  border: none;
  display: inline-flex;
  align-items: center;
  gap: .35rem;
}

.btn-ia:hover { filter: brightness(1.1); }
.btn-ia:disabled { opacity: .6; cursor: not-allowed; filter: none; }

/* ── CRM Timeline ──────────────────────────────────────────── */
.crm-timeline { display: flex; flex-direction: column; gap: .6rem; }

.crm-evento {
  display: flex;
  align-items: flex-start;
  gap: .85rem;
  padding: .75rem 1rem;
  background: var(--gray-50);
  border: 1px solid var(--gray-100);
  border-radius: var(--radius);
  position: relative;
}

.crm-icon {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  flex-shrink: 0;
  background: var(--gray-200);
}

.crm-icon.wa      { background: #dcfce7; }
.crm-icon.email   { background: var(--primary-light); }
.crm-icon.ligacao { background: #fef9c3; }
.crm-icon.nota    { background: var(--gray-100); }
.crm-icon.boleto  { background: var(--danger-light); }
.crm-icon.pagto   { background: var(--success-light); }

.crm-body { flex: 1; min-width: 0; }
.crm-meta { font-size: .75rem; color: var(--gray-400); margin-bottom: .2rem; }
.crm-tipo { font-weight: 700; color: var(--gray-700); font-size: .84rem; }
.crm-desc { font-size: .85rem; color: var(--gray-600); margin-top: .15rem; white-space: pre-wrap; }

.crm-excluir {
  background: none;
  border: none;
  color: var(--gray-300);
  cursor: pointer;
  font-size: .75rem;
  padding: .1rem .3rem;
  border-radius: var(--radius-sm);
  transition: color .15s;
  flex-shrink: 0;
}

.crm-excluir:hover { color: var(--danger); }

/* ── KPI mini cards (cliente detalhe) ──────────────────────── */
.kpi-mini-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: .75rem;
  margin-bottom: 1.25rem;
}

.kpi-mini-card {
  background: var(--white);
  border: 1px solid var(--gray-200);
  border-left: 3px solid var(--gray-300);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: .9rem 1.1rem;
}

.kpi-mini-card.kv-red    { border-left-color: var(--danger); }
.kpi-mini-card.kv-green  { border-left-color: var(--success); }
.kpi-mini-card.kv-blue   { border-left-color: var(--primary); }

.kpi-mini-label { font-size: .68rem; font-weight: 700; color: var(--gray-400); text-transform: uppercase; letter-spacing: .07em; margin-bottom: .3rem; }
.kpi-mini-valor { font-size: 1.3rem; font-weight: 800; color: var(--gray-900); letter-spacing: -.03em; line-height: 1.1; }
.kpi-mini-sub   { font-size: .72rem; color: var(--gray-400); margin-top: .2rem; }

/* ── Cards mensais de recebimentos ─────────────────────────── */
.meses-grid {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: .45rem;
  margin-bottom: 1rem;
}
.mes-card {
  background: var(--white);
  border-radius: var(--radius);
  border: 1px solid var(--gray-200);
  border-top: 3px solid var(--gray-300);
  padding: .55rem .5rem .5rem;
  text-align: center;
  box-shadow: var(--shadow-sm);
  min-width: 0;
}
.mes-card.mes-ok    { border-top-color: var(--success); }
.mes-card.mes-warn  { border-top-color: var(--warning); }
.mes-card.mes-alert { border-top-color: var(--danger); }
.mes-card.mes-empty { background: var(--gray-50); }
.mes-card.mes-clickable { cursor: pointer; transition: transform .12s, box-shadow .12s; }
.mes-card.mes-clickable:hover { transform: translateY(-2px); box-shadow: 0 4px 12px rgba(0,0,0,.1); }
.mes-card.mes-selected { outline: 2.5px solid var(--primary); outline-offset: 1px; box-shadow: 0 0 0 4px rgba(37,99,235,.12); }
.mes-nome    { font-size: .68rem; font-weight: 800; color: var(--gray-500); text-transform: uppercase; letter-spacing: .06em; margin-bottom: .3rem; }
.mes-valor   { font-size: .75rem; font-weight: 700; color: var(--gray-900); line-height: 1.2; margin-bottom: .18rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mes-qtd     { font-size: .65rem; color: var(--gray-400); margin-bottom: .12rem; }
.mes-pct     { font-size: .82rem; font-weight: 800; line-height: 1; }
.mes-card.mes-ok    .mes-pct { color: var(--success); }
.mes-card.mes-warn  .mes-pct { color: var(--warning); }
.mes-card.mes-alert .mes-pct { color: var(--danger); }
.mes-sem-dado { font-size: .75rem; color: var(--gray-300); margin-top: .4rem; }
.mes-variacao { font-size: .6rem; font-weight: 700; margin-top: .15rem; letter-spacing: .02em; }
.mes-variacao.var-pos { color: var(--success); }
.mes-variacao.var-neg { color: var(--danger); }
@media (max-width: 1100px) { .meses-grid { grid-template-columns: repeat(6, 1fr); } }
@media (max-width: 600px)  { .meses-grid { grid-template-columns: repeat(4, 1fr); } }

/* ── Print ─────────────────────────────────────────────────── */
@media print {
  .navbar, .no-print { display: none !important; }
  .card, .chart-card, .evo-card, .kpi-total-card, .aging-card, .kpi-rec-card {
    box-shadow: none !important;
    border: 1px solid #ddd;
  }
  body { background: white; }
}
