/* ============================================================
   ERP Financeiro Mebbi — Design System
   (baseado no design system do Mebbi SaaS — mesma identidade visual)
   ============================================================ */

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

:root {
  --primary:        #36B76B;
  --primary-light:  #D4F1E0;
  --primary-dark:   #2A9056;
  --secondary:      #F4A13A;
  --secondary-light:#FEF3C7;
  --mebbi:          #52177d;
  --mebbi-dark:     #3b1059;
  --mebbi-light:    #EDE9FE;

  --bg-app:         #F9FAFB;
  --bg-white:       #FFFFFF;
  --bg-hover:       #F3F4F6;

  --text-heading:   #111827;
  --text-body:      #374151;
  --text-muted:     #6B7280;
  --text-subtle:    #9CA3AF;

  --border:         #E5E7EB;
  --border-light:   #F0F0F0;

  --danger:         #EF4444;
  --danger-light:   #FEF2F2;

  --shadow-sm:      0 1px 2px rgba(0,0,0,.05);
  --shadow-md:      0 4px 6px rgba(0,0,0,.07);

  --radius-sm:  6px;
  --radius-md:  8px;
  --radius-lg:  12px;
  --radius-xl:  16px;

  --sidebar-w: 232px;

  --font: 'Inter', system-ui, -apple-system, sans-serif;
}

html, body { height: 100%; font-family: var(--font); background: var(--bg-app); color: var(--text-body); font-size: 14px; line-height: 1.5; }

@keyframes fadeInUp     { from { opacity:0; transform:translateY(12px); } to { opacity:1; transform:translateY(0); } }
@keyframes progressFill { from { width:0; } to { width:var(--target); } }

.fade-up { animation: fadeInUp 0.4s ease-out both; animation-delay: var(--delay, 0s); }

/* ── Layout ───────────────────────────────────────────────── */
.app-wrapper { display: flex; min-height: 100vh; }

/* ── Sidebar ──────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--bg-white);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  height: 100vh;
  position: sticky;
  top: 0;
  overflow-y: auto;
}

.sidebar-logo {
  padding: 20px 18px 16px;
  border-bottom: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  gap: 10px;
}
.logo-img { height: 34px; width: auto; object-fit: contain; }
.sidebar-tag { font-size: 10px; color: var(--text-subtle); font-weight: 600; text-transform: uppercase; letter-spacing: .06em; margin-top: 2px; }

.sidebar-nav { flex: 1; padding: 12px 8px; }
.nav-group { margin-bottom: 18px; }
.nav-group-label { font-size: 10px; font-weight: 700; color: var(--text-subtle); text-transform: uppercase; letter-spacing: .07em; padding: 0 10px 6px; display: block; }

.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-md);
  font-size: 13px; font-weight: 500;
  color: var(--text-muted);
  text-decoration: none;
  transition: background .15s, color .15s;
  margin-bottom: 2px;
}
.nav-item svg { width: 16px; height: 16px; fill: currentColor; flex-shrink: 0; }
.nav-item:hover { background: var(--bg-hover); color: var(--text-heading); }
.nav-item.active { background: var(--primary-light); color: var(--primary-dark); font-weight: 600; }

.sidebar-footer { padding: 12px 16px; border-top: 1px solid var(--border); display: flex; align-items: center; gap: 8px; }
.user-avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--mebbi); color: #fff; display: flex; align-items: center; justify-content: center; font-size: 13px; font-weight: 700; flex-shrink: 0; }
.user-info { flex: 1; min-width: 0; }
.user-name { display: block; font-size: 12px; font-weight: 600; color: var(--text-heading); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-email { display: block; font-size: 10px; color: var(--text-subtle); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.btn-logout { width: 28px; height: 28px; display: flex; align-items: center; justify-content: center; border-radius: var(--radius-sm); color: var(--text-subtle); transition: color .15s, background .15s; flex-shrink: 0; text-decoration: none; }
.btn-logout svg { width: 16px; height: 16px; fill: currentColor; }
.btn-logout:hover { color: var(--danger); background: var(--danger-light); }

/* ── Main Content ─────────────────────────────────────────── */
.main-content { flex: 1; min-width: 0; padding: 24px; }

/* ── Mobile sidebar toggle ────────────────────────────────── */
.sidebar-toggle { display: none; background: none; border: none; cursor: pointer; padding: 6px; border-radius: var(--radius-sm); }
.sidebar-toggle svg { width: 22px; height: 22px; fill: var(--mebbi); }
.topbar-mobile { display: none; align-items: center; justify-content: space-between; padding: 12px 16px; background: var(--bg-white); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 900; }

@media (max-width: 900px) {
  .sidebar { position: fixed; left: -260px; top: 0; z-index: 1000; transition: left .25s; box-shadow: 0 0 0 rgba(0,0,0,0); }
  .sidebar.show { left: 0; box-shadow: 8px 0 30px rgba(0,0,0,.15); }
  .topbar-mobile { display: flex; }
  .main-content { padding: 16px; }
}

/* ── Page Header ──────────────────────────────────────────── */
.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 22px; flex-wrap: wrap; gap: 12px; }
.page-title { font-size: 21px; font-weight: 700; color: var(--text-heading); letter-spacing: -.02em; }
.page-subtitle { font-size: 13px; color: var(--text-muted); margin-top: 2px; }
.page-header-right { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

/* ── Buttons ──────────────────────────────────────────────── */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 9px 16px; border-radius: var(--radius-md); font-size: 12.5px; font-weight: 600; cursor: pointer; border: none; text-decoration: none; transition: opacity .15s, transform .1s; white-space: nowrap; font-family: var(--font); }
.btn:hover { opacity: .88; }
.btn:active { transform: scale(.97); }
.btn svg { width: 14px; height: 14px; fill: currentColor; }

.btn-primary { background: var(--primary); color: #fff; }
.btn-mebbi   { background: var(--mebbi); color: #fff; }
.btn-danger  { background: var(--danger); color: #fff; }
.btn-ghost   { background: transparent; border: 1px solid var(--border); color: var(--text-body); }
.btn-ghost:hover { background: var(--bg-hover); opacity: 1; }
.btn-full    { width: 100%; justify-content: center; }
.btn-sm      { padding: 6px 12px; font-size: 11.5px; }

.btn-icon { width: 30px; height: 30px; border: none; background: none; cursor: pointer; border-radius: var(--radius-sm); display: flex; align-items: center; justify-content: center; transition: background .15s; color: var(--text-muted); text-decoration: none; }
.btn-icon svg { width: 15px; height: 15px; fill: currentColor; }
.btn-icon:hover { background: var(--bg-hover); }
.btn-icon-green:hover  { background: var(--primary-light); color: var(--primary-dark); }
.btn-icon-red:hover    { background: var(--danger-light); color: var(--danger); }
.btn-icon-muted        { color: var(--text-subtle); }

/* ── Cards ────────────────────────────────────────────────── */
.card { background: var(--bg-white); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 20px; box-shadow: var(--shadow-sm); margin-bottom: 16px; }
.card-header { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; }
.card-title  { font-size: 14px; font-weight: 600; color: var(--text-heading); flex: 1; display: flex; align-items: center; gap: 8px; }
.card-title svg { width: 16px; height: 16px; }
.card-link   { font-size: 12px; color: var(--primary-dark); text-decoration: none; font-weight: 600; }
.card-body-flush { padding: 0; margin: -20px; margin-top: 4px; }

/* ── KPI Grid ─────────────────────────────────────────────── */
.kpi-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 16px; }
@media (max-width: 1200px) { .kpi-grid { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 560px)  { .kpi-grid { grid-template-columns: 1fr; } }

.kpi-card { background: var(--bg-white); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 16px 18px; box-shadow: var(--shadow-sm); }
.kpi-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.kpi-label { font-size: 12px; font-weight: 500; color: var(--text-muted); }
.kpi-icon { width: 32px; height: 32px; border-radius: var(--radius-md); display: flex; align-items: center; justify-content: center; }
.kpi-icon svg { width: 16px; height: 16px; fill: currentColor; }
.icon-green  { background: var(--primary-light); color: var(--primary-dark); }
.icon-orange { background: var(--secondary-light); color: var(--secondary); }
.icon-purple { background: var(--mebbi-light); color: var(--mebbi); }
.icon-red    { background: var(--danger-light); color: var(--danger); }
.icon-blue   { background: #DBEAFE; color: #2563EB; }
.kpi-value { font-size: 25px; font-weight: 700; color: var(--text-heading); letter-spacing: -.03em; line-height: 1.1; margin-bottom: 4px; }
.kpi-sub   { font-size: 11px; color: var(--text-subtle); }

/* ── Badges / Pills ───────────────────────────────────────── */
.status-pill { display: inline-flex; align-items: center; padding: 3px 9px; border-radius: 999px; font-size: 11px; font-weight: 600; white-space: nowrap; }
.pill-active   { background: var(--primary-light); color: var(--primary-dark); }
.pill-inactive { background: var(--danger-light); color: var(--danger); }
.pill-neutral  { background: var(--bg-hover); color: var(--text-muted); }
.pill-purple   { background: var(--mebbi-light); color: var(--mebbi); }
.pill-orange   { background: var(--secondary-light); color: var(--secondary); }

.tag-dot { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; font-size: 11px; font-weight: 600; border: 1px solid transparent; }
.dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }

/* ── Tables ───────────────────────────────────────────────── */
.table-wrapper { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.data-table th { padding: 11px 14px; text-align: left; font-size: 11px; font-weight: 700; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; border-bottom: 1px solid var(--border); background: var(--bg-app); white-space: nowrap; }
.data-table td { padding: 12px 14px; border-bottom: 1px solid var(--border-light); color: var(--text-body); vertical-align: middle; }
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: var(--bg-hover); }
.text-end   { text-align: right; }
.text-center{ text-align: center; }
.empty-state { text-align: center; padding: 48px 20px; color: var(--text-subtle); }
.empty-state svg { width: 40px; height: 40px; fill: var(--border); margin-bottom: 10px; }
.empty-state p { color: var(--text-muted); margin-bottom: 12px; font-size: 13px; }

/* ── Filters / Search / Selects ───────────────────────────── */
.filters-bar { display: flex; flex-wrap: wrap; gap: 10px; align-items: end; margin-bottom: 16px; }
.filter-group { display: flex; flex-direction: column; gap: 5px; }
.filter-group label { font-size: 11px; font-weight: 600; color: var(--text-muted); }
.search-input, .select-input, .date-input-el {
  padding: 8px 12px; border: 1px solid var(--border); border-radius: var(--radius-md);
  font-size: 12.5px; font-family: var(--font); color: var(--text-body); background: var(--bg-white); outline: none;
}
.search-input:focus, .select-input:focus, .date-input-el:focus { border-color: var(--primary); }

/* ── Forms ────────────────────────────────────────────────── */
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; }
@media (max-width: 700px) { .form-grid { grid-template-columns: 1fr; } }
.form-grid .span-2 { grid-column: 1 / -1; }

.form-group  { margin-bottom: 4px; }
.form-label  { display: block; font-size: 12px; font-weight: 600; color: var(--text-body); margin-bottom: 6px; }
.form-label .req { color: var(--danger); }
.form-input, .form-select, .form-textarea {
  width: 100%; padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-size: 13px; font-family: var(--font);
  color: var(--text-heading);
  background: var(--bg-white);
  transition: border-color .15s;
  outline: none;
}
.form-textarea { resize: vertical; }
.form-input:focus, .form-select:focus, .form-textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(54,183,107,.1); }
.form-hint { color: var(--text-subtle); font-weight: 400; font-size: 11px; margin-top: 4px; display: block; }
.input-prefix-group { display: flex; align-items: stretch; }
.input-prefix { display: flex; align-items: center; padding: 0 10px; background: var(--bg-app); border: 1px solid var(--border); border-right: none; border-radius: var(--radius-md) 0 0 var(--radius-md); font-size: 12px; color: var(--text-muted); font-weight: 600; }
.input-prefix-group .form-input { border-radius: 0 var(--radius-md) var(--radius-md) 0; }
.form-check { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--text-body); }
.form-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--border-light); }

/* ── Alerts ───────────────────────────────────────────────── */
.alert { padding: 12px 16px; border-radius: var(--radius-md); font-size: 13px; font-weight: 500; margin-bottom: 16px; display: flex; align-items: center; gap: 10px; }
.alert svg { width: 18px; height: 18px; flex-shrink: 0; }
.alert-success { background: var(--primary-light); color: var(--primary-dark); border: 1px solid var(--primary); }
.alert-danger  { background: var(--danger-light); color: #DC2626; border: 1px solid #FECACA; }
.alert-warning { background: var(--secondary-light); color: #92400E; border: 1px solid var(--secondary); }
.alert-info    { background: #EFF6FF; color: #1E40AF; border: 1px solid #93C5FD; }

.flash-toast { position: fixed; top: 20px; right: 20px; z-index: 5000; min-width: 300px; max-width: 420px; box-shadow: var(--shadow-md); animation: fadeInUp .3s ease-out; }

/* ── Progress ─────────────────────────────────────────────── */
.progress-bar-track { height: 6px; background: var(--border); border-radius: 999px; overflow: hidden; }
.progress-bar-fill  { height: 100%; border-radius: 999px; transform-origin: left; animation: progressFill .7s ease-out both; width: var(--target, 0%); }
.progress-bar-fill.green  { background: var(--primary); }
.progress-bar-fill.orange { background: var(--secondary); }
.progress-bar-fill.red    { background: var(--danger); }

/* ── List rows (rankings) ─────────────────────────────────── */
.rank-list { display: flex; flex-direction: column; }
.rank-item { padding: 10px 0; border-bottom: 1px solid var(--border-light); }
.rank-item:last-child { border-bottom: none; }
.rank-item-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; gap: 8px; }
.rank-item-name { font-size: 12.5px; font-weight: 600; color: var(--text-heading); }
.rank-item-sub  { font-size: 11px; color: var(--text-subtle); }
.rank-item-value{ font-size: 12.5px; font-weight: 700; white-space: nowrap; }

/* ── Charts ───────────────────────────────────────────────── */
.chart-wrapper { position: relative; height: 240px; }
.chart-wrapper.sm { height: 200px; }
.chart-wrapper canvas { width: 100% !important; height: 100% !important; }

/* ── Modal ────────────────────────────────────────────────── */
.modal-overlay { display: none; position: fixed; inset: 0; background: rgba(17,24,39,.5); z-index: 2000; place-items: center; padding: 20px; }
.modal-overlay.open { display: grid; }
.modal { background: var(--bg-white); border-radius: var(--radius-xl); padding: 24px; width: 480px; max-width: 100%; max-height: 90vh; overflow-y: auto; box-shadow: 0 20px 50px rgba(0,0,0,.25); animation: fadeInUp .25s ease-out; }
.modal-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.modal-header h3 { font-size: 15px; font-weight: 700; color: var(--text-heading); }
.modal-close { background: none; border: none; font-size: 18px; cursor: pointer; color: var(--text-muted); border-radius: var(--radius-sm); padding: 3px 8px; line-height: 1; }
.modal-close:hover { background: var(--bg-hover); }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 18px; }

/* ── Login Page ───────────────────────────────────────────── */
.login-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: linear-gradient(135deg, var(--mebbi) 0%, var(--mebbi-dark) 100%); }
.login-wrapper { width: 100%; max-width: 420px; padding: 20px; }
.login-card { background: var(--bg-white); border-radius: var(--radius-xl); padding: 36px; box-shadow: 0 24px 60px rgba(0,0,0,.35); }
.login-logo { display: flex; justify-content: center; margin-bottom: 22px; }
.login-logo-img { height: 46px; width: auto; }
.login-title { font-size: 21px; font-weight: 700; color: var(--text-heading); text-align: center; margin-bottom: 4px; }
.login-subtitle { font-size: 13px; color: var(--text-muted); text-align: center; margin-bottom: 24px; }
.login-form { margin-top: 18px; display: flex; flex-direction: column; gap: 16px; }
.login-hint { font-size: 11px; color: var(--text-subtle); text-align: center; margin-top: 18px; line-height: 1.6; }

/* ── Text helpers ─────────────────────────────────────────── */
.text-muted { color: var(--text-muted); }
.text-subtle{ color: var(--text-subtle); }
.text-sm    { font-size: 12px; }
.text-xs    { font-size: 11px; }
.fw-600     { font-weight: 600; }
.fw-700     { font-weight: 700; }
.text-green { color: var(--primary-dark); }
.text-orange{ color: var(--secondary); }
.text-red   { color: var(--danger); }
.text-mebbi { color: var(--mebbi); }
.mt-1 { margin-top: 4px; } .mt-2 { margin-top: 8px; } .mt-3 { margin-top: 16px; }
.mb-0 { margin-bottom: 0 !important; }
.d-flex { display: flex; } .align-center { align-items: center; } .justify-between { justify-content: space-between; } .gap-2 { gap: 8px; } .gap-3 { gap: 12px; }
.flex-wrap { flex-wrap: wrap; }
.grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
@media (max-width: 900px) { .grid-2, .grid-3 { grid-template-columns: 1fr; } }
