/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Courier New', monospace;
    background: #0f0f1f;
    color: #ffffff;
    line-height: 1.4;
    overflow-x: hidden;
}

.app {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Header */
.header {
    background: #1a1a2e;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 30px;
    border-bottom: 1px solid #333;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 30px;
}

.logo-section {
    display: flex;
    align-items: center;
    gap: 8px;
}

.logo-img {
    height: 24px;
    width: auto;
}

.beta-tag {
    background: #00b894;
    color: #fff;
    font-size: 0.7rem;
    border-radius: 3px;
    padding: 2px 6px;
    font-weight: bold;
}

.nav-menu {
    display: flex;
    gap: 20px;
    font-size: 0.9rem;
    color: #888;
}

.nav-item {
    cursor: pointer;
    transition: color 0.3s;
}

.nav-item:hover, .nav-item.active {
    color: #fff;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 15px;
}

.wallet-address {
    font-size: 0.85rem;
    color: #b2bec3;
}

.disconnect-btn, .connect-wallet-btn {
    background: transparent;
    border: 1px solid #666;
    color: #fff;
    padding: 8px 12px;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s;
    font-family: 'Courier New', monospace;
    font-size: 0.85rem;
}

.disconnect-btn:hover, .connect-wallet-btn:hover {
    border-color: #fff;
    background: rgba(255, 255, 255, 0.1);
}

.disconnect-btn {
    background: #d63031;
    border-color: #d63031;
}

.disconnect-btn:hover {
    background: #e74c3c;
    border-color: #e74c3c;
}

/* Main Content */
.main-content {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
}

.swap-widget {
    width: 100%;
    max-width: 420px;
    background: #202040;
    border-radius: 12px;
    padding: 20px;
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.5);
    position: relative;
    border: 1px solid #333;
    overflow: hidden; /* Prevent content from spilling out */
}

.settings-icon {
    position: absolute;
    top: 15px;
    right: 15px;
    background: transparent;
    border: none;
    color: #888;
    font-size: 1.2rem;
    cursor: pointer;
    padding: 5px;
    border-radius: 4px;
    transition: color 0.3s;
    z-index: 10;
}

.settings-icon:hover {
    color: #fff;
}

/* Trade Boxes */
.trade-box {
    background: #1a1a2e;
    border-radius: 12px;
    padding: 16px;
    margin-bottom: 8px;
    border: 1px solid #333;
    position: relative;
    overflow: visible;
}

.trade-label {
    color: #888;
    font-size: 0.9rem;
    margin-bottom: 8px;
    font-weight: 500;
}

.trade-input-row {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 8px;
    flex-wrap: nowrap; /* Prevent wrapping */
}

.trade-amount {
    flex: 1;
    background: transparent;
    border: none;
    color: #fff;
    font-size: 1.8rem;
    font-weight: 600;
    outline: none;
    font-family: 'Courier New', monospace;
    padding: 8px 0;
    min-width: 0; /* Allow shrinking */
}

.trade-amount::placeholder {
    color: #444;
}

.trade-amount:focus {
    color: #fff;
}

/* Token Selector - Fixed positioning */
.token-select {
    display: flex;
    align-items: center;
    gap: 8px;
    background: #2a2a3e;
    border: 1px solid #444;
    border-radius: 8px;
    padding: 8px 12px;
    cursor: pointer;
    transition: all 0.2s;
    min-width: 110px;
    max-width: 140px;
    flex-shrink: 0; /* Don't shrink */
    justify-content: space-between;
    position: relative;
    z-index: 5;
}

.token-select:hover {
    background: #3a3a4e;
    border-color: #555;
}

.token-display {
    display: flex;
    align-items: center;
    gap: 6px;
    flex: 1;
    min-width: 0; /* Allow text truncation */
    overflow: hidden;
}

.token-icon-bg {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.token-icon {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.token-name {
    color: #fff;
    font-size: 0.9rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.select-token-text {
    color: #666;
    font-size: 0.85rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.dropdown-arrow {
    color: #888;
    font-size: 0.8rem;
    margin-left: 4px;
    flex-shrink: 0;
}

.balance-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.8rem;
    color: #888;
    margin-top: 4px;
}

.max-button {
    background: #0984e3;
    color: #fff;
    border: none;
    padding: 4px 8px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.75rem;
    transition: background 0.2s;
    font-family: 'Courier New', monospace;
    flex-shrink: 0;
}

.max-button:hover {
    background: #74b9ff;
}

/* Swap Arrow */
.swap-arrow-container {
    display: flex;
    justify-content: center;
    margin: 12px 0;
    position: relative;
    z-index: 1;
}

.swap-arrow {
    background: #2a2a3e;
    border: 1px solid #444;
    color: #888;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.swap-arrow:hover {
    color: #fff;
    background: #3a3a4e;
    transform: rotate(180deg);
}

/* Swap Details */
.swap-details {
    background: #1a1a2e;
    border: 1px solid #333;
    border-radius: 8px;
    padding: 12px;
    margin: 12px 0;
}

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

.detail-row:last-child {
    margin-bottom: 0;
}

.detail-row span:first-child {
    color: #888;
}

.detail-row span:last-child {
    color: #fff;
    font-weight: 500;
}

/* Main Action Button */
.main-action-btn {
    width: 100%;
    background: #27ae60;
    color: white;
    border: none;
    padding: 14px;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    font-family: 'Courier New', monospace;
    margin: 12px 0;
}

.main-action-btn:hover:not(:disabled) {
    background: #2ecc71;
    transform: translateY(-1px);
}

.main-action-btn:disabled {
    background: #666;
    cursor: not-allowed;
    opacity: 0.6;
    transform: none;
}

/* Expand Chart Button */
.expand-chart-btn {
    width: 100%;
    background: #2a2a3e;
    color: #888;
    border: 1px solid #444;
    padding: 10px;
    border-radius: 8px;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
    font-family: 'Courier New', monospace;
}

.expand-chart-btn:hover {
    color: #fff;
    background: #3a3a4e;
}

/* Footer */
.footer {
    background: #1a1a2e;
    padding: 15px 30px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.8rem;
    color: #888;
    border-top: 1px solid #333;
}

.footer-right {
    display: flex;
    align-items: center;
    gap: 5px;
}

.footer-link {
    color: #888;
    text-decoration: none;
    transition: color 0.2s;
}

.footer-link:hover {
    color: #fff;
}

.footer-separator {
    color: #555;
}

/* Modal Styles */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    backdrop-filter: blur(4px);
}

.modal {
    background: #2a2a3e;
    border: 1px solid #444;
    border-radius: 12px;
    padding: 20px;
    width: 90%;
    max-width: 420px;
    max-height: 80vh;
    overflow-y: auto;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

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

.modal-close {
    background: transparent;
    border: none;
    color: #888;
    font-size: 1.5rem;
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    transition: color 0.2s;
}

.modal-close:hover {
    color: #fff;
}

.search-container {
    margin-bottom: 16px;
}

.search-input {
    width: 100%;
    background: #1a1a2e;
    border: 1px solid #444;
    border-radius: 8px;
    padding: 12px;
    color: #fff;
    font-size: 0.9rem;
    outline: none;
    font-family: 'Courier New', monospace;
    transition: border-color 0.2s;
}

.search-input:focus {
    border-color: #0984e3;
}

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

/* Popular Tokens */
.popular-tokens {
    margin-bottom: 16px;
}

.section-title {
    color: #888;
    font-size: 0.85rem;
    margin-bottom: 8px;
}

.token-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    margin-bottom: 16px;
}

.popular-token-btn {
    background: #1a1a2e;
    border: 1px solid #444;
    border-radius: 8px;
    padding: 12px 8px;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    color: #fff;
    font-family: 'Courier New', monospace;
}

.popular-token-btn:hover {
    background: #2a2a3e;
    border-color: #555;
}

.popular-token-btn img {
    width: 24px;
    height: 24px;
    border-radius: 50%;
}

.popular-token-btn span {
    font-size: 0.8rem;
    font-weight: 600;
}

/* Token List */
.token-list-container {
    max-height: 240px;
    overflow-y: auto;
}

.token-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.token-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    cursor: pointer;
    transition: background 0.2s;
    border-radius: 8px;
}

.token-item:hover {
    background: #3a3a4e;
}

.token-item .token-icon {
    width: 28px;
    height: 28px;
    border-radius: 50%;
}

.token-info {
    flex: 1;
}

.token-info .token-name {
    color: #fff;
    font-weight: 600;
    margin-bottom: 2px;
    font-size: 0.9rem;
}

.token-info .token-symbol {
    color: #888;
    font-size: 0.8rem;
}

/* Wallet Options */
.wallet-options {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.wallet-option {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px;
    background: #1a1a2e;
    border: 1px solid #444;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
}

.wallet-option:hover {
    background: #2a2a3e;
    border-color: #555;
}

.wallet-option img {
    width: 28px;
    height: 28px;
    border-radius: 50%;
}

.wallet-option span {
    color: #fff;
    font-weight: 600;
}

/* Loading Overlay */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.9);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 2000;
}

.loading-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid rgba(255, 255, 255, 0.3);
    border-top: 3px solid #0984e3;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 16px;
}

.loading-text {
    color: #fff;
    font-size: 1rem;
    font-weight: 500;
}

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

/* Scrollbar Styling */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: #1a1a2e;
}

::-webkit-scrollbar-thumb {
    background: #0984e3;
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: #74b9ff;
}

/* Responsive Design */
@media (max-width: 768px) {
    .header {
        flex-direction: column;
        gap: 12px;
        padding: 12px 16px;
    }
    
    .header-left {
        flex-direction: column;
        gap: 12px;
    }
    
    .nav-menu {
        flex-wrap: wrap;
        gap: 12px;
        justify-content: center;
    }
    
    .main-content {
        padding: 12px;
    }
    
    .swap-widget {
        padding: 16px;
        max-width: 100%;
    }
    
    .footer {
        flex-direction: column;
        gap: 8px;
        text-align: center;
        padding: 12px 16px;
    }
    
    .trade-amount {
        font-size: 1.5rem;
    }
    
    .modal {
        width: 95%;
        padding: 16px;
    }
    
    .token-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .token-select {
        min-width: 90px;
        max-width: 120px;
    }
}

@media (max-width: 480px) {
    .trade-input-row {
        flex-direction: column;
        gap: 12px;
        align-items: stretch;
    }
    
    .token-select {
        width: 100%;
        max-width: none;
        justify-content: center;
    }
    
    .trade-amount {
        font-size: 1.3rem;
        text-align: center;
    }
    
    .token-grid {
        grid-template-columns: 1fr;
    }
    
    .swap-widget {
        padding: 12px;
    }
}

/* Fix for very small screens */
@media (max-width: 360px) {
    .swap-widget {
        margin: 8px;
        padding: 10px;
    }
    
    .trade-box {
        padding: 12px;
    }
    
    .trade-amount {
        font-size: 1.2rem;
    }
    
    .token-name, .select-token-text {
        font-size: 0.8rem;
    }
}

/* Image Error Handling */
.wallet-option img, .token-icon, .popular-token-btn img {
    object-fit: cover;
    background-color: #f0f0f0;
}

/* Ensure token icons are consistently sized */
.token-icon {
    width: 24px !important;
    height: 24px !important;
    border-radius: 50%;
    flex-shrink: 0;
}

.popular-token-btn img {
    width: 20px !important;
    height: 20px !important;
    border-radius: 50%;
    flex-shrink: 0;
}

/* Loading state for images */
.wallet-option img[src=""], .token-icon[src=""] {
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: loading 1.5s infinite;
}

@keyframes loading {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* Loading and error message styles */
.loading-message, .error-message {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    text-align: center;
    color: #666;
    font-size: 14px;
    height: 60px;
}

.error-message {
    color: #ff4444;
}

.loading-message {
    color: #0066cc;
}
