:root {
  --bg: #f8f9fa;
  --card: #ffffff;
  --border: #e5e7eb;
  --text-primary: #1a202c;
  --text-secondary: #64748b;
  --blue: #3b82f6;
  --green: #10b981;
  --yellow: #f59e0b;
  --red: #ef4444;
  --purple: #8b5cf6;
  --font-family: 'Inter', sans-serif;
  --transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
}

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

body {
  font-family: var(--font-family);
  background-color: var(--bg);
  color: var(--text-primary);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 {
  color: var(--text-primary);
  font-weight: 600;
}

.view-section {
  display: flex;
  min-height: 100vh;
  flex-direction: column;
}

.scene {
  padding: 24px;
  animation: fadeIn 0.4s ease-out;
  flex: 1;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* CARDS GLASSMORPHISM */
.glass-panel {
  background: rgba(255, 255, 255, 0.8) !important;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(255,255,255,0.4);
}

/* LOGIN */
#login-section {
  justify-content: center;
  align-items: center;
  background: linear-gradient(135deg, #fdfbfb 0%, #ebedee 100%);
  position: relative;
}

#login-section::before {
  content: '';
  position: absolute;
  top: -20%; left: -10%;
  width: 50%; height: 50%;
  background: radial-gradient(circle, rgba(59,130,246,0.15) 0%, transparent 70%);
}
#login-section::after {
  content: '';
  position: absolute;
  bottom: -20%; right: -10%;
  width: 50%; height: 50%;
  background: radial-gradient(circle, rgba(139,92,246,0.15) 0%, transparent 70%);
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--card);
  padding: 40px;
  border-radius: 16px;
  box-shadow: 0 10px 25px rgba(0,0,0,0.05);
  z-index: 10;
}

.logo-title {
  font-size: 28px;
  text-align: center;
  margin-bottom: 5px;
  color: var(--text-primary);
}
.logo-title span {
  color: var(--blue);
}

.subtitle {
  text-align: center;
  font-size: 14px;
  color: var(--text-secondary);
  margin-bottom: 30px;
}

/* FORMS & INPUTS */
.input-group {
  margin-bottom: 20px;
}
.input-group label {
  display: block;
  font-size: 13px;
  text-transform: uppercase;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 8px;
}
input, select {
  width: 100%;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-family: var(--font-family);
  font-size: 15px;
  transition: var(--transition);
  background: var(--card);
  color: var(--text-primary);
}
input:focus, select:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.error-message {
  color: var(--red);
  font-size: 14px;
  margin-top: 10px;
  text-align: center;
  min-height: 21px;
}

/* BUTTONS */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 20px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  transition: var(--transition);
}
.btn:hover {
  transform: translateY(-1px);
}
.btn-block { width: 100%; }
.mt-4 { margin-top: 24px; }

.btn-primary {
  background: var(--blue); color: white;
  box-shadow: 0 4px 10px rgba(59, 130, 246, 0.2);
}
.btn-primary:hover {
  background: #2563eb;
  box-shadow: 0 6px 14px rgba(59, 130, 246, 0.3);
}

.btn-success {
  background: var(--green); color: white;
  box-shadow: 0 4px 10px rgba(16, 185, 129, 0.2);
}
.btn-success:hover { background: #059669; }

.btn-outline {
  background: white; color: var(--text-primary);
  border: 1px solid var(--border);
}
.btn-outline:hover { background: #f8fafc; border-color: #cbd5e1; }

.btn-text {
  background: transparent; color: var(--text-secondary);
}
.btn-text:hover { color: var(--red); background: rgba(239, 68, 68, 0.05); }

/* HEADER */
.top-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 24px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 100;
}
.header-left {
  display: flex; align-items: center; gap: 16px;
}
.header-title { font-size: 20px; }
.empresa-highlight { color: var(--blue); }

.badge-period {
  background: rgba(59, 130, 246, 0.1);
  color: var(--blue);
  padding: 4px 12px;
  border-radius: 99px;
  font-size: 13px; font-weight: 500;
}

.header-right {
  display: flex; align-items: center; gap: 12px;
}
.timestamp {
  font-size: 12px; color: var(--text-secondary); margin-right: 8px;
}

/* FILTERS SCENE */
#filters-scene {
  display: flex; justify-content: center; align-items: center;
}
.filters-card {
  background: var(--card);
  padding: 32px; border-radius: 12px;
  width: 100%; max-width: 600px;
  box-shadow: 0 4px 6px -1px rgba(0,0,0,0.05);
}
.filters-card h2 { margin-bottom: 24px; font-size: 24px; }
.filter-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 20px;
}

/* DASHBOARD KPIs */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 20px;
  margin-bottom: 24px;
}
.kpi-card {
  background: var(--card);
  padding: 20px;
  border-radius: 12px;
  position: relative;
  overflow: hidden;
  box-shadow: 0 4px 6px -1px rgba(0,0,0,0.05);
  transition: var(--transition);
}
.kpi-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 15px -1px rgba(0,0,0,0.05);
}
.kpi-card::before {
  content: ''; position: absolute;
  top: 0; left: 0; bottom: 0; width: 4px;
}
.kpi-label {
  font-size: 13px; text-transform: uppercase; font-weight: 600;
  color: var(--text-secondary); margin-bottom: 8px;
}
.kpi-value {
  font-size: 32px; font-weight: 700; color: var(--text-primary);
  line-height: 1.1;
}

.color-red::before { background: var(--red); }
.color-red .kpi-value { color: var(--red); }
.color-blue::before { background: var(--blue); }
.color-blue .kpi-value { color: var(--blue); }
.color-yellow::before { background: var(--yellow); }
.color-yellow .kpi-value { color: var(--yellow); }
.color-green::before { background: var(--green); }
.color-green .kpi-value { color: var(--green); }
.color-purple::before { background: var(--purple); }
.color-purple .kpi-value { color: var(--purple); }

/* CHARTS */
.charts-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 20px;
  margin-bottom: 24px;
}
.chart-card {
  background: var(--card); padding: 20px;
  border-radius: 12px;
  box-shadow: 0 4px 6px -1px rgba(0,0,0,0.05);
}
.card-span-2 { grid-column: span 2; }
.chart-card h3 { font-size: 16px; margin-bottom: 16px; color: var(--text-secondary); }
.chart-container { position: relative; height: 300px; width: 100%; }

/* TABLE SECTION */
.data-section {
  background: var(--card);
  border-radius: 12px;
  padding: 20px;
  box-shadow: 0 4px 6px -1px rgba(0,0,0,0.05);
  margin-bottom: 40px;
}
.table-header-controls {
  display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px;
}
.table-filters {
  display: flex; gap: 12px;
}
.input-search {
  width: 250px; padding: 8px 12px;
}

.table-container {
  overflow-x: auto;
}
table { width: 100%; border-collapse: collapse; text-align: left; }
th, td {
  padding: 14px 16px; border-bottom: 1px solid var(--border);
}
th {
  font-size: 13px; text-transform: uppercase; color: var(--text-secondary);
  font-weight: 600; white-space: nowrap;
}
th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { background: #f8fafc; color: var(--blue); }
td { font-size: 14px; color: var(--text-primary); }
tr:hover td { background: #f8fafc; }
.num { text-align: right; }
.num-val { text-align: right; }

/* BADGES */
.badge {
  padding: 4px 10px; border-radius: 99px; font-size: 12px; font-weight: 600; display: inline-block;
}
.badge-alta { background: rgba(239, 68, 68, 0.1); color: var(--red); }
.badge-media { background: rgba(245, 158, 11, 0.1); color: #d97706; }
.badge-baixa { background: rgba(16, 185, 129, 0.1); color: var(--green); }
.badge-zero { background: var(--bg); color: var(--text-secondary); }

.btn-sm { padding: 6px 12px; font-size: 12px; }

/* MODAL */
.modal-overlay {
  position: fixed; top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(15, 23, 42, 0.7);
  display: flex; justify-content: center; align-items: center;
  z-index: 1000; padding: 20px;
  backdrop-filter: blur(4px);
}
.modal-dialog {
  background: var(--card); border-radius: 16px; width: 100%; max-width: 900px;
  max-height: 90vh; display: flex; flex-direction: column;
  box-shadow: 0 25px 50px -12px rgba(0,0,0,0.25);
  animation: slideUp 0.3s ease-out;
}
@keyframes slideUp {
  from { opacity: 0; transform: translateY(30px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
.modal-header {
  padding: 24px; border-bottom: 1px solid var(--border);
  display: flex; justify-content: space-between; align-items: center;
}
.btn-close {
  background: transparent; border: none; font-size: 24px; color: var(--text-secondary);
  cursor: pointer; transition: var(--transition);
}
.btn-close:hover { color: var(--red); transform: rotate(90deg); }
.modal-body {
  padding: 24px; overflow-y: auto; flex: 1;
}
.modal-kpis {
  grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 24px;
}
.kpi-value-small { font-size: 24px; font-weight: 700; color: var(--text-primary); }

.modal-table-container {
  border: 1px solid var(--border); border-radius: 8px; overflow: hidden;
}
.minimal-table th, .minimal-table td { padding: 12px; font-size: 13px; }

.modal-footer {
  padding: 20px 24px; border-top: 1px solid var(--border);
  display: flex; justify-content: space-between; background: var(--bg);
  border-bottom-left-radius: 16px; border-bottom-right-radius: 16px;
}

/* TRENDS */
.kpi-trend {
  font-size: 13px; font-weight: 600; margin-top: 4px; display: flex; align-items: center; gap: 4px;
}
.trend-up { color: var(--red); }
.trend-down { color: var(--green); }
.trend-neutral { color: var(--text-secondary); }
.trend-positive { color: var(--green); }
.trend-negative { color: var(--red); }

/* AI INSIGHT CARD */
.ai-insight-card {
  background: linear-gradient(135deg, rgba(139, 92, 246, 0.1) 0%, rgba(59, 130, 246, 0.05) 100%);
  border: 1px solid rgba(139, 92, 246, 0.2);
  border-radius: 12px; padding: 20px; margin-bottom: 24px;
  box-shadow: 0 4px 15px rgba(139, 92, 246, 0.05);
}
.ai-insight-header { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.ai-insight-header h3 { color: var(--purple); font-size: 16px; margin: 0; }
.ai-icon { font-size: 18px; }
.ai-insight-body { font-size: 15px; color: var(--text-primary); line-height: 1.5; }

.typing-indicator { color: var(--text-secondary); font-style: italic; }
.typing-indicator span { animation: blink 1.4s infinite both; }
.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink { 0% { opacity: 0.2; } 20% { opacity: 1; } 100% { opacity: 0.2; } }

.card-span-4 { grid-column: span 4; }

/* LOADER */
.loader-overlay {
  position: fixed; top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(255, 255, 255, 0.9);
  z-index: 2000; display: flex; flex-direction: column;
  justify-content: center; align-items: center;
}
.spinner {
  width: 50px; height: 50px; border: 4px solid var(--border);
  border-top-color: var(--blue); border-radius: 50%;
  animation: spin 1s linear infinite; margin-bottom: 16px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* RESPONSIVENESS */
@media (max-width: 1024px) {
  .kpi-grid { grid-template-columns: repeat(3, 1fr); }
  .charts-grid { grid-template-columns: repeat(2, 1fr); }
  .modal-kpis { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 768px) {
  .top-header { flex-direction: column; align-items: flex-start; gap: 12px; }
  .header-right { width: 100%; justify-content: space-between; }
  .filter-grid { grid-template-columns: 1fr; }
  .kpi-grid { grid-template-columns: 1fr; }
  .charts-grid { grid-template-columns: 1fr; }
  .card-span-2 { grid-column: span 1; }
  .table-header-controls { flex-direction: column; align-items: flex-start; gap: 16px; }
  .modal-kpis { grid-template-columns: 1fr; }
}
