/* Console-only overrides. Keep after themes/devices/agents so the 2.3
   components share the compact layout and the selected light/dark palette. */

/* Messages: override utility padding/widths without touching task/guest views. */
#view-chat #chat-messages { min-height: 0; }
#view-chat #chat-messages > .user-message-group,
#view-chat #chat-messages > .bot-message-group { padding-top: 7px; padding-bottom: 7px; }
#view-chat .user-message-group > div:first-child { min-width: 0; max-width: 86%; }
#view-chat .bot-message-group { gap: 8px; }
#view-chat .bot-message-group > .min-w-0 { max-width: 94%; }
#view-chat .msg-content { font-size: 13.5px; line-height: 1.55; }
#view-chat .user-bubble { padding: 7px 13px; border-radius: 14px; }
#view-chat .bot-message-group > .min-w-0 > .msg-content { padding: 9px 12px; border-radius: 14px; }
#view-chat .bot-face,
#view-chat .bot-face > .agent-avatar { width: 26px; height: 26px; }
#view-chat .bot-face > .agent-avatar { font-size: 13px; }
#view-chat .agent-content-step { font-size: inherit; line-height: inherit; }
#view-chat .tool-detail-label { opacity: 1; color: rgb(var(--cw-slate-500)); }
.dark #view-chat .tool-detail-label { color: rgb(var(--cw-slate-400)); }
#view-chat .tool-delivery { min-width: 0; overflow-wrap: anywhere; }
#view-chat .tool-delivery img,
#view-chat .tool-delivery video { max-width: 100%; }
#view-chat .tool-delivery .file-attachment { max-width: 100%; overflow-wrap: anywhere; }

/* Auto-height plus auto margins centers when there is room, but never clips
   the logo/top of the welcome page on short windows or with the keyboard up. */
#view-chat #welcome-screen {
    height: auto;
    min-height: 100%;
    justify-content: flex-start;
    padding: 24px 24px 28px !important; /* replaces inline 6vh top padding */
}
#view-chat #welcome-screen > * { flex-shrink: 0; }
#view-chat #welcome-screen > img:first-child { margin-top: auto; margin-bottom: 14px; width: 52px; height: 52px; }
#view-chat #welcome-screen > .grid:last-child { margin-bottom: auto; gap: 10px; }
#view-chat #welcome-title { font-size: 21px; margin-bottom: 8px; }
#view-chat #welcome-subtitle { font-size: 13px; line-height: 1.55; margin-bottom: 20px; }
#view-chat .example-card { min-width: 0; padding: 12px; }
#view-chat .example-card > div:first-child { margin-bottom: 6px; }
#view-chat .example-card > p { font-size: 12px; line-height: 1.5; min-height: 3em; }
#view-chat #chat-composer { padding-top: 8px; padding-bottom: 8px; }

/* Native details is intentionally NOT an .agent-tool-step: the group toggle
   must not be captured by individual tool handlers. Keep body flow unrestricted
   so nested lazy panels and keyboard focus remain reachable. */
#view-chat details.agent-tools-accordion {
    margin: 4px 0;
    border: 1px solid rgb(var(--cw-slate-200));
    border-radius: 8px;
    background: rgb(var(--cw-slate-50));
    color: rgb(var(--cw-slate-600));
    font-size: 12px;
    line-height: 1.45;
    min-width: 0;
}
#view-chat .agent-tools-accordion > .tools-group-header {
    display: flex;
    align-items: center;
    gap: 7px;
    min-height: 30px;
    padding: 6px 9px;
    border-radius: 7px;
    list-style: none;
    cursor: pointer;
    overflow-wrap: anywhere;
    user-select: none;
}
#view-chat .tools-group-header::-webkit-details-marker { display: none; }
#view-chat .tools-group-header::marker { content: ''; }
#view-chat .agent-tools-accordion > .tools-group-header::before {
    content: '';
    width: 6px;
    height: 6px;
    flex-shrink: 0;
    border-right: 1.5px solid currentColor;
    border-bottom: 1.5px solid currentColor;
    transform: rotate(-45deg);
    transition: transform .15s ease;
}
#view-chat .agent-tools-accordion[open] > .tools-group-header::before { transform: rotate(45deg); }
#view-chat .agent-tools-accordion > .tools-group-header:hover { background: rgb(var(--cw-slate-100)); color: rgb(var(--cw-slate-800)); }
#view-chat .agent-tools-accordion > .tools-group-body { min-width: 0; padding: 6px 9px 8px; border-top: 1px solid rgb(var(--cw-slate-200)); }
#view-chat .agent-tools-accordion:not([open]) > .tools-group-body { display: none; }
#view-chat .tools-group-body > .agent-step { margin-bottom: 5px; }
#view-chat .tools-group-body > .agent-step:last-child { margin-bottom: 0; }
.dark #view-chat details.agent-tools-accordion { background: rgba(255,255,255,.035); border-color: rgba(255,255,255,.1); color: rgb(var(--cw-slate-400)); }
.dark #view-chat .agent-tools-accordion > .tools-group-header:hover { background: rgba(255,255,255,.06); color: rgb(var(--cw-slate-200)); }
.dark #view-chat .agent-tools-accordion > .tools-group-body { border-top-color: rgba(255,255,255,.1); }

/* Light sidebar must remain readable even during pre-auth replay of an old
   theme cache containing a dark --cw-sidebar. New caches use panel as well. */
html:not(.dark) #sidebar {
    background: rgb(var(--cw-panel));
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    border-right: 1px solid rgb(var(--cw-slate-200));
}
.dark #sidebar { border-right: 1px solid rgba(255,255,255,.08); }
html:not(.dark) .sidebar-collapse-btn { color: rgb(var(--cw-slate-500)); }
html:not(.dark) .sidebar-collapse-btn:hover { color: rgb(var(--cw-slate-800)); background: rgb(var(--cw-slate-100)); }
html:not(.dark) #sidebar-nav:hover { scrollbar-color: rgb(var(--cw-slate-300)) transparent; }
html:not(.dark) #sidebar-nav:hover::-webkit-scrollbar-thumb { background: rgb(var(--cw-slate-300)); }
html:not(.dark) #sidebar-nav:hover::-webkit-scrollbar-thumb:hover { background: rgb(var(--cw-slate-400)); }
@media (min-width: 1024px) {
    html.sidebar-collapsed:not(.dark) .menu-group + .menu-group::before { background: rgb(var(--cw-slate-200)); }
}
html:not(.dark) .device-switcher { color: rgb(var(--cw-slate-700)); }
html:not(.dark) .device-switcher:hover,
html:not(.dark) .device-switcher[aria-expanded="true"] { background: rgb(var(--cw-slate-100)); }
html:not(.dark) .device-switcher-name { color: rgb(var(--cw-slate-800)); }
html:not(.dark) .device-switcher-sub,
html:not(.dark) .device-switcher-chevron { color: rgb(var(--cw-slate-500)); }
html:not(.dark) .device-switcher:hover .device-switcher-chevron { color: rgb(var(--cw-slate-700)); }
html:not(.dark) .device-switcher-icon,
html:not(.dark) .device-switcher.is-remote .device-switcher-sub { color: rgb(var(--cw-primary-700)); }

/* Menus are portalled outside the sidebar; do not scope them to #sidebar. */
.instance-menu,
.color-theme-menu { max-width: calc(100vw - 16px); max-height: calc(100vh - 16px); overflow-y: auto; }
html:not(.dark) .instance-menu,
html:not(.dark) .color-theme-menu {
    background: rgb(var(--cw-panel));
    border-color: rgb(var(--cw-slate-200));
    box-shadow: 0 8px 30px -6px rgba(0,0,0,.15), 0 2px 8px -2px rgba(0,0,0,.08);
}
html:not(.dark) .instance-menu-item,
html:not(.dark) .color-theme-item { color: rgb(var(--cw-slate-700)); }
html:not(.dark) .instance-menu-item:hover,
html:not(.dark) .color-theme-item:hover { background: rgb(var(--cw-slate-100)); color: rgb(var(--cw-slate-900)); }
html:not(.dark) .instance-menu-head,
html:not(.dark) .instance-menu-sub,
html:not(.dark) .color-theme-plus { color: rgb(var(--cw-slate-500)); }
html:not(.dark) .instance-menu-icon { background: rgb(var(--cw-slate-100)); color: rgb(var(--cw-slate-500)); }
html:not(.dark) .instance-menu-item.is-active .instance-menu-icon,
html:not(.dark) .instance-menu-check,
html:not(.dark) .color-theme-check { color: rgb(var(--cw-primary-700)); }
html:not(.dark) .instance-menu-icon .instance-dot { box-shadow: 0 0 0 2px rgb(var(--cw-panel)); }
html:not(.dark) .color-theme-divider { border-top-color: rgb(var(--cw-slate-200)); }
html:not(.dark) .color-theme-swatch { border-color: rgb(var(--cw-slate-300)); }

/* Visible keyboard affordances, scoped to console controls. */
#view-chat .tools-group-header:focus-visible,
#view-chat .tool-header:focus-visible,
#view-chat .thinking-header:focus-visible,
#chat-composer button:focus-visible,
#sidebar button:focus-visible,
#sidebar a:focus-visible,
.instance-menu button:focus-visible,
.color-theme-flyout button:focus-visible {
    outline: 2px solid rgb(var(--cw-primary-400));
    outline-offset: 2px;
}
#view-chat .user-message-group:focus-within .edit-msg-btn,
#view-chat .user-message-group:focus-within .delete-msg-btn,
#view-chat .bot-message-group:focus-within .regenerate-msg-btn { opacity: 1; }

@media (max-width: 768px) {
    #view-chat #chat-messages > .user-message-group,
    #view-chat #chat-messages > .bot-message-group { padding: 5px 10px; }
    #view-chat .msg-content { font-size: 13px; }
    #view-chat .user-bubble { padding: 6px 11px; border-radius: 12px; }
    #view-chat .bot-message-group > .min-w-0 > .msg-content { padding: 8px 10px; border-radius: 12px; }
    #view-chat .bot-message-group { gap: 6px; }
    #view-chat #chat-composer {
        padding: 6px max(8px, env(safe-area-inset-right, 0px)) calc(8px + env(safe-area-inset-bottom, 0px)) max(8px, env(safe-area-inset-left, 0px));
    }
    #view-chat .composer-card { padding: 6px 7px 5px; gap: 4px; border-radius: 14px; }
    /* 16px prevents iOS focus zoom while message bubbles stay at 13px. */
    #view-chat #chat-input { min-height: 36px; font-size: 16px; line-height: 1.5; }
    #view-chat .composer-icon-btn { width: 26px; height: 26px; font-size: 13px; }
    #view-chat .composer-send-btn { width: 28px; height: 28px; }
    #view-chat .composer-agent-btn,
    #view-chat .composer-agent-btn .agent-avatar { width: 26px; height: 26px; }
    #view-chat .composer-menu,
    #view-chat .workspace-selector-menu { max-width: 100%; max-height: min(380px, 50vh); }
    #view-chat #welcome-screen { padding: 16px 12px 20px !important; }
    #view-chat #welcome-screen > img:first-child { width: 44px; height: 44px; margin-bottom: 10px; border-radius: 12px; }
    #view-chat #welcome-title { font-size: 18px; margin-bottom: 6px; }
    #view-chat #welcome-subtitle { font-size: 12px; margin-bottom: 14px; }
    #view-chat #welcome-screen > .grid:last-child { gap: 8px; }
    #view-chat .example-card { padding: 9px; border-radius: 10px; }
    #view-chat .example-card > div:first-child { gap: 6px; margin-bottom: 4px; }
    #view-chat .example-card > div:first-child > div { width: 24px; height: 24px; }
    #view-chat .example-card > div:first-child > span { font-size: 12px; }
    #view-chat .example-card > p { font-size: 11px; }
    .instance-menu,
    .color-theme-menu { max-height: calc(100dvh - 16px); }
}
@media (max-width: 480px) {
    /* Never clip popovers with overflow:hidden: let the toolbar wrap when all
       optional controls (multi-Agent and steer) are visible on a 320px phone. */
    #view-chat .composer-toolbar { flex-wrap: wrap; gap: 4px; }
    #view-chat .composer-group { gap: 1px; }
    #view-chat .composer-group-end { flex: 1 1 auto; justify-content: flex-end; gap: 2px; }
    #view-chat .composer-chip { padding: 4px 5px; }
    #view-chat .composer-chip-caret { display: none; }
    #view-chat .composer-divider { margin: 0 2px; }
}
@media (prefers-reduced-motion: reduce) {
    #view-chat .agent-tools-accordion > .tools-group-header::before { transition: none; }
}
