/* Global Theme Transition */
body {
    transition: background-color 0.5s ease, color 0.5s ease;
}

/* 数字/符号换行修复：防止连续数字或符号撑破容器 */
textarea,
input[type="text"],
input[type="search"],
input[type="email"],
input[type="password"],
input[type="tel"],
input[type="url"],
[contenteditable],
.intro-quote,
.post-text-content,
.post-content,
.card-content,
.comment-text,
.content-text {
    overflow-wrap: break-word;
    word-break: break-word;
}

/* 移除 hero 相关的过渡效果和可能的装饰 */
.hero-glow, 
.hero-visual img {
    transition: none !important;
    filter: none !important;
}

/* Reusing styles from home.html for consistency */
/* Adjust gap for tabbar items to bring avatar closer */
.tabbar-item {
    gap: 20px !important;
}

/* Theme Toggle Button Styles */
.theme-toggle {
    margin-left: 0;
    cursor: pointer;
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background 0.3s;
}

.theme-toggle:hover {
    background: rgba(255, 255, 255, 0.1);
}

.theme-toggle img {
    width: 32px;
    height: 32px;
    display: block;
    filter: brightness(0) invert(1);
    transition: transform 0.5s cubic-bezier(0.68, -0.55, 0.27, 1.55), opacity 0.3s;
}

.theme-toggle.icon-anim img {
    transform: rotate(180deg) scale(0.2);
    opacity: 0;
}

/* GitHub Link Styles */
.github-link {
    display: flex !important; /* Force flex to override inline-block */
    align-items: center !important; /* Ensure vertical centering */
    justify-content: center !important; /* Ensure horizontal centering */
    width: 48px;
    height: 48px;
    border-radius: 50%;
    transition: background 0.3s;
    text-decoration: none; /* Remove underline from anchor */
    border-bottom: none !important; /* Remove nav link underline */
    margin-left: 0 !important; /* Reset margin for consistent spacing */
    padding: 0 !important; /* Reset padding inherited from .tabbar-item a to fix centering */
}

.github-link:hover {
    background: rgba(255, 255, 255, 0.1);
}

.github-link img {
    width: 32px;
    height: 32px;
    display: block;
    filter: brightness(0) invert(1); /* Make it white */
    transition: transform 0.3s ease;
    margin: auto; /* Ensure image is centered */
}

.github-link:hover img {
    transform: scale(1.1);
}

/* User Avatar Styles */
.user-avatar-container {
    margin-left: 0;
    cursor: pointer;
    position: relative; /* Added for dropdown positioning */
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Hide profile nav when not logged in */
html.guest .tabbar-item .nav-profile,
html.guest .tabbar-item > li.nav-profile,
html.guest li.nav-profile,
html.guest .tabbar-item li:has(a[href*="privacy"]) {
    display: none !important;
}

/* Auth pages: hide avatar before JS runs */
html.guest:has(.auth-container) .user-avatar-container {
    display: none !important;
}

.user-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background-color: #a3c2fa; /* Default placeholder color */
    border: 2px solid rgba(255, 255, 255, 0.2);
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #ffffff;
    font-weight: bold;
    font-size: 14px;
    transition: all 0.3s ease;
}

.user-avatar:hover {
    border-color: #ffffff;
    transform: scale(1.05);
    box-shadow: 0 0 10px rgba(255, 255, 255, 0.3);
}

.user-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* Dark Mode Avatar Adjustments */
body.dark-mode .user-avatar {
    border-color: rgba(255, 255, 255, 0.1);
}

body.dark-mode .user-avatar:hover {
    border-color: #ffffff;
    box-shadow: 0 0 15px rgba(255, 255, 255, 0.2);
}

/* Dark Mode Global Styles */
body.dark-mode {
    background: #0b1120;
    color: #e2e8f0;
}

/* Fix for browser autofill background in dark mode */
body.dark-mode input:-webkit-autofill,
body.dark-mode input:-webkit-autofill:hover, 
body.dark-mode input:-webkit-autofill:focus, 
body.dark-mode input:-webkit-autofill:active {
    -webkit-box-shadow: 0 0 0 30px #0f172a inset !important;
    -webkit-text-fill-color: #f1f5f9 !important;
    transition: background-color 5000s ease-in-out 0s;
}

body.dark-mode .head {
    background: #0f172a;
    border-bottom: none !important;
    box-shadow: none !important;
    transition: background-color 0.5s ease;
}

/* Dark Mode Specific Component Overrides */
body.dark-mode .hero {
    background: #0b1120;
}

body.dark-mode .hero-title {
    color: #f1f5f9;
}

body.dark-mode .hero-desc {
    color: #94a3b8;
}

body.dark-mode .search-form {
    background: #1e293b;
    border-color: #334155;
}

body.dark-mode .search-input {
    color: #f1f5f9;
}

body.dark-mode .search-input::placeholder {
    color: #64748b;
}

body.dark-mode .hero-btn.secondary {
    color: #60a5fa;
    border-color: #60a5fa;
}

body.dark-mode .hero-btn.secondary:hover {
    background: rgba(96, 165, 250, 0.1);
}

body.dark-mode .hero-visual img {
    filter: drop-shadow(0 10px 30px rgba(0, 0, 0, 0.4));
}

/* Dropdown Menu Styles */
.user-dropdown {
    visibility: hidden; /* Changed from display: none to allow transition */
    opacity: 0;
    position: absolute;
    top: 100%;
    left: 0;
    width: 180px; /* Adjusted width for better proportion */
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15);
    border-radius: 12px;
    padding: 0;
    z-index: 1001;
    margin-top: 12px;
    border: 1px solid rgba(255, 255, 255, 0.5);
    transform: translateY(10px) scale(0.95);
    transition: opacity 0.3s cubic-bezier(0.16, 1, 0.3, 1), 
                transform 0.3s cubic-bezier(0.16, 1, 0.3, 1),
                visibility 0.3s;
    transform-origin: top left;
}

.user-avatar-container:hover .user-dropdown,
.user-avatar-container.active .user-dropdown {
    visibility: visible !important;
    opacity: 1 !important;
    transform: translateY(0) scale(1) !important;
}

/* Add a bridge to prevent mouse leaving when moving from avatar to dropdown */
.user-avatar-container::after {
    content: '';
    position: absolute;
    top: 100%;
    left: 0;
    width: 100%;
    height: 15px; /* Increased bridge height */
}

/* Arrow for the dropdown */
.user-dropdown::before {
    content: '';
    position: absolute;
    top: -6px;
    left: 16px; /* Aligned with avatar container center (44px/2 - 12px/2 = 16px) */
    width: 12px;
    height: 12px;
    background: inherit;
    transform: rotate(45deg);
    border-top: 1px solid inherit;
    border-left: 1px solid inherit;
    border-color: inherit; /* Inherit border color from parent */
    z-index: -1; /* Behind the content but part of the box */
}

.dropdown-header {
    padding: 20px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.05);
    background: rgba(248, 250, 252, 0.5);
    border-radius: 12px 12px 0 0;
}

.dropdown-header .username {
    display: block;
    font-weight: 700;
    color: #1e293b;
    font-size: 16px;
    margin-bottom: 4px;
}

.dropdown-header .email {
    display: block;
    font-size: 13px;
    color: #64748b;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.dropdown-menu {
    list-style: none;
    padding: 8px;
    margin: 0;
}

.dropdown-menu li a {
    display: flex;
    align-items: center;
    padding: 10px 12px;
    color: #475569;
    text-decoration: none;
    font-size: 14px;
    border-radius: 8px;
    font-weight: 500;
    border: none !important; /* Reset inherited border from tabbar */
}

.dropdown-menu li a:hover {
    color: #2563eb;
}

.dropdown-menu li a .icon {
    margin-right: 10px;
    font-size: 16px;
    width: 20px;
    text-align: center;
}

.dropdown-menu li a.logout-link {
    color: #ef4444;
}

.dropdown-menu li a.logout-link:hover {
    color: #dc2626;
}

/* Dark Mode Dropdown Styles */
body.dark-mode .user-dropdown {
    background: rgba(30, 41, 59, 0.95);
    border-color: rgba(255, 255, 255, 0.1);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
}

body.dark-mode .dropdown-header {
    background: rgba(15, 23, 42, 0.5);
    border-bottom-color: rgba(255, 255, 255, 0.05);
}

body.dark-mode .dropdown-header .username {
    color: #f1f5f9;
}

body.dark-mode .dropdown-header .email {
    color: #94a3b8;
}

body.dark-mode .dropdown-menu li a {
    color: #cbd5e1;
}

body.dark-mode .dropdown-menu li a:hover {
    color: #60a5fa;
}

/* Dropdown arrow dark mode border adjustment */
body.dark-mode .user-dropdown::before {
    background: inherit; /* Match dark bg */
    border-color: rgba(255, 255, 255, 0.1);
}

/* =========================================
   Header Layout Optimization
   ========================================= */

/* Optimize Brand/Logo area */
.brand {
    font-size: 42px !important; /* Increased to be even more prominent */
    white-space: nowrap !important;
    flex-shrink: 0 !important;
    margin-right: 15px !important;
    line-height: 1 !important;
    font-weight: 900 !important; /* Extra bold to match Figure 2 */
    margin-left: -40px !important;
    letter-spacing: 1px !important;
}

/* Optimize Individual Links */
.tabbar-item > li > a {
    white-space: nowrap !important;
    font-size: 18px !important;
    padding: 8px 0 !important;
    flex-shrink: 0 !important;
    display: inline-block !important;
    font-weight: 600 !important; /* Bolder text for links */
    transition: all 0.2s ease;
    border-bottom: 2px solid transparent;
}

.tabbar-item > li > a:hover,
.tabbar-item > li > a.active {
    color: #ffffff !important;
    border-bottom-color: #8fb6ff !important;
}

/* Optimize tabbar items gap */
.tabbar-item {
    gap: 30px !important; /* Increased gap to match Figure 2 */
}

/* Optimize Search Bar */

/* Responsive Mobile & Left-Align Optimization */
.tabbar.tabbar-left-aligned {
    justify-content: flex-start !important;
    gap: 0 !important;
    padding-left: 10px !important; /* Adjusted: Shift layout slightly right */
}

.tabbar.tabbar-left-aligned .brand {
    margin-right: 80px !important; /* Increased from 60px */
}

.tabbar.tabbar-left-aligned .tabbar-item {
    justify-content: flex-start !important;
    margin-left: 0 !important;
    width: auto !important;
    gap: 4px !important; /* Minimized from 12px */
}

/* Mobile Adjustments (Max-width 768px) */
@media (max-width: 768px) {
    /* Reset left padding for mobile to save space */
    .tabbar.tabbar-left-aligned {
        padding-left: 10px !important; /* Minimal padding for mobile */
    }

    /* Hide text navigation links */
    .tabbar.tabbar-left-aligned .tabbar-item > li {
        display: none;
    }

    /* Show functional icons: Search, Theme, Github, Avatar */
    .tabbar.tabbar-left-aligned .tabbar-item > li.search-item,
    .tabbar.tabbar-left-aligned .tabbar-item > li.user-avatar-container,
    .tabbar.tabbar-left-aligned .tabbar-item > li:nth-last-child(2),
    .tabbar.tabbar-left-aligned .tabbar-item > li:nth-last-child(3)
    {
        display: flex !important;
    }

    /* Collapse Search Bar to Icon Only */
    .tabbar.tabbar-left-aligned .search-form {
        min-width: 36px !important;
        width: 36px !important;
        padding: 0 !important;
        background: transparent !important;
        border: none !important;
    }
    
    .tabbar.tabbar-left-aligned .search-input,
    .tabbar.tabbar-left-aligned .search-shortcut {
        display: none !important;
    }
    
    .tabbar.tabbar-left-aligned .search-button {
        width: 36px;
        height: 36px;
        margin: 0;
    }

    /* Adjust spacing and sizing for mobile fit */
    .tabbar.tabbar-left-aligned .brand {
        margin-right: 15px !important;
        font-size: 20px !important;
    }
    
    .tabbar.tabbar-left-aligned .tabbar-item {
        gap: 8px !important;
    }
}

/* Ensure 44px Touch Targets for Accessibility */
.user-avatar-container, 
.theme-toggle, 
.github-link {
    min-width: 44px;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-left: 0 !important; /* Minimized spacing */
    margin-right: 0 !important; /* Minimized spacing */
}

/* =========================================
   Custom Toast Notification
   ========================================= */
.custom-toast-container {
    position: fixed;
    top: 30px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 100000; /* Increased z-index to ensure it is above modals */
    display: flex;
    flex-direction: column;
    gap: 12px;
    pointer-events: none;
}

.custom-toast {
    min-width: 260px;
    max-width: 420px;
    background-color: #2b4c8a; /* Slightly deeper flat blue */
    color: #ffffff;
    padding: 14px 24px;
    border-radius: 8px; /* Slightly sharper corners for flat design */
    font-size: 15px;
    font-weight: 500;
    text-align: left; /* Better readability with icons */
    box-shadow: 0 10px 25px rgba(20, 40, 80, 0.2); /* Softer shadow */
    opacity: 0;
    transform: translateY(-30px) scale(0.95); /* Add scale to animation */
    transition: opacity 0.4s cubic-bezier(0.16, 1, 0.3, 1), transform 0.4s cubic-bezier(0.16, 1, 0.3, 1);
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 12px; /* Space between icon and text */
    word-break: break-word;
    letter-spacing: 0.5px;
}

.custom-toast-icon {
    font-size: 16px;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background-color: rgba(255, 255, 255, 0.2);
}

.custom-toast.toast-error {
    background-color: #ef4444; /* Brighter flat red */
    box-shadow: 0 10px 25px rgba(239, 68, 68, 0.2);
}

.custom-toast.toast-success {
    background-color: #10b981; /* Fresh flat green */
    box-shadow: 0 10px 25px rgba(16, 185, 129, 0.2);
}

.custom-toast.toast-info {
    background-color: #3b82f6; /* Lighter flat blue for info */
    box-shadow: 0 10px 25px rgba(59, 130, 246, 0.2);
}

.custom-toast.show {
    opacity: 1;
    transform: translateY(0) scale(1);
}

/* Dark mode adjustments for toast */
body.dark-mode .custom-toast {
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.5);
}

/* =========================================
   Global Custom Modal
   ========================================= */
.custom-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    z-index: 100001; /* Above everything */
    display: none;
    justify-content: center;
    align-items: center;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.custom-modal-overlay.active {
    display: flex;
    opacity: 1;
}

.custom-modal-container {
    width: min(420px, 90%);
    background: #ffffff;
    border-radius: 16px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.2);
    overflow: hidden;
    transform: translateY(20px) scale(0.95);
    transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.custom-modal-overlay.active .custom-modal-container {
    transform: translateY(0) scale(1);
}

.custom-modal-header {
    padding: 24px 24px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.custom-modal-title {
    font-size: 20px;
    font-weight: 700;
    color: #1e293b;
}

.custom-modal-close {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: #64748b;
    transition: all 0.2s;
}

.custom-modal-close:hover {
    background: #f1f5f9;
    color: #1e293b;
}

.custom-modal-content {
    padding: 0 24px 24px;
}

.custom-modal-message {
    font-size: 15px;
    line-height: 1.6;
    color: #475569;
    margin-bottom: 8px; /* Reduced from 24px to accommodate input */
}

.custom-modal-input {
    width: 100%;
    padding: 12px 16px;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    font-size: 14px;
    outline: none;
    background: #f8fafc;
    color: #1e293b;
    transition: all 0.2s;
}

.custom-modal-input:focus {
    border-color: #325aa4;
    background: #ffffff;
    box-shadow: 0 0 0 3px rgba(50, 90, 164, 0.1);
}

.custom-modal-footer {
    padding: 24px 24px 24px; /* Restored padding */
    display: flex;
    justify-content: flex-end;
    gap: 12px;
}

.modal-btn {
    padding: 10px 20px;
    border-radius: 20px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    border: none;
}

.modal-btn-cancel {
    background: #f1f5f9;
    color: #475569;
}

.modal-btn-cancel:hover {
    background: #e2e8f0;
}

.modal-btn-primary {
    background: #264580;
    color: #ffffff;
}

.modal-btn-primary:hover {
    background: #1e3666;
    box-shadow: 0 4px 12px rgba(38, 69, 128, 0.3);
}

/* Dark Mode Modal */
body.dark-mode .custom-modal-container {
    background: #1e293b;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

body.dark-mode .custom-modal-title {
    color: #f1f5f9;
}

body.dark-mode .custom-modal-message {
    color: #94a3b8;
}

body.dark-mode .custom-modal-input {
    background: rgba(0, 0, 0, 0.2);
    border-color: rgba(255, 255, 255, 0.1);
    color: #f1f5f9;
}

body.dark-mode .custom-modal-input:focus {
    border-color: #3b82f6;
    background: rgba(0, 0, 0, 0.3);
}

body.dark-mode .modal-btn-cancel {
    background: #334155;
    color: #cbd5e1;
}

body.dark-mode .modal-btn-cancel:hover {
    background: #475569;
}

body.dark-mode .custom-modal-close:hover {
    background: rgba(255, 255, 255, 0.1);
}

/* Search Results Styles */
.search-results-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.search-result-item {
    display: flex;
    align-items: center;
    padding: 12px;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.2s;
    text-decoration: none;
    color: inherit;
    margin-bottom: 4px;
}

.search-result-item:hover {
    background: rgba(255, 255, 255, 0.05);
}

body:not(.dark-mode) .search-result-item:hover {
    background: rgba(0, 0, 0, 0.03);
}

.search-result-icon {
    width: 40px;
    height: 40px;
    border-radius: 8px;
    background: rgba(50, 90, 164, 0.1);
    display: flex;
    align-items: center;
    justify-content: center;
    margin-right: 15px;
    font-size: 20px;
    flex-shrink: 0;
}

.search-result-info {
    flex: 1;
    min-width: 0;
}

.search-result-title {
    font-weight: 600;
    font-size: 15px;
    margin-bottom: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: #e2e8f0;
}

.search-result-meta {
    font-size: 12px;
    color: #64748b;
    display: flex;
    align-items: center;
    gap: 8px;
}

.search-empty {
    text-align: center;
    padding: 40px 20px;
    color: #64748b;
}

.search-loading {
    text-align: center;
    padding: 20px;
    color: #64748b;
}

/* User Role Tags */
.webmaster-tag {
    background-color: #142850;
    color: #ffffff;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: bold;
    margin-left: 8px;
    vertical-align: middle;
    display: inline-block;
    box-shadow: 0 2px 4px rgba(20, 40, 80, 0.2);
}

.admin-tag {
    background-color: #3b82f6;
    color: #ffffff;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: bold;
    margin-left: 8px;
    vertical-align: middle;
    display: inline-block;
}

body.dark-mode .webmaster-tag {
    background-color: #3b82f6;
    box-shadow: 0 0 8px rgba(59, 130, 246, 0.4);
}

body.dark-mode .admin-tag {
    background-color: #60a5fa;
}
