/* =====================================================================
   Sistema Unificado Super Epa — Shell CSS
   ===================================================================== */

:root {
  --bg:           #f4f6fb;
  --bg-elev:      #ffffff;
  --bg-sidebar:   #0f172a;
  --bg-topbar:    #ffffff;
  --surface:      #ffffff;
  --surface-2:    #f8fafc;
  --border:       #e5e7eb;
  --border-soft:  #f1f5f9;

  --text:         #0f172a;
  --text-muted:   #64748b;
  --text-soft:    #94a3b8;
  --text-inv:     #f8fafc;

  --primary:      #2563eb;
  --primary-hover:#1d4ed8;
  --primary-soft: #dbeafe;
  --accent:       #7c3aed;
  --success:      #16a34a;
  --warning:      #d97706;
  --danger:       #dc2626;

  --shadow-sm:    0 1px 2px rgba(15,23,42,.06);
  --shadow:       0 4px 12px rgba(15,23,42,.08);
  --shadow-lg:    0 12px 28px rgba(15,23,42,.12);

  --radius-sm:    8px;
  --radius:       12px;
  --radius-lg:    18px;

  --sidebar-w:    260px;
  --sidebar-w-mini: 72px;
  --topbar-h:     60px;

  --transition:   all .22s cubic-bezier(.4,0,.2,1);
  --font:         'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

[data-theme="dark"] {
  --bg:           #0b1220;
  --bg-elev:      #111a2e;
  --bg-sidebar:   #060d1c;
  --bg-topbar:    #111a2e;
  --surface:      #131e36;
  --surface-2:    #0f192e;
  --border:       #1f2a44;
  --border-soft:  #1a2540;

  --text:         #e8eef7;
  --text-muted:   #b6c2d6;  /* subido pra atingir WCAG AA em fundos escuros */
  --text-soft:    #8a99b3;

  --primary:      #60a5fa;
  --primary-hover:#93c5fd;
  --primary-soft: rgba(96,165,250,.18);

  --shadow-sm:    0 1px 2px rgba(0,0,0,.4);
  --shadow:       0 4px 12px rgba(0,0,0,.5);
  --shadow-lg:    0 12px 28px rgba(0,0,0,.6);
}

/* ---------- Foco visível (acessibilidade) ---------- */
:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
  border-radius: 6px;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; overflow-x: hidden; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  transition: background .25s ease, color .25s ease;
}
a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; }

.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  grid-template-rows: var(--topbar-h) 1fr;
  grid-template-areas:
    "sidebar topbar"
    "sidebar main";
  min-height: 100vh;
  transition: grid-template-columns .25s ease;
}
.app-shell.collapsed { grid-template-columns: var(--sidebar-w-mini) 1fr; }

/* ---------- Sidebar ---------- */
.sidebar {
  grid-area: sidebar;
  background: var(--bg-sidebar);
  color: #cbd5e1;
  display: flex;
  flex-direction: column;
  border-right: 1px solid rgba(255,255,255,.05);
  overflow: hidden auto;
  position: relative;
  z-index: 20;
}
.sidebar::-webkit-scrollbar { width: 6px; }
.sidebar::-webkit-scrollbar-thumb { background: rgba(255,255,255,.08); border-radius: 3px; }

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 18px 22px;
  border-bottom: 1px solid rgba(255,255,255,.06);
  min-height: var(--topbar-h);
}
.sidebar-brand .logo {
  width: 38px; height: 38px;
  border-radius: 10px;
  background: linear-gradient(135deg, #2563eb, #7c3aed);
  display: grid; place-items: center;
  font-weight: 800; color: #fff; font-size: 14px;
  letter-spacing: .5px;
  flex-shrink: 0;
  box-shadow: 0 4px 12px rgba(124,58,237,.35);
}

.sidebar-brand .logo img { width: 100%; height: 100%; object-fit: cover; border-radius: inherit; display: block; }
.sidebar-brand .logo { padding: 0; background: #fff; overflow: hidden; }

.sidebar-brand .brand-text {
  display: flex; flex-direction: column;
  white-space: nowrap;
  overflow: hidden;
}
.sidebar-brand .brand-name { color: #fff; font-weight: 700; font-size: 15px; }
.sidebar-brand .brand-sub  { color: #64748b; font-size: 11px; }

.sidebar-nav {
  list-style: none;
  margin: 0;
  padding: 8px 12px 20px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

/* Item principal (top-level) */
.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 10px;
  color: #cbd5e1;
  font-weight: 500;
  cursor: pointer;
  position: relative;
  transition: var(--transition);
  white-space: nowrap;
}
.nav-item:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav-item.active {
  background: linear-gradient(135deg, rgba(37,99,235,.25), rgba(124,58,237,.25));
  color: #fff;
  box-shadow: inset 3px 0 0 #3b82f6;
}
.nav-item .icon { width: 20px; height: 20px; flex-shrink: 0; display: grid; place-items: center; }
.nav-item .label { flex: 1; overflow: hidden; text-overflow: ellipsis; }
.collapsed .nav-item .label { opacity: 0; width: 0; }

/* Tooltip quando sidebar colapsada */
.collapsed .nav-item { position: relative; }
.collapsed .nav-item::after {
  content: attr(title);
  position: absolute;
  left: calc(100% + 12px);
  top: 50%;
  transform: translateY(-50%);
  background: var(--text);
  color: var(--bg);
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity .15s;
  z-index: 100;
  box-shadow: var(--shadow);
}
.collapsed .nav-item:hover::after { opacity: 1; }

/* Grupo expansível */
.nav-group {
  margin-top: 10px;
}
.nav-group-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  cursor: pointer;
  border-radius: 8px;
  color: #94a3b8;
  text-transform: uppercase;
  font-size: 10.5px;
  letter-spacing: 1.2px;
  font-weight: 600;
  user-select: none;
  transition: var(--transition);
}
.nav-group-header:hover { color: #fff; }
.nav-group-header .group-icon {
  width: 18px; height: 18px;
  display: grid; place-items: center;
  color: #64748b;
}
.nav-group-header .group-label { flex: 1; }
.nav-group-header .group-chevron {
  width: 16px; height: 16px;
  display: grid; place-items: center;
  transition: transform .25s;
}
.nav-group.expanded .group-chevron { transform: rotate(90deg); }
.collapsed .nav-group-header { padding: 6px 12px; }
.collapsed .nav-group-header .group-label,
.collapsed .nav-group-header .group-chevron { opacity: 0; width: 0; }

.nav-group-items {
  display: none;
  flex-direction: column;
  gap: 2px;
  padding: 4px 0 4px 8px;
  margin-left: 9px;
  border-left: 1px dashed rgba(255,255,255,.08);
}
.nav-group.expanded .nav-group-items { display: flex; }
.nav-group-items .nav-item { padding: 8px 10px; font-size: 13px; }
.nav-group-items .nav-item .icon svg { width: 16px; height: 16px; }

.sidebar-footer {
  margin-top: auto;
  padding: 14px 18px;
  border-top: 1px solid rgba(255,255,255,.06);
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 12px;
  color: #64748b;
}
.sidebar-footer .dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: #22c55e;
  box-shadow: 0 0 6px #22c55e;
  flex-shrink: 0;
}
.collapsed .sidebar-footer .status-text { display: none; }

/* ---------- Topbar ---------- */
.topbar {
  grid-area: topbar;
  background: var(--bg-topbar);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 16px;
  box-shadow: var(--shadow-sm);
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar-toggle {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  width: 36px; height: 36px;
  border-radius: 8px;
  display: grid; place-items: center;
  transition: var(--transition);
}
.topbar-toggle:hover { background: var(--surface-2); color: var(--text); }

.topbar-title {
  font-weight: 600;
  font-size: 15px;
  color: var(--text);
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.topbar-title small {
  color: var(--text-muted);
  font-weight: 400;
  font-size: 11.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-spacer { flex: 1; }
.topbar-actions { display: flex; align-items: center; gap: 8px; }
.icon-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  width: 38px; height: 38px;
  border-radius: 10px;
  display: grid; place-items: center;
  transition: var(--transition);
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); border-color: var(--primary); }
.icon-btn svg { width: 18px; height: 18px; }

/* ---------- User chip melhorado ---------- */
.user-chip {
  display: flex; align-items: center; gap: 10px;
  padding: 6px 14px 6px 6px;
  border: 1px solid var(--border);
  border-radius: 30px;
  background: var(--surface);
  cursor: pointer;
  transition: var(--transition);
  max-width: 240px;
  min-width: 0;
  font-family: inherit;
  color: inherit;
  text-align: left;
}
.user-chip:hover { box-shadow: var(--shadow); border-color: var(--primary); }
.user-chip .avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: linear-gradient(135deg, #2563eb, #7c3aed);
  color: #fff;
  display: grid; place-items: center;
  font-weight: 700;
  font-size: 12px;
  flex-shrink: 0;
}
.user-chip .user-info {
  display: flex;
  flex-direction: column;
  min-width: 0;
  line-height: 1.2;
}
.user-chip .user-name {
  font-weight: 600;
  font-size: 13px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 160px;
}
.user-chip .user-email {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 160px;
}
.user-chip .chevron { color: var(--text-muted); flex-shrink: 0; }

/* dropdown user menu */
.dropdown {
  position: absolute;
  top: calc(var(--topbar-h) - 4px);
  right: 20px;
  min-width: 220px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 8px;
  z-index: 50;
  display: none;
  animation: dropIn .18s ease;
}
.dropdown.open { display: block; }
.dropdown .item {
  padding: 9px 12px;
  border-radius: 8px;
  font-size: 13.5px;
  display: flex; align-items: center; gap: 10px;
  cursor: pointer;
  color: var(--text);
  transition: var(--transition);
}
.dropdown .item:hover { background: var(--surface-2); }
.dropdown .item.danger { color: var(--danger); }
.dropdown .divider { height: 1px; background: var(--border); margin: 6px 0; }
@keyframes dropIn { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: translateY(0); } }

/* ---------- Main / iframe wrapper ---------- */
.main {
  grid-area: main;
  background: var(--bg);
  overflow: hidden;
  position: relative;
}
.module-frame {
  width: 100%;
  height: 100%;
  border: 0;
  background: var(--bg);
  display: block;
}
.module-skeleton {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  background: var(--bg);
  z-index: 5;
  transition: opacity .25s;
}
.module-skeleton.hidden { opacity: 0; pointer-events: none; }
.spinner {
  width: 38px; height: 38px;
  border: 3px solid var(--primary-soft);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Home (página principal) ---------- */
.home {
  padding: 32px 32px 48px;
  height: 100%;
  overflow-y: auto;
  animation: fadeIn .3s ease;
  max-width: 1400px;
}
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }

.home-header { margin-bottom: 32px; }
.home h1 {
  margin: 0 0 4px;
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.3px;
}
.home .subtitle {
  color: var(--text-muted);
  font-size: 14px;
}

/* ---------- Cores das categorias ---------- */
.cat-blue   { --cat-from: #3b82f6; --cat-to: #2563eb; --cat-soft: rgba(59,130,246,.12); --cat-fg: #2563eb; }
.cat-green  { --cat-from: #10b981; --cat-to: #059669; --cat-soft: rgba(16,185,129,.12); --cat-fg: #059669; }
.cat-orange { --cat-from: #f59e0b; --cat-to: #d97706; --cat-soft: rgba(245,158,11,.12); --cat-fg: #d97706; }

[data-theme="dark"] .cat-blue   { --cat-fg: #60a5fa; }
[data-theme="dark"] .cat-green  { --cat-fg: #34d399; }
[data-theme="dark"] .cat-orange { --cat-fg: #fbbf24; }

/* Cabeçalhos de categoria */
.category-section { margin-bottom: 32px; }
.category-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 0 0 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}
.category-header .cat-icon {
  width: 34px; height: 34px;
  border-radius: 10px;
  background: var(--cat-soft, var(--primary-soft));
  color: var(--cat-fg, var(--primary));
  display: grid; place-items: center;
  flex-shrink: 0;
}
.category-header .cat-icon svg { width: 18px; height: 18px; }
.category-header h2 {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: 0.1px;
}
.category-header .cat-count {
  font-size: 11.5px;
  font-weight: 500;
  color: var(--text-muted);
  background: var(--surface-2);
  padding: 3px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  margin-left: 4px;
}

/* ---------- Cards de dashboards ---------- */
.dashboard-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 16px;
}
.dashboard-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 22px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  transition: transform .22s cubic-bezier(.4,0,.2,1), box-shadow .22s, border-color .22s;
  box-shadow: var(--shadow-sm);
  text-align: left;
  font-family: inherit;
  color: inherit;
  width: 100%;
}
.dashboard-card::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, var(--cat-soft, rgba(37,99,235,.05)), transparent 60%);
  opacity: 0;
  transition: opacity .3s;
  pointer-events: none;
}
.dashboard-card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-lg);
  border-color: var(--cat-fg, var(--primary));
}
.dashboard-card:hover::before { opacity: 1; }
.dashboard-card > * { position: relative; }

.dashboard-card .card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 14px;
  gap: 10px;
}
.dashboard-card .card-icon {
  width: 46px; height: 46px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--cat-from, var(--primary)), var(--cat-to, var(--accent)));
  color: #fff;
  display: grid; place-items: center;
  box-shadow: 0 6px 16px var(--cat-soft, rgba(37,99,235,.30));
  flex-shrink: 0;
}
.dashboard-card .card-icon svg { width: 22px; height: 22px; }
.dashboard-card h3 {
  margin: 0 0 6px;
  font-size: 15.5px;
  font-weight: 700;
  color: var(--text);
}
.dashboard-card p {
  margin: 0 0 16px;
  color: var(--text-muted);
  font-size: 13px;
  line-height: 1.5;
  min-height: 38px;
}
.dashboard-card .card-cta {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--cat-fg, var(--primary));
  font-weight: 600;
  font-size: 13px;
}
.dashboard-card .card-cta-icon {
  display: inline-flex;
  transition: transform .22s;
}
.dashboard-card:hover .card-cta-icon { transform: translateX(3px); }

/* ---------- Badge de atualização ---------- */
.update-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 9px;
  border-radius: 999px;
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.2px;
  text-transform: none;
  white-space: nowrap;
  border: 1px solid transparent;
}
.update-badge.live {
  background: rgba(16,185,129,.12);
  color: #059669;
  border-color: rgba(16,185,129,.25);
}
[data-theme="dark"] .update-badge.live { color: #34d399; }
.update-badge.live .pulse {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: #10b981;
  box-shadow: 0 0 0 0 rgba(16,185,129,.6);
  animation: pulse-dot 2s infinite;
}
@keyframes pulse-dot {
  0% { box-shadow: 0 0 0 0 rgba(16,185,129,.7); }
  70% { box-shadow: 0 0 0 6px rgba(16,185,129,0); }
  100% { box-shadow: 0 0 0 0 rgba(16,185,129,0); }
}
.update-badge.auto {
  background: var(--surface-2);
  color: var(--text-muted);
  border-color: var(--border);
}

/* ---------- Responsivo ---------- */
@media (max-width: 980px) {
  :root { --sidebar-w: 0px; }
  .app-shell {
    grid-template-columns: 0 1fr;
    grid-template-areas:
      "topbar topbar"
      "main   main";
  }
  .sidebar {
    position: fixed;
    top: 0; left: 0;
    height: 100vh;
    width: 260px;
    transform: translateX(-100%);
    transition: transform .3s ease;
    z-index: 100;
  }
  .sidebar.mobile-open { transform: translateX(0); box-shadow: var(--shadow-lg); }
  .sidebar-backdrop {
    position: fixed; inset: 0;
    background: rgba(0,0,0,.5);
    z-index: 90;
    display: none;
    animation: fadeIn .2s ease;
  }
  .sidebar-backdrop.active { display: block; }
  .home { padding: 18px; }
  .user-chip { max-width: 200px; }
}

@media (max-width: 640px) {
  .topbar { padding: 0 14px; gap: 10px; }
  .topbar-title { font-size: 13px; }
  .topbar-title small { display: none; }
  .home h1 { font-size: 18px; }
  .kpi { padding: 14px; }
  .kpi .info .num { font-size: 16px; }

  /* esconde texto do user chip em telas muito pequenas, mantém só avatar */
  .user-chip .user-info { display: none; }
  .user-chip .chevron { display: none; }
  .user-chip { padding: 4px; max-width: none; }
}
