/* Mobile Safe Area & Fixed Viewport */
html {
    height: 100%;
    height: -webkit-fill-available;
}

body {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: 100%;
    height: 100vh;
    height: 100dvh;
    height: -webkit-fill-available;
    margin: 0;
    padding: 0;
    overflow: hidden;
}

#app {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    display: flex;
}

/* Scroll Container Settings */
#messagesContainer {
    flex: 1 1 0%;
    min-height: 0;
    overflow-y: auto !important;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-y;
    overscroll-behavior-y: contain;
}

/* Safe Area Inset for Bottom Input Bar */
.bottom-bar {
    padding-bottom: max(0.75rem, env(safe-area-inset-bottom, 0.75rem)) !important;
}

/* Custom Scrollbars */
::-webkit-scrollbar {
    width: 5px;
    height: 5px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: rgba(100, 116, 139, 0.3);
    border-radius: 9999px;
}
::-webkit-scrollbar-thumb:hover {
    background: rgba(100, 116, 139, 0.5);
}

/* Thinking Box Animation & Styling */
.thinking-box {
    border-left: 3px solid #6366f1;
    background: linear-gradient(to right, rgba(99, 102, 241, 0.05), transparent);
}

.thinking-pulse {
    animation: thinking-glow 2s infinite ease-in-out;
}

@keyframes thinking-glow {
    0%, 100% { opacity: 0.6; }
    50% { opacity: 1; }
}

/* Tool Execution Box */
.tool-box {
    border-left: 3px solid #0ea5e9;
    background: rgba(15, 23, 42, 0.6);
}

/* Markdown Typography */
.prose-custom {
    color: #e2e8f0;
    line-height: 1.7;
    font-size: 0.925rem;
}
.prose-custom p {
    margin-bottom: 0.75rem;
}
.prose-custom p:last-child {
    margin-bottom: 0;
}
.prose-custom h1, .prose-custom h2, .prose-custom h3 {
    color: #ffffff;
    font-weight: 600;
    margin-top: 1.25rem;
    margin-bottom: 0.5rem;
}
.prose-custom h1 { font-size: 1.25rem; }
.prose-custom h2 { font-size: 1.1rem; }
.prose-custom h3 { font-size: 1.0rem; }

.prose-custom ul {
    list-style-type: disc;
    padding-left: 1.25rem;
    margin-bottom: 0.75rem;
}
.prose-custom ol {
    list-style-type: decimal;
    padding-left: 1.25rem;
    margin-bottom: 0.75rem;
}
.prose-custom li {
    margin-bottom: 0.25rem;
}
.prose-custom blockquote {
    border-left: 3px solid #475569;
    padding-left: 0.75rem;
    color: #94a3b8;
    margin: 0.75rem 0;
    font-style: italic;
}
.prose-custom code:not(pre code) {
    background: rgba(30, 41, 59, 0.8);
    color: #38bdf8;
    padding: 0.15rem 0.35rem;
    border-radius: 0.375rem;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    font-size: 0.85em;
    border: 1px solid rgba(51, 65, 85, 0.6);
}
.prose-custom pre {
    position: relative;
    background: #0f172a !important;
    border: 1px solid #1e293b;
    border-radius: 0.75rem;
    padding: 1rem;
    margin: 0.75rem 0;
    overflow-x: auto;
}
.prose-custom pre code {
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    font-size: 0.85rem;
    line-height: 1.5;
}

.prose-custom table {
    width: 100%;
    border-collapse: collapse;
    margin: 0.75rem 0;
    font-size: 0.85rem;
}
.prose-custom th, .prose-custom td {
    border: 1px solid #334155;
    padding: 0.5rem 0.75rem;
    text-align: left;
}
.prose-custom th {
    background: rgba(30, 41, 59, 0.7);
    color: #f8fafc;
}

/* Copy button for code blocks */
.copy-btn {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    background: rgba(30, 41, 59, 0.8);
    border: 1px solid rgba(51, 65, 85, 0.8);
    color: #94a3b8;
    font-size: 0.75rem;
    padding: 0.2rem 0.5rem;
    border-radius: 0.375rem;
    cursor: pointer;
    transition: all 0.2s;
}
.copy-btn:hover {
    background: #334155;
    color: #ffffff;
}

/* Scroll-to-bottom floating button */
#scrollBottomBtn {
    position: absolute;
    bottom: calc(85px + env(safe-area-inset-bottom, 0px));
    right: 20px;
    z-index: 25;
    transition: all 0.2s ease-in-out;
}

/* KaTeX equations styling */
.katex-display-wrapper {
    margin: 0.85rem 0;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 0.5rem 0;
    text-align: center;
}
.katex-display {
    margin: 0 !important;
}
.katex {
    font-size: 1.05em;
    color: #f1f5f9;
}
.katex-error {
    color: #f87171;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    font-size: 0.9em;
    background: rgba(248, 113, 113, 0.1);
    padding: 0.1rem 0.35rem;
    border-radius: 0.25rem;
    border: 1px solid rgba(248, 113, 113, 0.2);
}
