/**
 * WordPress 术语注释插件 - 前台样式
 *
 * 所有选择器以 .wpsg-glossary-* 开头，确保零全局污染
 * 高特异性CSS，不与主题冲突
 *
 * @package WPSG\Assets\CSS
 * @version 1.0.0
 */

/* ============================================================
   术语标记样式
   ============================================================ */

/* 术语标记基础样式 - 底部虚线边框，cursor: help，颜色继承 */
.wpsg-glossary-term {
    position: relative;
    display: inline;
    color: inherit;
    text-decoration: none;
    border-bottom: 1px dashed currentColor;
    cursor: help;
    transition: background-color 0.2s ease, color 0.2s ease;
    padding: 0 1px;
    line-height: inherit;
    font-size: inherit;
    font-weight: inherit;
    font-family: inherit;
    vertical-align: baseline;
}

/* 术语标记hover状态 - 背景高亮 */
.wpsg-glossary-term:hover,
.wpsg-glossary-term.wpsg-glossary-term--active {
    background-color: rgba(79, 70, 229, 0.1);
    border-bottom-color: #4F46E5;
    color: #4F46E5;
}

/* 术语标记链接样式（SEO内链模式） */
.wpsg-glossary-term a.wpsg-glossary-term-link {
    color: inherit;
    text-decoration: none;
    border-bottom: none;
    cursor: pointer;
    display: inline;
    font-size: inherit;
    font-weight: inherit;
}

.wpsg-glossary-term a.wpsg-glossary-term-link:hover {
    color: inherit;
    text-decoration: none;
}

/* 术语图标 - 小圆圈，右上角 */
.wpsg-glossary-term-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 14px;
    height: 14px;
    min-width: 14px;
    font-size: 10px;
    font-weight: 700;
    line-height: 1;
    text-align: center;
    vertical-align: super;
    margin-left: 1px;
    color: #fff;
    background-color: #4F46E5;
    border-radius: 50%;
    cursor: help;
    transition: background-color 0.2s ease, transform 0.2s ease;
    user-select: none;
    -webkit-user-select: none;
}

.wpsg-glossary-term:hover .wpsg-glossary-term-icon,
.wpsg-glossary-term.wpsg-glossary-term--active .wpsg-glossary-term-icon {
    background-color: #3730A3;
    transform: scale(1.1);
}

/* ============================================================
   弹窗样式
   ============================================================ */

/* 弹窗容器 */
.wpsg-glossary-popup {
    position: absolute;
    z-index: 999999;
    width: 100%;
    max-width: 400px;
    min-width: 260px;
    background-color: #ffffff;
    border-radius: 12px;
    box-shadow:
        0 4px 6px -1px rgba(0, 0, 0, 0.1),
        0 10px 15px -3px rgba(0, 0, 0, 0.1),
        0 20px 25px -5px rgba(0, 0, 0, 0.05);
    border: 1px solid rgba(0, 0, 0, 0.06);
    overflow: visible;
    opacity: 0;
    visibility: hidden;
    transform: translateY(8px) scale(0.96);
    transition:
        opacity 0.25s cubic-bezier(0.4, 0, 0.2, 1),
        transform 0.25s cubic-bezier(0.4, 0, 0.2, 1),
        visibility 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    pointer-events: none;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans SC", sans-serif;
    font-size: 14px;
    line-height: 1.6;
    color: #1F2937;
}

/* 弹窗显示状态 */
.wpsg-glossary-popup.wpsg-glossary-popup--visible {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

/* 弹窗箭头指示器 */
.wpsg-glossary-popup__arrow {
    position: absolute;
    width: 12px;
    height: 12px;
    background-color: #ffffff;
    border: 1px solid rgba(0, 0, 0, 0.06);
    transform: rotate(45deg);
    z-index: 1;
}

/* 箭头朝上（弹窗在术语下方时） */
.wpsg-glossary-popup__arrow--top {
    top: -7px;
    left: 50%;
    margin-left: -6px;
    border-right: none;
    border-bottom: none;
}

/* 箭头朝下（弹窗在术语上方时） */
.wpsg-glossary-popup__arrow--bottom {
    bottom: -7px;
    left: 50%;
    margin-left: -6px;
    border-left: none;
    border-top: none;
}

/* 箭头偏左 */
.wpsg-glossary-popup__arrow--left {
    left: 24px;
    margin-left: 0;
}

/* 箭头偏右 */
.wpsg-glossary-popup__arrow--right {
    left: auto;
    right: 24px;
    margin-left: 0;
}

/* 弹窗标题栏 */
.wpsg-glossary-popup__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 18px 10px;
    border-bottom: 1px solid #F3F4F6;
    background: linear-gradient(135deg, #F9FAFB 0%, #F3F4F6 100%);
    border-radius: 12px 12px 0 0;
}

/* 术语名称 */
.wpsg-glossary-popup__title {
    margin: 0;
    padding: 0;
    font-size: 16px;
    font-weight: 600;
    color: #111827;
    line-height: 1.4;
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* 分类标签 */
.wpsg-glossary-popup__category {
    display: inline-block;
    padding: 2px 8px;
    margin-left: 10px;
    font-size: 11px;
    font-weight: 500;
    color: #4F46E5;
    background-color: #EEF2FF;
    border-radius: 10px;
    white-space: nowrap;
    flex-shrink: 0;
    line-height: 1.5;
}

/* 弹窗关闭按钮 */
.wpsg-glossary-popup__close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    margin-left: 8px;
    padding: 0;
    border: none;
    background: transparent;
    color: #9CA3AF;
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
    border-radius: 4px;
    transition: background-color 0.15s ease, color 0.15s ease;
    flex-shrink: 0;
}

.wpsg-glossary-popup__close:hover {
    background-color: #F3F4F6;
    color: #374151;
}

/* 弹窗内容区 */
.wpsg-glossary-popup__body {
    padding: 14px 18px;
    font-size: 14px;
    line-height: 1.7;
    color: #374151;
    max-height: 200px;
    overflow-y: auto;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

/* 内容区滚动条美化 */
.wpsg-glossary-popup__body::-webkit-scrollbar {
    width: 4px;
}

.wpsg-glossary-popup__body::-webkit-scrollbar-track {
    background: transparent;
}

.wpsg-glossary-popup__body::-webkit-scrollbar-thumb {
    background-color: #D1D5DB;
    border-radius: 2px;
}

.wpsg-glossary-popup__body::-webkit-scrollbar-thumb:hover {
    background-color: #9CA3AF;
}

/* ============================================================
   多含义标签页样式
   ============================================================ */

/* 多含义术语的特殊标记 - 渐变图标 */
.wpsg-glossary-term[data-has-multiple="true"] .wpsg-glossary-term-icon {
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
}

/* 多含义标签页容器 */
.wpsg-glossary-meanings-tabs {
    display: flex;
    gap: 4px;
    margin-bottom: 12px;
    flex-wrap: wrap;
}

/* 多含义标签页按钮 */
.wpsg-glossary-meanings-tab {
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 12px;
    cursor: pointer;
    border: 1px solid rgba(0, 0, 0, 0.1);
    background: rgba(79, 70, 229, 0.06);
    color: #6B7280;
    transition: all 0.2s ease;
    white-space: nowrap;
    font-family: inherit;
    line-height: 1.5;
}

.wpsg-glossary-meanings-tab:hover {
    background: rgba(79, 70, 229, 0.12);
    color: #4F46E5;
    border-color: rgba(79, 70, 229, 0.2);
}

.wpsg-glossary-meanings-tab.wpsg-glossary-meanings-tab--active {
    background: rgba(79, 70, 229, 0.15);
    color: #4F46E5;
    border-color: rgba(79, 70, 229, 0.3);
    font-weight: 500;
}

/* 多含义内容区 */
.wpsg-glossary-meaning-content {
    animation: wpsgFadeIn 0.2s ease;
}

.wpsg-glossary-meaning-content.wpsg-glossary-meaning-content--hidden {
    display: none;
}

/* 多含义淡入动画 */
@keyframes wpsgFadeIn {
    from { opacity: 0; transform: translateY(4px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* 多含义数量标签 */
.wpsg-glossary-meanings-count {
    display: inline-block;
    background: rgba(79, 70, 229, 0.1);
    color: #6366F1;
    font-size: 11px;
    padding: 1px 8px;
    border-radius: 10px;
    margin-left: 8px;
    font-weight: normal;
    line-height: 1.5;
    vertical-align: middle;
}

/* 弹窗底部 - 来源信息 */
.wpsg-glossary-popup__footer {
    display: flex;
    align-items: center;
    padding: 10px 18px;
    border-top: 1px solid #F3F4F6;
    background-color: #FAFAFA;
    border-radius: 0 0 12px 12px;
    font-size: 12px;
    color: #9CA3AF;
}

.wpsg-glossary-popup__source-label {
    font-weight: 500;
    margin-right: 4px;
}

.wpsg-glossary-popup__source-name {
    color: #6B7280;
    font-weight: 400;
}

/* ============================================================
   弹窗遮罩层（移动端使用）
   ============================================================ */

.wpsg-glossary-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 999998;
    background-color: rgba(0, 0, 0, 0.3);
    opacity: 0;
    visibility: hidden;
    transition:
        opacity 0.25s cubic-bezier(0.4, 0, 0.2, 1),
        visibility 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    pointer-events: none;
}

.wpsg-glossary-overlay.wpsg-glossary-overlay--visible {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

/* ============================================================
   术语详情页样式
   ============================================================ */

.wpsg-glossary-detail-page {
    max-width: 800px;
    margin: 0 auto;
    padding: 40px 20px;
}

.wpsg-glossary-detail__header {
    margin-bottom: 30px;
    padding-bottom: 20px;
    border-bottom: 2px solid #F3F4F6;
}

.wpsg-glossary-detail__title {
    font-size: 28px;
    font-weight: 700;
    color: #111827;
    margin: 0 0 12px;
    line-height: 1.3;
}

.wpsg-glossary-detail__categories {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.wpsg-glossary-detail__category {
    display: inline-block;
    padding: 4px 12px;
    font-size: 13px;
    font-weight: 500;
    color: #4F46E5;
    background-color: #EEF2FF;
    border-radius: 12px;
}

.wpsg-glossary-detail__content {
    font-size: 16px;
    line-height: 1.8;
    color: #374151;
}

.wpsg-glossary-detail__footer {
    margin-top: 40px;
    padding-top: 20px;
    border-top: 1px solid #F3F4F6;
}

.wpsg-glossary-detail__back {
    display: inline-block;
    padding: 8px 16px;
    color: #4F46E5;
    text-decoration: none;
    border-radius: 6px;
    transition: background-color 0.2s ease;
    font-size: 14px;
}

.wpsg-glossary-detail__back:hover {
    background-color: #EEF2FF;
    text-decoration: none;
}

/* ============================================================
   响应式设计
   ============================================================ */

/* 平板端 */
@media screen and (max-width: 768px) {
    .wpsg-glossary-popup {
        position: fixed;
        top: auto !important;
        bottom: 0 !important;
        left: 0 !important;
        right: 0 !important;
        max-width: 100%;
        width: 100%;
        border-radius: 16px 16px 0 0;
        transform: translateY(100%);
        box-shadow:
            0 -4px 6px -1px rgba(0, 0, 0, 0.1),
            0 -10px 15px -3px rgba(0, 0, 0, 0.1);
    }

    .wpsg-glossary-popup.wpsg-glossary-popup--visible {
        transform: translateY(0);
    }

    .wpsg-glossary-popup__arrow {
        display: none;
    }

    .wpsg-glossary-popup__body {
        max-height: 40vh;
    }

    /* 移动端术语图标稍大 */
    .wpsg-glossary-term-icon {
        width: 16px;
        height: 16px;
        min-width: 16px;
        font-size: 11px;
    }
}

/* 小屏手机 */
@media screen and (max-width: 480px) {
    .wpsg-glossary-popup__header {
        padding: 12px 16px 8px;
    }

    .wpsg-glossary-popup__title {
        font-size: 15px;
    }

    .wpsg-glossary-popup__body {
        padding: 12px 16px;
        font-size: 13px;
        max-height: 35vh;
    }

    .wpsg-glossary-popup__footer {
        padding: 8px 16px;
    }

    .wpsg-glossary-detail-page {
        padding: 20px 16px;
    }

    .wpsg-glossary-detail__title {
        font-size: 24px;
    }
}

/* 桌面端适当最大宽度 */
@media screen and (min-width: 769px) {
    .wpsg-glossary-popup {
        max-width: 420px;
    }
}

/* 大屏桌面端 */
@media screen and (min-width: 1200px) {
    .wpsg-glossary-popup {
        max-width: 440px;
    }
}

/* ============================================================
   深色模式兼容
   ============================================================ */

@media (prefers-color-scheme: dark) {
    /* 术语标记 */
    .wpsg-glossary-term {
        border-bottom-color: rgba(255, 255, 255, 0.4);
    }

    .wpsg-glossary-term:hover,
    .wpsg-glossary-term.wpsg-glossary-term--active {
        background-color: rgba(129, 140, 248, 0.2);
        border-bottom-color: #818CF8;
        color: #A5B4FC;
    }

    /* 术语图标 */
    .wpsg-glossary-term-icon {
        background-color: #818CF8;
        color: #1E1B4B;
    }

    .wpsg-glossary-term:hover .wpsg-glossary-term-icon,
    .wpsg-glossary-term.wpsg-glossary-term--active .wpsg-glossary-term-icon {
        background-color: #A5B4FC;
    }

    /* 弹窗 */
    .wpsg-glossary-popup {
        background-color: #1F2937;
        border-color: rgba(255, 255, 255, 0.1);
        box-shadow:
            0 4px 6px -1px rgba(0, 0, 0, 0.3),
            0 10px 15px -3px rgba(0, 0, 0, 0.3),
            0 20px 25px -5px rgba(0, 0, 0, 0.2);
        color: #E5E7EB;
    }

    /* 箭头 */
    .wpsg-glossary-popup__arrow {
        background-color: #1F2937;
        border-color: rgba(255, 255, 255, 0.1);
    }

    /* 标题栏 */
    .wpsg-glossary-popup__header {
        border-bottom-color: rgba(255, 255, 255, 0.08);
        background: linear-gradient(135deg, #1F2937 0%, #111827 100%);
    }

    .wpsg-glossary-popup__title {
        color: #F9FAFB;
    }

    .wpsg-glossary-popup__category {
        color: #A5B4FC;
        background-color: rgba(129, 140, 248, 0.2);
    }

    .wpsg-glossary-popup__close {
        color: #6B7280;
    }

    .wpsg-glossary-popup__close:hover {
        background-color: rgba(255, 255, 255, 0.1);
        color: #E5E7EB;
    }

    /* 内容区 */
    .wpsg-glossary-popup__body {
        color: #D1D5DB;
    }

    .wpsg-glossary-popup__body::-webkit-scrollbar-thumb {
        background-color: #4B5563;
    }

    .wpsg-glossary-popup__body::-webkit-scrollbar-thumb:hover {
        background-color: #6B7280;
    }

    /* 底部 */
    .wpsg-glossary-popup__footer {
        border-top-color: rgba(255, 255, 255, 0.08);
        background-color: #111827;
        color: #6B7280;
    }

    .wpsg-glossary-popup__source-name {
        color: #9CA3AF;
    }

    /* 遮罩层 */
    .wpsg-glossary-overlay {
        background-color: rgba(0, 0, 0, 0.5);
    }

    /* 术语详情页 */
    .wpsg-glossary-detail__title {
        color: #F9FAFB;
    }

    .wpsg-glossary-detail__category {
        color: #A5B4FC;
        background-color: rgba(129, 140, 248, 0.2);
    }

    .wpsg-glossary-detail__content {
        color: #D1D5DB;
    }

    .wpsg-glossary-detail__header {
        border-bottom-color: rgba(255, 255, 255, 0.1);
    }

    .wpsg-glossary-detail__footer {
        border-top-color: rgba(255, 255, 255, 0.1);
    }

    .wpsg-glossary-detail__back {
        color: #A5B4FC;
    }

    .wpsg-glossary-detail__back:hover {
        background-color: rgba(129, 140, 248, 0.15);
    }

    /* 多含义标签页 - 深色模式适配 */
    .wpsg-glossary-meanings-tab {
        border-color: rgba(255, 255, 255, 0.12);
        background: rgba(129, 140, 248, 0.1);
        color: rgba(255, 255, 255, 0.6);
    }

    .wpsg-glossary-meanings-tab:hover {
        background: rgba(129, 140, 248, 0.2);
        color: #A5B4FC;
        border-color: rgba(129, 140, 248, 0.3);
    }

    .wpsg-glossary-meanings-tab.wpsg-glossary-meanings-tab--active {
        background: rgba(129, 140, 248, 0.25);
        color: #C7D2FE;
        border-color: rgba(129, 140, 248, 0.4);
    }

    /* 多含义数量标签 - 深色模式 */
    .wpsg-glossary-meanings-count {
        background: rgba(129, 140, 248, 0.2);
        color: #A5B4FC;
    }
}

/* ============================================================
   打印样式
   ============================================================ */

@media print {
    .wpsg-glossary-term {
        border-bottom-style: solid;
        cursor: default;
    }

    .wpsg-glossary-term-icon {
        display: none;
    }

    .wpsg-glossary-popup,
    .wpsg-glossary-overlay {
        display: none !important;
    }
}

/* ============================================================
   无障碍样式
   ============================================================ */

/* 焦点可见状态 */
.wpsg-glossary-term:focus,
.wpsg-glossary-term a.wpsg-glossary-term-link:focus {
    outline: 2px solid #4F46E5;
    outline-offset: 2px;
    border-radius: 2px;
}

.wpsg-glossary-popup__close:focus {
    outline: 2px solid #4F46E5;
    outline-offset: 2px;
}

/* 减少动画偏好 */
@media (prefers-reduced-motion: reduce) {
    .wpsg-glossary-term,
    .wpsg-glossary-term-icon,
    .wpsg-glossary-popup,
    .wpsg-glossary-overlay {
        transition: none !important;
    }

    .wpsg-glossary-popup {
        transform: none !important;
    }

    .wpsg-glossary-popup.wpsg-glossary-popup--visible {
        opacity: 1;
        visibility: visible;
    }

    /* 多含义内容切换动画禁用 */
    .wpsg-glossary-meaning-content {
        animation: none !important;
    }

    .wpsg-glossary-meanings-tab {
        transition: none !important;
    }
}

/* 高对比度模式 */
@media (prefers-contrast: high) {
    .wpsg-glossary-term {
        border-bottom-width: 2px;
        border-bottom-style: solid;
    }

    .wpsg-glossary-popup {
        border-width: 2px;
        border-color: #000;
    }

    .wpsg-glossary-popup__header {
        border-bottom-width: 2px;
    }

    .wpsg-glossary-popup__footer {
        border-top-width: 2px;
    }
}
