/* ==========================================================================
   Agent Manager · ElevenLabs-inspired design system
   Monochrome accent, system theme by default, smooth micro-interactions.
   ========================================================================== */

/* ---------- Design tokens ---------- */
:root {
    --bg:            250 250 250;   /* zinc-50  */
    --bg-elev:       255 255 255;
    --bg-subtle:     244 244 245;   /* zinc-100 */
    --bg-muted:      228 228 231;   /* zinc-200 */
    --bg-inverted:   9 9 11;        /* zinc-950 */

    --fg:            9 9 11;        /* zinc-950 */
    --fg-muted:      82 82 91;      /* zinc-600 */
    --fg-subtle:     113 113 122;   /* zinc-500 */
    --fg-faint:      161 161 170;   /* zinc-400 */
    --fg-inverted:   250 250 250;

    --border:        228 228 231;   /* zinc-200 */
    --border-strong: 212 212 216;   /* zinc-300 */

    --accent:        9 9 11;
    --accent-fg:     250 250 250;
    --accent-hover:  39 39 42;

    --success:       22 163 74;
    --success-soft:  220 252 231;
    --warning:       202 138 4;
    --warning-soft:  254 249 195;
    --danger:        220 38 38;
    --danger-soft:   254 226 226;
    --info:          37 99 235;
    --info-soft:     219 234 254;

    --ring:          9 9 11;
    --shadow-soft:   0 1px 2px 0 rgb(0 0 0 / 0.04), 0 1px 3px 0 rgb(0 0 0 / 0.05);
    --shadow-elev:   0 8px 24px -4px rgb(0 0 0 / 0.08), 0 4px 8px -2px rgb(0 0 0 / 0.04);
    --shadow-pop:    0 24px 48px -12px rgb(0 0 0 / 0.18);

    --radius-sm: 6px;
    --radius:    10px;
    --radius-lg: 14px;
    --radius-xl: 20px;

    --header-h: 56px;
    --sidebar-w: 248px;
    --sidebar-collapsed: 72px;

    --aurora-1: radial-gradient(55% 45% at 12% 15%, rgba(169, 244, 19, 0.28), transparent 70%);  /* dot lime #A9F413 */
    --aurora-2: radial-gradient(60% 50% at 88% 5%,  rgba(85, 140, 240, 0.20), transparent 70%); /* dot blue #558CF0 */
    --aurora-3: radial-gradient(55% 55% at 50% 100%, rgba(246, 47, 47, 0.14), transparent 70%); /* dot red #F62F2F */
}

.dark {
    --bg:            9 9 11;
    --bg-elev:       17 17 19;
    --bg-subtle:     24 24 27;
    --bg-muted:      39 39 42;
    --bg-inverted:   250 250 250;

    --fg:            250 250 250;
    --fg-muted:      161 161 170;
    --fg-subtle:     113 113 122;
    --fg-faint:      82 82 91;
    --fg-inverted:   9 9 11;

    --border:        39 39 42;
    --border-strong: 63 63 70;

    --accent:        250 250 250;
    --accent-fg:     9 9 11;
    --accent-hover:  228 228 231;

    --success:       74 222 128;
    --success-soft:  20 83 45 / 0.5;
    --warning:       250 204 21;
    --warning-soft:  113 63 18 / 0.45;
    --danger:        248 113 113;
    --danger-soft:   127 29 29 / 0.4;
    --info:          96 165 250;
    --info-soft:     30 58 138 / 0.4;

    --ring:          250 250 250;
    --shadow-soft:   0 1px 2px 0 rgb(0 0 0 / 0.4), 0 1px 3px 0 rgb(0 0 0 / 0.4);
    --shadow-elev:   0 8px 24px -4px rgb(0 0 0 / 0.5), 0 4px 8px -2px rgb(0 0 0 / 0.4);
    --shadow-pop:    0 24px 48px -12px rgb(0 0 0 / 0.7);

    --aurora-1: radial-gradient(55% 45% at 12% 15%, rgba(169, 244, 19, 0.20), transparent 70%);  /* dot lime #A9F413 */
    --aurora-2: radial-gradient(60% 50% at 88% 5%,  rgba(85, 140, 240, 0.18), transparent 70%); /* dot blue #558CF0 */
    --aurora-3: radial-gradient(55% 55% at 50% 100%, rgba(246, 47, 47, 0.14), transparent 70%); /* dot red #F62F2F */
}

/* ---------- Base layer ---------- */
*, ::before, ::after { border-color: rgb(var(--border)); }

html, body {
    background-color: rgb(var(--bg));
    color: rgb(var(--fg));
    font-family: 'Inter', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
    font-feature-settings: 'cv11', 'ss01', 'ss03', 'cv02', 'cv03', 'cv04';
    font-variant-numeric: tabular-nums;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

body { background-color: rgb(var(--bg)); }

::selection { background-color: rgb(var(--fg) / 0.15); color: rgb(var(--fg)); }

/* Scrollbars (subtle) */
* { scrollbar-width: thin; scrollbar-color: rgb(var(--border-strong)) transparent; }
*::-webkit-scrollbar { width: 8px; height: 8px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb { background-color: rgb(var(--border-strong)); border-radius: 999px; }
*::-webkit-scrollbar-thumb:hover { background-color: rgb(var(--fg-faint)); }

/* Focus ring */
:focus-visible { outline: 2px solid rgb(var(--ring) / 0.6); outline-offset: 2px; border-radius: 4px; }

/* ---------- Layout primitives ---------- */
.app-shell {
    display: grid;
    grid-template-columns: var(--sidebar-w) 1fr;
    min-height: 100vh;
    background:
        var(--aurora-1),
        var(--aurora-2),
        var(--aurora-3),
        rgb(var(--bg));
    background-attachment: fixed;
}

@media (max-width: 1024px) {
    .app-shell { grid-template-columns: 1fr; }
}

.sidebar {
    position: sticky;
    top: 0;
    height: 100vh;
    border-right: 1px solid rgb(var(--border));
    background-color: rgb(var(--bg) / 0.72);
    backdrop-filter: saturate(180%) blur(14px);
    -webkit-backdrop-filter: saturate(180%) blur(14px);
    padding: 18px 14px 14px;
    display: flex;
    flex-direction: column;
    z-index: 30;
}

@media (max-width: 1024px) {
    .sidebar {
        position: fixed;
        top: 0; left: 0;
        width: 80%;
        max-width: 280px;
        transform: translateX(-100%);
        transition: transform .25s ease;
        box-shadow: var(--shadow-pop);
    }
    .sidebar.is-open { transform: translateX(0); }
}

.sidebar-brand {
    display: flex;
    align-items: center;
    padding: 8px 10px 16px;
    color: rgb(var(--fg));
}

.brand-logo {
    height: 44px;
    width: auto;
    display: block;
    color: rgb(var(--fg));
}

.sidebar-section {
    padding-top: 10px;
    padding-bottom: 4px;
    font-size: 10px;
    font-weight: 600;
    color: rgb(var(--fg-faint));
    text-transform: uppercase;
    letter-spacing: 0.08em;
    padding-left: 10px;
}

.sidebar-nav { display: flex; flex-direction: column; gap: 2px; }

.nav-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border-radius: var(--radius);
    font-size: 13.5px;
    font-weight: 500;
    color: rgb(var(--fg-muted));
    transition: background-color .15s ease, color .15s ease, transform .15s ease;
    position: relative;
}
.nav-link:hover { background-color: rgb(var(--bg-subtle)); color: rgb(var(--fg)); }
.nav-link.is-active {
    background-color: rgb(var(--bg-subtle));
    color: rgb(var(--fg));
    box-shadow: inset 0 0 0 1px rgb(var(--border));
}
.nav-link.is-active::before {
    content: '';
    position: absolute;
    left: -14px;
    top: 8px; bottom: 8px;
    width: 2px; border-radius: 2px;
    background: rgb(var(--fg));
}
.nav-link svg { width: 16px; height: 16px; stroke-width: 1.6; flex-shrink: 0; opacity: .85; }

.sidebar-footer {
    margin-top: auto;
    padding-top: 14px;
    border-top: 1px solid rgb(var(--border));
    display: flex;
    align-items: center;
    gap: 10px;
}

.user-chip {
    flex: 1; min-width: 0;
    display: flex; align-items: center; gap: 9px;
    padding: 6px 8px;
    border-radius: var(--radius);
    color: rgb(var(--fg-muted));
}
.user-chip .avatar {
    width: 28px; height: 28px; border-radius: 999px;
    background: rgb(var(--bg-muted));
    color: rgb(var(--fg));
    display: grid; place-items: center;
    font-size: 11px; font-weight: 600;
    flex-shrink: 0;
}
.user-chip .meta { min-width: 0; }
.user-chip .name {
    font-size: 12.5px; font-weight: 500; color: rgb(var(--fg));
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.user-chip .role {
    font-size: 11px; color: rgb(var(--fg-faint));
}

.icon-btn {
    width: 32px; height: 32px;
    display: grid; place-items: center;
    border-radius: 8px;
    color: rgb(var(--fg-muted));
    background-color: transparent;
    border: 1px solid transparent;
    transition: background-color .15s ease, color .15s ease, border-color .15s ease;
}
.icon-btn:hover {
    background-color: rgb(var(--bg-subtle));
    color: rgb(var(--fg));
    border-color: rgb(var(--border));
}
.icon-btn svg { width: 16px; height: 16px; stroke-width: 1.6; }

/* ---------- Main content area ---------- */
.app-main { min-width: 0; display: flex; flex-direction: column; min-height: 100vh; }
.app-main:has(#detail-view:not(.hidden-imp)) {
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
}

.topbar {
    position: sticky; top: 0;
    z-index: 20;
    height: var(--header-h);
    display: flex; align-items: center;
    gap: 12px;
    padding: 0 24px;
    border-bottom: 1px solid rgb(var(--border));
    background-color: rgb(var(--bg) / 0.7);
    backdrop-filter: saturate(180%) blur(12px);
    -webkit-backdrop-filter: saturate(180%) blur(12px);
}
.topbar-title { font-size: 14px; font-weight: 600; color: rgb(var(--fg)); }
.topbar-sub { font-size: 12px; color: rgb(var(--fg-subtle)); }
.topbar-nav { display: flex; align-items: center; flex: 0 0 auto; }
.topbar-nav-link {
    display: inline-flex; align-items: center; gap: 6px;
    height: 32px; padding: 0 10px;
    border-radius: 8px;
    border: 1px solid transparent;
    font-size: 13px; font-weight: 600;
    color: rgb(var(--fg-muted));
}
.topbar-nav-link svg { width: 15px; height: 15px; stroke-width: 1.8; }
.topbar-nav-link:hover { background-color: rgb(var(--bg-subtle)); color: rgb(var(--fg)); }
.topbar-nav-link.is-active {
    background-color: rgb(var(--bg-subtle));
    color: rgb(var(--fg));
    border-color: rgb(var(--border));
}
@media (max-width: 640px) {
    .topbar-nav-label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
    .topbar-nav-link { padding: 0 8px; }
}
.topbar-org { display: flex; align-items: center; min-width: 0; }
.topbar-org form { min-width: 0; }
.topbar-org .select {
    width: auto;
    max-width: min(240px, 42vw);
    height: 32px;
    font-size: 12.5px;
    text-overflow: ellipsis;
}

.page {
    padding: 28px 24px 48px;
    max-width: 1400px;
    width: 100%;
    margin: 0 auto;
    animation: page-in .25s ease-out;
}
.page:has(#detail-view:not(.hidden-imp)) {
    padding: 0;
    flex: 1;
    min-height: 0;
    max-width: none;
    display: flex;
    flex-direction: column;
}
.page:has(#detail-view:not(.hidden-imp)) > .mb-4 {
    margin: 0;
    padding: 12px 24px 0;
}
.page:has(#detail-view:not(.hidden-imp)) #app {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
}
#detail-view:not(.hidden-imp) {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
}
#detail-view:not(.hidden-imp) > [data-conv-panel]:not(.hidden-imp) {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    width: 100%;
    max-width: none;
    padding: 16px 24px 20px;
}
#detail-view:not(.hidden-imp) #chat-messages > * {
    max-width: 48rem;
    width: 100%;
    margin-left: auto;
    margin-right: auto;
}
body:has(#detail-view:not(.hidden-imp)) {
    overflow: hidden;
}

.page-header { margin-bottom: 24px; }
.page-header h1 {
    font-size: 22px;
    font-weight: 600;
    letter-spacing: -0.02em;
    color: rgb(var(--fg));
}
.page-header p {
    margin-top: 4px;
    color: rgb(var(--fg-subtle));
    font-size: 13.5px;
    max-width: 680px;
}

.breadcrumbs {
    font-size: 12px;
    color: rgb(var(--fg-subtle));
    display: flex; gap: 6px; align-items: center;
    margin-bottom: 8px;
}
.breadcrumbs a { color: rgb(var(--fg-muted)); }
.breadcrumbs a:hover { color: rgb(var(--fg)); }
.breadcrumbs .sep { opacity: .5; }

/* ---------- Card ---------- */
.card {
    background-color: rgb(var(--bg-elev));
    border: 1px solid rgb(var(--border));
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-soft);
    overflow: hidden;
}
.card-header {
    padding: 14px 18px;
    border-bottom: 1px solid rgb(var(--border));
    display: flex; align-items: center; justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
}
.card-title { font-size: 14px; font-weight: 600; color: rgb(var(--fg)); }
.card-sub { font-size: 12.5px; color: rgb(var(--fg-subtle)); margin-top: 2px; }
.card-body { padding: 18px; }
.card-foot {
    padding: 12px 18px;
    border-top: 1px solid rgb(var(--border));
    background-color: rgb(var(--bg-subtle));
}

/* ---------- Stat ---------- */
.stat {
    padding: 16px 18px;
    background-color: rgb(var(--bg-elev));
    border: 1px solid rgb(var(--border));
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-soft);
}
.stat-label {
    font-size: 11px; font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: rgb(var(--fg-subtle));
}
.stat-value {
    margin-top: 6px;
    font-size: 26px;
    font-weight: 600;
    letter-spacing: -0.02em;
    color: rgb(var(--fg));
    font-variant-numeric: tabular-nums;
}
.stat-meta { margin-top: 6px; font-size: 11px; color: rgb(var(--fg-faint)); }

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    height: 34px;
    padding: 0 14px;
    border-radius: var(--radius);
    font-size: 13px;
    font-weight: 500;
    color: rgb(var(--fg));
    background-color: rgb(var(--bg-elev));
    border: 1px solid rgb(var(--border));
    transition: background-color .15s ease, border-color .15s ease, color .15s ease, transform .12s ease;
    white-space: nowrap;
    cursor: pointer;
}
.btn:hover { background-color: rgb(var(--bg-subtle)); border-color: rgb(var(--border-strong)); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn svg { width: 14px; height: 14px; stroke-width: 1.8; }

.btn-primary {
    background-color: rgb(var(--accent));
    color: rgb(var(--accent-fg));
    border-color: rgb(var(--accent));
}
.btn-primary:hover { background-color: rgb(var(--accent-hover)); border-color: rgb(var(--accent-hover)); }

.btn-ghost { background-color: transparent; border-color: transparent; color: rgb(var(--fg-muted)); }
.btn-ghost:hover { background-color: rgb(var(--bg-subtle)); color: rgb(var(--fg)); }

.btn-danger {
    background-color: rgb(var(--danger) / 0.1);
    color: rgb(var(--danger));
    border-color: rgb(var(--danger) / 0.25);
}
.btn-danger:hover { background-color: rgb(var(--danger) / 0.15); border-color: rgb(var(--danger) / 0.45); }

.btn-warning {
    background-color: rgb(var(--warning) / 0.12);
    color: rgb(var(--warning));
    border-color: rgb(var(--warning) / 0.25);
}
.btn-warning:hover { background-color: rgb(var(--warning) / 0.2); }

.btn-sm { height: 28px; padding: 0 10px; font-size: 12px; border-radius: 8px; }
.btn-xs { height: 24px; padding: 0 8px; font-size: 11.5px; border-radius: 7px; }

/* ---------- Form controls ---------- */
.field { display: block; }
.label {
    display: block;
    font-size: 12px;
    font-weight: 500;
    color: rgb(var(--fg-muted));
    margin-bottom: 6px;
}
.input, .select, .textarea {
    display: block;
    width: 100%;
    height: 36px;
    padding: 0 12px;
    background-color: rgb(var(--bg-elev));
    border: 1px solid rgb(var(--border));
    border-radius: var(--radius);
    font-size: 13.5px;
    color: rgb(var(--fg));
    transition: border-color .15s ease, box-shadow .15s ease, background-color .15s ease;
    font-family: inherit;
}
.textarea { height: auto; min-height: 96px; padding: 10px 12px; line-height: 1.5; resize: vertical; }
.input::placeholder, .textarea::placeholder { color: rgb(var(--fg-faint)); }
.input:focus, .select:focus, .textarea:focus {
    border-color: rgb(var(--fg) / 0.55);
    box-shadow: 0 0 0 3px rgb(var(--ring) / 0.10);
    outline: none;
}
.input-mono, .textarea-mono { font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; }

.password-field {
    display: flex;
    align-items: center;
    width: 100%;
    height: 36px;
    background-color: rgb(var(--bg-elev));
    border: 1px solid rgb(var(--border));
    border-radius: var(--radius);
    transition: border-color .15s ease, box-shadow .15s ease, background-color .15s ease;
}
.password-field:focus-within {
    border-color: rgb(var(--fg) / 0.55);
    box-shadow: 0 0 0 3px rgb(var(--ring) / 0.10);
}
.password-field .input {
    flex: 1 1 0;
    width: 0;
    min-width: 0;
    height: 100%;
    border: 0;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
    padding-right: 4px;
}
.password-field .input:focus {
    border: 0;
    box-shadow: none;
    outline: none;
}
.password-toggle {
    flex: 0 0 36px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 100%;
    margin: 0;
    padding: 0;
    border: 0;
    background: transparent;
    color: rgb(var(--fg-faint));
    cursor: pointer;
    border-radius: 0 var(--radius) var(--radius) 0;
    appearance: none;
    -webkit-appearance: none;
}
.password-toggle:hover { color: rgb(var(--fg-muted)); }
.password-toggle:focus-visible {
    outline: none;
    color: rgb(var(--fg));
}
.password-toggle svg {
    width: 16px;
    height: 16px;
    stroke: currentColor;
    fill: none;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
}
.password-toggle .icon-eye-off { display: none; }
.password-toggle[aria-pressed="true"] .icon-eye { display: none; }
.password-toggle[aria-pressed="true"] .icon-eye-off { display: block; }

.select {
    padding-right: 32px;
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'><polyline points='6 9 12 15 18 9'></polyline></svg>");
    background-repeat: no-repeat;
    background-position: right 10px center;
    background-size: 12px 12px;
    appearance: none;
    -webkit-appearance: none;
}

.tester-toolbar {
    min-width: 0;
    max-width: 100%;
}
.tester-select {
    min-width: 0;
    max-width: 240px;
    text-overflow: ellipsis;
    overflow: hidden;
    white-space: nowrap;
}
.tester-agent-select {
    width: 200px;
}
.tester-version-select {
    width: 240px;
}
@media (max-width: 720px) {
    .tester-select {
        width: min(100%, 240px);
        max-width: 100%;
    }
}

.tester-layout {
    display: flex;
    flex-direction: row;
    align-items: stretch;
    gap: 16px;
    height: calc(100vh - var(--header-h) - 80px);
    min-height: 420px;
    width: 100%;
}
.tester-studio-panel {
    display: flex;
    flex-direction: column;
    flex: 0 0 280px;
    width: 280px;
    max-width: 280px;
    overflow: hidden;
    min-height: 0;
    align-self: stretch;
}
.tester-studio-panel .card-header {
    align-items: flex-start;
}
.tester-chat {
    flex: 1 1 auto;
    min-width: 0;
    min-height: 0;
    align-self: stretch;
}
.tester-studio-close-mobile { display: none; }
.tester-studio-fab {
    display: none;
    position: fixed;
    left: max(16px, env(safe-area-inset-left));
    bottom: max(16px, env(safe-area-inset-bottom));
    z-index: 45;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
    border: 1px solid rgb(var(--border));
    border-radius: 999px;
    background: rgb(var(--accent));
    color: rgb(var(--accent-fg));
    box-shadow: var(--shadow-elev);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
}
.tester-studio-fab svg { width: 16px; height: 16px; }
.tester-studio-fab:active { transform: scale(0.98); }
.tester-studio-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 55;
    background: rgb(0 0 0 / 0.45);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

@media (max-width: 1023px) {
    .tester-layout {
        flex-direction: column;
        height: calc(100vh - var(--header-h) - 64px);
    }
    .tester-studio-fab { display: inline-flex; }
    body.tester-studio-open .tester-studio-fab { display: none; }
    .tester-studio-backdrop.is-open { display: block; }
    .tester-studio-close-mobile { display: inline-flex; }

    /* Fuera del flujo: no aparece arriba del chat cuando está cerrado */
    .tester-studio-panel {
        display: none;
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        z-index: 60;
        flex: none;
        width: min(92vw, 360px);
        max-width: min(92vw, 360px);
        height: 100%;
        max-height: none;
        border-radius: 0 var(--radius-lg) var(--radius-lg) 0;
        box-shadow: var(--shadow-pop);
        transform: translateX(-105%);
        transition: transform 0.22s ease;
    }
    .tester-studio-panel.is-open {
        display: flex;
        transform: translateX(0);
    }
    .tester-chat {
        flex: 1 1 auto;
        width: 100%;
        height: 100%;
    }
}

.check {
    accent-color: rgb(var(--fg));
}

.help { font-size: 11.5px; color: rgb(var(--fg-faint)); margin-top: 4px; }
.help.is-warning { color: rgb(var(--warning)); }

/* Field docs trigger + bottom sheet */
.label-with-tip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}
.field-tip {
    display: inline-flex;
    align-items: center;
    flex-shrink: 0;
}
.field-tip-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    padding: 0;
    border: none;
    border-radius: 999px;
    background: rgb(var(--bg-subtle));
    color: rgb(var(--fg-faint));
    cursor: pointer;
    line-height: 0;
}
.field-tip-btn:hover,
.field-tip-btn:focus-visible {
    color: rgb(var(--fg));
    background: rgb(var(--border));
    outline: none;
}
.field-tip-btn svg,
.field-tip-btn i {
    width: 12px !important;
    height: 12px !important;
    stroke-width: 2;
}
.field-docs-src {
    display: none !important;
}

.docs-sheet {
    position: fixed;
    inset: 0;
    z-index: 220;
    pointer-events: none;
}
.docs-sheet.is-open {
    pointer-events: auto;
}
.docs-sheet-backdrop {
    position: absolute;
    inset: 0;
    background: rgb(0 0 0 / 0.45);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    opacity: 0;
    transition: opacity .2s ease;
}
.docs-sheet.is-open .docs-sheet-backdrop {
    opacity: 1;
}
.docs-sheet-panel {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    max-height: min(78vh, 640px);
    display: flex;
    flex-direction: column;
    background: rgb(var(--bg-elev));
    border: 1px solid rgb(var(--border));
    border-bottom: none;
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    box-shadow: 0 -12px 40px rgb(0 0 0 / 0.18);
    transform: translateY(105%);
    transition: transform .28s cubic-bezier(.2, .8, .2, 1);
}
.docs-sheet.is-open .docs-sheet-panel {
    transform: translateY(0);
}
.docs-sheet-handle {
    width: 40px;
    height: 4px;
    margin: 10px auto 0;
    border-radius: 999px;
    background: rgb(var(--border));
    flex-shrink: 0;
}
.docs-sheet-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 14px 18px 10px;
    border-bottom: 1px solid rgb(var(--border));
    flex-shrink: 0;
}
.docs-sheet-title {
    margin: 0;
    font-size: 15px;
    font-weight: 600;
    color: rgb(var(--fg));
}
.docs-sheet-body {
    padding: 16px 18px 28px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    color: rgb(var(--fg-subtle));
    font-size: 13px;
    line-height: 1.5;
}
.docs-sheet-body strong {
    display: block;
    color: rgb(var(--fg));
    font-weight: 600;
    margin: 0 0 8px;
}
.docs-sheet-body code,
.docs-sheet-body pre {
    font-family: "JetBrains Mono", ui-monospace, monospace;
    font-size: 11.5px;
    color: rgb(var(--fg));
}
.docs-sheet-body pre {
    margin: 10px 0 0;
    padding: 10px 12px;
    border-radius: 8px;
    background: rgb(var(--bg-subtle));
    border: 1px solid rgb(var(--border));
    overflow-x: auto;
    white-space: pre;
}
.docs-sheet-body .ex {
    display: block;
    margin-top: 10px;
    color: rgb(var(--fg-faint));
    font-size: 12.5px;
}
.docs-sheet-body p {
    margin: 0 0 8px;
}
.docs-sheet-body p:last-child {
    margin-bottom: 0;
}
.docs-sheet-body ol,
.docs-sheet-body ul {
    margin: 0 0 12px;
    padding-left: 1.25rem;
}
.docs-sheet-body li {
    margin-bottom: 6px;
}
.docs-sheet-body h4 {
    margin: 14px 0 6px;
    font-size: 12.5px;
    font-weight: 600;
    color: rgb(var(--fg));
    text-transform: uppercase;
    letter-spacing: 0.02em;
}
.docs-sheet-body h4:first-child {
    margin-top: 0;
}

.billing-change-help {
    display: grid;
    grid-template-columns: 14px minmax(0, 1fr);
    column-gap: 8px;
    align-items: start;
    margin: 0;
    padding: 10px 12px;
    border-radius: var(--radius);
    background-color: rgb(var(--bg-subtle));
    border: 1px solid rgb(var(--border));
    color: rgb(var(--fg-subtle));
    font-size: 12px;
    line-height: 1.45;
}
.billing-change-help > svg,
.billing-change-help > i {
    width: 14px !important;
    height: 14px !important;
    margin-top: 2px;
    color: rgb(var(--fg-faint));
    stroke-width: 1.8;
}
.billing-change-help > p {
    margin: 0;
    min-width: 0;
}

.input-group {
    display: inline-flex; align-items: center;
    gap: 8px;
    height: 36px;
    padding: 0 4px 0 12px;
    background-color: rgb(var(--bg-elev));
    border: 1px solid rgb(var(--border));
    border-radius: var(--radius);
}
.input-group .input,
.input-group .select {
    height: 30px;
    border: none;
    background: transparent;
    padding: 0;
}
.input-group .input:focus,
.input-group .select:focus { box-shadow: none; }
.input-group-label {
    font-size: 11px; font-weight: 500;
    color: rgb(var(--fg-subtle));
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

/* ---------- Badges / chips ---------- */
.badge {
    display: inline-flex; align-items: center; gap: 4px;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 500;
    background-color: rgb(var(--bg-subtle));
    color: rgb(var(--fg-muted));
    border: 1px solid rgb(var(--border));
}
.badge-dot { width: 6px; height: 6px; border-radius: 999px; display: inline-block; }

.badge-success { color: rgb(var(--success)); background-color: rgb(var(--success-soft)); border-color: rgb(var(--success) / 0.25); }
.badge-warning { color: rgb(var(--warning)); background-color: rgb(var(--warning-soft)); border-color: rgb(var(--warning) / 0.25); }
.badge-danger  { color: rgb(var(--danger));  background-color: rgb(var(--danger-soft));  border-color: rgb(var(--danger) / 0.25); }
.badge-info    { color: rgb(var(--info));    background-color: rgb(var(--info-soft));    border-color: rgb(var(--info) / 0.25); }

.chip {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 5px 10px;
    border-radius: 999px;
    background-color: rgb(var(--bg-subtle));
    color: rgb(var(--fg-muted));
    border: 1px solid rgb(var(--border));
    font-size: 12px;
    cursor: pointer;
    transition: background-color .15s, color .15s, border-color .15s;
}
.chip:hover { background-color: rgb(var(--bg-muted)); color: rgb(var(--fg)); }
.chip.is-active { background-color: rgb(var(--fg)); color: rgb(var(--bg)); border-color: rgb(var(--fg)); }

/* ---------- Tables ---------- */
.table-wrap {
    background-color: rgb(var(--bg-elev));
    border: 1px solid rgb(var(--border));
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: var(--shadow-soft);
}
.table-scroll { overflow-x: auto; }

.table { width: 100%; border-collapse: collapse; }
.table th {
    text-align: left;
    font-size: 11px;
    font-weight: 500;
    color: rgb(var(--fg-subtle));
    text-transform: uppercase;
    letter-spacing: 0.06em;
    padding: 10px 16px;
    background-color: rgb(var(--bg-subtle));
    border-bottom: 1px solid rgb(var(--border));
    white-space: nowrap;
}
.table td {
    padding: 12px 16px;
    font-size: 13px;
    color: rgb(var(--fg));
    border-bottom: 1px solid rgb(var(--border));
}
.table tr:last-child td { border-bottom: none; }
.table tbody tr { transition: background-color .15s ease; }
.table tbody tr:hover { background-color: rgb(var(--bg-subtle) / 0.6); }
.table .num { font-variant-numeric: tabular-nums; text-align: right; }
.table .muted { color: rgb(var(--fg-subtle)); }

.table-row-clickable { cursor: pointer; }

/* ---------- Tabs ---------- */
.tabs {
    display: flex;
    flex-wrap: nowrap;
    align-items: stretch;
    gap: 2px;
    border-bottom: 1px solid rgb(var(--border));
    padding: 0 10px;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scroll-snap-type: x proximity;
    scrollbar-width: thin;
    overscroll-behavior-x: contain;
}
.tabs::-webkit-scrollbar { height: 3px; }
.tabs::-webkit-scrollbar-thumb {
    background: rgb(var(--border-strong));
    border-radius: 999px;
}
.tab {
    appearance: none;
    background: transparent;
    border: none;
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 10px 12px;
    font-size: 13px;
    font-weight: 500;
    color: rgb(var(--fg-subtle));
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    white-space: nowrap;
    scroll-snap-align: start;
    transition: color .15s ease, border-color .15s ease;
    cursor: pointer;
}
.tab:hover { color: rgb(var(--fg)); }
.tab.is-active { color: rgb(var(--fg)); border-bottom-color: rgb(var(--fg)); }
.tab .tab-full { display: inline; }
.tab .tab-short { display: none; }

@media (max-width: 768px) {
    .tabs {
        padding: 0 8px;
        gap: 0;
        mask-image: linear-gradient(90deg, transparent 0, #000 12px, #000 calc(100% - 12px), transparent 100%);
        -webkit-mask-image: linear-gradient(90deg, transparent 0, #000 12px, #000 calc(100% - 12px), transparent 100%);
    }
    .tab {
        padding: 11px 10px;
        font-size: 12.5px;
    }
    .tab .tab-full { display: none; }
    .tab .tab-short { display: inline; }
    .tab .badge { margin-left: 0 !important; }
}

@media (max-width: 420px) {
    .tab { padding: 10px 8px; font-size: 12px; }
}

.segmented {
    display: inline-flex;
    padding: 2px;
    border: 1px solid rgb(var(--border));
    border-radius: 10px;
    background-color: rgb(var(--bg-subtle));
}
.segmented button {
    appearance: none;
    background: transparent;
    border: none;
    color: rgb(var(--fg-subtle));
    padding: 5px 12px;
    font-size: 12.5px;
    font-weight: 500;
    border-radius: 7px;
    cursor: pointer;
    transition: background-color .15s, color .15s;
}
.segmented button.is-active {
    background-color: rgb(var(--bg-elev));
    color: rgb(var(--fg));
    box-shadow: var(--shadow-soft);
}

/* ---------- Empty states ---------- */
.empty {
    padding: 56px 24px;
    text-align: center;
    color: rgb(var(--fg-subtle));
}
.empty-icon {
    width: 56px; height: 56px;
    border-radius: 16px;
    margin: 0 auto 14px;
    display: grid; place-items: center;
    background: linear-gradient(180deg, rgb(var(--bg-subtle)), rgb(var(--bg-elev)));
    border: 1px solid rgb(var(--border));
    color: rgb(var(--fg-muted));
}
.empty-icon svg { width: 24px; height: 24px; }
.empty-title { color: rgb(var(--fg)); font-weight: 600; font-size: 14px; margin-bottom: 4px; }
.empty-desc { font-size: 13px; max-width: 380px; margin: 0 auto; }

/* ---------- Auth (login / standalone hero) ---------- */
.auth-shell {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
    position: relative;
    overflow: hidden;
    background:
        var(--aurora-1),
        var(--aurora-2),
        var(--aurora-3),
        rgb(var(--bg));
    background-attachment: fixed;
}
.auth-shell::before {
    content: '';
    position: absolute;
    inset: -15%;
    background:
        radial-gradient(42% 55% at 12% 18%, rgba(169, 244, 19, 0.42), transparent 68%),
        radial-gradient(46% 52% at 88% 8%, rgba(85, 140, 240, 0.34), transparent 68%),
        radial-gradient(50% 48% at 50% 100%, rgba(246, 47, 47, 0.26), transparent 68%);
    filter: blur(28px);
    pointer-events: none;
    z-index: 0;
}
.dark .auth-shell::before {
    background:
        radial-gradient(42% 55% at 12% 18%, rgba(169, 244, 19, 0.32), transparent 68%),
        radial-gradient(46% 52% at 88% 8%, rgba(85, 140, 240, 0.30), transparent 68%),
        radial-gradient(50% 48% at 50% 100%, rgba(246, 47, 47, 0.24), transparent 68%);
}
.auth-card {
    position: relative;
    width: 100%;
    max-width: 420px;
    border-radius: var(--radius-xl);
    border: 1px solid rgb(var(--border));
    background-color: rgb(var(--bg-elev) / 0.92);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    padding: 32px 28px;
    box-shadow: var(--shadow-pop);
    animation: page-in .35s ease;
}
.auth-brand {
    display: flex; align-items: center;
    color: rgb(var(--fg));
    margin-bottom: 24px;
}
.auth-brand .brand-logo { height: 52px; }
.auth-byline {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    margin-top: 18px;
    font-size: 11px;
    line-height: 16px;
    color: rgb(var(--fg-subtle));
    text-decoration: none;
    white-space: nowrap;
}
.auth-byline .blaise-logo {
    height: 14px;
    width: auto;
    color: rgb(var(--fg-muted));
}
.auth-byline:hover { color: rgb(var(--fg)); }
.auth-byline:hover .blaise-logo { color: rgb(var(--fg)); }
.auth-title { font-size: 22px; font-weight: 600; letter-spacing: -0.02em; margin-bottom: 6px; color: rgb(var(--fg)); }
.auth-sub   { font-size: 13.5px; color: rgb(var(--fg-subtle)); margin-bottom: 22px; }

/* ---------- Theme toggle ---------- */
.theme-toggle {
    display: inline-flex; align-items: center;
    padding: 2px;
    background-color: rgb(var(--bg-subtle));
    border: 1px solid rgb(var(--border));
    border-radius: 999px;
}
.theme-toggle button {
    appearance: none; background: transparent; border: none;
    width: 26px; height: 26px;
    display: grid; place-items: center;
    border-radius: 999px;
    color: rgb(var(--fg-subtle));
    cursor: pointer;
    transition: background-color .15s, color .15s;
}
.theme-toggle button:hover { color: rgb(var(--fg)); }
.theme-toggle button.is-active {
    background-color: rgb(var(--bg-elev));
    color: rgb(var(--fg));
    box-shadow: var(--shadow-soft);
}
.theme-toggle svg { width: 13px; height: 13px; stroke-width: 1.8; }

/* ---------- Flash messages ---------- */
.flash {
    margin-bottom: 12px;
    padding: 10px 14px;
    border-radius: var(--radius);
    border: 1px solid rgb(var(--border));
    background-color: rgb(var(--bg-elev));
    font-size: 13px;
    color: rgb(var(--fg));
    display: flex; align-items: center; gap: 10px;
}
.flash.is-error  { color: rgb(var(--danger));  background-color: rgb(var(--danger-soft));  border-color: rgb(var(--danger) / 0.3); }
.flash.is-success { color: rgb(var(--success)); background-color: rgb(var(--success-soft)); border-color: rgb(var(--success) / 0.3); }
.flash.is-info   { color: rgb(var(--info));   background-color: rgb(var(--info-soft));   border-color: rgb(var(--info) / 0.3); }

/* ---------- Markdown prose ---------- */
.markdown-prose { color: rgb(var(--fg)); font-size: 0.875rem; line-height: 1.65; }
.markdown-prose > :first-child { margin-top: 0; }
.markdown-prose > :last-child { margin-bottom: 0; }
.markdown-prose h1, .markdown-prose h2, .markdown-prose h3, .markdown-prose h4 { color: rgb(var(--fg)); font-weight: 600; letter-spacing: -0.01em; }
.markdown-prose h1 { font-size: 1.5rem; margin: 1.25rem 0 0.75rem; border-bottom: 1px solid rgb(var(--border)); padding-bottom: 0.35rem; }
.markdown-prose h2 { font-size: 1.25rem; margin: 1.15rem 0 0.55rem; }
.markdown-prose h3 { font-size: 1.05rem; margin: 1rem 0 0.45rem; }
.markdown-prose h4 { font-size: 0.95rem; margin: 0.9rem 0 0.35rem; }
.markdown-prose p  { margin: 0.55rem 0; color: rgb(var(--fg)); }
.markdown-prose strong { color: rgb(var(--fg)); font-weight: 600; }
.markdown-prose ul, .markdown-prose ol { padding-left: 1.4rem; margin: 0.55rem 0; }
.markdown-prose ul { list-style: disc; }
.markdown-prose ol { list-style: decimal; }
.markdown-prose li { margin: 0.15rem 0; }
.markdown-prose code {
    background: rgb(var(--bg-subtle));
    color: rgb(var(--fg));
    padding: 0.1rem 0.35rem;
    border-radius: 0.25rem;
    font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 0.82rem;
    border: 1px solid rgb(var(--border));
}
.markdown-prose pre {
    background: rgb(var(--bg-inverted));
    color: rgb(var(--fg-inverted));
    padding: 0.85rem 1rem;
    border-radius: 0.5rem;
    overflow-x: auto;
    margin: 0.7rem 0;
    font-size: 0.82rem;
    line-height: 1.5;
}
.markdown-prose pre code { background: transparent; padding: 0; color: inherit; border: none; }
.markdown-prose blockquote {
    border-left: 3px solid rgb(var(--border-strong));
    color: rgb(var(--fg-muted));
    padding: 0.15rem 0 0.15rem 0.9rem;
    margin: 0.7rem 0;
    font-style: italic;
}
.markdown-prose hr { border: none; border-top: 1px solid rgb(var(--border)); margin: 1.25rem 0; }
.markdown-prose a  { color: rgb(var(--fg)); text-decoration: underline; text-underline-offset: 2px; }
.markdown-prose-empty { color: rgb(var(--fg-faint)); font-style: italic; }

/* ---------- Code chip ---------- */
.code-chip {
    font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 11.5px;
    padding: 2px 6px;
    border-radius: 6px;
    background-color: rgb(var(--bg-subtle));
    border: 1px solid rgb(var(--border));
    color: rgb(var(--fg-muted));
}

/* ---------- Modal ---------- */
.modal-backdrop {
    position: fixed; inset: 0;
    background-color: rgb(0 0 0 / 0.45);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    z-index: 100;
    display: grid; place-items: center;
    padding: 24px;
    animation: fade-in .15s ease;
}
.modal {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 50;
}
.modal-header { padding: 18px 20px 0; }
.modal-title { font-size: 15px; font-weight: 600; color: rgb(var(--fg)); }
.modal-sub   { font-size: 12.5px; color: rgb(var(--fg-subtle)); margin-top: 4px; }
.modal-body  { padding: 18px 20px; }
.modal-foot  { padding: 12px 20px; border-top: 1px solid rgb(var(--border)); background-color: rgb(var(--bg-subtle)); display: flex; gap: 8px; justify-content: flex-end; }

/* ---------- Chat bubbles ---------- */
.chat-bubble {
    max-width: 80%;
    padding: 10px 14px;
    border-radius: 16px;
    font-size: 13.5px;
    line-height: 1.5;
    box-shadow: var(--shadow-soft);
    animation: bubble-in .2s ease-out;
}
#chat-messages.is-static .chat-bubble {
    animation: none;
}
.chat-bubble.user {
    background-color: rgb(var(--fg));
    color: rgb(var(--bg));
    border-bottom-right-radius: 6px;
    align-self: flex-end;
}
.chat-bubble.bot {
    background-color: rgb(var(--bg-elev));
    color: rgb(var(--fg));
    border: 1px solid rgb(var(--border));
    border-bottom-left-radius: 6px;
}
.chat-bubble.bot.bot-pulse { opacity: .85; }
.chat-bubble .chat-link {
    color: inherit;
    text-decoration: underline;
    text-underline-offset: 2px;
    word-break: break-all;
}
.chat-bubble.bot .chat-link {
    color: rgb(37 99 235);
}
.dark .chat-bubble.bot .chat-link {
    color: rgb(147 197 253);
}
.chat-bubble.user .chat-link {
    color: inherit;
    opacity: 0.92;
}
.chat-bubble.operator {
    background-color: rgb(var(--info-soft));
    color: rgb(var(--fg));
    border: 1px solid rgb(var(--info) / 0.35);
    border-bottom-left-radius: 6px;
}
.dark .chat-bubble.operator {
    background-color: rgb(var(--info) / 0.18);
    border-color: rgb(var(--info) / 0.4);
}
.chat-bubble-label {
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.02em;
    text-transform: uppercase;
    opacity: 0.7;
    margin-bottom: 4px;
}
.chat-media {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 8px;
}
.chat-media:last-child { margin-bottom: 0; }
.chat-media-link { display: block; width: fit-content; max-width: 100%; line-height: 0; }
.chat-media-img {
    display: block;
    width: 220px;
    height: 160px;
    max-width: 100%;
    border-radius: 10px;
    object-fit: contain;
    background: rgb(0 0 0 / 0.12);
}
.chat-bubble.bot .chat-media-img,
.chat-bubble.operator .chat-media-img {
    background: rgb(var(--bg-subtle));
}
.chat-media-video {
    display: block;
    width: 220px;
    height: 160px;
    max-width: 100%;
    border-radius: 10px;
    object-fit: contain;
    background: #000;
}
.chat-voice {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 248px;
    max-width: 100%;
    min-height: 40px;
}
.chat-voice-btn {
    flex: 0 0 auto;
    width: 36px;
    height: 36px;
    border: 0;
    border-radius: 999px;
    display: grid;
    place-items: center;
    cursor: pointer;
    color: rgb(var(--fg));
    background: rgb(var(--bg));
    box-shadow: var(--shadow-soft);
}
.chat-bubble.user .chat-voice-btn {
    color: rgb(var(--fg));
    background: rgb(var(--bg));
}
.chat-bubble.bot .chat-voice-btn,
.chat-bubble.operator .chat-voice-btn {
    color: rgb(var(--bg));
    background: rgb(var(--fg));
}
.chat-voice-btn svg {
    grid-area: 1 / 1;
    width: 16px;
    height: 16px;
    display: block;
}
.chat-voice-btn .chat-voice-icon-pause { display: none; }
.chat-voice.is-playing .chat-voice-btn .chat-voice-icon-play { display: none; }
.chat-voice.is-playing .chat-voice-btn .chat-voice-icon-pause { display: block; }
.chat-voice-wave {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 2px;
    height: 28px;
    min-width: 0;
}
.chat-voice-btn:hover {
    filter: brightness(1.08);
}
.chat-voice-wave span {
    flex: 1 1 0;
    min-width: 2px;
    border-radius: 999px;
    background: currentColor;
    opacity: 0.38;
    transform-origin: center bottom;
}
.chat-voice.is-playing .chat-voice-wave span {
    animation: chat-voice-bar 0.9s ease-in-out infinite;
}
.chat-voice-time {
    flex: 0 0 auto;
    font-size: 11px;
    font-variant-numeric: tabular-nums;
    opacity: 0.72;
    min-width: 2.4em;
    text-align: right;
}
@keyframes chat-voice-bar {
    0%, 100% { transform: scaleY(0.55); }
    50% { transform: scaleY(1); }
}
.chat-file-chip {
    display: inline-flex;
    align-items: center;
    font-size: 12px;
    padding: 6px 10px;
    border-radius: 999px;
    background: rgb(255 255 255 / 0.12);
    color: inherit;
    text-decoration: none;
    word-break: break-all;
}
.chat-bubble.bot .chat-file-chip,
.chat-bubble.operator .chat-file-chip {
    background: rgb(var(--bg-subtle));
    border: 1px solid rgb(var(--border));
}
.chat-file-chip.is-missing {
    opacity: 0.75;
    font-style: italic;
}

/* ---------- Conversation composer ---------- */
.conv-composer {
    position: sticky;
    bottom: 0;
    z-index: 14;
    margin: 20px -24px -8px;
    padding: 12px 24px 16px;
    background-color: rgb(var(--bg) / 0.9);
    backdrop-filter: saturate(180%) blur(12px);
    -webkit-backdrop-filter: saturate(180%) blur(12px);
    border-top: 1px solid rgb(var(--border));
}
#detail-view:not(.hidden-imp) .conv-composer {
    position: relative;
    bottom: auto;
    flex-shrink: 0;
    margin: 0;
    padding: 12px 24px calc(12px + env(safe-area-inset-bottom, 0px));
}
.conv-composer-row {
    display: flex;
    gap: 8px;
    align-items: flex-end;
    max-width: 48rem;
    margin: 0 auto;
}
.conv-composer-stack {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.conv-composer-row textarea {
    width: 100%;
    min-height: 44px;
    max-height: 160px;
    resize: vertical;
}
.conv-attach-btn {
    width: 44px;
    height: 44px;
    padding: 0;
    flex-shrink: 0;
}
.conv-attach-btn.is-active {
    background: rgb(var(--bg-subtle));
    border-color: rgb(var(--border-strong));
    color: rgb(var(--fg));
}
.conv-pending-file {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 8px;
    border: 1px solid rgb(var(--border));
    border-radius: 10px;
    background: rgb(var(--bg-elev));
    font-size: 12px;
    min-width: 0;
}
.conv-pending-file img {
    width: 36px;
    height: 36px;
    object-fit: cover;
    border-radius: 6px;
    flex-shrink: 0;
}
.conv-pending-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
}
.conv-pending-file .btn {
    margin-left: auto;
    flex-shrink: 0;
}
.conv-composer-hint {
    max-width: 48rem;
    margin: 0 auto 8px;
    font-size: 12px;
    color: rgb(var(--fg-subtle));
}
#template-picker {
    max-width: 48rem;
    margin: 0 auto 8px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}
#template-picker .conv-composer-hint {
    margin-bottom: 0;
}
#template-picker-rows .ci-template-list {
    max-height: 320px;
    overflow-y: auto;
}
#template-picker .ci-bubble {
    max-width: 100%;
    align-self: flex-start;
}
.template-form-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

/* ---------- Conversation sticky navbar ---------- */
.conv-sticky-nav {
    position: sticky;
    top: var(--header-h);
    z-index: 15;
    margin: 0 -24px 16px;
    padding: 10px 24px 0;
    background-color: rgb(var(--bg) / 0.78);
    backdrop-filter: saturate(180%) blur(12px);
    -webkit-backdrop-filter: saturate(180%) blur(12px);
    border-bottom: 1px solid rgb(var(--border));
}
#detail-view:not(.hidden-imp) .conv-sticky-nav {
    position: relative;
    top: auto;
    flex-shrink: 0;
    margin: 0;
}
.conv-sticky-nav-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    min-height: 36px;
}
.conv-sticky-nav-actions {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    margin-left: auto;
}
.conv-sticky-nav-meta {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px 16px;
    padding: 8px 0 10px;
    font-size: 12.5px;
    color: rgb(var(--fg-muted));
}
.conv-sticky-nav-meta strong {
    color: rgb(var(--fg));
    font-weight: 600;
}
.conv-sticky-nav .tabs {
    padding: 0;
}
.conv-sticky-nav .tab {
    padding-top: 8px;
    padding-bottom: 8px;
}
.conv-tool-wrap {
    display: flex;
    justify-content: center;
    width: 100%;
}
.conv-tool-card {
    width: 100%;
    max-width: 36rem;
    border: 1px solid rgb(var(--border));
    border-radius: 12px;
    background: rgb(var(--bg-elev));
    padding: 10px 12px;
    box-shadow: var(--shadow-soft);
}
.conv-tool-card.is-pending {
    border-style: dashed;
    opacity: 0.9;
}
.conv-tool-card-head {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 6px;
    color: rgb(var(--fg-muted));
}
.conv-tool-card-title {
    flex: 1;
    min-width: 0;
    font-size: 12.5px;
    font-weight: 560;
    color: rgb(var(--fg));
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.conv-tool-skill {
    color: rgb(var(--fg-subtle));
    font-weight: 500;
}
.conv-tool-sep {
    margin: 0 2px;
    color: rgb(var(--fg-faint));
}
.conv-tool-name {
    font-family: 'JetBrains Mono', ui-monospace, monospace;
    font-size: 12px;
}
.conv-tool-ts {
    font-size: 10.5px;
    color: rgb(var(--fg-faint));
    white-space: nowrap;
}
.conv-tool-details {
    margin-top: 4px;
    border-top: 1px solid rgb(var(--border));
    padding-top: 4px;
}
.conv-tool-details summary {
    cursor: pointer;
    font-size: 11.5px;
    font-weight: 550;
    color: rgb(var(--fg-subtle));
    user-select: none;
}
.conv-tool-details summary:hover {
    color: rgb(var(--fg));
}
.conv-tool-pre {
    margin: 6px 0 2px;
    padding: 8px 10px;
    max-height: 240px;
    overflow: auto;
    border-radius: 8px;
    background: rgb(var(--bg-subtle));
    border: 1px solid rgb(var(--border));
    font-family: 'JetBrains Mono', ui-monospace, monospace;
    font-size: 11px;
    line-height: 1.45;
    white-space: pre-wrap;
    word-break: break-word;
    color: rgb(var(--fg));
}

/* ---------- Misc ---------- */
.hidden-imp { display: none !important; }

.divider {
    height: 1px;
    background-color: rgb(var(--border));
    margin: 16px 0;
}

.kbd {
    display: inline-flex; align-items: center;
    height: 20px; padding: 0 6px;
    border-radius: 6px;
    background-color: rgb(var(--bg-subtle));
    color: rgb(var(--fg-muted));
    border: 1px solid rgb(var(--border));
    border-bottom-width: 2px;
    font-size: 10.5px;
    font-family: 'JetBrains Mono', ui-monospace, monospace;
}

/* ---------- Animations ---------- */
@keyframes page-in {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0); }
}
@keyframes fade-in {
    from { opacity: 0; }
    to   { opacity: 1; }
}
@keyframes modal-in {
    from { opacity: 0; transform: translateY(8px) scale(.985); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes bubble-in {
    from { opacity: 0; transform: translateY(4px); }
    to   { opacity: 1; transform: translateY(0); }
}
@keyframes shimmer {
    0%   { background-position: -200px 0; }
    100% { background-position: 200px 0; }
}
@keyframes spin-soft {
    to { transform: rotate(360deg); }
}
.spin-soft { animation: spin-soft 1s linear infinite; }

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}

/* ---------- Portal skeleton loaders (API / fetch) ---------- */
.portal-skel-shimmer {
    background: linear-gradient(
        90deg,
        rgb(var(--bg-muted)) 0%,
        rgb(var(--bg-subtle)) 42%,
        rgb(var(--bg-muted)) 88%
    );
    background-size: 220px 100%;
    background-repeat: no-repeat;
    animation: shimmer 1.15s ease-in-out infinite;
}

/* Block-level line (rows, preview blocks) */
.portal-skel-line {
    display: block;
    height: 12px;
    border-radius: 6px;
    max-width: 100%;
    box-sizing: border-box;
}
.portal-skel-line-sm {
    height: 8px;
    border-radius: 4px;
}

/* Inline bar that fits inside text/badges using em units */
.portal-skel-bar {
    display: inline-block;
    vertical-align: -0.15em;
    height: 0.95em;
    max-width: 100%;
    border-radius: 6px;
}
.portal-skel-bar-sm {
    height: 0.7em;
    border-radius: 4px;
}

.portal-skel-tr td {
    border-color: rgb(var(--border));
}
.table tbody tr.portal-skel-tr {
    pointer-events: none;
}
.table tbody tr.portal-skel-tr:hover {
    background-color: transparent;
}
.portal-skel-bubble {
    min-width: 120px;
    max-width: 85%;
}

/* Preview block: rows of skeleton lines that never overflow the host */
.portal-skel-preview {
    padding: 8px 4px 4px;
    min-width: 0;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    overflow: hidden;
}
.portal-skel-preview > .portal-skel-line {
    margin-bottom: 10px;
}
#prompt-preview.portal-skel-preview-host {
    overflow-x: hidden;
    overflow-y: auto;
}

/* Textarea-shaped skeleton overlayed on top of the real textarea */
.portal-skel-textbox {
    position: absolute;
    inset: 0;
    box-sizing: border-box;
    padding: 14px 16px;
    border: 1px solid rgb(var(--border));
    border-radius: var(--radius);
    background-color: rgb(var(--bg-elev));
    display: none;
    flex-direction: column;
    gap: 12px;
    overflow: hidden;
    pointer-events: none;
}
#editor-root.is-loading .portal-skel-textbox {
    display: flex;
}

/* Stats inline skeleton */
.portal-skel-stat-bar {
    display: inline-block;
    vertical-align: middle;
    min-width: 4.5rem;
    height: 1.15em;
    border-radius: 6px;
}

/* Chart overlay (usage page) */
.portal-skel-chart-overlay {
    position: absolute;
    inset: 0;
    z-index: 3;
    border-radius: var(--radius);
    pointer-events: none;
    opacity: 0.92;
}

@media (prefers-reduced-motion: reduce) {
    .portal-skel-shimmer {
        animation: none;
        opacity: 0.9;
    }
}

/* ---------- Objectives (agent editor) ---------- */
.objectives-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 10px;
}
.objective-card {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 12px 14px;
    border: 1px solid rgb(var(--border));
    border-radius: var(--radius);
    background-color: rgb(var(--bg-elev));
    cursor: pointer;
    text-align: left;
    transition: border-color .15s ease, background-color .15s ease, box-shadow .15s ease;
}
.objective-card:hover { border-color: rgb(var(--border-strong)); background-color: rgb(var(--bg-subtle)); }
.objective-card.is-selected {
    border-color: rgb(var(--fg));
    background-color: rgb(var(--bg-subtle));
    box-shadow: 0 0 0 1px rgb(var(--fg) / 0.08);
}
.objective-card.is-disabled { opacity: .45; cursor: not-allowed; }
.objective-card.is-disabled:hover { border-color: rgb(var(--border)); background-color: rgb(var(--bg-elev)); }
.objective-card-icon {
    width: 32px; height: 32px; flex-shrink: 0;
    display: grid; place-items: center;
    border-radius: 9px;
    background-color: rgb(var(--bg-subtle));
    color: rgb(var(--fg-muted));
    border: 1px solid rgb(var(--border));
}
.objective-card.is-selected .objective-card-icon {
    background-color: rgb(var(--fg));
    color: rgb(var(--bg));
    border-color: rgb(var(--fg));
}
.objective-card-icon svg { width: 16px; height: 16px; }
.objective-card-body { flex: 1; min-width: 0; }
.objective-card-title {
    font-size: 13px; font-weight: 600; color: rgb(var(--fg));
    display: flex; align-items: center; gap: 6px; justify-content: space-between;
}
.objective-card-desc { font-size: 12px; color: rgb(var(--fg-subtle)); margin-top: 3px; line-height: 1.4; }
.objective-card-check {
    width: 16px; height: 16px; flex-shrink: 0;
    border-radius: 5px;
    border: 1.5px solid rgb(var(--border-strong));
    display: grid; place-items: center;
    color: transparent;
    transition: background-color .15s ease, border-color .15s ease, color .15s ease;
}
.objective-card-check svg { width: 11px; height: 11px; }
.objective-card.is-selected .objective-card-check {
    opacity: 1;
    background-color: rgb(var(--accent));
    border-color: rgb(var(--accent));
    color: #fff;
}

.skill-bind-card {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    padding: 12px 14px;
    cursor: default;
}
.skill-bind-card:hover { cursor: default; }
.skill-bind-toggle {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    width: 100%;
    margin: 0;
    padding: 0;
    border: 0;
    background: transparent;
    text-align: left;
    cursor: pointer;
    color: inherit;
    font: inherit;
}
.skill-bind-toggle:disabled {
    cursor: not-allowed;
}
.skill-bind-version {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin: 0;
}
.skill-bind-version-label {
    font-size: 11px;
    font-weight: 600;
    color: rgb(var(--fg-subtle));
    text-transform: uppercase;
    letter-spacing: 0.02em;
}
.skill-bind-version-select {
    width: 100%;
    font-size: 12.5px;
}
.skill-bind-version-hint {
    font-size: 12px;
    color: rgb(var(--fg-faint));
}
    background-color: rgb(var(--fg));
    border-color: rgb(var(--fg));
    color: rgb(var(--bg));
}

/* ---------- Reports (agent editor) ---------- */
.reports-chart-section { padding: 0; }
.reports-chart-head { margin-bottom: 14px; }
.reports-list { display: flex; flex-direction: column; gap: 10px; }
.report-card {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 14px 16px;
    border: 1px solid rgb(var(--border));
    border-radius: var(--radius);
    background-color: rgb(var(--bg-elev));
    transition: border-color .15s ease, background-color .15s ease;
}
.report-card.is-clickable { cursor: pointer; }
.report-card.is-clickable:hover { border-color: rgb(var(--border-strong)); background-color: rgb(var(--bg-subtle)); }
.report-card-score {
    width: 44px; height: 44px; flex-shrink: 0;
    border-radius: 999px;
    display: grid; place-items: center;
    font-size: 13px; font-weight: 700;
    background-color: rgb(var(--bg-subtle));
    color: rgb(var(--fg-muted));
    border: 1px solid rgb(var(--border));
}
.report-card-score.is-good { color: rgb(var(--success)); border-color: rgb(var(--success) / 0.35); background-color: rgb(var(--success-soft)); }
.report-card-score.is-mid { color: rgb(var(--warning)); border-color: rgb(var(--warning) / 0.35); background-color: rgb(var(--warning-soft)); }
.report-card-score.is-low { color: rgb(var(--danger)); border-color: rgb(var(--danger) / 0.35); background-color: rgb(var(--danger-soft)); }
.report-card-body { flex: 1; min-width: 0; }
.report-card-title { font-size: 13px; font-weight: 600; color: rgb(var(--fg)); display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.report-card-meta { font-size: 11.5px; color: rgb(var(--fg-faint)); margin-top: 3px; }
.report-card-chips { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; }
.report-objective-block { padding: 14px 0; border-top: 1px solid rgb(var(--border)); }
.report-objective-block:first-of-type { border-top: none; padding-top: 4px; }
.report-objective-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 8px; }
.report-objective-title { font-size: 13px; font-weight: 600; color: rgb(var(--fg)); }
.report-score-pill {
    font-size: 12px; font-weight: 700;
    padding: 2px 9px;
    border-radius: 999px;
    background-color: rgb(var(--bg-subtle));
    color: rgb(var(--fg-muted));
    border: 1px solid rgb(var(--border));
}
.report-list-title { font-size: 11.5px; font-weight: 600; color: rgb(var(--fg-subtle)); text-transform: uppercase; letter-spacing: .04em; margin: 10px 0 6px; }
.report-list-plain { padding-left: 1.2rem; margin: 0; font-size: 12.5px; color: rgb(var(--fg)); }
.report-list-plain li { margin: 3px 0; line-height: 1.45; }

/* ---------------------------------------------------------------------------
   Agent Studio Copilot — chat UI
   --------------------------------------------------------------------------- */
.copilot-drawer {
    display: flex;
    flex-direction: column;
    width: 100%;
    max-width: 400px;
    min-width: 300px;
    border: 1px solid rgb(var(--border));
    border-radius: var(--radius-lg);
    background: rgb(var(--bg-elev));
    height: min(78vh, 760px);
    overflow: hidden;
    box-shadow: 0 1px 2px rgb(0 0 0 / 0.04);
}
.copilot-drawer.is-fullscreen {
    max-width: none;
    min-width: 0;
    height: min(84vh, 880px);
}
.copilot-aside {
    min-width: 0;
}
.copilot-aside .copilot-drawer {
    width: 100%;
    max-width: none;
    min-width: 0;
}
.copilot-close-mobile { display: none; }

.copilot-fab {
    display: none;
    position: fixed;
    right: max(16px, env(safe-area-inset-right));
    bottom: max(16px, env(safe-area-inset-bottom));
    z-index: 45;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
    border: 1px solid rgb(var(--border));
    border-radius: 999px;
    background: rgb(var(--accent));
    color: rgb(var(--accent-fg));
    box-shadow: var(--shadow-elev);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
}
.copilot-fab svg { width: 16px; height: 16px; }
.copilot-fab:active { transform: scale(0.98); }

.copilot-sheet-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 55;
    background: rgb(0 0 0 / 0.45);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

@media (max-width: 1023px) {
    .copilot-fab { display: inline-flex; }
    .copilot-sheet-backdrop.is-open { display: block; }
    .copilot-close-mobile { display: inline-flex; }
    body.copilot-sheet-open .copilot-fab { display: none; }

    .copilot-aside {
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 60;
        width: 100% !important;
        max-height: min(92vh, 820px);
        padding: 0;
        transform: translateY(110%);
        transition: transform .28s cubic-bezier(.22, 1, .36, 1);
        pointer-events: none;
    }
    .copilot-aside.is-open {
        transform: translateY(0);
        pointer-events: auto;
    }
    .copilot-aside .copilot-drawer {
        height: min(92vh, 820px);
        max-height: min(92vh, 820px);
        border-radius: 18px 18px 0 0;
        border-left: none;
        border-right: none;
        border-bottom: none;
        box-shadow: var(--shadow-pop);
    }
    body.copilot-sheet-open {
        overflow: hidden;
    }
}

@media (min-width: 1024px) {
    .copilot-fab,
    .copilot-sheet-backdrop,
    .copilot-close-mobile { display: none !important; }
    .copilot-aside {
        position: static !important;
        transform: none !important;
        pointer-events: auto !important;
        max-height: none !important;
    }
}
.copilot-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    border-bottom: 1px solid rgb(var(--border));
    background: rgb(var(--bg-elev));
    flex-shrink: 0;
}
@media (max-width: 1023px) {
    .copilot-header {
        flex-wrap: wrap;
        gap: 8px 10px;
        padding: 12px 14px;
    }
    .copilot-header .title { flex: 1 1 auto; min-width: 40%; }
}
.copilot-header-btn {
    width: 32px;
    height: 32px;
    padding: 0;
    border: 1px solid rgb(var(--border));
    border-radius: 10px;
    background: rgb(var(--bg));
    color: rgb(var(--fg-muted));
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    transition: color .15s ease, border-color .15s ease, background-color .15s ease;
}
.copilot-header-btn:hover {
    color: rgb(var(--fg));
    border-color: rgb(var(--border-strong));
    background: rgb(var(--bg-subtle));
}
.studio-session-item {
    padding: 10px 14px;
    border-bottom: 1px solid rgb(var(--border));
    cursor: pointer;
    font-size: 12px;
}
.studio-session-item__row {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 10px;
}
.studio-session-item__title {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.studio-session-item__cost {
    flex-shrink: 0;
    font-family: var(--font-mono, ui-monospace, monospace);
    font-size: 11px;
    color: rgb(var(--fg-subtle));
}
.studio-session-item:hover { background: rgb(var(--bg-subtle)); }
.studio-session-item.is-active {
    background: rgb(var(--fg) / 0.06);
    font-weight: 600;
}
.copilot-header .title {
    font-size: 13.5px;
    font-weight: 650;
    letter-spacing: -0.01em;
    flex: 1;
    min-width: 0;
}
.copilot-header .title-sub {
    display: block;
    font-size: 11px;
    font-weight: 500;
    color: rgb(var(--fg-faint));
    margin-top: 1px;
}
.copilot-mode {
    display: inline-flex;
    padding: 2px;
    gap: 2px;
    border: 1px solid rgb(var(--border));
    border-radius: 999px;
    background: rgb(var(--bg-subtle));
}
.copilot-mode button {
    font-size: 11px;
    font-weight: 600;
    padding: 5px 11px;
    background: transparent;
    color: rgb(var(--fg-muted));
    border: 0;
    border-radius: 999px;
    cursor: pointer;
    transition: background-color .15s ease, color .15s ease;
}
.copilot-mode button:hover { color: rgb(var(--fg)); }
.copilot-mode button.is-active {
    background: rgb(var(--fg));
    color: rgb(var(--bg));
}
.copilot-thread {
    flex: 1;
    overflow-y: auto;
    padding: 18px 14px 20px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    background:
        radial-gradient(1200px 400px at 50% -10%, rgb(var(--fg) / 0.03), transparent 60%),
        rgb(var(--bg));
}
.copilot-turn {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-width: 100%;
}
.copilot-turn.is-user {
    align-items: flex-end;
}
.copilot-turn.is-assistant {
    align-items: flex-start;
    max-width: min(100%, 34rem);
}
.copilot-msg {
    font-size: 13px;
    line-height: 1.5;
    word-break: break-word;
}
.copilot-msg.user {
    max-width: min(92%, 28rem);
    padding: 10px 14px;
    border-radius: 16px 16px 4px 16px;
    background: rgb(var(--fg));
    color: rgb(var(--bg));
    white-space: pre-wrap;
    box-shadow: 0 1px 2px rgb(0 0 0 / 0.06);
}
.copilot-msg.assistant {
    max-width: 100%;
    padding: 11px 14px;
    border-radius: 4px 16px 16px 16px;
    background: rgb(var(--bg-elev));
    color: rgb(var(--fg));
    border: 1px solid rgb(var(--border));
    box-shadow: 0 1px 2px rgb(0 0 0 / 0.03);
}
.copilot-msg.assistant.copilot-md {
    font-size: 13px;
    line-height: 1.55;
}
.copilot-msg.assistant.copilot-md p { margin: 0.45rem 0; }
.copilot-msg.assistant.copilot-md p:first-child { margin-top: 0; }
.copilot-msg.assistant.copilot-md p:last-child { margin-bottom: 0; }
.copilot-msg.assistant.copilot-md ul,
.copilot-msg.assistant.copilot-md ol { margin: 0.45rem 0; padding-left: 1.2rem; }
.copilot-msg.assistant.copilot-md li + li { margin-top: 0.2rem; }
.copilot-msg.assistant.copilot-md pre {
    max-height: 200px;
    overflow: auto;
    margin: 0.55rem 0;
    border-radius: var(--radius-sm);
}
.copilot-msg.assistant.copilot-md code {
    font-size: 11.5px;
}
.copilot-msg.system {
    align-self: center;
    max-width: 90%;
    font-size: 11.5px;
    font-weight: 500;
    color: rgb(var(--fg-muted));
    background: rgb(var(--bg-subtle));
    border: 1px solid rgb(var(--border));
    border-radius: 999px;
    padding: 5px 12px;
    white-space: pre-wrap;
    text-align: center;
}
.copilot-msg.system.is-typing {
    animation: copilot-pulse 1.2s ease-in-out infinite;
}
@keyframes copilot-pulse {
    0%, 100% { opacity: 0.55; }
    50% { opacity: 1; }
}
.copilot-traces {
    width: 100%;
    font-size: 11px;
    color: rgb(var(--fg-muted));
    border: 1px solid rgb(var(--border));
    border-radius: 12px;
    padding: 8px 11px;
    background: rgb(var(--bg-elev) / 0.7);
}
.copilot-traces summary {
    cursor: pointer;
    font-weight: 600;
    list-style: none;
}
.copilot-traces summary::-webkit-details-marker { display: none; }
.copilot-traces[open] summary { margin-bottom: 6px; }
.copilot-patch {
    width: 100%;
    border: 1px solid rgb(var(--border));
    border-radius: 14px;
    padding: 12px 13px;
    background: rgb(var(--bg-elev));
    box-shadow: 0 1px 2px rgb(0 0 0 / 0.03);
}
.copilot-patch .summary { font-size: 12.5px; font-weight: 650; margin-bottom: 4px; }
.copilot-patch .meta { font-size: 11px; color: rgb(var(--fg-faint)); margin-bottom: 8px; }
.copilot-patch-tabrow {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 8px;
    flex-wrap: wrap;
}
.copilot-patch-tabs {
    display: inline-flex;
    gap: 2px;
    padding: 2px;
    border: 1px solid rgb(var(--border));
    border-radius: 999px;
    background: rgb(var(--bg-subtle));
}
.copilot-patch-tab {
    font-size: 11px;
    font-weight: 600;
    padding: 4px 10px;
    border: 0;
    border-radius: 999px;
    background: transparent;
    color: rgb(var(--fg-muted));
    cursor: pointer;
}
.copilot-patch-tab.is-active {
    background: rgb(var(--fg));
    color: rgb(var(--bg));
}
.copilot-patch-expand {
    flex-shrink: 0;
}
.copilot-patch-views { margin-bottom: 10px; }
.copilot-patch-pane { display: none; }
.copilot-patch-pane.is-active { display: block; }
.copilot-patch-body,
.copilot-diff {
    font-size: 11px;
    max-height: 280px;
    overflow: auto;
    margin: 0;
    padding: 0;
    border-radius: var(--radius-sm);
    background: rgb(var(--bg));
    border: 1px solid rgb(var(--border));
    font-family: "JetBrains Mono", ui-monospace, monospace;
    line-height: 1.45;
}
.copilot-diff {
    /* pre defaults break the scroll-width highlight trick */
    white-space: normal;
}
.copilot-patch-body {
    padding: 10px;
    white-space: pre-wrap;
    word-break: break-word;
}
/* Grid column = max(viewport, longest line); all rows stretch to that width */
.copilot-diff-inner {
    display: grid;
    grid-template-columns: max-content;
    justify-content: stretch;
    width: max-content;
    min-width: 100%;
}
.copilot-diff-line {
    box-sizing: border-box;
    padding: 0 12px;
    min-height: 1.45em;
    white-space: pre;
    min-width: 100%;
}
.copilot-diff-line.add {
    background: rgb(16 185 129 / 0.14);
    color: rgb(4 120 87);
}
.copilot-diff-line.del {
    background: rgb(239 68 68 / 0.12);
    color: rgb(185 28 28);
}
.copilot-diff-line.hunk {
    background: rgb(59 130 246 / 0.1);
    color: rgb(var(--fg-muted));
}
.copilot-diff-line.file {
    color: rgb(var(--fg-muted));
    font-weight: 600;
}
.copilot-diff-line.meta { color: rgb(var(--fg-faint)); }
.copilot-patch .actions { display: flex; gap: 8px; flex-wrap: wrap; }
.dark .copilot-diff-line.add {
    background: rgb(16 185 129 / 0.18);
    color: rgb(110 231 183);
}
.dark .copilot-diff-line.del {
    background: rgb(239 68 68 / 0.18);
    color: rgb(252 165 165);
}

.copilot-diff-modal {
    max-width: min(1100px, 96vw);
    width: 100%;
    max-height: min(90vh, 920px);
    display: flex;
    flex-direction: column;
}
.copilot-diff-modal-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    padding: 16px 18px 0;
}
.copilot-diff-modal-title-wrap { min-width: 0; flex: 1; }
.copilot-diff-modal-body {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    padding: 14px 18px;
}
.copilot-diff-modal-toolbar {
    display: flex;
    align-items: center;
    margin-bottom: 10px;
}
.copilot-diff-modal-views {
    flex: 1;
    min-height: 0;
    margin-bottom: 0;
    display: flex;
    flex-direction: column;
}
.copilot-diff-modal-views .copilot-patch-pane.is-active {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
}
.copilot-diff.is-expanded,
.copilot-diff-modal-views .copilot-patch-body {
    max-height: none;
    flex: 1;
    min-height: 55vh;
}
.copilot-banner {
    margin: 10px 14px 0;
    padding: 9px 12px;
    border-radius: 12px;
    font-size: 12px;
    background: rgb(var(--success-soft));
    color: rgb(var(--success));
    border: 1px solid rgb(var(--success) / 0.2);
    display: none;
    flex-shrink: 0;
}
.copilot-banner.is-visible {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}
.copilot-banner [data-copilot-banner-text] {
    flex: 1;
    min-width: 0;
}
.copilot-banner-dismiss {
    border: 0;
    background: transparent;
    color: inherit;
    opacity: 0.7;
    font-size: 16px;
    line-height: 1;
    cursor: pointer;
    padding: 0 2px;
    flex-shrink: 0;
}
.copilot-banner-dismiss:hover { opacity: 1; }
.copilot-composer {
    border-top: 1px solid rgb(var(--border));
    padding: 12px 14px 14px;
    background: rgb(var(--bg-elev));
    flex-shrink: 0;
}
.copilot-composer-inner {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 8px 8px 8px 12px;
    border: 1px solid rgb(var(--border));
    border-radius: 16px;
    background: rgb(var(--bg));
    transition: border-color .15s ease, box-shadow .15s ease;
}
.copilot-composer-inner:focus-within {
    border-color: rgb(var(--border-strong));
    box-shadow: 0 0 0 3px rgb(var(--fg) / 0.06);
}
.copilot-composer textarea {
    flex: 1;
    min-height: 40px;
    max-height: 132px;
    resize: none;
    font-size: 13px;
    line-height: 1.45;
    border: 0 !important;
    background: transparent !important;
    box-shadow: none !important;
    padding: 8px 0 !important;
    outline: none;
}
.copilot-composer [data-copilot-send] {
    width: 36px;
    height: 36px;
    padding: 0;
    border-radius: 12px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.copilot-empty {
    margin: auto;
    max-width: 240px;
    font-size: 13px;
    line-height: 1.45;
    color: rgb(var(--fg-muted));
    text-align: center;
    padding: 28px 16px;
    border: 1px dashed rgb(var(--border));
    border-radius: 16px;
    background: rgb(var(--bg-elev) / 0.55);
}
.copilot-empty strong {
    display: block;
    color: rgb(var(--fg));
    font-weight: 650;
    margin-bottom: 6px;
}

/* ---------- Agents catalog (grid / table) ---------- */
.agents-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 14px;
}
.agents-toolbar .segmented button {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
}
.agents-toolbar .segmented button svg {
    width: 14px;
    height: 14px;
}

.agents-view[hidden] { display: none !important; }

.agents-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 14px;
}
@media (max-width: 640px) {
    .agents-grid { grid-template-columns: 1fr; gap: 10px; }
}

.agent-tile {
    display: flex;
    flex-direction: column;
    gap: 14px;
    padding: 16px;
    border-radius: var(--radius-lg);
    border: 1px solid rgb(var(--border));
    background: rgb(var(--bg-elev));
    box-shadow: var(--shadow-soft);
    transition: border-color .15s ease, box-shadow .15s ease, transform .15s ease;
    min-width: 0;
}
.agent-tile:hover {
    border-color: rgb(var(--border-strong));
    box-shadow: var(--shadow-elev);
    transform: translateY(-1px);
}
.agent-tile-top {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    min-width: 0;
}
.agent-tile-avatar {
    flex-shrink: 0;
    width: 40px;
    height: 40px;
    border-radius: 12px;
    display: grid;
    place-items: center;
    background: linear-gradient(160deg, rgb(var(--bg-subtle)), rgb(var(--bg-muted)));
    border: 1px solid rgb(var(--border));
    color: rgb(var(--fg-muted));
}
.agent-tile-avatar svg { width: 18px; height: 18px; }
.agent-tile-meta { min-width: 0; flex: 1; }
.agent-tile-name {
    display: block;
    font-size: 14.5px;
    font-weight: 600;
    color: rgb(var(--fg));
    line-height: 1.3;
    text-decoration: none;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.agent-tile-name:hover { text-decoration: underline; text-underline-offset: 2px; }
.agent-tile-id {
    display: block;
    margin-top: 4px;
    font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 11px;
    color: rgb(var(--fg-faint));
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.agent-tile-badges {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-items: center;
}
.agent-tile-badges .status-toggle { cursor: pointer; }
.agent-tile-model {
    font-size: 12px;
    color: rgb(var(--fg-subtle));
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.agent-tile-foot {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-top: auto;
    padding-top: 4px;
    border-top: 1px solid rgb(var(--border));
}
.agent-tile-foot .btn { flex-shrink: 0; }

.agent-tile-skeleton {
    pointer-events: none;
}
.agent-tile-skeleton:hover {
    transform: none;
    box-shadow: var(--shadow-soft);
    border-color: rgb(var(--border));
}

.agents-table-card { overflow: hidden; }
@media (max-width: 768px) {
    .agents-table .col-id,
    .agents-table .col-model { display: none; }
}
@media (max-width: 560px) {
    .agents-table .col-sub { display: none; }
}

/* ---------- Members table + IAM drawer ---------- */
.members-toolbar {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}
.members-toolbar .input { max-width: 320px; flex: 1; min-width: 180px; }
.members-toolbar .btn { margin-left: auto; }

.members-table tbody tr.is-hidden { display: none; }
.members-table .col-actions { text-align: right; white-space: nowrap; }
.members-hint {
    margin: 0 0 12px;
    font-size: 13px;
    color: rgb(var(--fg-subtle));
}

.members-drawer-backdrop,
.contacts-drawer-backdrop {
    position: fixed;
    inset: 0;
    background: rgb(9 9 11 / 0.35);
    z-index: 89;
    opacity: 0;
    pointer-events: none;
    transition: opacity .2s ease;
}
.members-drawer-backdrop.is-open,
.contacts-drawer-backdrop.is-open {
    opacity: 1;
    pointer-events: auto;
}
.dark .members-drawer-backdrop,
.dark .contacts-drawer-backdrop { background: rgb(0 0 0 / 0.55); }

.members-drawer,
.contacts-drawer {
    position: fixed;
    top: 0;
    right: 0;
    height: 100%;
    width: min(480px, 100%);
    background: rgb(var(--bg-elev));
    border-left: 1px solid rgb(var(--border));
    box-shadow: var(--shadow-pop);
    z-index: 90;
    display: flex;
    flex-direction: column;
    transform: translateX(100%);
    transition: transform .22s ease;
    pointer-events: none;
}
.members-drawer.is-open,
.contacts-drawer.is-open {
    transform: translateX(0);
    pointer-events: auto;
}

.members-drawer-header,
.contacts-drawer-header {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 18px 20px 14px;
    border-bottom: 1px solid rgb(var(--border));
}
.members-drawer-header h2,
.contacts-drawer-header h2 {
    font-size: 16px;
    font-weight: 600;
    margin: 0;
}
.members-drawer-header p,
.contacts-drawer-header p {
    margin: 4px 0 0;
    font-size: 12px;
    color: rgb(var(--fg-subtle));
}
.members-drawer-body,
.contacts-drawer-body {
    flex: 1;
    overflow-y: auto;
    padding: 16px 20px 24px;
}
.members-drawer-footer {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 20px;
    border-top: 1px solid rgb(var(--border));
    background: rgb(var(--bg-elev));
}
.members-drawer-footer .spacer { flex: 1; }

.contacts-row { cursor: pointer; }
.contacts-type {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 12px;
    background: rgb(var(--bg-subtle));
    border: 1px solid rgb(var(--border));
}
.contacts-notes {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 8px;
}
.contacts-note {
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    background: rgb(var(--bg-subtle));
    border: 1px solid rgb(var(--border));
}
.contacts-note p { margin: 0; white-space: pre-wrap; }
.contacts-note-meta {
    margin-top: 6px;
    font-size: 11px;
    color: rgb(var(--fg-subtle));
}
.contacts-drawer-error {
    margin: 0 0 12px;
    font-size: 13px;
    color: rgb(var(--danger));
}

.perm-editor { display: flex; flex-direction: column; gap: 10px; }
.perm-editor.is-disabled { opacity: 0.45; pointer-events: none; }
.perm-summary {
    font-size: 12px;
    color: rgb(var(--fg-muted));
    padding: 8px 10px;
    border-radius: var(--radius-sm);
    background: rgb(var(--bg-subtle));
    border: 1px solid rgb(var(--border));
}
.perm-group {
    border: 1px solid rgb(var(--border));
    border-radius: var(--radius);
    background: rgb(var(--bg-elev));
    overflow: hidden;
}
.perm-group-toggle {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    background: rgb(var(--bg-subtle));
    color: rgb(var(--fg));
    font-size: 13px;
    font-weight: 600;
    border: 0;
    cursor: pointer;
    text-align: left;
}
.perm-group-toggle .chevron {
    margin-left: auto;
    width: 14px;
    height: 14px;
    transition: transform .15s ease;
}
.perm-group.is-collapsed .chevron { transform: rotate(-90deg); }
.perm-group.is-collapsed .perm-group-body { display: none; }
.perm-group-body { padding: 12px; display: flex; flex-direction: column; gap: 10px; }
.perm-presets { display: flex; flex-wrap: wrap; gap: 6px; }
.perm-presets button {
    font-size: 11px;
    padding: 4px 8px;
    border-radius: 999px;
    border: 1px solid rgb(var(--border));
    background: rgb(var(--bg));
    color: rgb(var(--fg-muted));
    cursor: pointer;
}
.perm-presets button.is-active {
    background: rgb(var(--fg));
    color: rgb(var(--bg));
    border-color: rgb(var(--fg));
}
.perm-type-label {
    font-size: 11px;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: rgb(var(--fg-subtle));
}
.perm-all-row, .perm-resource-row, .perm-typewide-row {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 13px;
}
.perm-resource-row { justify-content: space-between; padding: 4px 0; }
.perm-resource-row .name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.perm-resource-row select, .perm-typewide-row select {
    font-size: 12px;
    padding: 4px 8px;
    border-radius: var(--radius-sm);
    border: 1px solid rgb(var(--border));
    background: rgb(var(--bg));
    color: rgb(var(--fg));
}
.perm-items {
    display: flex;
    flex-direction: column;
    gap: 2px;
    max-height: 220px;
    overflow-y: auto;
    padding-left: 4px;
}
.perm-inherit-note {
    font-size: 12px;
    color: rgb(var(--fg-subtle));
    margin: 0;
}

/* ---------- Contact inbox (chats) ---------- */
.app-main:has(.contact-inbox) {
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
}
.page:has(.contact-inbox) {
    padding: 0;
    flex: 1;
    min-height: 0;
    max-width: none;
    display: flex;
    flex-direction: column;
    animation: none;
}
.page:has(.contact-inbox) > .mb-4 {
    margin: 0;
    padding: 12px 24px 0;
}
.contact-inbox {
    flex: 1;
    min-height: 0;
    display: flex;
    overflow: hidden;
    position: relative;
}
.ci-list-pane {
    width: 340px;
    flex: 0 0 340px;
    min-height: 0;
    display: flex;
    flex-direction: column;
    border-right: 1px solid rgb(var(--border));
    background: rgb(var(--bg) / 0.72);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}
.ci-list-head {
    flex: 0 0 auto;
    padding: 14px 14px 10px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.ci-list-title-row { display: flex; align-items: center; justify-content: space-between; }
.ci-list-title { font-size: 15px; font-weight: 600; }
.ci-search { position: relative; }
.ci-search svg {
    position: absolute; left: 10px; top: 50%; transform: translateY(-50%);
    width: 14px; height: 14px; color: rgb(var(--fg-faint)); pointer-events: none;
}
.ci-search-input {
    width: 100%; height: 34px; padding: 0 10px 0 30px;
    border-radius: 8px; border: 1px solid rgb(var(--border));
    background: rgb(var(--bg-subtle)); color: rgb(var(--fg));
    font-size: 13px; font-family: inherit; outline: none;
}
.ci-search-input.no-icon { padding-left: 10px; }
.ci-search-input::placeholder { color: rgb(var(--fg-faint)); }
.ci-search-input:focus { border-color: rgb(var(--border-strong)); background: rgb(var(--bg-elev)); }
.ci-contact-list {
    flex: 1 1 auto; min-height: 0; overflow-y: auto;
    padding: 4px 8px 12px;
    display: flex; flex-direction: column; gap: 2px;
}
.ci-row {
    width: 100%; display: flex; align-items: center; gap: 10px;
    padding: 8px; border: 0; border-radius: 10px;
    background: transparent; color: inherit; text-align: left;
    cursor: pointer; font: inherit;
}
.ci-row:hover { background: rgb(var(--bg-subtle)); }
.ci-row.is-active { background: rgb(var(--bg-muted)); }
.ci-row.is-operator { background: rgba(85, 140, 240, 0.14); }
.ci-row.is-operator:hover { background: rgba(85, 140, 240, 0.22); }
.ci-row.is-operator.is-active { background: rgba(85, 140, 240, 0.30); }
.dark .ci-row.is-operator { background: rgba(85, 140, 240, 0.16); }
.dark .ci-row.is-operator:hover { background: rgba(85, 140, 240, 0.24); }
.dark .ci-row.is-operator.is-active { background: rgba(85, 140, 240, 0.32); }
.ci-avatar {
    flex: 0 0 auto; width: 40px; height: 40px; border-radius: 999px; color: #fff;
    display: grid; place-items: center; font-size: 13px; font-weight: 600; letter-spacing: 0.02em;
}
.ci-meta { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.ci-top, .ci-bottom { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.ci-top { align-items: baseline; }
.ci-name { font-size: 13.5px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ci-time { flex: 0 0 auto; font-size: 11px; color: rgb(var(--fg-faint)); }
.ci-preview { font-size: 12.5px; color: rgb(var(--fg-subtle)); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ci-unread {
    flex: 0 0 auto; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 999px;
    background: rgb(var(--fg)); color: rgb(var(--bg));
    font-size: 10.5px; font-weight: 700; display: grid; place-items: center;
}
.ci-skel-list, .ci-skel-thread { display: flex; flex-direction: column; }
.ci-skel-list { gap: 2px; }
.ci-skel-row { display: flex; align-items: center; gap: 10px; padding: 8px; }
.ci-skel-avatar { width: 40px; height: 40px; border-radius: 999px; flex: 0 0 auto; }
.ci-skel-meta { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: 8px; }
.ci-skel-line { display: block; height: 10px; border-radius: 999px; }
.ci-skel-thread { gap: 12px; padding: 8px 0 12px; }
.ci-skel-bubble { display: block; height: 52px; border-radius: 15px; }
.ci-skel-bubble.is-in { align-self: flex-start; border-bottom-left-radius: 5px; }
.ci-skel-bubble.is-out { align-self: flex-end; border-bottom-right-radius: 5px; }
.ci-chat {
    flex: 1 1 auto; min-width: 0; min-height: 0;
    display: flex; flex-direction: column;
    background: rgb(var(--bg) / 0.58);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}
.ci-chat-inner { display: flex; flex-direction: column; height: 100%; min-height: 0; min-width: 0; width: 100%; }
.ci-header {
    flex: 0 0 auto; display: flex; align-items: center; gap: 12px;
    padding: 10px 20px; border-bottom: 1px solid rgb(var(--border));
}
.ci-back {
    display: none; flex: 0 0 auto; width: 30px; height: 30px; border-radius: 8px; border: 0;
    background: transparent; color: rgb(var(--fg-muted));
    align-items: center; justify-content: center; cursor: pointer;
}
.ci-back:hover { background: rgb(var(--bg-subtle)); color: rgb(var(--fg)); }
.ci-header-identity {
    flex: 1 1 auto; min-width: 0; display: flex; align-items: center; gap: 12px;
    margin: 0; padding: 4px 6px; border: 0; border-radius: 10px;
    background: transparent; color: inherit; font: inherit; text-align: left; cursor: pointer;
}
.ci-header-identity:hover { background: rgb(var(--bg-subtle)); }
.ci-header-meta { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; }
.ci-header-name, .ci-header-phone { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ci-header-name { font-size: 14px; font-weight: 600; }
.ci-header-phone { font-size: 12px; color: rgb(var(--fg-subtle)); }
.ci-profile {
    flex: 1 1 auto; min-height: 0; overflow-y: auto;
    padding: 22px 28px 40px;
}
.ci-profile-back {
    display: inline-flex; align-items: center; gap: 4px;
    margin: 0 0 18px; padding: 4px 8px 4px 2px; border: 0; border-radius: 8px;
    background: transparent; color: rgb(var(--fg-muted)); font: inherit; font-size: 13px; cursor: pointer;
}
.ci-profile-back:hover { background: rgb(var(--bg-subtle)); color: rgb(var(--fg)); }
.ci-profile-hero { display: flex; align-items: center; gap: 14px; margin-bottom: 22px; }
.ci-avatar-lg { width: 56px; height: 56px; font-size: 16px; }
.ci-profile-id { min-width: 0; }
.ci-profile-name { font-size: 20px; font-weight: 650; }
.ci-profile-phone { margin-top: 2px; font-size: 13px; color: rgb(var(--fg-subtle)); }
.ci-profile-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px 20px; }
.ci-profile-label { font-size: 11px; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; color: rgb(var(--fg-faint)); }
.ci-profile-value { margin-top: 3px; font-size: 14px; overflow-wrap: anywhere; }
.ci-profile-notes { margin-top: 28px; }
.ci-profile-notes h3, .ci-profile-media h3 { margin: 0 0 10px; font-size: 14px; font-weight: 650; }
.ci-profile-media { margin-top: 28px; }
.ci-media-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.ci-media-tile {
    display: block; aspect-ratio: 1; border-radius: 10px; overflow: hidden;
    background: rgb(var(--bg-subtle)); border: 1px solid rgb(var(--border));
}
.ci-media-tile img { width: 100%; height: 100%; object-fit: cover; display: block; }
.ci-media-files { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }
.ci-media-file { display: flex; align-items: center; justify-content: space-between; gap: 10px; min-width: 0; }
.ci-media-file-meta { flex: 0 1 auto; font-size: 11px; color: rgb(var(--fg-faint)); text-align: right; }
.ci-header-badges {
    flex: 0 0 auto; display: flex; align-items: center; gap: 10px;
    flex-wrap: wrap; justify-content: flex-end;
}
.ci-pause { display: flex; align-items: center; gap: 6px; cursor: pointer; }
.ci-pause-track {
    position: relative; width: 32px; height: 18px; border-radius: 999px;
    background: rgb(var(--bg-muted)); flex: 0 0 auto; transition: background .15s ease;
}
.ci-pause-track.is-on { background: rgb(var(--warning)); }
.ci-pause-input { position: absolute; inset: 0; margin: 0; opacity: 0; cursor: pointer; }
.ci-pause-knob {
    position: absolute; top: 2px; left: 2px; width: 14px; height: 14px; border-radius: 999px;
    background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,0.3);
    transition: transform .15s ease; pointer-events: none;
}
.ci-pause-input:checked + .ci-pause-knob { transform: translateX(14px); }
.ci-pause-text { font-size: 11px; font-weight: 600; color: rgb(var(--fg-muted)); white-space: nowrap; }
.ci-messages {
    flex: 1 1 auto; min-height: 0; min-width: 0; width: 100%; overflow-y: auto;
    overflow-anchor: none;
    padding: 18px 22px; display: flex; flex-direction: column;
}
.ci-thread {
    position: relative; flex: 1 1 auto; min-height: 0; min-width: 0;
    display: flex; flex-direction: column;
}
.ci-new-pill {
    position: absolute; z-index: 4; left: 50%; bottom: 12px; transform: translateX(-50%);
    max-width: calc(100% - 24px); height: 32px; padding: 0 14px; border: 0; border-radius: 999px;
    background: rgb(var(--fg)); color: rgb(var(--bg));
    font: inherit; font-size: 12px; font-weight: 700; white-space: nowrap; cursor: pointer;
    box-shadow: var(--shadow-elev);
}
.ci-new-pill:hover { opacity: 0.9; }
.ci-messages-flow {
    margin-top: auto; display: flex; flex-direction: column; gap: 8px; min-width: 0;
}
.ci-bubble {
    max-width: 68%; padding: 9px 13px; border-radius: 15px;
    font-size: 13px; line-height: 1.5; overflow-wrap: anywhere;
}
.ci-bubble-user { background: rgb(var(--fg)); color: rgb(var(--bg)); border-bottom-left-radius: 5px; }
.ci-bubble-bot { background: rgb(var(--bg-elev)); color: rgb(var(--fg)); border: 1px solid rgb(var(--border)); border-bottom-right-radius: 5px; }
.ci-bubble-operator { background: rgb(var(--info-soft)); color: rgb(var(--fg)); border: 1px solid transparent; border-bottom-right-radius: 5px; }
.ci-bubble-template { background: rgb(var(--bg-elev)); color: rgb(var(--fg)); border: 1px dashed rgb(var(--border-strong)); border-bottom-right-radius: 5px; }
.ci-bubble-label { font-size: 10px; font-weight: 700; letter-spacing: 0.03em; text-transform: uppercase; opacity: 0.65; margin-bottom: 3px; }
.ci-bubble-time { margin-top: 4px; font-size: 10px; text-align: right; opacity: 0.6; }
.ci-msg { display: flex; min-width: 0; width: 100%; }
.ci-pill-row { display: flex; justify-content: center; margin: 4px 0; }
.ci-pill {
    display: inline-flex; align-items: center; gap: 6px; padding: 4px 13px; border-radius: 999px;
    font-size: 10.5px; font-weight: 600; white-space: nowrap;
    background: rgb(var(--bg-subtle)); color: rgb(var(--fg-subtle)); border: 1px solid rgb(var(--border));
}
.ci-pill-day { background: rgb(var(--bg-muted)); color: rgb(var(--fg-muted)); }
.ci-pill-start { color: rgb(var(--success)); background: rgb(var(--success-soft)); border-color: transparent; }
.ci-pill-end { color: rgb(var(--fg-faint)); background: rgb(var(--bg-subtle)); }
.ci-pill-dot { width: 6px; height: 6px; border-radius: 999px; background: currentColor; flex: 0 0 auto; }
.ci-thread-empty, .ci-empty {
    margin: auto; padding: 28px 16px; text-align: center;
    display: flex; flex-direction: column; align-items: center; gap: 6px;
}
.ci-empty { flex: 1; justify-content: center; }
.ci-empty-icon, .ci-thread-icon {
    border-radius: 10px; background: rgb(var(--bg-subtle));
    display: grid; place-items: center; color: rgb(var(--fg-faint));
}
.ci-thread-icon { width: 40px; height: 40px; }
.ci-empty-icon { width: 44px; height: 44px; border-radius: 12px; }
.ci-thread-title, .ci-empty-title { font-size: 13px; font-weight: 600; }
.ci-empty-title { font-size: 14px; }
.ci-thread-desc, .ci-empty-desc { font-size: 12px; color: rgb(var(--fg-subtle)); max-width: 280px; margin: 0; }
.ci-hint { margin: 0; padding: 0 20px 8px; font-size: 11.5px; color: rgb(var(--warning)); }
.ci-pause-banner {
    flex: 0 0 auto; margin: 0; padding: 9px 20px;
    background: rgb(202 138 4); color: #fff;
    font-size: 12.5px; font-weight: 700; line-height: 1.4; text-align: center;
}
.ci-composer {
    flex: 0 0 auto; display: flex; align-items: flex-end; gap: 8px;
    min-width: 0; width: 100%;
    padding: 12px 20px 16px; border-top: 1px solid rgb(var(--border));
}
.ci-composer-input {
    flex: 1 1 auto; min-width: 0; min-height: 40px; max-height: 140px; resize: none;
    border-radius: 12px; border: 1px solid rgb(var(--border));
    background: rgb(var(--bg-subtle)); color: rgb(var(--fg));
    font-size: 13px; font-family: inherit; padding: 10px 12px; outline: none;
}
.ci-composer-main { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.ci-attach { flex: 0 0 auto; align-self: center; color: rgb(var(--fg-muted)); }
.ci-attach:disabled { opacity: 0.35; cursor: not-allowed; }
.ci-pending-file {
    display: flex; align-items: center; gap: 8px; min-width: 0;
    padding: 6px 8px; border: 1px solid rgb(var(--border)); border-radius: 10px;
    background: rgb(var(--bg-elev)); font-size: 12px;
}
.ci-pending-file img { width: 36px; height: 36px; object-fit: cover; border-radius: 6px; flex: 0 0 auto; }
.ci-pending-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.ci-pending-size { flex: 0 0 auto; color: rgb(var(--fg-faint)); }
.ci-pending-file .btn { flex: 0 0 auto; margin-left: auto; }
.ci-bubble .chat-file-chip { background: rgb(var(--bg-subtle)); border: 1px solid rgb(var(--border)); }
.ci-bubble-user .chat-file-chip { background: rgb(255 255 255 / 0.12); border-color: transparent; }
.ci-bubble.is-pending { opacity: 0.78; }
.ci-send-skel,
.ci-skel {
    background: linear-gradient(90deg, rgb(var(--bg-muted)) 0%, rgb(var(--bg-subtle)) 42%, rgb(var(--bg-muted)) 88%);
    background-size: 140px 100%;
    animation: shimmer 1.15s ease-in-out infinite;
}
.ci-send-skel {
    display: inline-block; width: 42px; height: 8px; border-radius: 999px; vertical-align: middle;
}
.ci-media-pending { position: relative; }
.ci-skel-overlay { position: absolute; inset: 0; border-radius: 10px; opacity: 0.55; }
.ci-bubble .chat-voice { width: 220px; color: inherit; }
.ci-bubble-user .chat-voice-btn { background: rgb(var(--bg)); color: rgb(var(--fg)); }
.ci-bubble-bot .chat-voice-btn,
.ci-bubble-operator .chat-voice-btn,
.ci-bubble-template .chat-voice-btn { background: rgb(var(--fg)); color: rgb(var(--bg)); }
.ci-bubble .chat-voice-wave span { opacity: 0.35; background: currentColor; }
.ci-bubble .chat-voice-wave span.is-played { opacity: 1; }
.ci-bubble-user .chat-voice-time { color: inherit; }
.ci-media-hold {
    width: 220px; max-width: 100%; height: 160px; border-radius: 10px;
    display: grid; place-items: center; font-size: 12px; font-weight: 600;
    background: rgb(var(--bg-subtle)); color: rgb(var(--fg-muted));
}
.ci-media-hold-audio { width: 180px; height: 40px; }
.ci-media-hold-loading { position: relative; overflow: hidden; color: transparent; }
.ci-bubble-user .ci-media-hold { background: rgb(255 255 255 / 0.14); color: inherit; }
button.chat-media-link {
    border: 0; padding: 0; background: none; cursor: zoom-in; display: block; line-height: 0;
}
button.ci-media-tile { border: 0; padding: 0; cursor: zoom-in; width: 100%; }
.ci-lightbox {
    position: fixed; inset: 0; z-index: 120;
    display: flex; align-items: center; justify-content: center;
    padding: 28px; background: rgb(0 0 0 / 0.9);
}
.ci-lightbox img {
    max-width: 100%; max-height: 100%; object-fit: contain;
    border-radius: 4px;
}
.ci-lightbox-close {
    position: absolute; top: 16px; right: 16px;
    width: 40px; height: 40px; border: 0; border-radius: 999px;
    display: grid; place-items: center; cursor: pointer;
    background: rgb(255 255 255 / 0.12); color: #fff;
}
.ci-lightbox-close:hover { background: rgb(255 255 255 / 0.22); }
.ci-skel-file { display: block; width: 168px; height: 36px; border-radius: 8px; }
.ci-send-failed { color: rgb(var(--danger)); }
.ci-retry {
    border: 0; background: transparent; color: inherit; font: inherit; font-weight: 650;
    text-decoration: underline; cursor: pointer; padding: 0 0 0 4px;
}
.ci-composer-input::placeholder { color: rgb(var(--fg-faint)); }
.ci-composer-input:focus { border-color: rgb(var(--border-strong)); background: rgb(var(--bg-elev)); }
.ci-template-trigger { color: rgb(var(--fg-faint)); align-self: center; }
.ci-send {
    flex: 0 0 auto; width: 40px; height: 40px; border-radius: 999px; border: 0;
    background: rgb(var(--fg)); color: rgb(var(--bg));
    display: grid; place-items: center; cursor: pointer;
}
.ci-send:hover { opacity: 0.88; }
.ci-send:disabled { opacity: 0.35; cursor: not-allowed; }
.ci-composer-closed { justify-content: center; padding: 14px 20px 18px; }
.ci-template-cta {
    display: inline-flex; align-items: center; gap: 8px; height: 40px; padding: 0 16px;
    border-radius: 999px; border: 1px dashed rgb(var(--border-strong));
    background: rgb(var(--bg-subtle)); color: rgb(var(--fg));
    font-size: 13px; font-weight: 600; cursor: pointer; font-family: inherit;
}
.ci-template-cta:hover { background: rgb(var(--bg-muted)); }
.ci-overlay {
    position: fixed; inset: 0; background: rgba(0,0,0,0.5);
    display: flex; align-items: center; justify-content: center;
    z-index: 80; padding: 20px;
}
.ci-modal {
    width: 100%; max-width: 420px; max-height: 82vh;
    background: rgb(var(--bg-elev)); border-radius: 14px;
    display: flex; flex-direction: column; overflow: hidden;
    box-shadow: 0 20px 60px rgba(0,0,0,0.35);
}
.ci-modal-wide { max-width: 520px; }
.ci-modal-head {
    flex: 0 0 auto; display: flex; align-items: flex-start; justify-content: space-between; gap: 10px;
    padding: 16px 18px; border-bottom: 1px solid rgb(var(--border));
}
.ci-modal-title { font-size: 14.5px; font-weight: 600; }
.ci-modal-sub { font-size: 12px; color: rgb(var(--fg-subtle)); margin-top: 2px; }
.ci-modal-body {
    flex: 1 1 auto; min-height: 0; overflow-y: auto;
    padding: 16px 18px; display: flex; flex-direction: column; gap: 12px;
}
.ci-modal-foot {
    flex: 0 0 auto; display: flex; justify-content: flex-end; gap: 8px;
    padding: 12px 18px; border-top: 1px solid rgb(var(--border));
}
.ci-modal-hint { font-size: 11.5px; color: rgb(var(--fg-faint)); margin: 0; }
.ci-field { display: flex; flex-direction: column; gap: 6px; }
.ci-field-label { font-size: 12px; font-weight: 600; color: rgb(var(--fg-muted)); }
.ci-template-list { display: flex; flex-direction: column; gap: 6px; }
.ci-template-row {
    width: 100%; text-align: left; border: 1px solid rgb(var(--border));
    background: rgb(var(--bg)); border-radius: 10px; padding: 10px 12px;
    cursor: pointer; display: flex; flex-direction: column; gap: 4px;
    font: inherit; color: inherit;
}
.ci-template-row:hover { background: rgb(var(--bg-subtle)); border-color: rgb(var(--border-strong)); }
.ci-template-row-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.ci-template-name { font-size: 12.5px; font-weight: 600; font-family: 'JetBrains Mono', ui-monospace, monospace; }
.ci-template-body {
    margin: 0; font-size: 12px; color: rgb(var(--fg-subtle));
    display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.ci-template-meta { font-size: 11px; color: rgb(var(--fg-faint)); }
.ci-back-link {
    align-self: flex-start; border: 0; background: transparent;
    color: rgb(var(--fg-subtle)); font-size: 12px; cursor: pointer; padding: 0; font-family: inherit;
}
.ci-back-link:hover { color: rgb(var(--fg)); }
.ci-template-detail-name { font-size: 13.5px; font-weight: 600; font-family: 'JetBrains Mono', ui-monospace, monospace; }
.ci-template-badges { display: flex; gap: 6px; }
#ci-tpl-detail-view:not(.hidden-imp) {
    display: flex;
    flex-direction: column;
    min-height: 0;
    flex: 1 1 auto;
}
@media (max-width: 760px) {
    .app-main:has(.contact-inbox) .topbar > .flex-col { display: none; }
    .ci-list-pane { width: 100%; flex: 1 1 auto; border-right: none; }
    .ci-chat { display: none; }
    .contact-inbox.has-selection .ci-list-pane { display: none; }
    .contact-inbox.has-selection .ci-chat { display: flex; }
    .ci-back { display: inline-flex; }
    .ci-header { flex-wrap: nowrap; align-items: center; gap: 8px; padding: 8px 12px; }
    .ci-header-identity { gap: 8px; padding: 2px 0; }
    .ci-header-badges {
        flex: 0 1 auto; min-width: 0; margin-left: auto;
        flex-wrap: nowrap; justify-content: flex-end; gap: 4px;
    }
    .ci-header-badges .badge { padding: 2px 6px; font-size: 10px; white-space: nowrap; }
    .ci-pause-text { display: none; }
    .ci-composer, .ci-composer-closed { padding-left: 12px; padding-right: 12px; }
    .ci-messages { padding: 14px 12px; }
    .ci-bubble { max-width: 85%; }
    .ci-profile { padding: 16px 14px 32px; }
    .ci-profile-grid { grid-template-columns: 1fr; }
}
