/* OkCondoTech - Modern Slate Design System */

:root {
  --bg-primary: #0b0f19;
  --bg-secondary: #111827;
  --bg-card: #1f2937;
  --bg-card-hover: #283548;
  --bg-elevated: #374151;
  --border-color: #374151;
  --border-subtle: #1f2937;
  
  --text-primary: #f9fafb;
  --text-secondary: #9ca3af;
  --text-muted: #6b7280;
  
  --brand-primary: #0066FF;
  --brand-primary-hover: #0052cc;
  --brand-primary-light: rgba(0, 102, 255, 0.15);
  --brand-secondary: #0F172A;
  
  --success: #10b981;
  --success-bg: rgba(16, 185, 129, 0.12);
  --warning: #f59e0b;
  --warning-bg: rgba(245, 158, 11, 0.12);
  --danger: #ef4444;
  --danger-bg: rgba(239, 68, 68, 0.12);
  --info: #06b6d4;
  --info-bg: rgba(6, 182, 212, 0.12);

  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --sidebar-width: 260px;
  --header-height: 64px;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-full: 9999px;
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.2);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.3), 0 2px 4px -1px rgba(0, 0, 0, 0.2);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.4), 0 4px 6px -2px rgba(0, 0, 0, 0.25);
  --transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

[data-theme="light"] {
  --bg-primary: #f3f4f6;
  --bg-secondary: #ffffff;
  --bg-card: #ffffff;
  --bg-card-hover: #f9fafb;
  --bg-elevated: #e5e7eb;
  --border-color: #e5e7eb;
  --border-subtle: #f3f4f6;
  --text-primary: #111827;
  --text-secondary: #4b5563;
  --text-muted: #9ca3af;
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
}

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

body {
  font-family: var(--font-sans);
  background-color: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Typography & Links */
a {
  color: var(--brand-primary);
  text-decoration: none;
  transition: var(--transition);
}
a:hover {
  text-decoration: none;
  filter: brightness(1.15);
}

h1, h2, h3, h4, h5, h6 {
  font-weight: 600;
  color: var(--text-primary);
}

/* Layout Structure */
.app-layout {
  display: flex;
  height: 100vh;
  overflow: hidden;
}
/* Sidebar */
.app-sidebar {
  width: var(--sidebar-width);
  background-color: var(--bg-secondary);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  z-index: 40;
  transition: transform 0.3s ease;
}

.sidebar-brand {
  padding: 18px 20px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  gap: 12px;
}

.sidebar-brand-logo {
  max-height: 36px;
  width: auto;
  object-fit: contain;
}

.brand-icon {
  width: 36px;
  height: 36px;
  background: linear-gradient(135deg, var(--brand-primary), #00d2ff);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-weight: 700;
  font-size: 18px;
  box-shadow: 0 0 15px rgba(0, 102, 255, 0.4);
}

.brand-text h2 {
  font-size: 16px;
  letter-spacing: -0.3px;
  margin: 0;
  line-height: 1.2;
}

.brand-badge {
  display: inline-block;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  background-color: var(--brand-primary-light);
  color: var(--brand-primary);
  padding: 2px 6px;
  border-radius: var(--radius-full);
  font-weight: 600;
}

.sidebar-menu {
  padding: 16px 12px;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
  overflow-y: auto;
}

.menu-category {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-muted);
  padding: 12px 10px 4px 10px;
  font-weight: 600;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  color: var(--text-secondary);
  border-radius: var(--radius-md);
  font-size: 14px;
  font-weight: 500;
  transition: var(--transition);
}

.nav-link:hover {
  background-color: var(--bg-card);
  color: var(--text-primary);
}

.nav-link.active {
  background-color: var(--brand-primary);
  color: #ffffff;
  box-shadow: 0 4px 12px rgba(0, 102, 255, 0.3);
}

.nav-link svg {
  width: 18px;
  height: 18px;
}

.sidebar-footer {
  padding: 16px;
  border-top: 1px solid var(--border-color);
  background-color: rgba(0, 0, 0, 0.1);
}

.tech-profile-card {
  display: flex;
  align-items: center;
  gap: 12px;
}

.tech-avatar {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-full);
  background-color: var(--bg-elevated);
  border: 2px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  color: var(--brand-primary);
}

.tech-info {
  flex: 1;
  min-width: 0;
}

.tech-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tech-company {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Main Content Area */
.app-main {
  flex: 1;
  margin-left: var(--sidebar-width);
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow-y: auto;
  overflow-x: hidden;
}

/* Top Header */
.app-header {
  height: var(--header-height);
  background-color: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 24px;
  position: sticky;
  top: 0;
  z-index: 30;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 16px;
}

.header-title h1 {
  font-size: 18px;
  margin: 0;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.theme-toggle-btn, .btn-icon {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-md);
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: var(--transition);
}

.theme-toggle-btn:hover, .btn-icon:hover {
  background-color: var(--bg-elevated);
  color: var(--text-primary);
}

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

/* KPI Summary Cards Grid */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.kpi-card {
  background-color: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 20px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  transition: var(--transition);
  box-shadow: var(--shadow-sm);
}

.kpi-card:hover {
  transform: translateY(-2px);
  border-color: var(--brand-primary);
  box-shadow: var(--shadow-md);
}

/* Clickable KPI Cards */
a.kpi-card {
  text-decoration: none !important;
  color: inherit !important;
  cursor: pointer;
  display: flex;
  user-select: none;
}

a.kpi-card:hover {
  text-decoration: none !important;
  color: inherit !important;
  transform: translateY(-3px);
  border-color: var(--brand-primary);
  box-shadow: var(--shadow-md), 0 0 12px rgba(34, 197, 94, 0.15);
}

a.kpi-card:focus-visible {
  outline: 2px solid var(--brand-primary);
  outline-offset: 2px;
}

a.kpi-card:active {
  transform: translateY(-1px);
}

.kpi-title {
  font-size: 13px;
  color: var(--text-secondary);
  font-weight: 500;
  margin-bottom: 6px;
}

.kpi-value {
  font-size: 26px;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.1;
}

.kpi-subtitle {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 6px;
}

.kpi-icon {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: var(--brand-primary-light);
  color: var(--brand-primary);
  flex-shrink: 0;
  transition: transform 0.2s ease;
}

a.kpi-card:hover .kpi-icon {
  transform: scale(1.08);
}

.kpi-icon.success { background-color: var(--success-bg); color: var(--success); }
.kpi-icon.warning { background-color: var(--warning-bg); color: var(--warning); }
.kpi-icon.danger { background-color: var(--danger-bg); color: var(--danger); }
.kpi-icon.info { background-color: var(--info-bg); color: var(--info); }

/* Buttons & Inputs */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 9px 16px;
  font-size: 14px;
  font-weight: 500;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  cursor: pointer;
  transition: var(--transition);
  white-space: nowrap;
}

.btn-primary {
  background-color: var(--brand-primary);
  color: #ffffff;
}
.btn-primary:hover {
  background-color: var(--brand-primary-hover);
  box-shadow: 0 4px 12px rgba(0, 102, 255, 0.35);
}

.btn-secondary {
  background-color: var(--bg-card);
  border-color: var(--border-color);
  color: var(--text-primary);
}
.btn-secondary:hover {
  background-color: var(--bg-card-hover);
  border-color: var(--text-muted);
}

.btn-success {
  background-color: var(--success);
  color: #ffffff;
}
.btn-danger {
  background-color: var(--danger);
  color: #ffffff;
}

.btn-outline {
  background-color: transparent;
  border-color: var(--border-color);
  color: var(--text-secondary);
}
.btn-outline:hover {
  background-color: var(--bg-card-hover);
  border-color: var(--text-muted);
  color: var(--text-primary);
}

/* Photo Upload UI */
.photo-box-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 12px;
}
.photo-preview-frame {
  width: 140px;
  height: 160px;
  border: 2px dashed var(--border-color);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: var(--bg-card);
  position: relative;
}
.photo-preview-frame img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.photo-toolbar-btns {
  display: flex;
  gap: 6px;
  margin-top: 4px;
}
.photo-tool-btn {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  background: var(--bg-card);
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.15s ease;
}
.photo-tool-btn:hover {
  background: var(--bg-card-hover);
  border-color: var(--text-muted);
  color: var(--text-primary);
}

.btn-sm {
  padding: 6px 12px;
  font-size: 12px;
}

button:disabled,
.btn:disabled,
.btn[disabled] {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: auto;
}

.form-control, .form-select {
  width: 100%;
  padding: 9px 14px;
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 14px;
  outline: none;
  transition: var(--transition);
}

.form-control:focus, .form-select:focus {
  border-color: var(--brand-primary);
  box-shadow: 0 0 0 3px var(--brand-primary-light);
}

/* Condos Cards Grid */
.condo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 20px;
}

.condo-card {
  background-color: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: var(--transition);
  box-shadow: var(--shadow-sm);
}

.condo-card:hover {
  border-color: var(--brand-primary);
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}

.condo-card-header {
  padding: 18px 20px;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}

.condo-name {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 4px;
}

.condo-address {
  font-size: 12px;
  color: var(--text-secondary);
}

.condo-card-body {
  padding: 18px 20px;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.condo-meta-row {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  color: var(--text-secondary);
}

.condo-meta-value {
  font-weight: 600;
  color: var(--text-primary);
}

.iot-status-bar {
  background-color: var(--bg-card);
  border-radius: var(--radius-md);
  padding: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 13px;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 8px;
  border-radius: var(--radius-full);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
}

.status-badge.online, .status-badge.active, .status-badge.success {
  background-color: var(--success-bg);
  color: var(--success);
}

.status-badge.offline, .status-badge.danger {
  background-color: var(--danger-bg);
  color: var(--danger);
}

.status-badge.warning, .status-badge.trial {
  background-color: var(--warning-bg);
  color: var(--warning);
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background-color: currentColor;
}

.status-dot.pulse {
  animation: pulse-dot 2s infinite;
}

@keyframes pulse-dot {
  0% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7); }
  70% { transform: scale(1); box-shadow: 0 0 0 6px rgba(16, 185, 129, 0); }
  100% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(16, 185, 129, 0); }
}

.condo-card-footer {
  padding: 14px 20px;
  background-color: var(--bg-card);
  border-top: 1px solid var(--border-subtle);
  display: flex;
  gap: 8px;
}

/* Tabs Navigation in Diagnostic Portal */
.portal-tabs-nav {
  display: flex;
  gap: 8px;
  border-bottom: 1px solid var(--border-color);
  margin-bottom: 24px;
  overflow-x: auto;
  padding-bottom: 2px;
}

.portal-tab-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 12px 18px;
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
  white-space: nowrap;
}

.portal-tab-btn:hover {
  color: var(--text-primary);
}

.portal-tab-btn.active {
  color: var(--brand-primary);
  border-bottom-color: var(--brand-primary);
  font-weight: 600;
}

.tab-pane {
  display: none;
}
.tab-pane.active {
  display: block;
  animation: fadeIn 0.25s ease-in-out;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

/* IoT Device Grid */
.device-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 18px;
}

.device-card {
  background-color: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  position: relative;
  transition: var(--transition);
}

.device-card:hover {
  border-color: var(--brand-primary);
  box-shadow: var(--shadow-md);
}

.device-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}

.device-name {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
}

.device-type {
  font-size: 12px;
  color: var(--text-secondary);
}

.device-telemetry-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  background-color: var(--bg-card);
  padding: 12px;
  border-radius: var(--radius-md);
  font-size: 12px;
}

.telemetry-item span:first-child {
  color: var(--text-muted);
  display: block;
  font-size: 11px;
}

.telemetry-item span:last-child {
  color: var(--text-primary);
  font-weight: 600;
  font-family: monospace;
}

.device-actions-row {
  display: flex;
  gap: 8px;
  margin-top: auto;
}

/* Tables */
.data-table-container {
  background-color: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 13px;
}

.data-table th {
  background-color: var(--bg-card);
  padding: 12px 16px;
  font-weight: 600;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border-color);
  text-transform: uppercase;
  font-size: 11px;
  letter-spacing: 0.5px;
}

.data-table td {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border-subtle);
  color: var(--text-primary);
}

.data-table tr:hover td {
  background-color: var(--bg-card-hover);
}

.data-table tr.violation-row td {
  background-color: rgba(239, 68, 68, 0.08);
}

/* White Label Live Preview */
.whitelabel-layout {
  display: grid;
  grid-template-columns: 1fr 1.1fr;
  gap: 24px;
}

@media (max-width: 1024px) {
  .whitelabel-layout {
    grid-template-columns: 1fr;
  }
}

.preview-container {
  background-color: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 24px;
  position: sticky;
  top: 88px;
}

.phone-mockup-frame {
  width: 320px;
  height: 580px;
  margin: 0 auto;
  background-color: #000000;
  border: 10px solid #1f2937;
  border-radius: 36px;
  overflow: hidden;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
  display: flex;
  flex-direction: column;
  position: relative;
}

.phone-notch {
  width: 120px;
  height: 18px;
  background-color: #1f2937;
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  border-bottom-left-radius: 12px;
  border-bottom-right-radius: 12px;
  z-index: 10;
}

.phone-screen {
  flex: 1;
  background-color: #0f172a;
  display: flex;
  flex-direction: column;
  padding-top: 24px;
  overflow: hidden;
}

.phone-app-header {
  padding: 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  background-color: var(--preview-primary, #0066FF);
  color: white;
  transition: background-color 0.2s;
}

.phone-logo-img {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  object-fit: cover;
  background-color: rgba(255, 255, 255, 0.2);
}

.phone-app-body {
  padding: 16px;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 12px;
  color: #e2e8f0;
  font-size: 12px;
}

.phone-card {
  background-color: #1e293b;
  border-radius: 10px;
  padding: 12px;
}

.phone-btn {
  background-color: var(--preview-primary, #0066FF);
  color: white;
  border: none;
  border-radius: 8px;
  padding: 10px;
  text-align: center;
  font-weight: 600;
  cursor: pointer;
  margin-top: auto;
  transition: background-color 0.2s;
}

/* Modals */
.modal-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  z-index: 100;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-backdrop.show {
  display: flex;
}

.modal-box {
  background-color: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  max-width: 500px;
  width: 100%;
  max-height: calc(100vh - 40px);
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  animation: modalPop 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes modalPop {
  from { transform: scale(0.95); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

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

.modal-body {
  padding: 24px;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}

.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--border-color);
  background-color: var(--bg-card);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  flex-shrink: 0;
}

/* Relay Simulation Animation */
.relay-anim-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 20px 0;
}

.relay-switch-box {
  width: 120px;
  height: 80px;
  background-color: var(--bg-card);
  border: 2px solid var(--border-color);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  transition: all 0.3s;
}

.relay-switch-box.active {
  border-color: var(--success);
  box-shadow: 0 0 20px rgba(16, 185, 129, 0.4);
}

.relay-coil {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background-color: var(--bg-elevated);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
}

.relay-switch-box.active .relay-coil {
  background-color: var(--success);
  color: white;
  animation: pulse-dot 1s infinite;
}

/* Toast notifications */
#toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.toast {
  background-color: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 14px 18px;
  color: var(--text-primary);
  font-size: 14px;
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 280px;
  animation: toastSlide 0.25s ease-out;
}

.toast.success { border-left: 4px solid var(--success); }
.toast.error { border-left: 4px solid var(--danger); }
.toast.info { border-left: 4px solid var(--info); }

@keyframes toastSlide {
  from { transform: translateX(50px); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* ==========================================================================
   R7: COMPREHENSIVE RESPONSIVE DESIGN ARCHITECTURE
   Breakpoints: Desktop (>1024px) | Tablet (768-1024px) | Mobile (<768px) | Small Mobile (≤375px)
   ========================================================================== */

/* --- Global Box-Sizing, Layout & Overflow Guards --- */
html, body {
  margin: 0;
  padding: 0;
  overflow: hidden;
  overflow-x: hidden;
  height: 100vh;
  width: 100%;
}

.app-layout {
  overflow: hidden;
  overflow-x: hidden;
  width: 100%;
  height: 100vh;
  position: relative;
}

.page-content {
  padding-bottom: 60px !important; /* Space for persistent sync footer */
  width: 100%;
  max-width: 1400px;
  box-sizing: border-box;
}


/* --- Universal Table Horizontal Scroll Wrapper --- */
.table-container,
.data-table-container,
.table-responsive {
  overflow-x: auto !important;
  -webkit-overflow-scrolling: touch !important;
  width: 100% !important;
  max-width: 100% !important;
  position: relative;
}

.table-container,
.data-table-container,
.table-responsive,
.perm-matrix-container {
  overflow-x: auto !important;
  -webkit-overflow-scrolling: touch !important;
  width: 100% !important;
  max-width: 100% !important;
  position: relative;
}

.data-table,
.perm-matrix-table {
  min-width: 640px;
  width: 100%;
}

/* --- Desktop (>1024px) Breakpoint --- */
@media (min-width: 1025px) {
  .app-sidebar {
    width: var(--sidebar-width, 260px) !important;
    transform: translateX(0) !important;
    position: fixed;
    top: 0; bottom: 0; left: 0;
    z-index: 40;
  }

  .app-main {
    margin-left: var(--sidebar-width, 260px) !important;
  }

  #mobile-menu-toggle,
  .mobile-menu-toggle {
    display: none !important;
  }

  .sidebar-backdrop {
    display: none !important;
  }

  .dashboard-5-kpis {
    grid-template-columns: repeat(5, 1fr) !important;
  }

  .dashboard-grid-charts {
    grid-template-columns: 2fr 1fr !important;
  }

  .dashboard-grid-bottom {
    grid-template-columns: 1.2fr 1fr !important;
  }
}

/* Intermediate Desktop (<=1366px) */
@media (max-width: 1366px) and (min-width: 1025px) {
  .dashboard-5-kpis .kpi-card {
    padding: 16px 12px !important;
  }
  .dashboard-5-kpis .kpi-value {
    font-size: 22px !important;
  }
  .dashboard-5-kpis .kpi-icon {
    width: 38px !important;
    height: 38px !important;
  }
  .dashboard-5-kpis .kpi-breakdown {
    font-size: 11px !important;
    word-break: break-word;
  }
}

/* --- Tablet (768px - 1024px) Breakpoint --- */
@media (min-width: 768px) and (max-width: 1024px) {
  :root {
    --sidebar-width: 64px;
  }

  /* Collapsed icon-only sidebar */
  .app-sidebar {
    width: 64px !important;
    overflow: visible;
    transform: translateX(0) !important;
    position: fixed;
    top: 0; bottom: 0; left: 0;
    z-index: 40;
    transition: width 0.25s ease, box-shadow 0.25s ease;
  }

  .app-main {
    margin-left: 64px !important;
  }

  /* Hide textual elements in collapsed mode */
  .app-sidebar:not(:hover):not(.expanded) .brand-text,
  .app-sidebar:not(:hover):not(.expanded) .menu-category,
  .app-sidebar:not(:hover):not(.expanded) .accordion-header-title span,
  .app-sidebar:not(:hover):not(.expanded) .accordion-chevron,
  .app-sidebar:not(:hover):not(.expanded) .nav-link span,
  .app-sidebar:not(:hover):not(.expanded) .nav-badge,
  .app-sidebar:not(:hover):not(.expanded) .tech-info,
  .app-sidebar:not(:hover):not(.expanded) .tech-profile-card a[href*="logout"] {
    display: none !important;
  }

  .app-sidebar:not(:hover):not(.expanded) .sidebar-brand {
    padding: 14px 4px !important;
    justify-content: center !important;
  }

  .app-sidebar:not(:hover):not(.expanded) .sidebar-brand-link {
    justify-content: center !important;
    gap: 0 !important;
  }

  .app-sidebar:not(:hover):not(.expanded) .nav-link {
    justify-content: center !important;
    padding: 12px 0 !important;
    gap: 0 !important;
  }

  .app-sidebar:not(:hover):not(.expanded) .sidebar-accordion-header {
    justify-content: center !important;
    padding: 12px 0 !important;
  }

  .app-sidebar:not(:hover):not(.expanded) .accordion-header-title {
    justify-content: center !important;
    gap: 0 !important;
  }

  .app-sidebar:not(:hover):not(.expanded) .sidebar-accordion-body {
    padding-left: 0 !important;
  }

  .app-sidebar:not(:hover):not(.expanded) .tech-profile-card {
    justify-content: center !important;
    gap: 0 !important;
  }

  .app-sidebar:not(:hover):not(.expanded) .sidebar-footer {
    padding: 10px 4px !important;
    justify-content: center !important;
  }

  /* Expanded sidebar on hover or toggle click */
  .app-sidebar:hover,
  .app-sidebar.expanded {
    width: 260px !important;
    box-shadow: 6px 0 28px rgba(0, 0, 0, 0.7) !important;
    z-index: 100 !important;
  }

  .app-sidebar:hover .brand-text,
  .app-sidebar.expanded .brand-text {
    display: flex !important;
  }

  .app-sidebar:hover .menu-category,
  .app-sidebar.expanded .menu-category {
    display: block !important;
  }

  .app-sidebar:hover .accordion-header-title span,
  .app-sidebar.expanded .accordion-header-title span,
  .app-sidebar:hover .accordion-chevron,
  .app-sidebar.expanded .accordion-chevron,
  .app-sidebar:hover .nav-link span,
  .app-sidebar.expanded .nav-link span,
  .app-sidebar:hover .nav-badge,
  .app-sidebar.expanded .nav-badge {
    display: inline-block !important;
  }

  .app-sidebar:hover .tech-info,
  .app-sidebar.expanded .tech-info {
    display: flex !important;
    flex-direction: column !important;
  }

  .app-sidebar:hover .tech-profile-card a[href*="logout"],
  .app-sidebar.expanded .tech-profile-card a[href*="logout"] {
    display: flex !important;
  }

  .app-sidebar:hover .nav-link,
  .app-sidebar.expanded .nav-link {
    justify-content: flex-start !important;
    padding: 10px 14px !important;
    gap: 12px !important;
  }

  .app-sidebar:hover .sidebar-accordion-header,
  .app-sidebar.expanded .sidebar-accordion-header {
    justify-content: space-between !important;
    padding: 10px 14px !important;
  }

  .app-sidebar:hover .sidebar-brand-link,
  .app-sidebar.expanded .sidebar-brand-link {
    justify-content: flex-start !important;
    gap: 10px !important;
  }

  /* Hamburger menu visible on tablet */
  #mobile-menu-toggle,
  .mobile-menu-toggle {
    display: flex !important;
    align-items: center;
    justify-content: center;
  }

  /* KPI cards: 2 columns on tablet */
  .kpi-grid,
  .dashboard-5-kpis {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 14px !important;
  }

  /* 5th card spans both columns on 2-column tablet layout */
  .dashboard-5-kpis .kpi-card:last-child {
    grid-column: 1 / -1;
  }

  /* Charts: 1 column on tablet */
  .dashboard-charts-grid,
  .dashboard-grid-charts,
  .dashboard-bottom-grid,
  .dashboard-grid-bottom {
    grid-template-columns: 1fr !important;
    gap: 16px !important;
  }

  .condo-grid {
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  }
  .device-grid {
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  }
}

/* --- Mobile (<768px) Breakpoint --- */
@media (max-width: 767.98px) {
  /* Sidebar as slide-in overlay drawer */
  .app-sidebar {
    width: 280px !important;
    max-width: 85vw !important;
    position: fixed !important;
    top: 0 !important;
    bottom: 0 !important;
    left: 0 !important;
    z-index: 1000 !important;
    transform: translateX(-100%) !important;
    transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1) !important;
    box-shadow: none !important;
  }

  .app-sidebar.open {
    transform: translateX(0) !important;
    box-shadow: 6px 0 30px rgba(0, 0, 0, 0.7) !important;
  }

  /* Backdrop overlay */
  .sidebar-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.65);
    backdrop-filter: blur(4px);
    z-index: 999;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
  }

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

  body.sidebar-open {
    overflow: hidden !important;
  }

  .app-main {
    margin-left: 0 !important;
    width: 100% !important;
    min-width: 0 !important;
  }

  /* Hamburger toggle */
  #mobile-menu-toggle,
  .mobile-menu-toggle {
    display: flex !important;
    min-width: 44px !important;
    min-height: 44px !important;
    width: 44px !important;
    height: 44px !important;
    align-items: center;
    justify-content: center;
  }

  /* Header mobile adaptation - 2-row structure */
  .app-header {
    padding: 8px 12px !important;
    min-height: auto !important;
    height: auto !important;
    gap: 6px !important;
    width: 100% !important;
    max-width: 100vw !important;
    box-sizing: border-box !important;
    flex-wrap: wrap !important;
  }

  .header-left {
    gap: 8px !important;
    flex: 1 1 auto !important;
    min-width: 0 !important;
    order: 1 !important;
  }

  .header-title h1 {
    font-size: 14px !important;
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    max-width: none !important;
  }

  .header-subtitle {
    display: none !important;
  }

  .header-right {
    gap: 6px !important;
    margin-left: auto !important;
    order: 2 !important;
    flex-shrink: 0 !important;
  }

  /* Condo selector drops to full-width second row */
  .condo-selector-wrapper {
    margin-left: 0 !important;
    max-width: none !important;
    width: 100% !important;
    order: 10 !important;
    flex-basis: 100% !important;
    padding-top: 2px !important;
  }

  .condo-selector-wrapper select {
    width: 100% !important;
    font-size: 13px !important;
    padding: 8px 12px !important;
  }

  .header-right .btn span,
  .header-left .btn span,
  .quick-visit-btn span {
    display: none !important;
  }

  .header-right .btn,
  .header-left .btn,
  .quick-visit-btn,
  .theme-toggle-btn {
    min-width: 44px !important;
    min-height: 44px !important;
    width: 44px !important;
    height: 44px !important;
    padding: 0 !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    font-size: 12px !important;
    border-radius: 8px !important;
  }

  .header-right .btn i,
  .header-left .btn i,
  .quick-visit-btn i,
  .theme-toggle-btn i {
    width: 18px !important;
    height: 18px !important;
  }

  .chart-toggle-pill {
    min-height: 44px;
    min-width: 44px;
    display: inline-flex;
    align-items: center;
    padding: 4px 8px;
    border-radius: var(--radius-sm);
  }

  .donut-tab-btn {
    min-height: 44px !important;
  }

  .page-content {
    padding: 14px !important;
  }

  /* Dashboard: 1 col for KPIs, Charts, Bottom Grids */
  .kpi-grid,
  .dashboard-5-kpis {
    grid-template-columns: 1fr !important;
    gap: 12px !important;
  }
  .dashboard-5-kpis .kpi-card:last-child {
    grid-column: auto !important;
  }
  .kpi-card {
    padding: 14px !important;
  }
  .kpi-value {
    font-size: 20px !important;
  }

  .dashboard-charts-grid,
  .dashboard-grid-charts,
  .dashboard-bottom-grid,
  .dashboard-grid-bottom {
    grid-template-columns: 1fr !important;
    gap: 16px !important;
  }

  /* Chart & Donut fixed container heights to prevent Chart.js infinite canvas expansion */
  .chart-container {
    height: 220px !important;
  }

  .donut-view,
  #donut-view-capacity,
  #donut-view-areas {
    height: 220px !important;
    max-height: 240px !important;
    position: relative !important;
  }

  /* Live Event Drawer: Full-width overlay on mobile */
  .live-event-drawer {
    width: 100vw !important;
    max-width: 100vw !important;
    left: 0 !important;
    right: 0 !important;
    border-left: none !important;
    z-index: 1050 !important;
  }

  /* Filter popovers: Full-screen modal overlay on mobile with close button.
     IMPORTANT: Do NOT use display:flex !important here — it overrides inline
     display:none and makes the panel impossible to close. The panel's visibility
     is controlled by inline style (display:none/block) set by JS toggle functions. */
  .filter-popover-card[style*="display:block"],
  .filter-popover-card[style*="display: block"] {
    position: fixed !important;
    inset: 0 !important;
    z-index: 1100 !important;
    margin: 0 !important;
    border-radius: 0 !important;
    padding: 16px 16px 20px 16px !important;
    background: var(--bg-secondary) !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch !important;
    display: flex !important;
    flex-direction: column !important;
    box-shadow: none !important;
  }

  /* Filter popover close button: prominent and always touchable on mobile */
  .filter-close-btn {
    min-width: 44px !important;
    min-height: 44px !important;
    width: 44px !important;
    height: 44px !important;
    font-size: 22px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    background: var(--bg-elevated) !important;
    border: 1px solid var(--border-color) !important;
    border-radius: var(--radius-sm) !important;
    color: var(--text-primary) !important;
    cursor: pointer !important;
    flex-shrink: 0 !important;
  }

  /* Filter popover footer: sticky at bottom so buttons are always reachable */
  .filter-popover-footer {
    position: sticky !important;
    bottom: 0 !important;
    background: var(--bg-secondary) !important;
    padding: 12px 0 !important;
    margin-top: auto !important;
    flex-direction: column !important;
    gap: 8px !important;
  }
  .filter-popover-footer .btn {
    width: 100% !important;
    justify-content: center !important;
    text-align: center !important;
  }

  .filter-grid-2col {
    grid-template-columns: 1fr !important;
  }

  /* Breadcrumb: don't let long paths overflow */
  .breadcrumb-bar {
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch !important;
    white-space: nowrap !important;
    font-size: 12px !important;
  }

  /* Tables: horizontal scroll with minimum width so columns don't get cramped */
  .table-container {
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch !important;
  }
  .data-table {
    min-width: 640px !important;
  }

  /* Action toolbars: wrap gracefully */
  .action-bar,
  [style*="justify-content:space-between"][style*="flex-wrap:wrap"] {
    flex-wrap: wrap !important;
    gap: 10px !important;
  }

  /* Tab navigation: horizontal scroll on mobile */
  .tab-nav-bar,
  .settings-tabs-nav,
  .portal-tabs-nav,
  .catalog-tabs {
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch !important;
    flex-wrap: nowrap !important;
    scrollbar-width: none !important;
    -ms-overflow-style: none !important;
  }
  .tab-nav-bar::-webkit-scrollbar,
  .settings-tabs-nav::-webkit-scrollbar,
  .portal-tabs-nav::-webkit-scrollbar,
  .catalog-tabs::-webkit-scrollbar {
    display: none !important;
  }
  .modal-tab-btn span,
  .settings-tab-btn span,
  .portal-tab-btn span,
  .catalog-tab-btn span {
    white-space: nowrap !important;
  }

  /* Modals: Full-width on mobile */
  .modal-backdrop {
    padding: 8px !important;
    align-items: flex-start !important;
  }

  .modal-card,
  .modal-box {
    width: 95vw !important;
    max-width: 100% !important;
    margin: 10px auto !important;
    padding: 0 !important;
    max-height: 92vh !important;
    overflow-y: auto !important;
    box-sizing: border-box !important;
    border-radius: var(--radius-md) !important;
    display: flex !important;
    flex-direction: column !important;
  }

  /* Modal inner content: allow scroll while keeping header/footer visible */
  .modal-card .tab-pane,
  .modal-card form,
  .modal-box form {
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch !important;
    padding: 16px !important;
  }

  .modal-header {
    position: sticky !important;
    top: 0 !important;
    z-index: 10 !important;
    background: var(--bg-card) !important;
    padding: 14px 16px !important;
    flex-shrink: 0 !important;
    border-bottom: 1px solid var(--border-color) !important;
  }

  .modal-footer,
  .modal-card > form > div:last-child,
  .modal-card [style*="border-top"][style*="justify-content:flex-end"] {
    position: sticky !important;
    bottom: 0 !important;
    z-index: 10 !important;
    background: var(--bg-secondary) !important;
    flex-shrink: 0 !important;
  }

  .modal-footer {
    padding: 12px 16px !important;
    border-top: 1px solid var(--border-color) !important;
    flex-direction: column-reverse !important;
    gap: 8px !important;
  }
  .modal-footer .btn {
    width: 100% !important;
    justify-content: center !important;
  }

  /* Universal form grid collapse on mobile */
  .modal-card [style*="grid-template-columns"],
  .modal-box [style*="grid-template-columns"],
  .modal-body [style*="grid-template-columns"],
  .modal-dialog [style*="grid-template-columns"],
  form [style*="grid-template-columns"],
  .form-grid [style*="grid-template-columns"],
  .modal-grid-2,
  .modal-grid-3 {
    grid-template-columns: 1fr !important;
    gap: 12px !important;
  }

  /* Touch targets minimum 44px */
  .btn,
  .btn-sm,
  .form-control,
  .form-select,
  .input-material {
    min-height: 44px !important;
    font-size: 16px !important; /* Prevents auto-zoom on iOS Safari */
    box-sizing: border-box !important;
  }

  .btn-icon,
  .theme-toggle-btn {
    min-width: 44px !important;
    min-height: 44px !important;
  }

  /* Action bars & emergency bars */
  .emergency-bar,
  .page-actions,
  .action-bar {
    flex-wrap: wrap !important;
    gap: 8px !important;
  }

  .emergency-bar > div,
  .action-bar > div {
    display: flex;
    flex-wrap: wrap !important;
    gap: 8px !important;
    width: 100%;
  }

  /* Emergency action buttons: full-width on mobile to prevent overlap */
  .emergency-bar .btn,
  .emergency-bar [style*="display:flex"][style*="gap"] .btn {
    flex: 1 1 auto !important;
    justify-content: center !important;
  }

  /* Vehicle category selector: 2x2 grid on mobile */
  .vehicle-category-selector {
    flex-wrap: wrap !important;
  }
  .vehicle-category-selector .category-icon-btn {
    flex: 1 1 calc(50% - 4px) !important;
    min-width: calc(50% - 4px) !important;
  }

  /* Dual code row: stack vertically */
  .dual-code-row {
    flex-direction: column !important;
  }
  .dual-code-col {
    width: 100% !important;
  }

  /* Condo & Device Cards */
  .condo-grid,
  .device-grid {
    grid-template-columns: 1fr !important;
    gap: 14px !important;
  }
  .condo-card-header {
    flex-direction: column !important;
    gap: 8px !important;
  }
  .condo-card-footer {
    flex-direction: column !important;
    gap: 8px !important;
  }
  .condo-card-footer .condo-main-action {
    width: 100% !important;
    justify-content: center !important;
  }
  .condo-card-footer .condo-actions-group {
    display: flex !important;
    gap: 8px !important;
    width: 100% !important;
  }
  .condo-card-footer .condo-actions-group .btn {
    flex: 1 !important;
    justify-content: center !important;
  }

  /* Persistent Sync Footer Mobile Adaptation */
  .persistent-sync-footer {
    left: 0 !important;
    padding: 0 10px !important;
    font-size: 11px !important;
  }

  .sync-footer-left {
    display: none !important;
  }

  .sync-footer-right {
    width: 100% !important;
    justify-content: space-between !important;
  }

  /* Remote Door FAB */
  .fab-remote-door-container {
    bottom: 48px !important;
    right: 14px !important;
  }

  .fab-door-menu {
    width: calc(100vw - 32px) !important;
    max-width: 320px !important;
    right: 0 !important;
  }

  /* White Label Preview Mockup */
  .whitelabel-layout {
    grid-template-columns: 1fr !important;
  }

  .preview-container {
    padding: 12px !important;
  }

  .phone-mockup-frame {
    width: 100% !important;
    max-width: 280px !important;
    height: auto !important;
    aspect-ratio: 9/16 !important;
  }

  /* Portal tabs */
  .portal-tabs-nav {
    gap: 4px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  .portal-tab-btn {
    padding: 10px 12px;
    font-size: 12px;
    white-space: nowrap;
  }

  /* Toast */
  #toast-container {
    left: 14px;
    right: 14px;
    bottom: 48px;
  }
  .toast {
    min-width: auto;
    width: 100%;
  }
}

/* --- Small Phones (≤375px & 320px Viewports) --- */
@media (max-width: 375px) {
  .page-content {
    padding: 8px !important;
  }

  .app-header {
    padding: 0 6px !important;
  }

  .header-title h1 {
    max-width: 105px !important;
    font-size: 13px !important;
  }

  .card {
    padding: 12px !important;
  }

  .kpi-card {
    padding: 10px !important;
  }

  .kpi-value {
    font-size: 17px !important;
  }

  .form-select {
    min-width: 0 !important;
    width: 100% !important;
  }
}


/* --- Utility classes for responsive grids --- */
.modal-grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.modal-grid-3 {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 12px;
}

/* Unit preview */
.unit-preview-box {
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 14px;
  margin-top: 14px;
  max-height: 160px;
  overflow-y: auto;
}
.unit-preview-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.unit-preview-count {
  font-size: 13px;
  font-weight: 700;
  color: var(--brand-primary);
}
.unit-preview-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.unit-preview-tag {
  background-color: var(--bg-elevated);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 3px 8px;
  font-size: 11px;
  font-family: monospace;
  color: var(--text-primary);
}
.unit-preview-tag.block-header {
  background-color: var(--brand-primary-light);
  color: var(--brand-primary);
  font-weight: 600;
  font-family: var(--font-sans);
  width: 100%;
}

/* Condo type selector - always 2 columns */
.condo-type-selector {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 16px;
}
.condo-type-option {
  background-color: var(--bg-card);
  border: 2px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 16px 12px;
  text-align: center;
  cursor: pointer;
  transition: var(--transition);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  min-height: 80px;
  justify-content: center;
}
.condo-type-option:hover {
  border-color: var(--text-muted);
  background-color: var(--bg-card-hover);
}
.condo-type-option.selected {
  border-color: var(--brand-primary);
  background-color: var(--brand-primary-light);
  box-shadow: 0 0 0 1px var(--brand-primary);
}
.condo-type-option svg,
.condo-type-option i {
  width: 28px;
  height: 28px;
  color: var(--text-muted);
  flex-shrink: 0;
}
.condo-type-option.selected svg,
.condo-type-option.selected i {
  color: var(--brand-primary);
}
.condo-type-option .type-label {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1.2;
}
.condo-type-option .type-desc {
  font-size: 11px;
  color: var(--text-muted);
  line-height: 1.3;
}

/* ==========================================================================
   Milestone 3: Device Catalog, Category Badges & Responsive Layout
   ========================================================================== */

/* Category Badges */
.badge-category {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: var(--radius-full);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  white-space: nowrap;
}

.badge-facial {
  background-color: rgba(59, 130, 246, 0.15);
  color: #3b82f6;
  border: 1px solid rgba(59, 130, 246, 0.3);
}

.badge-biometric {
  background-color: rgba(20, 184, 166, 0.15);
  color: #14b8a6;
  border: 1px solid rgba(20, 184, 166, 0.3);
}

.badge-card_access {
  background-color: rgba(16, 185, 129, 0.15);
  color: #10b981;
  border: 1px solid rgba(16, 185, 129, 0.3);
}

.badge-gateway {
  background-color: rgba(245, 158, 11, 0.15);
  color: #f59e0b;
  border: 1px solid rgba(245, 158, 11, 0.3);
}

.badge-usb {
  background-color: rgba(156, 163, 175, 0.15);
  color: #9ca3af;
  border: 1px dashed rgba(156, 163, 175, 0.4);
}

/* Capability Badges */
.cap-badges-row {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 6px;
}

.cap-badge {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 10px;
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  color: var(--text-secondary);
  border: 1px solid var(--border-color);
  font-weight: 500;
}

/* Catalog Tabs in Add Device Modal */
.catalog-tabs {
  display: flex;
  gap: 6px;
  border-bottom: 1px solid var(--border-color);
  margin-bottom: 16px;
  overflow-x: auto;
  padding-bottom: 2px;
}

.catalog-tab-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
  white-space: nowrap;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
}

.catalog-tab-btn:hover {
  color: var(--text-primary);
  background: var(--bg-card-hover);
}

.catalog-tab-btn.active {
  color: var(--brand-primary);
  border-bottom-color: var(--brand-primary);
  font-weight: 600;
  background: var(--brand-primary-light);
}

/* Device Catalog Grid & Cards */
.device-catalog-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 12px;
  max-height: 420px;
  overflow-y: auto;
  padding: 4px;
}

.catalog-card {
  position: relative;
  background-color: var(--bg-card);
  border: 1.5px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 12px;
  cursor: pointer;
  transition: var(--transition);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 8px;
}

.catalog-card:hover {
  border-color: var(--brand-primary);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.catalog-card.selected {
  border-color: var(--brand-primary);
  background-color: var(--brand-primary-light);
  box-shadow: 0 0 0 1px var(--brand-primary);
}

.catalog-card-disabled {
  opacity: 0.55;
  border-style: dashed;
  cursor: not-allowed;
  filter: grayscale(0.4);
}

.catalog-card-disabled:hover {
  transform: none;
  border-color: var(--border-color);
  box-shadow: none;
}

/* Device Information Notice Banners */
.device-info-banner {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px 16px;
  border-radius: var(--radius-md);
  font-size: 13px;
  line-height: 1.5;
}

.banner-mip {
  background: rgba(245, 158, 11, 0.12);
  border: 1px solid rgba(245, 158, 11, 0.35);
  color: #fbbf24;
}

/* Responsive Overrides for Catalog & Modals */
@media (max-width: 768px) {
  .device-catalog-grid {
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    max-height: 320px;
  }
  .catalog-tabs {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 6px;
  }
  .catalog-card {
    padding: 10px;
  }
}

@media (max-width: 480px) {
  .header-left .btn span {
    display: none !important;
  }
  .device-catalog-grid {
    grid-template-columns: 1fr;
    max-height: 280px;
  }
  .catalog-card {
    padding: 10px;
  }
}

/* ==========================================================================
   Access Control Core Modules & Parity Components (Milestone 2)
   ========================================================================== */

/* Universal Modal System */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(4px);
  z-index: 9999;
  display: none;
  align-items: center;
  justify-content: center;
  overflow-y: auto;
  padding: 20px;
}

.modal-backdrop.show,
.modal-backdrop.active {
  display: flex;
}

.modal-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.6);
  max-height: 90vh;
  overflow-y: auto;
}

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

.modal-header h3 {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  color: var(--text-primary);
}

/* Alert Warning Banners */
.alert-warning-banner {
  background: rgba(245, 158, 11, 0.1);
  border: 1px solid var(--warning);
  color: #fbbf24;
  border-radius: var(--radius-md);
  padding: 14px 18px;
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  gap: 12px;
}

/* Sub-Tab Navigation for Modals */
.holiday-tab-btn {
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 600;
  padding: 12px 16px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.holiday-tab-btn:hover {
  color: var(--text-primary);
}

.holiday-tab-btn.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

/* Day-of-week segmented picker */
.day-pill {
  min-width: 44px;
  font-weight: 600;
  border-radius: var(--radius-sm);
}

/* Pulse animation for emergency buttons */
.pulse-btn {
  position: relative;
}

@keyframes buttonPulse {
  0% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.7); }
  70% { box-shadow: 0 0 0 8px rgba(239, 68, 68, 0); }
  100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0); }
}

.pulse-btn:hover {
  animation: buttonPulse 1.5s infinite;
}

/* Slot Rows */
.slot-row input[type="time"] {
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
}

/* ==========================================================================
   Milestone 3: Users, Visitors, Credentials, Vehicles, Operators & Reports
   ========================================================================== */

/* 5-Tab User & Entity Modal System */
.tab-nav-bar {
  display: flex;
  align-items: center;
  gap: 4px;
  border-bottom: 1px solid var(--border-color);
  background: var(--bg-secondary);
  padding: 0 16px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.modal-tab-btn {
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 600;
  padding: 12px 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  transition: all 0.2s ease;
}

.modal-tab-btn:hover {
  color: var(--text-primary);
}

.modal-tab-btn.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

.tab-pane {
  display: none;
  padding: 20px;
}

.tab-pane.active {
  display: block;
}

/* Photo & Webcam Capture Toolbar */
.photo-box-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.photo-preview-frame {
  width: 140px;
  height: 160px;
  border: 2px dashed var(--border-color);
  border-radius: var(--radius-md);
  background: var(--bg-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  position: relative;
  margin-bottom: 12px;
}

.photo-preview-frame img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.photo-toolbar-btns {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: center;
  margin-bottom: 12px;
}

.photo-tool-btn {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.15s ease;
}

.photo-tool-btn:hover {
  background: var(--border-color);
  color: var(--text-primary);
}

.facial-sync-banner {
  background: rgba(34, 197, 94, 0.1);
  border: 1px solid rgba(34, 197, 94, 0.3);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  font-size: 11px;
  color: var(--primary);
  margin-top: 8px;
  display: flex;
  align-items: center;
  gap: 6px;
  text-align: left;
}

/* Material Underline Inputs */
.input-material {
  width: 100%;
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--border-color);
  padding: 8px 4px;
  color: var(--text-primary);
  font-size: 14px;
  outline: none;
  transition: border-color 0.2s;
}

.input-material:focus {
  border-bottom-color: var(--primary);
}

.form-group-material {
  margin-bottom: 16px;
}

.form-group-material label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.form-group-material label .req-star {
  color: #ef4444;
  margin-left: 2px;
}

/* Validity Radio Presets */
.preset-pills-group {
  display: flex;
  gap: 8px;
  margin-top: 6px;
}

.preset-pill-label {
  padding: 6px 12px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background: var(--bg-secondary);
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: all 0.15s ease;
}

.preset-pill-label:hover {
  background: var(--bg-card);
  color: var(--text-primary);
}

.preset-pill-label.active,
input[type="radio"]:checked + .preset-pill-label {
  background: rgba(34, 197, 94, 0.15);
  border-color: var(--primary);
  color: var(--primary);
  font-weight: 600;
}

/* Autocomplete Container */
.autocomplete-wrapper {
  position: relative;
}

.autocomplete-dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  z-index: 1000;
  max-height: 220px;
  overflow-y: auto;
  display: none;
}

.autocomplete-dropdown.open {
  display: block;
}

.autocomplete-item {
  padding: 10px 14px;
  font-size: 13px;
  color: var(--text-primary);
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.autocomplete-item:hover {
  background: var(--bg-secondary);
  color: var(--primary);
}

.autocomplete-item:last-child {
  border-bottom: none;
}

/* Vehicle Category Selector */
.vehicle-category-selector {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

.category-icon-btn {
  flex: 1;
  padding: 10px 6px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
}

.category-icon-btn:hover {
  background: var(--bg-card);
  color: var(--text-primary);
}

.category-icon-btn.active {
  background: rgba(34, 197, 94, 0.15);
  border-color: var(--primary);
  color: var(--primary);
}

/* Dual Dec/Hex Credential Inputs */
.dual-code-row {
  display: flex;
  gap: 12px;
  align-items: flex-end;
}

.dual-code-col {
  flex: 1;
}

/* Permission Matrix Tree */
.perm-matrix-container {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  overflow-x: auto;
  overflow-y: auto;
  max-height: 480px;
  -webkit-overflow-scrolling: touch;
}

.perm-matrix-header {
  background: var(--bg-card);
  padding: 10px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border-color);
  position: sticky;
  top: 0;
  z-index: 10;
}

.perm-matrix-table {
  width: 100%;
  border-collapse: collapse;
}

.perm-matrix-table th {
  padding: 8px 12px;
  font-size: 11px;
  text-transform: uppercase;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border-color);
  text-align: center;
}

.perm-matrix-table th:first-child {
  text-align: left;
}

.perm-matrix-table td {
  padding: 10px 12px;
  font-size: 13px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  text-align: center;
}

.perm-matrix-table td:first-child {
  text-align: left;
  font-weight: 500;
  color: var(--text-primary);
}

.perm-matrix-table tr:hover {
  background: rgba(255, 255, 255, 0.02);
}

/* Popover 23-Field Filter Card */
.filter-popover-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.6);
  margin-bottom: 20px;
}

.filter-grid-2col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px 24px;
}

@media (max-width: 768px) {
  .filter-grid-2col {
    grid-template-columns: 1fr;
  }
}

.filter-popover-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border-color);
}

/* Quick Visit Topbar Button & Modal */
.quick-visit-btn {
  background: linear-gradient(135deg, #10b981 0%, #059669 100%);
  color: #ffffff;
  border: none;
  font-weight: 700;
  padding: 6px 14px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(16, 185, 129, 0.35);
  transition: all 0.2s ease;
}

.quick-visit-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 14px rgba(16, 185, 129, 0.5);
}

/* ==========================================================================
   Milestone 4: System Configuration, Services, Cameras, Dial Plans & Areas
   ========================================================================== */

/* 10-Tab Settings Navigation */
.settings-tabs-nav {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 8px;
  margin-bottom: 24px;
  border-bottom: 1px solid var(--border-color);
  scrollbar-width: thin;
}

.settings-tabs-nav::-webkit-scrollbar {
  height: 4px;
}

.settings-tabs-nav::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: 2px;
}

.btn-tab {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid transparent;
  border-bottom: 2px solid transparent;
  border-radius: var(--radius-md) var(--radius-md) 0 0;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.2s ease;
}

.btn-tab:hover {
  color: var(--text-primary);
  background: var(--bg-card);
}

.btn-tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
  background: var(--bg-secondary);
  font-weight: 600;
}

.settings-tab-pane {
  display: none;
  animation: fadeInPane 0.2s ease;
}

.settings-tab-pane.active {
  display: block;
}

@keyframes fadeInPane {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Service Monitor Cards */
.service-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 20px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  transition: border-color 0.2s, box-shadow 0.2s, transform 0.2s;
}

.service-card:hover {
  border-color: rgba(34, 197, 94, 0.4);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
  transform: translateY(-2px);
}

.service-status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.service-status-dot.active {
  background: #22c55e;
  box-shadow: 0 0 10px rgba(34, 197, 94, 0.8);
  animation: servicePulse 2s infinite ease-in-out;
}

.service-status-dot.inactive {
  background: #ef4444;
  box-shadow: 0 0 8px rgba(239, 68, 68, 0.5);
}

@keyframes servicePulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.2); opacity: 0.7; }
}

/* Feature Toggle Cards (11 Toggles) */
.toggle-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(360px, 1fr));
  gap: 16px;
}

.toggle-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 16px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  transition: border-color 0.2s;
}

.toggle-card:hover {
  border-color: rgba(255, 255, 255, 0.15);
}

.toggle-card.enabled {
  border-left: 3px solid var(--primary);
}

/* Switch styling */
.switch {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
  flex-shrink: 0;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  top: 0; left: 0; right: 0; bottom: 0;
  background-color: #374151;
  transition: .3s cubic-bezier(0.4, 0, 0.2, 1);
  border-radius: 24px;
}

.slider:before {
  position: absolute;
  content: "";
  height: 18px;
  width: 18px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  transition: .3s cubic-bezier(0.4, 0, 0.2, 1);
  border-radius: 50%;
}

input:checked + .slider {
  background-color: var(--primary);
}

input:checked + .slider:before {
  transform: translateX(20px);
}

/* Floor Plan 2D & Pin Positioning */
.floor-plan-viewport {
  position: relative;
  width: 100%;
  height: 580px;
  background: #0b1120;
  border: 2px solid var(--border-color);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.5);
  user-select: none;
}

.floor-plan-pin {
  position: absolute;
  transform: translate(-50%, -50%);
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--bg-card);
  border: 2px solid var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: grab;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.6);
  pointer-events: auto;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  z-index: 5;
}

.floor-plan-pin:hover {
  transform: translate(-50%, -50%) scale(1.2);
  box-shadow: 0 6px 18px rgba(34, 197, 94, 0.6);
  z-index: 20;
}

.floor-plan-pin.dragging {
  cursor: grabbing;
  transform: translate(-50%, -50%) scale(1.3);
  box-shadow: 0 8px 24px rgba(34, 197, 94, 0.8);
  border-color: #ffffff;
  z-index: 100;
}

.floor-plan-pin .pin-tooltip {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  background: rgba(15, 23, 42, 0.95);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  font-size: 11px;
  font-weight: 600;
  padding: 4px 8px;
  border-radius: 4px;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s ease;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
}

.floor-plan-pin:hover .pin-tooltip {
  opacity: 1;
}

/* Real-Time Occupancy HUD */
.occupancy-hud {
  position: absolute;
  top: 16px;
  left: 16px;
  z-index: 10;
  background: rgba(15, 23, 42, 0.92);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 14px 18px;
  min-width: 250px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.6);
}

/* Stream Preview Simulator Frame */
.stream-preview-box {
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #020617;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

.stream-preview-box::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(rgba(18, 16, 16, 0) 50%, rgba(0, 0, 0, 0.25) 50%), linear-gradient(90deg, rgba(255, 0, 0, 0.03), rgba(0, 255, 0, 0.01), rgba(0, 0, 255, 0.03));
  background-size: 100% 3px, 6px 100%;
  pointer-events: none;
  z-index: 2;
}

.badge-live-rec {
  position: absolute;
  top: 12px;
  left: 12px;
  background: rgba(239, 68, 68, 0.85);
  color: white;
  font-size: 10px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 4px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  display: flex;
  align-items: center;
  gap: 5px;
  z-index: 3;
}

.badge-live-rec::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: white;
  animation: servicePulse 1.2s infinite;
}

/* ==========================================================================
   Milestone 5: Modern Dashboard, Accordion Nav, Sync Footer, Live Drawer, Multi-Tower
   ========================================================================== */

/* 1. Sidebar Brand Link & Accordion Navigation */
.sidebar-brand-link {
  display: flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
  color: inherit;
  width: 100%;
}
.sidebar-brand-link:hover {
  text-decoration: none;
}

.sidebar-accordion-group {
  margin-bottom: 2px;
}

.sidebar-accordion-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 500;
  transition: var(--transition);
  user-select: none;
}

.sidebar-accordion-header:hover {
  background-color: var(--bg-card-hover);
  color: var(--text-primary);
}

.sidebar-accordion-group.open > .sidebar-accordion-header {
  color: var(--text-primary);
  font-weight: 600;
}

.accordion-header-title {
  display: flex;
  align-items: center;
  gap: 10px;
}

.accordion-header-title i {
  width: 16px;
  height: 16px;
  color: var(--text-muted);
}

.sidebar-accordion-header:hover .accordion-header-title i,
.sidebar-accordion-group.open .accordion-header-title i {
  color: var(--brand-primary);
}

.accordion-chevron {
  width: 14px;
  height: 14px;
  color: var(--text-muted);
  transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.sidebar-accordion-group.open .accordion-chevron {
  transform: rotate(180deg);
  color: var(--brand-primary);
}

.sidebar-accordion-body {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.25s ease-out;
  padding-left: 8px;
}

.sidebar-accordion-group.open .sidebar-accordion-body {
  max-height: 600px;
}

.sidebar-accordion-body .nav-link {
  padding: 6px 12px;
  font-size: 12.5px;
  margin: 1px 0;
}

/* 2. Persistent Sync Monitor Footer */
.persistent-sync-footer {
  position: fixed;
  bottom: 0;
  left: var(--sidebar-width);
  right: 0;
  height: 36px;
  background-color: var(--bg-secondary);
  border-top: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 18px;
  z-index: 30;
  font-size: 12px;
  color: var(--text-secondary);
  backdrop-filter: blur(8px);
}

@media (max-width: 1024px) {
  .persistent-sync-footer {
    left: 0;
  }
}

.sync-footer-left,
.sync-footer-right {
  display: flex;
  align-items: center;
  gap: 14px;
}

.sync-status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  padding: 2px 10px;
  border-radius: var(--radius-full);
  font-size: 11px;
  color: var(--text-secondary);
}

.sync-status-pill.highlight {
  background: rgba(16, 185, 129, 0.12);
  border-color: rgba(16, 185, 129, 0.3);
  color: var(--success);
}

.sync-label {
  color: var(--text-muted);
  font-weight: 500;
}

.sync-value {
  color: var(--text-primary);
}

.status-indicator-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  display: inline-block;
  background-color: var(--text-muted);
}

.status-indicator-dot.online,
.pulse-dot.online {
  background-color: var(--success);
}

.status-indicator-dot.warning {
  background-color: var(--warning);
}

.status-indicator-dot.offline {
  background-color: var(--danger);
}

.status-indicator-dot.pulse,
.pulse-dot {
  box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7);
  animation: syncPulseAnim 2s infinite;
}

@keyframes syncPulseAnim {
  0% {
    box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7);
  }
  70% {
    box-shadow: 0 0 0 6px rgba(16, 185, 129, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(16, 185, 129, 0);
  }
}

/* Add padding to page container so footer doesn't obscure content */
.main-content {
  padding-bottom: 50px;
}

/* 3. Remote Door Unlock Floating Action Button (FAB) */
.fab-remote-door-container {
  position: fixed;
  bottom: 52px;
  right: 24px;
  z-index: 50;
}

.fab-remote-door {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--brand-primary), #0052cc);
  color: white;
  border: none;
  box-shadow: 0 4px 14px rgba(0, 102, 255, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
  outline: none;
}

.fab-remote-door:hover {
  transform: scale(1.08);
  box-shadow: 0 6px 20px rgba(0, 102, 255, 0.6);
}

.fab-door-menu {
  position: absolute;
  bottom: 60px;
  right: 0;
  width: 290px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  animation: fabMenuFade 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes fabMenuFade {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.96);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.fab-door-menu-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  font-size: 12px;
  font-weight: 600;
  color: var(--text-primary);
}

.fab-door-list {
  max-height: 250px;
  overflow-y: auto;
  padding: 6px;
}

.fab-door-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  transition: background 0.15s;
}

.fab-door-item:hover {
  background: var(--bg-elevated);
}

.fab-door-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 175px;
}

.fab-door-action-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 9px;
  border-radius: var(--radius-sm);
  background: var(--brand-primary-light);
  color: var(--brand-primary);
  border: 1px solid rgba(0, 102, 255, 0.25);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
}

.fab-door-action-btn:hover {
  background: var(--brand-primary);
  color: white;
}

/* 4. Slide-in Right Live Event Drawer (LogEventos) */
.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(2px);
  z-index: 60;
  transition: opacity 0.3s ease;
}

.live-event-drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 440px;
  max-width: 92vw;
  background: var(--bg-secondary);
  border-left: 1px solid var(--border-color);
  z-index: 61;
  display: flex;
  flex-direction: column;
  box-shadow: -6px 0 28px rgba(0, 0, 0, 0.6);
  transform: translateX(100%);
  transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.live-event-drawer.open {
  transform: translateX(0);
}

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

.drawer-title {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
}

.drawer-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border-color);
}

.drawer-autorefresh-toggle {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  cursor: pointer;
  padding: 0 4px;
  user-select: none;
}

.drawer-body {
  flex: 1;
  overflow-y: auto;
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.drawer-empty-feed {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 200px;
  text-align: center;
}

.drawer-event-card {
  padding: 10px 12px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  border-left: 3px solid var(--border-color);
  transition: background 0.15s;
}

.drawer-event-card:hover {
  background: var(--bg-card-hover);
}

.drawer-event-card.granted {
  border-left-color: var(--success);
}

.drawer-event-card.denied {
  border-left-color: var(--danger);
}

.drawer-event-card.alarm {
  border-left-color: var(--warning);
}

.drawer-event-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 11px;
  margin-bottom: 4px;
}

.drawer-event-badge {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  padding: 2px 6px;
  border-radius: 4px;
}

.drawer-event-badge.granted {
  background: var(--success-bg);
  color: var(--success);
}

.drawer-event-badge.denied {
  background: var(--danger-bg);
  color: var(--danger);
}

.drawer-event-badge.alarm {
  background: var(--warning-bg);
  color: var(--warning);
}

.drawer-event-time {
  color: var(--text-muted);
  font-size: 11px;
}

.drawer-event-user {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1.3;
}

.drawer-event-details {
  font-size: 11px;
  color: var(--text-secondary);
  margin-top: 3px;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* 5. Dashboard 5 KPI Cards, Charts, Donuts & Flow */
.dashboard-5-kpis {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 16px;
  margin-bottom: 20px;
}

@media (min-width: 768px) and (max-width: 1024px) {
  .dashboard-5-kpis {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 14px;
  }
  .dashboard-5-kpis .kpi-card:last-child {
    grid-column: 1 / -1;
  }
}

@media (max-width: 767.98px) {
  .dashboard-5-kpis {
    grid-template-columns: 1fr !important;
    gap: 12px;
  }
  .dashboard-5-kpis .kpi-card:last-child {
    grid-column: auto !important;
  }
}

.kpi-breakdown {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
  word-break: break-word;
}

.kpi-pill {
  font-size: 10.5px;
  padding: 2px 7px;
  border-radius: var(--radius-full);
  background: var(--bg-elevated);
  color: var(--text-secondary);
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.kpi-trend {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: 4px;
}

.kpi-trend.positive {
  color: var(--success);
  background: var(--success-bg);
}

.kpi-trend.negative {
  color: var(--danger);
  background: var(--danger-bg);
}

.kpi-trend.neutral {
  color: var(--text-muted);
  background: var(--bg-elevated);
}

/* Card Base Utility */
.card {
  background-color: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow-sm);
  transition: var(--transition);
}

.dashboard-grid-charts {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 20px;
  margin-bottom: 24px;
  align-items: stretch;
}

@media (max-width: 1024px) {
  .dashboard-grid-charts {
    grid-template-columns: 1fr;
  }
}

/* Dashboard Chart Cards */
.dashboard-card-events,
.dashboard-card-donut {
  display: flex;
  flex-direction: column;
  min-height: 320px;
  max-height: 380px;
  overflow: hidden;
}

.chart-container {
  position: relative;
  height: 240px;
  width: 100%;
  overflow: hidden;
}

.donut-canvas-wrapper {
  position: relative;
  height: 180px;
  width: 100%;
  overflow: hidden;
}

.donut-view {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
}

.chart-legend-toggles {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.chart-legend-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  background: var(--bg-card);
  cursor: pointer;
  color: var(--text-secondary);
  transition: all 0.15s;
}

.chart-legend-btn.active {
  color: var(--text-primary);
  border-color: var(--brand-primary);
  background: var(--brand-primary-light);
}

.chart-legend-btn.inactive {
  opacity: 0.45;
  text-decoration: line-through;
}

.chart-legend-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
}

.donut-tab-header {
  display: flex;
  border-bottom: 1px solid var(--border-color);
  margin-bottom: 14px;
}

.donut-tab-btn {
  padding: 8px 14px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  transition: all 0.2s;
}

.donut-tab-btn.active {
  color: var(--brand-primary);
  border-bottom-color: var(--brand-primary);
  font-weight: 600;
}

.dashboard-grid-bottom {
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  gap: 20px;
  margin-bottom: 20px;
}

@media (max-width: 1024px) {
  .dashboard-grid-bottom {
    grid-template-columns: 1fr;
  }
}

.dashboard-alert-item {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: 10px 12px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
  gap: 12px;
}

.dashboard-alert-item.severity-critical {
  border-left: 3px solid var(--danger);
}

.dashboard-alert-item.severity-high {
  border-left: 3px solid var(--warning);
}

.dashboard-alert-item.severity-medium {
  border-left: 3px solid var(--info);
}

.flow-ranking-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border-subtle);
}

.flow-rank-num {
  font-size: 13px;
  font-weight: 700;
  color: var(--brand-primary);
  min-width: 24px;
  text-align: center;
}

.flow-rank-info {
  flex: 1;
}

.flow-rank-header {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  font-weight: 500;
  margin-bottom: 4px;
}

.flow-rank-bar-bg {
  height: 6px;
  border-radius: 3px;
  background: var(--bg-elevated);
  overflow: hidden;
}

.flow-rank-bar-fill {
  height: 100%;
  border-radius: 3px;
  background: linear-gradient(90deg, var(--brand-primary), #00d2ff);
}

/* 6. Multi-Tower Condo Creation UI */
.tower-row-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 14px;
  margin-bottom: 12px;
  transition: border-color 0.2s;
}

.tower-row-card:hover {
  border-color: var(--brand-primary);
}

.tower-row-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
  font-weight: 600;
  font-size: 13px;
}

.tower-row-grid {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr 1fr 1.5fr;
  gap: 10px;
}

@media (max-width: 768px) {
  .tower-row-grid {
    grid-template-columns: 1fr;
  }
}

.unit-preview-box {
  max-height: 120px;
  overflow-y: auto;
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 8px;
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  margin-top: 6px;
}

.unit-preview-tag {
  font-size: 10.5px;
  padding: 2px 6px;
  border-radius: 4px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  font-family: monospace;
}

