/**
 * TSM Frontend Styles
 * CRITICAL: ALWAYS LOADED - Never conditional!
 * Uses CSS variables for dynamic theming
 */

/* ========================================
   CSS Variables (Set by PHP)
   ======================================== */
:root {
    --tsm-primary: #667eea;
    --tsm-accent: #764ba2;
    --tsm-text: #1a202c;
}

/* ========================================
   FLOATING WIDGET (Always Display)
   ======================================== */

#tsm-floating-widget {
    position: fixed;
    z-index: 999999;
    display: flex;
    flex-direction: column;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    bottom: 30px;
}

/* Position Variants */
.tsm-position-right {
    right: 30px;
}

.tsm-position-left {
    left: 30px;
}

.tsm-position-center {
    left: 50%;
    transform: translateX(-50%);
}

/* Collapsed Trigger (Capsule) */
.tsm-widget-trigger {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 20px;
    background: linear-gradient(135deg, var(--tsm-primary), var(--tsm-accent));
    color: white;
    border-radius: 50px;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    transition: transform 0.2s, box-shadow 0.2s;
    position: relative;
}

.tsm-widget-trigger:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.2);
}

.tsm-icon {
    font-size: 20px;
}

.tsm-trigger-text {
    font-weight: 600;
    font-size: 14px;
    white-space: nowrap;
}

/* Breathing Dot Animation */
.tsm-breathing-dot {
    width: 8px;
    height: 8px;
    background: rgba(255, 255, 255, 0.9);
    border-radius: 50%;
    animation: tsm-breathing 2s ease-in-out infinite;
}

@keyframes tsm-breathing {

    0%,
    100% {
        opacity: 1;
        transform: scale(1);
    }

    50% {
        opacity: 0.4;
        transform: scale(0.8);
    }
}

/* Expanded Panel (Popover) */
.tsm-widget-panel {
    display: none;
    position: absolute;
    bottom: 100%;
    right: 0;
    margin-bottom: 15px;
    width: 380px;
    max-height: 500px;
    background: white;
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
    overflow: hidden;
}

.tsm-position-left .tsm-widget-panel {
    right: auto;
    left: 0;
}

.tsm-position-center .tsm-widget-panel {
    right: auto;
    left: 50%;
    transform: translateX(-50%);
}

#tsm-floating-widget.tsm-widget-expanded .tsm-widget-panel {
    display: flex;
    flex-direction: column;
    animation: tsm-panel-slide-up 0.3s ease-out;
}

@keyframes tsm-panel-slide-up {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.tsm-panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    background: linear-gradient(135deg, var(--tsm-primary), var(--tsm-accent));
    color: white;
}

.tsm-panel-header h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
}

.tsm-panel-close {
    background: none;
    border: none;
    color: white;
    font-size: 24px;
    line-height: 1;
    cursor: pointer;
    padding: 0;
    width: 24px;
    height: 24px;
    opacity: 0.8;
    transition: opacity 0.2s;
}

.tsm-panel-close:hover {
    opacity: 1;
}

.tsm-panel-content {
    overflow-y: auto;
    flex: 1;
}

/* ========================================
   ACCORDION (Inside Floating Panel)
   ======================================== */

.tsm-accordion-item {
    border-bottom: 1px solid #e5e7eb;
}

.tsm-accordion-item:last-child {
    border-bottom: none;
}

.tsm-accordion-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 20px;
    cursor: pointer;
    transition: background 0.15s;
}

.tsm-accordion-header:hover {
    background: #f9fafb;
}

.tsm-accordion-title {
    margin: 0;
    font-size: 14px;
    font-weight: 600;
    color: var(--tsm-text);
}

.tsm-accordion-icon {
    font-size: 12px;
    transition: transform 0.3s;
    color: #6b7280;
}

.tsm-accordion-expanded .tsm-accordion-icon {
    transform: rotate(180deg);
}

.tsm-accordion-content {
    overflow: hidden;
    transition: max-height 0.3s ease-out;
}

/* ========================================
   TOPIC ITEMS LIST (Shared by both modes)
   CRITICAL: No layout shift on hover
   ======================================== */

.tsm-topic-items {
    list-style: none;
    margin: 0;
    padding: 0;
}

.tsm-item {
    margin-bottom: 8px;
}

.tsm-item:last-child {
    margin-bottom: 0;
}

.tsm-item-link {
    display: block;
    padding: 10px 12px;
    border-radius: 6px;
    text-decoration: none;
    color: var(--tsm-text);
    font-size: 14px;
    transition: background 0.15s, color 0.15s;
}

.tsm-item-link:hover {
    background: #f3f4f6;
    color: var(--tsm-primary);
}

/* Current Article Highlight */
.tsm-item-current {
    position: relative;
    padding: 10px 12px;
    padding-left: 20px;
    background: linear-gradient(90deg, rgba(102, 126, 234, 0.1), rgba(118, 75, 162, 0.05));
    border-radius: 6px;
    pointer-events: none;
    border-left: 3px solid var(--tsm-primary);
}

.tsm-current-indicator {
    position: absolute;
    left: 8px;
    top: 50%;
    transform: translateY(-50%);
    width: 6px;
    height: 6px;
    background: var(--tsm-primary);
    border-radius: 50%;
}

.tsm-item-current .tsm-item-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--tsm-primary);
}

/* ========================================
   RESPONSIVE
   ======================================== */

@media (max-width: 480px) {
    #tsm-floating-widget {
        bottom: 15px;
        right: 15px;
    }

    .tsm-widget-panel {
        width: calc(100vw - 30px);
        max-width: 380px;
    }
}