/* Main CSS - Root Variables and Global Styles */

:root {
    /* Color Palette */
    --primary-color: #4285f4;
    --primary-hover: #3367d6;
    --primary-light: #e8f0fe;
    --secondary-color: #5f6368;
    --background-color: #ffffff;
    --surface-color: #f8f9fa;
    --sidebar-bg: #f8f9fa;
    --border-color: #e8eaed;
    --text-primary: #202124;
    --text-secondary: #5f6368;
    --text-tertiary: #80868b;
    --error-color: #d93025;
    --success-color: #1e8e3e;
    --warning-color: #f9ab00;
    
    /* Spacing */
    --spacing-xs: 4px;
    --spacing-sm: 8px;
    --spacing-md: 16px;
    --spacing-lg: 24px;
    --spacing-xl: 32px;
    
    /* Typography */
    --font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    --font-size-xs: 12px;
    --font-size-sm: 14px;
    --font-size-md: 16px;
    --font-size-lg: 18px;
    --font-size-xl: 24px;
    --font-size-xxl: 32px;
    
    /* Border Radius */
    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --radius-xl: 16px;
    --radius-full: 9999px;
    
    /* Shadows */
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1);
    
    /* Transitions */
    --transition-fast: 150ms ease-in-out;
    --transition-normal: 250ms ease-in-out;
    --transition-slow: 350ms ease-in-out;
    
    /* Z-index */
    --z-modal: 1000;
    --z-header: 100;
    --z-sidebar: 50;
}

/* Dark Mode Variables */
body.dark-mode {
    /* Hints the browser to render native form-control chrome (select
       dropdown popups, scrollbars, date pickers, etc.) in dark mode too -
       those are OS/browser-rendered and ignore our own CSS variables
       entirely otherwise, showing up starkly white against an otherwise
       dark page regardless of background-color/color set on the element
       itself. */
    color-scheme: dark;

    /* Color Palette - Dark Mode */
    --primary-color: #8ab4f8;
    --primary-hover: #aecbfa;
    --primary-light: #1a3a52;
    --secondary-color: #9aa0a6;
    --background-color: #1f1f1f;
    --surface-color: #2d2d2d;
    --sidebar-bg: #2d2d2d;
    --border-color: #3c4043;
    --text-primary: #e8eaed;
    --text-secondary: #9aa0a6;
    --text-tertiary: #5f6368;
    --error-color: #f28b82;
    --success-color: #81c995;
    --warning-color: #fdd663;
    
    /* Adjust shadows for dark mode */
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.5);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.6);
}

/* High Contrast Mode Variables */
body.high-contrast {
    /* High Contrast - Light Base */
    --primary-color: #0000ff;
    --primary-hover: #0000cc;
    --primary-light: #e0e0ff;
    --secondary-color: #000000;
    --background-color: #ffffff;
    --surface-color: #ffffff;
    --sidebar-bg: #ffffff;
    --border-color: #000000;
    --text-primary: #000000;
    --text-secondary: #000000;
    --text-tertiary: #333333;
    --error-color: #cc0000;
    --success-color: #008000;
    --warning-color: #cc8800;
    
    /* Enhanced shadows */
    --shadow-sm: 0 2px 4px 0 rgba(0, 0, 0, 0.8);
    --shadow-md: 0 4px 8px -1px rgba(0, 0, 0, 0.8);
    --shadow-lg: 0 10px 20px -3px rgba(0, 0, 0, 0.8);
    --shadow-xl: 0 20px 30px -5px rgba(0, 0, 0, 0.8);
}

/* High Contrast Dark Mode */
body.high-contrast.dark-mode {
    /* High Contrast - Dark Base */
    --primary-color: #ffff00;
    --primary-hover: #ffff66;
    --primary-light: #666600;
    --secondary-color: #ffffff;
    --background-color: #000000;
    --surface-color: #000000;
    --sidebar-bg: #000000;
    --border-color: #ffffff;
    --text-primary: #ffffff;
    --text-secondary: #ffffff;
    --text-tertiary: #cccccc;
    --error-color: #ff6666;
    --success-color: #66ff66;
    --warning-color: #ffcc00;
    
    /* Enhanced shadows for dark high contrast */
    --shadow-sm: 0 2px 4px 0 rgba(255, 255, 255, 0.5);
    --shadow-md: 0 4px 8px -1px rgba(255, 255, 255, 0.5);
    --shadow-lg: 0 10px 20px -3px rgba(255, 255, 255, 0.5);
    --shadow-xl: 0 20px 30px -5px rgba(255, 255, 255, 0.5);
}

/* High Contrast Enhanced Borders and Focus */
body.high-contrast * {
    border-width: 2px !important;
    font-weight: 500;
}

body.high-contrast button,
body.high-contrast input,
body.high-contrast textarea,
body.high-contrast select {
    border: 3px solid var(--border-color) !important;
}

body.high-contrast :focus-visible {
    outline: 4px solid var(--primary-color) !important;
    outline-offset: 4px;
}

body.high-contrast a {
    text-decoration: underline;
    font-weight: 600;
}

body.high-contrast .btn {
    font-weight: 700;
    border: 3px solid var(--border-color) !important;
}

body.high-contrast .chat-message {
    border: 2px solid var(--border-color) !important;
}

body.high-contrast code,
body.high-contrast pre {
    border: 2px solid var(--border-color) !important;
}

body.high-contrast .btn-new-chat {
    color: #ffffff !important;
}

body.high-contrast.dark-mode .btn-new-chat {
    color: #000000 !important;
}

/* Keep slider and high contrast button with standard colors (not high contrast yellow/blue) */
body.high-contrast #highContrastBtn.active {
    background-color: #4285f4 !important;
    color: #ffffff !important;
}

body.high-contrast.dark-mode #highContrastBtn.active {
    background-color: #8ab4f8 !important;
    color: #000000 !important;
}

body.high-contrast .theme-toggle input:checked + .theme-toggle-slider {
    background-color: #4285f4 !important;
}

body.high-contrast.dark-mode .theme-toggle input:checked + .theme-toggle-slider {
    background-color: #8ab4f8 !important;
}

/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: var(--font-family);
    color: var(--text-primary);
    background-color: var(--background-color);
    line-height: 1.6;
    overflow: hidden;
}

/* Utility Classes */
.hidden {
    display: none !important;
}

.visible {
    display: block !important;
}

.text-center {
    text-align: center;
}

.text-muted {
    color: var(--text-secondary);
}

.text-error {
    color: var(--error-color);
}

.text-success {
    color: var(--success-color);
}

/* Button Styles */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--spacing-sm);
    padding: var(--spacing-sm) var(--spacing-md);
    font-size: var(--font-size-sm);
    font-weight: 500;
    font-family: var(--font-family);
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition-fast);
    outline: none;
    user-select: none;
}

.btn:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.btn:active {
    transform: translateY(0);
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.btn-primary {
    background-color: var(--primary-color);
    color: white;
}

.btn-primary:hover:not(:disabled) {
    background-color: var(--primary-hover);
}

.btn-secondary {
    background-color: var(--surface-color);
    color: var(--text-primary);
}

.btn-secondary:hover:not(:disabled) {
    background-color: var(--border-color);
}

.btn-icon {
    padding: var(--spacing-sm);
    background-color: transparent;
    color: var(--text-secondary);
    border-radius: var(--radius-full);
}

.btn-icon:hover:not(:disabled) {
    background-color: var(--surface-color);
    color: var(--text-primary);
    box-shadow: none;
}

/* Container Layout */
.container {
    display: flex;
    height: 100vh;
    width: 100vw;
    overflow: hidden;
}

/* Modal Styles */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: var(--z-modal);
    backdrop-filter: blur(4px);
}

.modal-content {
    background-color: var(--background-color);
    border-radius: var(--radius-xl);
    padding: var(--spacing-xl);
    box-shadow: var(--shadow-xl);
    max-width: 500px;
    width: 90%;
    animation: modalSlideIn var(--transition-normal);
}

@keyframes modalSlideIn {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Scrollbar Styles */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: var(--radius-full);
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-tertiary);
}

/* Loading Spinner */
.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid var(--surface-color);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* Responsive Design */
@media (max-width: 768px) {
    .container {
        flex-direction: column;
    }
    
    .modal-content {
        max-width: 95%;
        padding: var(--spacing-lg);
    }
}

/* Selection */
::selection {
    background-color: var(--primary-light);
    color: var(--text-primary);
}

/* Focus Styles */
:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

/* Smooth Animations */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Dark Mode Toggle Switch */
.theme-toggle-container {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
}

#highContrastBtn {
    transition: all var(--transition-normal);
}

/* #highContrastBtn.active {
    background-color: #4285f4;
    color: white;
} 

body.dark-mode #highContrastBtn.active {
    background-color: #8ab4f8;
    color: #000000;
}
*/
.theme-toggle {
    position: relative;
    display: inline-block;
    width: 48px;
    height: 24px;
}

.theme-toggle input {
    opacity: 0;
    width: 0;
    height: 0;
}

.theme-toggle-slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: var(--border-color);
    transition: var(--transition-normal);
    border-radius: var(--radius-full);
}

.theme-toggle-slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: var(--transition-normal);
    border-radius: 50%;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.theme-toggle input:checked + .theme-toggle-slider {
    background-color: var(--primary-color);
}

.theme-toggle input:checked + .theme-toggle-slider:before {
    transform: translateX(24px);
}

.theme-toggle-slider:hover {
    opacity: 0.9;
}

.theme-icon {
    width: 18px;
    height: 18px;
    color: var(--text-secondary);
    transition: color var(--transition-fast);
}

.theme-toggle-container:hover .theme-icon {
    color: var(--text-primary);
}

/* High Contrast Button States */
body.high-contrast #highContrastBtn svg {
    stroke-width: 3;
}

/* ── Connected Services — header button ─────────────────────────────────── */

.header-left-controls {
    display: flex;
    align-items: center;
    gap: 0;
    flex-shrink: 0;
}

.btn-services-header {
    position: relative;
    flex-shrink: 0;
}

/* ── Knowledge Base — header button ─────────────────────────────────────── */

.btn-kb-header {
    flex-shrink: 0;
}

/* ── Agents — header button ──────────────────────────────────────────────── */

.btn-agents-header {
    flex-shrink: 0;
}

/* ── File Manager — header button ────────────────────────────────────────── */

.btn-filemanager-header {
    flex-shrink: 0;
    text-decoration: none;
}

/* ── File Manager — non-modal floating window ────────────────────────────
   Deliberately NOT built on .services-overlay (which is a modal: backdrop +
   aria-modal + body scroll lock). This floats over the chat interface like
   a real OS file-manager window (Dolphin/Finder) - draggable by its
   titlebar, resizable from its corner handle, and the rest of the page
   stays fully interactive behind/around it. Content is an iframe onto the
   existing standalone file_manager.html page, so the file-manager logic
   itself (file-manager.js) is untouched - this only adds window chrome. */

.fm-floating-window {
    position: fixed;
    top: 8vh;
    left: 50%;
    transform: translateX(-50%);
    width: min(920px, 92vw);
    height: min(640px, 84vh);
    min-width: 420px;
    min-height: 320px;
    display: flex;
    flex-direction: column;
    background: var(--background-color);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-xl);
    overflow: hidden;
    z-index: 500;
}

.fm-floating-titlebar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 8px 8px 14px;
    background: var(--surface-color);
    border-bottom: 1px solid var(--border-color);
    cursor: move;
    user-select: none;
    flex-shrink: 0;
}

.fm-floating-title {
    font-size: var(--font-size-sm);
    font-weight: 600;
    color: var(--text-primary);
}

.fm-floating-close {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    background: transparent;
    border: none;
    border-radius: var(--radius-full);
    color: var(--text-secondary);
    cursor: pointer;
}

.fm-floating-close:hover {
    background: var(--error-color);
    color: #fff;
}

.fm-floating-iframe {
    flex: 1;
    width: 100%;
    border: none;
    background: var(--background-color);
}

.fm-floating-resize-handle {
    position: absolute;
    right: 0;
    bottom: 0;
    width: 18px;
    height: 18px;
    cursor: nwse-resize;
}

.fm-floating-resize-handle::after {
    content: '';
    position: absolute;
    right: 4px;
    bottom: 4px;
    width: 8px;
    height: 8px;
    border-right: 2px solid var(--text-tertiary);
    border-bottom: 2px solid var(--text-tertiary);
    opacity: 0.6;
}

.fm-floating-window.fm-dragging,
.fm-floating-window.fm-resizing {
    user-select: none;
}

.fm-floating-window.fm-dragging .fm-floating-iframe,
.fm-floating-window.fm-resizing .fm-floating-iframe {
    pointer-events: none;
}

@media (max-width: 640px) {
    .fm-floating-window {
        top: 4vh;
        width: 96vw;
        height: 90vh;
    }
}

/* ── Agents Overlay ──────────────────────────────────────────────────────── */

.agents-overlay-panel {
    width: clamp(360px, 60vw, 820px) !important;
}

/* The body must be relative so the input dialog can sit on top of the grid */
#agentsOverlay .services-overlay-body {
    position: relative;
    overflow-y: auto;
    flex: 1;
    padding: 16px 20px;
}

.agents-overlay-hint {
    font-size: var(--font-size-sm);
    color: var(--text-secondary);
    margin: 0 0 14px;
}

.agents-loading,
.agents-empty {
    display: block;
    font-size: 13px;
    color: var(--text-secondary, #8b949e);
    padding: 32px 8px;
    text-align: center;
    line-height: 1.7;
}

/* ── Agent tile grid ─────────────────────────────────────────────────────── */

.agent-tiles-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 12px;
}

/* ── Individual tile ─────────────────────────────────────────────────────── */

.agent-tile {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
    padding: 16px 16px 14px;
    background: var(--surface-color);
    border: 1.5px solid var(--border-color);
    border-radius: var(--radius-lg);
    cursor: pointer;
    text-align: left;
    width: 100%;
    overflow: hidden;

    /* Smooth lift + glow on hover */
    transition:
        transform 0.22s cubic-bezier(0.34, 1.56, 0.64, 1),
        box-shadow 0.22s ease,
        border-color 0.18s ease;
}

.agent-tile:hover {
    transform: translateY(-6px);
    box-shadow: 0 10px 28px rgba(66, 133, 244, 0.22);
    border-color: var(--primary-color);
}

body.dark-mode .agent-tile:hover {
    box-shadow: 0 10px 28px rgba(138, 180, 248, 0.28);
}

.agent-tile:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

/* Avatar circle */
.agent-tile-avatar {
    flex-shrink: 0;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 700;
    color: #fff;
    background: var(--primary-color);
    user-select: none;
    transition: transform 0.22s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.agent-tile:hover .agent-tile-avatar {
    transform: scale(1.12);
}

/* Text body */
.agent-tile-body {
    flex: 1;
    min-width: 0;
}

.agent-tile-name {
    font-size: var(--font-size-sm);
    font-weight: 600;
    color: var(--text-primary);
    line-height: 1.3;
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}

.agent-tile-shortcut {
    font-size: 11px;
    font-weight: 500;
    color: var(--primary-color);
    background: var(--primary-light);
    border-radius: 4px;
    padding: 1px 5px;
    letter-spacing: 0.02em;
}

.agent-tile-desc {
    font-size: 12px;
    color: var(--text-secondary);
    line-height: 1.5;
    margin: 4px 0 0;
    /* clamp to 3 lines */
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* "Run" hint revealed on hover */
.agent-tile-run-hint {
    position: absolute;
    bottom: 10px;
    right: 12px;
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 11px;
    font-weight: 600;
    color: var(--primary-color);
    opacity: 0;
    transform: translateY(4px);
    transition: opacity 0.18s ease, transform 0.18s ease;
    pointer-events: none;
}

.agent-tile:hover .agent-tile-run-hint {
    opacity: 1;
    transform: translateY(0);
}

/* ── Per-tile accent colours (avatar background only) ───────────────────── */

.agent-tile-color-1 .agent-tile-avatar { background: #4285f4; }
.agent-tile-color-2 .agent-tile-avatar { background: #ea4335; }
.agent-tile-color-3 .agent-tile-avatar { background: #34a853; }
.agent-tile-color-4 .agent-tile-avatar { background: #fbbc05; color: #333; }
.agent-tile-color-5 .agent-tile-avatar { background: #8e24aa; }
.agent-tile-color-6 .agent-tile-avatar { background: #0097a7; }
.agent-tile-color-7 .agent-tile-avatar { background: #e65100; }
.agent-tile-color-8 .agent-tile-avatar { background: #558b2f; }

/* Small badge on tiles that need user input */
.agent-tile-input-badge {
    font-size: 11px;
    line-height: 1;
    opacity: 0.65;
    flex-shrink: 0;
}

/* ── Agent input dialog ───────────────────────────────────────────────────── */
/* Slides up over the tile grid inside the overlay body */

.agent-input-dialog {
    position: absolute;
    inset: 0;
    background: var(--surface-color, var(--background-color));
    border-radius: 0 0 var(--radius-lg) var(--radius-lg);
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 20px;
    animation: agentDialogIn 0.18s ease;
    z-index: 10;
}

.agent-input-dialog.hidden {
    display: none;
}

@keyframes agentDialogIn {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0);   }
}

.agent-input-dialog-header {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--primary-color);
}

.agent-input-dialog-name {
    font-size: var(--font-size-md);
    font-weight: 600;
    color: var(--text-primary);
}

.agent-input-dialog-hint {
    font-size: var(--font-size-sm);
    color: var(--text-secondary);
    margin: 0;
    line-height: 1.5;
}

.agent-input-dialog-textarea {
    width: 100%;
    box-sizing: border-box;
    padding: 10px 12px;
    font-size: var(--font-size-sm);
    font-family: var(--font-family);
    color: var(--text-primary);
    background: var(--background-color);
    border: 1.5px solid var(--border-color);
    border-radius: var(--radius-md);
    resize: vertical;
    min-height: 72px;
    transition: border-color 0.15s ease;
}

.agent-input-dialog-textarea:focus {
    outline: none;
    border-color: var(--primary-color);
}

.agent-input-dialog-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

/* ── Agent section headers (shared / my agents) ─────────────────────────── */

.agent-section {
    margin-bottom: 20px;
}

.agent-section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 10px;
    padding-bottom: 6px;
    border-bottom: 1px solid var(--border-subtle, rgba(255,255,255,0.08));
}

.agent-section-title {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted, #888);
}

.agent-create-btn {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 0.75rem;
    padding: 4px 10px;
    border-radius: 6px;
}

.agents-empty-private {
    display: block;
    font-size: 0.82rem;
    color: var(--text-muted, #888);
    padding: 6px 2px;
}

/* ── Private tile wrapper + action buttons (edit / delete icons) ─────────── */

.agent-tile-private {
    position: relative;
    display: block;
}

/* Lift the inner tile button to fill the wrapper */
.agent-tile-private .agent-tile {
    width: 100%;
}

.agent-tile-actions {
    position: absolute;
    top: 6px;
    right: 6px;
    display: flex;
    gap: 2px;
    opacity: 0;
    transition: opacity 0.15s ease;
    z-index: 2;
    pointer-events: none;
}

.agent-tile-private:hover .agent-tile-actions,
.agent-tile-private:focus-within .agent-tile-actions {
    opacity: 1;
    pointer-events: auto;
}

.agent-tile-edit-btn,
.agent-tile-delete-btn {
    width: 26px;
    height: 26px;
    border-radius: 5px;
    background: var(--surface-2, rgba(0,0,0,0.35));
    color: var(--text-muted, #aaa);
    border: 1px solid var(--border-subtle, rgba(255,255,255,0.1));
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}

.agent-tile-edit-btn:hover {
    background: var(--accent, #4f8ef7);
    color: #fff;
    border-color: transparent;
}

.agent-tile-delete-btn:hover {
    background: #c0392b;
    color: #fff;
    border-color: transparent;
}

/* ── Agent builder panel ─────────────────────────────────────────────────── */

.agent-builder-panel {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.agent-builder-panel.hidden {
    display: none;
}

.agent-builder-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 4px;
}

.agent-builder-back-btn {
    color: var(--text-muted, #aaa);
}

.agent-builder-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary, #eee);
}

.agent-builder-field {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.agent-builder-label {
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--text-secondary, #bbb);
}

.agent-builder-hint {
    font-weight: 400;
    color: var(--text-muted, #888);
    font-size: 0.75rem;
}

.agent-builder-input {
    background: var(--input-bg, rgba(255,255,255,0.06));
    border: 1px solid var(--border-subtle, rgba(255,255,255,0.12));
    border-radius: 6px;
    color: var(--text-primary, #eee);
    font-size: 0.85rem;
    padding: 7px 10px;
    outline: none;
    transition: border-color 0.15s;
}

.agent-builder-input:focus {
    border-color: var(--accent, #4f8ef7);
}

.agent-builder-steps-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 4px;
}

.agent-builder-add-step-btn {
    font-size: 0.75rem;
    padding: 4px 10px;
}

.agent-builder-steps-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

/* Old .agent-builder-step-row styles replaced by .ab-step-row — see below */



.agent-builder-step-remove-btn:hover {
    color: #c0392b;
}

/* ── ab-step-row: admin-quality step rows inside the user builder ─────────── */

.ab-step-row {
    background: var(--surface-1, rgba(255,255,255,0.04));
    border: 1px solid var(--border-subtle, rgba(255,255,255,0.1));
    border-radius: 10px;
    padding: 12px 14px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 10px;
}

.ab-step-header {
    display: flex;
    align-items: center;
    gap: 8px;
}

.ab-step-num {
    width: 22px;
    height: 22px;
    flex-shrink: 0;
    background: var(--accent, #4f8ef7);
    color: #fff;
    border-radius: 50%;
    font-size: 0.7rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
}

.ab-step-label {
    flex: 1;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary, #bbb);
}

.ab-step-remove {
    color: var(--text-muted, #888);
    width: 26px;
    height: 26px;
}

.ab-step-remove:hover {
    color: #c0392b;
}

.ab-field {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.ab-label {
    font-size: 0.76rem;
    font-weight: 600;
    color: var(--text-secondary, #bbb);
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 6px;
}

.ab-template-hint {
    font-weight: 400;
    font-size: 0.72rem;
    color: var(--text-muted, #888);
}

.ab-template-hint code {
    font-family: monospace;
    background: rgba(255,255,255,0.07);
    padding: 1px 4px;
    border-radius: 3px;
    font-size: 0.78rem;
    color: var(--accent, #7ab3ff);
}

.ab-service-row {
    display: flex;
    gap: 8px;
}

.ab-step-service {
    flex: 1;
    min-width: 0;
}

.ab-step-service-suffix {
    flex: 1;
    min-width: 0;
}

.ab-step-template {
    resize: vertical;
    min-height: 64px;
    font-family: monospace;
    font-size: 0.82rem;
}

.ab-depends-row {
    flex-direction: row;
    align-items: center;
    gap: 10px;
}

.ab-depends-label {
    white-space: nowrap;
}

.ab-depends-select {
    width: 140px;
    flex-shrink: 0;
}



.agent-builder-error {
    font-size: 0.82rem;
    color: #e74c3c;
    background: rgba(231, 76, 60, 0.1);
    border: 1px solid rgba(231, 76, 60, 0.25);
    border-radius: 6px;
    padding: 8px 12px;
}

.agent-builder-error.hidden {
    display: none;
}

.agent-builder-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 4px;
}



/* Slightly wider than services overlay to give the file tree room */
.kb-overlay-panel {
    width: clamp(420px, 55vw, 780px) !important;
}

/* The rag-body is always visible inside the overlay (overlay controls show/hide) */
.kb-overlay-panel .rag-body {
    display: flex;
    padding: 0;
    gap: 0;
}

/* Give the file tree more vertical space in the overlay */
.kb-overlay-panel .rag-file-tree {
    max-height: calc(75vh - 240px);
}

/* Fit drop zone inside overlay without sidebar margin */
.kb-overlay-panel .rag-drop-zone {
    margin: 8px 0;
}

.kb-overlay-panel .rag-actions {
    padding: 4px 0;
}

.kb-overlay-panel .rag-upload-hint {
    padding: 4px 0;
}

.kb-overlay-panel .rag-toolbar {
    padding: 0;
}

.kb-overlay-panel .rag-breadcrumb {
    padding: 4px 0 2px;
}

.kb-overlay-panel .services-overlay-body {
    padding: var(--spacing-md);
}

.services-header-badge {
    position: absolute;
    top: 2px;
    right: 4px;
    min-width: 16px;
    height: 16px;
    padding: 0 2px;
    border-radius: 8px;
    background: #23c55e;
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    line-height: 16px;
    text-align: center;
    pointer-events: none;
}

.services-header-badge.hidden {
    display: none;
}

/* ── Connected Services overlay ─────────────────────────────────────────── */

.services-overlay {
    position: fixed;
    inset: 0;
    z-index: 1100;
    display: flex;
    align-items: center;
    justify-content: center;
}

.services-overlay.hidden {
    display: none;
}

.services-overlay-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
}

.services-overlay-panel {
    position: relative;
    background: var(--surface-color, var(--background-color));
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: 0 12px 48px rgba(0, 0, 0, 0.28);
    width: clamp(340px, 48vw, 680px);
    max-width: 95vw;
    max-height: 75vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.services-overlay-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px 14px;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
    gap: 12px;
}

.services-overlay-title-row {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.services-overlay-title-row h2 {
    font-size: var(--font-size-lg);
    font-weight: 600;
    margin: 0;
    color: var(--text-primary);
    white-space: nowrap;
}

.services-count-label {
    font-size: 12px;
    color: var(--text-secondary);
    white-space: nowrap;
    background: var(--background-color);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 2px 8px;
}

.services-overlay-header-actions {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
}

.services-overlay-body {
    padding: 16px 20px;
    overflow-y: auto;
    flex: 1;
}

/* ── Service list items ──────────────────────────────────────────────────── */

.services-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.services-loading,
.services-empty {
    display: block;
    font-size: 13px;
    color: var(--text-secondary, #8b949e);
    padding: 24px 8px;
    text-align: center;
    line-height: 1.6;
}

.service-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 10px 12px;
    border-radius: 8px;
    background: var(--background-color, rgba(255,255,255,0.03));
    border: 1px solid transparent;
    transition: border-color .15s, background .15s;
}

.service-item:hover {
    background: var(--primary-light, rgba(66,133,244,0.07));
}

.service-item.service-connected {
    border-color: rgba(35, 197, 94, 0.3);
}

.service-item.service-disconnected {
    border-color: var(--border-color, rgba(255,255,255,0.08));
}

.service-info {
    display: flex;
    flex-direction: column;
    min-width: 0;
    gap: 2px;
}

.service-provider {
    font-size: 12px;
    color: var(--text-secondary, #8b949e);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.service-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary, #e6edf3);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.service-actions {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}

.service-badge.connected {
    font-size: 11px;
    font-weight: 600;
    color: #23c55e;
    background: rgba(35, 197, 94, 0.12);
    padding: 3px 9px;
    border-radius: 10px;
    white-space: nowrap;
}

.btn-service-connect {
    font-size: 12px;
    font-weight: 600;
    padding: 5px 12px;
    border-radius: 6px;
    border: 1px solid var(--accent, #2f81f7);
    background: transparent;
    color: var(--accent, #2f81f7);
    cursor: pointer;
    transition: background .15s, color .15s;
    white-space: nowrap;
}

.btn-service-connect:hover {
    background: var(--accent, #2f81f7);
    color: #fff;
}

.btn-service-disconnect {
    font-size: 13px;
    line-height: 1;
    padding: 4px 10px;
    border-radius: 6px;
    border: 1px solid rgba(239,68,68,0.35);
    background: transparent;
    color: #ef4444;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 4px;
    transition: background .15s, color .15s;
    white-space: nowrap;
    font-weight: 500;
}

.btn-service-disconnect:hover {
    background: rgba(239,68,68,0.15);
    border-color: rgba(239,68,68,0.6);
}
