/* ============================================================
   Cooperville — Sistema Administrativo
   Tokens e estilos base, seguindo o Design System Cooperville v1.0
   ============================================================ */

:root {
  --primary: #4F6228;
  --primary-dark: #34491C;
  --primary-light: #E8EEDB;
  --secondary: #156B13;
  --accent: #D89E00;
  --background: #F6F8F3;
  --surface: #FFFFFF;
  --text-primary: #263018;
  --text-secondary: #6B7280;
  --border: #DDE3D4;
  --success: #16803A;
  --warning: #D89E00;
  --danger: #C0392B;

  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 1px 3px rgba(38, 48, 24, 0.08), 0 1px 2px rgba(38, 48, 24, 0.06);
  --shadow-lg: 0 10px 30px rgba(38, 48, 24, 0.18);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--background);
  color: var(--text-primary);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
}

h1, h2, h3, h4 { margin: 0 0 4px 0; color: var(--text-primary); }
h1 { font-size: 26px; font-weight: 700; }
h2 { font-size: 19px; font-weight: 600; }
h3 { font-size: 15px; font-weight: 600; }
p { margin: 0 0 8px 0; }
a { color: var(--secondary); }

.text-secondary { color: var(--text-secondary); }
.hidden { display: none !important; }

/* ---------- Botões ---------- */
button, .btn {
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  padding: 9px 16px;
  cursor: pointer;
  transition: filter .12s ease, background .12s ease;
}
button:disabled, .btn:disabled { opacity: .55; cursor: not-allowed; }

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { filter: brightness(1.08); }

.btn-secondary { background: var(--primary-light); color: var(--primary-dark); }
.btn-secondary:hover:not(:disabled) { filter: brightness(0.97); }

.btn-neutral { background: var(--surface); color: var(--text-primary); border-color: var(--border); }
.btn-neutral:hover:not(:disabled) { background: #f0f2ec; }

.btn-danger { background: #fff; color: var(--danger); border-color: var(--danger); }
.btn-danger:hover:not(:disabled) { background: #fdf1ef; }

.btn-link { background: none; border: none; color: var(--secondary); padding: 4px 2px; }
.btn-sm { padding: 5px 10px; font-size: 12.5px; }

/* ---------- Inputs / formulários ---------- */
label { display: block; font-weight: 600; font-size: 12.5px; color: var(--text-secondary); margin: 12px 0 5px; }
label.required::after { content: " *"; color: var(--danger); }

input[type=text], input[type=email], input[type=password], input[type=date],
input[type=number], input[type=search], select, textarea {
  width: 100%;
  font-family: inherit;
  font-size: 14px;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text-primary);
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}
textarea { resize: vertical; }

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.form-row.cols-3 { grid-template-columns: 1fr 1fr 1fr; }
.field-hint { font-size: 12px; color: var(--text-secondary); margin-top: 4px; }
.field-error { font-size: 12px; color: var(--danger); margin-top: 4px; }
fieldset { border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; margin: 16px 0 0; }
legend { font-weight: 600; padding: 0 6px; color: var(--primary-dark); }

/* ---------- Cards / superfícies ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 20px;
}

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; margin-bottom: 20px; }
.stat-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); }
.stat-card .stat-value { font-size: 28px; font-weight: 700; color: var(--primary-dark); }
.stat-card .stat-label { font-size: 12.5px; color: var(--text-secondary); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }

/* ---------- Cards de distribuição (dashboard) ---------- */
.breakdown-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 14px; margin-bottom: 20px; }
.breakdown-card h3 { margin-bottom: 14px; }
.breakdown-row { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.breakdown-row:last-child { margin-bottom: 0; }
.breakdown-label { flex: 0 0 128px; font-size: 12.5px; color: var(--text-secondary); font-weight: 600; }
.breakdown-bar-wrap { flex: 1; background: var(--primary-light); border-radius: 999px; height: 10px; overflow: hidden; }
.breakdown-bar { height: 100%; border-radius: 999px; background: var(--primary); }
.breakdown-value { flex: 0 0 30px; text-align: right; font-weight: 700; color: var(--primary-dark); }

/* ---------- Badges ---------- */
.badge { display: inline-block; font-size: 11.5px; font-weight: 700; padding: 3px 9px; border-radius: 999px; text-transform: uppercase; letter-spacing: .02em; }
.badge-success { background: #E5F6EA; color: var(--success); }
.badge-warning { background: #FBF0D6; color: #8A6300; }
.badge-danger  { background: #FBEAE7; color: var(--danger); }
.badge-neutral { background: #EEF0EA; color: var(--text-secondary); }

/* ---------- Tabelas ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
table.data-table { width: 100%; border-collapse: collapse; min-width: 640px; }
table.data-table th {
  text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .03em;
  color: var(--text-secondary); background: var(--primary-light); padding: 10px 14px; border-bottom: 1px solid var(--border);
}
table.data-table td { padding: 10px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.data-table tr:last-child td { border-bottom: none; }
table.data-table tr:hover td { background: #FAFBF8; }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; }

/* ---------- Alertas / estados ---------- */
.alert { border-radius: var(--radius-sm); padding: 10px 14px; font-size: 13.5px; margin-bottom: 14px; border: 1px solid transparent; }
.alert-success { background: #E5F6EA; color: var(--success); border-color: #bfe6c9; }
.alert-danger  { background: #FBEAE7; color: var(--danger); border-color: #f2c6bd; }
.alert-info    { background: var(--primary-light); color: var(--primary-dark); border-color: var(--border); }

.empty-state { text-align: center; padding: 48px 20px; color: var(--text-secondary); }
.loading-state { text-align: center; padding: 40px 20px; color: var(--text-secondary); }

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(38,48,24,.45);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 40px 16px; overflow-y: auto; z-index: 1000;
}
.modal {
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow-lg);
  width: 100%; max-width: 560px; padding: 22px 24px;
}
.modal.modal-wide { max-width: 760px; }
.modal-header { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 6px; }
.modal-close { background: none; border: none; font-size: 20px; line-height: 1; color: var(--text-secondary); padding: 4px 8px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--border); }

/* ============================================================
   Shell (app.html): sidebar + header
   ============================================================ */
.shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 232px; flex-shrink: 0; background: var(--primary-dark); color: #fff;
  display: flex; flex-direction: column; padding: 18px 0;
}
.sidebar .brand { padding: 4px 20px 20px; font-size: 18px; font-weight: 700; letter-spacing: .02em; }
.sidebar .brand span { color: var(--accent); }
.sidebar .brand.brand-logo { display: flex; align-items: center; padding: 0 20px 20px; }
.sidebar .brand.brand-logo img { max-width: 100%; height: 56px; width: auto; object-fit: contain; }
.sidebar nav { flex: 1; }
.sidebar a.nav-item {
  display: flex; align-items: center; gap: 10px; padding: 11px 20px; color: #DCE6C9;
  text-decoration: none; font-size: 13.5px; font-weight: 500; border-left: 3px solid transparent;
}
.sidebar a.nav-item .ic { width: 18px; text-align: center; }
.sidebar a.nav-item:hover { background: rgba(255,255,255,.06); color: #fff; }
.sidebar a.nav-item.active { background: rgba(255,255,255,.10); color: #fff; border-left-color: var(--accent); }
.sidebar a.nav-item.disabled { opacity: .45; pointer-events: none; }
.sidebar .foot { padding: 14px 20px 4px; font-size: 11px; color: #9AAE7C; }

.main-area { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  height: 60px; background: var(--surface); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; padding: 0 22px; flex-shrink: 0;
}
.topbar .page-title { font-size: 16px; font-weight: 700; }
.topbar .user-box { display: flex; align-items: center; gap: 12px; font-size: 13px; color: var(--text-secondary); }
.topbar .user-email { font-weight: 600; color: var(--text-primary); }
.topbar-left { display: flex; align-items: center; gap: 12px; }

/* Botão de menu (hambúrguer) — só aparece em telas estreitas, ver breakpoint 900px abaixo */
.btn-menu-toggle {
  display: none; background: none; border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 6px 10px; font-size: 17px; line-height: 1; color: var(--text-primary); cursor: pointer;
}
.btn-menu-toggle:hover { background: var(--primary-light); }

/* Camada escura atrás do menu lateral quando aberto em telas estreitas */
.sidebar-backdrop { display: none; }

.content { padding: 24px; flex: 1; }
.content-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; margin-bottom: 18px; flex-wrap: wrap; }
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 16px; }
.toolbar input[type=search] { max-width: 280px; }

/* ============================================================
   Login
   ============================================================ */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: var(--primary-dark); padding: 20px; }
.login-card { background: var(--surface); width: 100%; max-width: 380px; border-radius: var(--radius); box-shadow: var(--shadow-lg); padding: 32px 30px; }
.login-card .brand { text-align: center; margin-bottom: 4px; color: var(--primary-dark); font-size: 22px; font-weight: 700; }
.login-card .brand span { color: var(--accent); }
.login-card .subtitle { text-align: center; color: var(--text-secondary); font-size: 13px; margin-bottom: 20px; }

.password-wrap { position: relative; }
.password-wrap input { padding-right: 40px; }
.password-toggle {
  position: absolute; right: 4px; top: 50%; transform: translateY(-50%);
  background: none; border: none; padding: 6px 8px; cursor: pointer;
  color: var(--text-secondary); font-size: 13px; font-weight: 600;
}
.password-toggle:hover { color: var(--text-primary); }
.login-links { display: flex; justify-content: flex-end; margin-top: 6px; }
.login-links button.btn-link { font-size: 12.5px; padding: 2px; }
.login-form-switch { text-align: center; margin-top: 4px; }

/* ============================================================
   Mapa
   ============================================================ */
.map-layout { display: grid; grid-template-columns: 1fr 320px; gap: 16px; height: calc(100vh - 150px); min-height: 480px; }
#map { width: 100%; height: 100%; border-radius: var(--radius); border: 1px solid var(--border); }
.map-panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; overflow-y: auto; }
.lot-icon {
  width: 26px; height: 26px; border-radius: 50%; color: #fff; font-size: 9.5px; font-weight: 700;
  display: flex; align-items: center; justify-content: center; border: 2px solid #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,.35);
}
.lot-icon.ocupada { background: var(--success); }
.lot-icon.disponivel { background: #9AA3AF; }
.lot-icon.corrigir { background: var(--accent); }
.lot-icon.vazio { background: #2563EB; }
.lot-icon.em-construcao { background: #DC2626; }
.legend-item { display: flex; align-items: center; gap: 8px; font-size: 12.5px; margin-bottom: 6px; }
.legend-dot { width: 12px; height: 12px; border-radius: 50%; flex-shrink: 0; }

/* Botões de girar / tela cheia do mapa (ao lado do zoom) */
.map-tool { font-size: 15px !important; }

/* Rótulos de nome de rua desenhados sobre o mapa */
.rua-label-icon { font-size: 11px; font-weight: 700; color: var(--primary-dark); text-shadow: 0 0 3px #fff, 0 0 3px #fff, 0 0 3px #fff; white-space: nowrap; }

/* Tooltip ao passar o mouse sobre um lote (código + cooperado) */
.leaflet-tooltip.lot-tooltip {
  background: var(--surface); color: var(--text-primary); border: 1px solid var(--border);
  border-radius: var(--radius-sm); box-shadow: var(--shadow); font-size: 12.5px; line-height: 1.4;
  padding: 6px 10px;
}
.leaflet-tooltip.lot-tooltip::before { border-top-color: var(--border); }

.map-layers-toggle { display: flex; flex-direction: column; gap: 6px; margin: 10px 0 4px; }
.map-layers-toggle label { display: flex; align-items: center; gap: 7px; font-weight: 400; font-size: 12.5px; color: var(--text-primary); margin: 0; }
.map-layers-toggle input[type=checkbox] { width: auto; }

.street-legend { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.street-chip { background: var(--primary-light); color: var(--primary-dark); font-size: 11.5px; font-weight: 600; padding: 3px 9px; border-radius: 999px; }

.search-result-item { padding: 8px 10px; border-radius: var(--radius-sm); cursor: pointer; font-size: 13.5px; }
.search-result-item:hover { background: var(--primary-light); }

@media (max-width: 900px) {
  .sidebar { position: fixed; left: -232px; top: 0; bottom: 0; z-index: 900; transition: left .18s ease; }
  .sidebar.open { left: 0; }
  .btn-menu-toggle { display: inline-flex; align-items: center; justify-content: center; }
  .sidebar-backdrop.show { display: block; position: fixed; inset: 0; background: rgba(38,48,24,.5); z-index: 850; }
  .map-layout { grid-template-columns: 1fr; height: auto; }
  #map { height: 420px; }
  .form-row, .form-row.cols-3 { grid-template-columns: 1fr; }
}


/* ============================================================
   Financeiro — Dashboard Financeiro (assets/financeiro.js)
   ============================================================ */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 20px; }
.kpi-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.kpi-card .kpi-value { font-size: 22px; font-weight: 700; color: var(--primary-dark); line-height: 1.2; }
.kpi-card .kpi-label { font-size: 11.5px; color: var(--text-secondary); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; margin-top: 4px; }
.kpi-card.kpi-danger .kpi-value { color: var(--danger); }
.kpi-card.kpi-warning .kpi-value { color: #8A6300; }
.kpi-card.kpi-success .kpi-value { color: var(--success); }

.filter-bar { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 18px; }
.filter-field { display: flex; flex-direction: column; min-width: 140px; }
.filter-field label { margin: 0 0 4px; }
.filter-actions { display: flex; gap: 8px; align-items: center; margin-left: auto; }

.charts-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(360px, 1fr)); gap: 16px; margin-bottom: 20px; }
.chart-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 18px; }
.chart-card h3 { margin-bottom: 12px; }
.chart-card .chart-wrap { position: relative; height: 240px; }
.chart-card .chart-empty { display: flex; align-items: center; justify-content: center; height: 240px; color: var(--text-secondary); font-size: 13px; }

.pagination { display: flex; align-items: center; justify-content: flex-end; gap: 10px; padding: 12px 14px; font-size: 12.5px; color: var(--text-secondary); }
.pagination button { padding: 5px 10px; }

th.sortable { cursor: pointer; user-select: none; white-space: nowrap; }
th.sortable .sort-ic { opacity: .5; margin-left: 3px; }
th.sortable.sorted .sort-ic { opacity: 1; }

.badge-info { background: #E6EEFB; color: #1F4FA0; }

@media (max-width: 900px) {
  .filter-field { min-width: 120px; flex: 1 1 45%; }
  .filter-actions { margin-left: 0; width: 100%; justify-content: flex-end; }
}

/* ---------- Financeiro: atalhos de período, chips de filtro ativo,
   indicador de documentação e insights automáticos ---------- */
   .period-presets { display: flex; gap: 6px; flex-wrap: wrap; width: 100%; margin-bottom: 2px; }
   .preset-btn.preset-active { background: var(--primary); color: #fff; border-color: var(--primary); }
   
   .filter-chips { display: flex; flex-wrap: wrap; gap: 8px; margin: -10px 0 18px; }
   .filter-chip { display: inline-flex; align-items: center; gap: 4px; background: var(--primary-light); color: var(--primary-dark); font-size: 12px; font-weight: 600; padding: 4px 6px 4px 10px; border-radius: 999px; }
   .filter-chip-remove { background: none; border: none; color: var(--primary-dark); font-size: 15px; line-height: 1; cursor: pointer; padding: 0 4px; }
   .filter-chip-remove:hover { color: var(--danger); }
   
   .doc-progress-card .doc-progress-track { width: 100%; height: 10px; border-radius: 999px; background: var(--border); overflow: hidden; }
   .doc-progress-card .doc-progress-fill { height: 100%; border-radius: 999px; transition: width .3s ease; }
   
   .insights-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 14px; margin-bottom: 20px; }
   .insight-card { background: var(--primary-light); border-color: var(--primary-light); }
   .insight-card .insight-title { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .03em; color: var(--primary-dark); margin-bottom: 6px; }
   .insight-card .insight-text { font-size: 13.5px; color: var(--text-primary); line-height: 1.45; }
   