/* サイドバー専用CSS */

.widget {
    border: none;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    margin-bottom: 1.5rem;
    border-radius: 0.5rem;
    overflow: hidden;
}

.widget:last-child {
    margin-bottom: 0;
}

.widget-header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    font-weight: 600;
    border-radius: 0.5rem 0.5rem 0 0;
}

/* 検索フォーム */
.search-form .input-group {
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    border-radius: 0.375rem;
    overflow: hidden;
}

.search-form .form-control {
    border-right: none;
}

.search-form .form-control:focus {
    box-shadow: none;
    border-color: #007bff;
}

.search-form .btn {
    border-left: none;
}

/* 人気記事ランキング */
.ranking-number {
    width: 2rem;
    height: 2rem;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.875rem;
    color: white;
}

.ranking-number.gold {
    background: linear-gradient(45deg, #ffd700, #ffed4e);
    color: #b45309;
}

.ranking-number.silver {
    background: linear-gradient(45deg, #c0c0c0, #e2e8f0);
    color: #4a5568;
}

.ranking-number.bronze {
    background: linear-gradient(45deg, #cd7f32, #d69e2e);
    color: white;
}

.ranking-number.normal {
    background: #6c757d;
}

/* カテゴリリンク */
.category-link {
    transition: all 0.3s ease;
    position: relative;
}

.category-link:hover {
    background-color: #f8f9fa !important;
    transform: translateX(5px);
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

/* カレンダー */
.calendar-table td {
    text-align: center;
    cursor: default;
    padding: 0.5rem;
    height: 2.5rem;
    vertical-align: middle;
    position: relative;
    transition: all 0.2s ease;
}

.calendar-table .has-posts {
    background-color: #28a745 !important;
    color: white !important;
    font-weight: 600 !important;
    cursor: pointer !important;
    border-radius: 0.25rem;
    position: relative;
    transition: all 0.2s ease;
    border: 2px solid transparent;
}

.calendar-table .has-posts:hover {
    background-color: #1e7e34 !important;
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(40,167,69,0.4);
    z-index: 10;
    border-color: #fff;
}

.calendar-table .has-posts::before {
    content: '';
    position: absolute;
    top: -2px;
    right: -2px;
    background: #dc3545;
    color: white;
    border-radius: 50%;
    width: 12px;
    height: 12px;
    font-size: 0.6rem;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    z-index: 1;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.1); }
    100% { transform: scale(1); }
}

.calendar-table .today {
    background-color: #ffc107 !important;
    color: #212529 !important;
    font-weight: 700 !important;
    border-radius: 0.25rem;
    position: relative;
}

.calendar-table .today::after {
    content: '今日';
    position: absolute;
    top: -12px;
    left: 50%;
    transform: translateX(-50%);
    background: #007bff;
    color: white;
    font-size: 0.6rem;
    padding: 1px 4px;
    border-radius: 2px;
    white-space: nowrap;
    font-weight: normal;
}

.calendar-table .has-posts.today {
    background: linear-gradient(135deg, #ffc107 0%, #28a745 100%) !important;
    color: white !important;
    font-weight: 700 !important;
}

/* table-responsiveを無効化してカスタム制御 */
.widget .table-responsive {
    overflow-x: visible !important; /* 横スクロールを完全に無効化 */
    overflow-y: visible !important;
}

/* サイドバー広告 - はみ出し防止 */
.sidebar-ad-item {
    background: white;
    border: 1px solid #e9ecef;
    border-radius: 0.5rem;
    overflow: hidden; /* はみ出し防止 */
    transition: all 0.3s ease;
    margin-bottom: 1rem;
}

.sidebar-ad-item:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

.sidebar-ad-link {
    text-decoration: none;
    color: inherit;
    display: block;
    padding: 1rem;
}

.sidebar-ad-link:hover {
    color: inherit;
    text-decoration: none;
}

/* サイドバー広告画像 - はみ出し防止 */
.sidebar-ad-image {
    height: 120px;
    overflow: hidden;
    border-radius: 0.375rem;
    background: #f8f9fa;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

.sidebar-ad-image img {
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
    object-fit: contain; /* はみ出し防止 */
    object-position: center;
    transition: transform 0.3s ease;
}

.sidebar-ad-item:hover .sidebar-ad-image img {
    transform: scale(1.02); /* 控えめなズーム */
}

/* RAW広告のはみ出し防止 */
.sidebar-ad-raw {
    padding: 1rem;
    overflow: hidden; /* はみ出し防止 */
    max-height: 200px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.sidebar-ad-raw img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain; /* はみ出し防止 */
}

.sidebar-ad-raw iframe,
.sidebar-ad-raw object,
.sidebar-ad-raw embed {
    max-width: 100%;
    max-height: 160px; /* 制限高さ */
}

.sidebar-ad-title {
    font-size: 0.9rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
    line-height: 1.3;
    /* テキストのはみ出し防止 */
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

.sidebar-ad-desc {
    font-size: 0.8rem;
    color: #6c757d;
    margin: 0;
    line-height: 1.4;
    /* テキストのはみ出し防止 */
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
}

/* アーカイブリンク */
.archive-link {
    transition: all 0.3s ease;
}

.archive-link:hover {
    background-color: #f8f9fa !important;
    transform: translateX(5px);
}

/* サイドウィジェット */
.sidebar-widgets .widget-item {
    background: white;
    border-radius: 0.5rem;
    padding: 1rem;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    border: none;
    margin-bottom: 1.5rem;
    overflow: hidden; /* はみ出し防止 */
}

.sidebar-widgets .widget-item:last-child {
    margin-bottom: 0;
}

/* ウィジェット内のコンテンツ制御 - はみ出し防止 */
.sidebar-widgets .widget-item iframe {
    max-width: 100%;
    height: auto;
    max-height: 300px; /* 制限高さ */
}

.sidebar-widgets .widget-item img {
    max-width: 100%;
    height: auto;
    border-radius: 0.25rem;
    object-fit: contain; /* はみ出し防止 */
}

.sidebar-widgets .widget-item table {
    width: 100%;
    font-size: 0.9rem;
    table-layout: fixed; /* テーブルのはみ出し防止 */
}

.sidebar-widgets .widget-item table td,
.sidebar-widgets .widget-item table th {
    word-wrap: break-word;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* レスポンシブ対応 */
@media (max-width: 768px) {
    .widget {
        margin-bottom: 1rem;
    }
    
    .calendar-table {
        font-size: 0.85rem;
    }
    
    .calendar-table td {
        height: 2rem;
        padding: 0.25rem;
    }
    
    .calendar-table .has-posts::before {
        width: 14px;
        height: 14px;
        font-size: 0.6rem;
        top: -6px;
        right: -6px;
    }
    
    .sidebar-ad-image {
        height: 100px;
    }
    
    .sidebar-ad-title {
        font-size: 0.85rem;
        -webkit-line-clamp: 1;
    }
    
    .sidebar-ad-desc {
        font-size: 0.75rem;
        -webkit-line-clamp: 2;
    }
    
    .sidebar-widgets .widget-item {
        padding: 0.75rem;
        margin-bottom: 1rem;
    }
}

/* アニメーション */
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.widget {
    animation: fadeInUp 0.6s ease;
}

.widget:nth-child(1) { animation-delay: 0.1s; }
.widget:nth-child(2) { animation-delay: 0.2s; }
.widget:nth-child(3) { animation-delay: 0.3s; }
.widget:nth-child(4) { animation-delay: 0.4s; }
.widget:nth-child(5) { animation-delay: 0.5s; }
.widget:nth-child(6) { animation-delay: 0.6s; }

/* はみ出し防止の共通ルール */
.widget * {
    max-width: 100% !important;
}

/* 特殊なコンテンツの制御 */
.widget table {
    max-width: 100% !important;
    table-layout: fixed;
}

.widget pre {
    white-space: pre-wrap;
    word-wrap: break-word;
    overflow: hidden;
}

.widget code {
    word-wrap: break-word;
}