/* TestNet 网络检测系统 - 共用样式 */
:root {
    --primary: #4f46e5;
    --primary-light: #818cf8;
    --success: #22c55e;
    --warning: #f59e0b;
    --danger: #ef4444;
    --bg: #0f172a;
    --bg-card: #1e293b;
    --bg-card-hover: #334155;
    --text: #f1f5f9;
    --text-muted: #94a3b8;
    --border: #334155;
    --radius: 12px;
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html {
    font-size: 16px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'PingFang SC', 'Microsoft YaHei', sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    min-height: 100dvh;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    overflow-x: hidden;
}

/* 头部 */
.header {
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    padding: 12px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 100;
    /* iOS safe area */
    padding-top: max(12px, env(safe-area-inset-top));
}

.header-title {
    font-size: 18px;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 8px;
}

.header-title .logo {
    width: 32px;
    height: 32px;
    background: var(--primary);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    flex-shrink: 0;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
    flex-shrink: 0;
}

.status-dot.online {
    background: var(--success);
    box-shadow: 0 0 6px var(--success);
    animation: pulse 2s infinite;
}

.status-dot.offline {
    background: var(--danger);
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* 主内容区 */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 16px;
    padding-bottom: calc(16px + var(--safe-bottom));
}

/* 统计卡片 */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    margin-bottom: 16px;
}

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    transition: all 0.2s;
}

.stat-card:hover {
    border-color: var(--primary-light);
}

.stat-label {
    font-size: 12px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 4px;
}

.stat-value {
    font-size: 24px;
    font-weight: 700;
    color: var(--text);
    line-height: 1.2;
}

.stat-value.good { color: var(--success); }
.stat-value.warn { color: var(--warning); }
.stat-value.bad { color: var(--danger); }

.stat-unit {
    font-size: 12px;
    font-weight: 400;
    color: var(--text-muted);
    margin-left: 2px;
}

/* 迷你图 */
.sparkline {
    margin-top: 6px;
    height: 24px;
    position: relative;
}

.sparkline svg {
    width: 100%;
    height: 100%;
}

/* 拨测站点列表 */
.targets-section {
    margin-bottom: 16px;
}

.targets-list {
    padding: 8px 0;
}

.target-item {
    display: flex;
    align-items: center;
    padding: 10px 16px;
    border-bottom: 1px solid var(--border);
    gap: 10px;
}

.target-item:last-child {
    border-bottom: none;
}

.target-status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
    background: var(--text-muted);
}

.target-status-dot.online {
    background: var(--success);
    box-shadow: 0 0 4px var(--success);
}

.target-status-dot.offline {
    background: var(--danger);
    box-shadow: 0 0 4px var(--danger);
}

.target-info {
    flex: 1;
    min-width: 0;
}

.target-name {
    font-size: 14px;
    font-weight: 600;
}

.target-url {
    font-size: 11px;
    color: var(--text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.target-result {
    font-size: 14px;
    font-weight: 700;
    min-width: 60px;
    text-align: right;
    flex-shrink: 0;
}

.target-result.good { color: var(--success); }
.target-result.warn { color: var(--warning); }
.target-result.bad { color: var(--danger); }

.empty-targets {
    text-align: center;
    padding: 20px 16px;
    color: var(--text-muted);
    font-size: 13px;
}

/* 控制栏 */
.control-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
    padding: 0 4px;
}

.session-info {
    display: flex;
    align-items: center;
    gap: 6px;
}

.session-label {
    color: var(--text-muted);
    font-size: 12px;
}

.session-id {
    font-family: 'Courier New', monospace;
    font-size: 11px;
    color: var(--text-muted);
    background: rgba(0, 0, 0, 0.3);
    padding: 3px 6px;
    border-radius: 4px;
}

/* 表格 */
.table-container {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

.table-header {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    font-weight: 600;
    font-size: 14px;
}

table {
    width: 100%;
    border-collapse: collapse;
}

th {
    text-align: left;
    padding: 10px 12px;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
    background: rgba(0, 0, 0, 0.2);
    white-space: nowrap;
}

td {
    padding: 10px 12px;
    font-size: 13px;
    border-bottom: 1px solid var(--border);
}

tr:last-child td {
    border-bottom: none;
}

tr:hover td {
    background: var(--bg-card-hover);
}

tr.offline td {
    opacity: 0.5;
}

tr.offline .status-dot {
    opacity: 1;
}

tr.network-offline td {
    background: rgba(239, 68, 68, 0.08);
}

tr.network-offline td:first-child::before {
    content: '⚠ ';
    color: var(--danger);
}

/* 按钮 */
.btn {
    padding: 8px 16px;
    border: none;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    touch-action: manipulation;
}

.btn-primary {
    background: var(--primary);
    color: white;
}

.btn-primary:hover {
    background: var(--primary-light);
}

.btn-primary:active {
    transform: scale(0.96);
}

.btn-danger {
    background: var(--danger);
    color: white;
}

.btn-danger:hover {
    opacity: 0.8;
}

.btn-danger:active {
    transform: scale(0.96);
}

.btn-sm {
    padding: 6px 12px;
    font-size: 12px;
}

/* 连接状态指示器 */
.connection-status {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    color: var(--text-muted);
}

.status-label {
    font-size: 12px;
}

/* 空状态 */
.empty-state {
    text-align: center;
    padding: 32px 16px;
    color: var(--text-muted);
}

.empty-state .icon {
    font-size: 36px;
    margin-bottom: 12px;
}

/* 登录覆盖层 */
.login-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--bg);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 16px;
}

.login-box {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 32px 24px;
    width: 100%;
    max-width: 360px;
    text-align: center;
}

.login-box h2 {
    margin-bottom: 20px;
    font-size: 20px;
}

.login-box input {
    width: 100%;
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg);
    color: var(--text);
    font-size: 16px; /* iOS 不缩放 */
    margin-bottom: 14px;
    outline: none;
}

.login-box input:focus {
    border-color: var(--primary);
}

.login-error {
    color: var(--danger);
    font-size: 13px;
    margin-bottom: 12px;
    display: none;
}

/* 检测日志 */
.log-container {
    max-height: 250px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.log-entry {
    padding: 6px 16px;
    font-size: 12px;
    font-family: 'Courier New', monospace;
    border-bottom: 1px solid var(--border);
    line-height: 1.5;
    word-break: break-all;
}

.log-entry:last-child {
    border-bottom: none;
}

.log-time {
    color: var(--text-muted);
    margin-right: 8px;
    white-space: nowrap;
}

/* ─── 管理端拨测站点配置 ─── */
.targets-config {
    margin-bottom: 16px;
}

.targets-config-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}

.targets-config-header h3 {
    font-size: 14px;
    font-weight: 600;
}

.target-config-item {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
    padding: 8px 12px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 8px;
}

.target-config-item input {
    flex: 1;
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--bg);
    color: var(--text);
    font-size: 13px;
    outline: none;
    min-width: 0;
}

.target-config-item input:focus {
    border-color: var(--primary);
}

.target-config-item input.name-input {
    max-width: 100px;
    flex: 0 0 100px;
}

.target-config-item .btn-remove {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: none;
    background: var(--danger);
    color: white;
    font-size: 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    padding: 0;
    line-height: 1;
}

/* ─── 历史趋势弹窗 ─── */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    padding: 16px;
}

.modal-box {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    width: 100%;
    max-width: 680px;
    max-height: 90vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    font-weight: 600;
    font-size: 16px;
}

.btn-close {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 20px;
    cursor: pointer;
    padding: 4px 8px;
    line-height: 1;
}

.btn-close:hover {
    color: var(--text);
}

.modal-body {
    padding: 16px 20px;
}

.history-tabs {
    display: flex;
    gap: 4px;
    margin-bottom: 16px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.history-tab {
    padding: 6px 14px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: transparent;
    color: var(--text-muted);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.15s;
}

.history-tab.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

.history-chart {
    min-height: 200px;
}

.history-stats {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 12px;
}

.history-stat {
    flex: 1 1 60px;
    min-width: 60px;
    text-align: center;
    padding: 8px 4px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 6px;
}

.history-stat-label {
    display: block;
    font-size: 10px;
    color: var(--text-muted);
    text-transform: uppercase;
    margin-bottom: 2px;
}

.history-stat-val {
    font-size: 14px;
    font-weight: 700;
    color: var(--text);
}

/* ─── 响应式 ─── */

/* 平板 (768px+) */
@media (min-width: 768px) {
    .container {
        padding: 24px;
    }

    .header {
        padding: 16px 24px;
        padding-top: max(16px, env(safe-area-inset-top));
    }

    .header-title {
        font-size: 20px;
    }

    .stats-grid {
        grid-template-columns: repeat(4, 1fr);
        gap: 16px;
    }

    .stat-value {
        font-size: 28px;
    }

    .stat-label {
        font-size: 13px;
    }

    .log-container {
        max-height: 300px;
    }

    .log-entry {
        font-size: 13px;
    }
}

/* 大屏 (1024px+) */
@media (min-width: 1024px) {
    .stats-grid {
        gap: 20px;
    }

    .stat-card {
        padding: 20px;
    }
}

/* 小手机 (360px 以下) */
@media (max-width: 359px) {
    .stats-grid {
        gap: 8px;
    }

    .stat-card {
        padding: 12px;
    }

    .stat-value {
        font-size: 20px;
    }

    .stat-label {
        font-size: 11px;
    }

    .header-title .header-text {
        font-size: 15px;
    }

    .target-name {
        min-width: 50px;
        font-size: 13px;
    }

    .target-result {
        min-width: 50px;
        font-size: 13px;
    }
}

/* 横屏手机 */
@media (max-height: 500px) and (orientation: landscape) {
    .stats-grid {
        grid-template-columns: repeat(4, 1fr);
        gap: 8px;
        margin-bottom: 8px;
    }

    .stat-card {
        padding: 8px 12px;
    }

    .stat-value {
        font-size: 18px;
    }

    .sparkline {
        display: none;
    }

    .log-container {
        max-height: 150px;
    }
}

/* 滚动条 */
::-webkit-scrollbar {
    width: 4px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 2px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}
