/* ============================================================
   MGA Peças Agrícolas — Mapa Estratégico de Expansão Comercial
   Identidade visual: verde #1a6b3a | laranja #f07820
   ============================================================ */

:root {
  --primary:        #1a6b3a;
  --primary-dark:   #124d2a;
  --primary-light:  #1e8449;
  --accent:         #f07820;
  --accent-dark:    #d4651a;
  --sidebar-bg:     #0f3d21;
  --sidebar-hover:  #1a6b3a;
  --sidebar-active: #f07820;
  --text:           #1a2520;
  --text-light:     #ffffff;
  --text-muted:     #6b7280;
  --bg:             #f0f5f2;
  --bg-card:        #ffffff;
  --border:         #dde8e3;
  --shadow:         0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-md:      0 4px 6px rgba(0,0,0,0.07), 0 2px 4px rgba(0,0,0,0.06);
  --radius:         10px;
  --sidebar-w:      260px;
  --header-h:       56px;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%; font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  font-size: 14px; color: var(--text); background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

/* ---- Layout ---- */
.app-container { display: flex; height: 100vh; overflow: hidden; }

/* ---- Sidebar ---- */
.sidebar {
  width: var(--sidebar-w); min-width: var(--sidebar-w);
  background: var(--sidebar-bg); color: var(--text-light);
  display: flex; flex-direction: column; height: 100vh;
  overflow: hidden; transition: width 0.25s ease, min-width 0.25s ease;
  z-index: 100; flex-shrink: 0;
}
.sidebar.collapsed { width: 60px; min-width: 60px; }
.sidebar.collapsed .menu-label,
.sidebar.collapsed .sidebar-title,
.sidebar.collapsed .sidebar-quick-actions,
.sidebar.collapsed .sidebar-footer { opacity: 0; pointer-events: none; white-space: nowrap; }
.sidebar.collapsed .menu-item { justify-content: center; }
.sidebar.collapsed .sidebar-header { justify-content: center; }
.sidebar.collapsed .sidebar-logo { width: 36px; height: 36px; }

.sidebar-header {
  display: flex; align-items: center; gap: 10px; padding: 16px 14px 14px;
  border-bottom: 1px solid rgba(255,255,255,0.08); min-height: 72px;
}
.sidebar-logo {
  width: 58px; height: 58px; object-fit: contain; flex-shrink: 0;
  border-radius: 6px; background: rgba(255,255,255,0.05);
}
.sidebar-title { flex: 1; min-width: 0; }
.sidebar-system-name { display: block; font-weight: 700; font-size: 0.85rem; line-height: 1.2; color: var(--accent); }
.sidebar-company { display: block; font-size: 0.75rem; color: rgba(255,255,255,0.55); margin-top: 1px; }
.sidebar-toggle {
  background: none; border: none; color: rgba(255,255,255,0.5);
  cursor: pointer; font-size: 1.2rem; padding: 4px; border-radius: 4px;
  flex-shrink: 0;
}
.sidebar-toggle:hover { color: white; background: rgba(255,255,255,0.1); }

.sidebar-menu { flex: 1; overflow-y: auto; padding: 8px 0; }
.sidebar-menu::-webkit-scrollbar { width: 4px; }
.sidebar-menu::-webkit-scrollbar-track { background: transparent; }
.sidebar-menu::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.15); border-radius: 2px; }

.menu-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px; cursor: pointer; transition: background 0.15s;
  border-left: 3px solid transparent; user-select: none;
}
.menu-item:hover { background: rgba(255,255,255,0.06); }
.menu-item.active { background: rgba(240,120,32,0.15); border-left-color: var(--accent); }
.menu-item.active .menu-label { color: var(--accent); font-weight: 600; }
.menu-item-inactive { opacity: 0.38; pointer-events: none; cursor: default; }
.menu-icon { font-size: 1rem; width: 20px; text-align: center; flex-shrink: 0; }
.menu-label { font-size: 0.875rem; white-space: nowrap; overflow: hidden; transition: opacity 0.2s; }

/* ---- Sidebar module groups ---- */
.menu-group { list-style: none; }
.menu-group + .menu-group { margin-top: 4px; }
.menu-group-header {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px 8px;
  margin: 4px 8px 0;
  border-radius: 8px;
  background: rgba(255,255,255,0.09);
  border: 1px solid rgba(255,255,255,0.07);
  cursor: pointer; user-select: none;
  transition: background 0.15s, border-color 0.15s;
}
.menu-group-header:hover { background: rgba(255,255,255,0.14); border-color: rgba(255,255,255,0.13); }
.menu-group-label {
  flex: 1; font-size: 0.72rem; font-weight: 700;
  letter-spacing: 0.07em; color: rgba(255,255,255,0.7);
  text-transform: uppercase; white-space: nowrap; overflow: hidden;
  transition: opacity 0.2s;
}
.menu-group-chevron {
  font-size: 0.7rem; color: rgba(255,255,255,0.45); flex-shrink: 0;
  transition: transform 0.2s, opacity 0.2s;
}
.menu-group-chevron.collapsed { transform: rotate(-90deg); }
.menu-group-soon {
  font-size: 0.62rem; color: rgba(255,255,255,0.35); font-style: italic;
  margin-left: auto; white-space: nowrap; transition: opacity 0.2s;
}
.menu-group-items { list-style: none; }
.menu-group-items.collapsed { display: none; }
.menu-group-items .menu-item { padding-left: 24px; }
.menu-group-locked { opacity: 0.35; pointer-events: none; }
.menu-group-locked .menu-group-header { cursor: default; }

/* Settings pinned at bottom */
.sidebar-settings-btn { border-top: 1px solid rgba(255,255,255,0.08); }

/* Collapsed sidebar — hide group labels */
.sidebar.collapsed .menu-group-label,
.sidebar.collapsed .menu-group-chevron,
.sidebar.collapsed .menu-group-soon { opacity: 0; pointer-events: none; width: 0; overflow: hidden; }
.sidebar.collapsed .menu-group-header { justify-content: center; padding: 8px; margin: 4px 6px 0; }
.sidebar.collapsed .menu-group-items .menu-item { padding-left: 14px; justify-content: center; }

.sidebar-footer { padding: 10px 14px; border-top: 1px solid rgba(255,255,255,0.08); }
.data-notice { display: flex; align-items: center; gap: 6px; font-size: 0.75rem; color: rgba(255,255,255,0.4); }

/* ---- Main Content ---- */
.main-content {
  flex: 1; display: flex; flex-direction: column; min-width: 0; overflow: hidden;
}

/* ---- Page Header ---- */
.page-header {
  height: var(--header-h); background: var(--bg-card); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 20px; gap: 12px; flex-shrink: 0; box-shadow: var(--shadow);
}
.header-left { display: flex; align-items: center; gap: 12px; }
.page-title { font-size: 1.1rem; font-weight: 700; color: var(--primary); white-space: nowrap; }
.header-right { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.header-actions { display: flex; gap: 6px; }
.last-update { font-size: 0.75rem; color: var(--text-muted); white-space: nowrap; }
.hamburger {
  display: none; background: none; border: none; cursor: pointer;
  font-size: 1.3rem; color: var(--primary); padding: 4px;
}

/* ---- System Notice ---- */
.system-notice {
  background: #fff8e6; border-bottom: 1px solid #fde68a;
  padding: 6px 20px; font-size: 0.78rem; color: #92400e; flex-shrink: 0;
}

/* ---- Content Area ---- */
.content-area {
  flex: 1; overflow-y: auto; overflow-x: hidden; padding: 20px;
}
.content-area::-webkit-scrollbar { width: 6px; }
.content-area::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ---- Cards ---- */
.card {
  background: var(--bg-card); border-radius: var(--radius);
  box-shadow: var(--shadow); border: 1px solid var(--border); margin-bottom: 16px;
}
.card-header {
  padding: 14px 18px 10px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 6px;
}
.card-header h3 { font-size: 0.95rem; font-weight: 700; color: var(--primary); }
.card-body { padding: 16px 18px; }
.card-badge { font-size: 0.72rem; background: #f0f5f2; color: var(--primary); padding: 2px 8px; border-radius: 20px; font-weight: 600; }
.badge-orange.card-badge { background: #fff3eb; color: var(--accent); }

/* ---- KPI Cards ---- */
.kpi-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 14px; margin-bottom: 20px;
}
.kpi-mini .kpi-card { padding: 12px; }
.kpi-card {
  background: var(--bg-card); border-radius: var(--radius); padding: 18px 16px;
  box-shadow: var(--shadow); border: 1px solid var(--border);
  display: flex; flex-direction: column; align-items: flex-start; gap: 6px;
  border-top: 3px solid var(--border);
}
.kpi-blue { border-top-color: #2563eb; }
.kpi-green { border-top-color: var(--primary-light); }
.kpi-orange { border-top-color: var(--accent); }
.kpi-red { border-top-color: #dc2626; }
.kpi-gray { border-top-color: #9ca3af; }
.kpi-icon { font-size: 1.4rem; }
.kpi-value { font-size: 1.8rem; font-weight: 800; color: var(--text); line-height: 1; }
.kpi-value-sm { font-size: 1.1rem; }
.kpi-label { font-size: 0.78rem; color: var(--text-muted); line-height: 1.3; }

/* ---- Dashboard Grid ---- */
.dashboard { display: flex; flex-direction: column; gap: 0; }
.dashboard-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 16px; margin-bottom: 16px; }
.dashboard-grid > * { min-width: 0; }
.chart-card .card-body { height: 270px; position: relative; }

/* ---- Alerts ---- */
.alert {
  display: flex; align-items: flex-start; gap: 8px; padding: 10px 14px;
  border-radius: 8px; margin-bottom: 8px; font-size: 0.875rem;
}
.alert-icon { flex-shrink: 0; }
.alert-danger { background: #fef2f2; border: 1px solid #fecaca; color: #991b1b; }
.alert-warning { background: #fffbeb; border: 1px solid #fde68a; color: #92400e; }
.alert-info { background: #eff6ff; border: 1px solid #bfdbfe; color: #1e40af; }
.alert-success { background: #f0fdf4; border: 1px solid #bbf7d0; color: #14532d; }

/* ---- Buttons ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 16px; border-radius: 7px; font-size: 0.875rem; font-weight: 600;
  cursor: pointer; border: 1.5px solid transparent; transition: all 0.15s;
  text-decoration: none; white-space: nowrap; line-height: 1;
}
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-sm { padding: 5px 12px; font-size: 0.8rem; }
.btn-primary { background: var(--primary); color: white; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }
.btn-outline { background: transparent; color: var(--primary); border-color: var(--border); }
.btn-outline:hover { background: var(--bg); border-color: var(--primary); }
.btn-danger { background: #dc2626; color: white; border-color: #dc2626; }
.btn-danger:hover { background: #b91c1c; }
.btn-danger-outline { background: transparent; color: #dc2626; border-color: #fecaca; }
.btn-danger-outline:hover { background: #fef2f2; }
.icon-btn {
  background: none; border: none; cursor: pointer; padding: 3px 6px;
  font-size: 0.95rem; border-radius: 4px; transition: background 0.15s;
}
.icon-btn:hover { background: var(--bg); }
.icon-btn.danger:hover { background: #fef2f2; }
.icon-btn:disabled { opacity: 0.3; cursor: not-allowed; }

/* ---- Badges ---- */
.badge {
  display: inline-flex; align-items: center; padding: 2px 8px; border-radius: 12px;
  font-size: 0.72rem; font-weight: 600; white-space: nowrap;
}
.badge-green { background: #dcfce7; color: #14532d; }
.badge-blue { background: #dbeafe; color: #1e40af; }
.badge-yellow { background: #fef9c3; color: #713f12; }
.badge-orange { background: #ffedd5; color: #9a3412; }
.badge-red { background: #fee2e2; color: #991b1b; }
.badge-gray { background: #f3f4f6; color: #374151; }
.badge-purple { background: #f3e8ff; color: #6b21a8; }
.demo-badge { display: inline-flex; align-items: center; padding: 1px 6px; border-radius: 10px; font-size: 0.65rem; font-weight: 700; background: #fef9c3; color: #713f12; margin-left: 6px; border: 1px solid #fde047; }

/* ---- Tables ---- */
.table-card { overflow: hidden; }
.table-wrap { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 0.875rem; }
.data-table th {
  background: #f8faf9; color: var(--primary); font-weight: 700; font-size: 0.78rem;
  text-transform: uppercase; letter-spacing: 0.03em; padding: 10px 12px;
  border-bottom: 2px solid var(--border); white-space: nowrap; text-align: left;
}
.data-table th.sortable { cursor: pointer; user-select: none; }
.data-table th.sortable:hover { background: #f0f5f2; }
.data-table th.sorted { color: var(--accent); }
.data-table td { padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: #f8faf9; }
.data-table tr.demo-row td { background: #fffbf0; }
.data-table tr.row-overdue td { background: #fff5f5; }
.action-cell { white-space: nowrap; }
.table-footer { padding: 10px 16px; font-size: 0.8rem; color: var(--text-muted); border-top: 1px solid var(--border); }

/* ---- Forms ---- */
.form-grid { display: flex; flex-direction: column; gap: 0; }
.form-section { border-bottom: 1px solid var(--border); padding-bottom: 16px; margin-bottom: 16px; }
.form-section:last-child { border-bottom: none; margin-bottom: 0; }
.form-section h4 { font-size: 0.85rem; font-weight: 700; color: var(--primary); text-transform: uppercase; letter-spacing: 0.04em; margin-bottom: 12px; }
.form-group { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.form-group:last-child { margin-bottom: 0; }
.form-row { display: flex; gap: 12px; margin-bottom: 12px; }
.form-row .form-group { flex: 1; margin-bottom: 0; }
label { font-size: 0.8rem; font-weight: 600; color: var(--text); }
input, select, textarea {
  padding: 8px 11px; border: 1.5px solid var(--border); border-radius: 7px;
  font-size: 0.875rem; color: var(--text); background: white;
  transition: border-color 0.15s; width: 100%; font-family: inherit;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(26,107,58,0.1); }
textarea { resize: vertical; min-height: 60px; }
input[type="color"] { padding: 2px; cursor: pointer; }

.checkbox-grid { display: flex; flex-wrap: wrap; gap: 6px; max-height: 160px; overflow-y: auto; padding: 8px; border: 1.5px solid var(--border); border-radius: 7px; background: #fafafa; }
.checkbox-item { display: flex; align-items: center; gap: 5px; font-size: 0.78rem; font-weight: 500; padding: 2px 6px; cursor: pointer; background: white; border: 1px solid var(--border); border-radius: 5px; }
.checkbox-item:has(input:checked) { background: #dcfce7; border-color: var(--primary-light); color: var(--primary); }
.checkbox-item input { width: auto; margin: 0; flex-shrink: 0; }

.demo-notice { background: #fffbeb; border: 1px solid #fde68a; border-radius: 7px; padding: 10px 14px; font-size: 0.825rem; color: #92400e; margin-bottom: 14px; }
.search-input { padding: 7px 12px; border: 1.5px solid var(--border); border-radius: 7px; font-size: 0.85rem; min-width: 220px; }
.filter-select { padding: 7px 10px; border: 1.5px solid var(--border); border-radius: 7px; font-size: 0.85rem; background: white; }

/* ---- Module layout ---- */
.module-layout { display: flex; flex-direction: column; gap: 0; }
.module-toolbar { padding: 12px 16px !important; display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 10px; margin-bottom: 16px; }
.toolbar-left, .toolbar-right { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.view-toggle { display: flex; border: 1.5px solid var(--border); border-radius: 7px; overflow: hidden; }
.view-btn { padding: 5px 10px; background: white; border: none; cursor: pointer; font-size: 1rem; transition: background 0.15s; color: var(--text-muted); }
.view-btn.active { background: var(--primary); color: white; }
.view-btn:hover:not(.active) { background: var(--bg); }
.empty-state { text-align: center; padding: 40px 20px !important; }
.empty-state p { color: var(--text-muted); margin-bottom: 16px; font-size: 1rem; }

/* ---- Cards grid ---- */
.cards-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; }
.rep-card, .opp-card { border-left: 4px solid var(--primary); }
.rep-card.demo-card, .opp-card.demo-card { border-left-color: #fde047; }
.card-overdue { border-left-color: #dc2626 !important; }
.rep-card-header { display: flex; justify-content: space-between; align-items: flex-start; padding: 14px 16px 10px; border-bottom: 1px solid var(--border); gap: 8px; }
.rep-card-body { padding: 12px 16px; }
.rep-card-actions { padding: 10px 16px; border-top: 1px solid var(--border); display: flex; gap: 6px; flex-wrap: wrap; }

/* ---- Info rows ---- */
.info-row { display: flex; justify-content: space-between; align-items: flex-start; padding: 4px 0; font-size: 0.875rem; gap: 8px; }
.info-row span:first-child { color: var(--text-muted); flex-shrink: 0; }
.info-row strong { color: var(--text); }
.text-danger { color: #dc2626; }
.text-muted { color: var(--text-muted); }

/* ---- Map ---- */
.map-layout { display: grid; grid-template-columns: 280px 1fr; gap: 16px; height: calc(100vh - var(--header-h) - 70px); }
.map-controls { overflow-y: auto; padding: 0 !important; }
.map-filters { padding: 14px 16px; border-bottom: 1px solid var(--border); display: flex; flex-direction: column; gap: 8px; }
.map-filters label { font-size: 0.78rem; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.03em; margin-bottom: 2px; }
.map-legend { padding: 14px 16px; }
.map-legend h4 { font-size: 0.85rem; font-weight: 700; color: var(--primary); margin-bottom: 10px; text-transform: uppercase; letter-spacing: 0.04em; }
.legend-item { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; font-size: 0.82rem; }
.legend-dot { width: 14px; height: 14px; border-radius: 50%; flex-shrink: 0; }
.map-container-wrap { position: relative; display: flex; flex-direction: column; min-height: 450px; }
.brazil-map { flex: 1; min-height: 450px; border-radius: var(--radius); border: 1px solid var(--border); }
.map-notice { position: absolute; bottom: 12px; left: 50%; transform: translateX(-50%); background: rgba(0,0,0,0.6); color: white; padding: 5px 12px; border-radius: 20px; font-size: 0.75rem; pointer-events: none; white-space: nowrap; }
.map-error { display: flex; flex-direction: column; align-items: center; justify-content: center; height: 100%; gap: 8px; color: var(--text-muted); text-align: center; padding: 20px; }

/* ---- State Panel ---- */
.state-panel {
  position: fixed; right: -440px; top: 0; width: 420px; height: 100vh;
  background: white; box-shadow: -4px 0 24px rgba(0,0,0,0.12);
  z-index: 1000; transition: right 0.3s ease; display: flex; flex-direction: column;
  border-left: 1px solid var(--border);
}
.state-panel.open { right: 0; }
.state-panel-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 18px; background: var(--primary); color: white; flex-shrink: 0;
}
.state-panel-header h2 { font-size: 1rem; font-weight: 700; }
.state-panel-body { flex: 1; overflow-y: auto; padding: 0; }
.state-panel-section { padding: 14px 18px; border-bottom: 1px solid var(--border); }
.state-panel-section h4 { font-size: 0.8rem; font-weight: 700; color: var(--primary); text-transform: uppercase; letter-spacing: 0.04em; margin-bottom: 8px; }
.state-panel-actions { padding: 14px 18px; display: flex; gap: 6px; flex-wrap: wrap; }
.potential-bar { height: 6px; background: #e5e7eb; border-radius: 3px; flex: 1; min-width: 60px; overflow: hidden; }
.potential-fill { height: 100%; border-radius: 3px; transition: width 0.5s ease; }
.auto-reading { font-size: 0.875rem; color: #374151; line-height: 1.6; background: #f8faf9; padding: 12px; border-radius: 8px; border-left: 3px solid var(--primary); }
.close-btn { background: rgba(255,255,255,0.15); border: none; color: white; cursor: pointer; width: 28px; height: 28px; border-radius: 50%; font-size: 0.9rem; display: flex; align-items: center; justify-content: center; transition: background 0.15s; }
.close-btn:hover { background: rgba(255,255,255,0.3); }

/* ---- Modal ---- */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.45); z-index: 300; display: none; backdrop-filter: blur(2px); }
.modal-overlay.open { display: block; }
.modal {
  position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%) scale(0.95);
  background: white; border-radius: 12px; box-shadow: 0 20px 60px rgba(0,0,0,0.2);
  z-index: 301; width: 90%; max-width: 700px; max-height: 90vh;
  display: none; flex-direction: column; transition: transform 0.2s ease;
}
.modal.open { display: flex; transform: translate(-50%, -50%) scale(1); }
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--border); flex-shrink: 0; }
.modal-title { font-size: 1rem; font-weight: 700; color: var(--primary); }
.modal-body { flex: 1; overflow-y: auto; padding: 20px; }
.modal-footer { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; flex-shrink: 0; }

/* ---- Toast ---- */
.toast-container { position: fixed; bottom: 20px; right: 20px; z-index: 500; display: flex; flex-direction: column; gap: 8px; }
.toast {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 12px 16px; border-radius: 8px; box-shadow: var(--shadow-md);
  font-size: 0.875rem; min-width: 240px; max-width: 400px;
  animation: slideIn 0.2s ease;
}
.toast-success { background: #14532d; color: white; }
.toast-error { background: #991b1b; color: white; }
.toast-warning { background: #92400e; color: white; }
.toast-info { background: #1e40af; color: white; }
.toast button { background: none; border: none; color: white; cursor: pointer; opacity: 0.7; font-size: 0.9rem; padding: 0 2px; }
.toast button:hover { opacity: 1; }
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* ---- Strategic Reading ---- */
.strategic-reading { margin-bottom: 16px; }

/* ---- Agriculture / Potencial ---- */
.matrix-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-bottom: 12px; }
.matrix-quadrant { background: #fafafa; border: 1px solid var(--border); border-radius: 8px; padding: 14px; }
.matrix-label { font-weight: 700; font-size: 0.9rem; margin-bottom: 4px; }
.matrix-desc { font-size: 0.78rem; color: var(--text-muted); margin-bottom: 10px; }
.matrix-states { display: flex; flex-wrap: wrap; gap: 5px; }

.uf-badge { display: inline-flex; align-items: center; padding: 3px 7px; border-radius: 5px; font-size: 0.75rem; font-weight: 700; border: 1.5px solid #9ca3af; color: #374151; cursor: pointer; transition: transform 0.1s; }
.uf-badge:hover { transform: scale(1.05); }
.uf-grid { display: flex; flex-wrap: wrap; gap: 5px; margin-bottom: 8px; }

.coverage-summary .card-body { padding: 12px 18px !important; }

/* ---- Culture rows ---- */
.culture-row { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; font-size: 0.875rem; }
.culture-name { width: 140px; flex-shrink: 0; font-weight: 500; }
.culture-bar-wrap { flex: 1; height: 8px; background: #e5e7eb; border-radius: 4px; overflow: hidden; }
.culture-bar { height: 100%; background: var(--primary); border-radius: 4px; transition: width 0.4s; }
.culture-count { font-size: 0.78rem; color: var(--text-muted); width: 70px; text-align: right; }

/* ---- Opportunities ---- */
.funnel-stage { border: 1px solid var(--border); border-radius: 8px; overflow: hidden; margin-bottom: 6px; }
.funnel-stage-header { display: flex; align-items: center; padding: 10px 14px; background: #f8faf9; cursor: pointer; gap: 10px; font-size: 0.875rem; }
.funnel-stage-header:hover { background: #f0f5f2; }
.funnel-label { flex: 1; font-weight: 600; }
.funnel-count { background: var(--primary); color: white; width: 22px; height: 22px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 0.75rem; font-weight: 700; flex-shrink: 0; }
.funnel-value { font-size: 0.82rem; color: var(--text-muted); }
.funnel-items { display: none; }
.funnel-stage.expanded .funnel-items { display: block; }
.opp-mini { display: flex; align-items: center; gap: 10px; padding: 8px 14px; border-top: 1px solid var(--border); font-size: 0.82rem; }
.opp-mini-title { flex: 1; }
.opp-mini-value { font-weight: 600; font-size: 0.8rem; color: var(--primary); }
.opp-mini-overdue { background: #fff5f5; }

/* ---- Actions/Kanban ---- */
.kanban-board { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; }
.kanban-col { background: #f8faf9; border-radius: 8px; padding: 12px; min-height: 300px; }
.kanban-col-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; padding-bottom: 8px; border-bottom: 2px solid; }
.kanban-count { background: #e5e7eb; width: 22px; height: 22px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 0.75rem; font-weight: 700; }
.kanban-card { background: white; border-radius: 6px; padding: 10px 12px; margin-bottom: 6px; box-shadow: var(--shadow); border: 1px solid var(--border); }
.kanban-overdue { border-left: 3px solid #dc2626; }
.kanban-card-title { font-weight: 600; font-size: 0.85rem; margin-bottom: 6px; }
.kanban-card-meta { display: flex; justify-content: space-between; font-size: 0.75rem; color: var(--text-muted); margin-bottom: 6px; }
.kanban-card-footer { display: flex; justify-content: space-between; align-items: center; font-size: 0.75rem; }

/* ---- Reports ---- */
.reports-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 14px; }
.report-card { display: flex; gap: 14px; align-items: flex-start; padding: 16px; background: #fafafa; border: 1px solid var(--border); border-radius: 8px; }
.report-icon { font-size: 1.8rem; flex-shrink: 0; }
.report-info { flex: 1; }
.report-info h4 { font-size: 0.9rem; font-weight: 700; color: var(--text); margin-bottom: 4px; }
.report-info p { font-size: 0.8rem; color: var(--text-muted); line-height: 1.4; }
.report-actions { display: flex; flex-direction: column; gap: 4px; flex-shrink: 0; }

/* ---- Settings ---- */
.settings-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(380px, 1fr)); gap: 16px; }

/* ---- Scrollbar global ---- */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #d1d5db; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #9ca3af; }

/* ---- Responsive ---- */
@media (max-width: 1200px) {
  .map-layout { grid-template-columns: 240px 1fr; }
}

/* ---- Tablet (≤ 900px) ---- */
@media (max-width: 900px) {
  .sidebar { position: fixed; left: -280px; transition: left 0.25s; z-index: 2000; }
  .sidebar.open { left: 0; box-shadow: 4px 0 24px rgba(0,0,0,0.25); }
  .hamburger { display: flex; }

  /* Overlay escuro atrás do sidebar no mobile */
  .sidebar-backdrop { display: block; }

  .header-actions .btn:not(.btn-primary) { display: none; }
  .last-update { display: none; }

  .map-layout { grid-template-columns: 1fr; grid-template-rows: auto 1fr; height: auto; }
  .brazil-map { height: 420px; }

  .dashboard-grid { grid-template-columns: 1fr !important; }
  .matrix-grid { grid-template-columns: 1fr; }
  .form-row { flex-direction: column; }

  .modal { max-width: 98%; max-height: 95vh; }
  .state-panel { width: 100%; right: -100%; }

  .reports-grid { grid-template-columns: 1fr; }
  .settings-grid { grid-template-columns: 1fr !important; }

  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
}

/* ---- Mobile (≤ 600px) ---- */
@media (max-width: 600px) {
  .content-area { padding: 10px; }

  .page-header { padding: 0 12px; gap: 8px; }
  .page-title { font-size: 0.9rem; }
  .user-email { display: none; }
  .header-right { gap: 6px; }

  .kpi-grid { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .kpi-card { padding: 10px 12px; }
  .kpi-value { font-size: 1.4rem; }

  .cards-grid { grid-template-columns: 1fr; }
  .kanban-board { grid-template-columns: 1fr; }

  .brazil-map { height: 320px; }

  .system-notice { display: none; }

  .btn-sm { padding: 5px 10px; font-size: 0.78rem; }

  /* Tabelas com scroll horizontal no mobile */
  .table-wrap, .data-table { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; }

  /* Map controls em baixo do mapa no mobile */
  .map-controls { order: 2; }
  .map-container-wrap { order: 1; }
}

/* Backdrop do sidebar no mobile */
.sidebar-backdrop {
  display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.45);
  z-index: 1999; cursor: pointer;
}

/* ---- Module Tabs (Faturamento, etc.) ---- */
.module-tabs { display: flex; border-bottom: 2px solid var(--border); background: #f8faf9; border-radius: var(--radius) var(--radius) 0 0; }
.tab-btn { padding: 13px 20px; background: none; border: none; cursor: pointer; font-size: 0.875rem; font-weight: 600; color: var(--text-muted); border-bottom: 2px solid transparent; margin-bottom: -2px; transition: all 0.15s; white-space: nowrap; }
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); background: white; }
.tab-btn:hover:not(.active) { color: var(--text); background: #f0f5f2; }

/* ---- Map Panel Tabs ---- */
.map-panel-tabs { display: flex; border-bottom: 1px solid var(--border); }
.map-tab-btn { flex: 1; padding: 10px 6px; background: none; border: none; cursor: pointer; font-size: 0.8rem; font-weight: 600; color: var(--text-muted); border-bottom: 2px solid transparent; margin-bottom: -1px; transition: all 0.15s; }
.map-tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); background: #f8faf9; }
.map-tab-btn:hover:not(.active) { background: var(--bg); }

/* ---- KPI sublabel ---- */
.kpi-sublabel { font-size: 0.72rem; color: var(--text-muted); margin-top: 1px; }

/* ---- CFOP Config (Settings) ---- */
.cfop-row { padding: 3px 0; }
.cfop-toggle { display: flex; align-items: center; gap: 8px; cursor: pointer; font-size: 0.83rem; }
.cfop-toggle input[type=checkbox] { width: 15px; height: 15px; accent-color: var(--primary); flex-shrink: 0; cursor: pointer; }
.cfop-code { font-weight: 700; font-family: monospace; color: var(--primary); min-width: 44px; }
.cfop-desc { color: var(--text-muted); }

/* ---- Territory panel items (inside map) ---- */
.terr-panel-item { padding: 10px 14px; border-bottom: 1px solid var(--border); display: flex; align-items: flex-start; gap: 8px; font-size: 0.82rem; }
.terr-panel-item:last-child { border-bottom: none; }
.terr-panel-info { flex: 1; min-width: 0; }
.terr-panel-name { font-weight: 600; color: var(--text); margin-bottom: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.terr-panel-meta { color: var(--text-muted); font-size: 0.75rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---- Login ---- */
.login-overlay {
  position: fixed; inset: 0; z-index: 9999;
  background: url('frontend-inicial.png') center center / cover no-repeat;
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
}
.login-overlay::before {
  content: ''; position: absolute; inset: 0;
  background: rgba(10, 30, 16, 0.52);
}
.login-box {
  position: relative; z-index: 1;
  background: #fff; border-radius: 16px; padding: 2.5rem;
  width: 100%; max-width: 520px; text-align: center;
  box-shadow: 0 25px 60px rgba(0,0,0,0.45);
  transform: translateY(15%);
}
.login-title { font-size: 1.4rem; font-weight: 700; color: var(--primary); margin-bottom: 0.2rem; }
.login-subtitle { color: var(--text-muted); font-size: 0.875rem; margin-bottom: 2rem; }
.login-field { text-align: left; margin-bottom: 1rem; }
.login-field label { display: block; font-size: 0.825rem; font-weight: 600; color: var(--text); margin-bottom: 0.35rem; }
.login-field input {
  width: 100%; padding: 0.7rem 1rem; border: 1.5px solid var(--border);
  border-radius: 8px; font-size: 0.95rem; box-sizing: border-box; transition: border-color 0.2s;
}
.login-field input:focus { outline: none; border-color: var(--primary); }
.login-btn { width: 100%; padding: 0.8rem; font-size: 1rem; margin-top: 0.5rem; }
.login-error { color: #dc2626; font-size: 0.825rem; margin: 0.4rem 0 0; }

/* ---- Header user ---- */
.header-user { display: flex; align-items: center; gap: 0.6rem; }
.user-email { font-size: 0.8rem; color: var(--text-muted); max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---- Visão Executiva (exec dashboard) ---- */
.exec-import-bar {
  display: flex; align-items: center; justify-content: space-between;
  background: #f8faf9; border: 1px solid #e5e7eb; border-radius: 8px;
  padding: 8px 14px; margin-bottom: 12px; flex-wrap: wrap; gap: 8px;
}
.exec-filters {
  margin-bottom: 12px !important;
  padding: 10px 14px !important;
}
.exec-filter-row {
  display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end;
}
.filter-group {
  display: flex; flex-direction: column; gap: 3px;
}
.filter-group label {
  font-size: 0.72rem; font-weight: 700; color: #6b7280; text-transform: uppercase; letter-spacing: .04em;
}
.filter-group select {
  border: 1px solid var(--border); border-radius: 6px; padding: 5px 8px;
  font-size: 0.82rem; background: #fff; color: var(--text);
  min-width: 120px; cursor: pointer;
}
.filter-group select:focus { outline: none; border-color: var(--primary); }
.chart-card .card-body { padding: 8px 10px !important; }

/* ---- Botão de importação + ícone de ajuda ---- */
/* Visão Executiva e DRE compartilham o mesmo botão: funções distintas, layout único. */
.import-btn-group { display: inline-flex; align-items: center; gap: 6px; }
.btn-import-erp {
  background: #15803d; color: #fff; border-color: #15803d; font-size: 0.76rem;
}
.btn-import-erp:hover { background: #166534; border-color: #166534; color: #fff; }

.info-hint {
  position: relative; display: inline-flex; align-items: center; justify-content: center;
  width: 18px; height: 18px; border-radius: 50%; flex-shrink: 0;
  border: 1.5px solid #9ca3af; background: #fff; color: #6b7280;
  font: italic 700 0.72rem/1 Georgia, "Times New Roman", serif;
  cursor: help; user-select: none;
}
.info-hint:hover, .info-hint:focus-visible { border-color: var(--primary); color: var(--primary); outline: none; }

.info-hint-bubble {
  position: absolute; z-index: 300; top: calc(100% + 9px); right: -4px;
  width: max-content; max-width: min(320px, 78vw);
  background: #1f2937; color: #f3f4f6; border-radius: 8px; padding: 10px 12px;
  /* o "i" é serif itálico; o balão volta à tipografia normal da interface */
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif; font-style: normal; font-weight: 400;
  font-size: 0.76rem; line-height: 1.5; text-align: left; white-space: normal;
  box-shadow: 0 10px 28px rgba(0,0,0,0.28);
  opacity: 0; visibility: hidden; transform: translateY(-4px);
  transition: opacity .14s ease, transform .14s ease, visibility .14s;
  pointer-events: none;
}
.info-hint:hover .info-hint-bubble,
.info-hint:focus-visible .info-hint-bubble { opacity: 1; visibility: visible; transform: none; }
.info-hint-bubble::before {
  content: ''; position: absolute; bottom: 100%; right: 8px;
  border: 6px solid transparent; border-bottom-color: #1f2937;
}
.info-hint-title {
  display: block; font-weight: 700; font-size: 0.72rem; letter-spacing: .04em;
  text-transform: uppercase; color: var(--accent); margin-bottom: 6px;
}
.info-hint-path { margin: 0; padding-left: 16px; }
.info-hint-path li { margin: 2px 0; }
.info-hint-path li:last-child { font-weight: 700; color: #fff; }
.info-hint-note {
  display: block; margin-top: 8px; padding-top: 7px;
  border-top: 1px solid rgba(255,255,255,0.14);
  font-size: 0.72rem; color: rgba(255,255,255,0.66);
}

/* ---- Home Page ---- */

/* No Início não há navegação lateral: a tela existe justamente para escolher o
   módulo. A lateral entra quando o usuário abre um deles. */
.app-container.home-mode .sidebar,
.app-container.home-mode .sidebar-backdrop,
.app-container.home-mode .hamburger { display: none !important; }
.app-container.home-mode .main-content { margin-left: 0; }

.home-page { max-width: 900px; margin: 0 auto; padding: 4px 0 48px; }

.home-welcome {
  display: flex; align-items: center; gap: 24px;
  background: var(--bg-card); border-radius: var(--radius);
  padding: 28px 32px; margin-bottom: 40px;
  box-shadow: var(--shadow);
  border-left: 5px solid var(--primary);
}
.home-logo { height: 68px; width: auto; object-fit: contain; flex-shrink: 0; }
.home-greeting { font-size: 1.7rem; font-weight: 700; color: var(--primary); margin-bottom: 4px; }
.home-subtitle { font-size: 0.95rem; color: var(--text-muted); margin: 0; }

.home-groups {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 18px;
}
.home-group-card {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; gap: 12px;
  border-radius: 14px; padding: 36px 20px;
  transition: transform .16s, box-shadow .16s;
}
.home-group-active {
  background: var(--primary); color: #fff;
  cursor: pointer; box-shadow: 0 4px 18px rgba(26,107,58,0.18);
  border: 2px solid transparent;
}
.home-group-active:hover {
  transform: translateY(-4px);
  box-shadow: 0 10px 32px rgba(26,107,58,0.28);
}
.home-group-inactive {
  background: var(--bg-card); color: var(--text-muted);
  border: 2px solid var(--border);
  opacity: 0.35; cursor: default; pointer-events: none;
}
.home-group-icon { font-size: 2.6rem; line-height: 1; }
.home-group-title { font-size: 1.05rem; font-weight: 700; letter-spacing: .01em; }
.home-group-desc { font-size: 0.78rem; line-height: 1.5; opacity: 0.85; }

@media (max-width: 640px) {
  .home-welcome { flex-direction: column; align-items: flex-start; padding: 20px; }
  .home-groups { grid-template-columns: 1fr 1fr; gap: 12px; }
  .home-group-card { padding: 24px 14px; }
}

/* ---- Indicador de carregamento de seção ---- */
.section-loading {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 14px; height: 260px; color: var(--text-muted); font-size: 0.9rem;
}
.spinner {
  width: 34px; height: 34px; border-radius: 50%;
  border: 3px solid var(--border); border-top-color: var(--primary);
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  .spinner { animation-duration: 2s; }
}

/* ---- DRE ---- */
.dre-toolbar { justify-content: flex-start !important; align-items: flex-end !important; }
.dre-filter { display: flex; flex-direction: column; gap: 3px; }
.dre-filter label { font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-muted); font-weight: 600; }
.dre-filter select { padding: 6px 8px; border: 1px solid var(--border); border-radius: 6px; font-size: 0.85rem; background: #fff; max-width: 220px; }

.dre-alert {
  background: #fef3c7; border: 1px solid #fcd34d; color: #92400e;
  padding: 10px 14px; border-radius: 8px; margin-bottom: 16px; font-size: 0.86rem;
}
.dre-alert a { color: #92400e; font-weight: 600; }

.dre-card { padding: 0 !important; overflow: hidden; }
.dre-scroll { overflow-x: auto; }
.dre-table { width: 100%; border-collapse: collapse; font-size: 0.84rem; white-space: nowrap; }
.dre-table th, .dre-table td { padding: 7px 12px; border-bottom: 1px solid var(--border); }
.dre-table thead th {
  position: sticky; top: 0; background: var(--bg); font-size: 0.74rem;
  text-transform: uppercase; letter-spacing: 0.03em; color: var(--text-muted);
}
.dre-table .dre-label { text-align: left; position: sticky; left: 0; background: #fff; z-index: 1; min-width: 260px; }
.dre-table thead .dre-label { background: var(--bg); z-index: 2; }
.dre-num { text-align: right; font-variant-numeric: tabular-nums; }
.dre-total-col { border-left: 2px solid var(--border); font-weight: 600; }

.dre-receita  td { background: #eef6f1; font-weight: 700; }
.dre-receita  .dre-label { background: #eef6f1; }
.dre-grupo    td { font-weight: 600; }
.dre-detalhe  td { color: var(--text-muted); font-size: 0.8rem; }
.dre-subtotal td { background: #f7faf8; font-weight: 700; border-top: 1px solid var(--border); }
.dre-subtotal .dre-label { background: #f7faf8; }
.dre-resultado td { background: var(--primary); color: #fff; font-weight: 700; }
.dre-resultado .dre-label { background: var(--primary); color: #fff; }
.dre-margem td { font-size: 0.76rem; color: var(--primary-light); font-style: italic; padding-top: 2px; padding-bottom: 6px; border-bottom: none; }
.dre-memo-header td {
  background: var(--bg); font-size: 0.72rem; text-transform: uppercase;
  letter-spacing: 0.05em; color: var(--text-muted); font-weight: 700; padding-top: 14px;
}
.dre-nota { font-size: 0.78rem; color: var(--text-muted); line-height: 1.6; margin-top: 14px; }

/* ---- CFOP de entrada (configurações) ---- */
.cfop-ent-row { display: grid; grid-template-columns: 68px 1fr 130px 1fr 74px; gap: 10px; align-items: center; padding: 7px 10px; border-bottom: 1px solid var(--border); font-size: 0.82rem; }
.cfop-ent-row:hover { background: var(--bg); }
.cfop-ent-head { font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-muted); font-weight: 700; }
.cfop-ent-row code { font-weight: 700; color: var(--primary); }
.cfop-ent-row select, .cfop-ent-row input[type=text] { padding: 4px 6px; border: 1px solid var(--border); border-radius: 5px; font-size: 0.8rem; width: 100%; }
.cfop-ent-nat { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 0.7rem; font-weight: 700; }

@media (max-width: 900px) {
  .cfop-ent-row { grid-template-columns: 60px 1fr; row-gap: 6px; }
  .dre-table .dre-label { position: static; min-width: 180px; }
}

/* ---- Print ---- */
@media print {
  .sidebar, .page-header, .system-notice, .module-toolbar, .state-panel, .modal, .toast-container, .header-actions, button { display: none !important; }
  .main-content { overflow: visible; }
  .content-area { padding: 0; overflow: visible; }
  .card { box-shadow: none; border: 1px solid #ccc; page-break-inside: avoid; }
}
