/**
 * @fileoverview 页面骨架与容器
 * @description 后台页面统一的宽度、留白、三栏网格、面板卡片、工具条、
 *              启动加载层与响应式断点。业务页面只组合这些结构类。
 * @author calvinliu@hk.chinamobile.com
 * @version V1.0.0
 * @license MIT
 */

/* 后台主体：顶部固定工具栏之下，保留统一的 12px 区块间距 */
.app-main {
    width: 100%;
    max-width: var(--content-max);
    min-height: calc(100vh - var(--shell-h));
    margin: 0 auto;
    padding: calc(var(--shell-h) + var(--block-gap)) var(--page-gutter) 24px;
}

.app-main.is-entering {
    animation: tbd-page-enter 460ms var(--ease-out) both;
}

/* 页面切换入场：启动加载层淡出后整体上浮淡入 */
@keyframes tbd-page-enter {
    from {
        opacity: 0;
        transform: translate3d(0, 12px, 0);
    }
    to {
        opacity: 1;
        transform: translate3d(0, 0, 0);
    }
}

.page {
    display: flex;
    flex-direction: column;
    gap: var(--block-gap);
}

/* 数据页视口锁定：整页固定为一屏高度，三栏在内部弹性分配，不产生页面滚动条 */
.app-body--fixed {
    height: 100dvh;
    min-height: 0;
    overflow: hidden;
}

.app-body--fixed .app-main {
    display: flex;
    height: 100dvh;
    min-height: 0;
    padding-bottom: var(--block-gap);
}

.app-body--fixed .page {
    flex: 1;
    min-height: 0;
}

/* 管理类页面同样锁定一屏：内容区在面板内部消化，页面不出现滚动条 */
.app-body--fixed .settings-page,
.app-body--fixed .users-page {
    overflow: hidden;
}

/* 管理页滚动模式：整页跟随文档流滚动，滚动条可见，内容不再被面板裁剪 */
.app-body--scroll {
    height: 100dvh;
    overflow-x: hidden;
    overflow-y: auto;
    scrollbar-color: var(--border-strong) transparent;
    scrollbar-width: thin;
}

.app-body--scroll::-webkit-scrollbar,
.app-body--scroll *::-webkit-scrollbar {
    display: block;
    width: 8px;
    height: 8px;
}

.app-body--scroll::-webkit-scrollbar-track,
.app-body--scroll *::-webkit-scrollbar-track {
    background: transparent;
}

.app-body--scroll::-webkit-scrollbar-thumb,
.app-body--scroll *::-webkit-scrollbar-thumb {
    background: var(--border-strong);
    background-clip: content-box;
    border: 2px solid transparent;
    border-radius: var(--radius-pill);
}

.app-body--scroll::-webkit-scrollbar-thumb:hover,
.app-body--scroll *::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
    background-clip: content-box;
}

.app-body--scroll .app-main {
    min-height: 100vh;
}

.app-body--fixed .data-layout {
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

.app-body--fixed .data-col-left,
.app-body--fixed .data-col-center,
.app-body--fixed .data-col-right {
    min-height: 0;
}

/* 移动端舞台切换控件：桌面隐藏，窄屏在工具条内独占一行 */
.page-stages {
    display: none;
}

/* 低高度视口：收紧面板标题，为图表与地图优先留出纵向空间 */
@media (max-height: 840px) {
    .panel-head {
        padding: 8px 14px;
    }

    .panel-head-title .panel-icon {
        width: 24px;
        height: 24px;
    }
}

/* 工具条内容区：左侧信息自适应，右侧操作固定不收缩 */
.toolbar-start {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    min-width: 0;
    flex: 1;
}

.toolbar-end {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    flex-shrink: 0;
}

/* 三栏数据布局：左信息、中图表、右日历与地图 */
.data-layout {
    display: grid;
    grid-template-columns: var(--col-left) minmax(0, 1fr) var(--col-right);
    grid-template-areas: "left center right";
    gap: var(--block-gap);
    align-items: stretch;
    min-height: 0;
}

.data-col-left {
    grid-area: left;
    display: flex;
    flex-direction: column;
    gap: var(--block-gap);
    min-width: 0;
}

.data-col-center {
    grid-area: center;
    display: flex;
    flex-direction: column;
    gap: var(--block-gap);
    min-width: 0;
}

.data-col-right {
    grid-area: right;
    display: flex;
    flex-direction: column;
    gap: var(--block-gap);
    min-width: 0;
}

/* 面板：深色为磨砂玻璃，浅色为白色卡片 */
.panel {
    position: relative;
    display: flex;
    flex-direction: column;
    min-width: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    -webkit-backdrop-filter: blur(var(--glass-blur)) saturate(var(--glass-saturate));
    backdrop-filter: blur(var(--glass-blur)) saturate(var(--glass-saturate));
    transition: border-color var(--dur-2) var(--ease-out), box-shadow var(--dur-2) var(--ease-out);
}

/* 深色面板顶部的高光细线，使用彩虹渐变但保持较低透明度 */
html[data-theme="dark"] .panel::before {
    position: absolute;
    top: -1px;
    left: 14px;
    right: 14px;
    height: 1px;
    content: "";
    background: linear-gradient(90deg, transparent, rgba(34, 211, 238, 0.56), rgba(129, 140, 248, 0.46), rgba(244, 114, 182, 0.44), transparent);
    opacity: 0.7;
    pointer-events: none;
}

.panel:hover {
    border-color: var(--border-strong);
}

html[data-theme="light"] .panel:hover {
    box-shadow: var(--shadow-md);
}

.panel--flush {
    overflow: hidden;
}

.panel-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
    padding: 12px 14px;
    border-bottom: 1px solid var(--border-soft);
    flex-shrink: 0;
}

/* 主面板标题栏：用户管理、系统配置、取数监控与区域地图共用同一高度，
   底部细分割线把标题操作区与内容区明确分开 */
.panel-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
    min-height: var(--panel-head-h);
    padding: 0 14px;
    border-bottom: 1px solid var(--border-soft);
    flex-shrink: 0;
}

.panel-head-title {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    min-width: 0;
}

.panel-head-title h2 {
    font-size: var(--font-md);
    font-weight: 650;
    letter-spacing: 0.02em;
    white-space: nowrap;
}

.panel-head-title .panel-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    font-size: var(--font-xs);
    color: var(--accent);
    background: var(--accent-soft);
    border-radius: var(--radius-sm);
    flex-shrink: 0;
}

.panel-head-actions {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    flex-shrink: 0;
}

.panel-body {
    flex: 1;
    min-height: 0;
    padding: 14px;
}

.panel-body--tight {
    padding: 10px;
}

.panel-body--flush {
    padding: 0;
}

/* 融合面板：标题与内容共处一块卡片，用间距与字色分层，不再用分割线切出独立标题栏 */
.panel--integrated .panel-head {
    padding: 14px 16px 0;
    border-bottom: 0;
}

.panel--integrated .panel-head-title {
    gap: 7px;
}

.panel--integrated .panel-head-title .panel-icon {
    width: 18px;
    height: 18px;
    font-size: 11px;
    color: var(--accent);
    background: transparent;
    opacity: 0.78;
}

.panel--integrated .panel-head-title h2 {
    letter-spacing: 0.03em;
    color: var(--text-primary);
}

.panel--integrated > .panel-body:not(.panel-body--flush) {
    padding-top: 8px;
}

.panel--integrated > .panel-body--flush {
    padding-top: 8px;
}

/* 页面级最大化：面板脱离网格铺满视口，层级高于外壳、低于弹窗与提示 */
.panel.is-maximized {
    position: fixed;
    inset: 0;
    z-index: var(--z-maximized);
    background: var(--surface-solid);
    border: 0;
    border-radius: 0;
    box-shadow: none;
    animation: tbd-panel-maximize var(--dur-3) var(--ease-out) both;
}

.panel.is-maximized::before {
    display: none;
}

.panel.is-maximized > .panel-body {
    flex: 1;
    min-height: 0;
}

.panel.is-maximized.is-restoring {
    opacity: 0;
    transform: scale(0.99);
    transition: opacity 160ms var(--ease-out), transform 160ms var(--ease-out);
}

@keyframes tbd-panel-maximize {
    from {
        opacity: 0;
        transform: scale(0.985);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

.panel-foot {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
    padding: 10px 14px;
    border-top: 1px solid var(--border-soft);
    flex-shrink: 0;
}

/* 图表容器：由脚本初始化 ECharts，加载时显示骨架 */
.chart-box {
    position: relative;
    width: 100%;
    min-height: 300px;
}

.chart-box--fill {
    flex: 1;
    min-height: 420px;
}

.chart-box__canvas {
    width: 100%;
    height: 100%;
    min-height: inherit;
}

.chart-box__loading {
    position: absolute;
    inset: 0;
    z-index: 2;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    font-size: var(--font-sm);
    color: var(--text-muted);
    background: var(--surface);
    border-radius: var(--radius-md);
    transition: opacity var(--dur-2) var(--ease-out);
}

.chart-box.is-ready .chart-box__loading {
    opacity: 0;
    pointer-events: none;
}

/* 图表空状态：覆盖画布中央，不影响图表实例尺寸 */
.chart-empty {
    position: absolute;
    inset: 0;
    z-index: 3;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    font-size: var(--font-sm);
    color: var(--text-muted);
    background: var(--surface);
    border-radius: var(--radius-md);
}

.chart-empty i {
    font-size: 22px;
    color: var(--text-muted);
    opacity: 0.7;
}

/* 图表提示框：由 ECharts formatter 生成，统一为紧凑的键值行 */
.chart-tooltip {
    min-width: 128px;
    color: var(--text-primary);
}

.chart-tooltip__head {
    padding-bottom: 5px;
    margin-bottom: 5px;
    font-size: var(--font-xs);
    color: var(--text-muted);
    border-bottom: 1px solid var(--border-soft);
}

.chart-tooltip__row {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 1px 0;
    font-size: var(--font-sm);
}

.chart-tooltip__row i {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    flex-shrink: 0;
}

.chart-tooltip__row span {
    flex: 1;
    color: var(--text-secondary);
}

.chart-tooltip__row strong {
    font-family: var(--font-number);
    font-size: var(--font-sm);
    font-weight: 650;
    font-variant-numeric: tabular-nums;
}

/* 地图容器：Leaflet 画布铺满，圆角由外层裁切 */
.map-box {
    position: relative;
    width: 100%;
    height: 240px;
    overflow: hidden;
    background: var(--map-water);
    border-radius: var(--radius-md);
    border: 1px solid var(--border-soft);
    z-index: var(--z-map);
}

.map-box .leaflet-container {
    width: 100%;
    height: 100%;
    font-family: var(--font-sans);
    background: transparent;
}

.map-box .leaflet-control-attribution {
    display: none;
}

.stack {
    display: flex;
    flex-direction: column;
    gap: var(--block-gap);
}

.row {
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

/* 空状态：图标、标题与补充说明 */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 220px;
    padding: var(--space-8) var(--space-4);
    text-align: center;
    color: var(--text-muted);
    gap: var(--space-2);
}

.empty-state__icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 52px;
    height: 52px;
    margin-bottom: var(--space-1);
    font-size: 20px;
    color: var(--text-muted);
    background: var(--surface-2);
    border: 1px solid var(--border-soft);
    border-radius: 50%;
}

.empty-state__title {
    font-size: var(--font-md);
    font-weight: 600;
    color: var(--text-secondary);
}

.empty-state__desc {
    max-width: 340px;
    font-size: var(--font-sm);
    line-height: 1.6;
}

/* 启动加载层：纯几何旋转轨道，不显示任何文字，页面就绪后整体淡出 */
.boot-loader {
    position: fixed;
    inset: 0;
    z-index: var(--z-loader);
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-base);
    transition: opacity var(--dur-4) var(--ease-out), visibility var(--dur-4) var(--ease-out);
}

.boot-loader.is-done {
    visibility: hidden;
    opacity: 0;
    pointer-events: none;
}

.boot-loader__core {
    position: relative;
    display: grid;
    width: 92px;
    height: 92px;
    place-items: center;
}

/* 中心冷光，让整体带一点悬浮感 */
.boot-loader__core::before {
    position: absolute;
    inset: 14px;
    content: "";
    background: radial-gradient(circle, rgba(34, 211, 238, 0.22), rgba(129, 140, 248, 0.08) 56%, transparent 72%);
    border-radius: 50%;
    animation: boot-halo 2.4s var(--ease-in-out) infinite;
}

.boot-loader__ring {
    position: absolute;
    border: 1.5px solid transparent;
    border-radius: 50%;
}

.boot-loader__ring--outer {
    inset: 0;
    border-top-color: var(--brand-cyan);
    border-right-color: rgba(34, 211, 238, 0.28);
    box-shadow: 0 0 20px rgba(34, 211, 238, 0.22);
    animation: tbd-spin 1.05s linear infinite;
}

.boot-loader__ring--mid {
    inset: 10px;
    border-bottom-color: var(--brand-indigo);
    border-left-color: rgba(129, 140, 248, 0.34);
    animation: tbd-spin 1.6s linear infinite reverse;
}

.boot-loader__ring--inner {
    inset: 20px;
    border-top-color: var(--brand-pink);
    border-bottom-color: rgba(244, 114, 182, 0.32);
    animation: tbd-spin 760ms linear infinite;
}

.boot-loader__dot {
    width: 11px;
    height: 11px;
    background: linear-gradient(135deg, var(--brand-cyan), var(--brand-indigo));
    border-radius: 50%;
    box-shadow: 0 0 16px rgba(34, 211, 238, 0.8);
    animation: boot-core-pulse 1.5s var(--ease-in-out) infinite;
}

@keyframes boot-halo {
    0%,
    100% {
        opacity: 0.55;
        transform: scale(0.92);
    }
    50% {
        opacity: 1;
        transform: scale(1.06);
    }
}

@keyframes boot-core-pulse {
    0%,
    100% {
        transform: scale(0.86);
    }
    50% {
        transform: scale(1.12);
    }
}

/* 响应式：中等屏幕收紧左右列，平板改为两栏，移动端单栏 */
@media (max-width: 1440px) {
    :root {
        --col-left: 284px;
        --col-right: 300px;
    }
}

@media (max-width: 1240px) {
    :root {
        --col-left: 268px;
        --col-right: 286px;
    }
}

@media (max-width: 1100px) {
    .data-layout {
        grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.35fr);
        grid-template-areas:
            "left center"
            "right right";
    }

    .data-col-right {
        display: grid;
        grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
        align-items: stretch;
    }

    .chart-box--fill {
        min-height: 360px;
    }

    /* 视口锁定的数据页在平板横向仍保持三栏，避免两行网格撑出一屏 */
    .app-body--fixed .data-layout {
        grid-template-columns: 250px minmax(0, 1fr) 260px;
        grid-template-areas: "left center right";
    }

    .app-body--fixed .data-col-right {
        display: flex;
        flex-direction: column;
        align-items: stretch;
    }
}

@media (max-width: 860px) {
    .app-main {
        padding-bottom: 16px;
    }

    .data-layout {
        grid-template-columns: minmax(0, 1fr);
        grid-template-areas:
            "left"
            "center"
            "right";
    }

    .data-col-right {
        grid-template-columns: minmax(0, 1fr);
    }

    .toolbar-start {
        flex-wrap: wrap;
    }

    .toolbar-end {
        margin-left: auto;
    }

    .chart-box--fill {
        min-height: 300px;
    }

    /* 窄屏改为单栏舞台：三栏叠在同一网格区域，由分段控件切换显示 */
    .app-body--fixed .data-layout {
        grid-template-columns: minmax(0, 1fr);
        grid-template-areas: "stage";
    }

    .app-body--fixed .data-layout > .data-col-left,
    .app-body--fixed .data-layout > .data-col-center,
    .app-body--fixed .data-layout > .data-col-right {
        display: none;
        grid-area: stage;
        min-height: 0;
    }

    .app-body--fixed .data-layout[data-stage="left"] > .data-col-left,
    .app-body--fixed .data-layout[data-stage="center"] > .data-col-center,
    .app-body--fixed .data-layout[data-stage="right"] > .data-col-right {
        display: flex;
    }

    .app-body--fixed .data-layout[data-stage="left"] > .data-col-left,
    .app-body--fixed .data-layout[data-stage="center"] > .data-col-center {
        flex-direction: column;
    }

    .page-stages {
        display: block;
        flex: 0 0 auto;
    }

    .page-stages .ui-segmented {
        width: 100%;
    }
}

@media (max-width: 560px) {
    .panel-head {
        padding: 10px 12px;
    }

    .panel-body {
        padding: 12px;
    }
}
