/* ===== MQTT 数据采集与监控平台 · 深色工业风主题 ===== */

:root {
    --bg: #0b0f17;
    --panel: #10161f;
    --panel-2: #0d131c;
    --border: #1e2a3a;
    --border-strong: #2a3a52;
    --text: #dbe4ef;
    --muted: #7f8ea3;
    --accent: #22d3ee;
    --accent-dim: rgba(34, 211, 238, 0.14);
    --accent-glow: rgba(34, 211, 238, 0.35);
    --green: #34d399;
    --amber: #fbbf24;
    --red: #f87171;
    --mono: "JetBrains Mono", "Cascadia Code", Consolas, "Courier New", monospace;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
    margin: 0;
    font-family: "Segoe UI", "Microsoft YaHei", "PingFang SC", sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
    line-height: 1.5;
}

/* 蓝图网格纹理 */
body::before {
    content: "";
    position: fixed;
    inset: 0;
    pointer-events: none;
    background-image:
        linear-gradient(rgba(120, 160, 220, 0.035) 1px, transparent 1px),
        linear-gradient(90deg, rgba(120, 160, 220, 0.035) 1px, transparent 1px);
    background-size: 32px 32px;
    z-index: 0;
}

/* ===== 布局骨架：左侧边栏 ===== */
.shell {
    position: relative;
    z-index: 1;
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: 232px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    background: rgba(8, 12, 19, 0.94);
    backdrop-filter: blur(8px);
    border-right: 1px solid var(--border);
    position: sticky;
    top: 0;
    height: 100vh;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 18px 20px;
    border-bottom: 1px solid var(--border);
}

.brand-mark {
    width: 14px;
    height: 14px;
    background: var(--accent);
    border-radius: 3px;
    box-shadow: 0 0 12px var(--accent-glow);
    flex-shrink: 0;
}

.brand-title { font-weight: 600; font-size: 14px; letter-spacing: 0.5px; line-height: 1.3; }
.brand-sub { color: var(--muted); font-size: 10px; letter-spacing: 2.5px; }

.side-nav { display: flex; flex-direction: column; gap: 4px; padding: 14px 12px; flex: 1; }

.side-link {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 10px 14px;
    border-radius: 8px;
    border: 1px solid transparent;
    border-left: 3px solid transparent;
    color: var(--muted);
    text-decoration: none;
    font-size: 14px;
    transition: all .15s;
}

.side-link svg { width: 17px; height: 17px; flex-shrink: 0; }

.side-link:hover { color: var(--text); background: rgba(255, 255, 255, 0.04); }

.side-link.active {
    color: var(--accent);
    background: var(--accent-dim);
    border-left-color: var(--accent);
    box-shadow: inset 0 0 18px rgba(34, 211, 238, 0.06);
}

.sidebar-footer {
    padding: 14px;
    border-top: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.user-chip { display: flex; align-items: center; gap: 10px; }

.avatar {
    width: 34px;
    height: 34px;
    border-radius: 8px;
    background: linear-gradient(135deg, #164e63, #0e7490);
    border: 1px solid rgba(34, 211, 238, 0.4);
    color: var(--accent);
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
}

.user-name { font-size: 13px; color: var(--text); }
.user-role { font-size: 10px; letter-spacing: 1.5px; color: var(--muted); }

.content {
    flex: 1;
    min-width: 0;
    max-width: 1460px;
    margin: 0 auto;
    padding: 26px 28px 40px;
}

/* ===== 标题 ===== */
h2 {
    margin: 0 0 18px;
    font-size: 19px;
    letter-spacing: 1px;
    display: flex;
    align-items: center;
    gap: 10px;
}

h2::before {
    content: "";
    width: 4px;
    height: 18px;
    background: var(--accent);
    border-radius: 2px;
    box-shadow: 0 0 8px var(--accent-glow);
}

h3 { font-size: 15px; letter-spacing: 0.5px; }

/* ===== KPI 磁贴 ===== */
.kpi-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 14px;
    margin-bottom: 18px;
}

.kpi {
    background: linear-gradient(180deg, var(--panel) 0%, var(--panel-2) 100%);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 14px 18px;
    position: relative;
    overflow: hidden;
}

.kpi::after {
    content: "";
    position: absolute;
    top: 0; left: 0;
    width: 100%;
    height: 2px;
    background: linear-gradient(90deg, var(--border-strong), transparent);
}

.kpi-green::after { background: linear-gradient(90deg, var(--green), transparent); }

.kpi-label { color: var(--muted); font-size: 12px; letter-spacing: 1.5px; text-transform: uppercase; }

.kpi-value {
    font-family: var(--mono);
    font-size: 28px;
    font-weight: 600;
    margin-top: 4px;
    color: var(--text);
}

.kpi-green .kpi-value { color: var(--green); text-shadow: 0 0 18px rgba(52, 211, 153, 0.35); }

.kpi-small { font-size: 22px; }

/* ===== 面板 ===== */
.panel {
    background: linear-gradient(180deg, var(--panel) 0%, var(--panel-2) 100%);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 18px 20px;
    margin-bottom: 20px;
    box-shadow: 0 8px 28px rgba(0, 0, 0, 0.3);
}

.filter-panel { padding: 14px 18px; }

.filters { display: flex; flex-direction: column; gap: 12px; margin-bottom: 16px; }

.filter-group { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; }

.filter-label { color: var(--muted); font-size: 13px; min-width: 42px; }

/* ===== 胶囊选项 ===== */
.checkbox-label {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    padding: 4px 12px;
    border: 1px solid var(--border);
    border-radius: 999px;
    font-size: 13px;
    color: var(--muted);
    transition: all .15s;
    user-select: none;
}

.checkbox-label:hover { border-color: var(--border-strong); color: var(--text); }

.checkbox-label input { accent-color: var(--accent); width: 14px; height: 14px; margin: 0; cursor: pointer; }

.checkbox-label:has(input:checked) {
    color: var(--accent);
    border-color: rgba(34, 211, 238, 0.5);
    background: var(--accent-dim);
    box-shadow: inset 0 0 12px rgba(34, 211, 238, 0.08);
}

/* ===== 表单控件 ===== */
.form-group { margin-bottom: 14px; max-width: 520px; }

.form-group label { display: block; margin-bottom: 5px; color: var(--muted); font-size: 13px; }

.form-control {
    width: 100%;
    padding: 8px 12px;
    background: #0a1018;
    border: 1px solid var(--border-strong);
    border-radius: 6px;
    color: var(--text);
    font-size: 14px;
    outline: none;
    transition: border-color .15s, box-shadow .15s;
}

.form-control:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(34, 211, 238, 0.15); }

select.form-control {
    appearance: none;
    background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%),
                      linear-gradient(135deg, var(--muted) 50%, transparent 50%);
    background-position: calc(100% - 16px) 55%, calc(100% - 11px) 55%;
    background-size: 5px 5px;
    background-repeat: no-repeat;
    padding-right: 30px;
}

input[type="datetime-local"].form-control { color-scheme: dark; }

.select-sm { width: auto; min-width: 150px; }

textarea.form-control { font-family: var(--mono); font-size: 13px; }

/* ===== 按钮 ===== */
.btn {
    display: inline-block;
    padding: 8px 18px;
    border: 1px solid var(--border-strong);
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.03);
    color: var(--text);
    cursor: pointer;
    font-size: 14px;
    text-decoration: none;
    transition: all .15s;
}

.btn:hover { border-color: var(--accent); color: var(--accent); }

.btn-primary {
    background: linear-gradient(180deg, #2ad8f0 0%, #14b8d4 100%);
    border-color: transparent;
    color: #06222c;
    font-weight: 600;
    box-shadow: 0 0 16px rgba(34, 211, 238, 0.25);
}

.btn-primary:hover {
    background: linear-gradient(180deg, #43e0f5 0%, #1cc4e0 100%);
    color: #06222c;
    box-shadow: 0 0 22px rgba(34, 211, 238, 0.45);
}

.btn-primary:disabled { opacity: 0.45; cursor: not-allowed; box-shadow: none; }

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

.btn-danger { color: var(--red); border-color: rgba(248, 113, 113, 0.4); }

.btn-danger:hover { border-color: var(--red); color: var(--red); background: rgba(248, 113, 113, 0.08); }

.btn-block { width: 100%; }

.btn-link { background: none; border: none; color: var(--accent); cursor: pointer; padding: 0; font-size: 13px; }

.btn-link:hover { text-decoration: underline; }

/* ===== 设备图表卡片 ===== */
.device-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(620px, 1fr));
    gap: 18px;
}

.device-card { margin-bottom: 0; padding: 16px 18px 12px; }

.device-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 10px;
}

.device-title { display: flex; align-items: center; gap: 10px; }

.device-name { font-size: 15px; font-weight: 600; letter-spacing: 0.5px; }

.device-code {
    font-family: var(--mono);
    font-size: 11px;
    color: var(--muted);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 1px 7px;
}

.stat-chips { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }

.stat-chip {
    display: flex;
    align-items: baseline;
    gap: 7px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 4px 10px;
}

.stat-name { font-size: 11px; color: var(--muted); letter-spacing: 1px; }

.stat-value { font-family: var(--mono); font-size: 15px; font-weight: 600; color: var(--accent); }

.chart-empty {
    height: 200px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--muted);
    border: 1px dashed var(--border-strong);
    border-radius: 8px;
}

/* ===== 表格 ===== */
.table { width: 100%; border-collapse: collapse; }

.table th, .table td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--border); }

.table th {
    color: var(--muted);
    font-weight: 500;
    font-size: 12px;
    letter-spacing: 1px;
    text-transform: uppercase;
    background: rgba(255, 255, 255, 0.02);
}

.table tbody tr { transition: background .12s; }

.table tbody tr:hover { background: rgba(34, 211, 238, 0.05); }

.table td code { font-family: var(--mono); font-size: 12px; color: var(--muted); }

.badge {
    display: inline-block;
    background: rgba(251, 191, 36, 0.12);
    color: var(--amber);
    border: 1px solid rgba(251, 191, 36, 0.35);
    border-radius: 4px;
    padding: 1px 7px;
    font-size: 12px;
    margin-left: 6px;
}

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

.dot-online {
    background: var(--green);
    box-shadow: 0 0 8px rgba(52, 211, 153, 0.8);
    animation: pulse 2s infinite;
}

.dot-offline { background: #4b5a6e; }

@keyframes pulse {
    0%, 100% { box-shadow: 0 0 4px rgba(52, 211, 153, 0.6); }
    50% { box-shadow: 0 0 10px rgba(52, 211, 153, 0.95); }
}

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

.alert { padding: 10px 14px; border-radius: 6px; margin-bottom: 12px; font-size: 13px; }

.alert-danger {
    background: rgba(248, 113, 113, 0.1);
    color: var(--red);
    border: 1px solid rgba(248, 113, 113, 0.35);
}

.alert-warning {
    background: rgba(251, 191, 36, 0.1);
    color: var(--amber);
    border: 1px solid rgba(251, 191, 36, 0.35);
}

/* 无错误时隐藏验证摘要容器 */
.validation-summary-valid { display: none; }

/* ===== 图表 ===== */
.chart-container {
    width: 100%;
    height: 320px;
    background: #0a0f16;
    border: 1px solid var(--border);
    border-radius: 8px;
}

/* ===== 登录页 ===== */
.login-page {
    background: var(--bg);
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

.login-page::before {
    content: "";
    position: absolute;
    inset: 0;
    background-image:
        linear-gradient(rgba(120, 160, 220, 0.05) 1px, transparent 1px),
        linear-gradient(90deg, rgba(120, 160, 220, 0.05) 1px, transparent 1px);
    background-size: 36px 36px;
}

.login-box {
    position: relative;
    background: linear-gradient(180deg, #121a26 0%, #0d141f 100%);
    border: 1px solid var(--border-strong);
    border-radius: 14px;
    padding: 40px 42px;
    width: 400px;
    box-shadow: 0 0 0 1px rgba(34, 211, 238, 0.06), 0 24px 64px rgba(0, 0, 0, 0.55);
}

.login-box::before {
    content: "";
    position: absolute;
    top: -1px; left: 10%; right: 10%;
    height: 1px;
    background: linear-gradient(90deg, transparent, var(--accent), transparent);
    box-shadow: 0 0 18px var(--accent-glow);
}

.login-box h1 {
    font-size: 18px;
    text-align: center;
    margin: 0 0 28px;
    letter-spacing: 2px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

.login-box h1::before {
    content: "";
    width: 12px;
    height: 12px;
    background: var(--accent);
    border-radius: 2px;
    box-shadow: 0 0 12px var(--accent-glow);
}

.login-box .btn-block { margin-top: 10px; }

/* 密码框小眼睛（按住显示明文） */
.password-wrap { position: relative; }

.password-wrap .form-control { padding-right: 36px; }

.pwd-eye {
    position: absolute;
    right: 6px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    cursor: pointer;
    color: var(--muted);
    padding: 5px;
    display: inline-flex;
    align-items: center;
    border-radius: 4px;
    touch-action: none;
}

.pwd-eye:hover { color: var(--text); }

.pwd-eye svg { width: 16px; height: 16px; }

.pwd-eye.active { color: var(--accent); }

/* ===== AI 助手 ===== */
.ai-settings-bar { display: flex; align-items: center; gap: 14px; padding: 12px 18px; }

.badge-ai {
    display: inline-block;
    background: rgba(52, 211, 153, 0.12);
    color: var(--green);
    border: 1px solid rgba(52, 211, 153, 0.35);
    border-radius: 4px;
    padding: 1px 7px;
    font-size: 12px;
    margin-left: 0;
}

.badge-critical { display: inline-block; background: rgba(248,113,113,.12); color: var(--red); border: 1px solid rgba(248,113,113,.4); border-radius: 4px; padding: 1px 7px; font-size: 12px; }
.badge-warning  { display: inline-block; background: rgba(251,191,36,.12); color: var(--amber); border: 1px solid rgba(251,191,36,.4); border-radius: 4px; padding: 1px 7px; font-size: 12px; }
.badge-info     { display: inline-block; background: rgba(96,165,250,.12); color: #60a5fa; border: 1px solid rgba(96,165,250,.4); border-radius: 4px; padding: 1px 7px; font-size: 12px; }

.form-inline-group { display: flex; flex-wrap: wrap; gap: 12px; }
.form-inline-group .form-group { max-width: 200px; }

.ai-layout { display: flex; gap: 16px; }
.ai-side { width: 220px; flex-shrink: 0; }
.ai-conv-item { padding: 8px 10px; border-radius: 6px; cursor: pointer; font-size: 13px; display: flex; justify-content: space-between; gap: 6px; }
.ai-conv-item:hover { background: rgba(255,255,255,.04); }
.ai-conv-item.active { background: var(--accent-dim); color: var(--accent); }
.ai-conv-del { color: var(--muted); border: none; background: none; cursor: pointer; padding: 0 2px; }
.ai-conv-del:hover { color: var(--red); }
.ai-main { flex: 1; min-width: 0; }
.ai-chart-box { width: 100%; height: 300px; margin-top: 8px; background: #0a0f16; border: 1px solid var(--border); border-radius: 8px; }

.ai-toggle-label { border-radius: 6px; }

.ai-chat-panel { display: flex; flex-direction: column; padding: 14px 16px; }

.ai-messages {
    height: 460px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 6px 4px;
}

.ai-empty-hint {
    margin: auto;
    color: var(--muted);
    font-size: 13px;
    line-height: 2;
    text-align: center;
}

.ai-msg { display: flex; flex-direction: column; max-width: 82%; }
.ai-msg-user { align-self: flex-end; align-items: flex-end; }
.ai-msg-assistant { align-self: flex-start; align-items: flex-start; }

.ai-bubble {
    padding: 10px 14px;
    border-radius: 10px;
    font-size: 14px;
    line-height: 1.6;
    white-space: pre-wrap;
    word-break: break-word;
}

.ai-msg-user .ai-bubble {
    background: linear-gradient(180deg, #164e63, #0e7490);
    border: 1px solid rgba(34, 211, 238, 0.35);
    color: #eafcff;
}

.ai-msg-assistant .ai-bubble {
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--border);
}

.ai-thinking { color: var(--muted); font-style: italic; }

.ai-files { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 6px; }

.ai-file-chip, .ai-attach-chip {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: 12px;
    padding: 4px 10px;
    border-radius: 6px;
    border: 1px solid rgba(34, 211, 238, 0.4);
    background: var(--accent-dim);
    color: var(--accent);
    text-decoration: none;
}

.ai-attachments { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0 4px; }

.ai-input-row { display: flex; gap: 10px; align-items: flex-end; margin-top: 10px; }

.ai-input { flex: 1; resize: none; font-family: inherit; }

.ai-file-input { max-width: 90px; font-size: 12px; color: var(--muted); align-self: center; }
.ai-file-input::file-selector-button {
    background: rgba(255,255,255,0.05);
    border: 1px solid var(--border-strong);
    color: var(--text);
    border-radius: 6px;
    padding: 6px 12px;
    cursor: pointer;
    margin-right: 6px;
}
.ai-file-input::file-selector-button:hover { border-color: var(--accent); color: var(--accent); }

/* ===== Blazor 错误 UI ===== */
#blazor-error-ui {
    display: none;
    background: #1c1408;
    color: var(--amber);
    border-top: 1px solid rgba(251, 191, 36, 0.4);
    position: fixed;
    bottom: 0;
    width: 100%;
    padding: 10px 20px;
    z-index: 1000;
}
