:root {
    --bg-primary: #0f172a;
    --bg-secondary: #1e293b;
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --accent-blue: #3b82f6;
    --accent-blue-hover: #2563eb;
    --accent-green: #10b981;
    --accent-red: #ef4444;
    --glass-bg: rgba(30, 41, 59, 0.7);
    --glass-border: rgba(255, 255, 255, 0.1);
    --card-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
}

html {
    font-size: 18px;
}
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Outfit', sans-serif;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    background-image:
        radial-gradient(circle at 15% 50%, rgba(59, 130, 246, 0.15) 0%, transparent 50%),
        radial-gradient(circle at 85% 30%, rgba(16, 185, 129, 0.15) 0%, transparent 50%);
    background-attachment: fixed;
}

.app-container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 2rem;
}

header {
    margin-bottom: 2.5rem;
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
    flex-wrap: wrap;
    gap: 1rem;
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.logo-icon {
    font-size: 1.5rem;
    color: var(--accent-blue);
}

h1 {
    font-size: 1.75rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.subtitle {
    color: var(--text-secondary);
    font-size: 0.95rem;
}

.status-indicator {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.85rem;
    background: rgba(0, 0, 0, 0.2);
    padding: 0.4rem 0.8rem;
    border-radius: 20px;
    border: 1px solid var(--glass-border);
}

.dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: var(--text-secondary);
}

.dot.online {
    background-color: var(--accent-green);
    box-shadow: 0 0 10px var(--accent-green);
    animation: pulse 2s infinite;
}

.dot.offline {
    background-color: var(--accent-red);
    box-shadow: 0 0 10px var(--accent-red);
}

@keyframes pulse {
    0% {
        transform: scale(0.95);
        opacity: 0.8;
    }

    50% {
        transform: scale(1.1);
        opacity: 1;
    }

    100% {
        transform: scale(0.95);
        opacity: 0.8;
    }
}

.glass-panel {
    background: var(--glass-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    padding: 1.5rem;
    box-shadow: var(--card-shadow);
    margin-bottom: 1.5rem;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.glass-panel h2 {
    font-size: 1.25rem;
    margin-bottom: 1.25rem;
    font-weight: 600;
}

.api-keys-section {
    max-width: 500px;
    margin: 0 auto;
}

.input-group {
    margin-bottom: 1rem;
}

.input-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.input-group input {
    width: 100%;
    padding: 0.75rem 1rem;
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    background: rgba(0, 0, 0, 0.2);
    color: white;
    font-family: monospace;
    transition: border-color 0.2s;
}

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

.btn {
    padding: 0.75rem 1.5rem;
    border-radius: 8px;
    border: none;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    width: 100%;
    font-family: inherit;
    font-size: 1rem;
}

.primary-btn {
    background-color: var(--accent-blue);
    color: white;
    margin-top: 0.5rem;
}

.primary-btn:hover {
    background-color: var(--accent-blue-hover);
    transform: translateY(-2px);
}

.secondary-btn {
    background-color: rgba(255, 255, 255, 0.1);
    color: white;
    width: auto;
    border: 1px solid var(--glass-border);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.secondary-btn:hover {
    background-color: rgba(255, 255, 255, 0.15);
}

.controls {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
}

.controls h2 {
    margin-bottom: 0.2rem;
}

/* Grid Styles for Multiple Markets */
.markets-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(440px, 1fr));
    gap: 1.5rem;
}

.market-card {
    padding: 1.25rem;
    margin-bottom: 0;
    display: flex;
    flex-direction: column;
}

.market-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.3);
    border-color: rgba(255, 255, 255, 0.2);
}

.market-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.market-name {
    font-size: 1.2rem;
    font-weight: 700;
    color: white;
}

.spread-percentage {
    font-size: 0.85rem;
    color: var(--accent-blue);
    font-weight: 600;
    background: rgba(59, 130, 246, 0.1);
    padding: 0.2rem 0.6rem;
    border-radius: 12px;
}

.arbitrage-banner {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    border-radius: 8px;
    margin-bottom: 1rem;
    font-size: 0.85rem;
    font-weight: 600;
}

.arb-icon {
    font-size: 1.1rem;
}

.comparison-grid {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    flex: 1;
}

.platform-col {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
}

.v-divider {
    width: 1px;
    background-color: var(--glass-border);
}

.platform-title {
    font-size: 0.9rem;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 0.3rem;
    margin-bottom: 0.4rem;
    padding-bottom: 0.4rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.calc-label {
    font-size: 0.65rem;
    opacity: 0.6;
}

.detail-row {
    display: flex;
    flex-direction: column;
}

.detail-label {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.15rem;
}

.detail-label.bid {
    color: var(--accent-green);
}

.detail-label.ask {
    color: var(--accent-red);
}

.detail-val {
    font-size: 0.9rem;
    font-weight: 600;
    font-family: monospace;
}


@media (max-width: 600px) {
    .controls {
        flex-direction: column;
        align-items: stretch;
        gap: 1rem;
    }

    .markets-grid {
        grid-template-columns: 1fr;
    }
}

/* Tabs */
.tabs-container {
    display: flex;
    gap: 1rem;
}

.tab-btn {
    padding: 0.75rem 1.5rem;
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    color: var(--text-secondary);
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.2s;
    font-family: inherit;
    font-size: 1rem;
}

.tab-btn:hover {
    background: rgba(255, 255, 255, 0.1);
}

.tab-btn.active {
    background: var(--accent-blue);
    color: white;
    border-color: var(--accent-blue);
}

/* Orderbook Tables */
.ob-table {
    width: 100%;
    border-collapse: collapse;
}

.ob-table th {
    text-align: left;
    color: var(--text-secondary);
    font-size: 0.85rem;
    padding-bottom: 0.8rem;
    border-bottom: 1px solid var(--glass-border);
}

.ob-table td {
    padding: 0.6rem 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    font-family: monospace;
    font-size: 0.95rem;
}

.buy-side .ob-table td:nth-child(1) {
    color: var(--accent-green);
}

.sell-side .ob-table td:nth-child(1) {
    color: var(--accent-red);
}

@media (max-width: 768px) {
    .orderbook-container {
        flex-direction: column;
    }
}

/* Filter Grid Styles */
.filter-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 0.75rem;
}

.filter-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.9rem;
    cursor: pointer;
    padding: 0.4rem 0.6rem;
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.05);
    transition: background 0.2s;
}

.filter-item:hover {
    background: rgba(255, 255, 255, 0.1);
}

.filter-item input {
    cursor: pointer;
    accent-color: var(--accent-blue);
}

.filter-section.expanded #filterToggleIcon {
    transform: rotate(90deg);
}

.filter-section.expanded #filterCollapseBody {
    max-height: 500px !important;
    margin-top: 0;
}

.filter-section.expanded #filterControls {
    display: flex !important;
}

/* Ticker Tape Styles */
.ticker-wrap {
    position: sticky;
    top: 0;
    z-index: 1001;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    width: 100%;
    overflow: hidden;
    background: rgba(16, 185, 129, 0.15);
    border-bottom: 1px solid rgba(16, 185, 129, 0.3);
    padding: 0.6rem 0;
    margin-bottom: 0px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
}

.return-ticker-wrap {
    top: 42px; /* Height of the ticker above */
    z-index: 1000;
    background: rgba(59, 130, 246, 0.15);
    border-bottom: 1px solid rgba(59, 130, 246, 0.3);
    margin-bottom: 0;
}

.return-ticker-wrap .ticker {
    animation-duration: 120s; /* Even slower for better readability (120s vs 40s) */
}

/* Fading edges for better look in full width */
.ticker-wrap::before, .ticker-wrap::after {
    content: '';
    position: absolute;
    top: 0;
    width: 50px;
    height: 100%;
    z-index: 2;
    pointer-events: none;
}

.ticker-wrap::before {
    left: 0;
    background: linear-gradient(to right, var(--bg-primary), transparent);
}

.ticker-wrap::after {
    right: 0;
    background: linear-gradient(to left, var(--bg-primary), transparent);
}

.ticker {
    display: inline-flex;
    white-space: nowrap;
    padding-left: 100%;
    animation: ticker 40s linear infinite;
    gap: 3rem;
    align-items: center;
}

.ticker:hover {
    animation-play-state: paused;
}

.ticker__item {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.95rem;
    font-weight: 600;
    color: white;
}

.ticker__item .usdt-badge {
    color: #f3ba2f;
}

.ticker__item .o2b {
    color: var(--accent-green);
}

.ticker__item .b2o {
    color: #f3ba2f;
}

.ticker__item .return-badge {
    color: var(--accent-blue);
}

.ticker__item .return-profit {
    color: var(--accent-green);
}

.ticker__item .return-loss {
    color: var(--accent-red);
}

@keyframes ticker {
    0% { transform: translate3d(0, 0, 0); }
    100% { transform: translate3d(-100%, 0, 0); }
}

/* P2P Merchant Ticker */
.p2p-ticker-wrap {
    top: 84px; /* Below both tickers */
    z-index: 999;
    background: rgba(243, 186, 47, 0.12);
    border-bottom: 1px solid rgba(243, 186, 47, 0.3);
    margin-bottom: 0;
}

.p2p-ticker-wrap .ticker {
    animation-duration: 60s;
}

/* Settings Button */
.settings-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 1px solid var(--glass-border);
    background: rgba(255, 255, 255, 0.08);
    color: white;
    font-size: 1.2rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

.settings-btn:hover {
    background: rgba(255, 255, 255, 0.15);
    transform: rotate(90deg) scale(1.1);
    border-color: var(--accent-blue);
    box-shadow: 0 0 15px rgba(59, 130, 246, 0.3);
}

/* Settings Modal */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.65);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: modalFadeIn 0.3s ease;
}

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

.modal-content {
    max-width: 520px;
    width: 90%;
    max-height: 85vh;
    overflow-y: auto;
    margin: 0;
    padding: 0;
    border-radius: 20px;
    border: 1px solid rgba(255, 255, 255, 0.15);
    background: rgba(20, 30, 50, 0.95);
    box-shadow: 0 24px 80px rgba(0, 0, 0, 0.5), 0 0 40px rgba(59, 130, 246, 0.1);
    animation: modalSlideIn 0.3s ease;
}

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

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

.modal-header h2 {
    font-size: 1.3rem;
    font-weight: 700;
    margin: 0;
}

.modal-close-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(239, 68, 68, 0.1);
    color: var(--accent-red);
    font-size: 1.4rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    line-height: 1;
}

.modal-close-btn:hover {
    background: rgba(239, 68, 68, 0.25);
    transform: scale(1.1);
}

.modal-body {
    padding: 1.25rem 1.5rem;
}

.settings-section {
    margin-bottom: 1.5rem;
    padding-bottom: 1.5rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.settings-section:last-child {
    border-bottom: none;
    margin-bottom: 0;
    padding-bottom: 0;
}

.settings-section-title {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 0.75rem;
    color: var(--text-primary);
}

.settings-help {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
    line-height: 1.4;
}

.settings-select {
    width: 100%;
    padding: 0.65rem 1rem;
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.15);
    background: rgba(0, 0, 0, 0.3);
    color: white;
    font-family: inherit;
    font-size: 0.95rem;
    outline: none;
    cursor: pointer;
    transition: border-color 0.2s;
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%2394a3b8' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.75rem center;
}

.settings-select:focus {
    border-color: var(--accent-blue);
}

.settings-select option {
    background: #1e293b;
    color: white;
}

.modal-footer {
    display: flex;
    gap: 0.75rem;
    justify-content: flex-end;
    padding: 1rem 1.5rem 1.5rem;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
}

/* P2P Merchant ticker item styling */
.p2p-merchant-item {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.9rem;
    padding: 0.15rem 0.6rem;
    border-radius: 6px;
    background: rgba(243, 186, 47, 0.08);
    border: 1px solid rgba(243, 186, 47, 0.15);
}

.p2p-merchant-name {
    color: #f3ba2f;
    font-weight: 600;
}

.p2p-merchant-price {
    color: white;
    font-family: monospace;
    font-weight: 700;
}

.p2p-merchant-detail {
    color: var(--text-secondary);
    font-size: 0.75rem;
}