/* ── Message Builder v2 (mb- prefix) ── */
/* ═══════════════════════════════════════════════════════════════
   Message Builder v2 Styles (mb- prefix)
   ═══════════════════════════════════════════════════════════════ */

/* Layout */
.mb-layout {
  display: grid;
  grid-template-columns: 1fr 400px;
  gap: 1.25rem;
  align-items: start;
}

.mb-form-col { min-width: 0; }

.mb-preview-col {
  position: relative;
}

.mb-preview-sticky {
  position: sticky;
  top: calc(var(--header-h) + 1rem);
  max-height: calc(100vh - var(--header-h) - 2rem);
  overflow-y: auto;
}

.navbar-hidden .mb-preview-sticky {
  top: 1rem;
  max-height: calc(100vh - 2rem);
}

/* Sections */
.mb-section {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.25rem;
  margin-bottom: 1rem;
}

.mb-section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.75rem;
}

.mb-advanced-head {
  cursor: pointer;
  user-select: none;
  gap: 0.4rem;
  margin-bottom: 0;
}

.mb-advanced-section #mbAdvancedSections {
  margin-top: 0.75rem;
}

.mb-advanced-section.mb-advanced-collapsed {
  cursor: pointer;
}

.mb-advanced-head .mb-section-title {
  transition: color 0.15s ease;
}

.mb-advanced-head:hover .mb-section-title {
  color: var(--text);
}

.mb-advanced-chevron {
  display: inline-flex;
  align-items: center;
  color: var(--text-muted);
  transition: transform 0.15s ease;
}

.mb-advanced-head.mb-advanced-collapsed .mb-advanced-chevron {
  transform: rotate(-90deg);
}

.mb-section-title {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-main);
}

/* Counters */
.mb-counter {
  font-size: 0.78rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.mb-counter-warn { color: #ff9f00; }
.mb-counter-over { color: var(--danger); }

.mb-field-counter {
  font-size: 0.72rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

/* Formatting toolbar */
.mb-fmt-toolbar {
  display: flex;
  gap: 0.25rem;
  margin-bottom: 0.5rem;
  flex-wrap: wrap;
}

.mb-fmt-btn {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-muted);
  padding: 0.3rem 0.55rem;
  font-size: 0.78rem;
  cursor: pointer;
  transition: all 0.15s;
  font-family: inherit;
}

.mb-fmt-btn:hover { background: rgba(255,255,255,0.08); color: var(--text-main); }
.mb-fmt-bold { font-weight: 800; }
.mb-fmt-italic { font-style: italic; }
.mb-fmt-underline { text-decoration: underline; }
.mb-fmt-strike { text-decoration: line-through; }
.mb-fmt-code { font-family: monospace; }
.mb-fmt-codeblock { font-family: monospace; }
.mb-fmt-spoiler { opacity: 0.7; }
.mb-fmt-link { text-decoration: underline; }

/* Textarea */
.mb-textarea {
  background: #1a1d24;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-main);
  padding: 0.75rem;
  font-size: 0.88rem;
  font-family: inherit;
  resize: vertical;
  width: 100%;
  box-sizing: border-box;
  outline: none;
  transition: border-color 0.2s;
  min-height: 80px;
}

.mb-textarea:focus { border-color: rgba(88,101,242,0.4); }
.mb-textarea { resize: none; overflow-y: auto; }

/* Add button */
.mb-add-btn {
  background: rgba(88,101,242,0.1);
  border: 1px solid rgba(88,101,242,0.2);
  border-radius: 6px;
  color: #5865F2;
  padding: 0.3rem 0.7rem;
  font-size: 0.8rem;
  cursor: pointer;
  font-weight: 600;
  transition: all 0.15s;
  white-space: nowrap;
}

.mb-add-btn:hover { background: rgba(88,101,242,0.18); }
.mb-add-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.mb-add-sm { padding: 0.2rem 0.5rem; font-size: 0.75rem; }

/* Embed card */
.mb-embed-card {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 0.75rem;
  overflow: hidden;
  transition: border-color 0.2s;
}

.mb-embed-active { border-color: rgba(88,101,242,0.3); }

.mb-embed-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.65rem 0.75rem;
  cursor: pointer;
  transition: background 0.15s;
}

.mb-embed-header:hover { background: rgba(255,255,255,0.02); }

.mb-embed-header-left {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.mb-embed-color-swatch {
  width: 14px;
  height: 14px;
  border-radius: 4px;
  flex-shrink: 0;
}

.mb-embed-label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-main);
}

.mb-embed-header-right {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.mb-embed-collapse,
.mb-embed-remove,
.mb-embed-icon-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0.25rem;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}

.mb-embed-collapse:hover,
.mb-embed-icon-btn:hover { background: rgba(255,255,255,0.05); }
.mb-embed-icon-btn:hover { color: #fff; }
.mb-embed-remove:hover { color: var(--danger); }

.mb-embed-icon-btn[style*="red"],
.mb-embed-icon-btn[style*="ed4245"] { color: rgba(237,66,69,0.6); }
.mb-embed-icon-btn[style*="red"]:hover,
.mb-embed-icon-btn[style*="ed4245"]:hover { color: var(--danger); background: rgba(255,80,80,0.08); }
.mb-embed-body { padding: 0.75rem 0.75rem 0.75rem; }

/* Embed grid & fields */
.mb-embed-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.65rem;
}

.mb-field {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.mb-field label {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.mb-field-full { grid-column: 1 / -1; }

.mb-input {
  background: #1a1d24;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-main);
  padding: 0.55rem 0.7rem;
  font-size: 0.85rem;
  font-family: inherit;
  width: 100%;
  box-sizing: border-box;
  outline: none;
  transition: border-color 0.2s;
}

.mb-input:focus { border-color: rgba(88,101,242,0.4); }
.mb-input::placeholder { color: var(--text-muted); opacity: 0.6; }

/* Toggle checkbox */
.mb-toggle-label {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.82rem;
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
}

.mb-toggle-label input[type="checkbox"] {
  appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 4px;
  background: rgba(255,255,255,0.08);
  border: 1px solid var(--border);
  cursor: pointer;
  position: relative;
  flex-shrink: 0;
  transition: all 0.15s;
}

.mb-toggle-label input[type="checkbox"]:checked { background: #5865F2; }

.mb-toggle-label input[type="checkbox"]::after {
  content: '';
  position: absolute;
  top: 1.5px;
  left: 1.5px;
  width: 11px;
  height: 11px;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='11' height='11' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='3.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='20 6 9 17 4 12'%3E%3C/polyline%3E%3C/svg%3E") center/contain no-repeat;
  border-radius: 2px;
  transition: transform 0.15s;
  opacity: 0;
  transform: scale(0.4);
}

.mb-toggle-label input[type="checkbox"]:checked::after { opacity: 1; transform: scale(1); }

/* Inline toggle checkbox */
.mb-inline-toggle input:checked { background: #5865F2; }

.mb-inline-toggle input::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 8px;
  height: 8px;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='8' height='8' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='20 6 9 17 4 12'%3E%3C/polyline%3E%3C/svg%3E") center/contain no-repeat;
  border-radius: 1px;
  opacity: 0;
  transform: scale(0.4);
  transition: opacity 0.12s, transform 0.12s;
}

.mb-inline-toggle input:checked::after { opacity: 1; transform: scale(1); }

/* Timestamp 3-state toggle button */
.mb-ts-toggle {
  background: #1a1d24;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-muted);
  padding: 0.45rem 0.85rem;
  font-size: 0.8rem;
  cursor: pointer;
  font-family: inherit;
  font-weight: 600;
  transition: all 0.15s;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}

.mb-ts-toggle:hover { background: rgba(255,255,255,0.06); }

.mb-ts-toggle.active {
  background: rgba(88,101,242,0.12);
  border-color: rgba(88,101,242,0.3);
  color: #5865F2;
}

.mb-ts-toggle .mb-ts-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
  transition: background 0.15s;
}

.mb-ts-toggle.active .mb-ts-dot { background: #5865F2; }


/* Mini formatting toolbar for embed fields */
.mb-mini-toolbar {
  display: flex;
  gap: 0.15rem;
  margin-bottom: 0.35rem;
}

.mb-mini-toolbar .mb-fmt-btn {
  padding: 0.2rem 0.35rem;
  font-size: 0.7rem;
}

.mb-mini-toolbar .mb-fmt-btn svg {
  width: 12px;
  height: 12px;
}

/* Image row (thumbnail + image on same line) */
.mb-image-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.65rem;
}

/* Subsection */
.mb-subsection {
  margin-top: 0.75rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
}

.mb-subsection-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.5rem;
}

.mb-subsection-head span {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

/* Field card redesign */
.mb-field-card {
  background: #1a1d24;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.75rem;
  margin-bottom: 0.6rem;
  transition: border-color 0.15s;
}

.mb-field-card:hover { border-color: rgba(255,255,255,0.12); }

.mb-field-card-head {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.mb-field-card-num {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--text-muted);
  background: rgba(255,255,255,0.06);
  border-radius: 4px;
  padding: 0.15rem 0.45rem;
  flex-shrink: 0;
}

.mb-field-card-head .mb-inline-toggle {
  margin-left: auto;
}

/* Field row (legacy, now unused but kept as fallback) */
.mb-field-row {
  display: grid;
  grid-template-columns: 1fr 1fr auto auto;
  gap: 0.5rem;
  align-items: end;
  margin-bottom: 0.5rem;
}

.mb-inline-toggle {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.75rem;
  color: var(--text-muted);
  white-space: nowrap;
  cursor: pointer;
}

.mb-inline-toggle input {
  appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 4px;
  background: rgba(255,255,255,0.08);
  border: 1px solid var(--border);
  cursor: pointer;
  position: relative;
  flex-shrink: 0;
  transition: all 0.15s;
}

/* (handled above with checkmark SVG) */

/* Remove small button */
.mb-remove-sm {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0.3rem;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
  flex-shrink: 0;
}

.mb-remove-sm:hover { color: var(--danger); background: rgba(255,80,80,0.08); }

/* Empty message */
.mb-empty-msg {
  color: var(--text-muted);
  font-size: 0.85rem;
  text-align: center;
  padding: 1.5rem 0.75rem;
  border: 1px dashed var(--border);
  border-radius: 8px;
}

/* Component card (action rows / buttons) */
.mb-comp-card {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 0.75rem;
  overflow: hidden;
}

.mb-comp-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.65rem 0.75rem;
  cursor: pointer;
  transition: background 0.15s;
}

.mb-comp-header:hover { background: rgba(255,255,255,0.02); }

.mb-comp-label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-main);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.mb-comp-header-right {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.mb-comp-body { padding: 0 0.75rem 0.75rem; }

/* Button card */
.mb-btn-card {
  background: var(--bg-dark);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem;
  margin-bottom: 0.5rem;
}

.mb-btn-type-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.mb-btn-type-label {
  font-size: 0.78rem;
  color: var(--text-muted);
  font-weight: 600;
}

.mb-btn-type-btns { display: flex; gap: 0.25rem; }

.mb-type-btn {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 5px;
  color: var(--text-muted);
  padding: 0.25rem 0.6rem;
  font-size: 0.78rem;
  cursor: pointer;
  transition: all 0.15s;
  font-family: inherit;
}

.mb-type-btn:hover { background: rgba(255,255,255,0.08); color: var(--text-main); }

.mb-type-active {
  background: rgba(88,101,242,0.12);
  border-color: rgba(88,101,242,0.3);
  color: #5865F2;
}

.mb-btn-fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
}

.mb-btn-style-row { display: flex; gap: 0.25rem; }

.mb-style-btn {
  width: 32px;
  height: 32px;
  border-radius: 6px;
  border: 2px solid transparent;
  color: #fff;
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.15s;
  padding: 0;
}

.mb-style-btn:hover { opacity: 0.85; }
.mb-style-active { border-color: #fff; transform: scale(1.05); }

/* Format toggle buttons */
.mb-format-btns { display: flex; gap: 0.2rem; }

.mb-format-btn {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-muted);
  padding: 0.25rem 0.55rem;
  font-size: 0.72rem;
  cursor: pointer;
  transition: all 0.15s;
  font-family: inherit;
  font-weight: 600;
}

.mb-format-btn:hover { background: rgba(255,255,255,0.08); color: var(--text-main); }

.mb-format-btn.active {
  background: rgba(88,101,242,0.12);
  border-color: rgba(88,101,242,0.3);
  color: #5865F2;
}

/* JSON hint */
.mb-json-hint {
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-top: 0.35rem;
  opacity: 0.7;
}

/* Action bar */
.mb-action-bar {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

.mb-action-btn {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-main);
  padding: 0.5rem 1rem;
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.15s;
  font-weight: 600;
  font-family: inherit;
}

.mb-action-btn:hover { background: rgba(255,255,255,0.08); }

.mb-action-primary {
  background: rgba(88,101,242,0.12);
  border-color: rgba(88,101,242,0.25);
  color: #5865F2;
}

.mb-action-primary:hover { background: rgba(88,101,242,0.2); }

/* Modal (webhook send) */
.mb-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.2s;
}

.mb-modal-visible { opacity: 1; }

.mb-modal {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 14px;
  width: 100%;
  max-width: 440px;
  margin: 1rem;
  transform: scale(0.95) translateY(10px);
  transition: transform 0.2s;
}

.mb-modal-visible .mb-modal { transform: scale(1) translateY(0); }

.mb-modal-header {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text-main);
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
}

.mb-modal-body {
  padding: 1rem 1.25rem;
}

.mb-modal-body label {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-muted);
  display: block;
  margin-bottom: 0.35rem;
}

.mb-modal-body input {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-main);
  padding: 0.55rem 0.7rem;
  font-size: 0.85rem;
  font-family: inherit;
  width: 100%;
  box-sizing: border-box;
  outline: none;
  transition: border-color 0.2s;
}

.mb-modal-body input:focus { border-color: rgba(88,101,242,0.4); }

.mb-modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  padding: 0.75rem 1.25rem;
  border-top: 1px solid var(--border);
}

.mb-modal-cancel {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-main);
  padding: 0.45rem 1rem;
  cursor: pointer;
  font-size: 0.85rem;
  font-family: inherit;
}

.mb-modal-ok {
  background: #5865F2;
  border: 1px solid #5865F2;
  border-radius: var(--radius);
  color: #fff;
  padding: 0.45rem 1rem;
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 700;
  font-family: inherit;
}

/* Responsive */

.mb-import-btn { margin-left: 0.4rem; }

@media (max-width: 640px) {
  .mb-section-head { flex-wrap: wrap; gap: 0.4rem; }
  .mb-format-btns { flex-wrap: wrap; row-gap: 0.4rem; }
  .mb-import-btn { margin-left: 0; }
}

@media (max-width: 1100px) {
  .mb-layout { grid-template-columns: 1fr; }
  .mb-preview-sticky { position: static; }
}

@media (max-width: 900px) {
 .mb-form-grid { grid-template-columns: 1fr; }
 .mb-embed-grid { grid-template-columns: 1fr; }
 .mb-field-row { grid-template-columns: 1fr; }
 .mb-btn-fields { grid-template-columns: 1fr; }
 .mb-btn-type-row { flex-wrap: wrap; }
}

/* ── Messages Split Layout (form left, preview right) ── */

.msg-split-layout {
  display: grid;
  grid-template-columns: 1fr 380px;
  gap: 1rem;
  align-items: start;
}
.msg-no-preview { grid-template-columns: 1fr; }
.msg-no-preview .msg-preview-side { display: none; }

.msg-form-side { min-width: 0; }
.msg-preview-side { position: relative; }

/* ── Settings Section Title ── */

.settings-section-title {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 0.75rem;
}

.settings-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-card);
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: 12px;
  padding: 1rem 1.25rem;
  transition: border-color var(--transition);
}

.settings-card:hover { border-color: rgba(255,255,255,0.12); }
.settings-card-info { flex: 1; min-width: 0; }
.settings-card-label { font-weight: 600; font-size: 0.95rem; margin-bottom: 0.2rem; }
.settings-card-desc { font-size: 0.85rem; color: var(--text-muted); }

/* ── Dashboard Access Roles ── */

.access-role-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  background: var(--bg-input);
  border-radius: var(--radius);
  margin-bottom: 0.4rem;
}

.access-role-name {
  flex: 1;
  font-size: 0.9rem;
  font-weight: 500;
}

.access-role-remove {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.85rem;
  padding: 0.15rem 0.35rem;
  border-radius: 4px;
  transition: var(--transition);
}

.access-role-remove:hover { color: var(--danger); background: rgba(255,80,80,0.1); }

/* ── Config Actions Grid ── */

.config-actions-grid {
  display: grid;
  gap: 0.75rem;
}

.config-action-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.85rem 1rem;
  background: var(--bg-input);
  border-radius: var(--radius);
  gap: 1rem;
}

.config-action-danger { border: 1px solid rgba(255,80,80,0.2); border-radius: var(--radius); }
.config-action-info { flex: 1; min-width: 0; }
.config-action-label { font-weight: 600; font-size: 0.9rem; margin-bottom: 0.1rem; }
.config-action-desc { font-size: 0.8rem; color: var(--text-muted); }

/* ── Field Group Title ── */

.field-group-title {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin: 1.25rem 0 0.75rem;
}

.config-group {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.02);
  padding: 1rem 1.25rem;
  margin-top: 1.25rem;
}
.config-group-header {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--primary);
  padding-bottom: 0.6rem;
  margin-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}
.config-subsection-header {
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin: 1.1rem 0 0.6rem;
  padding-top: 0.9rem;
  border-top: 1px dashed var(--border);
}
.config-subsection-header:first-child {
  margin-top: 0;
  padding-top: 0;
  border-top: none;
}
.config-group-body > :last-child { margin-bottom: 0; }

/* ── Module Sidebar ── */

.msidebar-back {
  color: var(--text-muted) !important;
  margin-bottom: 0.25rem;
}
.msidebar-back:hover {
  color: var(--text) !important;
}

.sidebar-module-header {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.75rem 0.5rem;
  margin: 0.5rem 0 0.75rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 0.75rem;
}

.sidebar-module-icon {
  display: flex;
  align-items: center;
  color: var(--text);
}

.sidebar-module-label {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text);
}

/* ── Console Page ── */

.console-output {
  background: var(--bg-card);
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: 12px;
  padding: 0.75rem;
  font-family: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', monospace;
  font-size: 0.8rem;
  line-height: 1.6;
  max-height: calc(100vh - var(--header-h) - 210px);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.console-toolbar {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 0.5rem;
  flex-wrap: wrap;
}

.console-toolbar-actions {
  /* Row 1: timezone + download + refresh */
}

.console-toolbar-search {
  /* Row 2: search + filter pills */
}

.console-toolbar-search .console-search-wrap {
  flex: 1;
  min-width: 180px;
  max-width: none;
}

.console-search-wrap {
  position: relative;
  flex: 1;
  min-width: 180px;
  max-width: 320px;
}

.console-search-icon {
  position: absolute;
  left: 0.6rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
}

.console-search-input {
  padding-left: 2rem !important;
  width: 100% !important;
}

.console-filter-pills {
  display: flex;
  gap: 0.3rem;
  flex-wrap: wrap;
}

.console-pill {
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.08);
  color: var(--text-muted);
  padding: 0.25rem 0.6rem;
  border-radius: 6px;
  font-size: 0.72rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  font-family: inherit;
}

.console-pill:hover {
  background: rgba(255,255,255,0.08);
  border-color: rgba(255,255,255,0.15);
  color: var(--text);
}

.console-pill.active {
  background: rgba(255,255,255,0.08);
  border-color: rgba(255,255,255,0.2);
  color: var(--text);
}

.console-line {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.25rem 0.4rem;
  border-radius: 4px;
  transition: background 0.1s ease;
}

.console-line:hover { background: rgba(255,255,255,0.03); }

.console-line-expandable { cursor: pointer; }
.console-line-expandable:hover { background: rgba(255,255,255,0.05); }

.console-line-expanded {
  background: rgba(255,255,255,0.04);
  border-radius: 4px 4px 0 0;
  margin-bottom: 0;
}

.console-expand-icon {
  color: var(--text-muted);
  font-size: 0.6rem;
  flex-shrink: 0;
  opacity: 0.5;
  transition: opacity 0.15s;
}
.console-line-expandable:hover .console-expand-icon { opacity: 1; }

.console-time {
  color: var(--text-muted);
  font-size: 0.72rem;
  flex-shrink: 0;
  min-width: 130px;
  opacity: 0.7;
}

.console-badge {
  font-size: 0.62rem;
  font-weight: 700;
  padding: 0.1em 0.45em;
  border-radius: 4px;
  flex-shrink: 0;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  font-family: inherit;
}

.console-msg { color: var(--text); flex: 1; min-width: 0; word-break: break-word; }
.console-log-level-warn { color: #ffd93d; }
.console-log-level-error { color: #ff6b6b; }

.console-detail-copy {
  position: absolute;
  top: 6px;
  right: 6px;
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.08);
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px 5px;
  border-radius: 4px;
  transition: color 0.15s, background 0.15s;
  display: flex;
  align-items: center;
}
.console-detail-copy:hover { color: var(--text); background: rgba(255,255,255,0.1); }

.console-detail {
  background: rgba(0,0,0,0.25);
  border: 1px solid rgba(255,255,255,0.05);
  border-top: none;
  border-radius: 0 0 8px 8px;
  margin: 0 0.4rem 0.35rem 0.4rem;
  padding: 0.6rem 0.8rem;
  padding-top: 2rem;
  overflow-x: auto;
  flex-shrink: 0;
  max-height: 400px;
  overflow-y: auto;
  position: relative;
}

.console-json {
  margin: 0;
  font-family: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', monospace;
  font-size: 0.73rem;
  line-height: 1.5;
  color: #c9d1d9;
  white-space: pre;
}

.console-empty {
  text-align: center;
  color: var(--text-muted);
  padding: 3rem 1rem;
  font-family: inherit;
  font-size: 0.9rem;
}

.console-loading {
  text-align: center;
  color: var(--text-muted);
  padding: 3rem 1rem;
  font-family: inherit;
  font-size: 0.9rem;
}

/* ── Scrollbar ── */

* {
  scrollbar-width: thin;
  scrollbar-color: #24252e transparent;
}

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.18); }

.sidebar::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.15); }
.sidebar { scrollbar-color: #2b2d38 transparent; }

/* ── Mobile Guild Bar (below navbar on mobile) ── */

.mobile-guild-bar {
  display: none;
}

.mobile-guild-bar-icon {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  flex-shrink: 0;
}

.mobile-guild-bar-name {
  font-weight: 700;
  font-size: 0.9rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  min-width: 0;
}

.mobile-guild-bar-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  transition: color 0.15s, background 0.15s;
}

.mobile-guild-bar-btn:hover {
  color: var(--text);
  background: rgba(255,255,255,0.06);
}

/* ── Sidebar Backdrop (mobile) ── */

.sidebar-backdrop {
  display: none;
}

/* ── Responsive ── */

@media (max-width: 1100px) {
  .home-stats-row { grid-template-columns: repeat(2, 1fr); }
  .home-grid { grid-template-columns: 1fr; }
  .msg-split-layout { grid-template-columns: 1fr; }
  .msg-preview-side { display: none; }
}

@media (max-width: 900px) {
 .log-event-channel { width: 160px; }
 .hc-bar-row { grid-template-columns: 120px 1fr 56px; }
}

@media (max-width: 768px) {
  .navbar.nav-open { z-index: 120; }

  /* Mobile guild bar */
  .mobile-guild-bar {
    display: flex;
    position: fixed;
    top: var(--header-h);
    left: 0;
    right: 0;
    height: 48px;
    align-items: center;
    gap: 0.6rem;
    padding: 0 0.85rem;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    z-index: 100;
    transition: transform 0.3s cubic-bezier(.4,0,.2,1);
  }

  .mobile-guild-bar.hide {
    transform: translateY(calc(var(--header-h) * -1));
  }

  .modules-toolbar { gap: 0.5rem; }
  .module-entry { padding: 0.7rem 0.75rem; gap: 0.65rem; }
  .me-icon { width: 32px; height: 32px; }
  .me-icon svg { width: 16px; height: 16px; }
  .me-name { white-space: normal; }
  .me-desc {
    white-space: normal;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }
  .me-star, .me-configure { opacity: 1; }

  .form-input, .modules-search, select.form-input, textarea.form-input { font-size: 16px; }


  /* Sidebar becomes a slide-out drawer */
  .sidebar {
    display: flex;
    position: fixed;
    top: calc(var(--header-h) + 48px);
    left: 0;
    bottom: 0;
    z-index: 150;
    width: min(280px, 85vw);
    transform: translateX(-100%);
    transition: transform 0.25s ease;
  }

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

  /* The mobile guild bar above the drawer already carries the name and icon */
  .sidebar-guild-info { display: none; }

  /* Sidebar backdrop */
  .sidebar-backdrop {
    display: block;
    position: fixed;
    top: calc(var(--header-h) + 48px);
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.55);
    z-index: 140;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
  }

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

  .main {
    margin-left: 0;
    padding-top: calc(var(--header-h) + 48px + 1.5rem);
  }

  .log-event-row { flex-direction: column; align-items: flex-start; gap: 0.5rem; }
  .log-event-channel { width: 100%; }
  .home-stats-row { grid-template-columns: 1fr 1fr; }
  .mb-send-row { flex-direction: column; align-items: stretch; }
  .mb-send-row .form-group { margin-bottom: 0.75rem; }

  .main { padding-left: 0.9rem; padding-right: 0.9rem; }
  .card { padding: 1rem 0.9rem; }
  .config-group { padding: 0.85rem 0.9rem; }
  .card-header { flex-wrap: wrap; gap: 0.5rem; }
  .field-row { flex-direction: column; gap: 0; }
  .field-row > .form-group { flex: 0 1 auto; }
  .field-row-compact > .form-group { flex: 1 1 auto; }
  .module-breadcrumb { flex-wrap: wrap; }
  .module-header-row { row-gap: 0.65rem; }
  .module-header-row .module-header-toggle { margin-left: 0; width: 100%; }
  .page-title { font-size: 1.3rem; }
}

/* ── Multi-Role Selector ── */
.multi-role-list { margin-bottom: 0.5rem; }
.multi-role-list p { margin-top: 0.35rem; }
.multi-role-add { margin-top: 0.35rem; }

/* ── Emoji Picker ── */
.emoji-picker-wrap { display: inline-block; }
.emoji-trigger-box {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 0.3rem; background: var(--bg-input);
  border: 1px solid var(--border); border-radius: var(--radius);
  color: var(--text); font-family: 'Inter', sans-serif;
  cursor: pointer; transition: var(--transition);
  width: 44px; height: 44px; box-sizing: border-box;
}
.emoji-trigger-box:hover { border-color: rgba(255,255,255,0.15); }
.emoji-trigger-box:focus { outline: none; border-color: var(--primary); }
.emoji-empty-icon { display: inline-flex; color: var(--text-muted); opacity: 0.75; }
.emoji-display { font-size: 1.5rem; line-height: 1; }
.emoji-display-img { width: 1.3em; height: 1.3em; object-fit: contain; display: inline-block; vertical-align: middle; }
.emoji-change-hint { color: var(--text-muted); font-size: 0.8rem; white-space: nowrap; }
.emoji-trigger-box.has-emoji .emoji-change-hint { color: var(--text-muted); }
.emoji-placeholder { color: var(--text-muted); font-size: 0.85rem; }

.ep-popup {
  position: fixed; z-index: 500; width: 340px;
  background: var(--bg-card); border: 1px solid rgba(255,255,255,0.1);
  border-radius: 8px; box-shadow: 0 8px 32px rgba(0,0,0,0.5);
  animation: csFadeIn 0.12s ease; display: flex; flex-direction: column;
  max-height: 420px;
}
.ep-header { padding: 0.5rem 0.6rem 0; }
.ep-header-row { display: flex; align-items: center; gap: 0.4rem; }
.ep-header-row .ep-search { flex: 1; min-width: 0; }
.ep-clear {
  flex-shrink: 0; width: 30px; height: 30px; display: flex;
  align-items: center; justify-content: center;
  background: var(--bg-input); border: 1px solid var(--border);
  border-radius: 6px; color: var(--text-muted); cursor: pointer;
  transition: var(--transition);
}
.ep-clear:hover { color: var(--text); border-color: var(--primary); }
.ep-search {
  width: 100%; padding: 0.4rem 0.6rem; background: var(--bg-input);
  border: 1px solid var(--border); border-radius: 6px;
  color: var(--text); font-size: 0.85rem; font-family: 'Inter', sans-serif;
  outline: none; box-sizing: border-box;
}
.ep-search:focus { border-color: var(--primary); }
.ep-search::placeholder { color: var(--text-muted); }
.ep-tabs {
  display: flex; gap: 0; padding: 0.4rem 0.4rem 0; overflow-x: auto;
  border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.ep-tab {
  flex-shrink: 0; width: 34px; height: 34px; display: flex;
  align-items: center; justify-content: center; background: none;
  border: none; border-bottom: 2px solid transparent;
  color: var(--text-muted); font-size: 1.1rem; cursor: pointer;
  border-radius: 6px 6px 0 0; transition: var(--transition);
}
.ep-tab:hover { color: var(--text); background: rgba(255,255,255,0.04); }
.ep-tab-active { color: var(--primary); border-bottom-color: var(--primary); }
.ep-grid-wrap {
  flex: 1; overflow-y: auto; padding: 0.4rem;
}
.ep-grid {
  display: grid; grid-template-columns: repeat(8, 1fr); gap: 2px;
}
.ep-emoji-btn {
  width: 100%; aspect-ratio: 1; display: flex; align-items: center;
  justify-content: center; background: none; border: none;
  border-radius: 6px; font-size: 1.35rem; cursor: pointer;
  transition: background 0.1s, transform 0.1s; padding: 0;
}
.ep-emoji-btn:hover { background: rgba(255,255,255,0.08); transform: scale(1.15); }
.ep-emoji-img {
  width: 22px; height: 22px; object-fit: contain; display: block;
}
.ep-emoji-selected { background: var(--primary-dim); }
.ep-emoji-selected:hover { background: var(--primary-dim); }
.ep-empty {
  grid-column: 1 / -1; text-align: center; padding: 2rem 0;
  color: var(--text-muted); font-size: 0.85rem;
}
.ep-footer {
  flex-shrink: 0; padding: 0.3rem 0.6rem; border-top: 1px solid var(--border);
  color: var(--text-muted); font-size: 0.72rem; text-align: right;
  min-height: 1.4em; box-sizing: border-box;
}

/* ── Field row (side-by-side) ── */
.field-row {
  display: flex;
  gap: 0.5rem;
  align-items: flex-start;
}
.field-row > .form-group {
  flex: 1;
  min-width: 0;
}
.field-row-compact > .form-group {
  flex: 0 1 320px;
}

@media (max-width: 768px) {
  .field-row > .form-group, .field-row-compact > .form-group { flex: 0 1 auto; }
}

