:root {
  /* Needed for light-dark() to work */
  color-scheme: light dark;

  /* Base colors */
  --mg-color-dark: hsl(255deg 0% 15%);
  --mg-color-light: hsl(255deg 0% 95%);
  --mg-color-primary: #50a367;
  --mg-control-radius: 1rem;
  --mg-input-radius: 1rem;
  --mg-color-red: #dc3545;
  --mg-color-orange: #fd7e14;
  --mg-color-blue: #007bff;
  --mg-color-green: #50a367;

  /* Gray scale (for dark theme) */
  --mg-color-secondary: #e9ecef;
  --mg-color-tertiary: #adb5bd;
  --mg-color-quaternary: #495057;
  --mg-color-quinary: #343a40;
  --mg-color-initial: #212529;
}

/* ========================================
   Custom Components (replacing Mg+ CSS)
   ======================================== */

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  border-radius: var(--mg-control-radius);
  border: 1px solid var(--mg-color-quaternary);
  background: transparent;
  color: var(--mg-color-secondary);
  cursor: pointer;
  transition: all 0.2s ease;
  font-size: 1rem;
}

.btn:hover {
  background: var(--mg-color-quinary);
}

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

.btn-primary:hover {
  opacity: 0.9;
}

.btn-sm {
  padding: 0.25rem 0.75rem;
  font-size: 0.875rem;
}

.btn-danger {
  background: var(--mg-color-red);
  border-color: var(--mg-color-red);
  color: white;
}

.btn-danger:hover {
  opacity: 0.9;
}

/* Input Fields */
.input-field {
  width: 100%;
  padding: 0.75rem 1rem;
  border-radius: var(--mg-control-radius);
  border: 1px solid var(--mg-color-quaternary);
  background: var(--mg-color-initial);
  color: var(--mg-color-secondary);
  font-size: 1rem;
  transition: border-color 0.2s ease;
}

.input-field:focus {
  outline: none;
  border-color: var(--mg-color-primary);
}

.input-field::placeholder {
  color: var(--mg-color-tertiary);
}

/* Toggle Switch */
.toggle-label {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  user-select: none;
}

.toggle-checkbox {
  display: none;
}

.toggle-switch {
  position: relative;
  width: 44px;
  height: 24px;
  background: var(--mg-color-quaternary);
  border-radius: 12px;
  transition: background 0.2s ease;
}

.toggle-switch::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 20px;
  height: 20px;
  background: white;
  border-radius: 50%;
  transition: transform 0.2s ease;
}

.toggle-checkbox:checked + .toggle-switch {
  background: var(--mg-color-primary);
}

.toggle-checkbox:checked + .toggle-switch::after {
  transform: translateX(20px);
}

/* Modal Overlay */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 1rem;
}

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

.modal-content {
  position: relative;
  background: var(--mg-color-initial);
  border-radius: var(--mg-control-radius);
  max-width: 90vw;
  max-height: 90vh;
  overflow-y: auto;
}

/* Tables */
.table--responsive {
  width: 100%;
  border-collapse: collapse;
}

.table--responsive th,
.table--responsive td {
  padding: 0.75rem 1rem;
  text-align: left;
  border-bottom: 1px solid var(--mg-color-quaternary);
}

.table--responsive th {
  background: var(--mg-color-quinary);
  font-weight: bold;
}

.table--responsive tr:hover {
  background: var(--mg-color-quinary);
}

/* Global box-sizing */
*,
*::before,
*::after {
  box-sizing: border-box;
}

/* For desktop: */

html,
body {
  height: 100%;
}

html * {
  transition: background 0.3s, color 0.3s;
}

.hidden-ux {
  visibility: hidden;
}
.main {
  height: 100%;
}

.main:has(.login-form) {
  min-height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
}

.wrapper {
  min-height: 100%;
  display: grid;
  grid-template-rows: auto 1fr auto;
}

.wrapper > header {
  width: 100%;
  display: flex;
  align-items: center;
}

.logo-view {
  flex-grow: 1;
}

#header-nav {
  font-size: 120%;
}

.mg-nav li {
  padding: 0.75rem;
}


.wrapper > footer {
  padding: 1rem;
}

.logo {
  width: 8rem;
}

.logo-view a > img,
.logo-view a > span {
  vertical-align: middle;
  font-size: 4rem;
  color: var(--mg-color-green);
}

.burger {
  cursor: pointer;
  background: none;
  border: none;
  color: inherit;
}

/* Node Grid Layout */
.node-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 1rem;
  margin: 1.5rem 0;
}

/* Ensure all grid items have equal width */
.node-grid > * {
  min-width: 0;
}

.node-grid .loading-message,
.node-grid .no-nodes-message,
.node-grid .error-message {
  grid-column: 1 / -1;
  text-align: center;
  padding: 2rem;
  font-style: italic;
  color: var(--mg-color-tertiary);
}

.node-grid .error-message {
  color: var(--mg-color-red);
}

@media only screen and (max-width: 640px) {
  .node-grid {
    grid-template-columns: 1fr;
  }
}

/* Node Card Styling */
.node-card {
  background-color: var(--node-color-bg, var(--mg-color-quinary));
  border-color: var(--node-color, var(--mg-color-quaternary));
  padding: 1rem;
  transition: all 0.2s ease;
}

.node-card:hover {
  box-shadow: 0 4px 12px light-dark(rgba(0, 0, 0, 0.15), rgba(0, 0, 0, 0.4));
  transform: translateY(-2px);
}

/* Node Header */
.node-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.75rem;
}

.node-header-left {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex: 1;
  min-width: 0;
}

.node-badge {
  background-color: var(--node-color, var(--mg-color-primary));
  color: white;
  padding: 0.4rem 0.875rem;
  border-radius: 0.5rem;
  font-weight: bold;
  flex-shrink: 0;
}

.node-name {
  font-size: 1em;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
  flex: 1;
}

/* Node Topic */
.node-topic {
  color: var(--mg-color-tertiary);
  margin-bottom: 0.75rem;
}

.node-topic code {
  background: var(--mg-color-quinary);
  padding: 0.15rem 0.5rem;
  border-radius: 0.25rem;
  font-size: 0.85rem;
}

/* Status Badges */
.node-status-row {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.status-badge {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  border-radius: 0.5rem;
  font-weight: 500;
  flex: 1;
  justify-content: center;
  font-size: 0.85em;
}


.status-badge-success {
  background-color: color-mix(in srgb, var(--mg-color-green) 15%, transparent);
  color: var(--mg-color-green);
}

.status-badge-error {
  background-color: color-mix(in srgb, var(--mg-color-red) 15%, transparent);
  color: var(--mg-color-red);
}

.status-badge-inactive {
  background-color: var(--mg-color-quinary);
  color: var(--mg-color-quaternary);
}

.status-badge-clickable {
  cursor: pointer;
  transition: all 0.2s ease;
}

.status-badge-clickable:hover {
  opacity: 0.8;
  transform: scale(1.02);
}

/* Node Info Row */
.node-info-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--mg-color-quinary);
  color: var(--mg-color-tertiary);
  font-size: 0.75em;
}

.node-info-text {
  flex: 1;
  text-align: center;
}

.node-info-text:first-child {
  text-align: left;
}

.node-info-text:last-child {
  text-align: right;
}

/* Validation Errors Modal */
.validation-modal-content {
  max-width: 600px;
  padding: 2rem;
}

.validation-modal-content h3 {
  color: var(--mg-color-primary);
  margin-bottom: 1.5rem;
}

.validation-errors-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.validation-errors-list li {
  padding: 0.75rem 1rem;
  margin-bottom: 0.75rem;
  background: color-mix(in srgb, var(--mg-color-red) 10%, transparent);
  border-left: 3px solid var(--mg-color-red);
  border-radius: 0.25rem;
  color: var(--mg-color-secondary);
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
}

.validation-errors-list li i {
  color: var(--mg-color-red);
  margin-top: 0.2rem;
  flex-shrink: 0;
}

.validation-success {
  padding: 1rem;
  background: color-mix(in srgb, var(--mg-color-green) 10%, transparent);
  border-left: 3px solid var(--mg-color-green);
  border-radius: 0.25rem;
  color: var(--mg-color-green);
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-weight: 500;
}

.validation-success i {
  font-size: 1.25rem;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 1.5rem;
  padding-top: 1rem;
  border-top: 1px solid var(--mg-color-quinary);
}

/* Onboarding Modal Styles */
.onboarding-content {
  max-width: 900px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 2rem;
}

/* Wizard Styles */
.wizard-header {
  margin-bottom: 1rem;
}

.wizard-header h2 {
  margin-top: 0.5rem;
  margin-bottom: 0.5rem;
  color: var(--mg-color-primary);
}

.wizard-progress {
  margin-bottom: 2rem;
}

.wizard-steps {
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: relative;
  margin-bottom: 1rem;
}

.wizard-step {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  flex: 1;
  position: relative;
}

.step-circle {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--mg-color-quinary);
  border: 2px solid var(--mg-color-quinary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
  color: var(--mg-color-tertiary);
  transition: all 0.3s ease;
  z-index: 2;
  position: relative;
}

.wizard-step.active .step-circle {
  background: var(--mg-color-primary);
  border-color: var(--mg-color-primary);
  color: white;
  transform: scale(1.1);
}

.wizard-step.completed .step-circle {
  background: var(--mg-color-green);
  border-color: var(--mg-color-green);
  color: white;
}

.wizard-step.completed .step-circle::after {
  content: '✓';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 1.2rem;
}

.wizard-step.completed .step-circle {
  font-size: 0;
}

.step-label {
  font-size: 0.9rem;
  color: var(--mg-color-tertiary);
  text-align: center;
  font-weight: 500;
}

.wizard-step.active .step-label {
  color: var(--mg-color-primary);
  font-weight: bold;
}

.wizard-step.completed .step-label {
  color: var(--mg-color-green);
}

.progress-bar-container {
  width: 100%;
  height: 4px;
  background: var(--mg-color-quinary);
  border-radius: 2px;
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  background: var(--mg-color-primary);
  transition: width 0.3s ease;
  width: 0%;
}

.wizard-body {
  min-height: 300px;
  margin: 2rem 0;
  font-size: 0.9375rem;
}

.wizard-step-content {
  display: none;
  animation: fadeIn 0.3s ease-in;
}

.wizard-step-content.active {
  display: block;
}

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

.wizard-navigation {
  border-top: 1px solid var(--mg-color-quinary);
  padding-top: 1rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-close {
  position: absolute;
  top: 1rem;
  right: 1rem;
  background: none;
  border: none;
  font-size: 2rem;
  cursor: pointer;
  color: var(--mg-color-secondary);
  line-height: 1;
  padding: 0.5rem;
}

.modal-close:hover {
  opacity: 0.7;
}

.wizard-step-content h3 {
  color: var(--mg-color-primary);
  font-size: 1.25rem;
  margin-bottom: 0.5rem;
}

.credential-box {
  margin: 1rem 0;
}

.credential-box label {
  display: block;
  font-weight: bold;
  margin-bottom: 0.5rem;
}

.copy-field {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  flex-wrap: wrap;
}

.copy-field code {
  flex: 1;
  padding: 0.75rem;
  background: var(--mg-color-quinary);
  border-radius: var(--mg-control-radius);
  font-family: 'Courier New', monospace;
  word-break: break-all;
  color: var(--mg-color-secondary);
}

.copy-btn {
  padding: 0.5rem 1rem;
  background: var(--mg-color-primary);
  color: white;
  border: none;
  border-radius: var(--mg-control-radius);
  cursor: pointer;
  white-space: nowrap;
}

.copy-btn:hover {
  opacity: 0.8;
}

.password-form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.password-form input {
  max-width: 400px;
}

.password-form button {
  max-width: 200px;
}

.message {
  padding: 0.75rem;
  border-radius: var(--mg-control-radius);
  margin-top: 0.5rem;
}

.message.error {
  background: light-dark(
    color-mix(in srgb, var(--mg-color-red) 10%, var(--mg-color-light)),
    color-mix(in srgb, var(--mg-color-red) 20%, var(--mg-color-dark))
  );
  color: var(--mg-color-red);
  border: 1px solid var(--mg-color-red);
}

.message.success {
  background: light-dark(
    color-mix(in srgb, var(--mg-color-green) 10%, var(--mg-color-light)),
    color-mix(in srgb, var(--mg-color-green) 20%, var(--mg-color-dark))
  );
  color: var(--mg-color-green);
  border: 1px solid var(--mg-color-green);
}

.settings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
  margin: 1rem 0;
}

.setting-item {
  padding: 1rem;
  background: var(--mg-color-quinary);
  border-radius: var(--mg-control-radius);
}

.setting-label {
  font-weight: bold;
  display: block;
  margin-bottom: 0.5rem;
}

.setting-value {
  display: block;
  color: var(--mg-color-primary);
}

.gateway-explainer {
  margin: 1.5rem 0;
  padding: 1rem;
  background: var(--mg-color-quinary);
  border-radius: var(--mg-control-radius);
}

.gateway-explainer h4 {
  margin-top: 0;
  color: var(--mg-color-primary);
  font-size: 1rem;
}

.gateway-details {
  margin-top: 1rem;
}

.gateway-details summary {
  cursor: pointer;
  padding: 0.75rem;
  background: var(--mg-color-initial);
  border-radius: var(--mg-control-radius);
  margin-bottom: 0.5rem;
}

.gateway-details summary:hover {
  background: var(--mg-color-quinary);
}

.gateway-use-cases {
  padding: 1rem;
  background: var(--mg-color-initial);
  border-radius: var(--mg-control-radius);
}

.gateway-use-cases ul {
  margin: 0.5rem 0;
  padding-left: 1.5rem;
}

.gateway-use-cases li {
  margin: 0.5rem 0;
  line-height: 1.6;
}

.gateway-warning {
  margin-top: 1rem;
  padding: 1rem;
  background: light-dark(
    color-mix(in srgb, var(--mg-color-orange) 15%, var(--mg-color-light)),
    color-mix(in srgb, var(--mg-color-orange) 20%, var(--mg-color-dark))
  );
  border: 1px solid var(--mg-color-orange);
  border-radius: var(--mg-control-radius);
}

.gateway-warning i {
  color: var(--mg-color-orange);
  margin-right: 0.5rem;
}

.topic-selection {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  margin: 1rem 0;
  font-size: 1rem;
}

.topic-radio-option {
  display: block;
  cursor: pointer;
}

.topic-radio-option input[type="radio"] {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.topic-radio-content {
  padding: 1rem;
  border: 2px solid var(--mg-color-quinary);
  border-radius: var(--mg-control-radius);
  transition: all 0.2s ease;
}

.topic-radio-option input[type="radio"]:checked + .topic-radio-content {
  border-color: var(--mg-color-primary);
  background: color-mix(in srgb, var(--mg-color-primary) 5%, transparent);
}

.topic-radio-option:hover .topic-radio-content {
  border-color: var(--mg-color-primary);
  box-shadow: 0 2px 8px light-dark(rgba(0, 0, 0, 0.1), rgba(0, 0, 0, 0.3));
}

.topic-radio-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.5rem;
}

.topic-radio-header i {
  font-size: 1.25rem;
  color: var(--mg-color-primary);
}

.topic-radio-header h4 {
  margin: 0;
  flex: 1;
  color: var(--mg-color-primary);
  font-size: 1.125rem;
}

.topic-badge {
  font-size: 0.75rem;
  padding: 0.25rem 0.75rem;
  border-radius: 1rem;
  background: var(--mg-color-primary);
  color: white;
  font-weight: bold;
}

.topic-badge-warning {
  background: var(--mg-color-orange);
}

.topic-radio-description {
  margin: 0 0 0.75rem 0;
  color: var(--mg-color-tertiary);
  font-size: 0.9rem;
  font-weight: 300;
}

.topic-radio-details {
  list-style: none;
  padding-left: 0;
  margin: 0;
}

.topic-radio-details li {
  position: relative;
  padding-left: 1.5rem;
  font-weight: 300;
  font-size: 0.9rem;
  margin-bottom: 0.25rem;
  color: var(--mg-color-secondary);
}

.topic-radio-details li::before {
  content: '✓';
  position: absolute;
  left: 0.25rem;
  color: var(--mg-color-green);
  font-weight: bold;
}

.gateway-warning-compact {
  margin-top: 0.75rem;
  padding: 0.75rem;
  background: color-mix(in srgb, var(--mg-color-orange) 10%, transparent);
  border-left: 3px solid var(--mg-color-orange);
  border-radius: 0.25rem;
  font-size: 0.875rem;
}

.gateway-warning-compact i {
  color: var(--mg-color-orange);
  margin-right: 0.5rem;
}

.selected-topic-display {
  padding: 1rem;
  background: var(--mg-color-quinary);
  border-radius: var(--mg-control-radius);
}

.selected-topic-display h4 {
  margin: 0;
  color: var(--mg-color-primary);
  font-size: 1rem;
}

.channel-box {
  margin: 1rem 0;
  padding: 1rem;
  border: 1px solid var(--mg-color-quinary);
  border-radius: var(--mg-control-radius);
}

.channel-box h4 {
  margin-top: 0;
  color: var(--mg-color-primary);
  font-size: 1rem;
}

.channel-settings {
  display: flex;
  gap: 2rem;
  margin-top: 1rem;
  flex-wrap: wrap;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 1rem;
  margin-top: 2rem;
  padding-top: 1rem;
  border-top: 1px solid var(--mg-color-light);
}

@media only screen and (max-width:768px) {
  .onboarding-content {
    padding: 1rem;
  }

  .copy-field {
    flex-direction: column;
    align-items: stretch;
  }

  .copy-btn {
    width: 100%;
  }

  /* Wizard mobile styles */
  .wizard-steps {
    gap: 0.25rem;
  }

  .wizard-step {
    gap: 0.25rem;
  }

  .step-circle {
    width: 32px;
    height: 32px;
    font-size: 0.85rem;
  }

  .step-label {
    font-size: 0.65rem;
  }

  .wizard-body {
    min-height: 250px;
  }

  .wizard-navigation {
    flex-wrap: wrap;
    gap: 0.5rem;
  }

  .wizard-navigation button {
    flex: 1;
    min-width: 120px;
  }

  /* Topic selection mobile styles */
  .topic-radio-content {
    padding: 1rem;
  }

  .topic-radio-header {
    flex-wrap: wrap;
  }

  .topic-radio-header i {
    font-size: 1.25rem;
  }

  .topic-radio-details li {
    font-size: 0.85rem;
  }
}

/* Node Table Filters and Controls */
.table-controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
  flex-wrap: wrap;
  gap: 1rem;
}

.table-controls h3 {
  margin: 0;
}

.filter-controls {
  display: flex;
  gap: 1.5rem;
  flex-wrap: wrap;
}

.filter-controls label {
  margin-bottom: 0.75rem;
}

.loading-message {
  text-align: center;
  padding: 2rem !important;
  font-style: italic;
  color: var(--mg-color-tertiary);
}

.error-message {
  text-align: center;
  padding: 2rem !important;
  color: var(--mg-color-red);
}

/* Highlight rows with validation errors */
tr.has-errors {
  background-color: light-dark(
    color-mix(in srgb, var(--mg-color-orange) 15%, var(--mg-color-light)),
    color-mix(in srgb, var(--mg-color-orange) 20%, var(--mg-color-dark))
  );
}

tr.has-errors:hover {
  background-color: light-dark(
    color-mix(in srgb, var(--mg-color-orange) 25%, var(--mg-color-light)),
    color-mix(in srgb, var(--mg-color-orange) 30%, var(--mg-color-dark))
  );
}

/* Prevent node IDs from wrapping */
#nodes-table td:first-child,
#other-clients-table td:first-child {
  white-space: nowrap;
}

/* Topic cell truncation */
.topic-cell {
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: help;
}

/* Gateway status badge in table */
.gw-status-cell {
  cursor: pointer;
}

.gw-badge {
  display: inline-block;
  padding: 0.2rem 0.5rem;
  border-radius: 0.25rem;
  font-size: 0.85rem;
  font-weight: 500;
}

.gw-badge.gw-valid {
  background: color-mix(in srgb, var(--mg-color-green) 20%, transparent);
  color: var(--mg-color-green);
}

.gw-badge.gw-invalid {
  background: color-mix(in srgb, var(--mg-color-red) 20%, transparent);
  color: var(--mg-color-red);
}

tr.has-errors .gw-badge.gw-invalid {
  background: color-mix(in srgb, var(--mg-color-orange) 30%, transparent);
  color: var(--mg-color-orange);
}

/* Status indicator dots for mobile */
.status-dots {
  display: flex;
  gap: 6px;
  align-items: center;
}

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

.status-dot.connected {
  background: var(--mg-color-green);
  box-shadow: 0 0 4px var(--mg-color-green);
}

.status-dot.disconnected {
  background: var(--mg-color-tertiary);
}

.status-dot.has-errors {
  background: var(--mg-color-orange);
  box-shadow: 0 0 4px var(--mg-color-orange);
}

.status-dot.no-errors {
  background: transparent;
  border: 1px solid var(--mg-color-quaternary);
}

.status-dot.valid-gw {
  background: var(--mg-color-blue);
  box-shadow: 0 0 4px var(--mg-color-blue);
}

.status-dot.invalid-gw {
  background: transparent;
  border: 1px solid var(--mg-color-quaternary);
}

/* Desktop defaults for mobile elements */
.mobile-only {
  display: none;
}

.node-details-row {
  display: none;
}

/* Forwarding Status Panel */
.forwarding-panel {
  padding: 1.5rem;
  background: var(--mg-color-quinary);
  border-radius: var(--mg-control-radius);
  overflow: hidden;
  max-width: 100%;
}

.forwarding-panel h3 {
  margin: 0 0 1rem 0;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  color: var(--mg-color-primary);
}

.forwarding-panel h3 i {
  font-size: 1.25rem;
}

/* Forwarding table (desktop) */
.forwarding-table {
  background: var(--mg-color-initial);
  border-radius: 0.5rem;
  overflow: hidden;
}

.forwarding-table code {
  background: var(--mg-color-quinary);
  padding: 0.15rem 0.5rem;
  border-radius: 0.25rem;
  font-size: 0.85rem;
}

.forwarding-table .target-name-cell {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.forwarding-table .topics-cell {
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.forwarding-table .details-cell {
  font-size: 0.85rem;
  color: var(--mg-color-tertiary);
}

.forwarding-table .error-text {
  color: var(--mg-color-red);
  cursor: help;
}

/* Hide cards by default (shown on mobile via media query) */
.forwarding-cards-mobile {
  display: none;
}

/* Forwarding target cards (used on mobile) */
.forwarding-target-card {
  padding: 1rem;
  background: var(--mg-color-initial);
  transition: all 0.2s ease;
  border-radius: var(--mg-control-radius);
  border: 1px solid var(--mg-color-quaternary);
  overflow: hidden;
  margin-bottom: 0.75rem;
}

.forwarding-target-card:last-child {
  margin-bottom: 0;
}

.forwarding-target-card.connected {
  border-color: var(--mg-color-green);
}

.forwarding-target-card.disconnected {
  border-color: var(--mg-color-red);
}

.target-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.75rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--mg-color-quinary);
}

.target-name {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.target-name strong {
  font-size: 1.1rem;
}

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

.status-indicator.status-connected {
  background: var(--mg-color-green);
  box-shadow: 0 0 8px var(--mg-color-green);
}

.status-indicator.status-disconnected {
  background: var(--mg-color-red);
  box-shadow: 0 0 8px var(--mg-color-red);
}

.target-status-badge {
  font-size: 0.75rem;
  padding: 0.25rem 0.75rem;
  border-radius: 1rem;
  font-weight: 600;
  text-transform: uppercase;
}

.target-status-badge.badge-connected {
  background: color-mix(in srgb, var(--mg-color-green) 15%, transparent);
  color: var(--mg-color-green);
}

.target-status-badge.badge-disconnected {
  background: color-mix(in srgb, var(--mg-color-red) 15%, transparent);
  color: var(--mg-color-red);
}

.target-details {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.target-detail-row {
  display: flex;
  gap: 0.5rem;
  font-size: 0.9rem;
}

.target-detail-row .detail-label {
  color: var(--mg-color-tertiary);
  flex-shrink: 0;
  min-width: 100px;
}

.target-detail-row code {
  background: var(--mg-color-quinary);
  padding: 0.15rem 0.5rem;
  border-radius: 0.25rem;
  font-size: 0.85rem;
  word-break: break-all;
  overflow-wrap: break-word;
}

.target-detail-row.target-error {
  color: var(--mg-color-red);
}

.target-detail-row .error-message {
  word-break: break-word;
}

.topics-list {
  word-break: break-word;
}

.no-targets-message {
  text-align: center;
  padding: 1rem;
  color: var(--mg-color-tertiary);
  font-style: italic;
}

/* ========================================
   Mobile Responsive Styles
   All mobile overrides at the end for clean cascade
   ======================================== */
@media only screen and (max-width: 768px) {
  /* Prevent horizontal overflow on mobile */
  html, body {
    overflow-x: hidden;
    max-width: 100vw;
    width: 100%;
  }

  .main, #tables-example, #nodes-section {
    overflow-x: hidden;
    max-width: 100%;
  }

  /* Header adjustments for mobile */
  .wrapper > header {
    padding-left: 0.5rem;
    padding-right: 0.5rem;
  }

  .logo-view {
    overflow: hidden;
  }

  .logo-view a {
    overflow: hidden;
  }

  .logo-view a > span {
    font-size: 2rem !important;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  /* Ensure container doesn't cause overflow */
  .wrapper {
    max-width: 100%;
    overflow-x: hidden;
  }

  .container {
    max-width: 100%;
    padding-left: 0.5rem;
    padding-right: 0.5rem;
  }

  .table-controls {
    flex-direction: column;
    align-items: flex-start;
  }

  .filter-controls {
    flex-direction: column;
    gap: 0.75rem;
  }

  /* Hide desktop columns, show mobile view */
  .nodes-table thead {
    display: none;
  }

  .nodes-table .desktop-only {
    display: none;
  }

  .nodes-table .mobile-only {
    display: table-cell;
  }

  .nodes-table .node-row {
    display: block;
    margin-bottom: 0.5rem;
    border: 1px solid var(--mg-color-quaternary);
    border-radius: 0.75rem;
    cursor: pointer;
    transition: all 0.2s ease;
  }

  .nodes-table .node-row:hover {
    border-color: var(--mg-color-primary);
  }

  .nodes-table .node-row.has-errors {
    border-color: var(--mg-color-orange);
  }

  .nodes-table .node-row td {
    border-bottom: none;
    padding: 0.75rem;
  }

  /* Compact row header */
  .compact-row-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
  }

  .node-badge-sm {
    color: white;
    padding: 0.3rem 0.6rem;
    font-size: 0.75rem;
    border-radius: 0.375rem;
    font-weight: bold;
    flex-shrink: 0;
  }

  .node-name-compact {
    flex: 1;
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
  }

  .expand-icon {
    color: var(--mg-color-tertiary);
    transition: transform 0.2s ease;
    flex-shrink: 0;
  }

  .node-row.expanded .expand-icon {
    transform: rotate(180deg);
  }

  .compact-row-subtext {
    font-size: 0.8rem;
    color: var(--mg-color-tertiary);
    margin-top: 0.4rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  /* Expandable details row */
  .nodes-table .node-details-row {
    display: none;
  }

  .nodes-table .node-row.expanded + .node-details-row {
    display: block;
    margin-top: -0.5rem;
    margin-bottom: 0.5rem;
    border: 1px solid var(--mg-color-quaternary);
    border-top: none;
    border-radius: 0 0 0.75rem 0.75rem;
    overflow: hidden;
  }

  .nodes-table .node-row.expanded {
    margin-bottom: 0;
    border-radius: 0.75rem 0.75rem 0 0;
  }

  .nodes-table .node-row.expanded.has-errors + .node-details-row {
    border-color: var(--mg-color-orange);
  }

  .nodes-table .node-details-row td {
    padding: 0;
    border-bottom: none;
  }

  .expanded-content {
    padding: 0.75rem;
    background: var(--mg-color-quinary);
  }

  .detail-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.5rem;
  }

  .detail-item {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
  }

  .detail-item:first-child {
    grid-column: 1 / -1;
  }

  .detail-label {
    font-size: 0.7rem;
    color: var(--mg-color-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
  }

  .detail-value {
    font-size: 0.85rem;
    color: var(--mg-color-secondary);
  }

  .topic-value {
    background: var(--mg-color-initial);
    padding: 0.25rem 0.5rem;
    border-radius: 0.25rem;
    font-size: 0.75rem;
    word-break: break-all;
  }

  /* Validation errors in expanded view */
  .validation-errors-compact {
    margin-top: 0.75rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--mg-color-quaternary);
  }

  .validation-errors-compact .error-label {
    display: block;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--mg-color-orange);
    margin-bottom: 0.5rem;
  }

  .validation-errors-compact .error-label i {
    margin-right: 0.4rem;
  }

  .validation-errors-compact ul {
    list-style: none;
    padding: 0;
    margin: 0;
  }

  .validation-errors-compact li {
    font-size: 0.8rem;
    color: var(--mg-color-secondary);
    padding: 0.35rem 0.5rem;
    margin-bottom: 0.25rem;
    background: color-mix(in srgb, var(--mg-color-orange) 10%, transparent);
    border-left: 2px solid var(--mg-color-orange);
    border-radius: 0 0.25rem 0.25rem 0;
  }

  /* Other clients table - simple responsive */
  #other-clients-table {
    display: block;
    width: 100%;
  }

  #other-clients-table thead {
    display: none;
  }

  #other-clients-table tbody {
    display: block;
  }

  #other-clients-table tr {
    display: block;
    margin-bottom: 0.5rem;
    padding: 0.75rem;
    border: 1px solid var(--mg-color-quaternary);
    border-radius: 0.5rem;
    background: var(--mg-color-quinary);
  }

  #other-clients-table td {
    display: block;
    padding: 0.25rem 0;
    border: none;
    text-align: left;
  }

  #other-clients-table td:first-child {
    font-weight: 500;
    white-space: normal;
    word-break: break-all;
  }

  #other-clients-table td:before {
    content: attr(data-label);
    display: inline-block;
    width: 80px;
    font-size: 0.7rem;
    color: var(--mg-color-tertiary);
    text-transform: uppercase;
  }

  /* Forwarding panel: hide table, show cards on mobile */
  .forwarding-table {
    display: none;
  }

  .forwarding-cards-mobile {
    display: block;
  }

  .forwarding-panel {
    padding: 1rem;
  }

  .forwarding-targets {
    grid-template-columns: 1fr;
  }

  .target-detail-row {
    flex-direction: column;
    gap: 0.25rem;
  }

  .target-detail-row .detail-label {
    min-width: auto;
  }

  /* Node grid and cards on mobile */
  .node-grid {
    padding: 0 0.25rem;
  }

  .node-card {
    max-width: 100%;
    overflow: hidden;
  }

  .node-card code {
    word-break: break-all;
    overflow-wrap: break-word;
  }

  .node-topic code {
    display: inline-block;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    vertical-align: bottom;
  }

  .node-info-row {
    flex-wrap: wrap;
  }

  .node-info-text {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  /* Ensure tables don't overflow */
  table {
    table-layout: fixed;
    width: 100%;
  }

  #other-clients-table td:first-child code,
  #other-clients-table td code {
    word-break: break-all;
    overflow-wrap: break-word;
  }
}