/* ==========================================================================
   Ontology Function Panel (M14)
   --------------------------------------------------------------------------
   function-panel.js 动态创建 DOM，使用自定义类 + 少量 Bootstrap 风格类。
   本应用基于 Tailwind（无 Bootstrap），因此这里为该面板补齐全部样式。
   所有选择器都限定在 .ontology-function-panel 作用域内，避免污染全局。
   布局与 action-panel/version-panel 等兄弟面板一致：右侧固定抽屉（420px 宽）。
   ========================================================================== */

/* ---- 容器：右侧固定抽屉 ---- */
.ontology-function-panel {
    position: fixed;
    top: 0;
    right: 0;
    height: 100%;
    width: 420px;
    max-width: 95vw;
    background: #ffffff;
    border-left: 1px solid #e2e8f0;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    z-index: 381; /* 略高于 action-panel，避免被覆盖 */
    display: block;
    color: #1e293b;
    font-size: 14px;
    line-height: 1.5;
}
.dark .ontology-function-panel {
    background: #0f172a;
    border-left-color: #334155;
    color: #e2e8f0;
}

/* 最小化：只保留头部 */
.ontology-function-panel.minimized {
    height: auto;
}
.ontology-function-panel.minimized .function-panel-content {
    display: none;
}

/* ---- 头部 ---- */
.ontology-function-panel .function-panel-header {
    height: 56px;
    box-sizing: border-box;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    border-bottom: 1px solid #e2e8f0;
    background: #f8fafc;
}
.dark .ontology-function-panel .function-panel-header {
    background: rgba(255, 255, 255, 0.03);
    border-bottom-color: #334155;
}
.ontology-function-panel .function-panel-header h3 {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0;
    font-size: 15px;
    font-weight: 600;
}
.ontology-function-panel .function-panel-header h3 i {
    color: #6366f1; /* 靛蓝色，呼应入口按钮 */
}
.ontology-function-panel .function-panel-controls {
    display: flex;
    align-items: center;
    gap: 4px;
}

/* ---- Tab 标签 ---- */
.ontology-function-panel .function-panel-tabs {
    display: flex;
    align-items: center;
    gap: 4px;
    background: #e2e8f0;
    padding: 3px;
    border-radius: 8px;
}
.dark .ontology-function-panel .function-panel-tabs {
    background: #1e293b;
}
.ontology-function-panel .function-panel-tab {
    border: none;
    background: transparent;
    color: #475569;
    font-size: 12px;
    font-weight: 500;
    padding: 5px 12px;
    border-radius: 6px;
    cursor: pointer;
    transition: background-color .15s ease, color .15s ease;
}
.dark .ontology-function-panel .function-panel-tab {
    color: #94a3b8;
}
.ontology-function-panel .function-panel-tab:hover {
    color: #1e293b;
}
.dark .ontology-function-panel .function-panel-tab:hover {
    color: #e2e8f0;
}
.ontology-function-panel .function-panel-tab.active {
    background: #ffffff;
    color: #1e293b;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
}
.dark .ontology-function-panel .function-panel-tab.active {
    background: #334155;
    color: #e2e8f0;
}

/* ---- 内容区 ---- */
.ontology-function-panel .function-panel-content {
    height: calc(100% - 56px);
    overflow-y: auto;
    padding: 16px;
    box-sizing: border-box;
}

/* ---- 列表视图 ---- */
.ontology-function-panel .function-list-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}
.ontology-function-panel .function-list-header h4 {
    margin: 0;
    font-size: 14px;
    font-weight: 600;
}
.ontology-function-panel .function-count {
    font-size: 12px;
    color: #94a3b8;
}
.ontology-function-panel .function-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.ontology-function-panel .function-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    background: #ffffff;
    cursor: pointer;
    transition: border-color .15s ease, box-shadow .15s ease;
}
.dark .ontology-function-panel .function-item {
    background: rgba(255, 255, 255, 0.02);
    border-color: #334155;
}
.ontology-function-panel .function-item:hover {
    border-color: #6366f1;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
}
.ontology-function-panel .function-item.disabled {
    opacity: .5;
}
.ontology-function-panel .function-item-icon {
    flex: 0 0 auto;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    background: #eef2ff;
    color: #4f46e5;
    font-size: 15px;
}
.dark .ontology-function-panel .function-item-icon {
    background: rgba(99, 102, 241, 0.15);
    color: #a5b4fc;
}
.ontology-function-panel .function-item-content {
    flex: 1 1 auto;
    min-width: 0;
}
.ontology-function-panel .function-item-name {
    font-size: 13px;
    font-weight: 600;
    color: #1e293b;
    display: flex;
    align-items: center;
    gap: 6px;
}
.dark .ontology-function-panel .function-item-name {
    color: #e2e8f0;
}
.ontology-function-panel .function-item-desc {
    font-size: 12px;
    color: #64748b;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.dark .ontology-function-panel .function-item-desc {
    color: #94a3b8;
}
.ontology-function-panel .function-item-actions {
    flex: 0 0 auto;
}

/* ---- 表单视图 ---- */
.ontology-function-panel .function-form-view {
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.ontology-function-panel .function-form-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 12px;
}
.ontology-function-panel .function-form-header h4 {
    margin: 0;
    font-size: 14px;
    font-weight: 600;
    flex: 1 1 auto;
}
.ontology-function-panel .function-badge {
    font-size: 11px;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 999px;
}
.ontology-function-panel .function-badge.builtin {
    background: #eef2ff;
    color: #4338ca;
}
.dark .ontology-function-panel .function-badge.builtin {
    background: rgba(99, 102, 241, 0.15);
    color: #a5b4fc;
}
.ontology-function-panel .function-badge.custom {
    background: #ecfeff;
    color: #0e7490;
}
.dark .ontology-function-panel .function-badge.custom {
    background: rgba(6, 182, 212, 0.15);
    color: #67e8f9;
}
.ontology-function-panel .function-badge.warning {
    background: #fef3c7;
    color: #b45309;
}
.ontology-function-panel .function-description {
    font-size: 13px;
    color: #64748b;
    margin-bottom: 16px;
    padding: 10px 12px;
    background: #f8fafc;
    border-radius: 8px;
}
.dark .ontology-function-panel .function-description {
    background: rgba(255, 255, 255, 0.03);
    color: #94a3b8;
}
.ontology-function-panel .function-description p {
    margin: 6px 0 0;
}
.ontology-function-panel .function-return-type {
    display: inline-block;
    margin-top: 8px;
    font-size: 11px;
    background: #e2e8f0;
    padding: 2px 6px;
    border-radius: 4px;
}
.dark .ontology-function-panel .function-return-type {
    background: #334155;
    color: #e2e8f0;
}

/* ---- 表单元素 ---- */
.ontology-function-panel .form-group {
    margin-bottom: 14px;
}
.ontology-function-panel .form-group label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: #475569;
    margin-bottom: 6px;
}
.dark .ontology-function-panel .form-group label {
    color: #94a3b8;
}
.ontology-function-panel .required {
    color: #e11d48;
    margin-left: 2px;
}
.ontology-function-panel .form-control {
    width: 100%;
    box-sizing: border-box;
    padding: 8px 10px;
    font-size: 13px;
    color: #1e293b;
    background: #ffffff;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    transition: border-color .15s ease, box-shadow .15s ease;
}
.ontology-function-panel .form-control:focus {
    outline: none;
    border-color: #6366f1;
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}
.dark .ontology-function-panel .form-control {
    background: #1e293b;
    border-color: #334155;
    color: #e2e8f0;
}
.ontology-function-panel textarea.form-control {
    resize: vertical;
    font-family: inherit;
}

/* ---- 按钮 ---- */
.ontology-function-panel .btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    font-size: 13px;
    font-weight: 500;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    background: transparent;
    color: inherit;
    transition: background-color .15s ease, color .15s ease;
}
.ontology-function-panel .btn-sm {
    padding: 4px 8px;
    font-size: 12px;
    border-radius: 6px;
}
.ontology-function-panel .btn-primary {
    background: #4f46e5;
    color: #ffffff;
}
.ontology-function-panel .btn-primary:hover {
    background: #4338ca;
}
.ontology-function-panel .btn-secondary {
    background: #e2e8f0;
    color: #334155;
}
.dark .ontology-function-panel .btn-secondary {
    background: #334155;
    color: #e2e8f0;
}
.ontology-function-panel .btn-secondary:hover {
    background: #cbd5e1;
}
.ontology-function-panel .btn-danger {
    background: #fef2f2;
    color: #b91c1c;
}
.dark .ontology-function-panel .btn-danger {
    background: rgba(225, 29, 72, 0.12);
    color: #fda4af;
}
.ontology-function-panel .btn-link {
    background: transparent;
    color: #64748b;
    padding: 4px 6px;
}
.ontology-function-panel .btn-link:hover {
    color: #334155;
    background: #f1f5f9;
    border-radius: 6px;
}
.dark .ontology-function-panel .btn-link:hover {
    color: #e2e8f0;
    background: rgba(255, 255, 255, 0.06);
}
.ontology-function-panel .btn[disabled] {
    opacity: .5;
    cursor: not-allowed;
}
.ontology-function-panel .function-form-actions {
    display: flex;
    gap: 8px;
    margin-top: 16px;
}

/* ---- 提示框 / 徽章 / muted ---- */
.ontology-function-panel .alert {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    font-size: 13px;
    border-radius: 8px;
    margin-bottom: 10px;
    border: 1px solid transparent;
}
.ontology-function-panel .alert-success {
    background: #EDFDF3;
    color: #1C6B3B;
    border-color: #ABF4C7;
}
.dark .ontology-function-panel .alert-success {
    background: rgba(53, 168, 91, 0.12);
    color: #74E9A4;
    border-color: rgba(53, 168, 91, 0.3);
}
.ontology-function-panel .alert-danger {
    background: #fef2f2;
    color: #b91c1c;
    border-color: #fecaca;
}
.dark .ontology-function-panel .alert-danger {
    background: rgba(225, 29, 72, 0.12);
    color: #fda4af;
    border-color: rgba(225, 29, 72, 0.3);
}
.ontology-function-panel .badge {
    background: #e2e8f0;
    color: #334155;
    border-radius: 999px;
    padding: 2px 8px;
    font-size: 11px;
    font-weight: 600;
}
.dark .ontology-function-panel .badge {
    background: #334155;
    color: #e2e8f0;
}
.ontology-function-panel .text-muted {
    color: #94a3b8;
    font-size: 13px;
}

/* ---- 调用结果 JSON 树 ---- */
.ontology-function-panel .function-invoke-result {
    margin-top: 16px;
}
.ontology-function-panel .function-result-json {
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 12px;
    margin: 0;
    font-size: 12px;
    line-height: 1.4;
    color: #334155;
    max-height: 360px;
    overflow-y: auto;
    white-space: pre-wrap;
    word-break: break-all;
}
.dark .ontology-function-panel .function-result-json {
    background: #0f172a;
    border-color: #334155;
    color: #e2e8f0;
}

/* ---- 管线编辑器 ---- */
.ontology-function-panel .function-pipeline-view {
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.ontology-function-panel .function-pipeline-header h4 {
    margin: 0 0 6px;
    font-size: 14px;
    font-weight: 600;
}
.ontology-function-panel .function-pipeline-header p {
    margin: 0;
    font-size: 12px;
}
.ontology-function-panel .function-pipeline-empty {
    padding: 24px;
    text-align: center;
    color: #94a3b8;
    background: #f8fafc;
    border-radius: 8px;
    font-size: 13px;
}
.dark .ontology-function-panel .function-pipeline-empty {
    background: rgba(255, 255, 255, 0.03);
    color: #94a3b8;
}
.ontology-function-panel .function-pipeline-step {
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    padding: 12px;
    background: #ffffff;
    margin-bottom: 10px;
}
.dark .ontology-function-panel .function-pipeline-step {
    background: rgba(255, 255, 255, 0.02);
    border-color: #334155;
}
.ontology-function-panel .function-pipeline-step-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 10px;
}
.ontology-function-panel .function-pipeline-step-number {
    font-size: 12px;
    font-weight: 700;
    color: #6366f1;
    background: #eef2ff;
    padding: 2px 8px;
    border-radius: 6px;
}
.dark .ontology-function-panel .function-pipeline-step-number {
    background: rgba(99, 102, 241, 0.15);
    color: #a5b4fc;
}
.ontology-function-panel .function-pipeline-step-function {
    flex: 1 1 auto;
}
.ontology-function-panel .function-pipeline-actions {
    display: flex;
    gap: 8px;
    margin-top: 16px;
}
