/* User Mode Styles */
.user-mode-content {
    position: absolute;
    top: 70px; /* Header height */
    left: 0;
    right: 0;
    bottom: 40px; /* Footer height */
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    background: var(--primary-bg);
    z-index: 10;
    overflow: hidden; /* Prevent any scrollbar on the main content */
}

.user-mode-container {
    width: 100%;
    height: 100%;
    display: flex;
    gap: 2%;
    transition: all 0.5s ease;
    overflow: hidden; /* Prevent scrollbar on container */
}

.user-mode-title {
    font-size: 2rem;
    color: #e0e0e0;
    margin-bottom: 2rem;
    font-weight: 300;
    transition: all 0.5s ease;
}

/* Initial centered state */
.user-mode-container:not(.building) {
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
}

.user-mode-container:not(.building) .left-container {
    width: 100%;
    max-width: 800px;
    height: auto;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.user-mode-container:not(.building) .right-container {
    display: none;
}

/* Building state - side by side layout */
.user-mode-container.building {
    flex-direction: row;
    align-items: stretch;
}

.user-mode-container.building .user-mode-title {
    display: none;
}

/* Left Container - 49% width, 100% height */
.left-container {
    width: 49%;
    height: 100%;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    transition: all 0.5s ease;
    position: relative; /* For absolute positioned children like widget picker */
}

.user-mode-container.building .left-container {
    padding: 0;
}

/* Chat Interface */
.chat-interface {
    display: none;
    flex-direction: column;
    height: 100%;
    gap: 0;
    overflow: hidden; /* Prevent overflow */
}

.user-mode-container.building .chat-interface {
    display: flex;
}

/* Chat History Area */
.chat-history {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid #333;
    border-radius: 8px 8px 0 0;
    border-bottom: none;
}

.chat-message {
    margin-bottom: 1rem;
    padding: 0.75rem;
    border-radius: 8px;
    max-width: 85%;
}

.user-message {
    background: #007acc;
    color: white;
    margin-left: auto;
    text-align: right;
}

.assistant-message {
    background: rgba(255, 255, 255, 0.1);
    color: #e0e0e0;
    margin-right: auto;
}

.message-content {
    font-size: 0.9rem;
    line-height: 1.4;
}

/* Chat Input Area */
.chat-input-area {
    display: flex;
    gap: 0;
    flex-shrink: 0;
    max-height: 200px; /* Limit maximum height to prevent overflow */
    overflow: visible;
    position: relative;
}

/* Element Autocomplete Dropdown */
.element-autocomplete {
    position: absolute;
    bottom: 100%;
    left: 0;
    right: 0;
    max-height: 280px;
    overflow-y: auto;
    background: #1e1e2e;
    border: 1px solid #3a3a4e;
    border-radius: 8px;
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.4);
    z-index: 1000;
    margin-bottom: 8px;
    display: none;
}

.element-autocomplete.show {
    display: block;
}

.element-autocomplete-header {
    padding: 10px 14px;
    border-bottom: 1px solid #3a3a4e;
    font-size: 12px;
    color: #888;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    background: #1e1e2e;
}

.element-autocomplete-header .hint {
    color: #667eea;
    font-weight: 500;
}

.element-autocomplete-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    cursor: pointer;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    transition: background-color 0.15s;
}

.element-autocomplete-item:last-child {
    border-bottom: none;
}

.element-autocomplete-item:hover,
.element-autocomplete-item.selected {
    background: rgba(102, 126, 234, 0.15);
}

.element-autocomplete-item.selected {
    background: rgba(102, 126, 234, 0.25);
}

.element-autocomplete-item .element-tag {
    padding: 2px 8px;
    background: rgba(102, 126, 234, 0.2);
    border-radius: 4px;
    font-size: 11px;
    font-weight: 600;
    color: #667eea;
    text-transform: uppercase;
    min-width: 50px;
    text-align: center;
}

.element-autocomplete-item .element-name {
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
    font-size: 13px;
    color: #4ade80;
    font-weight: 500;
}

.element-autocomplete-item .element-preview {
    flex: 1;
    font-size: 12px;
    color: #888;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.element-autocomplete-item .connector-badge {
    font-size: 14px;
    margin-left: 8px;
    opacity: 0.8;
}

.element-autocomplete-item.has-connector {
    border-left: 3px solid #4ade80;
}

.element-autocomplete-item.has-connector .element-name {
    color: #4ade80;
}

.element-autocomplete-empty {
    padding: 20px;
    text-align: center;
    color: #666;
    font-size: 13px;
}

.element-autocomplete-loading {
    padding: 20px;
    text-align: center;
    color: #667eea;
    font-size: 13px;
}

/* Name Mode Indicator */
.name-mode-indicator {
    position: absolute;
    top: -30px;
    right: 0;
    padding: 4px 10px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    font-size: 11px;
    font-weight: 600;
    border-radius: 4px;
    display: none;
}

.name-mode-indicator.show {
    display: block;
}

.chat-input {
    flex: 1;
    padding: 1rem;
    border: 1px solid #333;
    border-radius: 0 0 0 8px;
    background: rgba(255, 255, 255, 0.05);
    color: #e0e0e0;
    font-size: 16px;
    font-family: inherit;
    resize: none;
    min-height: 54px;
    max-height: 150px;
    line-height: 1.4;
    overflow-y: hidden;
    outline: none;
    border-right: none;
}

.chat-input:focus {
    border-color: #007acc;
}

/* Slim scrollbar for chat input */
.chat-input::-webkit-scrollbar {
    width: 6px;
}

.chat-input::-webkit-scrollbar-track {
    background: transparent;
}

.chat-input::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 3px;
}

.chat-input::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* Firefox */
.chat-input {
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.2) transparent;
}

.chat-submit {
    padding: 1rem 1.5rem;
    background: #007acc;
    color: white;
    border: 1px solid #007acc;
    border-radius: 0 0 8px 0;
    font-size: 16px;
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.3s ease;
    white-space: nowrap;
    min-height: 54px;
    display: flex;
    align-items: center;
    justify-content: center;
    align-self: stretch;
}

.chat-submit:hover {
    background: #005a9e;
    border-color: #005a9e;
}

/* Right Container - 49% width, 100% height */
.right-container {
    width: 49%;
    height: 100%;
    display: flex;
    align-items: stretch;
    justify-content: stretch;
    transition: all 0.5s ease;
}

/* Device Preview Container */
.device-preview {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    padding: 1rem;
}

.user-mode-container.building .right-container {
    display: flex;
    animation: fadeInRight 0.5s ease 0.3s both;
}

@keyframes fadeInRight {
    from {
        opacity: 0;
        transform: translateX(30px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

/* Left title in building mode */
.left-title {
    display: none;
    font-size: 1.5rem;
    color: #e0e0e0;
    margin-bottom: 1rem;
    font-weight: 300;
    text-align: left;
}

.user-mode-container.building .left-title {
    display: block;
    flex-shrink: 0;
}

/* Input section in building mode */
.user-mode-container.building .left-container .user-input-section {
    display: none;
}

.user-mode-container.building .left-container .user-input-row {
    display: flex;
    gap: 1rem;
    align-items: flex-end;
}

.user-mode-container.building .left-container .user-input-label {
    font-size: 1rem;
    color: #e0e0e0;
    margin-bottom: 0.5rem;
    display: block;
}

/* Phone device mockup */
.phone-device {
    /* iPhone 14 Pro: 1179/2556 ≈ 0.461 - Accurate Apple aspect ratio */
    height: calc(100% - 80px); /* Use most of available height */
    width: auto;                 /* let aspect-ratio compute width */
    max-width: 100%;
    max-height: 100%;
    background: #1a1a1a;
    border-radius: 25px;
    padding: 20px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.3);
    position: relative;
    display: flex;
    flex-direction: column;
    box-sizing: border-box;
    flex-shrink: 0;
    aspect-ratio: 1179 / 2556;   /* iPhone 14 Pro */
    transition: all 0.3s ease; /* Smooth transitions between device types */
}

/* iPhone 14 Pro Max variant */
.phone-device.iphone-pro-max {
    /* iPhone 14 Pro Max: 1290/2796 ≈ 0.461 - Same ratio as Pro, but larger display */
    aspect-ratio: 1290 / 2796;
    height: calc((100% - 80px) * 1.05); /* slightly taller instead of transform */
}

/* 11-inch iPad Pro variant */
.phone-device.ipad-pro {
    /* 11-inch iPad Pro: 1668/2388 ≈ 0.698 - Accurate iPad aspect ratio */
    width: auto;              /* rely on aspect-ratio to compute width */
    max-width: 100%;
    max-height: 100%;
    border-radius: 15px; /* Less rounded for tablet */
    aspect-ratio: 1668 / 2388;
    height: calc((100% - 80px) * 0.95);
    padding: 15px; /* Slightly less padding for iPad */
}

/* Legacy support for old class names - redirect to new accurate ones */
.phone-device.phone-max {
    /* Redirect to accurate iPhone Pro Max */
    aspect-ratio: 1290 / 2796;
    height: calc((100% - 80px) * 1.05);
}

.phone-device.tablet {
    /* Redirect to accurate iPad Pro */
    aspect-ratio: 1668 / 2388;
    height: calc((100% - 80px) * 0.95);
    border-radius: 15px;
    padding: 15px;
}

.phone-device::before {
    content: '';
    position: absolute;
    top: 8px;
    left: 50%;
    transform: translateX(-50%);
    width: 60px;
    height: 4px;
    background: #333;
    border-radius: 2px;
}

.phone-screen {
    width: 100%;
    height: 100%;
    background: var(--primary-bg);
    border-radius: 15px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    min-height: 0; /* Allow flex shrinking */
}

.phone-header {
    height: 50px; /* Reduced height for better proportions */
    background: var(--secondary-bg);
    display: flex;
    align-items: center;
    justify-content: center;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.phone-header h3 {
    margin: 0;
    color: var(--text-primary);
    font-size: 1.1rem; /* Larger font for bigger device */
}

.phone-content {
    flex: 1;
    padding: 1rem 0.75rem; /* Optimized padding for accurate iPhone ratios */
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    min-height: 0; /* Allow flex shrinking */
}

/* Adjust content padding for iPad */
.phone-device.ipad-pro .phone-content,
.phone-device.tablet .phone-content {
    padding: 1.5rem 1.25rem; /* More padding for larger iPad screen */
}

/* Adjust form mockup sizes for different devices */
.phone-device.ipad-pro .login-form-mockup,
.phone-device.tablet .login-form-mockup {
    max-width: 280px; /* Larger form for iPad */
}

.phone-device.iphone-pro-max .login-form-mockup,
.phone-device.phone-max .login-form-mockup {
    max-width: 220px; /* Slightly larger for Pro Max */
}

.login-form-mockup {
    max-width: 200px; /* Default for iPhone Pro */
}

/* Building status */
.building-status {
    width: 100%;
    text-align: center;
    color: var(--text-secondary);
    margin-bottom: 2rem;
}

.building-status .spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border);
    border-top: 3px solid var(--accent-purple);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 1rem;
}

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

/* Login form mockup */
.login-form-mockup {
    display: none;
    width: 100%;
    max-width: 200px; /* Larger for the bigger device */
}

.login-form-mockup.visible {
    display: block;
    animation: fadeIn 0.5s ease;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.form-group-mockup {
    margin-bottom: 1rem;
}

.form-group-mockup label {
    display: block;
    font-size: 0.85rem; /* Larger font for bigger device */
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
    text-align: left;
}

.form-group-mockup input {
    width: 100%;
    padding: 0.75rem; /* Larger padding for bigger device */
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--accent-bg);
    color: var(--text-primary);
    font-size: 0.85rem; /* Larger font for bigger device */
    box-sizing: border-box;
}

.form-group-mockup input:focus {
    outline: none;
    border-color: var(--accent-purple);
}

.login-btn-mockup {
    width: 100%;
    padding: 0.75rem; /* Larger padding for bigger device */
    background: var(--accent-purple);
    color: white;
    border: none;
    border-radius: 6px;
    font-size: 0.85rem; /* Larger font for bigger device */
    cursor: pointer;
    margin-top: 1rem;
}

.login-btn-mockup:hover {
    background: #7c3aed;
}

/* Input styling */
.user-mode-input {
    width: 100%;
    min-height: 150px;
    padding: 1.5rem;
    border: 2px solid #333;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.05);
    color: #e0e0e0;
    font-size: 18px;
    font-family: inherit;
    resize: vertical;
    transition: border-color 0.3s ease;
}

.user-mode-container.building .user-mode-input {
    flex: 1;
    min-height: 60px;
    max-height: 60px;
    resize: none;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.user-mode-input:focus {
    outline: none;
    border-color: #007acc;
}

.user-mode-input::placeholder {
    color: #888;
}

/* Button Group */
.button-group {
    display: flex;
    flex-direction: column;
    gap: 12px;
    align-items: center;
    align-self: center;
    margin-top: 1rem;
}

.button-row {
    display: flex;
    gap: 12px;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
}

#templatePickerBtn {
    align-self: flex-start;
}

.user-mode-container.building .button-group {
    align-self: flex-start;
}

.user-mode-submit {
    padding: 12px 24px;
    background: #007acc;
    color: white;
    border: none;
    border-radius: 6px;
    font-size: 16px;
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.3s ease;
    min-width: 120px;
}

.user-mode-submit:hover {
    background: #0098ff;
}

.search-templates-btn {
    padding: 10px 20px;
    background: transparent;
    color: #00d4ff;
    border: 2px solid #00d4ff;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 8px;
}

.search-templates-btn:hover {
    background: rgba(0, 212, 255, 0.1);
    border-color: #00ffff;
    color: #00ffff;
}

.search-templates-btn svg {
    width: 16px;
    height: 16px;
}

.user-mode-container.building .button-group {
    justify-content: flex-start;
}

/* Template Picker Button */
.template-picker-btn {
    padding: 10px 20px;
    background: transparent;
    color: #007acc;
    border: 2px solid #007acc;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
    align-self: center;
    margin-top: 12px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.template-picker-btn:hover {
    background: rgba(0, 122, 204, 0.1);
    border-color: #0098ff;
    color: #0098ff;
}

.template-picker-btn svg {
    width: 16px;
    height: 16px;
}

.user-mode-container.building .template-picker-btn {
    display: none;
}

.user-mode-container.building .search-templates-btn {
    display: none;
}

/* Template Suggestions */
.template-suggestions {
    margin-top: 1.5rem;
    background: rgba(0, 212, 255, 0.05);
    border: 2px solid rgba(0, 212, 255, 0.2);
    border-radius: 10px;
    padding: 1rem;
    animation: slideDown 0.3s ease;
}

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

.suggestions-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid rgba(0, 212, 255, 0.2);
}

.suggestions-header h4 {
    margin: 0;
    color: #00d4ff;
    font-size: 16px;
    font-weight: 600;
}

.close-suggestions {
    background: none;
    border: none;
    color: #666;
    font-size: 24px;
    cursor: pointer;
    padding: 0;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.3s ease;
}

.close-suggestions:hover {
    color: #00d4ff;
}

.suggestions-content {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 1rem;
}

.suggestion-card {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid #333;
    border-radius: 8px;
    padding: 1rem;
    cursor: pointer;
    transition: all 0.3s ease;
}

.suggestion-card:hover {
    border-color: #00d4ff;
    background: rgba(0, 212, 255, 0.1);
    transform: translateY(-2px);
}

.suggestion-card h5 {
    margin: 0 0 0.5rem 0;
    color: #e0e0e0;
    font-size: 15px;
    font-weight: 600;
}

.suggestion-card p {
    margin: 0 0 0.75rem 0;
    color: #b0b0b0;
    font-size: 13px;
    line-height: 1.5;
}

.suggestion-card .suggestion-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.suggestion-card .suggestion-tags .tag {
    padding: 3px 8px;
    background: rgba(0, 212, 255, 0.15);
    border: 1px solid rgba(0, 212, 255, 0.3);
    border-radius: 10px;
    font-size: 11px;
    color: #00d4ff;
    font-weight: 500;
}

.suggestions-loading {
    text-align: center;
    padding: 2rem;
    color: #00d4ff;
}

.suggestions-loading svg {
    animation: spin 1s linear infinite;
}

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

/* Template Modal */
.template-modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
    animation: fadeIn 0.3s ease;
}

.template-modal.show {
    display: flex;
    align-items: center;
    justify-content: center;
}

.template-modal-content {
    background: #1e1e1e;
    border-radius: 12px;
    width: 90%;
    max-width: 900px;
    height: 85vh;
    max-height: 85vh;
    overflow: hidden;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
    animation: slideUp 0.3s ease;
    display: flex;
    flex-direction: column;
}

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

.template-modal-header {
    padding: 1.5rem;
    border-bottom: 1px solid #333;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

.template-modal-header h2 {
    margin: 0;
    color: #e0e0e0;
    font-size: 24px;
}

.template-modal-close {
    background: none;
    border: none;
    color: #888;
    font-size: 32px;
    cursor: pointer;
    padding: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.3s ease;
    line-height: 1;
}

.template-modal-close:hover {
    color: #e0e0e0;
}

/* Template Search */
.template-search-container {
    padding: 1rem 1.5rem;
    border-bottom: 1px solid #333;
    position: relative;
    flex-shrink: 0;
}

.template-search-input {
    width: 100%;
    padding: 12px 45px 12px 15px;
    background: rgba(255, 255, 255, 0.05);
    border: 2px solid #333;
    border-radius: 8px;
    color: #e0e0e0;
    font-size: 15px;
    transition: all 0.3s ease;
}

.template-search-input:focus {
    outline: none;
    border-color: #007acc;
    background: rgba(255, 255, 255, 0.08);
}

.template-search-input::placeholder {
    color: #666;
}

.template-search-icon {
    position: absolute;
    right: 2rem;
    top: 50%;
    transform: translateY(-50%);
    color: #666;
    pointer-events: none;
}

.template-modal-body {
    padding: 1.5rem;
    overflow-y: auto;
    flex: 1;
    min-height: 0;
}

.template-section {
    margin-bottom: 2rem;
}

.template-section:last-child {
    margin-bottom: 0;
}

.template-section h3 {
    margin: 0 0 1rem 0;
    color: #e0e0e0;
    font-size: 18px;
    font-weight: 600;
}

.template-card {
    background: rgba(255, 255, 255, 0.05);
    border: 2px solid #333;
    border-radius: 10px;
    padding: 1.25rem;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    gap: 1rem;
}

.template-card:hover {
    border-color: #007acc;
    background: rgba(0, 122, 204, 0.1);
    transform: translateY(-2px);
}

.template-card.featured {
    border-color: #8b5cf6;
    background: linear-gradient(135deg, rgba(139, 92, 246, 0.1) 0%, rgba(0, 122, 204, 0.05) 100%);
}

.template-card.featured:hover {
    border-color: #a78bfa;
}

.template-icon {
    flex-shrink: 0;
    width: 48px;
    height: 48px;
    background: linear-gradient(135deg, #007acc 0%, #0098ff 100%);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
}

.template-card.featured .template-icon {
    background: linear-gradient(135deg, #8b5cf6 0%, #a78bfa 100%);
}

.template-info {
    flex: 1;
}

.template-info h4 {
    margin: 0 0 0.5rem 0;
    color: #e0e0e0;
    font-size: 16px;
    font-weight: 600;
}

.template-info p {
    margin: 0 0 0.75rem 0;
    color: #b0b0b0;
    font-size: 14px;
    line-height: 1.5;
}

.template-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.template-tags .tag {
    padding: 4px 10px;
    background: rgba(0, 122, 204, 0.2);
    border: 1px solid #007acc;
    border-radius: 12px;
    font-size: 12px;
    color: #00d4ff;
    font-weight: 500;
}

.templates-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1rem;
}

@media (max-width: 768px) {
    .templates-grid {
        grid-template-columns: 1fr;
    }

    .template-modal-content {
        width: 95%;
        max-height: 90vh;
    }
}

/* Dynamic Preview Styles */
.app-preview-container {
    display: none;
    width: 100%;
}

.app-preview-container.visible {
    display: block;
    animation: fadeIn 0.5s ease;
}

/* Adjust preview sizes for different devices */
.phone-device.ipad-pro .app-preview-container,
.phone-device.tablet .app-preview-container {
    /* Removed max-width for full RHS width */
}

.phone-device.iphone-pro-max .app-preview-container,
.phone-device.phone-max .app-preview-container {
    /* Removed max-width for full RHS width */
}

.preview-placeholder {
    text-align: center;
    color: var(--text-secondary);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
}

.placeholder-icon {
    font-size: 2rem;
    color: var(--accent-purple);
    opacity: 0.5;
}

.dynamic-preview {
    width: 100%;
}

.todo-preview, .form-preview, .generic-preview {
    background: rgba(255, 255, 255, 0.05);
    border-radius: 8px;
    padding: 1rem;
    border: 1px solid var(--border);
    font-size: 0.8rem;
}

.todo-preview h3, .form-preview h3, .generic-preview h3 {
    margin: 0 0 0.75rem 0;
    color: var(--text-primary);
    font-size: 0.9rem;
    text-align: center;
}

.todo-item {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    margin-bottom: 0.5rem;
    padding: 0.3rem;
    background: rgba(255, 255, 255, 0.02);
    border-radius: 4px;
}

.todo-item input[type="checkbox"] {
    margin: 0;
    transform: scale(0.8);
}

.todo-item label {
    color: var(--text-primary);
    font-size: 0.75rem;
    cursor: pointer;
    flex: 1;
}

.add-task {
    display: flex;
    gap: 0.3rem;
    margin-top: 0.75rem;
}

.add-task input {
    flex: 1;
    padding: 0.3rem;
    border: 1px solid var(--border);
    border-radius: 3px;
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-primary);
    font-size: 0.7rem;
}

.add-task button, .submit-btn {
    padding: 0.3rem 0.6rem;
    background: var(--accent-purple);
    color: white;
    border: none;
    border-radius: 3px;
    font-size: 0.7rem;
    cursor: pointer;
}

.add-task button:hover, .submit-btn:hover {
    background: #7c3aed;
}

.form-group-mockup {
    margin-bottom: 0.75rem;
}

.form-group-mockup label {
    display: block;
    font-size: 0.7rem;
    color: var(--text-secondary);
    margin-bottom: 0.2rem;
}

.form-group-mockup input, .form-group-mockup textarea {
    width: 100%;
    padding: 0.3rem;
    border: 1px solid var(--border);
    border-radius: 3px;
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-primary);
    font-size: 0.7rem;
    box-sizing: border-box;
}

.form-group-mockup textarea {
    height: 40px;
    resize: vertical;
}

.feature-list {
    margin-top: 0.75rem;
}

.feature {
    padding: 0.15rem 0;
    color: var(--text-secondary);
    font-size: 0.7rem;
}

.app-link {
    display: inline-block;
    padding: 0.75rem 1.5rem;
    background: var(--accent-gradient);
    color: white !important;
    text-decoration: none;
    font-weight: 600;
    border-radius: 8px;
    transition: all 0.3s ease;
    box-shadow: 0 4px 12px rgba(139, 92, 246, 0.3);
    margin: 0.5rem 0;
}

.app-link:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(139, 92, 246, 0.4);
    background: linear-gradient(135deg, var(--accent-purple) 0%, var(--accent-cyan) 100%);
    filter: brightness(1.1);
    text-decoration: none;
}

.app-link:active {
    transform: translateY(0);
    box-shadow: 0 2px 8px rgba(139, 92, 246, 0.3);
}

.user-mode-submit:hover {
    background: #005a9e;
}

.user-mode-submit:active {
    transform: translateY(1px);
}

/* Device Selector */
.device-selector {
    display: flex;
    gap: 0.75rem;
    justify-content: center;
    align-items: center;
    margin-top: auto;
    padding: 1rem;
    flex-wrap: wrap;
}

.device-btn {
    width: 60px;
    height: 50px;
    border: 2px solid #333;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.05);
    color: #888;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s ease;
    font-size: 0.8rem;
    position: relative;
    overflow: visible;
}

.device-btn::after {
    content: attr(title);
    position: absolute;
    bottom: -25px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 0.65rem;
    color: #666;
    white-space: nowrap;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.device-btn:hover::after {
    opacity: 1;
}

.device-btn:hover {
    border-color: #007acc;
    color: #007acc;
    background: rgba(0, 122, 204, 0.1);
}

.device-btn.active {
    border-color: #007acc;
    color: #007acc;
    background: rgba(0, 122, 204, 0.2);
}

.device-btn i {
    font-size: 1.4rem;
    margin-bottom: 2px;
}

/* Device-specific icon styling */
.device-btn[data-device="iphone-pro"] i,
.device-btn[data-device="phone"] i {
    font-size: 1.3rem;
}

.device-btn[data-device="iphone-pro-max"] i,
.device-btn[data-device="phone-max"] i {
    font-size: 1.5rem;
}

.device-btn[data-device="ipad-pro"] i,
.device-btn[data-device="tablet"] i {
    font-size: 1.6rem;
}

/* Expand Controls */
.expand-controls {
    position: absolute;
    top: 1rem;
    right: 1rem;
    z-index: 100;
}

.expand-btn {
    width: 40px;
    height: 40px;
    border: 2px solid #333;
    border-radius: 8px;
    background: rgba(0, 0, 0, 0.8);
    color: #888;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s ease;
    font-size: 1rem;
    backdrop-filter: blur(10px);
}

.expand-btn:hover {
    border-color: #007acc;
    color: #007acc;
    background: rgba(0, 122, 204, 0.1);
}

/* Expanded State Styles */
.user-mode-container.expanded {
    position: fixed;
    top: 70px;
    left: 0;
    right: 0;
    bottom: 40px;
    z-index: 1000;
    background: var(--primary-bg);
    flex-direction: row;
    padding: 1rem;
}

.user-mode-container.expanded .left-container {
    display: none;
}

.user-mode-container.expanded .right-container {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Expand/Restore Button */
.expand-toggle-btn {
    padding: 0.5rem 1rem;
    background: rgba(255, 255, 255, 0.1);
    color: rgba(255, 255, 255, 0.8);
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 6px;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
    margin-right: 0.5rem;
    display: none;
    align-items: center;
    gap: 0.5rem;
}

.expand-toggle-btn:hover {
    background: rgba(0, 122, 204, 0.2);
    border-color: #007acc;
    color: #007acc;
    transform: translateY(-1px);
}

.expand-toggle-btn i {
    transition: transform 0.3s ease;
    font-size: 14px;
}

.user-mode-container.expanded .device-preview {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

/* Expanded view: same principle — no fixed width */
.user-mode-container.expanded .phone-device {
    height: calc(100% - 40px);
    width: auto;
    max-width: none;
    max-height: none;
    /* aspect-ratio remains per device */
    transform: none; /* avoid visual distortion/blurriness */
    transition: all 0.5s ease;
}

.user-mode-container.expanded .phone-device.iphone-pro-max,
.user-mode-container.expanded .phone-device.phone-max {
    height: calc(100% - 40px);
}

.user-mode-container.expanded .phone-device.ipad-pro,
.user-mode-container.expanded .phone-device.tablet {
    height: calc(100% - 40px);
}

/* Adjust expand button for expanded state */
.user-mode-container.expanded .expand-btn {
    background: rgba(0, 0, 0, 0.9);
    border-color: #007acc;
    color: #007acc;
}

/* Phone Toggle Styles */
.phone-toggle {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-right: 1rem;
}

.phone-toggle .toggle-switch {
    position: relative;
    display: inline-block;
    width: 50px;
    height: 24px;
}

.phone-toggle .toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.phone-toggle .slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #333;
    transition: 0.3s;
    border-radius: 24px;
}

.phone-toggle .slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: 0.3s;
    border-radius: 50%;
}

.phone-toggle input:checked + .slider {
    background-color: var(--accent-purple);
}

.phone-toggle input:checked + .slider:before {
    transform: translateX(26px);
}

.phone-toggle .mode-label {
    color: var(--text-primary);
    font-size: 0.9rem;
    font-weight: 500;
}

/* Maximized Container Styles */
.maximized-container {
    width: 49%;
    height: 100%;
    display: flex;
    flex-direction: column;
    background: var(--secondary-bg);
    border-radius: 12px;
    border: 1px solid var(--border);
    overflow: hidden;
}

.maximized-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 2rem;
    min-height: 0;
}

/* Maximized Building Status */
.building-status.maximized {
    width: 100%;
    text-align: center;
    color: var(--text-secondary);
    margin-bottom: 3rem;
}

.building-status.maximized .spinner {
    width: 60px;
    height: 60px;
    border: 4px solid var(--border);
    border-top: 4px solid var(--accent-purple);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 1.5rem;
}

.building-status.maximized p {
    font-size: 1.2rem;
    margin: 0;
}

/* Maximized Preview Container */
.app-preview-container.maximized {
    width: 100%;
    height: auto;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}

.app-preview-container.maximized .preview-placeholder {
    text-align: center;
    color: var(--text-secondary);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.5rem;
}

.app-preview-container.maximized .placeholder-icon {
    font-size: 4rem;
    color: var(--accent-purple);
    opacity: 0.5;
}

.app-preview-container.maximized .placeholder-icon p {
    font-size: 1.1rem;
}

/* Maximized Dynamic Preview */
.dynamic-preview.maximized {
    width: 100%;
    max-width: 500px;
    animation: fadeIn 0.5s ease;
}

.dynamic-preview.maximized .todo-preview,
.dynamic-preview.maximized .form-preview,
.dynamic-preview.maximized .generic-preview {
    background: rgba(255, 255, 255, 0.05);
    border-radius: 12px;
    padding: 2rem;
    border: 1px solid var(--border);
}

.dynamic-preview.maximized h3 {
    margin: 0 0 1.5rem 0;
    color: var(--text-primary);
    font-size: 1.5rem;
    text-align: center;
}

.dynamic-preview.maximized .todo-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 1rem;
    padding: 0.75rem;
    background: rgba(255, 255, 255, 0.02);
    border-radius: 8px;
}

.dynamic-preview.maximized .todo-item label {
    color: var(--text-primary);
    font-size: 1rem;
    cursor: pointer;
    flex: 1;
}

.dynamic-preview.maximized .add-task {
    display: flex;
    gap: 0.75rem;
    margin-top: 1.5rem;
}

.dynamic-preview.maximized .add-task input {
    flex: 1;
    padding: 0.75rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-primary);
    font-size: 1rem;
}

.dynamic-preview.maximized .add-task button,
.dynamic-preview.maximized .submit-btn {
    padding: 0.75rem 1.5rem;
    background: var(--accent-purple);
    color: white;
    border: none;
    border-radius: 6px;
    font-size: 1rem;
    cursor: pointer;
}

.dynamic-preview.maximized .form-group-mockup {
    margin-bottom: 1.5rem;
}

.dynamic-preview.maximized .form-group-mockup label {
    display: block;
    font-size: 1rem;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
}

.dynamic-preview.maximized .form-group-mockup input,
.dynamic-preview.maximized .form-group-mockup textarea {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-primary);
    font-size: 1rem;
    box-sizing: border-box;
}

.dynamic-preview.maximized .form-group-mockup textarea {
    height: 80px;
    resize: vertical;
}

.dynamic-preview.maximized .feature-list {
    margin-top: 1.5rem;
}

.dynamic-preview.maximized .feature {
    padding: 0.5rem 0;
    color: var(--text-secondary);
    font-size: 1rem;
}

/* Layout adjustments when maximized view is active */
.user-mode-container.maximized-view {
    gap: 2%;
}

.user-mode-container.maximized-view .right-container {
    display: none;
}

.user-mode-container.maximized-view .maximized-container {
    display: flex;
}

/* ============================================
   App Preview Panel (v2 - No Phone Template)
   ============================================ */

.app-preview-panel {
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 100%;
    background: #1a1a1a;
    overflow: hidden;
}

.app-preview-panel .preview-header {
    background: #252936;
    border-bottom: 1px solid #3f4354;
    padding: 0.75rem 1rem;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    position: relative;
}

.app-preview-panel .preview-header h3 {
    margin: 0;
    color: white;
    font-size: 1.1rem;
    font-weight: 600;
    flex: 1;
}

#pageTabs {
    display: flex;
    gap: 0.5rem;
    overflow-x: auto;
    overflow-y: hidden;
    flex: 1;
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.3) transparent;
}

#pageTabs::-webkit-scrollbar {
    height: 6px;
}

#pageTabs::-webkit-scrollbar-track {
    background: transparent;
}

#pageTabs::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.3);
    border-radius: 3px;
}

#pageTabs::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.5);
}

.app-preview-panel .building-status {
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 3rem 2rem;
    gap: 1.5rem;
    background: #0f0f0f;
    flex: 1;
}

.app-preview-panel .building-status .spinner {
    width: 60px;
    height: 60px;
    border: 4px solid rgba(139, 92, 246, 0.2);
    border-top-color: var(--accent-purple);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

.app-preview-panel .building-status p {
    color: #e0e0e0;
    font-size: 1rem;
    margin: 0;
}

.app-preview-panel .app-preview-container {
    flex: 1;
    display: flex;
    align-items: stretch;
    justify-content: stretch;
    background: #0f0f0f;
    position: relative;
    overflow: hidden;
    width: 100%;
}

.app-preview-panel .preview-placeholder {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    color: #666;
    z-index: 1;
}

.app-preview-panel .preview-placeholder .placeholder-icon {
    font-size: 3rem;
    opacity: 0.5;
}

.app-preview-panel .preview-placeholder p {
    font-size: 1rem;
    margin: 0;
}

.app-preview-panel #appIframe {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 2;
    border: none;
    display: block;
}

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

/* Prompt History Dots */
.prompt-history {
    display: none;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 12px;
    margin-top: 40px;
    padding: 8px;
    background: rgba(255, 255, 255, 0.02);
    border-radius: 8px;
    border: 1px solid #333;
    max-height: 80px;
    overflow: visible !important;
    position: relative;
}

.view-history-btn {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 28px;
    height: 28px;
    background: rgba(0, 122, 204, 0.2);
    border: 1px solid #007acc;
    border-radius: 6px;
    color: #007acc;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s ease;
    font-size: 14px;
}

.view-history-btn:hover {
    background: rgba(0, 122, 204, 0.3);
    transform: scale(1.1);
}

.history-dot {
    position: relative;
    width: 12px;
    height: 12px;
    background: linear-gradient(135deg, #007acc 0%, #00d4ff 100%);
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.3s ease;
    flex-shrink: 0;
}

.history-dot:hover {
    transform: scale(1.3);
    box-shadow: 0 0 12px rgba(0, 212, 255, 0.6);
}

/* Tooltip element */
.history-dot-tooltip {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.95);
    color: #e0e0e0;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 13px;
    white-space: nowrap;
    max-width: 300px;
    overflow: hidden;
    text-overflow: ellipsis;
    z-index: 9999;
    pointer-events: none;
    border: 1px solid #00d4ff;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s ease, visibility 0.2s ease;
}

.history-dot:hover .history-dot-tooltip {
    opacity: 1;
    visibility: visible;
}
/* History Modal */
.history-modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
    animation: fadeIn 0.3s ease;
}

.history-modal.show {
    display: flex;
    align-items: center;
    justify-content: center;
}

.history-modal-content {
    background: #1e1e1e;
    border-radius: 12px;
    width: 90%;
    max-width: 700px;
    max-height: 80vh;
    overflow: hidden;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
    animation: slideUp 0.3s ease;
    display: flex;
    flex-direction: column;
}

.history-modal-header {
    padding: 1.5rem;
    border-bottom: 1px solid #333;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

.history-modal-header h2 {
    margin: 0;
    color: #e0e0e0;
    font-size: 24px;
}

.history-modal-close {
    background: none;
    border: none;
    color: #888;
    font-size: 32px;
    cursor: pointer;
    padding: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.3s ease;
    line-height: 1;
}

.history-modal-close:hover {
    color: #e0e0e0;
}

.history-modal-body {
    padding: 1.5rem;
    overflow-y: auto;
    flex: 1;
    min-height: 0;
}

.history-item {
    background: rgba(255, 255, 255, 0.05);
    border: 2px solid #333;
    border-radius: 10px;
    padding: 1rem;
    margin-bottom: 1rem;
    display: flex;
    gap: 1rem;
    align-items: center;
    transition: all 0.3s ease;
}

.history-item:hover {
    border-color: #007acc;
    background: rgba(0, 122, 204, 0.1);
}

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

.history-item-text {
    color: #e0e0e0;
    font-size: 15px;
    line-height: 1.5;
    word-wrap: break-word;
}

.history-item-actions {
    display: flex;
    gap: 0.5rem;
    flex-shrink: 0;
}

.history-use-btn,
.history-delete-btn {
    width: 36px;
    height: 36px;
    border: none;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s ease;
    font-size: 14px;
}

.history-use-btn {
    background: #007acc;
    color: white;
}

.history-use-btn:hover {
    background: #0098ff;
    transform: scale(1.1);
}

.history-delete-btn {
    background: rgba(255, 68, 68, 0.2);
    color: #ff4444;
}

.history-delete-btn:hover {
    background: #ff4444;
    color: white;
    transform: scale(1.1);
}
/* Quick Actions Bar */
.quick-actions-bar {
    display: flex;
    gap: 0.75rem;
    margin-top: 1rem;
    padding: 0.75rem;
    background: rgba(255, 255, 255, 0.03);
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.quick-action-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.625rem 1rem;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    border-radius: 6px;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    flex: 1;
}

.quick-action-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

.quick-action-btn:active {
    transform: translateY(0);
}

.quick-action-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.quick-action-btn svg {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
}

/* Layout Modal */
.layout-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(4px);
    z-index: 10000;
    align-items: center;
    justify-content: center;
}

.layout-modal.show {
    display: flex;
}

.layout-modal-content {
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
    border-radius: 16px;
    max-width: 900px;
    width: 90%;
    max-height: 85vh;
    overflow: hidden;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.layout-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.5rem 2rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.layout-modal-header h2 {
    margin: 0;
    font-size: 1.5rem;
    font-weight: 600;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.layout-modal-close {
    background: none;
    border: none;
    color: #888;
    font-size: 2rem;
    cursor: pointer;
    padding: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    border-radius: 50%;
}

.layout-modal-close:hover {
    background: rgba(255, 255, 255, 0.1);
    color: white;
}

.layout-modal-body {
    padding: 2rem;
    overflow-y: auto;
    max-height: calc(85vh - 100px);
}

.layout-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 1.5rem;
}

.layout-card {
    background: rgba(255, 255, 255, 0.03);
    border: 2px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    padding: 1rem;
    cursor: pointer;
    transition: all 0.3s ease;
}

.layout-card:hover {
    transform: translateY(-4px);
    border-color: #667eea;
    background: rgba(102, 126, 234, 0.1);
    box-shadow: 0 8px 24px rgba(102, 126, 234, 0.2);
}

.layout-preview {
    background: rgba(0, 0, 0, 0.3);
    border-radius: 8px;
    height: 120px;
    margin-bottom: 1rem;
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.layout-card h4 {
    margin: 0 0 0.5rem 0;
    font-size: 1rem;
    font-weight: 600;
    color: #e0e0e0;
}

.layout-card p {
    margin: 0;
    font-size: 0.8rem;
    color: #888;
    line-height: 1.4;
}

/* Responsive adjustments */
@media (max-width: 768px) {
    .layout-grid {
        grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
        gap: 1rem;
    }

    .layout-modal-content {
        width: 95%;
        max-height: 90vh;
    }

    .layout-modal-body {
        padding: 1rem;
    }

    .quick-actions-bar {
        flex-direction: column;
    }

    .quick-action-btn {
        width: 100%;
    }
}

/* My Apps Modal */
.my-apps-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 10px 20px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

.my-apps-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

.apps-list {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    padding: 1rem 0;
}

.app-item {
    background: rgba(255, 255, 255, 0.03);
    border: 2px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    padding: 1.25rem;
    display: grid;
    grid-template-columns: 1fr auto;
    grid-template-rows: auto auto auto;
    gap: 0.5rem 1rem;
    transition: all 0.3s ease;
}

.app-item:hover {
    border-color: #667eea;
    background: rgba(102, 126, 234, 0.1);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.2);
}

.app-item.running {
    border-color: #4ade80;
    background: rgba(74, 222, 128, 0.05);
}

.app-header {
    grid-column: 1;
    grid-row: 1;
}

.app-actions {
    grid-column: 2;
    grid-row: 1;
    justify-self: end;
    align-self: center;
    display: flex;
    gap: 0.5rem;
}

.app-header h4 {
    margin: 0 0 0.5rem 0;
    font-size: 1.1rem;
    color: #e0e0e0;
}

.app-description {
    margin: 0 0 0.75rem 0;
    font-size: 0.875rem;
    color: #999;
    line-height: 1.4;
}

.app-meta {
    grid-column: 1 / -1;
    grid-row: 2;
    display: flex;
    gap: 1rem;
    align-items: center;
}


.app-id {
    font-family: 'Courier New', monospace;
    font-size: 0.75rem;
    color: #666;
    background: rgba(255, 255, 255, 0.05);
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
}

.app-date {
    font-size: 0.75rem;
    color: #888;
    background: rgba(255, 255, 255, 0.03);
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
}

.app-status {
    font-size: 0.75rem;
    padding: 0.25rem 0.75rem;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.05);
    color: #999;
}

.app-status.running {
    background: rgba(74, 222, 128, 0.2);
    color: #4ade80;
}

.app-version {
    font-size: 0.7rem;
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
    background: rgba(139, 92, 246, 0.15);
    color: #a78bfa;
    font-family: 'Courier New', monospace;
    margin-left: auto;
}

.app-version.needs-rebuild {
    background: rgba(251, 191, 36, 0.2);
    color: #fbbf24;
}

.app-action-btn {
    display: flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.5rem 0.875rem;
    border: none;
    border-radius: 6px;
    font-size: 0.8125rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

.app-action-btn svg {
    flex-shrink: 0;
}

.view-btn {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.view-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(102, 126, 234, 0.4);
}

.start-btn {
    background: linear-gradient(135deg, #4ade80 0%, #22c55e 100%);
    color: white;
}

.start-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(74, 222, 128, 0.4);
}

.delete-btn {
    background: rgba(239, 68, 68, 0.1);
    color: #ef4444;
    border: 1px solid rgba(239, 68, 68, 0.3);
}

.delete-btn:hover {
    background: rgba(239, 68, 68, 0.2);
    transform: translateY(-2px);
}

.rebuild-btn {
    background: rgba(251, 191, 36, 0.15);
    color: #fbbf24;
    border: 1px solid rgba(251, 191, 36, 0.3);
}

.rebuild-btn:hover {
    background: rgba(251, 191, 36, 0.25);
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(251, 191, 36, 0.2);
}

/* Rebuild Progress Modal */
.rebuild-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.85);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.rebuild-modal.show {
    opacity: 1;
    visibility: visible;
}

.rebuild-modal-content {
    background: #1e1e2e;
    border-radius: 16px;
    padding: 2rem;
    width: 90%;
    max-width: 500px;
    box-shadow: 0 25px 50px rgba(0, 0, 0, 0.5);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.rebuild-modal-header {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.rebuild-modal-header .icon {
    width: 48px;
    height: 48px;
    background: linear-gradient(135deg, #fbbf24 0%, #f59e0b 100%);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.rebuild-modal-header .icon svg {
    width: 24px;
    height: 24px;
    color: #1e1e2e;
}

.rebuild-modal-header h3 {
    margin: 0;
    font-size: 1.25rem;
    color: #fff;
}

.rebuild-modal-header .app-name {
    font-size: 0.875rem;
    color: #888;
    margin-top: 0.25rem;
}

.rebuild-progress-container {
    background: rgba(0, 0, 0, 0.3);
    border-radius: 12px;
    padding: 1.5rem;
    margin-bottom: 1.5rem;
}

.rebuild-step {
    display: flex;
    align-items: flex-start;
    gap: 1rem;
    padding: 0.75rem 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.rebuild-step:last-child {
    border-bottom: none;
}

.rebuild-step-icon {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    background: rgba(255, 255, 255, 0.1);
    color: #666;
    font-size: 12px;
}

.rebuild-step.pending .rebuild-step-icon {
    background: rgba(255, 255, 255, 0.1);
    color: #666;
}

.rebuild-step.active .rebuild-step-icon {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    animation: pulse 1.5s ease-in-out infinite;
}

.rebuild-step.complete .rebuild-step-icon {
    background: #22c55e;
    color: white;
}

.rebuild-step.error .rebuild-step-icon {
    background: #ef4444;
    color: white;
}

@keyframes pulse {
    0%, 100% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.1); opacity: 0.8; }
}

.rebuild-step-content {
    flex: 1;
}

.rebuild-step-title {
    font-size: 0.9375rem;
    color: #fff;
    margin: 0 0 0.25rem 0;
}

.rebuild-step.pending .rebuild-step-title {
    color: #666;
}

.rebuild-step-detail {
    font-size: 0.8125rem;
    color: #888;
    margin: 0;
}

.rebuild-step.active .rebuild-step-detail {
    color: #a78bfa;
}

.rebuild-overall-progress {
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.rebuild-progress-bar {
    height: 6px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
    overflow: hidden;
}

.rebuild-progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #667eea 0%, #764ba2 100%);
    border-radius: 3px;
    transition: width 0.3s ease;
    width: 0%;
}

.rebuild-progress-text {
    display: flex;
    justify-content: space-between;
    margin-top: 0.5rem;
    font-size: 0.75rem;
    color: #888;
}

.rebuild-modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
}

.rebuild-modal-actions button {
    padding: 0.625rem 1.25rem;
    border-radius: 8px;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

.rebuild-cancel-btn {
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.rebuild-cancel-btn:hover {
    background: rgba(255, 255, 255, 0.15);
}

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

.rebuild-done-btn {
    background: linear-gradient(135deg, #22c55e 0%, #16a34a 100%);
    color: white;
    border: none;
    display: none;
}

.rebuild-done-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(34, 197, 94, 0.3);
}

.no-apps, .loading-apps, .error-loading {
    text-align: center;
    padding: 3rem 1rem;
    color: #999;
    font-size: 1rem;
}

.error-loading {
    color: #ef4444;
}

/* Confirmation Dialog */
.confirm-dialog {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(4px);
    z-index: 10001;
    align-items: center;
    justify-content: center;
}

.confirm-dialog.show {
    display: flex;
}

.confirm-dialog-content {
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
    border-radius: 16px;
    padding: 2rem;
    max-width: 400px;
    width: 90%;
    text-align: center;
    border: 2px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
    animation: confirmSlideIn 0.3s ease-out;
}

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

.confirm-dialog-icon {
    font-size: 3rem;
    margin-bottom: 1rem;
}

.confirm-dialog-content h3 {
    margin: 0 0 1rem 0;
    font-size: 1.5rem;
    color: #e0e0e0;
}

.confirm-dialog-content p {
    margin: 0 0 2rem 0;
    font-size: 1rem;
    color: #999;
    line-height: 1.5;
}

.confirm-dialog-buttons {
    display: flex;
    gap: 1rem;
    justify-content: center;
}

.confirm-dialog-buttons button {
    padding: 0.75rem 1.5rem;
    border-radius: 8px;
    font-size: 0.9375rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    min-width: 100px;
}

.cancel-btn {
    background: rgba(255, 255, 255, 0.1);
    color: #e0e0e0;
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.cancel-btn:hover {
    background: rgba(255, 255, 255, 0.15);
    transform: translateY(-2px);
}

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

.confirm-btn:not(.cancel-btn) {
    background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
    color: white;
    border: none;
}

.confirm-btn:not(.cancel-btn):hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(239, 68, 68, 0.4);
}

.confirm-btn.loading {
    opacity: 0.7;
    cursor: not-allowed;
    pointer-events: none;
}

/* Version mismatch dialog styles */
.version-details {
    font-family: monospace;
    font-size: 0.875rem;
    background: rgba(0, 0, 0, 0.3);
    padding: 0.5rem 1rem;
    border-radius: 6px;
    color: #6dd5ed;
    margin-bottom: 1.5rem !important;
}

.confirm-btn.loading::after {
    content: '';
    display: inline-block;
    width: 12px;
    height: 12px;
    margin-left: 8px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

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

.ok-btn {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.ok-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

/* Hide main content until auth is determined */
.header,
.user-mode-content,
.footer {
    opacity: 0;
    transition: opacity 0.2s ease;
}

.app-container.auth-ready .header,
.app-container.auth-ready .user-mode-content,
.app-container.auth-ready .footer {
    opacity: 1;
}

/* Full Page Login Styles */
.login-page {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, #0f0f1a 0%, #1a1a2e 50%, #16213e 100%);
    z-index: 9999;
    overflow: auto;
}

.login-page.show {
    display: flex;
    align-items: center;
    justify-content: center;
}

.login-page-container {
    width: 100%;
    max-width: 420px;
    padding: 2rem;
    text-align: center;
}

.login-page-header {
    margin-bottom: 2rem;
}

.login-logo {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
}

.login-logo .beetle-icon {
    width: 60px;
    height: 60px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.75rem;
    color: white;
    box-shadow: 0 4px 20px rgba(102, 126, 234, 0.4);
}

.login-logo .logo-text h1 {
    font-size: 2rem;
    margin: 0;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.login-logo .logo-text .tagline {
    font-size: 0.875rem;
    color: #888;
}

.login-page-card {
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
    border-radius: 20px;
    padding: 2.5rem;
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}

.login-page-card h2 {
    margin: 0 0 0.5rem 0;
    font-size: 1.75rem;
    color: #e0e0e0;
}

.login-subtitle {
    margin: 0 0 2rem 0;
    color: #888;
    font-size: 0.9375rem;
}

.login-form {
    text-align: left;
}

.login-field {
    margin-bottom: 1.25rem;
}

.login-field label {
    display: block;
    font-size: 0.875rem;
    color: #e0e0e0;
    margin-bottom: 0.5rem;
    font-weight: 500;
}

.login-field input {
    width: 100%;
    padding: 0.875rem 1rem;
    border-radius: 10px;
    border: 1px solid rgba(255, 255, 255, 0.15);
    background: rgba(0, 0, 0, 0.3);
    color: #e0e0e0;
    font-size: 1rem;
    transition: all 0.2s ease;
    box-sizing: border-box;
}

.login-field input:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.2);
}

.login-field input::placeholder {
    color: #666;
}

.password-input-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}

.password-input-wrapper input {
    padding-right: 3rem;
}

.password-toggle {
    position: absolute;
    right: 0.75rem;
    background: none;
    border: none;
    color: #666;
    cursor: pointer;
    padding: 0.25rem;
    font-size: 1rem;
    transition: color 0.2s ease;
}

.password-toggle:hover {
    color: #e0e0e0;
}

.login-error {
    color: #ef4444;
    font-size: 0.875rem;
    margin-bottom: 1rem;
    padding: 0.75rem 1rem;
    background: rgba(239, 68, 68, 0.1);
    border-radius: 8px;
    display: none;
    text-align: center;
}

.login-error.show {
    display: block;
}

.password-requirements {
    font-size: 0.8rem;
    color: rgba(255, 255, 255, 0.5);
    margin-bottom: 1rem;
    text-align: center;
}

.password-requirements p {
    margin: 0;
}

.login-submit-btn {
    width: 100%;
    padding: 1rem;
    border-radius: 10px;
    border: none;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    margin-top: 0.5rem;
}

.login-submit-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 20px rgba(102, 126, 234, 0.4);
}

.login-submit-btn:disabled {
    opacity: 0.7;
    cursor: not-allowed;
    transform: none;
}

.login-submit-btn.loading {
    position: relative;
    color: transparent;
}

.login-submit-btn.loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 20px;
    height: 20px;
    margin: -10px 0 0 -10px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

.login-footer-text {
    margin-top: 2rem;
    color: #666;
    font-size: 0.8125rem;
}

.login-version {
    margin-top: 0.5rem;
    color: #888;
    font-size: 0.75rem;
}

/* Quick Start Guide Styles */
.quick-start-page {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, #0f0f1a 0%, #1a1a2e 50%, #16213e 100%);
    z-index: 9998;
    overflow: auto;
}

.quick-start-page.show {
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 2rem;
}

.quick-start-container {
    width: 100%;
    max-width: 900px;
    padding: 2rem 0;
}

.quick-start-header {
    text-align: center;
    margin-bottom: 2.5rem;
}

.quick-start-header h1 {
    font-size: 2rem;
    color: #e0e0e0;
    margin: 0 0 0.5rem 0;
}

.quick-start-subtitle {
    font-size: 1rem;
    color: #888;
    margin: 0;
}

.quick-start-steps {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.quick-start-step {
    display: grid;
    grid-template-columns: auto 1fr 1fr;
    gap: 1.25rem;
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
    border-radius: 12px;
    padding: 1.25rem 1.5rem;
    border: 1px solid rgba(255, 255, 255, 0.08);
    align-items: start;
}

.step-number {
    width: 36px;
    height: 36px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    font-weight: 600;
    color: white;
    flex-shrink: 0;
}

.step-content h3 {
    margin: 0 0 0.5rem 0;
    font-size: 1rem;
    font-weight: 600;
    color: #e0e0e0;
}

.step-content p {
    margin: 0;
    font-size: 0.875rem;
    color: #999;
    line-height: 1.5;
}

.step-how {
    padding-left: 1rem;
    border-left: 1px solid rgba(255, 255, 255, 0.1);
}

.how-label {
    display: block;
    font-size: 0.75rem;
    color: #666;
    margin-bottom: 0.25rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.step-how p {
    margin: 0;
    font-size: 0.875rem;
    color: #888;
    line-height: 1.5;
}

.step-how strong {
    color: #6dd5ed;
}

.quick-start-footer {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.25rem;
    margin-top: 2rem;
}

.dont-show-again {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    color: #888;
    font-size: 0.875rem;
}

.dont-show-again input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: #667eea;
    cursor: pointer;
}

.quick-start-btn {
    padding: 0.875rem 3rem;
    border-radius: 8px;
    border: none;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.quick-start-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 20px rgba(102, 126, 234, 0.4);
}

.quick-start-buttons {
    display: flex;
    gap: 1rem;
    align-items: center;
}

.quick-start-btn-secondary {
    padding: 0.875rem 2rem;
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    background: transparent;
    color: #e0e0e0;
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

.quick-start-btn-secondary:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.3);
}

/* Responsive Quick Start */
@media (max-width: 768px) {
    .quick-start-step {
        grid-template-columns: auto 1fr;
        gap: 1rem;
    }

    .step-how {
        grid-column: 2;
        padding-left: 0;
        padding-top: 0.75rem;
        border-left: none;
        border-top: 1px solid rgba(255, 255, 255, 0.1);
    }

    .quick-start-buttons {
        flex-direction: column;
        width: 100%;
    }

    .quick-start-btn,
    .quick-start-btn-secondary {
        width: 100%;
    }
}

/* Help Manual Viewer Styles */
.help-manual-page {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, #0f0f1a 0%, #1a1a2e 50%, #16213e 100%);
    z-index: 10000;
    overflow: hidden;
}

.help-manual-page.show {
    display: flex;
    flex-direction: column;
}

.help-manual-container {
    display: flex;
    flex-direction: column;
    height: 100%;
    width: 100%;
}

.help-manual-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 2rem;
    background: rgba(0, 0, 0, 0.3);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    flex-shrink: 0;
}

.help-manual-header h1 {
    margin: 0;
    font-size: 1.5rem;
    color: #e0e0e0;
}

.help-manual-close {
    width: 40px;
    height: 40px;
    border-radius: 8px;
    border: none;
    background: rgba(255, 255, 255, 0.1);
    color: #e0e0e0;
    font-size: 1.25rem;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.help-manual-close:hover {
    background: rgba(255, 255, 255, 0.2);
}

.help-manual-content {
    flex: 1;
    overflow: auto;
    padding: 2rem;
}

.help-manual-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    padding: 4rem;
    color: #888;
}

.help-manual-loading i {
    font-size: 2rem;
    color: #667eea;
}

/* Markdown Body Styles */
.markdown-body {
    max-width: 900px;
    margin: 0 auto;
    color: #e0e0e0;
    line-height: 1.7;
}

.markdown-body h1 {
    font-size: 2rem;
    color: #e0e0e0;
    border-bottom: 2px solid rgba(102, 126, 234, 0.3);
    padding-bottom: 0.5rem;
    margin: 2rem 0 1rem 0;
}

.markdown-body h1:first-child {
    margin-top: 0;
}

.markdown-body h2 {
    font-size: 1.5rem;
    color: #e0e0e0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    padding-bottom: 0.5rem;
    margin: 2rem 0 1rem 0;
}

.markdown-body h3 {
    font-size: 1.25rem;
    color: #e0e0e0;
    margin: 1.5rem 0 0.75rem 0;
}

.markdown-body h4 {
    font-size: 1.1rem;
    color: #ccc;
    margin: 1.25rem 0 0.5rem 0;
}

.markdown-body p {
    margin: 0.75rem 0;
    color: #b8bcc8;
}

.markdown-body a {
    color: #6dd5ed;
    text-decoration: none;
}

.markdown-body a:hover {
    text-decoration: underline;
}

.markdown-body strong {
    color: #e0e0e0;
    font-weight: 600;
}

.markdown-body code {
    background: rgba(0, 0, 0, 0.4);
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
    font-size: 0.875rem;
    color: #6dd5ed;
}

.markdown-body pre {
    background: rgba(0, 0, 0, 0.4);
    padding: 1rem;
    border-radius: 8px;
    overflow-x: auto;
    margin: 1rem 0;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.markdown-body pre code {
    background: none;
    padding: 0;
    font-size: 0.875rem;
    color: #e0e0e0;
}

.markdown-body ul,
.markdown-body ol {
    margin: 0.75rem 0;
    padding-left: 1.5rem;
}

.markdown-body li {
    margin: 0.5rem 0;
    color: #b8bcc8;
}

.markdown-body blockquote {
    border-left: 4px solid #667eea;
    margin: 1rem 0;
    padding: 0.5rem 1rem;
    background: rgba(102, 126, 234, 0.1);
    border-radius: 0 8px 8px 0;
}

.markdown-body blockquote p {
    color: #999;
    margin: 0.5rem 0;
}

.markdown-body table {
    width: 100%;
    border-collapse: collapse;
    margin: 1rem 0;
}

.markdown-body th,
.markdown-body td {
    padding: 0.75rem 1rem;
    border: 1px solid rgba(255, 255, 255, 0.1);
    text-align: left;
}

.markdown-body th {
    background: rgba(102, 126, 234, 0.2);
    color: #e0e0e0;
    font-weight: 600;
}

.markdown-body td {
    color: #b8bcc8;
}

.markdown-body tr:nth-child(even) td {
    background: rgba(0, 0, 0, 0.2);
}

.markdown-body hr {
    border: none;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    margin: 2rem 0;
}

.markdown-body img {
    max-width: 100%;
    border-radius: 8px;
    margin: 1rem 0;
}

/* Hide screenshot placeholder images and style their containers */
.markdown-body img[alt="Screenshot Placeholder"] {
    display: none;
}

/* Style screenshot placeholder blockquotes as subtle info boxes */
.markdown-body blockquote:has(strong:first-child) {
    background: rgba(102, 126, 234, 0.05);
    border-left-color: #555;
    padding: 0.5rem 1rem;
    margin: 0.5rem 0;
}

.markdown-body blockquote p:has(img[alt="Screenshot Placeholder"]) {
    display: none;
}

/* ============================================
   EDIT MODE STYLES
   ============================================ */

/* Edit Toolbar */
.edit-toolbar {
    position: fixed;
    top: 50%;
    right: 20px;
    transform: translateY(-50%);
    width: 320px;
    background: #1e1e2e;
    border: 1px solid #2a2a3e;
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    z-index: 10000;
    overflow: hidden;
}

.edit-toolbar-header {
    padding: 16px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.edit-toolbar-title {
    color: white;
    font-weight: 600;
    font-size: 16px;
}

.edit-toolbar-close {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.edit-toolbar-close:hover {
    background: rgba(255, 255, 255, 0.3);
}

.edit-toolbar-content {
    padding: 20px;
}

.edit-panel {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.edit-label {
    color: #b4b4c8;
    font-size: 13px;
    font-weight: 500;
    margin-bottom: 4px;
}

.edit-textarea {
    width: 100%;
    min-height: 80px;
    padding: 10px;
    background: #2a2a3e;
    border: 1px solid #3a3a4e;
    border-radius: 6px;
    color: #e0e0e0;
    font-family: inherit;
    font-size: 14px;
    resize: vertical;
}

.edit-textarea:focus {
    outline: none;
    border-color: #667eea;
}

.edit-input {
    width: 100%;
    padding: 10px;
    background: #2a2a3e;
    border: 1px solid #3a3a4e;
    border-radius: 6px;
    color: #e0e0e0;
    font-size: 14px;
}

.edit-input:focus {
    outline: none;
    border-color: #667eea;
}

.edit-select {
    width: 100%;
    padding: 10px;
    background: #2a2a3e;
    border: 1px solid #3a3a4e;
    border-radius: 6px;
    color: #e0e0e0;
    font-size: 14px;
    cursor: pointer;
}

.edit-select:focus {
    outline: none;
    border-color: #667eea;
}

.edit-color-picker {
    width: 100%;
    height: 40px;
    border: 1px solid #3a3a4e;
    border-radius: 6px;
    background: #2a2a3e;
    cursor: pointer;
}

.edit-divider {
    text-align: center;
    color: #6c6c7e;
    font-size: 12px;
    margin: 8px 0;
}

.edit-buttons {
    display: flex;
    gap: 8px;
    margin-top: 8px;
}

.edit-btn {
    flex: 1;
    padding: 10px;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.edit-btn-cancel {
    background: #3a3a4e;
    color: #b4b4c8;
}

.edit-btn-cancel:hover {
    background: #4a4a5e;
}

.edit-btn-save,
.edit-btn-primary {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.edit-btn-save:hover,
.edit-btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

.image-preview-container {
    width: 100%;
    height: 150px;
    background: #2a2a3e;
    border: 1px solid #3a3a4e;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.image-preview {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

/* Image Gallery Modal */
.image-gallery-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    z-index: 10001;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.image-gallery-content {
    width: 100%;
    max-width: 900px;
    max-height: 90vh;
    background: #1e1e2e;
    border-radius: 12px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.image-gallery-header {
    padding: 20px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.image-gallery-header h2 {
    color: white;
    margin: 0;
    font-size: 20px;
}

.image-gallery-close {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.image-gallery-close:hover {
    background: rgba(255, 255, 255, 0.3);
}

.image-gallery-tabs {
    display: flex;
    gap: 8px;
    padding: 16px 20px;
    background: #2a2a3e;
    border-bottom: 1px solid #3a3a4e;
    overflow-x: auto;
}

.gallery-tab {
    padding: 8px 16px;
    background: #1e1e2e;
    border: 1px solid #3a3a4e;
    border-radius: 6px;
    color: #b4b4c8;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}

.gallery-tab:hover {
    background: #3a3a4e;
}

.gallery-tab.active {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-color: transparent;
}

.image-gallery-grid {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 12px;
}

.gallery-image-card {
    aspect-ratio: 1;
    background: #2a2a3e;
    border: 2px solid #3a3a4e;
    border-radius: 8px;
    overflow: hidden;
    cursor: pointer;
    transition: all 0.2s;
    position: relative;
}

.gallery-image-card:hover {
    border-color: #667eea;
    transform: scale(1.05);
}

.gallery-image-card img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.gallery-loading {
    grid-column: 1 / -1;
    text-align: center;
    padding: 40px;
    color: #6c6c7e;
}

/* Context Menu */
.context-menu {
    position: fixed;
    background: #1e1e2e;
    border: 1px solid #3a3a4e;
    border-radius: 8px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
    z-index: 10002;
    min-width: 200px;
    overflow: hidden;
}

.context-menu-item {
    padding: 12px 16px;
    color: #e0e0e0;
    font-size: 14px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 12px;
    transition: background 0.2s;
}

.context-menu-item:hover {
    background: #2a2a3e;
}

.context-menu-item svg {
    width: 16px;
    height: 16px;
    opacity: 0.7;
}

.context-menu-divider {
    height: 1px;
    background: #3a3a4e;
    margin: 4px 0;
}

/* Edit Mode Active Indicator */
#editModeBtn.active {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

#editModeBtn.active:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

/* Highlight selected element in edit mode */
.edit-mode-highlight {
    outline: 2px dashed #667eea !important;
    outline-offset: 2px;
    cursor: pointer !important;
}

.edit-mode-active [data-element-id]:hover {
    outline: 2px solid #667eea;
    outline-offset: 2px;
    cursor: pointer;
}

/* Inline Picker Panels (Style & Font) */
.inline-picker-panel {
    position: fixed;
    z-index: 10002;
    background: #1e1e2e;
    border: 1px solid #2a2a3e;
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.5);
    min-width: 300px;
    max-width: 380px;
    font-family: system-ui, -apple-system, sans-serif;
}

.inline-panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
    font-size: 14px;
    font-weight: 600;
    color: #fff;
}

.inline-panel-close {
    background: transparent;
    border: none;
    color: #888;
    cursor: pointer;
    font-size: 16px;
    padding: 4px 8px;
    border-radius: 4px;
}

.inline-panel-close:hover {
    background: rgba(255,255,255,0.1);
    color: #fff;
}

.inline-panel-content {
    padding: 16px;
    max-height: 500px;
    overflow-y: auto;
}

.inline-panel-loading {
    padding: 24px;
    text-align: center;
    color: #888;
}

.inline-panel-actions {
    display: flex;
    gap: 8px;
    padding: 12px 16px;
    border-top: 1px solid rgba(255,255,255,0.1);
}

.inline-panel-actions button {
    flex: 1;
    padding: 10px 16px;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.inline-panel-actions .btn-primary {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border: none;
    color: white;
}

.inline-panel-actions .btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

.inline-panel-actions .btn-secondary {
    background: transparent;
    border: 1px solid rgba(255,255,255,0.2);
    color: #ccc;
}

.inline-panel-actions .btn-secondary:hover {
    background: rgba(255,255,255,0.1);
}

/* Color Groups */
.color-group {
    margin-bottom: 14px;
}

.color-group:last-child {
    margin-bottom: 0;
}

.color-group-title {
    font-size: 10px;
    font-weight: 700;
    color: #888;
    text-transform: uppercase;
    margin-bottom: 8px;
    letter-spacing: 0.5px;
}

.color-swatches {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(48px, 1fr));
    gap: 6px;
}

.color-swatch {
    text-align: center;
}

.swatch-box {
    height: 32px;
    border-radius: 6px;
    border: 1px solid rgba(255,255,255,0.1);
    margin-bottom: 2px;
}

.swatch-label {
    font-size: 8px;
    color: #777;
}

/* Font Panel */
.font-preview {
    background: rgba(255,255,255,0.05);
    padding: 12px;
    border-radius: 8px;
    margin-bottom: 14px;
}

.form-group {
    margin-bottom: 12px;
}

.form-group label {
    display: block;
    font-size: 10px;
    color: #999;
    text-transform: uppercase;
    margin-bottom: 4px;
    letter-spacing: 0.3px;
}

.form-group select {
    width: 100%;
    padding: 8px 10px;
    background: rgba(255,255,255,0.08);
    border: 1px solid rgba(255,255,255,0.15);
    border-radius: 6px;
    color: #e0e0e0;
    font-size: 13px;
    cursor: pointer;
}

.form-group select:focus {
    outline: none;
    border-color: #667eea;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

/* ============================================
   Debug Panel Styles
   ============================================ */

.debug-panel {
    position: fixed;
    top: 70px;
    left: 0;
    right: 0;
    bottom: 40px;
    background: #1a1a2e;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.debug-panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 24px;
    background: #16213e;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}

.debug-panel-header h2 {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
    color: #e0e0e0;
}

.debug-panel-actions {
    display: flex;
    gap: 12px;
    align-items: center;
}

.debug-btn {
    background: rgba(102, 126, 234, 0.2);
    border: 1px solid rgba(102, 126, 234, 0.4);
    color: #667eea;
    padding: 6px 12px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
    transition: all 0.2s;
}

.debug-btn:hover {
    background: rgba(102, 126, 234, 0.3);
    border-color: #667eea;
}

.debug-close {
    background: none;
    border: none;
    color: #888;
    font-size: 24px;
    cursor: pointer;
    padding: 0 8px;
    line-height: 1;
}

.debug-close:hover {
    color: #e0e0e0;
}

.debug-panel-body {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.debug-tabs {
    display: flex;
    gap: 4px;
    padding: 12px 24px;
    background: rgba(0,0,0,0.2);
    border-bottom: 1px solid rgba(255,255,255,0.05);
}

.debug-tab {
    background: transparent;
    border: 1px solid transparent;
    color: #888;
    padding: 8px 16px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
    transition: all 0.2s;
}

.debug-tab:hover {
    color: #e0e0e0;
    background: rgba(255,255,255,0.05);
}

.debug-tab.active {
    background: rgba(102, 126, 234, 0.2);
    border-color: rgba(102, 126, 234, 0.4);
    color: #667eea;
}

.debug-content {
    flex: 1;
    overflow: hidden;
    position: relative;
}

.debug-tab-content {
    display: none;
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    overflow: auto;
    padding: 20px 24px;
}

.debug-tab-content.active {
    display: block;
}

.debug-loading, .debug-empty {
    color: #666;
    text-align: center;
    padding: 40px;
    font-size: 14px;
}

.debug-panel-footer {
    padding: 12px 24px;
    background: rgba(0,0,0,0.3);
    border-top: 1px solid rgba(255,255,255,0.05);
    font-size: 12px;
    color: #666;
}

.debug-panel-footer span {
    color: #888;
}

#debugFbId, #debugWsStatus {
    color: #667eea;
    font-family: monospace;
}

/* Debug Section Styles */
.debug-section {
    margin-bottom: 24px;
}

.debug-section-title {
    font-size: 14px;
    font-weight: 600;
    color: #667eea;
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.debug-section-title .count {
    background: rgba(102, 126, 234, 0.2);
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 11px;
    font-weight: normal;
}

.debug-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.debug-table th {
    text-align: left;
    padding: 10px 12px;
    background: rgba(0,0,0,0.3);
    color: #888;
    font-weight: 500;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}

.debug-table td {
    padding: 10px 12px;
    border-bottom: 1px solid rgba(255,255,255,0.05);
    color: #e0e0e0;
    vertical-align: top;
}

.debug-table tr:hover td {
    background: rgba(255,255,255,0.02);
}

.debug-table .id-cell {
    font-family: monospace;
    color: #4ecdc4;
    font-size: 12px;
}

.debug-table .type-cell {
    color: #f39c12;
}

.debug-table .value-cell {
    font-family: monospace;
    font-size: 12px;
    color: #98c379;
    max-width: 300px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.debug-table .path-cell {
    font-family: monospace;
    font-size: 11px;
    color: #666;
}

/* JSON Tree View */
.debug-json {
    background: rgba(0,0,0,0.3);
    border-radius: 8px;
    padding: 16px;
    font-family: monospace;
    font-size: 12px;
    overflow-x: auto;
    white-space: pre-wrap;
    color: #98c379;
    max-height: 400px;
    overflow-y: auto;
}

/* Event Log Styles */
.debug-events-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.debug-event {
    background: rgba(0,0,0,0.2);
    border-radius: 8px;
    padding: 12px 16px;
    border-left: 3px solid #667eea;
}

.debug-event-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.debug-event-fn {
    font-weight: 600;
    color: #667eea;
    font-family: monospace;
}

.debug-event-time {
    font-size: 11px;
    color: #666;
}

.debug-event-details {
    font-family: monospace;
    font-size: 12px;
    color: #e0e0e0;
}

.debug-event-id {
    color: #4ecdc4;
}

.debug-event-value {
    color: #98c379;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Element Found/Not Found Indicators */
.debug-found {
    color: #4ecdc4;
}

.debug-not-found {
    color: #e74c3c;
}

.debug-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 500;
}

.debug-badge-success {
    background: rgba(78, 205, 196, 0.2);
    color: #4ecdc4;
}

.debug-badge-warning {
    background: rgba(243, 156, 18, 0.2);
    color: #f39c12;
}

.debug-badge-error {
    background: rgba(231, 76, 60, 0.2);
    color: #e74c3c;
}

/* LLM Calls Debug Styles */
.debug-llm-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.debug-btn-small {
    padding: 6px 12px;
    background: rgba(102, 126, 234, 0.2);
    border: 1px solid rgba(102, 126, 234, 0.3);
    border-radius: 4px;
    color: #667eea;
    cursor: pointer;
    font-size: 12px;
}

.debug-btn-small:hover {
    background: rgba(102, 126, 234, 0.3);
}

.debug-llm-count {
    font-size: 12px;
    color: #888;
}

.debug-llm-list {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.debug-llm-entry {
    background: rgba(0, 0, 0, 0.3);
    border-radius: 8px;
    overflow: hidden;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.debug-llm-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    background: rgba(102, 126, 234, 0.15);
    cursor: pointer;
}

.debug-llm-header:hover {
    background: rgba(102, 126, 234, 0.25);
}

.debug-llm-title {
    display: flex;
    align-items: center;
    gap: 10px;
}

.debug-llm-status {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #4ade80;
}

.debug-llm-status.error {
    background: #e74c3c;
}

.debug-llm-prompt-preview {
    font-size: 13px;
    color: #e0e0e0;
    max-width: 400px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.debug-llm-meta {
    display: flex;
    gap: 16px;
    font-size: 11px;
    color: #888;
}

.debug-llm-body {
    display: none;
    padding: 16px;
}

.debug-llm-entry.expanded .debug-llm-body {
    display: block;
}

.debug-llm-section {
    margin-bottom: 16px;
}

.debug-llm-section:last-child {
    margin-bottom: 0;
}

.debug-llm-section-title {
    font-size: 11px;
    font-weight: 600;
    color: #667eea;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.debug-llm-section-title::after {
    content: '';
    flex: 1;
    height: 1px;
    background: rgba(102, 126, 234, 0.2);
}

.debug-llm-code {
    background: rgba(0, 0, 0, 0.4);
    border-radius: 6px;
    padding: 12px;
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
    font-size: 12px;
    line-height: 1.5;
    color: #e0e0e0;
    overflow-x: auto;
    white-space: pre-wrap;
    word-break: break-word;
    max-height: 300px;
    overflow-y: auto;
}

.debug-llm-code.system-prompt {
    max-height: 200px;
    color: #888;
}

.debug-llm-code.user-prompt {
    border-left: 3px solid #4ade80;
}

.debug-llm-code.response {
    border-left: 3px solid #667eea;
}

.debug-llm-code.function-calls {
    border-left: 3px solid #f39c12;
}

.debug-llm-code.error {
    border-left: 3px solid #e74c3c;
    color: #e74c3c;
}

.debug-llm-toggle {
    font-size: 14px;
    transition: transform 0.2s;
}

.debug-llm-entry.expanded .debug-llm-toggle {
    transform: rotate(180deg);
}

/* ========================================
   Widget Picker Styles
   ======================================== */

.widget-picker-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: 300px;
    overflow-y: auto;
    margin-bottom: 12px;
}

.widget-picker-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    background: var(--secondary-bg, #2a2a2a);
    border: 2px solid transparent;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.widget-picker-item:hover {
    background: var(--hover-bg, #333);
    border-color: var(--accent-color, #4a90d9);
}

.widget-picker-item.selected {
    background: var(--accent-color, #4a90d9);
    border-color: var(--accent-color, #4a90d9);
    color: white;
}

/* Dragging state for drag-and-drop widget placement */
.widget-picker-item[draggable="true"] {
    cursor: grab;
}

.widget-picker-item.dragging {
    opacity: 0.5;
    cursor: grabbing;
    transform: scale(0.98);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.widget-picker-icon {
    width: 40px;
    height: 40px;
    background: var(--primary-bg, #1e1e1e);
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
}

.widget-picker-info {
    flex: 1;
    min-width: 0;
}

.widget-picker-name {
    font-weight: 600;
    font-size: 14px;
    margin-bottom: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.widget-picker-desc {
    font-size: 12px;
    color: var(--text-muted, #888);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.widget-picker-item.selected .widget-picker-desc {
    color: rgba(255, 255, 255, 0.8);
}

.widget-loading {
    text-align: center;
    padding: 20px;
    color: var(--text-muted, #888);
}

.widget-empty {
    text-align: center;
    padding: 20px;
    color: var(--text-muted, #888);
}

.widget-empty a {
    color: var(--accent-color, #4a90d9);
    text-decoration: none;
}

.widget-empty a:hover {
    text-decoration: underline;
}

/* Slot Selector */
.slot-selector {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--border-color, #333);
}

/* Slot buttons removed - using drag and drop instead */

/* Widget Placement Status */
.widget-place-status {
    margin-top: 12px;
    padding: 12px;
    background: var(--success-bg, rgba(46, 204, 113, 0.1));
    border: 1px solid var(--success-color, #2ecc71);
    border-radius: 6px;
    color: var(--success-color, #2ecc71);
    font-size: 13px;
    text-align: center;
}

.widget-place-status.error {
    background: rgba(231, 76, 60, 0.1);
    border-color: #e74c3c;
    color: #e74c3c;
}

/* =============================================
   Widget Picker Sidebar (replaces left panel)
   ============================================= */
.widget-picker-sidebar {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--panel-bg, #1a1a2e);
    display: flex;
    flex-direction: column;
    z-index: 100;
}

.widget-picker-sidebar-header {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 16px 20px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.back-to-chat-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    background: rgba(255,255,255,0.2);
    border: none;
    color: white;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 13px;
    cursor: pointer;
    transition: background 0.2s;
}

.back-to-chat-btn:hover {
    background: rgba(255,255,255,0.3);
}

.widget-picker-title {
    font-weight: 600;
    font-size: 15px;
}

.widget-picker-sidebar-content {
    flex: 1;
    overflow: hidden; /* Changed from overflow-y: auto - let children scroll */
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    min-height: 0; /* Important for flex children to shrink */
}

.widget-picker-section {
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    gap: 8px;
}

/* Flexible sections that grow to fill space */
.widget-picker-section.flexible {
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

.section-label {
    font-size: 11px;
    font-weight: 600;
    color: #888;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    flex-shrink: 0;
}

.widget-picker-sidebar .widget-picker-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    flex: 1;
    overflow-y: auto;
    min-height: 80px;
}

.widget-picker-sidebar .widget-picker-list::-webkit-scrollbar {
    width: 6px;
}

.widget-picker-sidebar .widget-picker-list::-webkit-scrollbar-track {
    background: rgba(255,255,255,0.05);
    border-radius: 3px;
}

.widget-picker-sidebar .widget-picker-list::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.2);
    border-radius: 3px;
}

.widget-preview-area {
    background: #0d0d1a;
    border-radius: 8px;
    border: 1px solid rgba(255,255,255,0.1);
    overflow: hidden;
    display: flex;
    align-items: stretch;
    justify-content: stretch;
    height: 320px;
    padding: 0;
}

.widget-preview-placeholder {
    color: #666;
    font-size: 13px;
    text-align: center;
    padding: 20px;
}

.widget-preview-wrapper {
    width: 100%;
    height: 100%;
    display: flex;
    transition: all 0.3s ease;
}

/* Full width alignment (default) */
.widget-preview-wrapper.align-full {
    justify-content: stretch;
}

.widget-preview-wrapper.align-full .widget-preview-iframe {
    width: 100%;
}

/* Left alignment */
.widget-preview-wrapper.align-left {
    justify-content: flex-start;
}

.widget-preview-wrapper.align-left .widget-preview-iframe {
    width: 60%;
}

/* Center alignment */
.widget-preview-wrapper.align-center {
    justify-content: center;
}

.widget-preview-wrapper.align-center .widget-preview-iframe {
    width: 60%;
}

/* Right alignment */
.widget-preview-wrapper.align-right {
    justify-content: flex-end;
}

.widget-preview-wrapper.align-right .widget-preview-iframe {
    width: 60%;
}

.widget-preview-iframe {
    width: 100%;
    height: 100%;
    border: none;
    background: white;
    border-radius: 6px;
    transition: width 0.3s ease;
}

/* Alignment buttons */
.alignment-buttons-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
}

.alignment-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 12px;
    font-size: 12px;
    background: rgba(255,255,255,0.05);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 6px;
    color: #aaa;
    cursor: pointer;
    transition: all 0.2s;
}

.alignment-btn:hover {
    background: rgba(255,255,255,0.1);
    color: #fff;
}

.alignment-btn.selected {
    background: rgba(102, 126, 234, 0.2);
    border-color: #667eea;
    color: #667eea;
}

.alignment-btn svg {
    flex-shrink: 0;
}

/* Sizing buttons (new Flexbox-based layout system) */
.sizing-buttons-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
}

.sizing-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 12px 8px;
    font-size: 11px;
    background: rgba(255,255,255,0.05);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 8px;
    color: #aaa;
    cursor: pointer;
    transition: all 0.2s;
}

.sizing-btn:hover {
    background: rgba(255,255,255,0.1);
    color: #fff;
}

.sizing-btn.selected {
    background: rgba(102, 126, 234, 0.2);
    border-color: #667eea;
    color: #667eea;
}

.sizing-btn svg {
    flex-shrink: 0;
}

.fixed-width-input {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 12px;
    padding: 8px 12px;
    background: rgba(0,0,0,0.2);
    border-radius: 6px;
}

.fixed-width-input label {
    font-size: 12px;
    color: #888;
    white-space: nowrap;
}

.fixed-width-input input {
    flex: 1;
    padding: 6px 10px;
    font-size: 12px;
    background: rgba(255,255,255,0.1);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 4px;
    color: #fff;
}

.fixed-width-input input:focus {
    outline: none;
    border-color: #667eea;
}

.widget-picker-sidebar-footer {
    padding: 16px;
    background: rgba(0,0,0,0.2);
    border-top: 1px solid rgba(255,255,255,0.1);
}

.drag-hint {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 16px;
    background: rgba(102, 126, 234, 0.1);
    border: 1px dashed rgba(102, 126, 234, 0.4);
    border-radius: 8px;
    color: rgba(255, 255, 255, 0.7);
    font-size: 13px;
}

.drag-hint svg {
    opacity: 0.7;
}

.place-widget-btn {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 14px 20px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border: none;
    color: white;
}

.place-widget-btn:hover:not(:disabled) {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

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

.place-widget-btn.loading {
    background: linear-gradient(135deg, #555 0%, #666 100%);
}

.place-widget-btn .spinner {
    animation: spin 1s linear infinite;
}

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