/**
 * ArzPaya Crypto Table Plugin Styles
 * Complete styles for crypto table functionality
 */

/* ===== Base Crypto Section Styles ===== */
.crypto-section {
    direction: rtl;
    font-family: "IRANSansWeb", sans-serif;
    background: transparent;
    color: #1e1e2f;
    width: 100%;
}

/* ===== Tabs and Search Container ===== */
.tabsAndSearchContainer {
    display: flex;
    justify-content: space-between;
    width: 100%;
}

.tabs {
    display: flex;
    justify-content: flex-start;
    font-family: "IRANSansWeb", sans-serif;
    width: 30%;
}

.tab {
    padding: 10px 20px;
    background: #f1f5ff;
    border-top-left-radius: 8px;
    border-top-right-radius: 8px;
    border: none;
    cursor: pointer;
    font-weight: 500;
    color: #555;
    transition: all 0.3s ease;
    width: 50%;
    font-family: "IRANSansWeb", sans-serif;
}

.tab.active {
    background: #ffffff;
    border-top: 3px solid #3b82f6;
    color: #111;
    border-top-left-radius: 8px;
    border-top-right-radius: 8px;
}

.searchBox {
    flex-grow: 1;
    display: flex;
    justify-content: flex-end;
}

.searchInput {
    border: 1px dashed #3b82f6;
    border-radius: 8px;
    padding: 12px;
    margin-bottom: 10px;
    font-family: "IRANSansWeb", sans-serif;
    background: transparent;
    transition: all 0.3s ease;
}

.searchInput:focus {
    outline: none;
    border: 1px solid #3b82f6;
    border-radius: 8px;
    padding: 12px;
    margin-bottom: 10px;
    font-family: "IRANSansWeb", sans-serif;
    background: transparent;
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.1);
}

/* ===== Table Container ===== */
.table-container {
    overflow-x: auto;
    position: relative;
    border-bottom-left-radius: 4px;
    border-bottom-right-radius: 4px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    border: 1px solid #ddd;
    border-top: none; /* Remove top border for progress bar */
}

/* ===== Progress Bar Background ===== */
.table-container::before {
    content: '';
    position: sticky;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: #fafafa;
    display: block;
    z-index: 9;
}

/* ===== Progress Bar ===== */
.table-container .crypto-progress-bar {
    position: sticky;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: linear-gradient(90deg, #3b82f6, #60a5fa);
    transform: scaleX(var(--progress-width, 0));
    transform-origin: left;
    transition: var(--progress-transition, transform linear);
    z-index: 10;
    box-shadow: 0 0 8px rgba(59, 130, 246, 0.5);
    display: block;
    margin: 0;
    border-radius: 0;
    margin-top: -4px; /* Overlap with background */
}

[data-theme="dark"] .table-container::before {
    background: var(--header-bg, #2a2a2a);
}

[data-theme="dark"] .table-container .crypto-progress-bar {
    background: linear-gradient(90deg, #3b82f6, #60a5fa);
    box-shadow: 0 0 8px rgba(59, 130, 246, 0.6);
}

/* Fixed Height Style (Homepage style - fix_height=true) */
.arzpaya-crypto-table-fixed-height .table-container {
    height: 550px; /* ارتفاع کل جدول */
}

.arzpaya-crypto-table-fixed-height .crypto-table tbody {
    max-height: 480px;
    overflow-y: auto;
}

/* Auto Height Style (Buy/Price style - fix_height=false) */
.arzpaya-crypto-table-auto-height .table-container {
    height: auto !important;
    min-height: 400px;
}

.arzpaya-crypto-table-auto-height .crypto-table tbody {
    max-height: none !important;
    overflow-y: visible !important;
    display: table-row-group;
}

/* ===== Crypto Table ===== */
.crypto-table {
    width: 100%;
    border-collapse: collapse;
    display: none;
}

.crypto-table.active {
    display: table;
}

.crypto-table thead {
    position: sticky;
    top: 0;
    background: #fafafa;
    z-index: 2;
}

.crypto-table tbody {
    max-height: 480px;
    overflow-y: auto;
}

.crypto-table th,
.crypto-table td {
    padding: 16px;
    text-align: right;
    border-bottom: 1px solid #ddd;
    font-family: "IRANSansWeb", sans-serif;
}

.crypto-table th:not(:first-child),
.crypto-table td:not(:first-child) {
    text-align: center;
}

.crypto-table th {
    background: #fafafa;
    font-weight: 600;
    color: #555;
    white-space: nowrap;
}

.crypto-table tr {
    width: 100%;
}

.crypto-table tr:hover {
    background-color: #f1f5ff;
}

/* ===== Coin Name Cell ===== */
.crypto-section .coin-name-cell {
    display: flex;
    align-items: center;
    gap: 10px;
    text-align: center;
    margin-top: 12px;
    border-bottom: 1px solid #ddd;
    font-family: "IRANSansWeb", sans-serif;
}

.crypto-section .coin-name-cell img {
    width: 32px;
    height: 32px;
    flex-shrink: 0;
}

.crypto-section .coin-name {
    font-weight: 500;
    color: #1e1e2f;
}

/* Coin Name Wrapper (for symbol below name style) */
.crypto-section .coin-name-wrapper {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
}

.crypto-section .coin-symbol {
    font-size: 0.85em;
    color: #888;
    font-weight: 400;
    line-height: 1.2;
}

/* ===== Trade Button ===== */
.crypto-section .trade-btn {
    background: white;
    border: double 2px transparent;
    background-image: linear-gradient(white, white),
                      linear-gradient(to left, #3b82f6, #ef4444);
    background-origin: border-box;
    background-clip: padding-box, border-box;
    padding: 6px 14px;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
    font-family: "IRANSansWeb", sans-serif;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    text-decoration: none;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

.crypto-section .trade-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.15);
    text-decoration: none;
}

.crypto-section .trade-btn .buy {
    color: #3b82f6;
}

.crypto-section .trade-btn .sale {
    color: #ef4444;
}

.crypto-section .trade-btn .separator {
    color: #555;
    margin: 0 2px;
}

/* ===== Price Change Indicators ===== */
.crypto-section .up {
    color: #16a34a;
    font-weight: 600;
    direction: ltr;
}

.crypto-section .down {
    color: #dc2626;
    font-weight: 600;
    direction: ltr;
}

/* ===== Loading Spinner ===== */
.table-loading {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 10;
}

.spinner {
    border: 4px solid #f3f3f3;
    border-top: 4px solid #3b82f6;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    animation: spin 1s linear infinite;
}

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

/* ===== No Result Message ===== */
.no-result-message {
    display: none;
    text-align: center;
    color: #111;
    font-weight: 500;
    font-size: 1rem;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

/* ===== Error Message ===== */
.arzpaya-crypto-table-error {
    padding: 20px;
    text-align: center;
    color: #dc2626;
    background: #fee2e2;
    border: 1px solid #fecaca;
    border-radius: 4px;
    margin: 20px 0;
    direction: rtl;
}

/* ===== Dark Theme Styles ===== */
[data-theme="dark"] .crypto-section {
    background: transparent;
    color: var(--text-body, #e5e5e5);
}

[data-theme="dark"] .tab {
    background: var(--card-bg, #1f1f1f);
    color: var(--text-secondary, #aaa);
    border: 1px solid var(--border-color, #333);
}

[data-theme="dark"] .tab.active {
    background: var(--card-bg, #1f1f1f);
    border-top: 3px solid var(--accent-primary, #3b82f6);
    color: var(--text-primary, #fff);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

[data-theme="dark"] .searchInput {
    background: var(--card-bg, #1f1f1f);
    color: var(--text-body, #e5e5e5);
    border: 1px dashed var(--accent-primary, #3b82f6);
}

[data-theme="dark"] .searchInput:focus {
    background: var(--card-bg, #1f1f1f);
    border: 1px solid var(--accent-primary, #3b82f6);
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2);
}

[data-theme="dark"] .table-container {
    background: var(--card-bg, #1f1f1f);
    border: 1px solid var(--border-color, #333);
    border-top: none; /* Remove top border for progress bar */
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

[data-theme="dark"] .crypto-table thead {
    background: var(--header-bg, #2a2a2a);
}

[data-theme="dark"] .crypto-table th {
    background: var(--header-bg, #2a2a2a);
    color: var(--text-primary, #fff);
    border-bottom: 1px solid var(--border-color, #333);
}

[data-theme="dark"] .crypto-table {
    background: var(--card-bg, #1f1f1f);
    color: var(--text-body, #e5e5e5);
}

[data-theme="dark"] .crypto-table td {
    border-bottom: 1px solid var(--border-color, #333);
    color: var(--text-body, #e5e5e5);
}

[data-theme="dark"] .crypto-table tr:hover {
    background-color: rgba(59, 130, 246, 0.1);
}

[data-theme="dark"] .crypto-section .coin-name {
    color: var(--text-primary, #fff);
}

[data-theme="dark"] .crypto-section .coin-symbol {
    color: #aaa;
}

[data-theme="dark"] .crypto-section .trade-btn {
    background: var(--card-bg, #1f1f1f);
    border: double 2px transparent;
    background-image: linear-gradient(var(--card-bg, #1f1f1f), var(--card-bg, #1f1f1f)),
                      linear-gradient(to left, #3b82f6, #ef4444);
    background-origin: border-box;
    background-clip: padding-box, border-box;
    color: var(--text-body, #e5e5e5);
}

[data-theme="dark"] .crypto-section .trade-btn:hover {
    background: var(--card-bg, #1f1f1f);
    background-image: linear-gradient(var(--card-bg, #1f1f1f), var(--card-bg, #1f1f1f)),
                      linear-gradient(to left, #3b82f6, #ef4444);
    background-origin: border-box;
    background-clip: padding-box, border-box;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
    transform: translateY(-1px);
}

[data-theme="dark"] .crypto-section .trade-btn .buy {
    color: var(--accent-primary, #3b82f6);
}

[data-theme="dark"] .crypto-section .trade-btn .sale {
    color: #ef4444;
}

[data-theme="dark"] .crypto-section .trade-btn .separator {
    color: var(--text-secondary, #aaa);
}

[data-theme="dark"] .crypto-section .crypto-table .up {
    color: #16a34a !important;
    font-weight: 600;
    direction: ltr;
}

[data-theme="dark"] .crypto-section .crypto-table .down {
    color: #dc2626 !important;
    font-weight: 600;
    direction: ltr;
}

[data-theme="dark"] .no-result-message {
    color: var(--text-body, #e5e5e5);
}

/* ===== Mobile Responsive Styles ===== */
@media (max-width: 768px) {
    .tabs {
        width: 100%;
    }

    .tab {
        width: 50%;
        font-size: 0.9rem;
        padding: 12px 0;
    }

    .tabsAndSearchContainer {
        flex-direction: column;
        align-items: stretch;
        gap: 0; /* Remove gap to maintain vertical spacing */
    }

    .searchBox {
        width: 100%;
        justify-content: center;
        order: 1; /* Search box first (top) */
        margin-bottom: 10px; /* Space between search and tabs */
    }

    .tabs {
        order: 2; /* Tabs second (bottom) */
        margin-top: 0; /* Remove any top margin */
    }

    .searchInput {
        width: 100%;
        box-sizing: border-box;
    }

    /* Hide unnecessary columns on mobile */
    /* Show only: نام ارز, قیمت فروش, تغییرات امروز, ترید کردن */
    
    /* When showSymbolColumn=true (fixed-height): 
       - Column 1: نام ارز (show)
       - Column 2: نماد (hide)
       - Column 3: قیمت خرید (hide)
       - Column 4: قیمت فروش (show)
       - Column 5: آخرین قیمت (hide)
       - Column 6: تغییرات امروز (show) - MUST BE VISIBLE
       - Column 7: ترید کردن (show)
    */
    .arzpaya-crypto-table-fixed-height .crypto-table th:nth-child(2),
    .arzpaya-crypto-table-fixed-height .crypto-table td:nth-child(2),
    .arzpaya-crypto-table-fixed-height .crypto-table th:nth-child(3),
    .arzpaya-crypto-table-fixed-height .crypto-table td:nth-child(3),
    .arzpaya-crypto-table-fixed-height .crypto-table th:nth-child(5),
    .arzpaya-crypto-table-fixed-height .crypto-table td:nth-child(5) {
        display: none;
    }
    
    /* Ensure تغییرات امروز column is visible in fixed-height (Column 6) */
    .arzpaya-crypto-table-fixed-height .crypto-table th:nth-child(6),
    .arzpaya-crypto-table-fixed-height .crypto-table td:nth-child(6) {
        display: table-cell !important;
    }
    
    /* When showSymbolColumn=false (auto-height):
       - Column 1: نام ارز (show)
       - Column 2: قیمت خرید (hide)
       - Column 3: قیمت فروش (show)
       - Column 4: آخرین قیمت (hide)
       - Column 5: تغییرات امروز (show) - MUST BE VISIBLE
       - Column 6: ترید کردن (show)
    */
    .arzpaya-crypto-table-auto-height .crypto-table th:nth-child(2),
    .arzpaya-crypto-table-auto-height .crypto-table td:nth-child(2),
    .arzpaya-crypto-table-auto-height .crypto-table th:nth-child(4),
    .arzpaya-crypto-table-auto-height .crypto-table td:nth-child(4) {
        display: none;
    }
    
    /* Ensure تغییرات امروز column is visible in auto-height (Column 5) */
    .arzpaya-crypto-table-auto-height .crypto-table th:nth-child(5),
    .arzpaya-crypto-table-auto-height .crypto-table td:nth-child(5) {
        display: table-cell !important;
    }

    .crypto-table th,
    .crypto-table td {
        font-size: 0.85rem;
        padding: 8px 4px;
    }

    .crypto-section .trade-btn {
        padding: 5px 8px;
        font-size: 0.8rem;
        min-width: auto;
    }

    .crypto-section .coin-name-cell {
        display: flex;
        align-items: center;
        gap: 6px;
        padding: 8px 4px;
        text-align: center;
        margin-top: 0;
    }

    /* In mobile, ensure coin-name-wrapper displays correctly */
    .crypto-section .coin-name-cell .coin-name-wrapper {
        display: flex;
        flex-direction: column;
        align-items: flex-start;
        gap: 4px;
    }

    .crypto-section .coin-name-cell img {
        width: 30px;
        height: 30px;
        flex-shrink: 0;
    }

    .crypto-section .coin-name {
        font-size: 0.85rem;
        line-height: 1.3;
    }

    .crypto-section .coin-symbol {
        font-size: 0.75em;
    }

    .crypto-table td:not(:last-child),
    .crypto-table th:not(:last-child) {
        padding-left: 3px;
        padding-right: 3px;
    }

    .crypto-table td:last-child,
    .crypto-table th:last-child {
        padding-left: 3px;
        padding-right: 3px;
        width: auto;
    }
    
    /* Price change indicators font size */
    .crypto-section .crypto-table .up,
    .crypto-section .crypto-table .down {
        font-size: 0.85rem;
    }
}

@media (max-width: 480px) {
    .crypto-table th,
    .crypto-table td {
        font-size: 0.8rem;
        padding: 6px 3px;
    }

    .crypto-section .coin-name-cell {
        gap: 5px;
        padding: 6px 3px;
    }

    .crypto-section .coin-name-cell img {
        width: 26px;
        height: 26px;
    }

    .crypto-section .coin-name {
        font-size: 0.8rem;
    }

    .crypto-section .coin-symbol {
        font-size: 0.7em;
    }

    .crypto-section .trade-btn {
        padding: 4px 7px;
        font-size: 0.75rem;
    }

    .crypto-section .crypto-table .up,
    .crypto-section .crypto-table .down {
        font-size: 0.8rem;
    }
    
    /* Further reduce spacing on very small screens */
    .crypto-table td:not(:last-child),
    .crypto-table th:not(:last-child) {
        padding-left: 2px;
        padding-right: 2px;
    }

    .crypto-table td:last-child,
    .crypto-table th:last-child {
        padding-left: 2px;
        padding-right: 2px;
    }
}

