/* ============================================================================
 * statbook-viz.css
 * Hello 统计学 - 可视化组件样式
 * ========================================================================== */

.sb-viz-root {
    display: block;
    margin: 1.5rem 0;
    border: 1px solid var(--md-default-fg-color--lightest, #e3e3e7);
    border-radius: 10px;
    background: var(--md-default-bg-color);
    overflow: hidden;
}

.sb-viz-inner {
    padding: 0.75rem 1rem 1rem 1rem;
}

.sb-viz-title {
    font-weight: 600;
    font-size: 0.95rem;
    color: var(--md-default-fg-color);
    margin-bottom: 0.5rem;
    padding-left: 0.25rem;
    border-left: 3px solid var(--md-typeset-a-color);
}

.sb-viz-canvas {
    width: 100%;
    line-height: 0;
}

.sb-canvas {
    display: block;
    border-radius: 6px;
}

.sb-viz-controls {
    display: flex;
    flex-direction: column;
    flex-wrap: nowrap;
    gap: 0.55rem;
    align-items: flex-start;
    margin-top: 0.7rem;
    padding-top: 0;
    font-size: 0.75rem;
    line-height: 1.5;
}

.sb-viz-caption {
    margin-top: 0.7rem;
    padding: 0.55rem 0.7rem;
    border-radius: 6px;
    background: var(--md-code-bg-color, #f4f4f6);
    font-size: 0.75rem;
    color: var(--md-default-fg-color--light, #6a6a72);
    line-height: 1.5;
}

.sb-control {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    justify-content: flex-start;
    gap: 0.25rem;
    flex-wrap: nowrap;
    width: 100%;
}

.sb-label {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    color: var(--md-default-fg-color);
    white-space: nowrap;
}

.sb-value {
    font-family: "Fira Code", monospace;
    font-size: 0.75rem;
    line-height: 1.5;
    color: var(--md-typeset-a-color);
    min-width: 2.6em;
    text-align: right;
}

.sb-slider {
    width: min(360px, 100%);
    accent-color: var(--md-typeset-a-color);
}

.sb-select {
    padding: 0.2rem 0.4rem;
    border-radius: 4px;
    border: 1px solid var(--md-default-fg-color--lightest, #ccc);
    background: var(--md-default-bg-color);
    color: var(--md-default-fg-color);
    font-size: 0.75rem;
    line-height: 1.5;
}

.sb-btn {
    align-self: flex-start;
    padding: 0.3rem 0.75rem;
    border: 1px solid transparent;
    background: var(--md-typeset-btn-color, #2a8d85);
    color: #fff;
    border-radius: 5px;
    cursor: pointer;
    font-size: 0.75rem;
    line-height: 1.5;
    transition: all 0.15s ease;
}

.sb-btn:hover:not(:disabled) {
    background: var(--md-typeset-btn-hover-color, #52bbb1);
    color: #fff;
}

.sb-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.sb-btn-primary {
    background: var(--md-typeset-btn-color, #2a8d85);
    color: #fff;
    border-color: transparent;
}

.sb-btn-primary:hover:not(:disabled) {
    background: var(--md-typeset-btn-hover-color, #52bbb1);
    color: #fff;
}

.sb-stepper {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}

.sb-step-indicator {
    font-family: "Fira Code", monospace;
    color: var(--md-default-fg-color--light);
    min-width: 3em;
    text-align: center;
}

.sb-hint {
    flex-basis: 100%;
    color: var(--md-default-fg-color--light);
    font-size: 0.75rem;
    line-height: 1.5;
    background: var(--md-code-bg-color, #f4f4f6);
    padding: 0.4rem 0.6rem;
    border-radius: 4px;
}

.sb-viz-error {
    padding: 1rem;
    color: #c54a4a;
    font-family: "Fira Code", monospace;
    font-size: 0.85rem;
}

/* 暗色模式微调 */
[data-md-color-scheme="slate"] .sb-viz-root {
    border-color: #3a414c;
}

[data-md-color-scheme="slate"] .sb-viz-controls {
    border-top-color: #3a414c;
}

[data-md-color-scheme="slate"] .sb-viz-caption {
    background: #2c333d;
}

/* ============================================================================
 * Slide 步骤说明 (随 stepper 切换)
 * ========================================================================== */
.sb-step-desc {
    flex-basis: 100%;
    margin-top: 0.5rem;
    padding: 0.6rem 0.85rem;
    background: var(--md-code-bg-color, #f4f4f6);
    border-left: 3px solid var(--md-typeset-a-color);
    border-radius: 4px;
    font-size: 0.75rem;
    line-height: 1.5;
    color: var(--md-default-fg-color);
}

[data-md-color-scheme="slate"] .sb-step-desc {
    background: #2c333d;
}

/* ============================================================================
 * 对话气泡: <div class="sb-dlg" data-who="jun|lv" data-mood="...">文本</div>
 * 现代聊天软件风格: 纯白底, 阴影描边, 无姓名标签
 * ========================================================================== */
.sb-dlg {
    display: flex;
    align-items: flex-start;
    gap: 0.6rem;
    margin: 0.75rem 0;
    max-width: 100%;
}

.sb-dlg--jun {
    flex-direction: row;
}

.sb-dlg--lv {
    flex-direction: row-reverse;
}

.sb-dlg-avatar {
    flex: 0 0 44px;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background-image: url("../assets/figures/roles/avatar_slim.jpg");
    background-size: 300% 200%;
    /* 3 列 2 行 sprite */
    background-repeat: no-repeat;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12),
        0 0 0 2px var(--md-default-bg-color);
}

.sb-dlg-bubble {
    position: relative;
    flex: 0 1 auto;
    max-width: calc(100% - 70px);
    padding: 0.5rem 0.75rem;
    background: #ffffff;
    border-radius: 14px;
    border: 1px solid rgba(0, 0, 0, 0.08);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
}

.sb-dlg--jun .sb-dlg-bubble {
    border-top-left-radius: 4px;
}

.sb-dlg--lv .sb-dlg-bubble {
    border-top-right-radius: 4px;
}

/* 三角指针: 用 ::before(描边色) + ::after(白色) 双层制造带边框的尖角 */
.sb-dlg-bubble::before,
.sb-dlg-bubble::after {
    content: "";
    position: absolute;
    top: 12px;
    width: 0;
    height: 0;
    border-style: solid;
}

.sb-dlg--jun .sb-dlg-bubble::before {
    left: -8px;
    border-width: 6px 8px 6px 0;
    border-color: transparent rgba(0, 0, 0, 0.12) transparent transparent;
}

.sb-dlg--jun .sb-dlg-bubble::after {
    left: -6px;
    border-width: 5px 7px 5px 0;
    border-color: transparent #ffffff transparent transparent;
}

.sb-dlg--lv .sb-dlg-bubble::before {
    right: -8px;
    border-width: 6px 0 6px 8px;
    border-color: transparent transparent transparent rgba(0, 0, 0, 0.12);
}

.sb-dlg--lv .sb-dlg-bubble::after {
    right: -6px;
    border-width: 5px 0 5px 7px;
    border-color: transparent transparent transparent #ffffff;
}

.sb-dlg-text {
    font-size: 0.75rem;
    line-height: 1.5;
    color: var(--md-default-fg-color);
}

.sb-dlg-text p:first-child {
    margin-top: 0;
}

.sb-dlg-text p:last-child {
    margin-bottom: 0;
}

/* 让对话气泡内的 MathJax 公式与 0.75rem 文本相协调 */
.sb-dlg-text mjx-container {
    font-size: 100% !important;
}

/* 暗色模式: 用深色面板 + 浅色阴影描边 */
[data-md-color-scheme="slate"] .sb-dlg-bubble {
    background: #2c333d;
    border-color: rgba(255, 255, 255, 0.1);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
}

[data-md-color-scheme="slate"] .sb-dlg--jun .sb-dlg-bubble::before {
    border-right-color: rgba(255, 255, 255, 0.12);
}

[data-md-color-scheme="slate"] .sb-dlg--jun .sb-dlg-bubble::after {
    border-right-color: #2c333d;
}

[data-md-color-scheme="slate"] .sb-dlg--lv .sb-dlg-bubble::before {
    border-left-color: rgba(255, 255, 255, 0.12);
}

[data-md-color-scheme="slate"] .sb-dlg--lv .sb-dlg-bubble::after {
    border-left-color: #2c333d;
}

@media (max-width: 600px) {
    .sb-dlg-avatar {
        width: 36px;
        height: 36px;
        flex-basis: 36px;
    }

    .sb-dlg-bubble {
        padding: 0.4rem 0.65rem;
    }
}
/* ===== 交互组件占位卡片 (未注册组件的优雅降级) ===== */
.sb-viz-placeholder {
    margin: 0.8rem 0;
    padding: 0;
    border: 1px dashed #c8b99a;
    border-radius: 10px;
    background: linear-gradient(180deg, #fffaf2 0%, #fdf5e6 100%);
    overflow: hidden;
}

.sb-viz-placeholder__title {
    padding: 0.55rem 0.9rem;
    font-weight: 600;
    color: #8a5a1a;
    background: rgba(230, 128, 74, 0.08);
    border-bottom: 1px dashed #e0c9a0;
    font-size: 0.92rem;
}

.sb-viz-placeholder__body {
    padding: 0.9rem 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.sb-viz-placeholder__badge {
    align-self: flex-start;
    display: inline-block;
    padding: 0.12rem 0.55rem;
    font-size: 0.72rem;
    font-weight: 500;
    color: #fff;
    background: #e6804a;
    border-radius: 999px;
    letter-spacing: 0.5px;
}

.sb-viz-placeholder__caption {
    margin: 0;
    color: #4a4a50;
    font-size: 0.88rem;
    line-height: 1.55;
}

[data-md-color-scheme="slate"] .sb-viz-placeholder {
    background: linear-gradient(180deg, #2e2922 0%, #2a261f 100%);
    border-color: #5a4a30;
}

[data-md-color-scheme="slate"] .sb-viz-placeholder__title {
    color: #f0b870;
    background: rgba(240, 160, 112, 0.08);
    border-bottom-color: #5a4a30;
}

[data-md-color-scheme="slate"] .sb-viz-placeholder__badge {
    background: #f0a070;
    color: #22272e;
}

[data-md-color-scheme="slate"] .sb-viz-placeholder__caption {
    color: #c0c4cc;
}
