/**
 * 原始标签 + Sticky 标签 - 公共样式
 * 供 NHANES / CHARLS / ELSA / CRELES / Harmonized 等数据页面共用
 * 各页面特异覆盖可保留在对应 *_table.css
 */

/* ================= */
/* 原始标签区域 - 基础样式 */
/* ================= */

/* 标签基础样式 */
.tag {
    display: inline-flex;
    align-items: center;
    justify-content: flex-start; /* 避免聚焦时 tag-text↔tag-input 切换导致 delete-btn 位移 */
    gap: 5px;
    margin: 6px;
    padding: 4px 8px;
    background: transparent;
    border: 1px solid rgba(255, 208, 22, 0.4);
    border-radius: 12px;
    font-size: 13px;
    line-height: 1.2;
    color: #FFD016;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    cursor: default;
    width: 128px;
    box-sizing: border-box;
    position: relative;
}

.tag.dragging {
    opacity: 0.45;
    cursor: grabbing;
}

.tag.drag-over {
    box-shadow: 0 0 0 2px rgba(255, 208, 22, 0.6);
}

/* 标签删除按钮样式 */
.tag .delete-btn {
    width: 20px;
    height: 20px;
    line-height: 18px;
    text-align: center;
    border-radius: 50%;
    cursor: pointer;
    color: #FFD016;
    font-size: 14px;
    font-weight: 600;
    transition: all 0.3s ease;
    background: rgba(0, 161, 214, 0.1);
    flex-shrink: 0;
    border: 1px solid rgba(0, 161, 214, 0.4);
    line-height: 1;
}

.tag:hover .delete-btn {
    color: #888;
    background: rgba(255, 255, 255, 0.2);
    border-color: rgba(255, 255, 255, 0.3);
}

.tag .delete-btn:hover {
    color: #f56c6c;
    background: rgba(255, 255, 255, 0.3);
    transform: scale(1.1);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

/* 标签列表区域 */
.tag-list {
    flex: 1;
    min-height: 100px;
    padding: 8px;
    border-radius: 6px;
    margin: 0;
}

/* 标签文本样式 防止溢出 */
.tag .tag-text {
    cursor: text;
    padding: 2px 4px;
    border-radius: 4px;
    transition: background-color 0.2s;
    display: inline-block;
    width: 80px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: #FFD016;
}

/* 编辑状态下的标签样式 - 展开模式宽度自适应 */
.tag.editing {
    width: auto;
    transition: none; /* 禁用 transition，避免 tag-text↔tag-input 切换时 Y 位移跳动 */
}

/* 收起模式：编辑时标签宽度保持不变 */
.tag-list:not(.expanded-mode) .tag.editing {
    width: 128px;
}

/* 展开模式 input 宽度测量用（隐藏，不占位） */
.tag .tag-input-sizer {
    position: absolute;
    visibility: hidden;
    white-space: pre;
    overflow: hidden;
    padding: 2px 4px;
    margin: 0;
    border: 0;
    font: inherit;
    pointer-events: none;
}
/* 收起模式：inputSizer 需与 edit-tooltip .tag-input 完全一致，否则测量偏小导致文字被裁剪 */
.tag-list:not(.expanded-mode) .tag.editing .tag-input-sizer {
    padding: 6px 10px;
    font-size: 12px;
    font-weight: 600;
}
/* 白天模式：inputSizer 需与 tag-input 的 padding 一致，否则 resizeInputToContent 测量偏小导致文字被裁剪 */
[data-theme="light"] .tag .tag-input-sizer {
    padding: 6px 12px;
}

/* 展开模式编辑时：tag-text 保持占位，tag-input 绝对定位覆盖，避免其它标签下移抖动；收起模式 tooltip 保持原样 */
.tag-list.expanded-mode .tag.editing {
    z-index: 1; /* 长文本时不被相邻 tag 覆盖 */
    overflow: visible; /* 聚焦编辑时可溢出，方便输入长文本 */
}
.tag-list.expanded-mode .tag.editing .tag-text {
    display: inline-block !important;
    opacity: 0;
    pointer-events: none;
}
.tag-list.expanded-mode .tag.editing > .tag-input {
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    max-width: 300px;
    overflow: visible; /* 聚焦时可溢出 */
}
.tag.editing .tag-input {
    width: auto;
    min-width: 0;
    border: none;
    background: transparent;
    color: inherit;
    font-size: inherit;
    font-family: inherit;
    font-weight: inherit;
    line-height: inherit;
    letter-spacing: inherit;
    padding: 2px 4px;
    margin: 0;
    outline: none;
    box-sizing: border-box;
    vertical-align: baseline;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
}

/* 展开模式下的标签样式 - 只适用于原标签面板，宽度自适应 */
.tag-list.expanded-mode .tag {
    width: auto;
    max-width: 300px;
    min-width: 0;
    flex-shrink: 0;
    overflow: hidden; /* 非聚焦时内容不溢出 */
}

.tag-list.expanded-mode .tag .tag-text {
    width: auto;
    max-width: 100%;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis; /* 长文本省略号，不溢出；悬停 tooltip 可看全文 */
}

/* ================= */
/* 标签 Tooltip 悬浮提示 */
/* ================= */

.tag .tooltip {
    visibility: hidden;
    position: absolute;
    padding: 12px;
    background-color: var(--light-bg);
    border: 1px solid rgba(232, 229, 224, 0.4);
    border-radius: 4px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    font-size: 13px;
    max-width: 400px;
    width: max-content;
    z-index: 1000;
    opacity: 0;
    transition: opacity 0.2s, visibility 0.2s;
    pointer-events: none;
    white-space: normal;
    word-break: break-word;
    /* 默认位置：居中上方 */
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    margin-bottom: 8px;
}

/* 左下角位置（tag 加 tooltip-left 或 tooltip 加 tooltip-bottom-left） */
.tag.tooltip-left .tooltip,
.tag .tooltip.tooltip-bottom-left {
    bottom: auto;
    top: 100%;
    left: 0;
    right: auto;
    transform: none;
    margin-bottom: 0;
    margin-top: 8px;
}

/* 右下角位置（tag 加 tooltip-right 或 tooltip 加 tooltip-bottom-right） */
.tag.tooltip-right .tooltip,
.tag .tooltip.tooltip-bottom-right {
    bottom: auto;
    top: 100%;
    left: auto;
    right: 0;
    transform: none;
    margin-bottom: 0;
    margin-top: 8px;
}

/* 默认箭头（居中上方） */
.tag .tooltip::after {
    content: '';
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    border-width: 6px;
    border-style: solid;
    border-color: var(--light-bg) transparent transparent transparent;
}

/* 左下角/右下角 tooltip 的箭头 */
.tag.tooltip-left .tooltip::after,
.tag .tooltip.tooltip-bottom-left::after {
    top: auto;
    bottom: 100%;
    left: 10px;
    right: auto;
    transform: none;
    border-color: transparent transparent var(--light-bg) transparent;
}

.tag.tooltip-right .tooltip::after,
.tag .tooltip.tooltip-bottom-right::after {
    top: auto;
    bottom: 100%;
    left: auto;
    right: 10px;
    transform: none;
    border-color: transparent transparent var(--light-bg) transparent;
}

.tag:hover .tooltip {
    visibility: visible;
    opacity: 1;
}

.tooltip-variable {
    color: #000;
    font-weight: 500;
    margin-bottom: 8px;
    display: block;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.tooltip-description {
    color: #666;
    line-height: 1.5;
    white-space: pre-line;
}

/* ================= */
/* 收起模式 - 编辑 Tooltip（上方实时显示编辑内容） */
/* ================= */

.tag .edit-tooltip {
    display: none;
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    margin-bottom: 8px;
    padding: 8px 12px;
    background-color: #96969650;
    border: 1px solid rgba(232, 229, 224, 0.4);
    border-radius: 6px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    z-index: 1001;
    pointer-events: auto;
    white-space: nowrap;
    overflow: visible; /* 允许 input 随内容变宽时溢出，避免裁剪 */
}

/* 收起模式 + 编辑状态：显示 edit-tooltip */
.tag-list:not(.expanded-mode) .tag.editing .edit-tooltip {
    display: block;
}

.tag .edit-tooltip .tag-input {
    border: 1px solid rgba(255, 208, 22, 0.5);
    border-radius: 20px;
    background: #F7D378;
    color: #000000;
    font-size: 12px;
    font-weight: 600;
    padding: 6px 10px;
    min-width: 120px;
    outline: none;
}

.tag .edit-tooltip::after {
    content: '';
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    border-width: 6px;
    border-style: solid;
    border-color: #96969650 transparent transparent transparent;
}

/* 白天模式 - edit-tooltip */
[data-theme="light"] .tag .edit-tooltip {
    background-color: #96969650;
    border-color: #E5E7EB;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

[data-theme="light"] .tag .edit-tooltip .tag-input {
    background: #F9FAFB;
    color: #000;
    border-color: #D1D5DB;
}

[data-theme="light"] .tag .edit-tooltip::after {
    border-color: #96969650 transparent transparent transparent;
}

/* ================= */
/* Sticky 标签面板样式 */
/* ================= */

.sticky-tags-panel {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 150;
    background: rgba(77, 77, 77, 0.95);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid rgba(255, 208, 22, 0.3);
    transform: translateY(-100%);
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.15);
}

.sticky-tags-panel.visible {
    transform: translateY(0);
    opacity: 1;
    visibility: visible;
}

.sticky-tags-container {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 8px 16px;
    max-width: 90%;
    margin: 0 auto;
}

.sticky-tag-list {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 8px;
    overflow-x: auto;
    overflow-y: hidden;
    white-space: nowrap;
    scroll-behavior: smooth;
    padding: 4px 0;
    padding-right: 150px;
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 208, 22, 0.5) transparent;
}

.sticky-tag-list::-webkit-scrollbar {
    height: 4px;
}

.sticky-tag-list::-webkit-scrollbar-track {
    background: transparent;
}

.sticky-tag-list::-webkit-scrollbar-thumb {
    background: rgba(255, 208, 22, 0.5);
    border-radius: 2px;
}

.sticky-tag-list::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 208, 22, 0.7);
}

/* Sticky 标签样式 - 与原始标签外观对齐（黑夜模式），始终为展开模式 */
.sticky-tag-list .tag {
    flex-shrink: 0;
    margin: 0;
    padding: 4px 8px;
    min-width: 0;
    width: auto;
    max-width: 300px;
    overflow: hidden; /* 非聚焦时内容不溢出，与原始标签一致 */
    font-size: 13px;
    line-height: 1.2;
    color: #FFD016;
    border: 1px solid rgba(255, 208, 22, 0.4);
    background: transparent;
    border-radius: 12px;
    display: flex;
    align-items: center;
    gap: 6px;
    box-sizing: border-box;
}

.sticky-tag-list .tag .tag-text {
    padding: 2px 4px;
    border-radius: 4px;
    color: #FFD016;
    width: auto;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis; /* 长文本省略号，不溢出；与原始标签一致 */
    white-space: nowrap;
    cursor: pointer;
}

.sticky-tag-list .tag .tag-input {
    display: none;
    width: auto;
    padding: 2px 4px;
    border: none;
    border-radius: 4px;
    background: transparent;
    color: inherit;
    font-size: inherit;
    font-family: inherit;
    font-weight: inherit;
    line-height: inherit;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
}

.sticky-tag-list .tag.editing {
    z-index: 1; /* 长文本时不被相邻 tag 覆盖 */
    overflow: visible; /* 聚焦时可溢出 */
}
.sticky-tag-list .tag.editing .tag-text {
    display: inline-block !important;
    opacity: 0;
    pointer-events: none;
}
.sticky-tag-list .tag.editing .tag-input {
    display: block;
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    max-width: 300px;
    overflow: visible; /* 聚焦时可溢出 */
    padding: 2px 4px;
    /* 黑夜模式：键入时黄底黑字，圆角与 tag-text 一致 */
    background: #F7D378;
    border-radius: 11px;
    color: #000000;
}

/* 原始标签（展开模式）黑夜：键入时黄底黑字，圆角与 tag-text 一致 */
.tag-list.expanded-mode .tag.editing .tag-input {
    background: #F7D378;
    border-radius: 11px;
    color: #000000;
}

[data-theme="light"] .tag-list.expanded-mode .tag.editing .tag-input {
    background: #ffffff;
    color: #000000;
    border: none;
    box-shadow: inset 0 0 0 1px #A51111 !important;
}


.sticky-tag-list .tag .delete-btn {
    width: 20px;
    height: 20px;
    line-height: 18px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    color: #FFD016;
    background: rgba(0, 161, 214, 0.1);
    flex-shrink: 0;
    border: 1px solid rgba(0, 161, 214, 0.4);
    border-radius: 50%;
    text-align: center;
    line-height: 1;
}

/* Sticky 操作按钮（面板内隐藏，由原标签区提供） */
.sticky-tag-actions,
.sticky-action-btn,
.sticky-action-btn:hover,
.sticky-action-btn.primary,
.sticky-action-btn.primary:hover {
    display: none;
}

.sticky-tag-list .sticky-empty-tip {
    color: rgba(232, 229, 224, 0.7);
    font-size: 11px;
    font-style: italic;
    padding: 0 8px;
    white-space: nowrap;
}


.sticky-tag-list.expanded-mode .tag {
    width: auto;
    max-width: 300px;
    min-width: 0;
    flex-shrink: 0;
    overflow: hidden; /* 非聚焦时内容不溢出 */
}
.sticky-tag-list.expanded-mode .tag.editing {
    overflow: visible; /* 聚焦时可溢出 */
}

.sticky-tag-list.expanded-mode .tag .tag-text {
    width: auto;
    max-width: 100%;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis; /* 长文本省略号，不溢出 */
}

.sticky-tag-list.expanded-mode .tag .tag-input {
    width: auto;
}

/* =============================== */
/* 白天模式 - 原始标签样式 */
/* =============================== */

/* 白天模式 tag-text 与 tag-input 完全一致(display/height/对齐)，避免展开编辑时其它标签下移抖动 */
[data-theme="light"] .tag .tag-text {
    color: #000000;
    background: #ffd239;
    border: none;
    border-radius: 20px;
    font-weight: 600;
    padding: 6px 12px;
    transition: none;
    min-height: 28px;
    height: 28px;
    box-sizing: border-box;
    display: inline-block;
    vertical-align: middle;
    line-height: 16px;
}

[data-theme="light"] .tag:nth-child(5n+1) .tag-text { background: #ffd239; }
[data-theme="light"] .tag:nth-child(5n+2) .tag-text { background: #eda4ea; }
[data-theme="light"] .tag:nth-child(5n+3) .tag-text { background: #6fd090; }
[data-theme="light"] .tag:nth-child(5n+4) .tag-text { background: #f9a696; }
[data-theme="light"] .tag:nth-child(5n+5) .tag-text { background: #71c4ec; }

/* 白天模式：移除 tag-text hover 的 transform，避免聚焦时 tag-text↔tag-input 切换导致上移跳动 */
[data-theme="light"] .tag:hover .tag-text {
    transform: translateY(-1px) scale(1.02);
}


[data-theme="light"] .tag.editing .tag-input {
    color: #000000;
    background: #ffffff;
    border-radius: 11px !important; 
    font-weight: 600;
    padding: 6px 12px; /* 与 tag-text 一致，避免文本末尾多余占位 */
    transition: none;
    box-sizing: border-box;
    line-height: 16px;
    font-size: inherit;
    font-family: inherit;
    min-height: 36px;
    height: 36px;
    display: inline-block;
    vertical-align: middle;
    outline: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
}

[data-theme="light"] .tag .delete-btn {
    color: #9CA3AF;
    background: #F9FAFB;
    border-radius: 3px;
}

[data-theme="light"] .tag:hover .delete-btn {
    color: #9CA3AF;
    background: #FEF2F2;
}

[data-theme="light"] .tag .delete-btn:hover {
    color: #DC2626;
    background: #FEF2F2;
    box-shadow: none;
}

/* =============================== */
/* 白天模式 - Sticky 标签样式 */
/* =============================== */

[data-theme="light"] .sticky-tags-panel {
    background: rgba(255, 255, 255, 0.97);
    border-bottom: 1px solid #E5E7EB;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
}

[data-theme="light"] .sticky-tag-list .tag {
    background: none;
    border: none;
    border-radius: 6px;
}

[data-theme="light"] .sticky-tag-list .tag .tag-text {
    color: #000000;
    background: #ffd239;
    border: none;
    border-radius: 20px;
    font-weight: 600;
    padding: 6px 12px;
    transition: all 0.3s ease;
}

[data-theme="light"] .sticky-tag-list .tag .tag-input {
    color: #000000;
    background: #ffd239;
    border: none;
    border-radius: 20px;
    font-weight: 600;
    padding: 6px 12px;
    transition: all 0.3s ease;
}

[data-theme="light"] .sticky-tag-list .tag.editing .tag-input {
    background: #ffffff;
    border: none;
    box-shadow: inset 0 0 0 1px #A51111; /* 内边框，不增加尺寸 */
    padding: 6px 12px; /* 与 tag-text 一致，避免文本末尾多余占位 */
}

[data-theme="light"] .sticky-tag-list .tag .delete-btn {
    color: #9CA3AF;
    background: #F9FAFB;
    border-radius: 3px;
}

[data-theme="light"] .sticky-tag-list .tag:hover .delete-btn {
    color: #9CA3AF;
    background: #FEF2F2;
}

[data-theme="light"] .sticky-tag-list .tag .delete-btn:hover {
    color: #DC2626;
    background: #FEF2F2;
}

[data-theme="light"] .sticky-tag-list .sticky-empty-tip {
    color: #9CA3AF;
    font-style: normal;
}

[data-theme="light"] .sticky-tag-list::-webkit-scrollbar-thumb {
    background: #D1D5DB;
    border-radius: 4px;
}

[data-theme="light"] .sticky-tag-list::-webkit-scrollbar-thumb:hover {
    background: #9CA3AF;
}

[data-theme="light"] .sticky-tag-list .tag:nth-child(5n+1) .tag-text { background: #ffd239; }
[data-theme="light"] .sticky-tag-list .tag:nth-child(5n+2) .tag-text { background: #eda4ea; }
[data-theme="light"] .sticky-tag-list .tag:nth-child(5n+3) .tag-text { background: #6fd090; }
[data-theme="light"] .sticky-tag-list .tag:nth-child(5n+4) .tag-text { background: #f9a696; }
[data-theme="light"] .sticky-tag-list .tag:nth-child(5n+5) .tag-text { background: #71c4ec; }

/* 白天模式 - 标签操作按钮悬停颜色 */
[data-theme="light"] .tag-actions .action-btn.icon-only:hover .fa-clone { color: #71c4ec; }
[data-theme="light"] .tag-actions .action-btn.icon-only:hover .fa-edit { color: #6fd090; }
[data-theme="light"] .tag-actions .action-btn.icon-only:hover .fa-arrows-alt,
[data-theme="light"] .tag-actions .action-btn.icon-only:hover .fa-compress-alt { color: #f9a696; }
[data-theme="light"] .tag-actions .action-btn.icon-only.clear-all-tags-btn:hover .fa-trash-alt { color: #ff000095; }
