/* ===== Reset & Base ===== */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    font-size: 26.6667vw; /* 1rem = 100px on 375px screen */
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Helvetica Neue", Arial, sans-serif;
    font-size: 0.14rem;
    color: #333;
    background: #f5f6fa;
    line-height: 1.5;
    -webkit-overflow-scrolling: touch;
    overflow-x: hidden;
    max-width: 750px;
    margin: 0 auto;
}

a {
    text-decoration: none;
    color: inherit;
}

ul, li {
    list-style: none;
}

/* ===== Common ===== */
.hidden { display: none !important; }

.flex { display: flex; }
.flex-col { flex-direction: column; }
.flex-1 { flex: 1; }
.flex-center { display: flex; align-items: center; justify-content: center; }
.flex-between { display: flex; align-items: center; justify-content: space-between; }
.text-center { text-align: center; }
.text-right { text-align: right; }

/* ===== Loading ===== */
.monitor-loading {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(255,255,255,0.8);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
}
.monitor-loading .spinner {
    width: 0.4rem;
    height: 0.4rem;
    border: 3px solid #e0e0e0;
    border-top-color: #1a73e8;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}
.monitor-loading .text {
    margin-top: 0.12rem;
    font-size: 0.13rem;
    color: #999;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== Empty ===== */
.monitor-empty {
    padding: 0.6rem 0.2rem;
    text-align: center;
    color: #999;
}
.monitor-empty .icon {
    font-size: 0.6rem;
    margin-bottom: 0.1rem;
}
.monitor-empty .text {
    font-size: 0.14rem;
}

/* ===== Header Bar ===== */
.monitor-header {
    position: sticky;
    top: 0;
    z-index: 100;
    background: linear-gradient(135deg, #1a73e8, #1557b0);
    padding: 0.1rem 0.15rem;
    color: #fff;
}
.header-title {
    font-size: 0.16rem;
    font-weight: 600;
    text-align: center;
}
.header-time {
    font-size: 0.11rem;
    opacity: 0.85;
    text-align: center;
    margin-top: 0.02rem;
}

/* ===== Bottom Tab Bar ===== */
.monitor-tabs {
    position: sticky;
    top: 0;
    z-index: 99;
    background: #fff;
    border-bottom: 1px solid #eee;
    display: flex;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}
.monitor-tabs::-webkit-scrollbar { display: none; }
.monitor-tabs .tab-item {
    flex-shrink: 0;
    padding: 0.1rem 0.14rem;
    font-size: 0.13rem;
    color: #666;
    position: relative;
    white-space: nowrap;
    cursor: pointer;
    transition: color 0.2s;
}
.monitor-tabs .tab-item.active {
    color: #1a73e8;
    font-weight: 600;
}
.monitor-tabs .tab-item.active::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 20%;
    right: 20%;
    height: 2px;
    background: #1a73e8;
    border-radius: 1px;
}

/* ===== Filter Bar ===== */
.monitor-filter {
    background: #fff;
    padding: 0.08rem 0.12rem;
    border-bottom: 1px solid #f0f0f0;
}
.filter-time-tabs {
    display: flex;
    gap: 0.06rem;
    flex-wrap: wrap;
}
.filter-time-tabs .time-item {
    padding: 0.04rem 0.1rem;
    font-size: 0.11rem;
    border-radius: 0.12rem;
    border: 1px solid #ddd;
    color: #666;
    cursor: pointer;
    transition: all 0.2s;
}
.filter-time-tabs .time-item.active {
    background: #1a73e8;
    border-color: #1a73e8;
    color: #fff;
}
.filter-extend {
    margin-top: 0.06rem;
    display: none;
    padding-top: 0.06rem;
    border-top: 1px solid #f5f5f5;
}
.filter-extend.show { display: block; }
.filter-row {
    display: flex;
    align-items: center;
    margin-bottom: 0.06rem;
}
.filter-row .label {
    width: 0.5rem;
    font-size: 0.12rem;
    color: #666;
    flex-shrink: 0;
}
.filter-row .tag-list {
    display: flex;
    flex-wrap: wrap;
    gap: 0.05rem;
    flex: 1;
}
.filter-row .tag-item {
    padding: 0.03rem 0.08rem;
    font-size: 0.11rem;
    border-radius: 0.03rem;
    border: 1px solid #ddd;
    color: #666;
    cursor: pointer;
}
.filter-row .tag-item.selected {
    background: #e8f0fe;
    border-color: #1a73e8;
    color: #1a73e8;
}
.filter-input {
    flex: 1;
    height: 0.3rem;
    padding: 0 0.08rem;
    border: 1px solid #ddd;
    border-radius: 0.04rem;
    font-size: 0.12rem;
}
.filter-time-input {
    width: 1.2rem;
    height: 0.3rem;
    padding: 0 0.06rem;
    border: 1px solid #ddd;
    border-radius: 0.04rem;
    font-size: 0.1rem;
}
.filter-actions {
    display: flex;
    gap: 0.1rem;
    justify-content: flex-end;
    margin-top: 0.06rem;
}
.filter-btn {
    padding: 0.06rem 0.2rem;
    border-radius: 0.04rem;
    border: none;
    font-size: 0.13rem;
    cursor: pointer;
}
.filter-btn-reset {
    background: #f5f5f5;
    color: #666;
}
.filter-btn-confirm {
    background: #1a73e8;
    color: #fff;
}
.filter-toggle {
    text-align: right;
    margin-top: 0.02rem;
}
.filter-toggle-btn {
    font-size: 0.11rem;
    color: #1a73e8;
    cursor: pointer;
    background: none;
    border: none;
}

/* ===== Data Cards ===== */
.monitor-list {
    padding: 0.08rem 0.12rem;
}
.data-card {
    background: #fff;
    border-radius: 0.06rem;
    margin-bottom: 0.08rem;
    overflow: hidden;
    box-shadow: 0 1px 4px rgba(0,0,0,0.06);
    cursor: pointer;
    display: flex;
    transition: transform 0.15s;
}
.data-card:active {
    transform: scale(0.98);
}
.data-card .warn-strip {
    width: 0.04rem;
    flex-shrink: 0;
}
.warn-3 { background: #F56C6C; } /* 红色告警 */
.warn-2 { background: #E6A23C; } /* 橙色告警 */
.warn-1 { background: #F2D024; } /* 黄色告警 */
.warn-0 { background: #67C23A; } /* 正常 */
.warn--1 { background: #909399; } /* 异常/离线 */

.data-card .card-body {
    flex: 1;
    padding: 0.1rem 0.12rem;
}
.data-card .card-title {
    font-size: 0.14rem;
    font-weight: 600;
    color: #333;
    margin-bottom: 0.04rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.data-card .card-title .warn-badge {
    font-size: 0.1rem;
    padding: 0.02rem 0.06rem;
    border-radius: 0.08rem;
    color: #fff;
    font-weight: 500;
}
.badge-red { background: #F56C6C; }
.badge-orange { background: #E6A23C; }
.badge-yellow { background: #F2D024; color: #333; }
.badge-green { background: #67C23A; }
.badge-gray { background: #909399; }

.data-card .card-info {
    display: flex;
    flex-wrap: wrap;
    gap: 0.06rem 0.15rem;
}
.data-card .info-item {
    font-size: 0.11rem;
    color: #666;
}
.data-card .info-item .val {
    color: #333;
    font-weight: 500;
}
.data-card .info-item .unit {
    font-size: 0.09rem;
    color: #999;
}
.data-card .card-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 0.06rem;
}
.data-card .meta-time {
    font-size: 0.1rem;
    color: #999;
}
.data-card .meta-arrow {
    font-size: 0.14rem;
    color: #ccc;
}

/* ===== Pager ===== */
.monitor-pager {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0.1rem;
    gap: 0.15rem;
    background: #fff;
    border-top: 1px solid #f0f0f0;
}
.monitor-pager .page-btn {
    width: 0.3rem;
    height: 0.3rem;
    border-radius: 50%;
    border: 1px solid #ddd;
    background: #fff;
    font-size: 0.14rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #666;
}
.monitor-pager .page-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}
.monitor-pager .page-info {
    font-size: 0.12rem;
    color: #666;
}

/* ===== Summary Bar ===== */
.monitor-summary {
    display: flex;
    background: #fff;
    padding: 0.1rem 0.12rem;
    border-bottom: 1px solid #f0f0f0;
    gap: 0.08rem;
}
.monitor-summary .summary-item {
    flex: 1;
    text-align: center;
    padding: 0.06rem 0;
    border-radius: 0.04rem;
    background: #f8f9fb;
}
.summary-item .num {
    font-size: 0.18rem;
    font-weight: 700;
}
.summary-item .label {
    font-size: 0.1rem;
    color: #999;
    margin-top: 0.02rem;
}
.summary-total .num { color: #333; }
.summary-normal .num { color: #67C23A; }
.summary-warn .num { color: #E6A23C; }
.summary-error .num { color: #F56C6C; }

/* ===== Detail Page ===== */
.detail-page {
    min-height: 100vh;
    background: #f5f6fa;
}
.detail-header {
    background: linear-gradient(135deg, #1a73e8, #1557b0);
    color: #fff;
    padding: 0.1rem 0.15rem;
    position: relative;
}
.detail-back {
    position: absolute;
    left: 0.15rem;
    top: 50%;
    transform: translateY(-50%);
    font-size: 0.2rem;
    cursor: pointer;
    color: #fff;
}
.detail-back:active { opacity: 0.7; }
.detail-title {
    font-size: 0.16rem;
    font-weight: 600;
    text-align: center;
    padding: 0 0.3rem;
}
.detail-subtitle {
    font-size: 0.11rem;
    opacity: 0.85;
    text-align: center;
    margin-top: 0.02rem;
}

.detail-metrics {
    background: #fff;
    margin: 0.08rem 0.12rem;
    border-radius: 0.08rem;
    padding: 0.12rem 0.15rem;
    box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}
.metrics-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.1rem;
}
.metric-item {
    text-align: center;
    padding: 0.08rem 0.05rem;
    background: #f8f9fb;
    border-radius: 0.06rem;
}
.metric-item .metric-val {
    font-size: 0.22rem;
    font-weight: 700;
    color: #1a73e8;
}
.metric-item .metric-val.warn { color: #F56C6C; }
.metric-item .metric-val.orange { color: #E6A23C; }
.metric-item .metric-unit {
    font-size: 0.1rem;
    color: #999;
    margin-left: 0.02rem;
}
.metric-item .metric-label {
    font-size: 0.11rem;
    color: #666;
    margin-top: 0.02rem;
}

.detail-chart {
    background: #fff;
    margin: 0.08rem 0.12rem;
    border-radius: 0.08rem;
    padding: 0.12rem;
    box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}
.detail-chart .chart-title {
    font-size: 0.14rem;
    font-weight: 600;
    color: #333;
    margin-bottom: 0.08rem;
    padding-left: 0.08rem;
    border-left: 3px solid #1a73e8;
}
.chart-container {
    width: 100%;
    height: 2.5rem;
}

.detail-info-table {
    background: #fff;
    margin: 0.08rem 0.12rem;
    border-radius: 0.08rem;
    padding: 0.12rem;
    box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}
.info-table .info-row {
    display: flex;
    padding: 0.06rem 0;
    border-bottom: 1px solid #f5f5f5;
    font-size: 0.12rem;
}
.info-table .info-row:last-child { border-bottom: none; }
.info-row .info-key {
    color: #999;
    width: 0.7rem;
    flex-shrink: 0;
}
.info-row .info-val {
    color: #333;
    flex: 1;
}

/* ===== Video ===== */
.video-container {
    width: 100%;
    background: #000;
    position: relative;
}
.video-container video,
.video-container .video-js {
    width: 100%;
    max-height: 60vh;
}
.video-offline {
    text-align: center;
    padding: 1rem 0.2rem;
    color: #999;
    background: #fff;
    margin: 0.08rem 0.12rem;
    border-radius: 0.08rem;
}

/* ===== Toast ===== */
.monitor-toast {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0,0,0,0.75);
    color: #fff;
    padding: 0.1rem 0.2rem;
    border-radius: 0.06rem;
    font-size: 0.13rem;
    z-index: 10000;
    pointer-events: none;
    animation: toastFade 2s ease forwards;
}
@keyframes toastFade {
    0% { opacity: 0; }
    15% { opacity: 1; }
    85% { opacity: 1; }
    100% { opacity: 0; }
}

/* ===== Pull-to-refresh hint ===== */
.pull-hint {
    text-align: center;
    padding: 0.1rem;
    font-size: 0.11rem;
    color: #999;
}
.pull-hint .refresh-icon {
    display: inline-block;
    animation: spin 1s linear infinite;
    font-size: 0.14rem;
}

/* ===== Fix bottom when data not full ===== */
.monitor-content {
    padding-bottom: 0.4rem;
}

@media screen and (min-width: 420px) {
    html { font-size: 112px; }
}

/* ===== Touch & Interaction Optimizations ===== */
body { touch-action: manipulation; }
.data-card, .tab-item, .time-item, .tag-item, .filter-btn, .page-btn, button {
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}
input, select, textarea { font-size: 0.16rem; } /* Prevent iOS zoom on focus */

/* ===== Safe Area Support (iPhone X) ===== */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
    .monitor-pager { padding-bottom: calc(0.1rem + env(safe-area-inset-bottom)); }
    .monitor-content { padding-bottom: calc(0.4rem + env(safe-area-inset-bottom)); }
    .detail-page { padding-bottom: env(safe-area-inset-bottom); }
}

/* ===== Landscape Hint ===== */
@media screen and (orientation: landscape) and (max-height: 500px) {
    .detail-metrics .metrics-grid { grid-template-columns: repeat(4, 1fr); }
    .chart-container { height: 2rem; }
}
