/* ============================================================
   EVL CMS — Embed Builder
   Two-pane editor + Discord-accurate preview.
   Uses the dashboard tokens (--surface, --line, --ink…) so it
   inherits the light/dark theme. Loaded after styles.css.
   ============================================================ */

/* ---------- shell ---------- */

.eb-modal {
    padding: 28px 20px;
    align-items: flex-start;
}

.eb-modal .eb-shell {
    width: min(1280px, 96vw) !important;
    max-width: 1280px !important;
    max-height: calc(100vh - 56px);
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* ---------- header ---------- */

.eb-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 18px;
    padding: 20px 24px 16px;
    border-bottom: 1px solid var(--line);
    flex-shrink: 0;
}

.eb-head-text { min-width: 0; }

.eb-modal .eb-head h2 {
    margin: 0;
    padding: 0;
    border: none !important;
    font-family: var(--evl-serif);
    font-size: 1.45rem;
    line-height: 1.2;
    color: var(--ink);
}

.eb-context {
    margin: 4px 0 0;
    font-size: 13px;
    color: var(--ink-3);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.eb-head-tools {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.eb-ghost {
    height: 34px;
    padding: 0 14px;
    border-radius: var(--r-pill);
    border: 1px solid var(--line);
    background: var(--surface-2);
    color: var(--ink-2);
    font: 600 13px/1 var(--evl-sans);
    cursor: pointer;
    transition: border-color .18s var(--evl-ease), color .18s var(--evl-ease), background .18s var(--evl-ease);
}

.eb-ghost:hover {
    color: var(--evl-cyan);
    border-color: var(--evl-cyan);
    background: var(--evl-grad-soft);
}

.eb-x {
    width: 34px;
    height: 34px;
    border: none;
    border-radius: 50%;
    background: transparent;
    color: var(--ink-4);
    font-size: 24px;
    line-height: 1;
    cursor: pointer;
    transition: color .18s, background .18s;
}

.eb-x:hover { color: var(--ink); background: var(--surface-2); }

/* ---------- JSON panel ---------- */

.eb-json-panel {
    flex-shrink: 0;
    padding: 16px 24px;
    border-bottom: 1px solid var(--line);
    background: var(--surface-2);
}

.eb-json-text {
    width: 100%;
    min-height: 150px;
    max-height: 34vh;
    font: 12.5px/1.55 ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
    resize: vertical;
}

.eb-json-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    margin-top: 10px;
    flex-wrap: wrap;
}

/* ---------- body: editor | preview ---------- */

.eb-body {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 0;
    min-height: 0;   /* lets the children scroll instead of the page */
    flex: 1;
}

.eb-editor {
    min-width: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 18px 22px 26px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

/* Sections keep their natural height instead of being squeezed by the column */
.eb-editor > * { flex: 0 0 auto; }

.eb-preview {
    min-width: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 18px 22px 26px;
    border-left: 1px solid var(--line);
    background: var(--surface-2);
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.eb-editor::-webkit-scrollbar,
.eb-preview::-webkit-scrollbar { width: 8px; }

.eb-preview-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
}

.eb-preview-label {
    font: 700 11px/1 var(--evl-sans);
    letter-spacing: .12em;
    text-transform: uppercase;
    color: var(--ink-3);
}

.eb-total {
    font: 600 12px/1 var(--evl-sans);
    color: var(--ink-3);
    padding: 5px 10px;
    border-radius: var(--r-pill);
    background: var(--surface-3);
    white-space: nowrap;
}

.eb-total.is-over,
.eb-count.is-over { color: #ef4444; }

/* ---------- editor sections ---------- */

.eb-section {
    border: 1px solid var(--line);
    border-radius: var(--r-md);
    background: var(--surface);
    overflow: hidden;
}

.eb-summary {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 14px;
    cursor: pointer;
    list-style: none;
    user-select: none;
}

.eb-summary::-webkit-details-marker { display: none; }
.eb-summary:hover { background: var(--surface-2); }

.eb-summary-title {
    font: 700 13.5px/1.2 var(--evl-sans);
    color: var(--ink);
    flex-shrink: 0;
}

.eb-summary-meta {
    flex: 1;
    min-width: 0;
    font-size: 12px;
    color: var(--ink-4);
    text-align: right;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.eb-chevron {
    flex-shrink: 0;
    color: var(--ink-4);
    transition: transform .2s var(--evl-ease);
}

.eb-section[open] > .eb-summary .eb-chevron { transform: rotate(180deg); }

.eb-section-body {
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    border-top: 1px solid var(--line-2);
}

.eb-section-body > * { flex: 0 0 auto; }
.eb-fields > * { flex: 0 0 auto; }

/* ---------- form controls ---------- */

.eb-field {
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 0;
}

.eb-label {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 10px;
    font: 700 11px/1.3 var(--evl-sans);
    letter-spacing: .06em;
    text-transform: uppercase;
    color: var(--ink-3);
}

.eb-count {
    font-size: 10.5px;
    font-weight: 600;
    letter-spacing: 0;
    color: var(--ink-4);
    flex-shrink: 0;
    font-variant-numeric: tabular-nums;
}

.eb-hint {
    font-size: 11.5px;
    color: var(--ink-4);
}

.eb-optional { text-transform: none; letter-spacing: 0; color: var(--ink-4); font-weight: 500; }

.eb-input {
    width: 100%;
    min-width: 0;
    padding: 10px 12px;
    background: var(--surface);
    color: var(--ink);
    border: 1px solid var(--line);
    border-radius: var(--r-sm);
    font: 14px/1.45 var(--evl-sans);
    transition: border-color .16s var(--evl-ease), box-shadow .16s var(--evl-ease);
}

[data-theme="dark"] .eb-input { background: var(--app-bg); }

.eb-input::placeholder { color: var(--ink-4); }

.eb-input:focus {
    outline: none;
    border-color: var(--evl-cyan);
    box-shadow: 0 0 0 3px var(--ring);
}

.eb-textarea { resize: vertical; min-height: 62px; }
.eb-textarea-lg { min-height: 130px; }

.eb-grid-2 {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 14px;
}

.eb-check {
    flex-direction: row;
    align-items: center;
    gap: 9px;
    align-self: end;
    padding-bottom: 10px;
    font: 600 13.5px/1 var(--evl-sans);
    color: var(--ink-2);
    cursor: pointer;
}

.eb-check input { width: 17px; height: 17px; accent-color: var(--evl-cyan); cursor: pointer; }

/* ---------- colour ---------- */

.eb-color-row {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.eb-color {
    width: 44px;
    height: 42px;
    padding: 3px;
    border: 1px solid var(--line);
    border-radius: var(--r-sm);
    background: var(--surface);
    cursor: pointer;
    flex-shrink: 0;
}

.eb-color-hex {
    width: 104px;
    flex-shrink: 0;
    font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
    text-transform: lowercase;
}

.eb-swatches {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    min-width: 0;
}

.eb-swatch {
    width: 24px;
    height: 24px;
    border-radius: 7px;
    border: 1px solid rgba(0, 0, 0, .18);
    background: var(--sw);
    cursor: pointer;
    transition: transform .15s var(--evl-ease), box-shadow .15s var(--evl-ease);
}

.eb-swatch:hover { transform: translateY(-2px); box-shadow: 0 5px 12px -5px rgba(0, 0, 0, .5); }

/* ---------- fields ---------- */

.eb-fields {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.eb-field-card {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: var(--r-sm);
    background: var(--surface-2);
    min-width: 0;
}

.eb-field-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    flex-wrap: wrap;
}

.eb-field-num {
    font: 700 11px/1 var(--evl-sans);
    letter-spacing: .08em;
    text-transform: uppercase;
    color: var(--ink-4);
}

.eb-field-tools {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}

.eb-inline-toggle {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 9px;
    border-radius: var(--r-pill);
    background: var(--surface-3);
    font: 600 11.5px/1 var(--evl-sans);
    color: var(--ink-2);
    cursor: pointer;
    white-space: nowrap;
}

.eb-inline-toggle input { width: 14px; height: 14px; accent-color: var(--evl-cyan); cursor: pointer; }

.eb-icon-btn {
    width: 27px;
    height: 27px;
    border-radius: 8px;
    border: 1px solid var(--line);
    background: var(--surface);
    color: var(--ink-3);
    font-size: 14px;
    line-height: 1;
    cursor: pointer;
    transition: all .16s var(--evl-ease);
}

.eb-icon-btn:hover:not(:disabled) { color: var(--evl-cyan); border-color: var(--evl-cyan); }
.eb-icon-btn:disabled { opacity: .35; cursor: not-allowed; }
.eb-icon-danger:hover:not(:disabled) { color: #ef4444; border-color: rgba(239, 68, 68, .5); }

.eb-add {
    align-self: flex-start;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 9px 16px;
    border-radius: var(--r-pill);
    border: 1px dashed var(--line);
    background: transparent;
    color: var(--ink-2);
    font: 600 13px/1 var(--evl-sans);
    cursor: pointer;
    transition: all .18s var(--evl-ease);
}

.eb-add:hover:not(:disabled) { color: var(--evl-cyan); border-color: var(--evl-cyan); background: var(--evl-grad-soft); }
.eb-add:disabled { opacity: .45; cursor: not-allowed; }
.eb-add-plus { font-size: 15px; line-height: 1; }

.eb-empty {
    margin: 0;
    font-size: 13px;
    color: var(--ink-4);
    line-height: 1.5;
}

/* ---------- footer ---------- */

.eb-foot {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
    padding: 14px 24px;
    border-top: 1px solid var(--line);
    background: var(--surface);
}

.eb-foot-note {
    font-size: 12.5px;
    color: var(--ink-4);
    min-width: 0;
    flex: 1 1 220px;
}

.eb-foot-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

/* ============================================================
   Discord preview — fixed Discord colours in both themes
   ============================================================ */

.dc-preview {
    background: #313338;
    border: 1px solid rgba(0, 0, 0, .35);
    border-radius: var(--r-md);
    padding: 16px;
    min-width: 0;
    overflow: hidden;
    font-family: "gg sans", "Inter", system-ui, sans-serif;
}

.dc-msg { display: flex; gap: 14px; min-width: 0; }

.dc-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    flex-shrink: 0;
    background: #5865F2;
    object-fit: cover;
}

.dc-msg-body { min-width: 0; flex: 1; }

.dc-msg-head {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 3px;
}

.dc-name { color: #f2f3f5; font-weight: 600; font-size: 15px; }

.dc-tag {
    background: #5865F2;
    color: #fff;
    font-size: 10px;
    font-weight: 600;
    letter-spacing: .02em;
    padding: 1px 5px;
    border-radius: 4px;
    text-transform: uppercase;
}

.dc-time { color: #949ba4; font-size: 12px; }

.dc-content {
    color: #dbdee1;
    font-size: 15px;
    line-height: 1.45;
    margin-bottom: 8px;
    overflow-wrap: anywhere;
}

.dc-embed {
    position: relative;
    max-width: 520px;
    background: #2b2d31;
    border-radius: 4px;
    border-left: 4px solid var(--dc-accent, #33bdef);
    padding: 12px 16px 14px;
    min-width: 0;
}

.dc-embed-grid {
    display: flex;
    gap: 14px;
    align-items: flex-start;
    min-width: 0;
}

.dc-embed-main { flex: 1; min-width: 0; }

.dc-author {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
    min-width: 0;
}

.dc-author-icon { width: 24px; height: 24px; border-radius: 50%; flex-shrink: 0; object-fit: cover; }

.dc-author-name {
    color: #f2f3f5;
    font-size: 14px;
    font-weight: 600;
    overflow-wrap: anywhere;
}

.dc-title {
    display: block;
    color: #f2f3f5;
    font-size: 16px;
    font-weight: 600;
    line-height: 1.35;
    margin-bottom: 8px;
    overflow-wrap: anywhere;
}

a.dc-title { color: #00a8fc; }
a.dc-title:hover { text-decoration: underline; }

.dc-description {
    color: #dbdee1;
    font-size: 14px;
    line-height: 1.45;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.dc-fields {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 10px;
}

.dc-field-row {
    display: flex;
    gap: 12px;
    min-width: 0;
}

.dc-field { min-width: 0; flex: 1 1 0; }

.dc-field-name {
    color: #f2f3f5;
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 2px;
    overflow-wrap: anywhere;
}

.dc-field-value {
    color: #dbdee1;
    font-size: 13.5px;
    line-height: 1.4;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.dc-thumb {
    width: 80px;
    height: 80px;
    border-radius: 4px;
    object-fit: cover;
    flex-shrink: 0;
}

.dc-image {
    display: block;
    width: 100%;
    max-width: 100%;
    margin-top: 12px;
    border-radius: 4px;
}

.dc-footer {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 10px;
    min-width: 0;
}

.dc-footer-icon { width: 20px; height: 20px; border-radius: 50%; flex-shrink: 0; object-fit: cover; }

.dc-footer-text {
    color: #949ba4;
    font-size: 12px;
    line-height: 1.4;
    overflow-wrap: anywhere;
}

.dc-dot { margin: 0 2px; }

.dc-embed-placeholder {
    padding: 20px;
    border: 1px dashed rgba(255, 255, 255, .16);
    border-radius: 6px;
    color: #949ba4;
    font-size: 13px;
    text-align: center;
}

/* markdown bits */
.dc-link { color: #00a8fc; text-decoration: none; overflow-wrap: anywhere; }
.dc-link:hover { text-decoration: underline; }
.dc-code {
    background: #1e1f22;
    border-radius: 3px;
    padding: 1px 4px;
    font-family: ui-monospace, Consolas, monospace;
    font-size: 85%;
}
.dc-codeblock {
    background: #1e1f22;
    border: 1px solid #2b2d31;
    border-radius: 4px;
    padding: 8px 10px;
    margin: 6px 0;
    font-family: ui-monospace, Consolas, monospace;
    font-size: 12.5px;
    color: #dbdee1;
    white-space: pre-wrap;
    overflow-x: auto;
}
.dc-quote { border-left: 4px solid #4e5058; padding-left: 10px; margin: 3px 0; }
.dc-spoiler { background: #1e1f22; color: transparent; border-radius: 3px; }
.dc-spoiler:hover { color: inherit; }
.dc-h1 { font-size: 19px; font-weight: 700; color: #f2f3f5; margin: 6px 0 3px; }
.dc-h2 { font-size: 17px; font-weight: 700; color: #f2f3f5; margin: 6px 0 3px; }
.dc-h3 { font-size: 15px; font-weight: 700; color: #f2f3f5; margin: 6px 0 3px; }

/* ============================================================
   Saved embed cards (Announcements tab)
   ============================================================ */

.embeds-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 18px;
}

.embed-card {
    display: flex;
    flex-direction: column;
    gap: 14px;
    padding: 20px !important;
    min-width: 0;
}

.embed-card-preview {
    border-left: 3px solid var(--embed-accent, var(--evl-cyan));
    padding-left: 12px;
    min-width: 0;
}

.embed-card-preview h4 {
    margin: 0 0 5px;
    font-size: 15px;
    font-weight: 700;
    color: var(--ink);
    overflow-wrap: anywhere;
}

.embed-card-preview p {
    margin: 0;
    font-size: 13px;
    line-height: 1.5;
    color: var(--ink-3);
    display: -webkit-box;
    -webkit-line-clamp: 3;
    line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.embed-card-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    font-size: 12px;
    color: var(--ink-4);
    margin-top: auto;
}

.embed-card-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--embed-accent, var(--evl-cyan));
    flex-shrink: 0;
}

.embed-card-sep { color: var(--ink-4); }
.embed-card-link { color: var(--evl-cyan); text-decoration: none; font-weight: 600; }
.embed-card-link:hover { text-decoration: underline; }

.embed-card-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    padding-top: 12px;
    border-top: 1px solid var(--line);
}

/* ============================================================
   Responsive
   ============================================================ */

@media (max-width: 1080px) {
    .eb-body { grid-template-columns: minmax(0, 1fr); }
    .eb-modal .eb-shell { max-height: calc(100vh - 32px); }
    .eb-editor { overflow: visible; }
    .eb-preview {
        border-left: none;
        border-top: 1px solid var(--line);
        overflow: visible;
    }
    .eb-body { overflow-y: auto; }
}

@media (max-width: 620px) {
    .eb-modal { padding: 12px 8px; }
    .eb-head { padding: 16px 16px 12px; flex-wrap: wrap; }
    .eb-editor, .eb-preview { padding: 14px 14px 20px; }
    .eb-json-panel { padding: 14px 16px; }
    .eb-foot { padding: 12px 16px; }
    .eb-foot-actions { width: 100%; }
    .eb-foot-actions button { flex: 1 1 auto; }
    .dc-preview { padding: 12px; }
    .dc-field-row { flex-direction: column; gap: 8px; }
}
