/**
 * Broker Comparison Widget - Frontend Styles
 * Matches the exact design from the provided image
 */

/* Root variables for easy customization */
.broker-comparison-widget {
    --button-color: #28a745;
    --card-bg: #ffffff;
    --text-color: #333333;
    --border-color: #e6e6e6;
    --shadow-color: rgba(0, 0, 0, 0.08);
    --hover-shadow: rgba(0, 0, 0, 0.12);
    --gray-text: #666666;
    --light-gray: #f8f9fa;
}

/* Widget container */
.broker-comparison-widget {
    margin: 20px 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    color: var(--text-color);
    line-height: 1.5;
}

/* Widget header */
.broker-widget-header {
    display: flex;
    align-items: center;
    margin-bottom: 20px;
    padding: 10px 0;
}

.broker-widget-title {
    font-size: 24px;
    font-weight: 600;
    color: var(--text-color);
    margin: 0 10px 0 0;
    line-height: 1.2;
}

.broker-widget-arrow {
    color: var(--gray-text);
    font-size: 14px;
    transform: rotate(90deg);
    transition: transform 0.3s ease;
}

/* Grid Layout */
.broker-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 20px;
    margin: 0;
}

/* Broker Card - Main container */
.broker-card {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    overflow: hidden;
    transition: all 0.3s ease;
    box-shadow: 0 2px 8px var(--shadow-color);
    position: relative;
    min-height: 280px;
    display: flex;
    flex-direction: column;
}

.broker-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 16px var(--hover-shadow);
    border-color: var(--button-color);
}

/* Broker logo */
.broker-logo {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px 15px 15px;
    background: var(--light-gray);
    border-bottom: 1px solid var(--border-color);
    min-height: 60px;
}

.broker-logo img {
    max-width: 140px;
    max-height: 50px;
    height: auto;
    width: auto;
    object-fit: contain;
    filter: brightness(0.9);
    transition: filter 0.3s ease;
}

.broker-card:hover .broker-logo img {
    filter: brightness(1);
}

/* Broker info container */
.broker-info {
    padding: 20px 15px 15px;
    flex: 1;
    display: flex;
    flex-direction: column;
}

/* Broker name */
.broker-name {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-color);
    margin: 0 0 15px 0;
    text-align: center;
    line-height: 1.3;
}

/* Broker details container */
.broker-details {
    margin-bottom: 20px;
    flex: 1;
}

/* Detail item styling - matching the exact layout from image */
.detail-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
    padding: 8px 0;
    font-size: 14px;
    line-height: 1.4;
}

.detail-item:not(:last-child) {
    border-bottom: 1px solid #f0f0f0;
}

.detail-item .label {
    font-weight: 500;
    color: var(--gray-text);
    font-size: 13px;
}

.detail-item .value {
    font-weight: 600;
    color: var(--text-color);
    font-size: 14px;
    text-align: right;
}

/* Spread color coding */
.detail-item .value.low-spread {
    color: #28a745;
    background: #e8f5e8;
    padding: 2px 6px;
    border-radius: 3px;
    font-weight: 700;
}

.detail-item .value.high-spread {
    color: #dc3545;
    background: #fdeaea;
    padding: 2px 6px;
    border-radius: 3px;
    font-weight: 700;
}

/* Custom fields styling */
.detail-item.custom-field {
    border-top: 1px solid #f0f0f0;
    margin-top: 8px;
    padding-top: 12px;
}

.detail-item.custom-field .label {
    font-style: italic;
    color: #888;
}

/* Broker button - matching the green button from image */
.broker-button {
    display: block;
    width: 100%;
    background: var(--button-color);
    color: white;
    text-decoration: none;
    padding: 12px 20px;
    text-align: center;
    border-radius: 6px;
    font-weight: 600;
    font-size: 14px;
    transition: all 0.3s ease;
    border: none;
    cursor: pointer;
    text-transform: none;
    box-shadow: 0 2px 4px rgba(40, 167, 69, 0.2);
    margin-top: auto;
}

.broker-button:hover,
.broker-button:focus {
    background: #218838;
    color: white;
    text-decoration: none;
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(40, 167, 69, 0.3);
}

.broker-button:active {
    transform: translateY(0);
    box-shadow: 0 2px 4px rgba(40, 167, 69, 0.2);
}

/* Table Layout */
.broker-table-wrapper {
    overflow-x: auto;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    box-shadow: 0 2px 8px var(--shadow-color);
    background: var(--card-bg);
    margin: 20px 0;
}

.broker-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
    margin: 0;
    min-width: 800px; /* Ensure table doesn't get too cramped */
}

.broker-table th {
    background: linear-gradient(135deg, var(--light-gray) 0%, #e9ecef 100%);
    padding: 18px 15px;
    text-align: left;
    font-weight: 700;
    color: var(--text-color);
    border-bottom: 3px solid var(--button-color);
    position: sticky;
    top: 0;
    z-index: 1;
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    white-space: nowrap;
}

.broker-table td {
    padding: 16px 15px;
    border-bottom: 1px solid #f0f0f0;
    vertical-align: middle;
    font-size: 14px;
    color: var(--text-color);
}

.broker-table tr {
    transition: background-color 0.3s ease;
}

.broker-table tr:hover {
    background: #f8f9fa;
    box-shadow: inset 0 0 0 1px rgba(40, 167, 69, 0.1);
}

.broker-table tr:last-child td {
    border-bottom: none;
}

.broker-table tr:nth-child(even) {
    background: rgba(248, 249, 250, 0.5);
}

.broker-table tr:nth-child(even):hover {
    background: #f1f3f4;
}

/* Table broker name cell with logo */
.broker-name-cell {
    display: flex;
    align-items: center;
    gap: 12px;
}

.broker-logo-small {
    width: 80px;
    height: auto;
    max-height: 35px;
    object-fit: contain;
    border-radius: 4px;
    border: 1px solid #e0e0e0;
    padding: 4px;
    background: #fff;
}

/* Table button */
.broker-button.table-button {
    display: inline-block;
    width: auto;
    padding: 10px 18px;
    font-size: 13px;
    margin: 0;
    border-radius: 6px;
    font-weight: 600;
    transition: all 0.3s ease;
    white-space: nowrap;
    min-width: 140px;
    text-align: center;
}

.broker-button.table-button:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(40, 167, 69, 0.3);
}

/* Table spread highlighting */
.broker-table .low-spread {
    color: #28a745;
    background: #e8f5e8;
    padding: 4px 8px;
    border-radius: 4px;
    font-weight: 700;
    display: inline-block;
    min-width: 40px;
    text-align: center;
}

.broker-table .high-spread {
    color: #dc3545;
    background: #fdeaea;
    padding: 4px 8px;
    border-radius: 4px;
    font-weight: 700;
    display: inline-block;
    min-width: 40px;
    text-align: center;
}

/* Table header icons */
.broker-table th:first-child {
    border-top-left-radius: 8px;
}

.broker-table th:last-child {
    border-top-right-radius: 8px;
}

/* Table data formatting */
.broker-table .broker-name-cell span {
    font-weight: 600;
    color: var(--text-color);
}

.broker-table td:has(.broker-button) {
    text-align: center;
    padding: 12px 15px;
}

/* Responsive Design */
@media (max-width: 768px) {
    .broker-grid {
        grid-template-columns: 1fr;
        gap: 15px;
    }

    .broker-card {
        min-height: auto;
    }

    .broker-logo {
        padding: 15px 10px 10px;
        min-height: 50px;
    }

    .broker-logo img {
        max-width: 120px;
        max-height: 40px;
    }

    .broker-info {
        padding: 15px 12px 12px;
    }

    .broker-name {
        font-size: 16px;
        margin-bottom: 12px;
    }

    .detail-item {
        font-size: 13px;
        margin-bottom: 6px;
        padding: 6px 0;
    }

    .detail-item .label {
        font-size: 12px;
    }

    .detail-item .value {
        font-size: 13px;
    }

    .broker-button {
        padding: 10px 16px;
        font-size: 13px;
    }

    .broker-widget-title {
        font-size: 20px;
    }

    /* Table responsiveness */
    .broker-table-wrapper {
        font-size: 12px;
    }

    .broker-table th,
    .broker-table td {
        padding: 10px 8px;
    }

    .broker-logo-small {
        width: 40px;
        max-height: 20px;
    }
}

@media (max-width: 480px) {
    .broker-comparison-widget {
        margin: 15px 0;
    }

    .broker-grid {
        gap: 10px;
    }

    .broker-logo {
        padding: 12px 8px 8px;
        min-height: 45px;
    }

    .broker-logo img {
        max-width: 100px;
        max-height: 35px;
    }

    .broker-info {
        padding: 12px 10px 10px;
    }

    .broker-name {
        font-size: 15px;
        margin-bottom: 10px;
    }

    .broker-widget-title {
        font-size: 18px;
    }

    /* Hide some table columns on very small screens */
    .broker-table th:nth-child(n+4),
    .broker-table td:nth-child(n+4) {
        display: none;
    }
}

/* Loading and Animation States */
.broker-card.loading {
    opacity: 0.7;
    pointer-events: none;
}

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

.broker-card {
    animation: fadeIn 0.5s ease-out;
}

/* Accessibility improvements */
.broker-button:focus-visible {
    outline: 2px solid var(--button-color);
    outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
    .broker-card,
    .broker-button,
    .broker-logo img {
        transition: none;
    }

    .broker-card {
        animation: none;
    }
}

/* Print styles */
@media print {
    .broker-card {
        break-inside: avoid;
        box-shadow: none;
        border: 1px solid #000;
    }

    .broker-button {
        display: none;
    }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .broker-card {
        border: 2px solid var(--text-color);
    }

    .detail-item .value.low-spread {
        background: none;
        color: #000;
        font-weight: 700;
        text-decoration: underline;
    }

    .detail-item .value.high-spread {
        background: none;
        color: #000;
        font-weight: 700;
        text-decoration: underline;
    }
}

/* Block editor specific styles */
.bcw-block-preview {
    border: 1px dashed #ccc;
    padding: 20px;
    margin: 10px 0;
    background: #f9f9f9;
}

.bcw-block-preview .broker-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 15px;
}

/* Admin preview styles */
.broker-widget-preview {
    border: 1px solid #ddd;
    padding: 20px;
    background: #fff;
    border-radius: 4px;
}

.broker-widget-preview .broker-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 15px;
}

/* Live Forex Spreads Table Widget */
.broker-spreads-table-widget {
    margin: 20px 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: #fff;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
    border: 1px solid #e9ecef;
}

/* Spreads widget header */
.spreads-widget-header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: #fff;
    padding: 24px 20px;
    text-align: center;
    position: relative;
}

.spreads-widget-title {
    font-size: 26px;
    font-weight: 700;
    color: #fff;
    margin: 0;
    line-height: 1.2;
    letter-spacing: 0.8px;
    text-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

.spreads-widget-arrow {
    position: absolute;
    right: 20px;
    top: 50%;
    transform: translateY(-50%);
    color: #fff;
    font-size: 22px;
    opacity: 0.9;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 0.9; }
    50% { opacity: 0.6; }
}

/* Spreads table container */
.spreads-table-container {
    overflow-x: auto;
}

.spreads-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
    background: #fff;
    min-width: 650px;
}

.spreads-table thead th {
    background: linear-gradient(to bottom, #f8f9fa, #e9ecef);
    padding: 20px 16px;
    text-align: left;
    font-weight: 700;
    color: #495057;
    font-size: 15px;
    border-bottom: 3px solid #007bff;
    white-space: nowrap;
    text-transform: uppercase;
    letter-spacing: 1px;
    position: relative;
}

.spreads-table thead th::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: linear-gradient(90deg, #007bff, #0056b3);
}

.spreads-table .broker-column {
    width: 40%;
    min-width: 200px;
}

.spreads-table .spread-column {
    width: 20%;
    text-align: center;
    min-width: 120px;
}

.spreads-table .action-column {
    width: 20%;
    text-align: center;
    min-width: 140px;
}

/* Broker info cell */
.broker-info-cell {
    padding: 18px 16px;
    border-bottom: 1px solid #dee2e6;
}

.broker-info-compact {
    display: flex;
    align-items: center;
    gap: 15px;
}

.broker-logo-compact {
    width: 60px;
    height: auto;
    max-height: 35px;
    object-fit: contain;
    border-radius: 6px;
    background: #fff;
    border: 1px solid #e9ecef;
    padding: 2px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.broker-logo-placeholder {
    width: 60px;
    height: 35px;
    background: linear-gradient(135deg, #e9ecef, #dee2e6);
    color: #6c757d;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-size: 16px;
    border-radius: 6px;
    border: 1px solid #dee2e6;
}

.broker-name-compact {
    font-weight: 700;
    color: #212529;
    font-size: 16px;
    line-height: 1.4;
}

/* Spread cells */
.spread-cell {
    padding: 18px 12px;
    text-align: center;
    border-bottom: 1px solid #dee2e6;
    font-weight: 700;
}

.spread-value {
    font-weight: 800;
    padding: 8px 16px;
    border-radius: 25px;
    font-size: 15px;
    display: inline-block;
    min-width: 70px;
    text-align: center;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    transition: all 0.3s ease;
}

.spread-value:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.15);
}

.spread-value.excellent-spread {
    background: linear-gradient(135deg, #d4edda, #c3e6cb);
    color: #155724;
    border: 2px solid #b8e6c1;
}

.spread-value.good-spread {
    background: linear-gradient(135deg, #d1ecf1, #bee5eb);
    color: #0c5460;
    border: 2px solid #a6d9e5;
}

.spread-value.average-spread {
    background: linear-gradient(135deg, #fff3cd, #ffeaa7);
    color: #856404;
    border: 2px solid #f4d03f;
}

.spread-value.high-spread {
    background: linear-gradient(135deg, #f8d7da, #f1b0b7);
    color: #721c24;
    border: 2px solid #e6a8b0;
}

/* Action cell */
.action-cell {
    padding: 18px 12px;
    text-align: center;
    border-bottom: 1px solid #dee2e6;
}

.spreads-button {
    display: inline-block;
    padding: 12px 24px;
    background: linear-gradient(135deg, #28a745, #20c997);
    color: #fff;
    text-decoration: none;
    border-radius: 30px;
    font-size: 14px;
    font-weight: 700;
    transition: all 0.3s ease;
    white-space: nowrap;
    text-transform: uppercase;
    letter-spacing: 1px;
    box-shadow: 0 3px 6px rgba(40, 167, 69, 0.3);
    min-width: 120px;
}

.spreads-button:hover {
    background: linear-gradient(135deg, #218838, #1ea080);
    color: #fff;
    text-decoration: none;
    transform: translateY(-2px);
    box-shadow: 0 6px 12px rgba(40, 167, 69, 0.4);
}

.spreads-button:active {
    transform: translateY(-1px);
}

/* Row hover effects */
.broker-row {
    transition: all 0.3s ease;
    background: #fff;
}

.broker-row:nth-child(even) {
    background: #fafbfc;
}

.broker-row:hover {
    background: linear-gradient(to right, #f8f9fa, #e9ecef);
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.broker-row:nth-child(even):hover {
    background: linear-gradient(to right, #f1f3f4, #e8eaed);
}

.broker-row:last-child td {
    border-bottom: none;
}

/* Responsive design for spreads table */
@media (max-width: 768px) {
    .spreads-widget-title {
        font-size: 22px;
        letter-spacing: 0.5px;
    }

    .spreads-widget-header {
        padding: 20px 15px;
    }

    .spreads-table {
        min-width: 550px;
        font-size: 13px;
    }

    .spreads-table thead th {
        padding: 16px 12px;
        font-size: 13px;
    }

    .broker-info-cell,
    .spread-cell,
    .action-cell {
        padding: 15px 12px;
    }

    .broker-info-compact {
        gap: 12px;
    }

    .broker-logo-compact {
        width: 50px;
        max-height: 30px;
    }

    .broker-logo-placeholder {
        width: 50px;
        height: 30px;
        font-size: 14px;
    }

    .broker-name-compact {
        font-size: 15px;
    }

    .spread-value {
        font-size: 14px;
        padding: 6px 14px;
        min-width: 60px;
    }

    .spreads-button {
        padding: 10px 20px;
        font-size: 13px;
        min-width: 110px;
    }
}

@media (max-width: 480px) {
    .spreads-widget-title {
        font-size: 20px;
    }

    .spreads-table {
        min-width: 480px;
    }

    .spreads-table thead th {
        padding: 14px 8px;
        font-size: 12px;
    }

    .broker-info-cell,
    .spread-cell,
    .action-cell {
        padding: 12px 8px;
    }

    .broker-info-compact {
        gap: 10px;
    }

    .broker-logo-compact {
        width: 40px;
        max-height: 25px;
    }

    .broker-logo-placeholder {
        width: 40px;
        height: 25px;
        font-size: 12px;
    }

    .broker-name-compact {
        font-size: 14px;
    }

    .spread-value {
        font-size: 13px;
        padding: 5px 12px;
        min-width: 55px;
    }

    .spreads-button {
        padding: 8px 16px;
        font-size: 12px;
        min-width: 100px;
    }
}