/* ================================================================
   GBHub 国标视频平台 - 全局样式
   ================================================================ */

:root {
    --bg: #f0f2f5;
    --card-bg: #fff;
    --text: #1e293b;
    --text-secondary: #64748b;
    --border: #e2e8f0;
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --danger: #ef4444;
    --danger-hover: #dc2626;
    --success: #10b981;
    --radius: 10px;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04);
    --shadow: 0 4px 6px rgba(0, 0, 0, 0.04), 0 2px 4px rgba(0, 0, 0, 0.02);
    --shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.08);
    --font:
        "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
        "Helvetica Neue", sans-serif;
    --header-bg: #1d4ed8;
}
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}
body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    padding: 1.5rem;
    min-height: 100vh;
    -webkit-tap-highlight-color: transparent;
}
.container {
    max-width: min(1520px, 94vw);
    margin: 0 auto;
}

/* 2K+ 屏，放宽到 1700px */
@media (min-width: 2000px) {
    .container {
        max-width: 1700px;
    }
}

/* 4K 屏，再放宽到 1900px */
@media (min-width: 2800px) {
    .container {
        max-width: 1900px;
    }
}

/* ============ 顶部 ============ */
.app-header {
    background: var(--header-bg);
    color: white;
    padding: 0 1.5rem;
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 1rem;
    margin-bottom: 1.5rem;
    box-shadow: var(--shadow-lg);
    min-height: 72px;
}
.app-header .brand {
    display: flex;
    align-items: center;
    flex-shrink: 0;
}
.app-header .brand-logo {
    height: 52px;
    width: auto;
    display: block;
}
.header-actions {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

/* ============ 按钮 ============ */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
    padding: 0.5rem 1.1rem;
    border: none;
    border-radius: 8px;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
    background: var(--card-bg);
    color: var(--text);
    border: 1px solid var(--border);
    text-decoration: none;
    -webkit-touch-callout: none;
}
.btn-primary {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}
.btn-primary:hover {
    background: var(--primary-hover);
}
.btn-secondary {
    background: #f1f5f9;
    color: #334155;
    border-color: #e2e8f0;
}
.btn-secondary:hover {
    background: #e2e8f0;
}
.btn-sm {
    padding: 0.3rem 0.7rem;
    font-size: 0.8rem;
    border-radius: 6px;
}
.btn-success,
.btn-warning,
.btn-info {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}
.btn-success:hover,
.btn-warning:hover,
.btn-info:hover {
    background: var(--primary-hover);
    border-color: var(--primary-hover);
}
.btn-danger {
    background: #f1f5f9;
    color: #64748b;
    border-color: #e2e8f0;
}
.btn-danger:hover {
    background: #fee2e2;
    color: #991b1b;
    border-color: #fecaca;
}
.header-actions .btn {
    background: rgba(255, 255, 255, 0.12);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.25);
}
.header-actions .btn:hover {
    background: rgba(255, 255, 255, 0.25);
}

/* ============ 卡片 / 表单 ============ */
.card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    box-shadow: var(--shadow);
    transition: box-shadow 0.2s;
}
.card:hover {
    box-shadow: var(--shadow-lg);
}
.form-group {
    margin-bottom: 1rem;
}
label {
    display: block;
    font-weight: 500;
    margin-bottom: 0.35rem;
    color: var(--text-secondary);
    font-size: 0.85rem;
}
input,
select {
    width: 100%;
    padding: 0.6rem 0.8rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 0.9rem;
    transition: all 0.2s;
    background: #f8fafc;
}
input:focus,
select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
    background: white;
}
.flex-row {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
}
.flex-row > * {
    flex: 1 1 200px;
}

/* ============ 标签栏 ============ */
.tabs {
    display: flex;
    gap: 0.25rem;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 0.3rem;
    box-shadow: var(--shadow-sm);
}
.tablink {
    background: transparent;
    border: none;
    border-radius: 8px;
    padding: 0.6rem 1.2rem;
    cursor: pointer;
    font-weight: 500;
    font-size: 0.9rem;
    transition: all 0.2s;
    color: var(--text-secondary);
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    gap: 5px;
}
.tablink.active {
    background: var(--primary);
    color: white;
    box-shadow: 0 2px 6px rgba(37, 99, 235, 0.4);
}
.tablink:hover:not(.active) {
    background: #f1f5f9;
}

/* ============ 表格 ============ */
table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    margin-top: 0.5rem;
    border-radius: 8px;
    overflow: hidden;
    border: 1px solid var(--border);
}
th,
td {
    text-align: left;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border);
    font-size: 0.9rem;
}
th {
    font-weight: 600;
    background: #f8fafc;
    color: #475569;
    white-space: nowrap;
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}
tbody tr:hover {
    background: #f8fafc;
    cursor: pointer;
}

/* ============ 分页 ============ */
.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.3rem;
    margin-top: 1rem;
    flex-wrap: wrap;
}
.page-btn {
    padding: 0.3rem 0.7rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--card-bg);
    cursor: pointer;
    font-size: 0.85rem;
    transition: all 0.2s;
}
.page-btn.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}
.page-btn:hover:not(.active) {
    background: #f1f5f9;
}
.page-size-select {
    width: auto;
    padding: 0.3rem 0.5rem;
}

/* ============ 提示 ============ */
.alert {
    padding: 0.8rem 1.2rem;
    border-radius: 8px;
    margin-bottom: 1rem;
    font-size: 0.9rem;
}
.alert-error {
    background: #fee2e2;
    color: #991b1b;
    border: 1px solid #fecaca;
}
.alert-success {
    background: #dcfce7;
    color: #166534;
    border: 1px solid #bbf7d0;
}
.hidden {
    display: none !important;
}
.status-badge {
    display: inline-block;
    padding: 0.15em 0.7em;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.2px;
}
.status-ok {
    background: #dcfce7;
    color: #166534;
}
.status-error {
    background: #fee2e2;
    color: #991b1b;
}
#alertBox {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 3000;
    width: auto;
    max-width: 600px;
    pointer-events: none;
}
#alertBox .alert {
    pointer-events: auto;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
}

/* ============ 弹窗 ============ */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background: rgba(15, 23, 42, 0.6);
    backdrop-filter: blur(2px);
    animation: fadeIn 0.2s ease;
}
@keyframes fadeIn {
    from {
        opacity: 0;
    }
}
.modal-content {
    background: #fff;
    margin: 5% auto;
    padding: 1.8rem;
    width: 90%;
    max-width: 1000px;
    border-radius: 16px;
    position: relative;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 25px 50px rgba(0, 0, 0, 0.2);
    overflow-x: hidden;
}
.close-btn {
    position: absolute;
    right: 15px;
    top: 12px;
    font-size: 22px;
    cursor: pointer;
    color: #94a3b8;
    background: #f1f5f9;
    border: none;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}
.close-btn:hover {
    background: #e2e8f0;
    color: #0f172a;
}

/* ============ 播放器 ============ */
#videoElement {
    width: 100%;
    max-height: 65vh;
    background: #0f172a;
    border-radius: 8px;
    object-fit: cover;
}
.ptz-controls {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    margin-top: 1rem;
}
.ptz-controls div {
    display: flex;
    gap: 6px;
}
.error-msg {
    color: #b91c1c;
    text-align: center;
    padding: 0.8rem;
    background: #fee2e2;
    margin-top: 0.5rem;
    border-radius: 6px;
}

/* ============ 录像列表 ============ */
.record-list {
    margin-top: 1rem;
    max-height: 420px;
    overflow-y: auto;
    border: 1px solid var(--border);
    border-radius: 8px;
}
.record-item {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid #f1f5f9;
    transition: background 0.1s;
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
}
.record-item:hover {
    background: #f8fafc;
}
.record-item input[type="checkbox"] {
    margin-top: 0.3rem;
    width: auto;
    cursor: pointer;
}
.record-item-content {
    flex: 1;
}

/* ============ 通道表格 ============ */
.channel-modal-table {
    width: 100%;
    margin-top: 0.5rem;
    table-layout: auto;
    font-size: 0.85rem;
}
.channel-modal-table th,
.channel-modal-table td {
    padding: 0.5rem 0.6rem;
    white-space: nowrap;
    font-size: 0.85rem;
}
.channel-modal-table td select {
    width: 130px;
    font-size: 0.8rem;
    padding: 0.3rem 0.5rem;
}

/* ============ 搜索栏 ============ */
.search-box {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    flex-wrap: wrap;
    margin-bottom: 1rem;
}
.search-box input {
    max-width: 280px;
}
.search-box select {
    width: auto;
    min-width: 200px;
}
.copy-input {
    width: 260px;
    font-size: 0.8rem;
    padding: 0.3rem 0.5rem;
    margin-right: 0.25rem;
}

/* ============ 设备通道工具栏 ============ */
.channel-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
    flex-wrap: wrap;
    gap: 0.5rem;
}
.channel-toolbar-left {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-shrink: 0;
}
.channel-toolbar-left h3 {
    margin: 0;
    white-space: nowrap;
}
.channel-toolbar-right {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    flex-wrap: wrap;
    flex: 1 1 auto;
    justify-content: flex-end;
    min-width: 0;
}
.channel-toolbar-right input[type="text"] {
    width: 280px;
    min-width: 120px;
    max-width: 340px;
    flex: 0 1 auto;
}
.channel-toolbar-right select {
    width: 85px;
    min-width: 70px;
    flex-shrink: 0;
}
.channel-toolbar-right .btn {
    font-size: 0.75rem;
    padding: 0.25rem 0.5rem;
    white-space: nowrap;
    flex-shrink: 0;
}

/* ============ 列表页通用工具栏 ============ */
.list-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
}
.list-toolbar-left {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
    min-width: 0;
}
.list-toolbar-right {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: nowrap;
    min-width: 0;
}
.list-toolbar-right input {
    width: 240px !important;
    max-width: 240px !important;
    flex: 0 0 240px !important;
}
.list-toolbar-right select {
    width: 110px !important;
    max-width: 110px !important;
    flex: 0 0 110px !important;
}

/* ============ 操作列分组（设备列表） ============ */
.action-group {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    margin-right: 0.6rem;
}
.action-group-label {
    font-size: 0.7rem;
    color: #94a3b8;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    margin-right: 0.15rem;
}
.action-group + .action-group {
    padding-left: 0.6rem;
    border-left: 1px solid var(--border);
    margin-right: 0;
}

/* ============ 流管理表格列宽 ============ */
#zlmMediaTable {
    table-layout: fixed;
    width: 100%;
}

/* 第 1 列：流 ID —— 占据大头，超长自动换行 */
#zlmMediaTable th:nth-child(1),
#zlmMediaTable td:nth-child(1) {
    width: 55%;
    text-align: left;
    word-break: break-all;
    white-space: normal;
}

/* 第 2 列：应用 —— 右对齐 */
#zlmMediaTable th:nth-child(2),
#zlmMediaTable td:nth-child(2) {
    width: 12%;
    text-align: right;
    white-space: nowrap;
}

/* 第 3 列：WS‑TS —— 右对齐 */
#zlmMediaTable th:nth-child(3),
#zlmMediaTable td:nth-child(3) {
    width: 11%;
    text-align: right;
    white-space: nowrap;
}

/* 第 4 列：WebRTC —— 右对齐 */
#zlmMediaTable th:nth-child(4),
#zlmMediaTable td:nth-child(4) {
    width: 11%;
    text-align: right;
    white-space: nowrap;
}

/* 第 5 列：地址 —— 右对齐 */
#zlmMediaTable th:nth-child(5),
#zlmMediaTable td:nth-child(5) {
    width: 11%;
    text-align: right;
    white-space: nowrap;
}

/* 右对齐的列加一点右侧内边距，避免按钮贴边 */
#zlmMediaTable td:nth-child(n+2) {
    padding-right: 1.2rem;
}
#zlmMediaTable th:nth-child(n+2) {
    padding-right: 1.2rem;
}

/* ============ 鉴权 Tab ============ */
.token-select-tab {
    background: transparent;
    border: none;
    padding: 0.5rem 1rem;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 500;
    color: #64748b;
    border-bottom: 2px solid transparent;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 5px;
}
.token-select-tab.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}
.token-select-tab:hover {
    color: #1e293b;
}
.token-select-item {
    padding: 0.5rem 0.8rem;
    cursor: pointer;
    border-radius: 4px;
    transition: background 0.1s;
    border-bottom: 1px solid #f1f5f9;
}
.token-select-item:hover {
    background: #f1f5f9;
}
.token-select-item:last-child {
    border-bottom: none;
}

/* ============ H265 容器 ============ */
#h265web_container {
    width: 100%;
    height: auto;
    max-height: 80vh;
    background: #000;
    position: relative;
    overflow: hidden;
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}
#h265web_container canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100% !important;
    height: 100% !important;
    display: block;
}

/* ============ 内联 SVG 图标 ============ */
.btn-icon {
    width: 14px;
    height: 14px;
    flex-shrink: 0;
    color: currentColor;
    vertical-align: -2px;
    display: inline-block;
    pointer-events: none;
}
.btn .btn-icon {
    margin-right: 2px;
}
.btn-sm .btn-icon {
    width: 12px;
    height: 12px;
}
.tab-icon {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
    color: currentColor;
}
h2 .btn-icon,
h3 .btn-icon,
h4 .btn-icon {
    width: 18px;
    height: 18px;
    vertical-align: -3px;
    margin-right: 4px;
}
@keyframes icon-spin {
    from {
        transform: rotate(0deg);
    }
    to {
        transform: rotate(360deg);
    }
}
.icon-spin {
    animation: icon-spin 1s linear infinite;
    transform-origin: center;
    display: inline-block;
    vertical-align: -2px;
}

/* ============ 响应式 ============ */
@media (max-width: 768px) {
    body {
        padding: 0.5rem;
    }
    .app-header {
        padding: 0.8rem 1rem;
    }
    .app-header .brand-logo {
        height: 40px;
    }
    .btn {
        font-size: 0.8rem;
        padding: 0.4rem 0.8rem;
    }
    .card {
        padding: 1rem;
    }
    table {
        font-size: 0.8rem;
    }
    th,
    td {
        padding: 0.5rem 0.5rem;
    }
    .tablink {
        font-size: 0.8rem;
        padding: 0.4rem 0.8rem;
    }
    .tab-icon {
        width: 14px;
        height: 14px;
    }
    .modal-content {
        padding: 1rem;
        margin: 2% auto;
        max-width: 95%;
    }
    .search-box input {
        max-width: 180px;
    }
    .channel-modal-table td select {
        width: 100px;
    }

    /* 表单字段手机端独占一行 */
    .flex-row > * {
        flex: 1 1 100% !important;
    }

    /* 设备通道工具栏手机适配 */
    .channel-toolbar {
        flex-direction: column;
        align-items: stretch;
        gap: 0.6rem;
    }
    .channel-toolbar-left {
        justify-content: flex-start;
    }
    .channel-toolbar-right {
        justify-content: flex-start;
        flex-wrap: wrap;
        gap: 0.35rem;
    }
    .channel-toolbar-right input[type="text"] {
        width: 100%;
        max-width: none;
        flex: 1 1 100%;
        order: -1;
    }
    .channel-toolbar-right select {
        flex: 0 0 auto;
    }
    .channel-toolbar-right .btn {
        flex: 1 1 calc(50% - 0.35rem);
        font-size: 0.72rem;
        padding: 0.35rem 0.4rem;
        justify-content: center;
    }

    /* 列表页通用工具栏 */
    .list-toolbar {
        flex-direction: column;
        align-items: stretch;
        gap: 0.5rem;
    }
    .list-toolbar-left {
        width: 100%;
        justify-content: flex-start;
        flex-wrap: wrap;
    }
    .list-toolbar-right {
        width: 100%;
        justify-content: flex-start;
        flex-wrap: wrap;
    }
    .list-toolbar-right input {
        flex: 1 1 100% !important;
        width: 100% !important;
        max-width: 100% !important;
    }
    .list-toolbar-right select {
        flex: 1 1 100% !important;
        width: 100% !important;
        max-width: 100% !important;
    }
    .list-toolbar-right .btn {
        flex: 1 1 calc(50% - 0.25rem);
        justify-content: center;
    }

    /* 查询按钮独占一行 */
    .query-btn-wrap {
        flex: 1 1 100% !important;
    }
    .query-btn-wrap .btn {
        width: 100%;
    }

    /* 分页信息 */
    .pagination span {
        font-size: 0.8rem;
    }

    /* ============================================================
       手机端导航横向滚动（一行显示，左右滑动）
       ============================================================ */
    .tabs {
        flex-wrap: nowrap !important;
        overflow-x: auto !important;
        overflow-y: hidden !important;
        -webkit-overflow-scrolling: touch;
        padding-bottom: 0.4rem;
        scrollbar-width: none;
        touch-action: pan-x;
    }
    .tabs::-webkit-scrollbar {
        display: none;
    }
    .tablink {
        flex: 0 0 auto !important;
        white-space: nowrap;
    }

    /* ============================================================
       手机端顶部操作按钮横向滚动
       ============================================================ */
    .header-actions {
        flex-wrap: nowrap !important;
        overflow-x: auto !important;
        overflow-y: hidden !important;
        -webkit-overflow-scrolling: touch;
        width: 100%;
        padding-bottom: 0.3rem;
        scrollbar-width: none;
        touch-action: pan-x;
    }
    .header-actions::-webkit-scrollbar {
        display: none;
    }
    .header-actions .btn {
        flex: 0 0 auto !important;
        white-space: nowrap;
    }

    /* ============================================================
       通用表格卡片化：作用于 .card 内所有 table（含动态生成）
       ============================================================ */
    .card table {
        display: block;
        width: 100% !important;
        border: none;
        background: transparent;
        margin-top: 0.5rem;
        table-layout: auto !important;
    }
    .card table thead {
        display: none;
    }
    .card table tbody {
        display: block;
        width: 100%;
    }
    .card table tr {
        display: block;
        margin-bottom: 0.75rem;
        padding: 0.6rem 0.8rem;
        background: #fff;
        border: 1px solid var(--border);
        border-radius: 8px;
        box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
    }
    .card table tr:hover {
        background: #fff;
        cursor: default;
    }
    .card table th,
    .card table td {
        width: auto !important;
        min-width: 0 !important;
        max-width: none !important;
    }
    .card table td {
        display: block !important;
        padding: 0.35rem 0;
        border-bottom: 1px dashed #f1f5f9;
        font-size: 0.8rem;
        white-space: normal !important;
        word-break: break-word !important;
        overflow-wrap: anywhere !important;
        text-align: left;
        line-height: 1.5;
    }
    .card table td:last-child {
        border-bottom: none;
        padding-bottom: 0;
    }
    .card table td::before {
        content: attr(data-label);
        font-weight: 600;
        color: #64748b;
        display: inline-block;
        min-width: 76px;
        margin-right: 0.5rem;
        font-size: 0.72rem;
        text-transform: uppercase;
        letter-spacing: 0.3px;
        vertical-align: top;
        padding-top: 2px;
    }
    .card table td.td-checkbox::before {
        display: none;
    }
    .card table td.td-checkbox {
        padding-bottom: 0.5rem;
    }

    /* ============================================================
       操作列分组手机端（设备列表 / 通用）
       ============================================================ */
    .card table td.td-actions {
        display: block !important;
        padding-top: 0.5rem !important;
        border-top: 1px solid #f1f5f9;
        margin-top: 0.35rem;
        width: 100% !important;
    }
    .card table td.td-actions .action-group {
        display: flex !important;
        align-items: center;
        gap: 0.4rem;
        width: 100% !important;
        padding: 0.35rem 0;
        margin: 0 !important;
        border-left: none !important;
        border-bottom: 1px dashed #f1f5f9;
        flex-wrap: nowrap;
    }
    .card table td.td-actions .action-group:last-child {
        border-bottom: none;
        padding-bottom: 0;
    }
    .card table td.td-actions .action-group-label {
        min-width: 42px !important;
        flex: 0 0 42px !important;
        font-size: 0.75rem;
        color: #94a3b8;
        text-align: left;
        padding: 0;
    }
    .card table td.td-actions .action-group .btn {
        flex: 0 0 auto !important;
        min-width: 72px;
        font-size: 0.75rem;
        padding: 0.35rem 0.5rem;
        white-space: nowrap;
        justify-content: center;
        gap: 4px;
    }
    .card table td.td-actions .action-group .btn-icon {
        width: 12px;
        height: 12px;
        margin-right: 2px;
    }

    /* ============================================================
       设备通道列表特化（channel-modal-table）
       ============================================================ */
    .card table.channel-modal-table td {
        padding: 0.3rem 0;
    }
    .card table.channel-modal-table td::before {
        min-width: 60px;
    }
    .card table.channel-modal-table td.td-checkbox {
        display: inline-block;
        width: auto;
        padding: 0 0.5rem 0.4rem 0;
        border-bottom: none;
        margin-right: 0.3rem;
    }
    .card table.channel-modal-table td.td-checkbox::before {
        display: none;
    }
    .card table.channel-modal-table td.td-actions {
        display: inline-block;
        width: auto;
        padding: 0.3rem 0.4rem 0.3rem 0;
        border-bottom: none;
        border-top: none;
        margin-top: 0;
        white-space: nowrap;
    }
    .card table.channel-modal-table td.td-actions::before {
        display: none;
    }

    /* ============================================================
       修复级联页在手机端卡片变窄
       ============================================================ */
    .tabcontent,
    .tabcontent > .card,
    .tabcontent .card {
        display: block !important;
        width: 100% !important;
        max-width: 100% !important;
        min-width: 0 !important;
        box-sizing: border-box !important;
        overflow-x: hidden !important;
    }

    /* flex-row 容器撑满父容器 */
    .tabcontent .flex-row {
        display: flex !important;
        flex-wrap: wrap !important;
        width: 100% !important;
        max-width: 100% !important;
        min-width: 0 !important;
        gap: 0.6rem !important;
        align-items: stretch !important;
    }

    /* flex-row 子元素：每行一个，可收缩，不撑破父容器 */
    .tabcontent .flex-row > * {
        flex: 0 0 100% !important;
        width: 100% !important;
        max-width: 100% !important;
        min-width: 0 !important;
        box-sizing: border-box !important;
    }

    /* 表单内的 input / select 撑满 */
    .tabcontent .flex-row .form-group {
        width: 100% !important;
        max-width: 100% !important;
        min-width: 0 !important;
    }
    .tabcontent .flex-row .form-group input,
    .tabcontent .flex-row .form-group select {
        width: 100% !important;
        max-width: 100% !important;
        min-width: 0 !important;
        box-sizing: border-box !important;
    }

    /* ========== 播放器移动端关闭按钮 ========== */
    #playerModal .close-btn {
        position: fixed !important;
        top: 12px;
        right: 12px;
        z-index: 9999 !important;
        width: 44px;
        height: 44px;
        font-size: 26px;
        background: rgba(0, 0, 0, 0.75);
        color: #fff;
        border: 1px solid rgba(255, 255, 255, 0.35);
        box-shadow: 0 2px 10px rgba(0, 0, 0, 0.5);
        pointer-events: auto !important;
    }

    /* ========== iOS Safari 触摸穿透 ========== */
    #playerModal #videoElement {
        pointer-events: none !important;
    }
    #playerModal .close-btn,
    #playerModal #playerModeSwitch,
    #playerModal #ptzControlInPlayer,
    #playerModal #playerErrorMsg {
        pointer-events: auto !important;
    }
}

/* ================================================================
   强制隐藏（必须放在所有规则之后，否则会被 display:block 覆盖）
   ================================================================ */
.tabcontent.hidden,
.tabcontent.hidden > *,
.tabcontent.hidden .card,
.tabcontent.hidden .list-toolbar,
.tabcontent.hidden .flex-row,
.tabcontent.hidden table {
    display: none !important;
    visibility: hidden !important;
}

/* 其他 hidden 元素（含 modal、卡片内隐藏区域） */
.hidden,
.card.hidden,
.modal.hidden {
    display: none !important;
}

/* ================================================================
   列表 / 表格内的操作按钮：统一灰色（除"添加"类主按钮外）
   作用于：设备列表、通道列表、流管理、拉流、推流、告警、用户、
           节点、任务、录像等所有卡片内表格的操作列
   ================================================================ */

/* 表格单元格里的主色按钮（查看、WS-TS、录像等）→ 灰底 */
.card table td .btn-primary,
.channel-modal-table td .btn-primary,
.card table td .btn-success,
.card table td .btn-info,
.card table td .btn-warning {
    background: #f1f5f9;
    color: #334155;
    border-color: #e2e8f0;
}
.card table td .btn-primary:hover,
.channel-modal-table td .btn-primary:hover,
.card table td .btn-success:hover,
.card table td .btn-info:hover,
.card table td .btn-warning:hover {
    background: #e2e8f0;
    border-color: #cbd5e1;
}

/* 删除按钮保持：灰底 + hover 微红 */
.card table td .btn-danger,
.channel-modal-table td .btn-danger {
    background: #f1f5f9;
    color: #64748b;
    border-color: #e2e8f0;
}
.card table td .btn-danger:hover,
.channel-modal-table td .btn-danger:hover {
    background: #fee2e2;
    color: #991b1b;
    border-color: #fecaca;
}

/* 表格里的图标跟随按钮文字色 */
.card table td .btn .btn-icon,
.channel-modal-table td .btn .btn-icon {
    color: inherit;
}
/* ============ 页脚版权 ============ */
.app-footer {
    margin-top: 2.5rem;
    padding: 1.5rem 1rem 1.2rem;
    border-top: 1px solid #e2e8f0;
    text-align: center;
    color: #94a3b8;
    font-size: 0.85rem;
    user-select: text;
    -webkit-user-select: text;
    -webkit-touch-callout: default;
}

.app-footer .footer-links {
    display: block;
    margin-top: 0.4rem;
}

.app-footer a {
    color: #64748b;
    text-decoration: none;
    transition: color 0.15s;
}

.app-footer a:hover {
    color: #1d4ed8;
    text-decoration: underline;
}

.app-footer .footer-sep {
    margin: 0 0.5rem;
    color: #cbd5e1;
}
/* ================================================================
   资源监控（硬件指标）
   ================================================================ */
.metrics-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 1rem;
    margin-top: 0.5rem;
}

.metric-panel {
    background: #f8fafc;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 1rem;
}

.metric-head {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-bottom: 0.5rem;
    font-weight: 600;
    color: var(--text);
    font-size: 0.9rem;
}

.metric-value {
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--primary);
    line-height: 1;
}

.metric-bar {
    height: 8px;
    background: var(--border);
    border-radius: 4px;
    overflow: hidden;
    margin-bottom: 0.5rem;
}

.metric-bar-fill {
    height: 100%;
    background: var(--primary);
    width: 0;
    transition: width 0.3s, background 0.3s;
}

.metric-bar-fill.warn {
    background: #f59e0b;
}
.metric-bar-fill.danger {
    background: var(--danger);
}

.metric-sub {
    font-size: 0.82rem;
    color: var(--text-secondary);
    margin-bottom: 0.2rem;
    line-height: 1.4;
}

.metric-cores {
    display: flex;
    gap: 2px;
    margin-top: 0.5rem;
    height: 24px;
    align-items: flex-end;
}

.metric-core {
    flex: 1;
    background: var(--primary);
    border-radius: 2px 2px 0 0;
    min-height: 2px;
    transition: height 0.3s, background 0.3s;
}

.metric-core.warn {
    background: #f59e0b;
}
.metric-core.danger {
    background: var(--danger);
}

/* 资源监控弹窗内的表格：保持表格样式（不受手机端 .card table 卡片化影响） */
#metricsModal table {
    table-layout: fixed;
    font-size: 0.85rem;
}
#metricsModal th,
#metricsModal td {
    padding: 0.5rem 0.7rem;
}
#metricsModal th:nth-child(5),
#metricsModal td:nth-child(5) {
    width: 190px;
}
#metricsModal tbody tr:hover {
    background: transparent;
    cursor: default;
}
#metricsModal .metric-bar {
    margin-bottom: 0;
}

/* 主机信息文本 */
#metricsHostname {
    font-size: 0.85rem;
    color: var(--text-secondary);
    line-height: 1.4;
}

/* ── 手机适配 ── */
@media (max-width: 768px) {
    .metrics-grid {
        grid-template-columns: 1fr;
        gap: 0.75rem;
    }
    .metric-panel {
        padding: 0.85rem;
    }
    .metric-value {
        font-size: 1.2rem;
    }
    .metric-cores {
        height: 20px;
    }

    /* 手机端弹窗内的表格：允许横向滚动，不卡片化 */
    #metricsModal .modal-content {
        max-height: 92vh;
        padding: 1rem;
    }
    #metricsModal .modal-content > table {
        display: block;
        overflow-x: auto;
        white-space: nowrap;
    }
    #metricsModal th:nth-child(5),
    #metricsModal td:nth-child(5) {
        width: auto;
    }
    #metricsModal th,
    #metricsModal td {
        padding: 0.45rem 0.5rem;
        font-size: 0.8rem;
    }
}
/* ============ 告警 AI 列（只显示标签） ============ */
.alarm-ai-cell { white-space: nowrap; }

.alarm-tag {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 4px;
    font-size: 0.75rem;
    line-height: 1.5;
    vertical-align: middle;
    font-weight: 500;
}
/* AI 与设备同样式 */
.alarm-tag-ai,
.alarm-tag-device {
    background: #f1f5f9;
    color: #64748b;
}

/* 可点击的 AI 标签：cursor + hover 轻微加深（不用蓝色） */
.alarm-tag-clickable {
    cursor: pointer;
    transition: background .15s, border-color .15s;
}
.alarm-tag-clickable:hover {
    background: #e2e8f0;
    color: #334155;
}

/* ============ AI 详情弹窗 ============ */
.alarm-detail-body {
    display: flex;
    gap: 1.2rem;
    align-items: flex-start;
    flex-wrap: wrap;
    margin-top: 0.8rem;
}
.alarm-detail-left {
    flex: 1 1 380px;
    min-width: 0;
}
.alarm-detail-right {
    flex: 1 1 260px;
    min-width: 0;
}

.alarm-snapshot-wrap {
    position: relative;
    display: inline-block;
    max-width: 100%;
    line-height: 0;
}
.alarm-snapshot-wrap img {
    display: block;
    max-width: 100%;
    height: auto;
    border-radius: 6px;
}
.detection-overlay {
    position: absolute;
    inset: 0;
    display: none;
    pointer-events: none;
}
.detection-box {
    position: absolute;
    border: 2px solid #ef4444;
    box-sizing: border-box;
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.6);
}
.detection-label {
    position: absolute;
    top: -1.35em;
    left: -2px;
    background: #ef4444;
    color: #fff;
    font-size: 11px;
    line-height: 1.4;
    padding: 1px 5px;
    border-radius: 3px 3px 0 0;
    white-space: nowrap;
    font-weight: 500;
}

.alarm-detail-info {
    background: #f8fafc;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.6rem 0.8rem;
}
.alarm-detail-row {
    display: flex;
    gap: 0.6rem;
    padding: 0.3rem 0;
    font-size: 0.85rem;
    border-bottom: 1px dashed #e2e8f0;
    line-height: 1.5;
}
.alarm-detail-row:last-child { border-bottom: none; }
.alarm-detail-row .k {
    flex: 0 0 72px;
    color: #64748b;
    font-weight: 500;
}
.alarm-detail-row .v {
    flex: 1 1 auto;
    color: #1e293b;
    word-break: break-word;
}

.alarm-box-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
    max-height: 220px;
    overflow-y: auto;
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 0.4rem;
    background: #fff;
}
.alarm-box-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 4px 6px;
    font-size: 0.82rem;
    border-radius: 4px;
    background: #f8fafc;
}
.alarm-box-item .box-idx { color: #94a3b8; flex: 0 0 28px; }
.alarm-box-item .box-class { flex: 1 1 auto; color: #1e293b; }
.alarm-box-item .box-conf { color: #059669; font-weight: 600; }

.alarm-detail-empty {
    color: #94a3b8;
    font-size: 0.85rem;
    padding: 1rem;
    text-align: center;
}

/* ============ 手机端 ============ */
@media (max-width: 768px) {
    .alarm-detail-body { flex-direction: column; gap: 0.8rem; }
    .alarm-detail-left,
    .alarm-detail-right { flex: 1 1 100%; width: 100%; }
    .alarm-box-list { max-height: 160px; }
    .detection-label { font-size: 10px; }
}
/* ---------- 图片可点击放大 ---------- */
.alarm-snapshot-wrap img {
    cursor: zoom-in;
}

/* 放大状态：脱离父容器，全屏居中显示 */
.alarm-snapshot-wrap.zoomed {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 2600;
    max-width: none;
    max-height: none;
    cursor: zoom-out;
    /* 关掉原 wrap 的 inline-block 限制 */
    display: inline-block;
}
.alarm-snapshot-wrap.zoomed img {
    max-width: 92vw;
    max-height: 92vh;
    width: auto;
    height: auto;
    border-radius: 6px;
    cursor: zoom-out;
    /* 用超大 box-shadow 当四周遮罩，不需要额外元素 */
    box-shadow:
        0 0 0 9999px rgba(0, 0, 0, 0.88),
        0 8px 40px rgba(0, 0, 0, 0.5);
}

/* 手机端稍留边距 */
@media (max-width: 768px) {
    .alarm-snapshot-wrap.zoomed img {
        max-width: 96vw;
        max-height: 86vh;
    }
}

/* ================================================================
   喊话控制
   ================================================================ */
.broadcast-controls {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.6rem;
    margin-top: 0.8rem;
    padding: 0.6rem;
    border-top: 1px solid #e2e8f0;
}
.broadcast-mode-select {
    display: flex;
    gap: 1rem;
    justify-content: center;
    flex-wrap: wrap;
    font-size: 0.85rem;
}
.broadcast-mode-option {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    cursor: pointer;
    color: #475569;
    user-select: none;
}
.broadcast-mode-option input {
    width: auto;
    margin: 0;
    accent-color: #475569;
}
.broadcast-mode-option:has(input:checked) {
    color: #475569;
    font-weight: 600;
}
#broadcastSrcStreamInput {
    width: 260px;
    max-width: 90%;
    padding: 0.35rem 0.6rem;
    font-size: 0.85rem;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    background: #f8fafc;
}
.broadcast-action-row {
    display: flex;
    gap: 12px;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
}
#broadcastBtn {
    min-width: 120px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    transition: all 0.2s;
}
.broadcast-status {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 0.85rem;
    font-weight: 500;
    color: #ef4444;
}
.broadcast-status:empty { display: none; }
.broadcast-status::before {
    content: "";
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: currentColor;
    animation: broadcast-pulse 1s ease-in-out infinite;
}
@keyframes broadcast-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.3; }
}
.broadcast-mic-level {
    display: inline-block;
    width: 120px;
    height: 10px;
    background: #e2e8f0;
    border-radius: 5px;
    overflow: hidden;
    vertical-align: middle;
}
.broadcast-mic-level.hidden { display: none; }
.mic-level-bar {
    display: block;
    width: 0%;
    height: 100%;
    background: #10b981;
    transition: width 0.1s linear, background 0.2s;
}
@media (max-width: 768px) {
    .broadcast-controls { padding: 0.4rem; gap: 0.4rem; }
    .broadcast-mode-select { font-size: 0.75rem; gap: 0.6rem; }
    #broadcastSrcStreamInput { width: 100%; max-width: 100%; }
    .broadcast-action-row { gap: 8px; }
    #broadcastBtn { min-width: 100px; font-size: 0.75rem; padding: 0.35rem 0.6rem; }
    .broadcast-status { font-size: 0.75rem; }
    .broadcast-mic-level { width: 80px; height: 8px; }
}
