/* --- CSS Variables from Tailwind Config --- */
:root {
    --primary: #165DFF;
    --secondary: #36CFC9;
    --neutral: #F5F7FA;
    --dark: #1D2129;
    --configured: #E6FFFA;
    --configuredBorder: #36CFC9;
    --font-inter: 'Inter', system-ui, sans-serif;
}

/* --- Base and Reset Styles --- */
body {
    font-family: var(--font-inter);
    background-color: var(--neutral);
    color: #1f2937;
    margin: 0;
}

*,
::before,
::after {
    box-sizing: border-box;
    border-width: 0;
    border-style: solid;
    border-color: #e5e7eb;
}

/* --- Keyframes and Animations --- */
@keyframes pulse {
    0% {
        stroke-width: 2;
        opacity: 1;
    }

    50% {
        stroke-width: 4;
        opacity: 0.7;
    }

    100% {
        stroke-width: 2;
        opacity: 1;
    }
}

@keyframes configured {
    0% {
        stroke-width: 2;
        opacity: 0.8;
    }

    50% {
        stroke-width: 3;
        opacity: 1;
    }

    100% {
        stroke-width: 2;
        opacity: 0.8;
    }
}

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

    100% {
        transform: rotate(360deg);
    }
}

@keyframes lds-dual-ring {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

/* --- Utility Classes from original <style> block --- */
.content-auto {
    content-visibility: auto;
}

.pin-label {
    font-size: 10px;
    pointer-events: none;
}

.rotate-90 {
    transform: rotate(90deg);
}

.rotate-180 {
    transform: rotate(180deg);
}

.rotate-270 {
    transform: rotate(270deg);
}

.pulse-animation {
    animation: pulse 1.5s infinite;
}

.configured-animation {
    animation: configured 2s infinite;
}

.disabled-option {
    color: #999;
    background-color: #f0f0f0;
}

.svg-select {
    background-color: #fff;
    cursor: pointer;
}

.svg-container {
    overflow: auto;
    padding: 10px;
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    flex: 1;
    min-height: 0;
}

.svg-wrapper {
    width: 100%;
    height: 100%;
    transform-origin: center;
    transition: transform 0.3s ease;
}

.function-item {
    transition: all 0.2s ease;
    cursor: pointer;
}

.function-item:hover:not(.configured) {
    background-color: #e6f7ff;
}

.function-item.configured {
    background-color: var(--configured);
    border-left: 3px solid var(--configuredBorder);
}

.function-pin-item {
    transition: all 0.2s ease;
    cursor: pointer;
}

.function-pin-item:hover:not(.configured):not(.disabled) {
    background-color: #e6f7ff;
    transform: translateX(2px);
}

.function-pin-item.configured {
    background-color: var(--configured);
    border-left: 3px solid var(--configuredBorder);
}

.function-pin-item.disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.function-pins,
.subgroup-content,
.physical-pins-list {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease-out;
}

.function-pins.expanded,
.subgroup-content.expanded,
.physical-pins-list.expanded {
    max-height: 8000px;
    transition: max-height 0.5s ease-in;
}

.physical-pin-option {
    border-radius: 4px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.physical-pin-option:hover:not(.disabled) {
    background-color: #f0f8ff;
}

.physical-pin-option.disabled {
    opacity: 0.6;
    cursor: not-allowed;
    color: #64748b;
}

.physical-pin-option.disabled label {
    cursor: not-allowed;
}

.physical-pin-option label {
    cursor: pointer;
    flex-grow: 1;
}

.floating-hint {
    position: fixed;
    top: calc(20px + var(--top-nav-height, 0px));
    left: 50%;

    max-width: 300px;
    padding: 12px 16px;
    border-radius: 6px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    z-index: 999;

    transform: translate(-50%, -150%);
    opacity: 0;

    transition: transform 0.3s ease, opacity 0.3s ease;
}

.floating-hint.show {
    transform: translate(-50%, 0);
    opacity: 1;
}

.floating-hint .hint-content {
    display: flex;
    align-items: flex-start;
    gap: 8px;
}

.floating-hint .hint-icon {
    font-size: 18px;
    flex-shrink: 0;
    margin-top: 1px;
}

.floating-hint .hint-text {
    flex: 1;
}

.floating-hint .hint-title {
    font-weight: 600;
    margin-bottom: 4px;
}

.floating-hint .hint-message {
    font-size: 14px;
    line-height: 1.4;
}

.floating-hint.info {
    background-color: #ebf8ff;
    border-left: 4px solid var(--primary);
}

.floating-hint.success {
    background-color: #f0fff4;
    border-left: 4px solid var(--secondary);
}

.floating-hint.warning {
    background-color: #fffbf0;
    border-left: 4px solid #faad14;
}

.floating-hint.error {
    background-color: #fff1f0;
    border-left: 4px solid #ff4d4f;
}

/* --- Layout Styles --- */
.page-container {
    width: 100%;
    height: 88vh;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.main-layout {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    flex: 1;
    min-height: 0;
    padding: 1rem;
}

.config-panel {
    background-color: #fff;
    border-radius: 0.75rem;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.1);
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
}

.config-panel>div:first-of-type {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
}

.diagram-panel {
    background-color: #fff;
    border-radius: 0.75rem;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.1);
    padding: 0.5rem;
    display: flex;
    flex-direction: column;
}

.panel-title {
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: 1rem;
    color: var(--dark);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.panel-title>span {
    display: flex;
    align-items: center;
}

.panel-title .fa {
    color: var(--primary);
    margin-right: 0.5rem;
}

.config-section {
    margin-bottom: 6px;
}

.config-section:last-child {
    margin-bottom: 0;
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    color: #4b5563;
    margin-bottom: 0.25rem;
}

.label-ops {
    margin-bottom: 0.5rem;
}

.select-input {
    width: 100%;
    padding: 0.5rem;
    border: 1px solid #d1d5db;
    border-radius: 0.5rem;
    transition: all 0.2s;
}

.select-input:focus {
    outline: 2px solid transparent;
    outline-offset: 2px;
    box-shadow: 0 0 0 2px rgba(22, 93, 255, 0.5);
    border-color: var(--primary);
}

.select-input:disabled {
    background-color: #f3f4f6;
    cursor: not-allowed;
}

.ops-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.75rem;
}

.btn-collapse {
    border: 1px solid #a78bfa;
    color: #5b21b6;
}

.btn-collapse:hover {
    color: #5b21b6;
    background-color: #f5f3ff;
}

.btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    border-radius: 0.375rem;
    font-size: 0.875rem;
    font-weight: 500;
    transition: background-color 0.2s;
    cursor: pointer;
}

.btn-reset {
    border: 1px solid #fdba74;
    color: #c2410c;
}

.btn-reset:hover {
    background-color: #fff7ed;
    color: #c2410c !important;
}

.btn-import {
    border: 1px solid #d1d5db;
    color: #374151;
}

.btn-import:hover {
    background-color: #f9fafb;
    color: #374151 !important;
}

.btn-export {
    background-color: var(--primary);
    color: #374151;
}

.btn-export:hover {
    background-color: rgba(22, 93, 255, 0.9);
    color: #374151 !important;
}

#import-file-input {
    display: none;
}

#function-list {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    background-color: #f9fafb;
    padding: 0.75rem;
    border-radius: 0.5rem;
    border: 1px solid #e5e7eb;
    font-size: 0.875rem;
}

#function-list>*:not(:last-child) {
    margin-bottom: 0.25rem;
}

#function-list .text-gray-500 {
    color: #6b7280;
    font-style: italic;
}

.diagram-container-wrapper {
    position: relative;
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

.diagram-container {
    border: 1px solid #e5e7eb;
    border-radius: 0.5rem;
    background-color: #f9fafb;
    margin-top: 0.5rem;
    overflow: hidden;
}

#pin-diagram text.text-gray-500 {
    fill: #6b7280;
}

.guide-tooltip-wrapper {
    position: relative;
    display: inline-block;
}

.guide-tooltip-trigger {
    font-size: 1.1rem;
    color: #9ca3af;
    cursor: help;
    transition: color 0.2s ease;
    margin-right: 0;
}

.guide-tooltip-trigger:hover {
    color: var(--primary);
}

.guide-tooltip-content {
    visibility: hidden;
    opacity: 0;
    width: 320px;
    background-color: #ffffff;
    color: #1f2937;
    text-align: left;
    border-radius: 8px;
    padding: 1rem;
    position: absolute;
    z-index: 100;
    top: calc(100% + 10px);
    right: 0;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    border: 1px solid #e5e7eb;
    transition: opacity 0.25s ease-out, visibility 0.25s ease-out;
    pointer-events: none;
}

.guide-tooltip-content::after {
    content: "";
    position: absolute;
    bottom: 100%;
    right: 10px;
    border-width: 6px;
    border-style: solid;
    border-color: transparent transparent #ffffff transparent;
}

.guide-tooltip-wrapper:hover .guide-tooltip-content {
    visibility: visible;
    opacity: 1;
}

.guide-tooltip-content .font-medium {
    font-weight: 600;
    margin-bottom: 0.5rem;
    color: var(--dark);
}

.guide-tooltip-content ol {
    list-style-type: decimal;
    list-style-position: outside;
    padding-left: 1.2rem;
    margin: 0;
    font-size: 0.875rem;
    line-height: 1.5;
}

.guide-tooltip-content li:not(:last-child) {
    margin-bottom: 0.5rem;
}

#zoom-controls-container {
    position: absolute;
    top: 5px;
    right: 5px;
    z-index: 10;
    background: rgba(255, 255, 255, 0.9);
    border-radius: 6px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    padding: 4px;
    display: flex;
    align-items: center;
    gap: 4px;
}

#zoom-controls-container button {
    background-color: transparent;
    border: 1px solid #d1d5db;
    color: #374151;
    width: 28px;
    height: 28px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s, border-color 0.2s;
}

#zoom-controls-container button:hover {
    background-color: #f0f0f0;
    border-color: #aaa;
}

#zoom-level {
    font-size: 12px;
    color: #4b5563;
    font-weight: 500;
    padding: 0 8px;
    min-width: 45px;
    text-align: center;
}

.hidden {
    display: none;
}

#loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(249, 250, 251, 0.85);
    /* 半透明背景遮罩 */
    z-index: 1000;
}

#loading-indicator-content {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    /* 精确居中的关键 */
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
}

#loading-indicator-content .spinner {
    width: 64px;
    height: 64px;
}

#loading-indicator-content .spinner:after {
    content: " ";
    display: block;
    width: 50px;
    height: 50px;
    margin: 4px;
    border-radius: 50%;
    border: 5px solid var(--primary);
    border-color: var(--primary) transparent var(--primary) transparent;
    animation: lds-dual-ring 1.2s linear infinite;
}

#loading-indicator-content p {
    margin-top: 0;
    text-align: center;
    color: var(--dark);
    font-weight: 500;
    font-size: 1.1rem;
}

#error-message {
    background-color: #fef2f2;
    border: 1px solid #fecaca;
    color: #b91c1c;
    padding: 0.75rem 1rem;
    border-radius: 0.375rem;
    margin-bottom: 1.5rem;
}

#error-message .fa {
    margin-right: 0.5rem;
}

.assigned-pin-badge {
    margin-left: 0.5rem;
    font-size: 0.75rem;
    padding: 2px 8px;
    background-color: rgba(54, 207, 201, 0.2);
    color: var(--configuredBorder);
    border-radius: 9999px;
}

.function-item .flex .fa,
.function-pin-item .flex .fa {
    font-size: 0.75rem;
    color: #6b7280;
    transition: transform 0.3s;
}

.function-item .function-pins,
.function-pin-item .physical-pins-list {
    margin-left: 1rem;
}

.function-item .function-pins>*:not(:last-child),
.function-pin-item .physical-pins-list>*:not(:last-child) {
    margin-bottom: 0.25rem;
}

.btn {
    background-color: transparent !important;
    border-width: 1px !important;
    border-style: solid !important;
    margin-top: 0 !important;
}

@media (min-width: 1024px) {
    .main-layout {
        flex-direction: row;
        justify-content: space-between;
        gap: 1.5rem;
    }

    .config-panel {
        width: 400px;
        max-width: 450px;
        flex-shrink: 0;
    }

    .diagram-panel {
        flex: 1;
        min-width: 0;
    }
}

.svg-wrapper.is-dragging {
    transition: none !important;
}

/* 为 Konva 容器添加样式 */
#konva-container {
    width: 100%;
    height: 100%;
    overflow: hidden;
    /* 隐藏 Konva 自动添加的滚动条 */
}

.diagram-container {
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
}

#diagram-placeholder {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    height: 100%;
    color: #6b7280;
    /* text-gray-500 */
}

.swal2-html-container {
    text-align: left !important;
}