<div class="content" id="strats_content">
    <div style="display: grid; grid-template-columns: 1fr 1fr;">
        <div class="section" style="grid-column: 1;">
            <button class="btn" id="new_strats_btn" onclick="UI.strats.uiManager.displayForm('new')">New Strategy</button>
        </div>
        <div class="section" style="grid-column: 2;">
            <button class="btn" id="browse_public_btn" onclick="UI.strats.uiManager.showPublicStrategyBrowser()">Add Public</button>
        </div>
    </div>
    <hr>
    <h3>Strategies</h3>
    <div class="strategies-container" id="strats_display"></div>
</div>

<style>
.strategies-container {
    display: flex;
    flex-wrap: wrap;
    gap: 20px;
    position: relative;
}

.strategy-item {
    position: relative;
    width: 100px;
    height: 100px;
    text-align: center;
    transition: transform 0.3s ease;
    z-index: 1; /* Set default z-index */
}

.strategy-item:hover {
    transform: scale(1.05);
    z-index: 10; /* Bring the hovered item to the front */
}

.strategy-icon {
    width: 100px;
    height: 100px;
    background-image: url('/static/trading_strategy_icon.webp'); /* Path to your icon */
    background-size: cover;
    background-position: center;
    border-radius: 10px;
    position: relative;
}

.strategy-name {
    position: absolute;
    top: 60px;
    left: 50%;
    transform: translateX(-50%);
    background-color: white;
    padding: 5px 10px;
    border-radius: 20px;
    font-size: 12px;
    color: black;
    text-align: center;
    width: 80px;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.delete-button {
    z-index: 20;
    position: absolute;
    top: 5px;
    left: 5px;
    background-color: red;
    color: white;
    border: none;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    font-size: 14px;
    cursor: pointer;
    transition: transform 0.3s ease, background-color 0.3s ease, box-shadow 0.3s ease;
}

.delete-button:hover {
    transform: scale(1.2); /* Increase size slightly on hover */
    background-color: darkred; /* Darken background on hover */
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2); /* Add shadow effect */
}


.strategy-hover {
    display: none;
    position: absolute;
    top: 0;
    left: 100px; /* No gap - connects directly to the 100px wide icon */
    width: 200px;
    padding: 10px;
    padding-left: 20px; /* Visual padding to compensate for no gap */
    background-color: #f0f0f0;
    border-radius: 8px;
    box-shadow: 0px 4px 6px rgba(0, 0, 0, 0.1);
    font-size: 12px;
    color: #333;
    z-index: 50; /* Make sure it hovers above all other elements */
}

.strategy-item:hover .strategy-hover {
    display: block;
}

/* Run button styling */
.run-button {
    z-index: 20;
    position: absolute;
    top: 5px;
    right: 5px;
    background-color: #28a745;
    color: white;
    border: none;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    font-size: 10px;
    cursor: pointer;
    transition: transform 0.3s ease, background-color 0.3s ease, box-shadow 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.run-button:hover {
    transform: scale(1.2);
    background-color: #218838;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

.run-button.running {
    background-color: #dc3545;
}

.run-button.running:hover {
    background-color: #c82333;
}

/* Strategy hover panel controls */
.strategy-controls {
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid #ddd;
}

.strategy-controls select {
    width: 100%;
    padding: 5px 8px;
    margin-bottom: 8px;
    border-radius: 4px;
    border: 1px solid #ccc;
    font-size: 12px;
    min-height: 28px; /* Ensure text isn't cut off */
    line-height: 1.4;
}

.strategy-controls .btn-run {
    width: 100%;
    padding: 6px;
    background-color: #28a745;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    transition: background-color 0.2s;
}

.strategy-controls .btn-run:hover {
    background-color: #218838;
}

.strategy-controls .btn-run.running {
    background-color: #dc3545;
}

.strategy-controls .btn-run.running:hover {
    background-color: #c82333;
}

.strategy-status {
    margin-top: 8px;
    padding: 5px;
    background-color: #e9ecef;
    border-radius: 4px;
    font-size: 11px;
}

.strategy-status.running {
    background-color: #d4edda;
    color: #155724;
}

/* Running indicator on strategy icon */
.strategy-icon.running {
    border: 3px solid #28a745;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% { box-shadow: 0 0 0 0 rgba(40, 167, 69, 0.4); }
    70% { box-shadow: 0 0 0 10px rgba(40, 167, 69, 0); }
    100% { box-shadow: 0 0 0 0 rgba(40, 167, 69, 0); }
}

/* Subscribed strategy styling */
.strategy-item.subscribed .strategy-icon {
    border: 2px solid #17a2b8;
}

.strategy-item.subscribed .delete-button {
    display: none;
}

.strategy-icon.subscribed {
    border: 2px solid #17a2b8;
}

/* Unsubscribe button (replaces delete for subscribed) */
.unsubscribe-button {
    z-index: 20;
    position: absolute;
    top: 5px;
    left: 5px;
    background-color: #17a2b8;
    color: white;
    border: none;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    font-size: 14px;
    cursor: pointer;
    transition: transform 0.3s ease, background-color 0.3s ease, box-shadow 0.3s ease;
}

.unsubscribe-button:hover {
    transform: scale(1.2);
    background-color: #138496;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

/* Creator badge for subscribed strategies */
.creator-badge {
    position: absolute;
    bottom: 22px;
    left: 50%;
    transform: translateX(-50%);
    background-color: #17a2b8;
    color: white;
    padding: 2px 6px;
    border-radius: 10px;
    font-size: 9px;
    white-space: nowrap;
    max-width: 90px;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Modal overlay styles */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.modal-content {
    background-color: white;
    border-radius: 8px;
    padding: 0;
    max-height: 80vh;
    overflow: hidden;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px;
    border-bottom: 1px solid #ccc;
    background: linear-gradient(135deg, #3E3AF2 0%, #6366f1 100%);
    color: white;
    border-radius: 8px 8px 0 0;
}

.modal-header h2 {
    margin: 0;
    font-size: 18px;
    color: white;
}

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

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

.modal-body {
    padding: 20px;
    overflow-y: auto;
    max-height: calc(80vh - 60px);
}

/* Public Strategy Browser Modal */
.public-strategy-browser {
    max-width: 600px;
    width: 90%;
}

.public-strategies-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-height: 400px;
    overflow-y: auto;
}

.public-strategy-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px;
    background-color: #f8f9fa;
    border-radius: 6px;
    border: 1px solid #dee2e6;
}

.public-strategy-item.subscribed {
    border-color: #17a2b8;
    background-color: #e7f6f8;
}

.public-strategy-item .strategy-info {
    flex: 1;
}

.public-strategy-item .strategy-info strong {
    display: block;
    margin-bottom: 3px;
}

.public-strategy-item .strategy-info .creator {
    font-size: 11px;
    color: #666;
}

.no-strategies {
    text-align: center;
    color: #666;
    padding: 20px;
}

.subscribe-btn {
    padding: 6px 12px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    background-color: #28a745;
    color: white;
    transition: background-color 0.2s;
}

.subscribe-btn:hover {
    background-color: #218838;
}

.subscribe-btn.subscribed {
    background-color: #dc3545;
}

.subscribe-btn.subscribed:hover {
    background-color: #c82333;
}

</style>
