/**
 * AI Mindmap Generator - Frontend Styles（修正版）
 * ノード選択とテキスト表示問題を解決
 */

/* ==========================================================================
   マインドマップコンテナ
   ========================================================================== */

.aimm-mindmap-container {
    position: relative;
    background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
    border: 1px solid #ddd;
    border-radius: 8px;
    overflow: hidden;
    width: 100%;
    min-height: 600px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.1);
}

.aimm-mindmap-canvas {
    width: 100%;
    height: 100%;
    background: white;
    min-height: 600px;
}

/* ==========================================================================
   コントロール
   ========================================================================== */

.aimm-mindmap-controls {
    position: absolute;
    top: 10px;
    right: 10px;
    display: flex;
    gap: 5px;
    z-index: 100;
}

.aimm-mindmap-controls button {
    width: 40px;
    height: 40px;
    border: none;
    background: rgba(255, 255, 255, 0.95);
    border-radius: 50%;
    cursor: pointer;
    font-size: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

.aimm-mindmap-controls button:hover {
    background: #ff6b00;
    color: white;
    transform: scale(1.1);
    box-shadow: 0 4px 20px rgba(255, 107, 0, 0.4);
}

/* ==========================================================================
   エディターコンテナ
   ========================================================================== */

.aimm-editor-container {
    position: relative;
    background: #f8f9fa;
    border: 1px solid #dee2e6;
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    width: 100%;
    max-width: 100%;
    margin: 0 auto;
    min-height: 800px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.08);
}

/* ==========================================================================
   ツールバー
   ========================================================================== */

.aimm-editor-toolbar {
    display: flex;
    gap: 10px;
    padding: 15px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-bottom: none;
    flex-wrap: wrap;
    width: 100%;
    box-sizing: border-box;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

.aimm-toolbar-group {
    display: flex;
    gap: 5px;
    align-items: center;
    padding: 0 10px;
    border-right: 1px solid rgba(255, 255, 255, 0.2);
}

.aimm-toolbar-group:last-child {
    border-right: none;
}

/* ==========================================================================
   ボタン
   ========================================================================== */

.aimm-btn {
    padding: 10px 16px;
    border: none;
    background: rgba(255, 255, 255, 0.95);
    border-radius: 25px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: all 0.3s;
    white-space: nowrap;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}

.aimm-btn:hover {
    background: #ff6b00;
    color: white;
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(255, 107, 0, 0.3);
}

.aimm-btn .dashicons {
    width: 16px;
    height: 16px;
    font-size: 16px;
}

/* ==========================================================================
   エディターキャンバス
   ========================================================================== */

.aimm-editor-canvas {
    flex: 1;
    background: white;
    position: relative;
    overflow: auto;
    width: 100%;
    min-height: 700px;
    box-sizing: border-box;
}

/* ==========================================================================
   SVGスタイル - ノード選択とテキスト表示の修正
   ========================================================================== */

/* リンク */
.link {
    fill: none;
    stroke: #ccc;
    stroke-width: 2px;
    opacity: 0.6;
    transition: all 0.3s;
}

/* ノードグループ */
.node {
    cursor: pointer;
    transition: all 0.3s;
}

/* ノードの矩形（重要：テキストのはみ出し防止） */
.node rect {
    fill: #4CAF50;
    stroke: white;
    stroke-width: 2px;
    rx: 10;
    ry: 10;
    transition: all 0.3s;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.1));
}

/* ノードのホバー効果 */
.node:hover rect {
    filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.2));
    transform: scale(1.05);
}

/* 選択されたノード - IDベースの選択 */
.node.selected rect,
.node[data-selected="true"] rect {
    fill: #ff6b00 !important;
    stroke: #ff3300 !important;
    stroke-width: 3px !important;
    filter: drop-shadow(0 4px 12px rgba(255, 107, 0, 0.4));
}

/* データ属性による選択状態 */
g[data-node-selected="true"] rect {
    fill: #ff6b00 !important;
    stroke: #ff3300 !important;
    stroke-width: 3px !important;
}

/* ノードのテキスト */
.node text {
    font-size: 14px;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    pointer-events: none;
    fill: white;
    font-weight: 500;
    text-anchor: middle;
    dominant-baseline: middle;
}

/* テキストの折り返し処理 */
.node text tspan {
    x: 0;
    text-anchor: middle;
}

/* 深さによるノードスタイル */
.node.depth-0 rect {
    fill: #4CAF50;
}

.node.depth-1 rect {
    fill: #2196F3;
}

.node.depth-2 rect {
    fill: #9C27B0;
}

.node.depth-3 rect {
    fill: #607D8B;
}

/* ==========================================================================
   サイドパネル
   ========================================================================== */

.aimm-editor-sidepanel {
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    width: 320px;
    background: white;
    border-left: 1px solid #dee2e6;
    box-shadow: -2px 0 10px rgba(0, 0, 0, 0.1);
    z-index: 200;
    transform: translateX(0);
    transition: transform 0.3s ease;
}

.aimm-editor-sidepanel.collapsed {
    transform: translateX(100%);
}

.aimm-sidepanel-header {
    padding: 20px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.aimm-sidepanel-header h3 {
    margin: 0;
    font-size: 16px;
    color: white;
}

.aimm-sidepanel-close {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.3s;
    color: white;
}

.aimm-sidepanel-close:hover {
    transform: rotate(90deg);
}

.aimm-sidepanel-content {
    padding: 20px;
}

.aimm-field {
    margin-bottom: 20px;
}

.aimm-field label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
    font-size: 14px;
    color: #495057;
}

.aimm-field input[type="text"],
.aimm-field textarea {
    width: 100%;
    padding: 10px;
    border: 2px solid #e9ecef;
    border-radius: 8px;
    font-size: 14px;
    box-sizing: border-box;
    transition: all 0.3s;
}

.aimm-field input[type="text"]:focus,
.aimm-field textarea:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.aimm-field textarea {
    min-height: 100px;
    resize: vertical;
}

/* ==========================================================================
   ステータスバー
   ========================================================================== */

.aimm-editor-statusbar {
    padding: 12px 20px;
    background: #f8f9fa;
    border-top: 1px solid #dee2e6;
    display: flex;
    justify-content: space-between;
    font-size: 13px;
    color: #6c757d;
}

/* ==========================================================================
   ローディング
   ========================================================================== */

.aimm-loading {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: white;
    padding: 30px 50px;
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
    z-index: 1000;
    font-size: 16px;
    font-weight: 500;
    color: #333;
    display: flex;
    align-items: center;
    gap: 15px;
}

.aimm-loading::before {
    content: '';
    display: inline-block;
    width: 30px;
    height: 30px;
    border: 3px solid #f3f3f3;
    border-top: 3px solid #ff6b00;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

/* ==========================================================================
   メッセージ
   ========================================================================== */

.aimm-message {
    position: fixed;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%);
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 15px 30px;
    border-radius: 30px;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.2);
    z-index: 1000;
    font-size: 14px;
    font-weight: 500;
    opacity: 0;
    transition: all 0.3s;
    animation: slideUp 0.5s forwards;
}

@keyframes slideUp {
    from {
        transform: translateX(-50%) translateY(20px);
        opacity: 0;
    }
    to {
        transform: translateX(-50%) translateY(0);
        opacity: 1;
    }
}

.aimm-message.show {
    opacity: 1;
}

/* ==========================================================================
   ダイアログ
   ========================================================================== */

.aimm-mindmap-list {
    padding: 0;
}

.aimm-mindmap-list h3 {
    margin: 0 0 20px 0;
    color: #333;
    font-size: 18px;
}

.aimm-mindmap-list ul {
    list-style: none;
    padding: 0;
    margin: 0;
    max-height: 400px;
    overflow-y: auto;
}

.aimm-mindmap-list li {
    padding: 15px;
    border-bottom: 1px solid #e9ecef;
    cursor: pointer;
    transition: all 0.3s;
    background: white;
}

.aimm-mindmap-list li:hover {
    background: linear-gradient(135deg, rgba(102, 126, 234, 0.1) 0%, rgba(118, 75, 162, 0.1) 100%);
    padding-left: 20px;
}

.aimm-mindmap-list li:last-child {
    border-bottom: none;
}

.aimm-mindmap-list li strong {
    display: block;
    margin-bottom: 5px;
    color: #333;
    font-size: 15px;
}

.aimm-mindmap-list li small {
    color: #6c757d;
    font-size: 12px;
}

/* ==========================================================================
   jQuery UIダイアログのカスタマイズ
   ========================================================================== */

.ui-dialog {
    border-radius: 12px !important;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15) !important;
}

.ui-dialog-titlebar {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important;
    color: white !important;
    border: none !important;
    border-radius: 12px 12px 0 0 !important;
    padding: 15px 20px !important;
}

.ui-dialog-title {
    color: white !important;
    font-size: 16px !important;
    font-weight: 500 !important;
}

.ui-dialog-titlebar-close {
    background: none !important;
    border: none !important;
    color: white !important;
    opacity: 0.8 !important;
}

.ui-dialog-titlebar-close:hover {
    opacity: 1 !important;
}

.ui-dialog-content {
    padding: 20px !important;
}

.ui-dialog-buttonpane {
    background: #f8f9fa !important;
    border-top: 1px solid #dee2e6 !important;
    padding: 15px 20px !important;
}

.ui-dialog-buttonset button {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important;
    color: white !important;
    border: none !important;
    border-radius: 25px !important;
    padding: 10px 25px !important;
    font-weight: 500 !important;
    cursor: pointer !important;
    transition: all 0.3s !important;
}

.ui-dialog-buttonset button:hover {
    transform: translateY(-2px) !important;
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.3) !important;
}

/* ==========================================================================
   エラーメッセージ
   ========================================================================== */

.mindmap-error {
    padding: 20px;
    background: linear-gradient(135deg, #fc5c7d 0%, #ff6b6b 100%);
    border: none;
    border-radius: 8px;
    color: white;
    margin: 20px 0;
    text-align: center;
    font-weight: 500;
    box-shadow: 0 4px 15px rgba(252, 92, 125, 0.3);
}

/* ==========================================================================
   空の状態
   ========================================================================== */

.aimm-empty-state {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: #adb5bd;
    font-size: 18px;
    padding: 40px;
    text-align: center;
    flex-direction: column;
}

.aimm-empty-state::before {
    content: '📊';
    font-size: 48px;
    margin-bottom: 20px;
}

/* ==========================================================================
   エクスポート形式選択
   ========================================================================== */

.aimm-export-format {
    margin-left: 5px;
    padding: 8px 15px;
    border: none;
    border-radius: 25px;
    background: white;
    cursor: pointer;
    font-size: 14px;
    transition: all 0.3s;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}

.aimm-export-format:focus {
    outline: none;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.2);
}

/* ==========================================================================
   AIプロバイダー選択
   ========================================================================== */

.aimm-ai-provider {
    padding: 8px 15px;
    border: none;
    border-radius: 25px;
    background: white;
    cursor: pointer;
    font-size: 14px;
    transition: all 0.3s;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
    margin-right: 5px;
}

.aimm-ai-provider:focus {
    outline: none;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.2);
}

/* ==========================================================================
   レスポンシブ対応
   ========================================================================== */

@media (max-width: 1200px) {
    .aimm-editor-sidepanel {
        width: 280px;
    }
}

@media (max-width: 768px) {
    .aimm-editor-toolbar {
        flex-direction: column;
        gap: 10px;
        padding: 10px;
    }
    
    .aimm-toolbar-group {
        border-right: none;
        border-bottom: 1px solid rgba(255, 255, 255, 0.2);
        padding: 8px 0;
        width: 100%;
        justify-content: center;
        flex-wrap: wrap;
    }
    
    .aimm-toolbar-group:last-child {
        border-bottom: none;
    }
    
    .aimm-editor-sidepanel {
        width: 100%;
        position: fixed;
        height: 50%;
        top: auto;
        bottom: 0;
        border-left: none;
        border-top: 1px solid #dee2e6;
    }
    
    .aimm-editor-canvas {
        min-height: 500px;
    }
    
    .aimm-btn {
        padding: 8px 12px;
        font-size: 13px;
    }
}

@media (max-width: 480px) {
    .aimm-btn {
        padding: 6px 10px;
        font-size: 12px;
    }
    
    .aimm-mindmap-controls button {
        width: 35px;
        height: 35px;
        font-size: 14px;
    }
    
    .node text {
        font-size: 12px;
    }
    
    .aimm-editor-toolbar {
        padding: 8px;
    }
}

/* ==========================================================================
   フルスクリーン
   ========================================================================== */

.aimm-mindmap-container:fullscreen,
.aimm-editor-container:fullscreen {
    background: white;
    padding: 0;
    margin: 0;
    width: 100vw;
    height: 100vh;
    max-width: 100vw;
}

.aimm-mindmap-container:fullscreen .aimm-mindmap-canvas,
.aimm-editor-container:fullscreen .aimm-editor-canvas {
    height: calc(100vh - 100px);
}

/* ==========================================================================
   印刷用スタイル
   ========================================================================== */

@media print {
    .aimm-editor-toolbar,
    .aimm-mindmap-controls,
    .aimm-editor-statusbar,
    .aimm-editor-sidepanel {
        display: none !important;
    }
    
    .aimm-editor-canvas {
        border: none;
        box-shadow: none;
    }
}

/* ==========================================================================
   アニメーション
   ========================================================================== */

@keyframes fadeIn {
    from { 
        opacity: 0;
        transform: translateY(10px);
    }
    to { 
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes pulse {
    0% {
        box-shadow: 0 0 0 0 rgba(255, 107, 0, 0.7);
    }
    70% {
        box-shadow: 0 0 0 10px rgba(255, 107, 0, 0);
    }
    100% {
        box-shadow: 0 0 0 0 rgba(255, 107, 0, 0);
    }
}

.aimm-mindmap-container,
.aimm-editor-container {
    animation: fadeIn 0.5s ease-in;
}

/* 選択されたノードのパルスアニメーション */
.node.selected rect,
.node[data-selected="true"] rect {
    animation: pulse 2s infinite;
}

/* ==========================================================================
   ガイド表示
   ========================================================================== */

.close-guide {
    background: linear-gradient(135deg, #ff6b00 0%, #ff8e53 100%);
    color: white;
    border: none;
    padding: 8px 20px;
    border-radius: 25px;
    cursor: pointer;
    width: 100%;
    font-weight: 500;
    transition: all 0.3s;
    margin-top: 15px;
}

.close-guide:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(255, 107, 0, 0.3);
}

/* ==========================================================================
   アクセシビリティ
   ========================================================================== */

.aimm-btn:focus,
.aimm-mindmap-controls button:focus {
    outline: 3px solid #ff6b00;
    outline-offset: 2px;
}

/* ハイコントラストモード対応 */
@media (prefers-contrast: high) {
    .node rect {
        stroke-width: 3px;
    }
    
    .aimm-btn {
        border: 2px solid currentColor;
    }
}

/* ダークモード対応 */
@media (prefers-color-scheme: dark) {
    .aimm-editor-container {
        background: #1a1a1a;
        border-color: #333;
    }
    
    .aimm-editor-canvas {
        background: #2a2a2a;
    }
    
    .aimm-editor-statusbar {
        background: #1a1a1a;
        border-color: #333;
        color: #aaa;
    }
}