/* ==================== SimpleCloud 管理后台样式（设计体系参考 pet-tracker-admin-lite，无外部依赖，内网可用） ==================== */

:root {
    /* 设计 tokens：参考 pet-tracker-admin-lite（靛蓝主色 + slate 侧边栏） */
    --c-bg: #F5F7FA;            /* 工作区背景 */
    --c-surface: #FFFFFF;       /* 面板表面 */
    --c-border: #E5E7EB;        /* 分隔线 */
    --c-border-2: #EEF1F4;      /* 表格行线 */
    --c-text: #1F2937;          /* 主文字 */
    --c-text-2: #6B7280;        /* 次文字 */
    --c-text-3: #94A3B8;        /* 弱文字 */
    --c-primary: #4F6BF6;       /* 主色靛蓝 */
    --c-primary-d: #3D57D9;     /* 主色按下 */
    --c-primary-l: #EEF1FE;     /* 主色浅底 */
    --c-success: #10B981;
    --c-ok-bg: #E7F8F1;
    --c-warning: #F59E0B;
    --c-warn-bg: #FEF5E5;
    --c-critical: #EF4444;
    --c-crit-bg: #FDEEEE;
    --c-info: #3B82F6;
    --c-info-bg: #E8F1FE;
    --nav-w: 236px;             /* 侧边栏宽度 */
    --radius: 12px;
    --shadow: 0 1px 3px rgba(0, 0, 0, .08);
    --shadow-lg: 0 10px 30px rgba(15, 23, 42, .12);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
    margin: 0;
    font: 13px/1.55 "Segoe UI", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
    color: var(--c-text);
    background: var(--c-bg);
}

::selection { background: #DCE3FC; }

h1 { font-size: 18px; font-weight: 650; margin: 0 0 16px; letter-spacing: .2px; }
h3 { margin: 0; font-size: 14px; }

a { color: var(--c-primary); text-decoration: none; }

/* ==================== 布局骨架（固定视口：侧边栏/顶栏钉死，仅内容区滚动） ==================== */

.admin-shell { display: flex; height: 100vh; overflow: hidden; }

.admin-body { flex: 1; min-width: 0; display: flex; flex-direction: column; overflow: hidden; }

/* ==================== 顶栏（页面标题联动路由，同 pet-tracker） ==================== */

.topbar {
    height: 58px;
    flex-shrink: 0;
    background: var(--c-surface);
    border-bottom: 1px solid var(--c-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 28px;
}

.topbar h2 { font-size: 17px; font-weight: 700; margin: 0; }

.topbar-right { display: flex; align-items: center; gap: 12px; }

.topbar-date { font-size: 12.5px; color: var(--c-text-2); }

/* 顶栏通知提示音开关（偏好存 localStorage；关闭态斜杠图标） */
.sound-toggle {
    width: 30px;
    height: 30px;
    border: 1px solid var(--c-border);
    border-radius: 8px;
    background: var(--c-surface);
    color: var(--c-text-2);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: color .15s, border-color .15s, background .15s;
}

.sound-toggle:hover { color: var(--c-primary); border-color: var(--c-primary); }

.sound-toggle svg { width: 16px; height: 16px; }

.sound-toggle.off { color: var(--c-text-3); }
.sound-toggle .snd-off { display: none; }
.sound-toggle.off .snd-on { display: none; }
.sound-toggle.off .snd-off { display: inline; }

.admin-main { flex: 1; min-width: 0; overflow-y: auto; padding: 22px 28px 48px; }

/* ==================== 侧边导航（slate #1E293B，激活项主色浅底 + 左侧竖条） ==================== */

.nav-menu {
    width: var(--nav-w);
    flex-shrink: 0;
    background: #1E293B;
    color: #94A3B8;
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
}

.nav-menu::-webkit-scrollbar { width: 6px; }
.nav-menu::-webkit-scrollbar-thumb { background: #334155; border-radius: 3px; }

.nav-brand {
    padding: 18px 18px 14px;
    font-size: 15px;
    font-weight: 600;
    color: #fff;
    letter-spacing: .2px;
    border-bottom: 1px solid #2A3850;
}

.nav-role { padding: 10px 18px 14px; font-size: 10.5px; color: #64748B; letter-spacing: 1px; border-bottom: 1px solid #2A3850; }

/* 分组小标题：功能分区隔断（左缩进对齐菜单文字：nav-item 12px 边距 + nav-link 12px 内距） */
.nav-group-label {
    padding: 14px 24px 4px;
    font-size: 10.5px;
    font-weight: 600;
    letter-spacing: 1.2px;
    color: #64748B;
}

/* 菜单项：图标 + 文字 */
.nav-link-main { display: inline-flex; align-items: center; gap: 10px; }

.nav-link svg { width: 17px; height: 17px; flex-shrink: 0; opacity: .85; }

.nav-list { list-style: none; margin: 8px 0; padding: 0; flex: 1; overflow-y: auto; }

.nav-item { margin: 2px 12px; }

.nav-link {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 7.5px 12px;
    border-radius: 8px;
    color: #94A3B8;
    position: relative;
    transition: background .12s, color .12s;
}

.nav-link:hover { background: #2A3850; color: #D7E1EC; }

.nav-link.active { background: rgba(79, 107, 246, .18); color: #A5B4FC; }

/* 激活项左侧 3px 主色竖条（原型同款） */
.nav-link.active::before {
    content: "";
    position: absolute;
    left: -12px;
    top: 6px;
    bottom: 6px;
    width: 3px;
    background: var(--c-primary);
    border-radius: 0 3px 3px 0;
}

.nav-badge {
    min-width: 18px;
    padding: 0 5px;
    border-radius: 9px;
    font-size: 10.5px;
    font-weight: 600;
    text-align: center;
    color: #fff;
    line-height: 18px;
}

.badge-feedback { background: #0D9488; }

/* 侧边栏底部用户卡：头像 + 姓名/角色 + 登出（同 pet-tracker sidebar-footer） */
.nav-footer {
    padding: 14px 16px;
    border-top: 1px solid #2A3850;
    display: flex;
    align-items: center;
    gap: 10px;
}

.nav-avatar {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: var(--c-primary);
    color: #fff;
    font-size: 14px;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.nav-userinfo { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.3; }

.nav-userinfo .name { color: #fff; font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.nav-userinfo .role { color: #64748B; font-size: 11px; }

.nav-logout {
    border: none;
    background: none;
    color: #64748B;
    cursor: pointer;
    padding: 6px;
    border-radius: 7px;
    display: flex;
    transition: background .12s, color .12s;
}

.nav-logout:hover { background: #2A3850; color: #D7E1EC; }

/* ==================== 卡片与工具条 ==================== */

.card {
    background: var(--c-surface);
    border: 1px solid var(--c-border);
    border-radius: var(--radius);
    padding: 16px 18px;
    margin-bottom: 16px;
}

.card-title {
    font-size: 12px;
    font-weight: 650;
    letter-spacing: 1.2px;
    text-transform: uppercase;
    color: var(--c-text-2);
    margin-bottom: 12px;
}

/* 卡片标题旁的口径说明（不继承标题的大写/字距） */
.card-hint {
    margin-left: 8px;
    font-size: 11px;
    font-weight: 400;
    letter-spacing: 0;
    text-transform: none;
    color: var(--c-text-3);
}

/* 仪表盘双栏：左栏 活动告警 + 事件流，右栏 今日告警概览 + 设备在线率（同原型 1.4fr / 1fr） */
.dash-grid {
    display: grid;
    grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr);
    gap: 16px;
}

.dash-col { min-width: 0; }

/* 栏内最后一张卡片不再叠加下外边距（间距交给 grid gap） */
.dash-col > .card:last-child { margin-bottom: 0; }

@media (max-width: 1100px) {
    .dash-grid { grid-template-columns: 1fr; }
}

/* 在线率进度条：底色轨道 + 语义填充（正常/预警/告警） */
.rate-cell { display: flex; align-items: center; gap: 8px; }

.rate-bar {
    height: 6px;
    width: 96px;
    border-radius: 3px;
    background: #EFF2F5;
    overflow: hidden;
    flex-shrink: 0;
}

.rate-fill { height: 100%; border-radius: 3px; transition: width .3s; }
.rate-ok { background: var(--c-success); }
.rate-warn { background: var(--c-warning); }
.rate-bad { background: var(--c-critical); }

.rate-text { font-size: 11.5px; color: var(--c-text-2); font-variant-numeric: tabular-nums; }

.toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 10px;
    margin-bottom: 14px;
}

.toolbar .grow { flex: 1; }

.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 14px;
    margin-bottom: 16px;
}

/* 统计卡：语义浅底图标 + 数值/副行（同原型 4 KPI 布局） */
.stat-card {
    background: var(--c-surface);
    border: 1px solid var(--c-border);
    border-radius: var(--radius);
    padding: 16px 18px;
    display: flex;
    align-items: center;
    gap: 14px;
    transition: box-shadow .15s;
}

.stat-card:hover { box-shadow: var(--shadow-lg); }

.sc-icon {
    width: 44px;
    height: 44px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    color: #fff; /* 渐变底配白色图标（语义变体见下方 sc-* 类） */
}

/* 统计卡图标底：语义渐变色块（KPI 卡视觉升级） */
.sc-primary { background: linear-gradient(135deg, #4F6BF6, #3D57D9); }
.sc-info    { background: linear-gradient(135deg, #3B82F6, #2563EB); }
.sc-ok      { background: linear-gradient(135deg, #10B981, #059669); }
.sc-crit    { background: linear-gradient(135deg, #EF4444, #DC2626); }

.stat-card .stat-value { font-size: 24px; font-weight: 700; line-height: 1.2; font-variant-numeric: tabular-nums; }

.stat-card .stat-label { color: var(--c-text-2); font-size: 12px; margin-top: 2px; }

/* KPI 副行（在线/离线、critical/warning/info 分布） */
.stat-sub { font-size: 12px; color: var(--c-text-3); margin-top: 3px; font-variant-numeric: tabular-nums; }

.stat-warn .stat-value { color: var(--c-warning); }
.stat-crit .stat-value { color: var(--c-critical); }

/* KPI 数值变化：@key 重挂载时播放一次弹入（不闪烁、不常驻） */
.stat-value.stat-bump { animation: stat-bump .42s cubic-bezier(.2, .8, .3, 1.1); }

@keyframes stat-bump {
    0% { opacity: .45; transform: translateY(3px) scale(.96); }
    100% { opacity: 1; transform: none; }
}

/* 活动告警 > 0：临界卡低频呼吸描边（避免持续闪动干扰） */
.stat-card.stat-crit-live { animation: crit-breathe 2.4s ease-in-out infinite; }

@keyframes crit-breathe {
    0%, 100% { box-shadow: 0 0 0 0 rgba(220, 38, 38, 0); }
    50% { box-shadow: 0 0 0 4px rgba(220, 38, 38, .14); }
}

/* ==================== 表格 ==================== */

.table-wrap { overflow-x: auto; }

table.list {
    width: 100%;
    border-collapse: collapse;
    background: var(--c-surface);
}

table.list th, table.list td {
    padding: 8px 10px;
    border-bottom: 1px solid var(--c-border-2);
    text-align: left;
    white-space: nowrap;
    vertical-align: middle;
}

table.list th {
    background: #FAFBFC;
    color: var(--c-text-2);
    font-weight: 600;
    font-size: 11px;
    letter-spacing: .6px;
    border-bottom: 1px solid var(--c-border);
}

table.list td { font-size: 12.5px; }

table.list tr:hover td { background: #F7FAFB; }

/* 活动告警表：左栏宽度有限，按内容压缩列宽（设备号换行、告警内容允许折行），避免横向滚动 */
.alarm-table th, .alarm-table td { padding: 6px 7px; font-size: 12px; }
.alarm-table .dev-code { display: block; font-size: 10.5px; line-height: 1.3; color: var(--c-text-3); }
.alarm-table .alarm-title { white-space: normal; word-break: break-word; min-width: 140px; }
.alarm-table .tag { padding: 1px 7px; font-size: 10.5px; }

/* 操作列：td 必须保持 table-cell 语义——display:flex 会把 td 踢出表格布局（浏览器只能套匿名
   单元格），空单元格会自己占一行并带上 border-bottom，看起来就是"空白的第二行"。
   改为行内排列 + 相邻外边距实现按钮并列（.btn 本身是 inline-flex）。 */
td.acts { white-space: nowrap; }
td.acts > * + * { margin-left: 6px; }

/* ==================== 按钮（成行并列、统一样式） ==================== */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    height: 32px;
    padding: 0 14px;
    border-radius: 7px;
    border: 1px solid transparent;
    font-size: 12.5px;
    font-weight: 500;
    cursor: pointer;
    transition: filter .12s, background .12s, border-color .12s;
}

.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; }

.btn-primary { background: var(--c-primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--c-primary-d); }

.btn-ghost { background: #fff; border-color: #C9D4DC; color: var(--c-text-2); }
.btn-ghost:hover:not(:disabled) { border-color: #9FB0BD; color: var(--c-text); }

.btn-danger { background: #fff; border-color: #E4B7B2; color: var(--c-critical); }
.btn-danger:hover:not(:disabled) { background: var(--c-crit-bg); }

.btn-sm { height: 26px; padding: 0 10px; font-size: 11.5px; border-radius: 6px; }

.btn-block { width: 100%; }

.btn-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

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

.field { display: flex; flex-direction: column; gap: 4px; }

.field > span { font-size: 12px; color: var(--c-text-2); }

input[type="text"], input[type="password"], input[type="number"], input[type="datetime-local"],
select, textarea {
    padding: 7px 10px;
    border: 1px solid var(--c-border);
    border-radius: 7px;
    font: inherit;
    color: var(--c-text);
    background: #fff;
    min-width: 0;
}

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--c-primary);
    box-shadow: 0 0 0 3px rgba(79, 107, 246, .14);
}

textarea { resize: vertical; min-height: 64px; }

.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 12px;
}

.form-error { color: var(--c-critical); font-size: 13px; margin: 8px 0; }

.form-ok { color: var(--c-success); font-size: 13px; margin: 8px 0; }

/* ==================== 状态徽标（浅底彩字，同原型） ==================== */

.tag {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 20px;
    font-size: 11.5px;
    line-height: 17px;
    background: #EDF1F4;
    color: var(--c-text-2);
}

.tag-green { background: var(--c-ok-bg); color: var(--c-success); }
.tag-red { background: var(--c-crit-bg); color: var(--c-critical); }
.tag-orange { background: var(--c-warn-bg); color: var(--c-warning); }
.tag-blue { background: var(--c-info-bg); color: var(--c-info); }
.tag-gray { background: #EDF1F4; color: var(--c-text-2); }
.tag-teal { background: var(--c-primary-l); color: var(--c-primary); }

/* ==================== 页签 ==================== */

.tabs { display: flex; gap: 2px; border-bottom: 2px solid var(--c-border); margin-bottom: 16px; }

.tab-btn {
    padding: 8px 18px;
    border: none;
    background: none;
    font: inherit;
    color: var(--c-text-2);
    cursor: pointer;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
}

.tab-btn.active { color: var(--c-primary); border-bottom-color: var(--c-primary); font-weight: 600; }

/* ==================== 模态框 ==================== */

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(13, 21, 36, .45);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
}

.modal-box {
    background: #fff;
    border-radius: 9px;
    width: min(640px, calc(100vw - 48px));
    max-height: calc(100vh - 96px);
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-lg);
}

.modal-box.wide {
    width: min(1080px, calc(100vw - 48px));
}

.modal-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 18px;
    border-bottom: 1px solid var(--c-border);
}

.modal-close {
    border: none;
    background: none;
    font-size: 18px;
    cursor: pointer;
    color: var(--c-text-2);
}

.modal-body { padding: 16px 18px; overflow-y: auto; }

/* ==================== 快照分组行（设备列表「实时快照」弹窗） ==================== */

.list .snap-group td {
    background: #f4f6fa;
    font-size: 11.5px;
    font-weight: 600;
    color: #64748b;
}

.list .snap-subgroup td {
    background: transparent;
    font-size: 11.5px;
    font-weight: 500;
    color: #8a94a6;
    padding-left: 26px;
}

/* ==================== Toast（右上角浮层，05 分册 §1.5） ==================== */

.toast-host {
    position: fixed;
    top: 14px;
    right: 14px;
    z-index: 200;
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: 320px;
}

.toast {
    position: relative;
    overflow: hidden;
    border-radius: 9px;
    padding: 10px 14px;
    color: #fff;
    box-shadow: 0 4px 16px rgba(0, 0, 0, .18);
    animation: toast-in .2s ease;
}

@keyframes toast-in { from { transform: translateX(30px); opacity: 0; } }

/* 退场：Closing 标记后 220ms 内淡出，再由 Blazor 移除 */
.toast-closing { animation: toast-out .22s ease forwards; }

@keyframes toast-out { to { transform: translateX(30px); opacity: 0; } }

/* 非 critical：5s 倒计时进度条（与自动关闭计时一致） */
.toast-progress {
    position: absolute;
    left: 0;
    bottom: 0;
    height: 3px;
    width: 100%;
    background: rgba(255, 255, 255, .55);
    transform-origin: left;
    animation: toast-countdown 5s linear forwards;
}

@keyframes toast-countdown { to { transform: scaleX(0); } }

.toast-warning { background: var(--c-warning); }
.toast-critical { background: var(--c-critical); }
.toast-info { background: #33507a; }

.toast-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }

.toast-title { font-weight: 600; }

.toast-close { border: none; background: none; color: #fff; font-size: 16px; cursor: pointer; }

.toast-content { font-size: 13px; opacity: .92; margin-top: 2px; word-break: break-all; }

/* 减少动态：系统开启 prefers-reduced-motion 时关闭所有动画 */
@media (prefers-reduced-motion: reduce) {
    .stat-value.stat-bump,
    .stat-card.stat-crit-live,
    .toast,
    .toast-closing,
    .toast-progress { animation: none !important; }
}

/* ==================== 登录页（侧栏同族深色渐变 + 靛蓝 logo） ==================== */

.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #1E293B 0%, #334155 100%);
}

.login-box {
    width: 380px;
    background: #fff;
    border-radius: 14px;
    padding: 36px 32px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, .35);
}

.login-logo {
    width: 56px;
    height: 56px;
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #4F6BF6, #3D57D9);
    margin: 0 auto 14px;
    color: #fff;
}

.login-box h2 { text-align: center; margin: 0 0 6px; font-size: 20px; }

.login-sub { text-align: center; color: var(--c-text-2); font-size: 13px; margin-bottom: 24px; }

.login-box label { display: block; margin-bottom: 14px; font-size: 13px; color: var(--c-text-2); }

.login-box input { width: 100%; margin-top: 4px; }

.login-box button {
    width: 100%;
    padding: 10px;
    margin-top: 6px;
    background: var(--c-primary);
    color: #fff;
    border: none;
    border-radius: 7px;
    font-size: 15px;
    cursor: pointer;
}

.login-box button:hover { background: var(--c-primary-d); }

.login-error {
    background: var(--c-crit-bg);
    color: var(--c-critical);
    border-radius: 6px;
    padding: 8px 12px;
    margin-bottom: 14px;
    font-size: 13px;
}

/* ---- 登录页密码可见切换按钮（覆盖 .login-box button 的默认样式） ---- */
.pwd-wrap { position: relative; margin-top: 4px; }
.pwd-wrap input { margin-top: 0; }

.login-box .pwd-toggle {
    position: absolute;
    top: 50%;
    right: 8px;
    transform: translateY(-50%);
    display: flex;
    width: auto;
    margin: 0;
    padding: 4px;
    background: none;
    border: none;
    color: var(--c-text-2);
    cursor: pointer;
}

.login-box .pwd-toggle:hover { background: none; color: var(--c-text); }

/* ---- 记住用户名勾选行（横向排列，覆盖 label 的块级默认） ---- */
.login-box .remember-row {
    display: flex;
    align-items: center;
    gap: 6px;
    margin: -4px 0 6px;
    cursor: pointer;
    user-select: none;
}

.login-box .remember-row input { width: auto; margin: 0; accent-color: var(--c-primary); }

/* ==================== 分页 ==================== */

.pager { display: flex; align-items: center; gap: 8px; margin-top: 12px; color: var(--c-text-2); }

.pager button { padding: 4px 12px; }

/* ==================== 事件流 / 其他 ==================== */

.event-stream { list-style: none; margin: 0; padding: 0; max-height: 420px; overflow-y: auto; }

.event-stream li {
    padding: 8px 10px;
    border-bottom: 1px dashed var(--c-border-2);
    display: flex;
    justify-content: space-between;
    gap: 10px;
    font-size: 13px;
}

.event-time { color: var(--c-text-2); font-size: 12px; flex-shrink: 0; }

.mono { font-family: "Cascadia Code", Consolas, monospace; font-size: 12px; }

.muted { color: var(--c-text-2); }

.hint { font-size: 12px; color: var(--c-text-3); margin: 6px 0; }

.split-2 { display: grid; grid-template-columns: 340px 1fr; gap: 16px; align-items: start; }

@media (max-width: 900px) { .split-2 { grid-template-columns: 1fr; } }

.model-list-item {
    padding: 9px 12px;
    border-radius: 7px;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    gap: 6px;
}

.model-list-item:hover { background: #F7FAFB; }

.model-list-item.selected { background: var(--c-primary-l); color: var(--c-primary); font-weight: 600; }
