@import url('https://fonts.googleapis.com/css2?family=Lora:ital,wght@0,400;0,600;1,400&family=Mulish:wght@300;400;600;800&family=JetBrains+Mono:wght@400;500&display=swap');

:root {
    --bg-color: #1a1a1c;
    --surface-color: #252529;
    --primary-color: #d4b693;
    --secondary-color: #e4e4e7;
    --accent-color: #c084fc;
}

body {
    font-family: 'Mulish', sans-serif;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

h1, h2, h3, h4, h5, h6, .font-serif {
    font-family: 'Lora', serif;
}

code, pre, .font-mono {
    font-family: 'JetBrains Mono', monospace;
}

/* Smooth Transitions - Only for interactive elements (performance fix) */
button, a, input, select, textarea, .btn, .tab-btn, .nav-btn, .card, .modal, .toast, [role="button"] {
    transition-property: background-color, border-color, color, fill, stroke, opacity, box-shadow, transform;
    transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
    transition-duration: 150ms;
}

/* Custom Scrollbar - Minimal */
.custom-scrollbar::-webkit-scrollbar {
    width: 4px;
    height: 4px;
}
.custom-scrollbar::-webkit-scrollbar-track {
    background: transparent;
}
.custom-scrollbar::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 10px;
}
.custom-scrollbar::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* Chat Interface - Pi Style */
.message-bubble {
    max-width: 85%;
    padding: 1.25rem 1.5rem;
    position: relative;
    font-size: 0.95rem;
    line-height: 1.7;
    border-radius: 1.5rem; /* Fully rounded corners */
    margin-bottom: 1.5rem; /* Consistent vertical spacing */
}

@media (min-width: 768px) {
    .message-bubble {
        max-width: 75%;
    }
}

.user-message {
    background: #3f3f46; /* Zinc 700 */
    color: #f4f4f5;
    margin-left: auto;
}

.bot-message {
    background: transparent;
    color: #e4e4e7;
    padding-left: 0;
    padding-right: 0;
    margin-bottom: 1.5rem;
}

.bot-bubble {
    background: #27272a; /* Zinc 800 */
    color: #e4e4e7;
    border-radius: 1.5rem; /* Fully rounded corners */
    padding: 1.25rem 1.5rem;
    border: 1px solid rgba(255, 255, 255, 0.05);
    margin-right: auto;
    max-width: 85%;
    margin-bottom: 1.5rem;
}

@media (min-width: 768px) {
    .bot-bubble {
        max-width: 75%;
    }
}

/* Markdown Styling (Softer) */
.prose h1, .prose h2, .prose h3 {
    font-family: 'Lora', serif;
    color: #f4f4f5;
    font-weight: 600;
    margin-top: 1.5rem;
    margin-bottom: 0.5rem;
}
.prose p {
    margin-bottom: 0.75rem;
    font-weight: 300;
}
.prose strong {
    color: #d4b693; /* Primary Gold */
    font-weight: 600;
}
.prose code {
    background: rgba(255, 255, 255, 0.05);
    padding: 0.2em 0.4em;
    border-radius: 6px;
    font-size: 0.85em;
    color: #d4b693;
    font-family: 'JetBrains Mono', monospace;
}
.prose pre {
    background: #18181b;
    padding: 1rem;
    border-radius: 1rem;
    border: 1px solid rgba(255,255,255,0.05);
    overflow-x: auto;
    margin-top: 0.5rem;
    margin-bottom: 0.5rem;
}
.prose ul {
    list-style-type: none;
    padding-left: 0;
}
.prose ul li {
    position: relative;
    padding-left: 1.25rem;
    margin-bottom: 0.5rem;
}
.prose ul li::before {
    content: '•';
    position: absolute;
    left: 0;
    color: #d4b693;
}

/* Animations */
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translate3d(0, 20px, 0);
    }
    to {
        opacity: 1;
        transform: translate3d(0, 0, 0);
    }
}
.animate-fade-in-up {
    animation: fadeInUp 0.6s cubic-bezier(0.2, 0.8, 0.2, 1) forwards;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}
.animate-fade-in {
    animation: fadeIn 0.4s ease-out forwards;
}

/* Typing Indicator (Pulse) */
.typing-indicator {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 8px 16px;
    background: rgba(255, 255, 255, 0.03);
    border-radius: 20px;
}
.typing-dots span {
    width: 6px;
    height: 6px;
    background: #d4b693;
    border-radius: 50%;
    animation: typing 1.4s infinite ease-in-out both;
}
.typing-dots span:nth-child(1) { animation-delay: -0.32s; }
.typing-dots span:nth-child(2) { animation-delay: -0.16s; }
@keyframes typing {
    0%, 80%, 100% { transform: scale(0); opacity: 0.3; }
    40% { transform: scale(1); opacity: 1; }
}

/* Table Styling (Clean) */
table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
}
th {
    font-family: 'Mulish', sans-serif;
    font-weight: 800;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #b8b8bc;
    padding: 16px;
    text-align: left;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}
td {
    padding: 16px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.02);
    color: #e4e4e7;
    font-size: 0.9rem;
}
tr:last-child td {
    border-bottom: none;
}

/* Range Input for Settings */
input[type=range] {
    -webkit-appearance: none; 
    background: transparent; 
}
input[type=range]::-webkit-slider-thumb {
    -webkit-appearance: none;
}
input[type=range]:focus {
    outline: none;
}

/* Starred Section (Favorites) */
.starred-section summary {
    list-style: none;
}

.starred-section summary::-webkit-details-marker {
    display: none;
}

.starred-section .starred-chevron {
    transition: transform 0.2s ease;
}

.starred-section[open] .starred-chevron {
    transform: rotate(90deg);
}

.starred-list {
    animation: fadeIn 0.2s ease;
}

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

/* Process Container (Analysis Steps) */
.process-container {
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 1.25rem; /* Softer corners */
    overflow: hidden;
}

.process-container summary {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    cursor: pointer;
    font-size: 0.8rem;
    color: #b8b8bc;
    font-family: 'Mulish', sans-serif;
    transition: all 0.2s;
    list-style: none;
}

.process-container summary::-webkit-details-marker {
    display: none;
}

.process-container summary:hover {
    color: #e4e4e7;
    background: rgba(255, 255, 255, 0.03);
}

.process-container summary .chevron {
    transition: transform 0.2s;
}

.process-container[open] summary .chevron {
    transform: rotate(90deg);
}

.process-content {
    padding: 1rem;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
    font-size: 0.85rem;
    color: #d4d4d8;
    background: rgba(0, 0, 0, 0.2);
    max-height: 300px;
    overflow-y: auto;
}

.process-step-item {
    color: #b8b8bc;
    font-size: 0.85rem;
}

/* Result Container */
.result-container {
    margin-top: 1.5rem; /* Distinct separation */
}

/* Prose: Table inside chat bubble */
.prose .table-wrapper {
    overflow-x: auto;
    margin: 1rem 0;
    border-radius: 0.75rem;
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-left: 3px solid rgba(212, 182, 147, 0.55);
    background: rgba(255, 255, 255, 0.03);
}
.prose table {
    width: 100%;
    min-width: 240px;
    border-collapse: collapse;
    font-size: 0.85rem;
    background: transparent;
    border: none;
    border-radius: 0;
    margin: 0;
}
.prose th {
    background: rgba(212, 182, 147, 0.1);
    padding: 10px 16px;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    color: #b8b8bc;
    white-space: nowrap;
    text-align: left;
}
.prose td {
    padding: 10px 16px;
    font-size: 0.85rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}
/* 第一欄（標籤欄）較暗 */
.prose td:first-child, .prose th:first-child {
    color: #b8b8bc;
    font-size: 0.8rem;
}
/* 第二欄（數值欄）醒目 */
.prose td:last-child {
    color: #f4f4f5;
    font-weight: 600;
}
.prose tr:last-child td {
    border-bottom: none;
}
.prose tr:hover td {
    background: rgba(255, 255, 255, 0.04);
}

/* Prose: Ordered list inside chat bubble */
.prose ol {
    list-style: none;
    padding-left: 0;
    counter-reset: prose-counter;
}
.prose ol li {
    position: relative;
    padding-left: 2rem;
    margin-bottom: 0.5rem;
    counter-increment: prose-counter;
}
.prose ol li::before {
    content: counter(prose-counter);
    position: absolute;
    left: 0;
    top: 0.05em;
    width: 1.35rem;
    height: 1.35rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: rgba(212, 182, 147, 0.15);
    color: #d4b693;
    border-radius: 50%;
    font-size: 0.7rem;
    font-weight: 700;
    font-family: 'Mulish', sans-serif;
    flex-shrink: 0;
}

/* Prose: Links */
.prose a {
    color: #d4b693;
    text-decoration: underline;
    text-underline-offset: 2px;
    text-decoration-color: rgba(212, 182, 147, 0.35);
}
.prose a:hover {
    text-decoration-color: #d4b693;
}

/* Prose: h4 (smaller heading level in analysis results) */
.prose h4 {
    font-family: 'Lora', serif;
    color: #d4d4d8;
    font-weight: 600;
    font-size: 0.95rem;
    margin-top: 1rem;
    margin-bottom: 0.4rem;
}

/* Spinner */
.spinner {
    border: 2px solid rgba(255, 255, 255, 0.1);
    border-top-color: #d4b693;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

/* Input/Select Styling */
select {
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%23a1a1aa'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M19 9l-7 7-7-7'%3E%3C/path%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.75rem center;
    background-size: 1rem;
    padding-right: 2.5rem;
}

/* Pulse Animation for Status */
@keyframes pulse-glow {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.animate-pulse-slow {
    animation: pulse-glow 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}

/* Hide scrollbar but allow scrolling */
.no-scrollbar::-webkit-scrollbar {
    display: none;
}
.no-scrollbar {
    -ms-overflow-style: none;
    scrollbar-width: none;
}

/* Price Flash Animation (WebSocket Updates) */
@keyframes priceFlash {
    0% { background-color: rgba(212, 182, 147, 0.3); }
    100% { background-color: transparent; }
}

.price-flash {
    animation: priceFlash 0.3s ease-out;
    border-radius: 4px;
}

/* Prevent initial white flash */
body {
    background-color: #1a1a1c;
    opacity: 0;
    animation: bodyFadeIn 0.5s ease-out forwards;
}

@keyframes bodyFadeIn {
    to { opacity: 1; }
}

/* Tab Transition Animations */
.tab-content {
    animation: slideUpFade 0.4s cubic-bezier(0.4, 0, 0.2, 1) forwards;
    will-change: transform, opacity;
}

@keyframes slideUpFade {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Premium Modal Animation */
.modal-content-active {
    animation: modalIn 0.3s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

@keyframes modalIn {
    from {
        opacity: 0;
        transform: scale(0.95) translateY(10px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

/* Staggered List Item Animation */
.list-item-fade {
    animation: listItemIn 0.4s ease-out forwards;
    opacity: 0;
}

@keyframes listItemIn {
    from {
        opacity: 0;
        transform: translateX(-5px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

/* Sidebar Smooth Transition */
#chat-sidebar {
    transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1), box-shadow 0.4s;
    will-change: transform;
}
/* Hide browser default password reveal button */
input[type="password"]::-ms-reveal,
input[type="password"]::-ms-clear {
    display: none;
}

/* ========================================
 * Feature Menu - Navigation Customization
 * ======================================== */

/* Modal Active State */
#feature-menu-modal:not(.hidden) .feature-menu-content {
    transform: scale(1) translateY(0);
    opacity: 1;
}

/* Feature Menu Item */
.feature-menu-item {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 1rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.feature-menu-item:hover {
    background: rgba(255, 255, 255, 0.05);
    border-color: rgba(255, 255, 255, 0.1);
}

.feature-menu-item.disabled {
    opacity: 0.5;
}

.feature-menu-item.disabled .feature-item-icon {
    opacity: 0.3;
}

.feature-menu-item.disabled .feature-item-label {
    color: rgba(255, 255, 255, 0.3);
}

/* Feature Item Icon */
.feature-item-icon {
    width: 2.5rem;
    height: 2.5rem;
    border-radius: 0.75rem;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.05);
    transition: all 0.2s ease;
}

.feature-menu-item:hover .feature-item-icon {
    background: rgba(212, 182, 147, 0.1);
}

.feature-item-icon svg {
    width: 1.25rem;
    height: 1.25rem;
}

/* Feature Item Label */
.feature-item-label {
    flex: 1;
    font-weight: 600;
    color: #e4e4e7;
    transition: color 0.2s ease;
}

/* Toggle Switch */
.feature-toggle {
    position: relative;
    width: 3rem;
    height: 1.75rem;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 1rem;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.feature-toggle::after {
    content: '';
    position: absolute;
    top: 0.125rem;
    left: 0.125rem;
    width: 1.5rem;
    height: 1.5rem;
    background: white;
    border-radius: 50%;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.feature-toggle.enabled {
    background: #d4b693;
}

.feature-toggle.enabled::after {
    transform: translateX(1.25rem);
}

/* Shake Animation for Invalid Action */
@keyframes shake {
    0%, 100% { transform: translateX(0); }
    20%, 60% { transform: translateX(-4px); }
    40%, 80% { transform: translateX(4px); }
}

.feature-menu-item.shake {
    animation: shake 0.4s ease-in-out;
    border-color: rgba(239, 68, 68, 0.3);
}

/* Warning Banner Animation */
@keyframes warningPulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

#feature-menu-warning:not(.hidden) {
    animation: warningPulse 2s ease-in-out infinite;
}

/* Nav Item Transition (for when items are added/removed) */
.nav-btn {
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.nav-btn.nav-item-enter {
    animation: navItemEnter 0.3s ease-out forwards;
}

.nav-btn.nav-item-exit {
    animation: navItemExit 0.2s ease-in forwards;
}

@keyframes navItemEnter {
    from {
        opacity: 0;
        transform: scale(0.8) translateY(10px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

@keyframes navItemExit {
    from {
        opacity: 1;
        transform: scale(1);
    }
    to {
        opacity: 0;
        transform: scale(0.8);
    }
}

/* ========================================
 * Language Switcher Styles (Compact Nav Bar)
 * ======================================== */

.lang-switcher {
    position: relative;
    display: inline-flex;
}

.lang-trigger {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 2.5rem;
    height: 2.5rem;
    padding: 0;
    background: rgba(255, 255, 255, 0.05);
    border: none;
    border-radius: 9999px;
    cursor: pointer;
    transition: all 0.2s ease;
    user-select: none;
    color: #b8b8bc;
}

.lang-trigger:hover {
    background: rgba(255, 255, 255, 0.1);
}

.lang-trigger:focus {
    outline: 2px solid rgba(212, 182, 147, 0.5);
    outline-offset: 2px;
}

.lang-flag {
    font-size: 1.125rem;
    line-height: 1;
}

/* Dropdown opens UPWARD since nav is at bottom */
.lang-dropdown {
    position: absolute;
    bottom: calc(100% + 0.5rem);
    right: 0;
    min-width: 10rem;
    background: #252529;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 0.75rem;
    overflow: hidden;
    z-index: 1000;
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.4);
}

.lang-dropdown.hidden {
    display: none;
}

.lang-option {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.625rem 1rem;
    cursor: pointer;
    transition: background 0.15s ease;
}

.lang-option:hover {
    background: rgba(255, 255, 255, 0.05);
}

.lang-option:focus {
    outline: none;
    background: rgba(255, 255, 255, 0.05);
}

.lang-option.active {
    background: rgba(212, 182, 147, 0.1);
}

.lang-option-name {
    font-size: 0.8125rem;
    font-weight: 500;
    color: #b8b8bc;
}

.lang-option.active .lang-option-name {
    color: #d4b693;
}

/* ========================================
 * Forum Pages with Global Navigation
 * ======================================== */

/* Forum pages WITH global nav - add bottom padding to prevent content occlusion */
body[data-page="index"] main,
body[data-page="dashboard"] main {
    padding-bottom: 120px;
}

/* Deep content pages - no bottom padding needed (nav is hidden) */
body[data-page="post"] main,
body[data-page="create"] main,
body[data-page="profile"] main,
body[data-page="messages"] main,
body[data-page="wallet"] main,
body[data-page="premium"] main {
    padding-bottom: 0;
}

/* Ensure proper z-index layering */
#global-nav-container {
    z-index: 9999;
}

/* Forum page navbars should stay below global nav */
nav.sticky {
    z-index: 50;
}

/* Toast/Modal containers should be above global nav */
#toast-container,
.modal,
#confirm-modal,
#report-modal {
    z-index: 10000;
}
