/* Chortkeh - English Version - Simplified Styles */

:root {
    /* Light Mode */
    --primary: #3b82f6;
    --primary-dark: #2563eb;
    --accent: #f59e0b;
    --bg: #f8fafc;
    --card-bg: #ffffff;
    --text: #334155;
    --text-light: #64748b;
    --sell-color: #ef4444;
    --buy-color: #10b981;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --header-gradient: linear-gradient(135deg, var(--primary), var(--primary-dark));
    --block-bg: #f1f5f9;
    --block-border: #e2e8f0;
    --error-bg: #fee2e2;
    --error-text: #b91c1c;
    --error-border: #fca5a5;
}

@media (prefers-color-scheme: dark) {
    :root {
        --primary: #60a5fa;
        --primary-dark: #3b82f6;
        --bg: #0f172a;
        --card-bg: #1e293b;
        --text: #f1f5f9;
        --text-light: #94a3b8;
        --sell-color: #f87171;
        --buy-color: #34d399;
        --shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.5), 0 4px 6px -2px rgba(0, 0, 0, 0.3);
        --header-gradient: linear-gradient(135deg, #1e293b, #0f172a);
        --block-bg: #334155;
        --block-border: #475569;
    }
}

* {
    box-sizing: border-box;
}

html {
    height: 100%;
    overscroll-behavior: none;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    margin: 0;
    padding: 0;
    background-color: var(--bg);
    color: var(--text);
    display: flex;
    flex-direction: column;
    height: 100%;
    width: 100%;
    overflow-x: hidden;
    overflow-y: auto;
    transition: background-color 0.3s, color 0.3s;
    -webkit-tap-highlight-color: transparent;
}

.num-font {
    font-family: 'Roboto', monospace;
    font-weight: 500;
}

/* Loading & Banners */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: linear-gradient(90deg, var(--primary), var(--accent));
    z-index: 9999;
    display: none;
    animation: progress 2s infinite linear;
    background-size: 200% 100%;
}

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

    100% {
        background-position: -100% 0;
    }
}

.error-banner,
.offline-banner {
    background-color: var(--error-bg);
    color: var(--error-text);
    border-bottom: 3px solid var(--error-border);
    text-align: center;
    padding: 1rem;
    font-weight: 500;
    display: none;
    flex-direction: column;
    gap: 0.5rem;
    align-items: center;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

.offline-banner {
    background-color: #ff7675;
    color: white;
    border-bottom-color: #fab1a0;
}

.retry-btn {
    background-color: var(--error-text);
    color: white;
    border: none;
    padding: 0.5rem 1.5rem;
    border-radius: 6px;
    cursor: pointer;
    font-family: inherit;
    font-size: 0.9rem;
    transition: opacity 0.2s;
}

.retry-btn:hover {
    opacity: 0.9;
}

/* Header */
header {
    background: var(--header-gradient);
    width: 100%;
    padding: 1rem 0;
    color: white;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    margin-bottom: 2rem;
    display: flex;
    justify-content: center;
}

.header-inner {
    width: 90%;
    max-width: 900px;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 1rem;
}

.header-logo {
    width: 48px;
    height: 48px;
    border-radius: 8px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
}

.header-text {
    text-align: left;
}

h1 {
    margin: 0;
    font-weight: 800;
    font-size: 1.8rem;
    letter-spacing: -0.5px;
    line-height: 1;
}

.subtitle {
    margin-top: 0.2rem;
    opacity: 0.9;
    font-size: 0.9rem;
    font-weight: 300;
}

/* Container */
.container {
    width: 90%;
    max-width: 900px;
    display: flex;
    flex-direction: column;
    gap: 2rem;
    padding-bottom: 4rem;
    margin: 0 auto;
}

/* Cards */
.card {
    background: var(--card-bg);
    border-radius: 24px;
    padding: 10px;
    box-shadow: var(--shadow);
    transition: transform 0.2s, background-color 0.3s;
}

/* Calculator */
.calculator-container {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    position: relative;
}

@media (min-width: 768px) {
    .calculator-container {
        flex-direction: row;
        align-items: center;
    }
}

.calc-block {
    flex: 1;
    min-width: 0;
    background: transparent;
    border: none;
    padding: 10px;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.block-label {
    font-size: 0.9rem;
    font-weight: bold;
    color: var(--text-light);
    text-align: left;
}

.block-content {
    display: flex;
    align-items: center;
    gap: 0.8rem;
}

.block-content.vertical {
    flex-direction: column;
    align-items: stretch;
    gap: 0px;
}

.input-wrapper {
    position: relative;
    width: 100%;
}

.block-input {
    background: transparent;
    border: 2px solid #dfe6e9;
    border-radius: 16px;
    font-size: 1.8rem;
    color: var(--text);
    flex: 1;
    padding: 0 1rem;
    height: 64px;
    outline: none;
    direction: ltr;
    text-align: left;
    min-width: 60px;
    width: 100%;
    transition: all 0.2s;
}

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

.block-input::placeholder {
    color: #bdc3c7;
}

/* Swap Button */
.swap-container {
    display: flex;
    justify-content: center;
    margin: -25px 0;
    z-index: 10;
    position: relative;
}

@media (min-width: 768px) {
    .swap-container {
        position: relative;
        width: auto;
        height: auto;
        margin: 0;
    }
}

.swap-btn {
    background: rgba(59, 130, 246, 0.15);
    color: var(--primary);
    border: 1px solid rgba(59, 130, 246, 0.2);
    backdrop-filter: blur(8px);
    width: 48px;
    height: 48px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.4rem;
    transition: all 0.2s;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
}

.swap-btn:hover {
    background: rgba(59, 130, 246, 0.3);
    transform: scale(1.05);
}

/* Custom Select */
.custom-select-wrapper {
    position: relative;
    user-select: none;
    width: 100%;
}

.custom-select-trigger {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1rem;
    font-size: 1rem;
    font-weight: bold;
    color: var(--text);
    height: 56px;
    cursor: pointer;
    background: rgba(255, 255, 255, 0.5);
    backdrop-filter: blur(10px);
    border: 2px solid transparent;
    border-radius: 16px;
    transition: all 0.2s;
}

.custom-select-trigger:hover {
    background: rgba(255, 255, 255, 0.7);
}

.custom-select-wrapper.open .custom-select-trigger {
    border-color: var(--primary);
    background: rgba(255, 255, 255, 0.8);
}

.custom-options {
    position: absolute;
    top: 110%;
    left: 0;
    right: 0;
    border: 1px solid rgba(0, 0, 0, 0.05);
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(12px);
    border-radius: 16px;
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.15);
    z-index: 100;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transform: translateY(-10px);
    transition: all 0.2s;
    max-height: 300px;
    overflow-y: auto;
}

.custom-select-wrapper.open .custom-options {
    opacity: 1;
    visibility: visible;
    pointer-events: all;
    transform: translateY(0);
}

.option-item {
    padding: 0.8rem 1rem;
    display: flex;
    justify-content: space-between;
    cursor: pointer;
    transition: background 0.2s;
    border-bottom: 1px solid rgba(0, 0, 0, 0.03);
}

.option-item:hover {
    background: rgba(0, 0, 0, 0.03);
}

.option-item.selected {
    background: rgba(59, 130, 246, 0.1);
    color: var(--primary);
}

/* Currency Cards Grid */
.cards-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 1rem;
    margin-bottom: 1rem;
}

.currency-card {
    background: var(--card-bg);
    border-radius: 24px;
    box-shadow: var(--shadow);
    transition: transform 0.2s, box-shadow 0.2s, border-color 0.2s;
    cursor: pointer;
    position: relative;
    overflow: hidden;
    border: 2px solid transparent;
    aspect-ratio: 1 / 1;
    padding: 10px;
}

.currency-card:hover {
    transform: translateY(-4px);
    border-color: var(--primary);
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
}

.currency-card:active {
    transform: scale(0.96);
}

.card-icon {
    position: absolute;
    top: 14px;
    left: 14px;
    font-size: 1.8rem;
}

.card-info {
    position: absolute;
    top: 14px;
    right: 14px;
    text-align: right;
}

.card-code {
    font-size: 0.8rem;
    color: var(--text-light);
    text-transform: uppercase;
    font-weight: bold;
    opacity: 0.7;
}

.card-name {
    font-size: 0.85rem;
    font-weight: bold;
    margin-top: 0.2rem;
    color: var(--text);
    white-space: nowrap;
}

.card-price {
    position: absolute;
    bottom: 14px;
    left: 14px;
    text-align: left;
    font-size: clamp(1.1rem, 6vw, 1.5rem);
    color: var(--text);
    letter-spacing: -0.5px;
    direction: ltr;
}

/* Tables */
.table-wrapper {
    overflow-x: auto;
    padding: 0.5rem;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 1rem;
}

th,
td {
    text-align: center;
    padding: 1.2rem 0.8rem;
    border-bottom: 1px solid #f0f0f0;
    white-space: nowrap;
}

th {
    color: var(--text-light);
    font-weight: 500;
    font-size: 0.9rem;
}

.sell-val {
    color: var(--sell-color);
}

.buy-val {
    color: var(--buy-color);
}

/* Details/Summary */
details {
    background: var(--card-bg);
    border-radius: 24px;
    padding: 10px;
    box-shadow: var(--shadow);
    margin-bottom: 1rem;
}

summary {
    padding: 10px;
    cursor: pointer;
    font-weight: bold;
    display: flex;
    justify-content: space-between;
    align-items: center;
    list-style: none;
    color: var(--text);
    font-size: 1.1rem;
}

summary::-webkit-details-marker {
    display: none;
}

summary::after {
    content: '+';
    font-size: 1.5rem;
    color: var(--primary);
    transition: transform 0.2s;
}

details[open] summary::after {
    transform: rotate(45deg);
}

/* Buttons */
.btn-print {
    background: transparent;
    border: 2px solid #bdc3c7;
    color: #7f8c8d;
    padding: 0.8rem 2rem;
    border-radius: 50px;
    font-family: inherit;
    cursor: pointer;
    font-size: 1rem;
    font-weight: bold;
    transition: all 0.2s;
}

.btn-print:hover {
    border-color: var(--primary);
    color: var(--primary);
    background: rgba(46, 134, 222, 0.05);
    transform: translateY(-1px);
}

/* Timestamp */
.timestamp-container {
    margin-top: 1.5rem;
    display: inline-block;
    font-size: 0.9rem;
    color: var(--text-light);
    background: rgba(255, 255, 255, 0.6);
    backdrop-filter: blur(5px);
    padding: 1rem 1.5rem;
    border-radius: 16px;
    width: 100%;
}

.source-info {
    text-align: left;
    font-size: 0.85em;
    color: var(--text-light);
    margin-top: 10px;
    padding: 0 0.5rem;
}

/* Dark Mode Overrides */
@media (prefers-color-scheme: dark) {
    .block-input {
        color: var(--text);
        background: transparent;
        border-color: #636e72;
    }

    .block-input:focus {
        border-color: #74b9ff;
    }

    .custom-select-trigger {
        background: rgba(30, 41, 59, 0.4);
        color: var(--text);
    }

    .custom-options {
        background: rgba(15, 23, 42, 0.95);
        border-color: rgba(255, 255, 255, 0.05);
    }

    .timestamp-container {
        background: rgba(255, 255, 255, 0.05);
        color: var(--text-light);
    }

    th {
        color: var(--text-light);
        border-bottom-color: #334155;
    }

    td {
        border-bottom-color: #334155;
    }
}

/* Responsive */
@media (max-width: 480px) {
    .cards-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.5rem;
    }
}

/* Trend Indicators */
.trend-indicator {
    font-size: 0.75rem;
    padding: 2px 6px;
    border-radius: 4px;
    display: inline-flex;
    align-items: center;
    gap: 2px;
    margin-right: 6px;
    font-weight: bold;
}

.trend-up {
    background-color: rgba(16, 185, 129, 0.1);
    color: var(--buy-color);
}

.trend-down {
    background-color: rgba(239, 68, 68, 0.1);
    color: var(--sell-color);
}

.trend-neutral {
    background-color: rgba(100, 116, 139, 0.1);
    color: var(--text-light);
}

.price-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-top: 2px;
}

/* Advanced Custom Select */
.dropdown-search-box {
    padding: 10px;
    background: #f8fafc;
    border-bottom: 1px solid rgba(0, 0, 0, 0.05);
    position: sticky;
    top: 0;
    z-index: 10;
}

.dropdown-search-box input {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    font-size: 0.9rem;
    outline: none;
    transition: all 0.2s;
}

.dropdown-search-box input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.1);
}

.option-category {
    padding: 6px 12px;
    font-size: 0.75rem;
    font-weight: bold;
    color: var(--text-light);
    background: #f1f5f9;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    position: sticky;
    top: 55px;
    /* Adjust based on search box height */
}

/* Pull to Refresh */
.pull-indicator {
    position: fixed;
    top: -50px;
    left: 50%;
    transform: translateX(-50%);
    background: white;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    transition: transform 0.2s;
    opacity: 0;
}

.pull-indicator.visible {
    opacity: 1;
}

.pull-spinner {
    width: 20px;
    height: 20px;
    border: 2px solid var(--primary);
    border-top-color: transparent;
    border-radius: 50%;
}

.pull-indicator.loading .pull-spinner {
    animation: spin 1s linear infinite;
}

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

/* Search Container for Grid */
#searchContainer input {
    width: 100%;
    padding: 0.8rem;
    border-radius: 12px;
    border: 1px solid #e2e8f0;
    font-size: 1rem;
    background: var(--card-bg);
    color: var(--text);
    outline: none;
    transition: all 0.2s;
}

#searchContainer input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

/* Dark Mode Extensions */
@media (prefers-color-scheme: dark) {
    .dropdown-search-box {
        background: #1e293b;
        border-color: rgba(255, 255, 255, 0.1);
    }

    .dropdown-search-box input {
        background: #0f172a;
        border-color: #334155;
        color: white;
    }

    .option-category {
        background: #334155;
        color: #cbd5e1;
    }

    .pull-indicator {
        background: #334155;
    }

    #searchContainer input {
        background: var(--card-bg);
        border-color: #334155;
        color: white;
    }
}

/* Print Styles */
@media print {
    body {
        background: white;
        color: black;
    }

    header,
    .refresh-section,
    .offline-banner,
    .subtitle,
    summary::after {
        display: none !important;
    }

    .cards-grid {
        display: none !important;
    }

    #calculatorSection {
        box-shadow: none !important;
        border: 1px solid #ddd;
    }
}