/* ============================================================
   Theme
   ============================================================ */

:root {
  --bg: #313338;
  --bg-secondary: #2b2d31;
  --bg-tertiary: #1e1f22;
  --bg-elevated: #383a40;
  --bg-input: #1e1f22;

  --border: #3f4147;
  --border-light: #4e505a;

  --text: #f2f3f5;
  --text-muted: #b5bac1;
  --text-faint: #80838e;

  --accent: #5865f2;
  --accent-hover: #4752c4;
  --danger: #da373c;
  --danger-hover: #a12828;
  --success: #23a55a;

  --font: 'gg sans', 'Segoe UI', Roboto, -apple-system, BlinkMacSystemFont, sans-serif;
  --mono: 'Consolas', 'Courier New', monospace;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg-tertiary);
  color: var(--text);
  min-height: 100vh;
}

/* ============================================================
   Layout
   ============================================================ */

.app {
  display: grid;
  grid-template-columns: 1fr 460px;
  min-height: 100vh;
}

@media (max-width: 980px) {
  .app { grid-template-columns: 1fr; }
  .side { position: static; height: auto; min-height: 70vh; }
}

.builder {
  background: var(--bg-secondary);
  padding: 24px 28px 80px;
  overflow-y: auto;
}

.side {
  background: var(--bg-tertiary);
  padding: 24px;
  display: flex;
  flex-direction: column;
  border-left: 1px solid var(--border);
  position: sticky;
  top: 0;
  height: 100vh;
  align-self: start;
  overflow-y: auto;
}

/* ============================================================
   Webhook bar
   ============================================================ */

.webhook-bar {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px 16px;
  margin-bottom: 22px;
}

.webhook-bar label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--text-muted);
  letter-spacing: .3px;
  display: block;
  margin-bottom: 6px;
}

.webhook-row { display: flex; gap: 8px; }
.webhook-row input { flex: 1; }
.hint { font-size: 11.5px; color: var(--text-faint); margin-top: 6px; }

/* ============================================================
   Section headers
   ============================================================ */

.section-title {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--text-muted);
  letter-spacing: .4px;
  margin: 26px 0 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.section-title .count {
  background: var(--bg-elevated);
  color: var(--text-faint);
  font-size: 10.5px;
  padding: 2px 7px;
  border-radius: 10px;
  font-weight: 600;
}

/* ============================================================
   Form controls
   ============================================================ */

input[type=text],
input[type=url],
input[type=number],
textarea,
select {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  padding: 9px 11px;
  font-family: var(--font);
  font-size: 13.5px;
  outline: none;
  transition: border-color .12s;
  resize: vertical;
}

textarea { min-height: 64px; line-height: 1.4; }
select {
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  padding-right: 32px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M7 10l5 5 5-5' fill='none' stroke='%23b5bac1' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
  background-size: 18px;
}
select option { background: var(--bg-tertiary); color: var(--text); }

/* custom dropdown */
.dd { position: relative; }
.dd-btn {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  background: var(--bg-input);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 9px 11px;
  font-size: 13.5px;
  font-weight: 500;
  text-align: left;
}
.dd-btn:hover { border-color: var(--border-light); }
.dd-btn:focus-visible, .dd.open .dd-btn { outline: none; border-color: var(--accent); }
.dd-btn svg { width: 16px; height: 16px; color: var(--text-muted); flex-shrink: 0; transition: transform .15s; }
.dd.open .dd-btn svg { transform: rotate(180deg); }
.dd-menu {
  display: none;
  position: absolute;
  left: 0;
  right: 0;
  top: calc(100% + 4px);
  z-index: 50;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-light);
  border-radius: 8px;
  padding: 4px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .45);
}
.dd.open .dd-menu { display: block; }
.dd-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  border-radius: 5px;
  font-size: 13.5px;
  color: var(--text-muted);
  cursor: pointer;
}
.dd-item.focus, .dd-item:hover { background: var(--bg-elevated); color: var(--text); }
.dd-item.selected { color: var(--text); font-weight: 600; }
.dd-item.selected::after { content: '✓'; color: var(--accent); font-weight: 700; }
input::placeholder,
textarea::placeholder { color: var(--text-faint); }
input:focus,
textarea:focus,
select:focus { border-color: var(--accent); }

/* red outline shown on a field the payload validator flagged as invalid */
.field-warn { border-color: rgba(218, 55, 60, .55) !important; }
.field-warn-note { font-size: 11px; color: #ff8a8d; margin-top: 4px; }

.field { margin-bottom: 12px; }
.field label {
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-muted);
  display: block;
  margin-bottom: 5px;
}

.field-row { display: flex; gap: 10px; }
.field-row > .field { flex: 1; }

/* ============================================================
   Buttons
   ============================================================ */

button {
  font-family: var(--font);
  cursor: pointer;
  border: none;
  border-radius: 6px;
  font-weight: 600;
  transition: background .12s, opacity .12s, transform .05s;
}
button:active { transform: scale(.98); }

.btn-primary { background: var(--accent); color: #fff; padding: 9px 16px; font-size: 13.5px; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:disabled { opacity: .5; cursor: not-allowed; }

.btn-secondary { background: var(--bg-elevated); color: var(--text); padding: 9px 14px; font-size: 13px; }
.btn-secondary:hover { background: var(--border-light); }

.btn-add {
  width: 100%;
  background: var(--bg-elevated);
  color: var(--text-muted);
  border: 1px dashed var(--border-light);
  padding: 10px;
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
.btn-add:hover { background: var(--border-light); color: var(--text); border-style: solid; }

.empty-state {
  text-align: center;
  color: var(--text-faint);
  font-size: 12.5px;
  padding: 22px 10px;
  border: 1px dashed var(--border);
  border-radius: 8px;
  margin-bottom: 10px;
}

/* ============================================================
   Component blocks (the cards in the builder panel)
   ============================================================ */

.block {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-left: 3px solid var(--border-light);
  border-radius: 8px;
  padding: 14px 14px 12px;
  margin-bottom: 10px;
  transition: box-shadow .12s;
}

/* color-code the left border by component type so the builder is scannable */
.block.type-container { border-left-color: #5865f2; }
.block.type-section { border-left-color: #23a55a; }
.block.type-text { border-left-color: #f0b232; }
.block.type-separator { border-left-color: var(--text-faint); }
.block.type-gallery { border-left-color: #eb459e; }
.block.type-actionrow { border-left-color: #da373c; }

.block.dragging { opacity: .4; }
.block.drag-over-top { box-shadow: inset 0 2px 0 var(--accent); }
.block.drag-over-bottom { box-shadow: inset 0 -2px 0 var(--accent); }

.drag-handle {
  cursor: grab;
  color: var(--text-faint);
  font-size: 14px;
  line-height: 1;
  user-select: none;
  letter-spacing: -1px;
}
.drag-handle:hover { color: var(--text); }
.drag-handle:active { cursor: grabbing; }

.block-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}
.block-head .tag {
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .4px;
  color: var(--text-faint);
}
.block-head .left { display: flex; align-items: center; gap: 8px; }

.block-controls { display: flex; gap: 4px; align-items: center; }
.icon-btn {
  background: transparent;
  border: none;
  color: var(--text-faint);
  width: 24px;
  height: 24px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  line-height: 1;
}
.icon-btn:hover { background: var(--bg-elevated); color: var(--text); }
.icon-btn.danger:hover { color: var(--danger); }

.nested {
  padding-left: 14px;
  border-left: 2px solid var(--border);
  margin-top: 10px;
}

/* ============================================================
   Container-specific controls
   ============================================================ */

.color-row { display: flex; align-items: center; gap: 10px; }
.color-row input[type=color] {
  width: 38px;
  height: 32px;
  padding: 2px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
}

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-elevated);
  border-radius: 6px;
  padding: 9px 12px;
  margin-bottom: 10px;
}
.toggle-row .label-wrap { display: flex; flex-direction: column; gap: 1px; }
.toggle-row .label-wrap .title { font-size: 12.5px; font-weight: 600; color: var(--text); }
.toggle-row .label-wrap .sub { font-size: 11px; color: var(--text-faint); }

.switch { position: relative; width: 34px; height: 20px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch .slider {
  position: absolute;
  inset: 0;
  background: var(--border-light);
  border-radius: 20px;
  cursor: pointer;
  transition: background .15s;
}
.switch .slider::before {
  content: '';
  position: absolute;
  width: 14px;
  height: 14px;
  left: 3px;
  top: 3px;
  background: #fff;
  border-radius: 50%;
  transition: transform .15s;
}
.switch input:checked + .slider { background: var(--accent); }
.switch input:checked + .slider::before { transform: translateX(14px); }

/* ============================================================
   Section-specific controls
   ============================================================ */

.accessory-toggle { display: flex; gap: 6px; margin-bottom: 8px; }
.accessory-toggle button {
  flex: 1;
  background: var(--bg-elevated);
  color: var(--text-faint);
  padding: 7px;
  font-size: 11.5px;
  border: 1px solid transparent;
}
.accessory-toggle button.active {
  background: rgba(88, 101, 242, .15);
  color: #8e9aff;
  border-color: rgba(88, 101, 242, .4);
}

/* ============================================================
   Add-component menu
   ============================================================ */

.add-menu {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin-bottom: 10px;
}
.add-menu button {
  background: var(--bg-elevated);
  color: var(--text-muted);
  padding: 10px 8px;
  font-size: 12px;
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}
.add-menu button:hover { background: var(--border-light); color: var(--text); }
.add-menu button svg { width: 16px; height: 16px; fill: currentColor; }

/* ============================================================
   Send status message
   ============================================================ */

.status-msg {
  margin-top: 10px;
  font-size: 12.5px;
  padding: 9px 12px;
  border-radius: 6px;
  display: none;
}
.status-msg.show { display: block; }
.status-msg.ok {
  background: rgba(35, 165, 90, .12);
  color: #5fd88a;
  border: 1px solid rgba(35, 165, 90, .3);
}
.status-msg.err {
  background: rgba(218, 55, 60, .12);
  color: #ff7376;
  border: 1px solid rgba(218, 55, 60, .3);
}

/* ============================================================
   Right panel: preview / JSON tabs
   ============================================================ */

.side-tabs {
  display: flex;
  gap: 4px;
  background: var(--bg-tertiary);
  border-radius: 8px;
  padding: 4px;
  margin-bottom: 16px;
}
.side-tabs button {
  flex: 1;
  background: transparent;
  color: var(--text-muted);
  padding: 8px;
  font-size: 12.5px;
  border-radius: 6px;
}
.side-tabs button.active { background: var(--bg-elevated); color: var(--text); }

.preview-wrap { display: none; flex: 1; }
.preview-wrap.active { display: block; }
.json-wrap { display: none; flex: 1; flex-direction: column; }
.json-wrap.active { display: flex; }

.discord-msg { display: flex; gap: 14px; padding: 2px 0; }
.avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--accent);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  font-weight: 700;
  color: #fff;
}
.msg-body { flex: 1; min-width: 0; }
.msg-author-row { display: flex; align-items: baseline; gap: 8px; margin-bottom: 2px; }
.msg-author { font-size: 14.5px; font-weight: 600; color: var(--text); }
.msg-badge {
  background: var(--accent);
  color: #fff;
  font-size: 9.5px;
  font-weight: 700;
  padding: 1px 4px;
  border-radius: 3px;
  text-transform: uppercase;
}
.msg-time { font-size: 11px; color: var(--text-faint); }

/* ---- Components V2 render (mimics the real Discord layout) ---- */

.cv2-root { display: flex; flex-direction: column; gap: 8px; margin-top: 2px; }

.cv2-container {
  border-left: 4px solid var(--border-light);
  background: var(--bg-elevated);
  border-radius: 4px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.cv2-container.no-accent { border-left-color: transparent; padding-left: 12px; }

.cv2-text { font-size: 14px; line-height: 1.375; color: var(--text); white-space: pre-wrap; word-break: break-word; }

.cv2-section { display: flex; align-items: center; gap: 12px; }
.cv2-section-text { flex: 1; display: flex; flex-direction: column; gap: 4px; }
.cv2-thumb { width: 80px; height: 80px; border-radius: 4px; object-fit: cover; background: var(--bg-elevated); flex-shrink: 0; }
.cv2-btn-accessory {
  background: var(--bg-elevated);
  color: var(--text);
  padding: 8px 14px;
  font-size: 13px;
  border-radius: 4px;
  white-space: nowrap;
  border: 1px solid var(--border-light);
}

.cv2-separator { height: 1px; background: var(--border); margin: 4px 0; }

.cv2-gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(80px, 1fr)); gap: 4px; }
.cv2-gallery img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 4px; background: var(--bg-elevated); }

.cv2-actionrow { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 2px; }
.cv2-actionrow button {
  background: var(--bg-elevated);
  color: var(--text);
  padding: 8px 16px;
  font-size: 13.5px;
  border-radius: 4px;
  border: 1px solid var(--border-light);
  font-weight: 500;
}

.placeholder-preview { color: var(--text-faint); font-size: 13px; text-align: center; padding: 60px 20px; }

pre#jsonOut {
  flex: 1;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.55;
  color: #c9d1d9;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  margin: 0 0 10px;
}
.json-actions { display: flex; gap: 8px; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--bg-elevated); border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: var(--border-light); }


/* ============================================================
   Animations
   ============================================================ */

html { scroll-behavior: smooth; }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes slideInRight { from { opacity: 0; transform: translateX(18px); } to { opacity: 1; transform: none; } }
@keyframes blockIn { from { opacity: 0; transform: translateY(-8px) scale(.97); } to { opacity: 1; transform: none; } }
@keyframes blockOut { to { opacity: 0; transform: translateX(28px) scale(.95); } }
@keyframes pop { 0% { transform: scale(1); } 40% { transform: scale(1.4); } 100% { transform: scale(1); } }
@keyframes flash { 0% { box-shadow: 0 0 0 2px rgba(88, 101, 242, .9); } 100% { box-shadow: 0 0 0 2px rgba(88, 101, 242, 0); } }
@keyframes ddIn { from { opacity: 0; transform: translateY(-6px) scale(.97); } to { opacity: 1; transform: none; } }
@keyframes ripple { to { transform: scale(2.6); opacity: 0; } }
@keyframes stripes { to { background-position: 28px 0; } }
@keyframes warnIn { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }
@keyframes shake { 0%, 100% { transform: translateX(0); } 25% { transform: translateX(-5px); } 75% { transform: translateX(5px); } }

/* page load */
.builder { animation: slideUp .5s cubic-bezier(.2, .8, .2, 1) both; }
.side { animation: slideInRight .5s .08s cubic-bezier(.2, .8, .2, 1) both; }
.webhook-bar { transition: border-color .2s; }
.webhook-bar:focus-within { border-color: var(--accent); }
.empty-state { animation: fadeIn .3s ease; }

/* builder blocks */
.block { transition: box-shadow .15s, border-color .15s, transform .15s, opacity .15s; }
.block:hover { border-top-color: var(--border-light); border-right-color: var(--border-light); border-bottom-color: var(--border-light); }
.block.enter { animation: blockIn .3s cubic-bezier(.2, .8, .2, 1); }
.block.leaving { animation: blockOut .2s ease forwards; pointer-events: none; }
.block.flash { animation: flash .9s ease-out; }
.block.dragging { transform: scale(.985); }
.section-title .count.pop { animation: pop .3s ease; }

/* inputs */
input, textarea, select { transition: border-color .15s, box-shadow .15s; }
input:focus, textarea:focus, select:focus { box-shadow: 0 0 0 3px rgba(88, 101, 242, .2); }
.field-warn-note { animation: warnIn .2s ease; }

/* buttons */
.btn-primary, .btn-secondary, .btn-add, .add-menu button { position: relative; overflow: hidden; }
.btn-primary:hover:not(:disabled) { transform: translateY(-1px); box-shadow: 0 4px 14px rgba(88, 101, 242, .4); }
.btn-secondary:hover, .btn-add:hover, .add-menu button:hover { transform: translateY(-1px); }
.btn-primary:active:not(:disabled), .btn-secondary:active, .btn-add:active, .add-menu button:active { transform: scale(.97); }
.btn-primary.sending {
  background-image: linear-gradient(45deg, rgba(255,255,255,.18) 25%, transparent 25%, transparent 50%, rgba(255,255,255,.18) 50%, rgba(255,255,255,.18) 75%, transparent 75%);
  background-size: 28px 28px;
  animation: stripes .6s linear infinite;
}
.ripple { position: absolute; border-radius: 50%; background: rgba(255, 255, 255, .3); transform: scale(0); animation: ripple .6s ease-out forwards; pointer-events: none; }
.icon-btn { transition: background .12s, color .12s, transform .12s; }
.icon-btn:hover:not(:disabled) { transform: scale(1.15); }
.drag-handle { transition: color .12s, transform .12s; }
.drag-handle:hover { transform: scale(1.2); }
.accessory-toggle button, .side-tabs button { transition: background .2s, color .2s, border-color .2s; }
.toggle-row { transition: background .15s; }
.toggle-row:hover { background: #3e4047; }

/* dropdown */
.dd.open .dd-menu { animation: ddIn .16s ease-out; transform-origin: top; }
.dd-item { transition: background .12s, color .12s, padding-left .12s; }
.dd-item:hover { padding-left: 14px; }

/* status + tabs */
.status-msg.show { animation: slideUp .3s ease; }
.status-msg.err.show { animation: slideUp .3s ease, shake .4s .1s; }
.preview-wrap.active, .json-wrap.active { animation: fadeIn .25s ease; }

/* preview */
.pv-enter { animation: slideUp .3s cubic-bezier(.2, .8, .2, 1); }
.avatar { transition: transform .25s; }
.avatar:hover { transform: rotate(-6deg) scale(1.08); }
.cv2-container { transition: filter .35s ease; }
.cv2-gallery img { transition: transform .2s, opacity .2s; }
.cv2-gallery img:hover { transform: scale(1.04); }
.cv2-actionrow button, .cv2-btn-accessory { transition: background .15s, transform .15s; }
.cv2-actionrow button:hover, .cv2-btn-accessory:hover { background: var(--border-light); transform: translateY(-1px); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
    scroll-behavior: auto !important;
  }
}


/* markdown rendering in the preview */
.md-link { color: #00a8fc; text-decoration: none; }
.md-link:hover { text-decoration: underline; }
.md-code { background: var(--bg-tertiary); border: 1px solid var(--border); padding: 1px 4px; border-radius: 3px; font-family: var(--mono); font-size: 12.5px; }
.md-pre { display: block; padding: 8px 10px; margin: 4px 0; white-space: pre-wrap; border-radius: 4px; }
.md-h1 { font-size: 1.5em; font-weight: 700; line-height: 1.25; margin: 6px 0 2px; }
.md-h2 { font-size: 1.25em; font-weight: 700; line-height: 1.25; margin: 6px 0 2px; }
.md-h3 { font-size: 1.1em; font-weight: 700; line-height: 1.25; margin: 4px 0 2px; }
.md-sub { font-size: 12px; color: var(--text-muted); }
.md-quote { border-left: 4px solid #4e5058; padding-left: 10px; margin: 2px 0; }
.md-list { margin: 2px 0; padding-left: 24px; }
.md-mention { background: rgba(88, 101, 242, .3); color: #c9cdfb; border-radius: 3px; padding: 0 2px; font-weight: 500; }
.spoiler { background: #1e1f22; border-radius: 3px; padding: 0 2px; cursor: pointer; transition: background .2s; }
.spoiler:not(.revealed) { color: transparent; }
.spoiler:not(.revealed) * { color: transparent !important; opacity: 0; }
.spoiler.revealed { background: rgba(255, 255, 255, .1); }

.md-b { font-weight: 700; }
.md-i { font-style: italic; }
.md-u { text-decoration: underline; }
.md-s { text-decoration: line-through; }
