/* ===================================
   勵馨家系圖生成器 - 樣式表
   =================================== */

:root {
    /* 主題色彩 */
    --primary-color: #4a90d9;
    --primary-hover: #357abd;
    --primary-light: #e8f2fc;
    --secondary-color: #6c757d;
    --danger-color: #dc3545;
    --success-color: #28a745;

    /* 背景與邊框 */
    --bg-dark: #1e2530;
    --bg-medium: #2a3441;
    --bg-light: #f8f9fa;
    --bg-canvas: #ffffff;
    --border-color: #dee2e6;
    --border-light: #e9ecef;

    /* 文字顏色 */
    --text-primary: #212529;
    --text-secondary: #6c757d;
    --text-light: #ffffff;
    --text-muted: #adb5bd;

    /* 關係線條顏色 */
    --color-married: #6b66ff;
    --color-engaged: #6b66ff;
    --color-cohabiting: #4caf50;
    --color-separated: #fec107;
    --color-divorced: #f44336;
    --color-positive: #4caf50;
    --color-close: #4caf50;
    /* 親密 - 綠色 */
    --color-very-close: #4caf50;
    /* 過度親密 - 綠色 */
    --color-distant: #9e9e9e;
    --color-conflict: #f44336;
    --color-hostile: #ff9800;
    /* 敵對/惡化 - 橙色 */
    --color-cutoff: #333333;
    --color-abuse: #4a90d9;
    /* 虐待 - 藍色 */
    --color-manipulative: #fd7e14;
    /* 操控 - 橙色 */
    --color-controlling: #dc3545;
    /* 控制 - 紅色 */
    --color-focused: #4a90d9;
    /* 關注 - 藍色 */
    --color-admiration: #28a745;
    /* 崇拜 - 綠色 */
    --color-indifferent: #9e9e9e;
    /* 冷漠 - 灰色 */

    /* 間距與尺寸 */
    --toolbar-height: 60px;
    --panel-width: 280px;
    --border-radius: 8px;
    --border-radius-sm: 4px;

    /* 陰影 */
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.1);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.15);
    --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.2);

    /* 過渡動畫 */
    --transition-fast: 0.15s ease;
    --transition-normal: 0.25s ease;
}

/* ===================================
   基礎重置
   =================================== */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html,
body {
    height: 100%;
    overflow: hidden;
}

body {
    font-family: 'Noto Sans TC', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    font-size: 14px;
    color: var(--text-primary);
    background-color: var(--bg-light);
    line-height: 1.5;
}

/* ===================================
   應用程式容器
   =================================== */
.app-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

/* ===================================
   頂部工具列
   =================================== */
.toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: var(--toolbar-height);
    padding: 0 16px;
    background: linear-gradient(135deg, var(--bg-dark) 0%, var(--bg-medium) 100%);
    box-shadow: var(--shadow-md);
    z-index: 100;
}

.toolbar-left,
.toolbar-center,
.toolbar-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

.app-title {
    font-size: 18px;
    font-weight: 700;
    color: var(--text-light);
    letter-spacing: 1px;
}

.tool-group {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 4px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: var(--border-radius);
}

.tool-divider {
    width: 1px;
    height: 32px;
    background: rgba(255, 255, 255, 0.2);
    margin: 0 8px;
}

.tool-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-width: 56px;
    padding: 6px 10px;
    background: transparent;
    border: none;
    border-radius: var(--border-radius-sm);
    color: var(--text-light);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.tool-btn:hover {
    background: rgba(255, 255, 255, 0.15);
}

.tool-btn:active {
    transform: scale(0.95);
}

.tool-btn.active {
    background: var(--primary-color);
}

.tool-btn.primary {
    background: var(--primary-color);
}

.tool-btn.primary:hover {
    background: var(--primary-hover);
}

.tool-btn .icon {
    font-size: 18px;
    margin-bottom: 2px;
}

.tool-btn .tool-label {
    font-size: 11px;
    opacity: 0.9;
}

/* 人物圖示 */
.male-icon {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid currentColor;
    background: transparent;
}

.female-icon {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid currentColor;
    border-radius: 50%;
    background: transparent;
}

.same-icon {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid currentColor;
    border-radius: 50% 50% 0 0;
    background: transparent;
}

/* ===================================
   主要內容區
   =================================== */
.main-content {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* ===================================
   畫布區域
   =================================== */
.canvas-container {
    flex: 1;
    position: relative;
    background-color: var(--bg-canvas);
    background-image:
        linear-gradient(rgba(0, 0, 0, 0.03) 1px, transparent 1px),
        linear-gradient(90deg, rgba(0, 0, 0, 0.03) 1px, transparent 1px);
    background-size: 20px 20px;
    overflow: hidden;
}

#genogramCanvas {
    display: block;
    cursor: default;
}

/* 狀態提示條 */
.status-bar {
    position: absolute;
    top: 10px;
    left: 50%;
    transform: translateX(-50%);
    padding: 8px 20px;
    background: rgba(0, 0, 0, 0.8);
    color: #fff;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 500;
    z-index: 10;
    transition: all var(--transition-fast);
    pointer-events: none;
    white-space: normal;
    width: auto;
    min-width: 200px;
    max-width: 80%;
    text-align: center;
    line-height: 1.4;
}

.status-bar.connecting {
    background: var(--primary-color);
}

.status-bar.success {
    background: var(--success-color);
}

.status-bar.error {
    background: var(--danger-color);
}

.status-bar.hidden {
    display: none !important;
}

/* 縮放控制 */
.zoom-controls {
    position: absolute;
    bottom: 20px;
    left: 20px;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: rgba(255, 255, 255, 0.95);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-md);
}

.zoom-btn {
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-light);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-sm);
    cursor: pointer;
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
    transition: all var(--transition-fast);
}

.zoom-btn:hover {
    background: var(--primary-light);
    border-color: var(--primary-color);
}

.zoom-level {
    min-width: 48px;
    text-align: center;
    font-size: 12px;
    font-weight: 500;
    color: var(--text-secondary);
}

/* [NEW - G 方案] 自動排列預覽確認浮動欄 */
.layout-preview-bar {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 12px 20px;
    background: linear-gradient(135deg, var(--primary-color) 0%, #357abd 100%);
    border-radius: 30px;
    box-shadow: var(--shadow-lg);
    z-index: 100;
    animation: slideUp 0.3s ease;
}

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

    to {
        transform: translateX(-50%) translateY(0);
        opacity: 1;
    }
}

.layout-preview-bar .preview-message {
    color: white;
    font-size: 14px;
    font-weight: 500;
}

.layout-preview-bar .preview-actions {
    display: flex;
    gap: 8px;
}

.layout-preview-bar .btn-apply {
    padding: 8px 16px;
    background: white;
    color: var(--primary-color);
    border: none;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.layout-preview-bar .btn-apply:hover {
    background: var(--primary-light);
    transform: scale(1.05);
}

.layout-preview-bar .btn-cancel-preview {
    padding: 8px 16px;
    background: transparent;
    color: white;
    border: 2px solid rgba(255, 255, 255, 0.5);
    border-radius: 20px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.layout-preview-bar .btn-cancel-preview:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: white;
}

/* ===================================
   右側面板
   =================================== */
.side-panel {
    width: var(--panel-width);
    background: var(--bg-light);
    border-left: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}

.panel-section {
    border-bottom: 1px solid var(--border-color);
}

.panel-title {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    background: var(--bg-canvas);
    cursor: pointer;
    user-select: none;
}

.panel-title .toggle-icon {
    font-size: 10px;
    transition: transform var(--transition-fast);
}

.panel-section.collapsed .toggle-icon {
    transform: rotate(-90deg);
}

.panel-section.collapsed .panel-content {
    display: none;
}

.panel-content {
    padding: 16px;
}

.empty-hint {
    color: var(--text-muted);
    font-size: 13px;
    text-align: center;
    padding: 20px 0;
}

/* 屬性表單 */
.property-form {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.form-group label {
    font-size: 12px;
    font-weight: 500;
    color: var(--text-secondary);
}

.form-group input,
.form-group select {
    padding: 8px 12px;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-sm);
    font-size: 14px;
    transition: border-color var(--transition-fast);
}

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--primary-color);
}

.form-group-row {
    display: flex;
    gap: 12px;
}

.form-group-row .form-group {
    flex: 1;
}

.checkbox-group {
    display: flex;
    align-items: center;
    gap: 8px;
}

.checkbox-group input[type="checkbox"] {
    width: 16px;
    height: 16px;
    cursor: pointer;
}

.checkbox-group label {
    cursor: pointer;
}

/* ===================================
   關係圖例
   =================================== */
.legend-content {
    padding: 12px 16px;
}

.legend-category {
    margin-bottom: 16px;
}

.legend-category:last-child {
    margin-bottom: 0;
}

.legend-category h4 {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 8px;
    padding-bottom: 4px;
    border-bottom: 1px solid var(--border-light);
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 4px 0;
    font-size: 13px;
}

/* ===================================
   關係圖例線條樣式
   =================================== */

.legend-line {
    display: inline-block;
    width: 40px;
    height: 2px;
    position: relative;
    background-repeat: no-repeat;
    background-position: center;
    background-size: contain;
}

/* --- 家庭關係 --- */
.legend-line.married {
    background: #000;
    height: 2px;
}

.legend-line.parent-child {
    background: #000;
    height: 2px;
}

.legend-line.engaged {
    /* 訂婚：長虛線 (12px線段, 6px間隔) */
    background: repeating-linear-gradient(90deg, #000 0, #000 12px, transparent 12px, transparent 18px);
    height: 2px;
}

.legend-line.cohabiting {
    /* 同居：短點線 (2px線段, 6px間隔) - 與訂婚明顯區分 */
    background: repeating-linear-gradient(90deg, #000 0, #000 2px, transparent 2px, transparent 8px);
    height: 2px;
}

.legend-line.legal-cohabiting {
    height: 8px;
    /* 法律同居：短點線 + 房屋圖示 */
    background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='40' height='8'%3E%3Cline x1='0' y1='6' x2='15' y2='6' stroke='black' stroke-width='2' stroke-dasharray='2,6'/%3E%3Cline x1='25' y1='6' x2='40' y2='6' stroke='black' stroke-width='2' stroke-dasharray='2,6'/%3E%3Cpath d='M16,6 L20,2 L24,6' fill='none' stroke='black' stroke-width='2'/%3E%3Crect x='17' y='6' width='6' height='4' fill='none' stroke='black' stroke-width='1.5'/%3E%3C/svg%3E") no-repeat center;
}

.legend-line.separated {
    height: 8px;
    background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='40' height='10'%3E%3Cline x1='0' y1='5' x2='40' y2='5' stroke='black' stroke-width='2'/%3E%3Cline x1='18' y1='8' x2='22' y2='2' stroke='black' stroke-width='2'/%3E%3C/svg%3E") no-repeat center;
}

.legend-line.legal-separated {
    height: 8px;
    background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='40' height='10'%3E%3Cline x1='0' y1='5' x2='40' y2='5' stroke='black' stroke-width='2'/%3E%3Cline x1='16' y1='8' x2='20' y2='2' stroke='black' stroke-width='2'/%3E%3Cline x1='21' y1='8' x2='25' y2='2' stroke='black' stroke-width='2'/%3E%3C/svg%3E") no-repeat center;
}

.legend-line.divorced {
    height: 10px;
    background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='40' height='10'%3E%3Cline x1='0' y1='5' x2='40' y2='5' stroke='black' stroke-width='2'/%3E%3Cline x1='16' y1='8' x2='20' y2='2' stroke='black' stroke-width='2'/%3E%3Cline x1='21' y1='8' x2='25' y2='2' stroke='black' stroke-width='2'/%3E%3C/svg%3E") no-repeat center;
}

.legend-line.widowed {
    height: 10px;
    background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='40' height='10'%3E%3Cline x1='0' y1='5' x2='40' y2='5' stroke='black' stroke-width='2'/%3E%3Cline x1='18' y1='2' x2='22' y2='8' stroke='black' stroke-width='2'/%3E%3Cline x1='22' y1='2' x2='18' y2='8' stroke='black' stroke-width='2'/%3E%3C/svg%3E") no-repeat center;
}

.legend-line.affair {
    background: repeating-linear-gradient(90deg, #E53935 0, #E53935 6px, transparent 6px, transparent 10px);
    height: 2px;
}

/* --- 情感關係 (正向) --- */
.legend-line.harmony {
    background: #28a745;
    height: 2px;
}

.legend-line.love {
    height: 10px;
    background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='40' height='10'%3E%3Cline x1='0' y1='5' x2='40' y2='5' stroke='%2328a745' stroke-width='2'/%3E%3Ccircle cx='20' cy='5' r='3' stroke='%2328a745' stroke-width='2' fill='white'/%3E%3C/svg%3E") no-repeat center;
}

.legend-line.in-love {
    height: 10px;
    background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='40' height='10'%3E%3Cline x1='0' y1='5' x2='15' y2='5' stroke='%2328a745' stroke-width='2'/%3E%3Cline x1='25' y1='5' x2='40' y2='5' stroke='%2328a745' stroke-width='2'/%3E%3Ccircle cx='17' cy='5' r='3' stroke='%2328a745' stroke-width='2' fill='none'/%3E%3Ccircle cx='23' cy='5' r='3' stroke='%2328a745' stroke-width='2' fill='none'/%3E%3C/svg%3E") no-repeat center;
}

.legend-line.close {
    height: 6px;
    background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='40' height='6'%3E%3Cline x1='0' y1='1' x2='40' y2='1' stroke='%2328a745' stroke-width='2'/%3E%3Cline x1='0' y1='5' x2='40' y2='5' stroke='%2328a745' stroke-width='2'/%3E%3C/svg%3E") no-repeat center;
}

.legend-line.very-close {
    height: 10px;
    background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='40' height='10'%3E%3Cline x1='0' y1='1' x2='40' y2='1' stroke='%2328a745' stroke-width='2'/%3E%3Cline x1='0' y1='5' x2='40' y2='5' stroke='%2328a745' stroke-width='2'/%3E%3Cline x1='0' y1='9' x2='40' y2='9' stroke='%2328a745' stroke-width='2'/%3E%3C/svg%3E") no-repeat center;
}

.legend-line.admiration {
    height: 12px;
    background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='40' height='12'%3E%3Cline x1='0' y1='6' x2='40' y2='6' stroke='%23333333' stroke-width='2'/%3E%3Ccircle cx='20' cy='6' r='3' stroke='%23333333' stroke-width='2' fill='white'/%3E%3Cpath d='M34,2 L38,6 L34,10' stroke='%23333333' stroke-width='2' fill='none'/%3E%3C/svg%3E") no-repeat center;
}

.legend-line.focused {
    height: 12px;
    background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='40' height='12'%3E%3Cline x1='0' y1='6' x2='38' y2='6' stroke='%23333333' stroke-width='2'/%3E%3Cpath d='M32,2 L38,6 L32,10' fill='%23333333'/%3E%3C/svg%3E") no-repeat center;
}

/* --- 情感關係 (負向) --- */
.legend-line.indifferent {
    background: repeating-linear-gradient(90deg, #dc3545 0, #dc3545 4px, transparent 4px, transparent 8px);
    height: 2px;
}

.legend-line.distant {
    background: repeating-linear-gradient(90deg, #333 0, #333 4px, transparent 4px, transparent 8px);
    height: 2px;
}

.legend-line.distant::after {
    /* 兩個黑色雙豎線代表疏離 */
    content: '';
    position: absolute;
    left: 45%;
    top: -3px;
    width: 2px;
    height: 8px;
    background: transparent;
    /* 這裡比較難單純用CSS畫出兩個垂直線疊在虛線上 */
}

/* 改用 SVG 畫 Distant (虛線+兩個豎線) */
.legend-line.distant {
    height: 10px;
    background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='40' height='10'%3E%3Cline x1='0' y1='5' x2='40' y2='5' stroke='%23333' stroke-width='1.5' stroke-dasharray='4,4'/%3E%3Cline x1='18' y1='2' x2='18' y2='8' stroke='%23333' stroke-width='1.5'/%3E%3Cline x1='22' y1='2' x2='22' y2='8' stroke='%23333' stroke-width='1.5'/%3E%3C/svg%3E") no-repeat center;
}


.legend-line.cutoff {
    height: 10px;
    background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='40' height='10'%3E%3Cline x1='0' y1='5' x2='16' y2='5' stroke='%23E53935' stroke-width='1.5' stroke-dasharray='4,4'/%3E%3Cline x1='24' y1='5' x2='40' y2='5' stroke='%23E53935' stroke-width='1.5' stroke-dasharray='4,4'/%3E%3Cline x1='18' y1='1' x2='18' y2='9' stroke='%23E53935' stroke-width='2'/%3E%3Cline x1='22' y1='1' x2='22' y2='9' stroke='%23E53935' stroke-width='2'/%3E%3C/svg%3E") no-repeat center;
}

.legend-line.conflict {
    height: 8px;
    background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='40' height='8'%3E%3Cline x1='0' y1='2' x2='40' y2='2' stroke='%23E53935' stroke-width='2'/%3E%3Cline x1='0' y1='6' x2='40' y2='6' stroke='%23E53935' stroke-width='2'/%3E%3C/svg%3E") no-repeat center;
}

.legend-line.hate {
    height: 10px;
    background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='40' height='10'%3E%3Cline x1='0' y1='2' x2='40' y2='2' stroke='%23E53935' stroke-width='2'/%3E%3Cline x1='0' y1='5' x2='40' y2='5' stroke='%23E53935' stroke-width='2'/%3E%3Cline x1='0' y1='8' x2='40' y2='8' stroke='%23E53935' stroke-width='2'/%3E%3C/svg%3E") no-repeat center;
}

.legend-line.hostile {
    height: 10px;
    background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='40' height='10'%3E%3Cpath d='M0,5 Q2.5,1 5,5 T10,5 T15,5 T20,5 T25,5 T30,5 T35,5 T40,5' fill='none' stroke='%23E53935' stroke-width='2'/%3E%3C/svg%3E") no-repeat center;
}

.legend-line.distant-hostile {
    height: 10px;
    background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='40' height='10'%3E%3Cpath d='M0,5 Q2.5,2 5,5 T10,5 T15,5 T20,5 T25,5 T30,5 T35,5 T40,5' fill='none' stroke='%23E53935' stroke-width='2'/%3E%3Cpath d='M25,2 L30,5 L25,8' fill='none' stroke='%23E53935' stroke-width='1.5'/%3E%3C/svg%3E") no-repeat center;
}

.legend-line.close-hostile {
    height: 10px;
    background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='40' height='10'%3E%3Cline x1='0' y1='2' x2='40' y2='2' stroke='%23757575' stroke-width='1'/%3E%3Cline x1='0' y1='8' x2='40' y2='8' stroke='%23757575' stroke-width='1'/%3E%3Cpath d='M0,5 L5,2 L10,8 L15,2 L20,8 L25,2 L30,8 L35,2 L40,5' fill='none' stroke='%23E53935' stroke-width='1.5'/%3E%3C/svg%3E") no-repeat center;
}

.legend-line.conflict-close {
    height: 12px;
    background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='40' height='12'%3E%3Cpath d='M0,6 L5,3 L10,9 L15,3 L20,9 L25,3 L30,9 L35,3 L40,6' fill='none' stroke='%23E53935' stroke-width='1.5'/%3E%3Cline x1='0' y1='1' x2='40' y2='1' stroke='%2328a745' stroke-width='1.5'/%3E%3Cline x1='0' y1='11' x2='40' y2='11' stroke='%2328a745' stroke-width='1.5'/%3E%3C/svg%3E") no-repeat center;
}


/* --- 虐待/暴力 --- */
.legend-line.violence {
    height: 10px;
    background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='40' height='10'%3E%3Cpath d='M0,5 L2.5,1 5,5 L7.5,9 L10,5 L12.5,1 15,5 L17.5,9 L20,5 L22.5,1 25,5 L27.5,9 L30,5 L32.5,1 35,5 L37.5,9 L40,5' fill='none' stroke='%23007BFF' stroke-width='1.5'/%3E%3C/svg%3E") no-repeat center;
}

.legend-line.abuse {
    height: 10px;
    background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='40' height='10'%3E%3Cpath d='M0,5 Q2.5,1 5,5 T10,5 T15,5 T20,5 T25,5 T30,5 T35,5 T40,5' fill='none' stroke='%23007BFF' stroke-width='1.5'/%3E%3C/svg%3E") no-repeat center;
}

.legend-line.physical-abuse {
    height: 10px;
    background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='40' height='10'%3E%3Cpath d='M0,5 Q2.5,1 5,5 T10,5 T15,5 T20,5 T25,5 T30,5 T35,5 T40,5' fill='none' stroke='%23007BFF' stroke-width='1.5'/%3E%3Cline x1='0' y1='5' x2='40' y2='5' stroke='black' stroke-width='1'/%3E%3C/svg%3E") no-repeat center;
}

.legend-line.emotional-abuse {
    height: 10px;
    background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='40' height='10'%3E%3Cpath d='M0,5 L2.5,2 5,5 L7.5,8 L10,5 L12.5,2 15,5 L17.5,8 L20,5 L22.5,2 25,5 L27.5,8 L30,5 L32.5,2 35,5 L37.5,8 L40,5' fill='none' stroke='%23007BFF' stroke-width='1.5'/%3E%3Cline x1='0' y1='5' x2='40' y2='5' stroke='black' stroke-width='1'/%3E%3C/svg%3E") no-repeat center;
}

.legend-line.sexual-abuse {
    height: 12px;
    background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='40' height='12'%3E%3Cpath d='M0,4 L2.5,1 5,4 L7.5,7 L10,4 L12.5,1 15,4 L17.5,7 L20,4 L22.5,1 25,4 L27.5,7 L30,4 L32.5,1 35,4 L37.5,7 L40,4' fill='none' stroke='%23007BFF' stroke-width='1.5'/%3E%3Cpath d='M0,8 L2.5,5 5,8 L7.5,11 L10,8 L12.5,5 15,8 L17.5,11 L20,8 L22.5,5 25,8 L27.5,11 L30,8 L32.5,5 35,8 L37.5,11 L40,8' fill='none' stroke='%23007BFF' stroke-width='1.5'/%3E%3C/svg%3E") no-repeat center;
}

.legend-line.neglect {
    height: 12px;
    background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='40' height='12'%3E%3Cline x1='0' y1='6' x2='38' y2='6' stroke='%23007BFF' stroke-width='2'/%3E%3Cpath d='M34,2 L38,6 L34,10' fill='none' stroke='%23007BFF' stroke-width='2'/%3E%3Cline x1='30' y1='2' x2='30' y2='10' stroke='black' stroke-width='2'/%3E%3C/svg%3E") no-repeat center;
}

.legend-line.manipulative {
    height: 10px;
    background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='40' height='10'%3E%3Cline x1='0' y1='5' x2='40' y2='5' stroke='black' stroke-width='2'/%3E%3Cline x1='18' y1='2' x2='22' y2='8' stroke='%23E53935' stroke-width='2'/%3E%3Cline x1='22' y1='2' x2='18' y2='8' stroke='%23E53935' stroke-width='2'/%3E%3C/svg%3E") no-repeat center;
}

/* .legend-line.controlling - 已合併重複定義 */
.legend-line.controlling {
    height: 12px;
    background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='40' height='12'%3E%3Cline x1='0' y1='6' x2='38' y2='6' stroke='%23E53935' stroke-width='2'/%3E%3Crect x='15' y='3' width='6' height='6' fill='white' stroke='%23E53935' stroke-width='1.5'/%3E%3Cline x1='15' y1='3' x2='21' y2='9' stroke='%23E53935' stroke-width='1.5'/%3E%3Cline x1='21' y1='3' x2='15' y2='9' stroke='%23E53935' stroke-width='1.5'/%3E%3Cpath d='M32,2 L38,6 L32,10' fill='none' stroke='%23E53935' stroke-width='2'/%3E%3C/svg%3E") no-repeat center;
}



/* ===================================
   關係選擇對話框
   =================================== */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: all var(--transition-normal);
}

.modal-overlay.active {
    opacity: 1;
    visibility: visible;
}

.modal {
    background: var(--bg-canvas);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-lg);
    max-width: 480px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
    transform: translateY(-20px);
    transition: transform var(--transition-normal);
}

.modal-overlay.active .modal {
    transform: translateY(0);
}

.modal-title {
    padding: 16px 20px;
    font-size: 16px;
    font-weight: 600;
    border-bottom: 1px solid var(--border-color);
}

.modal-content {
    padding: 20px;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding: 16px 20px;
    border-top: 1px solid var(--border-color);
}

.relationship-type-group {
    margin-bottom: 16px;
}

.relationship-type-group:last-child {
    margin-bottom: 0;
}

.relationship-type-group h4 {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.btn-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
}

.btn-grid .rel-btn {
    margin: 0;
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 8px;
    height: auto;
}

.btn-grid .rel-btn .legend-line {
    width: 60px;
}

.help-modal-content {
    line-height: 1.6;
}

.help-section {
    margin-bottom: 20px;
}

.help-section h4 {
    margin-bottom: 8px;
    color: var(--primary-color);
    border-left: 4px solid var(--primary-color);
    padding-left: 10px;
}

.help-section ul {
    padding-left: 20px;
    margin: 0;
}

.help-section li {
    margin-bottom: 6px;
}

.shortcut-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    background: var(--bg-light);
    padding: 12px;
    border-radius: var(--border-radius-sm);
    font-size: 13px;
}

.rel-btn {
    padding: 8px 16px;
    margin: 4px;
    background: var(--bg-light);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-sm);
    font-size: 13px;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.rel-btn:hover {
    background: var(--primary-light);
    border-color: var(--primary-color);
    color: var(--primary-color);
}

.btn-cancel {
    padding: 8px 20px;
    background: var(--bg-light);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-sm);
    font-size: 14px;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.btn-cancel:hover {
    background: var(--border-color);
}

/* ===================================
   性別選擇對話框
   =================================== */
.gender-selection {
    display: flex;
    justify-content: center;
    gap: 24px;
    padding: 20px 0;
}

.gender-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    width: 120px;
    height: 120px;
    padding: 20px;
    background: var(--bg-light);
    border: 2px solid var(--border-color);
    border-radius: var(--border-radius);
    font-size: 16px;
    font-weight: 500;
    color: var(--text-primary);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.gender-btn:hover {
    background: var(--primary-light);
    border-color: var(--primary-color);
    color: var(--primary-color);
    transform: scale(1.05);
}

.gender-btn .icon {
    font-size: 24px;
}

.gender-btn .male-icon,
.gender-btn .female-icon,
.gender-btn .same-icon,
.gender-btn .ftm-icon,
.gender-btn .mtf-icon {
    width: 32px;
    height: 32px;
    border-width: 3px;
    position: relative;
    /* For orientation marker */
}

.gender-btn.small {
    width: 70px;
    height: 70px;
    padding: 5px;
}

.gender-btn.small span:not(.icon) {
    font-size: 11px;
    margin-top: 3px;
    white-space: nowrap;
}

/* FTM: 外方內圓 */
.ftm-icon {
    display: inline-block;
    border: 2px solid currentColor;
    background: transparent;
    position: relative;
}

.ftm-icon::after {
    content: '';
    position: absolute;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    border: 2px solid currentColor;
    /* Hollow circle */
    background: transparent;
    top: 0%;
    left: 0%;
    box-sizing: border-box;
    /* Ensure border is inside */
}

/* MTF: 外圓內方 */
.mtf-icon {
    display: inline-block;
    border: 2px solid currentColor;
    border-radius: 50%;
    background: transparent;
    position: relative;
    box-sizing: border-box;
}

.mtf-icon::after {
    content: '';
    position: absolute;
    width: 70.7%;
    /* Inscribed square side = D * 0.707 */
    height: 70.7%;
    border: 2px solid currentColor;
    /* Hollow square */
    background: transparent;
    top: 14.65%;
    /* (100 - 70.7) / 2 */
    left: 14.65%;
    box-sizing: border-box;
}

/* Gender Orientation Marker (Hollow Inverted Triangle) */
.icon.with-triangle::before {
    content: '';
    position: absolute;
    width: 60%;
    height: 60%;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background-image: url("data:image/svg+xml,%3Csvg width='24' height='24' viewBox='0 0 24 24' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M4 6 L20 6 L12 20 Z' fill='none' stroke='%23333' stroke-width='2'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: center;
    background-size: contain;
    z-index: 10;
}

/* ===================================
   響應式設計
   =================================== */
@media (max-width: 768px) {
    .side-panel {
        position: fixed;
        right: -100%;
        top: var(--toolbar-height);
        bottom: 0;
        z-index: 50;
        transition: right var(--transition-normal);
    }

    .side-panel.open {
        right: 0;
    }

    .tool-label {
        display: none;
    }

    .tool-btn {
        min-width: 40px;
    }
}

/* ===================================
   動畫效果
   =================================== */
@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

@keyframes slideIn {
    from {
        transform: translateY(-10px);
        opacity: 0;
    }

    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.fade-in {
    animation: fadeIn var(--transition-normal) ease;
}

.slide-in {
    animation: slideIn var(--transition-normal) ease;
}

/* ===================================
   子女選擇對話框
   =================================== */
.children-selection {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    max-height: 300px;
    overflow-y: auto;
    padding: 10px 0;
}

.child-option {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    background: var(--bg-light);
    border: 2px solid var(--border-color);
    border-radius: var(--border-radius-sm);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.child-option:hover {
    background: var(--primary-light);
    border-color: var(--primary-color);
}

.child-option.selected {
    background: var(--primary-light);
    border-color: var(--primary-color);
    color: var(--primary-color);
}

.child-option .child-icon {
    width: 20px;
    height: 20px;
    border: 2px solid currentColor;
}

.child-option .child-icon.male {
    background: transparent;
}

.child-option .child-icon.female {
    border-radius: 50%;
}

.btn-primary {
    padding: 8px 20px;
    background: var(--primary-color);
    border: none;
    border-radius: var(--border-radius-sm);
    font-size: 14px;
    color: white;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.btn-primary:hover {
    background: var(--primary-hover);
}

.no-children-hint {
    color: var(--text-muted);
    font-style: italic;
    padding: 20px;
    text-align: center;
}

/* ===================================
   匯出格式選擇
   =================================== */
.export-options {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
}

.export-option-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 16px 12px;
    border: 2px solid var(--border-color);
    border-radius: var(--border-radius);
    background: var(--bg-canvas);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.export-option-btn:hover {
    border-color: var(--primary-color);
    background: var(--primary-light);
}

.export-option-btn:active {
    transform: scale(0.98);
}

.export-option-btn .export-icon {
    font-size: 28px;
    margin-bottom: 8px;
}

.export-option-btn .format-name {
    font-weight: 600;
    font-size: 14px;
    color: var(--text-primary);
}

.export-option-btn .format-desc {
    font-size: 11px;
    color: var(--text-secondary);
    margin-top: 4px;
    text-align: center;
}