/* BestChange Parser - Modern UI Styles */

:root {
    --primary: #4f46e5;
    --primary-hover: #4338ca;
    --secondary: #6b7280;
    --success: #10b981;
    --danger: #ef4444;
    --warning: #f59e0b;
    --bg-main: #f3f4f6;
    --bg-card: #ffffff;
    --bg-dark: #1f2937;
    --text-primary: #111827;
    --text-secondary: #6b7280;
    --border: #e5e7eb;
    --shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    --radius: 8px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background: var(--bg-main);
    color: var(--text-primary);
    line-height: 1.5;
}

/* Header */
.header {
    background: var(--bg-dark);
    color: white;
    padding: 1rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: var(--shadow);
}

.header h1 {
    font-size: 1.5rem;
    font-weight: 600;
}

.header-status {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.875rem;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--success);
}

.status-dot.error {
    background: var(--danger);
}

/* Navigation */
.nav {
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    padding: 0 2rem;
}

.nav-tabs {
    display: flex;
    gap: 0;
    list-style: none;
}

.nav-tab {
    padding: 1rem 1.5rem;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    color: var(--text-secondary);
    font-weight: 500;
    transition: all 0.2s;
}

.nav-tab:hover {
    color: var(--primary);
    background: rgba(79, 70, 229, 0.05);
}

.nav-tab.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}

/* Main container */
.main {
    padding: 2rem;
    max-width: 1400px;
    margin: 0 auto;
}

/* Sections */
.section {
    display: none;
}

.section.active {
    display: block;
}

/* Cards */
.card {
    background: var(--bg-card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border);
}

.card-title {
    font-size: 1.125rem;
    font-weight: 600;
}

/* Buttons */
.btn {
    padding: 0.5rem 1rem;
    border-radius: var(--radius);
    border: none;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}

.btn-primary {
    background: var(--primary);
    color: white;
}

.btn-primary:hover {
    background: var(--primary-hover);
}

.btn-secondary {
    background: var(--secondary);
    color: white;
}

.btn-secondary:hover {
    background: #5b6170;
}

.btn-success {
    background: var(--success);
    color: white;
}

.btn-danger {
    background: var(--danger);
    color: white;
}

.btn-outline {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-secondary);
}

.btn-outline:hover {
    border-color: var(--primary);
    color: var(--primary);
}

.btn-sm {
    padding: 0.25rem 0.75rem;
    font-size: 0.75rem;
}

.btn-lg {
    padding: 0.75rem 1.5rem;
    font-size: 1rem;
}

/* Forms */
.form-group {
    margin-bottom: 1rem;
}

.form-label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    color: var(--text-secondary);
    font-size: 0.875rem;
}

.form-input, .form-select {
    width: 100%;
    padding: 0.625rem 0.875rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.875rem;
    transition: border-color 0.2s;
}

.form-input:focus, .form-select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
}

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

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

.table th, .table td {
    padding: 0.75rem 1rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

.table th {
    background: var(--bg-main);
    font-weight: 600;
    color: var(--text-secondary);
}

.table tr:hover {
    background: rgba(79, 70, 229, 0.02);
}

/* Tags/Badges */
.badge {
    display: inline-block;
    padding: 0.25rem 0.5rem;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 500;
}

.badge-success {
    background: rgba(16, 185, 129, 0.1);
    color: var(--success);
}

.badge-danger {
    background: rgba(239, 68, 68, 0.1);
    color: var(--danger);
}

.badge-warning {
    background: rgba(245, 158, 11, 0.1);
    color: var(--warning);
}

/* Smaller badge for currency items */
.currency-item .badge {
    font-size: 0.6rem;
    padding: 0.15rem 0.35rem;
    flex-shrink: 0;
    white-space: nowrap;
}

.badge-secondary {
    background: rgba(107, 114, 128, 0.1);
    color: var(--secondary);
}

/* Search & Filters */
.search-box {
    position: relative;
    max-width: 300px;
}

.search-box input {
    padding-left: 2.5rem;
}

.search-icon {
    position: absolute;
    left: 0.875rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-secondary);
}

.filters {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
    margin-bottom: 1rem;
}

/* Searchable Select */
.searchable-select {
    position: relative;
}

.searchable-select input {
    width: 100%;
}

.select-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    max-height: 350px;
    overflow-y: auto;
    z-index: 100;
    display: none;
}

.select-dropdown.active {
    display: block;
}

.select-option {
    padding: 0.5rem 0.75rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.875rem;
    border-bottom: 1px solid var(--border);
}

.select-option:last-child {
    border-bottom: none;
}

.select-option:hover {
    background: rgba(79, 70, 229, 0.05);
}

.select-option.selected {
    background: rgba(79, 70, 229, 0.1);
}

.select-option .currency-code {
    font-weight: 600;
    min-width: 60px;
}

.select-option .currency-name {
    color: var(--text-secondary);
    font-size: 0.75rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.select-option .badge {
    margin-left: auto;
    flex-shrink: 0;
}

.select-no-results {
    padding: 1rem;
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.875rem;
}

/* Currency selector */
.currency-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 0.75rem;
    max-height: 400px;
    overflow-y: auto;
    padding: 0.5rem;
}

.currency-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    transition: all 0.2s;
    font-size: 0.875rem;
    overflow: hidden;
    flex-wrap: wrap;
}

.currency-item:hover {
    border-color: var(--primary);
    background: rgba(79, 70, 229, 0.05);
}

.currency-item.selected {
    border-color: var(--primary);
    background: rgba(79, 70, 229, 0.1);
}

.currency-item input {
    margin: 0;
}

.currency-code {
    font-weight: 600;
}

.currency-name {
    color: var(--text-secondary);
    font-size: 0.75rem;
}

/* Task cards */
.task-list {
    display: grid;
    gap: 1rem;
}

.task-card {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
    display: grid;
    grid-template-columns: auto 1fr auto;
    gap: 1rem;
    align-items: center;
}

.task-status {
    width: 12px;
    height: 12px;
    border-radius: 50%;
}

.task-status.running {
    background: var(--primary);
    animation: pulse 1.5s infinite;
}

.task-status.success {
    background: var(--success);
}

.task-status.error {
    background: var(--danger);
}

.task-status.disabled {
    background: var(--secondary);
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.task-info h3 {
    font-size: 1rem;
    margin-bottom: 0.25rem;
}

.task-meta {
    display: flex;
    gap: 1rem;
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.task-actions {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

/* Task toggle switch */
.task-toggle {
    position: relative;
    width: 44px;
    height: 24px;
    display: inline-block;
}

.task-toggle input {
    opacity: 0;
    width: 0;
    height: 0;
}

.task-toggle .toggle-slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: var(--secondary);
    transition: 0.3s;
    border-radius: 24px;
}

.task-toggle .toggle-slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: 0.3s;
    border-radius: 50%;
}

.task-toggle input:checked + .toggle-slider {
    background-color: var(--success);
}

.task-toggle input:checked + .toggle-slider:before {
    transform: translateX(20px);
}

/* Direction builder */
.direction-list {
    margin-bottom: 1rem;
}

.direction-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem;
    background: var(--bg-main);
    border-radius: var(--radius);
    margin-bottom: 0.5rem;
}

.direction-arrow {
    color: var(--text-secondary);
    font-weight: bold;
}

/* Filter items (blacklist/whitelist) */
.filter-items {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: 0.5rem;
    min-height: 30px;
}

.filter-item {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.25rem 0.5rem;
    background: var(--bg-main);
    border: 1px solid var(--border);
    border-radius: 9999px;
    font-size: 0.75rem;
}

.filter-item .remove-btn {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--danger);
    font-size: 0.875rem;
    padding: 0;
    line-height: 1;
}

/* Direction cards in task view */
.direction-card {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.75rem 1rem;
    margin-bottom: 0.5rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    background: var(--bg-card);
}

.direction-toggle {
    position: relative;
    width: 40px;
    height: 20px;
}

.direction-toggle input {
    opacity: 0;
    width: 0;
    height: 0;
}

.direction-toggle .slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: var(--secondary);
    transition: 0.3s;
    border-radius: 20px;
}

.direction-toggle .slider:before {
    position: absolute;
    content: "";
    height: 14px;
    width: 14px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: 0.3s;
    border-radius: 50%;
}

.direction-toggle input:checked + .slider {
    background-color: var(--success);
}

.direction-toggle input:checked + .slider:before {
    transform: translateX(20px);
}

.direction-info {
    flex: 1;
}

.direction-pair {
    font-weight: 600;
    font-size: 0.95rem;
}

.direction-rate {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin-top: 0.25rem;
}

.direction-rate .rate-value {
    color: var(--success);
    font-weight: 600;
}

.direction-rate .changer-name {
    color: var(--primary);
}

.direction-actions {
    display: flex;
    gap: 0.5rem;
}

/* Difference colors in rating */
.diff-positive {
    color: var(--success);
}

.diff-negative {
    color: var(--danger);
}

.diff-zero {
    color: var(--text-secondary);
}

/* Rate display */
.rate-card {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 1rem;
}

.rate-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem;
    background: var(--bg-main);
    border-bottom: 1px solid var(--border);
    cursor: pointer;
}

.rate-pair {
    font-weight: 600;
}

.rate-best {
    color: var(--success);
    font-weight: 600;
}

.rate-body {
    display: none;
    padding: 1rem;
}

.rate-body.expanded {
    display: block;
}

/* XML Files */
.file-list {
    display: grid;
    gap: 0.5rem;
}

.file-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

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

.file-icon {
    width: 36px;
    height: 36px;
    background: rgba(79, 70, 229, 0.1);
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--primary);
}

.file-name {
    font-weight: 500;
}

.file-meta {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.file-url {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.5rem;
    align-items: center;
}

.file-urls {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    margin-top: 0.5rem;
}

.file-url-row {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.file-format-label {
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--text-secondary);
    min-width: 35px;
}

.url-input {
    flex: 1;
    min-width: 250px;
    padding: 0.25rem 0.5rem;
    font-size: 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-main);
    color: var(--text-primary);
}

.file-actions {
    display: flex;
    gap: 0.5rem;
    flex-shrink: 0;
}

/* Modal */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    display: none;
}

.modal-overlay.active {
    display: flex;
}

.modal {
    background: var(--bg-card);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 600px;
    max-height: 90vh;
    overflow: auto;
}

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

.modal-title {
    font-size: 1.125rem;
    font-weight: 600;
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-secondary);
}

.modal-body {
    padding: 1.5rem;
}

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

/* Loading */
.loading {
    display: flex;
    justify-content: center;
    padding: 2rem;
}

.spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

/* Toast notifications */
.toast-container {
    position: fixed;
    top: 1rem;
    right: 1rem;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.toast {
    padding: 0.75rem 1rem;
    background: var(--bg-card);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    display: flex;
    align-items: center;
    gap: 0.75rem;
    animation: slideIn 0.3s ease;
}

.toast.success {
    border-left: 4px solid var(--success);
}

.toast.error {
    border-left: 4px solid var(--danger);
}

@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

/* Responsive */
@media (max-width: 768px) {
    .header {
        padding: 1rem;
    }
    
    .nav {
        padding: 0 1rem;
        overflow-x: auto;
    }
    
    .main {
        padding: 1rem;
    }
    
    .form-row {
        grid-template-columns: 1fr;
    }
    
    .task-card {
        grid-template-columns: auto 1fr;
    }
    
    .task-actions {
        grid-column: span 2;
        justify-content: flex-end;
    }
}

/* ==================== WorldCash Rate Browser ==================== */

.wc-browser-card {
    padding: 1rem 1.5rem;
}

.wc-filters {
    display: flex;
    gap: 1rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}

.wc-filter-group {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    min-width: 160px;
    flex: 1;
}

.wc-filter-label {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.wc-filter-select {
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-card);
    color: var(--text-primary);
    font-size: 0.875rem;
    cursor: pointer;
    appearance: auto;
}

.wc-filter-select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(79, 70, 229, 0.15);
}

/* Rate Table */
.wc-table-wrap {
    overflow-x: auto;
    border: 1px solid #2d3748;
    border-radius: var(--radius);
    max-height: 65vh;
    overflow-y: auto;
}

.wc-table {
    width: 100%;
    border-collapse: collapse;
    background: #1a202c;
    color: #e2e8f0;
    font-size: 0.85rem;
}

.wc-table thead {
    position: sticky;
    top: 0;
    z-index: 1;
}

.wc-table th {
    background: #2d3748;
    color: #a0aec0;
    padding: 0.6rem 0.75rem;
    text-align: left;
    font-weight: 600;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    border-bottom: 2px solid #4a5568;
    white-space: nowrap;
    user-select: none;
}

.wc-table td {
    padding: 0.55rem 0.75rem;
    border-bottom: 1px solid #2d3748;
    white-space: nowrap;
}

.wc-table tbody tr {
    transition: background 0.15s;
}

.wc-table tbody tr:hover {
    background: #2d3748;
}

.wc-table tbody tr.wc-selected {
    background: rgba(79, 70, 229, 0.15);
}

.wc-table tbody tr.wc-selected:hover {
    background: rgba(79, 70, 229, 0.25);
}

.wc-table tbody tr.wc-blocked {
    opacity: 0.4;
}

/* Type badges */
.wc-badge-in {
    display: inline-block;
    padding: 0.15rem 0.5rem;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 700;
    background: #10b981;
    color: #fff;
}

.wc-badge-out {
    display: inline-block;
    padding: 0.15rem 0.5rem;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 700;
    background: #ef4444;
    color: #fff;
}

/* Amounts */
.wc-amount {
    display: flex;
    flex-direction: column;
    gap: 2px;
    font-size: 0.8rem;
}

.wc-amount-crypto {
    color: #e2e8f0;
    font-weight: 500;
}

.wc-amount-fiat {
    color: #718096;
    font-size: 0.75rem;
}

/* Checkbox in table */
.wc-table input[type="checkbox"] {
    width: 16px;
    height: 16px;
    cursor: pointer;
    accent-color: var(--primary);
}

/* Control Panel */
.wc-control-panel {
    padding: 1rem 1.5rem;
    position: sticky;
    bottom: 0;
    z-index: 10;
    border-top: 2px solid var(--primary);
}

.wc-control-row {
    display: flex;
    align-items: center;
    gap: 1.5rem;
    flex-wrap: wrap;
}

.wc-control-info {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    min-width: 120px;
}

.wc-selected-count {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--primary);
}

.wc-parsing-status {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.wc-control-settings {
    display: flex;
    gap: 1rem;
    align-items: flex-end;
}

.wc-control-field {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
}

.wc-control-field label {
    font-size: 0.7rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    font-weight: 600;
}

.wc-control-field .form-input {
    padding: 0.35rem 0.5rem;
    font-size: 0.85rem;
}

.wc-control-actions {
    display: flex;
    gap: 0.5rem;
    margin-left: auto;
    flex-wrap: wrap;
}

/* Table loading state */
.wc-table-loading {
    text-align: center;
    padding: 3rem;
    color: #718096;
}

.wc-table-loading .spinner {
    display: inline-block;
    width: 24px;
    height: 24px;
    border: 3px solid #4a5568;
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-bottom: 0.5rem;
}

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

/* Responsive */
@media (max-width: 768px) {
    .wc-filters {
        flex-direction: column;
    }
    .wc-control-row {
        flex-direction: column;
        align-items: stretch;
    }
    .wc-control-actions {
        margin-left: 0;
        justify-content: flex-end;
    }
}
