/* ============================================================
   Dennis 6.0 — Sidebar Widget Styles
   9 Components: Announcement, Checkin, Music, Timeline,
   Recent Comments, Featured, Categories, Links, Search
   Design Tokens: P1-05 B案色板（极夜深蓝）
   ============================================================ */

/* ============================================================
   0.0 Widget Token Extensions (I-1 / I-5 fix, 2026-10-11)
   Component-scoped tokens extending the P2-01 base token set
   (defined in assets/css/main.css). Values follow the P1-05
   dark-mode palette so dark-theme overrides no longer bypass
   the token system with hardcoded hex colors.
   ============================================================ */
:root {
    --color-primary-active: #1e40af;      /* primary pressed/active (light) */
    --color-bg-hover: #f8fafc;            /* subtle hover surface (light) */
    --color-primary-dark: #3b82f6;        /* primary on dark theme */
    --color-primary-dark-strong: #60a5fa; /* primary hover on dark theme */
    --color-warning-dark: #fbbf24;        /* accent/warning on dark theme */
    --color-surface-dark: #1e293b;        /* elevated surface on dark theme */
}

/* Screen-reader-only helper (live region for checkin, I-4 / D-4) */
.dennis-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;
}

/* ============================================================
   0. Widget Base & Shared
   ============================================================ */
.dennis-widget {
    background-color: var(--color-card);
    border-radius: var(--radius-lg);
    box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.05);
    padding: var(--space-md);
    margin-bottom: var(--space-lg);
}

.widget-title {
    font-size: 16px;
    font-weight: 700;
    line-height: 1.5;
    color: var(--color-text-primary);
    padding-bottom: var(--space-sm);
    margin-bottom: var(--space-sm);
    border-bottom: 1px solid var(--color-border);
    display: flex;
    align-items: center;
    gap: var(--space-xs);
}

.widget-icon {
    flex-shrink: 0;
    color: var(--color-primary);
}

.widget-empty {
    text-align: center;
    padding: var(--space-xl) 0;
    color: var(--color-text-tertiary);
    font-size: 12px;
}

/* ============================================================
   1. Announcement Widget
   ============================================================ */
.announcement-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.announcement-item {
    position: relative;
    border-bottom: 1px solid var(--color-border);
}

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

.announcement-item.is-new {
    padding-left: 8px;
}

.announcement-item.is-new::before {
    content: '';
    position: absolute;
    left: 0;
    top: 12px;
    bottom: 12px;
    width: 3px;
    background-color: var(--color-accent);
    border-radius: 2px;
}

.announcement-toggle {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-sm);
    padding: 10px 0;
    background: none;
    border: none;
    color: var(--color-text-primary);
    font-size: 14px;
    text-align: left;
    cursor: pointer;
    transition: color 0.2s ease;
}

.announcement-toggle:hover {
    color: var(--color-primary);
}

.announcement-toggle:hover .toggle-icon {
    color: var(--color-primary);
}

.announcement-title {
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.toggle-icon {
    flex-shrink: 0;
    color: var(--color-text-tertiary);
    transition: transform 0.3s ease, color 0.2s ease;
}

.announcement-toggle[aria-expanded="true"] .toggle-icon {
    transform: rotate(180deg);
}

.announcement-content {
    font-size: 13px;
    line-height: 1.7;
    color: var(--color-text-secondary);
    padding: 0 0 10px 0;
    overflow: hidden;
    transition: max-height 0.3s ease, opacity 0.3s ease, padding 0.3s ease;
    max-height: 200px;
    opacity: 1;
}

.announcement-content[hidden] {
    display: block;
    max-height: 0;
    opacity: 0;
    padding: 0;
    pointer-events: none;
}

/* ============================================================
   2. Check-in Widget
   ============================================================ */
.checkin-panel {
    margin-bottom: var(--space-sm);
}

.checkin-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-xs);
    width: 100%;
    height: 40px;
    padding: 0 24px;
    background-color: var(--color-primary);
    color: #ffffff;
    border-radius: var(--radius-md);
    font-size: 14px;
    font-weight: 500;
    text-decoration: none;
    border: none;
    cursor: pointer;
    transition: background-color 0.2s ease, box-shadow 0.2s ease;
}

.checkin-btn:hover:not(:disabled) {
    background-color: var(--color-secondary);
    box-shadow: 0 2px 8px rgba(37, 99, 235, 0.3);
    text-decoration: none;
}

.checkin-btn:active:not(:disabled) {
    background-color: var(--color-primary-active);
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.1);
}

.checkin-btn.checked,
.checkin-btn:disabled {
    background-color: var(--color-success);
    cursor: default;
}

.checkin-btn .checkin-loading {
    display: none;
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: #ffffff;
    border-radius: 50%;
    animation: dennis-spin 0.8s linear infinite;
}

.checkin-btn.is-loading .checkin-loading {
    display: inline-block;
}

.checkin-btn.is-loading svg,
.checkin-btn.is-loading span:not(.checkin-loading) {
    display: none;
}

@keyframes dennis-spin {
    to { transform: rotate(360deg); }
}

.checkin-rule {
    text-align: center;
    margin-top: var(--space-sm);
    font-size: 12px;
    color: var(--color-text-secondary);
    line-height: 1.5;
}

.checkin-leaderboard {
    list-style: none;
    padding: 0;
    margin: 0;
}

.leaderboard-item {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    height: 48px;
    border-bottom: 1px solid var(--color-border);
    padding: 0 var(--space-xs);
}

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

.rank {
    width: 20px;
    text-align: center;
    font-size: 13px;
    font-weight: 700;
    color: var(--color-text-tertiary);
    flex-shrink: 0;
}

.rank-top {
    color: var(--color-accent);
}

.leader-avatar .avatar-img {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-full);
    flex-shrink: 0;
}

.leader-name {
    font-size: 14px;
    color: var(--color-text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ============================================================
   3. Music Player Widget
   ============================================================ */
.music-player {
    user-select: none;
}

.music-info {
    text-align: center;
    margin-bottom: var(--space-sm);
    min-height: 42px;
}

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

.music-artist {
    font-size: 12px;
    color: var(--color-text-secondary);
    margin-top: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.music-progress {
    margin-bottom: var(--space-sm);
}

.progress-bar {
    width: 100%;
    height: 4px;
    background-color: var(--color-border);
    border-radius: 2px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background-color: var(--color-primary);
    border-radius: 2px;
    width: 0%;
    transition: width 0.1s linear;
}

.music-time {
    display: flex;
    justify-content: space-between;
    font-size: 11px;
    color: var(--color-text-tertiary);
    margin-top: 4px;
}

.music-controls {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-sm);
    margin-bottom: var(--space-sm);
}

.music-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    color: var(--color-text-secondary);
    cursor: pointer;
    padding: 4px;
    border-radius: var(--radius-md);
    transition: color 0.2s ease, background-color 0.2s ease;
}

.music-btn:hover {
    color: var(--color-primary);
    background-color: var(--color-bg-hover);
}

.music-btn.music-play {
    width: 36px;
    height: 36px;
    background-color: var(--color-primary);
    color: #ffffff;
    border-radius: 50%;
    padding: 0;
}

.music-btn.music-play:hover {
    background-color: var(--color-secondary);
    color: #ffffff;
    box-shadow: 0 2px 8px rgba(37, 99, 235, 0.3);
}

.music-btn.music-play:active {
    background-color: var(--color-primary-active);
}

.music-btn.music-mode {
    margin-left: auto;
}

.music-btn svg {
    display: block;
}

.music-btn [hidden] {
    display: none !important;
}

.playlist-toggle {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-xs);
    padding: 6px 0;
    background: none;
    border: none;
    border-top: 1px solid var(--color-border);
    color: var(--color-text-secondary);
    font-size: 12px;
    cursor: pointer;
    transition: color 0.2s ease;
}

.playlist-toggle:hover {
    color: var(--color-primary);
}

.playlist-toggle svg {
    transition: transform 0.3s ease;
}

.playlist-toggle[aria-expanded="true"] svg {
    transform: rotate(180deg);
}

.playlist {
    list-style: none;
    padding: 0;
    margin: 0;
    max-height: 240px;
    overflow-y: auto;
    transition: max-height 0.3s ease, opacity 0.3s ease;
    opacity: 1;
}

.playlist[hidden] {
    display: block;
    max-height: 0;
    opacity: 0;
    overflow: hidden;
    pointer-events: none;
}

.playlist-item {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 8px var(--space-sm);
    cursor: pointer;
    border-radius: var(--radius-sm, 4px);
    transition: background-color 0.15s ease;
}

.playlist-item:hover {
    background-color: var(--color-bg-hover);
}

.playlist-item.is-active {
    background-color: rgba(37, 99, 235, 0.06);
}

.playlist-item.is-active .track-title {
    color: var(--color-primary);
    font-weight: 500;
}

.track-title {
    font-size: 13px;
    color: var(--color-text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.track-artist {
    font-size: 11px;
    color: var(--color-text-tertiary);
}

/* ============================================================
   4. Timeline Widget (时光静好)
   ============================================================ */
.timeline-stats {
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
}

.timeline-item {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.timeline-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.timeline-label {
    font-size: 14px;
    color: var(--color-text-primary);
}

.timeline-elapsed {
    font-size: 12px;
    color: var(--color-text-secondary);
}

.timeline-bar {
    width: 100%;
    height: 6px;
    background-color: var(--color-border);
    border-radius: 3px;
    overflow: hidden;
}

.timeline-fill {
    height: 100%;
    background-color: var(--color-primary);
    border-radius: 3px;
    width: 0%;
    transition: width 0.8s ease-out;
}

/* ============================================================
   5. Recent Comments Widget
   ============================================================ */
.recent-comment-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.recent-comment-item {
    border-bottom: 1px solid var(--color-border);
}

.recent-comment-item:last-child {
    border-bottom: none;
}

.comment-link {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: 8px 0;
    text-decoration: none;
    transition: background-color 0.15s ease;
    border-radius: var(--radius-sm, 4px);
}

.comment-link:hover {
    background-color: var(--color-bg-hover);
    text-decoration: none;
}

.comment-link .avatar-img {
    width: 32px;
    height: 32px;
    border-radius: var(--radius-full);
    flex-shrink: 0;
}

.comment-body {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
    flex: 1;
}

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

.comment-excerpt {
    font-size: 12px;
    color: var(--color-text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ============================================================
   6. Featured Article Widget (站长推荐)
   ============================================================ */
.featured-article {
    display: block;
    text-decoration: none;
    border-radius: var(--radius-lg);
    overflow: hidden;
}

.featured-article:hover {
    text-decoration: none;
}

.featured-image-wrapper {
    position: relative;
    width: 100%;
    aspect-ratio: 16 / 9;
    overflow: hidden;
    border-radius: var(--radius-lg);
}

.featured-image-wrapper img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.3s ease;
}

.featured-article:hover .featured-image-wrapper img {
    transform: scale(1.02);
}

.featured-overlay {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 60%;
    background: linear-gradient(to top, rgba(0, 0, 0, 0.6), transparent);
    pointer-events: none;
}

.featured-title {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 12px;
    font-size: 14px;
    font-weight: 500;
    color: #ffffff;
    line-height: 1.5;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    transition: color 0.2s ease;
}

.featured-article:hover .featured-title {
    color: var(--color-accent);
}

/* ============================================================
   7. Categories Widget (栏目更新)
   ============================================================ */
.category-mini-list {
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
}

.cat-group {
    padding-bottom: var(--space-md);
    border-bottom: 1px solid var(--color-border);
}

.cat-group:last-child {
    border-bottom: none;
    padding-bottom: 0;
}

.cat-group-title {
    font-size: 14px;
    font-weight: 700;
    margin-bottom: var(--space-sm);
    line-height: 1.4;
}

.cat-group-title a {
    color: var(--color-primary);
    text-decoration: none;
    transition: color 0.2s ease;
}

.cat-group-title a:hover {
    color: var(--color-secondary);
    text-decoration: none;
}

.cat-posts {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.cat-posts li {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: var(--space-sm);
}

.cat-posts li a {
    font-size: 13px;
    color: var(--color-text-primary);
    text-decoration: none;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
    transition: color 0.2s ease;
}

.cat-posts li a:hover {
    color: var(--color-primary);
    text-decoration: none;
}

.cat-post-date {
    font-size: 12px;
    color: var(--color-text-tertiary);
    flex-shrink: 0;
}

/* ============================================================
   8. Friend Links Widget
   ============================================================ */
.friend-links {
    list-style: none;
    padding: 0;
    margin: 0;
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: var(--space-sm);
}

.friend-link-item a {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: 6px;
    text-decoration: none;
    border-radius: var(--radius-md);
    transition: background-color 0.2s ease;
}

.friend-link-item a:hover {
    background-color: var(--color-bg-hover);
    text-decoration: none;
}

.friend-link-item a:hover .link-name {
    color: var(--color-primary);
}

.friend-link-item a:hover .link-icon,
.friend-link-item a:hover .link-icon-fallback {
    transform: scale(1.05);
}

.link-icon,
.link-icon-fallback {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-full);
    flex-shrink: 0;
    transition: transform 0.2s ease;
    overflow: hidden;
}

.link-icon img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.link-icon-fallback {
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: var(--color-primary);
    color: #ffffff;
    font-size: 16px;
    font-weight: 700;
}

.link-name {
    font-size: 14px;
    color: var(--color-text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: color 0.2s ease;
}

/* ============================================================
   9. Search Widget
   ============================================================ */
.dennis-search-form {
    width: 100%;
}

.search-field-wrapper {
    display: flex;
    height: 40px;
    border-radius: var(--radius-md);
    overflow: hidden;
    border: 1px solid var(--color-border);
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.search-field-wrapper:focus-within {
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.search-field-wrapper .search-field {
    flex: 1;
    height: 100%;
    padding: 0 12px;
    border: none;
    background-color: var(--color-card);
    color: var(--color-text-primary);
    font-size: 14px;
    outline: none;
}

.search-field-wrapper .search-field::placeholder {
    color: var(--color-text-tertiary);
}

.search-field-wrapper .search-submit {
    width: 40px;
    height: 100%;
    background-color: var(--color-primary);
    color: #ffffff;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background-color 0.2s ease;
    flex-shrink: 0;
}

.search-field-wrapper .search-submit:hover {
    background-color: var(--color-secondary);
}

/* ============================================================
   10. Dark Mode Overrides
   ============================================================ */
[data-theme="dark"] .dennis-widget {
    box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.06);
}

[data-theme="dark"] .announcement-toggle:hover {
    color: var(--color-primary-dark);
}

[data-theme="dark"] .announcement-item.is-new::before {
    background-color: var(--color-warning-dark);
}

[data-theme="dark"] .checkin-btn:hover:not(:disabled) {
    box-shadow: 0 2px 8px rgba(59, 130, 246, 0.4);
}

[data-theme="dark"] .music-btn:hover {
    background-color: rgba(255, 255, 255, 0.06);
}

[data-theme="dark"] .music-btn.music-play {
    background-color: var(--color-primary-dark);
}

[data-theme="dark"] .music-btn.music-play:hover {
    background-color: var(--color-primary-dark-strong);
    box-shadow: 0 2px 8px rgba(59, 130, 246, 0.4);
}

[data-theme="dark"] .playlist-item:hover {
    background-color: rgba(255, 255, 255, 0.04);
}

[data-theme="dark"] .playlist-item.is-active {
    background-color: rgba(59, 130, 246, 0.12);
}

[data-theme="dark"] .comment-link:hover {
    background-color: rgba(255, 255, 255, 0.04);
}

[data-theme="dark"] .friend-link-item a:hover {
    background-color: rgba(255, 255, 255, 0.04);
}

[data-theme="dark"] .link-icon-fallback {
    background-color: var(--color-primary-dark);
}

[data-theme="dark"] .featured-article:hover .featured-title {
    color: var(--color-warning-dark);
}

[data-theme="dark"] .search-field-wrapper:focus-within {
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2);
}

[data-theme="dark"] .search-field-wrapper .search-field {
    background-color: var(--color-surface-dark);
}

/* ============================================================
   11. Mobile Responsive (< 768px)
   ============================================================ */
@media (max-width: 767px) {
    .dennis-widget {
        padding: var(--space-sm) var(--space-md);
    }

    .friend-links {
        grid-template-columns: repeat(2, 1fr);
    }

    .checkin-leaderboard {
        max-height: 240px;
        overflow-y: auto;
    }

    .leaderboard-item {
        height: 44px;
    }

    .music-controls {
        gap: 16px;
    }

    .playlist {
        max-height: 200px;
    }

    .category-mini-list {
        gap: var(--space-sm);
    }

    .cat-group {
        padding-bottom: var(--space-sm);
    }
}

/* ============================================================
   12. Reduced Motion
   ============================================================ */
@media (prefers-reduced-motion: reduce) {
    .announcement-content,
    .playlist,
    .timeline-fill,
    .toggle-icon,
    .playlist-toggle svg,
    .featured-image-wrapper img,
    .progress-fill {
        transition: none !important;
    }

    .checkin-btn .checkin-loading {
        animation: none;
    }
}
