/* =============================================
   ATTOS GESTOR — Design System
   ============================================= */

:root {
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --sidebar-bg: #0f172a;
  --sidebar-width: 240px;
  --topbar-height: 60px;
  --content-bg: #f8fafc;
  --card-bg: #ffffff;
  --text-primary: #1e293b;
  --text-secondary: #64748b;
  --border-color: #e2e8f0;
  --success: #16a34a;
  --warning: #ca8a04;
  --danger: #dc2626;
  --info: #0284c7;
  --shadow-sm: 0 1px 3px rgba(0,0,0,.04);
  --shadow-md: 0 4px 12px rgba(0,0,0,.06);
  --shadow-lg: 0 8px 24px rgba(15,23,42,.10);
}

[data-bs-theme="dark"] {
  --content-bg: #0f172a;
  --card-bg: #1e293b;
  --text-primary: #f1f5f9;
  --border-color: #334155;
  --shadow-sm: 0 1px 3px rgba(0,0,0,.25);
  --shadow-md: 0 4px 12px rgba(0,0,0,.35);
  --shadow-lg: 0 8px 24px rgba(0,0,0,.45);
}

* { box-sizing: border-box; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background-color: var(--content-bg);
  color: var(--text-primary);
  margin: 0;
}

/* =============================================
   APP LAYOUT
   ============================================= */

.app-layout {
  display: flex;
  min-height: 100vh;
}

/* Sidebar */
.sidebar {
  width: var(--sidebar-width);
  background: var(--sidebar-bg);
  color: #cbd5e1;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 1000;
  overflow-y: auto;
  transition: transform 0.25s ease;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  text-decoration: none;
  color: #f1f5f9;
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.3px;
}

.sidebar-brand img { filter: drop-shadow(0 0 6px rgba(26, 63, 255, 0.5)); }

.sidebar-toggle { color: #94a3b8; border: none; padding: 0.25rem; }

.sidebar-tenant {
  padding: 0.75rem 1.25rem;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}

.tenant-name {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: #f1f5f9;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tenant-plan {
  display: block;
  font-size: 0.7rem;
  color: #64748b;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.sidebar-nav {
  list-style: none;
  padding: 0.75rem 0;
  margin: 0;
  flex: 1;
}

.sidebar-nav li a {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.55rem 1.25rem;
  color: #94a3b8;
  text-decoration: none;
  font-size: 0.875rem;
  border-radius: 0;
  transition: color 0.15s, background 0.15s;
}

.sidebar-nav li a:hover,
.sidebar-nav li a.active {
  color: #f1f5f9;
  background: rgba(255,255,255,0.07);
}

.sidebar-nav li a.active {
  background: rgba(79, 70, 229, 0.25);
  color: #818cf8;
  border-right: 2px solid #818cf8;
}

.sidebar-nav li a i { width: 18px; text-align: center; font-size: 1rem; }

.sidebar-section {
  padding: 0.6rem 1.25rem 0.2rem;
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: #475569;
  font-weight: 600;
}

.sidebar-footer {
  padding: 1rem 1.25rem;
  border-top: 1px solid rgba(255,255,255,0.08);
}

.user-info { display: flex; align-items: center; gap: 0.6rem; }

.user-avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  object-fit: cover;
}

.user-avatar-placeholder {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: #4f46e5;
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.8rem;
  flex-shrink: 0;
}

.user-details { overflow: hidden; }

.user-name {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: #f1f5f9;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-role {
  display: block;
  font-size: 0.7rem;
  color: #64748b;
  text-transform: capitalize;
}

/* Mobile overlay */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 999;
}

/* Main content */
.main-content {
  margin-left: var(--sidebar-width);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

/* Topbar */
.topbar {
  height: var(--topbar-height);
  background: var(--card-bg);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0 1.5rem;
  position: sticky;
  top: 0;
  z-index: 100;
}

.page-title {
  font-size: 1rem;
  font-weight: 600;
  margin: 0;
  flex: 1;
}

.topbar-toggle { color: var(--text-secondary); padding: 0.25rem; border: none; }
.topbar-actions { display: flex; gap: 0.5rem; }

/* Content area */
.content-area {
  padding: 1.5rem;
  flex: 1;
}

/* =============================================
   CARDS
   ============================================= */

.card {
  background: var(--card-bg);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  box-shadow: var(--shadow-sm);
}

.card-header {
  background: transparent;
  border-bottom: 1px solid var(--border-color);
  padding: 0.875rem 1.25rem;
  font-weight: 600;
}

.card-footer {
  background: transparent;
  border-top: 1px solid var(--border-color);
  padding: 0.75rem 1.25rem;
}

.pagination .page-link { color: var(--text-primary); border-color: var(--border-color); }
.pagination .page-item.active .page-link { background: var(--primary); border-color: var(--primary); }
.pagination .page-item.disabled .page-link { color: var(--text-secondary); background: transparent; }

/* =============================================
   STAT CARDS
   ============================================= */

.stat-card {
  background: var(--card-bg);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  padding: 1.25rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  box-shadow: var(--shadow-sm);
  transition: box-shadow .15s ease, transform .15s ease;
}

.stat-card:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

.stat-delta {
  display: inline-flex;
  align-items: center;
  font-weight: 600;
  font-size: 0.7rem;
  margin-left: 0.35rem;
}

.stat-delta.up { color: var(--success); }
.stat-delta.down { color: var(--danger); }

.stat-icon {
  width: 50px; height: 50px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  flex-shrink: 0;
}

.stat-body { overflow: hidden; }

.stat-value {
  display: block;
  font-size: 1.4rem;
  font-weight: 700;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.stat-label {
  display: block;
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin-top: 0.15rem;
}

.bg-primary-soft { background: rgba(79,70,229,0.1); }
.bg-success-soft { background: rgba(22,163,74,0.1); }
.bg-warning-soft { background: rgba(202,138,4,0.1); }
.bg-danger-soft  { background: rgba(220,38,38,0.1); }
.bg-info-soft    { background: rgba(2,132,199,0.1); }

/* =============================================
   MODULE CHIPS
   ============================================= */

.module-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.35rem 0.75rem;
  background: rgba(79,70,229,0.08);
  color: var(--primary);
  border-radius: 20px;
  font-size: 0.8rem;
  font-weight: 500;
  text-decoration: none;
  border: 1px solid rgba(79,70,229,0.2);
  transition: background 0.15s;
}

.module-chip:hover {
  background: rgba(79,70,229,0.16);
  color: var(--primary);
}

/* =============================================
   MODULE TOGGLE CARD (DEV PANEL)
   ============================================= */

.module-toggle-card {
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 0.875rem;
  background: var(--card-bg);
  transition: border-color 0.15s;
}

.module-toggle-card.enabled {
  border-color: rgba(79,70,229,0.4);
  background: rgba(79,70,229,0.03);
}

/* =============================================
   CUSTOMER AVATAR (SHOW PAGE)
   ============================================= */

.customer-avatar {
  width: 64px; height: 64px;
  border-radius: 50%;
  background: var(--primary);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.8rem;
  font-weight: 700;
}

/* =============================================
   AUTH
   ============================================= */

.auth-bg {
  background: radial-gradient(ellipse at center, #1e1b4b 0%, #0f172a 70%);
}

.auth-card {
  background: #1e293b;
  border: 1px solid #334155;
  color: #f1f5f9;
  border-radius: 16px;
}

.auth-card .form-control,
.auth-card .form-select {
  background: #0f172a;
  border-color: #334155;
  color: #f1f5f9;
}

.auth-card .form-control::placeholder { color: #475569; }
.auth-card .form-control:focus { border-color: #818cf8; box-shadow: 0 0 0 3px rgba(129,140,248,0.2); }
.auth-card .form-label { color: #94a3b8; font-size: 0.875rem; }
.auth-card a { color: #818cf8; }

/* Logo glow no fundo escuro (auth/landing) */
.auth-bg img[alt="ATTOS"],
.landing-hero img[alt="ATTOS GESTOR"] {
  filter: drop-shadow(0 0 16px rgba(26, 63, 255, 0.7));
}

/* =============================================
   LANDING
   ============================================= */

.landing-hero { min-height: 100vh; }

.feature-card {
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 12px;
  padding: 2rem 1.5rem;
  transition: background 0.2s;
}

.feature-card:hover { background: rgba(255,255,255,0.07); }

/* =============================================
   TABLES
   ============================================= */

.table { color: var(--text-primary); }
.table thead th {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-secondary);
  font-weight: 600;
  border-bottom: 1px solid var(--border-color);
  padding: 0.75rem 1rem;
}
.table td { padding: 0.75rem 1rem; border-color: var(--border-color); vertical-align: middle; }
.table-hover tbody tr:hover { background: rgba(79,70,229,0.03); }

/* =============================================
   BUTTONS
   ============================================= */

.btn-primary { background: var(--primary); border-color: var(--primary); }
.btn-primary:hover, .btn-primary:focus { background: var(--primary-hover); border-color: var(--primary-hover); }

/* =============================================
   MOBILE
   ============================================= */

@media (max-width: 991.98px) {
  .sidebar {
    transform: translateX(-100%);
  }

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

  .sidebar-overlay.open {
    display: block;
  }

  .main-content {
    margin-left: 0;
  }

  .stat-value { font-size: 1.1rem; }
}

@media (max-width: 575.98px) {
  .content-area { padding: 1rem; }
}

/* =============================================
   DASHBOARD BI & CENTRAL DE ALERTAS
   ============================================= */

.chart-container {
  position: relative;
  min-height: 260px;
}

.alerts-bell {
  position: relative;
}

.alerts-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: 8px;
  background: var(--danger);
  color: #fff;
  font-size: 0.65rem;
  font-weight: 700;
  line-height: 16px;
  text-align: center;
}

.alerts-dropdown {
  width: 340px;
  max-width: 90vw;
  max-height: 380px;
  overflow-y: auto;
  padding: 0.5rem 0;
  box-shadow: var(--shadow-lg);
  z-index: 1050;
}

.alert-item {
  border-left: 3px solid transparent;
}

.alert-item-danger  { border-left-color: var(--danger); }
.alert-item-warning { border-left-color: var(--warning); }
.alert-item-info    { border-left-color: var(--info); }
.alert-item-success { border-left-color: var(--success); }

.alert-item:hover { background: var(--content-bg); }

/* =============================================
   BUSCA GLOBAL
   ============================================= */

.global-search { position: relative; }

/* O input precisa ser irmão direto do .dropdown-menu para a API do Bootstrap
   localizá-lo (SelectorEngine.next) — por isso o ícone é posicionado por cima
   via absolute em vez de embrulhar os dois numa div. */
.global-search-icon {
  position: absolute;
  left: 0.65rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-secondary);
  font-size: 0.8rem;
  pointer-events: none;
}

.global-search-input {
  width: 220px;
  padding-left: 1.9rem;
  background: var(--content-bg);
}

.global-search-dropdown {
  width: 360px;
  max-width: 92vw;
  max-height: 420px;
  overflow-y: auto;
  padding: 0.5rem 0;
  box-shadow: var(--shadow-lg);
  z-index: 1050;
}

.global-search-item:hover { background: var(--content-bg); }

@media (max-width: 767.98px) {
  .global-search.global-search-mobile-open .global-search-icon,
  .global-search.global-search-mobile-open .global-search-input {
    display: block !important;
    position: absolute;
    top: calc(100% + 4px);
  }
  .global-search.global-search-mobile-open .global-search-icon {
    left: 0.25rem;
    z-index: 1041;
  }
  .global-search.global-search-mobile-open .global-search-input {
    left: -1rem;
    right: -1rem;
    width: auto;
    margin: 0 1rem;
    background: var(--card-bg);
    box-shadow: var(--shadow-md);
    z-index: 1040;
  }
}
