/* 
 * コードブロック専用スタイル
 * Python側で生成されたHTMLに対応
 */

/* コードブロックのラッパー */
.code-block-wrapper {
    position: relative;
    margin: 1.5rem 0;
    background: #1e293b;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

/* 言語ラベル */
.code-language-label {
    position: absolute;
    top: 0;
    right: 0;
    background: #334155;
    color: #94a3b8;
    padding: 4px 12px;
    font-size: 0.75rem;
    text-transform: uppercase;
    font-weight: 600;
    border-radius: 0 8px 0 8px;
    z-index: 10;
}

/* コードブロック本体 */
.code-block-wrapper pre {
    margin: 0;
    padding: 1.5rem 1rem 1rem;
    overflow-x: auto;
    background: transparent;
    border: none;
}

.code-block-wrapper pre code {
    display: block;
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    font-size: 0.9rem;
    line-height: 1.6;
    color: #e2e8f0;
}

/* 標準的なコードブロック（行番号なし）のスタイル */
.code-block-wrapper pre code:not(:has(.code-line)) {
    white-space: pre;
    word-wrap: normal;
}

/* 行番号付きコード行 */
.code-line {
    display: flex;
    position: relative;
    margin: 0 -1rem;
    padding: 0 1rem;
    transition: background-color 0.2s ease;
}

.code-line:hover {
    background-color: rgba(255, 255, 255, 0.05);
}

/* 行番号 */
.line-number {
    user-select: none;
    display: inline-block;
    width: 3rem;
    margin-right: 1rem;
    text-align: right;
    color: #64748b;
    font-size: 0.85rem;
    flex-shrink: 0;
}

/* 差分表示 - 追加行 */
.code-line.line-add {
    background-color: rgba(40, 167, 69, 0.1);
    border-left: 3px solid #28a745;
}

.code-line.line-add .line-number {
    color: #28a745;
}

/* 差分表示 - エラー/削除行 */
.code-line.line-error {
    background-color: rgba(220, 53, 69, 0.1);
    border-left: 3px solid #dc3545;
}

.code-line.line-error .line-number {
    color: #dc3545;
}

/* インラインコード */
p code,
li code,
td code {
    background: #f1f5f9;
    color: #e11d48;
    padding: 0.2rem 0.4rem;
    border-radius: 4px;
    font-size: 0.875rem;
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    font-weight: 500;
}

/* 既存のPrism.jsスタイルとの競合を回避 */
.code-block-wrapper pre[class*="language-"] {
    padding: 1.5rem 1rem 1rem;
    margin: 0;
}

.code-block-wrapper code[class*="language-"] {
    background: none;
    text-shadow: none;
}

/* チェックボックスリスト */
.post-body ul {
    list-style: none;
    padding-left: 0;
}

.post-body ul li {
    position: relative;
    padding-left: 1.5rem;
    margin-bottom: 0.5rem;
}

/* 通常のリストマーカー */
.post-body ul li:not(:has(☐)):not(:has(☑))::before {
    content: "•";
    position: absolute;
    left: 0.5rem;
    color: #6b7280;
}

/* チェックボックス - 未チェック */
.post-body ul li:has(☐) {
    padding-left: 1.8rem;
}

.post-body ul li:has(☐)::before {
    content: "☐";
    position: absolute;
    left: 0;
    font-size: 1.2rem;
    line-height: 1.2;
    color: #6b7280;
}

/* チェックボックス - チェック済み */
.post-body ul li:has(☑) {
    padding-left: 1.8rem;
}

.post-body ul li:has(☑)::before {
    content: "☑";
    position: absolute;
    left: 0;
    font-size: 1.2rem;
    line-height: 1.2;
    color: #22c55e;
}

/* 
 * 画像の中央寄せとキャプション
 * 重要: figure要素をブロック要素として扱い、キャプションを本文幅に合わせる
 */
.wp-block-image {
    display: block;           /* インラインブロックではなくブロック要素に */
    width: 100%;              /* 本文の幅に合わせる */
    text-align: center;
    margin: 1.5rem auto;
    overflow: hidden;         /* 画像がはみ出さないように */
}

.wp-block-image img {
    display: inline-block;    /* 画像自体はインラインブロックで中央寄せ */
    margin: 0 auto;
    width: auto;              /* 幅は自動調整 */
    max-width: 100%;          /* コンテナ幅を超えない */
    height: auto;             /* アスペクト比を維持 */
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

/* 幅指定がある画像でもレスポンシブに対応 */
.wp-block-image img[width] {
    width: auto !important;   /* 固定幅を上書き */
    max-width: 100% !important;
    height: auto !important;
}

/* スタイル属性で幅が指定されている場合の対応 */
.wp-block-image img[style*="width"] {
    width: auto !important;
    max-width: 100% !important;
    height: auto !important;
}

/* インラインで最大幅が指定されている場合の処理 */
.wp-block-image img[style*="max-width"] {
    max-width: min(100%, var(--img-max-width)) !important;
}

/* キャプションを本文幅に合わせる */
.wp-block-image figcaption,
.wp-element-caption {
    display: block;           /* ブロック要素として扱う */
    width: 100%;              /* 親要素（figure）の幅いっぱいに */
    max-width: none;          /* 最大幅の制限を解除 */
    margin-top: 0.5rem;
    padding: 0 20px;          /* 左右に適度なパディング */
    font-size: 0.875rem;
    color: #6b7280;
    font-style: italic;
    line-height: 1.6;
    text-align: center;
    word-wrap: break-word;    /* 長い単語の改行を許可 */
}

/* テーブルのスタイル改善 */
.wp-table {
    width: 100%;
    margin: 1rem 0;
    border-collapse: collapse;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
    font-size: 0.9rem;  /* フォントサイズを少し小さく */
}

.wp-table thead {
    background: #f8fafc;
    border-bottom: 2px solid #e5e7eb;
}

.wp-table th {
    padding: 8px 12px;  /* パディングを削減（12px → 8px） */
    font-weight: 600;
    color: #1f2937;
    font-size: 0.875rem;  /* ヘッダーのフォントサイズを小さく */
    text-align: left;
}

.wp-table th[style*="text-align: center"] {
    text-align: center !important;
}

.wp-table th[style*="text-align: right"] {
    text-align: right !important;
}

.wp-table td {
    padding: 8px 12px;  /* パディングを削減（12px → 8px） */
    border-bottom: 1px solid #f3f4f6;
    font-size: 0.9rem;  /* データのフォントサイズ調整 */
    line-height: 1.4;   /* 行間を詰める */
}

.wp-table td[style*="text-align: center"] {
    text-align: center !important;
}

.wp-table td[style*="text-align: right"] {
    text-align: right !important;
}

.wp-table tbody tr:last-child td {
    border-bottom: none;
}

.wp-table tbody tr:hover {
    background: #f9fafb;
}

.wp-table tbody tr:nth-child(even) {
    background: #fcfcfc;
}

/* コンパクトなテーブル用のクラス（オプション） */
.wp-table-compact th,
.wp-table-compact td {
    padding: 6px 10px;
    font-size: 0.85rem;
}

/* モバイル対応 */
@media (max-width: 768px) {
    .wp-table {
        font-size: 0.85rem;
    }
    
    .wp-table th,
    .wp-table td {
        padding: 6px 8px;
    }
}

/* 水平線 */
hr {
    border: none;
    height: 1px;
    background: #e5e7eb;
    margin: 2rem 0;
}

/* 引用ブロック */
blockquote {
    margin: 1.5rem 0;
    padding: 1rem 1.5rem;
    border-left: 4px solid #3b82f6;
    background: #f0f9ff;
    color: #1e40af;
    font-style: italic;
}

blockquote p {
    margin-bottom: 0.5rem;
}

blockquote p:last-child {
    margin-bottom: 0;
}

/* URLカード */
.url-card {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 1.5rem 0;
    padding: 12px;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    text-decoration: none;
    color: #374151;
    transition: all 0.2s ease;
}

/* 連続するURLカードの間隔を調整 */
.url-card + .url-card {
    margin-top: 0.75rem;  /* 通常の1.5remから0.75remに削減 */
}

/* 段落に含まれるURLカードの処理 */
p + .url-card,
.url-card + p {
    margin-top: 1rem;
}

/* URLカード直後の段落の間隔調整 */
.url-card + p:not(:has(.url-card)) {
    margin-top: 1.5rem;
}

.url-card:hover {
    background: #f1f5f9;
    border-color: #cbd5e1;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.url-card-image {
    width: 48px;
    height: 48px;
    background: #e5e7eb;
    border-radius: 6px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.url-card-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.url-card-content {
    flex: 1;
    min-width: 0;
}

.url-card-title {
    font-weight: 600;
    color: #1f2937;
    margin-bottom: 4px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.url-card-description {
    font-size: 0.875rem;
    color: #6b7280;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.url-card-url {
    color: #6b7280;
    font-size: 0.8rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ネストされた引用 */
blockquote blockquote {
    margin: 0.5rem 0;
    padding: 0.5rem 1rem;
    border-left-color: #60a5fa;
    background: #e0f2fe;
}

/* 打ち消し線 */
del {
    text-decoration: line-through;
    color: #6b7280;
    opacity: 0.8;
}

/* スクロールバーのスタイリング */
.code-block-wrapper pre::-webkit-scrollbar {
    height: 8px;
}

.code-block-wrapper pre::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
}

.code-block-wrapper pre::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.3);
    border-radius: 4px;
}

.code-block-wrapper pre::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.5);
}
@media (max-width: 768px) {
    .code-block-wrapper pre {
        padding: 1rem 0.5rem;
    }
    
    .code-line {
        margin: 0 -0.5rem;
        padding: 0 0.5rem;
    }
    
    .line-number {
        width: 2.5rem;
        margin-right: 0.5rem;
        font-size: 0.75rem;
    }
    
    .code-language-label {
        font-size: 0.7rem;
        padding: 3px 8px;
    }
}

/* ダークモードのサポート（必要に応じて） */
@media (prefers-color-scheme: dark) {
    p code,
    li code,
    td code {
        background: #334155;
        color: #fbbf24;
    }
    
    blockquote {
        background: #1e3a8a;
        color: #dbeafe;
        border-left-color: #60a5fa;
    }
    
    blockquote blockquote {
        background: #1e40af;
    }
}