/* Webhook Studio · estilo Discord, herramienta independiente */
:root {
  --bg-deepest: #111214;
  --bg-dark: #1e1f22;
  --bg-mid: #2b2d31;
  --bg-light: #313338;
  --bg-input: #383a40;
  --bg-hover: #404249;
  --text: #dbdee1;
  --text-strong: #f2f3f5;
  --text-muted: #949ba4;
  --blurple: #5865f2;
  --blurple-hover: #4752c4;
  --link: #00a8fc;
  --green: #2dc770;
  --red: #fa777c;
  --mention-bg: rgba(88, 101, 242, .3);
  --radius: 8px;
  --font: "gg sans", "Segoe UI", "Noto Sans", Helvetica, Arial, sans-serif;
  --mono: "Cascadia Code", Consolas, "Liberation Mono", Menlo, monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg-dark);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.45;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ---------- barra superior ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--bg-deepest);
  padding: 10px 16px;
  border-bottom: 1px solid #000;
  position: sticky; top: 0; z-index: 30;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-icon { display: flex; }
.brand-text h1 { font-size: 16px; margin: 0; color: var(--text-strong); letter-spacing: .2px; }
.brand-sub { font-size: 12px; color: var(--text-muted); }
.topbar-right { display: flex; gap: 8px; }
.only-mobile { display: none; }

/* ---------- layout ---------- */
.layout {
  flex: 1;
  display: grid;
  grid-template-columns: 250px minmax(0, 1.15fr) minmax(0, 1fr);
  min-height: 0;
}

/* ---------- sidebar plantillas ---------- */
.sidebar {
  background: var(--bg-mid);
  padding: 14px 10px;
  display: flex; flex-direction: column; gap: 4px;
  overflow-y: auto;
}
.sidebar-title {
  font-size: 11px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .5px; color: var(--text-muted); padding: 0 6px 8px;
}
.template-list { display: flex; flex-direction: column; gap: 3px; }
.tpl {
  text-align: left; background: none; border: 0; color: var(--text);
  padding: 8px 10px; border-radius: 6px; cursor: pointer;
  display: flex; flex-direction: column; gap: 2px;
  font-family: var(--font);
}
.tpl:hover { background: var(--bg-hover); }
.tpl.active { background: var(--bg-light); color: var(--text-strong); }
.tpl .tpl-name { font-weight: 600; font-size: 14px; }
.tpl .tpl-tag {
  font-size: 11px; color: var(--text-muted);
  display: inline-flex; align-items: center; gap: 5px;
}
.tpl .dot { width: 7px; height: 7px; border-radius: 50%; display: inline-block; }
.dot-msg { background: var(--green); }
.dot-embed { background: var(--blurple); }
.dot-v2 { background: #f0b232; }
.sidebar-note { font-size: 12px; color: var(--text-muted); padding: 12px 6px 0; }

/* ---------- editor ---------- */
.editor {
  background: var(--bg-light);
  padding: 16px;
  overflow-y: auto;
  display: flex; flex-direction: column; gap: 14px;
}
.mode-tabs { display: flex; gap: 4px; background: var(--bg-deepest); padding: 4px; border-radius: var(--radius); }
.mode-tab {
  flex: 1; border: 0; border-radius: 6px; padding: 8px 6px;
  background: transparent; color: var(--text-muted);
  font-family: var(--font); font-size: 13.5px; font-weight: 600; cursor: pointer;
}
.mode-tab:hover { color: var(--text); }
.mode-tab.active { background: var(--blurple); color: #fff; }

.card {
  background: var(--bg-mid);
  border-radius: var(--radius);
  padding: 14px;
  display: flex; flex-direction: column; gap: 10px;
}
.card-title { font-size: 13px; font-weight: 700; color: var(--text-strong); text-transform: uppercase; letter-spacing: .4px; }
.card-head { display: flex; align-items: center; justify-content: space-between; }

.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field.grow { flex: 1; }
.field-label { font-size: 12px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: .3px; }
.field-label em { text-transform: none; font-weight: 400; font-style: normal; }
input[type="text"], input[type="url"], input[type="password"], textarea, select {
  background: var(--bg-input); border: 1px solid transparent; color: var(--text);
  border-radius: 6px; padding: 9px 10px; font-family: var(--font); font-size: 14px;
  width: 100%; outline: none;
}
input:focus, textarea:focus { border-color: var(--blurple); }
textarea { resize: vertical; min-height: 90px; line-height: 1.5; }
input::placeholder, textarea::placeholder { color: #6d6f78; }

.input-secret { display: flex; gap: 6px; }
.input-secret input { flex: 1; font-family: var(--mono); font-size: 13px; }
.eye {
  border: 0; background: var(--bg-input); color: var(--text-muted);
  border-radius: 6px; padding: 0 12px; cursor: pointer; font-size: 15px;
}
.eye:hover { color: var(--text-strong); }

.webhook-row { display: flex; gap: 10px; flex-wrap: wrap; }
.webhook-row.checks { gap: 18px; }
.check { display: flex; gap: 8px; align-items: center; font-size: 13px; color: var(--text); cursor: pointer; }
.check input { accent-color: var(--blurple); width: 15px; height: 15px; }
.hint { font-size: 12px; color: var(--text-muted); margin: 0; line-height: 1.5; }

/* toolbar markdown */
.md-toolbar { display: flex; flex-wrap: wrap; gap: 4px; }
.md-toolbar button {
  border: 0; background: var(--bg-input); color: var(--text);
  border-radius: 5px; min-width: 30px; height: 28px; padding: 0 8px;
  cursor: pointer; font-size: 13px; font-weight: 600;
}
.md-toolbar button:hover { background: var(--bg-hover); color: var(--text-strong); }
.counter { font-size: 11.5px; color: var(--text-muted); text-align: right; }
.counter.over { color: var(--red); font-weight: 700; }

/* embeds */
.embed-nav { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.embed-chip {
  border: 1px solid var(--bg-input); background: var(--bg-dark); color: var(--text);
  border-radius: 20px; padding: 4px 12px; font-size: 12.5px; cursor: pointer;
}
.embed-chip.active { border-color: var(--blurple); background: var(--mention-bg); color: var(--text-strong); }
.embed-chip.add { border-style: dashed; color: var(--text-muted); }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.color-row { display: flex; gap: 8px; align-items: center; }
.color-row input[type="color"] {
  width: 42px; height: 38px; border: 0; border-radius: 6px; background: var(--bg-input);
  padding: 3px; cursor: pointer;
}
.field-row {
  display: grid; grid-template-columns: 1fr 2fr auto auto auto; gap: 8px; align-items: end;
  background: var(--bg-dark); border-radius: 6px; padding: 8px;
}
.field-row .check { font-size: 12px; }
.mini-btn {
  border: 0; background: var(--bg-input); color: var(--text); border-radius: 5px;
  width: 28px; height: 28px; cursor: pointer; font-size: 14px; line-height: 1;
}
.mini-btn:hover { background: var(--bg-hover); }
.mini-btn.danger:hover { background: var(--red); color: #fff; }

/* v2 builder */
.v2-add { display: flex; gap: 6px; flex-wrap: wrap; }
.v2-add button {
  border: 1px dashed #4e5058; background: transparent; color: var(--text);
  border-radius: 6px; padding: 7px 12px; font-size: 13px; cursor: pointer; font-family: var(--font);
}
.v2-add button:hover { border-color: var(--blurple); color: var(--text-strong); }
.comp {
  background: var(--bg-dark); border: 1px solid #3f4147; border-radius: 6px;
  padding: 10px; display: flex; flex-direction: column; gap: 8px;
}
.comp-head { display: flex; align-items: center; gap: 8px; }
.comp-kind {
  font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .4px;
  color: var(--text-strong); background: var(--bg-input); padding: 3px 8px; border-radius: 4px;
}
.comp-tools { margin-left: auto; display: flex; gap: 4px; }
.comp .children { display: flex; flex-direction: column; gap: 8px; border-left: 3px solid var(--blurple); padding-left: 10px; }
.gallery-item { display: grid; grid-template-columns: 1fr auto; gap: 8px; }

/* sendbar + json */
.sendbar { display: flex; align-items: center; gap: 12px; }
.send-status { flex: 1; font-size: 13.5px; min-height: 20px; }
.send-status.ok { color: var(--green); }
.send-status.err { color: var(--red); white-space: pre-wrap; }
.btn {
  border: 0; border-radius: 6px; padding: 10px 18px; font-family: var(--font);
  font-size: 14px; font-weight: 600; cursor: pointer; color: #fff; background: var(--bg-input);
}
.btn-primary { background: var(--blurple); }
.btn-primary:hover { background: var(--blurple-hover); }
.btn-primary:disabled { opacity: .55; cursor: wait; }
.btn-ghost { background: transparent; color: var(--text-muted); padding: 8px 12px; }
.btn-ghost:hover { color: var(--text-strong); background: var(--bg-input); }
.json-panel { background: var(--bg-deepest); border-radius: var(--radius); padding: 14px; }
.json-panel pre {
  margin: 8px 0 0; font-family: var(--mono); font-size: 12.5px; color: #b5bac1;
  white-space: pre-wrap; word-break: break-word; max-height: 340px; overflow: auto;
}

/* ---------- vista previa Discord ---------- */
.preview { background: var(--bg-dark); display: flex; flex-direction: column; min-height: 0; }
.preview-head {
  padding: 12px 16px; font-weight: 700; color: var(--text-strong);
  border-bottom: 1px solid #232428; display: flex; align-items: center; gap: 6px;
  font-size: 15px;
}
.preview-hash { color: var(--text-muted); font-weight: 400; font-size: 20px; }
.chat { flex: 1; overflow-y: auto; padding: 16px 16px 8px; }
.chat-day {
  text-align: center; font-size: 12px; color: var(--text-muted); font-weight: 600;
  border-top: 1px solid #3f4147; margin: 8px 0 16px; position: relative; top: 0;
}
.chat-day::before { content: ""; }
.chat-day { line-height: 0; }
.chat-day span { background: var(--bg-dark); padding: 0 8px; }
.msg { display: flex; gap: 12px; padding: 4px 8px; border-radius: 6px; }
.msg:hover { background: #26272c; }
.msg-avatar { width: 40px; height: 40px; border-radius: 50%; flex-shrink: 0; overflow: hidden; background: var(--blurple); display: flex; align-items: center; justify-content: center; }
.msg-avatar img { width: 100%; height: 100%; object-fit: cover; }
.msg-body { min-width: 0; flex: 1; }
.msg-meta { display: flex; align-items: baseline; gap: 7px; }
.msg-name { color: var(--text-strong); font-weight: 600; font-size: 15px; }
.msg-badge {
  background: var(--blurple); color: #fff; font-size: 10px; font-weight: 700;
  border-radius: 4px; padding: 1.5px 5px; text-transform: uppercase; letter-spacing: .4px;
}
.msg-time { font-size: 11.5px; color: var(--text-muted); }
.msg-content { color: var(--text); word-wrap: break-word; overflow-wrap: anywhere; }
.preview-foot { padding: 10px 16px; font-size: 11.5px; color: var(--text-muted); border-top: 1px solid #232428; }

/* markdown render */
.md h1, .md h2, .md h3 { color: var(--text-strong); margin: 12px 0 6px; line-height: 1.25; }
.md h1 { font-size: 1.45em; } .md h2 { font-size: 1.25em; } .md h3 { font-size: 1.08em; }
.md h1:first-child, .md h2:first-child, .md h3:first-child { margin-top: 2px; }
.md p { margin: 4px 0; }
.md .subtext { font-size: 12.5px; color: var(--text-muted); }
.md code {
  background: #1e1f22; border: 1px solid #2b2d31; border-radius: 4px;
  font-family: var(--mono); font-size: 85%; padding: 1.5px 4px;
}
.embed-area .md code, .v2-area .md code { background: #111214; }
.md pre {
  background: #1e1f22; border: 1px solid #2b2d31; border-radius: 6px;
  padding: 8px 10px; font-family: var(--mono); font-size: 85%; overflow-x: auto; margin: 6px 0;
}
.md pre code { background: none; border: 0; padding: 0; }
.md blockquote {
  margin: 4px 0; padding: 0 0 0 10px; border-left: 4px solid #4e5058; color: var(--text);
}
.md ul { margin: 4px 0; padding-left: 20px; }
.md a { color: var(--link); text-decoration: none; }
.md a:hover { text-decoration: underline; }
.md .mention {
  background: var(--mention-bg); color: #c9cdfb; border-radius: 3px; padding: 0 3px; font-weight: 500;
}
.md .spoiler {
  background: #111214; color: transparent; border-radius: 4px; cursor: pointer;
  padding: 0 4px; user-select: none;
}
.md .spoiler.revealed { background: rgba(17, 18, 20, .35); color: var(--text); user-select: text; }
.md u { text-decoration: underline; }

/* embed clásico en preview */
.embed-area { display: flex; flex-direction: column; gap: 8px; margin-top: 4px; max-width: 516px; }
.embed {
  background: var(--bg-mid); border-radius: 4px; display: flex; overflow: hidden;
  border-left: 4px solid var(--blurple);
}
.embed-inner { padding: 12px 14px 14px; display: flex; gap: 12px; width: 100%; min-width: 0; }
.embed-main { min-width: 0; flex: 1; }
.embed-author { display: flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 600; color: var(--text-strong); margin-bottom: 6px; }
.embed-author img { width: 22px; height: 22px; border-radius: 50%; }
.embed-title { font-size: 15px; font-weight: 700; color: var(--text-strong); margin-bottom: 5px; }
.embed-title a { color: var(--link); }
.embed-desc { font-size: 13.5px; }
.embed-fields { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 8px; }
.embed-field { min-width: 0; }
.embed-field.wide { grid-column: 1 / -1; }
.embed-fname { font-size: 12px; font-weight: 700; color: var(--text-strong); margin-bottom: 2px; }
.embed-fval { font-size: 13px; }
.embed-thumb { flex-shrink: 0; }
.embed-thumb img { width: 80px; height: 80px; border-radius: 4px; object-fit: cover; }
.embed-image { margin-top: 10px; }
.embed-image img { max-width: 100%; border-radius: 4px; display: block; }
.embed-footer { display: flex; align-items: center; gap: 7px; margin-top: 10px; font-size: 11.5px; color: var(--text-muted); }
.embed-footer img { width: 18px; height: 18px; border-radius: 50%; }

/* components v2 en preview */
.v2-area { display: flex; flex-direction: column; gap: 2px; margin-top: 4px; max-width: 516px; }
.v2-text { padding: 4px 0; }
.v2-sep { border: 0; border-top: 1px solid #3f4147; margin: 8px 0; }
.v2-sep.noline { border-top-color: transparent; }
.v2-sep.lg { margin: 16px 0; }
.v2-gallery { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 6px; margin: 4px 0; }
.v2-gallery img { width: 100%; border-radius: 6px; display: block; object-fit: cover; max-height: 300px; }
.v2-section { display: flex; gap: 14px; align-items: flex-start; padding: 4px 0; }
.v2-section .sec-text { flex: 1; min-width: 0; }
.v2-section .sec-thumb { flex-shrink: 0; }
.v2-section .sec-thumb img { width: 80px; height: 80px; border-radius: 6px; object-fit: cover; }
.v2-container {
  background: var(--bg-mid); border-radius: 8px; border: 1px solid #3f4147;
  border-left: 4px solid var(--blurple); padding: 12px 14px; margin: 4px 0;
  display: flex; flex-direction: column; gap: 2px;
}
.img-fail {
  background: var(--bg-input); border-radius: 6px; color: var(--text-muted);
  font-size: 12px; padding: 18px 10px; text-align: center; word-break: break-all;
}

/* ---------- pie ---------- */
.sitefoot {
  background: var(--bg-deepest); color: var(--text-muted); font-size: 12px;
  text-align: center; padding: 10px 16px; border-top: 1px solid #000;
}

/* ---------- responsive ---------- */
@media (max-width: 1100px) {
  .layout { grid-template-columns: 220px minmax(0, 1fr); }
  .preview {
    position: fixed; inset: 0; z-index: 40; display: none;
  }
  .preview.open { display: flex; }
  .only-mobile { display: inline-block; }
}
@media (max-width: 760px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar {
    flex-direction: row; align-items: center; overflow-x: auto; padding: 8px;
    gap: 8px;
  }
  .sidebar-title, .sidebar-note { display: none; }
  .template-list { flex-direction: row; gap: 6px; }
  .tpl { white-space: nowrap; padding: 7px 12px; background: var(--bg-dark); }
  .two-col { grid-template-columns: 1fr; }
  .field-row { grid-template-columns: 1fr; }
  .embed-fields { grid-template-columns: 1fr; }
  .sendbar { position: sticky; bottom: 0; background: var(--bg-light); padding: 10px 0; }
}

.preview-head { display: flex; align-items: center; gap: 6px; }
.preview-close { margin-left: auto; padding: 5px 12px; }

.check .warn { color: #f0b232; font-size: 12px; display: block; }

/* ---------- diálogos ---------- */
.topbar-right { flex-wrap: wrap; justify-content: flex-end; align-items: center; }
dialog.dlg {
  background: var(--bg-mid); color: var(--text); border: 1px solid #000; border-radius: 10px;
  padding: 0; width: min(520px, calc(100vw - 24px)); max-height: calc(100vh - 32px);
  box-shadow: 0 12px 40px rgba(0,0,0,.6); overflow: hidden;
}
dialog.dlg[open] { display: flex; flex-direction: column; }
dialog.dlg-wide { width: min(980px, calc(100vw - 24px)); }
dialog.dlg::backdrop { background: rgba(0,0,0,.7); }
.dlg-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; padding: 18px 20px 6px; }
.dlg-head h2 { margin: 0; font-size: 18px; color: var(--text-strong); }
.dlg-sub { margin: 2px 0 0; font-size: 13px; color: var(--text-muted); }
.dlg-x { padding: 4px 10px; }
.dlg-body { padding: 8px 20px 12px; overflow-y: auto; flex: 1; min-height: 0; }
.dlg-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 20px; background: var(--bg-dark); border-top: 1px solid #000; }
.dlg-text { margin: 4px 0 10px; color: var(--text); }
.dlg-note { padding: 8px 12px; border-radius: 6px; margin: 8px 0; font-size: 13px; border-left: 3px solid var(--blurple); background: var(--bg-dark); }
.dlg-note.err { border-color: var(--red); color: var(--red); }
.dlg-note.warn { border-color: #f0b232; color: #f0b232; }
.dlg-note.ok { border-color: var(--green); color: var(--text-strong); }
.dlg-list { font-size: 13px; color: var(--text-muted); margin: 10px 0; display: grid; gap: 4px; }
.dlg textarea, .dlg input[type=text], .dlg input[type=search], .dlg select, .dlg input[type=password], .dlg input[type=file] {
  width: 100%; background: var(--bg-input); color: var(--text); border: 1px solid transparent; border-radius: 6px; padding: 8px 10px; font: inherit;
}
.dlg input:focus, .dlg textarea:focus, .dlg select:focus { outline: none; border-color: var(--blurple); }
.dlg .input-secret { display: flex; gap: 6px; }
.dlg .field { display: grid; gap: 4px; margin: 10px 0; }
.dlg .check { display: flex; gap: 8px; align-items: flex-start; margin: 8px 0; font-size: 14px; }
.dlg .send-status { margin-top: 8px; white-space: pre-line; }
.btn-danger { background: #da373c; color: #fff; }
.btn-danger:hover { background: #a12828; }
.import-result { margin-top: 8px; }

/* comunidad */
.comm-bar { display: grid; grid-template-columns: 1fr 160px 160px; gap: 8px; margin: 6px 0 10px; }
.comm-split { display: grid; grid-template-columns: 340px minmax(0, 1fr); gap: 14px; min-height: 340px; }
.comm-list { display: flex; flex-direction: column; gap: 8px; max-height: 52vh; overflow-y: auto; padding-right: 4px; }
.comm-card { text-align: left; background: var(--bg-dark); color: var(--text); border: 1px solid transparent; border-radius: 8px; padding: 10px 12px; cursor: pointer; font: inherit; }
.comm-card:hover { background: var(--bg-hover); }
.comm-card.active { border-color: var(--blurple); background: var(--bg-light); }
.comm-card-top { display: flex; justify-content: space-between; gap: 8px; align-items: center; }
.comm-card-name { font-weight: 600; color: var(--text-strong); overflow-wrap: anywhere; }
.comm-card-desc { font-size: 13px; color: var(--text-muted); margin-top: 4px; overflow-wrap: anywhere; }
.comm-card-meta { font-size: 12px; color: var(--text-muted); margin-top: 6px; }
.comm-mine { margin-left: 6px; background: var(--green); color: #000; border-radius: 4px; padding: 0 5px; font-weight: 700; font-size: 11px; }
.comm-badge { font-size: 11px; padding: 1px 6px; border-radius: 4px; background: var(--bg-input); color: var(--text-strong); white-space: nowrap; }
.comm-badge.b-embed { background: #3b4bd8; } .comm-badge.b-v2 { background: #8a6d12; } .comm-badge.b-message { background: #1f7a45; }
.comm-detail { background: var(--bg-light); border-radius: 8px; padding: 12px; min-width: 0; overflow-y: auto; max-height: 52vh; }
.comm-detail-head h3 { margin: 0; color: var(--text-strong); }
.comm-preview { background: var(--bg-light); padding: 10px 4px; border-radius: 6px; margin-top: 8px; }
.comm-actions { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.comm-placeholder, .comm-msg { color: var(--text-muted); padding: 24px 8px; text-align: center; font-size: 14px; }
.comm-empty { text-align: center; padding: 28px 10px; color: var(--text-muted); }
.comm-empty strong { color: var(--text-strong); display: block; margin-bottom: 4px; }
.comm-back { display: none; }
@media (max-width: 760px) {
  .topbar { flex-wrap: wrap; row-gap: 4px; position: static; }
  .topbar-right { width: 100%; justify-content: flex-start; flex-wrap: wrap; gap: 2px 4px; }
  .topbar-right .btn { white-space: nowrap; padding: 6px 10px; font-size: 13px; }
  .comm-bar { grid-template-columns: 1fr 1fr; } .comm-bar input { grid-column: 1 / -1; }
  .comm-split { grid-template-columns: 1fr; }
  .comm-list { max-height: 34vh; }
  .comm-detail { max-height: none; }
  dialog.dlg { max-height: calc(100vh - 16px); }
}

/* Apariencia dentro del diálogo de envío */
.ap-block { margin: 4px 0 14px; padding-bottom: 12px; border-bottom: 1px solid var(--border, rgba(255,255,255,.08)); }
.ap-block .card-title { margin-bottom: 8px; }
.ap-block .webhook-row { display: flex; gap: 12px; flex-wrap: wrap; }
.ap-block .field.grow { flex: 1 1 200px; min-width: 0; }
