/* MODAL v.1.0.5 */

.modal-backdrop {
    z-index: 2000;
}

.modal-dialog {
    z-index: 2001;
    margin-top: 1%;
}

.modal-title {
    width: 90%;
    white-space: nowrap;
    overflow: hidden;
    -ms-text-overflow: ellipsis;
    text-overflow: ellipsis;
}

.modal-body img {
    background-color: #ddd;
    width: 100% !important;
    height: auto !important;
}

.modal-body .modal-description {
    margin: 15px 0 0;
}

.modal-body .modal-description p {
    width: 90%;
    -ms-word-wrap: break-word;
    word-wrap: break-word;
    white-space: normal;
}

.modal a:hover {
    text-decoration: none !important;
}

body > svg,
.modal .modal-img-svg {
    position: absolute;
    left: -800px;
    top: -800px;
    z-index: -99999;
}

@media (max-width: 1024px) {
    .modal-dialog {
        margin-top: 15%;
    }
}

@media (max-width: 800px) {
    .modal-dialog {
        margin-top: 25%;
    }
}

@media (min-width: 100px) and (max-width: 480px) {
    .modal-dialog {
        margin-top: 30%;
    }
    .modal-content {
        margin: 15px;
    }
}

/* Insights modal: nearly full viewport with 50px margin on all sides */

/* Web: two columns 50% each – chart left, insights right with vertical scroll */
@media (min-width: 768px) {
    .modal.insights-modal-full .modal-body {
        flex-direction: row;
    }
    .modal.insights-modal-full .modal-body .insights-viz-panel {
        flex: 0 0 50%;
        width: 50%;
        min-width: 0;
        border-right: 1px solid #ddd;
        border-bottom: none;
    }
    .modal.insights-modal-full .modal-body .insights-response-panel {
        flex: 0 0 50%;
        width: 50%;
        min-width: 0;
        display: flex;
        flex-direction: column;
        overflow: hidden;
        border-top: none;
    }
    .modal.insights-modal-full .modal-body .insights-response-header {
        flex-shrink: 0;
    }
    .modal.insights-modal-full .modal-body .insights-response-content {
        flex: 1;
        min-height: 0;
        overflow-y: auto;
    }
}

/* Mobile: stacked 50% height each – chart top, insights bottom */
@media (max-width: 767px) {
    .modal.insights-modal-full .modal-body {
        flex-direction: column;
    }
    .modal.insights-modal-full .modal-body .insights-viz-panel {
        flex: 0 0 50%;
        min-height: 200px;
        border-bottom: 1px solid #ddd;
        border-right: none;
    }
    .modal.insights-modal-full .modal-body .insights-response-panel {
        flex: 1;
        min-height: 200px;
        display: flex;
        flex-direction: column;
        overflow: hidden;
        border-top: 1px solid #eee;
    }
    .modal.insights-modal-full .modal-body .insights-response-header {
        flex-shrink: 0;
    }
    .modal.insights-modal-full .modal-body .insights-response-content {
        flex: 1;
        min-height: 0;
        overflow-y: auto;
    }
}

.modal.insights-modal-full .modal-dialog {
    margin: 50px;
    width: calc(100vw - 100px);
    max-width: none;
    height: calc(100vh - 70px);
}
.modal.insights-modal-full .modal-content {
    height: 100%;
    display: flex;
    flex-direction: column;
}
.modal.insights-modal-full .modal-body {
    flex: 1;
    min-height: 0;
    display: flex;
    overflow: hidden;
}
.modal.insights-modal-full .modal-body .insights-viz-panel,
.modal.insights-modal-full .modal-body .insights-response-panel {
    min-height: 0;
    overflow: hidden;
}
.modal.insights-modal-full .modal-footer {
    flex-shrink: 0;
}

.insights-response-header {
    padding: 8px 10px;
    font-weight: 600;
    background: #f5f5f5;
    border-bottom: 1px solid #eee;
}
.insights-viz-container {
    margin: 10px;
    height: 100%;
}

.insights-markdown-content h1,
.insights-markdown-content h2,
.insights-markdown-content h3 {
    margin: 1em 0 0.5em;
    font-weight: 600;
}
.insights-markdown-content h1 { font-size: 1.50rem; }
.insights-markdown-content h2 { font-size: 1.25rem; }
.insights-markdown-content h3 { font-size: 1.10rem; }
.insights-markdown-content p { margin: 0.5em 0; font-size: 1.25rem; line-height: 2;}
.insights-markdown-content ul,
.insights-markdown-content ol { margin: 0.5em 0; padding-left: 1.8em; }
.insights-markdown-content ul { list-style-type: disc; }
.insights-markdown-content ol { list-style-type: decimal; }
.insights-markdown-content li {
    margin: 0.3em 0;
    font-size: 1.25rem;
    line-height: 1.7;
}
.insights-markdown-content ul ul,
.insights-markdown-content ol ul { list-style-type: circle; }
.insights-markdown-content ul ul ul,
.insights-markdown-content ol ul ul { list-style-type: square; }
.insights-markdown-content ul ol,
.insights-markdown-content ol ol { list-style-type: lower-alpha; }
.insights-markdown-content code {
    background: #f4f4f4;
    padding: 2px 5px;
    border-radius: 3px;
    font-size: 0.9em;
}
.insights-markdown-content pre {
    background: #f4f4f4;
    padding: 12px;
    border-radius: 4px;
    overflow-x: auto;
    margin: 0.5em 0;
}
.insights-markdown-content pre code {
    background: none;
    padding: 0;
    border-radius: 0;
    font-size: 0.9em;
}
.insights-markdown-content blockquote {
    border-left: 3px solid #ddd;
    padding-left: 12px;
    color: #666;
    margin: 0.5em 0;
}
.insights-markdown-content table {
    border-collapse: collapse;
    width: 100%;
    margin: 0.5em 0;
}
.insights-markdown-content th,
.insights-markdown-content td {
    border: 1px solid #ddd;
    padding: 6px 10px;
    text-align: left;
}
.insights-markdown-content th {
    background: #f5f5f5;
    font-weight: 600;
}
.insights-markdown-content hr {
    border: none;
    border-top: 1px solid #ddd;
    margin: 1em 0;
}
.insights-markdown-content a {
    color: #337ab7;
    text-decoration: underline;
}
.insights-markdown-content del {
    text-decoration: line-through;
    color: #999;
}

/* ═════════════════════════════════════════════════════════════════
   STRUCTURED INSIGHTS v.2.0.0 — Figma fidelity
   Components rendered from LLM JSON response (cards, grids, tables, etc.)
   ═════════════════════════════════════════════════════════════════ */

/* ── Structured content wrapper ────────────────────────────────── */
.si-structured-content {
    padding: 0;
}

/* ── Section wrapper ───────────────────────────────────────────── */
.si-section {
    margin-bottom: 0;
    padding: 0 16px;
}
.si-section__title {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: #888;
    margin: 0 0 8px;
    padding: 0;
}

/* ── Header bar ────────────────────────────────────────────────── */
.si-header {
    padding: 14px 16px 12px;
    border-bottom: 1px solid #e5e7eb;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 10px;
}
.si-header__text {
    flex: 1;
    min-width: 0;
}
.si-header__title {
    font-size: 16px;
    font-weight: 600;
    color: #1a1a1a;
    margin: 0;
    line-height: 1.3;
}
.si-header__subtitle {
    font-size: 12px;
    color: #888;
    margin: 3px 0 0;
    line-height: 1.3;
}
.si-header__badge {
    display: inline-block;
    font-size: 11px;
    font-weight: 600;
    border-radius: 12px;
    padding: 3px 10px;
    white-space: nowrap;
    flex-shrink: 0;
    margin-top: 2px;
    line-height: 1.3;
}
.si-header__badge--positive { background: #f0fdf4; color: #16a34a; }
.si-header__badge--negative { background: #fef2f2; color: #dc2626; }
.si-header__badge--neutral  { background: #f3f4f6; color: #666; }
.si-header__badge--mixed    { background: #fefce8; color: #a16207; }

/* ── Section divider ───────────────────────────────────────────── */
.si-divider {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: #888;
    border-bottom: 1px solid #e5e7eb;
    padding: 10px 0 5px;
    margin: 6px 0 10px;
}

/* ── Cards (1-2 headline values) ───────────────────────────────── */
.si-cards {
    display: flex;
    gap: 10px;
    margin-bottom: 10px;
}
.si-card {
    flex: 1;
    border-radius: 6px;
    padding: 12px 14px;
    border: 1px solid #e5e7eb;
    background: #fff;
    min-width: 0;
}
.si-card--positive { border-color: #dcfce7; background: #f9fefb; }
.si-card--negative { border-color: #fee2e2; background: #fffbfb; }
.si-card--neutral  { border-color: #e5e7eb; background: #fff; }

.si-card__label {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    color: #888;
    margin: 0 0 4px;
    line-height: 1.3;
}
.si-card__value {
    font-size: 24px;
    font-weight: 700;
    color: #1a1a1a;
    margin: 0 0 2px;
    line-height: 1.15;
    word-break: break-word;
}
.si-card--positive .si-card__value { color: #15803d; }
.si-card--negative .si-card__value { color: #dc2626; }

.si-card__sub-value {
    font-size: 12px;
    font-weight: 600;
    margin: 1px 0 2px;
    line-height: 1.3;
    color: #666;
}
.si-card__sub-value--positive { color: #16a34a; }
.si-card__sub-value--negative { color: #dc2626; }

.si-card__entity {
    font-size: 12px;
    color: #888;
    margin: 0;
    line-height: 1.3;
}

/* ── Stat grid (2-6 summary metrics) ──────────────────────────── */
.si-stat-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
    margin-bottom: 10px;
}
.si-stat-grid--cols-3 {
    grid-template-columns: repeat(3, 1fr);
}
.si-stat-cell {
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    padding: 10px 12px;
    border-left: 3px solid #ccc;
    background: #fff;
}
.si-stat-cell--positive { border-left-color: #22c55e; }
.si-stat-cell--negative { border-left-color: #ef4444; }
.si-stat-cell--neutral  { border-left-color: #3b82f6; }

.si-stat-cell__label {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    color: #888;
    margin: 0 0 3px;
    line-height: 1.3;
}
.si-stat-cell__value {
    font-size: 18px;
    font-weight: 700;
    color: #1a1a1a;
    margin: 0;
    line-height: 1.2;
    word-break: break-word;
}
.si-stat-cell__entity {
    font-size: 11px;
    color: #888;
    margin: 2px 0 0;
    line-height: 1.3;
}

/* ── Key-value list ────────────────────────────────────────────── */
.si-kvl {
    border-left: 3px solid #ccc;
    padding: 8px 12px;
    margin-bottom: 8px;
}
.si-kvl--positive { border-left-color: #22c55e; }
.si-kvl--negative { border-left-color: #ef4444; }
.si-kvl--neutral  { border-left-color: #3b82f6; }

.si-kvl__title {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    color: #888;
    margin: 0 0 4px;
    line-height: 1.3;
}
.si-kvl__row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    padding: 2px 0;
    gap: 12px;
}
.si-kvl__key {
    font-size: 13px;
    color: #555;
    flex-shrink: 0;
}
.si-kvl__val {
    font-size: 13px;
    font-weight: 600;
    color: #1a1a1a;
    text-align: right;
}
.si-kvl__val--positive { color: #16a34a; }
.si-kvl__val--negative { color: #dc2626; }

/* ── Ranking list ──────────────────────────────────────────────── */
.si-ranking {
    margin-bottom: 4px;
}
.si-ranking__header {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    color: #888;
    display: flex;
    justify-content: space-between;
    padding: 0 4px 6px;
    border-bottom: 1px solid #e5e7eb;
    margin-bottom: 4px;
}
.si-ranking__row {
    display: flex;
    align-items: center;
    padding: 6px 4px;
    border-bottom: 1px solid #f3f4f6;
}
.si-ranking__row:last-child {
    border-bottom: none;
}
.si-ranking__rank {
    width: 20px;
    font-size: 12px;
    font-weight: 700;
    color: #999;
    text-align: left;
    flex-shrink: 0;
}
.si-ranking__name {
    flex: 1;
    font-size: 13px;
    font-weight: 600;
    color: #1a1a1a;
    padding: 0 10px 0 4px;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.si-ranking__bar-wrap {
    flex: 0 0 140px;
    height: 8px;
    background: #f3f4f6;
    border-radius: 4px;
    overflow: hidden;
    margin-right: 10px;
}
.si-ranking__bar {
    height: 100%;
    border-radius: 4px;
    background: #3b82f6;
    transition: width 0.3s ease;
}
.si-ranking__value {
    width: 64px;
    font-size: 13px;
    font-weight: 600;
    color: #1a1a1a;
    text-align: right;
    flex-shrink: 0;
}

/* ── Table ─────────────────────────────────────────────────────── */
.si-table-wrap {
    overflow-x: auto;
    margin-bottom: 0;
    border-top: 1px solid #e5e7eb;
}
.si-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}
.si-table thead th {
    position: sticky;
    top: 0;
    z-index: 2;
    background: #f5f5f5;
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    color: #666;
    padding: 8px 10px;
    text-align: left;
    border-bottom: 1px solid #e5e7eb;
    white-space: nowrap;
}
.si-table tbody td {
    padding: 7px 10px;
    border-bottom: 1px solid #f3f4f6;
    color: #333;
    vertical-align: middle;
}
.si-table tbody tr:last-child td {
    border-bottom: none;
}
.si-table__row--highest {
    background: #f0fdf4;
}
.si-table__row--highest td:nth-child(2) {
    font-weight: 700;
}
.si-table__row--lowest {
    background: #fef2f2;
}
.si-table__row--benchmark {
    background: #eff6ff;
}

.si-val--up   { color: #16a34a; }
.si-val--down { color: #dc2626; }

/* ── Color dot (chart series indicator) ────────────────────────── */
.si-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-right: 6px;
    vertical-align: middle;
    flex-shrink: 0;
}

/* ── Trend arrows ──────────────────────────────────────────────── */
.si-arrow {
    display: inline-block;
    font-size: 14px;
    line-height: 1;
    vertical-align: middle;
}
.si-arrow--up   { color: #16a34a; }
.si-arrow--down { color: #dc2626; }
.si-arrow--right { color: #a16207; }

/* ── Table footer ──────────────────────────────────────────────── */
.si-table__footer {
    font-size: 10px;
    color: #999;
    font-style: italic;
    padding: 6px 10px;
    border-top: 1px solid #e5e7eb;
    background: #fafafa;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.si-table__footer-text {
    flex: 1;
}
.si-table__legend {
    display: flex;
    gap: 12px;
    align-items: center;
    font-style: normal;
}
.si-table__legend-item {
    display: flex;
    align-items: center;
    gap: 4px;
}
.si-table__legend-box {
    display: inline-block;
    width: 12px;
    height: 12px;
    border-radius: 2px;
    flex-shrink: 0;
}
.si-table__legend-box--highest { background: #dcfce7; }
.si-table__legend-box--lowest  { background: #fee2e2; }

/* ── Narrative ─────────────────────────────────────────────────── */
.si-narrative {
    font-size: 14px;
    line-height: 1.65;
    color: #333;
    padding: 6px 0 8px;
}
.si-narrative p   { margin: 0.4em 0; }
.si-narrative ul,
.si-narrative ol  { margin: 0.4em 0; padding-left: 1.6em; }
.si-narrative li  { margin: 0.2em 0; }
.si-narrative strong { color: #1a1a1a; }

/* ── Analyzing loader ──────────────────────────────────────────── */
.si-loader {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 48px 24px 36px;
    gap: 16px;
}

.si-loader__icon {
    display: flex;
    align-items: flex-end;
    gap: 3px;
    height: 28px;
}
.si-loader__bar {
    display: block;
    width: 4px;
    border-radius: 2px;
    background: #6366f1;
    animation: siBarPulse 1.2s ease-in-out infinite;
}
.si-loader__bar:nth-child(1) { height: 10px; animation-delay: 0s; }
.si-loader__bar:nth-child(2) { height: 20px; animation-delay: 0.15s; }
.si-loader__bar:nth-child(3) { height: 14px; animation-delay: 0.3s; }
.si-loader__bar:nth-child(4) { height: 24px; animation-delay: 0.45s; }

@keyframes siBarPulse {
    0%, 100% { transform: scaleY(0.4); opacity: 0.4; }
    50%      { transform: scaleY(1); opacity: 1; }
}

.si-loader__label {
    font-size: 14px;
    font-weight: 500;
    color: #555;
    letter-spacing: 0.2px;
}
.si-loader__dots span {
    animation: siDotFade 1.4s ease-in-out infinite;
    opacity: 0;
}
.si-loader__dots span:nth-child(1) { animation-delay: 0s; }
.si-loader__dots span:nth-child(2) { animation-delay: 0.2s; }
.si-loader__dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes siDotFade {
    0%, 80%, 100% { opacity: 0; }
    40% { opacity: 1; }
}

.si-loader__skeleton {
    width: 100%;
    max-width: 320px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 8px;
}
.si-loader__shimmer {
    height: 10px;
    border-radius: 5px;
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: siShimmer 1.5s ease-in-out infinite;
}
.si-loader__shimmer--wide   { width: 100%; }
.si-loader__shimmer--medium { width: 75%; }
.si-loader__shimmer--narrow { width: 50%; }

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

/* ── Structured insights responsive ───────────────────────────── */
@media (max-width: 480px) {
    .si-cards {
        flex-direction: column;
    }
    .si-stat-grid {
        grid-template-columns: 1fr;
    }
    .si-stat-grid--cols-3 {
        grid-template-columns: 1fr;
    }
    .si-ranking__bar-wrap {
        flex-basis: 60px;
    }
    .si-card__value {
        font-size: 18px;
    }
    .si-header {
        flex-direction: column;
    }
}
