:root {
  --bg-color: #121212;
  --text-color: #e0e0e0;
  --card-bg: #232323;
  --card-neutral-bg: var(--card-bg);
  --card-neutral-bg-dark: var(--card-bg-dark, #2e3338);
  --accent-color: #81d4fa;
  --card-bg-light: #2e3338;
  --grow-tab-active: var(--card-bg-dark, rgba(56, 61, 66, 1));
  --accent-color-dark-rgb: 50, 60, 70;
  --error-color: #ef5350;
}

[data-theme="light"] {
  --bg-color: #f5f5f5;
  --text-color: #222;
  --card-bg: #fff;
  --card-neutral-bg: var(--card-bg);
  --card-neutral-bg-dark: var(--card-bg-dark, #f6f6f6);
  --accent-color: #1a73e8;
  --error-color: #d32f2f;
}

/* Base Styles */
body {
  min-height: 100vh;
  margin: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  background: var(--bg-color);
  color: var(--text-color);
  transition: background-color 0.3s, color 0.3s;
}

.theme-switch {
  position: fixed;
  top: 22px;
  right: 80px;
  display: flex;
  align-items: center;
  gap: 8px;
  z-index: 103;
}

.switch {
  width: 44px;
  height: 22px;
  position: relative;
  display: inline-block;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  top: 0; 
  left: 0; 
  right: 0; 
  bottom: 0;
  background: #888;
  transition: .4s;
  border-radius: 22px;
}

.slider:before {
  content: "";
  position: absolute;
  height: 16px;
  width: 16px;
  left: 3px;
  bottom: 3px;
  background: #fff;
  border-radius: 50%;
  transition: .4s;
}

input:checked + .slider {
  background: var(--accent-color);
}

input:checked + .slider:before {
  transform: translateX(22px);
}

/* Header */
h1 {
  font-size: 1.7rem;
  margin: 24px 0 10px 0;
  text-align: center;
  letter-spacing: 1px;
  color: var(--accent-color);
}

/* Profile Bar and Dropdown */
.profile-bar {
  display: flex;
  align-items: center;
  position: absolute;
  top: 16px;
  left: 16px;
  z-index: 100;
  background: transparent;
  border-radius: 14px;
  min-width: 0;
  min-height: 48px;
  outline: none;
}

.profile-displayname-dropdown-group {
  display: flex;
  align-items: center;
  position: relative;
}

.profile-displayname {
  font-weight: 600;
  color: var(--accent-color, #81d4fa);
  font-size: 1.08rem;
  letter-spacing: 0.01em;
  cursor: pointer;
  padding: 2px 8px;
  border-radius: 6px;
  transition: background 0.15s;
  margin-right: 2px;
  user-select: none;
  background: none;
}
.profile-displayname:hover {
  background: rgba(var(--accent-color-rgb, 129,212,250), 0.12);
  color: var(--accent-color, #81d4fa);
}

.profile-dropdown-trigger {
  display: flex;
  align-items: center;
  cursor: pointer;
  padding: 3px 2px 3px 2px;
  border-radius: 4px;
  transition: background 0.15s;
}
.profile-dropdown-trigger:hover {
  background: rgba(var(--accent-color-rgb, 129,212,250), 0.12);
  color: var(--accent-color, #81d4fa);
}

/* Theme-aware SVG icons */
.dropdown-chevron {
  color: var(--accent-color);
}
.themed-icon {
  color: var(--accent-color);
}

.profile-dropdown {
  position: absolute;
  left: 0;
  top: 110%;
  background: var(--card-bg, #333333);
  border-radius: 10px;
  box-shadow: 0 8px 32px #0005;
  min-width: 180px;
  display: none;
  flex-direction: column;
  padding: 10px 0;
  z-index: 1000;
  animation: fadeInDropdown 0.18s;
}
.profile-dropdown.open {
  display: flex;
}
@keyframes fadeInDropdown {
  from { opacity: 0; transform: translateY(-8px);}
  to   { opacity: 1; transform: translateY(0);}
}
.dropdown-username-label {
  padding: 4px 20px 0 20px;
  font-size: 0.86rem;
  color: var(--accent-color-soft);
  letter-spacing: 0.02em;
  font-weight: 500;
}
.dropdown-username {
  padding: 2px 20px 10px 20px;
  font-weight: 600;
  color: var(--accent-color);
  font-size: 1.01rem;
  border-bottom: 1px solid #2226;
  margin-bottom: 6px;
  line-break: anywhere;
}
.dropdown-item {
  padding: 10px 20px;
  color: var(--text-color, #e0e0e0);
  text-decoration: none;
  background: none;
  border: none;
  font-size: 1.01rem;
  text-align: left;
  cursor: pointer;
  width: 100%;
  margin: 3px 0;
  border-radius: 8px;
  box-sizing: border-box;
  display: block;
  transition: background 0.14s, color 0.14s;
}
.dropdown-item:hover {
  background: rgba(var(--accent-color-rgb, 129,212,250), 0.16);
  color: var(--accent-color, #81d4fa);
}
.dropdown-item.logout {
  color: var(--error-color, #ef5350);
}
.dropdown-item.logout:hover {
  background: rgba(var(--error-color-rgb, 239,83,80), 0.18);
  color: var(--error-color, #ef5350);
}

.dropdown-divider {
  height: 1px;
  background: rgba(255, 255, 255, 0.08);
  margin: 6px 18px;
  border-radius: 999px;
}

.profile-circle {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  overflow: hidden;
  background: #222;
  border: 2.5px solid var(--card-bg);
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: center;
}
.profile-circle img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: var(--card-bg, #232323);
  border-radius: 50%;
  display: block;
}

/* Chat Button in Profile Bar */
.profile-chat-btn {
  margin-left: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border: none;
  border-radius: 50%;
  background: var(--card-bg, #232323);
  box-shadow: 0 2px 8px #0003;
  cursor: pointer;
  transition: background 0.18s, box-shadow 0.18s, filter 0.16s;
  outline: none;
  position: relative;
  z-index: 1;
  padding: 0;
}
.profile-chat-btn:hover, .profile-chat-btn:focus {
  background: var(--accent-color, #81d4fa);
  box-shadow: 0 4px 18px #0005;
  filter: brightness(1.13);
}
.profile-chat-btn svg {
  width: 22px;
  height: 22px;
  display: block;
}
.profile-chat-btn svg circle {
  stroke: var(--accent-color, #81d4fa);
  stroke-width: 2.2;
  fill: none;
  transition: stroke 0.18s;
}
.profile-chat-btn svg path {
  stroke: var(--accent-color, #81d4fa);
  stroke-width: 2.1;
  stroke-linecap: round;
  transition: stroke 0.18s;
}
.profile-chat-btn:hover svg circle,
.profile-chat-btn:focus svg circle,
.profile-chat-btn:hover svg path,
.profile-chat-btn:focus svg path {
  stroke: #fff;
}

/* Only one unread badge for chat button */
.unread-badge {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 20px;
  height: 20px;
  background: #e53935;
  color: #fff;
  font-size: 12px;
  font-weight: bold;
  border-radius: 50%;
  border: 2px solid #232323;
  box-shadow: 0 1px 6px 0 rgba(0,0,0,0.14);
  text-align: center;
  pointer-events: none;
  z-index: 20;
  line-height: 20px;
  padding: 0;
  display: none; /* show with JS as needed */
  box-sizing: border-box;
  overflow: hidden;
}
@media (max-width:600px) {
  .unread-badge {
    width: 16px;
    height: 16px;
    font-size: 10px;
    line-height: 16px;
    top: -4px;
    right: -4px;
    border-width: 1.5px;
  }
}

/* Only one unread badge for chatbox list items */
.chatbox-unread-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  background: #e53935;
  color: #fff;
  font-size: 13px;
  font-weight: bold;
  border-radius: 50%;
  border: 2px solid #232323;
  box-shadow: 0 1px 6px 0 rgba(0,0,0,0.14);
  text-align: center;
  line-height: 1;
  margin-left: 8px;
  margin-right: 2px;
  box-sizing: border-box;
  pointer-events: none;
  z-index: 20;
}
.chatbox-unread-badge:empty { display: none; }

@media (max-width:600px) {
  .chatbox-unread-badge {
    width: 16px;
    height: 16px;
    font-size: 11px;
    border-width: 1.5px;
    margin-left: 6px;
  }
}

/* Section Titles */
.section-title {
  color: var(--accent-color);
  margin: 10px 0 4px 0;
  width: 100%;
  max-width: 680px;
  text-align: left;
  font-size: 1.08rem;
  display: flex;
  align-items: center;
  cursor: pointer;
  padding: 0 3px;
}

.section-title .dropdown-icon {
  margin-left: 7px;
  font-size: 0.9em;
  transition: transform 0.2s;
}

.section-title.collapsed .dropdown-icon {
  transform: rotate(-90deg);
}

/* Edit/Delete Icons */
.section-title .edit-icon,
.section-title .delete-icon {
  opacity: 0;
  transition: opacity 0.18s;
  pointer-events: auto;
}

.section-title:hover .edit-icon,
.section-title:hover .delete-icon,
.section-title .edit-icon:hover,
.section-title .delete-icon:hover {
  opacity: 1;
}

.section-title .edit-icon::before {
  content: "";
  display: block;
  width: 14px;
  height: 14px;
  background-color: var(--accent-color);
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7'%3E%3C/path%3E%3Cpath d='M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z'%3E%3C/path%3E%3C/svg%3E") no-repeat center;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7'%3E%3C/path%3E%3Cpath d='M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z'%3E%3C/path%3E%3C/svg%3E") no-repeat center;
}

.section-title .delete-icon::before {
  content: "";
  display: block;
  width: 14px;
  height: 14px;
  background-color: var(--error-color);
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M3 6h18'%3E%3C/path%3E%3Cpath d='M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2'%3E%3C/path%3E%3C/svg%3E") no-repeat center;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M3 6h18'%3E%3C/path%3E%3Cpath d='M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2'%3E%3C/path%3E%3C/svg%3E") no-repeat center;
}

/* Sensor Layout */
.sensor-row {
  display: flex;
  justify-content: space-between;
  width: 100%;
  max-width: 680px;
  margin-bottom: 18px;
  gap: 10px;
  transition: all 0.3s;
}

.sensor-row.collapsed {
  opacity: 0;
  height: 0;
  margin-bottom: 0;
  overflow: hidden;
}

.sensor-box {
  background: var(--card-bg);
  border-radius: 12px;
  padding: 0.7rem 0.4rem;
  text-align: center;
  flex: 1;
  min-width: 0;
  box-shadow: 0 2px 6px rgba(0,0,0,0.15);
  border: 1px solid rgba(0,0,0,0.07);
  position: relative;
  transition: all 0.2s;
  font-size: 0.97rem;
  cursor: pointer;
}

.sensor-box:hover {
  transform: translateY(-1.5px) scale(1.03);
  box-shadow: 0 4px 12px rgba(0,0,0,0.16);
}

.sensor-title {
  font-weight: 600;
  font-size: 1.04rem;
  margin-bottom: 0.1rem;
  color: var(--accent-color);
}

.sensor-value {
  font-size: 1.13rem;
  font-weight: 500;
  color: var(--text-color);
  min-height: 30px;
  margin-bottom: 0;
}

.error-message {
  color: var(--error-color);
  margin-top: 0.7rem;
  text-align: center;
  width: 100%;
  font-size: 0.98rem;
}

/* Graph Viewer - removed */

.close-btn {
  position: absolute;
  top: 14px;
  right: 14px;
  background: none;
  border: none;
  color: #fff;
  font-size: 1.30rem;
  cursor: pointer;
}

/* Modals */
.edit-modal, 
.add-section-modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,0.6);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 2000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}

.edit-modal.active, 
.add-section-modal.active {
  opacity: 1;
  pointer-events: all;
}

.edit-content, 
.add-section-content {
  background: var(--card-bg);
  padding: 12px 16px;
  border-radius: 8px;
  width: 90%;
  max-width: 320px;
  box-sizing: border-box;
  font-size: 1rem;
}

.edit-content input, 
.add-section-content input {
  width: 100%;
  padding: 7px 9px;
  margin-bottom: 10px;
  background: var(--bg-color);
  color: var(--text-color);
  border: 1px solid var(--accent-color);
  border-radius: 4px;
  font-size: 1rem;
  box-sizing: border-box;
}

.edit-actions, 
.add-section-actions {
  display: flex;
  justify-content: flex-end;
  gap: 6px;
}

.edit-actions button, 
.add-section-actions button {
  padding: 5px 14px;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.98rem;
}

.edit-actions .save-btn, 
.add-section-actions .create-btn {
  background: var(--accent-color);
  color: #fff;
}

.edit-actions .cancel-btn, 
.add-section-actions .cancel-btn {
  background: #888;
  color: #fff;
}

/* Add Section Button */
.add-section {
  width: 100%;
  max-width: 680px;
  display: flex;
  justify-content: center;
  margin-top: 10px;
}

.add-section-btn {
  background: var(--accent-color);
  color: #fff;
  border: none;
  border-radius: 50%;
  width: 32px;
  height: 32px;
  font-size: 1.25rem;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.18s;
}

.add-section-btn:hover {
  transform: scale(1.10);
}

/* Drag and Drop */
.noselect, 
.noselect * {
  user-select: none !important;
  -webkit-user-select: none !important;
  -ms-user-select: none !important;
  -moz-user-select: none !important;
  cursor: grab !important;
}

.sensor-box.dragging {
  opacity: 0.4;
  cursor: grabbing !important;
}

.drop-ghost.active {
  outline: 2px dashed var(--accent-color);
  background: rgba(129,212,250,0.18);
  border-radius: 8px;
  min-height: 48px;
  margin: 4px 0;
  z-index: 9999;
  position: fixed;
  pointer-events: none;
  transition: all 0.08s;
}

/* Hamburger menu button (top right) */
.menu-btn {
  position: fixed;
  top: 22px;
  right: 24px;
  width: 48px;
  height: 48px;
  background: #23262c;
  border: none;
  border-radius: 50%;
  box-shadow: 0 2px 10px #0003;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 102;
  transition: background 0.2s;
}
.menu-btn:hover,
.menu-btn:focus {
  background: #323846;
}
.menu-icon {
  width: 28px;
  height: 28px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 5px;
}
.menu-icon-bar {
  width: 24px;
  height: 3px;
  border-radius: 2px;
  background: #cdd1dd;
  transition: all 0.3s;
}

/* Sidebar and overlay */
.sidebar-overlay {
  position: fixed;
  inset: 0;
  background: rgba(30,32,40,0.3);
  z-index: 101;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
}
.sidebar-overlay.open {
  opacity: 1;
  pointer-events: auto;
}
.sidebar {
  position: fixed;
  top: 0;
  right: 0;
  height: 100vh;
  width: 290px;
  background: rgba(var(--accent-color-dark-rgb, var(--accent-color-rgb, 129,212,250)), 0.12);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  box-shadow: -2px 0 24px #0005;
  padding: 2.5rem 1.7rem 1.5rem 1.7rem;
  display: flex;
  flex-direction: column;
  gap: 2rem;
  z-index: 110;
  transform: translateX(100%);
  transition: transform 0.35s cubic-bezier(0.75,0,0.25,1);
}
.sidebar.open {
  transform: translateX(0);
}
.sidebar .sidebar-title {
  font-size: 1.35rem;
  font-weight: bold;
  letter-spacing: 0.06em;
  color: var(--accent-color);
  margin-bottom: 0.5rem;
}
.sidebar nav {
  display: flex;
  flex-direction: column;
  gap: 1.2rem;
}
.sidebar nav a {
  color: #d6dcf0;
  text-decoration: none;
  font-size: 1.07rem;
  padding: 0.4rem 0.8rem;
  border-radius: 7px;
  transition: background 0.17s, color 0.17s;
  font-weight: 500;
}
.sidebar nav a:hover,
.sidebar nav a:focus {
  background: rgba(var(--accent-color-rgb), 0.2);
  color: var(--accent-color);
}
.sidebar .sidebar-close {
  position: absolute;
  top: 18px;
  right: 20px;
  background: none;
  border: none;
  color: var(--accent-color-soft);
  font-size: 2rem;
  cursor: pointer;
  padding: 0;
  z-index: 120;
  transition: color 0.2s;
}
.sidebar .sidebar-close:hover {
  color: var(--accent-color);
}

/* Modern Textbox Style (from ESP32.html) */
.modern-textbox {
  width: 100%;
  padding: 0.5em 0.6em;
  padding-right: 2em; /* More right padding for unit badges */
  border: none;
  border-radius: 7px;
  background: var(--card-bg, #232323);
  color: var(--text-color, #e0e0e0);
  font-size: 1.12em;
  box-shadow: 0 2px 8px #0002;
  outline: none;
  transition: box-shadow 0.2s, border 0.2s, background 0.2s;
  border: 1.5px solid var(--accent-color, #81d4fa);
  margin-bottom: 18px;
  box-sizing: border-box;
}
.modern-textbox:focus {
  background: var(--bg-color, #181c24);
  border-color: #fff176;
  box-shadow: 0 0 0 3px rgba(var(--accent-color-rgb), 0.35);
}

/* Responsive Design */
@media (max-width: 800px) {
  .sensor-row, 
  .add-section, 
  h1, 
  .section-title {
    max-width: 98vw;
  }
}

@media (max-width: 600px) {
  .sensor-row {
    flex-direction: column;
    gap: 8px;
  }
  
  h1 {
    font-size: 1.25rem;
  }
  
  .section-title {
    font-size: 0.95rem;
  }
  
  .add-section {
    margin-top: 8px;
  }

  .profile-bar { 
    top: 10px; 
    left: 10px; 
  }
  .profile-circle { 
    width: 32px; 
    height: 32px; 
  }
  .profile-displayname { 
    font-size: 1rem; 
  }
  .profile-dropdown { 
    min-width: 140px; 
  }
  .profile-chat-btn {
    width: 31px;
    height: 31px;
    margin-left: 7px;
  }
  .profile-chat-btn svg {
    width: 17px;
    height: 17px;
  }
  .unread-badge {
    width: 16px;
    height: 16px;
    font-size: 10px;
    line-height: 16px;
    top: -4px;
    right: -4px;
    border-width: 1.5px;
  }
  #chat-widget {
    width: 99vw;
    right: 0;
    bottom: 0;
    border-radius: 0;
    min-width: 0;
    max-width: 100vw;
  }
  .chatbox-unread-badge {
    width: 16px;
    height: 16px;
    font-size: 11px;
    border-width: 1.5px;
    margin-left: 6px;
  }
}

@media (max-width: 430px) {
  .sidebar { 
    width: 88vw; 
    min-width: 140px; 
    max-width: 99vw;
  }
}

.section-title.no-delete .delete-icon {
  display: none !important;
}

#chat-widget {
  position: fixed;
  bottom: 24px;
  left: 24px;
  right: auto;
  width: 390px;
  background: var(--chat-widget-bg-open, #2b313d);
  color: #fff;
  border-radius: 13px;
  box-shadow: 0 2px 18px #0007;
  z-index: 10000;
  font-size: 1em;
  display: flex;
  flex-direction: column;
  min-height: 400px;
  max-height: 85vh;
  backdrop-filter: var(--chat-panel-blur, blur(14px));
  -webkit-backdrop-filter: var(--chat-panel-blur, blur(14px));
  overflow: hidden;
}
#chat-header {
  background: var(--chat-header-bg, #2b313d);
  padding: 11px 22px 11px 20px;
  border-radius: 13px 13px 0 0;
  font-weight: bold;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--chat-top-border, rgba(255, 255, 255, 0.06));
}
#chat-header-title {
  font-size: 1.16em;
}
#chat-header-title {
  color: var(--accent-color, #81d4fa);
}
#chat-close {
  cursor: pointer;
  font-size: 1.5em;
}
#chat-close {
  color: var(--text-color);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 6px;
  border-radius: 8px;
  transition: color 120ms ease, background 120ms ease, transform 120ms ease;
}
#chat-close:hover {
  color: var(--error-color, #ef5350);
  transform: scale(1.03);
}
/* Back button (left of convo header) styling */
.chat-back-btn {
  background: none;
  border: none;
  color: var(--accent-color, #81d4fa);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 6px 8px;
  margin-right: 8px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 120ms ease, transform 120ms ease, color 120ms ease;
}
.chat-back-btn .chat-back-icon { width: 28px; height: 28px; }
.chat-back-btn:hover {
  background: rgba(var(--accent-color-rgb, 129,212,250), 0.08);
  transform: translateX(-2px);
}
#chat-convo-list {
  flex: 1 1 auto;
  min-height: 160px;
  max-height: 580px;
  overflow-y: auto;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0;
  background: var(--chat-panel-bg, rgba(var(--accent-color-rgb, 129, 212, 250), 0.22));
  border-radius: 0 0 13px 13px;
}
#chat-convo-list,
#chat-convo-box,
#chat-messages,
.chat-user-search-results,
.chat-embed {
  backdrop-filter: var(--chat-panel-blur, blur(14px));
  -webkit-backdrop-filter: var(--chat-panel-blur, blur(14px));
}
.chat-convo-item {
  display: flex;
  align-items: center;
  gap: 15px;
  padding: 16px 22px;
  cursor: pointer;
  transition: background 0.16s ease;
  background: transparent;
  border-bottom: 1px solid var(--chat-item-border, rgba(var(--accent-color-rgb, 129, 212, 250), 0.28));
}
.chat-convo-item:last-child {
  border-bottom: none;
}
.chat-convo-item:hover,
.chat-convo-item.active {
  background: var(--chat-item-hover-bg, rgba(var(--accent-color-rgb, 129, 212, 250), 0.22));
}
.chat-convo-item img {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--chat-avatar-bg, var(--card-bg, #232323));
  object-fit: cover;
  border: 2px solid var(--chat-item-border, rgba(var(--accent-color-rgb, 129, 212, 250), 0.32));
}
.chat-convo-username {
  font-size: 1.08em;
  font-weight: 500;
  color: var(--accent-color, #81d4fa);
}
#chat-convo-box {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  height: 100%;
  background: var(--chat-panel-bg, rgba(var(--accent-color-rgb, 129, 212, 250), 0.24));
  border-radius: 0 0 13px 13px;
  overflow: hidden;
}
#chat-convo-profile {
  display: flex;
  align-items: center;
  gap: 13px;
  background: var(--chat-convo-profile-bg, #2b303d);
  padding: 10px 18px;
  border-bottom: 1px solid var(--chat-top-border, rgba(255, 255, 255, 0.06));
}
#chat-convo-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--chat-avatar-bg, var(--card-bg, #232323));
  object-fit: cover;
  border: 2px solid var(--chat-item-border, rgba(var(--accent-color-rgb, 129, 212, 250), 0.32));
}
#chat-convo-username {
  font-size: 1.07em;
  font-weight: 500;
  color: var(--accent-color, #81d4fa);
}
#chat-messages {
  flex: 1 1 auto;
  min-height: 120px;
  max-height: 340px;
  overflow-y: auto;
  padding: 12px 18px;
  font-size: 1em;
  background: var(--chat-messages-bg, rgba(var(--accent-color-rgb, 129, 212, 250), 0.18));
  margin-bottom: 0;
  border-bottom: 1px solid var(--chat-messages-border, rgba(var(--accent-color-rgb, 129, 212, 250), 0.22));
}
#chat-form {
  display: flex;
  border-top: 1px solid var(--chat-form-border, rgba(var(--accent-color-rgb, 129, 212, 250), 0.26));
  background: var(--chat-form-bg, #2c303d);
  border-radius: 0 0 13px 13px;
  align-items: stretch;
  min-height: 68px;
}
#chat-input {
  flex: 1;
  border: none;
  outline: none;
  background: var(--chat-input-bg, #2c303d);
  color: var(--chat-input-color, #fff);
  padding: 16px 20px;
  font-size: 1em;
  border-radius: 0 0 0 13px;
  border-right: 1px solid var(--chat-input-border, rgba(var(--accent-color-rgb, 129, 212, 250), 0.32));
}
#chat-input::placeholder {
  color: rgba(244, 247, 254, 0.7);
}

.chat-image-label {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 6px;
  cursor: pointer;
  color: var(--accent-color, #81d4fa);
  transition: background 0.16s ease, color 0.16s ease;
  border-left: 1px solid var(--chat-input-border, rgba(var(--accent-color-rgb, 129, 212, 250), 0.32));
  height: 100%;
  min-width: 72px;
  align-self: stretch;
  box-sizing: border-box;
  line-height: 0;
}
.chat-image-label svg {
  width: auto;
  height: calc(100% - 2px);
  max-height: 66px;
  display: block;
}
.chat-image-label:hover {
  background: var(--chat-item-hover-bg, rgba(var(--accent-color-rgb, 129, 212, 250), 0.18));
  color: #fff;
}
#chat-form button {
  background: var(--accent-color, #81d4fa);
  border: none;
  color: #222;
  padding: 0 26px;
  font-weight: bold;
  border-radius: 0 0 13px 0;
  cursor: pointer;
  font-size: 1em;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 68px;
}
@media (max-width:700px) {
  #chat-widget {
    left: 0;
    width: 98vw;
    max-width: 100vw;
    border-radius: 0;
  }
  .chat-image-label { min-width: 68px; padding: 0 12px; }
  .chat-image-label svg { width: auto; height: 100%; max-height: 44px; }
}

#chat-add-btn:hover {
  background: var(--chat-item-hover-bg, rgba(var(--accent-color-rgb, 129, 212, 250), 0.18));
}

#chat-user-search-results {
  display: flex;
  flex-direction: column;
  gap: 0;
  padding: 0;
  background: var(--chat-panel-bg, rgba(var(--accent-color-rgb, 129, 212, 250), 0.22));
  border-radius: 0 0 13px 13px;
  border-top: 2px solid var(--chat-divider-accent, var(--accent-color, #81d4fa));
  flex: 1 1 auto;
}
#chat-user-search-results .chat-convo-item {
  margin: 0;
}
#chat-convo-list,
#chat-messages,
.chat-user-search-results {
  scrollbar-width: thin;
  scrollbar-color: rgba(182, 190, 204, 0.6) transparent;
}
#chat-convo-list::-webkit-scrollbar,
#chat-messages::-webkit-scrollbar,
.chat-user-search-results::-webkit-scrollbar {
  width: 10px;
}
#chat-convo-list::-webkit-scrollbar-track,
#chat-messages::-webkit-scrollbar-track,
.chat-user-search-results::-webkit-scrollbar-track {
  background: transparent;
}
#chat-convo-list::-webkit-scrollbar-thumb,
#chat-messages::-webkit-scrollbar-thumb,
.chat-user-search-results::-webkit-scrollbar-thumb {
  background: rgba(182, 190, 204, 0.62);
  border-radius: 999px;
  border: 2px solid transparent;
  background-clip: padding-box;
}
#chat-convo-list::-webkit-scrollbar-corner,
#chat-messages::-webkit-scrollbar-corner,
.chat-user-search-results::-webkit-scrollbar-corner {
  background: transparent;
}
.chat-message {
  display: flex;
  margin: 8px 0;
  width: 100%;
}

.chat-message.sent {
  justify-content: flex-end;
}

.chat-message.received {
  justify-content: flex-start;
}

.bubble {
  max-width: 70%;
  padding: 10px 14px;
  border-radius: 20px;
  background: var(--chat-sent-bg, var(--accent-color, var(--accent-color, #007aff)));
  color: var(--chat-sent-color, #fff);
  font-size: 15px;
  word-break: break-word;
  box-shadow: 0 1px 4px rgba(0,0,0,0.07);
}

.chat-message.received .bubble {
  background: var(--chat-received-bg, var(--card-bg-light, #e5e5ea));
  color: var(--chat-received-color, #222);
  border-bottom-left-radius: 4px;
}

.chat-message.sent .bubble {
  background: var(--chat-sent-bg, var(--accent-color, #007aff));
  color: var(--chat-sent-color, #fff);
  border-bottom-right-radius: 4px;
}

#chat-search-section {
  background: var(--chat-search-bg, #2b303d);
  padding: 14px 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  border-bottom: none;
}
.chat-search-form {
  margin: 0;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: stretch;
}
#chat-user-search-input {
  width: 100%;
  margin: 0;
  background: var(--chat-search-input-bg, #2f3442);
  border: 1.5px solid var(--chat-search-input-border, rgba(255, 255, 255, 0.1));
  border-radius: 10px;
  color: var(--text-color, #e0e0e0);
  font-size: 1em;
  padding: 0.65em 0.85em;
  box-shadow: 0 2px 8px #0002;
  outline: none;
  transition: box-shadow 0.2s, border 0.2s, background 0.2s;
  box-sizing: border-box;
}
#chat-user-search-input::placeholder {
  color: var(--text-muted, #aeb7c5);
}
#chat-user-search-input:focus {
  background: var(--bg-color, #181c24);
  border-color: var(--accent-color, #81d4fa);
  box-shadow: 0 0 0 3px rgba(var(--accent-color-rgb, 129, 212, 250), 0.28);
}

.chat-user-search-results {
  flex: 1 1 0;
  overflow-y: auto;
  width: 100%;
  background: var(--chat-panel-bg, rgba(var(--accent-color-rgb, 129, 212, 250), 0.22));
  border: 1px solid var(--chat-panel-border, rgba(var(--accent-color-rgb, 129, 212, 250), 0.28));
  border-radius: 12px;
  padding: 6px 0;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.06);
}

#chat-convo-box .chat-back-btn {
  margin-left: 0;
  margin-right: 8px;
  background: none;
  border: none;
  color: var(--accent-color, #81d4fa);
  font-size: 1.1em;
  cursor: pointer;
  padding: 6px 8px;
  border-radius: 8px;
}
.chat-embed {
  margin: 8px 0;
  border-radius: 10px;
  overflow: hidden;
  background: var(--chat-embed-bg, rgba(var(--accent-color-rgb, 129, 212, 250), 0.2));
}
.twitter-tweet {
  margin: 8px 0 !important;
}

/* Scoped neutralization for Grow Info: when the Grow Info big box is active
   override the accent-related CSS variables in the subtree so any descendant
   using "rgba(var(--accent-color-rgb)...)" will get a neutral (grey) value.
   This prevents the bigbox or its children from showing a tinted overlay
   when the user's accent color is bright (e.g., red). */
.grow-bigbox.growinfo-active {
  /* Ensure the container uses the expected neutral background */
  --grow-tab-active: var(--card-neutral-bg-dark, var(--card-bg-dark));
  --grow-tab-bg: var(--card-neutral-bg, var(--card-bg));
  --grow-tab-hover: var(--card-neutral-bg-dark, var(--card-bg-dark));
  --live-card-bg: var(--card-neutral-bg, var(--card-bg));
  --live-card-hover: var(--card-neutral-bg-dark, var(--card-bg-dark));
  /* Replace accent RGB variables inside the bigbox to stop descendant rgba(...) from tinting.
    Do not override --accent-color so buttons that intentionally use the accent color remain accent. */
  /* Pick a neutral RGB (a dark gray near the card bg) */
  --accent-color-rgb: 40, 44, 50;
  --accent-color-dark-rgb: 26, 28, 34;
  /* Soft and medium variants should be neutral as well */
  --accent-color-soft: rgba(40,44,50,0.06);
  --accent-color-medium: rgba(40,44,50,0.12);
  --accent-color-dark: rgba(40,44,50,0.16);
  /* Prevent blend-mode and backdrop or background blending into the neutral background */
  isolation: isolate !important;
  background-blend-mode: normal !important;
}

/* Stronger neutralization rules for children of the Grow Info active box.
   These prevent any descendant using accent colors, semi-transparent overlays,
   background images, or box-shadows from tinting the main neutral background.
   Keep the primary CTAs accent-colored (gi-btn and add-section-btn).
*/
.grow-bigbox.growinfo-active *:not(.gi-btn):not(.add-section-btn):not(.gi-btn *):not(.gi-input):not(.gi-input *):not(.gi-input-select):not(.gi-input-select *):not(.gi-textarea):not(.gi-textarea *) {
  /* Replace background images and direct background colors */
  background-image: none !important;
  background: var(--card-neutral-bg, var(--card-bg)) !important;
  /* Keep text color readable */
  color: var(--text-color) !important;
  /* Remove any overlayish shadows or outlines that might use accent colors */
  box-shadow: none !important;
  outline: none !important;
  /* Prevent backdrop or filter blend modes affecting colors */
  filter: none !important;
  backdrop-filter: none !important;
  -webkit-backdrop-filter: none !important;
  mix-blend-mode: normal !important;
  /* Neutralize borders */
  border-color: rgba(255,255,255,0.04) !important;
}

/* Exceptions: allow gi-btn and add-section-btn to retain accent color */
.grow-bigbox.growinfo-active .gi-btn,
.grow-bigbox.growinfo-active .add-section-btn {
  background: var(--accent-color, #81d4fa) !important;
  color: #fff !important;
  box-shadow: 0 2px 10px #0002 !important;
}

/* Disable any pseudo element backgrounds inside growinfo that might still overlay */
.grow-bigbox.growinfo-active *::before,
.grow-bigbox.growinfo-active *::after {
  background-image: none !important;
  background: transparent !important;
  box-shadow: none !important;
}

/* Keep subtle neutral focus on inputs (override the global none rule above) */
.grow-bigbox.growinfo-active .gi-input:focus,
.grow-bigbox.growinfo-active .gi-input-select:focus,
.grow-bigbox.growinfo-active .gi-textarea:focus {
  box-shadow: 0 0 0 3px rgba(0,0,0,0.12) !important;
}

/* Global modal close (X) used across modals */
.modal-close {
  position: absolute;
  top: 8px;
  right: 12px;
  background: transparent;
  border: none;
  color: #fff;
  font-size: 20px;
  line-height: 1;
  padding: 6px;
  border-radius: 8px;
  cursor: pointer;
  transition: color 120ms ease, transform 120ms ease, background 120ms ease;
}
.modal-close:hover { color: var(--error-color, #ef5350); transform: scale(1.05); }

/* Full width create button for standardized modals */
.create-btn.full-width, .modal .create-btn.full-width, .modal-bg .create-btn.full-width { width: 100%; display:block; padding: 12px 14px; border-radius: 8px; }

/* Global modal background / container used across pages (modal-bg vs .modal fallback) */
.modal-bg, .modal { position: fixed; inset: 0; width: 100vw; height: 100vh; display: none; align-items: center; justify-content: center; z-index: 10000; }
.modal-bg.active, .modal.active { display: flex; }
.modal-bg { background: rgba(20,25,34,0.64); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); }
.modal { background: rgba(0,0,0,0.36); }

/* Default modal content box */
.modal-content { background: var(--card-bg, #232323); border-radius: 12px; box-shadow: 0 8px 40px #0008; padding: 28px 28px 22px 28px; min-width: 260px; max-width: 96vw; position: relative; display: flex; flex-direction: column; gap: 10px; }
.modal-content .modal-actions { margin-top: 6px; display: flex; gap: 8px; justify-content: flex-end; }

/* Global create button styles (primary CTA). Applied site-wide so modal CTAs, copy buttons, etc. default to accent color */
.create-btn {
  background: var(--accent-color);
  color: #fff;
  border: none;
  cursor: pointer;
  padding: 9px 12px;
  border-radius: 8px;
  font-weight: 600;
  transition: background 120ms ease, transform 120ms ease, box-shadow 120ms ease;
}
.create-btn:hover, .create-btn:focus {
  background: var(--accent-color-medium, #52b8f7);
  transform: translateY(-1px);
  box-shadow: 0 6px 18px rgba(var(--accent-color-rgb), 0.18);
}