/**
 * MSL Tools Renderer - Core Styles
 * Based on Base44 design system
 */

/* CSS Variables */
:root {
    --msl-primary: #10b981;
    --msl-primary-dark: #059669;
    --msl-success: #22c55e;
    --msl-warning: #f59e0b;
    --msl-danger: #ef4444;
    --msl-info: #3b82f6;
    --msl-gray-50: #f9fafb;
    --msl-gray-100: #f3f4f6;
    --msl-gray-200: #e5e7eb;
    --msl-gray-300: #d1d5db;
    --msl-gray-400: #9ca3af;
    --msl-gray-500: #6b7280;
    --msl-gray-600: #4b5563;
    --msl-gray-700: #374151;
    --msl-gray-800: #1f2937;
    --msl-gray-900: #111827;
    --msl-radius: 12px;
    --msl-radius-sm: 8px;
    --msl-shadow: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
    --msl-shadow-md: 0 4px 6px -1px rgba(0,0,0,0.1), 0 2px 4px -1px rgba(0,0,0,0.06);
    --msl-transition: all 0.2s ease;
}

/* RTL Support */
[dir="rtl"] .msl-tool-result,
.rtl .msl-tool-result,
:lang(he) .msl-tool-result {
    direction: rtl;
    text-align: right;
}

/* Base Container */
.msl-tool-result {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    line-height: 1.6;
    color: var(--msl-gray-800);
    max-width: 900px;
    margin: 0 auto;
    padding: 0 16px;
}

/* Widgets Container */
.msl-widgets {
    display: flex;
    flex-direction: column;
    gap: 24px;
    margin-bottom: 32px;
}

.msl-widget {
    background: #fff;
    border-radius: var(--msl-radius);
    border: 1px solid var(--msl-gray-200);
    overflow: hidden;
}

/* ============================================
   KPI Cards
   ============================================ */
.msl-kpi-cards {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
    padding: 0;
}

.msl-widget--kpi_cards {
    background: transparent;
    border: none;
}

.msl-kpi-card {
    background: #fff;
    border: 1px solid var(--msl-gray-200);
    border-radius: var(--msl-radius);
    padding: 20px;
    text-align: center;
    transition: var(--msl-transition);
}

.msl-kpi-card:hover {
    border-color: var(--msl-primary);
    box-shadow: var(--msl-shadow-md);
}

.msl-kpi-card__label {
    display: block;
    font-size: 12px;
    font-weight: 500;
    color: var(--msl-gray-500);
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.msl-kpi-card__value {
    display: block;
    font-size: 28px;
    font-weight: 700;
    color: var(--msl-gray-900);
}

.msl-kpi-card.positive .msl-kpi-card__value {
    color: var(--msl-success);
}

.msl-kpi-card.negative .msl-kpi-card__value {
    color: var(--msl-danger);
}

/* Small text under value */
.msl-kpi-card__sub {
    display: block;
    font-size: 13px;
    color: var(--msl-gray-500);
    margin-top: 4px;
}

/* ============================================
   TradingView Chart
   ============================================ */
.msl-widget--tradingview_embed {
    padding: 0;
}

.msl-tradingview-container {
    background: #fff;
}

.msl-tradingview-container h3 {
    padding: 16px 20px;
    margin: 0;
    font-size: 16px;
    font-weight: 600;
    color: var(--msl-gray-800);
    border-bottom: 1px solid var(--msl-gray-200);
}

.msl-tradingview-chart {
    width: 100%;
    height: 400px;
    min-height: 400px;
}

/* ============================================
   Analyst Card
   ============================================ */
.msl-analyst-card {
    padding: 24px;
}

.msl-analyst-card__title {
    font-size: 18px;
    font-weight: 600;
    color: var(--msl-gray-900);
    margin: 0 0 24px;
}

/* Main two-column layout */
.msl-analyst-card__main {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 32px;
    margin-bottom: 32px;
}

/* Price targets table */
.msl-analyst-card__targets-section h4 {
    font-size: 14px;
    font-weight: 600;
    color: var(--msl-gray-600);
    margin: 0 0 16px;
}

.msl-analyst-card__targets-table {
    width: 100%;
    border-collapse: collapse;
}

.msl-analyst-card__targets-table td {
    padding: 12px 0;
    border-bottom: 1px solid var(--msl-gray-100);
    font-size: 14px;
}

.msl-analyst-card__targets-table td:first-child {
    color: var(--msl-gray-600);
}

.msl-analyst-card__targets-table td.value {
    text-align: left;
    font-weight: 600;
    color: var(--msl-gray-800);
    font-size: 16px;
}

.msl-analyst-card__targets-table td.value.highlight {
    color: var(--msl-primary);
    font-size: 18px;
}

/* Score section */
.msl-analyst-card__score-section {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 24px;
    background: var(--msl-gray-50);
    border-radius: 12px;
}

.msl-analyst-card__score-big {
    font-size: 48px;
    font-weight: 700;
    color: var(--msl-primary);
    line-height: 1;
    margin-bottom: 12px;
}

.msl-analyst-card__score-label {
    font-size: 18px;
    font-weight: 600;
    padding: 6px 16px;
    border-radius: 8px;
    margin-bottom: 8px;
}

.msl-analyst-card__score-count {
    font-size: 13px;
    color: var(--msl-gray-500);
}

/* Distribution - Base44 style horizontal bars */
.msl-analyst-card__distribution {
    border-top: 1px solid var(--msl-gray-200);
    padding-top: 24px;
}

.msl-analyst-card__distribution h4,
.msl-analyst-card__distribution-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--msl-gray-800);
    margin: 0 0 16px;
    text-align: right;
}

.msl-analyst-card__dist-row {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 8px;
}

.msl-analyst-card__dist-bar-wrap {
    flex: 1;
    background: var(--msl-gray-100);
    border-radius: 4px;
    height: 28px;
    overflow: hidden;
}

.msl-analyst-card__dist-bar {
    height: 100%;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    padding-right: 10px;
    min-width: fit-content;
    transition: width 0.3s ease;
}

.msl-analyst-card__dist-value {
    font-size: 13px;
    font-weight: 600;
    color: #fff;
    text-shadow: 0 1px 2px rgba(0,0,0,0.2);
}

.msl-analyst-card__dist-label {
    width: 80px;
    font-size: 13px;
    color: var(--msl-gray-600);
    text-align: left;
}

/* Legacy support */
.msl-analyst-card__header {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 24px;
    flex-wrap: wrap;
}

.msl-analyst-card__score {
    font-size: 48px;
    font-weight: 700;
    color: var(--msl-primary);
    line-height: 1;
}

.msl-analyst-card__label {
    font-size: 20px;
    font-weight: 600;
    padding: 4px 12px;
    border-radius: 6px;
}

.msl-analyst-card__count {
    font-size: 14px;
    color: var(--msl-gray-500);
}

/* Price Targets */
.msl-analyst-card__targets {
    border-top: 1px solid var(--msl-gray-200);
    padding-top: 20px;
}

.msl-analyst-card__targets h4 {
    font-size: 14px;
    font-weight: 600;
    color: var(--msl-gray-700);
    margin: 0 0 16px;
}

.msl-analyst-card__targets-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
    text-align: center;
}

.msl-analyst-card__targets-grid .label {
    display: block;
    font-size: 12px;
    color: var(--msl-gray-500);
    margin-bottom: 4px;
}

.msl-analyst-card__targets-grid .value {
    display: block;
    font-size: 18px;
    font-weight: 600;
    color: var(--msl-gray-800);
}

.msl-analyst-card__targets-grid .value.highlight {
    color: var(--msl-primary);
    font-size: 22px;
}

/* ============================================
   Sections
   ============================================ */
.msl-sections {
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.msl-section {
    background: #fff;
    border: 1px solid var(--msl-gray-200);
    border-radius: var(--msl-radius);
    padding: 24px;
}

.msl-section__title {
    font-size: 18px;
    font-weight: 600;
    color: var(--msl-gray-900);
    margin: 0 0 16px;
    padding-bottom: 12px;
    border-bottom: 2px solid var(--msl-primary);
    display: inline-block;
}

.msl-section__content {
    color: var(--msl-gray-700);
    line-height: 1.8;
}

.msl-section__content p {
    margin: 0 0 16px;
}

.msl-section__content p:last-child {
    margin-bottom: 0;
}

.msl-section__content ul {
    margin: 0 0 16px;
    padding-right: 20px;
    list-style-type: disc;
}

.msl-section__content li {
    margin-bottom: 8px;
}

.msl-section__content strong {
    color: var(--msl-gray-900);
}

/* ============================================
   Table Widget - Enhanced Styling
   ============================================ */
.msl-table-container {
    padding: 24px;
}

.msl-table__title {
    font-size: 16px;
    font-weight: 600;
    color: var(--msl-gray-800);
    margin: 0 0 20px;
    display: flex;
    align-items: baseline;
    gap: 8px;
}

.msl-table__title small {
    font-weight: 400;
    font-size: 13px;
    color: var(--msl-gray-500);
}

.msl-table-wrapper {
    overflow-x: auto;
    border-radius: 8px;
    border: 1px solid var(--msl-gray-200);
}

.msl-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

.msl-table th {
    background: linear-gradient(180deg, var(--msl-gray-50) 0%, #fff 100%);
    font-weight: 600;
    font-size: 13px;
    color: var(--msl-gray-600);
    padding: 14px 16px;
    text-align: right;
    border-bottom: 2px solid var(--msl-gray-200);
    white-space: nowrap;
}

.msl-table th:first-child {
    text-align: right;
}

.msl-table td {
    padding: 14px 16px;
    border-bottom: 1px solid var(--msl-gray-100);
    color: var(--msl-gray-700);
    font-variant-numeric: tabular-nums;
}

.msl-table__label {
    font-weight: 600;
    color: var(--msl-gray-800);
}

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

.msl-table tbody tr:hover {
    background: var(--msl-gray-50);
}

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

/* Positive/Negative value styling */
.msl-table td.positive,
.msl-table .value-positive {
    color: var(--msl-success);
    font-weight: 500;
}

.msl-table td.negative,
.msl-table .value-negative {
    color: var(--msl-danger);
    font-weight: 500;
}

/* Highlight rows */
.msl-table tbody tr.highlight td {
    background: rgba(16, 185, 129, 0.05);
}

.msl-table tbody tr.highlight td:first-child {
    border-right: 3px solid var(--msl-primary);
}

/* ============================================
   Notice Widget
   ============================================ */
.msl-notice {
    padding: 16px 20px;
    border-radius: var(--msl-radius-sm);
    font-size: 14px;
    line-height: 1.6;
}

.msl-notice--info {
    background: #eff6ff;
    border: 1px solid #bfdbfe;
    color: #1e40af;
}

.msl-notice--warning {
    background: #fffbeb;
    border: 1px solid #fde68a;
    color: #92400e;
}

.msl-notice--error {
    background: #fef2f2;
    border: 1px solid #fecaca;
    color: #991b1b;
}

.msl-notice--success {
    background: #f0fdf4;
    border: 1px solid #bbf7d0;
    color: #166534;
}

/* ============================================
   Insights Widget
   ============================================ */
.msl-insights {
    padding: 20px;
}

.msl-insights__title {
    font-size: 16px;
    font-weight: 600;
    margin: 0 0 16px;
    color: var(--msl-gray-800);
}

.msl-insight {
    padding: 16px;
    margin-bottom: 12px;
    border-radius: var(--msl-radius-sm);
    background: var(--msl-gray-50);
    border-right: 4px solid var(--msl-gray-300);
}

.msl-insight--high {
    border-right-color: var(--msl-danger);
    background: #fef2f2;
}

.msl-insight--medium {
    border-right-color: var(--msl-warning);
    background: #fffbeb;
}

.msl-insight--low {
    border-right-color: var(--msl-success);
    background: #f0fdf4;
}

.msl-insight__header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
}

.msl-insight__indicator {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: currentColor;
}

.msl-insight--high .msl-insight__indicator { background: var(--msl-danger); }
.msl-insight--medium .msl-insight__indicator { background: var(--msl-warning); }
.msl-insight--low .msl-insight__indicator { background: var(--msl-success); }

.msl-insight__title {
    font-size: 14px;
    font-weight: 600;
    color: var(--msl-gray-800);
}

.msl-insight__why,
.msl-insight__action,
.msl-insight__evidence {
    margin: 8px 0 0;
    font-size: 13px;
    color: var(--msl-gray-600);
}

/* ============================================
   CTA Box Widget
   ============================================ */
.msl-cta-box {
    padding: 24px;
    background: linear-gradient(135deg, var(--msl-primary) 0%, var(--msl-primary-dark) 100%);
    color: #fff;
    text-align: center;
}

.msl-cta-box__message {
    font-size: 16px;
    margin-bottom: 16px;
}

.msl-cta-box__buttons {
    display: flex;
    gap: 12px;
    justify-content: center;
}

.msl-cta-box__btn {
    display: inline-block;
    padding: 12px 24px;
    border-radius: 8px;
    font-weight: 600;
    text-decoration: none;
    transition: var(--msl-transition);
}

.msl-cta-box__btn--primary {
    background: #fff;
    color: var(--msl-primary);
}

.msl-cta-box__btn--secondary {
    background: rgba(255,255,255,0.2);
    color: #fff;
    border: 1px solid rgba(255,255,255,0.4);
}

.msl-cta-box__disclosure {
    margin-top: 16px;
    font-size: 11px;
    opacity: 0.8;
}

/* ============================================
   Disclaimer
   ============================================ */
.msl-disclaimer {
    padding: 20px;
    background: var(--msl-gray-50);
    border-radius: var(--msl-radius);
    border: 1px solid var(--msl-gray-200);
    font-size: 12px;
    color: var(--msl-gray-500);
    line-height: 1.6;
    margin-top: 24px;
}

.msl-disclaimer p {
    margin: 0;
}

/* ============================================
   Responsive
   ============================================ */
@media (max-width: 768px) {
    .msl-kpi-cards {
        grid-template-columns: 1fr;
    }

    .msl-analyst-card__header {
        flex-direction: column;
        text-align: center;
    }

    .msl-analyst-card__targets-grid {
        grid-template-columns: 1fr;
        gap: 12px;
    }

    .msl-section {
        padding: 16px;
    }

    .msl-tradingview-chart {
        height: 300px;
        min-height: 300px;
    }
}
