/* =========================================================
   基础
========================================================= */

html,
body {
    width: 100%;
    height: 100%;

    margin: 0;
    padding: 0;

}


html.device-form-modal-open,
body.device-form-modal-open {
    overflow: hidden;
    overscroll-behavior: none;
}


body {
    font-family:
        -apple-system,
        BlinkMacSystemFont,
        "Segoe UI",
        "Microsoft YaHei",
        Arial,
        sans-serif;
}



/* =========================================================
   页面
========================================================= */

.device-manager-page {
    padding: 18px;
}



/* =========================================================
   顶部
========================================================= */

.device-manager-header-card {
    position: sticky;
    top: 0;
    z-index: 20;
    margin-bottom: 16px;
}


.device-manager-header {
    min-height: 52px;

    display: flex;

    align-items: center;

    justify-content: space-between;

    gap: 20px;
}


.device-manager-title-box {
    min-width: 0;
}


.device-manager-title {
    font-size: 20px;

    font-weight: 600;

    color: #222222;
}


.device-manager-desc {
    margin-top: 7px;

    font-size: 13px;

    color: #999999;
}


.device-manager-actions {
    display: flex;
    align-items: center;
    gap: 6px;
    flex: 0 0 auto;
}


.device-manager-actions .layui-form-select {
    width: 116px;
}

.device-manager-actions .layui-form-select .layui-select-title input {
    height: 32px;
    line-height: 32px;
}

.device-manager-icon-btn {
    width: 32px;
    min-width: 32px;
    height: 32px;
    line-height: 32px;
    padding: 0;
    text-align: center;
}

/* Layui 默认给相邻按钮加 10px 左外边距；工具栏统一交给 flex gap 控制。 */
.device-manager-actions .layui-btn + .layui-btn {
    margin-left: 0;
}

.device-manager-icon-btn .layui-icon {
    margin: 0;
    font-size: 17px;
}

.device-list-refresh-btn.loading {
    pointer-events: none;
    color: #16baaa;
}

.device-list-refresh-btn.loading i {
    display: inline-block;
    animation: device-refresh-rotate .5s linear infinite;
}

/* 自定义层沿用 Layui 提示框的紧凑白底布局，图标颜色可独立控制。 */
.layui-layer.device-list-custom-loading {
    min-width: 0 !important;
    width: 100% !important;
    height: 100% !important;
    border: 0 !important;
    background: transparent !important;
    box-shadow: none !important;
}

.layui-layer.device-list-custom-loading .layui-layer-content {
    width: 100% !important;
    height: 100% !important;
    padding: 0 !important;
    overflow: hidden !important;
    background: transparent !important;
}

.device-list-custom-loading-content {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    padding: 0;
    line-height: 32px;
}

.device-list-custom-loading-content .layui-icon {
    color: #16baaa;
    font-size: 32px;
}

/* =========================================================
   设备卡片
========================================================= */

.device-card {
    position: relative;
    min-width: 214px;
    margin-bottom: 16px;

    border-radius: 6px;
    border: 1px solid #dcdfe6;
    overflow: hidden;

    transition:
        transform .2s ease,
        box-shadow .2s ease;
}


/* 数据库 ID：仅作定位用，放在左上角且不抢名称与状态的视觉重点。 */
.device-card::before {
    content: attr(data-device-id);
    position: absolute;
    top: 0;
    left: 0;
    z-index: 1;
    padding: 0 7px;
    border-radius: 0 0 5px 0;
    background: rgba(22, 183, 119, .5);
    color: #fff;
    font: 700 11px/17px Arial, "Microsoft YaHei", sans-serif;

    pointer-events: none;
}

/* 删除操作绝对定位在右上角，与 ID 同高，不占据卡片正文空间。 */
.device-card-delete-top {
    position: absolute;
    top: 0;
    right: 0;
    z-index: 2;
    width: 17px;
    height: 17px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    border: 0;
    border-radius: 0 0 0 5px;
    background: #ff5722;
    color: #ffffff;
    line-height: 1;
    text-align: center;
    cursor: pointer;
}

.device-card-delete-top:hover {
    background: #e94416;
    color: #ffffff;
}

.device-card-delete-top .layui-icon {
    font-size: 11px;
}


.device-card:hover {
    transform: translateY(-2px);

    box-shadow:
        0 8px 24px rgba(0, 0, 0, .08);
}


.device-card .layui-card-body {
    padding: 18px;
}



/* =========================================================
   卡片顶部
========================================================= */

.device-card-header {
    display: flex;

    align-items: flex-start;

    justify-content: space-between;

    gap: 12px;

    padding-bottom: 16px;

    border-bottom: 1px solid #eeeeee;
}


.device-card-name-box {
    flex: 1;

    min-width: 0;
}


.device-card-name {
    overflow: hidden;

    text-overflow: ellipsis;

    white-space: nowrap;

    font-size: 17px;

    font-weight: 600;

    color: #333333;
}


.device-card-ip {
    margin-top: 6px;

    font-size: 13px;

    color: #999999;
}



/* =========================================================
   状态
========================================================= */

.device-status {
    display: inline-flex;

    align-items: center;

    gap: 6px;

    padding: 4px 8px;

    border-radius: 4px;

    font-size: 12px;

    white-space: nowrap;
}


.device-status-dot {
    width: 7px;

    height: 7px;

    flex: 0 0 7px;

    border-radius: 50%;
}



/* 在线 */

.device-status-online {
    color: #16baaa;

    background: #effbf9;
}


.device-status-online .device-status-dot {
    background: #16baaa;
}



/* 离线 */

.device-status-offline {
    color: #f56c6c;

    background: #fef0f0;
}


.device-status-offline .device-status-dot {
    background: #f56c6c;
}



/* 已禁用 */

.device-status-disabled {
    color: #909399;

    background: #f4f4f5;
}


.device-status-disabled .device-status-dot {
    background: #909399;
}


/* 未检测 */

.device-status-unchecked {
    color: #409eff;

    background: #ecf5ff;
}


.device-status-unchecked .device-status-dot {
    background: #409eff;
}

/* 异常 */

.device-status-error {
    color: #e6a23c;

    background: #fdf6ec;
}


.device-status-error .device-status-dot {
    background: #e6a23c;
}



/* =========================================================
   状态 + 刷新按钮
========================================================= */

.device-status-actions {
    display: flex;

    /* 刷新按钮与状态标签使用同一垂直中心线。 */
    align-items: center;

    gap: 8px;

    flex: 0 0 auto;

    flex-shrink: 0;
}


.device-status-meta {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 4px;
}


.device-refresh-meta {
    position: relative;
    width: 28px;
    height: 28px;
}


.device-uptime {
    position: absolute;
    top: 32px;
    right: 0;
    font-size: 12px;
    line-height: 16px;
    color: #999999;
    white-space: nowrap;
}



/* 刷新按钮 */

.device-refresh-btn {
    width: 28px;

    height: 28px;

    flex: 0 0 28px;

    display: flex;

    align-items: center;

    justify-content: center;

    padding: 0;

    border: 0;

    border-radius: 4px;

    background: transparent;

    color: #999999;

    cursor: pointer;

    transition:
        background .15s,
        color .15s;
}


.device-refresh-btn:hover {
    background: #f4fbfa;

    color: #16baaa;
}


.device-refresh-btn i {
    font-size: 17px;
}



/* 刷新中 */

.device-refresh-btn.loading {
    pointer-events: none;

    cursor: default;

    color: #16baaa;
}


.device-refresh-btn.loading i {
    animation:
        device-refresh-rotate
        .5s
        linear
        infinite;
}


@keyframes device-refresh-rotate {

    from {

        transform:
            rotate(0deg);

    }

    to {

        transform:
            rotate(360deg);

    }

}



/* =========================================================
   设备信息
========================================================= */

.device-card-info {
    padding: 14px 0;
}


.device-info-item {
    min-height: 32px;

    display: flex;

    align-items: center;

    justify-content: space-between;

    gap: 15px;
}


.device-info-label {
    flex: 0 0 auto;

    font-size: 13px;

    color: #333333;
}


.device-info-value {
    flex: 1;

    min-width: 0;

    overflow: hidden;

    text-align: right;

    text-overflow: ellipsis;

    white-space: nowrap;

    font-size: 13px;

    color: #333333;
}

/* Layui 备注浮层必须接收鼠标事件，允许进入浮层后拖选、复制完整文字。 */
.layui-layer-tips.device-remark-layer-tips,
.layui-layer-tips.device-remark-layer-tips * {
    pointer-events: auto !important;
    user-select: text !important;
    -webkit-user-select: text !important;
}

.layui-layer-tips.device-remark-layer-tips .layui-layer-content {
    cursor: text;
    max-width: 420px;
    white-space: normal;
    word-break: break-word;
}


.device-resource-row {
    display: grid;
    grid-template-columns: minmax(0, 7fr) minmax(0, 3fr);
    justify-content: initial;
    gap: 12px;
}


.device-resource-item {
    display: flex;
    min-width: 0;
    align-items: center;
    gap: 6px;
}


.device-resource-item:first-child {
    flex: 0 0 auto;
}


.device-resource-item:first-child .device-info-value {
    flex: 0 0 auto;
}


.device-resource-item:last-child {
    flex: 1 1 0;
}



/* =========================================================
   底部操作
========================================================= */

.device-card-actions {
    display: flex;

    justify-content: flex-end;

    gap: 10px;

    padding-top: 14px;

    border-top: 1px solid #eeeeee;
}

.device-card-remark {
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    color: #7a8799;
    font-size: 12px;
    line-height: 30px;
    text-align: left;
    text-overflow: ellipsis;
    white-space: nowrap;
}



/* =========================================================
   禁用设备
========================================================= */

.device-card-disabled {
    opacity: .65;
}


.device-filter-empty {
    padding: 48px 16px;
    text-align: center;
    color: #999999;
    background: #ffffff;
}

.device-list-loading,
.device-list-load-error {
    min-height: 180px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    color: #7a8799;
    text-align: center;
}

.device-list-loading .layui-icon {
    color: #16b7ad;
    font-size: 28px;
}

.device-list-load-error .layui-icon {
    color: #ff5722;
    font-size: 30px;
}

.device-list-load-error > div {
    color: #3b4656;
    font-size: 15px;
}

.device-list-load-error p {
    max-width: min(90%, 520px);
    margin: -3px 0 4px;
    color: #9aa4b2;
    word-break: break-word;
}



/* =========================================================
   空状态
========================================================= */

.device-empty {
    min-height: 420px;

    display: flex;

    flex-direction: column;

    align-items: center;

    justify-content: center;

    text-align: center;
}


.device-empty-icon {
    width: 76px;

    height: 76px;

    display: flex;

    align-items: center;

    justify-content: center;

    border-radius: 50%;

    background: #effbf9;

    color: #16baaa;
}


.device-empty-icon i {
    font-size: 36px;
}


.device-empty-title {
    margin-top: 20px;

    font-size: 18px;

    font-weight: 600;

    color: #333333;
}


.device-empty-desc {
    margin-top: 8px;

    margin-bottom: 22px;

    font-size: 14px;

    color: #999999;
}



/* =========================================================
   表单
========================================================= */

.device-form {
    padding: 14px 18px 4px;
}


.device-form .layui-form-item {
    margin-bottom: 7px;
}


.device-form .layui-form-label {
    width: 58px;
    padding: 7px 4px 7px 0;
}


.device-form .layui-input-block {
    margin-left: 62px;
}


/* 添加/编辑设备采用紧凑控件尺寸，不影响页面上的筛选表单。 */
.device-form .layui-input,
.device-form .layui-form-select .layui-input {
    height: 34px;
    line-height: 34px;
}


.device-form .layui-form-select .layui-edge {
    margin-top: -3px;
}


.device-form .layui-textarea {
    min-height: 68px;
    height: 68px;
    padding-top: 7px;
    padding-bottom: 7px;
    line-height: 18px;
    resize: vertical;
}


.device-password-input-wrap {
    position: relative;
}


.device-password-input-wrap .layui-input {
    padding-right: 42px;
}


.device-password-toggle {
    position: absolute;
    top: 50%;
    right: 1px;
    width: 38px;
    height: calc(100% - 2px);
    padding: 0;
    border: 0;
    transform: translateY(-50%);
    background: transparent;
    color: #909399;
    cursor: pointer;
}


.device-password-toggle:hover {
    color: #16baaa;
}


.device-password-toggle:active {
    transform: translateY(-50%) scale(.9);
    color: #0fa898;
}


.device-form-layer .layui-layer-content {
    /*
     * 弹窗由 Index 顶层承载：高度超过可视区时，仅表单内容滚动，
     * 标题和底部按钮始终留在窗口内。
     */
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto !important;
    overscroll-behavior: contain;
    touch-action: pan-y;
}


.device-form-layer.layui-layer {
    display: flex;
    width: min(460px, calc(100vw - 24px)) !important;
    height: auto !important;
    max-height: calc(100vh - 24px);
    flex-direction: column;
}


.device-form-layer .layui-layer-title,
.device-form-layer .layui-layer-btn {
    flex: 0 0 auto;
}


/* 弹窗按钮顺序为“取消、保存”：取消保持次要样式，保存使用主色。 */
.device-form-layer .layui-layer-btn0 {
    border-color: #dcdfe6;

    background: #ffffff;

    color: #606266;
}


.device-form-layer .layui-layer-btn1 {
    border-color: #16baaa;

    background: #16baaa;

    color: #ffffff;
}


.device-form-layer .layui-layer-btn1:hover {
    border-color: #0fa898;

    background: #0fa898;
}



/* =========================================================
   移动端
========================================================= */


@media screen and (max-width: 520px) {
    #deviceList > .layui-col-xs6 {
        width: 100%;
    }
}


@media screen and (max-width: 520px) {

    .device-manager-page {
        padding: 12px;
    }


    .device-manager-header {
        flex-direction: column;

        align-items: stretch;
    }


    .device-manager-header .layui-btn {
        width: 100%;
    }


    .device-manager-actions {
        width: 100%;
    }


    .device-manager-actions .layui-form-select {
        flex: 0 0 116px;
        width: 116px;
    }


    .device-manager-header .device-manager-actions .layui-btn {
        width: auto;
        min-width: 0;
        flex: 1 1 auto;
        white-space: nowrap;
    }

    .device-manager-header .device-manager-actions .device-manager-icon-btn {
        width: 32px;
        min-width: 32px;
        flex: 0 0 32px;
    }


    .device-form {
        padding: 12px 14px 2px;
    }


    .device-form-layer {
        border-radius: 8px;

        overflow: hidden;
    }


    .device-form-layer .layui-layer-title {
        padding: 0 16px;
    }


    .device-form-layer .layui-layer-content {
        overflow-y: auto !important;

        -webkit-overflow-scrolling: touch;
    }


    .device-form-layer .layui-layer-btn {
        padding: 10px 12px;

        background: #ffffff;

        border-top: 1px solid #eeeeee;

        text-align: center;
    }


    .device-form .layui-form-item {
        display: flex;
        align-items: center;
        margin-bottom: 7px;
    }


    .device-form .layui-form-label {
        width: 58px;
        flex: 0 0 58px;
        padding: 0 2px 0 0;
        line-height: 20px;
        text-align: left;
        white-space: nowrap;
    }


    .device-form .layui-input-block {
        margin-left: 0;
        min-width: 0;
        flex: 1 1 auto;
    }


    .device-form .layui-form-text {
        align-items: flex-start;
    }


    .device-form .layui-form-text .layui-form-label {
        padding-top: 8px;
    }

}
