/* Buttons */
button {
    font-family: inherit;
}

.btn-primary,
.btn-secondary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 1.1;
    min-height: 32px;
    white-space: nowrap;
}

.btn-primary {
    border: none;
    background: var(--color-primary-red);
    color: #fff;
    padding: 8px 16px;
    border-radius: 20px;
    cursor: pointer;
    font-weight: 600;
    transition: transform 0.1s;
    gap: 8px;
    text-decoration: none;
}

.btn-primary:hover:not(:disabled) {
    transform: translateY(-1px);
    filter: brightness(1.1);
}

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

.btn-secondary {
    border: 1px solid var(--color-primary-red);
    background: var(--color-surface);
    color: var(--color-primary-red);
    padding: 8px 16px;
    border-radius: 20px;
    cursor: pointer;
    font-weight: 600;
    transition: background 0.1s;
}

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

tr:hover td {
    background: var(--color-surface-active);
    color: var(--color-text-primary);
}

.btn-secondary:disabled {
    border-color: var(--color-border);
    color: var(--color-text-secondary);
    cursor: not-allowed;
    opacity: 0.6;
    filter: grayscale(1);
    box-shadow: inset 4px 0 0 rgba(245, 67, 47, 0.35);
}

.icon-btn {
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    color: var(--color-text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, color 0.2s;
}

.icon-btn:hover {
    background: rgba(0, 0, 0, 0.05);
    color: var(--color-text-primary);
}

.icon-btn.danger:hover {
    background: rgba(217, 48, 37, 0.1);
    color: var(--color-danger);
}

/* Forms (Inputs, Selects, Textareas) */
.form-group {
    margin-bottom: 20px;
}

.form-label {
    display: block;
    margin-bottom: 6px;
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--color-text-body);
}

.form-input,
.form-select,
.form-textarea,
input[type="text"],
input[type="number"],
input[type="search"],
select,
textarea {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 0.95rem;
    transition: border-color 0.2s, box-shadow 0.2s;
    background-color: var(--color-surface-input);
    color: var(--color-text-primary);
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus,
input[type="text"]:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: var(--color-primary-green);
    box-shadow: 0 0 0 3px rgba(13, 102, 107, 0.1);
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus,
input[type="number"]:focus,
input[type="search"]:focus,
select:focus,
textarea:focus {
    border-color: var(--color-primary-green);
    outline: none;
    box-shadow: 0 0 0 3px rgba(13, 102, 107, 0.1);
}

/* Checkboxes */
input[type="checkbox"] {
    accent-color: var(--color-primary-green);
    width: 1rem;
    height: 1rem;
    cursor: pointer;
}

/* Toggle Switch */
.toggle-switch {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
}

.toggle-switch input {
    display: none;
}

.toggle-track {
    width: 40px;
    height: 22px;
    background: #ccc;
    border-radius: 999px;
    position: relative;
    transition: background 0.2s;
}

.toggle-track::after {
    content: '';
    position: absolute;
    left: 2px;
    top: 2px;
    width: 18px;
    height: 18px;
    background: #fff;
    border-radius: 50%;
    transition: transform 0.2s;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.toggle-switch input:checked+.toggle-track {
    background: var(--color-primary-green);
}

.toggle-switch input:checked+.toggle-track::after {
    transform: translateX(18px);
}

/* Custom Select Styling Override */
select,
.form-select {
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    padding-right: 40px;
    background-image:
        linear-gradient(45deg, transparent 50%, var(--color-text-body) 50%),
        linear-gradient(135deg, var(--color-text-body) 50%, transparent 50%),
        linear-gradient(to right, #d0d7de, #d0d7de);
    background-position: calc(100% - 22px) 50%, calc(100% - 14px) 50%, calc(100% - 2.8em) 50%;
    background-size: 7px 7px, 7px 7px, 1px 40%;
    background-repeat: no-repeat;
    cursor: pointer;
}

.form-textarea {
    min-height: 120px;
    resize: vertical;
    overflow: auto;
    border-color: var(--color-border);
    padding-bottom: 14px;
    background-image: linear-gradient(-45deg,
            transparent 0 53%,
            var(--color-border-light) 53% 59%,
            transparent 59% 69%,
            var(--color-border) 69% 75%,
            transparent 75%);
    background-size: 14px 14px;
    background-repeat: no-repeat;
    background-position: right 6px bottom 6px;
}

/* Custom Select & Multi-Pick */
.custom-select {
    position: relative;
    width: 100%;
}

.select-trigger {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    background-color: var(--color-surface-input);
    color: var(--color-text-primary);
    cursor: pointer;
    font-size: 0.95rem;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.select-trigger.disabled {
    cursor: not-allowed;
    opacity: 0.7;
}

.select-trigger:focus,
.select-trigger.open {
    outline: none;
    border-color: var(--color-primary-green);
    box-shadow: 0 0 0 3px rgba(13, 102, 107, 0.1);
}

.select-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    right: auto;
    margin-top: 4px;
    background: var(--color-surface-panel);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-md);
    z-index: 50;
    /* Expand to fit the longest option when space allows (prevents cut-off labels). */
    min-width: 100%;
    width: max-content;
    max-width: calc(100vw - 24px);
    max-height: 200px;
    overflow-y: auto;
    overflow-x: auto;
    display: none;
}

.select-dropdown.open {
    display: block;
}

.select-search {
    position: sticky;
    top: 0;
    z-index: 1;
    background: var(--color-surface-panel);
    border-bottom: 1px solid var(--color-border);
    padding: 8px 12px;
}

.select-search-input {
    width: 100%;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    padding: 6px 10px;
    font-size: 0.95rem;
    background: var(--color-surface-input);
    color: var(--color-text-primary);
}

.select-search-input:focus {
    outline: none;
    border-color: var(--color-primary-green);
    box-shadow: 0 0 0 3px rgba(13, 102, 107, 0.1);
}

.select-option {
    padding: 8px 12px;
    cursor: pointer;
    color: var(--color-text-primary);
    transition: background 0.1s;
}

.select-option:hover {
    background: var(--color-surface-alt);
}

.select-option.selected {
    background: var(--color-surface-active);
    color: var(--color-text-primary);
    font-weight: 700;
    box-shadow: inset 3px 0 0 var(--color-primary-green);
}

.select-empty,
.select-overflow-hint {
    padding: 8px 12px;
    color: var(--color-text-secondary);
    font-size: 0.9rem;
}

.select-overflow-hint {
    border-top: 1px dashed var(--color-border);
}

/* Input Wrapper (Search, Chip Inputs) */
.input-wrapper {
    position: relative;
    display: flex;
    align-items: center;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    background: var(--color-surface-input);
    padding: 4px 12px;
    transition: box-shadow 0.2s;
    gap: 8px;
}

.input-wrapper:focus-within {
    border-color: var(--color-primary-green);
    box-shadow: 0 0 0 3px rgba(13, 102, 107, 0.1);
}

.input-wrapper.multiline {
    align-items: flex-end;
}

.chip-input {
    border: none;
    outline: none;
    flex: 1;
    min-width: 120px;
    padding: 4px;
    font-family: inherit;
    font-size: 0.95rem;
    background: transparent;
    box-shadow: none !important;
    /* override default input focus */
}

textarea.chip-input.chip-textarea {
    resize: none;
    overflow-y: hidden;
    min-height: 34px;
    max-height: 180px;
    padding: 6px 4px;
    line-height: 1.4;
    white-space: pre-wrap;
    word-break: break-word;
}

textarea.chip-input.chip-textarea.form-input,
textarea.chip-input.chip-textarea.form-textarea {
    width: 100%;
    flex: initial;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    background: var(--color-surface-input);
    resize: vertical;
    overflow-y: auto;
    min-height: 120px;
    max-height: none;
    padding: 8px 12px 14px;
    background-image: linear-gradient(-45deg,
            transparent 0 53%,
            var(--color-border-light) 53% 59%,
            transparent 59% 69%,
            var(--color-border) 69% 75%,
            transparent 75%);
    background-size: 14px 14px;
    background-repeat: no-repeat;
    background-position: right 6px bottom 6px;
}

textarea.chip-input.chip-textarea.form-input:focus,
textarea.chip-input.chip-textarea.form-textarea:focus {
    border-color: var(--color-primary-green);
    box-shadow: 0 0 0 3px rgba(13, 102, 107, 0.1) !important;
}

.search-wrapper {
    position: relative;
    max-width: 300px;
    width: 100%;
}

.search-input {
    width: 100%;
    padding: 8px 12px 8px 36px;
    border: 1px solid var(--color-border-light);
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 0.95rem;
}

.search-icon {
    position: absolute;
    left: 10px;
    top: 50%;
    transform: translateY(-50%);
    color: #999;
    pointer-events: none;
}

/* Chips */
.chip {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
    margin-right: 4px;
    margin-bottom: 2px;
}

.chip.tool,
.function-chip {
    background: var(--color-surface-active);
    color: var(--color-text-primary);
    border: 1px solid var(--color-border);
}

.function-chip {
    display: inline-flex;
    align-items: center;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: 600;
    gap: 4px;
}

.chip.kb {
    background: #fff4e0;
    color: #d68b00;
}

.chip.more {
    background: #eee;
    color: #666;
}

/* Status Badges */
.status-badge {
    display: inline-block;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: capitalize;
}

.status-badge.published {
    background: #e6f4ea;
    color: #137333;
}

.status-badge.draft {
    background: #f1f3f4;
    color: #5f6368;
}

.status-badge.deprecated {
    background: #fce8e6;
    color: #c5221f;
}

.status-badge.sync-completed {
    background: #e6f4ea;
    color: #0c5c20;
}

.status-badge.sync-in_progress {
    background: #fff4e0;
    color: #b15e0f;
}

.status-badge.sync-failed {
    background: #fbe4e2;
    color: #c5221f;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #ccc;
}

.status-dot.active {
    background: var(--color-primary-green);
    box-shadow: 0 0 0 4px rgba(13, 102, 107, 0.15);
}

/* Chat UI */
.chat-wrapper {
    display: flex;
    flex: 0 1 auto;
    width: var(--chat-width, 800px);
    max-width: 100%;
    min-width: 480px;
    height: 100%;
    margin: 0 auto;
    position: relative;
    transition: width 0.1s;
    gap: 8px;
    min-height: 0;
}

.chat-shell {
    background: var(--color-surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    border: 1px solid var(--color-border);
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto;
    height: 100%;
    max-height: 100%;
    flex: 1;
    overflow: hidden;
    position: relative;
    min-height: 0;
}

.chat-header {
    padding: 12px 20px;
    border-bottom: 1px solid var(--color-border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--color-surface-alt);
    font-weight: 600;
}

.chat-body {
    padding: 20px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 16px;
    scroll-behavior: smooth;
    min-height: 0;
    color: var(--color-text-primary);
}

.chat-footer {
    padding: 16px;
    border-top: 1px solid var(--color-border);
    background: var(--color-surface);
}

.attachment-preview,
.message-attachment {
    display: flex;
    gap: 12px;
    align-items: center;
}

.attachment-preview {
    padding: 10px 12px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    background: var(--color-surface-input);
    margin-bottom: 10px;
}

.message-attachment {
    align-items: flex-start;
    margin-bottom: 8px;
}

.attachment-thumb {
    width: 72px;
    height: 72px;
    border: 1px dashed var(--color-border-light);
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--color-surface);
    overflow: hidden;
    flex-shrink: 0;
}

.message-attachment .attachment-thumb {
    width: 140px;
    height: 96px;
}

.attachment-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.attachment-details {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 0;
}

.attachment-name {
    font-weight: 700;
    color: var(--color-text-primary);
}

.attachment-meta {
    font-size: 0.85rem;
    color: var(--color-text-secondary);
}

.attachment-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.attachment-link {
    color: var(--color-primary-blue);
    font-weight: 600;
    text-decoration: none;
}

.attachment-link:hover {
    text-decoration: underline;
}

.message {
    max-width: 85%;
    padding: 12px 18px;
    border-radius: 18px;
    font-size: 0.95rem;
    line-height: 1.5;
    box-shadow: var(--shadow-sm);
    position: relative;
}

.message.user {
    align-self: flex-end;
    background-color: var(--color-user-bubble-bg);
    color: var(--color-text-inverse);
    border-bottom-right-radius: 4px;
}

.message.user * {
    color: var(--color-text-inverse) !important;
}

.message.bot {
    align-self: flex-start;
    background-color: var(--color-bot-bubble-bg);
    color: var(--color-text-primary);
    border-bottom-left-radius: 4px;
}

.message.tool {
    align-self: center;
    background-color: #e7f2f5;
    color: #0d666b;
    font-size: 0.85rem;
    padding: 8px 12px;
    border-radius: 12px;
    border: 1px solid #b5dfe2;
    width: auto;
    max-width: 90%;
}

.message-feedback-badge {
    position: absolute;
    top: -12px;
    right: -12px;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--color-surface-pilled);
    border: 1px solid var(--color-border);
    box-shadow: var(--shadow-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2;
}

.message-feedback-badge svg {
    width: 16px;
    height: 16px;
}

.message-feedback-badge.thumbs_up {
    color: var(--color-primary-green);
}

.message-feedback-badge.thumbs_down {
    color: var(--color-primary-red);
}

.message-actions {
    position: absolute;
    bottom: -16px;
    right: 0;
    background: var(--color-surface-pilled);
    border-radius: 20px;
    padding: 2px;
    box-shadow: var(--shadow-sm);
    display: flex;
    opacity: 0;
    transition: opacity 0.2s;
    border: 1px solid var(--color-border);
}

.message-actions .icon-btn.active.thumbs-up {
    color: var(--color-primary-green);
}

.message-actions .icon-btn.active.thumbs-down {
    color: var(--color-primary-red);
}

.message:hover .message-actions {
    opacity: 1;
}

.typing-indicator span {
    display: inline-block;
    width: 5px;
    height: 5px;
    background: #aaa;
    border-radius: 50%;
    margin: 0 2px;
    animation: bounce 1s infinite;
}

.typing-indicator span:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-indicator span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes bounce {

    0%,
    100% {
        transform: translateY(0);
    }

    50% {
        transform: translateY(-4px);
    }
}

/* Chat Overlays */
.chat-overlay {
    position: absolute;
    inset: 0;
    background: rgba(255, 255, 255, 0.7);
    backdrop-filter: blur(2px);
    z-index: 5;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 20px;
    color: var(--color-text-primary);
}

:root[data-theme="dark"] .chat-overlay {
    background: rgba(0, 0, 0, 0.55);
    backdrop-filter: blur(6px);
}

.chat-overlay.unauth {
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.75), rgba(255, 243, 236, 0.9));
    backdrop-filter: blur(8px) saturate(115%);
    border: 1px solid rgba(217, 48, 37, 0.12);
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.5);
}

:root[data-theme="dark"] .chat-overlay.unauth {
    background: linear-gradient(135deg, rgba(40, 40, 40, 0.9), rgba(28, 28, 28, 0.92));
    border: 1px solid rgba(110, 204, 223, 0.22);
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.06);
}

.chat-overlay .chat-overlay-card {
    background: var(--color-surface);
    border-radius: 18px;
    padding: 16px 20px;
    box-shadow: var(--shadow-lg);
    display: flex;
    flex-direction: column;
    gap: 12px;
    min-width: 260px;
    max-width: 340px;
    border: 1px solid var(--color-border);
    color: var(--color-text-primary);
}

:root[data-theme="dark"] .chat-overlay .chat-overlay-card {
    background: var(--color-surface-panel);
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.5);
}

.chat-overlay .chat-overlay-headline {
    display: flex;
    align-items: center;
    gap: 12px;
}

.chat-overlay .chat-overlay-icon {
    width: 40px;
    height: 40px;
    border-radius: 12px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: rgba(217, 48, 37, 0.1);
    color: var(--color-primary-red);
}

:root[data-theme="dark"] .chat-overlay .chat-overlay-icon {
    background: rgba(245, 67, 47, 0.16);
}

.chat-overlay .chat-overlay-title {
    font-weight: 700;
    color: var(--color-text-primary);
}

.chat-overlay .chat-overlay-subtitle {
    font-size: 0.95rem;
    color: var(--color-text-secondary);
}

.chat-overlay .chat-overlay-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
}

.chat-overlay .chat-overlay-actions .btn-secondary {
    padding: 6px 12px;
}

.chat-blur-target {
    filter: blur(3px);
    pointer-events: none;
    user-select: none;
}

.drag-overlay {
    position: absolute;
    inset: 0;
    background: rgba(13, 102, 107, 0.1);
    border: 2px dashed var(--color-primary-green);
    border-radius: var(--radius-lg);
    z-index: 20;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--color-primary-green);
}

.drag-overlay.active {
    opacity: 1;
    background: radial-gradient(circle at 50% 30%, rgba(13, 102, 107, 0.15), rgba(13, 102, 107, 0.05));
    box-shadow: 0 12px 32px rgba(13, 102, 107, 0.12);
}

.drag-overlay .drag-overlay-card {
    background: rgba(255, 255, 255, 0.98);
    border-radius: 18px;
    padding: 14px 18px;
    box-shadow: var(--shadow-lg);
    display: inline-flex;
    align-items: center;
    gap: 12px;
    border: 1px solid rgba(13, 102, 107, 0.15);
}

.drag-overlay .drag-overlay-icon {
    width: 40px;
    height: 40px;
    border-radius: 12px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: rgba(13, 102, 107, 0.1);
    color: var(--color-primary-green);
}

.drag-overlay .drag-overlay-text {
    display: flex;
    flex-direction: column;
    gap: 2px;
    text-align: left;
}

.drag-overlay .drag-overlay-text .title {
    font-weight: 700;
    color: var(--color-text-primary);
}

.drag-overlay .drag-overlay-text .subtitle {
    font-size: 0.9rem;
    color: var(--color-text-secondary);
}

/* Slash Menu */
.slash-menu {
    position: absolute;
    bottom: 100%;
    left: 0;
    right: 0;
    background: #fff;
    border: 1px solid var(--color-border-light);
    border-radius: 12px;
    box-shadow: var(--shadow-lg);
    max-height: 240px;
    overflow-y: auto;
    margin-bottom: 8px;
    z-index: 20;
}

.slash-item {
    padding: 8px 12px;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    gap: 2px;
    border-bottom: 1px solid #f0f0f0;
}

.slash-item.active {
    background: #eef2ff;
}

.slash-item:hover {
    background: #f7f9fc;
}

/* Side Panel (Chat Context) */
.side-panel {
    background: var(--color-surface);
    /* Width is handled inline by JS for resizing */
    border-left: 1px solid var(--color-border);
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-lg);
    z-index: 20;
    height: calc(100% - 32px);
    /* Vertical float */
    color: var(--color-text-primary);
    border-radius: var(--radius-lg);
    border: 1px solid var(--color-border);
    margin: 16px;
    /* Fully floating */
    transition: opacity 0.2s;
    position: relative;
    min-width: 300px;
    max-width: 800px;
}

.side-panel.inactive {
    border-color: var(--color-border-light);
    box-shadow: inset 0 0 0 1px var(--color-border-light);
    background: var(--color-surface-alt);
}

/* Disabled state applies to the body content wrapper, not the whole panel */
.sp-content-wrapper.disabled {
    pointer-events: none;
    opacity: 0.6;
    filter: grayscale(1);
}

.sp-content-wrapper.inactive {
    pointer-events: none;
    opacity: 0.8;
    filter: grayscale(0.2);
}

.side-panel.inactive .sp-header h3 {
    color: var(--color-text-secondary);
}

.side-panel.inactive .sp-field input,
.side-panel.inactive .sp-field select,
.side-panel.inactive .sp-field textarea {
    pointer-events: none;
    background: var(--color-surface);
    border-color: var(--color-border-light);
    color: var(--color-text-secondary);
}

.side-panel.inactive .sp-actions,
.side-panel.inactive .sp-body .btn-primary,
.side-panel.inactive .sp-body .btn-secondary {
    display: none !important;
}

.sp-record-title {
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--color-text-primary);
    margin-bottom: 12px;
}

.sp-record-link {
    color: var(--color-primary-blue);
    text-decoration: none;
}

.sp-record-link:hover {
    text-decoration: underline;
}

.deep-dive-table td {
    vertical-align: top;
}

.sp-truncate {
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 3;
    word-break: break-word;
}

.sp-truncate.sp-value {
    color: var(--color-text-body);
}

.panel-rail {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 16px 8px;
    border-left: 1px solid transparent;
    /* Placeholder for alignment */
    height: 100%;
}

.panel-rail.disabled {
    pointer-events: none;
    opacity: 0.6;
    filter: grayscale(1);
}

.panel-chip {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    border: 1px solid var(--color-primary-red);
    background: var(--color-surface);
    box-shadow: var(--shadow-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--color-primary-red);
    text-align: center;
    transition: transform 0.1s, box-shadow 0.1s, background 0.1s;
}

.panel-chip:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
    background: var(--color-bg-cream);
}

:root[data-theme="dark"] .panel-chip {
    background: var(--color-surface-panel);
    border-color: var(--color-primary-red);
    color: var(--color-primary-red);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.panel-chip.disabled {
    border-color: var(--color-border);
    color: var(--color-text-secondary);
    background: var(--color-surface-alt);
    cursor: not-allowed;
    box-shadow: none;
    transform: none;
}

:root[data-theme="dark"] .panel-chip.disabled {
    background: var(--color-surface);
}


.sp-header {
    min-height: 64px;
    padding: 0 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--color-border);
    font-weight: 600;
    gap: 16px;
}

.sp-body {
    padding: 16px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.sp-grid {
    display: grid;
    gap: 12px;
}

.sp-grid.two-col {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

@media (max-width: 720px) {
    .sp-grid.two-col {
        grid-template-columns: 1fr;
    }
}

.sp-field label {
    font-size: 0.8rem;
    color: var(--color-text-body);
    font-weight: 600;
    display: block;
    margin-bottom: 4px;
}

.sp-field input {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid var(--color-border-light);
    border-radius: 6px;
}

/* Tables */
.table-container {
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    /* Enable vertical scrolling for CRUD/admin tables inside fixed-height shells */
    overflow: auto;
    background: var(--color-surface);
    flex: 1 1 auto;
    min-height: 0;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.95rem;
    color: var(--color-text-primary);
}

th {
    text-align: left;
    padding: 12px 16px;
    background: var(--color-surface-alt);
    color: var(--color-text-secondary);
    font-weight: 600;
    border-bottom: 1px solid var(--color-border);
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

th.sortable-th {
    cursor: pointer;
    user-select: none;
}

th.sortable-th:hover {
    background: var(--color-surface-active);
}

th.sortable-th:focus {
    outline: none;
    box-shadow: inset 0 0 0 2px rgba(13, 102, 107, 0.25);
}

.th-label {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.th-indicator {
    font-size: 0.75rem;
    color: var(--color-text-secondary);
    transform: translateY(-1px);
}

td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--color-border);
    vertical-align: middle;
}

tr:last-child td {
    border-bottom: none;
}

tr:hover td {
    background-color: var(--color-surface-active);
    cursor: pointer;
}

/* Modals */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal {
    background: var(--color-surface);
    padding: 24px;
    border-radius: 16px;
    width: 400px;
    max-width: 90%;
    box-shadow: var(--shadow-lg);
    color: var(--color-text-primary);
    border: 1px solid var(--color-border);
}

:root[data-theme="dark"] .modal {
    background: var(--color-surface-panel);
}

.floating-table-overlay {
    position: fixed;
    inset: 0;
    z-index: 260;
    background: rgba(0, 0, 0, 0.42);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.floating-table-dialog {
    position: relative;
    width: min(1100px, calc(100vw - 48px));
    max-height: calc(100vh - 56px);
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 16px;
    box-shadow: var(--shadow-lg);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.floating-table-resize-handle {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 14px;
    cursor: ew-resize;
    z-index: 2;
    touch-action: none;
}

.floating-table-resize-handle--left {
    left: -7px;
}

.floating-table-resize-handle--right {
    right: -7px;
}

.floating-table-dialog__header {
    padding: 12px 16px;
    border-bottom: 1px solid var(--color-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}

.floating-table-dialog__title {
    margin: 0;
    font-size: 1rem;
    font-weight: 700;
    color: var(--color-text-primary);
}

.floating-table-dialog__body {
    padding: 16px;
    overflow: auto;
    min-height: 180px;
}

@media (max-width: 720px) {
    .floating-table-overlay {
        padding: 12px;
    }

    .floating-table-dialog {
        width: calc(100vw - 24px);
        max-height: calc(100vh - 24px);
    }

    .floating-table-dialog__body {
        padding: 12px;
    }
}

/* Typography Utilities */
.text-h1 {
    font-size: 2rem;
    font-weight: 700;
    color: var(--color-text-link);
    margin-bottom: 1rem;
}

.text-h2 {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--color-text-link);
    margin-bottom: 0.75rem;
}

.text-body {
    font-size: 1rem;
    line-height: 1.6;
    color: var(--color-text-primary);
}

.text-meta {
    font-size: 0.85rem;
    color: var(--color-text-secondary);
}

.text-link,
a {
    color: var(--color-text-link);
    text-decoration: none;
    font-weight: inherit;
    cursor: pointer;
}

.text-link:hover,
a:hover {
    text-decoration: underline;
}

.text-link:visited,
a:visited {
    color: var(--color-text-link);
}

.link-button {
    border: none;
    background: none;
    padding: 0;
    margin: 0;
    color: var(--color-text-link);
    font: inherit;
    cursor: pointer;
    text-decoration: underline;
}

.link-button:hover {
    color: var(--color-primary-red);
}

/* Tabs */
.tabs {
    display: flex;
    padding: 0 16px;
    border-bottom: 1px solid var(--color-border-light);
    background: #faf9f7;
}

.tab {
    padding: 12px 16px;
    cursor: pointer;
    color: var(--color-text-body);
    font-weight: 600;
    border-bottom: 2px solid transparent;
    font-size: 0.9rem;
}

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

.tab.active {
    color: var(--color-text-charcoal);
    border-bottom-color: var(--color-primary-green);
}

/* Empty State */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--color-text-body);
    text-align: center;
    padding: 40px;
}

/* Markdown Styles */
.markdown-content p {
    margin-bottom: 0.5em;
}

.markdown-content p:last-child {
    margin-bottom: 0;
}

.markdown-content code {
    background: rgba(0, 0, 0, 0.1);
    padding: 2px 4px;
    border-radius: 4px;
    font-family: monospace;
}

.markdown-content pre {
    background: #2d2d2d;
    color: #f8f8f2;
    padding: 12px;
    border-radius: 8px;
    overflow-x: auto;
    margin: 8px 0;
}

.markdown-content pre code {
    background: transparent;
    color: inherit;
    padding: 0;
}

.markdown-content ul,
.markdown-content ol {
    padding-left: 20px;
    margin: 8px 0;
}

.markdown-content table {
    border-collapse: collapse;
    width: 100%;
    margin: 10px 0;
    font-size: 0.9em;
}

.markdown-content th,
.markdown-content td {
    border: 1px solid #ddd;
    padding: 6px 10px;
    text-align: left;
}

.markdown-content th {
    background: rgba(0, 0, 0, 0.05);
}

/* Conversation List Item (Left Panel) */
.conv-item {
    padding: 12px;
    border-bottom: 1px solid var(--color-border-light);
    cursor: pointer;
    transition: background 0.1s, color 0.1s;
    color: var(--color-text-primary);
}

.conv-item:hover {
    background: var(--color-surface-alt);
}

.conv-item.active {
    background: var(--color-surface-active);
    border-left: 3px solid var(--color-primary-green);
    color: var(--color-text-primary);
}

.conv-date {
    color: var(--color-text-secondary);
    font-size: 0.8rem;
    margin-bottom: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.conv-title {
    font-weight: 600;
    font-size: 0.95rem;
    line-height: 1.3;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Spinner */
.spinner {
    width: 20px;
    height: 20px;
    border: 2px solid rgba(0, 0, 0, 0.1);
    border-left-color: currentColor;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

.loading-spinner {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    border: 3px solid var(--color-border-light);
    border-top-color: var(--color-primary-blue);
    animation: spin 0.9s linear infinite;
}

.loading-spinner.sm {
    width: 18px;
    height: 18px;
    border-width: 2px;
}

.loading-spinner.lg {
    width: 44px;
    height: 44px;
    border-width: 4px;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.08);
}

.loading-spinner-wrap {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    color: var(--color-text-secondary);
}

.loading-spinner-wrap .loading-label {
    font-weight: 600;
    color: var(--color-text-primary);
}

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

/* Utilities */
.small {
    font-size: 0.85rem;
    color: #666;
}

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

/* Top Nav - Dropdown (Reusable) */
.nav-group {
    display: inline-flex;
    align-items: center;
    gap: 10px;
}

.nav-dropdown {
    position: relative;
}

.nav-dropdown > summary {
    list-style: none;
    cursor: pointer;
    user-select: none;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border-radius: 999px;
    border: 1px solid var(--color-border);
    background: var(--color-surface);
    color: var(--color-text-primary);
    font-weight: 600;
    font-size: 0.9rem;
}

.nav-summary-content {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.nav-dropdown > summary::-webkit-details-marker {
    display: none;
}

.nav-dropdown[open] > summary {
    box-shadow: 0 0 0 3px rgba(13, 102, 107, 0.1);
    border-color: rgba(13, 102, 107, 0.35);
}

.nav-dropdown .nav-menu {
    position: absolute;
    top: calc(100% + 10px);
    right: 0;
    left: auto;
    min-width: 220px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 14px;
    box-shadow: var(--shadow-lg);
    overflow: hidden;
    padding: 6px;
    z-index: 60;
}

.nav-menu .nav-menu-item {
    width: 100%;
    text-align: left;
    border: none;
    background: transparent;
    color: var(--color-text-primary);
    cursor: pointer;
    border-radius: 10px;
    padding: 10px 10px;
    font-weight: 600;
}

.nav-menu .nav-menu-item.nav-menu-item--active {
    background: var(--color-surface-alt);
}

.nav-menu .nav-menu-item.nav-menu-item--highlight {
    background: var(--color-primary-red);
    color: #fff;
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.12);
}

.nav-menu .nav-menu-item.nav-menu-item--highlight:hover {
    background: var(--color-primary-light, #e04130);
    color: #fff;
}

.nav-menu .nav-menu-item.nav-menu-item--disabled,
.nav-menu .nav-menu-item:disabled {
    color: var(--color-text-secondary);
    cursor: not-allowed;
    opacity: 0.55;
    filter: grayscale(0.6);
}

.nav-menu .nav-menu-item.nav-menu-item--disabled:hover,
.nav-menu .nav-menu-item:disabled:hover {
    background: transparent;
}

.nav-menu .nav-menu-item:hover {
    background: var(--color-surface-alt);
}

.nav-menu .nav-menu-divider {
    height: 1px;
    background: var(--color-border);
    margin: 6px 2px;
}

/* Admin Console */
.admin-console-scrim {
    position: fixed;
    top: var(--pushai-nav-height, 64px);
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(10, 12, 20, 0.45);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 0.2s ease, visibility 0.2s ease;
    z-index: 120;
}

.admin-console-scrim.open {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

.admin-console {
    position: fixed;
    top: var(--pushai-nav-height, 64px);
    left: 0;
    bottom: 0;
    width: 280px;
    max-width: 80vw;
    background: var(--color-surface);
    border-right: 1px solid var(--color-border);
    box-shadow: var(--shadow-lg);
    transform: translateX(-100%);
    opacity: 0;
    pointer-events: none;
    transition: transform 0.25s ease, opacity 0.2s ease;
    z-index: 130;
    display: flex;
    flex-direction: column;
}

.admin-console.open {
    transform: translateX(0);
    opacity: 1;
    pointer-events: auto;
}

.admin-console__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--color-border);
    font-weight: 700;
}

.admin-console__title {
    font-size: 1rem;
    color: var(--color-text-primary);
}

.admin-console__body {
    padding: 10px 0 14px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.admin-console__section {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.admin-console__section + .admin-console__section {
    border-top: 1px solid var(--color-border);
    padding-top: 10px;
}

.admin-console__section-title {
    display: inline-flex;
    align-self: flex-start;
    margin: 0 14px 4px;
    padding: 5px 10px;
    border: 1px solid var(--color-border);
    border-radius: 999px;
    background: var(--color-surface-alt);
    color: var(--color-text-secondary);
    font-size: 0.67rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    line-height: 1.1;
    text-transform: uppercase;
    cursor: default;
    user-select: none;
    pointer-events: none;
}

.admin-console__item {
    width: 100%;
    text-align: left;
    border: none;
    background: transparent;
    color: var(--color-text-primary);
    cursor: pointer;
    padding: 12px 20px;
    font-weight: 600;
    transition: background 0.1s;
}

.admin-console__item:hover {
    background: var(--color-surface-alt);
}

.admin-console.admin-console--docked {
    position: relative;
    top: 0;
    left: 0;
    bottom: auto;
    height: 100%;
    width: 240px;
    max-width: none;
    transform: none;
    opacity: 1;
    pointer-events: auto;
    box-shadow: none;
    transition: none;
    z-index: 1;
    flex: 0 0 240px;
}

.admin-console--docked .admin-console__body {
    flex: 1;
}

.admin-console__item--active {
    background: var(--color-surface-alt);
    box-shadow: inset 3px 0 0 var(--color-primary-red);
}

/* 
========================================
   Mobile Components (Drawer & Sheet)
========================================
*/

/* Drawer (Side Menu) */
.drawer-scrim {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 900;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s, visibility 0.3s;
    backdrop-filter: blur(2px);
}

.drawer-scrim.open {
    opacity: 1;
    visibility: visible;
}

.drawer {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    width: 280px;
    max-width: 80%;
    background: var(--color-surface);
    z-index: 950;
    transform: translateX(-100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: var(--shadow-lg);
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--color-border);
}

.drawer.open {
    transform: translateX(0);
}

.drawer-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--color-border);
    font-weight: 700;
    font-size: 1.1rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--color-surface);
}

.drawer-body {
    flex: 1;
    overflow-y: auto;
    padding: 0;
}

/* Bottom Sheet */
.sheet-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 900;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s, visibility 0.3s;
}

.sheet-overlay.open {
    opacity: 1;
    visibility: visible;
}

.sheet {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--color-surface);
    z-index: 950;
    transform: translateY(100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    border-top-left-radius: 20px;
    border-top-right-radius: 20px;
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.15);
    display: flex;
    flex-direction: column;
    max-height: 85vh;
}

.sheet.open {
    transform: translateY(0);
}

:root[data-theme='dark'] .sheet {
    border-top: 1px solid var(--color-border);
}

.sheet-handle-bar {
    width: 100%;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: grab;
}

.sheet-handle {
    width: 40px;
    height: 4px;
    background: var(--color-border);
    border-radius: 4px;
}

.sheet-header {
    padding: 0 20px 12px 20px;
    font-weight: 700;
    font-size: 1.1rem;
    border-bottom: 1px solid var(--color-border-light);
}

.sheet-body {
    padding: 16px 0;
    overflow-y: auto;
    overscroll-behavior: contain;
}

.sheet-item {
    padding: 12px 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
    transition: background 0.1s;
    border-bottom: 1px solid var(--color-border-light);
}

.sheet-item:last-child {
    border-bottom: none;
}

.sheet-item:active {
    background: var(--color-surface-active);
}

.sheet-item-icon {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    background: var(--color-surface-input);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--color-text-secondary);
}

.sheet-item-content {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.sheet-item-title {
    font-weight: 600;
    color: var(--color-text-primary);
}

.sheet-item-subtitle {
    font-size: 0.85rem;
    color: var(--color-text-secondary);
}
