/* ========================================
   JB Document Engine — Neo-Minimalism Dark
   ======================================== */
:root {
    /* Color Palette */
    --bg-base: #0A0A0E;
    --bg-surface: #12121A;
    --bg-surface-raised: #1A1A24;
    --bg-surface-glass: rgba(18, 18, 26, 0.7);

    --accent-glow: #6c5ce7;
    --accent: #8b7af0;
    --accent-hover: #a29bfe;
    --accent-transparent: rgba(108, 92, 231, 0.15);

    --text-primary: #FFFFFF;
    --text-secondary: #8E8E9F;
    --text-tertiary: #5C5C6B;

    --border-light: rgba(255, 255, 255, 0.05);
    --border-focus: rgba(139, 122, 240, 0.5);

    --error: #ff4757;
    --warning: #ffa502;
    --success: #2ed573;

    /* Typography */
    --font-heading: 'Outfit', -apple-system, sans-serif;
    --font-body: 'Inter', -apple-system, sans-serif;

    /* Layout */
    --sidebar-width: 280px;
    --content-max-width: 800px;

    /* Specs */
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 24px;

    --shadow-glow: 0 0 24px rgba(108, 92, 231, 0.15);
    --shadow-surface: 0 8px 32px rgba(0, 0, 0, 0.4);

    --transition-fast: 0.15s ease-out;
    --transition-smooth: 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

/* Reset */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    background-color: var(--bg-base);
    color: var(--text-primary);
    font-family: var(--font-body);
    font-size: 15px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    height: 100vh;
    overflow: hidden;
}

/* Layout */
.app-container {
    display: flex;
    height: 100vh;
    width: 100vw;
}

/* Mobile Header */
.mobile-header {
    display: none;
    height: 60px;
    padding: 0 16px;
    align-items: center;
    justify-content: space-between;
    background: var(--bg-surface-glass);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border-light);
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 40;
}

/* Logo */
.logo {
    display: flex;
    align-items: center;
}

.nav-logo {
    height: 32px;
    width: auto;
    object-fit: contain;
}

.sidebar {
    width: var(--sidebar-width);
    height: 100%;
    background: var(--bg-surface);
    border-right: 1px solid var(--border-light);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    z-index: 105;
    transition: transform var(--transition-smooth);
}

.sidebar-header {
    height: 80px;
    padding: 0 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.close-menu-btn {
    display: none;
}

.sidebar-content {
    flex: 1;
    padding: 0 20px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 32px;
}

/* New Doc Button */
.new-doc-btn {
    width: 100%;
    padding: 14px;
    background: var(--bg-surface-raised);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-family: var(--font-heading);
    font-weight: 500;
    font-size: 15px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    transition: all var(--transition-fast);
}

.new-doc-btn:hover {
    background: var(--accent-transparent);
    border-color: var(--border-focus);
    color: var(--accent);
}

/* History */
.section-title {
    font-family: var(--font-heading);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-tertiary);
    margin-bottom: 16px;
    padding-left: 4px;
}

.history-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.history-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px;
    border-radius: var(--radius-sm);
    transition: background var(--transition-fast);
    cursor: pointer;
}

.history-item:hover {
    background: var(--bg-surface-raised);
}

.history-item:hover .history-actions {
    opacity: 1;
}

.history-item-content {
    flex: 1;
    min-width: 0;
}

.history-title {
    font-size: 14px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 4px;
}

.history-date {
    font-size: 12px;
    color: var(--text-tertiary);
}

.history-actions {
    display: flex;
    gap: 4px;
    opacity: 0;
    transition: opacity var(--transition-fast);
}

@media (max-width: 768px) {
    .history-actions {
        opacity: 1;
        /* Always visible on mobile */
    }
}

.history-loading {
    font-size: 13px;
    color: var(--text-tertiary);
    text-align: center;
    padding: 24px 0;
}

.sidebar-footer {
    padding: 20px 24px;
    border-top: 1px solid var(--border-light);
}

/* Status Indicator */
.status-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    color: var(--text-secondary);
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--success);
    box-shadow: 0 0 10px var(--success);
}

/* Main Content area */
.main-content {
    flex: 1;
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.chat-area {
    flex: 1;
    width: 100%;
    max-width: var(--content-max-width);
    overflow-y: auto;
    padding: 40px 24px 160px;
    display: flex;
    flex-direction: column;
    scrollbar-width: thin;
    scrollbar-color: var(--bg-surface-raised) transparent;
}

.chat-area::-webkit-scrollbar {
    width: 6px;
}

.chat-area::-webkit-scrollbar-thumb {
    background: var(--bg-surface-raised);
    border-radius: var(--radius-sm);
}

/* Empty State centering */
body.empty-state .chat-area {
    justify-content: center;
    padding-bottom: 0;
}

body.empty-state .welcome-screen {
    display: block;
    text-align: center;
    margin-bottom: 40px;
    transform: translateY(-40px);
}

.welcome-screen {
    display: none;
    animation: fadeUp 0.8s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

.hero-logo {
    height: 48px;
    width: auto;
    object-fit: contain;
    margin-bottom: 16px;
    filter: drop-shadow(0 0 20px rgba(255, 255, 255, 0.1));
}

.welcome-screen p {
    color: var(--text-secondary);
    font-size: 16px;
}

/* Messages */
.messages-container {
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.message {
    display: flex;
    gap: 16px;
    animation: fadeUp 0.4s ease-out forwards;
}

.message-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-surface-raised);
    flex-shrink: 0;
    font-size: 14px;
}

.message.system .message-avatar {
    background: var(--accent-transparent);
    color: white;
}

.message-content {
    background: var(--bg-surface);
    border: 1px solid var(--border-light);
    padding: 16px 20px;
    border-radius: var(--radius-lg);
    border-top-left-radius: 4px;
    font-size: 15px;
    color: var(--text-primary);
    max-width: 90%;
    line-height: 1.6;
}

.message-content p {
    margin-bottom: 8px;
}

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

.message.user .message-content {
    background: var(--bg-surface-raised);
    border-top-left-radius: var(--radius-lg);
    border-top-right-radius: 4px;
}

.message.user {
    flex-direction: row-reverse;
}

.message a.doc-link {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    margin-top: 12px;
    padding: 10px 16px;
    background: rgba(46, 213, 115, 0.1);
    border: 1px solid rgba(46, 213, 115, 0.2);
    border-radius: var(--radius-sm);
    color: var(--success);
    text-decoration: none;
    font-weight: 500;
    transition: all var(--transition-fast);
}

.message a.doc-link:hover {
    background: rgba(46, 213, 115, 0.15);
}

/* Fixed Input Area */
.input-container {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 32px 24px;
    display: flex;
    flex-direction: column;
    align-items: center;
    background: linear-gradient(to top, var(--bg-base) 60%, transparent);
    z-index: 20;
    transition: transform 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

body.empty-state .input-container {
    position: relative;
    padding: 0;
    background: none;
    transform: translateY(-40px);
}

.input-wrapper {
    position: relative;
    width: 100%;
    max-width: 800px;
    background: var(--bg-surface);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-xl);
    padding: 12px 16px;
    display: flex;
    align-items: flex-end;
    gap: 12px;
    box-shadow: var(--shadow-surface);
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.input-wrapper:focus-within {
    border-color: var(--border-focus);
    box-shadow: 0 0 0 1px var(--border-focus), var(--shadow-glow);
}

.attach-btn,
.send-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition-fast);
    flex-shrink: 0;
}

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

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

.send-btn:hover:not(:disabled) {
    background: var(--accent-hover);
    transform: scale(1.05);
}

.send-btn:disabled {
    opacity: 0.5;
    background: var(--bg-surface-raised);
    color: var(--text-tertiary);
    transform: none;
    cursor: not-allowed;
}

textarea#messageInput {
    flex: 1;
    background: transparent;
    border: none;
    outline: none;
    color: var(--text-primary);
    font-family: var(--font-body);
    font-size: 15px;
    line-height: 1.5;
    resize: none;
    padding: 10px 0;
    min-height: 48px;
    max-height: 200px;
    scrollbar-width: none;
}

textarea#messageInput::-webkit-scrollbar {
    display: none;
}

textarea#messageInput::placeholder {
    color: var(--text-tertiary);
}

.input-hint {
    margin-top: 12px;
    font-size: 12px;
    color: var(--text-tertiary);
}

body.empty-state .input-hint {
    display: none;
}

/* Image Previews */
.image-previews {
    display: flex;
    gap: 8px;
    margin-top: 12px;
    max-width: 800px;
    width: 100%;
    overflow-x: auto;
}

.image-preview-item {
    position: relative;
    width: 60px;
    height: 60px;
    border-radius: var(--radius-sm);
    overflow: hidden;
    flex-shrink: 0;
}

.image-preview-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.remove-image {
    position: absolute;
    top: 2px;
    right: 2px;
    width: 18px;
    height: 18px;
    background: rgba(0, 0, 0, 0.6);
    color: white;
    border-radius: 50%;
    border: none;
    font-size: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

/* Icon Buttons */
.icon-btn {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition-fast);
}

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

/* Bottom Sheet */
.sheet-overlay,
.drawer-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    z-index: 100;
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--transition-smooth);
}

.sheet-overlay.active,
.drawer-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

.bottom-sheet {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--bg-surface);
    border-top: 1px solid var(--border-light);
    border-top-left-radius: var(--radius-xl);
    border-top-right-radius: var(--radius-xl);
    z-index: 110;
    transform: translateY(100%);
    transition: transform var(--transition-smooth);
    display: flex;
    flex-direction: column;
    max-height: 90vh;
    box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.5);
}

.bottom-sheet.active {
    transform: translateY(0);
}

.sheet-handle {
    width: 40px;
    height: 4px;
    background: var(--border-light);
    border-radius: 2px;
    margin: 12px auto;
}

.sheet-header {
    padding: 0 24px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--border-light);
}

.sheet-header h2 {
    font-family: var(--font-heading);
    font-size: 20px;
    font-weight: 500;
}

.sheet-body {
    padding: 24px;
    overflow-y: auto;
    flex: 1;
}

.sheet-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--border-light);
    display: flex;
    gap: 12px;
    justify-content: flex-end;
}

/* Inputs in Sheet (Floating Label Style) */
.var-group {
    margin-bottom: 24px;
}

.var-group-title {
    font-size: 13px;
    text-transform: uppercase;
    color: var(--accent);
    letter-spacing: 1px;
    margin-bottom: 16px;
    font-family: var(--font-heading);
}

.var-field {
    position: relative;
    margin-bottom: 16px;
}

.var-input {
    width: 100%;
    background: var(--bg-surface-raised);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-md);
    padding: 22px 16px 8px;
    color: var(--text-primary);
    font-size: 15px;
    font-family: var(--font-body);
    transition: all var(--transition-fast);
}

.var-input:focus {
    border-color: var(--border-focus);
    outline: none;
    box-shadow: 0 0 0 1px var(--border-focus);
}

.var-label {
    position: absolute;
    left: 17px;
    top: 15px;
    color: var(--text-tertiary);
    font-size: 15px;
    pointer-events: none;
    transition: all var(--transition-fast);
}

.var-input:focus~.var-label,
.var-input:not(:placeholder-shown)~.var-label {
    top: 6px;
    font-size: 11px;
    color: var(--accent);
}

.var-input.empty {
    border-color: rgba(255, 165, 2, 0.4);
    background: rgba(255, 165, 2, 0.05);
}

.missing-warning {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    background: rgba(255, 165, 2, 0.1);
    border-left: 3px solid var(--warning);
    border-radius: var(--radius-sm);
    color: var(--warning);
    margin-bottom: 24px;
    font-size: 14px;
}

/* Buttons */
.btn {
    padding: 12px 24px;
    border-radius: var(--radius-md);
    font-family: var(--font-heading);
    font-weight: 500;
    font-size: 15px;
    cursor: pointer;
    transition: all var(--transition-fast);
    border: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.btn-primary {
    background: var(--accent);
    color: #FFF;
}

.btn-primary:hover:not(:disabled) {
    background: var(--accent-hover);
    box-shadow: var(--shadow-glow);
}

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

.btn-outline {
    background: transparent;
    border: 1px solid var(--border-light);
    color: var(--text-primary);
}

.btn-outline:hover {
    background: var(--bg-surface-raised);
}

/* Loading animations */
.loading-dots {
    display: flex;
    gap: 4px;
    padding: 4px 0;
}

.loading-dots span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--text-tertiary);
    animation: dotBounce 1.4s infinite ease-in-out;
}

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

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

@keyframes dotBounce {

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

    30% {
        transform: translateY(-4px);
        opacity: 1;
        background: var(--accent);
    }
}

@keyframes fadeUp {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Spinner */
.spinner {
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    display: inline-block;
}

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

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

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

    .mobile-header {
        display: flex;
    }

    .close-menu-btn {
        display: flex;
    }

    .chat-area {
        padding-top: 100px;
        padding-bottom: 120px;
    }

    body.empty-state .chat-area {
        padding-top: 60px;
    }

    .input-wrapper {
        border-radius: var(--radius-lg);
        max-width: 100%;
    }

    .input-container {
        padding: 16px;
        background: var(--bg-surface);
        border-top: 1px solid var(--border-light);
    }

    .bottom-sheet {
        border-radius: 0;
        border-top-left-radius: var(--radius-xl);
        border-top-right-radius: var(--radius-xl);
    }
}

/* Desktop Bottom Sheet (centered modal variant) */
@media (min-width: 769px) {
    .new-doc-btn {
        display: none;
    }

    .bottom-sheet {
        top: 50%;
        left: 50%;
        bottom: auto;
        right: auto;
        transform: translate(-50%, -50%) scale(0.95);
        opacity: 0;
        pointer-events: none;
        width: 600px;
        border-radius: var(--radius-xl);
        border: 1px solid var(--border-light);
        box-shadow: var(--shadow-surface), 0 0 100px rgba(0, 0, 0, 0.8);
    }

    .bottom-sheet.active {
        transform: translate(-50%, -50%) scale(1);
        opacity: 1;
        pointer-events: auto;
    }

    .sheet-handle {
        display: none;
    }
}