/* ============================================================
   AI Visibility Matrix — ai-visibility-matrix.css
   Version: 1.2.0
   Fixes: rotated headers, forced dark mode, insights contrast,
          legend transition, review date legibility
   ============================================================ */

/* ── Force dark variables always — theme is dark-mode default.
      Do NOT rely on prefers-color-scheme for this plugin.     ── */
.aivm-wrap {
    --aivm-bg:            #0d0d0f;
    --aivm-surface:       #181820;
    --aivm-surface-2:     #1e1e28;
    --aivm-surface-3:     #22222e;
    --aivm-border:        rgba(255,255,255,0.08);
    --aivm-border-2:      rgba(255,255,255,0.14);

    --aivm-text:          #e8e8f0;
    --aivm-text-muted:    #9090a8;
    --aivm-text-dim:      #55556a;

    --aivm-high-bg:       rgba(34, 197, 94, 0.13);
    --aivm-high-text:     #4ade80;
    --aivm-high-border:   rgba(34, 197, 94, 0.28);

    --aivm-medium-bg:     rgba(234, 179, 8, 0.11);
    --aivm-medium-text:   #fbbf24;
    --aivm-medium-border: rgba(234, 179, 8, 0.28);

    --aivm-low-bg:        rgba(239, 68, 68, 0.10);
    --aivm-low-text:      #f87171;
    --aivm-low-border:    rgba(239, 68, 68, 0.25);

    --aivm-accent:        #7c6aff;
    --aivm-accent-2:      #b8a8ff;
    --aivm-accent-glow:   rgba(124, 106, 255, 0.15);

    --aivm-radius:        6px;
    --aivm-radius-lg:     12px;
    --aivm-font-mono:     'JetBrains Mono', 'Fira Code', 'Courier New', monospace;
    --aivm-transition:    0.18s ease;

    width: 100%;
    font-family: inherit;
    color: var(--aivm-text);
    margin: 2.5rem 0 3rem;
    background: transparent;
}

/* ── Filter controls ────────────────────────────────────────── */

.aivm-controls {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 1.25rem;
}

.aivm-filter {
    background: var(--aivm-surface);
    border: 1px solid var(--aivm-border-2);
    color: var(--aivm-text-muted);
    padding: 0.4rem 1rem;
    border-radius: 2rem;
    font-size: 0.8rem;
    font-family: var(--aivm-font-mono);
    letter-spacing: 0.02em;
    cursor: pointer;
    transition: all var(--aivm-transition);
}

.aivm-filter:hover {
    border-color: var(--aivm-accent);
    color: var(--aivm-accent-2);
}

.aivm-filter.active {
    background: var(--aivm-accent);
    border-color: var(--aivm-accent);
    color: #fff;
    font-weight: 600;
}

/* ── Table wrapper ───────────────────────────────────────────── */

.aivm-table-wrap {
    width: 100%;
    overflow-x: auto;
    border: 1px solid var(--aivm-border);
    border-radius: var(--aivm-radius-lg);
    background: var(--aivm-surface);
    -webkit-overflow-scrolling: touch;
}

/* ── Table ───────────────────────────────────────────────────── */

.aivm-table {
    width: 100%;
    border-collapse: collapse;
    min-width: 760px;
    /* Auto layout: let header height drive column width */
    table-layout: auto;
}

/* ── FIX 1: Rotated column headers ──────────────────────────── */

.aivm-table thead {
    background: var(--aivm-surface-2);
    border-bottom: 1px solid var(--aivm-border-2);
}

.aivm-table thead th {
    padding: 0;
    text-align: center;
    border-right: 1px solid var(--aivm-border);
    vertical-align: bottom;
    /* Fixed width for data columns — platform name col is wider */
    width: 90px;
}

.aivm-table thead th:last-child {
    border-right: none;
}

/* Platform name column — wider, left-aligned, no rotation */
.aivm-th-platform {
    width: 160px !important;
    min-width: 140px;
    text-align: left !important;
    padding: 0.85rem 1rem !important;
    font-size: 0.7rem;
    font-family: var(--aivm-font-mono);
    font-weight: 600;
    letter-spacing: 0.06em;
    color: var(--aivm-text-muted);
    text-transform: uppercase;
    vertical-align: middle !important;
}

/* Rotated label wrapper — creates the angled header */
.aivm-criterion-label {
    display: block;
    /* Rotate container upward */
    writing-mode: vertical-rl;
    text-orientation: mixed;
    transform: rotate(180deg);
    /* Readable sizing */
    font-size: 0.68rem;
    font-family: var(--aivm-font-mono);
    font-weight: 600;
    letter-spacing: 0.04em;
    color: var(--aivm-text-muted);
    text-transform: uppercase;
    white-space: nowrap;
    /* Padding creates the column height */
    padding: 0.9rem 0.6rem 0.7rem;
    line-height: 1;
}

/* ── Rows ────────────────────────────────────────────────────── */

.aivm-row {
    border-bottom: 1px solid var(--aivm-border);
    transition: background var(--aivm-transition);
}

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

.aivm-row:hover {
    background: rgba(255,255,255,0.02);
}

.aivm-row.aivm-hidden {
    display: none;
}

/* ── Platform name cell ──────────────────────────────────────── */

.aivm-platform-name {
    padding: 0.85rem 1rem;
    border-right: 1px solid var(--aivm-border-2);
    vertical-align: middle;
}

.aivm-platform-label {
    display: block;
    font-size: 0.88rem;
    font-weight: 700;
    color: var(--aivm-text);
    margin-bottom: 0.3rem;
    white-space: nowrap;
}

/* ── Category badges ─────────────────────────────────────────── */

.aivm-category-badge {
    display: inline-block;
    font-size: 0.64rem;
    font-family: var(--aivm-font-mono);
    letter-spacing: 0.03em;
    padding: 0.15rem 0.5rem;
    border-radius: 2rem;
    font-weight: 500;
}

.aivm-cat-live-index {
    background: rgba(99, 179, 237, 0.13);
    color: #63b3ed;
    border: 1px solid rgba(99, 179, 237, 0.22);
}

.aivm-cat-hybrid {
    background: rgba(167, 139, 250, 0.13);
    color: #c4b5fd;
    border: 1px solid rgba(167, 139, 250, 0.22);
}

.aivm-cat-training-based {
    background: rgba(251, 146, 60, 0.11);
    color: #fb923c;
    border: 1px solid rgba(251, 146, 60, 0.22);
}

/* ── Score cells ─────────────────────────────────────────────── */

.aivm-cell {
    padding: 0.45rem 0.35rem;
    text-align: center;
    border-right: 1px solid var(--aivm-border);
    vertical-align: middle;
    position: relative;
}

.aivm-cell:last-child {
    border-right: none;
}

.aivm-score-btn {
    background: none;
    border: none;
    cursor: pointer;
    width: 100%;
    padding: 0.3rem 0.4rem;
    border-radius: var(--aivm-radius);
    transition: all var(--aivm-transition);
    display: flex;
    align-items: center;
    justify-content: center;
}

.aivm-score-label {
    font-family: var(--aivm-font-mono);
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

/* Score colours */
.aivm-high   .aivm-score-btn { background: var(--aivm-high-bg);   border: 1px solid var(--aivm-high-border); }
.aivm-medium .aivm-score-btn { background: var(--aivm-medium-bg); border: 1px solid var(--aivm-medium-border); }
.aivm-low    .aivm-score-btn { background: var(--aivm-low-bg);    border: 1px solid var(--aivm-low-border); }

.aivm-high   .aivm-score-label { color: var(--aivm-high-text); }
.aivm-medium .aivm-score-label { color: var(--aivm-medium-text); }
.aivm-low    .aivm-score-label { color: var(--aivm-low-text); }

.aivm-score-btn:hover,
.aivm-score-btn[aria-expanded="true"] {
    transform: scale(1.06);
    box-shadow: 0 0 0 2px var(--aivm-accent);
    outline: none;
}

/* ── Tooltip ─────────────────────────────────────────────────── */

.aivm-tooltip {
    display: none;
    position: absolute;
    z-index: 100;
    width: 270px;
    background: #1a1a28;
    border: 1px solid var(--aivm-border-2);
    border-radius: var(--aivm-radius-lg);
    padding: 1rem 1.1rem;
    box-shadow: 0 8px 32px rgba(0,0,0,0.6), 0 0 0 1px rgba(124,106,255,0.12);
    text-align: left;
    top: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%);
    pointer-events: none;
}

.aivm-tooltip.aivm-tooltip-above {
    top: auto;
    bottom: calc(100% + 8px);
}

/* Arrow */
.aivm-tooltip::before {
    content: '';
    position: absolute;
    top: -6px;
    left: 50%;
    transform: translateX(-50%);
    width: 10px;
    height: 10px;
    background: #1a1a28;
    border-left: 1px solid var(--aivm-border-2);
    border-top: 1px solid var(--aivm-border-2);
    rotate: 45deg;
}

.aivm-tooltip.aivm-tooltip-above::before {
    top: auto;
    bottom: -6px;
    border-left: none;
    border-top: none;
    border-right: 1px solid var(--aivm-border-2);
    border-bottom: 1px solid var(--aivm-border-2);
}

.aivm-tooltip strong {
    display: block;
    font-size: 0.72rem;
    font-family: var(--aivm-font-mono);
    color: var(--aivm-accent-2);
    letter-spacing: 0.03em;
    margin-bottom: 0.45rem;
    text-transform: uppercase;
}

.aivm-tooltip p {
    margin: 0;
    font-size: 0.8rem;
    line-height: 1.65;
    color: var(--aivm-text);
}

.aivm-tooltip.is-visible {
    display: block;
    animation: aivm-tooltip-in 0.14s ease;
}

@keyframes aivm-tooltip-in {
    from { opacity: 0; transform: translateX(-50%) translateY(4px); }
    to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ── Legend ──────────────────────────────────────────────────── */

.aivm-legend {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 1.25rem;
    margin-top: 1rem;
    padding: 0 0.25rem;
}

.aivm-legend-item {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.78rem;
    color: var(--aivm-text-muted);
    font-family: var(--aivm-font-mono);
}

.aivm-legend-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}

.aivm-legend-dot.aivm-high   { background: var(--aivm-high-text); }
.aivm-legend-dot.aivm-medium { background: var(--aivm-medium-text); }
.aivm-legend-dot.aivm-low    { background: var(--aivm-low-text); }

.aivm-legend-hint {
    margin-left: auto;
    font-size: 0.72rem;
    color: var(--aivm-text-dim);
    font-family: var(--aivm-font-mono);
    font-style: italic;
}

/* ── FIX 2 & 3: Insights block — dark background, full contrast ── */

.aivm-insights {
    margin-top: 2.5rem;
    padding: 1.75rem 2rem;
    /* Explicit dark background — never inherits page light mode */
    background: var(--aivm-surface) !important;
    color: var(--aivm-text) !important;
    border: 1px solid var(--aivm-border);
    border-left: 3px solid var(--aivm-accent);
    border-radius: var(--aivm-radius-lg);
}

.aivm-insights-title {
    font-size: 0.7rem;
    font-family: var(--aivm-font-mono);
    font-weight: 700;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    /* FIX 3: Strong accent colour, not muted */
    color: var(--aivm-accent-2) !important;
    margin: 0 0 1.5rem;
}

.aivm-insights-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.75rem;
}

.aivm-insight {
    display: flex;
    gap: 0.85rem;
    align-items: flex-start;
}

.aivm-insight-icon {
    font-size: 1.15rem;
    /* FIX 3: Full accent colour, not faded */
    color: var(--aivm-accent) !important;
    flex-shrink: 0;
    line-height: 1.5;
    margin-top: 0.05rem;
    opacity: 1;
}

.aivm-insight strong {
    display: block;
    font-size: 0.9rem;
    font-weight: 700;
    /* FIX 3: Full text colour — white, not muted */
    color: var(--aivm-text) !important;
    margin-bottom: 0.4rem;
}

.aivm-insight p {
    margin: 0;
    font-size: 0.83rem;
    line-height: 1.7;
    /* FIX 3: Readable muted — not near-invisible */
    color: var(--aivm-text-muted) !important;
}

/* ── FIX 4: Review date — legible on dark background ────────── */

.aivm-review-date {
    margin-top: 1.25rem;
    font-size: 0.72rem;
    font-family: var(--aivm-font-mono);
    /* Bumped from --aivm-text-dim to --aivm-text-muted for legibility */
    color: var(--aivm-text-muted);
    text-align: right;
    /* Ensure it sits on the dark page, not bleeding from insights */
    background: transparent;
}

/* ── Mobile card view ────────────────────────────────────────── */

@media ( max-width: 768px ) {
    .aivm-table-wrap {
        display: none;
    }
    .aivm-mobile-cards {
        display: block;
    }
    .aivm-insights-grid {
        grid-template-columns: 1fr;
    }
    .aivm-legend-hint {
        display: none;
    }
    .aivm-insights {
        padding: 1.25rem;
    }
}

@media ( min-width: 769px ) {
    .aivm-mobile-cards {
        display: none;
    }
}

/* ── Mobile cards ────────────────────────────────────────────── */

.aivm-mobile-cards {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.aivm-card {
    background: var(--aivm-surface);
    border: 1px solid var(--aivm-border);
    border-radius: var(--aivm-radius-lg);
    overflow: hidden;
}

.aivm-card.aivm-card-hidden {
    display: none;
}

.aivm-card-header {
    padding: 0.9rem 1.1rem;
    background: var(--aivm-surface-2);
    border-bottom: 1px solid var(--aivm-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.aivm-card-platform {
    font-size: 0.92rem;
    font-weight: 700;
    color: var(--aivm-text);
}

.aivm-card-rows {
    padding: 0.25rem 0;
}

.aivm-card-row {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    padding: 0.7rem 1.1rem;
    border-bottom: 1px solid var(--aivm-border);
}

.aivm-card-row:last-child {
    border-bottom: none;
}

.aivm-card-criterion {
    flex: 1;
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--aivm-text);
    line-height: 1.4;
}

.aivm-card-score {
    font-family: var(--aivm-font-mono);
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    padding: 0.2rem 0.6rem;
    border-radius: var(--aivm-radius);
    flex-shrink: 0;
    margin-top: 0.1rem;
}

.aivm-card-score.aivm-high   { background: var(--aivm-high-bg);   color: var(--aivm-high-text);   border: 1px solid var(--aivm-high-border); }
.aivm-card-score.aivm-medium { background: var(--aivm-medium-bg); color: var(--aivm-medium-text); border: 1px solid var(--aivm-medium-border); }
.aivm-card-score.aivm-low    { background: var(--aivm-low-bg);    color: var(--aivm-low-text);    border: 1px solid var(--aivm-low-border); }

.aivm-card-note {
    font-size: 0.76rem;
    color: var(--aivm-text-muted);
    line-height: 1.55;
    margin-top: 0.3rem;
    font-weight: 400;
}
