/* Global Layout Variables */
:root {
    --sidebar-width: 260px;
    --header-height: 0px; /* Header is removed/merged */
    --primary-color: #202124;
    --secondary-color: #5f6368;
    --border-color: #e0e0e0;
    --hover-bg: #f1f3f4;
}

/* Sidebar Layout */
.sidebar {
    width: var(--sidebar-width);
    height: 100%;
    position: relative; /* Changed from fixed to relative for flex layout */
    flex-shrink: 0; /* Prevent shrinking */
    background-color: #ffffff;
    border-right: 1px solid #f0f0f0;
    display: flex;
    flex-direction: column;
    padding: 0;
    z-index: 1000;
}

/* Sidebar Header (Text Logo & Toggle) */
.sidebar-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    padding: 20px 16px;
    height: auto;
}

.sidebar-logo-container {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 8px;
}

.sidebar-logo-details {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.sidebar-logo-img {
    width: 28px;
    height: 28px;
    object-fit: contain;
    /* display: none; Removed so it shows by default */
}

.sidebar-logo-text {
    font-size: 18px;
    font-weight: 800;
    background: linear-gradient(135deg, #202124 0%, #5f6368 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    letter-spacing: 0.5px;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

.sidebar-logo-subtitle {
    font-size: 11px;
    color: #9aa0a6;
    font-weight: 500;
}

.collapse-btn {
    background: none;
    border: none;
    color: var(--secondary-color);
    cursor: pointer;
    padding: 6px; /* Slightly reduced padding */
    border-radius: 6px; /* Slightly softer corners */
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-top: 2px; /* Align with top line of text */
}

.collapse-btn:hover {
    background-color: var(--hover-bg);
    color: var(--primary-color);
}

.collapse-btn svg {
    width: 20px;
    height: 20px;
}

/* New Chat Button (Long) */
.new-chat-wrapper {
    padding: 0 16px 16px 16px;
}

.new-chat-btn-long {
    width: 100%;
    height: 44px;
    border-radius: 10px;
    background-color: #ffffff;
    border: 1px solid var(--border-color);
    color: var(--primary-color);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    transition: all 0.2s ease;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}

.new-chat-btn-long .btn-content-left {
    display: flex;
    align-items: center;
    gap: 8px;
}

.new-chat-btn-long .btn-shortcut {
    font-size: 12px;
    color: #9aa0a6;
    background-color: #f1f3f4;
    padding: 2px 6px;
    border-radius: 4px;
    font-family: monospace;
}

.new-chat-btn-long:hover {
    background-color: #f8f9fa;
    box-shadow: 0 2px 4px rgba(0,0,0,0.08);
    border-color: #dcdcdc;
}

.new-chat-btn-long i {
    font-size: 14px;
    color: var(--primary-color);
}

/* Navigation Menu */
.nav-group {
    padding: 0 12px;
    margin-bottom: 10px;
}

.nav-label {
    font-size: 12px; /* Slightly larger for section headers */
    font-weight: 500;
    color: #9aa0a6; /* Light gray */
    margin: 16px 0 8px 12px; /* More spacing */
    letter-spacing: 0;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-radius: 8px;
    color: #202124; /* Darker text */
    font-size: 14px;
    font-weight: 400;
    cursor: pointer;
    transition: all 0.2s ease;
    text-decoration: none;
    margin-bottom: 2px;
}

.nav-item:hover {
    background-color: #f1f3f4;
}

.nav-item.active {
    background-color: #e8f0fe; /* Light blue bg */
    color: #1967d2; /* Blue text */
    font-weight: 500;
}

.nav-item.active i {
    color: #1967d2;
}

.nav-item i {
    width: 20px;
    text-align: center;
    font-size: 16px;
    color: #5f6368; /* Icon color */
}

.nav-badge-new {
    font-size: 10px;
    background-color: #f1f3f4;
    color: #5f6368;
    padding: 1px 6px;
    border-radius: 4px;
    margin-left: 8px;
    font-weight: 500;
    border: 1px solid #e0e0e0;
}

.nav-history-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px; /* Tighter padding */
    margin-top: 12px;
    font-size: 13px;
    color: #9aa0a6;
    cursor: pointer;
    font-weight: 500;
    transition: color 0.2s;
}

.nav-history-header:hover {
    color: #5f6368;
}

.nav-history-header i {
    font-size: 12px;
    transition: transform 0.2s ease;
}

.history-empty-state {
    padding: 12px 24px;
    font-size: 13px;
    color: #9aa0a6;
    font-style: italic;
}

/* Chat History List */
.chat-history-list {
    flex: 1;
    overflow-y: auto;
    padding: 0 12px;
    font-size: 10px;
}

.chat-history-loader {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    height: 100%;
    min-height: 100px;
    padding: 20px;
    color: var(--secondary-color);
    font-size: 20px;
    box-sizing: border-box;
}

.group-title {
    font-size: 11px;
    color: #9aa0a6;
    margin: 16px 12px 8px;
    font-weight: 600;
    text-transform: uppercase;
}

.history-item {
    padding: 10px 12px;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 12px;
    color: var(--primary-color);
    font-size: 14px;
    margin-bottom: 2px;
    transition: background 0.2s;
    text-decoration: none;
}

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

.history-item.active {
    background-color: rgb(244 244 244);
}

.history-item i {
    font-size: 15px;
    color: var(--secondary-color);
    width: 20px;
    text-align: center;
}


/* Sidebar Footer (Upgrade & User Info) */
.sidebar-footer {
    padding: 16px;
    background-color: #ffffff;
    margin-top: auto;
}

/* Upgrade Card */
.upgrade-card {
    background: linear-gradient(135deg, #ffffff 0%, #f8f9fa 100%);
    border: 1px solid #e0e0e0;
    border-radius: 12px;
    padding: 12px;
    margin-bottom: 16px;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 12px;
    position: relative;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.02);
}

.upgrade-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 50%;
    height: 100%;
    background: linear-gradient(to right, transparent, rgba(249, 115, 22, 0.08), transparent);
    transform: skewX(-20deg);
    animation: shine 3s infinite;
}

@keyframes shine {
    0% { left: -100%; }
    20% { left: 200%; }
    100% { left: 200%; }
}

.upgrade-card:hover {
    border-color: #f97316;
    box-shadow: 0 4px 12px rgba(249, 115, 22, 0.15);
    transform: translateY(-2px);
}

.upgrade-icon {
    width: 32px;
    height: 32px;
    background: linear-gradient(135deg, #f97316 0%, #ea580c 100%);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    color: white;
    font-size: 14px;
    box-shadow: 0 2px 6px rgba(249, 115, 22, 0.3);
}

.upgrade-text {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
    z-index: 2;
}

.upgrade-title {
    font-size: 13px;
    font-weight: 700;
    color: #202124;
    white-space: nowrap;
    display: flex;
    align-items: center;
    gap: 6px;
}

.upgrade-badge {
    background: #fff7ed;
    color: #ea580c;
    font-size: 10px;
    padding: 2px 6px;
    border-radius: 100px;
    border: 1px solid #fed7aa;
    font-weight: 700;
}

.upgrade-desc {
    font-size: 11px;
    color: #5f6368;
    margin-top: 2px;
    white-space: nowrap;
}

/* User Profile */
.user-profile-compact {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.2s;
    border: 1px solid transparent;
}

.user-profile-compact:hover {
    background-color: #f8f9fa;
    border-color: #f0f0f0;
}

.user-avatar-small {
    width: 32px;
    height: 32px;
    border-radius: 20%;
    background: #202124;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 14px;
    flex-shrink: 0;
    overflow: hidden;
}

.user-details {
    flex: 1;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.user-name-row {
    font-size: 13px;
    font-weight: 600;
    color: #202124;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-meta-row {
    font-size: 11px;
    color: #9aa0a6;
    margin-top: 1px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-arrow {
    font-size: 12px;
    color: #ccc;
    margin-left: 4px;
}


/* Collapsed Sidebar Width */
.sidebar.collapsed {
    width: 60px;
}

/* Main Content Adjustment */
.main-content {
    /* margin-left removed, handled by flexbox */
    padding-top: 20px;
    flex: 1;
    min-width: 0; /* Allow flex item to shrink below content size */
}

/* Rule for collapsed sidebar margin is no longer needed in flex layout */
/* .sidebar.collapsed ~ .main-content { margin-left: 60px; } */

/* Smooth Text Transition Styles */
.sidebar-logo-text,
.sidebar-logo-subtitle,
.new-chat-btn-long span,
.new-chat-btn-long .btn-shortcut,
.group-title,
.history-text,
.project-name,
.upgrade-text,
.user-details,
.user-arrow,
.item-actions {
    white-space: nowrap;
    overflow: hidden;
    opacity: 1;
    transition: opacity 0.2s ease, width 0.2s ease, margin 0.2s ease, padding 0.2s ease;
}

/* Hide elements when collapsed */
.sidebar.collapsed .sidebar-logo-text,
.sidebar.collapsed .sidebar-logo-subtitle,
.sidebar.collapsed .new-chat-btn-long .btn-shortcut,
.sidebar.collapsed .new-chat-btn-long span,
.sidebar.collapsed .group-title,
.sidebar.collapsed .nav-label,
.sidebar.collapsed .nav-item span,
.sidebar.collapsed .nav-badge-new,
.sidebar.collapsed .nav-history-header,
.sidebar.collapsed .history-empty-state,
.sidebar.collapsed .history-text,
.sidebar.collapsed .project-name,
.sidebar.collapsed .upgrade-text,
.sidebar.collapsed .user-details,
.sidebar.collapsed .user-arrow,
.sidebar.collapsed .item-actions {
    opacity: 0;
    width: 0;
    margin: 0;
    padding: 0;
    pointer-events: none;
    position: absolute; /* Take out of flow to prevent layout shifts */
}

/* Adjust history items in collapsed mode */
.sidebar.collapsed .history-item {
    justify-content: center;
    padding: 10px 0;
}

.sidebar.collapsed .item-content {
    justify-content: center;
    flex: 0 0 auto;
}

.sidebar.collapsed .item-content i {
    margin-right: 0 !important;
    font-size: 16px;
}

.sidebar.collapsed .sidebar-header {
    justify-content: center;
    align-items: center;
    flex-direction: column;
    gap: 16px;
    padding: 20px 0;
}

.sidebar.collapsed .sidebar-logo-details {
    display: none;
}

.sidebar.collapsed .sidebar-logo-img {
    display: block;
}

.sidebar.collapsed .collapse-btn {
    position: static;
}

.sidebar.collapsed .new-chat-wrapper {
    padding: 0 10px 16px;
}

.sidebar.collapsed .new-chat-btn-long {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    padding: 0;
    justify-content: center;
}

.sidebar.collapsed .new-chat-btn-long .btn-content-left {
    gap: 0;
}

.sidebar.collapsed .sidebar-footer {
    padding: 16px 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    border-top: none;
}

.sidebar.collapsed .upgrade-card {
    padding: 0;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    justify-content: center;
    background: none;
    border: none;
    margin-bottom: 16px;
    box-shadow: none;
}

.sidebar.collapsed .upgrade-card:hover {
    background-color: #f1f3f4;
    transform: none;
}

.sidebar.collapsed .upgrade-icon {
    width: 32px;
    height: 32px;
    border-radius: 50%;
}

.sidebar.collapsed .user-profile-compact {
    padding: 0;
    justify-content: center;
    width: 40px;
    height: 40px;
    background: none;
    border: none;
}

.sidebar.collapsed .user-profile-compact:hover {
    background-color: #f1f3f4;
}



/* User Popup Card */
.user-popup-card {
    position: absolute;
    bottom: 0; 
    left: calc(100% + 10px); /* Pop out to the right of the sidebar */
    width: 240px;
    background: white;
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.15);
    border: 1px solid #eee;
    padding: 16px;
    display: none; /* Hidden by default */
    z-index: 1100;
    animation: slideRight 0.2s ease-out;
}

.user-popup-card.active {
    display: block;
}

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

.popup-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
    padding-bottom: 16px;
    border-bottom: 1px solid #eee;
}

.popup-avatar {
    width: 40px;
    height: 40px;
    background: #000;
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    font-weight: bold;
}

.popup-info {
    flex: 1;
}

.popup-name {
    font-weight: 700;
    font-size: 15px;
    color: var(--primary-color);
}

.popup-email {
    font-size: 11px;
    color: var(--secondary-color);
    margin-top: 2px;
}

.popup-stats-single {
    margin-bottom: 16px;
}

.stat-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 6px;
    font-size: 13px;
}

.stat-label {
    color: var(--secondary-color);
}

.stat-value {
    font-weight: 700;
    color: var(--primary-color);
}

.stat-bar {
    height: 6px;
    background-color: #f1f3f4;
    border-radius: 3px;
    overflow: hidden;
}

.stat-progress {
    height: 100%;
    background-color: #000;
    border-radius: 3px;
}

.popup-menu {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.menu-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    color: var(--primary-color);
    transition: background 0.2s;
}

.menu-item:hover {
    background-color: #f1f3f4;
}

.menu-item i {
    width: 20px;
    text-align: center;
    color: var(--secondary-color);
}

.menu-divider {
    height: 1px;
    background-color: #eee;
    margin: 4px 0;
}

.text-red {
    color: #d93025;
}

.text-red i {
    color: #d93025;
}

/* Collapsed Sidebar Popup Adjustment */
.sidebar.collapsed .user-popup-card {
    left: 70px; /* Still to the right */
    bottom: 20px;
    transform-origin: bottom left;
}

/* ==========================================================================
   Workflow Selection Modal Styles
   ========================================================================== */

.workflow-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(8px);
    z-index: 11000; /* Ensure it's above everything */
    display: none;
    justify-content: center;
    align-items: center;
    opacity: 0;
    transition: opacity 0.3s ease;
}

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

.workflow-modal-content {
    background: #ffffff;
    border-radius: 20px;
    width: 100%;
    max-width: 800px;
    padding: 40px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
    position: relative;
    transform: translateY(20px);
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.workflow-modal-overlay.active .workflow-modal-content {
    transform: translateY(0);
}

.workflow-modal-close {
    position: absolute;
    top: 20px;
    right: 20px;
    background: transparent;
    border: none;
    font-size: 20px;
    color: #999;
    cursor: pointer;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.workflow-modal-close:hover {
    background-color: #f1f3f4;
    color: #333;
}

.workflow-title {
    font-size: 28px;
    font-weight: 700;
    color: #202124;
    margin-bottom: 8px;
    text-align: center;
}

.workflow-subtitle {
    font-size: 16px;
    color: #5f6368;
    margin-bottom: 40px;
    text-align: center;
}

.workflow-cards-container {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 30px;
}

.workflow-card {
    background: #fff;
    border: 1px solid #e0e0e0;
    border-radius: 16px;
    overflow: hidden;
    cursor: pointer;
    transition: all 0.3s ease;
    position: relative;
    display: flex;
    flex-direction: column;
}

.workflow-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 12px 28px rgba(0, 0, 0, 0.1);
    border-color: transparent;
}

.workflow-card.disabled {
    cursor: default;
    opacity: 0.7;
    filter: grayscale(0.5);
}

.workflow-card.disabled:hover {
    transform: none;
    box-shadow: none;
    border-color: #e0e0e0;
}

.card-image-wrapper {
    height: 180px;
    position: relative;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Gradients for backgrounds */
.image-bg {
    background: linear-gradient(135deg, #FF9A9E 0%, #FECFEF 100%);
}

.video-bg {
    background: linear-gradient(135deg, #a18cd1 0%, #fbc2eb 100%);
}

.card-text-content {
    padding: 24px;
    flex: 1;
}

.card-text-content h3 {
    font-size: 18px;
    font-weight: 700;
    color: #202124;
    margin-bottom: 8px;
}

.card-text-content p {
    font-size: 14px;
    color: #5f6368;
    line-height: 1.5;
}

.card-arrow-icon {
    position: absolute;
    bottom: 24px;
    right: 24px;
    width: 32px;
    height: 32px;
    background: #f1f3f4;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #202124;
    opacity: 0;
    transform: translateX(-10px);
    transition: all 0.3s ease;
}

.workflow-card:hover .card-arrow-icon {
    opacity: 1;
    transform: translateX(0);
    background: #202124;
    color: #fff;
}

/* Model Icons Badge */
.model-badge-container {
    position: absolute;
    top: 12px;
    right: 12px;
    display: flex;
    gap: 8px;
    z-index: 5;
}

.model-badge {
    background: rgba(255, 255, 255, 0.9);
    padding: 4px 8px;
    border-radius: 6px;
    font-size: 10px;
    font-weight: 600;
    color: #333;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    display: flex;
    align-items: center;
    gap: 4px;
    backdrop-filter: blur(4px);
    transition: transform 0.2s ease;
}

.workflow-card:hover .model-badge {
    transform: translateY(-2px);
}

.model-badge i {
    font-size: 10px;
}

.badge-naon { color: #FF9A9E; }
.badge-seedream { color: #a18cd1; }
.badge-sora { color: #4facfe; }
.badge-doubao { color: #00f260; }

/* CSS Art for Image Stack */
.image-stack {
    position: relative;
    width: 100px;
    height: 100px;
}

.stack-item {
    position: absolute;
    width: 80px;
    height: 60px;
    background: rgba(255, 255, 255, 0.9);
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
    transition: transform 0.3s ease;
}

.item-1 {
    top: 30px;
    left: 10px;
    transform: rotate(-5deg);
    z-index: 1;
}

.item-2 {
    top: 20px;
    left: 10px;
    transform: rotate(2deg);
    z-index: 2;
}

.item-3 {
    top: 10px;
    left: 10px;
    transform: rotate(5deg);
    z-index: 3;
}

.workflow-card:hover .item-1 { transform: rotate(-10deg) translate(-5px, 5px); }
.workflow-card:hover .item-2 { transform: rotate(0deg); }
.workflow-card:hover .item-3 { transform: rotate(10deg) translate(5px, -5px); }

.card-icon-overlay {
    position: absolute;
    bottom: 10px;
    right: 10px;
    font-size: 24px;
    color: rgba(255, 255, 255, 0.8);
    z-index: 4;
}

/* CSS Art for Video Preview */
.video-preview {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.play-button {
    width: 60px;
    height: 60px;
    background: rgba(255, 255, 255, 0.9);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 16px rgba(0,0,0,0.2);
    z-index: 2;
    transition: transform 0.3s ease;
}

.play-button i {
    font-size: 24px;
    color: #a18cd1;
    margin-left: 4px; /* Optical adjustment */
}

.workflow-card:hover .play-button {
    transform: scale(1.1);
    background: #fff;
}

.video-wave {
    position: absolute;
    width: 100%;
    height: 100%;
    background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 1440 320'%3E%3Cpath fill='%23ffffff' fill-opacity='0.2' d='M0,192L48,197.3C96,203,192,213,288,229.3C384,245,480,267,576,250.7C672,235,768,181,864,181.3C960,181,1056,235,1152,234.7C1248,235,1344,181,1392,154.7L1440,128L1440,320L1392,320C1344,320,1248,320,1152,320C1056,320,960,320,864,320C768,320,672,320,576,320C480,320,384,320,288,320C192,320,96,320,48,320L0,320Z'%3E%3C/path%3E%3C/svg%3E");
    background-size: cover;
    background-position: bottom;
    bottom: 0;
    left: 0;
    opacity: 0.6;
}

@media (max-width: 600px) {
    .workflow-cards-container {
        grid-template-columns: 1fr;
    }
    
    .workflow-modal-content {
        padding: 24px;
        width: 90%;
    }
}
