/* ============ 全局设计系统 ============ */
:root {
    --color-primary: #2563eb;
    --color-primary-dark: #1e40af;
    --color-primary-light: #dbeafe;
    --color-success: #16a34a;
    --color-success-light: #dcfce7;
    --color-warning: #d97706;
    --color-warning-light: #fef3c7;
    --color-danger: #dc2626;
    --color-danger-light: #fee2e2;
    --color-info: #0891b2;
    --color-info-light: #cffafe;
    --color-bg: #f8fafc;
    --color-surface: #ffffff;
    --color-surface-dark: #1e293b;
    --color-text: #0f172a;
    --color-text-muted: #64748b;
    --color-border: #e2e8f0;
    --radius-sm: 6px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
    --shadow-md: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
    --shadow-lg: 0 4px 6px -1px rgba(0,0,0,0.1), 0 2px 4px -2px rgba(0,0,0,0.1);
}

/* ============ 全局 ============ */
body {
    background: var(--color-bg);
    color: var(--color-text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
    -webkit-font-smoothing: antialiased;
}

/* ============ 导航栏 ============ */
.nav-bar {
    background: linear-gradient(135deg, #1e3a8a 0%, #1e40af 100%);
    color: #fff;
    box-shadow: 0 4px 12px rgba(30, 58, 138, 0.3);
    position: relative;
    z-index: 1000;
}
.nav-bar a {
    color: rgba(255,255,255,0.8);
    transition: all 0.2s;
    padding: 6px 14px;
    border-radius: 6px;
    font-weight: 500;
}
.nav-bar a:hover {
    color: #fff;
    background: rgba(255,255,255,0.1);
}
.nav-bar a.nav-active {
    color: #fff;
    background: rgba(255,255,255,0.2);
}
.nav-bar .nav-dropdown a.nav-active {
    color: var(--color-primary-dark) !important;
    background: #dbeafe !important;
}

/* 下拉菜单内的 <a> 要深色文字（白底配白字看不见） */
.nav-bar .nav-dropdown a {
    color: var(--color-text) !important;
    padding: 8px 16px !important;
    border-radius: 0 !important;
    font-weight: normal !important;
}
.nav-bar .nav-dropdown a:hover {
    color: var(--color-primary-dark) !important;
    background: #f1f5f9 !important;
}
.nav-bar .nav-dropdown a.font-semibold {
    font-weight: 600 !important;
    color: var(--color-primary) !important;
}

/* 下拉菜单：hover/focus-within 展开 + 层级 */
.nav-group { position: relative; z-index: 1001; }
.nav-group:hover .nav-dropdown,
.nav-group:focus-within .nav-dropdown {
    opacity: 1; visibility: visible; transform: translateY(0);
}
.nav-dropdown {
    z-index: 2000 !important;
    transition: opacity .15s, transform .15s;
}
.nav-bar .nav-logo {
    font-weight: 700;
    font-size: 1.1rem;
    letter-spacing: 0.5px;
}

/* ============ 卡片 ============ */
.surface-card {
    background: var(--color-surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    border: 1px solid var(--color-border);
}
.stat-card {
    background: linear-gradient(135deg, #fff 0%, #f8fafc 100%);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    border: 1px solid var(--color-border);
    position: relative;
    overflow: hidden;
    transition: transform 0.2s, box-shadow 0.2s;
}
.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}
.stat-card::before {
    content: '';
    position: absolute;
    top: 0; left: 0;
    width: 4px; height: 100%;
    background: var(--stat-color, var(--color-primary));
}

/* ============ 按钮 ============ */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: var(--radius-md);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    border: 1px solid transparent;
    transition: all 0.15s;
    text-decoration: none;
}
.btn-primary { background: var(--color-primary); color: #fff; }
.btn-primary:hover { background: var(--color-primary-dark); }
.btn-secondary { background: #fff; color: var(--color-text); border-color: var(--color-border); }
.btn-secondary:hover { background: #f1f5f9; }
.btn-danger { background: var(--color-danger); color: #fff; }
.btn-danger:hover { background: #b91c1c; }
.btn-success { background: var(--color-success); color: #fff; }
.btn-success:hover { background: #15803d; }

/* ============ 徽章（统一体系） ============ */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 500;
    letter-spacing: 0.02em;
    white-space: nowrap;
}
/* 卡密状态 */
.badge-unused  { background: #e0e7ff; color: #4338ca; }
.badge-used    { background: var(--color-success-light); color: var(--color-success); }
.badge-revoked { background: var(--color-danger-light); color: var(--color-danger); }
.badge-expired { background: var(--color-warning-light); color: var(--color-warning); }
/* 设备状态 */
.badge-active  { background: var(--color-success-light); color: var(--color-success); }
.badge-banned  { background: var(--color-danger-light); color: var(--color-danger); }
/* 多开授权规格 */
.badge-multi   { background: var(--color-info-light); color: var(--color-info); }
.badge-trial   { background: #f3e8ff; color: #7c3aed; }
/* 实例心跳 */
.badge-warning { background: var(--color-warning-light); color: var(--color-warning); }

/* ============ 表格 ============ */
.table-header th {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 600;
    color: var(--color-text-muted);
    background: #f8fafc;
    border-bottom: 1px solid var(--color-border);
}
.table-row:hover { background: #f8fafc; }

/* ============ 筛选栏 ============ */
.filter-bar select,
.filter-bar input {
    min-width: 160px;
}

/* ============ 统计数字 ============ */
.stat-number {
    font-size: 2rem;
    font-weight: 700;
    line-height: 1.1;
    font-variant-numeric: tabular-nums;
}

/* ============ 登录页 ============ */
.login-card {
    background: #fff;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg), 0 0 80px rgba(30,58,138,0.15);
    border: 1px solid var(--color-border);
}

/* ============ Card key 脱敏 ============ */
.card-key-masked {
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    letter-spacing: 0.5px;
}

/* ============ 表单 ============ */
input[type="text"], input[type="password"], input[type="number"], select, textarea {
    transition: border-color 0.15s, box-shadow 0.15s;
}
input[type="text"]:focus, input[type="password"]:focus, input[type="number"]:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--color-primary) !important;
    box-shadow: 0 0 0 3px rgba(37,99,235,0.15);
}
input[readonly].bg-gray-100 {
    background: #f1f5f9 !important;
    color: #64748b;
    cursor: not-allowed;
}

/* ============ 弹窗 ============ */
.modal-overlay {
    backdrop-filter: blur(4px);
}

/* ============ 渐变分隔线 ============ */
.hr-gradient {
    height: 1px;
    background: linear-gradient(90deg, transparent, var(--color-border), transparent);
    border: none;
}
/* 诊断自检结论徽章（设计 11-L2 §6.1：ok 绿 / degraded 橙 / fail 红） */
.badge-ok {
    background: #dcfce7;
    color: #16a34a;
}
.badge-degraded {
    background: #fef3c7;
    color: #d97706;
}
.badge-fail {
    background: #fee2e2;
    color: #dc2626;
}

/* ============ 场控（淘宝直播） ============ */
.live-msg {
    cursor: pointer;
    transition: opacity .3s, transform .3s, border-color .15s, box-shadow .15s;
}
.live-msg:hover { border-color: #cbd5e1; }
.live-msg.selected {
    border-color: var(--color-primary);
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.18);
}
.live-msg.resolved { opacity: .55; }
.live-msg.resolved:hover { opacity: .8; }
.live-msg .live-text { white-space: pre-wrap; word-break: break-word; }
.live-msg .live-text.clamp2 {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.live-msg .live-text.clamp2.open {
    display: block;
    -webkit-line-clamp: unset;
    overflow: visible;
}
.live-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 12px;
    border-radius: 999px;
    border: 1px solid var(--color-border);
    background: #fff;
    font-size: 13px;
    color: var(--color-text);
    cursor: pointer;
    white-space: nowrap;
    transition: all .15s;
}
.live-chip:hover { border-color: #94a3b8; }
.live-chip.active {
    background: var(--color-primary);
    border-color: var(--color-primary);
    color: #fff;
}
.live-chip .dot { width: 7px; height: 7px; border-radius: 50%; background: #cbd5e1; }
.live-chip .dot.on { background: #22c55e; }
.live-chip.active .dot { background: #fff; }

/* 语音条 / 按住说话 */
.live-voicebar {
    background: #fff;
    border-top: 1px solid var(--color-border);
    box-shadow: 0 -4px 16px rgba(15, 23, 42, 0.06);
}
.talk-btn {
    touch-action: none;
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
    min-width: 128px;
    height: 44px;
    border-radius: 999px;
    background: var(--color-primary);
    color: #fff;
    font-size: 15px;
    font-weight: 600;
    border: none;
    cursor: pointer;
}
.talk-btn:active, .talk-btn.recording { background: var(--color-primary-dark); }
.talk-btn.cancel { background: var(--color-danger); }
.talk-btn[disabled] { opacity: .5; cursor: not-allowed; }
/* 录音浮层提示（微信式）：录音中「上滑取消」，上滑到阈值变红「松开手指，取消发送」 */
.talk-tip {
    position: fixed;
    left: 50%;
    transform: translateX(-50%);
    z-index: 45;
    padding: 9px 16px;
    border-radius: 10px;
    background: rgba(15, 23, 42, .9);
    color: #fff;
    font-size: 13px;
    font-weight: 600;
    white-space: nowrap;
    pointer-events: none;
    opacity: 0;
    transition: opacity .12s ease, background .12s ease;
}
.talk-tip.show { opacity: 1; }
.talk-tip.cancel { background: rgba(220, 38, 38, .94); }
/* 长按不弹系统菜单（复制/分享/全选）：按钮与整条语音栏禁用文本选择与 iOS callout */
.talk-btn,
.talk-btn *,
.live-voicebar,
.live-voicebar * {
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
    -webkit-user-drag: none;
}
.talk-btn { -webkit-tap-highlight-color: transparent; }
.live-level {
    height: 6px;
    border-radius: 999px;
    background: #e2e8f0;
    overflow: hidden;
}
.live-level > i {
    display: block;
    height: 100%;
    width: 0;
    background: linear-gradient(90deg, #22c55e, #eab308, #ef4444);
    transition: width .06s linear;
}
.live-recording { background: rgba(37, 99, 235, 0.08); }

/* ============ 按钮 loading 态 ============ */
button[disabled],
.btn[disabled] {
    opacity: 0.6;
    cursor: not-allowed;
}
.btn-loading::before {
    content: '';
    display: inline-block;
    width: 12px;
    height: 12px;
    margin-right: 6px;
    border: 2px solid currentColor;
    border-top-color: transparent;
    border-radius: 50%;
    animation: btn-spin 0.6s linear infinite;
    vertical-align: -2px;
}
@keyframes btn-spin {
    to { transform: rotate(360deg); }
}

/* ============ 汉堡菜单按钮（默认隐藏，仅移动端显示） ============ */
.nav-burger {
    display: none;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    font-size: 18px;
    line-height: 1;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
    cursor: pointer;
    border: none;
}

/* ============ 响应式：移动端（<768px） ============ */
@media (max-width: 768px) {
    /* 导航折叠为汉堡菜单 */
    .nav-burger { display: inline-flex; }
    .nav-menu {
        display: none;
    }
    .nav-menu.open {
        display: flex;
        flex-direction: column;
        align-items: stretch;
        position: absolute;
        top: 100%;
        left: 0;
        right: 0;
        padding: 8px 12px 16px;
        gap: 2px;
        background: linear-gradient(180deg, #1e3a8a 0%, #1e40af 100%);
        box-shadow: 0 12px 24px rgba(15, 23, 42, 0.35);
        max-height: 72vh;
        overflow-y: auto;
        z-index: 1900;
    }
    /* 移动端分组按钮退化为分组标题，下拉内容常显（避免 hover 不可用） */
    .nav-menu .nav-group > button {
        pointer-events: none;
        width: 100%;
        font-size: 12px;
        opacity: 0.7;
        padding: 8px 4px 2px;
        background: transparent !important;
    }
    .nav-menu .nav-dropdown {
        position: static;
        opacity: 1;
        visibility: visible;
        transform: none;
        padding-top: 0;
    }
    .nav-menu .nav-dropdown > div {
        width: 100% !important;
        box-shadow: none;
        border: none;
        background: rgba(255, 255, 255, 0.06);
    }
    .nav-menu .nav-dropdown a { color: #fff !important; }
    .nav-menu .nav-dropdown a:hover,
    .nav-menu .nav-dropdown a.nav-active {
        background: rgba(255, 255, 255, 0.15) !important;
    }
    .nav-menu > a {
        width: 100%;
        display: block;
    }

    /* 表格容器横向滚动，避免 8~10 列宽表撑破视口 */
    main .rounded-lg.shadow.overflow-hidden {
        overflow-x: auto;
        overflow-y: hidden;
        -webkit-overflow-scrolling: touch;
    }
    main table {
        min-width: 560px;
    }

    /* 统计卡 / 栅格在窄屏降为单列 */
    main .grid.grid-cols-2,
    main .grid.grid-cols-3,
    main .grid.grid-cols-4 {
        grid-template-columns: repeat(1, minmax(0, 1fr)) !important;
    }

    /* 筛选栏 / 顶部操作区换行 */
    main form.flex,
    main .flex.items-center.justify-between {
        flex-wrap: wrap;
        gap: 8px 12px;
    }

    /* 弹窗宽度自适应 */
    main .fixed.inset-0 > div {
        width: 92vw !important;
        max-width: 92vw !important;
    }

    /* 页面标题缩小 */
    main h1.text-2xl {
        font-size: 1.25rem;
    }
}

