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

/* ── Tema escuro (padrão) ── */
:root {
  --sidebar-width: 250px;
  --sidebar-icon-width: 62px;
  --topbar-height: 60px;

  --bg-dark: #0b1c2e;
  --bg-sidebar: #091625;
  --bg-topbar: #091625;
  --bg-item-hover: rgba(0, 230, 80, 0.08);
  --bg-item-active: rgba(0, 230, 80, 0.12);

  --accent: #00e650;

  --text-primary: #e8eaf0;
  --text-muted: #8892a4;
  --border: #1a2d42;
}

/* ── Tema claro ── */
body.theme-light {
  --bg-dark: #f0f4f8;
  --bg-sidebar: #e2eaf3;
  --bg-topbar: #ffffff;
  --bg-item-hover: rgba(0, 160, 60, 0.08);
  --bg-item-active: rgba(0, 160, 60, 0.13);
  --accent: #00a83c;
  --text-primary: #0f1e2e;
  --text-muted: #4a5568;
  --border: #c4d4e4;
}

body {
  font-family: 'Segoe UI', system-ui, sans-serif;
  font-size: 15px;
  background: var(--bg-dark);
  color: var(--text-primary);
  height: 100vh;
  overflow: hidden;
}

/* ── Topbar ── */
#topbar {
  height: var(--topbar-height);
  background: var(--bg-topbar);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 12px;
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 100;
  overflow: visible;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

.topbar-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
  overflow: visible;
  position: relative;
}

#nav-toggle {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 7px;
  border-radius: 7px;
  display: flex;
  align-items: center;
  transition: background 0.15s, color 0.15s;
}
#nav-toggle:hover { background: var(--bg-item-hover); color: var(--accent); }

#logo-img { height: 30px; width: 30px; }

.logo-text { font-size: 17px; font-weight: 700; color: var(--text-primary); letter-spacing: 0.5px; }
.logo-text span { color: var(--accent); }

/* Top nav */
#top-nav-items {
  display: none;
  flex: 1;
  align-items: center;
  gap: 4px;
  padding: 0 10px;
}

.top-nav-item {
  display: flex;
  align-items: center;
  gap: 0;
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
  color: var(--text-muted);
  border-bottom: 2px solid transparent;
  flex-shrink: 0;
  overflow: hidden;
  transition: color 0.15s, background 0.15s;
}
.top-nav-item:hover { color: var(--text-primary); background: var(--bg-item-hover); }
.top-nav-item:hover .top-label { max-width: 180px; margin-left: 8px; }
.top-nav-item.active { color: var(--accent); border-bottom-color: var(--accent); }
.top-nav-item.inactive { opacity: 0.35; cursor: not-allowed; }

.top-icon { font-size: 22px; line-height: 1; flex-shrink: 0; }
.top-icon svg { width: 22px; height: 22px; }

.top-label {
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  max-width: 0;
  transition: max-width 0.2s ease, margin-left 0.2s ease;
}

#module-breadcrumb {
  font-size: 14px;
  color: var(--text-muted);
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#user-wrap { position: relative; cursor: default; }

#user-name {
  font-size: 14px;
  color: var(--text-muted);
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  display: block;
}

#grupos-tooltip {
  position: fixed;
  background: var(--bg-sidebar);
  border: 1px solid var(--border);
  color: var(--text-primary);
  font-size: 13px;
  padding: 7px 14px;
  border-radius: 8px;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s;
  z-index: 9999;
  top: calc(var(--topbar-height) + 4px);
  right: 100px;
}
#user-wrap:hover #grupos-tooltip { opacity: 1; }

/* Botão tema */
#btn-theme {
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-muted);
  cursor: pointer;
  padding: 5px 7px;
  display: flex;
  align-items: center;
  transition: all 0.15s;
}
#btn-theme:hover { background: var(--bg-item-hover); color: var(--accent); border-color: var(--accent); }

#btn-logout {
  font-size: 13px;
  padding: 5px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}
#btn-logout:hover {
  background: rgba(239, 68, 68, 0.1);
  border-color: rgba(239, 68, 68, 0.4);
  color: #f87171;
}

/* ── Shell body ── */
#shell-body {
  display: flex;
  height: calc(100vh - var(--topbar-height));
  margin-top: var(--topbar-height);
  overflow: hidden;
}

/* ── Sidebar ── */
#sidebar {
  width: var(--sidebar-icon-width);
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow: hidden;
  transition: width 0.2s ease;
}

body.sidebar-open #sidebar { width: var(--sidebar-width); }

#nav-modules {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 6px 0 10px;
}

.nav-home {
  color: var(--accent) !important;
  font-weight: 600;
}
.nav-home.active { background: var(--bg-item-active); }
body.sidebar-open .nav-home.active { border-left-color: var(--accent) !important; }

.nav-separator {
  height: 1px;
  background: var(--border);
  margin: 6px 12px;
}

.nav-category {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: var(--text-muted);
  padding: 14px 16px 4px;
  white-space: nowrap;
  overflow: hidden;
  max-height: 0;
  opacity: 0;
  transition: max-height 0.2s, opacity 0.15s, padding 0.2s;
}
body.sidebar-open .nav-category { max-height: 40px; opacity: 1; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 0;
  padding: 10px 0;
  justify-content: center;
  cursor: pointer;
  border-radius: 8px;
  margin: 2px 6px;
  font-size: 15px;
  color: var(--text-primary);
  transition: background 0.15s, color 0.15s;
  user-select: none;
  white-space: nowrap;
  border-left: 2px solid transparent;
}
.nav-item:hover { background: var(--bg-item-hover); }
.nav-item.active { background: var(--bg-item-active); color: var(--accent); }
.nav-item.inactive { opacity: 0.35; cursor: not-allowed; }

body.sidebar-open .nav-item {
  gap: 10px;
  padding: 10px 16px;
  justify-content: flex-start;
  margin: 2px 8px;
}
body.sidebar-open .nav-item.active { border-left-color: var(--accent); }

.nav-icon {
  font-size: 20px;
  flex-shrink: 0;
  width: 24px;
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
}
.nav-icon svg { width: 20px; height: 20px; }

.nav-label {
  flex: none;
  overflow: hidden;
  text-overflow: ellipsis;
  opacity: 0;
  width: 0;
  transition: opacity 0.15s;
}
body.sidebar-open .nav-label { flex: 1; opacity: 1; width: auto; }

/* Botão expandir/recolher sidebar */
#sidebar-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  border-bottom: 1px solid var(--border);
  color: var(--text-muted);
  cursor: pointer;
  padding: 12px 0;
  width: 100%;
  flex-shrink: 0;
  transition: color 0.15s, background 0.15s;
}
#sidebar-btn:hover { background: var(--bg-item-hover); color: var(--accent); }

/* ── Layout top ── */
body.layout-top #sidebar { display: none; }
body.layout-top #top-nav-items { display: flex; }

/* ── Content ── */
#content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#welcome {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
}

.welcome-logo { width: 76px; height: 76px; opacity: 0.9; }

#welcome h2 { font-size: 24px; font-weight: 600; color: var(--text-primary); }
#welcome h2 em { font-style: normal; color: var(--accent); }
#welcome p { font-size: 15px; color: var(--text-muted); }

#module-frame {
  display: none;
  flex: 1;
  width: 100%;
  height: 100%;
  border: none;
  background: #fff;
}

#login-error {
  display: none;
}

/* ── Login page ── */
body.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
}

#login-box {
  background: var(--bg-sidebar);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 44px 40px;
  width: 100%;
  max-width: 380px;
  display: flex;
  flex-direction: column;
  gap: 30px;
}

#login-logo { display: flex; flex-direction: column; align-items: center; gap: 14px; }
#login-logo img { width: 90px; height: 90px; object-fit: contain; }

.login-brand { display: flex; align-items: baseline; gap: 1px; }
.login-brand-cb  { font-size: 26px; font-weight: 800; color: var(--text-primary); }
.login-brand-net { font-size: 26px; font-weight: 300; color: var(--text-primary); }
.login-brand-hub {
  font-size: 12px; color: var(--accent); margin-left: 9px;
  letter-spacing: 2px; text-transform: uppercase; font-weight: 600; align-self: center;
}

#login-form { display: flex; flex-direction: column; gap: 18px; }

.field { display: flex; flex-direction: column; gap: 7px; }
.field label { font-size: 14px; color: var(--text-muted); }
.field input {
  background: var(--bg-dark);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 11px 14px;
  color: var(--text-primary);
  font-size: 15px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.field input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(0, 230, 80, 0.1);
}
.field input::placeholder { color: var(--text-muted); opacity: 0.5; }

#btn-login {
  margin-top: 4px;
  padding: 13px;
  background: var(--accent);
  color: #071810;
  border: none;
  border-radius: 9px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.1s;
}
#btn-login:hover { opacity: 0.88; }
#btn-login:active { transform: scale(0.98); }
#btn-login:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }

.login-error {
  font-size: 14px;
  color: #f87171;
  text-align: center;
  background: rgba(239, 68, 68, 0.08);
  border: 1px solid rgba(239, 68, 68, 0.2);
  border-radius: 8px;
  padding: 9px 14px;
}

/* ── Backdrop (mobile) ── */
#sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  top: var(--topbar-height);
  background: rgba(0, 0, 0, 0.5);
  z-index: 199;
}

/* ── Mobile ── */
@media (max-width: 768px) {
  :root {
    --topbar-height: 54px;
  }

  /* Sidebar vira gaveta overlay */
  #sidebar {
    position: fixed;
    top: var(--topbar-height);
    left: 0;
    bottom: 0;
    width: var(--sidebar-width) !important;
    z-index: 200;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
  }

  body.sidebar-open #sidebar {
    transform: translateX(0);
  }

  body.sidebar-open #sidebar-backdrop {
    display: block;
  }

  /* Conteúdo ocupa tela toda (sidebar não empurra) */
  #shell-body {
    flex-direction: column;
  }

  #content {
    width: 100%;
  }

  /* Topbar simplificada */
  .logo-text { display: none; }
  #module-breadcrumb { display: none; }
  #user-name { max-width: 100px; font-size: 12px; }

  /* Botão de expandir sidebar fica escondido no mobile (hamburger faz o papel) */
  #sidebar-btn { display: none; }

  /* Sidebar sempre mostra labels no mobile quando aberta */
  #sidebar .nav-label { opacity: 1 !important; width: auto !important; }
  #sidebar .nav-item { padding: 11px 16px !important; justify-content: flex-start !important; margin: 2px 8px !important; }
  #sidebar .nav-item.active { border-left-color: var(--accent) !important; }
  #sidebar .nav-category { max-height: 40px !important; opacity: 1 !important; }

  /* Top nav escondido no mobile */
  body.layout-top #top-nav-items { display: none; }
  body.layout-top #sidebar { display: flex; }

  /* Login */
  #login-box { padding: 32px 24px; margin: 0 16px; }
}
