/* =========================================================
   CONTENT STUDIO — chat
   History | conversation | settings. Messages are bubbles; the agent's
   reply is its console, then the post as it will look where it's posted.
========================================================= */

.chatlab {
    display: grid;
    grid-template-columns: 240px minmax(0, 1fr) 360px;
    gap: 16px;
    height: calc(100vh - var(--topbar) - 190px);
    min-height: 560px;
}

.chatlab.no-history { grid-template-columns: 0 minmax(0, 1fr) 360px; }
.chatlab.no-settings { grid-template-columns: 240px minmax(0, 1fr) 0; }
.chatlab.no-history.no-settings { grid-template-columns: 0 minmax(0, 1fr) 0; }
.chatlab.no-history .chat-history, .chatlab.no-settings .chat-settings { display: none; }

.chat-history, .chat-settings, .chat-main {
    min-height: 0;
    border: 1px solid var(--border);
    border-radius: 16px;
    background: var(--surface);
    box-shadow: var(--shadow-sm);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Pin each panel to its column explicitly — otherwise hiding .chat-history
   (display: none) removes it from grid auto-placement and the remaining
   panels shift left into the wrong (zero-width) tracks. */
.chat-history { grid-column: 1; }
.chat-main { grid-column: 2; }
.chat-settings { grid-column: 3; }

.chat-side-title { font-size: 12.5px; font-weight: 800; color: var(--text); }

/* ---------- history ---------- */

.chat-history-head, .chat-settings-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 12px 12px 10px;
    border-bottom: 1px solid var(--border);
}

.chat-history-head-actions { display: flex; align-items: center; gap: 6px; }

.chat-new {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 6px 10px;
    border: 1px solid var(--border);
    border-radius: 9px;
    background: var(--surface);
    color: var(--text-2);
    font: inherit;
    font-size: 11.5px;
    font-weight: 800;
    cursor: pointer;
}

.chat-new svg { width: 13px; height: 13px; color: var(--primary); }
.chat-new:hover { border-color: var(--primary); color: var(--primary-dark); }

.chat-collapse-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    width: 28px;
    height: 28px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
    color: var(--text-2);
    cursor: pointer;
}

.chat-collapse-btn svg { width: 15px; height: 15px; }
.chat-collapse-btn:hover { border-color: var(--primary); color: var(--primary-dark); }

.chat-history-list { flex: 1; overflow-y: auto; padding: 6px; }

.chat-day { padding: 10px 8px 4px; font-size: 10px; font-weight: 800; color: var(--text-3); letter-spacing: .03em; }

.chat-item {
    position: relative;
    display: block;
    width: 100%;
    padding: 8px 30px 8px 10px;
    border: 0;
    border-radius: 9px;
    background: none;
    font: inherit;
    text-align: left;
    cursor: pointer;
}

.chat-item:hover { background: var(--surface-soft); }
.chat-item.is-active { background: var(--primary-soft-2); }
.chat-item-title { display: block; font-size: 12px; font-weight: 700; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-item.is-active .chat-item-title { color: var(--primary-dark); }
.chat-item-meta { display: block; margin-top: 2px; font-size: 10.5px; color: var(--text-3); }

.chat-item-menu {
    position: absolute;
    top: 7px;
    right: 6px;
    display: none;
    gap: 2px;
}

.chat-item:hover .chat-item-menu, .chat-item:focus-within .chat-item-menu { display: flex; }

.chat-item-menu span {
    padding: 2px 5px;
    border-radius: 5px;
    font-size: 11px;
    color: var(--text-3);
}

.chat-item-menu span:hover { background: var(--surface); color: var(--text); }

.chat-history-empty { padding: 14px 10px; font-size: 11.5px; line-height: 1.5; color: var(--text-3); }

/* ---------- conversation ---------- */

.chat-head {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
}

.chat-icon, .chat-settings-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 8px;
    border: 1px solid var(--border);
    border-radius: 9px;
    background: var(--surface);
    font: inherit;
    font-size: 11.5px;
    font-weight: 700;
    color: var(--text-2);
    cursor: pointer;
}

.chat-icon svg, .chat-settings-btn svg { width: 15px; height: 15px; }
.chat-settings-btn[aria-expanded="true"] { border-color: var(--primary); color: var(--primary-dark); background: var(--primary-soft-2); }

.chat-title { flex: 1; min-width: 0; font-size: 14px; font-weight: 800; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.chat-thread {
    flex: 1;
    overflow-y: auto;
    padding: 18px 18px 8px;
    display: flex;
    flex-direction: column;
    gap: 18px;
    background:
        radial-gradient(circle at 1px 1px, var(--border) 1px, transparent 0) 0 0 / 22px 22px,
        var(--surface);
}

.chat-thread .lab-empty { margin: auto 0; }

.turn { display: flex; flex-direction: column; gap: 10px; }

.msg-user {
    align-self: flex-end;
    max-width: 78%;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 5px;
}

.msg-user-bubble {
    padding: 10px 14px;
    border-radius: 16px 16px 4px 16px;
    background: var(--user-bubble);
    color: #fff;
    font-size: 13px;
    line-height: 1.55;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.msg-user-bubble .msg-kind { display: block; margin-bottom: 3px; font-size: 10px; font-weight: 800; color: rgba(255, 255, 255, .8); letter-spacing: .02em; }
.msg-chips { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 4px; }

.msg-attach {
    width: 96px;
    height: 96px;
    border-radius: 12px;
    overflow: hidden;
    background: var(--identity-gradient);
}

.msg-attach img { width: 100%; height: 100%; object-fit: cover; }

.msg-agent { display: flex; gap: 10px; align-items: flex-start; }

.msg-avatar {
    flex: 0 0 30px;
    height: 30px;
    border-radius: 9px;
    background: var(--primary-gradient);
    position: relative;
}

.msg-avatar::after {
    content: "";
    position: absolute;
    inset: 7px;
    background: #fff;
    -webkit-mask: var(--emblem-mask-image) center / contain no-repeat;
            mask: var(--emblem-mask-image) center / contain no-repeat;
}

.msg-agent-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 10px; }
.msg-agent-body .agent { margin: 0; }

.msg-note { font-size: 12.5px; line-height: 1.55; color: var(--text-2); }
.msg-note b { color: var(--text); }

/* ---------- composer ---------- */

.chat-composer { padding: 10px 12px 10px; border-top: 1px solid var(--border); background: var(--surface); }

.chat-revise {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
    padding: 7px 10px;
    border-radius: 9px;
    background: var(--primary-soft-2);
    border: 1px solid var(--primary-soft);
    font-size: 12px;
    color: var(--primary-dark);
}

.chat-revise[hidden] { display: none; }
.chat-revise svg { width: 14px; height: 14px; }
.chat-revise span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-revise button { border: 0; background: none; color: inherit; cursor: pointer; font-size: 13px; }

.chat-attach-chip {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 8px 10px 0;
    padding: 5px 8px;
    border-radius: 10px;
    background: var(--primary-soft-2);
    border: 1px solid var(--primary-soft);
    font-size: 12px;
    color: var(--primary-dark);
}

.chat-attach-chip[hidden] { display: none; }

.chat-attach-thumb {
    flex: 0 0 24px;
    width: 24px;
    height: 24px;
    border-radius: 6px;
    overflow: hidden;
    background: var(--identity-gradient);
}

.chat-attach-thumb img { width: 100%; height: 100%; object-fit: cover; }

.chat-attach-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 700; }
.chat-attach-chip button { border: 0; background: none; color: inherit; cursor: pointer; font-size: 13px; }

.chat-attach-btn {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border: 1px solid var(--border);
    border-radius: 9px;
    background: var(--surface);
    color: var(--text-2);
    cursor: pointer;
}

.chat-attach-btn svg { width: 15px; height: 15px; }
.chat-attach-btn:hover { border-color: var(--primary); color: var(--primary-dark); }
.chat-attach-btn:disabled { opacity: .45; pointer-events: none; }

.chat-box {
    border: 1px solid var(--border-strong);
    border-radius: 14px;
    background: var(--surface);
    transition: border-color var(--transition), box-shadow var(--transition);
}

.chat-box:focus-within { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }

.chat-box #studioPrompt {
    width: 100%;
    min-height: 48px;
    max-height: 200px;
    resize: none;
    border: 0;
    padding: 11px 13px 4px;
    font: inherit;
    font-size: 13.5px;
    line-height: 1.55;
    color: var(--text);
    background: transparent;
    outline: none;
    box-shadow: none;
}

.chat-bar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 6px 8px 8px; }

.chat-format { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; flex: 1; min-width: 0; }
.chat-format .lab-field { display: contents; }
.chat-format .lab-label { display: none; }
.chat-format .studio-seg { width: auto; display: inline-flex; flex-wrap: nowrap; }
.chat-format #studioPlatformControl[hidden] { display: none; }

.chat-bar .lab-generate { margin-left: 0; padding: 9px 16px; }

.chat-hint { margin-top: 5px; font-size: 10.5px; color: var(--text-3); }
.chat-hint kbd {
    padding: 0 4px;
    border: 1px solid var(--border-strong);
    border-bottom-width: 2px;
    border-radius: 4px;
    font: inherit;
    font-size: 9.5px;
    font-weight: 700;
}

/* ---------- settings ---------- */

.chat-settings .lab-groups { flex: 1; overflow-y: auto; padding: 6px 8px 12px; }
.chat-settings-head .lab-note { font-size: 10.5px; }

/* =========================================================
   POST PREVIEWS — the post as it will look where it lands
========================================================= */

.post-frame { position: relative; }

.post-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.post-toolbar .btn { padding: 6px 11px; font-size: 11.5px; }
.post-toolbar .post-spacer { flex: 1; }

.post-version { font-size: 10.5px; font-weight: 700; color: var(--text-3); }
.post-version button { border: 0; background: none; padding: 0; font: inherit; color: var(--primary-dark); text-decoration: underline; cursor: pointer; }

.post-scheduled {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    padding: 9px 11px;
    border-radius: 10px;
    background: var(--success-soft);
    color: var(--success);
    font-size: 12px;
    font-weight: 700;
}

.post-scheduled input { border: 1px solid var(--border); border-radius: 7px; padding: 4px 7px; font: inherit; font-size: 11.5px; color: var(--text); background: var(--surface); }
.post-scheduled button { padding: 4px 9px; border: 1px solid var(--success); border-radius: 7px; background: var(--surface); color: var(--success); font: inherit; font-size: 11px; font-weight: 800; cursor: pointer; }

/* ---------- Instagram ---------- */

.ig {
    width: 100%;
    max-width: 420px;
    border: 1px solid #dbdbdb;
    border-radius: 12px;
    background: #fff;
    color: #0f0f0f;
    font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    overflow: hidden;
}

.ig-head { display: flex; align-items: center; gap: 9px; padding: 10px 12px; }

.brand-avatar {
    flex: 0 0 32px;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    background: var(--primary);
    color: #fff;
    font-size: 13px;
    font-weight: 800;
    overflow: hidden;
}

.brand-avatar img { width: 100%; height: 100%; object-fit: cover; background: #fff; }
.ig .brand-avatar { box-shadow: 0 0 0 2px #fff, 0 0 0 3.5px #0071db; }

.ig-handle { font-size: 13px; font-weight: 700; }
.ig-sub { font-size: 11px; color: #737373; }
.ig-more { margin-left: auto; font-size: 18px; color: #262626; letter-spacing: 1px; }

.ig .cs-media, .fb .cs-media, .tt .cs-media { border-radius: 0; min-height: 200px; background: #f4f4f4; }
.ig .cs-media img, .fb .cs-media img { max-height: none; object-fit: cover; background: #f4f4f4; }

.ig-actions { display: flex; gap: 14px; padding: 9px 12px 4px; color: #0f0f0f; }
.ig-actions svg { width: 22px; height: 22px; }
.ig-actions .ig-save { margin-left: auto; }

.ig-caption { padding: 4px 12px 12px; font-size: 13px; line-height: 1.5; white-space: pre-wrap; overflow-wrap: anywhere; }
.ig-caption b { font-weight: 700; margin-right: 5px; }
.ig-caption .tag, .fb-text .tag, .tt-caption .tag { color: #00376b; }
.ig-headline { display: block; margin-bottom: 4px; font-weight: 700; }

/* ---------- Facebook ---------- */

.fb {
    width: 100%;
    max-width: 500px;
    border: 1px solid #dddfe2;
    border-radius: 12px;
    background: #fff;
    color: #050505;
    font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    overflow: hidden;
}

.fb-head { display: flex; align-items: center; gap: 9px; padding: 12px 14px 6px; }
.fb-name { font-size: 14px; font-weight: 700; }
.fb-sub { font-size: 12px; color: #65676b; }
.fb-text { padding: 4px 14px 10px; font-size: 14.5px; line-height: 1.45; white-space: pre-wrap; overflow-wrap: anywhere; }
.fb-bar { display: grid; grid-template-columns: repeat(3, 1fr); border-top: 1px solid #ced0d4; margin: 0 12px; }
.fb-bar span { padding: 8px 0; text-align: center; font-size: 13px; font-weight: 600; color: #65676b; }

/* ---------- TikTok / Reel ---------- */

.tt {
    position: relative;
    width: 100%;
    max-width: 300px;
    aspect-ratio: 9 / 16;
    border-radius: 16px;
    background: #121212;
    color: #fff;
    overflow: hidden;
    font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

.tt .cs-media { position: absolute; inset: 0; min-height: 0; background: #121212; }
.tt .cs-media video, .tt .cs-media img { width: 100%; height: 100%; max-height: none; object-fit: cover; }
.tt-placeholder { position: absolute; inset: 0; display: grid; place-items: center; font-size: 12px; color: #aaa; }
.tt-rail { position: absolute; right: 8px; bottom: 90px; display: flex; flex-direction: column; gap: 16px; align-items: center; }
.tt-rail span { width: 34px; height: 34px; border-radius: 50%; background: rgba(255, 255, 255, .18); }
.tt-caption {
    position: absolute;
    left: 0;
    right: 50px;
    bottom: 0;
    padding: 40px 12px 14px;
    background: linear-gradient(transparent, rgba(0, 0, 0, .75));
    font-size: 12.5px;
    line-height: 1.45;
}
.tt-caption b { display: block; margin-bottom: 3px; }

/* The caption and rail sit over the video like the real app, but never take its
   clicks: a full-size button underneath plays and pauses, and they fade while it plays. */
.tt-rail, .tt-caption { pointer-events: none; transition: opacity .25s ease; z-index: 2; }
.tt.is-playing .tt-rail, .tt.is-playing .tt-caption { opacity: 0; }

.tt-play {
    position: absolute;
    inset: 0;
    z-index: 1;
    display: grid;
    place-items: center;
    padding: 0;
    border: 0;
    background: none;
    cursor: pointer;
}

.tt-play-icon {
    display: grid;
    place-items: center;
    width: 58px;
    height: 58px;
    margin-bottom: 40px;
    border-radius: 50%;
    background: rgba(0, 0, 0, .45);
    backdrop-filter: blur(4px);
    transition: opacity .2s ease, transform .2s ease;
}

.tt-play-icon svg { width: 26px; height: 26px; margin-left: 3px; fill: #fff; }
.tt-play:hover .tt-play-icon { transform: scale(1.06); background: rgba(0, 0, 0, .6); }
.tt.is-playing .tt-play-icon { opacity: 0; transform: scale(.85); }
.tt-play:focus-visible { outline: none; }
.tt-play:focus-visible .tt-play-icon { opacity: 1; box-shadow: 0 0 0 3px var(--primary); }

.tt-progress {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 3;
    height: 14px;
    cursor: pointer;
}

.tt-progress::before,
.tt-progress span {
    content: "";
    position: absolute;
    left: 0;
    bottom: 0;
    height: 3px;
    transition: height .15s ease;
}

.tt-progress::before { right: 0; background: rgba(255, 255, 255, .25); }
.tt-progress span { width: 0; background: #fff; }
.tt-progress:hover::before, .tt-progress:hover span,
.tt-progress:focus-visible::before, .tt-progress:focus-visible span { height: 6px; }
.tt-progress:focus-visible { outline: none; }
.tt-caption .tag { color: #fff; font-weight: 700; }

/* ---------- Blog ---------- */

.blog {
    width: 100%;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: #fff;
    overflow: hidden;
}

.blog .cs-media { border-radius: 0; min-height: 180px; }
.blog .cs-media img { max-height: 340px; width: 100%; object-fit: cover; }

.blog-body { padding: 18px 22px 20px; }
.blog-kicker { font-size: 11px; font-weight: 800; color: var(--primary-dark); letter-spacing: .02em; }

.blog-title {
    margin: 6px 0 8px;
    font-size: 24px;
    line-height: 1.25;
    font-weight: 800;
    letter-spacing: -0.02em;
    color: var(--text);
}

.blog-lede { margin: 0 0 12px; font-size: 14px; line-height: 1.6; color: var(--text-2); }
.blog-by { display: flex; align-items: center; gap: 8px; margin-bottom: 14px; font-size: 11.5px; color: var(--text-3); }
.blog-by .brand-avatar { flex-basis: 24px; width: 24px; height: 24px; font-size: 10px; }

.blog-article { font-size: 14px; line-height: 1.75; color: var(--text); }
.blog-article p { margin: 0 0 12px; }
.blog-article h3, .blog-article h4, .blog-article h5 { margin: 18px 0 8px; font-size: 16px; font-weight: 800; }
.blog-article ul, .blog-article ol { margin: 0 0 12px; padding-left: 22px; }
.blog.is-collapsed .blog-article { max-height: 260px; overflow: hidden; mask-image: linear-gradient(#000 70%, transparent); }
.blog-more { margin-top: 8px; border: 0; background: none; padding: 0; font: inherit; font-size: 12.5px; font-weight: 800; color: var(--primary-dark); cursor: pointer; }
.blog-seo { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 14px; }

/* the editable version of any preview */
.post-edit { display: flex; flex-direction: column; gap: 10px; padding: 12px; border: 1px dashed var(--primary); border-radius: 12px; background: var(--primary-soft-2); }
.post-edit .lab-input { background: #fff; font-size: 13px; }
.post-edit textarea.is-body { min-height: 200px; }

/* ---------- narrower screens ---------- */

@media (max-width: 1280px) {
    .chatlab, .chatlab.no-history { grid-template-columns: 0 minmax(0, 1fr) 340px; }
    .chatlab .chat-history { display: none; }
    .chatlab.show-history { grid-template-columns: 220px minmax(0, 1fr) 0; }
    .chatlab.show-history .chat-history { display: flex; }
    .chatlab.show-history .chat-settings { display: none; }
    .chatlab.no-settings { grid-template-columns: 0 minmax(0, 1fr) 0; }
}

@media (max-width: 900px) {
    .chatlab, .chatlab.no-settings, .chatlab.show-history { grid-template-columns: 1fr; height: auto; }
    .chatlab .chat-history, .chatlab .chat-main, .chatlab .chat-settings { grid-column: 1; }
    .chatlab .chat-settings { order: 3; }
    .chat-main { min-height: 70vh; }
    .msg-user { max-width: 92%; }
}

/* while revising, the format controls don't apply */
.chat-format.is-disabled { opacity: .45; pointer-events: none; }
.post-scheduled .post-spacer { flex: 1; }
.chat-format .studio-seg-btn { padding: 5px 9px; font-size: 11.5px; }

/* ---------- cross-posting ---------- */

.studio-platform-btn .studio-check {
    display: inline-grid;
    place-items: center;
    width: 13px;
    height: 13px;
    border-radius: 4px;
    border: 1px solid var(--border-strong);
    font-size: 9px;
    line-height: 1;
    color: var(--text-3);
}

.studio-platform-btn.active .studio-check {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}

.post-publications {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px 12px;
    padding: 9px 11px;
    border-radius: 10px;
    background: var(--surface-soft);
    border: 1px solid var(--border);
    font-size: 12px;
}

.post-publications ul {
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex: 1;
    min-width: 220px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.pub-row {
    display: flex;
    align-items: baseline;
    gap: 8px;
    color: var(--text-2);
}

.pub-row b {
    min-width: 72px;
    color: var(--text);
}

.pub-row b::before {
    content: "";
    display: inline-block;
    width: 7px;
    height: 7px;
    margin-right: 6px;
    border-radius: 50%;
    background: var(--text-3);
}

.pub-row.is-live b::before { background: var(--success); }
.pub-row.is-failed b::before { background: var(--danger); }
.pub-row.is-failed span { color: var(--danger); }
.pub-row a { color: var(--primary-dark); font-weight: 700; text-decoration: none; }
.pub-row a:hover { text-decoration: underline; }

/* Several platforms can be picked, so keep each control whole and let the bar wrap. */
.chat-format { min-width: min-content; }
.chat-format .studio-seg { flex-shrink: 0; }
.chat-format .studio-seg-btn { white-space: nowrap; }
.chat-bar #studioTarget { flex: 1 1 160px; min-width: 0; font-size: 11.5px; text-align: right; }
.chat-bar .lab-generate { margin-left: auto; }
