/*
 * SSTR Design System - Frontend Widgets
 * Theme: Modern Dark (Google Analytics Style)
 * Scoped to .sstr-widget to prevent theme conflicts
 */

/* Base Widget Container - Nuclear Force Dark */
html body .sstr-widget {
    /* Palette */
    --sstr-bg-dark: #141414;
    --sstr-bg-card: #1f1f1f;
    --sstr-bg-hover: #2a2a2a;

    --sstr-border: #333333;
    --sstr-border-light: #444444;

    --sstr-text-primary: #ffffff;
    --sstr-text-secondary: #a0a0a0;
    --sstr-text-muted: #666666;

    --sstr-accent: #3b82f6;
    --sstr-success: #10b981;
    --sstr-warning: #f59e0b;
    --sstr-danger: #ef4444;

    /* Base Widget Container */
    background: var(--sstr-bg-card);
    border: 1px solid var(--sstr-border);
    border-radius: 8px;
    padding: 0;
    /* Header/Body handles padding */
    margin-bottom: 24px;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    color: var(--sstr-text-primary);
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    overflow: hidden;
    line-height: 1.5;
    background-image: none;
    /* Remove theme backgrounds */
}

/* Force Transparency on all parent containers */
html body .sstr-widget-body,
html body .sstr-widget-header {
    background: transparent;
    border-color: var(--sstr-border);
}

/* Nuclear Table Force */
html body .sstr-widget .sstr-widget-table,
html body .sstr-widget .sstr-widget-table thead,
html body .sstr-widget .sstr-widget-table tbody,
html body .sstr-widget .sstr-widget-table tr,
html body .sstr-widget .sstr-widget-table td,
html body .sstr-widget .sstr-widget-table th {
    background: transparent !important;
    background-color: transparent !important;
    border-color: var(--sstr-border-light) !important;
    color: var(--sstr-text-primary) !important;
}

html body .sstr-widget .sstr-widget-table th {
    color: var(--sstr-text-secondary) !important;
    border-bottom: 2px solid var(--sstr-border) !important;
}

html body .sstr-widget .sstr-widget-table td {
    border-bottom: 1px solid var(--sstr-border-light) !important;
}

/* Reset inside widget */
.sstr-widget * {
    box-sizing: border-box;
}

/* Header */
.sstr-widget-header {
    padding: 16px;
    border-bottom: 1px solid var(--sstr-border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: rgba(255, 255, 255, 0.02);
}

.sstr-widget-title {
    margin: 0;
    font-size: 15px;
    font-weight: 600;
    color: var(--sstr-text-primary);
    letter-spacing: 0.3px;
}

/* Controls / Export */
.sstr-btn-export {
    font-size: 11px;
    text-transform: uppercase;
    color: var(--sstr-text-secondary);
    border: 1px solid var(--sstr-border-light);
    padding: 4px 8px;
    border-radius: 4px;
    text-decoration: none;
    transition: all 0.2s;
}

.sstr-btn-export:hover {
    border-color: var(--sstr-accent);
    color: var(--sstr-accent);
}

/* Body */
.sstr-widget-body {
    padding: 16px;
    position: relative;
    min-height: 150px;
    background: var(--sstr-bg-card) !important;
    /* Ensure no background leak */
}

/* Table Style */
.sstr-widget-table,
.sstr-widget-table thead,
.sstr-widget-table tbody,
.sstr-widget-table tr,
.sstr-widget-table td,
.sstr-widget-table th {
    background: transparent !important;
    border-color: var(--sstr-border-light) !important;
    color: var(--sstr-text-primary) !important;
}

.sstr-widget-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
    background: transparent !important;
    border: none !important;
    margin: 0;
}

.sstr-widget-table th {
    text-align: left;
    color: var(--sstr-text-secondary) !important;
    font-weight: 500;
    padding: 12px 8px;
    border-bottom: 2px solid var(--sstr-border) !important;
    background: transparent;
}

.sstr-widget-table td {
    padding: 12px 8px;
    border-bottom: 1px solid var(--sstr-border-light) !important;
    color: var(--sstr-text-primary);
    background: transparent;
}

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

.sstr-num {
    text-align: right;
    font-variant-numeric: tabular-nums;
}

/* Badges */
.sstr-badge {
    padding: 3px 8px;
    border-radius: 12px;
    font-size: 11px;
    background: #333;
    color: #fff;
    font-weight: 500;
}

.sstr-high-eng-badge {
    background: rgba(245, 158, 11, 0.2) !important;
    color: var(--sstr-warning) !important;
    border: 1px solid var(--sstr-warning) !important;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    margin-left: 8px;
    vertical-align: middle;
}

.platform-tiktok {
    color: #ff0050;
    background: rgba(255, 0, 80, 0.1);
}

.platform-instagram {
    color: #e1306c;
    background: rgba(225, 48, 108, 0.1);
}

.platform-youtube {
    color: #ff0000;
    background: rgba(255, 0, 0, 0.1);
}

/* Delta Indicators */
.sstr-delta {
    font-size: 11px;
    font-weight: 600;
}

.sstr-delta.positive {
    color: var(--sstr-success);
}

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

/* Chart Container */
.sstr-chart-container {
    position: relative;
    height: 240px;
    width: 100%;
}

/* Loading */
.sstr-loading {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100%;
    color: var(--sstr-text-muted);
    font-size: 13px;
    font-style: italic;
}

/* --- Insights V2: Graphic & Minimal --- */

/* 1. Stat Grid (Overview) */
.sstr-stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
    gap: 12px;
    padding: 16px;
}

.sstr-stat-card {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--sstr-border-light);
    border-radius: 8px;
    padding: 12px;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    transition: transform 0.2s;
}

.sstr-stat-card:hover {
    transform: translateY(-2px);
    background: rgba(255, 255, 255, 0.05);
}

.sstr-stat-icon {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    margin-bottom: 8px;
}

.sstr-stat-value {
    font-size: 18px;
    font-weight: 700;
    line-height: 1.2;
    color: var(--sstr-text-primary);
}

.sstr-stat-label {
    font-size: 11px;
    color: var(--sstr-text-secondary);
    margin-top: 2px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* 2. Graphic List (Top Posts) */
.sstr-graphic-list {
    padding: 0;
}

.sstr-graphic-item {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    border-bottom: 1px solid var(--sstr-border-light);
    transition: background 0.1s;
}

.sstr-graphic-item:last-child {
    border-bottom: none;
}

.sstr-graphic-item:hover {
    background: rgba(255, 255, 255, 0.02);
}

.sstr-item-rank {
    font-size: 16px;
    margin-right: 12px;
    width: 24px;
    text-align: center;
}

.sstr-item-content {
    flex: 1;
    min-width: 0;
    /* Truncate fix */
    margin-right: 12px;
}

.sstr-item-main {
    font-size: 14px;
    font-weight: 500;
    color: var(--sstr-text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sstr-item-sub {
    font-size: 11px;
    color: var(--sstr-text-muted);
    margin-top: 2px;
}

/* Global Wrapper for Shortcodes */
.sstr-shortcode-wrapper {
    background: transparent;
    color: var(--sstr-text-primary);
    margin-bottom: 20px;
}

.sstr-sc-title {
    font-size: 18px;
    margin-bottom: 12px;
    color: var(--sstr-text-primary);
}

.sstr-sc-table {
    background: var(--sstr-bg-card) !important;
    border-radius: 8px;
    overflow: hidden;
    margin-bottom: 20px;
}

.sstr-metric-val {
    font-size: 13px;
    font-weight: 700;
    color: var(--sstr-accent);
}

.sstr-metric-bar-bg {
    width: 100%;
    height: 4px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 2px;
    margin-top: 4px;
    overflow: hidden;
}

.sstr-metric-bar {
    height: 100%;
    background: var(--sstr-accent);
    border-radius: 2px;
}

/* Responsive */
@media (max-width: 600px) {
    .sstr-widget-table {
        font-size: 12px;
    }

    .sstr-widget-table td,
    .sstr-widget-table th {
        padding: 6px 4px;
    }

    .sstr-chart-container {
        height: 180px;
    }
}

/* --- Author Widgets CSS --- */

/* Slide Panel */
.sstr-slide-panel {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: 400px;
    max-width: 90vw;
    background: #141414;
    box-shadow: -5px 0 20px rgba(0, 0, 0, 0.5);
    transform: translateX(100%);
    transition: transform 0.3s ease;
    z-index: 99999;
    display: flex;
    flex-direction: column;
}

.sstr-slide-panel.open {
    transform: translateX(0);
}

.sstr-panel-content {
    padding: 24px;
    overflow-y: auto;
    flex: 1;
    color: #eee;
}

.sstr-close-btn {
    position: absolute;
    top: 10px;
    right: 10px;
    background: none;
    border: none;
    color: #fff;
    font-size: 24px;
    cursor: pointer;
}

.sstr-panel-header h2 {
    margin: 0 0 8px 0;
    font-size: 24px;
    color: #fff;
}

.sstr-panel-stats {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 12px;
    margin: 24px 0;
    padding-bottom: 24px;
    border-bottom: 1px solid #333;
}

.sstr-stat-box label {
    display: block;
    font-size: 11px;
    color: #888;
    text-transform: uppercase;
}

.sstr-stat-box value {
    display: block;
    font-size: 18px;
    font-weight: bold;
}

.sstr-recent-posts {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.sstr-post-item {
    background: #1f1f1f;
    padding: 12px;
    border-radius: 8px;
    border: 1px solid #333;
    font-size: 13px;
}

.sstr-post-date {
    color: #666;
    font-size: 11px;
    margin-bottom: 4px;
}

.sstr-post-metrics {
    display: flex;
    gap: 12px;
    margin-top: 8px;
    color: #a0a0a0;
    font-size: 12px;
}

/* Buttons */
.sstr-btn {
    background: transparent;
    border: 1px solid #444;
    color: #ccc;
    padding: 6px 12px;
    border-radius: 4px;
    cursor: pointer;
    transition: 0.2s;
    font-size: 13px;
}

.sstr-btn:hover {
    background: #333;
    color: #fff;
    border-color: #666;
}