/* =====================================================
   AURABRAIN - HIERARCHICAL HOME AUTOMATION PLATFORM
   Modern SaaS-style theme
   Primary: Blue (#2563eb)
   Secondary: Yellow (#eab308)
   Accent: Pink (#ec4899)
   ===================================================== */

:root {
  --sidebar-width: 260px;
  --topbar-height: 64px;

  /* AuraBrain Brand Palette */
  --primary: #2563eb;
  --primary-light: #60a5fa;
  --primary-dark: #1d4ed8;
  --primary-bg: rgba(37, 99, 235, 0.08);
  --secondary: #eab308;
  --secondary-light: #fde047;
  --secondary-bg: rgba(234, 179, 8, 0.1);
  --accent: #ec4899;
  --accent-light: #f472b6;
  --accent-bg: rgba(236, 72, 153, 0.08);
  --success: #16a34a;
  --success-light: rgba(22, 163, 74, 0.1);
  --warning: #d97706;
  --warning-light: rgba(217, 119, 6, 0.1);
  --danger: #dc2626;
  --danger-light: rgba(220, 38, 38, 0.1);
  --info: #2563eb;

  /* Clean Surfaces */
  --bg-body: #f8fafc;
  --bg-sidebar: #0f172a;
  --bg-card: #ffffff;
  --bg-input: #ffffff;

  /* Text */
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #94a3b8;
  --text-sidebar: #94a3b8;
  --text-sidebar-active: #f8fafc;

  /* Borders */
  --border-color: #e2e8f0;
  --border-light: #f1f5f9;

  /* Shadows */
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.1);
  --shadow-xl: 0 16px 32px rgba(0,0,0,0.12);

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --transition-fast: 0.15s ease;
  --transition-base: 0.2s ease;
}

html { font-size: 15px; }
@media (min-width: 768px) { html { font-size: 16px; } }
* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg-body);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
  overflow-x: hidden;
}

::selection { background: var(--primary); color: white; }
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 3px; }

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

/* --- Sidebar (Dark) --- */
.sidebar {
  position: fixed; top: 0; left: 0;
  width: var(--sidebar-width); height: 100vh;
  background: var(--bg-sidebar);
  z-index: 1050;
  display: flex; flex-direction: column;
  box-shadow: 2px 0 8px rgba(0,0,0,0.15);
}

.sidebar-brand {
  display: flex; align-items: center; gap: 12px;
  padding: 18px 20px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
  min-height: var(--topbar-height);
}

.sidebar-brand .brand-icon {
  width: 36px; height: 36px;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  font-size: 1rem; flex-shrink: 0;
}

.sidebar-brand .brand-text {
  font-size: 1rem; font-weight: 700;
  color: var(--text-sidebar-active);
  letter-spacing: -0.3px;
}

.sidebar-brand .brand-text small {
  display: block; font-size: 0.6rem; font-weight: 400;
  color: rgba(255,255,255,0.4);
  text-transform: uppercase; letter-spacing: 0.5px;
}

.sidebar-nav { flex: 1; overflow-y: auto; padding: 12px 10px; }

.sidebar-nav .nav-section {
  font-size: 0.6rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: 1.2px;
  color: rgba(255,255,255,0.25);
  padding: 16px 12px 6px;
}

.sidebar-nav .nav-item { list-style: none; }

.sidebar-nav .nav-link {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px;
  color: var(--text-sidebar);
  text-decoration: none;
  border-radius: var(--radius-sm);
  transition: all var(--transition-fast);
  font-size: 0.85rem; font-weight: 500;
  margin-bottom: 1px;
  position: relative;
}

.sidebar-nav .nav-link:hover {
  background: rgba(255,255,255,0.06);
  color: var(--text-sidebar-active);
}

.sidebar-nav .nav-link.active {
  background: rgba(37, 99, 235, 0.15);
  color: var(--primary-light);
}

.sidebar-nav .nav-link.active::before {
  content: '';
  position: absolute; left: 0; top: 50%;
  transform: translateY(-50%);
  width: 3px; height: 18px;
  background: var(--primary-light);
  border-radius: 0 3px 3px 0;
}

.sidebar-nav .nav-link .nav-icon {
  width: 30px; height: 30px;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius-sm);
  font-size: 0.9rem; flex-shrink: 0;
  background: rgba(255,255,255,0.04);
}

.sidebar-nav .nav-link.active .nav-icon {
  background: rgba(37, 99, 235, 0.2);
  color: var(--primary-light);
}

.sidebar-footer {
  border-top: 1px solid rgba(255,255,255,0.06);
  padding: 14px 16px;
}

.sidebar-user { display: flex; align-items: center; gap: 10px; }

.sidebar-user .user-avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  display: flex; align-items: center; justify-content: center;
  color: white; font-weight: 600; font-size: 0.8rem;
  flex-shrink: 0;
}

.sidebar-user .user-name {
  color: var(--text-sidebar-active);
  font-size: 0.8rem; font-weight: 600;
}

.sidebar-user .user-role {
  color: rgba(255,255,255,0.4);
  font-size: 0.65rem;
}

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

/* Top Bar */
.topbar {
  height: var(--topbar-height);
  background: var(--bg-card);
  border-bottom: 1px solid var(--border-color);
  display: flex; align-items: center;
  padding: 0 28px;
  position: sticky; top: 0; z-index: 1040;
}

.topbar .topbar-title {
  font-size: 1rem; font-weight: 600;
  color: var(--text-primary);
}

.topbar .topbar-right { margin-left: auto; display: flex; align-items: center; gap: 10px; }

/* Page Content */
.page-content {
  flex: 1;
  padding: 24px 28px;
  max-width: 1400px;
  width: 100%;
  margin: 0 auto;
}

/* Page Header */
.page-header { margin-bottom: 24px; }
.page-header h1 {
  font-size: 1.5rem; font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.3px;
  margin-bottom: 2px;
}
.page-header .page-description { color: var(--text-secondary); font-size: 0.85rem; margin: 0; }

/* --- Stats Cards --- */
.stat-card {
  background: var(--bg-card);
  border-radius: var(--radius-md);
  padding: 18px 22px;
  border: 1px solid var(--border-color);
  transition: all var(--transition-base);
  position: relative; overflow: hidden;
}

.stat-card::before {
  content: '';
  position: absolute; top: 0; left: 0; right: 0;
  height: 3px;
}

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

.stat-card .stat-icon {
  width: 44px; height: 44px;
  border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.2rem; margin-bottom: 12px;
}

.stat-card .stat-label {
  font-size: 0.75rem; font-weight: 500;
  color: var(--text-secondary);
  text-transform: uppercase; letter-spacing: 0.5px;
  margin-bottom: 2px;
}

.stat-card .stat-value {
  font-size: 1.6rem; font-weight: 800;
  color: var(--text-primary);
  line-height: 1.2; letter-spacing: -1px;
}

.stat-card.tenants::before { background: linear-gradient(90deg, var(--primary), var(--primary-light)); }
.stat-card.tenants .stat-icon { background: var(--primary-bg); color: var(--primary); }
.stat-card.clients::before { background: linear-gradient(90deg, var(--accent), var(--accent-light)); }
.stat-card.clients .stat-icon { background: var(--accent-bg); color: var(--accent); }
.stat-card.homes::before { background: linear-gradient(90deg, var(--secondary), var(--secondary-light)); }
.stat-card.homes .stat-icon { background: var(--secondary-bg); color: var(--secondary); }
.stat-card.devices::before { background: linear-gradient(90deg, var(--success), #4ade80); }
.stat-card.devices .stat-icon { background: var(--success-light); color: var(--success); }
.stat-card.floors::before { background: linear-gradient(90deg, var(--primary), var(--primary-light)); }
.stat-card.floors .stat-icon { background: var(--primary-bg); color: var(--primary); }
.stat-card.rooms::before { background: linear-gradient(90deg, #7c3aed, #a78bfa); }
.stat-card.rooms .stat-icon { background: rgba(124,58,237,0.1); color: #7c3aed; }

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

.card-header {
  background: transparent;
  border-bottom: 1px solid var(--border-color);
  padding: 16px 20px;
  font-weight: 600; font-size: 0.9rem;
  display: flex; align-items: center; justify-content: space-between;
}

.card-body { padding: 20px; }
.card-footer { background: transparent; border-top: 1px solid var(--border-color); padding: 12px 20px; }

/* --- Modern Tables --- */
.table {
  width: 100%; margin-bottom: 0;
  border-collapse: collapse;
}

.table thead th {
  background: #f8fafc;
  padding: 10px 14px;
  font-size: 0.75rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.4px;
  color: var(--text-secondary);
  border-bottom: 2px solid var(--border-color);
}

.table tbody td {
  padding: 10px 14px;
  font-size: 0.85rem;
  border-bottom: 1px solid var(--border-light);
  vertical-align: middle;
}

.table tbody tr:hover { background: #fafbfc; }
.table tbody tr:last-child td { border-bottom: none; }

/* --- Buttons --- */
.btn {
  font-weight: 600;
  border-radius: var(--radius-sm);
  padding: 7px 16px;
  transition: all var(--transition-base);
  font-size: 0.85rem;
  display: inline-flex; align-items: center;
  gap: 6px;
  border: 1px solid transparent;
  cursor: pointer;
  line-height: 1.4;
  text-decoration: none;
}

.btn:focus { box-shadow: 0 0 0 3px rgba(37,99,235,0.15); outline: none; }
.btn-sm { padding: 4px 10px; font-size: 0.78rem; }

.btn-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: white;
}
.btn-primary:hover {
  background: var(--primary-dark);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(37,99,235,0.3);
}

.btn-success { background: var(--success); border-color: var(--success); color: white; }
.btn-success:hover { background: #15803d; transform: translateY(-1px); box-shadow: 0 4px 12px rgba(22,163,74,0.3); }

.btn-danger { background: var(--danger); border-color: var(--danger); color: white; }
.btn-danger:hover { background: #b91c1c; transform: translateY(-1px); box-shadow: 0 4px 12px rgba(220,38,38,0.3); }

.btn-outline-primary { background: transparent; border: 1px solid var(--primary); color: var(--primary); }
.btn-outline-primary:hover { background: var(--primary); color: white; }

.btn-outline-secondary { background: transparent; border: 1px solid var(--border-color); color: var(--text-secondary); }
.btn-outline-secondary:hover { background: #f8fafc; border-color: var(--text-secondary); color: var(--text-primary); }

.btn-outline-danger { background: transparent; border: 1px solid var(--danger); color: var(--danger); }
.btn-outline-danger:hover { background: var(--danger); color: white; }

.btn-ghost { background: transparent; border: none; color: var(--text-secondary); padding: 4px 8px; }
.btn-ghost:hover { background: #f1f5f9; color: var(--text-primary); border-radius: var(--radius-sm); }

/* --- Forms --- */
.form-group { margin-bottom: 18px; }

.form-label {
  display: block; font-size: 0.82rem;
  font-weight: 600; color: var(--text-primary);
  margin-bottom: 5px;
}

.form-control {
  display: block; width: 100%;
  padding: 9px 12px;
  font-size: 0.88rem; font-family: inherit;
  color: var(--text-primary);
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  transition: all var(--transition-fast);
}

.form-control:focus {
  border-color: var(--primary);
  background: white;
  box-shadow: 0 0 0 3px rgba(37,99,235,0.1);
  outline: none;
}

.form-control-sm { padding: 5px 8px; font-size: 0.8rem; }
.form-text { font-size: 0.75rem; color: var(--text-muted); margin-top: 3px; }

/* --- Alerts --- */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  display: flex; align-items: center; gap: 8px;
  margin-bottom: 16px;
  animation: slideDown 0.25s ease;
}

@keyframes slideDown { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: translateY(0); } }

.alert-success { background: var(--success-light); color: #166534; border-left: 4px solid var(--success); }
.alert-danger { background: var(--danger-light); color: #991b1b; border-left: 4px solid var(--danger); }
.alert-warning { background: var(--warning-light); color: #92400e; border-left: 4px solid var(--warning); }
.alert-info { background: var(--primary-bg); color: var(--primary); border-left: 4px solid var(--primary); }

/* --- Bootstrap Badge Overrides --- */
.badge { font-weight: 500; font-size: 0.75rem; padding: 3px 8px; border-radius: 20px; }
.bg-primary-light { background: var(--primary-bg) !important; color: var(--primary) !important; }
.bg-secondary-light { background: var(--secondary-bg) !important; color: var(--secondary) !important; }
.bg-info-light { background: rgba(6,182,212,0.1) !important; color: var(--info) !important; }
.bg-success-light { background: var(--success-light) !important; color: var(--success) !important; }
.bg-danger-light { background: var(--danger-light) !important; color: var(--danger) !important; }
.bg-warning-light { background: var(--warning-light) !important; color: var(--warning) !important; }

/* --- Device Badge --- */
.device-badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px; border-radius: 20px;
  font-size: 0.7rem; font-weight: 600;
}
.device-badge.online { background: var(--success-light); color: var(--success); }
.device-badge.offline { background: var(--danger-light); color: var(--danger); }

/* --- Modal --- */
.modal-overlay {
  display: none;
  position: fixed; top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(15,23,42,0.5);
  backdrop-filter: blur(4px);
  z-index: 9999;
  align-items: center;
  justify-content: center;
}

.modal-overlay.show {
  display: flex !important;
}

.modal-dialog {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xl);
  width: 90%; max-width: 500px;
  max-height: 85vh; overflow-y: auto;
  animation: modalIn 0.2s ease;
  pointer-events: auto;
  position: relative;
}

@keyframes modalIn { from { opacity: 0; transform: translateY(-20px) scale(0.96); } to { opacity: 1; transform: translateY(0) scale(1); } }

.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-color);
}

.modal-header h5 { font-size: 1.05rem; font-weight: 700; margin: 0; }

.modal-close {
  width: 30px; height: 30px;
  border: none; background: transparent;
  font-size: 1.2rem; cursor: pointer;
  border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  color: var(--text-muted);
}

.modal-close:hover { background: var(--bg-body); color: var(--text-primary); }

.modal-body { padding: 20px; }
.modal-footer {
  display: flex; align-items: center; justify-content: flex-end;
  gap: 8px; padding: 14px 20px;
  border-top: 1px solid var(--border-color);
}

/* Delete Icon */
.delete-icon {
  width: 56px; height: 56px;
  border-radius: 50%;
  background: var(--danger-light);
  color: var(--danger);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.5rem; margin: 0 auto 12px;
}

/* --- Login Page --- */
.login-page {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #e0e7ff, #dbeafe, #ede9fe);
  padding: 20px;
}

.login-container { width: 100%; max-width: 400px; }

.login-card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: 36px;
  box-shadow: var(--shadow-xl);
}

.login-card .login-logo { text-align: center; margin-bottom: 28px; }

.login-card .login-logo .logo-icon {
  width: 56px; height: 56px;
  background: linear-gradient(135deg, #1e1b4b, #312e81);
  border-radius: var(--radius-md);
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 1.4rem; margin-bottom: 12px;
}

.login-card .login-logo h2 { font-size: 1.2rem; font-weight: 800; color: #1e1b4b; }
.login-card .login-logo p { color: var(--text-muted); font-size: 0.8rem; }
.login-card .form-control { padding: 10px 14px; }

/* Utility */
.text-primary { color: var(--primary) !important; }
.text-success { color: var(--success) !important; }
.text-danger { color: var(--danger) !important; }
.text-warning { color: var(--warning) !important; }
.text-muted { color: var(--text-muted) !important; }
.fw-bold { font-weight: 700 !important; }
.fw-semibold { font-weight: 600 !important; }

/* Responsive */
@media (max-width: 991.98px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .main-content { margin-left: 0; }
  .page-content { padding: 16px; }
}
