:root {
    --primary: #2c6e3f;
    --primary-light: #4caf50;
    --primary-dark: #1a4a2a;
    --bg: #eef2e9;
    --card-bg: #ffffff;
    --text: #1f2e1c;
    --text-light: #5a6e52;
    --border: #dfebd9;
    --danger: #e74c3c;
    --warning: #f39c12;
    --success: #27ae60;
    --shadow: 0 2px 12px rgba(0, 32, 0, 0.08);
    --radius: 16px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
}

/* ─── Navigation ─── */
.navbar {
    background: var(--primary-dark);
    color: white;
    padding: 0 24px;
    display: flex;
    align-items: center;
    height: 56px;
    gap: 24px;
    position: sticky;
    top: 0;
    z-index: 100;
}

.navbar .brand {
    font-weight: 700;
    font-size: 1.1rem;
    white-space: nowrap;
}

.navbar .nav-links { display: flex; gap: 4px; flex: 1; }

.navbar .nav-links a {
    color: rgba(255,255,255,0.8);
    text-decoration: none;
    padding: 8px 16px;
    border-radius: 8px;
    font-size: 0.9rem;
    transition: all 0.2s;
}

.navbar .nav-links a:hover,
.navbar .nav-links a.active {
    background: rgba(255,255,255,0.15);
    color: white;
}

.navbar .user-info {
    font-size: 0.85rem;
    display: flex;
    align-items: center;
    gap: 12px;
}

.navbar .user-info .logout-btn {
    background: rgba(255,255,255,0.15);
    border: none;
    color: white;
    padding: 6px 14px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.85rem;
}

/* ─── Container ─── */
.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 24px;
}

.page-title {
    font-size: 1.5rem;
    color: var(--primary-dark);
    margin-bottom: 20px;
}

/* ─── Cards ─── */
.card {
    background: var(--card-bg);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    padding: 20px;
    box-shadow: var(--shadow);
}

.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

/* ─── Sensor Cards ─── */
.sensor-card {
    background: var(--card-bg);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    padding: 20px;
    box-shadow: var(--shadow);
    transition: transform 0.2s;
}

.sensor-card:hover { transform: translateY(-2px); }

.sensor-card .sensor-label {
    font-size: 0.85rem;
    color: var(--text-light);
    margin-bottom: 4px;
}

.sensor-card .sensor-value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--primary-dark);
}

.sensor-card .sensor-unit {
    font-size: 0.9rem;
    color: var(--text-light);
}

.progress-bar {
    height: 8px;
    background: #e8f1e5;
    border-radius: 4px;
    margin-top: 10px;
    overflow: hidden;
}

.progress-bar .fill {
    height: 100%;
    background: linear-gradient(90deg, var(--primary-light), var(--primary));
    border-radius: 4px;
    transition: width 0.5s ease;
}

/* ─── Switch Controls ─── */
.switch-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 0;
    border-bottom: 1px solid var(--border);
}

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

.switch-info { display: flex; align-items: center; gap: 12px; }

.switch-indicator {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    transition: background 0.3s;
}

.switch-indicator.on { background: var(--success); box-shadow: 0 0 8px rgba(39,174,96,0.4); }
.switch-indicator.off { background: #bdc3c7; }

.switch-name { font-weight: 600; }

.switch-actions { display: flex; gap: 8px; }

/* ─── Buttons ─── */
.btn {
    padding: 8px 20px;
    border-radius: 8px;
    border: none;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); }

.btn-success { background: var(--success); color: white; }
.btn-success:hover { background: #219a52; }

.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover { background: #c0392b; }

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

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

.btn-sm { padding: 4px 12px; font-size: 0.8rem; }

/* ─── Forms ─── */
.form-group { margin-bottom: 16px; }

.form-group label {
    display: block;
    margin-bottom: 4px;
    font-weight: 600;
    font-size: 0.9rem;
}

.form-input {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 0.9rem;
    outline: none;
    transition: border 0.2s;
}

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

select.form-input { appearance: auto; }

/* ─── Login Page ─── */
.login-page {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    background: linear-gradient(135deg, #1a4a2a 0%, #2c6e3f 50%, #4caf50 100%);
}

.login-card {
    background: white;
    border-radius: 24px;
    padding: 40px;
    width: 400px;
    max-width: 90vw;
    box-shadow: 0 20px 60px rgba(0,0,0,0.2);
}

.login-card h1 {
    text-align: center;
    color: var(--primary-dark);
    margin-bottom: 8px;
    font-size: 1.5rem;
}

.login-card .subtitle {
    text-align: center;
    color: var(--text-light);
    margin-bottom: 28px;
    font-size: 0.9rem;
}

.login-card .form-group { margin-bottom: 20px; }

.login-card .btn {
    width: 100%;
    padding: 12px;
    font-size: 1rem;
}

.login-card .error-msg {
    color: var(--danger);
    font-size: 0.85rem;
    text-align: center;
    margin-bottom: 12px;
    display: none;
}

/* ─── Table ─── */
.table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

.table th {
    background: #e8f1e5;
    padding: 10px 12px;
    text-align: left;
    font-weight: 600;
    border: 1px solid var(--border);
}

.table td {
    padding: 10px 12px;
    border: 1px solid var(--border);
}

.table tr:hover { background: #f6faf3; }

/* ─── Modal ─── */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 200;
    justify-content: center;
    align-items: center;
}

.modal-overlay.active { display: flex; }

.modal {
    background: white;
    border-radius: 20px;
    padding: 28px;
    width: 700px;
    max-width: 90vw;
    max-height: 80vh;
    overflow-y: auto;
}

/* 模态框内表格列不换行 */
.modal .table th, .modal .table td { white-space: nowrap; padding: 8px 12px; }

.modal h3 { margin-bottom: 16px; }

.modal .btn-row { display: flex; gap: 12px; justify-content: flex-end; margin-top: 20px; }

/* ─── Badge ─── */
/* ─── 自定义滚动条（主题色配套） ─── */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-light); }

/* ─── Badge ─── */
.badge {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
}

.badge-success { background: #e8f8e8; color: var(--success); }
.badge-danger { background: #fde8e8; color: var(--danger); }
.badge-info { background: #e3f0fa; color: #2980b9; }

/* ─── Utilities ─── */
.flex { display: flex; }
.flex-center { display: flex; align-items: center; justify-content: center; }
.gap-2 { gap: 8px; }
.gap-4 { gap: 16px; }
.mb-2 { margin-bottom: 8px; }
.mb-4 { margin-bottom: 16px; }
.mt-4 { margin-top: 16px; }
.text-center { text-align: center; }
.text-right { text-align: right; }

/* ─── Responsive ─── */
@media (max-width: 768px) {
    .navbar { flex-wrap: wrap; height: auto; padding: 12px; gap: 8px; }
    .navbar .nav-links { flex-wrap: wrap; }
    .container { padding: 12px; }
    .card-grid { grid-template-columns: 1fr; }
    .sensor-card .sensor-value { font-size: 1.5rem; }
}

@media (min-width: 769px) and (max-width: 1024px) {
    .card-grid { grid-template-columns: repeat(2, 1fr); }
}

/* ─── Device Radio Group（看板设备单选，风格与各主题导航标签一致） ─── */
.device-radio-group {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px 20px;
    margin: 1rem 0;
    box-shadow: var(--shadow);
}

.device-radio-header {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--primary-dark);
    margin-bottom: 10px;
}

.device-radio-items {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.device-radio-item {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 18px;
    border: none;
    border-radius: 2.5rem;
    cursor: pointer;
    transition: all 0.2s;
    background: transparent;
    color: var(--text-light);
    font-weight: 600;
    font-size: 0.85rem;
    user-select: none;
    font-family: inherit;
}

.device-radio-item:hover {
    background: var(--border);
    color: var(--primary-dark);
}

.device-radio-item.selected {
    background: var(--border);
    color: var(--primary-dark);
}

.device-radio-name {
    font-weight: 600;
    font-size: 0.9rem;
}

.device-radio-code {
    font-size: 0.75rem;
    opacity: 0.7;
}

/* ─── Charts ─── */
.chart-container {
    background: var(--card-bg);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    padding: 20px;
    margin-bottom: 20px;
    box-shadow: var(--shadow);
}

.chart-box {
    width: 100%;
    height: 400px;
}

/* ─── Loading ─── */
.loading {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 40px;
    color: var(--text-light);
}

.hidden { display: none !important; }

.spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }
