/* public/assets/css/social_office/network-tester.css */
:root {
    --primary: #6366f1; --secondary: #a855f7; --success: #10b981; --warning: #f59e0b; --danger: #ef4444;
    --bg: #ffffff; --card: #f8fafc; --text-main: #0f172a; --text-sub: #64748b;
    --border: #e2e8f0; --shadow: 0 10px 25px -5px rgba(0,0,0,0.05);
}

.chat-wrapper { 
    width: 100%; max-width: 1100px; margin: 0 auto;
    background: var(--bg); border-radius: 20px; overflow: hidden; 
    border: 1px solid var(--border); box-shadow: var(--shadow);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; color: var(--text-main);
    display: flex; flex-direction: column;
}
.chat-wrapper *, .chat-wrapper *::before, .chat-wrapper *::after { box-sizing: border-box; }

.chat-header { padding: 24px; text-align: center; border-bottom: 1px solid var(--border); flex-shrink: 0; }
.chat-title { margin: 0 0 10px 0; font-size: 1.7rem; font-weight: 800; color: var(--text-main); }
.chat-subtitle { margin: 0 auto; max-width: 800px; font-size: 0.95rem; color: var(--text-sub); line-height: 1.6; }
.chat-workspace { padding: 24px; flex: 1; display: flex; flex-direction: column; min-height: 0; }

.chat-layout { display: flex; gap: 24px; align-items: stretch; min-height: 600px; max-height: 900px; flex: 1; transition: 0.3s; }

/* 左侧面板 */
.chat-sys-panel { width: 340px; flex-shrink: 0; background: #0f172a; border-radius: 16px; border: 2px solid #1e293b; padding: 24px; display: flex; flex-direction: column; gap: 16px; box-shadow: inset 0 5px 20px rgba(0,0,0,0.5); overflow-y: auto; transition: 0.3s; }
.chat-sys-panel::-webkit-scrollbar { width: 4px; }
.chat-sys-panel::-webkit-scrollbar-thumb { background: #334155; border-radius: 4px; }
.chat-panel-title { font-size: 1.05rem; font-weight: 800; color: #cbd5e1; text-transform: uppercase; letter-spacing: 0.5px; border-bottom: 2px solid #334155; padding-bottom: 12px; font-family: monospace; margin-bottom: 0; }
.id-display-card { background: #1e293b; border-radius: 12px; padding: 20px; text-align: center; border: 1px solid #334155; }
.id-label { font-size: 12px; color: #94a3b8; letter-spacing: 1px; margin-bottom: 12px; font-weight: bold; }
.id-number { font-size: 42px; font-weight: 900; color: var(--primary); font-family: 'Consolas', monospace; letter-spacing: 8px; text-shadow: 0 2px 10px rgba(99, 102, 241, 0.3); line-height: 1;}
.pc-qr-box { display: flex; justify-content: center; background: white; padding: 10px; border-radius: 12px; margin: 0 auto 15px; width: fit-content; min-height: 130px; align-items: center; }
.mobile-qr-btn { display: none !important; }
.id-actions { display: flex; gap: 10px; margin-top: 15px; }
.id-actions .btn { flex: 1; border-radius: 8px; }
.dial-card { background: #1e293b; border-radius: 12px; padding: 20px; text-align: center; border: 1px solid #334155; }
.qr-label { font-size: 13px; color: #cbd5e1; margin-bottom: 15px; font-weight: 600; }
.dial-input { width: 100%; padding: 14px; border-radius: 8px; border: 2px solid #334155; font-size: 20px; text-align: center; font-family: 'Consolas', monospace; font-weight: 900; color: #f8fafc; background: #0f172a; outline: none; transition: 0.2s; letter-spacing: 4px; }
.dial-input:focus { border-color: var(--primary); box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.15); }
.btn-connect-action { width: 100%; margin-top: 15px; font-size: 16px; padding: 12px; border-radius: 8px; }
.connection-status-card { display: flex; align-items: center; gap: 10px; background: #1e293b; border-radius: 8px; padding: 12px 16px; border: 1px solid #334155; font-size: 13px; color: #cbd5e1; font-weight: 600; margin-top: auto; flex-wrap: wrap; }
.status-dot { width: 10px; height: 10px; border-radius: 50%; background: #64748b; flex-shrink: 0; }
.status-dot.active { background: var(--success); box-shadow: 0 0 8px var(--success); animation: pulse 2s infinite; }

/* 测速主面板基础样式 */
.chat-msg-panel { flex: 1; border-radius: 16px; border: 1px solid var(--border); display: flex; flex-direction: column; min-width: 0; overflow: hidden; position: relative; padding: 20px; }

/* =========================================================
   测速仪表盘核心排版 (彻底重构防文字挤压)
   ========================================================= */
.board-overlay { position: absolute; top: 0; left: 0; width: 100%; height: 100%; background: rgba(248,250,252,0.95); z-index: 50; display: flex; flex-direction: column; align-items: center; justify-content: center; backdrop-filter: blur(8px); border-radius: 12px; }
.board-overlay i { font-size: 60px; color: #cbd5e1; margin-bottom: 20px; }
.board-overlay p { font-size: 16px; font-weight: 600; color: #64748b; margin: 0; letter-spacing: 1px;}
.chat-wrapper.is-connected .board-overlay { display: none; }

.dashboard-container { display: flex; flex-direction: column; height: 100%; gap: 20px; }

/* 头部：CSS Grid 网格强制占比分配，杜绝 flex 互挤 */
.dash-top-grid { display: grid; grid-template-columns: 2fr 1fr; gap: 20px; flex-shrink: 0; }

.ice-diag-card { 
    background: #ffffff; border: 1px solid var(--border); border-radius: 16px; 
    padding: 20px; display: flex; flex-direction: column; justify-content: center;
    box-shadow: 0 4px 6px rgba(0,0,0,0.02); overflow: hidden;
}
.ice-title { font-size: 13px; font-weight: 700; color: #94a3b8; text-transform: uppercase; margin-bottom: 8px; white-space: nowrap; }
.ice-title i { margin-right: 6px; }
.ice-value { font-size: 22px; font-weight: 800; color: var(--primary); margin-bottom: 6px; font-family: 'Consolas', monospace; letter-spacing: 0.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ice-value.lan { color: var(--success); }
.ice-value.wan { color: var(--warning); }
.ice-value.relay { color: var(--danger); }
.ice-desc { font-size: 13px; color: var(--text-sub); }

.action-card {
    background: #ffffff; border: 1px solid var(--border); border-radius: 16px;
    padding: 20px; display: flex; flex-direction: column; align-items: center; justify-content: center;
    box-shadow: 0 4px 6px rgba(0,0,0,0.02);
}

/* 强制按钮文字不换行，防止文字变竖向排列 */
.btn-start-test {
    background: var(--primary); color: white; border: none; border-radius: 30px;
    padding: 12px 24px; font-size: 15px; font-weight: 800; cursor: pointer;
    box-shadow: 0 10px 20px rgba(99, 102, 241, 0.3); transition: 0.2s;
    display: inline-flex; align-items: center; gap: 8px; justify-content: center;
    width: 100%; white-space: nowrap; flex-shrink: 0; min-width: 150px;
}
.btn-start-test:hover { transform: translateY(-3px); box-shadow: 0 15px 25px rgba(99, 102, 241, 0.4); }
.btn-start-test.testing { background: var(--danger); box-shadow: 0 10px 20px rgba(239, 68, 68, 0.3); animation: pulse 2s infinite; }
.test-status { font-size: 12px; font-weight: 700; color: #94a3b8; margin-top: 15px; font-family: 'Consolas', monospace; white-space: nowrap; }

/* 核心数据网格也是 Grid，确保对齐 */
.metrics-grid { display: grid; grid-template-columns: 2fr 1fr; gap: 20px; flex: 1; min-height: 200px; }

.metric-card { 
    background: #ffffff; border: 1px solid var(--border); border-radius: 16px; 
    padding: 24px; box-shadow: 0 4px 6px rgba(0,0,0,0.02);
    display: flex; flex-direction: column; position: relative; overflow: hidden;
}
.speed-card { justify-content: center; align-items: center; }
.side-metrics { display: flex; flex-direction: column; gap: 20px; justify-content: space-between;}
.sub-card { flex: 1; justify-content: center; padding: 15px 24px; }

/* 强制 Label 文字不换行 */
.metric-label { font-size: 12px; font-weight: 700; color: #94a3b8; letter-spacing: 1px; margin-bottom: auto; position: absolute; top: 20px; left: 24px; white-space: nowrap;}
.metric-value-wrapper { display: flex; align-items: baseline; gap: 10px; margin-top: 30px; }
.metric-value { font-size: 72px; font-weight: 900; color: var(--primary); font-family: 'Consolas', monospace; line-height: 1; text-shadow: 0 0 15px rgba(99,102,241,0.2); transition: color 0.3s;}
.testing .metric-value { color: var(--danger); text-shadow: 0 0 15px rgba(239,68,68,0.2); }

.metric-unit { font-size: 24px; font-weight: 700; color: var(--text-sub); }

.metric-value-wrapper.small { margin-top: 20px; }
.metric-value-wrapper.small .metric-value { font-size: 42px; color: var(--text-main); text-shadow: none;}
.metric-value-wrapper.small .metric-unit { font-size: 16px; }

/* CSS 动感速度条 */
.bar-bg { width: 80%; height: 8px; background: var(--border); border-radius: 4px; position: absolute; bottom: 30px; left: 10%; overflow: hidden; }
.bar-fill { height: 100%; background: linear-gradient(90deg, var(--primary), var(--secondary)); border-radius: 4px; transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1); }

/* 日志控制台 */
.terminal-log {
    height: 120px; background: #0f172a; border-radius: 12px; padding: 15px;
    font-family: 'Consolas', monospace; font-size: 13px; color: #34d399;
    overflow-y: auto; display: flex; flex-direction: column; gap: 6px;
    border: 2px solid #1e293b; box-shadow: inset 0 5px 15px rgba(0,0,0,0.5);
    flex-shrink: 0;
}
.terminal-log::-webkit-scrollbar { width: 6px; }
.terminal-log::-webkit-scrollbar-thumb { background: #334155; border-radius: 3px; }
.log-line { opacity: 0.9; line-height: 1.4; word-break: break-all; }
.log-line.warn { color: #fbbf24; }
.log-line.err { color: #f87171; }

/* Bento Grid */
.chat-features-bento { display: grid; grid-template-columns: repeat(2, 1fr); gap: 20px; padding: 0 24px 24px 24px; }
.bento-card { background: var(--card); border: 1px solid var(--border); border-radius: 16px; padding: 24px; transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), box-shadow 0.3s; display: flex; flex-direction: column; gap: 10px; }
.bento-card:hover { transform: translateY(-4px); box-shadow: 0 12px 30px -10px rgba(0,0,0,0.08); border-color: var(--primary); }
.bento-header { display: flex; align-items: center; gap: 12px; }
.bento-icon { width: 36px; height: 36px; background: rgba(99, 102, 241, 0.1); color: var(--primary); border-radius: 10px; display: flex; align-items: center; justify-content: center; font-size: 16px; flex-shrink: 0; }
.bento-card h3 { margin: 0; font-size: 1.05rem; font-weight: 800; color: var(--text-main); line-height: 1.2; }
.bento-card p { margin: 0; font-size: 0.85rem; color: var(--text-sub); line-height: 1.6; }

/* 弹窗通用样式 */
.overlay { position: fixed; top: 0; left: 0; width: 100vw; height: 100vh; background: rgba(0,0,0,0.8); z-index: 99999; display: none; align-items: center; justify-content: center; backdrop-filter: blur(8px); }
.modal-box { background: var(--card); padding: 30px; border-radius: 24px; text-align: center; width: 85%; max-width: 340px; box-shadow: 0 20px 40px rgba(0,0,0,0.5); border: 1px solid var(--border); }
.ringing-animation { font-size: 40px; margin-bottom: 15px; animation: bounce 1s infinite alternate; }
@keyframes bounce { from { transform: translateY(0); } to { transform: translateY(-10px); } }

.btn { border: none; padding: 10px 16px; border-radius: 8px; font-weight: 800; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 8px; transition: 0.2s; font-size: 14px; color: white; }
.btn-sm { padding: 6px 12px; font-size: 12px; }
.btn-primary { background: var(--primary); }
.btn-primary:hover { filter: brightness(1.1); }
.btn-secondary { background: #e2e8f0; color: #0f172a; }
.btn-secondary:hover { background: #cbd5e1; }
.btn-success { background: var(--success); }
.btn-success:hover { filter: brightness(1.1); }
.btn-danger { background: var(--danger); }
.btn-danger:hover { filter: brightness(1.1); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; pointer-events: none; }

#toast-container { position: fixed; top: 20px; left: 50%; transform: translateX(-50%); z-index: 100000; pointer-events: none; }
.toast { background: rgba(0,0,0,0.85); color: white; padding: 10px 24px; border-radius: 25px; font-size: 13px; margin-bottom: 10px; box-shadow: var(--shadow); }

/* =========================================================
   移动端终极响应式适配 (全屏沉浸与内部弹性滚动)
   ========================================================= */
@media (max-width: 850px) { 
    .desktop-only { display: none !important; }
    .pc-qr-box { display: none !important; }
    .mobile-qr-btn { display: inline-flex !important; } 

    .chat-wrapper { height: auto; min-height: calc(100vh - 80px); display: flex; flex-direction: column; }
    .chat-header { padding: 16px 12px; flex-shrink: 0; }
    .chat-title { font-size: 1.4rem; }
    .chat-workspace { padding: 10px; display: flex; flex-direction: column; flex: 1; }
    
    /* 解除高度限制，允许自然拉伸 */
    .chat-layout { flex-direction: column; height: 100%; min-height: auto; gap: 10px; display: flex; } 
    
    .chat-sys-panel { width: 100%; padding: 12px; display: grid; grid-template-columns: 1fr 1fr; gap: 10px; overflow: hidden; border-radius: 12px; flex-shrink: 0; }
    .chat-panel-title { display: none; }
    
    .id-display-card, .dial-card { padding: 10px; margin: 0; display: flex; flex-direction: column; justify-content: center; }
    .id-label, .qr-label { font-size: 10px; margin-bottom: 4px; }
    .id-number { font-size: 22px; letter-spacing: 2px; }
    .id-actions { margin-top: 8px; gap: 6px; }
    .id-actions .btn { font-size: 12px; padding: 6px; }
    .id-actions .btn span, .btn-connect-action span { display: none; }
    .dial-input { font-size: 18px; padding: 6px; margin-bottom: 0; text-align: center; }
    .btn-connect-action { font-size: 13px; padding: 6px; margin-top: 8px; }
    .connection-status-card { grid-column: 1 / 3; margin-top: 0; padding: 8px 12px; }
    
    /* 未连接时的默认状态：允许自然撑高 */
    .chat-msg-panel { padding: 12px; flex: 1; display: flex; flex-direction: column; border-radius: 12px; height: auto; min-height: 400px; }

    /* ==========================================================
       【核心修复】：手机端连接成功后，强行霸占整个屏幕并开启内部滚动！
       ========================================================== */
    .chat-wrapper.is-connected { 
        position: fixed !important; top: 0; left: 0; right: 0; bottom: 0;
        width: 100vw; height: 100vh; z-index: 99999;
        border-radius: 0; border: none; margin: 0;
        background: var(--bg);
    }
    .chat-wrapper.is-connected .chat-header { display: none; }
    .chat-wrapper.is-connected .chat-features-bento { display: none; }
    .chat-wrapper.is-connected .chat-workspace { padding: 10px; height: 100%; display: flex; flex-direction: column; }
    .chat-wrapper.is-connected .chat-layout { height: 100%; min-height: 0; gap: 10px; flex: 1; display: flex; flex-direction: column; }
    
    /* 面板本身高度被锁死在视口内，超出的内容在内部滚动 */
    .chat-wrapper.is-connected .chat-msg-panel { 
        flex: 1; height: 0; /* 触发 flex 内部滚动 */
        overflow-y: auto; overflow-x: hidden; 
        padding-bottom: max(20px, env(safe-area-inset-bottom));
    }

    /* 内部容器允许无限撑高 */
    .dashboard-container { height: max-content; gap: 12px; padding-bottom: 20px; }
    
    /* Grid 在手机端直接单列排列，绝不互相挤压 */
    .dash-top-grid { grid-template-columns: 1fr; gap: 12px; }
    .ice-diag-card, .action-card { padding: 15px; }
    
    .metrics-grid { grid-template-columns: 1fr; gap: 12px; }
    .speed-card { min-height: 200px; }
    /* 大字号在手机上稍微缩小，并使用 vw 单位防止越界 */
    .metric-value { font-size: 14vw; } 
    
    .side-metrics { flex-direction: row; gap: 12px; }
    .metric-value-wrapper.small .metric-value { font-size: 8vw; }
    
    .terminal-log { height: 120px; font-size: 12px; flex-shrink: 0;}

    .chat-features-bento { grid-template-columns: 1fr; padding: 0 10px 20px 10px; gap: 12px; }
    .bento-card { padding: 16px; gap: 8px; border-radius: 12px; }
}

[data-theme="dark"]:root { --bg: #1e293b; --card: #0f172a; --text-main: #f8fafc; --text-sub: #94a3b8; --border: #334155; }
[data-theme="dark"] .chat-msg-panel { background: #0f172a; border-color: #334155; }
[data-theme="dark"] .ice-diag-card, [data-theme="dark"] .action-card, [data-theme="dark"] .metric-card { background: #1e293b; border-color: #334155; }
[data-theme="dark"] .board-overlay { background: rgba(15,23,42,0.9); }
[data-theme="dark"] .btn-secondary { background: #334155; color: #f8fafc; border: 1px solid #475569; }
[data-theme="dark"] .btn-secondary:hover { background: #475569; }
[data-theme="dark"] .bento-card { background: #0f172a; border-color: #334155; }
[data-theme="dark"] .bento-card:hover { border-color: var(--primary); }
[data-theme="dark"] .metric-value-wrapper.small .metric-value { color: #f8fafc; }