/* ============================================
   图元备注样式文件
   ============================================ */

/* Overlay 容器：不随 scale 缩放，覆盖画布区域 */
#opm-notes-overlay {
    position: absolute;
    inset: 0; /* 覆盖 #opm-canvas 内部 */
    pointer-events: none; /* 默认不拦截事件 */
    z-index: 120; /* 高于链接层 */
}

/* 备注容器 */
.element-note {
    position: absolute;
    background: var(--note-bg, var(--color-bg-tertiary));
    color: var(--note-fg, var(--color-text-secondary));
    border: var(--note-border, 1px solid var(--color-border-light));
    border-radius: var(--note-radius, 0);
    padding: var(--note-padding, 4px 8px);
    font-family: var(--app-font-family);
    font-size: calc(var(--font-size-xs) * var(--note-font-scale, 1));
    line-height: var(--line-height-normal);
    max-width: 200px;
    min-width: 80px;
    word-wrap: break-word;
    white-space: pre-wrap;
    z-index: 100;
    box-shadow: var(--note-shadow, none);
    pointer-events: none; /* 容器不拦截，内部可按需启用 */
    opacity: 1; /* 完全不透明 */
    transition: opacity 0.2s ease;
    transform-origin: top left; /* 设置缩放原点 */
    transition: left 0.12s cubic-bezier(0.4,0,0.2,1), top 0.12s cubic-bezier(0.4,0,0.2,1), opacity 0.12s ease;
}

/* 分级显示 */
.element-note.note-hidden {
  opacity: 0;
  visibility: hidden;
}

.element-note.note-capsule {
  --note-radius: 10px;
  --note-padding: 2px 10px;
  --note-shadow: none;
  width: var(--note-capsule-width, 80px);
  min-width: 0;
  max-width: none;
}
.element-note.note-capsule .element-note-arrow { display: block; }
.element-note.note-capsule .element-note-text {
  white-space: normal; /* 自动换行 */
  overflow: visible;
  text-overflow: clip;
}

.element-note.note-card {
  --note-radius: 10px;
  --note-padding: 4px 8px;
  opacity: 1;
  visibility: visible;
}
.element-note.note-card .element-note-text {
  white-space: pre-wrap;
}

/* 备注悬停效果 */
.element-note:hover {
    opacity: 1;
    /* 移除 pointer-events: auto 以避免阻挡画布拖拽 */
}

/* 备注连接线 */
.note-connector {
    position: absolute;
    pointer-events: none !important; /* 确保SVG不阻挡鼠标事件 */
    z-index: 99;
}

.note-connector-line {
    stroke: #b0b0b0;
    stroke-width: 2px;
    stroke-dasharray: 4 2;
    opacity: 0.8;
    fill: none;
    pointer-events: none !important; /* 确保线条不阻挡鼠标事件 */
    vector-effect: non-scaling-stroke; /* 保持线条粗细不随缩放变化 */
}

/* 备注指示点 */
.note-indicator {
    position: absolute;
    top: -4px;
    right: -4px;
    width: 8px;
    height: 8px;
    background: rgba(255, 170, 0, 0.9);
    border-radius: 50%;
    border: 1px solid rgba(255, 255, 255, 0.95);
    z-index: 201;
    pointer-events: none;
    box-shadow: none;
}

/* 图元有备注时的标识 */
.opm-element.opm-object.has-note::after,
.opm-element.opm-process.has-note::after,
.opm-object-state.has-note::after,
.opm-object-process.has-note::after,
.opm-object-activity.has-note::after,
.opm-object-agent.has-note::after,
.opm-object-instrument.has-note::after,
.opm-object-entity.has-note::after,
.opm-object-physical.has-note::after,
.opm-object-informatical.has-note::after {
    content: '';
    position: absolute;
    top: -4px;
    right: -4px;
    background: rgba(255, 170, 0, 0.9);
    border-radius: 50%;
    width: 8px;
    height: 8px;
    border: 1px solid rgba(255, 255, 255, 0.95);
    z-index: 15000;
    pointer-events: none;
    box-shadow: none;
}

/* 备注在不同位置的样式调整 */
.element-note.position-top-right {
    /* 右上角位置，无需额外调整 */
}

.element-note.position-top-left {
    /* 左上角位置，无需额外调整 */
}

.element-note.position-bottom-right {
    /* 右下角位置，无需额外调整 */
}

.element-note.position-bottom-left {
    /* 左下角位置，无需额外调整 */
}

.element-note.position-right {
    /* 右侧中央位置 */
}

.element-note.position-left {
    /* 左侧中央位置 */
}

/* 备注文本样式 */
.element-note-text {
    margin: 0;
    padding: 0;
    font-size: inherit;
    line-height: inherit;
    color: var(--note-text, var(--color-text-muted));
    background: none;
    border: none;
    outline: none;
    resize: none;
    font-family: inherit;
}

/* 备注编辑状态 */
.element-note.editing {
    /* 只在编辑模式下允许pointer-events */
    pointer-events: auto;
    opacity: 1;
    border-color: #ff6b35;
    box-shadow: none;
    z-index: 1000; /* 编辑时提高z-index */
}

.element-note.editing .element-note-text {
    background: rgba(255, 255, 255, 0.05);
    border: none;
    border-radius: 3px;
    padding: 4px;
    color: var(--color-text-inverse);
}

/* 响应式调整 */
@media (max-width: 768px) {
    .element-note {
        max-width: 150px;
        font-size: var(--font-size-xs);
        padding: 6px 8px;
    }
    
    .opm-element.opm-object.has-note::after,
    .opm-element.opm-process.has-note::after,
    .opm-object-state.has-note::after,
    .opm-object-process.has-note::after,
    .opm-object-activity.has-note::after,
    .opm-object-agent.has-note::after,
    .opm-object-instrument.has-note::after,
    .opm-object-entity.has-note::after,
    .opm-object-physical.has-note::after,
    .opm-object-informatical.has-note::after {
        width: 7px;
        height: 7px;
        top: -3px;
        right: -3px;
        z-index: 15000;
    }
}

/* 备注动画效果 */
@keyframes noteAppear {
    from {
        opacity: 0;
        transform: scale(0.8);
    }
    to {
        opacity: 0.85;
        transform: scale(1);
    }
}

@keyframes noteDisappear {
    from {
        opacity: 0.85;
        transform: scale(1);
    }
    to {
        opacity: 0;
        transform: scale(0.8);
    }
}

.element-note.appearing {
    animation: noteAppear 0.2s ease-out forwards;
}

.element-note.disappearing {
    animation: noteDisappear 0.2s ease-in forwards;
}

/* 备注在选中元素上的特殊样式 */
.opm-object-state.selected .element-note,
.opm-object-process.selected .element-note,
.opm-object-activity.selected .element-note,
.opm-object-agent.selected .element-note,
.opm-object-instrument.selected .element-note,
.opm-object-entity.selected .element-note,
.opm-object-physical.selected .element-note,
.opm-object-informatical.selected .element-note {
    border-color: #00ff41;
    box-shadow: none;
}

.opm-object-state.selected .note-connector-line,
.opm-object-process.selected .note-connector-line,
.opm-object-activity.selected .note-connector-line,
.opm-object-agent.selected .note-connector-line,
.opm-object-instrument.selected .note-connector-line,
.opm-object-entity.selected .note-connector-line,
.opm-object-physical.selected .note-connector-line,
.opm-object-informatical.selected .note-connector-line {
    stroke: #00ff41;
    opacity: 0.8;
}

.opm-element.opm-object.selected .note-indicator,
.opm-element.opm-process.selected .note-indicator,
.opm-object-state.selected .note-indicator,
.opm-object-process.selected .note-indicator,
.opm-object-activity.selected .note-indicator,
.opm-object-agent.selected .note-indicator,
.opm-object-instrument.selected .note-indicator,
.opm-object-entity.selected .note-indicator,
.opm-object-physical.selected .note-indicator,
.opm-object-informatical.selected .note-indicator {
    background: #00ff41;
    box-shadow: none;
}

@media (max-width: 768px) {
    .note-indicator {
        width: 7px;
        height: 7px;
        top: -3px;
        right: -3px;
    }
}

/* 备注工具提示 */
.note-tooltip {
    position: absolute;
    background: rgba(0, 0, 0, 0.9);
    color: var(--color-text-inverse);
    padding: 4px 8px;
    border-radius: 4px;
    font-size: var(--font-size-xs);
    font-family: var(--app-font-family);
    white-space: nowrap;
    z-index: 1000;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.note-tooltip.show {
    opacity: 1;
}

/* 备注计数器 */
.note-counter {
    position: absolute;
    top: -6px;
    right: -6px;
    background: #ff6b35;
    color: var(--color-black);
    font-size: var(--font-size-xs);
    font-weight: var(--font-weight-bold);
    border-radius: 50%;
    width: 16px;
    height: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: var(--app-font-family);
    z-index: 103;
    pointer-events: none;
    box-shadow: none;
}

/* 隐藏默认的备注图标，当有计数器时 */
.opm-element.opm-object.has-note.has-multiple-notes::after,
.opm-element.opm-process.has-note.has-multiple-notes::after,
.opm-object-state.has-note.has-multiple-notes::after,
.opm-object-process.has-note.has-multiple-notes::after,
.opm-object-activity.has-note.has-multiple-notes::after,
.opm-object-agent.has-note.has-multiple-notes::after,
.opm-object-instrument.has-note.has-multiple-notes::after,
.opm-object-entity.has-note.has-multiple-notes::after,
.opm-object-physical.has-note.has-multiple-notes::after,
.opm-object-informatical.has-note.has-multiple-notes::after {
    display: none;
}

/* ============================================
   备注模态框样式 - 主题感知
   ============================================ */

/* 模态框基础样式 */
#note-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background-color: var(--color-bg-overlay);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 15000;
}

/* 模态框内容 */
#note-modal .modal-content {
    background: var(--color-bg-primary);
    border: 1px solid var(--color-border-medium);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-lg);
    padding: 0; /* override global .modal-content padding to avoid thick border feel */
    max-width: 420px; /* was 500px */
    width: 86%; /* was 90% */
    max-height: 90vh;
    overflow: hidden;
    animation: scaleIn 0.2s ease;
}

/* 模态框头部 */
#note-modal .modal-header {
    background: var(--color-bg-secondary);
    border-bottom: 1px solid var(--color-border-medium);
    padding: 10px 12px; /* compact header */
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-radius: var(--border-radius) var(--border-radius) 0 0;
}

#note-modal .modal-header h3 {
    color: var(--color-text-primary);
    margin: 0;
    font-family: var(--app-font-family);
    font-size: var(--font-size-lg);
    font-weight: var(--font-weight-semibold);
}

/* 关闭按钮 */
#note-modal .modal-close {
    background: none;
    border: none;
    color: var(--color-text-secondary);
    font-size: 24px;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    border-radius: var(--border-radius);
    transition: var(--transition-fast);
}

#note-modal .modal-close:hover {
    color: var(--color-text-primary);
    background: var(--color-bg-tertiary);
}

/* 模态框主体 */
#note-modal .modal-body {
    padding: 8px 12px; /* compact body */
    background: var(--color-bg-primary);
}

/* modal footer spacing (if present, early declaration; main block below overrides details) */
#note-modal .modal-footer {
    padding: 10px 12px; /* compact footer */
}

/* 输入组样式 */
.note-input-group {
    margin-bottom: 10px; /* compact spacing */
}

/* 标签样式 */
#note-modal .modal-body label {
    display: block;
    margin-bottom: 6px; /* compact spacing */
    color: var(--color-text-primary);
    font-family: var(--app-font-family);
    font-weight: var(--font-weight-semibold);
    font-size: var(--font-size-sm);
}

/* 文本域样式 */
#note-text {
    width: 100%;
    height: 96px; /* was 120px */
    padding: 10px; /* was 12px */
    border: 1px solid var(--color-border-medium);
    background: var(--color-bg-tertiary);
    color: var(--color-text-primary);
    font-family: var(--app-font-family);
    font-size: var(--font-size-sm);
    line-height: var(--line-height-normal);
    resize: vertical;
    border-radius: var(--border-radius);
    box-sizing: border-box;
    transition: var(--transition-fast);
}

#note-text:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 2px rgba(255, 107, 53, 0.2);
}

#note-text::placeholder {
    color: var(--color-text-muted);
}

/* 字符计数 */
.note-char-count {
    text-align: right;
    margin-top: 5px;
    font-size: var(--font-size-xs);
    color: var(--color-text-muted);
    font-family: var(--app-font-family);
}

/* 模态框底部 */
#note-modal .modal-footer {
    background: var(--color-bg-secondary);
    border-top: 1px solid var(--color-border-medium);
    padding: 10px 12px; /* compact footer */
    display: flex;
    justify-content: flex-end;
    gap: 8px; /* compact spacing */
    border-radius: 0 0 var(--border-radius) var(--border-radius);
}

/* 按钮样式 */
#note-cancel-btn {
    background: transparent;
    color: var(--color-text-secondary);
    border: 1px solid var(--color-border-medium);
    padding: 6px 12px; /* compact button */
    border-radius: var(--border-radius);
    cursor: pointer;
    font-family: var(--app-font-family);
    font-size: var(--font-size-sm);
    transition: var(--transition-fast);
}

#note-cancel-btn:hover {
    color: var(--color-text-primary);
    border-color: var(--color-border-dark);
    background: var(--color-bg-tertiary);
}

#note-save-btn {
    background: var(--color-primary);
    color: var(--color-white);
    border: none;
    padding: 6px 12px; /* compact button */
    border-radius: var(--border-radius);
    cursor: pointer;
    font-family: var(--app-font-family);
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-semibold);
    transition: var(--transition-fast);
}

#note-save-btn:hover {
    background: var(--color-primary-dark);
}

#note-save-btn:active {
    transform: translateY(1px);
}

/* 模态框动画 */
@keyframes scaleIn {
    from {
        opacity: 0;
        transform: scale(0.9);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

/* 亮色主题适配 */
[data-theme="light"] #note-modal {
    background-color: rgba(0, 0, 0, 0.5);
}

[data-theme="light"] #note-modal .modal-content {
    background: var(--color-bg-primary);
    border: 1px solid var(--color-border-light);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
}

[data-theme="light"] #note-modal .modal-header {
    background: var(--color-bg-light);
    border-bottom: 1px solid var(--color-border-light);
}

[data-theme="light"] #note-modal .modal-body {
    background: var(--color-bg-primary);
}

[data-theme="light"] #note-modal .modal-footer {
    background: var(--color-bg-light);
    border-top: 1px solid var(--color-border-light);
}

[data-theme="light"] #note-text {
    background: var(--color-white);
    border: 1px solid var(--color-border-light);
}

[data-theme="light"] #note-text:focus {
    border-color: var(--color-primary);
    box-shadow: 0 0 0 2px rgba(255, 107, 53, 0.15);
}

[data-theme="light"] #note-cancel-btn {
    border-color: var(--color-border-light);
}

[data-theme="light"] #note-cancel-btn:hover {
    background: var(--color-bg-secondary);
    border-color: var(--color-border-medium);
}

/* 备注小三角形样式 */
.element-note-arrow {
  position: absolute;
  width: 8px;
  height: 8px;
  background: var(--note-bg, var(--color-bg-tertiary));
  border: 1px solid var(--color-border-light);
  transform: rotate(45deg);
  opacity: 0.9;
  box-shadow: none;
}

/* 右上角 */
.element-note.position-top-right .element-note-arrow { left: -4px; top: 6px; }

/* 左上角 */
.element-note.position-top-left .element-note-arrow { right: -4px; top: 6px; }

/* 右下角 */
.element-note.position-bottom-right .element-note-arrow { left: -4px; bottom: 6px; }

/* 左下角 */
.element-note.position-bottom-left .element-note-arrow { right: -4px; bottom: 6px; }

/* 右侧 */
.element-note.position-right .element-note-arrow { left: -4px; top: 50%; transform: translateY(-50%) rotate(45deg); }

/* 左侧 */
.element-note.position-left .element-note-arrow { right: -4px; top: 50%; transform: translateY(-50%) rotate(45deg); }

/* 主题令牌（可被上层主题覆盖） */
:root {
  --note-bg: color-mix(in oklab, var(--color-bg-tertiary) 92%, transparent);
  --note-fg: var(--color-text-secondary);
  --note-text: var(--color-text-muted);
  --note-border: 1px solid color-mix(in oklab, var(--color-border-light) 70%, transparent);
  --note-shadow: none;
  --note-radius: 10px;
  --note-padding: 4px 8px;
}

[data-theme="dark"],
body.dark-theme {
  --note-bg: color-mix(in oklab, var(--color-bg-tertiary) 88%, transparent);
  --note-fg: var(--color-text-primary);
  --note-text: var(--color-text-primary);
  --note-border: 1px solid color-mix(in oklab, var(--color-text-primary) 55%, transparent);
}

[data-theme="light"],
body.light-theme {
  --note-bg: color-mix(in oklab, var(--color-bg-primary) 90%, transparent);
  --note-fg: var(--color-text-primary);
  --note-text: var(--color-text-secondary);
  --note-border: 1px solid color-mix(in oklab, var(--color-border-light) 80%, transparent);
}
