/**
 * RSL Announcements Component
 * Version: 1.0.0
 *
 * A two-mode announcement system with bar (collapsed) and panel (expanded) views.
 * Fully ADA compliant with WCAG 2.1 AA support.
 *
 * Modes:
 * - Bar Mode: Single-line ticker with navigation controls
 * - Panel Mode: Expanded scannable list of all announcements
 */

/* ==========================================================================
   CSS Variables
   ========================================================================== */

:root {
    /* Bar colors */
    --rsl-announcements-bar-bg: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    --rsl-announcements-bar-text: #ffffff;
    --rsl-announcements-bar-height: 48px;

    /* Panel colors */
    --rsl-announcements-panel-bg: #ffffff;
    --rsl-announcements-panel-border: #e0e0e0;
    --rsl-announcements-panel-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);

    /* Item colors */
    --rsl-announcements-item-bg: #f8f9fa;
    --rsl-announcements-item-hover-bg: #e9ecef;
    --rsl-announcements-item-border: #dee2e6;
    --rsl-announcements-item-text: #333333;
    --rsl-announcements-item-meta: #6c757d;

    /* Priority badges */
    --rsl-announcements-urgent-bg: #dc3545;
    --rsl-announcements-urgent-text: #ffffff;
    --rsl-announcements-event-bg: #007bff;
    --rsl-announcements-event-text: #ffffff;
    --rsl-announcements-news-bg: #28a745;
    --rsl-announcements-news-text: #ffffff;
    --rsl-announcements-reminder-bg: #ffc107;
    --rsl-announcements-reminder-text: #212529;

    /* Controls */
    --rsl-announcements-btn-bg: rgba(255, 255, 255, 0.2);
    --rsl-announcements-btn-hover-bg: rgba(255, 255, 255, 0.3);
    --rsl-announcements-btn-focus-outline: 2px solid #ffffff;

    /* Focus states - High contrast for ADA */
    --rsl-announcements-focus-outline: 3px solid #000000;
    --rsl-announcements-focus-outline-offset: 2px;

    /* Timing */
    --rsl-announcements-transition: 0.2s ease;
}

/* ==========================================================================
   Bar Mode (Collapsed State)
   ========================================================================== */

.rsl-announcements {
    position: relative;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 0.9375rem;
    line-height: 1.5;
}

.rsl-announcements-bar {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0 1rem;
    min-height: var(--rsl-announcements-bar-height);
    background: var(--rsl-announcements-bar-bg);
    color: var(--rsl-announcements-bar-text);
    border-radius: 8px;
}

/* Icon/Label area */
.rsl-announcements-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 600;
    white-space: nowrap;
    flex-shrink: 0;
}

.rsl-announcements-label i {
    font-size: 1rem;
}

/* Current announcement display */
.rsl-announcements-current {
    flex: 1;
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    overflow: hidden;
    position: relative;
}

/* Navigation hint tooltip */
.rsl-announcements-nav-hint {
    position: absolute;
    bottom: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.85);
    color: #ffffff;
    padding: 0.5rem 0.75rem;
    border-radius: 4px;
    font-size: 0.8125rem;
    white-space: nowrap;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s ease, visibility 0.2s ease;
    z-index: 100;
    pointer-events: none;
}

.rsl-announcements-nav-hint::after {
    content: '';
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    border: 6px solid transparent;
    border-top-color: rgba(0, 0, 0, 0.85);
}

.rsl-announcements-nav-hint.visible {
    opacity: 1;
    visibility: visible;
}

.rsl-announcements-text {
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.rsl-announcements-text a {
    color: inherit;
    text-decoration: none;
}

.rsl-announcements-text a:hover {
    text-decoration: underline;
}

.rsl-announcements-text a:focus {
    outline: var(--rsl-announcements-focus-outline);
    outline-offset: var(--rsl-announcements-focus-outline-offset);
    border-radius: 2px;
}

/* New indicator */
.rsl-announcements-new {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.125rem 0.5rem;
    font-size: 0.6875rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    background: rgba(255, 255, 255, 0.9);
    color: #667eea;
    border-radius: 9999px;
    flex-shrink: 0;
}

/* Controls area */
.rsl-announcements-controls {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    flex-shrink: 0;
}

.rsl-announcements-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    padding: 0;
    border: none;
    border-radius: 6px;
    background: var(--rsl-announcements-btn-bg);
    color: inherit;
    cursor: pointer;
    transition: background var(--rsl-announcements-transition);
}

.rsl-announcements-btn:hover {
    background: var(--rsl-announcements-btn-hover-bg);
}

.rsl-announcements-btn:focus {
    outline: var(--rsl-announcements-focus-outline);
    outline-offset: var(--rsl-announcements-focus-outline-offset);
    background: var(--rsl-announcements-btn-hover-bg);
}

.rsl-announcements-btn:focus:not(:focus-visible) {
    outline: none;
}

.rsl-announcements-btn:focus-visible {
    outline: var(--rsl-announcements-focus-outline);
    outline-offset: var(--rsl-announcements-focus-outline-offset);
}

.rsl-announcements-btn[disabled] {
    opacity: 0.5;
    cursor: not-allowed;
}

.rsl-announcements-btn i {
    font-size: 0.875rem;
}

/* Counter (e.g., "2 of 5") */
.rsl-announcements-counter {
    font-size: 0.8125rem;
    opacity: 0.9;
    white-space: nowrap;
    padding: 0 0.5rem;
}

/* Expand button */
.rsl-announcements-expand {
    margin-left: 0.25rem;
}

/* ==========================================================================
   Priority Badges
   ========================================================================== */

.rsl-announcements-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.125rem 0.5rem;
    font-size: 0.6875rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    border-radius: 4px;
    flex-shrink: 0;
}

.rsl-announcements-badge[data-priority="urgent"] {
    background: var(--rsl-announcements-urgent-bg);
    color: var(--rsl-announcements-urgent-text);
}

.rsl-announcements-badge[data-priority="event"] {
    background: var(--rsl-announcements-event-bg);
    color: var(--rsl-announcements-event-text);
}

.rsl-announcements-badge[data-priority="news"] {
    background: var(--rsl-announcements-news-bg);
    color: var(--rsl-announcements-news-text);
}

.rsl-announcements-badge[data-priority="reminder"] {
    background: var(--rsl-announcements-reminder-bg);
    color: var(--rsl-announcements-reminder-text);
}

/* ==========================================================================
   Panel Mode (Expanded State)
   ========================================================================== */

.rsl-announcements-panel {
    position: absolute;
    top: calc(100% + 0.5rem);
    left: 0;
    right: 0;
    max-height: 0;
    overflow: hidden;
    background: var(--rsl-announcements-panel-bg);
    border-radius: 12px;
    box-shadow: var(--rsl-announcements-panel-shadow);
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: max-height 0.3s ease, opacity 0.2s ease, visibility 0.2s ease;
}

.rsl-announcements.is-expanded .rsl-announcements-panel {
    max-height: 400px;
    opacity: 1;
    visibility: visible;
    overflow-y: auto;
}

/* Panel header */
.rsl-announcements-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--rsl-announcements-panel-border);
    position: sticky;
    top: 0;
    background: var(--rsl-announcements-panel-bg);
    z-index: 1;
}

.rsl-announcements-panel-title {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--rsl-announcements-item-text);
    margin: 0;
}

.rsl-announcements-panel-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    padding: 0;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: var(--rsl-announcements-item-meta);
    cursor: pointer;
    transition: background var(--rsl-announcements-transition), color var(--rsl-announcements-transition);
}

.rsl-announcements-panel-close:hover {
    background: var(--rsl-announcements-item-bg);
    color: var(--rsl-announcements-item-text);
}

.rsl-announcements-panel-close:focus {
    outline: var(--rsl-announcements-focus-outline);
    outline-offset: var(--rsl-announcements-focus-outline-offset);
}

.rsl-announcements-panel-close:focus:not(:focus-visible) {
    outline: none;
}

.rsl-announcements-panel-close:focus-visible {
    outline: var(--rsl-announcements-focus-outline);
    outline-offset: var(--rsl-announcements-focus-outline-offset);
}

/* Panel list */
.rsl-announcements-list {
    list-style: none;
    margin: 0;
    padding: 0.5rem 0;
}

.rsl-announcements-item {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    padding: 0.875rem 1.25rem;
    border-bottom: 1px solid var(--rsl-announcements-item-border);
    transition: background var(--rsl-announcements-transition);
}

.rsl-announcements-item:last-child {
    border-bottom: none;
}

.rsl-announcements-item:hover {
    background: var(--rsl-announcements-item-hover-bg);
}

.rsl-announcements-item:focus-within {
    background: var(--rsl-announcements-item-hover-bg);
}

/* Item content */
.rsl-announcements-item-content {
    flex: 1;
    min-width: 0;
}

.rsl-announcements-item-title {
    font-weight: 500;
    color: var(--rsl-announcements-item-text);
    margin: 0 0 0.25rem 0;
    font-size: 0.9375rem;
}

.rsl-announcements-item-title a {
    color: inherit;
    text-decoration: none;
}

.rsl-announcements-item-title a:hover {
    text-decoration: underline;
}

.rsl-announcements-item-title a:focus {
    outline: var(--rsl-announcements-focus-outline);
    outline-offset: var(--rsl-announcements-focus-outline-offset);
    border-radius: 2px;
}

.rsl-announcements-item-meta {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.8125rem;
    color: var(--rsl-announcements-item-meta);
}

.rsl-announcements-item-date i {
    margin-right: 0.25rem;
}

/* Item badges */
.rsl-announcements-item-badges {
    display: flex;
    gap: 0.375rem;
    flex-shrink: 0;
    padding-top: 0.125rem;
}

/* ==========================================================================
   Screen Reader Only / Live Region
   ========================================================================== */

.rsl-announcements-sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Live region for announcements */
.rsl-announcements-live {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* ==========================================================================
   Paused State
   ========================================================================== */

.rsl-announcements.is-paused .rsl-announcements-bar {
    /* Subtle visual indicator that auto-rotation is paused */
}

.rsl-announcements.is-paused .rsl-announcements-pause i::before {
    content: "\f04b"; /* Font Awesome play icon */
}

/* ==========================================================================
   Empty State
   ========================================================================== */

.rsl-announcements-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    text-align: center;
    color: var(--rsl-announcements-item-meta);
}

.rsl-announcements-empty i {
    font-size: 2rem;
    margin-bottom: 0.75rem;
    opacity: 0.5;
}

.rsl-announcements-empty p {
    margin: 0;
    font-size: 0.9375rem;
}

/* ==========================================================================
   Reduced Motion
   ========================================================================== */

@media (prefers-reduced-motion: reduce) {
    .rsl-announcements-panel {
        transition: none;
    }

    .rsl-announcements-btn,
    .rsl-announcements-panel-close,
    .rsl-announcements-item {
        transition: none;
    }
}

/* ==========================================================================
   Responsive - Mobile
   ========================================================================== */

@media (max-width: 767px) {
    .rsl-announcements-bar {
        flex-direction: column;
        padding: 0.75rem 1rem;
        gap: 0.625rem;
        min-height: auto;
    }

    /* Label row */
    .rsl-announcements-label {
        width: 100%;
        display: flex;
        justify-content: flex-start;
        align-items: center;
    }

    /* Current announcement - full width, allow text to wrap */
    .rsl-announcements-current {
        width: 100%;
        order: 2;
    }

    .rsl-announcements-text {
        white-space: normal;
        overflow: visible;
        text-overflow: clip;
        line-height: 1.4;
    }

    /* Controls row at bottom - all buttons inline */
    .rsl-announcements-controls {
        width: 100%;
        justify-content: center;
        order: 3;
        padding-top: 0.5rem;
        border-top: 1px solid rgba(255, 255, 255, 0.2);
    }

    /* Panel adjustments - slide up from bottom */
    .rsl-announcements-panel {
        position: fixed;
        top: auto;
        bottom: 0;
        left: 0;
        right: 0;
        border-radius: 16px 16px 0 0;
        max-height: 70vh;
    }

    .rsl-announcements.is-expanded .rsl-announcements-panel {
        max-height: 70vh;
    }

    .rsl-announcements-item {
        flex-direction: column;
        gap: 0.5rem;
    }

    .rsl-announcements-item-badges {
        order: -1;
        padding-top: 0;
    }
}

/* Extra small screens - even more compact */
@media (max-width: 480px) {
    .rsl-announcements-bar {
        padding: 0.625rem 0.75rem;
    }

    .rsl-announcements-btn {
        width: 28px;
        height: 28px;
    }

    .rsl-announcements-btn i {
        font-size: 0.75rem;
    }

    .rsl-announcements-counter {
        font-size: 0.75rem;
        padding: 0 0.25rem;
    }
}

/* ==========================================================================
   Dark Mode
   ========================================================================== */

[data-theme="dark"] {
    --rsl-announcements-bar-bg: linear-gradient(135deg, #4a5568 0%, #2d3748 100%);
    --rsl-announcements-bar-text: #e0e0e0;

    --rsl-announcements-panel-bg: #1a1a1a;
    --rsl-announcements-panel-border: #333333;
    --rsl-announcements-panel-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);

    --rsl-announcements-item-bg: #2a2a2a;
    --rsl-announcements-item-hover-bg: #333333;
    --rsl-announcements-item-border: #3a3a3a;
    --rsl-announcements-item-text: #e0e0e0;
    --rsl-announcements-item-meta: #a0a0a0;

    --rsl-announcements-btn-bg: rgba(255, 255, 255, 0.1);
    --rsl-announcements-btn-hover-bg: rgba(255, 255, 255, 0.2);

    /* High contrast focus for dark mode */
    --rsl-announcements-focus-outline: 3px solid #ffffff;
}

[data-theme="dark"] .rsl-announcements-new {
    background: rgba(255, 255, 255, 0.15);
    color: #e0e0e0;
}

/* ==========================================================================
   Color Variants
   ========================================================================== */

/* Info variant (blue) */
.rsl-announcements[data-variant="info"] {
    --rsl-announcements-bar-bg: linear-gradient(135deg, #007bff 0%, #0056b3 100%);
}

/* Success variant (green) */
.rsl-announcements[data-variant="success"] {
    --rsl-announcements-bar-bg: linear-gradient(135deg, #28a745 0%, #1e7e34 100%);
}

/* Warning variant (amber) */
.rsl-announcements[data-variant="warning"] {
    --rsl-announcements-bar-bg: linear-gradient(135deg, #ffc107 0%, #e0a800 100%);
    --rsl-announcements-bar-text: #212529;
}

[data-theme="dark"] .rsl-announcements[data-variant="warning"] {
    --rsl-announcements-bar-text: #212529;
}

/* Danger variant (red) */
.rsl-announcements[data-variant="danger"] {
    --rsl-announcements-bar-bg: linear-gradient(135deg, #dc3545 0%, #c82333 100%);
}

/* Neutral variant (gray) */
.rsl-announcements[data-variant="neutral"] {
    --rsl-announcements-bar-bg: linear-gradient(135deg, #6c757d 0%, #495057 100%);
}

/* ==========================================================================
   Filter Integration Highlight
   ========================================================================== */

.rsl-announcements-item[data-filter-match="true"] {
    background: rgba(102, 126, 234, 0.1);
    border-left: 3px solid #667eea;
}

[data-theme="dark"] .rsl-announcements-item[data-filter-match="true"] {
    background: rgba(102, 126, 234, 0.15);
}

/* Hidden items when filtered */
.rsl-announcements-item[data-filter-hidden="true"] {
    display: none;
}
