/* ============================================
   Base CSS - Professional LLM Chat Application
   Light & Dark Theme Support
   ============================================ */

/* ---------- CSS Variables - Light Theme ---------- */
:root[data-theme="light"] {
    /* Colors */
    /* Copper accent, darkened from the dark theme's #c9885a so it clears 4.5:1
       against white as both button fill and link text. */
    --color-primary: #a05f30;
    --color-primary-hover: #8a5325;
    --color-primary-light: rgba(160, 95, 48, 0.12);
    /* Text/icon color for anything filled with --color-primary */
    --color-on-primary: #ffffff;

    --color-background: #ffffff;
    --color-background-alt: #f9fafb;
    --color-surface: #ffffff;
    --color-surface-hover: #f3f4f6;
    
    --color-text-primary: #111827;
    --color-text-secondary: #6b7280;
    --color-text-tertiary: #9ca3af;
    
    --color-border: #e5e7eb;
    --color-border-hover: #d1d5db;
    
    --color-success: #10b981;
    --color-warning: #f59e0b;
    --color-error: #ef4444;
    
    /* 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), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
}

/* ---------- CSS Variables - Dark Theme ---------- */
:root[data-theme="dark"] {
    /* Colors */
    --color-primary: #c9885a;
    --color-primary-hover: #b8774a;
    --color-primary-light: rgba(201, 136, 90, 0.15);
    /* Copper is light enough here that white text on it only reaches 2.9:1 — ink reads instead */
    --color-on-primary: #121212;

    --color-background: #121212;
    --color-background-alt: #1a1a1a;
    --color-surface: #1e1e1e;
    --color-surface-hover: #2a2a2a;

    --color-text-primary: #ffffff;
    --color-text-secondary: #b3b3b3;
    --color-text-tertiary: #808080;

    --color-border: #2e2e2e;
    --color-border-hover: #404040;
    
    --color-success: #22c55e;
    --color-warning: #fbbf24;
    --color-error: #f87171;
    
    /* Shadows */
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.4), 0 2px 4px -1px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.4), 0 4px 6px -2px rgba(0, 0, 0, 0.3);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.5), 0 10px 10px -5px rgba(0, 0, 0, 0.4);
}

/* ---------- Global 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: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Inter', 'Roboto', 'Helvetica Neue',
        Arial, sans-serif;
    font-weight: 400;
    line-height: 1.6;
    color: var(--color-text-primary);
    background-color: var(--color-background);
    transition: background-color 0.3s ease, color 0.3s ease;
    height: 100vh;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* ---------- Typography ---------- */
h1, h2, h3, h4, h5, h6 {
    font-weight: 600;
    line-height: 1.2;
    color: var(--color-text-primary);
}

h1 { font-size: 2.25rem; }
h2 { font-size: 1.875rem; }
h3 { font-size: 1.5rem; }
h4 { font-size: 1.25rem; }
h5 { font-size: 1.125rem; }
h6 { font-size: 1rem; }

p {
    margin-bottom: 1rem;
    color: var(--color-text-secondary);
}

a {
    color: var(--color-primary);
    text-decoration: none;
    transition: color 0.2s ease;
}

a:hover {
    color: var(--color-primary-hover);
}

/* ---------- Layout Components ---------- */
.container {
    width: 100%;
    max-width: 1280px;
    margin: 0 auto;
    padding: 0 1.5rem;
}

.container-sm {
    max-width: 640px;
}

.container-lg {
    max-width: 1536px;
}

/* ---------- Header ---------- */
.header {
    background-color: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    flex-shrink: 0;
    z-index: 100;
    backdrop-filter: blur(10px);
    background-color: rgba(255, 255, 255, 0.95);
}

[data-theme="dark"] .header {
    background-color: rgba(18, 18, 18, 0.95);
}

.header-content {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 48px;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* Collapsed-nav toggle — only shown on narrow screens.
   Scoped under .header-actions so it outranks the generic .icon-btn
   { display: flex } rule that appears later in this file. */
.header-actions .nav-toggle {
    display: none;
}

.logo {
    display: flex;
    align-items: center;
    font-size: 1.25rem;
    font-weight: 300;
    color: var(--color-text-primary);
}

.logo a {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    color: inherit;
    transition: opacity 0.2s ease;
}

.logo a:hover {
    opacity: 0.8;
}

.logo-text {
    font-family: 'Helvetica', sans-serif;
    font-weight: 500;
    font-size: 1.5rem;
    background: linear-gradient(135deg, var(--color-primary) 0%, var(--color-primary-hover) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

/* ---------- Navigation ---------- */
.nav {
    display: flex;
    align-items: center;
    gap: 2rem;
}

.nav-link {
    color: var(--color-text-secondary);
    font-weight: 300;
    padding: 0.5rem 1rem;
    border-radius: 0.5rem;
    transition: all 0.2s ease;
}

.nav-link:hover {
    color: var(--color-text-primary);
    background-color: var(--color-surface-hover);
}

.nav-link.active {
    color: var(--color-primary);
    background-color: var(--color-primary-light);
}

/* ---------- Header Actions ---------- */
.header-actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.625rem 1.25rem;
    font-size: 0.875rem;
    font-weight: 300;
    border-radius: 0.5rem;
    border: none;
    cursor: pointer;
    transition: all 0.2s ease;
    text-decoration: none;
    outline: none;
}

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

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

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

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

.icon-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: 0.5rem;
    border: none;
    background-color: transparent;
    color: var(--color-text-secondary);
    cursor: pointer;
    transition: all 0.2s ease;
}

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

/* ---------- Profile Dropdown ---------- */
.profile-dropdown-wrapper {
    position: relative;
}

.profile-avatar-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: none;
    background-color: var(--color-primary-light);
    color: var(--color-primary);
    cursor: pointer;
    transition: all 0.2s ease;
}

.profile-avatar-btn:hover {
    background-color: var(--color-primary);
    color: var(--color-on-primary);
}

.header-profile-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
}

.profile-dropdown {
    display: none;
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    min-width: 220px;
    background-color: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 0.5rem;
    box-shadow: var(--shadow-lg);
    z-index: 200;
    overflow: hidden;
}

.profile-dropdown.open {
    display: block;
    animation: fadeIn 0.15s ease;
}

.profile-dropdown-header {
    padding: 0.75rem 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.125rem;
}

.profile-dropdown-name {
    font-size: 0.875rem;
    font-weight: 300;
    color: var(--color-text-primary);
}

.profile-dropdown-email {
    font-size: 0.75rem;
    color: var(--color-text-tertiary);
}

.profile-dropdown-divider {
    height: 1px;
    background-color: var(--color-border);
}

.profile-dropdown-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    width: 100%;
    padding: 0.625rem 1rem;
    font-size: 0.875rem;
    color: var(--color-text-secondary);
    background: none;
    border: none;
    cursor: pointer;
    text-decoration: none;
    transition: background-color 0.15s ease;
}

.profile-dropdown-item:hover {
    background-color: var(--color-surface-hover);
    color: var(--color-text-primary);
}

.profile-dropdown-logout:hover {
    color: var(--color-error);
}

/* ---------- Main Content ---------- */
.main {
    flex: 1;
    width: 100%;
    min-height: 0;
    overflow-y: auto;
}

/* ---------- Footer ---------- */
.footer {
    background-color: var(--color-surface);
    border-top: 1px solid var(--color-border);
    padding: 1.5rem 0;
    margin-top: auto;
}

.footer-text {
    text-align: center;
    color: var(--color-text-tertiary);
    font-size: 0.875rem;
}

/* ---------- Utility Classes ---------- */
.text-center {
    text-align: center;
}

.text-primary {
    color: var(--color-primary) !important;
}

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

.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.mt-4 { margin-top: 2rem; }

.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.mb-3 { margin-bottom: 1.5rem; }
.mb-4 { margin-bottom: 2rem; }

.p-1 { padding: 0.5rem; }
.p-2 { padding: 1rem; }
.p-3 { padding: 1.5rem; }
.p-4 { padding: 2rem; }

/* ---------- Animations ---------- */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.fade-in {
    animation: fadeIn 0.3s ease;
}

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

::-webkit-scrollbar-track {
    background: var(--color-background-alt);
}

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

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

/* ---------- Responsive Design ---------- */
@media (max-width: 768px) {
    .container {
        padding: 0 1rem;
    }

    .header-content {
        height: 44px;
    }

    .header-actions .nav-toggle {
        display: flex;
    }

    .nav {
        position: absolute;
        top: calc(100% + 0.5rem);
        right: 0;
        flex-direction: column;
        align-items: stretch;
        gap: 0.125rem;
        min-width: 200px;
        padding: 0.5rem;
        background-color: var(--color-surface);
        border: 1px solid var(--color-border);
        border-radius: 0.75rem;
        box-shadow: var(--shadow-lg);
        z-index: 200;
        opacity: 0;
        visibility: hidden;
        transform: translateY(-0.25rem);
        transition: opacity 0.15s ease, transform 0.15s ease, visibility 0.15s;
    }

    .nav.open {
        opacity: 1;
        visibility: visible;
        transform: translateY(0);
    }

    .nav-link {
        padding: 0.625rem 0.75rem;
        font-size: 0.9375rem;
    }

    h1 { font-size: 1.875rem; }
    h2 { font-size: 1.5rem; }
    h3 { font-size: 1.25rem; }
}

@media (max-width: 480px) {
    .logo-text {
        display: none;
    }

    .nav {
        gap: 0.5rem;
    }
}

/* ---------- User Data Font Override ---------- */
/* Chat messages, mail content, and user-generated text use standard system font */
.chat-sidebar,
.chat-history,
.chat-messages,
.message-content,
.message-bubble,
.mail-body-html,
.mail-detail-body,
.mail-preview-text,
.compose-body,
.cognis-messages,
textarea,
input[type="text"],
input[type="email"],
input[type="password"],
input[type="search"] {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
        'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif;
    font-weight: normal;
}

/* ---------- Resizable Side Panels ---------- */
.panel-resize-handle {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 6px;
    cursor: col-resize;
    background: transparent;
    z-index: 50;
    user-select: none;
    touch-action: none;
    transition: background-color 0.15s ease;
}

.panel-resize-handle--right {
    right: -3px;
}

.panel-resize-handle--left {
    left: -3px;
}

.panel-resize-handle:hover,
.panel-resize-handle:active,
body.is-resizing-panel .panel-resize-handle {
    background-color: var(--color-primary, #6366f1);
    opacity: 0.4;
}

body.is-resizing-panel {
    cursor: col-resize !important;
    user-select: none !important;
}

body.is-resizing-panel * {
    cursor: col-resize !important;
    user-select: none !important;
}

/* ---------- User search picker (share / grant-access inputs) ---------- */

.user-search-wrap {
    position: relative;
    flex: 1;
}

.user-search-dropdown {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    z-index: 50;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 6px;
    box-shadow: var(--shadow-md);
    max-height: 240px;
    overflow-y: auto;
}

.user-search-option {
    display: flex;
    align-items: baseline;
    gap: 8px;
    padding: 8px 12px;
    cursor: pointer;
}

.user-search-option.active,
.user-search-option:hover {
    background: var(--color-surface-hover);
}

.user-search-option-name {
    color: var(--color-text-primary);
    font-size: 0.9em;
}

.user-search-option-email {
    color: var(--color-text-secondary);
    font-size: 0.8em;
}

/* ── Shared folder-picker modal (ts/utils/folderPicker.ts) ─────────────────
   Breadcrumb-navigable bank/folder browser, used by the editor's "publish
   to knowledge" picker and the Knowledge module's "move to" picker. */

.folder-picker-backdrop {
    position: fixed;
    inset: 0;
    z-index: 1300;
    background: rgba(0, 0, 0, 0.35);
    display: flex;
    align-items: center;
    justify-content: center;
}

.folder-picker-modal {
    display: flex;
    flex-direction: column;
    gap: 6px;
    width: min(420px, calc(100vw - 32px));
    padding: 18px;
    background: var(--color-surface);
    border-radius: 10px;
    box-shadow: 0 16px 48px rgba(0, 0, 0, 0.2);
}
.folder-picker-modal h3 {
    margin: 0 0 8px;
    font-size: 15px;
    font-weight: 600;
    color: var(--color-text-primary);
}
.folder-picker-bank {
    padding: 7px 8px;
    border: 1px solid var(--color-border);
    border-radius: 6px;
    background: var(--color-background);
    color: var(--color-text-primary);
    font-size: 13px;
    margin-bottom: 4px;
}

.folder-picker-crumbs {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 2px;
    padding: 4px 2px;
    font-size: 12px;
}
.folder-picker-crumb {
    border: none;
    background: transparent;
    color: var(--color-text-secondary);
    cursor: pointer;
    padding: 2px 3px;
    border-radius: 4px;
    white-space: nowrap;
    max-width: 140px;
    overflow: hidden;
    text-overflow: ellipsis;
}
.folder-picker-crumb:hover { background: var(--color-surface-hover); }
.folder-picker-crumb.is-current { color: var(--color-primary); font-weight: 600; cursor: default; }
.folder-picker-crumb.is-current:hover { background: transparent; }
.folder-picker-crumb-sep { color: var(--color-text-tertiary); }

.folder-picker-browser {
    display: flex;
    flex-direction: column;
    gap: 2px;
    height: 220px;
    overflow-y: auto;
    padding: 4px;
    border: 1px solid var(--color-border);
    border-radius: 8px;
    background: var(--color-background);
}
.folder-picker-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 7px 8px;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: var(--color-text-primary);
    font-size: 13px;
    text-align: left;
    cursor: pointer;
}
.folder-picker-row:hover { background: var(--color-surface-hover); }
.folder-picker-row svg { flex-shrink: 0; color: var(--color-text-tertiary); }
.folder-picker-empty {
    margin: auto;
    font-size: 12px;
    color: var(--color-text-tertiary);
}

.folder-picker-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 12px;
}
.folder-picker-actions button {
    padding: 7px 14px;
    border-radius: 6px;
    border: 1px solid var(--color-border);
    background: var(--color-background);
    color: var(--color-text-primary);
    font-size: 13px;
    cursor: pointer;
}
.folder-picker-confirm {
    border-color: var(--color-primary) !important;
    background: var(--color-primary) !important;
    color: var(--color-on-primary, #fff) !important;
}
.folder-picker-confirm:disabled {
    opacity: 0.5;
    cursor: default;
}

