:root {
    --primary-color: #009688;
    --primary-dark: #00796B;
    --primary-light: #B2DFDB;
    --accent-color: #FF5722;
    --bg-gradient-start: #E0F2F1;
    --bg-gradient-end: #B2DFDB;
    --text-color: #333;
    --text-secondary: #666;
    --card-bg: rgba(255, 255, 255, 0.75);
    --danger-color: #f44336;
}

* {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    margin: 0;
    padding: 0;
    background: linear-gradient(135deg, var(--bg-gradient-start) 0%, var(--bg-gradient-end) 100%);
    color: var(--text-color);
    min-height: 100vh;
}

/* 通用样式 */
.page {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.container {
    padding: 12px;
    width: 100%;
    max-width: 600px; /* 限制最大宽度，模拟手机体验 */
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.glass-effect {
    background: var(--card-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(255, 255, 255, 0.6);
    box-shadow: 0 4px 16px rgba(0, 150, 136, 0.08);
    border-radius: 12px;
}

/* 导航栏 */
.nav-bar {
    background: #F0F4F3;
    color: #000;
    padding: 12px 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}

.nav-title {
    font-weight: 600;
    font-size: 1.1rem;
}

.nav-back, .btn-text {
    background: none;
    border: none;
    font-size: 1.2rem;
    cursor: pointer;
    color: var(--primary-color);
    padding: 4px 8px;
}

/* 认证页面 */
.auth-container {
    max-width: 360px;
    margin: 60px auto;
    padding: 2rem;
    text-align: center;
}

.auth-title {
    color: var(--primary-dark);
    margin-bottom: 0.5rem;
}

.auth-subtitle {
    color: var(--text-secondary);
    margin-bottom: 2rem;
    font-size: 0.9rem;
}

.form-group {
    margin-bottom: 1.2rem;
    text-align: left;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.form-group input {
    width: 100%;
    padding: 0.8rem;
    border: 1px solid rgba(0,0,0,0.1);
    border-radius: 8px;
    background: rgba(255,255,255,0.8);
    font-size: 1rem;
}

.btn-primary {
    width: 100%;
    padding: 0.8rem;
    background-color: var(--primary-color);
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 1rem;
    font-weight: 600;
    margin-top: 1rem;
    transition: opacity 0.2s;
}

.btn-primary:hover {
    opacity: 0.9;
}

.switch-auth {
    margin-top: 1.5rem;
    font-size: 0.9rem;
}

.switch-auth a {
    color: var(--primary-color);
    text-decoration: none;
    font-weight: 600;
}

/* 设备列表 */
.device-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding-bottom: 80px;
}

.device-card {
    padding: 16px;
    display: flex;
    align-items: center;
    cursor: pointer;
    transition: transform 0.2s;
    background: rgba(255, 255, 255, 0.65);
    border-radius: 12px;
}

.device-card:active {
    transform: scale(0.98);
}

.device-icon-box {
    width: 44px;
    height: 44px;
    border-radius: 10px;
    background: rgba(0, 150, 136, 0.1);
    display: flex;
    align-items: center;
    justify-content: center;
    margin-right: 12px;
    color: var(--primary-color);
    font-size: 1.2rem;
}

.device-info {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.device-name {
    font-size: 1rem;
    font-weight: 600;
    color: #004D40;
    margin-bottom: 4px;
}

.device-status {
    font-size: 0.8rem;
    display: flex;
    align-items: center;
    color: #999;
}

.device-status::before {
    content: '';
    display: inline-block;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    margin-right: 4px;
    background-color: #ccc;
}

.device-status.online {
    color: var(--primary-dark);
}

.device-status.online::before {
    background-color: var(--primary-color);
    box-shadow: 0 0 4px rgba(0, 150, 136, 0.6);
}

.device-arrow {
    color: #ccc;
    font-size: 0.8rem;
}

.add-btn-wrapper {
    position: fixed;
    bottom: 20px;
    left: 0;
    right: 0;
    display: flex;
    justify-content: center;
    pointer-events: none;
}

.add-btn {
    pointer-events: auto;
    background: var(--primary-color);
    color: white;
    border: none;
    padding: 12px 32px;
    border-radius: 30px;
    font-size: 1rem;
    font-weight: 600;
    box-shadow: 0 4px 12px rgba(0, 150, 136, 0.3);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
}

/* RGB 矩阵控制样式 */
.rgb-card {
    padding: 12px 12px 16px 12px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.rgb-header {
    display: flex;
    flex-direction: column;
    gap: 8px;
    font-size: 0.9rem;
}

.rgb-title-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: 600;
}

.rgb-controls {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
}

.rgb-presets {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.color-preset {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
    transition: transform 0.15s, box-shadow 0.15s;
}

.color-preset:hover {
    transform: scale(1.15);
    box-shadow: 0 3px 8px rgba(0,0,0,0.3);
}

.color-preset:active {
    transform: scale(0.95);
}

.rgb-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.rgb-brightness-label,
.rgb-color-label {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 0.8rem;
}

#rgb-brightness {
    width: 100px;
}

#rgb-color {
    width: 32px;
    height: 24px;
    padding: 0;
    border: none;
    background: transparent;
    cursor: pointer;
}

.btn-mini {
    padding: 6px 10px;
    border-radius: 10px;
    border: none;
    background: var(--primary-color);
    color: #fff;
    font-size: 0.75rem;
    cursor: pointer;
    transition: opacity 0.2s, transform 0.15s;
}

.btn-mini:hover {
    opacity: 0.9;
}

.btn-mini:active {
    transform: scale(0.95);
}

.btn-mini.btn-danger {
    background: var(--danger-color);
}

.btn-mini.btn-warning {
    background: #FF9800;
}

.btn-mini.btn-secondary {
    background: #9E9E9E;
}

.rgb-matrix {
    margin-top: 8px;
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 8px;
    justify-items: center;
    padding: 10px;
    background: rgba(0,0,0,0.03);
    border-radius: 8px;
}

.rgb-cell {
    width: 40px;
    height: 40px;
    border-radius: 8px;
    border: 2px solid rgba(0,0,0,0.1);
    background: #f5f5f5;
    cursor: pointer;
    box-shadow: inset 0 0 4px rgba(0,0,0,0.1);
    position: relative;
    transition: transform 0.15s, box-shadow 0.15s;
}

.rgb-cell:hover {
    transform: scale(1.08);
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}

.rgb-cell.selected::after {
    content: '✓';
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: rgba(255,255,255,0.9);
    font-size: 1.2rem;
    font-weight: bold;
    text-shadow: 0 1px 2px rgba(0,0,0,0.5);
    border: 2px solid var(--primary-color);
    border-radius: 6px;
    background: rgba(0,150,136,0.2);
}

.rgb-tip {
    font-size: 0.75rem;
    color: #888;
    text-align: center;
    margin-top: 4px;
}

/* 设备详情页 */
.header-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 5px 2px;
}

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

.avatar-placeholder {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.8);
    box-shadow: 0 2px 6px rgba(0, 150, 136, 0.15);
    overflow: hidden;
    border: 1px solid #fff;
}

.avatar-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.user-text {
    display: flex;
    flex-direction: column;
}

.greeting {
    font-size: 0.75rem;
    color: #555;
}

.username {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--primary-dark);
}

.weather-widget {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    padding: 6px 12px;
    border-radius: 15px;
}

.weather-main {
    display: flex;
    align-items: baseline;
    gap: 4px;
}

.weather-temp {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--primary-dark);
}

.weather-cond {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.weather-loc {
    font-size: 0.7rem;
    color: #888;
    display: flex;
    align-items: center;
    gap: 2px;
}

.update-bar {
    display: flex;
    align-items: center;
    font-size: 0.75rem;
    color: #888;
    padding-left: 4px;
}

.update-dot {
    width: 6px;
    height: 6px;
    background-color: var(--primary-color);
    border-radius: 50%;
    margin-right: 6px;
    animation: pulse 2s infinite;
}

.update-dot.offline {
    background-color: var(--text-secondary);
    animation: none;
}

@keyframes pulse {
    0% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.5; transform: scale(0.8); }
    100% { opacity: 1; transform: scale(1); }
}

/* 卡片通用 */
.card {
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-bottom: 8px;
    border-bottom: 1px solid rgba(0,0,0,0.05);
}

.card-title {
    font-size: 1rem;
    font-weight: 600;
    color: #333;
    border-left: 4px solid var(--primary-color);
    padding-left: 8px;
}

.status-badge {
    font-size: 0.75rem;
    padding: 2px 8px;
    border-radius: 10px;
    background: #eee;
    color: #666;
}

.status-badge.normal {
    background: rgba(0, 150, 136, 0.1);
    color: var(--primary-color);
}

.status-badge.danger {
    background: rgba(244, 67, 54, 0.1);
    color: var(--danger-color);
}

/* 监控卡片 */
.monitor-content {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
    padding: 10px 0;
    justify-items: center;
}

.monitor-block {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.monitor-icon-circle {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    box-shadow: 0 2px 8px rgba(0,0,0,0.05);
}

.icon-temp { color: #FF9800; }
.icon-humid { color: #2196F3; }
.icon-light-sensor { color: #FFC107; }
.icon-bt { color: #0082FC; }
.icon-fan { background: rgba(33, 150, 243, 0.15); color: #2196F3; }

.monitor-data {
    text-align: center;
}

.monitor-val {
    font-size: 1.5rem;
    font-weight: 600;
    color: #333;
    display: block;
    line-height: 1.2;
}

.monitor-val .unit {
    font-size: 0.9rem;
    color: #666;
    margin-left: 2px;
}

.monitor-lbl {
    font-size: 0.8rem;
    color: #888;
}

/* 控制卡片网格布局 */
.control-grid-container {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); /* 自适应列宽 */
    gap: 12px;
    margin-bottom: 20px;
}

.control-card {
    padding: 16px;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 12px;
    transition: transform 0.2s;
}

.control-card:active {
    transform: scale(0.98);
}

.card-icon {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    margin-bottom: 4px;
}

.icon-light { background: rgba(255, 193, 7, 0.15); color: #FFC107; }
.icon-alarm { background: rgba(244, 67, 54, 0.15); color: #F44336; }
.icon-power { background: rgba(255, 71, 87, 0.15); color: #ff4757; }
.icon-fan { background: rgba(33, 150, 243, 0.15); color: #2196F3; }

.card-info {
    width: 100%;
}

.card-title {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 4px;
}

.card-status {
    font-size: 0.8rem;
    color: #888;
}

/* 开关样式 */
.switch {
    position: relative;
    display: inline-block;
    width: 48px;
    height: 26px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #ccc;
    transition: .4s;
}

.slider:before {
    position: absolute;
    content: "";
    height: 20px;
    width: 20px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: .4s;
}

input:checked + .slider {
    background-color: var(--primary-color);
}

input:checked + .slider:before {
    transform: translateX(22px);
}

.slider.round {
    border-radius: 34px;
}

.slider.round:before {
    border-radius: 50%;
}

/* Range Slider */
.range-slider {
    -webkit-appearance: none;
    width: 100%;
    height: 6px;
    border-radius: 5px;
    background: #d3d3d3;
    outline: none;
    opacity: 0.7;
    transition: opacity .2s;
    margin-top: 10px;
}

.range-slider:hover {
    opacity: 1;
}

.range-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--primary-color);
    cursor: pointer;
    box-shadow: 0 0 5px rgba(0,0,0,0.2);
}

.range-slider::-moz-range-thumb {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--primary-color);
    cursor: pointer;
    box-shadow: 0 0 5px rgba(0,0,0,0.2);
}

/* 关机按钮 */
.btn-shutdown {
    background: #ff4757;
    color: white;
    border: none;
    padding: 8px 20px;
    border-radius: 20px;
    font-size: 0.9rem;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(255, 71, 87, 0.3);
    transition: opacity 0.2s;
}

.btn-shutdown:hover {
    opacity: 0.9;
}

/* 阈值设置卡片 */
.config-card {
    padding: 20px;
}

.config-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-bottom: 16px;
}

.config-item {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.config-item label {
    font-size: 0.85rem;
    color: #555;
    font-weight: 500;
}

.config-item input {
    width: 100%;
    padding: 10px;
    border: 1px solid rgba(0,0,0,0.1);
    border-radius: 8px;
    background: rgba(255,255,255,0.8);
    font-size: 1rem;
    text-align: center;
    transition: border-color 0.2s;
}

.config-item input:focus {
    outline: none;
    border-color: var(--primary-color);
    background: #fff;
}

.btn-save {
    width: 100%;
    padding: 12px;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    margin-top: 8px;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0, 150, 136, 0.3);
    transition: opacity 0.2s;
}

.btn-save:hover {
    opacity: 0.9;
}

.section-title {
    font-size: 1.1rem;
    font-weight: 600;
    margin: 16px 4px 8px;
    color: #004D40;
    display: flex;
    align-items: center;
}

.section-title::before {
    content: '';
    display: block;
    width: 4px;
    height: 16px;
    background: var(--primary-color);
    margin-right: 8px;
    border-radius: 2px;
}

/* 弹窗样式 */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    backdrop-filter: blur(4px);
}

.modal-content {
    width: 85%;
    max-width: 320px;
    background: #fff;
    border-radius: 16px;
    padding: 20px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.1);
    animation: modalFadeIn 0.3s ease;
}

@keyframes modalFadeIn {
    from { opacity: 0; transform: scale(0.9); }
    to { opacity: 1; transform: scale(1); }
}

.modal-header {
    margin-bottom: 12px;
    text-align: center;
}

.modal-title {
    font-size: 1.1rem;
    font-weight: 600;
    color: #333;
}

.modal-body {
    margin-bottom: 20px;
    text-align: center;
}

.modal-desc {
    font-size: 0.9rem;
    color: #666;
    margin-bottom: 16px;
}

.pin-input-container {
    display: flex;
    justify-content: center;
}

.pin-input {
    width: 100%;
    padding: 12px;
    font-size: 1.5rem;
    text-align: center;
    letter-spacing: 4px;
    border: 2px solid #eee;
    border-radius: 8px;
    outline: none;
    transition: border-color 0.3s;
}

.pin-input:focus {
    border-color: var(--primary-color);
}

.modal-footer {
    display: flex;
    gap: 12px;
}

.modal-btn {
    flex: 1;
    padding: 10px;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    cursor: pointer;
    transition: opacity 0.2s;
}

.modal-btn.cancel {
    background: #f5f5f5;
    color: #666;
}

.modal-btn.confirm {
    background: var(--primary-color);
    color: white;
}

.modal-btn:active {
    opacity: 0.8;
}

/* ========== 历史曲线图表样式 ========== */
.chart-card {
    padding: 15px;
    border-radius: 16px;
}

.chart-tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 12px;
}

.chart-tab {
    flex: 1;
    padding: 8px 12px;
    border: none;
    border-radius: 8px;
    background: rgba(0, 150, 136, 0.1);
    color: var(--primary-color);
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.2s;
}

.chart-tab.active {
    background: var(--primary-color);
    color: white;
}

.chart-tab:hover:not(.active) {
    background: rgba(0, 150, 136, 0.2);
}

.chart-container {
    position: relative;
    height: 200px;
    width: 100%;
}

.chart-legend {
    display: flex;
    justify-content: center;
    gap: 20px;
    margin-top: 10px;
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 5px;
}

.legend-color {
    width: 12px;
    height: 12px;
    border-radius: 3px;
}

