/* ─────────────────────────────────────────────────────────────
   GHOST — connection chip, responsive header, unified search cards
   Loaded last so it wins over style.css / ghost-premium.css.
   ───────────────────────────────────────────────────────────── */

/* 1. Header: title and the ••• menu can never overlap ------------------ */

.sidebar-topbar {
    display: flex !important;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    min-width: 0;
    flex-shrink: 0 !important;
}

.sidebar-topbar > .brand-row {
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
}

.brand-copy {
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
}

.brand-title,
.brand-subtitle {
    display: block;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sidebar-topbar > .more-button {
    flex: 0 0 auto;
    margin-left: auto;
    order: 3;
    align-self: flex-start;
}

.sidebar-topbar > .popover-menu {
    right: 8px;
    left: auto;
    max-width: calc(100vw - 24px);
}

/* 2. Connection chip --------------------------------------------------- */

.ghost-connect-chip {
    order: unset !important;
    flex: 0 0 auto !important;
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    min-width: 0 !important;
    padding: 0 !important;
    border: none !important;
    background: transparent !important;
    margin-left: 6px !important;
}

.ghost-connect-chip .gcc-text {
    display: none !important;
}

.ghost-connect-chip .gcc-dot {
    flex: 0 0 auto;
    width: 6px !important;
    height: 6px !important;
    border-radius: 50%;
    background: #7a7a7a;
    box-shadow: none !important;
}

.ghost-connect-chip.is-checking .gcc-dot { background: #d2a84d; }
.ghost-connect-chip.is-online .gcc-dot { background: #47c07a; box-shadow: 0 0 6px rgba(71, 192, 122, .6) !important; }
.ghost-connect-chip.is-offline .gcc-dot { background: #d2a84d; box-shadow: 0 0 6px rgba(210, 168, 77, .4) !important; }
.ghost-connect-chip.is-online { border-color: transparent !important; }
.ghost-connect-chip.is-offline { border-color: transparent !important; }

/* 3. Unified search result cards -------------------------------------- */

.cloud-item-badges {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-top: 3px;
}

.cloud-badge {
    padding: 1px 5px;
    border: 1px solid var(--border, #3d3d3d);
    border-radius: 4px;
    background: rgba(255, 255, 255, .04);
    color: #b9b9b9;
    font-size: 8.5px;
    letter-spacing: .04em;
    text-transform: uppercase;
    white-space: nowrap;
}

.cloud-badge.is-source-local { border-color: rgba(120, 170, 240, .45); color: #a9c9f4; }
.cloud-badge.is-source-cloud { border-color: rgba(71, 192, 122, .45); color: #96dfb4; }
.cloud-badge.is-source-api { border-color: rgba(210, 168, 77, .45); color: #e0c483; }

.cloud-item-thumb img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    background: #191919;
}

.cloud-item-thumb.is-empty::after {
    content: attr(data-kind);
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    color: #6f6f6f;
    font-size: 10px;
    letter-spacing: .12em;
    text-transform: uppercase;
}

/* 4. Responsive: everything in GHOST CACHE reflows ---------------------- */

@media (max-width: 900px) {
    .cloud-strip-grid,
    .cloud-group-grid {
        grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)) !important;
    }
}

@media (max-width: 640px) {
    .sidebar-topbar { padding: 9px 9px 8px !important; }
    .brand-icon { width: 26px !important; height: 26px !important; }
    .brand-subtitle { display: none; }
    .ghost-connect-chip { font-size: 9px; }
    .cloud-strip-grid,
    .cloud-group-grid {
        grid-template-columns: repeat(auto-fill, minmax(88px, 1fr)) !important;
    }
    .cloud-item-actions { flex-wrap: wrap; }
}

/* 5. GHOST COMMAND — prompt library strip ------------------------------- */

.gpl-bar {
    display: flex;
    align-items: flex-start;
    gap: 6px;
    padding: 6px 10px 0;
    min-width: 0;
}

.gpl-toggle {
    flex: 0 0 auto;
    padding: 3px 8px;
    border: 1px solid var(--border, #3a3a3a);
    border-radius: 999px;
    background: rgba(255, 255, 255, .04);
    color: #cfcfcf;
    font-size: 9.5px;
    letter-spacing: .06em;
    text-transform: uppercase;
    cursor: pointer;
}

.gpl-toggle:hover { color: #fff; border-color: #5c5c5c; }

.gpl-strip {
    display: flex;
    flex-wrap: nowrap;
    gap: 5px;
    min-width: 0;
    overflow-x: auto;
    padding-bottom: 4px;
}

.gpl-bar.expanded .gpl-strip {
    flex-wrap: wrap;
    max-height: 132px;
    overflow-y: auto;
}

.gpl-chip {
    flex: 0 0 auto;
    padding: 3px 9px;
    border: 1px solid #3d3d3d;
    border-radius: 6px;
    background: #2a2a2a;
    color: #ddd;
    font-size: 10.5px;
    cursor: pointer;
    white-space: nowrap;
}

.gpl-chip:hover { background: #343434; border-color: #6d8bb5; color: #fff; }

@media (max-width: 640px) {
    .gpl-bar { flex-wrap: wrap; }
    .gpl-strip { flex-wrap: wrap; }
}

/* 6. Resizable sidebar + single-line tree rows (v3.8.4) ------------------ */

.sidebar { position: relative; }

.sidebar-resizer {
    position: absolute;
    top: 0;
    right: -2px;
    bottom: 0;
    width: 6px;
    cursor: col-resize;
    z-index: 6;
}

.sidebar-resizer::after {
    content: "";
    position: absolute;
    inset: 0 2px;
    background: transparent;
    transition: background .12s ease;
}

.sidebar-resizer:hover::after { background: var(--ghost-accent, #2d8ceb); opacity: .6; }
body.is-resizing-sidebar { cursor: col-resize; user-select: none; }
body.is-resizing-sidebar * { pointer-events: none; }
body.is-resizing-sidebar .sidebar-resizer { pointer-events: auto; }

/* Long names now stay on one line: the column is user-resizable instead. */
.folder-history .history-name,
.cloud-source-name,
.history-item.history-child .history-name {
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    display: block !important;
    -webkit-line-clamp: unset !important;
    line-height: 1.4;
}

.folder-history .history-item,
.cloud-source-item { min-width: 0; }

/* 7. Cloud library browser — alignment + totals ------------------------- */

.glib-head { flex-wrap: wrap; row-gap: 6px; }

.glib-totals {
    flex: 0 0 auto;
    padding: 2px 7px;
    border: 1px solid var(--border, #3a3a3a);
    border-radius: 999px;
    background: rgba(255, 255, 255, .04);
    color: #c9c9c9;
    font-size: 9.5px;
    letter-spacing: .05em;
    text-transform: uppercase;
    white-space: nowrap;
}

.glib-packs,
.glib-chips { align-items: center; }

.glib-card figcaption { min-width: 0; text-align: left; }
.glib-cat { font-size: 9px; color: #8f8f8f; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.glib-thumb img { object-fit: contain; }

@media (max-width: 640px) {
    .glib-totals { order: 3; flex: 1 1 100%; text-align: center; }
    .glib-search { flex: 1 1 100%; order: 4; }
}

/* 8. Apple Dynamic Island Styled Control Capsule */
.header-control-capsule {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 4px 10px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.08);
    height: 28px;
    flex-shrink: 0;
    margin-left: auto;
}

.capsule-btn {
    width: 20px;
    height: 20px;
    border: none !important;
    background: transparent !important;
    padding: 0 !important;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    opacity: 0.65;
    transition: opacity 120ms ease;
}

.capsule-btn:hover {
    opacity: 1 !important;
}

.capsule-btn img {
    width: 14px;
    height: 14px;
}

/* 9. Compact Top Header overrides */
.sidebar-topbar {
    padding: 6px 6px !important;
    gap: 6px !important;
    margin-bottom: 8px !important;
}

.brand-row {
    gap: 6px !important;
}

.brand-icon {
    width: 22px !important;
    height: 22px !important;
}

.brand-title {
    font-size: 10px !important;
    font-weight: 700 !important;
}

.brand-subtitle {
    font-size: 8px !important;
    text-transform: lowercase !important;
    letter-spacing: 0.02em !important;
    margin-top: -1px !important;
}

.header-control-capsule {
    height: 22px !important;
    padding: 2px 8px !important;
    gap: 6px !important;
}

.capsule-btn {
    width: 16px !important;
    height: 16px !important;
}

.capsule-btn img {
    width: 11px !important;
    height: 11px !important;
}

.ghost-connect-chip .gcc-dot {
    width: 5px !important;
    height: 5px !important;
}

/* 10. Popover Menu Redesign, spacing out items, removing backgrounds, new swatches */
.popover-menu {
    background: #000000 !important;
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
    border: 1px solid rgba(255, 255, 255, 0.08) !important;
    box-shadow: 0 12px 36px rgba(0,0,0,0.85) !important;
    padding: 12px !important;
}

.popover-menu button[role="menuitem"] {
    margin-bottom: 6px !important;
    background: transparent !important;
    border: none !important;
    color: var(--ghost-text-secondary, #9D9DA5) !important;
}

.popover-menu button[role="menuitem"]:hover {
    background: rgba(255, 255, 255, 0.06) !important;
    color: #ffffff !important;
}

.theme-preset {
    padding: 6px 2px !important;
    background: transparent !important;
    border: 1px solid transparent !important;
}

.theme-preset.active {
    background: transparent !important;
    border-color: transparent !important;
    color: var(--ghost-accent, #3B82F6) !important;
}

.swatch-midnight { background: linear-gradient(135deg, #05060d, #0f1322) !important; }
.swatch-neon     { background: linear-gradient(135deg, #0a0a12, #171728) !important; }
