/* ==========================================================================
   MakeShift AI — main app shell (index.html)
   Themed conversations rail (--rail-* tokens: light in light mode, ink in
   dark mode) + content surface driven by the shared theme tokens.
   Depends on theme.css. The JS contract (index.js) relies on:
     body.no-chat-selected / body.sidebar-collapsed
     .modal.active, .tab-button.active, .tab-content.active, .collapsed,
     .collapse-icon.expanded, .conversation-item.active, .chat-iframe,
     .custom-select-* (model picker, currently unused), .status-badge, etc.
   ========================================================================== */

body {
    height: 100vh;
    height: 100dvh; /* track the visible area on mobile (address bar / keyboard) */
    overflow: hidden;
}

.admin-container {
    display: flex;
    height: 100vh;
    height: 100dvh;
    width: 100%;
    overflow: hidden;
    background: var(--bg-secondary);
}

/* Off-canvas scrim behind the mobile conversations drawer. Hidden by default
   (desktop never shows it); the mobile media query reveals it when the drawer
   is open. Tapping it calls toggleSidebar() — see index.html / index.js. */
.sidebar-scrim {
    display: none;
}

/* ==========================================================================
   Conversations rail (dark)
   ========================================================================== */

.conversations-sidebar {
    position: relative;
    width: 320px;
    min-width: 320px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: width 0.32s var(--ease-out), min-width 0.32s var(--ease-out);
    border-right: 1px solid var(--rail-border);
    background:
        radial-gradient(900px 500px at 85% -10%, var(--rail-glow-1), transparent 60%),
        radial-gradient(700px 600px at -15% 110%, var(--rail-glow-2), transparent 55%),
        var(--rail-bg);
}

.conversations-sidebar::before {
    content: '';
    position: absolute;
    inset: 0;
    background-image: radial-gradient(var(--rail-dots) 1px, transparent 1px);
    background-size: 22px 22px;
    mask-image: linear-gradient(180deg, rgba(0, 0, 0, 0.7), rgba(0, 0, 0, 0.25));
    -webkit-mask-image: linear-gradient(180deg, rgba(0, 0, 0, 0.7), rgba(0, 0, 0, 0.25));
    pointer-events: none;
}

/* Keep children from reflowing while the rail animates closed */
.conversations-sidebar > * {
    min-width: 280px;
}

body.sidebar-collapsed .conversations-sidebar {
    width: 0;
    min-width: 0;
    border-right: none;
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    min-height: 68px;
    padding: 14px 18px;
    flex-shrink: 0;
    position: relative;
    z-index: 1;
}

.sidebar-header h2 {
    font-family: var(--font-display);
    font-size: 1.02rem;
    font-weight: 700;
    letter-spacing: -0.01em;
    color: var(--rail-text);
    display: inline-flex;
    align-items: center;
    gap: 10px;
    transition: font-size 0.25s var(--ease-out);
}

.new-chat-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 9px 16px;
    background: var(--grad-signal);
    color: #fff;
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    font-family: var(--font-body);
    font-size: 0.85rem;
    font-weight: 600;
    letter-spacing: 0.005em;
    transition: transform 0.15s var(--ease-out), box-shadow 0.2s, filter 0.2s;
    box-shadow: 0 2px 10px -2px rgba(69, 193, 230, 0.5);
    white-space: nowrap;
}

.new-chat-btn:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-glow);
    filter: brightness(1.07);
}

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

/* Closes the full-screen rail drawer on narrow screens. Hidden on desktop and
   on the home screen; the chat-open mobile breakpoint reveals it. */
.sidebar-close-btn {
    display: none;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 38px;
    height: 38px;
    padding: 0;
    background: var(--rail-card-bg);
    border: 1px solid var(--rail-border);
    border-radius: var(--radius-md);
    color: var(--rail-text-dim);
    cursor: pointer;
    transition: color 0.15s, border-color 0.15s, background 0.15s;
}

.sidebar-close-btn:hover {
    color: var(--rail-text);
    border-color: var(--rail-text-dim);
}

.new-chat-btn span:first-child {
    font-size: 1.05rem;
    line-height: 1;
}

/* Search */
.conversation-search {
    padding: 2px 14px 10px;
    position: relative;
    z-index: 1;
}

.conversation-search-input {
    width: 100%;
    padding: 10px 14px;
    font-family: var(--font-body);
    font-size: 0.83rem;
    color: var(--rail-text);
    background: var(--rail-input-bg);
    border: 1px solid var(--rail-border);
    border-radius: var(--radius-md);
    outline: none;
    transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
}

.conversation-search-input::placeholder {
    color: var(--rail-text-faint);
}

.conversation-search-input:focus {
    border-color: rgba(69, 193, 230, 0.55);
    background: var(--rail-input-focus-bg);
    box-shadow: 0 0 0 3px rgba(69, 193, 230, 0.12);
}

html[data-theme="dark"] .conversation-search-input::-webkit-search-cancel-button {
    filter: invert(0.7);
}

/* List */
.conversations-list {
    flex: 1;
    overflow-y: auto;
    padding: 4px 10px 16px;
    position: relative;
    z-index: 1;
    transition: padding 0.3s var(--ease-out);
}

.conversation-item {
    position: relative;
    padding: 12px 14px;
    margin-bottom: 4px;
    border-radius: var(--radius-md);
    border: 1px solid transparent;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
}

.conversation-item:hover {
    background: var(--rail-hover);
}

.conversation-item.active {
    background: linear-gradient(135deg, rgba(69, 193, 230, 0.14), rgba(37, 99, 235, 0.12));
    border-color: rgba(69, 193, 230, 0.32);
}

.conversation-item.active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 12px;
    bottom: 12px;
    width: 3px;
    border-radius: 99px;
    background: var(--grad-signal);
    box-shadow: 0 0 8px rgba(69, 193, 230, 0.7);
}

.conversation-title {
    font-size: 0.87rem;
    font-weight: 600;
    letter-spacing: -0.005em;
    color: var(--rail-text);
    margin-bottom: 3px;
    padding-right: 54px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.conversation-preview {
    font-size: 0.78rem;
    color: var(--rail-text-dim);
    line-height: 1.45;
    margin-bottom: 7px;
    display: -webkit-box;
    -webkit-line-clamp: 4;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.conversation-meta {
    display: flex;
    justify-content: space-between;
    font-size: 0.7rem;
    font-weight: 500;
    color: var(--rail-text-faint);
}

.delete-btn {
    position: absolute;
    top: 9px;
    right: 9px;
    padding: 3px 9px;
    font-family: var(--font-body);
    font-size: 0.68rem;
    font-weight: 600;
    color: var(--danger-text);
    background: var(--danger-bg);
    border: 1px solid var(--danger-border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.15s, background 0.15s, color 0.15s;
}

.conversation-item:hover .delete-btn {
    opacity: 1;
}

/* Touch devices have no hover — keep the delete affordance visible so it's
   reachable without a hover state that never fires. */
@media (hover: none) {
    .delete-btn {
        opacity: 1;
    }
}

.delete-btn:hover {
    background: var(--danger);
    border-color: var(--danger);
    color: #fff;
}

.conversations-loading-more {
    text-align: center;
    padding: 12px;
    font-size: 0.78rem;
    color: var(--rail-text-faint);
}

/* Rail-context overrides for shared pieces rendered inside the sidebar */
.conversations-sidebar .empty-state {
    color: var(--rail-text-dim);
}

.conversations-sidebar .loading-spinner {
    color: var(--rail-text-faint);
}

.conversations-sidebar .loading-spinner::before {
    border-color: var(--rail-border);
    border-top-color: var(--signal);
}

/* ==========================================================================
   Home state — no conversation selected: the rail becomes the stage
   ========================================================================== */

body.no-chat-selected .conversations-sidebar {
    width: 75vw;
    min-width: 75vw;
}

body.no-chat-selected .sidebar-header {
    justify-content: center;
    align-items: center;
    flex-wrap: wrap;
    gap: 18px 32px;
    padding: 44px 40px 10px;
    min-height: 0;
}

body.no-chat-selected .sidebar-header h2 {
    font-size: 1.7rem;
}

body.no-chat-selected .new-chat-btn {
    padding: 14px 64px;
    font-size: 1rem;
    border-radius: var(--radius-lg);
}

body.no-chat-selected .conversation-search {
    padding: 14px 40px 18px;
    display: flex;
    justify-content: center;
}

body.no-chat-selected .conversation-search-input {
    max-width: 560px;
    padding: 12px 18px;
    font-size: 0.9rem;
    border-radius: var(--radius-lg);
}

/* Fewer, larger cards: ~2 columns centered, with twice the preview text */
body.no-chat-selected .conversations-list {
    padding: 8px max(40px, calc((100% - 1150px) / 2)) 32px;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(470px, 100%), 1fr));
    gap: 16px;
    align-content: start;
}

body.no-chat-selected .conversation-item {
    margin-bottom: 0;
    padding: 22px 24px;
    border-radius: var(--radius-lg);
    border-color: var(--rail-border);
    background: var(--rail-card-bg);
    box-shadow: var(--shadow-sm);
}

body.no-chat-selected .conversation-item:hover {
    border-color: rgba(69, 193, 230, 0.45);
    box-shadow: var(--shadow-md);
}

body.no-chat-selected .conversation-title {
    font-size: 1.08rem;
    margin-bottom: 8px;
}

body.no-chat-selected .conversation-preview {
    font-size: 0.9rem;
    line-height: 1.55;
    -webkit-line-clamp: 4;
}

body.no-chat-selected .conversation-meta {
    font-size: 0.78rem;
    margin-top: 12px;
}

body.no-chat-selected .conversations-list .empty-state,
body.no-chat-selected .conversations-list .loading-spinner,
body.no-chat-selected .conversations-loading-more,
body.no-chat-selected .conversations-list .error-message {
    grid-column: 1 / -1;
}

/* Header buttons that make no sense on the home screen */
body.no-chat-selected #settings-btn,
body.no-chat-selected .btn-sidebar-toggle,
body.no-chat-selected .btn-new-chat-inline {
    display: none;
}

/* ==========================================================================
   Chat column (light)
   ========================================================================== */

.chat-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    position: relative;
    background: var(--bg-primary);
    min-width: 0;
    overflow: hidden;
}

.chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 10px 14px;
    min-height: 68px;
    padding: 12px 20px;
    flex-shrink: 0;
    background: var(--bg-primary);
    border-bottom: 1px solid var(--border-light);
}

.chat-header-left {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

#chat-title {
    font-family: var(--font-display);
    font-size: 1.08rem;
    font-weight: 700;
    letter-spacing: -0.015em;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.header-controls {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

/* Icon chips on the left of the title */
.btn-sidebar-toggle,
.btn-new-chat-inline {
    width: 34px;
    height: 34px;
    border-radius: var(--radius-md);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all 0.15s;
}

.btn-sidebar-toggle {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    color: var(--text-secondary);
}

.btn-sidebar-toggle:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.btn-new-chat-inline {
    display: none;
    background: var(--grad-signal);
    border: none;
    color: #fff;
    box-shadow: 0 2px 8px -2px rgba(69, 193, 230, 0.55);
}

body.sidebar-collapsed .btn-new-chat-inline {
    display: inline-flex;
}

.btn-new-chat-inline:hover {
    filter: brightness(1.08);
    box-shadow: var(--shadow-glow);
}

/* Header action chips.
   NOTE: index.js force-sets style.display to 'inline-block' on .admin-only
   buttons, so these are deliberately laid out without flex. */
.btn-settings,
.btn-sources {
    display: inline-block;
    padding: 8px 13px;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    cursor: pointer;
    font-family: var(--font-body);
    font-size: 0.81rem;
    font-weight: 600;
    color: var(--text-secondary);
    white-space: nowrap;
    line-height: 1;
    transition: all 0.15s;
}

.btn-settings:hover,
.btn-sources:hover {
    border-color: rgba(69, 193, 230, 0.6);
    color: var(--accent);
    background: var(--accent-lighter);
    box-shadow: var(--shadow-sm);
}

/* Emoji icons inside the header chips */
.btn-ic {
    margin-right: 7px;
    font-size: 0.92rem;
    vertical-align: -1px;
}

#theme-toggle-btn {
    padding: 8px 10px;
}

#theme-toggle-btn .btn-ic {
    margin-right: 0;
}

.user-info {
    display: inline-block;
    padding: 8px 13px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-md);
    font-size: 0.81rem;
    font-weight: 500;
    color: var(--text-secondary);
    white-space: nowrap;
    line-height: 1;
    cursor: pointer;
    transition: all 0.15s;
}

.user-info:hover {
    border-color: rgba(69, 193, 230, 0.6);
    box-shadow: var(--shadow-sm);
}

.user-role {
    margin-left: 8px;
    padding: 2px 8px;
    background: var(--accent-light);
    color: var(--accent);
    border-radius: 99px;
    font-size: 0.66rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    vertical-align: 1px;
}

.logout-btn {
    display: inline-block;
    padding: 8px 13px;
    background: var(--bg-primary);
    color: var(--text-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    cursor: pointer;
    font-family: var(--font-body);
    font-size: 0.81rem;
    font-weight: 600;
    white-space: nowrap;
    line-height: 1;
    transition: all 0.15s;
}

.logout-btn:hover {
    color: var(--danger);
    border-color: rgba(224, 45, 60, 0.45);
    background: var(--danger-bg);
}

/* ==========================================================================
   Chat stage
   ========================================================================== */

.chat-iframe-container {
    flex: 1;
    position: relative;
    overflow: hidden;
    background:
        radial-gradient(850px 480px at 88% -8%, var(--page-glow-1), transparent 60%),
        radial-gradient(700px 540px at -12% 108%, var(--page-glow-2), transparent 55%),
        radial-gradient(600px 420px at 105% 110%, var(--page-glow-3), transparent 60%),
        var(--page-base);
}

.chat-iframe {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    border: none;
    background: var(--bg-primary);
    opacity: 0;
    transition: opacity 0.18s ease;
}

.no-selection {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 14px;
    color: var(--text-tertiary);
    font-size: 0.95rem;
    text-align: center;
    padding: 24px;
}

.no-selection::before {
    content: '';
    width: 58px;
    height: 58px;
    border-radius: 18px;
    background:
        var(--grad-signal);
    opacity: 0.18;
    mask: none;
}

.chat-iframe-container .loading-spinner {
    position: absolute;
    inset: 0;
    background: var(--bg-secondary);
}

.chat-iframe-container .error-message {
    border-radius: var(--radius-md);
}

/* ==========================================================================
   Settings & source modals
   ========================================================================== */

.settings-section {
    background: var(--bg-secondary);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-lg);
    padding: 18px;
    margin-bottom: 14px;
}

.settings-section:last-of-type {
    margin-bottom: 18px;
}

.settings-section .form-group:last-child {
    margin-bottom: 0;
}

.section-title {
    font-family: var(--font-display);
    font-size: 0.78rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.09em;
    color: var(--text-secondary);
    margin-bottom: 14px;
}

.section-title.collapsible {
    cursor: pointer;
    user-select: none;
    margin-bottom: 0;
    transition: color 0.15s;
}

.section-title.collapsible:hover {
    color: var(--accent);
}

#advanced-settings {
    margin-top: 14px;
}

#advanced-settings.collapsed,
.collapsed {
    display: none;
}

.collapse-icon {
    display: inline-block;
    font-size: 0.62rem;
    margin-right: 6px;
    transition: transform 0.2s var(--ease-out);
}

.collapse-icon.expanded {
    transform: rotate(90deg);
}

/* Sliders */
.slider-container {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-top: 4px;
}

.slider-label-left,
.slider-label-right {
    font-size: 0.74rem;
    font-weight: 600;
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    flex-shrink: 0;
}

.slider {
    flex: 1;
    -webkit-appearance: none;
    appearance: none;
    height: 6px;
    background: linear-gradient(90deg, rgba(69, 193, 230, 0.45), rgba(37, 99, 235, 0.45));
    border-radius: 99px;
    outline: none;
    cursor: pointer;
}

.slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #fff;
    border: 2.5px solid var(--accent);
    box-shadow: 0 1px 6px rgba(16, 24, 40, 0.25);
    cursor: grab;
    transition: transform 0.12s, box-shadow 0.15s;
}

.slider::-webkit-slider-thumb:hover {
    transform: scale(1.12);
    box-shadow: 0 0 0 5px rgba(69, 193, 230, 0.18);
}

.slider::-moz-range-thumb {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #fff;
    border: 2.5px solid var(--accent);
    box-shadow: 0 1px 6px rgba(16, 24, 40, 0.25);
    cursor: grab;
}

.slider-value-display {
    text-align: center;
    margin-top: 9px;
}

.slider-value-display span {
    display: inline-block;
    padding: 3px 12px;
    background: var(--accent-light);
    color: var(--accent);
    border-radius: 99px;
    font-size: 0.76rem;
    font-weight: 700;
}

/* Label utilities (override theme's block labels) */
.form-group label.label-centered {
    text-align: center;
}

.form-group label.radio-option {
    display: inline-flex;
    margin-bottom: 0;
    font-weight: 500;
}

.form-group label.checkbox-row {
    display: flex;
    margin-bottom: 0;
    font-weight: 500;
}

/* Radio rows (model tier) */
.radio-row {
    display: flex;
    gap: 18px;
    flex-wrap: wrap;
}

.radio-row.centered {
    justify-content: center;
}

.radio-option {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-primary);
}

.radio-option input[type="radio"] {
    accent-color: var(--accent);
    width: 15px;
    height: 15px;
    cursor: pointer;
}

.radio-option .option-note {
    color: var(--text-tertiary);
    font-size: 0.78rem;
    font-weight: 400;
}

/* Inline number field (max tool calls) */
.inline-field {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.inline-field label {
    margin-bottom: 0;
}

.inline-field input[type="number"] {
    width: 76px;
    padding: 7px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: var(--font-mono);
    font-size: 0.85rem;
    text-align: center;
}

.inline-field input[type="number"]:focus {
    outline: none;
    border-color: var(--signal);
    box-shadow: 0 0 0 3px rgba(69, 193, 230, 0.18);
}

/* Checkbox rows */
label.checkbox-row,
.checkbox-row {
    display: flex;
    align-items: center;
    gap: 9px;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 500;
}

.checkbox-row input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: var(--accent);
    cursor: pointer;
    flex-shrink: 0;
}

.pill-recommended {
    background: var(--success);
    color: #fff;
    padding: 2px 9px;
    border-radius: 99px;
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.03em;
}

/* Knowledge sources list (read-only summary) */
.checkbox-list {
    font-size: 0.875rem;
    color: var(--text-primary);
    line-height: 1.55;
}

.source-group {
    margin-bottom: 16px;
}

.source-group:last-child {
    margin-bottom: 0;
}

/* Save button */
.btn-save {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 11px 22px;
    background: var(--grad-signal);
    color: #fff;
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    font-family: var(--font-body);
    font-size: 0.9rem;
    font-weight: 600;
    transition: transform 0.15s var(--ease-out), box-shadow 0.2s, filter 0.2s;
    box-shadow: var(--shadow-sm);
}

.btn-save:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-glow);
    filter: brightness(1.05);
}

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

#save-settings {
    width: 100%;
}

.modal-footer {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    margin-top: 20px;
}

.modal-subtitle {
    color: var(--text-secondary);
    font-size: 0.875rem;
    margin: -8px 0 20px;
    line-height: 1.5;
}

/* Tabs (source config) */
.modal-tabs {
    display: inline-flex;
    gap: 4px;
    background: var(--bg-tertiary);
    border-radius: var(--radius-md);
    padding: 4px;
    margin-bottom: 18px;
}

.tab-button {
    padding: 7px 16px;
    background: transparent;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-family: var(--font-body);
    font-size: 0.83rem;
    font-weight: 600;
    color: var(--text-secondary);
    transition: all 0.15s;
}

.tab-button:hover {
    color: var(--text-primary);
}

.tab-button.active {
    background: var(--bg-primary);
    color: var(--accent);
    box-shadow: var(--shadow-sm);
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
    animation: tab-in 0.2s ease-out;
}

@keyframes tab-in {
    from { opacity: 0; transform: translateY(4px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Indexing progress */
.progress-container {
    margin-top: 18px;
}

.progress-bar {
    height: 8px;
    background: var(--bg-tertiary);
    border-radius: 99px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    width: 0%;
    background: var(--grad-signal);
    border-radius: 99px;
    box-shadow: 0 0 10px rgba(69, 193, 230, 0.6);
    transition: width 0.4s ease;
}

.progress-text {
    display: flex;
    justify-content: space-between;
    margin-top: 8px;
    font-size: 0.8rem;
    color: var(--text-secondary);
}

#progress-percent {
    font-family: var(--font-mono);
    font-weight: 600;
    color: var(--accent);
}

/* Indexed sources list (injected by index.js) */
.repo-item {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 16px;
    padding: 16px;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    margin-bottom: 12px;
    transition: box-shadow 0.15s, border-color 0.15s;
}

.repo-item:hover {
    border-color: rgba(69, 193, 230, 0.45);
    box-shadow: var(--shadow-md);
}

.repo-info {
    min-width: 0;
}

.repo-info h4 {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    font-size: 0.95rem;
    font-weight: 700;
    letter-spacing: -0.005em;
    margin-bottom: 6px;
}

.repo-info p {
    font-size: 0.79rem;
    color: var(--text-secondary);
    word-break: break-all;
}

.repo-stats {
    display: flex;
    flex-wrap: wrap;
    gap: 7px;
    margin-top: 10px;
}

.stat-item {
    padding: 3px 10px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-light);
    border-radius: 99px;
    font-size: 0.73rem;
    font-weight: 500;
    color: var(--text-secondary);
    white-space: nowrap;
}

.status-badge {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 99px;
    font-size: 0.67rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.status-badge.success {
    background: var(--success-bg);
    color: var(--success-text);
}

.status-badge.warning {
    background: var(--warning-bg);
    color: var(--warning-text);
}

.status-badge.danger {
    background: var(--danger-bg);
    color: var(--danger-text);
}

/* Danger button (delete source — injected by index.js) */
.btn-danger {
    padding: 7px 14px;
    background: var(--bg-primary);
    color: var(--danger);
    border: 1px solid rgba(224, 45, 60, 0.4);
    border-radius: var(--radius-md);
    cursor: pointer;
    font-family: var(--font-body);
    font-size: 0.8rem;
    font-weight: 600;
    flex-shrink: 0;
    transition: all 0.15s;
}

.btn-danger:hover {
    background: var(--danger);
    border-color: var(--danger);
    color: #fff;
    box-shadow: 0 3px 10px -2px rgba(224, 45, 60, 0.5);
}

/* ==========================================================================
   API keys modal
   ========================================================================== */

.api-keys-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}

.api-keys-table thead tr {
    border-bottom: 1px solid var(--border);
    text-align: left;
}

.api-keys-table th {
    padding: 8px 12px;
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-tertiary);
}

.api-access-info {
    margin: 4px 0 20px;
    font-size: 0.82rem;
    color: var(--text-secondary);
    line-height: 1.5;
}

.api-access-option {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 8px;
}

.api-access-tag {
    flex: none;
    width: 44px;
    text-align: center;
    padding: 2px 0;
    border-radius: 999px;
    background: var(--signal);
    color: var(--ink-900, #06121c);
    font-family: var(--font-mono);
    font-size: 0.62rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.api-access-details {
    margin-top: 10px;
}

.api-access-details summary {
    cursor: pointer;
    color: var(--text-tertiary);
    font-size: 0.78rem;
    font-weight: 600;
}

.api-access-details-body {
    margin-top: 8px;
    padding-left: 2px;
}

.api-access-details-body p {
    margin: 8px 0 4px;
}

.api-access-details-body ul {
    margin: 0 0 4px;
    padding-left: 18px;
}

.api-access-details-body li {
    margin-bottom: 3px;
}

.api-access-info code {
    padding: 1px 5px;
    background: var(--ink-900);
    color: #cfe3f5;
    border-radius: 4px;
    font-family: var(--font-mono);
    font-size: 0.72rem;
}

.api-keys-create {
    margin-top: 24px;
    padding-top: 20px;
    border-top: 1px solid var(--border-light);
}

.api-keys-create h3 {
    font-family: var(--font-display);
    font-size: 0.95rem;
    font-weight: 700;
    margin-bottom: 12px;
}

.api-keys-create-row {
    display: flex;
    gap: 10px;
    align-items: center;
}

.api-keys-create-row input {
    flex: 1;
    padding: 9px 13px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    font-family: var(--font-body);
    font-size: 0.875rem;
    background: var(--bg-primary);
    color: var(--text-primary);
}

.api-keys-create-row input:focus {
    outline: none;
    border-color: var(--signal);
    box-shadow: 0 0 0 3px rgba(69, 193, 230, 0.18);
}

.new-key-panel {
    margin-top: 16px;
    padding: 16px;
    background: var(--warning-bg);
    border: 1px solid var(--warning-border);
    border-radius: var(--radius-lg);
}

.new-key-warning {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 10px;
    color: var(--warning-text);
    font-weight: 600;
    font-size: 0.875rem;
}

.new-key-row {
    display: flex;
    gap: 8px;
    align-items: center;
}

.new-key-row code {
    flex: 1;
    padding: 10px 12px;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: var(--font-mono);
    font-size: 0.76rem;
    word-break: break-all;
}

.new-key-row button {
    padding: 9px 13px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--bg-primary);
    color: var(--text-primary);
    font-family: var(--font-body);
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.15s;
}

.new-key-row button:hover {
    border-color: var(--signal);
    color: var(--accent);
}

.setup-details {
    margin-top: 12px;
}

.setup-details summary {
    cursor: pointer;
    color: var(--text-secondary);
    font-size: 0.85rem;
    font-weight: 600;
}

.setup-details-body {
    margin-top: 10px;
    font-size: 0.82rem;
    color: var(--text-secondary);
}

.setup-details-body p {
    margin: 12px 0 6px;
}

.setup-details-body p:first-child {
    margin-top: 0;
}

.setup-details-body pre {
    padding: 12px;
    background: var(--ink-900);
    color: #cfe3f5;
    border-radius: var(--radius-md);
    overflow-x: auto;
    font-family: var(--font-mono);
    font-size: 0.72rem;
    line-height: 1.6;
}

/* ==========================================================================
   Project-context modal helpers
   ========================================================================== */

.context-textarea {
    width: 100%;
    min-height: 200px;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    font-family: var(--font-mono);
    font-size: 0.83rem;
    line-height: 1.55;
    resize: vertical;
    color: var(--text-primary);
    background: var(--bg-primary);
}

.context-textarea:focus {
    outline: none;
    border-color: var(--signal);
    box-shadow: 0 0 0 3px rgba(69, 193, 230, 0.18);
}

/* ==========================================================================
   Responsive
   ========================================================================== */

@media (max-width: 1380px) {
    /* Collapse header chips to icons only */
    .header-controls .btn-label {
        display: none;
    }

    .btn-settings .btn-ic,
    .btn-sources .btn-ic,
    .logout-btn .btn-ic {
        margin-right: 0;
    }

    .btn-settings,
    .btn-sources,
    .logout-btn {
        padding: 8px 10px;
    }

    /* Header is getting tight — drop the ADMIN role badge to free up room. */
    .user-role {
        display: none;
    }
}

@media (max-width: 1000px) {
    #userEmail {
        display: none;
    }

    .user-info .btn-ic {
        margin-right: 0;
    }

    .conversations-sidebar {
        width: 280px;
        min-width: 280px;
    }

    .conversations-sidebar > * {
        min-width: 250px;
    }
}

/* ==========================================================================
   Narrow widths (chat open): the rail becomes an off-canvas drawer.
   Below this width an inline rail would crush the chat down to a useless
   sliver, so instead the rail floats over the chat as a full-width slide-in
   drawer — all-or-nothing: open fully or closed fully, never a squished
   in-between. index.js (isMobileViewport, same 900px threshold) auto-collapses
   the drawer when a chat is selected, so it starts closed; the in-rail close
   button (shown only here) slides it back to the chat.
   ========================================================================== */
@media (max-width: 900px) {
    body:not(.no-chat-selected) .conversations-sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        z-index: 60;
        width: 100vw;
        min-width: 0;
        transform: translateX(0);
        transition: transform 0.3s var(--ease-out);
        box-shadow: var(--shadow-xl);
    }

    body:not(.no-chat-selected) .conversations-sidebar > * {
        min-width: 0;
    }

    body:not(.no-chat-selected).sidebar-collapsed .conversations-sidebar {
        transform: translateX(-100%);
        width: 100vw;
        min-width: 0;
        border-right: 1px solid var(--rail-border);
        box-shadow: none;
    }

    /* The drawer covers the whole screen, so close it from inside the rail. */
    body:not(.no-chat-selected) .sidebar-close-btn {
        display: inline-flex;
    }
}

@media (max-width: 768px) {
    /* ----- Home state: the rail is the full-screen stage ----- */
    body.no-chat-selected .conversations-sidebar {
        width: 100vw;
        min-width: 100vw;
    }

    body.no-chat-selected .conversations-list {
        grid-template-columns: 1fr;
        padding: 8px 18px 24px;
    }

    body.no-chat-selected .conversation-search {
        padding: 12px 18px 14px;
    }

    body.no-chat-selected .sidebar-header {
        padding: 32px 20px 8px;
    }

    /* ----- Roomier tap targets on phones ----- */
    .btn-sidebar-toggle,
    .btn-new-chat-inline {
        width: 40px;
        height: 40px;
    }

    .btn-settings,
    .btn-sources,
    .logout-btn,
    #theme-toggle-btn,
    .user-info {
        padding: 10px 12px;
    }

    .delete-btn {
        padding: 6px 11px;
        font-size: 0.72rem;
    }
}
