/* ── Layout ────────────────────────────────────────── */
.page-wrap {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

body::after {
  content: '';
  position: fixed;
  inset: 0;
  /* Modern subtle grid + noise texture */
  background-image:
    linear-gradient(to right, rgba(255, 255, 255, 0.05) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(255, 255, 255, 0.05) 1px, transparent 1px),
    url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noiseFilter'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.7' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noiseFilter)' opacity='0.07'/%3E%3C/svg%3E");
  background-size:
    50px 50px,
    50px 50px,
    120px 120px;
  background-position: center center;
  mask-image: radial-gradient(
    ellipse at 50% 40%,
    rgba(0, 0, 0, 1) 20%,
    rgba(0, 0, 0, 0) 80%
  );
  -webkit-mask-image: radial-gradient(
    ellipse at 50% 40%,
    rgba(0, 0, 0, 1) 20%,
    rgba(0, 0, 0, 0) 80%
  );
  pointer-events: none;
  z-index: 0;
}

/* Content body: sidebar + main side by side */
.content-body {
  display: flex;
  flex: 1;
  min-height: 0;
}

.main {
  flex: 1;
  min-width: 0;
  padding: 40px 32px 80px;
  max-width: 1200px;
  margin: 0 auto;
}

/* ── Topbar ────────────────────────────────────────── */
.topbar {
  position: sticky;
  top: 0;
  z-index: 200;
  background: rgba(6, 12, 26, 0.75);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  padding: 0 24px;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

/* Hide old topbar-nav — navigation is now in the sidebar */
.topbar-nav {
  display: none !important;
}

/* Left area: brand logo and hamburger */
.topbar-left {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
  margin-right: auto;
}

/* Logo inside topbar-left */
.topbar-logo {
  display: flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
}

.logo-icon {
  width: 36px;
  height: 36px;
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 17px;
  box-shadow: 0 4px 14px var(--primary-glow);
}

.logo-text {
  font-weight: 800;
  font-size: 1.1rem;
}

/* Hamburger: only on mobile */
.btn-hamburger {
  display: none;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 10px;
  color: var(--text-light);
  cursor: pointer;
  padding: 8px;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  flex-shrink: 0;
}
.btn-hamburger:hover {
  background: rgba(99, 102, 241, 0.15);
  border-color: rgba(99, 102, 241, 0.3);
  color: var(--text);
}

/* ── App Sidebar ────────────────────────────────────── */
.app-sidebar {
  --sb-w: 280px;
  --sb-cw: 68px;
  position: sticky;
  padding-block: 16px;
  top: 64px;
  height: calc(100vh - 64px);
  width: var(--sb-w);
  flex-shrink: 0;
  background: linear-gradient(
    180deg,
    rgba(10, 16, 35, 0.98) 0%,
    rgba(6, 12, 26, 0.99) 100%
  );
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  overflow-y: auto;
  transition: all 0.35s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 150;
  box-shadow: 4px 0 24px rgba(0, 0, 0, 0.25);
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.08) transparent;
}

/* Sidebar inner gradient glow */
.app-sidebar::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 200px;
  background: radial-gradient(
    ellipse 120% 80% at 50% -10%,
    rgba(99, 102, 241, 0.12) 0%,
    transparent 70%
  );
  pointer-events: none;
  z-index: 0;
}

.app-sidebar:not(:hover) {
  width: var(--sb-cw);
  overflow-y: hidden;
}

/* Sidebar Header */
.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 16px 14px;
  flex-shrink: 0;
  position: relative;
  z-index: 1;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
  margin-bottom: 6px;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  overflow: hidden;
  min-width: 0;
  flex: 1;
}

.sidebar-logo-img {
  width: 32px;
  height: 32px;
  object-fit: contain;
  background: transparent;
  border-radius: 8px;
  flex-shrink: 0;
  filter: drop-shadow(0 0 8px rgba(99, 102, 241, 0.4));
  transition: filter 0.3s;
}

.sidebar-logo-img:hover {
  filter: drop-shadow(0 0 14px rgba(99, 102, 241, 0.7));
}

.sidebar-brand-text {
  font-weight: 800;
  font-size: 1.05rem;
  white-space: nowrap;
  opacity: 1;
  transform: translateX(0);
  transition:
    opacity 0.25s ease,
    transform 0.25s ease;
  overflow: hidden;
}

.app-sidebar:not(:hover) .sidebar-brand-text {
  opacity: 0;
  transform: translateX(-8px);
  pointer-events: none;
  width: 0;
}

/* Collapse button */
.sidebar-collapse-btn {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  color: var(--text-muted);
  cursor: pointer;
  padding: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  flex-shrink: 0;
  margin-left: 6px;
}

.sidebar-collapse-btn:hover {
  background: rgba(99, 102, 241, 0.15);
  border-color: rgba(99, 102, 241, 0.3);
  color: #818cf8;
}

.sidebar-collapse-btn svg {
  transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

.app-sidebar:not(:hover) .sidebar-collapse-btn svg {
  transform: rotate(180deg);
}

/* Section label */
.sidebar-section-label {
  font-size: 0.62rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--text-muted);
  padding: 0 16px 6px;
  white-space: nowrap;
  overflow: hidden;
  position: relative;
  z-index: 1;
  opacity: 1;
  transition:
    opacity 0.2s ease,
    padding 0.35s ease;
}

.app-sidebar:not(:hover) .sidebar-section-label {
  opacity: 0;
  padding-left: 0;
  padding-right: 0;
  height: 0;
  padding-bottom: 0;
}

/* Divider */
.sidebar-divider {
  height: 1px;
  background: linear-gradient(
    90deg,
    transparent,
    rgba(255, 255, 255, 0.06),
    transparent
  );
  margin: 10px 12px;
  flex-shrink: 0;
  position: relative;
  z-index: 1;
}

/* Nav container */
.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 0 8px;
  position: relative;
  z-index: 1;
}

/* Individual nav link */
.sidebar-link {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  border-radius: 12px;
  text-decoration: none;
  color: var(--text-light);
  font-size: 0.875rem;
  font-weight: 600;
  transition:
    background 0.2s ease,
    color 0.2s ease,
    border-color 0.2s ease,
    transform 0.15s ease,
    box-shadow 0.2s ease;
  border: 1px solid transparent;
  overflow: hidden;
  white-space: nowrap;
  cursor: pointer;
  font-family: inherit;
  background: none;
  width: 100%;
  text-align: left;
}

/* Animated left indicator bar */
.sidebar-link::before {
  content: '';
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%) scaleY(0);
  width: 3px;
  height: 100%;
  border-radius: 0 3px 3px 0;
  background: linear-gradient(to bottom, #818cf8, #6366f1);
  opacity: 0;
  transition:
    opacity 0.25s ease,
    transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.sidebar-link:hover::before,
.sidebar-link.active::before {
  opacity: 1;
  transform: translateY(-50%) scaleY(1);
}

.sidebar-link:hover {
  background: rgba(99, 102, 241, 0.08);
  border-color: rgba(99, 102, 241, 0.15);
  color: #c7d2fe;
  transform: translateX(2px);
}

.sidebar-link.active {
  background: linear-gradient(
    135deg,
    rgba(99, 102, 241, 0.18),
    rgba(99, 102, 241, 0.08)
  );
  border-color: rgba(99, 102, 241, 0.28);
  color: #a5b4fc;
  box-shadow:
    0 4px 16px rgba(99, 102, 241, 0.12),
    inset 0 1px 0 rgba(255, 255, 255, 0.05);
}

.sidebar-link.active .sidebar-link-icon {
  color: #818cf8;
  filter: drop-shadow(0 0 6px rgba(99, 102, 241, 0.5));
}

/* Link icon */
.sidebar-link-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 20px;
  color: inherit;
  transition:
    color 0.2s,
    filter 0.2s,
    transform 0.2s;
}

.sidebar-link:hover .sidebar-link-icon {
  transform: scale(1.1);
}

/* Link label */
.sidebar-link-label {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  transition:
    opacity 0.2s ease,
    transform 0.25s ease;
}

.app-sidebar:not(:hover) .sidebar-link-label {
  opacity: 0;
  transform: translateX(-6px);
  width: 0;
  pointer-events: none;
}

/* Tooltip (shown when sidebar is collapsed) */
.sidebar-link-tooltip {
  position: absolute;
  left: calc(100% + 12px);
  top: 50%;
  transform: translateY(-50%) translateX(-4px);
  background: rgba(15, 23, 42, 0.97);
  border: 1px solid rgba(99, 102, 241, 0.3);
  color: #f1f5f9;
  font-size: 0.8rem;
  font-weight: 700;
  white-space: nowrap;
  padding: 6px 12px;
  border-radius: 8px;
  pointer-events: none;
  opacity: 0;
  transition:
    opacity 0.18s ease,
    transform 0.18s ease;
  z-index: 500;
  box-shadow:
    0 8px 24px rgba(0, 0, 0, 0.4),
    0 0 0 1px rgba(99, 102, 241, 0.1);
}

.sidebar-link-tooltip::before {
  content: '';
  position: absolute;
  right: 100%;
  top: 50%;
  transform: translateY(-50%);
  border-top: 5px solid transparent;
  border-bottom: 5px solid transparent;
  border-right: 6px solid rgba(99, 102, 241, 0.3);
}

.app-sidebar:not(:hover) .sidebar-link:hover .sidebar-link-tooltip {
  opacity: 1;
  transform: translateY(-50%) translateX(0);
}

/* Footer */
.sidebar-footer {
  margin-top: auto;
  padding: 14px 16px;
  border-top: 1px solid rgba(255, 255, 255, 0.04);
  flex-shrink: 0;
  position: relative;
  z-index: 1;
  overflow: hidden;
}

.sidebar-footer-text {
  font-size: 0.68rem;
  color: var(--text-muted);
  white-space: nowrap;
  transition: opacity 0.2s;
}

.app-sidebar:not(:hover) .sidebar-footer-text {
  opacity: 0;
}

/* Sidebar overlay (mobile) */
/* Overlay is position:fixed so it's out of flex flow */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 249;
  opacity: 0;
  transition: opacity 0.3s ease;
  pointer-events: none;
}

.sidebar-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

/* ── Scrollbars ──────────────────────────────────────── */
select {
  background-color: rgba(6, 12, 26, 0.5) !important;
}

*::-webkit-scrollbar {
  width: 6px;
}

*::-webkit-scrollbar-track {
  background: transparent;
}

*::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 10px;
}

*::-webkit-scrollbar-thumb:hover {
  background: rgba(16, 185, 129, 0.3);
}

/* Badge dot pulse */
.badge-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #34d399;
  animation: pulse-dot 2s infinite;
}

@keyframes pulse-dot {
  0%,
  100% {
    opacity: 1;
    transform: scale(1);
  }
  50% {
    opacity: 0.4;
    transform: scale(1.5);
  }
}

/* btn-logout nav-label (tooltip) */
.btn-logout .nav-label {
  display: none;
}

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

.badge-location {
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(16, 185, 129, 0.1);
  border: 1px solid rgba(16, 185, 129, 0.2);
  padding: 6px 12px;
  border-radius: 9999px;
  font-size: 0.73rem;
  font-weight: 700;
  color: #34d399;
}

.btn-logout {
  display: flex;
  align-items: center;
  gap: 7px;
  background: rgba(244, 63, 94, 0.08);
  border: 1px solid rgba(244, 63, 94, 0.2);
  color: #fb7185;
  padding: 8px 14px;
  border-radius: 10px;
  font-size: 0.8rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s;
  font-family: inherit;
}

.btn-logout:hover {
  background: rgba(244, 63, 94, 0.15);
  border-color: rgba(244, 63, 94, 0.35);
}

/* ── Nav link (kept for btn-logout style) ───────────── */
.nav-link {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  color: var(--text-light);
  font-size: 0.85rem;
  font-weight: 600;
  padding: 8px 10px;
  border-radius: 10px;
  transition:
    background 0.2s,
    border-color 0.2s,
    color 0.2s;
  border: 1px solid transparent;
}

/* ── Mobile responsive ─────────────────────────────── */
@media (max-width: 900px) {
  .topbar {
    justify-content: space-between; /* On mobile, we want space-between for left area and right area */
    padding: 0 16px;
  }

  /* Show left area (hamburger + logo) on mobile */
  .topbar-left {
    display: flex !important;
    margin-right: 0;
  }

  /* Hamburger and topbar-logo will inherit flex from topbar-left */
  .btn-hamburger {
    display: flex !important;
  }

  /* Sidebar becomes a fixed drawer from left */
  .app-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100%;
    width: 280px !important;
    z-index: 300;
    transform: translateX(-100%);
    transition:
      transform 0.35s cubic-bezier(0.4, 0, 0.2, 1),
      width 0.35s ease;
    box-shadow: 8px 0 40px rgba(0, 0, 0, 0.5);
    /* Never collapsed on mobile */
  }

  /* When open, slide in */
  .app-sidebar.mobile-open {
    transform: translateX(0);
  }

  /* Show overlay on mobile when sidebar is open */
  .sidebar-overlay {
    display: block;
  }

  /* Hide collapse button on mobile (sidebar is always expanded when open) */
  .sidebar-collapse-btn {
    display: none;
  }

  /* Always show labels on mobile */
  .app-sidebar .sidebar-brand-text,
  .app-sidebar .sidebar-link-label,
  .app-sidebar .sidebar-section-label,
  .app-sidebar .sidebar-footer-text {
    opacity: 1 !important;
    transform: none !important;
    width: auto !important;
    height: auto !important;
    padding-bottom: inherit;
    pointer-events: auto !important;
  }

  .content-body {
    flex-direction: column;
  }

  .main {
    padding: 28px 16px 60px;
  }
}

@media (max-width: 640px) {
  .topbar {
    padding: 0 12px;
  }
  .credit-badge-group,
  #plan-badge {
    display: none;
  }
  .main {
    padding: 20px 14px 60px;
  }
}

.page-label {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: rgba(99, 102, 241, 0.1);
  border: 1px solid rgba(99, 102, 241, 0.22);
  padding: 5px 14px;
  border-radius: 9999px;
  font-size: 0.72rem;
  font-weight: 700;
  color: #818cf8;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-bottom: 14px;
}

.page-title {
  font-size: clamp(2rem, 4vw, 3rem);
  font-weight: 800;
  letter-spacing: -0.04em;
  line-height: 1.1;
  background: linear-gradient(to right, #f1f5f9, #94a3b8);
  background-clip: text;
  -webkit-text-fill-color: transparent;
  margin-bottom: 10px;
}

.page-subtitle {
  color: var(--text-light);
  font-size: 1rem;
  max-width: 540px;
}

/* ── Search card ───────────────────────────────────── */
.search-card {
  background: var(--card);
  backdrop-filter: blur(16px);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 36px;
  box-shadow: var(--shadow);
  margin-bottom: 32px;
  position: relative;
  overflow: hidden;
}

.search-card::before {
  content: '';
  position: absolute;
  top: -40px;
  right: -40px;
  width: 180px;
  height: 180px;
  background: radial-gradient(
    circle,
    rgba(99, 102, 241, 0.08) 0%,
    transparent 70%
  );
  pointer-events: none;
}

.search-card-title {
  font-size: 0.75rem;
  font-weight: 800;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin-bottom: 22px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.search-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* Inner grid for address fields (rua + numero side by side) */
#fields-address {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

#unidade-group,
#address-opportunities-wrap {
  grid-column: 1 / -1;
}

#fields-building {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* Actions row (clear btn + search btn) */
.search-form-actions {
  display: flex;
  gap: 8px;
  align-items: stretch;
}

@media (max-width: 640px) {
  #fields-address {
    grid-template-columns: 1fr;
  }
}

/* ── Credit Badge ──────────────────────────────────── */
.credit-badge-group {
  display: flex;
  align-items: stretch;
  gap: 0;
}

.credit-badge-group #credit-badge {
  border-top-right-radius: 0;
  border-bottom-right-radius: 0;
  border-right: none;
}

.btn-add-credits-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: auto;
  border-radius: 0 9999px 9999px 0;
  background: rgba(245, 158, 11, 0.1);
  border: 1px solid rgba(245, 158, 11, 0.28);
  border-left: 1px solid rgba(245, 158, 11, 0.15);
  color: #fbbf24;
  cursor: pointer;
  transition: all 0.2s ease;
  /* box-shadow: 0 2px 8px rgba(245, 158, 11, 0.1); */
  padding: 0;
}

.btn-add-credits-nav:hover {
  background: rgba(245, 158, 11, 0.2);
  border-color: rgba(245, 158, 11, 0.4);
  border-left-color: rgba(245, 158, 11, 0.3);
  transform: none;
  box-shadow: 0 4px 12px rgba(245, 158, 11, 0.15);
}

.btn-add-credits-nav svg {
  width: 14px;
  height: 14px;
}

.credit-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(245, 158, 11, 0.1);
  border: 1px solid rgba(245, 158, 11, 0.28);
  padding: 6px 13px;
  border-radius: 9999px;
  font-size: 0.75rem;
  font-weight: 800;
  color: #fbbf24;
  letter-spacing: 0.02em;
  transition: all 0.3s;
  white-space: nowrap;
}

.credit-badge.low {
  background: rgba(244, 63, 94, 0.1);
  border-color: rgba(244, 63, 94, 0.3);
  color: #fb7185;
  animation: pulse-low 1.8s ease-in-out infinite;
}

.credit-badge.admin-badge {
  background: rgba(99, 102, 241, 0.1);
  border-color: rgba(99, 102, 241, 0.28);
  color: #818cf8;
}

.plan-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(99, 102, 241, 0.1);
  border: 1px solid rgba(99, 102, 241, 0.28);
  padding: 6px 13px;
  border-radius: 9999px;
  font-size: 0.75rem;
  font-weight: 800;
  color: #818cf8;
  letter-spacing: 0.02em;
  transition: all 0.3s;
  white-space: nowrap;
}

.credit-badge-skeleton {
  width: 90px;
  height: 28px;
  border-radius: 9999px;
  background: linear-gradient(
    90deg,
    rgba(255, 255, 255, 0.04) 25%,
    rgba(255, 255, 255, 0.09) 50%,
    rgba(255, 255, 255, 0.04) 75%
  );
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
}

@keyframes shimmer {
  0% {
    background-position: 200% 0;
  }

  100% {
    background-position: -200% 0;
  }
}

@keyframes pulse-low {
  0%,
  100% {
    box-shadow: 0 0 0 0 rgba(244, 63, 94, 0);
  }

  50% {
    box-shadow: 0 0 0 4px rgba(244, 63, 94, 0.15);
  }
}
[data-theme='light'] .credit-badge {
  background: rgba(255, 255, 255, 0.9) !important;
  border-color: rgba(0, 0, 0, 0.08) !important;
  color: #0f172a !important;
}

[data-theme='light'] .btn-add-credits-nav {
  background: rgba(255, 255, 255, 0.9) !important;
  border-color: rgba(0, 0, 0, 0.08) !important;
  color: #0f172a !important;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05) !important;
}

[data-theme='light'] .btn-add-credits-nav:hover {
  background: #f1f5f9 !important;
  border-color: rgba(0, 0, 0, 0.15) !important;
}
