/* ==========================================================================
   THEME STYLING VARIABLES (PREMIUM LIGHT MODE - CURSOR STYLE)
   ========================================================================== */
:root {
  --bg-dark: #f8fafc; /* Crisp light-slate background */
  --bg-card: #ffffff; /* White panels */
  --bg-card-hover: #f1f5f9; /* Slate-100 hover indicator */
  --bg-sidebar: #ffffff; /* White sidebar drawer */
  --border-color: #e2e8f0; /* Crisp slate-200 border lines */
  --border-focus: #2563eb; /* Primary royal blue border focus */
  
  --text-primary: #0f172a; /* Slate-900 primary labels */
  --text-secondary: #475569; /* Slate-600 description text */
  --text-muted: #94a3b8; /* Slate-400 placeholder text */

  --primary-color: #2563eb; /* Royal blue accent */
  --primary-glow: rgba(37, 99, 235, 0.08); /* Clean tint highlights */
  
  --secondary-color: #64748b; /* Slate-500 general UI buttons */
  
  --success-color: #16a34a; /* Emerald green indicators */
  --success-glow: rgba(22, 163, 74, 0.08);
  
  --danger-color: #dc2626; /* Crimson red alert */
  --danger-glow: rgba(220, 38, 38, 0.08);
  
  --warning-color: #ea580c; /* Clean orange warning */
  --warning-glow: rgba(234, 88, 12, 0.08);
  
  --info-color: #0891b2; /* Teal info badge */
  --info-glow: rgba(8, 145, 178, 0.08);

  --font-family: 'Outfit', sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
  --border-radius: 8px; /* Classic premium developer-tool corners */
  --border-radius-sm: 4px;
  --transition-fast: 0.15s ease;
  --transition-normal: 0.25s ease;
  
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -1px rgba(0, 0, 0, 0.03);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.05), 0 4px 6px -2px rgba(0, 0, 0, 0.03);
}

/* ==========================================================================
   BASE RESET & LAYOUT SYSTEM
   ========================================================================== */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  outline: none;
}

body {
  font-family: var(--font-family);
  background-color: var(--bg-dark);
  color: var(--text-primary);
  line-height: 1.5;
  overflow: hidden;
  height: 100vh;
  height: 100dvh;
  width: 100vw;
  width: 100dvw;
  -webkit-font-smoothing: antialiased;
}

a {
  text-decoration: none;
  color: inherit;
}

button, input, select, textarea {
  font-family: inherit;
  font-size: inherit;
}

/* Scrollbar styles */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: var(--bg-dark);
}
::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: 10px;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* Helper utilities */
.hidden {
  display: none !important;
}

.text-secondary {
  color: var(--text-secondary);
}

.text-success {
  color: var(--success-color);
}

.text-danger {
  color: var(--danger-color);
}

.text-center {
  text-align: center;
}

.code-text {
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  background-color: var(--bg-dark);
  padding: 3px 6px;
  border-radius: var(--border-radius-sm);
  border: 1px solid var(--border-color);
}

/* Horizontal scrollable code cell (For API Paths) */
.code-scroll-wrapper {
  display: inline-block;
  overflow-x: auto;
  white-space: nowrap;
  padding: 4px 8px;
  background-color: var(--bg-dark);
  border-radius: var(--border-radius-sm);
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  border: 1px solid var(--border-color);
  vertical-align: middle;
}

/* Material icon helper size properties */
.material-icons-outlined {
  display: inline-block;
  vertical-align: middle;
  line-height: 1;
}

.md-18 { font-size: 18px; }
.md-24 { font-size: 24px; }
.md-36 { font-size: 36px; }
.md-48 { font-size: 48px; color: var(--text-secondary); }
.md-logo { font-size: 28px; color: var(--primary-color); }
.text-icon-size { font-size: 1.25rem; }

/* ==========================================================================
   AUTHENTICATION CARD PAGE
   ========================================================================== */
.page-container {
  display: none;
  width: 100%;
  min-height: 100vh;
  min-height: 100dvh;
  padding: 20px;
  justify-content: center;
  align-items: center;
  position: relative;
  background-color: var(--bg-dark);
}

.page-container.active-flex {
  display: flex;
}

.login-card {
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius);
  width: 100%;
  max-width: 400px;
  padding: 40px 30px;
  box-shadow: var(--shadow-lg);
  animation: cardFadeIn 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

.brand-header {
  text-align: center;
  margin-bottom: 30px;
}

.brand-header h2 {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.025em;
  margin-top: 15px;
  margin-bottom: 6px;
  color: var(--text-primary);
}

.brand-header p {
  color: var(--text-secondary);
  font-size: 0.875rem;
}

/* ==========================================================================
   LAYOUT STRUCTURE (SIDEBAR & HEADER)
   ========================================================================== */
.layout-container {
  display: flex;
  height: 100%;
  width: 100%;
  overflow: hidden;
}

/* Navigation Drawer Sidebar */
.sidebar {
  width: 250px;
  background-color: var(--bg-sidebar);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  height: 100%;
  flex-shrink: 0;
  transition: transform var(--transition-normal);
  z-index: 100;
}

.sidebar-brand {
  height: 70px;
  padding: 0 20px;
  display: flex;
  align-items: center;
  border-bottom: 1px solid var(--border-color);
  position: relative;
  box-sizing: border-box;
}

.sidebar-brand .logo {
  margin-right: 10px;
  display: flex;
  align-items: center;
}

.sidebar-brand .brand-text h1 {
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: -0.025em;
}

.sidebar-brand .brand-text span {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.mobile-close {
  display: none;
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  position: absolute;
  right: 20px;
}

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

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

.sidebar-nav li {
  margin-bottom: 4px;
}

.nav-item, .nav-item-external {
  display: flex;
  align-items: center;
  padding: 10px 14px;
  color: var(--text-secondary);
  border-radius: var(--border-radius-sm);
  font-size: 0.875rem;
  font-weight: 500;
  transition: all var(--transition-fast);
  text-decoration: none;
}

.nav-item:hover, .nav-item-external:hover {
  background-color: var(--bg-dark);
  color: var(--text-primary);
}

.nav-item.active {
  background-color: var(--primary-glow);
  color: var(--primary-color);
  font-weight: 600;
}

.nav-icon {
  margin-right: 12px;
  display: flex;
  align-items: center;
  color: inherit;
}

.nav-icon .material-icons-outlined {
  font-size: 1.25rem;
}

.sidebar-footer {
  padding: 15px 10px;
  border-top: 1px solid var(--border-color);
}

/* Top Content Header & Main Frame */
.main-content {
  flex-grow: 1;
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
}

.main-header {
  height: 60px;
  background-color: var(--bg-card);
  border-bottom: 1px solid var(--border-color);
  padding: 0 30px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  z-index: 90;
  flex-shrink: 0;
}

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

.mobile-toggle {
  display: none;
  background: none;
  border: none;
  color: var(--text-primary);
  margin-right: 15px;
  cursor: pointer;
  align-items: center;
}

.header-left h2 {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text-primary);
}

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

.connection-pill {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
  border-radius: 12px;
  font-size: 0.75rem;
  font-weight: 600;
  border: 1px solid var(--border-color);
}

.status-connected {
  background-color: var(--success-glow);
  color: var(--success-color);
  border-color: rgba(22, 163, 74, 0.15);
}

.status-disconnected {
  background-color: var(--danger-glow);
  color: var(--danger-color);
  border-color: rgba(220, 38, 38, 0.15);
}

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

.user-profile-badge {
  display: flex;
  align-items: center;
  gap: 8px;
}

.user-profile-badge .avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background-color: var(--bg-dark);
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
}

.user-profile-badge .avatar .material-icons-outlined {
  font-size: 1.1rem;
}

.user-profile-badge .username {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.content-wrapper {
  padding: 30px;
  overflow-y: auto;
  overflow-x: hidden;
  background-color: var(--bg-dark);
  flex-grow: 1;
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
}

/* ==========================================================================
   DASHBOARD SECTIONS & GRID CARDS
   ========================================================================== */
.dashboard-section {
  display: none;
  animation: sectionFadeIn 0.25s ease-out;
}

.dashboard-section.active-section {
  display: block;
}

/* 4x2 Grid Layout for PC screens */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 20px;
  margin-bottom: 30px;
}

@media (min-width: 1025px) {
  .stats-grid {
    grid-template-columns: repeat(4, 1fr); /* Exactly 4 columns per row */
  }
}

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

.stat-card:hover {
  transform: translateY(-1px);
  border-color: var(--text-muted);
}

.stat-icon {
  width: 40px;
  height: 40px;
  border-radius: var(--border-radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
}

.stat-icon .material-icons-outlined {
  font-size: 1.35rem;
}

.bg-blue-glow { background-color: #eff6ff; color: #2563eb; border: 1px solid rgba(37, 99, 235, 0.1); }
.bg-green-glow { background-color: #f0fdf4; color: #16a34a; border: 1px solid rgba(22, 163, 74, 0.15); }
.bg-purple-glow { background-color: #faf5ff; color: #9333ea; border: 1px solid rgba(147, 51, 234, 0.15); }
.bg-orange-glow { background-color: #fff7ed; color: #ea580c; border: 1px solid rgba(234, 88, 12, 0.15); }
.bg-yellow-glow { background-color: #fef9c3; color: #ca8a04; border: 1px solid rgba(202, 138, 4, 0.15); }
.bg-cyan-glow { background-color: #ecfeff; color: #0891b2; border: 1px solid rgba(8, 145, 178, 0.15); }

.bg-emerald-trans {
  background-color: #f0fdf4;
  border-color: rgba(22, 163, 74, 0.15);
}
.bg-rose-trans {
  background-color: #fef2f2;
  border-color: rgba(220, 38, 38, 0.15);
}

.stat-info h3 {
  font-size: 0.75rem;
  color: var(--text-secondary);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 2px;
}

.stat-info p {
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--text-primary);
}

/* Charts layouts */
.charts-row {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 20px;
}

.card {
  min-width: 0;
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

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

.card-header-title-group {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
}

.card-header-title-group h3 {
  font-size: 0.9375rem;
  font-weight: 700;
  color: var(--text-primary);
  margin: 0;
}

.card-header-title-group p {
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin: 0;
}

.card-header h3 {
  font-size: 0.9375rem;
  font-weight: 700;
  color: var(--text-primary);
}

.card-body {
  padding: 20px;
  position: relative;
}

.centered-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

/* ==========================================================================
   SVG PIE CHART STYLING (FLAT ACCENT)
   ========================================================================== */
.pie-chart-container {
  position: relative;
  width: 160px;
  height: 160px;
  margin-bottom: 15px;
}

#success-pie-chart {
  transform: rotate(-90deg);
  border-radius: 50%;
}

.pie-chart-label {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
}

.pie-chart-label span {
  font-size: 1.5rem;
  font-weight: 800;
  display: block;
  line-height: 1;
  color: var(--text-primary);
}

.pie-chart-label small {
  font-size: 0.6875rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  font-weight: 600;
}

.pie-chart-legend {
  display: flex;
  gap: 15px;
  font-size: 0.8125rem;
  color: var(--text-secondary);
}

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

.success-bg { background-color: var(--success-color); }
.danger-bg { background-color: var(--danger-color); }

/* SVG Performance Bar Chart */
.svg-bar-chart-container {
  width: 100%;
  min-width: 0;
  height: 180px;
  display: flex;
  align-items: flex-end;
  gap: 12px;
  padding: 10px 0 25px 0;
  border-bottom: 1px solid var(--border-color);
  position: relative;
  overflow-x: auto;
  overflow-y: hidden;
}

.svg-bar-chart-container::-webkit-scrollbar {
  height: 5px;
}
.svg-bar-chart-container::-webkit-scrollbar-track {
  background: transparent;
}
.svg-bar-chart-container::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: 3px;
}

.bar-wrapper {
  flex-grow: 1;
  min-width: 45px;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: center;
  position: relative;
}

.chart-bar {
  width: 100%;
  max-width: 32px;
  background-color: var(--primary-glow);
  border: 1px solid var(--primary-color);
  border-bottom: none;
  border-radius: 2px 2px 0 0;
  transition: background-color var(--transition-fast);
  position: relative;
}

.chart-bar:hover {
  background-color: rgba(37, 99, 235, 0.15);
}

.chart-bar.bar-failed {
  background-color: var(--danger-glow);
  border-color: var(--danger-color);
}

.chart-bar.bar-failed:hover {
  background-color: rgba(220, 38, 38, 0.15);
}

.chart-card {
  min-width: 0;
  overflow: visible !important;
}

.chart-card .card-body {
  overflow: visible !important;
}

.chart-tooltip {
  visibility: hidden;
  position: absolute;
  top: 5px;
  left: 50%;
  transform: translateX(-50%);
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-md);
  border-radius: var(--border-radius-sm);
  padding: 6px 10px;
  font-size: 0.75rem;
  white-space: nowrap;
  pointer-events: none;
  z-index: 999;
  color: var(--text-primary);
}

.bar-wrapper:hover .chart-tooltip {
  visibility: visible;
}

/* Align tooltips near edges to prevent clipping on mobile/scroll */
.bar-wrapper:nth-child(1) .chart-tooltip,
.bar-wrapper:nth-child(2) .chart-tooltip {
  left: 0 !important;
  transform: translateX(0) !important;
}

.bar-wrapper:nth-last-child(1) .chart-tooltip,
.bar-wrapper:nth-last-child(2) .chart-tooltip {
  left: auto !important;
  right: 0 !important;
  transform: translateX(0) !important;
}

.bar-label {
  position: absolute;
  top: 102%;
  font-size: 0.6875rem;
  color: var(--text-secondary);
  width: 100%;
  text-align: center;
  text-overflow: ellipsis;
  overflow: hidden;
  white-space: nowrap;
}

/* ==========================================================================
   BUTTONS STYLING
   ========================================================================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 14px;
  border-radius: var(--border-radius-sm);
  font-weight: 600;
  font-size: 0.8125rem;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all var(--transition-fast);
  gap: 6px;
}

.btn-sm {
  padding: 4px 8px;
  font-size: 0.75rem;
}

.btn-full {
  width: 100%;
}

.btn-primary {
  background-color: var(--primary-color);
  color: white;
  border-color: var(--primary-color);
  box-shadow: 0 1px 2px rgba(37, 99, 235, 0.2);
}
.btn-primary:hover {
  background-color: #1d4ed8;
}

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

.btn-danger {
  background-color: var(--danger-color);
  color: white;
  border-color: var(--danger-color);
  box-shadow: 0 1px 2px rgba(220, 38, 38, 0.2);
}
.btn-danger:hover {
  background-color: #b91c1c;
}

.btn-orange {
  background-color: var(--warning-color);
  color: white;
  border-color: var(--warning-color);
  box-shadow: 0 1px 2px rgba(234, 88, 12, 0.2);
}
.btn-orange:hover {
  background-color: #c2410c;
}

.btn-icon-left {
  font-size: 1.15rem !important;
}

.btn-spinner {
  width: 14px;
  height: 14px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

/* ==========================================================================
   INPUTS, SELECTIONS, AND CUSTOM UPLOADS
   ========================================================================== */
.form-group {
  margin-bottom: 16px;
}

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

.form-group input[type="text"],
.form-group input[type="password"],
.form-group input[type="url"],
.form-group input[type="email"],
.form-group input[type="number"],
.form-select-control,
.filter-select,
.search-input,
.code-textarea {
  width: 100%;
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius-sm);
  padding: 8px 12px;
  color: var(--text-primary);
  font-size: 0.875rem;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
  box-shadow: var(--shadow-sm);
}

.form-group input:focus,
.form-select-control:focus,
.filter-select:focus,
.search-input:focus,
.code-textarea:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.15);
}

.form-help {
  display: block;
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 4px;
}

.row-checkbox {
  display: flex;
  align-items: center;
  gap: 8px;
}

.row-checkbox label {
  margin-bottom: 0;
  cursor: pointer;
}

.row-checkbox input[type="checkbox"] {
  width: 16px;
  height: 16px;
  cursor: pointer;
}

.form-max-card {
  max-width: 550px;
  margin: 0 auto;
}

.form-actions-row {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 25px;
}

.color-picker-input {
  width: 50px;
  height: 35px;
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius-sm);
  background: none;
  cursor: pointer;
}

/* Custom Styled Backup File Upload */
.file-upload-group {
  margin-bottom: 12px;
}

.custom-file-upload-label {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background-color: var(--bg-dark);
  border: 2px dashed var(--border-color);
  border-radius: var(--border-radius-sm);
  padding: 15px;
  text-align: center;
  cursor: pointer;
  color: var(--text-secondary);
  font-size: 0.8125rem;
  font-weight: 600;
  transition: all var(--transition-fast);
}

.custom-file-upload-label:hover {
  border-color: var(--primary-color);
  background-color: var(--primary-glow);
  color: var(--primary-color);
}

.custom-file-upload-label .material-icons-outlined {
  font-size: 1.35rem;
}

.hidden-file-input {
  display: none !important;
}

/* Dropdown selector for device actions inline table row */
.action-select-dropdown {
  width: 130px;
  padding: 4px 8px;
  font-size: 0.75rem;
  font-weight: 600;
  border-radius: var(--border-radius-sm);
  border: 1px solid var(--border-color);
  background-color: var(--bg-card);
  color: var(--text-primary);
  margin-right: 6px;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
}

.action-select-dropdown:focus {
  border-color: var(--border-focus);
}

.btn-perform {
  background-color: var(--success-color) !important;
  color: white !important;
  border-color: var(--success-color) !important;
  font-weight: 700;
  box-shadow: 0 1px 2px rgba(22, 163, 74, 0.2);
}
.btn-perform:hover {
  background-color: #15803d !important;
  border-color: #15803d !important;
}

/* ==========================================================================
   TABLES & GENERAL PAGE HEADERS
   ========================================================================== */
.action-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  flex-wrap: wrap;
  gap: 12px;
}

.search-filters {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.search-input {
  width: 220px;
}

.filter-select {
  width: 140px;
}

.table-card {
  width: 100%;
  overflow-x: auto;
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius);
  box-shadow: var(--shadow-sm);
}

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

.data-table th {
  background-color: #f8fafc;
  color: var(--text-secondary);
  font-weight: 700;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-color);
  white-space: nowrap;
}

.data-table td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-color);
  font-size: 0.875rem;
  color: var(--text-secondary);
  white-space: nowrap;
}

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

.data-table tbody tr:hover {
  background-color: #f8fafc;
}

.ua-text {
  display: block;
  width: 100%;
  max-width: 250px;
  overflow-x: auto;
  white-space: nowrap;
  vertical-align: middle;
  box-sizing: border-box;
}

.ua-text::-webkit-scrollbar {
  height: 4px;
}

.ua-text::-webkit-scrollbar-track {
  background: transparent;
}

.ua-text::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: 2px;
}

.data-table tbody tr:last-child td {
  border-bottom: none;
}

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 8px;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 600;
}

.badge-success { background-color: #f0fdf4; color: #16a34a; border: 1px solid rgba(22, 163, 74, 0.15); }
.badge-danger { background-color: #fef2f2; color: #dc2626; border: 1px solid rgba(220, 38, 38, 0.15); }
.badge-warning { background-color: #fff7ed; color: #ea580c; border: 1px solid rgba(234, 88, 12, 0.15); }
.badge-info { background-color: #eff6ff; color: #2563eb; border: 1px solid rgba(37, 99, 235, 0.15); }

/* Unique Device Type Badges */
.badge-device-light { background-color: #fef9c3; color: #a16207; border: 1px solid rgba(234, 179, 8, 0.2); }
.badge-device-switch { background-color: #e0e7ff; color: #4338ca; border: 1px solid rgba(79, 70, 229, 0.2); }
.badge-device-fan { background-color: #ecfeff; color: #0891b2; border: 1px solid rgba(6, 182, 212, 0.2); }
.badge-device-cover { background-color: #f3e8ff; color: #6b21a8; border: 1px solid rgba(147, 51, 234, 0.2); }
.badge-device-lock { background-color: #fee2e2; color: #b91c1c; border: 1px solid rgba(239, 68, 68, 0.2); }
.badge-device-climate { background-color: #ccfbf1; color: #0f766e; border: 1px solid rgba(20, 184, 166, 0.2); }
.badge-device-scene { background-color: #fce7f3; color: #be185d; border: 1px solid rgba(236, 72, 153, 0.2); }
.badge-device-script { background-color: #d1fae5; color: #047857; border: 1px solid rgba(16, 185, 129, 0.2); }
.badge-device-mediaplayer { background-color: #dbeafe; color: #1d4ed8; border: 1px solid rgba(59, 130, 246, 0.2); }
.badge-device-vacuum { background-color: #f1f5f9; color: #475569; border: 1px solid rgba(100, 116, 139, 0.2); }
.badge-device-custom { background-color: #fafaf9; color: #57534e; border: 1px solid rgba(120, 113, 108, 0.2); }
.badge-device-input { background-color: #fae8ff; color: #701a75; border: 1px solid rgba(217, 70, 239, 0.2); }

/* Pagination styling */
.table-pagination {
  padding: 10px 16px;
  background-color: #f8fafc;
  border-top: 1px solid var(--border-color);
  display: flex;
  justify-content: flex-end;
  gap: 4px;
  align-items: center;
}

.pagination-btn {
  padding: 4px 10px;
  border: 1px solid var(--border-color);
  background-color: var(--bg-card);
  color: var(--text-secondary);
  border-radius: var(--border-radius-sm);
  cursor: pointer;
  font-size: 0.75rem;
  font-weight: 600;
  transition: all var(--transition-fast);
}

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

.pagination-btn.active {
  background-color: var(--primary-color);
  border-color: var(--primary-color);
  color: white;
}

.pagination-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* ==========================================================================
   ROOM CARDS & DEVICE ACTION UTILS
   ========================================================================== */
.rooms-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 20px;
}

.room-card {
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-top: 3px solid var(--primary-color);
  border-radius: var(--border-radius);
  padding: 20px;
  box-shadow: var(--shadow-sm);
  position: relative;
  transition: transform var(--transition-fast), border-color var(--transition-fast);
}

.room-card:hover {
  transform: translateY(-2px);
  border-color: var(--text-muted);
  box-shadow: var(--shadow-md);
}

.room-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 10px;
}

.room-icon-box {
  width: 38px;
  height: 38px;
  border-radius: var(--border-radius-sm);
  background-color: var(--bg-dark);
  border: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
}

.room-card-actions {
  display: flex;
  gap: 4px;
}

.action-icon-btn {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 4px;
  border-radius: var(--border-radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
}

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

.action-icon-btn.delete:hover {
  color: var(--danger-color);
}

.room-card h3 {
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: 4px;
  color: var(--text-primary);
}

.room-card p {
  font-size: 0.8125rem;
  color: var(--text-secondary);
  min-height: 36px;
}

/* Inline action buttons */
.row-actions-cell {
  display: flex;
  gap: 4px;
  align-items: center;
}

.row-action-btn {
  padding: 4px 8px;
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  font-size: 0.75rem;
  font-weight: 600;
  border-radius: var(--border-radius-sm);
  cursor: pointer;
  transition: all var(--transition-fast);
}

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

.row-action-btn.delete-text {
  color: var(--danger-color);
}
.row-action-btn.delete-text:hover {
  background-color: #fef2f2;
  border-color: rgba(220, 38, 38, 0.2);
}

/* ==========================================================================
   GENERATED APIS INTERFACE
   ========================================================================== */
.info-alert {
  background-color: var(--info-glow);
  border: 1px solid rgba(8, 145, 178, 0.15);
  border-radius: var(--border-radius);
  padding: 14px 18px;
  display: flex;
  gap: 12px;
  margin-bottom: 25px;
}

.info-alert-icon {
  color: var(--info-color);
  display: flex;
  align-items: center;
}

.info-alert-text h4 {
  font-size: 0.875rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 2px;
}

.info-alert-text p {
  font-size: 0.8125rem;
  color: var(--text-secondary);
}

.apis-list {
  display: flex;
  flex-direction: column;
  gap: 15px;
}

.api-card {
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius);
  overflow: hidden;
}

.api-card-header {
  padding: 12px 20px;
  background-color: #f8fafc;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.api-card-header h4 {
  font-size: 0.875rem;
  font-weight: 700;
  color: var(--text-primary);
}

.api-endpoints {
  padding: 16px 20px;
}

.api-endpoint-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 16px;
}

.api-endpoint-row:last-child {
  margin-bottom: 0;
}

.api-route,
.api-doc-route {
  display: flex;
  align-items: center;
  background-color: var(--bg-dark);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius-sm);
  overflow: hidden;
  position: relative;
  justify-content: space-between;
  width: 100%;
}

.api-route-buttons {
  display: flex;
  flex-shrink: 0;
  margin-left: auto;
}

.mini-copy-btn {
  background: none;
  border: none;
  padding: 2px 4px;
  cursor: pointer;
  color: var(--text-secondary);
  display: inline-flex;
  align-items: center;
  vertical-align: middle;
  border-radius: var(--border-radius-sm);
  transition: all var(--transition-fast);
}

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

.api-method {
  background-color: #eab308;
  color: white;
  padding: 6px 12px;
  font-weight: 800;
  font-size: 0.6875rem;
  letter-spacing: 0.05em;
  min-width: 70px;
  text-align: center;
}

.api-path {
  /* Scrollable code wrapper styling */
  flex-grow: 1;
  border: none;
  background: none;
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  padding: 8px 12px;
  color: var(--text-primary);
  overflow-x: auto;
  white-space: nowrap;
}

.api-path::-webkit-scrollbar {
  height: 4px;
}
.api-path::-webkit-scrollbar-track {
  background: transparent;
}
.api-path::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: 2px;
}

.copy-btn {
  background-color: var(--bg-card);
  border: none;
  border-left: 1px solid var(--border-color);
  padding: 6px 12px;
  color: var(--text-secondary);
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition-fast);
}

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

.api-actions-row {
  display: flex;
  gap: 4px;
}

/* ==========================================================================
   SETTINGS LAYOUT & VERTICAL DIAGNOSTICS CARD
   ========================================================================== */
.settings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 20px;
}

.card-span-full {
  grid-column: 1 / -1;
}

.card-divider {
  border: 0;
  border-top: 1px solid var(--border-color);
  margin: 16px 0;
}

.settings-action-block p {
  font-size: 0.8125rem;
  color: var(--text-secondary);
  margin-bottom: 12px;
}

.code-textarea {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  resize: vertical;
}

/* Diagnostics layout that prevents awkward wrapping */
.health-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 15px;
}

@media (min-width: 1025px) {
  .health-grid {
    grid-template-columns: repeat(3, 1fr); /* Exactly 3 columns (3 x 2 layout) */
  }
}

.health-item {
  display: flex;
  flex-direction: column; /* Stack vertically to prevent long line breaks */
  align-items: flex-start;
  gap: 4px;
  padding: 12px 16px;
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius-sm);
  box-shadow: var(--shadow-sm);
}

.health-label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.health-val {
  font-size: 0.875rem;
  font-weight: 700;
  color: var(--text-primary);
  word-break: break-word; /* Safe wrapping */
}

.server-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

/* ==========================================================================
   MODAL DIALOG POPUPS
   ========================================================================== */
.modal-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background-color: rgba(15, 23, 42, 0.3);
  backdrop-filter: blur(2px);
  z-index: 1000;
  justify-content: center;
  align-items: center;
}

.modal-overlay.active-flex {
  display: flex;
}

.modal-card {
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius);
  box-shadow: var(--shadow-lg);
  width: calc(100% - 32px);
  max-width: 440px;
  overflow: hidden;
  animation: modalScaleUp 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.modal-large {
  max-width: 650px;
}

.modal-small {
  max-width: 340px;
}

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

.modal-header h3 {
  font-size: 0.9375rem;
  font-weight: 700;
  color: var(--text-primary);
}

.modal-close {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
}

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

.modal-card form {
  padding: 20px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 20px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

.form-span-2 {
  grid-column: span 2;
}

.modal-divider {
  border: 0;
  border-top: 1px solid var(--border-color);
  margin: 12px 0;
}

.custom-action-row {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 8px;
}

.custom-action-row input {
  flex-grow: 1;
  padding: 6px 10px;
  font-size: 0.8125rem;
}

/* ==========================================================================
   FLOATING TOAST NOTIFICATIONS
   ========================================================================== */
.toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 10000;
}

.toast {
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-left: 3px solid var(--primary-color);
  border-radius: var(--border-radius-sm);
  padding: 10px 16px;
  box-shadow: var(--shadow-md);
  color: var(--text-primary);
  font-size: 0.8125rem;
  font-weight: 600;
  min-width: 260px;
  max-width: 380px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  animation: toastSlideIn 0.25s cubic-bezier(0.16, 1, 0.3, 1),
             toastFadeOut 0.25s ease 4.75s forwards;
}

.toast-success { border-left-color: var(--success-color); }
.toast-danger { border-left-color: var(--danger-color); }
.toast-warning { border-left-color: var(--warning-color); }

.toast-close {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1rem;
  margin-left: 8px;
}

/* ==========================================================================
   ANIMATIONS KEYFRAMES
   ========================================================================== */
@keyframes cardFadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes sectionFadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes modalScaleUp {
  from { opacity: 0; transform: scale(0.97); }
  to { opacity: 1; transform: scale(1); }
}

@keyframes toastSlideIn {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

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

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Desktop layout constraints for parameter card */
#gen-api-param-card {
  max-height: 120px;
}

/* ==========================================================================
   RESPONSIVE DESIGN ADAPTABILITY
   ========================================================================== */
@media (max-width: 1024px) {
  .charts-row {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    transform: translateX(-100%);
  }

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

  .mobile-close {
    display: flex;
    align-items: center;
  }

  .mobile-toggle {
    display: flex;
  }

  .main-header {
    padding: 0 20px;
  }

  .content-wrapper {
    padding: 20px;
  }

  .form-grid {
    grid-template-columns: 1fr;
  }

  .form-span-2 {
    grid-column: span 1;
  }

  /* Padding Reduction for all elements on Mobile */
  .content-wrapper {
    padding: 12px !important;
  }

  .card-header {
    padding: 12px 16px !important;
  }

  .card-body {
    padding: 12px !important;
  }

  .api-endpoints {
    padding: 12px !important;
  }

  .api-endpoint-row {
    margin-bottom: 8px !important;
  }

  .api-route,
  .api-doc-route {
    flex-wrap: wrap !important;
    padding: 0 !important;
  }

  .api-path {
    padding: 6px 8px !important;
    font-size: 0.75rem !important;
  }

  .api-method {
    padding: 4px 8px !important;
    font-size: 0.625rem !important;
    min-width: 50px !important;
  }

  .api-route-buttons {
    width: 100% !important;
    display: flex !important;
    border-top: 1px solid var(--border-color) !important;
    margin-left: 0 !important;
  }

  .api-route-buttons .copy-btn {
    flex: 1 !important;
    text-align: center !important;
    border-left: none !important;
    border-right: 1px solid var(--border-color) !important;
    padding: 8px !important;
    font-size: 0.75rem !important;
  }

  .api-route-buttons .copy-btn:last-child {
    border-right: none !important;
  }

  /* Hide HA connection status indicator pill on Mobile */
  #header-ha-status {
    display: none !important;
  }

  /* Compact spacing for generated APIs parameter card on Mobile */
  #gen-api-param-card {
    padding: 10px 12px !important;
    max-height: none !important;
  }

  /* Hide username inside user profile badge on Mobile */
  .user-profile-badge .username {
    display: none !important;
  }

  .user-profile-badge {
    gap: 0 !important;
  }

  /* Utility helper to hide elements on mobile */
  .hide-mobile {
    display: none !important;
  }

  /* Prevent Table Header and Cell Wrapping/Breaking */
  .data-table th,
  .data-table td {
    white-space: nowrap !important;
  }

  /* Action Header responsive grid (inputs/selects/buttons stretch full width and share space) */
  .action-header {
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 12px !important;
    width: 100% !important;
  }

  .search-filters {
    display: flex !important;
    flex-direction: row !important;
    flex-wrap: wrap !important;
    gap: 8px !important;
    width: 100% !important;
  }

  .search-filters input,
  .search-filters select {
    flex: 1 1 45% !important; /* 2 items split the row (50% space each), 1 item takes full width */
    min-width: 120px !important;
    width: auto !important;
    box-sizing: border-box !important;
    margin: 0 !important;
  }

  /* Specific overrides for Generated APIs tab on mobile only */
  #api-search {
    flex: 1 1 100% !important;
    width: 100% !important;
  }

  #api-filter-room,
  #api-filter-type {
    flex: 1 1 45% !important;
    width: auto !important;
  }

  .action-header > .btn,
  .action-header > button,
  .action-header .button-group {
    width: 100% !important;
    display: flex !important;
    gap: 8px !important;
    margin: 0 !important;
  }

  .action-header .button-group button,
  .action-header .button-group .btn {
    flex: 1 1 50% !important; /* 2 buttons split the row equally */
    width: 100% !important;
    justify-content: center !important;
    box-sizing: border-box !important;
    margin: 0 !important;
  }

  .action-header > .btn,
  .action-header > button {
    justify-content: center !important;
  }

  /* Prevent entire page horizontal scrolling by isolating grids and cards */
  .layout-container {
    height: 100vh !important;
    height: 100dvh !important;
  }

  .main-content {
    height: 100vh !important;
    height: 100dvh !important;
    max-width: 100% !important;
    overflow-x: hidden !important;
  }

  .stats-grid,
  .health-grid,
  .rooms-grid,
  .settings-grid {
    grid-template-columns: 1fr !important;
    width: 100% !important;
  }

  .form-max-card {
    width: 100% !important;
    max-width: 100% !important;
  }

  /* Full Width Server Actions inside settings */
  .server-actions {
    display: flex !important;
    flex-direction: column !important;
    align-items: stretch !important;
    width: 100% !important;
    gap: 10px !important;
  }

  .server-actions button,
  .server-actions .btn {
    width: 100% !important;
    justify-content: center !important;
    box-sizing: border-box !important;
    margin: 0 !important;
  }

  /* Full Width profile password update button */
  #profile-password-form button,
  #profile-password-form .btn {
    width: 100% !important;
    justify-content: center !important;
    box-sizing: border-box !important;
  }

  /* Restrict User Agent string display space on mobile */
  .ua-text {
    max-width: 130px !important;
  }

  /* SVG Bar chart label: hide on mobile to prevent clutter */
  .bar-label {
    display: none !important;
  }
}

/* Pulsing Status Animation Keyframe */
@keyframes statusPulse {
  0% { transform: scale(0.9); opacity: 0.8; }
  50% { transform: scale(1.2); opacity: 1; box-shadow: 0 0 8px currentColor; }
  100% { transform: scale(0.9); opacity: 0.8; }
}
