/* AI WebUI Custom Styles (Bootstrap 5.3 Theme Extension) */

:root {
    --sidebar-width: 280px;
}

body {
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    user-select: text;
}

/* Sidebar Styles */
.sidebar {
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    transition: transform 0.3s ease-in-out, margin 0.3s ease-in-out;
    z-index: 1040;
}

@media (max-width: 767.98px) {
    .sidebar {
        position: fixed;
        top: 0;
        bottom: 0;
        left: 0;
        transform: translateX(-100%);
        box-shadow: 0 0 20px rgba(0, 0, 0, 0.5);
    }

    .sidebar.show {
        transform: translateX(0);
    }
}

.cursor-pointer {
    cursor: pointer;
}

.conversation-item {
    transition: background-color 0.15s ease-in-out;
}

.conversation-item:hover {
    background-color: var(--bs-tertiary-bg);
}

.conversation-item:hover .item-actions {
    display: flex !important;
}

.conversation-item.active {
    background-color: var(--bs-primary-bg-subtle);
    border-left: 3px solid var(--bs-primary) !important;
}

/* Chat Feed Messages */
.chat-messages-container {
    scroll-behavior: smooth;
}

.message-bubble-wrapper {
    max-width: 860px;
    margin-left: auto;
    margin-right: auto;
    width: 100%;
}

.message-bubble {
    border-radius: 1rem;
    padding: 0.85rem 1.15rem;
    position: relative;
    word-break: break-word;
}

.message-bubble.user-bubble {
    background-color: var(--bs-primary-bg-subtle);
    border: 1px solid var(--bs-primary-border-subtle);
    margin-left: auto;
    max-width: 85%;
}

.message-bubble.assistant-bubble {
    background-color: transparent;
    width: 100%;
    padding-left: 0;
    padding-right: 0;
}

/* Thinking / Reasoning Box (DeepSeek-R1 style) */
.thinking-box {
    background-color: rgba(125, 125, 125, 0.08);
    border-left: 3px solid var(--bs-secondary);
    border-radius: 0.375rem;
    padding: 0.5rem 0.75rem;
    margin-bottom: 0.75rem;
    font-size: 0.875rem;
    color: var(--bs-secondary-color);
}

.thinking-box summary {
    cursor: pointer;
    font-weight: 600;
    outline: none;
    user-select: none;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.thinking-content {
    margin-top: 0.5rem;
    white-space: pre-wrap;
    font-family: inherit;
    font-size: 0.83rem;
    line-height: 1.4;
    border-top: 1px dashed rgba(125, 125, 125, 0.2);
    padding-top: 0.5rem;
}

/* Markdown Typography */
.markdown-body {
    line-height: 1.6;
    font-size: 0.95rem;
}

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

.markdown-body pre {
    position: relative;
    background-color: #1e1e2e;
    border-radius: 0.5rem;
    padding: 1rem;
    margin: 0.75rem 0;
    overflow-x: auto;
}

.markdown-body pre code {
    font-family: "Fira Code", Consolas, Monaco, "Andale Mono", monospace;
    font-size: 0.875rem;
    color: #e0e0e0;
    background-color: transparent;
    padding: 0;
}

.markdown-body table {
    width: 100%;
    margin-bottom: 1rem;
    border-collapse: collapse;
}

.markdown-body table th,
.markdown-body table td {
    padding: 0.5rem;
    border: 1px solid var(--bs-border-color);
}

/* Copy code block button */
/* Code block action buttons */
.code-block-wrapper {
    position: relative;
}

.code-action-buttons {
    position: absolute;
    top: 8px;
    right: 8px;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    z-index: 10;
}

.btn-copy-code,
.btn-preview-code {
    padding: 3px 10px;
    font-size: 0.73rem;
    font-weight: 500;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
    display: inline-flex;
    align-items: center;
    gap: 4px;
    line-height: 1.3;
    text-decoration: none;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.15);
}

.btn-preview-code {
    background: rgba(13, 110, 253, 0.25);
    color: #9ec5fe;
    border: 1px solid rgba(13, 110, 253, 0.45);
}

.btn-preview-code:hover {
    background: rgba(13, 110, 253, 0.85);
    color: #ffffff;
    border-color: rgba(13, 110, 253, 1);
    transform: translateY(-1px);
    box-shadow: 0 4px 10px rgba(13, 110, 253, 0.35);
}

.btn-copy-code {
    background: rgba(255, 255, 255, 0.12);
    color: #e0e0e0;
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.btn-copy-code:hover {
    background: rgba(255, 255, 255, 0.25);
    color: #ffffff;
    border-color: rgba(255, 255, 255, 0.4);
    transform: translateY(-1px);
}

/* ==========================================
   Web Preview Side Panel & Desktop Fullscreen
   ========================================== */
.web-preview-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    z-index: 1040;
    transition: opacity 0.25s ease;
}

.web-preview-drawer {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: 480px;
    max-width: 100vw;
    height: 100vh;
    background-color: var(--bs-body-bg);
    border-left: 1px solid var(--bs-border-color);
    box-shadow: -10px 0 40px rgba(0, 0, 0, 0.45);
    display: flex;
    flex-direction: column;
    z-index: 1050;
    transform: translateX(100%);
    transition: transform 0.32s cubic-bezier(0.16, 1, 0.3, 1), width 0.32s cubic-bezier(0.16, 1, 0.3, 1), left 0.32s cubic-bezier(0.16, 1, 0.3, 1);
}

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

/* Fullscreen Web Desktop Mode */
.web-preview-drawer.fullscreen-mode {
    width: 100vw !important;
    max-width: 100vw !important;
    left: 0 !important;
    right: 0 !important;
    border-left: none;
}

.preview-header {
    height: 52px;
    flex-shrink: 0;
}

.preview-viewport-body {
    background: repeating-linear-gradient(
        45deg,
        rgba(125, 125, 125, 0.05),
        rgba(125, 125, 125, 0.05) 10px,
        rgba(255, 255, 255, 0.02) 10px,
        rgba(255, 255, 255, 0.02) 20px
    );
    background-color: var(--bs-tertiary-bg);
}

/* Device Mockup Frame */
.preview-device-frame {
    display: flex;
    flex-direction: column;
    background: #000;
    transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    position: relative;
}

/* Mobile size mode (~390px iPhone/Android standard) */
.preview-device-frame.mobile-mode {
    width: 390px;
    max-width: 100%;
    height: 94%;
    max-height: 820px;
    border-radius: 40px;
    border: 9px solid #1a1c20;
    box-shadow: 0 25px 60px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(255, 255, 255, 0.12);
    overflow: hidden;
}

.preview-device-frame.mobile-mode .device-status-bar {
    display: flex !important;
    flex-shrink: 0;
}

/* Web Desktop Fullscreen mode */
.preview-device-frame.desktop-mode {
    width: 100% !important;
    height: 100% !important;
    border-radius: 0 !important;
    border: none !important;
    box-shadow: none !important;
    max-height: none !important;
}

.preview-device-frame.desktop-mode .device-status-bar {
    display: none !important;
}

.preview-iframe {
    width: 100%;
    height: 100%;
    display: block;
    background-color: #ffffff;
}

/* Typing cursor indicator */
.typing-cursor::after {
    content: "▋";
    display: inline-block;
    vertical-align: baseline;
    color: var(--bs-primary);
    animation: blink 0.8s infinite;
    margin-left: 2px;
}

@keyframes blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0; }
}

/* Prompt suggestions hover */
.prompt-suggestion {
    transition: transform 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}

.prompt-suggestion:hover {
    transform: translateY(-2px);
    border-color: var(--bs-primary) !important;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

/* Custom Scrollbar */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

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

::-webkit-scrollbar-thumb {
    background: rgba(125, 125, 125, 0.25);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(125, 125, 125, 0.45);
}

/* PDF Export Button & Styling */
.btn-pdf-msg {
    color: #dc3545 !important;
    opacity: 0.85;
    transition: opacity 0.15s ease, transform 0.15s ease;
}

.btn-pdf-msg:hover {
    opacity: 1;
    transform: translateY(-1px);
    text-decoration: none !important;
}

/* Printable PDF Document Wrapper */
.pdf-export-document {
    background-color: #ffffff;
    color: #1a202c;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 11pt;
    line-height: 1.6;
    padding: 24px;
    max-width: 800px;
    margin: 0 auto;
}

.pdf-export-header {
    border-bottom: 2px solid #0d6efd;
    padding-bottom: 12px;
    margin-bottom: 20px;
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
}

.pdf-export-header .brand-title {
    font-size: 16pt;
    font-weight: 700;
    color: #0d6efd;
    margin: 0;
}

.pdf-export-header .brand-sub {
    font-size: 9pt;
    color: #64748b;
    margin: 0;
}

.pdf-export-header .doc-meta {
    font-size: 9pt;
    color: #64748b;
    text-align: right;
}

.pdf-export-body h1, .pdf-export-body h2, .pdf-export-body h3, .pdf-export-body h4 {
    color: #0f172a;
    font-weight: 700;
    margin-top: 18px;
    margin-bottom: 10px;
    page-break-after: avoid;
}

.pdf-export-body h1 { font-size: 16pt; border-bottom: 1px solid #e2e8f0; padding-bottom: 6px; }
.pdf-export-body h2 { font-size: 14pt; }
.pdf-export-body h3 { font-size: 12pt; }

.pdf-export-body p {
    margin-bottom: 10px;
}

.pdf-export-body table {
    width: 100%;
    border-collapse: collapse;
    margin: 15px 0;
    page-break-inside: avoid;
}

.pdf-export-body table th,
.pdf-export-body table td {
    border: 1px solid #cbd5e1;
    padding: 8px 10px;
    font-size: 10pt;
    text-align: left;
}

.pdf-export-body table th {
    background-color: #f1f5f9;
    font-weight: 600;
    color: #1e293b;
}

.pdf-export-body pre {
    background-color: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    padding: 12px;
    font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace;
    font-size: 9.5pt;
    page-break-inside: avoid;
    overflow-x: auto;
}

.pdf-export-body blockquote {
    border-left: 4px solid #0d6efd;
    padding-left: 12px;
    margin-left: 0;
    color: #475569;
    font-style: italic;
}

.pdf-export-footer {
    border-top: 1px solid #e2e8f0;
    margin-top: 30px;
    padding-top: 12px;
    font-size: 8.5pt;
    color: #94a3b8;
    display: flex;
    justify-content: space-between;
}

@media print {
    body * {
        visibility: hidden;
    }
    .pdf-printable-section, .pdf-printable-section * {
        visibility: visible;
    }
    .pdf-printable-section {
        position: absolute;
        left: 0;
        top: 0;
        width: 100%;
    }
}

/* ========================================================
   ChatGPT Style Pill Input Bar & Attachments (+)
======================================================== */
.chat-pill-form {
    border-radius: 28px;
    background-color: var(--bs-tertiary-bg);
    border: 1px solid var(--bs-border-color);
    padding: 4px 8px;
    transition: border-color 0.2s ease, box-shadow 0.2s ease, border-radius 0.2s ease;
}

.chat-pill-form:focus-within {
    border-color: var(--bs-primary);
    box-shadow: 0 0 0 3px rgba(13, 110, 253, 0.12) !important;
}

.chat-pill-textarea {
    font-size: 0.95rem;
    line-height: 1.5;
    color: var(--bs-body-color);
    outline: none !important;
}

.chat-pill-textarea::placeholder {
    color: var(--bs-secondary-color);
    opacity: 0.75;
}

.btn-attach {
    width: 36px;
    height: 36px;
    min-width: 36px;
    border-radius: 50%;
    color: var(--bs-body-color);
    opacity: 0.75;
    text-decoration: none !important;
    transition: all 0.15s ease;
}

.btn-attach:hover {
    opacity: 1;
    background-color: rgba(125, 125, 125, 0.15);
    transform: scale(1.05);
}

.btn-mic {
    width: 34px;
    height: 34px;
    min-width: 34px;
    border-radius: 50%;
    color: var(--bs-secondary-color);
    text-decoration: none !important;
    transition: all 0.15s ease;
}

.btn-mic:hover {
    color: var(--bs-body-color);
    background-color: rgba(125, 125, 125, 0.15);
}

.btn-mic.recording {
    color: #dc3545 !important;
    animation: mic-pulse 1s infinite alternate;
}

@keyframes mic-pulse {
    0% { transform: scale(1); opacity: 1; }
    100% { transform: scale(1.15); opacity: 0.7; }
}

.btn-chat-send {
    width: 34px;
    height: 34px;
    min-width: 34px;
    border-radius: 50%;
    transition: transform 0.15s ease, background-color 0.15s ease;
}

.btn-chat-send:hover {
    transform: scale(1.06);
}

/* Attachment Tray & Chips */
.attachment-tray {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 8px 10px 4px 10px;
    border-bottom: 1px solid var(--bs-border-color-translucent);
    margin-bottom: 4px;
}

.attachment-chip {
    display: inline-flex;
    align-items: center;
    background-color: rgba(125, 125, 125, 0.1);
    border: 1px solid var(--bs-border-color);
    border-radius: 16px;
    padding: 4px 10px;
    font-size: 0.8rem;
    max-width: 260px;
}

.attachment-chip .chip-name {
    max-width: 140px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.attachment-chip .chip-thumb {
    width: 22px;
    height: 22px;
    border-radius: 4px;
    object-fit: cover;
}

.attachment-chip .btn-remove-chip {
    background: none;
    border: none;
    padding: 0;
    margin-left: 6px;
    color: var(--bs-secondary-color);
    cursor: pointer;
    font-size: 1rem;
    line-height: 1;
    display: flex;
    align-items: center;
    opacity: 0.65;
    transition: opacity 0.15s ease, color 0.15s ease;
}

.attachment-chip .btn-remove-chip:hover {
    opacity: 1;
    color: #dc3545;
}

/* Attached Image in Message Bubble */
.chat-attached-image {
    max-width: 280px;
    max-height: 220px;
    border-radius: 12px;
    object-fit: cover;
    border: 1px solid rgba(0, 0, 0, 0.1);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    cursor: pointer;
    transition: transform 0.15s ease;
}

.chat-attached-image:hover {
    transform: scale(1.02);
}

.chat-doc-attachment-badge {
    display: inline-flex;
    align-items: center;
    background: rgba(13, 110, 253, 0.1);
    border: 1px solid rgba(13, 110, 253, 0.2);
    border-radius: 8px;
    padding: 6px 12px;
    font-size: 0.85rem;
    margin-bottom: 8px;
}

/* ==========================================
   PWA & Mobile Responsive Optimizations
   ========================================== */

/* iOS & Android Notch / Dynamic Island Safe Area insets */
@supports (padding: env(safe-area-inset-bottom)) {
    body {
        padding-top: env(safe-area-inset-top);
        padding-bottom: env(safe-area-inset-bottom);
        padding-left: env(safe-area-inset-left);
        padding-right: env(safe-area-inset-right);
    }

    .chat-pill-bar {
        padding-bottom: max(0.5rem, env(safe-area-inset-bottom)) !important;
    }
}

/* Standalone PWA adjustments */
@media all and (display-mode: standalone) {
    /* Hide unnecessary web-only clutter when launched as an installed app */
    .pwa-only {
        display: block !important;
    }
    .pwa-hide {
        display: none !important;
    }
}

/* Mobile Touch & Viewport Tuning */
@media (max-width: 767.98px) {
    .btn-attach, .btn-send-pill {
        width: 38px;
        height: 38px;
    }

    .chat-pill-box {
        padding: 0.4rem 0.6rem !important;
    }

    .message-bubble {
        max-width: 92% !important;
        font-size: 0.95rem;
    }

    .sidebar {
        width: 82vw !important;
        max-width: 320px !important;
    }
}

/* Floating PWA Install Banner */
.pwa-install-banner {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%) translateY(120px);
    z-index: 1060;
    max-width: 420px;
    width: calc(100% - 32px);
    background: var(--bs-body-bg);
    border: 1px solid var(--bs-border-color-translucent);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
    border-radius: 16px;
    padding: 14px 16px;
    transition: transform 0.35s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    backdrop-filter: blur(12px);
}

.pwa-install-banner.show {
    transform: translateX(-50%) translateY(0);
}


