/* ================================================================
   LockPulse App CSS — v2.0 (Sidebar + Topbar + TagsView 布局)
   ================================================================ */
:root {
    --lp-primary: #0d6efd;
    --lp-danger: #dc3545;
    --lp-success: #198754;
    --sidebar-width: 240px;
    --sidebar-collapsed-width: 64px;
    --topbar-height: 50px;
    --tagsview-height: 38px;
    --sidebar-bg: #1e293b;
    --sidebar-text: #94a3b8;
    --sidebar-active: #0d6efd;
    --sidebar-hover-bg: #334155;
    --topbar-bg: #ffffff;
    --border-color: #e2e8f0;
}

* { box-sizing: border-box; }
html { height: 100%; }

body {
    margin: 0;
    font-size: 0.9rem;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background-color: #f1f5f9;
    color: #334155;
    overflow: hidden;
    display: flex;
    height: 100vh;
    width: 100vw;
}

/* ===================== Layout System ===================== */

.layout {
    display: flex;
    height: 100vh;
    width: 100vw;
    overflow: hidden;
}

/* ---------- Sidebar ---------- */
.layout-sidebar {
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    display: flex;
    flex-direction: column;
    transition: width 0.25s ease, min-width 0.25s ease;
    z-index: 100;
    overflow: hidden;
}
.layout-sidebar.collapsed {
    width: var(--sidebar-collapsed-width);
    min-width: var(--sidebar-collapsed-width);
}

.sidebar-header {
    height: var(--topbar-height);
    display: flex;
    align-items: center;
    padding: 0 16px;
    gap: 10px;
    color: #fff;
    font-weight: 700;
    font-size: 1.1rem;
    border-bottom: 1px solid rgba(255,255,255,0.08);
    flex-shrink: 0;
    white-space: nowrap;
}
.sidebar-header i { font-size: 1.3rem; color: var(--lp-primary); }
.layout-sidebar.collapsed .sidebar-header span { display: none; }

.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 8px 0;
}
.sidebar-nav::-webkit-scrollbar { width: 4px; }
.sidebar-nav::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.15); border-radius: 2px; }

.nav-group { margin-bottom: 4px; }
.nav-group-title {
    padding: 8px 16px 4px;
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: #64748b;
    white-space: nowrap;
}
.layout-sidebar.collapsed .nav-group-title { display: none; }

.nav-item {
    display: flex;
    align-items: center;
    padding: 9px 16px;
    cursor: pointer;
    color: var(--sidebar-text);
    text-decoration: none;
    gap: 10px;
    white-space: nowrap;
    transition: background 0.15s, color 0.15s;
    border-left: 3px solid transparent;
    font-size: 0.88rem;
}
.nav-item i { font-size: 1.05rem; width: 20px; text-align: center; flex-shrink: 0; }
.nav-item:hover { background: var(--sidebar-hover-bg); color: #e2e8f0; }
.nav-item.active {
    background: rgba(13, 110, 253, 0.12);
    color: #60a5fa;
    border-left-color: var(--sidebar-active);
}
.layout-sidebar.collapsed .nav-item span { display: none; }
.layout-sidebar.collapsed .nav-item { justify-content: center; padding: 9px 0; }

/* Sub navigation (nested menu) */
.nav-sub {
    overflow: hidden;
    max-height: 0;
    transition: max-height 0.25s ease;
    background: rgba(0,0,0,0.15);
}
.nav-sub.open { max-height: 300px; }
.nav-sub .nav-item {
    padding-left: 49px;
    font-size: 0.83rem;
}
.layout-sidebar.collapsed .nav-sub { display: none; }

.nav-arrow {
    margin-left: auto;
    font-size: 0.7rem;
    transition: transform 0.2s;
}
.nav-item.open .nav-arrow { transform: rotate(180deg); }

.sidebar-footer {
    padding: 10px;
    border-top: 1px solid rgba(255,255,255,0.08);
    flex-shrink: 0;
    text-align: center;
}
.sidebar-footer button {
    background: none;
    border: 1px solid rgba(255,255,255,0.15);
    color: var(--sidebar-text);
    border-radius: 6px;
    padding: 4px 10px;
    cursor: pointer;
    font-size: 0.85rem;
    transition: background 0.15s;
}
.sidebar-footer button:hover { background: var(--sidebar-hover-bg); color: #fff; }

/* ---------- Main Area ---------- */
.layout-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    overflow: hidden;
}

/* ---------- Topbar ---------- */
.topbar {
    height: var(--topbar-height);
    background: var(--topbar-bg);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    padding: 0 16px;
    flex-shrink: 0;
    gap: 12px;
}
.topbar-toggle {
    background: none;
    border: none;
    font-size: 1.2rem;
    color: #64748b;
    cursor: pointer;
    padding: 4px 6px;
    border-radius: 4px;
    display: none;
}
.topbar-toggle:hover { background: #f1f5f9; }

.topbar-breadcrumb {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.83rem;
    color: #94a3b8;
}
.breadcrumb-item { color: #94a3b8; }
.breadcrumb-item.active { color: #334155; font-weight: 500; }
.breadcrumb-sep { color: #cbd5e1; }

.topbar-right {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 12px;
}
.topbar-user {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 6px;
    position: relative;
    transition: background 0.15s;
}
.topbar-user:hover { background: #f1f5f9; }
.user-avatar {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: var(--lp-primary);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    font-weight: 600;
}
.user-name { font-size: 0.85rem; color: #334155; }

/* User dropdown */
.user-dropdown {
    display: none;
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 4px;
    background: #fff;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.1);
    min-width: 140px;
    padding: 4px 0;
    z-index: 200;
}
.user-dropdown.show { display: block; }
.user-dropdown a {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    color: #334155;
    text-decoration: none;
    font-size: 0.85rem;
    transition: background 0.15s;
}
.user-dropdown a:hover { background: #f1f5f9; color: var(--lp-primary); }

/* ---------- TagsView ---------- */
.tags-view {
    height: var(--tagsview-height);
    background: #fff;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    padding: 0 8px;
    flex-shrink: 0;
    overflow: hidden;
}
.tags-wrapper {
    display: flex;
    align-items: center;
    gap: 2px;
    overflow-x: auto;
    scrollbar-width: none;
    flex: 1;
}
.tags-wrapper::-webkit-scrollbar { display: none; }

.tag {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 4px 12px;
    font-size: 0.8rem;
    color: #64748b;
    border: 1px solid transparent;
    border-radius: 4px;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.15s;
    user-select: none;
    flex-shrink: 0;
}
.tag:hover { background: #f1f5f9; color: #334155; }
.tag.active {
    background: #eff6ff;
    color: var(--lp-primary);
    border-color: #bfdbfe;
    font-weight: 500;
}
.tag-close {
    font-size: 1rem;
    line-height: 1;
    color: #94a3b8;
    cursor: pointer;
    border-radius: 2px;
    padding: 0 2px;
    display: none;
}
.tag:hover .tag-close { display: inline; }
.tag-close:hover { color: var(--lp-danger); background: #fef2f2; }
.tag.dashboard .tag-close { display: none !important; }

/* ---------- Content Area ---------- */
.content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-height: 0;
    background: #f1f5f9;
}
.content > .container-fluid {
    max-width: 1600px;
}

/* Tab panes */
#tab-content-area {
    display: none;
    flex: 1;
    flex-direction: column;
    min-height: 0;
}
.tab-pane-frame {
    display: none;
    flex: 1;
    min-height: 0;
    flex-direction: column;
}
.tab-pane-frame.active { display: flex; }
.tab-pane-frame iframe {
    width: 100%;
    flex: 1;
    border: none;
    min-height: 0;
}

/* ===================== Embed mode ===================== */
body.embed-mode .layout-sidebar,
body.embed-mode .topbar,
body.embed-mode .tags-view,
body.embed-mode .sidebar-overlay {
    display: none !important;
}
body.embed-mode {
    display: flex;
    flex-direction: column;
    height: 100%;
    width: 100%;
    overflow: hidden;
}
body.embed-mode .flex-table-page {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
    box-sizing: border-box;
    padding: 0.75rem 1rem;
}
.flex-table-page .card-table-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    height: 0;
    overflow: hidden;
}
.flex-table-page .card-table-wrapper .card-body {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    height: 0;
}
.flex-table-page .card-table-wrapper .table-responsive {
    flex: 1;
    overflow-y: auto;
    min-height: 0;
    max-height: none;
}
.flex-table-page .card-table-wrapper thead th {
    position: sticky;
    top: 0;
    background: #f8f9fa;
    z-index: 1;
}
.flex-table-page .pagination-bar {
    flex-shrink: 0;
}

/* ===================== Mobile responsive ===================== */
@media (max-width: 768px) {
    .layout-sidebar {
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        z-index: 1000;
        transform: translateX(-100%);
        transition: transform 0.25s ease;
    }
    .layout-sidebar.mobile-open { transform: translateX(0); }
    .layout-sidebar.collapsed { width: var(--sidebar-width); min-width: var(--sidebar-width); }
    .layout-sidebar.collapsed .nav-item span { display: inline; }
    .layout-sidebar.collapsed .nav-item { justify-content: flex-start; padding: 9px 16px; }
    .layout-sidebar.collapsed .sidebar-header span { display: inline; }
    .layout-sidebar.collapsed .nav-group-title { display: block; }
    .layout-sidebar.collapsed .nav-sub { display: block; }

    .sidebar-overlay {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(0,0,0,0.4);
        z-index: 999;
    }
    .sidebar-overlay.show { display: block; }

    .topbar-toggle { display: inline-flex; }
    .user-name { display: none; }
    .fs-4 { font-size: 1.2rem !important; }
    .card-body { padding: 0.5rem; }
    .btn { min-height: 44px; }
}

@media (max-width: 576px) {
    .container-fluid { padding: 0.5rem; }
    .row.g-3 { --bs-gutter-x: 0.5rem; }
}

/* ===================== Tab Context Menu ===================== */
.tab-context-menu {
    position: fixed;
    z-index: 9999;
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.15);
    min-width: 160px;
    padding: 4px 0;
    user-select: none;
}
.context-menu-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    font-size: 0.85rem;
    color: #334155;
    cursor: pointer;
    transition: background 0.1s;
}
.context-menu-item:hover {
    background: #f1f5f9;
    color: var(--lp-primary);
}
.context-menu-item i {
    font-size: 0.9rem;
    width: 16px;
    text-align: center;
    color: #94a3b8;
}
.context-menu-item:hover i {
    color: var(--lp-primary);
}
.context-menu-item.danger {
    color: var(--lp-danger);
}
.context-menu-item.danger:hover {
    background: #fef2f2;
    color: #b91c1c;
}
.context-menu-item.danger:hover i {
    color: #b91c1c;
}
.context-menu-divider {
    height: 1px;
    margin: 4px 8px;
    background: #e2e8f0;
}
body:not(.layout-ready) .layout-sidebar,
body:not(.layout-ready) .topbar,
body:not(.layout-ready) .tags-view { display: none; }
body:not(.layout-ready) .content { height: 100vh; }

/* ===================== Existing styles (unchanged) ===================== */

/* Cards */
.card {
    border: 1px solid #e8ecf0;
    border-radius: 8px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}
.card-header {
    background-color: #fff;
    font-weight: 600;
    font-size: 0.85rem;
    border-bottom: 1px solid #e8ecf0;
}

.fs-4 { font-size: 1.5rem !important; }

/* Table */
.table-sm th, .table-sm td {
    font-size: 0.8rem;
    padding: 0.3rem 0.5rem;
}
.table-responsive { max-height: 500px; overflow-y: auto; }

/* Pagination */
.page-link { font-size: 0.8rem; padding: 0.25rem 0.5rem; }

/* Form labels */
.form-label { font-weight: 500; color: #666; }

/* ==================== 监控看板样式 ==================== */

/* KPI 卡片 */
.kpi-card {
    transition: transform 0.2s, box-shadow 0.2s;
    border: 1px solid #e8ecf0;
    border-top: 3px solid #0d6efd;
    border-left: none;
    border-radius: 8px;
    box-shadow: 0 2px 6px rgba(0,0,0,0.06);
    height: 100%;
}
.kpi-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 14px rgba(0,0,0,0.1);
    border-top-color: #0b5ed7;
}
.kpi-value { font-size: 1.5rem; line-height: 1.2; }

/* 模块区域标题 */
.section-label {
    font-size: 0.8rem;
    font-weight: 600;
    color: #6c757d;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 0.5rem;
    padding-left: 2px;
}

/* SIM 卡预警统计 */
.sim-stat { padding: 10px 4px; border-radius: 6px; text-align: center; border: 1px solid transparent; }
.sim-stat-value { font-size: 1.3rem; font-weight: 700; }
.sim-stat-label { font-size: 0.75rem; color: #666; margin-top: 2px; }
.sim-expired { background: #fff0f0; color: #dc3545; border-color: #fecdd3; }
.sim-7d { background: #fff8e1; color: #fd7e14; border-color: #ffe0b2; }
.sim-30d { background: #fff3cd; color: #ffc107; border-color: #ffe69c; }
.sim-normal { background: #d1e7dd; color: #198754; border-color: #a3cfbb; }

/* 机构排名表格可点击行 */
.ranking-row { cursor: pointer; transition: background-color 0.15s; }
.ranking-row:hover { background-color: rgba(13, 110, 253, 0.06) !important; }

/* 告警表格 */
#alert-table thead, #ranking-table thead { position: sticky; top: 0; z-index: 1; }

/* Modal 全屏适配 */
.modal-xl { max-width: 90%; }
.modal-body .card { margin-bottom: 0.75rem; }

.font-monospace { font-family: 'Consolas', 'Monaco', monospace; }

/* 状态标签 */
.badge { font-weight: 500; font-size: 0.7rem; }

/* WebSocket 连接状态 */
#ws-status {
    padding: 2px 10px;
    border-radius: 12px;
    background: #f8f9fa;
    border: 1px solid #e8ecf0;
    font-size: 0.75rem;
    color: #666;
}
#ws-status .text-success { animation: ws-pulse 2s infinite; }
/* ==================== 行内编辑样式 ==================== */

.editable-cell {
    cursor: pointer;
    position: relative;
    transition: background-color 0.15s;
    border-radius: 3px;
    padding: 0 4px;
}
.editable-cell:hover {
    background-color: #fff8e1;
    outline: 1px dashed #ffc107;
}
.editable-cell.editing {
    padding: 0;
    background-color: #fff;
    outline: 2px solid #0d6efd;
}
.editable-cell input {
    border: none !important;
    outline: none !important;
    box-shadow: none !important;
    background: transparent;
    width: 100%;
}