/* ===== 报表设计器样式（仅报表相关部分，不含全局骨架） ===== */

body.is-dragging { user-select: none; cursor: grabbing; }
body.is-dragging .widget-header { cursor: grabbing; }

/* 通用页面 */
.rd-page-container { padding: 22px; max-width: 1400px; margin: 0 auto; width: 100%; }
.rd-page-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 18px; }
.rd-page-title { font-size: 22px; font-weight: 700; margin: 0; }
.rd-page-subtitle { color: #8a919f; margin-top: 4px; font-size: 13px; }

.rd-empty-state {
    background: #fff; border: 1px dashed #c0c4cc; border-radius: 12px;
    text-align: center; padding: 70px 20px; color: #8a919f;
}
.rd-empty-state .emoji { font-size: 46px; display: block; margin-bottom: 12px; }

/* 模板卡片 */
.rd-dashboard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(290px, 1fr));
    gap: 16px;
}
.rd-dashboard-card {
    background: #fff; border-radius: 12px; padding: 18px;
    box-shadow: 0 2px 10px rgba(31, 35, 41, .08); border: 1px solid transparent;
    transition: transform .15s, border-color .15s;
    display: flex; flex-direction: column;
}
.rd-dashboard-card:hover { transform: translateY(-3px); border-color: #2c6ef2; }
.rd-dashboard-card h5 { font-size: 16px; font-weight: 600; margin: 0 0 6px; }
.rd-dashboard-card .desc { color: #8a919f; font-size: 13px; min-height: 20px; flex: 1; }
.rd-dashboard-card .meta { color: #a3a8b4; font-size: 12px; margin: 10px 0; }
.rd-dashboard-card .actions { display: flex; gap: 8px; }

/* ===== 设计器三栏布局 ===== */
.rd-designer-page { flex: 1; display: flex; flex-direction: column; overflow: hidden; height: calc(100vh - 140px); }

.rd-designer-toolbar {
    background: #fff;
    border-bottom: 1px solid #e4e7ed;
    padding: 10px 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}
.rd-designer-toolbar .name-input { width: 220px; font-weight: 600; font-size: 15px; }
.rd-route-input {
    display: flex;
    align-items: center;
    border: 1px solid #ced4da;
    border-radius: 6px;
    overflow: hidden;
    background: #fff;
    flex-shrink: 0;
}
.rd-route-input:focus-within { border-color: #2c6ef2; box-shadow: 0 0 0 2px rgba(44,110,242,.15); }
.rd-route-prefix {
    padding: 0 8px 0 10px;
    font-size: 12px;
    color: #9aa0ab;
    background: #f4f5f7;
    align-self: stretch;
    display: flex;
    align-items: center;
    white-space: nowrap;
    border-right: 1px solid #e5e6eb;
}
.rd-route-input input {
    width: 190px;
    border: none !important;
    border-radius: 0 !important;
    font-size: 13px;
    font-family: Consolas, "SFMono-Regular", monospace;
}
.rd-route-input input:focus { box-shadow: none !important; }
.rd-toolbar-spacer { flex: 1; }

.rd-designer-body { flex: 1; display: flex; overflow: hidden; }

.rd-side-panel {
    width: 264px;
    min-width: 264px;
    background: #fff;
    overflow-y: auto;
    padding: 14px;
}
.rd-side-panel.left { border-right: 1px solid #e4e7ed; }
.rd-side-panel.right { border-left: 1px solid #e4e7ed; width: 300px; min-width: 300px; }

.rd-panel-section { margin-bottom: 22px; }
.rd-panel-section h6 {
    font-size: 12px; font-weight: 700; color: #8a919f;
    text-transform: uppercase; letter-spacing: .5px; margin: 0 0 10px;
}

/* 图表组件库 */
.rd-palette-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.rd-palette-item, .report-palette-item {
    border: 1px solid #e4e7ed;
    border-radius: 8px;
    background: #fafbfc;
    padding: 12px 6px;
    text-align: center;
    cursor: grab;
    transition: all .15s;
    font-size: 12px;
    color: #1f2329;
}
.rd-palette-item:hover, .report-palette-item:hover {
    border-color: #2c6ef2; color: #2c6ef2;
    background: #f0f5ff; transform: translateY(-1px);
}
.rd-palette-item .icon, .report-palette-item .icon { font-size: 20px; display: block; margin-bottom: 5px; }
.rd-palette-item:active, .report-palette-item:active { cursor: grabbing; }

/* 数据源列表 */
.datasource-card {
    border: 1px solid #e4e7ed; border-radius: 8px;
    margin-bottom: 10px; overflow: hidden;
}
.datasource-card .ds-title {
    background: #f7f8fa; padding: 8px 10px; font-weight: 600; font-size: 13px;
    display: flex; align-items: center; gap: 6px;
}
.datasource-card .ds-fields { padding: 6px 10px; display: flex; flex-wrap: wrap; gap: 5px; }
.field-chip {
    font-size: 11px; padding: 2px 8px; border-radius: 10px;
    background: #eef3ff; color: #3a64c9; border: 1px solid #d6e2ff;
}
.field-chip.measure { background: #ecf9f0; color: #1f8f4d; border-color: #cdeed8; }

/* 画布 */
.rd-canvas-scroll { flex: 1; overflow: auto; padding: 18px; }

.rd-canvas-empty {
    position: absolute; inset: 0;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    color: #b3b9c4; pointer-events: none;
}
.rd-canvas-empty .emoji { font-size: 52px; margin-bottom: 12px; }

/* 画布组件 */
.widget-card {
    position: absolute;
    background: #fff;
    border: 1px solid #e4e7ed;
    border-radius: 10px;
    box-shadow: 0 2px 10px rgba(31, 35, 41, .08);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.widget-card.selected {
    border-color: #2c6ef2;
    box-shadow: 0 0 0 2px rgba(44, 110, 242, .25), 0 2px 10px rgba(31, 35, 41, .08);
}
.widget-header {
    height: 40px; min-height: 40px;
    padding: 0 10px 0 14px;
    display: flex; align-items: center; gap: 8px;
    border-bottom: 1px solid #f0f1f4;
    background: #fafbfc;
    cursor: grab;
}
.widget-card.readonly .widget-header { cursor: default; background: transparent; }
.widget-title {
    font-weight: 600; font-size: 13px;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1;
}
.widget-badge {
    font-size: 11px; color: #2c6ef2; background: #eef3ff;
    padding: 1px 8px; border-radius: 9px;
}
.widget-del {
    border: none; background: transparent; color: #b3b9c4;
    font-size: 17px; line-height: 1; padding: 2px 6px; border-radius: 5px;
    cursor: pointer;
}
.widget-del:hover { color: #e34d4d; background: #fdeeee; }

.widget-body { flex: 1; position: relative; min-height: 0; padding: 6px 10px 10px; }
.widget-chart { width: 100%; height: 100%; min-height: 120px; }

.widget-resize-handle {
    position: absolute; right: 2px; bottom: 2px;
    width: 16px; height: 16px;
    cursor: nwse-resize;
    background: linear-gradient(135deg, transparent 50%, #c0c4cc 50%, #c0c4cc 60%, transparent 60%,
        transparent 70%, #c0c4cc 70%, #c0c4cc 80%, transparent 80%);
    opacity: .6;
}

/* 数字卡 */
.stat-body {
    height: 100%; display: flex; flex-direction: column;
    align-items: center; justify-content: center; gap: 6px;
}
.stat-value {
    font-size: 34px; font-weight: 700; color: #2c6ef2;
    line-height: 1.1; word-break: break-all;
}
.stat-label { font-size: 12px; color: #8a919f; }

/* 明细表 */
.table-wrap { height: 100%; overflow: auto; }
.widget-table { width: 100%; font-size: 12px; border-collapse: collapse; }
.widget-table th {
    background: #f7f8fa; padding: 7px 10px; text-align: left;
    font-weight: 600; color: #5c6370; white-space: nowrap;
    position: sticky; top: 0;
}
.widget-table td { padding: 6px 10px; border-top: 1px solid #f0f1f4; white-space: nowrap; }
.widget-table tr:hover td { background: #f8faff; }

.widget-loading, .widget-error, .widget-hint {
    height: 100%; min-height: 120px;
    display: flex; align-items: center; justify-content: center;
    color: #8a919f; font-size: 13px; text-align: center; padding: 10px;
}
.widget-error { color: #d4483c; }

/* 属性面板 */
.prop-group { margin-bottom: 16px; }
.prop-group label.form-label {
    font-size: 12px; font-weight: 600; color: #5c6370; margin-bottom: 5px;
    white-space: nowrap;
}
.prop-empty {
    text-align: center; color: #8a919f; font-size: 13px;
    border: 1px dashed #e4e7ed; border-radius: 8px; padding: 30px 12px;
}
.form-select, .form-control { font-size: 13px; }
.form-check-label { font-size: 13px; }

/* 多元素对齐工具栏 */
.rd-align-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
}
.rd-align-grid .btn { font-size: 12px; padding: 5px 6px; }
kbd {
    background: #eef3ff; color: #2c6ef2;
    padding: 1px 5px; border-radius: 3px;
    font-size: 11px; font-family: Consolas, monospace;
    border: 1px solid #d6e2ff;
}
.lh-base { line-height: 1.7; }
/* 多选主选高亮：最后选中元素=锚点，蓝框加粗以区分 */
.report-el.selected.multi-primary {
    box-shadow: 0 0 0 2.5px rgba(44, 110, 242, .55), 0 0 0 4px rgba(44, 110, 242, .15) !important;
    border-color: #2c6ef2 !important;
}

/* 加载遮罩 */
.rd-page-loading { padding: 80px 0; text-align: center; color: #8a919f; }
.rd-page-loading .spinner-border { color: #2c6ef2; }

/* ===== 报表：纸张与元素 ===== */
.report-paper-scroll {
    flex: 1; overflow: auto;
    padding: 22px;
    display: flex;
    justify-content: center;
    align-items: flex-start;
}
.report-paper {
    background: #fff;
    box-shadow: 0 4px 22px rgba(31, 35, 41, .16);
    border-radius: 2px;
}
.report-canvas { position: relative; }

.report-el {
    position: absolute;
    display: flex;
    flex-direction: column;
    color: #1f2329;
    border-radius: 2px;
}
.report-el.widget-card {
    border: 1px dashed #b9c2d6;
    box-shadow: none;
    background: transparent;
}
.report-el.widget-card:hover { border-color: #2c6ef2; }
.report-el.selected {
    border-style: solid !important;
    border-color: #2c6ef2 !important;
    box-shadow: 0 0 0 1.5px rgba(44, 110, 242, .35) !important;
}

/* 设计器浮层拖动条 */
.re-float-header {
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 14px; min-height: 14px;
    opacity: 0;
    padding: 0 4px;
    border-bottom: none;
    background: rgba(44, 110, 242, .18);
    border-radius: 2px 2px 0 0;
    z-index: 6;
    justify-content: flex-end;
}
.report-el:hover .re-float-header,
.report-el.selected .re-float-header { opacity: 1; }
.report-el .re-float-header .widget-badge { display: none; }
.report-el .re-float-header .widget-del { font-size: 12px; color: #2c6ef2; }

/* 文本元素 */
.re-label { flex: 1; width: 100%; display: flex; padding: 0 1mm; min-height: 0; }
.re-text {
    flex: 1;
    white-space: pre-wrap;
    word-break: break-word;
    line-height: 1.35;
}
.re-vc-top { align-items: flex-start; }
.re-vc-middle { align-items: center; }
.re-vc-bottom { align-items: flex-end; }

/* 分割线 */
.re-divider-wrap { flex: 1; width: 100%; display: flex; padding: 0 0.5mm; }
.re-divider { width: 100%; border-top: 0.3mm solid #333; }

/* 数据类元素 */
.re-el-title {
    font-size: 9.5pt;
    font-weight: 600;
    color: #5c6370;
    padding: 0 0 0.8mm;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.re-body { flex: 1; min-height: 0; position: relative; }
.re-table-body { overflow: hidden; }

.report-el .widget-loading,
.report-el .widget-error,
.report-el .widget-hint { min-height: 0; font-size: 9pt; }

.report-el .stat-value { font-size: 22px; }
.report-el .stat-label { font-size: 9pt; }

/* 报表表格 */
.re-table {
    width: 100%;
    border-collapse: collapse;
    table-layout: fixed;
}
.re-table th,
.re-table td {
    border: 1px solid #63656c;
    padding: 0.7mm 1.4mm;
    font-size: 9pt;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.re-table th { font-weight: 600; color: #1f2329; text-align: center; }
.re-total-row td { font-weight: 700; background: #f7f8fa; }

/* ===== 设计态：列头排序 / 列宽拖拽 ===== */
.re-table-design th.re-th-draggable {
    position: relative;
    cursor: move;
    user-select: none;
}
.re-table-design th.re-th-draggable.col-dragging {
    opacity: 0.55;
    background: #eef3ff;
}
.re-table-design th.re-th-draggable.col-drop-over {
    border-left: 2px solid #2c6ef2;
    background: #eef3ff;
}
.re-th-text { pointer-events: none; }
.re-col-grip {
    position: absolute;
    top: 0;
    right: -2px;
    width: 6px;
    height: 100%;
    cursor: col-resize;
    z-index: 2;
}
.re-col-grip:hover { background: rgba(44,110,242,0.35); }

/* ===== form-field 表单字段（表格单元格风格，对齐 SoQuotations 打印 .zyd .border） ===== */
.re-form-table {
    /* 负 margin 与相邻元素边框重叠，模拟 border-collapse，拼接后整表为 1px 线 */
    margin: -1px 0 0 -1px;
    width: calc(100% + 1px);
    height: calc(100% + 1px);
    border-collapse: collapse;
    table-layout: fixed;
}
.re-form-table td {
    border: 1px solid #63656c;
    padding: 0 1.4mm;
    font-size: 9pt;
    vertical-align: middle;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: #1f2329;
}
.re-ff-label {
    width: 40%;
    text-align: left;
    font-weight: 600;
    position: relative;
}
.re-ff-value {
    text-align: left;
}
/* 标签列右缘拖宽手柄（设计态） */
.re-ff-resizable .re-ff-grip {
    position: absolute;
    top: 0;
    right: -2px;
    width: 6px;
    height: 100%;
    cursor: col-resize;
    z-index: 2;
}
.re-ff-resizable .re-ff-grip:hover { background: rgba(44,110,242,0.35); }

/* ===== image 图片元素 ===== */
.re-image-wrap {
    flex: 1;
    width: 100%;
    min-height: 0;
    display: flex;
    padding: 0.5mm;
}
.re-image-wrap img {
    -webkit-user-drag: none;
    user-select: none;
    pointer-events: none; /* 防止图片劫持鼠标拖动 */
}
.re-image-placeholder {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px dashed #c0c4cc;
    border-radius: 4px;
    width: 100%;
}

/* 设计态：报表元素整体可鼠标拖动 */
.report-el.widget-card { cursor: move; }
.report-el.widget-card .widget-resize-handle { cursor: nwse-resize; }
body.is-dragging .report-el.widget-card { cursor: grabbing; }

/* 报表预览工具栏 */
.report-preview-bar {
    background: #fff;
    border-bottom: 1px solid #e4e7ed;
    padding: 10px 18px;
    display: flex;
    align-items: center;
    gap: 10px;
}
.report-preview-bar .rp-title { font-weight: 600; font-size: 15px; margin: 0; }
.report-preview-bar .rp-meta { color: #8a919f; font-size: 12px; }

/* ===== 打印（导出 PDF）===== */
@media print {
    .report-preview-bar { display: none !important; }

    .report-paper-scroll {
        padding: 0 !important;
        margin: 0 !important;
        display: block !important;
        overflow: visible !important;
    }
    .report-paper {
        box-shadow: none !important;
        border-radius: 0 !important;
        margin: 0 !important;
    }
    .report-el.widget-card { border: none !important; }
    .re-float-header, .widget-resize-handle { display: none !important; }

    .widget-chart canvas { max-width: 100%; }
}

/* ===== SQL 数据源对话框 ===== */
.rd-modal-mask {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.45);
    z-index: 2000;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 5vh 16px;
    overflow-y: auto;
}
.rd-modal-dialog {
    width: 760px;
    max-width: calc(100vw - 32px);
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    background: #fff;
    border-radius: 10px;
    box-shadow: 0 18px 48px rgba(15, 23, 42, 0.25);
    overflow: hidden;
}
.rd-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 14px 18px;
    font-size: 15px;
    font-weight: 600;
    background: #f7f8fa;
    border-bottom: 1px solid #e5e6eb;
    flex-shrink: 0;
}
.rd-modal-header > span {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.rd-modal-body {
    padding: 18px;
    overflow-y: auto;
    flex: 1 1 auto;
    /* 所有文本默认可在任意位置折行，杜绝长英文/标识符撑破布局；中文按词组正常换行 */
    word-break: break-word;
    overflow-wrap: anywhere;
    line-height: 1.6;
}
/* 短标签保持单行，避免“唯一标识 /（英文）”这类词组中间断开 */
.rd-modal-body .form-label { white-space: nowrap; }
.rd-sql-textarea {
    width: 100%;
    resize: vertical;
    min-height: 170px;
    line-height: 1.5;
    tab-size: 4;
    /* SQL 长句按词软换行，不出现横向溢出 */
    white-space: pre-wrap;
    word-break: break-word;
    overflow-wrap: break-word;
}
.rd-sql-hint {
    margin-top: 6px;
    line-height: 1.6;
}
.rd-sql-hint code {
    white-space: nowrap;
}
.rd-modal-body .alert {
    word-break: break-word;
    overflow-wrap: anywhere;
}
.rd-sql-meta {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}
.rd-sql-joins {
    margin: 4px 0 0;
    padding-left: 18px;
    font-size: 12.5px;
    line-height: 1.9;
}
.rd-sql-joins li { margin-bottom: 2px; }
.rd-sql-joins code, .rd-sql-list code {
    color: #2c6ef2;
    background: #eef3ff;
    padding: 0 4px;
    border-radius: 3px;
    /* 超长表名/字段名可在代码片段内部折行 */
    word-break: break-all;
    overflow-wrap: anywhere;
}
.rd-sql-fields {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
}
.rd-sql-fields .field-chip {
    max-width: 100%;
    overflow-wrap: anywhere;
}
.rd-sql-fields .field-chip em {
    font-style: normal;
    font-size: 10px;
    color: #9aa0ab;
    margin-left: 4px;
    white-space: nowrap;
}
.rd-sql-fields .field-chip.measure em { color: #d4483c; }
.rd-sql-fields .field-chip .field-phys {
    font-size: 10px;
    color: #9aa0ab;
    margin-left: 5px;
    font-family: Consolas, "SFMono-Regular", monospace;
}
.rd-sql-list {
    list-style: none;
    margin: 6px 0 0;
    padding: 0;
}
.rd-sql-list li {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 8px 10px;
    border: 1px solid #e5e6eb;
    border-radius: 6px;
    margin-bottom: 6px;
    font-size: 13px;
}
.rd-sql-list-info {
    flex: 1 1 auto;
    min-width: 0;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 4px 8px;
}
.rd-sql-list-name {
    font-weight: 600;
    color: #2b2f36;
    max-width: 100%;
}
.rd-sql-list-key {
    font-size: 12px;
}
.rd-sql-list-meta {
    flex-basis: 100%;
    font-size: 11.5px;
    font-style: normal;
    color: #9aa0ab;
}
.rd-sql-list .btn {
    flex-shrink: 0;
}

@media (max-width: 576px) {
    .rd-modal-mask { padding: 16px 8px; }
    .rd-modal-dialog { max-width: calc(100vw - 16px); border-radius: 8px; }
    .rd-modal-header { padding: 12px 14px; font-size: 14px; }
    .rd-modal-body { padding: 14px; }
    .rd-sql-textarea { min-height: 140px; }
}
