/* =========================================================
   通用详情浮层 · 报错信息 / AI 请求体 / 生成通道调用链路
   ---------------------------------------------------------
   与 css/task-center.css 同一套品牌语言，自包含深浅双主题令牌，
   不依赖页面是否挂载 .brand-theme / 是否加载 --color-* 变量。
   所有选择器以 #error-detail-overlay 起头，避免污染宿主页面。
   DOS 契约：showDetailOverlay() 动态创建 #error-detail-overlay。
   ========================================================= */

/* ---------------- 品牌令牌（深色，默认） ---------------- */
#error-detail-overlay.do-overlay {
    --do-canvas: #08090b;
    --do-surface: #0f1115;
    --do-surface-raised: #161a20;
    --do-surface-soft: #1b2027;
    --do-line: rgba(255, 255, 255, 0.10);
    --do-line-strong: rgba(255, 255, 255, 0.22);
    --do-ink: #f5f4f0;
    --do-body: #b9b8b2;
    --do-muted: #84847e;
    --do-accent: #d3b58f;
    --do-accent-rgb: 211, 181, 143;
    --do-active: #7cb8ff;
    --do-active-rgb: 124, 184, 255;
    --do-done: #57d38c;
    --do-done-rgb: 87, 211, 140;
    --do-fail: #ff8080;
    --do-fail-rgb: 255, 128, 128;
    --do-idle: #e8bd6d;
    --do-idle-rgb: 232, 189, 109;
    --do-scrim: rgba(0, 0, 0, 0.68);
    --do-shadow: 0 30px 90px rgba(0, 0, 0, 0.55), 0 2px 12px rgba(0, 0, 0, 0.25);
    --do-code-bg: rgba(0, 0, 0, 0.26);
    --do-tone: var(--do-accent);
    --do-tone-rgb: var(--do-accent-rgb);
    color-scheme: dark;
}

/* ---------------- 品牌令牌（浅色） ---------------- */
html[data-theme="light"] #error-detail-overlay.do-overlay {
    --do-canvas: #f1eee8;
    --do-surface: #fbfaf7;
    --do-surface-raised: #ffffff;
    --do-surface-soft: #f5f1ea;
    --do-line: rgba(52, 43, 31, 0.13);
    --do-line-strong: rgba(52, 43, 31, 0.28);
    --do-ink: #24231f;
    --do-body: #4f4b44;
    --do-muted: #7a746a;
    --do-accent: #8a6740;
    --do-accent-rgb: 138, 103, 64;
    --do-active: #2563c9;
    --do-active-rgb: 37, 99, 201;
    --do-done: #12804a;
    --do-done-rgb: 18, 128, 74;
    --do-fail: #c0392f;
    --do-fail-rgb: 192, 57, 47;
    --do-idle: #a26a14;
    --do-idle-rgb: 162, 106, 20;
    --do-scrim: rgba(38, 32, 24, 0.46);
    --do-shadow: 0 30px 80px rgba(52, 43, 31, 0.22), 0 2px 10px rgba(52, 43, 31, 0.08);
    --do-code-bg: rgba(52, 43, 31, 0.045);
    color-scheme: light;
}

/* ---------------- 遮罩 ---------------- */
#error-detail-overlay.do-overlay {
    position: fixed;
    inset: 0;
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: var(--do-scrim);
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
    color: var(--do-ink);
    font-family: inherit;
    animation: do-fade 0.18s ease both;
}
@keyframes do-fade { from { opacity: 0; } to { opacity: 1; } }

/* ---------------- 面板 ---------------- */
#error-detail-overlay .do-panel {
    position: relative;
    /* 高度随内容自适应，只在内容过长时触发滚动：短报错不留大片空白 */
    display: flex;
    flex-direction: column;
    width: 100%;
    max-width: 880px;
    height: auto;
    max-height: min(780px, 86vh);
    max-height: min(780px, 86dvh);
    margin: 0;
    overflow: hidden;
    border: 1px solid var(--do-line-strong);
    border-radius: 18px;
    background: var(--do-surface);
    box-shadow: var(--do-shadow);
    animation: do-rise 0.22s cubic-bezier(0.2, 0.8, 0.2, 1) both;
}
@keyframes do-rise { from { opacity: 0; transform: translateY(12px) scale(0.985); } to { opacity: 1; transform: none; } }
#error-detail-overlay .do-panel::before {
    content: "";
    position: absolute;
    z-index: 1;
    inset: 0 0 auto;
    height: 3px;
    background: linear-gradient(90deg, var(--do-tone), rgba(var(--do-tone-rgb), 0.12) 62%, transparent 100%);
}
#error-detail-overlay .do-panel[data-kind="error"] { --do-tone: var(--do-fail); --do-tone-rgb: var(--do-fail-rgb); }
#error-detail-overlay .do-panel[data-kind="trace"] { --do-tone: var(--do-active); --do-tone-rgb: var(--do-active-rgb); }

/* ---------------- 头部 ---------------- */
#error-detail-overlay .do-head {
    flex: 0 0 auto;
    display: flex;
    flex-direction: column;
    gap: 0;
    padding: 26px 76px 20px 30px;
    border-bottom: 1px solid var(--do-line);
    background:
        radial-gradient(110% 130% at 0% 0%, rgba(var(--do-tone-rgb), 0.12), transparent 62%),
        var(--do-canvas);
}
#error-detail-overlay .do-eyebrow {
    display: flex;
    align-items: center;
    gap: 9px;
    margin: 0 0 10px;
    color: var(--do-tone);
    font-family: var(--font-mono, monospace);
    font-size: 10px;
    letter-spacing: 0.18em;
    line-height: 1.3;
}
#error-detail-overlay .do-eyebrow::before {
    content: "";
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--do-tone);
    box-shadow: 0 0 0 3px rgba(var(--do-tone-rgb), 0.18);
}
#error-detail-overlay .do-title {
    margin: 0;
    color: var(--do-ink);
    font-family: var(--brand-font-display, var(--font-body));
    font-size: 24px;
    font-weight: 300;
    letter-spacing: -0.025em;
    line-height: 1.3;
    overflow-wrap: anywhere;
}
#error-detail-overlay .do-subtitle {
    margin: 8px 0 0;
    color: var(--do-muted);
    font-size: 12px;
    line-height: 1.7;
}
#error-detail-overlay .do-close {
    position: absolute;
    top: 20px;
    right: 20px;
    display: grid;
    place-items: center;
    width: 34px;
    height: 34px;
    padding: 0;
    border: 1px solid var(--do-line);
    border-radius: 50%;
    background: var(--do-surface-raised);
    color: var(--do-muted);
    cursor: pointer;
    transition: color 0.15s, border-color 0.15s, background 0.15s;
}
#error-detail-overlay .do-close svg { width: 15px; height: 15px; }
#error-detail-overlay .do-close:hover {
    border-color: var(--do-tone);
    background: rgba(var(--do-tone-rgb), 0.13);
    color: var(--do-ink);
}
#error-detail-overlay :is(button, summary, input):focus-visible {
    outline: 2px solid var(--do-tone);
    outline-offset: 2px;
}

/* 摘要 chips */
#error-detail-overlay .do-meta {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 7px;
    margin: 16px 0 0;
    padding: 0;
    list-style: none;
}
#error-detail-overlay .do-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    max-width: 100%;
    padding: 4px 10px;
    border: 1px solid var(--do-line);
    border-radius: 999px;
    background: var(--do-surface-raised);
    font-size: 11px;
    line-height: 1.5;
}
#error-detail-overlay .do-chip-k { color: var(--do-muted); white-space: nowrap; }
#error-detail-overlay .do-chip-v {
    min-width: 0;
    max-width: 230px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--do-ink);
    font-weight: 600;
}
#error-detail-overlay .do-chip[data-tone="tone"] { border-color: rgba(var(--do-tone-rgb), 0.4); background: rgba(var(--do-tone-rgb), 0.09); }
#error-detail-overlay .do-chip[data-tone="tone"] .do-chip-v { color: var(--do-tone); }
#error-detail-overlay .do-chip[data-tone="done"] { border-color: rgba(var(--do-done-rgb), 0.38); background: rgba(var(--do-done-rgb), 0.1); }
#error-detail-overlay .do-chip[data-tone="done"] .do-chip-v { color: var(--do-done); }
#error-detail-overlay .do-chip[data-tone="fail"] { border-color: rgba(var(--do-fail-rgb), 0.38); background: rgba(var(--do-fail-rgb), 0.1); }
#error-detail-overlay .do-chip[data-tone="fail"] .do-chip-v { color: var(--do-fail); }

/* ---------------- 正文滚动区 ---------------- */
#error-detail-overlay .do-body {
    flex: 1 1 auto;
    min-height: 0;
    padding: 20px 30px 26px;
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-width: thin;
    scrollbar-color: var(--do-line-strong) transparent;
}
#error-detail-overlay .do-body::-webkit-scrollbar { width: 7px; }
#error-detail-overlay .do-body::-webkit-scrollbar-thumb { background: var(--do-line-strong); border-radius: 4px; }

/* ---------------- 焦点摘要卡（报错 / 计费） ---------------- */
#error-detail-overlay .do-hero {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    gap: 14px;
    margin-bottom: 18px;
    padding: 18px 20px;
    border: 1px solid rgba(var(--do-tone-rgb), 0.34);
    border-radius: 12px;
    background:
        radial-gradient(90% 160% at 0% 0%, rgba(var(--do-tone-rgb), 0.13), transparent 70%),
        var(--do-surface-raised);
}
#error-detail-overlay .do-hero-mark {
    display: grid;
    place-items: center;
    width: 34px;
    height: 34px;
    border: 1px solid rgba(var(--do-tone-rgb), 0.42);
    border-radius: 10px;
    background: rgba(var(--do-tone-rgb), 0.1);
    color: var(--do-tone);
    font-family: var(--font-mono, monospace);
    font-size: 17px;
    line-height: 1;
}
#error-detail-overlay .do-hero-label {
    margin: 0 0 6px;
    color: var(--do-muted);
    font-family: var(--font-mono, monospace);
    font-size: 10px;
    letter-spacing: 0.14em;
}
#error-detail-overlay .do-hero-text {
    margin: 0;
    color: var(--do-ink);
    font-size: 14px;
    font-weight: 500;
    line-height: 1.65;
    overflow-wrap: anywhere;
}
#error-detail-overlay .do-hero[data-variant="error"] .do-hero-text { color: var(--do-fail); font-family: var(--font-mono, monospace); font-size: 13px; font-weight: 400; }

/* 计费三格 */
#error-detail-overlay .do-figures {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
    margin-bottom: 18px;
}
#error-detail-overlay .do-figure {
    padding: 14px 16px;
    border: 1px solid var(--do-line);
    border-radius: 12px;
    background: var(--do-surface-raised);
}
#error-detail-overlay .do-figure-k { display: block; margin-bottom: 8px; color: var(--do-muted); font-size: 11px; }
#error-detail-overlay .do-figure-v {
    display: block;
    color: var(--do-ink);
    font-family: var(--font-mono, monospace);
    font-size: 22px;
    font-weight: 500;
    line-height: 1.1;
}
#error-detail-overlay .do-figure-v small { margin-left: 4px; color: var(--do-muted); font-size: 11px; font-weight: 400; }
#error-detail-overlay .do-figure[data-tone="tone"] .do-figure-v { color: var(--do-tone); }
#error-detail-overlay .do-figure[data-tone="done"] .do-figure-v { color: var(--do-done); }
#error-detail-overlay .do-figure[data-tone="fail"] .do-figure-v { color: var(--do-fail); }

/* ---------------- 分区卡片 ---------------- */
#error-detail-overlay .do-section {
    margin-bottom: 12px;
    border: 1px solid var(--do-line);
    border-radius: 12px;
    background: var(--do-surface-raised);
    overflow: hidden;
}
#error-detail-overlay .do-section:last-child { margin-bottom: 0; }
#error-detail-overlay .do-section-head {
    display: flex;
    align-items: center;
    gap: 9px;
    min-height: 42px;
    padding: 9px 15px;
    border-bottom: 1px solid var(--do-line);
    background: var(--do-surface-soft);
}
#error-detail-overlay .do-section-head::before {
    content: "";
    flex: 0 0 auto;
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: var(--do-tone);
}
#error-detail-overlay .do-section-name {
    color: var(--do-ink);
    font-size: 12px;
    font-weight: 600;
    line-height: 1.4;
}
#error-detail-overlay .do-section-badge {
    margin-left: auto;
    padding: 2px 8px;
    border: 1px solid var(--do-line);
    border-radius: 999px;
    color: var(--do-muted);
    font-family: var(--font-mono, monospace);
    font-size: 10px;
    white-space: nowrap;
}
#error-detail-overlay .do-section[data-emphasis="true"] { border-color: rgba(var(--do-tone-rgb), 0.36); }
#error-detail-overlay .do-section[data-emphasis="true"] .do-section-head { background: rgba(var(--do-tone-rgb), 0.08); }
#error-detail-overlay .do-section-body { padding: 14px 16px; }

/* 代码 / 原文 */
#error-detail-overlay .do-code {
    max-height: 360px;
    margin: 0;
    padding: 0;
    overflow: auto;
    color: var(--do-body);
    font-family: Consolas, Menlo, Monaco, monospace;
    font-size: 12px;
    line-height: 1.75;
    white-space: pre-wrap;
    word-break: break-word;
    scrollbar-width: thin;
}
#error-detail-overlay .do-code[data-tone="error"] { color: var(--do-fail); }

/* 键值表 */
#error-detail-overlay .do-kv { display: grid; grid-template-columns: minmax(110px, auto) minmax(0, 1fr); gap: 0; margin: 0; }
#error-detail-overlay .do-kv > dt,
#error-detail-overlay .do-kv > dd {
    margin: 0;
    padding: 7px 8px;
    border-bottom: 1px solid var(--do-line);
    font-size: 12px;
    line-height: 1.6;
    overflow-wrap: anywhere;
}
#error-detail-overlay .do-kv > dt { color: var(--do-muted); }
#error-detail-overlay .do-kv > dd { color: var(--do-ink); font-family: var(--font-mono, monospace); font-size: 11px; }
#error-detail-overlay .do-kv > :nth-last-child(1),
#error-detail-overlay .do-kv > :nth-last-child(2) { border-bottom: 0; }

/* 编号列表 */
#error-detail-overlay .do-list { display: flex; flex-direction: column; gap: 8px; margin: 0; padding: 0; list-style: none; }
#error-detail-overlay .do-list li {
    display: grid;
    grid-template-columns: 22px minmax(0, 1fr);
    gap: 9px;
    align-items: start;
    color: var(--do-body);
    font-size: 12px;
    line-height: 1.65;
    overflow-wrap: anywhere;
}
#error-detail-overlay .do-list-num {
    display: grid;
    place-items: center;
    width: 20px;
    height: 20px;
    border: 1px solid var(--do-line);
    border-radius: 6px;
    color: var(--do-muted);
    font-family: var(--font-mono, monospace);
    font-size: 10px;
}

/* ---------------- 通道时间线 ---------------- */
#error-detail-overlay .do-timeline { position: relative; display: flex; flex-direction: column; gap: 0; }
#error-detail-overlay .do-timeline::before {
    content: "";
    position: absolute;
    top: 14px;
    bottom: 22px;
    left: 12px;
    width: 1px;
    background: var(--do-line-strong);
}
#error-detail-overlay .do-step {
    position: relative;
    display: grid;
    grid-template-columns: 26px minmax(0, 1fr);
    gap: 12px;
    padding: 0 0 16px;
}
#error-detail-overlay .do-step:last-child { padding-bottom: 0; }
#error-detail-overlay .do-step-marker {
    position: relative;
    z-index: 1;
    display: grid;
    place-items: center;
    width: 25px;
    height: 25px;
    border: 1px solid var(--do-line-strong);
    border-radius: 50%;
    background: var(--do-surface);
    color: var(--do-muted);
    font-family: var(--font-mono, monospace);
    font-size: 10px;
}
#error-detail-overlay .do-step[data-state="success"] .do-step-marker { border-color: rgba(var(--do-done-rgb), 0.55); background: rgba(var(--do-done-rgb), 0.14); color: var(--do-done); }
#error-detail-overlay .do-step[data-state="failed"] .do-step-marker { border-color: rgba(var(--do-fail-rgb), 0.55); background: rgba(var(--do-fail-rgb), 0.14); color: var(--do-fail); }
#error-detail-overlay .do-step[data-state="skipped"] .do-step-marker { opacity: 0.7; }
#error-detail-overlay .do-step-card {
    min-width: 0;
    padding: 12px 14px;
    border: 1px solid var(--do-line);
    border-radius: 10px;
    background: var(--do-surface-soft);
}
#error-detail-overlay .do-step-top { display: flex; align-items: baseline; flex-wrap: wrap; gap: 8px; }
#error-detail-overlay .do-step-name {
    min-width: 0;
    color: var(--do-ink);
    font-size: 13px;
    font-weight: 600;
    overflow-wrap: anywhere;
}
#error-detail-overlay .do-step-state {
    padding: 1px 8px;
    border-radius: 999px;
    font-size: 10px;
    font-weight: 600;
    white-space: nowrap;
}
#error-detail-overlay .do-step[data-state="success"] .do-step-state { background: rgba(var(--do-done-rgb), 0.15); color: var(--do-done); }
#error-detail-overlay .do-step[data-state="failed"] .do-step-state { background: rgba(var(--do-fail-rgb), 0.15); color: var(--do-fail); }
#error-detail-overlay .do-step[data-state="skipped"] .do-step-state { background: rgba(127, 127, 127, 0.16); color: var(--do-muted); }
#error-detail-overlay .do-step[data-state="pending"] .do-step-state { background: rgba(var(--do-idle-rgb), 0.15); color: var(--do-idle); }
#error-detail-overlay .do-step-facts { display: flex; flex-wrap: wrap; gap: 6px 16px; margin: 9px 0 0; padding: 0; list-style: none; }
#error-detail-overlay .do-step-facts li { color: var(--do-muted); font-size: 11px; line-height: 1.5; }
#error-detail-overlay .do-step-facts strong { color: var(--do-body); font-weight: 600; }
#error-detail-overlay .do-step-error {
    margin: 10px 0 0;
    padding: 9px 11px;
    border: 1px solid rgba(var(--do-fail-rgb), 0.26);
    border-radius: 8px;
    background: rgba(var(--do-fail-rgb), 0.07);
    color: var(--do-fail);
    font-family: var(--font-mono, monospace);
    font-size: 11px;
    line-height: 1.65;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}
/* 只有真正失败的通道用红色；跳过 / 未完成 / 成功的说明文字用中性色，避免误判为故障 */
#error-detail-overlay .do-step:not([data-state="failed"]) .do-step-error {
    border-color: var(--do-line);
    background: rgba(127, 127, 127, 0.07);
    color: var(--do-muted);
}

/* ---------------- 折叠原始 JSON ---------------- */
#error-detail-overlay .do-details {
    margin-top: 12px;
    border: 1px solid var(--do-line);
    border-radius: 10px;
    background: var(--do-code-bg);
    overflow: hidden;
}
#error-detail-overlay .do-details > summary {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    color: var(--do-body);
    font-size: 11px;
    cursor: pointer;
    list-style: none;
    user-select: none;
}
#error-detail-overlay .do-details > summary::-webkit-details-marker { display: none; }
#error-detail-overlay .do-details > summary::before {
    content: "▸";
    color: var(--do-tone);
    font-size: 11px;
    transition: transform 0.15s;
}
#error-detail-overlay .do-details[open] > summary::before { transform: rotate(90deg); }
#error-detail-overlay .do-details > summary:hover { color: var(--do-ink); background: rgba(var(--do-tone-rgb), 0.06); }
#error-detail-overlay .do-details-body {
    max-height: 300px;
    padding: 0 14px 14px;
    overflow: auto;
    color: var(--do-muted);
    font-family: Consolas, Menlo, Monaco, monospace;
    font-size: 11px;
    line-height: 1.7;
    white-space: pre-wrap;
    word-break: break-word;
    scrollbar-width: thin;
}
#error-detail-overlay .do-empty { margin: 0; color: var(--do-muted); font-size: 12px; line-height: 1.7; }

/* ---------------- 底部工具条 ---------------- */
#error-detail-overlay .do-foot {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 13px 30px;
    border-top: 1px solid var(--do-line);
    background: var(--do-canvas);
}
#error-detail-overlay .do-hint { color: var(--do-muted); font-size: 11px; line-height: 1.5; }
#error-detail-overlay .do-hint kbd {
    padding: 1px 6px;
    border: 1px solid var(--do-line-strong);
    border-radius: 4px;
    font-family: var(--font-mono, monospace);
    font-size: 10px;
}
#error-detail-overlay .do-actions { display: flex; align-items: center; gap: 8px; flex: 0 0 auto; }
#error-detail-overlay .do-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-height: 32px;
    padding: 5px 13px;
    border: 1px solid var(--do-line-strong);
    border-radius: 999px;
    background: transparent;
    color: var(--do-body);
    font-family: inherit;
    font-size: 11px;
    cursor: pointer;
    white-space: nowrap;
    transition: color 0.15s, border-color 0.15s, background 0.15s;
}
#error-detail-overlay .do-btn svg { width: 13px; height: 13px; }
#error-detail-overlay .do-btn:hover { border-color: var(--do-tone); background: rgba(var(--do-tone-rgb), 0.09); color: var(--do-ink); }
#error-detail-overlay .do-btn.is-primary {
    border-color: var(--do-tone);
    background: var(--do-tone);
    color: var(--do-canvas);
    font-weight: 600;
}
/* 文字色用画布色，深浅主题自动反相，保证在实心主色底上都有对比度 */
#error-detail-overlay .do-btn.is-primary:hover { filter: brightness(1.12); }
#error-detail-overlay .do-btn.is-copied { border-color: rgba(var(--do-done-rgb), 0.6); color: var(--do-done); }

/* ---------------- 响应式 ---------------- */
@media (max-width: 760px) {
    #error-detail-overlay.do-overlay { padding: 12px; }
    #error-detail-overlay .do-panel { height: calc(100dvh - 24px); max-height: none; border-radius: 14px; }
    #error-detail-overlay .do-head { padding: 20px 62px 16px 18px; }
    #error-detail-overlay .do-title { font-size: 20px; }
    #error-detail-overlay .do-close { top: 14px; right: 14px; width: 30px; height: 30px; }
    #error-detail-overlay .do-body { padding: 16px 18px 20px; }
    #error-detail-overlay .do-foot { flex-wrap: wrap; padding: 11px 18px; }
    #error-detail-overlay .do-hint { display: none; }
}
@media (max-width: 480px) {
    #error-detail-overlay .do-figures { grid-template-columns: minmax(0, 1fr); gap: 8px; }
    #error-detail-overlay .do-figure { display: flex; align-items: baseline; justify-content: space-between; padding: 10px 13px; }
    #error-detail-overlay .do-figure-k { margin: 0; }
    #error-detail-overlay .do-figure-v { font-size: 17px; }
    #error-detail-overlay .do-kv { grid-template-columns: minmax(0, 1fr); }
    #error-detail-overlay .do-kv > dt { padding-bottom: 2px; border-bottom: 0; }
    #error-detail-overlay .do-kv > dd { padding-top: 0; }
    #error-detail-overlay .do-kv > :nth-last-child(2) { border-bottom: 1px solid var(--do-line); }
    #error-detail-overlay .do-actions { flex-wrap: wrap; }
}
@media (prefers-reduced-motion: reduce) {
    #error-detail-overlay.do-overlay,
    #error-detail-overlay .do-panel { animation: none !important; }
    #error-detail-overlay * { transition: none !important; }
}
