/* ウィジェット共通CSS */

/* ウィジェットコンテナのスタイル */
.widgets-container {
    margin-bottom: 1rem;
    overflow: hidden; /* はみ出し防止 */
}

.widget-item {
    margin-bottom: 1.5rem;
    transition: all 0.3s ease;
    overflow: hidden; /* はみ出し防止 */
    border-radius: 0.5rem;
}

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

/* 位置別ウィジェットコンテナ */
.top-widgets-container {
    background: linear-gradient(135deg, #f8f9fa, #e9ecef);
    border-radius: 0.5rem;
    padding: 1rem;
    border: 1px solid #dee2e6;
    overflow: hidden; /* はみ出し防止 */
}

.bottom-widgets-container {
    background: linear-gradient(135deg, #f8f9fa, #e9ecef);
    border-radius: 0.5rem;
    padding: 1rem;
    border: 1px solid #dee2e6;
    overflow: hidden; /* はみ出し防止 */
}

.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;
    overflow: hidden; /* はみ出し防止 */
}

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

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

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

.widget-item table td,
.widget-item table th {
    word-wrap: break-word;
    overflow: hidden;
    text-overflow: ellipsis;
    padding: 0.5rem;
}

.widget-item video {
    max-width: 100%;
    height: auto;
    max-height: 300px; /* 制限高さ */
}

.widget-item object,
.widget-item embed {
    max-width: 100%;
    max-height: 300px; /* 制限高さ */
}

/* ウィジェット内のテキスト制御 */
.widget-item h1,
.widget-item h2,
.widget-item h3,
.widget-item h4,
.widget-item h5,
.widget-item h6 {
    word-wrap: break-word;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 0.75rem;
}

.widget-item p {
    word-wrap: break-word;
    overflow: hidden;
    margin-bottom: 0.75rem;
    line-height: 1.6;
}

.widget-item ul,
.widget-item ol {
    padding-left: 1.5rem;
    margin-bottom: 0.75rem;
}

.widget-item li {
    word-wrap: break-word;
    margin-bottom: 0.25rem;
}

.widget-item pre {
    white-space: pre-wrap;
    word-wrap: break-word;
    overflow: hidden;
    background: #f8f9fa;
    padding: 1rem;
    border-radius: 0.25rem;
    font-size: 0.875rem;
    max-height: 200px; /* 制限高さ */
    overflow-y: auto;
}

.widget-item code {
    word-wrap: break-word;
    background: #f8f9fa;
    padding: 0.125rem 0.25rem;
    border-radius: 0.125rem;
    font-size: 0.875rem;
}

/* ウィジェット内のリンク */
.widget-item a {
    word-wrap: break-word;
    color: #007bff;
    text-decoration: none;
    transition: color 0.3s ease;
}

.widget-item a:hover {
    color: #0056b3;
    text-decoration: underline;
}

/* ウィジェット内のフォーム */
.widget-item form {
    margin-bottom: 0.75rem;
}

.widget-item input,
.widget-item textarea,
.widget-item select {
    max-width: 100%;
    margin-bottom: 0.5rem;
}

.widget-item button {
    max-width: 100%;
    word-wrap: break-word;
}

/* ウィジェット内の引用 */
.widget-item blockquote {
    border-left: 4px solid #007bff;
    padding-left: 1rem;
    margin: 1rem 0;
    font-style: italic;
    background: #f8f9fa;
    padding: 1rem;
    border-radius: 0.25rem;
}

/* ウィジェット内のカード */
.widget-item .card {
    margin-bottom: 0.75rem;
    max-width: 100%;
}

.widget-item .card-body {
    padding: 0.75rem;
}

/* ウィジェット内のバッジ */
.widget-item .badge {
    margin: 0.125rem;
    word-wrap: break-word;
}

/* ウィジェット内のアラート */
.widget-item .alert {
    margin-bottom: 0.75rem;
    word-wrap: break-word;
}

/* ウィジェット内のプログレスバー */
.widget-item .progress {
    margin-bottom: 0.75rem;
    max-width: 100%;
}

/* レスポンシブ対応 */
@media (max-width: 768px) {
    .top-widgets-container,
    .bottom-widgets-container {
        padding: 0.75rem;
        margin-bottom: 1rem;
    }
    
    .sidebar-widgets .widget-item {
        padding: 0.75rem;
        margin-bottom: 1rem;
    }
    
    .widget-item {
        margin-bottom: 1rem;
    }
    
    .widget-item table {
        font-size: 0.8rem;
    }
    
    .widget-item iframe {
        max-height: 250px;
    }
    
    .widget-item video {
        max-height: 200px;
    }
    
    .widget-item pre {
        font-size: 0.75rem;
        max-height: 150px;
    }
}

@media (max-width: 480px) {
    .top-widgets-container,
    .bottom-widgets-container,
    .sidebar-widgets .widget-item {
        padding: 0.5rem;
    }
    
    .widget-item iframe {
        max-height: 200px;
    }
    
    .widget-item video {
        max-height: 150px;
    }
    
    .widget-item table {
        font-size: 0.75rem;
    }
    
    .widget-item table td,
    .widget-item table th {
        padding: 0.25rem;
    }
}

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

.widget-item {
    animation: fadeInUp 0.6s ease;
}

.top-widgets-container .widget-item:nth-child(1) { animation-delay: 0.1s; }
.top-widgets-container .widget-item:nth-child(2) { animation-delay: 0.2s; }
.top-widgets-container .widget-item:nth-child(3) { animation-delay: 0.3s; }

.bottom-widgets-container .widget-item:nth-child(1) { animation-delay: 0.1s; }
.bottom-widgets-container .widget-item:nth-child(2) { animation-delay: 0.2s; }
.bottom-widgets-container .widget-item:nth-child(3) { animation-delay: 0.3s; }

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

/* はみ出し防止の最終ルール */
.widgets-container *,
.widget-item * {
    max-width: 100% !important;
}

/* 特殊なコンテンツの制御 */
.widget-item canvas {
    max-width: 100%;
    height: auto;
}

.widget-item svg {
    max-width: 100%;
    height: auto;
}

.widget-item .responsive-embed {
    position: relative;
    display: block;
    width: 100%;
    padding: 0;
    overflow: hidden;
}

.widget-item .responsive-embed::before {
    content: "";
    display: block;
    padding-bottom: 56.25%; /* 16:9 aspect ratio */
}

.widget-item .responsive-embed iframe,
.widget-item .responsive-embed object,
.widget-item .responsive-embed embed {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border: 0;
}

/* ウィジェット読み込み状態 */
.widget-item.loading {
    position: relative;
    min-height: 100px;
}

.widget-item.loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 20px;
    height: 20px;
    margin: -10px 0 0 -10px;
    border: 2px solid #f3f3f3;
    border-top: 2px solid #007bff;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* ウィジェットエラー状態 */
.widget-item.error {
    background-color: #f8d7da;
    border: 1px solid #f5c6cb;
    color: #721c24;
    padding: 1rem;
    text-align: center;
}

.widget-item.error::before {
    content: "⚠️ ";
    font-size: 1.2rem;
}

/* ウィジェット空状態 */
.widget-item.empty {
    background-color: #f8f9fa;
    border: 1px dashed #dee2e6;
    color: #6c757d;
    padding: 2rem;
    text-align: center;
    font-style: italic;
}

.widget-item.empty::before {
    content: "📝 ";
    font-size: 1.2rem;
    display: block;
    margin-bottom: 0.5rem;
}

/* ダークモード対応（将来拡張用） */
@media (prefers-color-scheme: dark) {
    .widget-item {
        background-color: #2d3748;
        color: #e2e8f0;
    }
    
    .widget-item pre {
        background-color: #1a202c;
        color: #e2e8f0;
    }
    
    .widget-item code {
        background-color: #1a202c;
        color: #e2e8f0;
    }
    
    .widget-item blockquote {
        background-color: #2d3748;
        border-left-color: #4299e1;
    }
    
    .widget-item a {
        color: #63b3ed;
    }
    
    .widget-item a:hover {
        color: #90cdf4;
    }
}