/* Custom Text Copy & Image Download Button Styles */

/* 共通のアクションボタン コンテナ */
.action-button-container {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 0;
    max-width: 100%;
    box-sizing: border-box;
}

/* 画像表示部分 */
.action-image-display {
    flex: 1;
    max-width: 100%;
    text-align: center;
    overflow: hidden;
    max-height: 400px; /* 最大高さを400pxに設定 */
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 0 8px; /* 内側の余白 */
}

.action-image-display img {
    max-width: 100%;
    max-height: 150px;
    width: auto;
    height: auto;
    display: block;
    margin: 0 auto;
    border-radius: 4px;
    object-fit: contain; /* 縦横比を保って画像をコンテナに収める */
}

/* コンテナの位置 */
.action-button-container.center {
    justify-content: center;
    margin: 15px auto;
    max-width: fit-content;
}

.action-button-container.left {
    justify-content: flex-start;
    margin-left: 0;
    margin-right: auto;
}

.action-button-container.right {
    justify-content: flex-end;
    margin-left: auto;
    margin-right: 0;
}

.action-button-container.inline {
    display: inline-flex;
    vertical-align: middle;
}

/* アクションテキスト表示部分（コピーテキストや画像URL表示） */
.action-text-display {
    flex: 1;
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-family: 'Courier New', monospace;
    font-size: 14px;
    background: #fff;
    color: #333;
    word-break: break-all;
    line-height: 1.4;
    min-height: 20px;
    max-width: calc(100% - 20px);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

.action-text-display:hover {
    background: #f8f8f8;
    cursor: default;
}

/* 共通のアクションボタンスタイル */
.custom-action-button {
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.3s ease;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    line-height: 1.4;
    text-align: center;
    outline: none;
    text-decoration: none;
    flex-shrink: 0;
    white-space: nowrap;
}

/* コピーボタン専用スタイル */
.custom-action-button.copy-button {
    background: #71717a;
}

/* ダウンロードボタン専用スタイル */
.custom-action-button.download-button {
    background: #3b82f6;
}

/* ボタンサイズのバリエーション */
.custom-action-button.small {
    padding: 6px 12px;
    font-size: 12px;
    min-width: 80px;
}

.custom-action-button.medium {
    padding: 10px 16px;
    font-size: 14px;
    min-width: 100px;
}

.custom-action-button.large {
    padding: 14px 24px;
    font-size: 16px;
    min-width: 120px;
}

/* ホバー効果 */
.custom-action-button:hover {
    color: #ffffff;
}

/* アクション完了メッセージ */
.action-message {
    position: fixed;
    top: 20px;
    right: 20px;
    padding: 12px 24px;
    border-radius: 12px;
    font-size: 14px;
    font-weight: 500;
    z-index: 1000000;
    animation: slideInOut 2s ease-in-out;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    pointer-events: none;
}

.action-message.success {
    background: #4caf50;
    color: white;
}

.action-message.error {
    background: #f44336;
    color: white;
}

/* メッセージのアニメーション */
@keyframes slideInOut {
    0% {
        opacity: 0;
        transform: translateX(100%);
    }
    20% {
        opacity: 1;
        transform: translateX(0);
    }
    80% {
        opacity: 1;
        transform: translateX(0);
    }
    100% {
        opacity: 0;
        transform: translateX(100%);
    }
}

/* 管理画面でのボタンスタイル */
#insert-action-button {
    margin-left: 5px;
    background: linear-gradient(135deg, #64748b 0%, #475569 100%);
    color: white;
    border: 1px solid #64748b;
    border-radius: 8px;
    padding: 8px 16px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: none;
}

#insert-action-button:hover {
    background: linear-gradient(135deg, #475569 0%, #334155 100%);
    border-color: #475569;
}

/* レスポンシブデザイン - タブレット以下 */
@media (max-width: 768px) {
    .action-button-container {
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
        padding: 0;
    }

    .action-button-container.inline {
        display: flex;
        flex-direction: column;
        vertical-align: top;
    }

    .action-text-display {
        max-width: 100%;
        margin-bottom: 0;
        white-space: normal;
        word-wrap: break-word;
        text-overflow: initial;
        overflow: visible;
        flex: none;
    }

    .action-image-display {
        max-width: 100%;
        max-height: 300px; /* タブレットでは最大高さを300pxに */
        margin-bottom: 0;
        flex: none;
    }

    .action-image-display img {
        max-width: 100%;
        max-height: 100px;
    }

    .custom-action-button {
        width: 100%;
        max-width: 100%;
        min-width: 0;
        flex: none;
    }

    .custom-action-button.small {
        padding: 10px 16px;
        font-size: 14px;
        min-width: 0;
    }

    .custom-action-button.medium {
        padding: 12px 20px;
        font-size: 15px;
        min-width: 0;
    }

    .custom-action-button.large {
        padding: 14px 24px;
        font-size: 16px;
        min-width: 0;
    }

    .action-message {
        font-size: 13px;
        padding: 10px 20px;
        left: 10px;
        right: 10px;
        width: auto;
    }
}

/* レスポンシブデザイン - スマートフォン */
@media (max-width: 480px) {
    .action-button-container {
        padding: 0 10px;
        gap: 8px;
    }

    .action-text-display {
        padding: 10px 12px;
        font-size: 13px;
    }

    .action-image-display {
        padding: 6px;
        max-height: 200px; /* スマートフォンでは最大高さを200pxに */
    }

    .custom-action-button {
        padding: 12px 16px;
        font-size: 14px;
        font-weight: 600;
    }

    .custom-action-button.small {
        padding: 10px 14px;
        font-size: 13px;
    }

    .custom-action-button.medium {
        padding: 12px 18px;
        font-size: 14px;
    }

    .custom-action-button.large {
        padding: 14px 22px;
        font-size: 15px;
    }

    .action-message {
        font-size: 12px;
        padding: 8px 16px;
        top: 10px;
        left: 5px;
        right: 5px;
    }
}

/* ダークモード対応 */
@media (prefers-color-scheme: dark) {
    .action-button-container {
        background: #2d3748;
        border-color: #4a5568;
    }

    .action-text-display {
        background: #1a202c;
        border-color: #4a5568;
        color: #e2e8f0;
    }

    .action-text-display:hover {
        background: #2d3748;
    }

    .action-image-display {
        background: #1a202c;
        border-color: #4a5568;
    }

    .custom-action-button.copy-button {
        background: #1e293b;
    }

    .custom-action-button.copy-button:hover {
        background: #334155;
    }

    .custom-action-button.download-button {
        background: #1e40af;
    }

    .custom-action-button.download-button:hover {
        background: #1d4ed8;
    }
}

/* 印刷時は非表示 */
@media print {
    .action-button-container,
    .custom-action-button,
    .action-message {
        display: none !important;
    }
}

/* テキスト選択を無効化（右クリック禁止サイト用） */
.action-button-container,
.action-text-display,
.action-image-display,
.custom-action-button {
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
    -webkit-tap-highlight-color: transparent;
}

/* アクセシビリティ */
.custom-action-button:focus-visible {
    outline: 2px solid #005cbb;
    outline-offset: 2px;
}

/* 特定の状況での表示調整 */
.custom-action-button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.custom-action-button:disabled:hover {
    transform: none;
}

/* 後方互換性のために古いクラス名も残す */
.copy-button-container {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 0;
    max-width: 100%;
    box-sizing: border-box;
}

.copy-button-container.center {
    justify-content: center;
    margin: 15px auto;
    max-width: fit-content;
}

.copy-button-container.left {
    justify-content: flex-start;
    margin-left: 0;
    margin-right: auto;
}

.copy-button-container.right {
    justify-content: flex-end;
    margin-left: auto;
    margin-right: 0;
}

.copy-button-container.inline {
    display: inline-flex;
    vertical-align: middle;
}

.copy-text-display {
    flex: 1;
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-family: 'Courier New', monospace;
    font-size: 14px;
    background: #fff;
    color: #333;
    word-break: break-all;
    line-height: 1.4;
    min-height: 20px;
    max-width: calc(100% - 20px);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

.copy-text-display:hover {
    background: #f8f8f8;
    cursor: default;
}

.custom-copy-button {
    background: #71717a;
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.3s ease;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    line-height: 1.4;
    text-align: center;
    outline: none;
    text-decoration: none;
    flex-shrink: 0;
    white-space: nowrap;
}

.custom-copy-button.small {
    padding: 6px 12px;
    font-size: 12px;
    min-width: 80px;
}

.custom-copy-button.medium {
    padding: 10px 16px;
    font-size: 14px;
    min-width: 100px;
}

.custom-copy-button.large {
    padding: 14px 24px;
    font-size: 16px;
    min-width: 120px;
}

.custom-copy-button:hover {
    color: #dddddf;
}

.custom-copy-button:focus {
    outline: 2px solid #ffffff;
    outline-offset: 2px;
}

.copy-message {
    position: fixed;
    top: 20px;
    right: 20px;
    padding: 12px 24px;
    border-radius: 12px;
    font-size: 14px;
    font-weight: 500;
    z-index: 1000000;
    animation: slideInOut 2s ease-in-out;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    pointer-events: none;
}

.copy-message.success {
    background: #4caf50;
    color: white;
}

.copy-message.error {
    background: #f44336;
    color: white;
}

#insert-copy-button {
    margin-left: 5px;
}

/* 後方互換性のために古いクラス名もレスポンシブ対応 */
@media (max-width: 768px) {
    .copy-button-container {
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
        padding: 0;
    }

    .copy-button-container.inline {
        display: flex;
        flex-direction: column;
        vertical-align: top;
    }

    .copy-text-display {
        max-width: 100%;
        margin-bottom: 0;
        white-space: normal;
        word-wrap: break-word;
        text-overflow: initial;
        overflow: visible;
        flex: none;
    }

    .custom-copy-button {
        width: 100%;
        max-width: 100%;
        min-width: 0;
        flex: none;
    }

    .custom-copy-button.small {
        padding: 10px 16px;
        font-size: 14px;
        min-width: 0;
    }

    .custom-copy-button.medium {
        padding: 12px 20px;
        font-size: 15px;
        min-width: 0;
    }

    .custom-copy-button.large {
        padding: 14px 24px;
        font-size: 16px;
        min-width: 0;
    }
}

@media (max-width: 480px) {
    .copy-button-container {
        padding: 0 10px;
        gap: 8px;
    }

    .copy-text-display {
        padding: 10px 12px;
        font-size: 13px;
    }

    .custom-copy-button {
        padding: 12px 16px;
        font-size: 14px;
        font-weight: 600;
    }

    .custom-copy-button.small {
        padding: 10px 14px;
        font-size: 13px;
    }

    .custom-copy-button.medium {
        padding: 12px 18px;
        font-size: 14px;
    }

    .custom-copy-button.large {
        padding: 14px 22px;
        font-size: 15px;
    }
}
