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

/* =============================================
   CSS VARIABLES — TEMA CLARO E ESCURO
   ============================================= */
:root {
  --primary: #6366f1;
  --primary-dark: #4f46e5;
  --primary-light: #818cf8;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --info: #06b6d4;

  /* Light theme (padrão) */
  --bg-body: #f1f5f9;
  --bg-card: #ffffff;
  --bg-sidebar: #ffffff;
  --bg-header: #ffffff;
  --bg-input: #f8fafc;
  --bg-hover: #f1f5f9;
  --bg-table-alt: #f8fafc;
  --text-primary: #0f172a;
  --text-secondary: #64748b;
  --text-muted: #94a3b8;
  --border: #e2e8f0;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.05);
  --shadow-md: 0 4px 16px rgba(0,0,0,.08);
  --sidebar-width: 260px;
}

[data-theme="dark"] {
  --bg-body: #0f172a;
  --bg-card: #1e293b;
  --bg-sidebar: #1e293b;
  --bg-header: #1e293b;
  --bg-input: #0f172a;
  --bg-hover: #334155;
  --bg-table-alt: #243044;
  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --border: #334155;
  --shadow: 0 1px 3px rgba(0,0,0,.3);
  --shadow-md: 0 4px 20px rgba(0,0,0,.4);
}

/* =============================================
   RESET & BASE
   ============================================= */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; }
body {
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--bg-body);
  color: var(--text-primary);
  line-height: 1.6;
  transition: background .3s, color .3s;
}
a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-dark); }
img { max-width: 100%; }
ul { list-style: none; }

/* =============================================
   LAYOUT
   ============================================= */
.layout {
  display: flex;
  min-height: 100vh;
}

/* SIDEBAR */
.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0;
  height: 100vh;
  z-index: 100;
  transition: transform .3s, background .3s;
  box-shadow: var(--shadow-md);
}
.sidebar-brand {
  padding: 24px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
}
.brand-icon {
  width: 40px; height: 40px;
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px; flex-shrink: 0;
}
.brand-name { font-size: 1rem; font-weight: 700; color: var(--text-primary); line-height: 1.2; }
.brand-sub { font-size: .7rem; color: var(--text-muted); font-weight: 400; }

.sidebar-nav { flex: 1; overflow-y: auto; padding: 12px 0; }
.nav-group-label {
  font-size: .65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--text-muted);
  padding: 14px 20px 6px;
}
.nav-item a {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 20px;
  color: var(--text-secondary);
  font-size: .88rem;
  font-weight: 500;
  border-radius: 0;
  transition: all .2s;
  position: relative;
}
.nav-item a:hover, .nav-item a.active {
  color: var(--primary);
  background: var(--bg-hover);
}
.nav-item a.active::before {
  content: '';
  position: absolute;
  left: 0; top: 4px; bottom: 4px;
  width: 3px;
  background: var(--primary);
  border-radius: 0 3px 3px 0;
}
.nav-icon { font-size: 1.1rem; width: 20px; text-align: center; }
.nav-badge {
  margin-left: auto;
  background: var(--danger);
  color: #fff;
  font-size: .65rem;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 20px;
}

.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  font-size: .8rem;
  color: var(--text-muted);
}

/* MAIN CONTENT */
.main {
  margin-left: var(--sidebar-width);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* HEADER */
.header {
  background: var(--bg-header);
  border-bottom: 1px solid var(--border);
  padding: 0 28px;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 50;
  box-shadow: var(--shadow);
  transition: background .3s;
}
.header-title h1 { font-size: 1.1rem; font-weight: 600; color: var(--text-primary); }
.header-title p { font-size: .78rem; color: var(--text-muted); }
.header-actions { display: flex; align-items: center; gap: 12px; }

/* Theme Toggle */
.theme-toggle {
  width: 40px; height: 40px;
  border: 1px solid var(--border);
  background: var(--bg-input);
  color: var(--text-secondary);
  border-radius: 10px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 1rem;
  transition: all .2s;
}
.theme-toggle:hover { border-color: var(--primary); color: var(--primary); }

/* PAGE CONTENT */
.page-content { padding: 28px; flex: 1; }

/* =============================================
   CARDS
   ============================================= */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  transition: background .3s, border-color .3s;
}
.card-header {
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.card-title { font-size: .95rem; font-weight: 600; color: var(--text-primary); display: flex; align-items: center; gap: 8px; }
.card-body { padding: 22px; }

/* KPI CARDS */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 18px;
  margin-bottom: 24px;
}
.kpi-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 22px;
  position: relative;
  overflow: hidden;
  transition: transform .2s, box-shadow .2s, background .3s;
}
.kpi-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.kpi-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: var(--kpi-color, var(--primary));
}
.kpi-label { font-size: .78rem; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--text-muted); margin-bottom: 10px; }
.kpi-value { font-size: 1.8rem; font-weight: 800; color: var(--text-primary); line-height: 1; }
.kpi-sub { font-size: .78rem; color: var(--text-secondary); margin-top: 8px; }
.kpi-icon {
  position: absolute;
  right: 18px; top: 18px;
  width: 44px; height: 44px;
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.3rem;
  background: color-mix(in srgb, var(--kpi-color, var(--primary)) 15%, transparent);
  color: var(--kpi-color, var(--primary));
}

/* =============================================
   GRID
   ============================================= */
.grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 20px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px; }
.mb-20 { margin-bottom: 20px; }
.mb-24 { margin-bottom: 24px; }
.gap-20 { gap: 20px; }

/* =============================================
   FILTERS BAR
   ============================================= */
.filters-bar {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}
.filter-group { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.filter-label { font-size: .8rem; font-weight: 600; color: var(--text-muted); white-space: nowrap; }

/* =============================================
   FORMS
   ============================================= */
.form-group { margin-bottom: 18px; }
.form-label { display: block; font-size: .82rem; font-weight: 600; color: var(--text-secondary); margin-bottom: 6px; }
.form-control {
  width: 100%;
  padding: 10px 14px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text-primary);
  font-size: .9rem;
  font-family: inherit;
  transition: border-color .2s, box-shadow .2s, background .3s;
}
.form-control:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 18%, transparent);
}
.form-control::placeholder { color: var(--text-muted); }
select.form-control { cursor: pointer; }
textarea.form-control { resize: vertical; min-height: 90px; }
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; }
.form-check { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.form-check input[type=checkbox] { width: 18px; height: 18px; accent-color: var(--primary); cursor: pointer; }
.form-check-label { font-size: .88rem; color: var(--text-secondary); cursor: pointer; }

/* =============================================
   BUTTONS
   ============================================= */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 9px 18px;
  border-radius: 10px;
  font-size: .875rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all .2s;
  white-space: nowrap;
  font-family: inherit;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); transform: translateY(-1px); }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { background: #059669; transform: translateY(-1px); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #dc2626; transform: translateY(-1px); }
.btn-warning { background: var(--warning); color: #fff; }
.btn-warning:hover { background: #d97706; }
.btn-outline {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-secondary);
}
.btn-outline:hover { border-color: var(--primary); color: var(--primary); background: var(--bg-hover); }
.btn-sm { padding: 6px 12px; font-size: .8rem; border-radius: 8px; }
.btn-icon { padding: 8px; border-radius: 8px; }

/* =============================================
   TABLES
   ============================================= */
.table-responsive { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: .875rem; }
.table th {
  text-align: left;
  padding: 11px 16px;
  font-size: .75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  background: var(--bg-input);
  white-space: nowrap;
}
.table th:first-child { border-radius: 8px 0 0 8px; }
.table th:last-child { border-radius: 0 8px 8px 0; }
.table td {
  padding: 13px 16px;
  border-bottom: 1px solid var(--border);
  color: var(--text-primary);
  vertical-align: middle;
}
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover td { background: var(--bg-hover); }
.table tbody tr:nth-child(even) td { background: var(--bg-table-alt); }
.table tbody tr:nth-child(even):hover td { background: var(--bg-hover); }
.table .td-actions { display: flex; gap: 6px; }

/* =============================================
   BADGES
   ============================================= */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: .72rem;
  font-weight: 700;
  letter-spacing: .03em;
}
.badge-success { background: color-mix(in srgb, var(--success) 18%, transparent); color: var(--success); }
.badge-danger  { background: color-mix(in srgb, var(--danger) 18%, transparent); color: var(--danger); }
.badge-warning { background: color-mix(in srgb, var(--warning) 18%, transparent); color: var(--warning); }
.badge-info    { background: color-mix(in srgb, var(--info) 18%, transparent); color: var(--info); }
.badge-muted   { background: var(--bg-hover); color: var(--text-muted); }

/* =============================================
   ALERTS / TOAST
   ============================================= */
.alert {
  padding: 14px 18px;
  border-radius: 12px;
  font-size: .875rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 18px;
}
.alert-success { background: color-mix(in srgb,var(--success) 12%,transparent); color: var(--success); border: 1px solid color-mix(in srgb,var(--success) 30%,transparent); }
.alert-danger  { background: color-mix(in srgb,var(--danger) 12%,transparent); color: var(--danger); border: 1px solid color-mix(in srgb,var(--danger) 30%,transparent); }
.alert-warning { background: color-mix(in srgb,var(--warning) 12%,transparent); color: var(--warning); border: 1px solid color-mix(in srgb,var(--warning) 30%,transparent); }

/* Toast */
#toast-container { position: fixed; top: 20px; right: 20px; z-index: 9999; display: flex; flex-direction: column; gap: 10px; }
.toast {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 18px;
  box-shadow: var(--shadow-md);
  display: flex; align-items: center; gap: 10px;
  font-size: .875rem; font-weight: 500;
  min-width: 280px; max-width: 380px;
  animation: slideIn .3s ease;
}
.toast.success { border-left: 4px solid var(--success); }
.toast.error   { border-left: 4px solid var(--danger); }
.toast.warning { border-left: 4px solid var(--warning); }
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
@keyframes slideOut { from { transform: translateX(0); opacity: 1; } to { transform: translateX(100%); opacity: 0; } }

/* =============================================
   MODAL
   ============================================= */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.5);
  backdrop-filter: blur(4px);
  z-index: 200;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal-overlay.open { display: flex; }
.modal {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 18px;
  width: 100%;
  max-width: 560px;
  box-shadow: 0 25px 60px rgba(0,0,0,.3);
  animation: modalIn .2s ease;
}
@keyframes modalIn { from { transform: scale(.95); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.modal-header {
  padding: 22px 24px 18px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.modal-title { font-size: 1rem; font-weight: 700; color: var(--text-primary); }
.modal-close { background: none; border: none; cursor: pointer; color: var(--text-muted); font-size: 1.3rem; line-height: 1; padding: 4px; border-radius: 6px; transition: color .2s; }
.modal-close:hover { color: var(--danger); }
.modal-body { padding: 24px; }
.modal-footer { padding: 16px 24px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 10px; }

/* =============================================
   EMPTY STATE
   ============================================= */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}
.empty-state .empty-icon { font-size: 3rem; margin-bottom: 16px; opacity: .5; }
.empty-state h3 { font-size: 1rem; font-weight: 600; color: var(--text-secondary); margin-bottom: 8px; }
.empty-state p { font-size: .875rem; }

/* =============================================
   STATS & PROGRESS
   ============================================= */
.progress-bar { background: var(--border); border-radius: 99px; height: 8px; overflow: hidden; }
.progress-fill { height: 100%; border-radius: 99px; transition: width .6s ease; }

/* =============================================
   PAGE HEADER
   ============================================= */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}
.page-header-info h2 { font-size: 1.3rem; font-weight: 700; color: var(--text-primary); }
.page-header-info p { font-size: .85rem; color: var(--text-muted); margin-top: 3px; }

/* =============================================
   CHART CONTAINERS
   ============================================= */
.chart-wrap { position: relative; height: 260px; }
.chart-wrap canvas { max-height: 260px !important; }

/* =============================================
   QUICK DATE BUTTONS
   ============================================= */
.date-shortcuts { display: flex; gap: 6px; flex-wrap: wrap; }
.date-shortcut {
  padding: 5px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-input);
  color: var(--text-secondary);
  font-size: .78rem;
  font-weight: 500;
  cursor: pointer;
  transition: all .2s;
}
.date-shortcut:hover, .date-shortcut.active { border-color: var(--primary); background: var(--primary); color: #fff; }

/* =============================================
   SIDEBAR TOGGLE (mobile)
   ============================================= */
.sidebar-toggle {
  display: none;
  background: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-secondary);
  padding: 6px 10px;
  cursor: pointer;
  font-size: 1.1rem;
}
.sidebar-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,.4);
  z-index: 99;
}

/* =============================================
   RESPONSIVE
   ============================================= */
@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .sidebar-overlay.open { display: block; }
  .main { margin-left: 0; }
  .sidebar-toggle { display: flex; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
}
@media (max-width: 600px) {
  .page-content { padding: 16px; }
  .kpi-grid { grid-template-columns: 1fr 1fr; }
  .header { padding: 0 16px; }
  .kpi-value { font-size: 1.4rem; }
}
@media (max-width: 400px) {
  .kpi-grid { grid-template-columns: 1fr; }
}

/* =============================================
   SCROLLBAR
   ============================================= */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 6px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* =============================================
   UTILITY
   ============================================= */
.text-success { color: var(--success) !important; }
.text-danger  { color: var(--danger) !important; }
.text-warning { color: var(--warning) !important; }
.text-muted   { color: var(--text-muted) !important; }
.text-right   { text-align: right; }
.text-center  { text-align: center; }
.fw-bold      { font-weight: 700; }
.fw-semibold  { font-weight: 600; }
.d-flex       { display: flex; }
.align-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-8  { gap: 8px; }
.gap-12 { gap: 12px; }
.w-100  { width: 100%; }
.mt-8   { margin-top: 8px; }
.mt-16  { margin-top: 16px; }
.mb-8   { margin-bottom: 8px; }
.p-0    { padding: 0; }
.hidden { display: none !important; }
