/* =============================================================
   CIB — Global CSS Design System
   Chiaweb Intelligence Business
   Identidade: Dark Gray & Blue (Serious Corporate)
   Fundos: Dark (#0E1117) / Light (#FFFFFF)
   ============================================================= */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&family=Poppins:wght@600;700;800;900&display=swap');

/* ---- CSS Custom Properties ---- */
:root {
  /* Brand Colors */
  --purple-900:  #1E0A3C;
  --purple-800:  #3B0E8C;
  --purple:      #7C3AED;
  --purple-mid:  #8B5CF6;
  --lilac:       #A78BFA;
  --lilac-light: #C4B5FD;
  --blue:        #3B82F6;
  --blue-light:  #60A5FA;
  --blue-dark:   #1D4ED8;

  /* Gradients - Flattened for a more serious look */
  --gradient-brand:        linear-gradient(135deg, #3B82F6 0%, #2563EB 100%);
  --gradient-brand-h:      linear-gradient(90deg, #F9FAFB 0%, #E5E7EB 100%); /* Used for titles */
  --gradient-brand-subtle: rgba(59,130,246,0.08);
  --gradient-brand-glow:   0 0 20px rgba(59,130,246,0.2);

  /* Semantic Colors */
  --success:     #10B981;
  --success-bg:  rgba(16,185,129,0.12);
  --success-border: rgba(16,185,129,0.3);
  --warning:     #F59E0B;
  --warning-bg:  rgba(245,158,11,0.12);
  --warning-border: rgba(245,158,11,0.3);
  --danger:      #EF4444;
  --danger-bg:   rgba(239,68,68,0.12);
  --danger-border: rgba(239,68,68,0.3);
  --info:        #3B82F6;
  --info-bg:     rgba(59,130,246,0.12);
  --info-border: rgba(59,130,246,0.3);

  /* Layout */
  --sidebar-width:    260px;
  --header-height:    64px;
  --content-max:      1400px;

  /* Radius */
  --radius-xs:   4px;
  --radius-sm:   6px;
  --radius-md:   10px;
  --radius-lg:   16px;
  --radius-xl:   24px;
  --radius-full: 9999px;

  /* Transitions */
  --transition:      all 0.2s cubic-bezier(0.4,0,0.2,1);
  --transition-slow: all 0.4s cubic-bezier(0.4,0,0.2,1);
  --transition-fast: all 0.12s ease;

  /* Z-index */
  --z-sidebar: 100;
  --z-header:  90;
  --z-modal:   200;
  --z-toast:   300;
  --z-tooltip: 400;
}

/* ---- DARK THEME (padrão) ---- */
[data-theme="dark"], :root {
  --bg-base:      #0E1117; /* Fundo principal (body) */
  --bg-surface:   #161B22; /* Sidebar, Topbar */
  --bg-card:      #1A1D24; /* Cards, Modais */
  --bg-elevated:  #21262D; /* Dropdowns, Hover intenso */
  --bg-hover:     #2A2F37; /* Hover suave */
  --bg-input:     #161B22; /* Inputs */

  --border:        rgba(255,255,255,0.08);
  --border-strong: rgba(255,255,255,0.15);
  --border-subtle: rgba(255,255,255,0.04);

  --text-primary:   #F0F6FC;
  --text-secondary: #8B949E;
  --text-muted:     #6E7681;
  --text-link:      #3B82F6;

  --shadow-sm:    0 1px 3px rgba(0,0,0,0.4);
  --shadow-md:    0 4px 12px rgba(0,0,0,0.5);
  --shadow-lg:    0 8px 24px rgba(0,0,0,0.6);
  --shadow-brand: 0 4px 14px rgba(59,130,246,0.25);
  --shadow-glow:  0 0 20px rgba(59,130,246,0.15);

  --sidebar-bg:   #111318;
  --sidebar-text: #8B949E;
  --sidebar-active-bg: rgba(59,130,246,0.1);
  --sidebar-active-text: #3B82F6;
}

/* ---- LIGHT THEME ---- */
[data-theme="light"] {
  --bg-base:      #F8FAFC;
  --bg-surface:   #FFFFFF;
  --bg-card:      #FFFFFF;
  --bg-elevated:  #F1F5F9;
  --bg-hover:     #E2E8F0;
  --bg-input:     #F8FAFC;

  --border:        rgba(0,0,0,0.08);
  --border-strong: rgba(0,0,0,0.15);
  --border-subtle: rgba(0,0,0,0.04);

  --text-primary:   #1E293B;
  --text-secondary: #64748B;
  --text-muted:     #94A3B8;
  --text-link:      #2563EB;

  --shadow-sm:    0 1px 3px rgba(0,0,0,0.05);
  --shadow-md:    0 4px 12px rgba(0,0,0,0.08);
  --shadow-lg:    0 8px 24px rgba(0,0,0,0.12);
  --shadow-brand: 0 4px 14px rgba(37,99,235,0.2);
  --shadow-glow:  0 0 20px rgba(37,99,235,0.15);

  --sidebar-bg:   #1E293B;
  --sidebar-text: #94A3B8;
  --sidebar-active-bg: rgba(255,255,255,0.1);
  --sidebar-active-text: #F8FAFC;
}

/* ---- RESET & BASE ---- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  scroll-behavior: smooth;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background-color: var(--bg-base);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
  transition: background-color 0.3s ease, color 0.3s ease;
}

/* ---- TYPOGRAPHY ---- */
h1, h2, h3, h4, h5, h6 {
  font-family: 'Poppins', sans-serif;
  font-weight: 700;
  line-height: 1.3;
  color: var(--text-primary);
}

h1 { font-size: 2rem; }
h2 { font-size: 1.5rem; }
h3 { font-size: 1.25rem; }
h4 { font-size: 1.1rem; }

p { color: var(--text-secondary); }

a {
  color: var(--text-link);
  text-decoration: none;
  transition: var(--transition);
}
a:hover { opacity: 0.85; }

strong { font-weight: 600; color: var(--text-primary); }

/* ---- SCROLLBAR ---- */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg-base); }
::-webkit-scrollbar-thumb {
  background: linear-gradient(180deg, var(--purple), var(--blue));
  border-radius: var(--radius-full);
}
::-webkit-scrollbar-thumb:hover { background: var(--lilac); }

/* ============================================================
   LAYOUT PRINCIPAL (Sidebar + Content)
   ============================================================ */

.app-layout {
  display: flex;
  min-height: 100vh;
}

/* ---- SIDEBAR ---- */
.sidebar {
  width: var(--sidebar-width);
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  height: 100vh;
  z-index: var(--z-sidebar);
  overflow-y: auto;
  overflow-x: hidden;
  transition: width 0.3s cubic-bezier(0.4,0,0.2,1), transform 0.3s ease;
}

.sidebar-logo {
  padding: 20px 20px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: var(--header-height);
}

.sidebar-logo-icon {
  width: 40px;
  height: 40px;
  background: var(--gradient-brand);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow: var(--shadow-brand);
}

.sidebar-logo-icon svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: #fff;
  stroke-width: 1.5px;
}

.sidebar-brand {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-brand-name {
  font-family: 'Poppins', sans-serif;
  font-size: 0.9rem;
  font-weight: 700;
  background: var(--gradient-brand-h);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  white-space: nowrap;
}

.sidebar-brand-sub {
  font-size: 0.68rem;
  color: var(--sidebar-text);
  white-space: nowrap;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

/* Nav groups */
.sidebar-nav {
  flex: 1;
  padding: 16px 12px;
  overflow-y: auto;
  overflow-x: hidden;
}

.sidebar-group {
  margin-bottom: 8px;
}

.sidebar-group-label {
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  padding: 8px 10px 4px;
}

.sidebar-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-md);
  color: var(--sidebar-text);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
  border: 1px solid transparent;
  text-decoration: none;
  white-space: nowrap;
  overflow: hidden;
  position: relative;
}

.sidebar-item svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  opacity: 0.7;
  transition: var(--transition);
}

.sidebar-item:hover {
  background: var(--sidebar-active-bg);
  color: var(--sidebar-active-text);
  border-color: var(--border);
}

.sidebar-item:hover svg { opacity: 1; }

.sidebar-item.active {
  background: var(--sidebar-active-bg);
  color: var(--sidebar-active-text);
  border-color: var(--border-strong);
  font-weight: 600;
}

.sidebar-item.active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 3px;
  background: var(--gradient-brand);
  border-radius: 0 3px 3px 0;
}

.sidebar-item.active svg { opacity: 1; }

.sidebar-badge {
  margin-left: auto;
  background: var(--danger);
  color: #fff;
  font-size: 0.65rem;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: var(--radius-full);
  min-width: 18px;
  text-align: center;
}

/* Sidebar footer — user */
.sidebar-footer {
  padding: 12px;
  border-top: 1px solid var(--border);
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: var(--transition);
}

.sidebar-user:hover { background: var(--bg-hover); }

.sidebar-avatar {
  width: 34px;
  height: 34px;
  border-radius: var(--radius-full);
  background: var(--gradient-brand);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
  box-shadow: var(--shadow-brand);
}

.sidebar-user-info {
  flex: 1;
  min-width: 0;
  overflow: hidden;
}

.sidebar-user-name {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-user-role {
  font-size: 0.7rem;
  color: var(--sidebar-text);
  text-transform: capitalize;
}

/* ---- MAIN CONTENT ---- */
.main-wrapper {
  margin-left: var(--sidebar-width);
  flex: 1;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  transition: margin-left 0.3s cubic-bezier(0.4,0,0.2,1);
}

/* Topbar */
.topbar {
  height: var(--header-height);
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 28px;
  position: sticky;
  top: 0;
  z-index: var(--z-header);
  backdrop-filter: blur(12px);
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 16px;
}

.topbar-title {
  font-family: 'Poppins', sans-serif;
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-primary);
}

.topbar-breadcrumb {
  font-size: 0.8rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 6px;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* Topbar theme toggle */
.theme-toggle {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-md);
  background: var(--bg-card);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: var(--transition);
  color: var(--text-secondary);
}

.theme-toggle:hover {
  background: var(--bg-hover);
  border-color: var(--border-strong);
  color: var(--lilac);
}

/* Content area */
.content {
  flex: 1;
  padding: 28px;
  max-width: var(--content-max);
  width: 100%;
}

.content-full { max-width: 100%; }

/* ---- PAGE HEADER ---- */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 28px;
  gap: 16px;
  flex-wrap: wrap;
}

.page-header-left h1 {
  font-size: 1.6rem;
  background: var(--gradient-brand-h);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.page-header-left p {
  font-size: 0.875rem;
  color: var(--text-muted);
  margin-top: 3px;
}

/* ---- KPI CARDS ---- */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 20px;
  margin-bottom: 28px;
}

.kpi-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 22px 24px;
  display: flex;
  align-items: flex-start;
  gap: 16px;
  transition: var(--transition);
  position: relative;
  overflow: hidden;
}

.kpi-card::before {
  content: '';
  position: absolute;
  inset: 0;
  background: var(--gradient-brand-subtle);
  opacity: 0;
  transition: var(--transition);
}

.kpi-card:hover {
  border-color: var(--border-strong);
  transform: translateY(-2px);
  box-shadow: var(--shadow-brand);
}

.kpi-card:hover::before { opacity: 1; }

.kpi-icon {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 1.3rem;
  position: relative;
  z-index: 1;
}

.kpi-icon.purple { background: rgba(124,58,237,0.15); color: var(--lilac); }
.kpi-icon.blue   { background: rgba(59,130,246,0.15);  color: var(--blue-light); }
.kpi-icon.green  { background: var(--success-bg);       color: var(--success); }
.kpi-icon.orange { background: var(--warning-bg);       color: var(--warning); }
.kpi-icon.red    { background: var(--danger-bg);        color: var(--danger); }

.kpi-info { flex: 1; position: relative; z-index: 1; }

.kpi-label {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 6px;
}

.kpi-value {
  font-family: 'Poppins', sans-serif;
  font-size: 1.8rem;
  font-weight: 800;
  color: var(--text-primary);
  line-height: 1;
  margin-bottom: 6px;
}

.kpi-change {
  font-size: 0.75rem;
  display: flex;
  align-items: center;
  gap: 4px;
}

.kpi-change.up   { color: var(--success); }
.kpi-change.down { color: var(--danger); }
.kpi-change.flat { color: var(--text-muted); }

/* ---- SECTION CARD ---- */
.section-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  margin-bottom: 24px;
}

.section-card-header {
  padding: 18px 24px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.section-card-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 10px;
}

.section-card-title svg { color: var(--lilac); }

.section-card-body { padding: 24px; }
.section-card-body.no-pad { padding: 0; }

/* ---- ANIMATIONS ---- */
@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(20px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

@keyframes slideInRight {
  from { opacity: 0; transform: translateX(30px); }
  to   { opacity: 1; transform: translateX(0); }
}

@keyframes slideInLeft {
  from { opacity: 0; transform: translateX(-30px); }
  to   { opacity: 1; transform: translateX(0); }
}

@keyframes scaleIn {
  from { opacity: 0; transform: scale(0.95); }
  to   { opacity: 1; transform: scale(1); }
}

@keyframes gradientShift {
  0%   { background-position: 0% 50%; }
  50%  { background-position: 100% 50%; }
  100% { background-position: 0% 50%; }
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.5; }
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.animate-fade-in     { animation: fadeInUp 0.5s ease both; }
.animate-slide-right { animation: slideInRight 0.4s ease both; }
.animate-scale-in    { animation: scaleIn 0.3s ease both; }

/* Staggered children animation */
.stagger-children > *:nth-child(1) { animation-delay: 0.05s; }
.stagger-children > *:nth-child(2) { animation-delay: 0.10s; }
.stagger-children > *:nth-child(3) { animation-delay: 0.15s; }
.stagger-children > *:nth-child(4) { animation-delay: 0.20s; }
.stagger-children > *:nth-child(5) { animation-delay: 0.25s; }
.stagger-children > *:nth-child(6) { animation-delay: 0.30s; }

/* ---- TOAST NOTIFICATIONS ---- */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: none;
}

.toast {
  padding: 14px 20px;
  border-radius: var(--radius-md);
  font-size: 0.875rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 10px;
  pointer-events: all;
  animation: slideInRight 0.3s ease;
  box-shadow: var(--shadow-lg);
  border-left: 4px solid;
  max-width: 380px;
  backdrop-filter: blur(12px);
}

.toast-success { background: var(--bg-elevated); border-color: var(--success); color: var(--success); }
.toast-danger  { background: var(--bg-elevated); border-color: var(--danger);  color: var(--danger); }
.toast-warning { background: var(--bg-elevated); border-color: var(--warning); color: var(--warning); }
.toast-info    { background: var(--bg-elevated); border-color: var(--info);    color: var(--info); }
.toast-message { color: var(--text-primary); }

/* ---- LOADER ---- */
.loader {
  width: 20px;
  height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--purple);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  display: inline-block;
}

/* ---- UTILITY ---- */
.gradient-text {
  background: var(--gradient-brand-h);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.gradient-bg {
  background: var(--gradient-brand);
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
}

.text-center  { text-align: center; }
.text-right   { text-align: right; }
.text-muted   { color: var(--text-muted); font-size: 0.85rem; }
.text-small   { font-size: 0.82rem; }
.text-success { color: var(--success); }
.text-danger  { color: var(--danger); }
.text-warning { color: var(--warning); }
.text-info    { color: var(--info); }

.flex         { display: flex; }
.flex-center  { display: flex; align-items: center; justify-content: center; }
.flex-between { display: flex; align-items: center; justify-content: space-between; }
.gap-4        { gap: 4px; }
.gap-8        { gap: 8px; }
.gap-12       { gap: 12px; }
.gap-16       { gap: 16px; }
.gap-20       { gap: 20px; }
.gap-24       { gap: 24px; }

.mt-8  { margin-top: 8px; }
.mt-12 { margin-top: 12px; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }
.mt-32 { margin-top: 32px; }
.mb-16 { margin-bottom: 16px; }
.mb-24 { margin-bottom: 24px; }

.w-full  { width: 100%; }
.h-full  { height: 100%; }
.hidden  { display: none !important; }
.visible { visibility: visible; }

.divider {
  height: 1px;
  background: var(--border);
  margin: 20px 0;
}

/* empty state */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 24px;
  text-align: center;
}

.empty-state-icon {
  font-size: 3rem;
  margin-bottom: 16px;
  opacity: 0.5;
}

.empty-state h3 {
  font-size: 1.1rem;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.empty-state p {
  font-size: 0.875rem;
  color: var(--text-muted);
}

/* ---- RESPONSIVE ---- */
@media (max-width: 1024px) {
  .sidebar {
    transform: translateX(-100%);
  }
  .sidebar.open {
    transform: translateX(0);
    box-shadow: var(--shadow-lg);
  }
  .main-wrapper {
    margin-left: 0;
  }
  .content {
    padding: 20px 16px;
  }
}

@media (max-width: 640px) {
  .kpi-grid {
    grid-template-columns: 1fr 1fr;
  }
  .page-header {
    flex-direction: column;
    align-items: flex-start;
  }
}
