/* ================================================================
   SolarLight PWA — 淡蓝色主题样式系统
   ================================================================ */

/* ---------- CSS 变量 ---------- */
:root {
    /* 主题色系 */
    --primary: #1976D2;
    --primary-dark: #1565C0;
    --primary-light: #42A5F5;
    --primary-pale: #E3F2FD;
    --primary-medium: #BBDEFB;

    /* 功能色 */
    --success: #4CAF50;
    --success-bg: #E8F5E9;
    --warning: #FF9800;
    --warning-bg: #FFF3E0;
    --danger: #F44336;
    --danger-bg: #FCE4EC;
    --info: #2196F3;

    /* 中性色 */
    --bg: #F0F4F8;
    --surface: #FFFFFF;
    --border: #E0E4E8;
    --text-primary: #1A1A2E;
    --text-secondary: #6B7280;
    --text-muted: #9CA3AF;

    /* 阴影 */
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.06);
    --shadow-md: 0 2px 8px rgba(0,0,0,0.10);
    --shadow-lg: 0 4px 16px rgba(0,0,0,0.12);
    --shadow-xl: 0 8px 32px rgba(0,0,0,0.14);

    /* 圆角 */
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;
    --radius-full: 9999px;

    /* 尺寸 */
    --header-h: 56px;
    --nav-h: 64px;
    --max-width: 800px;

    /* 动画 */
    --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);

    /* 字体 */
    --font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
                   "Microsoft YaHei", "Helvetica Neue", sans-serif;
}

/* ---------- 全局重置 ---------- */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: var(--font-family);
    background: var(--bg);
    color: var(--text-primary);
    line-height: 1.5;
    min-height: 100vh;
    min-height: 100dvh;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
}

/* ---------- App 容器 ---------- */
#app {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    min-height: 100dvh;
    max-width: var(--max-width);
    margin: 0 auto;
    position: relative;
    background: var(--bg);
}

/* ---------- 顶部导航 ---------- */
#app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: var(--header-h);
    padding: 0 16px;
    background: linear-gradient(135deg, var(--primary-dark), var(--primary));
    color: #fff;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow-md);
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
}

.header-left {
    display: flex;
    align-items: center;
    gap: 10px;
}

.header-icon {
    font-size: 24px;
}

.header-title {
    font-size: 20px;
    font-weight: 700;
    letter-spacing: -0.5px;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

.bt-status {
    font-size: 12px;
    padding: 4px 10px;
    border-radius: var(--radius-full);
    background: rgba(255,255,255,0.2);
    display: flex;
    align-items: center;
    gap: 4px;
    white-space: nowrap;
}

.bt-status.connected {
    background: rgba(76,175,80,0.4);
}

.bt-status.connecting {
    background: rgba(255,152,0,0.4);
    animation: pulse 1.5s ease-in-out infinite;
}

.header-device-name {
    font-size: 12px;
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* 演示模式按钮 */
.btn-demo {
    font-size: 11px;
    padding: 4px 10px;
    border: 1.5px solid rgba(255,255,255,0.5);
    border-radius: var(--radius-full);
    background: transparent;
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 4px;
    white-space: nowrap;
    font-family: var(--font-family);
    font-weight: 600;
    transition: all var(--transition);
}

.btn-demo:hover {
    background: rgba(255,255,255,0.15);
}

.btn-demo.active {
    background: rgba(255,152,0,0.5);
    border-color: rgba(255,152,0,0.7);
    animation: pulse 2s ease-in-out infinite;
}

/* 安装按钮 */
.btn-install {
    font-size: 11px;
    padding: 4px 10px;
    border: 1.5px solid rgba(255,255,255,0.5);
    border-radius: var(--radius-full);
    background: rgba(76,175,80,0.3);
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 4px;
    white-space: nowrap;
    font-family: var(--font-family);
    font-weight: 600;
    transition: all var(--transition);
    animation: pulse 1.5s ease-in-out infinite;
}
.btn-install:hover { background: rgba(76,175,80,0.5); }
.btn-install.hidden { display: none; }

/* ---------- 主内容区 ---------- */
#app-content {
    flex: 1;
    padding: 16px;
    padding: 16px;
    overflow-y: auto;
}

/* ---------- 页面切换 ---------- */
.page {
    display: none;
    animation: fadeSlideIn 0.3s ease;
}

.page.active {
    display: block;
}

@keyframes fadeSlideIn {
    from { opacity: 0; transform: translateY(12px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* ---------- 页面标题 ---------- */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
    flex-wrap: wrap;
    gap: 8px;
}

.page-header h2 {
    font-size: 22px;
    font-weight: 700;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 8px;
}

.page-header h2 i {
    color: var(--primary-light);
    font-size: 20px;
}

.time-text {
    font-size: 14px;
    color: var(--text-secondary);
}

.device-label {
    font-size: 13px;
    color: var(--text-muted);
    background: var(--primary-pale);
    color: var(--primary);
    padding: 4px 12px;
    border-radius: var(--radius-full);
    font-weight: 500;
}

/* ---------- 概览卡片 ---------- */
.overview-cards {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    margin-bottom: 16px;
}

.overview-card {
    background: var(--surface);
    border-radius: var(--radius-lg);
    padding: 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    box-shadow: var(--shadow-sm);
    transition: transform var(--transition), box-shadow var(--transition);
    cursor: pointer;
}

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

.overview-card:hover {
    box-shadow: var(--shadow-md);
}

.card-icon {
    width: 48px;
    height: 48px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    flex-shrink: 0;
}

.card-info {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.card-value {
    font-size: 26px;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1.2;
}

.card-label {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 2px;
}

/* ---------- 区块卡片 ---------- */
.section-card {
    background: var(--surface);
    border-radius: var(--radius-lg);
    padding: 16px;
    margin-bottom: 16px;
    box-shadow: var(--shadow-sm);
}

.section-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 14px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--border);
}

.section-title i {
    color: var(--primary-light);
}

/* ---------- 按钮 ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 18px;
    border: none;
    border-radius: var(--radius-md);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
    white-space: nowrap;
    font-family: var(--font-family);
    min-height: 42px;
}

.btn:active {
    transform: scale(0.97);
}

.btn-primary {
    background: var(--primary);
    color: #fff;
}

.btn-primary:hover {
    background: var(--primary-dark);
    box-shadow: var(--shadow-md);
}

.btn-outline {
    background: transparent;
    color: var(--primary);
    border: 1.5px solid var(--primary);
}

.btn-outline:hover {
    background: var(--primary-pale);
}

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

.btn-danger:hover {
    background: #D32F2F;
}

.btn-sm {
    padding: 6px 12px;
    font-size: 12px;
    min-height: 32px;
    border-radius: var(--radius-sm);
}

/* ---------- 顶部导航 ---------- */
#top-nav {
    display: flex;
    align-items: center;
    justify-content: space-evenly;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 0;
    position: sticky;
    top: var(--header-h);
    z-index: 99;
    box-shadow: var(--shadow-sm);
}

.nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    border: none;
    background: none;
    cursor: pointer;
    padding: 10px 16px;
    border-radius: 0;
    transition: all var(--transition);
    color: var(--text-muted);
    font-size: 12px;
    font-weight: 500;
    font-family: var(--font-family);
    flex: 1;
    position: relative;
    border-bottom: 2px solid transparent;
}

.nav-item i {
    font-size: 18px;
    transition: all var(--transition);
}

.nav-item.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}

.nav-item.active i {
    /* active icon stays in place */
}

/* ---------- 设备列表 ---------- */
.search-box {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--surface);
    border: 1.5px solid var(--border);
    border-radius: var(--radius-full);
    padding: 10px 16px;
    margin-bottom: 16px;
    transition: border-color var(--transition);
}

.search-box:focus-within {
    border-color: var(--primary-light);
    box-shadow: 0 0 0 3px rgba(25,118,210,0.1);
}

.search-box i {
    color: var(--text-muted);
    font-size: 16px;
}

.search-box input {
    flex: 1;
    border: none;
    outline: none;
    font-size: 14px;
    background: transparent;
    font-family: var(--font-family);
    color: var(--text-primary);
}

.search-box input::placeholder {
    color: var(--text-muted);
}

.scan-status {
    text-align: center;
    padding: 12px;
    color: var(--primary);
    font-size: 14px;
    font-weight: 500;
    background: var(--primary-pale);
    border-radius: var(--radius-md);
    margin-bottom: 16px;
}

.scan-status.hidden {
    display: none;
}

/* ---------- 设备卡片 ---------- */
.device-card {
    background: var(--surface);
    border-radius: var(--radius-lg);
    padding: 12px 14px;
    margin-bottom: 10px;
    box-shadow: var(--shadow-sm);
}

.dev-line1 {
    display: flex;
    align-items: center;
    gap: 10px;
}
.dev-icon { font-size: 18px; flex-shrink: 0; }
.dev-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-primary);
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.dev-tag {
    font-size: 10px;
    padding: 1px 8px;
    border-radius: var(--radius-full);
    font-weight: 600;
    white-space: nowrap;
    flex-shrink: 0;
}
.dev-tag.on  { background: var(--success-bg); color: var(--success); }
.dev-tag.near { background: var(--warning-bg); color: var(--warning); }
.dev-tag.off { background: var(--bg); color: var(--text-muted); }

.dev-btns {
    display: flex;
    gap: 6px;
    flex-shrink: 0;
}
.dev-line2 {
    font-size: 13px;
    color: var(--text-secondary);
    padding: 4px 0 2px 28px;
}

/* ---------- 设备列表单列布局 ---------- */
#device-list-container {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

/* ---------- 空状态 ---------- */
.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-muted);
}

.empty-state i {
    font-size: 48px;
    margin-bottom: 12px;
    opacity: 0.5;
}

.empty-state p {
    font-size: 14px;
    margin-bottom: 12px;
}

.empty-state-small {
    text-align: center;
    padding: 16px;
    color: var(--text-muted);
    font-size: 13px;
}

/* ---------- 实时数据网格 ---------- */
.realtime-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
}

.realtime-grid.hidden,
.realtime-disabled.hidden,
.control-disabled.hidden,
.control-panel.hidden,
#timer-settings.hidden {
    display: none !important;
}

.data-card {
    background: var(--surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}

.data-card-header {
    padding: 12px 14px;
    font-weight: 600;
    font-size: 14px;
    color: #fff;
    display: flex;
    align-items: center;
    gap: 8px;
}

.battery-card .data-card-header { background: linear-gradient(135deg, #43A047, #66BB6A); }
.solar-card .data-card-header   { background: linear-gradient(135deg, #EF6C00, #FF9800); }
.led-card .data-card-header     { background: linear-gradient(135deg, #F9A825, #FDD835); color: #333; }
.env-card .data-card-header     { background: linear-gradient(135deg, #1976D2, #42A5F5); }

.data-card-body {
    padding: 10px 14px;
}

.data-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 0;
    border-bottom: 1px solid var(--border);
}

.data-row:last-child {
    border-bottom: none;
}

.data-label {
    font-size: 13px;
    color: var(--text-secondary);
}

.data-value {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-primary);
}

/* ---------- 控制面板 ---------- */
.power-toggle-area {
    display: flex;
    justify-content: center;
    padding: 20px 0 10px;
}

.power-btn {
    width: 100px;
    height: 100px;
    border-radius: var(--radius-full);
    border: none;
    cursor: pointer;
    font-size: 32px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 6px;
    transition: all 0.3s ease;
    font-family: var(--font-family);
    font-weight: 600;
    font-size: 14px;
    color: #fff;
    background: #B0BEC5;
    box-shadow: var(--shadow-lg);
}

.power-btn.on {
    background: linear-gradient(135deg, #F9A825, #FFD54F);
    color: #333;
    box-shadow: 0 4px 24px rgba(249,168,37,0.5);
}

.power-btn span {
    font-size: 12px;
}

.power-btn i {
    font-size: 28px;
}

.slider-area {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 8px 0;
}

.slider-area input[type="range"] {
    flex: 1;
    -webkit-appearance: none;
    height: 8px;
    border-radius: 4px;
    background: linear-gradient(to right, var(--primary-pale), var(--primary));
    outline: none;
}

.slider-area input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--primary);
    cursor: pointer;
    box-shadow: var(--shadow-md);
    border: 3px solid #fff;
}

.slider-value {
    font-size: 22px;
    font-weight: 700;
    color: var(--primary);
    min-width: 60px;
    text-align: right;
}

.slider-value span:last-child {
    font-size: 14px;
    color: var(--text-secondary);
}

/* ---------- 模式选择器 ---------- */
.mode-selector {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
}

.mode-option {
    cursor: pointer;
}

.mode-option input {
    display: none;
}

.mode-card {
    padding: 14px;
    text-align: center;
    border: 2px solid var(--border);
    border-radius: var(--radius-md);
    transition: all var(--transition);
    background: var(--bg);
}

.mode-card i {
    font-size: 24px;
    color: var(--text-muted);
    display: block;
    margin-bottom: 6px;
    transition: color var(--transition);
}

.mode-name {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    display: block;
}

.mode-desc {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 2px;
}

.mode-option input:checked + .mode-card {
    border-color: var(--primary);
    background: var(--primary-pale);
}

.mode-option input:checked + .mode-card i {
    color: var(--primary);
}

/* ---------- 表单 ---------- */
.form-group {
    margin-bottom: 14px;
}

.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.form-group input[type="number"],
.form-group input[type="text"],
.form-group input[type="time"],
.form-group input[type="date"],
.form-group select {
    width: 100%;
    padding: 10px 14px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-family: var(--font-family);
    color: var(--text-primary);
    background: var(--bg);
    transition: all var(--transition);
    outline: none;
}

.form-group input:focus,
.form-group select:focus {
    border-color: var(--primary-light);
    box-shadow: 0 0 0 3px rgba(25,118,210,0.1);
    background: var(--surface);
}

.date-range {
    display: flex;
    align-items: center;
    gap: 8px;
}

.date-range input {
    flex: 1;
}

.date-range span {
    color: var(--text-muted);
    font-size: 13px;
}

.inline-value {
    font-size: 14px;
    font-weight: 600;
    color: var(--primary);
    margin-left: 8px;
}

/* ---------- 图表 ---------- */
.charts-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 16px;
}

.chart-range-select {
    padding: 8px 14px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-full);
    font-size: 13px;
    font-family: var(--font-family);
    color: var(--text-primary);
    background: var(--surface);
    outline: none;
    cursor: pointer;
}

.chart-card {
    background: var(--surface);
    border-radius: var(--radius-lg);
    padding: 16px;
    box-shadow: var(--shadow-sm);
}

.chart-card-header {
    font-size: 15px;
    font-weight: 600;
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    gap: 8px;
}

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

.chart-container canvas {
    width: 100% !important;
    height: 100% !important;
}

/* ---------- 告警列表 ---------- */
.alarm-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.alarm-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    background: var(--bg);
    font-size: 13px;
}

.alarm-item.critical {
    background: var(--danger-bg);
    border-left: 3px solid var(--danger);
}

.alarm-item.warning {
    background: var(--warning-bg);
    border-left: 3px solid var(--warning);
}

.alarm-item i {
    font-size: 16px;
}

.alarm-item.critical i { color: var(--danger); }
.alarm-item.warning i { color: var(--warning); }

.alarm-item .alarm-msg { flex: 1; color: var(--text-primary); }
.alarm-item .alarm-time { font-size: 11px; color: var(--text-muted); }

/* ---------- 紧凑设备列表 ---------- */
.compact-device-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.compact-device-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    background: var(--bg);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background var(--transition);
}

.compact-device-item:hover {
    background: var(--primary-pale);
}

.compact-device-item .device-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}

.compact-device-item .device-dot.online { background: var(--success); }
.compact-device-item .device-dot.offline { background: var(--text-muted); }

.compact-device-item .device-name-sm {
    flex: 1;
    font-size: 14px;
    font-weight: 500;
}

.compact-device-item .device-brief {
    font-size: 12px;
    color: var(--text-muted);
}

/* ---------- 弹窗 ---------- */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    animation: fadeIn 0.2s ease;
}

.modal-overlay.hidden { display: none; }

.modal-box {
    background: var(--surface);
    border-radius: var(--radius-xl);
    padding: 28px 24px 20px;
    width: 100%;
    max-width: 340px;
    text-align: center;
    box-shadow: var(--shadow-xl);
    animation: scaleIn 0.25s ease;
}

.modal-icon {
    font-size: 44px;
    margin-bottom: 12px;
}

.modal-title {
    font-size: 18px;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 8px;
}

.modal-message {
    font-size: 14px;
    color: var(--text-secondary);
    margin-bottom: 20px;
    line-height: 1.6;
}

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

.modal-actions .btn {
    flex: 1;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

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

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* ---------- Toast ---------- */
.toast {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 300;
    padding: 12px 24px;
    border-radius: var(--radius-full);
    background: #333;
    color: #fff;
    font-size: 14px;
    font-weight: 500;
    box-shadow: var(--shadow-lg);
    transition: all 0.3s ease;
    pointer-events: none;
}

.toast.hidden {
    opacity: 0;
    transform: translateX(-50%) translateY(-20px);
}

.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }
.toast.info { background: var(--primary); }

/* ---------- 危险区域 ---------- */
.danger-area {
    padding: 8px 0;
}

/* ---------- 关于 ---------- */
.about-info p {
    font-size: 13px;
    color: var(--text-secondary);
    line-height: 1.8;
}

.about-info strong {
    color: var(--text-primary);
}

/* ---------- 响应式：平板/桌面 ---------- */
@media (min-width: 768px) {
    #app {
        max-width: 900px;
    }

    #app-content {
        padding: 24px;
        padding-bottom: 24px;
    }

    #top-nav {
        justify-content: center;
        padding: 4px 0;
    }

    .nav-item {
        flex-direction: row;
        gap: 8px;
        font-size: 14px;
        max-width: none;
        padding: 12px 20px;
        border-radius: 0;
        border-bottom: 2px solid transparent;
    }

    .nav-item i {
        font-size: 16px;
    }

    .nav-item.active {
        background: transparent;
        border-bottom-color: var(--primary);
    }

    .overview-cards {
        grid-template-columns: repeat(4, 1fr);
    }

    .realtime-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .mode-selector {
        grid-template-columns: repeat(4, 1fr);
    }

    .charts-grid {
        grid-template-columns: repeat(2, 1fr);
    }

}

@media (min-width: 1024px) {
    #app {
        max-width: 1000px;
    }

    .overview-cards {
        grid-template-columns: repeat(4, 1fr);
    }

    .realtime-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .charts-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}
