.icon-blue { background: var(--primary-light); color: var(--primary); }
.icon-green { background: #d1fae5; color: var(--success); }
.icon-yellow { background: #fef3c7; color: var(--warning); }
.icon-red { background: #fee2e2; color: var(--danger); }
.icon-purple { background: #ede9fe; color: #7c3aed; }

.btn { display: inline-flex; align-items: center; gap: 8px; padding: 10px 18px; border-radius: var(--radius); font-size: 0.9rem; font-weight: 500; border: none; cursor: pointer; transition: all 0.2s; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-success { background: var(--success); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-warning { background: var(--warning); color: #fff; }
.btn-outline { background: transparent; border: 1px solid var(--gray-300); color: var(--gray-700); }
.btn-outline:hover { background: var(--gray-50); }
.btn-sm { padding: 6px 12px; font-size: 0.8rem; }

.form-group { margin-bottom: 16px; }
.form-label { display: block; font-size: 0.85rem; font-weight: 500; color: var(--gray-700); margin-bottom: 6px; }
.form-control { width: 100%; padding: 10px 14px; border: 1px solid var(--gray-300); border-radius: var(--radius); font-size: 0.9rem; background: #fff; }
.form-control:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-light); }
select.form-control { cursor: pointer; }
textarea.form-control { resize: vertical; min-height: 80px; }

.table-container { overflow-x: auto; background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); }
table { width: 100%; border-collapse: collapse; }
table th, table td { padding: 12px 16px; text-align: left; border-bottom: 1px solid var(--gray-200); font-size: 0.9rem; }
table th { background: var(--gray-50); font-weight: 600; color: var(--gray-700); font-size: 0.75rem; text-transform: uppercase; }
table tr:hover { background: var(--gray-50); }

.badge { display: inline-block; padding: 4px 10px; border-radius: 20px; font-size: 0.75rem; font-weight: 600; }
.badge-success { background: #d1fae5; color: #065f46; }
.badge-warning { background: #fef3c7; color: #92400e; }
.badge-danger { background: #fee2e2; color: #991b1b; }
.badge-info { background: #dbeafe; color: #1e40af; }
.badge-primary { background: var(--primary-light); color: var(--primary); }

.actions { display: flex; gap: 6px; }

.modal-overlay { position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,0.5); display: flex; align-items: center; justify-content: center; z-index: 2000; opacity: 0; visibility: hidden; }
.modal-overlay.active { opacity: 1; visibility: visible; }
.modal { background: #fff; border-radius: var(--radius); width: 100%; max-width: 500px; max-height: 90vh; overflow-y: auto; }
.modal-header { padding: 20px; border-bottom: 1px solid var(--gray-200); display: flex; align-items: center; justify-content: space-between; }
.modal-body { padding: 20px; }
.modal-footer { padding: 16px 20px; border-top: 1px solid var(--gray-200); display: flex; justify-content: flex-end; gap: 10px; }
.modal-close { width: 32px; height: 32px; border-radius: 50%; border: none; background: var(--gray-100); cursor: pointer; }

.grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }

.empty-state { text-align: center; padding: 60px 20px; color: var(--gray-500); }
.empty-state h3 { font-size: 1.1rem; color: var(--gray-700); margin: 16px 0 8px; }

.device-control { display: flex; align-items: center; justify-content: space-between; padding: 14px 0; border-bottom: 1px solid var(--gray-200); }
.device-status { width: 10px; height: 10px; border-radius: 50%; display: inline-block; margin-right: 8px; }
.device-status.on { background: var(--success); }
.device-status.off { background: var(--gray-400); }

.toggle-switch { position: relative; width: 50px; height: 26px; background: var(--gray-300); border-radius: 13px; cursor: pointer; }
.toggle-switch.active { background: var(--primary); }
.toggle-switch::after { content: ''; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; background: #fff; border-radius: 50%; transition: transform 0.3s; }
.toggle-switch.active::after { transform: translateX(24px); }

.login-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: var(--gray-100); padding: 20px; }
.login-card { background: #fff; border-radius: var(--radius); width: 100%; max-width: 420px; padding: 40px; }
.login-card .logo { text-align: center; margin-bottom: 32px; }
.login-card .logo h1 { font-size: 1.5rem; font-weight: 700; color: var(--primary); }

.chart-container { position: relative; width: 100%; height: 300px; }

/* ---------- Bootstrap 5 collision guards (our CSS loads after bootstrap.min.css) ---------- */
.modal-overlay .modal { display: flex; flex-direction: column; position: relative; z-index: 1; }
.dropdown-menu { display: block !important; }
.card { border: none; }
.toast-container { position: fixed; top: 20px; right: 20px; z-index: 3000; display: flex; flex-direction: column; gap: 10px; }
.toast-container .toast { display: flex; align-items: center; gap: 10px; background: #fff; border-radius: var(--radius); box-shadow: 0 4px 16px rgba(0,0,0,0.18); border: 1px solid var(--gray-200); border-left: 4px solid var(--gray-400); padding: 12px 16px; min-width: 260px; max-width: 380px; font-size: 0.9rem; color: var(--gray-700); opacity: 1; transition: opacity 0.3s; }
.toast-container .toast i { font-size: 1.1rem; }
.toast-container .toast.success { border-left-color: #059669; }
.toast-container .toast.success i { color: #059669; }
.toast-container .toast.error { border-left-color: #dc2626; }
.toast-container .toast.error i { color: #dc2626; }
.toast-container .toast.warning { border-left-color: #d97706; }
.toast-container .toast.warning i { color: #d97706; }
.toast-container .toast.info { border-left-color: #2563eb; }
.toast-container .toast.info i { color: #2563eb; }
@media (max-width: 991px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.open { transform: translateX(0); }
    .main-content { margin-left: 0; }
    .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
}
@media (max-width: 767px) {
    .navbar { padding: 0 16px; }
    .page-content { padding: 16px; }
    .kpi-grid { grid-template-columns: repeat(2, 1fr); }
    .user-info { display: none; }
}
